From 19b8f1c10adeefd9413687ab7a7c21b509fe777d Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sat, 13 Jun 2015 12:51:24 +0200 Subject: VolumeWiiCrypted: Replace ChangePartition with a partition parameter By removing mutable state in VolumeWiiCrypted, this change makes partition-related code simpler. It also gets rid of other ugly things, like ISOProperties's "over 9000" loop that creates a list of partitions by trying possible combinations, and DiscScrubber's volume swapping that recreates the entire volume when it needs to change partition. --- Source/Core/DiscIO/VolumeGC.cpp | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index adc20f5569..6f7568a3a1 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -32,21 +32,21 @@ CVolumeGC::~CVolumeGC() { } -bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const +bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, const Partition& partition) const { - if (decrypt) - PanicAlertT("Tried to decrypt data from a non-Wii volume"); + if (partition != PARTITION_NONE) + return false; return m_pReader->Read(_Offset, _Length, _pBuffer); } -std::string CVolumeGC::GetGameID() const +std::string CVolumeGC::GetGameID(const Partition& partition) const { static const std::string NO_UID("NO_UID"); char ID[6]; - if (!Read(0, sizeof(ID), reinterpret_cast(ID))) + if (!Read(0, sizeof(ID), reinterpret_cast(ID), partition)) { PanicAlertT("Failed to read unique ID from disc image"); return NO_UID; @@ -58,43 +58,43 @@ std::string CVolumeGC::GetGameID() const Region CVolumeGC::GetRegion() const { u8 country_code; - if (!ReadSwapped(3, &country_code, false)) + if (!ReadSwapped(3, &country_code, PARTITION_NONE)) return Region::UNKNOWN_REGION; return RegionSwitchGC(country_code); } -Country CVolumeGC::GetCountry() const +Country CVolumeGC::GetCountry(const Partition& partition) const { u8 country_code; - if (!ReadSwapped(3, &country_code, false)) + if (!ReadSwapped(3, &country_code, partition)) return Country::COUNTRY_UNKNOWN; return CountrySwitch(country_code); } -std::string CVolumeGC::GetMakerID() const +std::string CVolumeGC::GetMakerID(const Partition& partition) const { char makerID[2]; - if (!Read(0x4, 0x2, (u8*)&makerID)) + if (!Read(0x4, 0x2, (u8*)&makerID, partition)) return std::string(); return DecodeString(makerID); } -u16 CVolumeGC::GetRevision() const +u16 CVolumeGC::GetRevision(const Partition& partition) const { u8 revision; - if (!ReadSwapped(7, &revision, false)) + if (!ReadSwapped(7, &revision, partition)) return 0; return revision; } -std::string CVolumeGC::GetInternalName() const +std::string CVolumeGC::GetInternalName(const Partition& partition) const { char name[0x60]; - if (Read(0x20, 0x60, (u8*)name)) + if (Read(0x20, 0x60, (u8*)name, partition)) return DecodeString(name); return ""; @@ -138,19 +138,19 @@ std::vector CVolumeGC::GetBanner(int* width, int* height) const return m_image_buffer; } -u64 CVolumeGC::GetFSTSize() const +u64 CVolumeGC::GetFSTSize(const Partition& partition) const { u32 size; - if (!Read(0x428, 0x4, (u8*)&size)) + if (!Read(0x428, 0x4, (u8*)&size, partition)) return 0; return Common::swap32(size); } -std::string CVolumeGC::GetApploaderDate() const +std::string CVolumeGC::GetApploaderDate(const Partition& partition) const { char date[16]; - if (!Read(0x2440, 0x10, (u8*)&date)) + if (!Read(0x2440, 0x10, (u8*)&date, partition)) return std::string(); return DecodeString(date); @@ -171,10 +171,10 @@ u64 CVolumeGC::GetRawSize() const return m_pReader->GetRawSize(); } -u8 CVolumeGC::GetDiscNumber() const +u8 CVolumeGC::GetDiscNumber(const Partition& partition) const { u8 disc_number = 0; - ReadSwapped(6, &disc_number, false); + ReadSwapped(6, &disc_number, partition); return disc_number; } @@ -192,8 +192,8 @@ void CVolumeGC::LoadBannerFile() const m_banner_loaded = true; GCBanner banner_file; - std::unique_ptr file_system(CreateFileSystem(this)); - size_t file_size = (size_t)file_system->GetFileSize("opening.bnr"); + std::unique_ptr file_system(CreateFileSystem(this, PARTITION_NONE)); + size_t file_size = static_cast(file_system->GetFileSize("opening.bnr")); constexpr int BNR1_MAGIC = 0x31524e42; constexpr int BNR2_MAGIC = 0x32524e42; -- cgit v1.2.3 From 2bcad57225b9b0a4635d62eeabbbb138d71386bf Mon Sep 17 00:00:00 2001 From: JosJuice Date: Wed, 3 Jun 2015 13:19:28 +0200 Subject: Check file system validity before reading opening.bnr This happened to work without any problems because the only way for a file system to be invalid was to not have the right GC/Wii magic word in the unencrypted area, and a volume could not be created without having the right GC/Wii magic word there. Now that file systems read the magic word from a partition instead, a fix is needed. --- Source/Core/DiscIO/VolumeGC.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/VolumeGC.cpp') diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 6f7568a3a1..d6abd08263 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -193,8 +193,10 @@ void CVolumeGC::LoadBannerFile() const GCBanner banner_file; std::unique_ptr file_system(CreateFileSystem(this, PARTITION_NONE)); - size_t file_size = static_cast(file_system->GetFileSize("opening.bnr")); + if (!file_system) + return; + size_t file_size = static_cast(file_system->GetFileSize("opening.bnr")); constexpr int BNR1_MAGIC = 0x31524e42; constexpr int BNR2_MAGIC = 0x32524e42; if (file_size != BNR1_SIZE && file_size != BNR2_SIZE) -- cgit v1.2.3