Compare commits

..

No commits in common. "2be1bc4352534190299224970610cdd479d615ec" and "3b9ff6c8522f8ac48fff76f275058993c7f15bd9" have entirely different histories.

3 changed files with 48 additions and 47 deletions

View File

@ -6,31 +6,32 @@ using System.Text;
namespace KeepersCompound.LGS.Database.Chunks; namespace KeepersCompound.LGS.Database.Chunks;
public class Property public class PropertyModelName : IChunk
{ {
public int objectId; public record Property
public int length;
public virtual void Read(BinaryReader reader)
{ {
objectId = reader.ReadInt32(); public int objectId;
length = (int)reader.ReadUInt32(); 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 class PropertyChunk<T> : IChunk where T : Property, new()
{
public ChunkHeader Header { get; set; } public ChunkHeader Header { get; set; }
public List<T> properties; public List<Property> properties;
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry) public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
{ {
properties = new List<T>(); properties = new List<Property>();
while (reader.BaseStream.Position < entry.Offset + entry.Size + 24) while (reader.BaseStream.Position < entry.Offset + entry.Size + 24)
{ {
var prop = new T(); properties.Add(new Property(reader));
prop.Read(reader);
properties.Add(prop);
} }
} }
@ -40,36 +41,36 @@ public class PropertyChunk<T> : IChunk where T : Property, new()
} }
} }
public class PropGeneric : Property public class PropertyScale : IChunk
{ {
public byte[] data; public record Property
public override void Read(BinaryReader reader)
{ {
base.Read(reader); public int objectId;
data = reader.ReadBytes(length); public int length;
} public Vector3 scale;
}
public Property(BinaryReader reader)
public class PropModelName : Property {
{ objectId = reader.ReadInt32();
public string modelName; length = (int)reader.ReadUInt32();
scale = reader.ReadVec3();
public override void Read(BinaryReader reader) }
{ }
base.Read(reader);
var tmpName = Encoding.UTF8.GetString(reader.ReadBytes(length)).Replace("\0", string.Empty); public ChunkHeader Header { get; set; }
modelName = tmpName[..Math.Min(length - 1, tmpName.Length)]; 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)
public Vector3 scale; {
properties.Add(new Property(reader));
public override void Read(BinaryReader reader) }
{ }
base.Read(reader);
scale = reader.ReadVec3(); public void WriteData(BinaryWriter writer)
{
throw new System.NotImplementedException();
} }
} }

View File

@ -102,8 +102,8 @@ public class DbFile
"TXLIST" => new TxList(), "TXLIST" => new TxList(),
"WREXT" => new WorldRep(), "WREXT" => new WorldRep(),
"BRLIST" => new BrList(), "BRLIST" => new BrList(),
"P$ModelName" => new PropertyChunk<PropModelName>(), "P$ModelName" => new PropertyModelName(),
"P$Scale" => new PropertyChunk<PropScale>(), "P$Scale" => new PropertyScale(),
"LD$MetaProp" => new LinkDataMetaProp(), "LD$MetaProp" => new LinkDataMetaProp(),
_ when entryName.StartsWith("L$") => new LinkChunk(), _ when entryName.StartsWith("L$") => new LinkChunk(),
_ => new GenericChunk(), _ => new GenericChunk(),

View File

@ -111,8 +111,8 @@ public partial class Mission : Node3D
) )
{ {
var brList = (BrList)brListRaw; var brList = (BrList)brListRaw;
var modelNames = (PropertyChunk<PropModelName>)modelNamesRaw; var modelNames = (PropertyModelName)modelNamesRaw;
var scales = (PropertyChunk<PropScale>)scalesRaw; var scales = (PropertyScale)scalesRaw;
var metaPropLinks = (LinkChunk)metaPropLinksRaw; var metaPropLinks = (LinkChunk)metaPropLinksRaw;
var metaPropLinkData = (LinkDataMetaProp)metaPropLinkDataRaw; var metaPropLinkData = (LinkDataMetaProp)metaPropLinkDataRaw;
@ -136,10 +136,10 @@ public partial class Mission : Node3D
gamFile.Chunks.TryGetValue("P$Scale", out var gamChunk4)) gamFile.Chunks.TryGetValue("P$Scale", out var gamChunk4))
{ {
GD.Print($"Pre-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}"); GD.Print($"Pre-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}");
modelNames.properties.AddRange(((PropertyChunk<PropModelName>)gamChunk1).properties); modelNames.properties.AddRange(((PropertyModelName)gamChunk1).properties);
metaPropLinks.links.AddRange(((LinkChunk)gamChunk2).links); metaPropLinks.links.AddRange(((LinkChunk)gamChunk2).links);
metaPropLinkData.linkData.AddRange(((LinkDataMetaProp)gamChunk3).linkData); metaPropLinkData.linkData.AddRange(((LinkDataMetaProp)gamChunk3).linkData);
scales.properties.AddRange(((PropertyChunk<PropScale>)gamChunk4).properties); scales.properties.AddRange(((PropertyScale)gamChunk4).properties);
GD.Print($"Post-Merged chunks: {modelNames.properties.Count} {metaPropLinks.links.Count} {metaPropLinkData.linkData.Count}"); 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( private void PlaceObjects(
BrList brList, BrList brList,
PropertyChunk<PropModelName> modelNames, PropertyModelName modelNames,
PropertyChunk<PropScale> scales, PropertyScale scales,
LinkChunk metapropLink, LinkChunk metapropLink,
LinkDataMetaProp metaPropLinkData) LinkDataMetaProp metaPropLinkData)
{ {