Timers fix for III

This commit is contained in:
Silent 2017-09-11 16:41:40 +02:00
parent 94fa223e8c
commit 832828ac8f
2 changed files with 41 additions and 63 deletions

View File

@ -3,16 +3,30 @@
#include "Patterns.h"
int& CTimer::m_snTimeInMilliseconds = **hook::get_pattern<int*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", -20 + 1 );
#if _GTA_III
float& CTimer::ms_fTimeScale = **hook::get_pattern<float*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0x66 + 2 );
float& CTimer::ms_fTimeStep = **hook::get_pattern<float*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0xE1 + 2 );
bool& CTimer::m_UserPause = **hook::get_pattern<bool*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0xBE + 2 );
bool& CTimer::m_CodePause = **hook::get_pattern<bool*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0xD8 + 2 );
int& CTimer::m_snTimeInMillisecondsNonClipped = **hook::get_pattern<int*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0x129 + 1 );
int& CTimer::m_snTimeInMillisecondsPauseMode = **hook::get_pattern<int*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0x8E + 1 );
#elif _GTA_VC
float& CTimer::ms_fTimeScale = **hook::get_pattern<float*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0x70 + 2 );
float& CTimer::ms_fTimeStep = **hook::get_pattern<float*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0xF3 + 2 );
bool& CTimer::m_UserPause = **hook::get_pattern<bool*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0x4A + 2 );
bool& CTimer::m_CodePause = **hook::get_pattern<bool*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0x67 + 2 );
int& CTimer::m_snTimeInMilliseconds = **hook::get_pattern<int*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0x102 + 1 );
int& CTimer::m_snTimeInMillisecondsNonClipped = **hook::get_pattern<int*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0x13B + 1 );
int& CTimer::m_snTimeInMillisecondsPauseMode = **hook::get_pattern<int*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 0x9C + 1 );
static uint32_t& timerFrequency = **hook::get_pattern<uint32_t*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", -7 );
static LARGE_INTEGER& prevTimer = **hook::get_pattern<LARGE_INTEGER*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 64 );
#endif
static uint32_t& timerFrequency = **hook::get_pattern<uint32_t*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", -8 + 1 );
static LARGE_INTEGER& prevTimer = **hook::get_pattern<LARGE_INTEGER*>( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08", 62 + 2 );
void CTimer::Update_SilentPatch()
@ -21,7 +35,12 @@ void CTimer::Update_SilentPatch()
QueryPerformanceCounter( &perfCount );
double diff = double(perfCount.QuadPart - prevTimer.QuadPart);
if ( !m_UserPause && !m_CodePause ) diff *= ms_fTimeScale;
#if _GTA_VC
if ( !m_UserPause && !m_CodePause )
#endif
{
diff *= ms_fTimeScale;
}
prevTimer = perfCount;

View File

@ -2,6 +2,7 @@
#include "General.h"
#include "Timer.h"
#include "Patterns.h"
struct PsGlobalType
{
@ -353,17 +354,6 @@ void Patch_III_10(const RECT& desktop)
HeadlightsFix_JumpBack = (void*)0x5382F2;
SubtitlesShadowFix_JumpBack = (void*)0x500D32;
CTimer::ms_fTimeScale = *(float**)0x43F73F;
CTimer::ms_fTimeStep = *(float**)0x41428E;
CTimer::ms_fTimeStepNotClipped = *(float**)0x404F9B;
CTimer::m_UserPause = *(bool**)0x4076E9;
CTimer::m_CodePause = *(bool**)0x4076F2;
CTimer::m_snTimeInMilliseconds = *(int**)0x40B3B8;
CTimer::m_snPreviousTimeInMilliseconds = *(int**)0x41543D;
CTimer::m_snTimeInMillisecondsNonClipped = *(int**)0x4ACEA2;
CTimer::m_snTimeInMillisecondsPauseMode = *(int**)0x47A780;
CTimer::m_FrameCounter = *(unsigned int**)0x4AD2F3;
Patch<BYTE>(0x490F83, 1);
Patch<BYTE>(0x43177D, 16);
@ -380,14 +370,6 @@ void Patch_III_10(const RECT& desktop)
InjectHook(0x4C4004, PurpleNinesGlitchFix, PATCH_JUMP);
InjectHook(0x4ACE60, CTimer::Initialise, PATCH_JUMP);
InjectHook(0x4AD310, CTimer::Suspend, PATCH_JUMP);
InjectHook(0x4AD370, CTimer::Resume, PATCH_JUMP);
InjectHook(0x4AD410, CTimer::GetCyclesPerFrame, PATCH_JUMP);
InjectHook(0x4AD3F0, CTimer::GetCyclesPerMillisecond, PATCH_JUMP);
InjectHook(0x4ACF70, CTimer::Update, PATCH_JUMP);
InjectHook(0x590D9F, CTimer::RecoverFromSave);
InjectHook(0x4A5870, ShowRadarTrace, PATCH_JUMP);
InjectHook(0x4209A7, SetScaleProperly);
InjectHook(0x420A1F, SetScaleProperly);
@ -536,17 +518,6 @@ void Patch_III_11(const RECT& desktop)
HeadlightsFix_JumpBack = (void*)0x538532;
SubtitlesShadowFix_JumpBack = (void*)0x500E12;
CTimer::ms_fTimeScale = *(float**)0x43F73F;
CTimer::ms_fTimeStep = *(float**)0x41428E;
CTimer::ms_fTimeStepNotClipped = *(float**)0x404F9B;
CTimer::m_UserPause = *(bool**)0x4076E9;
CTimer::m_CodePause = *(bool**)0x4076F2;
CTimer::m_snTimeInMilliseconds = *(int**)0x40B3B8;
CTimer::m_snPreviousTimeInMilliseconds = *(int**)0x41543D;
CTimer::m_snTimeInMillisecondsNonClipped = *(int**)0x4ACF92;
CTimer::m_snTimeInMillisecondsPauseMode = *(int**)0x47A770;
CTimer::m_FrameCounter = *(unsigned int**)0x4AD3E3;
Patch<BYTE>(0x491043, 1);
Patch<BYTE>(0x43177D, 16);
@ -563,14 +534,6 @@ void Patch_III_11(const RECT& desktop)
InjectHook(0x4C40A4, PurpleNinesGlitchFix, PATCH_JUMP);
InjectHook(0x4ACF50, CTimer::Initialise, PATCH_JUMP);
InjectHook(0x4AD400, CTimer::Suspend, PATCH_JUMP);
InjectHook(0x4AD460, CTimer::Resume, PATCH_JUMP);
InjectHook(0x4AD500, CTimer::GetCyclesPerFrame, PATCH_JUMP);
InjectHook(0x4AD4E0, CTimer::GetCyclesPerMillisecond, PATCH_JUMP);
InjectHook(0x4AD060, CTimer::Update, PATCH_JUMP);
InjectHook(0x59105F, CTimer::RecoverFromSave);
InjectHook(0x4A5960, ShowRadarTrace, PATCH_JUMP);
InjectHook(0x4209A7, SetScaleProperly);
InjectHook(0x420A1F, SetScaleProperly);
@ -697,17 +660,6 @@ void Patch_III_Steam(const RECT& desktop)
RsGlobal = *(RsGlobalType**)0x584E72;
SubtitlesShadowFix_JumpBack = (void*)0x500DA2;
CTimer::ms_fTimeScale = *(float**)0x43F73F;
CTimer::ms_fTimeStep = *(float**)0x41428E;
CTimer::ms_fTimeStepNotClipped = *(float**)0x404F9B;
CTimer::m_UserPause = *(bool**)0x4076E9;
CTimer::m_CodePause = *(bool**)0x4076F2;
CTimer::m_snTimeInMilliseconds = *(int**)0x40B3B8;
CTimer::m_snPreviousTimeInMilliseconds = *(int**)0x41543D;
CTimer::m_snTimeInMillisecondsNonClipped = *(int**)0x4ACF22;
CTimer::m_snTimeInMillisecondsPauseMode = *(int**)0x47A770;
CTimer::m_FrameCounter = *(unsigned int**)0x4AD373;
Patch<BYTE>(0x490FD3, 1);
Patch<BYTE>(0x43177D, 16);
@ -721,14 +673,6 @@ void Patch_III_Steam(const RECT& desktop)
InjectHook(0x4C4034, PurpleNinesGlitchFix, PATCH_JUMP);
InjectHook(0x4ACEE0, CTimer::Initialise, PATCH_JUMP);
InjectHook(0x4AD390, CTimer::Suspend, PATCH_JUMP);
InjectHook(0x4AD3F0, CTimer::Resume, PATCH_JUMP);
InjectHook(0x4AD490, CTimer::GetCyclesPerFrame, PATCH_JUMP);
InjectHook(0x4AD470, CTimer::GetCyclesPerMillisecond, PATCH_JUMP);
InjectHook(0x4ACFF0, CTimer::Update, PATCH_JUMP);
InjectHook(0x590F4F, CTimer::RecoverFromSave);
InjectHook(0x4A58F0, ShowRadarTrace, PATCH_JUMP);
InjectHook(0x4209A7, SetScaleProperly);
InjectHook(0x420A1F, SetScaleProperly);
@ -831,6 +775,21 @@ void Patch_III_Steam(const RECT& desktop)
InjectHook(0x4139B2, AutoPilotTimerFix_III, PATCH_JUMP);
}
void Patch_III_Common()
{
using namespace Memory;
using namespace hook;
// New timers fix
{
auto hookPoint = pattern( "83 E4 F8 89 44 24 08 C7 44 24 0C 00 00 00 00 DF 6C 24 08" ).get_one();
auto jmpPoint = get_pattern( "DD D8 E9 37 FF FF FF DD D8" );
InjectHook( hookPoint.get<int>( 0x21 ), CTimer::Update_SilentPatch, PATCH_CALL );
InjectHook( hookPoint.get<int>( 0x21 + 5 ), jmpPoint, PATCH_JUMP );
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(hinstDLL);
@ -842,14 +801,14 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
GetWindowRect(GetDesktopWindow(), &desktop);
sprintf_s(aNoDesktopMode, "Cannot find %dx%dx32 video mode", desktop.right, desktop.bottom);
ScopedUnprotect::Section Protect( (HINSTANCE)0x400000, ".text" );
ScopedUnprotect::Section Protect( GetModuleHandle( nullptr ), ".text" );
if (*(DWORD*)0x5C1E75 == 0xB85548EC) Patch_III_10(desktop);
else if (*(DWORD*)0x5C2135 == 0xB85548EC) Patch_III_11(desktop);
else if (*(DWORD*)0x5C6FD5 == 0xB85548EC) Patch_III_Steam(desktop);
else return TRUE;
CTimer::Initialise();
Patch_III_Common();
HMODULE hDummyHandle;
GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)&DllMain, &hDummyHandle);