From 09b5a9f1d856d885d4621076fe3723c2fea98422 Mon Sep 17 00:00:00 2001 From: mostlikely4r Date: Wed, 2 Oct 2024 11:30:03 +0200 Subject: [PATCH] -Bg crash fix: Fixes crash when bots join a bg from another bg. --- .../strategy/actions/BattleGroundJoinAction.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/playerbot/strategy/actions/BattleGroundJoinAction.cpp b/playerbot/strategy/actions/BattleGroundJoinAction.cpp index 6e287c64..4b945bb7 100644 --- a/playerbot/strategy/actions/BattleGroundJoinAction.cpp +++ b/playerbot/strategy/actions/BattleGroundJoinAction.cpp @@ -1483,6 +1483,18 @@ bool BGStatusAction::Execute(Event& event) packet << type << unk2 << (uint32)_bgTypeId << unk << action; #endif + if (bot->InBattleGround() && bot->GetBattleGroundTypeId() != _bgTypeId) + { + //We are already in a BG. Joining a new one directly causes a crash when SetBattleGroundId is reset during leave right before teleporting in the new one. + //Here we leave the current BG proper so we can join the next fresh. + WorldPacket leave(CMSG_LEAVE_BATTLEFIELD); + leave << uint8(0) << uint8(0) << uint32(0) << uint16(0); + bot->GetSession()->HandleLeaveBattlefieldOpcode(leave); + //Queue the event again to try to join next tick. + ai->HandleBotOutgoingPacket(event.getPacket()); + return true; + } + bot->GetSession()->HandleBattlefieldPortOpcode(packet); ai->ResetStrategies(false);