SilentPatchSA: Fixup the MSVC inline assembly statements (part 1)

Also clean them up in general
This commit is contained in:
Echo J 2024-11-08 01:02:29 +02:00 committed by Silent
parent 5d90ed55d7
commit 94f967245b

View File

@ -1602,9 +1602,9 @@ namespace FirelaHook
static uintptr_t UpdateMovingCollisionJmp; static uintptr_t UpdateMovingCollisionJmp;
static uintptr_t HydraulicControlJmpBack; static uintptr_t HydraulicControlJmpBack;
void __declspec(naked) TestFirelaAndFlags() __declspec(naked) static void TestFirelaAndFlags()
{ {
__asm _asm
{ {
push ecx // Required in 0x6B1FE4: test cl, cl push ecx // Required in 0x6B1FE4: test cl, cl
mov ecx, esi mov ecx, esi
@ -1613,29 +1613,29 @@ namespace FirelaHook
test al, al test al, al
jnz TestFirelaAndFlags_UpdateMovingCollision jnz TestFirelaAndFlags_UpdateMovingCollision
test [esi].hFlagsLocal, FLAG_HYDRAULICS_INSTALLED test [esi].hFlagsLocal, FLAG_HYDRAULICS_INSTALLED
jmp [HydraulicControlJmpBack] jmp HydraulicControlJmpBack
TestFirelaAndFlags_UpdateMovingCollision: TestFirelaAndFlags_UpdateMovingCollision:
jmp [UpdateMovingCollisionJmp] jmp UpdateMovingCollisionJmp
} }
} }
static uintptr_t FollowCarCamNoMovement; static uintptr_t FollowCarCamNoMovement;
static uintptr_t FollowCarCamJmpBack; static uintptr_t FollowCarCamJmpBack;
void __declspec(naked) CamControlFirela() __declspec(naked) static void CamControlFirela()
{ {
__asm _asm
{ {
mov ecx, edi mov ecx, edi
call CVehicle::HasFirelaLadder call CVehicle::HasFirelaLadder
test al, al test al, al
jnz TestFirelaAndFlags_UpdateMovingCollision jnz TestFirelaAndFlags_UpdateMovingCollision
mov eax, [edi].m_dwVehicleClass mov eax, [edi].m_dwVehicleClass
jmp [FollowCarCamJmpBack] jmp FollowCarCamJmpBack
TestFirelaAndFlags_UpdateMovingCollision: TestFirelaAndFlags_UpdateMovingCollision:
jmp [FollowCarCamNoMovement] jmp FollowCarCamNoMovement
} }
} }
} }
@ -1857,25 +1857,25 @@ namespace TrueInvincibility
static bool isEnabled = false; static bool isEnabled = false;
static uintptr_t WillKillJumpBack; static uintptr_t WillKillJumpBack;
void __declspec(naked) ComputeWillKillPedHook() __declspec(naked) static void ComputeWillKillPedHook()
{ {
_asm _asm
{ {
cmp dword ptr [ebp+0Ch], WEAPONTYPE_LAST_WEAPONTYPE cmp dword ptr [ebp+0xC], WEAPONTYPE_LAST_WEAPONTYPE
jl ComputeWillKillPedHook_DoNotKill jl ComputeWillKillPedHook_DoNotKill
cmp [isEnabled], 0 cmp isEnabled, 0
je ComputeWillKillPedHook_Kill je ComputeWillKillPedHook_Kill
cmp dword ptr [ebp+0Ch], WEAPONTYPE_UZI_DRIVEBY cmp dword ptr [ebp+0xC], WEAPONTYPE_UZI_DRIVEBY
jne ComputeWillKillPedHook_Kill jne ComputeWillKillPedHook_Kill
ComputeWillKillPedHook_DoNotKill: ComputeWillKillPedHook_DoNotKill:
pop esi pop esi
pop ebp pop ebp
pop ebx pop ebx
retn 0Ch ret 0xC
ComputeWillKillPedHook_Kill: ComputeWillKillPedHook_Kill:
jmp [WillKillJumpBack] jmp WillKillJumpBack
} }
} }
} }
@ -2035,66 +2035,66 @@ namespace QuadbikeHandlebarAnims
{ {
static const float POW_CONSTANT = 0.86f; static const float POW_CONSTANT = 0.86f;
static const float SLOW_SPEED_THRESHOLD = 0.02f; static const float SLOW_SPEED_THRESHOLD = 0.02f;
__declspec(naked) void ProcessRiderAnims_FixInterp() __declspec(naked) static void ProcessRiderAnims_FixInterp()
{ {
_asm _asm
{ {
xor edx, edx xor edx, edx
cmp [esp+130h-100h], edx // Reverse animation cmp [esp+0x130-0x100], edx // Reverse animation
jne FuncSetToZero jne FuncSetToZero
cmp [esp+130h-0F8h], edx // Drive-by animation cmp [esp+0x130-0xF8], edx // Drive-by animation
jne FuncSetToZero jne FuncSetToZero
fld dword ptr [esp+130h-108h] fld dword ptr [esp+0x130-0x108]
fabs fabs
fcomp [SLOW_SPEED_THRESHOLD] fcomp SLOW_SPEED_THRESHOLD
fnstsw ax fnstsw ax
test ah, 5 test ah, 5
jp FuncReturn jp FuncReturn
FuncSetToZero: FuncSetToZero:
mov [esp+130h-118h], edx mov [esp+0x130-0x118], edx
FuncReturn: FuncReturn:
fld [POW_CONSTANT] fld POW_CONSTANT
retn ret
} }
} }
static uint32_t savedClumpAssociation; static uint32_t savedClumpAssociation;
__declspec(naked) void SaveDriveByAnim_Steam() __declspec(naked) static void SaveDriveByAnim_Steam()
{ {
_asm _asm
{ {
mov eax, [ebp-14h] mov eax, [ebp-0x14]
mov [savedClumpAssociation], eax mov savedClumpAssociation, eax
fdiv dword ptr [ecx+18h] fdiv dword ptr [ecx+0x18]
fstp [ebp-14h] fstp dword ptr [ebp-0x14]
retn ret
} }
} }
__declspec(naked) void ProcessRiderAnims_FixInterp_Steam() __declspec(naked) static void ProcessRiderAnims_FixInterp_Steam()
{ {
_asm _asm
{ {
xor edx, edx xor edx, edx
cmp [ebp-28h], edx // Reverse animation cmp [ebp-0x28], edx // Reverse animation
jne FuncSetToZero jne FuncSetToZero
cmp [savedClumpAssociation], edx // Drive-by animation cmp savedClumpAssociation, edx // Drive-by animation
jne FuncSetToZero jne FuncSetToZero
fld dword ptr [ebp-24h] fld dword ptr [ebp-0x24]
fabs fabs
fcomp [SLOW_SPEED_THRESHOLD] fcomp SLOW_SPEED_THRESHOLD
fnstsw ax fnstsw ax
test ah, 5 test ah, 5
jp FuncReturn jp FuncReturn
FuncSetToZero: FuncSetToZero:
mov [ebp-14h], edx mov [ebp-0x14], edx
FuncReturn: FuncReturn:
fld [POW_CONSTANT] fld [POW_CONSTANT]
retn ret
} }
} }
@ -2119,31 +2119,31 @@ namespace UprightBoatRadioStationChange
// ============= Fix a memory leak when taking photos ============= // ============= Fix a memory leak when taking photos =============
namespace CameraMemoryLeakFix namespace CameraMemoryLeakFix
{ {
__declspec(naked) void psGrabScreen_UnlockAndReleaseSurface() __declspec(naked) static void psGrabScreen_UnlockAndReleaseSurface()
{ {
_asm _asm
{ {
// Preserve the function result so we don't need two ASM hooks // Preserve the function result so we don't need two ASM hooks
push eax push eax
mov eax, [esp+34h-2Ch] mov eax, [esp+0x34-0x2C]
mov edx, [eax] mov edx, [eax]
push eax push eax
call dword ptr [edx+38h] // IDirect3DSurface9.UnlockRect call dword ptr [edx+0x38] // IDirect3DSurface9.UnlockRect
mov eax, [esp+34h-2Ch] mov eax, [esp+0x34-0x2C]
mov edx, [eax] mov edx, [eax]
push eax push eax
call dword ptr [edx+8h] // IDirect3DSurface9.Release call dword ptr [edx+0x8] // IDirect3DSurface9.Release
pop eax pop eax
pop ebp pop ebp
add esp, 2Ch add esp, 0x2C
retn retn
} }
} }
__declspec(naked) void psGrabScreen_UnlockAndReleaseSurface_Steam() __declspec(naked) static void psGrabScreen_UnlockAndReleaseSurface_Steam()
{ {
_asm _asm
{ {
@ -2153,18 +2153,18 @@ namespace CameraMemoryLeakFix
mov eax, [ebp-4] mov eax, [ebp-4]
mov edx, [eax] mov edx, [eax]
push eax push eax
call dword ptr [edx+38h] // IDirect3DSurface9.UnlockRect call dword ptr [edx+0x38] // IDirect3DSurface9.UnlockRect
mov eax, [ebp-4] mov eax, [ebp-4]
mov edx, [eax] mov edx, [eax]
push eax push eax
call dword ptr [edx+8h] // IDirect3DSurface9.Release call dword ptr [edx+0x8] // IDirect3DSurface9.Release
pop eax pop eax
pop esi pop esi
mov esp, ebp mov esp, ebp
pop ebp pop ebp
retn ret
} }
} }
} }
@ -2231,67 +2231,67 @@ namespace RacingCheckpointsRender
// ============= Correct an improperly decrypted CPlayerPedData::operator= that broke gang recruiting after activating replays ============= // ============= Correct an improperly decrypted CPlayerPedData::operator= that broke gang recruiting after activating replays =============
namespace PlayerPedDataAssignment namespace PlayerPedDataAssignment
{ {
__declspec(naked) void AssignmentOp_Hoodlum() __declspec(naked) static void AssignmentOp_Hoodlum()
{ {
_asm _asm
{ {
xor edx, [ecx+34h] xor edx, [ecx+0x34]
and edx, 1 and edx, 1
xor [eax+34h], edx xor [eax+0x34], edx
mov esi, [eax+34h] mov esi, [eax+0x34]
mov edx, [ecx+34h] mov edx, [ecx+0x34]
xor edx, esi xor edx, esi
and edx, 2 and edx, 2
xor edx, esi xor edx, esi
mov [eax+34h], edx mov [eax+0x34], edx
mov esi, [ecx+34h] mov esi, [ecx+0x34]
xor esi, edx xor esi, edx
and esi, 4 and esi, 4
xor esi, edx xor esi, edx
mov [eax+34h], esi mov [eax+0x34], esi
mov edx, [ecx+34h] mov edx, [ecx+0x34]
xor edx, esi xor edx, esi
and edx, 8 and edx, 8
xor edx, esi xor edx, esi
mov [eax+34h], edx mov [eax+0x34], edx
mov esi, [ecx+34h] mov esi, [ecx+0x34]
xor esi, edx xor esi, edx
and esi, 10h and esi, 0x10
xor esi, edx xor esi, edx
mov [eax+34h], esi mov [eax+0x34], esi
mov edx, [ecx+34h] mov edx, [ecx+0x34]
xor edx, esi xor edx, esi
and edx, 20h and edx, 0x20
xor edx, esi xor edx, esi
mov [eax+34h], edx mov [eax+0x34], edx
mov esi, [ecx+34h] mov esi, [ecx+0x34]
xor esi, edx xor esi, edx
and esi, 40h and esi, 0x40
xor esi, edx xor esi, edx
mov [eax+34h], esi mov [eax+0x34], esi
mov edx, [ecx+34h] mov edx, [ecx+0x34]
xor edx, esi xor edx, esi
and edx, 80h and edx, 0x80
xor edx, esi xor edx, esi
mov [eax+34h], edx mov [eax+0x34], edx
mov esi, [ecx+34h] mov esi, [ecx+0x34]
xor esi, edx xor esi, edx
and esi, 100h and esi, 0x100
xor esi, edx xor esi, edx
mov [eax+34h], esi mov [eax+0x34], esi
mov edx, [ecx+34h] mov edx, [ecx+0x34]
retn ret
} }
} }
__declspec(naked) void AssignmentOp_Compact() __declspec(naked) static void AssignmentOp_Compact()
{ {
_asm _asm
{ {
call AssignmentOp_Hoodlum call AssignmentOp_Hoodlum
xor edx, esi xor edx, esi
and edx, 200h and edx, 0x200
retn ret
} }
} }
} }
@ -2300,7 +2300,7 @@ namespace PlayerPedDataAssignment
// ============= Spawn lapdm1 (biker cop) correctly if the script requests one with PEDTYPE_COP ============= // ============= Spawn lapdm1 (biker cop) correctly if the script requests one with PEDTYPE_COP =============
namespace GetCorrectPedModel_Lapdm1 namespace GetCorrectPedModel_Lapdm1
{ {
__declspec(naked) void BikerCop_Retail() __declspec(naked) static void BikerCop_Retail()
{ {
_asm _asm
{ {
@ -2309,11 +2309,11 @@ namespace GetCorrectPedModel_Lapdm1
mov dword ptr [eax], 1 mov dword ptr [eax], 1
BikerCop_Return: BikerCop_Return:
retn 8 ret 8
} }
} }
__declspec(naked) void BikerCop_Steam() __declspec(naked) static void BikerCop_Steam()
{ {
_asm _asm
{ {
@ -2323,7 +2323,7 @@ namespace GetCorrectPedModel_Lapdm1
BikerCop_Return: BikerCop_Return:
pop ebp pop ebp
retn 8 ret 8
} }
} }
} }
@ -2444,7 +2444,7 @@ namespace JetpackKeyboardControlsHover
static void* ProcessControlInput_DontHover; static void* ProcessControlInput_DontHover;
static void* ProcessControlInput_Hover; static void* ProcessControlInput_Hover;
__declspec(naked) void ProcessControlInput_HoverWithKeyboard() __declspec(naked) static void ProcessControlInput_HoverWithKeyboard()
{ {
_asm _asm
{ {
@ -2453,7 +2453,7 @@ namespace JetpackKeyboardControlsHover
test al, al test al, al
jnz Hovering jnz Hovering
mov ecx, ebp mov ecx, ebp
mov byte ptr [esi+0Dh], 0 mov byte ptr [esi+0xD], 0
jmp ProcessControlInput_DontHover jmp ProcessControlInput_DontHover
Hovering: Hovering:
@ -2461,7 +2461,7 @@ namespace JetpackKeyboardControlsHover
} }
} }
__declspec(naked) void ProcessControlInput_HoverWithKeyboard_Steam() __declspec(naked) static void ProcessControlInput_HoverWithKeyboard_Steam()
{ {
_asm _asm
{ {
@ -2470,7 +2470,7 @@ namespace JetpackKeyboardControlsHover
test al, al test al, al
jnz Hovering jnz Hovering
mov ecx, ebx mov ecx, ebx
mov byte ptr [edi+0Dh], 0 mov byte ptr [edi+0xD], 0
jmp ProcessControlInput_DontHover jmp ProcessControlInput_DontHover
Hovering: Hovering:
@ -2487,11 +2487,11 @@ namespace RiotDontTargetPlayerGroupDuringMissions
static void* SkipTargetting; static void* SkipTargetting;
static void* DontSkipTargetting; static void* DontSkipTargetting;
__declspec(naked) void CheckIfInPlayerGroupAndOnAMission() __declspec(naked) static void CheckIfInPlayerGroupAndOnAMission()
{ {
_asm _asm
{ {
cmp byte ptr [ebp+2D0h], 1 cmp byte ptr [ebp+0x2D0], 1
jne NotInGroup jne NotInGroup
call IsPlayerOnAMission call IsPlayerOnAMission
test al, al test al, al
@ -2499,18 +2499,18 @@ namespace RiotDontTargetPlayerGroupDuringMissions
jmp SkipTargetting jmp SkipTargetting
NotOnAMission: NotOnAMission:
cmp byte ptr [ebp+2D0h], 1 cmp byte ptr [ebp+0x2D0], 1
NotInGroup: NotInGroup:
jmp DontSkipTargetting jmp DontSkipTargetting
} }
} }
__declspec(naked) void CheckIfInPlayerGroupAndOnAMission_Steam() __declspec(naked) static void CheckIfInPlayerGroupAndOnAMission_Steam()
{ {
_asm _asm
{ {
cmp byte ptr [ebx+2D0h], 1 cmp byte ptr [ebx+0x2D0], 1
jne NotInGroup jne NotInGroup
call IsPlayerOnAMission call IsPlayerOnAMission
test al, al test al, al
@ -2518,7 +2518,7 @@ namespace RiotDontTargetPlayerGroupDuringMissions
jmp SkipTargetting jmp SkipTargetting
NotOnAMission: NotOnAMission:
cmp byte ptr [ebx+2D0h], 1 cmp byte ptr [ebx+0x2D0], 1
NotInGroup: NotInGroup:
jmp DontSkipTargetting jmp DontSkipTargetting