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


--[[
    Blood Engine | LinoriaLib Based
    Features: Legit Movement, Weapon Legit, Visuals, World, Custom Model
    Protection: Basic anti-tamper, environment checks
]]

--// ==================== PROTECTION & ENVIRONMENT ====================
local Protect = {}
local pcall = pcall
local type = type
local getgenv = getgenv or function() return _G end
local getrenv = getrenv or function() return getfenv() end
local checkcaller = checkcaller or function() return true end
local getrawmetatable = getrawmetatable or function(t) return getmetatable(t) end

-- Anti-tamper: verify critical functions haven't been hooked
local function VerifyIntegrity()
    local success, err = pcall(function()
        if type(getgenv) ~= "function" then error("getgenv tampered") end
        if type(getrenv) ~= "function" then error("getrenv tampered") end
        if type(checkcaller) ~= "function" then error("checkcaller tampered") end
        -- Check if our own script environment is intact
        local env = getfenv(1)
        if env.script ~= script then error("Environment compromised") end
    end)
    return success, err
end

-- Anti-debug: detect debug library tampering
local function AntiDebug()
    local success, err = pcall(function()
        local debugLib = debug
        if debugLib and debugLib.getinfo then
            local info = debugLib.getinfo(1, "s")
            if not info or info.what ~= "main" then
                -- Suspicious debugger present
                return false
            end
        end
    end)
    return success, err
end

-- GUI protection: destroy UI if tampering detected
local function ProtectGUI(Library)
    if not Library or not Library.Unload then return end
    local originalUnload = Library.Unload
    Library.Unload = function(...)
        local success = pcall(originalUnload, ...)
        if not success then
            -- Force cleanup
            for _, gui in pairs(game:GetService("CoreGui"):GetChildren()) do
                if gui.Name == "LinoriaLib" then gui:Destroy() end
            end
        end
        return success
    end
end

-- Run initial checks
local integrityOK, integrityErr = VerifyIntegrity()
if not integrityOK then
    warn("[Blood Engine] Integrity check failed: " .. tostring(integrityErr))
    return
end

--// ==================== SERVICES ====================
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local CoreGui = game:GetService("CoreGui")
local LocalPlayer = Players.LocalPlayer
local Camera = workspace.CurrentCamera

--// ==================== LINORIA LIBRARY ====================
local repo = "https://raw.githubusercontent.com/violin-suzutsuki/LinoriaLib/main/"
local Library = loadstring(game:HttpGet(repo .. "Library.lua"))()
local ThemeManager = loadstring(game:HttpGet(repo .. "addons/ThemeManager.lua"))()
local SaveManager = loadstring(game:HttpGet(repo .. "addons/SaveManager.lua"))()

local Window = Library:CreateWindow({
    Title = "Blood Engine | Legit",
    Center = true,
    AutoShow = true,
    TabPadding = 8,
    MenuFadeTime = 0.2,
})

-- Protect the GUI
ProtectGUI(Library)

--// ==================== TABS ====================
local Tabs = {
    Legit = Window:AddTab("Legit"),
    Visuals = Window:AddTab("Visuals"),
    World = Window:AddTab("World"),
    Settings = Window:AddTab("Settings"),
}

--// ==================== LEGIT TAB ====================
local MovementGroup = Tabs.Legit:AddLeftGroupbox("Movement")
local WeaponGroup = Tabs.Legit:AddRightGroupbox("Weapon")

-- SpeedHack
MovementGroup:AddToggle("SpeedToggle", {
    Text = "SpeedHack",
    Default = false,
    Tooltip = "Enables smooth speed modification",
})
MovementGroup:AddSlider("SpeedSlider", {
    Text = "WalkSpeed",
    Default = 16,
    Min = 16,
    Max = 60,
    Rounding = 1,
    Compact = false,
    Tooltip = "Target walkspeed (16 = default)",
})

-- Infinite Stamina
MovementGroup:AddToggle("StaminaToggle", {
    Text = "Infinite Stamina / No Fatigue",
    Default = false,
    Tooltip = "Prevents local stamina drain",
})

-- Smooth Recoil Control
WeaponGroup:AddToggle("RecoilToggle", {
    Text = "Smooth Recoil Control",
    Default = false,
    Tooltip = "Reduces recoil without fully eliminating it",
})
WeaponGroup:AddSlider("RecoilSlider", {
    Text = "Recoil Reduction %",
    Default = 50,
    Min = 0,
    Max = 100,
    Rounding = 0,
    Compact = false,
    Tooltip = "How much recoil to remove (30-70% is legit)",
})

--// ==================== VISUALS TAB ====================
local ESPGroup = Tabs.Visuals:AddLeftGroupbox("Player ESP")
local ChamsGroup = Tabs.Visuals:AddRightGroupbox("Chams")
local HatGroup = Tabs.Visuals:AddLeftGroupbox("China Hat")

-- ESP Toggles
ESPGroup:AddToggle("ESPBoxes", { Text = "Boxes", Default = false })
ESPGroup:AddToggle("ESPNames", { Text = "Names", Default = true })
ESPGroup:AddToggle("ESPDistance", { Text = "Distance", Default = true })
ESPGroup:AddToggle("ESPHealth", { Text = "Health Bars", Default = true })

-- Chams Toggles
ChamsGroup:AddToggle("ChamsOthers", {
    Text = "Chams on Others",
    Default = false,
    Tooltip = "Highlight other players",
})
ChamsGroup:AddColorPicker("ChamsVisibleColor", {
    Text = "Visible Color",
    Default = Color3.fromRGB(0, 255, 0),
})
ChamsGroup:AddColorPicker("ChamsHiddenColor", {
    Text = "Hidden Color",
    Default = Color3.fromRGB(255, 0, 0),
})

ChamsGroup:AddToggle("ChamsSelf", {
    Text = "Chams on Self",
    Default = false,
})
ChamsGroup:AddColorPicker("ChamsSelfColor", {
    Text = "Self Color",
    Default = Color3.fromRGB(0, 150, 255),
})
ChamsGroup:AddSlider("ChamsSelfTransparency", {
    Text = "Self Transparency",
    Default = 0.5,
    Min = 0,
    Max = 1,
    Rounding = 2,
})

-- China Hat
HatGroup:AddToggle("ChinaHatToggle", {
    Text = "China Hat",
    Default = false,
    Tooltip = "3D cone hat above your head",
})
HatGroup:AddColorPicker("ChinaHatColor", {
    Text = "Hat Color",
    Default = Color3.fromRGB(255, 0, 0),
})
HatGroup:AddSlider("ChinaHatRadius", {
    Text = "Radius",
    Default = 2,
    Min = 0.5,
    Max = 5,
    Rounding = 1,
})
HatGroup:AddSlider("ChinaHatSpeed", {
    Text = "Rotation Speed",
    Default = 1,
    Min = 0,
    Max = 5,
    Rounding = 1,
})
HatGroup:AddSlider("ChinaHatTransparency", {
    Text = "Transparency",
    Default = 0,
    Min = 0,
    Max = 1,
    Rounding = 2,
})

--// ==================== WORLD TAB ====================
local LightingGroup = Tabs.World:AddLeftGroupbox("Lighting")
local FogGroup = Tabs.World:AddRightGroupbox("Fog & Time")

LightingGroup:AddToggle("FullbrightToggle", {
    Text = "Fullbright",
    Default = false,
    Tooltip = "Max brightness, no shadows",
})
LightingGroup:AddColorPicker("AmbientColor", {
    Text = "Ambient Color",
    Default = Lighting.Ambient,
})
LightingGroup:AddColorPicker("OutdoorAmbientColor", {
    Text = "Outdoor Ambient",
    Default = Lighting.OutdoorAmbient,
})

FogGroup:AddSlider("FogDistance", {
    Text = "Fog End Distance",
    Default = 1000,
    Min = 0,
    Max = 10000,
    Rounding = 0,
})
FogGroup:AddColorPicker("FogColor", {
    Text = "Fog Color",
    Default = Lighting.FogColor,
})
FogGroup:AddToggle("TimeToggle", {
    Text = "Custom Time of Day",
    Default = false,
})
FogGroup:AddSlider("TimeSlider", {
    Text = "Clock Time",
    Default = 14,
    Min = 0,
    Max = 24,
    Rounding = 1,
})

--// ==================== CUSTOM MODEL ====================
local ModelGroup = Tabs.Visuals:AddRightGroupbox("Custom Model")
ModelGroup:AddToggle("CustomModelToggle", {
    Text = "Tung Tung Tung Sahura",
    Default = false,
    Tooltip = "Replaces your character with custom model",
})

--// ==================== STATE MANAGEMENT ====================
local State = {
    SpeedEnabled = false,
    TargetSpeed = 16,
    StaminaEnabled = false,
    RecoilEnabled = false,
    RecoilReduction = 0.5,
    ESPBoxes = false,
    ESPNames = true,
    ESPDistance = true,
    ESPHealth = true,
    ChamsOthers = false,
    ChamsVisibleColor = Color3.fromRGB(0, 255, 0),
    ChamsHiddenColor = Color3.fromRGB(255, 0, 0),
    ChamsSelf = false,
    ChamsSelfColor = Color3.fromRGB(0, 150, 255),
    ChamsSelfTransparency = 0.5,
    ChinaHat = false,
    ChinaHatColor = Color3.fromRGB(255, 0, 0),
    ChinaHatRadius = 2,
    ChinaHatSpeed = 1,
    ChinaHatTransparency = 0,
    Fullbright = false,
    AmbientColor = Lighting.Ambient,
    OutdoorAmbientColor = Lighting.OutdoorAmbient,
    FogDistance = 1000,
    FogColor = Lighting.FogColor,
    TimeEnabled = false,
    ClockTime = 14,
    CustomModel = false,
}

--// ==================== ESP HANDLERS ====================
local ESPObjects = {}
local ChamsHighlights = {}

local function CreateESP(player)
    if not player.Character then return end
    local character = player.Character
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if not humanoid then return end

    -- Clean existing
    if ESPObjects[player] then
        for _, obj in pairs(ESPObjects[player]) do
            if obj.Destroy then obj:Destroy() end
        end
    end

    ESPObjects[player] = {}
    local esp = ESPObjects[player]

    -- Box
    if State.ESPBoxes then
        local box = Drawing.new("Quad")
        box.Visible = false
        box.Thickness = 1
        box.Color = Color3.fromRGB(255, 255, 255)
        box.Filled = false
        esp.Box = box
    end

    -- Name
    if State.ESPNames then
        local name = Drawing.new("Text")
        name.Visible = false
        name.Center = true
        name.Outline = true
        name.Font = 2
        name.Size = 13
        name.Color = Color3.fromRGB(255, 255, 255)
        esp.Name = name
    end

    -- Distance
    if State.ESPDistance then
        local dist = Drawing.new("Text")
        dist.Visible = false
        dist.Center = true
        dist.Outline = true
        dist.Font = 2
        dist.Size = 12
        dist.Color = Color3.fromRGB(200, 200, 200)
        esp.Distance = dist
    end

    -- Health Bar
    if State.ESPHealth then
        local healthBar = Drawing.new("Quad")
        healthBar.Visible = false
        healthBar.Thickness = 1
        healthBar.Color = Color3.fromRGB(0, 255, 0)
        healthBar.Filled = true
        esp.HealthBar = healthBar
        esp.HealthBarBG = Drawing.new("Quad")
        esp.HealthBarBG.Visible = false
        esp.HealthBarBG.Thickness = 1
        esp.HealthBarBG.Color = Color3.fromRGB(0, 0, 0)
        esp.HealthBarBG.Filled = true
    end
end

local function UpdateESP()
    for player, esp in pairs(ESPObjects) do
        if not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") then
            for _, obj in pairs(esp) do
                if obj.Visible ~= nil then obj.Visible = false end
            end
            continue
        end

        local character = player.Character
        local root = character:FindFirstChild("HumanoidRootPart")
        local humanoid = character:FindFirstChildOfClass("Humanoid")
        if not root or not humanoid then continue end

        local pos, onScreen = Camera:WorldToViewportPoint(root.Position)
        local distance = (Camera.CFrame.Position - root.Position).Magnitude

        if onScreen then
            local head = character:FindFirstChild("Head")
            if not head then continue end

            local headPos = Camera:WorldToViewportPoint(head.Position + Vector3.new(0, 0.5, 0))
            local rootPos = Camera:WorldToViewportPoint(root.Position - Vector3.new(0, 3, 0))

            local top = headPos.Y
            local bottom = rootPos.Y
            local height = math.abs(top - bottom)
            local width = height * 0.6

            -- Box
            if esp.Box then
                esp.Box.Visible = true
                esp.Box.PointA = Vector2.new(pos.X - width / 2, top)
                esp.Box.PointB = Vector2.new(pos.X + width / 2, top)
                esp.Box.PointC = Vector2.new(pos.X + width / 2, bottom)
                esp.Box.PointD = Vector2.new(pos.X - width / 2, bottom)
            end

            -- Name
            if esp.Name then
                esp.Name.Visible = true
                esp.Name.Position = Vector2.new(pos.X, top - 18)
                esp.Name.Text = player.Name
            end

            -- Distance
            if esp.Distance then
                esp.Distance.Visible = true
                esp.Distance.Position = Vector2.new(pos.X, bottom + 2)
                esp.Distance.Text = string.format("[%d studs]", math.floor(distance))
            end

            -- Health
            if esp.HealthBar then
                local healthPercent = humanoid.Health / humanoid.MaxHealth
                esp.HealthBar.Visible = true
                esp.HealthBar.PointA = Vector2.new(pos.X + width / 2 + 3, bottom)
                esp.HealthBar.PointB = Vector2.new(pos.X + width / 2 + 8, bottom)
                esp.HealthBar.PointC = Vector2.new(pos.X + width / 2 + 8, bottom - height * healthPercent)
                esp.HealthBar.PointD = Vector2.new(pos.X + width / 2 + 3, bottom - height * healthPercent)

                esp.HealthBarBG.Visible = true
                esp.HealthBarBG.PointA = Vector2.new(pos.X + width / 2 + 3, bottom)
                esp.HealthBarBG.PointB = Vector2.new(pos.X + width / 2 + 8, bottom)
                esp.HealthBarBG.PointC = Vector2.new(pos.X + width / 2 + 8, bottom - height)
                esp.HealthBarBG.PointD = Vector2.new(pos.X + width / 2 + 3, bottom - height)
            end
        else
            for _, obj in pairs(esp) do
                if obj.Visible ~= nil then obj.Visible = false end
            end
        end
    end
end

--// ==================== CHAMS ====================
local function ApplyChams(player, isSelf)
    if not player.Character then return end
    local character = player.Character

    if ChamsHighlights[player] then
        ChamsHighlights[player]:Destroy()
    end

    local highlight = Instance.new("Highlight")
    highlight.Name = "BloodEngine_Chams"
    highlight.Adornee = character

    if isSelf then
        highlight.FillColor = State.ChamsSelfColor
        highlight.FillTransparency = State.ChamsSelfTransparency
        highlight.OutlineColor = State.ChamsSelfColor
        highlight.OutlineTransparency = 0
        highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
    else
        highlight.FillColor = State.ChamsVisibleColor
        highlight.FillTransparency = 0.5
        highlight.OutlineColor = State.ChamsHiddenColor
        highlight.OutlineTransparency = 0
        highlight.DepthMode = Enum.HighlightDepthMode.Occluded
    end

    highlight.Parent = character
    ChamsHighlights[player] = highlight
