南南.lua

Pasted Nov 21, 2026, 3:39 AM1 file1,548 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/zzgs0crcvtk1qdp7
南南.lua
local Players=game:GetService("Players")
local RunService=game:GetService("RunService")
local UIS=game:GetService("UserInputService")
local HS=game:GetService("HttpService")
local Player=Players.LocalPlayer
if not Player then warn("[UUI] Player 為 nil") return end
local PlayerGui=Player:WaitForChild("PlayerGui",10)
if not PlayerGui then warn("[UUI] PlayerGui 取得失敗") return end
local IS_STUDIO=RunService:IsStudio()
local HAS_WRITEFILE=(writefile~=nil and readfile~=nil)
local HAS_HOOK=(hookmetamethod~=nil and getnamecallmethod~=nil)
local IS_RIVALS=(game.GameId==6035872082)
print("[UUI] 啟動,玩家:",Player.Name,"Studio=",IS_STUDIO)

-- ============ 全局状态 ============
local S={
    Underground=false,UndergroundDistance=10,
    VoidStrike=false,VoidDepth=9,
    VoidToggle=false,VoidToggleDepth=53,VoidToggleLRDistance=10,VoidToggleLRSpeed=5,
    Boost=false,Crosshair=false,DeltaAim=false,Skin=false,
    ESP=false,ESPName=true,ESPDistance=true,ESPHealth=true,ESPHealthBar=true,
    -- 新增功能开关
    VoidSpam=false,Orbit=false,Prediction=false,AntiAim=false,
    Riot=false,RiotAbuse=false,ProjBypass=false,
}
local CONFIG_FILE="UndergroundMobileUI_Saves.json"
local Saves={}
local Character,Root,Humanoid
local function GetCharacter()
    Character=Player.Character
    if not Character then return false end
    Root=Character:FindFirstChild("HumanoidRootPart")
    Humanoid=Character:FindFirstChildOfClass("Humanoid")
    return Root~=nil and Humanoid~=nil
end
GetCharacter()

local UndergroundStartCFrame,SavedCollision={},{}
local VoidReturnCFrame,VoidAngle=nil,0
local VoidToggleActive,VoidToggleBase=false,nil
local VoidToggleRightVector,VoidToggleStart
local ESPObjects,ControlRefs={},{}
local CrosshairGui,CrosshairConnection
local DeltaAimGui,DeltaAimConnection,DeltaAimBoxes=nil,nil,{}
local SkinActive,SkinHooked=false,false
local SkinOrig,SkinEquipped,SkinFavorites={},{},{}
local SkinSaveFile="Rivals-Skinchanger/skins.txt"
local rageActive=false
local rageWeaponSlot="Melee"
local rageFireRate=0.0005
local rageModules=nil
local rageLastFire=0
local rageDeflecting={}
local rageEquipRunning=false

-- 新增功能状态
local CFG_V={METHOD="Quantum",SPEED=1e9,RADIUS=2e11,BASE_ALTITUDE=1e10,EVADE=true}
local voidConn=nil,voidElapsed=0,voidPos=Vector3.new(0,CFG_V.BASE_ALTITUDE,0)
local voidDriftDir=Vector3.new(1,0,0).Unit,voidBasePos=Vector3.new(0,CFG_V.BASE_ALTITUDE,0)
local cfgO={orbitEnabled=false,orbitSpeed=90,orbitDist=8,orbitHeight=0,orbitLerp=0.3,orbitMode="Circle",orbitPredict=false,orbitPredStrength=0.2,orbitFaceTarget=true,orbitAutoLockDist=50}
local orbitAngle,orbitLocalElapsed,orbitCurrentRadius=0,0,0
local orbitConn=nil
local cfgD={predEnabled=false,predRadius=20,predDodgeDist=30,predCooldown=0.3,predThreshold=800,predMult=1}
local lastDodgeTick=0,predConn=nil
local cfgAA={enabled=false,mode="Spin",speed=5000,angle=90,randomSpeed=true,jitterPitch=true}
local aaAngleAccum,aaJitterState,aaRandomTimer,aaRandomMultiplier=0,0,0,1
local aaConn=nil
local riotCfg={speed=0.03,range=50,evadeRange=30,spinSpeed=180}
local riotTimer,riotAngle=0,0
local riotConn=nil
local riotAbuseCfg={height=3,forward=0,right=0,down=0,mode="Stick"}
local riotAbuseConn=nil
local projBypass={enabled=false,spoof=true,pred=true,expand=0.18,lerp=0.88,spd=90,predMult=1}
local projSpoofed=nil
local projHooked=false

local function SafeCall(fn,...)
    local ok,e=pcall(fn,...)
    if not ok then warn("[UUI] SafeCall:",e) end
    return ok
end
local function SaveAll()
    if not HAS_WRITEFILE then return false end
    return pcall(function() writefile(CONFIG_FILE,HS:JSONEncode(Saves)) end)
end
local function LoadAll()
    if not(isfile and readfile) then return end
    pcall(function() if isfile(CONFIG_FILE) then Saves=HS:JSONDecode(readfile(CONFIG_FILE)) end end)
end
local function AddSave(name)
    name=tostring(name or ""):gsub("^%s+",""):gsub("%s+$","")
    if name=="" then return false end
    local d={}
    for k,v in pairs(S) do d[k]=v end
    Saves[name]={time=os.date("%Y-%m-%d %H:%M:%S"),data=d}
    return SaveAll()
end
local function DeleteSave(name)
    if not Saves[name] then return false end
    Saves[name]=nil
    SaveAll()
    return true
end
local function ApplySave(name)
    local e=Saves[name]
    if not e or type(e.data)~="table" then return false end
    for k,v in pairs(e.data) do if S[k]~=nil and type(S[k])==type(v) then S[k]=v end end
    return true
end
LoadAll()

-- ============ 加速 ============
local RivalsBoost={Applied=false,Original={}}
local function GetRivalsItems()
    local ok,It=pcall(function() return require(game:GetService("ReplicatedStorage").Modules.ItemLibrary).Items end)
    return ok and typeof(It)=="table" and It or nil
end
local function ApplyRivalsBoost()
    if not IS_RIVALS then warn("[UUI] Boost 僅在 Rivals") return false end
    if RivalsBoost.Applied then return true end
    local Items=GetRivalsItems()
    if not Items then return false end
    RivalsBoost.Original={}
    local function Save(n,f,v) RivalsBoost.Original[n]=RivalsBoost.Original[n] or {} RivalsBoost.Original[n][f]=v end
    local gunExc={Sniper=true,Crossbow=true,Bow=true,RPG=true}
    for name,data in pairs(Items) do
        if typeof(data)=="table" and not gunExc[name] then
            for _,f in ipairs({"ShootSpread","ShootAccuracy","ShootRecoil"}) do if data[f] then Save(name,f,data[f]) data[f]=0 end end
            for _,f in ipairs({"ShootCooldown","ShootBurstCooldown"}) do if data[f] then Save(name,f,data[f]) data[f]=0.001 end end
        end
    end
    for name,data in pairs(Items) do
        if typeof(data)=="table" then
            for _,f in ipairs({"AttackCooldown","SwingCooldown","MeleeCooldown","Cooldown","RecoveryTime","ResetTime"}) do if data[f] then Save(name,f,data[f]) data[f]=0.001 end end
        end
    end
    RivalsBoost.Applied=true
    return true
end
local function RestoreRivalsBoost()
    if not RivalsBoost.Applied then return end
    local Items=GetRivalsItems()
    if Items then
        for name,fields in pairs(RivalsBoost.Original) do
            if typeof(Items[name])=="table" then for f,v in pairs(fields) do Items[name][f]=v end end
        end
    end
    RivalsBoost.Original={}
    RivalsBoost.Applied=false
end

-- ============ 皮肤(原样保留)============
local function SkinCloneCosmetic(CL,EL,name,cType,opt)
    local base=CL.Cosmetics[name]
    if not base then return nil end
    local d={} for k,v in pairs(base) do d[k]=v end
    d.Name=name d.Type=d.Type or cType d.Seed=d.Seed or math.random(1,1000000)
    if EL then local ok,id=pcall(EL.ToEnum,EL,name) if ok and id then d.Enum,d.ObjectID=id,d.ObjectID or id end end
    if opt then
        if opt.inverted~=nil then d.Inverted=opt.inverted end
        if opt.favoritesOnly~=nil then d.OnlyUseFavorites=opt.favoritesOnly end
    end
    return d
end
local function SkinSaveConfig()
    if not writefile then return end
    pcall(function()
        local c={equipped={},favorites=SkinFavorites}
        for w,cs in pairs(SkinEquipped) do
            c.equipped[w]={}
            for ct,cd in pairs(cs) do if cd and cd.Name then c.equipped[w][ct]={name=cd.Name,seed=cd.Seed,inverted=cd.Inverted} end end
        end
        pcall(function() makefolder("Rivals-Skinchanger") end)
        writefile(SkinSaveFile,HS:JSONEncode(c))
    end)
end
local function SkinLoadConfig(CL,EL)
    if not(readfile and isfile) then return end
    pcall(function()
        if not isfile(SkinSaveFile) then return end
        local c=HS:JSONDecode(readfile(SkinSaveFile))
        SkinFavorites=c.favorites or {}
        if c.equipped then
            for w,cs in pairs(c.equipped) do
                SkinEquipped[w]=SkinEquipped[w] or {}
                for ct,cd in pairs(cs) do
                    local cl=SkinCloneCosmetic(CL,EL,cd.name,ct,{inverted=cd.inverted})
                    if cl then cl.Seed=cd.seed SkinEquipped[w][ct]=cl end
                end
            end
        end
    end)
end
local function InstallSkinHooks()
    if SkinHooked then return true end
    if not HAS_HOOK then warn("[UUI] Skin 需要執行器") return false end
    if not IS_RIVALS then warn("[UUI] Skin 僅在 Rivals") return false end
    local RS=game:GetService("ReplicatedStorage")
    local ps=Player:FindFirstChild("PlayerScripts")
    if not ps then warn("[UUI] Skin 找不到 PlayerScripts") return false end
    local ctrl=ps:FindFirstChild("Controllers")
    if not ctrl then warn("[UUI] Skin 找不到 Controllers") return false end
    local okE,EL=pcall(function() return require(RS.Modules:WaitForChild("EnumLibrary",5)) end)
    if okE and EL and EL.WaitForEnumBuilder then pcall(function() EL:WaitForEnumBuilder() end) end
    local okC,CL=pcall(function() return require(RS.Modules:WaitForChild("CosmeticLibrary",5)) end)
    local okD,DC=pcall(function() return require(ctrl:WaitForChild("PlayerDataController",5)) end)
    if not(okC and CL) then warn("[UUI] Skin 找不到 CosmeticLibrary") return false end
    if not(okD and DC) then warn("[UUI] Skin 找不到 DataController") return false end
    SkinLoadConfig(CL,EL)
    local function isFin(c) if not c then return false end local t=c.Type return t=="Finisher" or t=="Finish" or (t and string.find(t:lower(),"finish")) end
    local function isEmo(c) if not c then return false end local t=c.Type return t=="Dance" or t=="Emote" end
    if CL.OwnsCosmetic then
        SkinOrig.OwnsCosmetic=CL.OwnsCosmetic
        CL.OwnsCosmetic=function(self,inv,name,w)
            if not SkinActive then return SkinOrig.OwnsCosmetic(self,inv,name,w) end
            if name:find("MISSING_") then return SkinOrig.OwnsCosmetic(self,inv,name,w) end
            if CL.Cosmetics[name] then return true end
            return SkinOrig.OwnsCosmetic(self,inv,name,w)
        end
    end
    if DC.Get then
        SkinOrig.DataGet=DC.Get
        DC.Get=function(self,key)
            local d=SkinOrig.DataGet(self,key)
            if not SkinActive then return d end
            if key=="CosmeticInventory" then
                local px={}
                if d then for k,v in pairs(d) do if CL.Cosmetics[k] then px[k]=v end end end
                return setmetatable(px,{__index=function(_,k) return CL.Cosmetics[k] and true or nil end})
            end
            if key=="FavoritedCosmetics" then
                local r=d and table.clone(d) or {}
                for w,fs in pairs(SkinFavorites) do
                    r[w]=r[w] or {}
                    for name,isF in pairs(fs) do if CL.Cosmetics[name] then r[w][name]=isF end end
                end
                return r
            end
            return d
        end
    end
    if DC.GetWeaponData then
        SkinOrig.GetWeaponData=DC.GetWeaponData
        DC.GetWeaponData=function(self,w)
            local d=SkinOrig.GetWeaponData(self,w)
            if not SkinActive or not d then return d end
            local m={} for k,v in pairs(d) do m[k]=v end
            m.Name=w
            if SkinEquipped[w] then for ct,cd in pairs(SkinEquipped[w]) do if ct~="Dances" then m[ct]=cd end end end
            return m
        end
    end
    local rem=RS:FindFirstChild("Remotes")
    local dr=rem and rem:FindFirstChild("Data")
    local er=dr and dr:FindFirstChild("EquipCosmetic")
    local fr=dr and dr:FindFirstChild("FavoriteCosmetic")
    if er and hookmetamethod then
        local old
        old=hookmetamethod(game,"__namecall",function(self,...)
            if not SkinActive then return old(self,...) end
            if getnamecallmethod()~="FireServer" then return old(self,...) end
            local args={...}
            if self==er then
                local w,ct,cn=args[1],args[2],args[3]
                local opt=args[4] or {}
                local cos=CL.Cosmetics[cn]
                if cos and (isFin(cos) or isEmo(cos)) then
                    if isEmo(cos) then
                        SkinEquipped.Dances=SkinEquipped.Dances or {}
                        if not cn or cn=="None" or cn=="" then SkinEquipped.Dances[ct]=nil
                        else local c=SkinCloneCosmetic(CL,EL,cn,ct,{inverted=opt.IsInverted,favoritesOnly=opt.OnlyUseFavorites}) if c then SkinEquipped.Dances[ct]=c end end
                    else
                        SkinEquipped[w]=SkinEquipped[w] or {}
                        if not cn or cn=="None" or cn=="" then
                            SkinEquipped[w][ct]=nil
                            if not next(SkinEquipped[w]) then SkinEquipped[w]=nil end
                        else local c=SkinCloneCosmetic(CL,EL,cn,ct,{inverted=opt.IsInverted,favoritesOnly=opt.OnlyUseFavorites}) if c then SkinEquipped[w][ct]=c end end
                    end
                    SkinSaveConfig()
                    return old(self,...)
                end
                if cn and cn~="None" and cn~="" then
                    local inv=DC:Get("CosmeticInventory")
                    if inv and rawget(inv,cn) then return old(self,...) end
                end
                SkinEquipped[w]=SkinEquipped[w] or {}
                if not cn or cn=="None" or cn=="" then
                    SkinEquipped[w][ct]=nil
                    if not next(SkinEquipped[w]) then SkinEquipped[w]=nil end
                else local c=SkinCloneCosmetic(CL,EL,cn,ct,{inverted=opt.IsInverted,favoritesOnly=opt.OnlyUseFavorites}) if c then SkinEquipped[w][ct]=c end end
                task.defer(function() pcall(function() DC.CurrentData:Replicate("WeaponInventory") end) task.wait(0.2) SkinSaveConfig() end)
                return
            end
            if self==fr then
                local cos=CL.Cosmetics[args[2]]
                if cos then
                    SkinFavorites[args[1]]=SkinFavorites[args[1]] or {}
                    SkinFavorites[args[1]][args[2]]=args[3] or nil
                    SkinSaveConfig()
                    task.spawn(function() pcall(function() DC.CurrentData:Replicate("FavoritedCosmetics") end) end)
                end
                return
            end
            return old(self,...)
        end)
    end
    local cw=nil
    local okCI,CI=pcall(function() return require(ps.Modules.ClientReplicatedClasses.ClientFighter.ClientItem) end)
    if okCI and CI and CI._CreateViewModel then
        SkinOrig.CreateViewModel=CI._CreateViewModel
        CI._CreateViewModel=function(self,vmr)
            if not SkinActive then return SkinOrig.CreateViewModel(self,vmr) end
            local w=self.Name
            local wp=self.ClientFighter and self.ClientFighter.Player
            cw=(wp==Player) and w or nil
            if wp==Player and SkinEquipped[w] and vmr then
                local dk=self:ToEnum("Data")
                local d=vmr[dk] or vmr.Data
                if d then
                    local sk=SkinEquipped[w].Skin
                    if sk then d[self:ToEnum("Skin")]=sk d[self:ToEnum("Name")]=sk.Name end
                    if SkinEquipped[w].Charm then d[self:ToEnum("Charm")]=SkinEquipped[w].Charm end
                    if SkinEquipped[w].Wrap then d[self:ToEnum("Wrap")]=SkinEquipped[w].Wrap end
                end
            end
            local r=SkinOrig.CreateViewModel(self,vmr)
            cw=nil
            return r
        end
    end
    local okVM,VM=pcall(function() return require(ps.Modules.ClientReplicatedClasses.ClientFighter.ClientItem.ClientViewModel) end)
    if okVM and VM and VM.new then
        SkinOrig.VMNew=VM.new
        VM.new=function(rd,ci)
            if not SkinActive then return SkinOrig.VMNew(rd,ci) end
            local wp=ci.ClientFighter and ci.ClientFighter.Player
            local w=cw or ci.Name
            if wp==Player and SkinEquipped[w] then
                local RC=require(RS.Modules.ReplicatedClass)
                local dk=RC:ToEnum("Data")
                rd[dk]=rd[dk] or {}
                local c=SkinEquipped[w]
                if c.Skin then rd[dk][RC:ToEnum("Skin")]=c.Skin end
                if c.Charm then rd[dk][RC:ToEnum("Charm")]=c.Charm end
                if c.Wrap then rd[dk][RC:ToEnum("Wrap")]=c.Wrap end
            end
            local r=SkinOrig.VMNew(rd,ci)
            if wp==Player and SkinEquipped[w] and SkinEquipped[w].Wrap and r._UpdateWrap then
                r:_UpdateWrap()
                task.delay(0.1,function() if not r._destroyed then r:_UpdateWrap() end end)
            end
            return r
        end
    end
    SkinHooked=true
    return true
end
local function StartSkin()
    if SkinHooked then SkinActive=true return true end
    if InstallSkinHooks() then SkinActive=true return true end
    return false
end
local function StopSkin() SkinActive=false end

-- ============ Ragebot ============
local function GetRageSlotNumber()
    if rageWeaponSlot=="Primary" then return 1 elseif rageWeaponSlot=="Secondary" then return 2 else return 3 end
end
local function LoadRageModules()
    if rageModules then return true end
    local ok,result=pcall(function()
        local RS=game:GetService("ReplicatedStorage")
        local ps=Player:FindFirstChild("PlayerScripts")
        if not ps then error("找不到 PlayerScripts") end
        local ctrl=ps:FindFirstChild("Controllers")
        if not ctrl then error("找不到 Controllers") end
        local FC=ctrl:FindFirstChild("FighterController")
        if not FC then error("找不到 FighterController") end
        local SC=ctrl:FindFirstChild("SpectateController")
        return {util=require(RS.Modules.Utility),enum=require(RS.Modules.EnumLibrary),FighterController=require(FC),SpectateController=SC and require(SC) or nil}
    end)
    if not ok then warn("[Ragebot] 模組載入失敗:",result) return false end
    rageModules=result
    return true
end
local function StartRagebot()
    if rageActive then return true end
    if not IS_RIVALS then warn("[Ragebot] 僅在 Rivals 中可用") return false end
    if not LoadRageModules() then return false end
    rageActive=true
    if rageEquipRunning then return true end
    rageEquipRunning=true
    task.spawn(function()
        while rageEquipRunning do
            task.wait(1)
            if not rageActive then break end
            if rageModules and rageModules.FighterController then
                local lf=rageModules.FighterController.LocalFighter
                if lf then pcall(function() lf:EquipItem(GetRageSlotNumber()) end) end
            end
        end
        rageEquipRunning=false
    end)
    return true
end
local function StopRagebot() rageActive=false end
local function UpdateRagebot()
    if not rageActive or not rageModules then return end
    if not Root or not Root.Parent then return end
    local util=rageModules.util
    local enum=rageModules.enum
    local FC=rageModules.FighterController
    local SC=rageModules.SpectateController
    if not FC then return end
    if FC.Objects then
        for _,fighterObj in FC.Objects do
            local player=fighterObj.Player
            if player then
                if not fighterObj.Entity or not fighterObj.Entity:IsAlive() or fighterObj:Get("IsSpectating") then rageDeflecting[player]=false
                else
                    local equipped=fighterObj.EquippedItem
                    local isKatana=equipped and equipped.ViewModel and equipped.ViewModel.Name=="Katana"
                    local isDef=false
                    if isKatana then isDef=(equipped._attack_cooldown and equipped._attack_cooldown>tick()) or false end
                    rageDeflecting[player]=isDef
                end
            end
        end
    end
    local function isEnemy(player)
        if player==Player then return false end
        if SC and SC.CurrentDuelSubject then
            local duel=SC.CurrentDuelSubject
            local localDueler=duel and duel:GetDueler(Player)
            local localTeam=localDueler and localDueler:Get("TeamID") or nil
            if localTeam and duel and duel.Duelers then
                for _,dueler in duel.Duelers do if dueler.Player==player then local team=dueler:Get("TeamID") return team~=localTeam end end
            end
        end
        local pTeam=player:GetAttribute("TeamID")
        local lTeam=Player:GetAttribute("TeamID")
        if pTeam and lTeam then return pTeam~=lTeam end
        return true
    end
    local closestPlayer,closestRoot,closestHead=nil,nil,nil
    local closestDist=500
    for _,plr in ipairs(Players:GetPlayers()) do
        if isEnemy(plr) then
            local pChar=plr.Character
            if pChar then
                local pRoot=pChar:FindFirstChild("HumanoidRootPart")
                local pHead=pChar:FindFirstChild("Head")
                local pHum=pChar:FindFirstChildWhichIsA("Humanoid")
                if pRoot and pHead and pHum and pHum.Health>0 then
                    local dd=(Root.Position-pRoot.Position).Magnitude
                    if dd<closestDist then closestDist=dd closestPlayer=plr closestRoot=pRoot closestHead=pHead end
                end
            end
        end
    end
    local function hasKnife(tp)
        if not tp then return false end
        local vm=workspace:FindFirstChild("ViewModels")
        if not vm then return false end
        for _,m in ipairs(vm:GetChildren()) do
            if m:IsA("Model") and string.find(m.Name,tp.Name,1,true) and string.find(m.Name,"Knife",1,true) then return true end
        end
        return false
    end
    local desyncCF=nil
    if closestRoot and closestHead then
        local desyncPos
        if hasKnife(closestPlayer) then desyncPos=(closestRoot.CFrame*CFrame.new(0,6,0)).Position
        else desyncPos=(closestRoot.CFrame*CFrame.new(0,1,2)).Position end
        desyncCF=CFrame.lookAt(desyncPos,closestHead.Position)
    end
    if desyncCF then
        local oldCF=Root.CFrame local oldVel=Root.Velocity local oldRotVel=Root.RotVelocity
        Root.CFrame=desyncCF
        RunService:BindToRenderStep("__rage_restore",101,function()
            if Root then Root.CFrame=oldCF Root.Velocity=oldVel Root.RotVelocity=oldRotVel end
            RunService:UnbindFromRenderStep("__rage_restore")
        end)
    end
    if not closestPlayer or not closestHead or not closestRoot then return end
    if rageDeflecting[closestPlayer] then return end
    local lf=FC.LocalFighter
    if not lf then return end
    local item=lf.EquippedItem
    if not item then return end
    if tick()-rageLastFire<rageFireRate then return end
    rageLastFire=tick()
    local originPos=desyncCF and desyncCF.Position or closestRoot.Position
    local targetPos=closestHead.Position
    local aimCF=CFrame.lookAt(originPos,targetPos)
    local targetCF=closestHead.CFrame
    local rnd=Vector3.new((math.random()-0.5)*0.1,(math.random()-0.5)*0.1,(math.random()-0.5)*0.1)
    local aimedPos=targetPos+rnd
    local objSpaceHeadOffset=closestHead.CFrame:ToObjectSpace(CFrame.new(aimedPos))
    local cameradata={}
    cameradata[utf8.char(1)]={[utf8.char(0)]=util:EncodeCFrame(aimCF),[utf8.char(1)]=util:EncodeCFrame(targetCF),[utf8.char(2)]=closestHead,[utf8.char(3)]=util:EncodeCFrame(objSpaceHeadOffset)}
    pcall(function()
        game:GetService("ReplicatedStorage").Remotes.Replication.Fighter.UseItem:FireServer(item:Get("ObjectID"),enum:ToEnum("StartShooting"),cameradata,nil)
    end)
