Fix binding related crash
This commit is contained in:
parent
18f6a6fa57
commit
33062ec55f
@ -94,22 +94,48 @@ namespace binding
|
||||
return ORIGINAL_BIND_COUNT + get_binding_for_custom_command(command);
|
||||
}
|
||||
|
||||
void cl_execute_key_stub(const int local_client_num, int key, const int down, const unsigned int time)
|
||||
{
|
||||
if (key >= ORIGINAL_BIND_COUNT)
|
||||
std::optional<std::string> get_custom_binding_for_key(int key)
|
||||
{
|
||||
key -= ORIGINAL_BIND_COUNT;
|
||||
|
||||
if (static_cast<size_t>(key) < custom_binds.size() && !custom_binds[key].empty())
|
||||
{
|
||||
game::Cbuf_AddText(local_client_num, utils::string::va("%s\n", custom_binds[key].data()));
|
||||
return {custom_binds[key]};
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void cl_execute_key_stub(const int local_client_num, int key, const int down, const unsigned int time)
|
||||
{
|
||||
if (key >= ORIGINAL_BIND_COUNT)
|
||||
{
|
||||
const auto bind = get_custom_binding_for_key(key);
|
||||
if (!bind.has_value())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return game::Cbuf_AddText(local_client_num, utils::string::va("%s\n", bind.value().data()));
|
||||
}
|
||||
|
||||
cl_execute_key_hook.invoke<void>(local_client_num, key, down, time);
|
||||
}
|
||||
|
||||
const char* cmd_get_binding_for_key_stub(unsigned int key)
|
||||
{
|
||||
if (key >= ORIGINAL_BIND_COUNT)
|
||||
{
|
||||
const auto bind = get_custom_binding_for_key(key);
|
||||
if (!bind.has_value())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return utils::string::va("%s", bind.value().data());
|
||||
}
|
||||
|
||||
return game::command_whitelist[key];
|
||||
}
|
||||
}
|
||||
|
||||
class component final : public component_interface
|
||||
@ -125,6 +151,8 @@ namespace binding
|
||||
|
||||
// execute custom binds
|
||||
cl_execute_key_hook.create(0x1403CF1E0, &cl_execute_key_stub);
|
||||
|
||||
utils::hook::jump(0x14059AE90, cmd_get_binding_for_key_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user