forked from Epix-Incorporated/Adonis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.luau
More file actions
1697 lines (1464 loc) · 45.4 KB
/
Functions.luau
File metadata and controls
1697 lines (1464 loc) · 45.4 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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--// Function stuff
return function(Vargs, GetEnv)
local env = GetEnv(nil, {script = script})
setfenv(1, env)
local server = Vargs.Server
local service = Vargs.Service
local logError
local Functions, Admin, Anti, Core, HTTP, Logs, Remote, Process, Variables, Settings
local function Init()
Functions = server.Functions;
Admin = server.Admin;
Anti = server.Anti;
Core = server.Core;
HTTP = server.HTTP;
Logs = server.Logs;
Remote = server.Remote;
Process = server.Process;
Variables = server.Variables;
Settings = server.Settings;
logError = server.logError;
Functions.NuclearExplode = select(2, xpcall(require, warn, server.Dependencies.FastNuke));
Functions.Init = nil
Logs:AddLog("Script", "Functions Module Initialized")
end;
local function RunAfterPlugins(data)
Functions.RunAfterPlugins = nil
Logs:AddLog("Script", "Functions Module RunAfterPlugins Finished")
end
server.Functions = {
Init = Init;
RunAfterPlugins = RunAfterPlugins;
PlayerFinders = {
["me"] = {
Match = "me";
Prefix = true;
Absolute = true;
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
table.insert(players, plr)
plus()
end;
};
["all"] = {
Match = "all";
Prefix = true;
Absolute = true;
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local everyone = true
if isKicking then
local lower = string.lower
local sub = string.sub
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and sub(lower(p.Name), 1, #msg)==lower(msg) then
everyone = false
table.insert(players, p)
plus()
end
end
end
if everyone then
for _,v in parent:GetChildren() do
local p = getplr(v)
if p then
table.insert(players, p)
plus()
end
end
end
end;
};
["everyone"] = {
Match = "everyone";
Absolute = true;
Prefix = true;
Function = function(...)
return Functions.PlayerFinders.all.Function(...)
end
};
["others"] = {
Match = "others";
Prefix = true;
Absolute = true;
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and p ~= plr then
table.insert(players, p)
plus()
end
end
end;
};
["random"] = {
Match = "random";
Prefix = true;
Absolute = true;
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
table.insert(randplayers, "random")
plus()
end;
};
["admins"] = {
Match = "admins";
Prefix = true;
Absolute = true;
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and Admin.CheckAdmin(p,false) then
table.insert(players, p)
plus()
end
end
end;
};
["nonadmins"] = {
Match = "nonadmins";
Prefix = true;
Absolute = true;
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and not Admin.CheckAdmin(p,false) then
table.insert(players, p)
plus()
end
end
end;
};
["friends"] = {
Match = "friends";
Prefix = true;
Absolute = true;
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and p:IsFriendsWith(plr.UserId) then
table.insert(players, p)
plus()
end
end
end;
};
["@username"] = {
Match = "@";
Prefix = false;
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local matched = string.match(msg, "@(.*)")
local foundNum = 0
if matched then
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and p.Name == matched then
table.insert(players, p)
plus()
foundNum += 1
end
end
end
end;
};
["%team"] = {
Match = "%";
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local matched = string.match(msg, "%%(.*)")
local lower = string.lower
local sub = string.sub
if matched and #matched > 0 then
for _,v in service.Teams:GetChildren() do
if sub(lower(v.Name), 1, #matched) == lower(matched) then
for _,m in parent:GetChildren() do
local p = getplr(m)
if p and p.TeamColor == v.TeamColor then
table.insert(players, p)
plus()
end
end
end
end
end
end;
};
["$group"] = {
Match = "$";
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local matched = string.match(msg, "%$(.*)")
if matched and tonumber(matched) then
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and p:IsInGroup(tonumber(matched)) then
table.insert(players, p)
plus()
end
end
end
end;
};
["id-"] = {
Match = "id-";
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local matched = tonumber(string.match(msg, "id%-(.*)"))
local foundNum = 0
if matched then
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and p.UserId == matched then
table.insert(players, p)
plus()
foundNum += 1
end
end
if foundNum == 0 and useFakePlayer then
local ran, name = pcall(service.Players.GetNameFromUserIdAsync, service.Players, matched)
if ran or allowUnknownUsers then
local fakePlayer = Functions.GetFakePlayer({
UserId = matched,
Name = name,
})
table.insert(players, fakePlayer)
plus()
end
end
end
end;
};
["displayname-"] = {
Match = "displayname-";
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local matched = tonumber(string.match(msg, "displayname%-(.*)"))
local foundNum = 0
if matched then
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and p.DisplayName == matched then
table.insert(players, p)
plus()
foundNum += 1
end
end
end
end;
};
["team-"] = {
Match = "team-";
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local lower = string.lower
local sub = string.sub
local matched = string.match(msg, "team%-(.*)")
if matched then
for _,v in service.Teams:GetChildren() do
if sub(lower(v.Name), 1, #matched) == lower(matched) then
for _,m in parent:GetChildren() do
local p = getplr(m)
if p and p.TeamColor == v.TeamColor then
table.insert(players, p)
plus()
end
end
end
end
end
end;
};
["group-"] = {
Match = "group-";
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local matched = string.match(msg, "group%-(.*)")
matched = tonumber(matched)
if matched then
for _,v in parent:GetChildren() do
local p = getplr(v)
if p and p:IsInGroup(matched) then
table.insert(players, p)
plus()
end
end
end
end;
};
["-name"] = {
Match = "-";
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local matched = string.match(msg, "%-(.*)")
if matched then
local removes = service.GetPlayers(plr,matched, {
DontError = true;
})
for k,p in removes do
if p then
table.insert(delplayers,p)
plus()
end
end
end
end;
};
["+name"] = {
Match = "+";
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local matched = string.match(msg, "%+(.*)")
if matched then
local adds = service.GetPlayers(plr,matched, {
DontError = true;
})
for k,p in adds do
if p then
table.insert(addplayers,p)
plus()
end
end
end
end;
};
["#number"] = {
Match = "#";
Function = function(msg, plr, ...)
local matched = string.match(msg, "#(.*)")
if matched and tonumber(matched) then
local num = tonumber(matched)
if not num then
Remote.MakeGui(plr,"Output", {Title = "Invalid argument"; Message = "Argument supplied is not a number!"})
return;
end
for i = 1, math.min(num, #service.Players:GetPlayers()) do
Functions.PlayerFinders.random.Function(msg, plr, ...)
end
end
end;
};
["radius-"] = {
Match = "radius-";
Function = function(msg, plr, parent, players, delplayers, addplayers, randplayers, getplr, plus, isKicking, isServer, dontError, useFakePlayer, allowUnknownUsers)
local matched = string.match(msg, "radius%-(.*)")
if matched and tonumber(matched) then
local num = tonumber(matched)
if not num then
Remote.MakeGui(plr,"Output", {Title = "Invalid argument"; Message = "Argument supplied is not a number!"})
return;
end
for _,v in parent:GetChildren() do
local p = getplr(v)
local character = p.Character
local Head = character and character:FindFirstChild("Head")
if Head and p and p ~= plr and plr:DistanceFromCharacter(Head.Position) <= num then
table.insert(players,p)
plus()
end
end
end
end;
};
};
GetFakePlayer = function(options)
local fakePlayer = service.Wrap(service.New("Folder", {
Name = options.Name or "Fake_Player";
Archivable = false;
}))
local data = {
ClassName = "Player";
Name = "[Unknown User]";
DisplayName = "[Unknown User]";
UserId = 0;
AccountAge = 0;
MembershipType = Enum.MembershipType.None;
CharacterAppearanceId = options.UserId or 0;
FollowUserId = 0;
GameplayPaused = false;
Parent = service.Players;
Character = service.New("Model", {Name = options.Name or "Fake_Player"});
Backpack = service.New("Backpack", {Name = "FakeBackpack"});
PlayerGui = service.New("Folder", {Name = "FakePlayerGui"});
PlayerScripts = service.New("Folder", {Name = "FakePlayerScripts"});
GetJoinData = function() return {} end;
GetFriendsOnline = function() return {} end;
GetRankInGroup = function() return 0 end;
GetRoleInGroup = function() return "Guest" end;
IsFriendsWith = function() return false end;
Kick = function() fakePlayer:SetSpecial("Parent", nil) fakePlayer:Destroy() end;
IsA = function(_, className) return className == "Player" or className == "Instance" end;
}
for k, v in options do
data[k] = v
end
if data.UserId > 0 then
local success, actualName = pcall(service.Players.GetNameFromUserIdAsync, service.Players, data.UserId)
if success then
data.Name = actualName
end
end
data.userId = data.UserId
data.ToString = data.Name
for k, v in data do
fakePlayer:SetSpecial(k, v)
end
return fakePlayer
end;
GetChatService = function()
return if service.TextChatService.ChatVersion == Enum.ChatVersion.TextChatService then false else nil
end;
ArgsToString = function(args)
local str = table.create(args.n or #args)
for i, arg in args do
str[i] = `Arg{i}: {arg}; `
end
return string.sub(table.concat(str), 1, -3)
end;
GetPlayers = function(plr, argument, options)
options = options or {}
local parent = options.Parent or service.Players
local players = {}
local delplayers = {}
local addplayers = {}
local randplayers = {}
local function getplr(p)
if p then
if p.ClassName == "Player" then
return p
elseif p:IsA("NetworkReplicator") then
local networkPeerPlayer = p:GetPlayer()
if networkPeerPlayer and networkPeerPlayer.ClassName == "Player" then
return networkPeerPlayer
end
end
end
return nil
end
local function checkMatch(msg)
msg = string.lower(msg)
local doReturn
local PlrLevel = if plr then Admin.GetLevel(plr) else 0
for _, data in Functions.PlayerFinders do
if not data.Level or (data.Level and PlrLevel >= data.Level) then
local check = `{(data.Prefix and Settings.SpecialPrefix) or ""}{data.Match}`
if (data.Absolute and msg == check) or (not data.Absolute and string.sub(msg, 1, #check) == string.lower(check)) then
if data.Absolute then
return data
else --// Prioritize absolute matches over non-absolute matches
doReturn = data
end
end
end
end
return doReturn
end
if plr == nil then
--// Select all players
for _, v in parent:GetChildren() do
local p = getplr(v)
if p then
table.insert(players, p)
end
end
elseif plr and not argument then
--// Default to the executor ("me")
return {plr}
else
if string.match(argument, "^##") then
error(`String passed to GetPlayers is filtered: {argument}`, 2)
end
local selectors = string.gmatch(argument, "([^,]+)")
--// This is for player commands that take in service.GetPlayers() to make sure someone isnt passing in a message that is insanely long
local PlrLevel = if plr then Admin.GetLevel(plr) else 0
local AllowUnsafeSelectors = PlrLevel > 0 or options.AllowUnsafeSelectors
local MaxSelectors = Variables.MaxSafeSelectors or 400 -- 400 seems like a good "max" that won't ever be reached
local index = 0
for s in selectors do
index += 1
if not AllowUnsafeSelectors and index > MaxSelectors then
break
end
local plrCount = 0
local function plus() plrCount += 1 end
if not options.NoSelectors then
local matchFunc = checkMatch(s)
if matchFunc then
matchFunc.Function(
s,
plr,
parent,
players,
delplayers,
addplayers,
randplayers,
getplr,
plus,
options.IsKicking,
options.IsServer,
options.DontError,
options.UseFakePlayer,
options.AllowUnknownUsers
)
end
end
if plrCount == 0 then
--// Check for display names
for _, v in parent:GetChildren() do
local p = getplr(v)
if p and p.ClassName == "Player" and string.match(string.lower(p.DisplayName), `^{service.SanitizePattern(string.lower(s))}`) then
table.insert(players, p)
plus()
end
end
if plrCount == 0 then
--// Check for usernames
for _, v in parent:GetChildren() do
local p = getplr(v)
if p and p.ClassName == "Player" and string.match(string.lower(p.Name), `^{service.SanitizePattern(string.lower(s))}`) then
table.insert(players, p)
plus()
end
end
--// Check for user IDs
if tonumber(s) then
for _, v in parent:GetChildren() do
local p = getplr(v)
if p and p.ClassName == "Player" and p.UserId == tonumber(s) then
table.insert(players, p)
plus()
end
end
end
if plrCount == 0 then
if options.UseFakePlayer then
--// Attempt to retrieve non-ingame user
local UserId
if Functions.GetUserIdFromNameAsync(s) then
UserId = Functions.GetUserIdFromNameAsync(s)
else
if tonumber(s) then
UserId = s
end
end
if UserId or options.AllowUnknownUsers then
table.insert(players, Functions.GetFakePlayer({
Name = s;
DisplayName = s;
UserId = if UserId then UserId else -1;
}))
plus()
end
end
if plrCount == 0 and not options.DontError then
Remote.MakeGui(plr, "Output", {
Title = "Missing player";
Message = if options.UseFakePlayer then `No user named '{s}' exists`
else `No players matching '{s}' were found!`;
})
end
end
end
end
end
end
--// The following is intended to prevent name spamming (eg. :re scel,scel,scel,scel,scel,scel,scel,scel,scel,scel,scel,scel,scel,scel...)
--// It will also prevent situations where a player falls within multiple player finders (eg. :re group-1928483,nonadmins,radius-50 (one player can match all 3 of these))
--// Edited to adjust removals and randomizers.
local filteredList = {}
local checkList = {}
for _, v in players do
if not checkList[v] then
table.insert(filteredList, v)
checkList[v] = true
end
end
local delFilteredList = {}
local delCheckList = {}
for _, v in delplayers do
if not delCheckList[v] then
table.insert(delFilteredList, v)
delCheckList[v] = true
end
end
local addFilteredList = {}
local addCheckList = {}
for _, v in addplayers do
if not addCheckList[v] then
table.insert(addFilteredList, v)
addCheckList[v] = true
end
end
local removalSuccessList = {}
for i, v in filteredList do
for j, w in delFilteredList do
if v.Name == w.Name then
table.remove(filteredList,i)
table.insert(removalSuccessList, w)
end
end
end
for j, w in addFilteredList do
table.insert(filteredList, w)
end
local checkList2 = {}
local finalFilteredList = {}
for _, v in filteredList do
if not checkList2[v] then
table.insert(finalFilteredList, v)
checkList2[v] = true
end
end
local comboTableCheck = {}
for _, v in finalFilteredList do
table.insert(comboTableCheck, v)
end
for _, v in delFilteredList do
table.insert(comboTableCheck, v)
end
local function rplrsort()
local children = parent:GetChildren()
local childcount = #children
local excludecount = #comboTableCheck
if excludecount < childcount then
local rand = children[math.random(#children)]
local rp = getplr(rand)
for _, v in comboTableCheck do
if v.Name == rp.Name then
rplrsort()
return
end
end
table.insert(finalFilteredList, rp)
local comboTableCheck = {}
for _, v in finalFilteredList do
table.insert(comboTableCheck, v)
end
for _, v in delFilteredList do
table.insert(comboTableCheck, v)
end
end
end
for i, v in randplayers do
rplrsort()
end
return finalFilteredList
end;
-- ROT 47: ROT13 BUT BETTER
Rot47Cipher = function(data,mode)
if not (mode == "enc" or mode == "dec") then error("Invalid ROT47 Cipher Mode") end
local base = 33
local range = 126 - 33 + 1
-- Checks if the given char is convertible
-- ASCII Code should be within the range [33 .. 126]
local function rot47_convertible(char)
local v = string.byte(char)
return v >= 33 and v <= 126
end
local function cipher(str, key)
return (string.gsub(str, ".", function(s)
if not rot47_convertible(s) then return s end
return string.char(((string.byte(s) - base + key) % range) + base)
end))
end
if mode == "enc" then return cipher(data,47) end
if mode == "dec" then return cipher(data,-47) end
end;
-- Thanks to Tiffany352 for this base64 implementation!
Base64Encode = function(str)
local floor = math.floor
local char = string.char
local sub = string.sub
local nOut = 0
local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
local strLen = #str
local out = table.create(math.ceil(strLen / 0.75))
-- 3 octets become 4 hextets
for i = 1, strLen - 2, 3 do
local b1, b2, b3 = string.byte(str, i, i + 3)
local word = b3 + b2 * 256 + b1 * 256 * 256
local h4 = word % 64 + 1
word = floor(word / 64)
local h3 = word % 64 + 1
word = floor(word / 64)
local h2 = word % 64 + 1
word = floor(word / 64)
local h1 = word % 64 + 1
out[nOut + 1] = sub(alphabet,h1, h1)
out[nOut + 2] = sub(alphabet,h2, h2)
out[nOut + 3] = sub(alphabet,h3, h3)
out[nOut + 4] = sub(alphabet,h4, h4)
nOut = nOut + 4
end
local remainder = strLen % 3
if remainder == 2 then
-- 16 input bits -> 3 hextets (2 full, 1 partial)
local b1, b2 = str:byte(-2, -1)
-- partial is 4 bits long, leaving 2 bits of zero padding ->
-- offset = 4
local word = b2 * 4 + b1 * 4 * 256
local h3 = word % 64 + 1
word = floor(word / 64)
local h2 = word % 64 + 1
word = floor(word / 64)
local h1 = word % 64 + 1
out[nOut + 1] = sub(alphabet,h1, h1)
out[nOut + 2] = sub(alphabet,h2, h2)
out[nOut + 3] = sub(alphabet,h3, h3)
out[nOut + 4] = "="
elseif remainder == 1 then
-- 8 input bits -> 2 hextets (2 full, 1 partial)
local b1 = str:byte(-1, -1)
-- partial is 2 bits long, leaving 4 bits of zero padding ->
-- offset = 16
local word = b1 * 16
local h2 = word % 64 + 1
word = floor(word / 64)
local h1 = word % 64 + 1
out[nOut + 1] = sub(alphabet,h1, h1)
out[nOut + 2] = sub(alphabet,h2, h2)
out[nOut + 3] = "="
out[nOut + 4] = "="
end
-- if the remainder is 0, then no work is needed
return table.concat(out, "")
end;
Base64Decode = function(str)
local floor = math.floor
local char = string.char
local sub = string.sub
local nOut = 0
local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
local strLen = #str
local out = table.create(math.ceil(strLen * 0.75))
local acc = 0
local nAcc = 0
local alphabetLut = {}
for i = 1, #alphabet do
alphabetLut[sub(alphabet, i, i)] = i - 1
end
-- 4 hextets become 3 octets
for i = 1, strLen do
local ch = sub(str, i, i)
local byte = alphabetLut[ch]
if byte then
acc = acc * 64 + byte
nAcc += 1
end
if nAcc == 4 then
local b3 = acc % 256
acc = floor(acc / 256)
local b2 = acc % 256
acc = floor(acc / 256)
local b1 = acc % 256
out[nOut + 1] = char(b1)
out[nOut + 2] = char(b2)
out[nOut + 3] = char(b3)
nOut += 3
nAcc = 0
acc = 0
end
end
if nAcc == 3 then
-- 3 hextets -> 16 bit output
acc *= 64
acc = floor(acc / 256)
local b2 = acc % 256
acc = floor(acc / 256)
local b1 = acc % 256
out[nOut + 1] = char(b1)
out[nOut + 2] = char(b2)
elseif nAcc == 2 then
-- 2 hextets -> 8 bit output
acc *= 64
acc = floor(acc / 256)
acc *= 64
acc = floor(acc / 256)
local b1 = acc % 256
out[nOut + 1] = char(b1)
elseif nAcc == 1 then
error("Base64 has invalid length")
end
return table.concat(out, "")
end;
Hint = function(message, players, duration, title, image)
duration = duration or (#tostring(message) / 19) + 2.5
for _, v in players do
Remote.MakeGui(v, "Hint", {
Message = message;
Time = duration;
Title = title;
Image = image;
})
end
end;
Message = function(sender, title, message, image, players, scroll, duration)
-- Currently not used
if sender == "Adonis" or sender == "HelpSystem" or sender == "Command" then
sender = nil
end
-- ////////// Compatability for older plugins (before sender and image ares were introduced)
if sender ~= nil and typeof(sender) ~= "Instance" and typeof(sender) ~= "userdata" and type(sender) ~= "table" then
local oldVars = {
sender = sender,
title = title,
message = message,
image = image,
players = players,
scroll = scroll,
duration = duration,
}
title = oldVars.sender
message = oldVars.title
players = oldVars.message
scroll = oldVars.image
duration = oldVars.players
sender = nil
image = nil
end
duration = duration or (#tostring(message) / 19) + 2.5
if image then
-- Support "MatIcon://" for fast access to maticons
local MatIcon = string.match(image, "MatIcon://(.+)")
if MatIcon then
image = server.MatIcons[MatIcon]
elseif sender and (image == "HeadShot") then
image = `rbxthumb://type=AvatarHeadShot&id={sender.UserId}&w=48&h=48`
end
end
for _, v in players do
task.defer(function()
Remote.RemoveGui(v, "Message")
Remote.MakeGui(v, "Message", {
Title = title;
Message = message;
Scroll = scroll;
Time = duration;
Image = image;
UserId = sender and sender.UserId or nil;
})
end)
end
end;
Notify = function(title, message, players, duration, author)
duration = duration or (#tostring(message) / 19) + 2.5
for _, v in players do
task.defer(function()
Remote.RemoveGui(v, "Notify")
Remote.MakeGui(v, "Notify", {
Title = title;
Message = message;
Time = duration;
UserId = author and author.UserId or nil;
})
end)
end
end;
Notification = function(title, message, players, duration, icon, onClick)
icon = icon and string.match(icon, "MatIcon://(.+)") or icon
for _, v in players do
Remote.MakeGui(v, "Notification", {
Title = title;
Message = message;
Time = duration;
Icon = server.MatIcons[icon or "Info"];
OnClick = onClick;
})
end
end;
MakeWeld = function(a, b, c0, c1)
local weld = service.New("Weld")
weld.Part0 = a
weld.Part1 = b
weld.C0 = c0 or a.CFrame:Inverse() * b.CFrame
weld.C1 = c1 or CFrame.new()
weld.Parent = a
return weld
end;
SetLighting = function(prop, value)
if service.CheckProperty(service.Lighting, prop) then
local success = pcall(function()
service.Lighting[prop] = value
end)