#include <android/log.h>
#include <unistd.h>
#include <thread>
#include <limits>
#include <string>
#include <iostream>
#include <cstring>
#include <Struct/main.h>
#include <xdl.h>
#include <KittyUtils.h>
#include <KittyMemory/KittyMemory.h>
#include <KittyMemory/MemoryPatch.h>
#include <KittyMemory/KittyScanner.h>
#include <KittyMemory/KittyUtils.h>
#include <KittyMemory.h>
#include <Il2Cpp.h>
#include <SubstrateHook.h>
#include <CydiaSubstrate.h>
#include "Chams.h"
#include "Struct/gui.hpp"
#include "Struct/DrawMenu.h"
#include "FireWall.h"
#include "Zygisk_GoluYT.hpp"
#include "Golu-YT.h"
#include "GoluYT/Tools/Call_Tools.h"
#include "GoluYT/Font.h"
#include "GoluYT/CN.h"
#include "GoluYT/Icon.h"
#include "GoluYT/Iconcpp.h"
using Zygisk_GoluYT::AKG;
using Zygisk_GoluYT::GoluSingh366;
using Zygisk_GoluYT::GoluYT_Hack;
void hack();
void writeLog(const std::string& logMessage, const std::string& filename = "/storage/emulated/0/Android/data/com.dualspace.multispace.androidx/files/log.txt");


JavaVM *jvm;
JNIEnv *genv;
//extern JavaVM* jvm;
//extern JNIEnv* genv;

class MyModule : public Zygisk_GoluYT::ModuleBase {
 public:
  void onLoad(AKG *api, JNIEnv *env) override {
    this->api_ = api;
    this->env_ = env;
    genv = env;
   // gEnv = env;

  }

  void preAppSpecialize(GoluSingh366 *args) override {
    static constexpr const char *packages[] = {
        "com.dts.freefireth"
    };
    const char *process = env_->GetStringUTFChars(args->nice_name, nullptr);
    for (const auto *package: packages) {
      is_game_ = (strcmp(process, package) == 0);
      if (is_game_) {
        break;
      }
    }
    env_->ReleaseStringUTFChars(args->nice_name, process);
  }

  void postAppSpecialize(const GoluSingh366 *args) override {
    if (is_game_) {
       genv->GetJavaVM(&jvm);
     //  genv->GetJavaVM(&gJvm);
      std::thread{hack}.detach();
    }
  }

 private:
  AKG *api_ = nullptr;
  JNIEnv *env_ = nullptr;
  bool is_game_ = false;
};


uintptr_t il2cpp_base = 0;
void *getRealAddr(ulong offset) {
    return reinterpret_cast<void*>(il2cpp_base + offset);
};





void (*OpenURL)(String *url);
//inline static bool g_IsSetup = false;
//inline int prevWidth, prevHeight;
bool WORTERSYPORNO; 
bool GoluSingh366;
#include "imgui.h"
#include <cmath>


// Rainbow wheel with animated rotation
void DrawRotatingColorWheel(ImVec2 center, float radius, float time) {
    ImDrawList* draw_list = ImGui::GetWindowDrawList();
    const int num_segments = 60;
    for (int i = 0; i < num_segments; ++i) {
        float start_angle = (2.0f * IM_PI * i) / num_segments + time;
        float end_angle = (2.0f * IM_PI * (i + 1)) / num_segments + time;
        ImVec2 p1(center.x + cosf(start_angle) * radius, center.y + sinf(start_angle) * radius);
        ImVec2 p2(center.x + cosf(end_angle) * radius, center.y + sinf(end_angle) * radius);
        float hue = (float)i / num_segments;
        ImU32 color = ImColor::HSV(hue, 1.0f, 1.0f);
        draw_list->AddTriangleFilled(center, p1, p2, color);
    }
}

