2019-06-30 22:01:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-09-10 05:08:12 +00:00
|
|
|
|
using System.Text;
|
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 INST : IBinaryFileChunk
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-06-30 22:01:19 +00:00
|
|
|
|
public int ClassIndex { get; internal set; }
|
|
|
|
|
public string ClassName { get; internal set; }
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
|
|
|
|
public bool IsService { get; internal set; }
|
|
|
|
|
public List<bool> RootedServices { get; internal set; }
|
|
|
|
|
|
|
|
|
|
public int NumInstances { get; internal set; }
|
|
|
|
|
public List<int> InstanceIds { get; internal set; }
|
2019-01-26 00:39:37 +00:00
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
public override string ToString() => ClassName;
|
|
|
|
|
|
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-06-30 22:01:19 +00:00
|
|
|
|
ClassIndex = reader.ReadInt32();
|
|
|
|
|
ClassName = reader.ReadString();
|
2019-06-08 03:43:28 +00:00
|
|
|
|
IsService = reader.ReadBoolean();
|
|
|
|
|
|
|
|
|
|
NumInstances = reader.ReadInt32();
|
|
|
|
|
InstanceIds = reader.ReadInstanceIds(NumInstances);
|
|
|
|
|
|
2020-10-30 20:07:11 +00:00
|
|
|
|
Type instType = Type.GetType($"RobloxFiles.{ClassName}");
|
|
|
|
|
file.Classes[ClassIndex] = this;
|
|
|
|
|
|
|
|
|
|
if (instType == null)
|
|
|
|
|
{
|
2021-01-20 20:45:58 +00:00
|
|
|
|
RobloxFile.LogError($"INST - Unknown class: {ClassName} while reading INST chunk.");
|
2020-10-30 20:07:11 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
if (IsService)
|
2019-01-26 00:39:37 +00:00
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
RootedServices = new List<bool>();
|
2019-01-26 00:39:37 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
for (int i = 0; i < NumInstances; i++)
|
|
|
|
|
{
|
|
|
|
|
bool isRooted = reader.ReadBoolean();
|
|
|
|
|
RootedServices.Add(isRooted);
|
|
|
|
|
}
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
2019-01-29 09:50:55 +00:00
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
for (int i = 0; i < NumInstances; i++)
|
2019-01-29 09:50:55 +00:00
|
|
|
|
{
|
2019-06-08 03:43:28 +00:00
|
|
|
|
int instId = InstanceIds[i];
|
2020-10-30 20:07:11 +00:00
|
|
|
|
|
2019-06-30 22:01:19 +00:00
|
|
|
|
var inst = Activator.CreateInstance(instType) as Instance;
|
|
|
|
|
inst.Referent = instId.ToString();
|
|
|
|
|
inst.IsService = IsService;
|
|
|
|
|
|
2019-06-08 03:43:28 +00:00
|
|
|
|
if (IsService)
|
|
|
|
|
{
|
2019-06-30 22:01:19 +00:00
|
|
|
|
bool isRooted = RootedServices[i];
|
|
|
|
|
inst.Parent = (isRooted ? file : null);
|
2019-06-08 03:43:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 09:50:55 +00:00
|
|
|
|
file.Instances[instId] = inst;
|
|
|
|
|
}
|
2019-01-26 00:39:37 +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
|
|
|
|
{
|
2019-06-30 22:01:19 +00:00
|
|
|
|
writer.Write(ClassIndex);
|
|
|
|
|
writer.WriteString(ClassName);
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
|
|
|
|
writer.Write(IsService);
|
|
|
|
|
writer.Write(NumInstances);
|
|
|
|
|
writer.WriteInstanceIds(InstanceIds);
|
|
|
|
|
|
|
|
|
|
if (IsService)
|
|
|
|
|
{
|
2020-07-13 01:19:30 +00:00
|
|
|
|
var file = writer.File;
|
2019-06-08 03:43:28 +00:00
|
|
|
|
|
|
|
|
|
foreach (int instId in InstanceIds)
|
|
|
|
|
{
|
|
|
|
|
Instance service = file.Instances[instId];
|
2019-07-07 15:27:07 +00:00
|
|
|
|
writer.Write(service.Parent == file);
|
2019-06-08 03:43:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-10 05:08:12 +00:00
|
|
|
|
|
|
|
|
|
public void WriteInfo(StringBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
builder.AppendLine($"- ClassIndex: {ClassIndex}");
|
|
|
|
|
builder.AppendLine($"- ClassName: {ClassName}");
|
|
|
|
|
builder.AppendLine($"- IsService: {IsService}");
|
|
|
|
|
|
|
|
|
|
if (IsService && RootedServices != null)
|
|
|
|
|
builder.AppendLine($"- RootedServices: `{string.Join(", ", RootedServices)}`");
|
|
|
|
|
|
|
|
|
|
builder.AppendLine($"- NumInstances: {NumInstances}");
|
|
|
|
|
builder.AppendLine($"- InstanceIds: `{string.Join(", ", InstanceIds)}`");
|
|
|
|
|
}
|
2019-01-26 00:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|