#include <android_native_app_glue.h>
#include <EGL/egl.h>
#include <pthread.h>
#include <unistd.h>
#include <vector>
#include <cstring>
#include <sstream>
#include <regex>
#include <chrono>
#include <fcntl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <mutex>
#include <thread>
#include <atomic>
#include <queue> 
#include "imgui/imgui.h"
#include "imgui/imgui_impl_android.h"
#include "imgui/imgui_impl_opengl3.h"
#include "font.h"
#include "Syscall读写.h"
#include <dobby.h>
#include "SDK.hpp"
#include <cstdlib>   
#include <ctime>     
#include <android/log.h>
#include <fstream>
#include <string>



using namespace SDK;

bool   initImGui   = false;
int    screenWidth = 2400, screenHeight = 1080, glWidth, glHeight;
float  density     = -1;
uintptr_t UE4      = 0;
android_app* g_App = nullptr;

static char BQAQSQEQ[128] = {"OY8/SHeiAuCsQ5w01fyjpla6Uh9GZIb2qNKzMnDXFEmc+R4W7oTPJt3gkBVvLdxr"};

#include "T3/T3验证.h"
static char s[64];
static bool isLogin = true;
static char playerName[64] = "Player"; 
static char g_ActorPath[256] = "";  // 存储用户输入的 Actor 路径
static bool bEnableCameraOverride = false;
static float CamLoc[3] = {0.0f, 0.0f, 0.0f}; // X, Y, Z
static float CamRot[3] = {0.0f, 0.0f, 0.0f}; // Pitch, Yaw, Roll
// 场景管理（原有）
static std::vector<AActor*> g_AllActors;
static int g_SelectedActorIndex = -1;
static bool g_NeedRefreshActors = true;   // 如果不需要可删除

// 新增
enum class EScanMode { Actors, StaticMeshes };
static EScanMode g_ScanMode = EScanMode::Actors;
static std::vector<UStaticMeshComponent*> g_AllStaticMeshes;
static std::vector<AActor*> g_ComponentOwners;
static int g_SelectedComponentIndex = -1;
static float g_SpawnCoordBuffer[3] = { 0.0f, 0.0f, 0.0f }; // 坐标缓冲区（用于指定生成位置）
static char g_CustomClassName[256] = ""; // 用于存储手动输入的类名


#include <jni.h>
#include <sys/system_properties.h>

static std::string GetAndroidID(JNIEnv *env, jobject activity) {
    jclass contextCls = env->FindClass("android/content/Context");
    jmethodID getContentResolver = env->GetMethodID(contextCls, "getContentResolver",
                                                    "()Landroid/content/ContentResolver;");
    jobject resolver = env->CallObjectMethod(activity, getContentResolver);

    jclass secureCls = env->FindClass("android/provider/Settings$Secure");
    jmethodID getString = env->GetStaticMethodID(secureCls, "getString",
                                                 "(Landroid/content/ContentResolver;Ljava/lang/String;)Ljava/lang/String;");
    jstring key = env->NewStringUTF("android_id");
    jstring id  = (jstring)env->CallStaticObjectMethod(secureCls, getString, resolver, key);
    const char* utf = env->GetStringUTFChars(id, nullptr);
    std::string result = utf ? utf : "";
    env->ReleaseStringUTFChars(id, utf);
    env->DeleteLocalRef(key);
    env->DeleteLocalRef(id);
    env->DeleteLocalRef(resolver);
    env->DeleteLocalRef(secureCls);
    env->DeleteLocalRef(contextCls);
    return result;
}

static std::string GetDeviceModel(JNIEnv* env) {
    char buf[PROP_VALUE_MAX]{0};
    __system_property_get("ro.product.model", buf);
    return buf;
}

static std::string GetDeviceBrand(JNIEnv* env) {
    char buf[PROP_VALUE_MAX]{0};
    __system_property_get("ro.product.brand", buf);
    return buf;
}

std::string getClipboardText() {
	if (!g_App)
		return "";
	auto activity = g_App->activity;
	if (!activity)
		return "";
	auto vm = activity->vm;
	if (!vm)
		return "";
	auto object = activity->clazz;
	if (!object)
		return "";
	std::string result;
	JNIEnv *env;
	vm->AttachCurrentThread(&env, 0);
	{
		auto ContextClass = env->FindClass("android/content/Context");
		auto getSystemServiceMethod = env->GetMethodID(ContextClass, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
		auto str = env->NewStringUTF("clipboard");
		auto clipboardManager = env->CallObjectMethod(object, getSystemServiceMethod, str);
		env->DeleteLocalRef(str);
		auto ClipboardManagerClass = env->FindClass("android/content/ClipboardManager");
		auto getText = env->GetMethodID(ClipboardManagerClass, "getText", "()Ljava/lang/CharSequence;");
		auto CharSequenceClass = env->FindClass("java/lang/CharSequence");
		auto toStringMethod = env->GetMethodID(CharSequenceClass, "toString", "()Ljava/lang/String;");
		auto text = env->CallObjectMethod(clipboardManager, getText);
		if (text)
		{
			str = (jstring)env->CallObjectMethod(text, toStringMethod);
			result = env->GetStringUTFChars(str, 0);
			env->DeleteLocalRef(str);
			env->DeleteLocalRef(text);
		}
		env->DeleteLocalRef(CharSequenceClass);
		env->DeleteLocalRef(ClipboardManagerClass);
		env->DeleteLocalRef(clipboardManager);
		env->DeleteLocalRef(ContextClass);
	}
	vm->DetachCurrentThread();
	return result;
}


bool showVirtualKeyboard=false;
void RenderVirtualKeyboard() {
    ImGui::Begin("虚拟键盘");
    
    ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 4);
    if (ImGui::Button("1", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '1';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("2", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '2';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("3", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '3';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("4", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '4';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("5", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '5';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("6", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '6';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("7", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '7';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("8", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '8';
            s[len + 1] = '\0';
        }
    }
    
    ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 4);
    if (ImGui::Button("9", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '9';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("0", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '0';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("Q", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'Q';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("W", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'W';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("E", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'E';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("R", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'R';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("T", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'T';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("Y", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'Y';
            s[len + 1] = '\0';
        }
    }
    
    ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 4);
    if (ImGui::Button("U", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'U';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("I", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'I';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("O", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'O';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("P", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'P';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("A", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'A';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("S", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'S';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("D", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'D';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("F", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'F';
            s[len + 1] = '\0';
        }
    }
    
    ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 4);
    if (ImGui::Button("G", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'G';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("H", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'H';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("J", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'J';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("K", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'K';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("L", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'L';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("Z", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'Z';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("X", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'X';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("C", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'C';
            s[len + 1] = '\0';
        }
    }
    
    ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 4);
    if (ImGui::Button("V", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'V';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("B", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'B';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("N", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'N';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("M", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = 'M';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button(":", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = ':';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button(".", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len < sizeof(s) - 1) {
            s[len] = '.';
            s[len + 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("删除", ImVec2(56, 56))) {
        int len = strlen(s);
        if (len > 0) {
            s[len - 1] = '\0';
        }
    }
    ImGui::SameLine();
    if (ImGui::Button("关闭", ImVec2(56, 56))) {
        showVirtualKeyboard = false;
    }

    ImGui::End();
}

#include <chrono>

enum class EventState {
    None,
    WaitingForB,
    WaitingForC
};
static bool delayAction = false;
static std::chrono::steady_clock::time_point delayStartTime;

static bool delayAction2 = false;
static std::chrono::steady_clock::time_point delayStartTime2;

static std::string currentAutomationMap = "";


static EventState currentState = EventState::None;
static std::mutex              g_ServerMutex;          
static std::atomic<bool>       g_ServerListFetching{false};
static std::atomic<bool>       g_ServerListFetched{false};
bool                           g_OfflineMode = false;  
static int g_MapPage = 0;

static float 巨人 = 1.0f;
static float Gun_Size = 1.0f;
static bool 人物变大 = false;
static bool 枪械变大 = false;
static bool 飞天2 = false;
static bool 飞天1 = false;
static bool 飞天关 = false;
static bool 飞天跳开 = false;
static bool 飞天跳关 = false;
static bool 能量加速开 = false;
static bool 能量加速关 = false;

void OpenMapMainPage()  { g_MapPage = 0; }
void OpenMapOnlinePage(){ g_MapPage = 1; }
void OpenMapOfflinePage(){ g_MapPage = 2; }
void OpenMapTeamPage(){ g_MapPage = 3; }
void OpenMaptrainingPage(){ g_MapPage = 4; }
void OpenMapwarPage(){ g_MapPage = 5; }




static int currentTheme = 0;
static const char* themeNames[] = { "默认主题", "浅色主题", "经典主题" };
static ImVec4 customAccentColor = ImVec4(0.20f, 0.45f, 0.78f, 1.00f);
static ImVec4 accentColor = ImVec4(0.20f, 0.45f, 0.78f, 1.00f);
static ImVec4 successColor = ImVec4(0.16f, 0.70f, 0.32f, 1.00f);
static ImVec4 warningColor = ImVec4(0.95f, 0.60f, 0.07f, 1.00f);

static float g_WindowRounding = 5.0f;
static float g_FrameRounding = 3.0f;
static float g_GrabRounding = 3.0f;
static float g_TabRounding = 4.0f;
static float g_ChildRounding = 4.0f;
static float g_PopupRounding = 5.0f;
static float g_WindowBorderSize = 1.0f;
static float g_FrameBorderSize = 0.5f;
static float g_PopupBorderSize = 1.0f;


void ApplyTheme(int theme) {
    ImGuiStyle& style = ImGui::GetStyle();
    ImVec4* colors = style.Colors;
    
    switch(theme) {
        case 0: 
            ImGui::StyleColorsDark();
            customAccentColor = ImVec4(0.00f, 0.44f, 0.88f, 1.00f);
            break;
        case 1: 
            ImGui::StyleColorsLight();
            customAccentColor = ImVec4(0.00f, 0.47f, 1.00f, 1.00f);
            break;
        case 2: 
            ImGui::StyleColorsClassic();
            customAccentColor = ImVec4(0.00f, 0.60f, 1.00f, 1.00f);
            break;
    }
    style.WindowRounding = g_WindowRounding;
    style.FrameRounding = g_FrameRounding;
    style.GrabRounding = g_GrabRounding;
    style.TabRounding = g_TabRounding;
    style.ChildRounding = g_ChildRounding;
    style.PopupRounding = g_PopupRounding;
    style.WindowBorderSize = g_WindowBorderSize;
    style.FrameBorderSize = g_FrameBorderSize;
    style.PopupBorderSize = g_PopupBorderSize;
    accentColor = customAccentColor;
}


static void log_to_file(const char* fmt, ...) {
    static int fd = -1;
    if (fd == -1)
        fd = open("/data/user/0/com.aure.pubg/files/logs.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    if (fd < 0) return;
    char buf[2048];
    va_list ap;
    va_start(ap, fmt);
    vsnprintf(buf, sizeof(buf), fmt, ap);
    va_end(ap);
    strcat(buf, "\n");
    write(fd, buf, strlen(buf));
    fsync(fd);
}



// --- 新增的全局日志辅助函数 ---
void ExportReferenceToLog(const char* label, const char* content) {
    // 1. 打印到 Android Logcat，过滤 "UE4_Mod" 即可查看
    __android_log_print(ANDROID_LOG_INFO, "UE4_Mod", "[%s] %s", label, content);

    // 2. 写入到本地文件，方便直接打开文本查看
    std::ofstream outfile("/sdcard/UE4_Actor_Log.txt", std::ios_base::app);
    if (outfile.is_open()) {
        outfile << "[" << label << "] " << content << "\n";
        outfile.close();
    } else {
        __android_log_print(ANDROID_LOG_ERROR, "UE4_Mod", "无法写入文件，可能是没有存储权限: /sdcard/UE4_Actor_Log.txt");
    }
}




struct ServerInfo {
    std::string name;
    std::string ipPort;
    int ping = -1;
    int64_t lastPingTime = 0;
    bool isPinging = false;
};

std::mutex serversMutex;
std::vector<ServerInfo> g_Servers;
bool networkThreadRunning = true;
std::thread networkThread;

void updateServerPing(int index, int ping) {
    std::lock_guard<std::mutex> lock(serversMutex);
    if (index >= 0 && index < g_Servers.size()) {
        g_Servers[index].ping = ping;
        g_Servers[index].isPinging = false;
    }
}

int Ping(const std::string& ipPort) {
    size_t colon = ipPort.find(':');
    if (colon == std::string::npos) return -1;
    
    std::string host = ipPort.substr(0, colon);
    int port = std::stoi(ipPort.substr(colon + 1));

    int sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock < 0) return -1;

    struct sockaddr_in addr {};
    addr.sin_family = AF_INET;
    addr.sin_port   = htons(port);
    if (inet_pton(AF_INET, host.c_str(), &addr.sin_addr) <= 0) {
        close(sock);
        return -1;
    }

    struct timeval timeout;
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;
    setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
    setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));

    fcntl(sock, F_SETFL, O_NONBLOCK);
    
    auto t0 = std::chrono::steady_clock::now();
    int connectResult = connect(sock, (sockaddr*)&addr, sizeof(addr));
    
    int ms = -1;
    
    if (connectResult == 0) {
        auto t1 = std::chrono::steady_clock::now();
        ms = (int)std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count();
    } else if (errno == EINPROGRESS) {
        struct pollfd pfd;
        pfd.fd = sock;
        pfd.events = POLLOUT;
        
        int pollResult = poll(&pfd, 1, 300);
        
        if (pollResult > 0 && (pfd.revents & POLLOUT)) {
            auto t1 = std::chrono::steady_clock::now();
            ms = (int)std::chrono::duration_cast<std::chrono::milliseconds>(t1 - t0).count();
        }
    }
    
    close(sock);
    return ms;
}

std::string http_get(const std::string& host, const std::string& path) {
    int sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock < 0) return "";

    struct hostent* server = gethostbyname(host.c_str());
    if (!server) {
        close(sock);
        return "";
    }

    struct sockaddr_in serv_addr {};
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port   = htons(80);
    memcpy(&serv_addr.sin_addr.s_addr, server->h_addr, server->h_length);

    struct timeval timeout;
    timeout.tv_sec = 3;
    timeout.tv_usec = 0;
    setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
    setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));

    fcntl(sock, F_SETFL, O_NONBLOCK);
    
    connect(sock, (sockaddr*)&serv_addr, sizeof(serv_addr));
    
    fd_set fdset;
    struct timeval tv;
    
    FD_ZERO(&fdset);
    FD_SET(sock, &fdset);
    tv.tv_sec = 3;
    tv.tv_usec = 0;
    
    if (select(sock + 1, NULL, &fdset, NULL, &tv) == 1) {
        int so_error;
        socklen_t len = sizeof(so_error);
        getsockopt(sock, SOL_SOCKET, SO_ERROR, &so_error, &len);
        
        if (so_error == 0) {
            std::string request = "GET " + path + " HTTP/1.1\r\n"
                                 "Host: " + host + "\r\n"
                                 "Connection: close\r\n\r\n";

            if (send(sock, request.c_str(), request.length(), 0) < 0) {
                close(sock);
                return "";
            }

            std::string response;
            char buffer[4096];
            int bytes_read;
            
            FD_ZERO(&fdset);
            FD_SET(sock, &fdset);
            tv.tv_sec = 3;
            tv.tv_usec = 0;
            
            while (select(sock + 1, &fdset, NULL, NULL, &tv) == 1) {
                bytes_read = recv(sock, buffer, sizeof(buffer) - 1, 0);
                if (bytes_read <= 0) break;
                
                buffer[bytes_read] = '\0';
                response += buffer;
            }

            close(sock);

            size_t body_start = response.find("\r\n\r\n");
            if (body_start != std::string::npos) {
                return response.substr(body_start + 4);
            }

            return response;
        }
    }
    
    close(sock);
    return "";
}

void FetchServerListFromUrl() {
    std::lock_guard<std::mutex> lock(serversMutex);
    g_Servers.clear();
    
    // 从网络获取服务器列表
    std::string buf = http_get("xinle2.xhyu.top", "/server_list2.txt");
    
    if (buf.empty()) {
        return;
    }
    
    std::vector<std::regex> patterns = {
        std::regex(R"(服务器\d+【([^;]+);([^】]+)】)"),
        std::regex(R"(([^【]+)【([^】]+)】)"),
        std::regex(R"(([^,]+),([^,]+))")
    };
    
    for (const auto& re : patterns) {
        std::sregex_iterator it(buf.begin(), buf.end(), re);
        std::sregex_iterator end;
        bool found = false;
        
        for (; it != end; ++it) {
            g_Servers.push_back({(*it)[1], (*it)[2], -1});
            found = true;
        }
        
        if (found) break;
    }
    
    if (g_Servers.empty()) {
        std::istringstream stream(buf);
        std::string line;
        while (std::getline(stream, line)) {
            size_t separator = line.find(';');
            if (separator != std::string::npos) {
                std::string name = line.substr(0, separator);
                std::string ipPort = line.substr(separator + 1);
                g_Servers.push_back({name, ipPort, -1});
            }
        }
    }
}

void network_thread_func() {
    while (networkThreadRunning) {
        {
            std::lock_guard<std::mutex> lock(serversMutex);
            int64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(
                std::chrono::system_clock::now().time_since_epoch()).count();
            
            for (int i = 0; i < g_Servers.size(); i++) {
                auto& srv = g_Servers[i];
                // 每5秒ping一次服务器
                if (!srv.isPinging && (now - srv.lastPingTime > 5000)) {
                    srv.isPinging = true;
                    srv.lastPingTime = now;
                    
                    // 在实际线程中执行ping
                    int ping = Ping(srv.ipPort);
                    updateServerPing(i, ping);
                }
            }
        }
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }
}

TNameEntryArray* GetGNames() {
    return (TNameEntryArray*)getPointer(UE4 + 0x4431ae4);
}

UWorld* GetWorld() {
    return (UWorld*)getPointer(getPointer(getPointer(UE4 + 0x4634ef0) + 0x38) + 0x58);
}







std::vector<AActor *> getActors() {
    auto World = GetWorld();
    auto Actors = *(TArray<AActor *> *)(*(uintptr_t*) ((uintptr_t) World +0x20)+0x70);
    std::vector<AActor *> actors;
    for (int i = 0; i < Actors.Num(); i++) { auto Actor = Actors[i]; if (Actor) actors.push_back(Actor); }
    return actors;
}


AUAEGameMode* GameMode = 0;         
ASTExtraPlayerController* PlayerController = 0; 
ASTExtraPlayerController *g_LocalController = 0;
ASTExtraPlayerCharacter *STExtraPlayerCharacter = nullptr;
ASTExtraPlayerCharacter* g_LocalPlayer = 0;    


void 获取对象() {
    auto Actors = getActors();
    for (auto Actor : Actors) {
        if (Actor && Actor->IsA(AUAEGameMode::StaticClass())) GameMode = (AUAEGameMode*)Actor;
        if (Actor && Actor->IsA(ASTExtraPlayerController::StaticClass())) PlayerController = (ASTExtraPlayerController*)Actor;
        if (Actor && Actor->IsA(ASTExtraPlayerCharacter::StaticClass())) STExtraPlayerCharacter = (ASTExtraPlayerCharacter*)Actor;
    }
}

class AActor* SpawnActorFromClass(
    class UObject* WorldContextObject,  class UClass* ActorClass,
    const struct FTransform& SpawnTransform,
    ESpawnActorCollisionHandlingMethod CollisionHandlingOverride,
    class AActor* Owner) {
    auto Spawned = UGameplayStatics::BeginDeferredActorSpawnFromClass(
        WorldContextObject, ActorClass, SpawnTransform, CollisionHandlingOverride,
        Owner);

    Spawned = UGameplayStatics::FinishSpawningActor(Spawned, SpawnTransform);

    return Spawned;
}
struct sRegion { uintptr_t start, end; };
std::vector<sRegion> trapRegions;
bool isObjectInvalid(UObject *obj) {
    if (!IsPtrValid(obj)) return true;
    if (!IsPtrValid(obj->ClassPrivate)) return true;
    if (obj->InternalIndex <= 0) return true;
    if (obj->NamePrivate.ComparisonIndex <= 0) return true;
    if ((uintptr_t)(obj) % sizeof(uintptr_t) != 0x0 && (uintptr_t)(obj) % sizeof(uintptr_t) != 0x4) return true;
    if (std::any_of(trapRegions.begin(), trapRegions.end(), [obj](sRegion region) {
        return ((uintptr_t) obj) >= region.start && ((uintptr_t) obj) <= region.end;
    }) || std::any_of(trapRegions.begin(), trapRegions.end(), [obj](sRegion region) {
        return ((uintptr_t) obj->ClassPrivate) >= region.start && ((uintptr_t) obj->ClassPrivate) <= region.end;
    })) return true;
    return false;
}
bool(*ogm)(); bool gm() { return true; }

void CreateItem(int ItemType, int TypeSpecificID, int Count) {
获取对象();
FTransform Transform;
if(STExtraPlayerCharacter){
Transform=STExtraPlayerCharacter->GetTransform();
}
AActor*Actor=UGameplayStatics::BeginSpawningActorFromClass(GetWorld(),APickUpWrapperActor::StaticClass(),Transform,true,UGameplayStatics::GetPlayerController(GetWorld(),0));
APickUpWrapperActor*PickUpActor=reinterpret_cast<APickUpWrapperActor*>(Actor);
if(PickUpActor){
FItemDefineID Item;
Item.Type=ItemType;
Item.TypeSpecificID=TypeSpecificID;
PickUpActor->SetDefineID(Item);
PickUpActor->SetCountOnServerAfterSpawn(Count);
PickUpActor->ShowMesh(true);
PickUpActor->ShowActor();     
PickUpActor->SetReplicates(true);
PickUpActor->SetReplicateMovement(true);    
    GameMode->bEnableDamage=20;
     UGameplayStatics::FinishSpawningActor(PickUpActor,Transform);

}
}
void Aure(int ItemType, int TypeSpecificID, int Count, int 伤害) {
    获取对象();
    FTransform Transform;
    if (STExtraPlayerCharacter) Transform = STExtraPlayerCharacter->GetTransform();
    APickUpWrapperActor* PickUpActor = reinterpret_cast<APickUpWrapperActor*>(
        UGameplayStatics::BeginSpawningActorFromClass(
            GetWorld(), APickUpWrapperActor::StaticClass(), Transform, true,
            UGameplayStatics::GetPlayerController(GetWorld(), 0)));
    if (PickUpActor) {
        FItemDefineID Item; Item.Type = ItemType; Item.TypeSpecificID = TypeSpecificID;
        PickUpActor->SetCountOnServerAfterSpawn(Count);
        PickUpActor->SetDefineID(Item);
        PickUpActor->ShowMesh(true);
        PickUpActor->SetActorEnableCollision(true);
        PickUpActor->SetReplicates(true);
        PickUpActor->SetReplicateMovement(true);    
        if (GameMode) GameMode->bEnableDamage = 伤害;
        PickUpActor->ShowActor();
        UGameplayStatics::FinishSpawningActor(PickUpActor, Transform);
    }
}
void AKM_Chicheng() { CreateItem(1, 101001001, 10); }
void AKM_Rongyao() { CreateItem(1, 101001002, 10); }
void AKM_Wumujinwen() { CreateItem(1, 101001003, 10); }
void AKM_Xueshi() { CreateItem(1, 101001004, 10); }
void AKM_Kuangnu() { CreateItem(1, 101001005, 10); }
void M16A4_Shachi() { CreateItem(1, 101002001, 10); }
void M16A4_Qingyao() { CreateItem(1, 101002002, 10); }
void M16A4_Wumujinwen() { CreateItem(1, 101002003, 10); }
void M16A4_Huangshi() { CreateItem(1, 101002004, 10); }
void M16A4_Yezhanyinghao() { CreateItem(1, 101002005, 10); }
void M16A4_Kuangnu() { CreateItem(1, 101002006, 10); }
void SCARL_Kuangnu() { CreateItem(1, 101003001, 10); }
void SCARL_Wumujinwen() { CreateItem(1, 101003002, 10); }
void SCARL_Chicheng() { CreateItem(1, 101003003, 10); }
void SCARL_Xueshi() { CreateItem(1, 101003004, 10); }
void M416_RocketGirl() { CreateItem(1, 101004001, 10); }
void M416_Wumujinwen() { CreateItem(1, 101004002, 10); }
void M416_Kuishe() { CreateItem(1, 101004003, 10); }
void M416_Tuya() { CreateItem(1, 101004004, 10); }
void M416_Shamofengbao() { CreateItem(1, 101004005, 10); }
void M416_Xueyumicai() { CreateItem(1, 101004006, 10); }
void M416_Xueshi() { CreateItem(1, 101004007, 10); }
void M416_Chicheng() { CreateItem(1, 101004008, 10); }
void M416_Spring() { CreateItem(1, 101004009, 10); }
void GROZA_Kuangnu() { CreateItem(1, 101005001, 10); }
void AUG_Xueshi() { CreateItem(1, 101006001, 10); }
void UZI_Kuangnu() { CreateItem(1, 102001001, 10); }
void UMP9_Chicheng() { CreateItem(1, 102002001, 10); }
void UMP9_Rongyao() { CreateItem(1, 102002002, 10); }
void UMP9_RocketGirl() { CreateItem(1, 102002003, 10); }
void UMP9_Spring() { CreateItem(1, 102002004, 10); }
void Kar98K_Qingyao() { CreateItem(1, 103001001, 10); }
void Kar98K_Wumujinwen() { CreateItem(1, 103001002, 10); }
void Kar98K_FireLava() { CreateItem(1, 103001003, 10); }
void Kar98K_Xueshi() { CreateItem(1, 103001004, 10); }
void Kar98K_Spring() { CreateItem(1, 103001005, 10); }
void AWM_Rainbow() { CreateItem(1, 103003001, 10); }
void SKS_Chicheng() { CreateItem(1, 103004001, 10); }
void S686_Chicheng() { CreateItem(1, 104001001, 10); }
void P92_Kuangnu() { CreateItem(1, 106001001, 10); }
void P1911_Qingyao() { CreateItem(1, 106002001, 10); }
void Crowbar_RedNight() { CreateItem(1, 108002001, 10); }
void Pan_DoubleYolk() { CreateItem(1, 108004001, 10); }
void Pan_Survivor() { CreateItem(1, 108004002, 10); }
void Pan_NoHunt() { CreateItem(1, 108004003, 10); }
void Pan_RottenTomato() { CreateItem(1, 108004004, 10); }
void Pan_Forward() { CreateItem(1, 108004005, 10); }
void Pan_RedNight() { CreateItem(1, 108004006, 10); }

void 你好() { Aure(22, 2200101, 20, 0); }
void 感谢() { Aure(22, 2200201, 20, 0); }
void 鼓掌() { Aure(22, 2200301, 20, 0); }
void 大笑() { Aure(22, 2200401, 20, 0); }
void 来这里() { Aure(22, 2200501, 20, 0); }
void 走() { Aure(22, 2200601, 20, 0); }
void 否定() { Aure(22, 2200701, 20, 0); }
void 肯定() { Aure(22, 2200801, 20, 0); }
void 投降() { Aure(22, 2200901, 20, 0); }
void 愤怒() { Aure(22, 2201001, 20, 0); }
void 摇摆舞() { Aure(22, 2201101, 20, 0); }
void 电摇() { Aure(22, 2201201, 20, 0); }
void 拍灰舞() { Aure(22, 2201301, 20, 0); }
void 俄舞() { Aure(22, 2201401, 20, 0); }
void 安静() { Aure(22, 2201501, 20, 0); }
void 雀跃() { Aure(22, 2201601, 20, 0); }
void 崩溃() { Aure(22, 2201701, 20, 0); }
void 海带舞() { Aure(22, 2201801, 20, 0); }
void 街舞() { Aure(22, 2201901, 20, 0); }
void 壁虎步() { Aure(22, 2202001, 20, 0); }
void 机械舞() { Aure(22, 2202101, 20, 0); }
void 蹦迪舞() { Aure(22, 2202201, 20, 0); }
void 斗舞() { Aure(22, 2202301, 20, 0); }
void 秀舞() { Aure(22, 2202401, 20, 0); }
void 拉票舞() { Aure(22, 2202501, 20, 0); }
void 创造舞() { Aure(22, 2202601, 20, 0); }
void 三连赞() { Aure(22, 2202701, 20, 0); }
void 桑巴舞() { Aure(22, 2202801, 20, 0); }
void 空翻() { Aure(22, 2202901, 20, 0); }
void 摇篮舞() { Aure(22, 2203001, 20, 0); }
void 摆裙舞() { Aure(22, 2203101, 20, 0); }
void 吃鸡舞() { Aure(22, 2203201, 20, 0); }
void 抖胸舞() { Aure(22, 2203301, 20, 0); }
void 青蛙舞() { Aure(22, 2203401, 20, 0); }
void 甩手舞() { Aure(22, 2203501, 20, 0); }
void 点赞() { Aure(22, 2203601, 20, 0); }
void 欢庆舞() { Aure(22, 2203701, 20, 0); }
void 螃蟹舞() { Aure(22, 2203801, 20, 0); }
void 快看我() { Aure(22, 2203901, 20, 0); }
void 难过() { Aure(22, 2204001, 20, 0); }
void 扭秧歌() { Aure(22, 2204101, 20, 0); }
void 拜年男() { Aure(22, 2204201, 20, 0); }
void 红包来了() { Aure(22, 2204301, 20, 0); }
void 拜年女() { Aure(22, 2204401, 20, 0); }
void 黄金风衣() { Aure(4, 403188, 10, 0); }
void 黑曜金尊() { Aure(4, 403410, 10, 0); }
void 晶翼女神() { Aure(4, 403409, 10, 0); }
void 小黄裤() { Aure(4, 404001, 10, 0); }
void 小黄衣() { Aure(4, 403017, 10, 0); }
void 老玩家裤子() { Aure(4, 404049, 10, 0); }
void 老玩家上衣() { Aure(4, 403124, 10, 0); }
void 现金() { Aure(100, 1011, 520,0); }
void Q币() { Aure(100, 1012, 520,0); }

void 点券() { Aure(100, 1006, 520,0); }
void 新年烟花() { Aure(30, 3000301, 50, 30); }
void 新年爆竹() { Aure(30, 3000302, 50, 30); }
  void 红包() { Aure(30, 3001027, 50, 0); }
void 坚甲() { Aure(30, 3001028, 50, 0); }
void 利爪() { Aure(30, 3001029, 50, 0); }
void 小鸡() { Aure(30, 3002001, 50, 0); }
void 鸡蛋() { Aure(30, 3002002, 50, 0); }
void 南瓜() { Aure(30, 3001013, 50, 0); }
void 圣诞糖果() { Aure(30, 3001014, 50, 0); }
void 西瓜() { Aure(30, 3001001, 50, 0); }
void 小黄鸭() { Aure(30, 3001002, 90,0); }
void 鸡() { Aure(30, 3001003, 90,0); }
void 机密情报() { Aure(16, 1602056, 50, 0); }
void 鸡神奖杯() { Aure(16, 1602046, 50, 0); }
void 胜利手雷() { Aure(16, 1602039, 50, 0); }
void 足球() { Aure(16, 1602030, 50, 0); }
void 震爆弹() { Aure(6, 602001, 50, 0); }
void 烟雾弹() { Aure(6, 602002, 50, 0); }
void 燃烧瓶() { Aure(6, 602003, 50, 50); }
void 破片手榴弹() { Aure(6, 602004, 50, 50); }
void 跳舞弹() { Aure(6, 602006, 50, 0); }
void 大春雷() { Aure(6, 602010, 50, 30); }
void 鞭炮() { Aure(6, 602011, 50, 30); }
void 小春雷() { Aure(6, 602012, 50, 30); }
void 南瓜炸弹() { Aure(6, 602013, 50, 30); }
void 苹果() { Aure(6, 602005, 50, 0); }
void 圣诞玩具苹果() { Aure(6, 602007, 50, 0); }
void 圣诞小鸡玩偶() { Aure(6, 602008, 50, 0); }
void 冬季雪球() { Aure(6, 602009, 50, 0); }
void 肾上腺素() { Aure(6, 601002, 50, 0); }
void AKM() { Aure(1, 101001, 10, 20); }
void M416() { Aure(1, 101004, 10, 20); }
void AWM() { Aure(1, 103003, 10, 20); }
void M16A4() { Aure(1, 101002, 10, 20); }
void GROZA() { Aure(1, 101005, 10, 20); }
void SCARL() { Aure(1, 101003, 10, 20); }
void AUG() { Aure(1, 101006, 10, 20); }
void QBZ() { Aure(1, 101007, 10, 20); }
void M762() { Aure(1, 101008, 10, 20); }
void MK47() { Aure(1, 101009, 10, 20); }
void G36C() { Aure(1, 101010, 10, 20); }
void UZI() { Aure(1, 102001, 10, 20); }
void UMP9() { Aure(1, 102002, 10, 20); }
void Vector() { Aure(1, 102003, 10, 20); }
void Thompson() { Aure(1, 102004, 10, 20); }
void PP19() { Aure(1, 102005, 10, 20); }
void Kar98K() { Aure(1, 103001, 10, 20); }
void M24() { Aure(1, 103002, 10, 20); }
void SKS() { Aure(1, 103004, 10, 20); }
void VSS() { Aure(1, 103005, 10, 20); }
void Mini14() { Aure(1, 103006, 10, 20); }
void Mk14() { Aure(1, 103007, 10, 20); }
void Win94() { Aure(1, 103008, 10, 20); }
void SLR() { Aure(1, 103009, 10, 20); }
void QBU() { Aure(1, 103010, 10, 20); }
void S686() { Aure(1, 104001, 10, 20); }
void S1897() { Aure(1, 104002, 10, 20); }
void S12K() { Aure(1, 104003, 10, 20); }
void M249() { Aure(1, 105001, 10, 20); }
void DP28() { Aure(1, 105002, 10, 20); }
void P92() { Aure(1, 106001, 10, 20); }
void P1911() { Aure(1, 106002, 10, 20); }
void R1895() { Aure(1, 106003, 10, 20); }
void P18C() { Aure(1, 106004, 10, 20); }
void R45() { Aure(1, 106005, 10, 20); }
void SawedOff() { Aure(1, 106006, 10, 20); }
void SignalGun() { Aure(1, 106007, 10, 20); }
void Scorpion() { Aure(1, 106008, 10, 20); }
void ChickenFirework() { Aure(1, 106095, 10, 20); }
void LanternFirework() { Aure(1, 106096, 10, 20); }
void BeastSignal() { Aure(1, 106097, 10, 20); }
void ChristmasSignal() { Aure(1, 106098, 10, 20); }  
void NewYearFirework() { Aure(1, 106099, 10, 20); } 
void Crossbow() { Aure(1, 107001, 10, 20); }
void RiotShield() { Aure(1, 107003, 10, 20); }  
void Machete() { Aure(1, 108001, 10, 20); }
void Crowbar() { Aure(1, 108002, 10, 20); }
void Sickle() { Aure(1, 108003, 10, 20); }
void Pan() { Aure(1, 108004, 10, 20); }
void Bullet762() { Aure(3, 302001, 900, 20); }
void Bullet556() { Aure(3, 303001, 900, 20); }
void ShotgunShell() { Aure(3, 304001, 900, 20); }
void Bullet45() { Aure(3, 305001, 900, 20); }
void Magnum() { Aure(3, 306001, 900, 20); }
void SignalFlare() { Aure(3, 308001, 900, 20); }
void Arrow() { Aure(3, 307001, 900, 20); }
void FireworkShell() { Aure(3, 308002, 900, 20); }
void BeastBait() { Aure(3, 308003, 900, 20); }  
void Choke() { Aure(1, 201001, 10, 0); }
void SMGCompensator() { Aure(1, 201002, 10, 0); }
void SniperCompensator() { Aure(1, 201003, 10, 0); }
void SMGFlashHider() { Aure(1, 201004, 10, 0); }
void SniperFlashHider() { Aure(1, 201005, 10, 0); }
void SMGSilencer() { Aure(1, 201006, 10, 0); }
void SniperSilencer() { Aure(1, 201007, 10, 0); }
void PistolSilencer() { Aure(1, 201008, 10, 0); }
void RifleCompensator() { Aure(1, 201009, 10, 0); }
void RifleFlashHider() { Aure(1, 201010, 10, 0); }
void RifleSilencer() { Aure(1, 201011, 10, 0); }
void Duckbill() { Aure(1, 201012, 10, 0); }
void AngledGrip() { Aure(1, 202001, 10, 0); }
void VerticalGrip() { Aure(1, 202002, 10, 0); }
void LightGrip() { Aure(1, 202004, 10, 0); }
void HalfGrip() { Aure(1, 202005, 10, 0); }
void ThumbGrip() { Aure(1, 202006, 10, 0); }
void LaserSight() { Aure(1, 202007, 10, 0); }
void RedDot() { Aure(1, 203001, 10, 0); }
void Holographic() { Aure(1, 203002, 10, 0); }
void Scope2x() { Aure(1, 203003, 10, 0); }
void Scope4x() { Aure(1, 203004, 10, 0); }
void Scope8x() { Aure(1, 203005, 10, 0); }
void CantedSight() { Aure(1, 203018, 10, 0); }
void PistolExtMag() { Aure(1, 204001, 10, 0); }
void PistolQuickMag() { Aure(1, 204002, 10, 0); }
void PistolQuickExtMag() { Aure(1, 204003, 10, 0); }
void SMGExtMag() { Aure(1, 204004, 10, 0); }
void SMGQuickMag() { Aure(1, 204005, 10, 0); }
void SMGQuickExtMag() { Aure(1, 204006, 10, 0); }
void SniperExtMag() { Aure(1, 204007, 10, 0); }
void SniperQuickMag() { Aure(1, 204008, 10, 0); }
void SniperQuickExtMag() { Aure(1, 204009, 10, 0); }
void ShotgunBulletLoops() { Aure(1, 204010, 10, 0); }
void RifleExtMag() { Aure(1, 204011, 10, 0); }
void RifleQuickMag() { Aure(1, 204012, 10, 0); }
void RifleQuickExtMag() { Aure(1, 204013, 10, 0); }
void Kar98kLoops() { Aure(1, 204014, 10, 0); }
void UziStock() { Aure(1, 205001, 10, 0); }
void TacticalStock() { Aure(1, 205002, 10, 0); }
void CheekPad() { Aure(1, 205003, 10, 0); }
void Quiver() { Aure(1, 205004, 10, 0); }
void 夜视仪() { Aure(5, 504001, 10, 0); }
void HelmetLv3() { Aure(5, 502003, 10, 0); }
void VestLv3() { Aure(5, 503003, 10, 0); }
void BackpackLv3() { Aure(5, 501003, 10, 0); }
void HelmetLv1() { Aure(5, 502001, 10, 0); }
void VestLv1() { Aure(5, 503001, 10, 0); }
void BackpackLv1() { Aure(5, 501004, 10, 0); }
void HelmetLv2() { Aure(5, 502002, 10, 0); }
void VestLv2() { Aure(5, 503002, 10, 0); }
void BackpackLv2() { Aure(5, 501005, 10, 0); }
void ChristmasHelmet() { Aure(5, 502010, 10, 0); }
void BeastHelmet() { Aure(5, 502011, 10, 0); }
void 一键生成投掷物() {
       胜利手雷(); 震爆弹(); 烟雾弹(); 燃烧瓶(); 破片手榴弹(); 跳舞弹(); 苹果(); 
}
void 一键生成衣服() {
    黄金风衣(); 黑曜金尊(); 晶翼女神(); 小黄裤(); 小黄衣(); 老玩家裤子(); 
    老玩家上衣(); 
}
void 一键生成动作() {
    你好(); 感谢(); 鼓掌(); 大笑(); 来这里(); 走(); 否定(); 肯定(); 投降(); 愤怒(); 
    摇摆舞(); 电摇(); 拍灰舞(); 俄舞(); 安静(); 雀跃(); 崩溃(); 海带舞(); 街舞(); 
    壁虎步(); 机械舞(); 蹦迪舞(); 斗舞(); 秀舞(); 拉票舞(); 创造舞(); 三连赞(); 
    桑巴舞(); 空翻(); 摇篮舞(); 摆裙舞(); 吃鸡舞(); 抖胸舞(); 青蛙舞(); 甩手舞(); 
    点赞(); 欢庆舞(); 螃蟹舞(); 快看我(); 难过();    
    
}

int getItemType(int itemID) {
    if (itemID >= 101001 && itemID <= 603001) {
        while (itemID >= 10) {
            itemID /= 10;
        }
        return itemID;
    }
    else if (itemID >= 1500001 && itemID <= 1601002 && itemID != 1601001) {
        return 15;
    }
    else if (itemID >= 1601001 && itemID <= 1602118 && itemID != 1601002) {
        return 16;
    }
    else if (itemID == 1701001) {
        return 17;
    }
    else if (itemID >= 2001001 && itemID <= 2004308) {
        return 20;
    }
    else if (itemID >= 2101001 && itemID <= 2105001) {
        return 21;
    }
    else if (itemID >= 2200101 && itemID <= 2204401) {
        return 22;
    }
    else if (itemID >= 2401001 && itemID <= 2408055) {
        return 24;
    }
    else if (itemID >= 2501001 && itemID <= 2508001) {
        return 25;
    }
    else if (itemID >= 3000301 && itemID <= 3002002) {
        return 30;
    }
    else if (itemID >= 4001001 && itemID <= 4001006) {
        return 40;
    }
    else if (itemID >= 1000 && itemID <= 1015) {
        return 100;
    }
    else if (itemID >= 100100101 && itemID <= 100400903 || itemID >= 200200101 && itemID <= 200400103) {
        return 2;
    }
    else if (itemID >= 401992001 && itemID <= 407001004) {
        return 4;
    }    
    return 1;
}

//一键生成皮肤枪械
void SpawnAllSkinWeapons() {
    AKM_Chicheng(); AKM_Rongyao(); AKM_Wumujinwen(); AKM_Xueshi(); AKM_Kuangnu();
    M16A4_Shachi(); M16A4_Qingyao(); M16A4_Wumujinwen(); M16A4_Huangshi(); M16A4_Yezhanyinghao(); M16A4_Kuangnu();
    SCARL_Kuangnu(); SCARL_Wumujinwen(); SCARL_Chicheng(); SCARL_Xueshi();
    M416_RocketGirl(); M416_Wumujinwen(); M416_Kuishe(); M416_Tuya(); M416_Shamofengbao();
    M416_Xueyumicai(); M416_Xueshi(); M416_Chicheng(); M416_Spring();
    GROZA_Kuangnu(); AUG_Xueshi();
    UZI_Kuangnu();
    Kar98K_Qingyao(); Kar98K_Wumujinwen(); Kar98K_FireLava(); Kar98K_Xueshi(); Kar98K_Spring();
    AWM_Rainbow();
    Crowbar_RedNight();
    Pan_DoubleYolk(); Pan_Survivor(); Pan_NoHunt(); Pan_RottenTomato(); Pan_Forward(); Pan_RedNight();
}
//一键生成子弹
void SpawnAllAmmo() {
    Bullet762(); Bullet556(); ShotgunShell(); Bullet45(); Magnum(); SignalFlare(); 
    Arrow(); FireworkShell(); 
}
//一键生成配件
void SpawnAllAttachments() {
    Choke(); SMGCompensator(); SniperCompensator(); SMGFlashHider(); SniperFlashHider(); 
    SMGSilencer(); SniperSilencer(); PistolSilencer(); RifleCompensator(); RifleFlashHider(); 
    RifleSilencer(); Duckbill(); AngledGrip(); VerticalGrip(); LightGrip(); HalfGrip(); 
    ThumbGrip(); LaserSight(); RedDot(); Holographic(); Scope2x(); Scope4x(); Scope8x(); 
    CantedSight(); PistolExtMag(); PistolQuickMag(); PistolQuickExtMag(); SMGExtMag(); 
    SMGQuickMag(); SMGQuickExtMag(); SniperExtMag(); SniperQuickMag(); SniperQuickExtMag(); 
    ShotgunBulletLoops(); RifleExtMag(); RifleQuickMag(); RifleQuickExtMag(); Kar98kLoops(); 
    UziStock(); TacticalStock(); CheekPad(); Quiver();
}
//一键生成装备
void SpawnAllGear() {
    HelmetLv3(); VestLv3(); BackpackLv3(); HelmetLv1(); VestLv1(); BackpackLv1(); 
    HelmetLv2(); VestLv2(); BackpackLv2(); ChristmasHelmet(); 
}
//一键生成武器
void SpawnAllGear2() {
AKM(); M416(); AWM(); M16A4(); GROZA(); SCARL(); AUG(); QBZ(); M762(); MK47(); G36C();
UZI(); UMP9(); Vector(); Thompson(); PP19(); Kar98K(); M24(); SKS(); VSS(); Mini14(); Mk14();
Win94(); SLR(); QBU(); S686(); S1897(); S12K(); M249(); DP28(); P92(); P1911(); R1895();
P18C(); R45(); SawedOff(); SignalGun(); Scorpion(); ChickenFirework(); LanternFirework();
BeastSignal(); ChristmasSignal(); NewYearFirework(); Crossbow(); RiotShield(); Machete();
Crowbar(); Sickle(); Pan();
}


void automation() {
AKM(); M416(); AWM(); M16A4(); GROZA(); SCARL(); AUG(); QBZ(); M762(); MK47(); G36C();
UZI(); UMP9(); Vector(); Thompson(); PP19(); Kar98K(); M24(); SKS(); VSS(); Mini14(); Mk14();
Win94(); SLR(); QBU(); S686(); S1897(); S12K(); M249(); DP28(); P92(); P1911(); R1895();
P18C(); R45(); SawedOff(); SignalGun(); Scorpion(); ChickenFirework(); LanternFirework();
BeastSignal(); ChristmasSignal(); NewYearFirework(); Crossbow(); RiotShield(); Machete();
Crowbar(); Sickle(); Pan(); HelmetLv3(); VestLv3(); BackpackLv3(); HelmetLv1(); VestLv1(); BackpackLv1(); 
    HelmetLv2(); VestLv2(); BackpackLv2(); ChristmasHelmet(); Choke(); SMGCompensator(); SniperCompensator(); SMGFlashHider(); SniperFlashHider(); 
    SMGSilencer(); SniperSilencer(); PistolSilencer(); RifleCompensator(); RifleFlashHider(); 
    RifleSilencer(); Duckbill(); AngledGrip(); VerticalGrip(); LightGrip(); HalfGrip(); 
    ThumbGrip(); LaserSight(); RedDot(); Holographic(); Scope2x(); Scope4x(); Scope8x(); 
    CantedSight(); PistolExtMag(); PistolQuickMag(); PistolQuickExtMag(); SMGExtMag(); 
    SMGQuickMag(); SMGQuickExtMag(); SniperExtMag(); SniperQuickMag(); SniperQuickExtMag(); 
    ShotgunBulletLoops(); RifleExtMag(); RifleQuickMag(); RifleQuickExtMag(); Kar98kLoops(); 
    UziStock(); TacticalStock(); CheekPad(); Quiver();     Bullet762(); Bullet556(); ShotgunShell(); Bullet45(); Magnum(); SignalFlare(); 
    Arrow(); FireworkShell(); 胜利手雷(); 震爆弹(); 烟雾弹(); 燃烧瓶(); 破片手榴弹(); 跳舞弹(); 苹果();  黄金风衣(); 黑曜金尊(); 晶翼女神(); 小黄裤(); 小黄衣(); 老玩家裤子(); 
    老玩家上衣(); 
}

void teleport() {
            long x=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x150;
            long y=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x154;
            long z=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x158;
            writefloat(x,318196.5); writefloat(y,16122.200195); writefloat(z,726.837036);
            }





void Fix_Hitbox(ASTExtraBaseCharacter* Character) {


    // 开启碰撞：QueryAndPhysics(3)
    Character->CapsuleComponent->SetCollisionEnabled((ECollisionEnabled)3);
    // 阻挡所有：BlockAll(2)
    Character->CapsuleComponent->SetCollisionResponseToAllChannels((ECollisionResponse)2);
}

#include <chrono>
#include <functional>
#include <vector>
#include <algorithm>

class DelayedExecutor
{
public:
    using Clock   = std::chrono::steady_clock;
    using Task    = std::function<void()>;
    static void Add(int delayMs, Task&& task)
    {
        Instance().add(delayMs, std::move(task));
    }
    static void Update()
    {
        Instance().update();
    }

private:
    struct Item
    {
        Clock::time_point fireTime;
        Task              task;
    };

    static DelayedExecutor& Instance()
    {
        static DelayedExecutor inst;
        return inst;
    }

    void add(int delayMs, Task&& task)
    {
        m_tasks.emplace_back(Item{
            Clock::now() + std::chrono::milliseconds(delayMs),
            std::move(task)
        });
    }

    void update()
    {
        auto now = Clock::now();
        m_tasks.erase(
            std::remove_if(m_tasks.begin(), m_tasks.end(),
                [&](Item& it)
                {
                    if (now >= it.fireTime)
                    {
                        it.task();          
                        return true;        
                    }
                    return false;
                }),
            m_tasks.end());
    }

    std::vector<Item> m_tasks;
};



char *appkey = "0da7acad0797d8221929b1f640b27c19";
char *登录调用码 = "C53B87CC1BF58E79";
char *公告调用码 = "FFDDD0051600BDF9";
char *解绑调用码 = "811C377ECEBA945C";
char *提示 = "";
static bool 错误提示 = false;
char *公告 = httppost("w.t3data.net", 公告调用码, "FFDDD0051600BDF9");

std::string Login(const char *user_key) {
    if (!g_App) return "内部错误";
    auto activity = g_App->activity;
    if (!activity) return "内部错误";
    auto vm = activity->vm;
    if (!vm) return "内部错误";
    auto object = activity->clazz;
    if (!object) return "内部错误";

    JNIEnv *env;
    vm->AttachCurrentThread(&env, nullptr);

    std::string hwid = user_key;
    hwid += GetAndroidID(env, object);
    hwid += GetDeviceModel(env);
    hwid += GetDeviceBrand(env);
    std::string UUID = getHEX(加64(GetAndroidID(env, object).c_str()));
    vm->DetachCurrentThread();
    
    int64_t local_sec = std::chrono::duration_cast<std::chrono::seconds>(
        std::chrono::system_clock::now().time_since_epoch()).count();

    char sj[24]{0};
    snprintf(sj, sizeof(sj), "%lld", local_sec);

    std::string sjc = getHEX(加64(sj));
    std::string kamiHex = getHEX(加64(user_key));
    char sign2[512]{0};
    snprintf(sign2, sizeof(sign2),
             "kami=%s&imei=%s&t=%s&%s",
             kamiHex.c_str(), UUID.c_str(), sjc.c_str(), appkey);

    char sign2md5[33]{0};
    获取MD5(sign2, sign2md5);
    std::string sign22 = getHEX(加64(sign2md5));

    char postBuf[4096]{0};
    snprintf(postBuf, sizeof(postBuf),
             "kami=%s&imei=%s&t=%s&s=%s",
             kamiHex.c_str(), UUID.c_str(), sjc.c_str(), sign22.c_str());

    char *data = httppost("w.t3data.net", 登录调用码, postBuf);
    char *plain = 解64(data);

    if (strncmp(plain, "登录成功:200;", 12) == 0) {
        char *srvTimeStr = strstrstr(plain, "当前时间戳:", ";");
        if (!srvTimeStr) srvTimeStr = strstrstr(plain, "当前时间:", ";");

        if (srvTimeStr) {
            int64_t srv_sec = atoll(srvTimeStr);
            int64_t diff    = std::llabs(local_sec - srv_sec);
            log_to_file("[Login] local=%lld, server=%lld, diff=%lld",
                        local_sec, srv_sec, diff);
            if (diff < 18) {              
                isLogin = true;
            } else {
                错误提示 = true;
                提示 = "时间戳校验失败";
            }
        } else {
            错误提示 = true;
            提示 = "服务器未返回时间戳";
        }
    } else {
        错误提示 = true;
        提示 = plain;
    }
    return "OK";
}

std::string Unbind(const char *user_key) {
    char 解绑整[256];
    sprintf(解绑整, "kami=%s", user_key);
    char *解绑数据 = httppost("w.t3data.net", 解绑调用码, 解绑整);
    错误提示 = true;
    提示 = 解绑数据;
    return "OK";
}

// [NEW] 关卡管理相关变量
std::vector<ULevelStreaming*> g_LevelStreamingList;
int g_SelectedLevelIndex = -1;

// [NEW] 刷新所有 ULevelStreaming 对象列表
void RefreshLevelStreamingList() {
    g_LevelStreamingList.clear();
    auto objs = UObject::GetGlobalObjects();
    for (int i = 0; i < objs.Num(); i++) {
        auto obj = objs.GetByIndex(i);
        if (!IsPtrValid(obj)) continue;
        if (obj->IsA(ULevelStreaming::StaticClass())) {
            g_LevelStreamingList.push_back((ULevelStreaming*)obj);
        }
    }
    g_SelectedLevelIndex = -1;
}

// [NEW] 隐藏选中的关卡（仅不可见）
void HideSelectedLevel() {
    if (g_SelectedLevelIndex >= 0 && g_SelectedLevelIndex < (int)g_LevelStreamingList.size()) {
        auto level = g_LevelStreamingList[g_SelectedLevelIndex];
        if (level) {
            level->bShouldBeVisible = false;
        }
    }
}

// [NEW] 移除选中的关卡（卸载）
void UnloadSelectedLevel() {
    if (g_SelectedLevelIndex >= 0 && g_SelectedLevelIndex < (int)g_LevelStreamingList.size()) {
        auto level = g_LevelStreamingList[g_SelectedLevelIndex];
        if (level) {
            level->bShouldBeLoaded = false;
            level->bShouldBeVisible = false;
        }
    }
}

// [NEW] 恢复选中的关卡（重新加载并显示）
void RestoreSelectedLevel() {
    if (g_SelectedLevelIndex >= 0 && g_SelectedLevelIndex < (int)g_LevelStreamingList.size()) {
        auto level = g_LevelStreamingList[g_SelectedLevelIndex];
        if (level) {
            level->bShouldBeLoaded = true;
            level->bShouldBeVisible = true;
        }
    }
}

    // [NEW] 一键隐藏所有关卡（仅不可见）
void HideAllLevels() {
    for (auto level : g_LevelStreamingList) {
        if (level) {
            level->bShouldBeVisible = false;
        }
    }
}

// [NEW] 一键显示所有关卡（恢复可见，同时确保已加载）
void ShowAllLevels() {
    for (auto level : g_LevelStreamingList) {
        if (level) {
            level->bShouldBeLoaded = true;
            level->bShouldBeVisible = true;
        }
    }
}

// [NEW] 根据路径生成 Actor
void SpawnActorFromPath(const char* path) {
    if (!path || strlen(path) == 0) return;

    FTransform transform;
    // 初始化变换矩阵：旋转为单位矩阵，缩放为 1，位置使用当前相机坐标 CamLoc
    transform.Rotation = { 0.0f, 0.0f, 0.0f, 1.0f };
    transform.Translation = { CamLoc[0], CamLoc[1], CamLoc[2] };
    transform.Scale3D = { 1.0f, 1.0f, 1.0f };

    USTExtraBlueprintFunctionLibrary::SpawnActorFromString(FString(path), transform, nullptr, nullptr);
}

// [NEW] 随机隐藏一半关卡（使用 rand 实现）
void HideHalfLevels() {
    if (g_LevelStreamingList.empty()) return;
    
    int total = (int)g_LevelStreamingList.size();
    int toHide = total / 2;  // 向下取整
    if (toHide == 0) return;
    
    // 生成索引列表
    std::vector<int> indices(total);
    for (int i = 0; i < total; ++i) indices[i] = i;
    
    // 播种随机数（只播种一次）
    static bool seeded = false;
    if (!seeded) {
        std::srand(static_cast<unsigned>(std::time(nullptr)));
        seeded = true;
    }
    
    // Fisher-Yates 洗牌
    for (int i = total - 1; i > 0; --i) {
        int j = std::rand() % (i + 1);
        std::swap(indices[i], indices[j]);
    }
    
    // 隐藏前 toHide 个
    for (int i = 0; i < toHide; ++i) {
        auto level = g_LevelStreamingList[indices[i]];
        if (level) {
            level->bShouldBeVisible = false;
        }
    }
}



EGLBoolean(*orig_eglSwapBuffers)(EGLDisplay dpy,EGLSurface surface);
EGLBoolean _eglSwapBuffers(EGLDisplay dpy,EGLSurface surface){
eglQuerySurface(dpy,surface,EGL_WIDTH,&glWidth);
eglQuerySurface(dpy,surface,EGL_HEIGHT,&glHeight);
if(glWidth<=0||glHeight<=0){
return orig_eglSwapBuffers(dpy,surface);
}
if(!g_App){
return orig_eglSwapBuffers(dpy,surface);
}
screenWidth=ANativeWindow_getWidth(g_App->window);
screenHeight=ANativeWindow_getHeight(g_App->window);
density=AConfiguration_getDensity(g_App->config);
      if (!initImGui) {
        initImGui = true;
        ImGui::CreateContext();
        ImGuiIO&      io    = ImGui::GetIO();
        ImGuiStyle&   style = ImGui::GetStyle();
        style.WindowPadding = ImVec2(10, 10);
        style.FramePadding = ImVec2(8, 5);
        style.ItemSpacing = ImVec2(10, 7);
        style.ItemInnerSpacing = ImVec2(6, 4);
        style.IndentSpacing = 20.0f;
        style.ScrollbarSize = 15.0f;
        style.ScrollbarRounding = 5.0f;
        style.GrabMinSize = 10.0f;
        ApplyTheme(currentTheme);
        
//        ImGui::StyleColorsDark();
//            ImGui::StyleColorsLight();
  //          ImGui::StyleColorsClassic();
io.Fonts->AddFontFromMemoryTTF((void*)Custom_data, Custom_size, 23.5f, nullptr, io.Fonts->GetGlyphRangesChineseFull());
static const ImWchar diamondRange[] = { 0x25C6, 0x25C6, 0 };
ImFontConfig cfgMerge; cfgMerge.MergeMode = true;
io.Fonts->AddFontFromMemoryTTF((void*)Custom_data, Custom_size, 23.5f, &cfgMerge, diamondRange);

        io.Fonts->Build();
        io.ConfigWindowsMoveFromTitleBarOnly = true;
        ImGui_ImplAndroid_Init();
        ImGui_ImplOpenGL3_Init("#version 300 es");
    }







    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplAndroid_NewFrame(glWidth, glHeight);
    ImGui::NewFrame();
   
    ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(495.5f, 520.0f), ImGuiCond_FirstUseEver);
    ImGui::Begin("刺激战场调试器", nullptr, ImGuiWindowFlags_NoResize);
    
    if (!isLogin) {
        ImGui::PushItemWidth(-1);
        ImGui::InputText("##key", s, sizeof(s));
        
        if (ImGui::Button("粘贴", ImVec2(ImGui::GetContentRegionAvailWidth(), 0))) {
            std::string clip = getClipboardText();
            if (!clip.empty()) {
                strncpy(s, clip.c_str(), sizeof(s) - 1);
                s[sizeof(s) - 1] = '\0';
            }
        }
        
        if (ImGui::Button("登录", ImVec2(ImGui::GetContentRegionAvailWidth(), 0))) Login(s);
        ImGui::PopItemWidth();
        
        if (错误提示) ImGui::Text("提示:%s", 提示);
        ImGui::Text("公告:%s", 公告);
    } else {
    
    ImGui::PushStyleColor(ImGuiCol_Text, accentColor);
        ImGui::Text("永远相信美好的事情即将发生.");
        ImGui::PopStyleColor();
        ImGui::SameLine(ImGui::GetWindowWidth() - 120);
        ImGui::Separator();
        ImGui::Spacing();
        
        if (ImGui::BeginTabBar("MainTabs")) {
            if (ImGui::BeginTabItem("地图选择")) {
            ImGui::Spacing();
                
                if (ImGui::CollapsingHeader("联机模式")) {
                    if (ImGui::Button("海岛地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Forest/PUBG_Forest?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("沙漠地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Desert/PUBG_Desert?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("雨林地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Savage/PUBG_Savage_Main?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("训练场", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/Shooting_Range/shooting_test/shooting_range4?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("雪地年兽", ImVec2(-1, 35))) {
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_DihorOtok/DihorOtok_Main?game=/Game/BluePrints/Core/YearBeast/BP_BRGameModeTeam_YearBeast.BP_BRGameModeTeam_YearBeast_C?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                    }
                }
                
                if (ImGui::CollapsingHeader("单机模式")) {
                    if (ImGui::Button("海岛地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Forest/PUBG_Forest",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("沙漠地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Desert/PUBG_Desert",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("雨林地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Savage/PUBG_Savage_Main",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("训练场", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/Shooting_Range/shooting_test/shooting_range4",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("雪地年兽", ImVec2(-1, 35))) {
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_DihorOtok/DihorOtok_Main?game=/Game/BluePrints/Core/YearBeast/BP_BRGameModeTeam_YearBeast.BP_BRGameModeTeam_YearBeast_C",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                    }
                }
                
                if (ImGui::CollapsingHeader("团队模式")) {
                    if (ImGui::Button("海岛地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Forest/PUBG_Forest?game=/Game/BluePrints/Core/BP_BattleRoyaleGameModeTeamPUBG.BP_BattleRoyaleGameModeTeamPUBG_C?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("沙漠地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Desert/PUBG_Desert?game=/Game/BluePrints/Core/BP_BattleRoyaleGameModeTeamPUBG.BP_BattleRoyaleGameModeTeamPUBG_C?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("雨林地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Savage/PUBG_Savage_Main?game=/Game/BluePrints/Core/BP_BattleRoyaleGameModeTeamPUBG.BP_BattleRoyaleGameModeTeamPUBG_C?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                }
                
                if (ImGui::CollapsingHeader("训练模式")) {
                    if (ImGui::Button("海岛地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Forest/PUBG_Forest?Game=/Game/BluePrints/Core/BP_BattleRoyalTrainingGameMode.BP_BattleRoyalTrainingGameMode_C?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("沙漠地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Desert/PUBG_Desert?Game=/Game/BluePrints/Core/BP_BattleRoyalTrainingGameMode.BP_BattleRoyalTrainingGameMode_C?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("雨林地图", ImVec2(-1, 35))) {
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),
                            "open /Game/Maps/PUBG_Savage/PUBG_Savage_Main?Game=/Game/BluePrints/Core/BP_BattleRoyalTrainingGameMode.BP_BattleRoyalTrainingGameMode_C?listen",
                            UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                }
                
                if (ImGui::CollapsingHeader("战争模式")) {
                    if (ImGui::Button("雪地-战争", ImVec2(-1,0))){
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),"open /Game/Maps/PUBG_DihorOtok/DihorOtok_Main?game=/Game/Blueprints/Core/War/BP_WarGameMode.BP_WarGameMode_C?listen",UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("海岛-战争", ImVec2(-1,0))){
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),"open /Game/Maps/PUBG_Forest/PUBG_Forest?game=/Game/Blueprints/Core/War/BP_WarGameMode.BP_WarGameMode_C?listen",UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("训练-战争", ImVec2(-1,0))){
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),"open /Game/Maps/Shooting_Range/shooting_test/shooting_range4?game=/Game/Blueprints/Core/War/BP_WarGameMode.BP_WarGameMode_C?listen",UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("沙漠-战争", ImVec2(-1,0))){
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),"open /Game/Maps/PUBG_Desert/PUBG_Desert?game=/Game/Blueprints/Core/War/BP_WarGameMode.BP_WarGameMode_C?listen",UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                    if (ImGui::Button("雨林-战争", ImVec2(-1,0))){
                        UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),"open /Game/Maps/PUBG_Savage/PUBG_Savage_Main?game=/Game/Blueprints/Core/War/BP_WarGameMode.BP_WarGameMode_C?listen",UGameplayStatics::GetPlayerController(GetWorld(),0));
                        SDK::UGameBackendHUD*Instance=UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD*HUD=Instance->GetFirstGameFrontendHUD();
                        HUD->PendingGameStatus="Fighting";
                    }
                }

                ImGui::EndTabItem();
            }
            
            
            if (ImGui::BeginTabItem("服务器")) {
            
                ImGui::Spacing();

                ImGui::PushItemWidth(-1);
    if (ImGui::CollapsingHeader("自定义服务器")) {
        ImGui::Text("玩家名称:");
        ImGui::SameLine();
        ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.6f);
        ImGui::InputText("##player_name", playerName, sizeof(playerName));
        
        ImGui::SameLine(0.0f, 8.0f);
        if (ImGui::Button("粘贴##paste_name", ImVec2(ImGui::GetContentRegionAvail().x, 0))) {
            std::string clip = getClipboardText();
            if (!clip.empty()) {
                strncpy(playerName, clip.c_str(), sizeof(playerName) - 1);
                playerName[sizeof(playerName) - 1] = '\0';
            }
        }
        
        ImGui::Spacing();
        ImGui::Text("服务器IP:");
        ImGui::SameLine();
        ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x * 0.6f);
        ImGui::InputText("##server_ip", s, sizeof(s));
        
        ImGui::SameLine(0.0f, 8.0f);
        if (ImGui::Button("粘贴IP##paste_ip", ImVec2(ImGui::GetContentRegionAvail().x, 0))) {
            std::string clip = getClipboardText();
            if (!clip.empty()) {
                strncpy(s, clip.c_str(), sizeof(s) - 1);
                s[sizeof(s) - 1] = '\0';
            }
        }
        
        ImGui::Spacing();
        if (ImGui::Button("打开键盘", ImVec2(ImGui::GetContentRegionAvail().x * 0.5f - ImGui::GetStyle().ItemSpacing.x * 0.5f, 35))) {
            showVirtualKeyboard = true;
        }
        
        ImGui::SameLine();
        if (ImGui::Button("进入服务器", ImVec2(ImGui::GetContentRegionAvail().x, 35))) {
            std::string command = "open " + std::string(s);
            if (strlen(playerName) > 0) {
                command += "?PlayerName=" + std::string(playerName);
            }
            UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(), command,UGameplayStatics::GetPlayerController(GetWorld(), 0));
            SDK::UGameBackendHUD* Instance = UGameBackendHUD::GetInstance();
            SDK::UGameFrontendHUD* HUD = Instance->GetFirstGameFrontendHUD();
            HUD->PendingGameStatus = "Fighting";
            
        }
        if (showVirtualKeyboard) {
            RenderVirtualKeyboard();
        }
    }
    
                ImGui::PopItemWidth();
                ImGui::EndTabItem();
            }

            
            
            if (ImGui::BeginTabItem("开服功能")) {
            ImGui::Spacing();
                
                if (ImGui::CollapsingHeader("开服必备")) {
                    if (ImGui::Button("倒计时1万", ImVec2(-1, 35))) {
                        SDK::UGameBackendHUD* backendHUD = UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD* frontendHUD = backendHUD->GetFirstGameFrontendHUD();
                        auto BattleRoyaleGameModeBase = (ABattleRoyaleGameModeBase*)(frontendHUD->GetGameMode());
                        auto gamemode = (UGameModeStateReady*)(BattleRoyaleGameModeBase->GameModeStateReady);
                        gamemode->StateTime = 10000;
                    }
                    
                    if (ImGui::Button("攀爬调试", ImVec2(-1, 35))) {
                        获取对象();
                        if (GameMode) GameMode->bEnableClimbing = true;
                    }
                    
                    if (ImGui::Button("内存上机", ImVec2(-1, 35))){
                        WriteInt(UE4+0xc5ebbc,-476053503);
                        WriteInt(UE4+0xedd870,-516948194);
                        WriteInt(UE4+0xedf42c,-516948194);
                        WriteInt(UE4+0x30b92f8,-516948194);
                        WriteInt(UE4+0x30b93c4,-516948194);
                        WriteInt(UE4+0x103f880,-516948194);
                        WriteInt(UE4+0x10ba09c,-516948194);
                        WriteInt(UE4+0x1040090,1);
                    }
                    if (ImGui::CollapsingHeader("刷新人机")) {
                        if (ImGui::Button("刷30个人机", ImVec2(-1, 35))) {
                            USkillUtils::GetPlayerController(UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn)->SpawnAI(30);
                        }
                        if (ImGui::Button("刷50个人机", ImVec2(-1, 35))) {
                            USkillUtils::GetPlayerController(UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn)->SpawnAI(50);
                        }
                        if (ImGui::Button("刷100个人机", ImVec2(-1, 35))) {
                            USkillUtils::GetPlayerController(UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn)->SpawnAI(100);
                        }
                        if (ImGui::Button("刷1000个人机", ImVec2(-1, 35))) {
                            USkillUtils::GetPlayerController(UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn)->SpawnAI(1000);
                        }
                        if (ImGui::Button("刷10000个人机", ImVec2(-1, 35))) {
                            USkillUtils::GetPlayerController(UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn)->SpawnAI(10000);
                        }
                    }


                }
                
                                

                if (ImGui::CollapsingHeader("刷新物资")) {
                
                    if (ImGui::Button("刷游戏武器", ImVec2(-1, 35))) SpawnAllGear2();
                    if (ImGui::Button("刷武器皮肤", ImVec2(-1, 35))) SpawnAllSkinWeapons();
                    if (ImGui::Button("刷游戏装备", ImVec2(-1, 35))) SpawnAllGear();
                    if (ImGui::Button("刷武器子弹", ImVec2(-1, 35))) SpawnAllAmmo();
                    if (ImGui::Button("刷武器配件", ImVec2(-1, 35))) SpawnAllAttachments();
                    if (ImGui::Button("刷人物动作", ImVec2(-1, 35))) 一键生成动作();
                    if (ImGui::Button("刷人物衣服", ImVec2(-1, 35))) 一键生成衣服();
                    if (ImGui::Button("刷投掷物品", ImVec2(-1, 35))) 一键生成投掷物();
                
                }

                
                if (ImGui::CollapsingHeader("传送功能")) {
                    if (ImGui::Button("年兽刷新点", ImVec2(-1, 35))) {
                        long x=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x150;
                        long y=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x154;
                        long z=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x158;
                        writefloat(x,243108); writefloat(y,252095); writefloat(z,7939);
                    }
                    if (ImGui::Button("训练场", ImVec2(-1, 35))) {
                        long x=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x150;
                        long y=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x154;
                        long z=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x158;
                        writefloat(x,318196.5); writefloat(y,16122.200195); writefloat(z,726.837036);
                    }
                    if (ImGui::Button("高空", ImVec2(-1, 35))) {
                        long z=getPointer(getPointer(getPointer(getPointer(UE4+0x4634ef0)+0x20)+0x139c)+0x130)+0x158;
                        writefloat(z,7726.837036);
                    }
                }
                
                if (ImGui::CollapsingHeader("防崩方案")) {
                    if (ImGui::Button("心跳防崩", ImVec2(-1, 35))){
                        SDK::UGameBackendHUD* hud = UGameBackendHUD::GetInstance();
                        SDK::UGameFrontendHUD* hd = hud->GetFirstGameFrontendHUD();
                        hd->PendingGameStatus="Fighting";
                        auto BattleRoyaleGameModeBase=(ABattleRoyaleGameModeBase*)(hd->GetGameMode());
                        auto gamemode=(UGameModeStateReady*)(BattleRoyaleGameModeBase->GameModeStateReady);
                        BattleRoyaleGameModeBase->bEnableDamage=true;
                        BattleRoyaleGameModeBase->bEnableDamage=100;
                    }
                    
                    if (ImGui::Button("发信防崩", ImVec2(-1, 35))){
                        static float HeartbeatTimer = 0.0f;
                        static const float HeartbeatInterval = 0.2f;
                        
                        HeartbeatTimer += ImGui::GetIO().DeltaTime;
                        if (HeartbeatTimer >= HeartbeatInterval) {
                            SDK::UGameBackendHUD* hud = SDK::UGameBackendHUD::GetInstance();
                            if (hud) {
                                SDK::UGameFrontendHUD* frontendHUD = hud->GetFirstGameFrontendHUD();
                                if (frontendHUD) {
                                    frontendHUD->PendingGameStatus = "Fighting";
                                    frontendHUD->PendingGameStatus = frontendHUD->PendingGameStatus;
                                }
                            }
                            
                            HeartbeatTimer = 0.0f;
                        }
                    }
                    
                    if (ImGui::Button("物资防崩", ImVec2(-1, 35))){
                        {
                            FTransform Transform = UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn->GetTransform();
                            Transform.Translation = UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn->RootComponent->RelativeLocation;
                            
                            AActor *SpawnedPickup = SpawnActorFromClass(GetWorld(), APickUpWrapperActor::StaticClass(), Transform,
                                                                        ESpawnActorCollisionHandlingMethod::ESpawnActorCollisionHandlingMethod__AlwaysSpawn,
                                                                        UGameplayStatics::GetPlayerController(GetWorld(), 0));
                            APickUpWrapperActor *_SpawnedPickup = static_cast<APickUpWrapperActor *>(SpawnedPickup);
                            
                            FItemDefineID ItemID;
                            ItemID.Type = 5;
                            ItemID.TypeSpecificID = 1001;
                            _SpawnedPickup->SetDefineID(ItemID);
                            
                            _SpawnedPickup->SetCountOnServerAfterSpawn(1);
                            
                            _SpawnedPickup->ShowMesh(true);
                            _SpawnedPickup->ShowActor();
                            
                            
                        }
                        
                        {
                            FTransform Transform = UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn->GetTransform();
                            Transform.Translation = UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn->RootComponent->RelativeLocation;
                            
                            AActor *SpawnedPickup = SpawnActorFromClass(GetWorld(), APickUpWrapperActor::StaticClass(), Transform,
                                                                        ESpawnActorCollisionHandlingMethod::ESpawnActorCollisionHandlingMethod__AlwaysSpawn,
                                                                        UGameplayStatics::GetPlayerController(GetWorld(), 0));
                            APickUpWrapperActor *_SpawnedPickup = static_cast<APickUpWrapperActor *>(SpawnedPickup);
                            
                            FItemDefineID ItemID;
                            ItemID.Type = 5;
                            ItemID.TypeSpecificID = 1001;
                            _SpawnedPickup->SetDefineID(ItemID);
                            
                            _SpawnedPickup->SetCountOnServerAfterSpawn(350);
                            
                            _SpawnedPickup->ShowMesh(true);
                            _SpawnedPickup->ShowActor();
                            
                            
                        }
                        
                        {
                            FTransform Transform = UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn->GetTransform();
                            Transform.Translation = UGameplayStatics::GetPlayerController(GetWorld(), 0)->Pawn->RootComponent->RelativeLocation;
                            
                            AActor *SpawnedPickup = SpawnActorFromClass(GetWorld(), APickUpWrapperActor::StaticClass(), Transform,
                                                                        ESpawnActorCollisionHandlingMethod::ESpawnActorCollisionHandlingMethod__AlwaysSpawn,
                                                                        UGameplayStatics::GetPlayerController(GetWorld(), 0));
                            APickUpWrapperActor *_SpawnedPickup = static_cast<APickUpWrapperActor *>(SpawnedPickup);
                            
                            FItemDefineID ItemID;
                            ItemID.Type = 3;
                            ItemID.TypeSpecificID = 1514005;
                            _SpawnedPickup->SetDefineID(ItemID);
                            
                            _SpawnedPickup->SetCountOnServerAfterSpawn(350);
                            
                            _SpawnedPickup->ShowMesh(true);
                            _SpawnedPickup->ShowActor();
                            
                            
                        }
                    }
                }
                
                ImGui::EndTabItem();
            }
            
            
            

            
            
            
            
            if (ImGui::BeginTabItem("其他功能")) {
            ImGui::Spacing();

                
            ImGui::PushItemWidth(-1);
                
                if (ImGui::CollapsingHeader("主题设置")) {
                
                
                
                if (ImGui::Combo("选择主题", &currentTheme, themeNames, IM_ARRAYSIZE(themeNames))) {
                    ApplyTheme(currentTheme);
                }
                
                
                if (ImGui::ColorEdit4("主题颜色", (float*)&customAccentColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel)) {
                    accentColor = customAccentColor;
                }
                
                
                ImGui::Separator();
                ImGui::Text("圆角设置:");
                if (ImGui::SliderFloat("窗口圆角", &g_WindowRounding, 0.0f, 12.0f, "%.1f")) {
                    ApplyTheme(currentTheme);
                }
                if (ImGui::SliderFloat("控件圆角", &g_FrameRounding, 0.0f, 12.0f, "%.1f")) {
                    ApplyTheme(currentTheme);
                }
                if (ImGui::SliderFloat("抓取圆角", &g_GrabRounding, 0.0f, 12.0f, "%.1f")) {
                    ApplyTheme(currentTheme);
                }
                if (ImGui::SliderFloat("标签圆角", &g_TabRounding, 0.0f, 12.0f, "%.1f")) {
                    ApplyTheme(currentTheme);
                }
               
                ImGui::Separator();
                ImGui::Text("边框设置:");
                if (ImGui::SliderFloat("窗口边框", &g_WindowBorderSize, 0.0f, 5.0f, "%.1f")) {
                    ApplyTheme(currentTheme);
                }
                if (ImGui::SliderFloat("控件边框", &g_FrameBorderSize, 0.0f, 5.0f, "%.1f")) {
                    ApplyTheme(currentTheme);
                }
                
                if (ImGui::Button("重置样式", ImVec2(-1, 35))) {
                    g_WindowRounding = 5.0f;
                    g_FrameRounding = 3.0f;
                    g_GrabRounding = 3.0f;
                    g_TabRounding = 4.0f;
                    g_ChildRounding = 4.0f;
                    g_PopupRounding = 5.0f;
                    g_WindowBorderSize = 1.0f;
                    g_FrameBorderSize = 0.5f;
                    g_PopupBorderSize = 1.0f;
                    ApplyTheme(currentTheme);
                }
                
            }
            

                if (ImGui::CollapsingHeader("基础功能")) {
                    if (ImGui::Button("单机刷航线", ImVec2(-1, 35))) {
                        USkillUtils::GetPlayerController(UGameplayStatics::GetPlayerController(GetWorld(),0)->Pawn)->SpawnAI(1);
                    }

                    if (ImGui::Button("爬墙",  ImVec2(-1,35))){
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object))
                                continue;
                            
                            if (Object->IsA(AActor::StaticClass())) {
                                auto playerChar = (AActor *) Object;
                                if (playerChar->bActorEnableCollision) {
                                    playerChar->SetActorEnableCollision(true);
                                    playerChar->bActorEnableCollision = true;
                                }
                            }
                        }
                    }
                    
                    if (ImGui::Button("240帧",  ImVec2(-1,35))){
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object))
                                continue;
                            
                            if (Object->IsA(USTExtraGameInstance::StaticClass())) {
                                auto SDK_USTExtraGameInstance = (USTExtraGameInstance *) Object;   
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSLow = 240;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSMid = 240; 
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHigh = 240;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHDR = 240;
                            }
                        }
                    }
                    if (ImGui::Button("120帧", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object))
                                continue;

                            if (Object->IsA(USTExtraGameInstance::StaticClass())) {
                                auto SDK_USTExtraGameInstance = (USTExtraGameInstance*)Object;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSLow = 120;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSMid = 120;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHigh = 120;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHDR = 120;
                            }
                        }
                    }
                    if (ImGui::Button("60帧", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object))
                                continue;

                            if (Object->IsA(USTExtraGameInstance::StaticClass())) {
                                auto SDK_USTExtraGameInstance = (USTExtraGameInstance*)Object;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSLow = 60;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSMid = 60;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHigh = 60;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHDR = 60;
                            }
                        }
                    }
                    
                    if (ImGui::Button("除雾",  ImVec2(-1,35))){
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object))
                                continue;
                            
                            if (Object->IsA(UExponentialHeightFogComponent::StaticClass())) {
                                auto playerChar = (UExponentialHeightFogComponent *) Object;
                                playerChar->SetFogMaxOpacity(0.0f);
                                playerChar->SetFogDensity(0.0f);
                                playerChar->SetFogHeightFalloff(0.0f);
                                playerChar->SetFogCutoffDistance(0.0f);
                                playerChar->SetStartDistance(0.0f);
                            }
                        }
                    }
                    
                    if (ImGui::Button("枪械一套",  ImVec2(-1,35))){
                        auto WeaponManagerComponent = g_LocalPlayer->WeaponManagerComponent;
                        if (WeaponManagerComponent) {
                            auto Slot = WeaponManagerComponent->GetCurrentUsingPropSlot();
                            if ((int) Slot.GetValue() >= 1 && (int) Slot.GetValue() <= 3) {
                                auto CurrentWeaponReplicated = (ASTExtraShootWeapon *) WeaponManagerComponent->CurrentWeaponReplicated;
                                if (CurrentWeaponReplicated) {
                                    auto ShootWeaponEntityComp = CurrentWeaponReplicated->ShootWeaponEntityComp;
                                    auto ShootWeaponEffectComp = CurrentWeaponReplicated->ShootWeaponEffectComp;
                                    if (ShootWeaponEntityComp && ShootWeaponEffectComp) {
                                        memset(&ShootWeaponEntityComp->RecoilInfo, 0, sizeof(FSRecoilInfo));
                                        
                                        ShootWeaponEntityComp->AccessoriesVRecoilFactor = 0.0f;
                                        ShootWeaponEntityComp->AccessoriesHRecoilFactor = 0.0f;
                                        ShootWeaponEntityComp->AccessoriesRecoveryFactor = 0.0f;
                                        
                                        memset(&ShootWeaponEntityComp->DeviationInfo, 0, sizeof(FSDeviation));
                                        
                                        ShootWeaponEntityComp->ShotGunVerticalSpread = 0.0f;
                                        ShootWeaponEntityComp->ShotGunHorizontalSpread = 0.0f;
                                        
                                        ShootWeaponEntityComp->GameDeviationFactor = 0.0f;
                                        ShootWeaponEntityComp->GameDeviationAccuracy = 0.0f;
                                        
                                        ShootWeaponEntityComp->CrossHairInitialSize = 0.0f;
                                        ShootWeaponEntityComp->CrossHairBurstSpeed = 0.0f;
                                        ShootWeaponEntityComp->CrossHairBurstIncreaseSpeed = 0.0f;
                                        
                                        ShootWeaponEntityComp->RecoilKickADS = 0.0f;
                                        memset(&ShootWeaponEntityComp->DeviationInfo, 0, sizeof(FSDeviation));
                                        
                                        ShootWeaponEntityComp->ShotGunVerticalSpread = 0.0f;
                                        ShootWeaponEntityComp->ShotGunHorizontalSpread = 0.0f;
                                        ShootWeaponEntityComp->GameDeviationFactor = 0.0f;
                                        ShootWeaponEntityComp->GameDeviationAccuracy = 0.0f;
                                        ShootWeaponEntityComp->CrossHairInitialSize = 0.0f;
                                        ShootWeaponEntityComp->CrossHairBurstSpeed = 0.0f;
                                        ShootWeaponEntityComp->CrossHairBurstIncreaseSpeed = 0.0f;
                                        
                                        ShootWeaponEffectComp->CameraShakeInnerRadius = 0.0f;
                                        ShootWeaponEffectComp->CameraShakeOuterRadius = 0.0f;
                                        ShootWeaponEffectComp->CameraShakFalloff = 0.0f;
                                    }
                                }
                            }
                        }
                    }
                }
                
                if (ImGui::CollapsingHeader("高级功能")) {
                    if (ImGui::Button("趴下加速[开]", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object)) continue;
                            if (Object->IsA(ASTExtraBaseCharacter::StaticClass())) {
                                auto playerChar = (ASTExtraBaseCharacter *) Object;
                                playerChar->SpeedScale = 999999;
                            }
                        }
                    }
                    if (ImGui::CollapsingHeader("特殊功能")) {
                        if (ImGui::Button("传送(高空)", ImVec2(-1, 60))) {
                            long z = getPointer(getPointer(getPointer(getPointer(UE4 + 0x4634ef0) + 0x20) + 0x139c) + 0x130) + 0x158;
                            writefloat(z, 7726.837036);
                        }
                        if (ImGui::Button("自由落体", ImVec2(-1, 60))) {
                            auto pc = UGameplayStatics::GetPlayerController(GetWorld(), 0);
                            auto STExtraPlayerCharacter = (ASTExtraPlayerCharacter*)(pc->Pawn);
                            STExtraPlayerCharacter->SetParachuteState(EParachuteState::PS_FreeFall);
                        }
                        if (ImGui::Button("开伞", ImVec2(-1, 60)))
                        {
                            auto pc = UGameplayStatics::GetPlayerController(GetWorld(), 0);
                            auto STExtraPlayerCharacter = (ASTExtraPlayerCharacter*)(pc->Pawn);
                            STExtraPlayerCharacter->SetParachuteState(EParachuteState::PS_Opening);
                        }
                        if (ImGui::Button("收伞", ImVec2(-1, 60)))
                        {
                            auto pc = UGameplayStatics::GetPlayerController(GetWorld(), 0);
                            auto STExtraPlayerCharacter = (ASTExtraPlayerCharacter*)(pc->Pawn);
                            STExtraPlayerCharacter->SetParachuteState(EParachuteState::PS_None);
                        }
                    }
                    
                    if (ImGui::Button("趴下加速[关]", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object)) continue;
                            if (Object->IsA(ASTExtraBaseCharacter::StaticClass())) {
                                auto playerChar = (ASTExtraBaseCharacter *) Object;
                                playerChar->SpeedScale = 1.0f;
                            }
                        }
                    }
                    
                    if (ImGui::Button("枪械地震[开]", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object)) continue;
                            if (Object->IsA(UShootWeaponEntity::StaticClass())) {
                                auto JLSDK = (UShootWeaponEntity *) Object;
                                JLSDK->AnimationKick = 16.f;
                            }
                        }
                    }
                    
                    if (ImGui::Button("枪械地震[关]", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object)) continue;
                            if (Object->IsA(UShootWeaponEntity::StaticClass())) {
                                auto JLSDK = (UShootWeaponEntity *) Object;
                                JLSDK->AnimationKick = 1.f;
                            }
                        }
                    }
                    
                    if (ImGui::Button("240帧", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object))
                                continue;

                            if (Object->IsA(USTExtraGameInstance::StaticClass())) {
                                auto SDK_USTExtraGameInstance = (USTExtraGameInstance*)Object;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSLow = 240;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSMid = 240;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHigh = 240;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHDR = 240;
                            }
                        }
                    }
                    if (ImGui::Button("120帧", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object))
                                continue;

                            if (Object->IsA(USTExtraGameInstance::StaticClass())) {
                                auto SDK_USTExtraGameInstance = (USTExtraGameInstance*)Object;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSLow = 120;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSMid = 120;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHigh = 120;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHDR = 120;
                            }
                        }
                    }
                    if (ImGui::Button("60帧", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object))
                                continue;

                            if (Object->IsA(USTExtraGameInstance::StaticClass())) {
                                auto SDK_USTExtraGameInstance = (USTExtraGameInstance*)Object;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSLow = 60;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSMid = 60;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHigh = 60;
                                SDK_USTExtraGameInstance->UserDetailSetting.PUBGDeviceFPSHDR = 60;
                            }
                        }
                    }

                    if (ImGui::Button("除雾", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object))
                                continue;

                            if (Object->IsA(UExponentialHeightFogComponent::StaticClass())) {
                                auto playerChar = (UExponentialHeightFogComponent*)Object;
                                playerChar->SetFogMaxOpacity(0.0f);
                                playerChar->SetFogDensity(0.0f);
                                playerChar->SetFogHeightFalloff(0.0f);
                                playerChar->SetFogCutoffDistance(0.0f);
                                playerChar->SetStartDistance(0.0f);
                            }
                        }
                    }
                    }
                    
                    if (ImGui::Button("无限子弹", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object)) continue;
                            if (Object->IsA(UShootWeaponEntity::StaticClass())) {
                                auto playerChar = (UShootWeaponEntity *) Object;
                                playerChar->bHasInfiniteClips = true;
                                playerChar->bClipHasInfiniteBullets = true;
                            }
                            if (Object->IsA(ASTExtraShootWeapon::StaticClass())) {
                                auto playerChar = (ASTExtraShootWeapon *) Object;
                                playerChar->CurMaxBulletNumInOneClip = 105;
                            }
                        }
                    }
                    
                    if (ImGui::Button("六道仙人", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object)) continue;
                            if (Object->IsA(UShootWeaponEntity::StaticClass())) {
                                auto playerChar = (UShootWeaponEntity *) Object;
                                playerChar->BurstShootBulletsNum = 999;
                            }
                            if (Object->IsA(UShootWeaponEntity::StaticClass())) {
                                auto playerChar = (UShootWeaponEntity *) Object;
                                playerChar->ShootInterval = 0.f;
                            }
                        }
                    }
                    
                    if (ImGui::Button("人物广角", ImVec2(-1, 35))) {
                        auto objs = UObject::GetGlobalObjects();
                        for (int i = 0; i < objs.Num(); i++) {
                            auto Object = objs.GetByIndex(i);
                            if (isObjectInvalid(Object)) continue;
                            if (Object->IsA(ULocalPlayer::StaticClass())) {
                                auto playerChar = (ULocalPlayer *) Object;
                                playerChar->AspectRatioAxisConstraint = EAspectRatioAxisConstraint::AspectRatio_MaintainYFOV;
                            }
                        }
                    }
                }
                if (ImGui::CollapsingHeader("测试功能")) {

                
                
                
                 ImGui::InputText("##key", s, sizeof(s));
                
                if (ImGui::Button("粘贴命令", ImVec2(-1, 35))) {
                    auto key = getClipboardText();
                    strncpy(s, key.c_str(), sizeof s);
                }
                
                if (ImGui::Button("执行命令", ImVec2(-1, 35))) {
                    UKismetSystemLibrary::ExecuteConsoleCommand(GetWorld(),std::string(s),UGameplayStatics::GetPlayerController(GetWorld(), 0));
                
                }
                
if (ImGui::CollapsingHeader("流式关卡管理")) {
    // 刷新按钮
    if (ImGui::Button("刷新关卡列表", ImVec2(-1, 35))) {
        RefreshLevelStreamingList();
    }
    ImGui::Separator();
    
    // 关卡列表显示区域
    ImGui::BeginChild("LevelList", ImVec2(0, 200), true);
    if (g_LevelStreamingList.empty()) {
        ImGui::Text("暂无关卡数据，请点击刷新");
    } else {
        for (int i = 0; i < (int)g_LevelStreamingList.size(); i++) {
            auto level = g_LevelStreamingList[i];
            if (!level) continue;
            if (ImGui::Selectable(level->GetName().c_str(), g_SelectedLevelIndex == i)) {
                g_SelectedLevelIndex = i;
            }
        }
    }
    ImGui::EndChild();
    ImGui::Separator();
    
    // 选中关卡信息及操作
    if (g_SelectedLevelIndex >= 0 && g_SelectedLevelIndex < (int)g_LevelStreamingList.size()) {
        ImGui::Text("当前选中: %s", g_LevelStreamingList[g_SelectedLevelIndex]->GetName().c_str());
    } else {
        ImGui::Text("未选中任何关卡");
    }
    if (ImGui::Button("隐藏选中", ImVec2(-1, 35))) HideSelectedLevel();
    if (ImGui::Button("移除选中", ImVec2(-1, 35))) UnloadSelectedLevel();
    if (ImGui::Button("恢复选中", ImVec2(-1, 35))) RestoreSelectedLevel();
    ImGui::Spacing();
    if (ImGui::Button("一键隐藏所有", ImVec2(-1, 35))) HideAllLevels();
    if (ImGui::Button("隐藏一半", ImVec2(-1, 35))) HideHalfLevels();
    if (ImGui::Button("一键显示所有", ImVec2(-1, 35))) ShowAllLevels();
    
    // 新增：生成 Actor 功能（含粘贴按钮）
    ImGui::Separator();
    ImGui::Text("生成 Actor（按路径）:");
    ImGui::PushItemWidth(-1);
    ImGui::InputText("##actor_path", g_ActorPath, sizeof(g_ActorPath));
    if (ImGui::Button("粘贴", ImVec2(-1, 30))) {
        std::string clip = getClipboardText();
        if (!clip.empty()) {
            strncpy(g_ActorPath, clip.c_str(), sizeof(g_ActorPath) - 1);
            g_ActorPath[sizeof(g_ActorPath) - 1] = '\0';
        }
    }
    if (ImGui::Button("生成", ImVec2(-1, 30))) {
        SpawnActorFromPath(g_ActorPath);
    }
    ImGui::PopItemWidth();
}






                }
                


                ImGui::EndTabItem();
            }
            
            
            ImGui::EndTabBar();
        }
    
    ImGui::End();
    
    const char* text = "";
    ImVec2 txtSize   = ImGui::CalcTextSize(text);
    ImVec2 pos{(float)glWidth - txtSize.x - 100.f, (float)glHeight - txtSize.y - 50.f};