// Custom switch with proper rounded edges and bigger rainbow knob
void DrawCustomSwitch(const char* id, const char* label, bool* state, float time) {
    ImVec2 size = ImVec2(160, 70); // Switch size
    ImVec2 pos = ImGui::GetCursorScreenPos();
    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    // Perfect rounded corner (pill shape)
    float rounding = size.y / 2.0f;

    // Background
    ImU32 bg_color = *state ? IM_COL32(0, 200, 0, 255) : IM_COL32(120, 120, 120, 255);
    ImU32 border_color = IM_COL32(0, 255, 0, 255);
    draw_list->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), bg_color, rounding);
    draw_list->AddRect(pos, ImVec2(pos.x + size.x, pos.y + size.y), border_color, rounding, 0, 3.0f);

    // Knob position
    float knob_offset = *state ? (pos.x + size.x - 60) : (pos.x + 10);
    ImVec2 knob_center = ImVec2(knob_offset + 25, pos.y + size.y / 2);

    // Black circle background
    draw_list->AddCircleFilled(knob_center, 22, IM_COL32(0, 0, 0, 255)); // Slightly bigger

    // Rotating rainbow wheel (bigger)
    DrawRotatingColorWheel(knob_center, 26, time);

    // ON/OFF text (black)
    const char* onoff_text = *state ? "ON" : "OFF";
    ImVec2 text_size = ImGui::CalcTextSize(onoff_text);
    ImVec2 text_pos = *state
        ? ImVec2(pos.x + 10, pos.y + size.y / 2 - text_size.y / 2)
        : ImVec2(pos.x + size.x - text_size.x - 10, pos.y + size.y / 2 - text_size.y / 2);
    draw_list->AddText(text_pos, IM_COL32(0, 0, 0, 255), onoff_text);

    // Clickable button area
    ImGui::SetCursorScreenPos(pos);
    if (ImGui::InvisibleButton(id, size)) {
        *state = !*state;
    }

    // Label (right side)
    ImVec2 label_pos = ImVec2(pos.x + size.x + 10, pos.y + size.y / 2 - ImGui::CalcTextSize(label).y / 2);
    draw_list->AddText(label_pos, IM_COL32(0, 255, 255, 255), label);

    ImGui::Dummy(ImVec2(size.x + 100, size.y));
}
   
   // apne switch ki jagah ye switch lagao
   //DrawCustomSwitch("SPEED HACK", OBFUSCATE("SPEED HACK"), &Speed, ImGui::GetTime());


bool RainbowToggleSwitch(const char* label, bool* v)
{
    ImGui::PushID(label);

    static float knob_anim = 0.0f;
    static float hue_offset = 0.0f;

    float width = 90.0f;
    float height = 40.0f;
    float knob_radius = 16.0f;

    ImVec2 p = ImGui::GetCursorScreenPos();
    ImDrawList* draw_list = ImGui::GetWindowDrawList();

    ImU32 bgColor = *v ? IM_COL32(255,0,0, 255) : IM_COL32(0,255,0, 255);
    ImU32 textColor = IM_COL32(0, 0, 0, 255);

    // Background
    draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), bgColor, height * 0.5f);

    // Animate knob position
    float target = *v ? 1.0f : 0.0f;
    knob_anim = ImLerp(knob_anim, target, 0.5f); // smoothing

    float knob_x = ImLerp(p.x + knob_radius + 6, p.x + width - knob_radius - 6, knob_anim);
    ImVec2 knob_center = ImVec2(knob_x, p.y + height / 2);

    // Rotate rainbow
    hue_offset += 0.01f;
    if (hue_offset > 1.0f) hue_offset -= 1.0f;

    // Draw rainbow circle
    float inner_radius = 0.0f;
    float outer_radius = knob_radius;
    int segments = 100;
    for (int i = 0; i < segments; ++i)
    {
        float a0 = (i / (float)segments) * 2.0f * IM_PI;
        float a1 = ((i + 1) / (float)segments) * 2.0f * IM_PI;

        ImVec2 p0 = ImVec2(knob_center.x + cosf(a0) * inner_radius, knob_center.y + sinf(a0) * inner_radius);
        ImVec2 p1 = ImVec2(knob_center.x + cosf(a1) * inner_radius, knob_center.y + sinf(a1) * inner_radius);
        ImVec2 p2 = ImVec2(knob_center.x + cosf(a1) * outer_radius, knob_center.y + sinf(a1) * outer_radius);
        ImVec2 p3 = ImVec2(knob_center.x + cosf(a0) * outer_radius, knob_center.y + sinf(a0) * outer_radius);

        float hue = fmodf(i / (float)segments + hue_offset, 1.0f);
        ImU32 col = ImColor::HSV(hue, 1.0f, 1.0f);

        draw_list->AddQuadFilled(p0, p1, p2, p3, col);
    }

    // Text ON/OFF
    const char* text = *v ? "ON" : "OFF";
    ImVec2 textSize = ImGui::CalcTextSize(text);
    ImVec2 textPos = ImVec2(
        *v ? (p.x + 12) : (p.x + width - textSize.x - 12),
        p.y + (height - textSize.y) / 2
    );
    draw_list->AddText(textPos, textColor, text);

    // Toggle button (interaction)
    ImGui::InvisibleButton("##switch", ImVec2(width, height));
    if (ImGui::IsItemClicked())
        *v = !*v;

    // Ending format matching CustomToggleSwitch
    ImGui::SameLine();
    ImGui::Text(label);

    ImGui::PopID();
    return *v;
}
//# define HOOK(offset, ptr, orig) MSHookFunction((void *)getAbsoluteAddress(targetLibName, offset), (void *)ptr, (void **)&orig);


bool clearMousePos = true;
bool initImGui = false;

void SetupImgui() {
    IMGUI_CHECKVERSION();
    
    ImGui::CreateContext();
    ImGui_ImplAndroid_Init(nullptr);
    ImGuiIO& io = ImGui::GetIO();
    ImGuiStyle* style = &ImGui::GetStyle();
    io.Fonts->AddFontFromMemoryTTF((void *)BaiduZY_data, BaiduZY_size, 35.0f, NULL, io.Fonts->GetGlyphRangesChineseFull());
    //io.DisplaySize = ImVec2((float)g_GlWidth, (float)g_GlHeight);

    ImGui_ImplOpenGL3_Init("#version 300 es");
    ImFontConfig font_cfg;
    font_cfg.SizePixels = 22.0f;
    io.Fonts->AddFontDefault(&font_cfg);

    ImVec4 whiteColor(1.0f, 1.0f, 1.0f, 1.0f);
    style->WindowTitleAlign = ImVec2(0.5f,0.5f);

  //  ImGui::StyleColorsLight();
    ImGui::StyleColorsDark();//   Màu Xanh Nước Biển

    ImFontConfig CustomFont;
    CustomFont.FontDataOwnedByAtlas = false;
    font_cfg.SizePixels = 22.0f;
    static const ImWchar vietnamese_chars[] = {
        0x0020, 0x00FF, // Basic Latin + Latin Supplement
        0x0102, 0x0103, // Â, â
        0x0110, 0x0111, // Đ, đ
        0x0128, 0x0129, // Ĩ, ĩ
        0x0168, 0x0169, // Ũ, ũ
        0x01A0, 0x01A1, // Ơ, ơ
        0x01AF, 0x01B0, // Ư, ư
        0x1EA0, 0x1EF9, // Vietnamese specific characters
        0 // null-terminated list
    };
    ImGui::GetStyle().ScaleAllSizes(3.0f);
}



