maint: refactor command functions

This commit is contained in:
Diavolo 2022-12-19 13:13:13 +01:00
parent 0db51382c6
commit 876e82ffc7
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
4 changed files with 14 additions and 10 deletions

View File

@ -65,6 +65,7 @@ namespace game
SV_ClientEnterWorld_t SV_ClientEnterWorld;
SV_Cmd_TokenizeString_t SV_Cmd_TokenizeString;
SV_Cmd_EndTokenizedString_t SV_Cmd_EndTokenizedString;
SV_SpawnServer_t SV_SpawnServer;
XUIDToString_t XUIDToString;
@ -750,6 +751,7 @@ namespace game
native::SV_ClientEnterWorld = native::SV_ClientEnterWorld_t(SELECT_VALUE(0x0, 0x571100));
native::SV_Cmd_TokenizeString = native::SV_Cmd_TokenizeString_t(SELECT_VALUE(0x0, 0x545D40));
native::SV_Cmd_EndTokenizedString = native::SV_Cmd_EndTokenizedString_t(SELECT_VALUE(0x0, 0x545D70));
native::SV_SpawnServer = native::SV_SpawnServer_t(SELECT_VALUE(0x0, 0x575020));
native::mp::SV_GameSendServerCommand = native::mp::SV_GameSendServerCommand_t(0x573220);
native::mp::SV_GetGuid = native::mp::SV_GetGuid_t(0x573990);

View File

@ -136,6 +136,9 @@ namespace game
typedef void (*SV_Cmd_EndTokenizedString_t)();
extern SV_Cmd_EndTokenizedString_t SV_Cmd_EndTokenizedString;
typedef void (*SV_SpawnServer_t)(const char* server, int mapIsPreloaded, int savegame);
extern SV_SpawnServer_t SV_SpawnServer;
typedef void (*XUIDToString_t)(const unsigned __int64* xuid, char* str);
extern XUIDToString_t XUIDToString;

View File

@ -11,8 +11,8 @@
static utils::memory::allocator allocator;
std::unordered_map<std::string, std::function<void(const command::params&)>> command::handlers;
std::unordered_map<std::string, std::function<void(game::native::gentity_s*, command::params_sv&)>> command::handlers_sv;
std::unordered_map<std::string, std::function<void(game::native::sp::gentity_s*, command::params_sv&)>> command::handlers_sp_sv;
std::unordered_map<std::string, std::function<void(game::native::gentity_s*, const command::params_sv&)>> command::handlers_sv;
std::unordered_map<std::string, std::function<void(game::native::sp::gentity_s*, const command::params_sv&)>> command::handlers_sp_sv;
command::params::params()
: nesting_(game::native::cmd_args->nesting)
@ -87,7 +87,7 @@ void command::add_raw(const char* name, void (*callback)())
game::native::Cmd_AddCommand(name, callback, allocator.allocate<game::native::cmd_function_t>());
}
void command::add(const char* name, const std::function<void(const command::params&)>& callback)
void command::add(const char* name, const std::function<void(const params&)>& callback)
{
const auto command = utils::string::to_lower(name);
@ -107,7 +107,7 @@ void command::add(const char* name, const std::function<void()>& callback)
});
}
void command::add_sv(const char* name, std::function<void(game::native::gentity_s*, const command::params_sv&)> callback)
void command::add_sv(const char* name, std::function<void(game::native::gentity_s*, const params_sv&)> callback)
{
// Since the game console is not usable there is no point in calling add_raw
const auto command = utils::string::to_lower(name);
@ -144,7 +144,7 @@ void command::execute(std::string command, bool sync)
void command::main_handler()
{
params params;
const params params;
const auto command = utils::string::to_lower(params[0]);
@ -163,7 +163,7 @@ void command::client_command_stub(int client_num)
return;
}
params_sv params;
const params_sv params;
const auto command = utils::string::to_lower(params[0]);
@ -182,7 +182,7 @@ void command::client_command_sp(int client_num, const char* s)
assert(entity->client); // On sp it should only be an assertion
params_sv params;
const params_sv params;
const auto command = utils::string::to_lower(params[0]);

View File

@ -51,15 +51,14 @@ public:
private:
static std::unordered_map<std::string, std::function<void(const params&)>> handlers;
static std::unordered_map<std::string, std::function<void(game::native::gentity_s*, params_sv&)>> handlers_sv;
static std::unordered_map<std::string, std::function<void(game::native::sp::gentity_s*, params_sv&)>> handlers_sp_sv;
static std::unordered_map<std::string, std::function<void(game::native::gentity_s*, const params_sv&)>> handlers_sv;
static std::unordered_map<std::string, std::function<void(game::native::sp::gentity_s*, const params_sv&)>> handlers_sp_sv;
static void main_handler();
static void client_command_stub(int client_num);
static void client_command_sp(int client_num, const char* s);
static void client_command_sp_stub();
static void client_command_dedi_stub();
static void add_raw(const char* name, void (*callback)());