Compare commits

..

18 commits

Author SHA1 Message Date
Echo J
a48e81a296 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-11 12:15:16 +02:00
Echo J
b742b73ad4 SilentPatchIII: Add GCC/Clang-specific inline assembly statements
This also matches the MSVC statements more closely to the GCC/Clang
ones
2024-11-11 11:48:08 +02:00
Echo J
9ab93cd79e SilentPatchIII: Add a missing functional header include
MinGW GCC doesn't implicitly include it either
2024-11-10 10:01:32 +02:00
Echo J
0d1694aeee SilentPatch: Add missing cmath header include
It's required for the modf() function (and it isn't implicitly
included on MinGW GCC)
2024-11-10 10:01:32 +02:00
Echo J
8ed97f0e7f SilentPatch: Move a header include in SVF
This makes sure the fixed-width integer types are included in SVF.h
2024-11-10 10:01:32 +02:00
Echo J
055a319374 SilentPatch: Define a replacement for _stricmp() if needed
MinGW GCC doesn't have this MSVC-specific function
2024-11-10 10:01:32 +02:00
Echo J
5459cbf037 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-10 10:01:32 +02:00
Echo J
a3f946b30f SilentPatch: Don't define certain Rw* functions if not needed
Redefining them can cause strange compile errors with MinGW GCC
2024-11-10 10:01:32 +02:00
Echo J
0c377ae10e DDraw: Cast the memcpy() source argument
This works around the MinGW GCC type strictness
2024-11-10 10:01:32 +02:00
Echo J
47ac4d7f2d DDraw: Change the forwarded name for DirectDrawCreateEx
MinGW GCC exports this function a bit differently (which doesn't
work here)
2024-11-10 10:01:32 +02:00
Echo J
c815a407da SilentPatchIII/VC/SA: Mark some function pointers as inline
MinGW GCC's linker can't find them otherwise
2024-11-10 10:01:32 +02:00
Echo J
b13b3139d6 SilentPatchIII/VC: Remove extern from ppUserFilesDir variable definitions
This fixes compile warnings with MinGW GCC
2024-11-10 10:01:32 +02:00
Echo J
ccfa4eda99 SilentPatchIII/VC/SA: Add GCC/Clang-compatible safebuffers equivalent
And switch to a common define for this attribute (this fixes
compile warnings on MinGW GCC)
2024-11-10 10:01:10 +02:00
Echo J
2b5c5b7ce0 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-10 09:55:18 +02:00
Echo J
33074475bd Set Windows defines earlier
This avoids compile warnings on MinGW GCC (because standard C++
headers eventually import the Windows stuff)
2024-11-10 09:55:18 +02:00
Echo J
e0a0200f90 Use lowercase names for Windows headers
This fixes missing header issues on a case-sensitive filesystem
with MinGW GCC
2024-11-10 09:55:18 +02:00
Echo J
c7354a8ebf 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-10 09:55:18 +02:00
Silent
47e7ab6b1f
SA: Call the game's own User Files path getter to make device_remembered.set respect Portable GTA's changes
Fixes #105
2024-11-09 22:42:32 +01:00
5 changed files with 63 additions and 62 deletions

View file

