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

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

View file

@ -2530,22 +2530,22 @@ namespace RiotDontTargetPlayerGroupDuringMissions
// ============= Fixed vehicles exploding twice if the driver leaves the car while it's exploding ============= // ============= Fixed vehicles exploding twice if the driver leaves the car while it's exploding =============
namespace RemoveDriverStatusFix namespace RemoveDriverStatusFix
{ {
__declspec(naked) void RemoveDriver_SetStatus() __declspec(naked) static void RemoveDriver_SetStatus()
{ {
// if (m_nStatus != STATUS_WRECKED) // if (m_nStatus != STATUS_WRECKED)
// m_nStatus = STATUS_ABANDONED; // m_nStatus = STATUS_ABANDONED;
_asm _asm
{ {
mov bl, [edi+36h] mov bl, [edi+0x36]
mov al, bl mov al, bl
and bl, 0F8h and bl, 0xF8
cmp bl, 28h cmp bl, 0x28
je DontSetStatus je DontSetStatus
and al, 7 and al, 7
or al, 20h or al, 0x20
DontSetStatus: DontSetStatus:
retn ret
} }
} }
@ -3028,35 +3028,35 @@ namespace CrosshairScalingFixes
// Debugged by Wesser // Debugged by Wesser
namespace MapScreenScalingFixes namespace MapScreenScalingFixes
{ {
void __declspec(naked) ScaleX_NewBinaries() __declspec(naked) void ScaleX_NewBinaries()
{ {
_asm _asm
{ {
push ecx push ecx
push 3F800000h // 1.0f push 0x3F800000 // 1.0f
call [ScaleX] call [ScaleX]
add esp, 4 add esp, 4
fsub st(1), st fsub st(1), st
fxch st(1) fxch st(1)
pop ecx pop ecx
retn ret
} }
} }
void __declspec(naked) ScaleY_NewBinaries() __declspec(naked) void ScaleY_NewBinaries()
{ {
_asm _asm
{ {
push ecx push ecx
push 3F800000h // 1.0f push 0x3F800000 // 1.0f
call [ScaleY] call [ScaleY]
add esp, 4 add esp, 4
fsub st(1), st fsub st(1), st
fxch st(1) fxch st(1)
pop ecx pop ecx
retn ret
} }
} }
@ -3182,41 +3182,41 @@ namespace TextRectPaddingScalingFixes
// By Wesser // By Wesser
namespace NitrousReverseRechargeFix namespace NitrousReverseRechargeFix
{ {
void __declspec(naked) NitrousControl_DontRechargeWhenReversing() __declspec(naked) static void NitrousControl_DontRechargeWhenReversing()
{ {
// x = 1.0f; \ if m_fGasPedal >= 0.0f x -= m_fGasPedal; // x = 1.0f; \ if m_fGasPedal >= 0.0f x -= m_fGasPedal;
_asm _asm
{ {
fld [esi+49Ch] fld dword ptr [esi+0x49C]
fldz fldz
fcomp st(1) fcomp st(1)
fnstsw ax fnstsw ax
test ah, 41h test ah, 0x41
jnz BiggerOrEqual jnz BiggerOrEqual
fstp st fstp st
retn ret
BiggerOrEqual: BiggerOrEqual:
fsubp st(1), st fsubp st(1), st
retn ret
} }
} }
void __declspec(naked) NitrousControl_DontRechargeWhenReversing_NewBinaries() __declspec(naked) static void NitrousControl_DontRechargeWhenReversing_NewBinaries()
{ {
_asm _asm
{ {
fld [esi+49Ch] fld dword ptr [esi+0x49C]
fldz fldz
fcomp st(1) fcomp st(1)
fnstsw ax fnstsw ax
test ah, 41h test ah, 0x41
jnz BiggerOrEqual jnz BiggerOrEqual
fstp st fstp st
fldz fldz
BiggerOrEqual: BiggerOrEqual:
retn ret
} }
} }
} }
@ -3503,7 +3503,7 @@ void InstallMemValidator()
// Hooks // Hooks
void __declspec(naked) LightMaterialsFix() __declspec(naked) void LightMaterialsFix()
{ {
_asm _asm
{ {
@ -3519,24 +3519,24 @@ void __declspec(naked) LightMaterialsFix()
mov [ebx+16], edi mov [ebx+16], edi
add ebx, 20 add ebx, 20
mov [ecx], ebx mov [ecx], ebx
retn ret
} }
} }
void __declspec(naked) UserTracksFix() __declspec(naked) void UserTracksFix()
{ {
_asm _asm
{ {
push [esp+4] push [esp+4]
call SetVolume call SetVolume
mov ecx, [pUserTracksStuff] mov ecx, [pUserTracksStuff]
mov byte ptr [ecx+0Dh], 1 mov byte ptr [ecx+0xD], 1
call InitializeUtrax call InitializeUtrax
retn 4 ret 4
} }
} }
void __declspec(naked) UserTracksFix_Steam() __declspec(naked) void UserTracksFix_Steam()
{ {
_asm _asm
{ {
@ -3545,14 +3545,14 @@ void __declspec(naked) UserTracksFix_Steam()
mov ecx, [pUserTracksStuff] mov ecx, [pUserTracksStuff]
mov byte ptr [ecx+5], 1 mov byte ptr [ecx+5], 1
call InitializeUtrax call InitializeUtrax
retn 4 ret 4
} }
} }
static void* PlaneAtomicRendererSetup_JumpBack = AddressByVersion<void*>(0x4C7986, 0x4C7A06, 0x4D2275); static void* PlaneAtomicRendererSetup_JumpBack = AddressByVersion<void*>(0x4C7986, 0x4C7A06, 0x4D2275);
static void* RenderVehicleHiDetailAlphaCB_BigVehicle = AddressByVersion<void*>(0x734370, 0x734BA0, 0x76E400); static void* RenderVehicleHiDetailAlphaCB_BigVehicle = AddressByVersion<void*>(0x734370, 0x734BA0, 0x76E400);
static void* RenderVehicleHiDetailCB_BigVehicle = AddressByVersion<void*>(0x733420, 0x733C50, 0x76D6C0); static void* RenderVehicleHiDetailCB_BigVehicle = AddressByVersion<void*>(0x733420, 0x733C50, 0x76D6C0);
void __declspec(naked) PlaneAtomicRendererSetup() __declspec(naked) void PlaneAtomicRendererSetup()
{ {
static const char aStaticProp[] = "static_prop"; static const char aStaticProp[] = "static_prop";
static const char aMovingProp[] = "moving_prop"; static const char aMovingProp[] = "moving_prop";
@ -3561,31 +3561,30 @@ void __declspec(naked) PlaneAtomicRendererSetup()
mov eax, [esi+4] mov eax, [esi+4]
push eax push eax
call GetFrameNodeName call GetFrameNodeName
//push eax
mov [esp+8+8], eax mov [esp+8+8], eax
push 11 push 11
push offset aStaticProp push offset aStaticProp
push eax push eax
call strncmp call strncmp
add esp, 10h add esp, 0x10
test eax, eax test eax, eax
jz PlaneAtomicRendererSetup_Alpha jz PlaneAtomicRendererSetup_Alpha
push 11 push 11
push offset aMovingProp push offset aMovingProp
push [esp+12+8] push [esp+12+8]
call strncmp call strncmp
add esp, 0Ch add esp, 0xC
test eax, eax test eax, eax
jnz PlaneAtomicRendererSetup_NoAlpha jnz PlaneAtomicRendererSetup_NoAlpha
PlaneAtomicRendererSetup_Alpha: PlaneAtomicRendererSetup_Alpha:
push [RenderVehicleHiDetailAlphaCB_BigVehicle] push RenderVehicleHiDetailAlphaCB_BigVehicle
jmp PlaneAtomicRendererSetup_Return jmp PlaneAtomicRendererSetup_Return
PlaneAtomicRendererSetup_NoAlpha: PlaneAtomicRendererSetup_NoAlpha:
push [RenderVehicleHiDetailCB_BigVehicle] push RenderVehicleHiDetailCB_BigVehicle
PlaneAtomicRendererSetup_Return: PlaneAtomicRendererSetup_Return:
jmp PlaneAtomicRendererSetup_JumpBack jmp PlaneAtomicRendererSetup_JumpBack
} }
} }
@ -3604,7 +3603,7 @@ static int strcmp_wrap(const char *s1, const char *s2)
return strcmp( s1, s2 ); return strcmp( s1, s2 );
} }
void __declspec(naked) HunterTest() __declspec(naked) void HunterTest()
{ {
static const char aDoorDummy[] = "door_lf_ok"; static const char aDoorDummy[] = "door_lf_ok";
static const char aStaticRotor[] = "static_rotor"; static const char aStaticRotor[] = "static_rotor";
@ -3619,7 +3618,7 @@ void __declspec(naked) HunterTest()
push offset aWindscreen push offset aWindscreen
push ebp push ebp
call strncmp call strncmp
add esp, 0Ch add esp, 0xC
test eax, eax test eax, eax
jz HunterTest_RegularAlpha jz HunterTest_RegularAlpha
@ -3640,10 +3639,10 @@ void __declspec(naked) HunterTest()
test di, di test di, di
jnz HunterTest_DoorTest jnz HunterTest_DoorTest
push [RenderVehicleHiDetailCB] push RenderVehicleHiDetailCB
jmp HunterTest_JumpBack jmp HunterTest_JumpBack
HunterTest_DoorTest: HunterTest_DoorTest:
cmp nCachedCRC, 0x45D0B41C cmp nCachedCRC, 0x45D0B41C
jnz HunterTest_RegularAlpha jnz HunterTest_RegularAlpha
push offset aDoorDummy push offset aDoorDummy
@ -3655,22 +3654,22 @@ HunterTest_DoorTest:
push RenderVehicleHiDetailAlphaCB_HunterDoor push RenderVehicleHiDetailAlphaCB_HunterDoor
jmp HunterTest_JumpBack jmp HunterTest_JumpBack
HunterTest_RegularAlpha: HunterTest_RegularAlpha:
push [RenderVehicleHiDetailAlphaCB] push RenderVehicleHiDetailAlphaCB
jmp HunterTest_JumpBack jmp HunterTest_JumpBack
HunterTest_StaticRotorAlphaSet: HunterTest_StaticRotorAlphaSet:
push [RenderHeliRotorAlphaCB] push RenderHeliRotorAlphaCB
jmp HunterTest_JumpBack jmp HunterTest_JumpBack
HunterTest_StaticRotor2AlphaSet: HunterTest_StaticRotor2AlphaSet:
push [RenderHeliTailRotorAlphaCB] push RenderHeliTailRotorAlphaCB
jmp HunterTest_JumpBack jmp HunterTest_JumpBack
} }
} }
static void* CacheCRC32_JumpBack = AddressByVersion<void*>(0x4C7B10, 0x4C7B90, 0x4D2400); static void* CacheCRC32_JumpBack = AddressByVersion<void*>(0x4C7B10, 0x4C7B90, 0x4D2400);
void __declspec(naked) CacheCRC32() __declspec(naked) void CacheCRC32()
{ {
_asm _asm
{ {
@ -3682,7 +3681,7 @@ void __declspec(naked) CacheCRC32()
static void* const TrailerDoubleRWheelsFix_ReturnFalse = AddressByVersion<void*>(0x4C9333, 0x4C9533, 0x4D3C59); static void* const TrailerDoubleRWheelsFix_ReturnFalse = AddressByVersion<void*>(0x4C9333, 0x4C9533, 0x4D3C59);
static void* const TrailerDoubleRWheelsFix_ReturnTrue = AddressByVersion<void*>(0x4C9235, 0x4C9435, 0x4D3B59); static void* const TrailerDoubleRWheelsFix_ReturnTrue = AddressByVersion<void*>(0x4C9235, 0x4C9435, 0x4D3B59);
void __declspec(naked) TrailerDoubleRWheelsFix() __declspec(naked) void TrailerDoubleRWheelsFix()
{ {
_asm _asm
{ {
@ -3693,26 +3692,26 @@ void __declspec(naked) TrailerDoubleRWheelsFix()
cmp eax, 5 cmp eax, 5
je TrailerDoubleRWheelsFix_False je TrailerDoubleRWheelsFix_False
TrailerDoubleRWheelsFix_DoWheels: TrailerDoubleRWheelsFix_DoWheels:
jmp TrailerDoubleRWheelsFix_ReturnTrue jmp TrailerDoubleRWheelsFix_ReturnTrue
TrailerDoubleRWheelsFix_False: TrailerDoubleRWheelsFix_False:
jmp TrailerDoubleRWheelsFix_ReturnFalse jmp TrailerDoubleRWheelsFix_ReturnFalse
} }
} }
void __declspec(naked) TrailerDoubleRWheelsFix2() __declspec(naked) void TrailerDoubleRWheelsFix2()
{ {
_asm _asm
{ {
add esp, 18h add esp, 0x18
mov eax, [ebx] mov eax, [ebx]
mov eax, [esi+eax+4] mov eax, [esi+eax+4]
jmp TrailerDoubleRWheelsFix jmp TrailerDoubleRWheelsFix
} }
} }
void __declspec(naked) TrailerDoubleRWheelsFix_Steam() __declspec(naked) void TrailerDoubleRWheelsFix_Steam()
{ {
_asm _asm
{ {
@ -3731,11 +3730,11 @@ TrailerDoubleRWheelsFix_False:
} }
} }
void __declspec(naked) TrailerDoubleRWheelsFix2_Steam() __declspec(naked) void TrailerDoubleRWheelsFix2_Steam()
{ {
_asm _asm
{ {
add esp, 18h add esp, 0x18
mov eax, [ebp] mov eax, [ebp]
mov eax, [ebx+eax+4] mov eax, [ebx+eax+4]
jmp TrailerDoubleRWheelsFix_Steam jmp TrailerDoubleRWheelsFix_Steam
@ -3743,7 +3742,7 @@ void __declspec(naked) TrailerDoubleRWheelsFix2_Steam()
} }
static void* LoadFLAC_JumpBack = AddressByVersion<void*>(0x4F3743, Memory::GetVersion().version == 1 ? (*(BYTE*)0x4F3A50 == 0x6A ? 0x4F3BA3 : 0x5B6B81) : 0, 0x4FFC3F); static void* LoadFLAC_JumpBack = AddressByVersion<void*>(0x4F3743, Memory::GetVersion().version == 1 ? (*(BYTE*)0x4F3A50 == 0x6A ? 0x4F3BA3 : 0x5B6B81) : 0, 0x4FFC3F);
void __declspec(naked) LoadFLAC() __declspec(naked) void LoadFLAC()
{ {
_asm _asm
{ {
@ -3754,36 +3753,36 @@ void __declspec(naked) LoadFLAC()
call DecoderCtor call DecoderCtor
jmp LoadFLAC_Success jmp LoadFLAC_Success
LoadFLAC_WindowsMedia: LoadFLAC_WindowsMedia:
jmp LoadFLAC_JumpBack jmp LoadFLAC_JumpBack
LoadFLAC_Success: LoadFLAC_Success:
test eax, eax test eax, eax
mov [esp+20h+4], eax mov [esp+0x20+4], eax
jnz LoadFLAC_Return_NoDelete jnz LoadFLAC_Return_NoDelete
LoadFLAC_Return: LoadFLAC_Return:
mov ecx, esi mov ecx, esi
call CAEDataStreamOld::~CAEDataStreamOld call CAEDataStreamOld::~CAEDataStreamOld
push esi push esi
call GTAdelete call GTAdelete
add esp, 4 add esp, 4
LoadFLAC_Return_NoDelete: LoadFLAC_Return_NoDelete:
mov eax, [esp+20h+4] mov eax, [esp+0x20+4]
mov ecx, [esp+20h-0Ch] mov ecx, [esp+0x20-0xC]
pop esi pop esi
pop ebp pop ebp
pop edi pop edi
pop ebx pop ebx
mov fs:0, ecx mov fs:0, ecx
add esp, 10h add esp, 0x10
retn 4 ret 4
} }
} }
// 1.01 securom butchered this func, might not be reliable // 1.01 securom butchered this func, might not be reliable
void __declspec(naked) LoadFLAC_11() __declspec(naked) void LoadFLAC_11()
{ {
_asm _asm
{ {
@ -3794,36 +3793,36 @@ void __declspec(naked) LoadFLAC_11()
call DecoderCtor call DecoderCtor
jmp LoadFLAC_Success jmp LoadFLAC_Success
LoadFLAC_WindowsMedia: LoadFLAC_WindowsMedia:
jmp LoadFLAC_JumpBack jmp LoadFLAC_JumpBack
LoadFLAC_Success: LoadFLAC_Success:
test eax, eax test eax, eax
mov [esp+20h+4], eax mov [esp+0x20+4], eax
jnz LoadFLAC_Return_NoDelete jnz LoadFLAC_Return_NoDelete
LoadFLAC_Return: LoadFLAC_Return:
mov ecx, esi mov ecx, esi
call CAEDataStreamNew::~CAEDataStreamNew call CAEDataStreamNew::~CAEDataStreamNew
push esi push esi
call GTAdelete call GTAdelete
add esp, 4 add esp, 4
LoadFLAC_Return_NoDelete: LoadFLAC_Return_NoDelete:
mov eax, [esp+20h+4] mov eax, [esp+0x20+4]
mov ecx, [esp+20h-0Ch] mov ecx, [esp+0x20-0xC]
pop esi pop esi
pop ebp pop ebp
pop edi pop edi
pop ebx pop ebx
mov fs:0, ecx mov fs:0, ecx
add esp, 10h add esp, 0x10
retn 4 ret 4
} }
} }
void __declspec(naked) LoadFLAC_Steam() __declspec(naked) void LoadFLAC_Steam()
{ {
_asm _asm
{ {
@ -3834,44 +3833,44 @@ void __declspec(naked) LoadFLAC_Steam()
call DecoderCtor call DecoderCtor
jmp LoadFLAC_Success jmp LoadFLAC_Success
LoadFLAC_WindowsMedia: LoadFLAC_WindowsMedia:
jmp LoadFLAC_JumpBack jmp LoadFLAC_JumpBack
LoadFLAC_Success: LoadFLAC_Success:
test eax, eax test eax, eax
mov [esp+20h+4], eax mov [esp+0x20+4], eax
jnz LoadFLAC_Return_NoDelete jnz LoadFLAC_Return_NoDelete
LoadFLAC_Return: LoadFLAC_Return:
mov ecx, esi mov ecx, esi
call CAEDataStreamOld::~CAEDataStreamOld call CAEDataStreamOld::~CAEDataStreamOld
push esi push esi
call GTAdelete call GTAdelete
add esp, 4 add esp, 4
LoadFLAC_Return_NoDelete: LoadFLAC_Return_NoDelete:
mov eax, [esp+20h+4] mov eax, [esp+0x20+4]
mov ecx, [esp+20h-0Ch] mov ecx, [esp+0x20-0xC]
pop ebx pop ebx
pop esi pop esi
pop ebp pop ebp
pop edi pop edi
mov fs:0, ecx mov fs:0, ecx
add esp, 10h add esp, 0x10
retn 4 ret 4
} }
} }
void __declspec(naked) FLACInit() __declspec(naked) void FLACInit()
{ {
_asm _asm
{ {
mov byte ptr [ecx+0Dh], 1 mov byte ptr [ecx+0xD], 1
jmp InitializeUtrax jmp InitializeUtrax
} }
} }
void __declspec(naked) FLACInit_Steam() __declspec(naked) void FLACInit_Steam()
{ {
_asm _asm
{ {