diff --git a/main.cpp b/main.cpp index 4a0b4684e..72508b7ef 100644 --- a/main.cpp +++ b/main.cpp @@ -15,35 +15,47 @@ static bool g_Initialized = false; -// --- 触摸数据结构 --- +/** + * 分屏坐标对齐逻辑: + * 物理分辨率 (wm size): 2400 x 3392 + * 渲染分辨率 (EGL Query): 1426 x 1008 + * 比例计算: + * X = 1426 / 2400 = 0.594166667 + * Y = 1008 / 3392 = 0.297169811 + */ struct { float x, y; bool down; - // 使用 Frida 测出的分屏比例 (1426 / 2802) - float scaleX = 0.5089f; - float scaleY = 0.5089f; + // 采用物理分辨率对齐后的精确比例 + float scaleX = 0.594166667f; + float scaleY = 0.297169811f; } g_Touch = {0, 0, false}; typedef EGLBoolean (*p_eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface); static p_eglSwapBuffers old_eglSwapBuffers = nullptr; -// --- 触摸事件处理逻辑 --- +// 触摸事件分发处理 void handle_android_event(AInputEvent* event) { if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_MOTION) { int32_t action = AMotionEvent_getAction(event) & AMOTION_EVENT_ACTION_MASK; + + // 拿取系统原始物理坐标 float lx = AMotionEvent_getX(event, 0); float ly = AMotionEvent_getY(event, 0); - // 映射坐标到 ImGui + // 像素级映射转换 g_Touch.x = lx * g_Touch.scaleX; g_Touch.y = ly * g_Touch.scaleY; - if (action == AMOTION_EVENT_ACTION_DOWN) g_Touch.down = true; - else if (action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL) g_Touch.down = false; + if (action == AMOTION_EVENT_ACTION_DOWN) { + g_Touch.down = true; + } else if (action == AMOTION_EVENT_ACTION_UP || action == AMOTION_EVENT_ACTION_CANCEL) { + g_Touch.down = false; + } } } -// --- InputConsumer Hook --- +// Hook InputConsumer::consume (解决分屏触摸的关键) typedef int (*p_InputConsumer_consume)(void* instance, void* factory, bool consumeBatches, int64_t frameTime, uint32_t* outSeq, void** outEvent); static p_InputConsumer_consume old_consume = nullptr; @@ -55,86 +67,94 @@ int hook_consume(void* a, void* b, bool c, int64_t d, uint32_t* e, void** f) { return res; } -// 渲染钩子函数 +// 渲染钩子 EGLBoolean hook_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { - if (!g_Initialized) { - LOGI("Successfully Entered Hook! Initializing ImGui..."); - - EGLint width, height; - eglQuerySurface(dpy, surface, EGL_WIDTH, &width); - eglQuerySurface(dpy, surface, EGL_HEIGHT, &height); - LOGI("Detected Display Size: %d x %d", width, height); + EGLint width, height; + eglQuerySurface(dpy, surface, EGL_WIDTH, &width); + eglQuerySurface(dpy, surface, EGL_HEIGHT, &height); + if (width <= 0 || height <= 0) return old_eglSwapBuffers(dpy, surface); + + if (!g_Initialized) { + LOGI("Initializing ImGui... Render: %d x %d", width, height); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)width, (float)height); - ImGui::GetStyle().ScaleAllSizes(3.0f); + // 针对 2400x3392 高分屏调整 UI 大小 + ImGui::GetStyle().ScaleAllSizes(4.0f); + io.FontGlobalScale = 4.0f; ImGui_ImplOpenGL3_Init("#version 300 es"); g_Initialized = true; - LOGI("ImGui Initialized Successfully!"); } - // 同步触摸状态到 ImGui ImGuiIO& io = ImGui::GetIO(); + io.DisplaySize = ImVec2((float)width, (float)height); + + // 将转换后的坐标传递给 ImGui io.MousePos = ImVec2(g_Touch.x, g_Touch.y); io.MouseDown[0] = g_Touch.down; ImGui_ImplOpenGL3_NewFrame(); ImGui::NewFrame(); - // 强制显示一个简单的测试窗口 + // 绘制一个同步圆点:如果这个圆点不在你指尖,说明 wm size 有误或系统有额外偏移 + if (g_Touch.down) { + ImGui::GetForegroundDrawList()->AddCircleFilled(io.MousePos, 20.0f, IM_COL32(255, 0, 0, 255)); + } + ImGui::SetNextWindowPos(ImVec2(100, 100), ImGuiCond_FirstUseEver); - ImGui::SetNextWindowSize(ImVec2(600, 400), ImGuiCond_FirstUseEver); + ImGui::SetNextWindowSize(ImVec2(800, 500), ImGuiCond_FirstUseEver); - if (ImGui::Begin("AndKitty Menu", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { - ImGui::TextColored(ImVec4(1,1,0,1), "Plugin Status: ACTIVE"); + if (ImGui::Begin("AndKitty SGame Precision", nullptr, ImGuiWindowFlags_NoCollapse)) { + ImGui::Text("Physical: 2400x3392"); + ImGui::Text("Render: %d x %d", width, height); + ImGui::Text("Input: %.1f, %.1f", g_Touch.x, g_Touch.y); ImGui::Separator(); - ImGui::Text("Touch Pos: %.1f, %.1f", g_Touch.x, g_Touch.y); - ImGui::Text("Package: com.tencent.jkchess"); - static bool test_check = true; - ImGui::Checkbox("Test Feature", &test_check); + ImGui::Checkbox("Precision Mode", &test_check); - ImGui::SliderFloat("ScaleX", &g_Touch.scaleX, 0.4f, 1.2f); - - if (ImGui::Button("Close Menu", ImVec2(-1, 60))) { - // 逻辑处理 + if (ImGui::Button("Reset Menu Pos", ImVec2(-1, 80))) { + ImGui::SetWindowPos(ImVec2(100, 100)); } + ImGui::End(); } ImGui::Render(); + + // 渲染保护 + GLint last_depth; + glGetIntegerv(GL_DEPTH_TEST, &last_depth); + glDisable(GL_DEPTH_TEST); + ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); + + if (last_depth) glEnable(GL_DEPTH_TEST); return old_eglSwapBuffers(dpy, surface); } void* init_thread(void*) { - // 已根据要求修改为 5 秒 - LOGI("Step 1: Thread Started, sleeping 5s..."); + // 注入后等待 5 秒,确保游戏渲染已稳定 + LOGI("Plugin thread started. Sleeping 5s..."); sleep(5); - LOGI("Step 2: Searching for symbols..."); - // 1. Hook 渲染 - void* sym_addr = dlsym(RTLD_DEFAULT, "eglSwapBuffers"); - if (sym_addr) { - LOGI("Step 3: Found eglSwapBuffers at %p, Hooking...", sym_addr); - DobbyHook(sym_addr, (void*)hook_eglSwapBuffers, (void**)&old_eglSwapBuffers); + void* sym_egl = dlsym(RTLD_DEFAULT, "eglSwapBuffers"); + if (sym_egl) { + DobbyHook(sym_egl, (void*)hook_eglSwapBuffers, (void**)&old_eglSwapBuffers); } // 2. Hook 输入 const char* consume_sym = "_ZN7android13InputConsumer7consumeEPNS_26InputEventFactoryInterfaceEblPjPPNS_10InputEventE"; void* consume_addr = DobbySymbolResolver("libinput.so", consume_sym); if (consume_addr) { - LOGI("Step 3.5: Found InputConsumer at %p, Hooking...", consume_addr); DobbyHook(consume_addr, (void*)hook_consume, (void**)&old_consume); + LOGI("InputConsumer Hooked Successfully!"); } - LOGI("Step 4: All Done!"); return nullptr; }