diff --git a/src/component/command.cpp b/src/component/command.cpp index 79f523e..55be10b 100644 --- a/src/component/command.cpp +++ b/src/component/command.cpp @@ -6,6 +6,7 @@ #include "command.hpp" #include "gsc.hpp" #include "scripting.hpp" +#include "scheduler.hpp" #include #include @@ -91,6 +92,16 @@ namespace command return result; } + std::vector params::get_all() const + { + std::vector params_; + for (auto i = 0; i < this->size(); i++) + { + params_.push_back(this->get(i)); + } + return params_; + } + params_sv::params_sv() : nesting_(game::sv_cmd_args->nesting) { @@ -128,6 +139,16 @@ namespace command return result; } + std::vector params_sv::get_all() const + { + std::vector params_; + for (auto i = 0; i < this->size(); i++) + { + params_.push_back(this->get(i)); + } + return params_; + } + void add_raw(const char* name, void (*callback)()) { game::Cmd_AddCommandInternal(name, callback, utils::memory::get_allocator()->allocate()); @@ -216,14 +237,18 @@ namespace command { command::add_script_command(name, [function](const command::params& params) { - scripting::array array; - - for (auto i = 0; i < params.size(); i++) + const auto params_ = params.get_all(); + scheduler::once([=]() { - array.push(params[i]); - } + scripting::array array; - function({array}); + for (auto i = 0; i < params.size(); i++) + { + array.push(params[i]); + } + + function({array}); + }); }); }, "addcommand", "command::add"); @@ -231,16 +256,20 @@ namespace command { command::add_script_sv_command(name, [function](const int client_num, const command::params_sv& params) { - const scripting::entity player = game::Scr_GetEntityId(game::SCRIPTINSTANCE_SERVER, client_num, 0, 0); - - scripting::array array; - - for (auto i = 0; i < params.size(); i++) + const auto params_ = params.get_all(); + scheduler::once([=]() { - array.push(params[i]); - } + const scripting::entity player = game::Scr_GetEntityId(game::SCRIPTINSTANCE_SERVER, client_num, 0, 0); - function(player, {array}); + scripting::array array; + + for (auto i = 0; i < params.size(); i++) + { + array.push(params[i]); + } + + function(player, {array}); + }, scheduler::pipeline::server); }); }, "addclientcommand", "command::add_sv"); diff --git a/src/component/command.hpp b/src/component/command.hpp index dbfaa51..f8644e6 100644 --- a/src/component/command.hpp +++ b/src/component/command.hpp @@ -10,6 +10,7 @@ namespace command int size() const; const char* get(int index) const; std::string join(int index) const; + std::vector get_all() const; const char* operator[](const int index) const { @@ -28,6 +29,7 @@ namespace command int size() const; const char* get(int index) const; std::string join(int index) const; + std::vector get_all() const; const char* operator[](const int index) const { diff --git a/src/component/scheduler.cpp b/src/component/scheduler.cpp index 00ddf87..af60c4e 100644 --- a/src/component/scheduler.cpp +++ b/src/component/scheduler.cpp @@ -11,6 +11,8 @@ namespace scheduler { namespace { + utils::hook::detour server_frame_hook; + struct task { std::function handler{}; @@ -94,13 +96,10 @@ namespace scheduler execute(pipeline::server); } - void server_frame_stub(utils::hook::assembler& a) + void server_frame_stub() { - a.pushad(); - a.call(execute_server); - a.popad(); - - a.jmp(SELECT_VALUE(0x0, 0x0)); + execute(pipeline::server); + server_frame_hook.invoke(); } } @@ -151,9 +150,9 @@ namespace scheduler } }); - + server_frame_hook.create(SELECT_VALUE(0x43E340, 0x46B680), server_frame_stub); } }; } -//REGISTER_COMPONENT(scheduler::component) +REGISTER_COMPONENT(scheduler::component) diff --git a/src/game/symbols.hpp b/src/game/symbols.hpp index cd0e47a..d811451 100644 --- a/src/game/symbols.hpp +++ b/src/game/symbols.hpp @@ -101,7 +101,7 @@ namespace game WEAK symbol SV_GameDropClient{0x0, 0x0}; WEAK symbol SV_IsTestClient{0x0, 0x0}; - WEAK symbol SV_GameSendServerCommand{0x0, 0x0}; + WEAK symbol SV_GameSendServerCommand{0x543CF0, 0x6B8730}; WEAK symbol Sys_GetValue{0x67D4F0, 0x529EB0}; WEAK symbol Sys_Milliseconds{0x0, 0x0};