From ccfa4eda99f56de12dafb4dcc6b6e022c27be1e0 Mon Sep 17 00:00:00 2001 From: Echo J Date: Wed, 6 Nov 2024 23:29:46 +0200 Subject: [PATCH] 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) --- SilentPatch/Maths.h | 11 ++++++++++- SilentPatchIII/SilentPatchIII.cpp | 2 +- SilentPatchSA/SilentPatchSA.cpp | 4 ++-- SilentPatchVC/SilentPatchVC.cpp | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/SilentPatch/Maths.h b/SilentPatch/Maths.h index c25c5ee..7f76c97 100644 --- a/SilentPatch/Maths.h +++ b/SilentPatch/Maths.h @@ -6,6 +6,15 @@ #include +// 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)) +#endif + constexpr double RAD_TO_DEG (180.0/M_PI); constexpr double DEG_TO_RAD (M_PI/180.0); @@ -570,4 +579,4 @@ public: return angle; } -}; \ No newline at end of file +}; diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index d95867f..ab3d8bd 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -380,7 +380,7 @@ void __declspec(naked) RadarBoundsCheckEntityBlip() extern char** ppUserFilesDir = AddressByVersion(0x580C16, 0x580F66, 0x580E66); static LARGE_INTEGER FrameTime; -__declspec(safebuffers) int32_t GetTimeSinceLastFrame() +NOBUFFERCHECKS int32_t GetTimeSinceLastFrame() { LARGE_INTEGER curTime; QueryPerformanceCounter(&curTime); diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 7eefaad..e8f767f 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -950,7 +950,7 @@ char* GetMyDocumentsPathSA() } static LARGE_INTEGER FrameTime; -__declspec(safebuffers) int32_t GetTimeSinceLastFrame() +NOBUFFERCHECKS int32_t GetTimeSinceLastFrame() { LARGE_INTEGER curTime; QueryPerformanceCounter(&curTime); @@ -3961,7 +3961,7 @@ DarkVehiclesFix4_MakeItDark: } // 1.0 ONLY ENDS HERE -__declspec(safebuffers) static int _Timers_ftol_internal( double timer, double& remainder ) +NOBUFFERCHECKS static int _Timers_ftol_internal( double timer, double& remainder ) { double integral; remainder = modf( timer + remainder, &integral ); diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index 0d952ef..f4c5571 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -699,7 +699,7 @@ void __declspec(naked) CreateInstance_BikeFix() extern char** ppUserFilesDir = AddressByVersion(0x6022AA, 0x60228A, 0x601ECA); static LARGE_INTEGER FrameTime; -__declspec(safebuffers) int32_t GetTimeSinceLastFrame() +NOBUFFERCHECKS int32_t GetTimeSinceLastFrame() { LARGE_INTEGER curTime; QueryPerformanceCounter(&curTime);