From 9f67a4f62d0d3e213e5e17de8af6281708aa6763 Mon Sep 17 00:00:00 2001 From: Edo Date: Sat, 24 Dec 2022 23:14:47 +0100 Subject: [PATCH] [Bots]: Add requested feature (#665) --- src/Components/Loader.cpp | 2 +- src/Components/Loader.hpp | 2 +- src/Components/Modules/Bots.cpp | 11 +++++++++++ src/Components/Modules/Bots.hpp | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index bf5e3a7d..74caf387 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -35,8 +35,8 @@ namespace Components Loader::Register(new Exception()); Loader::Register(new Auth()); Loader::Register(new Bans()); - Loader::Register(new Bots()); Loader::Register(new Dvar()); + Loader::Register(new Bots()); Loader::Register(new Lean()); Loader::Register(new Maps()); Loader::Register(new News()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 833168d0..b45931db 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -64,8 +64,8 @@ namespace Components #include "Modules/Scheduler.hpp" #include "Modules/Auth.hpp" #include "Modules/Bans.hpp" -#include "Modules/Bots.hpp" #include "Modules/Dvar.hpp" +#include "Modules/Bots.hpp" #include "Modules/Lean.hpp" #include "Modules/Maps.hpp" #include "Modules/News.hpp" diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index bd65eb50..ae85897b 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -5,6 +5,8 @@ namespace Components { std::vector Bots::BotNames; + Dvar::Var Bots::SVRandomBotNames; + struct BotMovementInfo { std::int32_t buttons; // Actions @@ -57,6 +59,13 @@ namespace Components { auto data = Utils::String::Split(bots.getBuffer(), '\n'); + if (SVRandomBotNames.get()) + { + std::random_device rd; + std::mt19937 gen(rd()); + std::ranges::shuffle(data, gen); + } + for (auto& entry : data) { // Take into account for CR line endings @@ -334,6 +343,8 @@ namespace Components Utils::Hook(0x441B80, G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick(); + SVRandomBotNames = Dvar::Register("sv_RandomBotNames", false, Game::DVAR_NONE, "Randomize the bots' names"); + // Reset BotMovementInfo.active when client is dropped Events::OnClientDisconnect([](const int clientNum) { diff --git a/src/Components/Modules/Bots.hpp b/src/Components/Modules/Bots.hpp index 1182f92f..f47f7a9a 100644 --- a/src/Components/Modules/Bots.hpp +++ b/src/Components/Modules/Bots.hpp @@ -11,6 +11,8 @@ namespace Components using botData = std::pair< std::string, std::string>; static std::vector BotNames; + static Dvar::Var SVRandomBotNames; + static int BuildConnectString(char* buffer, const char* connectString, int num, int, int protocol, int checksum, int statVer, int statStuff, int port); static void Spawn(unsigned int count);