From d75a5a71e58d8520fe5364ed5e71c0aaf7ba4a60 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Thu, 5 May 2022 23:48:33 +0100 Subject: [PATCH 1/2] [Bots] Add isBot GSC meth back --- src/Components/Modules/Bots.cpp | 21 +++++++++++++-------- src/Components/Modules/Bots.hpp | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index edccc68b..8c53ec2d 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -108,8 +108,19 @@ namespace Components } } + void Bots::GScr_isTestClient(Game::scr_entref_t entref) + { + const auto* ent = Game::GetPlayerEntity(entref); + const auto* client = Script::GetClient(ent); + + Game::Scr_AddBool(client->bIsTestClient == 1); + } + void Bots::AddMethods() { + Script::AddMethod("IsBot", Bots::GScr_isTestClient); // Usage: self IsBot(); + Script::AddMethod("IsTestClient", Bots::GScr_isTestClient); // Usage: self IsTestClient(); + Script::AddMethod("SetPing", [](Game::scr_entref_t entref) // gsc: self SetPing() { auto ping = Game::Scr_GetInt(0); @@ -128,14 +139,6 @@ namespace Components client->ping = static_cast(ping); }); - Script::AddMethod("IsTestClient", [](Game::scr_entref_t entref) // Usage: IsTestClient(); - { - const auto* gentity = Game::GetPlayerEntity(entref); - const auto* client = Script::GetClient(gentity); - - Game::Scr_AddBool(client->bIsTestClient == 1); - }); - Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: BotStop(); { const auto* ent = Game::GetPlayerEntity(entref); @@ -327,6 +330,8 @@ namespace Components Bots::Bots() { + AssertOffset(Game::client_s, bIsTestClient, 0x41AF0); + // Replace connect string Utils::Hook::Set(0x48ADA6, "connect bot%d \"\\cg_predictItems\\1\\cl_anonymous\\0\\color\\4\\head\\default\\model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\protocol\\%d\\checksum\\%d\\statver\\%d %u\\qport\\%d\""); diff --git a/src/Components/Modules/Bots.hpp b/src/Components/Modules/Bots.hpp index 910bacfa..8bf9045c 100644 --- a/src/Components/Modules/Bots.hpp +++ b/src/Components/Modules/Bots.hpp @@ -14,6 +14,7 @@ namespace Components static void Spawn(unsigned int count); + static void GScr_isTestClient(Game::scr_entref_t entref); static void AddMethods(); static void BotAiAction(Game::client_t* cl); From 849b890a96751dd2ed1f6b692dfe99f3a308b65c Mon Sep 17 00:00:00 2001 From: FutureRave Date: Sat, 7 May 2022 00:49:29 +0100 Subject: [PATCH 2/2] Get rid of direct checks of bistestclient --- src/Components/Modules/Bots.cpp | 43 +++++++++++++-------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index 8c53ec2d..e89c73a2 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -111,9 +111,7 @@ namespace Components void Bots::GScr_isTestClient(Game::scr_entref_t entref) { const auto* ent = Game::GetPlayerEntity(entref); - const auto* client = Script::GetClient(ent); - - Game::Scr_AddBool(client->bIsTestClient == 1); + Game::Scr_AddBool(Game::SV_IsTestClient(ent->s.number) != 0); } void Bots::AddMethods() @@ -130,7 +128,7 @@ namespace Components const auto* ent = Game::GetPlayerEntity(entref); auto* client = Script::GetClient(ent); - if (!client->bIsTestClient) + if (Game::SV_IsTestClient(ent->s.number) == 0) { Game::Scr_Error("^1SetPing: Can only call on a bot!\n"); return; @@ -142,9 +140,8 @@ namespace Components Script::AddMethod("BotStop", [](Game::scr_entref_t entref) // Usage: BotStop(); { const auto* ent = Game::GetPlayerEntity(entref); - const auto* client = Script::GetClient(ent); - if (!client->bIsTestClient) + if (Game::SV_IsTestClient(ent->s.number) == 0) { Game::Scr_Error("^1BotStop: Can only call on a bot!\n"); return; @@ -157,17 +154,16 @@ namespace Components Script::AddMethod("BotWeapon", [](Game::scr_entref_t entref) // Usage: BotWeapon(); { - const auto* weapon = Game::Scr_GetString(0); - const auto* ent = Game::GetPlayerEntity(entref); - const auto* client = Script::GetClient(ent); - if (!client->bIsTestClient) + if (Game::SV_IsTestClient(ent->s.number) == 0) { Game::Scr_Error("^1BotWeapon: Can only call on a bot!\n"); return; } + const auto* weapon = Game::Scr_GetString(0); + if (weapon == nullptr || weapon[0] == '\0') { g_botai[entref.entnum].weapon = 1; @@ -181,6 +177,14 @@ namespace Components Script::AddMethod("BotAction", [](Game::scr_entref_t entref) // Usage: BotAction(); { + const auto* ent = Game::GetPlayerEntity(entref); + + if (Game::SV_IsTestClient(ent->s.number) == 0) + { + Game::Scr_Error("^1BotAction: Can only call on a bot!\n"); + return; + } + const auto* action = Game::Scr_GetString(0); if (action == nullptr) @@ -189,15 +193,6 @@ namespace Components return; } - const auto* ent = Game::GetPlayerEntity(entref); - const auto* client = Script::GetClient(ent); - - if (!client->bIsTestClient) - { - Game::Scr_Error("^1BotAction: Can only call on a bot!\n"); - return; - } - if (action[0] != '+' && action[0] != '-') { Game::Scr_ParamError(0, "^1BotAction: Sign for action must be '+' or '-'.\n"); @@ -223,20 +218,16 @@ namespace Components Script::AddMethod("BotMovement", [](Game::scr_entref_t entref) // Usage: BotMovement(, ); { - auto forwardInt = Game::Scr_GetInt(0); - auto rightInt = Game::Scr_GetInt(1); - const auto* ent = Game::GetPlayerEntity(entref); - const auto* client = Script::GetClient(ent); - if (!client->bIsTestClient) + if (Game::SV_IsTestClient(ent->s.number) == 0) { Game::Scr_Error("^1BotMovement: Can only call on a bot!\n"); return; } - forwardInt = std::clamp(forwardInt, std::numeric_limits::min(), std::numeric_limits::max()); - rightInt = std::clamp(rightInt, std::numeric_limits::min(), std::numeric_limits::max()); + const auto forwardInt = std::clamp(Game::Scr_GetInt(0), std::numeric_limits::min(), std::numeric_limits::max()); + const auto rightInt = std::clamp(Game::Scr_GetInt(1), std::numeric_limits::min(), std::numeric_limits::max()); g_botai[entref.entnum].forward = static_cast(forwardInt); g_botai[entref.entnum].right = static_cast(rightInt);