Skip to content

Commit

Permalink
Merge pull request #5056 from JosJuice/use-readswapped
Browse files Browse the repository at this point in the history
Volume: Use ReadSwapped more
  • Loading branch information
degasus committed Mar 13, 2017
2 parents 1eba936 + 135733e commit f63d402
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 68 deletions.
34 changes: 7 additions & 27 deletions Source/Core/DiscIO/VolumeGC.cpp
Expand Up @@ -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];

Expand All @@ -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);
Expand All @@ -73,17 +71,14 @@ 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);
}

std::string CVolumeGC::GetMakerID() const
{
if (m_pReader == nullptr)
return std::string();

char makerID[2];
if (!Read(0x4, 0x2, (u8*)&makerID))
return std::string();
Expand All @@ -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;
Expand All @@ -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 "";
Expand Down Expand Up @@ -152,9 +144,6 @@ std::vector<u32> 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;
Expand All @@ -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();
Expand All @@ -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;
}

Expand Down
6 changes: 1 addition & 5 deletions Source/Core/DiscIO/VolumeWad.cpp
Expand Up @@ -112,11 +112,7 @@ std::string CVolumeWAD::GetMakerID() const

bool CVolumeWAD::GetTitleID(u64* buffer) const
{
if (!Read(m_offset + 0x01DC, sizeof(u64), reinterpret_cast<u8*>(buffer)))
return false;

*buffer = Common::swap64(*buffer);
return true;
return ReadSwapped(m_offset + 0x01DC, buffer, false);
}

u16 CVolumeWAD::GetRevision() const
Expand Down
44 changes: 8 additions & 36 deletions Source/Core/DiscIO/VolumeWiiCrypted.cpp
Expand Up @@ -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<u8*>(buffer), false))
return false;

*buffer = Common::swap64(*buffer);
return true;
return ReadSwapped(m_VolumeOffset + 0x1DC, buffer, false);
}

IOS::ES::TicketReader CVolumeWiiCrypted::GetTicket() const
Expand All @@ -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)
{
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand All @@ -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;
Expand All @@ -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 "";
Expand Down Expand Up @@ -259,9 +243,6 @@ std::vector<u32> 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))
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit f63d402

Please sign in to comment.