Skip to content

Commit

Permalink
StreamMap: Speculative fix for stream blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Greavesy1899 committed Apr 2, 2024
1 parent 0254e0e commit 350362d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Mafia2Libs/ResourceTypes/FileTypes/StreamMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public class StreamMapLoader
private StreamLine[] lines;
private StreamLoader[] loaders;
private StreamBlock[] blocks;
private ulong[] hashes;

public StreamGroup[] Groups {
get { return groups; }
Expand Down Expand Up @@ -519,7 +518,7 @@ public void ReadFromFile(BinaryReader reader)

ToolkitAssert.Ensure(reader.BaseStream.Position == hashOffset, "Did not reach the block hashes starting offset!");

hashes = new ulong[numHashes];
ulong[] hashes = new ulong[numHashes];

for (int i = 0; i < numHashes; i++)
{
Expand Down Expand Up @@ -728,15 +727,18 @@ private void InternalWriteToFile(BinaryWriter writer)

blockOffset = (int)writer.BaseStream.Position;

List<ulong> hashesArray = new List<ulong>();
foreach (var block in blocks)
{
writer.Write(block.startOffset);
writer.Write(block.endOffset);
// add and update offsets
writer.Write(hashesArray.Count); // Start Offset
hashesArray.AddRange(block.Hashes);
writer.Write(hashesArray.Count); // End Offset
}

hashOffset = (int)writer.BaseStream.Position;

foreach (var value in hashes)
foreach (var value in hashesArray)
{
writer.Write(value);
}
Expand All @@ -760,7 +762,7 @@ private void InternalWriteToFile(BinaryWriter writer)
writer.Write(loadersOffset);
writer.Write(blocks.Length);
writer.Write(blockOffset);
writer.Write(hashes.Length);
writer.Write(hashesArray.Count);
writer.Write(hashOffset);
writer.Write(rawPool.Length);
writer.Write(poolOffset);
Expand Down

0 comments on commit 350362d

Please sign in to comment.