From f3b9cd4a394564a96d7afd1efda3498a3460aa9f Mon Sep 17 00:00:00 2001 From: Lierrmm Date: Mon, 27 Feb 2023 09:01:57 +0000 Subject: [PATCH 1/6] fix: handle addtestclient when not host --- src/client/component/client_patches.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/client/component/client_patches.cpp b/src/client/component/client_patches.cpp index 0a2cf29d..aab28323 100644 --- a/src/client/component/client_patches.cpp +++ b/src/client/component/client_patches.cpp @@ -13,6 +13,7 @@ namespace client_patches namespace { utils::hook::detour preload_map_hook; + utils::hook::detour sv_addtestclient_hook; void stop_zombies_intro_if_needed() { @@ -43,6 +44,18 @@ namespace client_patches preload_map_hook.invoke(localClientNum, mapname, gametype); } + int sv_addtestclient_stub() + { + const auto state = reinterpret_cast(0x1576FB318_g); + + if (*state == 0) + { + return 0; + } + + return sv_addtestclient_hook.invoke(); + } + void reduce_process_affinity() { const DWORD_PTR affinity = (1ULL << (std::min(std::thread::hardware_concurrency(), 4U))) - 1; @@ -82,6 +95,8 @@ namespace client_patches utils::hook::set(0x15AAEB254_g, mixer_open_stub); preload_map_hook.create(0x14135A1E0_g, preload_map_stub); + + sv_addtestclient_hook.create(0x1422499A0_g, sv_addtestclient_stub); } }; } From b669a37632dd9cdc0ece870545808473c256e03b Mon Sep 17 00:00:00 2001 From: Lierrmm Date: Mon, 27 Feb 2023 10:43:36 +0000 Subject: [PATCH 2/6] revert: remove addtestclient changes from client_patches.cpp --- src/client/component/client_patches.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/client/component/client_patches.cpp b/src/client/component/client_patches.cpp index aab28323..d423a485 100644 --- a/src/client/component/client_patches.cpp +++ b/src/client/component/client_patches.cpp @@ -44,18 +44,6 @@ namespace client_patches preload_map_hook.invoke(localClientNum, mapname, gametype); } - int sv_addtestclient_stub() - { - const auto state = reinterpret_cast(0x1576FB318_g); - - if (*state == 0) - { - return 0; - } - - return sv_addtestclient_hook.invoke(); - } - void reduce_process_affinity() { const DWORD_PTR affinity = (1ULL << (std::min(std::thread::hardware_concurrency(), 4U))) - 1; @@ -95,8 +83,6 @@ namespace client_patches utils::hook::set(0x15AAEB254_g, mixer_open_stub); preload_map_hook.create(0x14135A1E0_g, preload_map_stub); - - sv_addtestclient_hook.create(0x1422499A0_g, sv_addtestclient_stub); } }; } From 7bf8abe917c6de7b7bd70fa876d00841ae4789af Mon Sep 17 00:00:00 2001 From: Lierrmm Date: Mon, 27 Feb 2023 10:46:44 +0000 Subject: [PATCH 3/6] feat: check client state before spawning bots --- src/client/component/bots.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/client/component/bots.cpp b/src/client/component/bots.cpp index 6d99ecf8..43f2a6e7 100644 --- a/src/client/component/bots.cpp +++ b/src/client/component/bots.cpp @@ -126,6 +126,15 @@ namespace bots command::add("spawnBot", [](const command::params& params) { + if (!game::is_server()) + { + const auto client_states = *reinterpret_cast(0x1576FB318_g); + if (!client_states) + { + return; + } + } + size_t count = 1; if (params.size() > 1) { From 7d4f89b26494a1f2579809b4dc5b5d7ffda77880 Mon Sep 17 00:00:00 2001 From: Lierrmm Date: Mon, 27 Feb 2023 10:47:54 +0000 Subject: [PATCH 4/6] fix: remove unused detour --- src/client/component/client_patches.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/component/client_patches.cpp b/src/client/component/client_patches.cpp index d423a485..0a2cf29d 100644 --- a/src/client/component/client_patches.cpp +++ b/src/client/component/client_patches.cpp @@ -13,7 +13,6 @@ namespace client_patches namespace { utils::hook::detour preload_map_hook; - utils::hook::detour sv_addtestclient_hook; void stop_zombies_intro_if_needed() { From c3386b52583648a52be436a04fe6751f14dfbcf6 Mon Sep 17 00:00:00 2001 From: Lierrmm Date: Mon, 27 Feb 2023 11:32:29 +0000 Subject: [PATCH 5/6] feat: add is_host check to getinfo --- src/client/component/bots.cpp | 9 +++------ src/client/component/getinfo.cpp | 16 ++++++++++++++++ src/client/component/getinfo.hpp | 1 + 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/client/component/bots.cpp b/src/client/component/bots.cpp index 43f2a6e7..23ca2bc5 100644 --- a/src/client/component/bots.cpp +++ b/src/client/component/bots.cpp @@ -8,6 +8,7 @@ #include #include +#include "getinfo.hpp" namespace bots { @@ -126,13 +127,9 @@ namespace bots command::add("spawnBot", [](const command::params& params) { - if (!game::is_server()) + if (!getinfo::is_host()) { - const auto client_states = *reinterpret_cast(0x1576FB318_g); - if (!client_states) - { - return; - } + return; } size_t count = 1; diff --git a/src/client/component/getinfo.cpp b/src/client/component/getinfo.cpp index 0a8d92fb..fbbaebce 100644 --- a/src/client/component/getinfo.cpp +++ b/src/client/component/getinfo.cpp @@ -78,6 +78,22 @@ namespace getinfo return (rand() % 2) + 1; } + bool is_host() + { + if (game::is_server()) + { + return true; + } + + const auto client_states = *reinterpret_cast(0x1576FB318_g); + if (!client_states) + { + return false; + } + + return true; + } + struct component final : generic_component { void post_unpack() override diff --git a/src/client/component/getinfo.hpp b/src/client/component/getinfo.hpp index 7d016ffa..5d9d14be 100644 --- a/src/client/component/getinfo.hpp +++ b/src/client/component/getinfo.hpp @@ -5,4 +5,5 @@ namespace getinfo int get_max_client_count(); int get_client_count(); int get_bot_count(); + bool is_host(); } From 59a5550eb0dc81b77f241d19f56ea58ed3ee12e5 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 27 Feb 2023 11:38:10 +0000 Subject: [PATCH 6/6] Update src/client/component/getinfo.cpp Co-authored-by: Maurice Heumann --- src/client/component/getinfo.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/client/component/getinfo.cpp b/src/client/component/getinfo.cpp index fbbaebce..5fcda151 100644 --- a/src/client/component/getinfo.cpp +++ b/src/client/component/getinfo.cpp @@ -86,12 +86,7 @@ namespace getinfo } const auto client_states = *reinterpret_cast(0x1576FB318_g); - if (!client_states) - { - return false; - } - - return true; + return client_states == 0; } struct component final : generic_component