diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index a1ab46ed3c..c518601b41 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -58,7 +58,7 @@ namespace fs = std::filesystem; #include "Core/PowerPC/PowerPC.h" #include "DiscIO/Enums.h" -#include "DiscIO/Volume.h" +#include "DiscIO/VolumeDisc.h" #include "DiscIO/VolumeWad.h" static std::vector ReadM3UFile(const std::string& m3u_path, diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index 48462c768d..f4c5cb83e9 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -16,7 +16,7 @@ #include "Core/IOS/IOSC.h" #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" -#include "DiscIO/Volume.h" +#include "DiscIO/VolumeDisc.h" #include "DiscIO/VolumeWad.h" namespace File diff --git a/Source/Core/Core/Boot/Boot_BS2Emu.cpp b/Source/Core/Core/Boot/Boot_BS2Emu.cpp index 0c7de549a6..62b7512c3a 100644 --- a/Source/Core/Core/Boot/Boot_BS2Emu.cpp +++ b/Source/Core/Core/Boot/Boot_BS2Emu.cpp @@ -33,7 +33,7 @@ #include "Core/PowerPC/PowerPC.h" #include "DiscIO/Enums.h" -#include "DiscIO/Volume.h" +#include "DiscIO/VolumeDisc.h" namespace { diff --git a/Source/Core/Core/HW/DVD/DVDInterface.cpp b/Source/Core/Core/HW/DVD/DVDInterface.cpp index 679cbd48dc..8f8ec4f4e4 100644 --- a/Source/Core/Core/HW/DVD/DVDInterface.cpp +++ b/Source/Core/Core/HW/DVD/DVDInterface.cpp @@ -38,7 +38,7 @@ #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" -#include "DiscIO/Volume.h" +#include "DiscIO/VolumeDisc.h" #include "DiscIO/VolumeWii.h" #include "VideoCommon/OnScreenDisplay.h" diff --git a/Source/Core/Core/WiiUtils.cpp b/Source/Core/Core/WiiUtils.cpp index e198e069e3..667fe0e663 100644 --- a/Source/Core/Core/WiiUtils.cpp +++ b/Source/Core/Core/WiiUtils.cpp @@ -40,7 +40,7 @@ #include "DiscIO/DiscExtractor.h" #include "DiscIO/Enums.h" #include "DiscIO/Filesystem.h" -#include "DiscIO/Volume.h" +#include "DiscIO/VolumeDisc.h" #include "DiscIO/VolumeFileBlobReader.h" #include "DiscIO/VolumeWad.h" diff --git a/Source/Core/DiscIO/CMakeLists.txt b/Source/Core/DiscIO/CMakeLists.txt index 4c0f04f78a..604d9e8914 100644 --- a/Source/Core/DiscIO/CMakeLists.txt +++ b/Source/Core/DiscIO/CMakeLists.txt @@ -32,6 +32,8 @@ add_library(discio TGCBlob.h Volume.cpp Volume.h + VolumeDisc.cpp + VolumeDisc.h VolumeFileBlobReader.cpp VolumeFileBlobReader.h VolumeGC.cpp diff --git a/Source/Core/DiscIO/DiscIO.vcxproj b/Source/Core/DiscIO/DiscIO.vcxproj index 10f870fe69..f439564e72 100644 --- a/Source/Core/DiscIO/DiscIO.vcxproj +++ b/Source/Core/DiscIO/DiscIO.vcxproj @@ -60,6 +60,7 @@ + @@ -89,6 +90,7 @@ + diff --git a/Source/Core/DiscIO/DiscIO.vcxproj.filters b/Source/Core/DiscIO/DiscIO.vcxproj.filters index fd67a4487f..196120fd6a 100644 --- a/Source/Core/DiscIO/DiscIO.vcxproj.filters +++ b/Source/Core/DiscIO/DiscIO.vcxproj.filters @@ -99,6 +99,7 @@ Volume\Blob + @@ -182,6 +183,7 @@ Volume\Blob + diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp index 7e1a3a0015..7e3b3452b9 100644 --- a/Source/Core/DiscIO/FileSystemGCWii.cpp +++ b/Source/Core/DiscIO/FileSystemGCWii.cpp @@ -23,7 +23,7 @@ #include "DiscIO/DiscExtractor.h" #include "DiscIO/FileSystemGCWii.h" #include "DiscIO/Filesystem.h" -#include "DiscIO/Volume.h" +#include "DiscIO/VolumeDisc.h" namespace DiscIO { diff --git a/Source/Core/DiscIO/ScrubbedBlob.cpp b/Source/Core/DiscIO/ScrubbedBlob.cpp index 255edebf57..011e833a79 100644 --- a/Source/Core/DiscIO/ScrubbedBlob.cpp +++ b/Source/Core/DiscIO/ScrubbedBlob.cpp @@ -12,7 +12,7 @@ #include "Common/Align.h" #include "DiscIO/Blob.h" #include "DiscIO/DiscScrubber.h" -#include "DiscIO/Volume.h" +#include "DiscIO/VolumeDisc.h" namespace DiscIO { diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index e1f1bbae4e..23df2afc5c 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -17,6 +17,7 @@ #include "DiscIO/Blob.h" #include "DiscIO/Enums.h" +#include "DiscIO/VolumeDisc.h" #include "DiscIO/VolumeGC.h" #include "DiscIO/VolumeWad.h" #include "DiscIO/VolumeWii.h" diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index ab251d6763..74a7cf35fc 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -23,6 +23,7 @@ namespace DiscIO class BlobReader; enum class BlobType; class FileSystem; +class VolumeDisc; class VolumeWAD; struct Partition final @@ -162,10 +163,6 @@ protected: static const std::vector INVALID_CERT_CHAIN; }; -class VolumeDisc : public Volume -{ -}; - std::unique_ptr CreateDisc(const std::string& path); std::unique_ptr CreateWAD(const std::string& path); std::unique_ptr CreateVolume(const std::string& path); diff --git a/Source/Core/DiscIO/VolumeDisc.cpp b/Source/Core/DiscIO/VolumeDisc.cpp new file mode 100644 index 0000000000..bf622bb8fb --- /dev/null +++ b/Source/Core/DiscIO/VolumeDisc.cpp @@ -0,0 +1,87 @@ +// Copyright 2020 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DiscIO/VolumeDisc.h" + +#include +#include + +#include "Common/CommonTypes.h" +#include "DiscIO/Enums.h" + +namespace DiscIO +{ +std::string VolumeDisc::GetGameID(const Partition& partition) const +{ + char id[6]; + + if (!Read(0, sizeof(id), reinterpret_cast(id), partition)) + return std::string(); + + return DecodeString(id); +} + +Country VolumeDisc::GetCountry(const Partition& partition) const +{ + // The 0 that we use as a default value is mapped to Country::Unknown and Region::Unknown + const u8 country_byte = ReadSwapped(3, partition).value_or(0); + const Region region = GetRegion(); + const std::optional revision = GetRevision(); + + if (CountryCodeToRegion(country_byte, GetVolumeType(), region, revision) != region) + return TypicalCountryForRegion(region); + + return CountryCodeToCountry(country_byte, GetVolumeType(), region, revision); +} + +Region VolumeDisc::RegionCodeToRegion(std::optional region_code) const +{ + if (!region_code) + return Region::Unknown; + + const Region region = static_cast(*region_code); + return region <= Region::NTSC_K ? region : Region::Unknown; +} + +std::string VolumeDisc::GetMakerID(const Partition& partition) const +{ + char maker_id[2]; + + if (!Read(0x4, sizeof(maker_id), reinterpret_cast(&maker_id), partition)) + return std::string(); + + return DecodeString(maker_id); +} + +std::optional VolumeDisc::GetRevision(const Partition& partition) const +{ + std::optional revision = ReadSwapped(7, partition); + return revision ? *revision : std::optional(); +} + +std::string VolumeDisc::GetInternalName(const Partition& partition) const +{ + char name[0x60]; + if (!Read(0x20, sizeof(name), reinterpret_cast(&name), partition)) + return std::string(); + + return DecodeString(name); +} + +std::string VolumeDisc::GetApploaderDate(const Partition& partition) const +{ + char date[16]; + + if (!Read(0x2440, sizeof(date), reinterpret_cast(&date), partition)) + return std::string(); + + return DecodeString(date); +} + +std::optional VolumeDisc::GetDiscNumber(const Partition& partition) const +{ + return ReadSwapped(6, partition); +} + +} // namespace DiscIO diff --git a/Source/Core/DiscIO/VolumeDisc.h b/Source/Core/DiscIO/VolumeDisc.h new file mode 100644 index 0000000000..333ea7d4aa --- /dev/null +++ b/Source/Core/DiscIO/VolumeDisc.h @@ -0,0 +1,30 @@ +// Copyright 2020 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include "Common/CommonTypes.h" +#include "DiscIO/Volume.h" + +namespace DiscIO +{ +class VolumeDisc : public Volume +{ +public: + std::string GetGameID(const Partition& partition = PARTITION_NONE) const override; + Country GetCountry(const Partition& partition = PARTITION_NONE) const override; + std::string GetMakerID(const Partition& partition = PARTITION_NONE) const override; + std::optional GetRevision(const Partition& partition = PARTITION_NONE) const override; + std::string GetInternalName(const Partition& partition = PARTITION_NONE) const override; + std::string GetApploaderDate(const Partition& partition) const override; + std::optional GetDiscNumber(const Partition& partition = PARTITION_NONE) const override; + +protected: + Region RegionCodeToRegion(std::optional region_code) const; +}; + +} // namespace DiscIO diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 74b612f647..83b0d3dd00 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -57,21 +57,6 @@ const FileSystem* VolumeGC::GetFileSystem(const Partition& partition) const return m_file_system->get(); } -std::string VolumeGC::GetGameID(const Partition& partition) const -{ - static const std::string NO_UID("NO_UID"); - - char id[6]; - - if (!Read(0, sizeof(id), reinterpret_cast(id), partition)) - { - PanicAlertT("Failed to read unique ID from disc image"); - return NO_UID; - } - - return DecodeString(id); -} - std::string VolumeGC::GetGameTDBID(const Partition& partition) const { // Don't return an ID for Datel discs @@ -83,48 +68,7 @@ std::string VolumeGC::GetGameTDBID(const Partition& partition) const Region VolumeGC::GetRegion() const { - const std::optional region_code = ReadSwapped(0x458, PARTITION_NONE); - if (!region_code) - return Region::Unknown; - const Region region = static_cast(*region_code); - return region <= Region::PAL ? region : Region::Unknown; -} - -Country VolumeGC::GetCountry(const Partition& partition) const -{ - // The 0 that we use as a default value is mapped to Country::Unknown and Region::Unknown - const u8 country = ReadSwapped(3, partition).value_or(0); - const Region region = GetRegion(); - const std::optional revision = GetRevision(); - - if (CountryCodeToRegion(country, Platform::GameCubeDisc, region, revision) != region) - return TypicalCountryForRegion(region); - - return CountryCodeToCountry(country, Platform::GameCubeDisc, region, revision); -} - -std::string VolumeGC::GetMakerID(const Partition& partition) const -{ - char maker_id[2]; - if (!Read(0x4, sizeof(maker_id), reinterpret_cast(&maker_id), partition)) - return std::string(); - - return DecodeString(maker_id); -} - -std::optional VolumeGC::GetRevision(const Partition& partition) const -{ - std::optional revision = ReadSwapped(7, partition); - return revision ? *revision : std::optional(); -} - -std::string VolumeGC::GetInternalName(const Partition& partition) const -{ - char name[0x60]; - if (Read(0x20, sizeof(name), reinterpret_cast(name), partition)) - return DecodeString(name); - - return ""; + return RegionCodeToRegion(m_reader->ReadSwapped(0x458)); } std::map VolumeGC::GetShortNames() const @@ -159,15 +103,6 @@ std::vector VolumeGC::GetBanner(u32* width, u32* height) const return m_converted_banner->image_buffer; } -std::string VolumeGC::GetApploaderDate(const Partition& partition) const -{ - char date[16]; - if (!Read(0x2440, sizeof(date), reinterpret_cast(&date), partition)) - return std::string(); - - return DecodeString(date); -} - BlobType VolumeGC::GetBlobType() const { return m_reader->GetBlobType(); @@ -193,11 +128,6 @@ const BlobReader& VolumeGC::GetBlobReader() const return *m_reader; } -std::optional VolumeGC::GetDiscNumber(const Partition& partition) const -{ - return ReadSwapped(6, partition); -} - Platform VolumeGC::GetVolumeType() const { return Platform::GameCubeDisc; diff --git a/Source/Core/DiscIO/VolumeGC.h b/Source/Core/DiscIO/VolumeGC.h index b9da441270..3d16988500 100644 --- a/Source/Core/DiscIO/VolumeGC.h +++ b/Source/Core/DiscIO/VolumeGC.h @@ -14,6 +14,7 @@ #include "Common/Lazy.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" +#include "DiscIO/VolumeDisc.h" namespace DiscIO { @@ -33,28 +34,21 @@ public: bool Read(u64 offset, u64 length, u8* buffer, const Partition& partition = PARTITION_NONE) const override; const FileSystem* GetFileSystem(const Partition& partition = PARTITION_NONE) const override; - std::string GetGameID(const Partition& partition = PARTITION_NONE) const override; std::string GetGameTDBID(const Partition& partition = PARTITION_NONE) const override; - std::string GetMakerID(const Partition& partition = PARTITION_NONE) const override; - std::optional GetRevision(const Partition& partition = PARTITION_NONE) const override; - std::string GetInternalName(const Partition& partition = PARTITION_NONE) const override; std::map GetShortNames() const override; std::map GetLongNames() const override; std::map GetShortMakers() const override; std::map GetLongMakers() const override; std::map GetDescriptions() const override; std::vector GetBanner(u32* width, u32* height) const override; - std::string GetApploaderDate(const Partition& partition = PARTITION_NONE) const override; - std::optional GetDiscNumber(const Partition& partition = PARTITION_NONE) const override; Platform GetVolumeType() const override; Region GetRegion() const override; - Country GetCountry(const Partition& partition = PARTITION_NONE) const override; BlobType GetBlobType() const override; u64 GetSize() const override; bool IsSizeAccurate() const override; u64 GetRawSize() const override; - const BlobReader& GetBlobReader() const; + const BlobReader& GetBlobReader() const override; private: static const u32 GC_BANNER_WIDTH = 96; diff --git a/Source/Core/DiscIO/VolumeWad.h b/Source/Core/DiscIO/VolumeWad.h index 5bb885023f..ce8db892c2 100644 --- a/Source/Core/DiscIO/VolumeWad.h +++ b/Source/Core/DiscIO/VolumeWad.h @@ -66,7 +66,7 @@ public: u64 GetSize() const override; bool IsSizeAccurate() const override; u64 GetRawSize() const override; - const BlobReader& GetBlobReader() const; + const BlobReader& GetBlobReader() const override; private: std::unique_ptr m_reader; diff --git a/Source/Core/DiscIO/VolumeWii.cpp b/Source/Core/DiscIO/VolumeWii.cpp index 6e2b40041f..c17744f172 100644 --- a/Source/Core/DiscIO/VolumeWii.cpp +++ b/Source/Core/DiscIO/VolumeWii.cpp @@ -299,16 +299,6 @@ u64 VolumeWii::PartitionOffsetToRawOffset(u64 offset, const Partition& partition return EncryptedPartitionOffsetToRawOffset(offset, partition, data_offset); } -std::string VolumeWii::GetGameID(const Partition& partition) const -{ - char id[6]; - - if (!Read(0, sizeof(id), reinterpret_cast(id), partition)) - return std::string(); - - return DecodeString(id); -} - std::string VolumeWii::GetGameTDBID(const Partition& partition) const { // Don't return an ID for Datel discs @@ -320,49 +310,7 @@ std::string VolumeWii::GetGameTDBID(const Partition& partition) const Region VolumeWii::GetRegion() const { - const std::optional region_code = m_reader->ReadSwapped(0x4E000); - if (!region_code) - return Region::Unknown; - const Region region = static_cast(*region_code); - return region <= Region::NTSC_K ? region : Region::Unknown; -} - -Country VolumeWii::GetCountry(const Partition& partition) const -{ - // The 0 that we use as a default value is mapped to Country::Unknown and Region::Unknown - const u8 country_byte = ReadSwapped(3, partition).value_or(0); - const Region region = GetRegion(); - const std::optional revision = GetRevision(); - - if (CountryCodeToRegion(country_byte, Platform::WiiDisc, region, revision) != region) - return TypicalCountryForRegion(region); - - return CountryCodeToCountry(country_byte, Platform::WiiDisc, region, revision); -} - -std::string VolumeWii::GetMakerID(const Partition& partition) const -{ - char maker_id[2]; - - if (!Read(0x4, sizeof(maker_id), reinterpret_cast(&maker_id), partition)) - return std::string(); - - return DecodeString(maker_id); -} - -std::optional VolumeWii::GetRevision(const Partition& partition) const -{ - std::optional revision = ReadSwapped(7, partition); - return revision ? *revision : std::optional(); -} - -std::string VolumeWii::GetInternalName(const Partition& partition) const -{ - char name_buffer[0x60]; - if (Read(0x20, sizeof(name_buffer), reinterpret_cast(&name_buffer), partition)) - return DecodeString(name_buffer); - - return ""; + return RegionCodeToRegion(m_reader->ReadSwapped(0x4E000)); } std::map VolumeWii::GetLongNames() const @@ -385,26 +333,11 @@ std::vector VolumeWii::GetBanner(u32* width, u32* height) const return WiiSaveBanner(*title_id).GetBanner(width, height); } -std::string VolumeWii::GetApploaderDate(const Partition& partition) const -{ - char date[16]; - - if (!Read(0x2440, sizeof(date), reinterpret_cast(&date), partition)) - return std::string(); - - return DecodeString(date); -} - Platform VolumeWii::GetVolumeType() const { return Platform::WiiDisc; } -std::optional VolumeWii::GetDiscNumber(const Partition& partition) const -{ - return ReadSwapped(6, partition); -} - BlobType VolumeWii::GetBlobType() const { return m_reader->GetBlobType(); diff --git a/Source/Core/DiscIO/VolumeWii.h b/Source/Core/DiscIO/VolumeWii.h index 0f2bb43d01..361c06ffe1 100644 --- a/Source/Core/DiscIO/VolumeWii.h +++ b/Source/Core/DiscIO/VolumeWii.h @@ -19,6 +19,7 @@ #include "Core/IOS/ES/Formats.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" +#include "DiscIO/VolumeDisc.h" namespace DiscIO { @@ -73,15 +74,9 @@ public: static u64 EncryptedPartitionOffsetToRawOffset(u64 offset, const Partition& partition, u64 partition_data_offset); u64 PartitionOffsetToRawOffset(u64 offset, const Partition& partition) const override; - std::string GetGameID(const Partition& partition = PARTITION_NONE) const override; std::string GetGameTDBID(const Partition& partition = PARTITION_NONE) const override; - std::string GetMakerID(const Partition& partition = PARTITION_NONE) const override; - std::optional GetRevision(const Partition& partition = PARTITION_NONE) const override; - std::string GetInternalName(const Partition& partition = PARTITION_NONE) const override; std::map GetLongNames() const override; std::vector GetBanner(u32* width, u32* height) const override; - std::string GetApploaderDate(const Partition& partition) const override; - std::optional GetDiscNumber(const Partition& partition = PARTITION_NONE) const override; Platform GetVolumeType() const override; bool SupportsIntegrityCheck() const override { return m_encrypted; } @@ -91,12 +86,11 @@ public: bool CheckBlockIntegrity(u64 block_index, const Partition& partition) const override; Region GetRegion() const override; - Country GetCountry(const Partition& partition = PARTITION_NONE) const override; BlobType GetBlobType() const override; u64 GetSize() const override; bool IsSizeAccurate() const override; u64 GetRawSize() const override; - const BlobReader& GetBlobReader() const; + const BlobReader& GetBlobReader() const override; // The in parameter can either contain all the data to begin with, // or read_function can write data into the in parameter when called.