From cfc8bc2e9f0cd532563d9a8b4bd6e0ed6f871cb5 Mon Sep 17 00:00:00 2001 From: FutureRave Date: Fri, 29 Apr 2022 21:17:18 +0100 Subject: [PATCH] override vstr in another way --- src/client/component/command.cpp | 14 ++++++++++---- src/client/game/structs.hpp | 6 +++--- src/client/game/symbols.hpp | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index e52792d..c9e2280 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -13,7 +13,9 @@ namespace command { std::unordered_map> handlers; namespace { -void cmd_vstr_f(const params& params) { +void cmd_vstr_f() { + const params params; + if (params.size() < 2) { game::Com_Printf(game::CON_CHANNEL_DONT_FILTER, "vstr : execute a variable command\n"); @@ -31,6 +33,7 @@ void cmd_vstr_f(const params& params) { if (dvar->type == game::DVAR_TYPE_STRING || dvar->type == game::DVAR_TYPE_ENUM) { + // Adds \n automatically execute(dvar->current.string); } else { game::Com_Printf(game::CON_CHANNEL_DONT_FILTER, @@ -77,7 +80,7 @@ std::string params::join(const int index) const { void add_raw(const char* name, void (*callback)()) { game::Cmd_AddCommandInternal( name, callback, - utils::memory::get_allocator()->allocate()); + utils::memory::get_allocator()->allocate()); } void add(const char* name, const std::function& callback) { @@ -116,8 +119,11 @@ private: game::Com_Printf(game::CON_CHANNEL_DONT_FILTER, "\n"); }); - game::Cmd_RemoveCommand("vstr"); - add("vstr", cmd_vstr_f); + // Override vstr this way + auto* cmd = game::Cmd_FindCommand("vstr"); + if (cmd != nullptr) { + cmd->function = cmd_vstr_f; + } } }; } // namespace command diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index f0b5ca4..a0ec50b 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -130,8 +130,8 @@ struct usercmd_s { static_assert(sizeof(usercmd_s) == 52); -struct cmd_function_t { - cmd_function_t* next; +struct cmd_function_s { + cmd_function_s* next; const char* name; const char* autoCompleteDir; const char* autoCompleteExt; @@ -139,7 +139,7 @@ struct cmd_function_t { bool consoleAccess; }; -static_assert(sizeof(cmd_function_t) == 24); +static_assert(sizeof(cmd_function_s) == 24); struct CmdArgs { int nesting; diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index 81cc094..ab35520 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -49,10 +49,10 @@ WEAK symbol Dvar_RegisterInt{0x58D900, 0x651910}; -WEAK symbol Cmd_AddCommandInternal{ +WEAK symbol Cmd_AddCommandInternal{ 0x6AD580, 0x661400}; WEAK symbol Cmd_RemoveCommand{0x527EA0, 0x5F1A90}; -WEAK symbol Cmd_FindCommand{0x445B60, 0x479DD0}; +WEAK symbol Cmd_FindCommand{0x445B60, 0x479DD0}; WEAK symbol I_CleanStr{0x4B0700, 0x0};