From bf08a40d1a2da41a729ab2c7e1bd5c6a1cb98689 Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 2 Apr 2018 21:01:11 +0200 Subject: [PATCH] Updated MemoryMgr --- SilentPatch/MemoryMgr.h | 31 ++++++++++++++++++++----------- SilentPatchSA/SilentPatchSA.cpp | 4 +--- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/SilentPatch/MemoryMgr.h b/SilentPatch/MemoryMgr.h index b637f29..a07e87b 100644 --- a/SilentPatch/MemoryMgr.h +++ b/SilentPatch/MemoryMgr.h @@ -490,17 +490,18 @@ namespace Memory } while ( --count != 0 ); } #endif - template - inline void InjectHook(AT address, HT hook) + template + inline void InjectHook(AT address, Func hook) { - intptr_t dwHook; - _asm + union member_cast { - mov eax, hook - mov dwHook, eax - } + intptr_t addr; + Func funcPtr; + } cast; + static_assert( sizeof(cast.addr) == sizeof(cast.funcPtr), "member_cast failure!" ); - *(ptrdiff_t*)((intptr_t)address + 1) = dwHook - (intptr_t)address - 5; + cast.funcPtr = hook; + *(ptrdiff_t*)((intptr_t)address + 1) = cast.addr - (intptr_t)address - 5; } template @@ -521,7 +522,15 @@ namespace Memory template inline void ReadCall(AT address, Func& func) { - func = Func(*(ptrdiff_t*)((intptr_t)address+1) + (intptr_t)address + 5); + union member_cast + { + intptr_t addr; + Func funcPtr; + } cast; + static_assert( sizeof(cast.addr) == sizeof(cast.funcPtr), "member_cast failure!" ); + + cast.addr = *(ptrdiff_t*)((intptr_t)address+1) + (intptr_t)address + 5; + func = cast.funcPtr; } template @@ -643,9 +652,9 @@ namespace Memory { DWORD dwProtect[2]; - VirtualProtect((void*)((DWORD)address + 1), 4, PAGE_EXECUTE_READWRITE, &dwProtect[0]); + VirtualProtect((void*)((DWORD_PTR)address + 1), 4, PAGE_EXECUTE_READWRITE, &dwProtect[0]); Memory::InjectHook( address, hook ); - VirtualProtect((void*)((DWORD)address + 1), 4, dwProtect[0], &dwProtect[1]); + VirtualProtect((void*)((DWORD_PTR)address + 1), 4, dwProtect[0], &dwProtect[1]); } template diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 83e19aa..b436c5b 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -3456,9 +3456,7 @@ void Patch_SA_10() // Fixed animations for boats - void* vehiclePreRender; - ReadCall( 0x6F119E, vehiclePreRender ); - CVehicle::orgVehiclePreRender = *(decltype(CVehicle::orgVehiclePreRender)*)(&vehiclePreRender); + ReadCall( 0x6F119E, CVehicle::orgVehiclePreRender ); InjectHook( 0x6F119E, &CBoat::PreRender_SilentPatch );