From 35228f6d9bb0f56d4f3d84b7d39425ed62d3061f Mon Sep 17 00:00:00 2001 From: Ramok <63268168+ramok0@users.noreply.github.com> Date: Fri, 30 May 2025 14:26:24 +0200 Subject: [PATCH] crashfix: prevent division by zero when spawning too many bots --- Project Reboot 3.0/botnames.h | 2 ++ Project Reboot 3.0/bots.h | 12 +++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Project Reboot 3.0/botnames.h b/Project Reboot 3.0/botnames.h index 1526425..e55d7c8 100644 --- a/Project Reboot 3.0/botnames.h +++ b/Project Reboot 3.0/botnames.h @@ -69,4 +69,6 @@ static inline void InitBotNames() PlayerBotNames.push_back(L"AllyJax"); PlayerBotNames.push_back(L"secret_pommes"); PlayerBotNames.push_back(L"Twin1"); + + std::shuffle(PlayerBotNames.begin(), PlayerBotNames.end(), std::default_random_engine((unsigned int)time(0))); } diff --git a/Project Reboot 3.0/bots.h b/Project Reboot 3.0/bots.h index c8423dd..ab600d7 100644 --- a/Project Reboot 3.0/bots.h +++ b/Project Reboot 3.0/bots.h @@ -232,21 +232,15 @@ public: } else { - if (Fortnite_Version < 11) + if (Fortnite_Version < 11 || PlayerBotNames.empty()) { BotNumWStr = std::to_wstring(CurrentBotNum++ + 200); NewName = (std::format(L"Anonymous[{}]", BotNumWStr)).c_str(); } else { - if (!PlayerBotNames.empty()) - { - // std::shuffle(PlayerBotNames.begin(), PlayerBotNames.end(), std::default_random_engine((unsigned int)time(0))); - - int RandomIndex = std::rand() % (PlayerBotNames.size() - 1); - NewName = PlayerBotNames[RandomIndex]; - PlayerBotNames.erase(PlayerBotNames.begin() + RandomIndex); - } + NewName = PlayerBotNames.back(); + PlayerBotNames.pop_back(); } }