end
Players.PlayerRemoving:Connect(function(p) rageDeflecting[p]=nil end)

-- ============ 新增功能实现 ============
-- VoidSpam
local function computeVoidDriftDir3D(t)
    local nx,ny,nz,amp,freq=0,0,0,1,0.0001
    for i=1,4 do nx=nx+math.noise(t*freq,0,0)*amp ny=ny+math.noise(0,t*freq,0)*amp nz=nz+math.noise(0,0,t*freq)*amp freq=freq*2.37 amp=amp*0.5 end
    local sp,cp=t*0.00073,t*0.00213
    nx=nx+math.noise(sp+13.7,7.3,0)*0.3+math.sin(cp)*math.cos(cp*1.618)*0.2
    ny=ny+math.noise(0,sp+31.1,17.9)*0.3+math.cos(cp*0.618)*math.sin(cp*2.718)*0.2
    nz=nz+math.noise(7.3,0,sp+11.5)*0.3+math.sin(cp*1.3)*math.cos(cp*0.7)*0.2
    local len=math.sqrt(nx*nx+ny*ny+nz*nz)
    if len<0.001 then return 1,0,0 end
    return nx/len,ny/len,nz/len
end
local function stepVoidDrift(dt)
    local m=CFG_V.METHOD
    if m=="Drift" then
        local dx,dy,dz=computeVoidDriftDir3D(voidElapsed)
        voidDriftDir=voidDriftDir:Lerp(Vector3.new(dx,dy,dz).Unit,0.98*dt*10)
        voidPos=voidPos+voidDriftDir*CFG_V.SPEED*dt
        if (voidPos-voidBasePos).Magnitude>CFG_V.RADIUS then voidPos=voidBasePos+(voidPos-voidBasePos).Unit*CFG_V.RADIUS voidDriftDir=-voidDriftDir end
        return voidPos
    elseif m=="Chaos" then
        voidPos=voidPos+Vector3.new((math.random()-0.5)*CFG_V.SPEED*dt*5,(math.random()-0.5)*CFG_V.SPEED*dt*5,(math.random()-0.5)*CFG_V.SPEED*dt*5)
        if (voidPos-voidBasePos).Magnitude>CFG_V.RADIUS then voidPos=voidBasePos+(voidPos-voidBasePos).Unit*CFG_V.RADIUS end
        return voidPos
    elseif m=="Loop" then
        local r=math.min(CFG_V.RADIUS*0.8,1e9+(voidElapsed%100)*1e7)
        return voidBasePos+Vector3.new(math.cos(voidElapsed*2)*r,math.sin(voidElapsed*1.3)*r*0.2,math.sin(voidElapsed*2)*r)
    elseif m=="Spiral" then
        local r=math.min(CFG_V.RADIUS*0.9,(voidElapsed%50)*2e9)
        return voidBasePos+Vector3.new(math.cos(voidElapsed*3)*r,math.sin(voidElapsed*0.5)*r*0.3,math.sin(voidElapsed*3)*r)
    else
        local r=CFG_V.RADIUS*(math.random()>0.5 and 1 or -1)
        return voidBasePos+Vector3.new(r,(math.random()-0.5)*CFG_V.RADIUS*0.2,r)+Vector3.new((math.random()-0.5)*CFG_V.RADIUS,0,(math.random()-0.5)*CFG_V.RADIUS)
    end
end
local function startVoidSpam()
    if voidConn then voidConn:Disconnect() voidConn=nil end
    if not GetCharacter() then return end
    voidPos=Vector3.new(Root.Position.X,CFG_V.BASE_ALTITUDE,Root.Position.Z)
    voidBasePos=Vector3.new(0,CFG_V.BASE_ALTITUDE,0)
    voidElapsed=0
    voidConn=RunService.Heartbeat:Connect(function(dt)
        if not S.VoidSpam then if voidConn then voidConn:Disconnect() voidConn=nil end return end
        if not GetCharacter() then return end
        voidElapsed=voidElapsed+dt
        local target=stepVoidDrift(dt)
        pcall(function()
            Root.CFrame=CFrame.new(target)
            Root.AssemblyLinearVelocity=Vector3.zero
            Root.AssemblyAngularVelocity=Vector3.zero
        end)
    end)
end
local function stopVoidSpam() if voidConn then voidConn:Disconnect() voidConn=nil end end

-- Orbit
local function startOrbit()
    if orbitConn then orbitConn:Disconnect() orbitConn=nil end
    if Humanoid then pcall(function() Humanoid:ChangeState(Enum.HumanoidStateType.Physics) end) end
    orbitAngle=0 orbitLocalElapsed=0 orbitCurrentRadius=cfgO.orbitDist
    orbitConn=RunService.Heartbeat:Connect(function(dt)
        if not S.Orbit then if orbitConn then orbitConn:Disconnect() orbitConn=nil end return end
        if not GetCharacter() then return end
        local target,best=nil,math.huge
        for _,p in ipairs(Players:GetPlayers()) do
            if p~=Player and p.Character then
                local hrp=p.Character:FindFirstChild("HumanoidRootPart")
                if hrp then local d=(Root.Position-hrp.Position).Magnitude if d<best then best=d target=p end end
            end
        end
        if not target or not target.Character then return end
        local hrp=target.Character:FindFirstChild("HumanoidRootPart")
        if not hrp then return end
        if (Root.Position-hrp.Position).Magnitude>cfgO.orbitAutoLockDist then return end
        local targetPos=hrp.Position
        if cfgO.orbitPredict then targetPos=targetPos+hrp.AssemblyLinearVelocity*cfgO.orbitPredStrength end
        orbitAngle=orbitAngle+math.rad(cfgO.orbitSpeed)*dt
        orbitLocalElapsed=orbitLocalElapsed+dt
        local r=cfgO.orbitDist local h=cfgO.orbitHeight local x,y,z=0,0,0
        if cfgO.orbitMode=="Circle" then x=math.cos(orbitAngle)*r z=math.sin(orbitAngle)*r y=h
        elseif cfgO.orbitMode=="Figure 8" then x=math.sin(orbitAngle)*r z=math.sin(orbitAngle)*math.cos(orbitAngle)*r*0.7 y=h
        elseif cfgO.orbitMode=="Spiral In" then orbitCurrentRadius=math.max(1,orbitCurrentRadius-(dt*2)) x=math.cos(orbitAngle)*orbitCurrentRadius z=math.sin(orbitAngle)*orbitCurrentRadius y=h
        elseif cfgO.orbitMode=="Spiral Out" then orbitCurrentRadius=math.min(cfgO.orbitDist*2,orbitCurrentRadius+(dt*2)) x=math.cos(orbitAngle)*orbitCurrentRadius z=math.sin(orbitAngle)*orbitCurrentRadius y=h
        elseif cfgO.orbitMode=="Bounce" then x=math.cos(orbitAngle)*r z=math.sin(orbitAngle)*r y=h+math.sin(orbitLocalElapsed*3)*5 end
        local dst=targetPos+Vector3.new(x,y,z)
        local smooth=Root.Position:Lerp(dst,cfgO.orbitLerp)
        pcall(function()
            if cfgO.orbitFaceTarget then Root.CFrame=CFrame.new(smooth,Vector3.new(targetPos.X,smooth.Y,targetPos.Z))
            else Root.CFrame=CFrame.new(smooth) end
        end)
    end)
end
local function stopOrbit() if orbitConn then orbitConn:Disconnect() orbitConn=nil end end

-- Prediction
local function startPrediction()
    if predConn then predConn:Disconnect() predConn=nil end
    lastDodgeTick=0
    predConn=RunService.Heartbeat:Connect(function(dt)
        if not S.Prediction then if predConn then predConn:Disconnect() predConn=nil end return end
        if not GetCharacter() then return end
        if Humanoid and Humanoid.Health<=0 then return end
        local myPos=Root.Position
        for _,p in ipairs(Players:GetPlayers()) do
            if p~=Player and p.Character then
                local hrp=p.Character:FindFirstChild("HumanoidRootPart")
                local vel=hrp and hrp.AssemblyLinearVelocity
                if hrp and vel and vel.Magnitude>cfgD.predThreshold then
                    local predictedPos=hrp.Position+vel*(dt*3*cfgD.predMult)
                    if (predictedPos-myPos).Magnitude<cfgD.predRadius and tick()-lastDodgeTick>cfgD.predCooldown then
                        lastDodgeTick=tick()
                        local perp=Vector3.new(-vel.Z,0,vel.X).Unit
                        local dir=math.random(0,1)==0 and perp or -perp
                        pcall(function() Root.CFrame=CFrame.new(myPos+dir*cfgD.predDodgeDist) end)
                        break
                    end
                end
            end
        end
    end)
end
local function stopPrediction() if predConn then predConn:Disconnect() predConn=nil end end

-- AntiAim
local function startAntiAim()
    if aaConn then aaConn:Disconnect() aaConn=nil end
    aaAngleAccum=0 aaJitterState=0
    aaConn=RunService.Heartbeat:Connect(function(dt)
        if not S.AntiAim then if aaConn then aaConn:Disconnect() aaConn=nil end return end
        if not GetCharacter() then return end
        local speed=cfgAA.speed
        if cfgAA.randomSpeed then
            aaRandomTimer=aaRandomTimer+dt
            if aaRandomTimer>0.1 then aaRandomTimer=0 aaRandomMultiplier=0.2+math.random()*0.8 end
            speed=speed*aaRandomMultiplier
        end
        pcall(function()
            if cfgAA.mode=="Spin" then
                aaAngleAccum=aaAngleAccum+speed*dt
                Root.CFrame=Root.CFrame*CFrame.Angles(0,math.rad(aaAngleAccum),0)
            elseif cfgAA.mode=="Jitter" then
                Root.CFrame=Root.CFrame*CFrame.Angles(math.rad(aaJitterState==0 and cfgAA.angle or -cfgAA.angle),math.rad(aaJitterState==0 and cfgAA.angle or -cfgAA.angle),0)
                aaJitterState=(aaJitterState+1)%2
            else
                Root.CFrame=Root.CFrame*CFrame.Angles(0,math.rad(cfgAA.angle),0)
            end
        end)
    end)
end
local function stopAntiAim() if aaConn then aaConn:Disconnect() aaConn=nil end end

-- Riot
local function startRiot()
    if riotConn then riotConn:Disconnect() riotConn=nil end
    riotTimer=0 riotAngle=0
    riotConn=RunService.Heartbeat:Connect(function(dt)
        if not S.Riot then if riotConn then riotConn:Disconnect() riotConn=nil end return end
        if not GetCharacter() then return end
        riotTimer=riotTimer+dt
        if riotTimer<riotCfg.speed then return end
        riotTimer=0
        local currentPos=Root.Position
        local target,best=nil,math.huge
        for _,p in ipairs(Players:GetPlayers()) do
            if p~=Player and p.Character then
                local hrp=p.Character:FindFirstChild("HumanoidRootPart")
                if hrp then local d=(currentPos-hrp.Position).Magnitude if d<best then best=d target=p end end
            end
        end
        local newPos=currentPos
        if target and target.Character then
            local hrp=target.Character:FindFirstChild("HumanoidRootPart")
            if hrp and (currentPos-hrp.Position).Magnitude<riotCfg.evadeRange then
                local dir=(currentPos-hrp.Position).Unit
                newPos=currentPos+dir*math.random(riotCfg.range*0.5,riotCfg.range*1.5)
            else
                local angle=math.random()*2*math.pi
                newPos=currentPos+Vector3.new(math.cos(angle)*math.random(riotCfg.range*0.2,riotCfg.range),math.random(-riotCfg.range*0.5,riotCfg.range*0.5),math.sin(angle)*math.random(riotCfg.range*0.2,riotCfg.range))
            end
        else
            local angle=math.random()*2*math.pi
            newPos=currentPos+Vector3.new(math.cos(angle)*math.random(riotCfg.range*0.2,riotCfg.range),math.random(-riotCfg.range*0.5,riotCfg.range*0.5),math.sin(angle)*math.random(riotCfg.range*0.2,riotCfg.range))
        end
        riotAngle=riotAngle+(riotCfg.spinSpeed*dt)
        if riotAngle>=360 then riotAngle=riotAngle-360 end
        pcall(function()
            Root.CFrame=CFrame.new(newPos)*CFrame.Angles(0,math.rad(riotAngle),0)
            Root.AssemblyLinearVelocity=Vector3.zero
        end)
    end)
end
local function stopRiot() if riotConn then riotConn:Disconnect() riotConn=nil end end

-- Riot Abuse
local function startRiotAbuse()
    if riotAbuseConn then riotAbuseConn:Disconnect() riotAbuseConn=nil end
    riotAbuseConn=RunService.Heartbeat:Connect(function()
        if not S.RiotAbuse then if riotAbuseConn then riotAbuseConn:Disconnect() riotAbuseConn=nil end return end
        if not GetCharacter() then return end
        local target,best=nil,math.huge
        for _,p in ipairs(Players:GetPlayers()) do
            if p~=Player and p.Character then
                local hrp=p.Character:FindFirstChild("HumanoidRootPart")
                if hrp then local d=(Root.Position-hrp.Position).Magnitude if d<best then best=d target=p end end
            end
        end
        if not target or not target.Character then return end
        local targetRoot=target.Character:FindFirstChild("HumanoidRootPart")
        if not targetRoot then return end
        local offset=Vector3.new(riotAbuseCfg.right,riotAbuseCfg.height-riotAbuseCfg.down,riotAbuseCfg.forward)
        local targetPos=targetRoot.Position+offset
        pcall(function()
            if riotAbuseCfg.mode=="Stick" then Root.CFrame=CFrame.new(targetPos)
            else
                local bounceOffset=math.abs(math.sin(tick()*8))*math.abs(riotAbuseCfg.height)
                Root.CFrame=CFrame.new(targetRoot.Position+Vector3.new(riotAbuseCfg.right,bounceOffset-riotAbuseCfg.down,riotAbuseCfg.forward))
            end
            Root.AssemblyLinearVelocity=Vector3.zero
        end)
    end)
end
local function stopRiotAbuse() if riotAbuseConn then riotAbuseConn:Disconnect() riotAbuseConn=nil end end

-- Projectile Bypass
local function predictTarget(targetRoot,origin)
    local vel=targetRoot.AssemblyLinearVelocity
    local prevVel=targetRoot:GetAttribute("PrevVel") or vel
    local accel=(vel-prevVel)/0.1
    targetRoot:SetAttribute("PrevVel",vel)
    local dist=(origin-targetRoot.Position).Magnitude
    local time=(dist/projBypass.spd)*projBypass.predMult
    return targetRoot.Position+vel*time+0.5*accel*time*time
end
local function expandPosition(pos)
    local cam=workspace.CurrentCamera
    if not cam then return pos end
    return pos+(pos-cam.CFrame.Position).Unit*projBypass.expand
end
local function tickProjSpoof()
    if not S.ProjBypass then return end
    local cam=workspace.CurrentCamera
    if not cam then return end
    local orig=cam.CFrame.Position
    local best,bestRoot=nil,math.huge
    for _,p in ipairs(Players:GetPlayers()) do
        if p~=Player and p.Character then
            local hrp=p.Character:FindFirstChild("HumanoidRootPart")
            local hum=p.Character:FindFirstChildOfClass("Humanoid")
            if hrp and hum and hum.Health>0 then
                local d=(orig-hrp.Position).Magnitude
                if d<best then best=d bestRoot=hrp end
            end
        end
    end
    if bestRoot then
        local dist=(orig-bestRoot.Position).Magnitude
        local pos=orig+(bestRoot.Position-orig).Unit*(dist*0.5)
        projSpoofed=CFrame.new(pos,bestRoot.Position)
    else
        projSpoofed=CFrame.new(orig,cam.CFrame.LookVector)
    end
end
local function tickProjAim()
    if not S.ProjBypass or not projBypass.spoof then return end
    local cam=workspace.CurrentCamera
    if not cam then return end
    local best,bestRoot=nil,math.huge
    for _,p in ipairs(Players:GetPlayers()) do
        if p~=Player and p.Character then
            local hrp=p.Character:FindFirstChild("HumanoidRootPart")
            local hum=p.Character:FindFirstChildOfClass("Humanoid")
            if hrp and hum and hum.Health>0 then
                local d=(cam.CFrame.Position-hrp.Position).Magnitude
                if d<best then best=d bestRoot=hrp end
            end
        end
    end
    if not bestRoot then return end
    local origin=cam.CFrame.Position
    local aim=expandPosition(projBypass.pred and predictTarget(bestRoot,origin) or bestRoot.Position)
    local dir=(aim-origin).Unit
    cam.CFrame=cam.CFrame:Lerp(CFrame.new(origin,origin+dir),projBypass.lerp)
end
local function hookRemoteEvents()
    if projHooked then return end
    projHooked=true
    local remotes=game:GetService("ReplicatedStorage"):FindFirstChild("Remotes")
    if not remotes then return end
    for _,r in ipairs(remotes:GetDescendants()) do
        if r:IsA("RemoteEvent") and not r:GetAttribute("_uui_hooked") then
            r:SetAttribute("_uui_hooked",true)
            local oldFire=r.FireServer
            r.FireServer=function(self,data,...)
                if S.ProjBypass and projBypass.spoof and type(data)=="table" and projSpoofed then
                    local sc=projSpoofed
                    if data.Origin~=nil then data.Origin=sc.Position end
                    if data.Position~=nil then data.Position=sc.Position end
                    if data.CFrame~=nil then data.CFrame=sc end
                    if data.LookDir~=nil then data.LookDir=sc.LookVector end
                    if data.Source~=nil then data.Source=sc.Position end
                    if data.Spread~=nil then data.Spread=0 end
                end
                return oldFire(self,data,...)
            end
        end
    end
end
local projLoop=nil
local function startProjBypass()
    projBypass.enabled=true
    task.spawn(hookRemoteEvents)
    if projLoop then projLoop:Disconnect() projLoop=nil end
    projLoop=RunService.RenderStepped:Connect(function()
        if not S.ProjBypass then if projLoop then projLoop:Disconnect() projLoop=nil end return end
        pcall(tickProjSpoof)
        pcall(tickProjAim)
    end)
end
local function stopProjBypass()
    projBypass.enabled=false
    if projLoop then projLoop:Disconnect() projLoop=nil end
    projSpoofed=nil
end

-- ============ 遁地/虚空(原样保留)============
local function SetUndergroundNoclip(en)
    if not Character then return end
    for _,p in ipairs(Character:GetDescendants()) do
        if p:IsA("BasePart") then
            if en then
                if SavedCollision[p]==nil then SavedCollision[p]=p.CanCollide end
                p.CanCollide=false
            else
                local o=SavedCollision[p]
                if o~=nil then p.CanCollide=o SavedCollision[p]=nil end
            end
        end
    end
end
local function StartUnderground()
    if not Root or not Root.Parent then return end
    UndergroundStartCFrame=Root.CFrame S.Underground=true
    SetUndergroundNoclip(true)
    Root.CFrame=UndergroundStartCFrame*CFrame.new(0,-math.abs(S.UndergroundDistance),0)
    Root.AssemblyLinearVelocity=Vector3.zero Root.AssemblyAngularVelocity=Vector3.zero
end
local function StopUnderground()
    S.Underground=false
    if Root and Root.Parent then
        if UndergroundStartCFrame then
            local rot=Root.CFrame-Root.Position
            Root.CFrame=CFrame.new(UndergroundStartCFrame.Position)*rot
        end
        Root.AssemblyLinearVelocity=Vector3.zero Root.AssemblyAngularVelocity=Vector3.zero
        SetUndergroundNoclip(false)
    end
    UndergroundStartCFrame=nil
end
local function StartVoidToggle()
    if VoidToggleActive then return end
    if not GetCharacter() then return end
    S.VoidToggle=true VoidToggleActive=true
    if S.Underground then StopUnderground() if ControlRefs.Underground then ControlRefs.Underground.Set(false) end end
    VoidToggleBase=Root.Position
    VoidToggleRightVector=Root.CFrame.RightVector
    VoidToggleStart=os.clock()
    SetUndergroundNoclip(true)
    task.spawn(function()
        while VoidToggleActive do
            task.wait()
            if not VoidToggleActive then break end
            if GetCharacter() and Root and Root.Parent and VoidToggleBase and VoidToggleRightVector then
                local el=os.clock()-VoidToggleStart
                local off=math.sin(el*S.VoidToggleLRSpeed)*math.abs(S.VoidToggleLRDistance)
                local rot=Root.CFrame-Root.Position
                local targetPos=VoidToggleBase+Vector3.new(0,-math.abs(S.VoidToggleDepth),0)+VoidToggleRightVector*off
                Root.CFrame=CFrame.new(targetPos)*rot
                Root.AssemblyLinearVelocity=Vector3.zero Root.AssemblyAngularVelocity=Vector3.zero
            end
        end
        if GetCharacter() and Root and Root.Parent and VoidToggleBase then
            local rot=Root.CFrame-Root.Position
            Root.CFrame=CFrame.new(VoidToggleBase)*rot
            Root.AssemblyLinearVelocity=Vector3.zero Root.AssemblyAngularVelocity=Vector3.zero
        end
        VoidToggleBase=nil VoidToggleRightVector=nil
        if not(S.Underground or S.VoidStrike) then SetUndergroundNoclip(false) end
    end)
