mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-06 22:45:48 +01:00
Update main.cpp
This commit is contained in:
parent
769dfb66f0
commit
7aef9fc73c
103
main.cpp
103
main.cpp
@ -5,45 +5,41 @@
|
||||
#include <android/log.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl3.h>
|
||||
#include <dlfcn.h> // 修复:必须包含此头文件以使用 dlopen 和 dlsym
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_android.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include "dobby.h"
|
||||
|
||||
// 日志配置
|
||||
#define LOG_TAG "AndKitty"
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
||||
#define KITTY_LOGI(...) __android_log_print(ANDROID_LOG_INFO, "AndKitty", __VA_ARGS__)
|
||||
|
||||
// --- 全局状态 ---
|
||||
bool g_Initialized = false;
|
||||
bool g_ShowMenu = true;
|
||||
int g_Width = 0;
|
||||
int g_Height = 0;
|
||||
static bool g_Initialized = false;
|
||||
static bool g_ShowMenu = true;
|
||||
static int g_Width = 0;
|
||||
static int g_Height = 0;
|
||||
|
||||
// --- Hook 目标定义 ---
|
||||
typedef EGLBoolean (*eglSwapBuffers_t)(EGLDisplay dpy, EGLSurface surf);
|
||||
eglSwapBuffers_t orig_eglSwapBuffers = nullptr;
|
||||
static eglSwapBuffers_t orig_eglSwapBuffers = nullptr;
|
||||
|
||||
// --- 渲染 UI 逻辑 ---
|
||||
// 渲染主函数
|
||||
void DrawImGuiMenu() {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplAndroid_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
if (g_ShowMenu) {
|
||||
// 设置菜单初始大小
|
||||
ImGui::SetNextWindowSize(ImVec2(g_Width / 3.5f, g_Height / 2.5f), ImGuiCond_FirstUseEver);
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(g_Width / 3.0f, g_Height / 2.0f), ImGuiCond_FirstUseEver);
|
||||
if (ImGui::Begin("AndKitty Mod Menu", &g_ShowMenu)) {
|
||||
ImGui::Text("分辨率: %d x %d", g_Width, g_Height);
|
||||
ImGui::Text("Package: com.tencent.tmgp.sgame");
|
||||
ImGui::Text("Display: %d x %d", g_Width, g_Height);
|
||||
ImGui::Separator();
|
||||
|
||||
static bool aim = false;
|
||||
ImGui::Checkbox("自动瞄准 (Aimbot)", &aim);
|
||||
static bool example_feature = false;
|
||||
ImGui::Checkbox("Feature Test", &example_feature);
|
||||
|
||||
if (ImGui::Button("隐藏菜单 (Hide)")) {
|
||||
if (ImGui::Button("Hide Menu")) {
|
||||
g_ShowMenu = false;
|
||||
}
|
||||
}
|
||||
@ -54,10 +50,13 @@ void DrawImGuiMenu() {
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
|
||||
// --- Hook 后的 eglSwapBuffers ---
|
||||
// 核心 Hook 函数
|
||||
EGLBoolean hook_eglSwapBuffers(EGLDisplay dpy, EGLSurface surf) {
|
||||
// 状态保护:保存当前 GL 绑定,防止 ImGui 渲染干扰游戏逻辑
|
||||
GLint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
|
||||
GLint last_buffer; glGetIntegerv(GL_ARRAY_BUFFER, &last_buffer);
|
||||
|
||||
if (!g_Initialized) {
|
||||
// 动态获取真实屏幕宽高
|
||||
eglQuerySurface(dpy, surf, EGL_WIDTH, &g_Width);
|
||||
eglQuerySurface(dpy, surf, EGL_HEIGHT, &g_Height);
|
||||
|
||||
@ -65,55 +64,65 @@ EGLBoolean hook_eglSwapBuffers(EGLDisplay dpy, EGLSurface surf) {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// 将真实分辨率赋给 ImGui
|
||||
io.DisplaySize = ImVec2((float)g_Width, (float)g_Height);
|
||||
|
||||
// 初始化后端
|
||||
ImGui_ImplAndroid_Init(nullptr);
|
||||
ImGui_ImplOpenGL3_Init("#version 300 es");
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
// 调整 UI 缩放以适配高分屏
|
||||
// 根据高度自动缩放 UI
|
||||
ImGui::GetStyle().ScaleAllSizes(g_Height / 1080.0f);
|
||||
|
||||
g_Initialized = true;
|
||||
LOGI("ImGui 适配完成: %d x %d", g_Width, g_Height);
|
||||
KITTY_LOGI("ImGui Initialized: %dx%d", g_Width, g_Height);
|
||||
}
|
||||
}
|
||||
|
||||
DrawImGuiMenu();
|
||||
if (g_Initialized && g_ShowMenu) {
|
||||
DrawImGuiMenu();
|
||||
}
|
||||
|
||||
// 恢复状态
|
||||
glUseProgram(last_program);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, last_buffer);
|
||||
|
||||
return orig_eglSwapBuffers(dpy, surf);
|
||||
}
|
||||
|
||||
// --- 渲染 Hook 查找 ---
|
||||
void setup_render_hook() {
|
||||
// 显式使用动态链接库操作
|
||||
void* egl_handle = dlopen("libEGL.so", RTLD_LAZY);
|
||||
if (egl_handle) {
|
||||
void* target = dlsym(egl_handle, "eglSwapBuffers");
|
||||
// 实际的线程函数
|
||||
void thread_function() {
|
||||
KITTY_LOGI("Thread started, waiting for EGL...");
|
||||
// 增加等待时间至 15 秒,确保游戏环境自检完成
|
||||
sleep(15);
|
||||
|
||||
void* handle = dlopen("libEGL.so", RTLD_LAZY);
|
||||
if (handle) {
|
||||
void* target = dlsym(handle, "eglSwapBuffers");
|
||||
if (target) {
|
||||
DobbyHook(target, (dobby_dummy_func_t)hook_eglSwapBuffers, (dobby_dummy_func_t*)&orig_eglSwapBuffers);
|
||||
LOGI("成功挂载 eglSwapBuffers");
|
||||
KITTY_LOGI("eglSwapBuffers Hooked Successfully!");
|
||||
}
|
||||
dlclose(handle);
|
||||
}
|
||||
}
|
||||
|
||||
// --- AndKittyInjector 入口 (JNI_OnLoad) ---
|
||||
extern "C" jint JNIEXPORT JNI_OnLoad(JavaVM* vm, void *key) {
|
||||
// 校验 AndKittyInjector 的特有 Key (1337)
|
||||
if (key != (void*)1337) {
|
||||
// 注入器专用入口
|
||||
extern "C" jint JNIEXPORT JNI_OnLoad(JavaVM* vm, void *key)
|
||||
{
|
||||
// 严格校验注入器 Key
|
||||
if (key != (void*)1337)
|
||||
return JNI_VERSION_1_6;
|
||||
|
||||
KITTY_LOGI("JNI_OnLoad called by injector.");
|
||||
|
||||
JNIEnv *env = nullptr;
|
||||
if (vm->GetEnv((void**)&env, JNI_VERSION_1_6) == JNI_OK)
|
||||
{
|
||||
KITTY_LOGI("JavaEnv acquired: %p.", env);
|
||||
}
|
||||
|
||||
LOGI("AndKittyInjector 授权成功,准备注入...");
|
||||
|
||||
std::thread([]() {
|
||||
// 等待游戏渲染环境完全启动
|
||||
sleep(5);
|
||||
setup_render_hook();
|
||||
}).detach();
|
||||
|
||||
|
||||
// 按照文档推荐方式启动线程
|
||||
std::thread(thread_function).detach();
|
||||
|
||||
return JNI_VERSION_1_6;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user