Add UTIL_IsValidPlayer

Ignore dormant players
Minor refactoring
This commit is contained in:
s1lentq 2024-05-28 22:44:29 +07:00
parent c08e6d0180
commit 7372573c89
22 changed files with 262 additions and 203 deletions

View File

@ -43,10 +43,7 @@ int GetBotFollowCount(CBasePlayer *pLeader)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -685,10 +682,7 @@ CBasePlayer *CCSBot::GetImportantEnemy(bool checkVisibility) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))

View File

@ -65,10 +65,7 @@ void BotMeme::Transmit(CCSBot *pSender) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -1525,10 +1522,7 @@ BotStatement *BotChatterInterface::GetActiveStatement()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))

View File

@ -337,6 +337,10 @@ void CCSBotManager::ClientDisconnect(CBasePlayer *pPlayer)
pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pevTemp);
AddEntityHashValue(pPlayer->pev, STRING(pPlayer->pev->classname), CLASSNAME);
pPlayer->pev->flags = FL_DORMANT;
#ifdef REGAMEDLL_FIXES
pPlayer->has_disconnected = true;
#endif
}
void PrintAllEntities()
@ -396,10 +400,8 @@ void CCSBotManager::ServerCommand(const char *pcmd)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
const char *name = STRING(pPlayer->pev->netname);
@ -425,10 +427,8 @@ void CCSBotManager::ServerCommand(const char *pcmd)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
const char *name = STRING(pPlayer->pev->netname);
@ -665,6 +665,9 @@ void CCSBotManager::ServerCommand(const char *pcmd)
CBaseEntity *pEntity = nullptr;
while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player")))
{
if (FNullEnt(pEntity->edict()))
break;
if (!pEntity->IsPlayer())
continue;
@ -1580,7 +1583,8 @@ void CCSBotManager::OnFreeEntPrivateData(CBaseEntity *pEntity)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || pPlayer->IsDormant())
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->IsBot())

View File

@ -1118,10 +1118,7 @@ bool CCSBot::IsFriendInTheWay(const Vector *goalPos) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsAlive())

View File

@ -253,7 +253,7 @@ bool CCSBot::IsVisible(CBasePlayer *pPlayer, bool testFOV, unsigned char *visPar
if ((pPlayer->pev->flags & FL_NOTARGET) || (pPlayer->pev->effects & EF_NODRAW))
return false;
#endif
Vector spot = pPlayer->pev->origin;
unsigned char testVisParts = NONE;
@ -701,10 +701,7 @@ CBasePlayer *CCSBot::FindMostDangerousThreat()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
// is it a player?

View File

@ -545,7 +545,11 @@ void CCareerTaskManager::HandleDeath(int team, CBasePlayer *pAttacker)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer && pPlayer->m_iTeam == enemyTeam && pPlayer->IsAlive())
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->m_iTeam == enemyTeam && pPlayer->IsAlive())
numEnemies++;
}

View File

