2009-07-28 21:32:10 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2009-07-03 22:34:51 +00:00
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2013-03-03 22:51:26 +00:00
|
|
|
#include <algorithm>
|
2009-07-03 22:34:51 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "VolumeWad.h"
|
|
|
|
#include "StringUtil.h"
|
|
|
|
#include "MathUtil.h"
|
|
|
|
|
|
|
|
#define ALIGN_40(x) ROUND_UP(Common::swap32(x), 0x40)
|
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
|
|
|
CVolumeWAD::CVolumeWAD(IBlobReader* _pReader)
|
|
|
|
: m_pReader(_pReader), OpeningBnrOffset(0), hdr_size(0), cert_size(0), tick_size(0), tmd_size(0), data_size(0)
|
|
|
|
{
|
|
|
|
Read(0x00, 4, (u8*)&hdr_size);
|
|
|
|
Read(0x08, 4, (u8*)&cert_size);
|
|
|
|
Read(0x10, 4, (u8*)&tick_size);
|
|
|
|
Read(0x14, 4, (u8*)&tmd_size);
|
|
|
|
Read(0x18, 4, (u8*)&data_size);
|
|
|
|
|
2010-12-16 07:36:26 +00:00
|
|
|
u32 TmdOffset = ALIGN_40(hdr_size) + ALIGN_40(cert_size) + ALIGN_40(tick_size);
|
|
|
|
OpeningBnrOffset = TmdOffset + ALIGN_40(tmd_size) + ALIGN_40(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);
|
2011-05-05 22:38:07 +00:00
|
|
|
m_Country = GetSysMenuRegion(Common::swap16(titlever));
|
2010-12-16 07:36:26 +00:00
|
|
|
}
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CVolumeWAD::~CVolumeWAD()
|
|
|
|
{
|
|
|
|
delete m_pReader;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CVolumeWAD::Read(u64 _Offset, u64 _Length, u8* _pBuffer) const
|
|
|
|
{
|
|
|
|
if (m_pReader == NULL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
IVolume::ECountry CVolumeWAD::GetCountry() const
|
|
|
|
{
|
|
|
|
if (!m_pReader)
|
|
|
|
return COUNTRY_UNKNOWN;
|
|
|
|
|
2010-12-16 07:36:26 +00:00
|
|
|
return CountrySwitch(m_Country);
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeWAD::GetUniqueID() const
|
|
|
|
{
|
|
|
|
std::string temp = GetMakerID();
|
|
|
|
u32 Offset = ALIGN_40(hdr_size) + ALIGN_40(cert_size);
|
|
|
|
|
|
|
|
char GameCode[8];
|
|
|
|
if(!Read(Offset + 0x01E0, 4, (u8*)GameCode))
|
|
|
|
return "0";
|
|
|
|
|
|
|
|
GameCode[4] = temp.at(0);
|
|
|
|
GameCode[5] = temp.at(1);
|
|
|
|
GameCode[6] = 0;
|
|
|
|
|
|
|
|
return GameCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeWAD::GetMakerID() const
|
|
|
|
{
|
|
|
|
u32 Offset = ALIGN_40(hdr_size) + ALIGN_40(cert_size) + ALIGN_40(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)
|
|
|
|
return "00";
|
|
|
|
|
|
|
|
temp[2] = 0;
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CVolumeWAD::GetTitleID(u8* _pBuffer) const
|
|
|
|
{
|
|
|
|
u32 Offset = ALIGN_40(hdr_size) + ALIGN_40(cert_size);
|
|
|
|
|
|
|
|
if(!Read(Offset + 0x01DC, 8, _pBuffer))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-03 01:46:55 +00:00
|
|
|
std::vector<std::string> CVolumeWAD::GetNames() const
|
2011-12-19 05:42:20 +00:00
|
|
|
{
|
2013-03-03 01:46:55 +00:00
|
|
|
std::vector<std::string> names;
|
2011-12-19 05:42:20 +00:00
|
|
|
|
2013-03-03 01:46:55 +00:00
|
|
|
u32 footer_size;
|
2011-12-19 05:42:20 +00:00
|
|
|
if (!Read(0x1C, 4, (u8*)&footer_size))
|
|
|
|
{
|
2013-03-03 01:46:55 +00:00
|
|
|
return names;
|
2011-12-19 05:42:20 +00:00
|
|
|
}
|
2013-03-03 22:51:26 +00:00
|
|
|
|
|
|
|
footer_size = Common::swap32(footer_size);
|
|
|
|
|
2011-12-19 05:42:20 +00:00
|
|
|
//Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean
|
2013-03-03 22:51:26 +00:00
|
|
|
for (int i = 0; i != 10; ++i)
|
2011-12-19 05:42:20 +00:00
|
|
|
{
|
2013-03-03 22:51:26 +00:00
|
|
|
static const u32 string_length = 42;
|
|
|
|
static const u32 bytes_length = string_length * sizeof(u16);
|
|
|
|
|
|
|
|
u16 temp[string_length];
|
2011-12-19 05:42:20 +00:00
|
|
|
|
2013-03-03 22:51:26 +00:00
|
|
|
if (footer_size < 0xF1 || !Read(0x9C + (i * bytes_length) + OpeningBnrOffset, bytes_length, (u8*)&temp))
|
2011-12-19 05:42:20 +00:00
|
|
|
{
|
2013-03-03 01:46:55 +00:00
|
|
|
names.push_back("");
|
2011-12-19 05:42:20 +00:00
|
|
|
}
|
2013-03-03 22:51:26 +00:00
|
|
|
else
|
2011-12-19 05:42:20 +00:00
|
|
|
{
|
2013-03-03 22:51:26 +00: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());
|
|
|
|
|
|
|
|
names.push_back(UTF16ToUTF8(out_temp));
|
2011-12-19 05:42:20 +00:00
|
|
|
}
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2013-03-03 01:46:55 +00:00
|
|
|
return names;
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 CVolumeWAD::GetSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
|
|
|
return (size_t)m_pReader->GetDataSize();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|