Skip to content

Commit

Permalink
fix hide crash on player_death
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyano1337 committed Feb 28, 2025
1 parent 186930c commit 22a9b21
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 145 deletions.
3 changes: 0 additions & 3 deletions launch.vs.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"args": [
"-insecure",
"-dedicated",
"+hostport 27025",
"+game_mode 0",
"+game_type 0",
"+developer 5",
Expand All @@ -30,7 +29,6 @@
"args": [
"-insecure",
"-dedicated",
"+hostport 27025",
"+game_mode 0",
"+game_type 0",
"+map de_dust2",
Expand All @@ -48,7 +46,6 @@
"args": [
"-insecure",
"-dedicated",
"+hostport 27025",
"+game_mode 0",
"+game_type 0",
"+map de_dust2",
Expand Down
8 changes: 8 additions & 0 deletions src/sdk/entity/cbaseplayercontroller.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#include "cbaseplayercontroller.h"
#include <core/memory.h>
#include <utils/utils.h>

void CBasePlayerController::SetPawn(CCSPlayerPawn* pawn) {
MEM::CALL::SetPawn(this, pawn, true, false, false);
}

void CBasePlayerController::SendFullUpdate() {
CServerSideClient* pClient = UTIL::GetClientBySlot(GetPlayerSlot());
if (pClient) {
pClient->ForceFullUpdate();
}
}
1 change: 1 addition & 0 deletions src/sdk/entity/cbaseplayercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ class CBasePlayerController : public CBaseEntity {
}

void SetPawn(CCSPlayerPawn* pawn);
void SendFullUpdate();
};
4 changes: 4 additions & 0 deletions src/sdk/entity/cbaseplayerpawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class CBasePlayerPawn : public CBaseModelEntity {
return !!(this->m_fFlags() & FL_PAWN_FAKECLIENT);
}

bool IsObserver() {
return m_pObserverServices() != nullptr;
}

void CommitSuicide(bool bExplode, bool bForce);

void SetCollisionGroup(StandardCollisionGroups_t group);
Expand Down
170 changes: 42 additions & 128 deletions src/sdk/serversideclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,32 +140,14 @@ class CServerSideClientBase {
return m_nSignonState == SIGNONSTATE_FULL;
}

virtual bool IsFakeClient() const {
return m_bFakePlayer;
}
virtual bool IsFakeClient() = 0;

virtual bool IsHLTV() = 0;

// Is an actual human player or splitscreen player (not a bot and not a HLTV slot)
virtual bool IsHumanPlayer() const {
return false;
}

virtual bool IsHearingClient(CPlayerSlot nSlot) const {
return false;
}

virtual bool IsLowViolenceClient() const {
return m_bLowViolence;
}
virtual bool IsHumanPlayer() = 0;

virtual bool IsSplitScreenUser() const {
return m_bSplitScreenUser;
}

int GetClientPlatform() const {
return m_ClientPlatform;
} // CrossPlayPlatform_t
virtual bool IsHearingClient(CPlayerSlot nSlot) = 0;

public: // Message Handlers
virtual bool ProcessTick(const CNETMsg_Tick_t& msg) = 0;
Expand Down Expand Up @@ -220,15 +202,13 @@ class CServerSideClientBase {
virtual bool UpdateAcknowledgedFramecount(int tick) = 0;

void ForceFullUpdate() {
UpdateAcknowledgedFramecount(-1);
m_nForceWaitForTick = -1;
}

virtual bool ShouldSendMessages() = 0;
virtual void UpdateSendState() = 0;

virtual const CMsgPlayerInfo& GetPlayerInfo() const {
return m_playerInfo;
}
virtual CMsgPlayerInfo& GetPlayerInfo() = 0;

virtual void UpdateUserSettings() = 0;
virtual void ResetUserSettings() = 0;
Expand Down Expand Up @@ -258,9 +238,7 @@ class CServerSideClientBase {
m_bFullyAuthenticated = true;
}

virtual CServerSideClientBase* GetSplitScreenOwner() {
return m_pAttachedTo;
}
virtual CServerSideClientBase* GetSplitScreenOwner() = 0;

virtual int GetNumPlayers() = 0;

Expand Down Expand Up @@ -289,39 +267,30 @@ class CServerSideClientBase {
virtual void PerformDisconnection(ENetworkDisconnectionReason reason) = 0;

public:
void* m_pVT1; // INetworkMessageProcessingPreFilter
CUtlString m_unk16; // 16
void* m_pVT1; // INetworkMessageProcessingPreFilter

private:
[[maybe_unused]] char pad24[0x16]; // 24
MEM_PAD(0x20);
#ifdef __linux__
[[maybe_unused]] char pad46[0x10]; // 46
MEM_PAD(0x10);
#endif

public:
void (*RebroadcastSource)(int msgID); // 64
CUtlString m_UserIDString; // 72
CUtlString m_Name; // 80
CPlayerSlot m_nClientSlot; // 88
CEntityIndex m_nEntityIndex; // 92
CNetworkGameServerBase* m_Server; // 96
INetChannel* m_NetChannel; // 104
uint8 m_nUnkVariable; // 112
bool m_bMarkedToKick; // 113
int32 m_nSignonState; // 116
bool m_bSplitScreenUser; // 120
bool m_bSplitAllowFastDisconnect; // 121
int m_nSplitScreenPlayerSlot; // 124
CServerSideClientBase* m_SplitScreenUsers[4]; // 128
CServerSideClientBase* m_pAttachedTo; // 160
bool m_bSplitPlayerDisconnecting; // 168
int m_UnkVariable172; // 172
bool m_bFakePlayer; // 176
bool m_bSendingSnapshot; // 177
[[maybe_unused]] char pad6[0x5];
CPlayerUserId m_UserID; // 184
bool m_bReceivedPacket; // 186
CSteamID m_SteamID; // 187
void (*RebroadcastSource)(int msgID); // 48
CUtlString m_UserIDString; // 56
CUtlString m_Name; // 64
CPlayerSlot m_nClientSlot; // 72
CEntityIndex m_nEntityIndex; // 76
CNetworkGameServerBase* m_Server; // 80
INetChannel* m_NetChannel; // 88
uint8 m_nUnkVariable; // 96
bool m_bMarkedToKick; // 97
int32 m_nSignonState; // 100
MEM_PAD(0x38);
bool m_bFakePlayer; // 160
MEM_PAD(0x7);
CPlayerUserId m_UserID; // 168
CSteamID m_SteamID; // 170
CSteamID m_UnkSteamID; // 195
CSteamID m_UnkSteamID2; // 203 from auth ticket
CSteamID m_nFriendsID; // 211
Expand All @@ -334,90 +303,35 @@ class CServerSideClientBase {
bool m_bIsReplay; // 299

private:
[[maybe_unused]] char pad29[0xA];
MEM_PAD(0x15);

public:
uint32 m_nSendtableCRC; // 312
int m_ClientPlatform; // 316
int m_nSignonTick; // 320
int m_nDeltaTick; // 324
int m_UnkVariable3; // 328
int m_nStringTableAckTick; // 332
int m_UnkVariable4; // 336
CFrameSnapshot* m_pLastSnapshot; // 344
CUtlVector<void*> m_vecLoadedSpawnGroups; // 352
CMsgPlayerInfo m_playerInfo; // 376
CFrameSnapshot* m_pBaseline; // 432
int m_nBaselineUpdateTick; // 440
CBitVec<MAX_EDICTS> m_BaselinesSent; // 444
int m_nBaselineUsed = 0; // 2492
int m_nLoadingProgress = 0; // 2496
int m_nForceWaitForTick = -1; // 2500
CCircularBuffer m_UnkBuffer = {1024}; // 2504 (24 bytes)
bool m_bLowViolence = false; // 2528
bool m_bSomethingWithAddressType = true; // 2529
bool m_bFullyAuthenticated = false; // 2530
bool m_bUnk1 = false; // 2531
bool m_bUnk2 = false; // 2532
bool m_bUnk3 = false; // 2533
bool m_bUnk4 = false; // 2534
bool m_bUnk5 = false; // 2535
float m_fNextMessageTime = 0.0f; // 2536
float m_fSnapshotInterval = -1.0f; // 2540
float m_fAuthenticatedTime = 0.0f; // 2544

private:
// CSVCMsg_PacketEntities_t m_packetmsg; // 2552
[[maybe_unused]] char pad2552[0x138]; // 2552
int m_nForceWaitForTick; // 308
MEM_PAD(0x882);
bool m_bFullyAuthenticated = false; // 2490
MEM_PAD(0x1C2);
};

public:
CNetworkStatTrace m_Trace; // 2864
int m_spamCommandsCount = 0; // 2904 if the value is greater than 16, the player will be kicked with reason 39
int m_unknown = 0; // 2908
double m_lastExecutedCommand = 0.0; // 2912 if command executed more than once per second, ++m_spamCommandCount

private:
[[maybe_unused]] char pad2920[0x20]; // 2920
}; // sizeof 2952
#ifdef _WIN32
COMPILE_TIME_ASSERT(sizeof(CServerSideClientBase) == 2944);
#endif

class CServerSideClient : public CServerSideClientBase {
public:
virtual ~CServerSideClient() = 0;

public:
CPlayerBitVec m_VoiceStreams; // 2952
CPlayerBitVec m_VoiceProximity; // 2960
void* m_Unk2952;
CCheckTransmitInfo m_PackInfo; // 2968
CClientFrameManager m_FrameManager; // 3568

private:
[[maybe_unused]] char pad3856[8]; // 3856

public:
float m_flLastClientCommandQuotaStart = 0.0f; // 3864
float m_flTimeClientBecameFullyConnected = -1.0f; // 3868
bool m_bVoiceLoopback = false; // 3872
bool m_bUnk10 = false; // 3873
int m_nHltvReplayDelay = 0; // 3876
CHLTVServer* m_pHltvReplayServer; // 3880
int m_nHltvReplayStopAt; // 3888
int m_nHltvReplayStartAt; // 3892
int m_nHltvReplaySlowdownBeginAt; // 3896
int m_nHltvReplaySlowdownEndAt; // 3900
float m_flHltvReplaySlowdownRate; // 3904
int m_nHltvLastSendTick; // 3908
float m_flHltvLastReplayRequestTime; // 3912
CUtlVector<INetMessage*> m_HltvQueuedMessages; // 3920
HltvReplayStats_t m_HltvReplayStats; // 3944
void* m_pLastJob; // 4000

private:
[[maybe_unused]] char pad3984[8]; // 4008
}; // sizeof 4016
CPlayerBitVec m_VoiceStreams; // 2944
CPlayerBitVec m_VoiceProximity; // 2952
CCheckTransmitInfo m_PackInfo; // 2960
MEM_PAD(0x240);
CClientFrameManager m_FrameManager; // 3552
MEM_PAD(0xA0);
};

#ifdef _WIN32
static_assert(offsetof(CServerSideClient, m_PackInfo) == 2960);
COMPILE_TIME_ASSERT(offsetof(CServerSideClient, m_PackInfo) == 2960);
COMPILE_TIME_ASSERT(sizeof(CServerSideClient) == 3968);
#endif

// not full class reversed
Expand Down
30 changes: 20 additions & 10 deletions src/surf/misc/hide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <sdk/entity/ccsplayercontroller.h>
#include <utils/utils.h>
#include <core/playermanager.h>
#include <core/eventmanager.h>

CHidePlugin g_HidePlugin;

Expand All @@ -15,7 +16,7 @@ void SetMenuEntityTransmiter(CBaseEntity* pMenu, CBasePlayerController* pOwner)
g_HidePlugin.SetExclude(pOwner, pMenu, true);
}

void CHidePlugin::ClearEntityTransmitInfo(CEdictBitVec* pTransmitEntity, CEdictBitVec* pTransmitAlways, CBaseEntity* pEntity) {
void CHidePlugin::ClearEntityTransmitInfo(CEdictBitVec* pTransmitEntity, CBaseEntity* pEntity) {
if (!pEntity) {
return;
}
Expand All @@ -26,12 +27,9 @@ void CHidePlugin::ClearEntityTransmitInfo(CEdictBitVec* pTransmitEntity, CEdictB
}

pTransmitEntity->Clear(iEntityIndex);
if (pTransmitAlways->Get(iEntityIndex)) {
pTransmitAlways->Clear(iEntityIndex);
}
};

void CHidePlugin::ClearEntityChildEntities(CEdictBitVec* pTransmitEntity, CEdictBitVec* pTransmitAlways, CBaseEntity* pEntity) {
void CHidePlugin::ClearEntityChildEntities(CEdictBitVec* pTransmitEntity, CBaseEntity* pEntity) {
CBodyComponent* pBodyComponent = pEntity->m_CBodyComponent();
if (!pBodyComponent) {
return;
Expand All @@ -48,7 +46,7 @@ void CHidePlugin::ClearEntityChildEntities(CEdictBitVec* pTransmitEntity, CEdict
continue;
}

ClearEntityTransmitInfo(pTransmitEntity, pTransmitAlways, pChildOwnerEntity);
ClearEntityTransmitInfo(pTransmitEntity, pChildOwnerEntity);
}
}

Expand Down Expand Up @@ -102,6 +100,19 @@ void CHidePlugin::Reset(CBasePlayerController* pOwner) {
m_vBlockTransmit.at(iOwnerSlot).ClearAll();
}

void CHidePlugin::OnPlayerDeath(IGameEvent* pEvent, const char* szName, bool bDontBroadcast) {
auto pController = (CCSPlayerController*)pEvent->GetPlayerController("userid");
if (!pController) {
return;
}

pController->SendFullUpdate();
}

void CHidePlugin::OnPluginStart() {
EVENT::HookEvent("player_death", OnPlayerDeath);
}

void CHidePlugin::OnClientSendSnapshotBefore(CServerSideClient* pClient) {
if (pClient->IsFakeClient() || pClient->m_bIsHLTV) {
return;
Expand All @@ -118,8 +129,7 @@ void CHidePlugin::OnClientSendSnapshotBefore(CServerSideClient* pClient) {
}

auto pTransmitEntity = pClient->m_PackInfo.m_pTransmitEntity;
auto pTransmitAlways = pClient->m_PackInfo.m_pTransmitAlways;
if (!pTransmitEntity || !pTransmitAlways) {
if (!pTransmitEntity) {
return;
}

Expand Down Expand Up @@ -153,7 +163,7 @@ void CHidePlugin::OnClientSendSnapshotBefore(CServerSideClient* pClient) {
}
}

ClearEntityChildEntities(pTransmitEntity, pTransmitAlways, pEnt);
ClearEntityTransmitInfo(pTransmitEntity, pTransmitAlways, pEnt);
ClearEntityChildEntities(pTransmitEntity, pEnt);
ClearEntityTransmitInfo(pTransmitEntity, pEnt);
}
}
8 changes: 6 additions & 2 deletions src/surf/misc/hide.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using CEdictBitVec = CBitVec<MAX_EDICTS>;

class CHidePlugin : CCoreForward {
private:
virtual void OnPluginStart() override;
virtual void OnClientSendSnapshotBefore(CServerSideClient* pClient) override;

public:
Expand All @@ -15,8 +16,11 @@ class CHidePlugin : CCoreForward {
void Reset(CBasePlayerController* pOwner);

private:
void ClearEntityTransmitInfo(CEdictBitVec* pTransmitEntity, CEdictBitVec* pTransmitAlways, CBaseEntity* pEntity);
void ClearEntityChildEntities(CEdictBitVec* pTransmitEntity, CEdictBitVec* pTransmitAlways, CBaseEntity* pEntity);
void ClearEntityTransmitInfo(CEdictBitVec* pTransmitEntity, CBaseEntity* pEntity);
void ClearEntityChildEntities(CEdictBitVec* pTransmitEntity, CBaseEntity* pEntity);

private:
static void OnPlayerDeath(IGameEvent* pEvent, const char* szName, bool bDontBroadcast);

private:
std::array<CEdictBitVec, MAXPLAYERS> m_vBlockTransmit;
Expand Down

0 comments on commit 22a9b21

Please sign in to comment.