From 135733e28519b36015a87554b22b314fb575f095 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 9 Mar 2017 19:44:38 +0100 Subject: [PATCH] Volume: Use ReadSwapped more Most of the Volume code was written before this convenience function was added. Let's use it more. Also deleting m_pReader nullptr checks that are unnecessary because of Read (which ReadSwapped calls) already having a nullptr check. --- Source/Core/DiscIO/VolumeGC.cpp | 34 ++++--------------- Source/Core/DiscIO/VolumeWad.cpp | 6 +--- Source/Core/DiscIO/VolumeWiiCrypted.cpp | 44 +++++-------------------- 3 files changed, 16 insertions(+), 68 deletions(-) diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index fcba359931..10d1047e54 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -47,8 +47,6 @@ bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const std::string CVolumeGC::GetGameID() const { static const std::string NO_UID("NO_UID"); - if (m_pReader == nullptr) - return NO_UID; char ID[6]; @@ -64,7 +62,7 @@ std::string CVolumeGC::GetGameID() const Region CVolumeGC::GetRegion() const { u8 country_code; - if (!m_pReader->Read(3, 1, &country_code)) + if (!ReadSwapped(3, &country_code, false)) return Region::UNKNOWN_REGION; return RegionSwitchGC(country_code); @@ -73,7 +71,7 @@ Region CVolumeGC::GetRegion() const Country CVolumeGC::GetCountry() const { u8 country_code; - if (!m_pReader->Read(3, 1, &country_code)) + if (!ReadSwapped(3, &country_code, false)) return Country::COUNTRY_UNKNOWN; return CountrySwitch(country_code); @@ -81,9 +79,6 @@ Country CVolumeGC::GetCountry() const std::string CVolumeGC::GetMakerID() const { - if (m_pReader == nullptr) - return std::string(); - char makerID[2]; if (!Read(0x4, 0x2, (u8*)&makerID)) return std::string(); @@ -93,11 +88,8 @@ std::string CVolumeGC::GetMakerID() const u16 CVolumeGC::GetRevision() const { - if (!m_pReader) - return 0; - u8 revision; - if (!Read(7, 1, &revision)) + if (!ReadSwapped(7, &revision, false)) return 0; return revision; @@ -106,7 +98,7 @@ u16 CVolumeGC::GetRevision() const std::string CVolumeGC::GetInternalName() const { char name[0x60]; - if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) + if (Read(0x20, 0x60, (u8*)name)) return DecodeString(name); return ""; @@ -152,9 +144,6 @@ std::vector CVolumeGC::GetBanner(int* width, int* height) const u64 CVolumeGC::GetFSTSize() const { - if (m_pReader == nullptr) - return 0; - u32 size; if (!Read(0x428, 0x4, (u8*)&size)) return 0; @@ -164,9 +153,6 @@ u64 CVolumeGC::GetFSTSize() const std::string CVolumeGC::GetApploaderDate() const { - if (m_pReader == nullptr) - return std::string(); - char date[16]; if (!Read(0x2440, 0x10, (u8*)&date)) return std::string(); @@ -181,24 +167,18 @@ BlobType CVolumeGC::GetBlobType() const u64 CVolumeGC::GetSize() const { - if (m_pReader) - return m_pReader->GetDataSize(); - else - return 0; + return m_pReader ? m_pReader->GetDataSize() : 0; } u64 CVolumeGC::GetRawSize() const { - if (m_pReader) - return m_pReader->GetRawSize(); - else - return 0; + return m_pReader ? m_pReader->GetRawSize() : 0; } u8 CVolumeGC::GetDiscNumber() const { u8 disc_number; - Read(6, 1, &disc_number); + ReadSwapped(6, &disc_number, false); return disc_number; } diff --git a/Source/Core/DiscIO/VolumeWad.cpp b/Source/Core/DiscIO/VolumeWad.cpp index 01080c7b52..08a8f4656f 100644 --- a/Source/Core/DiscIO/VolumeWad.cpp +++ b/Source/Core/DiscIO/VolumeWad.cpp @@ -112,11 +112,7 @@ std::string CVolumeWAD::GetMakerID() const bool CVolumeWAD::GetTitleID(u64* buffer) const { - if (!Read(m_offset + 0x01DC, sizeof(u64), reinterpret_cast(buffer))) - return false; - - *buffer = Common::swap64(*buffer); - return true; + return ReadSwapped(m_offset + 0x01DC, buffer, false); } u16 CVolumeWAD::GetRevision() const diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index 541331bcc7..88ac4643f5 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -106,13 +106,7 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool de bool CVolumeWiiCrypted::GetTitleID(u64* buffer) const { - // Tik is at m_VolumeOffset size 0x2A4 - // TitleID offset in tik is 0x1DC - if (!Read(m_VolumeOffset + 0x1DC, sizeof(u64), reinterpret_cast(buffer), false)) - return false; - - *buffer = Common::swap64(*buffer); - return true; + return ReadSwapped(m_VolumeOffset + 0x1DC, buffer, false); } IOS::ES::TicketReader CVolumeWiiCrypted::GetTicket() const @@ -127,10 +121,9 @@ IOS::ES::TMDReader CVolumeWiiCrypted::GetTMD() const u32 tmd_size; u32 tmd_address; - Read(m_VolumeOffset + 0x2a4, sizeof(u32), (u8*)&tmd_size, false); - Read(m_VolumeOffset + 0x2a8, sizeof(u32), (u8*)&tmd_address, false); - tmd_size = Common::swap32(tmd_size); - tmd_address = Common::swap32(tmd_address) << 2; + ReadSwapped(m_VolumeOffset + 0x2a4, &tmd_size, false); + ReadSwapped(m_VolumeOffset + 0x2a8, &tmd_address, false); + tmd_address <<= 2; if (tmd_size > 1024 * 1024 * 4) { @@ -156,9 +149,6 @@ u64 CVolumeWiiCrypted::PartitionOffsetToRawOffset(u64 offset) const std::string CVolumeWiiCrypted::GetGameID() const { - if (m_pReader == nullptr) - return std::string(); - char ID[6]; if (!Read(0, 6, (u8*)ID, true)) @@ -204,9 +194,6 @@ Country CVolumeWiiCrypted::GetCountry() const std::string CVolumeWiiCrypted::GetMakerID() const { - if (m_pReader == nullptr) - return std::string(); - char makerID[2]; if (!Read(0x4, 0x2, (u8*)&makerID, true)) @@ -217,9 +204,6 @@ std::string CVolumeWiiCrypted::GetMakerID() const u16 CVolumeWiiCrypted::GetRevision() const { - if (!m_pReader) - return 0; - u8 revision; if (!ReadSwapped(7, &revision, true)) return 0; @@ -230,7 +214,7 @@ u16 CVolumeWiiCrypted::GetRevision() const std::string CVolumeWiiCrypted::GetInternalName() const { char name_buffer[0x60]; - if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)&name_buffer, true)) + if (Read(0x20, 0x60, (u8*)&name_buffer, true)) return DecodeString(name_buffer); return ""; @@ -259,9 +243,6 @@ std::vector CVolumeWiiCrypted::GetBanner(int* width, int* height) const u64 CVolumeWiiCrypted::GetFSTSize() const { - if (m_pReader == nullptr) - return 0; - u32 size; if (!Read(0x428, 0x4, (u8*)&size, true)) @@ -272,9 +253,6 @@ u64 CVolumeWiiCrypted::GetFSTSize() const std::string CVolumeWiiCrypted::GetApploaderDate() const { - if (m_pReader == nullptr) - return std::string(); - char date[16]; if (!Read(0x2440, 0x10, (u8*)&date, true)) @@ -302,18 +280,12 @@ BlobType CVolumeWiiCrypted::GetBlobType() const u64 CVolumeWiiCrypted::GetSize() const { - if (m_pReader) - return m_pReader->GetDataSize(); - else - return 0; + return m_pReader ? m_pReader->GetDataSize() : 0; } u64 CVolumeWiiCrypted::GetRawSize() const { - if (m_pReader) - return m_pReader->GetRawSize(); - else - return 0; + return m_pReader ? m_pReader->GetRawSize() : 0; } bool CVolumeWiiCrypted::CheckIntegrity() const @@ -332,7 +304,7 @@ bool CVolumeWiiCrypted::CheckIntegrity() const u8 clusterMDCrypted[0x400]; u8 clusterMD[0x400]; u8 IV[16] = {0}; - if (!m_pReader->Read(clusterOff, 0x400, clusterMDCrypted)) + if (!Read(clusterOff, 0x400, clusterMDCrypted, false)) { WARN_LOG(DISCIO, "Integrity Check: fail at cluster %d: could not read metadata", clusterID); return false;