diff --git a/project/code/LGS/Database/Chunks/Link.cs b/project/code/LGS/Database/Chunks/Link.cs new file mode 100644 index 0000000..1a78b18 --- /dev/null +++ b/project/code/LGS/Database/Chunks/Link.cs @@ -0,0 +1,105 @@ + +using System.Collections.Generic; +using System.IO; + +namespace KeepersCompound.LGS.Database.Chunks; + +public record LinkId +{ + private readonly uint _data; + + public LinkId(uint data) + { + _data = data; + } + + public uint GetId() + { + return _data & 0xFFFF; + } + + public bool IsConcrete() + { + return (_data & 0xF0000) != 0; + } + + public uint GetRelation() + { + return (_data >> 20) & 0xFFF; + } + + public uint GetRaw() + { + return _data; + } +} + +public class LinkChunk : IChunk +{ + public record Link + { + public LinkId linkId; + public int source; + public int destination; + public ushort relation; + + public Link(BinaryReader reader) + { + linkId = new LinkId(reader.ReadUInt32()); + source = reader.ReadInt32(); + destination = reader.ReadInt32(); + relation = reader.ReadUInt16(); + } + } + + public ChunkHeader Header { get; set; } + public List links; + + public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry) + { + links = new List(); + while (reader.BaseStream.Position < entry.Offset + entry.Size + 24) + { + links.Add(new Link(reader)); + } + } + + public void WriteData(BinaryWriter writer) + { + throw new System.NotImplementedException(); + } +} + +public class LinkDataMetaProp : IChunk +{ + public record LinkData + { + public LinkId linkId; + public int priority; + + public LinkData(BinaryReader reader) + { + linkId = new LinkId(reader.ReadUInt32()); + priority = reader.ReadInt32(); + } + } + + public ChunkHeader Header { get; set; } + public int DataSize; + public List linkData; + + public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry) + { + DataSize = reader.ReadInt32(); + linkData = new List(); + while (reader.BaseStream.Position < entry.Offset + entry.Size + 24) + { + linkData.Add(new LinkData(reader)); + } + } + + public void WriteData(BinaryWriter writer) + { + throw new System.NotImplementedException(); + } +} \ No newline at end of file diff --git a/project/code/LGS/Database/Chunks/Property.cs b/project/code/LGS/Database/Chunks/Property.cs new file mode 100644 index 0000000..410a3c1 --- /dev/null +++ b/project/code/LGS/Database/Chunks/Property.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace KeepersCompound.LGS.Database.Chunks; + +public class PropertyModelName : IChunk +{ + public record Property + { + 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)]; + } + } + + public ChunkHeader Header { get; set; } + public List properties; + + public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry) + { + properties = new List(); + while (reader.BaseStream.Position < entry.Offset + entry.Size + 24) + { + properties.Add(new Property(reader)); + } + } + + 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 f0c4211..d18f968 100644 --- a/project/code/LGS/Database/File.cs +++ b/project/code/LGS/Database/File.cs @@ -101,6 +101,9 @@ public class DbFile "TXLIST" => new TxList(), "WREXT" => new WorldRep(), "BRLIST" => new BrList(), + "P$ModelName" => new PropertyModelName(), + "LD$MetaProp" => new LinkDataMetaProp(), + _ when entryName.StartsWith("L$") => new LinkChunk(), _ => new GenericChunk(), }; }