Skip to content

Commit

Permalink
add bindlist cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Joelrau committed Jul 15, 2024
1 parent f35b102 commit 4967ed9
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/client/component/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
31 changes: 23 additions & 8 deletions src/client/component/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -125,6 +124,18 @@ namespace input
return index;
}

std::optional<std::string*> get_custom_binding_for_key(int key)
{
key -= get_num_keys();

if (static_cast<size_t>(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
Expand All @@ -140,16 +151,19 @@ namespace input
return get_num_keys() + get_binding_for_custom_command(command);
}

std::optional<std::string> 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<size_t>(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)
Expand All @@ -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<void>(local_client_num, key, down, time);
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/client/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "game.hpp"
#include "dvars.hpp"

#include "component/console/console.hpp"

#include <utils/flags.hpp>
#include <utils/string.hpp>
#include <utils/io.hpp>
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/client/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 22 additions & 2 deletions src/client/game/structs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/client/game/symbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ namespace game
WEAK symbol<char* (const char* filename, char* buf, int size)> DB_ReadRawFile{ 0x140A79E30 };
WEAK symbol<int(const RawFile* rawfile)> DB_GetRawFileLen{ 0x140F20AF0 };
WEAK symbol<void(int flags)> DB_UnloadFastfilesByZoneFlags{ 0x140A7BCE0 };
WEAK symbol<int()> DB_Zones_GetInUseFlags{ 0x1403BC160 };

WEAK symbol<const char* (const DDLState* state, int enumValue)> DDL_Lookup_GetEnumString{ 0x140030430 };
WEAK symbol<bool(const DDLState* state)> DDL_StateIsLeaf{ 0x14002E3C0 };
Expand Down Expand Up @@ -151,7 +152,10 @@ namespace game

WEAK symbol<char* (char* string)> I_CleanStr{ 0x140CFACC0 };

WEAK symbol<const char* (int, int, int)> Key_KeynumToString{ 0x1409A95E0 };
WEAK symbol<const char* (int keynum, int translate, int gamePadOnly)> Key_KeynumToString{ 0x1409A95E0 };
WEAK symbol<int (int localClientNum, int keynum)> Key_GetActiveBinding{ 0x1409A8E80 };
WEAK symbol<const char* (int localClientNum, int keyBinding)> Key_GetCmdForBinding{ 0x1409A91D0 };
WEAK symbol<const char* (const char* cmd)> Key_GetBindingForCmd{ 0x1409A8EA0 };

WEAK symbol<bool()> LUI_CoD_InFrontEnd{ 0x140615080 };
WEAK symbol<void(bool frontend, bool errorRecovery)> LUI_CoD_Init{ 0x140615090 };
Expand Down

0 comments on commit 4967ed9

Please sign in to comment.