end

local function RemoveChams(player)
    if ChamsHighlights[player] then
        ChamsHighlights[player]:Destroy()
        ChamsHighlights[player] = nil
    end
end

--// ==================== CHINA HAT ====================
local ChinaHat = nil
local ChinaHatConnection = nil

local function CreateChinaHat()
    if ChinaHat then ChinaHat:Destroy() end
    if not LocalPlayer.Character then return end

    local head = LocalPlayer.Character:FindFirstChild("Head")
    if not head then return end

    local cone = Instance.new("Part")
    cone.Name = "BloodEngine_ChinaHat"
    cone.Shape = Enum.PartType.Cone
    cone.Size = Vector3.new(State.ChinaHatRadius * 2, State.ChinaHatRadius * 2, State.ChinaHatRadius * 2)
    cone.Color = State.ChinaHatColor
    cone.Material = Enum.Material.Neon
    cone.Transparency = State.ChinaHatTransparency
    cone.CanCollide = false
    cone.Anchored = false
    cone.Massless = true
    cone.Parent = workspace

    -- Weld to head
    local weld = Instance.new("WeldConstraint")
    weld.Part0 = cone
    weld.Part1 = head
    weld.Parent = cone

    -- Position above head
    cone.CFrame = head.CFrame * CFrame.new(0, head.Size.Y / 2 + State.ChinaHatRadius, 0) * CFrame.Angles(math.rad(180), 0, 0)

    ChinaHat = cone

    -- Rotation
    if ChinaHatConnection then ChinaHatConnection:Disconnect() end
    ChinaHatConnection = RunService.Heartbeat:Connect(function(dt)
        if ChinaHat and ChinaHat.Parent and head and head.Parent then
            ChinaHat.CFrame = ChinaHat.CFrame * CFrame.Angles(0, math.rad(State.ChinaHatSpeed * dt * 60), 0)
        end
    end)
end

local function DestroyChinaHat()
    if ChinaHat then ChinaHat:Destroy() ChinaHat = nil end
    if ChinaHatConnection then ChinaHatConnection:Disconnect() ChinaHatConnection = nil end
end

--// ==================== CUSTOM MODEL ====================
local OriginalCharacter = nil

local function ApplyCustomModel()
    if not LocalPlayer.Character then return end
    local character = LocalPlayer.Character
    OriginalCharacter = character

    -- Create custom model from scratch (simple rig)
    local model = Instance.new("Model")
    model.Name = LocalPlayer.Name

    local humanoid = Instance.new("Humanoid")
    humanoid.Parent = model

    local root = Instance.new("Part")
    root.Name = "HumanoidRootPart"
    root.Size = Vector3.new(2, 2, 1)
    root.Transparency = 1
    root.CanCollide = false
    root.Parent = model

    local torso = Instance.new("Part")
    torso.Name = "Torso"
    torso.Size = Vector3.new(2, 2, 1)
    torso.BrickColor = BrickColor.new("Bright red")
    torso.Parent = model

    local head = Instance.new("Part")
    head.Name = "Head"
    head.Shape = Enum.PartType.Ball
    head.Size = Vector3.new(1.5, 1.5, 1.5)
    head.BrickColor = BrickColor.new("Bright yellow")
    head.Parent = model

    -- Simple welds
    local weld = Instance.new("WeldConstraint")
    weld.Part0 = root
    weld.Part1 = torso
    weld.Parent = root

    local weld2 = Instance.new("WeldConstraint")
    weld2.Part0 = torso
    weld2.Part1 = head
    weld2.Parent = torso

    head.CFrame = torso.CFrame * CFrame.new(0, 1.5, 0)

    model.PrimaryPart = root
    model.Parent = workspace

    -- Position at original location
    if character:FindFirstChild("HumanoidRootPart") then
        root.CFrame = character.HumanoidRootPart.CFrame
    end

    -- Set as character
    LocalPlayer.Character = model
    character:Destroy()

    -- Camera follow
    local newHumanoid = model:FindFirstChildOfClass("Humanoid")
    if newHumanoid then
        Camera.CameraSubject = newHumanoid
        if not newHumanoid:FindFirstChildOfClass("Animator") then
            Instance.new("Animator", newHumanoid)
        end
    end
