Skip to content

Commit a901534

Browse files
committed
Improve clan tag handling
No more stutters!
1 parent 0ad4e84 commit a901534

7 files changed

Lines changed: 25 additions & 97 deletions

File tree

src/cs2_sdk/entity/cbaseplayercontroller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CBasePlayerController : public CBaseEntity
4141

4242
SCHEMA_FIELD(uint64, m_steamID)
4343
SCHEMA_FIELD(CHandle<CBasePlayerPawn>, m_hPawn)
44-
SCHEMA_FIELD_POINTER(char, m_iszPlayerName)
44+
SCHEMA_FIELD_POINTER(char, m_iszPlayerName) // char m_iszPlayerName[128]
4545
SCHEMA_FIELD(PlayerConnectedState, m_iConnected)
4646
SCHEMA_FIELD(bool, m_bIsHLTV)
4747
SCHEMA_FIELD(uint, m_iDesiredFOV)

src/cs2_sdk/entity/ccsplayercontroller.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class CCSPlayerController : public CBasePlayerController
3333
SCHEMA_FIELD(CCSPlayerController_ActionTrackingServices*, m_pActionTrackingServices)
3434
SCHEMA_FIELD(uint32_t, m_iPing)
3535
SCHEMA_FIELD(CUtlSymbolLarge, m_szClan)
36-
SCHEMA_FIELD_POINTER(char, m_szClanName) // char m_szClanName[32]
3736
SCHEMA_FIELD(bool, m_bEverFullyConnected)
3837
SCHEMA_FIELD(bool, m_bPawnIsAlive)
3938
SCHEMA_FIELD(int32_t, m_nDisconnectionTick)
@@ -144,4 +143,24 @@ class CCSPlayerController : public CBasePlayerController
144143
{
145144
m_iScore() = m_iScore() + iScore;
146145
}
146+
147+
void SetClanTag(const char* pszClanTag)
148+
{
149+
// Skip if clan tag is unchanged, since name swap trick has a bit of overhead
150+
if (!V_strcmp(m_szClan().String(), pszClanTag))
151+
return;
152+
153+
m_szClan = g_pEntitySystem->AllocPooledString(pszClanTag);
154+
155+
// This name swap trick is necessary to get clients to display the new clan tag
156+
std::string strName = GetPlayerName();
157+
158+
if (!strName.empty() && strName.back() == ' ')
159+
strName.pop_back();
160+
else
161+
strName.push_back(' ');
162+
163+
V_strncpy(m_iszPlayerName, strName.c_str(), 128);
164+
m_iszPlayerName.NetworkStateChanged();
165+
}
147166
};

src/entwatch.cpp

Lines changed: 4 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -798,14 +798,12 @@ void EWItemInstance::Pickup(int slot)
798798
if (bShouldSetClantag)
799799
{
800800
bHasThisClantag = true;
801-
pController->m_szClan(sClantag);
801+
pController->SetClanTag(sClantag);
802802
if (g_cvarItemHolderScore.Get() > -1)
803803
{
804804
int score = pController->m_iScore + g_cvarItemHolderScore.Get();
805805
pController->m_iScore = score;
806806
}
807-
808-
EW_UpdateClientClanTags();
809807
}
810808
}
811809

@@ -840,7 +838,7 @@ void EWItemInstance::Drop(EWDropReason reason, CCSPlayerController* pController)
840838
{
841839
// Player IS holding another item, score doesnt need adjusting
842840

843-
pController->m_szClan(g_pEWHandler->vecItems[otherItem]->sClantag);
841+
pController->SetClanTag(g_pEWHandler->vecItems[otherItem]->sClantag);
844842
g_pEWHandler->vecItems[otherItem]->bHasThisClantag = true;
845843
bSetAnotherClantag = true;
846844
break;
@@ -857,10 +855,8 @@ void EWItemInstance::Drop(EWDropReason reason, CCSPlayerController* pController)
857855
pController->m_iScore = score;
858856
}
859857

860-
pController->m_szClan("");
858+
pController->SetClanTag("");
861859
}
862-
863-
EW_UpdateClientClanTags();
864860
}
865861

866862
char sPlayerInfo[64];
@@ -1504,10 +1500,8 @@ void CEWHandler::ResetAllClantags()
15041500
pController->m_iScore = score;
15051501
}
15061502

1507-
pController->m_szClan("");
1503+
pController->SetClanTag("");
15081504
}
1509-
1510-
EW_UpdateClientClanTags();
15111505
}
15121506

15131507
int CEWHandler::RegisterItem(CBasePlayerWeapon* pWeapon)
@@ -2259,49 +2253,6 @@ void EW_PlayerDisconnect(int slot)
22592253
g_pEWHandler->PlayerDrop(EWDropReason::Disconnect, -1, pController);
22602254
}
22612255

