
// PAID SRC BY @RISHABHMODX
#include <android/log.h>
#include <unistd.h>
#include <thread>
#include <limits>
#include <KittyMemory/KittyMemory.h>
#include <KittyMemory/MemoryPatch.h>
#include <KittyMemory/KittyScanner.h>
#include <KittyMemory/KittyUtils.h>
#include <xdl.h>
#include <KittyUtils.h>
#include <KittyMemory.h>
#include <Il2Cpp.h>
#include <ImguiPP.h>
#include <Themes.h>
#include <fstream>
#include <SubstrateHook.h>
#include <CydiaSubstrate.h>
#include "RishabhHooks/gui.hpp"
#include "Firewall.h"
#include "exptime.h"
#include "Chams.h"
#include "oxorany/oxorany.h"
#include "kalaland.h"
#include "Icon/OPPOSans-H.h"
#include "Rishabh_AutoUpdate/Icon.h"
#include "Rishabh_AutoUpdate/Iconcpp.h"
#include "il2cpp.h"
#include "fonts/FontAwesome6_solid.h"
#include "kalaland.hpp"
#include "Rishabh_AutoUpdate/Tools/Call_Tools.h"
// PAID SRC BY @RISHABHMODX

#include "BebasNeue-Regular.h"
float SIZE_REDUCE = 0.f;
bool REDUCER = true;
ImFont* F50 = nullptr;
ImFont* F107 = nullptr;
ImFont* SOCIAL = nullptr;
ImFont* Bold = nullptr;
//============
void (*OpenURL)(String *url);

struct My_Patches {
    MemoryPatch Bypass1;
    MemoryPatch Bypass2;
    MemoryPatch Bypass3;
    MemoryPatch Bypass4;
    MemoryPatch Bypass5;
    MemoryPatch Bypass6;
    MemoryPatch Bypass7;
    MemoryPatch Bypass8;
    MemoryPatch Bypass9;
    MemoryPatch Bypass10;
    MemoryPatch Bypass11;
    MemoryPatch Bypass12;
    MemoryPatch Bypass13;
    MemoryPatch Bypass14;
    MemoryPatch Bypass15;
    
    MemoryPatch Guest;
} hexPatches;
using zygisk::Api;
using zygisk::AppSpecializeArgs;
using zygisk::ServerSpecializeArgs;



void hack();
void writeLog(const std::string& logMessage, const std::string& filename = "/storage/emulated/0/Android/data/com.dualspace.multispace.androidx/files/log.txt");


// PAID SRC BY @RISHABHMODX

class MyModule : public zygisk::ModuleBase {
 public:
  void onLoad(Api *api, JNIEnv *env) override {
    this->api_ = api;
    this->env_ = env;
  

  }

  void preAppSpecialize(AppSpecializeArgs *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 AppSpecializeArgs *args) override {
    if (is_game_) {

     //  genv->GetJavaVM(&gJvm);
      std::thread{hack}.detach();
    }
  }

 private:
  Api *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);
};

struct checkbox_animation {
    float animation;
    float text_opacity;
    float clr1, clr2, clr3; // ये menu[] से आते हैं, सुनिश्चित करें कि menu[] एक्सेसिबल है
    float lodaa;
    float lodaa1;
    float lodaa2;
    checkbox_animation() : animation(0.0f), text_opacity(0.5f), clr1(90/255.0f), clr2(90/255.0f), clr3(90/255.0f), lodaa(0.5f), lodaa1(0.0f), lodaa2(255/255.0f) {}
};

struct tab_animation {
    float lerped_alpha; // 0.0f से 1.0f तक, रंग परिवर्तन के लिए
    tab_animation() : lerped_alpha(0.0f) {}
};

static std::map<ImGuiID, checkbox_animation> g_checkbox_animations;
static std::map<ImGuiID, tab_animation> g_tab_animations;

bool MyCustomCheckbox(const char* label, bool* v) { 
    ImGuiWindow* window = ImGui::GetCurrentWindow();
    if (window->SkipItems)
        return false;
    ImGuiContext& g = *GImGui;
    const ImGuiStyle& style = g.Style;
    const ImGuiID id = window->GetID(label);
    const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);

    const float content_width_for_checkbox = ImGui::GetContentRegionAvail().x;
    const float w = content_width_for_checkbox - 5; 

    const ImVec2 pos = window->DC.CursorPos;
    const ImRect jaat(ImVec2(pos.x + 10, pos.y), ImVec2(pos.x + w, pos.y + 35));

    ImGui::ItemSize(jaat, 0.f);
    if (!ImGui::ItemAdd(jaat, id)) return false;
    bool hovered, held, pressed = ImGui::ButtonBehavior(jaat, id, &hovered, &held);
    if (ImGui::IsItemClicked()) {
        *v = !(*v);
        ImGui::MarkItemEdited(id);
    }

    auto it_anim = g_checkbox_animations.find(id);
    if (it_anim == g_checkbox_animations.end()) {
        g_checkbox_animations.insert({ id, checkbox_animation() });
        it_anim = g_checkbox_animations.find(id);
    }

    float delta_time = ImGui::GetIO().DeltaTime;
    float animation_factor = delta_time > 0 ? (1.0f / 0.24f) * delta_time : 1.0f;
    animation_factor = ImClamp(animation_factor, 0.0f, 1.0f);

    float circle_start_x = jaat.Max.x - 58 + 13.0f;
    float circle_slide_distance = 29.0f;

    it_anim->second.animation = ImLerp(it_anim->second.animation, *v ? 1.0f : 0.0f, 0.24f);
    it_anim->second.text_opacity = ImLerp(it_anim->second.text_opacity, *v ? 1.0f : 0.5f, 0.45f);
    it_anim->second.lodaa = ImLerp(it_anim->second.lodaa, *v ? 1.0f : 0.5f, 0.17f);
    it_anim->second.lodaa1 = ImLerp(it_anim->second.lodaa1, *v ? 1.0f : 0.0f, 0.07f);
    it_anim->second.lodaa2 = ImLerp(it_anim->second.lodaa2, *v ? 1.0f : 1.0f, 0.07f);

    // ✅ Fixed: Text white/gray instead of black
    ImU32 text_col = ImColor(255, 255, 255, (int)(it_anim->second.text_opacity * 255));
    window->DrawList->AddText(NULL, 32.0f, 
        ImVec2(jaat.Min.x + 0, jaat.Min.y + 6.5), 
        text_col, label);

    // Background
    window->DrawList->AddRectFilled(ImVec2(jaat.Max.x - 60, jaat.Min.y + 3), 
        ImVec2(jaat.Max.x - 0, jaat.Max.y - 3), 
        ImColor(100, 100, 100, 255), 100.f, ImDrawFlags_RoundCornersAll);

    // Active color overlay (red here)
    window->DrawList->AddRectFilled(ImVec2(jaat.Max.x - 60, jaat.Min.y + 3), 
        ImVec2(jaat.Max.x - 0, jaat.Max.y - 3), 
        ImColor(207, 120, 39, (int)(it_anim->second.lodaa1 * 255)), 100.f, ImDrawFlags_RoundCornersAll);

    // Circle knob
    window->DrawList->AddCircleFilled(
        ImVec2(circle_start_x + circle_slide_distance * it_anim->second.animation, jaat.GetCenter().y), 
        13.0f, ImColor(220, 220, 220, 255), 360);

    IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (*v ? ImGuiItemStatusFlags_Checked : 0));
    return pressed;
}

void Particles()
{
    
  ImVec2 screen_size = ImVec2(g_GlWidth, g_GlHeight);
    static ImVec2 partile_pos[100];
    static ImVec2 partile_target_pos[100];
    static float partile_speed[100];
    static float partile_radius[100];


    for (int i = 1; i < 50; i++)
    {
        if (partile_pos[i].x == 0 || partile_pos[i].y == 0)
        {
            partile_pos[i].x = rand() % (int)screen_size.x + 1;
            partile_pos[i].y = 15.f;
            partile_speed[i] = 1 + rand() % 25;
            partile_radius[i] = rand() % 4;

            partile_target_pos[i].x = rand() % (int)screen_size.x;
            partile_target_pos[i].y = screen_size.y * 2;
        }

        partile_pos[i] = ImLerp(partile_pos[i], partile_target_pos[i], ImGui::GetIO().DeltaTime * (partile_speed[i] / 60));

        if (partile_pos[i].y > screen_size.y)
        {
            partile_pos[i].x = 0;
            partile_pos[i].y = 0;
        }

        ImGui::GetWindowDrawList()->AddCircleFilled(partile_pos[i], partile_radius[i], ImColor(255,255,255, 255/2));
    }

}

