#pragma comment(lib, "dwmapi.lib")
#include <Windows.h>
#include <dxgi.h>
#include <dwmapi.h>
#include <thread>
#include <chrono>
#include <d3d11.h>
#include <wincodec.h>
#include <string>
#include <vector>
#include <algorithm>
#include "Graphics.h"
#include <Globals.hxx>
#include <imgui/misc/imgui_freetype.h>
#include "imgui/imgui_internal.h"
#include "Fonts/Tahoma.h"
#include "Fonts/Tahoma_Bold.h"
#include "../Features/Cheats/Visuals/Visuals.h"
#include <ImGui/addons/colors/colors.h>
#include "Core/Features/Cheats/Aimbot/Silent/Silent.h"

extern HWND g_RobloxWindow;

static void DrawWobblyRect(
    ImDrawList* dl,
    Graphics::WobblyState& W,
    ImU32 fillColor,
    ImU32 borderColor,
    float borderThick = 1.f,
    bool fill = true)
{
    int GW = Graphics::WobblyState::GRID_W;
    int GH = Graphics::WobblyState::GRID_H;
    for (int x = 0; x < GW - 1; x++) {
        for (int y = 0; y < GH - 1; y++) {
            ImVec2 p0 = W.grid[x][y].pos;
            ImVec2 p1 = W.grid[x + 1][y].pos;
            ImVec2 p2 = W.grid[x + 1][y + 1].pos;
            ImVec2 p3 = W.grid[x][y + 1].pos;

            if (fill) {
                dl->AddTriangleFilled(p0, p1, p3, fillColor);
                dl->AddTriangleFilled(p1, p2, p3, fillColor);
            }
        }
    }

    for (int x = 0; x < GW - 1; x++) {
        dl->AddLine(W.grid[x][0].pos, W.grid[x + 1][0].pos, borderColor, borderThick);
    }
    for (int x = 0; x < GW - 1; x++) {
        dl->AddLine(W.grid[x][GH - 1].pos, W.grid[x + 1][GH - 1].pos, borderColor, borderThick);
    }
    for (int y = 0; y < GH - 1; y++) {
        dl->AddLine(W.grid[0][y].pos, W.grid[0][y + 1].pos, borderColor, borderThick);
    }
    for (int y = 0; y < GH - 1; y++) {
        dl->AddLine(W.grid[GW - 1][y].pos, W.grid[GW - 1][y + 1].pos, borderColor, borderThick);
    }
}

extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND Hwnd, UINT Msg, WPARAM WParam, LPARAM LParam);
static LRESULT CALLBACK WndProc(HWND Hwnd, UINT Msg, WPARAM WParam, LPARAM LParam)
{
    if (ImGui_ImplWin32_WndProcHandler(Hwnd, Msg, WParam, LParam)) return true;
    switch (Msg) {
    case WM_SYSCOMMAND: if ((WParam & 0xfff0) == SC_KEYMENU) return 0; break;
    case WM_SYSKEYDOWN: if (WParam == VK_F4) { DestroyWindow(Hwnd); return 0; } break;
    case WM_DESTROY: PostQuitMessage(0); break;
    case WM_CLOSE: return 0;
    }
    return DefWindowProcA(Hwnd, Msg, WParam, LParam);
}

Graphics::Graphics() { Detail = std::make_unique<detail_t>(); }
Graphics::~Graphics() { Destroy_Imgui(); Destroy_Window(); Destroy_Device(); }

bool Graphics::Create_Window()
{
    Detail->WindowClass.cbSize = sizeof(WNDCLASSEX);
    Detail->WindowClass.style = CS_HREDRAW | CS_VREDRAW;
    Detail->WindowClass.lpfnWndProc = WndProc;
    Detail->WindowClass.hInstance = GetModuleHandleA(NULL);
    Detail->WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    Detail->WindowClass.lpszClassName = "FangOverlay";
    RegisterClassExA(&Detail->WindowClass);

    Detail->Window = CreateWindowExA(
        WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_TOOLWINDOW,
        Detail->WindowClass.lpszClassName, "Fang Overlay", WS_POPUP,
        0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
        NULL, NULL, Detail->WindowClass.hInstance, NULL
    );
    if (!Detail->Window) return false;
    SetLayeredWindowAttributes(Detail->Window, RGB(0, 0, 0), 255, LWA_ALPHA);
    MARGINS margins = { -1 };
    DwmExtendFrameIntoClientArea(Detail->Window, &margins);
    ShowWindow(Detail->Window, SW_SHOW);
    UpdateWindow(Detail->Window);
    return true;
}

bool Graphics::Create_Device()
{
    IDXGIFactory1* dxgiFactory = nullptr;
    HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
    if (FAILED(hr)) return false;
    IDXGIAdapter1* dxgiAdapter = nullptr;
    if (dxgiFactory->EnumAdapters1(0, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) { dxgiFactory->Release(); return false; }

    DXGI_SWAP_CHAIN_DESC sd{};
    sd.BufferCount = 2; sd.BufferDesc.Width = 0; sd.BufferDesc.Height = 0;
    sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1;
    sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    sd.OutputWindow = Detail->Window;
    sd.SampleDesc.Count = 1; sd.Windowed = TRUE;
    sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
    sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

    D3D_FEATURE_LEVEL featureLevel;
    const D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0 };
    dxgiFactory->MakeWindowAssociation(Detail->Window, DXGI_MWA_NO_ALT_ENTER);

    hr = D3D11CreateDeviceAndSwapChain(dxgiAdapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, &sd, &Detail->SwapChain, &Detail->Device, &featureLevel, &Detail->DeviceContext);
    dxgiAdapter->Release(); dxgiFactory->Release();
    if (FAILED(hr)) return false;

    ID3D11Texture2D* pBackBuffer;
    Detail->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
    Detail->Device->CreateRenderTargetView(pBackBuffer, nullptr, &Detail->GraphicsTargetView);
    pBackBuffer->Release();
    return true;
}

