mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-07 23:15:52 +01:00
Update main.cpp
This commit is contained in:
parent
a413042c11
commit
98d2362cde
206
main.cpp
206
main.cpp
@ -1,158 +1,184 @@
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include <android/log.h>
|
||||
#include <android/input.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES3/gl3.h>
|
||||
#include <dlfcn.h>
|
||||
#include "dobby.h"
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_android.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include "dobby.h"
|
||||
#include <android/log.h>
|
||||
#include <android/input.h>
|
||||
|
||||
#define TAG "AndKitty_Menu"
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
|
||||
#define LOG_TAG "AndKitty_Menu"
|
||||
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
|
||||
|
||||
// --- 全局变量与状态 ---
|
||||
static bool g_Initialized = false;
|
||||
static bool g_ShowMenu = true;
|
||||
static float g_MenuX = 100.0f;
|
||||
static float g_MenuY = 100.0f;
|
||||
|
||||
// 触摸状态全局变量 (数据补偿池)
|
||||
// 触摸状态全局快照 (用于底层拦截同步)
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
bool down;
|
||||
int count;
|
||||
} g_CompensatedTouch = {0, 0, false, 0};
|
||||
} g_RealTimeTouch = {0.0f, 0.0f, false};
|
||||
|
||||
// --- 原函数指针声明 ---
|
||||
typedef EGLBoolean (*p_eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface);
|
||||
static p_eglSwapBuffers old_eglSwapBuffers = nullptr;
|
||||
|
||||
// --- 深度补偿 Hook: 即使 Unity 不走 Queue,只要它读坐标,我们就截获 ---
|
||||
typedef float (*p_AMotionEvent_getX)(const AInputEvent* motion_event, size_t pointer_index);
|
||||
static p_AMotionEvent_getX old_getX = nullptr;
|
||||
|
||||
typedef float (*p_AMotionEvent_getRawX)(const AInputEvent* motion_event, size_t pointer_index);
|
||||
static p_AMotionEvent_getRawX old_getRawX = nullptr;
|
||||
|
||||
typedef float (*p_AMotionEvent_getRawY)(const AInputEvent* motion_event, size_t pointer_index);
|
||||
static p_AMotionEvent_getRawY old_getRawY = nullptr;
|
||||
typedef float (*p_AMotionEvent_getY)(const AInputEvent* motion_event, size_t pointer_index);
|
||||
static p_AMotionEvent_getY old_getY = nullptr;
|
||||
|
||||
typedef int32_t (*p_AMotionEvent_getAction)(const AInputEvent* motion_event);
|
||||
static p_AMotionEvent_getAction old_getAction = nullptr;
|
||||
|
||||
float hook_AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) {
|
||||
float x = old_getRawX(motion_event, pointer_index);
|
||||
if (g_ShowMenu && pointer_index == 0) {
|
||||
g_CompensatedTouch.x = x;
|
||||
g_CompensatedTouch.count++;
|
||||
}
|
||||
// --- 触摸 Hook 回调 ---
|
||||
// 拦截系统底层坐标换算,确保拿到最真实的点击位置
|
||||
float hook_AMotionEvent_getX(const AInputEvent* event, size_t index) {
|
||||
float x = old_getX(event, index);
|
||||
if (index == 0) g_RealTimeTouch.x = x;
|
||||
return x;
|
||||
}
|
||||
|
||||
float hook_AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) {
|
||||
float y = old_getRawY(motion_event, pointer_index);
|
||||
if (g_ShowMenu && pointer_index == 0) {
|
||||
g_CompensatedTouch.y = y;
|
||||
}
|
||||
float hook_AMotionEvent_getY(const AInputEvent* event, size_t index) {
|
||||
float y = old_getY(event, index);
|
||||
if (index == 0) g_RealTimeTouch.y = y;
|
||||
return y;
|
||||
}
|
||||
|
||||
int32_t hook_AMotionEvent_getAction(const AInputEvent* motion_event) {
|
||||
int32_t action = old_getAction(motion_event);
|
||||
if (g_ShowMenu) {
|
||||
int32_t code = action & AMOTION_EVENT_ACTION_MASK;
|
||||
if (code == AMOTION_EVENT_ACTION_DOWN || code == AMOTION_EVENT_ACTION_POINTER_DOWN) {
|
||||
g_CompensatedTouch.down = true;
|
||||
} else if (code == AMOTION_EVENT_ACTION_UP || code == AMOTION_EVENT_ACTION_POINTER_UP || code == AMOTION_EVENT_ACTION_CANCEL) {
|
||||
g_CompensatedTouch.down = false;
|
||||
}
|
||||
}
|
||||
int32_t hook_AMotionEvent_getAction(const AInputEvent* event) {
|
||||
int32_t action = old_getAction(event);
|
||||
int32_t code = action & AMOTION_EVENT_ACTION_MASK;
|
||||
|
||||
// 处理按下与抬起状态
|
||||
if (code == AMOTION_EVENT_ACTION_DOWN || code == AMOTION_EVENT_ACTION_POINTER_DOWN)
|
||||
g_RealTimeTouch.down = true;
|
||||
else if (code == AMOTION_EVENT_ACTION_UP || code == AMOTION_EVENT_ACTION_POINTER_UP || code == AMOTION_EVENT_ACTION_CANCEL)
|
||||
g_RealTimeTouch.down = false;
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
// 渲染钩子
|
||||
EGLBoolean hook_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
|
||||
if (!g_Initialized) {
|
||||
EGLint width, height;
|
||||
eglQuerySurface(dpy, surface, EGL_WIDTH, &width);
|
||||
eglQuerySurface(dpy, surface, EGL_HEIGHT, &height);
|
||||
// --- 渲染逻辑 ---
|
||||
void SetupImGui(int width, int height) {
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// 设置字体大小等 UI 风格
|
||||
ImGui::StyleColorsDark();
|
||||
ImGui_ImplOpenGL3_Init("#version 300 es");
|
||||
g_Initialized = true;
|
||||
LOGI("ImGui Initialized: %dx%d", width, height);
|
||||
}
|
||||
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.DisplaySize = ImVec2((float)width, (float)height);
|
||||
|
||||
float scale = (float)width / 1920.0f;
|
||||
ImGui::GetStyle().ScaleAllSizes(scale > 1.2f ? scale : 1.2f);
|
||||
|
||||
ImGui_ImplOpenGL3_Init("#version 300 es");
|
||||
g_Initialized = true;
|
||||
LOGI("ImGui Context Created.");
|
||||
EGLBoolean hook_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
|
||||
static int width = 0, height = 0;
|
||||
if (width == 0 || height == 0) {
|
||||
EGLint w, h;
|
||||
eglQuerySurface(dpy, surface, EGL_WIDTH, &w);
|
||||
eglQuerySurface(dpy, surface, EGL_HEIGHT, &h);
|
||||
width = w; height = h;
|
||||
}
|
||||
|
||||
if (!g_Initialized) {
|
||||
SetupImGui(width, height);
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
if (g_ShowMenu) {
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
// 强制将补偿的触摸数据注入 ImGui
|
||||
io.MousePos = ImVec2(g_CompensatedTouch.x, g_CompensatedTouch.y);
|
||||
io.MouseDown[0] = g_CompensatedTouch.down;
|
||||
// 【核心注入】:将底层 Hook 拿到的坐标强制塞给 ImGui
|
||||
io.MousePos = ImVec2(g_RealTimeTouch.x, g_RealTimeTouch.y);
|
||||
io.MouseDown[0] = g_RealTimeTouch.down;
|
||||
io.DisplaySize = ImVec2((float)width, (float)height);
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
// 绘制菜单界面
|
||||
ImGui::SetNextWindowPos(ImVec2(g_MenuX, g_MenuY), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 300), ImGuiCond_FirstUseEver);
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(100, 100), ImGuiCond_FirstUseEver);
|
||||
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
|
||||
|
||||
if (ImGui::Begin("AndKitty SGame Ultimate", &g_ShowMenu)) {
|
||||
ImGui::TextColored(ImVec4(0,1,1,1), "Direct Hook Active");
|
||||
ImGui::Text("Captured Count: %d", g_CompensatedTouch.count);
|
||||
ImGui::Text("Last Pos: %.1f, %.1f", g_CompensatedTouch.x, g_CompensatedTouch.y);
|
||||
ImGui::Text("Touch Status: %s", g_CompensatedTouch.down ? "HOLDING" : "IDLE");
|
||||
|
||||
if (ImGui::Begin("AndKitty Mod Menu", &g_ShowMenu)) {
|
||||
ImGui::Text("Status: Running");
|
||||
ImGui::Separator();
|
||||
if (ImGui::Button("Reset Trace")) g_CompensatedTouch.count = 0;
|
||||
|
||||
static bool esp = true;
|
||||
ImGui::Checkbox("Draw ESP", &esp);
|
||||
static bool esp = false;
|
||||
ImGui::Checkbox("Enable ESP", &esp);
|
||||
|
||||
static float aim_speed = 5.0f;
|
||||
ImGui::SliderFloat("Aim Speed", &aim_speed, 1.0f, 20.0f);
|
||||
|
||||
if (ImGui::Button("Hide Menu")) {
|
||||
g_ShowMenu = false;
|
||||
}
|
||||
|
||||
// 调试信息:显示实时捕获的坐标
|
||||
ImGui::Text("Touch: X:%.1f Y:%.1f (%s)",
|
||||
g_RealTimeTouch.x, g_RealTimeTouch.y,
|
||||
g_RealTimeTouch.down ? "DOWN" : "UP");
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
return old_eglSwapBuffers(dpy, surface);
|
||||
}
|
||||
|
||||
// --- 初始化线程 ---
|
||||
void* init_thread(void*) {
|
||||
// 等待 libunity.so 及其依赖库加载
|
||||
LOGI("Plugin thread: waiting for modules...");
|
||||
while (true) {
|
||||
if (dlopen("libunity.so", RTLD_NOLOAD)) break;
|
||||
usleep(500000);
|
||||
LOGI("Plugin thread started, waiting for game initialization...");
|
||||
sleep(15); // 等待游戏过掉检测和 Logo 加载
|
||||
|
||||
// 1. Hook 渲染函数
|
||||
void* egl_addr = dlsym(RTLD_DEFAULT, "eglSwapBuffers");
|
||||
if (egl_addr) {
|
||||
DobbyHook(egl_addr, (void*)hook_eglSwapBuffers, (void**)&old_eglSwapBuffers);
|
||||
LOGI("Hooked eglSwapBuffers at %p", egl_addr);
|
||||
}
|
||||
sleep(10);
|
||||
|
||||
// 1. Hook 渲染
|
||||
void* swap_addr = dlsym(RTLD_DEFAULT, "eglSwapBuffers");
|
||||
if (swap_addr) DobbyHook(swap_addr, (void*)hook_eglSwapBuffers, (void**)&old_eglSwapBuffers);
|
||||
|
||||
// 2. 深度 Hook libandroid.so 导出的原始函数
|
||||
// 即使 Unity 绕过了 AInputQueue,它读坐标时也大概率会调这些导出的 API
|
||||
// 2. Hook 底层触摸 (libandroid.so)
|
||||
// 即使游戏屏蔽了上层的 InputQueue,底层的这些函数依然会被调用
|
||||
void* h_android = dlopen("libandroid.so", RTLD_NOW);
|
||||
if (h_android) {
|
||||
void* getRawX = dlsym(h_android, "AMotionEvent_getRawX");
|
||||
void* getRawY = dlsym(h_android, "AMotionEvent_getRawY");
|
||||
void* getX = dlsym(h_android, "AMotionEvent_getX");
|
||||
void* getY = dlsym(h_android, "AMotionEvent_getY");
|
||||
void* getAction = dlsym(h_android, "AMotionEvent_getAction");
|
||||
|
||||
if (getRawX) DobbyHook(getRawX, (void*)hook_AMotionEvent_getRawX, (void**)&old_getRawX);
|
||||
if (getRawY) DobbyHook(getRawY, (void*)hook_AMotionEvent_getRawY, (void**)&old_getRawY);
|
||||
if (getX) DobbyHook(getX, (void*)hook_AMotionEvent_getX, (void**)&old_getX);
|
||||
if (getY) DobbyHook(getY, (void*)hook_AMotionEvent_getY, (void**)&old_getY);
|
||||
if (getAction) DobbyHook(getAction, (void*)hook_AMotionEvent_getAction, (void**)&old_getAction);
|
||||
|
||||
LOGI("Deep Touch Hooks applied.");
|
||||
LOGI("Touch Force-Sync Hooks Applied!");
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
__attribute__((constructor)) void init_plugin() {
|
||||
// .so 加载入口
|
||||
__attribute__((constructor))
|
||||
void main_entry() {
|
||||
pthread_t t;
|
||||
pthread_create(&t, nullptr, init_thread, nullptr);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user