#include "imGui/stb_image.h"
#include "Rishabh.h"
#include "RishabhPapa.h"

struct TextureInfo { ImTextureID textureId; int x; int y; int w; int h; };
static TextureInfo textureInfo;
TextureInfo createTexture(char *ImagePath) {
int w, h, n;
stbi_uc *data = stbi_load(ImagePath, &w, &h, &n, 0);
GLuint texture;
glGenTextures(1, &texture);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if (n == 3) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
} else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
}stbi_image_free(data);
textureInfo.textureId = reinterpret_cast<ImTextureID>((GLuint *) texture);
textureInfo.w = w;
textureInfo.h = h;
return textureInfo;
}TextureInfo CreateTexture(const unsigned char* buf, int len) {
TextureInfo image;
unsigned char* image_data = stbi_load_from_memory(buf, len, &image.w, &image.h, NULL, 0);
if (image_data == NULL) perror("文件不存在"); GLuint image_texture;
glGenTextures(1, &image_texture);
glBindTexture(GL_TEXTURE_2D, image_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //对于非二次方纹理，这在 WebGL 上是必需的
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); //相同的
#if defined(GL_UNPACK_ROW_LENGTH) && !defined(__EMSCRIPTEN__)
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
#endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.w, image.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
stbi_image_free(image_data);
image.textureId = (ImTextureID)image_texture;
return image;
}

TextureInfo Rishabh;
TextureInfo Darkayu;

extern TextureInfo Rishabh;
extern TextureInfo Darkayu;

void InitTexture() {
Rishabh = CreateTexture(Rishabh_data, sizeof(Rishabh_data));
Darkayu = CreateTexture(Darkayu_data, sizeof(Darkayu_data));  
}

static int Tab = 1;

void SetupImgui() {
IMGUI_CHECKVERSION();
InitTexture();
ImGui::CreateContext();
ImGui_ImplAndroid_Init(nullptr);
ImGuiIO& io = ImGui::GetIO();
//ImGuiStyle* style = &ImGui::GetStyle();

static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
ImFontConfig icons_config;
 // ImFontConfig CustomFont;
 // CustomFont.FontDataOwnedByAtlas = false;
icons_config.MergeMode = true;
icons_config.PixelSnapH = true;
icons_config.OversampleH = 2.5;
icons_config.OversampleV = 2.5;
   io.Fonts->AddFontFromMemoryTTF(&BebasNeueRegular_ttf, sizeof BebasNeueRegular_ttf, 34, NULL, io.Fonts->GetGlyphRangesVietnamese());
io.Fonts->AddFontFromMemoryCompressedTTF(font_awesome_data, font_awesome_size, 25.0f, &icons_config, icons_ranges);
ImGui_ImplOpenGL3_Init("#version 300 es");
ImFontConfig font_cfg;
font_cfg.SizePixels = 22.0f;
io.Fonts->AddFontDefault(&font_cfg);

ImGuiStyle *style = &ImGui::GetStyle();
//


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

  //  ImGui::StyleColorsLight();
    ImGui::StyleColorsLight();//   Màu Xanh Nước Biển
ImGui::GetStyle().ScaleAllSizes(3.0f);
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
};
}
// PAID SRC BY @RISHABHMODX
namespace Settings
{
    static int Tab = 1;
}

bool clearMousePos = true;
bool ImGuiOK = false;
bool initImGui = 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();
 ImGuiStyle* style = &ImGui::GetStyle();

