mirror of
https://github.com/alicealys/t5-gsc-utils.git
synced 2025-05-09 05:54:50 +00:00
Execute script command callbacks on server frame
This commit is contained in:
parent
90b3a553db
commit
5fb5d2d1fe
@ -6,6 +6,7 @@
|
||||
#include "command.hpp"
|
||||
#include "gsc.hpp"
|
||||
#include "scripting.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
#include <utils/string.hpp>
|
||||
#include <utils/memory.hpp>
|
||||
@ -91,6 +92,16 @@ namespace command
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> params::get_all() const
|
||||
{
|
||||
std::vector<std::string> 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<std::string> params_sv::get_all() const
|
||||
{
|
||||
std::vector<std::string> 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<game::cmd_function_t>());
|
||||
@ -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");
|
||||
|
||||
|
@ -10,6 +10,7 @@ namespace command
|
||||
int size() const;
|
||||
const char* get(int index) const;
|
||||
std::string join(int index) const;
|
||||
std::vector<std::string> 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<std::string> get_all() const;
|
||||
|
||||
const char* operator[](const int index) const
|
||||
{
|
||||
|
@ -11,6 +11,8 @@ namespace scheduler
|
||||
{
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour server_frame_hook;
|
||||
|
||||
struct task
|
||||
{
|
||||
std::function<bool()> 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<void>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
@ -101,7 +101,7 @@ namespace game
|
||||
|
||||
WEAK symbol<void(int clientNum, const char* reason)> SV_GameDropClient{0x0, 0x0};
|
||||
WEAK symbol<bool(int clientNum)> SV_IsTestClient{0x0, 0x0};
|
||||
WEAK symbol<void(int clientNum, int type, const char* command)> SV_GameSendServerCommand{0x0, 0x0};
|
||||
WEAK symbol<void(int clientNum, int type, const char* command)> SV_GameSendServerCommand{0x543CF0, 0x6B8730};
|
||||
|
||||
WEAK symbol<void*(int valueIndex)> Sys_GetValue{0x67D4F0, 0x529EB0};
|
||||
WEAK symbol<int()> Sys_Milliseconds{0x0, 0x0};
|
||||
|
Loading…
x
Reference in New Issue
Block a user