2021-09-06 18:40:37 -04:00
|
|
|
#include <std_include.hpp>
|
2021-04-23 14:57:21 -04:00
|
|
|
#include "loader/component_loader.hpp"
|
2021-04-19 18:56:11 -04:00
|
|
|
|
|
|
|
#include "game/game.hpp"
|
|
|
|
|
|
|
|
#include "game_console.hpp"
|
2021-12-19 11:42:37 -05:00
|
|
|
#include "gui.hpp"
|
2022-03-22 15:27:20 -04:00
|
|
|
#include "game/ui_scripting/execution.hpp"
|
2021-04-19 18:56:11 -04:00
|
|
|
|
|
|
|
#include <utils/hook.hpp>
|
|
|
|
|
|
|
|
namespace input
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2021-09-09 21:21:51 -04:00
|
|
|
struct point
|
|
|
|
{
|
|
|
|
short x;
|
|
|
|
short y;
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:56:11 -04:00
|
|
|
utils::hook::detour cl_char_event_hook;
|
|
|
|
utils::hook::detour cl_key_event_hook;
|
2021-09-09 21:21:51 -04:00
|
|
|
utils::hook::detour cl_mouse_move_hook;
|
2021-04-19 18:56:11 -04:00
|
|
|
|
|
|
|
void cl_char_event_stub(const int local_client_num, const int key)
|
|
|
|
{
|
2022-04-18 20:22:59 -04:00
|
|
|
if (!game_console::console_char_event(local_client_num, key))
|
2022-03-22 15:27:20 -04:00
|
|
|
{
|
2022-04-18 14:01:23 -04:00
|
|
|
return;
|
|
|
|
}
|
2021-09-09 21:21:51 -04:00
|
|
|
|
2022-04-18 20:22:59 -04:00
|
|
|
if (!gui::gui_char_event(local_client_num, key))
|
2021-04-19 18:56:11 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-18 14:01:23 -04:00
|
|
|
ui_scripting::notify("keypress",
|
2021-12-19 11:42:37 -05:00
|
|
|
{
|
2022-04-18 14:01:23 -04:00
|
|
|
{"keynum", key},
|
|
|
|
{"key", game::Key_KeynumToString(key, 0, 1)},
|
|
|
|
});
|
2021-12-19 11:42:37 -05:00
|
|
|
|
2021-04-19 18:56:11 -04:00
|
|
|
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-04-18 20:22:59 -04:00
|
|
|
if (!game_console::console_key_event(local_client_num, key, down))
|
2022-03-22 15:27:20 -04:00
|
|
|
{
|
2022-04-18 14:01:23 -04:00
|
|
|
return;
|
|
|
|
}
|
2021-09-09 21:21:51 -04:00
|
|
|
|
2022-04-18 20:22:59 -04:00
|
|
|
if (!gui::gui_key_event(local_client_num, key, down))
|
2021-04-19 18:56:11 -04:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-18 14:01:23 -04:00
|
|
|
if (!(*game::keyCatchers & 1) && !(*game::keyCatchers & 0x10))
|
2021-12-19 11:42:37 -05:00
|
|
|
{
|
2022-04-18 14:01:23 -04:00
|
|
|
ui_scripting::notify(down ? "keydown" : "keyup",
|
|
|
|
{
|
|
|
|
{"keynum", key},
|
|
|
|
{"key", game::Key_KeynumToString(key, 0, 1)},
|
|
|
|
});
|
2021-12-19 11:42:37 -05:00
|
|
|
}
|
|
|
|
|
2021-04-19 18:56:11 -04:00
|
|
|
cl_key_event_hook.invoke<void>(local_client_num, key, down);
|
|
|
|
}
|
2021-09-09 21:21:51 -04:00
|
|
|
|
|
|
|
void cl_mouse_move_stub(const int local_client_num, int x, int y)
|
|
|
|
{
|
2021-12-19 11:42:37 -05:00
|
|
|
if (!gui::gui_mouse_event(local_client_num, x, y))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-09 21:21:51 -04:00
|
|
|
cl_mouse_move_hook.invoke<void>(local_client_num, x, y);
|
|
|
|
}
|
2021-04-19 18:56:11 -04:00
|
|
|
}
|
|
|
|
|
2021-04-23 14:57:21 -04:00
|
|
|
class component final : public component_interface
|
2021-04-19 18:56:11 -04:00
|
|
|
{
|
2021-04-23 14:57:21 -04:00
|
|
|
public:
|
|
|
|
void post_unpack() override
|
|
|
|
{
|
2022-03-18 17:02:44 -04:00
|
|
|
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);
|
2021-04-23 14:57:21 -04:00
|
|
|
}
|
|
|
|
};
|
2021-04-19 18:56:11 -04:00
|
|
|
}
|
2021-04-23 14:57:21 -04:00
|
|
|
|
|
|
|
REGISTER_COMPONENT(input::component)
|