From 2614f4d1b0fb429133bb31eae8280b6a7a57db77 Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 28 Mar 2018 21:23:16 +0200 Subject: [PATCH] Decreased keyboard input latency - III, VC, SA 1.0/newsteam --- SilentPatchIII/SilentPatchIII.cpp | 37 +++++++++++++++++++++ SilentPatchSA/SilentPatchSA.cpp | 54 +++++++++++++++++++++++++++++++ SilentPatchVC/SilentPatchVC.cpp | 36 +++++++++++++++++++++ 3 files changed, 127 insertions(+) diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index 428b079..fcd91ba 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -361,6 +361,25 @@ static void __fastcall GiveWeapon_SP( void* ped, void*, unsigned int weapon, uns orgGiveWeapon( ped, weapon, ammo ); } + +// ============= Keyboard latency input fix ============= +namespace KeyboardInputFix +{ + static void* NewKeyState; + static void* OldKeyState; + static void* TempKeyState; + static constexpr size_t objSize = 0x270; + static void (__fastcall *orgClearSimButtonPressCheckers)(void*); + void __fastcall ClearSimButtonPressCheckers(void* pThis) + { + memcpy( OldKeyState, NewKeyState, objSize ); + memcpy( NewKeyState, TempKeyState, objSize ); + + orgClearSimButtonPressCheckers(pThis); + } +} + + void Patch_III_10(const RECT& desktop) { using namespace Memory; @@ -859,6 +878,24 @@ void Patch_III_Common() give_weapon = get_pattern( "89 C7 A1 ? ? ? ? 55 89 F9 50", 11 ); InjectHook( give_weapon, GiveWeapon_SP ); } + + + // Decreased keyboard input latency + { + using namespace KeyboardInputFix; + + auto updatePads = pattern( "BE ? ? ? ? BF ? ? ? ? A5" ).get_one(); + void* jmpDest = get_pattern( "66 A3 ? ? ? ? 5F", 6 ); + void* simButtonCheckers = get_pattern( "84 DB 74 11 6A 00", -0x24 ); + + NewKeyState = *updatePads.get( 1 ); + OldKeyState = *updatePads.get( 5 + 1 ); + TempKeyState = *updatePads.get( 0x244 + 1 ); + + ReadCall( simButtonCheckers, orgClearSimButtonPressCheckers ); + InjectHook( simButtonCheckers, ClearSimButtonPressCheckers ); + InjectHook( updatePads.get( 10 ), jmpDest, PATCH_JUMP ); + } } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 709ff7d..83e19aa 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -1413,6 +1413,24 @@ namespace BicycleFire } +// ============= Keyboard latency input fix ============= +namespace KeyboardInputFix +{ + static void* NewKeyState; + static void* OldKeyState; + static void* TempKeyState; + static size_t objSize; + static void (__fastcall *orgClearSimButtonPressCheckers)(void*); + void __fastcall ClearSimButtonPressCheckers(void* pThis) + { + memcpy( OldKeyState, NewKeyState, objSize ); + memcpy( NewKeyState, TempKeyState, objSize ); + + orgClearSimButtonPressCheckers(pThis); + } +} + + #ifndef NDEBUG // ============= QPC spoof for verifying high timer issues ============= @@ -3552,6 +3570,22 @@ void Patch_SA_10() CFireManager::orgStartFire = *(decltype(CFireManager::orgStartFire)*)&func; InjectHook( 0x53A9B7, &CFireManager::StartFire_NullEntityCheck ); } + + + // Decreased keyboard input latency + { + using namespace KeyboardInputFix; + + NewKeyState = *(void**)( 0x541E21 + 1 ); + OldKeyState = *(void**)( 0x541E26 + 1 ); + TempKeyState = *(void**)( 0x541E32 + 1 ); + objSize = *(uint32_t*)( 0x541E1C + 1 ) * 4; + + ReadCall( 0x541DEB, orgClearSimButtonPressCheckers ); + InjectHook( 0x541DEB, ClearSimButtonPressCheckers ); + Nop( 0x541E2B, 2 ); + Nop( 0x541E3C, 2 ); + } } void Patch_SA_11() @@ -4824,6 +4858,26 @@ void Patch_SA_NewSteam_Common() ReadCall( drawScriptSprites, orgDrawScriptSpritesAndRectangles ); InjectHook( drawScriptSprites, DrawScriptSpritesAndRectangles ); } + + + // TODO: OTHER FIXES NEED TO GO HERE + + // Decreased keyboard input latency + { + using namespace KeyboardInputFix; + + auto updatePads = pattern( "E8 ? ? ? ? B9 ? ? ? ? BE" ).get_one(); // 0x552DB7 + + NewKeyState = *updatePads.get( 10 + 1 ); + OldKeyState = *updatePads.get( 15 + 1 ); + TempKeyState = *updatePads.get( 27 + 1 ); + objSize = *updatePads.get( 5 + 1 ) * 4; + + ReadCall( updatePads.get( -44 ), orgClearSimButtonPressCheckers ); + InjectHook( updatePads.get( -44 ), ClearSimButtonPressCheckers ); + Nop( updatePads.get( 20 ), 2 ); + Nop( updatePads.get( 37 ), 2 ); + } } diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index 2dc54a7..bc9edfa 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -232,6 +232,24 @@ static void __fastcall GiveWeapon_SP( void* ped, void*, unsigned int weapon, uns orgGiveWeapon( ped, weapon, ammo, flag ); } + +// ============= Keyboard latency input fix ============= +namespace KeyboardInputFix +{ + static void* NewKeyState; + static void* OldKeyState; + static void* TempKeyState; + static constexpr size_t objSize = 0x270; + static void (__fastcall *orgClearSimButtonPressCheckers)(void*); + void __fastcall ClearSimButtonPressCheckers(void* pThis) + { + memcpy( OldKeyState, NewKeyState, objSize ); + memcpy( NewKeyState, TempKeyState, objSize ); + + orgClearSimButtonPressCheckers(pThis); + } +} + void Patch_VC_10(const RECT& desktop) { using namespace Memory; @@ -685,6 +703,24 @@ void Patch_VC_Common() InjectHook( createInstance, CreateInstance_BikeFix, PATCH_CALL ); } + + // Decreased keyboard input latency + { + using namespace KeyboardInputFix; + + auto updatePads = pattern( "66 8B 42 1A" ).get_one(); + void* jmpDest = get_pattern( "66 A3 ? ? ? ? 5F", 6 ); + void* simButtonCheckers = get_pattern( "56 57 B3 01", 0x16 ); + + NewKeyState = *updatePads.get( 0x27 + 1 ); + OldKeyState = *updatePads.get( 4 + 1 ); + TempKeyState = *updatePads.get( 0x270 + 1 ); + + ReadCall( simButtonCheckers, orgClearSimButtonPressCheckers ); + InjectHook( simButtonCheckers, ClearSimButtonPressCheckers ); + InjectHook( updatePads.get( 9 ), jmpDest, PATCH_JUMP ); + } + } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)