Add support for XML files.

XML support is now implemented and should generally be working!
This library should be useable now, but I still need to set it up to
work as a NuGet package.
If there are any bugs, let me know!
This commit is contained in:
CloneTrooper1019
2019-01-30 00:36:56 -06:00
parent 5319ae72f9
commit 50561460ac
44 changed files with 1292 additions and 99 deletions

View File

@ -6,7 +6,7 @@ using Roblox.BinaryFormat.Chunks;
namespace Roblox.BinaryFormat
{
public class RobloxBinaryFile : IRobloxFile
public class BinaryRobloxFile : IRobloxFile
{
// Header Specific
public const string MagicHeader = "<roblox!\x89\xff\x0d\x0a\x1a\x0a";
@ -17,8 +17,8 @@ namespace Roblox.BinaryFormat
public byte[] Reserved;
// IRobloxFile
public List<Instance> BinaryTrunk = new List<Instance>();
public IReadOnlyList<Instance> Trunk => BinaryTrunk.AsReadOnly();
internal readonly Instance BinContents = new Instance("Folder", "BinaryRobloxFile");
public Instance Contents => BinContents;
// Runtime Specific
public List<RobloxBinaryChunk> Chunks = new List<RobloxBinaryChunk>();
@ -28,7 +28,7 @@ namespace Roblox.BinaryFormat
public META Metadata;
public INST[] Types;
public void Initialize(byte[] contents)
public void ReadFile(byte[] contents)
{
using (MemoryStream file = new MemoryStream(contents))
using (RobloxBinaryReader reader = new RobloxBinaryReader(file))
@ -38,7 +38,7 @@ namespace Roblox.BinaryFormat
string signature = Encoding.UTF7.GetString(binSignature);
if (signature != MagicHeader)
throw new InvalidDataException("Provided file's signature does not match RobloxBinaryFile.MagicHeader!");
throw new InvalidDataException("Provided file's signature does not match BinaryRobloxFile.MagicHeader!");
// Read header data.
Version = reader.ReadUInt16();
@ -69,8 +69,8 @@ namespace Roblox.BinaryFormat
PROP.ReadProperties(this, chunk);
break;
case "PRNT":
PRNT prnt = new PRNT(chunk);
prnt.Assemble(this);
PRNT hierarchy = new PRNT(chunk);
hierarchy.Assemble(this);
break;
case "META":
Metadata = new META(chunk);
@ -91,4 +91,4 @@ namespace Roblox.BinaryFormat
}
}
}
}
}

View File

@ -26,13 +26,11 @@
}
}
public void Allocate(RobloxBinaryFile file)
public void Allocate(BinaryRobloxFile file)
{
foreach (int instId in InstanceIds)
{
Instance inst = new Instance();
inst.ClassName = TypeName;
Instance inst = new Instance(TypeName);
file.Instances[instId] = inst;
}

View File

@ -20,7 +20,7 @@
}
}
public void Assemble(RobloxBinaryFile file)
public void Assemble(BinaryRobloxFile file)
{
for (int i = 0; i < NumRelations; i++)
{
@ -28,16 +28,14 @@
int parentId = ParentIds[i];
Instance child = file.Instances[childId];
Instance parent = null;
if (parentId >= 0)
{
Instance parent = file.Instances[parentId];
child.Parent = parent;
}
parent = file.Instances[parentId];
else
{
file.BinaryTrunk.Add(child);
}
parent = file.BinContents;
child.Parent = parent;
}
}
}

View File

@ -9,7 +9,7 @@ namespace Roblox.BinaryFormat.Chunks
{
public class PROP
{
public static void ReadProperties(RobloxBinaryFile file, RobloxBinaryChunk chunk)
public static void ReadProperties(BinaryRobloxFile file, RobloxBinaryChunk chunk)
{
RobloxBinaryReader reader = chunk.GetReader("PROP");
@ -38,13 +38,14 @@ namespace Roblox.BinaryFormat.Chunks
for (int i = 0; i < instCount; i++)
{
int instId = ids[i];
Instance inst = file.Instances[instId];
Property prop = new Property();
prop.Name = name;
prop.Type = propType;
prop.Instance = inst;
props[i] = prop;
Instance inst = file.Instances[instId];
inst.AddProperty(ref prop);
}