From f2f3a170e590d35cc06b54656f4b65ef503160cf Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Sat, 23 Mar 2019 23:33:50 +0200 Subject: [PATCH] Fix mind control on old clients. --- src/game/Handlers/MovementHandler.cpp | 10 ++++++- src/game/Objects/Object.cpp | 2 +- src/game/Objects/Player.cpp | 27 ++++++++++++++++++ src/game/Objects/Player.h | 2 ++ src/game/Spells/SpellAuras.cpp | 40 +++++++++++++-------------- 5 files changed, 59 insertions(+), 22 deletions(-) diff --git a/src/game/Handlers/MovementHandler.cpp b/src/game/Handlers/MovementHandler.cpp index 4e80b0037..91301187f 100644 --- a/src/game/Handlers/MovementHandler.cpp +++ b/src/game/Handlers/MovementHandler.cpp @@ -501,7 +501,15 @@ void WorldSession::HandleSetActiveMoverOpcode(WorldPacket &recv_data) ObjectGuid guid; recv_data >> guid; - if (_player->GetMover() && _player->GetMover()->GetObjectGuid() != guid) + ObjectGuid serverMoverGuid = _player->GetMover()->GetObjectGuid(); + + // Before 1.10, client sends 0 as guid if it has no control. +#if SUPPORTED_CLIENT_BUILD <= CLIENT_BUILD_1_9_4 + if ((serverMoverGuid == _player->GetObjectGuid()) && !_player->HasSelfMovementControl()) + serverMoverGuid = ObjectGuid(); +#endif + + if (serverMoverGuid != guid) { sLog.outError("HandleSetActiveMoverOpcode: incorrect mover guid: mover is %s and should be %s", _player->GetMover()->GetGuidStr().c_str(), guid.GetString().c_str()); diff --git a/src/game/Objects/Object.cpp b/src/game/Objects/Object.cpp index b36548334..350017493 100644 --- a/src/game/Objects/Object.cpp +++ b/src/game/Objects/Object.cpp @@ -335,7 +335,7 @@ void Object::BuildCreateUpdateBlockForPlayer(UpdateData *data, Player *target) c BuildMovementUpdate(&buf, updateFlags); #if SUPPORTED_CLIENT_BUILD <= CLIENT_BUILD_1_8_4 - buf << uint32(target == this ? 1 : 0); // Flags, 1 - Active Player + buf << uint32(target->IsMoverOf(this) ? 1 : 0); // Flags, 1 - Active Player buf << uint32(0); // AttackCycle buf << uint32(0); // TimerId buf << uint64(0); // VictimGuid diff --git a/src/game/Objects/Player.cpp b/src/game/Objects/Player.cpp index a14ef9a75..58f6c4e95 100644 --- a/src/game/Objects/Player.cpp +++ b/src/game/Objects/Player.cpp @@ -19360,6 +19360,33 @@ void Player::SetClientControl(Unit* target, uint8 allowMove) #endif } +bool Player::IsMoverOf(Object const* pObject) const +{ + if (Player const* pPlayer = pObject->ToPlayer()) + { + if (GetMover() == pPlayer) + return true; + } + + return false; +} + +bool Player::HasSelfMovementControl() const +{ + // Using Mind Vision + if (GetUInt64Value(PLAYER_FARSIGHT)) + return false; + + // Using Far Sight + if (m_longSightSpell) + return false; + + if (hasUnitState(UNIT_STAT_LOST_CONTROL | UNIT_STAT_CONFUSED | UNIT_STAT_TAXI_FLIGHT)) + return false; + + return true; +} + bool Player::IsAllowedToMove(Unit* unit) const { if (unit == this) diff --git a/src/game/Objects/Player.h b/src/game/Objects/Player.h index a7902f4e0..35efae32a 100644 --- a/src/game/Objects/Player.h +++ b/src/game/Objects/Player.h @@ -1782,6 +1782,8 @@ class MANGOS_DLL_SPEC Player final: public Unit void SetMover(Unit* target) { m_mover = target ? target : this; } Unit* GetMover() const { return m_mover; } bool IsSelfMover() const { return m_mover == this; }// normal case for player not controlling other unit + bool IsMoverOf(Object const* pObject) const; + bool HasSelfMovementControl() const; bool IsNextRelocationIgnored() const { return m_bNextRelocationsIgnored ? true : false; } void SetNextRelocationsIgnoredCount(uint32 count) { m_bNextRelocationsIgnored = count; } void DoIgnoreRelocation() { if (m_bNextRelocationsIgnored) --m_bNextRelocationsIgnored; } diff --git a/src/game/Spells/SpellAuras.cpp b/src/game/Spells/SpellAuras.cpp index 696b97df3..c929c1db4 100644 --- a/src/game/Spells/SpellAuras.cpp +++ b/src/game/Spells/SpellAuras.cpp @@ -2808,14 +2808,10 @@ void Unit::ModPossess(Unit* target, bool apply, AuraRemoveMode m_removeMode) Unit* caster = this; - Player* p_caster = nullptr; - if (caster->IsCreature() && target->IsPlayer()) - { - // Creature cast CM sur Joueur - } - else if (caster->IsPlayer()) - p_caster = (Player*)caster; - else + Player* pPlayerCaster = caster->ToPlayer(); + Player* pPlayerTarget = target->ToPlayer(); + + if (!pPlayerCaster && !pPlayerTarget) return; if (apply) @@ -2833,11 +2829,11 @@ void Unit::ModPossess(Unit* target, bool apply, AuraRemoveMode m_removeMode) target->setFaction(caster->getFaction()); // target should became visible at SetView call(if not visible before): - // otherwise client\p_caster will ignore packets from the target(SetClientControl for example) - p_caster->GetCamera().SetView(target); + // otherwise client\pPlayerCaster will ignore packets from the target(SetClientControl for example) + pPlayerCaster->GetCamera().SetView(target); caster->SetCharm(target); - p_caster->SetMover(target); + pPlayerCaster->SetMover(target); target->CombatStop(true); @@ -2849,15 +2845,15 @@ void Unit::ModPossess(Unit* target, bool apply, AuraRemoveMode m_removeMode) charmInfo->SetOriginalFactionTemplate(origFactionTemplate); } - p_caster->PossessSpellInitialize(); + pPlayerCaster->PossessSpellInitialize(); if (Creature* pTargetCrea = target->ToCreature()) if (!pTargetCrea->hasUnitState(UNIT_STAT_CAN_NOT_REACT)) if (pTargetCrea->AI()->SwitchAiAtControl()) pTargetCrea->AIM_Initialize(); - if (target->IsPlayer() && !caster->IsPlayer()) - target->ToPlayer()->SetControlledBy(caster); + if (pPlayerTarget && !pPlayerCaster) + pPlayerTarget->SetControlledBy(caster); // Les mobs doivent attaquer celui qui est CM. // On appelle donc 'MoveInLineOfSight' pour les mobs a cote. target->ScheduleAINotify(0); @@ -2865,7 +2861,7 @@ void Unit::ModPossess(Unit* target, bool apply, AuraRemoveMode m_removeMode) if (target->hasUnitState(UNIT_STAT_STUNNED | UNIT_STAT_PENDING_STUNNED | UNIT_STAT_ROOT | UNIT_STAT_PENDING_ROOT)) target->SetMovement(MOVE_ROOT); target->StopMoving(); - target->SetWalk(p_caster->IsWalking()); + target->SetWalk(pPlayerCaster->IsWalking()); } else { @@ -2875,15 +2871,14 @@ void Unit::ModPossess(Unit* target, bool apply, AuraRemoveMode m_removeMode) // spell is interrupted on channeled aura removal, don't need to interrupt here //caster->InterruptSpell(CURRENT_CHANNELED_SPELL); - p_caster->SetMover(nullptr); - + pPlayerCaster->SetMover(nullptr); caster->SetCharm(nullptr); caster->UpdateControl(); - // there is a possibility that target became invisible for client\p_caster at ResetView call: + // there is a possibility that target became invisible for client\pPlayerCaster at ResetView call: // it must be called after movement control unapplying, not before! the reason is same as at aura applying - p_caster->GetCamera().ResetView(); - p_caster->RemovePetActionBar(); + pPlayerCaster->GetCamera().ResetView(); + pPlayerCaster->RemovePetActionBar(); // on delete only do caster related effects if (m_removeMode == AURA_REMOVE_BY_DELETE) @@ -2930,6 +2925,11 @@ void Unit::ModPossess(Unit* target, bool apply, AuraRemoveMode m_removeMode) } } target->SetUnitMovementFlags(MOVEFLAG_NONE); + +#if SUPPORTED_CLIENT_BUILD <= CLIENT_BUILD_1_9_4 + if (pPlayerCaster && pPlayerTarget) + pPlayerTarget->SendCreateUpdateToPlayer(pPlayerCaster); +#endif } void Aura::HandleModPossessPet(bool apply, bool Real)