if getgenv().patchmaskid =="gay" then return end getgenv().patchmaskid ="gay" local IN=Instance.new local V3=Vector3.new local C3=Color3.new local V2=Vector2.new local CF=CFrame.new local NS=NumberSequence.new local NSK=NumberSequenceKeypoint.new local UD2=UDim2.fromScale local SafeSvc=setmetatable({}, {__index=function(t, n) local s=cloneref(game:GetService(n)) t[n]=s return s end}) local clock=os.clock local floor=math.floor local ceil=math.ceil local abs=math.abs local max=math.max local min=math.min local rand=math.random local rad=math.rad local deg=math.deg local tan=math.tan local atan=math.atan local exp=math.exp local clamp=math.clamp local huge=math.huge local AIR=Enum.Material.Air local R6=Enum.HumanoidRigType.R6 local refs={} local fr=0 local slotN=0 local vis=true local nm=0 local nb=0 local mir={} local bl={} local pc={} local tracked={} local npcSet={} local npcPending={} local watch={"BasePart","Accessory","Clothing","ShirtGraphic","BodyColors","CharacterMesh","SurfaceAppearance","WrapLayer","Humanoid"} local OFFS={V3(0,0,0),V3(0.35,0,0),V3(-0.35,0,0),V3(0,0.35,0),V3(0,-0.35,0),V3(0,0,0.35),V3(0,0,-0.35)} local NOFFS=#OFFS local CULL_DIST=150 local BLK_DIST=60 local STEP2_DIST=110 local NPC_MAX=8 local NPC_RANGE=70 local NPC_DESPAWN=NPC_RANGE * 1.25 local ALPHA_RATE=12 local SCAN_IV=0.25 local SLOW_IV=0.25 local DIRTY_DELAY=0.1 local FADE_T=0.1 local AIR_STATE={[Enum.HumanoidStateType.Jumping]=true, [Enum.HumanoidStateType.Freefall]=true} local OWN_PARTS={LeftFoot=true,RightFoot=true,["Left Leg"]=true,["Right Leg"]=true,LeftLowerLeg=true,RightLowerLeg=true} local pt, gui, vpf, vcam local lVs, lFov, lIT local frameConn function rmRef(key, r) r=refs[key] if r then refs[key]=nil if r.npc then tracked[key]=nil end for _, cn in ipairs(r.conns) do cn:Disconnect() end if r.clone then r.clone:Destroy() end end end function mcf(oc, fy, x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22) x, y, z, r00, r01, r02, r10, r11, r12, r20, r21, r22=oc:GetComponents() return CF(x, (2 * fy) - y, z, -r00, r01, r02, r10, -r11, -r12, -r20, r21, r22) end function pTree(a, b, out, pool, used, k, m) pool={} for _, ch in ipairs(b:GetChildren()) do pool[ch.Name]=pool[ch.Name] or {} table.insert(pool[ch.Name], ch) end used={} for _, ch in ipairs(a:GetChildren()) do k=ch.Name used[k]=(used[k] or 0) + 1 m=pool[k] and pool[k][used[k]] if m and m.ClassName == ch.ClassName then if ch:IsA("BasePart") then table.insert(out, {ch, m, f=0, tg=0, rOn=false, vis=true}) end pTree(ch, m, out) end end end function cRad(r, m, x) m=4 for _, p in ipairs(r.pairs) do if p[1].Parent then x=(p[1].Position - r.hrp.Position).Magnitude + p.qr if x > m then m=x end end end r.mrad=m + 2 end function calcHH(r, h, v, leg) h=r.hum if not h then return end v=h.HipHeight + r.hrp.Size.Y * 0.5 if h.RigType == R6 then leg=r.char:FindFirstChild("Left Leg") if leg then v=v + leg.Size.Y end end r.hh=v end function lowest(r, m, y) m=huge for _, p in ipairs(r.pairs) do if p[1].Parent then y=p[1].Position.Y - p.hy if y < m then m=y end end end return m ~= huge and m or nil end function bld(r, cln, prs) if r.clone then r.clone:Destroy() r.clone=nil end r.pairs={} r.char.Archivable=true cln=r.char:Clone() if not cln then return end prs={} pTree(r.char, cln, prs) for _, v in ipairs(cln:GetDescendants()) do if v:IsA("LuaSourceContainer") or v:IsA("Sound") or v:IsA("BillboardGui") or v:IsA("ParticleEmitter") or v:IsA("Trail") or v:IsA("Beam") or v:IsA("Light") or v:IsA("Fire") or v:IsA("Smoke") or v:IsA("Sparkles") or v:IsA("ForceField") or v:IsA("Highlight") then v:Destroy() elseif v:IsA("Humanoid") then v.DisplayDistanceType=Enum.HumanoidDisplayDistanceType.None v.HealthDisplayType=Enum.HumanoidHealthDisplayType.AlwaysOff end end for _, p in ipairs(prs) do p[2].Anchored=true p[2].CanCollide=false p[2].CastShadow=false p[2].Material=Enum.Material.SmoothPlastic p.sz=p[1].Size p.hx=p.sz.X * 0.5 p.hy=p.sz.Y * 0.5 p.hz=p.sz.Z * 0.5 p.qr=p.sz.Magnitude * 0.5 p.own=(r.isLocal and OWN_PARTS[p[1].Name]) and true or false if p[1] == r.hrp and r.hrp.Name == "HumanoidRootPart" then p.root=true p[2].Transparency=1 end end r.clone=cln r.pairs=prs r.scale=r.char:GetScale() r.lfy=nil r.hum=r.char:FindFirstChildOfClass("Humanoid") calcHH(r) cRad(r) end function sTick(r) if r.scale ~= r.char:GetScale() then bld(r) return end for _, p in ipairs(r.pairs) do if p[1].Parent and p[1].Size ~= p.sz then p.sz=p[1].Size p[2].Size=p.sz p.hx=p.sz.X * 0.5 p.hy=p.sz.Y * 0.5 p.hz=p.sz.Z * 0.5 p.qr=p.sz.Magnitude * 0.5 end end calcHH(r) cRad(r) end function addRef(key, c, npc, hrp, r, mkDrt) if refs[key] and refs[key].char == c then return end rmRef(key) hrp=c:WaitForChild("HumanoidRootPart", npc and 3 or 5) if not hrp and npc then hrp=c.PrimaryPart or c:FindFirstChild("Torso") or c:FindFirstChild("UpperTorso") or c:FindFirstChild("Head") end if not hrp or not vpf then return end if npc then if not c.Parent then return end else if not key.Parent or key.Character ~= c then return end end if refs[key] then return end slotN=slotN + 1 r={char=c, hrp=hrp, pairs={}, conns={}, dirty=false, dirtyAt=0, isLocal=(key == SafeSvc.Players.LocalPlayer), npc=npc and true or false, mrad=6, slot=slotN, d=0, slow=clock() + rand() * SLOW_IV, cands={}, blk=false, step=1, upd=true, doOcc=false, hh=3, fyT=0} refs[key]=r mkDrt=function(v) for _, cls in ipairs(watch) do if v:IsA(cls) then r.dirty=true r.dirtyAt=clock() + DIRTY_DELAY return end end end table.insert(r.conns, c.DescendantAdded:Connect(mkDrt)) table.insert(r.conns, c.DescendantRemoving:Connect(mkDrt)) bld(r) end function trk(plr) if tracked[plr] then return end tracked[plr]=true plr.CharacterAdded:Connect(function(c) task.wait(0.25) addRef(plr, c) end) plr.CharacterRemoving:Connect(function() rmRef(plr) end) if plr.Character then task.spawn(addRef, plr, plr.Character) end end function trkNpc(m) if npcSet[m] or not m:IsA("Model") then return end if SafeSvc.Players:GetPlayerFromCharacter(m) then return end npcSet[m]=true end function npcScan(cPos, have, near, root, d) if not vpf then return end cPos=SafeSvc.Workspace.CurrentCamera.CFrame.Position have=0 near={} for m in pairs(npcSet) do if not m.Parent or not m:IsDescendantOf(SafeSvc.Workspace) then npcSet[m]=nil if refs[m] then rmRef(m) end elseif SafeSvc.Players:GetPlayerFromCharacter(m) then npcSet[m]=nil else root=m:FindFirstChild("HumanoidRootPart") or m.PrimaryPart if root then d=(root.Position - cPos).Magnitude if refs[m] then if d > NPC_DESPAWN then rmRef(m) else have=have + 1 end elseif d < NPC_RANGE and not npcPending[m] then near[#near + 1]={m, d} end end end end for _ in pairs(npcPending) do have=have + 1 end table.sort(near, function(x, y) return x[2] < y[2] end) for i=1, #near do if have >= NPC_MAX then break end have=have + 1 npcPending[near[i][1]]=true task.spawn(function(m) pcall(addRef, m, m, true) npcPending[m]=nil end, near[i][1]) end end function stop() if frameConn then frameConn:Disconnect() frameConn=nil end pcall(function() SafeSvc.RunService:UnbindFromRenderStep("ReflectionStep") end) for p in pairs(refs) do rmRef(p) end if gui then gui:Destroy() gui, vpf, vcam=nil, nil, nil end if pt then pt:Destroy() pt=nil end end function blk(q, s, l, tmin, tmax, d, t1, t2) l=q.cf:PointToObjectSpace(s) tmin, tmax=0, 1 d=l.X - q.o.X if abs(d) < 1e-8 then if abs(q.o.X) > q.hx then return false end else t1=(-q.hx - q.o.X) / d t2=(q.hx - q.o.X) / d if t1 > t2 then t1, t2=t2, t1 end if t1 > tmin then tmin=t1 end if t2 < tmax then tmax=t2 end if tmin > tmax then return false end end d=l.Y - q.o.Y if abs(d) < 1e-8 then if abs(q.o.Y) > q.hy then return false end else t1=(-q.hy - q.o.Y) / d t2=(q.hy - q.o.Y) / d if t1 > t2 then t1, t2=t2, t1 end if t1 > tmin then tmin=t1 end if t2 < tmax then tmax=t2 end if tmin > tmax then return false end end d=l.Z - q.o.Z if abs(d) < 1e-8 then if abs(q.o.Z) > q.hz then return false end else t1=(-q.hz - q.o.Z) / d t2=(q.hz - q.o.Z) / d if t1 > t2 then t1, t2=t2, t1 end if t1 > tmin then tmin=t1 end if t2 < tmax then tmax=t2 end if tmin > tmax then return false end end return tmin < 0.999 end function detach(r) if r.clone.Parent then r.clone.Parent=nil end end function collect(plr, r, now, cPos, lk, valid, hp, d, h, cBlk, fyC, p, acf) r.blk=false if r.npc then valid=r.char.Parent ~= nil else valid=plr.Parent and plr.Character == r.char end if not valid or not r.char.Parent or not r.hrp.Parent then rmRef(plr) return end if r.dirty and now >= r.dirtyAt then r.dirty=false bld(r) elseif now >= r.slow then r.slow=now + SLOW_IV sTick(r) end if not r.clone then return end hp=r.hrp.Position d=(hp - cPos).Magnitude if d > CULL_DIST then detach(r) return end -- floor height from math only, no raycast h=r.hum if h then if not r.fy or (h.FloorMaterial ~= AIR and not AIR_STATE[h:GetState()]) then r.fy=hp.Y - r.hh end elseif now >= r.fyT then r.fyT=now + 0.1 r.fy=lowest(r) or r.fy end if not r.fy or cPos.Y <= r.fy then detach(r) return end if r.clone.Parent ~= vpf then r.clone.Parent=vpf end r.mc=V3(hp.X, 2 * r.fy - hp.Y, hp.Z) r.d=d r.c=hp if (r.mc - cPos):Dot(lk) < -r.mrad then return end cBlk=r.isLocal or d <= BLK_DIST r.step=(cBlk or d < STEP2_DIST) and 1 or 2 r.upd=(r.step == 1) or (r.lfy == nil) or ((fr + r.slot) % r.step == 0) r.doOcc=r.upd if r.upd then fyC=(r.fy ~= r.lfy) for i=1, #r.pairs do p=r.pairs[i] if p[1].Parent then acf=p[1].CFrame if fyC or acf ~= p.lc then p.lc=acf p.mcf=mcf(acf, r.fy) p[2].CFrame=p.mcf end if not p.root then p.base=p[1].Transparency p.vis=true if cBlk and max(p.base, p[1].LocalTransparencyModifier) < 0.9 then p.cf=acf p.wp=acf.Position p.o=acf:PointToObjectSpace(cPos) p.rOn=true else p.rOn=false end end else p.vis=false p.rOn=false end end r.lfy=r.fy if cBlk then r.blk=true nb=nb + 1 bl[nb]=r end end nm=nm + 1 mir[nm]=r end function occ(r, cPos, nc, v, vv, o, w, t, dd, lm, p, v2, vv2, npc, q, nMn, hts, s, tg) nc=0 v=r.mc - cPos vv=v:Dot(v) for k=1, nb do o=bl[k] w=o.c - cPos t=vv > 1e-6 and w:Dot(v) / vv or 0 if t < 0 then t=0 elseif t > 1 then t=1 end dd=v * t - w lm=o.mrad + r.mrad if dd:Dot(dd) < lm * lm then nc=nc + 1 r.cands[nc]=o end end for i=1, #r.pairs do p=r.pairs[i] if not p.root and p.vis then tg=0 if nc > 0 then v2=p.mcf.Position - cPos vv2=v2:Dot(v2) npc=0 for k=1, nc do o=r.cands[k] if not (p.own and o.isLocal) then for m=1, #o.pairs do q=o.pairs[m] if q.rOn then w=q.wp - cPos t=vv2 > 1e-6 and w:Dot(v2) / vv2 or 0 if t < 0 then t=0 elseif t > 1 then t=1 end dd=v2 * t - w lm=q.qr + p.qr if dd:Dot(dd) < lm * lm then npc=npc + 1 pc[npc]=q end end end end end if npc > 0 then for si=1, NOFFS do s=p.mcf:PointToWorldSpace(OFFS[si] * p.sz) for m=1, npc do if blk(pc[m], s) then tg=p.own and 0.35 or 0.95 break end end if tg > 0 then break end end end end p.tg=tg end end end function fade(r, now, p, tr, f, tgt, s) for i=1, #r.pairs do p=r.pairs[i] if not p.root then if p.vis then f, tgt=p.f, p.tg s=min((now - (p.ft or now)) / FADE_T, 1) p.ft=now if f ~= tgt then if f < tgt then f=f + s if f > tgt then f=tgt end else f=f - s if f < tgt then f=tgt end end p.f=f end tr=p.base + (1 - p.base) * f else tr=1 end if tr ~= p.wt then p[2].Transparency=tr p.wt=tr end end end end function frame(dt, now, cam, vs, cCF, cPos, fov, fRad, h, lk, it, hd, al, j0, r) fr=fr + 1 now=clock() cam=SafeSvc.Workspace.CurrentCamera if pt.Parent ~= cam then pt.Parent=cam end vs=cam.ViewportSize cCF=cam.CFrame cPos=cCF.Position fov=cam.FieldOfView if vs ~= lVs or fov ~= lFov then lVs, lFov=vs, fov fRad=rad(fov) h=2 * tan(fRad / 2) * 1.05 pt.Size=V3(h * (vs.X / vs.Y), h, 0.05) gui.CanvasSize=vs vcam.FieldOfView=min(120, deg(2 * atan(tan(fRad / 2) * 1.05))) end pt.CFrame=cCF * CF(0, 0, -(1 + 0.05 / 2)) vcam.CFrame=cCF lk=cCF.LookVector it=0.55 + (1 - 0.55) * clamp((-lk.Y - 0.35) / (0.75 - 0.35), 0, 1) if it ~= lIT then vpf.ImageTransparency=it lIT=it end hd=it >= 0.995 if hd == vis then vis=not hd vpf.Visible=vis end if hd then return end al=ALPHA_RATE > 0 and (1 - exp(-dt * ALPHA_RATE)) or 1 nm, nb=0, 0 for plr, rf in pairs(refs) do collect(plr, rf, now, cPos, lk) end j0=nm > 0 and (fr % nm) or 0 for jj=1, nm do r=mir[(jj + j0 - 1) % nm + 1] if r.doOcc then occ(r, cPos) end if r.upd then fade(r, now) end end end pt=IN("Part") pt.Name="ReflectionSurface" pt.Anchored=true pt.CanCollide=false pt.CanTouch=false pt.CanQuery=false pt.CastShadow=false pt.Transparency=1 pt.Size=V3(1, 1, 0.05) pt.Parent=SafeSvc.Workspace.CurrentCamera gui=IN("SurfaceGui") gui.Name="Reflection" gui.Adornee=pt gui.Face=Enum.NormalId.Back gui.AlwaysOnTop=true gui.LightInfluence=0 gui.ResetOnSpawn=false gui.ClipsDescendants=true gui.SizingMode=Enum.SurfaceGuiSizingMode.FixedSize gui.CanvasSize=SafeSvc.Workspace.CurrentCamera.ViewportSize gui.Parent=gethui() vpf=IN("ViewportFrame") vpf.AnchorPoint=V2(0.5, 0.5) vpf.Position=UD2(0.5, 0.5) vpf.Size=UD2(1, 1) vpf.BackgroundTransparency=1 vpf.BorderSizePixel=0 vpf.Ambient=C3(0.7, 0.7, 0.7) vpf.LightColor=C3(1, 1, 1) vpf.LightDirection=V3(0, 1, 0) vpf.Parent=gui vcam=IN("Camera") vcam.Name="ReflectionCam" vcam.CFrame=SafeSvc.Workspace.CurrentCamera.CFrame vcam.FieldOfView=SafeSvc.Workspace.CurrentCamera.FieldOfView vcam.Parent=vpf vpf.CurrentCamera=vcam local grd=IN("UIGradient") grd.Transparency=NS({NSK(0, 0.2), NSK(0.6, 0.4), NSK(1, 0.8)}) grd.Rotation=90 grd.Parent=vpf SafeSvc.RunService:BindToRenderStep("ReflectionStep", Enum.RenderPriority.Last.Value, frame) for _, p in ipairs(SafeSvc.Players:GetPlayers()) do trk(p) end SafeSvc.Workspace.DescendantAdded:Connect(function(d) if vpf and d:IsA("Humanoid") and d.Parent then trkNpc(d.Parent) end end) task.spawn(function(n) n=0 for _, d in ipairs(SafeSvc.Workspace:GetDescendants()) do if d:IsA("Humanoid") and d.Parent then trkNpc(d.Parent) end n=n + 1 if n % 1500 == 0 then task.wait() end end end) task.spawn(function() while vpf do pcall(npcScan) task.wait(SCAN_IV) end end) SafeSvc.Players.PlayerAdded:Connect(function(p) if vpf then trk(p) end end) SafeSvc.Players.PlayerRemoving:Connect(function(p) rmRef(p) tracked[p]=nil end)