mirror of
https://github.com/s1lentq/ReGameDLL_CS.git
synced 2024-12-26 22:55:41 +03:00
Fix spectator check, small refactoring (#265)
* Fix spectator check, small refactoring * Update observer.cpp minor refactor-patch
This commit is contained in:
parent
ff3891d98b
commit
40f3bc488b
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<CCSPlayer>((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<CCSPlayer>((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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user