override vstr in another way

This commit is contained in:
6arelyFuture 2022-04-29 21:17:18 +01:00
parent b0c23745d6
commit cfc8bc2e9f
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
3 changed files with 15 additions and 9 deletions

View File

@ -13,7 +13,9 @@ namespace command {
std::unordered_map<std::string, std::function<void(params&)>> 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 <variablename> : 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<game::cmd_function_t>());
utils::memory::get_allocator()->allocate<game::cmd_function_s>());
}
void add(const char* name, const std::function<void(const params&)>& 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

View File

@ -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;

View File

@ -49,10 +49,10 @@ WEAK symbol<const dvar_s*(const char*, int, int, int, unsigned __int16,
const char*)>
Dvar_RegisterInt{0x58D900, 0x651910};
WEAK symbol<void(const char*, void(), cmd_function_t*)> Cmd_AddCommandInternal{
WEAK symbol<void(const char*, void(), cmd_function_s*)> Cmd_AddCommandInternal{
0x6AD580, 0x661400};
WEAK symbol<void(const char* cmdName)> Cmd_RemoveCommand{0x527EA0, 0x5F1A90};
WEAK symbol<cmd_function_t*(const char*)> Cmd_FindCommand{0x445B60, 0x479DD0};
WEAK symbol<cmd_function_s*(const char*)> Cmd_FindCommand{0x445B60, 0x479DD0};
WEAK symbol<char*(char*)> I_CleanStr{0x4B0700, 0x0};