Compare commits

..

20 commits

Author SHA1 Message Date
Echo J.
7b111d1f10
Merge dcde67d8e2 into 47e7ab6b1f 2024-11-09 22:44:37 +01:00
Echo J
dcde67d8e2 SilentPatchVC: Explicitly define _USE_MATH_DEFINES
Not doing that makes M_PI disappear (possibly) due to rwcore.h
secretly including a math header (which breaks Maths.h on MinGW
GCC)
2024-11-07 14:16:06 +02:00
Echo J
00a48ec059 SilentPatchVC: Add GCC/Clang-specific inline assembly statements
This also includes a small wrapper to call a C++ function from inline ASM

(From III: This change also matches the MSVC statements more closely to
the GCC/Clang ones)
2024-11-07 14:16:06 +02:00
Echo J
135ceed86c SilentPatchIII: Add GCC/Clang-specific inline assembly statements
This also matches the MSVC statements more closely to the GCC/Clang
ones
2024-11-07 14:16:06 +02:00
Echo J
75004322ab SilentPatchIII: Add a missing functional header include
MinGW GCC doesn't implicitly include it either
2024-11-07 14:16:06 +02:00
Echo J
b386f216e4 SilentPatch: Add missing cmath header include
It's required for the modf() function (and it isn't implicitly
included on MinGW GCC)
2024-11-07 14:16:06 +02:00
Echo J
37a53c384a SilentPatch: Move a header include in SVF
This makes sure the fixed-width integer types are included in SVF.h
2024-11-07 14:16:06 +02:00
Echo J
52038fdd27 SilentPatch: Define a replacement for _stricmp() if needed
MinGW GCC doesn't have this MSVC-specific function
2024-11-07 14:16:06 +02:00
Echo J
8233e826ec SilentPatch: Simplify RwIm2DRenderLine function pointer declaration
MinGW GCC doesn't seem to unwind the layers of the macro define
properly (which causes it to not find the declaration type)
2024-11-07 14:15:54 +02:00
Echo J
9cf2881779 SilentPatch: Don't define certain Rw* functions if not needed
Redefining them can cause strange compile errors with MinGW GCC
2024-11-07 14:14:51 +02:00
Echo J
96e971e364 DDraw: Cast the memcpy() source argument
This works around the MinGW GCC type strictness
2024-11-07 14:14:51 +02:00
Echo J
f523ea372a DDraw: Change the forwarded name for DirectDrawCreateEx
MinGW GCC exports this function a bit differently (which doesn't
work here)
2024-11-07 14:14:51 +02:00
Echo J
b1a86e8a89 SilentPatchIII/VC/SA: Mark some function pointers as inline
MinGW GCC's linker can't find them otherwise
2024-11-07 14:14:33 +02:00
Echo J
9d988b3396 SilentPatchIII/VC: Remove extern from ppUserFilesDir variable definitions
This fixes compile warnings with MinGW GCC
2024-11-07 13:40:01 +02:00
Echo J
3eab9e4461 SilentPatchIII/VC/SA: Add GCC-compatible safebuffers equivalent
And switch to a common define for this attribute (this fixes
compile warnings on MinGW GCC)
2024-11-07 13:39:54 +02:00
Echo J
743fedfed2 Use reinterpret_cast for function pointer casts
MSVC (wrongly) allows those casts to succeed with static_cast:
https://stackoverflow.com/questions/74002657/why-cant-i-static-cast-a-void-to-a-pointer-to-function
(so adjust those casts for better compiler compatibility including MinGW GCC)
2024-11-07 13:38:07 +02:00
Echo J
a14472a16d Set Windows defines earlier
This avoids compile warnings on MinGW GCC (because standard C++
headers eventually import the Windows stuff)
2024-11-07 13:38:07 +02:00
Echo J
661336ecc9 Use lowercase names for Windows headers
This fixes missing header issues on a case-sensitive filesystem
with MinGW GCC
2024-11-07 13:37:56 +02:00
Echo J
539d923a6c Update Utils submodule
This pulls in the required cross-compile changes
2024-11-07 10:28:52 +02:00
Echo J
96e731cff9 Remove unused dllmain.cpp file
It seems to be used in the early days of SilentPatch (but it's
no longer included since the III/VC/SA code split and serves no purpose)
2024-11-07 10:26:39 +02:00
4 changed files with 60 additions and 61 deletions