@ -438,6 +438,9 @@ NOXREF int CountTeams()
if (FNullEnt(pEntity->edict()))
break;
if (pEntity->IsDormant())
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->m_iTeam == UNASSIGNED)
@ -499,7 +502,8 @@ int CountTeamPlayers(int iTeam)
if (pEntity->IsDormant())
continue;
if (GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev)->m_iTeam == iTeam)
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->m_iTeam == iTeam)
{
nCount++;
}
@ -534,6 +538,9 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
if (FNullEnt(pTempEntity->edict()))
break;
if (pTempEntity->IsDormant())
continue;
pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
@ -571,6 +578,9 @@ void ProcessKickVote(CBasePlayer *pVotingPlayer, CBasePlayer *pKickPlayer)
if (FNullEnt(pTempEntity->edict()))
break;
if (pTempEntity->IsDormant())
continue;
pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
if (!pTempPlayer || pTempPlayer->m_iTeam == UNASSIGNED)
@ -976,6 +986,9 @@ void Host_Say(edict_t *pEntity, BOOL teamonly)
if (pReceiver->edict() == pEntity)
continue;
if (pReceiver->IsDormant())
continue;
// Not a client ? (should never be true)
if (!pReceiver->IsNetClient())
continue;
@ -2343,6 +2356,9 @@ CBaseEntity *EntityFromUserID(int userID)
if (FNullEnt(pTempEntity->edict()))
break;
if (pTempEntity->IsDormant())
continue;
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
if (pTempPlayer->m_iTeam != UNASSIGNED && userID == GETPLAYERUSERID(pTempEntity->edict()))
@ -2363,6 +2379,9 @@ NOXREF int CountPlayersInServer()
if (FNullEnt(pTempEntity->edict()))
break;
if (pTempEntity->IsDormant())
continue;
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pTempEntity->pev);
if (pTempPlayer->m_iTeam != UNASSIGNED)
@ -3343,7 +3362,11 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
if (pObserver && pObserver->IsObservingPlayer(pPlayer))
if (!UTIL_IsValidPlayer(pObserver))
continue;
if (pObserver->IsObservingPlayer(pPlayer))
{
EMIT_SOUND(ENT(pObserver->pev), CHAN_ITEM, "items/nvg_off.wav", RANDOM_FLOAT(0.92, 1), ATTN_NORM);
@ -3368,7 +3391,11 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
if (pObserver && pObserver->IsObservingPlayer(pPlayer))
if (!UTIL_IsValidPlayer(pObserver))
continue;
if (pObserver->IsObservingPlayer(pPlayer))
{
EMIT_SOUND(ENT(pObserver->pev), CHAN_ITEM, "items/nvg_on.wav", RANDOM_FLOAT(0.92, 1), ATTN_NORM);

View File

@ -37,7 +37,10 @@ void SV_Continue_f()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer && !pPlayer->IsBot())
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsBot())
{
// at the end of the round is showed window with the proposal surrender or continue
// now of this time HUD is completely hidden
@ -96,7 +99,7 @@ void SV_Career_EndRound_f()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->IsBot() && pPlayer->m_iTeam == pLocalPlayer->m_iTeam)

View File

@ -9,7 +9,11 @@ void PlayerBlind(CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAt
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
if (pObserver && pObserver->IsObservingPlayer(pPlayer))
if (!UTIL_IsValidPlayer(pObserver))
continue;
if (pObserver->IsObservingPlayer(pPlayer))
{
UTIL_ScreenFade(pObserver, color, fadeTime, fadeHold, alpha, 0);
}

View File

@ -1242,7 +1242,7 @@ void CHostage::SendHostagePositionMsg()
if (!pEntity->IsPlayer())
continue;
if (pEntity->pev->flags == FL_DORMANT)
if (pEntity->IsDormant())
continue;
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
@ -1271,7 +1271,7 @@ void CHostage::SendHostageEventMsg()
if (!pEntity->IsPlayer())
continue;
if (pEntity->pev->flags == FL_DORMANT)
if (pEntity->IsDormant())
continue;
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);

View File

@ -358,10 +358,7 @@ bool CHostageImprov::IsFriendInTheWay(const Vector &goalPos) const
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsAlive() || pPlayer->m_iTeam == TERRORIST)
@ -675,10 +672,7 @@ void CHostageImprov::UpdateVision()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))

View File

