From 4967ed95692bd06c5b421ef4e69d49bd9ef24538 Mon Sep 17 00:00:00 2001 From: quaK Date: Mon, 15 Jul 2024 20:07:53 +0300 Subject: [PATCH] add bindlist cmd --- src/client/component/command.cpp | 5 +++++ src/client/component/input.cpp | 31 +++++++++++++++++++++++-------- src/client/game/game.cpp | 18 ++++++++++++++++++ src/client/game/game.hpp | 2 ++ src/client/game/structs.hpp | 24 ++++++++++++++++++++++-- src/client/game/symbols.hpp | 6 +++++- 6 files changed, 75 insertions(+), 11 deletions(-) diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index 2bfa525..140e6b5 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -477,6 +477,11 @@ namespace command game::Com_GameMode_SetDesiredGameMode(game::GAME_MODE_CP); }); + add("bindlist", []() + { + game::Key_Bindlist_f(); + }); + add_sv("god", [](const int client_num, const params_sv&) { if (!game::shared::cheats_ok(client_num, true)) diff --git a/src/client/component/input.cpp b/src/client/component/input.cpp index 58d7089..14278f1 100644 --- a/src/client/component/input.cpp +++ b/src/client/component/input.cpp @@ -17,7 +17,6 @@ namespace input utils::hook::detour cl_char_event_hook; utils::hook::detour cl_key_event_hook; utils::hook::detour cl_execute_key_hook; - utils::hook::detour key_get_binding_for_key_hook; int key_get_binding_for_cmd_stub(const char* command); @@ -125,6 +124,18 @@ namespace input return index; } + std::optional get_custom_binding_for_key(int key) + { + key -= get_num_keys(); + + if (static_cast(key) < custom_binds.size() && !custom_binds[key].empty()) + { + return { &custom_binds[key] }; + } + + return {}; + } + int key_get_binding_for_cmd_stub(const char* command) { // original binds @@ -140,16 +151,19 @@ namespace input return get_num_keys() + get_binding_for_custom_command(command); } - std::optional get_custom_binding_for_key(int key) + const char* key_get_cmd_for_binding_stub(int localClientNum, int keyBinding) { - key -= get_num_keys(); - - if (static_cast(key) < custom_binds.size() && !custom_binds[key].empty()) + if (keyBinding >= get_num_keys()) { - return { custom_binds[key] }; + const auto bind = get_custom_binding_for_key(keyBinding); + if (bind.has_value()) + { + return bind.value()->data(); + } + return ""; } - return {}; + return game::command_whitelist[keyBinding]; } void cl_execute_key_stub(const int local_client_num, int key, const int down, const unsigned int time) @@ -162,7 +176,7 @@ namespace input return; } - return game::Cbuf_AddText(local_client_num, utils::string::va("%s\n", bind.value().data())); + 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); @@ -190,6 +204,7 @@ namespace input // links a custom command to an index utils::hook::jump(0x1409A8EA0, key_get_binding_for_cmd_stub); + utils::hook::jump(0x1409A91D0, key_get_cmd_for_binding_stub); // execute custom binds cl_execute_key_hook.create(0x14032A3B0, &cl_execute_key_stub); diff --git a/src/client/game/game.cpp b/src/client/game/game.cpp index 63e23e5..4e49a04 100644 --- a/src/client/game/game.cpp +++ b/src/client/game/game.cpp @@ -2,6 +2,8 @@ #include "game.hpp" #include "dvars.hpp" +#include "component/console/console.hpp" + #include #include #include @@ -253,6 +255,22 @@ namespace game va_buffer ), true); } + + void Key_Bindlist_f() + { + for (int keynum = 0; keynum < 256; ++keynum) + { + auto value = game::Key_GetActiveBinding(0, keynum); + if (value) + { + auto* binding = game::Key_GetCmdForBinding(0, value); + if (*binding) + { + console::info("%s \"%s\"\n", game::Key_KeynumToString(keynum, 0, 0), binding); + } + } + } + } } size_t reverse_b(const size_t ptr) diff --git a/src/client/game/game.hpp b/src/client/game/game.hpp index 04d234e..31c5d3f 100644 --- a/src/client/game/game.hpp +++ b/src/client/game/game.hpp @@ -69,6 +69,8 @@ namespace game bool SV_ClientIsBot(unsigned int client_num); void G_LogPrintf(const char* fmt, ...); + + void Key_Bindlist_f(); } size_t reverse_b(const size_t ptr); diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index b768824..8a14793 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -347,7 +347,7 @@ namespace game int overstrikeMode; int anyKeyDown; KeyState keys[256]; - field_t test; + field_t chatField; char __pad0[8]; }; static_assert(sizeof(PlayerKeyState) == 0x1128); @@ -897,7 +897,27 @@ namespace game entityState_t s; // 0 char __pad0[368 - sizeof(entityState_t)]; gclient_s* client; // 368 - char __pad1[80]; + void* turret; + void* agent; + void* sentient; + void* vehicle; + __int64 physObjId; + unsigned __int16 model; + unsigned __int8 physicsObject; + unsigned __int8 takedamage; + unsigned __int8 active; + unsigned __int8 handler; + unsigned __int8 team; + bool freeAfterEvent; + unsigned __int16 disconnectedLinks; + __int16 padding_short2; + scr_string_t classname; + scr_string_t script_classname; + scr_string_t script_linkName; + scr_string_t target; + scr_string_t targetname; + unsigned int attachIgnoreCollision; + int spawnflags; int flags; // 456 char __pad3[556]; }; static_assert(sizeof(gentity_s) == 1016); diff --git a/src/client/game/symbols.hpp b/src/client/game/symbols.hpp index 5002822..2f975ee 100644 --- a/src/client/game/symbols.hpp +++ b/src/client/game/symbols.hpp @@ -89,6 +89,7 @@ namespace game WEAK symbol DB_ReadRawFile{ 0x140A79E30 }; WEAK symbol DB_GetRawFileLen{ 0x140F20AF0 }; WEAK symbol DB_UnloadFastfilesByZoneFlags{ 0x140A7BCE0 }; + WEAK symbol DB_Zones_GetInUseFlags{ 0x1403BC160 }; WEAK symbol DDL_Lookup_GetEnumString{ 0x140030430 }; WEAK symbol DDL_StateIsLeaf{ 0x14002E3C0 }; @@ -151,7 +152,10 @@ namespace game WEAK symbol I_CleanStr{ 0x140CFACC0 }; - WEAK symbol Key_KeynumToString{ 0x1409A95E0 }; + WEAK symbol Key_KeynumToString{ 0x1409A95E0 }; + WEAK symbol Key_GetActiveBinding{ 0x1409A8E80 }; + WEAK symbol Key_GetCmdForBinding{ 0x1409A91D0 }; + WEAK symbol Key_GetBindingForCmd{ 0x1409A8EA0 }; WEAK symbol LUI_CoD_InFrontEnd{ 0x140615080 }; WEAK symbol LUI_CoD_Init{ 0x140615090 };