mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 18:09:26 +08:00
add: support to hook input on real device
This commit is contained in:
@@ -61,10 +61,33 @@ int64_t my_Consume(void* thiz, int64_t arg1, char arg2, int64_t arg3, uint32_t*
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef USE_32
|
||||
using android_InputEvent_initialize_fnT = void*(void* thiz, AInputEvent** input_event);
|
||||
#endif
|
||||
#ifdef USE_64
|
||||
using android_InputEvent_initialize_fnT = long double(void* thiz, AInputEvent** input_event);
|
||||
#endif
|
||||
android_InputEvent_initialize_fnT* old_android_InputEvent_initialize = nullptr;
|
||||
|
||||
#ifdef USE_32
|
||||
void* my_android_InputEvent_initialize(void* thiz, AInputEvent** input_event)
|
||||
#endif
|
||||
#ifdef USE_64
|
||||
long double my_android_InputEvent_initialize(void* thiz, AInputEvent** input_event)
|
||||
#endif
|
||||
{
|
||||
auto result = old_android_InputEvent_initialize(thiz, input_event);
|
||||
if(result != 0 || *input_event == nullptr)
|
||||
return result;
|
||||
ImGui_ImplAndroid_HandleInputEvent(*input_event);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool has_hooked = false;
|
||||
|
||||
#define android_InputConsumer_initializeMotionEvent "_ZN7android13InputConsumer21initializeMotionEventEPNS_11MotionEventEPKNS_12InputMessageE"
|
||||
#define android_InputConsumer_consume "_ZN7android13InputConsumer7consumeEPNS_26InputEventFactoryInterfaceEblPjPPNS_10InputEventE"
|
||||
#define android_InputEvent_initialize "_ZN7android10InputEvent10initializeERKS0_"
|
||||
|
||||
void do_ui_hook() {
|
||||
if (has_hooked) {
|
||||
@@ -99,7 +122,15 @@ void do_ui_hook() {
|
||||
if (sys_consume_status != 0) {
|
||||
SPDLOG_INFO("Hook android_InputConsumer_consume err: {}", sys_consume_status);
|
||||
}
|
||||
|
||||
auto sys_android_InputEvent_initialize = xhook_register(
|
||||
"libinput",
|
||||
android_InputEvent_initialize,
|
||||
reinterpret_cast<void*>(my_android_InputEvent_initialize),
|
||||
reinterpret_cast<void **>(&old_android_InputEvent_initialize)
|
||||
);
|
||||
if (sys_consume_status != 0) {
|
||||
SPDLOG_INFO("Hook android_InputEvent_initialize err: {}", sys_android_InputEvent_initialize);
|
||||
}
|
||||
has_hooked = true;
|
||||
SPDLOG_INFO("Hook ingame ui done!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user