forked from marbeast823/Celery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaveinstance.lua
370 lines (344 loc) · 16.9 KB
/
saveinstance.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
return function(first)
assert(first, "Cannot save instance (instance is nil)");
local reflection;
--[[
This takes a recently updated and formatted api dump
of a majority of ROBLOX classes and parses it
into a large table, which we can use for reference
for instance properties/functions/etc.
]]
local function loadreflection()
--[[ Thanks MaximumADHD! ]]
local raw = httpget("https://raw.githubusercontent.com/MaximumADHD/Roblox-Client-Tracker/roblox/API-Dump.txt");
local rbxapi = {};
local t;
local at = 1;
local function nextkeyword()
local keyword = "";
while (raw:sub(at, at) ~= ' ' and raw:sub(at, at) ~= '\n') do
keyword = keyword .. raw:sub(at, at);
at = at + 1;
end
return keyword;
end
while at < string.len(raw) do
if (raw:sub(at, at + 5) == "Class ") then
at = at + 6;
local name = nextkeyword();
t = {};
t.Name = name;
t.Type = "Class";
t.BaseClass = name;
at = at + 1;
if (raw:sub(at, at) == ':') then
at = at + 2;
local inheritedclass = "";
while (raw:sub(at, at) ~= ' ' and raw:sub(at, at) ~= '\n' and raw:sub(at, at) ~= '\r') do
inheritedclass = inheritedclass .. raw:sub(at, at);
at = at + 1;
end
t.BaseClass = inheritedclass;
local x = t;
while x.BaseClass ~= x.Name and rbxapi[x.BaseClass] do
for k,v in pairs(rbxapi[x.BaseClass]) do
if (v.Type == "Property") then
--[[ warn("Adding " .. v.Name .. " to rbxapi['" .. name .. "']") ]]
t[k] = v;
end
end
x = rbxapi[x.BaseClass];
end
end
rbxapi[name] = t;
--[[ print("rbxapi['" .. name .. "'] = ", rbxapi[name]); ]]
elseif (raw:sub(at, at + 5) == "\nEnum ") then
at = at + 6;
local name = "";
while (raw:sub(at, at) ~= ' ' and raw:sub(at, at) ~= '\n' and raw:sub(at, at) ~= '\r') do
name = name .. raw:sub(at, at);
at = at + 1;
end
t = {};
t.Name = name;
t.Type = "EnumItem";
t.RawType = "EnumItem";
rbxapi[name] = t;
end
if (t and raw:sub(at, at + 9) == "\tEnumItem ") then
if type(t.Name) == "string" then
at = at + 10;
at = at + string.len(t.Name);
local enumname = nextkeyword();
local e = {};
e.Name = enumname;
e.Type = "EnumItem";
e.RawType = "EnumItem";
t[enumname] = e;
end
end
if (t and raw:sub(at, at + 9) == "\tProperty ") then
if type(t.Name) == "string" then
at = at + 10;
local propertytype = nextkeyword();
--[[
-- V-------->V
-- \Property bool Instance.RobloxLocked [PluginSecurity]
-- skip the current name to get to the property name
]]
at = at + string.len(t.Name) + 2;
local propertyname = nextkeyword();
local p = {};
p.Type = "Property";
p.Name = propertyname;
p.RawType = propertytype;
t[propertyname] = p;
end
end
at = at + 1;
end
return rbxapi;
end
local function getreflection()
if reflection ~= nil then return reflection end
reflection = loadreflection();
return reflection;
end
local function getproperties(object)
if typeof(object) ~= "Instance" then error'Instance expected' end
local rbxapi = getreflection();
return rbxapi[object.ClassName];
end
local depthSpace = 4;
local rbxapi = getreflection();
local header = '<roblox xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.roblox.com/roblox.xsd" version="4">\n';
header = header .. string.rep(' ', depthSpace) .. "<External>null</External>\n";
header = header .. string.rep(' ', depthSpace) .. "<External>nil</External>\n";
local cacheduids = {};
local function generatesuid(instance)
for i = 1, #cacheduids do
if cacheduids[i].Instance == instance then
return cacheduids[i].SUID;
end
end
local suid = "RBX";
for i = 1,32 do
suid = suid .. string.char(0x30 + math.random(0,9));
end
table.insert(cacheduids, {["Instance"] = instance, ["SUID"] = suid});
return suid;
end
local function serialize(object, depth)
if (object.ClassName == "DataModel") then
local xml = "";
local scan = { "Workspace", "Lighting", "Players", "ReplicatedFirst", "ReplicatedStorage", "StarterGui", "StarterPack", "StarterPlayer" };
for i = 1,#scan do
local service = game:GetService(scan[i]);
if service then
--[[print("Indexing DataModel --> '" .. service.Name .. "'...");]]
pcall(function()
xml = xml .. serialize(service, depth)
end);
--[[else
warn("DataModel --> '" .. service.Name .. "' not found!");]]
end
end
return xml;
end
if (object.Parent) then
if (object.Parent.ClassName == "DataModel") then
local folder = Instance.new("Folder");
folder.Name = object.Name;
for _,v in pairs(object:GetChildren()) do
pcall(function()
v.Archivable = true;
v:Clone().Parent = folder;
end);
end
object = folder;
end
end
local properties = rbxapi[object.ClassName];
local xml = string.rep(' ', depth * depthSpace);
local suid = generatesuid(object);
xml = xml .. "<Item class=\"" .. object.ClassName .. "\" referent=\"" .. suid .. "\">\n";
depth = depth + 1;
xml = xml .. string.rep(' ', depth * depthSpace);
xml = xml .. "<Properties>\n";
depth = depth + 1;
xml = xml .. string.rep(' ', depth * depthSpace);
xml = xml .. "<BinaryString name=\"AttributesSerialize\"></BinaryString>\n";
xml = xml .. string.rep(' ', depth * depthSpace);
for k,v in pairs(properties) do
local prop = nil;
local proptype = properties[k].RawType;
local propname = k;
local ignore = false
local ignoreList = { "EvaluationThrottled", "TileSize" }
for i = 1,#ignoreList do
if propname == ignoreList[i] then
ignore = true
break
end
end
if ignore then continue end
pcall(function()
prop = object[propname];
end);
if not prop then
--[[ splice the '\r' character, if present ]]
pcall(function()
propname = propname:sub(1, string.len(propname) - 1);
prop = object[propname];
end);
end
if prop and proptype then
--[[ Adjust some labels from the api dump to RBX format ]]
--[[ TO-DO: Move this to the parser ]]
if (proptype:sub(1, 5) == "Enum.") then --[[ enum? let's use the "token" type ]]
proptype = "token";
elseif (proptype == "CFrame") then --[[ cframe? let's use CoordinateFrame ]]
proptype = "CoordinateFrame";
elseif (proptype == "Object" or proptype == "Instance") then
proptype = "Ref";
elseif (proptype == "Color") then
proptype = "Color3";
elseif (proptype == "BrickColor") then
--[[ It should look like: ]]
--[[ <Color3uint8 name="Color3uint8">4280374457</Color3uint8> ]]
proptype = "Color3uint8";
propname = proptype;
end
local temp = "";
xpcall(function()
temp = temp .. "<" .. proptype .. " name=\"" .. propname .. "\">";
if (proptype == "Vector2") then
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<X>" ..tostring(prop.X).. "</X>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Y>" ..tostring(prop.Y).. "</Y>";
temp = temp .. "\n" .. string.rep(' ', depth * depthSpace);
elseif (proptype == "Vector3") then
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<X>" ..tostring(prop.X).. "</X>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Y>" ..tostring(prop.Y).. "</Y>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Z>" ..tostring(prop.Z).. "</Z>";
temp = temp .. "\n" .. string.rep(' ', depth * depthSpace);
elseif (proptype == "Color3") then
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R>" ..tostring(prop.R).. "</R>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<G>" ..tostring(prop.G).. "</G>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<B>" ..tostring(prop.B).. "</B>";
temp = temp .. "\n" .. string.rep(' ', depth * depthSpace);
elseif (proptype == "CoordinateFrame") then
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<X>" ..tostring(prop.X).. "</X>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Y>" ..tostring(prop.Y).. "</Y>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Z>" ..tostring(prop.Z).. "</Z>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R00>" .. tostring(prop.RightVector.x) .. "</R00>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R01>" .. tostring(prop.RightVector.y) .. "</R01>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R02>" .. tostring(prop.RightVector.z) .. "</R02>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R10>" .. tostring(prop.UpVector.x) .. "</R10>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R11>" .. tostring(prop.UpVector.y) .. "</R11>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R12>" .. tostring(prop.UpVector.z) .. "</R12>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R20>" .. tostring(prop.LookVector.x) .. "</R20>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R21>" .. tostring(prop.LookVector.y) .. "</R21>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<R22>" .. tostring(prop.LookVector.z) .. "</R22>";
temp = temp .. "\n" .. string.rep(' ', depth * depthSpace);
elseif (proptype == "Faces") then
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Bottom>" .. tostring(prop.Bottom) .. "</Bottom>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Top>" .. tostring(prop.Top) .. "</Top>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Left>" .. tostring(prop.Left) .. "</Left>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Right>" .. tostring(prop.Right) .. "</Right>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Back>" .. tostring(prop.Back) .. "</Back>";
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Front>" .. tostring(prop.Front) .. "</Front>";
temp = temp .. "\n" .. string.rep(' ', depth * depthSpace);
elseif (proptype == "UDim2") then
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<XS>" .. tostring(prop.X.Scale) .. "</XS>"
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<XO>" .. tostring(prop.X.Offset) .. "</XO>"
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<YS>" .. tostring(prop.Y.Scale) .. "</YS>"
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<YO>" .. tostring(prop.Y.Offset) .. "</YO>"
temp = temp .. "\n" .. string.rep(' ', depth * depthSpace);
elseif (proptype == "FontFace") then
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Family><url>" .. tostring(prop.Family) .. "</url></Family>"
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Weight>" .. tostring(prop.Weight.Value) .. "</Weight>"
temp = temp .. "\n" .. string.rep(' ', (depth + 1) * depthSpace);
temp = temp .. "<Style>" .. tostring(prop.Style.Name) .. "</Style>"
temp = temp .. "\n" .. string.rep(' ', depth * depthSpace);
--[[ temp = temp .. "<CachedFaceId><url></url></CachedFaceId>" ]]
elseif (proptype == "Color3uint8") then
local rgbavalue = bit32.bor(bit32.bor(bit32.bor(bit32.lshift(0xFF, 24), bit32.lshift(0xFF * prop.r, 16)), bit32.lshift(0xFF * prop.g, 8)), 0xFF * prop.b);
temp = temp .. tostring(rgbavalue);
elseif (proptype == "BrickColor") then
temp = temp .. tostring(prop.Number)
elseif (proptype == "Content") then
temp = temp .. "<url>" ..tostring(prop).. "</url>";
elseif (proptype == "Ref") then
if prop == object then
temp = temp .. suid;
else
local refsuid = generatesuid(prop);
if refsuid ~= nil then
temp = temp .. refsuid;
end
end
elseif (proptype == "token") then
temp = temp .. tostring(prop.Value); --[[ Use the enum number value]]
else --[[ string, int, float, etc. use tostring ]]
temp = temp .. tostring(prop);
end
temp = temp .. "</" .. proptype .. ">\n";
temp = temp .. string.rep(' ', depth * depthSpace);
end, function(err)
temp = ""
end)
if string.len(temp) > 0 then
xml = xml .. temp
end
end
end
xml = xml .. "<BinaryString name=\"Tags\"></BinaryString>\n";
depth = depth - 1;
xml = xml .. string.rep(' ', depth * depthSpace);
xml = xml .. "</Properties>\n";
--[[ serialize the instance's children ]]
for _,v in ipairs(object:GetChildren()) do
pcall(function()
xml = xml .. serialize(v, depth)
end);
end
depth = depth - 1;
xml = xml .. string.rep(' ', depth * depthSpace);
xml = xml .. "</Item>\n";
return xml;
end
local xml = serialize(first, 1);
xml = header .. xml .. '</roblox>';
return xml;
end