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 ); }
#endif
template<typename AT, typename HT>
inline void InjectHook(AT address, HT hook)
template<typename AT, typename Func>
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<typename AT, typename HT>
@ -521,7 +522,15 @@ namespace Memory
template<typename Func, typename AT>
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>
@ -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<typename AT, typename HT>

View file

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