Does anyone have a table encoder/decoder for parts i can use?

i made my own but its terrible
it only spports a few parts, it skips parts, and other stuff

Heres mine:

Encoder:

local function EncodePart(Part)
	local Table = {}
	
	if Part:IsA("BasePart") then
		local Table = ReturnTableBasePart
		Table.CastShadow = Part.CastShadow
		Table.Color = Part.Color
		Table.Material = Part.Material
		Table.Reflectance = Part.Reflectance
		Table.Transparency = Part.Transparency
		Table.Size = Part.Size
		Table.CFrame = Part.CFrame
		if Part:IsA("Part") then
			Table.Shape = Part.Shape
		else
			Table.Shape = "None"
		end
		Table.Type = "BasePart"
		Table.Name = Part.Name
		--table.insert(Table, typeof(Part))
		return Table
	elseif Part:IsA("UnionOperation") then
		local Table = ReturnTableUnion
		Table.CastShadow = Part.CastShadow
		Table.Color = Part.Color
		Table.Material = Part.Material
		Table.Reflectance = Part.Reflectance
		Table.Transparency = Part.Transparency
		Table.SmoothingAngle = Part.SmoothingAngle
		Table.UsePartColor = Part.UsePartColor
		Table.Size = Part.Size
		Table.CFrame = Part.CFrame
		Table.Type = "UnionOperation"
		Table.Name = Part.Name
		--table.insert(Table, typeof(Part))
		return Table
	elseif Part:IsA("MeshPart") then
		local Table = ReturnTableMesh
		Table.CastShadow = Part.CastShadow
		Table.Color = Part.Color
		Table.DoubleSided = Part.DoubleSided
		Table.Material = Part.Material
		Table.MeshId = Part.MeshId
		Table.Reflectance = Part.Reflectance
		Table.TextureID = Part.TextureID
		Table.Transparency = Part.Transparency
		Table.Size = Part.Size
		Table.CFrame = Part.CFrame
		Table.Type = "MeshPart"
		Table.Name = Part.Name
		--table.insert(Table, typeof(Part))
		return Table
	elseif Part:IsA("Decal") then
		local Table = RetunTableDecal
		Table.Color3 = Part.Color3
		Table.Texture = Part.Texture
		Table.Transparency = Part.Transparency
		Table.ZIndex = Part.ZIndex
		Table.Face = Part.Face
		Table.Type = "Decal"
		Table.Name = Part.Name
		--table.insert(Table, typeof(Part))
		return Table
	elseif Part:IsA("Texture") then
		local Table = ReturnTableTexture
		Table.Color3 = Part.Color3
		Table.OffsetStudsU = Part.OffsetStudsU
		Table.OffsetStudsV = Part.OffsetStudsV
		Table.StudsPerTileU = Part.StudsPerTileU
		Table.StudsPerTileV = Part.StudsPerTileV
		Table.Texture = Part.Texture
		Table.Transparency = Part.Transparency
		Table.ZIndex = Part.ZIndex
		Table.Face = Part.Face
		Table.Type = "Texture"
		Table.Name = Part.Name
		--table.insert(Table, typeof(Part))
		return Table
	end
end

Decoder:

local function DecodePart(PartTable, Type)
	--print(Type)
	Type = PartTable["Type"]
	--print(PartTable[4])
	if Type == "BasePart" then
		local iInstance = Instance.new("Part")
		iInstance.CastShadow = PartTable["CastShadow"]
		iInstance.Color = PartTable["Color"]
		iInstance.Material = PartTable["Material"]
		iInstance.Reflectance = PartTable["Reflectance"]
		iInstance.Transparency = PartTable["Transparency"]
		iInstance.Size = PartTable["Size"]
		iInstance.CFrame = PartTable["CFrame"]
		if PartTable["Shape"] ~= "None" then
			iInstance.Shape = PartTable["Shape"]
		end
		iInstance.Name = PartTable["Name"]
		iInstance.Anchored = true
		return iInstance
	elseif Type == "UnionOperation" then
		local iInstance = Instance.new("UnionOperation")
		iInstance.CastShadow = PartTable["CastShadow"]
		iInstance.Color = PartTable["Color"]
		iInstance.Material = PartTable["Material"]
		iInstance.Reflectance = PartTable["Reflectance"]
		iInstance.Transparency = PartTable["Transparency"]
		iInstance.SmoothingAngle = PartTable["SmoothingAngle"]
		iInstance.UsePartColor = PartTable["UsePartColor"]
		iInstance.Size = PartTable["Size"]
		iInstance.CFrame = PartTable["CFrame"]
		iInstance.Name = PartTable["Name"]
		iInstance.Anchored = true
		return iInstance
	elseif Type == "MeshPart" then
		local iInstance = Instance.new("MeshPart")
		iInstance.CastShadow = PartTable["CastShadow"]
		iInstance.Color = PartTable["Color"]
		--iInstance.DoubleSided = PartTable["DoubleSided"]
		iInstance.Material = PartTable["Material"]
		--iInstance.MeshId = PartTable["MeshId"]
		iInstance.Reflectance = PartTable["Reflectance"]
		iInstance.TextureID = PartTable["TextureID"]
		iInstance.Transparency = PartTable["Transparency"]
		iInstance.Size = PartTable["Size"]
		iInstance.CFrame = PartTable["CFrame"]
		iInstance.Name = PartTable["Name"]
		iInstance.Anchored = true
		return iInstance
	elseif Type == "Decal" then
		local iInstance = Instance.new("Decal")
		iInstance.Color3 = PartTable["Color3"]
		iInstance.Texture = PartTable["Texture"]
		iInstance.Transparency = PartTable["Transparency"]
		iInstance.ZIndex = PartTable["ZIndex"]
		iInstance.Face = PartTable["Face"]
		iInstance.Name = PartTable["Name"]
		return iInstance
	elseif Type == "Texture" then
		local iInstance = Instance.new("Texture")
		iInstance.Color3 = PartTable["Color3"]
		iInstance.OffsetStudsU = PartTable["OffsetStudsU"]
		iInstance.OffsetStudsV = PartTable["OffsetStudsV"]
		iInstance.StudsPerTileU = PartTable["StudsPerTileU"]
		iInstance.StudsPerTileV = PartTable["StudsPerTileV"]
		iInstance.Texture = PartTable["Texture"]
		iInstance.Transparency = PartTable["Transparency"]
		iInstance.ZIndex = PartTable["ZIndex"]
		iInstance.Face = PartTable["Face"]
		iInstance.Name = PartTable["Name"]
		return iInstance
	else
		
		return "What ?"
	end
	
	

