Skip to content

Commit 3fc59f0

Browse files
committed
Add utilities file
1 parent bc0ccf8 commit 3fc59f0

File tree

16 files changed

+155
-97
lines changed

16 files changed

+155
-97
lines changed

AMBuilder

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ for sdk_target in MMSPlugin.sdk_targets:
4949
'src/utils/entity.cpp',
5050
'src/utils/weapon.cpp',
5151
'src/utils/hud_manager.cpp',
52+
'src/utils/utils.cpp',
5253
'src/cs2_sdk/entity/services.cpp',
5354
'src/cs2_sdk/entity/ccsplayerpawn.cpp',
5455
'src/cs2_sdk/entity/cbasemodelentity.cpp',

CS2Fixes.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@
218218
<ClCompile Include="src\utils\plat_win.cpp" />
219219
<ClCompile Include="src\utils\weapon.cpp" />
220220
<ClCompile Include="src\utils\hud_manager.cpp" />
221+
<ClCompile Include="src\utils\utils.cpp" />
221222
<ClCompile Include="src\cs2_sdk\entity\services.cpp" />
222223
<ClCompile Include="src\cs2_sdk\entity\ccsplayerpawn.cpp" />
223224
<ClCompile Include="src\cs2_sdk\entity\cbasemodelentity.cpp" />
@@ -296,6 +297,7 @@
296297
<ClInclude Include="src\utils\weapon.h" />
297298
<ClInclude Include="src\utils\version_gen_placeholder.h" />
298299
<ClInclude Include="src\utils\hud_manager.h" />
300+
<ClInclude Include="src\utils\utils.h" />
299301
</ItemGroup>
300302
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
301303
<ImportGroup Label="ExtensionTargets" />

CS2Fixes.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@
185185
<ClCompile Include="src\utils\hud_manager.cpp">
186186
<Filter>Source Files\utils</Filter>
187187
</ClCompile>
188+
<ClCompile Include="src\utils\utils.cpp">
189+
<Filter>Source Files\utils</Filter>
190+
</ClCompile>
188191
<ClCompile Include="src\cs2_sdk\entity\services.cpp">
189192
<Filter>Source Files\cs2_sdk\entity</Filter>
190193
</ClCompile>
@@ -412,6 +415,9 @@
412415
<ClInclude Include="src\utils\hud_manager.h">
413416
<Filter>Header Files\utils</Filter>
414417
</ClInclude>
418+
<ClInclude Include="src\utils\utils.h">
419+
<Filter>Header Files\utils</Filter>
420+
</ClInclude>
415421
<ClInclude Include="src\cs2_sdk\entity\cpointorient.h">
416422
<Filter>Header Files\cs2_sdk\entity</Filter>
417423
</ClInclude>

src/adminsystem.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,11 +594,9 @@ CON_COMMAND_CHAT_FLAGS(rcon, "<command> - Send a command to server console", ADM
594594
}
595595

596596
// Normally this should be done on plugin init, but for whatever reason "log_flags <channel> +donotecho" crashes AFTER this
597-
ExecuteOnce
598-
(
597+
ExecuteOnce(
599598
LoggingSystem_RegisterBackdoorLoggingListener(&g_LoggingListener);
600-
LoggingSystem_EnableBackdoorLoggingListeners(true);
601-
);
599+
LoggingSystem_EnableBackdoorLoggingListeners(true););
602600

603601
// We don't have the equivalent of ServerExecute (to immediately execute commands) in source2, so manually find and execute the command
604602

src/commands.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,12 @@ CON_COMMAND_CHAT(showteam, "<name> - Get a player's current team")
744744
}
745745
}
746746

747+
// Because sv_fullupdate doesn't work
748+
CON_COMMAND_F(cs2f_fullupdate, "- Force a full update for all clients.", FCVAR_LINKED_CONCOMMAND | FCVAR_SPONLY)
749+
{
750+
g_playerManager->FullUpdateAllClients();
751+
}
752+
747753
#if _DEBUG
748754
CON_COMMAND_CHAT(myuid, "- Test")
749755
{

src/common.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#pragma once
2121

2222
#include "platform.h"
23+
#include "utils.h"
2324

2425
#define VPROF_LEVEL 1
2526

@@ -44,7 +45,4 @@
4445
#endif
4546

4647
void UnlockConVars();
47-
void UnlockConCommands();
48-
49-
void Message(const char*, ...);
50-
void Panic(const char*, ...);
48+
void UnlockConCommands();

src/cs2_sdk/entity/globaltypes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ struct EmitSound_t
152152
{
153153
}
154154
const char* m_pSoundName; // 0x0
155-
Vector m_vecSoundOrigin; // 0x8
156-
float m_flVolume; // 0x14
157-
float m_flSoundTime; // 0x18
155+
Vector m_vecSoundOrigin; // 0x8
156+
float m_flVolume; // 0x14
157+
float m_flSoundTime; // 0x18
158158
private:
159159
uint8_t pad_1c[0x4];
160160

src/cs2fixes.cpp

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* =============================================================================
33
* CS2Fixes
44
* Copyright (C) 2023-2025 Source2ZE
@@ -63,32 +63,6 @@
6363

6464
#include "tier0/memdbgon.h"
6565

66-
void Message(const char* msg, ...)
67-
{
68-
va_list args;
69-
va_start(args, msg);
70-
71-
char buf[1024] = {};
72-
V_vsnprintf(buf, sizeof(buf) - 1, msg, args);
73-
74-
ConColorMsg(Color(255, 0, 255, 255), "[CS2Fixes] %s", buf);
75-
76-
va_end(args);
77-
}
78-
79-
void Panic(const char* msg, ...)
80-
{
81-
va_list args;
82-
va_start(args, msg);
83-
84-
char buf[1024] = {};
85-
V_vsnprintf(buf, sizeof(buf) - 1, msg, args);
86-
87-
Warning("[CS2Fixes] %s", buf);
88-
89-
va_end(args);
90-
}
91-
9266
class GameSessionConfiguration_t
9367
{};
9468

@@ -691,11 +665,6 @@ void CS2Fixes::Hook_GameServerSteamAPIDeactivated()
691665
RETURN_META(MRES_IGNORED);
692666
}
693667

