From 5921d565a9a888d30cc16a519546ef086dfd16c7 Mon Sep 17 00:00:00 2001 From: gggaa2152 <60614405+gggaa2152@users.noreply.github.com> Date: Sat, 4 Apr 2026 22:23:51 +0800 Subject: [PATCH] Update main.cpp --- main.cpp | 119 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 84 insertions(+), 35 deletions(-) diff --git a/main.cpp b/main.cpp index c506dff4d..456b6d9ed 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,13 @@ #include +#include +#include +#include #include #include #include #include -#include +// ImGui 核心与渲染器 #include "dobby.h" #include "imgui.h" #include "imgui_impl_android.h" @@ -14,67 +17,113 @@ #define LOG_TAG "JKMenu" #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) -// 存储原始函数 -typedef void (*glFlush_t)(); -glFlush_t orig_glFlush = nullptr; +// 原始函数指针 +typedef EGLBoolean (*eglSwapBuffers_t)(EGLDisplay dpy, EGLSurface surface); +eglSwapBuffers_t orig_eglSwapBuffers = nullptr; +// 全局状态 bool g_Initialized = false; +bool g_ShowMenu = true; +int g_Width = 0; +int g_Height = 0; -// 渲染逻辑 -void PerformRender() { +// 菜单绘制内容 +void DrawImGuiMenu() { + if (!g_ShowMenu) return; + + ImGui::SetNextWindowSize(ImVec2(450, 400), ImGuiCond_FirstUseEver); + ImGui::Begin("JKMenu - OpenGL Mode", &g_ShowMenu); + + ImGui::Text("Device: OnePlus Pad Pro 2"); + ImGui::Text("Package: com.tencent.jkchess"); + ImGui::Text("Screen: %dx%d", g_Width, g_Height); + ImGui::Separator(); + + static bool feature1 = false; + ImGui::Checkbox("显示射线", &feature1); + + static float menu_scale = 1.0f; + ImGui::SliderFloat("菜单缩放", &menu_scale, 0.5f, 2.0f); + + if (ImGui::Button("隐藏菜单 (需重启注入显示)")) { + g_ShowMenu = false; + } + + ImGui::End(); +} + +// 核心 Hook 函数 +EGLBoolean hooked_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { if (!g_Initialized) { - LOGI("SUCCESS!!! glFlush Triggered rendering."); + LOGI("SUCCESS: OpenGL Render triggered via eglSwapBuffers!"); - // 获取当前屏幕宽高 - GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); - - ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); - io.DisplaySize = ImVec2((float)viewport[2], (float)viewport[3]); - - if (ImGui_ImplOpenGL3_Init("#version 300 es")) { - g_Initialized = true; - LOGI("ImGui Initialized via glFlush: %d x %d", viewport[2], viewport[3]); + // 获取实际渲染表面的宽高 + eglQuerySurface(dpy, surface, EGL_WIDTH, &g_Width); + eglQuerySurface(dpy, surface, EGL_HEIGHT, &g_Height); + + if (g_Width > 0 && g_Height > 0) { + ImGui::CreateContext(); + ImGuiIO& io = ImGui::GetIO(); + + // 针对高分辨率平板优化字体大小 + io.FontGlobalScale = 2.5f; + io.DisplaySize = ImVec2((float)g_Width, (float)g_Height); + + if (ImGui_ImplOpenGL3_Init("#version 300 es")) { + g_Initialized = true; + LOGI("ImGui Initialized Successfully!"); + } } } if (g_Initialized) { ImGui_ImplOpenGL3_NewFrame(); ImGui::NewFrame(); - - ImGui::Begin("JKMenu - Emergency Hook"); - ImGui::Text("If you see this, glFlush Hook works!"); - ImGui::End(); + + DrawImGuiMenu(); ImGui::Render(); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } + + return orig_eglSwapBuffers(dpy, surface); } -// Hook 回调 -void hooked_glFlush() { - PerformRender(); - orig_glFlush(); -} - +// 注入后的初始化线程 void* hack_thread(void*) { - LOGI("SO Loaded. Searching for glFlush in libGLESv2..."); - sleep(10); + LOGI("SO Loaded! Waiting for Game Engine..."); + + // 等待游戏加载,金铲铲这类游戏建议等 10-15 秒 + sleep(12); + + // 尝试寻找 Hook 点 + // 1. 标准 EGL 函数 + void* target = DobbySymbolResolver("libEGL.so", "eglSwapBuffers"); + + // 2. 如果标准没搜到,尝试搜腾讯私有渲染函数 + if (!target) { + target = dlsym(RTLD_DEFAULT, "nw_main_swap_buffers"); + } - // glFlush 是 GLES 必调用的函数,比 SwapBuffers 更底层 - void* target = DobbySymbolResolver("libGLESv2.so", "glFlush"); if (target) { - LOGI("Found glFlush at %p, applying hook...", target); - DobbyHook(target, (dobby_dummy_func_t)hooked_glFlush, (dobby_dummy_func_t*)&orig_glFlush); + LOGI("Found render target at %p, applying DobbyHook...", target); + DobbyHook(target, + (dobby_dummy_func_t)hooked_eglSwapBuffers, + (dobby_dummy_func_t*)&orig_eglSwapBuffers); + + if (orig_eglSwapBuffers) { + LOGI("Dobby Hook Applied Successfully!"); + } } else { - LOGI("Failed to find glFlush. This is very strange."); + LOGE("CRITICAL: No render function found. Is the game still in Vulkan mode?"); } return nullptr; } +// 构造函数:SO 加载时自动运行 void __attribute__((constructor)) init() { pthread_t t; pthread_create(&t, nullptr, hack_thread, nullptr);