Update main.cpp

This commit is contained in:
gggaa2152 2026-04-06 08:28:26 +08:00 committed by GitHub
parent e0c48acf1b
commit 87ef53712a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4,6 +4,7 @@
#include <android/log.h>
#include <EGL/egl.h>
#include <GLES3/gl3.h>
#include <dlfcn.h> // 修复:添加此头文件以支持 dlsym, dlopen, RTLD_DEFAULT
#include "dobby.h"
#include "imgui.h"
#include "imgui_impl_android.h"
@ -11,6 +12,7 @@
#define TAG "AndKitty_Menu"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
// 状态控制
static bool g_Initialized = false;
@ -18,7 +20,7 @@ static bool g_ShowMenu = true;
// 原始函数指针
typedef EGLBoolean (*p_eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface);
p_eglSwapBuffers old_eglSwapBuffers = nullptr;
static p_eglSwapBuffers old_eglSwapBuffers = nullptr;
// 菜单渲染逻辑
void DrawMenu() {
@ -26,11 +28,12 @@ void DrawMenu() {
ImGui::SetNextWindowSize(ImVec2(400, 300), ImGuiCond_FirstUseEver);
if (ImGui::Begin("AndKitty Mod Menu", &g_ShowMenu)) {
ImGui::Text("注入成功!");
ImGui::Text("Status: Injected Successfully");
ImGui::Separator();
static bool cheat1 = false;
ImGui::Checkbox("显示射线", &cheat1);
if (ImGui::Button("隐藏菜单")) {
static bool feature_test = false;
ImGui::Checkbox("ESP Line", &feature_test);
if (ImGui::Button("Hide Menu")) {
g_ShowMenu = false;
}
}
@ -43,43 +46,49 @@ EGLBoolean hook_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
LOGI("检测到渲染上下文,正在初始化 ImGui...");
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.DisplaySize = ImVec2(2400, 1080); // 这里可以动态获取
// 默认分辨率设置,防止初始化失败
io.DisplaySize = ImVec2(2400.0f, 1080.0f);
ImGui_ImplOpenGL3_Init("#version 300 es");
g_Initialized = true;
LOGI("ImGui 初始化完毕!");
}
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();
if (g_ShowMenu) {
ImGui_ImplOpenGL3_NewFrame();
ImGui::NewFrame();
DrawMenu();
DrawMenu();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
return old_eglSwapBuffers(dpy, surface);
}
// 插件入口线程
void* init_thread(void*) {
LOGI("插件线程已启动,等待 25 秒避开游戏自检...");
sleep(25); // 王者荣耀建议等待时间拉长,直到进入登录界面
LOGI("插件线程已启动,等待 40 秒避开自检...");
// 王者荣耀建议等待 40 秒,确保进入大厅
sleep(40);
// 获取 eglSwapBuffers 地址
void* sym_addr = dlsym(RTLD_DEFAULT, "eglSwapBuffers");
if (!sym_addr) {
LOGI("无法通过 RTLD_DEFAULT 找到 eglSwapBuffers,尝试直接从 libEGL.so 获取");
LOGI("RTLD_DEFAULT 失败,尝试直接从 libEGL.so 获取");
void* h_egl = dlopen("libEGL.so", RTLD_NOW);
sym_addr = dlsym(h_egl, "eglSwapBuffers");
if (h_egl) sym_addr = dlsym(h_egl, "eglSwapBuffers");
}
if (sym_addr) {
LOGI("目标 eglSwapBuffers 地址: %p,正在执行 Hook...", sym_addr);
DobbyHook(sym_addr, (void*)hook_eglSwapBuffers, (void**)&old_eglSwapBuffers);
LOGI("Hook 完成!请检查屏幕是否有菜单。");
LOGI("Hook 完成!请检查屏幕。");
} else {
LOGI("错误:找不到 eglSwapBuffers 符号!");
LOGE("错误:无法找到 eglSwapBuffers 符号!");
}
return nullptr;