bool Graphics::Create_Imgui()
{
    using namespace ImGui;
    CreateContext(); StyleColorsDark();
    float MainScale = ImGui_ImplWin32_GetDpiScaleForMonitor(::MonitorFromPoint(POINT{ 0, 0 }, MONITOR_DEFAULTTOPRIMARY));
    ImGuiStyle& Style = ImGui::GetStyle();
    ImGuiIO& IO = ImGui::GetIO(); (void)IO;
    IO.IniFilename = nullptr;
    const unsigned int freetype_flags = ImGuiFreeTypeLoaderFlags_MonoHinting | ImGuiFreeTypeLoaderFlags_Monochrome;
    IO.Fonts->SetFontLoader(ImGuiFreeType::GetFontLoader());
    IO.Fonts->FontLoaderFlags = freetype_flags;

    ImFontConfig font_cfg{};
    font_cfg.PixelSnapH = true; font_cfg.OversampleH = 2; font_cfg.OversampleV = 1; font_cfg.RasterizerMultiply = 1.05f; font_cfg.FontLoaderFlags = freetype_flags;
    ImFontConfig font_configuration = font_cfg; font_configuration.FontDataOwnedByAtlas = false;
    float Verdana_Size = 13.0f * MainScale;

    IO.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(Tahoma), sizeof(Tahoma), Verdana_Size, &font_configuration);
    Tahoma_BoldXP = IO.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(Tahoma_Bold), sizeof(Tahoma_Bold), Verdana_Size, &font_configuration, IO.Fonts->GetGlyphRangesCyrillic());

    if (!ImGui_ImplWin32_Init(Detail->Window)) return false;
    if (!Detail->Device || !Detail->DeviceContext) return false;
    if (!ImGui_ImplDX11_Init(Detail->Device, Detail->DeviceContext)) return false;
    return true;
}

void Graphics::Destroy_Device() { if (Detail->GraphicsTargetView) Detail->GraphicsTargetView->Release(); if (Detail->SwapChain) Detail->SwapChain->Release(); if (Detail->DeviceContext) Detail->DeviceContext->Release(); if (Detail->Device) Detail->Device->Release(); }
void Graphics::Destroy_Window() { DestroyWindow(Detail->Window); UnregisterClassA(Detail->WindowClass.lpszClassName, Detail->WindowClass.hInstance); }
void Graphics::Destroy_Imgui() { ImGui_ImplDX11_Shutdown(); ImGui_ImplWin32_Shutdown(); ImGui::DestroyContext(); }

void Graphics::Start_Render()
{
    MSG Msg;
    while (PeekMessage(&Msg, nullptr, 0, 0, PM_REMOVE)) { TranslateMessage(&Msg); DispatchMessage(&Msg); }
    if (Globals::Settings::Streamproof) SetWindowDisplayAffinity(Detail->Window, WDA_EXCLUDEFROMCAPTURE);
    else SetWindowDisplayAffinity(Detail->Window, WDA_NONE);

    static int last_w = 0, last_h = 0;
    RECT rect;
    HWND roblox_hwnd = FindWindowA(NULL, "Roblox");
    if (roblox_hwnd) {
        GetWindowRect(roblox_hwnd, &rect);
        int width = rect.right - rect.left; int height = rect.bottom - rect.top;
        if (width > 0 && height > 0) {
            if (width != last_w || height != last_h) {
                last_w = width; last_h = height;
                SetWindowPos(Detail->Window, HWND_TOPMOST, rect.left, rect.top, width, height, SWP_NOACTIVATE);
                if (Detail->SwapChain) {
                    if (Detail->GraphicsTargetView) { Detail->GraphicsTargetView->Release(); Detail->GraphicsTargetView = nullptr; }
                    Detail->SwapChain->ResizeBuffers(0, width, height, DXGI_FORMAT_UNKNOWN, 0);
                    ID3D11Texture2D* pBackBuffer;
                    Detail->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
                    Detail->Device->CreateRenderTargetView(pBackBuffer, NULL, &Detail->GraphicsTargetView);
                    pBackBuffer->Release();
                }
                ImGui::GetIO().DisplaySize = ImVec2((float)width, (float)height);
            }
            else SetWindowPos(Detail->Window, HWND_TOPMOST, rect.left, rect.top, width, height, SWP_NOACTIVATE | SWP_NOSIZE);
        }
    }
    ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); ImGui::NewFrame();
    if (GetAsyncKeyState(VK_INSERT) & 1) Running = !Running;
    if (Running) SetWindowLong(Detail->Window, GWL_EXSTYLE, WS_EX_TOOLWINDOW | WS_EX_LAYERED);
    else SetWindowLong(Detail->Window, GWL_EXSTYLE, WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_LAYERED);
}

void Graphics::End_Render()
{
    ImGui::Render();
    float ClearColor[4]{ 0, 0, 0, 0 };
    Detail->DeviceContext->OMSetRenderTargets(1, &Detail->GraphicsTargetView, nullptr);
    Detail->DeviceContext->ClearRenderTargetView(Detail->GraphicsTargetView, ClearColor);
    ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
    if (Globals::Settings::Performance_Mode == 0) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); Detail->SwapChain->Present(0, 0); }
    else if (Globals::Settings::Performance_Mode == 1) Detail->SwapChain->Present(1, 0);
    else Detail->SwapChain->Present(0, 0);
}

