Skip to content

Commit b64b551

Browse files
authored
fix dereferencing nullptr in ghost_capture event (#1883)
* init * checked in playerbyindex already * do the same for the vip, check each cap exists before turning it off * fxies to vip and jug nullptr dereference * we do not have a player_ghost_capture event
1 parent 0eee1ec commit b64b551

2 files changed

Lines changed: 34 additions & 15 deletions

File tree

src/game/client/neo/ui/neo_hud_deathnotice.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -908,19 +908,20 @@ void CNEOHud_DeathNotice::AddPlayerRankChange(IGameEvent* event)
908908

909909
void CNEOHud_DeathNotice::AddPlayerGhostCapture(IGameEvent* event)
910910
{
911-
// the event should be "player_ghost_capture"
912-
const int playerCapturedGhost = engine->GetPlayerForUserID(event->GetInt("userid"));
911+
// the event should be "ghost_capture"
912+
const int playerCapturedGhostUserID = event->GetInt("userid");
913+
const int playerCapturedGhostIndex = playerCapturedGhostUserID != INVALID_USER_ID ? engine->GetPlayerForUserID(playerCapturedGhostUserID) : 0;
913914

914915
// Get the name of the player
915-
C_NEO_Player* pPlayer = ToNEOPlayer(UTIL_PlayerByIndex(playerCapturedGhost));
916-
const char* playerCapturedGhostName = pPlayer ? pPlayer->GetPlayerNameWithTakeoverContext(playerCapturedGhost) : "";
916+
C_NEO_Player* pPlayer = ToNEOPlayer(UTIL_PlayerByIndex(playerCapturedGhostIndex));
917+
const char* playerCapturedGhostName = pPlayer ? pPlayer->GetPlayerNameWithTakeoverContext(playerCapturedGhostIndex) : "";
917918

918919
// Make a new death notice
919920
DeathNoticeItem deathMsg;
920-
deathMsg.Killer.iEntIndex = playerCapturedGhost;
921+
deathMsg.Killer.iEntIndex = playerCapturedGhostIndex;
921922
g_pVGuiLocalize->ConvertANSIToUnicode(playerCapturedGhostName, deathMsg.Killer.szName, sizeof(deathMsg.Killer.szName));
922923
deathMsg.Killer.iNameLength = V_wcslen(deathMsg.Killer.szName);
923-
if (const auto playerCapturedGhostTeam = GetPlayersTeam(playerCapturedGhost))
924+
if (const auto playerCapturedGhostTeam = GetPlayersTeam(playerCapturedGhostIndex))
924925
{
925926
deathMsg.Killer.iTeam = playerCapturedGhostTeam->GetTeamNumber();
926927
}
@@ -937,18 +938,19 @@ void CNEOHud_DeathNotice::AddPlayerGhostCapture(IGameEvent* event)
937938
void CNEOHud_DeathNotice::AddVIPExtract(IGameEvent* event)
938939
{
939940
// the event should be "vip_extract"
940-
const int playerExtracted = engine->GetPlayerForUserID(event->GetInt("userid"));
941+
const int playerExtractedUserID = event->GetInt("userid");
942+
const int playerExtractedIndex = playerExtractedUserID != INVALID_USER_ID ? engine->GetPlayerForUserID(playerExtractedUserID) : 0;
941943

942944
// Name of VIP
943-
C_NEO_Player* pPlayer = ToNEOPlayer(UTIL_PlayerByIndex(playerExtracted));
944-
const char* playerExtractedName = pPlayer ? pPlayer->GetPlayerNameWithTakeoverContext(playerExtracted) : "";
945+
C_NEO_Player* pPlayer = ToNEOPlayer(UTIL_PlayerByIndex(playerExtractedIndex));
946+
const char* playerExtractedName = pPlayer ? pPlayer->GetPlayerNameWithTakeoverContext(playerExtractedIndex) : "";
945947

946948
// Make a new death notice
947949
DeathNoticeItem deathMsg;
948-
deathMsg.Killer.iEntIndex = playerExtracted;
950+
deathMsg.Killer.iEntIndex = playerExtractedIndex;
949951
g_pVGuiLocalize->ConvertANSIToUnicode(playerExtractedName, deathMsg.Killer.szName, sizeof(deathMsg.Killer.szName));
950952
deathMsg.Killer.iNameLength = V_wcslen(deathMsg.Killer.szName);
951-
if (const auto playerExtractedTeam = GetPlayersTeam(playerExtracted))
953+
if (const auto playerExtractedTeam = GetPlayersTeam(playerExtractedIndex))
952954
{
953955
deathMsg.Killer.iTeam = playerExtractedTeam->GetTeamNumber();
954956
}

src/game/shared/neo/neo_gamerules.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,13 +1431,19 @@ void CNEORules::Think(void)
14311431
for (int i = 0; i < m_pGhostCaps.Count(); i++)
14321432
{
14331433
auto pGhostCap = dynamic_cast<CNEOGhostCapturePoint*>(UTIL_EntityByIndex(m_pGhostCaps[i]));
1434+
if (!pGhostCap)
1435+
{
1436+
Assert(false);
1437+
continue;
1438+
}
14341439
pGhostCap->SetActive(false);
14351440
}
14361441

14371442
IGameEvent* event = gameeventmanager->CreateEvent("ghost_capture");
14381443
if (event)
14391444
{
1440-
event->SetInt("userid", UTIL_PlayerByIndex(m_iGhosterPlayer)->GetUserID());
1445+
CBasePlayer* pCaptorClient = UTIL_PlayerByIndex(captorClient);
1446+
event->SetInt("userid", pCaptorClient ? pCaptorClient->GetUserID() : INVALID_USER_ID);
14411447
gameeventmanager->FireEvent(event);
14421448
}
14431449

@@ -1505,8 +1511,7 @@ void CNEORules::Think(void)
15051511
gameeventmanager->FireEvent(event);
15061512
}
15071513
}
1508-
1509-
if (!m_pVIP->IsAlive())
1514+
else if (!m_pVIP->IsAlive())
15101515
{
15111516
if (sv_neo_vip_ctg_on_death.GetBool())
15121517
{
@@ -1544,6 +1549,11 @@ void CNEORules::Think(void)
15441549
for (int i = 0; i < m_pGhostCaps.Count(); i++)
15451550
{
15461551
auto pGhostCap = dynamic_cast<CNEOGhostCapturePoint*>(UTIL_EntityByIndex(m_pGhostCaps[i]));
1552+
if (!pGhostCap)
1553+
{
1554+
Assert(false);
1555+
continue;
1556+
}
15471557
pGhostCap->SetActive(false);
15481558
}
15491559

@@ -1553,7 +1563,8 @@ void CNEORules::Think(void)
15531563
IGameEvent* event = gameeventmanager->CreateEvent("vip_extract");
15541564
if (event)
15551565
{
1556-
event->SetInt("userid", m_pVIP->GetUserID());
1566+
CBasePlayer* pCaptorClient = UTIL_PlayerByIndex(captorClient);
1567+
event->SetInt("userid", pCaptorClient ? pCaptorClient->GetUserID() : INVALID_USER_ID);
15571568
gameeventmanager->FireEvent(event);
15581569
}
15591570

@@ -4243,9 +4254,15 @@ void CNEORules::ClientDisconnected(edict_t* pClient)
42434254

42444255
if (pNeoPlayer->GetClass() == NEO_CLASS_JUGGERNAUT && pNeoPlayer->IsAlive())
42454256
{
4257+
m_pJuggernautPlayer = nullptr;
42464258
pNeoPlayer->SpawnJuggernautPostDeath();
42474259
}
42484260

4261+
if (pNeoPlayer->GetClass() == NEO_CLASS_VIP)
4262+
{ // can't check if m_pVIP is this player, assume only one vip per round. NEO TODO (Adam) Use CHandles or entity indexes for m_pVIP, m_pJuggernautPlayer
4263+
m_pVIP = nullptr;
4264+
}
4265+
42494266
// Save XP/death counts
42504267
if (sv_neo_player_restore.GetBool())
42514268
{

0 commit comments

Comments
 (0)