-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMInstance.luau
More file actions
740 lines (595 loc) · 23.7 KB
/
MInstance.luau
File metadata and controls
740 lines (595 loc) · 23.7 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
--!optimize 2
local NULL = nil
local EMPTY_TABLE = {}
local AssetService = game:GetService("AssetService")
local ReflectionServiceWrapper = require(script.DefaultProperties)
local BufferEncoder = require(script.BufferEncoder)
local OldCompress = require(script.OldCompress)
local NewCompress = require(script.NewCompress)
local Base94 = require(script.Encoders.Base94)
local CreateInstanceMap, ReverseInstanceMap -- these function are declared this way because they will be calling themselves
local InstanceReferenceCache = {}
local CreatableInstancesCache = {}
local PropertiesOfClassCache = {}
local PropertyCompressionCount = 0 -- resets every mapping session, make sure to reset inside serializeinstance after use
local Minstance = {}
local InstanceCreationInternalHooks = {}
-- localize luau api functions for faster access, avoid having to invoke the internal metamethods to fetch a function like "new" from Instance (Instance.new)
local Instance_new = Instance.new
local table_insert = table.insert
local table_create = table.create
local string_format = string.format
local buffer_tostring = buffer.tostring
local buffer_fromstring = buffer.fromstring
local table_clear = table.clear
local debug_info = debug.info
local os_clock = os.clock
local typeof = typeof
local type = type
local ipairs = ipairs
local __index = function(Object, Index)
return Object[Index]
end
local __newindex = function(Object, Index, New)
Object[Index] = New
end
-- see if we can fetch the internal metamethods for faster indexing and newindexing (proven to be 15% faster! WOW!)
pcall(function()
local TemporaryInstance = Instance_new("Part")
local SuspectedIndex = select(2, xpcall(function()
return game.___
end, function()
return debug_info(2, "f")
end))
local SuspectedNewindex = select(2, xpcall(function()
game.___ = NULL
end, function()
return debug_info(2, "f")
end))
SuspectedNewindex(TemporaryInstance, "Name", "i love my girlfriend yana")
if TemporaryInstance.Name == "i love my girlfriend yana" then
__newindex = SuspectedNewindex
end
if SuspectedIndex(TemporaryInstance, "Name") == "i love my girlfriend yana" then
__index = SuspectedIndex
end
TemporaryInstance:Destroy()
end)
if ReflectionServiceWrapper.InitializeApiDump() ~= true then
return error("Failed to initialize API. Minstance will not work.")
end
local IsClassCreatable = function(ClassName)
local Cached = CreatableInstancesCache[ClassName]
if Cached then
return Cached
end
local Status, TestInstance = pcall(Instance_new, ClassName)
if not Status or TestInstance == NULL then
CreatableInstancesCache[ClassName] = false
return false
else
pcall(function()
TestInstance:Destroy()
end)
CreatableInstancesCache[ClassName] = true
return true
end
end
local SafelyIndexInto = function(Object, Index)
local Status, Value = pcall(__index, Object, Index)
if Status then
return Status, Value
else
return Status
end
end
local ThrowToConsole = function(Message, Type)
if Type == 2 then
return error(`[Minstance] {Message}`)
-- elseif Type == 1 then
-- return warn(`[Minstance] {Message}`)
-- end
end
-- return print(`[Minstance] {Message}`)
return warn(`[Minstance] {Message}`)
end
local CreateAddressFromDescendantToParent = function(Descendant, Parent)
local Address = {}
local CurrentDescendant = Descendant
if Descendant == Parent then
return {0}
end
while CurrentDescendant and CurrentDescendant ~= Parent do
local DescendantParent = __index(CurrentDescendant, "Parent")
if not DescendantParent then
return {}
end
local Position = 0
for i, Child in ipairs(DescendantParent:GetChildren()) do
if Child == CurrentDescendant then
Position = i
break
end
end
table_insert(Address, 1, Position)
CurrentDescendant = DescendantParent
end
return Address
end
CreateInstanceMap = function(TargetInstance, IncludeDescendants, PrintProcess, MainInstanceReference, IncludeAttributes, DisallowedProperties, PropertyCompression)
local ClassName = __index(TargetInstance, "ClassName")
local Map = {
C = ClassName, -- the key of this dict was previously ClassName, shortened for compression
P = {} -- the key of this dict was previously Properties, shortened for compression
}
if not PropertyCompression then
Map.PC = {} -- the key of this dict was previously PropertyCompression, shortened for compression
PropertyCompression = Map.PC
end
if not IsClassCreatable(ClassName) then
ThrowToConsole(`Skipping Instance "{TargetInstance:GetFullName()}" ({ClassName}) because it is not creatable.`)
return
end
local FreshInstance, PropertiesOfClass
local PropertiesInMap = Map.P
local FoundValidPropertyOnce = false
local CachedFreshInstance = InstanceReferenceCache[ClassName]
local PropertiesCache = PropertiesOfClassCache[ClassName]
if PropertiesCache then
PropertiesOfClass = PropertiesCache
else
PropertiesOfClass = ReflectionServiceWrapper.GetPropertiesOfClass(ClassName)
PropertiesOfClassCache[ClassName] = PropertiesOfClass
end
if CachedFreshInstance then
FreshInstance = CachedFreshInstance
else
FreshInstance = Instance_new(ClassName)
InstanceReferenceCache[ClassName] = FreshInstance
end
for _, Property in ipairs(PropertiesOfClass) do
if DisallowedProperties then
local List = DisallowedProperties[ClassName]
if List then
if List[Property] then
continue
end
end
end
if not PropertiesInMap[Property] and Property ~= "Parent" then
local Status, ValueInFreshInstance = SafelyIndexInto(FreshInstance, Property)
if Status then
local ValueInOriginalInstance = __index(TargetInstance, Property)
if ValueInFreshInstance ~= ValueInOriginalInstance then
if not FoundValidPropertyOnce then
FoundValidPropertyOnce = true
end
-- i just realized i can compress my serialized data further by generating a list of properties used in all of the instances and having that list in the main instance map like {Name = 1, BrickColor = 2, ...} and then the properties table of child instances would be {[1] = "name", [2] = enum.some.value}
local ShortenedProperty = PropertyCompression[Property]
if not ShortenedProperty then
PropertyCompressionCount = PropertyCompressionCount + 1
PropertyCompression[Property] = PropertyCompressionCount
ShortenedProperty = PropertyCompressionCount
end
if typeof(ValueInOriginalInstance) == "Instance" then -- this is rare to occur
if ValueInOriginalInstance == MainInstanceReference then
PropertiesInMap[ShortenedProperty] = {["Pointer"] = {0}}
else
if ValueInOriginalInstance:IsDescendantOf(MainInstanceReference) then
local Pointer = CreateAddressFromDescendantToParent(ValueInOriginalInstance, MainInstanceReference)
if #Pointer >= 1 then
PropertiesInMap[ShortenedProperty] = {["Pointer"] = Pointer}
end
else
ThrowToConsole(`Skipping property "{Property}" of Instance "{TargetInstance:GetFullName()}" ({ClassName}) because the value of the property references an Instance that is not a descendant of the main Instance being serialized.`)
end
end
else
PropertiesInMap[ShortenedProperty] = ValueInOriginalInstance
end
end
end
end
end
if not FoundValidPropertyOnce then
Map.P = NULL -- the key of this dict was previously Properties, shortened for compression
end
if IncludeAttributes then
local Attributes = TargetInstance:GetAttributes()
for _ in pairs(Attributes) do
Map.A = Attributes -- the key of this dict was previously Attributes, shortened for compression
break
end
end
-- if PrintProcess then
-- ThrowToConsole(`Mapping Instance "{TargetInstance:GetFullName()}" ({ClassName})...`)
-- end
if IncludeDescendants then
local Children = TargetInstance:GetChildren()
local ChildrenCount = #Children
if ChildrenCount > 0 then
Map.K = table_create(ChildrenCount) -- the key of this dict was previously Children, shortened for compression, now set to K as in Kids
local MicroOptimizationReference = Map.K
for _, Child in ipairs(Children) do
local NewInstanceMap = CreateInstanceMap(Child, true, PrintProcess, MainInstanceReference, IncludeAttributes, DisallowedProperties, PropertyCompression)
if NewInstanceMap then
table_insert(MicroOptimizationReference, NewInstanceMap)
end
end
end
end
return Map
end
-- support meshparts deserialization
local CreateMeshPart = function(Id, Options)
local Success, ErrorOrMeshPart = pcall(function()
return AssetService:CreateMeshPartAsync(Id, Options)
end)
if Success then
return ErrorOrMeshPart
else
ThrowToConsole(`Failed to create MeshPart with content ID "{tostring(Id)}". Returning default MeshPart. Error: {ErrorOrMeshPart}`)
return Instance_new("MeshPart")
end
end
InstanceCreationInternalHooks.MeshPart = function(Properties, InvertedPropertyCompression)
local Id
local Options = {}
local HandledProperties = {}
-- WASTE OF CPU CYCLES I KNOW.. TODO: FIX
for PropertyId, Value in pairs(Properties) do
local PropertyName = InvertedPropertyCompression[PropertyId]
if PropertyName == "MeshContent" then
if not Id then
Id = Value
end
HandledProperties[PropertyName] = true
elseif PropertyName == "MeshId" then
if not Id then
Id = Value
end
HandledProperties[PropertyName] = true
elseif PropertyName == "CollisionFidelity" then
Options["CollisionFidelity"] = Value
HandledProperties[PropertyName] = true
elseif PropertyName == "RenderFidelity" then
Options["RenderFidelity"] = Value
HandledProperties[PropertyName] = true
elseif PropertyName == "FluidFidelity" then
Options["FluidFidelity"] = Value
HandledProperties[PropertyName] = true
end
end
if not Id then
ThrowToConsole("Attempted to deserialize a MeshPart without a MeshId property. Returning default MeshPart.")
return Instance_new("MeshPart"), {}
end
if not next(Options) then
Options = nil
end
-- silence the noise.
HandledProperties["MeshContent"] = true
return CreateMeshPart(Id, Options), HandledProperties
end
ReverseInstanceMap = function(Map, ParentOfInstance, DeserializeMeshPartsProperly, MainMapReference, TemporaryCacheTable, PropertyCompression)
local ClassName = Map.C
local Properties = Map.P
local Children = Map.K
local Attributes = Map.A
local CallbackTable = Map.Callbacks
local InternalPropertyHooks = EMPTY_TABLE
local UseInternalPropertyHooks = false -- CPU CYCLES MUST NOT GO TO WASTE!!
local CreationHook = InstanceCreationInternalHooks[ClassName]
local MainInstance
if not PropertyCompression then
local PotentialPropertyCompression = Map.PC
if not PotentialPropertyCompression then
return ThrowToConsole(`This version of MInstance is sadly not backwards compatible with MInstance 1.0 data due to changes in data structure to achieve more compression.`)
else
local ReversedPC = {}
for PropertyName, PropertyId in pairs(PotentialPropertyCompression) do
ReversedPC[PropertyId] = PropertyName
end
PropertyCompression = ReversedPC
end
end
if CreationHook then
if ClassName == "MeshPart" then
if DeserializeMeshPartsProperly then
UseInternalPropertyHooks = true
MainInstance, InternalPropertyHooks = CreationHook(Properties, PropertyCompression)
else
MainInstance = Instance_new(ClassName)
end
else
MainInstance = CreationHook(Properties, PropertyCompression)
end
else
MainInstance = Instance_new(ClassName)
end
local SafelySetProperty = function(Property, Value)
local Status, Error = pcall(__newindex, MainInstance, Property, Value)
if not Status then
ThrowToConsole(`Unable to set property {Property} to Instance "{tostring(MainInstance)}" ({ClassName}) for reason: "{Error}"`)
end
end
TemporaryCacheTable[Map] = MainInstance
if CallbackTable then
for _,func in CallbackTable do
func(MainInstance)
end
end
if ParentOfInstance then
__newindex(MainInstance, "Parent", ParentOfInstance)
end
if Properties then
for PropertyId, Value in pairs(Properties) do
local PropertyName = PropertyCompression[PropertyId]
if not PropertyName then
ThrowToConsole(`A property with an unknown name has been skipped due to it not being in the reverse table (PropertyCompression table). If you encounter this, data corruption might have occured to the serialized data.`)
continue
end
if type(Value) == "table" then
local Location = Value.Pointer
if type(Location) == "table" then
if #Location >= 1 then
local CurrentlyPointingTo = NULL
if #Location == 1 and Location[1] == 0 then
CurrentlyPointingTo = MainMapReference
else
for _, Index in ipairs(Location) do
if CurrentlyPointingTo then
local ChildrenList = CurrentlyPointingTo.K
if ChildrenList then
local IsValidMap = ChildrenList[Index]
if IsValidMap then
CurrentlyPointingTo = IsValidMap
else
ThrowToConsole(`Skipped setting property "{PropertyName}" to Instance "{tostring(MainInstance)}" because it was trying to find the Instance that the property was referencing to but could not find it.`)
break
end
end
else
local ChildrenList = MainMapReference.K
if ChildrenList then
local IsValidMap = ChildrenList[Index]
if IsValidMap then
CurrentlyPointingTo = IsValidMap
else
ThrowToConsole(`Skipped setting property "{PropertyName}" to Instance "{tostring(MainInstance)}" because it was trying to find the Instance that the property was referencing to but could not find it.`)
break
end
end
end
end
end
local CachedInstance = TemporaryCacheTable[CurrentlyPointingTo]
if CachedInstance then
SafelySetProperty(PropertyName, CachedInstance)
else
local function Callback(GotInstance)
SafelySetProperty(PropertyName, GotInstance)
end
if CurrentlyPointingTo.Callbacks then
table_insert(CurrentlyPointingTo.Callbacks, Callback)
else
CurrentlyPointingTo.Callbacks = {Callback}
end
end
else
ThrowToConsole(`Skipped setting property "{PropertyName}" to Instance "{tostring(MainInstance)}" because it was trying to find the Instance that the property was referencing to but could not find it.`)
end
end
else
if UseInternalPropertyHooks then -- CPU CYCLES MUST NOT GO TO WASTE!!
if InternalPropertyHooks[PropertyName] then
continue
end
end
SafelySetProperty(PropertyName, Value)
end
end
end
if Attributes then
for Name, Value in pairs(Attributes) do
MainInstance:SetAttribute(Name, Value)
end
end
if Children then
for _, Child in ipairs(Children) do
ReverseInstanceMap(Child, MainInstance, DeserializeMeshPartsProperly, MainMapReference, TemporaryCacheTable, PropertyCompression)
end
end
return MainInstance
end
Minstance.SerializeInstance = function(TargetInstance: Instance, SerializationSettings: {
IncludeDescendants: boolean,
CompressSerializedData: boolean,
CompressionLevel: number,
EncodeInBase94: boolean,
AnnoyingConsolePrints: boolean,
UseLegacySlowCompressor: boolean,
IncludeAttributes: boolean,
DisallowedProperties: {[string]: {[string]: any} } | nil
})
local StartBenchmarkTime
local DefaultSerializationSettings = {
IncludeDescendants = true,
CompressSerializedData = true,
CompressionLevel = 8, -- seems to be the sweet spot to balance performance and compression ratio
EncodeInBase94 = false,
AnnoyingConsolePrints = false,
UseLegacySlowCompressor = false,
IncludeAttributes = true,
DisallowedProperties = NULL
-- EXAMPLE:
-- {
-- ["Part"] = {
-- ["BrickColor"] = true
-- }
-- }
}
local Settings = SerializationSettings or {}
for Setting, DefaultValue in pairs(DefaultSerializationSettings) do
if Settings[Setting] == NULL then
Settings[Setting] = DefaultValue
end
end
if not ReflectionServiceWrapper.IsApiInitialized() then
return ThrowToConsole(`There was a problem with initalizing the API and Minstance can not serialize an Instance. Please get in contact with @WalletOverflow in Roblox and let them know about this, and please show recent console errors coming from this module.`, 2)
end
if typeof(TargetInstance) ~= "Instance" then
return ThrowToConsole(`Invalid first argument passed into SerializeInstance! Expected: Instance`, 2)
end
if not IsClassCreatable(TargetInstance.ClassName) then
return ThrowToConsole(`Instance "{TargetInstance:GetFullName()}" ({TargetInstance.ClassName}) is not creatable and can not be serialized.`, 2)
end
if Settings.AnnoyingConsolePrints then
ThrowToConsole(`You are seeing this because AnnoyingConsolePrints setting was set to true in SerializationSettings.`)
ThrowToConsole(`Target Instance: "{TargetInstance:GetFullName()}" ({TargetInstance.ClassName}) ({tostring(#TargetInstance:GetDescendants())} descendants)`)
ThrowToConsole(`Mapping Instance...`)
StartBenchmarkTime = os_clock()
end
if PropertyCompressionCount > 0 then
PropertyCompressionCount = 0
end
local MainMap = CreateInstanceMap(TargetInstance, Settings.IncludeDescendants, Settings.AnnoyingConsolePrints, TargetInstance, Settings.IncludeAttributes, Settings.DisallowedProperties)
if PropertyCompressionCount > 0 then
PropertyCompressionCount = 0
end
if Settings.AnnoyingConsolePrints then
if Settings.IncludeDescendants then
ThrowToConsole(string_format(`Finished serializing/mapping "{TargetInstance:GetFullName()}" (and {tostring(#TargetInstance:GetDescendants())} descendants) in %.4fs!`, os_clock() - StartBenchmarkTime))
else
ThrowToConsole(string_format(`Finished serializing/mapping "{TargetInstance:GetFullName()}" in %.4fs!`, os_clock() - StartBenchmarkTime))
end
end
local BinaryEncoded = BufferEncoder.write(MainMap, nil, nil, true)
if not Settings.CompressSerializedData then
if Settings.EncodeInBase94 then
return buffer_tostring(Base94.encode(BinaryEncoded))
else
return buffer_tostring(BinaryEncoded)
end
else
if Settings.AnnoyingConsolePrints then
ThrowToConsole(`Attempting to compress serialized data...`)
StartBenchmarkTime = os_clock()
end
local BinaryEncodedString = buffer_tostring(BinaryEncoded)
if Settings.UseLegacySlowCompressor then
if Settings.EncodeInBase94 then
local FinalCompressedData = OldCompress.Compress(BinaryEncodedString)
if Settings.AnnoyingConsolePrints then
ThrowToConsole(string_format(`Finished compressing & encoding serialized data in %.4fs!`, os_clock() - StartBenchmarkTime))
ThrowToConsole(`Serialized data character count before compression: {#BinaryEncodedString}`)
ThrowToConsole(`Serialized data character count after compression: {#FinalCompressedData}`)
end
return FinalCompressedData
else
local FinalCompressedData = OldCompress.CompressNoEncoding(BinaryEncodedString, Settings.CompressionLevel)
if Settings.AnnoyingConsolePrints then
ThrowToConsole(string_format(`Finished compressing serialized data in %.4fs!`, os_clock() - StartBenchmarkTime))
ThrowToConsole(`Serialized data character count before compression: {#BinaryEncodedString}`)
ThrowToConsole(`Serialized data character count after compression: {#FinalCompressedData}`)
end
return FinalCompressedData
end
else
local Compressed = NewCompress.Compress(BinaryEncodedString, Settings.CompressionLevel)
if Settings.EncodeInBase94 then
local Base94Encoded = buffer_tostring(Base94.encode(buffer_fromstring(Compressed)))
if Settings.AnnoyingConsolePrints then
ThrowToConsole(string_format(`Finished compressing & encoding serialized data in %.4fs!`, os_clock() - StartBenchmarkTime))
ThrowToConsole(`Serialized data character count before compression: {#BinaryEncodedString}`)
ThrowToConsole(`Serialized data character count after compression: {#Base94Encoded}`)
end
return Base94Encoded
else
if Settings.AnnoyingConsolePrints then
ThrowToConsole(string_format(`Finished compressing serialized data in %.4fs!`, os_clock() - StartBenchmarkTime))
ThrowToConsole(`Serialized data character count before compression: {#BinaryEncodedString}`)
ThrowToConsole(`Serialized data character count after compression: {#Compressed}`)
end
return Compressed
end
end
end
end
Minstance.DeserializeInstance = function(SerializedData: string, DeserializationSettings: {
IsDataCompressed: boolean,
IsBase94Encoded: boolean,
AnnoyingConsolePrints: boolean,
IsCompressedWithLegacyCompressor: boolean,
ProperlyDeserializeMeshParts: boolean,
ParentInstanceWhileDeserializing: Instance?
})
local StartBenchmarkTime, MainMap
local DefaultDeserializationSettings = {
IsDataCompressed = true,
IsBase94Encoded = false,
AnnoyingConsolePrints = false,
IsCompressedWithLegacyCompressor = false,
ProperlyDeserializeMeshParts = false, -- load mesh parts, if off then put mesh put but not load content
ParentInstanceWhileDeserializing = NULL
}
local Settings = DeserializationSettings or {}
for Setting, DefaultValue in pairs(DefaultDeserializationSettings) do
if Settings[Setting] == NULL then
Settings[Setting] = DefaultValue
end
end
if not ReflectionServiceWrapper.IsApiInitialized() then
return ThrowToConsole(`There was a problem with initalizing the API and Minstance can not deserialize an Instance. Please get in contact with @WalletOverflow in Roblox and let them know about this, and please show recent console errors coming from this module.`, 2)
end
if typeof(SerializedData) ~= "string" then
return ThrowToConsole(`Invalid first argument passed into DeserializeInstance! Expected: string`, 2)
end
if Settings.AnnoyingConsolePrints then
ThrowToConsole(`You are seeing this because AnnoyingConsolePrints setting was set to true in SerializationSettings.`)
ThrowToConsole(`Processing serialized data...`)
StartBenchmarkTime = os_clock()
end
if Settings.IsDataCompressed then
if Settings.IsCompressedWithLegacyCompressor then
if Settings.IsBase94Encoded then
local BinaryFormat = OldCompress.Decompress(SerializedData)
MainMap = BufferEncoder.read(buffer_fromstring(BinaryFormat), nil, nil, true)
else
local BinaryFormat = OldCompress.DecompressNoEncoding(SerializedData)
MainMap = BufferEncoder.read(buffer_fromstring(BinaryFormat), nil, nil, true)
end
else
if Settings.IsBase94Encoded then
local Base94Decoded = buffer_tostring(Base94.decode(buffer_fromstring(SerializedData)))
local BinaryFormat = NewCompress.Decompress(Base94Decoded)
MainMap = BufferEncoder.read(buffer_fromstring(BinaryFormat), nil, nil, true)
else
local BinaryFormat = NewCompress.Decompress(SerializedData)
MainMap = BufferEncoder.read(buffer_fromstring(BinaryFormat), nil, nil, true)
end
end
else
if Settings.IsBase94Encoded then
local BinaryBuffer = Base94.decode(buffer_fromstring(SerializedData))
MainMap = BufferEncoder.read(BinaryBuffer, nil, nil, true)
else
MainMap = BufferEncoder.read(buffer_fromstring(SerializedData), nil, nil, true)
end
end
if Settings.AnnoyingConsolePrints then
ThrowToConsole(string_format(`Finished processing serialized data in %.4fs!`, os_clock() - StartBenchmarkTime))
ThrowToConsole(`Attempting to demap/deserialize serialized data into Instance...`)
StartBenchmarkTime = os_clock()
end
local MapReversalCache = {}
local MainInstance = ReverseInstanceMap(MainMap, Settings.ParentInstanceWhileDeserializing, Settings.ProperlyDeserializeMeshParts, MainMap, MapReversalCache)
table_clear(MapReversalCache)
if Settings.AnnoyingConsolePrints then
ThrowToConsole(string_format(`Finished demapping/deserializing serialized data into an Instance in %.4fs!`, os_clock() - StartBenchmarkTime))
end
return MainInstance
end
-- Minstance.CreateInstanceMap = CreateInstanceMap
-- Minstance.ReverseInstanceMap = ReverseInstanceMap
return Minstance