From 6fa9f7122bc56e7a1e04f458e310019b9b560809 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Wed, 8 Jan 2025 13:25:49 -0500 Subject: [PATCH] libeuropa/io: Fix PakWriter AlignBy() so it actually works Oops. This makes sector alignment actually work for writing sector aligned paks now. --- src/libeuropa/io/PakWriter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libeuropa/io/PakWriter.cpp b/src/libeuropa/io/PakWriter.cpp index d234733..3c60061 100644 --- a/src/libeuropa/io/PakWriter.cpp +++ b/src/libeuropa/io/PakWriter.cpp @@ -29,11 +29,11 @@ namespace europa::io { this->version = version; } - // move to a util/ header + // FIXME: It would be nice to move to a util/ header template constexpr T AlignBy(T value, std::size_t alignment) { - return (-value) & (alignment - 1); + return static_cast(((value + (alignment - 1)) & ~(alignment - 1))); } void PakWriter::Write(std::ostream& os, std::vector&& vec, PakProgressReportSink& sink, SectorAlignment sectorAlignment) { @@ -77,7 +77,7 @@ namespace europa::io { // Align first file to sector boundary. if(sectorAlignment == SectorAlignment::Align) os.seekp( - AlignBy(os.tellp(), kCDSectorSize), + AlignBy(static_cast(os.tellp()), kCDSectorSize), std::istream::beg); // Write all the file data @@ -118,7 +118,7 @@ namespace europa::io { // Align to sector boundary. if(sectorAlignment == SectorAlignment::Align) os.seekp( - AlignBy(os.tellp(), kCDSectorSize), + AlignBy(static_cast(os.tellp()), kCDSectorSize), std::istream::beg); sink.OnEvent({ PakProgressReportSink::FileEvent::EventCode::FileWriteEnd,