diff --git a/Source/Core/DiscIO/DirectoryBlob.cpp b/Source/Core/DiscIO/DirectoryBlob.cpp index 8840283777..65451a33d1 100644 --- a/Source/Core/DiscIO/DirectoryBlob.cpp +++ b/Source/Core/DiscIO/DirectoryBlob.cpp @@ -28,6 +28,7 @@ #include "Core/Boot/DolReader.h" #include "Core/IOS/ES/Formats.h" #include "DiscIO/Blob.h" +#include "DiscIO/DiscUtils.h" #include "DiscIO/VolumeWii.h" #include "DiscIO/WiiEncryptionCache.h" @@ -653,8 +654,8 @@ void DirectoryBlobPartition::SetDiscHeaderAndDiscType(std::optional is_wii } else { - m_is_wii = Common::swap32(&m_disc_header[0x18]) == 0x5d1c9ea3; - const bool is_gc = Common::swap32(&m_disc_header[0x1c]) == 0xc2339f3d; + m_is_wii = Common::swap32(&m_disc_header[0x18]) == WII_DISC_MAGIC; + const bool is_gc = Common::swap32(&m_disc_header[0x1c]) == GAMECUBE_DISC_MAGIC; if (m_is_wii == is_gc) ERROR_LOG_FMT(DISCIO, "Couldn't detect disc type based on {}", boot_bin_path); } diff --git a/Source/Core/DiscIO/DiscUtils.cpp b/Source/Core/DiscIO/DiscUtils.cpp index f352c5d5c8..d0bcd66857 100644 --- a/Source/Core/DiscIO/DiscUtils.cpp +++ b/Source/Core/DiscIO/DiscUtils.cpp @@ -130,10 +130,9 @@ u64 GetBiggestReferencedOffset(const Volume& volume) // This can happen when certain programs that create WBFS files scrub the entirety of // the Masterpiece partitions in Super Smash Bros. Brawl without removing them from // the partition table. https://bugs.dolphin-emu.org/issues/8733 - constexpr u32 WII_MAGIC = 0x5D1C9EA3; const auto it = std::remove_if(partitions.begin(), partitions.end(), [&](const Partition& partition) { - return volume.ReadSwapped(0x18, partition) != WII_MAGIC; + return volume.ReadSwapped(0x18, partition) != WII_DISC_MAGIC; }); partitions.erase(it, partitions.end()); diff --git a/Source/Core/DiscIO/DiscUtils.h b/Source/Core/DiscIO/DiscUtils.h index b2844e7759..91bf3eaece 100644 --- a/Source/Core/DiscIO/DiscUtils.h +++ b/Source/Core/DiscIO/DiscUtils.h @@ -22,6 +22,9 @@ constexpr u64 SL_DVD_R_SIZE = 4707319808; // Wii RVT-R constexpr u64 DL_DVD_SIZE = 8511160320; // Wii retail constexpr u64 DL_DVD_R_SIZE = 8543666176; // Wii RVT-R +constexpr u32 GAMECUBE_DISC_MAGIC = 0xC2339F3D; +constexpr u32 WII_DISC_MAGIC = 0x5D1C9EA3; + constexpr u32 PARTITION_DATA = 0; constexpr u32 PARTITION_UPDATE = 1; constexpr u32 PARTITION_CHANNEL = 2; // Mario Kart Wii, Wii Fit, Wii Fit Plus, Rabbids Go Home diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index cc48fa8f85..5b64931be7 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -232,9 +232,9 @@ FileSystemGCWii::FileSystemGCWii(const VolumeDisc* volume, const Partition& part { u8 offset_shift; // Check if this is a GameCube or Wii disc - if (volume->ReadSwapped(0x18, partition) == u32(0x5D1C9EA3)) + if (volume->ReadSwapped(0x18, partition) == WII_DISC_MAGIC) offset_shift = 2; // Wii file system - else if (volume->ReadSwapped(0x1c, partition) == u32(0xC2339F3D)) + else if (volume->ReadSwapped(0x1c, partition) == GAMECUBE_DISC_MAGIC) offset_shift = 0; // GameCube file system else return; // Invalid partition (maybe someone removed its data but not its partition table entry) diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index ab4b0e562b..911a486a4e 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -20,6 +20,7 @@ #include "Core/IOS/ES/Formats.h" #include "DiscIO/Blob.h" +#include "DiscIO/DiscUtils.h" #include "DiscIO/Enums.h" #include "DiscIO/VolumeDisc.h" #include "DiscIO/VolumeGC.h" @@ -87,14 +88,10 @@ std::map Volume::ReadWiiNames(const std::vector static std::unique_ptr CreateDisc(std::unique_ptr& reader) { - // Check for Wii - const std::optional wii_magic = reader->ReadSwapped(0x18); - if (wii_magic == u32(0x5D1C9EA3)) + if (reader->ReadSwapped(0x18) == WII_DISC_MAGIC) return std::make_unique(std::move(reader)); - // Check for GC - const std::optional gc_magic = reader->ReadSwapped(0x1C); - if (gc_magic == u32(0xC2339F3D)) + if (reader->ReadSwapped(0x1C) == GAMECUBE_DISC_MAGIC) return std::make_unique(std::move(reader)); // No known magic words found diff --git a/Source/Core/DiscIO/VolumeVerifier.cpp b/Source/Core/DiscIO/VolumeVerifier.cpp index d9ef9b991b..79c589f5c1 100644 --- a/Source/Core/DiscIO/VolumeVerifier.cpp +++ b/Source/Core/DiscIO/VolumeVerifier.cpp @@ -523,12 +523,11 @@ bool VolumeVerifier::CheckPartition(const Partition& partition) bool invalid_header = false; bool blank_contents = false; std::vector disc_header(0x80); - constexpr u32 WII_MAGIC = 0x5D1C9EA3; if (!m_volume.Read(0, disc_header.size(), disc_header.data(), partition)) { invalid_header = true; } - else if (Common::swap32(disc_header.data() + 0x18) != WII_MAGIC) + else if (Common::swap32(disc_header.data() + 0x18) != WII_DISC_MAGIC) { for (size_t i = 0; i < disc_header.size(); i += 4) {