Guest User

Universal silent aim

a guest
Mar 6th, 2023
3,128
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.41 KB | Source Code | 0 1
  1. -- universal aim fixed by exponential!
  2. if not game:IsLoaded() then
  3. game.Loaded:Wait()
  4. end
  5.  
  6. if not syn or not protectgui then
  7. getgenv().protectgui = function() end
  8. end
  9.  
  10. local SilentAimSettings = {
  11. Enabled = false,
  12.  
  13. ClassName = "Universal Silent Aim - Averiias, Stefanuk12, xaxa",
  14. ToggleKey = "RightAlt",
  15.  
  16. TeamCheck = false,
  17. VisibleCheck = false,
  18. TargetPart = "HumanoidRootPart",
  19. SilentAimMethod = "Raycast",
  20.  
  21. FOVRadius = 130,
  22. FOVVisible = false,
  23. ShowSilentAimTarget = false,
  24.  
  25. MouseHitPrediction = false,
  26. MouseHitPredictionAmount = 0.165,
  27. HitChance = 100
  28. }
  29.  
  30. -- variables
  31. getgenv().SilentAimSettings = Settings
  32. local MainFileName = "UniversalSilentAim"
  33. local SelectedFile, FileToSave = "", ""
  34.  
  35. local Camera = workspace.CurrentCamera
  36. local Players = game:GetService("Players")
  37. local RunService = game:GetService("RunService")
  38. local GuiService = game:GetService("GuiService")
  39. local UserInputService = game:GetService("UserInputService")
  40. local HttpService = game:GetService("HttpService")
  41.  
  42. local LocalPlayer = Players.LocalPlayer
  43. local Mouse = LocalPlayer:GetMouse()
  44.  
  45. local GetChildren = game.GetChildren
  46. local GetPlayers = Players.GetPlayers
  47. local WorldToScreen = Camera.WorldToScreenPoint
  48. local WorldToViewportPoint = Camera.WorldToViewportPoint
  49. local GetPartsObscuringTarget = Camera.GetPartsObscuringTarget
  50. local FindFirstChild = game.FindFirstChild
  51. local RenderStepped = RunService.RenderStepped
  52. local GuiInset = GuiService.GetGuiInset
  53. local GetMouseLocation = UserInputService.GetMouseLocation
  54.  
  55. local resume = coroutine.resume
  56. local create = coroutine.create
  57.  
  58. local ValidTargetParts = {"Head", "HumanoidRootPart"}
  59. local PredictionAmount = 0.165
  60.  
  61. local mouse_box = Drawing.new("Square")
  62. mouse_box.Visible = true
  63. mouse_box.ZIndex = 999
  64. mouse_box.Color = Color3.fromRGB(54, 57, 241)
  65. mouse_box.Thickness = 20
  66. mouse_box.Size = Vector2.new(20, 20)
  67. mouse_box.Filled = true
  68.  
  69. local fov_circle = Drawing.new("Circle")
  70. fov_circle.Thickness = 1
  71. fov_circle.NumSides = 100
  72. fov_circle.Radius = 180
  73. fov_circle.Filled = false
  74. fov_circle.Visible = false
  75. fov_circle.ZIndex = 999
  76. fov_circle.Transparency = 1
  77. fov_circle.Color = Color3.fromRGB(54, 57, 241)
  78.  
  79. local ExpectedArguments = {
  80. FindPartOnRayWithIgnoreList = {
  81. ArgCountRequired = 3,
  82. Args = {
  83. "Instance", "Ray", "table", "boolean", "boolean"
  84. }
  85. },
  86. FindPartOnRayWithWhitelist = {
  87. ArgCountRequired = 3,
  88. Args = {
  89. "Instance", "Ray", "table", "boolean"
  90. }
  91. },
  92. FindPartOnRay = {
  93. ArgCountRequired = 2,
  94. Args = {
  95. "Instance", "Ray", "Instance", "boolean", "boolean"
  96. }
  97. },
  98. Raycast = {
  99. ArgCountRequired = 3,
  100. Args = {
  101. "Instance", "Vector3", "Vector3", "RaycastParams"
  102. }
  103. }
  104. }
  105.  
  106. function CalculateChance(Percentage)
  107. -- // Floor the percentage
  108. Percentage = math.floor(Percentage)
  109.  
  110. -- // Get the chance
  111. local chance = math.floor(Random.new().NextNumber(Random.new(), 0, 1) * 100) / 100
  112.  
  113. -- // Return
  114. return chance <= Percentage / 100
  115. end
  116.  
  117.  
  118. --[[file handling]] do
  119. if not isfolder(MainFileName) then
  120. makefolder(MainFileName);
  121. end
  122.  
  123. if not isfolder(string.format("%s/%s", MainFileName, tostring(game.PlaceId))) then
  124. makefolder(string.format("%s/%s", MainFileName, tostring(game.PlaceId)))
  125. end
  126. end
  127.  
  128. local Files = listfiles(string.format("%s/%s", "UniversalSilentAim", tostring(game.PlaceId)))
  129.  
  130. -- functions
  131. local function GetFiles() -- credits to the linoria lib for this function, listfiles returns the files full path and its annoying
  132. local out = {}
  133. for i = 1, #Files do
  134. local file = Files[i]
  135. if file:sub(-4) == '.lua' then
  136. -- i hate this but it has to be done ...
  137.  
  138. local pos = file:find('.lua', 1, true)
  139. local start = pos
  140.  
  141. local char = file:sub(pos, pos)
  142. while char ~= '/' and char ~= '\\' and char ~= '' do
  143. pos = pos - 1
  144. char = file:sub(pos, pos)
  145. end
  146.  
  147. if char == '/' or char == '\\' then
  148. table.insert(out, file:sub(pos + 1, start - 1))
  149. end
  150. end
  151. end
  152.  
  153. return out
  154. end
  155.  
  156. local function UpdateFile(FileName)
  157. assert(FileName or FileName == "string", "oopsies");
  158. writefile(string.format("%s/%s/%s.lua", MainFileName, tostring(game.PlaceId), FileName), HttpService:JSONEncode(SilentAimSettings))
  159. end
  160.  
  161. local function LoadFile(FileName)
  162. assert(FileName or FileName == "string", "oopsies");
  163.  
  164. local File = string.format("%s/%s/%s.lua", MainFileName, tostring(game.PlaceId), FileName)
  165. local ConfigData = HttpService:JSONDecode(readfile(File))
  166. for Index, Value in next, ConfigData do
  167. SilentAimSettings[Index] = Value
  168. end
  169. end
  170.  
  171. local function getPositionOnScreen(Vector)
  172. local Vec3, OnScreen = WorldToScreen(Camera, Vector)
  173. return Vector2.new(Vec3.X, Vec3.Y), OnScreen
  174. end
  175.  
  176. local function ValidateArguments(Args, RayMethod)
  177. local Matches = 0
  178. if #Args < RayMethod.ArgCountRequired then
  179. return false
  180. end
  181. for Pos, Argument in next, Args do
  182. if typeof(Argument) == RayMethod.Args[Pos] then
  183. Matches = Matches + 1
  184. end
  185. end
  186. return Matches >= RayMethod.ArgCountRequired
  187. end
  188.  
  189. local function getDirection(Origin, Position)
  190. return (Position - Origin).Unit * 1000
  191. end
  192.  
  193. local function getMousePosition()
  194. return GetMouseLocation(UserInputService)
  195. end
  196.  
  197. local function IsPlayerVisible(Player)
  198. local PlayerCharacter = Player.Character
  199. local LocalPlayerCharacter = LocalPlayer.Character
  200.  
  201. if not (PlayerCharacter or LocalPlayerCharacter) then return end
  202.  
  203. local PlayerRoot = FindFirstChild(PlayerCharacter, Options.TargetPart.Value) or FindFirstChild(PlayerCharacter, "HumanoidRootPart")
  204.  
  205. if not PlayerRoot then return end
  206.  
  207. local CastPoints, IgnoreList = {PlayerRoot.Position, LocalPlayerCharacter, PlayerCharacter}, {LocalPlayerCharacter, PlayerCharacter}
  208. local ObscuringObjects = #GetPartsObscuringTarget(Camera, CastPoints, IgnoreList)
  209.  
  210. return ((ObscuringObjects == 0 and true) or (ObscuringObjects > 0 and false))
  211. end
  212.  
  213. local function getClosestPlayer()
  214. if not Options.TargetPart.Value then return end
  215. local Closest
  216. local DistanceToMouse
  217. for _, Player in next, GetPlayers(Players) do
  218. if Player == LocalPlayer then continue end
  219. if Toggles.TeamCheck.Value and Player.Team == LocalPlayer.Team then continue end
  220.  
  221. local Character = Player.Character
  222. if not Character then continue end
  223.  
  224. if Toggles.VisibleCheck.Value and not IsPlayerVisible(Player) then continue end
  225.  
  226. local HumanoidRootPart = FindFirstChild(Character, "HumanoidRootPart")
  227. local Humanoid = FindFirstChild(Character, "Humanoid")
  228. if not HumanoidRootPart or not Humanoid or Humanoid and Humanoid.Health <= 0 then continue end
  229.  
  230. local ScreenPosition, OnScreen = getPositionOnScreen(HumanoidRootPart.Position)
  231. if not OnScreen then continue end
  232.  
  233. local Distance = (getMousePosition() - ScreenPosition).Magnitude
  234. if Distance <= (DistanceToMouse or Options.Radius.Value or 2000) then
  235. Closest = ((Options.TargetPart.Value == "Random" and Character[ValidTargetParts[math.random(1, #ValidTargetParts)]]) or Character[Options.TargetPart.Value])
  236. DistanceToMouse = Distance
  237. end
  238. end
  239. return Closest
  240. end
  241.  
  242. -- ui creating & handling
  243. local Library = loadstring(game:HttpGet("https://raw.githubusercontent.com/violin-suzutsuki/LinoriaLib/main/Library.lua"))()
  244. Library:SetWatermark("github.com/Averiias")
  245.  
  246. local Window = Library:CreateWindow("Universal Silent Aim, by Averiias, xaxa, and Stefanuk12, fixed by Exponential")
  247. local GeneralTab = Window:AddTab("General")
  248. local MainBOX = GeneralTab:AddLeftTabbox("Main") do
  249. local Main = MainBOX:AddTab("Main")
  250.  
  251. Main:AddToggle("aim_Enabled", {Text = "Enabled"}):AddKeyPicker("aim_Enabled_KeyPicker", {Default = "RightAlt", SyncToggleState = true, Mode = "Toggle", Text = "Enabled", NoUI = false});
  252. Options.aim_Enabled_KeyPicker:OnClick(function()
  253. SilentAimSettings.Enabled = not SilentAimSettings.Enabled
  254.  
  255. Toggles.aim_Enabled.Value = SilentAimSettings.Enabled
  256. Toggles.aim_Enabled:SetValue(SilentAimSettings.Enabled)
  257.  
  258. mouse_box.Visible = SilentAimSettings.Enabled
  259. end)
  260.  
  261. Main:AddToggle("TeamCheck", {Text = "Team Check", Default = SilentAimSettings.TeamCheck}):OnChanged(function()
  262. SilentAimSettings.TeamCheck = Toggles.TeamCheck.Value
  263. end)
  264. Main:AddToggle("VisibleCheck", {Text = "Visible Check", Default = SilentAimSettings.VisibleCheck}):OnChanged(function()
  265. SilentAimSettings.VisibleCheck = Toggles.VisibleCheck.Value
  266. end)
  267. Main:AddDropdown("TargetPart", {Text = "Target Part", Default = SilentAimSettings.TargetPart, Values = {"Head", "HumanoidRootPart", "Random"}}):OnChanged(function()
  268. SilentAimSettings.TargetPart = Options.TargetPart.Value
  269. end)
  270. Main:AddDropdown("Method", {Text = "Silent Aim Method", Default = SilentAimSettings.SilentAimMethod, Values = {
  271. "Raycast","FindPartOnRay",
  272. "FindPartOnRayWithWhitelist",
  273. "FindPartOnRayWithIgnoreList",
  274. "Mouse.Hit/Target"
  275. }}):OnChanged(function()
  276. SilentAimSettings.SilentAimMethod = Options.Method.Value
  277. end)
  278. Main:AddSlider('HitChance', {
  279. Text = 'Hit chance',
  280. Default = 100,
  281. Min = 0,
  282. Max = 100,
  283. Rounding = 1,
  284.  
  285. Compact = false,
  286. })
  287. Options.HitChance:OnChanged(function()
  288. SilentAimSettings.HitChance = Options.HitChance.Value
  289. end)
  290. end
  291.  
  292. local MiscellaneousBOX = GeneralTab:AddLeftTabbox("Miscellaneous")
  293. local FieldOfViewBOX = GeneralTab:AddLeftTabbox("Field Of View") do
  294. local Main = FieldOfViewBOX:AddTab("Visuals")
  295.  
  296. Main:AddToggle("Visible", {Text = "Show FOV Circle"}):AddColorPicker("Color", {Default = Color3.fromRGB(54, 57, 241)}):OnChanged(function()
  297. fov_circle.Visible = Toggles.Visible.Value
  298. SilentAimSettings.FOVVisible = Toggles.Visible.Value
  299. end)
  300. Main:AddSlider("Radius", {Text = "FOV Circle Radius", Min = 0, Max = 360, Default = 130, Rounding = 0}):OnChanged(function()
  301. fov_circle.Radius = Options.Radius.Value
  302. SilentAimSettings.FOVRadius = Options.Radius.Value
  303. end)
  304. Main:AddToggle("MousePosition", {Text = "Show Silent Aim Target"}):AddColorPicker("MouseVisualizeColor", {Default = Color3.fromRGB(54, 57, 241)}):OnChanged(function()
  305. mouse_box.Visible = Toggles.MousePosition.Value
  306. SilentAimSettings.ShowSilentAimTarget = Toggles.MousePosition.Value
  307. end)
  308. local PredictionTab = MiscellaneousBOX:AddTab("Prediction")
  309. PredictionTab:AddToggle("Prediction", {Text = "Mouse.Hit/Target Prediction"}):OnChanged(function()
  310. SilentAimSettings.MouseHitPrediction = Toggles.Prediction.Value
  311. end)
  312. PredictionTab:AddSlider("Amount", {Text = "Prediction Amount", Min = 0.165, Max = 1, Default = 0.165, Rounding = 3}):OnChanged(function()
  313. PredictionAmount = Options.Amount.Value
  314. SilentAimSettings.MouseHitPredictionAmount = Options.Amount.Value
  315. end)
  316. end
  317.  
  318. local CreateConfigurationBOX = GeneralTab:AddRightTabbox("Create Configuration") do
  319. local Main = CreateConfigurationBOX:AddTab("Create Configuration")
  320.  
  321. Main:AddInput("CreateConfigTextBox", {Default = "", Numeric = false, Finished = false, Text = "Create Configuration to Create", Tooltip = "Creates a configuration file containing settings you can save and load", Placeholder = "File Name here"}):OnChanged(function()
  322. if Options.CreateConfigTextBox.Value and string.len(Options.CreateConfigTextBox.Value) ~= "" then
  323. FileToSave = Options.CreateConfigTextBox.Value
  324. end
  325. end)
  326.  
  327. Main:AddButton("Create Configuration File", function()
  328. if FileToSave ~= "" or FileToSave ~= nil then
  329. UpdateFile(FileToSave)
  330. end
  331. end)
  332. end
  333.  
  334. local SaveConfigurationBOX = GeneralTab:AddRightTabbox("Save Configuration") do
  335. local Main = SaveConfigurationBOX:AddTab("Save Configuration")
  336. Main:AddDropdown("SaveConfigurationDropdown", {Values = GetFiles(), Text = "Choose Configuration to Save"})
  337. Main:AddButton("Save Configuration", function()
  338. if Options.SaveConfigurationDropdown.Value then
  339. UpdateFile(Options.SaveConfigurationDropdown.Value)
  340. end
  341. end)
  342. end
  343.  
  344. local LoadConfigurationBOX = GeneralTab:AddRightTabbox("Load Configuration") do
  345. local Main = LoadConfigurationBOX:AddTab("Load Configuration")
  346.  
  347. Main:AddDropdown("LoadConfigurationDropdown", {Values = GetFiles(), Text = "Choose Configuration to Load"})
  348. Main:AddButton("Load Configuration", function()
  349. if table.find(GetFiles(), Options.LoadConfigurationDropdown.Value) then
  350. LoadFile(Options.LoadConfigurationDropdown.Value)
  351.  
  352. Toggles.TeamCheck:SetValue(SilentAimSettings.TeamCheck)
  353. Toggles.VisibleCheck:SetValue(SilentAimSettings.VisibleCheck)
  354. Options.TargetPart:SetValue(SilentAimSettings.TargetPart)
  355. Options.Method:SetValue(SilentAimSettings.SilentAimMethod)
  356. Toggles.Visible:SetValue(SilentAimSettings.FOVVisible)
  357. Options.Radius:SetValue(SilentAimSettings.FOVRadius)
  358. Toggles.MousePosition:SetValue(SilentAimSettings.ShowSilentAimTarget)
  359. Toggles.Prediction:SetValue(SilentAimSettings.MouseHitPrediction)
  360. Options.Amount:SetValue(SilentAimSettings.MouseHitPredictionAmount)
  361. Options.HitChance:SetValue(SilentAimSettings.HitChance)
  362. end
  363. end)
  364. end
  365.  
  366. resume(create(function()
  367. RenderStepped:Connect(function()
  368. if Toggles.MousePosition.Value and Toggles.aim_Enabled.Value then
  369. if getClosestPlayer() then
  370. local Root = getClosestPlayer().Parent.PrimaryPart or getClosestPlayer()
  371. local RootToViewportPoint, IsOnScreen = WorldToViewportPoint(Camera, Root.Position);
  372. -- using PrimaryPart instead because if your Target Part is "Random" it will flicker the square between the Target's Head and HumanoidRootPart (its annoying)
  373.  
  374. mouse_box.Visible = IsOnScreen
  375. mouse_box.Position = Vector2.new(RootToViewportPoint.X, RootToViewportPoint.Y)
  376. else
  377. mouse_box.Visible = false
  378. mouse_box.Position = Vector2.new()
  379. end
  380. end
  381.  
  382. if Toggles.Visible.Value then
  383. fov_circle.Visible = Toggles.Visible.Value
  384. fov_circle.Color = Options.Color.Value
  385. fov_circle.Position = getMousePosition()
  386. end
  387. end)
  388. end))
  389.  
  390. -- hooks
  391. local oldNamecall
  392. oldNamecall = hookmetamethod(game, "__namecall", newcclosure(function(...)
  393. local Method = getnamecallmethod()
  394. local Arguments = {...}
  395. local self = Arguments[1]
  396. local chance = CalculateChance(SilentAimSettings.HitChance)
  397. if Toggles.aim_Enabled.Value and self == workspace and not checkcaller() and chance == true then
  398. if Method == "FindPartOnRayWithIgnoreList" and Options.Method.Value == Method then
  399. if ValidateArguments(Arguments, ExpectedArguments.FindPartOnRayWithIgnoreList) then
  400. local A_Ray = Arguments[2]
  401.  
  402. local HitPart = getClosestPlayer()
  403. if HitPart then
  404. local Origin = A_Ray.Origin
  405. local Direction = getDirection(Origin, HitPart.Position)
  406. Arguments[2] = Ray.new(Origin, Direction)
  407.  
  408. return oldNamecall(unpack(Arguments))
  409. end
  410. end
  411. elseif Method == "FindPartOnRayWithWhitelist" and Options.Method.Value == Method then
  412. if ValidateArguments(Arguments, ExpectedArguments.FindPartOnRayWithWhitelist) then
  413. local A_Ray = Arguments[2]
  414.  
  415. local HitPart = getClosestPlayer()
  416. if HitPart then
  417. local Origin = A_Ray.Origin
  418. local Direction = getDirection(Origin, HitPart.Position)
  419. Arguments[2] = Ray.new(Origin, Direction)
  420.  
  421. return oldNamecall(unpack(Arguments))
  422. end
  423. end
  424. elseif (Method == "FindPartOnRay" or Method == "findPartOnRay") and Options.Method.Value:lower() == Method:lower() then
  425. if ValidateArguments(Arguments, ExpectedArguments.FindPartOnRay) then
  426. local A_Ray = Arguments[2]
  427.  
  428. local HitPart = getClosestPlayer()
  429. if HitPart then
  430. local Origin = A_Ray.Origin
  431. local Direction = getDirection(Origin, HitPart.Position)
  432. Arguments[2] = Ray.new(Origin, Direction)
  433.  
  434. return oldNamecall(unpack(Arguments))
  435. end
  436. end
  437. elseif Method == "Raycast" and Options.Method.Value == Method then
  438. if ValidateArguments(Arguments, ExpectedArguments.Raycast) then
  439. local A_Origin = Arguments[2]
  440.  
  441. local HitPart = getClosestPlayer()
  442. if HitPart then
  443. Arguments[3] = getDirection(A_Origin, HitPart.Position)
  444.  
  445. return oldNamecall(unpack(Arguments))
  446. end
  447. end
  448. end
  449. end
  450. return oldNamecall(...)
  451. end))
  452.  
  453. local oldIndex = nil
  454. oldIndex = hookmetamethod(game, "__index", newcclosure(function(self, Index)
  455. if self == Mouse and not checkcaller() and Toggles.aim_Enabled.Value and Options.Method.Value == "Mouse.Hit/Target" and getClosestPlayer() then
  456. local HitPart = getClosestPlayer()
  457.  
  458. if Index == "Target" or Index == "target" then
  459. return HitPart
  460. elseif Index == "Hit" or Index == "hit" then
  461. return ((Toggles.Prediction.Value and (HitPart.CFrame + (HitPart.Velocity * PredictionAmount))) or (not Toggles.Prediction.Value and HitPart.CFrame))
  462. elseif Index == "X" or Index == "x" then
  463. return self.X
  464. elseif Index == "Y" or Index == "y" then
  465. return self.Y
  466. elseif Index == "UnitRay" then
  467. return Ray.new(self.Origin, (self.Hit - self.Origin).Unit)
  468. end
  469. end
  470.  
  471. return oldIndex(self, Index)
  472. end))
Advertisement
Add Comment
Please, Sign In to add comment