mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Merge pull request #2113 from Stevoisiak/VolumeCleanup
Basic volume code cleanup
This commit is contained in:
@ -77,8 +77,8 @@ bool CISOFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
|
||||
}
|
||||
|
||||
out_ptr += bytes_to_read;
|
||||
offset += bytes_to_read;
|
||||
nbytes -= bytes_to_read;
|
||||
offset += bytes_to_read;
|
||||
nbytes -= bytes_to_read;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -240,14 +240,14 @@ bool CNANDContentLoader::Initialize(const std::string& _rName)
|
||||
m_Content.resize(m_numEntries);
|
||||
|
||||
|
||||
for (u32 i=0; i<m_numEntries; i++)
|
||||
for (u32 i=0; i < m_numEntries; i++)
|
||||
{
|
||||
SNANDContent& rContent = m_Content[i];
|
||||
|
||||
rContent.m_ContentID = Common::swap32(pTMD + 0x01e4 + 0x24*i);
|
||||
rContent.m_Index = Common::swap16(pTMD + 0x01e8 + 0x24*i);
|
||||
rContent.m_Type = Common::swap16(pTMD + 0x01ea + 0x24*i);
|
||||
rContent.m_Size= (u32)Common::swap64(pTMD + 0x01ec + 0x24*i);
|
||||
rContent.m_Size = (u32)Common::swap64(pTMD + 0x01ec + 0x24*i);
|
||||
memcpy(rContent.m_SHA1Hash, pTMD + 0x01f4 + 0x24*i, 20);
|
||||
memcpy(rContent.m_Header, pTMD + 0x01e4 + 0x24*i, 36);
|
||||
|
||||
@ -271,7 +271,7 @@ bool CNANDContentLoader::Initialize(const std::string& _rName)
|
||||
else
|
||||
rContent.m_Filename = StringFromFormat("%s/%08x.app", m_Path.c_str(), rContent.m_ContentID);
|
||||
|
||||
// Be graceful about incorrect tmds.
|
||||
// Be graceful about incorrect TMDs.
|
||||
if (File::Exists(rContent.m_Filename))
|
||||
rContent.m_Size = (u32) File::GetSize(rContent.m_Filename);
|
||||
}
|
||||
@ -355,7 +355,7 @@ void CNANDContentLoader::RemoveTitle() const
|
||||
INFO_LOG(DISCIO, "RemoveTitle %08x/%08x", (u32)(m_TitleID >> 32), (u32)m_TitleID);
|
||||
if (IsValid())
|
||||
{
|
||||
// remove tmd?
|
||||
// remove TMD?
|
||||
for (u32 i = 0; i < m_numEntries; i++)
|
||||
{
|
||||
if (!(m_Content[i].m_Type & 0x8000)) // skip shared apps
|
||||
@ -455,7 +455,7 @@ u64 CNANDContentManager::Install_WiiWAD(std::string &fileName)
|
||||
|
||||
u64 TitleID = ContentLoader.GetTitleID();
|
||||
|
||||
//copy WAD's tmd header and contents to content directory
|
||||
//copy WAD's TMD header and contents to content directory
|
||||
|
||||
std::string ContentPath(Common::GetTitleContentPath(TitleID));
|
||||
std::string TMDFileName(Common::GetTMDFileName(TitleID));
|
||||
|
@ -35,12 +35,12 @@ public:
|
||||
virtual std::vector<std::string> GetNames() const = 0;
|
||||
virtual u32 GetFSTSize() const = 0;
|
||||
virtual std::string GetApploaderDate() const = 0;
|
||||
|
||||
virtual bool IsDiscTwo() const { return false; }
|
||||
virtual bool IsWiiDisc() const { return false; }
|
||||
virtual bool IsWadFile() const { return false; }
|
||||
virtual bool SupportsIntegrityCheck() const { return false; }
|
||||
virtual bool CheckIntegrity() const { return false; }
|
||||
|
||||
virtual bool ChangePartition(u64 offset) { return false; }
|
||||
|
||||
// Increment CACHE_REVISION if the code below is modified (ISOFile.cpp & GameFile.cpp)
|
||||
@ -71,7 +71,7 @@ public:
|
||||
};
|
||||
|
||||
// Generic Switch function for all volumes
|
||||
IVolume::ECountry CountrySwitch(u8 CountryCode);
|
||||
IVolume::ECountry CountrySwitch(u8 country_code);
|
||||
u8 GetSysMenuRegion(u16 _TitleVersion);
|
||||
|
||||
} // namespace
|
||||
|
@ -12,9 +12,9 @@
|
||||
// Increment CACHE_REVISION if the code below is modified (ISOFile.cpp & GameFile.cpp)
|
||||
namespace DiscIO
|
||||
{
|
||||
IVolume::ECountry CountrySwitch(u8 CountryCode)
|
||||
IVolume::ECountry CountrySwitch(u8 country_code)
|
||||
{
|
||||
switch (CountryCode)
|
||||
switch (country_code)
|
||||
{
|
||||
// Region free - Uses European flag as placeholder
|
||||
case 'A':
|
||||
@ -68,8 +68,8 @@ IVolume::ECountry CountrySwitch(u8 CountryCode)
|
||||
return IVolume::COUNTRY_TAIWAN;
|
||||
|
||||
default:
|
||||
if (CountryCode > 'A') // Silently ignore IOS wads
|
||||
WARN_LOG(DISCIO, "Unknown Country Code! %c", CountryCode);
|
||||
if (country_code > 'A') // Silently ignore IOS wads
|
||||
WARN_LOG(DISCIO, "Unknown Country Code! %c", country_code);
|
||||
return IVolume::COUNTRY_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
@ -140,9 +140,9 @@ bool CVolumeDirectory::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt
|
||||
if (!reader->Read(fileOffset, fileBytes, _pBuffer))
|
||||
return false;
|
||||
|
||||
_Length -= fileBytes;
|
||||
_Length -= fileBytes;
|
||||
_pBuffer += fileBytes;
|
||||
_Offset += fileBytes;
|
||||
_Offset += fileBytes;
|
||||
}
|
||||
|
||||
++fileIter;
|
||||
@ -174,9 +174,9 @@ void CVolumeDirectory::SetUniqueID(const std::string& id)
|
||||
|
||||
IVolume::ECountry CVolumeDirectory::GetCountry() const
|
||||
{
|
||||
u8 CountryCode = m_diskHeader[3];
|
||||
u8 country_code = m_diskHeader[3];
|
||||
|
||||
return CountrySwitch(CountryCode);
|
||||
return CountrySwitch(country_code);
|
||||
}
|
||||
|
||||
std::string CVolumeDirectory::GetMakerID() const
|
||||
|
@ -108,7 +108,7 @@ private:
|
||||
u32 debug_flag;
|
||||
u32 track_location;
|
||||
u32 track_size;
|
||||
u32 countrycode;
|
||||
u32 country_code;
|
||||
u32 unknown;
|
||||
u32 unknown2;
|
||||
|
||||
@ -121,7 +121,7 @@ private:
|
||||
debug_flag = 0;
|
||||
track_location = 0;
|
||||
track_size = 0;
|
||||
countrycode = 0;
|
||||
country_code = 0;
|
||||
unknown = 0;
|
||||
unknown2 = 0;
|
||||
}
|
||||
|
@ -61,10 +61,10 @@ IVolume::ECountry CVolumeGC::GetCountry() const
|
||||
if (!m_pReader)
|
||||
return COUNTRY_UNKNOWN;
|
||||
|
||||
u8 CountryCode;
|
||||
m_pReader->Read(3, 1, &CountryCode);
|
||||
u8 country_code;
|
||||
m_pReader->Read(3, 1, &country_code);
|
||||
|
||||
return CountrySwitch(CountryCode);
|
||||
return CountrySwitch(country_code);
|
||||
}
|
||||
|
||||
std::string CVolumeGC::GetMakerID() const
|
||||
@ -149,9 +149,9 @@ u64 CVolumeGC::GetRawSize() const
|
||||
|
||||
bool CVolumeGC::IsDiscTwo() const
|
||||
{
|
||||
bool discTwo = false;
|
||||
Read(6,1, (u8*) &discTwo);
|
||||
return discTwo;
|
||||
u8 disc_two_check;
|
||||
Read(6, 1, &disc_two_check);
|
||||
return (disc_two_check == 1);
|
||||
}
|
||||
|
||||
CVolumeGC::StringDecoder CVolumeGC::GetStringDecoder(ECountry country)
|
||||
|
@ -30,10 +30,12 @@ public:
|
||||
std::vector<std::string> GetNames() const override;
|
||||
u32 GetFSTSize() const override;
|
||||
std::string GetApploaderDate() const override;
|
||||
|
||||
bool IsDiscTwo() const override;
|
||||
|
||||
ECountry GetCountry() const override;
|
||||
u64 GetSize() const override;
|
||||
u64 GetRawSize() const override;
|
||||
bool IsDiscTwo() const override;
|
||||
|
||||
typedef std::string(*StringDecoder)(const std::string&);
|
||||
|
||||
|
@ -19,25 +19,19 @@
|
||||
namespace DiscIO
|
||||
{
|
||||
CVolumeWAD::CVolumeWAD(IBlobReader* _pReader)
|
||||
: m_pReader(_pReader), m_opening_bnr_offset(0), m_hdr_size(0)
|
||||
, m_cert_size(0), m_tick_size(0), m_tmd_size(0), m_data_size(0)
|
||||
: m_pReader(_pReader), m_offset(0), m_tmd_offset(0), m_opening_bnr_offset(0),
|
||||
m_hdr_size(0), m_cert_size(0), m_tick_size(0), m_tmd_size(0), m_data_size(0)
|
||||
{
|
||||
// Source: http://wiibrew.org/wiki/WAD_files
|
||||
Read(0x00, 4, (u8*)&m_hdr_size);
|
||||
Read(0x08, 4, (u8*)&m_cert_size);
|
||||
Read(0x10, 4, (u8*)&m_tick_size);
|
||||
Read(0x14, 4, (u8*)&m_tmd_size);
|
||||
Read(0x18, 4, (u8*)&m_data_size);
|
||||
|
||||
u32 TmdOffset = ALIGN_40(m_hdr_size) + ALIGN_40(m_cert_size) + ALIGN_40(m_tick_size);
|
||||
m_opening_bnr_offset = TmdOffset + ALIGN_40(m_tmd_size) + ALIGN_40(m_data_size);
|
||||
// read the last digit of the titleID in the ticket
|
||||
Read(TmdOffset + 0x0193, 1, &m_Country);
|
||||
if (m_Country == 2) // SYSMENU
|
||||
{
|
||||
u16 titlever = 0;
|
||||
Read(TmdOffset + 0x01dc, 2, (u8*)&titlever);
|
||||
m_Country = GetSysMenuRegion(Common::swap16(titlever));
|
||||
}
|
||||
m_offset = ALIGN_40(m_hdr_size) + ALIGN_40(m_cert_size);
|
||||
m_tmd_offset = ALIGN_40(m_hdr_size) + ALIGN_40(m_cert_size) + ALIGN_40(m_tick_size);
|
||||
m_opening_bnr_offset = m_tmd_offset + ALIGN_40(m_tmd_size) + ALIGN_40(m_data_size);
|
||||
}
|
||||
|
||||
CVolumeWAD::~CVolumeWAD()
|
||||
@ -60,16 +54,26 @@ IVolume::ECountry CVolumeWAD::GetCountry() const
|
||||
if (!m_pReader)
|
||||
return COUNTRY_UNKNOWN;
|
||||
|
||||
return CountrySwitch(m_Country);
|
||||
// read the last digit of the titleID in the ticket
|
||||
u8 country_code;
|
||||
Read(m_tmd_offset + 0x0193, 1, &country_code);
|
||||
|
||||
if (country_code == 2) // SYSMENU
|
||||
{
|
||||
u16 title_version = 0;
|
||||
Read(m_tmd_offset + 0x01dc, 2, (u8*)&title_version);
|
||||
country_code = GetSysMenuRegion(Common::swap16(title_version));
|
||||
}
|
||||
|
||||
return CountrySwitch(country_code);
|
||||
}
|
||||
|
||||
std::string CVolumeWAD::GetUniqueID() const
|
||||
{
|
||||
std::string temp = GetMakerID();
|
||||
u32 Offset = ALIGN_40(m_hdr_size) + ALIGN_40(m_cert_size);
|
||||
|
||||
char GameCode[8];
|
||||
if (!Read(Offset + 0x01E0, 4, (u8*)GameCode))
|
||||
if (!Read(m_offset + 0x01E0, 4, (u8*)GameCode))
|
||||
return "0";
|
||||
|
||||
GameCode[4] = temp.at(0);
|
||||
@ -81,11 +85,9 @@ std::string CVolumeWAD::GetUniqueID() const
|
||||
|
||||
std::string CVolumeWAD::GetMakerID() const
|
||||
{
|
||||
u32 Offset = ALIGN_40(m_hdr_size) + ALIGN_40(m_cert_size) + ALIGN_40(m_tick_size);
|
||||
|
||||
char temp[3] = {1};
|
||||
// Some weird channels use 0x0000 in place of the MakerID, so we need a check there
|
||||
if (!Read(0x198 + Offset, 2, (u8*)temp) || temp[0] == 0 || temp[1] == 0)
|
||||
if (!Read(0x198 + m_tmd_offset, 2, (u8*)temp) || temp[0] == 0 || temp[1] == 0)
|
||||
return "00";
|
||||
|
||||
temp[2] = 0;
|
||||
@ -95,9 +97,7 @@ std::string CVolumeWAD::GetMakerID() const
|
||||
|
||||
bool CVolumeWAD::GetTitleID(u8* _pBuffer) const
|
||||
{
|
||||
u32 Offset = ALIGN_40(m_hdr_size) + ALIGN_40(m_cert_size);
|
||||
|
||||
if (!Read(Offset + 0x01DC, 8, _pBuffer))
|
||||
if (!Read(m_offset + 0x01DC, 8, _pBuffer))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@ -105,10 +105,8 @@ bool CVolumeWAD::GetTitleID(u8* _pBuffer) const
|
||||
|
||||
int CVolumeWAD::GetRevision() const
|
||||
{
|
||||
u32 TmdOffset = ALIGN_40(m_hdr_size) + ALIGN_40(m_cert_size) + ALIGN_40(m_tick_size);
|
||||
|
||||
u16 revision;
|
||||
if (!m_pReader->Read(TmdOffset + 0x1dc, 2, (u8*)&revision))
|
||||
if (!m_pReader->Read(m_tmd_offset + 0x1dc, 2, (u8*)&revision))
|
||||
return 0;
|
||||
|
||||
return Common::swap16(revision);
|
||||
|
@ -29,24 +29,27 @@ public:
|
||||
bool GetTitleID(u8* _pBuffer) const override;
|
||||
std::string GetUniqueID() const override;
|
||||
std::string GetMakerID() const override;
|
||||
int GetRevision() const override;
|
||||
std::vector<std::string> GetNames() const override;
|
||||
u32 GetFSTSize() const override { return 0; }
|
||||
std::string GetApploaderDate() const override { return "0"; }
|
||||
|
||||
bool IsWadFile() const override;
|
||||
|
||||
ECountry GetCountry() const override;
|
||||
u64 GetSize() const override;
|
||||
u64 GetRawSize() const override;
|
||||
int GetRevision() const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IBlobReader> m_pReader;
|
||||
u32 m_offset;
|
||||
u32 m_tmd_offset;
|
||||
u32 m_opening_bnr_offset;
|
||||
u32 m_hdr_size;
|
||||
u32 m_cert_size;
|
||||
u32 m_tick_size;
|
||||
u32 m_tmd_size;
|
||||
u32 m_data_size;
|
||||
u8 m_Country;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -95,7 +95,7 @@ bool CVolumeWiiCrypted::Read(u64 _ReadOffset, u64 _Length, u8* _pBuffer, bool de
|
||||
memcpy(_pBuffer, &m_LastDecryptedBlock[Offset], (size_t)CopySize);
|
||||
|
||||
// Update offsets
|
||||
_Length -= CopySize;
|
||||
_Length -= CopySize;
|
||||
_pBuffer += CopySize;
|
||||
_ReadOffset += CopySize;
|
||||
}
|
||||
@ -158,10 +158,10 @@ IVolume::ECountry CVolumeWiiCrypted::GetCountry() const
|
||||
if (!m_pReader)
|
||||
return COUNTRY_UNKNOWN;
|
||||
|
||||
u8 CountryCode;
|
||||
m_pReader->Read(3, 1, &CountryCode);
|
||||
u8 country_code;
|
||||
m_pReader->Read(3, 1, &country_code);
|
||||
|
||||
return CountrySwitch(CountryCode);
|
||||
return CountrySwitch(country_code);
|
||||
}
|
||||
|
||||
std::string CVolumeWiiCrypted::GetMakerID() const
|
||||
@ -237,6 +237,14 @@ bool CVolumeWiiCrypted::IsWiiDisc() const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CVolumeWiiCrypted::IsDiscTwo() const
|
||||
{
|
||||
u8 disc_two_check;
|
||||
m_pReader->Read(6, 1, &disc_two_check);
|
||||
return (disc_two_check == 1);
|
||||
}
|
||||
|
||||
|
||||
u64 CVolumeWiiCrypted::GetSize() const
|
||||
{
|
||||
if (m_pReader)
|
||||
|
@ -29,19 +29,22 @@ public:
|
||||
virtual std::unique_ptr<u8[]> GetTMD(u32 *_sz) const override;
|
||||
std::string GetUniqueID() const override;
|
||||
std::string GetMakerID() const override;
|
||||
int GetRevision() const override;
|
||||
std::vector<std::string> GetNames() const override;
|
||||
u32 GetFSTSize() const override;
|
||||
std::string GetApploaderDate() const override;
|
||||
|
||||
bool IsDiscTwo() const override;
|
||||
bool IsWiiDisc() const override;
|
||||
bool SupportsIntegrityCheck() const override { return true; }
|
||||
bool CheckIntegrity() const override;
|
||||
bool ChangePartition(u64 offset) override;
|
||||
|
||||
ECountry GetCountry() const override;
|
||||
u64 GetSize() const override;
|
||||
u64 GetRawSize() const override;
|
||||
int GetRevision() const override;
|
||||
|
||||
bool SupportsIntegrityCheck() const override { return true; }
|
||||
bool CheckIntegrity() const override;
|
||||
|
||||
bool ChangePartition(u64 offset) override;
|
||||
|
||||
private:
|
||||
static const unsigned int s_block_header_size = 0x0400;
|
||||
|
Reference in New Issue
Block a user