Advertisement
Guest User

reru save switch

a guest
Apr 24th, 2018
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.91 KB | None | 0 0
  1. local Classes; -- Author @Rerumu <3
  2. local Props         = {};
  3. local Concat        = table.concat; -- Concatenation is going to get reworked just a couple times maybe?
  4. local tostring      = tostring;
  5. local Players       = game:GetService('Players');
  6. local Beat          = game:GetService('RunService').Heartbeat;
  7.  
  8. -- Changelog
  9. --[[
  10.     * Whatever version this is
  11.         - Re-did Elysian callback stuff because it was slow
  12.         - Added an Elysian fallback to LuaDec whenever needed
  13.         -- Delays improved
  14.         -- Changed how LocalPlayer and nil are handled
  15.         --- Fixed Synapse support
  16.         ---- Added a cache tick for Elysian
  17. ]]
  18.  
  19. local UseCache = true; -- Set to false to disable script decompile cache
  20.  
  21. local InNil;
  22. local Print;
  23. local WritesFl;
  24. local Decompile;
  25.  
  26. local SaveList  = {
  27.     game:GetService('Workspace');
  28.     game:GetService('ReplicatedFirst');
  29.     game:GetService('ReplicatedStorage');
  30.     game:GetService('ServerStorage'); -- Internal stuff
  31.     game:GetService('Lighting');
  32.     game:GetService('StarterGui');
  33.     game:GetService('StarterPack');
  34.     game:GetService('StarterPlayer');
  35.     game:GetService('Teams');
  36.     game:GetService('InsertService');
  37. };
  38.  
  39. local IgnoredList   = {
  40.     'CameraScript';
  41.     'ControlScript';
  42.     'ChatScript';
  43.     'BubbleChat';
  44.     'Camera';
  45. }
  46.  
  47. local NoNoProp  = {
  48.     Instance    = {
  49.         Archivable      = true,
  50.         DataCost        = true,
  51.         ClassName       = true,
  52.         RobloxLocked    = true,
  53.         Parent          = true
  54.     };
  55.     BasePart    = {
  56.         Position    = true,
  57.         Rotation    = true
  58.     };
  59. };
  60.  
  61. for Idx = 1, 3 do
  62.     local Ran, Err  = ypcall(function()
  63.         Classes = game:HttpGet('http://anaminus.github.io/rbx/json/api/latest.json', true);
  64. --      Classes = game:GetService('HttpService'):GetAsync('http://anaminus.github.io/rbx/json/api/latest.json');
  65.     end);
  66.  
  67.     if (not Ran) then
  68.         if (Idx == 3) then
  69.             error(Err, 0);
  70.         else
  71.             wait(1);
  72.         end;
  73.     else -- Setup stuff
  74.         local Me        = Players.LocalPlayer;
  75.  
  76.         for _, Player in next, Players:GetPlayers() do
  77.             if (Player ~= Me) then
  78.                 table.insert(IgnoredList, tostring(Player)); -- Let's *not*
  79.             end;
  80.         end;
  81.  
  82.         local NumIg = #IgnoredList;
  83.  
  84.         Classes = game:GetService('HttpService'):JSONDecode(Classes);
  85.  
  86.         for Idx = 1, NumIg do
  87.             IgnoredList[IgnoredList[Idx]]   = true;
  88.             IgnoredList[Idx]    = nil;
  89.         end;
  90.  
  91.         break;
  92.     end;
  93. end;
  94.  
  95. if elysianexecute then -- Scripts is handled async in Elysian because the decompiler is callback based
  96.     local Sources   = {};
  97.  
  98.     InNil       = getnilinstances;
  99.     WritesFl    = writefile;
  100.  
  101.     function Decompile(Script) -- Austin finna gonna make me die
  102.         local Name  = Script.Name; -- Remove if you don't want a cache
  103.         local Scr;
  104.  
  105.         if UseCache then
  106.             Scr = Sources[Name];
  107.         end;
  108.  
  109.         if (not Scr) then
  110.             local Timeout   = tick() + 8;
  111.  
  112.             local Ran, Err = decompile(Script, 'unluac', newcclosure(function(Res, Err) -- Fix or something on newcclosure
  113.                 if Res then
  114.                     Scr = Res:gsub('\r+', ''); -- Austin-proof newline machine
  115.                 else
  116.                     Scr = '--[[\n' .. tostring(Err) .. '\n--]]';
  117.                 end;
  118.             end));
  119.  
  120.             if (not Ran) then
  121.                 Scr = '--[[\n' .. tostring(Err) .. '\n--]]';
  122.             else
  123.                 Print('Decompiling ' .. Script:GetFullName());
  124.  
  125.                 Beat:wait();
  126.             end;
  127.  
  128.             while (not Scr) do
  129.                 if (tick() > Timeout) then
  130.                     Print('Script timeout ' .. Script:GetFullName());
  131.  
  132.                     Scr = '-- Unluac timed out, falling back to LuaDec\n';
  133.  
  134.                     Beat:wait();
  135.                     Beat:wait();
  136.  
  137.                     Ran, Err    = decompile(Script);
  138.  
  139.                     if Ran then
  140.                         Print('LuaDec fallback succeeded');
  141.  
  142.                         Scr = Scr .. Ran;
  143.                     else
  144.                         Scr = Scr .. '--[[\n' .. tostring(Err) .. '\n--]]';
  145.                     end;
  146.  
  147.                     break;
  148.                 else
  149.                     Beat:wait(); -- Shouldn't cause an issue
  150.                     Beat:wait();
  151.                 end;
  152.             end;
  153.  
  154.             Sources[Name]   = Scr;
  155.         end;
  156.  
  157.         return Scr;
  158.     end;
  159.  
  160.     function Print(String)
  161.         printconsole(String, 100, 200, 180);
  162.     end;
  163.  
  164.     Print('ReruSavePlace detected Elysian, functions loaded');
  165. elseif Synapse then -- Oh my god 3ds why couldn't you just use '.' syntax
  166.     function InNil()
  167.         return Synapse:GetNilInstances();
  168.     end;
  169.  
  170.     function WritesFl(Location, Data)
  171.         return Synapse:WriteFile(Location, Data);
  172.     end;
  173.  
  174.     function Decompile(Script)
  175.         return Synapse:Decompile(Script);
  176.     end;
  177.  
  178.     Print = warn;
  179.  
  180.     Print('ReruSavePlace detected Synapse, functions loaded');
  181. else
  182.     error('This exploit may not be supported by RSP, please contact me');
  183. end;
  184.  
  185. do
  186.     local Temp  = {};
  187.  
  188.     for Idx, Val in next, Classes do
  189.         if (Val.type == 'Class') then
  190.             Temp[Val.Name]  = Val;
  191.             Temp[Val.Name].Properties   = {};
  192.         elseif (Val.type == 'Property') then
  193.             local Ignore;
  194.  
  195.             for _, Tag in next, Val.tags do
  196.                 if (Tag == 'deprecated') or (Tag == 'readonly') then
  197.                     Ignore  = true;
  198.  
  199.                     break;
  200.                 end;
  201.             end;
  202.  
  203.             if (not Ignore) then
  204.                 local Ignored   = NoNoProp[Val.Class];
  205.  
  206.                 if Ignored and Ignored[Val.Name] then
  207.                     Ignore  = true;
  208.                 end;
  209.  
  210.                 if (not Ignore) then
  211.                     local Props = Temp[Val.Class].Properties;
  212.  
  213.                     Props[#Props + 1]   = Val;
  214.                 end;
  215.             end;
  216.         end;
  217.     end;
  218.  
  219.     Classes = Temp;
  220. end;
  221.  
  222. local function PropsOf(Obj)
  223.     if Props[Obj.ClassName] then
  224.         return Props[Obj.ClassName];
  225.     end;
  226.  
  227.     local Prop  = {};
  228.     local Class = Obj.ClassName;
  229.  
  230.     while Class do
  231.         local Curr  = Classes[Class];
  232.  
  233.         for Index, Value in next, Curr.Properties do
  234.             Prop[#Prop + 1] = Value;
  235.         end;
  236.  
  237.         Class = Curr.Superclass;
  238.     end;
  239.  
  240.     table.sort(Prop, function(A, B)
  241.         return A.Name < B.Name;
  242.     end);
  243.  
  244.     Props[Obj.ClassName] = Prop;
  245.  
  246.     return Prop;
  247. end;
  248.  
  249. local function SetParent(Obj, Parent)
  250.     local Cloned;
  251.  
  252.     if Obj.Archivable then
  253.         Cloned = Obj:Clone();
  254.     end;
  255.  
  256.     if (not Cloned) then
  257.         local pcall = pcall;
  258.  
  259.         Cloned = Instance.new'Folder'
  260.  
  261.         for Index, Child in next, Obj:GetChildren() do
  262.             pcall(SetParent, Child, Cloned);
  263.         end;
  264.  
  265.         Cloned.Name     = Obj.Name .. ':' .. Obj.ClassName;
  266.     end;
  267.  
  268.     Cloned.Parent   = Parent;
  269. end;
  270.  
  271. local function SavePlaceAsync()
  272.     local Count = 0;
  273.     local Final = {};
  274.     local Timer = tick();
  275.     local Saved = setmetatable({}, {__index = function(This, Idx) local C = Count + 1; Count = C; This[Idx] = C; return C; end});
  276.  
  277.     local pcall = pcall; -- Skid syndrome
  278.  
  279.     Final[1]    = '<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"><External>null</External><External>nil</External>';
  280.     Print('Saving place...');
  281.  
  282.     local function SaveInstance(Obj)
  283.         if Classes[Obj.ClassName] and (not IgnoredList[Obj.Name]) then
  284.             local Props = PropsOf(Obj);
  285.             local Num   = Saved[Obj];
  286.             local Conversions   = {
  287.                 ['&']   = '&amp;';
  288.                 ['<']   = '&lt;';
  289.                 ['>']   = '&gt;';
  290.             }
  291.  
  292.             Final[#Final + 1]   = '<Item class="' .. Obj.ClassName .. '" referent="RBX' .. Num .. '"><Properties>';
  293.  
  294.             if ((Num % 1080) == 0) then
  295.                 Beat:wait();
  296.             end;
  297.  
  298.             for _, Prop in next, Props do
  299.                 local Append;
  300.                 local Type = Prop.ValueType;
  301.                 local ObjProp = Prop.Name;
  302.                 local Objp = Obj[ObjProp];
  303.  
  304.                 if (typeof(Objp) == 'EnumItem') then
  305.                     Append  = '<token name="' .. ObjProp .. '">' .. Objp.Value .. '</token>';
  306.                 else
  307.                     if (Type == 'bool') then
  308.                         Append  = '<bool name="' .. ObjProp .. '">' .. tostring(Objp) .. '</bool>';
  309.                     elseif (Type == 'float') then
  310.                         Append = '<float name="' .. ObjProp .. '">' .. tostring(Objp) .. '</float>';
  311.                     elseif (Type == 'int') then
  312.                         Append = '<int name="' .. ObjProp .. '">' .. tostring(Objp) .. '</int>';
  313.                     elseif (Type == 'double') then
  314.                         Append = '<float name="' .. ObjProp .. '">' .. tostring(Objp) .. '</float>';
  315.                     elseif (Type == 'string') then
  316.                         local String = Objp:gsub("[&<>]", Conversions); -- Because I got C O M P L A I N T S
  317.  
  318.                         Append = '<string name="' .. ObjProp .. '">' .. String .. '</string>';
  319.                     elseif (Type == 'BrickColor') then
  320.                         Append = '<int name="' .. ObjProp .. '">' .. Objp.Number .. '</int>';
  321.                     elseif (Type == 'Vector2') then
  322.                         Append =
  323.                             '<Vector2 name="' .. ObjProp .. '">'
  324.                         .. '<X>' .. Objp.x .. '</X>'
  325.                         .. '<Y>' .. Objp.y .. '</Y>'
  326.                         .. '</Vector2>'
  327.                     elseif (Type == 'Vector3') then
  328.                         Append =
  329.                             '<Vector3 name="' .. ObjProp .. '">'
  330.                         .. '<X>' .. Objp.x .. '</X>'
  331.                         .. '<Y>' .. Objp.y .. '</Y>'
  332.                         .. '<Z>' .. Objp.z .. '</Z>'
  333.                         .. '</Vector3>'
  334.                     elseif (Type == 'CoordinateFrame') then
  335.                         local X, Y, Z, R00, R01, R02, R10, R11, R12, R20, R21, R22 = Objp:components()
  336.  
  337.                         Append =
  338.                             '<CoordinateFrame name="' .. ObjProp .. '">'
  339.                         .. '<X>' .. X .. '</X>'
  340.                         .. '<Y>' .. Y .. '</Y>'
  341.                         .. '<Z>' .. Z .. '</Z>'
  342.                         .. '<R00>' .. R00 .. '</R00>'
  343.                         .. '<R01>' .. R01 .. '</R01>'
  344.                         .. '<R02>' .. R02 .. '</R02>'
  345.                         .. '<R10>' .. R10 .. '</R10>'
  346.                         .. '<R11>' .. R11 .. '</R11>'
  347.                         .. '<R12>' .. R12 .. '</R12>'
  348.                         .. '<R20>' .. R20 .. '</R20>'
  349.                         .. '<R21>' .. R21 .. '</R21>'
  350.                         .. '<R22>' .. R22 .. '</R22>'
  351.                         .. '</CoordinateFrame>'
  352.                     elseif (Type == 'Content') then
  353.                         local String = Objp:gsub("[&<>]", Conversions);
  354.  
  355.                         Append = '<Content name="' .. ObjProp .. '"><url>' .. String .. '</url></Content>';
  356.                     elseif (Type == 'UDim2') then
  357.                         local Objp  = Objp;
  358.  
  359.                         Append =
  360.                             '<UDim2 name="' .. ObjProp .. '">'
  361.                         .. '<XS>' .. Objp.X.Scale .. '</XS>'
  362.                         .. '<XO>' .. Objp.X.Offset .. '</XO>'
  363.                         .. '<YS>' .. Objp.Y.Scale .. '</YS>'
  364.                         .. '<YO>' .. Objp.Y.Offset .. '</YO>'
  365.                         .. '</UDim2>'
  366.                     elseif (Type == 'Color3') then
  367.                         Append =
  368.                             '<Color3 name="' .. ObjProp .. '">'
  369.                         .. '<R>' .. Objp.r .. '</R>'
  370.                         .. '<G>' .. Objp.g .. '</G>'
  371.                         .. '<B>' .. Objp.b .. '</B>'
  372.                         .. '</Color3>'
  373.                     elseif (Type == 'NumberRange') then
  374.                         Append =
  375.                             '<NumberRange name="' .. ObjProp .. '">'
  376.                         .. tostring(Objp.Min)
  377.                         .. ' '
  378.                         .. tostring(Objp.Max)
  379.                         .. '</NumberRange>'
  380.                     elseif (Type == 'NumberSequence') then
  381.                         local Ob    = {};
  382.  
  383.                         Ob[1]   = '<NumberSequence name="' .. ObjProp .. '">'
  384.  
  385.                         for i, v in next, Objp.Keypoints do
  386.                             Ob[#Ob + 1] = tostring(v.Time) .. ' ' .. tostring(v.Value) .. ' ' .. tostring(v.Envelope) .. ' ';
  387.                         end
  388.  
  389.                         Ob[#Ob + 1] = '</NumberSequence>';
  390.  
  391.                         Append = Concat(Ob);
  392.                     elseif (Type == 'ColorSequence') then
  393.                         local Ob    = {};
  394.  
  395.                         Ob[1]   = '<ColorSequence name="' .. ObjProp .. '">'
  396.  
  397.                         for i, v in next, Objp.Keypoints do
  398.                             Ob[#Ob + 1] = Concat{tostring(v.Time) .. ' ' .. tostring(v.Value.r) .. ' ' .. tostring(v.Value.g) .. ' ' .. tostring(v.Value.b), " 0 "};
  399.                         end
  400.  
  401.                         Ob[#Ob + 1] = '</ColorSequence>';
  402.  
  403.                         Append = Concat(Ob);
  404.                     elseif (Type == 'Rect2D') then
  405.                         Append =
  406.                             '<Rect2D name="' .. ObjProp .. '">'
  407.                         .. '<min>'
  408.                         .. '<X>' .. tostring(Objp.Min.X) .. '</X>'
  409.                         .. '<Y>' .. tostring(Objp.Min.Y) .. '</Y>'
  410.                         .. '</min>'
  411.                         .. '<max>'
  412.                         .. '<X>' .. tostring(Objp.Max.X) .. '</X>'
  413.                         .. '<Y>' .. tostring(Objp.Max.Y) .. '</Y>'
  414.                         .. '</max>'
  415.                         .. '</Rect2D>'
  416.                     elseif (Type == 'ProtectedString') then
  417.                         local Src;
  418.  
  419.                         if (ObjProp == 'Source') then
  420.                             if (Obj.ClassName ~= 'Script') then
  421.                                 local Sc, Er    = Decompile(Obj);
  422.  
  423.                                 if (not Sc) then
  424.                                     Src = '--[[\n\t' .. Er .. '\n--]]';
  425.                                 else
  426.                                     Src = Sc;
  427.                                 end;
  428.                             else
  429.                                 Src = '-- Server script not decompiled :(';
  430.                             end;
  431.                         else
  432.                             Src = '';
  433.                         end;
  434.  
  435.                         Append = '<ProtectedString name="' .. ObjProp .. '"><![CDATA[' .. Src .. ']]></ProtectedString>';
  436.                     elseif (Type == 'Object') then
  437.                         if (not Objp) then
  438.                             Objp    = 'null';
  439.                         else
  440.                             Objp    = 'RBX' .. Saved[Objp];
  441.                         end;
  442.  
  443.                         Append = '<Ref name="' .. ObjProp .. '">' .. Objp .. '</Ref>';
  444.                     elseif (Type == 'PhysicalProperties') then
  445.                         if Objp then
  446.                             Append =
  447.                                 '<PhysicalProperties name="' .. ObjProp .. '"><CustomPhysics>true</CustomPhysics>'
  448.                             .. '<Density>' .. tostring(Objp.Density) .. '</Density>'
  449.                             .. '<Friction>' .. tostring(Objp.Friction) .. '</Friction>'
  450.                             .. '<Elasticity>' .. tostring(Objp.Elasticity) .. '</Elasticity>'
  451.                             .. '<FrictionWeight>' .. tostring(Objp.FrictionWeight) .. '</FrictionWeight>'
  452.                             .. '<ElasticityWeight>' .. tostring(Objp.ElasticityWeight) .. '</ElasticityWeight>'
  453.                             .. '</PhysicalProperties>'
  454.                         else
  455.                             Append = '<PhysicalProperties name="' .. ObjProp .. '"><CustomPhysics>false</CustomPhysics></PhysicalProperties>';
  456.                         end;
  457.                     end;
  458.                 end;
  459.  
  460.                 if Append then
  461.                     Final[#Final + 1]   = Append;
  462.                 end;
  463.             end
  464.  
  465.             Final[#Final + 1]   = '</Properties>';
  466.  
  467.             for _, Obj in next, Obj:GetChildren() do
  468.                 SaveInstance(Obj);
  469.             end;
  470.  
  471.             Final[#Final + 1]   = '</Item>';
  472.         end;
  473.     end;
  474.  
  475.     do
  476.         local Other = Instance.new'Folder';
  477.  
  478.         local Real  = Players.LocalPlayer;
  479.         local Play  = Instance.new'Folder';
  480.  
  481.         Other.Name          = 'Other';
  482.         Other.RobloxLocked  = true;
  483.         Other.Parent        = game;
  484.  
  485.         Play.Parent         = Other;
  486.         Play.Name           = 'LocalPlayer';
  487.  
  488.         for _, Des in next, Real:GetChildren() do
  489.             pcall(SetParent, Des, Play);
  490.         end;
  491.  
  492.         if InNil then
  493.             local Extr  = Instance.new'Folder';
  494.  
  495.             Extr.Parent         = Other;
  496.             Extr.Name           = 'Nil_Instances';
  497.  
  498.             for _, Nil in next, InNil() do
  499.                 pcall(SetParent, Nil, Extr);
  500.             end;
  501.         end;
  502.  
  503.         SaveList[#SaveList + 1] = Other;
  504.     end;
  505.  
  506.     for _, Child in next, SaveList do
  507.         SaveInstance(Child);
  508.     end;
  509.  
  510.     Final[#Final + 1]   = '</roblox>';
  511.  
  512.     local Place = game:GetService('MarketplaceService'):GetProductInfo(game.PlaceId);
  513.  
  514.     if Place.Name then
  515.         local Illegal   = {'/', '\\', ':', '?', '"', '\'', '<', '>', '|'};
  516.  
  517.         for Idx = 1, #Illegal do
  518.             Illegal[Illegal[Idx]]   = '';
  519.  
  520.             Illegal[Idx]    = nil;
  521.         end;
  522.  
  523.         Place   = string.gsub(Place.Name, '.', Illegal);
  524.     else
  525.         Place   = 'Unknown';
  526.     end;
  527.  
  528.     Final = Concat(Final);
  529.  
  530.     Print(string.format('Done serializing, saving (%d bytes)', #Final));
  531.  
  532.     WritesFl(tostring(game.PlaceId) .. '.rbxl', Final);
  533.  
  534.     Print(string.format('Saving took %d second(s), please check your workspace folder', tick() - Timer));
  535. end;
  536.  
  537. SavePlaceAsync();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement