mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-07 06:55:53 +01:00
Update main.cpp
This commit is contained in:
parent
9f6cf5cee6
commit
ea771008f7
33
main.cpp
33
main.cpp
@ -1,44 +1,40 @@
|
||||
#include <jni.h>
|
||||
#include <dlfcn.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h> // 必须包含,修复 sleep 报错
|
||||
#include <unistd.h>
|
||||
#include <android/log.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl3.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include "dobby.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_android.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
|
||||
#define TAG "JKMenu_Core"
|
||||
#define TAG "JKMenu_SGame"
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
|
||||
|
||||
static bool g_Initialized = false;
|
||||
static bool g_VulkanMode = false;
|
||||
|
||||
typedef EGLBoolean (*eglSwapBuffers_t)(EGLDisplay, EGLSurface);
|
||||
static eglSwapBuffers_t old_eglSwapBuffers = nullptr;
|
||||
|
||||
// 简单的 ImGui 菜单界面
|
||||
void DrawJKMenu() {
|
||||
if (!ImGui::GetCurrentContext()) return;
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 300), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("JKMenu - Version 1.0", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Render: %s", g_VulkanMode ? "Vulkan (Limited Support)" : "GLES 3.0 (Active)");
|
||||
ImGui::Begin("JKMenu for SGame", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
ImGui::Text("Build Date: 2026-04-06");
|
||||
ImGui::Separator();
|
||||
if (ImGui::Button("Log Test")) { LOGI("ImGui Button Clicked!"); }
|
||||
static bool hack_enabled = false;
|
||||
ImGui::Checkbox("功能开关示例", &hack_enabled);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
// OpenGL 渲染 Hook
|
||||
EGLBoolean hook_eglSwapBuffers(EGLDisplay dpy, EGLSurface surf) {
|
||||
if (!g_Initialized) {
|
||||
ImGui::CreateContext();
|
||||
ImGui_ImplAndroid_Init(nullptr);
|
||||
ImGui_ImplOpenGL3_Init("#version 300 es");
|
||||
g_Initialized = true;
|
||||
LOGI("ImGui Initialized in SGame process.");
|
||||
}
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplAndroid_NewFrame();
|
||||
@ -50,20 +46,13 @@ EGLBoolean hook_eglSwapBuffers(EGLDisplay dpy, EGLSurface surf) {
|
||||
}
|
||||
|
||||
void* init_thread(void*) {
|
||||
LOGI("JKMenu init_thread started...");
|
||||
sleep(5); // 等待游戏完全进入
|
||||
|
||||
// 探测 Vulkan 驱动
|
||||
if (dlopen("vulkan.adreno.so", RTLD_NOLOAD)) {
|
||||
g_VulkanMode = true;
|
||||
LOGI("Detected Vulkan. Switch to Compatibility Mode if menu is invisible.");
|
||||
}
|
||||
|
||||
// 挂载 EGL Hook (libEGL.so 在 Android 兼容模式下必用)
|
||||
// 王者荣耀启动较慢,建议延迟 10 秒等待渲染库加载完毕
|
||||
sleep(10);
|
||||
|
||||
void* egl_addr = DobbySymbolResolver("libEGL.so", "eglSwapBuffers");
|
||||
if (egl_addr) {
|
||||
DobbyHook(egl_addr, (void*)hook_eglSwapBuffers, (void**)&old_eglSwapBuffers);
|
||||
LOGI("GLES Hooked successfully.");
|
||||
LOGI("Hook eglSwapBuffers Success!");
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user