From 40f3bc488be6fb7893df1490f06c595af8785259 Mon Sep 17 00:00:00 2001 From: In-line Date: Thu, 8 Feb 2018 13:37:02 +0400 Subject: [PATCH] Fix spectator check, small refactoring (#265) * Fix spectator check, small refactoring * Update observer.cpp minor refactor-patch --- regamedll/dlls/client.cpp | 8 +++--- regamedll/dlls/multiplay_gamerules.cpp | 36 +++++++++++++------------- regamedll/dlls/observer.cpp | 16 ++++++------ regamedll/dlls/player.cpp | 28 ++++++++++---------- regamedll/dlls/player.h | 2 +- 5 files changed, 45 insertions(+), 45 deletions(-) diff --git a/regamedll/dlls/client.cpp b/regamedll/dlls/client.cpp index 5278b327..7185f3a4 100644 --- a/regamedll/dlls/client.cpp +++ b/regamedll/dlls/client.cpp @@ -362,7 +362,7 @@ void EXT_FUNC ClientKill(edict_t *pEntity) entvars_t *pev = &pEntity->v; CBasePlayer *pPlayer = CBasePlayer::Instance(pev); - if (pPlayer->IsObserver()) + if (pPlayer->GetObserverMode() != OBS_NONE) return; if (pPlayer->m_iJoiningState != JOINED) @@ -3093,7 +3093,7 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa { // new spectator mode int mode = Q_atoi(parg1); - if (pPlayer->IsObserver() && pPlayer->CanSwitchObserverModes()) + if (pPlayer->GetObserverMode() != OBS_NONE && pPlayer->CanSwitchObserverModes()) pPlayer->Observer_SetMode(mode); else pPlayer->m_iObserverLastMode = mode; @@ -3113,14 +3113,14 @@ void EXT_FUNC InternalCommand(edict_t *pEntity, const char *pcmd, const char *pa { // follow next player int arg = Q_atoi(parg1); - if (pPlayer->IsObserver() && pPlayer->CanSwitchObserverModes()) + if (pPlayer->GetObserverMode() != OBS_NONE && pPlayer->CanSwitchObserverModes()) { pPlayer->Observer_FindNextPlayer(arg != 0); } } else if (FStrEq(pcmd, "follow")) { - if (pPlayer->IsObserver() && pPlayer->CanSwitchObserverModes()) + if (pPlayer->GetObserverMode() != OBS_NONE && pPlayer->CanSwitchObserverModes()) { pPlayer->Observer_FindNextPlayer(false, parg1); } diff --git a/regamedll/dlls/multiplay_gamerules.cpp b/regamedll/dlls/multiplay_gamerules.cpp index 865facf3..9e93e121 100644 --- a/regamedll/dlls/multiplay_gamerules.cpp +++ b/regamedll/dlls/multiplay_gamerules.cpp @@ -97,32 +97,32 @@ bool CCStrikeGameMgrHelper::__API_HOOK(CanPlayerHearPlayer)(CBasePlayer *pListen case 2: return (pListener->m_iTeam == pSender->m_iTeam); case 3: - return (pListener->m_iTeam == pSender->m_iTeam || pListener->IsObserver()); + return (pListener->m_iTeam == pSender->m_iTeam || pListener->m_iTeam == SPECTATOR || pListener->m_iTeam == UNASSIGNED); case 4: return (pListener->IsAlive() == pSender->IsAlive() || pSender->IsAlive()); - default: // Default behavior - break; #endif - } - - if ( + default: + { + if ( #ifndef REGAMEDLL_FIXES !pSender->IsPlayer() || #endif - pListener->m_iTeam != pSender->m_iTeam) // Different teams can't hear each other - { - return false; + pListener->m_iTeam != pSender->m_iTeam) // Different teams can't hear each other + { + return false; + } + + if (pListener->GetObserverMode() != OBS_NONE) // 2 spectators don't need isAlive() checks. + { + return true; + } + + BOOL bListenerAlive = pListener->IsAlive(); + BOOL bSenderAlive = pSender->IsAlive(); + + return (bListenerAlive == bSenderAlive || bSenderAlive); // Dead/alive voice chats are separated, but dead can hear alive. } - - if (pListener->IsObserver()) // 2 spectators don't need isAlive() checks. - { - return true; } - - BOOL bListenerAlive = pListener->IsAlive(); - BOOL bSenderAlive = pSender->IsAlive(); - - return (bListenerAlive == bSenderAlive || bSenderAlive); // Dead/alive voice chats are separated, but dead can hear alive. } void Broadcast(const char *sentence) diff --git a/regamedll/dlls/observer.cpp b/regamedll/dlls/observer.cpp index ed1b3328..d92c85b4 100644 --- a/regamedll/dlls/observer.cpp +++ b/regamedll/dlls/observer.cpp @@ -29,7 +29,7 @@ CBasePlayer *CBasePlayer::__API_HOOK(Observer_IsValidTarget)(int iPlayerIndex, b CBasePlayer *pPlayer = UTIL_PlayerByIndex(iPlayerIndex); // Don't spec observers or players who haven't picked a class yet - if (!pPlayer || pPlayer == this || pPlayer->has_disconnected || pPlayer->IsObserver() || (pPlayer->pev->effects & EF_NODRAW) || pPlayer->m_iTeam == UNASSIGNED || (bSameTeam && pPlayer->m_iTeam != m_iTeam)) + if (!pPlayer || pPlayer == this || pPlayer->has_disconnected || pPlayer->GetObserverMode() != OBS_NONE || (pPlayer->pev->effects & EF_NODRAW) || pPlayer->m_iTeam == UNASSIGNED || (bSameTeam && pPlayer->m_iTeam != m_iTeam)) return nullptr; return pPlayer; @@ -42,7 +42,7 @@ void UpdateClientEffects(CBasePlayer *pObserver, int oldMode) bool blindnessOk = (fadetoblack.value == 0); bool clearNightvision = false; - if (pObserver->IsObserver() == OBS_IN_EYE) + if (pObserver->GetObserverMode() == OBS_IN_EYE) { clearProgress = true; clearBlindness = true; @@ -424,14 +424,14 @@ void CBasePlayer::Observer_CheckProperties() // Attempt to change the observer mode void CBasePlayer::Observer_SetMode(int iMode) { - int _forcecamera; + int forcecamera; int oldMode; // Just abort if we're changing to the mode we're already in if (iMode == pev->iuser1) return; - _forcecamera = GetForceCamera(this); + forcecamera = GetForceCamera(this); // is valid mode ? if (iMode < OBS_CHASE_LOCKED || iMode > OBS_MAP_CHASE) @@ -441,21 +441,21 @@ void CBasePlayer::Observer_SetMode(int iMode) if (m_iTeam != SPECTATOR) { - if (_forcecamera == CAMERA_MODE_SPEC_ONLY_TEAM) + if (forcecamera == CAMERA_MODE_SPEC_ONLY_TEAM) { if (iMode == OBS_ROAMING) iMode = OBS_MAP_FREE; } - else if (_forcecamera == CAMERA_MODE_SPEC_ONLY_FRIST_PERSON) + else if (forcecamera == CAMERA_MODE_SPEC_ONLY_FRIST_PERSON) iMode = OBS_IN_EYE; } // verify observer target again if (m_hObserverTarget) { - CBaseEntity *pEnt = m_hObserverTarget; + CBasePlayer *pTarget = m_hObserverTarget; - if (pEnt == this || !pEnt || pEnt->has_disconnected || ((CBasePlayer *)pEnt)->IsObserver() || (pEnt->pev->effects & EF_NODRAW) || (_forcecamera != CAMERA_MODE_SPEC_ANYONE && ((CBasePlayer *)pEnt)->m_iTeam != m_iTeam)) + if (pTarget == this || !pTarget || pTarget->has_disconnected || pTarget->GetObserverMode() != OBS_NONE || (pTarget->pev->effects & EF_NODRAW) || (forcecamera != CAMERA_MODE_SPEC_ANYONE && pTarget->m_iTeam != m_iTeam)) m_hObserverTarget = nullptr; } diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index 6b23bb4e..ab3cad3a 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -317,7 +317,7 @@ CBasePlayer *CBasePlayer::GetNextRadioRecipient(CBasePlayer *pStartPlayer) } else if (pPlayer) { - int iSpecMode = IsObserver(); + int iSpecMode = GetObserverMode(); if (iSpecMode != OBS_CHASE_LOCKED && iSpecMode != OBS_CHASE_FREE && iSpecMode != OBS_IN_EYE) continue; @@ -378,7 +378,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(Radio)(const char *msg_id, const char *msg else { // do this when spectator mode is in - int iSpecMode = pPlayer->IsObserver(); + int iSpecMode = pPlayer->GetObserverMode(); if (iSpecMode != OBS_CHASE_LOCKED && iSpecMode != OBS_CHASE_FREE && iSpecMode != OBS_IN_EYE) continue; @@ -1587,7 +1587,7 @@ void CBasePlayer::SetProgressBarTime(int time) CBasePlayer *pPlayer = GetClassPtr((CBasePlayer *)pEntity->pev); - if (pPlayer->IsObserver() == OBS_IN_EYE && pPlayer->pev->iuser2 == playerIndex) + if (pPlayer->GetObserverMode() == OBS_IN_EYE && pPlayer->pev->iuser2 == playerIndex) { MESSAGE_BEGIN(MSG_ONE, gmsgBarTime, nullptr, pPlayer->pev); WRITE_SHORT(time); @@ -1627,7 +1627,7 @@ void CBasePlayer::SetProgressBarTime2(int time, float timeElapsed) CBasePlayer *pPlayer = GetClassPtr((CBasePlayer *)pEntity->pev); - if (pPlayer->IsObserver() == OBS_IN_EYE && pPlayer->pev->iuser2 == playerIndex) + if (pPlayer->GetObserverMode() == OBS_IN_EYE && pPlayer->pev->iuser2 == playerIndex) { MESSAGE_BEGIN(MSG_ONE, gmsgBarTime2, nullptr, pPlayer->pev); WRITE_SHORT(time); @@ -3176,7 +3176,7 @@ void CBasePlayer::SyncRoundTimer() if (!g_pGameRules->IsMultiplayer()) return; - if (bFreezePeriod && TheTutor && !IsObserver()) + if (bFreezePeriod && TheTutor && GetObserverMode() == OBS_NONE) { MESSAGE_BEGIN(MSG_ONE, gmsgBlinkAcct, nullptr, pev); WRITE_BYTE(MONEY_BLINK_AMOUNT); @@ -3534,7 +3534,7 @@ void CBasePlayer::PlayerDeathThink() if (pev->deadflag == DEAD_RESPAWNABLE) { #ifdef REGAMEDLL_FIXES - if (IsObserver() && (m_iTeam == UNASSIGNED || m_iTeam == SPECTATOR)) + if (GetObserverMode() != OBS_NONE && (m_iTeam == UNASSIGNED || m_iTeam == SPECTATOR)) return; // Player cannot respawn while in the Choose Appearance menu @@ -4230,7 +4230,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)() #endif // Observer Button Handling - if (IsObserver() && (m_afPhysicsFlags & PFLAG_OBSERVER)) + if (GetObserverMode() != OBS_NONE && (m_afPhysicsFlags & PFLAG_OBSERVER)) { Observer_Think(); return; @@ -7011,7 +7011,7 @@ void EXT_FUNC CBasePlayer::__API_HOOK(ResetMaxSpeed)() { float speed; - if (IsObserver()) + if (GetObserverMode() != OBS_NONE) { // Player gets speed bonus in observer mode speed = 900; @@ -7197,9 +7197,9 @@ void CBasePlayer::UpdateStatusBar() newSBarState[SBAR_ID_TARGETNAME] = ENTINDEX(pTarget->edict()); newSBarState[SBAR_ID_TARGETTYPE] = (pTarget->m_iTeam == m_iTeam) ? SBAR_TARGETTYPE_TEAMMATE : SBAR_TARGETTYPE_ENEMY; - if (pTarget->m_iTeam == m_iTeam || IsObserver()) + if (pTarget->m_iTeam == m_iTeam || GetObserverMode() != OBS_NONE) { - if (playerid.value != PLAYERID_MODE_OFF || IsObserver()) + if (playerid.value != PLAYERID_MODE_OFF || GetObserverMode() != OBS_NONE) Q_strcpy(sbuf0, "1 %c1: %p2\n2 %h: %i3%%"); else Q_strcpy(sbuf0, " "); @@ -7212,7 +7212,7 @@ void CBasePlayer::UpdateStatusBar() HintMessage("#Hint_spotted_a_friend"); } } - else if (!IsObserver()) + else if (GetObserverMode() == OBS_NONE) { if (playerid.value != PLAYERID_MODE_TEAMONLY && playerid.value != PLAYERID_MODE_OFF) Q_strcpy(sbuf0, "1 %c1: %p2"); @@ -7230,7 +7230,7 @@ void CBasePlayer::UpdateStatusBar() } else if (pEntity->Classify() == CLASS_HUMAN_PASSIVE) { - if (playerid.value != PLAYERID_MODE_OFF || IsObserver()) + if (playerid.value != PLAYERID_MODE_OFF || GetObserverMode() != OBS_NONE) Q_strcpy(sbuf0, "1 %c1 %h: %i3%%"); else Q_strcpy(sbuf0, " "); @@ -9125,7 +9125,7 @@ bool CBasePlayer::IsObservingPlayer(CBasePlayer *pPlayer) if (FNullEnt(pPlayer)) return false; - return (IsObserver() == OBS_IN_EYE && pev->iuser2 == pPlayer->entindex()) != 0; + return (GetObserverMode() == OBS_IN_EYE && pev->iuser2 == pPlayer->entindex()) != 0; } void CBasePlayer::UpdateLocation(bool forceUpdate) @@ -9481,7 +9481,7 @@ bool EXT_FUNC CBasePlayer::__API_HOOK(GetIntoGame)() void CBasePlayer::PlayerRespawnThink() { #ifdef REGAMEDLL_ADD - if (IsObserver() && (m_iTeam == UNASSIGNED || m_iTeam == SPECTATOR)) + if (GetObserverMode() != OBS_NONE && (m_iTeam == UNASSIGNED || m_iTeam == SPECTATOR)) return; // Player cannot respawn while in the Choose Appearance menu diff --git a/regamedll/dlls/player.h b/regamedll/dlls/player.h index 956dfab4..d1c02976 100644 --- a/regamedll/dlls/player.h +++ b/regamedll/dlls/player.h @@ -438,7 +438,7 @@ public: void Observer_SetMode(int iMode); void Observer_CheckTarget(); void Observer_CheckProperties(); - int IsObserver() { return pev->iuser1; } + int GetObserverMode() { return pev->iuser1; } void PlantC4(); void Radio(const char *msg_id, const char *msg_verbose = nullptr, short pitch = 100, bool showIcon = true); CBasePlayer *GetNextRadioRecipient(CBasePlayer *pStartPlayer);