@ -34,7 +34,10 @@ bool IsBotSpeaking()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || !pPlayer->IsBot())
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsBot())
continue;
CCSBot *pBot = static_cast<CCSBot *>(pPlayer);
@ -704,7 +707,7 @@ CBasePlayer *EXT_FUNC CHalfLifeMultiplay::__API_HOOK(GiveC4)()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || FNullEnt(pPlayer->edict()))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->pev->deadflag != DEAD_NO || pPlayer->m_iTeam != TERRORIST)
@ -1079,10 +1082,8 @@ bool EXT_FUNC CHalfLifeMultiplay::NeededPlayersCheck()
if (IsCareer())
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(gpGlobals->maxClients);
if (!pPlayer || !pPlayer->IsBot())
{
if (!UTIL_IsValidPlayer(pPlayer) || !pPlayer->IsBot())
return true;
}
}
return OnRoundEnd_Intercept(WINSTATUS_DRAW, ROUND_GAME_COMMENCE, IsCareer() ? 0 : 3);
@ -1815,10 +1816,11 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(RestartRound)()
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer && !FNullEnt(pPlayer->pev))
{
pPlayer->Reset();
}
if (!UTIL_IsValidPlayer(pPlayer))
continue;
pPlayer->Reset();
}
if (TheBots)
@ -1986,7 +1988,7 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(RestartRound)()
if (FNullEnt(pEntity->edict()))
break;
if (pEntity->pev->flags == FL_DORMANT)
if (pEntity->IsDormant())
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
@ -2097,12 +2099,17 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(RestartRound)()
BOOL CHalfLifeMultiplay::IsThereABomber()
{
CBasePlayer *pPlayer = nullptr;
while ((pPlayer = UTIL_FindEntityByClassname(pPlayer, "player")))
CBaseEntity *pEntity = nullptr;
while ((pEntity = UTIL_FindEntityByClassname(pEntity, "player")))
{
if (FNullEnt(pPlayer->edict()))
if (FNullEnt(pEntity->edict()))
break;
if (pEntity->IsDormant())
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->m_iTeam != CT && pPlayer->IsBombGuy())
{
// There you are.
@ -2517,7 +2524,10 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(Think)()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer && !pPlayer->IsBot())
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsBot())
{
MESSAGE_BEGIN(MSG_ONE, gmsgCZCareerHUD, nullptr, pPlayer->pev);
WRITE_STRING("ROUND");
@ -2727,9 +2737,9 @@ bool CHalfLifeMultiplay::CheckFragLimit()
// check if any player is over the frag limit
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
auto pPlayer = UTIL_PlayerByIndex(i);
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || pPlayer->has_disconnected)
if (!UTIL_IsValidPlayer(pPlayer) || pPlayer->has_disconnected)
continue;
if (pPlayer->pev->frags >= fraglimit.value)
@ -2822,9 +2832,15 @@ void EXT_FUNC CHalfLifeMultiplay::OnRoundFreezeEnd()
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *plr = UTIL_PlayerByIndex(i);
if (!plr || plr->pev->flags == FL_DORMANT)
if (!UTIL_IsValidPlayer(plr))
continue;
#ifndef REGAMEDLL_FIXES
if (plr->pev->flags == FL_DORMANT)
continue;
#endif
if (plr->m_iJoiningState == JOINED)
{
if (plr->m_iTeam == CT && !bCTPlayed)
@ -3200,7 +3216,7 @@ void CHalfLifeMultiplay::MarkLivingPlayersOnTeamAsNotReceivingMoneyNextRound(int
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->m_iTeam == iTeam)
@ -3238,7 +3254,7 @@ void CHalfLifeMultiplay::CareerRestart()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsBot())
@ -3439,13 +3455,9 @@ void CHalfLifeMultiplay::InitHUD(CBasePlayer *pl)
{
// FIXME: Probably don't need to cast this just to read m_iDeaths
CBasePlayer *plr = UTIL_PlayerByIndex(i);
if (!plr)
if (!UTIL_IsValidPlayer(plr))
continue;
#ifdef REGAMEDLL_FIXES
if (plr->IsDormant())
continue;
#endif
MESSAGE_BEGIN(MSG_ONE, gmsgScoreInfo, nullptr, pl->edict());
WRITE_BYTE(i); // client number
WRITE_SHORT(int(plr->pev->frags));
@ -3484,13 +3496,9 @@ void CHalfLifeMultiplay::InitHUD(CBasePlayer *pl)
for (i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *plr = UTIL_PlayerByIndex(i);
if (!plr)
continue;
#ifdef REGAMEDLL_FIXES
if (plr->IsDormant())
if (!UTIL_IsValidPlayer(plr))
continue;
#endif
MESSAGE_BEGIN(MSG_ONE, gmsgTeamInfo, nullptr, pl->edict());
WRITE_BYTE(plr->entindex());
@ -3502,7 +3510,7 @@ void CHalfLifeMultiplay::InitHUD(CBasePlayer *pl)
if (pl->entindex() != i)
{
#ifndef REGAMEDLL_FIXES
if (plr->pev->flags == FL_DORMANT)
if (plr->IsDormant())
continue;
#endif
if (plr->pev->deadflag == DEAD_NO
@ -3663,6 +3671,9 @@ void CHalfLifeMultiplay::ClientDisconnected(edict_t *pClient)
if (!pObserver->pev || pObserver == pPlayer)
continue;
if (pObserver->IsDormant())
continue;
// If a spectator was chasing this player, move him/her onto the next player
if (pObserver->m_hObserverTarget == pPlayer)
{
@ -4641,10 +4652,11 @@ int CountPlayers()
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer)
{
nCount++;
}
if (!UTIL_IsValidPlayer(pPlayer) || pPlayer->IsBot())
continue;
nCount++;
}
return nCount;
@ -4746,6 +4758,9 @@ void CHalfLifeMultiplay::ResetAllMapVotes()
if (FNullEnt(pEntity->edict()))
break;
if (pEntity->IsDormant())
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->m_iTeam != UNASSIGNED)
{
@ -4849,6 +4864,9 @@ void CHalfLifeMultiplay::ProcessMapVote(CBasePlayer *pPlayer, int iVote)
if (FNullEnt(pEntity->edict()))
break;
if (pEntity->IsDormant())
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->m_iTeam != UNASSIGNED)
@ -5228,7 +5246,7 @@ CBasePlayer *CHalfLifeMultiplay::CheckAssistsToKill(CBaseEntity *pKiller, CBaseP
continue; // dealt no damage
CBasePlayer *pAttackerPlayer = UTIL_PlayerByIndex(i);
if (!pAttackerPlayer || pAttackerPlayer->IsDormant())
if (!UTIL_IsValidPlayer(pAttackerPlayer))
continue; // ignore idle clients
CCSPlayer *pCSAttackerPlayer = pAttackerPlayer->CSPlayer();
@ -5412,7 +5430,7 @@ void CHalfLifeMultiplay::GiveDefuserToRandomPlayer()
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || FNullEnt(pPlayer->edict()))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsAlive() || pPlayer->m_iTeam != CT)

View File

@ -332,7 +332,10 @@ CBasePlayer *CBasePlayer::GetNextRadioRecipient(CBasePlayer *pStartPlayer)
continue;
CBasePlayer *pTarget = CBasePlayer::Instance(pPlayer->m_hObserverTarget->pev);
if (pTarget && pTarget->m_iTeam == m_iTeam)
if (!pTarget || pTarget->IsDormant())
continue;
if (pTarget->m_iTeam == m_iTeam)
{
bSend = true;
}
@ -365,6 +368,9 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Radio)(const char *msg_id, const char *msg
if (FNullEnt(pEntity->edict()))
break;
if (pEntity->IsDormant())
continue;
bool bSend = false;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
@ -396,7 +402,11 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Radio)(const char *msg_id, const char *msg
if (FNullEnt(pPlayer->m_hObserverTarget))
continue;
if (pPlayer->m_hObserverTarget && g_pGameRules->PlayerRelationship(this, pPlayer->m_hObserverTarget) == GR_TEAMMATE)
CBasePlayer *pTarget = CBasePlayer::Instance(pPlayer->m_hObserverTarget->pev);
if (!pTarget || pTarget->IsDormant())
continue;
if (g_pGameRules->PlayerRelationship(this, pTarget) == GR_TEAMMATE)
{
bSend = true;
}
@ -1029,7 +1039,10 @@ BOOL EXT_FUNC CBasePlayer::__API_HOOK(TakeDamage)(entvars_t *pevInflictor, entva
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || pPlayer->m_hObserverTarget != this)
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->m_hObserverTarget != this)
continue;
MESSAGE_BEGIN(MSG_ONE, gmsgSpecHealth, nullptr, pPlayer->edict());
@ -1092,6 +1105,9 @@ BOOL EXT_FUNC CBasePlayer::__API_HOOK(TakeDamage)(entvars_t *pevInflictor, entva
if (FNullEnt(pEntity->edict()))
break;
if (pEntity->IsDormant())
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->m_iTeam == m_iTeam)
@ -1278,7 +1294,7 @@ BOOL EXT_FUNC CBasePlayer::__API_HOOK(TakeDamage)(entvars_t *pevInflictor, entva
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->m_hObserverTarget == this)
@ -1876,6 +1892,9 @@ void CBasePlayer::SetProgressBarTime(int time)
if (FNullEnt(pEntity->edict()))
break;
if (pEntity->IsDormant())
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->GetObserverMode() == OBS_IN_EYE && pPlayer->pev->iuser2 == playerIndex)
@ -1916,6 +1935,9 @@ void CBasePlayer::SetProgressBarTime2(int time, float timeElapsed)
if (FNullEnt(pEntity->edict()))
break;
if (pEntity->IsDormant())
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->GetObserverMode() == OBS_IN_EYE && pPlayer->pev->iuser2 == playerIndex)
@ -2188,7 +2210,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
if (!UTIL_IsValidPlayer(pPlayer))
continue;
bool killedByHumanPlayer = (!pPlayer->IsBot() && pPlayer->pev == pevAttacker && pPlayer->m_iTeam != m_iTeam);
@ -2219,7 +2241,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Killed)(entvars_t *pevAttacker, int iGib)
{
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
if (!pObserver)
if (!UTIL_IsValidPlayer(pObserver))
continue;
if (pObserver->IsObservingPlayer(this))
@ -4443,7 +4465,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(AddPointsToTeam)(int score, BOOL bAllowNeg
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer && i != index)
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (i != index)
{
if (g_pGameRules->PlayerRelationship(this, pPlayer) == GR_TEAMMATE)
{
@ -5830,7 +5855,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Spawn)()
{
CBasePlayer *pObserver = UTIL_PlayerByIndex(i);
if (pObserver && pObserver->IsObservingPlayer(this))
if (!UTIL_IsValidPlayer(pObserver))
continue;
if (pObserver->IsObservingPlayer(this))
{
MESSAGE_BEGIN(MSG_ONE, gmsgNVGToggle, nullptr, pObserver->pev);
WRITE_BYTE(0);
@ -5959,8 +5987,10 @@ void CBasePlayer::SetScoreboardAttributes(CBasePlayer *destination)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer && !FNullEnt(pPlayer->edict()))
SetScoreboardAttributes(pPlayer);
if (!UTIL_IsValidPlayer(pPlayer))
continue;
SetScoreboardAttributes(pPlayer);
}
}
@ -6509,10 +6539,8 @@ void CBasePlayer::ForceClientDllUpdate()
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || FNullEnt(pPlayer->edict()))
continue;
if (pPlayer->IsDormant())
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pev->deadflag == DEAD_NO)
@ -7663,14 +7691,14 @@ void EXT_FUNC CBasePlayer::__API_HOOK(UpdateClientData)()
{
CBaseEntity *pEntity = UTIL_PlayerByIndex(i);
if (!pEntity || i == entindex())
if (!UTIL_IsValidPlayer(pEntity))
continue;
if (i == entindex())
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pPlayer->pev->flags == FL_DORMANT)
continue;
if (pPlayer->pev->deadflag != DEAD_NO)
continue;
@ -7704,16 +7732,11 @@ void EXT_FUNC CBasePlayer::__API_HOOK(UpdateClientData)()
{
CBaseEntity *pEntity = UTIL_PlayerByIndex(playerIndex);
if (!pEntity)
if (!UTIL_IsValidPlayer(pEntity))
continue;
CBasePlayer *pPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
#ifdef REGAMEDLL_FIXES
if (pPlayer->IsDormant())
continue;
#endif // REGAMEDLL_FIXES
#ifdef REGAMEDLL_FIXES
if (scoreboard_showhealth.value != -1.0f)
#endif
@ -8237,24 +8260,21 @@ CBaseEntity *EXT_FUNC CBasePlayer::__API_HOOK(DropPlayerItem)(const char *pszIte
if (FNullEnt(pEntity->edict()))
break;
if (!pEntity->IsPlayer())
if (!pEntity->IsPlayer() || pEntity->IsDormant())
continue;
if (pEntity->pev->flags != FL_DORMANT)
CBasePlayer *pOther = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
if (pOther->pev->deadflag == DEAD_NO && pOther->m_iTeam == TERRORIST)
{
CBasePlayer *pOther = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);
ClientPrint(pOther->pev, HUD_PRINTCENTER, "#Game_bomb_drop", STRING(pev->netname));
if (pOther->pev->deadflag == DEAD_NO && pOther->m_iTeam == TERRORIST)
{
ClientPrint(pOther->pev, HUD_PRINTCENTER, "#Game_bomb_drop", STRING(pev->netname));
MESSAGE_BEGIN(MSG_ONE, gmsgBombDrop, nullptr, pOther->pev);
WRITE_COORD(pev->origin.x);
WRITE_COORD(pev->origin.y);
WRITE_COORD(pev->origin.z);
WRITE_BYTE(BOMB_FLAG_DROPPED);
MESSAGE_END();
}
MESSAGE_BEGIN(MSG_ONE, gmsgBombDrop, nullptr, pOther->pev);
WRITE_COORD(pev->origin.x);
WRITE_COORD(pev->origin.y);
WRITE_COORD(pev->origin.z);
WRITE_BYTE(BOMB_FLAG_DROPPED);
MESSAGE_END();
}
}
}
@ -10137,7 +10157,7 @@ void CBasePlayer::UpdateLocation(bool forceUpdate)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->m_iTeam == m_iTeam || pPlayer->m_iTeam == SPECTATOR)

View File

@ -986,6 +986,19 @@ inline CBasePlayer *UTIL_PlayerByIndex(int playerIndex)
return GET_PRIVATE<CBasePlayer>(INDEXENT(playerIndex));
}
// return true if the given player is valid
inline bool UTIL_IsValidPlayer(CBaseEntity *pPlayer)
{
return pPlayer && !FNullEnt(pPlayer->pev) && !pPlayer->IsDormant();
}
#else
inline bool UTIL_IsValidPlayer(CBaseEntity *pPlayer)
{
return pPlayer && !FNullEnt(pPlayer->pev);
}
#endif
inline CBasePlayer *UTIL_PlayerByIndexSafe(int playerIndex)

View File

@ -2029,7 +2029,7 @@ void CEscapeZone::EscapeTouch(CBaseEntity *pOther)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->m_iTeam == pEscapee->m_iTeam)

View File

@ -75,7 +75,10 @@ void MonitorTutorStatus()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer && !pPlayer->IsBot())
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsBot())
numHumans++;
}

View File

@ -2040,7 +2040,11 @@ void CCSTutor::GetNumPlayersAliveOnTeams(int &numT, int &numCT)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || !pPlayer->IsAlive())
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsAlive())
continue;
switch (pPlayer->m_iTeam)
@ -2132,7 +2136,11 @@ void CCSTutor::CheckForBombViewable()
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer && pPlayer->m_bHasC4)
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->m_bHasC4)
{
pBombCarrier = pPlayer;
break;
@ -2819,7 +2827,7 @@ void CCSTutor::ConstructRecentDeathsList(TeamName team, char *buf, int buflen, T
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
if (!UTIL_IsValidPlayer(pPlayer))
continue;
// ignore alive players

View File

@ -506,7 +506,11 @@ void UTIL_ScreenShake(const Vector &center, float amplitude, float frequency, fl
for (i = 1; i <= gpGlobals->maxClients; i++)
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || !(pPlayer->pev->flags & FL_ONGROUND))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!(pPlayer->pev->flags & FL_ONGROUND))
continue;
localAmplitude = 0;
@ -552,7 +556,10 @@ void UTIL_ScreenFadeBuild(ScreenFade &fade, const Vector &color, float fadeTime,
void UTIL_ScreenFadeWrite(const ScreenFade &fade, CBaseEntity *pEntity)
{
if (!pEntity || !pEntity->IsNetClient())
if (!UTIL_IsValidPlayer(pEntity))
return;
if (!pEntity->IsNetClient())
return;
MESSAGE_BEGIN(MSG_ONE, gmsgFade, nullptr, pEntity->edict());
@ -634,10 +641,11 @@ void UTIL_HudMessageAll(const hudtextparms_t &textparms, const char *pMessage)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer)
{
UTIL_HudMessage(pPlayer, textparms, pMessage);
}
if (!UTIL_IsValidPlayer(pPlayer))
continue;
UTIL_HudMessage(pPlayer, textparms, pMessage);
}
}
@ -843,8 +851,11 @@ void UTIL_ShowMessageAll(const char *pString, bool isHint)
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer)
UTIL_ShowMessage(pString, pPlayer, isHint);
if (!UTIL_IsValidPlayer(pPlayer))
continue;
UTIL_ShowMessage(pString, pPlayer, isHint);
}
}
@ -1749,10 +1760,11 @@ int UTIL_GetNumPlayers()
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (pPlayer)
{
nNumPlayers++;
}
if (!UTIL_IsValidPlayer(pPlayer))
continue;
nNumPlayers++;
}
return nNumPlayers;
@ -1837,7 +1849,10 @@ int UTIL_CountPlayersInBrushVolume(bool bOnlyAlive, CBaseEntity *pBrushEntity, i
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer || !pPlayer->IsInWorld())
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (!pPlayer->IsInWorld())
continue;
if (bOnlyAlive && !pPlayer->IsAlive())

View File

@ -1460,9 +1460,12 @@ void CBasePlayerWeapon::ReloadSound()
CBasePlayer *pPlayer = nullptr;
while ((pPlayer = UTIL_FindEntityByClassname(pPlayer, "player")))
{
if (pPlayer->IsDormant())
if (FNullEnt(pPlayer->edict()))
break;
if (pPlayer->IsDormant())
continue;
if (pPlayer == m_pPlayer)
continue;
@ -2043,7 +2046,7 @@ void CWeaponBox::Touch(CBaseEntity *pOther)
if (!pEntity->IsPlayer())
continue;
if (pEntity->pev->flags == FL_DORMANT)
if (pEntity->IsDormant())
continue;
CBasePlayer *pTempPlayer = GetClassPtr<CCSPlayer>((CBasePlayer *)pEntity->pev);

View File

@ -352,10 +352,8 @@ int CBot::GetEnemiesRemaining() const
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -380,10 +378,8 @@ int CBot::GetFriendsRemaining() const
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))

View File

@ -196,7 +196,7 @@ void CBotManager::StartFrame()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->IsBot() && IsEntityValid(pPlayer))
@ -229,10 +229,7 @@ void CBotManager::__API_HOOK(OnEvent)(GameEventType event, CBaseEntity* pEntity,
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))

View File

@ -11,10 +11,7 @@ bool UTIL_IsNameTaken(const char *name, bool ignoreHumans)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -46,14 +43,12 @@ bool UTIL_IsNameTaken(const char *name, bool ignoreHumans)
int UTIL_ClientsInGame()
{
int iCount = 0;
for (int iIndex = 1; iIndex <= gpGlobals->maxClients; iIndex++)
{
CBaseEntity *pPlayer = UTIL_PlayerByIndex(iIndex);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -68,14 +63,12 @@ int UTIL_ClientsInGame()
int UTIL_ActivePlayersInGame()
{
int iCount = 0;
for (int iIndex = 1; iIndex <= gpGlobals->maxClients; iIndex++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(iIndex);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -102,10 +95,7 @@ int UTIL_HumansInGame(bool ignoreSpectators)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(iIndex);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -138,12 +128,9 @@ int UTIL_SpectatorsInGame()
for (int iIndex = 1; iIndex <= gpGlobals->maxClients; iIndex++)
{
CBasePlayer* pPlayer = UTIL_PlayerByIndex(iIndex);
CBasePlayer *pPlayer = UTIL_PlayerByIndex(iIndex);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -167,14 +154,12 @@ int UTIL_SpectatorsInGame()
int UTIL_HumansOnTeam(int teamID, bool isAlive)
{
int iCount = 0;
for (int iIndex = 1; iIndex <= gpGlobals->maxClients; iIndex++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(iIndex);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -203,10 +188,7 @@ int UTIL_BotsInGame()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(iIndex);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -230,10 +212,7 @@ bool UTIL_KickBotFromTeam(TeamName kickTeam)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
const char *name = STRING(pPlayer->pev->netname);
@ -256,10 +235,7 @@ bool UTIL_KickBotFromTeam(TeamName kickTeam)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
const char *name = STRING(pPlayer->pev->netname);
@ -283,19 +259,17 @@ bool UTIL_KickBotFromTeam(TeamName kickTeam)
bool UTIL_IsTeamAllBots(int team)
{
int botCount = 0;
for (int i = 1; i <= gpGlobals->maxClients; i++)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (pPlayer->m_iTeam != team)
continue;
if (FNullEnt(pPlayer->pev))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
continue;
@ -403,10 +377,7 @@ bool UTIL_IsVisibleToTeam(const Vector &spot, int team, float maxRange)
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(i);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))
@ -443,10 +414,7 @@ CBasePlayer *UTIL_GetLocalPlayer()
{
CBasePlayer *pPlayer = UTIL_PlayerByIndex(iIndex);
if (!pPlayer)
continue;
if (FNullEnt(pPlayer->pev))
if (!UTIL_IsValidPlayer(pPlayer))
continue;
if (FStrEq(STRING(pPlayer->pev->netname), ""))