style->WindowRounding = 6.0f;
style->FrameRounding  = 4.0f;
style->ChildRounding  = 4.0f;
style->ScrollbarRounding = 3.0f;
style->GrabRounding   = 4.0f;
style->WindowTitleAlign = ImVec2(0.5f, 0.5f);
style->WindowMinSize    = ImVec2(400, 200);
style->FramePadding     = ImVec2(8, 6);
style->Colors[ImGuiCol_Text]                   = ImColor(255, 255, 255, 255);
style->Colors[ImGuiCol_TextDisabled]           = ImColor(255, 255, 255, 255);
style->Colors[ImGuiCol_WindowBg]               = ImColor(35,0,55,200); 
style->Colors[ImGuiCol_ChildBg]                = ImColor(35,0,55,150); 
style->Colors[ImGuiCol_PopupBg]                = ImColor(10, 150, 255, 235); 
style->Colors[ImGuiCol_Border]                 = ImColor(207, 120, 39, 255); 
style->Colors[ImGuiCol_BorderShadow]           = ImColor(0, 0, 0, 0);
style->Colors[ImGuiCol_FrameBg]                = ImColor(55, 55, 55, 255);
style->Colors[ImGuiCol_FrameBgHovered]         = ImColor(55, 55, 55, 255);
style->Colors[ImGuiCol_FrameBgActive]          = ImColor(55, 55, 55, 255);
style->Colors[ImGuiCol_TitleBg]                = ImColor(207, 120, 39, 255); 
style->Colors[ImGuiCol_TitleBgActive]          = ImColor(207, 120, 39, 255); 
style->Colors[ImGuiCol_TitleBgCollapsed]       = ImColor(207, 120, 39, 255); 
style->Colors[ImGuiCol_MenuBarBg]              = ImColor(20, 20, 20, 255);
style->Colors[ImGuiCol_ScrollbarBg]            = ImColor(20, 20, 20, 255);
style->Colors[ImGuiCol_ScrollbarGrab]          = ImColor(80, 80, 80, 255);
style->Colors[ImGuiCol_ScrollbarGrabHovered]   = ImColor(100, 100, 100, 255);
style->Colors[ImGuiCol_ScrollbarGrabActive]    = ImColor(120, 120, 120, 255);
style->Colors[ImGuiCol_CheckMark]              = ImColor(10, 177, 255, 255); 
style->Colors[ImGuiCol_SliderGrab]             = ImColor(207, 120, 39, 255); 
style->Colors[ImGuiCol_SliderGrabActive]       = ImColor(207, 120, 39, 255); 
style->Colors[ImGuiCol_Header]                 = ImColor(40, 40, 40, 255);
style->Colors[ImGuiCol_HeaderHovered]          = ImColor(60, 60, 60, 255);
style->Colors[ImGuiCol_HeaderActive]           = ImColor(80, 80, 80, 255);
style->Colors[ImGuiCol_Tab]                    = ImColor(30, 30, 30, 255);
style->Colors[ImGuiCol_TabHovered]             = ImColor(50, 50, 50, 255);
style->Colors[ImGuiCol_TabActive]              = ImColor(70, 70, 70, 255);
style->Colors[ImGuiCol_TabUnfocused]           = ImColor(25, 25, 25, 255);
style->Colors[ImGuiCol_TabUnfocusedActive]     = ImColor(50, 50, 50, 255);
style->Colors[ImGuiCol_Separator]              = ImColor(70, 70, 70, 255);
style->Colors[ImGuiCol_SeparatorHovered]       = ImColor(255, 0, 0, 180);
style->Colors[ImGuiCol_SeparatorActive]        = ImColor(255, 0, 0, 255);
style->Colors[ImGuiCol_ResizeGrip]             = ImColor(80, 80, 80, 0);
style->Colors[ImGuiCol_ResizeGripHovered]      = ImColor(100, 100, 100, 0);
style->Colors[ImGuiCol_ResizeGripActive]       = ImColor(120, 120, 120, 0);
style->Colors[ImGuiCol_TableHeaderBg]          = ImColor(30, 30, 30, 255);
style->Colors[ImGuiCol_TableBorderStrong]      = ImColor(80, 80, 80, 255);
style->Colors[ImGuiCol_TableBorderLight]       = ImColor(50, 50, 50, 255);
style->Colors[ImGuiCol_TableRowBg]             = ImColor(15, 15, 15, 255);
style->Colors[ImGuiCol_TableRowBgAlt]          = ImColor(20, 20, 20, 255);
style->Colors[ImGuiCol_TextSelectedBg]         = ImColor(255, 0, 0, 100);
style->Colors[ImGuiCol_DragDropTarget]         = ImColor(255, 0, 0, 200);
style->Colors[ImGuiCol_NavHighlight]           = ImColor(255, 0, 0, 200);
style->Colors[ImGuiCol_NavWindowingHighlight]  = ImColor(255, 0, 0, 180);
style->Colors[ImGuiCol_NavWindowingDimBg]      = ImColor(0, 0, 0, 120);
style->Colors[ImGuiCol_ModalWindowDimBg]       = ImColor(0, 0, 0, 150);

   //     style->ScaleAllSizes(std::max(1.0f, density / 150.0f));
        style->ScrollbarSize /= 1;











// PAID SRC BY @RISHABHMODX



    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;
        }
    }
	}
	
	
	

//===========================MADE BY :- @RISHABHMODX============================

