diff --git a/SAFix/SilentPatchSA.cpp b/SAFix/SilentPatchSA.cpp index 482fb5f..9e16d3d 100644 --- a/SAFix/SilentPatchSA.cpp +++ b/SAFix/SilentPatchSA.cpp @@ -1201,7 +1201,7 @@ void __declspec(naked) TrailerDoubleRWheelsFix2_Steam() } } -static void* LoadFLAC_JumpBack = AddressByVersion(0x4F3743, *(BYTE*)0x4F3A50 == 0x6A ? 0x4F3BA3 : 0x5B6B81, 0x4FFC3F); +static void* LoadFLAC_JumpBack = AddressByVersion(0x4F3743, *GetVer() == 1 ? (*(BYTE*)0x4F3A50 == 0x6A ? 0x4F3BA3 : 0x5B6B81) : 0, 0x4FFC3F); void __declspec(naked) LoadFLAC() { _asm @@ -2938,6 +2938,47 @@ void Patch_SA_Steam() InjectHook(0x5EDFD9, 0x5EE0FA, PATCH_JUMP); } +void Patch_SA_NewSteam() +{ + using namespace MemoryVP::DynBase; + + // No framedelay + InjectHook(0x54ECC6, GetModule() + 0x14ED0C, PATCH_JUMP); + Patch(0x54ED45, 0x4); + Nop(0x54ED47, 1); + + // Unlock 1.0/1.01 saves loading + Patch(0x5ED3E9, 0xE990); + + // Old .set files working again + static const DWORD dwSetVersion = 6; + Patch(0x59058A, &dwSetVersion); + Patch(0x59086D, 6); + Patch(0x53EC4A, 6); + + // Unlocked widescreen resolutions + Patch(0x779BAD, 0x607D); + // TODO: Do the rest + + // Disable re-initialization of DirectInput mouse device by the game + Patch(0x58A891, 0xEB); + Patch(0x58AA77, 0xEB); + Patch(0x58AB59, 0xEB); + + // Make sure DirectInput mouse device is set non-exclusive (may not be needed?) + Nop(0x77AB3F, 1); + Patch(0x77AB40, 0x01B0); + //Nop(0x77AB3B, 3); + //Nop(0x77AB3F, 3); + + + // Proper aspect ratios + static const float f43 = 4.0f/3.0f, f54 = 5.0f/4.0f, f169 = 16.0f/9.0f; + Patch(0x73424B, &f169); + Patch(0x734267, &f54); + Patch(0x73427A, &f43); +} + BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { @@ -2947,9 +2988,12 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { hDLLModule = hinstDLL; - if (*(DWORD*)0x82457C == 0x94BF || *(DWORD*)0x8245BC == 0x94BF) Patch_SA_10(); + if ( *(DWORD*)(GetModule()+0x458D21) == 0x3539F633) Patch_SA_NewSteam(); + + else if (*(DWORD*)0x82457C == 0x94BF || *(DWORD*)0x8245BC == 0x94BF) Patch_SA_10(); else if (*(DWORD*)0x8252FC == 0x94BF || *(DWORD*)0x82533C == 0x94BF) Patch_SA_11(); else if (*(DWORD*)0x85EC4A == 0x94BF) Patch_SA_Steam(); + else return FALSE; } return TRUE; diff --git a/SilentPatch/MemoryMgr.h b/SilentPatch/MemoryMgr.h index 8ca20c1..ff4dd00 100644 --- a/SilentPatch/MemoryMgr.h +++ b/SilentPatch/MemoryMgr.h @@ -35,6 +35,12 @@ inline void* GetDummy() return &dwDummy; } +inline ptrdiff_t GetModule() +{ + static HMODULE hModule = GetModuleHandle(nullptr); + return (ptrdiff_t)hModule; +} + #if defined SILENTPATCH_III_VER // This function initially detects III version then chooses the address basing on game version @@ -104,7 +110,13 @@ inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam) if ( *bVer == -1 ) { - if ( *(DWORD*)0x82457C == 0x94BF ) + if ( *(DWORD*)(GetModule()+0x458D21) == 0x3539F633 ) + { + *bVer = 3; + *bEuropean = false; + } + + else if ( *(DWORD*)0x82457C == 0x94BF ) { *bVer = 0; *bEuropean = false; @@ -156,6 +168,9 @@ inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam) return (T)GetDummy(); return (T)addressSteam; + case 3: + // TODO: DO + return (T)GetDummy(); default: assert(address10); // Adjust to EU if needed @@ -290,7 +305,6 @@ namespace MemoryVP template inline void Nop(AT address, unsigned int nCount) - // TODO: Finish multibyte nops { DWORD dwProtect[2]; VirtualProtect((void*)address, nCount, PAGE_EXECUTE_READWRITE, &dwProtect[0]); @@ -329,6 +343,27 @@ namespace MemoryVP else VirtualProtect((void*)address, 5, dwProtect[0], &dwProtect[1]); } + + namespace DynBase + { + template + inline void Patch(AT address, T value) + { + MemoryVP::Patch(GetModule() - 0x400000 + address, value); + } + + template + inline void Nop(AT address, unsigned int nCount) + { + MemoryVP::Nop(GetModule() - 0x400000 + address, nCount); + } + + template + inline void InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) + { + MemoryVP::InjectHook(GetModule() - 0x400000 + address, hook, nType); + } + }; }; #endif \ No newline at end of file