From 83b750d17e7bf50777d044ab091aa17d39117a12 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Fri, 17 Feb 2023 10:51:47 +0000 Subject: [PATCH 1/3] maint: add some extra bot names by default --- src/client/component/bots.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/component/bots.cpp b/src/client/component/bots.cpp index 2ae201b2..8c264a80 100644 --- a/src/client/component/bots.cpp +++ b/src/client/component/bots.cpp @@ -25,6 +25,12 @@ namespace bots {"momo5502", "IW5x"}, {"Maurice", "IW5x" }, {"Jasmin", "<3"}, + {"Dss0", "IW3x"}, + {"FutureRave", "FR"}, + {"Diamante", "IW2x"}, + {"St0rm", "NN"}, + {"Joel", "NN"}, + {"Louve", "IW5x"}, }; std::string buffer; @@ -88,7 +94,7 @@ namespace bots } int format_bot_string(char* buffer, [[maybe_unused]] const char* format, const char* name, const char* xuid, - const char* xnaddr, int protocol, int netfieldchk, const char* session_mode, int qport) + const char* xnaddr, int protocol, int net_field_chk, const char* session_mode, int qport) { const auto find_name = [](const std::string& needle) -> const char* { @@ -103,7 +109,7 @@ namespace bots return "3arc"; }; - return sprintf_s(buffer, 1024, bot_format_string, name, find_name(name), xuid, xnaddr, protocol, netfieldchk, session_mode, qport); + return sprintf_s(buffer, 1024, bot_format_string, name, find_name(name), xuid, xnaddr, protocol, net_field_chk, session_mode, qport); } } From a0dedc2a527f0b7e17434712fd6af81e9d8d60fa Mon Sep 17 00:00:00 2001 From: FutureRave Date: Fri, 17 Feb 2023 10:58:15 +0000 Subject: [PATCH 2/3] maint: fix line endings in the scheduler --- src/client/component/scheduler.cpp | 380 ++++++++++++++--------------- 1 file changed, 190 insertions(+), 190 deletions(-) diff --git a/src/client/component/scheduler.cpp b/src/client/component/scheduler.cpp index a964200c..8b5ae514 100644 --- a/src/client/component/scheduler.cpp +++ b/src/client/component/scheduler.cpp @@ -1,191 +1,191 @@ -#include -#include "loader/component_loader.hpp" - -#include "scheduler.hpp" - -#include "game/game.hpp" - -#include -#include -#include - -namespace scheduler -{ - namespace - { - struct task - { - std::function handler{}; - std::chrono::milliseconds interval{}; - std::chrono::high_resolution_clock::time_point last_call{}; - }; - - using task_list = std::vector; - - class task_pipeline - { - public: - void add(task&& task) - { - new_callbacks_.access([&task](task_list& tasks) - { - tasks.emplace_back(std::move(task)); - }); - } - - void execute() - { - callbacks_.access([&](task_list& tasks) - { - this->merge_callbacks(); - - for (auto i = tasks.begin(); i != tasks.end();) - { - const auto now = std::chrono::high_resolution_clock::now(); - const auto diff = now - i->last_call; - - if (diff < i->interval) - { - ++i; - continue; - } - - i->last_call = now; - - const auto res = i->handler(); - if (res == cond_end) - { - i = tasks.erase(i); - } - else - { - ++i; - } - } - }); - } - - private: - utils::concurrency::container new_callbacks_; - utils::concurrency::container callbacks_; - - void merge_callbacks() - { - callbacks_.access([&](task_list& tasks) - { - new_callbacks_.access([&](task_list& new_tasks) - { - tasks.insert(tasks.end(), std::move_iterator(new_tasks.begin()), - std::move_iterator(new_tasks.end())); - new_tasks = {}; - }); - }); - } - }; - - volatile bool kill = false; - std::thread thread; - task_pipeline pipelines[pipeline::count]; - - utils::hook::detour r_end_frame_hook; - utils::hook::detour g_run_frame_hook; - utils::hook::detour main_frame_hook; - - - void r_end_frame_stub() - { - execute(pipeline::renderer); - r_end_frame_hook.invoke(); - } - - void server_frame_stub() - { - g_run_frame_hook.invoke(); - execute(pipeline::server); - } - - void main_frame_stub() - { - main_frame_hook.invoke(); - execute(pipeline::main); - } +#include +#include "loader/component_loader.hpp" + +#include "scheduler.hpp" + +#include "game/game.hpp" + +#include +#include +#include + +namespace scheduler +{ + namespace + { + struct task + { + std::function handler{}; + std::chrono::milliseconds interval{}; + std::chrono::high_resolution_clock::time_point last_call{}; + }; + + using task_list = std::vector; + + class task_pipeline + { + public: + void add(task&& task) + { + new_callbacks_.access([&task](task_list& tasks) + { + tasks.emplace_back(std::move(task)); + }); + } + + void execute() + { + callbacks_.access([&](task_list& tasks) + { + this->merge_callbacks(); + + for (auto i = tasks.begin(); i != tasks.end();) + { + const auto now = std::chrono::high_resolution_clock::now(); + const auto diff = now - i->last_call; + + if (diff < i->interval) + { + ++i; + continue; + } + + i->last_call = now; + + const auto res = i->handler(); + if (res == cond_end) + { + i = tasks.erase(i); + } + else + { + ++i; + } + } + }); + } + + private: + utils::concurrency::container new_callbacks_; + utils::concurrency::container callbacks_; + + void merge_callbacks() + { + callbacks_.access([&](task_list& tasks) + { + new_callbacks_.access([&](task_list& new_tasks) + { + tasks.insert(tasks.end(), std::move_iterator(new_tasks.begin()), + std::move_iterator(new_tasks.end())); + new_tasks = {}; + }); + }); + } + }; + + volatile bool kill = false; + std::thread thread; + task_pipeline pipelines[pipeline::count]; + + utils::hook::detour r_end_frame_hook; + utils::hook::detour g_run_frame_hook; + utils::hook::detour main_frame_hook; + + + void r_end_frame_stub() + { + execute(pipeline::renderer); + r_end_frame_hook.invoke(); + } + + void server_frame_stub() + { + g_run_frame_hook.invoke(); + execute(pipeline::server); + } + + void main_frame_stub() + { + main_frame_hook.invoke(); + execute(pipeline::main); + } } - - void execute(const pipeline type) - { - assert(type >= 0 && type < pipeline::count); - pipelines[type].execute(); - } - - void schedule(const std::function& callback, const pipeline type, - const std::chrono::milliseconds delay) - { - assert(type >= 0 && type < pipeline::count); - - task task; - task.handler = callback; - task.interval = delay; - task.last_call = std::chrono::high_resolution_clock::now(); - - pipelines[type].add(std::move(task)); - } - - void loop(const std::function& callback, const pipeline type, - const std::chrono::milliseconds delay) - { - schedule([callback]() - { - callback(); - return cond_continue; - }, type, delay); - } - - void once(const std::function& callback, const pipeline type, - const std::chrono::milliseconds delay) - { - schedule([callback]() - { - callback(); - return cond_end; - }, type, delay); - } - - struct component final : generic_component - { - void post_load() override - { - thread = utils::thread::create_named_thread("Async Scheduler", []() - { - while (!kill) - { - execute(pipeline::async); - std::this_thread::sleep_for(10ms); - } - }); - } - - void post_unpack() override - { - if (!game::is_server()) - { - r_end_frame_hook.create(0x142273560_g, r_end_frame_stub); - // some func called before R_EndFrame, maybe SND_EndFrame? - } - - //g_run_frame_hook.create(0x14065C360_g, server_frame_stub); // GlassSv_Update - main_frame_hook.create(game::select(0x1420F9860, 0x1405020E0), main_frame_stub); - // Com_Frame_Try_Block_Function - } - - void pre_destroy() override - { - kill = true; - if (thread.joinable()) - { - thread.join(); - } - } - }; -} - -REGISTER_COMPONENT(scheduler::component) + + void execute(const pipeline type) + { + assert(type >= 0 && type < pipeline::count); + pipelines[type].execute(); + } + + void schedule(const std::function& callback, const pipeline type, + const std::chrono::milliseconds delay) + { + assert(type >= 0 && type < pipeline::count); + + task task; + task.handler = callback; + task.interval = delay; + task.last_call = std::chrono::high_resolution_clock::now(); + + pipelines[type].add(std::move(task)); + } + + void loop(const std::function& callback, const pipeline type, + const std::chrono::milliseconds delay) + { + schedule([callback]() + { + callback(); + return cond_continue; + }, type, delay); + } + + void once(const std::function& callback, const pipeline type, + const std::chrono::milliseconds delay) + { + schedule([callback]() + { + callback(); + return cond_end; + }, type, delay); + } + + struct component final : generic_component + { + void post_load() override + { + thread = utils::thread::create_named_thread("Async Scheduler", []() + { + while (!kill) + { + execute(pipeline::async); + std::this_thread::sleep_for(10ms); + } + }); + } + + void post_unpack() override + { + if (!game::is_server()) + { + r_end_frame_hook.create(0x142273560_g, r_end_frame_stub); + // some func called before R_EndFrame, maybe SND_EndFrame? + } + + //g_run_frame_hook.create(0x14065C360_g, server_frame_stub); // GlassSv_Update + main_frame_hook.create(game::select(0x1420F9860, 0x1405020E0), main_frame_stub); + // Com_Frame_Try_Block_Function + } + + void pre_destroy() override + { + kill = true; + if (thread.joinable()) + { + thread.join(); + } + } + }; +} + +REGISTER_COMPONENT(scheduler::component) From 680eddd7aa1d485898a0243a316e18db1e5b9353 Mon Sep 17 00:00:00 2001 From: Edo Date: Fri, 17 Feb 2023 12:26:40 +0000 Subject: [PATCH 3/3] fix: remove name --- src/client/component/bots.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/component/bots.cpp b/src/client/component/bots.cpp index 8c264a80..6d99ecf8 100644 --- a/src/client/component/bots.cpp +++ b/src/client/component/bots.cpp @@ -23,7 +23,6 @@ namespace bots std::vector bot_names = { {"momo5502", "IW5x"}, - {"Maurice", "IW5x" }, {"Jasmin", "<3"}, {"Dss0", "IW3x"}, {"FutureRave", "FR"},