-
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathClient.luau
More file actions
798 lines (709 loc) · 19.5 KB
/
Client.luau
File metadata and controls
798 lines (709 loc) · 19.5 KB
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
-------------------
-- Adonis Client --
-------------------
--!nocheck
--[[
This module is part of Adonis 1.0 and contains lots of old code;
future updates will generally only be made to fix bugs, typos or functionality-affecting problems.
If you find bugs or similar issues, please submit an issue report to us!
]]
--// Load Order List
local CORE_LOADING_ORDER = table.freeze({
--// Required by most modules
"Variables",
"Functions",
--// Core functionality
"Core",
"Remote",
"UI",
"Process",
--// Misc
"Anti",
})
--// Loccalllsssss
local _G, game, script, getfenv, setfenv, workspace, getmetatable, setmetatable, loadstring, coroutine, rawequal, typeof, print, math, warn, error, pcall, xpcall, select, rawset, rawget, ipairs, pairs, next, Rect, Axes, os, time, Faces, unpack, string, Color3, newproxy, tostring, tonumber, Instance, TweenInfo, BrickColor, NumberRange, ColorSequence, NumberSequence, ColorSequenceKeypoint, NumberSequenceKeypoint, PhysicalProperties, Region3int16, Vector3int16, require, table, type, wait, Enum, UDim, UDim2, Vector2, Vector3, Region3, CFrame, Ray, delay, spawn, task, tick, assert =
_G,
game,
script,
getfenv,
setfenv,
workspace,
getmetatable,
setmetatable,
loadstring,
coroutine,
rawequal,
typeof,
print,
math,
warn,
error,
pcall,
xpcall,
select,
rawset,
rawget,
ipairs,
pairs,
next,
Rect,
Axes,
os,
time,
Faces,
table.unpack,
string,
Color3,
newproxy,
tostring,
tonumber,
Instance,
TweenInfo,
BrickColor,
NumberRange,
ColorSequence,
NumberSequence,
ColorSequenceKeypoint,
NumberSequenceKeypoint,
PhysicalProperties,
Region3int16,
Vector3int16,
require,
table,
type,
task.wait,
Enum,
UDim,
UDim2,
Vector2,
Vector3,
Region3,
CFrame,
Ray,
task.delay,
task.defer,
task,
tick,
function(cond, errMsg)
return cond or error(errMsg or "assertion failed!", 2)
end
local SERVICES_WE_USE = table.freeze({
"Workspace",
"Players",
"Lighting",
"ReplicatedStorage",
"ReplicatedFirst",
"ScriptContext",
"JointsService",
"LogService",
"Teams",
"SoundService",
"StarterGui",
"StarterPack",
"StarterPlayer",
"GroupService",
"MarketplaceService",
"HttpService",
"TestService",
"RunService",
"NetworkClient",
})
local oldPrint = print
print = function(...)
oldPrint(":: Adonis ::", ...)
end
local oldWarn = warn
warn = function(...)
oldWarn(":: Adonis ::", ...)
end
--// Logging
local clientLog = {}
local dumplog = function()
print("Dumping client log...")
for _, v in clientLog do
print(v)
end
end
local log = function(...)
table.insert(clientLog, table.concat({ ... }, " "))
end
--// Dump log on disconnect
local Folder = script.Parent
local isStudio = game:GetService("RunService"):IsStudio()
game:GetService("NetworkClient").ChildRemoved:Connect(function(p)
if not isStudio or Folder:FindFirstChild("ADONIS_DEBUGMODE_ENABLED") then
print("~! PLAYER DISCONNECTED/KICKED! DUMPING ADONIS CLIENT LOG!")
dumplog()
end
end)
local unique = {}
local origEnv = getfenv()
setfenv(1, setmetatable({}, { __metatable = unique }))
local startTime = time()
local oldInstNew = Instance.new
local oldReq = require
local locals = {}
local client = {}
local service = {}
local ServiceSpecific = {}
local function isModule(module)
for _, modu in client.Modules do
if rawequal(module, modu) then
return true
end
end
return false
end
local function logError(...)
warn("ERROR: ", ...)
table.insert(clientLog, table.concat({"ERROR:", ...}, " "))
if client and client.Remote then
client.Remote.Send("LogError", table.concat({...}, " "))
end
end
local Pcall = function(func, ...)
local ran, err = pcall(func, ...)
-- Log the error if the protected-call did not complete successfully
if not ran and err then
logError(tostring(err))
end
return ran, err
end
local Routine = function(func, ...)
return coroutine.resume(coroutine.create(func), ...)
end
local Immutable = function(...)
local mut = coroutine.wrap(function(...)
while true do
coroutine.yield(...)
end
end)
mut(...)
return mut
end
local Kill
local Fire, Detected = nil, nil
do
Kill = Immutable(function(info)
--if true then print(info or "SOMETHING TRIED TO CRASH CLIENT?") return end
spawn(pcall, function()
if Detected then
Detected("kick", info)
elseif Fire then
Fire("BadMemes", info)
end
end)
spawn(pcall, function()
task.wait(1)
service.Player:Kick(info)
end)
if not isStudio then
spawn(pcall, function()
task.wait(5)
if client.Core and client.Core.RemoteEvent then
spawn(pcall, table.clear, client.Core.RemoteEvent)
spawn(pcall, table.freeze, client.Core.RemoteEvent)
client.Core.RemoteEvent = nil
end
spawn(pcall, table.clear, locals)
spawn(pcall, table.freeze, locals)
client = nil
locals = nil
while true do continue end
end)
end
end)
end
local GetEnv
GetEnv = function(env, repl)
local scriptEnv = setmetatable({}, {
__index = function(tab, ind)
return (locals[ind] or (env or origEnv)[ind])
end,
__metatable = if Folder:FindFirstChild("ADONIS_DEBUGMODE_ENABLED") then nil else unique,
})
if repl and type(repl) == "table" then
for ind, val in repl do
scriptEnv[ind] = val
end
end
return scriptEnv
end
local GetVargTable = function()
return {
Client = client,
Service = service,
}
end
local LoadModule = function(module, yield, envVars, noEnv)
local isRaw = type(module) == "string"
local isValue = not isRaw and module:IsA("StringValue")
local plugran, plug
if isRaw then
plugran, plug = pcall(assert(assert(client.Core.Loadstring, "Cannot compile plugin due to Core.Loadstring missing")(module, GetEnv({}, envVars)), "Failed to compile module"))
elseif isValue then
plugran, plug = pcall(client.Core.LoadCode or function(...) return require(client.Shared.FiOne, true)(...) end, client.Functions.Base64Decode(module.Value), GetEnv({}, envVars))
else
plugran, plug = pcall(require, module)
end
if plugran then
if type(plug) == "function" then
if yield then
local ran, err = service.TrackTask(
`Plugin: {module}`,
((noEnv or isRaw or isValue) and plug) or setfenv(plug, GetEnv(getfenv(plug), envVars)),
function(err)
warn(`Module encountered an error while loading: {module}\n{err}\n{debug.traceback()}`)
end,
GetVargTable(),
GetEnv
)
else
local ran, err = service.TrackTask(
`Thread: Plugin: {module}`,
((noEnv or isRaw or isValue) and plug) or setfenv(plug, GetEnv(getfenv(plug), envVars)),
function(err)
warn(`Module encountered an error while loading: {module}\n{err}\n{debug.traceback()}`)
end,
GetVargTable(),
GetEnv
)
end
else
client[module.Name] = plug
end
else
warn("Error while loading client module", module, plug)
end
end
log("Client setmetatable")
client = setmetatable({
Handlers = {},
Modules = {},
Service = service,
Module = script,
Print = print,
Warn = warn,
Deps = {},
Pcall = Pcall,
Routine = Routine,
OldPrint = oldPrint,
LogError = logError,
Disconnect = function(info)
service.Player:Kick(info or "Disconnected from server")
--wait(30)
--client.Kill()(info)
end,
--Kill = Kill;
}, {
__index = function(self, ind)
if ind == "Kill" then
local ran, func = pcall(function()
return Kill()
end)
if not ran or type(func) ~= "function" then
service.Players.LocalPlayer:Kick("1x00353 Adonis (PlrClientIndexKlErr)")
warn("Failed to retrieve Kill function")
return function() end
end
return func
end
end,
})
locals = {
Pcall = Pcall,
GetEnv = GetEnv,
client = client,
Folder = Folder,
Routine = Routine,
service = service,
logError = logError,
origEnv = origEnv,
log = log,
dumplog = dumplog,
}
log("Create service metatable")
service = require(Folder.Parent.Shared.Service)(function(eType, msg, desc, ...)
--warn(eType, msg, desc, ...)
local extra = { ... }
if eType == "MethodError" then
--Kill()("Shananigans denied")
--player:Kick("Method error")
--service.Detected("kick", "Method change detected")
logError("Client", `Method Error Occured: {msg}`)
elseif eType == "ServerError" then
logError("Client", tostring(msg))
elseif eType == "ReadError" then
--message("===== READ ERROR:::::::")
--message(tostring(msg))
--message(tostring(desc))
--message(" ")
Kill()(tostring(msg))
--if Detected then
-- Detected("log", tostring(msg))
--end
end
end, function(c, parent, tab)
if not isModule(c) and c ~= script and c ~= Folder and parent == nil then
tab.UnHook()
end
end, ServiceSpecific, GetEnv(nil, { client = client }))
--// Localize
log("Localize")
local Localize = service.Localize
os = Localize(os)
math = Localize(math)
table = Localize(table)
string = Localize(string)
coroutine = Localize(coroutine)
Instance = Localize(Instance)
Vector2 = Localize(Vector2)
Vector3 = Localize(Vector3)
CFrame = Localize(CFrame)
UDim2 = Localize(UDim2)
UDim = Localize(UDim)
Ray = Localize(Ray)
Rect = Localize(Rect)
Faces = Localize(Faces)
Color3 = Localize(Color3)
NumberRange = Localize(NumberRange)
NumberSequence = Localize(NumberSequence)
NumberSequenceKeypoint = Localize(NumberSequenceKeypoint)
ColorSequenceKeypoint = Localize(ColorSequenceKeypoint)
PhysicalProperties = Localize(PhysicalProperties)
ColorSequence = Localize(ColorSequence)
Region3int16 = Localize(Region3int16)
Vector3int16 = Localize(Vector3int16)
BrickColor = Localize(BrickColor)
TweenInfo = Localize(TweenInfo)
Axes = Localize(Axes)
task = Localize(task)
--// Wrap
log("Wrap")
local service_Wrap = service.Wrap
local service_UnWrap = service.UnWrap
for i, val in service do
if type(val) == "userdata" then
service[i] = service_Wrap(val, true)
end
end
--// Folder Wrap
Folder = service_Wrap(Folder, true)
--// Global Wrapping
Enum = service_Wrap(Enum, true)
rawequal = service.RawEqual
script = service_Wrap(script, true)
game = service_Wrap(game, true)
workspace = service_Wrap(workspace, true)
Instance = {
new = function(obj, parent)
return service_Wrap(oldInstNew(obj, service_UnWrap(parent)), true)
end,
}
require = function(obj, noWrap: boolean?)
return if noWrap == true then oldReq(service_UnWrap(obj)) else service_Wrap(oldReq(service_UnWrap(obj)), true)
end
client.Service = service
client.Module = service_Wrap(client.Module, true)
--// Setting things up
log("Setting things up")
for ind, loc in
{
_G = _G,
game = game,
spawn = spawn,
script = script,
getfenv = getfenv,
setfenv = setfenv,
workspace = workspace,
getmetatable = getmetatable,
setmetatable = setmetatable,
loadstring = loadstring,
coroutine = coroutine,
rawequal = rawequal,
typeof = typeof,
print = print,
math = math,
warn = warn,
error = error,
assert = assert,
pcall = pcall,
xpcall = xpcall,
select = select,
rawset = rawset,
rawget = rawget,
ipairs = ipairs,
pairs = pairs,
next = next,
Rect = Rect,
Axes = Axes,
os = os,
time = time,
Faces = Faces,
delay = delay,
unpack = unpack,
string = string,
Color3 = Color3,
newproxy = newproxy,
tostring = tostring,
tonumber = tonumber,
Instance = Instance,
TweenInfo = TweenInfo,
BrickColor = BrickColor,
NumberRange = NumberRange,
ColorSequence = ColorSequence,
NumberSequence = NumberSequence,
ColorSequenceKeypoint = ColorSequenceKeypoint,
NumberSequenceKeypoint = NumberSequenceKeypoint,
PhysicalProperties = PhysicalProperties,
Region3int16 = Region3int16,
Vector3int16 = Vector3int16,
require = require,
table = table,
type = type,
wait = wait,
Enum = Enum,
UDim = UDim,
UDim2 = UDim2,
Vector2 = Vector2,
Vector3 = Vector3,
Region3 = Region3,
CFrame = CFrame,
Ray = Ray,
task = task,
tick = tick,
service = service,
}
do
locals[ind] = loc
end
--// Init
log("Return init function")
return service.NewProxy({
__call = function(self, data)
log("Begin init")
local remoteName, depsName = string.match(data.Name, "(.*)\\(.*)")
Folder = service.Wrap(data.Folder --[[or folder and folder:Clone()]] or Folder)
if Folder:FindFirstChild("ADONIS_DEBUGMODE_ENABLED") then
data.DebugMode = true
else
data.DebugMode = false
end
log("Adding ACLI logs to the client logs")
if data.acliLogs then
for _, v in data.acliLogs do
log(v)
end
end
log("Clearing environment")
setfenv(1, setmetatable({}, { __metatable = unique }))
log("Loading necessary client values")
client.Folder = Folder
client.UIFolder = Folder:WaitForChild("UI", 9e9)
client.Shared = Folder.Parent:WaitForChild("Shared", 9e9)
client.Loader = data.Loader
client.Module = data.Module
client.DepsName = depsName
client.TrueStart = data.Start
client.LoadingTime = data.LoadingTime
client.RemoteName = remoteName
client.DebugMode = data.DebugMode
client.Typechecker = oldReq(service_UnWrap(client.Shared.Typechecker))
client.Changelog = oldReq(service_UnWrap(client.Shared.Changelog))
client.FormattedChangelog = table.create(#client.Changelog)
--// Create formatted changelog from standard changelog
local function applyColour(line)
local prefix = line:sub(1, 2)
if prefix == "[v" or prefix == "[1" or prefix == "[0" or prefix == "1." or line:sub(1, 1) == "v" then
return `<font color='#8FAEFF'>{line}</font>`
elseif line:sub(1, 6) == "[Patch" then
return `<font color='#F0B654'>{line}</font>`
elseif line:sub(1, 9) == "Version: " then
return `<b>{line}</b>`
elseif line:sub(1,2) == "# " then
return `<b>{string.sub(line, 3)}</b>`
else
return line
end
end
log("Fomratting chatlogs")
for i, line in ipairs(client.Changelog) do
client.FormattedChangelog[i] = applyColour(line)
end
--// Setup MatIcons
log("Setting up material icons")
do
local MaterialIcons = oldReq(service_UnWrap(client.Shared.MatIcons))
client.MatIcons = setmetatable({}, {
__index = function(self, ind)
local materialIcon = MaterialIcons[ind]
if materialIcon then
self[ind] = `rbxassetid://{materialIcon}`
return self[ind]
end
end,
__metatable = if not data.DebugMode then "Adonis" else unique,
})
end
--// Toss deps into a table so we don't need to directly deal with the Folder instance they're in
log("Get dependencies")
for _, obj in Folder:WaitForChild("Dependencies", 9e9):GetChildren() do
client.Deps[obj.Name] = obj
end
--// Do this before we start hooking up events
log("Destroy script object")
--folder:Destroy()
script.Parent = nil --script:Destroy()
--// Intial setup
log("Initial services caching")
for _, serv in SERVICES_WE_USE do
local _ = service[serv]
end
--// Client specific service variables/functions
log("Add service specific")
ServiceSpecific.Player = service.Players.LocalPlayer
or (function()
service.Players:GetPropertyChangedSignal("LocalPlayer"):Wait()
return service.Players.LocalPlayer
end)()
ServiceSpecific.PlayerGui = ServiceSpecific.Player:FindFirstChildWhichIsA("PlayerGui")
if not ServiceSpecific.PlayerGui then
Routine(function()
local PlayerGui = ServiceSpecific.Player:WaitForChild("PlayerGui", 120)
if not PlayerGui then
logError("PlayerGui unable to be fetched? [Waited 120 Seconds]")
return
end
ServiceSpecific.PlayerGui = PlayerGui
end)
end
ServiceSpecific.Filter = function(str, from, to)
return client.Remote.Get("Filter", str, (to and from) or service.Player, to or from)
end
ServiceSpecific.LaxFilter = function(str, from)
return service.Filter(str, from or service.Player, from or service.Player)
end
ServiceSpecific.BroadcastFilter = function(str, from)
return client.Remote.Get("BroadcastFilter", str, from or service.Player)
end
ServiceSpecific.IsMobile = function()
return service.UserInputService.TouchEnabled
and not service.UserInputService.MouseEnabled
and not service.UserInputService.KeyboardEnabled
end
ServiceSpecific.LocalContainer = function()
local Variables = client.Variables
if not (Variables.LocalContainer and Variables.LocalContainer.Parent) then
Variables.LocalContainer = service.New("Folder", {
Parent = workspace,
Archivable = false,
Name = `__ADONIS_LOCALCONTAINER_{service.HttpService:GenerateGUID(false)}`,
})
end
return Variables.LocalContainer
end
ServiceSpecific.IncognitoPlayers = {}
--// Load Core Modules
log("Loading core modules")
for _, load in CORE_LOADING_ORDER do
local modu = Folder.Core:FindFirstChild(load)
if modu then
log(`~! Loading Core Module: {load}`)
LoadModule(modu, true, { script = script }, true)
end
end
--// Start of module loading and server connection process
local runLast = {}
local runAfterInit = {}
local runAfterLoaded = {}
local runAfterPlugins = {}
--// Loading Finisher
client.Finish_Loading = function()
log("Client fired finished loading")
if client.Core.Key then
--// Run anything from core modules that needs to be done after the client has finished loading
log("~! Doing run after loaded")
for _, f in runAfterLoaded do
Pcall(f, data)
end
--// Stuff to run after absolutely everything else
log("~! Doing run last")
for _, f in runLast do
Pcall(f, data)
end
--// Finished loading
log("Finish loading")
client.Finish_Loading = function() end
client.LoadingTime() --warn(tostring(time()-(client.TrueStart or startTime)))
service.Events.FinishedLoading:Fire(os.time())
log("~! FINISHED LOADING!")
else
log("Client missing remote key")
client.Kill()("Missing remote key")
end
end
--// Initialize Cores
log("~! Init cores")
for _, name in CORE_LOADING_ORDER do
local core = client[name]
log(`~! INIT: {name}`)
if core then
if type(core) == "table" or (type(core) == "userdata" and getmetatable(core) == "ReadOnly_Table") then
if core.RunLast then
table.insert(runLast, core.RunLast)
core.RunLast = nil
end
if core.RunAfterInit then
table.insert(runAfterInit, core.RunAfterInit)
core.RunAfterInit = nil
end
if core.RunAfterPlugins then
table.insert(runAfterPlugins, core.RunAfterPlugins)
core.RunAfterPlugins = nil
end
if core.RunAfterLoaded then
table.insert(runAfterLoaded, core.RunAfterLoaded)
core.RunAfterLoaded = nil
end
if core.Init then
log(`Run init for {name}`)
Pcall(core.Init, data)
core.Init = nil
end
end
end
end
--// Load any afterinit functions from modules (init steps that require other modules to have finished loading)
log("~! Running after init")
for _, f in runAfterInit do
Pcall(f, data)
end
--// Load Plugins
log("~! Running plugins")
for _, module in Folder.Plugins:GetChildren() do
--// Pass example/README plugins.
if module.Name == "README" then
continue
end
task.defer(LoadModule, module, false, { --noenv
script = module, cPcall = client.cPcall
})
end
--// We need to do some stuff *after* plugins are loaded (in case we need to be able to account for stuff they may have changed before doing something, such as determining the max length of remote commands)
log("~! Running after plugins")
for _, f in runAfterPlugins do
Pcall(f, data)
end
log("Initial loading complete")
--// Below can be used to determine when all modules and plugins have finished loading; service.Events.AllModulesLoaded:Connect(function() doSomething end)
client.AllModulesLoaded = true
service.Events.AllModulesLoaded:Fire(os.time())
service.Events.ClientInitialized:Fire()
log("~! Return success")
return "SUCCESS"
end,
__metatable = if not Folder:FindFirstChild("ADONIS_DEBUGMODE_ENABLED") then "Adonis" else unique,
__tostring = function()
return "Adonis"
end,
})