//bool clearMousePos = true;
bool ImGuiOK = false;
//bool initImGui = false;
//bool rainbow = false;
inline EGLBoolean (*old_eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface);
inline EGLBoolean hook_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
    
        eglQuerySurface(dpy, surface, EGL_WIDTH, &g_GlWidth);
    eglQuerySurface(dpy, surface, EGL_HEIGHT, &g_GlHeight);
    
    

    if (!g_IsSetup) {
        prevWidth = g_GlWidth;
        prevHeight = g_GlHeight;
        SetupImgui();
        
        g_IsSetup = true;
    }
    
    

    ImGuiIO &io = ImGui::GetIO();
	//Darkness();
	// Thiết lập màu chủ đề
	ImVec4* colors = ImGui::GetStyle().Colors;

	colors[ImGuiCol_Text]                   = ImVec4(0.86f, 0.86f, 0.86f, 1.00f); // Màu chữ
	colors[ImGuiCol_TextDisabled]           = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); // Màu chữ vô hiệu hóa
	colors[ImGuiCol_WindowBg]               = ImVec4(0.16f, 0.16f, 0.16f, 0.95f); // Màu nền cửa sổ
	colors[ImGuiCol_ChildBg]                = ImVec4(0.18f, 0.18f, 0.18f, 0.58f); // Màu nền bên trong Child window
	colors[ImGuiCol_PopupBg]                = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); // Màu nền của Popup window
	colors[ImGuiCol_Border]                 = ImVec4(0.08f, 0.08f, 0.08f, 0.40f); // Màu đường viền
	colors[ImGuiCol_BorderShadow]           = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); // Màu bóng đổ đường viền
	colors[ImGuiCol_FrameBg]                = ImVec4(0.27f, 0.27f, 0.27f, 0.54f); // Màu nền Frame
	colors[ImGuiCol_FrameBgHovered]         = ImVec4(0.47f, 0.47f, 0.47f, 0.40f); // Màu nền Frame khi hover
	colors[ImGuiCol_FrameBgActive]          = ImVec4(0.40f, 0.40f, 0.40f, 0.67f); // Màu nền Frame khi active
	colors[ImGuiCol_TitleBg]                = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); // Màu nền tiêu đề cửa sổ
	colors[ImGuiCol_TitleBgActive]          = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); // Màu nền tiêu đề cửa sổ khi active
	colors[ImGuiCol_TitleBgCollapsed]       = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); // Màu nền tiêu đề cửa sổ khi bị thu gọn
	colors[ImGuiCol_MenuBarBg]              = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); // Màu nền của MenuBar
	colors[ImGuiCol_ScrollbarBg]            = ImVec4(0.02f, 0.02f, 0.02f, 0.53f); // Màu nền của thanh cuộn
	colors[ImGuiCol_ScrollbarGrab]          = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); // Màu của cần cẩu thanh cuộn
	colors[ImGuiCol_ScrollbarGrabHovered]   = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); // Màu của cần cẩu thanh cuộn khi hover
	colors[ImGuiCol_ScrollbarGrabActive]    = ImVec4(0.51f, 0.51f, 0.51f, 1.00f); // Màu của cần cẩu thanh cuộn khi active
	colors[ImGuiCol_CheckMark]              = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); // Màu của dấu check
	colors[ImGuiCol_SliderGrab]             = ImVec4(0.24f, 0.52f, 0.88f, 1.00f); // Màu của cần cẩu thanh trượt
	colors[ImGuiCol_SliderGrabActive]       = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); // Màu của cần cẩu thanh trượt khi active
	colors[ImGuiCol_Button]                 = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); // Màu của nút
	colors[ImGuiCol_ButtonHovered]          = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); // Màu của nút khi hover
	colors[ImGuiCol_ButtonActive]           = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); // Màu của nút khi active
	colors[ImGuiCol_Header]                 = ImVec4(0.26f, 0.59f, 0.98f, 0.31f); // Màu của tiêu đề
	colors[ImGuiCol_HeaderHovered]          = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); // Màu của tiêu đề khi hover
	colors[ImGuiCol_HeaderActive]           = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); // Màu của tiêu đề khi active
	colors[ImGuiCol_Separator]              = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); // Màu của dấu phân cách
	colors[ImGuiCol_SeparatorHovered]       = ImVec4(0.10f, 0.40f, 0.75f, 0.78f); // Màu của dấu phân cách khi hover
	colors[ImGuiCol_SeparatorActive]        = ImVec4(0.10f, 0.40f, 0.75f, 1.00f); // Màu của dấu phân cách khi active
	colors[ImGuiCol_ResizeGrip]             = ImVec4(0.26f, 0.59f, 0.98f, 0.25f); // Màu của khớp co giãn
	colors[ImGuiCol_ResizeGripHovered]      = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); // Màu của khớp co giãn khi hover
	colors[ImGuiCol_ResizeGripActive]       = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); // Màu của khớp co giãn khi active
	colors[ImGuiCol_Tab]                    = ImVec4(0.18f, 0.18f, 0.18f, 0.86f); // Màu của tab
	colors[ImGuiCol_TabHovered]             = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); // Màu của tab khi hover
	colors[ImGuiCol_TabActive]              = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); // Màu của tab khi active
	colors[ImGuiCol_TabUnfocused]           = ImVec4(0.06f, 0.06f, 0.06f, 0.97f); // Màu của tab khi không focus
	colors[ImGuiCol_TabUnfocusedActive]     = ImVec4(0.13f, 0.13f, 0.13f, 1.00f); // Màu của tab khi không focus nhưng active
	colors[ImGuiCol_PlotLines]              = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); // Màu của đồ thị dạng line
	colors[ImGuiCol_PlotLinesHovered]       = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); // Màu của đồ thị dạng line khi hover
	colors[ImGuiCol_PlotHistogram]          = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); // Màu của đồ thị dạng histogram
	colors[ImGuiCol_PlotHistogramHovered]   = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); // Màu của đồ thị dạng histogram khi hover
	colors[ImGuiCol_TextSelectedBg]         = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); // Màu nền khi chọn văn bản
	colors[ImGuiCol_DragDropTarget]         = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); // Màu của Drag and Drop target
	colors[ImGuiCol_NavHighlight]           = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); // Màu highlight trong navigation
	colors[ImGuiCol_NavWindowingHighlight]  = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); // Màu highlight trong navigation khi windowing
	colors[ImGuiCol_NavWindowingDimBg]      = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); // Màu nền khi windowing
	colors[ImGuiCol_ModalWindowDimBg]       = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); // Màu nền khi modal window

    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplAndroid_NewFrame(g_GlWidth, g_GlHeight);
    ImGui::NewFrame();
	if (ImGuiOK) {
	    int touchCount = (((int (*)())(Class_Input__get_touchCount))());
    if (touchCount > 0) {
        UnityEngine_Touch_Fields touch = ((UnityEngine_Touch_Fields(*)(int))(Class_Input__GetTouch))(0);
        float reverseY = io.DisplaySize.y - touch.m_Position.fields.y;
        switch (touch.m_Phase) {
            case TouchPhase::Began:
            case TouchPhase::Stationary:
                io.MousePos = ImVec2(touch.m_Position.fields.x, reverseY);
                io.MouseDown[0] = true;
                break;
            case TouchPhase::Ended:
            case TouchPhase::Canceled:
                io.MouseDown[0] = false;
                clearMousePos = true;
                break;
            case TouchPhase::Moved:
                io.MousePos = ImVec2(touch.m_Position.fields.x, reverseY);
                break;
            default:
                break;
        }
    }
	}
	//DrawESP(g_GlWidth, g_GlHeight);  
	
    ExpireDate exp;
    exp.setExpirationDate(27,7,2025);//d,m,y
    if (exp.isExpired()) {
    //ImGui::SetNextWindowSize(ImVec2(glWidth/3.5, glHeight/1.5), ImGuiCond_FirstUseEver);
    ImGui::Begin(OBFUSCATE("MODS MENU EXPIRED️"));

  ImGui::Text(OBFUSCATE("MOD MENU EXPIRED"));
    OpenURL(Il2CppString::Create("https://t.me/+"));
}
    
    DrawESP(g_GlWidth, g_GlHeight);
static float isRed = 0.0f, isGreen = 0.01f, isBlue = 0.0f;
const float speed = 0.05f;  // Speed increase

if (isGreen == 0.01f && isBlue == 0.0f) {
    isRed += speed;
}

if (isRed > 0.99f && isBlue == 0.0f) {
    isRed = 1.0f;
    isGreen += speed;
}

if (isGreen > 0.99f && isBlue == 0.0f) {
    isGreen = 1.0f;
    isRed -= speed;
}

if (isRed < 0.01f && isGreen == 1.0f) {
    isRed = 0.0f;
    isBlue += speed;
}

if (isBlue > 0.99f && isRed == 0.0f) {
    isBlue = 1.0f;
    isGreen -= speed;
}

if (isGreen < 0.01f && isBlue == 1.0f) {
    isGreen = 0.0f;
    isRed += speed;
}

if (isRed > 0.99f && isGreen == 0.0f) {
    isRed = 1.0f;
    isBlue -= speed;
}

if (isBlue < 0.01f && isGreen == 0.0f) {
    isBlue = 0.0f;
    isRed -= speed;
    if (isRed < 0.01f) isGreen = 0.01f;
}

ImGui::PushStyleColor(ImGuiCol_Border, ImColor(isRed, isBlue, isGreen, 1.0f).Value);

    ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));


    
