Загрузка данных


local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Stats = game:GetService("Stats")
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")
local TextService = game:GetService("TextService")
local LocalPlayer = Players.LocalPlayer
local LP = LocalPlayer
local PG = LP:WaitForChild("PlayerGui", 5)

-- Персонализированная система UID
local uidFile = "Plague_UID_" .. tostring(LP.UserId) .. ".txt"
local globalCounterFile = "Plague_Global_UID_Counter.txt"
local userUID = 1

pcall(function()
    if isfile and isfile(uidFile) then
        userUID = tonumber(readfile(uidFile)) or 1
    else
        local currentGlobal = 1
        if isfile and isfile(globalCounterFile) then
            currentGlobal = tonumber(readfile(globalCounterFile)) or 1
        end
        userUID = currentGlobal + 1
        if writefile then
            writefile(globalCounterFile, tostring(userUID))
            writefile(uidFile, tostring(userUID))
        end
    end
end)

local ui = {}

local function create(class, props)
    local instance = Instance.new(class)
    for prop, value in pairs(props) do
        instance[prop] = value
    end
    return instance
end

function ui:Window(options)
    options = options or {}
    local window = { title = options.title or "UI Window", size = options.size or Vector2.new(555, 475), tabs = {} }

    local screenGui = create("ScreenGui", {
        Name = "PlagueUI", Parent = game:GetService("CoreGui"),
        ZIndexBehavior = Enum.ZIndexBehavior.Sibling, IgnoreGuiInset = true
    })

    local mainFrame = create("Frame", {
        Name = "Main", Parent = screenGui, BackgroundColor3 = Color3.fromRGB(21, 21, 21),
        BorderMode = Enum.BorderMode.Inset, Size = UDim2.new(0, window.size.X, 0, window.size.Y),
        Position = UDim2.new(0.5, -window.size.X/2, 0.5, -window.size.Y/2), BorderColor3 = Color3.fromRGB(29, 29, 29)
    })
    create("UIStroke", { Name = "MainOutline", Parent = mainFrame, ApplyStrokeMode = Enum.ApplyStrokeMode.Border, LineJoinMode = Enum.LineJoinMode.Miter })

    local holder = create("Frame", {
        Name = "Holder", Parent = mainFrame, BorderSizePixel = 0, BackgroundColor3 = Color3.fromRGB(14, 14, 14),
        Size = UDim2.new(1, 0, 1, -48), Position = UDim2.new(0, 0, 0, 24), BorderColor3 = Color3.fromRGB(0, 0, 0)
    })
    create("Frame", { Name = "TopAccentLine", Parent = holder, BorderSizePixel = 0, BackgroundColor3 = Color3.fromRGB(91, 134, 198), Size = UDim2.new(1, 0, 0, 1), Position = UDim2.new(0, 0, 0, -1) })
    create("Frame", { Name = "BottomAccentLine", Parent = holder, BorderSizePixel = 0, BackgroundColor3 = Color3.fromRGB(91, 134, 198), Size = UDim2.new(1, 0, 0, 1), Position = UDim2.new(0, 0, 1, 0) })

    local tabsContainer = create("Frame", { Name = "Tabs", Parent = mainFrame, BorderSizePixel = 0, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 24) })
    create("UIPadding", { Name = "TabsPadding", Parent = tabsContainer, PaddingLeft = UDim.new(0, 5), PaddingBottom = UDim.new(0, 3) })
    create("UIListLayout", { Name = "TabsLayout", Parent = tabsContainer, Padding = UDim.new(0, 9), SortOrder = Enum.SortOrder.LayoutOrder, FillDirection = Enum.FillDirection.Horizontal })

    local titleText = create("TextLabel", {
        Name = "TitleText", Parent = mainFrame, BorderSizePixel = 0, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Left,
        BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 24), Position = UDim2.new(0, 0, 1, -24), Text = window.title,
        FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = Color3.fromRGB(255, 255, 255)
    })
    create("UIPadding", { Name = "TitleTextPadding", Parent = titleText, PaddingLeft = UDim.new(0, 5) })

    local welcomeText = create("TextLabel", {
        Name = "WelcomeText", Parent = mainFrame, BorderSizePixel = 0, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Right,
        BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 24), Text = "Plague Cheat, UID " .. tostring(userUID),
        FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = Color3.fromRGB(255, 255, 255)
    })
    create("UIPadding", { Name = "WelcomeTextPadding", Parent = welcomeText, PaddingRight = UDim.new(0, 150), PaddingBottom = UDim.new(0, 1) })

    local expiresText = create("TextLabel", {
        Name = "ExpiresText", Parent = mainFrame, BorderSizePixel = 0, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Right,
        BackgroundTransparency = 1, Size = UDim2.new(0, 130, 0, 24), Text = "expires: never",
        FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = Color3.fromRGB(160, 160, 160),
        Position = UDim2.new(1, -135, 1, -24)
    })

    local dragData = { dragging = false, dragStart = Vector2.new(0, 0), startPos = UDim2.new(0, 0, 0, 0) }
    local resizeData = { resizing = false, resizeStart = Vector2.new(0,0), startSize = UDim2.new(0, 0, 0, 0) }
    local resizeHandle = create("Frame", { Size = UDim2.new(0, 25, 0, 25), Position = UDim2.new(1, -25, 1, -25), BackgroundTransparency = 1, Parent = mainFrame })
    
    resizeHandle.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 then
            resizeData.resizing = true; dragData.dragging = false; resizeData.resizeStart = input.Position; resizeData.startSize = mainFrame.Size; dragData.startPos = mainFrame.Position
        end
    end)
    mainFrame.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1 and not resizeData.resizing and input.Position.X < (mainFrame.AbsolutePosition.X + mainFrame.AbsoluteSize.X - 25) and input.Position.Y < (mainFrame.AbsolutePosition.Y + mainFrame.AbsoluteSize.Y - 25) then
            dragData.dragging = true; dragData.dragStart = input.Position; dragData.startPos = mainFrame.Position
        end
    end)
    UserInputService.InputChanged:Connect(function(input)
        if resizeData.resizing and input.UserInputType == Enum.UserInputType.MouseMovement then
            local delta = input.Position - resizeData.resizeStart
            mainFrame.Size = UDim2.new(0, math.max(400, resizeData.startSize.X.Offset + delta.X), 0, math.max(300, resizeData.startSize.Y.Offset + delta.Y))
            mainFrame.Position = dragData.startPos
        elseif dragData.dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
            local delta = input.Position - dragData.dragStart
            mainFrame.Position = UDim2.new(dragData.startPos.X.Scale, dragData.startPos.X.Offset + delta.X, dragData.startPos.Y.Scale, dragData.startPos.Y.Offset + delta.Y)
        end
    end)
    UserInputService.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.MouseButton1 then dragData.dragging = false; resizeData.resizing = false end end)

    function window:Tab(name)
        local tab = { name = name, sections = {}, active = false }
        local tabButton = create("TextButton", {
            Name = "TabButton", Parent = tabsContainer, BorderSizePixel = 0, TextSize = 12,
            TextColor3 = Color3.fromRGB(200, 200, 200), BackgroundTransparency = 1, AutomaticSize = Enum.AutomaticSize.X,
            Size = UDim2.new(0, 0, 1, 0), Text = name, FontFace = Font.new("rbxasset://fonts/families/Zekton.json")
        })
        tab.content = create("Frame", { Name = name .. "Content", Parent = holder, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 1, 0), Visible = false })

        tabButton.MouseButton1Click:Connect(function()
            for _, otherTab in pairs(window.tabs) do
                otherTab.active = false; otherTab.content.Visible = false; otherTab.tabButton.TextColor3 = Color3.fromRGB(200, 200, 200)
            end
            tab.active = true; tab.content.Visible = true; tabButton.TextColor3 = Color3.fromRGB(255, 255, 255)
        end)

        if #window.tabs == 0 then tab.active = true; tab.content.Visible = true; tabButton.TextColor3 = Color3.fromRGB(255, 255, 255) end
        tab.tabButton = tabButton; window.tabs[#window.tabs + 1] = tab

        -- Внутренняя функция для сборки элементов в секцию
        local function populateSection(section, sectionContent)
            function section:Toggle(options)
                options = options or {}
                local toggle = { title = options.title or "Toggle", default = options.default or false, callback = options.callback or function() end, state = options.default or false }
                local toggleButton = create("TextButton", { Name = "ToggleButton", Parent = sectionContent, BorderSizePixel = 0, TextSize = 14, AutoButtonColor = false, TextColor3 = Color3.fromRGB(0, 0, 0), BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 10), Text = "", ZIndex = 15 })
                local toggleIndicator = create("Frame", { Name = "Toggle", Parent = toggleButton, BackgroundColor3 = Color3.fromRGB(18, 18, 18), Size = UDim2.new(0, 10, 0, 10), Position = UDim2.new(0, 14, 0, 3), BorderColor3 = Color3.fromRGB(29, 29, 29) })
                local toggleAccent = create("Frame", { Name = "ToggleAccent", Parent = toggleIndicator, BorderSizePixel = 0, BackgroundColor3 = Color3.fromRGB(91, 134, 198), Size = UDim2.new(1, 0, 1, 0), Visible = toggle.state })
                create("UIGradient", { Name = "ToggleAccentGradient", Parent = toggleAccent, Rotation = -90, Color = ColorSequence.new{ColorSequenceKeypoint.new(0, Color3.fromRGB(200, 192, 205)), ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 255, 255))} })
                local titleLabel = create("TextLabel", { Name = "Title", Parent = toggleButton, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Left, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 1, 0), Position = UDim2.new(0, 31, 0, 2), Text = toggle.title, FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = toggle.state and Color3.fromRGB(255, 255, 255) or Color3.fromRGB(200, 200, 200) })

                toggleButton.MouseButton1Click:Connect(function()
                    toggle.state = not toggle.state; toggleAccent.Visible = toggle.state; titleLabel.TextColor3 = toggle.state and Color3.fromRGB(255, 255, 255) or Color3.fromRGB(200, 200, 200); toggle.callback(toggle.state)
                end)
                function toggle:Set(state) toggle.state = state; toggleAccent.Visible = state; titleLabel.TextColor3 = state and Color3.fromRGB(255, 255, 255) or Color3.fromRGB(200, 200, 200); toggle.callback(state) end
                function toggle:Get() return toggle.state end
                return toggle
            end

            function section:Button(options)
                options = options or {}
                local button = { title = options.title or "Button", callback = options.callback or function() end }
                local buttonFrame = create("Frame", { Name = "Button", Parent = sectionContent, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 22) })
                local buttonElement = create("TextButton", { Name = "Button", Parent = buttonFrame, TextSize = 12, TextColor3 = Color3.fromRGB(200, 200, 200), BackgroundColor3 = Color3.fromRGB(19, 19, 19), FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), Size = UDim2.new(1, -28, 0, 18), BorderColor3 = Color3.fromRGB(30, 30, 30), Position = UDim2.new(0, 14, 0, 2), Text = button.title })
                buttonElement.MouseButton1Click:Connect(function() button.callback() end)
                buttonElement.MouseEnter:Connect(function() buttonElement.TextColor3 = Color3.fromRGB(255, 255, 255) end)
                buttonElement.MouseLeave:Connect(function() buttonElement.TextColor3 = Color3.fromRGB(200, 200, 200) end)
                return button
            end

            function section:TextBox(options)
                options = options or {}
                local textbox = { placeholder = options.placeholder or "Enter text...", callback = options.callback or function() end, default = options.default or "" }
                local textboxFrame = create("Frame", { Name = "TextBox", Parent = sectionContent, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 24) })
                local textboxElement = create("TextBox", { Name = "TextBox", Parent = textboxFrame, TextSize = 12, TextColor3 = Color3.fromRGB(200, 200, 200), PlaceholderColor3 = Color3.fromRGB(130, 130, 130), BackgroundColor3 = Color3.fromRGB(19, 19, 19), FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), Size = UDim2.new(1, -28, 0, 18), Position = UDim2.new(0, 14, 0, 2), BorderColor3 = Color3.fromRGB(30, 30, 30), PlaceholderText = textbox.placeholder, Text = textbox.default, ClearTextOnFocus = false })
                textboxElement.FocusLost:Connect(function(enterPressed) textbox.callback(textboxElement.Text) end)
                function textbox:Set(text) textboxElement.Text = text end
                function textbox:Get() return textboxElement.Text end
                return textbox
            end

            function section:Dropdown(options)
                options = options or {}
                local dropdown = { title = options.title or "Dropdown", options = options.options or {"Option 1"}, default = options.default or options.options[1], callback = options.callback or function() end, open = false }
                local dropdownFrame = create("Frame", { Name = "Dropdown", Parent = sectionContent, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 35), ZIndex = 3 })
                create("TextLabel", { Name = "Title", Parent = dropdownFrame, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Left, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 10), Position = UDim2.new(0, 13, 0, 4), Text = dropdown.title, FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = Color3.fromRGB(255, 255, 255), ZIndex = 3 })
                local dropdownButton = create("TextButton", { Name = "Dropdown", Parent = dropdownFrame, AutoButtonColor = false, BackgroundColor3 = Color3.fromRGB(19, 19, 19), Size = UDim2.new(1, -28, 0, 18), Position = UDim2.new(0, 14, 0, 20), BorderColor3 = Color3.fromRGB(30, 30, 30), Text = "" })
                local valueLabel = create("TextLabel", { Name = "Value", Parent = dropdownButton, BorderSizePixel = 0, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Left, BackgroundTransparency = 1, Size = UDim2.new(1, -10, 1, 0), Position = UDim2.new(0, 2, 0, 0), Text = dropdown.default, FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = Color3.fromRGB(200, 200, 200) })
                local iconLabel = create("TextLabel", { Name = "Icon", Parent = dropdownButton, BorderSizePixel = 0, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Right, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 1, 0), Position = UDim2.new(0, -4, 0, 0), Text = "-", FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = Color3.fromRGB(200, 200, 200) })
                local dropdownContent = create("Frame", { Name = "DropdownContent", Parent = dropdownButton, Visible = false, BackgroundColor3 = Color3.fromRGB(19, 19, 19), Size = UDim2.new(1, 0, 0, 0), Position = UDim2.new(0, 0, 0, 22), BorderColor3 = Color3.fromRGB(30, 30, 30) })
                create("UIListLayout", { Name = "DropdownContentLayout", Parent = dropdownContent, SortOrder = Enum.SortOrder.LayoutOrder })

                local function createOption(option)
                    local optionButton = create("TextButton", { Name = "Option", Parent = dropdownContent, BorderSizePixel = 0, TextSize = 14, AutoButtonColor = false, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 15), BorderColor3 = Color3.fromRGB(0, 0, 0), Text = "" })
                    create("TextLabel", { Name = "OptionName", Parent = optionButton, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Left, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 1, 0), Position = UDim2.new(0, 2, 0, 0), Text = option, FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = option == dropdown.default and Color3.fromRGB(255, 255, 255) or Color3.fromRGB(200, 200, 200) })
                    optionButton.MouseButton1Click:Connect(function()
                        valueLabel.Text = option; dropdown.callback(option); dropdownContent.Visible = false; dropdown.open = false; iconLabel.Text = "-"
                        for _, child in ipairs(dropdownContent:GetChildren()) do
                            if child:IsA("TextButton") and child.Name == "Option" then child.OptionName.TextColor3 = child.OptionName.Text == option and Color3.fromRGB(255, 255, 255) or Color3.fromRGB(200, 200, 200) end
                        end
                    end)
                end
                for _, option in ipairs(dropdown.options) do createOption(option) end
                dropdownButton.MouseButton1Click:Connect(function()
                    dropdown.open = not dropdown.open; dropdownContent.Visible = dropdown.open; iconLabel.Text = dropdown.open and "+" or "-"; dropdownContent.Size = UDim2.new(1, 0, 0, math.min(#dropdown.options * 15, 150))
                end)
                function dropdown:RefreshOptions(newOptions)
                    dropdown.options = newOptions
                    for _, child in ipairs(dropdownContent:GetChildren()) do if child:IsA("TextButton") then child:Destroy() end end
                    for _, option in ipairs(newOptions) do createOption(option) end
                end
                function dropdown:Set(value)
                    if table.find(dropdown.options, value) then
                        valueLabel.Text = value; dropdown.callback(value)
                        for _, child in ipairs(dropdownContent:GetChildren()) do
                            if child:IsA("TextButton") and child.Name == "Option" then child.OptionName.TextColor3 = child.OptionName.Text == value and Color3.fromRGB(255, 255, 255) or Color3.fromRGB(200, 200, 200) end
                        end
                    end
                end
                function dropdown:Get() return valueLabel.Text end
                return dropdown
            end
        end

        -- Секция на ВСЮ высоту (Как в Visuals)
        function tab:Section(name, side)
            local section = { name = name, elements = {} }
            local position = side == "right" and UDim2.new(0.5, 7, 0, 11) or UDim2.new(0, 12, 0, 11)
            local size = UDim2.new(0.5, -19, 1, -22)

            local sectionFrame = create("Frame", {
                Name = "Section", Parent = tab.content, BackgroundColor3 = Color3.fromRGB(21, 21, 21),
                BorderMode = Enum.BorderMode.Inset, Size = size, Position = position,
                BorderColor3 = Color3.fromRGB(29, 29, 29), BackgroundTransparency = 0
            })
            create("UIStroke", { Name = "SectionOutline", Parent = sectionFrame, ApplyStrokeMode = Enum.ApplyStrokeMode.Border, LineJoinMode = Enum.LineJoinMode.Miter, Color = Color3.fromRGB(0, 0, 0) })
            local accentLine = create("Frame", { Name = "SectionAccentLine", Parent = sectionFrame, BorderSizePixel = 0, BackgroundColor3 = Color3.fromRGB(91, 134, 198), Size = UDim2.new(1, 0, 0, 1), Position = UDim2.new(0, 0, 0, 23) })
            
            local titleLabel = create("TextLabel", {
                Name = "SectionTitle", Parent = accentLine, BorderSizePixel = 0, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Left,
                BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 23), Position = UDim2.new(0, 0, 0, -23), Text = name,
                FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = Color3.fromRGB(255, 255, 255)
            })
            create("UIPadding", { Name = "SectionTitlePadding", Parent = titleLabel, PaddingLeft = UDim.new(0, 5), PaddingBottom = UDim.new(0, 2) })

            local sectionContent = create("Frame", {
                Name = "SectionContent", Parent = sectionFrame, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 1, -24),
                Position = UDim2.new(0, 0, 0, 24), BackgroundColor3 = Color3.fromRGB(0, 0, 0)
            })
            create("UIPadding", { Name = "SectionContentPadding", Parent = sectionContent, PaddingTop = UDim.new(0, 5) })
            create("UIListLayout", { Name = "SectionContentLayout", Parent = sectionContent, Padding = UDim.new(0, 7), SortOrder = Enum.SortOrder.LayoutOrder })

            populateSection(section, sectionContent)
            return section
        end

        -- Секция на ПОЛОВИНУ высоты (Специально для Name Protect / Badge)
        function tab:SubSection(name, side, isBottom)
            local section = { name = name, elements = {} }
            local yOffset = isBottom and 0.5 or 0
            local position = side == "right" and UDim2.new(0.5, 7, yOffset, 11) or UDim2.new(0, 12, yOffset, 11)
            local size = UDim2.new(0.5, -19, 0.5, -22)

            local sectionFrame = create("Frame", {
                Name = "SubSection", Parent = tab.content, BackgroundColor3 = Color3.fromRGB(21, 21, 21),
                BorderMode = Enum.BorderMode.Inset, Size = size, Position = position,
                BorderColor3 = Color3.fromRGB(29, 29, 29), BackgroundTransparency = 0
            })
            create("UIStroke", { Name = "SectionOutline", Parent = sectionFrame, ApplyStrokeMode = Enum.ApplyStrokeMode.Border, LineJoinMode = Enum.LineJoinMode.Miter, Color = Color3.fromRGB(0, 0, 0) })
            local accentLine = create("Frame", { Name = "SectionAccentLine", Parent = sectionFrame, BorderSizePixel = 0, BackgroundColor3 = Color3.fromRGB(91, 134, 198), Size = UDim2.new(1, 0, 0, 1), Position = UDim2.new(0, 0, 0, 23) })
            
            local titleLabel = create("TextLabel", {
                Name = "SectionTitle", Parent = accentLine, BorderSizePixel = 0, TextSize = 12, TextXAlignment = Enum.TextXAlignment.Left,
                BackgroundTransparency = 1, Size = UDim2.new(1, 0, 0, 23), Position = UDim2.new(0, 0, 0, -23), Text = name,
                FontFace = Font.new("rbxasset://fonts/families/Zekton.json"), TextColor3 = Color3.fromRGB(255, 255, 255)
            })
            create("UIPadding", { Name = "SectionTitlePadding", Parent = titleLabel, PaddingLeft = UDim.new(0, 5), PaddingBottom = UDim.new(0, 2) })

            local sectionContent = create("Frame", {
                Name = "SectionContent", Parent = sectionFrame, BackgroundTransparency = 1, Size = UDim2.new(1, 0, 1, -24),
                Position = UDim2.new(0, 0, 0, 24), BackgroundColor3 = Color3.fromRGB(0, 0, 0)
            })
            create("UIPadding", { Name = "SectionContentPadding", Parent = sectionContent, PaddingTop = UDim.new(0, 5) })
            create("UIListLayout", { Name = "SectionContentLayout", Parent = sectionContent, Padding = UDim.new(0, 7), SortOrder = Enum.SortOrder.LayoutOrder })

            populateSection(section, sectionContent)
            return section
        end

        return tab
    end
    return window
end

-- ========================================== --
-- СТРУКТУРИРОВАНИЕ СЕКЦИЙ И ВКЛАДОК
-- ========================================== --
local Window = ui:Window({ title = "Plague.cc", size = Vector2.new(600, 450) })

-- Вкладка ESP (Теперь на всю высоту, симметрично как в Visuals)
local EspTab = Window:Tab("Esp")
local EspItemsSection = EspTab:Section("Items", "left")
local EspSettingsSection = EspTab:Section("Settings", "right")

-- Вкладка Visuals
local VisualsTab = Window:Tab("Visuals")
local VisWorldSection = VisualsTab:Section("World", "left")
local VisCharacterSection = VisualsTab:Section("Character", "right")

-- Вкладка Misc (Miscellaneous на всю высоту, правая разделена пополам)
local MiscTab = Window:Tab("Misc")
local MiscSection = MiscTab:Section("Miscellaneous", "left")
local NameProtectSection = MiscTab:SubSection("Name Protect", "right", false) -- Верхняя половина
local BadgeSection = MiscTab:SubSection("Badge", "right", true)             -- Нижня половина (пустая)

local ConfigTab = Window:Tab("Configs")
local MiscConfigSection = ConfigTab:Section("Configs", "left")

-- ========================================== --
-- ДИНАМИЧЕСКИЙ HUD ВАТЕРМАРКА (ФИКС)
-- ========================================== --
local hudGui = create("ScreenGui", {
    Name = "PlagueHUD", Parent = game:GetService("CoreGui"),
    ZIndexBehavior = Enum.ZIndexBehavior.Sibling, IgnoreGuiInset = true
})

-- Убран AutomaticSize, возвращен абсолютный контроль над шириной Frame
local hudFrame = create("Frame", {
    Name = "HUDContainer", Parent = hudGui, BackgroundColor3 = Color3.fromRGB(21, 21, 21),
    Size = UDim2.new(0, 180, 0, 28), Position = UDim2.new(1, -10, 0, 10),
    AnchorPoint = Vector2.new(1, 0), Visible = false, BorderSizePixel = 0
})
create("UICorner", { Parent = hudFrame, CornerRadius = UDim.new(0, 5) })

local gradientBar = create("Frame", {
    Name = "GradientBar", Parent = hudFrame,
    Size = UDim2.new(1, 0, 0, 3), Position = UDim2.new(0, 0, 0, 0),
    BorderSizePixel = 0, BackgroundColor3 = Color3.fromRGB(255, 255, 255)
})
create("UICorner", { Parent = gradientBar, CornerRadius = UDim.new(0, 5) })

local uiGradient = create("UIGradient", {
    Parent = gradientBar, Rotation = 0,
    Color = ColorSequence.new({
        ColorSequenceKeypoint.new(0, Color3.fromRGB(91, 134, 198)),
        ColorSequenceKeypoint.new(1, Color3.fromRGB(151, 91, 198))
    })
})

create("Frame", {
    Parent = gradientBar, BackgroundColor3 = Color3.fromRGB(21, 21, 21),
    Size = UDim2.new(1, 0, 0, 1), Position = UDim2.new(0, 0, 1, 0), BorderSizePixel = 0
})

local hudLabel = create("TextLabel", {
    Parent = hudFrame, BackgroundTransparency = 1, 
    Size = UDim2.new(1, 0, 1, -3), Position = UDim2.new(0, 0, 0, 3), 
    Text = "Plague.cc", TextColor3 = Color3.fromRGB(255, 255, 255),
    FontFace = Font.new("rbxasset://fonts/families/Zekton.json"),
    TextSize = 13, TextXAlignment = Enum.TextXAlignment.Center
})

-- ========================================== --
-- ЛОГИКА ЗАМЕНЫ НИКА
-- ========================================== --
local NICK = { Hide = false, FakeText = "" }
local _origText = {}  
local _nickConns = {} 

local function _isNickLabel(c)
    if not (c:IsA("TextLabel") or c:IsA("TextButton")) then return false end
    local t = c.Text
    if not t or t == "" or t == NICK.FakeText then return false end  
    local n, dn = LP.Name, LP.DisplayName
    if n  ~= "" and (t == n  or string.find(t, n,  1, true)) then return true end
    if dn ~= "" and (t == dn or string.find(t, dn, 1, true)) then return true end
    return false
end

local function _patchLabel(c)
    if not _origText[c] then _origText[c] = c.Text end
    c.Text = NICK.FakeText
    if not _nickConns[c] then
        _nickConns[c] = c:GetPropertyChangedSignal("Text"):Connect(function()
            if NICK.Hide and c.Text ~= NICK.FakeText and _isNickLabel(c) then
                _origText[c] = c.Text; c.Text = NICK.FakeText
            end
        end)
    end
end

local function scanTargetContainers()
    if not NICK.Hide then return end
    if PG then for _, d in ipairs(PG:GetDescendants()) do if _isNickLabel(d) then _patchLabel(d) end end end
    for _, p in ipairs(Players:GetPlayers()) do
        if p.Character then for _, d in ipairs(p.Character:GetDescendants()) do if _isNickLabel(d) then _patchLabel(d) end end end
    end
end

local function clearOldNickSettings()
    for lbl, conn in pairs(_nickConns) do pcall(function() conn:Disconnect() end) end
    table.clear(_nickConns)
    for lbl, orig in pairs(_origText) do if lbl and lbl.Parent then pcall(function() lbl.Text = orig end) end end
    table.clear(_origText)
end

-- ========================================== --
-- НАПОЛНЕНИЕ КАТЕГОРИЙ
-- ========================================== --

-- Miscellaneous
MiscSection:Button({
    title = "Server Hop",
    callback = function()
        local x = pcall(function()
            local Http = game:GetService("HttpService")
            local Api = "https://games.roblox.com/v1/games/" .. game.PlaceId .. "/servers/Public?sortOrder=Asc&limit=100"
            local Next = ""
            local BestServer = nil
            local MinPlayers = math.huge
            for i = 1, 3 do
                local Url = Api .. (Next ~= "" and "&cursor=" .. Next or "")
                local Req = HttpGet(game, Url)
                local Json = Http:JSONDecode(Req)
                if Json and Json.data then
                    for _, s in pairs(Json.data) do
                        if s.playing and s.playing < s.maxPlayers and s.id ~= game.JobId then
                            if s.playing < MinPlayers then MinPlayers = s.playing; BestServer = s.id end
                        end
                    end
                    if Json.nextPageCursor then Next = Json.nextPageCursor else break end
                else break end
            end
            if BestServer then TeleportService:TeleportToPlaceInstance(game.PlaceId, BestServer, LP) else TeleportService:Teleport(game.PlaceId, LP) end
        end)
        if not x then TeleportService:Teleport(game.PlaceId, LP) end
    end
})

-- Visuals -> World (Перенесенная ватермарка)
local hudToggle = VisWorldSection:Toggle({
    title = "Enable HUD",
    default = false,
    callback = function(state) hudFrame.Visible = state end
})

-- Name Protect (Текстбокс без лишней надписи сверху)
local NameBox = NameProtectSection:TextBox({
    placeholder = "Custom Nick...",
    callback = function(text) end
})

NameProtectSection:Button({
    title = "Apply",
    callback = function()
        local name = NameBox:Get()
        if name and name ~= "" then
            clearOldNickSettings()
            NICK.FakeText = name; NICK.Hide = true; scanTargetContainers()
        end
    end
})

task.spawn(function()
    while true do task.wait(3) if NICK.Hide then scanTargetContainers() end end
end)

PG.DescendantAdded:Connect(function(d) if NICK.Hide and _isNickLabel(d) then _patchLabel(d) end end)

-- ========================================== --
-- СИСТЕМА КОНФИГОВ И ПЛАВНЫЙ ЦИКЛ ОБНОВЛЕНИЯ
-- ========================================== --
local ConfigFolder = "PlagueConfigs"
if not isfolder(ConfigFolder) then makefolder(ConfigFolder) end

local RegisteredElements = {}
RegisteredElements["hud_enabled"] = hudToggle

local ConfigDropdown = MiscConfigSection:Dropdown({ title = "Config", options = {"None"}, default = "None", callback = function(val) end })

local function RefreshConfigs()
    local files = listfiles(ConfigFolder)
    local names = {}
    for _, file in ipairs(files) do
        local name = file:match(ConfigFolder .. "[/\\](.-)%.json")
        if name then table.insert(names, name) end
    end
    if #names == 0 then names = {"None"} end
    ConfigDropdown:RefreshOptions(names)
