2022-02-03 14:05:24 -05:00
|
|
|
#include <std_include.hpp>
|
|
|
|
#include "loader/component_loader.hpp"
|
|
|
|
|
|
|
|
#include "game/game.hpp"
|
|
|
|
|
|
|
|
#include "game_console.hpp"
|
2022-04-05 15:41:02 -04:00
|
|
|
#include "game/ui_scripting/execution.hpp"
|
2022-02-03 14:05:24 -05:00
|
|
|
|
|
|
|
#include <utils/hook.hpp>
|
|
|
|
|
|
|
|
namespace input
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
utils::hook::detour cl_char_event_hook;
|
|
|
|
utils::hook::detour cl_key_event_hook;
|
|
|
|
|
|
|
|
void cl_char_event_stub(const int local_client_num, const int key)
|
|
|
|
{
|
2022-06-05 15:50:12 -04:00
|
|
|
if (game::environment::is_sp() && ui_scripting::lui_running())
|
2022-04-05 15:41:02 -04:00
|
|
|
{
|
2022-04-08 10:18:00 -04:00
|
|
|
ui_scripting::notify("keypress",
|
|
|
|
{
|
|
|
|
{"keynum", key},
|
|
|
|
{"key", game::Key_KeynumToString(key, 0, 1)},
|
|
|
|
});
|
|
|
|
}
|
2022-04-05 15:41:02 -04:00
|
|
|
|
2022-02-03 14:05:24 -05:00
|
|
|
if (!game_console::console_char_event(local_client_num, key))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cl_char_event_hook.invoke<void>(local_client_num, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cl_key_event_stub(const int local_client_num, const int key, const int down)
|
|
|
|
{
|
2022-06-05 15:50:12 -04:00
|
|
|
if (game::environment::is_sp() && ui_scripting::lui_running())
|
2022-04-05 15:41:02 -04:00
|
|
|
{
|
2022-04-08 10:18:00 -04:00
|
|
|
ui_scripting::notify(down ? "keydown" : "keyup",
|
|
|
|
{
|
|
|
|
{"keynum", key},
|
2022-06-04 20:04:53 -04:00
|
|
|
{"key", game::Key_KeynumToString(key, 0, 1)},
|
2022-04-08 10:18:00 -04:00
|
|
|
});
|
|
|
|
}
|
2022-04-05 15:41:02 -04:00
|
|
|
|
2022-02-03 14:05:24 -05:00
|
|
|
if (!game_console::console_key_event(local_client_num, key, down))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cl_key_event_hook.invoke<void>(local_client_num, key, down);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class component final : public component_interface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void post_unpack() override
|
|
|
|
{
|
|
|
|
if (game::environment::is_dedi())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-24 11:48:37 -04:00
|
|
|
cl_char_event_hook.create(SELECT_VALUE(0x1AB8F0_b, 0x12C8F0_b), cl_char_event_stub);
|
|
|
|
cl_key_event_hook.create(SELECT_VALUE(0x1ABC20_b, 0x135A70_b), cl_key_event_stub);
|
2022-02-03 14:05:24 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-18 20:14:06 -04:00
|
|
|
REGISTER_COMPONENT(input::component)
|