From d7ebf62c38c3426ac08a04249bd5bf73e223e459 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 5 Feb 2025 00:36:48 +0100 Subject: [PATCH] Detours: only keep duplication tracking code in debug builds This serves no purpose in release builds as all these issues must be resolved first before making a release. --- src/thirdparty/detours/include/idetour.h | 2 +- src/thirdparty/detours/src/idetour.cpp | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/thirdparty/detours/include/idetour.h b/src/thirdparty/detours/include/idetour.h index ff2b5bb7..b39e2c8d 100644 --- a/src/thirdparty/detours/include/idetour.h +++ b/src/thirdparty/detours/include/idetour.h @@ -27,7 +27,7 @@ public: }; extern std::vector g_DetourVec; -std::size_t AddDetour(IDetour* pDetour); +std::size_t AddDetour(IDetour* const pDetour); #define ADDDETOUR(x,y) static std::size_t dummy_reg_##y = AddDetour( new x() ); #define XREGISTER(x,y) ADDDETOUR(x, y) diff --git a/src/thirdparty/detours/src/idetour.cpp b/src/thirdparty/detours/src/idetour.cpp index bbd1de53..c5d3b5dc 100644 --- a/src/thirdparty/detours/src/idetour.cpp +++ b/src/thirdparty/detours/src/idetour.cpp @@ -5,7 +5,9 @@ //===========================================================================// #include #include +#ifdef _DEBUG #include +#endif // _DEBUG #include #include "../include/detours.h" #include "../include/idetour.h" @@ -15,18 +17,21 @@ // used by one class instance. This is to avoid duplicate registrations. //----------------------------------------------------------------------------- std::vector g_DetourVec; -std::unordered_set g_DetourSet; +#ifdef _DEBUG +static std::unordered_set s_DetourSet; +#endif // _DEBUG //----------------------------------------------------------------------------- // Purpose: adds a detour context to the list //----------------------------------------------------------------------------- -std::size_t AddDetour(IDetour* pDetour) +std::size_t AddDetour(IDetour* const pDetour) { - IDetour* pVFTable = reinterpret_cast(pDetour)[0]; - auto p = g_DetourSet.insert(pVFTable); // Only register if VFTable isn't already registered. +#ifdef _DEBUG + const IDetour* const pVFTable = reinterpret_cast(pDetour)[0]; + const auto p = s_DetourSet.insert(pVFTable); // Track duplicate registrations. assert(p.second); // Code bug: duplicate registration!!! (called 'REGISTER(...)' from a header file?). - p.second ? g_DetourVec.push_back(pDetour) : delete pDetour; - +#endif // _DEBUG + g_DetourVec.push_back(pDetour); return g_DetourVec.size(); }