end
RefreshConfigs()

local ConfigNameBox = MiscConfigSection:TextBox({ placeholder = "Config Name...", callback = function() end })

MiscConfigSection:Button({
    title = "Save Config",
    callback = function()
        local name = ConfigNameBox:Get()
        if name == "" then return end
        local data = {}
        for k, v in pairs(RegisteredElements) do if v.Get then data[k] = v:Get() end end
        writefile(ConfigFolder .. "/" .. name .. ".json", HttpService:JSONEncode(data))
        RefreshConfigs()
    end
})

MiscConfigSection:Button({
    title = "Load Config",
    callback = function()
        local name = ConfigNameBox:Get()
        if name == "" or not isfile(ConfigFolder .. "/" .. name .. ".json") then return end
        local data = HttpService:JSONDecode(readfile(ConfigFolder .. "/" .. name .. ".json"))
        for k, v in pairs(data) do if RegisteredElements[k] and RegisteredElements[k].Set then RegisteredElements[k]:Set(v) end end
    end
})

-- Настройки фильтрации сглаживания
local smoothedFPS = 60
local smoothedPing = 0
local lastTime = tick()
local Speed = 0.7
local textFont = Font.new("rbxasset://fonts/families/Zekton.json")

RunService.RenderStepped:Connect(function(dt)
    local now = tick()
    local frameTime = now - lastTime
    lastTime = now
    
    local rawFps = 1 / frameTime
    local rawPing = 0
    pcall(function()
        rawPing = Stats.Network.ServerStatsItem["Data Ping"]:GetValue()
    end)
    
    -- Мягкий lerp (0.05), чтобы значения FPS/Ping обновлялись плавно без дерганий
    smoothedFPS = smoothedFPS + (rawFps - smoothedFPS) * 0.05
    smoothedPing = smoothedPing + (rawPing - smoothedPing) * 0.05
    
    if hudFrame.Visible then
        local displayNick = NICK.Hide and NICK.FakeText or LocalPlayer.DisplayName
        local textString = string.format("%s | Plague.cc | %d fps | %d ms", displayNick, math.round(smoothedFPS), math.round(smoothedPing))
        hudLabel.Text = textString
        
        -- Вычисление идеальной длины строки через TextService
        local textSize = TextService:GetTextSize(textString, 13, Enum.Font.Code, Vector2.new(1000, 28))
        hudFrame.Size = UDim2.new(0, textSize.X + 20, 0, 28) -- +20 для красивых отступов по бокам
    end
    
    local offset = math.sin(os.clock() * Speed)
    uiGradient.Offset = Vector2.new(offset * 0.5, 0)
end)