694-
uint32 GetSoundEventHash(const char* pszSoundEventName)
695-
{
696-
return MurmurHash2LowerCase(pszSoundEventName, 0x53524332);
697-
}
698-
699668
void CS2Fixes::Hook_PostEvent(CSplitScreenSlot nSlot, bool bLocalOnly, int nClientCount, const uint64* clients,
700669
INetworkMessageInternal* pEvent, const CNetMessage* pData, unsigned long nSize, NetChannelBufType_t bufType)
701670
{
@@ -839,42 +808,6 @@ void CS2Fixes::AllPluginsLoaded()
839808
Message("AllPluginsLoaded\n");
840809
}
841810

842-
CUtlVector<CServerSideClient*>* GetClientList()
843-
{
844-
if (!GetNetworkGameServer())
845-
return nullptr;
846-
847-
static int offset = g_GameConfig->GetOffset("CNetworkGameServer_ClientList");
848-
return (CUtlVector<CServerSideClient*>*)(&GetNetworkGameServer()[offset]);
849-
}
850-
851-
CServerSideClient* GetClientBySlot(CPlayerSlot slot)
852-
{
853-
CUtlVector<CServerSideClient*>* pClients = GetClientList();
854-
855-
if (!pClients)
856-
return nullptr;
857-
858-
return pClients->Element(slot.Get());
859-
}
860-
861-
void FullUpdateAllClients()
862-
{
863-
auto pClients = GetClientList();
864-
865-
if (!pClients)
866-
return;
867-
868-
FOR_EACH_VEC(*pClients, i)
869-
(*pClients)[i]->ForceFullUpdate();
870-
}
871-
872-
// Because sv_fullupdate doesn't work
873-
CON_COMMAND_F(cs2f_fullupdate, "- Force a full update for all clients.", FCVAR_LINKED_CONCOMMAND | FCVAR_SPONLY)
874-
{
875-
FullUpdateAllClients();
876-
}
877-
878811
void CS2Fixes::Hook_ClientActive(CPlayerSlot slot, bool bLoadGame, const char* pszName, uint64 xuid)
879812
{
880813
Message("Hook_ClientActive(%d, %d, \"%s\", %lli)\n", slot, bLoadGame, pszName, xuid);

src/cs2fixes.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* =============================================================================
33
* CS2Fixes
44
* Copyright (C) 2023-2025 Source2ZE
@@ -52,11 +52,8 @@ extern CSteamGameServerAPIContext g_steamAPI;
5252
extern CCSGameRules* g_pGameRules;
5353
extern CSpawnGroupMgrGameSystem* g_pSpawnGroupMgr;
5454
extern double g_flUniversalTime;
55+
extern INetworkGameServer* GetNetworkGameServer();
5556
extern CGlobalVars* GetGlobals();
56-
extern uint32 GetSoundEventHash(const char* pszSoundEventName);
57-
extern CUtlVector<CServerSideClient*>* GetClientList();
58-
extern CServerSideClient* GetClientBySlot(CPlayerSlot slot);
59-
extern void FullUpdateAllClients();
6057
extern CConVar<bool> g_cvarDropMapWeapons;
6158

6259
class CS2Fixes : public ISmmPlugin, public IMetamodListener, public ICS2Fixes

src/map_votes.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ std::vector<std::shared_ptr<CMap>> CMapVoteSystem::GetMapsFromSubstring(const ch
607607

608608
void CMapVoteSystem::HandlePlayerMapLookup(CCSPlayerController* pController, std::string strMapSubstring, bool bAdmin, QueryCallback_t callbackSuccess)
609609
{
610-
strMapSubstring = g_pMapVoteSystem->StringToLower(strMapSubstring);
610+
strMapSubstring = StringToLower(strMapSubstring);
611611
const char* pszMapSubstring = strMapSubstring.c_str();
612612
auto vecFoundMaps = GetMapsFromSubstring(pszMapSubstring);
613613

@@ -1212,14 +1212,6 @@ std::string CMapVoteSystem::ConvertFloatToString(float fValue, int precision)
12121212
return str;
12131213
}
12141214

1215-
std::string CMapVoteSystem::StringToLower(std::string strValue)
1216-
{
1217-
for (int i = 0; strValue[i]; i++)
1218-
strValue[i] = tolower(strValue[i]);
1219-
1220-
return strValue;
1221-
}
1222-
12231215
std::string CMapVoteSystem::GetMapCooldownText(const char* pszMapName, bool bPlural)
12241216
{
12251217
std::shared_ptr<CCooldown> pCooldown = GetMapCooldown(pszMapName);

0 commit comments

Comments
 (0)