Replace the UTIL_DecalTrace memory patches with a detour to make it easier to maintain

This commit is contained in:
Irineu
2026-09-20 18:12:23 -03:00
parent 537d4be911
commit 3688d62a46
2 changed files with 32 additions and 28 deletions
+26 -28
View File
@@ -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);