Skip to content

Commit

Permalink
Fix spawn point deserializer in .ppd version 24
Browse files Browse the repository at this point in the history
  • Loading branch information
sk-zk committed Oct 3, 2024
1 parent e65b6d7 commit 559378b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
4 changes: 0 additions & 4 deletions TruckLib/Models/Ppd/NavCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ public void Deserialize(BinaryReader r, uint? version = null)
Deserialize15(r);
break;
case 0x16:
Deserialize16to18(r);
break;
case 0x17:
Deserialize16to18(r);
break;
case 0x18:
Deserialize16to18(r);
break;
Expand Down
2 changes: 1 addition & 1 deletion TruckLib/Models/Ppd/PrefabDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private void Deserialize18(BinaryReader r)
NavCurves = r.ReadObjectList<NavCurve>(navCurveCount, version);
Signs = r.ReadObjectList<Sign>(signCount);
Semaphores = r.ReadObjectList<Semaphore>(semaphoreCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount);
SpawnPoints = r.ReadObjectList<SpawnPoint>(spawnPointCount, version);
TerrainPointPositions = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointNormals = r.ReadObjectList<Vector3>(terrainPointCount);
TerrainPointVariants = r.ReadObjectList<TerrainPointVariant>(terrainPointVariantCount);
Expand Down
28 changes: 28 additions & 0 deletions TruckLib/Models/Ppd/SpawnPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,46 @@ public class SpawnPoint : IBinarySerializable

public SpawnPointType Type { get; set; }

public uint Unknown { get; set; }

public void Deserialize(BinaryReader r, uint? version = null)
{
switch (version)
{
case 0x15:
case 0x16:
case 0x17:
Deserialize15to17(r);
break;
case 0x18:
Deserialize18(r);
break;
default:
throw new NotSupportedException($"Version {version} is not supported.");
}
}

private void Deserialize15to17(BinaryReader r)
{
Position = r.ReadVector3();
Rotation = r.ReadQuaternion();
Type = (SpawnPointType)r.ReadUInt32();
}

private void Deserialize18(BinaryReader r)
{
Position = r.ReadVector3();
Rotation = r.ReadQuaternion();
Type = (SpawnPointType)r.ReadUInt32();
Unknown = r.ReadUInt32();
}

public void Serialize(BinaryWriter w)
{
w.Write(Position);
w.Write(Rotation);
w.Write((uint)Type);
w.Write(Unknown);
}
}
}

0 comments on commit 559378b

Please sign in to comment.