diff --git a/src/client/component/binding.cpp b/src/client/component/binding.cpp index e29c2871..30c3affd 100644 --- a/src/client/component/binding.cpp +++ b/src/client/component/binding.cpp @@ -93,23 +93,49 @@ namespace binding // custom binds return ORIGINAL_BIND_COUNT + get_binding_for_custom_command(command); } + + std::optional get_custom_binding_for_key(int key) + { + key -= ORIGINAL_BIND_COUNT; + + if (static_cast(key) < custom_binds.size() && !custom_binds[key].empty()) + { + 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) { - key -= ORIGINAL_BIND_COUNT; - - if (static_cast(key) < custom_binds.size() && !custom_binds[key].empty()) + const auto bind = get_custom_binding_for_key(key); + if (!bind.has_value()) { - game::Cbuf_AddText(local_client_num, utils::string::va("%s\n", custom_binds[key].data())); + return; } - return; + return game::Cbuf_AddText(local_client_num, utils::string::va("%s\n", bind.value().data())); } cl_execute_key_hook.invoke(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); } }; }