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