kaualima12

Btools

Apr 30th, 2019
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 62.73 KB | None | 0 0
  1. <External>null</External>
  2. <External>nil</External>
  3. <Item class="Script" referent="RBXC31DDC25848247ADBFDBECCDD7CCE851">
  4. <Properties>
  5. <bool name="Disabled">false</bool>
  6. <Content name="LinkedSource"><null></null></Content>
  7. <string name="kaioo12345k">Import from Building Tools by F3X</string>
  8. <string name="ScriptGuid">{CE3F9297-3A87-4589-BC1C-50DBC6CB8472}</string>
  9. <ProtectedString name="Source"><![CDATA[------------------------------------------
  10. -- Make references to important items
  11. ------------------------------------------
  12. Services = {
  13. HttpService = Game:GetService( 'HttpService' );
  14. Workspace = Game:GetService( 'Workspace' );
  15. ContentProvider = Game:GetService( 'ContentProvider' );
  16. CoreGui = Game:GetService( 'CoreGui' );
  17. Selection = Game:GetService( 'Selection' );
  18. Players = Game:GetService 'Players';
  19. };
  20.  
  21. bt_logo = 'http://www.roblox.com/asset/?id=129747824';
  22. plugin_icon = 'http://www.roblox.com/asset/?id=144549739';
  23. export_base_url = 'http://www.f3xteam.com/bt/export/%s';
  24.  
  25. -- Create the plugin
  26. Plugin = plugin;
  27. Toolbar = Plugin:CreateToolbar( 'Building Tools by F3X' );
  28. Launcher = Toolbar:CreateButton( '', 'Import from Building Tools by F3X', plugin_icon );
  29. local GUI;
  30.  
  31. ------------------------------------------
  32. -- Load external dependencies
  33. ------------------------------------------
  34. RbxUtility = LoadLibrary( 'RbxUtility' );
  35. Services.ContentProvider:Preload( bt_logo );
  36. SerializationV2 = require(script.SerializationModule2);
  37. SerializationV3 = require(script.SerializationModule3);
  38.  
  39. ------------------------------------------
  40. -- Define functions that are depended-upon
  41. ------------------------------------------
  42. function _findTableOccurrences( haystack, needle )
  43. -- Returns the positions of instances of `needle` in table `haystack`
  44. local positions = {};
  45.  
  46. -- Add any indexes from `haystack` that have `needle`
  47. for index, value in pairs( haystack ) do
  48. if value == needle then
  49. table.insert( positions, index );
  50. end;
  51. end;
  52.  
  53. return positions;
  54. end;
  55.  
  56. ------------------------------------------
  57. -- Provide actual functionality
  58. ------------------------------------------
  59. function showGUI( message, ok_text )
  60.  
  61. -- Make sure the UI isn't already open
  62. if GUI then
  63. hideGUI();
  64. end;
  65.  
  66. local Create = RbxUtility.Create;
  67.  
  68. GUI = Create 'ScreenGui' {
  69. Name = 'BTImportUI';
  70. Parent = Services.CoreGui;
  71. };
  72.  
  73. local Container = Create 'Frame' {
  74. Name = 'Container';
  75. Parent = GUI;
  76. BackgroundTransparency = 1;
  77. Size = UDim2.new( 1, 0, 0, 0 );
  78. BorderSizePixel = 0;
  79. ClipsDescendants = true;
  80. };
  81.  
  82. local Highlight = Create 'Frame' {
  83. Name = 'Highlight';
  84. Parent = Container;
  85. ZIndex = 2;
  86. BackgroundColor3 = Color3.new( 1, 1, 1 );
  87. BackgroundTransparency = 0.95;
  88. BorderSizePixel = 0;
  89. Position = UDim2.new( 0, 0, 0, 270 );
  90. Size = UDim2.new( 1, 0, 0, 180 );
  91. ZIndex = 2;
  92. };
  93.  
  94. if message then
  95. local OkButton = Create 'TextButton' {
  96. Name = 'OkButton';
  97. Parent = Highlight;
  98. BackgroundColor3 = Color3.new( 1, 162 / 255, 47 / 255 );
  99. BorderSizePixel = 0;
  100. Position = UDim2.new( 0.3, 0, 1, -60 );
  101. Size = UDim2.new( 0.4, 0, 0, 40 );
  102. ZIndex = 2;
  103. Font = Enum.Font.SourceSansBold;
  104. FontSize = Enum.FontSize.Size24;
  105. Text = ok_text;
  106. TextColor3 = Color3.new( 1, 1, 1 );
  107. TextStrokeColor3 = Color3.new( 0, 0, 0 );
  108. TextStrokeTransparency = 0.85;
  109. TextWrapped = true;
  110. [Create.E 'MouseButton1Up'] = function ()
  111. hideGUI();
  112. end;
  113. };
  114. Create 'Frame' {
  115. Name = 'Bevel';
  116. Parent = OkButton;
  117. BorderSizePixel = 0;
  118. BackgroundColor3 = Color3.new( 184 / 255, 116 / 255, 33 / 255 );
  119. Position = UDim2.new( 0, 0, 1, -2 );
  120. Size = UDim2.new( 1, 0, 0, 2 );
  121. ZIndex = 2;
  122. };
  123. local Message = Create 'TextLabel' {
  124. Name = 'Message';
  125. Parent = Highlight;
  126. BackgroundTransparency = 1;
  127. BorderSizePixel = 0;
  128. Position = UDim2.new( 0.1, 0, 0, 0 );
  129. Size = UDim2.new( 0.8, 0, 1, -30 );
  130. Font = Enum.Font.Arial;
  131. FontSize = Enum.FontSize.Size24;
  132. Text = message;
  133. TextColor3 = Color3.new( 1, 1, 1 );
  134. TextWrapped = true;
  135. };
  136. end;
  137.  
  138. local Interface = Create 'Frame' {
  139. Name = 'Interface';
  140. Parent = Container;
  141. ZIndex = 2;
  142. Size = UDim2.new( 0.6, 0, 0, 110 );
  143. Position = UDim2.new( 0.2, 0, 0, 300 );
  144. BorderSizePixel = 0;
  145. BackgroundTransparency = 1;
  146. Visible = not message;
  147. };
  148.  
  149. local CreationID = Create 'Frame' {
  150. Name = 'CreationID';
  151. Parent = Interface;
  152. BackgroundTransparency = 1;
  153. BorderSizePixel = 0;
  154. Position = UDim2.new( 0, 0, 0, 10 );
  155. Size = UDim2.new( 1, 0, 0, 30 );
  156. ZIndex = 2;
  157. };
  158.  
  159. Create 'Frame' {
  160. Name = 'BottomBorder';
  161. Parent = CreationID;
  162. BorderSizePixel = 0;
  163. BackgroundColor3 = Color3.new( 1, 162 / 255, 47 / 255 );
  164. Position = UDim2.new( 0, 0, 1, -1 );
  165. Size = UDim2.new( 1, 0, 0, 1 );
  166. ZIndex = 2;
  167. };
  168.  
  169. Create 'Frame' {
  170. Name = 'LeftBorder';
  171. Parent = CreationID;
  172. BorderSizePixel = 0;
  173. BackgroundColor3 = Color3.new( 1, 162 / 255, 47 / 255 );
  174. Position = UDim2.new( 0, 0, 0.8, 0 );
  175. Size = UDim2.new( 0, 1, 0.2, 0 );
  176. ZIndex = 2;
  177. };
  178.  
  179. Create 'Frame' {
  180. Name = 'RightBorder';
  181. Parent = CreationID;
  182. BorderSizePixel = 0;
  183. BackgroundColor3 = Color3.new( 1, 162 / 255, 47 / 255 );
  184. Position = UDim2.new( 1, -1, 0.8, 0 );
  185. Size = UDim2.new( 0, 1, 0.2, 0 );
  186. ZIndex = 2;
  187. };
  188.  
  189. local TextBox;
  190. TextBox = Create 'TextBox' {
  191. Parent = CreationID;
  192. BackgroundTransparency = 1;
  193. BorderSizePixel = 0;
  194. ClearTextOnFocus = true;
  195. Position = UDim2.new( 0, 10, 0, -10 );
  196. Size = UDim2.new( 1, -10, 1, 10 );
  197. ZIndex = 2;
  198. Font = Enum.Font.SourceSans;
  199. FontSize = Enum.FontSize.Size24;
  200. Text = "What's your creation's ID?";
  201. TextColor3 = Color3.new( 1, 1, 1 );
  202. TextTransparency = 0.3;
  203. TextXAlignment = Enum.TextXAlignment.Left;
  204. [Create.E 'FocusLost'] = function ( enter_pressed )
  205. if not enter_pressed then
  206. return;
  207. end;
  208. import( TextBox.Text:lower() );
  209. end;
  210. };
  211.  
  212. local CancelButton = Create 'TextButton' {
  213. Parent = Interface;
  214. BackgroundColor3 = Color3.new( 1, 162 / 255, 47 / 255 );
  215. BackgroundTransparency = 0.3;
  216. BorderSizePixel = 0;
  217. Name = 'CancelButton';
  218. Position = UDim2.new( 0.55, 0, 0, 65 );
  219. Size = UDim2.new( 0.45, 0, 0, 40 );
  220. ZIndex = 2;
  221. Font = Enum.Font.SourceSansBold;
  222. FontSize = Enum.FontSize.Size24;
  223. Text = 'Cancel';
  224. TextColor3 = Color3.new( 1, 1, 1 );
  225. TextStrokeColor3 = Color3.new( 0, 0, 0 );
  226. TextStrokeTransparency = 0.85;
  227. TextTransparency = 0.3;
  228. [Create.E 'MouseButton1Up'] = function ()
  229. hideGUI();
  230. end;
  231. };
  232.  
  233. Create 'Frame' {
  234. Parent = CancelButton;
  235. BackgroundColor3 = Color3.new( 131 / 255, 83 / 255, 23 / 255 );
  236. BorderSizePixel = 0;
  237. Name = 'Bevel';
  238. Position = UDim2.new( 0, 0, 1, -2 );
  239. Size = UDim2.new( 1, 0, 0, 2 );
  240. ZIndex = 2;
  241. };
  242.  
  243. local ImportButton = Create 'TextButton' {
  244. Parent = Interface;
  245. BackgroundColor3 = Color3.new( 1, 162 / 255, 47 / 255 );
  246. BorderSizePixel = 0;
  247. Name = 'ImportButton';
  248. Position = UDim2.new( 0, 0, 0, 65 );
  249. Size = UDim2.new( 0.45, 0, 0, 40 );
  250. ZIndex = 2;
  251. Font = Enum.Font.SourceSansBold;
  252. FontSize = Enum.FontSize.Size24;
  253. Text = 'Import';
  254. TextColor3 = Color3.new( 1, 1, 1 );
  255. TextStrokeColor3 = Color3.new( 0, 0, 0 );
  256. TextStrokeTransparency = 0.85;
  257. [Create.E 'MouseButton1Up'] = function ()
  258. import( TextBox.Text:lower() );
  259. end;
  260. };
  261.  
  262. Create 'Frame' {
  263. Parent = ImportButton;
  264. BackgroundColor3 = Color3.new( 204 / 255, 129 / 255, 37 / 255 );
  265. BorderSizePixel = 0;
  266. Name = 'Bevel';
  267. Position = UDim2.new( 0, 0, 1, -2 );
  268. Size = UDim2.new( 1, 0, 0, 2 );
  269. ZIndex = 2;
  270. };
  271.  
  272. Create 'Frame' {
  273. Name = 'Overlay';
  274. Parent = Container;
  275. BackgroundColor3 = Color3.new( 0, 0, 0 );
  276. BackgroundTransparency = 0.25;
  277. BorderSizePixel = 0;
  278. Size = UDim2.new( 1, 0, 1, 0 );
  279. };
  280.  
  281. local Logo = Create 'ImageLabel' {
  282. Name = 'Logo';
  283. Parent = Container;
  284. BackgroundTransparency = 1;
  285. BorderSizePixel = 0;
  286. Image = bt_logo;
  287. Position = UDim2.new( 0, GUI.AbsoluteSize.x / 2 - 128, 0, 0 );
  288. Size = UDim2.new( 0, 256, 0, 256 );
  289. ZIndex = 2;
  290. };
  291. GUI.Changed:connect( function ( property )
  292. if property == 'AbsoluteSize' then
  293. Logo.Position = UDim2.new( 0, GUI.AbsoluteSize.x / 2 - 128, 0, 0 );
  294. end;
  295. end );
  296.  
  297. Container:TweenSize( UDim2.new( 1, 0, 1, 0 ), Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, 0.5, true );
  298.  
  299. end;
  300.  
  301. function hideGUI()
  302.  
  303. -- Hide the current GUI
  304. if GUI then
  305. GUI:Destroy();
  306. end;
  307.  
  308. end;
  309.  
  310. Launcher.Click:connect( function ()
  311. if SoloMode then
  312. showGUI( 'Use regular Studio to import.', 'Sure' );
  313. else
  314. showGUI();
  315. end;
  316. end );
  317.  
  318. function import( creation_id )
  319.  
  320. hideGUI();
  321.  
  322. -- Try to download the creation
  323. local creation_data;
  324. local download_attempt, download_error = ypcall( function ()
  325. creation_data = Services.HttpService:GetAsync( export_base_url:format( creation_id ) );
  326. end );
  327.  
  328. -- Fail graciously
  329. if not download_attempt and download_error == 'Http requests are not enabled' then
  330. print 'Import from Building Tools by F3X: Please enable HTTP requests (see http://wiki.roblox.com/index.php?title=Sending_HTTP_requests#Http_requests_are_not_enabled)';
  331. showGUI( 'Please enable HTTP requests (see Output)', 'Got it' );
  332. return false;
  333. end;
  334. if not download_attempt then
  335. print( 'Import from Building Tools by F3X (download request error): ' .. tostring( download_error ) );
  336. showGUI( "We couldn't get your creation", 'Oh' );
  337. return false;
  338. end;
  339. if not ( creation_data and type( creation_data ) == 'string' and creation_data:len() > 0 ) then
  340. showGUI( "We couldn't get your creation", ':(' );
  341. return false;
  342. end;
  343. if not pcall( function () creation_data = Services.HttpService:JSONDecode( creation_data ); end ) then
  344. showGUI( "We couldn't get your creation", ":'(" );
  345. return false;
  346. end;
  347.  
  348. -- Create a container to hold the creation
  349. local Container = Instance.new( 'Model', Services.Workspace );
  350. Container.Name = 'BTExport';
  351.  
  352. if creation_data.version == 1 then
  353.  
  354. local objects = {};
  355.  
  356. for part_id, part_data in pairs( creation_data.parts ) do
  357. local Part;
  358.  
  359. local part_type = part_data[1];
  360. if part_type == 1 then
  361. Part = Instance.new( "Part" );
  362. elseif part_type == 2 then
  363. Part = Instance.new( "TrussPart" );
  364. elseif part_type == 3 then
  365. Part = Instance.new( "WedgePart" );
  366. elseif part_type == 4 then
  367. Part = Instance.new( "CornerWedgePart" );
  368. elseif part_type == 5 then
  369. Part = Instance.new( "Part" );
  370. Part.Shape = "Cylinder";
  371. elseif part_type == 6 then
  372. Part = Instance.new( "Part" );
  373. Part.Shape = "Ball";
  374. elseif part_type == 7 then
  375. Part = Instance.new( "Seat" );
  376. elseif part_type == 8 then
  377. Part = Instance.new( "VehicleSeat" );
  378. elseif part_type == 9 then
  379. Part = Instance.new( "SpawnLocation" );
  380. end;
  381. objects[part_id] = Part;
  382.  
  383. Part.Size = Vector3.new( unpack( part_data[2] ) );
  384. Part.CFrame = CFrame.new( unpack( part_data[3] ) );
  385. Part.BrickColor = BrickColor.new( part_data[4] );
  386. Part.Material = part_data[5];
  387. Part.Anchored = part_data[6];
  388. Part.CanCollide = part_data[7];
  389. Part.Reflectance = part_data[8];
  390. Part.Transparency = part_data[9];
  391. Part.TopSurface = part_data[10];
  392. Part.BottomSurface = part_data[11];
  393. Part.LeftSurface = part_data[12];
  394. Part.RightSurface = part_data[13];
  395. Part.FrontSurface = part_data[14];
  396. Part.BackSurface = part_data[15];
  397.  
  398. Part.Parent = Container;
  399.  
  400. -- Add the part ID if it's referenced somewhere else
  401. if creation_data.welds then
  402. for _, Weld in pairs( creation_data.welds ) do
  403. if Weld[1] == part_id or Weld[2] == part_id then
  404. RbxUtility.Create 'StringValue' {
  405. Name = 'BTID';
  406. Parent = Part;
  407. Value = part_id;
  408. };
  409. break;
  410. end;
  411. end;
  412. end;
  413.  
  414. end;
  415.  
  416. if creation_data.welds then
  417. local weld_count = 0;
  418. for _, __ in pairs( creation_data.welds ) do
  419. weld_count = weld_count + 1;
  420. end;
  421. if weld_count > 0 then
  422. local WeldScript = Instance.new( 'Script' );
  423. WeldScript.Name = 'BTWelder';
  424. WeldScript.Source = [[-- This script creates the welds between parts imported by the Building Tools by F3X plugin.
  425.  
  426. local BeforeAnchored = {};
  427. for _, Part in pairs(script.Parent:GetChildren()) do
  428. if Part:IsA 'BasePart' then
  429. BeforeAnchored[Part] = Part.Anchored;
  430. Part.Anchored = true;
  431. end;
  432. end;
  433.  
  434. local create = LoadLibrary( 'RbxUtility' ).Create;
  435. function _getAllDescendants( Parent )
  436. -- Recursively gets all the descendants of `Parent` and returns them
  437.  
  438. local descendants = {};
  439.  
  440. for _, Child in pairs( Parent:GetChildren() ) do
  441.  
  442. -- Add the direct descendants of `Parent`
  443. table.insert( descendants, Child );
  444.  
  445. -- Add the descendants of each child
  446. for _, Subchild in pairs( _getAllDescendants( Child ) ) do
  447. table.insert( descendants, Subchild );
  448. end;
  449.  
  450. end;
  451.  
  452. return descendants;
  453.  
  454. end;
  455. function findExportedPart( part_id )
  456. for _, Object in pairs( _getAllDescendants( script.Parent ) ) do
  457. if Object:IsA( 'StringValue' ) then
  458. if Object.Name == 'BTID' and Object.Value == part_id then
  459. return Object.Parent;
  460. end;
  461. end;
  462. end;
  463. end;
  464.  
  465. ]];
  466.  
  467. for weld_id, weld_data in pairs( creation_data.welds ) do
  468. WeldScript.Source = WeldScript.Source .. [[
  469.  
  470. ( function ()
  471. local Part0 = findExportedPart( ']] .. weld_data[1] .. [[' );
  472. local Part1 = findExportedPart( ']] .. weld_data[2] .. [[' );
  473. if not Part0 or not Part1 then
  474. return;
  475. end;
  476. create 'Weld' {
  477. Name = 'BTWeld';
  478. Parent = Game.JointsService;
  479. Archivable = false;
  480. Part0 = Part0;
  481. Part1 = Part1;
  482. C1 = CFrame.new( ]] .. table.concat( weld_data[3], ', ' ) .. [[ );
  483. };
  484. end )();
  485. ]];
  486. end;
  487.  
  488. WeldScript.Source = WeldScript.Source .. [[
  489.  
  490. for Part, Anchored in pairs(BeforeAnchored) do
  491. Part.Anchored = Anchored;
  492. end;]];
  493. WeldScript.Parent = Container;
  494. end;
  495. end;
  496.  
  497. if creation_data.meshes then
  498. for mesh_id, mesh_data in pairs( creation_data.meshes ) do
  499.  
  500. -- Create, place, and register the mesh
  501. local Mesh = Instance.new( "SpecialMesh", objects[mesh_data[1]] );
  502. objects[mesh_id] = Mesh;
  503.  
  504. -- Set the mesh's properties
  505. Mesh.MeshType = mesh_data[2];
  506. Mesh.Scale = Vector3.new( unpack( mesh_data[3] ) );
  507. Mesh.MeshId = mesh_data[4];
  508. Mesh.TextureId = mesh_data[5];
  509. Mesh.VertexColor = Vector3.new( unpack( mesh_data[6] ) );
  510.  
  511. end;
  512. end;
  513.  
  514. if creation_data.textures then
  515. for texture_id, texture_data in pairs( creation_data.textures ) do
  516.  
  517. -- Create, place, and register the texture
  518. local texture_class;
  519. if texture_data[2] == 1 then
  520. texture_class = 'Decal';
  521. elseif texture_data[2] == 2 then
  522. texture_class = 'Texture';
  523. end;
  524. local Texture = Instance.new( texture_class, objects[texture_data[1]] );
  525. objects[texture_id] = Texture;
  526.  
  527. -- Set the texture's properties
  528. Texture.Face = texture_data[3];
  529. Texture.Texture = texture_data[4];
  530. Texture.Transparency = texture_data[5];
  531. if Texture:IsA( "Texture" ) then
  532. Texture.StudsPerTileU = texture_data[6];
  533. Texture.StudsPerTileV = texture_data[7];
  534. end;
  535.  
  536. end;
  537. end;
  538.  
  539. if creation_data.lights then
  540. for light_id, light_data in pairs( creation_data.lights ) do
  541.  
  542. -- Create, place, and register the light
  543. local light_class;
  544. if light_data[2] == 1 then
  545. light_class = 'PointLight';
  546. elseif light_data[2] == 2 then
  547. light_class = 'SpotLight';
  548. end;
  549. local Light = Instance.new( light_class, objects[light_data[1]] )
  550. objects[light_id] = Light;
  551.  
  552. -- Set the light's properties
  553. Light.Color = Color3.new( unpack( light_data[3] ) );
  554. Light.Brightness = light_data[4];
  555. Light.Range = light_data[5];
  556. Light.Shadows = light_data[6];
  557. if Light:IsA( 'SpotLight' ) then
  558. Light.Angle = light_data[7];
  559. Light.Face = light_data[8];
  560. end;
  561.  
  562. end;
  563. end;
  564.  
  565. if creation_data.decorations then
  566. for decoration_id, decoration_data in pairs( creation_data.decorations ) do
  567.  
  568. -- Create and register the decoration
  569. if decoration_data[2] == 1 then
  570. local Smoke = RbxUtility.Create 'Smoke' {
  571. Parent = objects[decoration_data[1]];
  572. Color = Color3.new( unpack( decoration_data[3] ) );
  573. Opacity = decoration_data[4];
  574. RiseVelocity = decoration_data[5];
  575. Size = decoration_data[6];
  576. };
  577. objects[decoration_id] = Smoke;
  578.  
  579. elseif decoration_data[2] == 2 then
  580. local Fire = RbxUtility.Create 'Fire' {
  581. Parent = objects[decoration_data[1]];
  582. Color = Color3.new( unpack( decoration_data[3] ) );
  583. SecondaryColor = Color3.new( unpack( decoration_data[4] ) );
  584. Heat = decoration_data[5];
  585. Size = decoration_data[6];
  586. };
  587. objects[decoration_id] = Fire;
  588.  
  589. elseif decoration_data[2] == 3 then
  590. local Sparkles = RbxUtility.Create 'Sparkles' {
  591. Parent = objects[decoration_data[1]];
  592. SparkleColor = Color3.new( unpack( decoration_data[3] ) );
  593. };
  594. objects[decoration_id] = Sparkles;
  595. end;
  596.  
  597. end;
  598. end;
  599.  
  600. Container:MakeJoints();
  601. Services.Selection:Set( { Container } );
  602.  
  603. -- Parse builds with serialization format version 2
  604. elseif creation_data.Version == 2 then
  605.  
  606. -- Inflate the build data
  607. local Parts = SerializationV2.InflateBuildData(creation_data);
  608.  
  609. -- Parent the build into the export container
  610. for _, Part in pairs(Parts) do
  611. Part.Parent = Container;
  612. end;
  613.  
  614. -- Finalize the import
  615. Container:MakeJoints();
  616. Services.Selection:Set { Container };
  617.  
  618. -- Parse builds with serialization format version 3
  619. elseif creation_data.Version == 3 then
  620.  
  621. -- Inflate the build data
  622. local Parts = SerializationV3.InflateBuildData(creation_data);
  623.  
  624. -- Parent the build into the export container
  625. for _, Part in pairs(Parts) do
  626. Part.Parent = Container;
  627. end;
  628.  
  629. -- Finalize the import
  630. Container:MakeJoints();
  631. Services.Selection:Set { Container };
  632.  
  633. end;
  634.  
  635. end;]]></ProtectedString>
  636. </Properties>
  637. <Item class="ModuleScript" referent="RBX7DE39C6EBF52434597B33516946E415B">
  638. <Properties>
  639. <Content name="LinkedSource"><null></null></Content>
  640. <string name="Name">SerializationModule2</string>
  641. <string name="ScriptGuid">{175547C9-C6CE-443E-8ED2-EE4F26AB5DF8}</string>
  642. <ProtectedString name="Source"><![CDATA[Serialization = {};
  643.  
  644. -- Import services
  645. Support = require(script.Parent.SupportLibrary);
  646. Support.ImportServices();
  647.  
  648. local Types = {
  649. Part = 0,
  650. WedgePart = 1,
  651. CornerWedgePart = 2,
  652. VehicleSeat = 3,
  653. Seat = 4,
  654. TrussPart = 5,
  655. SpecialMesh = 6,
  656. Texture = 7,
  657. Decal = 8,
  658. PointLight = 9,
  659. SpotLight = 10,
  660. SurfaceLight = 11,
  661. Smoke = 12,
  662. Fire = 13,
  663. Sparkles = 14,
  664. Model = 15
  665. };
  666.  
  667. local DefaultNames = {
  668. Part = 'Part',
  669. WedgePart = 'Wedge',
  670. CornerWedgePart = 'CornerWedge',
  671. VehicleSeat = 'VehicleSeat',
  672. Seat = 'Seat',
  673. TrussPart = 'Truss',
  674. SpecialMesh = 'Mesh',
  675. Texture = 'Texture',
  676. Decal = 'Decal',
  677. PointLight = 'PointLight',
  678. SpotLight = 'SpotLight',
  679. SurfaceLight = 'SurfaceLight',
  680. Smoke = 'Smoke',
  681. Fire = 'Fire',
  682. Sparkles = 'Sparkles',
  683. Model = 'Model'
  684. };
  685.  
  686. function Serialization.SerializeModel(Items)
  687. -- Returns a serialized version of the given model
  688.  
  689. -- Filter out non-serializable items in `Items`
  690. local SerializableItems = {};
  691. for Index, Item in ipairs(Items) do
  692. table.insert(SerializableItems, Types[Item.ClassName] and Item or nil);
  693. end;
  694. Items = SerializableItems;
  695.  
  696. -- Get a snapshot of the content
  697. local Keys = Support.FlipTable(Items);
  698.  
  699. local Data = {};
  700. Data.Version = 2;
  701. Data.Items = {};
  702.  
  703. -- Serialize each item in the model
  704. for Index, Item in pairs(Items) do
  705.  
  706. if Item:IsA 'BasePart' then
  707. local Datum = {};
  708. Datum[1] = Types[Item.ClassName];
  709. Datum[2] = Keys[Item.Parent] or 0;
  710. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  711. Datum[4] = Item.Size.X;
  712. Datum[5] = Item.Size.Y;
  713. Datum[6] = Item.Size.Z;
  714. Support.ConcatTable(Datum, { Item.CFrame:components() });
  715. Datum[19] = Item.BrickColor.Number;
  716. Datum[20] = Item.Material.Value;
  717. Datum[21] = Item.Anchored and 1 or 0;
  718. Datum[22] = Item.CanCollide and 1 or 0;
  719. Datum[23] = Item.Reflectance;
  720. Datum[24] = Item.Transparency;
  721. Datum[25] = Item.TopSurface.Value;
  722. Datum[26] = Item.BottomSurface.Value;
  723. Datum[27] = Item.FrontSurface.Value;
  724. Datum[28] = Item.BackSurface.Value;
  725. Datum[29] = Item.LeftSurface.Value;
  726. Datum[30] = Item.RightSurface.Value;
  727. Data.Items[Index] = Datum;
  728. end;
  729.  
  730. if Item.ClassName == 'Part' then
  731. local Datum = Data.Items[Index];
  732. Datum[31] = Item.Shape.Value;
  733. end;
  734.  
  735. if Item.ClassName == 'VehicleSeat' then
  736. local Datum = Data.Items[Index];
  737. Datum[31] = Item.MaxSpeed;
  738. Datum[32] = Item.Torque;
  739. Datum[33] = Item.TurnSpeed;
  740. end;
  741.  
  742. if Item.ClassName == 'TrussPart' then
  743. local Datum = Data.Items[Index];
  744. Datum[31] = Item.Style.Value;
  745. end;
  746.  
  747. if Item.ClassName == 'SpecialMesh' then
  748. local Datum = {};
  749. Datum[1] = Types[Item.ClassName];
  750. Datum[2] = Keys[Item.Parent] or 0;
  751. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  752. Datum[4] = Item.MeshType.Value;
  753. Datum[5] = Item.MeshId;
  754. Datum[6] = Item.TextureId;
  755. Datum[7] = Item.Offset.X;
  756. Datum[8] = Item.Offset.Y;
  757. Datum[9] = Item.Offset.Z;
  758. Datum[10] = Item.Scale.X;
  759. Datum[11] = Item.Scale.Y;
  760. Datum[12] = Item.Scale.Z;
  761. Datum[13] = Item.VertexColor.X;
  762. Datum[14] = Item.VertexColor.Y;
  763. Datum[15] = Item.VertexColor.Z;
  764. Data.Items[Index] = Datum;
  765. end;
  766.  
  767. if Item:IsA 'Decal' then
  768. local Datum = {};
  769. Datum[1] = Types[Item.ClassName];
  770. Datum[2] = Keys[Item.Parent] or 0;
  771. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  772. Datum[4] = Item.Texture;
  773. Datum[5] = Item.Transparency;
  774. Datum[6] = Item.Face.Value;
  775. Data.Items[Index] = Datum;
  776. end;
  777.  
  778. if Item.ClassName == 'Texture' then
  779. local Datum = Data.Items[Index];
  780. Datum[7] = Item.StudsPerTileU;
  781. Datum[8] = Item.StudsPerTileV;
  782. end;
  783.  
  784. if Item:IsA 'Light' then
  785. local Datum = {};
  786. Datum[1] = Types[Item.ClassName];
  787. Datum[2] = Keys[Item.Parent] or 0;
  788. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  789. Datum[4] = Item.Brightness;
  790. Datum[5] = Item.Color.r;
  791. Datum[6] = Item.Color.g;
  792. Datum[7] = Item.Color.b;
  793. Datum[8] = Item.Enabled and 1 or 0;
  794. Datum[9] = Item.Shadows and 1 or 0;
  795. Data.Items[Index] = Datum;
  796. end;
  797.  
  798. if Item.ClassName == 'PointLight' then
  799. local Datum = Data.Items[Index];
  800. Datum[10] = Item.Range;
  801. end;
  802.  
  803. if Item.ClassName == 'SpotLight' then
  804. local Datum = Data.Items[Index];
  805. Datum[10] = Item.Range;
  806. Datum[11] = Item.Angle;
  807. Datum[12] = Item.Face.Value;
  808. end;
  809.  
  810. if Item.ClassName == 'SurfaceLight' then
  811. local Datum = Data.Items[Index];
  812. Datum[10] = Item.Range;
  813. Datum[11] = Item.Angle;
  814. Datum[12] = Item.Face.Value;
  815. end;
  816.  
  817. if Item.ClassName == 'Smoke' then
  818. local Datum = {};
  819. Datum[1] = Types[Item.ClassName];
  820. Datum[2] = Keys[Item.Parent] or 0;
  821. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  822. Datum[4] = Item.Enabled and 1 or 0;
  823. Datum[5] = Item.Color.r;
  824. Datum[6] = Item.Color.g;
  825. Datum[7] = Item.Color.b;
  826. Datum[8] = Item.Size;
  827. Datum[9] = Item.RiseVelocity;
  828. Datum[10] = Item.Opacity;
  829. Data.Items[Index] = Datum;
  830. end;
  831.  
  832. if Item.ClassName == 'Fire' then
  833. local Datum = {};
  834. Datum[1] = Types[Item.ClassName];
  835. Datum[2] = Keys[Item.Parent] or 0;
  836. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  837. Datum[4] = Item.Enabled and 1 or 0;
  838. Datum[5] = Item.Color.r;
  839. Datum[6] = Item.Color.g;
  840. Datum[7] = Item.Color.b;
  841. Datum[8] = Item.SecondaryColor.r;
  842. Datum[9] = Item.SecondaryColor.g;
  843. Datum[10] = Item.SecondaryColor.b;
  844. Datum[11] = Item.Heat;
  845. Datum[12] = Item.Size;
  846. Data.Items[Index] = Datum;
  847. end;
  848.  
  849. if Item.ClassName == 'Sparkles' then
  850. local Datum = {};
  851. Datum[1] = Types[Item.ClassName];
  852. Datum[2] = Keys[Item.Parent] or 0;
  853. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  854. Datum[4] = Item.Enabled and 1 or 0;
  855. Datum[5] = Item.SparkleColor.r;
  856. Datum[6] = Item.SparkleColor.g;
  857. Datum[7] = Item.SparkleColor.b;
  858. Data.Items[Index] = Datum;
  859. end;
  860.  
  861. if Item.ClassName == 'Model' then
  862. local Datum = {};
  863. Datum[1] = Types[Item.ClassName];
  864. Datum[2] = Keys[Item.Parent] or 0;
  865. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  866. Datum[4] = Item.PrimaryPart and Keys[Item.PrimaryPart] or 0;
  867. Data.Items[Index] = Datum;
  868. end;
  869.  
  870. -- Spread the workload over time to avoid locking up the CPU
  871. if Index % 100 == 0 then
  872. wait(0.01);
  873. end;
  874.  
  875. end;
  876.  
  877. -- Return the serialized data
  878. return HttpService:JSONEncode(Data);
  879.  
  880. end;
  881.  
  882. function Serialization.InflateBuildData(Data)
  883. -- Returns an inflated version of the given build data
  884.  
  885. local Build = {};
  886. local Instances = {};
  887.  
  888. -- Create each instance
  889. for Index, Datum in ipairs(Data.Items) do
  890.  
  891. -- Inflate BaseParts
  892. if Datum[1] == Types.Part
  893. or Datum[1] == Types.WedgePart
  894. or Datum[1] == Types.CornerWedgePart
  895. or Datum[1] == Types.VehicleSeat
  896. or Datum[1] == Types.Seat
  897. or Datum[1] == Types.TrussPart
  898. then
  899. local Item = Instance.new(Support.FindTableOccurrence(Types, Datum[1]));
  900. Item.Size = Vector3.new(unpack(Support.Slice(Datum, 4, 6)));
  901. Item.CFrame = CFrame.new(unpack(Support.Slice(Datum, 7, 18)));
  902. Item.BrickColor = BrickColor.new(Datum[19]);
  903. Item.Material = Datum[20];
  904. Item.Anchored = Datum[21] == 1;
  905. Item.CanCollide = Datum[22] == 1;
  906. Item.Reflectance = Datum[23];
  907. Item.Transparency = Datum[24];
  908. Item.TopSurface = Datum[25];
  909. Item.BottomSurface = Datum[26];
  910. Item.FrontSurface = Datum[27];
  911. Item.BackSurface = Datum[28];
  912. Item.LeftSurface = Datum[29];
  913. Item.RightSurface = Datum[30];
  914.  
  915. -- Register the part
  916. Instances[Index] = Item;
  917. end;
  918.  
  919. -- Inflate specific Part properties
  920. if Datum[1] == Types.Part then
  921. local Item = Instances[Index];
  922. Item.Shape = Datum[31];
  923. end;
  924.  
  925. -- Inflate specific VehicleSeat properties
  926. if Datum[1] == Types.VehicleSeat then
  927. local Item = Instances[Index];
  928. Item.MaxSpeed = Datum[31];
  929. Item.Torque = Datum[32];
  930. Item.TurnSpeed = Datum[33];
  931. end;
  932.  
  933. -- Inflate specific TrussPart properties
  934. if Datum[1] == Types.TrussPart then
  935. local Item = Instances[Index];
  936. Item.Style = Datum[31];
  937. end;
  938.  
  939. -- Inflate SpecialMesh instances
  940. if Datum[1] == Types.SpecialMesh then
  941. local Item = Instance.new('SpecialMesh');
  942. Item.MeshType = Datum[4];
  943. Item.MeshId = Datum[5];
  944. Item.TextureId = Datum[6];
  945. Item.Offset = Vector3.new(unpack(Support.Slice(Datum, 7, 9)));
  946. Item.Scale = Vector3.new(unpack(Support.Slice(Datum, 10, 12)));
  947. Item.VertexColor = Vector3.new(unpack(Support.Slice(Datum, 13, 15)));
  948.  
  949. -- Register the mesh
  950. Instances[Index] = Item;
  951. end;
  952.  
  953. -- Inflate Decal instances
  954. if Datum[1] == Types.Decal or Datum[1] == Types.Texture then
  955. local Item = Instance.new(Support.FindTableOccurrence(Types, Datum[1]));
  956. Item.Texture = Datum[4];
  957. Item.Transparency = Datum[5];
  958. Item.Face = Datum[6];
  959.  
  960. -- Register the Decal
  961. Instances[Index] = Item;
  962. end;
  963.  
  964. -- Inflate specific Texture properties
  965. if Datum[1] == Types.Texture then
  966. local Item = Instances[Index];
  967. Item.StudsPerTileU = Datum[7];
  968. Item.StudsPerTileV = Datum[8];
  969. end;
  970.  
  971. -- Inflate Light instances
  972. if Datum[1] == Types.PointLight
  973. or Datum[1] == Types.SpotLight
  974. or Datum[1] == Types.SurfaceLight
  975. then
  976. local Item = Instance.new(Support.FindTableOccurrence(Types, Datum[1]));
  977. Item.Brightness = Datum[4];
  978. Item.Color = Color3.new(unpack(Support.Slice(Datum, 5, 7)));
  979. Item.Enabled = Datum[8] == 1;
  980. Item.Shadows = Datum[9] == 1;
  981.  
  982. -- Register the light
  983. Instances[Index] = Item;
  984. end;
  985.  
  986. -- Inflate specific PointLight properties
  987. if Datum[1] == Types.PointLight then
  988. local Item = Instances[Index];
  989. Item.Range = Datum[10];
  990. end;
  991.  
  992. -- Inflate specific SpotLight properties
  993. if Datum[1] == Types.SpotLight then
  994. local Item = Instances[Index];
  995. Item.Range = Datum[10];
  996. Item.Angle = Datum[11];
  997. Item.Face = Datum[12];
  998. end;
  999.  
  1000. -- Inflate specific SurfaceLight properties
  1001. if Datum[1] == Types.SurfaceLight then
  1002. local Item = Instances[Index];
  1003. Item.Range = Datum[10];
  1004. Item.Angle = Datum[11];
  1005. Item.Face = Datum[12];
  1006. end;
  1007.  
  1008. -- Inflate Smoke instances
  1009. if Datum[1] == Types.Smoke then
  1010. local Item = Instance.new('Smoke');
  1011. Item.Enabled = Datum[4] == 1;
  1012. Item.Color = Color3.new(unpack(Support.Slice(Datum, 5, 7)));
  1013. Item.Size = Datum[8];
  1014. Item.RiseVelocity = Datum[9];
  1015. Item.Opacity = Datum[10];
  1016.  
  1017. -- Register the smoke
  1018. Instances[Index] = Item;
  1019. end;
  1020.  
  1021. -- Inflate Fire instances
  1022. if Datum[1] == Types.Fire then
  1023. local Item = Instance.new('Fire');
  1024. Item.Enabled = Datum[4] == 1;
  1025. Item.Color = Color3.new(unpack(Support.Slice(Datum, 5, 7)));
  1026. Item.SecondaryColor = Color3.new(unpack(Support.Slice(Datum, 8, 10)));
  1027. Item.Heat = Datum[11];
  1028. Item.Size = Datum[12];
  1029.  
  1030. -- Register the fire
  1031. Instances[Index] = Item;
  1032. end;
  1033.  
  1034. -- Inflate Sparkles instances
  1035. if Datum[1] == Types.Sparkles then
  1036. local Item = Instance.new('Sparkles');
  1037. Item.Enabled = Datum[4] == 1;
  1038. Item.SparkleColor = Color3.new(unpack(Support.Slice(Datum, 5, 7)));
  1039.  
  1040. -- Register the instance
  1041. Instances[Index] = Item;
  1042. end;
  1043.  
  1044. -- Inflate Model instances
  1045. if Datum[1] == Types.Model then
  1046. local Item = Instance.new('Model');
  1047.  
  1048. -- Register the model
  1049. Instances[Index] = Item;
  1050. end;
  1051.  
  1052. end;
  1053.  
  1054. -- Set object values on each instance
  1055. for Index, Datum in pairs(Data.Items) do
  1056.  
  1057. -- Get the item's instance
  1058. local Item = Instances[Index];
  1059.  
  1060. -- Set each item's parent and name
  1061. if Item and Datum[1] <= 15 then
  1062. Item.Name = (Datum[3] == '') and DefaultNames[Item.ClassName] or Datum[3];
  1063. if Datum[2] == 0 then
  1064. table.insert(Build, Item);
  1065. else
  1066. Item.Parent = Instances[Datum[2]];
  1067. end;
  1068. end;
  1069.  
  1070. -- Set model primary parts
  1071. if Item and Datum[1] == 15 then
  1072. Item.PrimaryPart = (Datum[4] ~= 0) and Instances[Datum[4]] or nil;
  1073. end;
  1074.  
  1075. end;
  1076.  
  1077. -- Return the model
  1078. return Build;
  1079.  
  1080. end;
  1081.  
  1082. -- Return the API
  1083. return Serialization;]]></ProtectedString>
  1084. </Properties>
  1085. </Item>
  1086. <Item class="ModuleScript" referent="RBXAAAC7DD1E3E04685B790375DBC0CAFA3">
  1087. <Properties>
  1088. <Content name="LinkedSource"><null></null></Content>
  1089. <string name="Name">SupportLibrary</string>
  1090. <string name="ScriptGuid">{B34CAB38-2088-42A7-9DD7-D0A6D6989372}</string>
  1091. <ProtectedString name="Source"><![CDATA[SupportLibrary = {};
  1092.  
  1093. function SupportLibrary.FindTableOccurrences(Haystack, Needle)
  1094. -- Returns the positions of instances of `needle` in table `haystack`
  1095.  
  1096. local Positions = {};
  1097.  
  1098. -- Add any indexes from `Haystack` that are `Needle`
  1099. for Index, Value in pairs(Haystack) do
  1100. if Value == Needle then
  1101. table.insert(Positions, Index);
  1102. end;
  1103. end;
  1104.  
  1105. return Positions;
  1106. end;
  1107.  
  1108. function SupportLibrary.FindTableOccurrence(Haystack, Needle)
  1109. -- Returns one occurrence of `Needle` in `Haystack`
  1110.  
  1111. -- Search for the first instance of `Needle` found and return it
  1112. for Index, Value in pairs(Haystack) do
  1113. if Value == Needle then
  1114. return Index;
  1115. end;
  1116. end;
  1117.  
  1118. -- If no occurrences exist, return `nil`
  1119. return nil;
  1120.  
  1121. end;
  1122.  
  1123. function SupportLibrary.IsInTable(Haystack, Needle)
  1124. -- Returns whether the given `Needle` can be found within table `Haystack`
  1125.  
  1126. -- Go through every value in `Haystack` and return whether `Needle` is found
  1127. for _, Value in pairs(Haystack) do
  1128. if Value == Needle then
  1129. return true;
  1130. end;
  1131. end;
  1132.  
  1133. -- If no instances were found, return false
  1134. return false;
  1135. end;
  1136.  
  1137. function SupportLibrary.DoTablesMatch(A, B)
  1138. -- Returns whether the values of tables A and B are the same
  1139.  
  1140. -- Check B table differences
  1141. for Index in pairs(A) do
  1142. if A[Index] ~= B[Index] then
  1143. return false;
  1144. end;
  1145. end;
  1146.  
  1147. -- Check A table differences
  1148. for Index in pairs(B) do
  1149. if B[Index] ~= A[Index] then
  1150. return false;
  1151. end;
  1152. end;
  1153.  
  1154. -- Return true if no differences
  1155. return true;
  1156. end;
  1157.  
  1158. function SupportLibrary.Round(Number, Places)
  1159. -- Returns `Number` rounded to the given number of decimal places (from lua-users)
  1160.  
  1161. -- Ensure that `Number` is a number
  1162. if type(Number) ~= 'number' then
  1163. return;
  1164. end;
  1165.  
  1166. -- Round the number
  1167. local Multiplier = 10 ^ (Places or 0);
  1168. local RoundedNumber = math.floor(Number * Multiplier + 0.5) / Multiplier;
  1169.  
  1170. -- Return the rounded number
  1171. return RoundedNumber;
  1172. end;
  1173.  
  1174. function SupportLibrary.CloneTable(Table)
  1175. -- Returns a copy of `Table`
  1176.  
  1177. local ClonedTable = {};
  1178.  
  1179. -- Copy all values into `ClonedTable`
  1180. for Key, Value in pairs(Table) do
  1181. ClonedTable[Key] = Value;
  1182. end;
  1183.  
  1184. -- Return the clone
  1185. return ClonedTable;
  1186. end;
  1187.  
  1188. function SupportLibrary.GetAllDescendants(Parent)
  1189. -- Recursively gets all the descendants of `Parent` and returns them
  1190.  
  1191. local Descendants = {};
  1192.  
  1193. for _, Child in pairs(Parent:GetChildren()) do
  1194.  
  1195. -- Add the direct descendants of `Parent`
  1196. table.insert(Descendants, Child);
  1197.  
  1198. -- Add the descendants of each child
  1199. for _, Subchild in pairs(SupportLibrary.GetAllDescendants(Child)) do
  1200. table.insert(Descendants, Subchild);
  1201. end;
  1202.  
  1203. end;
  1204.  
  1205. return Descendants;
  1206. end;
  1207.  
  1208. function SupportLibrary.GetDescendantCount(Parent)
  1209. -- Recursively gets a count of all the descendants of `Parent` and returns them
  1210.  
  1211. local Count = 0;
  1212.  
  1213. for _, Child in pairs(Parent:GetChildren()) do
  1214.  
  1215. -- Count the direct descendants of `Parent`
  1216. Count = Count + 1;
  1217.  
  1218. -- Count and add the descendants of each child
  1219. Count = Count + SupportLibrary.GetDescendantCount(Child);
  1220.  
  1221. end;
  1222.  
  1223. return Count;
  1224. end;
  1225.  
  1226. function SupportLibrary.CloneParts(Parts)
  1227. -- Returns a table of cloned `Parts`
  1228.  
  1229. local Clones = {};
  1230.  
  1231. -- Copy the parts into `Clones`
  1232. for Index, Part in pairs(Parts) do
  1233. Clones[Index] = Part:Clone();
  1234. end;
  1235.  
  1236. return Clones;
  1237. end;
  1238.  
  1239. function SupportLibrary.SplitString(String, Delimiter)
  1240. -- Returns a table of string `String` split by pattern `Delimiter`
  1241.  
  1242. local StringParts = {};
  1243. local Pattern = ('([^%s]+)'):format(Delimiter);
  1244.  
  1245. -- Capture each separated part
  1246. String:gsub(Pattern, function (Part)
  1247. table.insert(StringParts, Part);
  1248. end);
  1249.  
  1250. return StringParts;
  1251. end;
  1252.  
  1253. function SupportLibrary.GetChildOfClass(Parent, ClassName, Inherit)
  1254. -- Returns the first child of `Parent` that is of class `ClassName`
  1255. -- or nil if it couldn't find any
  1256.  
  1257. -- Look for a child of `Parent` of class `ClassName` and return it
  1258. if not Inherit then
  1259. for _, Child in pairs(Parent:GetChildren()) do
  1260. if Child.ClassName == ClassName then
  1261. return Child;
  1262. end;
  1263. end;
  1264. else
  1265. for _, Child in pairs(Parent:GetChildren()) do
  1266. if Child:IsA(ClassName) then
  1267. return Child;
  1268. end;
  1269. end;
  1270. end;
  1271.  
  1272. return nil;
  1273. end;
  1274.  
  1275. function SupportLibrary.GetChildrenOfClass(Parent, ClassName, Inherit)
  1276. -- Returns a table containing the children of `Parent` that are
  1277. -- of class `ClassName`
  1278.  
  1279. local Matches = {};
  1280.  
  1281. if not Inherit then
  1282. for _, Child in pairs(Parent:GetChildren()) do
  1283. if Child.ClassName == ClassName then
  1284. table.insert(Matches, Child);
  1285. end;
  1286. end;
  1287. else
  1288. for _, Child in pairs(Parent:GetChildren()) do
  1289. if Child:IsA(ClassName) then
  1290. table.insert(Matches, Child);
  1291. end;
  1292. end;
  1293. end;
  1294.  
  1295. return Matches;
  1296. end;
  1297.  
  1298. function SupportLibrary.HSVToRGB(Hue, Saturation, Value)
  1299. -- Returns the RGB equivalent of the given HSV-defined color
  1300. -- (adapted from some code found around the web)
  1301.  
  1302. -- If it's achromatic, just return the value
  1303. if Saturation == 0 then
  1304. return Value;
  1305. end;
  1306.  
  1307. -- Get the hue sector
  1308. local HueSector = math.floor(Hue / 60);
  1309. local HueSectorOffset = (Hue / 60) - HueSector;
  1310.  
  1311. local P = Value * (1 - Saturation);
  1312. local Q = Value * (1 - Saturation * HueSectorOffset);
  1313. local T = Value * (1 - Saturation * (1 - HueSectorOffset));
  1314.  
  1315. if HueSector == 0 then
  1316. return Value, T, P;
  1317. elseif HueSector == 1 then
  1318. return Q, Value, P;
  1319. elseif HueSector == 2 then
  1320. return P, Value, T;
  1321. elseif HueSector == 3 then
  1322. return P, Q, Value;
  1323. elseif HueSector == 4 then
  1324. return T, P, Value;
  1325. elseif HueSector == 5 then
  1326. return Value, P, Q;
  1327. end;
  1328. end;
  1329.  
  1330. function SupportLibrary.RGBToHSV(Red, Green, Blue)
  1331. -- Returns the HSV equivalent of the given RGB-defined color
  1332. -- (adapted from some code found around the web)
  1333.  
  1334. local Hue, Saturation, Value;
  1335.  
  1336. local MinValue = math.min(Red, Green, Blue);
  1337. local MaxValue = math.max(Red, Green, Blue);
  1338.  
  1339. Value = MaxValue;
  1340.  
  1341. local ValueDelta = MaxValue - MinValue;
  1342.  
  1343. -- If the color is not black
  1344. if MaxValue ~= 0 then
  1345. Saturation = ValueDelta / MaxValue;
  1346.  
  1347. -- If the color is purely black
  1348. else
  1349. Saturation = 0;
  1350. Hue = -1;
  1351. return Hue, Saturation, Value;
  1352. end;
  1353.  
  1354. if Red == MaxValue then
  1355. Hue = (Green - Blue) / ValueDelta;
  1356. elseif Green == MaxValue then
  1357. Hue = 2 + (Blue - Red) / ValueDelta;
  1358. else
  1359. Hue = 4 + (Red - Green) / ValueDelta;
  1360. end;
  1361.  
  1362. Hue = Hue * 60;
  1363. if Hue < 0 then
  1364. Hue = Hue + 360;
  1365. end;
  1366.  
  1367. return Hue, Saturation, Value;
  1368. end;
  1369.  
  1370. function SupportLibrary.IdentifyCommonItem(Items)
  1371. -- Returns the common item in table `Items`, or `nil` if
  1372. -- they vary
  1373.  
  1374. local CommonItem = nil;
  1375.  
  1376. for ItemIndex, Item in pairs(Items) do
  1377.  
  1378. -- Set the initial item to compare against
  1379. if ItemIndex == 1 then
  1380. CommonItem = Item;
  1381.  
  1382. -- Check if this item is the same as the rest
  1383. else
  1384. -- If it isn't the same, there is no common item, so just stop right here
  1385. if Item ~= CommonItem then
  1386. return nil;
  1387. end;
  1388. end;
  1389.  
  1390. end;
  1391.  
  1392. -- Return the common item
  1393. return CommonItem;
  1394. end;
  1395.  
  1396. function SupportLibrary.IdentifyCommonProperty(Items, Property)
  1397. -- Returns the common `Property` value in the instances given in `Items`
  1398.  
  1399. local PropertyVariations = {};
  1400.  
  1401. -- Capture all the variations of the property value
  1402. for _, Item in pairs(Items) do
  1403. table.insert(PropertyVariations, Item[Property]);
  1404. end;
  1405.  
  1406. -- Return the common property value
  1407. return SupportLibrary.IdentifyCommonItem(PropertyVariations);
  1408.  
  1409. end;
  1410.  
  1411. function SupportLibrary.CreateSignal()
  1412. -- Returns a ROBLOX-like signal for connections (RbxUtility's is buggy)
  1413.  
  1414. local Signal = {
  1415. Connections = {};
  1416.  
  1417. -- Provide a function to connect an event handler
  1418. Connect = function (Signal, Handler)
  1419.  
  1420. -- Register the handler
  1421. table.insert(Signal.Connections, Handler);
  1422.  
  1423. -- Return a controller for this connection
  1424. local ConnectionController = {
  1425.  
  1426. -- Include a reference to the connection's handler
  1427. Handler = Handler;
  1428.  
  1429. -- Provide a way to disconnect this connection
  1430. Disconnect = function (Connection)
  1431. local ConnectionSearch = SupportLibrary.FindTableOccurrences(Signal.Connections, Connection.Handler);
  1432. if #ConnectionSearch > 0 then
  1433. local ConnectionIndex = ConnectionSearch[1];
  1434. table.remove(Signal.Connections, ConnectionIndex);
  1435. end;
  1436. end;
  1437.  
  1438. };
  1439.  
  1440. -- Add compatibility aliases
  1441. ConnectionController.disconnect = ConnectionController.Disconnect;
  1442.  
  1443. -- Return the connection's controller
  1444. return ConnectionController;
  1445.  
  1446. end;
  1447.  
  1448. -- Provide a function to trigger any connections' handlers
  1449. Fire = function (Signal, ...)
  1450. for _, Connection in pairs(Signal.Connections) do
  1451. Connection(...);
  1452. end;
  1453. end;
  1454. };
  1455.  
  1456. -- Add compatibility aliases
  1457. Signal.connect = Signal.Connect;
  1458. Signal.fire = Signal.Fire;
  1459.  
  1460. return Signal;
  1461. end;
  1462.  
  1463. function SupportLibrary.GetPartCorners(Part)
  1464. -- Returns a table of the given part's corners' CFrames
  1465.  
  1466. -- Make references to functions called a lot for efficiency
  1467. local Insert = table.insert;
  1468. local ToWorldSpace = CFrame.new().toWorldSpace;
  1469. local NewCFrame = CFrame.new;
  1470.  
  1471. -- Get info about the part
  1472. local PartCFrame = Part.CFrame;
  1473. local SizeX, SizeY, SizeZ = Part.Size.x / 2, Part.Size.y / 2, Part.Size.z / 2;
  1474.  
  1475. -- Get each corner
  1476. local Corners = {};
  1477. Insert(Corners, ToWorldSpace(PartCFrame, NewCFrame(SizeX, SizeY, SizeZ)));
  1478. Insert(Corners, ToWorldSpace(PartCFrame, NewCFrame(-SizeX, SizeY, SizeZ)));
  1479. Insert(Corners, ToWorldSpace(PartCFrame, NewCFrame(SizeX, -SizeY, SizeZ)));
  1480. Insert(Corners, ToWorldSpace(PartCFrame, NewCFrame(SizeX, SizeY, -SizeZ)));
  1481. Insert(Corners, ToWorldSpace(PartCFrame, NewCFrame(-SizeX, SizeY, -SizeZ)));
  1482. Insert(Corners, ToWorldSpace(PartCFrame, NewCFrame(-SizeX, -SizeY, SizeZ)));
  1483. Insert(Corners, ToWorldSpace(PartCFrame, NewCFrame(SizeX, -SizeY, -SizeZ)));
  1484. Insert(Corners, ToWorldSpace(PartCFrame, NewCFrame(-SizeX, -SizeY, -SizeZ)));
  1485.  
  1486. return Corners;
  1487. end;
  1488.  
  1489. function SupportLibrary.CreatePart(PartType)
  1490. -- Creates and returns new part based on `PartType` with sensible defaults
  1491.  
  1492. local NewPart;
  1493.  
  1494. if PartType == 'Normal' then
  1495. NewPart = Instance.new('Part');
  1496. NewPart.Size = Vector3.new(4, 1, 2);
  1497.  
  1498. elseif PartType == 'Truss' then
  1499. NewPart = Instance.new('TrussPart');
  1500.  
  1501. elseif PartType == 'Wedge' then
  1502. NewPart = Instance.new('WedgePart');
  1503. NewPart.Size = Vector3.new(4, 1, 2);
  1504.  
  1505. elseif PartType == 'Corner' then
  1506. NewPart = Instance.new('CornerWedgePart');
  1507.  
  1508. elseif PartType == 'Cylinder' then
  1509. NewPart = Instance.new('Part');
  1510. NewPart.Shape = 'Cylinder';
  1511. NewPart.TopSurface = Enum.SurfaceType.Smooth;
  1512. NewPart.BottomSurface = Enum.SurfaceType.Smooth;
  1513. NewPart.Size = Vector3.new(2, 2, 2);
  1514.  
  1515. elseif PartType == 'Ball' then
  1516. NewPart = Instance.new('Part');
  1517. NewPart.Shape = 'Ball';
  1518. NewPart.TopSurface = Enum.SurfaceType.Smooth;
  1519. NewPart.BottomSurface = Enum.SurfaceType.Smooth;
  1520.  
  1521. elseif PartType == 'Seat' then
  1522. NewPart = Instance.new('Seat');
  1523. NewPart.Size = Vector3.new(4, 1, 2);
  1524.  
  1525. elseif PartType == 'Vehicle Seat' then
  1526. NewPart = Instance.new('VehicleSeat');
  1527. NewPart.Size = Vector3.new(4, 1, 2);
  1528.  
  1529. elseif PartType == 'Spawn' then
  1530. NewPart = Instance.new('SpawnLocation');
  1531. NewPart.Size = Vector3.new(4, 1, 2);
  1532. end;
  1533.  
  1534. -- Make sure the part is anchored
  1535. NewPart.Anchored = true;
  1536.  
  1537. return NewPart;
  1538. end;
  1539.  
  1540. function SupportLibrary.ImportServices()
  1541. -- Adds references to common services into the calling environment
  1542.  
  1543. -- Get the calling environment
  1544. local CallingEnvironment = getfenv(2);
  1545.  
  1546. -- Add the services
  1547. CallingEnvironment.Workspace = Game:GetService 'Workspace';
  1548. CallingEnvironment.Players = Game:GetService 'Players';
  1549. CallingEnvironment.MarketplaceService = Game:GetService 'MarketplaceService';
  1550. CallingEnvironment.ContentProvider = Game:GetService 'ContentProvider';
  1551. CallingEnvironment.SoundService = Game:GetService 'SoundService';
  1552. CallingEnvironment.UserInputService = Game:GetService 'UserInputService';
  1553. CallingEnvironment.SelectionService = Game:GetService 'Selection';
  1554. CallingEnvironment.CoreGui = Game:GetService 'CoreGui';
  1555. CallingEnvironment.HttpService = Game:GetService 'HttpService';
  1556. CallingEnvironment.ChangeHistoryService = Game:GetService 'ChangeHistoryService';
  1557. CallingEnvironment.ReplicatedStorage = Game:GetService 'ReplicatedStorage';
  1558. CallingEnvironment.GroupService = Game:GetService 'GroupService';
  1559. CallingEnvironment.ServerScriptService = Game:GetService 'ServerScriptService';
  1560. CallingEnvironment.ServerStorage = Game:GetService 'ServerStorage';
  1561. CallingEnvironment.StarterGui = Game:GetService 'StarterGui';
  1562. CallingEnvironment.RunService = Game:GetService 'RunService';
  1563. end;
  1564.  
  1565. function SupportLibrary.GetListMembers(List, MemberName)
  1566. -- Gets the given member for each object in the given list table
  1567.  
  1568. local Members = {};
  1569.  
  1570. -- Collect the member values for each item in the list
  1571. for _, Item in pairs(List) do
  1572. table.insert(Members, Item[MemberName]);
  1573. end;
  1574.  
  1575. -- Return the members
  1576. return Members;
  1577.  
  1578. end;
  1579.  
  1580. function SupportLibrary.AddUserInputListener(InputState, InputType, CatchAll, Callback)
  1581. -- Connects to the given user input event and takes care of standard boilerplate code
  1582.  
  1583. -- Turn the given `InputType` string into a proper enum
  1584. local InputType = Enum.UserInputType[InputType];
  1585.  
  1586. -- Create a UserInputService listener based on the given `InputState`
  1587. return Game:GetService('UserInputService')['Input' .. InputState]:connect(function (Input, GameProcessedEvent)
  1588.  
  1589. -- Make sure this input was not captured by the client (unless `CatchAll` is enabled)
  1590. if GameProcessedEvent and not CatchAll then
  1591. return;
  1592. end;
  1593.  
  1594. -- Make sure this is the right input type
  1595. if Input.UserInputType ~= InputType then
  1596. return;
  1597. end;
  1598.  
  1599. -- Make sure any key input did not occur while typing into a UI
  1600. if InputType == Enum.UserInputType.Keyboard and Game:GetService('UserInputService'):GetFocusedTextBox() then
  1601. return;
  1602. end;
  1603.  
  1604. -- Call back upon passing all conditions
  1605. Callback(Input);
  1606.  
  1607. end);
  1608.  
  1609. end;
  1610.  
  1611. function SupportLibrary.AddGuiInputListener(Gui, InputState, InputType, CatchAll, Callback)
  1612. -- Connects to the given GUI user input event and takes care of standard boilerplate code
  1613.  
  1614. -- Turn the given `InputType` string into a proper enum
  1615. local InputType = Enum.UserInputType[InputType];
  1616.  
  1617. -- Create a UserInputService listener based on the given `InputState`
  1618. return Gui['Input' .. InputState]:connect(function (Input, GameProcessedEvent)
  1619.  
  1620. -- Make sure this input was not captured by the client (unless `CatchAll` is enabled)
  1621. if GameProcessedEvent and not CatchAll then
  1622. return;
  1623. end;
  1624.  
  1625. -- Make sure this is the right input type
  1626. if Input.UserInputType ~= InputType then
  1627. return;
  1628. end;
  1629.  
  1630. -- Call back upon passing all conditions
  1631. Callback(Input);
  1632.  
  1633. end);
  1634.  
  1635. end;
  1636.  
  1637. function SupportLibrary.AreKeysPressed(...)
  1638. -- Returns whether the given keys are pressed
  1639.  
  1640. local RequestedKeysPressed = 0;
  1641.  
  1642. -- Get currently pressed keys
  1643. local PressedKeys = SupportLibrary.GetListMembers(Game:GetService('UserInputService'):GetKeysPressed(), 'KeyCode');
  1644.  
  1645. -- Go through each requested key
  1646. for _, Key in pairs({ ... }) do
  1647.  
  1648. -- Count requested keys that are pressed
  1649. if SupportLibrary.IsInTable(PressedKeys, Key) then
  1650. RequestedKeysPressed = RequestedKeysPressed + 1;
  1651. end;
  1652.  
  1653. end;
  1654.  
  1655. -- Return whether all the requested keys are pressed or not
  1656. return RequestedKeysPressed == #{...};
  1657.  
  1658. end;
  1659.  
  1660. function SupportLibrary.ConcatTable(DestinationTable, SourceTable)
  1661. -- Inserts all values of SourceTable into DestinationTable
  1662.  
  1663. -- Add each value from `SourceTable` into `DestinationTable`
  1664. for _, Value in ipairs(SourceTable) do
  1665. table.insert(DestinationTable, Value);
  1666. end;
  1667.  
  1668. -- Return the destination table
  1669. return DestinationTable;
  1670. end;
  1671.  
  1672. function SupportLibrary.ClearTable(Table)
  1673. -- Clears out every value in `Table`
  1674.  
  1675. -- Clear each index
  1676. for Index in pairs(Table) do
  1677. Table[Index] = nil;
  1678. end;
  1679.  
  1680. -- Return the given table
  1681. return Table;
  1682. end;
  1683.  
  1684. function SupportLibrary.Values(Table)
  1685. -- Returns all the values in the given table
  1686.  
  1687. local Values = {};
  1688.  
  1689. -- Go through each key and get each value
  1690. for _, Value in pairs(Table) do
  1691. table.insert(Values, Value);
  1692. end;
  1693.  
  1694. -- Return the values
  1695. return Values;
  1696. end;
  1697.  
  1698. function SupportLibrary.Keys(Table)
  1699. -- Returns all the keys in the given table
  1700.  
  1701. local Keys = {};
  1702.  
  1703. -- Go through each key and get each value
  1704. for Key in pairs(Table) do
  1705. table.insert(Keys, Key);
  1706. end;
  1707.  
  1708. -- Return the values
  1709. return Keys;
  1710. end;
  1711.  
  1712. function SupportLibrary.Call(Function, ...)
  1713. -- Returns a callback to `Function` with the given arguments
  1714. local Args = { ... };
  1715. return function (...)
  1716. return Function(unpack(
  1717. SupportLibrary.ConcatTable(SupportLibrary.CloneTable(Args), { ... })
  1718. ));
  1719. end;
  1720. end;
  1721.  
  1722. function SupportLibrary.Trim(String)
  1723. -- Returns a trimmed version of `String` (adapted from code from lua-users)
  1724. return (String:gsub("^%s*(.-)%s*$", "%1"));
  1725. end
  1726.  
  1727. function SupportLibrary.ChainCall(...)
  1728. -- Returns function that passes arguments through given functions and returns the final result
  1729.  
  1730. -- Get the given chain of functions
  1731. local Chain = { ... };
  1732.  
  1733. -- Return the chaining function
  1734. return function (...)
  1735.  
  1736. -- Get arguments
  1737. local Arguments = { ... };
  1738.  
  1739. -- Go through each function and store the returned data to reuse in the next function's arguments
  1740. for _, Function in ipairs(Chain) do
  1741. Arguments = { Function(unpack(Arguments)) };
  1742. end;
  1743.  
  1744. -- Return the final returned data
  1745. return unpack(Arguments);
  1746.  
  1747. end;
  1748.  
  1749. end;
  1750.  
  1751. function SupportLibrary.CountKeys(Table)
  1752. -- Returns the number of keys in `Table`
  1753.  
  1754. local Count = 0;
  1755.  
  1756. -- Count each key
  1757. for _ in pairs(Table) do
  1758. Count = Count + 1;
  1759. end;
  1760.  
  1761. -- Return the count
  1762. return Count;
  1763.  
  1764. end;
  1765.  
  1766. function SupportLibrary.Slice(Table, Start, End)
  1767. -- Returns values from `Start` to `End` in `Table`
  1768.  
  1769. local Slice = {};
  1770.  
  1771. -- Go through the given indices
  1772. for Index = Start, End do
  1773. table.insert(Slice, Table[Index]);
  1774. end;
  1775.  
  1776. -- Return the slice
  1777. return Slice;
  1778.  
  1779. end;
  1780.  
  1781. function SupportLibrary.FlipTable(Table)
  1782. -- Returns a table with keys and values in `Table` swapped
  1783.  
  1784. local FlippedTable = {};
  1785.  
  1786. -- Flip each key and value
  1787. for Key, Value in pairs(Table) do
  1788. FlippedTable[Value] = Key;
  1789. end;
  1790.  
  1791. -- Return the flipped table
  1792. return FlippedTable;
  1793.  
  1794. end;
  1795.  
  1796. function SupportLibrary.ScheduleRecurringTask(TaskFunction, Interval)
  1797. -- Repeats `Task` every `Interval` seconds until stopped
  1798.  
  1799. -- Create a task object
  1800. local Task = {
  1801.  
  1802. -- A switch determining if it's running or not
  1803. Running = true;
  1804.  
  1805. -- A function to stop this task
  1806. Stop = function (Task)
  1807. Task.Running = false;
  1808. end;
  1809.  
  1810. -- References to the task function and set interval
  1811. TaskFunction = TaskFunction;
  1812. Interval = Interval;
  1813.  
  1814. };
  1815.  
  1816. coroutine.wrap(function (Task)
  1817.  
  1818. -- Repeat the task
  1819. while wait(Task.Interval) and Task.Running do
  1820. Task.TaskFunction();
  1821. end;
  1822.  
  1823. end)(Task);
  1824.  
  1825. -- Return the task object
  1826. return Task;
  1827.  
  1828. end;
  1829.  
  1830. function SupportLibrary.Clamp(Number, Minimum, Maximum)
  1831. -- Returns the given number, clamped according to the provided min/max
  1832.  
  1833. -- Clamp the number
  1834. if Minimum and Number < Minimum then
  1835. Number = Minimum;
  1836. elseif Maximum and Number > Maximum then
  1837. Number = Maximum;
  1838. end;
  1839.  
  1840. -- Return the clamped number
  1841. return Number;
  1842.  
  1843. end;
  1844.  
  1845. function SupportLibrary.ReverseTable(Table)
  1846. -- Returns a new table with values in the opposite order
  1847.  
  1848. local ReversedTable = {};
  1849.  
  1850. -- Copy each value at the opposite key
  1851. for Index, Value in ipairs(Table) do
  1852. ReversedTable[#Table - Index + 1] = Value;
  1853. end;
  1854.  
  1855. -- Return the reversed table
  1856. return ReversedTable;
  1857.  
  1858. end;
  1859.  
  1860. return SupportLibrary;]]></ProtectedString>
  1861. </Properties>
  1862. </Item>
  1863. <Item class="ModuleScript" referent="RBXF8091488FF32432C99021E3C16DA36CB">
  1864. <Properties>
  1865. <Content name="LinkedSource"><null></null></Content>
  1866. <string name="Name">SerializationModule3</string>
  1867. <string name="ScriptGuid">{4BA70DF3-3280-41FA-A236-E3606FBDDA4B}</string>
  1868. <ProtectedString name="Source"><![CDATA[Serialization = {};
  1869.  
  1870. -- Import services
  1871. Support = require(script.Parent.SupportLibrary);
  1872. Support.ImportServices();
  1873.  
  1874. local Types = {
  1875. Part = 0,
  1876. WedgePart = 1,
  1877. CornerWedgePart = 2,
  1878. VehicleSeat = 3,
  1879. Seat = 4,
  1880. TrussPart = 5,
  1881. SpecialMesh = 6,
  1882. Texture = 7,
  1883. Decal = 8,
  1884. PointLight = 9,
  1885. SpotLight = 10,
  1886. SurfaceLight = 11,
  1887. Smoke = 12,
  1888. Fire = 13,
  1889. Sparkles = 14,
  1890. Model = 15
  1891. };
  1892.  
  1893. local DefaultNames = {
  1894. Part = 'Part',
  1895. WedgePart = 'Wedge',
  1896. CornerWedgePart = 'CornerWedge',
  1897. VehicleSeat = 'VehicleSeat',
  1898. Seat = 'Seat',
  1899. TrussPart = 'Truss',
  1900. SpecialMesh = 'Mesh',
  1901. Texture = 'Texture',
  1902. Decal = 'Decal',
  1903. PointLight = 'PointLight',
  1904. SpotLight = 'SpotLight',
  1905. SurfaceLight = 'SurfaceLight',
  1906. Smoke = 'Smoke',
  1907. Fire = 'Fire',
  1908. Sparkles = 'Sparkles',
  1909. Model = 'Model'
  1910. };
  1911.  
  1912. function Serialization.SerializeModel(Items)
  1913. -- Returns a serialized version of the given model
  1914.  
  1915. -- Filter out non-serializable items in `Items`
  1916. local SerializableItems = {};
  1917. for Index, Item in ipairs(Items) do
  1918. table.insert(SerializableItems, Types[Item.ClassName] and Item or nil);
  1919. end;
  1920. Items = SerializableItems;
  1921.  
  1922. -- Get a snapshot of the content
  1923. local Keys = Support.FlipTable(Items);
  1924.  
  1925. local Data = {};
  1926. Data.Version = 3;
  1927. Data.Items = {};
  1928.  
  1929. -- Serialize each item in the model
  1930. for Index, Item in pairs(Items) do
  1931.  
  1932. if Item:IsA 'BasePart' then
  1933. local Datum = {};
  1934. Datum[1] = Types[Item.ClassName];
  1935. Datum[2] = Keys[Item.Parent] or 0;
  1936. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  1937. Datum[4] = Item.Size.X;
  1938. Datum[5] = Item.Size.Y;
  1939. Datum[6] = Item.Size.Z;
  1940. Support.ConcatTable(Datum, { Item.CFrame:components() });
  1941. Datum[19] = Item.Color.r;
  1942. Datum[20] = Item.Color.g;
  1943. Datum[21] = Item.Color.b;
  1944. Datum[22] = Item.Material.Value;
  1945. Datum[23] = Item.Anchored and 1 or 0;
  1946. Datum[24] = Item.CanCollide and 1 or 0;
  1947. Datum[25] = Item.Reflectance;
  1948. Datum[26] = Item.Transparency;
  1949. Datum[27] = Item.TopSurface.Value;
  1950. Datum[28] = Item.BottomSurface.Value;
  1951. Datum[29] = Item.FrontSurface.Value;
  1952. Datum[30] = Item.BackSurface.Value;
  1953. Datum[31] = Item.LeftSurface.Value;
  1954. Datum[32] = Item.RightSurface.Value;
  1955. Data.Items[Index] = Datum;
  1956. end;
  1957.  
  1958. if Item.ClassName == 'Part' then
  1959. local Datum = Data.Items[Index];
  1960. Datum[33] = Item.Shape.Value;
  1961. end;
  1962.  
  1963. if Item.ClassName == 'VehicleSeat' then
  1964. local Datum = Data.Items[Index];
  1965. Datum[33] = Item.MaxSpeed;
  1966. Datum[34] = Item.Torque;
  1967. Datum[35] = Item.TurnSpeed;
  1968. end;
  1969.  
  1970. if Item.ClassName == 'TrussPart' then
  1971. local Datum = Data.Items[Index];
  1972. Datum[33] = Item.Style.Value;
  1973. end;
  1974.  
  1975. if Item.ClassName == 'SpecialMesh' then
  1976. local Datum = {};
  1977. Datum[1] = Types[Item.ClassName];
  1978. Datum[2] = Keys[Item.Parent] or 0;
  1979. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  1980. Datum[4] = Item.MeshType.Value;
  1981. Datum[5] = Item.MeshId;
  1982. Datum[6] = Item.TextureId;
  1983. Datum[7] = Item.Offset.X;
  1984. Datum[8] = Item.Offset.Y;
  1985. Datum[9] = Item.Offset.Z;
  1986. Datum[10] = Item.Scale.X;
  1987. Datum[11] = Item.Scale.Y;
  1988. Datum[12] = Item.Scale.Z;
  1989. Datum[13] = Item.VertexColor.X;
  1990. Datum[14] = Item.VertexColor.Y;
  1991. Datum[15] = Item.VertexColor.Z;
  1992. Data.Items[Index] = Datum;
  1993. end;
  1994.  
  1995. if Item:IsA 'Decal' then
  1996. local Datum = {};
  1997. Datum[1] = Types[Item.ClassName];
  1998. Datum[2] = Keys[Item.Parent] or 0;
  1999. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  2000. Datum[4] = Item.Texture;
  2001. Datum[5] = Item.Transparency;
  2002. Datum[6] = Item.Face.Value;
  2003. Data.Items[Index] = Datum;
  2004. end;
  2005.  
  2006. if Item.ClassName == 'Texture' then
  2007. local Datum = Data.Items[Index];
  2008. Datum[7] = Item.StudsPerTileU;
  2009. Datum[8] = Item.StudsPerTileV;
  2010. end;
  2011.  
  2012. if Item:IsA 'Light' then
  2013. local Datum = {};
  2014. Datum[1] = Types[Item.ClassName];
  2015. Datum[2] = Keys[Item.Parent] or 0;
  2016. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  2017. Datum[4] = Item.Brightness;
  2018. Datum[5] = Item.Color.r;
  2019. Datum[6] = Item.Color.g;
  2020. Datum[7] = Item.Color.b;
  2021. Datum[8] = Item.Enabled and 1 or 0;
  2022. Datum[9] = Item.Shadows and 1 or 0;
  2023. Data.Items[Index] = Datum;
  2024. end;
  2025.  
  2026. if Item.ClassName == 'PointLight' then
  2027. local Datum = Data.Items[Index];
  2028. Datum[10] = Item.Range;
  2029. end;
  2030.  
  2031. if Item.ClassName == 'SpotLight' then
  2032. local Datum = Data.Items[Index];
  2033. Datum[10] = Item.Range;
  2034. Datum[11] = Item.Angle;
  2035. Datum[12] = Item.Face.Value;
  2036. end;
  2037.  
  2038. if Item.ClassName == 'SurfaceLight' then
  2039. local Datum = Data.Items[Index];
  2040. Datum[10] = Item.Range;
  2041. Datum[11] = Item.Angle;
  2042. Datum[12] = Item.Face.Value;
  2043. end;
  2044.  
  2045. if Item.ClassName == 'Smoke' then
  2046. local Datum = {};
  2047. Datum[1] = Types[Item.ClassName];
  2048. Datum[2] = Keys[Item.Parent] or 0;
  2049. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  2050. Datum[4] = Item.Enabled and 1 or 0;
  2051. Datum[5] = Item.Color.r;
  2052. Datum[6] = Item.Color.g;
  2053. Datum[7] = Item.Color.b;
  2054. Datum[8] = Item.Size;
  2055. Datum[9] = Item.RiseVelocity;
  2056. Datum[10] = Item.Opacity;
  2057. Data.Items[Index] = Datum;
  2058. end;
  2059.  
  2060. if Item.ClassName == 'Fire' then
  2061. local Datum = {};
  2062. Datum[1] = Types[Item.ClassName];
  2063. Datum[2] = Keys[Item.Parent] or 0;
  2064. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  2065. Datum[4] = Item.Enabled and 1 or 0;
  2066. Datum[5] = Item.Color.r;
  2067. Datum[6] = Item.Color.g;
  2068. Datum[7] = Item.Color.b;
  2069. Datum[8] = Item.SecondaryColor.r;
  2070. Datum[9] = Item.SecondaryColor.g;
  2071. Datum[10] = Item.SecondaryColor.b;
  2072. Datum[11] = Item.Heat;
  2073. Datum[12] = Item.Size;
  2074. Data.Items[Index] = Datum;
  2075. end;
  2076.  
  2077. if Item.ClassName == 'Sparkles' then
  2078. local Datum = {};
  2079. Datum[1] = Types[Item.ClassName];
  2080. Datum[2] = Keys[Item.Parent] or 0;
  2081. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  2082. Datum[4] = Item.Enabled and 1 or 0;
  2083. Datum[5] = Item.SparkleColor.r;
  2084. Datum[6] = Item.SparkleColor.g;
  2085. Datum[7] = Item.SparkleColor.b;
  2086. Data.Items[Index] = Datum;
  2087. end;
  2088.  
  2089. if Item.ClassName == 'Model' then
  2090. local Datum = {};
  2091. Datum[1] = Types[Item.ClassName];
  2092. Datum[2] = Keys[Item.Parent] or 0;
  2093. Datum[3] = Item.Name == DefaultNames[Item.ClassName] and '' or Item.Name;
  2094. Datum[4] = Item.PrimaryPart and Keys[Item.PrimaryPart] or 0;
  2095. Data.Items[Index] = Datum;
  2096. end;
  2097.  
  2098. -- Spread the workload over time to avoid locking up the CPU
  2099. if Index % 100 == 0 then
  2100. wait(0.01);
  2101. end;
  2102.  
  2103. end;
  2104.  
  2105. -- Return the serialized data
  2106. return HttpService:JSONEncode(Data);
  2107.  
  2108. end;
  2109.  
  2110. function Serialization.InflateBuildData(Data)
  2111. -- Returns an inflated version of the given build data
  2112.  
  2113. local Build = {};
  2114. local Instances = {};
  2115.  
  2116. -- Create each instance
  2117. for Index, Datum in ipairs(Data.Items) do
  2118.  
  2119. -- Inflate BaseParts
  2120. if Datum[1] == Types.Part
  2121. or Datum[1] == Types.WedgePart
  2122. or Datum[1] == Types.CornerWedgePart
  2123. or Datum[1] == Types.VehicleSeat
  2124. or Datum[1] == Types.Seat
  2125. or Datum[1] == Types.TrussPart
  2126. then
  2127. local Item = Instance.new(Support.FindTableOccurrence(Types, Datum[1]));
  2128. Item.Size = Vector3.new(unpack(Support.Slice(Datum, 4, 6)));
  2129. Item.CFrame = CFrame.new(unpack(Support.Slice(Datum, 7, 18)));
  2130. Item.Color = Color3.new(Datum[19], Datum[20], Datum[21]);
  2131. Item.Material = Datum[22];
  2132. Item.Anchored = Datum[23] == 1;
  2133. Item.CanCollide = Datum[24] == 1;
  2134. Item.Reflectance = Datum[25];
  2135. Item.Transparency = Datum[26];
  2136. Item.TopSurface = Datum[27];
  2137. Item.BottomSurface = Datum[28];
  2138. Item.FrontSurface = Datum[29];
  2139. Item.BackSurface = Datum[30];
  2140. Item.LeftSurface = Datum[31];
  2141. Item.RightSurface = Datum[32];
  2142.  
  2143. -- Register the part
  2144. Instances[Index] = Item;
  2145. end;
  2146.  
  2147. -- Inflate specific Part properties
  2148. if Datum[1] == Types.Part then
  2149. local Item = Instances[Index];
  2150. Item.Shape = Datum[33];
  2151. end;
  2152.  
  2153. -- Inflate specific VehicleSeat properties
  2154. if Datum[1] == Types.VehicleSeat then
  2155. local Item = Instances[Index];
  2156. Item.MaxSpeed = Datum[33];
  2157. Item.Torque = Datum[34];
  2158. Item.TurnSpeed = Datum[35];
  2159. end;
  2160.  
  2161. -- Inflate specific TrussPart properties
  2162. if Datum[1] == Types.TrussPart then
  2163. local Item = Instances[Index];
  2164. Item.Style = Datum[33];
  2165. end;
  2166.  
  2167. -- Inflate SpecialMesh instances
  2168. if Datum[1] == Types.SpecialMesh then
  2169. local Item = Instance.new('SpecialMesh');
  2170. Item.MeshType = Datum[4];
  2171. Item.MeshId = Datum[5];
  2172. Item.TextureId = Datum[6];
  2173. Item.Offset = Vector3.new(unpack(Support.Slice(Datum, 7, 9)));
  2174. Item.Scale = Vector3.new(unpack(Support.Slice(Datum, 10, 12)));
  2175. Item.VertexColor = Vector3.new(unpack(Support.Slice(Datum, 13, 15)));
  2176.  
  2177. -- Register the mesh
  2178. Instances[Index] = Item;
  2179. end;
  2180.  
  2181. -- Inflate Decal instances
  2182. if Datum[1] == Types.Decal or Datum[1] == Types.Texture then
  2183. local Item = Instance.new(Support.FindTableOccurrence(Types, Datum[1]));
  2184. Item.Texture = Datum[4];
  2185. Item.Transparency = Datum[5];
  2186. Item.Face = Datum[6];
  2187.  
  2188. -- Register the Decal
  2189. Instances[Index] = Item;
  2190. end;
  2191.  
  2192. -- Inflate specific Texture properties
  2193. if Datum[1] == Types.Texture then
  2194. local Item = Instances[Index];
  2195. Item.StudsPerTileU = Datum[7];
  2196. Item.StudsPerTileV = Datum[8];
  2197. end;
  2198.  
  2199. -- Inflate Light instances
  2200. if Datum[1] == Types.PointLight
  2201. or Datum[1] == Types.SpotLight
  2202. or Datum[1] == Types.SurfaceLight
  2203. then
  2204. local Item = Instance.new(Support.FindTableOccurrence(Types, Datum[1]));
  2205. Item.Brightness = Datum[4];
  2206. Item.Color = Color3.new(unpack(Support.Slice(Datum, 5, 7)));
  2207. Item.Enabled = Datum[8] == 1;
  2208. Item.Shadows = Datum[9] == 1;
  2209.  
  2210. -- Register the light
  2211. Instances[Index] = Item;
  2212. end;
  2213.  
  2214. -- Inflate specific PointLight properties
  2215. if Datum[1] == Types.PointLight then
  2216. local Item = Instances[Index];
  2217. Item.Range = Datum[10];
  2218. end;
  2219.  
  2220. -- Inflate specific SpotLight properties
  2221. if Datum[1] == Types.SpotLight then
  2222. local Item = Instances[Index];
  2223. Item.Range = Datum[10];
  2224. Item.Angle = Datum[11];
  2225. Item.Face = Datum[12];
  2226. end;
  2227.  
  2228. -- Inflate specific SurfaceLight properties
  2229. if Datum[1] == Types.SurfaceLight then
  2230. local Item = Instances[Index];
  2231. Item.Range = Datum[10];
  2232. Item.Angle = Datum[11];
  2233. Item.Face = Datum[12];
  2234. end;
  2235.  
  2236. -- Inflate Smoke instances
  2237. if Datum[1] == Types.Smoke then
  2238. local Item = Instance.new('Smoke');
  2239. Item.Enabled = Datum[4] == 1;
  2240. Item.Color = Color3.new(unpack(Support.Slice(Datum, 5, 7)));
  2241. Item.Size = Datum[8];
  2242. Item.RiseVelocity = Datum[9];
  2243. Item.Opacity = Datum[10];
  2244.  
  2245. -- Register the smoke
  2246. Instances[Index] = Item;
  2247. end;
  2248.  
  2249. -- Inflate Fire instances
  2250. if Datum[1] == Types.Fire then
  2251. local Item = Instance.new('Fire');
  2252. Item.Enabled = Datum[4] == 1;
  2253. Item.Color = Color3.new(unpack(Support.Slice(Datum, 5, 7)));
  2254. Item.SecondaryColor = Color3.new(unpack(Support.Slice(Datum, 8, 10)));
  2255. Item.Heat = Datum[11];
  2256. Item.Size = Datum[12];
  2257.  
  2258. -- Register the fire
  2259. Instances[Index] = Item;
  2260. end;
  2261.  
  2262. -- Inflate Sparkles instances
  2263. if Datum[1] == Types.Sparkles then
  2264. local Item = Instance.new('Sparkles');
  2265. Item.Enabled = Datum[4] == 1;
  2266. Item.SparkleColor = Color3.new(unpack(Support.Slice(Datum, 5, 7)));
  2267.  
  2268. -- Register the instance
  2269. Instances[Index] = Item;
  2270. end;
  2271.  
  2272. -- Inflate Model instances
  2273. if Datum[1] == Types.Model then
  2274. local Item = Instance.new('Model');
  2275.  
  2276. -- Register the model
  2277. Instances[Index] = Item;
  2278. end;
  2279.  
  2280. end;
  2281.  
  2282. -- Set object values on each instance
  2283. for Index, Datum in pairs(Data.Items) do
  2284.  
  2285. -- Get the item's instance
  2286. local Item = Instances[Index];
  2287.  
  2288. -- Set each item's parent and name
  2289. if Item and Datum[1] <= 15 then
  2290. Item.Name = (Datum[3] == '') and DefaultNames[Item.ClassName] or Datum[3];
  2291. if Datum[2] == 0 then
  2292. table.insert(Build, Item);
  2293. else
  2294. Item.Parent = Instances[Datum[2]];
  2295. end;
  2296. end;
  2297.  
  2298. -- Set model primary parts
  2299. if Item and Datum[1] == 15 then
  2300. Item.PrimaryPart = (Datum[4] ~= 0) and Instances[Datum[4]] or nil;
  2301. end;
  2302.  
  2303. end;
  2304.  
  2305. -- Return the model
  2306. return Build;
  2307.  
  2308. end;
  2309.  
  2310. -- Return the API
  2311. return Serialization;]]></ProtectedString>
  2312. </Properties>
  2313. </Item>
  2314. </Item>
  2315. </roblox>
Advertisement
Add Comment
Please, Sign In to add comment