Skip to content

Commit

Permalink
Make OBJX decoding version dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
ammaraskar committed Oct 12, 2024
1 parent 3bcb9bc commit e5fa723
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Assets/Scripts/OpenTS2/Files/Formats/DBPF/SimsObjectCodec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ public override AbstractAsset Deserialize(byte[] bytes, ResourceKey tgi, DBPFFil
var stream = new MemoryStream(bytes);
var reader = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN);

// This file needs a version that comes from the OBJM file. Without that, just default to 0xAD for now which
// seems to be what my ultimate collection lots are saved with.
return DeserializeWithVersion(reader, version: 0xAD);
}

private static SimsObjectAsset DeserializeWithVersion(IoBuffer reader, int version)
{
var asset = new SimsObjectAsset();

// Skip first 64 bytes.
reader.Seek(SeekOrigin.Begin, 64);

// TODO: this is for versions = 0xAD, see if we need to handle lower.

// 4 skipped/unused floats
for (int i = 0; i < 4; i++)
{
Expand Down Expand Up @@ -71,7 +78,11 @@ public override AbstractAsset Deserialize(byte[] bytes, ResourceKey tgi, DBPFFil
Debug.Log($"dataArray: [{string.Join(", ", dataArray)}]");

// Next is a number of shorts that depends on the exact version of the file.
uint numShorts = 0x58;
uint numShorts = version switch
{
0xAD => 0x58,
_ => throw new NotImplementedException($"SimObjectCodec not implemented for version {version:X}"),
};
for (var i = 0; i < numShorts; i++)
{
reader.ReadInt16();
Expand Down

0 comments on commit e5fa723

Please sign in to comment.