Decreased keyboard input latency - III, VC, SA 1.0/newsteam

This commit is contained in:
Silent 2018-03-28 21:23:16 +02:00
parent b95f77224f
commit 2614f4d1b0
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
3 changed files with 127 additions and 0 deletions

View File

@ -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<void*>( 1 );
OldKeyState = *updatePads.get<void*>( 5 + 1 );
TempKeyState = *updatePads.get<void*>( 0x244 + 1 );
ReadCall( simButtonCheckers, orgClearSimButtonPressCheckers );
InjectHook( simButtonCheckers, ClearSimButtonPressCheckers );
InjectHook( updatePads.get<void>( 10 ), jmpDest, PATCH_JUMP );
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)

View File

@ -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<void*>( 10 + 1 );
OldKeyState = *updatePads.get<void*>( 15 + 1 );
TempKeyState = *updatePads.get<void*>( 27 + 1 );
objSize = *updatePads.get<uint32_t>( 5 + 1 ) * 4;
ReadCall( updatePads.get<void>( -44 ), orgClearSimButtonPressCheckers );
InjectHook( updatePads.get<void>( -44 ), ClearSimButtonPressCheckers );
Nop( updatePads.get<void>( 20 ), 2 );
Nop( updatePads.get<void>( 37 ), 2 );
}
}

View File

@ -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<void*>( 0x27 + 1 );
OldKeyState = *updatePads.get<void*>( 4 + 1 );
TempKeyState = *updatePads.get<void*>( 0x270 + 1 );
ReadCall( simButtonCheckers, orgClearSimButtonPressCheckers );
InjectHook( simButtonCheckers, ClearSimButtonPressCheckers );
InjectHook( updatePads.get<void>( 9 ), jmpDest, PATCH_JUMP );
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)