From 5fc74508e308be625a312cf558fe4e6d8d5e28fb Mon Sep 17 00:00:00 2001 From: Treeston Date: Mon, 15 Jan 2018 15:42:41 +0100 Subject: [PATCH] Core/Threat: Fix a potential crash that would occur in specific edge cases of AI being a bit naughty. --- src/server/game/Combat/CombatManager.cpp | 2 +- src/server/game/Combat/ThreatManager.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/server/game/Combat/CombatManager.cpp b/src/server/game/Combat/CombatManager.cpp index 956b86daf8a..de290610113 100644 --- a/src/server/game/Combat/CombatManager.cpp +++ b/src/server/game/Combat/CombatManager.cpp @@ -202,7 +202,7 @@ bool CombatManager::SetInCombatWith(Unit* who) NotifyAICombat(_owner, who); if (needOtherAI) NotifyAICombat(who, _owner); - return true; + return IsInCombatWith(who); } bool CombatManager::IsInCombatWith(ObjectGuid const& guid) const diff --git a/src/server/game/Combat/ThreatManager.cpp b/src/server/game/Combat/ThreatManager.cpp index 622931ad828..6b30229216c 100644 --- a/src/server/game/Combat/ThreatManager.cpp +++ b/src/server/game/Combat/ThreatManager.cpp @@ -354,6 +354,10 @@ void ThreatManager::AddThreat(Unit* target, float amount, SpellInfo const* spell } } + // ensure we're in combat (threat implies combat!) + if (!_owner->GetCombatManager().SetInCombatWith(target)) // if this returns false, we're not actually in combat, and thus cannot have threat! + return; // typical causes: bad scripts trying to add threat to GMs, dead targets etc + // ok, now we actually apply threat // check if we already have an entry - if we do, just increase threat for that entry and we're done auto it = _myThreatListEntries.find(target->GetGUID()); @@ -363,10 +367,6 @@ void ThreatManager::AddThreat(Unit* target, float amount, SpellInfo const* spell return; } - // otherwise, ensure we're in combat (threat implies combat!) - if (!_owner->GetCombatManager().SetInCombatWith(target)) // if this returns false, we're not actually in combat, and thus cannot have threat! - return; // typical causes: bad scripts trying to add threat to GMs, dead targets etc - // ok, we're now in combat - create the threat list reference and push it to the respective managers ThreatReference* ref = new ThreatReference(this, target, amount); PutThreatListRef(target->GetGUID(), ref);