Updated MemoryMgr

This commit is contained in:
Silent 2018-04-02 21:01:11 +02:00
parent 1a8bb9dd6c
commit bf08a40d1a
No known key found for this signature in database
GPG key ID: AE53149BB0C45AF1
2 changed files with 21 additions and 14 deletions

View file

@ -490,17 +490,18 @@ namespace Memory
} while ( --count != 0 ); } } while ( --count != 0 ); }
#endif #endif
template<typename AT, typename HT> template<typename AT, typename Func>
inline void InjectHook(AT address, HT hook) inline void InjectHook(AT address, Func hook)
{ {
intptr_t dwHook; union member_cast
_asm
{ {
mov eax, hook intptr_t addr;
mov dwHook, eax 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<typename AT, typename HT> template<typename AT, typename HT>
@ -521,7 +522,15 @@ namespace Memory
template<typename Func, typename AT> template<typename Func, typename AT>
inline void ReadCall(AT address, Func& func) 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<typename AT> template<typename AT>
@ -643,9 +652,9 @@ namespace Memory
{ {
DWORD dwProtect[2]; 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 ); 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<typename AT, typename HT> template<typename AT, typename HT>

View file

@ -3456,9 +3456,7 @@ void Patch_SA_10()
// Fixed animations for boats // Fixed animations for boats
void* vehiclePreRender; ReadCall( 0x6F119E, CVehicle::orgVehiclePreRender );
ReadCall( 0x6F119E, vehiclePreRender );
CVehicle::orgVehiclePreRender = *(decltype(CVehicle::orgVehiclePreRender)*)(&vehiclePreRender);
InjectHook( 0x6F119E, &CBoat::PreRender_SilentPatch ); InjectHook( 0x6F119E, &CBoat::PreRender_SilentPatch );