diff --git a/project/code/LGS/Database/Chunks/Property.cs b/project/code/LGS/Database/Chunks/Property.cs index 3777422..1b85059 100644 --- a/project/code/LGS/Database/Chunks/Property.cs +++ b/project/code/LGS/Database/Chunks/Property.cs @@ -6,32 +6,31 @@ using System.Text; namespace KeepersCompound.LGS.Database.Chunks; -public class PropertyModelName : IChunk +public class Property { - public record Property + public int objectId; + public int length; + + public virtual void Read(BinaryReader reader) { - public int objectId; - public int length; - public string modelName; - - public Property(BinaryReader reader) - { - objectId = reader.ReadInt32(); - length = (int)reader.ReadUInt32(); - var tmpName = Encoding.UTF8.GetString(reader.ReadBytes(length)).Replace("\0", string.Empty); - modelName = tmpName[..Math.Min(length - 1, tmpName.Length)]; - } + objectId = reader.ReadInt32(); + length = (int)reader.ReadUInt32(); } +} +public class PropertyChunk : IChunk where T : Property, new() +{ public ChunkHeader Header { get; set; } - public List properties; + public List properties; public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry) { - properties = new List(); + properties = new List(); while (reader.BaseStream.Position < entry.Offset + entry.Size + 24) { - properties.Add(new Property(reader)); + var prop = new T(); + prop.Read(reader); + properties.Add(prop); } } @@ -41,36 +40,25 @@ public class PropertyModelName : IChunk } } -public class PropertyScale : IChunk +public class PropModelName : Property { - public record Property + public string modelName; + + public override void Read(BinaryReader reader) { - public int objectId; - public int length; - public Vector3 scale; - - public Property(BinaryReader reader) - { - objectId = reader.ReadInt32(); - length = (int)reader.ReadUInt32(); - scale = reader.ReadVec3(); - } + 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 properties; +public class PropScale : Property +{ + public Vector3 scale; - public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry) + public override void Read(BinaryReader reader) { - properties = new List(); - while (reader.BaseStream.Position < entry.Offset + entry.Size + 24) - { - properties.Add(new Property(reader)); - } + base.Read(reader); + scale = reader.ReadVec3(); } - - public void WriteData(BinaryWriter writer) - { - throw new System.NotImplementedException(); - } -} \ No newline at end of file +} diff --git a/project/code/LGS/Database/File.cs b/project/code/LGS/Database/File.cs index 904ef44..6d8cecd 100644 --- a/project/code/LGS/Database/File.cs +++ b/project/code/LGS/Database/File.cs @@ -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(), + "P$Scale" => new PropertyChunk(), "LD$MetaProp" => new LinkDataMetaProp(), _ when entryName.StartsWith("L$") => new LinkChunk(), _ => new GenericChunk(), diff --git a/project/code/TMV/Mission.cs b/project/code/TMV/Mission.cs index 4b2831f..0d081a6 100644 --- a/project/code/TMV/Mission.cs +++ b/project/code/TMV/Mission.cs @@ -111,8 +111,8 @@ public partial class Mission : Node3D ) { var brList = (BrList)brListRaw; - var modelNames = (PropertyModelName)modelNamesRaw; - var scales = (PropertyScale)scalesRaw; + var modelNames = (PropertyChunk)modelNamesRaw; + var scales = (PropertyChunk)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)gamChunk1).properties); metaPropLinks.links.AddRange(((LinkChunk)gamChunk2).links); metaPropLinkData.linkData.AddRange(((LinkDataMetaProp)gamChunk3).linkData); - scales.properties.AddRange(((PropertyScale)gamChunk4).properties); + scales.properties.AddRange(((PropertyChunk)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 modelNames, + PropertyChunk scales, LinkChunk metapropLink, LinkDataMetaProp metaPropLinkData) {