end

Im not asking for anyone to make me code, im asking if anyone has/knows about a part encoder/decoder

Thank you

2 Likes

Alright so let me help with some clarification of jargon to help you communicate better.

Encoding/Decoding has very specific meanings in programing and I don’t think that’s what you are looking for here.

Really what you are looking for is a serialization of a part and DeSerialization

Serialization is any time you take a complex data and you transform it into a simpler form. Like breaking things into their primitave data form for json etc. The process of making something that converts things to make their data acceptable for json is serialization.

It looks like you are asking for something to assist in the serialization of instances.

This is a pretty wide field, and generally speaking you do it as for your needs as generic serialization, in most cases, will never fit the needs of performance / Data exclusion that you may need and instead is just kind of a godstopper.

That being said I can help you make what you have here be a little cleaner.


local InstanceTypeAttributeTemplates = {
  Part = {
    "CastShadow",
    "Color", 
    "Material", 
    "Reflectance", 
    "Transparency", 
    "SmoothingAngle", 
    "UsePartColor", 
    "Size", 
    "CFrame",
    "Type",
  "Name"
  }
}

local function createPreSerializationTable(_instance, instanceTemplate)
  local FinalTable = {}
  local tempAttribute = nil

  for i = 1, #instanceTemplate do
      tempAttribute = instanceTemplate[i]
      FinalTable[tempAttribute] = _instance[tempAttribute]
  end
  
  return FinalTable
end

--[[
Now you can just go through your loop to figure out hwa tyoou want to do. 
If you want to get ULTRA fancy you can break them up your templates like
Default, and then have the other ones based on whats special and then you could pass through all the applicable ones and concat the table before you go through or 
you could make a high level table that has access for all the generally grouped ones that you make first and then break those down into the sub groups. 

You want to take into considerations names CHANGE on things, and this will be much more visible, as well as easier for you to maintain if something changes ever down the line. 

Also doing it this way makes the added benefit that you can add it as you need it instead of needing to write one massive one that you take a ton of time to write you can just extend it as you need it. Which is more time efficient for you. 
--]]

This is just one way to do it, the other way is to do the same thing I have done but there are repositories you can find that will give you a dump out of their standing info that you can use as a resource instead of making your own table reference to work with.  

In my last note, the reason I recommend my method, is you will likely find you don't want or need ALL the data on a thing when you are seralizing aspects.  And this would lend itself to you making variations like Like PARTS don't have textureIDs so you don't need to fill it out, but meshes DO.  And any time you don't care what an attributes baseline default is then you don't need to store and reconstruct that aspect because you don't care.  

Also remember, ALL part types are BaseParts so everything that exist in basepart only should be accessible by all.   So you want to consider that data being shared between mesh and parts etc etc.  You have the right idea, you just need to organize it out a bit better to make your lif easier. 

2 Likes

im confused? how do i set this up? do i add more templates?

Im assuming templates have all the data i need like for a meshpart it needs to have meshId but for a decal it needs to have ImageId right?

And what about decoding this table?

1 Like

search next time

optionally dissect a backdoor game stealer and an API dump

1 Like

Depends on how you are doing it, the format I gave you was more generalized. You would create a table with all of the data that you want to store. You can store them in an ordered table and unwind it in the same order or you could set the dictionary name to the attribute called and then use the same name to pull the data off the part.

From there, its how you want to expand it. If you have special configurations per part you will want to add a special ID component to it as well, if you don’t use your own method just use HTTP service it has a getGUID function that will generate a guaranteed UUID every time.

Again, what you are asking for is very very generic and open ended I was giving you a generalization and a direction on where to go

1 Like