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)
{
PreventDefaultAction();
if (Unit* target = GetTarget())
{
uint32 triggerSpellId = GetSpellProto()->EffectTriggerSpell[aurEff->GetEffIndex()];
target->CastSpell(target, triggerSpellId, true);
Unit* target = GetTarget();
uint32 triggerSpellId = GetSpellProto()->EffectTriggerSpell[aurEff->GetEffIndex()];
target->CastSpell(target, triggerSpellId, true);
if (target->GetDistance(GetCaster()) <= 12.0f)
target->CastSpell(GetCaster(), SPELL_SIPHONED_MIGHT, true);
}
if (Unit * caster = GetCaster())
if (target->GetDistance(caster) <= 12.0f)
target->CastSpell(caster, SPELL_SIPHONED_MIGHT, true);
}
void Register()
@@ -465,11 +465,12 @@ class spell_tyrannus_mark_of_rimefang : public SpellScriptLoader
void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
if (!GetCaster() || GetCaster()->GetTypeId() != TYPEID_UNIT)
Unit * caster = GetCaster();
if (!caster || caster->GetTypeId() != TYPEID_UNIT)
return;
if (InstanceScript* instance = GetCaster()->GetInstanceScript())
if (Creature* rimefang = ObjectAccessor::GetCreature(*GetCaster(), instance->GetData64(DATA_RIMEFANG)))
if (InstanceScript* instance = caster->GetInstanceScript())
if (Creature* rimefang = ObjectAccessor::GetCreature(*caster, instance->GetData64(DATA_RIMEFANG)))
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*/)
{
uint32 inoculatedId = sSpellMgr->GetSpellIdForDifficulty(SPELL_INOCULATED, GetCaster());
uint32 currStack = 0;
if (Aura const* inoculate = GetTarget()->GetAura(inoculatedId))
currStack = inoculate->GetStackAmount();
if (Unit * caster = GetCaster())
{
uint32 inoculatedId = sSpellMgr->GetSpellIdForDifficulty(SPELL_INOCULATED, caster);
uint32 currStack = 0;
if (Aura const* inoculate = GetTarget()->GetAura(inoculatedId))
currStack = inoculate->GetStackAmount();
GetTarget()->CastSpell(GetTarget(), SPELL_INOCULATED, true);
++currStack;
GetCaster()->ToCreature()->AI()->SetData(DATA_INOCULATED_STACK, currStack);
GetTarget()->CastSpell(GetTarget(), SPELL_INOCULATED, true);
++currStack;
caster->ToCreature()->AI()->SetData(DATA_INOCULATED_STACK, currStack);
}
}
void Register()
@@ -971,10 +971,12 @@ class spell_deathwhisper_mana_barrier : public SpellScriptLoader
void HandlePeriodicTick(AuraEffect const* /*aurEff*/)
{
PreventDefaultAction();
Unit* caster = GetCaster();
int32 missingHealth = int32(caster->GetMaxHealth() - caster->GetHealth());
caster->ModifyHealth(missingHealth);
caster->ModifyPower(POWER_MANA, -missingHealth);
if (Unit* caster = GetCaster())
{
int32 missingHealth = int32(caster->GetMaxHealth() - caster->GetHealth());
caster->ModifyHealth(missingHealth);
caster->ModifyPower(POWER_MANA, -missingHealth);
}
}
void Register()
@@ -717,10 +717,12 @@ class spell_putricide_gaseous_bloat : public SpellScriptLoader
void HandleExtraEffect(AuraEffect const* /*aurEff*/)
{
Unit* target = GetTarget();
Unit* caster = GetCaster();
target->RemoveAuraFromStack(GetSpellProto()->Id, GetCasterGUID());
if (!target->HasAura(GetId()) && caster && caster->GetTypeId() == TYPEID_UNIT)
caster->ToCreature()->DespawnOrUnsummon();
if (Unit* caster = GetCaster())
{
target->RemoveAuraFromStack(GetSpellProto()->Id, GetCasterGUID());
if (!target->HasAura(GetId())&& caster->GetTypeId() == TYPEID_UNIT)
caster->ToCreature()->DespawnOrUnsummon();
}
}
void Register()
@@ -671,35 +671,38 @@ class spell_malygos_vortex_visual : public SpellScriptLoader
void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
std::list<HostileReference*> &m_threatlist = GetCaster()->getThreatManager().getThreatList();
for (std::list<HostileReference*>::const_iterator itr = m_threatlist.begin(); itr!= m_threatlist.end(); ++itr)
if (Unit * caster = GetCaster())
{
if (Unit* target = (*itr)->getTarget())
std::list<HostileReference*> &m_threatlist = caster->getThreatManager().getThreatList();
for (std::list<HostileReference*>::const_iterator itr = m_threatlist.begin(); itr!= m_threatlist.end(); ++itr)
{
Player* targetPlayer = target->ToPlayer();
if (!targetPlayer || targetPlayer->isGameMaster())
continue;
if (InstanceScript* instance = GetCaster()->GetInstanceScript())
if (Unit* target = (*itr)->getTarget())
{
// 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)))
trigger->CastSpell(targetPlayer, SPELL_VORTEX_6, true);
Player* targetPlayer = target->ToPlayer();
if (!targetPlayer || targetPlayer->isGameMaster())
continue;
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
if (Creature* trigger = caster->GetMap()->GetCreature(instance->GetData64(DATA_TRIGGER)))
trigger->CastSpell(targetPlayer, SPELL_VORTEX_6, true);
}
}
}
}
if (Creature* malygos = GetCaster()->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.
// Anyway even with this issue, the boss does not enter in evade mode - this prevents iterate an empty list in the next vortex execution.
malygos->SetInCombatWithZone();
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.
// Anyway even with this issue, the boss does not enter in evade mode - this prevents iterate an empty list in the next vortex execution.
malygos->SetInCombatWithZone();
malygos->RemoveUnitMovementFlag(MOVEMENTFLAG_LEVITATING);
malygos->RemoveUnitMovementFlag(MOVEMENTFLAG_LEVITATING);
malygos->GetMotionMaster()->MoveChase(GetCaster()->getVictim());
malygos->RemoveAura(SPELL_VORTEX_1);
malygos->GetMotionMaster()->MoveChase(caster->getVictim());
malygos->RemoveAura(SPELL_VORTEX_1);
}
}
}
@@ -254,8 +254,9 @@ class spell_eregos_planar_shift : public SpellScriptLoader
void OnRemove(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
if (Creature* caster = GetCaster()->ToCreature())
caster->AI()->DoAction(ACTION_SET_NORMAL_EVENTS);
if (Unit * caster = GetCaster())
if (Creature* creatureCaster = caster->ToCreature())
creatureCaster->AI()->DoAction(ACTION_SET_NORMAL_EVENTS);
}
void Register()
@@ -244,27 +244,33 @@ class spell_varos_centrifuge_shield : public SpellScriptLoader
{
PrepareAuraScript(spell_varos_centrifuge_shield_AuraScript);
bool Load()
{
Unit * caster = GetCaster();
return (caster && caster->ToCreature());
}
void OnApply(AuraEffect const* /*aurEff*/, AuraEffectHandleModes /*mode*/)
{
if (!GetCaster()->ToCreature())
return;
// flags taken from sniffs
// 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 (Unit * caster = GetCaster())
{
GetCaster()->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);
// flags taken from sniffs
// UNIT_FLAG_UNK_9 -> means passive but it is not yet implemented in core
if (caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_15|UNIT_FLAG_PASSIVE|UNIT_FLAG_OOC_NOT_ATTACKABLE|UNIT_FLAG_UNK_6))
{
caster->ToCreature()->SetReactState(REACT_PASSIVE);
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*/)
{
if (!GetCaster()->ToCreature())
return;
GetCaster()->ToCreature()->SetReactState(REACT_AGGRESSIVE);
GetCaster()->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_15|UNIT_FLAG_PASSIVE|UNIT_FLAG_OOC_NOT_ATTACKABLE|UNIT_FLAG_UNK_6);
if (Unit * caster = GetCaster())
{
caster->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);
}
}
void Register()
@@ -448,7 +448,8 @@ class spell_mark_of_the_faceless : public SpellScriptLoader
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()
@@ -910,7 +910,7 @@ class spell_biting_cold : public SpellScriptLoader
Unit* target = GetTarget();
bool found = false;
if (!caster || !target)
if (!caster)
return;
for (TargetList::iterator itr = listOfTargets.begin(); itr != listOfTargets.end(); ++itr)
+6 -1
View File
@@ -363,12 +363,17 @@ public:
if (aurEff->GetAmount() > 0)
return;
Unit * caster = GetCaster();
if (!caster)
return;
uint32 spellId = SPELL_SNIPER_TRAINING_BUFF_R1 + GetId() - SPELL_SNIPER_TRAINING_R1;
Unit * pTarget = GetTarget();
if (!pTarget->HasAura(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);
}
}
+13 -15
View File
@@ -644,23 +644,21 @@ public:
{
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())
{
case NPC_FROSTWORG:
target->CastSpell(player, SPELL_FROSTWORG_CREDIT, true);
target->CastSpell(target, SPELL_IMMOLATION, true);
target->CastSpell(target, SPELL_ABLAZE, true);
break;
case NPC_FROSTGIANT:
target->CastSpell(player, SPELL_FROSTGIANT_CREDIT, true);
target->CastSpell(target, SPELL_IMMOLATION, true);
target->CastSpell(target, SPELL_ABLAZE, true);
break;
}
case NPC_FROSTWORG:
target->CastSpell(player, SPELL_FROSTWORG_CREDIT, true);
target->CastSpell(target, SPELL_IMMOLATION, true);
target->CastSpell(target, SPELL_ABLAZE, true);
break;
case NPC_FROSTGIANT:
target->CastSpell(player, SPELL_FROSTGIANT_CREDIT, true);
target->CastSpell(target, SPELL_IMMOLATION, true);
target->CastSpell(target, SPELL_ABLAZE, true);
break;
}
}
}