From 936f9d4d93d62f27660ea8df936261d0f53a970a Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 20 Aug 2021 18:50:01 -0400 Subject: [PATCH] Core/Auras: added sanity checks for area auras having a different owner unit than caster Port From (https://github.com/TrinityCore/TrinityCore/commit/6c642f33b58ce81eb5b1345a7f0eb89de6040251) --- Source/Game/Spells/Auras/Aura.cs | 19 +++++++++++++++++-- Source/Game/Spells/SpellManager.cs | 7 +++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Source/Game/Spells/Auras/Aura.cs b/Source/Game/Spells/Auras/Aura.cs index 3a5100eed..a0de52a44 100644 --- a/Source/Game/Spells/Auras/Aura.cs +++ b/Source/Game/Spells/Auras/Aura.cs @@ -965,9 +965,21 @@ namespace Game.Spells return false; // Check if aura is single target, not only spell info - if (GetCasterGUID() != GetOwner().GetGUID() || IsSingleTarget()) - if (GetSpellInfo().IsSingleTarget()) + if (GetCasterGUID() != GetOwner().GetGUID()) + { + // owner == caster for area auras, check for possible bad data in DB + foreach (SpellEffectInfo effect in GetSpellInfo().GetEffects()) + { + if (effect == null || !effect.IsEffect()) + continue; + + if (effect.IsTargetingArea() || effect.IsAreaAuraEffect()) + return false; + } + + if (IsSingleTarget() || GetSpellInfo().IsSingleTarget()) return false; + } if (GetSpellInfo().HasAttribute(SpellCustomAttributes.AuraCannotBeSaved)) return false; @@ -2547,6 +2559,9 @@ namespace Game.Spells } else { + Cypher.Assert(caster != null, $"Area aura (Id: {GetSpellInfo().Id}) has nullptr caster ({GetCasterGUID()})"); + Cypher.Assert(GetCasterGUID() == GetUnitOwner().GetGUID(), $"Area aura (Id: {GetSpellInfo().Id}) has owner ({GetUnitOwner().GetGUID()}) different to caster ({GetCasterGUID()})"); + // skip area update if owner is not in world! if (!GetUnitOwner().IsInWorld) continue; diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index aac115777..f7c1b1d0a 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -2962,6 +2962,13 @@ namespace Game.Entities if (effect.TargetA.GetSelectionCategory() == SpellTargetSelectionCategories.Cone || effect.TargetB.GetSelectionCategory() == SpellTargetSelectionCategories.Cone) if (MathFunctions.fuzzyEq(spellInfo.ConeAngle, 0.0f)) spellInfo.ConeAngle = 90.0f; + + // Area auras may not target area (they're self cast) + if (effect.IsAreaAuraEffect() && effect.IsTargetingArea()) + { + effect.TargetA = new(Targets.UnitCaster); + effect.TargetB = new(); + } } // disable proc for magnet auras, they're handled differently