From 84a737fb88a0f0a3c54c2321af4b2dc03c8255d6 Mon Sep 17 00:00:00 2001 From: Echo J Date: Wed, 6 Nov 2024 22:59:53 +0200 Subject: [PATCH] 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) --- SilentPatch/RWGTA.cpp | 10 +++++----- SilentPatchIII/SilentPatchIII.cpp | 2 +- SilentPatchSA/SilentPatchSA.cpp | 4 ++-- SilentPatchVC/SilentPatchVC.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/SilentPatch/RWGTA.cpp b/SilentPatch/RWGTA.cpp index 551db45..fc64513 100644 --- a/SilentPatch/RWGTA.cpp +++ b/SilentPatch/RWGTA.cpp @@ -78,19 +78,19 @@ bool RWGTA::Patches::TryLocateRwD3D8() try auto pfnRwD3D8SetRenderState = [] { try { // Everything except for III Steam - return static_cast(get_pattern("39 0C C5 ? ? ? ? 74 31", -8)); + return reinterpret_cast(get_pattern("39 0C C5 ? ? ? ? 74 31", -8)); } catch (const hook::txn_exception&) { // III Steam - return static_cast(get_pattern("8B 0C C5 ? ? ? ? 3B CA", -8)); + return reinterpret_cast(get_pattern("8B 0C C5 ? ? ? ? 3B CA", -8)); } }(); auto pfnRwD3D8GetRenderState = [] { try { // Everything except for III Steam - return static_cast(get_pattern("8B 0C C5 ? ? ? ? 89 0A C3", -8)); + return reinterpret_cast(get_pattern("8B 0C C5 ? ? ? ? 89 0A C3", -8)); } catch (const hook::txn_exception&) { // III Steam - return static_cast(get_pattern("8B 04 C5 ? ? ? ? 89 02 C3", -8)); + return reinterpret_cast(get_pattern("8B 04 C5 ? ? ? ? 89 02 C3", -8)); } }(); @@ -101,4 +101,4 @@ bool RWGTA::Patches::TryLocateRwD3D8() try catch (const hook::txn_exception&) { return false; -} \ No newline at end of file +} diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index 051ab2a..811751e 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -543,7 +543,7 @@ namespace Localization // ============= Call cDMAudio::IsAudioInitialised before adding one shot sounds, like in VC ============= namespace AudioInitializedFix { - auto IsAudioInitialised = static_cast(Memory::ReadCallFrom( hook::get_pattern( "E8 ? ? ? ? 84 C0 74 ? 0F B7 47 10" ) )); + auto IsAudioInitialised = reinterpret_cast(Memory::ReadCallFrom( hook::get_pattern( "E8 ? ? ? ? 84 C0 74 ? 0F B7 47 10" ) )); void* (*operatorNew)(size_t size); void* operatorNew_InitializedCheck( size_t size ) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index da3f0bd..706ba92 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -7680,7 +7680,7 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance) // Fixed escalators crash try { - orgEscalatorsUpdate = static_cast(get_pattern( "80 3D ? ? ? ? ? 74 23 56" )); + orgEscalatorsUpdate = reinterpret_cast(get_pattern( "80 3D ? ? ? ? ? 74 23 56" )); auto updateEscalators = get_pattern("80 3D ? ? ? ? ? 74 22 56"); auto removeEscalatorsForEntity = pattern( "80 7E F5 00 74 56" ).get_one(); @@ -8539,7 +8539,7 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance) ppRWD3D9 = *get_pattern("33 ED A3 ? ? ? ? 3B C5", 2 + 1); FrontEndMenuManager = *get_pattern("50 50 68 ? ? ? ? B9 ? ? ? ? E8", 7 + 1); // This has 2 identical matches, we just need one - orgGetDocumentsPath = static_cast(get_pattern( "8D 45 FC 50 68 19 00 02 00", -6 )); + orgGetDocumentsPath = reinterpret_cast(get_pattern( "8D 45 FC 50 68 19 00 02 00", -6 )); Patch(dialogBoxParam, &pDialogBoxParamA_New); Patch(setFocus, &pSetFocus_NOP); diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index c5b6ebd..d4a52c7 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -1876,7 +1876,7 @@ void InjectDelayedPatches_VC_Common( bool bHasDebugMenu, const wchar_t* wcModule // Stuff to let us (re)initialize - static void (*HUDReInitialise)() = static_cast(get_pattern("31 C0 53 0F EF C0 C6 05")); + static void (*HUDReInitialise)() = reinterpret_cast(get_pattern("31 C0 53 0F EF C0 C6 05")); // This pattern has 5 hits - first 2 are in Reinitialise, the rest is in Initialise auto reinitialise1 = pattern("C7 05 ? ? ? ? 05 00 00 00 66 C7 05 ? ? ? ? 00 00 C7 05 ? ? ? ? 00 00 00 00").count(5); @@ -2759,7 +2759,7 @@ void Patch_VC_Common() using namespace IsPlayerTargettingCharFix; auto isPlayerTargettingChar = pattern("83 7C 24 ? ? A3 ? ? ? ? 0F 84").get_one(); - auto using1stPersonWeaponMode = static_cast(get_pattern("66 83 F8 07 74 18", -7)); + auto using1stPersonWeaponMode = reinterpret_cast(get_pattern("66 83 F8 07 74 18", -7)); bool* useMouse3rdPerson = *get_pattern("80 3D ? ? ? ? ? 75 09 66 C7 05 ? ? ? ? ? ? 8B 35", 2); void* theCamera = *get_pattern("B9 ? ? ? ? 31 DB E8", 1);