From 24800b17e29e1cf087b10a436c84f76ce74f37e9 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 8 Nov 2014 12:36:14 +0100 Subject: [PATCH] Fixed widescreen patch for 1.0, 3.0 and newsteam --- SAFix/SilentPatchSA.cpp | 17 ++++++++++------- SilentPatch/MemoryMgr.h | 28 +++++++++++++++++----------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/SAFix/SilentPatchSA.cpp b/SAFix/SilentPatchSA.cpp index 9e16d3d..f6230c0 100644 --- a/SAFix/SilentPatchSA.cpp +++ b/SAFix/SilentPatchSA.cpp @@ -2328,7 +2328,8 @@ void Patch_SA_10() #endif // Unlocked widescreen resolutions - Patch(0x745B71, 0x9090687D); + //Patch(0x745B71, 0x9090687D); + Patch(0x745B81, 0x9090587D); Patch(0x74596C, 0x9090127D); Nop(0x745970, 2); Nop(0x745B75, 2); @@ -2797,7 +2798,8 @@ void Patch_SA_Steam() Patch(0x734DF0, &dSunMult); // Unlocked widescreen resolutions - Patch(0x77F9F0, 0x6E7d); + //Patch(0x77F9F0, 0x6E7D); + Patch(0x77F9FC, 0x627D); Patch(0x77F80B, 0x9090127D); Nop(0x77F80F, 2); Nop(0x77F880, 2); @@ -2957,7 +2959,8 @@ void Patch_SA_NewSteam() Patch(0x53EC4A, 6); // Unlocked widescreen resolutions - Patch(0x779BAD, 0x607D); + //Patch(0x779BAD, 0x607D); + Patch(0x779BB8, 0x557D); // TODO: Do the rest // Disable re-initialization of DirectInput mouse device by the game @@ -2988,11 +2991,11 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { hDLLModule = hinstDLL; - if ( *(DWORD*)(GetModule()+0x458D21) == 0x3539F633) Patch_SA_NewSteam(); + if (*(DWORD*)DynBaseAddress(0x82457C) == 0x94BF || *(DWORD*)DynBaseAddress(0x8245BC) == 0x94BF) Patch_SA_10(); + else if (*(DWORD*)DynBaseAddress(0x8252FC) == 0x94BF || *(DWORD*)DynBaseAddress(0x82533C) == 0x94BF) Patch_SA_11(); + else if (*(DWORD*)DynBaseAddress(0x85EC4A) == 0x94BF) Patch_SA_Steam(); - 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 if ( *(DWORD*)DynBaseAddress(0x858D21) == 0x3539F633) Patch_SA_NewSteam(); else return FALSE; } diff --git a/SilentPatch/MemoryMgr.h b/SilentPatch/MemoryMgr.h index ff4dd00..0459491 100644 --- a/SilentPatch/MemoryMgr.h +++ b/SilentPatch/MemoryMgr.h @@ -41,6 +41,12 @@ inline ptrdiff_t GetModule() return (ptrdiff_t)hModule; } +template +inline AT DynBaseAddress(AT address) +{ + return GetModule() - 0x400000 + address; +} + #if defined SILENTPATCH_III_VER // This function initially detects III version then chooses the address basing on game version @@ -110,33 +116,33 @@ inline T AddressByVersion(DWORD address10, DWORD address11, DWORD addressSteam) if ( *bVer == -1 ) { - if ( *(DWORD*)(GetModule()+0x458D21) == 0x3539F633 ) + if ( *(DWORD*)DynBaseAddress(0x858D21) == 0x3539F633 ) { *bVer = 3; *bEuropean = false; } - else if ( *(DWORD*)0x82457C == 0x94BF ) + else if ( *(DWORD*)DynBaseAddress(0x82457C) == 0x94BF ) { *bVer = 0; *bEuropean = false; } - else if ( *(DWORD*)0x8245BC == 0x94BF ) + else if ( *(DWORD*)DynBaseAddress(0x8245BC) == 0x94BF ) { *bVer = 0; *bEuropean = true; } - else if ( *(DWORD*)0x8252FC == 0x94BF ) + else if ( *(DWORD*)DynBaseAddress(0x8252FC) == 0x94BF ) { *bVer = 1; *bEuropean = false; } - else if ( *(DWORD*)0x82533C == 0x94BF ) + else if ( *(DWORD*)DynBaseAddress(0x82533C) == 0x94BF ) { *bVer = 1; *bEuropean = true; } - else if (*(DWORD*)0x85EC4A == 0x94BF ) + else if (*(DWORD*)DynBaseAddress(0x85EC4A) == 0x94BF ) { *bVer = 2; *bEuropean = false; @@ -288,7 +294,7 @@ namespace Memory break; } - *(DWORD*)((DWORD)address + 1) = dwHook - (DWORD)address - 5; + *(ptrdiff_t*)((DWORD)address + 1) = dwHook - (DWORD)address - 5; } }; @@ -337,7 +343,7 @@ namespace MemoryVP mov dwHook, eax } - *(DWORD*)((DWORD)address + 1) = (DWORD)dwHook - (DWORD)address - 5; + *(ptrdiff_t*)((DWORD)address + 1) = (DWORD)dwHook - (DWORD)address - 5; if ( nType == PATCH_NOTHING ) VirtualProtect((void*)((DWORD)address + 1), 4, dwProtect[0], &dwProtect[1]); else @@ -349,19 +355,19 @@ namespace MemoryVP template inline void Patch(AT address, T value) { - MemoryVP::Patch(GetModule() - 0x400000 + address, value); + MemoryVP::Patch(DynBaseAddress(address), value); } template inline void Nop(AT address, unsigned int nCount) { - MemoryVP::Nop(GetModule() - 0x400000 + address, nCount); + MemoryVP::Nop(DynBaseAddress(address), nCount); } template inline void InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) { - MemoryVP::InjectHook(GetModule() - 0x400000 + address, hook, nType); + MemoryVP::InjectHook(DynBaseAddress(address), hook, nType); } }; };