2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2009-07-03 16:34:51 -06:00
|
|
|
|
2013-03-03 15:51:26 -07:00
|
|
|
#include <algorithm>
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <cstddef>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2009-07-03 16:34:51 -06:00
|
|
|
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/MathUtil.h"
|
|
|
|
#include "Common/StringUtil.h"
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "DiscIO/Blob.h"
|
|
|
|
#include "DiscIO/Volume.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DiscIO/VolumeWad.h"
|
2009-07-03 16:34:51 -06:00
|
|
|
|
|
|
|
#define ALIGN_40(x) ROUND_UP(Common::swap32(x), 0x40)
|
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
CVolumeWAD::CVolumeWAD(IBlobReader* _pReader)
|
2015-02-23 17:48:25 -07:00
|
|
|
: 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)
|
2009-07-03 16:34:51 -06:00
|
|
|
{
|
2014-09-01 13:48:02 -06:00
|
|
|
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);
|
|
|
|
|
2015-02-23 17:48:25 -07:00
|
|
|
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);
|
|
|
|
|
2010-12-16 00:36:26 -07:00
|
|
|
// read the last digit of the titleID in the ticket
|
2015-02-23 17:48:25 -07:00
|
|
|
Read(m_tmd_offset + 0x0193, 1, &m_Country);
|
2010-12-16 00:36:26 -07:00
|
|
|
if (m_Country == 2) // SYSMENU
|
|
|
|
{
|
|
|
|
u16 titlever = 0;
|
2015-02-23 17:48:25 -07:00
|
|
|
Read(m_tmd_offset + 0x01dc, 2, (u8*)&titlever);
|
2011-05-05 16:38:07 -06:00
|
|
|
m_Country = GetSysMenuRegion(Common::swap16(titlever));
|
2010-12-16 00:36:26 -07:00
|
|
|
}
|
2009-07-03 16:34:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
CVolumeWAD::~CVolumeWAD()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-12-28 02:35:48 -07:00
|
|
|
bool CVolumeWAD::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const
|
2009-07-03 16:34:51 -06:00
|
|
|
{
|
2014-12-28 02:35:48 -07:00
|
|
|
if (decrypt)
|
|
|
|
PanicAlertT("Tried to decrypt data from a non-Wii volume");
|
|
|
|
|
2014-03-09 14:14:26 -06:00
|
|
|
if (m_pReader == nullptr)
|
2009-07-03 16:34:51 -06:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
IVolume::ECountry CVolumeWAD::GetCountry() const
|
|
|
|
{
|
|
|
|
if (!m_pReader)
|
|
|
|
return COUNTRY_UNKNOWN;
|
|
|
|
|
2010-12-16 00:36:26 -07:00
|
|
|
return CountrySwitch(m_Country);
|
2009-07-03 16:34:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeWAD::GetUniqueID() const
|
|
|
|
{
|
|
|
|
std::string temp = GetMakerID();
|
|
|
|
|
|
|
|
char GameCode[8];
|
2015-02-23 17:48:25 -07:00
|
|
|
if (!Read(m_offset + 0x01E0, 4, (u8*)GameCode))
|
2009-07-03 16:34:51 -06:00
|
|
|
return "0";
|
|
|
|
|
|
|
|
GameCode[4] = temp.at(0);
|
|
|
|
GameCode[5] = temp.at(1);
|
|
|
|
GameCode[6] = 0;
|
|
|
|
|
|
|
|
return GameCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeWAD::GetMakerID() const
|
|
|
|
{
|
|
|
|
char temp[3] = {1};
|
|
|
|
// Some weird channels use 0x0000 in place of the MakerID, so we need a check there
|
2015-02-23 17:48:25 -07:00
|
|
|
if (!Read(0x198 + m_tmd_offset, 2, (u8*)temp) || temp[0] == 0 || temp[1] == 0)
|
2009-07-03 16:34:51 -06:00
|
|
|
return "00";
|
|
|
|
|
|
|
|
temp[2] = 0;
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CVolumeWAD::GetTitleID(u8* _pBuffer) const
|
|
|
|
{
|
2015-02-23 17:48:25 -07:00
|
|
|
if (!Read(m_offset + 0x01DC, 8, _pBuffer))
|
2009-07-03 16:34:51 -06:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-30 18:43:48 -07:00
|
|
|
int CVolumeWAD::GetRevision() const
|
|
|
|
{
|
|
|
|
u16 revision;
|
2015-02-23 17:48:25 -07:00
|
|
|
if (!m_pReader->Read(m_tmd_offset + 0x1dc, 2, (u8*)&revision))
|
2015-01-30 18:43:48 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return Common::swap16(revision);
|
|
|
|
}
|
|
|
|
|
2015-01-17 05:21:02 -07:00
|
|
|
bool CVolumeWAD::IsWadFile() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> CVolumeWAD::GetNames() const
|
2011-12-18 22:42:20 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> names;
|
2011-12-18 22:42:20 -07:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
u32 footer_size;
|
2011-12-18 22:42:20 -07:00
|
|
|
if (!Read(0x1C, 4, (u8*)&footer_size))
|
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
return names;
|
2011-12-18 22:42:20 -07:00
|
|
|
}
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-03 15:51:26 -07:00
|
|
|
footer_size = Common::swap32(footer_size);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2011-12-18 22:42:20 -07:00
|
|
|
//Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean
|
2013-03-03 15:51:26 -07:00
|
|
|
for (int i = 0; i != 10; ++i)
|
2011-12-18 22:42:20 -07:00
|
|
|
{
|
2013-03-03 15:51:26 -07:00
|
|
|
static const u32 string_length = 42;
|
|
|
|
static const u32 bytes_length = string_length * sizeof(u16);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-03 15:51:26 -07:00
|
|
|
u16 temp[string_length];
|
2011-12-18 22:42:20 -07:00
|
|
|
|
2014-09-01 13:48:02 -06:00
|
|
|
if (footer_size < 0xF1 || !Read(0x9C + (i * bytes_length) + m_opening_bnr_offset, bytes_length, (u8*)&temp))
|
2011-12-18 22:42:20 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
names.push_back("");
|
2011-12-18 22:42:20 -07:00
|
|
|
}
|
2013-03-03 15:51:26 -07:00
|
|
|
else
|
2011-12-18 22:42:20 -07:00
|
|
|
{
|
2013-03-03 15:51:26 -07:00
|
|
|
std::wstring out_temp;
|
|
|
|
out_temp.resize(string_length);
|
|
|
|
std::transform(temp, temp + out_temp.size(), out_temp.begin(), (u16(&)(u16))Common::swap16);
|
|
|
|
out_temp.erase(std::find(out_temp.begin(), out_temp.end(), 0x00), out_temp.end());
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-03 15:51:26 -07:00
|
|
|
names.push_back(UTF16ToUTF8(out_temp));
|
2011-12-18 22:42:20 -07:00
|
|
|
}
|
2009-07-03 16:34:51 -06:00
|
|
|
}
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
return names;
|
2009-07-03 16:34:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 CVolumeWAD::GetSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
2013-04-09 11:58:56 -06:00
|
|
|
return m_pReader->GetDataSize();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 CVolumeWAD::GetRawSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
|
|
|
return m_pReader->GetRawSize();
|
2009-07-03 16:34:51 -06:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|