Entities/Unit: Cleanup all the direct accesses to m_unitMovedByMe. Refactor the field to be protected. Add assertions to catch dangling pointers.

This commit is contained in:
Treeston
2019-06-23 16:44:37 +02:00
parent b3ee407707
commit 396f87c30d
8 changed files with 36 additions and 50 deletions
+1 -9
View File
@@ -22226,7 +22226,7 @@ bool Player::IsNeverVisible() const
bool Player::CanAlwaysSee(WorldObject const* obj) const
{
// Always can see self
if (m_unitMovedByMe == obj)
if (GetUnitBeingMoved() == obj)
return true;
if (ObjectGuid guid = GetGuidValue(PLAYER_FARSIGHT))
@@ -23894,14 +23894,6 @@ void Player::SetClientControl(Unit* target, bool allowMove)
SetMovedUnit(target);
}
void Player::SetMovedUnit(Unit* target)
{
m_unitMovedByMe->m_playerMovingMe = nullptr;
m_unitMovedByMe = target;
m_unitMovedByMe->m_playerMovingMe = this;
}
void Player::UpdateZoneDependentAuras(uint32 newZone)
{
// Some spells applied at enter into zone (with subzones), aura removed in UpdateAreaDependentAuras that called always at zone->area update
-3
View File
@@ -1942,7 +1942,6 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
/*********************************************************/
void UpdateFallInformationIfNeed(MovementInfo const& minfo, uint16 opcode);
// only changed for direct client control (possess, vehicle etc.), not stuff you control using pet commands
Unit* m_unitMovedByMe;
WorldObject* m_seer;
void SetFallInformation(uint32 time, float z);
void HandleFall(MovementInfo const& movementInfo);
@@ -1951,8 +1950,6 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void SetClientControl(Unit* target, bool allowMove);
void SetMovedUnit(Unit* target);
void SetSeer(WorldObject* target) { m_seer = target; }
void SetViewpoint(WorldObject* target, bool apply);
WorldObject* GetViewpoint() const;
+12 -17
View File
@@ -289,9 +289,9 @@ bool DispelableAura::RollDispel() const
}
Unit::Unit(bool isWorldObject) :
WorldObject(isWorldObject), m_playerMovingMe(nullptr), m_lastSanctuaryTime(0), LastCharmerGUID(),
movespline(new Movement::MoveSpline()), m_ControlledByPlayer(false), m_AutoRepeatFirstCast(false),
m_procDeep(0), m_transformSpell(0), m_removedAurasCount(0), m_charmer(nullptr), m_charmed(nullptr),
WorldObject(isWorldObject), m_lastSanctuaryTime(0), LastCharmerGUID(), movespline(new Movement::MoveSpline()),
m_ControlledByPlayer(false), m_AutoRepeatFirstCast(false), m_procDeep(0), m_transformSpell(0),
m_removedAurasCount(0), m_unitMovedByMe(nullptr), m_playerMovingMe(nullptr), m_charmer(nullptr), m_charmed(nullptr),
i_motionMaster(new MotionMaster(this)), m_regenTimer(0), m_vehicle(nullptr), m_vehicleKit(nullptr),
m_unitTypeMask(UNIT_MASK_NONE), m_Diminishing(), m_isEngaged(false), m_combatManager(this), m_threatManager(this),
m_aiLocked(false), m_comboTarget(nullptr), m_comboPoints(0), m_spellHistory(new SpellHistory(this))
@@ -412,6 +412,7 @@ Unit::~Unit()
ASSERT(m_removedAuras.empty());
ASSERT(m_gameObj.empty());
ASSERT(m_dynObj.empty());
ASSERT(!m_playerMovingMe);
}
void Unit::Update(uint32 p_time)
@@ -8561,7 +8562,7 @@ void Unit::SetSpeedRate(UnitMoveType mtype, float rate)
pet->SetSpeedRate(mtype, m_speed_rate[mtype]);
}
if (Player* playerMover = GetPlayerBeingMoved()) // unit controlled by a player.
if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) // unit controlled by a player.
{
// Send notification to self. this packet is only sent to one client (the client of the player concerned by the change).
WorldPacket self;
@@ -9841,18 +9842,11 @@ void CharmInfo::SetSpellAutocast(SpellInfo const* spellInfo, bool state)
}
}
Unit* Unit::GetUnitBeingMoved() const
void Unit::SetMovedUnit(Unit* target)
{
if (Player const* player = ToPlayer())
return player->m_unitMovedByMe;
return nullptr;
}
Player* Unit::GetPlayerBeingMoved() const
{
if (Unit* mover = GetUnitBeingMoved())
return mover->ToPlayer();
return nullptr;
m_unitMovedByMe->m_playerMovingMe = nullptr;
m_unitMovedByMe = ASSERT_NOTNULL(target);
m_unitMovedByMe->m_playerMovingMe = ASSERT_NOTNULL(ToPlayer());
}
uint32 createProcHitMask(SpellNonMeleeDamage* damageInfo, SpellMissInfo missCondition)
@@ -12003,7 +11997,7 @@ void Unit::KnockbackFrom(float x, float y, float speedXY, float speedZ)
if (Unit* charmer = GetCharmer())
{
player = charmer->ToPlayer();
if (player && player->m_unitMovedByMe != this)
if (player && player->GetUnitBeingMoved() != this)
player = nullptr;
}
}
@@ -12744,7 +12738,8 @@ void Unit::SendTeleportPacket(Position const& pos, bool teleportingTransport /*=
moveUpdateTeleport << GetPackGUID();
Unit* broadcastSource = this;
if (Player* playerMover = GetPlayerBeingMoved())
// should this really be the unit _being_ moved? not the unit doing the moving?
if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved()))
{
WorldPacket moveTeleport(MSG_MOVE_TELEPORT_ACK, 41);
moveTeleport << GetPackGUID();
+7 -5
View File
@@ -1190,14 +1190,14 @@ class TC_GAME_API Unit : public WorldObject
CharmInfo* GetCharmInfo() { return m_charmInfo; }
CharmInfo* InitCharmInfo();
void DeleteCharmInfo();
// all of these are for DIRECT CLIENT CONTROL only
void SetMovedUnit(Unit* target);
// returns the unit that this player IS CONTROLLING
Unit* GetUnitBeingMoved() const;
// returns the player that this player IS CONTROLLING
Player* GetPlayerBeingMoved() const;
Unit* GetUnitBeingMoved() const { return m_unitMovedByMe; }
// returns the player that this unit is BEING CONTROLLED BY
Player* GetPlayerMovingMe() const { return m_playerMovingMe; }
// only set for direct client control (possess effects, vehicles and similar)
Player* m_playerMovingMe;
SharedVisionList const& GetSharedVisionList() { return m_sharedVision; }
void AddPlayerToVision(Player* player);
void RemovePlayerFromVision(Player* player);
@@ -1739,6 +1739,8 @@ class TC_GAME_API Unit : public WorldObject
float m_speed_rate[MAX_MOVE_TYPE];
Unit* m_unitMovedByMe; // only ever set for players, and only for direct client control
Player* m_playerMovingMe; // only set for direct client control (possess effects, vehicles and similar)
Unit* m_charmer; // Unit that is charming ME
Unit* m_charmed; // Unit that is being charmed BY ME
CharmInfo* m_charmInfo;
+1 -1
View File
@@ -1387,7 +1387,7 @@ void WorldSession::HandleMoveSetCanFlyAckOpcode(WorldPacket& recvData)
recvData.read_skip<float>(); // unk2
_player->m_unitMovedByMe->m_movementInfo.flags = movementInfo.GetMovementFlags();
_player->GetUnitBeingMoved()->m_movementInfo.flags = movementInfo.GetMovementFlags();
}
void WorldSession::HandleRequestPetInfoOpcode(WorldPacket& /*recvData */)
+5 -5
View File
@@ -216,7 +216,7 @@ void WorldSession::HandleMoveTeleportAck(WorldPacket& recvData)
uint32 sequenceIndex, time;
recvData >> sequenceIndex >> time;
Player* plMover = _player->m_unitMovedByMe->ToPlayer();
Player* plMover = _player->GetUnitBeingMoved()->ToPlayer();
if (!plMover || !plMover->IsBeingTeleportedNear())
return;
@@ -260,7 +260,7 @@ void WorldSession::HandleMovementOpcodes(WorldPacket& recvData)
{
uint16 opcode = recvData.GetOpcode();
Unit* mover = _player->m_unitMovedByMe;
Unit* mover = _player->GetUnitBeingMoved();
ASSERT(mover != nullptr); // there must always be a mover
@@ -521,8 +521,8 @@ void WorldSession::HandleSetActiveMoverOpcode(WorldPacket &recvData)
recvData >> guid;
if (GetPlayer()->IsInWorld())
if (_player->m_unitMovedByMe->GetGUID() != guid)
TC_LOG_DEBUG("network", "HandleSetActiveMoverOpcode: incorrect mover guid: mover is %s and should be %s" , guid.ToString().c_str(), _player->m_unitMovedByMe->GetGUID().ToString().c_str());
if (_player->GetUnitBeingMoved()->GetGUID() != guid)
TC_LOG_DEBUG("network", "HandleSetActiveMoverOpcode: incorrect mover guid: mover is %s and should be %s" , guid.ToString().c_str(), _player->GetUnitBeingMoved()->GetGUID().ToString().c_str());
}
void WorldSession::HandleMoveNotActiveMover(WorldPacket &recvData)
@@ -555,7 +555,7 @@ void WorldSession::HandleMoveKnockBackAck(WorldPacket& recvData)
ObjectGuid guid;
recvData >> guid.ReadAsPacked();
if (_player->m_unitMovedByMe->GetGUID() != guid)
if (_player->GetUnitBeingMoved()->GetGUID() != guid)
return;
recvData.read_skip<uint32>(); // unk
+8 -8
View File
@@ -66,7 +66,7 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket)
Player* pUser = _player;
// ignore for remote control state
if (pUser->m_unitMovedByMe != pUser)
if (pUser->GetUnitBeingMoved() != pUser)
return;
uint8 bagIndex, slot, castFlags;
@@ -177,7 +177,7 @@ void WorldSession::HandleOpenItemOpcode(WorldPacket& recvPacket)
Player* player = GetPlayer();
// ignore for remote control state
if (player->m_unitMovedByMe != player)
if (player->GetUnitBeingMoved() != player)
return;
// additional check, client outputs message on its own
@@ -297,8 +297,8 @@ void WorldSession::HandleGameObjectUseOpcode(WorldPacket& recvData)
if (GameObject* obj = GetPlayer()->GetGameObjectIfCanInteractWith(guid))
{
// ignore for remote control state
if (GetPlayer()->m_unitMovedByMe != GetPlayer())
if (!(GetPlayer()->IsOnVehicle(GetPlayer()->m_unitMovedByMe) || GetPlayer()->IsMounted()) && !obj->GetGOInfo()->IsUsableMounted())
if (GetPlayer()->GetUnitBeingMoved() != GetPlayer())
if (!(GetPlayer()->IsOnVehicle(GetPlayer()->GetUnitBeingMoved()) || GetPlayer()->IsMounted()) && !obj->GetGOInfo()->IsUsableMounted())
return;
obj->Use(GetPlayer());
@@ -313,7 +313,7 @@ void WorldSession::HandleGameobjectReportUse(WorldPacket& recvPacket)
TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_GAMEOBJ_REPORT_USE Message [%s]", guid.ToString().c_str());
// ignore for remote control state
if (_player->m_unitMovedByMe != _player)
if (_player->GetUnitBeingMoved() != _player)
return;
if (GameObject* go = GetPlayer()->GetGameObjectIfCanInteractWith(guid))
@@ -335,7 +335,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket)
TC_LOG_DEBUG("network", "WORLD: got cast spell packet, castCount: %u, spellId: %u, castFlags: %u, data length = %u", castCount, spellId, castFlags, (uint32)recvPacket.size());
// ignore for remote control state (for player case)
Unit* mover = _player->m_unitMovedByMe;
Unit* mover = _player->GetUnitBeingMoved();
if (mover != _player && mover->GetTypeId() == TYPEID_PLAYER)
{
recvPacket.rfinish(); // prevent spam at ignore packet
@@ -549,7 +549,7 @@ void WorldSession::HandleCancelChanneling(WorldPacket& recvData)
recvData.read_skip<uint32>(); // spellid, not used
// ignore for remote control state (for player case)
Unit* mover = _player->m_unitMovedByMe;
Unit* mover = _player->GetUnitBeingMoved();
if (mover != _player && mover->GetTypeId() == TYPEID_PLAYER)
return;
@@ -559,7 +559,7 @@ void WorldSession::HandleCancelChanneling(WorldPacket& recvData)
void WorldSession::HandleTotemDestroyed(WorldPacket& recvPacket)
{
// ignore for remote control state
if (_player->m_unitMovedByMe != _player)
if (_player->GetUnitBeingMoved() != _player)
return;
uint8 slotId;
+2 -2
View File
@@ -934,8 +934,8 @@ void WorldSession::ReadMovementInfo(WorldPacket &data, MovementInfo* mi)
*/
REMOVE_VIOLATING_FLAGS(mi->HasMovementFlag(MOVEMENTFLAG_FLYING | MOVEMENTFLAG_CAN_FLY) && GetSecurity() == SEC_PLAYER &&
!GetPlayer()->m_unitMovedByMe->HasAuraType(SPELL_AURA_FLY) &&
!GetPlayer()->m_unitMovedByMe->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED),
!GetPlayer()->GetUnitBeingMoved()->HasAuraType(SPELL_AURA_FLY) &&
!GetPlayer()->GetUnitBeingMoved()->HasAuraType(SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED),
MOVEMENTFLAG_FLYING | MOVEMENTFLAG_CAN_FLY);
//! Cannot fly and fall at the same time