From 3688d62a46661dd593d575fc9a990d4d606d3c7f Mon Sep 17 00:00:00 2001 From: Irineu Date: Sun, 20 Sep 2026 18:12:23 -0300 Subject: [PATCH] Replace the UTIL_DecalTrace memory patches with a detour to make it easier to maintain --- extension.cpp | 54 +++++++++++++++++++++---------------------- gamedata/CSSFixes.txt | 6 +++++ 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/extension.cpp b/extension.cpp index 3c875d8..1677af0 100644 --- a/extension.cpp +++ b/extension.cpp @@ -290,34 +290,6 @@ static struct SrcdsPatch "x?xx", (unsigned char *)"\x90\x90\x8B\x09", "bin/dedicated_srv.so" - }, - // 17: void CBaseGrenade::Explode( trace_t *pTrace, int bitsDamageType ) NOP out UTIL_DecalTrace( pTrace, "Scorch" ); to stop grenades from causing - // "Too many indices for index buffer. Tell a programmer". Grenades cause decals on too many faces for the client to handle. - { - "_ZN12CBaseGrenade7ExplodeEP10CGameTracei", - (unsigned char *)"\xE8\xEA\x8E\x21\x00", - "xxxxx", - (unsigned char *)"\x90\x90\x90\x90\x90", - "cstrike/bin/server_srv.so" - }, - - // 18: void CPlantedC4::Explode( trace_t *pTrace, int bitsDamageType ) NOP out UTIL_DecalTrace( pTrace, "Scorch" ); same reason as 17. - { - "_ZN10CPlantedC47ExplodeEP10CGameTracei", - (unsigned char *)"\xE8\x72\xBE\xEB\xFF", - "xxxxx", - (unsigned char *)"\x90\x90\x90\x90\x90", - "cstrike/bin/server_srv.so" - }, - // 19: void CEnvExplosion::InputExplode( inputdata_t &inputdata ) NOP out UTIL_DecalTrace( &tr, "Scorch" ); same reason as 17. - { - "_ZN13CEnvExplosion12InputExplodeER11inputdata_t", - (unsigned char *)"\xE8\xEA\x2A\x1A\x00", - "xxxxx", - (unsigned char *)"\x90\x90\x90\x90\x90", - "cstrike/bin/server_srv.so", - 0x800, - 1 } }; @@ -370,6 +342,8 @@ CDetour *g_pDetour_CTraceFilterSimple = NULL; CDetour *g_pDetour_KeyValue = NULL; CDetour *g_pDetour_FireBullets = NULL; CDetour *g_pDetour_SwingOrStab = NULL; +CDetour *g_pDetour_UTIL_DecalTrace = NULL; + int g_SH_SkipTwoEntitiesShouldHitEntity = 0; int g_SH_SimpleShouldHitEntity = 0; @@ -575,6 +549,15 @@ DETOUR_DECL_MEMBER3(DETOUR_CTraceFilterSimple, void, const IHandleEntity *, pass *(uintptr_t *)this = g_CTraceFilterNoNPCsOrPlayer; } +DETOUR_DECL_STATIC2(DETOUR_UTIL_DecalTrace, void, void *, pTrace, char *, decalName) +{ + // to stop grenades from causing "Too many indices for index buffer. Tell a programmer". Grenades cause decals on too many faces for the client to handle. + if (strcmp(decalName, "Scorch") == 0) + return; + + DETOUR_STATIC_CALL(DETOUR_UTIL_DecalTrace)(pTrace, decalName); +} + /* Make bullets ignore teammates */ char *g_pPhysboxToClientMap = NULL; bool g_InFireBullets = false; @@ -801,6 +784,14 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) return false; } + g_pDetour_UTIL_DecalTrace = DETOUR_CREATE_STATIC(DETOUR_UTIL_DecalTrace, "UTIL_DecalTrace"); + if (g_pDetour_UTIL_DecalTrace == NULL) + { + snprintf(error, maxlength, "Could not create detour for UTIL_DecalTrace"); + SDK_OnUnload(); + return false; + } + g_pDetour_InputTestActivator->EnableDetour(); g_pDetour_PostConstructor->EnableDetour(); g_pDetour_CreateEntityByName->EnableDetour(); @@ -810,6 +801,7 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) g_pDetour_KeyValue->EnableDetour(); g_pDetour_FireBullets->EnableDetour(); g_pDetour_SwingOrStab->EnableDetour(); + g_pDetour_UTIL_DecalTrace->EnableDetour(); // Find VTable for CTraceFilterSkipTwoEntities uintptr_t pCTraceFilterSkipTwoEntities; @@ -1012,6 +1004,12 @@ void CSSFixes::SDK_OnUnload() g_pDetour_SwingOrStab = NULL; } + if (g_pDetour_UTIL_DecalTrace != NULL) + { + g_pDetour_UTIL_DecalTrace->Destroy(); + g_pDetour_UTIL_DecalTrace = NULL; + } + if(g_SH_SkipTwoEntitiesShouldHitEntity) SH_REMOVE_HOOK_ID(g_SH_SkipTwoEntitiesShouldHitEntity); diff --git a/gamedata/CSSFixes.txt b/gamedata/CSSFixes.txt index b04b961..660d47f 100644 --- a/gamedata/CSSFixes.txt +++ b/gamedata/CSSFixes.txt @@ -81,6 +81,12 @@ "library" "server" "linux" "@_ZN6CKnife11SwingOrStabEb" } + + "UTIL_DecalTrace" + { + "library" "server" + "linux" "@_Z15UTIL_DecalTraceP10CGameTracePKc" + } } } } -- 2.47.3