From 0726ac1602525dd0666539d4f9c92e0aeac029fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Borz=C3=AC?= Date: Tue, 3 Mar 2026 01:57:25 +0100 Subject: [PATCH] fix(Core/Scripts): missing null checks for GetCharmerOrOwner and GetOwner (#24902) --- src/server/game/AI/CoreAI/PetAI.cpp | 13 +++++++++---- src/server/scripts/Spells/spell_generic.cpp | 2 +- src/server/scripts/World/npcs_special.cpp | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp index 1c8222126..c251edc5b 100644 --- a/src/server/game/AI/CoreAI/PetAI.cpp +++ b/src/server/game/AI/CoreAI/PetAI.cpp @@ -746,10 +746,15 @@ bool PetAI::CanAttack(Unit* target, SpellInfo const* spellInfo) // Check if our owner selected this target and clicked "attack" Unit* ownerTarget = nullptr; - if (Player* owner = me->GetCharmerOrOwner()->ToPlayer()) - ownerTarget = owner->GetSelectedUnit(); - else - ownerTarget = me->GetCharmerOrOwner()->GetVictim(); + Unit* charmerOrOwner = me->GetCharmerOrOwner(); + + if (charmerOrOwner) + { + if (Player* owner = charmerOrOwner->ToPlayer()) + ownerTarget = owner->GetSelectedUnit(); + else + ownerTarget = charmerOrOwner->GetVictim(); + } if (ownerTarget && me->GetCharmInfo()->IsCommandAttack()) return (target->GetGUID() == ownerTarget->GetGUID()); diff --git a/src/server/scripts/Spells/spell_generic.cpp b/src/server/scripts/Spells/spell_generic.cpp index b81ec36f1..7b72cf252 100644 --- a/src/server/scripts/Spells/spell_generic.cpp +++ b/src/server/scripts/Spells/spell_generic.cpp @@ -2559,7 +2559,7 @@ class spell_gen_vehicle_scaling_aura: public AuraScript bool Load() override { - return GetCaster() && GetCaster()->IsPlayer() && GetOwner()->IsCreature(); + return GetCaster() && GetCaster()->IsPlayer() && GetOwner() && GetOwner()->IsCreature(); } void CalculateAmount(AuraEffect const* /*aurEff*/, int32& amount, bool& /*canBeRecalculated*/) diff --git a/src/server/scripts/World/npcs_special.cpp b/src/server/scripts/World/npcs_special.cpp index fa120635b..59405ce01 100644 --- a/src/server/scripts/World/npcs_special.cpp +++ b/src/server/scripts/World/npcs_special.cpp @@ -2674,7 +2674,8 @@ struct npc_controller : public PossessedAI { if (!apply) { - me->GetCharmerOrOwner()->InterruptNonMeleeSpells(false); + if (Unit* charmerOrOwner = me->GetCharmerOrOwner()) + charmerOrOwner->InterruptNonMeleeSpells(false); } } };