2262-
// An event needs to be sent to force clients to see up to date clantags
2263-
void EW_UpdateClientClanTags()
2264-
{
2265-
// Cannot send this event during map vote, as it breaks voting client side
2266-
if (!GetGlobals() || !g_pMapVoteSystem->IsIntermissionAllowed())
2267-
return;
2268-
2269-
static IGameEvent* pEvent = nullptr;
2270-
2271-
if (!pEvent)
2272-
pEvent = g_gameEventManager->CreateEvent("nextlevel_changed");
2273-
2274-
if (!pEvent)
2275-
{
2276-
Panic("Failed to create nextlevel_changed event\n");
2277-
return;
2278-
}
2279-
2280-
INetworkMessageInternal* pMsg = g_pNetworkMessages->FindNetworkMessageById(GE_Source1LegacyGameEvent);
2281-
if (!pMsg)
2282-
{
2283-
Panic("Failed to create Source1LegacyGameEvent\n");
2284-
return;
2285-
}
2286-
CNetMessagePB<CMsgSource1LegacyGameEvent>* data = pMsg->AllocateMessage()->ToPB<CMsgSource1LegacyGameEvent>();
2287-
g_gameEventManager->SerializeEvent(pEvent, data);
2288-
2289-
CRecipientFilter filter;
2290-
for (int i = 0; i < GetGlobals()->maxClients; i++)
2291-
{
2292-
ZEPlayer* pPlayer = g_playerManager->GetPlayer(i);
2293-
2294-
if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsAuthenticated())
2295-
continue;
2296-
2297-
if (pPlayer->GetEntwatchClangtags())
2298-
filter.AddRecipient(pPlayer->GetPlayerSlot());
2299-
}
2300-
2301-
g_gameEventSystem->PostEventAbstract(-1, false, &filter, pMsg, data, 0);
2302-
delete data;
2303-
}
2304-
23052256
bool EW_IsFireOutputHooked()
23062257
{
23072258
return std::any_of(mapIOFunctions.begin(), mapIOFunctions.end(), [](const auto& p) { return p.first == "entwatch"; });
@@ -2650,34 +2601,6 @@ CON_COMMAND_CHAT(ew_dump, "- Prints the currently loaded config to console")
26502601
g_pEWHandler->PrintLoadedConfig(player->GetPlayerSlot());
26512602
}
26522603

