Fix lui keydown & keyup events
This commit is contained in:
parent
a63ce4f254
commit
a30132f85c
@ -22,6 +22,7 @@ namespace input
|
||||
utils::hook::detour cl_char_event_hook;
|
||||
utils::hook::detour cl_key_event_hook;
|
||||
utils::hook::detour cl_mouse_move_hook;
|
||||
utils::hook::detour lui_cod_key_event_hook;
|
||||
|
||||
void cl_char_event_stub(const int local_client_num, const int key)
|
||||
{
|
||||
@ -35,12 +36,6 @@ namespace input
|
||||
return;
|
||||
}
|
||||
|
||||
ui_scripting::notify("keypress",
|
||||
{
|
||||
{"keynum", key},
|
||||
{"key", game::Key_KeynumToString(key, 0, 1)},
|
||||
});
|
||||
|
||||
cl_char_event_hook.invoke<void>(local_client_num, key);
|
||||
}
|
||||
|
||||
@ -56,16 +51,22 @@ namespace input
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(*game::keyCatchers & 1) && !(*game::keyCatchers & 0x10))
|
||||
cl_key_event_hook.invoke<void>(local_client_num, key, down);
|
||||
}
|
||||
|
||||
void lui_cod_key_event_stub(const int local_client_num, const int a2, const int key, const int down)
|
||||
{
|
||||
const auto state = *game::hks::lua_state;
|
||||
if (game::LUI_BeginCachedEvent(local_client_num, down ? 3 : 4, state))
|
||||
{
|
||||
ui_scripting::notify(down ? "keydown" : "keyup",
|
||||
{
|
||||
{"keynum", key},
|
||||
{"key", game::Key_KeynumToString(key, 0, 1)},
|
||||
});
|
||||
const auto key_str = game::Key_KeynumToString(key, 0, 1);
|
||||
game::LUI_SetTableInt("keynum", key, state);
|
||||
game::LUI_SetTableString("key", key_str, state);
|
||||
game::LUI_SetTableString("name", down ? "keydown" : "keyup", state);
|
||||
game::LUI_EndEvent(state);
|
||||
}
|
||||
|
||||
cl_key_event_hook.invoke<void>(local_client_num, key, down);
|
||||
lui_cod_key_event_hook.invoke<void>(local_client_num, a2, key, down);
|
||||
}
|
||||
|
||||
void cl_mouse_move_stub(const int local_client_num, int x, int y)
|
||||
@ -84,9 +85,21 @@ namespace input
|
||||
public:
|
||||
void post_unpack() override
|
||||
{
|
||||
static const char* lui_cached_events[5] =
|
||||
{
|
||||
"process_events",
|
||||
"gamepad_button",
|
||||
"transition_complete",
|
||||
"keydown",
|
||||
"keyup",
|
||||
};
|
||||
|
||||
utils::hook::inject(0x14031EB8B, lui_cached_events);
|
||||
|
||||
cl_char_event_hook.create(0x1403D27B0, cl_char_event_stub);
|
||||
cl_key_event_hook.create(0x1403D2AE0, cl_key_event_stub);
|
||||
cl_mouse_move_hook.create(0x1403296F0, cl_mouse_move_stub);
|
||||
lui_cod_key_event_hook.create(0x140328F50, lui_cod_key_event_stub);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -332,6 +332,17 @@ namespace ui_scripting
|
||||
const auto lua = get_globals();
|
||||
lua["EnableGlobals"]();
|
||||
|
||||
table keydown_event{};
|
||||
keydown_event["key"] = "";
|
||||
keydown_event["keynum"] = 0;
|
||||
|
||||
table keyup_event{};
|
||||
keyup_event["key"] = "";
|
||||
keyup_event["keynum"] = 0;
|
||||
|
||||
lua["LUI"]["CachedEvents"]["keydown"] = keydown_event;
|
||||
lua["LUI"]["CachedEvents"]["keyup"] = keyup_event;
|
||||
|
||||
setup_functions();
|
||||
|
||||
lua["print"] = function(reinterpret_cast<game::hks::lua_function>(0x1402B81C0));
|
||||
|
@ -91,6 +91,9 @@ namespace game
|
||||
|
||||
WEAK symbol<void(int clientNum, const char* menu, int a3, int a4, unsigned int a5)> LUI_OpenMenu{0x1405F0EE0};
|
||||
WEAK symbol<bool(int clientNum, const char* name, hks::lua_State* s)> LUI_BeginEvent{0x1403155E0};
|
||||
WEAK symbol<bool(int clientNum, int lui_event_cache, hks::lua_State* s)> LUI_BeginCachedEvent{0x1403153E0};
|
||||
WEAK symbol<void(const char* name, int value, hks::lua_State* s)> LUI_SetTableInt{0x140320060};
|
||||
WEAK symbol<void(const char* name, const char* value, hks::lua_State* s)> LUI_SetTableString{0x1403201F0};
|
||||
WEAK symbol<void(hks::lua_State* s)> LUI_EndEvent{0x140316890};
|
||||
WEAK symbol<void()> LUI_EnterCriticalSection{0x140316980};
|
||||
WEAK symbol<void()> LUI_LeaveCriticalSection{0x14031BC20};
|
||||
|
Loading…
x
Reference in New Issue
Block a user