end
local function StopVoidToggleLoop() VoidToggleActive=false end
local function StopVoidToggle() VoidToggleActive=false S.VoidToggle=false end

-- ============ 准心 / DeltaAim ============
local function Corner(o,r) local c=Instance.new("UICorner") c.CornerRadius=UDim.new(0,r or 8) c.Parent=o end
local function Stroke(o) local s=Instance.new("UIStroke") s.Thickness=1 s.Transparency=0.35 s.Parent=o end
local function StartCrosshair()
    if CrosshairGui and CrosshairGui.Parent then return end
    CrosshairGui=nil
    local SG,RAD,TH=60,26,1.5
    local sg=Instance.new("ScreenGui") sg.Name="UUI_Crosshair" sg.ResetOnSpawn=false sg.IgnoreGuiInset=true sg.DisplayOrder=90 sg.Parent=PlayerGui
    local c=Instance.new("Frame") c.Size=UDim2.new(0,0,0,0) c.Position=UDim2.new(0.5,0,0.5,0) c.BackgroundTransparency=1 c.Parent=sg
    local ct=Instance.new("Frame") ct.Size=UDim2.fromOffset(SG,SG) ct.AnchorPoint=Vector2.new(0.5,0.5) ct.BackgroundTransparency=1 ct.Parent=c
    local sc=Instance.new("UIScale") sc.Scale=1 sc.Parent=ct
    local ls={}
    local function mk(x1,y1,x2,y2)
        local dx,dy=x2-x1,y2-y1
        local ln=math.sqrt(dx*dx+dy*dy)
        local f=Instance.new("Frame")
        f.Size=UDim2.new(0,ln,0,TH) f.AnchorPoint=Vector2.new(0.5,0.5) f.Position=UDim2.new(0.5,(x1+x2)/2,0.5,(y1+y2)/2) f.Rotation=math.deg(math.atan2(dy,dx)) f.BorderSizePixel=0 f.BackgroundColor3=Color3.new(1,1,1) f.Parent=ct
        table.insert(ls,f)
    end
    local function vt(a) local r=math.rad(a) return math.cos(r)*RAD,math.sin(r)*RAD end
    local function tri(as) local p={} for i=1,3 do p[i]={vt(as[i])} end for i=1,3 do local a,b=p[i],p[i%3+1] mk(a[1],a[2],b[1],b[2]) end end
    tri({-90,30,150}) tri({90,210,330})
    local dt=Instance.new("Frame") dt.Size=UDim2.fromOffset(3,3) dt.AnchorPoint=Vector2.new(0.5,0.5) dt.Position=UDim2.new(0.5,0,0.5,0) dt.BackgroundColor3=Color3.new(1,1,1) dt.BorderSizePixel=0 dt.Parent=ct
    Corner(dt,100)
    local lb=Instance.new("TextLabel") lb.Size=UDim2.fromOffset(120,20) lb.AnchorPoint=Vector2.new(0.5,0) lb.Position=UDim2.new(0,0,0,40) lb.BackgroundTransparency=1 lb.Text="delta.316" lb.Font=Enum.Font.Arcade lb.TextSize=14 lb.Parent=c
    local hue,ang,wv=0,0,0
    CrosshairConnection=RunService.RenderStepped:Connect(function(d)
        hue=(hue+d*0.25)%1
        local col=Color3.fromHSV(hue,1,1)
        for _,l in ipairs(ls) do l.BackgroundColor3=col end
        dt.BackgroundColor3=col lb.TextColor3=col
        ang=(ang+d*45)%360 ct.Rotation=ang
        wv=wv+d*5 sc.Scale=1+((math.sin(wv)+1)/2)*0.15
    end)
    CrosshairGui=sg
end
local function StopCrosshair()
    if CrosshairConnection then CrosshairConnection:Disconnect() CrosshairConnection=nil end
    if CrosshairGui then CrosshairGui:Destroy() CrosshairGui=nil end
end
local function ClearDAH()
    for _,p in ipairs(Players:GetPlayers()) do
        if p~=Player and p.Character then
            local h=p.Character:FindFirstChild("DeltaAimHighlight")
            if h then h:Destroy() end
        end
    end
end
local function StartDeltaAim()
    if DeltaAimGui and DeltaAimGui.Parent then return end
    DeltaAimGui=nil
    local MG,mG,PL,SP=12,4,5,200
    local sg=Instance.new("ScreenGui") sg.Name="UUI_DeltaAim" sg.ResetOnSpawn=false sg.IgnoreGuiInset=true sg.DisplayOrder=91 sg.Parent=PlayerGui
    local c=Instance.new("Frame") c.Size=UDim2.new(0,0,0,0) c.Position=UDim2.new(0.5,0,0.5,0) c.BackgroundTransparency=1 c.Parent=sg
    local ct=Instance.new("Frame") ct.Size=UDim2.fromOffset(60,60) ct.AnchorPoint=Vector2.new(0.5,0.5) ct.BackgroundTransparency=1 ct.Parent=c
    local lb=Instance.new("TextLabel") lb.Size=UDim2.fromOffset(100,20) lb.AnchorPoint=Vector2.new(0.5,0) lb.Position=UDim2.new(0,0,0,22) lb.BackgroundTransparency=1 lb.Text="delta.316" lb.Font=Enum.Font.Arcade lb.TextSize=14 lb.Parent=c
    local function mk(w,h) local f=Instance.new("Frame") f.Size=UDim2.fromOffset(w,h) f.BorderSizePixel=0 f.Parent=ct return f end
    local t,b,l,r=mk(1,14),mk(1,14),mk(14,1),mk(14,1)
    local hue,ang,wv=0,0,0
    DeltaAimConnection=RunService.RenderStepped:Connect(function(d)
        local cam=workspace.CurrentCamera
        if not cam then return end
        local sh=cam.ViewportSize.Y
        hue=(hue+d*0.25)%1
        local col=Color3.fromHSV(hue,1,1)
        t.BackgroundColor3=col b.BackgroundColor3=col l.BackgroundColor3=col r.BackgroundColor3=col lb.TextColor3=col
        ang=(ang+d*SP)%360 ct.Rotation=ang
        wv=wv+d*PL
        local aa=(math.sin(wv)+1)/2
        local gp=mG+aa*(MG-mG)
        t.Position=UDim2.new(0.5,-0.5,0.5,-(14+gp))
        b.Position=UDim2.new(0.5,-0.5,0.5,gp)
        l.Position=UDim2.new(0.5,-(14+gp),0.5,-0.5)
        r.Position=UDim2.new(0.5,gp,0.5,-0.5)
        local cl=nil local bA=math.huge
        for _,p in ipairs(Players:GetPlayers()) do
            if p~=Player and p.Character then
                local rr=p.Character:FindFirstChild("HumanoidRootPart") or p.Character:FindFirstChild("Head")
                if rr then
                    local _,ons=cam:WorldToViewportPoint(rr.Position)
                    if ons then
                        local dir=(rr.Position-cam.CFrame.Position).Unit
                        local a=math.acos(math.clamp(cam.CFrame.LookVector:Dot(dir),-1,1))
                        if a<bA then bA=a cl=p.Character end
                    end
                end
            end
        end
        for _,p in ipairs(Players:GetPlayers()) do
            if p~=Player and p.Character then
                local ch=p.Character
                local rr=ch:FindFirstChild("HumanoidRootPart") or ch:FindFirstChild("Head")
                if rr then
                    local pos,ons=cam:WorldToViewportPoint(rr.Position)
                    if ons then
                        local bs=(sh/pos.Z)*1.8
                        local w,h=bs*0.7,bs*1.3
                        if not DeltaAimBoxes[p] then
                            local bx=Instance.new("Frame") bx.BackgroundTransparency=1 bx.BorderSizePixel=0 bx.Parent=sg
                            local st=Instance.new("UIStroke") st.Color=Color3.fromRGB(255,105,180) st.Thickness=1 st.Parent=bx
                            DeltaAimBoxes[p]=bx
                        end
                        local bx=DeltaAimBoxes[p]
                        bx.Visible=true bx.Size=UDim2.fromOffset(w,h) bx.Position=UDim2.new(0,pos.X-w/2,0,pos.Y-w/2)
                        local hl=ch:FindFirstChild("DeltaAimHighlight")
                        if not hl then hl=Instance.new("Highlight") hl.Name="DeltaAimHighlight" hl.DepthMode=Enum.HighlightDepthMode.AlwaysOnTop hl.Parent=ch end
                        if ch==cl then hl.FillColor=Color3.fromRGB(255,20,147) hl.FillTransparency=0.4 hl.OutlineColor=Color3.new(1,1,1) hl.OutlineTransparency=0 hl.Enabled=true
                        else hl.Enabled=false end
                    else
                        if DeltaAimBoxes[p] then DeltaAimBoxes[p].Visible=false end
                        local hl=ch:FindFirstChild("DeltaAimHighlight") if hl then hl.Enabled=false end
                    end
                else
                    if DeltaAimBoxes[p] then DeltaAimBoxes[p].Visible=false end
                end
            else
                if DeltaAimBoxes[p] then DeltaAimBoxes[p]:Destroy() DeltaAimBoxes[p]=nil end
            end
        end
    end)
    DeltaAimGui=sg
end
local function StopDeltaAim()
    if DeltaAimConnection then DeltaAimConnection:Disconnect() DeltaAimConnection=nil end
    for _,b in pairs(DeltaAimBoxes) do if b then b:Destroy() end end
    DeltaAimBoxes={} ClearDAH()
    if DeltaAimGui then DeltaAimGui:Destroy() DeltaAimGui=nil end
end

-- ============ ESP(修复版)============
local ESPGui=nil
local function GetESPGui()
    if ESPGui and ESPGui.Parent then return ESPGui end
    ESPGui=Instance.new("ScreenGui")
    ESPGui.Name="UUI_ESP_Container"
    ESPGui.ResetOnSpawn=false
    ESPGui.IgnoreGuiInset=true
    ESPGui.DisplayOrder=50
    ESPGui.Parent=PlayerGui
    return ESPGui
end
local function RemoveESP(p)
    local o=ESPObjects[p]
    if o then
        if o.Highlight then pcall(function() o.Highlight:Destroy() end) end
        if o.Billboard then pcall(function() o.Billboard:Destroy() end) end
        ESPObjects[p]=nil
    end
end
local function CreateESP(p)
    if p==Player or not S.ESP then return end
    RemoveESP(p)
    local ch=p.Character
    if not ch then return end
    local rr=ch:FindFirstChild("HumanoidRootPart")
    local hm=ch:FindFirstChildOfClass("Humanoid")
    if not rr or not hm then return end
    local hl=Instance.new("Highlight")
    hl.Adornee=ch hl.FillColor=Color3.fromRGB(255,60,60) hl.OutlineColor=Color3.new(1,1,1)
    hl.FillTransparency=0.65 hl.DepthMode=Enum.HighlightDepthMode.AlwaysOnTop hl.Parent=ch
    local bb=Instance.new("BillboardGui")
    bb.Adornee=rr bb.Size=UDim2.fromOffset(180,76) bb.StudsOffset=Vector3.new(0,3.5,0)
    bb.AlwaysOnTop=true bb.MaxDistance=10000 bb.ResetOnSpawn=false
    bb.Parent=GetESPGui()
    local function mk(y,cl)
        local l=Instance.new("TextLabel") l.Size=UDim2.new(1,0,0,19) l.Position=UDim2.fromOffset(0,y)
        l.BackgroundTransparency=1 l.TextColor3=cl l.TextStrokeTransparency=0 l.TextSize=13
        l.Font=Enum.Font.GothamBold l.Parent=bb return l
    end
    local nL=mk(0,Color3.new(1,1,1))
    local dL=mk(19,Color3.fromRGB(100,220,255))
    local hL=mk(38,Color3.fromRGB(100,255,120))
    local bg=Instance.new("Frame") bg.Size=UDim2.new(0.8,0,0,7) bg.Position=UDim2.new(0.1,0,0,61) bg.BackgroundColor3=Color3.fromRGB(45,45,45) bg.BorderSizePixel=0 bg.Parent=bb
    Corner(bg,5)
    local bar=Instance.new("Frame") bar.Size=UDim2.new(1,0,1,0) bar.BackgroundColor3=Color3.fromRGB(50,220,80) bar.BorderSizePixel=0 bar.Parent=bg
    Corner(bar,5)
    ESPObjects[p]={Highlight=hl,Billboard=bb,NameLabel=nL,DistanceLabel=dL,HealthLabel=hL,HealthBar=bar,HealthBackground=bg}
