Make defining property chunks easier
This commit is contained in:
parent
3b9ff6c852
commit
df923492cf
|
@ -6,32 +6,31 @@ using System.Text;
|
||||||
|
|
||||||
namespace KeepersCompound.LGS.Database.Chunks;
|
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;
|
objectId = reader.ReadInt32();
|
||||||
public int length;
|
length = (int)reader.ReadUInt32();
|
||||||
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<Property> properties;
|
public List<T> properties;
|
||||||
|
|
||||||
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
|
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
|
||||||
{
|
{
|
||||||
properties = new List<Property>();
|
properties = new List<T>();
|
||||||
while (reader.BaseStream.Position < entry.Offset + entry.Size + 24)
|
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;
|
base.Read(reader);
|
||||||
public int length;
|
var tmpName = Encoding.UTF8.GetString(reader.ReadBytes(length)).Replace("\0", string.Empty);
|
||||||
public Vector3 scale;
|
modelName = tmpName[..Math.Min(length - 1, tmpName.Length)];
|
||||||
|
}
|
||||||
public Property(BinaryReader reader)
|
}
|
||||||
{
|
|
||||||
objectId = reader.ReadInt32();
|
public class PropScale : Property
|
||||||
length = (int)reader.ReadUInt32();
|
{
|
||||||
scale = reader.ReadVec3();
|
public Vector3 scale;
|
||||||
}
|
|
||||||
}
|
public override void Read(BinaryReader reader)
|
||||||
|
{
|
||||||
public ChunkHeader Header { get; set; }
|
base.Read(reader);
|
||||||
public List<Property> properties;
|
scale = reader.ReadVec3();
|
||||||
|
|
||||||
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(),
|
"TXLIST" => new TxList(),
|
||||||
"WREXT" => new WorldRep(),
|
"WREXT" => new WorldRep(),
|
||||||
"BRLIST" => new BrList(),
|
"BRLIST" => new BrList(),
|
||||||
"P$ModelName" => new PropertyModelName(),
|
"P$ModelName" => new PropertyChunk<PropModelName>(),
|
||||||
"P$Scale" => new PropertyScale(),
|
"P$Scale" => new PropertyChunk<PropScale>(),
|
||||||
"LD$MetaProp" => new LinkDataMetaProp(),
|
"LD$MetaProp" => new LinkDataMetaProp(),
|
||||||
_ when entryName.StartsWith("L$") => new LinkChunk(),
|
_ when entryName.StartsWith("L$") => new LinkChunk(),
|
||||||
_ => new GenericChunk(),
|
_ => new GenericChunk(),
|
||||||
|
|
|
@ -111,8 +111,8 @@ public partial class Mission : Node3D
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var brList = (BrList)brListRaw;
|
var brList = (BrList)brListRaw;
|
||||||
var modelNames = (PropertyModelName)modelNamesRaw;
|
var modelNames = (PropertyChunk<PropModelName>)modelNamesRaw;
|
||||||
var scales = (PropertyScale)scalesRaw;
|
var scales = (PropertyChunk<PropScale>)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(((PropertyModelName)gamChunk1).properties);
|
modelNames.properties.AddRange(((PropertyChunk<PropModelName>)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(((PropertyScale)gamChunk4).properties);
|
scales.properties.AddRange(((PropertyChunk<PropScale>)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,
|
||||||
PropertyModelName modelNames,
|
PropertyChunk<PropModelName> modelNames,
|
||||||
PropertyScale scales,
|
PropertyChunk<PropScale> scales,
|
||||||
LinkChunk metapropLink,
|
LinkChunk metapropLink,
|
||||||
LinkDataMetaProp metaPropLinkData)
|
LinkDataMetaProp metaPropLinkData)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue