Skip to content

Commit bd5a92a

Browse files
committed
also merge in some of my earlier work, general improvements
1 parent deb651e commit bd5a92a

8 files changed

Lines changed: 114 additions & 38 deletions

File tree

src/commands.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ extern CGameEntitySystem* g_pEntitySystem;
5353
extern IVEngineServer2* g_pEngineServer2;
5454
extern ISteamHTTP* g_http;
5555
extern CConVar<CUtlString> g_cvarFlashLightAttachment;
56+
extern INetworkGameServer* GetNetworkGameServer();
57+
extern int g_iSpawnGroupLoads;
58+
extern CSpawnGroupMgrGameSystem* g_pSpawnGroupMgr;
59+
extern CUtlVector<CServerSideClient*>* GetClientList();
5660

5761
CConVar<bool> g_cvarEnableCommands("cs2f_commands_enable", FCVAR_NONE, "Whether to enable chat commands", false);
5862
CConVar<bool> g_cvarEnableAdminCommands("cs2f_admin_commands_enable", FCVAR_NONE, "Whether to enable admin chat commands", false);
@@ -742,6 +746,48 @@ CON_COMMAND_CHAT(showteam, "<name> - Get a player's current team")
742746
}
743747
}
744748

749+
750+
CON_COMMAND_CHAT_FLAGS(spawngroups, "Debug spawngroup info", ADMFLAG_ROOT)
751+
{
752+
if (!GetNetworkGameServer())
753+
return;
754+
755+
for (int i = 0; i < GetGlobals()->maxClients; i++)
756+
{
757+
ZEPlayer* pPlayer = g_playerManager->GetPlayer(i);
758+
759+
if (!pPlayer)
760+
continue;
761+
762+
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "Slot %i counts CCheckTransmitInfo->m_vecSpawnGroups: %i CServerSideClient->m_vecLoadedSpawnGroups: %i", i, pPlayer->GetCheckTransmitSpawnGroupCount(), pPlayer->GetClientSpawnGroupCount());
763+
}
764+
765+
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "PostSpawnGroupLoad count for %s: %i", GetNetworkGameServer()->GetMapName(), g_iSpawnGroupLoads);
766+
}
767+
768+
CON_COMMAND_CHAT_FLAGS(clean_client_spawngroups, "Clean client spawngroups", ADMFLAG_ROOT)
769+
{
770+
if (!g_pSpawnGroupMgr)
771+
return;
772+
773+
CUtlVector<SpawnGroupHandle_t> vecActualSpawnGroups;
774+
addresses::GetSpawnGroups(g_pSpawnGroupMgr, &vecActualSpawnGroups);
775+
776+
auto pClients = GetClientList();
777+
778+
FOR_EACH_VEC(*pClients, i)
779+
{
780+
auto pClient = (*pClients)[i];
781+
782+
if (!pClient || pClient->m_vecLoadedSpawnGroups.Count() == vecActualSpawnGroups.Count())
783+
continue;
784+
785+
pClient->m_vecLoadedSpawnGroups = vecActualSpawnGroups;
786+
}
787+
788+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Cleaned client spawngroups.");
789+
}
790+
745791
#if _DEBUG
746792
CON_COMMAND_CHAT(myuid, "- Test")
747793
{

src/cs2fixes.cpp

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include "gameconfig.h"
4141
#include "gameevents.pb.h"
4242
#include "gamesystem.h"
43-
#include "gamesystems/spawngroup_manager.h"
4443
#include "httpmanager.h"
4544
#include "icvar.h"
4645
#include "idlemanager.h"
@@ -69,6 +68,7 @@ double g_flUniversalTime;
6968
float g_flLastTickedTime;
7069
bool g_bHasTicked;
7170
int g_iRoundNum = 0;
71+
int g_iSpawnGroupLoads = 0;
7272

7373
void Message(const char* msg, ...)
7474
{
@@ -124,7 +124,7 @@ SH_DECL_HOOK2(IGameEventManager2, LoadEventsFromFile, SH_NOATTRIB, 0, int, const
124124
SH_DECL_MANUALHOOK1_void(GoToIntermission, 0, 0, 0, bool);
125125
SH_DECL_MANUALHOOK2_void(PhysicsTouchShuffle, 0, 0, 0, CUtlVector<TouchLinked_t>*, bool);
126126
SH_DECL_MANUALHOOK3_void(DropWeapon, 0, 0, 0, CBasePlayerWeapon*, Vector*, Vector*);
127-
SH_DECL_HOOK1_void(CSpawnGroupMgrGameSystem, SetActiveSpawnGroup, SH_NOATTRIB, 0, SpawnGroupHandle_t);
127+
SH_DECL_HOOK1_void(IServer, SetGameSpawnGroupMgr, SH_NOATTRIB, 0, IGameSpawnGroupMgr*);
128128

129129
CS2Fixes g_CS2Fixes;
130130

@@ -138,7 +138,7 @@ CGameConfig* g_GameConfig = nullptr;
138138
ISteamHTTP* g_http = nullptr;
139139
CSteamGameServerAPIContext g_steamAPI;
140140
CCSGameRules* g_pGameRules = nullptr; // Will be null between map end & new map startup, null check if necessary!
141-
CSpawnGroupMgrGameSystem* g_pSpawnGroupMgr = nullptr;
141+
CSpawnGroupMgrGameSystem* g_pSpawnGroupMgr = nullptr; // Will be null between map end & new map startup, null check if necessary!
142142
int g_iCGamePlayerEquipUseId = -1;
143143
int g_iCGamePlayerEquipPrecacheId = -1;
144144
int g_iCreateWorkshopMapGroupId = -1;
@@ -148,7 +148,7 @@ int g_iLoadEventsFromFileId = -1;
148148
int g_iGoToIntermissionId = -1;
149149
int g_iPhysicsTouchShuffle = -1;
150150
int g_iWeaponServiceDropWeaponId = -1;
151-
int g_iReleaseSpawnGroupId = -1;
151+
int g_iSetGameSpawnGroupMgrId = -1;
152152

153153
CGameEntitySystem* GameEntitySystem()
154154
{
@@ -339,9 +339,6 @@ bool CS2Fixes::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen, bool
339339
SH_MANUALHOOK_RECONFIGURE(GoToIntermission, offset, 0, 0);
340340
g_iGoToIntermissionId = SH_ADD_MANUALDVPHOOK(GoToIntermission, pCCSGameRulesVTable, SH_MEMBER(this, &CS2Fixes::Hook_GoToIntermission), false);
341341

342-
auto pCSpawnGroupMgrGameSystem = (CSpawnGroupMgrGameSystem*)modules::server->FindVirtualTable("CSpawnGroupMgrGameSystem");
343-
g_iReleaseSpawnGroupId = SH_ADD_DVPHOOK(CSpawnGroupMgrGameSystem, SetActiveSpawnGroup, pCSpawnGroupMgrGameSystem, SH_MEMBER(this, &CS2Fixes::Hook_SetActiveSpawnGroup), true);
344-
345342
Message("All hooks started!\n");
346343

347344
UnlockConVars();
@@ -442,7 +439,9 @@ bool CS2Fixes::Unload(char* error, size_t maxlen)
442439
SH_REMOVE_HOOK_ID(g_iWeaponServiceDropWeaponId);
443440
SH_REMOVE_HOOK_ID(g_iGoToIntermissionId);
444441
SH_REMOVE_HOOK_ID(g_iCGamePlayerEquipUseId);
445-
SH_REMOVE_HOOK_ID(g_iReleaseSpawnGroupId);
442+
443+
if (g_iSetGameSpawnGroupMgrId != -1)
444+
SH_REMOVE_HOOK_ID(g_iSetGameSpawnGroupMgrId);
446445

447446
if (g_iCGamePlayerEquipPrecacheId != -1)
448447
SH_REMOVE_HOOK_ID(g_iCGamePlayerEquipPrecacheId);
@@ -609,6 +608,9 @@ void CS2Fixes::Hook_StartupServer(const GameSessionConfiguration_t& config, ISou
609608
g_pEntitySystem = GameEntitySystem();
610609
g_pEntitySystem->AddListenerEntity(g_pEntityListener);
611610

611+
if (g_pNetworkServerService->GetIGameServer())
612+
g_iSetGameSpawnGroupMgrId = SH_ADD_HOOK(IServer, SetGameSpawnGroupMgr, g_pNetworkServerService->GetIGameServer(), SH_MEMBER(this, &CS2Fixes::Hook_SetGameSpawnGroupMgr), false);
613+
612614
Message("Hook_StartupServer: %s\n", pszMapName);
613615

614616
RegisterEventListeners();
@@ -990,6 +992,7 @@ void CS2Fixes::Hook_CheckTransmit(CCheckTransmitInfo** ppInfoList, int infoCount
990992
for (int i = 0; i < infoCount; i++)
991993
{
992994
auto& pInfo = ppInfoList[i];
995+
CUtlVector<SpawnGroupHandle_t> m_vecSpawnGroups = *((uint8*)pInfo + 40);
993996

994997
// the offset happens to have a player index here,
995998
// though this is probably part of the client class that contains the CCheckTransmitInfo
@@ -1006,10 +1009,13 @@ void CS2Fixes::Hook_CheckTransmit(CCheckTransmitInfo** ppInfoList, int infoCount
10061009
if (!pSelfZEPlayer)
10071010
continue;
10081011

1012+
if (m_vecSpawnGroups.Count() != pSelfZEPlayer->GetCheckTransmitSpawnGroupCount())
1013+
pSelfZEPlayer->SetCheckTransmitSpawnGroupCount(m_vecSpawnGroups.Count());
1014+
10091015
auto pClient = GetClientBySlot(iPlayerSlot);
10101016

1011-
if (pClient && pSelfZEPlayer->IsAdminFlagSet(ADMFLAG_ROOT))
1012-
ClientPrint(pSelfController, HUD_PRINTCENTER, "Client loaded SpawnGroups: %d", pClient->m_vecLoadedSpawnGroups.Count());
1017+
if (pClient && pClient->m_vecLoadedSpawnGroups.Count() != pSelfZEPlayer->GetClientSpawnGroupCount())
1018+
pSelfZEPlayer->SetClientSpawnGroupCount(pClient->m_vecLoadedSpawnGroups.Count());
10131019

10141020
for (int j = 0; j < GetGlobals()->maxClients; j++)
10151021
{
@@ -1223,29 +1229,10 @@ int CS2Fixes::Hook_LoadEventsFromFile(const char* filename, bool bSearchAll)
12231229
RETURN_META_VALUE(MRES_IGNORED, 0);
12241230
}
12251231

1226-
void CS2Fixes::Hook_SetActiveSpawnGroup(SpawnGroupHandle_t h)
1232+
void CS2Fixes::Hook_SetGameSpawnGroupMgr(IGameSpawnGroupMgr* pSpawnGroupMgr)
12271233
{
1228-
g_pSpawnGroupMgr = META_IFACEPTR(CSpawnGroupMgrGameSystem);
1229-
1230-
RETURN_META(MRES_IGNORED);
1231-
}
1232-
1233-
CON_COMMAND_F(c_clean_client_spawngroups, "", FCVAR_SPONLY)
1234-
{
1235-
CUtlVector<SpawnGroupHandle_t> vecActualSpawnGroups;
1236-
addresses::GetSpawnGroups(g_pSpawnGroupMgr, &vecActualSpawnGroups);
1237-
1238-
auto pClients = GetClientList();
1239-
1240-
FOR_EACH_VEC(*pClients, i)
1241-
{
1242-
auto pClient = (*pClients)[i];
1243-
1244-
if (!pClient || pClient->m_vecLoadedSpawnGroups.Count() == vecActualSpawnGroups.Count())
1245-
continue;
1246-
1247-
pClient->m_vecLoadedSpawnGroups = vecActualSpawnGroups;
1248-
}
1234+
// This also resets our stored pointer on deletion, since null gets passed into this function, nice!
1235+
g_pSpawnGroupMgr = (CSpawnGroupMgrGameSystem*)pSpawnGroupMgr;
12491236
}
12501237

12511238
void CS2Fixes::OnLevelInit(char const* pMapName,
@@ -1284,6 +1271,8 @@ void CS2Fixes::OnLevelShutdown()
12841271
{
12851272
Message("OnLevelShutdown()\n");
12861273

1274+
g_iSpawnGroupLoads = 0;
1275+
12871276
if (g_cvarVoteManagerEnable.Get())
12881277
g_pMapVoteSystem->OnLevelShutdown();
12891278
}

src/cs2fixes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#pragma once
2121

22+
#include "gamesystems/spawngroup_manager.h"
2223
#include "igameevents.h"
2324
#include "networksystem/inetworkserializer.h"
2425
#include <ISmmPlugin.h>
@@ -83,7 +84,7 @@ class CS2Fixes : public ISmmPlugin, public IMetamodListener
8384
void Hook_CheckMovingGround(double frametime);
8485
void Hook_DropWeaponPost(CBasePlayerWeapon* pWeapon, Vector* pVecTarget, Vector* pVelocity);
8586
int Hook_LoadEventsFromFile(const char* filename, bool bSearchAll);
86-
void Hook_SetActiveSpawnGroup(SpawnGroupHandle_t h);
87+
void Hook_SetGameSpawnGroupMgr(IGameSpawnGroupMgr* pSpawnGroupMgr);
8788

8889
public:
8990
const char* GetAuthor();

src/events.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "entwatch.h"
2828
#include "eventlistener.h"
2929
#include "idlemanager.h"
30+
#include "iserver.h"
3031
#include "leader.h"
3132
#include "map_votes.h"
3233
#include "networkstringtabledefs.h"
@@ -43,6 +44,8 @@ extern CGameEntitySystem* g_pEntitySystem;
4344
extern CGlobalVars* GetGlobals();
4445
extern CCSGameRules* g_pGameRules;
4546
extern IVEngineServer2* g_pEngineServer2;
47+
extern INetworkGameServer* GetNetworkGameServer();
48+
extern int g_iSpawnGroupLoads;
4649

4750
extern int g_iRoundNum;
4851

@@ -277,6 +280,28 @@ GAME_EVENT_F(round_start)
277280

278281
GAME_EVENT_F(round_end)
279282
{
283+
if (GetNetworkGameServer())
284+
{
285+
int iHighestCheckTransmitSpawnGroupCount = 0;
286+
int iHighestClientSpawnGroupCount = 0;
287+
288+
for (int i = 0; i < GetGlobals()->maxClients; i++)
289+
{
290+
ZEPlayer* pPlayer = g_playerManager->GetPlayer(i);
291+
292+
if (!pPlayer)
293+
continue;
294+
295+
if (pPlayer->GetCheckTransmitSpawnGroupCount() > iHighestCheckTransmitSpawnGroupCount)
296+
iHighestCheckTransmitSpawnGroupCount = pPlayer->GetCheckTransmitSpawnGroupCount();
297+
298+
if (pPlayer->GetClientSpawnGroupCount() > iHighestClientSpawnGroupCount)
299+
iHighestClientSpawnGroupCount = pPlayer->GetClientSpawnGroupCount();
300+
}
301+
302+
Message("PostSpawnGroupLoad count for %s at round_end: %i Highest counts CCheckTransmitInfo->m_vecSpawnGroups: %i CServerSideClient->m_vecLoadedSpawnGroups: %i\n", GetNetworkGameServer()->GetMapName(), g_iSpawnGroupLoads, iHighestCheckTransmitSpawnGroupCount, iHighestClientSpawnGroupCount);
303+
}
304+
280305
if (!g_cvarEnableTopDefender.Get() || !GetGlobals())
281306
return;
282307

src/gamesystem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
extern CGlobalVars* GetGlobals();
3636
extern CGameConfig* g_GameConfig;
3737
extern CCSGameRules* g_pGameRules;
38+
extern int g_iSpawnGroupLoads;
3839

3940
CBaseGameSystemFactory** CBaseGameSystemFactory::sm_pFirst = nullptr;
4041

@@ -186,3 +187,8 @@ GS_EVENT_MEMBER(CGameSystem, GameShutdown)
186187
{
187188
g_pGameRules = nullptr;
188189
}
190+
191+
GS_EVENT_MEMBER(CGameSystem, PostSpawnGroupLoad)
192+
{
193+
g_iSpawnGroupLoads++;
194+
}

src/gamesystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class CGameSystem : public CBaseGameSystem
6868
GS_EVENT(ServerPreEntityThink);
6969
GS_EVENT(ServerPostEntityThink);
7070
GS_EVENT(GameShutdown);
71+
GS_EVENT(PostSpawnGroupLoad);
7172

7273
void Shutdown() override
7374
{

src/playermanager.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ class ZEPlayer
193193
m_flEntwatchHudX = -7.5f;
194194
m_flEntwatchHudY = -2.0f;
195195
m_flEntwatchHudSize = 60.0f;
196+
m_iCheckTransmitSpawnGroupCount = 0;
197+
m_iClientSpawnGroupCount = 0;
196198
}
197199

198200
~ZEPlayer()
@@ -262,6 +264,8 @@ class ZEPlayer
262264
void SetEntwatchHudColor(Color colorHud);
263265
void SetEntwatchHudPos(float x, float y);
264266
void SetEntwatchHudSize(float flSize);
267+
void SetCheckTransmitSpawnGroupCount(int iCheckTransmitSpawnGroupCount) { m_iCheckTransmitSpawnGroupCount = iCheckTransmitSpawnGroupCount; }
268+
void SetClientSpawnGroupCount(int iClientSpawnGroupCount) { m_iClientSpawnGroupCount = iClientSpawnGroupCount; }
265269

266270
uint64 GetAdminFlags() { return m_iAdminFlags; }
267271
int GetAdminImmunity() { return m_iAdminImmunity; }
@@ -311,6 +315,8 @@ class ZEPlayer
311315
float GetEntwatchHudX() { return m_flEntwatchHudX; }
312316
float GetEntwatchHudY() { return m_flEntwatchHudY; }
313317
float GetEntwatchHudSize() { return m_flEntwatchHudSize; }
318+
int GetCheckTransmitSpawnGroupCount() { return m_iCheckTransmitSpawnGroupCount; }
319+
int GetClientSpawnGroupCount() { return m_iClientSpawnGroupCount; }
314320

315321
void OnSpawn();
316322
void OnAuthenticated();
@@ -382,6 +388,8 @@ class ZEPlayer
382388
float m_flEntwatchHudX;
383389
float m_flEntwatchHudY;
384390
float m_flEntwatchHudSize;
391+
int m_iCheckTransmitSpawnGroupCount;
392+
int m_iClientSpawnGroupCount;
385393
};
386394

387395
class CPlayerManager

src/serversideclient.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CHLTVServer;
2929
class INetMessage;
3030
class CNetworkGameServerBase;
3131
class CNetworkGameServer;
32-
struct CUtlSlot;
32+
class CUtlSlot;
3333

3434
struct HltvReplayStats_t
3535
{
@@ -92,7 +92,7 @@ class CCopyableLock : public MUTEX
9292
// ...
9393
};
9494

95-
struct CUtlSlot
95+
class CUtlSlot
9696
{
9797
CUtlVectorMT<CUtlVector<CUtlSignaller_Base*>, CCopyableLock<CThreadFastMutex> > m_ConnectedSignallers;
9898

@@ -391,7 +391,7 @@ class CServerSideClient : public CServerSideClientBase
391391
CClientFrameManager m_FrameManager; // 3568
392392

393393
private:
394-
[[maybe_used]] char pad3856[8]; // 3856
394+
[[maybe_unused]] char pad3856[8]; // 3856
395395

396396
public:
397397
float m_flLastClientCommandQuotaStart = 0.0f; // 3864
@@ -412,7 +412,7 @@ class CServerSideClient : public CServerSideClientBase
412412
void* m_pLastJob; // 4000
413413

414414
private:
415-
[[maybe_used]] char pad3984[8]; // 4008
415+
[[maybe_unused]] char pad3984[8]; // 4008
416416
};
417417

418418
// not full class reversed
@@ -439,7 +439,7 @@ class CHLTVClient : public CServerSideClientBase
439439
bool m_bUnkBool3 = false; // 3019
440440

441441
private:
442-
[[maybe_used]] char pad3976[0x24]; // 3020
442+
[[maybe_unused]] char pad3976[0x24]; // 3020
443443
};
444444

445445
#endif // SERVERSIDECLIENT_H

0 commit comments

Comments
 (0)