Merge pull request #4733 from leoetlino/expose-wad-tmd

VolumeWad: Implement GetTMD()
This commit is contained in:
Matthew Parlane 2017-01-24 09:20:14 +13:00 committed by GitHub
commit 86b758d7ca
2 changed files with 23 additions and 12 deletions

View File

@ -25,19 +25,17 @@ namespace DiscIO
CVolumeWAD::CVolumeWAD(std::unique_ptr<IBlobReader> reader) : m_reader(std::move(reader))
{
// 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);
ReadSwapped(0x00, &m_hdr_size, false);
ReadSwapped(0x08, &m_cert_size, false);
ReadSwapped(0x10, &m_tick_size, false);
ReadSwapped(0x14, &m_tmd_size, false);
ReadSwapped(0x18, &m_data_size, false);
m_offset = Common::AlignUp(Common::swap32(m_hdr_size), 0x40) +
Common::AlignUp(Common::swap32(m_cert_size), 0x40);
m_tmd_offset = Common::AlignUp(Common::swap32(m_hdr_size), 0x40) +
Common::AlignUp(Common::swap32(m_cert_size), 0x40) +
Common::AlignUp(Common::swap32(m_tick_size), 0x40);
m_opening_bnr_offset = m_tmd_offset + Common::AlignUp(Common::swap32(m_tmd_size), 0x40) +
Common::AlignUp(Common::swap32(m_data_size), 0x40);
m_offset = Common::AlignUp(m_hdr_size, 0x40) + Common::AlignUp(m_cert_size, 0x40);
m_tmd_offset = Common::AlignUp(m_hdr_size, 0x40) + Common::AlignUp(m_cert_size, 0x40) +
Common::AlignUp(m_tick_size, 0x40);
m_opening_bnr_offset =
m_tmd_offset + Common::AlignUp(m_tmd_size, 0x40) + Common::AlignUp(m_data_size, 0x40);
}
CVolumeWAD::~CVolumeWAD()
@ -81,6 +79,18 @@ Country CVolumeWAD::GetCountry() const
return CountrySwitch(country_code);
}
std::vector<u8> CVolumeWAD::GetTMD() const
{
if (m_tmd_size > 1024 * 1024 * 4)
{
ERROR_LOG(DISCIO, "TMD is too large: %u bytes", m_tmd_size);
return {};
}
std::vector<u8> buffer(m_tmd_size);
Read(m_tmd_offset, m_tmd_size, buffer.data(), false);
return buffer;
}
std::string CVolumeWAD::GetGameID() const
{
char GameCode[6];

View File

@ -32,6 +32,7 @@ public:
~CVolumeWAD();
bool Read(u64 offset, u64 length, u8* buffer, bool decrypt = false) const override;
bool GetTitleID(u64* buffer) const override;
std::vector<u8> GetTMD() const override;
std::string GetGameID() const override;
std::string GetMakerID() const override;
u16 GetRevision() const override;