From 668f8e05ead94482da2cb154e10082aeca85ef25 Mon Sep 17 00:00:00 2001 From: Skull <86374920+skkuull@users.noreply.github.com> Date: Tue, 14 Jun 2022 21:51:52 +0300 Subject: [PATCH 1/6] Create bots.cpp --- src/component/bots.cpp | 102 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/component/bots.cpp diff --git a/src/component/bots.cpp b/src/component/bots.cpp new file mode 100644 index 0000000..7ac7592 --- /dev/null +++ b/src/component/bots.cpp @@ -0,0 +1,102 @@ +#include +#include "loader/component_loader.hpp" + +#include "gsc.hpp" + +#include +#include +#include + +namespace bots +{ + namespace + { + typedef std::pair bot_entry; + + std::vector bot_names; + utils::hook::detour sv_bot_name_random_hook; + + // Json file is expected to contain one "names" object and that should contain a string (key) + // for the bot's name and one string (value) for the clantag + void load_bot_data() + { + if (!utils::io::file_exists("bots/bots.json")) + { + printf("bots.json was not found\n"); + return; + } + + nlohmann::json obj; + try + { + obj = nlohmann::json::parse(utils::io::read_file("bots/bots.json").data()); + } + catch (const nlohmann::json::parse_error& ex) + { + printf("%s\n", ex.what()); + return; + } + + for (const auto& [key, val] : obj["names"].items()) + { + if (val.is_string()) + { + bot_names.emplace_back(std::make_pair(key, val.get())); + } + } + } + + // If the list contains at least 18 names there should not be any collisions + const char* sv_bot_name_random_stub() + { + if (bot_names.empty()) + { + load_bot_data(); + } + + static size_t bot_id = 0; + if (!bot_names.empty()) + { + bot_id %= bot_names.size(); + const auto& entry = bot_names.at(bot_id++); + return entry.first.data(); + } + + return sv_bot_name_random_hook.invoke(); + } + + int build_connect_string(char* buf, const char* connect_string, const char* name, const char* xuid, + const char* xnaddr, int protocol, int netfield, int session_mode, int port) + { + // Default + auto clantag = "3arc"s; + for (const auto& entry : bot_names) + { + if (entry.first == name) + { + clantag = entry.second; + break; + } + } + + return _snprintf_s(buf, 0x400, _TRUNCATE, connect_string, name, + clantag.data(), xuid, xnaddr, protocol, netfield, session_mode, port); + } + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + // Add custom clantag + utils::hook::set(0x6B6294, "connect \"\\cg_predictItems\\1\\cl_punkbuster\\0\\cl_anonymous\\0\\color\\4\\head\\default\\model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\clanAbbrev\\3arc\\bdOnlineUserID\\%s\\protocol\\%d\\qport\\%d\""); + + sv_bot_name_random_hook.create(0x49ED80, &sv_bot_name_random_stub); + utils::hook::call(0x6B6299, build_connect_string); + } + + }; +} + +REGISTER_COMPONENT(bots::component) \ No newline at end of file From ba2e2556df3ca071827adc4365f29294b0bcba8f Mon Sep 17 00:00:00 2001 From: Skull <86374920+skkuull@users.noreply.github.com> Date: Tue, 14 Jun 2022 21:52:36 +0300 Subject: [PATCH 2/6] one more check to disable sp/zm --- src/component/bots.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/component/bots.cpp b/src/component/bots.cpp index 7ac7592..4bf8749 100644 --- a/src/component/bots.cpp +++ b/src/component/bots.cpp @@ -89,6 +89,11 @@ namespace bots public: void post_unpack() override { + if (game::environment::is_sp()) + { + return; + } + // Add custom clantag utils::hook::set(0x6B6294, "connect \"\\cg_predictItems\\1\\cl_punkbuster\\0\\cl_anonymous\\0\\color\\4\\head\\default\\model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\clanAbbrev\\3arc\\bdOnlineUserID\\%s\\protocol\\%d\\qport\\%d\""); From 625f4a306ad5db9f671afd2c7c9a109319066c40 Mon Sep 17 00:00:00 2001 From: Skull <86374920+skkuull@users.noreply.github.com> Date: Tue, 14 Jun 2022 21:53:40 +0300 Subject: [PATCH 3/6] xD --- src/component/bots.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/component/bots.cpp b/src/component/bots.cpp index 4bf8749..988a9e1 100644 --- a/src/component/bots.cpp +++ b/src/component/bots.cpp @@ -1,7 +1,7 @@ #include #include "loader/component_loader.hpp" -#include "gsc.hpp" +#include "game/game.hpp" #include #include From 1a55e3f20ce52ac4e30b22e36e0b73a68b9e948a Mon Sep 17 00:00:00 2001 From: Skull <86374920+skkuull@users.noreply.github.com> Date: Tue, 14 Jun 2022 21:55:20 +0300 Subject: [PATCH 4/6] remove public --- src/component/bots.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/component/bots.cpp b/src/component/bots.cpp index 988a9e1..09534ba 100644 --- a/src/component/bots.cpp +++ b/src/component/bots.cpp @@ -86,7 +86,6 @@ namespace bots class component final : public component_interface { - public: void post_unpack() override { if (game::environment::is_sp()) From 23edbb1e82720b0feb0406edc9e5ce12acb8a656 Mon Sep 17 00:00:00 2001 From: Skull <86374920+skkuull@users.noreply.github.com> Date: Tue, 14 Jun 2022 21:57:51 +0300 Subject: [PATCH 5/6] looks more gentle --- src/component/bots.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/component/bots.cpp b/src/component/bots.cpp index 09534ba..8b64c2d 100644 --- a/src/component/bots.cpp +++ b/src/component/bots.cpp @@ -94,7 +94,8 @@ namespace bots } // Add custom clantag - utils::hook::set(0x6B6294, "connect \"\\cg_predictItems\\1\\cl_punkbuster\\0\\cl_anonymous\\0\\color\\4\\head\\default\\model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\clanAbbrev\\3arc\\bdOnlineUserID\\%s\\protocol\\%d\\qport\\%d\""); + utils::hook::set(0x6B6294, "connect \"\\cg_predictItems\\1\\cl_punkbuster\\0\\cl_anonymous\\0\\color\\4\\head\\default\\" + " model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\clanAbbrev\\3arc\\bdOnlineUserID\\%s\\protocol\\%d\\qport\\%d\""); sv_bot_name_random_hook.create(0x49ED80, &sv_bot_name_random_stub); utils::hook::call(0x6B6299, build_connect_string); From 8bb6203ddc6b4a0e5ddeb9347c5ec9387f47ccb4 Mon Sep 17 00:00:00 2001 From: Skull <86374920+skkuull@users.noreply.github.com> Date: Tue, 14 Jun 2022 22:15:22 +0300 Subject: [PATCH 6/6] Revert "remove public" This reverts commit 1a55e3f20ce52ac4e30b22e36e0b73a68b9e948a. --- src/component/bots.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/component/bots.cpp b/src/component/bots.cpp index 8b64c2d..5ed2723 100644 --- a/src/component/bots.cpp +++ b/src/component/bots.cpp @@ -86,6 +86,7 @@ namespace bots class component final : public component_interface { + public: void post_unpack() override { if (game::environment::is_sp())