Make defining property chunks easier
This commit is contained in:
parent
3b9ff6c852
commit
df923492cf
|
@ -6,71 +6,59 @@ using System.Text;
|
|||
|
||||
namespace KeepersCompound.LGS.Database.Chunks;
|
||||
|
||||
public class PropertyModelName : IChunk
|
||||
{
|
||||
public record Property
|
||||
public class Property
|
||||
{
|
||||
public int objectId;
|
||||
public int length;
|
||||
public string modelName;
|
||||
|
||||
public Property(BinaryReader reader)
|
||||
public virtual void Read(BinaryReader reader)
|
||||
{
|
||||
objectId = reader.ReadInt32();
|
||||
length = (int)reader.ReadUInt32();
|
||||
}
|
||||
}
|
||||
|
||||
public class PropertyChunk<T> : IChunk where T : Property, new()
|
||||
{
|
||||
public ChunkHeader Header { get; set; }
|
||||
public List<T> properties;
|
||||
|
||||
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
|
||||
{
|
||||
properties = new List<T>();
|
||||
while (reader.BaseStream.Position < entry.Offset + entry.Size + 24)
|
||||
{
|
||||
var prop = new T();
|
||||
prop.Read(reader);
|
||||
properties.Add(prop);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteData(BinaryWriter writer)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class PropModelName : Property
|
||||
{
|
||||
public string modelName;
|
||||
|
||||
public override void Read(BinaryReader reader)
|
||||
{
|
||||
base.Read(reader);
|
||||
var tmpName = Encoding.UTF8.GetString(reader.ReadBytes(length)).Replace("\0", string.Empty);
|
||||
modelName = tmpName[..Math.Min(length - 1, tmpName.Length)];
|
||||
}
|
||||
}
|
||||
|
||||
public ChunkHeader Header { get; set; }
|
||||
public List<Property> properties;
|
||||
|
||||
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
|
||||
public class PropScale : Property
|
||||
{
|
||||
properties = new List<Property>();
|
||||
while (reader.BaseStream.Position < entry.Offset + entry.Size + 24)
|
||||
{
|
||||
properties.Add(new Property(reader));
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteData(BinaryWriter writer)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class PropertyScale : IChunk
|
||||
{
|
||||
public record Property
|
||||
{
|
||||
public int objectId;
|
||||
public int length;
|
||||
public Vector3 scale;
|
||||
|
||||
public Property(BinaryReader reader)
|
||||
public override void Read(BinaryReader reader)
|
||||
{
|
||||
objectId = reader.ReadInt32();
|
||||
length = (int)reader.ReadUInt32();
|
||||
base.Read(reader);
|
||||
scale = reader.ReadVec3();
|
||||
}
|
||||
}
|
||||
|
||||
public ChunkHeader Header { get; set; }
|
||||
public List<Property> properties;
|
||||
|
||||
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
|
||||
{
|
||||
properties = new List<Property>();
|
||||
while (reader.BaseStream.Position < entry.Offset + entry.Size + 24)
|
||||
{
|
||||
properties.Add(new Property(reader));
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteData(BinaryWriter writer)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
|
@ -102,8 +102,8 @@ public class DbFile
|
|||
"TXLIST" => new TxList(),
|
||||
"WREXT" => new WorldRep(),
|
||||
"BRLIST" => new BrList(),
|
||||
"P$ModelName" => new PropertyModelName(),
|
||||
"P$Scale" => new PropertyScale(),
|
||||
"P$ModelName" => new PropertyChunk<PropModelName>(),
|
||||
"P$Scale" => new PropertyChunk<PropScale>(),
|
||||
"LD$MetaProp" => new LinkDataMetaProp(),
|
||||
_ when entryName.StartsWith("L$") => new LinkChunk(),
|
||||
_ => new GenericChunk(),
|
||||
|
|
|
@ -111,8 +111,8 @@ public partial class Mission : Node3D
|
|||
)
|
||||
{
|
||||
var brList = (BrList)brListRaw;
|
||||
var modelNames = (PropertyModelName)modelNamesRaw;
|
||||
var scales = (PropertyScale)scalesRaw;
|
||||
var modelNames = (PropertyChunk<PropModelName>)modelNamesRaw;
|
||||
var scales = (PropertyChunk<PropScale>)scalesRaw;
|
||||
var metaPropLinks = (LinkChunk)metaPropLinksRaw;
|
||||
var metaPropLinkData = (LinkDataMetaProp)metaPropLinkDataRaw;
|
||||
|
||||
|
@ -136,10 +136,10 @@ public partial class Mission : Node3D
|
|||
gamFile.Chunks.TryGetValue("P$Scale", out var gamChunk4))
|
||||
{
|
||||
GD.Print($"Pre-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}");
|
||||
modelNames.properties.AddRange(((PropertyModelName)gamChunk1).properties);
|
||||
modelNames.properties.AddRange(((PropertyChunk<PropModelName>)gamChunk1).properties);
|
||||
metaPropLinks.links.AddRange(((LinkChunk)gamChunk2).links);
|
||||
metaPropLinkData.linkData.AddRange(((LinkDataMetaProp)gamChunk3).linkData);
|
||||
scales.properties.AddRange(((PropertyScale)gamChunk4).properties);
|
||||
scales.properties.AddRange(((PropertyChunk<PropScale>)gamChunk4).properties);
|
||||
GD.Print($"Post-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}");
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +163,8 @@ public partial class Mission : Node3D
|
|||
|
||||
private void PlaceObjects(
|
||||
BrList brList,
|
||||
PropertyModelName modelNames,
|
||||
PropertyScale scales,
|
||||
PropertyChunk<PropModelName> modelNames,
|
||||
PropertyChunk<PropScale> scales,
|
||||
LinkChunk metapropLink,
|
||||
LinkDataMetaProp metaPropLinkData)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue