Compare commits

...

2 commits

Author SHA1 Message Date
Echo J.
c9a935d5a0
Merge 815ee10a52 into 2a597da1bc 2024-11-29 14:54:56 +01:00
Echo J
815ee10a52 SilentPatchVC: Add GCC-style inline assembly statements
This also includes a small wrapper to call a C++ function from GCC-style inline ASM

These statements almost work on llvm-mingw too (but there's some stubborn call instructions)
2024-11-29 15:53:40 +02:00

View file

@ -671,6 +671,7 @@ float FixedRefValue()
__declspec(naked) void SubtitlesShadowFix() __declspec(naked) void SubtitlesShadowFix()
{ {
#ifdef _MSC_VER
_asm _asm
{ {
mov [esp], eax mov [esp], eax
@ -683,10 +684,33 @@ __declspec(naked) void SubtitlesShadowFix()
call Recalculate call Recalculate
jmp SubtitlesShadowFix_JumpBack jmp SubtitlesShadowFix_JumpBack
} }
#else
__asm__ volatile
(
"mov [esp], eax\n"
"fild dword ptr [esp]\n"
"push eax\n"
"lea eax, [esp+0x20-0x18]\n"
"push eax\n"
"lea eax, [esp+0x24-0x14]\n"
"push eax\n"
"call %[Recalculate]\n"
"jmp %[SubtitlesShadowFix_JumpBack]"
:: [Recalculate] "i" (Recalculate),
[SubtitlesShadowFix_JumpBack] "m" (SubtitlesShadowFix_JumpBack)
);
#endif
}
// C-style wrapper for calling a C++ function in GCC-style inline assembly (the function signature is really important here)
RwFrame* __thiscall CVehicleModelInfo_GetExtrasFrame(CVehicleModelInfo* modelInfo, RpClump* clump)
{
return modelInfo->GetExtrasFrame(clump);
} }
__declspec(naked) void CreateInstance_BikeFix() __declspec(naked) void CreateInstance_BikeFix()
{ {
#ifdef _MSC_VER
_asm _asm
{ {
push eax push eax
@ -694,6 +718,16 @@ __declspec(naked) void CreateInstance_BikeFix()
call CVehicleModelInfo::GetExtrasFrame call CVehicleModelInfo::GetExtrasFrame
ret ret
} }
#else
__asm__ volatile
(
"push eax\n"
"mov ecx, ebp\n"
"call %[CVehicleModelInfo_GetExtrasFrame]\n"
"ret"
:: [CVehicleModelInfo_GetExtrasFrame] "i" (CVehicleModelInfo_GetExtrasFrame)
);
#endif
} }
char** ppUserFilesDir = AddressByVersion<char**>(0x6022AA, 0x60228A, 0x601ECA); char** ppUserFilesDir = AddressByVersion<char**>(0x6022AA, 0x60228A, 0x601ECA);
@ -733,6 +767,7 @@ unsigned int __cdecl AutoPilotTimerCalculation_VC(unsigned int nTimer, int nScal
__declspec(naked) void AutoPilotTimerFix_VC() __declspec(naked) void AutoPilotTimerFix_VC()
{ {
#ifdef _MSC_VER
_asm _asm
{ {
push dword ptr [esp + 0xC] push dword ptr [esp + 0xC]
@ -746,6 +781,22 @@ __declspec(naked) void AutoPilotTimerFix_VC()
pop ebx pop ebx
ret 4 ret 4
} }
#else
__asm__ volatile
(
"push dword ptr [esp + 0xC]\n"
"push dword ptr [ebx + 0x10]\n"
"push eax\n"
"call %[AutoPilotTimerCalculation_VC]\n"
"add esp, 0xC\n"
"mov [ebx + 0xC], eax\n"
"add esp, 0x30\n"
"pop ebp\n"
"pop ebx\n"
"ret 4"
:: [AutoPilotTimerCalculation_VC] "i" (AutoPilotTimerCalculation_VC)
);
#endif
} }
@ -866,6 +917,7 @@ namespace SirenSwitchingFix
{ {
__declspec(naked) static void IsFBIRanchOrFBICar() __declspec(naked) static void IsFBIRanchOrFBICar()
{ {
#ifdef _MSC_VER
_asm _asm
{ {
mov dword ptr [esi+0x1C], 0x1C mov dword ptr [esi+0x1C], 0x1C
@ -882,6 +934,24 @@ namespace SirenSwitchingFix
xor al, al xor al, al
ret ret
} }
#else
__asm__ volatile
(
"mov dword ptr [esi+0x1C], 0x1C\n"
// al = 0 - high pitched siren
// al = 1 - normal siren
"cmp dword ptr [ebp+0x14], 90\n" // fbiranch
"je IsFBIRanchOrFBICar_HighPitchSiren\n"
"cmp dword ptr [ebp+0x14], 17\n" // fbicar
"setne al\n"
"ret\n"
"IsFBIRanchOrFBICar_HighPitchSiren:\n"
"xor al, al\n"
"ret"
);
#endif
} }
} }
@ -950,6 +1020,7 @@ namespace RemoveDriverStatusFix
{ {
// if (m_nStatus != STATUS_WRECKED) // if (m_nStatus != STATUS_WRECKED)
// m_nStatus = STATUS_ABANDONED; // m_nStatus = STATUS_ABANDONED;
#ifdef _MSC_VER
_asm _asm
{ {
mov cl, [ebx+0x50] mov cl, [ebx+0x50]
@ -963,6 +1034,21 @@ namespace RemoveDriverStatusFix
DontSetStatus: DontSetStatus:
ret ret
} }
#else
__asm__ volatile
(
"mov cl, [ebx+0x50]\n"
"mov al, cl\n"
"and cl, 0xF8\n"
"cmp cl, 0x28\n"
"je DontSetStatus\n"
"and al, 7\n"
"or al, 0x20\n"
"DontSetStatus:\n"
"ret"
);
#endif
} }
} }
@ -1035,12 +1121,22 @@ namespace NullTerminatedLines
static void* orgSscanf_LoadPath; static void* orgSscanf_LoadPath;
__declspec(naked) static void sscanf1_LoadPath_Terminate() __declspec(naked) static void sscanf1_LoadPath_Terminate()
{ {
#ifdef _MSC_VER
_asm _asm
{ {
mov eax, [esp+4] mov eax, [esp+4]
mov byte ptr [eax+ecx], 0 mov byte ptr [eax+ecx], 0
jmp orgSscanf_LoadPath jmp orgSscanf_LoadPath
} }
#else
__asm__ volatile
(
"mov eax, [esp+4]\n"
"mov byte ptr [eax+ecx], 0\n"
"jmp %[orgSscanf_LoadPath]"
:: [orgSscanf_LoadPath] "m" (orgSscanf_LoadPath)
);
#endif
} }
} }
@ -1065,16 +1161,26 @@ namespace PickupEffectsFixes
{ {
__declspec(naked) static void PickUpEffects_BigDollarColor() __declspec(naked) static void PickUpEffects_BigDollarColor()
{ {
#ifdef _MSC_VER
_asm _asm
{ {
mov byte ptr [esp+0x184-0x170], 0 mov byte ptr [esp+0x184-0x170], 0
mov dword ptr [esp+0x184-0x174], 37 mov dword ptr [esp+0x184-0x174], 37
ret ret
} }
#else
__asm__ volatile
(
"mov byte ptr [esp+0x184-0x170], 0\n"
"mov dword ptr [esp+0x184-0x174], 37\n"
"ret"
);
#endif
} }
__declspec(naked) static void PickUpEffects_Minigun2Glow() __declspec(naked) static void PickUpEffects_Minigun2Glow()
{ {
#ifdef _MSC_VER
_asm _asm
{ {
cmp ecx, 294 // minigun2 cmp ecx, 294 // minigun2
@ -1090,6 +1196,23 @@ namespace PickupEffectsFixes
mov ebx, ecx mov ebx, ecx
ret ret
} }
#else
__asm__ volatile
(
"cmp ecx, 294\n" // minigun2
"jnz NotMinigun2\n"
"mov byte ptr [esp+0x184-0x170], 0\n"
"xor eax, eax\n"
"jmp Return\n"
"NotMinigun2:\n"
"lea eax, [ecx+1]\n"
"Return:\n"
"mov ebx, ecx\n"
"ret"
);
#endif
} }
} }
@ -1106,6 +1229,7 @@ namespace IsPlayerTargettingCharFix
__declspec(naked) static void IsPlayerTargettingChar_ExtraChecks() __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 // After this extra block of code, there is a jz Return, so set ZF to 0 here if this path is to be entered
#ifdef _MSC_VER
_asm _asm
{ {
test bl, bl test bl, bl
@ -1126,6 +1250,31 @@ namespace IsPlayerTargettingCharFix
xor al, al xor al, al
ret ret
} }
#else
__asm__ volatile
(
"test bl, bl\n"
"jnz ReturnToUpdateCompareFlag\n"
"mov eax, %[bUseMouse3rdPerson]\n"
"cmp byte ptr [eax], 0\n"
"jne CmpAndReturn\n"
"mov ecx, %[TheCamera]\n"
"call %[Using1stPersonWeaponMode]\n"
"test al, al\n"
"jz ReturnToUpdateCompareFlag\n"
"CmpAndReturn:\n"
"cmp byte ptr [esp+0x11C-0x10C], 0\n"
"ret\n"
"ReturnToUpdateCompareFlag:\n"
"xor al, al\n"
"ret"
:: [bUseMouse3rdPerson] "m" (bUseMouse3rdPerson),
[TheCamera] "m" (TheCamera),
[Using1stPersonWeaponMode] "m" (Using1stPersonWeaponMode)
);
#endif
} }
} }
@ -1209,6 +1358,7 @@ namespace SelectableBackfaceCulling
static void* EntityRender_Prologue_JumpBack; static void* EntityRender_Prologue_JumpBack;
__declspec(naked) static void __fastcall EntityRender_Original(CEntity*) __declspec(naked) static void __fastcall EntityRender_Original(CEntity*)
{ {
#ifdef _MSC_VER
_asm _asm
{ {
push ebx push ebx
@ -1216,6 +1366,16 @@ namespace SelectableBackfaceCulling
cmp dword ptr [ebx+0x4C], 0 cmp dword ptr [ebx+0x4C], 0
jmp EntityRender_Prologue_JumpBack jmp EntityRender_Prologue_JumpBack
} }
#else
__asm__ volatile
(
"push ebx\n"
"mov ebx, ecx\n"
"cmp dword ptr [ebx+0x4C], 0\n"
"jmp %[EntityRender_Prologue_JumpBack]"
:: [EntityRender_Prologue_JumpBack] "m" (EntityRender_Prologue_JumpBack)
);
#endif
} }
static bool ShouldDisableBackfaceCulling(const CEntity* entity) static bool ShouldDisableBackfaceCulling(const CEntity* entity)
@ -1391,6 +1551,7 @@ namespace TommyFistShakeWithWeapons
__declspec(naked) static void CheckWeaponGroupHook() __declspec(naked) static void CheckWeaponGroupHook()
{ {
#ifdef _MSC_VER
_asm _asm
{ {
push dword ptr [eax] push dword ptr [eax]
@ -1399,6 +1560,17 @@ namespace TommyFistShakeWithWeapons
test al, al test al, al
ret ret
} }
#else
__asm__ volatile
(
"push dword ptr [eax]\n"
"call %[WeaponProhibitsFistShake]\n"
"add esp, 4\n"
"test al, al\n"
"ret"
:: [WeaponProhibitsFistShake] "i" (WeaponProhibitsFistShake)
);
#endif
} }
template<std::size_t Index> template<std::size_t Index>