static void DrawCursor()
{
    if (!SilentAimInstance.Address) return;
    bool is_visible = Driver->Read<bool>(SilentAimInstance.Address + Offsets::GuiObject::Visible);
    if (!is_visible) return;
    POINT pt; if (!GetCursorPos(&pt)) return;
    bool right_click_held = GetAsyncKeyState(VK_RBUTTON) & 0x8000;
    float gap = right_click_held ? 4.0f : 10.0f;
    ImDrawList* draw = ImGui::GetBackgroundDrawList();
    ImU32 col = IM_COL32(255, 255, 255, 255);
    float dot_size = 4.0f; float line_width = 2.0f; float line_length = 10.0f;
    ImVec2 center = { (float)pt.x, (float)pt.y };
    draw->AddRectFilled({ center.x - dot_size * 0.5f, center.y - dot_size * 0.5f }, { center.x + dot_size * 0.5f, center.y + dot_size * 0.5f }, col, 0.0f);
    draw->AddRectFilled({ center.x - line_width * 0.5f, center.y - gap - line_length }, { center.x + line_width * 0.5f, center.y - gap }, col, 0.0f);
    draw->AddRectFilled({ center.x - line_width * 0.5f, center.y + gap }, { center.x + line_width * 0.5f, center.y + gap + line_length }, col, 0.0f);
    draw->AddRectFilled({ center.x - gap - line_length, center.y - line_width * 0.5f }, { center.x - gap, center.y + line_width * 0.5f }, col, 0.0f);
    draw->AddRectFilled({ center.x + gap, center.y - line_width * 0.5f }, { center.x + gap + line_length, center.y + line_width * 0.5f }, col, 0.0f);
}

void Graphics::Update_Wobbly(ImVec2 WinPos, ImVec2 WinSize) {
    ImGuiIO& IO = ImGui::GetIO();
    float dt = IO.DeltaTime;
    if (dt <= 0.f || dt > 0.05f) dt = 0.016f;
    int GW = WobblyState::GRID_W; int GH = WobblyState::GRID_H;

    if (!Wobbly.Initialized) {
        for (int x = 0; x < GW; x++) {
            for (int y = 0; y < GH; y++) {
                float nx = (float)x / (GW - 1); float ny = (float)y / (GH - 1);
                ImVec2 t = ImVec2(WinPos.x + WinSize.x * nx, WinPos.y + WinSize.y * ny);
                Wobbly.grid[x][y].pos = t; Wobbly.grid[x][y].vel = { 0.f, 0.f }; Wobbly.grid[x][y].target = t;
            }
        }
        Wobbly.LastWindowPos = WinPos; Wobbly.Initialized = true; return;
    }

    if (!Globals::Settings::Wobbly_Enabled || Globals::Settings::Wobbly_Strength <= 0.f) {
        for (int x = 0; x < GW; x++) {
            for (int y = 0; y < GH; y++) {
                float nx = (float)x / (GW - 1); float ny = (float)y / (GH - 1);
                Wobbly.grid[x][y].pos = ImVec2(WinPos.x + WinSize.x * nx, WinPos.y + WinSize.y * ny);
                Wobbly.grid[x][y].vel = { 0.f, 0.f };
            }
        }
        Wobbly.LastWindowPos = WinPos; return;
    }

    // FIX: Увеличенные коэффициенты для быстрой анимации
    float Str = fminf(Globals::Settings::Wobbly_Strength * 0.2f, 2.0f);
    float Speed = fminf(Globals::Settings::Wobbly_Speed * 2.0f, 20.0f);

    float Stiffness = 150.f + Speed * 30.f;
    float Damping = 10.f + Speed * 5.f;

    ImVec2 delta = { WinPos.x - Wobbly.LastWindowPos.x, WinPos.y - Wobbly.LastWindowPos.y };

    // Ограничение дельты
    float maxDelta = 100.f;
    delta.x = fmaxf(fminf(delta.x, maxDelta), -maxDelta);
    delta.y = fmaxf(fminf(delta.y, maxDelta), -maxDelta);

    Wobbly.LastWindowPos = WinPos;

    for (int x = 0; x < GW; x++) {
        for (int y = 0; y < GH; y++) {
            float nx = (float)x / (GW - 1); float ny = (float)y / (GH - 1);
            Wobbly.grid[x][y].target = ImVec2(WinPos.x + WinSize.x * nx, WinPos.y + WinSize.y * ny);
            auto& s = Wobbly.grid[x][y];

            bool isCornerX = (x == 0 || x == GW - 1);
            bool isCornerY = (y == 0 || y == GH - 1);
            float weight = 0.f;

            if (isCornerX && isCornerY) weight = 0.f;
            else if (isCornerX || isCornerY) {
                float ex = isCornerX ? 0.f : (nx < 0.5f ? nx : 1.f - nx);
                float ey = isCornerY ? 0.f : (ny < 0.5f ? ny : 1.f - ny);
                weight = (ex + ey) * 0.8f;
                if (weight > 1.f) weight = 1.f;
            }

            if (weight < 0.001f) { s.pos = s.target; s.vel = { 0.f, 0.f }; continue; }

            float impulse = weight * Str * 8.f;
            s.vel.x -= delta.x * impulse;
            s.vel.y -= delta.y * impulse;

            float fx = -Stiffness * (s.pos.x - s.target.x) - Damping * s.vel.x;
            float fy = -Stiffness * (s.pos.y - s.target.y) - Damping * s.vel.y;

            s.vel.x += fx * dt;
            s.vel.y += fy * dt;

            // Ограничение скорости
            float maxVel = 1000.f * dt;
            s.vel.x = fmaxf(fminf(s.vel.x, maxVel), -maxVel);
            s.vel.y = fmaxf(fminf(s.vel.y, maxVel), -maxVel);

            s.pos.x += s.vel.x * dt;
            s.pos.y += s.vel.y * dt;

            // Жёсткий clamp
            float maxDist = 40.f * Str;
            float dx = s.pos.x - s.target.x;
            float dy = s.pos.y - s.target.y;
            if (dx > maxDist) { s.pos.x = s.target.x + maxDist; s.vel.x *= 0.5f; }
            if (dx < -maxDist) { s.pos.x = s.target.x - maxDist; s.vel.x *= 0.5f; }
            if (dy > maxDist) { s.pos.y = s.target.y + maxDist; s.vel.y *= 0.5f; }
            if (dy < -maxDist) { s.pos.y = s.target.y - maxDist; s.vel.y *= 0.5f; }
        }
    }
}