ImVec4 btnColor = ImColor(55, 0, 75, 200).Value;
	
static bool loginIndia    = false;
static bool fixCrash      = false;
static bool enableFunc    = false;
static bool enableAim     = false;
static bool enableEsp     = false;
static bool aimbotPlayer  = false;

DrawESP(g_GlWidth, g_GlHeight);
static int glWidth = 1920;  // Default value
static int glHeight = 1080; // Default value

static int mainTab = 0;

static float aimFov = 500.0f;
static float smoothing = 0.10f;
static int headAimLevel = 35;

ImGui::SetNextWindowSize(ImVec2(700, 600), ImGuiCond_Once);
   if (ImGui::Begin(" RISHABH MODS - OB51 ", nullptr, 
    ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoResize)) {
	
// Add this inside your render loop after ImGui::Begin()
ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImVec2 winPos = ImGui::GetWindowPos();
ImVec2 winSize = ImGui::GetWindowSize();

static const int numParticles = 85;
static ImVec2 pos[numParticles];
static ImVec2 vel[numParticles];
static ImVec4 col[numParticles];
static float size[numParticles];
static float sparkle[numParticles];
static bool initialized = false;

if (!initialized)
{
    srand((unsigned)time(0));
    for (int i = 0; i < numParticles; i++)
    {
        pos[i] = ImVec2(
            winPos.x + (float)(rand() % (int)winSize.x),
            winPos.y + (float)(rand() % (int)winSize.y)
        );

        vel[i] = ImVec2(
            ((rand() % 200) - 100) / 200.0f,
            ((rand() % 200) - 100) / 200.0f
        );

        // random festive colors
        float h = (float)(rand() % 360) / 360.0f;
        col[i] = ImColor::HSV(h, 0.8f, 1.0f, 1.0f);
        size[i] = 2.0f + (rand() % 4);
        sparkle[i] = (rand() % 100) / 100.0f;
    }
    initialized = true;
}

float dt = ImGui::GetIO().DeltaTime;

// update + render glowing dots
for (int i = 0; i < numParticles; i++)
{
    pos[i].x += vel[i].x * dt * 40.0f;
    pos[i].y += vel[i].y * dt * 40.0f;

    // keep inside window
    if (pos[i].x < winPos.x) pos[i].x = winPos.x + winSize.x;
    if (pos[i].x > winPos.x + winSize.x) pos[i].x = winPos.x;
    if (pos[i].y < winPos.y) pos[i].y = winPos.y + winSize.y;
    if (pos[i].y > winPos.y + winSize.y) pos[i].y = winPos.y;

    // sparkle pulse animation
    sparkle[i] += dt * ((rand() % 100) / 50.0f);
    float pulse = 0.5f + 0.5f * sinf(sparkle[i]);

    // draw soft glow outer ring
    ImVec4 glow = ImVec4(col[i].x, col[i].y, col[i].z, 0.15f * pulse);
    draw_list->AddCircleFilled(pos[i], size[i] * 3.5f, ImGui::ColorConvertFloat4ToU32(glow));

    // draw main bright center
    ImVec4 bright = ImVec4(col[i].x, col[i].y, col[i].z, 0.9f);
    draw_list->AddCircleFilled(pos[i], size[i], ImGui::ColorConvertFloat4ToU32(bright));
}
		
ImGui::PushStyleColor(ImGuiCol_Button, btnColor);         // Normal
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, btnColor);  // Hovered
ImGui::PushStyleColor(ImGuiCol_ButtonActive, btnColor);   // Active
		
ImGui::BeginChild("RishabhPapa", ImVec2(0, 0), true);
const char* tabs[] = {"AIM", "ESP", "ACCOUNT"};
ImVec2 tabSize(140, 50);
for (int i = 0; i < 3; i++) {
    if (i > 0) ImGui::SameLine();
    if (ImGui::Button(tabs[i], tabSize)) mainTab = i;
    ImGui::PopStyleColor();
}
ImGui::EndChild();