View file

@ -9,10 +9,8 @@
// FIXME: Common.h might be a better place for this (but SA doesn't include it)
#ifdef _MSC_VER
#define NOBUFFERCHECKS __declspec(safebuffers)
#elif defined(__GNUC__) && !defined(__clang__)
#define NOBUFFERCHECKS __attribute__((optimize("-fno-stack-protector")))
#else
#define NOBUFFERCHECKS __attribute__((no_stack_protector))
#define NOBUFFERCHECKS __attribute__((optimize("-fno-stack-protector")))
#endif
constexpr double RAD_TO_DEG (180.0/M_PI);

View file

@ -201,7 +201,7 @@ void __declspec(naked) M16StatsFix()
{
add eax, 0x34
add ebx, 0x34
mov ecx, InstantHitsFiredByPlayer
mov ecx, [InstantHitsFiredByPlayer]
inc dword ptr [ecx]
ret
}
@ -210,17 +210,17 @@ void __declspec(naked) M16StatsFix()
(
"add eax, 0x34\n"
"add ebx, 0x34\n"
"mov ecx, %[InstantHitsFiredByPlayer]\n"
"mov ecx, [%[InstantHitsFiredByPlayer]]\n"
"inc dword ptr [ecx]\n"
"ret"
"ret\n"
:: [InstantHitsFiredByPlayer] "m" (InstantHitsFiredByPlayer)
);
#endif
}
static const float fMinusOne = -1.0f;
void __declspec(naked) HeadlightsFix()
{
static const float fMinusOne = -1.0f;
#ifdef _MSC_VER
_asm
{
@ -237,7 +237,7 @@ HeadlightsFix_DontLimit:
fld dword ptr [esp+0x708-0x690]
fabs
fld st
jmp HeadlightsFix_JumpBack
jmp [HeadlightsFix_JumpBack]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
@ -248,15 +248,15 @@ HeadlightsFix_DontLimit:
"and ah, 5\n"
"cmp ah, 1\n"
"jnz HeadlightsFix_DontLimit\n"
"fld %[fMinusOne]\n"
"fld %0\n"
"fstp dword ptr [esp+0x708-0x690]\n"
"HeadlightsFix_DontLimit:\n"
"fld dword ptr [esp+0x708-0x690]\n"
"fabs\n"
"fld st\n"
"jmp %[HeadlightsFix_JumpBack]"
:: [fMinusOne] "f" (fMinusOne),
"jmp [%[HeadlightsFix_JumpBack]]\n"
:: [fMinusOne] "m" (fMinusOne),
[HeadlightsFix_JumpBack] "m" (HeadlightsFix_JumpBack)
);
#endif
@ -354,7 +354,7 @@ void __declspec(naked) SubtitlesShadowFix()
push eax
call Recalculate
fadd dword ptr [esp+0x50+8]
fadd fShadowYSize
fadd [fShadowYSize]
jmp SubtitlesShadowFix_JumpBack
}
#elif defined(__GNUC__) || defined(__clang__)
@ -363,8 +363,8 @@ void __declspec(naked) SubtitlesShadowFix()
"push eax\n"
"call %[Recalculate]\n"
"fadd dword ptr [esp+0x50+8]\n"
"fadd %[fShadowYSize]\n"
"jmp %[SubtitlesShadowFix_JumpBack]"
"fadd [%[fShadowYSize]]\n"
"jmp %[SubtitlesShadowFix_JumpBack]\n"
:: [Recalculate] "i" (Recalculate),
[fShadowYSize] "m" (fShadowYSize),
[SubtitlesShadowFix_JumpBack] "m" (SubtitlesShadowFix_JumpBack)
@ -396,7 +396,7 @@ void __declspec(naked) III_SensResetFix()
"rep stosd\n"
"fstp dword ptr [ebp+0x198]\n"
"fstp dword ptr [ebp+0x194]\n"
"ret"
"ret\n"
);
#endif
}
@ -408,7 +408,7 @@ void __declspec(naked) RadarBoundsCheckCoordBlip()
#ifdef _MSC_VER
_asm
{
mov edx, RadarBoundsCheckCoordBlip_Count
mov edx, dword ptr [RadarBoundsCheckCoordBlip_Count]
cmp cl, byte ptr [edx]
jnb OutOfBounds
mov edx, ecx
@ -423,7 +423,7 @@ OutOfBounds:
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov edx, %[RadarBoundsCheckCoordBlip_Count]\n"
"mov edx, dword ptr [%[RadarBoundsCheckCoordBlip_Count]]\n"
"cmp cl, byte ptr [edx]\n"
"jnb OutOfBounds\n"
"mov edx, ecx\n"
@ -433,7 +433,7 @@ OutOfBounds:
"OutOfBounds:\n"
"or eax, -1\n"
"fcompp\n"
"ret"
"ret\n"
:: [RadarBoundsCheckCoordBlip_Count] "m" (RadarBoundsCheckCoordBlip_Count),
[RadarBoundsCheckCoordBlip_JumpBack] "m" (RadarBoundsCheckCoordBlip_JumpBack)
);
@ -446,7 +446,7 @@ void __declspec(naked) RadarBoundsCheckEntityBlip()
#ifdef _MSC_VER
_asm
{
mov edx, RadarBoundsCheckCoordBlip_Count
mov edx, dword ptr [RadarBoundsCheckCoordBlip_Count]
cmp cl, byte ptr [edx]
jnb OutOfBounds
mov edx, ecx
@ -460,7 +460,7 @@ void __declspec(naked) RadarBoundsCheckEntityBlip()
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov edx, %[RadarBoundsCheckCoordBlip_Count]\n"
"mov edx, dword ptr [%[RadarBoundsCheckCoordBlip_Count]]\n"
"cmp cl, byte ptr [edx]\n"
"jnb OutOfBounds2\n"
"mov edx, ecx\n"
@ -469,7 +469,7 @@ void __declspec(naked) RadarBoundsCheckEntityBlip()
"OutOfBounds2:\n"
"or eax, -1\n"
"ret"
"ret\n"
:: [RadarBoundsCheckCoordBlip_Count] "m" (RadarBoundsCheckCoordBlip_Count),
[RadarBoundsCheckEntityBlip_JumpBack] "m" (RadarBoundsCheckEntityBlip_JumpBack)
);
@ -539,7 +539,7 @@ void __declspec(naked) AutoPilotTimerFix_III()
"pop ebp\n"
"pop esi\n"
"pop ebx\n"
"ret 4"
"ret 4\n"
:: [AutoPilotTimerCalculation_III] "i" (AutoPilotTimerCalculation_III)
);
#endif
@ -723,7 +723,7 @@ namespace RemoveDriverStatusFix
"or al, 0x20\n"
"DontSetStatus:\n"
"ret"
"ret\n"
);
#endif
}
@ -778,7 +778,7 @@ namespace EvasiveDiveFix
"add esp, 8\n"
"mov ecx, ebp\n"
"ret"
"ret\n"
:: [CalculateAngle] "i" (CalculateAngle)
);
#endif
@ -799,14 +799,14 @@ namespace NullTerminatedLines
{
mov eax, [esp+4]
mov byte ptr [eax+ecx], 0
jmp orgSscanf_LoadPath
jmp [orgSscanf_LoadPath]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov eax, [esp+4]\n"
"mov byte ptr [eax+ecx], 0\n"
"jmp %[orgSscanf_LoadPath]"
"jmp [%[orgSscanf_LoadPath]]\n"
:: [orgSscanf_LoadPath] "m" (orgSscanf_LoadPath)
);
#endif
@ -820,14 +820,14 @@ namespace NullTerminatedLines
{
mov eax, [esp+4]
mov byte ptr [eax+ecx], 0
jmp orgSscanf1
jmp [orgSscanf1]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov eax, [esp+4]\n"
"mov byte ptr [eax+ecx], 0\n"
"jmp %[orgSscanf1]"
"jmp [%[orgSscanf1]]\n"
:: [orgSscanf1] "m" (orgSscanf1)
);
#endif
@ -838,7 +838,7 @@ namespace NullTerminatedLines
#ifdef _MSC_VER
_asm
{
mov ecx, gString
mov ecx, [gString]
mov byte ptr [ecx+edx], 0
mov ecx, [esi]
inc ebp
@ -848,12 +848,12 @@ namespace NullTerminatedLines
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov ecx, %[gString]\n"
"mov ecx, [%[gString]]\n"
"mov byte ptr [ecx+edx], 0\n"
"mov ecx, [esi]\n"
"inc ebp\n"
"add ecx, [esp+0xAC-0x98]\n"
"ret"
"ret\n"
:: [gString] "m" (gString)
);
#endif
@ -886,8 +886,8 @@ namespace DodoKeyboardControls
#ifdef _MSC_VER
_asm
{
call orgFindPlayerVehicle
mov ecx, bAllDodosCheat
call [orgFindPlayerVehicle]
mov ecx, [bAllDodosCheat]
cmp byte ptr [ecx], 0
je CheatDisabled
mov byte ptr [esp+0x1C-0x14], 1
@ -898,14 +898,14 @@ namespace DodoKeyboardControls
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"call %[orgFindPlayerVehicle]\n"
"mov ecx, %[bAllDodosCheat]\n"
"call [%[orgFindPlayerVehicle]]\n"
"mov ecx, [%[bAllDodosCheat]]\n"
"cmp byte ptr [ecx], 0\n"
"je CheatDisabled\n"
"mov byte ptr [esp+0x1C-0x14], 1\n"
"CheatDisabled:\n"
"ret"
"ret\n"
:: [orgFindPlayerVehicle] "m" (orgFindPlayerVehicle),
[bAllDodosCheat] "m" (bAllDodosCheat)
);
@ -969,7 +969,7 @@ namespace GenerateNewPickup_ReuseObjectFix
#ifdef _MSC_VER
_asm
{
mov eax, pPickupObject
mov eax, [pPickupObject]
add eax, ebp
mov eax, [eax]
test eax, eax
@ -978,7 +978,7 @@ namespace GenerateNewPickup_ReuseObjectFix
mov edi, eax
push edi
call offset WorldRemove
call [WorldRemove]
add esp, 4
// Call dtor
@ -990,12 +990,12 @@ namespace GenerateNewPickup_ReuseObjectFix
pop edi
NoPickup:
jmp orgGiveUsAPickUpObject
jmp [orgGiveUsAPickUpObject]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov eax, %[pPickupObject]\n"
"mov eax, [%[pPickupObject]]\n"
"add eax, ebp\n"
"mov eax, [eax]\n"
"test eax, eax\n"
@ -1004,7 +1004,7 @@ namespace GenerateNewPickup_ReuseObjectFix
"mov edi, eax\n"
"push edi\n"
"call offset %[WorldRemove]\n"
"call [%[WorldRemove]]\n"
"add esp, 4\n"
// Call dtor
@ -1016,7 +1016,7 @@ namespace GenerateNewPickup_ReuseObjectFix
"pop edi\n"
"NoPickup:\n"
"jmp %[orgGiveUsAPickUpObject]"
"jmp [%[orgGiveUsAPickUpObject]]\n"
:: [pPickupObject] "m" (pPickupObject),
[WorldRemove] "m" (WorldRemove),
[orgGiveUsAPickUpObject] "m" (orgGiveUsAPickUpObject)

View file

@ -1,5 +1,6 @@
#pragma once
#define _USE_MATH_DEFINES
#include <rwcore.h>
#include <rpworld.h>

View file

@ -695,7 +695,7 @@ void __declspec(naked) SubtitlesShadowFix()
"lea eax, [esp+0x24-0x14]\n"
"push eax\n"
"call %[Recalculate]\n"
"jmp %[SubtitlesShadowFix_JumpBack]"
"jmp %[SubtitlesShadowFix_JumpBack]\n"
:: [Recalculate] "i" (Recalculate),
[SubtitlesShadowFix_JumpBack] "m" (SubtitlesShadowFix_JumpBack)
);
@ -724,7 +724,7 @@ void __declspec(naked) CreateInstance_BikeFix()
"push eax\n"
"mov ecx, ebp\n"
"call %[CVehicleModelInfo_GetExtrasFrame]\n"
"ret"
"ret\n"
:: [CVehicleModelInfo_GetExtrasFrame] "i" (CVehicleModelInfo_GetExtrasFrame)
);
#endif
@ -793,7 +793,7 @@ void __declspec(naked) AutoPilotTimerFix_VC()
"add esp, 0x30\n"
"pop ebp\n"
"pop ebx\n"
"ret 4"
"ret 4\n"
:: [AutoPilotTimerCalculation_VC] "i" (AutoPilotTimerCalculation_VC)
);
#endif
@ -949,7 +949,7 @@ namespace SirenSwitchingFix
"IsFBIRanchOrFBICar_HighPitchSiren:\n"
"xor al, al\n"
"ret"
"ret\n"
);
#endif
}
@ -1046,7 +1046,7 @@ namespace RemoveDriverStatusFix
"or al, 0x20\n"
"DontSetStatus:\n"
"ret"
"ret\n"
);
#endif
}
@ -1126,14 +1126,14 @@ namespace NullTerminatedLines
{
mov eax, [esp+4]
mov byte ptr [eax+ecx], 0
jmp orgSscanf_LoadPath
jmp [orgSscanf_LoadPath]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
(
"mov eax, [esp+4]\n"
"mov byte ptr [eax+ecx], 0\n"
"jmp %[orgSscanf_LoadPath]"
"jmp [%[orgSscanf_LoadPath]]\n"
:: [orgSscanf_LoadPath] "m" (orgSscanf_LoadPath)
);
#endif
@ -1173,7 +1173,7 @@ namespace PickupEffectsFixes
(
"mov byte ptr [esp+0x184-0x170], 0\n"
"mov dword ptr [esp+0x184-0x174], 37\n"
"ret"
"ret\n"
);
#endif
}
@ -1210,7 +1210,7 @@ namespace PickupEffectsFixes
"Return:\n"
"mov ebx, ecx\n"
"ret"
"ret\n"
);
#endif
}
@ -1234,11 +1234,11 @@ namespace IsPlayerTargettingCharFix
{
test bl, bl
jnz ReturnToUpdateCompareFlag
mov eax, bUseMouse3rdPerson
mov eax, [bUseMouse3rdPerson]
cmp byte ptr [eax], 0
jne CmpAndReturn
mov ecx, TheCamera
call Using1stPersonWeaponMode
mov ecx, [TheCamera]
call [Using1stPersonWeaponMode]
test al, al
jz ReturnToUpdateCompareFlag
@ -1255,11 +1255,11 @@ namespace IsPlayerTargettingCharFix
(
"test bl, bl\n"
"jnz ReturnToUpdateCompareFlag\n"
"mov eax, %[bUseMouse3rdPerson]\n"
"mov eax, [%[bUseMouse3rdPerson]]\n"
"cmp byte ptr [eax], 0\n"
"jne CmpAndReturn\n"
"mov ecx, %[TheCamera]\n"
"call %[Using1stPersonWeaponMode]\n"
"mov ecx, [%[TheCamera]]\n"
"call [%[Using1stPersonWeaponMode]]\n"
"test al, al\n"
"jz ReturnToUpdateCompareFlag\n"
@ -1269,7 +1269,7 @@ namespace IsPlayerTargettingCharFix
"ReturnToUpdateCompareFlag:\n"
"xor al, al\n"
"ret"
"ret\n"
:: [bUseMouse3rdPerson] "m" (bUseMouse3rdPerson),
[TheCamera] "m" (TheCamera),
[Using1stPersonWeaponMode] "m" (Using1stPersonWeaponMode)
@ -1366,7 +1366,7 @@ namespace SelectableBackfaceCulling
push ebx
mov ebx, ecx
cmp dword ptr [ebx+0x4C], 0
jmp EntityRender_Prologue_JumpBack
jmp [EntityRender_Prologue_JumpBack]
}
#elif defined(__GNUC__) || defined(__clang__)
__asm__ volatile
@ -1374,7 +1374,7 @@ namespace SelectableBackfaceCulling
"push ebx\n"
"mov ebx, ecx\n"
"cmp dword ptr [ebx+0x4C], 0\n"
"jmp %[EntityRender_Prologue_JumpBack]"
"jmp [%[EntityRender_Prologue_JumpBack]]\n"
:: [EntityRender_Prologue_JumpBack] "m" (EntityRender_Prologue_JumpBack)
);
#endif
@ -1569,7 +1569,7 @@ namespace TommyFistShakeWithWeapons
"call %[WeaponProhibitsFistShake]\n"
"add esp, 4\n"
"test al, al\n"
"ret"
"ret\n"
:: [WeaponProhibitsFistShake] "i" (WeaponProhibitsFistShake)
);
#endif