ImGui::SetNextWindowSize(ImVec2(620, 520), ImGuiCond_Once);
   if (ImGui::Begin(OBFUSCATE("MODS  !! PC LOGO !! "), 0, ImGuiWindowFlags_NoBringToFrontOnFocus)) {

{
    // Get window position and size.
    ImVec2 winPos  = ImGui::GetWindowPos();
    ImVec2 winSize = ImGui::GetWindowSize();
    auto bg        = ImGui::GetBackgroundDrawList();

    // Time variable for dynamic animations.
    float t = ImGui::GetTime();

    // Dynamically calculate each corner's color using sin wave oscillation.
    // You can adjust amplitude and frequency as desired.
    ImColor colTL = ImColor(
        int(255 + 0 * sin(t * 255)),  // R: base 102, oscillation ±20
        int(255 + 0 * sin(t * 255)),  // G: base 126
        int(234 + 20 * sin(t * 0.7f)),  // B: base 234
        255                           // Alpha fully opaque
    );
    ImColor colTR = ImColor(
        int(255 + 20 * sin(t * 0.8f)),  // R: base 255
        int(204 + 20 * sin(t * 0.9f)),  // G: base 204
        int(0   + 20 * sin(t * 1.0f)),  // B: base 0, yellowish tone
        255
    );
    ImColor colBL = ImColor(
        int(0   + 20 * sin(t * 1.1f)),  // R: base 0
        int(210 + 20 * sin(t * 1.2f)),  // G: base 210
        int(255 + 20 * sin(t * 1.3f)),  // B: base 255
        255
    );
    ImColor colBR = ImColor(
        int(118 + 20 * sin(t * 1.4f)),  // R: base 118
        int(75  + 20 * sin(t * 1.5f)),  // G: base 75
        int(162 + 20 * sin(t * 1.6f)),  // B: base 162
        255
    );

    // Draw the gradient background.
    // The rectangle is fixed, ensuring full coverage, while the colors dynamically mix.
    bg->AddRectFilledMultiColor(
        ImVec2(winPos.x - 10, winPos.y - 10), 
        ImVec2(winPos.x + winSize.x + 10, winPos.y + winSize.y + 10),
        colTL,
        colTR,
        colBL,
        colBR
    );

   
  
      	            if (ImGui::BeginTabBar("##tabbar", ImGuiTabBarFlags_None)) {
						
          	            if (ImGui::BeginTabItem(OBFUSCATE("Aim Menu"))) {
                           RainbowToggleSwitch(OBFUSCATE("Aim Bot (Devoloper :- @"), &Aimbot);//ImGui::Text(OBFUSCATE("Chams Custom"));
						   ImGui::Separator();
                            RainbowToggleSwitch(OBFUSCATE("Aim Visible"), &AimWhen2);
							ImGui::Separator();
							RainbowToggleSwitch(OBFUSCATE("Aimsilent"), &AimSilent);
							ImGui::Separator();
							RainbowToggleSwitch(OBFUSCATE("PC LOGO"), &NikuPapa);
							ImGui::Separator();
                            ImGui::SliderFloat(OBFUSCATE("Aim Fov"),&Fov_Aim,0.0f,660.0f,"%.f");
				   ImGui::Text(OBFUSCATE("CLICK AND SEND FEEDBACK"));
     
                            if (ImGui::Button(OBFUSCATE("   JOIN TELEGRAM NEXT VERSION       "))){

                            OpenURL(Il2CppString::Create(OBFUSCATE("https://t.me/+")));
     }			
							
                    ImGui::EndTabItem();
                        }
          	            if (ImGui::BeginTabItem(OBFUSCATE("Esp Menu"))) {
                            

							RainbowToggleSwitch(OBFUSCATE("Active Function"), &Enable);
							ImGui::Separator();
                           RainbowToggleSwitch(OBFUSCATE("Esp Line"), &Config.ESP.Line); 
							ImGui::Separator();
                            RainbowToggleSwitch(OBFUSCATE("Esp Box"), &box);
							ImGui::Separator();
                            RainbowToggleSwitch(OBFUSCATE("ESP Health"), &Config.ESP.Target);
							ImGui::Separator();
                            (OBFUSCATE("ESP Info"), &Config.ESP.Health);						
                            ImGui::EndTabItem();
                        
						}
						ImGui::EndTabItem();
                        }
          	            if (ImGui::BeginTabItem(OBFUSCATE("Chams"))) {
					
                  RainbowToggleSwitch("Chams Active",&wireframe);
	ImGui::Separator();
ImGui::Text(OBFUSCATE("Chams Custom"));

ImGui::SliderFloat(OBFUSCATE("Red"), &r, 0.0f, 255.0f);
            ImGui::SliderFloat(OBFUSCATE("Green"), &g, 0.0f, 255.0f);
            ImGui::SliderFloat(OBFUSCATE("Blue"), &b, 0.0f, 255.0f);


			 
			    }
			    
						
					
    ImGui::EndTabItem();
}
						
          	            if (ImGui::BeginTabItem(OBFUSCATE("Other"))) {

							//ImGui::Checkbox(OBFUSCATE("Bypass Active"), &Firewall);
                           RainbowToggleSwitch(OBFUSCATE("Speed Run"), &speedrun);
							ImGui::Separator();
                           RainbowToggleSwitch(OBFUSCATE("Reset Guest"), &Reset);
							}
                            ImGui::EndTabItem();
                      
	 
    

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


typedef unsigned long DWORD;
static uintptr_t libBase;
inline void hack_injec();
inline void StartGUI() {
    void *ptr_eglSwapBuffer = DobbySymbolResolver("/system/lib/libEGL.so", "eglSwapBuffers");
    if (NULL != ptr_eglSwapBuffer) {
        DobbyHook((void *)ptr_eglSwapBuffer, (void*)hook_eglSwapBuffers, (void**)&old_eglSwapBuffers);
            LOGD("Gui Started");
			hack_injec();
        }
    }

bool libLoaded = false;

DWORD findLibrary(const char *library) {
    char filename[0xFF] = {0},
            buffer[1024] = {0};
    FILE *fp = NULL;
    DWORD address = 0;

    sprintf(filename, OBFUSCATE("/proc/self/maps"));

    fp = fopen(filename, OBFUSCATE("rt"));
    if (fp == NULL) {
        perror(OBFUSCATE("fopen"));
        goto done;
    }

    while (fgets(buffer, sizeof(buffer), fp)) {
        if (strstr(buffer, library)) {
            address = (DWORD) strtoul(buffer, NULL, 16);
            goto done;
        }
    }

    done:

    if (fp) {
        fclose(fp);
    }

    return address;
}

DWORD getAbsoluteAddress(const char *libraryName, DWORD relativeAddr) {
    libBase = findLibrary(libraryName);
    if (libBase == 0)
        return 0;
    return (reinterpret_cast<DWORD>(libBase + relativeAddr));
}
ProcMap unityMap, anogsMap, il2cppMap;
using KittyScanner::RegisterNativeFn;



    
    
void hack() {
     LOGD("Inject Ok");
    //std::thread thread_hack(hack_thread, getpid());
    //thread_hack.detach();
    
}
uintptr_t get_symbol_addr_in_pid(pid_t pid, const char* libname, uintptr_t offset_in_lib) {
    char maps_path[64];
    snprintf(maps_path, sizeof(maps_path), "/proc/%d/maps", pid);

    FILE* fp = fopen(maps_path, "r");
    if (!fp) return 0;

    char line[512];
    uintptr_t base = 0;

    while (fgets(line, sizeof(line), fp)) {
        if (strstr(line, libname)) {
            sscanf(line, "%lx-%*lx", &base);
            break;
        }
    }
    fclose(fp);

    if (base == 0) return 0;
    return base + offset_in_lib;
}

pid_t get_pid_by_name(const char* process_name) {
    DIR* proc_dir = opendir("/proc");
    if (!proc_dir) return -1;

    struct dirent* entry;
    while ((entry = readdir(proc_dir)) != NULL) {
        if (entry->d_type != DT_DIR) continue;

        pid_t pid = atoi(entry->d_name);
        if (pid <= 0) continue;

        char cmdline_path[256];
        snprintf(cmdline_path, sizeof(cmdline_path), "/proc/%d/cmdline", pid);

        FILE* fp = fopen(cmdline_path, "r");
        if (!fp) continue;

        char cmdline[256];
        fgets(cmdline, sizeof(cmdline), fp);
        fclose(fp);

        if (strstr(cmdline, process_name)) {
            closedir(proc_dir);
            return pid;
        }
    }

    closedir(proc_dir);
    return -1;
}

#include <cstdio>

void writeLog(const std::string& logMessage, const std::string& filename) {
    FILE* file = fopen(filename.c_str(), "a");  // Open in append mode
    if (file) {
        fprintf(file, "%s\n", logMessage.c_str());
        fclose(file);
    } else {
        // Can't use cerr either; log to logcat or do nothing
        // You can use __android_log_print instead if needed
    }
}

bool is_current_process(const char* target_name) {
    char cmdline_path[64];
    snprintf(cmdline_path, sizeof(cmdline_path), "/proc/%d/cmdline", getpid());

    FILE* fp = fopen(cmdline_path, "r");
    if (!fp) return false;

    char cmdline[256] = {0};
    fgets(cmdline, sizeof(cmdline), fp);
    fclose(fp);

    return strcmp(cmdline, target_name) == 0;
}

void hack_injec() {
	while (!unityMap.isValid()) {
        unityMap = KittyMemory::getLibraryBaseMap("libunity.so");
		anogsMap = KittyMemory::getLibraryBaseMap("libanogs.so");
		il2cppMap = KittyMemory::getLibraryBaseMap("libil2cpp.so");
		
        sleep(6);
	}
    
 sleep(5);
    Il2CppAttach();
	
	if (mlovinit()) {
        setShader("_AlphaMask");
        LogShaders();
        Wallhack();
    }
    
    //DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("Player"), OBFUSCATE("LateUpdate"), 0), (void *) _LateUpdate, (void **) &LateUpdate);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("Player"), OBFUSCATE("UpdateBehavior"), 2), (void *) _LateUpdate, (void **) &LateUpdate);
    //aim silent
	DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("Player"), OBFUSCATE("OJOHLBJEIJO"), 2), (void *) hook_mrAimSilent, (void **)&orig_mrSilentAim);
	
	DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE(""), OBFUSCATE("GGP"), OBFUSCATE("getEVData"), 0), (void *)_hookpclogo, (void **)& origpclogo);
    
DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE(""), OBFUSCATE("GGP"), OBFUSCATE("IsEmulator"), 0),  (void *)_hookpclogo, (void **)& origpclogo);
	
  //DobbyHook((void *)getRealOffset(0x13899b0), (void *)AimSilent_Hook, (void **)&AimSilent_Backup);
	//Tools::Hook((void *) (uintptr_t)IL2Cpp::Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("Player"), OBFUSCATE("OJOHLBJEIJO"), 2), (void *) hook_mrAimSilent, (void **)&orig_mrSilentAim);
	 //Tools::Hook((void *) (uintptr_t)IL2Cpp::Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("Player"), OBFUSCATE("OJOHLBJEIJO"), 2), (void *) hook_mrAimSilent, (void **)&orig_mrSilentAim);
    // Speed Run
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("Player"), OBFUSCATE("IsFoldWingGliding"), 0), (void *) _IsFoldWingGliding, (void **)& IsFoldWingGliding);
	DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("message"), OBFUSCATE("LLOABGDLMGK"), OBFUSCATE("LEBIPIGPEEP"), 1), (void *) _LEBIPIGPEEP, (void **)& LEBIPIGPEEP);
	//DobbyHook((void *)(uintptr_t)Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("Player"), OBFUSCATE("CGAHOGKAFNJ"), 0), (void *) _camcao0, (void **) &camcao0);

    // ResetGuest
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW"), OBFUSCATE("GameConfig") , OBFUSCATE("get_ResetGuest"), 0), (void *) ResetGuest, (void **) &_ResetGuest);
    
    // Bypass
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("UnityEngine.CoreModule.dll"), OBFUSCATE("UnityEngine"), OBFUSCATE("AndroidJNI"), OBFUSCATE("IsInstanceOf"), 2), (void *) &_Bypass, (void **) &Bypass);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("JPPGAJBAAKK"), OBFUSCATE("IsOnlineGame"), 2), (void *) &_Bypass, (void **) &Bypass);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("AnoSDKNamespace"), OBFUSCATE("IOPOOHPNCKH"), OBFUSCATE("LBABEMNOJAJ"), 8), (void *) &_Bypass, (void **) &Bypass);
    
    //Fix Game
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("mscorlib.dll"), OBFUSCATE("System"), OBFUSCATE("SerializableAttribute"), OBFUSCATE(".ctor"), 0), (void *) &_FixGame, (void **) &FixGame);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("GarenaMSDK"), OBFUSCATE("GarenaMSDKMgr"), OBFUSCATE("IsPlatformInstalled"), 0), (void *) &_FixGame, (void **) &FixGame);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("System.dll"), OBFUSCATE("System.Net"), OBFUSCATE("WebProxy"), OBFUSCATE("IsBypassed"), 0), (void *) &_FixGame, (void **) &FixGame);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("System.dll"), OBFUSCATE("System.Net"), OBFUSCATE("IWebProxy"), OBFUSCATE("IsBypassed"), 0), (void *) &_FixGame, (void **) &FixGame);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("System.dll"), OBFUSCATE("System.Net"), OBFUSCATE("WebProxy"), OBFUSCATE(".ctor"), 0), (void *) &_FixGame, (void **) &FixGame);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("System.dll"), OBFUSCATE("System.Net"), OBFUSCATE("WebProxy"), OBFUSCATE("CheckBypassList"), 0), (void *) &_FixGame, (void **) &FixGame);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW"), OBFUSCATE("EventLogger"), OBFUSCATE("LogReportCheatInHistory"), 0), (void *) &_FixGame, (void **) &FixGame);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW"), OBFUSCATE("EventLogger"), OBFUSCATE("LogReportCheat"), 0), (void *) &_FixGame, (void **) &FixGame);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW"), OBFUSCATE("MobileReplayManager"), OBFUSCATE("GetGameTimeMS"), 0), (void *) &_FixGame, (void **) &FixGame);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW"), OBFUSCATE("CreditPunishManager"), OBFUSCATE("ShowPunishWindow"), 0), (void *) &_FixGame, (void **) &FixGame);

	
	
	
	
    // Bypass Esp
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("SceneGraphicsQuality"), OBFUSCATE("SetGraphicsQuality"), 0), (void *) _BypassESP, (void **) &BypassESP);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("UnityEngine.CoreModule.dll"), OBFUSCATE("UnityEngine"), OBFUSCATE("Screen"), OBFUSCATE("SetResolution"), 0), (void *) _BypassESP, (void **) &BypassESP);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("UnityEngine.CoreModule.dll"), OBFUSCATE("UnityEngine"), OBFUSCATE("QualitySettings"), OBFUSCATE("GetQualityLevel"), 0), (void *) _BypassESP, (void **) &BypassESP);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("SceneGraphicsQuality"), OBFUSCATE("SetGraphicsQuality"), 0), (void *) _BypassESP, (void **) &BypassESP);

    // Bypass New
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("GCommon"), OBFUSCATE("PlatformUtility_Android"), OBFUSCATE("IsPackageInstalled"), 0), (void *) _Set_Aim, (void **) &Set_Aim);
    DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("GCommon"), OBFUSCATE("PlatformUtility_Android"), OBFUSCATE("CheckFileExists"), 0), (void *) _Set_Aim, (void **) &Set_Aim);
 OpenURL = (void (*)(String *))Il2CppGetMethodOffset("UnityEngine.CoreModule.dll","UnityEngine","Application","OpenURL",1);
    ImGuiOK = true;
    
}


void hack_thread(pid_t pid) {
	
	StartGUI();
	while(pid == -1){pid = get_pid_by_name("com.dts.freefireth");} 
	remote_inject(pid);
	writeLog(to_string(pid));
    
}
__attribute__((constructor))
void lib_main()
{
    std::thread thread_hack(hack_thread, get_pid_by_name("com.dts.freefireth"));
    thread_hack.detach();
}
//REGISTER_Zygisk_GoluYT_MODULE( by GoluYT)

