summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO
diff options
context:
space:
mode:
authorssdsnake <id4-ssdsnake@proxyid.net>2021-12-03 15:40:19 -0600
committerssdsnake <id4-ssdsnake@proxyid.net>2021-12-03 15:40:19 -0600
commit1aa8a4d46ffbf019f6bb4bccb81cc89bec07bb38 (patch)
tree725a6aedd59f48ffaf32a213dafe1a1a68200a63 /Source/Core/DiscIO
parent1e212d6212e8ee35c2fda7291ec61651e3c4324e (diff)
DolphinTool: CLI utility interface and disc image tools
Diffstat (limited to 'Source/Core/DiscIO')
-rw-r--r--Source/Core/DiscIO/DiscUtils.cpp47
-rw-r--r--Source/Core/DiscIO/DiscUtils.h29
2 files changed, 76 insertions, 0 deletions
diff --git a/Source/Core/DiscIO/DiscUtils.cpp b/Source/Core/DiscIO/DiscUtils.cpp
index 84cf7ed7c4..002ce066db 100644
--- a/Source/Core/DiscIO/DiscUtils.cpp
+++ b/Source/Core/DiscIO/DiscUtils.cpp
@@ -12,6 +12,8 @@
#include <fmt/format.h>
#include "Common/CommonTypes.h"
+#include "Common/MathUtil.h"
+#include "DiscIO/Blob.h"
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
@@ -198,4 +200,49 @@ u64 GetBiggestReferencedOffset(const Volume& volume, const std::vector<Partition
return biggest_offset;
}
+bool IsGCZBlockSizeLegacyCompatible(int block_size, u64 file_size)
+{
+ // In order for versions of Dolphin prior to 5.0-11893 to be able to convert a GCZ file
+ // to ISO without messing up the final part of the file in some way, the file size
+ // must be an integer multiple of the block size (fixed in 3aa463c) and must not be
+ // an integer multiple of the block size multiplied by 32 (fixed in 26b21e3).
+ return file_size % block_size == 0 && file_size % (block_size * 32) != 0;
+}
+
+bool IsDiscImageBlockSizeValid(int block_size, DiscIO::BlobType format)
+{
+ switch (format)
+ {
+ case DiscIO::BlobType::GCZ:
+ // Block size "must" be a power of 2
+ if (!MathUtil::IsPow2(block_size))
+ return false;
+
+ break;
+ case DiscIO::BlobType::WIA:
+ // Block size must not be less than the minimum, and must be a multiple of it
+ if (block_size < WIA_MIN_BLOCK_SIZE || block_size % WIA_MIN_BLOCK_SIZE != 0)
+ return false;
+
+ break;
+ case DiscIO::BlobType::RVZ:
+ // Block size must not be smaller than the minimum
+ // Block sizes smaller than the large block size threshold must be a power of 2
+ // Block sizes larger than that threshold must be a multiple of the threshold
+ if (block_size < RVZ_MIN_BLOCK_SIZE ||
+ (block_size < RVZ_BIG_BLOCK_SIZE_LCM && !MathUtil::IsPow2(block_size)) ||
+ (block_size > RVZ_BIG_BLOCK_SIZE_LCM && block_size % RVZ_BIG_BLOCK_SIZE_LCM != 0))
+ {
+ return false;
+ }
+
+ break;
+ default:
+ ASSERT(false);
+ break;
+ }
+
+ return true;
+}
+
} // namespace DiscIO
diff --git a/Source/Core/DiscIO/DiscUtils.h b/Source/Core/DiscIO/DiscUtils.h
index 0b0cb80684..5baf5fcafa 100644
--- a/Source/Core/DiscIO/DiscUtils.h
+++ b/Source/Core/DiscIO/DiscUtils.h
@@ -8,6 +8,7 @@
#include <vector>
#include "Common/CommonTypes.h"
+#include "DiscIO/Blob.h"
namespace DiscIO
{
@@ -49,6 +50,31 @@ constexpr u32 WII_NONPARTITION_DISCHEADER_SIZE = 0x100;
constexpr u32 WII_REGION_DATA_ADDRESS = 0x4E000;
constexpr u32 WII_REGION_DATA_SIZE = 0x20;
+// 128 KiB (0x20000) is the default block size for GCZ/RVZ images
+constexpr int GCZ_RVZ_PREFERRED_BLOCK_SIZE = 0x20000;
+
+// 32 KiB (0x8000) was picked because DVD timings are emulated as if we can't read less than
+// an entire ECC block at once. Therefore, little reason to choose a smaller block size.
+constexpr int PREFERRED_MIN_BLOCK_SIZE = 0x8000;
+
+// 2 MiB (0x200000) was picked because it is the smallest block size supported by WIA.
+// For performance reasons, blocks shouldn't be too large.
+constexpr int PREFERRED_MAX_BLOCK_SIZE = 0x200000;
+
+// If we didn't find a good GCZ block size, pick the block size which was hardcoded
+// in legacy versions. That way, at least we're not worse than older versions.
+// 16 KiB (0x4000) for supporting GCZs in versions of Dolphin prior to 5.0-11893
+constexpr int GCZ_FALLBACK_BLOCK_SIZE = 0x4000;
+
+// 2 MiB (0x200000) is the smallest block size supported by WIA.
+constexpr int WIA_MIN_BLOCK_SIZE = 0x200000;
+
+// 32 KiB (0x8000) is the smallest block size supported by RVZ.
+constexpr int RVZ_MIN_BLOCK_SIZE = 0x8000;
+
+// 2 MiB (0x200000): for RVZ, block sizes larger than 2 MiB must be an integer multiple of 2 MiB.
+constexpr int RVZ_BIG_BLOCK_SIZE_LCM = 0x200000;
+
std::string NameForPartitionType(u32 partition_type, bool include_prefix);
std::optional<u64> GetApploaderSize(const Volume& volume, const Partition& partition);
@@ -59,4 +85,7 @@ std::optional<u64> GetFSTSize(const Volume& volume, const Partition& partition);
u64 GetBiggestReferencedOffset(const Volume& volume);
u64 GetBiggestReferencedOffset(const Volume& volume, const std::vector<Partition>& partitions);
+
+bool IsGCZBlockSizeLegacyCompatible(int block_size, u64 file_size);
+bool IsDiscImageBlockSizeValid(int block_size, DiscIO::BlobType format);
} // namespace DiscIO