-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesync.lua
More file actions
2548 lines (2337 loc) · 104 KB
/
desync.lua
File metadata and controls
2548 lines (2337 loc) · 104 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
do
makefolder("testhake")
makefolder("testhake\\configs")
if #listfiles("testhake\\configs") == 0 then
writefile("testhake\\configs\\default.cfg", "")
end
end
-- Services
local cas = game:GetService("ContextActionService")
local rpf = game:GetService("ReplicatedFirst")
local uis = game:GetService("UserInputService")
local cs = game:GetService("CollectionService")
local tps = game:GetService("TeleportService")
local sui = game:GetService("StarterGui")
local rs = game:GetService("RunService")
local lit = game:GetService("Lighting")
local sc = game:GetService("ScriptContext")
local ls = game:GetService("LogService")
local plrs = game:GetService("Players")
local ws = game:GetService("Workspace")
-- Local
local plr = plrs.LocalPlayer
-- Global Tables
local library = {}
local utility = {}
local global = {
drawing_containers = {
menu = {},
notification = {},
esp = {},
},
connections = {},
hidden_connections = {},
pointers = {},
theme = {
inline = Color3.fromRGB(3, 3, 3),
dark = Color3.fromRGB(24, 24, 24),
text = Color3.fromRGB(155, 155, 155),
section = Color3.fromRGB(60, 60, 60),
accent = Color3.fromRGB(155, 39, 222)
},
accents = {},
moveKeys = {
["Movement"] = {
["Up"] = "Up",
["Down"] = "Down"
},
["Action"] = {
["Return"] = "Enter",
["Left"] = "Left",
["Right"] = "Right"
}
},
allowedKeyCodes = { "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M", "One", "Two", "Three", "Four", "Five", "Six", "Seveen", "Eight", "Nine", "0", "Insert", "Tab", "Home", "End", "LeftAlt", "LeftControl", "LeftShift", "RightAlt", "RightControl", "RightShift", "CapsLock", "Return", "Up", "Down", "Left", "Right" },
allowedInputTypes = { "MouseButton1", "MouseButton2", "MouseButton3" },
shortenedInputs = {
-- Control Keys
["LeftControl"] = 'left control',
["RightControl"] = 'right control',
["LeftShift"] = 'left shift',
["RightShift"] = 'right shift',
-- Numberbar
["Backquote"] = "grave",
["Tilde"] = "~",
["At"] = "@",
["Hash"] = "#",
["Dollar"] = "$",
["Percent"] = "%",
["Caret"] = "^",
["Ampersand"] = "&",
["Asterisk"] = "*",
["LeftParenthesis"] = "(",
["RightParenthesis"] = ")",
["Underscore"] = '_',
["Minus"] = '-',
["Plus"] = '+',
["Period"] = '.',
["Slash"] = '/',
["BackSlash"] = '\\',
["Question"] = '?',
-- Super
["PageUp"] = "pgup",
["PageDown"] = "pgdwn",
-- Keyboard
["Comma"] = ",",
["Period"] = ".",
["Semicolon"] = ",",
["Colon"] = ":",
["GreaterThan"] = ">",
["LessThan"] = "<",
["LeftBracket"] = "[",
["RightBracket"] = "]",
["LeftCurly"] = "{",
["RightCurly"] = "}",
["Pipe"] = "|",
-- Numberpad
["NumLock"] = "num lock",
["KeypadNine"] = "num 9",
["KeypadEight"] = "num 8",
["KeypadSeven"] = "num 7",
["KeypadSix"] = "num 6",
["KeypadFive"] = "num 5",
["KeypadFour"] = "num 4",
["KeypadThree"] = "num 3",
["KeypadTwo"] = "num 2",
["KeypadOne"] = "num 1",
["KeypadZero"] = "num 0",
["KeypadMultiply"] = "num multiply",
["KeypadDivide"] = "num divide",
["KeypadPeriod"] = "num decimal",
["KeypadPlus"] = "num plus",
["KeypadMinus"] = "num sub",
["KeypadEnter"] = "num enter",
["KeypadEquals"] = "num equals",
-- Mouse
["MouseButton1"] = 'mouse1',
["MouseButton2"] = 'mouse2',
["MouseButton3"] = 'mouse3',
},
colors = { Color3.fromRGB(255, 0, 0), Color3.fromRGB(255, 100, 0), Color3.fromRGB(255, 200, 0), Color3.fromRGB(210, 255, 0), Color3.fromRGB(110, 255, 0), Color3.fromRGB(10, 255, 0), Color3.fromRGB(0, 255, 90), Color3.fromRGB(0, 255, 190), Color3.fromRGB(0, 220, 255), Color3.fromRGB(0, 120, 255), Color3.fromRGB(0, 20, 255), Color3.fromRGB(80, 0, 255), Color3.fromRGB(180, 0, 255), Color3.fromRGB(255, 0, 230), Color3.fromRGB(255, 0, 130), Color3.fromRGB(255, 255, 255), Color3.fromRGB(0, 0, 0) },
toggleKey = { Enum.KeyCode.Home, true },
unloadKey = { Enum.KeyCode.End, true },
saveKey = { Enum.KeyCode.PageUp, true },
loadKey = { Enum.KeyCode.PageDown, true },
windowActive = true,
notifications = {},
}
-- Encrypt Module
do
local BitBuffer
do -- Bit Buffer Module
BitBuffer = {}
local NumberToBase64
local Base64ToNumber
do
NumberToBase64 = {}
Base64ToNumber = {}
local chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
for i = 1, #chars do
local ch = chars:sub(i, i)
NumberToBase64[i - 1] = ch
Base64ToNumber[ch] = i - 1
end
end
local PowerOfTwo;
do
PowerOfTwo = {}
for i = 0, 64 do
PowerOfTwo[i] = 2 ^ i
end
end
local BrickColorToNumber; local NumberToBrickColor; do
BrickColorToNumber = {}
NumberToBrickColor = {}
for i = 0, 63 do
local color = BrickColor.palette(i)
BrickColorToNumber[color.Number] = i
NumberToBrickColor[i] = color
end
end
local floor, insert = math.floor, table.insert
function ToBase(n, b)
n = floor(n)
if not b or b == 10 then return tostring(n) end
local digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
local t = {}
local sign = ""
if n < 0 then
sign = "-"
n = -n
end
repeat
local d = (n % b) + 1
n = floor(n / b)
insert(t, 1, digits:sub(d, d))
until n == 0
return sign .. table.concat(t, "")
end
function BitBuffer.Create()
local this = {}
-- Tracking
local mBitPtr = 0
local mBitBuffer = {}
function this:ResetPtr()
mBitPtr = 0
end
function this:Reset()
mBitBuffer = {}
mBitPtr = 0
end
-- Set debugging on
local mDebug = false
function this:SetDebug(state)
mDebug = state
end
-- Read / Write to a string
function this:FromString(str)
this:Reset()
for i = 1, #str do
local ch = str:sub(i, i):byte()
for i = 1, 8 do
mBitPtr = mBitPtr + 1
mBitBuffer[mBitPtr] = ch % 2
ch = math.floor(ch / 2)
end
end
mBitPtr = 0
end
function this:ToString()
local str = ""
local accum = 0
local pow = 0
for i = 1, math.ceil((#mBitBuffer) / 8) * 8 do
accum = accum + PowerOfTwo[pow] * (mBitBuffer[i] or 0)
pow = pow + 1
if pow >= 8 then
str = str .. string.char(accum)
accum = 0
pow = 0
end
end
return str
end
-- Read / Write to base64
function this:FromBase64(str)
this:Reset()
for i = 1, #str do
local ch = Base64ToNumber[str:sub(i, i)]
assert(ch, "Bad character: 0x" .. ToBase(str:sub(i, i):byte(), 16))
for i = 1, 6 do
mBitPtr = mBitPtr + 1
mBitBuffer[mBitPtr] = ch % 2
ch = math.floor(ch / 2)
end
assert(ch == 0, "Character value 0x" .. ToBase(Base64ToNumber[str:sub(i, i)], 16) .. " too large")
end
this:ResetPtr()
end
function this:ToBase64()
local strtab = {}
local accum = 0
local pow = 0
for i = 1, math.ceil((#mBitBuffer) / 6) * 6 do
accum = accum + PowerOfTwo[pow] * (mBitBuffer[i] or 0)
pow = pow + 1
if pow >= 6 then
table.insert(strtab, NumberToBase64[accum])
accum = 0
pow = 0
end
end
return table.concat(strtab)
end
-- Dump
function this:Dump()
local str = ""
local str2 = ""
local accum = 0
local pow = 0
for i = 1, math.ceil((#mBitBuffer) / 8) * 8 do
str2 = str2 .. (mBitBuffer[i] or 0)
accum = accum + PowerOfTwo[pow] * (mBitBuffer[i] or 0)
--print(pow..": +"..PowerOfTwo[pow].."*["..(mBitBuffer[i] or 0).."] -> "..accum)
pow = pow + 1
if pow >= 8 then
str2 = str2 .. " "
str = str .. "0x" .. ToBase(accum, 16) .. " "
accum = 0
pow = 0
end
end
end
-- Read / Write a bit
local function writeBit(v)
mBitPtr = mBitPtr + 1
mBitBuffer[mBitPtr] = v
end
local function readBit(v)
mBitPtr = mBitPtr + 1
return mBitBuffer[mBitPtr]
end
-- Read / Write an unsigned number
function this:WriteUnsigned(w, value, printoff)
assert(w, "Bad arguments to BitBuffer::WriteUnsigned (Missing BitWidth)")
assert(value, "Bad arguments to BitBuffer::WriteUnsigned (Missing Value)")
assert(value >= 0, "Negative value to BitBuffer::WriteUnsigned")
assert(math.floor(value) == value, "Non-integer value to BitBuffer::WriteUnsigned")
if mDebug and not printoff then
print("WriteUnsigned[" .. w .. "]:", value)
end
-- Store LSB first
for i = 1, w do
writeBit(value % 2)
value = math.floor(value / 2)
end
assert(value == 0, "Value " .. tostring(value) .. " has width greater than " .. w .. "bits")
end
function this:ReadUnsigned(w, printoff)
local value = 0
for i = 1, w do
value = value + readBit() * PowerOfTwo[i - 1]
end
return value
end
-- Read / Write a signed number
function this:WriteSigned(w, value)
assert(w and value, "Bad arguments to BitBuffer::WriteSigned (Did you forget a bitWidth?)")
assert(math.floor(value) == value, "Non-integer value to BitBuffer::WriteSigned")
-- Write sign
if value < 0 then
writeBit(1)
value = -value
else
writeBit(0)
end
-- Write value
this:WriteUnsigned(w - 1, value, true)
end
function this:ReadSigned(w)
-- Read sign
local sign = (-1) ^ readBit()
-- Read value
local value = this:ReadUnsigned(w - 1, true)
if mDebug then
print("ReadSigned[" .. w .. "]:", sign * value)
end
return sign * value
end
-- Read / Write a string. May contain embedded nulls (string.char(0))
function this:WriteString(s)
-- First check if it's a 7 or 8 bit width of string
local bitWidth = 7
for i = 1, #s do
if s:sub(i, i):byte() > 127 then
bitWidth = 8
break
end
end
-- Write the bit width flag
if bitWidth == 7 then
this:WriteBool(false)
else
this:WriteBool(true) -- wide chars
end
-- Now write out the string, terminated with "0x10, 0b0"
-- 0x10 is encoded as "0x10, 0b1"
for i = 1, #s do
local ch = s:sub(i, i):byte()
if ch == 0x10 then
this:WriteUnsigned(bitWidth, 0x10)
this:WriteBool(true)
else
this:WriteUnsigned(bitWidth, ch)
end
end
-- Write terminator
this:WriteUnsigned(bitWidth, 0x10)
this:WriteBool(false)
end
function this:ReadString()
-- Get bit width
local bitWidth;
if this:ReadBool() then
bitWidth = 8
else
bitWidth = 7
end
-- Loop
local str = ""
while true do
local ch = this:ReadUnsigned(bitWidth)
if ch == 0x10 then
local flag = this:ReadBool()
if flag then
str = str .. string.char(0x10)
else
break
end
else
str = str .. string.char(ch)
end
end
return str
end
-- Read / Write a bool
function this:WriteBool(v)
if v then
this:WriteUnsigned(1, 1, true)
else
this:WriteUnsigned(1, 0, true)
end
end
function this:ReadBool()
local v = (this:ReadUnsigned(1, true) == 1)
return v
end
-- Read / Write a floating point number with |wfrac| fraction part
-- bits, |wexp| exponent part bits, and one sign bit.
function this:WriteFloat(wfrac, wexp, f)
assert(wfrac and wexp and f)
-- Sign
local sign = 1
if f < 0 then
f = -f
sign = -1
end
-- Decompose
local mantissa, exponent = math.frexp(f)
if exponent == 0 and mantissa == 0 then
this:WriteUnsigned(wfrac + wexp + 1, 0)
return
else
mantissa = ((mantissa - 0.5) / 0.5 * PowerOfTwo[wfrac])
end
-- Write sign
if sign == -1 then
this:WriteBool(true)
else
this:WriteBool(false)
end
-- Write mantissa
mantissa = math.floor(mantissa + 0.5) -- Not really correct, should round up/down based on the parity of |wexp|
this:WriteUnsigned(wfrac, mantissa)
-- Write exponent
local maxExp = PowerOfTwo[wexp - 1] - 1
if exponent > maxExp then
exponent = maxExp
end
if exponent < -maxExp then
exponent = -maxExp
end
this:WriteSigned(wexp, exponent)
end
function this:ReadFloat(wfrac, wexp)
assert(wfrac and wexp)
-- Read sign
local sign = 1
if this:ReadBool() then
sign = -1
end
-- Read mantissa
local mantissa = this:ReadUnsigned(wfrac)
-- Read exponent
local exponent = this:ReadSigned(wexp)
if exponent == 0 and mantissa == 0 then
return 0
end
-- Convert mantissa
mantissa = mantissa / PowerOfTwo[wfrac] * 0.5 + 0.5
-- Output
return sign * math.ldexp(mantissa, exponent)
end
-- Read / Write single precision floating point
function this:WriteFloat32(f)
this:WriteFloat(23, 8, f)
end
function this:ReadFloat32()
return this:ReadFloat(23, 8)
end
-- Read / Write double precision floating point
function this:WriteFloat64(f)
this:WriteFloat(52, 11, f)
end
function this:ReadFloat64()
return this:ReadFloat(52, 11)
end
-- Read / Write a BrickColor
function this:WriteBrickColor(b)
local pnum = BrickColorToNumber[b.Number]
if not pnum then
warn("Attempt to serialize non-pallete BrickColor `" ..
tostring(b) .. "` (#" .. b.Number .. "), using Light Stone Grey instead.")
pnum = BrickColorToNumber[BrickColor.new(1032).Number]
end
this:WriteUnsigned(6, pnum)
end
function this:ReadBrickColor()
return NumberToBrickColor[this:ReadUnsigned(6)]
end
-- Read / Write a rotation as a 64bit value.
local function round(n)
return math.floor(n + 0.5)
end
function this:WriteRotation(cf)
local lookVector = cf.lookVector
local azumith = math.atan2(-lookVector.X, -lookVector.Z)
local ybase = (lookVector.X ^ 2 + lookVector.Z ^ 2) ^ 0.5
local elevation = math.atan2(lookVector.Y, ybase)
local withoutRoll = CFrame.new(cf.p) * CFrame.Angles(0, azumith, 0) * CFrame.Angles(elevation, 0, 0)
local x, y, z = (withoutRoll:inverse() * cf):toEulerAnglesXYZ()
local roll = z
-- Atan2 -> in the range [-pi, pi]
azumith = round((azumith / math.pi) * (2 ^ 21 - 1))
roll = round((roll / math.pi) * (2 ^ 20 - 1))
elevation = round((elevation / (math.pi / 2)) * (2 ^ 20 - 1))
--
this:WriteSigned(22, azumith)
this:WriteSigned(21, roll)
this:WriteSigned(21, elevation)
end
function this:ReadRotation()
local azumith = this:ReadSigned(22)
local roll = this:ReadSigned(21)
local elevation = this:ReadSigned(21)
--
azumith = math.pi * (azumith / (2 ^ 21 - 1))
roll = math.pi * (roll / (2 ^ 20 - 1))
elevation = (math.pi / 2) * (elevation / (2 ^ 20 - 1))
--
local rot = CFrame.Angles(0, azumith, 0)
rot = rot * CFrame.Angles(elevation, 0, 0)
rot = rot * CFrame.Angles(0, 0, roll)
--
return rot
end
return this
end
end
local TypeIntegerLength = 3
local IntegerLength = 10
local function TypeToId(Type)
if Type == "Integer" then
return 1
elseif Type == "NegInteger" then
return 2
elseif Type == "Number" then
return 3
elseif Type == "String" then
return 4
elseif Type == "Boolean" then
return 5
elseif Type == "Table" then
return 6
end
return 0
end
local function IdToType(Type)
if Type == 1 then
return "Integer"
elseif Type == 2 then
return "NegInteger"
elseif Type == 3 then
return "Number"
elseif Type == 4 then
return "String"
elseif Type == 5 then
return "Boolean"
elseif Type == 6 then
return "Table"
end
end
local function IsInt(Number)
local Decimal = string.find(tostring(Number), "%.")
if Decimal then
return false
else
return true
end
end
local function log(Base, Number)
return math.log(Number) / math.log(Base)
end
local function GetMaxBitsInt(Table)
local Max = 0
for Key, Value in pairs(Table) do
if type(Value) == "number" then
Value = math.abs(Value)
if IsInt(Value) and Value > 0 then
local Bits = math.ceil(log(2, Value + 1))
if Bits > Max then Max = Bits end
end
end
if type(Key) == "number" then
Key = math.abs(Key)
if IsInt(Key) and Key > 0 then
local Bits = math.ceil(log(2, Key + 1))
if Bits > Max then Max = Bits end
end
end
end
return Max * 2
end
local function GetTableLength(Table)
local Total = 0
for _, _ in pairs(Table) do
Total = Total + 1
end
return Total
end
local function GetType(Key)
local Type = type(Key)
if Type == "number" then
if IsInt(Key) then
if Key < 0 then
return "NegInteger"
end
return "Integer"
else
return "Number"
end
else
return Type
end
end
local function GetAllType(Table)
local Type
for Key, _ in pairs(Table) do
if not Type then
Type = GetType(Key)
end
if type(Key) ~= Type then
local NewType = GetType(Key)
if NewType ~= Type then
return nil
end
end
end
if Type == "Number" then
return "Number"
elseif Type == "Integer" then
return "Integer"
elseif Type == "NegInteger" then
return "NegInteger"
else
return "String"
end
end
local crypt = {}
function crypt:encode(Table, UseBase64)
local AllType = GetAllType(Table)
local Buffer = BitBuffer.Create()
if UseBase64 == true then
Buffer:WriteBool(true)
else
Buffer:WriteBool(false)
end
Buffer:WriteUnsigned(IntegerLength, GetTableLength(Table))
local function WriteFloat(Number)
if UseBase64 == true then
Buffer:WriteFloat64(Number)
else
Buffer:WriteFloat32(Number)
end
end
Buffer:WriteUnsigned(TypeIntegerLength, TypeToId(AllType))
local MaxBits = GetMaxBitsInt(Table)
Buffer:WriteUnsigned(IntegerLength, MaxBits)
local function WriteKey(Key, AllowAllSame)
if not (AllowAllSame == true and AllType) then
Buffer:WriteUnsigned(TypeIntegerLength, Key)
elseif AllowAllSame == false then
Buffer:WriteUnsigned(TypeIntegerLength, Key)
end
end
for Key, Value in pairs(Table) do
if type(Key) == "string" then
WriteKey(TypeToId("String"), true)
Buffer:WriteString(Key)
elseif type(Key) == "number" and IsInt(Key) then
if Key >= 0 then
WriteKey(TypeToId("Integer"), true)
Buffer:WriteUnsigned(MaxBits, Key)
else
WriteKey(TypeToId("NegInteger"), true)
Buffer:WriteSigned(MaxBits * 2, Key)
end
elseif type(Key) == "number" then
WriteKey(TypeToId("Number"), true)
WriteFloat(Key)
end
if type(Value) == "boolean" then
WriteKey(TypeToId("Boolean"))
Buffer:WriteBool(Value)
elseif type(Value) == "number" then
if IsInt(Value) then
if Value < 0 then
WriteKey(TypeToId("NegInteger"))
Buffer:WriteSigned(MaxBits * 2, Value)
else
WriteKey(TypeToId("Integer"))
Buffer:WriteUnsigned(MaxBits, Value)
end
else
WriteKey(TypeToId("Number"))
WriteFloat(Value)
end
elseif type(Value) == "table" then
WriteKey(TypeToId("Table"))
Buffer:WriteString(crypt:encode(Value, UseBase64))
elseif type(Value) == "string" then
WriteKey(TypeToId("String"))
Buffer:WriteString(tostring(Value))
end
end
return Buffer:ToBase64()
end
function crypt:decode(BinaryString)
local Buffer = BitBuffer.Create()
Buffer:FromBase64(BinaryString)
local Table = {}
local UseBase64 = Buffer:ReadBool()
local function ReadFloat()
if UseBase64 == true then
return Buffer:ReadFloat64()
else
return Buffer:ReadFloat32()
end
end
local Length = Buffer:ReadUnsigned(IntegerLength)
local AllType = Buffer:ReadUnsigned(TypeIntegerLength)
local MaxBits = Buffer:ReadUnsigned(IntegerLength)
if AllType == 0 then AllType = nil end
for i = 1, Length do
local KeyType, Key = AllType or Buffer:ReadUnsigned(TypeIntegerLength)
local KeyRealType = IdToType(KeyType)
if KeyRealType == "Integer" then
Key = Buffer:ReadUnsigned(MaxBits)
elseif KeyRealType == "NegInteger" then
Key = Buffer:ReadSigned(MaxBits * 2)
elseif KeyRealType == "Number" then
Key = ReadFloat()
elseif KeyRealType == "String" then
Key = Buffer:ReadString()
end
local ValueType, Value = Buffer:ReadUnsigned(TypeIntegerLength)
local ValueRealType = IdToType(ValueType)
if ValueRealType == "String" then
Value = Buffer:ReadString()
elseif ValueRealType == "Boolean" then
Value = Buffer:ReadBool()
elseif ValueRealType == "Number" then
Value = ReadFloat()
elseif ValueRealType == "Integer" then
Value = Buffer:ReadUnsigned(MaxBits)
elseif ValueRealType == "NegInteger" then
Value = Buffer:ReadSigned((MaxBits * 2))
elseif ValueRealType == "Table" then
Value = crypt:decode(Buffer:ReadString())
elseif ValueRealType == "Color3" then
Value = Color3.new(ReadFloat(), ReadFloat(), ReadFloat())
elseif ValueRealType == "CFrame" then
Value = CFrame.new(ReadFloat(), ReadFloat(), ReadFloat()) * Buffer:ReadRotation()
elseif ValueRealType == "BrickColor" then
Value = Buffer:ReadBrickColor()
elseif ValueRealType == "UDim2" then
Value = UDim2.new(ReadFloat(), ReadFloat(), ReadFloat(), ReadFloat())
elseif ValueRealType == "UDim" then
Value = UDim.new(ReadFloat(), ReadFloat())
elseif ValueRealType == "Region3" then
Value = Region3.new(Vector3.new(ReadFloat(), ReadFloat(), ReadFloat()),
Vector3.new(ReadFloat(), ReadFloat(), ReadFloat()))
elseif ValueRealType == "Region3int16" then
Value = Region3int16.new(Vector3int16.new(ReadFloat(), ReadFloat(), ReadFloat()),
Vector3int16.new(ReadFloat(), ReadFloat(), ReadFloat()))
elseif ValueRealType == "Vector3" then
Value = Vector3.new(ReadFloat(Value.X), ReadFloat(Value.Y), ReadFloat(Value.Z))
elseif ValueRealType == "Vector2" then
Value = Vector2.new(ReadFloat(Value.X), ReadFloat(Value.Y))
elseif ValueRealType == "EnumItem" then
Value = Enum[Buffer:ReadString()][Buffer:ReadString()]
elseif ValueRealType == "Enums" then
Value = Enum[Buffer:ReadString()]
elseif ValueRealType == "Enum" then
Value = Enum
elseif ValueRealType == "Ray" then
Value = Ray.new(Vector3.new(ReadFloat(), ReadFloat(), ReadFloat()),
Vector3.new(ReadFloat(), ReadFloat(), ReadFloat()))
elseif ValueRealType == "Axes" then
local X, Y, Z = Buffer:ReadBool(), Buffer:ReadBool(), Buffer:ReadBool()
Value = Axes.new(X == true and Enum.Axis.X, Y == true and Enum.Axis.Y, Z == true and Enum.Axis.Z)
elseif ValueRealType == "Faces" then
local Front, Back, Left, Right, Top, Bottom = Buffer:ReadBool(), Buffer:ReadBool(), Buffer:ReadBool(),
Buffer:ReadBool(), Buffer:ReadBool(), Buffer:ReadBool()
Value = Faces.new(Front == true and Enum.NormalId.Front, Back == true and Enum.NormalId.Back,
Left == true and Enum.NormalId.Left, Right == true and Enum.NormalId.Right,
Top == true and Enum.NormalId.Top, Bottom == true and Enum.NormalId.Bottom)
elseif ValueRealType == "ColorSequence" then
local Points = crypt:decode(Buffer:ReadString())
Value = ColorSequence.new(Points[1].Value, Points[2].Value)
elseif ValueRealType == "ColorSequenceKeypoint" then
Value = ColorSequenceKeypoint.new(ReadFloat(), Color3.new(ReadFloat(), ReadFloat(), ReadFloat()))
elseif ValueRealType == "NumberRange" then
Value = NumberRange.new(ReadFloat(), ReadFloat())
elseif ValueRealType == "NumberSequence" then
Value = NumberSequence.new(crypt:decode(Buffer:ReadString()))
elseif ValueRealType == "NumberSequenceKeypoint" then
Value = NumberSequenceKeypoint.new(ReadFloat(), ReadFloat(), ReadFloat())
end
Table[Key] = Value
end
return Table
end
global.crypt = crypt
end
-- Utility Functions
do
function utility:Create(instanceType, instanceProperties, container)
local instance = Drawing.new(instanceType)
local parent
--
if instanceProperties["Parent"] or instanceProperties["parent"] then
parent = instanceProperties["Parent"] or instanceProperties["parent"]
--
instanceProperties["parent"] = nil
instanceProperties["Parent"] = nil
end
--
for property, value in pairs(instanceProperties) do
if property and value then
if property == "Size" or property == "Size" then
if instanceType == "Text" then
instance.Size = value
else
local xSize = (value.X.Scale * ((parent and parent.Size) or ws.CurrentCamera.ViewportSize).X) +
value.X.Offset
local ySize = (value.Y.Scale * ((parent and parent.Size) or ws.CurrentCamera.ViewportSize).Y) +
value.Y.Offset
--
instance.Size = Vector2.new(xSize, ySize)
end
elseif property == "Position" or property == "position" then
if instanceType == "Text" then
local xPosition = ((((parent and parent.Position) or Vector2.new(0, 0)).X) + (value.X.Scale * ((typeof(parent.Size) == "number" and parent.TextBounds) or parent.Size).X)) +
value.X.Offset
local yPosition = ((((parent and parent.Position) or Vector2.new(0, 0)).Y) + (value.Y.Scale * ((typeof(parent.Size) == "number" and parent.TextBounds) or parent.Size).Y)) +
value.Y.Offset
--
instance.Position = Vector2.new(xPosition, yPosition)
else
local xPosition = ((((parent and parent.Position) or Vector2.new(0, 0)).X) + value.X.Scale * ((parent and parent.Size) or ws.CurrentCamera.ViewportSize).X) +
value.X.Offset
local yPosition = ((((parent and parent.Position) or Vector2.new(0, 0)).Y) + value.Y.Scale * ((parent and parent.Size) or ws.CurrentCamera.ViewportSize).Y) +
value.Y.Offset
--
instance.Position = Vector2.new(xPosition, yPosition)
end
elseif property == "Color" or property == "color" then
if typeof(value) == "string" then
instance["Color"] = global.theme[value]
--
if value == "accent" then
global.accents[#global.accents + 1] = instance
end
else
instance[property] = value
end
else
instance[property] = value
end
end
end
--
global.drawing_containers[container][#global.drawing_containers[container] + 1] = instance
--
return instance
end
function utility:Update(instance, instanceProperty, instanceValue, instanceParent)
if instanceProperty == "Size" or instanceProperty == "Size" then
local xSize = (instanceValue.X.Scale * ((instanceParent and instanceParent.Size) or ws.CurrentCamera.ViewportSize).X) +
instanceValue.X.Offset
local ySize = (instanceValue.Y.Scale * ((instanceParent and instanceParent.Size) or ws.CurrentCamera.ViewportSize).Y) +
instanceValue.Y.Offset
--
instance.Size = Vector2.new(xSize, ySize)
elseif instanceProperty == "Position" or instanceProperty == "position" then
local xPosition = ((((instanceParent and instanceParent.Position) or Vector2.new(0, 0)).X) + (instanceValue.X.Scale * ((typeof(instanceParent.Size) == "number" and instanceParent.TextBounds) or instanceParent.Size).X)) +
instanceValue.X.Offset
local yPosition = ((((instanceParent and instanceParent.Position) or Vector2.new(0, 0)).Y) + (instanceValue.Y.Scale * ((typeof(instanceParent.Size) == "number" and instanceParent.TextBounds) or instanceParent.Size).Y)) +
instanceValue.Y.Offset
--
instance.Position = Vector2.new(xPosition, yPosition)
elseif instanceProperty == "Color" or instanceProperty == "color" then
if typeof(instanceValue) == "string" then
instance.Color = global.theme[instanceValue]
--
if instanceValue == "accent" then
global.accents[#global.accents + 1] = instance
else
if table.find(global.accents, instance) then
table.remove(global.accents, table.find(global.accents, instance))
end
end
else
instance.Color = instanceValue
end
end
end
function utility:Connection(connectionType, connectionCallback)
local connection = connectionType:Connect(connectionCallback)
global.connections[#global.connections + 1] = connection
--
return connection
end
function utility:RemoveConnection(connection)
for index, con in pairs(global.connections) do
if con == connection then
global.connections[index] = nil
con:Disconnect()
end
end
--
for index, con in pairs(global.hidden_connections) do
if con == connection then
global.hidden_connections[index] = nil
con:Disconnect()
end
end
end
function utility:Object(type, properties)
local object = Instance.new(type)
for i, v in next, properties do
object[i] = v
end