From 9eb4cf7508a28d07eea2a51ef65578855e8e62f7 Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Wed, 6 Sep 2023 00:53:03 +0300 Subject: [PATCH] CCoreCharacter: Add and use HookedPlayer() --- src/game/client/prediction/entities/character.cpp | 2 +- src/game/client/prediction/gameworld.cpp | 4 ++-- src/game/gamecore.h | 3 ++- src/game/server/entities/character.cpp | 12 +++++++----- src/game/server/gameworld.cpp | 2 +- src/game/server/save.cpp | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp index 09edebeb8..931276d57 100644 --- a/src/game/client/prediction/entities/character.cpp +++ b/src/game/client/prediction/entities/character.cpp @@ -1171,7 +1171,7 @@ void CCharacter::ResetPrediction() SetWeaponGot(w, false); SetWeaponAmmo(w, -1); } - if(m_Core.m_HookedPlayer >= 0) + if(m_Core.HookedPlayer() >= 0) { m_Core.SetHookedPlayer(-1); m_Core.m_HookState = HOOK_IDLE; diff --git a/src/game/client/prediction/gameworld.cpp b/src/game/client/prediction/gameworld.cpp index 63d250c22..839ad8d02 100644 --- a/src/game/client/prediction/gameworld.cpp +++ b/src/game/client/prediction/gameworld.cpp @@ -315,7 +315,7 @@ void CGameWorld::ReleaseHooked(int ClientID) for(; pChr; pChr = (CCharacter *)pChr->TypeNext()) { CCharacterCore *pCore = pChr->Core(); - if(pCore->m_HookedPlayer == ClientID) + if(pCore->HookedPlayer() == ClientID) { pCore->SetHookedPlayer(-1); pCore->m_HookState = HOOK_RETRACTED; @@ -556,7 +556,7 @@ void CGameWorld::NetObjEnd() for(int i = 0; i < MAX_CLIENTS; i++) if(CCharacter *pChar = GetCharacterByID(i)) if(!pChar->m_MarkedForDestroy) - if(CCharacter *pHookedChar = GetCharacterByID(pChar->m_Core.m_HookedPlayer)) + if(CCharacter *pHookedChar = GetCharacterByID(pChar->m_Core.HookedPlayer())) if(pHookedChar->m_MarkedForDestroy) { pHookedChar->m_Pos = pHookedChar->m_Core.m_Pos = pChar->m_Core.m_HookPos; diff --git a/src/game/gamecore.h b/src/game/gamecore.h index 42c9ddbc2..be915c9c8 100644 --- a/src/game/gamecore.h +++ b/src/game/gamecore.h @@ -236,8 +236,8 @@ public: vec2 m_HookTeleBase; int m_HookTick; int m_HookState; - int m_HookedPlayer; std::set m_AttachedPlayers; + int HookedPlayer() const { return m_HookedPlayer; } void SetHookedPlayer(int HookedPlayer); int m_ActiveWeapon; @@ -318,6 +318,7 @@ public: private: CTeamsCore *m_pTeams; int m_MoveRestrictions; + int m_HookedPlayer; static bool IsSwitchActiveCb(int Number, void *pUser); }; diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index dafc7dcdb..2babaad32 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -768,7 +768,8 @@ void CCharacter::Tick() if(m_Core.m_TriggeredEvents & COREEVENT_HOOK_ATTACH_PLAYER) { - if(m_Core.m_HookedPlayer != -1 && GameServer()->m_apPlayers[m_Core.m_HookedPlayer]->GetTeam() != TEAM_SPECTATORS) + const int HookedPlayer = m_Core.HookedPlayer(); + if(HookedPlayer != -1 && GameServer()->m_apPlayers[HookedPlayer]->GetTeam() != TEAM_SPECTATORS) { Antibot()->OnHookAttach(m_pPlayer->GetCID(), true); } @@ -1138,7 +1139,7 @@ bool CCharacter::IsSnappingCharacterInView(int SnappingClientID) for(const auto &AttachedPlayerID : m_Core.m_AttachedPlayers) { CCharacter *pOtherPlayer = GameServer()->GetPlayerChar(AttachedPlayerID); - if(pOtherPlayer && pOtherPlayer->m_Core.m_HookedPlayer == ID) + if(pOtherPlayer && pOtherPlayer->m_Core.HookedPlayer() == ID) { if(!NetworkClippedLine(SnappingClientID, m_Pos, pOtherPlayer->m_Pos)) { @@ -1269,7 +1270,7 @@ void CCharacter::FillAntibot(CAntibotCharacterData *pData) pData->m_Pos = m_Pos; pData->m_Vel = m_Core.m_Vel; pData->m_Angle = m_Core.m_Angle; - pData->m_HookedPlayer = m_Core.m_HookedPlayer; + pData->m_HookedPlayer = m_Core.HookedPlayer(); pData->m_SpawnTick = m_SpawnTick; pData->m_WeaponChangeTick = m_WeaponChangeTick; pData->m_aLatestInputs[0].m_TargetX = m_LatestInput.m_TargetX; @@ -2229,7 +2230,7 @@ void CCharacter::Pause(bool Pause) GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCID()] = 0; GameServer()->m_World.RemoveEntity(this); - if(m_Core.m_HookedPlayer != -1) // Keeping hook would allow cheats + if(m_Core.HookedPlayer() != -1) // Keeping hook would allow cheats { ResetHook(); GameWorld()->ReleaseHooked(GetPlayer()->GetCID()); @@ -2332,5 +2333,6 @@ CClientMask CCharacter::TeamMask() void CCharacter::SwapClients(int Client1, int Client2) { - m_Core.SetHookedPlayer(m_Core.m_HookedPlayer == Client1 ? Client2 : m_Core.m_HookedPlayer == Client2 ? Client1 : m_Core.m_HookedPlayer); + const int HookedPlayer = m_Core.HookedPlayer(); + m_Core.SetHookedPlayer(HookedPlayer == Client1 ? Client2 : HookedPlayer == Client2 ? Client1 : HookedPlayer); } diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 7ea14b342..ee931602d 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -428,7 +428,7 @@ void CGameWorld::ReleaseHooked(int ClientID) for(; pChr; pChr = (CCharacter *)pChr->TypeNext()) { CCharacterCore *pCore = pChr->Core(); - if(pCore->m_HookedPlayer == ClientID && !pChr->IsSuper()) + if(pCore->HookedPlayer() == ClientID && !pChr->IsSuper()) { pCore->SetHookedPlayer(-1); pCore->m_TriggeredEvents |= COREEVENT_HOOK_RETRACT; diff --git a/src/game/server/save.cpp b/src/game/server/save.cpp index abdce8acf..fb764e77c 100644 --- a/src/game/server/save.cpp +++ b/src/game/server/save.cpp @@ -100,7 +100,7 @@ void CSaveTee::Save(CCharacter *pChr) m_HookTick = pChr->m_Core.m_HookTick; m_HookState = pChr->m_Core.m_HookState; - m_HookedPlayer = pChr->m_Core.m_HookedPlayer; + m_HookedPlayer = pChr->m_Core.HookedPlayer(); m_NewHook = pChr->m_Core.m_NewHook != 0; m_InputDirection = pChr->m_SavedInput.m_Direction;