From 7f9214a64f116fdce9c28377fb1e6fe95cf26d51 Mon Sep 17 00:00:00 2001 From: WinterSolstice8 <60417494+wintersolstice8@users.noreply.github.com> Date: Mon, 4 May 2026 10:38:03 -0600 Subject: [PATCH] [core] Adjust some logic for BST pets causing heap corruption --- src/map/ai/controllers/pet_controller.cpp | 41 ++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/map/ai/controllers/pet_controller.cpp b/src/map/ai/controllers/pet_controller.cpp index 6c00181be64..5b2a2ebb459 100644 --- a/src/map/ai/controllers/pet_controller.cpp +++ b/src/map/ai/controllers/pet_controller.cpp @@ -95,28 +95,39 @@ auto CPetController::DoRoamTick(timer::time_point tick) -> Task if (PPet->objtype == TYPE_PET || (PPet->objtype == TYPE_MOB && PPet->PMaster && PPet->PMaster->objtype == TYPE_PC)) { - CPetEntity* PetEntity = static_cast(PPet); - // automaton, wyvern - if (PetEntity->getPetType() == PET_TYPE::WYVERN || PetEntity->getPetType() == PET_TYPE::AUTOMATON) + bool isBstPet = false; + + CPetEntity* PetEntity = dynamic_cast(PPet); + if (PetEntity) { - if (PetIsHealing()) + isBstPet = PetEntity->isBstPet(); + // automaton, wyvern + if (PetEntity->getPetType() == PET_TYPE::WYVERN || PetEntity->getPetType() == PET_TYPE::AUTOMATON) { - co_return; + if (PetIsHealing()) + { + co_return; + } } - } - else if (PetEntity->isBstPet() && PPet->StatusEffectContainer->GetStatusEffect(EFFECT_HEALING)) - { - co_return; - } - else if (PetEntity->m_PetID == PETID_LIGHTSPIRIT) // Only Light Spirit will cast on roam tick - { - // this will respect the pet's mob casting cooldown properties via MOBMOD_MAGIC_COOL - if (CMobController::IsSpellReady(0) && CMobController::TryCastSpell()) + else if (PetEntity->m_PetID == PETID_LIGHTSPIRIT) // Only Light Spirit will cast on roam tick + { + // this will respect the pet's mob casting cooldown properties via MOBMOD_MAGIC_COOL + if (CMobController::IsSpellReady(0) && CMobController::TryCastSpell()) + { + co_return; + } + } + else if (immobilePets.contains(static_cast(PetEntity->m_PetID))) // certain pets do not roam { co_return; } } - else if (immobilePets.contains(static_cast(PetEntity->m_PetID))) // certain pets do not roam + else + { + isBstPet = true; + } + + if (isBstPet && PPet->StatusEffectContainer->GetStatusEffect(EFFECT_HEALING)) { co_return; }