Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- getgenv().SaveInstance = function(inst,fname,skp)
- _G.SaveInstance(inst,fname,skp)
- end
- local instanceCount = 0
- local saveString = ""
- local propertiesAPI = "http://wiki.roblox.com/index.php/API:Class_reference/Dump/raw?action=raw"
- local props = {}
- local savedProps = {}
- local instanceRefs = {}
- local storedInstances = {}
- local skipObjects = false
- function httpGet(url)
- return game:HttpGet(url,true)
- end
- local propertiesList = httpGet(propertiesAPI)--require(script.studiotest)
- function findClass(str, clsname, addon)
- local findX, findY = string.find(str, "Class "..clsname)
- local check = string.match(string.sub(str,findX + 5),"%w+")
- findY = findY + 1
- if check ~= clsname then
- return findClass(string.sub(str,findY),clsname, addon + findY)
- else
- return findY + addon
- end
- end
- function getAllProperties(cName)
- local findPos = findClass(propertiesList,cName, 0)
- local findBookmark = string.sub(propertiesList,findPos)
- local bookmarkCount = 0
- for line in string.gmatch(findBookmark,"%C+") do
- if string.sub(line,1,8) == "Property" and not string.find(line, "deprecated") and not string.find(line, "hidden") then
- local propFindCount = 0
- local propType = "Bool"
- local propName = ""
- local readOnly = false
- for w in string.gmatch(line, "%w+") do
- propFindCount = propFindCount + 1
- if propFindCount == 2 then
- propType = w
- elseif propFindCount == 4 then
- propName = w
- end
- end
- if string.find(line, "readonly") then
- readOnly = true
- end
- local propPacket = {Type = propType, Name = propName, ReadOnly = readOnly}
- table.insert(props,propPacket)
- elseif string.sub(line,1,8) ~= "Property" then
- if bookmarkCount > 0 then
- break
- end
- bookmarkCount = bookmarkCount + 1
- end
- end
- if cName ~= "Instance" then
- getAllProperties(string.match(findBookmark,"%w+"))
- end
- end
- function checkFoundProps(pname)
- for i,v in pairs(savedProps) do
- if v.ClassName == pname then
- return v
- end
- end
- return false
- end
- function getProperties(obj)
- local toFind = obj.ClassName
- local checkProps = checkFoundProps(toFind)
- if checkProps then
- return checkProps.Props
- end
- props = {}
- getAllProperties(toFind)
- local function sortProps(val1, val2)
- return val1.Name < val2.Name
- end
- table.sort(props, sortProps)
- table.insert(savedProps,{ClassName = toFind, Props = props})
- return props
- end
- function checkRef(obj)
- for i,v in pairs(instanceRefs) do
- if v.Instance == obj then
- return tostring(v.Number)
- end
- end
- return tostring(instanceCount)
- end
- function setRef(obj)
- if obj == nil then return "null" end
- for i,v in pairs(instanceRefs) do
- if v.Instance == obj then
- return "RBX"..tostring(v.Number)
- end
- end
- instanceCount = instanceCount + 1
- table.insert(instanceRefs,{Instance = obj, Number = instanceCount})
- return "RBX"..tostring(instanceCount)
- end
- function writeInstance(inst)
- for i,v in pairs(inst:GetChildren()) do
- instanceCount = instanceCount + 1
- local props = getProperties(v)
- if skipObjects then
- saveString = saveString..'\n<Item class="'..v.ClassName..'" referent="RBX'..tostring(instanceCount)..'">'
- else
- saveString = saveString..'\n<Item class="'..v.ClassName..'" referent="RBX'..checkRef(v)..'">'
- table.insert(instanceRefs,{Instance = v, Number = instanceCount})
- end
- saveString = saveString.."\n<Properties>"
- for i2,v2 in pairs(props) do
- ypcall(function()
- if v2.Name == "Archivable" or v2.Name == "DataCost" or v2.Name == "ClassName" or v2.Name == "RobloxLocked" then return end
- if v2.Type == "bool" then
- saveString = saveString..'\n<bool name="'..v2.Name..'">'..tostring(v[v2.Name])..'</bool>'
- elseif v2.Type == "float" then
- saveString = saveString..'\n<float name="'..v2.Name..'">'..tostring(v[v2.Name])..'</float>'
- elseif v2.Type == "int" then
- saveString = saveString..'\n<int name="'..v2.Name..'">'..tostring(v[v2.Name])..'</int>'
- elseif v2.Type == "string" then
- local cleanName = v[v2.Name]
- cleanName = string.gsub(cleanName,"<","<")
- cleanName = string.gsub(cleanName,">",">")
- saveString = saveString..'\n<string name="'..v2.Name..'">'..cleanName..'</string>'
- elseif v2.Type == "BrickColor" then
- saveString = saveString..'\n<int name="'..v2.Name..'">'..tostring(v[v2.Name].Number)..'</int>'
- elseif v2.Type == "Vector2" then
- saveString = saveString..'\n<Vector2 name="'..v2.Name..'">'
- saveString = saveString..'\n<X>'..v[v2.Name].x..'</X>'
- saveString = saveString..'\n<Y>'..v[v2.Name].y..'</Y>'
- saveString = saveString..'\n</Vector2>'
- elseif v2.Type == "Vector3" then
- saveString = saveString..'\n<Vector3 name="'..v2.Name..'">'
- saveString = saveString..'\n<X>'..v[v2.Name].x..'</X>'
- saveString = saveString..'\n<Y>'..v[v2.Name].y..'</Y>'
- saveString = saveString..'\n<Z>'..v[v2.Name].z..'</Z>'
- saveString = saveString..'\n</Vector3>'
- elseif v2.Type == "CoordinateFrame" then
- saveString = saveString..'\n<CoordinateFrame name="'..v2.Name..'">'
- local X,Y,Z,R00,R01,R02,R10,R11,R12,R20,R21,R22 = v[v2.Name]:components()
- saveString = saveString..'\n<X>'..X..'</X>'
- saveString = saveString..'\n<Y>'..Y..'</Y>'
- saveString = saveString..'\n<Z>'..Z..'</Z>'
- saveString = saveString..'\n<R00>'..R00..'</R00>'
- saveString = saveString..'\n<R01>'..R01..'</R01>'
- saveString = saveString..'\n<R02>'..R02..'</R02>'
- saveString = saveString..'\n<R10>'..R10..'</R10>'
- saveString = saveString..'\n<R11>'..R11..'</R11>'
- saveString = saveString..'\n<R12>'..R12..'</R12>'
- saveString = saveString..'\n<R20>'..R20..'</R20>'
- saveString = saveString..'\n<R21>'..R21..'</R21>'
- saveString = saveString..'\n<R22>'..R22..'</R22>'
- saveString = saveString..'\n</CoordinateFrame>'
- elseif v2.Type == "Content" then
- saveString = saveString..'\n<Content name="'..v2.Name..'"><url>'..tostring(v[v2.Name])..'</url></Content>'
- elseif v2.Type == "UDim2" then
- saveString = saveString..'\n<UDim2 name="'..v2.Name..'">'
- saveString = saveString..'\n<XS>'..v[v2.Name].X.Scale..'</XS>'
- saveString = saveString..'\n<XO>'..v[v2.Name].X.Offset..'</XO>'
- saveString = saveString..'\n<YS>'..v[v2.Name].Y.Scale..'</YS>'
- saveString = saveString..'\n<YO>'..v[v2.Name].Y.Offset..'</YO>'
- saveString = saveString..'\n</UDim2>'
- elseif v2.Type == "Color3" then
- saveString = saveString..'\n<Color3 name="'..v2.Name..'">'
- saveString = saveString..'\n<R>'..v[v2.Name].r..'</R>'
- saveString = saveString..'\n<G>'..v[v2.Name].g..'</G>'
- saveString = saveString..'\n<B>'..v[v2.Name].b..'</B>'
- saveString = saveString..'\n</Color3>'
- elseif v2.Type == "NumberRange" then
- saveString = saveString..'\n<NumberRange name="'..v2.Name..'">'..tostring(v[v2.Name].Min).." "..tostring(v[v2.Name].Max).." "..'</NumberRange>'
- elseif v2.Type == "NumberSequence" then
- saveString = saveString..'\n<NumberSequence name="'..v2.Name..'">'
- for i3,v3 in pairs(v[v2.Name].Keypoints) do
- saveString = saveString..tostring(v3.Time).." "..tostring(v3.Value).." "..tostring(v3.Envelope).." "
- end
- saveString = saveString..'</NumberSequence>'
- elseif v2.Type == "ColorSequence" then
- local myProp = v[v2.Name].Keypoints[1]
- local myProp2 = v[v2.Name].Keypoints[2]
- saveString = saveString..'\n<ColorSequence name="'..v2.Name..'">'..tostring(myProp.Time).." "..tostring(myProp.Value.r).." "..tostring(myProp.Value.g).." "..tostring(myProp.Value.b).." 0 "..tostring(myProp2.Time).." "..tostring(myProp2.Value.r).." "..tostring(myProp2.Value.g).." "..tostring(myProp2.Value.b).." 0 "..'</ColorSequence>'
- elseif v2.Type == "Object" and v2.Name ~= "Parent" then
- if skipObjects then
- saveString = saveString..'\n<Ref name="'..v2.Name..'">null</Ref>'
- else
- saveString = saveString..'\n<Ref name="'..v2.Name..'">'..setRef(v[v2.Name])..'</Ref>'
- end
- elseif v[v2.Name].Value then
- saveString = saveString..'\n<token name="'..v2.Name..'">'..v[v2.Name].Value..'</token>'
- end
- end)
- end
- saveString = saveString.."\n</Properties>"
- writeInstance(v)
- saveString = saveString.."\n</Item>"
- table.insert(storedInstances,saveString)
- saveString = ""
- end
- end
- function _G.SaveInstance(inst,fname,skipObj)
- instanceCount = 0
- instanceRefs = {}
- storedInstances = {}
- saveString = ""
- if skipObj then
- skipObjects = true
- else
- skipObjects = false
- end
- saveString = [[<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>]]
- local saveFolder = Instance.new("Folder")
- inst:Clone().Parent = saveFolder
- writeInstance(saveFolder)
- saveString = saveString.."\n</roblox>"
- table.insert(storedInstances,saveString)
- --print(saveString)
- writefile(getelysianpath()..fname,table.concat(storedInstances))
- end
- game:GetService"UserInputService".InputBegan:connect(function(key, gameProcessed)
- if key.KeyCode == Enum.KeyCode.Semicolon and (not gameProcessed) then
- local copyWhat = {"Workspace","Lighting","StarterGui","StarterPack","ReplicatedStorage"}
- local copyGroup = Instance.new("Model",game.ReplicatedStorage)
- function archivable(root)
- for i,v in pairs(root:GetChildren()) do
- if not game.Players:GetPlayerFromCharacter(v) then
- v.Archivable = true
- archivable(v)
- end
- end
- end
- function decompileS(root)
- for i,v in pairs(root:GetChildren()) do
- if v:IsA("LocalScript") then
- local isDisabled = v.Disabled
- v.Disabled = true
- v.Source = decompile(v)
- v.Disabled = isDisabled
- elseif v:IsA("ModuleScript") then
- v.Source = decompile(v)
- end
- decompileS(v)
- end
- end
- for i,v in pairs(copyWhat) do
- archivable(game[v])
- end
- for j,obj in pairs(copyWhat) do
- local newFolder = Instance.new("Folder",copyGroup)
- newFolder.Name = obj
- for i,v in pairs(game[obj]:GetChildren()) do
- pcall(function()
- v:Clone().Parent = newFolder
- end)
- end
- end
- --decompileS(copyGroup) -- Remove the "--" when elysian adds decompiler.
- saveinstance(getelysianpath()..tostring(game.PlaceId)..table.concat(copyWhat)..".rbxm",copyGroup)
- print("Saved!")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement