From 7372573c89e0bbc5068c90cb8ac5b7357adf595a Mon Sep 17 00:00:00 2001 From: s1lentq Date: Tue, 28 May 2024 22:44:29 +0700 Subject: [PATCH] Add UTIL_IsValidPlayer Ignore dormant players Minor refactoring --- regamedll/dlls/bot/cs_bot.cpp | 10 +-- regamedll/dlls/bot/cs_bot_chatter.cpp | 10 +-- regamedll/dlls/bot/cs_bot_manager.cpp | 18 +++-- regamedll/dlls/bot/cs_bot_pathfind.cpp | 5 +- regamedll/dlls/bot/cs_bot_vision.cpp | 7 +- regamedll/dlls/career_tasks.cpp | 6 +- regamedll/dlls/client.cpp | 33 +++++++- regamedll/dlls/cmdhandler.cpp | 7 +- regamedll/dlls/combat.cpp | 6 +- regamedll/dlls/hostage/hostage.cpp | 4 +- regamedll/dlls/hostage/hostage_improv.cpp | 10 +-- regamedll/dlls/multiplay_gamerules.cpp | 90 ++++++++++++--------- regamedll/dlls/player.cpp | 98 ++++++++++++++--------- regamedll/dlls/player.h | 13 +++ regamedll/dlls/triggers.cpp | 2 +- regamedll/dlls/tutor.cpp | 5 +- regamedll/dlls/tutor_cs_tutor.cpp | 14 +++- regamedll/dlls/util.cpp | 41 +++++++--- regamedll/dlls/weapons.cpp | 7 +- regamedll/game_shared/bot/bot.cpp | 8 +- regamedll/game_shared/bot/bot_manager.cpp | 7 +- regamedll/game_shared/bot/bot_util.cpp | 66 ++++----------- 22 files changed, 263 insertions(+), 204 deletions(-) diff --git a/regamedll/dlls/bot/cs_bot.cpp b/regamedll/dlls/bot/cs_bot.cpp index 838387a95..dd85448c6 100644 --- a/regamedll/dlls/bot/cs_bot.cpp +++ b/regamedll/dlls/bot/cs_bot.cpp @@ -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), "")) diff --git a/regamedll/dlls/bot/cs_bot_chatter.cpp b/regamedll/dlls/bot/cs_bot_chatter.cpp index 2c6b3336e..1476d8d58 100644 --- a/regamedll/dlls/bot/cs_bot_chatter.cpp +++ b/regamedll/dlls/bot/cs_bot_chatter.cpp @@ -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), "")) diff --git a/regamedll/dlls/bot/cs_bot_manager.cpp b/regamedll/dlls/bot/cs_bot_manager.cpp index 78ce0cf5d..fc1d50c88 100644 --- a/regamedll/dlls/bot/cs_bot_manager.cpp +++ b/regamedll/dlls/bot/cs_bot_manager.cpp @@ -337,6 +337,10 @@ void CCSBotManager::ClientDisconnect(CBasePlayer *pPlayer) pPlayer = GetClassPtr((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()) diff --git a/regamedll/dlls/bot/cs_bot_pathfind.cpp b/regamedll/dlls/bot/cs_bot_pathfind.cpp index 00386be7b..f418b56cb 100644 --- a/regamedll/dlls/bot/cs_bot_pathfind.cpp +++ b/regamedll/dlls/bot/cs_bot_pathfind.cpp @@ -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()) diff --git a/regamedll/dlls/bot/cs_bot_vision.cpp b/regamedll/dlls/bot/cs_bot_vision.cpp index 8fc811ed2..db9e2143c 100644 --- a/regamedll/dlls/bot/cs_bot_vision.cpp +++ b/regamedll/dlls/bot/cs_bot_vision.cpp @@ -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? diff --git a/regamedll/dlls/career_tasks.cpp b/regamedll/dlls/career_tasks.cpp index 200c67558..972ccca9b 100644 --- a/regamedll/dlls/career_tasks.cpp +++ b/regamedll/dlls/career_tasks.cpp @@ -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++; } diff --git a/regamedll/dlls/client.cpp b/regamedll/dlls/client.cpp index 1ac3dd562..7d3fb659e 100644 --- a/regamedll/dlls/client.cpp +++ b/regamedll/dlls/client.cpp @@ -438,6 +438,9 @@ NOXREF int CountTeams() if (FNullEnt(pEntity->edict())) break; + if (pEntity->IsDormant()) + continue; + CBasePlayer *pPlayer = GetClassPtr((CBasePlayer *)pEntity->pev); if (pPlayer->m_iTeam == UNASSIGNED) @@ -499,7 +502,8 @@ int CountTeamPlayers(int iTeam) if (pEntity->IsDormant()) continue; - if (GetClassPtr((CBasePlayer *)pEntity->pev)->m_iTeam == iTeam) + CBasePlayer *pPlayer = GetClassPtr((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((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((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((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((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); diff --git a/regamedll/dlls/cmdhandler.cpp b/regamedll/dlls/cmdhandler.cpp index d715de641..73bfe7cfd 100644 --- a/regamedll/dlls/cmdhandler.cpp +++ b/regamedll/dlls/cmdhandler.cpp @@ -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) diff --git a/regamedll/dlls/combat.cpp b/regamedll/dlls/combat.cpp index 4cbc485dc..17fe84e27 100644 --- a/regamedll/dlls/combat.cpp +++ b/regamedll/dlls/combat.cpp @@ -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); } diff --git a/regamedll/dlls/hostage/hostage.cpp b/regamedll/dlls/hostage/hostage.cpp index c9ff79725..7ef34b222 100644 --- a/regamedll/dlls/hostage/hostage.cpp +++ b/regamedll/dlls/hostage/hostage.cpp @@ -1242,7 +1242,7 @@ void CHostage::SendHostagePositionMsg() if (!pEntity->IsPlayer()) continue; - if (pEntity->pev->flags == FL_DORMANT) + if (pEntity->IsDormant()) continue; CBasePlayer *pTempPlayer = GetClassPtr((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((CBasePlayer *)pEntity->pev); diff --git a/regamedll/dlls/hostage/hostage_improv.cpp b/regamedll/dlls/hostage/hostage_improv.cpp index a70d2c76a..9cdba7777 100644 --- a/regamedll/dlls/hostage/hostage_improv.cpp +++ b/regamedll/dlls/hostage/hostage_improv.cpp @@ -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), "")) diff --git a/regamedll/dlls/multiplay_gamerules.cpp b/regamedll/dlls/multiplay_gamerules.cpp index f9aaa8c30..7651527be 100644 --- a/regamedll/dlls/multiplay_gamerules.cpp +++ b/regamedll/dlls/multiplay_gamerules.cpp @@ -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(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((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((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,8 +2832,14 @@ 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) { @@ -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((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((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) diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 875f085bb..52eaeaea6 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -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((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((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((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((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; - CBasePlayer *pPlayer = GetClassPtr((CBasePlayer *)pEntity->pev); - - if (pPlayer->pev->flags == FL_DORMANT) + if (i == entindex()) continue; + CBasePlayer *pPlayer = GetClassPtr((CBasePlayer *)pEntity->pev); + 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((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((CBasePlayer *)pEntity->pev); + CBasePlayer *pOther = GetClassPtr((CBasePlayer *)pEntity->pev); - 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(); - } + 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(); } } } @@ -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) diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index ced1fe973..82e81aa6b 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -986,6 +986,19 @@ inline CBasePlayer *UTIL_PlayerByIndex(int playerIndex) return GET_PRIVATE(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) diff --git a/regamedll/dlls/triggers.cpp b/regamedll/dlls/triggers.cpp index 01e29bad8..82bf6907a 100644 --- a/regamedll/dlls/triggers.cpp +++ b/regamedll/dlls/triggers.cpp @@ -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) diff --git a/regamedll/dlls/tutor.cpp b/regamedll/dlls/tutor.cpp index 5f2dbeca0..0f83d4812 100644 --- a/regamedll/dlls/tutor.cpp +++ b/regamedll/dlls/tutor.cpp @@ -75,7 +75,10 @@ void MonitorTutorStatus() { CBasePlayer *pPlayer = UTIL_PlayerByIndex(i); - if (pPlayer && !pPlayer->IsBot()) + if (!UTIL_IsValidPlayer(pPlayer)) + continue; + + if (!pPlayer->IsBot()) numHumans++; } diff --git a/regamedll/dlls/tutor_cs_tutor.cpp b/regamedll/dlls/tutor_cs_tutor.cpp index f8ca0aef7..18e5d2b67 100644 --- a/regamedll/dlls/tutor_cs_tutor.cpp +++ b/regamedll/dlls/tutor_cs_tutor.cpp @@ -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 diff --git a/regamedll/dlls/util.cpp b/regamedll/dlls/util.cpp index 7c3c3db6c..7841b006b 100644 --- a/regamedll/dlls/util.cpp +++ b/regamedll/dlls/util.cpp @@ -506,7 +506,11 @@ void UTIL_ScreenShake(const Vector ¢er, 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()) diff --git a/regamedll/dlls/weapons.cpp b/regamedll/dlls/weapons.cpp index 4ea949128..a472e0030 100644 --- a/regamedll/dlls/weapons.cpp +++ b/regamedll/dlls/weapons.cpp @@ -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((CBasePlayer *)pEntity->pev); diff --git a/regamedll/game_shared/bot/bot.cpp b/regamedll/game_shared/bot/bot.cpp index 33f0d8083..f53266bdb 100644 --- a/regamedll/game_shared/bot/bot.cpp +++ b/regamedll/game_shared/bot/bot.cpp @@ -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), "")) diff --git a/regamedll/game_shared/bot/bot_manager.cpp b/regamedll/game_shared/bot/bot_manager.cpp index 7e10f1bcc..7ccd32814 100644 --- a/regamedll/game_shared/bot/bot_manager.cpp +++ b/regamedll/game_shared/bot/bot_manager.cpp @@ -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), "")) diff --git a/regamedll/game_shared/bot/bot_util.cpp b/regamedll/game_shared/bot/bot_util.cpp index 9b5e2013e..449b7e373 100644 --- a/regamedll/game_shared/bot/bot_util.cpp +++ b/regamedll/game_shared/bot/bot_util.cpp @@ -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); - - if (!pPlayer) - continue; + CBasePlayer *pPlayer = UTIL_PlayerByIndex(iIndex); - 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), ""))