Scripts: Fix some crashes occuring due to unsafe use of AuraScript::GetCaster() method.

There's "returns unit which casted the aura or NULL if not avalible" written in description of the method, but who cares...
This commit is contained in:
QAston
2011-06-11 12:42:01 +02:00
parent 252ac95e1b
commit 677cbbb93a
12 changed files with 100 additions and 79 deletions
@@ -311,14 +311,13 @@ class spell_baltharus_enervating_brand : public SpellScriptLoader
void HandleTriggerSpell(AuraEffect const* aurEff) void HandleTriggerSpell(AuraEffect const* aurEff)
{ {
PreventDefaultAction(); PreventDefaultAction();
if (Unit* target = GetTarget()) Unit* target = GetTarget();
{
uint32 triggerSpellId = GetSpellProto()->EffectTriggerSpell[aurEff->GetEffIndex()]; uint32 triggerSpellId = GetSpellProto()->EffectTriggerSpell[aurEff->GetEffIndex()];
target->CastSpell(target, triggerSpellId, true); target->CastSpell(target, triggerSpellId, true);
if (target->GetDistance(GetCaster()) <= 12.0f) if (Unit * caster = GetCaster())
target->CastSpell(GetCaster(), SPELL_SIPHONED_MIGHT, true); if (target->GetDistance(caster) <= 12.0f)
} target->CastSpell(caster, SPELL_SIPHONED_MIGHT, true);
} }
void Register() void Register()
@@ -465,11 +465,12 @@ class spell_tyrannus_mark_of_rimefang : public SpellScriptLoader
void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/) void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{ {
if (!GetCaster() || GetCaster()->GetTypeId() != TYPEID_UNIT) Unit * caster = GetCaster();
if (!caster || caster->GetTypeId() != TYPEID_UNIT)
return; return;
if (InstanceScript* instance = GetCaster()->GetInstanceScript()) if (InstanceScript* instance = caster->GetInstanceScript())
if (Creature* rimefang = ObjectAccessor::GetCreature(*GetCaster(), instance->GetData64(DATA_RIMEFANG))) if (Creature* rimefang = ObjectAccessor::GetCreature(*caster, instance->GetData64(DATA_RIMEFANG)))
rimefang->AI()->SetGUID(GetTarget()->GetGUID(), GUID_HOARFROST); rimefang->AI()->SetGUID(GetTarget()->GetGUID(), GUID_HOARFROST);
} }
@@ -439,14 +439,17 @@ class spell_festergut_blighted_spores : public SpellScriptLoader
void ExtraEffect(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/) void ExtraEffect(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{ {
uint32 inoculatedId = sSpellMgr->GetSpellIdForDifficulty(SPELL_INOCULATED, GetCaster()); if (Unit * caster = GetCaster())
{
uint32 inoculatedId = sSpellMgr->GetSpellIdForDifficulty(SPELL_INOCULATED, caster);
uint32 currStack = 0; uint32 currStack = 0;
if (Aura const* inoculate = GetTarget()->GetAura(inoculatedId)) if (Aura const* inoculate = GetTarget()->GetAura(inoculatedId))
currStack = inoculate->GetStackAmount(); currStack = inoculate->GetStackAmount();
GetTarget()->CastSpell(GetTarget(), SPELL_INOCULATED, true); GetTarget()->CastSpell(GetTarget(), SPELL_INOCULATED, true);
++currStack; ++currStack;
GetCaster()->ToCreature()->AI()->SetData(DATA_INOCULATED_STACK, currStack); caster->ToCreature()->AI()->SetData(DATA_INOCULATED_STACK, currStack);
}
} }
void Register() void Register()
@@ -971,11 +971,13 @@ class spell_deathwhisper_mana_barrier : public SpellScriptLoader
void HandlePeriodicTick(AuraEffect const* /*aurEff*/) void HandlePeriodicTick(AuraEffect const* /*aurEff*/)
{ {
PreventDefaultAction(); PreventDefaultAction();
Unit* caster = GetCaster(); if (Unit* caster = GetCaster())
{
int32 missingHealth = int32(caster->GetMaxHealth() - caster->GetHealth()); int32 missingHealth = int32(caster->GetMaxHealth() - caster->GetHealth());
caster->ModifyHealth(missingHealth); caster->ModifyHealth(missingHealth);
caster->ModifyPower(POWER_MANA, -missingHealth); caster->ModifyPower(POWER_MANA, -missingHealth);
} }
}
void Register() void Register()
{ {
@@ -717,11 +717,13 @@ class spell_putricide_gaseous_bloat : public SpellScriptLoader
void HandleExtraEffect(AuraEffect const* /*aurEff*/) void HandleExtraEffect(AuraEffect const* /*aurEff*/)
{ {
Unit* target = GetTarget(); Unit* target = GetTarget();
Unit* caster = GetCaster(); if (Unit* caster = GetCaster())
{
target->RemoveAuraFromStack(GetSpellProto()->Id, GetCasterGUID()); target->RemoveAuraFromStack(GetSpellProto()->Id, GetCasterGUID());
if (!target->HasAura(GetId()) && caster && caster->GetTypeId() == TYPEID_UNIT) if (!target->HasAura(GetId())&& caster->GetTypeId() == TYPEID_UNIT)
caster->ToCreature()->DespawnOrUnsummon(); caster->ToCreature()->DespawnOrUnsummon();
} }
}
void Register() void Register()
{ {
@@ -671,7 +671,9 @@ class spell_malygos_vortex_visual : public SpellScriptLoader
void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/) void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{ {
std::list<HostileReference*> &m_threatlist = GetCaster()->getThreatManager().getThreatList(); if (Unit * caster = GetCaster())
{
std::list<HostileReference*> &m_threatlist = caster->getThreatManager().getThreatList();
for (std::list<HostileReference*>::const_iterator itr = m_threatlist.begin(); itr!= m_threatlist.end(); ++itr) for (std::list<HostileReference*>::const_iterator itr = m_threatlist.begin(); itr!= m_threatlist.end(); ++itr)
{ {
if (Unit* target = (*itr)->getTarget()) if (Unit* target = (*itr)->getTarget())
@@ -681,16 +683,16 @@ class spell_malygos_vortex_visual : public SpellScriptLoader
if (!targetPlayer || targetPlayer->isGameMaster()) if (!targetPlayer || targetPlayer->isGameMaster())
continue; continue;
if (InstanceScript* instance = GetCaster()->GetInstanceScript()) if (InstanceScript* instance = caster->GetInstanceScript())
{ {
// teleport spell - i am not sure but might be it must be casted by each vehicle when its passenger leaves it // teleport spell - i am not sure but might be it must be casted by each vehicle when its passenger leaves it
if (Creature* trigger = GetCaster()->GetMap()->GetCreature(instance->GetData64(DATA_TRIGGER))) if (Creature* trigger = caster->GetMap()->GetCreature(instance->GetData64(DATA_TRIGGER)))
trigger->CastSpell(targetPlayer, SPELL_VORTEX_6, true); trigger->CastSpell(targetPlayer, SPELL_VORTEX_6, true);
} }
} }
} }
if (Creature* malygos = GetCaster()->ToCreature()) if (Creature* malygos = caster->ToCreature())
{ {
// This is a hack, we have to re add players to the threat list because when they enter to the vehicles they are removed. // This is a hack, we have to re add players to the threat list because when they enter to the vehicles they are removed.
// Anyway even with this issue, the boss does not enter in evade mode - this prevents iterate an empty list in the next vortex execution. // Anyway even with this issue, the boss does not enter in evade mode - this prevents iterate an empty list in the next vortex execution.
@@ -698,9 +700,10 @@ class spell_malygos_vortex_visual : public SpellScriptLoader
malygos->RemoveUnitMovementFlag(MOVEMENTFLAG_LEVITATING); malygos->RemoveUnitMovementFlag(MOVEMENTFLAG_LEVITATING);
malygos->GetMotionMaster()->MoveChase(GetCaster()->getVictim()); malygos->GetMotionMaster()->MoveChase(caster->getVictim());
malygos->RemoveAura(SPELL_VORTEX_1); malygos->RemoveAura(SPELL_VORTEX_1);
} }
}
} }
@@ -254,8 +254,9 @@ class spell_eregos_planar_shift : public SpellScriptLoader
void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/) void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{ {
if (Creature* caster = GetCaster()->ToCreature()) if (Unit * caster = GetCaster())
caster->AI()->DoAction(ACTION_SET_NORMAL_EVENTS); if (Creature* creatureCaster = caster->ToCreature())
creatureCaster->AI()->DoAction(ACTION_SET_NORMAL_EVENTS);
} }
void Register() void Register()
@@ -244,27 +244,33 @@ class spell_varos_centrifuge_shield : public SpellScriptLoader
{ {
PrepareAuraScript(spell_varos_centrifuge_shield_AuraScript); PrepareAuraScript(spell_varos_centrifuge_shield_AuraScript);
bool Load()
{
Unit * caster = GetCaster();
return (caster && caster->ToCreature());
}
void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/) void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{ {
if (!GetCaster()->ToCreature()) if (Unit * caster = GetCaster())
return; {
// flags taken from sniffs // flags taken from sniffs
// UNIT_FLAG_UNK_9 -> means passive but it is not yet implemented in core // UNIT_FLAG_UNK_9 -> means passive but it is not yet implemented in core
if (GetCaster()->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_15|UNIT_FLAG_PASSIVE|UNIT_FLAG_OOC_NOT_ATTACKABLE|UNIT_FLAG_UNK_6)) if (caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_15|UNIT_FLAG_PASSIVE|UNIT_FLAG_OOC_NOT_ATTACKABLE|UNIT_FLAG_UNK_6))
{ {
GetCaster()->ToCreature()->SetReactState(REACT_PASSIVE); caster->ToCreature()->SetReactState(REACT_PASSIVE);
GetCaster()->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_15|UNIT_FLAG_PASSIVE|UNIT_FLAG_OOC_NOT_ATTACKABLE|UNIT_FLAG_UNK_6); caster->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_15|UNIT_FLAG_PASSIVE|UNIT_FLAG_OOC_NOT_ATTACKABLE|UNIT_FLAG_UNK_6);
}
} }
} }
void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/) void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{ {
if (!GetCaster()->ToCreature()) if (Unit * caster = GetCaster())
return; {
caster->ToCreature()->SetReactState(REACT_AGGRESSIVE);
GetCaster()->ToCreature()->SetReactState(REACT_AGGRESSIVE); caster->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_15|UNIT_FLAG_PASSIVE|UNIT_FLAG_OOC_NOT_ATTACKABLE|UNIT_FLAG_UNK_6);
GetCaster()->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_15|UNIT_FLAG_PASSIVE|UNIT_FLAG_OOC_NOT_ATTACKABLE|UNIT_FLAG_UNK_6); }
} }
void Register() void Register()
@@ -448,7 +448,8 @@ class spell_mark_of_the_faceless : public SpellScriptLoader
void HandleEffectPeriodic(AuraEffect const* aurEff) void HandleEffectPeriodic(AuraEffect const* aurEff)
{ {
GetCaster()->CastCustomSpell(SPELL_MARK_OF_THE_FACELESS_DAMAGE, SPELLVALUE_BASE_POINT1, aurEff->GetAmount(), GetTarget(), true); if (Unit * caster = GetCaster())
caster->CastCustomSpell(SPELL_MARK_OF_THE_FACELESS_DAMAGE, SPELLVALUE_BASE_POINT1, aurEff->GetAmount(), GetTarget(), true);
} }
void Register() void Register()
@@ -910,7 +910,7 @@ class spell_biting_cold : public SpellScriptLoader
Unit* target = GetTarget(); Unit* target = GetTarget();
bool found = false; bool found = false;
if (!caster || !target) if (!caster)
return; return;
for (TargetList::iterator itr = listOfTargets.begin(); itr != listOfTargets.end(); ++itr) for (TargetList::iterator itr = listOfTargets.begin(); itr != listOfTargets.end(); ++itr)
+6 -1
View File
@@ -363,12 +363,17 @@ public:
if (aurEff->GetAmount() > 0) if (aurEff->GetAmount() > 0)
return; return;
Unit * caster = GetCaster();
if (!caster)
return;
uint32 spellId = SPELL_SNIPER_TRAINING_BUFF_R1 + GetId() - SPELL_SNIPER_TRAINING_R1; uint32 spellId = SPELL_SNIPER_TRAINING_BUFF_R1 + GetId() - SPELL_SNIPER_TRAINING_R1;
Unit * pTarget = GetTarget(); Unit * pTarget = GetTarget();
if (!pTarget->HasAura(spellId)) if (!pTarget->HasAura(spellId))
{ {
SpellEntry const * triggeredSpellInfo = sSpellStore.LookupEntry(spellId); SpellEntry const * triggeredSpellInfo = sSpellStore.LookupEntry(spellId);
Unit* triggerCaster = GetTriggeredSpellCaster(triggeredSpellInfo, GetCaster(), pTarget); Unit* triggerCaster = GetTriggeredSpellCaster(triggeredSpellInfo, caster, pTarget);
triggerCaster->CastSpell(pTarget, triggeredSpellInfo, true, 0, aurEff); triggerCaster->CastSpell(pTarget, triggeredSpellInfo, true, 0, aurEff);
} }
} }
+1 -3
View File
@@ -644,8 +644,7 @@ public:
{ {
if (Unit* caster = GetCaster()) if (Unit* caster = GetCaster())
{ {
if (Unit* target = GetTarget()) Unit* target = GetTarget();
{
if (Player* player = caster->GetCharmerOrOwnerPlayerOrPlayerItself()) if (Player* player = caster->GetCharmerOrOwnerPlayerOrPlayerItself())
{ {
switch(target->GetEntry()) switch(target->GetEntry())
@@ -664,7 +663,6 @@ public:
} }
} }
} }
}
void Register() void Register()
{ {