Skip to content

Commit

Permalink
Update libutil
Browse files Browse the repository at this point in the history
Includes the Mini-UPnP compat fix and `Tell` improvement
Adapt types in `Replay` to fix signed/unsigned mismatch
adapt comments and write compressed flag after starting compression
  • Loading branch information
Flamefire committed Jun 18, 2024
1 parent 8396ee0 commit 092d52b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions libs/s25main/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool Replay::StopRecording()
{
if(!isRecording_)
return true;
const unsigned replayDataSize = file_.Tell();
const auto replayDataSize = file_.Tell();
isRecording_ = false;
file_.Close();

Expand All @@ -64,18 +64,18 @@ bool Replay::StopRecording()
const auto lastGF = file.ReadUnsignedInt();
RTTR_Assert(lastGF == lastGF_);
compressedReplay.WriteUnsignedInt(lastGF);
file.ReadUnsignedChar(); // Ignore compressed flag
compressedReplay.WriteUnsignedChar(1);
file.ReadUnsignedChar(); // Ignore compressed flag (always zero for the temporary file)

// Read and compress remaining data
const auto uncompressedSize = replayDataSize - file.Tell();
const auto uncompressedSize = replayDataSize - file.Tell(); // Always positive as there is always some game data
data.resize(uncompressedSize);
file.ReadRawData(data.data(), data.size());
data = CompressedData::compress(data);
// If the compressed data turns out to be larger than the uncompressed one, bail out
// This can happen for very short replays
if(data.size() >= uncompressedSize)
return true;
compressedReplay.WriteUnsignedChar(1); // Compressed flag
compressedReplay.WriteUnsignedInt(uncompressedSize);
compressedReplay.WriteUnsignedInt(data.size());
compressedReplay.WriteRawData(data.data(), data.size());
Expand Down

0 comments on commit 092d52b

Please sign in to comment.