ImGui::GetBackgroundDrawList()->AddText(nullptr, 25.2f, pos, IM_COL32(255, 0, 0, 255), text);


    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
    return orig_eglSwapBuffers(dpy, surface);
}

int32_t (*orig_onInputEvent)(android_app*, AInputEvent*);
int32_t onInputEvent(android_app* app, AInputEvent* e) {
    ImGui_ImplAndroid_HandleInputEvent(e,
        {(float)screenWidth/(float)glWidth, (float)screenHeight/(float)glHeight});
    return orig_onInputEvent ? orig_onInputEvent(app, e) : 0;
}

extern "C" void android_main(struct android_app*) { app_dummy(); }

void* main_thread(void*) {
    UE4 = get_Module_Base("libUE4.so");
    while (!UE4) { sleep(1); UE4 = get_Module_Base("libUE4.so"); }
    while (!g_App) { g_App = *(android_app**)(UE4 + 0x4249ca4); sleep(1); }
    orig_onInputEvent   = g_App->onInputEvent;
    g_App->onInputEvent = onInputEvent;
    FName::GNames       = GetGNames();
    UObject::GUObjectArray = (FUObjectArray*)(UE4 + 0x454dd28);
    DobbyHook((void*)DobbySymbolResolver("/system/lib/libEGL.so", "eglSwapBuffers"),
              (void*)_eglSwapBuffers, (void**)&orig_eglSwapBuffers);
    DobbyHook((void*)(UE4+0x0),(void*)gm,(void**)&ogm);
    

    return nullptr;
}

__attribute__((constructor))
void _init() {
    pthread_t tid;
    pthread_create(&tid, nullptr, main_thread, nullptr);
}




