From 6cf4b973b52d33111d1102187daccda1cd58630f Mon Sep 17 00:00:00 2001 From: A1mDev <33463136+A1mDev@users.noreply.github.com> Date: Thu, 23 Oct 2025 07:26:03 +0700 Subject: [PATCH] Add platform-specific DETOUR macros for TF2 (Linux i386) and CSGO (Windows) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR introduces a new macro, DETOUR_CUSTOM_STATIC2, to unify detour declarations across different platforms and Source Engine versions, improving code readability. - Linux i386 (TF2) → uses __attribute__((regparm(2))) - Windows (CSGO) → uses __fastcall - All other platforms → falls back to standard DETOUR_DECL_STATIC2 By consolidating detour declarations into a single macro, code is easier to read, maintain, and less error-prone across different platforms and ABIs. --- src/extension.cpp | 9 ++------- src/extension.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/extension.cpp b/src/extension.cpp index 3011160..1270232 100644 --- a/src/extension.cpp +++ b/src/extension.cpp @@ -39,13 +39,8 @@ IForward *g_pPassFwd = NULL; int gSetCollisionSolverHookId, gShouldCollideHookId; -#if defined(__linux__) && defined(__i386__) -CDetour* PassServerEntityFilterFuncDetour; -__attribute__((regparm(2))) bool (*PassServerEntityFilterFunc_Actual)(const IHandleEntity*, const IHandleEntity*); -__attribute__((regparm(2))) bool PassServerEntityFilterFunc(const IHandleEntity* pTouch, const IHandleEntity* pPass) -#else -DETOUR_DECL_STATIC2( PassServerEntityFilterFunc, bool, const IHandleEntity *, pTouch, const IHandleEntity *, pPass ) -#endif + +DETOUR_CUSTOM_STATIC2( PassServerEntityFilterFunc, bool, const IHandleEntity *, pTouch, const IHandleEntity *, pPass ) { if ( g_pPassFwd->GetFunctionCount() == 0 ) return DETOUR_STATIC_CALL( PassServerEntityFilterFunc )( pTouch, pPass ); diff --git a/src/extension.h b/src/extension.h index ff8e568..ce3faf6 100644 --- a/src/extension.h +++ b/src/extension.h @@ -107,5 +107,21 @@ inline const CBaseEntity *UTIL_EntityFromEntityHandle( const IHandleEntity *pCon return pUnk->GetBaseEntity(); } +#define DETOUR_DECL_STATIC2_REGPARM(name, ret, p1type, p1name, p2type, p2name) \ +ret (*name##_Actual)(p1type, p2type) __attribute__((regparm(2))) = NULL; \ +ret name(p1type p1name, p2type p2name) __attribute__((regparm(2))) + +#define DETOUR_DECL_STATIC2_FASTCALL(name, ret, p1type, p1name, p2type, p2name) \ +ret (__fastcall *name##_Actual)(p1type, p2type) = NULL; \ +ret __fastcall name(p1type p1name, p2type p2name) + + +#if SOURCE_ENGINE == SE_TF2 && defined(PLATFORM_LINUX) && defined(__i386__) + #define DETOUR_CUSTOM_STATIC2 DETOUR_DECL_STATIC2_REGPARM +#elif SOURCE_ENGINE == SE_CSGO && defined(PLATFORM_WINDOWS) + #define DETOUR_CUSTOM_STATIC2 DETOUR_DECL_STATIC2_FASTCALL +#else + #define DETOUR_CUSTOM_STATIC2 DETOUR_DECL_STATIC2 +#endif #endif // _INCLUDE_COLLISIONHOOK_EXTENSION_H_