Example #1
0
void pattern_show(pattern_t *pattern)
{
	int size = strlen(pattern->id) + strlen(pattern->source) + 256;
	char buf[size];
	pattern_str(pattern, buf, size);
	printf("%s", buf);
}
void Init()
{
    CIniReader iniReader("");
    Screen.Width = iniReader.ReadInteger("MAIN", "ResX", 0);
    Screen.Height = iniReader.ReadInteger("MAIN", "ResY", 0);
    bool bFixHUD = iniReader.ReadInteger("MAIN", "FixHUD", 1) != 0;
    bool bFixFOV = iniReader.ReadInteger("MAIN", "FixFOV", 1) != 0;
    bool bRandomSongOrderFix = iniReader.ReadInteger("MAIN", "RandomSongOrderFix", 1) != 0;

    if (!Screen.Width || !Screen.Height)
        std::tie(Screen.Width, Screen.Height) = GetDesktopRes();

    Screen.fWidth = static_cast<float>(Screen.Width);
    Screen.fHeight = static_cast<float>(Screen.Height);
    Screen.Width43 = static_cast<int32_t>(Screen.fHeight * (4.0f / 3.0f));
    Screen.fAspectRatio = (Screen.fWidth / Screen.fHeight);
    Screen.fAspectRatioDiff = 1.0f / (Screen.fAspectRatio / (4.0f / 3.0f));
    Screen.fHUDScaleX = 1.0f / Screen.fWidth * (Screen.fHeight / 480.0f);
    Screen.fHudOffset = ((480.0f * Screen.fAspectRatio) - 640.0f) / 2.0f;
    Screen.fHudOffsetReal = (Screen.fWidth - Screen.fHeight * (4.0f / 3.0f)) / 2.0f;

    //Resolution
    auto pattern = hook::pattern("89 0D ? ? ? ? 89 15 ? ? ? ? 89 0D ? ? ? ? 89 15 ? ? ? ? 74");
    static int32_t* dword_67FBCC = *pattern.get_first<int32_t*>(2);
    static int32_t* dword_67FBD0 = *pattern.get_first<int32_t*>(8);
    static int32_t* dword_787A7C = *pattern.get_first<int32_t*>(12 + 2);
    static int32_t* dword_787A80 = *pattern.get_first<int32_t*>(12 + 8);
    struct SetResHook
    {
        void operator()(injector::reg_pack& regs)
        {
            *dword_67FBCC = Screen.Width;
            *dword_67FBD0 = Screen.Height;
            *dword_787A7C = Screen.Width;
            *dword_787A80 = Screen.Height;
        }
    };

    pattern = hook::pattern(pattern_str(0x89, '?', to_bytes(dword_67FBCC)));
    injector::MakeInline<SetResHook>(pattern.get_first(0), pattern.get_first(6));
    pattern = hook::pattern(pattern_str(0xA3, to_bytes(dword_67FBCC)));
    injector::MakeInline<SetResHook>(pattern.get_first(0));
    pattern = hook::pattern(pattern_str(0x89, '?', to_bytes(dword_67FBD0)));
    injector::MakeInline<SetResHook>(pattern.count(2).get(0).get<void*>(0), pattern.count(2).get(0).get<void*>(6));
    injector::MakeInline<SetResHook>(pattern.count(2).get(1).get<void*>(0), pattern.count(2).get(1).get<void*>(6));

    pattern = hook::pattern(pattern_str(0x89, '?', to_bytes(dword_787A7C)));
    injector::MakeNOP(pattern.count(2).get(0).get<void*>(0), 6, true); //injector::MakeInline<SetResHook>(pattern.count(2).get(0).get<void*>(0), pattern.count(2).get(0).get<void*>(6));
    injector::MakeNOP(pattern.count(2).get(1).get<void*>(0), 6, true); //injector::MakeInline<SetResHook>(pattern.count(2).get(1).get<void*>(0), pattern.count(2).get(1).get<void*>(6));

    pattern = hook::pattern(pattern_str(0x89, '?', to_bytes(dword_787A80)));
    injector::MakeNOP(pattern.count(2).get(0).get<void*>(0), 6, true); //injector::MakeInline<SetResHook>(pattern.count(2).get(0).get<void*>(0), pattern.count(2).get(0).get<void*>(6));
    injector::MakeNOP(pattern.count(2).get(1).get<void*>(0), 6, true); //injector::MakeInline<SetResHook>(pattern.count(2).get(1).get<void*>(0), pattern.count(2).get(1).get<void*>(6));

    //Aspect Ratio
    pattern = hook::pattern("68 ? ? ? ? E8 ? ? ? ? 6A 00 68 ? ? ? ? E8 ? ? ? ? D9");
    injector::WriteMemory<float>(pattern.get_first(1), Screen.fAspectRatio, true);
    pattern = hook::pattern("E8 ? ? ? ? D9 04 24 D8 74 24 04 DE C9");
    injector::WriteMemory(injector::GetBranchDestination(pattern.get_first()).as_int() + 2, &Screen.fAspectRatio, true);

    //FOV
    if (bFixFOV)
    {
        pattern = hook::pattern("D9 96 B0 00 00 00 D8 0D ? ? ? ? D9 F2 DD D8"); //0x485B57
        struct FovHook
        {
            void operator()(injector::reg_pack& regs)
            {
                float fov = 0.0f;
                _asm {fst dword ptr[fov]}
                *(float*)(regs.esi + 0xB0) = AdjustFOV(fov, Screen.fAspectRatio);
            }
        }; injector::MakeInline<FovHook>(pattern.get_first(), pattern.get_first(6));
    }

    //HUD
    if (bFixHUD)
    {
        static int32_t nHudOffset = static_cast<int32_t>(Screen.fHudOffsetReal);
        static int32_t* dword_787D88;
        struct SetOffsetHook
        {
            void operator()(injector::reg_pack& regs)
            {
                *dword_787D88 = nHudOffset;
            }
        };

        pattern = hook::pattern("D8 0D ? ? ? ? 89 0D ? ? ? ? 89 15 ? ? ? ? 0F B6 C8");
        injector::WriteMemory<float>(*pattern.get_first<float*>(2), Screen.fHUDScaleX, true);
        dword_787D88 = *hook::get_pattern<int32_t*>("DB 05 ? ? ? ? 57 D9 05 ? ? ? ? 8B F9", 2);

        pattern = hook::pattern(pattern_str(0x89, '?', to_bytes(dword_787D88)));
        for (size_t i = 0; i < pattern.size(); ++i)
            injector::MakeInline<SetOffsetHook>(pattern.get(i).get<uint32_t>(0), pattern.get(i).get<uint32_t>(6));
    }

    if (bRandomSongOrderFix)
    {
        pattern = hook::pattern("83 C4 08 ? D0 07 00 00");
        auto rpattern = hook::range_pattern((uintptr_t)pattern.get_first(3), (uintptr_t)pattern.get_first(110), "75 ? A1");
        static auto dword_69B718 = *rpattern.get_first<int32_t*>(3);
        static auto dword_681D14 = *hook::range_pattern((uintptr_t)pattern.get_first(3), (uintptr_t)pattern.get_first(60), "A1 ? ? ? ?").get_first<int32_t*>(1);
        struct RandomHook
        {
            void operator()(injector::reg_pack& regs)
            {
                auto num_songs = *dword_681D14;
                int32_t* sp_xbox_randomized_songs = dword_69B718;

                std::vector<int32_t> songs;
                songs.assign(std::addressof(sp_xbox_randomized_songs[0]), std::addressof(sp_xbox_randomized_songs[num_songs]));
                std::mt19937 r{ std::random_device{}() };
                std::shuffle(std::begin(songs), std::end(songs), r);

                std::copy(songs.begin(), songs.end(), sp_xbox_randomized_songs);
            }
        }; injector::MakeInline<RandomHook>(pattern.get_first(3), rpattern.get_first(2));
    }
}
void Init()
{
    CIniReader iniReader("");
    Screen.Width = iniReader.ReadInteger("MAIN", "ResX", 0);
    Screen.Height = iniReader.ReadInteger("MAIN", "ResY", 0);
    bool bFixHUD = iniReader.ReadInteger("MAIN", "FixHUD", 1) != 0;

    if (!Screen.Width || !Screen.Height)
        std::tie(Screen.Width, Screen.Height) = GetDesktopRes();

    Screen.fWidth = static_cast<float>(Screen.Width);
    Screen.fHeight = static_cast<float>(Screen.Height);
    Screen.Width43 = static_cast<int32_t>(Screen.fHeight * (4.0f / 3.0f));
    Screen.fAspectRatio = (Screen.fWidth / Screen.fHeight);
    Screen.fHudOffset = ((480.0f * Screen.fAspectRatio) - 640.0f) / 2.0f;
    Screen.fHudOffsetReal = (Screen.fWidth - Screen.fHeight * (4.0f / 3.0f)) / 2.0f;

    auto pattern = hook::pattern("A3 ? ? ? ? E8 ? ? ? ? 8B 15 ? ? ? ? A1 ? ? ? ? 6A 10"); //4F3FEE
    static int32_t* dword_29D6FE8 = *pattern.get_first<int32_t*>(1);
    static int32_t* dword_29D6FE4 = *pattern.get_first<int32_t*>(17);

    struct SetResHook1
    {
        void operator()(injector::reg_pack& regs)
        {
            *dword_29D6FE4 = Screen.Width;
            *dword_29D6FE8 = Screen.Height;
        }
    }; injector::MakeInline<SetResHook1>(pattern.get_first(0));

    pattern = hook::pattern("A3 ? ? ? ? 8B 0D ? ? ? ? 6A 10 51 50"); //4F54A4
    struct SetResHook2
    {
        void operator()(injector::reg_pack& regs)
        {
            *dword_29D6FE4 = Screen.Width;
            *dword_29D6FE8 = Screen.Height;
        }
    }; injector::MakeInline<SetResHook2>(pattern.get_first(0));

    pattern = hook::pattern("89 0D ? ? ? ? 8D 34 49"); //46463F
    static int32_t* dword_55ED00 = *pattern.get_first<int32_t*>(2);
    pattern = hook::pattern("A3 ? ? ? ? ? ? 8D 04 49 33 D2");
    static int32_t* dword_55ED18 = *pattern.get_first<int32_t*>(1);
    pattern = hook::pattern("C7 05 ? ? ? ? 00 10 00 00 5E A3");
    static int32_t* dword_5606CC = *pattern.get_first<int32_t*>(2);
    static int32_t* dword_5606D0 = *pattern.get_first<int32_t*>(12);
    struct AspectRatioHook
    {
        void operator()(injector::reg_pack& regs)
        {
            *dword_55ED00 = Screen.Width;
            *dword_55ED18 = Screen.Height;
            *dword_5606D0 = 4096;
            *dword_5606CC = 4096;
        }
    };
    pattern = hook::pattern("E8 ? ? ? ? 83 C4 08 E8 ? ? ? ? 5E 5B 83 C4 08 C3"); //0x430466
    injector::MakeInline<AspectRatioHook>(pattern.get_first(0));
    pattern = hook::pattern("E8 ? ? ? ? 83 C4 08 53 56"); //0x4645B8
    injector::MakeInline<AspectRatioHook>(pattern.get_first(0));

    //FOV
    Screen.FOV = static_cast<int32_t>(4096.0f / (Screen.fAspectRatio / (4.0f / 3.0f)));
    pattern = hook::pattern("F7 3D ? ? ? ? 33 C9 66 8B 4E"); //45E9E9
    injector::WriteMemory(pattern.get_first(2), &Screen.FOV, true);

    //Main menu wheel fix
    auto sub_4F0A70 = [](int16_t a1) -> int32_t
    {
        return (int32_t)(cos((float)(a1 & 0xFFF) * 0.00024414062f * 6.2831855f) * (4096.0f / (Screen.fHeight / 480.0f)));
    };
    pattern = hook::pattern("E8 ? ? ? ? 53 89 44 24 1C 89");
    injector::MakeCALL(pattern.get_first(0), static_cast<int32_t(*)(int16_t)>(sub_4F0A70), true); //0x457939
    pattern = hook::pattern("E8 ? ? ? ? 0F AF 44 24 20 C1");
    injector::MakeCALL(pattern.get_first(0), static_cast<int32_t(*)(int16_t)>(sub_4F0A70), true); //0x457992

    auto sub_4F0AA0 = [](int16_t a1) -> int32_t
    {
        return (int32_t)(sin((float)(a1 & 0xFFF) * 0.00024414062f * 6.2831855f) * (4096.0f / (Screen.fHeight / 480.0f)));
    };
    pattern = hook::pattern("E8 ? ? ? ? 8B F0 53 0F AF");
    injector::MakeCALL(pattern.get_first(0), static_cast<int32_t(*)(int16_t)>(sub_4F0AA0), true); //0x457947
    pattern = hook::pattern("E8 ? ? ? ? 8B 5D 0C 89 44");
    injector::MakeCALL(pattern.get_first(0), static_cast<int32_t(*)(int16_t)>(sub_4F0AA0), true); //0x45795D

    if (bFixHUD)
    {
        //menu backgrounds
        pattern = hook::pattern("A1 ? ? ? ? 81 EC 98"); //4D4BA0
        auto sub_4D4BA0 = pattern.get_first(0);
        static auto dword_29D6FF0 = *pattern.get_first<uint32_t*>(1);
        struct MenuHook1
        {
            void operator()(injector::reg_pack& regs)
            {
                regs.eax = *dword_29D6FF0;
                *(float*)(regs.esp + 0x8) += Screen.fHudOffset;
            }
        }; injector::MakeInline<MenuHook1>(sub_4D4BA0);

        auto rpattern = hook::range_pattern((uintptr_t)sub_4D4BA0, (uintptr_t)sub_4D4BA0 + 0x414, pattern_str(0xA1, to_bytes(dword_29D6FE4))); //mov     eax, dword_29D6FE4
        for (size_t i = 0; i < rpattern.size(); ++i)
        {
            //0x4D4CEF, 0x4D4D51, 0x4D4D8A, 0x4D4DBD, 0x4D4E4F, 0x4D4E82, 0x4D4EBB
            injector::WriteMemory(rpattern.get(i).get<uint32_t>(1), &Screen.Width43, true);
        }

        //some menu things
        pattern = hook::pattern("C7 41 28 00 00 80 BF"); //457C0E
        struct MenuHook2
        {
            void operator()(injector::reg_pack& regs)
            {
                *(int16_t*)(regs.ecx + 0x08) += (int16_t)Screen.fHudOffsetReal;
                *(int16_t*)(regs.ecx + 0x10) += (int16_t)Screen.fHudOffsetReal;
                *(int16_t*)(regs.ecx + 0x18) += (int16_t)Screen.fHudOffsetReal;
                *(int16_t*)(regs.ecx + 0x20) += (int16_t)Screen.fHudOffsetReal;
                *(float*)(regs.ecx + 0x28) = -1.0f;
            }
        };

        for (size_t i = 0; i < pattern.size(); ++i)
        {
            injector::MakeInline<MenuHook2>(pattern.get(i).get<uint32_t>(0), pattern.get(i).get<uint32_t>(7));

            rpattern = hook::range_pattern((uintptr_t)pattern.get(i).get<uint32_t>(-0x170), (uintptr_t)pattern.get(i).get<uint32_t>(0), pattern_str(0x0F, 0xAF, '?', to_bytes(dword_29D6FE4))); //imul    e?x, dword_29D6FE4
            for (size_t i = 0; i < rpattern.size(); ++i)
            {
                injector::WriteMemory(rpattern.get(i).get<uint32_t>(3), &Screen.Width43, true);
            }
        }
    }
}
void Init()
{
    CIniReader iniReader("");
    Screen.Width = iniReader.ReadInteger("MAIN", "ResX", 0);
    Screen.Height = iniReader.ReadInteger("MAIN", "ResY", 0);
    bool bFix2D = iniReader.ReadInteger("MAIN", "Fix2D", 1) != 0;
    bool bFixFOV = iniReader.ReadInteger("MAIN", "FixFOV", 1) != 0;
    bool bDisableCutsceneBorders = iniReader.ReadInteger("MAIN", "DisableCutsceneBorders", 1) != 0;
    bool bIncreaseBackgroundRes = iniReader.ReadInteger("MAIN", "IncreaseBackgroundRes", 1) != 0;
    bool bCutsceneFrameRateFix = iniReader.ReadInteger("MAIN", "CutsceneFrameRateFix", 1) != 0;
    bool bDisableCheckSpec = iniReader.ReadInteger("MAIN", "DisableCheckSpec", 1) != 0;
    bool bDisableRegistryDependency = iniReader.ReadInteger("MISC", "DisableRegistryDependency", 1) != 0;
    bool bDisableSafeMode = iniReader.ReadInteger("MISC", "DisableSafeMode", 1) != 0;
    bool bSkipIntro = iniReader.ReadInteger("MISC", "SkipIntro", 1) != 0;
    bool bBrightnessFix = iniReader.ReadInteger("MISC", "BrightnessFix", 1) != 0;

    if (!Screen.Width || !Screen.Height)
        std::tie(Screen.Width, Screen.Height) = GetDesktopRes();

    Screen.fWidth = static_cast<float>(Screen.Width);
    Screen.fHeight = static_cast<float>(Screen.Height);
    Screen.fAspectRatio = (Screen.fWidth / Screen.fHeight);
    Screen.fFieldOfView = ((1.0f / Screen.fAspectRatio) * (4.0f / 3.0f));
    Screen.fHudScale = ((1.0f / Screen.fAspectRatio) * (4.0f / 3.0f));
    Screen.fHudOffset = ((480.0f * Screen.fAspectRatio) - 640.0f) / 2.0f;
    Screen.fHudOffsetReal = (Screen.fWidth - Screen.fHeight * (4.0f / 3.0f)) / 2.0f;

    //Resolution
    static auto nWidthPtr = *hook::pattern("8B 0D ? ? ? ? 6A 00 50 51").count(1).get(0).get<uint32_t*>(2);
    auto pattern = hook::pattern(pattern_str(0xC7, 0x05, to_bytes(nWidthPtr))); //0x4141E3

    for (size_t i = 0; i < pattern.size(); i++)
    {
        injector::WriteMemory(pattern.get(i).get<uint32_t>(6), Screen.Width, true);
    }

    static auto nHeightPtr = *hook::pattern("8B 0D ? ? ? ? 89 44 24 1C 39").count(1).get(0).get<uint32_t*>(2);
    pattern = hook::pattern(pattern_str(0xC7, 0x05, to_bytes(nHeightPtr))); //0x4141ED

    for (size_t i = 0; i < pattern.size(); i++)
    {
        injector::WriteMemory(pattern.get(i).get<uint32_t>(6), Screen.Height, true);
    }

    pattern = hook::pattern("89 35 ? ? ? ? 33 C0 5E C3"); //0x414A38
    struct SetResHook
    {
        void operator()(injector::reg_pack&)
        {
            *nWidthPtr = Screen.Width;
            *nHeightPtr = Screen.Height;
        }
    }; injector::MakeInline<SetResHook>(pattern.count(1).get(0).get<uintptr_t>(0), pattern.count(1).get(0).get<uintptr_t>(6));

    if (bFixFOV)
    {
        pattern = hook::pattern("83 C4 14 68 ? ? ? ? E8 ? ? ? ? 68"); //0x55BC74 
        injector::MakeNOP(pattern.count(1).get(0).get<uint32_t>(8), 5, true);
        injector::WriteMemory<float>(pattern.count(1).get(0).get<uint32_t>(14), Screen.fFieldOfView, true);

        pattern = hook::pattern("C7 46 48 ? ? ? ? C7 46 44"); //0x41D295
        injector::WriteMemory<float>(pattern.count(1).get(0).get<uint32_t>(3), 0.78125f * Screen.fHudScale, true);
    }

    if (bFix2D)
    {
        //Menu scale and disabling of some overlays
        static float fMenuScale = 0.00390625f * Screen.fHudScale;
        pattern = hook::pattern("D8 0D ? ? ? ? 6A 01 8D 54 24 1C 52 D9 5C 24 10 6A 5E"); //0x404E4C + 2
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(2), &fMenuScale, true); // Menu Width

        //in game overlay
        auto ret_512 = []() -> int32_t
        {
            return static_cast<int32_t>(512.0f * Screen.fHudScale);
        };
        pattern = hook::pattern("E8 ? ? ? ? 8B 4C 24 1C 99 2B C2 8B 51 10 D1 F8"); //433C4D
        injector::MakeCALL(pattern.get_first(0), static_cast<int32_t(*)()>(ret_512), true);
        pattern = hook::pattern("E8 ? ? ? ? 8B 7C 24 50 99 2B C2 8B 57 10 D1 F8"); //433CCF
        injector::MakeCALL(pattern.get_first(0), static_cast<int32_t(*)()>(ret_512), true);
        pattern = hook::pattern("DB 44 24 20 D9 5C 24 20 E8 ? ? ? ? 8B 4C 24 1C 99 2B C2 8B 51 14 D1 F8"); //433C69
        struct OverlayWidthHook1
        {
            void operator()(injector::reg_pack& regs)
            {
                float f = 0.0f;
                int32_t n = *(int32_t*)(regs.esp + 0x20);
                _asm {fild dword ptr[n]}
                _asm {fdiv dword ptr[Screen.fHudScale]}
                _asm {fstp dword ptr[f]}
                *(float*)(regs.esp + 0x20) = f;
            }
        }; injector::MakeInline<OverlayWidthHook1>(pattern.get_first(0), pattern.get_first(8));

        pattern = hook::pattern("DB 44 24 50 D9 5C 24 38 E8 ? ? ? ? 8B 4F 14 99 2B C2 D1 F8"); //433CEB
        struct OverlayWidthHook2
        {
            void operator()(injector::reg_pack& regs)
            {
                float f = 0.0f;
                int32_t n = *(int32_t*)(regs.esp + 0x50);
                _asm {fild dword ptr[n]}
                _asm {fdiv dword ptr[Screen.fHudScale]}
                _asm {fstp dword ptr[f]}
                *(float*)(regs.esp + 0x38) = f;
            }
        }; injector::MakeInline<OverlayWidthHook2>(pattern.get_first(0), pattern.get_first(8));

        pattern = hook::pattern("55 8B EC 83 E4 F0 83 EC 64 D9 45 18"); //0x42EAC0
        injector::MakeRET(pattern.get_first());

        pattern = hook::pattern("E8 ? ? ? ? 83 C4 5C C6 05 ? ? ? ? 00 B8"); //0x42E719
        injector::MakeNOP(pattern.get_first(), 5, true); // Cutscene Wall Darkness Effect

        pattern = hook::pattern("E8 ? ? ? ? 83 C4 5C C6 05 ? ? ? ? 00 A1"); //0x45EBD2
        injector::MakeNOP(pattern.get_first(), 5, true); //Cutscene Wall Grunge Effect

        // Text fix
        pattern = hook::pattern("C7 44 24 34 00 00 80 BF D9 5C"); //0x404EBB
        injector::WriteMemory<float>(pattern.count(1).get(0).get<uint32_t>(4), -1.0f * Screen.fHudScale, true); // Text X Pos
        pattern = hook::pattern("C7 44 24 24 CD CC 4C 3B D9 44 24 14"); //0x404E91
        injector::WriteMemory<float>(pattern.count(1).get(0).get<uint32_t>(4), 0.003125f * Screen.fHudScale, true); // Text Width

        //FMV
        pattern = hook::pattern("E8 ? ? ? ? 8B 14 B5 ? ? ? ? A1"); //0x412EAF
        hb_563BF0.fun = injector::MakeCALL(pattern.count(1).get(0).get<uint32_t>(0), FMVHook, true).get();

        //Width
        //sub_563BF0
        auto sub_563BF0 = (uint32_t)hook::pattern("8B 44 24 04 53 8B 5C 24 18 55 8B").count(1).get(0).get<uint32_t>(0);
        pattern = hook::pattern("E8 ? ? ? ?");
        for (size_t i = 0, j = 1; i < pattern.size(); ++i)
        {
            auto addr = pattern.get(i).get<uint32_t>(0);
            auto dest = injector::GetBranchDestination(addr, true).as_int();
            if (dest == sub_563BF0)
            {
                j++;

                if (j == 33 || j == 71 || j == 66 || j == 70) //menu and save menu backgrounds, 1 -> 0x4053C8... http://pastebin.com/Hv6TdTLh
                    continue;

                if (
                    (j >= 44 && j <= 49) || //intro overlay
                    (j >= 56 && j <= 65 && j != 64) //DOF/blur overlay
                    )
                {
                    hb_563BF0.fun = injector::MakeCALL(pattern.get(i).get<uint32_t>(0), sub_563BF0_hook, true).get();
                    continue;
                }

                if (j >= 64) //blur
                {
                    hb_563BF0.fun = injector::MakeCALL(pattern.get(i).get<uint32_t>(0), sub_563BF0_hook2, true).get();
                    continue;
                }

                hbOverlays.fun = injector::MakeCALL(pattern.get(i).get<uint32_t>(0), OverlaysHook, true).get();
            }
        }

        //Cutscene Borders
        static float fBorderWidth = 4096.0f;
        pattern = hook::pattern("DB 05 ? ? ? ? D9 5C 24 08 DB 05 ? ? ? ? D9 5C 24 04 DB 05 ? ? ? ? D9 1C 24"); //0x4F4926
        injector::WriteMemory(pattern.count(2).get(0).get<uint32_t>(2), &fBorderWidth, true);
        injector::WriteMemory(pattern.count(2).get(1).get<uint32_t>(2), &fBorderWidth, true);
        static float fBorderPosX = -2048.0f;
        injector::WriteMemory(pattern.count(2).get(0).get<uint32_t>(22), &fBorderPosX, true);
        injector::WriteMemory(pattern.count(2).get(1).get<uint32_t>(22), &fBorderPosX, true);

        //Map Zoom
        static float fMapZoom = (0.5f / ((4.0f / 3.0f) / (Screen.fAspectRatio)));
        pattern = hook::pattern("D8 0D ? ? ? ? 51 52 6A 00 D9 5C"); //0x0051D6DB
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(2), &fMapZoom, true);

        //Film Effect (loading animation & bathroom hole)
        static float fFilmEffectWidth = 0.1f * ((4.0f / 3.0f) / (Screen.fAspectRatio));
        pattern = hook::pattern("D8 0D ? ? ? ? D8 44 24 14 D9 1C 24 E8 ? ? ? ? 89 44 24 30"); //0x0056807F
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(2), &fFilmEffectWidth, true);
        pattern = hook::pattern("D8 0D ? ? ? ? 8B 44 24 38 89 44 24 34 83 C4 28"); //0x005680F3 
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(2), &fFilmEffectWidth, true);
        pattern = hook::pattern("D8 0D ? ? ? ? D8 44 24 14 D9 1C 24 E8 ? ? ? ? 89 44 24 38"); //0x00568193 
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(2), &fFilmEffectWidth, true);
        pattern = hook::pattern("D8 0D ? ? ? ? 8B 4C 24 38 83 C4 28 89 4C 24 0C D8 44 24 04"); //0x00568207 
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(2), &fFilmEffectWidth, true);

        static float fFilmEffectPos = 0.0f - ((480.0f * Screen.fAspectRatio) - 640.0f) / 2.0f;
        pattern = hook::pattern("C7 44 24 0C 00 00 00 00 C7 44 24 04 00 00 00 00 DF E0"); //0x00567FF8 
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(4), &fFilmEffectPos, true);
        //injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(12), &fFilmEffectPos, true);

        //blood stains
        pattern = hook::pattern("50 51 52 C6 05 ? ? ? ? 01 E8"); //0x565AEC
        injector::MakeNOP(pattern.get_first(10), 5, true);

        //Blur Restoration
        static int32_t n640 = static_cast<int32_t>(round(((640.0f - (640.0f / Screen.fHudScale)) * 8.0f) + (640.0f / Screen.fHudScale)));
        pattern = hook::pattern("B8 80 02 00 00 DB 44 24 34 99 F7 FE"); //0x566A79
        injector::WriteMemory(pattern.get_first(1), n640, true);
    }

    if (bDisableCutsceneBorders)
    {
        static uint32_t nOff = 0;
        pattern = hook::pattern("A1 ? ? ? ? 85 C0 74 ? 6A 02 68"); //0x4F4A0A
        injector::WriteMemory(pattern.count(2).get(0).get<uint32_t>(1), &nOff, true);
        injector::WriteMemory(pattern.count(2).get(1).get<uint32_t>(1), &nOff, true);
        //injector::WriteMemory(0x565053+1, 2048 - 48, true); //borders pos
    }

    if (bIncreaseBackgroundRes)
    {
        pattern = hook::pattern("B8 ? ? ? ? 89 4C 24 28 8B 0D ? ? ? ? 89 44 24 2C"); //0x403320
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(1), Screen.Width, true);
        pattern = hook::pattern("68 ? ? ? ? 68 ? ? ? ? 51 E8 ? ? ? ? 8B 15 ? ? ? ? 83 C4 50"); //0x40362E
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(1), Screen.Width, true);
        injector::WriteMemory(pattern.count(1).get(0).get<uint32_t>(6), Screen.Width, true);

        pattern = hook::pattern("C7 05 ? ? ? ? ? ? ? ? C7 05 ? ? ? ? ? ? ? ? C7 05 ? ? ? ? ? ? ? ? C7 05 ? ? ? ? ? ? ? ? 89 35"); //0055A699
        injector::WriteMemory<float>(pattern.count(6).get(3).get<uint32_t>(0x06), Screen.fWidth - 0.5f, true);
        injector::WriteMemory<float>(pattern.count(6).get(3).get<uint32_t>(0x52), Screen.fWidth - 0.5f, true);
        injector::WriteMemory<float>(pattern.count(6).get(3).get<uint32_t>(0x8A), Screen.fWidth - 0.5f, true);
        injector::WriteMemory<float>(pattern.count(6).get(3).get<uint32_t>(0x94), Screen.fWidth - 0.5f, true);
    }

    if (bCutsceneFrameRateFix)
    {
        pattern = hook::pattern("0F 94 C0 A3 ? ? ? ? EB ? C3"); //0x004EFA85
        injector::WriteMemory<uint8_t>(pattern.count(1).get(0).get<uint32_t>(1), 0x95, true);
    }

    if (bDisableCheckSpec)
    {
        pattern = hook::pattern("8B 15 ? ? ? ? A1 ? ? ? ? 8B 0D ? ? ? ? 89 17 66"); //0x00414688 
        injector::MakeNOP(pattern.count(1).get(0).get<uint32_t>(0), 6, true);
    }

    if (bDisableRegistryDependency)
    {
        auto RegIATpat = hook::pattern("FF 15 ? ? ? ? 8B 44 24 00 50");
        if (RegIATpat.size() > 0)
        {
            RegistryWrapper("KONAMI", "");
            RegistryWrapper::AddPathWriter("Install Path", "Movie Install");
            uintptr_t* RegIAT = *RegIATpat.count(1).get(0).get<uintptr_t*>(2); //0x413D67
            injector::WriteMemory(&RegIAT[0], RegQueryValueExA, true);
            injector::WriteMemory(&RegIAT[1], RegOpenKeyA, true);
            injector::WriteMemory(&RegIAT[2], RegSetValueExA, true);
            injector::WriteMemory(&RegIAT[3], RegDeleteValueA, true);
            injector::WriteMemory(&RegIAT[4], RegCloseKey, true);
        }
    }

    if (bDisableSafeMode)
    {
        pattern = hook::pattern("83 C8 FF 83 C4 10 C3"); //00413E53
        injector::MakeNOP(pattern.get_first(-2), 2, true);
    }

    if (bSkipIntro)
    {
        pattern = hook::pattern("A1 ? ? ? ? 3B C6 0F 84 ? ? ? ? 83 F8 01"); //415180
        static auto dword_107BFE0 = *pattern.get_first<uint32_t*>(1);
        struct GameStateHook
        {
            void operator()(injector::reg_pack& regs)
            {
                static bool once = false;
                if (!once)
                    *dword_107BFE0 = 3;
                regs.eax = *dword_107BFE0;
                once = true;
            }
        }; injector::MakeInline<GameStateHook>(pattern.get_first(0));
    }

    if (bBrightnessFix)
    {
        static constexpr auto fContrastScale = 0.0075f;
        static constexpr auto fBrightnessScale = 0.003875f;
        static constexpr auto gamma = 0x000A0A0A;

        pattern = hook::pattern("D8 0D ? ? ? ? DB 05 ? ? ? ? D8 0D ? ? ? ? 74 10 DD D8 DD D8");
        injector::WriteMemory(pattern.get_first(2), &fContrastScale, true);    // 55A17E
        injector::WriteMemory(pattern.get_first(14), &fBrightnessScale, true); // 55A18A

        pattern = hook::pattern("68 ? ? ? ? C7 05 ? ? ? ? ? ? ? ? E8 ? ? ? ? 8B 44 24 1C");
        injector::WriteMemory(pattern.get_first(1), gamma, true);  // 5226A9
        injector::WriteMemory(pattern.get_first(11), gamma, true); // 5226AE

        pattern = hook::pattern("BE ? ? ? ? 8D 7C 24 0C F3 A5");
        injector::WriteMemory(*pattern.get_first<uint32_t>(1) + 0x1C, gamma, true); // 5C5B10

        pattern = hook::pattern("83 FF 08 7D 2A 47 EB 1A");
        injector::WriteMemory<uint8_t>(pattern.get_first<uint32_t>(2), 0x05, true); // 5222D2
    }
}