Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.54 KB | None | 0 0
  1. getgenv().SaveInstance = function(inst,fname,skp)
  2. _G.SaveInstance(inst,fname,skp)
  3. end
  4.  
  5. local instanceCount = 0
  6. local saveString = ""
  7.  
  8. local propertiesAPI = "http://wiki.roblox.com/index.php/API:Class_reference/Dump/raw?action=raw"
  9. local props = {}
  10.  
  11. local savedProps = {}
  12.  
  13. local instanceRefs = {}
  14.  
  15. local storedInstances = {}
  16.  
  17. local skipObjects = false
  18.  
  19. function httpGet(url)
  20. return game:HttpGet(url,true)
  21. end
  22.  
  23. local propertiesList = httpGet(propertiesAPI)--require(script.studiotest)
  24.  
  25. function findClass(str, clsname, addon)
  26. local findX, findY = string.find(str, "Class "..clsname)
  27. local check = string.match(string.sub(str,findX + 5),"%w+")
  28. findY = findY + 1
  29. if check ~= clsname then
  30. return findClass(string.sub(str,findY),clsname, addon + findY)
  31. else
  32. return findY + addon
  33. end
  34. end
  35.  
  36. function getAllProperties(cName)
  37. local findPos = findClass(propertiesList,cName, 0)
  38.  
  39. local findBookmark = string.sub(propertiesList,findPos)
  40.  
  41. local bookmarkCount = 0
  42.  
  43. for line in string.gmatch(findBookmark,"%C+") do
  44. if string.sub(line,1,8) == "Property" and not string.find(line, "deprecated") and not string.find(line, "hidden") then
  45. local propFindCount = 0
  46. local propType = "Bool"
  47. local propName = ""
  48. local readOnly = false
  49.  
  50. for w in string.gmatch(line, "%w+") do
  51. propFindCount = propFindCount + 1
  52. if propFindCount == 2 then
  53. propType = w
  54. elseif propFindCount == 4 then
  55. propName = w
  56. end
  57. end
  58.  
  59. if string.find(line, "readonly") then
  60. readOnly = true
  61. end
  62.  
  63. local propPacket = {Type = propType, Name = propName, ReadOnly = readOnly}
  64. table.insert(props,propPacket)
  65. elseif string.sub(line,1,8) ~= "Property" then
  66. if bookmarkCount > 0 then
  67. break
  68. end
  69. bookmarkCount = bookmarkCount + 1
  70. end
  71. end
  72.  
  73. if cName ~= "Instance" then
  74. getAllProperties(string.match(findBookmark,"%w+"))
  75. end
  76. end
  77.  
  78. function checkFoundProps(pname)
  79. for i,v in pairs(savedProps) do
  80. if v.ClassName == pname then
  81. return v
  82. end
  83. end
  84. return false
  85. end
  86.  
  87. function getProperties(obj)
  88. local toFind = obj.ClassName
  89.  
  90. local checkProps = checkFoundProps(toFind)
  91.  
  92. if checkProps then
  93. return checkProps.Props
  94. end
  95.  
  96. props = {}
  97. getAllProperties(toFind)
  98.  
  99. local function sortProps(val1, val2)
  100. return val1.Name < val2.Name
  101. end
  102.  
  103. table.sort(props, sortProps)
  104.  
  105. table.insert(savedProps,{ClassName = toFind, Props = props})
  106.  
  107. return props
  108. end
  109.  
  110. function checkRef(obj)
  111. for i,v in pairs(instanceRefs) do
  112. if v.Instance == obj then
  113. return tostring(v.Number)
  114. end
  115. end
  116. return tostring(instanceCount)
  117. end
  118.  
  119. function setRef(obj)
  120. if obj == nil then return "null" end
  121. for i,v in pairs(instanceRefs) do
  122. if v.Instance == obj then
  123. return "RBX"..tostring(v.Number)
  124. end
  125. end
  126. instanceCount = instanceCount + 1
  127. table.insert(instanceRefs,{Instance = obj, Number = instanceCount})
  128. return "RBX"..tostring(instanceCount)
  129. end
  130.  
  131. function writeInstance(inst)
  132. for i,v in pairs(inst:GetChildren()) do
  133. instanceCount = instanceCount + 1
  134. local props = getProperties(v)
  135. if skipObjects then
  136. saveString = saveString..'\n<Item class="'..v.ClassName..'" referent="RBX'..tostring(instanceCount)..'">'
  137. else
  138. saveString = saveString..'\n<Item class="'..v.ClassName..'" referent="RBX'..checkRef(v)..'">'
  139. table.insert(instanceRefs,{Instance = v, Number = instanceCount})
  140. end
  141. saveString = saveString.."\n<Properties>"
  142. for i2,v2 in pairs(props) do
  143. ypcall(function()
  144. if v2.Name == "Archivable" or v2.Name == "DataCost" or v2.Name == "ClassName" or v2.Name == "RobloxLocked" then return end
  145. if v2.Type == "bool" then
  146. saveString = saveString..'\n<bool name="'..v2.Name..'">'..tostring(v[v2.Name])..'</bool>'
  147. elseif v2.Type == "float" then
  148. saveString = saveString..'\n<float name="'..v2.Name..'">'..tostring(v[v2.Name])..'</float>'
  149. elseif v2.Type == "int" then
  150. saveString = saveString..'\n<int name="'..v2.Name..'">'..tostring(v[v2.Name])..'</int>'
  151. elseif v2.Type == "string" then
  152. local cleanName = v[v2.Name]
  153. cleanName = string.gsub(cleanName,"<","&lt;")
  154. cleanName = string.gsub(cleanName,">","&gt;")
  155. saveString = saveString..'\n<string name="'..v2.Name..'">'..cleanName..'</string>'
  156. elseif v2.Type == "BrickColor" then
  157. saveString = saveString..'\n<int name="'..v2.Name..'">'..tostring(v[v2.Name].Number)..'</int>'
  158. elseif v2.Type == "Vector2" then
  159. saveString = saveString..'\n<Vector2 name="'..v2.Name..'">'
  160. saveString = saveString..'\n<X>'..v[v2.Name].x..'</X>'
  161. saveString = saveString..'\n<Y>'..v[v2.Name].y..'</Y>'
  162. saveString = saveString..'\n</Vector2>'
  163. elseif v2.Type == "Vector3" then
  164. saveString = saveString..'\n<Vector3 name="'..v2.Name..'">'
  165. saveString = saveString..'\n<X>'..v[v2.Name].x..'</X>'
  166. saveString = saveString..'\n<Y>'..v[v2.Name].y..'</Y>'
  167. saveString = saveString..'\n<Z>'..v[v2.Name].z..'</Z>'
  168. saveString = saveString..'\n</Vector3>'
  169. elseif v2.Type == "CoordinateFrame" then
  170. saveString = saveString..'\n<CoordinateFrame name="'..v2.Name..'">'
  171. local X,Y,Z,R00,R01,R02,R10,R11,R12,R20,R21,R22 = v[v2.Name]:components()
  172. saveString = saveString..'\n<X>'..X..'</X>'
  173. saveString = saveString..'\n<Y>'..Y..'</Y>'
  174. saveString = saveString..'\n<Z>'..Z..'</Z>'
  175. saveString = saveString..'\n<R00>'..R00..'</R00>'
  176. saveString = saveString..'\n<R01>'..R01..'</R01>'
  177. saveString = saveString..'\n<R02>'..R02..'</R02>'
  178. saveString = saveString..'\n<R10>'..R10..'</R10>'
  179. saveString = saveString..'\n<R11>'..R11..'</R11>'
  180. saveString = saveString..'\n<R12>'..R12..'</R12>'
  181. saveString = saveString..'\n<R20>'..R20..'</R20>'
  182. saveString = saveString..'\n<R21>'..R21..'</R21>'
  183. saveString = saveString..'\n<R22>'..R22..'</R22>'
  184. saveString = saveString..'\n</CoordinateFrame>'
  185. elseif v2.Type == "Content" then
  186. saveString = saveString..'\n<Content name="'..v2.Name..'"><url>'..tostring(v[v2.Name])..'</url></Content>'
  187. elseif v2.Type == "UDim2" then
  188. saveString = saveString..'\n<UDim2 name="'..v2.Name..'">'
  189. saveString = saveString..'\n<XS>'..v[v2.Name].X.Scale..'</XS>'
  190. saveString = saveString..'\n<XO>'..v[v2.Name].X.Offset..'</XO>'
  191. saveString = saveString..'\n<YS>'..v[v2.Name].Y.Scale..'</YS>'
  192. saveString = saveString..'\n<YO>'..v[v2.Name].Y.Offset..'</YO>'
  193. saveString = saveString..'\n</UDim2>'
  194. elseif v2.Type == "Color3" then
  195. saveString = saveString..'\n<Color3 name="'..v2.Name..'">'
  196. saveString = saveString..'\n<R>'..v[v2.Name].r..'</R>'
  197. saveString = saveString..'\n<G>'..v[v2.Name].g..'</G>'
  198. saveString = saveString..'\n<B>'..v[v2.Name].b..'</B>'
  199. saveString = saveString..'\n</Color3>'
  200. elseif v2.Type == "NumberRange" then
  201. saveString = saveString..'\n<NumberRange name="'..v2.Name..'">'..tostring(v[v2.Name].Min).." "..tostring(v[v2.Name].Max).." "..'</NumberRange>'
  202. elseif v2.Type == "NumberSequence" then
  203. saveString = saveString..'\n<NumberSequence name="'..v2.Name..'">'
  204. for i3,v3 in pairs(v[v2.Name].Keypoints) do
  205. saveString = saveString..tostring(v3.Time).." "..tostring(v3.Value).." "..tostring(v3.Envelope).." "
  206. end
  207. saveString = saveString..'</NumberSequence>'
  208. elseif v2.Type == "ColorSequence" then
  209. local myProp = v[v2.Name].Keypoints[1]
  210. local myProp2 = v[v2.Name].Keypoints[2]
  211. 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>'
  212. elseif v2.Type == "Object" and v2.Name ~= "Parent" then
  213. if skipObjects then
  214. saveString = saveString..'\n<Ref name="'..v2.Name..'">null</Ref>'
  215. else
  216. saveString = saveString..'\n<Ref name="'..v2.Name..'">'..setRef(v[v2.Name])..'</Ref>'
  217. end
  218. elseif v[v2.Name].Value then
  219. saveString = saveString..'\n<token name="'..v2.Name..'">'..v[v2.Name].Value..'</token>'
  220. end
  221. end)
  222. end
  223. saveString = saveString.."\n</Properties>"
  224. writeInstance(v)
  225. saveString = saveString.."\n</Item>"
  226. table.insert(storedInstances,saveString)
  227. saveString = ""
  228. end
  229. end
  230.  
  231. function _G.SaveInstance(inst,fname,skipObj)
  232. instanceCount = 0
  233. instanceRefs = {}
  234. storedInstances = {}
  235. saveString = ""
  236. if skipObj then
  237. skipObjects = true
  238. else
  239. skipObjects = false
  240. end
  241. 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">
  242. <External>null</External>
  243. <External>nil</External>]]
  244. local saveFolder = Instance.new("Folder")
  245. inst:Clone().Parent = saveFolder
  246. writeInstance(saveFolder)
  247. saveString = saveString.."\n</roblox>"
  248. table.insert(storedInstances,saveString)
  249. --print(saveString)
  250. writefile(getelysianpath()..fname,table.concat(storedInstances))
  251. end
  252.  
  253. game:GetService"UserInputService".InputBegan:connect(function(key, gameProcessed)
  254.  
  255. if key.KeyCode == Enum.KeyCode.Semicolon and (not gameProcessed) then
  256.  
  257. local copyWhat = {"Workspace","Lighting","StarterGui","StarterPack","ReplicatedStorage"}
  258.  
  259.  
  260.  
  261. local copyGroup = Instance.new("Model",game.ReplicatedStorage)
  262.  
  263. function archivable(root)
  264. for i,v in pairs(root:GetChildren()) do
  265. if not game.Players:GetPlayerFromCharacter(v) then
  266. v.Archivable = true
  267. archivable(v)
  268. end
  269. end
  270. end
  271.  
  272. function decompileS(root)
  273. for i,v in pairs(root:GetChildren()) do
  274. if v:IsA("LocalScript") then
  275. local isDisabled = v.Disabled
  276. v.Disabled = true
  277. v.Source = decompile(v)
  278. v.Disabled = isDisabled
  279. elseif v:IsA("ModuleScript") then
  280. v.Source = decompile(v)
  281. end
  282. decompileS(v)
  283. end
  284. end
  285.  
  286. for i,v in pairs(copyWhat) do
  287. archivable(game[v])
  288. end
  289.  
  290. for j,obj in pairs(copyWhat) do
  291. local newFolder = Instance.new("Folder",copyGroup)
  292. newFolder.Name = obj
  293. for i,v in pairs(game[obj]:GetChildren()) do
  294. pcall(function()
  295. v:Clone().Parent = newFolder
  296. end)
  297. end
  298. end
  299.  
  300. --decompileS(copyGroup) -- Remove the "--" when elysian adds decompiler.
  301.  
  302. saveinstance(getelysianpath()..tostring(game.PlaceId)..table.concat(copyWhat)..".rbxm",copyGroup)
  303. print("Saved!")
  304.  
  305. end
  306.  
  307. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement