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 );