summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLC <mathew1800@gmail.com>2020-09-01 17:58:51 -0400
committerGitHub <noreply@github.com>2020-09-01 17:58:51 -0400
commitdb067104ed42debf28e60f31c31131ae2a7c8441 (patch)
treea81459172f463cddab20370b19667a982421507e /Source/Core
parent936702bd045a804c4a7849f1b5a31577a5776e09 (diff)
parentbdd28c0edf986244fc7a2845df5537b5bc4bcf7a (diff)
Merge pull request #9047 from JosJuice/wia-header-heuristic
DiscIO: Adjust WIA/RVZ header size heuristic
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/DiscIO/WIABlob.cpp15
1 files changed, 10 insertions, 5 deletions
diff --git a/Source/Core/DiscIO/WIABlob.cpp b/Source/Core/DiscIO/WIABlob.cpp
index bdeb3a2951..51a9c65694 100644
--- a/Source/Core/DiscIO/WIABlob.cpp
+++ b/Source/Core/DiscIO/WIABlob.cpp
@@ -1770,19 +1770,24 @@ WIARVZFileReader<RVZ>::Convert(BlobReader* infile, const VolumeDisc* infile_volu
const size_t raw_data_entries_size = raw_data_entries.size() * sizeof(RawDataEntry);
const size_t group_entries_size = group_entries.size() * sizeof(GroupEntry);
- // Conservative estimate for how much space will be taken up by headers.
- // The compression methods None and Purge have very predictable overhead,
- // and the other methods are able to compress group entries well
+ // An estimate for how much space will be taken up by headers.
+ // We will reserve this much space at the beginning of the file, and if the headers don't
+ // fit on that space, we will need to write them at the end of the file instead.
const u64 headers_size_upper_bound = [&] {
+ // 0x100 is added to account for compression overhead (in particular for Purge).
u64 upper_bound = sizeof(WIAHeader1) + sizeof(WIAHeader2) + partition_entries_size +
raw_data_entries_size + 0x100;
- // RVZ's added data in GroupEntry usually compresses well
+ // RVZ's added data in GroupEntry usually compresses well, so we'll assume the compression ratio
+ // for RVZ GroupEntries is 9 / 16 or better. This constant is somehwat arbitrarily chosen, but
+ // no games were found that get a worse compression ratio than that. There are some games that
+ // get a worse ratio than 1 / 2, such as Metroid: Other M (PAL) with the default settings.
if (RVZ && compression_type > WIARVZCompressionType::Purge)
- upper_bound += group_entries_size / 2;
+ upper_bound += static_cast<u64>(group_entries_size) * 9 / 16;
else
upper_bound += group_entries_size;
+ // This alignment is also somewhat arbitrary.
return Common::AlignUp(upper_bound, VolumeWii::BLOCK_TOTAL_SIZE);
}();