// ==== TAB CONTENT ====
if (mainTab == 0) { 
ImGui::BeginChild("RishabhPapa", ImVec2(0, 0), true);
ImGui::Text("PLAYER AIM - SETTINGS");
ImGui::Separator();
MyCustomCheckbox("ENABLE FUNCTION", &ActiveFeature);
ImGui::Separator();   
MyCustomCheckbox("ENABLE AIMBOT", &Aimbot);
ImGui::Separator();   
MyCustomCheckbox("AIMKILL", &AimKill1);
ImGui::Separator();
ImGui::SliderFloat(OBFUSCATE("AIM FOV"), &Fov_Aim, 0.0f, 3000.0f, "%.0f°", ImGuiSliderFlags_AlwaysClamp | ImGuiSliderFlags_NoInput);
ImGui::SliderFloat(OBFUSCATE("HEAD"), &DistanceTele, 0.0f, 3000.0f, "%.0f°", ImGuiSliderFlags_AlwaysClamp | ImGuiSliderFlags_NoInput);
ImGui::Separator();   
ImGui::EndChild();
} 
else if (mainTab == 1) {
ImGui::BeginChild("RishabhPapa", ImVec2(0, 0), true);
ImGui::Text("PLAYER ESP - SETTINGS");
ImGui::Separator();
MyCustomCheckbox("ESP Player Line", &Enable);
ImGui::Separator();   
MyCustomCheckbox("ESP Player Box", &Config.ESP.Box);
ImGui::Separator();   
MyCustomCheckbox("ESP Player health", &Config.ESP.Health);
ImGui::Separator();   
ImGui::EndChild();
}

else if (mainTab == 2) {
ImGui::BeginChild("RishabhPapa", ImVec2(0, 0), true);
ImGui::Text("MOD SETTINGS INFORMATION");
ImGui::Separator();
ImGui::TextColored(ImColor(207, 120, 39, 255),"DEVELOPER - @RISHABHMODX");
ImGui::Separator();
ImGui::TextColored(ImColor(207, 120, 39, 255),"MOD VERSION - V19");
ImGui::Separator();
ImGui::TextColored(ImColor(207, 120, 39, 255),"EXPIRY - 3 DAYS!");
ImGui::Separator();
ImGui::TextColored(ImColor(207, 120, 39, 255),"OBB CODE - 2019115661");
ImGui::Separator();   
ImGui::EndChild();
}

ImGui::End();
ImGui::PopStyleVar(3);
ImGui::PopStyleColor(4);
}
    // === FRAME END & RENDER ===
    ImGui::EndFrame();
    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

    return old_eglSwapBuffers(dpy, surface);
}

//===========================MADE BY :- @RISHABHMODX============================

typedef unsigned long DWORD;
static uintptr_t libBase;

uintptr_t string2Offset(const char *c) {
    int base = 16;
    // See if this function catches all possibilities.
    // If it doesn't, the function would have to be amended
    // whenever you add a combination of architecture and
    // compiler that is not yet addressed.
    static_assert(sizeof(uintptr_t) == sizeof(unsigned long)
                  || sizeof(uintptr_t) == sizeof(unsigned long long),
                  "Please add string to handle conversion for this architecture.");

    // Now choose the correct function ...
    if (sizeof(uintptr_t) == sizeof(unsigned long)) {
        return strtoul(c, nullptr, base);
    }

    // All other options exhausted, sizeof(uintptr_t) == sizeof(unsigned long long))
    return strtoull(c, nullptr, base);
}

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();
        }
    }
// PAID SRC BY @RISHABHMODX
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;
}

void writeLog(const std::string& logMessage, const std::string& filename) {
    std::ofstream outFile(filename, std::ios::app); // Mở file ở chế độ append (thêm)
    if (outFile.is_open()) {
        outFile << logMessage << std::endl;
        outFile.close();
    } else {
        std::cerr << "Không thể mở file log: " << filename << std::endl;
    }
}

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;
}


// PAID SRC BY @RISHABHMODX

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"); //Varies according to game
        LogShaders();
        Wallhack();
    }
DobbyHook(Il2CppGetMethodOffset(OBFUSCATE("Assembly-CSharp.dll"), OBFUSCATE("COW.GamePlay"), OBFUSCATE("Player"), OBFUSCATE("UpdateBehavior"), 2), (void *) _LateUpdate, (void **) &LateUpdate);

	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));
    
}

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * reserved) {
JNIEnv *env;
vm->GetEnv((void **) &env, JNI_VERSION_1_6); 
return JNI_VERSION_1_6;
}

__attribute__((constructor))
void lib_main()
{
    std::thread thread_hack(hack_thread, get_pid_by_name("com.dts.freefireth"));
    thread_hack.detach();
}
//REGISTER_ZYGISK_MODULE(MyModule)
// PAID SRC BY @RISHABHMODX
