From 2e0a161623eaa97b7d9ceea076779ae0cabeb877 Mon Sep 17 00:00:00 2001 From: Alex Dcnh <140754794+Wishmaster117@users.noreply.github.com> Date: Mon, 11 Aug 2025 16:27:38 +0200 Subject: [PATCH] =?UTF-8?q?[Fix=20issue=20#1528]=20Close=20small=20window?= =?UTF-8?q?=20where=20the=20=E2=80=9Cin=20a=20BG/arena=E2=80=9D=20state=20?= =?UTF-8?q?can=20change=20between=20the=20check=20(InBattleground()=20/=20?= =?UTF-8?q?InArena())=20and=20grabbing=20the=20pointer=20(GetBattleground(?= =?UTF-8?q?)),=20which=20leads=20to=20a=20null=20dereference.=20(#1530)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Harden playerbot logout & packet dispatch; add null-safety in chat hooks and RPG checks * Fix Issue 1528 --- src/RandomPlayerbotMgr.cpp | 54 +++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 658e43d3..def80972 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -994,9 +994,18 @@ void RandomPlayerbotMgr::CheckBgQueue() isRated = ginfo.IsRated; } - if (bgQueue.IsPlayerInvitedToRatedArena(player->GetGUID()) || + /*if (bgQueue.IsPlayerInvitedToRatedArena(player->GetGUID()) || (player->InArena() && player->GetBattleground()->isRated())) + isRated = true;*/ + if (bgQueue.IsPlayerInvitedToRatedArena(player->GetGUID())) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528 + { isRated = true; + } + else if (Battleground const* bg = player->GetBattleground()) + { + if (player->InArena() && bg->isRated()) + isRated = true; + } if (isRated) BattlegroundData[queueTypeId][bracketId].ratedArenaPlayerCount++; @@ -1011,15 +1020,24 @@ void RandomPlayerbotMgr::CheckBgQueue() else BattlegroundData[queueTypeId][bracketId].bgHordePlayerCount++; - // If a player has joined the BG, update the instance count in BattlegroundData (for consistency) + /*// If a player has joined the BG, update the instance count in BattlegroundData (for consistency) if (player->InBattleground()) { std::vector* instanceIds = nullptr; uint32 instanceId = player->GetBattleground()->GetInstanceID(); - instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances; - if (instanceIds && + instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances;*/ + // If a player has joined the BG, update the instance count in BattlegroundData (for consistency) + if (Battleground const* bg = player->GetBattleground()) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528 + { + std::vector* instanceIds = nullptr; + uint32 instanceId = bg->GetInstanceID(); + + instanceIds = &BattlegroundData[queueTypeId][bracketId].bgInstances; + + if (instanceIds && std::find(instanceIds->begin(), instanceIds->end(), instanceId) == instanceIds->end()) + instanceIds->push_back(instanceId); BattlegroundData[queueTypeId][bracketId].bgInstanceCount = instanceIds->size(); @@ -1082,10 +1100,20 @@ void RandomPlayerbotMgr::CheckBgQueue() isRated = ginfo.IsRated; } - if (bgQueue.IsPlayerInvitedToRatedArena(guid) || (bot->InArena() && bot->GetBattleground()->isRated())) + /*if (bgQueue.IsPlayerInvitedToRatedArena(guid) || (bot->InArena() && bot->GetBattleground()->isRated())) + isRated = true;*/ + if (bgQueue.IsPlayerInvitedToRatedArena(guid)) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528 + { isRated = true; - - if (isRated) + } + else if (Battleground const* bg = bot->GetBattleground()) + { + if (bot->InArena() && bg->isRated()) + isRated = true; + } + // END [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528 + + if (isRated) BattlegroundData[queueTypeId][bracketId].ratedArenaBotCount++; else BattlegroundData[queueTypeId][bracketId].skirmishArenaBotCount++; @@ -1098,10 +1126,15 @@ void RandomPlayerbotMgr::CheckBgQueue() BattlegroundData[queueTypeId][bracketId].bgHordeBotCount++; } - if (bot->InBattleground()) + /*if (bot->InBattleground()) { std::vector* instanceIds = nullptr; - uint32 instanceId = bot->GetBattleground()->GetInstanceID(); + uint32 instanceId = bot->GetBattleground()->GetInstanceID();*/ + if (Battleground const* bg = bot->GetBattleground()) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528 + { + std::vector* instanceIds = nullptr; + uint32 instanceId = bg->GetInstanceID(); + //END [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528 bool isArena = false; bool isRated = false; @@ -1109,7 +1142,8 @@ void RandomPlayerbotMgr::CheckBgQueue() if (bot->InArena()) { isArena = true; - if (bot->GetBattleground()->isRated()) + // if (bot->GetBattleground()->isRated()) + if (bg->isRated()) // [Crash Fix] Issue Crash in RandomPlayerbotMgr:1018 #1528 { isRated = true; instanceIds = &BattlegroundData[queueTypeId][bracketId].ratedArenaInstances;