thief-mission-viewer/project/code/LGS/Database/Chunks/Property.cs

65 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
2024-08-25 10:53:50 +00:00
using System.Numerics;
using System.Text;
namespace KeepersCompound.LGS.Database.Chunks;
2024-08-25 12:07:49 +00:00
public class Property
{
2024-08-25 12:07:49 +00:00
public int objectId;
public int length;
2024-08-25 12:07:49 +00:00
public virtual void Read(BinaryReader reader)
{
objectId = reader.ReadInt32();
length = (int)reader.ReadUInt32();
}
2024-08-25 12:07:49 +00:00
}
2024-08-25 12:07:49 +00:00
public class PropertyChunk<T> : IChunk where T : Property, new()
{
public ChunkHeader Header { get; set; }
2024-08-25 12:07:49 +00:00
public List<T> properties;
public void ReadData(BinaryReader reader, DbFile.TableOfContents.Entry entry)
{
2024-08-25 12:07:49 +00:00
properties = new List<T>();
while (reader.BaseStream.Position < entry.Offset + entry.Size + 24)
{
2024-08-25 12:07:49 +00:00
var prop = new T();
prop.Read(reader);
properties.Add(prop);
}
}
2024-08-25 10:53:50 +00:00
public void WriteData(BinaryWriter writer)
{
throw new System.NotImplementedException();
}
}
2024-08-25 12:07:49 +00:00
public class PropModelName : Property
2024-08-25 10:53:50 +00:00
{
2024-08-25 12:07:49 +00:00
public string modelName;
2024-08-25 10:53:50 +00:00
2024-08-25 12:07:49 +00:00
public override void Read(BinaryReader reader)
2024-08-25 10:53:50 +00:00
{
2024-08-25 12:07:49 +00:00
base.Read(reader);
var tmpName = Encoding.UTF8.GetString(reader.ReadBytes(length)).Replace("\0", string.Empty);
modelName = tmpName[..Math.Min(length - 1, tmpName.Length)];
2024-08-25 10:53:50 +00:00
}
2024-08-25 12:07:49 +00:00
}
2024-08-25 10:53:50 +00:00
2024-08-25 12:07:49 +00:00
public class PropScale : Property
{
public Vector3 scale;
public override void Read(BinaryReader reader)
{
2024-08-25 12:07:49 +00:00
base.Read(reader);
scale = reader.ReadVec3();
}
2024-08-25 12:07:49 +00:00
}