end
local function UpdateESP()
    if not S.ESP then for p in pairs(ESPObjects) do RemoveESP(p) end return end
    if not GetCharacter() then return end
    for _,p in ipairs(Players:GetPlayers()) do
        if p~=Player then
            local ch=p.Character
            local rr=ch and ch:FindFirstChild("HumanoidRootPart")
            local hm=ch and ch:FindFirstChildOfClass("Humanoid")
            if rr and hm then
                -- 檢查舊 ESP 是否失效(重生後 highlight 掛的 character 已換)
                local o=ESPObjects[p]
                if o and (not o.Highlight.Parent or not o.Billboard.Parent or o.Highlight.Adornee~=ch) then
                    RemoveESP(p) o=nil
                end
                if not o then CreateESP(p) o=ESPObjects[p] end
                if o then
                    local ds=(Root.Position-rr.Position).Magnitude
                    local hp=hm.Health
                    local mh=math.max(hm.MaxHealth,1)
                    o.NameLabel.Visible=S.ESPName o.DistanceLabel.Visible=S.ESPDistance o.HealthLabel.Visible=S.ESPHealth o.HealthBackground.Visible=S.ESPHealthBar
                    o.NameLabel.Text=p.DisplayName
                    o.DistanceLabel.Text=string.format("%.0f studs",ds)
                    o.HealthLabel.Text=string.format("HP:%.0f / %.0f",hp,mh)
                    o.HealthBar.Size=UDim2.new(math.clamp(hp/mh,0,1),0,1,0)
                end
            else RemoveESP(p) end
        end
    end
end
Players.PlayerRemoving:Connect(RemoveESP)

local function UpdateMovement(d)
    if not GetCharacter() then return end
    if VoidToggleActive then return end
    if S.VoidSpam then return end -- VoidSpam 自己接管 CFrame
    if S.Orbit or S.Riot or S.RiotAbuse or S.AntiAim then return end -- 這些功能也會接管 CFrame
    if S.VoidStrike then
        local tgt,tP=nil,nil
        local dst=math.huge
        for _,p in ipairs(Players:GetPlayers()) do
            if p~=Player and p.Character then
                local r=p.Character:FindFirstChild("HumanoidRootPart")
                local h=p.Character:FindFirstChildOfClass("Humanoid")
                if r and h and h.Health>0 then
                    local dd=(Root.Position-r.Position).Magnitude
                    if dd<dst then dst=dd tgt=p.Character tP=r end
                end
            end
        end
        if tP then
            VoidAngle=(VoidAngle+45)%360
            local dp=-math.abs(S.VoidDepth)
            Root.CFrame=tP.CFrame*CFrame.new(0,dp,0)*CFrame.Angles(0,math.rad(VoidAngle),0)
            Root.AssemblyLinearVelocity=Vector3.zero Root.AssemblyAngularVelocity=Vector3.zero
            return
        end
    end
    local pos=Root.Position
    local rot=Root.CFrame-Root.Position
    if S.Underground and UndergroundStartCFrame then
        pos=Vector3.new(pos.X,UndergroundStartCFrame.Position.Y-math.abs(S.UndergroundDistance),pos.Z)
    end
    Root.CFrame=CFrame.new(pos)*rot
    if S.Underground then
        local v=Root.AssemblyLinearVelocity
        Root.AssemblyLinearVelocity=Vector3.new(v.X,0,v.Z) Root.AssemblyAngularVelocity=Vector3.zero
    end
end

-- ============ UI 初始化 ============
local old=PlayerGui:FindFirstChild("UndergroundMobileUI")
if old then old:Destroy() end
local Gui=Instance.new("ScreenGui")
Gui.Name="UndergroundMobileUI" Gui.ResetOnSpawn=false Gui.IgnoreGuiInset=true Gui.DisplayOrder=100 Gui.ZIndexBehavior=Enum.ZIndexBehavior.Sibling Gui.Parent=PlayerGui

local OB=Instance.new("TextButton")
OB.Size=UDim2.fromOffset(54,54) OB.Position=UDim2.new(0,15,0.5,-27) OB.BackgroundColor3=Color3.fromRGB(35,35,35) OB.BorderSizePixel=0 OB.Text="☰" OB.TextSize=27 OB.TextColor3=Color3.new(1,1,1) OB.Font=Enum.Font.GothamBold OB.Parent=Gui
Corner(OB,100) Stroke(OB)

local Panel=Instance.new("Frame")
Panel.Size=UDim2.fromOffset(340,390) Panel.Position=UDim2.new(0.5,-170,0.5,-195) Panel.BackgroundColor3=Color3.fromRGB(25,25,25) Panel.BorderSizePixel=0 Panel.Visible=false Panel.ClipsDescendants=true Panel.Parent=Gui
Corner(Panel,12) Stroke(Panel)
local function UpdatePanelSize()
    local cam=workspace.CurrentCamera
    if not cam then return end
    local vp=cam.ViewportSize
    local w=math.max(250,math.min(vp.X*0.94,620))
    local h=math.max(260,math.min(vp.Y*0.48,420))
    Panel.Size=UDim2.fromOffset(w,h)
    Panel.Position=UDim2.new(0.5,-w/2,0.5,-h/2)
end
UpdatePanelSize()
workspace:GetPropertyChangedSignal("CurrentCamera"):Connect(function() task.wait() UpdatePanelSize() end)

local Header=Instance.new("TextLabel")
Header.Size=UDim2.new(1,-55,0,36) Header.Position=UDim2.fromOffset(10,0) Header.BackgroundTransparency=1 Header.Text="Underground Mobile UI" Header.TextColor3=Color3.new(1,1,1) Header.TextSize=15 Header.Font=Enum.Font.GothamBold Header.TextXAlignment=Enum.TextXAlignment.Left Header.Active=true Header.Parent=Panel

local CB=Instance.new("TextButton")
CB.Size=UDim2.fromOffset(38,34) CB.Position=UDim2.new(1,-42,0,1) CB.BackgroundTransparency=1 CB.Text="×" CB.TextSize=27 CB.TextColor3=Color3.new(1,1,1) CB.Parent=Panel
CB.Activated:Connect(function() Panel.Visible=false end)
OB.Activated:Connect(function() Panel.Visible=not Panel.Visible end)

local Pages,TabButtons={},{}
local TF=Instance.new("Frame")
TF.Size=UDim2.new(1,-12,0,34) TF.Position=UDim2.fromOffset(6,37) TF.BackgroundTransparency=1 TF.Parent=Panel
for i=1,7 do
    local tab=Instance.new("TextButton")
    tab.Size=UDim2.new(1/7,-4,1,0) tab.Position=UDim2.new((i-1)/7,0,0,0) tab.BackgroundColor3=i==1 and Color3.fromRGB(45,100,160) or Color3.fromRGB(45,45,45) tab.BorderSizePixel=0 tab.Text=i.."" tab.TextColor3=Color3.new(1,1,1) tab.TextSize=13 tab.Parent=TF
    Corner(tab,6)
    local page=Instance.new("ScrollingFrame")
    page.Size=UDim2.new(1,-14,1,-78) page.Position=UDim2.fromOffset(7,74) page.BackgroundTransparency=1 page.BorderSizePixel=0 page.ScrollBarThickness=4 page.ScrollBarImageColor3=Color3.fromRGB(120,120,120) page.ScrollingDirection=Enum.ScrollingDirection.Y page.ElasticBehavior=Enum.ElasticBehavior.WhenScrollable page.CanvasSize=UDim2.new(0,0,0,2000) page.Visible=i==1 page.Active=true page.Parent=Panel
    local l=Instance.new("UIListLayout") l.Padding=UDim.new(0,5) l.SortOrder=Enum.SortOrder.LayoutOrder l.Parent=page
    local p=Instance.new("UIPadding") p.PaddingTop=UDim.new(0,3) p.PaddingBottom=UDim.new(0,12) p.PaddingLeft=UDim.new(0,3) p.PaddingRight=UDim.new(0,3) p.Parent=page
    l:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function() page.CanvasSize=UDim2.new(0,0,0,math.max(l.AbsoluteContentSize.Y+20,500)) end)
    Pages[i]=page TabButtons[i]=tab
    tab.Activated:Connect(function()
        for n=1,7 do Pages[n].Visible=(n==i) TabButtons[n].BackgroundColor3=(n==i) and Color3.fromRGB(45,100,160) or Color3.fromRGB(45,45,45) end
    end)
end

local Scroll
local function UsePage(n) Scroll=Pages[n] end

local function AddTitle(txt)
    local t=Instance.new("TextLabel")
    t.Size=UDim2.new(1,-4,0,24) t.BackgroundTransparency=1 t.Text=txt t.TextColor3=Color3.fromRGB(150,200,255) t.TextSize=14 t.Font=Enum.Font.GothamBold t.TextXAlignment=Enum.TextXAlignment.Left t.Parent=Scroll
end
local function AddToggle(key,label,init,cb)
    local val=init
    local btn=Instance.new("TextButton")
    btn.Size=UDim2.new(1,-4,0,36) btn.BorderSizePixel=0 btn.TextColor3=Color3.new(1,1,1) btn.TextSize=14 btn.Parent=Scroll
    Corner(btn,7)
    local function upd()
        btn.Text=label..":"..(val and "開啟" or "關閉")
        btn.BackgroundColor3=val and Color3.fromRGB(35,120,70) or Color3.fromRGB(45,45,45)
    end
    upd()
    btn.Activated:Connect(function() val=not val upd() SafeCall(cb,val) end)
    ControlRefs[key]={Set=function(v) val=v upd() end}
end
local function AddInput(key,label,init,hint,mn,mx,cb)
    local val=init
    local fr=Instance.new("Frame")
    fr.Size=UDim2.new(1,-4,0,62) fr.BackgroundColor3=Color3.fromRGB(38,38,38) fr.BorderSizePixel=0 fr.Parent=Scroll
    Corner(fr,7)
    local ti=Instance.new("TextLabel")
    ti.Size=UDim2.new(1,-100,0,26) ti.Position=UDim2.fromOffset(8,2) ti.BackgroundTransparency=1 ti.Text=label ti.TextColor3=Color3.new(1,1,1) ti.TextSize=14 ti.TextXAlignment=Enum.TextXAlignment.Left ti.Parent=fr
    local box=Instance.new("TextBox")
    box.Size=UDim2.fromOffset(80,28) box.Position=UDim2.new(1,-88,0,3) box.BackgroundColor3=Color3.fromRGB(55,55,55) box.BorderSizePixel=0 box.Text=tostring(val) box.TextColor3=Color3.new(1,1,1) box.TextSize=14 box.ClearTextOnFocus=false box.Parent=fr
    Corner(box,6)
    local hl=Instance.new("TextLabel")
    hl.Size=UDim2.new(1,-15,0,25) hl.Position=UDim2.fromOffset(8,32) hl.BackgroundTransparency=1 hl.Text=hint hl.TextColor3=Color3.fromRGB(180,180,180) hl.TextSize=12 hl.TextWrapped=true hl.TextXAlignment=Enum.TextXAlignment.Left hl.Parent=fr
    box.FocusLost:Connect(function()
        local n=tonumber(box.Text)
        if not n then box.Text=tostring(val) return end
        val=math.clamp(n,mn,mx)
        box.Text=tostring(val)
        SafeCall(cb,val)
    end)
    ControlRefs[key]={Set=function(v) val=v box.Text=tostring(v) end}