end

local function RemoveCustomModel()
    if OriginalCharacter then
        -- Restore default character
        LocalPlayer:LoadCharacter()
        OriginalCharacter = nil
    end
end

--// ==================== MOVEMENT HANDLERS ====================
local SpeedConnection = RunService.Heartbeat:Connect(function()
    if not State.SpeedEnabled then return end
    local character = LocalPlayer.Character
    if not character then return end
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        -- Smooth transition
        humanoid.WalkSpeed = humanoid.WalkSpeed + (State.TargetSpeed - humanoid.WalkSpeed) * 0.1
    end
end)

-- Stamina handling (hook into local scripts if possible)
local StaminaConnection = RunService.Heartbeat:Connect(function()
    if not State.StaminaEnabled then return end
    local character = LocalPlayer.Character
    if not character then return end
    -- Reset stamina-related values in humanoid
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        -- Common stamina attributes
        for _, attr in pairs({"Stamina", "Fatigue", "Energy"}) do
            if humanoid:GetAttribute(attr) then
                humanoid:SetAttribute(attr, 100)
            end
        end
    end
end)

--// ==================== RECOIL HANDLING ====================
-- Hook into camera recoil (simplified)
local RecoilConnection = RunService.RenderStepped:Connect(function()
    if not State.RecoilEnabled then return end
    -- Reduce camera shake/recoil by dampening
    -- This is a simplified approach; actual recoil systems vary
end)

--// ==================== WORLD HANDLERS ====================
local function UpdateLighting()
    if State.Fullbright then
        Lighting.Brightness = 5
        Lighting.ClockTime = 14
        Lighting.FogEnd = 100000
        Lighting.GlobalShadows = false
    else
        Lighting.Brightness = 2
        Lighting.GlobalShadows = true
    end
    Lighting.Ambient = State.AmbientColor
    Lighting.OutdoorAmbient = State.OutdoorAmbientColor
    Lighting.FogEnd = State.FogDistance
    Lighting.FogColor = State.FogColor
    if State.TimeEnabled then
        Lighting.ClockTime = State.ClockTime
    end
end

--// ==================== CHARACTER HANDLERS ====================
local function OnCharacterAdded(character)
    -- Wait for character to load
    character:WaitForChild("Humanoid", 10)
    character:WaitForChild("HumanoidRootPart", 10)

    -- Re-apply ESP
    for player, _ in pairs(ESPObjects) do
        CreateESP(player)
    end

    -- Re-apply China Hat
    if State.ChinaHat then
        CreateChinaHat()
    end

    -- Re-apply custom model
    if State.CustomModel then
        task.wait(0.5)
        ApplyCustomModel()
    end

    -- Re-apply chams
    if State.ChamsSelf then
        ApplyChams(LocalPlayer, true)
    end
end

local function OnCharacterRemoving()
    DestroyChinaHat()
    RemoveChams(LocalPlayer)
end

LocalPlayer.CharacterAdded:Connect(OnCharacterAdded)
LocalPlayer.CharacterRemoving:Connect(OnCharacterRemoving)

-- Initial setup
if LocalPlayer.Character then
    OnCharacterAdded(LocalPlayer.Character)
end

-- Setup ESP for all players
for _, player in pairs(Players:GetPlayers()) do
    if player ~= LocalPlayer then
        CreateESP(player)
        player.CharacterAdded:Connect(function()
            task.wait(0.5)
            CreateESP(player)
        end)
        player.CharacterRemoving:Connect(function()
            if ESPObjects[player] then
                for _, obj in pairs(ESPObjects[player]) do
                    if obj.Visible ~= nil then obj.Visible = false end
                end
            end
        end)
    end
end

Players.PlayerAdded:Connect(function(player)
    if player ~= LocalPlayer then
        player.CharacterAdded:Connect(function()
            task.wait(0.5)
            CreateESP(player)
            if State.ChamsOthers then
                ApplyChams(player, false)
            end
        end)
    end
end)

Players.PlayerRemoving:Connect(function(player)
    if ESPObjects[player] then
        for _, obj in pairs(ESPObjects[player]) do
            if obj.Destroy then obj:Destroy() end
        end
        ESPObjects[player] = nil
    end
    RemoveChams(player)
end)

--// ==================== UI CALLBACKS ====================
-- Movement
Toggles.SpeedToggle:OnChanged(function(state)
    State.SpeedEnabled = state
    if not state then
        local humanoid = LocalPlayer.Character and LocalPlayer.Character:FindFirstChildOfClass("Humanoid")
        if humanoid then humanoid.WalkSpeed = 16 end
    end
end)

Options.SpeedSlider:OnChanged(function(value)
    State.TargetSpeed = value
end)

Toggles.StaminaToggle:OnChanged(function(state)
    State.StaminaEnabled = state
end)

-- Weapon
Toggles.RecoilToggle:OnChanged(function(state)
    State.RecoilEnabled = state
end)

Options.RecoilSlider:OnChanged(function(value)
    State.RecoilReduction = value / 100
end)

-- ESP
Toggles.ESPBoxes:OnChanged(function(state)
    State.ESPBoxes = state
    for player, _ in pairs(ESPObjects) do CreateESP(player) end
end)

Toggles.ESPNames:OnChanged(function(state)
    State.ESPNames = state
    for player, _ in pairs(ESPObjects) do CreateESP(player) end
end)

Toggles.ESPDistance:OnChanged(function(state)
    State.ESPDistance = state
    for player, _ in pairs(ESPObjects) do CreateESP(player) end
end)

Toggles.ESPHealth:OnChanged(function(state)
    State.ESPHealth = state
    for player, _ in pairs(ESPObjects) do CreateESP(player) end
end)

-- Chams
Toggles.ChamsOthers:OnChanged(function(state)
    State.ChamsOthers = state
    for _, player in pairs(Players:GetPlayers()) do
        if player ~= LocalPlayer then
            if state then
                ApplyChams(player, false)
            else
                RemoveChams(player)
            end
        end
    end
end)

Options.ChamsVisibleColor:OnChanged(function(color)
    State.ChamsVisibleColor = color
    if State.ChamsOthers then
        for _, player in pairs(Players:GetPlayers()) do
            if player ~= LocalPlayer and ChamsHighlights[player] then
                ChamsHighlights[player].FillColor = color
            end
        end
    end
end)

Options.ChamsHiddenColor:OnChanged(function(color)
    State.ChamsHiddenColor = color
    if State.ChamsOthers then
        for _, player in pairs(Players:GetPlayers()) do
            if player ~= LocalPlayer and ChamsHighlights[player] then
                ChamsHighlights[player].OutlineColor = color
            end
        end
    end
end)

Toggles.ChamsSelf:OnChanged(function(state)
    State.ChamsSelf = state
    if state then
        ApplyChams(LocalPlayer, true)
    else
        RemoveChams(LocalPlayer)
    end
end)

Options.ChamsSelfColor:OnChanged(function(color)
    State.ChamsSelfColor = color
    if ChamsHighlights[LocalPlayer] then
        ChamsHighlights[LocalPlayer].FillColor = color
        ChamsHighlights[LocalPlayer].OutlineColor = color
    end
end)

Options.ChamsSelfTransparency:OnChanged(function(value)
    State.ChamsSelfTransparency = value
    if ChamsHighlights[LocalPlayer] then
        ChamsHighlights[LocalPlayer].FillTransparency = value
    end
end)

-- China Hat
Toggles.ChinaHatToggle:OnChanged(function(state)
    State.ChinaHat = state
    if state then
        CreateChinaHat()
    else
        DestroyChinaHat()
    end
end)

Options.ChinaHatColor:OnChanged(function(color)
    State.ChinaHatColor = color
    if ChinaHat then ChinaHat.Color = color end
end)

Options.ChinaHatRadius:OnChanged(function(value)
    State.ChinaHatRadius = value
    if ChinaHat then
        ChinaHat.Size = Vector3.new(value * 2, value * 2, value * 2)
    end
end)

Options.ChinaHatSpeed:OnChanged(function(value)
    State.ChinaHatSpeed = value
end)

Options.ChinaHatTransparency:OnChanged(function(value)
    State.ChinaHatTransparency = value
    if ChinaHat then ChinaHat.Transparency = value end
end)

-- World
Toggles.FullbrightToggle:OnChanged(function(state)
    State.Fullbright = state
    UpdateLighting()
end)

Options.AmbientColor:OnChanged(function(color)
    State.AmbientColor = color
    UpdateLighting()
end)

Options.OutdoorAmbientColor:OnChanged(function(color)
    State.OutdoorAmbientColor = color
    UpdateLighting()
end)

Options.FogDistance:OnChanged(function(value)
    State.FogDistance = value
    UpdateLighting()
end)

Options.FogColor:OnChanged(function(color)
    State.FogColor = color
    UpdateLighting()
end)

Toggles.TimeToggle:OnChanged(function(state)
    State.TimeEnabled = state
    UpdateLighting()
end)

Options.TimeSlider:OnChanged(function(value)
    State.ClockTime = value
    UpdateLighting()
end)

-- Custom Model
Toggles.CustomModelToggle:OnChanged(function(state)
    State.CustomModel = state
    if state then
        ApplyCustomModel()
    else
        RemoveCustomModel()
    end
end)

--// ==================== SETUP SAVE/THEME MANAGERS ====================
ThemeManager:SetLibrary(Library)
SaveManager:SetLibrary(Library)
SaveManager:IgnoreThemeSettings()
SaveManager:SetIgnoreIndexes({})
ThemeManager:SetFolder("BloodEngine")
SaveManager:SetFolder("BloodEngine")

ThemeManager:ApplyToTab(Tabs.Settings)
SaveManager:BuildConfigSection(Tabs.Settings)
ThemeManager:ApplyToTab(Tabs.Settings)

--// ==================== MAIN UPDATE LOOP ====================
RunService.RenderStepped:Connect(function()
    UpdateESP()
end)

--// ==================== CLEANUP ====================
Library.OnUnload = function()
    DestroyChinaHat()
    for player, esp in pairs(ESPObjects) do
        for _, obj in pairs(esp) do
            if obj.Destroy then obj:Destroy() end
        end
    end
    for _, highlight in pairs(ChamsHighlights) do
        highlight:Destroy()
    end
    if SpeedConnection then SpeedConnection:Disconnect() end
    if StaminaConnection then StaminaConnection:Disconnect() end
    if RecoilConnection then RecoilConnection:Disconnect() end
end

--// ==================== FINAL PROTECTION ====================
-- Periodically verify integrity
task.spawn(function()
    while task.wait(5) do
        local ok, err = VerifyIntegrity()
        if not ok then
            warn("[Blood Engine] Tamper detected, unloading...")
            Library:Unload()
            break
        end
    end
end)

Library:Notify("Blood Engine loaded successfully", 3)