2653-
CON_COMMAND_CHAT(etag, "- Toggle EntWatch clantags on the scoreboard")
2654-
{
2655-
if (!g_cvarEnableEntWatch.Get())
2656-
return;
2657-
2658-
if (!player)
2659-
{
2660-
ClientPrint(player, HUD_PRINTTALK, EW_PREFIX "Only usable in game.");
2661-
return;
2662-
}
2663-
2664-
ZEPlayer* zpPlayer = g_playerManager->GetPlayer(player->GetPlayerSlot());
2665-
if (!zpPlayer)
2666-
{
2667-
ClientPrint(player, HUD_PRINTTALK, EW_PREFIX "Something went wrong, try again later.");
2668-
return;
2669-
}
2670-
2671-
bool bCurrentStatus = zpPlayer->GetEntwatchClangtags();
2672-
bCurrentStatus = !bCurrentStatus;
2673-
zpPlayer->SetEntwatchClangtags(bCurrentStatus);
2674-
2675-
if (bCurrentStatus)
2676-
ClientPrint(player, HUD_PRINTTALK, EW_PREFIX "You have\x04 Enabled\x01 EntWatch clantag updates");
2677-
else
2678-
ClientPrint(player, HUD_PRINTTALK, EW_PREFIX "You have\x07 Disabled\x01 EntWatch clantag updates");
2679-
}
2680-
26812604
CON_COMMAND_CHAT(hud, "- Toggle EntWatch HUD")
26822605
{
26832606
if (!g_cvarEnableEntWatch.Get())

src/entwatch.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ extern CConVar<bool> g_cvarEnableEntwatchHud;
3636
#define EW_PREFIX " \4[EntWatch]\1 "
3737

3838
#define EW_PREF_HUD_MODE "entwatch_hud"
39-
#define EW_PREF_CLANTAG "entwatch_clantag"
4039
#define EW_PREF_HUDPOS_X "entwatch_hudpos_x"
4140
#define EW_PREF_HUDPOS_Y "entwatch_hudpos_y"
4241
#define EW_PREF_HUDCOLOR "entwatch_hudcolor"
@@ -297,7 +296,6 @@ void EW_DropWeapon(CCSPlayer_WeaponServices* pWeaponServices, CBasePlayerWeapon*
297296
void EW_PlayerDeath(IGameEvent* pEvent);
298297
void EW_PlayerDeathPre(CCSPlayerController* pController);
299298
void EW_PlayerDisconnect(int slot);
300-
void EW_UpdateClientClanTags();
301299
bool EW_IsFireOutputHooked();
302300
void EW_FireOutput(const CEntityIOOutput* pThis, CEntityInstance* pActivator, CEntityInstance* pCaller, const CVariant* value, float flDelay);
303301
int GetTemplateSuffixNumber(const char* szName);

src/playermanager.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,6 @@ void ZEPlayer::SetEntwatchHudMode(int iMode)
715715
g_pUserPreferencesSystem->SetPreferenceInt(m_slot.Get(), EW_PREF_HUD_MODE, m_iEntwatchHudMode);
716716
}
717717

718-
void ZEPlayer::SetEntwatchClangtags(bool bStatus)
719-
{
720-
m_bEntwatchClantags = bStatus;
721-
g_pUserPreferencesSystem->SetPreferenceInt(m_slot.Get(), EW_PREF_CLANTAG, bStatus ? 1 : 0);
722-
}
723-
724718
void ZEPlayer::SetEntwatchHudColor(Color colorHud)
725719
{
726720
m_colorEntwatchHud = colorHud;

src/playermanager.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ class ZEPlayer
192192
m_pActiveZRModel = nullptr;
193193
m_iButtonWatchMode = 0;
194194
m_iEntwatchHudMode = 0;
195-
m_bEntwatchClantags = true;
196195
m_colorEntwatchHud = Color(255, 255, 255, 255);
197196
m_flEntwatchHudX = -7.5f;
198197
m_flEntwatchHudY = -2.0f;
@@ -261,7 +260,6 @@ class ZEPlayer
261260
void SetActiveZRClass(std::shared_ptr<ZRClass> pZRModel) { m_pActiveZRClass = pZRModel; }
262261
void SetActiveZRModel(std::shared_ptr<ZRModelEntry> pZRClass) { m_pActiveZRModel = pZRClass; }
263262
void SetEntwatchHudMode(int iMode);
264-
void SetEntwatchClangtags(bool bStatus);
265263
void SetPointOrient(CPointOrient* pOrient) { m_hPointOrient.Set(pOrient); }
266264
void SetEntwatchHud(CPointWorldText* pWorldText) { m_hEntwatchHud.Set(pWorldText); }
267265
void SetEntwatchHudColor(Color colorHud);
@@ -309,7 +307,6 @@ class ZEPlayer
309307
std::shared_ptr<ZRModelEntry> GetActiveZRModel() { return m_pActiveZRModel; }
310308
int GetButtonWatchMode();
311309
int GetEntwatchHudMode();
312-
bool GetEntwatchClangtags() { return m_bEntwatchClantags; }
313310
CPointOrient* GetPointOrient() { return m_hPointOrient.Get(); }
314311
CPointWorldText* GetEntwatchHud() { return m_hEntwatchHud.Get(); }
315312
Color GetEntwatchHudColor() { return m_colorEntwatchHud; }
@@ -384,7 +381,6 @@ class ZEPlayer
384381
CHandle<CPointOrient> m_hPointOrient;
385382
CHandle<CPointWorldText> m_hEntwatchHud;
386383
int m_iEntwatchHudMode;
387-
bool m_bEntwatchClantags;
388384
Color m_colorEntwatchHud;
389385
float m_flEntwatchHudX;
390386
float m_flEntwatchHudY;

src/user_preferences.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ void CUserPreferencesSystem::OnPutPreferences(int iSlot)
116116

117117
// EntWatch
118118
int iEntwatchMode = GetPreferenceInt(iSlot, EW_PREF_HUD_MODE, 0);
119-
bool bEntwatchClantag = (bool)GetPreferenceInt(iSlot, EW_PREF_CLANTAG, 1);
120119
float flEntwatchHudposX = GetPreferenceFloat(iSlot, EW_PREF_HUDPOS_X, EW_HUDPOS_X_DEFAULT);
121120
float flEntwatchHudposY = GetPreferenceFloat(iSlot, EW_PREF_HUDPOS_Y, EW_HUDPOS_Y_DEFAULT);
122121
Color ewHudColor;
@@ -137,7 +136,6 @@ void CUserPreferencesSystem::OnPutPreferences(int iSlot)
137136

138137
// Set EntWatch
139138
player->SetEntwatchHudMode(iEntwatchMode);
140-
player->SetEntwatchClangtags(bEntwatchClantag);
141139
player->SetEntwatchHudPos(flEntwatchHudposX, flEntwatchHudposY);
142140
player->SetEntwatchHudColor(ewHudColor);
143141
player->SetEntwatchHudSize(flEntwatchHudSize);

0 commit comments

Comments
 (0)