Created
January 16, 2019 08:45
-
-
Save Langerz82/e35985d8c6c8282a714a1e5459c14825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp | |
index a831649589..4ee107eb3e 100644 | |
--- a/src/server/game/AI/SmartScripts/SmartAI.cpp | |
+++ b/src/server/game/AI/SmartScripts/SmartAI.cpp | |
@@ -609,6 +609,11 @@ void SmartAI::SpellHit(Unit* unit, SpellInfo const* spellInfo) | |
{ | |
GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, unit, 0, 0, false, spellInfo); | |
} | |
+void SmartAI::SpellHit(GameObject* caster, SpellInfo const* spellInfo) | |
+{ | |
+ GetScript()->ProcessEventsFor(SMART_EVENT_SPELLHIT, nullptr, 0, 0, false, spellInfo, caster); | |
+} | |
+ | |
void SmartAI::SpellHitTarget(Unit* target, SpellInfo const* spellInfo) | |
{ | |
diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h | |
index b96682564f..aef3ce994b 100644 | |
--- a/src/server/game/AI/SmartScripts/SmartAI.h | |
+++ b/src/server/game/AI/SmartScripts/SmartAI.h | |
@@ -102,6 +102,7 @@ class TC_GAME_API SmartAI : public CreatureAI | |
// Called when hit by a spell | |
void SpellHit(Unit* unit, SpellInfo const* spellInfo) override; | |
+ void SpellHit(GameObject* caster, SpellInfo const* spellInfo) override; | |
// Called when spell hits a target | |
void SpellHitTarget(Unit* target, SpellInfo const* spellInfo) override; | |
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp | |
index 6150dbb422..c224cf3bc4 100644 | |
--- a/src/server/game/Spells/Spell.cpp | |
+++ b/src/server/game/Spells/Spell.cpp | |
@@ -2352,9 +2352,17 @@ void Spell::TargetInfo::DoDamageAndTriggers(Spell* spell) | |
// Get original caster (if exist) and calculate damage/healing from him data | |
// Skip if m_originalCaster not available | |
- Unit* caster = spell->m_originalCaster ? spell->m_originalCaster : spell->m_caster->ToUnit(); | |
- if (!caster) | |
- return; | |
+ Unit* caster = NULL; | |
+ if (spell->m_caster->GetTypeId() == TYPEID_GAMEOBJECT) | |
+ { | |
+ if (!spell->m_caster->ToGameObject()) | |
+ return; | |
+ } | |
+ else { | |
+ caster = spell->m_originalCaster ? spell->m_originalCaster : spell->m_caster->ToUnit(); | |
+ if (!caster) | |
+ return; | |
+ } | |
// Fill base trigger info | |
uint32 procAttacker = spell->m_procAttacker; | |
@@ -2509,7 +2517,7 @@ void Spell::TargetInfo::DoDamageAndTriggers(Spell* spell) | |
Unit::ProcSkillsAndAuras(caster, spell->unitTarget, procAttacker, procVictim, procSpellType, PROC_SPELL_PHASE_HIT, hitMask, spell, spellDamageInfo.get(), healInfo.get()); | |
// item spells (spell hit of non-damage spell may also activate items, for example seal of corruption hidden hit) | |
- if (caster->GetTypeId() == TYPEID_PLAYER && (procSpellType & (PROC_SPELL_TYPE_DAMAGE | PROC_SPELL_TYPE_NO_DMG_HEAL))) | |
+ if (caster && caster->GetTypeId() == TYPEID_PLAYER && (procSpellType & (PROC_SPELL_TYPE_DAMAGE | PROC_SPELL_TYPE_NO_DMG_HEAL))) | |
{ | |
if (spell->m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MELEE || spell->m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_RANGED) | |
if (!spell->m_spellInfo->HasAttribute(SPELL_ATTR0_STOP_ATTACK_TARGET) && !spell->m_spellInfo->HasAttribute(SPELL_ATTR4_CANT_TRIGGER_ITEM_SPELLS)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this check is not needed as you are already checking GetTypeId() .
caster is dereferenced everywhere after the null check you removed, this code will trigger null dereference crashes