diff options
| author | Treeston <treeston.mmoc@gmail.com> | 2019-06-23 16:44:37 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2021-12-12 01:26:41 +0100 |
| commit | edc75831194bc2419e3abada47121fadf4b2aa8d (patch) | |
| tree | 9791827b1de920d98fd333f570bf4e3e9c31f7bf /src/server/game/Entities/Unit | |
| parent | 06823f19cdc08937a28b618c63e645851bbf80fb (diff) | |
Entities/Unit: Cleanup all the direct accesses to m_unitMovedByMe. Refactor the field to be protected. Add assertions to catch dangling pointers.
(cherry picked from commit 396f87c30dff1b50f1eb0d924778a7fbab7e8d11)
Diffstat (limited to 'src/server/game/Entities/Unit')
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 54 | ||||
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 12 |
2 files changed, 33 insertions, 33 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 324a44646ec..ba787843086 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -298,11 +298,10 @@ SpellNonMeleeDamage::SpellNonMeleeDamage(Unit* _attacker, Unit* _target, SpellIn } 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_interruptMask(SpellAuraInterruptFlags::None), m_interruptMask2(SpellAuraInterruptFlags2::None), - 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_interruptMask(SpellAuraInterruptFlags::None), m_interruptMask2(SpellAuraInterruptFlags2::None), + 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), _playHoverAnim(false), _aiAnimKitId(0), _movementAnimKitId(0), _meleeAnimKitId(0), @@ -433,6 +432,7 @@ Unit::~Unit() ASSERT(m_removedAuras.empty()); ASSERT(m_gameObj.empty()); ASSERT(m_dynObj.empty()); + ASSERT(!m_playerMovingMe); } void Unit::Update(uint32 p_time) @@ -8093,7 +8093,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 WorldPackets::Movement::MoveSetSpeed selfpacket(moveTypeToOpcode[mtype][1]); @@ -9481,18 +9481,15 @@ 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; -} + m_unitMovedByMe->m_playerMovingMe = nullptr; + m_unitMovedByMe = ASSERT_NOTNULL(target); + m_unitMovedByMe->m_playerMovingMe = ASSERT_NOTNULL(ToPlayer()); -Player* Unit::GetPlayerBeingMoved() const -{ - if (Unit* mover = GetUnitBeingMoved()) - return mover->ToPlayer(); - return nullptr; + WorldPackets::Movement::MoveSetActiveMover packet; + packet.MoverGUID = target->GetGUID(); + ToPlayer()->SendDirectMessage(packet.Write()); } uint32 createProcHitMask(SpellNonMeleeDamage* damageInfo, SpellMissInfo missCondition) @@ -10740,7 +10737,7 @@ void Unit::SetRooted(bool apply, bool packetOnly /*= false*/) { SMSG_MOVE_SPLINE_ROOT, SMSG_MOVE_ROOT } }; - if (Player* playerMover = GetPlayerBeingMoved()) // unit controlled by a player. + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) // unit controlled by a player. { WorldPackets::Movement::MoveSetFlag packet(rootOpcodeTable[apply][1]); packet.MoverGUID = GetGUID(); @@ -11534,7 +11531,7 @@ void Unit::KnockbackFrom(Position const& origin, float speedXY, float speedZ, Mo if (Unit* charmer = GetCharmer()) { player = charmer->ToPlayer(); - if (player && player->m_unitMovedByMe != this) + if (player && player->GetUnitBeingMoved() != this) player = nullptr; } } @@ -12002,7 +11999,8 @@ void Unit::SendTeleportPacket(Position const& pos) moveUpdateTeleport.MovementForces = _movementForces->GetForces(); 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())) { float x, y, z, o; pos.GetPosition(x, y, z, o); @@ -12360,7 +12358,7 @@ bool Unit::SetDisableGravity(bool disable) { SMSG_MOVE_SPLINE_DISABLE_GRAVITY, SMSG_MOVE_DISABLE_GRAVITY } }; - if (Player* playerMover = GetPlayerBeingMoved()) + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) { WorldPackets::Movement::MoveSetFlag packet(gravityOpcodeTable[disable][1]); packet.MoverGUID = GetGUID(); @@ -12438,7 +12436,7 @@ bool Unit::SetCanFly(bool enable) if (!enable && GetTypeId() == TYPEID_PLAYER) ToPlayer()->SetFallInformation(0, GetPositionZ()); - if (Player* playerMover = GetPlayerBeingMoved()) + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) { WorldPackets::Movement::MoveSetFlag packet(flyOpcodeTable[enable][1]); packet.MoverGUID = GetGUID(); @@ -12475,7 +12473,7 @@ bool Unit::SetWaterWalking(bool enable) { SMSG_MOVE_SPLINE_SET_WATER_WALK, SMSG_MOVE_SET_WATER_WALK } }; - if (Player* playerMover = GetPlayerBeingMoved()) + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) { WorldPackets::Movement::MoveSetFlag packet(waterWalkingOpcodeTable[enable][1]); packet.MoverGUID = GetGUID(); @@ -12513,7 +12511,7 @@ bool Unit::SetFeatherFall(bool enable) { SMSG_MOVE_SPLINE_SET_FEATHER_FALL, SMSG_MOVE_SET_FEATHER_FALL } }; - if (Player* playerMover = GetPlayerBeingMoved()) + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) { WorldPackets::Movement::MoveSetFlag packet(featherFallOpcodeTable[enable][1]); packet.MoverGUID = GetGUID(); @@ -12566,7 +12564,7 @@ bool Unit::SetHover(bool enable) { SMSG_MOVE_SPLINE_SET_HOVER, SMSG_MOVE_SET_HOVERING } }; - if (Player* playerMover = GetPlayerBeingMoved()) + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) { WorldPackets::Movement::MoveSetFlag packet(hoverOpcodeTable[enable][1]); packet.MoverGUID = GetGUID(); @@ -12603,7 +12601,7 @@ bool Unit::SetCollision(bool disable) { SMSG_MOVE_SPLINE_DISABLE_COLLISION, SMSG_MOVE_DISABLE_COLLISION } }; - if (Player* playerMover = GetPlayerBeingMoved()) + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) { WorldPackets::Movement::MoveSetFlag packet(collisionOpcodeTable[disable][1]); packet.MoverGUID = GetGUID(); @@ -12643,7 +12641,7 @@ bool Unit::SetCanTransitionBetweenSwimAndFly(bool enable) SMSG_MOVE_ENABLE_TRANSITION_BETWEEN_SWIM_AND_FLY }; - if (Player* playerMover = GetPlayerBeingMoved()) + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) { WorldPackets::Movement::MoveSetFlag packet(swimToFlyTransOpcodeTable[enable]); packet.MoverGUID = GetGUID(); @@ -12675,7 +12673,7 @@ bool Unit::SetCanTurnWhileFalling(bool enable) SMSG_MOVE_SET_CAN_TURN_WHILE_FALLING }; - if (Player* playerMover = GetPlayerBeingMoved()) + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) { WorldPackets::Movement::MoveSetFlag packet(canTurnWhileFallingOpcodeTable[enable]); packet.MoverGUID = GetGUID(); @@ -12706,7 +12704,7 @@ bool Unit::SetCanDoubleJump(bool enable) SMSG_MOVE_ENABLE_DOUBLE_JUMP }; - if (Player* playerMover = GetPlayerBeingMoved()) + if (Player* playerMover = Unit::ToPlayer(GetUnitBeingMoved())) { WorldPackets::Movement::MoveSetFlag packet(doubleJumpOpcodeTable[enable]); packet.MoverGUID = GetGUID(); diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 0b01aad923a..837004de029 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1288,14 +1288,14 @@ class TC_GAME_API Unit : public WorldObject void DeleteCharmInfo(); void SetPetNumberForClient(uint32 petNumber) { SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::PetNumber), petNumber); } void SetPetNameTimestamp(uint32 timestamp) { SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::PetNameTimestamp), timestamp); } + + // 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); @@ -1918,6 +1918,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; |
