2020-07-13 01:19:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
|
|
|
|
namespace RobloxFiles.BinaryFormat.Chunks
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
public class PRNT : IBinaryFileChunk
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2020-07-13 01:19:30 +00:00
|
|
|
|
private const byte FORMAT = 0;
|
2019-01-26 00:39:37 +00:00
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
public void Load(BinaryRobloxFileReader reader)
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
BinaryRobloxFile file = reader.File;
|
2019-01-26 00:39:37 +00:00
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
byte format = reader.ReadByte();
|
|
|
|
|
int idCount = reader.ReadInt32();
|
|
|
|
|
|
|
|
|
|
if (format != FORMAT)
|
|
|
|
|
throw new Exception($"Unexpected PRNT format: {format} (expected {FORMAT}!)");
|
2019-01-29 09:50:55 +00:00
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
var childIds = reader.ReadInstanceIds(idCount);
|
|
|
|
|
var parentIds = reader.ReadInstanceIds(idCount);
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
for (int i = 0; i < idCount; i++)
|
2019-01-29 09:50:55 +00:00
|
|
|
|
{
|
2020-07-13 01:19:30 +00:00
|
|
|
|
int childId = childIds[i];
|
|
|
|
|
int parentId = parentIds[i];
|
2019-01-29 09:50:55 +00:00
|
|
|
|
|
|
|
|
|
Instance child = file.Instances[childId];
|
2019-05-19 04:44:51 +00:00
|
|
|
|
child.Parent = (parentId >= 0 ? file.Instances[parentId] : file);
|
2019-06-30 22:01:19 +00:00
|
|
|
|
child.ParentLocked = child.IsService;
|
2019-01-29 09:50:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
public void Save(BinaryRobloxFileWriter writer)
|
2019-06-08 03:43:28 +00:00
|
|
|
|
{
|
2020-07-13 01:19:30 +00:00
|
|
|
|
var postInstances = writer.PostInstances;
|
|
|
|
|
var idCount = postInstances.Count;
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
var childIds = new List<int>();
|
|
|
|
|
var parentIds = new List<int>();
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
foreach (Instance inst in writer.PostInstances)
|
2019-06-08 03:43:28 +00:00
|
|
|
|
{
|
|
|
|
|
Instance parent = inst.Parent;
|
|
|
|
|
|
|
|
|
|
int childId = int.Parse(inst.Referent);
|
|
|
|
|
int parentId = -1;
|
|
|
|
|
|
|
|
|
|
if (parent != null)
|
|
|
|
|
parentId = int.Parse(parent.Referent);
|
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
childIds.Add(childId);
|
|
|
|
|
parentIds.Add(parentId);
|
2019-06-08 03:43:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
writer.Write(FORMAT);
|
|
|
|
|
writer.Write(idCount);
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
2020-07-13 01:19:30 +00:00
|
|
|
|
writer.WriteInstanceIds(childIds);
|
|
|
|
|
writer.WriteInstanceIds(parentIds);
|
2019-06-08 03:43:28 +00:00
|
|
|
|
}
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|