end
local function AddButton(label,cb)
    local btn=Instance.new("TextButton")
    btn.Size=UDim2.new(1,-4,0,36) btn.BackgroundColor3=Color3.fromRGB(50,50,50) btn.BorderSizePixel=0 btn.Text=label btn.TextColor3=Color3.new(1,1,1) btn.TextSize=14 btn.Parent=Scroll
    Corner(btn,7)
    btn.Activated:Connect(function() SafeCall(cb) end)
end
local function AddCycle(key,label,init,options,cb)
    local idx=1
    for i,opt in ipairs(options) do if opt==init then idx=i break end end
    local btn=Instance.new("TextButton")
    btn.Size=UDim2.new(1,-4,0,36) btn.BackgroundColor3=Color3.fromRGB(45,45,45) btn.BorderSizePixel=0 btn.TextColor3=Color3.new(1,1,1) btn.TextSize=14 btn.Parent=Scroll
    Corner(btn,7)
    local function upd() btn.Text=label..":"..options[idx] end
    upd()
    btn.Activated:Connect(function() idx=idx%#options+1 upd() SafeCall(cb,options[idx]) end)
    ControlRefs[key]={Set=function(v)
        for i,opt in ipairs(options) do if opt==v then idx=i break end end
        upd()
    end}
end

-- ============ 第 1 页:遁地 ============
UsePage(1)
AddTitle("遁地")
AddToggle("Underground","遁地",S.Underground,function(v) if v then StartUnderground() else StopUnderground() end end)
AddInput("UndergroundDistance","遁地距離",S.UndergroundDistance,"數值範圍:1~100",1,100,function(v) S.UndergroundDistance=v end)

-- ============ 第 2 页:虚空 + 加速 ============
UsePage(2)
AddTitle("虛空打擊")
AddToggle("VoidStrike","虛空打擊",S.VoidStrike,function(v)
    S.VoidStrike=v
    if v and GetCharacter() then VoidReturnCFrame=Root.CFrame VoidAngle=0 SetUndergroundNoclip(true)
    else
        S.VoidStrike=false
        if VoidReturnCFrame and Root and Root.Parent then
            local rot=Root.CFrame-Root.Position
            Root.CFrame=CFrame.new(VoidReturnCFrame.Position)*rot
            Root.AssemblyLinearVelocity=Vector3.zero Root.AssemblyAngularVelocity=Vector3.zero
        end
        VoidReturnCFrame,VoidAngle=nil,0
        if not(S.Underground or S.VoidToggle) then SetUndergroundNoclip(false) end
    end
end)
AddInput("VoidDepth","鑽地深度",S.VoidDepth,"數值範圍:1~100(預設 9)",1,100,function(v) S.VoidDepth=v end)

AddTitle("拉虛空(遁地 53 左右亂動)")
AddInput("VoidToggleDepth","遁地深度",S.VoidToggleDepth,"數值範圍:1~500(預設 53)",1,500,function(v) S.VoidToggleDepth=v end)
AddInput("VoidToggleLRDistance","左右距離",S.VoidToggleLRDistance,"數值範圍:1~1000(預設 10)",1,1000,function(v) S.VoidToggleLRDistance=v end)
AddInput("VoidToggleLRSpeed","左右速度",S.VoidToggleLRSpeed,"數值範圍:1~100(預設 5)",1,100,function(v) S.VoidToggleLRSpeed=v end)
local toggleStartBtn=Instance.new("TextButton")
toggleStartBtn.Size=UDim2.new(1,-4,0,36) toggleStartBtn.BackgroundColor3=Color3.fromRGB(35,120,70) toggleStartBtn.BorderSizePixel=0 toggleStartBtn.Text="▶ 開始拉虛空" toggleStartBtn.TextColor3=Color3.new(1,1,1) toggleStartBtn.TextSize=14 toggleStartBtn.Parent=Scroll
Corner(toggleStartBtn,7)
toggleStartBtn.Activated:Connect(function() SafeCall(StartVoidToggle) end)
local toggleStopBtn=Instance.new("TextButton")
toggleStopBtn.Size=UDim2.new(1,-4,0,36) toggleStopBtn.BackgroundColor3=Color3.fromRGB(150,35,35) toggleStopBtn.BorderSizePixel=0 toggleStopBtn.Text="■ 結束拉虛空" toggleStopBtn.TextColor3=Color3.new(1,1,1) toggleStopBtn.TextSize=14 toggleStopBtn.Parent=Scroll
Corner(toggleStopBtn,7)
toggleStopBtn.Activated:Connect(function() SafeCall(StopVoidToggle) end)

AddTitle("加速(Rivals 專用)")
AddToggle("Boost","加速",S.Boost,function(v)
    S.Boost=v
    if v then if not ApplyRivalsBoost() then S.Boost=false warn("[UUI] 加速功能不可用") end
    else RestoreRivalsBoost() end
end)

-- ============ 第 3 页:准心 + 皮肤 ============
UsePage(3)
AddTitle("六芒星準心")
AddToggle("Crosshair","六芒星準心",S.Crosshair,function(v) S.Crosshair=v if v then StartCrosshair() else StopCrosshair() end end)
AddTitle("旋轉準心")
AddToggle("DeltaAim","旋轉準心",S.DeltaAim,function(v) S.DeltaAim=v if v then StartDeltaAim() else StopDeltaAim() end end)
AddTitle("全皮膚(執行器專用)")
AddToggle("Skin","全皮膚",S.Skin,function(v)
    S.Skin=v
    if v then if not StartSkin() then S.Skin=false warn("[UUI] 全皮膚功能不可用") end
    else StopSkin() end
end)

-- ============ 第 4 页:ESP + Ragebot ============
UsePage(4)
AddTitle("ESP")
AddToggle("ESP","ESP",S.ESP,function(v) S.ESP=v end)
AddToggle("ESPName","顯示名稱",S.ESPName,function(v) S.ESPName=v end)
AddToggle("ESPDistance","顯示距離",S.ESPDistance,function(v) S.ESPDistance=v end)
AddToggle("ESPHealth","顯示血量",S.ESPHealth,function(v) S.ESPHealth=v end)
AddToggle("ESPHealthBar","顯示血量條",S.ESPHealthBar,function(v) S.ESPHealthBar=v end)

AddTitle("Ragebot")
local rageBtn=Instance.new("TextButton")
rageBtn.Size=UDim2.new(1,-4,0,40) rageBtn.BorderSizePixel=0 rageBtn.TextColor3=Color3.new(1,1,1) rageBtn.TextSize=14 rageBtn.Font=Enum.Font.GothamBold rageBtn.Parent=Scroll
Corner(rageBtn,7)
local function UpdateRageBtn()
    rageBtn.Text="Ragebot:"..(rageActive and "開啟" or "關閉")
    rageBtn.BackgroundColor3=rageActive and Color3.fromRGB(35,120,70) or Color3.fromRGB(45,45,45)
end
UpdateRageBtn()
rageBtn.Activated:Connect(function()
    SafeCall(function()
        if rageActive then StopRagebot()
        else if not StartRagebot() then warn("[UUI] Ragebot 無法啟動") end end
        UpdateRageBtn()
    end)
end)
AddTitle("武器槽(點擊切換)")
local slotLabels={Primary="1 主武器",Secondary="2 副武器",Melee="3 近戰"}
local slotOrder={"Primary","Secondary","Melee"}
local slotButtons={}
for i,slot in ipairs(slotOrder) do
    local btn=Instance.new("TextButton")
    btn.Size=UDim2.new(1,-4,0,34) btn.BorderSizePixel=0 btn.Text=slotLabels[slot] btn.TextColor3=Color3.new(1,1,1) btn.TextSize=14 btn.Font=Enum.Font.GothamBold btn.Parent=Scroll
    Corner(btn,7)
    btn.BackgroundColor3=(slot==rageWeaponSlot) and Color3.fromRGB(35,120,70) or Color3.fromRGB(45,45,45)
    slotButtons[slot]=btn
    btn.Activated:Connect(function()
        rageWeaponSlot=slot
        for s,b in pairs(slotButtons) do b.BackgroundColor3=(s==slot) and Color3.fromRGB(35,120,70) or Color3.fromRGB(45,45,45) end
        if rageActive and rageModules and rageModules.FighterController then
            local lf=rageModules.FighterController.LocalFighter
            if lf then pcall(function() lf:EquipItem(GetRageSlotNumber()) end) end
        end
    end)
end
AddInput("RageFireRate","射速間隔",rageFireRate,"數值範圍:0.0001~1(秒)",0.0001,1,function(v) rageFireRate=v end)

-- ============ 第 5 页:新功能 A ============
UsePage(5)
AddTitle("VoidSpam(虛空位移)")
AddToggle("VoidSpam","啟用 VoidSpam",S.VoidSpam,function(v) S.VoidSpam=v if v then startVoidSpam() else stopVoidSpam() end end)
AddCycle("VoidMethod","方法",CFG_V.METHOD,{"Drift","Chaos","Loop","Spiral","Quantum"},function(v) CFG_V.METHOD=v end)
AddInput("VoidSpeed","速度 (B/s)",1,"範圍:1~2000(1B = 10億 studs/s)",1,2000,function(v) CFG_V.SPEED=v*1e9 end)
AddInput("VoidRadius","半徑 (B)",200,"範圍:1~2000",1,2000,function(v) CFG_V.RADIUS=v*1e9 end)
AddInput("VoidAltitude","高度 (B)",10,"範圍:1~1000",1,1000,function(v) CFG_V.BASE_ALTITUDE=v*1e9 end)

AddTitle("Orbit(繞圈)")
AddToggle("Orbit","啟用 Orbit",S.Orbit,function(v) S.Orbit=v cfgO.orbitEnabled=v if v then startOrbit() else stopOrbit() end end)
AddCycle("OrbitMode","模式",cfgO.orbitMode,{"Circle","Figure 8","Spiral In","Spiral Out","Bounce"},function(v) cfgO.orbitMode=v end)
AddInput("OrbitSpeed","速度 (deg/s)",90,"範圍:5~720",5,720,function(v) cfgO.orbitSpeed=v end)
AddInput("OrbitDist","半徑",8,"範圍:1~200",1,200,function(v) cfgO.orbitDist=v end)
AddInput("OrbitHeight","高度偏移",0,"範圍:-200~200",-200,200,function(v) cfgO.orbitHeight=v end)

AddTitle("Prediction(預測閃避)")
AddToggle("Prediction","啟用 Prediction",S.Prediction,function(v) S.Prediction=v cfgD.predEnabled=v if v then startPrediction() else stopPrediction() end end)
AddInput("PredRadius","危險半徑",20,"範圍:5~100",5,100,function(v) cfgD.predRadius=v end)
AddInput("PredDodgeDist","閃避距離",30,"範圍:5~150",5,150,function(v) cfgD.predDodgeDist=v end)
AddInput("PredThreshold","速度閾值",800,"範圍:200~5000",200,5000,function(v) cfgD.predThreshold=v end)

AddTitle("AntiAim(反瞄準)")
AddToggle("AntiAim","啟用 AntiAim",S.AntiAim,function(v) S.AntiAim=v cfgAA.enabled=v if v then startAntiAim() else stopAntiAim() end end)
AddCycle("AntiAimMode","模式",cfgAA.mode,{"Spin","Jitter","Static"},function(v) cfgAA.mode=v end)
AddInput("AntiAimSpeed","速度 (deg/s)",5000,"範圍:100~5000",100,5000,function(v) cfgAA.speed=v end)
AddInput("AntiAimAngle","角度",90,"範圍:10~180",10,180,function(v) cfgAA.angle=v end)

-- ============ 第 6 页:新功能 B ============
UsePage(6)
AddTitle("Riot(亂跳 + 旋轉)")
AddToggle("Riot","啟用 Riot",S.Riot,function(v) S.Riot=v if v then startRiot() else stopRiot() end end)
AddInput("RiotSpeed","傳送間隔 (秒)",0.03,"範圍:0.01~0.5",0.01,0.5,function(v) riotCfg.speed=v end)
AddInput("RiotRange","跳躍範圍 (studs)",50,"範圍:10~200",10,200,function(v) riotCfg.range=v end)
AddInput("RiotEvadeRange","閃避觸發 (studs)",30,"範圍:0~100",0,100,function(v) riotCfg.evadeRange=v end)
AddInput("RiotSpinSpeed","旋轉速度 (deg/s)",180,"範圍:0~720",0,720,function(v) riotCfg.spinSpeed=v end)

AddTitle("Riot Abuse(貼臉)")
AddToggle("RiotAbuse","啟用 Riot Abuse",S.RiotAbuse,function(v) S.RiotAbuse=v if v then startRiotAbuse() else stopRiotAbuse() end end)
AddCycle("RiotAbuseMode","模式",riotAbuseCfg.mode,{"Stick","Bounce"},function(v) riotAbuseCfg.mode=v end)
AddInput("RiotAbuseHeight","高度偏移",3,"範圍:-50~50",-50,50,function(v) riotAbuseCfg.height=v end)
AddInput("RiotAbuseForward","前後偏移",0,"範圍:-50~50",-50,50,function(v) riotAbuseCfg.forward=v end)
AddInput("RiotAbuseRight","左右偏移",0,"範圍:-50~50",-50,50,function(v) riotAbuseCfg.right=v end)
AddInput("RiotAbuseDown","向下偏移",0,"範圍:0~50",0,50,function(v) riotAbuseCfg.down=v end)

AddTitle("Projectile Bypass(BETA)")
AddToggle("ProjBypass","啟用 Proj Bypass",S.ProjBypass,function(v) S.ProjBypass=v if v then startProjBypass() else stopProjBypass() end end)
local pbHint=Instance.new("TextLabel")
pbHint.Size=UDim.new(1,-4,0,48) pbHint.BackgroundTransparency=1 pbHint.Text="• 會 hook Remotes 下所有 RemoteEvent 的 FireServer\n• 僅在 Rivals + 執行器環境下有效" pbHint.TextColor3=Color3.fromRGB(180,180,180) pbHint.TextSize=12 pbHint.TextWrapped=true pbHint.TextXAlignment=Enum.TextXAlignment.Left pbHint.Parent=Scroll

-- ============ 第 7 页:存档 ============
UsePage(7)
AddTitle("存檔管理")
local SaveNameBox=Instance.new("TextBox")
SaveNameBox.Size=UDim2.new(1,-4,0,38) SaveNameBox.BackgroundColor3=Color3.fromRGB(45,45,45) SaveNameBox.BorderSizePixel=0 SaveNameBox.PlaceholderText=HAS_WRITEFILE and "輸入存檔名稱" or "(此環境不支援存檔)" SaveNameBox.Text="" SaveNameBox.TextColor3=Color3.new(1,1,1) SaveNameBox.TextSize=14 SaveNameBox.ClearTextOnFocus=false SaveNameBox.Parent=Scroll
Corner(SaveNameBox,7)
local SaveStatus=Instance.new("TextLabel")
SaveStatus.Size=UDim2.new(1,-4,0,28) SaveStatus.BackgroundTransparency=1 SaveStatus.Text="存檔數量:0" SaveStatus.TextColor3=Color3.fromRGB(180,180,180) SaveStatus.TextSize=13 SaveStatus.Parent=Scroll
local SaveList=Instance.new("Frame")
SaveList.Size=UDim2.new(1,-4,0,10) SaveList.AutomaticSize=Enum.AutomaticSize.Y SaveList.BackgroundTransparency=1 SaveList.Parent=Scroll
local SL=Instance.new("UIListLayout") SL.Padding=UDim.new(0,5) SL.Parent=SaveList

-- 前向声明 RefreshAll
local RefreshAll

local function RefreshSaves()
    for _,c in ipairs(SaveList:GetChildren()) do if c:IsA("Frame") then c:Destroy() end end
    local cnt=0
    for name,entry in pairs(Saves) do
        cnt=cnt+1
        local row=Instance.new("Frame") row.Size=UDim2.new(1,0,0,64) row.BackgroundColor3=Color3.fromRGB(38,38,38) row.BorderSizePixel=0 row.Parent=SaveList
        Corner(row,7)
        local nL=Instance.new("TextLabel") nL.Size=UDim2.new(1,-150,0,25) nL.Position=UDim2.fromOffset(8,3) nL.BackgroundTransparency=1 nL.Text=tostring(name) nL.TextColor3=Color3.new(1,1,1) nL.TextSize=13 nL.TextXAlignment=Enum.TextXAlignment.Left nL.Parent=row
        local tL=Instance.new("TextLabel") tL.Size=UDim2.new(1,-150,0,22) tL.Position=UDim2.fromOffset(8,30) tL.BackgroundTransparency=1 tL.Text=tostring(entry.time or "") tL.TextColor3=Color3.fromRGB(160,160,160) tL.TextSize=11 tL.TextXAlignment=Enum.TextXAlignment.Left tL.Parent=row
        local lB=Instance.new("TextButton") lB.Size=UDim2.fromOffset(60,28) lB.Position=UDim2.new(1,-130,0,17) lB.BackgroundColor3=Color3.fromRGB(35,100,160) lB.BorderSizePixel=0 lB.Text="載入" lB.TextColor3=Color3.new(1,1,1) lB.TextSize=12 lB.Parent=row
        Corner(lB,5)
        lB.Activated:Connect(function()
            if ApplySave(name) then
                RefreshAll()
                SaveStatus.Text="已載入:"..name
            end
        end)
        local dB=Instance.new("TextButton") dB.Size=UDim2.fromOffset(60,28) dB.Position=UDim2.new(1,-65,0,17) dB.BackgroundColor3=Color3.fromRGB(150,50,50) dB.BorderSizePixel=0 dB.Text="刪除" dB.TextColor3=Color3.new(1,1,1) dB.TextSize=12 dB.Parent=row
        Corner(dB,5)
        dB.Activated:Connect(function() DeleteSave(name) RefreshSaves() end)
    end
    SaveStatus.Text="存檔數量:"..cnt
end
AddButton("新增存檔",function()
    if AddSave(SaveNameBox.Text) then SaveStatus.Text="存檔成功" RefreshSaves()
    else SaveStatus.Text=HAS_WRITEFILE and "存檔失敗" or "此環境不支援存檔" end
end)
AddButton("重新整理存檔",RefreshSaves)
AddButton("清空全部存檔",function() Saves={} SaveAll() RefreshSaves() SaveStatus.Text="已清空" end)

-- ============ RefreshAll(修復版:先 Stop 再 Start)============
RefreshAll=function()
    -- 1. 同步所有 UI 控件狀態
    for k,ref in pairs(ControlRefs) do if S[k]~=nil then ref.Set(S[k]) end end

    -- 2. ESP:關閉時清空;開啟時下一幀會自動重建(UpdateESP 每幀調用)
    if not S.ESP then for p in pairs(ESPObjects) do RemoveESP(p) end end

    -- 3. Boost
    if S.Boost then ApplyRivalsBoost() else RestoreRivalsBoost() end

    -- 4. VoidStrike
    if S.VoidStrike and GetCharacter() then
        VoidReturnCFrame=Root.CFrame VoidAngle=0 SetUndergroundNoclip(true)
    else
        VoidReturnCFrame,VoidAngle=nil,0
    end

    -- 5. Underground
    if S.Underground then
        if not UndergroundStartCFrame then StartUnderground() end
    else
        if UndergroundStartCFrame then StopUnderground() end
    end

    -- 6. 准心(重啟,避免 CrosshairGui 引用泄漏導致早退)
    StopCrosshair()
    if S.Crosshair then StartCrosshair() end

    -- 7. 旋转准心(重啟)
    StopDeltaAim()
    if S.DeltaAim then StartDeltaAim() end

    -- 8. 全皮膚
    StopSkin()
    if S.Skin then StartSkin() end

    -- 9. 新功能(重啟,避免旧连接残留)
    stopVoidSpam() if S.VoidSpam then startVoidSpam() end
    stopOrbit() if S.Orbit then startOrbit() end
    stopPrediction() if S.Prediction then startPrediction() end
    stopAntiAim() if S.AntiAim then startAntiAim() end
    stopRiot() if S.Riot then startRiot() end
    stopRiotAbuse() if S.RiotAbuse then startRiotAbuse() end
    stopProjBypass() if S.ProjBypass then startProjBypass() end
end

RefreshSaves()
if S.Skin then StartSkin() end
-- 首次同步 UI(不觸發任何 Start,因為 S 全是預設 false)
for k,ref in pairs(ControlRefs) do if S[k]~=nil then ref.Set(S[k]) end end

-- ============ 主循环 ============
RunService.Heartbeat:Connect(function(d)
    local ok,e=pcall(function()
        if Player.Character~=Character then
            StopVoidToggleLoop()
            Character=Player.Character
            Root,Humanoid=nil,nil
            SavedCollision={}
            VoidReturnCFrame,VoidAngle=nil,0
            VoidToggleBase,VoidToggleRightVector=nil,nil
            rageDeflecting={}
            -- ESP 清理旧对象(下一帧 UpdateESP 会重建)
            for p in pairs(ESPObjects) do RemoveESP(p) end
            task.spawn(function()
                if not Character then return end
                Root=Character:WaitForChild("HumanoidRootPart",10)
                Humanoid=Character:WaitForChild("Humanoid",10)
                if not Root or not Humanoid then return end
                UndergroundStartCFrame=nil
                if S.Underground then StartUnderground() end
                if S.VoidStrike then VoidReturnCFrame=Root.CFrame VoidAngle=0 SetUndergroundNoclip(true) end
                if S.VoidToggle then StartVoidToggle() end
            end)
        end
        if not GetCharacter() then return end
        if S.Underground or S.VoidStrike or VoidToggleActive then SetUndergroundNoclip(true) end
        UpdateMovement(d)
        UpdateESP()
    end)
    if not ok then warn("[UUI] Heartbeat 錯誤:",e) end
    if rageActive then
        local rok,rerr=pcall(UpdateRagebot)
        if not rok then warn("[Ragebot] 錯誤:",rerr) end
    end
end)

print("[UUI] 初始化完成(7 頁,含新功能 + ESP/準心修復)")

77,452 chars · codepastes.com