Advertisement
eruaaaaaaa

non fps dependent?

Apr 24th, 2022 (edited)
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.36 KB | None | 0 0
  1. local Aimbot = {}
  2. Aimbot.__index = Aimbot
  3.  
  4. --//Localization
  5. local Instance = Instance
  6. local game = game
  7. local math = math
  8. local setmetatable = setmetatable
  9. local workspace = workspace
  10. local CFrame = CFrame
  11. local Vector3 = Vector3
  12. local Vector2 = Vector2
  13. local Random = Random
  14. local RaycastParams = RaycastParams
  15. local pairs = pairs
  16. local string = string
  17. local table = table
  18. local Enum = Enum
  19. local getrawmetatable = getrawmetatable
  20. local replaceclosure = replaceclosure
  21. local setreadonly = setreadonly
  22. local checkcaller = checkcaller
  23. local getclock = os.clock
  24. local mouse1press = mouse1press
  25. local mouse1release = mouse1release
  26. local mousemoverel = mousemoverel
  27. local hookfunction = hookfunction
  28. local newcclosure = newcclosure
  29.  
  30. --//Instance methods
  31. local Raycast = workspace.Raycast
  32. local GetPropertyChangedSignal = game.GetPropertyChangedSignal
  33. local Connect = game.ChildAdded.Connect
  34. local Destroy = game.Destroy
  35. local GetService = game.GetService
  36. local FindFirstChildOfClass = game.FindFirstChildOfClass
  37. local FindFirstChild = game.FindFirstChild
  38. local GetChildren = game.GetChildren
  39. local IsA = game.IsA
  40. local IsDescendantOf = game.IsDescendantOf
  41.  
  42. --//Services
  43. local Players = GetService(game, "Players")
  44. local UserInputService = GetService(game, "UserInputService")
  45. local RunService = GetService(game, "RunService")
  46. local GuiService = GetService(game, "GuiService")
  47.  
  48. --//Temporary instances
  49. local tempcam = Instance.new("Camera")
  50. local tempconn = Connect(game.AncestryChanged, function() end)
  51.  
  52. --//Other instance methods
  53. local WorldToViewportPoint = tempcam.WorldToViewportPoint
  54. local WorldToScreenPoint = tempcam.WorldToScreenPoint
  55. local GetPlayers = Players.GetPlayers
  56. local GetMouseLocation = UserInputService.GetMouseLocation
  57. local ViewportPointToRay = tempcam.ViewportPointToRay
  58. local Disconnect = tempconn.Disconnect
  59. local Lerp2D = Vector2.new().Lerp
  60.  
  61. --//Cleanup
  62. Destroy(tempcam)
  63. Disconnect(tempconn)
  64.  
  65. --//Local functions and constant variables
  66. Aimbot.DefaultSettings = {
  67.     RadiusPercentAt1 = 130, --//Radius percent of screen width at 1 stud for aimbot
  68.     XSmoothingPercent = .125,
  69.     YSmoothingPercent = .15, --//Slows down mouse movement by a percentage of screen width
  70.     DistanceBias = 1, --//Raises sensitivity of distance from camera when choosing target
  71.     Offset = Vector2.new(0, 0), --//Mouse offset in pixels
  72.     SilentRadiusPercentAt1 = 130, --//Radius percent of screen width at 1 stud for silent aim
  73.     IgnoreTransparent = true, --//Whether to ignore transparent parts above the threshold or not in wallcheck
  74.     IgnoreWater = false, --//Whether to ignore water in wallcheck
  75.     TransparencyThreshold = .5, --//Threshold for what transparency or greater counts as ignorable
  76.     DefaultIgnore = {}, --//List for what the aimbot should ignore during wallcheck
  77.     IsAliveCheck = true, --//Ignore dead players
  78.     TeamCheck = true,
  79.     TriggerBot = true
  80. }
  81.  
  82. local LocalPlayer = Players.LocalPlayer
  83. local Mouse = LocalPlayer.GetMouse(LocalPlayer)
  84. local GuiInset = GuiService.GetGuiInset(GuiService)
  85. local GameMeta = getrawmetatable(game)
  86.  
  87. local function OnCameraChange()
  88.     local cam = workspace.CurrentCamera
  89.  
  90.     Aimbot.Camera = cam
  91.     Aimbot.ViewportSize = cam.ViewportSize
  92.     Aimbot.WidthFactor = cam.ViewportSize.X / 100
  93. end
  94.  
  95. local function UpdateTable(tab, update)
  96.     for name, value in pairs(update) do
  97.         if tab[name] == nil then
  98.             tab[name] = value
  99.         end
  100.     end
  101. end
  102.  
  103. local function GetChildrenWhichIsA(part, baseclass)
  104.     local parts = GetChildren(part)
  105.     local len = #parts
  106.  
  107.     local filtered = {}
  108.  
  109.     if len > 0 then
  110.         for i = 1, len do
  111.             local p = parts[i]
  112.  
  113.             if IsA(p, baseclass) then
  114.                 table.insert(filtered, p)
  115.             end
  116.         end
  117.     end
  118.  
  119.     return filtered
  120. end
  121.  
  122.  
  123. local function GetChildrenWhichIsNotA(part, baseclass)
  124.     local parts = GetChildren(part)
  125.     local len = #parts
  126.  
  127.     local filtered = {}
  128.  
  129.     if len > 0 then
  130.         for i = 1, len do
  131.             local p = parts[i]
  132.  
  133.             if not IsA(p, baseclass) then
  134.                 table.insert(filtered, p)
  135.             end
  136.         end
  137.     end
  138.  
  139.     return filtered
  140. end
  141.  
  142. if workspace.CurrentCamera then
  143.     OnCameraChange()
  144. end
  145.  
  146. Connect(GetPropertyChangedSignal(workspace, "CurrentCamera"), OnCameraChange)
  147.  
  148. --//Methods
  149.  
  150. --//Gets bias value at a given distance
  151. function Aimbot:GetBiasAtDistance(distance)
  152.     if self.Camera then
  153.         return distance * self.DistanceBias * self.WidthFactor
  154.     end
  155. end
  156.  
  157. --//Gets circle radius at a given distance
  158. function Aimbot:GetRadiusAtDistance(rpercent, distance)
  159.     if self.Camera then
  160.         return rpercent / distance * self.WidthFactor
  161.     end
  162. end
  163.  
  164. --//Checks for parts obscuring camera, including terrain - unlike Camera:GetPartsObscuringTarget
  165. function Aimbot:GetBlockingPart(origin, position, ignore)
  166.     self.WallCheckParams.FilterDescendantsInstances = self.DefaultIgnore --//Incase it got updated
  167.  
  168.     local dir = position - origin
  169.     local thisignore = self.WallCheckParams.FilterDescendantsInstances --//Copies table for you essentially
  170.  
  171.     if ignore then
  172.         table.move(ignore, 1, #ignore, #thisignore + 1, thisignore)
  173.     end
  174.  
  175.     while true do
  176.         self.WallCheckParams.FilterDescendantsInstances = thisignore --//Copies
  177.         local result = Raycast(workspace, origin, dir, self.WallCheckParams)
  178.  
  179.         if result then
  180.             if self.IgnoreTransparent and result.Instance.ClassName ~= "Terrain" and result.Instance.Transparency >= self.TransparencyThreshold then
  181.                 table.insert(thisignore, result.Instance)
  182.                 continue
  183.             end
  184.  
  185.             self.WallCheckParams.FilterDescendantsInstances = self.DefaultIgnore
  186.             return result.Instance
  187.         end
  188.  
  189.         self.WallCheckParams.FilterDescendantsInstances = self.DefaultIgnore
  190.         return nil
  191.     end
  192. end
  193.  
  194. --//Gets target from viewport point
  195. function Aimbot:GetTargetFromViewportPoint(point, distance, ignore)
  196.     local camera = self.Camera
  197.  
  198.     if camera then
  199.         local ray = ViewportPointToRay(camera, point.X, point.Y)
  200.         return self:GetBlockingPart(ray.Origin, ray.Origin + ray.Direction * distance, ignore)
  201.     end
  202. end
  203.  
  204. --//Gets closest edge on part from viewport point
  205. function Aimbot:GetClosestEdgeFromViewportPoint(point, part)
  206.     local camera = self.Camera
  207.  
  208.     if camera then
  209.         local ray = ViewportPointToRay(camera, point.X, point.Y)
  210.         local ppos = part.Position
  211.  
  212.         local dist = (ray.Origin - ppos).Magnitude
  213.         local dir = (ray.Origin + ray.Direction * dist - ppos).Unit
  214.  
  215.         local size = part.Size
  216.  
  217.         local half = size / 2
  218.         local final = dir * size
  219.  
  220.         return ppos + Vector3.new(
  221.             final.X < 0 and math.max(final.X, -half.X + size.X / 10) or math.min(final.X, half.X - size.X / 10),
  222.             final.Y < 0 and math.max(final.Y, -half.Y + size.Y / 10) or math.min(final.Y, half.Y - size.Y / 10),
  223.             final.Z < 0 and math.max(final.Z, -half.Z + size.Z / 10) or math.min(final.Z, half.Z - size.Z / 10)
  224.         )
  225.     end
  226. end
  227.  
  228. --//Gets mouse location with offset accounted for
  229. function Aimbot:GetMouseViewportPoint()
  230.     return GetMouseLocation(UserInputService) + self.Offset
  231. end
  232.  
  233. --//Gets best target from a list of parts and a viewport point, ignoreparent specifies whether to filter the entire parent
  234. function Aimbot:GetBestPartFromViewportPoint(position, parts, ignoreparent, ignore)
  235.     local camera = self.Camera
  236.  
  237.     if camera then
  238.         local len = #parts
  239.  
  240.         if len > 0 then
  241.             local leastbias, leastwdist, leastpdist, part = math.huge, math.huge, math.huge, nil
  242.             local campos = camera.CFrame.Position
  243.  
  244.             ignore = ignore or {}
  245.             local ipos = #ignore + 1
  246.  
  247.             for i = 1, len do
  248.                 local cpart = parts[i]
  249.                 local cpos = cpart.Position
  250.  
  251.                 local point, onscreen = WorldToViewportPoint(camera, cpos)
  252.                 ignore[ipos] = ignoreparent and cpart.Parent or cpart
  253.  
  254.                 if onscreen and not self:GetBlockingPart(campos, cpos, ignore) then
  255.                     local pdist = (position - Vector2.new(point.X, point.Y)).Magnitude --//Pixel Distance
  256.                     local wdist = (campos - cpos).Magnitude --//World Distance
  257.  
  258.                     if pdist <= self:GetRadiusAtDistance(self.RadiusPercentAt1, wdist) then
  259.                         local bias = self:GetBiasAtDistance(wdist) + pdist
  260.  
  261.                         if bias < leastbias or (bias == leastbias and wdist < leastwdist) then
  262.                             leastbias = bias
  263.                             leastwdist = wdist
  264.                             leastpdist = pdist
  265.                             part = cpart
  266.                         end
  267.                     end
  268.                 end
  269.             end
  270.  
  271.             ignore[ipos] = nil
  272.             return part, part and leastpdist <= self:GetRadiusAtDistance(self.SilentRadiusPercentAt1, leastwdist)
  273.         end
  274.     end
  275. end
  276.  
  277. --//Gets best player to target based on a viewport point
  278. function Aimbot:GetBestPlayerTargetFromViewportPoint(pos)
  279.     if self.Camera then
  280.         local plrs = GetPlayers(Players)
  281.         local len = #plrs
  282.  
  283.         if len > 0 then
  284.             local parts = {}
  285.             local lparts = 1
  286.  
  287.             for i = 1, len do
  288.                 local plr = plrs[i]
  289.                 local charac = plr.Character
  290.  
  291.                 if plr ~= LocalPlayer and charac then
  292.                     if self.TeamCheck and not plr.Neutral and plr.Team == LocalPlayer.Team then
  293.                         continue
  294.                     end
  295.                    
  296.                     if self.IsAliveCheck then
  297.                         local hum = FindFirstChildOfClass(charac, "Humanoid")
  298.  
  299.                         if not hum or hum.Health <= 0 then
  300.                             continue
  301.                         end
  302.                     end
  303.  
  304.                     if self.InvisibleCheck then
  305.                         local head = FindFirstChild(charac, "Head")
  306.  
  307.                         if not head or head.Transparency >= 1 then
  308.                             continue
  309.                         end
  310.                     end
  311.  
  312.                     local filtered = GetChildrenWhichIsA(charac, "BasePart")
  313.                     local lfiltered = #filtered
  314.  
  315.                     table.move(filtered, 1, lfiltered, lparts, parts)
  316.                     lparts = lparts + lfiltered
  317.                 end
  318.             end
  319.  
  320.             local target, silent = self:GetBestPartFromViewportPoint(pos, parts, true)
  321.  
  322.             if target then
  323.                 return target, silent
  324.             end
  325.         end
  326.     end
  327. end
  328.  
  329. --//Begins aimbot
  330. function Aimbot:Start()
  331.     self.Enabled = true
  332.  
  333.     local relative
  334.     local holding = false
  335.     local mspoof
  336.    
  337.     local lastframe = getclock()
  338.  
  339.     if not self.RenderStep then
  340.         local totalTime = 0
  341.         self.RenderStep = Connect(RunService.RenderStepped, function(delta)
  342.             totalTime += delta
  343.             if (totalTime < 1 / 144) then return end
  344.             totalTime = 0
  345.             if self.Enabled and relative then
  346.                 mousemoverel(relative.X, relative.Y)
  347.             end
  348.         end)
  349.     end
  350.  
  351.     if not self.Heartbeat then
  352.         local totalTime = 0
  353.         self.Heartbeat = Connect(RunService.Heartbeat, function(delta)
  354.             totalTime += delta
  355.             if (totalTime < 1 / 144) then return end
  356.             totalTime = 0
  357.             relative = nil
  358.            
  359.             if self.Enabled then
  360.                 local camera = self.Camera
  361.  
  362.                 if camera then
  363.                     local mpos = self:GetMouseViewportPoint()
  364.                     local target, silent = self:GetBestPlayerTargetFromViewportPoint(mpos)
  365.                        
  366.                     if target then
  367.                         local charac = target.Parent
  368.                         local lcharac = LocalPlayer.Character
  369.                         local cignore = GetChildrenWhichIsNotA(charac, "BasePart")
  370.  
  371.                         --if cignore then
  372.                         table.insert(cignore, lcharac)
  373.                         local mtarget = self:GetTargetFromViewportPoint(mpos, 5000, cignore)
  374.                         local bodyPart = (FindFirstChild(lcharac, "Head") or FindFirstChild(lcharac, "HumanoidRootPart"))
  375.                         local BlockingParts = self:GetBlockingPart(bodyPart and bodyPart.Position, target.Position, cignore)
  376.                         if silent and self.TriggerBot and lcharac and BlockingParts and BlockingParts:IsDescendantOf(charac) then
  377.                             if not holding then
  378.                                 holding = true
  379.                                 mouse1press()
  380.                             end
  381.                         elseif holding then
  382.                             holding = false
  383.                             mouse1release()
  384.                         end
  385.  
  386.                         if mtarget and IsDescendantOf(mtarget, charac) then
  387.                             mspoof = nil
  388.                            
  389.                             if not self.TargetPart then
  390.                                 return
  391.                             end
  392.                         elseif silent then
  393.                             mspoof = self:GetClosestEdgeFromViewportPoint(mpos, target)
  394.                         else
  395.                             mspoof = nil
  396.                         end
  397.                        
  398.                         target = (self.TargetPart and FindFirstChild(charac, self.TargetPart)) or target
  399.                         local pos, onscreen = WorldToViewportPoint(camera, target.Position)
  400.                        
  401.                         if onscreen then
  402.                             relative = (Vector2.new(pos.X, pos.Y) - mpos) / Vector2.new(self.XSmoothingPercent * self.WidthFactor, self.YSmoothingPercent * self.WidthFactor)
  403.                         end
  404.                     else
  405.                         if holding then
  406.                             holding = false
  407.                             mouse1release()
  408.                         end
  409.                        
  410.                         mspoof = nil
  411.                     end
  412.                 else
  413.                     if holding then
  414.                         holding = false
  415.                         mouse1release()
  416.                     end
  417.                        
  418.                     mspoof = nil
  419.                 end
  420.             else
  421.                 if holding then
  422.                     holding = false
  423.                     mouse1release()
  424.                 end
  425.                        
  426.                 mspoof = nil
  427.             end
  428.         end)
  429.     end
  430.     local Players2 = game.GetService(game, "Players");
  431.     local Client2 = Players2.LocalPlayer;
  432.     local Mouse2 = Client2.GetMouse(Client2);
  433.  
  434.     local old; old = hookmetamethod(game, "__index", function(i,v)
  435.         if old(i, "ClassName") == "PlayerMouse" and v == "Hit" or v == "hit" and not checkcaller() then
  436.             if mspoof then
  437.                 return CFrame.new(mspoof);
  438.             end
  439.         end
  440.         return old(i,v);
  441.     end)
  442.  
  443.     local old2; old2 = hookmetamethod(game, "__namecall", function(self2, ...)
  444.         if getnamecallmethod() == "ViewportPointToRay" and not checkcaller() and mspoof then
  445.             local args = {...}
  446.             local pos = GetMouseLocation(UserInputService)
  447.             if math.abs(args[1] - (pos.X + self.Offset.X)) <= 3 and math.abs(args[2] - (pos.Y + self.Offset.Y)) <= 3 then
  448.                 local newPos = workspace.CurrentCamera.WorldToViewportPoint(workspace.CurrentCamera, mspoof)
  449.                 args[1] = newPos.X
  450.                 args[2] = newPos.Y
  451.                 return old2(self2, table.unpack(args))
  452.             else
  453.                 if math.abs(args[1] - (Mouse2.X + self.Offset.X)) <= 3 and math.abs(args[2] - (Mouse2.Y + self.Offset.Y)) <= 3 then
  454.                     local newPos = workspace.CurrentCamera.WorldToViewportPoint(workspace.CurrentCamera, mspoof)
  455.                     args[1] = newPos.X
  456.                     args[2] = newPos.Y
  457.                     return old2(self2, table.unpack(args))
  458.                 end
  459.             end
  460.         elseif getnamecallmethod() == "ScreenPointToRay" and not checkcaller() and mspoof then
  461.             local args = {...}
  462.             local pos = GetMouseLocation(UserInputService)
  463.             if math.abs(args[1] - (pos.X + self.Offset.X)) <= 3 and math.abs(args[2] - (pos.Y + self.Offset.Y)) <= 3 then
  464.                 local newPos = workspace.CurrentCamera.WorldToScreenPoint(workspace.CurrentCamera, mspoof)
  465.                 args[1] = newPos.X
  466.                 args[2] = newPos.Y
  467.                 return old2(self2, table.unpack(args))
  468.             else
  469.                 if math.abs(args[1] - (Mouse2.X + self.Offset.X)) <= 3 and math.abs(args[2] - (Mouse2.Y + self.Offset.Y)) <= 3 then
  470.                     local newPos = workspace.CurrentCamera.WorldToScreenPoint(workspace.CurrentCamera, mspoof)
  471.                     args[1] = newPos.X
  472.                     args[2] = newPos.Y
  473.                     return old2(self2, table.unpack(args))
  474.                 end
  475.             end
  476.         end
  477.         return old2(self2, ...)
  478.     end)
  479.    
  480.     --[[
  481.     local old2; old2 = hookmetamethod(game, "__namecall", function(self2, ...)
  482.         local args = {...}
  483.         if getnamecallmethod() == "ScreenPointToRay" or getnamecallmethod() == "ViewportPointToRay" and mspoof then
  484.             local SecondPosition = game.GetService(game, "UserInputService").GetMouseLocation(game.GetService(game, "UserInputService"))
  485.             if args[1] == Mouse2.X and args[2] == Mouse2.Y or args[1] == SecondPosition.X and args[2] == SecondPosition.Y then
  486.                 local newPos = workspace.CurrentCamera.WorldToScreenPoint(workspace.CurrentCamera, mspoof)
  487.                 args[1] = newPos.X
  488.                 args[2] = newPos.Y
  489.                 return old2(self2, table.unpack(args))    
  490.             end  
  491.         end
  492.         return old2(self2, ...)
  493.     end)
  494.     --]]
  495. end
  496.  
  497. --//Completely kills aimbot, as opposed to enabled = false
  498. function Aimbot:Kill()
  499.     self.Enabled = false
  500.  
  501.     if self.RenderStep then
  502.         Disconnect(self.RenderStep)
  503.         self.RenderStep = nil
  504.     end
  505.  
  506.     if self.Heartbeat then
  507.         Disconnect(self.Heartbeat)
  508.         self.Heartbeat = nil
  509.     end
  510. end
  511.  
  512. --//Constructor
  513. function Aimbot.new(presets)
  514.     presets = presets or {}
  515.     UpdateTable(presets, Aimbot.DefaultSettings)
  516.  
  517.     local WallCheckParams = RaycastParams.new()
  518.     WallCheckParams.FilterType = Enum.RaycastFilterType.Blacklist
  519.     WallCheckParams.IgnoreWater = presets.IgnoreWater
  520.     WallCheckParams.FilterDescendantsInstances = presets.DefaultIgnore
  521.  
  522.     presets.WallCheckParams = WallCheckParams
  523.     return setmetatable(presets, Aimbot)
  524. end
  525.  
  526. --//Return with default settings
  527. return Aimbot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement