From 61c7488698d45b3a24d65acce822a7e9580edb49 Mon Sep 17 00:00:00 2001 From: Nefertumm Date: Sun, 21 Nov 2021 11:41:51 -0300 Subject: [PATCH] fix(Core/Spells): possible crashes within class spells (#9168) --- src/server/scripts/Spells/spell_dk.cpp | 6 +++--- src/server/scripts/Spells/spell_druid.cpp | 6 ++++++ src/server/scripts/Spells/spell_generic.cpp | 13 +++++++++---- src/server/scripts/Spells/spell_hunter.cpp | 17 +++++++++++------ src/server/scripts/Spells/spell_mage.cpp | 7 ++++++- src/server/scripts/Spells/spell_paladin.cpp | 13 ++++++++----- src/server/scripts/Spells/spell_shaman.cpp | 5 +++++ src/server/scripts/Spells/spell_warlock.cpp | 12 +++++++----- src/server/scripts/Spells/spell_warrior.cpp | 12 +++++++++++- 9 files changed, 66 insertions(+), 25 deletions(-) diff --git a/src/server/scripts/Spells/spell_dk.cpp b/src/server/scripts/Spells/spell_dk.cpp index b22bea6ff..3ebf87d33 100644 --- a/src/server/scripts/Spells/spell_dk.cpp +++ b/src/server/scripts/Spells/spell_dk.cpp @@ -444,7 +444,7 @@ class spell_dk_improved_blood_presence_proc : public AuraScript bool CheckProc(ProcEventInfo& eventInfo) { - return eventInfo.GetDamageInfo()->GetDamage(); + return eventInfo.GetDamageInfo() && eventInfo.GetDamageInfo()->GetDamage(); } void Register() override @@ -461,7 +461,7 @@ class spell_dk_wandering_plague_aura : public AuraScript bool CheckProc(ProcEventInfo& eventInfo) { const SpellInfo* spellInfo = eventInfo.GetSpellInfo(); - if (!spellInfo || !eventInfo.GetActionTarget() || !eventInfo.GetDamageInfo()) + if (!spellInfo || !eventInfo.GetActionTarget() || !eventInfo.GetDamageInfo() || !eventInfo.GetActor()) return false; if (!roll_chance_f(eventInfo.GetActor()->GetUnitCriticalChance(BASE_ATTACK, eventInfo.GetActionTarget()))) @@ -548,7 +548,7 @@ class spell_dk_blood_caked_blade : public AuraScript bool CheckProc(ProcEventInfo& eventInfo) { - return eventInfo.GetActionTarget() && eventInfo.GetActionTarget()->IsAlive(); + return eventInfo.GetActionTarget() && eventInfo.GetActionTarget()->IsAlive() && eventInfo.GetActor(); } void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo) diff --git a/src/server/scripts/Spells/spell_druid.cpp b/src/server/scripts/Spells/spell_druid.cpp index d92c54f12..45f741f52 100644 --- a/src/server/scripts/Spells/spell_druid.cpp +++ b/src/server/scripts/Spells/spell_druid.cpp @@ -601,6 +601,12 @@ class spell_dru_living_seed : public AuraScript void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo) { PreventDefaultAction(); + + if (!eventInfo.GetHealInfo() || !eventInfo.GetProcTarget()) + { + return; + } + int32 amount = CalculatePct(eventInfo.GetHealInfo()->GetHeal(), aurEff->GetAmount()); GetTarget()->CastCustomSpell(SPELL_DRUID_LIVING_SEED_PROC, SPELLVALUE_BASE_POINT0, amount, eventInfo.GetProcTarget(), true, nullptr, aurEff); } diff --git a/src/server/scripts/Spells/spell_generic.cpp b/src/server/scripts/Spells/spell_generic.cpp index 10c8f3157..451143fcc 100644 --- a/src/server/scripts/Spells/spell_generic.cpp +++ b/src/server/scripts/Spells/spell_generic.cpp @@ -743,11 +743,16 @@ class spell_gen_proc_once_per_cast : public AuraScript bool CheckProc(ProcEventInfo& eventInfo) { - if (Player* player = eventInfo.GetActor()->ToPlayer()) + if (eventInfo.GetActor()) { - if (player->m_spellModTakingSpell == _spellPointer) - return false; - _spellPointer = player->m_spellModTakingSpell; + if (Player* player = eventInfo.GetActor()->ToPlayer()) + { + if (player->m_spellModTakingSpell == _spellPointer) + { + return false; + } + _spellPointer = player->m_spellModTakingSpell; + } } return true; } diff --git a/src/server/scripts/Spells/spell_hunter.cpp b/src/server/scripts/Spells/spell_hunter.cpp index 9c26cfb8a..3214aa2b6 100644 --- a/src/server/scripts/Spells/spell_hunter.cpp +++ b/src/server/scripts/Spells/spell_hunter.cpp @@ -706,12 +706,17 @@ class spell_hun_sniper_training : public AuraScript PreventDefaultAction(); if (aurEff->GetAmount() <= 0) { - Unit* caster = GetCaster(); - uint32 spellId = SPELL_HUNTER_SNIPER_TRAINING_BUFF_R1 + GetId() - SPELL_HUNTER_SNIPER_TRAINING_R1; - if (Unit* target = GetTarget()) + if (!GetCaster() || !GetTarget()) { - SpellInfo const* triggeredSpellInfo = sSpellMgr->GetSpellInfo(spellId); - Unit* triggerCaster = triggeredSpellInfo->NeedsToBeTriggeredByCaster(GetSpellInfo()) ? caster : target; + return; + } + + Unit* target = GetTarget(); + + uint32 spellId = SPELL_HUNTER_SNIPER_TRAINING_BUFF_R1 + GetId() - SPELL_HUNTER_SNIPER_TRAINING_R1; + if (SpellInfo const* triggeredSpellInfo = sSpellMgr->GetSpellInfo(spellId)) + { + Unit* triggerCaster = triggeredSpellInfo->NeedsToBeTriggeredByCaster(GetSpellInfo()) ? GetCaster() : target; triggerCaster->CastSpell(target, triggeredSpellInfo, true, 0, aurEff); } } @@ -1119,7 +1124,7 @@ class spell_hun_lock_and_load : public AuraScript bool CheckTrapProc(ProcEventInfo& eventInfo) { SpellInfo const* spellInfo = eventInfo.GetSpellInfo(); - if (!spellInfo) + if (!spellInfo || !eventInfo.GetActor()) { return false; } diff --git a/src/server/scripts/Spells/spell_mage.cpp b/src/server/scripts/Spells/spell_mage.cpp index 40f9e3994..5c6253dc3 100644 --- a/src/server/scripts/Spells/spell_mage.cpp +++ b/src/server/scripts/Spells/spell_mage.cpp @@ -156,6 +156,11 @@ class spell_mage_molten_armor : public AuraScript if (!spellInfo || (eventInfo.GetTypeMask() & PROC_FLAG_TAKEN_MELEE_AUTO_ATTACK)) return true; + if (!eventInfo.GetActionTarget()) + { + return false; + } + // Xinef: Molten Shields talent if (AuraEffect* aurEff = eventInfo.GetActionTarget()->GetAuraEffect(SPELL_AURA_ADD_FLAT_MODIFIER, SPELLFAMILY_MAGE, 16, EFFECT_0)) return roll_chance_i(aurEff->GetSpellInfo()->GetRank() * 50); @@ -803,7 +808,7 @@ class spell_mage_master_of_elements : public AuraScript bool CheckProc(ProcEventInfo& eventInfo) { _spellInfo = eventInfo.GetSpellInfo(); - if (!_spellInfo) + if (!_spellInfo || !eventInfo.GetActor() || !eventInfo.GetActionTarget()) { return false; } diff --git a/src/server/scripts/Spells/spell_paladin.cpp b/src/server/scripts/Spells/spell_paladin.cpp index 7b58718db..0282ba7cc 100644 --- a/src/server/scripts/Spells/spell_paladin.cpp +++ b/src/server/scripts/Spells/spell_paladin.cpp @@ -94,6 +94,11 @@ class spell_pal_seal_of_command_aura : public AuraScript bool CheckProc(ProcEventInfo& eventInfo) { + if (!eventInfo.GetActor() || !eventInfo.GetActionTarget()) + { + return false; + } + if (const SpellInfo* procSpell = eventInfo.GetSpellInfo()) { if (procSpell->SpellIconID == 3025) // Righteous Vengeance, should not proc SoC @@ -117,12 +122,10 @@ class spell_pal_seal_of_command_aura : public AuraScript } } - if (Unit* target = eventInfo.GetActionTarget()) + Unit* target = eventInfo.GetActionTarget(); + if (target->IsAlive()) { - if (target->IsAlive()) - { - eventInfo.GetActor()->CastCustomSpell(aurEff->GetSpellInfo()->Effects[EFFECT_0].TriggerSpell, SPELLVALUE_MAX_TARGETS, targets, target, false, nullptr, aurEff); - } + eventInfo.GetActor()->CastCustomSpell(aurEff->GetSpellInfo()->Effects[EFFECT_0].TriggerSpell, SPELLVALUE_MAX_TARGETS, targets, target, false, nullptr, aurEff); } } diff --git a/src/server/scripts/Spells/spell_shaman.cpp b/src/server/scripts/Spells/spell_shaman.cpp index c944fae35..2d3ce14ca 100644 --- a/src/server/scripts/Spells/spell_shaman.cpp +++ b/src/server/scripts/Spells/spell_shaman.cpp @@ -658,6 +658,11 @@ class spell_sha_earthliving_weapon : public AuraScript { auto chance = 20; Unit* caster = eventInfo.GetActor(); + if (!caster || !eventInfo.GetProcTarget()) + { + return false; + } + if (AuraEffect const* aurEff = caster->GetAuraEffectOfRankedSpell(SPELL_SHAMAN_BLESSING_OF_THE_ETERNALS_R1, EFFECT_1, caster->GetGUID())) { if (eventInfo.GetProcTarget()->HasAuraState(AURA_STATE_HEALTHLESS_35_PERCENT)) diff --git a/src/server/scripts/Spells/spell_warlock.cpp b/src/server/scripts/Spells/spell_warlock.cpp index ed7ffb310..2d967be1a 100644 --- a/src/server/scripts/Spells/spell_warlock.cpp +++ b/src/server/scripts/Spells/spell_warlock.cpp @@ -1142,12 +1142,14 @@ class spell_warl_drain_soul : public AuraScript { PreventDefaultAction(); - Unit* caster = eventInfo.GetActor(); - // Improved Drain Soul. - if (Aura const* impDrainSoul = caster->GetAuraOfRankedSpell(SPELL_WARLOCK_IMPROVED_DRAIN_SOUL_R1, caster->GetGUID())) + if (Unit* caster = eventInfo.GetActor()) { - int32 amount = CalculatePct(caster->GetMaxPower(POWER_MANA), impDrainSoul->GetSpellInfo()->Effects[EFFECT_2].CalcValue()); - caster->CastCustomSpell(SPELL_WARLOCK_IMPROVED_DRAIN_SOUL_PROC, SPELLVALUE_BASE_POINT0, amount, caster, true, nullptr, aurEff, caster->GetGUID()); + // Improved Drain Soul. + if (Aura const* impDrainSoul = caster->GetAuraOfRankedSpell(SPELL_WARLOCK_IMPROVED_DRAIN_SOUL_R1, caster->GetGUID())) + { + int32 amount = CalculatePct(caster->GetMaxPower(POWER_MANA), impDrainSoul->GetSpellInfo()->Effects[EFFECT_2].CalcValue()); + caster->CastCustomSpell(SPELL_WARLOCK_IMPROVED_DRAIN_SOUL_PROC, SPELLVALUE_BASE_POINT0, amount, caster, true, nullptr, aurEff, caster->GetGUID()); + } } } diff --git a/src/server/scripts/Spells/spell_warrior.cpp b/src/server/scripts/Spells/spell_warrior.cpp index 271f48eee..ee94beb4c 100644 --- a/src/server/scripts/Spells/spell_warrior.cpp +++ b/src/server/scripts/Spells/spell_warrior.cpp @@ -150,7 +150,7 @@ class spell_warr_improved_spell_reflection : public AuraScript bool CheckProc(ProcEventInfo& eventInfo) { - return eventInfo.GetSpellInfo() && eventInfo.GetSpellInfo()->Id == SPELL_WARRIOR_SPELL_REFLECTION; + return eventInfo.GetSpellInfo() && eventInfo.GetActor() && eventInfo.GetSpellInfo()->Id == SPELL_WARRIOR_SPELL_REFLECTION; } void OnProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo) @@ -623,6 +623,11 @@ class spell_warr_sweeping_strikes : public AuraScript bool CheckProc(ProcEventInfo& eventInfo) { + if (!eventInfo.GetActor() || eventInfo.GetProcTarget()) + { + return false; + } + _procTarget = eventInfo.GetActor()->SelectNearbyNoTotemTarget(eventInfo.GetProcTarget()); DamageInfo* damageInfo = eventInfo.GetDamageInfo(); @@ -801,6 +806,11 @@ class spell_warr_retaliation : public AuraScript bool CheckProc(ProcEventInfo& eventInfo) { + if (!eventInfo.GetActor() || !eventInfo.GetProcTarget()) + { + return false; + } + // check attack comes not from behind and warrior is not stunned return GetTarget()->isInFront(eventInfo.GetActor(), M_PI) && !GetTarget()->HasUnitState(UNIT_STATE_STUNNED); }