eruaaaaaaa

newwww

May 3rd, 2022 (edited)
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.22 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.     Aimbot = {
  68.         TrackingSettings = {
  69.             XSmoothingPercent = .6,
  70.             YSmoothingPercent = .6,
  71.             RadiusPercentAt1 = 250
  72.         },
  73.  
  74.         FlickSettings = {
  75.             XSmoothingPercent = 1.3,
  76.             YSmoothingPercent = 1.3,
  77.             RadiusPercentAt1 = 175
  78.         },
  79.  
  80.         DistanceBias = 1.6
  81.     },
  82.  
  83.     Silent = {
  84.         RadiusPercentAt1 = 145
  85.     },
  86.  
  87.     TriggerBot = {
  88.         Enabled = false,
  89.         Semi = false,
  90.         TimeBetweenClick = .3,
  91.         Delay = 160
  92.     },
  93.  
  94.     DeadZone = {
  95.         Enabled = false,
  96.         XSmoothingPercent = 1.3,
  97.         YSmoothingPercent = 1.3
  98.     },
  99.  
  100.     AutoPeak = {
  101.         Enabled = false
  102.     },
  103.  
  104.     General = {
  105.         Offset = Vector2.new(0, 0),
  106.         IgnoreWater = true,
  107.         DefaultIgnore = {},
  108.         TransparencyThreshold = 1,
  109.         IsAliveCheck = true,
  110.         TeamCheck = true,
  111.         InvisibleCheck = true,
  112.         SizeCheck = true,
  113.         RadiusCap = 300
  114.     }
  115. }
  116.  
  117. local LocalPlayer = Players.LocalPlayer
  118. local Mouse = LocalPlayer.GetMouse(LocalPlayer)
  119. local GuiInset = GuiService.GetGuiInset(GuiService)
  120.  
  121. local function OnCameraChange()
  122.     local cam = workspace.CurrentCamera
  123.     Aimbot.Camera = cam
  124.     Aimbot.ViewportSize = cam.ViewportSize
  125.     Aimbot.WidthFactor = cam.ViewportSize.X / 100
  126. end
  127.  
  128. local function UpdateTable(tab, update)
  129.     for name, value in pairs(update) do
  130.         if tab[name] == nil then
  131.             tab[name] = value
  132.         end
  133.     end
  134. end
  135.  
  136. local function GetChildrenWhichIsA(part, baseclass)
  137.     local parts = GetChildren(part)
  138.     local len = #parts
  139.     local filtered = {}
  140.     if len > 0 then
  141.         for i = 1, len do
  142.             local p = parts[i]
  143.             if IsA(p, baseclass) then
  144.                 table.insert(filtered, p)
  145.             end
  146.         end
  147.     end
  148.     return filtered
  149. end
  150.  
  151. local function GetChildrenWhichIsNotA(part, baseclass)
  152.     local parts = GetChildren(part)
  153.     local len = #parts
  154.     local filtered = {}
  155.     if len > 0 then
  156.         for i = 1, len do
  157.             local p = parts[i]
  158.             if not IsA(p, baseclass) then
  159.                 table.insert(filtered, p)
  160.             end
  161.         end
  162.     end
  163.     return filtered
  164. end
  165.  
  166. if workspace.CurrentCamera then
  167.     OnCameraChange()
  168. end
  169. Connect(GetPropertyChangedSignal(workspace, "CurrentCamera"), OnCameraChange)
  170.  
  171. --//Methods
  172.  
  173. --//Gets bias value at a given distance
  174. function Aimbot:GetBiasAtDistance(distance)
  175.     if self.Camera then
  176.         return distance * self.Aimbot.DistanceBias * self.WidthFactor
  177.     end
  178. end
  179.  
  180. --//Gets circle radius at a given distance
  181. function Aimbot:GetRadiusAtDistance(radius, distance)
  182.     if self.Camera then
  183.         if self.General.RadiusCap then
  184.             if distance >= self.General.RadiusCap then
  185.                 distance = self.General.RadiusCap
  186.             end
  187.         end
  188.         return radius / distance * self.WidthFactor
  189.     end
  190. end
  191.  
  192. --//Checks for parts obscuring camera, including terrain - unlike Camera:GetPartsObscuringTarget
  193. function Aimbot:GetBlockingPart(origin, position, ignore)
  194.     self.WallCheckParams.FilterDescendantsInstances = self.General.DefaultIgnore
  195.     local direction = position - origin
  196.     local thisignore = self.WallCheckParams.FilterDescendantsInstances
  197.     if ignore then
  198.         table.move(ignore, 1, #ignore, #thisignore+ 1, thisignore)
  199.     end
  200.     while true do
  201.         self.WallCheckParams.FilterDescendantsInstances = thisignore
  202.         local result = Raycast(workspace, origin, direction, self.WallCheckParams)
  203.         if result then
  204.             if self.IgnoreTransparent and result.Instance.ClassName ~= "Terrain" and result.Instance.Transparency >= self.General.TransparencyThreshold then
  205.                 table.insert(thisignore, result.Instance)
  206.             end
  207.             self.WallCheckParams.FilterDescendantsInstances = self.General.DefaultIgnore
  208.             return result.Instance
  209.         end
  210.         self.WallCheckParams.FilterDescendantsInstances = self.General.DefaultIgnore
  211.         return nil
  212.     end
  213. end
  214.  
  215. --//Gets target from viewport point
  216. function Aimbot:GetTargetFromViewportPoint(point, distance, ignore)
  217.     local camera = self.Camera
  218.     if camera then
  219.         local ray = ViewportPointToRay(camera, point.X, point.Y)
  220.         return self:GetBlockingPart(ray.Origin, ray.Origin + ray.Direction * distance, ignore)
  221.     end
  222. end
  223.  
  224. --//Gets closest edge on part from viewport point
  225. function Aimbot:GetClosestEdgeFromViewportPoint(point, part)
  226.     local camera = self.Camera
  227.     if camera then
  228.         local ray = ViewportPointToRay(camera, point.X, point.Y)
  229.         local ppos = part.Position
  230.         local distance = (ray.Origin - ppos).Magnitude
  231.         local direction = (ray.Origin + ray.Direction * distance - ppos).Unit
  232.         local size = part.Size; local half = part.Size / 2; local final = direction * size
  233.         return ppos + Vector3.new(
  234.             final.X < 0 and math.max(final.X, -half.X + size.X / 10) or math.min(final.X, half.X - size.X / 10),
  235.             final.Y < 0 and math.max(final.Y, -half.Y + size.Y / 10) or math.min(final.Y, half.Y - size.Y / 10),
  236.             final.Z < 0 and math.max(final.Z, -half.Z + size.Z / 10) or math.min(final.Z, half.Z - size.Z / 10)
  237.         )
  238.     end
  239. end
  240.  
  241. --//Gets mouse location with offset accounted for
  242. function Aimbot:GetMouseViewportPoint()
  243.     return GetMouseLocation(UserInputService) + self.General.Offset
  244. end
  245.  
  246. --//Gets best target from a list of parts and a viewport point, ignoreparent specifies whether to filter the entire parent
  247. function Aimbot:GetBestPartFromViewportPoint(position, parts, ignoreparent, ignore)
  248.     local camera = self.Camera
  249.     if camera then
  250.         local len = #parts
  251.         if len > 0 then
  252.             local leastbias, leastwdist, leastpdist, part = math.huge, math.huge, math.huge, nil
  253.             local campos = camera.CFrame.Position
  254.             ignore = ignore or {}
  255.             table.insert(ignore, LocalPlayer.Character)
  256.             local ipos = #ignore + 1
  257.             for i = 1, len do
  258.                 local cpart = parts[i]
  259.                 local cpos = cpart.Position
  260.                 local point, onscreen = WorldToViewportPoint(camera, cpos)
  261.                 ignore[ipos] = ignoreparent and cpart.Parent or cpart  
  262.                 if onscreen and not self:GetBlockingPart(campos, cpos, ignore) then
  263.                     local pdist = (position - Vector2.new(point.X, point.Y)).Magnitude
  264.                     local wdist = (campos - cpos).Magnitude
  265.                     local playerOb = cpart.Parent:FindFirstChildOfClass("Humanoid") and game:GetService("Players"):GetPlayerFromCharacter(cpart.Parent) or cpart.Parent.Parent:FindFirstChildOfClass("Humanoid") and game:GetService("Players"):GetPlayerFromCharacter(cpart.Parent.Parent)
  266.                     if pdist <= self:GetRadiusAtDistance(self.Targets[playerOb] and self.Aimbot.TrackingSettings.RadiusPercentAt1 or self.Aimbot.FlickSettings.RadiusPercentAt1, wdist) then
  267.                         local bias = self:GetBiasAtDistance(wdist) + pdist
  268.                         if bias < leastbias or (bias == leastbias and wdist < leastwdist) then
  269.                             leastbias = bias
  270.                             leastwdist = wdist
  271.                             leastpdist = pdist
  272.                             part = cpart
  273.                         end
  274.                     end
  275.                 end
  276.             end
  277.             ignore[ipos] = nil
  278.             return part, part and leastpdist <= self:GetRadiusAtDistance(self.Silent.RadiusPercentAt1, leastwdist)
  279.         end
  280.     end
  281. end
  282.  
  283. function Aimbot:IsMousePosition(pos1, pos2)
  284.     return math.abs(pos1 - (pos2 + self.General.Offset.X)) <= 3
  285. end
  286.  
  287. --//Gets best player to target based on a viewport point
  288. function Aimbot:GetBestPlayerTargetFromViewportPoint(pos, tracking)
  289.     if self.Camera then
  290.         local plrs = GetPlayers(Players)
  291.         local len = #plrs
  292.         if len > 0 then
  293.             local parts = {}
  294.             local lparts = 1
  295.             for i = 1, len do
  296.                 local plr = plrs[i]
  297.                 local charac = plr.Character
  298.                 if plr ~= LocalPlayer and charac then
  299.                     if self.General.TeamCheck and not plr.Neutral and plr.Team == LocalPlayer.Team then
  300.                         continue
  301.                     end
  302.                     if self.General.IsAliveCheck then
  303.                         local hum = FindFirstChildOfClass(charac, "Humanoid")
  304.                         if not hum or hum.Health <= 0 then
  305.                            continue  
  306.                         end
  307.                     end
  308.                     if self.General.InvisibleCheck then
  309.                         local head = FindFirstChild(charac, "Head")
  310.                         if not head or head.Transparency >= 1 then
  311.                             continue
  312.                         end
  313.                     end
  314.                     if self.General.SizeCheck then
  315.                         local hum = FindFirstChild(charac, "HumanoidRootPart")
  316.                         if not hum or hum.Size.X < 2 or hum.Size.Y < 2 or hum.Size.Z < 1 then
  317.                             continue
  318.                         end
  319.                     end
  320.                     local filtered = GetChildrenWhichIsA(charac, "BasePart")
  321.                     local lfiltered = #filtered
  322.                     table.move(filtered, 1, lfiltered, lparts, parts)
  323.                     lparts = lparts + lfiltered
  324.                 end
  325.             end
  326.             local target, silent = self:GetBestPartFromViewportPoint(pos, parts, true)
  327.             local plrz = target and game:GetService("Players"):GetPlayerFromCharacter(target.Parent) or "nil"
  328.             for aa,_ in pairs(self.Targets) do
  329.                 if aa ~= plrz then self.Targets[aa] = false end
  330.             end
  331.             if target then
  332.                 return target, silent
  333.             end
  334.         end
  335.     end
  336. end
  337.  
  338. function Aimbot:Start()
  339.     self.Enabled = true
  340.     self.LastTrigger = 0
  341.     self.TriggerPaused = false
  342.     self.Targets = {}; setmetatable(self.Targets, {__index = function(s, k)
  343.         s[k] = false
  344.         return false
  345.     end})
  346.     local relative
  347.     local holding = false
  348.     local mspoof
  349.     if not self.RenderStep then
  350.         local totalTime = 0
  351.         self.RenderStep = Connect(RunService.RenderStepped, function(delta)
  352.             totalTime += delta
  353.             if (totalTime < 1 / 144) then
  354.                 return
  355.             end
  356.             totalTime = 0
  357.             if self.Enabled and relative then
  358.                 mousemoverel(relative.X, relative.Y)
  359.             end
  360.         end)
  361.     end
  362.     if not self.Heartbeat then
  363.         local totalTime = 0
  364.         self.Heartbeat = Connect(RunService.Heartbeat, function(delta)
  365.             totalTime += delta
  366.             if (totalTime < 1 / 144) then
  367.                 return
  368.             end
  369.             totalTime = 0
  370.             relative = nil
  371.             if self.Enabled then
  372.                 local camera = self.Camera
  373.                 if camera then
  374.                     local mpos = self:GetMouseViewportPoint()
  375.                     local target, silent = self:GetBestPlayerTargetFromViewportPoint(mpos)
  376.                     if not target then
  377.                         if holding then
  378.                             holding = false
  379.                             mouse1release()
  380.                         end
  381.                     end
  382.                     if target then
  383.                         local charac = target.Parent
  384.                         local plrz = game:GetService("Players"):GetPlayerFromCharacter(charac)
  385.                         local lcharac = LocalPlayer.Character
  386.                         local cignore = GetChildrenWhichIsNotA(charac, "BasePart")
  387.                         table.insert(cignore, lcharac)
  388.                         local mtarget = self:GetTargetFromViewportPoint(mpos, 5000, cignore)
  389.                         local bodyPart = (FindFirstChild(lcharac, "Head") or FindFirstChild(lcharac, "HumanoidRootPart"))
  390.                         local blockingParts = self:GetBlockingPart(bodyPart and bodyPart.Position, target.Position, cignore)
  391.                         if silent and self.TriggerBot.Enabled and lcharac and blockingParts and blockingParts:IsDescendantOf(charac) then
  392.                             if not holding then
  393.                                 holding = true
  394.                                 mouse1press()
  395.                             else
  396.                                 if self.TriggerBot.Semi and (tick() - self.LastTrigger) >= self.TriggerBot.TimeBetweenClick and not self.TriggerPaused then
  397.                                     self.TriggerPaused = true
  398.                                     task.wait(self.TriggerBot.Delay / 1000)
  399.                                     mouse1click()
  400.                                     self.LastTrigger = tick()
  401.                                     self.TriggerPaused = false
  402.                                 end
  403.                             end
  404.                         elseif silent and self.TriggerBot.Enabled and lcharac and (not blockingParts or not blockingParts:IsDescendantOf(charac)) then
  405.                             if holding then
  406.                                 holding = false
  407.                                 mouse1release()
  408.                             end
  409.                         end
  410.  
  411.                         if mtarget and IsDescendantOf(mtarget, charac) then
  412.                             mspoof = nil
  413.                             self.Targets[plrz] = true
  414.                         elseif silent then
  415.                             mspoof = self:GetClosestEdgeFromViewportPoint(mpos, target)
  416.                         else
  417.                             mspoof = nil
  418.                         end
  419.  
  420.                         local pos, onscreen = WorldToViewportPoint(camera, self:GetClosestEdgeFromViewportPoint(mpos, target))
  421.                         if onscreen then
  422.                             if self.Targets[plrz] then
  423.                                 relative = (Vector2.new(pos.X, pos.Y) - mpos) / Vector2.new(self.Aimbot.TrackingSettings.XSmoothingPercent * self.WidthFactor, self.Aimbot.TrackingSettings.YSmoothingPercent * self.WidthFactor)                                
  424.                             else
  425.                                 relative = (Vector2.new(pos.X, pos.Y) - mpos) / Vector2.new(self.Aimbot.FlickSettings.XSmoothingPercent * self.WidthFactor, self.Aimbot.FlickSettings.YSmoothingPercent * self.WidthFactor)                                
  426.                             end
  427.                         end
  428.                     end
  429.                 end
  430.             end
  431.         end)
  432.     end
  433.  
  434.     local old; old = hookmetamethod(game, "__index", function(i,v)
  435.         if string.lower(v) == "hit" and mspoof then
  436.             if old(i, "ClassName") == "Mouse" or old(i, "ClassName") == "PlayerMouse" then
  437.                 if not checkcaller() then
  438.                     return CFrame.new(mspoof)
  439.                 end
  440.             end
  441.         end
  442.         return old(i,v)
  443.     end)
  444.  
  445.     local old2; old2 = hookmetamethod(game, "__namecall", function(self2, ...)
  446.         local args = {...}
  447.         if getnamecallmethod() == "ViewportPointToRay" and not checkcaller() and mspoof then
  448.             local pos = GetMouseLocation(UserInputService)
  449.             if math.abs(args[1] - (pos.X + self.General.Offset.X)) <= 3  and math.abs(args[2] - (pos.Y + self.General.Offset.Y)) <= 3 then
  450.                 local newPos = WorldToViewportPoint(self.Camera, mspoof)
  451.                 args[1] = newPos.X
  452.                 args[2] = newPos.Y
  453.                 return old2(self2, table.unpack(args))
  454.             else
  455.                 local pos = Vector2.new(Mouse.X, Mouse.Y)
  456.                 if math.abs(args[1] - (pos.X + self.General.Offset.X)) <= 3  and math.abs(args[2] - (pos.Y + self.General.Offset.Y)) <= 3 then
  457.                     local newPos = WorldToViewportPoint(self.Camera, mspoof)
  458.                     args[1] = newPos.X
  459.                     args[2] = newPos.Y
  460.                     return old2(self2, table.unpack(args))
  461.                 end
  462.             end
  463.         elseif getnamecallmethod() == "ScreenPointToRay" and not checkcaller() and  mspoof then
  464.             local pos = GetMouseLocation(UserInputService)
  465.             if math.abs(args[1] - (pos.X + self.General.Offset.X)) <= 3  and math.abs(args[2] - (pos.Y + self.General.Offset.Y)) <= 3 then
  466.                 local newPos = WorldToScreenPoint(self.Camera, mspoof)
  467.                 args[1] = newPos.X
  468.                 args[2] = newPos.Y
  469.                 return old2(self2, table.unpack(args))
  470.             else
  471.                 local pos = Vector2.new(Mouse.X, Mouse.Y)
  472.                 if math.abs(args[1] - (pos.X + self.General.Offset.X)) <= 3  and math.abs(args[2] - (pos.Y + self.General.Offset.Y)) <= 3 then
  473.                     local newPos = WorldToScreenPoint(self.Camera, mspoof)
  474.                     args[1] = newPos.X
  475.                     args[2] = newPos.Y
  476.                     return old2(self2, table.unpack(args))
  477.                 end
  478.             end
  479.         end
  480.         return old2(self2, ...)
  481.     end)
  482. end
  483.  
  484. function Aimbot:Kill()
  485.     self.Enabled = false
  486.     if self.RenderStep then
  487.         Disconnect(self.RenderStep)
  488.         self.RenderStep = nil
  489.     end
  490.     if self.Heartbeat then
  491.         Disconnect(self.Heartbeat)
  492.         self.Heartbeat = nil
  493.     end
  494. end
  495.  
  496. function Aimbot.new(presets)
  497.     presets = presets or {}
  498.     UpdateTable(presets, Aimbot.DefaultSettings)
  499.     local WallCheckParams = RaycastParams.new()
  500.     WallCheckParams.FilterType = Enum.RaycastFilterType.Blacklist
  501.     WallCheckParams.IgnoreWater = presets.General.IgnoreWater
  502.     WallCheckParams.FilterDescendantsInstances = presets.General.DefaultIgnore
  503.     presets.WallCheckParams = WallCheckParams
  504.     return setmetatable(presets, Aimbot)
  505. end
  506.  
  507. return Aimbot
Add Comment
Please, Sign In to add comment