From e9debbd4f5a0bea99bc05b837acc768048675df9 Mon Sep 17 00:00:00 2001 From: ineed bots Date: Tue, 5 Dec 2023 17:34:33 -0600 Subject: [PATCH] Address comments --- src/Components/Modules/Bots.cpp | 26 +++++++++++--------- src/Components/Modules/GSC/IO.cpp | 4 +-- src/Components/Modules/GSC/ScriptStorage.cpp | 4 +-- src/Game/Script.hpp | 2 ++ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index 43ce6ef7..0d2e07b6 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -301,8 +301,10 @@ namespace Components return; } + auto clientNum = cl - Game::svs_clients; + // Keep test client functionality - if (!g_botai[cl - Game::svs_clients].active) + if (!g_botai[clientNum].active) { Game::SV_BotUserMove(cl); return; @@ -313,11 +315,11 @@ namespace Components userCmd.serverTime = *Game::svs_time; - userCmd.buttons = g_botai[cl - Game::svs_clients].buttons; - userCmd.forwardmove = g_botai[cl - Game::svs_clients].forward; - userCmd.rightmove = g_botai[cl - Game::svs_clients].right; - userCmd.weapon = g_botai[cl - Game::svs_clients].weapon; - userCmd.primaryWeaponForAltMode = g_botai[cl - Game::svs_clients].lastAltWeapon; + userCmd.buttons = g_botai[clientNum].buttons; + userCmd.forwardmove = g_botai[clientNum].forward; + userCmd.rightmove = g_botai[clientNum].right; + userCmd.weapon = g_botai[clientNum].weapon; + userCmd.primaryWeaponForAltMode = g_botai[clientNum].lastAltWeapon; userCmd.angles[0] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[0] - cl->gentity->client->ps.delta_angles[0])); userCmd.angles[1] = ANGLE2SHORT((cl->gentity->client->ps.viewangles[1] - cl->gentity->client->ps.delta_angles[1])); @@ -350,21 +352,21 @@ namespace Components auto* def = Game::BG_GetWeaponCompleteDef(iWeaponIndex); - if (def->weapDef->inventoryType == Game::WEAPINVENTORY_ALTMODE) + if (def && def->weapDef->inventoryType == Game::WEAPINVENTORY_ALTMODE) { auto* ps = &Game::g_entities[clientNum].client->ps; - auto num_weaps = Game::BG_GetNumWeapons(); + auto numWeaps = Game::BG_GetNumWeapons(); - for (auto i = 1u; i < num_weaps; i++) + for (auto i = 1u; i < numWeaps; i++) { if (!Game::BG_PlayerHasWeapon(ps, i)) { continue; } - auto* this_def = Game::BG_GetWeaponCompleteDef(i); + auto* thisDef = Game::BG_GetWeaponCompleteDef(i); - if (this_def->altWeaponIndex != iWeaponIndex) + if (!thisDef || thisDef->altWeaponIndex != iWeaponIndex) { continue; } @@ -523,7 +525,7 @@ namespace Components Utils::Hook(0x441B80, G_SelectWeaponIndex_Hk, HOOK_JUMP).install()->quick(); - // fix bots using objects + // fix bots using objects (SV_IsClientBot) Utils::Hook(0x4D79C5, Player_UpdateActivate_stub, HOOK_CALL).install()->quick(); Utils::Hook(0x459654, SV_GetClientPing_Hk, HOOK_CALL).install()->quick(); diff --git a/src/Components/Modules/GSC/IO.cpp b/src/Components/Modules/GSC/IO.cpp index 0843fe2e..7d866434 100644 --- a/src/Components/Modules/GSC/IO.cpp +++ b/src/Components/Modules/GSC/IO.cpp @@ -33,9 +33,9 @@ namespace Components::GSC // check if we need to append scriptdata folder, for backwards compat std::string spath = path; - if (!spath.starts_with("scriptdata/") && !spath.starts_with("scriptdata\\")) + if (!spath.starts_with(Game::SCRIPTDATA_DIR + "/"s) && !spath.starts_with(Game::SCRIPTDATA_DIR + "\\"s)) { - spath = "scriptdata/" + spath; + spath = Game::SCRIPTDATA_DIR + "/"s + spath; } if (!fsGame.empty()) diff --git a/src/Components/Modules/GSC/ScriptStorage.cpp b/src/Components/Modules/GSC/ScriptStorage.cpp index 672a599c..326b1ce5 100644 --- a/src/Components/Modules/GSC/ScriptStorage.cpp +++ b/src/Components/Modules/GSC/ScriptStorage.cpp @@ -84,12 +84,12 @@ namespace Components::GSC const nlohmann::json json = Data; - FileSystem::FileWriter("scriptdata/scriptstorage.json").write(json.dump()); + FileSystem::FileWriter(Game::SCRIPTDATA_DIR + "/scriptstorage.json"s).write(json.dump()); }); Script::AddFunction("StorageLoad", [] // gsc: StorageLoad(); { - FileSystem::File storageFile("scriptdata/scriptstorage.json"); + FileSystem::File storageFile(Game::SCRIPTDATA_DIR + "/scriptstorage.json"s); if (!storageFile.exists()) { return; diff --git a/src/Game/Script.hpp b/src/Game/Script.hpp index 14ebbbb5..64182e73 100644 --- a/src/Game/Script.hpp +++ b/src/Game/Script.hpp @@ -221,6 +221,8 @@ namespace Game constexpr auto LOCAL_VAR_STACK_SIZE = 64; + constexpr auto SCRIPTDATA_DIR = "scriptdata"; + extern void IncInParam(); extern void Scr_AddBool(int value);