From f6ba6be75a3198fc514697e8dd3b43b25af20e7c Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 17 Apr 2024 23:31:03 +0200 Subject: [PATCH] Fixed IS_PLAYER_TARGETTING_CHAR incorrectly detecting targetting in Classic controls when the player is not aiming Contributed by Wesser Fixes #10 --- SilentPatchVC/SilentPatchVC.cpp | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index e6527ef..c071d4e 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -647,6 +647,42 @@ namespace PickupEffectsFixes } } + +// ============= Fixed IS_PLAYER_TARGETTING_CHAR incorrectly detecting targetting in Classic controls ============= +// ============= when the player is not aiming ============= +// ============= By Wesser ============= +namespace IsPlayerTargettingCharFix +{ + static bool* bUseMouse3rdPerson; + static void* TheCamera; + static bool (__fastcall* Using1stPersonWeaponMode)(); + + __declspec(naked) static void IsPlayerTargettingChar_ExtraChecks() + { + // After this extra block of code, there is a jz Return, so set ZF to 0 here if this path is to be entered + _asm + { + test bl, bl + jnz ReturnToUpdateCompareFlag + mov eax, [bUseMouse3rdPerson] + cmp byte ptr [eax], 0 + jne CmpAndReturn + mov ecx, [TheCamera] + call [Using1stPersonWeaponMode] + test al, al + jz ReturnToUpdateCompareFlag + + CmpAndReturn: + cmp byte ptr [esp+11Ch-10Ch], 0 + retn + + ReturnToUpdateCompareFlag: + xor al, al + retn + } + } +} + void InjectDelayedPatches_VC_Common( bool bHasDebugMenu, const wchar_t* wcModulePath ) { using namespace Memory; @@ -1479,6 +1515,28 @@ void Patch_VC_Common() Patch(fireInstantHit.get(15), { 0xD9, 0xEE, 0x90, 0x90 }); Patch(fireInstantHit.get(30), { 0xD9, 0xEE, 0x90, 0x90 }); } + + + // Fixed IS_PLAYER_TARGETTING_CHAR incorrectly detecting targetting in Classic controls + // when the player is not aiming + // By Wesser + { + using namespace IsPlayerTargettingCharFix; + + auto isPlayerTargettingChar = pattern("83 7C 24 ? ? A3 ? ? ? ? 0F 84").get_one(); + auto using1stPersonWeaponMode = static_cast(get_pattern("66 83 F8 07 74 18", -7)); + bool* useMouse3rdPerson = *get_pattern("80 3D ? ? ? ? ? 75 09 66 C7 05 ? ? ? ? ? ? 8B 35", 2); + void* theCamera = *get_pattern("B9 ? ? ? ? 31 DB E8", 1); + + Using1stPersonWeaponMode = using1stPersonWeaponMode; + bUseMouse3rdPerson = useMouse3rdPerson; + TheCamera = theCamera; + + // Move mov ds:dword_784030, eax one instruction earlier so we don't need + // to include it in the patched routine + memmove(isPlayerTargettingChar.get(), isPlayerTargettingChar.get(5), 5); + InjectHook(isPlayerTargettingChar.get(5), IsPlayerTargettingChar_ExtraChecks, HookType::Call); + } } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)