From 7e96e7f759856afe2994965070563cf8f2817a92 Mon Sep 17 00:00:00 2001 From: Vauff Date: Fri, 30 Oct 2026 00:49:01 -0400 Subject: [PATCH 1/9] Fix round restarts randomly duplicating default ents into world layers --- gamedata/cs2fixes.jsonc | 7 +++++++ src/detours.cpp | 12 ++++++++++++ src/detours.h | 8 +++++++- src/virtual_hooks.cpp | 10 ++++++++++ src/virtual_hooks.h | 2 ++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/gamedata/cs2fixes.jsonc b/gamedata/cs2fixes.jsonc index 2881febf..e030dd6c 100644 --- a/gamedata/cs2fixes.jsonc +++ b/gamedata/cs2fixes.jsonc @@ -353,6 +353,13 @@ "library": "worldrenderer", "windows": "48 89 5C 24 ? 48 89 54 24 ? 55 56 57 48 81 EC", "linux": "55 48 89 E5 41 56 41 55 41 54 49 89 FC 53 48 89 F3 48 83 EC ? F6 46" + }, + // Called in CCSGameRules::CleanUpMap with filter "cs_respawn" + "CGameEntitySystem_CreateEntities": + { + "library": "server", + "windows": "4C 89 4C 24 ? 89 54 24 ? 48 89 4C 24 ? 55 53 56 57 41 54 41 55 41 56 41 57 48 81 EC", + "linux": "55 48 89 E5 41 57 41 56 48 8D 85 ? ? ? ? 49 89 D6" } }, "Offsets": diff --git a/src/detours.cpp b/src/detours.cpp index 5f08d116..86f7fe8d 100644 --- a/src/detours.cpp +++ b/src/detours.cpp @@ -87,6 +87,7 @@ KHOOK_MEMBER(CCSGameRules_GoToIntermission, Detour_CCSGameRules_GoToIntermission KHOOK_MEMBER(SetBeamOrigin, Detour_SetBeamOrigin, nullptr); KHOOK_MEMBER(SetBeamEndPos, Detour_SetBeamEndPos, nullptr); KHOOK_MEMBER(CWorldRendererMgr_CreateWorld_Internal, nullptr, Detour_CWorldRendererMgr_CreateWorld_Internal_Post); +KHOOK_MEMBER(CGameEntitySystem_CreateEntities, Detour_CGameEntitySystem_CreateEntities, nullptr); std::vector& GetKHookList() { @@ -938,3 +939,14 @@ KHook::Return Detour_CWorldRendererMgr_CreateWorld_Internal_Po return {KHook::Action::Ignore}; } + +std::set g_setUnloadingSpawnGroups; + +KHook::Return Detour_CGameEntitySystem_CreateEntities(CGameEntitySystem* pThis, SpawnGroupHandle_t hSpawnGroup, const CUtlVector* pKeyValues, const matrix3x4a_t* pSpawnOffset, const char* pszFilter, CreateSpawnGroupType_t createType, const void* pNameFixup, CUtlVector* pOutEntities, bool bUnk) +{ + if (!pszFilter || V_strcmp(pszFilter, "cs_respawn") || !g_setUnloadingSpawnGroups.contains(hSpawnGroup)) + return {KHook::Action::Ignore}; + + // CCSGameRules::CleanUpMap respawns the default entity lump of every spawngroup that hasn't finished unloading, so don't spawn into ones pending unload + return {KHook::Action::Supersede, nullptr}; +} diff --git a/src/detours.h b/src/detours.h index b98b6eed..8372d01b 100644 --- a/src/detours.h +++ b/src/detours.h @@ -19,9 +19,11 @@ #pragma once #include "cs2_sdk/entityio.h" +#include "engine2/isource2engine.h" #include "khook.hpp" #include "map.h" -#include + +#include class CCheckTransmitInfo; class IRecipientFilter; @@ -54,11 +56,14 @@ class Vector; class QAngle; class CEconItemView; class CCSGameRules; +class CGameEntitySystem; class CBeam; class IWorldRendererMgr; struct CPulseArgumentPack; struct CTakeDamageResult; +extern std::set g_setUnloadingSpawnGroups; + enum class AcquireMethod { PickUp, @@ -117,3 +122,4 @@ KHook::Return Detour_CCSGameRules_GoToIntermission(CCSGameRules* pThis, bo KHook::Return Detour_SetBeamOrigin(CBeam* pThis, const Vector* pVecWorldPosition); KHook::Return Detour_SetBeamEndPos(CBeam* pThis, const Vector* pVecWorldPosition); KHook::Return Detour_CWorldRendererMgr_CreateWorld_Internal_Post(IWorldRendererMgr* pThis, CSingleWorldRep* pSingleWorld); +KHook::Return Detour_CGameEntitySystem_CreateEntities(CGameEntitySystem* pThis, SpawnGroupHandle_t hSpawnGroup, const CUtlVector* pKeyValues, const matrix3x4a_t* pSpawnOffset, const char* pszFilter, CreateSpawnGroupType_t createType, const void* pNameFixup, CUtlVector* pOutEntities, bool bUnk); diff --git a/src/virtual_hooks.cpp b/src/virtual_hooks.cpp index 9566311f..303f9e9d 100644 --- a/src/virtual_hooks.cpp +++ b/src/virtual_hooks.cpp @@ -26,6 +26,7 @@ #include "cs_gameevents.pb.h" #include "cstrike15_usermessages.pb.h" #include "ctimer.h" +#include "detours.h" #include "engine2/iengineservicemgr.h" #include "engine2/inetworkgameserver.h" #include "engine2/ivengineserver2.h" @@ -74,6 +75,7 @@ KHOOK_VIRTUAL(StartupServer, &INetworkServerService::StartupServer, g_pNetworkSe KHOOK_VIRTUAL(CheckTransmit, &ISource2GameEntities::CheckTransmit, g_pSource2GameEntities, nullptr, Hook_CheckTransmit_Post); KHOOK_VIRTUAL(DispatchConCommand, &ICvar::DispatchConCommand, g_pCVar, Hook_DispatchConCommand, nullptr); KHOOK_VIRTUAL(SwitchToLoop, &IEngineServiceMgr::SwitchToLoop, g_pEngineServiceMgr, Hook_SwitchToLoop, nullptr); +KHOOK_VIRTUAL(UnloadSpawnGroup, &IVEngineServer2::UnloadSpawnGroup, g_pEngineServer2, Hook_UnloadSpawnGroup, nullptr); KHook::Virtual createWorkshopMapGroupHook(0U, Hook_CreateWorkshopMapGroup, nullptr); KHook::Virtual loadEventsFromFileHook(&IGameEventManager2::LoadEventsFromFile, Hook_LoadEventsFromFile, nullptr); @@ -524,6 +526,7 @@ KHook::Return Hook_StartupServer_Post(INetworkServerService* pThis, const g_pPanoramaVoteHandler->Reset(); g_pVoteManager->VoteManager_Init(); g_pIdleSystem->Reset(); + g_setUnloadingSpawnGroups.clear(); INetworkStringTable* pInfoPanelTable = g_pNetworkStringTableServer->FindTable("InfoPanel"); @@ -723,6 +726,13 @@ KHook::Return Hook_SwitchToLoop(IEngineServiceMgr* pThis, const char* pszL return {KHook::Action::Ignore}; } +KHook::Return Hook_UnloadSpawnGroup(IVEngineServer2* pThis, SpawnGroupHandle_t hSpawnGroup, int unloadOption) +{ + g_setUnloadingSpawnGroups.insert(hSpawnGroup); + + return {KHook::Action::Ignore}; +} + KHook::Return Hook_CreateWorkshopMapGroup(IGameTypes* pThis, const char* name, const CUtlStringList& mapList) { if (g_cvarVoteManagerEnable.Get() && g_pMapVoteSystem->IsMapListLoaded()) diff --git a/src/virtual_hooks.h b/src/virtual_hooks.h index 12721c94..d0a398e6 100644 --- a/src/virtual_hooks.h +++ b/src/virtual_hooks.h @@ -41,6 +41,7 @@ class CVPhys2World; class CTriggerGravity; class CGameConfig; class IEngineServiceMgr; +class IVEngineServer2; void InitVirtualHooks(); void RemoveVirtualHooks(); @@ -63,6 +64,7 @@ KHook::Return Hook_CheckTransmit_Post(ISource2GameEntities* pThis, CCheckT CBitVec<16384>&, const Entity2Networkable_t** pNetworkables, const uint16* pEntityIndicies, int nEntities); KHook::Return Hook_DispatchConCommand(ICvar* pThis, ConCommandRef cmd, const CCommandContext& ctx, const CCommand& args); KHook::Return Hook_SwitchToLoop(IEngineServiceMgr* pThis, const char* pszLoopModeName, KeyValues* pKV, uint32 nId, const char* pszAddonName, bool bUnk); +KHook::Return Hook_UnloadSpawnGroup(IVEngineServer2* pThis, SpawnGroupHandle_t hSpawnGroup, int unloadOption); KHook::Return Hook_CreateWorkshopMapGroup(IGameTypes* pThis, const char* name, const CUtlStringList& mapList); KHook::Return Hook_LoadEventsFromFile(IGameEventManager2* pThis, const char* filename, bool bSearchAll); KHook::Return Hook_ProcessVoiceData(CServerSideClient* pClient, const CNetMessagePB& msg); From 54be99032645a0648d461b9982bca3e0f4560138 Mon Sep 17 00:00:00 2001 From: Vauff Date: Fri, 30 Oct 2026 20:45:16 -0400 Subject: [PATCH 2/9] Replace SayTextFilter signatures --- gamedata/cs2fixes.jsonc | 14 ---- src/detours.cpp | 142 ---------------------------------------- src/detours.h | 2 - src/virtual_hooks.cpp | 124 +++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+), 158 deletions(-) diff --git a/gamedata/cs2fixes.jsonc b/gamedata/cs2fixes.jsonc index e030dd6c..54a9363f 100644 --- a/gamedata/cs2fixes.jsonc +++ b/gamedata/cs2fixes.jsonc @@ -1,20 +1,6 @@ { "Signatures": { - // Called from Host_Say - "UTIL_SayTextFilter": - { - "library": "server", - "windows": "48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 49 8B D8", - "linux": "55 48 8D 05 ? ? ? ? 48 89 E5 41 57 41 56 4C 8D 75 ? 41 55 41 89 CD" - }, - // Called from Host_Say - "UTIL_SayText2Filter": - { - "library": "server", - "windows": "48 89 5C 24 ? 48 89 74 24 ? 48 89 7C 24 ? 55 41 56 41 57 48 8D 6C 24 ? 48 81 EC ? ? ? ? 41 8B D8", - "linux": "55 48 8D 05 ? ? ? ? 48 89 E5 41 57 41 89 D7 31 D2" - }, // idk a good way to find this again, i just brute forced the vtable. offset is 136 on CTriggerPush "TriggerPush_Touch": { diff --git a/src/detours.cpp b/src/detours.cpp index 86f7fe8d..8090f1b6 100644 --- a/src/detours.cpp +++ b/src/detours.cpp @@ -49,15 +49,12 @@ #include "map_votes.h" #include "mapmigrations.h" #include "playermanager.h" -#include "tier0/splitstring.h" #include "tier0/vprof.h" #include "votemanager.h" #include "zombiereborn.h" #include "tier0/memdbgon.h" -KHOOK_FUNCTION(UTIL_SayTextFilter, Detour_UTIL_SayTextFilter, nullptr); -KHOOK_FUNCTION(UTIL_SayText2Filter, Detour_UTIL_SayText2Filter, nullptr); KHOOK_MEMBER(TriggerPush_Touch, Detour_TriggerPush_Touch, nullptr); KHOOK_MEMBER(CBaseEntity_TakeDamageOld, Detour_CBaseEntity_TakeDamageOld, Detour_CBaseEntity_TakeDamageOld_Post); KHOOK_MEMBER(CCSPlayer_WeaponServices_CanUse, Detour_CCSPlayer_WeaponServices_CanUse, nullptr); @@ -260,145 +257,6 @@ KHook::Return Detour_TriggerPush_Touch(CTriggerPush* pPush, CBaseEntity* p return {KHook::Action::Supersede}; } -KHook::Return SayChatMessageWithTimer(IRecipientFilter& filter, const char* pText, CCSPlayerController* pPlayer, uint64 eMessageType) -{ - VPROF("SayChatMessageWithTimer"); - - char buf[256]; - - // Filter console message - remove non-alphanumeric chars and convert to lowercase - uint32 uiTextLength = strlen(pText); - uint32 uiFilteredTextLength = 0; - char filteredText[256]; - - for (uint32 i = 0; i < uiTextLength; i++) - { - if (pText[i] >= 'A' && pText[i] <= 'Z') - filteredText[uiFilteredTextLength++] = pText[i] + 32; - if (pText[i] == ' ' || (pText[i] >= '0' && pText[i] <= '9') || (pText[i] >= 'a' && pText[i] <= 'z')) - filteredText[uiFilteredTextLength++] = pText[i]; - } - filteredText[uiFilteredTextLength] = '\0'; - - // Split console message into words seperated by the space character - CSplitString words(filteredText, " "); - - // Word count includes the first word "Console:" at index 0, first relevant word is at index 1 - int iWordCount = words.Count(); - uint32 uiTriggerTimerLength = 0; - - if (iWordCount == 2) - uiTriggerTimerLength = V_StringToUint32(words.Element(1), 0, NULL, NULL, PARSING_FLAG_SKIP_WARNING); - - for (int i = 1; i < iWordCount && uiTriggerTimerLength == 0; i++) - { - uint32 uiCurrentValue = V_StringToUint32(words.Element(i), 0, NULL, NULL, PARSING_FLAG_SKIP_WARNING); - uint32 uiNextWordLength = 0; - char* pNextWord = NULL; - - if (i + 1 < iWordCount) - { - pNextWord = words.Element(i + 1); - uiNextWordLength = strlen(pNextWord); - } - - // Case: ... X sec(onds) ... or ... X s ... or ... X min(utes) ... - if (pNextWord != NULL && uiCurrentValue > 0) - { - if (uiNextWordLength == 1) - { - if (pNextWord[0] == 's') - uiTriggerTimerLength = uiCurrentValue; - } - else if (uiNextWordLength > 2) - { - if (pNextWord[0] == 's' && pNextWord[1] == 'e' && pNextWord[2] == 'c') - uiTriggerTimerLength = uiCurrentValue; - if (pNextWord[0] == 'm' && pNextWord[1] == 'i' && pNextWord[2] == 'n') - uiTriggerTimerLength = uiCurrentValue * 60; - } - } - - // Case: ... Xs - only support up to 3 digit numbers (in seconds) for this timer parse method - if (uiCurrentValue == 0) - { - char* pCurrentWord = words.Element(i); - uint32 uiCurrentScanLength = MIN(strlen(pCurrentWord), 4); - - for (uint32 j = 0; j < uiCurrentScanLength; j++) - { - if (pCurrentWord[j] >= '0' && pCurrentWord[j] <= '9') - continue; - - if (pCurrentWord[j] == 's') - { - pCurrentWord[j] = '\0'; - uiTriggerTimerLength = V_StringToUint32(pCurrentWord, 0, NULL, NULL, PARSING_FLAG_SKIP_WARNING); - } - break; - } - } - } - - float fCurrentRoundClock = g_pGameRules->m_iRoundTime - (GetGlobals()->curtime - g_pGameRules->m_fRoundStartTime.Get().GetTime()); - - // Only display trigger time if the timer is greater than 4 seconds, and time expires within the round - if ((uiTriggerTimerLength > 4) && (fCurrentRoundClock > uiTriggerTimerLength)) - { - int iTriggerTime = fCurrentRoundClock - uiTriggerTimerLength; - - // Round timer to nearest whole second - if ((int)(fCurrentRoundClock - 0.5f) == (int)fCurrentRoundClock) - iTriggerTime++; - - int mins = iTriggerTime / 60; - int secs = iTriggerTime % 60; - - V_snprintf(buf, sizeof(buf), "%s %s %s %2d:%02d", " \7CONSOLE:\4", pText + sizeof("Console:"), "\x10- @", mins, secs); - } - else - V_snprintf(buf, sizeof(buf), "%s %s", " \7CONSOLE:\4", pText + sizeof("Console:")); - - return KHook::Recall(nullptr, {KHook::Action::Ignore}, filter, buf, pPlayer, eMessageType); -} - -CConVar g_cvarEnableTriggerTimer("cs2f_trigger_timer_enable", FCVAR_NONE, "Whether to process countdown messages said by Console (e.g. Hold for 10 seconds) and append the round time where the countdown resolves", false); - -KHook::Return Detour_UTIL_SayTextFilter(IRecipientFilter& filter, const char* pText, CCSPlayerController* pPlayer, int eMessageType) -{ - if (pPlayer) - return {KHook::Action::Ignore}; - - if (g_cvarEnableTriggerTimer.Get() && GetGlobals() && g_pGameRules) - return SayChatMessageWithTimer(filter, pText, pPlayer, eMessageType); - - char buf[256]; - V_snprintf(buf, sizeof(buf), "%s %s", " \7CONSOLE:\4", pText + sizeof("Console:")); - - return KHook::Recall(nullptr, {KHook::Action::Ignore}, filter, buf, pPlayer, eMessageType); -} - -KHook::Return Detour_UTIL_SayText2Filter( - IRecipientFilter& filter, - CCSPlayerController* pEntity, - int eMessageType, - const char* msg_name, - const char* param1, - const char* param2, - const char* param3, - const char* param4) -{ -#ifdef _DEBUG - CPlayerSlot slot = filter.GetRecipientIndex(0); - CCSPlayerController* target = CCSPlayerController::FromSlot(slot); - - if (target) - Message("Chat from %s to %s: %s\n", param1, target->GetPlayerName(), param2); -#endif - - return KHook::Recall(nullptr, {KHook::Action::Ignore}, filter, pEntity, eMessageType, msg_name, param1, param2, param3, param4); -} - KHook::Return Detour_CCSPlayer_WeaponServices_CanUse(CCSPlayer_WeaponServices* pWeaponServices, CBasePlayerWeapon* pPlayerWeapon) { if (g_cvarEnableEntWatch.Get() && !EW_Detour_CCSPlayer_WeaponServices_CanUse(pWeaponServices, pPlayerWeapon)) diff --git a/src/detours.h b/src/detours.h index 8372d01b..1e46b9ea 100644 --- a/src/detours.h +++ b/src/detours.h @@ -88,8 +88,6 @@ enum class AcquireResult KHook::Return Detour_CBaseEntity_TakeDamageOld(CBaseEntity* pThis, CTakeDamageInfo* pInfo, CTakeDamageResult* pResult); KHook::Return Detour_CBaseEntity_TakeDamageOld_Post(CBaseEntity* pThis, CTakeDamageInfo* pInfo, CTakeDamageResult* pResult); KHook::Return Detour_TriggerPush_Touch(CTriggerPush* pPush, CBaseEntity* pOther); -KHook::Return Detour_UTIL_SayTextFilter(IRecipientFilter&, const char*, CCSPlayerController*, int); -KHook::Return Detour_UTIL_SayText2Filter(IRecipientFilter&, CCSPlayerController*, int, const char*, const char*, const char*, const char*, const char*); KHook::Return Detour_CCSPlayer_WeaponServices_CanUse(CCSPlayer_WeaponServices*, CBasePlayerWeapon*); KHook::Return Detour_CCSPlayer_WeaponServices_EquipWeapon(CCSPlayer_WeaponServices*, CBasePlayerWeapon*); KHook::Return Detour_CEntityIdentity_AcceptInput(CEntityIdentity* pThis, CUtlSymbolLarge* pInputName, CEntityInstance* pActivator, CEntityInstance* pCaller, variant_t* value, CPulseArgumentPack* pArgumentPack, CPulseInputParamMap* pParamMap); diff --git a/src/virtual_hooks.cpp b/src/virtual_hooks.cpp index 303f9e9d..9bd29caf 100644 --- a/src/virtual_hooks.cpp +++ b/src/virtual_hooks.cpp @@ -34,6 +34,7 @@ #include "entities.h" #include "entity/ccsplayercontroller.h" #include "entity/cgameplayerequip.h" +#include "entity/cgamerules.h" #include "entity/customhudlayout.h" #include "entity/services.h" #include "entitylistener.h" @@ -52,6 +53,7 @@ #include "panoramavote.h" #include "playermanager.h" #include "tier0/icvar.h" +#include "tier0/splitstring.h" #include "tier0/vprof.h" #include "usermessages.pb.h" #include "votemanager.h" @@ -371,6 +373,110 @@ KHook::Return Hook_ClientSvcUserMessage(IServerGameClients* pThis, CPlayer return {KHook::Action::Ignore}; } +void SayChatMessageWithTimer(CUserMessageSayText* pMsg) +{ + VPROF("SayChatMessageWithTimer"); + + const char* pText = pMsg->text().c_str(); + char buf[256]; + + // Filter console message - remove non-alphanumeric chars and convert to lowercase + uint32 uiTextLength = strlen(pText); + uint32 uiFilteredTextLength = 0; + char filteredText[256]; + + for (uint32 i = 0; i < uiTextLength; i++) + { + if (pText[i] >= 'A' && pText[i] <= 'Z') + filteredText[uiFilteredTextLength++] = pText[i] + 32; + if (pText[i] == ' ' || (pText[i] >= '0' && pText[i] <= '9') || (pText[i] >= 'a' && pText[i] <= 'z')) + filteredText[uiFilteredTextLength++] = pText[i]; + } + filteredText[uiFilteredTextLength] = '\0'; + + // Split console message into words seperated by the space character + CSplitString words(filteredText, " "); + + // Word count includes the first word "Console:" at index 0, first relevant word is at index 1 + int iWordCount = words.Count(); + uint32 uiTriggerTimerLength = 0; + + if (iWordCount == 2) + uiTriggerTimerLength = V_StringToUint32(words.Element(1), 0, NULL, NULL, PARSING_FLAG_SKIP_WARNING); + + for (int i = 1; i < iWordCount && uiTriggerTimerLength == 0; i++) + { + uint32 uiCurrentValue = V_StringToUint32(words.Element(i), 0, NULL, NULL, PARSING_FLAG_SKIP_WARNING); + uint32 uiNextWordLength = 0; + char* pNextWord = NULL; + + if (i + 1 < iWordCount) + { + pNextWord = words.Element(i + 1); + uiNextWordLength = strlen(pNextWord); + } + + // Case: ... X sec(onds) ... or ... X s ... or ... X min(utes) ... + if (pNextWord != NULL && uiCurrentValue > 0) + { + if (uiNextWordLength == 1) + { + if (pNextWord[0] == 's') + uiTriggerTimerLength = uiCurrentValue; + } + else if (uiNextWordLength > 2) + { + if (pNextWord[0] == 's' && pNextWord[1] == 'e' && pNextWord[2] == 'c') + uiTriggerTimerLength = uiCurrentValue; + if (pNextWord[0] == 'm' && pNextWord[1] == 'i' && pNextWord[2] == 'n') + uiTriggerTimerLength = uiCurrentValue * 60; + } + } + + // Case: ... Xs - only support up to 3 digit numbers (in seconds) for this timer parse method + if (uiCurrentValue == 0) + { + char* pCurrentWord = words.Element(i); + uint32 uiCurrentScanLength = MIN(strlen(pCurrentWord), 4); + + for (uint32 j = 0; j < uiCurrentScanLength; j++) + { + if (pCurrentWord[j] >= '0' && pCurrentWord[j] <= '9') + continue; + + if (pCurrentWord[j] == 's') + { + pCurrentWord[j] = '\0'; + uiTriggerTimerLength = V_StringToUint32(pCurrentWord, 0, NULL, NULL, PARSING_FLAG_SKIP_WARNING); + } + break; + } + } + } + + float fCurrentRoundClock = g_pGameRules->m_iRoundTime - (GetGlobals()->curtime - g_pGameRules->m_fRoundStartTime.Get().GetTime()); + + // Only display trigger time if the timer is greater than 4 seconds, and time expires within the round + if ((uiTriggerTimerLength > 4) && (fCurrentRoundClock > uiTriggerTimerLength)) + { + int iTriggerTime = fCurrentRoundClock - uiTriggerTimerLength; + + // Round timer to nearest whole second + if ((int)(fCurrentRoundClock - 0.5f) == (int)fCurrentRoundClock) + iTriggerTime++; + + int mins = iTriggerTime / 60; + int secs = iTriggerTime % 60; + + V_snprintf(buf, sizeof(buf), "%s %s %s %2d:%02d", " \7CONSOLE:\4", pText + sizeof("Console:"), "\x10- @", mins, secs); + } + else + V_snprintf(buf, sizeof(buf), "%s %s", " \7CONSOLE:\4", pText + sizeof("Console:")); + + pMsg->set_text(buf); +} + +CConVar g_cvarEnableTriggerTimer("cs2f_trigger_timer_enable", FCVAR_NONE, "Whether to process countdown messages said by Console (e.g. Hold for 10 seconds) and append the round time where the countdown resolves", false); CConVar g_cvarBlockParticleMsgs("cs2f_block_particle_msgs", FCVAR_NONE, "Whether to block CUserMsg_ParticleManager messages to fix lag/crashes, experimental", false); KHook::Return Hook_PostEventAbstract(IGameEventSystem* pThis, CSplitScreenSlot nSlot, bool bLocalOnly, int nClientCount, const uint64* clients, @@ -496,6 +602,24 @@ KHook::Return Hook_PostEventAbstract(IGameEventSystem* pThis, CSplitScreen *(uint64*)clients &= ~silenceSoundMask; } } + else if (info->m_MessageId == UM_SayText) + { + auto msg = const_cast(pData)->ToPB(); + + if (msg->playerindex() != -1 || V_strncmp(msg->text().c_str(), "Console: ", 9)) + return {KHook::Action::Ignore}; + + if (g_cvarEnableTriggerTimer.Get() && GetGlobals() && g_pGameRules) + { + SayChatMessageWithTimer(msg); + } + else + { + char buf[256]; + V_snprintf(buf, sizeof(buf), "%s %s", " \7CONSOLE:\4", msg->text().c_str() + sizeof("Console:")); + msg->set_text(buf); + } + } else if (info->m_MessageId == UM_ParticleManager) { // These messages were previously unused, but recently started being used for weapon particles in the AG2 update From 7f83e8f3d510067557634454f29754f00e343672 Mon Sep 17 00:00:00 2001 From: Vauff Date: Sat, 31 Oct 2026 12:26:23 -0400 Subject: [PATCH 3/9] Update VS solution for new build scripts/SDK --- CS2Fixes.vcxproj | 29 ++++++++++++++++------------- CS2Fixes.vcxproj.filters | 31 ++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/CS2Fixes.vcxproj b/CS2Fixes.vcxproj index 5e73c528..3e5dce0d 100644 --- a/CS2Fixes.vcxproj +++ b/CS2Fixes.vcxproj @@ -124,7 +124,7 @@ NotUsing pch.h stdcpp20 - build/cs2fixes.cs2/windows-x86_64;src/utils;src/cs2_sdk;sdk/public;sdk/public/tier0;sdk/game/shared;sdk/game/server;sdk/public/tier1;sdk/public/mathlib;$(MMSOURCE112)/core;$(MMSOURCE112)/third_party/khook/include;$(MMSOURCE_DEV)/core;$(MMSOURCE_DEV)/third_party/khook/include;sdk/public/entity2;sdk/public/game/server;sdk/thirdparty/protobuf-3.21.8/src;$(SolutionDir);%(AdditionalIncludeDirectories) + $(SolutionDir);$(MMSOURCE_DEV)/core;$(MMSOURCE_DEV)/third_party/khook/include;sdk/thirdparty/protobuf-3.21.8/src;sdk/public;sdk/public/engine2;sdk/public/mathlib;sdk/public/tier0;sdk/public/entity2;sdk/game/shared;sdk/common;src/cs2_sdk;src/utils;public;build/cs2fixes.2.cs2/windows-x86_64;%(AdditionalIncludeDirectories) %(UndefinePreprocessorDefinitions) MultiThreadedDebug true @@ -150,7 +150,7 @@ NotUsing pch.h stdcpp20 - build/cs2fixes.cs2/windows-x86_64;src/utils;src/cs2_sdk;sdk/public;sdk/public/tier0;sdk/game/shared;sdk/game/server;sdk/public/tier1;sdk/public/mathlib;$(MMSOURCE112)/core;$(MMSOURCE112)/third_party/khook/include;$(MMSOURCE_DEV)/core;$(MMSOURCE_DEV)/third_party/khook/include;sdk/public/entity2;sdk/public/game/server;sdk/thirdparty/protobuf-3.21.8/src;$(SolutionDir);%(AdditionalIncludeDirectories) + $(SolutionDir);$(MMSOURCE_DEV)/core;$(MMSOURCE_DEV)/third_party/khook/include;sdk/thirdparty/protobuf-3.21.8/src;sdk/public;sdk/public/engine2;sdk/public/mathlib;sdk/public/tier0;sdk/public/entity2;sdk/game/shared;sdk/common;src/cs2_sdk;src/utils;public;build/cs2fixes.2.cs2/windows-x86_64;%(AdditionalIncludeDirectories) MultiThreaded %(UndefinePreprocessorDefinitions) true @@ -169,17 +169,20 @@ - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/CS2Fixes.vcxproj.filters b/CS2Fixes.vcxproj.filters index 6f6d191c..ad674533 100644 --- a/CS2Fixes.vcxproj.filters +++ b/CS2Fixes.vcxproj.filters @@ -140,37 +140,46 @@ Source Files - + Source Files\protobuf - + Source Files\protobuf - + Source Files\protobuf - + Source Files\protobuf - + Source Files\protobuf - + Source Files\protobuf - + Source Files\protobuf - + Source Files\protobuf - + Source Files\protobuf - + Source Files\protobuf - + + Source Files\protobuf + + + Source Files\protobuf + + + Source Files\protobuf + + Source Files\protobuf From 7254db1fcb1cfa03afddfd0a3e141cee2e70bf2a Mon Sep 17 00:00:00 2001 From: Vauff Date: Sat, 31 Oct 2026 20:05:52 -0400 Subject: [PATCH 4/9] Remove KV1 discord bot config converter --- src/discord.cpp | 75 ++----------------------------------------------- src/discord.h | 3 -- 2 files changed, 2 insertions(+), 76 deletions(-) diff --git a/src/discord.cpp b/src/discord.cpp index c5b2f3f7..39f8c8ab 100644 --- a/src/discord.cpp +++ b/src/discord.cpp @@ -20,8 +20,6 @@ #include "discord.h" #include "common.h" #include "httpmanager.h" -#include "interfaces/interfaces.h" -#include "tier0/keyvalues.h" #include #include "vendor/nlohmann/json.hpp" @@ -82,13 +80,8 @@ bool CDiscordBotManager::LoadDiscordBotsConfig() if (!jsonFile.is_open()) { - if (!ConvertDiscordBotsKVToJSON()) - { - Panic("Failed to open %s and convert KV1 discordbots.cfg to JSON format, discord bots are not loaded!\n", pszJsonPath); - return false; - } - - jsonFile.open(szPath); + Panic("Failed to open %s, discord bots are not loaded!\n", pszJsonPath); + return false; } ordered_json jDiscordBots = ordered_json::parse(jsonFile, nullptr, false, true); @@ -123,67 +116,3 @@ bool CDiscordBotManager::LoadDiscordBotsConfig() return true; } - -// TODO: Remove this once servers have been given a few months to update cs2fixes -bool CDiscordBotManager::ConvertDiscordBotsKVToJSON() -{ - KeyValues* pKV = new KeyValues("discordbots"); - KeyValues::AutoDelete autoDelete(pKV); - - const char* pszPath = "addons/cs2fixes/configs/discordbots.cfg"; - if (!pKV->LoadFromFile(g_pFullFileSystem, pszPath)) - { - Panic("Failed to load %s\n", pszPath); - return false; - } - - ordered_json jDiscordBots; - - for (KeyValues* pKey = pKV->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey()) - { - const char* pszWebhookUrl = pKey->GetString("webhook", nullptr); - - if (!pszWebhookUrl) - { - Panic("Discord bot entry %s is missing 'webhook' key\n", pKey->GetName()); - return false; - } - - ordered_json jDiscordBot; - jDiscordBot["webhook"] = pszWebhookUrl; - - if (pKey->FindKey("avatar")) - jDiscordBot["avatar"] = pKey->GetString("avatar", ""); - - jDiscordBot["override_name"] = pKey->GetBool("override_name", false); - jDiscordBots[pKey->GetName()] = jDiscordBot; - } - - const char* pszJsonPath = "addons/cs2fixes/configs/discordbots.jsonc"; - const char* pszKVConfigRenamePath = "addons/cs2fixes/configs/discordbots_old.cfg"; - char szPath[MAX_PATH]; - V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszJsonPath); - std::ofstream jsonFile(szPath); - - if (!jsonFile.is_open()) - { - Panic("Failed to open %s\n", pszJsonPath); - return false; - } - - jsonFile << std::setfill('\t') << std::setw(1) << jDiscordBots << std::endl; - - char szKVRenamePath[MAX_PATH]; - V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszPath); - V_snprintf(szKVRenamePath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszKVConfigRenamePath); - - std::rename(szPath, szKVRenamePath); - - // remove old cfg example if it exists - const char* pszKVExamplePath = "addons/cs2fixes/configs/discordbots.cfg.example"; - V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszKVExamplePath); - std::remove(szPath); - - Message("Successfully converted KV1 discordbots.cfg to JSON format at %s\n", pszJsonPath); - return true; -} diff --git a/src/discord.h b/src/discord.h index f3113b10..ea97ad96 100644 --- a/src/discord.h +++ b/src/discord.h @@ -53,9 +53,6 @@ class CDiscordBotManager void PostDiscordMessage(const char* pszDiscordBotName, const char* pszMessage); bool LoadDiscordBotsConfig(); - // TODO: Remove this once servers have been given a few months to update cs2fixes - bool ConvertDiscordBotsKVToJSON(); - private: std::vector> m_vecDiscordBots; }; From 900959e0abcbdd152ad246baad86bb83fe369398 Mon Sep 17 00:00:00 2001 From: Vauff Date: Sat, 31 Oct 2026 21:07:13 -0400 Subject: [PATCH 5/9] Migrate remaining KV1 ZR configs to JSONC --- PackageScript | 4 +- configs/zr/hitgroups.cfg.example | 47 ----- configs/zr/hitgroups.jsonc.example | 42 +++++ configs/zr/weapons.cfg.example | 273 ----------------------------- configs/zr/weapons.jsonc.example | 271 ++++++++++++++++++++++++++++ src/zombiereborn.cpp | 181 ++++++++++++++++--- src/zombiereborn.h | 6 + 7 files changed, 482 insertions(+), 342 deletions(-) delete mode 100644 configs/zr/hitgroups.cfg.example create mode 100644 configs/zr/hitgroups.jsonc.example delete mode 100644 configs/zr/weapons.cfg.example create mode 100644 configs/zr/weapons.jsonc.example diff --git a/PackageScript b/PackageScript index c6aab278..86e3fabf 100644 --- a/PackageScript +++ b/PackageScript @@ -119,8 +119,8 @@ for task in MMSPlugin.tasks: builder.AddCopy(os.path.join('cfg', 'cs2fixes.cfg'), cfg_folder) builder.AddCopy(os.path.join('cfg', 'maps', 'de_somemap.cfg'), mapcfg_folder) builder.AddCopy(os.path.join('configs', 'zr', 'playerclass.jsonc.example'), zr_folder) - builder.AddCopy(os.path.join('configs', 'zr', 'weapons.cfg.example'), zr_folder) - builder.AddCopy(os.path.join('configs', 'zr', 'hitgroups.cfg.example'), zr_folder) + builder.AddCopy(os.path.join('configs', 'zr', 'weapons.jsonc.example'), zr_folder) + builder.AddCopy(os.path.join('configs', 'zr', 'hitgroups.jsonc.example'), zr_folder) builder.AddCopy(os.path.join('configs', 'entwatch', 'maps', 'template.jsonc'), ew_maps_folder) builder.AddCopy(os.path.join('gamedata', 'cs2fixes.jsonc'), gamedata_folder) diff --git a/configs/zr/hitgroups.cfg.example b/configs/zr/hitgroups.cfg.example deleted file mode 100644 index 3a324929..00000000 --- a/configs/zr/hitgroups.cfg.example +++ /dev/null @@ -1,47 +0,0 @@ -// Attribute: Values: Description: -// ---------------------------------------------------------------------------- -// knockback decimal The knockback multiplier for this hitgroup. - -"Hitgroups" -{ - "Generic" - { - "knockback" "1.0" - } - "Head" - { - "knockback" "1.0" - } - "Chest" - { - "knockback" "1.0" - } - "Stomach" - { - "knockback" "1.0" - } - "LeftArm" - { - "knockback" "1.0" - } - "RightArm" - { - "knockback" "1.0" - } - "LeftLeg" - { - "knockback" "1.0" - } - "RightLeg" - { - "knockback" "1.0" - } - "Neck" - { - "knockback" "1.0" - } - "Gear" - { - "knockback" "1.0" - } -} diff --git a/configs/zr/hitgroups.jsonc.example b/configs/zr/hitgroups.jsonc.example new file mode 100644 index 00000000..47f6ceaa --- /dev/null +++ b/configs/zr/hitgroups.jsonc.example @@ -0,0 +1,42 @@ +{ + "Generic": + { + "knockback": 1.0 // The knockback multiplier for this hitgroup + }, + "Head": + { + "knockback": 1.0 + }, + "Chest": + { + "knockback": 1.0 + }, + "Stomach": + { + "knockback": 1.0 + }, + "LeftArm": + { + "knockback": 1.0 + }, + "RightArm": + { + "knockback": 1.0 + }, + "LeftLeg": + { + "knockback": 1.0 + }, + "RightLeg": + { + "knockback": 1.0 + }, + "Neck": + { + "knockback": 1.0 + }, + "Gear": + { + "knockback": 1.0 + } +} diff --git a/configs/zr/weapons.cfg.example b/configs/zr/weapons.cfg.example deleted file mode 100644 index 0d6d36f1..00000000 --- a/configs/zr/weapons.cfg.example +++ /dev/null @@ -1,273 +0,0 @@ -// CSGO Weapons -"Weapons" -{ - //"weapon classname w/o weapon_" - //{ - // "enabled" "0" //whether this weapon can be used by human - // "knockback" "0.0" //knockback scale for when humans shoot a zombie using this weapon - //} - - // Gear - "c4" - { - "enabled" "1" - } - "knife" - { - "enabled" "1" - "knockback" "1.0" - } - "taser" - { - "enabled" "0" - } - "shield" - { - "enabled" "0" - } - "bumpmine" - { - "enabled" "0" - } - "breachcharge" - { - "enabled" "0" - } - "kevlar" - { - "enabled" "1" - } - "assaultsuit" - { - "enabled" "0" - } - "defuser" - { - "enabled" "0" - } - - // Grenade - "decoy" - { - "enabled" "0" - } - "flashbang" - { - "enabled" "0" - } - "healthshot" - { - "enabled" "0" - } - "hegrenade" - { - "enabled" "1" - "knockback" "3.0" - } - "hegrenade_projectile" // hegrenade explosion knockback - { - "enabled" "1" - "knockback" "3.0" - } - "inferno" // incgrenade and molotov flames knockback - { - "enabled" "1" - "knockback" "5.0" - } - "incgrenade" - { - "enabled" "1" - "knockback" "5.0" - } - "molotov" - { - "enabled" "1" - "knockback" "5.0" - } - "smokegrenade" - { - "enabled" "0" - } - "tagrenade" - { - "enabled" "0" - } - - // Heavy - "m249" - { - "enabled" "1" - "knockback" "1.0" - } - "mag7" - { - "enabled" "1" - "knockback" "1.0" - } - "negev" - { - "enabled" "1" - "knockback" "1.0" - } - "nova" - { - "enabled" "1" - "knockback" "1.0" - } - "sawedoff" - { - "enabled" "1" - "knockback" "1.0" - } - "xm1014" - { - "enabled" "1" - "knockback" "1.0" - } - - // Pistol - "cz75a" - { - "enabled" "1" - "knockback" "1.0" - } - "deagle" - { - "enabled" "1" - "knockback" "1.0" - } - "elite" - { - "enabled" "1" - "knockback" "1.0" - } - "fiveseven" - { - "enabled" "1" - "knockback" "1.0" - } - "glock" - { - "enabled" "1" - "knockback" "1.0" - } - "hkp2000" - { - "enabled" "1" - "knockback" "1.0" - } - "p250" - { - "enabled" "1" - "knockback" "1.0" - } - "revolver" - { - "enabled" "1" - "knockback" "1.0" - } - "tec9" - { - "enabled" "1" - "knockback" "1.0" - } - "usp_silencer" - { - "enabled" "1" - "knockback" "1.0" - } - - // Rifle - "ak47" - { - "enabled" "1" - "knockback" "1.0" - } - "aug" - { - "enabled" "1" - "knockback" "1.0" - } - "awp" - { - "enabled" "1" - "knockback" "1.0" - } - "famas" - { - "enabled" "1" - "knockback" "1.0" - } - "g3sg1" - { - "enabled" "1" - "knockback" "1.0" - } - "galilar" - { - "enabled" "1" - "knockback" "1.0" - } - "m4a1" - { - "enabled" "1" - "knockback" "1.0" - } - "m4a1_silencer" - { - "enabled" "1" - "knockback" "1.0" - } - "scar20" - { - "enabled" "1" - "knockback" "1.0" - } - "sg556" - { - "enabled" "1" - "knockback" "1.0" - } - "ssg08" - { - "enabled" "1" - "knockback" "1.0" - } - - // SMG - "bizon" - { - "enabled" "1" - "knockback" "1.0" - } - "mac10" - { - "enabled" "1" - "knockback" "1.0" - } - "mp5sd" - { - "enabled" "1" - "knockback" "1.0" - } - "mp7" - { - "enabled" "1" - "knockback" "1.0" - } - "mp9" - { - "enabled" "1" - "knockback" "1.0" - } - "p90" - { - "enabled" "1" - "knockback" "1.0" - } - "ump45" - { - "enabled" "1" - "knockback" "1.0" - } -} \ No newline at end of file diff --git a/configs/zr/weapons.jsonc.example b/configs/zr/weapons.jsonc.example new file mode 100644 index 00000000..cf7fb0ea --- /dev/null +++ b/configs/zr/weapons.jsonc.example @@ -0,0 +1,271 @@ +{ + // "weapon classname w/o weapon_": + // { + // "enabled": false, // whether this weapon can be used by humans + // "knockback": 0.0 // knockback scale for when humans shoot a zombie using this weapon + // }, + + // Gear + "c4": + { + "enabled": true + }, + "knife": + { + "enabled": true, + "knockback": 1.0 + }, + "taser": + { + "enabled": false + }, + "shield": + { + "enabled": false + }, + "bumpmine": + { + "enabled": false + }, + "breachcharge": + { + "enabled": false + }, + "kevlar": + { + "enabled": true + }, + "assaultsuit": + { + "enabled": false + }, + "defuser": + { + "enabled": false + }, + + // Grenade + "decoy": + { + "enabled": false + }, + "flashbang": + { + "enabled": false + }, + "healthshot": + { + "enabled": false + }, + "hegrenade": + { + "enabled": true, + "knockback": 3.0 + }, + "hegrenade_projectile": // hegrenade explosion knockback + { + "enabled": true, + "knockback": 3.0 + }, + "inferno": // incgrenade and molotov flames knockback + { + "enabled": true, + "knockback": 5.0 + }, + "incgrenade": + { + "enabled": true, + "knockback": 5.0 + }, + "molotov": + { + "enabled": true, + "knockback": 5.0 + }, + "smokegrenade": + { + "enabled": false + }, + "tagrenade": + { + "enabled": false + }, + + // Heavy + "m249": + { + "enabled": true, + "knockback": 1.0 + }, + "mag7": + { + "enabled": true, + "knockback": 1.0 + }, + "negev": + { + "enabled": true, + "knockback": 1.0 + }, + "nova": + { + "enabled": true, + "knockback": 1.0 + }, + "sawedoff": + { + "enabled": true, + "knockback": 1.0 + }, + "xm1014": + { + "enabled": true, + "knockback": 1.0 + }, + + // Pistol + "cz75a": + { + "enabled": true, + "knockback": 1.0 + }, + "deagle": + { + "enabled": true, + "knockback": 1.0 + }, + "elite": + { + "enabled": true, + "knockback": 1.0 + }, + "fiveseven": + { + "enabled": true, + "knockback": 1.0 + }, + "glock": + { + "enabled": true, + "knockback": 1.0 + }, + "hkp2000": + { + "enabled": true, + "knockback": 1.0 + }, + "p250": + { + "enabled": true, + "knockback": 1.0 + }, + "revolver": + { + "enabled": true, + "knockback": 1.0 + }, + "tec9": + { + "enabled": true, + "knockback": 1.0 + }, + "usp_silencer": + { + "enabled": true, + "knockback": 1.0 + }, + + // Rifle + "ak47": + { + "enabled": true, + "knockback": 1.0 + }, + "aug": + { + "enabled": true, + "knockback": 1.0 + }, + "awp": + { + "enabled": true, + "knockback": 1.0 + }, + "famas": + { + "enabled": true, + "knockback": 1.0 + }, + "g3sg1": + { + "enabled": true, + "knockback": 1.0 + }, + "galilar": + { + "enabled": true, + "knockback": 1.0 + }, + "m4a1": + { + "enabled": true, + "knockback": 1.0 + }, + "m4a1_silencer": + { + "enabled": true, + "knockback": 1.0 + }, + "scar20": + { + "enabled": true, + "knockback": 1.0 + }, + "sg556": + { + "enabled": true, + "knockback": 1.0 + }, + "ssg08": + { + "enabled": true, + "knockback": 1.0 + }, + + // SMG + "bizon": + { + "enabled": true, + "knockback": 1.0 + }, + "mac10": + { + "enabled": true, + "knockback": 1.0 + }, + "mp5sd": + { + "enabled": true, + "knockback": 1.0 + }, + "mp7": + { + "enabled": true, + "knockback": 1.0 + }, + "mp9": + { + "enabled": true, + "knockback": 1.0 + }, + "p90": + { + "enabled": true, + "knockback": 1.0 + }, + "ump45": + { + "enabled": true, + "knockback": 1.0 + } +} diff --git a/src/zombiereborn.cpp b/src/zombiereborn.cpp index a180a260..24a4c577 100644 --- a/src/zombiereborn.cpp +++ b/src/zombiereborn.cpp @@ -736,34 +736,106 @@ void ZR_OnLevelInit() void ZRWeaponConfig::LoadWeaponConfig() { m_WeaponMap.clear(); - KeyValues* pKV = new KeyValues("Weapons"); - KeyValues::AutoDelete autoDelete(pKV); - const char* pszPath = "addons/cs2fixes/configs/zr/weapons.cfg"; + const char* pszJsonPath = "addons/cs2fixes/configs/zr/weapons.jsonc"; + char szPath[MAX_PATH]; + V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszJsonPath); + std::ifstream jsonFile(szPath); - if (!pKV->LoadFromFile(g_pFullFileSystem, pszPath)) + if (!jsonFile.is_open()) + { + if (!ConvertWeaponsKVToJSON()) + { + Panic("Failed to open %s and convert KV1 weapons.cfg to JSON format, weapons are not loaded!\n", pszJsonPath); + return; + } + + jsonFile.open(szPath); + } + + ordered_json jsonWeapons = ordered_json::parse(jsonFile, nullptr, false, true); + + if (jsonWeapons.is_discarded()) { - Warning("Failed to load %s\n", pszPath); + Panic("Failed parsing JSON from %s, weapons are not loaded!\n", pszJsonPath); return; } - for (KeyValues* pKey = pKV->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey()) + + for (auto& [szWeaponName, jsonWeapon] : jsonWeapons.items()) { - const char* pszWeaponName = pKey->GetName(); - bool bEnabled = pKey->GetBool("enabled", false); - float flKnockback = pKey->GetFloat("knockback", 1.0f); - Message("%s knockback: %f\n", pszWeaponName, flKnockback); + bool bEnabled = jsonWeapon.value("enabled", false); + float flKnockback = jsonWeapon.value("knockback", 1.0f); + Message("%s knockback: %f\n", szWeaponName.c_str(), flKnockback); std::shared_ptr weapon = std::make_shared(); + if (!bEnabled) continue; weapon->flKnockback = flKnockback; - m_WeaponMap.insert(std::make_pair(hash_32_fnv1a_const(pszWeaponName), weapon)); + m_WeaponMap.insert(std::make_pair(hash_32_fnv1a_const(szWeaponName.c_str()), weapon)); } return; } +// TODO: Remove this once servers have been given a few months to update cs2fixes +bool ZRWeaponConfig::ConvertWeaponsKVToJSON() +{ + KeyValues* pKV = new KeyValues("Weapons"); + KeyValues::AutoDelete autoDelete(pKV); + + const char* pszPath = "addons/cs2fixes/configs/zr/weapons.cfg"; + + if (!pKV->LoadFromFile(g_pFullFileSystem, pszPath)) + { + Panic("Failed to load %s\n", pszPath); + return false; + } + + ordered_json jsonWeapons; + + for (KeyValues* pKey = pKV->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey()) + { + ordered_json jsonWeapon; + + // combating float imprecision when writing to .jsonc + if (pKey->FindKey("knockback")) + jsonWeapon["knockback"] = std::strtod(pKey->GetString("knockback"), nullptr); + + jsonWeapon["enabled"] = pKey->GetBool("enabled", false); + jsonWeapons[pKey->GetName()] = jsonWeapon; + } + + const char* pszJsonPath = "addons/cs2fixes/configs/zr/weapons.jsonc"; + const char* pszKVConfigRenamePath = "addons/cs2fixes/configs/zr/weapons_old.cfg"; + char szPath[MAX_PATH]; + V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszJsonPath); + std::ofstream jsonFile(szPath); + + if (!jsonFile.is_open()) + { + Panic("Failed to open %s\n", pszJsonPath); + return false; + } + + jsonFile << std::setfill('\t') << std::setw(1) << jsonWeapons << std::endl; + + char szKVRenamePath[MAX_PATH]; + V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszPath); + V_snprintf(szKVRenamePath, sizeof(szKVRenamePath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszKVConfigRenamePath); + + std::rename(szPath, szKVRenamePath); + + // remove old cfg example if it exists + const char* pszKVExamplePath = "addons/cs2fixes/configs/zr/weapons.cfg.example"; + V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszKVExamplePath); + std::remove(szPath); + + Message("Successfully converted KV1 weapons.cfg to JSON format at %s\n", pszJsonPath); + return true; +} + std::shared_ptr ZRWeaponConfig::FindWeapon(const char* pszWeaponName) { if (V_strlen(pszWeaponName) > 7 && !V_strncasecmp(pszWeaponName, "weapon_", 7)) @@ -782,20 +854,35 @@ std::shared_ptr ZRWeaponConfig::FindWeapon(const char* pszWeaponName) void ZRHitgroupConfig::LoadHitgroupConfig() { m_HitgroupMap.clear(); - KeyValues* pKV = new KeyValues("Hitgroups"); - KeyValues::AutoDelete autoDelete(pKV); - const char* pszPath = "addons/cs2fixes/configs/zr/hitgroups.cfg"; + const char* pszJsonPath = "addons/cs2fixes/configs/zr/hitgroups.jsonc"; + char szPath[MAX_PATH]; + V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszJsonPath); + std::ifstream jsonFile(szPath); - if (!pKV->LoadFromFile(g_pFullFileSystem, pszPath)) + if (!jsonFile.is_open()) + { + if (!ConvertHitgroupsKVToJSON()) + { + Panic("Failed to open %s and convert KV1 hitgroups.cfg to JSON format, hitgroups are not loaded!\n", pszJsonPath); + return; + } + + jsonFile.open(szPath); + } + + ordered_json jsonHitgroups = ordered_json::parse(jsonFile, nullptr, false, true); + + if (jsonHitgroups.is_discarded()) { - Warning("Failed to load %s\n", pszPath); + Panic("Failed parsing JSON from %s, hitgroups are not loaded!\n", pszJsonPath); return; } - for (KeyValues* pKey = pKV->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey()) + + for (auto& [szHitgroupName, jsonHitgroup] : jsonHitgroups.items()) { - const char* pszHitgroupName = pKey->GetName(); - float flKnockback = pKey->GetFloat("knockback", 1.0f); + const char* pszHitgroupName = szHitgroupName.c_str(); + float flKnockback = jsonHitgroup.value("knockback", 1.0f); int iIndex = -1; if (!V_strcasecmp(pszHitgroupName, "Generic")) @@ -821,7 +908,7 @@ void ZRHitgroupConfig::LoadHitgroupConfig() if (iIndex == -1) { - Panic("Failed to load hitgroup %s, invalid name!", pszHitgroupName); + Panic("Failed to load hitgroup %s, invalid name!\n", pszHitgroupName); continue; } @@ -835,6 +922,60 @@ void ZRHitgroupConfig::LoadHitgroupConfig() return; } +// TODO: Remove this once servers have been given a few months to update cs2fixes +bool ZRHitgroupConfig::ConvertHitgroupsKVToJSON() +{ + KeyValues* pKV = new KeyValues("Hitgroups"); + KeyValues::AutoDelete autoDelete(pKV); + + const char* pszPath = "addons/cs2fixes/configs/zr/hitgroups.cfg"; + + if (!pKV->LoadFromFile(g_pFullFileSystem, pszPath)) + { + Panic("Failed to load %s\n", pszPath); + return false; + } + + ordered_json jsonHitgroups; + + for (KeyValues* pKey = pKV->GetFirstSubKey(); pKey; pKey = pKey->GetNextKey()) + { + ordered_json jsonHitgroup; + + // combating float imprecision when writing to .jsonc + jsonHitgroup["knockback"] = std::strtod(pKey->GetString("knockback", "1.0"), nullptr); + jsonHitgroups[pKey->GetName()] = jsonHitgroup; + } + + const char* pszJsonPath = "addons/cs2fixes/configs/zr/hitgroups.jsonc"; + const char* pszKVConfigRenamePath = "addons/cs2fixes/configs/zr/hitgroups_old.cfg"; + char szPath[MAX_PATH]; + V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszJsonPath); + std::ofstream jsonFile(szPath); + + if (!jsonFile.is_open()) + { + Panic("Failed to open %s\n", pszJsonPath); + return false; + } + + jsonFile << std::setfill('\t') << std::setw(1) << jsonHitgroups << std::endl; + + char szKVRenamePath[MAX_PATH]; + V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszPath); + V_snprintf(szKVRenamePath, sizeof(szKVRenamePath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszKVConfigRenamePath); + + std::rename(szPath, szKVRenamePath); + + // remove old cfg example if it exists + const char* pszKVExamplePath = "addons/cs2fixes/configs/zr/hitgroups.cfg.example"; + V_snprintf(szPath, sizeof(szPath), "%s%s%s", Plat_GetGameDirectory(), "/csgo/", pszKVExamplePath); + std::remove(szPath); + + Message("Successfully converted KV1 hitgroups.cfg to JSON format at %s\n", pszJsonPath); + return true; +} + std::shared_ptr ZRHitgroupConfig::FindHitgroupIndex(int iIndex) { // Message("We are finding hitgroup index with index: %d and index is: %d\n", iIndex, index); diff --git a/src/zombiereborn.h b/src/zombiereborn.h index 12825f70..cf8f255e 100644 --- a/src/zombiereborn.h +++ b/src/zombiereborn.h @@ -252,6 +252,9 @@ class ZRWeaponConfig void LoadWeaponConfig(); std::shared_ptr FindWeapon(const char* pszWeaponName); + // TODO: Remove this once servers have been given a few months to update cs2fixes + bool ConvertWeaponsKVToJSON(); + private: std::map> m_WeaponMap; }; @@ -264,6 +267,9 @@ class ZRHitgroupConfig void LoadHitgroupConfig(); std::shared_ptr FindHitgroupIndex(int iIndex); + // TODO: Remove this once servers have been given a few months to update cs2fixes + bool ConvertHitgroupsKVToJSON(); + private: std::map> m_HitgroupMap; }; From 0787c87d82b5b93c8bfc2f66b2aa5b1aae5c584e Mon Sep 17 00:00:00 2001 From: Vauff Date: Mon, 2 Nov 2026 00:27:26 -0500 Subject: [PATCH 6/9] Filter movers out of push traces to fix lag on moving entities Co-authored-by: 2vg --- CS2Fixes.vcxproj | 1 + CS2Fixes.vcxproj.filters | 3 ++ cfg/cs2fixes.cfg | 1 + gamedata/cs2fixes.jsonc | 21 ++++++++++++ src/cs2_sdk/pushentity.h | 49 ++++++++++++++++++++++++++ src/detours.cpp | 74 ++++++++++++++++++++++++++++++++++++++++ src/detours.h | 6 ++++ src/virtual_hooks.cpp | 27 +++++++++++++++ src/virtual_hooks.h | 3 ++ 9 files changed, 185 insertions(+) create mode 100644 src/cs2_sdk/pushentity.h diff --git a/CS2Fixes.vcxproj b/CS2Fixes.vcxproj index 3e5dce0d..3a744236 100644 --- a/CS2Fixes.vcxproj +++ b/CS2Fixes.vcxproj @@ -274,6 +274,7 @@ + diff --git a/CS2Fixes.vcxproj.filters b/CS2Fixes.vcxproj.filters index ad674533..db253c67 100644 --- a/CS2Fixes.vcxproj.filters +++ b/CS2Fixes.vcxproj.filters @@ -412,6 +412,9 @@ Header Files\cs2_sdk + + Header Files\cs2_sdk + Header Files diff --git a/cfg/cs2fixes.cfg b/cfg/cs2fixes.cfg index 2ed7948d..a511f24f 100644 --- a/cfg/cs2fixes.cfg +++ b/cfg/cs2fixes.cfg @@ -28,6 +28,7 @@ cs2f_cvarwhitelist_enable 0 // Whether to enable the custom ConVar whitelist f cs2f_block_particle_msgs 0 // Whether to block CUserMsg_ParticleManager messages to fix lag/crashes, experimental cs2f_disable_setmodel 0 // Whether to disable SetModel usage from maps (custom input, cs_script function) cs2f_allow_duck_spam 0 // Whether to allow duck spamming by removing the duck slowdown, clients will only partially predict [0 = disabled, 1 = both teams, 2 = T only, 3 = CT only] +cs2f_fix_pusher_solid_toggle 0 // Whether to filter movers out of push traces, fixes lag with many players on moving entities cs2f_beacon_particle "particles/cs2fixes/admin_beacon.vpcf" // .vpcf file to be precached and used for player beacon cs2f_motd_url "" // Server MOTD URL, shows up as a "Server Website" button in scoreboard diff --git a/gamedata/cs2fixes.jsonc b/gamedata/cs2fixes.jsonc index 54a9363f..43880b3a 100644 --- a/gamedata/cs2fixes.jsonc +++ b/gamedata/cs2fixes.jsonc @@ -346,6 +346,27 @@ "library": "server", "windows": "4C 89 4C 24 ? 89 54 24 ? 48 89 4C 24 ? 55 53 56 57 41 54 41 55 41 56 41 57 48 81 EC", "linux": "55 48 89 E5 41 57 41 56 48 8D 85 ? ? ? ? 49 89 D6" + }, + // "Interpenetrating entities! (%s and %s)" + "SpeculativelyCheckPush": + { + "library": "server", + "windows": "44 88 4C 24 ? 55 41 54 41 55 41 56 41 57 48 81 EC", + "linux": "55 48 89 E5 41 57 41 56 4C 8D 35 ? ? ? ? 41 55 49 89 D5 41 54 49 89 FC" + }, + // Called right before the player push in function with string "Pushing linear hard!", two instances of this + "UnlinkPusherList": + { + "library": "server", + "windows": "48 89 74 24 ? 57 48 83 EC ? 8B 41 ? 48 8B F1 83 E8 ? 48 63 F8 78 ? 48 89 5C 24 ? 48 8D 1C 7F 48 C1 E3 ? 66 66 66 0F 1F 84 00", + "linux": "48 63 47 ? 89 C2 83 EA ? 0F 88 ? ? ? ? 48 63 CA 89 D2 55 48 29 D0 48 89 E5 41 56 48 8D 04 40 41 55 41 54 4C 8D 34 C5" + }, + // Called right after the player push in function with string "Pushing linear hard!", two instances of this + "RelinkPusherList": + { + "library": "server", + "windows": "48 89 74 24 ? 57 48 83 EC ? 8B 41 ? 48 8B F1 83 E8 ? 48 63 F8 78 ? 48 89 5C 24 ? 48 8D 1C 7F 48 C1 E3 ? 48 8B 46", + "linux": "48 63 47 ? 89 C2 83 EA ? 0F 88 ? ? ? ? 48 63 CA 89 D2 55 48 29 D0 48 89 E5 41 56 48 8D 04 40 41 55 41 54 4C 8D 2C C5" } }, "Offsets": diff --git a/src/cs2_sdk/pushentity.h b/src/cs2_sdk/pushentity.h new file mode 100644 index 00000000..198cae09 --- /dev/null +++ b/src/cs2_sdk/pushentity.h @@ -0,0 +1,49 @@ +/** + * ============================================================================= + * CS2Fixes + * Copyright (C) 2023-2026 Source2ZE + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +#include "mathlib/vector.h" +#include "tier0/utlvector.h" + +class CEntityInstance; + +// Workaround to access CUtlVector::m_Size, which is protected, without constructing or destructing any elements +template +class CUtlVectorAccessor : public CUtlVector +{ +public: + void SetCountUnsafe(int nCount) { this->m_Size = nCount; } +}; + +struct PhysicsPusherInfo_t +{ + CEntityInstance* m_pEntity; + Vector m_vecStartAbsOrigin; + bool m_bCollisionCleared; +}; +static_assert(sizeof(PhysicsPusherInfo_t) == 0x18); + +class CPhysicsPushedEntities +{ +public: + void* m_pVTable; + CUtlVector m_rgPusher; +}; +static_assert(offsetof(CPhysicsPushedEntities, m_rgPusher) == 0x8); diff --git a/src/detours.cpp b/src/detours.cpp index 8090f1b6..9f54f6ea 100644 --- a/src/detours.cpp +++ b/src/detours.cpp @@ -49,6 +49,7 @@ #include "map_votes.h" #include "mapmigrations.h" #include "playermanager.h" +#include "pushentity.h" #include "tier0/vprof.h" #include "votemanager.h" #include "zombiereborn.h" @@ -85,6 +86,9 @@ KHOOK_MEMBER(SetBeamOrigin, Detour_SetBeamOrigin, nullptr); KHOOK_MEMBER(SetBeamEndPos, Detour_SetBeamEndPos, nullptr); KHOOK_MEMBER(CWorldRendererMgr_CreateWorld_Internal, nullptr, Detour_CWorldRendererMgr_CreateWorld_Internal_Post); KHOOK_MEMBER(CGameEntitySystem_CreateEntities, Detour_CGameEntitySystem_CreateEntities, nullptr); +KHOOK_MEMBER(UnlinkPusherList, Detour_UnlinkPusherList, nullptr); +KHOOK_MEMBER(RelinkPusherList, Detour_RelinkPusherList, nullptr); +KHOOK_MEMBER(SpeculativelyCheckPush, Detour_SpeculativelyCheckPush, nullptr); std::vector& GetKHookList() { @@ -808,3 +812,73 @@ KHook::Return Detour_CGameEntitySystem_CreateEntities(CGame // CCSGameRules::CleanUpMap respawns the default entity lump of every spawngroup that hasn't finished unloading, so don't spawn into ones pending unload return {KHook::Action::Supersede, nullptr}; } + +// For every entity a mover pushes, the game toggles the collision of the mover and all its children off and back on around the push trace, which is very expensive with many riders. Instead, leave the pushers solid and filter them out of the traces. +CConVar g_cvarFixPusherSolidToggle("cs2f_fix_pusher_solid_toggle", FCVAR_NONE, "Whether to filter movers out of push traces, fixes lag with many players on moving entities", false); + +CPhysicsPushedEntities* g_pCurrentPushedEntities = nullptr; +int g_iCurrentPusherCount = 0; +int g_iSpeculativePushDepth = 0; + +bool IsNonSolidPusher(CEntityInstance* pEntity, bool bPushFinalTrace) +{ + // SpeculativelyCheckPush only traces with PushFinal after relinking, where the pushers must be solid + if (!g_pCurrentPushedEntities || (bPushFinalTrace && g_iSpeculativePushDepth > 0)) + return false; + + // Base() as the count is 0 inside SpeculativelyCheckPush + for (int i = 0; i < g_iCurrentPusherCount; i++) + if (g_pCurrentPushedEntities->m_rgPusher.Base()[i].m_pEntity == pEntity) + return true; + + return false; +} + +KHook::Return Detour_UnlinkPusherList(CPhysicsPushedEntities* pThis) +{ + // SpeculativelyCheckPush calls this on Linux, it's handled there instead + if (g_iSpeculativePushDepth > 0 || !g_cvarFixPusherSolidToggle.Get()) + return {KHook::Action::Ignore}; + + // Makes RelinkPusherList a no-op + for (auto& pusher : pThis->m_rgPusher) + pusher.m_bCollisionCleared = false; + + g_pCurrentPushedEntities = pThis; + g_iCurrentPusherCount = pThis->m_rgPusher.Count(); + return {KHook::Action::Supersede}; +} + +KHook::Return Detour_RelinkPusherList(CPhysicsPushedEntities* pThis) +{ + if (g_iSpeculativePushDepth == 0 && g_pCurrentPushedEntities == pThis) + g_pCurrentPushedEntities = nullptr; + + return {KHook::Action::Ignore}; +} + +// MSVC inlines UnlinkPusherList here, so empty m_rgPusher instead, which also skips the inlined relink loop. +KHook::Return Detour_SpeculativelyCheckPush(CPhysicsPushedEntities* pThis, void* pPushedInfo, const Vector* pVecAbsPush, bool bRotationalPush, int64_t unk5) +{ + if (!g_cvarFixPusherSolidToggle.Get()) + return {KHook::Action::Ignore}; + + auto pPrevPushedEntities = g_pCurrentPushedEntities; + int iPrevCount = g_iCurrentPusherCount; + int iCount = pThis->m_rgPusher.Count(); + auto pPushers = static_cast*>(&pThis->m_rgPusher); + + g_pCurrentPushedEntities = pThis; + g_iCurrentPusherCount = iCount; + pPushers->SetCountUnsafe(0); + g_iSpeculativePushDepth++; + + bool bResult = hookSpeculativelyCheckPush->CallOriginal(pThis, pPushedInfo, pVecAbsPush, bRotationalPush, unk5); + + g_iSpeculativePushDepth--; + pPushers->SetCountUnsafe(iCount); + g_pCurrentPushedEntities = pPrevPushedEntities; + g_iCurrentPusherCount = iPrevCount; + + return {KHook::Action::Supersede, bResult}; +} diff --git a/src/detours.h b/src/detours.h index 1e46b9ea..d02e55b8 100644 --- a/src/detours.h +++ b/src/detours.h @@ -50,6 +50,7 @@ class CUserCmd; class CCSPlayerPawn; class CCSPlayer_UseServices; class CTraceFilter; +class CPhysicsPushedEntities; class CNavMesh; class CBaseModelEntity; class Vector; @@ -121,3 +122,8 @@ KHook::Return Detour_SetBeamOrigin(CBeam* pThis, const Vector* pVecWorldPo KHook::Return Detour_SetBeamEndPos(CBeam* pThis, const Vector* pVecWorldPosition); KHook::Return Detour_CWorldRendererMgr_CreateWorld_Internal_Post(IWorldRendererMgr* pThis, CSingleWorldRep* pSingleWorld); KHook::Return Detour_CGameEntitySystem_CreateEntities(CGameEntitySystem* pThis, SpawnGroupHandle_t hSpawnGroup, const CUtlVector* pKeyValues, const matrix3x4a_t* pSpawnOffset, const char* pszFilter, CreateSpawnGroupType_t createType, const void* pNameFixup, CUtlVector* pOutEntities, bool bUnk); +KHook::Return Detour_UnlinkPusherList(CPhysicsPushedEntities* pThis); +KHook::Return Detour_RelinkPusherList(CPhysicsPushedEntities* pThis); +KHook::Return Detour_SpeculativelyCheckPush(CPhysicsPushedEntities* pThis, void* pPushedInfo, const Vector* pVecAbsPush, bool bRotationalPush, int64_t unk5); + +bool IsNonSolidPusher(CEntityInstance* pEntity, bool bPushFinalTrace); diff --git a/src/virtual_hooks.cpp b/src/virtual_hooks.cpp index 9bd29caf..83a7d2a3 100644 --- a/src/virtual_hooks.cpp +++ b/src/virtual_hooks.cpp @@ -43,6 +43,7 @@ #include "eventlistener.h" #include "gameconfig.h" #include "gameevents.pb.h" +#include "gametrace.h" #include "idlemanager.h" #include "khook_helpers.h" #include "leader.h" @@ -91,6 +92,8 @@ KHook::Virtual triggerGravityPre KHook::Virtual triggerGravityEndTouchHook(0U, nullptr, Hook_TriggerGravityEndTouch_Post); KHook::Virtual onTakeDamageAliveHook(0U, Hook_OnTakeDamage_Alive, nullptr); KHook::Virtual playerPawnTeleportHook(0U, Hook_CCSPlayerPawn_Teleport, Hook_CCSPlayerPawn_Teleport_Post); +KHook::Virtual pushMoveShouldHitEntityHook(&CTraceFilter::ShouldHitEntity, Hook_TraceFilterPushMove_ShouldHitEntity, nullptr); +KHook::Virtual pushFinalShouldHitEntityHook(&CTraceFilter::ShouldHitEntity, Hook_TraceFilterPushFinal_ShouldHitEntity, nullptr); IGameEventManager2* g_pCGameEventManagerVTable = nullptr; CVPhys2World* g_pCVPhys2WorldVTable = nullptr; @@ -100,6 +103,8 @@ CGamePlayerEquip* g_pCGamePlayerEquipVTable = nullptr; CTriggerGravity* g_pTriggerGravityVTable = nullptr; CCSPlayerPawn* g_pCCSPlayerPawnVTable = nullptr; CServerSideClient* g_pCServerSideClientVTable = nullptr; +CTraceFilter* g_pCTraceFilterPushMoveVTable = nullptr; +CTraceFilter* g_pCTraceFilterPushFinalVTable = nullptr; template bool SetupVirtualHook(KHook::Virtual& hook, const char* name, CLASS* pInstance = nullptr) @@ -154,6 +159,8 @@ void InitVirtualHooks() SetupGlobalVirtualHook(triggerGravityEndTouchHook, g_pTriggerGravityVTable, modules::server, "CTriggerGravity", "CBaseEntity::EndTouch"); SetupGlobalVirtualHook(onTakeDamageAliveHook, g_pCCSPlayerPawnVTable, modules::server, "CCSPlayerPawn", "CCSPlayerPawn::OnTakeDamage_Alive"); SetupGlobalVirtualHook(playerPawnTeleportHook, g_pCCSPlayerPawnVTable, modules::server, "CCSPlayerPawn", "Teleport"); + SetupGlobalVirtualHook(pushMoveShouldHitEntityHook, g_pCTraceFilterPushMoveVTable, modules::server, "CTraceFilterPushMove"); + SetupGlobalVirtualHook(pushFinalShouldHitEntityHook, g_pCTraceFilterPushFinalVTable, modules::server, "CTraceFilterPushFinal"); } void RemoveVirtualHooks() @@ -170,6 +177,8 @@ void RemoveVirtualHooks() triggerGravityEndTouchHook.RemoveGlobal((CTriggerGravity*)&g_pTriggerGravityVTable); onTakeDamageAliveHook.RemoveGlobal((CCSPlayerPawn*)&g_pCCSPlayerPawnVTable); playerPawnTeleportHook.RemoveGlobal((CCSPlayerPawn*)&g_pCCSPlayerPawnVTable); + pushMoveShouldHitEntityHook.RemoveGlobal((CTraceFilter*)&g_pCTraceFilterPushMoveVTable); + pushFinalShouldHitEntityHook.RemoveGlobal((CTraceFilter*)&g_pCTraceFilterPushFinalVTable); } KHook::Return Hook_GameFrame_Post(IServerGameDLL* pThis, bool simulating, bool bFirstTick, bool bLastTick) @@ -1087,3 +1096,21 @@ KHook::Return Hook_CCSPlayerPawn_Teleport_Post(CCSPlayerPawn* pPawn, const pPawn->SnapViewAngles(pCastAngles); return {KHook::Action::Ignore}; } + +KHook::Return Hook_TraceFilterPushMove_ShouldHitEntity(CTraceFilter* pThis, CEntityInstance* pEntity) +{ + // Pushers are left solid by solid toggle fix, filter them out of push traces instead + if (IsNonSolidPusher(pEntity, false)) + return {KHook::Action::Supersede, false}; + + return {KHook::Action::Ignore}; +} + +KHook::Return Hook_TraceFilterPushFinal_ShouldHitEntity(CTraceFilter* pThis, CEntityInstance* pEntity) +{ + // Pushers are left solid by solid toggle fix, filter them out of push traces instead + if (IsNonSolidPusher(pEntity, true)) + return {KHook::Action::Supersede, false}; + + return {KHook::Action::Ignore}; +} diff --git a/src/virtual_hooks.h b/src/virtual_hooks.h index d0a398e6..19a8f650 100644 --- a/src/virtual_hooks.h +++ b/src/virtual_hooks.h @@ -39,6 +39,7 @@ class CGamePlayerEquip; class CCSPlayerPawn; class CVPhys2World; class CTriggerGravity; +class CTraceFilter; class CGameConfig; class IEngineServiceMgr; class IVEngineServer2; @@ -78,3 +79,5 @@ KHook::Return Hook_TriggerGravityEndTouch_Post(CTriggerGravity* pThis, CBa KHook::Return Hook_OnTakeDamage_Alive(CCSPlayerPawn* pPawn, CTakeDamageResult* pDamageResult); KHook::Return Hook_CCSPlayerPawn_Teleport(CCSPlayerPawn* pPawn, const Vector* pPosition, const QAngle* pAngles, const Vector* pVelocity); KHook::Return Hook_CCSPlayerPawn_Teleport_Post(CCSPlayerPawn* pPawn, const Vector* pPosition, const QAngle* pAngles, const Vector* pVelocity); +KHook::Return Hook_TraceFilterPushMove_ShouldHitEntity(CTraceFilter* pThis, CEntityInstance* pEntity); +KHook::Return Hook_TraceFilterPushFinal_ShouldHitEntity(CTraceFilter* pThis, CEntityInstance* pEntity); From f5551d7b65eef7708e730435262f6b4927d98011 Mon Sep 17 00:00:00 2001 From: Vauff Date: Wed, 4 Nov 2026 22:47:27 -0500 Subject: [PATCH 7/9] Update gamedata for 2026-11-04 CS2 update --- gamedata/cs2fixes.jsonc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gamedata/cs2fixes.jsonc b/gamedata/cs2fixes.jsonc index 43880b3a..2f3b03d7 100644 --- a/gamedata/cs2fixes.jsonc +++ b/gamedata/cs2fixes.jsonc @@ -130,8 +130,8 @@ "CS_Script_SetModel": { "library": "server", - "windows": "40 55 57 41 56 48 83 EC ? 48 8B F9 BA ? ? ? ? 8B 0D ? ? ? ? FF 15 ? ? ? ? 4C 8D 35 ? ? ? ? 84 C0 74 ? 8B 0D ? ? ? ? 4C 8D 0D ? ? ? ? 4C 8D 05 ? ? ? ? 4C 89 74 24 ? BA ? ? ? ? FF 15 ? ? ? ? 48 89 5C 24 ? 48 89 74 24 ? E8 ? ? ? ? 48 8B D0 48 8D 4C 24 ? 48 8B E8 E8 ? ? ? ? E8 ? ? ? ? 48 85 C0 75 ? 48 8D 15 ? ? ? ? E9 ? ? ? ? 48 8D 94 24 ? ? ? ? 48 8B C8 E8 ? ? ? ? 48 8B 5F ? 48 83 EB ? 48 8B CB E8 ? ? ? ? 83 F8 ? 0F 85 ? ? ? ? 48 8B 0B 48 8B 41 ? 0F B7 40 ? 3D ? ? ? ? 74 ? 05 ? ? ? ? 3D ? ? ? ? 76 ? 33 D2 48 8B CB E8 ? ? ? ? EB ? 48 8B 41 ? 48 8D 0D ? ? ? ? 48 3B C1 0F 85 ? ? ? ? 48 8B 0B 48 8B 41 ? 0F B7 40 ? 3D ? ? ? ? 74 ? 05 ? ? ? ? 3D ? ? ? ? 76 ? BA ? ? ? ? 48 8B CB E8 ? ? ? ? EB ? 48 8B 41 ? 48 85 C0 0F 84 ? ? ? ? 33 DB 83 38 ? 75 ? 8B 48 ? 83 F9 ? 74 ? 4C 8B 05 ? ? ? ? 4D 85 C0 74 ? 83 F9 ? 74 ? 8B C1 25 ? ? ? ? 8B D0 48 C1 E8 ? 4D 8B 0C C0 4D 85 C9 74 ? 81 E2 ? ? ? ? 48 6B C2 ? 49 03 C1 74 ? 39 48 ? 48 0F 45 C3 EB ? 48 8B C3 48 85 C0 74 ? 48 8B 08 EB ? 48 8B CB 4C 8D 0D ? ? ? ? 89 5C 24 ? 4C 8D 05 ? ? ? ? 33 D2 E8 ? ? ? ? 48 8B F0 48 85 C0 75 ? 48 8D 15 ? ? ? ? E9 ? ? ? ? 8B 47 ? 83 F8 ? 7D ? 48 8D 0D ? ? ? ? 41 B9 ? ? ? ? 48 89 4C 24 ? 48 8D 15 ? ? ? ? 89 44 24 ? 48 8D 0D ? ? ? ? 48 89 54 24 ? 4D 8B C6 48 8D 15 ? ? ? ? E8 ? ? ? ? E9 ? ? ? ? 48 8B 57 ? 4C 8D 84 24 ? ? ? ? 48 8B 8C 24 ? ? ? ? 48 89 9C 24 ? ? ? ? E8 ? ? ? ? 84 C0 0F 85 ? ? ? ? 83 7F ? ? 7F ? 48 8B 07 4C 8B 40 ? 49 81 C0 ? ? ? ? EB ? 4C 8B 47 ? 48 8B 94 24 ? ? ? ? 48 8D 8C 24 ? ? ? ? E8 ? ? ? ? 48 8D 15 ? ? ? ? 4D 8B C6 48 8B 08 48 8D 05 ? ? ? ? 48 85 C9 48 0F 45 D1 45 33 C9 48 89 54 24 ? 48 8D 0D ? ? ? ? 48 8D 15 ? ? ? ? 48 89 44 24 ? E8 ? ? ? ? 48 83 BC 24 ? ? ? ? ? 74", - "linux": "55 BE ? ? ? ? 48 89 E5 41 57 41 56 41 55 41 54 53 48 89 FB 48 83 EC ? 4C 8D 25 ? ? ? ? 41 8B 3C 24 E8 ? ? ? ? 84 C0 0F 85 ? ? ? ? E8 ? ? ? ? 4C 8D 6D ? 4C 89 EF 48 89 C6 49 89 C4 E8 ? ? ? ? E8 ? ? ? ? 48 89 C7 48 85 C0 0F 84 ? ? ? ? E8 ? ? ? ? 49 89 C6 48 8B 43 ? 48 8D 78 ? E8 ? ? ? ? 48 85 C0 0F 84 ? ? ? ? 83 38 ? 0F 85 ? ? ? ? 8B 48 ? 83 F9 ? 0F 84 ? ? ? ? 48 8B 35 ? ? ? ? 83 F9 ? 0F 84 ? ? ? ? 48 85 F6 0F 84 ? ? ? ? 0F B7 40 ? 48 89 C2 48 C1 EA ? 83 E2 ? 48 8B 14 D6 48 85 D2 0F 84 ? ? ? ? 25 ? ? ? ? 48 6B C0 ? 48 01 D0 3B 48 ? 0F 85 ? ? ? ? 48 8B 38 48 85 FF 0F 84 ? ? ? ? 48 8D 15 ? ? ? ? 31 C9 48 8D 35 ? ? ? ? E8 ? ? ? ? 49 89 C7 48 85 C0 74" + "windows": "40 53 55 56 48 83 EC ? 48 8B D9 BA ? ? ? ? 8B 0D ? ? ? ? FF 15 ? ? ? ? 48 8D 2D ? ? ? ? 84 C0 74 ? 8B 0D ? ? ? ? 4C 8D 0D ? ? ? ? 4C 8D 05 ? ? ? ? 48 89 6C 24 ? BA ? ? ? ? FF 15 ? ? ? ? 48 89 BC 24 ? ? ? ? E8 ? ? ? ? 48 8B D0 48 8D 4C 24 ? 48 8B F0 E8 ? ? ? ? E8 ? ? ? ? 48 85 C0 75 ? 48 8D 15 ? ? ? ? E9 ? ? ? ? 48 8D 94 24 ? ? ? ? 48 8B C8 E8 ? ? ? ? 48 8B 4B ? 48 83 E9 ? E8 ? ? ? ? 48 8B F8 48 85 C0 75 ? 48 8D 15 ? ? ? ? EB ? 83 38 ? 75 ? 48 8B CF E8 ? ? ? ? 48 85 C0 75 ? 48 8D 15 ? ? ? ? EB ? 48 8B CF E8 ? ? ? ? 48 8B C8 C7 44 24 ? ? ? ? ? 4C 8D 0D ? ? ? ? 33 D2 4C 8D 05 ? ? ? ? E8 ? ? ? ? 48 8B F8 48 85 C0 75 ? 48 8D 15 ? ? ? ? 4C 8B CD 4C 8D 05 ? ? ? ? 48 8B CE E8 ? ? ? ? E9 ? ? ? ? 8B 43 ? 83 F8 ? 7D ? 48 8D 0D ? ? ? ? 41 B9 ? ? ? ? 48 89 4C 24 ? 48 8D 15 ? ? ? ? 89 44 24 ? 48 8D 0D ? ? ? ? 48 89 54 24", + "linux": "55 BE ? ? ? ? 48 89 E5 41 57 41 56 41 55 41 54 53 48 89 FB 48 83 EC ? 4C 8D 25 ? ? ? ? 41 8B 3C 24 E8 ? ? ? ? 84 C0 0F 85 ? ? ? ? E8 ? ? ? ? 4C 8D 75 ? 4C 89 F7 48 89 C6 49 89 C5 E8 ? ? ? ? E8 ? ? ? ? 48 89 C7 48 85 C0 0F 84 ? ? ? ? E8 ? ? ? ? 49 89 C7 48 8B 43 ? 48 8D 78 ? E8 ? ? ? ? 49 89 C4 48 85 C0 0F 84 ? ? ? ? 83 38 ? 0F 84 ? ? ? ? 4C 89 E7 E8 ? ? ? ? 48 89 C7 48 85 C0 0F 84 ? ? ? ? 48 8D 15 ? ? ? ? 31 C9 48 8D 35 ? ? ? ? E8 ? ? ? ? 49 89 C4 48 85 C0 0F 84 ? ? ? ? 44 8B 4B ? 45 85 C9 0F 8E ? ? ? ? 48 8B 73 ? 4C 8D 6D" }, // Called by CS_Script_SetModel // This has two identical functions, but because we're detouring for cs_script, we must go beyond function boundaries for a unique signature From 9834531b3f9a599e477273a921e04b4f96e5b86d Mon Sep 17 00:00:00 2001 From: Vauff Date: Thu, 12 Nov 2026 19:39:19 -0500 Subject: [PATCH 8/9] Update SDK --- sdk | 2 +- src/commands.cpp | 4 ++-- src/detours.h | 2 +- src/panoramavote.cpp | 6 +++--- src/playermanager.cpp | 2 +- src/utils/hud_manager.cpp | 2 +- src/virtual_hooks.cpp | 21 ++++++++++----------- src/virtual_hooks.h | 6 +++--- src/zombiereborn.cpp | 2 +- 9 files changed, 23 insertions(+), 24 deletions(-) diff --git a/sdk b/sdk index 30c1a859..2283c1f9 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 30c1a859fe846846081ce0e6125c23e497a9a186 +Subproject commit 2283c1f919cb7b75329eb059ef6b064b36c2fdaa diff --git a/src/commands.cpp b/src/commands.cpp index 7be7388d..96081cd0 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -323,7 +323,7 @@ void ClientPrintAll(int hud_dest, const char* msg, ...) va_end(args); - INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("TextMsg"); + NetMessageInfo_t* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("TextMsg"); auto data = pNetMsg->AllocateMessage()->ToPB(); data->set_dest(hud_dest); @@ -355,7 +355,7 @@ void ClientPrint(CCSPlayerController* player, int hud_dest, const char* msg, ... return; } - INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("TextMsg"); + NetMessageInfo_t* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("TextMsg"); auto data = pNetMsg->AllocateMessage()->ToPB(); data->set_dest(hud_dest); diff --git a/src/detours.h b/src/detours.h index d02e55b8..a84983d3 100644 --- a/src/detours.h +++ b/src/detours.h @@ -41,7 +41,7 @@ class CCSPlayer_WeaponServices; class CCSPlayer_MovementServices; class CCSPlayer_ItemServices; class CBasePlayerWeapon; -class INetworkMessageInternal; +struct NetMessageInfo_t; class IEngineServiceMgr; class CServerSideClient; class INetChannel; diff --git a/src/panoramavote.cpp b/src/panoramavote.cpp index 4fe5faf3..aaf0be36 100644 --- a/src/panoramavote.cpp +++ b/src/panoramavote.cpp @@ -208,7 +208,7 @@ bool CPanoramaVoteHandler::SendYesNoVoteToAll(float flDuration, int iCaller, con void CPanoramaVoteHandler::SendVoteStartUM(IRecipientFilter* pFilter) { - INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("VoteStart"); + NetMessageInfo_t* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("VoteStart"); auto data = pNetMsg->AllocateMessage()->ToPB(); data->set_team(-1); @@ -332,7 +332,7 @@ void CPanoramaVoteHandler::EndVote(YesNoVoteEndReason reason) void CPanoramaVoteHandler::SendVoteFailed() { - INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("VoteFailed"); + NetMessageInfo_t* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("VoteFailed"); auto data = pNetMsg->AllocateMessage()->ToPB(); @@ -348,7 +348,7 @@ void CPanoramaVoteHandler::SendVoteFailed() void CPanoramaVoteHandler::SendVotePassed() { - INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("VotePass"); + NetMessageInfo_t* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("VotePass"); auto data = pNetMsg->AllocateMessage()->ToPB(); diff --git a/src/playermanager.cpp b/src/playermanager.cpp index 0b5780ab..95bd2079 100644 --- a/src/playermanager.cpp +++ b/src/playermanager.cpp @@ -612,7 +612,7 @@ void ZEPlayer::SetSteamIdAttribute() void ZEPlayer::ReplicateConVar(const char* pszName, const char* pszValue) { - INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("SetConVar"); + NetMessageInfo_t* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("SetConVar"); auto data = pNetMsg->AllocateMessage()->ToPB(); CMsg_CVars_CVar* cvarMsg = data->mutable_convars()->add_cvars(); diff --git a/src/utils/hud_manager.cpp b/src/utils/hud_manager.cpp index 24e0f87c..b6eedc86 100644 --- a/src/utils/hud_manager.cpp +++ b/src/utils/hud_manager.cpp @@ -64,7 +64,7 @@ void CreateHudMessage(std::shared_ptr pHudMessage) pEvent->SetInt("duration", pHudMessage->GetDuration() + g_cvarHudDurationLeeway.Get()); pEvent->SetInt("userid", -1); - INetworkMessageInternal* pMsg = g_pNetworkMessages->FindNetworkMessageById(GE_Source1LegacyGameEvent); + NetMessageInfo_t* pMsg = g_pNetworkMessages->FindNetworkMessageById(GE_Source1LegacyGameEvent); if (!pMsg) return; diff --git a/src/virtual_hooks.cpp b/src/virtual_hooks.cpp index 83a7d2a3..9a31db85 100644 --- a/src/virtual_hooks.cpp +++ b/src/virtual_hooks.cpp @@ -274,7 +274,7 @@ KHook::Return Hook_ClientDisconnect_Post(IServerGameClients* pThis, CPlaye return {KHook::Action::Ignore}; } -KHook::Return Hook_ClientPutInServer_Post(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, int type, uint64 xuid) +KHook::Return Hook_ClientPutInServer_Post(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, ClientPutInServerType_t type, uint64 xuid) { Message("Hook_ClientPutInServer(%d, \"%s\", %d, %d, %lli)\n", slot, pszName, type, xuid); @@ -489,12 +489,11 @@ CConVar g_cvarEnableTriggerTimer("cs2f_trigger_timer_enable", FCVAR_NONE, CConVar g_cvarBlockParticleMsgs("cs2f_block_particle_msgs", FCVAR_NONE, "Whether to block CUserMsg_ParticleManager messages to fix lag/crashes, experimental", false); KHook::Return Hook_PostEventAbstract(IGameEventSystem* pThis, CSplitScreenSlot nSlot, bool bLocalOnly, int nClientCount, const uint64* clients, - INetworkMessageInternal* pEvent, const CNetMessage* pData, unsigned long nSize, NetChannelBufType_t bufType) + NetMessageInfo_t* pEvent, const CNetMessage* pData, unsigned long nSize, NetChannelBufType_t bufType) { // Message( "Hook_PostEvent(%d, %d, %d, %lli)\n", nSlot, bLocalOnly, nClientCount, clients ); - NetMessageInfo_t* info = pEvent->GetNetMessageInfo(); - if (g_cvarEnableStopSound.Get() && info->m_MessageId == GE_FireBulletsId) + if (g_cvarEnableStopSound.Get() && pEvent->m_MessageId == GE_FireBulletsId) { if (g_playerManager->GetSilenceSoundMask()) { @@ -525,16 +524,16 @@ KHook::Return Hook_PostEventAbstract(IGameEventSystem* pThis, CSplitScreen *(uint64*)clients &= ~g_playerManager->GetStopSoundMask(); *(uint64*)clients &= ~g_playerManager->GetSilenceSoundMask(); } - else if (info->m_MessageId == GE_PlaceDecalEvent) + else if (pEvent->m_MessageId == GE_PlaceDecalEvent) { *(uint64*)clients &= ~g_playerManager->GetStopDecalsMask(); } - else if (info->m_MessageId == GE_Source1LegacyGameEvent) + else if (pEvent->m_MessageId == GE_Source1LegacyGameEvent) { if (g_cvarEnableLeader.Get()) Leader_PostEventAbstract_Source1LegacyGameEvent(clients, pData); } - else if (info->m_MessageId == UM_Shake) + else if (pEvent->m_MessageId == UM_Shake) { auto pPBData = const_cast(pData)->ToPB(); if (g_cvarMaxShakeAmp.Get() >= 0 && pPBData->amplitude() > g_cvarMaxShakeAmp.Get()) @@ -544,7 +543,7 @@ KHook::Return Hook_PostEventAbstract(IGameEventSystem* pThis, CSplitScreen if (g_cvarEnableNoShake.Get()) *(uint64*)clients &= ~g_playerManager->GetNoShakeMask(); } - else if (info->m_MessageId == GE_SosStartSoundEvent) + else if (pEvent->m_MessageId == GE_SosStartSoundEvent) { auto msg = const_cast(pData)->ToPB(); @@ -611,7 +610,7 @@ KHook::Return Hook_PostEventAbstract(IGameEventSystem* pThis, CSplitScreen *(uint64*)clients &= ~silenceSoundMask; } } - else if (info->m_MessageId == UM_SayText) + else if (pEvent->m_MessageId == UM_SayText) { auto msg = const_cast(pData)->ToPB(); @@ -629,7 +628,7 @@ KHook::Return Hook_PostEventAbstract(IGameEventSystem* pThis, CSplitScreen msg->set_text(buf); } } - else if (info->m_MessageId == UM_ParticleManager) + else if (pEvent->m_MessageId == UM_ParticleManager) { // These messages were previously unused, but recently started being used for weapon particles in the AG2 update // Unfortunately, this new system seems extremely unoptimized for 64 players, and was causing severe performance issues & vector overflow client crashes @@ -859,7 +858,7 @@ KHook::Return Hook_SwitchToLoop(IEngineServiceMgr* pThis, const char* pszL return {KHook::Action::Ignore}; } -KHook::Return Hook_UnloadSpawnGroup(IVEngineServer2* pThis, SpawnGroupHandle_t hSpawnGroup, int unloadOption) +KHook::Return Hook_UnloadSpawnGroup(IVEngineServer2* pThis, SpawnGroupHandle_t hSpawnGroup, ESpawnGroupUnloadOption eUnloadOption) { g_setUnloadingSpawnGroups.insert(hSpawnGroup); diff --git a/src/virtual_hooks.h b/src/virtual_hooks.h index 19a8f650..0d618b81 100644 --- a/src/virtual_hooks.h +++ b/src/virtual_hooks.h @@ -52,20 +52,20 @@ KHook::Return Hook_GameServerSteamAPIActivated(IServerGameDLL* pThis); KHook::Return Hook_ApplyGameSettings(IServerGameDLL* pThis, KeyValues* pKV); KHook::Return Hook_ClientActive_Post(IServerGameClients* pThis, CPlayerSlot slot, bool bLoadGame, const char* pszName, uint64 xuid); KHook::Return Hook_ClientDisconnect_Post(IServerGameClients* pThis, CPlayerSlot slot, ENetworkDisconnectionReason reason, const char* pszName, uint64 xuid, const char* pszNetworkID); -KHook::Return Hook_ClientPutInServer_Post(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, int type, uint64 xuid); +KHook::Return Hook_ClientPutInServer_Post(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, ClientPutInServerType_t type, uint64 xuid); KHook::Return Hook_ClientSettingsChanged(IServerGameClients* pThis, CPlayerSlot slot); KHook::Return Hook_OnClientConnected(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, const char* pszAddress, bool bFakePlayer); KHook::Return Hook_ClientConnect(IServerGameClients* pThis, CPlayerSlot slot, const char* pszName, uint64 xuid, const char* pszNetworkID, bool unk1, CBufferString* pRejectReason); KHook::Return Hook_ClientCommand(IServerGameClients* pThis, CPlayerSlot nSlot, const CCommand& _cmd); KHook::Return Hook_ClientSvcUserMessage(IServerGameClients* pThis, CPlayerSlot slot, int um_type, uint32 size, const void* buf); KHook::Return Hook_PostEventAbstract(IGameEventSystem* pThis, CSplitScreenSlot nSlot, bool bLocalOnly, int nClientCount, const uint64* clients, - INetworkMessageInternal* pEvent, const CNetMessage* pData, unsigned long nSize, NetChannelBufType_t bufType); + NetMessageInfo_t* pEvent, const CNetMessage* pData, unsigned long nSize, NetChannelBufType_t bufType); KHook::Return Hook_StartupServer_Post(INetworkServerService* pThis, const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*); KHook::Return Hook_CheckTransmit_Post(ISource2GameEntities* pThis, CCheckTransmitInfo** ppInfoList, int infoCount, CBitVec<16384>& unionTransmitEdicts, CBitVec<16384>&, const Entity2Networkable_t** pNetworkables, const uint16* pEntityIndicies, int nEntities); KHook::Return Hook_DispatchConCommand(ICvar* pThis, ConCommandRef cmd, const CCommandContext& ctx, const CCommand& args); KHook::Return Hook_SwitchToLoop(IEngineServiceMgr* pThis, const char* pszLoopModeName, KeyValues* pKV, uint32 nId, const char* pszAddonName, bool bUnk); -KHook::Return Hook_UnloadSpawnGroup(IVEngineServer2* pThis, SpawnGroupHandle_t hSpawnGroup, int unloadOption); +KHook::Return Hook_UnloadSpawnGroup(IVEngineServer2* pThis, SpawnGroupHandle_t hSpawnGroup, ESpawnGroupUnloadOption eUnloadOption); KHook::Return Hook_CreateWorkshopMapGroup(IGameTypes* pThis, const char* name, const CUtlStringList& mapList); KHook::Return Hook_LoadEventsFromFile(IGameEventManager2* pThis, const char* filename, bool bSearchAll); KHook::Return Hook_ProcessVoiceData(CServerSideClient* pClient, const CNetMessagePB& msg); diff --git a/src/zombiereborn.cpp b/src/zombiereborn.cpp index 24a4c577..3b561318 100644 --- a/src/zombiereborn.cpp +++ b/src/zombiereborn.cpp @@ -1279,7 +1279,7 @@ void ZR_InfectShake(CCSPlayerController* pController) if (!pController || !pController->IsConnected() || pController->IsBot() || !g_cvarInfectShake.Get()) return; - INetworkMessageInternal* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("Shake"); + NetMessageInfo_t* pNetMsg = g_pNetworkMessages->FindNetworkMessagePartial("Shake"); auto data = pNetMsg->AllocateMessage()->ToPB(); From 4763f487a100c4c8acb5478bf274ac50bfb7d1c3 Mon Sep 17 00:00:00 2001 From: Vauff Date: Sat, 21 Nov 2026 15:56:40 -0500 Subject: [PATCH 9/9] Migrate to new SDK entity helpers --- gamedata/cs2fixes.jsonc | 12 --- src/addresses.cpp | 2 - src/addresses.h | 2 - src/commands.cpp | 68 +++++-------- src/cs2_sdk/entity/cbaseentity.h | 5 - src/cs2_sdk/entity/cpointworldtext.h | 5 - src/cs2_sdk/entity/customhudlayout.cpp | 12 +-- src/customio.cpp | 14 +-- src/leader.cpp | 31 +++--- src/playermanager.cpp | 126 +++++++++++++------------ src/utils/entity.h | 6 -- src/zombiereborn.cpp | 11 ++- 12 files changed, 120 insertions(+), 174 deletions(-) diff --git a/gamedata/cs2fixes.jsonc b/gamedata/cs2fixes.jsonc index 2f3b03d7..6b1d4b0f 100644 --- a/gamedata/cs2fixes.jsonc +++ b/gamedata/cs2fixes.jsonc @@ -160,18 +160,6 @@ "windows": "48 89 5C 24 ? 57 48 83 EC ? 48 83 79 ? ? 48 8B FA 48 8B D9 75 ? E8 ? ? ? ? 48 8B 53", "linux": "55 48 89 E5 41 55 41 54 49 89 FC 53 48 89 F3 48 83 EC ? 48 8B 77" }, - "CreateEntityByName": - { - "library": "server", - "windows": "48 83 EC 48 C6 44 24 30 00", - "linux": "48 8D 05 ? ? ? ? 55 48 89 FA" - }, - "DispatchSpawn": - { - "library": "server", - "windows": "48 89 5C 24 10 57 48 83 EC 30 48 8B DA 48 8B F9 48 85 C9", - "linux": "48 85 FF 74 ? 55 48 89 E5 41 55 41 54 49 89 FC" - }, // "Error - cannot add bots after game is over." "BotNavIgnore": { diff --git a/src/addresses.cpp b/src/addresses.cpp index f8847f02..799bdaee 100644 --- a/src/addresses.cpp +++ b/src/addresses.cpp @@ -72,8 +72,6 @@ bool addresses::Initialize() RESOLVE_SIG("CGameEntitySystem_FindEntityByClassName", addresses::CGameEntitySystem_FindEntityByClassName); RESOLVE_SIG("CGameEntitySystem_FindEntityByName", addresses::CGameEntitySystem_FindEntityByName); RESOLVE_SIG("CGameRules_TerminateRound", addresses::CGameRules_TerminateRound); - RESOLVE_SIG("CreateEntityByName", addresses::CreateEntityByName); - RESOLVE_SIG("DispatchSpawn", addresses::DispatchSpawn); RESOLVE_SIG("DispatchParticleEffect", addresses::DispatchParticleEffect); RESOLVE_SIG("CBaseEntity_EmitSoundFilter", addresses::CBaseEntity_EmitSoundFilter); RESOLVE_SIG("CBaseEntity_SetMoveType", addresses::CBaseEntity_SetMoveType); diff --git a/src/addresses.h b/src/addresses.h index b48a2a4d..3e1ce03c 100644 --- a/src/addresses.h +++ b/src/addresses.h @@ -103,8 +103,6 @@ namespace addresses CEntityInstance* pSearchingEntity, CEntityInstance* pActivator, CEntityInstance* pCaller, IEntityFindFilter* pFilter); inline void(FASTCALL* CGameRules_TerminateRound)(CGameRules* pGameRules, float delay, unsigned int reason, int64 a4); - inline CBaseEntity*(FASTCALL* CreateEntityByName)(const char* className, int iForceEdictIndex); - inline void(FASTCALL* DispatchSpawn)(CBaseEntity* pEntity, CEntityKeyValues* pEntityKeyValues); inline int(FASTCALL* DispatchParticleEffect)(const char* pszParticleName, int iAttachType, CBaseEntity* pEntity, char iAttachmentPoint, CUtlSymbolLarge iAttachmentName, bool bResetAllParticlesOnEntity, int nSplitScreenPlayerSlot, IRecipientFilter* a7, byte* a8); inline StartSoundEventInfo(FASTCALL* CBaseEntity_EmitSoundFilter)(IRecipientFilter& filter, CEntityIndex ent, const EmitSound_t& params); diff --git a/src/commands.cpp b/src/commands.cpp index 96081cd0..89fcea6b 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -903,26 +903,25 @@ CON_COMMAND_CHAT(fl, "- Flashlight") origin.z += 64.0f; origin += forward * 54.0f; // The minimum distance such that an awp wouldn't block the light - CBarnLight* pLight = CreateEntityByName("light_barn"); - - pLight->m_bEnabled = true; - pLight->m_Color->SetColor(255, 255, 255, 255); - pLight->m_flBrightness = 1.0f; - pLight->m_flRange = 2048.0f; - pLight->m_flSoftX = 1.0f; - pLight->m_flSoftY = 1.0f; - pLight->m_flSkirt = 0.5f; - pLight->m_flSkirtNear = 1.0f; - pLight->m_vSizeParams->Init(45.0f, 45.0f, 0.03f); - pLight->m_nCastShadows = 1; - pLight->m_nDirectLight = 3; - pLight->Teleport(&origin, &pPawn->m_angEyeAngles(), nullptr); - - // Have to use keyvalues for this since the schema prop is a resource handle - CEntityKeyValues* pKeyValues = new CEntityKeyValues(); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(nullptr, &origin, &pPawn->m_angEyeAngles()); + + pKeyValues->SetBool("enabled", true); + pKeyValues->SetColor("color", Color(255, 255, 255, 255)); + pKeyValues->SetFloat("brightness", 1.0f); + pKeyValues->SetFloat("range", 2048.0f); + pKeyValues->SetFloat("soft_x", 1.0f); + pKeyValues->SetFloat("soft_y", 1.0f); + pKeyValues->SetFloat("skirt", 0.5f); + pKeyValues->SetFloat("skirt_near", 1.0f); + pKeyValues->SetVector("size_params", Vector(45.0f, 45.0f, 0.03f)); + pKeyValues->SetInt("castshadows", 1); + pKeyValues->SetInt("directlight", 3); pKeyValues->SetString("lightcookie", "materials/effects/lightcookies/flashlight.vtex"); - pLight->DispatchSpawn(pKeyValues); + CBarnLight* pLight = g_pEntitySystem->SpawnEntityByClassname("light_barn", pKeyValues); + + if (!pLight) + return; pLight->SetParent(pPawn); pLight->AcceptInput("SetParentAttachmentMaintainOffset", g_cvarFlashLightAttachment.Get().String()); @@ -993,40 +992,19 @@ CON_COMMAND_CHAT(particle, "- Spawn a particle") Vector vecAbsOrigin = player->GetPawn()->GetAbsOrigin(); vecAbsOrigin.z += 64.0f; - CParticleSystem* particle = CreateEntityByName("info_particle_system"); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(nullptr, &vecAbsOrigin); + pKeyValues->SetString("effect_name", args[1]); + pKeyValues->SetBool("start_active", true); - particle->m_bStartActive(true); - particle->m_iszEffectName(args[1]); - particle->Teleport(&vecAbsOrigin, nullptr, nullptr); + CParticleSystem* particle = g_pEntitySystem->SpawnEntityByClassname("info_particle_system", pKeyValues); - particle->DispatchSpawn(); + if (!particle) + return; ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have spawned a particle with effect name: %s", particle->m_iszEffectName().String()); Message("You have spawned a particle with effect name: %s\n", particle->m_iszEffectName().String()); } -CON_COMMAND_CHAT(particle_kv, "- Spawn a particle but using keyvalues to spawn") -{ - if (!player) - return; - - Vector vecAbsOrigin = player->GetPawn()->GetAbsOrigin(); - vecAbsOrigin.z += 64.0f; - - CParticleSystem* particle = CreateEntityByName("info_particle_system"); - - CEntityKeyValues* pKeyValues = new CEntityKeyValues(); - - pKeyValues->SetString("effect_name", args[1]); - pKeyValues->SetBool("start_active", true); - pKeyValues->SetVector("origin", vecAbsOrigin); - - particle->DispatchSpawn(pKeyValues); - - ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "You have spawned a particle using keyvalues with effect name: %s", particle->m_iszEffectName().String()); - Message("You have spawned a particle using keyvalues with effect name: %s\n", particle->m_iszEffectName().String()); -} - CON_COMMAND_CHAT(dispatch_particle, "- Test") { if (!player) diff --git a/src/cs2_sdk/entity/cbaseentity.h b/src/cs2_sdk/entity/cbaseentity.h index 7fda0b3e..9d7dcf15 100644 --- a/src/cs2_sdk/entity/cbaseentity.h +++ b/src/cs2_sdk/entity/cbaseentity.h @@ -217,11 +217,6 @@ class CBaseEntity : public CEntityInstance // A double pointer to entity VData is available 4 bytes past m_nSubclassID, if applicable CEntitySubclassVDataBase* GetVData() { return *(CEntitySubclassVDataBase**)((uint8*)(m_nSubclassID()) + 4); } - void DispatchSpawn(CEntityKeyValues* pEntityKeyValues = nullptr) - { - addresses::DispatchSpawn(this, pEntityKeyValues); - } - // Emit a sound event void EmitSound(const char* pszSound, int nPitch = 100, float flVolume = 1.0, float flDelay = 0.0) { diff --git a/src/cs2_sdk/entity/cpointworldtext.h b/src/cs2_sdk/entity/cpointworldtext.h index 6e713d33..5d47757c 100644 --- a/src/cs2_sdk/entity/cpointworldtext.h +++ b/src/cs2_sdk/entity/cpointworldtext.h @@ -65,9 +65,4 @@ class CPointWorldText : public CBaseModelEntity SCHEMA_FIELD(PointWorldTextJustifyHorizontal_t, m_nJustifyHorizontal) SCHEMA_FIELD(PointWorldTextJustifyVertical_t, m_nJustifyVertical) SCHEMA_FIELD(PointWorldTextReorientMode_t, m_nReorientMode) - - void SetMessage(const char* sMessage) - { - V_strncpy(m_messageText, sMessage, 512); - } }; diff --git a/src/cs2_sdk/entity/customhudlayout.cpp b/src/cs2_sdk/entity/customhudlayout.cpp index 79991709..b3985106 100644 --- a/src/cs2_sdk/entity/customhudlayout.cpp +++ b/src/cs2_sdk/entity/customhudlayout.cpp @@ -24,21 +24,15 @@ std::unordered_map CCSCustomHudLayout::sm_mapCu CCSCustomHudLayout* CCSCustomHudLayout::Create(std::string sLayout, std::string sTargetName) { - CCSCustomHudLayout* pLayout = CreateEntityByName("custom_hud_layout"); - - if (!pLayout) - return nullptr; - - CEntityKeyValues* pKeyValues = new CEntityKeyValues(); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(); std::string sLayoutPath = "panorama/layout/custom_game/" + std::string(sLayout) + ".vxml_c"; + pKeyValues->SetString("layout", sLayoutPath.c_str()); if (!sTargetName.empty()) pKeyValues->SetString("targetname", sTargetName.c_str()); - pLayout->DispatchSpawn(pKeyValues); - - return pLayout; + return g_pEntitySystem->SpawnEntityByClassname("custom_hud_layout", pKeyValues); } void CCSCustomHudLayout::ClearCallbacks() diff --git a/src/customio.cpp b/src/customio.cpp index ebdad3f3..be7b625b 100644 --- a/src/customio.cpp +++ b/src/customio.cpp @@ -515,18 +515,20 @@ bool IgnitePawn(CCSPlayerPawn* pPawn, float flDuration, CBaseEntity* pInflictor, } const auto vecOrigin = pPawn->GetAbsOrigin(); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(nullptr, &vecOrigin); - pParticleEnt = CreateEntityByName("info_particle_system"); + pKeyValues->SetString("effect_name", g_cvarBurnParticle.Get().String()); + pKeyValues->SetBool("start_active", false); + pParticleEnt = g_pEntitySystem->SpawnEntityByClassname("info_particle_system", pKeyValues); + + if (!pParticleEnt) + return false; - pParticleEnt->m_bStartActive(true); - pParticleEnt->m_iszEffectName(g_cvarBurnParticle.Get().String()); pParticleEnt->m_hControlPointEnts[0] = pPawn; pParticleEnt->m_flDissolveStartTime = GetGlobals()->curtime + flDuration; // Store the end time in the particle itself so we can increment if needed - pParticleEnt->Teleport(&vecOrigin, nullptr, nullptr); - - pParticleEnt->DispatchSpawn(); pParticleEnt->SetParent(pPawn); + pParticleEnt->AcceptInput("Start"); pPawn->m_hEffectEntity = pParticleEnt; diff --git a/src/leader.cpp b/src/leader.cpp index 251e87b3..201f392c 100644 --- a/src/leader.cpp +++ b/src/leader.cpp @@ -336,20 +336,20 @@ static bool Leader_CreateDefendMarker(ZEPlayer* pPlayer, Color clrTint, int iDur return -1.0f; }); - CParticleSystem* pMarker = CreateEntityByName("info_particle_system"); - Vector vecOrigin = pPawn->GetAbsOrigin(); vecOrigin.z += 10; - CEntityKeyValues* pKeyValues = new CEntityKeyValues(); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(nullptr, &vecOrigin); pKeyValues->SetString("effect_name", g_cvarDefendParticlePath.Get().String()); pKeyValues->SetInt("tint_cp", 1); pKeyValues->SetColor("tint_cp_color", clrTint); - pKeyValues->SetVector("origin", vecOrigin); pKeyValues->SetBool("start_active", true); - pMarker->DispatchSpawn(pKeyValues); + CParticleSystem* pMarker = g_pEntitySystem->SpawnEntityByClassname("info_particle_system", pKeyValues); + + if (!pMarker) + return false; UTIL_AddEntityIOEvent(pMarker, "DestroyImmediately", nullptr, nullptr, "", iDuration); UTIL_AddEntityIOEvent(pMarker, "Kill", nullptr, nullptr, "", iDuration + 0.02f); @@ -493,14 +493,7 @@ void Leader_BulletImpact(IGameEvent* pEvent) CCSPlayerPawn* pPawn = (CCSPlayerPawn*)pEvent->GetPlayerPawn("userid"); CBasePlayerWeapon* pWeapon = pPawn->m_pWeaponServices->m_hActiveWeapon.Get(); - - CParticleSystem* particle = CreateEntityByName("info_particle_system"); - - // Teleport particle to muzzle_flash attachment of player's weapon - particle->AcceptInput("SetParent", "!activator", pWeapon, nullptr); - particle->AcceptInput("SetParentAttachment", "muzzle_flash"); - - CEntityKeyValues* pKeyValues = new CEntityKeyValues(); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(); // Event contains other end of the particle Vector vecData = Vector(pEvent->GetFloat("x"), pEvent->GetFloat("y"), pEvent->GetFloat("z")); @@ -510,9 +503,17 @@ void Leader_BulletImpact(IGameEvent* pEvent) pKeyValues->SetVector("data_cp_value", vecData); pKeyValues->SetInt("tint_cp", 2); pKeyValues->SetColor("tint_cp_color", pPlayer->GetTracerColor()); - pKeyValues->SetBool("start_active", true); + pKeyValues->SetBool("start_active", false); + + CParticleSystem* particle = g_pEntitySystem->SpawnEntityByClassname("info_particle_system", pKeyValues); + + if (!particle) + return; - particle->DispatchSpawn(pKeyValues); + // Teleport particle to muzzle_flash attachment of player's weapon + particle->AcceptInput("SetParent", "!activator", pWeapon, nullptr); + particle->AcceptInput("SetParentAttachment", "muzzle_flash"); + particle->AcceptInput("Start"); UTIL_AddEntityIOEvent(particle, "DestroyImmediately", nullptr, nullptr, "", 0.1f); UTIL_AddEntityIOEvent(particle, "Kill", nullptr, nullptr, "", 0.12f); diff --git a/src/playermanager.cpp b/src/playermanager.cpp index 95bd2079..0b4dfb63 100644 --- a/src/playermanager.cpp +++ b/src/playermanager.cpp @@ -227,29 +227,27 @@ void ZEPlayer::SpawnFlashLight() return; CCSPlayerPawn* pPawn = (CCSPlayerPawn*)CCSPlayerController::FromSlot(GetPlayerSlot())->GetPawn(); - - CBarnLight* pLight = CreateEntityByName("light_barn"); - - pLight->m_bEnabled = false; - pLight->m_Color->SetColor(g_cvarFlashLightColor.Get().r(), g_cvarFlashLightColor.Get().g(), g_cvarFlashLightColor.Get().b()); - pLight->m_flBrightness = g_cvarFlashLightBrightness.Get(); - pLight->m_flRange = 2048.0f; - pLight->m_flSoftX = 1.0f; - pLight->m_flSoftY = 1.0f; - pLight->m_flSkirt = 0.5f; - pLight->m_flSkirtNear = 1.0f; - pLight->m_vSizeParams->Init(g_cvarFlashLightAngle.Get(), g_cvarFlashLightAngle.Get(), 0.02f); - pLight->m_nCastShadows = g_cvarFlashLightShadows.Get(); - pLight->m_nDirectLight = 3; - - // Have to use keyvalues for this since the schema prop is a resource handle - CEntityKeyValues* pKeyValues = new CEntityKeyValues(); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(); + + pKeyValues->SetBool("enabled", false); + pKeyValues->SetColor("color", Color(g_cvarFlashLightColor.Get().r(), g_cvarFlashLightColor.Get().g(), g_cvarFlashLightColor.Get().b())); + pKeyValues->SetFloat("brightness", g_cvarFlashLightBrightness.Get()); + pKeyValues->SetFloat("range", 2048.0f); + pKeyValues->SetFloat("soft_x", 1.0f); + pKeyValues->SetFloat("soft_y", 1.0f); + pKeyValues->SetFloat("skirt", 0.5f); + pKeyValues->SetFloat("skirt_near", 1.0f); + pKeyValues->SetVector("size_params", Vector(g_cvarFlashLightAngle.Get(), g_cvarFlashLightAngle.Get(), 0.02f)); + pKeyValues->SetInt("castshadows", g_cvarFlashLightShadows.Get()); + pKeyValues->SetInt("directlight", 3); pKeyValues->SetString("lightcookie", "materials/effects/lightcookies/flashlight.vtex"); - pLight->DispatchSpawn(pKeyValues); + CBarnLight* pLight = g_pEntitySystem->SpawnEntityByClassname("light_barn", pKeyValues); - TeleportFlashLight(pPawn, pLight); + if (!pLight) + return; + TeleportFlashLight(pPawn, pLight); SetFlashLight(pLight); } @@ -324,25 +322,23 @@ void ZEPlayer::StartBeacon(Color color, ZEPlayerHandle hGiver /* = 0*/) SetBeaconColor(color); CCSPlayerController* pPlayer = CCSPlayerController::FromSlot(m_slot); - Vector vecAbsOrigin = pPlayer->GetPawn()->GetAbsOrigin(); vecAbsOrigin.z += 10; - CParticleSystem* particle = CreateEntityByName("info_particle_system"); - - CEntityKeyValues* pKeyValues = new CEntityKeyValues(); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(nullptr, &vecAbsOrigin); pKeyValues->SetString("effect_name", g_cvarBeaconParticle.Get().String()); pKeyValues->SetInt("tint_cp", 1); - pKeyValues->SetVector("origin", vecAbsOrigin); + pKeyValues->SetColor("tint_cp_color", color); pKeyValues->SetBool("start_active", false); - particle->m_clrTint->SetRawColor(color.GetRawColor()); + CParticleSystem* particle = g_pEntitySystem->SpawnEntityByClassname("info_particle_system", pKeyValues); - particle->DispatchSpawn(pKeyValues); - particle->SetParent(pPlayer->GetPawn()); + if (!particle) + return; + particle->SetParent(pPlayer->GetPawn()); m_hBeaconParticle.Set(particle); CHandle hParticle = particle->GetHandle(); @@ -421,16 +417,17 @@ void ZEPlayer::CreateMark(float fDuration, Vector vecOrigin) if (fDuration <= 0) return; - CParticleSystem* pMarker = CreateEntityByName("info_particle_system"); - CEntityKeyValues* pKeyValues = new CEntityKeyValues(); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(nullptr, &vecOrigin); pKeyValues->SetString("effect_name", g_cvarMarkParticlePath.Get().String()); pKeyValues->SetInt("tint_cp", 1); pKeyValues->SetColor("tint_cp_color", GetLeaderColor()); - pKeyValues->SetVector("origin", vecOrigin); pKeyValues->SetBool("start_active", true); - pMarker->DispatchSpawn(pKeyValues); + CParticleSystem* pMarker = g_pEntitySystem->SpawnEntityByClassname("info_particle_system", pKeyValues); + + if (!pMarker) + return; UTIL_AddEntityIOEvent(pMarker, "DestroyImmediately", nullptr, nullptr, "", fDuration); UTIL_AddEntityIOEvent(pMarker, "Kill", nullptr, nullptr, "", fDuration + 0.02f); @@ -469,20 +466,17 @@ void ZEPlayer::PurgeLeaderVotes() void ZEPlayer::StartGlow(Color color, int duration) { SetGlowColor(color); + CCSPlayerController* pController = CCSPlayerController::FromSlot(m_slot); CCSPlayerPawn* pPawn = (CCSPlayerPawn*)pController->GetPawn(); - const char* pszModelName = pPawn->GetModelName(); - - CBaseModelEntity* pModelGlow = CreateEntityByName("prop_dynamic"); - CBaseModelEntity* pModelRelay = CreateEntityByName("prop_dynamic"); - CEntityKeyValues* pKeyValuesRelay = new CEntityKeyValues(); + CEntityKeyValues* pKeyValuesRelay = g_pEntitySystem->CreateEntityKeyValues(); + CEntityKeyValues* pKeyValuesGlow = g_pEntitySystem->CreateEntityKeyValues(); pKeyValuesRelay->SetString("model", pszModelName); pKeyValuesRelay->SetInt64("spawnflags", 256U); pKeyValuesRelay->SetInt("rendermode", kRenderNone); - CEntityKeyValues* pKeyValuesGlow = new CEntityKeyValues(); pKeyValuesGlow->SetString("model", pszModelName); pKeyValuesGlow->SetInt64("spawnflags", 256U); pKeyValuesGlow->SetColor("glowcolor", color); @@ -491,8 +485,12 @@ void ZEPlayer::StartGlow(Color color, int duration) pKeyValuesGlow->SetInt("glowstate", 3); pKeyValuesGlow->SetInt("renderamt", 1); - pModelGlow->DispatchSpawn(pKeyValuesGlow); - pModelRelay->DispatchSpawn(pKeyValuesRelay); + CBaseModelEntity* pModelGlow = g_pEntitySystem->SpawnEntityByClassname("prop_dynamic", pKeyValuesGlow); + CBaseModelEntity* pModelRelay = g_pEntitySystem->SpawnEntityByClassname("prop_dynamic", pKeyValuesRelay); + + if (!pModelGlow || !pModelRelay) + return; + pModelRelay->AcceptInput("FollowEntity", "!activator", pPawn); pModelGlow->AcceptInput("FollowEntity", "!activator", pModelRelay); @@ -642,16 +640,18 @@ void ZEPlayer::CreatePointOrient() if (!pPawn) return; - pOrient = CreateEntityByName("point_orient"); - pOrient->m_bActive(true); - pOrient->m_nGoalDirection(PointOrientGoalDirectionType_t::eEyesForward); + Vector origin = pPawn->GetEyePosition(); + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(nullptr, &origin); - pOrient->DispatchSpawn(); - SetPointOrient(pOrient); + pKeyValues->SetInt("start_active", 1); + pKeyValues->SetString("goal_direction_type", "eEyesForward"); - Vector origin = pPawn->GetEyePosition(); - pOrient->Teleport(&origin, nullptr, nullptr); + pOrient = g_pEntitySystem->SpawnEntityByClassname("point_orient", pKeyValues); + if (!pOrient) + return; + + SetPointOrient(pOrient); pOrient->AcceptInput("SetParent", "!activator", pPawn); pOrient->AcceptInput("SetTarget", "!activator", pPawn); } @@ -713,8 +713,10 @@ void ZEPlayer::ToggleThirdPerson(float flDistance, bool bForce) if (!pCamera) { // No camera found, spawn one - pCamera = CreateEntityByName("custom_player_camera"); - pCamera->DispatchSpawn(); + pCamera = g_pEntitySystem->SpawnEntityByClassname("custom_player_camera"); + + if (!pCamera) + return; } m_hCustomCamera = pCamera; @@ -760,31 +762,31 @@ void ZEPlayer::CreateEntwatchHud() pText = nullptr; } - pText = CreateEntityByName("point_worldtext"); - pText->m_bEnabled(true); - pText->m_bFullbright(true); - pText->m_flFontSize(GetEntwatchHudSize()); - Color col; + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(); + int a = m_colorEntwatchHud.a(); if (a == 255) // 254 allows it to be visible through some items col.SetColor(m_colorEntwatchHud.r(), m_colorEntwatchHud.g(), m_colorEntwatchHud.b(), 254); else col.SetColor(m_colorEntwatchHud.r(), m_colorEntwatchHud.g(), m_colorEntwatchHud.b(), a); - pText->m_Color = col; + pKeyValues->SetBool("enabled", true); + pKeyValues->SetBool("fullbright", true); + pKeyValues->SetFloat("font_size", GetEntwatchHudSize()); + pKeyValues->SetColor("color", col); + pKeyValues->SetFloat("world_units_per_pixel", 0.005f); + pKeyValues->SetString("font_name", "Verdana Bold"); + pKeyValues->SetInt("justify_vertical", (int)PointWorldTextJustifyVertical_t::POINT_WORLD_TEXT_JUSTIFY_VERTICAL_TOP); + pKeyValues->SetString("message", ""); - pText->m_flWorldUnitsPerPx(0.005f); - pText->m_nJustifyVertical(PointWorldTextJustifyVertical_t::POINT_WORLD_TEXT_JUSTIFY_VERTICAL_TOP); + pText = g_pEntitySystem->SpawnEntityByClassname("point_worldtext", pKeyValues); - V_strncpy(pText->m_FontName, "Verdana Bold", 64); - - pText->SetMessage(""); + if (!pText) + return; - pText->DispatchSpawn(); SetEntwatchHud(pText); - - pText->AcceptInput("SetParent", "!activator", pOrient); + pText->SetParent(pOrient); Vector origin = pOrient->GetAbsOrigin(); QAngle vmangles = pOrient->GetAbsRotation(); diff --git a/src/utils/entity.h b/src/utils/entity.h index fad7d4fa..e7aee948 100644 --- a/src/utils/entity.h +++ b/src/utils/entity.h @@ -34,12 +34,6 @@ CBaseEntity* UTIL_FindEntityByName(CEntityInstance* pStartEntity, const char* sz CEntityInstance* pSearchingEntity = nullptr, CEntityInstance* pActivator = nullptr, CEntityInstance* pCaller = nullptr, IEntityFindFilter* pFilter = nullptr); -template -T* CreateEntityByName(const char* className) -{ - return reinterpret_cast(addresses::CreateEntityByName(className, -1)); -} - // Add an entity IO event to the event queue, just like a map would // The queue is processed after all entities are simulated every frame void UTIL_AddEntityIOEvent(CEntityInstance* pTarget, const char* pszInput, diff --git a/src/zombiereborn.cpp b/src/zombiereborn.cpp index 3b561318..7e08e2b8 100644 --- a/src/zombiereborn.cpp +++ b/src/zombiereborn.cpp @@ -1058,12 +1058,13 @@ void ZR_OnRoundPrestart(IGameEvent* pEvent) void SetupRespawnToggler() { - CBaseEntity* relay = CreateEntityByName("logic_relay"); - CEntityKeyValues* pKeyValues = new CEntityKeyValues(); - + CEntityKeyValues* pKeyValues = g_pEntitySystem->CreateEntityKeyValues(); pKeyValues->SetString("targetname", "zr_toggle_respawn"); - relay->DispatchSpawn(pKeyValues); - g_hRespawnToggler = relay->GetHandle(); + + CBaseEntity* relay = g_pEntitySystem->SpawnEntityByClassname("logic_relay", pKeyValues); + + if (relay) + g_hRespawnToggler = relay->GetHandle(); } void SetupCTeams()