From 71bf14a7950fc046ec5862b3385362879c50c2ef Mon Sep 17 00:00:00 2001 From: gggaa2152 <60614405+gggaa2152@users.noreply.github.com> Date: Sat, 4 Apr 2026 22:09:37 +0800 Subject: [PATCH] Update main.cpp --- main.cpp | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/main.cpp b/main.cpp index 7c028c97d..4ef2f2b6a 100644 --- a/main.cpp +++ b/main.cpp @@ -25,7 +25,6 @@ typedef EGLBoolean (*eglSwapBuffers_t)(EGLDisplay dpy, EGLSurface surface); eglSwapBuffers_t orig_eglSwapBuffers = nullptr; -// Vulkan 相关的简单定义 (用于寻找符号) typedef void* (*vkQueuePresentKHR_t)(void* queue, const void* pPresentInfo); vkQueuePresentKHR_t orig_vkQueuePresentKHR = nullptr; @@ -34,21 +33,28 @@ bool g_Initialized = false; bool g_ShowMenu = true; int g_Width = 0; int g_Height = 0; +bool g_IsVulkanMode = false; -// 菜单渲染逻辑 +// 菜单渲染逻辑 (仅限 GLES 环境) void DrawImGuiMenu() { if (!g_ShowMenu) return; ImGui::SetNextWindowSize(ImVec2(400, 350), ImGuiCond_FirstUseEver); - ImGui::Begin("JKMenu - Dual Renderer Support", &g_ShowMenu); + ImGui::Begin("JKMenu - Renderer Check", &g_ShowMenu); ImGui::Text("Device: OnePlus Pad Pro 2"); ImGui::Text("Target: com.tencent.jkchess"); + ImGui::Text("Mode: %s", g_IsVulkanMode ? "Vulkan (Unsupported)" : "GLES3 (Active)"); ImGui::Text("Screen: %dx%d", g_Width, g_Height); ImGui::Separator(); - static float f = 0.5f; - ImGui::SliderFloat("Scale", &f, 0.1f, 2.0f); + if (g_IsVulkanMode) { + ImGui::TextColored(ImVec4(1, 0, 0, 1), "ERROR: Cannot draw in Vulkan mode!"); + ImGui::Text("Please disable High Quality in settings."); + } else { + static float f = 0.5f; + ImGui::SliderFloat("Scale", &f, 0.1f, 2.0f); + } if (ImGui::Button("Hide Menu")) { g_ShowMenu = false; @@ -60,14 +66,16 @@ void DrawImGuiMenu() { // OpenGL 渲染执行器 void PerformRenderGLES(EGLDisplay dpy, EGLSurface surface) { if (!g_Initialized) { - LOGI("SUCCESS! OpenGL Render function triggered."); + LOGI("SUCCESS! OpenGL (GLES) Render triggered."); eglQuerySurface(dpy, surface, EGL_WIDTH, &g_Width); eglQuerySurface(dpy, surface, EGL_HEIGHT, &g_Height); + if (g_Width <= 0 || g_Height <= 0) return; ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = ImVec2((float)g_Width, (float)g_Height); + if (ImGui_ImplOpenGL3_Init("#version 300 es")) { g_Initialized = true; LOGI("ImGui GLES Initialized: %dx%d", g_Width, g_Height); @@ -85,46 +93,47 @@ void PerformRenderGLES(EGLDisplay dpy, EGLSurface surface) { // Hook 回调: OpenGL EGLBoolean hooked_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) { + g_IsVulkanMode = false; PerformRenderGLES(dpy, surface); return orig_eglSwapBuffers(dpy, surface); } -// Hook 回调: Vulkan (仅做日志记录,提醒用户切换模式) +// Hook 回调: Vulkan void* hooked_vkQueuePresentKHR(void* queue, const void* pPresentInfo) { - static bool logged_vk = false; - if (!logged_vk) { - LOGI("DETECTED: Game is using Vulkan Renderer! ImGui GLES will NOT show."); - LOGI("Please disable 'High Frame Rate' or 'Ultra Graphics' in game settings."); - logged_vk = true; + static int vk_warn_count = 0; + g_IsVulkanMode = true; + if (vk_warn_count % 300 == 0) { + LOGE("Vulkan Present triggered! Please switch game to GLES mode to see menu."); } + vk_warn_count++; return orig_vkQueuePresentKHR(queue, pPresentInfo); } // 动态搜索并 Hook void* hack_thread(void*) { - LOGI("SO Loaded! Waiting 10s for engine..."); + LOGI("SO Loaded! Starting Multi-Renderer Scanner..."); sleep(10); - // 1. Hook OpenGL (主要渲染器) + // 1. 尝试 Hook OpenGL (GLES) const char* gles_syms[] = {"eglSwapBuffers", "nw_main_swap_buffers"}; for (const char* sym : gles_syms) { void* target = DobbySymbolResolver("libEGL.so", sym); if (!target) target = dlsym(RTLD_DEFAULT, sym); if (target) { - LOGI("Found GLES target: %s at %p", sym, target); + LOGI("Found GLES Hook Point: %s at %p", sym, target); DobbyHook(target, (dobby_dummy_func_t)hooked_eglSwapBuffers, (dobby_dummy_func_t*)&orig_eglSwapBuffers); } } - // 2. Hook Vulkan (用于监测) + // 2. 尝试 Hook Vulkan (仅用于识别状态) void* vk_target = DobbySymbolResolver("libvulkan.so", "vkQueuePresentKHR"); if (vk_target) { - LOGI("Found Vulkan target: vkQueuePresentKHR at %p", vk_target); + LOGI("Found Vulkan Hook Point: vkQueuePresentKHR at %p", vk_target); DobbyHook(vk_target, (dobby_dummy_func_t)hooked_vkQueuePresentKHR, (dobby_dummy_func_t*)&orig_vkQueuePresentKHR); } if (!orig_eglSwapBuffers && !orig_vkQueuePresentKHR) { - LOGE("CRITICAL: No render symbols found at all."); + LOGE("Could not find any render functions!"); } return nullptr;