void Graphics::Render_Menu()
{
    ImGuiStyle& Style = ImGui::GetStyle();
    ImGuiIO& Io = ImGui::GetIO(); (void)Io;
    ImGui::SetNextWindowSize(ImVec2(500, 530), ImGuiCond_Once);
    ImGui::SetNextWindowPos(Io.DisplaySize / 2, ImGuiCond_Once, ImVec2(0.5f, 0.5f));
    ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
    ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);

    bool MainWindow = ImGui::Begin("main", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBackground);
    ImGui::PopStyleVar(2);

    if (MainWindow)
    {
        ImVec2 WinPos = ImGui::GetWindowPos();
        ImVec2 WinSize = ImGui::GetWindowSize();
        ImDrawList* DrawList = ImGui::GetWindowDrawList();

        Update_Wobbly(WinPos, WinSize);

        float Top = ImGui::GetFontSize() + 6.0f * 2.0f + Style.WindowBorderSize - 8.0f;
        float Bottom = Style.WindowBorderSize + Style.WindowPadding.y + 1.0f;

        ImVec2 ContentMin = WinPos + ImVec2(Style.WindowBorderSize * 2.0f + Style.WindowPadding.x, Top + Style.WindowPadding.y + 6.0f);
        ImVec2 ContentMax = WinPos + ImVec2(WinSize.x - Style.WindowBorderSize * 2.0f - Style.WindowPadding.x, WinSize.y - Bottom);

        static int Section = 0;
        const char* TabLabels[] = { "Aimbot", "Visuals", "Rage", "Players", "Explorer", "Settings" };
        const int TabCount = IM_ARRAYSIZE(TabLabels);

        // ============================================
        // 1. РИСУЕМ ФОН (ПЕРВЫМ СЛОЕМ)
        // ============================================
        if (Globals::Settings::Wobbly_Enabled && Globals::Settings::Wobbly_Strength > 0.f)
        {
            int GW = Graphics::WobblyState::GRID_W;
            int GH = Graphics::WobblyState::GRID_H;

            DrawWobblyRect(DrawList, Wobbly, Menu::Bg, 0, 0.f, true);

            float cx0 = (ContentMin.x - WinPos.x) / WinSize.x;
            float cy0 = (ContentMin.y - WinPos.y) / WinSize.y;
            float cx1 = (ContentMax.x - WinPos.x) / WinSize.x;
            float cy1 = (ContentMax.y - WinPos.y) / WinSize.y;

            auto SampleGrid = [&](float nx, float ny) -> ImVec2 {
                float gx = nx * (GW - 1); float gy = ny * (GH - 1);
                int ix = (int)gx; if (ix >= GW - 1) ix = GW - 2;
                int iy = (int)gy; if (iy >= GH - 1) iy = GH - 2;
                float fx = gx - ix; float fy = gy - iy;
                ImVec2 p00 = Wobbly.grid[ix][iy].pos;
                ImVec2 p10 = Wobbly.grid[ix + 1][iy].pos;
                ImVec2 p01 = Wobbly.grid[ix][iy + 1].pos;
                ImVec2 p11 = Wobbly.grid[ix + 1][iy + 1].pos;
                return ImVec2(
                    p00.x * (1 - fx) * (1 - fy) + p10.x * fx * (1 - fy) + p01.x * (1 - fx) * fy + p11.x * fx * fy,
                    p00.y * (1 - fx) * (1 - fy) + p10.y * fx * (1 - fy) + p01.y * (1 - fx) * fy + p11.y * fx * fy
                );
                };

            ImVec2 cTL = SampleGrid(cx0, cy0);
            ImVec2 cTR = SampleGrid(cx1, cy0);
            ImVec2 cBR = SampleGrid(cx1, cy1);
            ImVec2 cBL = SampleGrid(cx0, cy1);

            DrawList->AddQuadFilled(cTL, cTR, cBR, cBL, Menu::InnerBg);
            DrawList->AddQuad(cTL, cTR, cBR, cBL, Menu::Outline, 1.f);

            float inset = 2.f;
            ImVec2 iTL = SampleGrid(cx0 + inset / WinSize.x, cy0 + inset / WinSize.y);
            ImVec2 iTR = SampleGrid(cx1 - inset / WinSize.x, cy0 + inset / WinSize.y);
            ImVec2 iBR = SampleGrid(cx1 - inset / WinSize.x, cy1 - inset / WinSize.y);
            ImVec2 iBL = SampleGrid(cx0 + inset / WinSize.x, cy1 - inset / WinSize.y);
            DrawList->AddQuad(iTL, iTR, iBR, iBL, Menu::DarkAccent, 1.f);

            DrawWobblyRect(DrawList, Wobbly, 0, Menu::Outline, 1.0f, false);

            ImVec2 tl = Wobbly.grid[0][0].pos + ImVec2(2.f, 2.f);
            ImVec2 tr = Wobbly.grid[GW - 1][0].pos + ImVec2(-2.f, 2.f);
            ImVec2 br = Wobbly.grid[GW - 1][GH - 1].pos + ImVec2(-2.f, -2.f);
            ImVec2 bl = Wobbly.grid[0][GH - 1].pos + ImVec2(2.f, -2.f);
            DrawList->AddLine(tl, tr, Menu::Accent, 1.f);
            DrawList->AddLine(tr, br, Menu::Accent, 1.f);
            DrawList->AddLine(br, bl, Menu::Accent, 1.f);
            DrawList->AddLine(bl, tl, Menu::Accent, 1.f);

            ImGui::SetCursorScreenPos(ContentMin);
            ImGui::PushClipRect(ContentMin, ContentMax, true);
        }
        else
        {
            DrawList->AddRectFilled(WinPos, WinPos + WinSize, Menu::Bg);
            DrawList->AddRect(WinPos + ImVec2(1, 1), WinPos + WinSize - ImVec2(1, 1), Menu::Outline);
            DrawList->AddRect(WinPos + ImVec2(2, 2), WinPos + WinSize - ImVec2(2, 2), Menu::Accent);
            DrawList->AddRectFilled(ContentMin, ContentMax, Menu::InnerBg);
            DrawList->AddRect(ContentMin - ImVec2(1, 1), ContentMax + ImVec2(1, 1), Menu::Outline);
            DrawList->AddRect(ContentMin - ImVec2(2, 2), ContentMax + ImVec2(2, 2), Menu::DarkAccent);
            ImGui::SetCursorScreenPos(ContentMin);
            ImGui::PushClipRect(ContentMin, ContentMax, true);
        }

        // ============================================
        // 2. КОНТЕНТ (ВНУТРИ КЛИПА)
        // ============================================
        ImGui::BeginGroup();

        if (Section == 0)
        {
            ImVec2 AvailSize(ContentMax.x - ContentMin.x, ContentMax.y - ContentMin.y);
            float Spacing = Style.ItemSpacing.x;
            float LeftWidth = (AvailSize.x - Spacing) * 0.5f;
            float RightWidth = AvailSize.x - Spacing - LeftWidth;
            float SidePad = 4.0f;
            float HalfHeight = (AvailSize.y - SidePad * 2.0f) * 0.5f;

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);

            if (Menu::BeginChild("Aimbot", ImVec2(LeftWidth - SidePad, HalfHeight)))
            {
                Menu::CheckBox("Enabled", &Globals::Aimbot::Enabled);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Aimbot Key", &Globals::Aimbot::Aimbot_Key, &Globals::Aimbot::Aimbot_Mode);
                Menu::CheckBox("Sticky aim", &Globals::Aimbot::AimbotSticky);
                Menu::CheckBox("Knocked check", &Globals::Aimbot::KnockedCheck);
                Menu::Combo("Aimbot type", &Globals::Aimbot::Aimbot_type, { "Mouse", "Camera" });
                Menu::Combo("HitPart", &Globals::Aimbot::HitPart, { "Head", "Torso", "LowerTorso" });
                if (Globals::Aimbot::Aimbot_type == 0)
                {
                    Menu::SliderFloat("Mouse smoothing X", &Globals::Aimbot::Mouse::Smoothing_X, 0.0f, 12.0f);
                    Menu::SliderFloat("Mouse smoothing Y", &Globals::Aimbot::Mouse::Smoothing_Y, 0.0f, 12.0f);
                    Menu::SliderFloat("Mouse sensitivty", &Globals::Aimbot::Mouse::Mouse_Sensitivty, 0.0f, 5.0f);
                }
                else if (Globals::Aimbot::Aimbot_type == 1)
                {
                    Menu::SliderFloat("Camera smoothing X", &Globals::Aimbot::Camera::Smoothing_X, 0.0f, 12.0f);
                    Menu::SliderFloat("Camera smoothing Y", &Globals::Aimbot::Camera::Smoothing_Y, 0.0f, 12.0f);
                }
                Menu::EndChild();
            }

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);
            float BottomFOV = HalfHeight - 8;
            if (Menu::BeginChild("Aimbot FOV", ImVec2(LeftWidth - SidePad, BottomFOV)))
            {
                if (Globals::Aimbot::Enabled)
                {
                    Menu::CheckBox("Draw", &Globals::Aimbot::DrawFov);
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                    Menu::ColorEdit4("FOV Color", Globals::Aimbot::FovColor);
                    if (Globals::Aimbot::DrawFov)
                    {
                        Menu::SliderFloat("Size", &Globals::Aimbot::FovSize, 1.0f, 500.0f);
                        Menu::CheckBox("Spin", &Globals::Aimbot::FovSpin);
                        if (Globals::Aimbot::FovSpin) Menu::SliderInt("Speed", &Globals::Aimbot::FovSpinSpeed, 1, 5);
                        Menu::CheckBox("Use FOV", &Globals::Aimbot::useFov);
                    }
                }
                Menu::EndChild();
            }

            ImGui::SameLine(0.0f, Spacing);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 248);
            if (Menu::BeginChild("Silent", ImVec2(RightWidth - SidePad, HalfHeight)))
            {
                Menu::CheckBox("Enabled", &Globals::Silent::Enabled);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Silent Key", &Globals::Silent::Silent_Key, &Globals::Silent::Silent_Mode);
                Menu::CheckBox("Sticky aim", &Globals::Silent::StickyAim);
                Menu::CheckBox("Knocked check", &Globals::Silent::KnockedCheck);
                Menu::Combo("Silent Part", &Globals::Silent::AimPart, { "Head", "Torso", "LowerTorso" });
                Menu::EndChild();
            }

            ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 236);
            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad + 240.0f);
            if (Menu::BeginChild("Silent FOV", ImVec2(RightWidth - SidePad, BottomFOV)))
            {
                if (Globals::Silent::Enabled)
                {
                    Menu::CheckBox("Draw", &Globals::Silent::DrawFov);
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                    Menu::ColorEdit4("FOV Color", Globals::Silent::FovColor);
                    Menu::CheckBox("Gun based FOV", &Globals::Silent::GunBasedFov);
                    if (Globals::Silent::GunBasedFov)
                    {
                        Menu::SliderFloat("Default", &Globals::Silent::Fov, 0.0f, 300.0f);
                        Menu::SliderFloat("Double Barrel", &Globals::Silent::FovDoubleBarrel, 0.0f, 300.0f);
                        Menu::SliderFloat("Tactical", &Globals::Silent::FovTacticalShotgun, 0.0f, 300.0f);
                        Menu::SliderFloat("Revolver", &Globals::Silent::FovRevolver, 0.0f, 300.0f);
                    }
                    else Menu::SliderFloat("Static FOV", &Globals::Silent::Fov, 0.0f, 500.0f);
                    Menu::CheckBox("Spin", &Globals::Silent::FovSpin);
                    if (Globals::Silent::FovSpin) Menu::SliderInt("Spin Speed", &Globals::Silent::FovSpinSpeed, 1, 5);
                    Menu::CheckBox("Use FOV", &Globals::Silent::UseFov);
                }
                Menu::EndChild();
            }
        }

        // Section 1 - Visuals
        if (Section == 1)
        {
            ImVec2 AvailSize(ContentMax.x - ContentMin.x, ContentMax.y - ContentMin.y);
            float Spacing = Style.ItemSpacing.x;
            float LeftWidth = (AvailSize.x - Spacing) * 0.5f;
            float RightWidth = AvailSize.x - Spacing - LeftWidth;
            float SidePad = 4.0f;
            float HalfHeight = (AvailSize.y - SidePad * 2.0f) * 0.5f;

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);

            if (Menu::BeginChild("Visuals", ImVec2(LeftWidth - SidePad, HalfHeight)))
            {
                Menu::CheckBox("Enabled", &Globals::Visuals::Enabled);
                Menu::CheckBox("Box", &Globals::Visuals::Box);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Box Color", Globals::Visuals::Colors::Box);
                if (Globals::Visuals::Box)
                {
                    Menu::CheckBox("Box Fill", &Globals::Visuals::Box_Fill);
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                    Menu::ColorEdit4("Box Fill Top", Globals::Visuals::Colors::BoxFill_Top);
                    if (Globals::Visuals::Box_Fill_Gradient)
                    {
                        ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 24);
                        Menu::ColorEdit4("Box Fill Bottom", Globals::Visuals::Colors::BoxFill_Bottom);
                    }
                }
                Menu::CheckBox("Healthbar", &Globals::Visuals::Healthbar);
                if (Globals::Visuals::Healthbar_Type == 0)
                {
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                    Menu::ColorEdit4("Healthbar Color", Globals::Visuals::Colors::Healthbar);
                }
                else if (Globals::Visuals::Healthbar_Type == 1)
                {
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                    Menu::ColorEdit4("Healthbar Top", Globals::Visuals::Colors::Healthbar_Top);
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 24);
                    Menu::ColorEdit4("Healthbar Middle", Globals::Visuals::Colors::Healthbar_Middle);
                    ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 51);
                    Menu::ColorEdit4("Healthbar Bottom", Globals::Visuals::Colors::Healthbar_Bottom);
                }
                Menu::CheckBox("Health", &Globals::Visuals::Health);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Health Color", Globals::Visuals::Colors::Health);
                Menu::CheckBox("Name", &Globals::Visuals::Name);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Name Color", Globals::Visuals::Colors::Name);
                Menu::CheckBox("Distance", &Globals::Visuals::Distance);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Distance Color", Globals::Visuals::Colors::Distance);
                Menu::CheckBox("Rig Type", &Globals::Visuals::Rig_Type);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Rig Type Color", Globals::Visuals::Colors::Rig_Type);
                Menu::CheckBox("Tool", &Globals::Visuals::Tool);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Tool Color", Globals::Visuals::Colors::Tool);
                Menu::CheckBox("Skeleton", &Globals::Visuals::Skeleton);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Skeleton Color", Globals::Visuals::Colors::Skeleton);
                Menu::CheckBox("Chams", &Globals::Visuals::Chams);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Chams Color", Globals::Visuals::Colors::Chams);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 24);
                Menu::ColorEdit4("Chams Outline", Globals::Visuals::Colors::ChamsOutline);
                Menu::EndChild();
            }

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);
            float Bottom = HalfHeight - 8;
            if (Menu::BeginChild("World", ImVec2(LeftWidth - SidePad, Bottom)))
            {
                Menu::CheckBox("Skybox Changer", &Globals::World::Skybox);
                if (Globals::World::Skybox)
                {
                    Menu::Combo("Skybox Type", &Globals::World::Skybox_Type, { "Fang.wtf", "Space", "Pink Sky", "Minecraft", "Night Cloudy", "Sparkling Night", "Winterness", "Dark Crimson", "Nebula", "Tropical", "Green Sky" });
                    Menu::CheckBox("Skybox Rotation", &Globals::World::Rotate);
                    if (Globals::World::Rotate) Menu::SliderFloat("Rotation Speed", &Globals::World::Skybox_Rotate_Speed, 0.0f, 5.0f);
                }
                Menu::CheckBox("Atmosphere", &Globals::World::Ambience);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Atmosphere Color", Globals::World::Colors::Ambience);
                Menu::CheckBox("Fog", &Globals::World::Fog);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Fog Color", Globals::World::Colors::Fog);
                if (Globals::World::Fog) Menu::SliderFloat("Fog Distance", &Globals::World::Fog_Distance, 0.0f, 1000.0f);
                Menu::CheckBox("Brightness", &Globals::World::Brightness);
                if (Globals::World::Brightness) Menu::SliderFloat("Brightness Value", &Globals::World::BrightnessI, 0.0f, 10.0f);
                Menu::CheckBox("Exposure", &Globals::World::Exposure);
                if (Globals::World::Exposure) Menu::SliderFloat("Exposure Value", &Globals::World::ExposureI, -3.0f, 3.0f);
                Menu::CheckBox("FOV", &Globals::World::FOV);
                if (Globals::World::FOV) Menu::SliderFloat("FOV Value", &Globals::World::FOV_Distance, 70.0f, 120.0f);
                Menu::EndChild();
            }

            ImGui::SameLine(0.0f, Spacing);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() - 248);
            if (Menu::BeginChild("Options", ImVec2(RightWidth - SidePad, AvailSize.y - SidePad * 2.0f)))
            {
                Menu::CheckBox("Exclude Client", &Globals::Settings::Client_Check);
                Menu::CheckBox("Exclude Team", &Globals::Settings::Team_Check);
                Menu::SliderFloat("Render Distance", &Globals::Visuals::Render_Distance, 0.0f, 500.0f);
                if (Globals::Visuals::Healthbar)
                {
                    Menu::Combo("Healthbar Style", &Globals::Visuals::Healthbar_Type, { "Static", "Gradient" });
                    Menu::SliderInt("Healthbar Thickness", &Globals::Visuals::Thickness, 1, 5);
                }
                if (Globals::Visuals::Box)
                {
                    Menu::Combo("Box Style", &Globals::Visuals::Box_Type, { "Bounding", "Corner" });
                }
                if (Globals::Visuals::Box_Fill)
                {
                    Menu::CheckBox("Fill Gradient", &Globals::Visuals::Box_Fill_Gradient);
                    if (Globals::Visuals::Box_Fill_Gradient)
                    {
                        Menu::CheckBox("Fill Rotation", &Globals::Visuals::Box_Fill_Gradient_Rotate);
                        if (Globals::Visuals::Box_Fill_Gradient_Rotate)
                        {
                            Menu::Combo("Rotation Type", &Globals::Visuals::Box_Fill_Type, { "Side", "Bottom", "Spin" });
                            Menu::SliderInt("Rotation Speed", &Globals::Visuals::BoxFillSpeed, 1, 5);
                        }
                    }
                }
                if (Globals::Visuals::Name)
                {
                    Menu::Combo("Name Display", &Globals::Visuals::Name_Type, { "Name", "Display Name", "Name & Display Name" });
                }
                if (Globals::Visuals::Chams)
                {
                    Menu::CheckBox("Chams Fade", &Globals::Visuals::ChamsFade);
                    if (Globals::Visuals::ChamsFade) Menu::SliderInt("Fade Speed", &Globals::Visuals::ChamsFadeSpeed, 1, 5);
                }
                Menu::EndChild();
            }
        }

        // Section 2 - Misc
        if (Section == 2)
        {
            ImVec2 AvailSize(ContentMax.x - ContentMin.x, ContentMax.y - ContentMin.y);
            float Spacing = Style.ItemSpacing.x;
            float LeftWidth = (AvailSize.x - Spacing) * 0.5f;
            float RightWidth = AvailSize.x - Spacing - LeftWidth;
            float SidePad = 4.0f;
            float HalfHeight = (AvailSize.y - SidePad * 2.0f) * 0.5f;

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);

            if (Menu::BeginChild("other shit", ImVec2(LeftWidth - SidePad, HalfHeight)))
            {
                Menu::CheckBox("Custom FireRate", &Globals::Misc::firerate);
                Menu::SliderFloat("Rate", &Globals::Misc::fireratevalue, 0.01f, 1.0f);
                ImGui::Separator();
                Menu::CheckBox("Enable Fly", &Globals::Misc::Fly);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Fly Key", &Globals::Misc::Fly_Key, &Globals::Misc::Fly_Mode);
                Menu::SliderFloat("Fly Speed", &Globals::Misc::Fly_Speed, 1.0f, 150.0f, "%.1f");
                Menu::CheckBox("Noclip", &Globals::Misc::Noclip);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Noclip Key", &Globals::Misc::Noclip_Key, &Globals::Misc::Noclip_Mode);
                Menu::CheckBox("Desync", &Globals::Misc::Desync);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Desync Key", &Globals::Misc::Desync_Key, &Globals::Misc::Desync_Mode);
                Menu::CheckBox("Ghost Chams", &Globals::Misc::DesyncChams);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                Menu::ColorEdit4("Ghost Color", Globals::Misc::DesyncChamsColor);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() - 24.0f);
                Menu::ColorEdit4("Ghost Outline", Globals::Misc::DesyncChamsOutline);
                Menu::CheckBox("Hitbox Expander", &Globals::Hitbox::Enabled);
                ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x + 12.0f);
                Menu::KeyBindEx("Hitbox Key", &Globals::Hitbox::Hitbox_Key, &Globals::Hitbox::Hitbox_Mode);
                if (Globals::Hitbox::Enabled)
                {
                    Menu::SliderFloat("Hitbox Size", &Globals::Hitbox::Size, 1.0f, 20.0f, "%.1f");
                    Menu::CheckBox("Head Only", &Globals::Hitbox::HeadOnly);
                    Menu::CheckBox("Draw Hitbox", &Globals::Hitbox::DrawHitbox);
                    if (Globals::Hitbox::DrawHitbox)
                    {
                        ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                        Menu::ColorEdit4("Box Color", Globals::Hitbox::HitboxColor);
                        Menu::CheckBox("Fill Hitbox", &Globals::Hitbox::FillHitbox);
                        if (Globals::Hitbox::FillHitbox)
                        {
                            ImGui::SameLine(ImGui::GetContentRegionAvail().x - Menu::GetColorPickerWidth() + Style.ChildPadding.x - 1.0f);
                            Menu::ColorEdit4("Fill Color", Globals::Hitbox::HitboxFillColor);
                        }
                        Menu::SliderFloat("Thickness", &Globals::Hitbox::HitboxThickness, 0.5f, 5.0f, "%.1f");
                    }
                }
                Menu::EndChild();
            }
        }

        if (Section == 3) {}
        if (Section == 4) {}

        // Section 5 - Settings
        if (Section == 5)
        {
            ImVec2 AvailSize(ContentMax.x - ContentMin.x, ContentMax.y - ContentMin.y);
            float Spacing = Style.ItemSpacing.x;
            float LeftWidth = (AvailSize.x - Spacing) * 0.5f;
            float RightWidth = AvailSize.x - Spacing - LeftWidth;
            float SidePad = 4.0f;
            float HalfHeight = (AvailSize.y - SidePad * 2.0f) * 0.5f;

            ImGui::SetCursorPosX(ImGui::GetCursorPosX() + SidePad);
            ImGui::SetCursorPosY(ImGui::GetCursorPosY() + SidePad);

            if (Menu::BeginChild("Settings", ImVec2(RightWidth - SidePad, HalfHeight)))
            {
                Menu::CheckBox("Streamproof", &Globals::Settings::Streamproof);
                Menu::Combo("Performance Type", &Globals::Settings::Performance_Mode, { "Low", "Medium", "High" });
                Menu::CheckBox("Wobbly Animation", &Globals::Settings::Wobbly_Enabled);
                if (Globals::Settings::Wobbly_Enabled)
                {
                    Menu::SliderFloat("Wobbly Strength", &Globals::Settings::Wobbly_Strength, 0.0f, 10.0f, "%.1f");
                    Menu::SliderFloat("Wobbly Speed", &Globals::Settings::Wobbly_Speed, 1.0f, 10.0f, "%.1f");
                }
                Menu::EndChild();
            }
        }

        ImGui::EndGroup();
        ImGui::PopClipRect();

        // ============================================
        // 3. ЗАГОЛОВОК И ТАБЫ (ПОСЛЕДНИМ СЛОЕМ - ПОВЕРХ ВСЕГО!)
        // ============================================
        float TextX = WinPos.x + Style.WindowBorderSize + 8.0f;
        float TextY = WinPos.y + (Top - ImGui::CalcTextSize("Fang.wtf").y) * 0.5f + 8.0f;
        ImVec2 TextPos(TextX, TextY);
        Menu::DrawLabelShadow(DrawList, TextPos, Menu::Accent, "Fang.");
        TextPos.x += ImGui::CalcTextSize("Fang.").x;
        Menu::DrawLabelShadow(DrawList, TextPos, Menu::Text, "wtf");
        Menu::Tabs(DrawList, WinPos, TextY, Section, TabLabels, TabCount, 10.0f, 8.0f);
    }
    ImGui::End();
}
void Graphics::Render_Visuals()
{
    DrawCursor();
    Visuals::RunService();
    if (Globals::Misc::Desync && Globals::Misc::desync_active && Globals::Misc::DesyncChams)
    {
        SDK::VisualEngine Ve(Globals::VisualEngine.Address);
        SDK::Vector3 pos = Globals::Misc::desync_activation_pos;
        float w = 2.0f; float h = 3.0f; float d = 1.0f;
        HWND hwnd = FindWindowA(0, "Roblox");
        POINT offset = { 0, 0 }; RECT ClientRect = { 0, 0, 0, 0 };
        if (hwnd) { ClientToScreen(hwnd, &offset); GetClientRect(hwnd, &ClientRect); }
        auto v1 = Ve.World_To_Screen({ pos.x - w, pos.y + h, pos.z - d }); ImVec2 s1(v1.x + offset.x, v1.y + offset.y);
        auto v2 = Ve.World_To_Screen({ pos.x + w, pos.y + h, pos.z - d }); ImVec2 s2(v2.x + offset.x, v2.y + offset.y);
        auto v3 = Ve.World_To_Screen({ pos.x + w, pos.y + h, pos.z + d }); ImVec2 s3(v3.x + offset.x, v3.y + offset.y);
        auto v4 = Ve.World_To_Screen({ pos.x - w, pos.y + h, pos.z + d }); ImVec2 s4(v4.x + offset.x, v4.y + offset.y);
        auto v5 = Ve.World_To_Screen({ pos.x - w, pos.y - h, pos.z - d }); ImVec2 s5(v5.x + offset.x, v5.y + offset.y);
        auto v6 = Ve.World_To_Screen({ pos.x + w, pos.y - h, pos.z - d }); ImVec2 s6(v6.x + offset.x, v6.y + offset.y);
        auto v7 = Ve.World_To_Screen({ pos.x + w, pos.y - h, pos.z + d }); ImVec2 s7(v7.x + offset.x, v7.y + offset.y);
        auto v8 = Ve.World_To_Screen({ pos.x - w, pos.y - h, pos.z + d }); ImVec2 s8(v8.x + offset.x, v8.y + offset.y);
        auto vc = Ve.World_To_Screen(pos); ImVec2 center(vc.x + offset.x, vc.y + offset.y);
        if (vc.x > offset.x && vc.y > offset.y && vc.x < (offset.x + ClientRect.right) && vc.y < (offset.y + ClientRect.bottom))
        {
            ImDrawList* DrawList = ImGui::GetBackgroundDrawList();
            ImU32 FillColor = ImGui::ColorConvertFloat4ToU32(*(ImVec4*)Globals::Misc::DesyncChamsColor);
            ImU32 OutlineColor = ImGui::ColorConvertFloat4ToU32(*(ImVec4*)Globals::Misc::DesyncChamsOutline);
            DrawList->AddQuadFilled(s1, s2, s6, s5, FillColor); DrawList->AddQuadFilled(s2, s3, s7, s6, FillColor);
            DrawList->AddQuadFilled(s3, s4, s8, s7, FillColor); DrawList->AddQuadFilled(s4, s1, s5, s8, FillColor);
            DrawList->AddQuadFilled(s1, s2, s3, s4, FillColor); DrawList->AddQuadFilled(s5, s6, s7, s8, FillColor);
            float t = 1.5f;
            DrawList->AddLine(s1, s2, OutlineColor, t); DrawList->AddLine(s2, s3, OutlineColor, t);
            DrawList->AddLine(s3, s4, OutlineColor, t); DrawList->AddLine(s4, s1, OutlineColor, t);
            DrawList->AddLine(s5, s6, OutlineColor, t); DrawList->AddLine(s6, s7, OutlineColor, t);
            DrawList->AddLine(s7, s8, OutlineColor, t); DrawList->AddLine(s8, s5, OutlineColor, t);
            DrawList->AddLine(s1, s5, OutlineColor, t); DrawList->AddLine(s2, s6, OutlineColor, t);
            DrawList->AddLine(s3, s7, OutlineColor, t); DrawList->AddLine(s4, s8, OutlineColor, t);
            const char* Text = "DESYNC";
            ImGui::PushFont(Tahoma_BoldXP);
            ImVec2 TextSize = ImGui::CalcTextSize(Text);
            float highestY = min(min(s1.y, s2.y), min(s3.y, s4.y));
            ImVec2 TextPos = ImVec2(center.x - (TextSize.x / 2.0f), highestY - TextSize.y - 4.0f);
            ImU32 BlackStroke = IM_COL32(0, 0, 0, 255);
            DrawList->AddText(TextPos + ImVec2(1, 0), BlackStroke, Text); DrawList->AddText(TextPos + ImVec2(-1, 0), BlackStroke, Text);
            DrawList->AddText(TextPos + ImVec2(0, 1), BlackStroke, Text); DrawList->AddText(TextPos + ImVec2(0, -1), BlackStroke, Text);
            DrawList->AddText(TextPos + ImVec2(1, 1), BlackStroke, Text); DrawList->AddText(TextPos + ImVec2(-1, -1), BlackStroke, Text);
            DrawList->AddText(TextPos + ImVec2(1, -1), BlackStroke, Text); DrawList->AddText(TextPos + ImVec2(-1, 1), BlackStroke, Text);
            DrawList->AddText(TextPos, OutlineColor, Text);
            ImGui::PopFont();
        }
    }
}