Skip to content

Commit

Permalink
Fixed OldOffsetList to support Road Rage
Browse files Browse the repository at this point in the history
  • Loading branch information
Hampo committed Sep 1, 2024
1 parent ac8b7f7 commit 1775585
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions NetP3DLib/NetP3DLib/P3D/Chunks/OldOffsetListChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public uint NumOffsets
}
public uint KeyIndex { get; set; }
public List<OffsetEntry> Offsets { get; } = [];
public bool HasPrimGroupIndex { get; set; }
public uint PrimGroupIndex { get; set; }

public override byte[] DataBytes
Expand All @@ -48,7 +49,7 @@ public override byte[] DataBytes
return [.. data];
}
}
public override uint DataLength => sizeof(uint) + sizeof(uint) + (uint)Offsets.Sum(x => x.DataBytes.Length) + sizeof(uint);
public override uint DataLength => sizeof(uint) + sizeof(uint) + (uint)Offsets.Sum(x => x.DataBytes.Length) + (HasPrimGroupIndex ? sizeof(uint) : 0u);

public OldOffsetListChunk(BinaryReader br) : base((uint)ChunkIdentifier.Old_Offset_List)
{
Expand All @@ -57,16 +58,30 @@ public OldOffsetListChunk(BinaryReader br) : base((uint)ChunkIdentifier.Old_Offs
Offsets.Capacity = numOffsets;
for (int i = 0; i < numOffsets; i++)
Offsets.Add(new(br));
if (br.BaseStream.Position == br.BaseStream.Length)
{
HasPrimGroupIndex = false;
return;
}
HasPrimGroupIndex = true;
PrimGroupIndex = br.ReadUInt32();
}

public OldOffsetListChunk(uint keyIndex, IList<OffsetEntry> offsets, uint primGroupIndex) : base((uint)ChunkIdentifier.Old_Offset_List)
{
KeyIndex = keyIndex;
Offsets.AddRange(offsets);
HasPrimGroupIndex = true;
PrimGroupIndex = primGroupIndex;
}

public OldOffsetListChunk(uint keyIndex, IList<OffsetEntry> offsets) : base((uint)ChunkIdentifier.Old_Offset_List)
{
KeyIndex = keyIndex;
Offsets.AddRange(offsets);
HasPrimGroupIndex = false;
}

public override void Validate()
{
base.Validate();
Expand All @@ -78,7 +93,8 @@ internal override void WriteData(BinaryWriter bw)
bw.Write(KeyIndex);
foreach (var offset in Offsets)
offset.Write(bw);
bw.Write(PrimGroupIndex);
if (HasPrimGroupIndex)
bw.Write(PrimGroupIndex);
}

public class OffsetEntry
Expand Down

0 comments on commit 1775585

Please sign in to comment.