Entities/Unit: Cleanup all the direct accesses to m_unitMovedByMe. Refactor the field to be protected. Add assertions to catch dangling pointers.
Port From (https://github.com/TrinityCore/TrinityCore/commit/edc75831194bc2419e3abada47121fadf4b2aa8d)
This commit is contained in:
@@ -209,8 +209,6 @@ namespace Game.Entities
|
|||||||
public List<ObjectGuid> m_clientGUIDs = new();
|
public List<ObjectGuid> m_clientGUIDs = new();
|
||||||
public List<ObjectGuid> m_visibleTransports = new();
|
public List<ObjectGuid> m_visibleTransports = new();
|
||||||
public WorldObject seerView;
|
public WorldObject seerView;
|
||||||
// only changed for direct client control (possess, vehicle etc.), not stuff you control using pet commands
|
|
||||||
public Unit m_unitMovedByMe;
|
|
||||||
Team m_team;
|
Team m_team;
|
||||||
ReputationMgr reputationMgr;
|
ReputationMgr reputationMgr;
|
||||||
QuestObjectiveCriteriaManager m_questObjectiveCriteriaMgr;
|
QuestObjectiveCriteriaManager m_questObjectiveCriteriaMgr;
|
||||||
|
|||||||
@@ -4013,7 +4013,7 @@ namespace Game.Entities
|
|||||||
public override bool CanAlwaysSee(WorldObject obj)
|
public override bool CanAlwaysSee(WorldObject obj)
|
||||||
{
|
{
|
||||||
// Always can see self
|
// Always can see self
|
||||||
if (m_unitMovedByMe == obj)
|
if (GetUnitBeingMoved() == obj)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ObjectGuid guid = m_activePlayerData.FarsightObject;
|
ObjectGuid guid = m_activePlayerData.FarsightObject;
|
||||||
@@ -5544,7 +5544,7 @@ namespace Game.Entities
|
|||||||
initialSetup.ServerExpansionLevel = (byte)WorldConfig.GetIntValue(WorldCfg.Expansion);
|
initialSetup.ServerExpansionLevel = (byte)WorldConfig.GetIntValue(WorldCfg.Expansion);
|
||||||
SendPacket(initialSetup);
|
SendPacket(initialSetup);
|
||||||
|
|
||||||
SetMover(this);
|
SetMovedUnit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendInitialPacketsAfterAddToMap()
|
public void SendInitialPacketsAfterAddToMap()
|
||||||
@@ -7228,18 +7228,7 @@ namespace Game.Entities
|
|||||||
SetViewpoint(target, allowMove);
|
SetViewpoint(target, allowMove);
|
||||||
|
|
||||||
if (allowMove)
|
if (allowMove)
|
||||||
SetMover(target);
|
SetMovedUnit(target);
|
||||||
}
|
|
||||||
|
|
||||||
public void SetMover(Unit target)
|
|
||||||
{
|
|
||||||
m_unitMovedByMe.m_playerMovingMe = null;
|
|
||||||
m_unitMovedByMe = target;
|
|
||||||
m_unitMovedByMe.m_playerMovingMe = this;
|
|
||||||
|
|
||||||
MoveSetActiveMover packet = new();
|
|
||||||
packet.MoverGUID = target.GetGUID();
|
|
||||||
SendPacket(packet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item GetWeaponForAttack(WeaponAttackType attackType, bool useable = false)
|
public Item GetWeaponForAttack(WeaponAttackType attackType, bool useable = false)
|
||||||
|
|||||||
@@ -42,8 +42,9 @@ namespace Game.Entities
|
|||||||
MotionMaster i_motionMaster;
|
MotionMaster i_motionMaster;
|
||||||
public uint m_movementCounter; //< Incrementing counter used in movement packets
|
public uint m_movementCounter; //< Incrementing counter used in movement packets
|
||||||
TimeTrackerSmall movesplineTimer;
|
TimeTrackerSmall movesplineTimer;
|
||||||
public Player m_playerMovingMe;
|
|
||||||
MovementForces _movementForces;
|
MovementForces _movementForces;
|
||||||
|
protected Unit m_unitMovedByMe; // only ever set for players, and only for direct client control
|
||||||
|
protected Player m_playerMovingMe; // only set for direct client control (possess effects, vehicles and similar)
|
||||||
|
|
||||||
//Combat
|
//Combat
|
||||||
protected List<Unit> attackerList = new();
|
protected List<Unit> attackerList = new();
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace Game.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved(); // unit controlled by a player.
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer(); // unit controlled by a player.
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
// Send notification to self
|
// Send notification to self
|
||||||
@@ -244,7 +244,7 @@ namespace Game.Entities
|
|||||||
if (charmer)
|
if (charmer)
|
||||||
{
|
{
|
||||||
player = charmer.ToPlayer();
|
player = charmer.ToPlayer();
|
||||||
if (player && player.m_unitMovedByMe != this)
|
if (player && player.GetUnitBeingMoved() != this)
|
||||||
player = null;
|
player = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -287,7 +287,7 @@ namespace Game.Entities
|
|||||||
else
|
else
|
||||||
RemoveUnitMovementFlag(MovementFlag.DisableCollision);
|
RemoveUnitMovementFlag(MovementFlag.DisableCollision);
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(disable ? ServerOpcodes.MoveSplineEnableCollision : ServerOpcodes.MoveEnableCollision);
|
MoveSetFlag packet = new(disable ? ServerOpcodes.MoveSplineEnableCollision : ServerOpcodes.MoveEnableCollision);
|
||||||
@@ -322,7 +322,7 @@ namespace Game.Entities
|
|||||||
else
|
else
|
||||||
RemoveUnitMovementFlag2(MovementFlag2.CanSwimToFlyTrans);
|
RemoveUnitMovementFlag2(MovementFlag2.CanSwimToFlyTrans);
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveEnableTransitionBetweenSwimAndFly : ServerOpcodes.MoveDisableTransitionBetweenSwimAndFly);
|
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveEnableTransitionBetweenSwimAndFly : ServerOpcodes.MoveDisableTransitionBetweenSwimAndFly);
|
||||||
@@ -349,7 +349,7 @@ namespace Game.Entities
|
|||||||
else
|
else
|
||||||
RemoveUnitMovementFlag2(MovementFlag2.CanTurnWhileFalling);
|
RemoveUnitMovementFlag2(MovementFlag2.CanTurnWhileFalling);
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetCanTurnWhileFalling : ServerOpcodes.MoveUnsetCanTurnWhileFalling);
|
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetCanTurnWhileFalling : ServerOpcodes.MoveUnsetCanTurnWhileFalling);
|
||||||
@@ -375,7 +375,7 @@ namespace Game.Entities
|
|||||||
else
|
else
|
||||||
RemoveUnitMovementFlag2(MovementFlag2.CanDoubleJump);
|
RemoveUnitMovementFlag2(MovementFlag2.CanDoubleJump);
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveEnableDoubleJump : ServerOpcodes.MoveDisableDoubleJump);
|
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveEnableDoubleJump : ServerOpcodes.MoveDisableDoubleJump);
|
||||||
@@ -672,7 +672,7 @@ namespace Game.Entities
|
|||||||
RemoveUnitMovementFlag(MovementFlag.DisableGravity);
|
RemoveUnitMovementFlag(MovementFlag.DisableGravity);
|
||||||
|
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(disable ? ServerOpcodes.MoveDisableGravity : ServerOpcodes.MoveEnableGravity);
|
MoveSetFlag packet = new(disable ? ServerOpcodes.MoveDisableGravity : ServerOpcodes.MoveEnableGravity);
|
||||||
@@ -816,8 +816,8 @@ namespace Game.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ProcessPositionDataChanged(PositionFullTerrainStatus data)
|
public override void ProcessPositionDataChanged(PositionFullTerrainStatus data)
|
||||||
{
|
{
|
||||||
base.ProcessPositionDataChanged(data);
|
base.ProcessPositionDataChanged(data);
|
||||||
ProcessTerrainStatusUpdate(data.LiquidStatus, data.LiquidInfo);
|
ProcessTerrainStatusUpdate(data.LiquidStatus, data.LiquidInfo);
|
||||||
@@ -922,7 +922,7 @@ namespace Game.Entities
|
|||||||
if (!enable && IsTypeId(TypeId.Player))
|
if (!enable && IsTypeId(TypeId.Player))
|
||||||
ToPlayer().SetFallInformation(0, GetPositionZ());
|
ToPlayer().SetFallInformation(0, GetPositionZ());
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetCanFly : ServerOpcodes.MoveUnsetCanFly);
|
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetCanFly : ServerOpcodes.MoveUnsetCanFly);
|
||||||
@@ -955,7 +955,7 @@ namespace Game.Entities
|
|||||||
RemoveUnitMovementFlag(MovementFlag.WaterWalk);
|
RemoveUnitMovementFlag(MovementFlag.WaterWalk);
|
||||||
|
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetWaterWalk : ServerOpcodes.MoveSetLandWalk);
|
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetWaterWalk : ServerOpcodes.MoveSetLandWalk);
|
||||||
@@ -988,7 +988,7 @@ namespace Game.Entities
|
|||||||
RemoveUnitMovementFlag(MovementFlag.FallingSlow);
|
RemoveUnitMovementFlag(MovementFlag.FallingSlow);
|
||||||
|
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetFeatherFall : ServerOpcodes.MoveSetNormalFall);
|
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetFeatherFall : ServerOpcodes.MoveSetNormalFall);
|
||||||
@@ -1036,7 +1036,7 @@ namespace Game.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetHovering : ServerOpcodes.MoveUnsetHovering);
|
MoveSetFlag packet = new(enable ? ServerOpcodes.MoveSetHovering : ServerOpcodes.MoveUnsetHovering);
|
||||||
@@ -1107,6 +1107,17 @@ namespace Game.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetMovedUnit(Unit target)
|
||||||
|
{
|
||||||
|
m_unitMovedByMe.m_playerMovingMe = null;
|
||||||
|
m_unitMovedByMe = target;
|
||||||
|
m_unitMovedByMe.m_playerMovingMe = ToPlayer();
|
||||||
|
|
||||||
|
MoveSetActiveMover packet = new();
|
||||||
|
packet.MoverGUID = target.GetGUID();
|
||||||
|
ToPlayer().SendPacket(packet);
|
||||||
|
}
|
||||||
|
|
||||||
public void SetControlled(bool apply, UnitState state)
|
public void SetControlled(bool apply, UnitState state)
|
||||||
{
|
{
|
||||||
if (apply)
|
if (apply)
|
||||||
@@ -1254,7 +1265,7 @@ namespace Game.Entities
|
|||||||
RemoveUnitMovementFlag(MovementFlag.Root);
|
RemoveUnitMovementFlag(MovementFlag.Root);
|
||||||
}
|
}
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();// unit controlled by a player.
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();// unit controlled by a player.
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
MoveSetFlag packet = new(apply ? ServerOpcodes.MoveRoot : ServerOpcodes.MoveUnroot);
|
MoveSetFlag packet = new(apply ? ServerOpcodes.MoveRoot : ServerOpcodes.MoveUnroot);
|
||||||
@@ -1624,14 +1635,7 @@ namespace Game.Entities
|
|||||||
SendMessageToSet(data, true);
|
SendMessageToSet(data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Unit GetUnitBeingMoved()
|
public Unit GetUnitBeingMoved() { return m_unitMovedByMe; }
|
||||||
{
|
|
||||||
Player player = ToPlayer();
|
|
||||||
if (player)
|
|
||||||
return player.m_unitMovedByMe;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player GetPlayerBeingMoved()
|
Player GetPlayerBeingMoved()
|
||||||
{
|
{
|
||||||
@@ -1759,7 +1763,8 @@ namespace Game.Entities
|
|||||||
moveUpdateTeleport.MovementForces = _movementForces.GetForces();
|
moveUpdateTeleport.MovementForces = _movementForces.GetForces();
|
||||||
Unit broadcastSource = this;
|
Unit broadcastSource = this;
|
||||||
|
|
||||||
Player playerMover = GetPlayerBeingMoved();
|
// should this really be the unit _being_ moved? not the unit doing the moving?
|
||||||
|
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
|
||||||
if (playerMover)
|
if (playerMover)
|
||||||
{
|
{
|
||||||
float x, y, z, o;
|
float x, y, z, o;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace Game
|
|||||||
Player user = GetPlayer();
|
Player user = GetPlayer();
|
||||||
|
|
||||||
// ignore for remote control state
|
// ignore for remote control state
|
||||||
if (user.m_unitMovedByMe != user)
|
if (user.GetUnitBeingMoved() != user)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Item item = user.GetUseableItemByPos(packet.PackSlot, packet.Slot);
|
Item item = user.GetUseableItemByPos(packet.PackSlot, packet.Slot);
|
||||||
@@ -133,7 +133,7 @@ namespace Game
|
|||||||
Player player = GetPlayer();
|
Player player = GetPlayer();
|
||||||
|
|
||||||
// ignore for remote control state
|
// ignore for remote control state
|
||||||
if (player.m_unitMovedByMe != player)
|
if (player.GetUnitBeingMoved() != player)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// additional check, client outputs message on its own
|
// additional check, client outputs message on its own
|
||||||
@@ -243,8 +243,8 @@ namespace Game
|
|||||||
if (obj)
|
if (obj)
|
||||||
{
|
{
|
||||||
// ignore for remote control state
|
// ignore for remote control state
|
||||||
if (GetPlayer().m_unitMovedByMe != GetPlayer())
|
if (GetPlayer().GetUnitBeingMoved() != GetPlayer())
|
||||||
if (!(GetPlayer().IsOnVehicle(GetPlayer().m_unitMovedByMe) || GetPlayer().IsMounted()) && !obj.GetGoInfo().IsUsableMounted())
|
if (!(GetPlayer().IsOnVehicle(GetPlayer().GetUnitBeingMoved()) || GetPlayer().IsMounted()) && !obj.GetGoInfo().IsUsableMounted())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
obj.Use(GetPlayer());
|
obj.Use(GetPlayer());
|
||||||
@@ -255,7 +255,7 @@ namespace Game
|
|||||||
void HandleGameobjectReportUse(GameObjReportUse packet)
|
void HandleGameobjectReportUse(GameObjReportUse packet)
|
||||||
{
|
{
|
||||||
// ignore for remote control state
|
// ignore for remote control state
|
||||||
if (GetPlayer().m_unitMovedByMe != GetPlayer())
|
if (GetPlayer().GetUnitBeingMoved() != GetPlayer())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GameObject go = GetPlayer().GetGameObjectIfCanInteractWith(packet.Guid);
|
GameObject go = GetPlayer().GetGameObjectIfCanInteractWith(packet.Guid);
|
||||||
@@ -272,7 +272,7 @@ namespace Game
|
|||||||
void HandleCastSpell(CastSpell cast)
|
void HandleCastSpell(CastSpell cast)
|
||||||
{
|
{
|
||||||
// ignore for remote control state (for player case)
|
// ignore for remote control state (for player case)
|
||||||
Unit mover = GetPlayer().m_unitMovedByMe;
|
Unit mover = GetPlayer().GetUnitBeingMoved();
|
||||||
if (mover != GetPlayer() && mover.IsTypeId(TypeId.Player))
|
if (mover != GetPlayer() && mover.IsTypeId(TypeId.Player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -472,7 +472,7 @@ namespace Game
|
|||||||
void HandleCancelChanneling(CancelChannelling cancelChanneling)
|
void HandleCancelChanneling(CancelChannelling cancelChanneling)
|
||||||
{
|
{
|
||||||
// ignore for remote control state (for player case)
|
// ignore for remote control state (for player case)
|
||||||
Unit mover = _player.m_unitMovedByMe;
|
Unit mover = _player.GetUnitBeingMoved();
|
||||||
if (mover != _player && mover.IsTypeId(TypeId.Player))
|
if (mover != _player && mover.IsTypeId(TypeId.Player))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -483,7 +483,7 @@ namespace Game
|
|||||||
void HandleTotemDestroyed(TotemDestroyed totemDestroyed)
|
void HandleTotemDestroyed(TotemDestroyed totemDestroyed)
|
||||||
{
|
{
|
||||||
// ignore for remote control state
|
// ignore for remote control state
|
||||||
if (GetPlayer().m_unitMovedByMe != GetPlayer())
|
if (GetPlayer().GetUnitBeingMoved() != GetPlayer())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
byte slotId = totemDestroyed.Slot;
|
byte slotId = totemDestroyed.Slot;
|
||||||
|
|||||||
Reference in New Issue
Block a user