@ -9,8 +9,10 @@
// FIXME: Common.h might be a better place for this (but SA doesn't include it)
#ifdef _MSC_VER
#define NOBUFFERCHECKS __declspec(safebuffers)
#else
#elif defined(__GNUC__) && !defined(__clang__)
#define NOBUFFERCHECKS __attribute__((optimize("-fno-stack-protector")))
#else
#define NOBUFFERCHECKS __attribute__((no_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\n"
"ret"
:: [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 %0\n"
"fld %[fMinusOne]\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]]\n"
:: [fMinusOne] "m" (fMinusOne),
"jmp %[HeadlightsFix_JumpBack]"
:: [fMinusOne] "f" (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]\n"
"fadd %[fShadowYSize]\n"
"jmp %[SubtitlesShadowFix_JumpBack]"
:: [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\n"
"ret"
);
#endif
}
@ -408,7 +408,7 @@ void __declspec(naked) RadarBoundsCheckCoordBlip()
#ifdef _MSC_VER
_asm
{
mov edx, dword ptr [RadarBoundsCheckCoordBlip_Count]
mov edx, 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, dword ptr [%[RadarBoundsCheckCoordBlip_Count]]\n"
"mov edx, %[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\n"
"ret"
:: [RadarBoundsCheckCoordBlip_Count] "m" (RadarBoundsCheckCoordBlip_Count),
[RadarBoundsCheckCoordBlip_JumpBack] "m" (RadarBoundsCheckCoordBlip_JumpBack)
);
@ -446,7 +446,7 @@ void __declspec(naked) RadarBoundsCheckEntityBlip()
#ifdef _MSC_VER
_asm
{
mov edx, dword ptr [RadarBoundsCheckCoordBlip_Count]
mov edx, 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, dword ptr [%[RadarBoundsCheckCoordBlip_Count]]\n"
"mov edx, %[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\n"
"ret"
:: [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\n"
"ret 4"
:: [AutoPilotTimerCalculation_III] "i" (AutoPilotTimerCalculation_III)
);
#endif
@ -723,7 +723,7 @@ namespace RemoveDriverStatusFix
"or al, 0x20\n"
"DontSetStatus:\n"
"ret\n"
"ret"
);
#endif
}
@ -778,7 +778,7 @@ namespace EvasiveDiveFix
"add esp, 8\n"
"mov ecx, ebp\n"
"ret\n"
"ret"
:: [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]]\n"
"jmp %[orgSscanf_LoadPath]"
:: [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]]\n"
"jmp %[orgSscanf1]"
:: [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\n"
"ret"
:: [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\n"
"ret"
:: [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 [WorldRemove]
call offset 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 [%[WorldRemove]]\n"
"call offset %[WorldRemove]\n"
"add esp, 4\n"
// Call dtor
@ -1016,7 +1016,7 @@ namespace GenerateNewPickup_ReuseObjectFix
"pop edi\n"
"NoPickup:\n"
"jmp [%[orgGiveUsAPickUpObject]]\n"
"jmp %[orgGiveUsAPickUpObject]"
:: [pPickupObject] "m" (pPickupObject),
[WorldRemove] "m" (WorldRemove),
[orgGiveUsAPickUpObject] "m" (orgGiveUsAPickUpObject)

View file

@ -2614,7 +2614,7 @@ namespace NewResolutionSelectionDialog
static bool ShouldSkipDeviceSelection()
{
char cTmpPath[MAX_PATH];
PathCombineA(cTmpPath, GetMyDocumentsPathSA(), SettingsFileName);
PathCombineA(cTmpPath, orgGetDocumentsPath(), SettingsFileName);
bool bSkip = false;
@ -2631,7 +2631,7 @@ namespace NewResolutionSelectionDialog
static void RememberDeviceSelection(bool bDoNotShowAgain)
{
char cTmpPath[MAX_PATH];
PathCombineA(cTmpPath, GetMyDocumentsPathSA(), SettingsFileName);
PathCombineA(cTmpPath, orgGetDocumentsPath(), SettingsFileName);
FILE* hFile = nullptr;
if (fopen_s(&hFile, cTmpPath, "w") == 0)

View file

@ -1,6 +1,5 @@
#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]\n"
"jmp %[SubtitlesShadowFix_JumpBack]"
:: [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\n"
"ret"
:: [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\n"
"ret 4"
:: [AutoPilotTimerCalculation_VC] "i" (AutoPilotTimerCalculation_VC)
);
#endif
@ -949,7 +949,7 @@ namespace SirenSwitchingFix
"IsFBIRanchOrFBICar_HighPitchSiren:\n"
"xor al, al\n"
"ret\n"
"ret"
);
#endif
}
@ -1046,7 +1046,7 @@ namespace RemoveDriverStatusFix
"or al, 0x20\n"
"DontSetStatus:\n"
"ret\n"
"ret"
);
#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]]\n"
"jmp %[orgSscanf_LoadPath]"
:: [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\n"
"ret"
);
#endif
}
@ -1210,7 +1210,7 @@ namespace PickupEffectsFixes
"Return:\n"
"mov ebx, ecx\n"
"ret\n"
"ret"
);
#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\n"
"ret"
:: [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]]\n"
"jmp %[EntityRender_Prologue_JumpBack]"
:: [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\n"
"ret"
:: [WeaponProhibitsFistShake] "i" (WeaponProhibitsFistShake)
);
#endif