2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2009-07-03 22:34:51 +00:00
|
|
|
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <cstddef>
|
2015-09-28 15:57:16 +00:00
|
|
|
#include <cstring>
|
2015-04-09 15:44:53 +00:00
|
|
|
#include <map>
|
2015-08-31 23:27:18 +00:00
|
|
|
#include <memory>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <string>
|
2015-08-31 23:27:18 +00:00
|
|
|
#include <utility>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <vector>
|
2009-07-03 22:34:51 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/MathUtil.h"
|
2015-09-26 21:13:07 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2015-09-26 21:13:07 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Blob.h"
|
|
|
|
#include "DiscIO/Volume.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DiscIO/VolumeWad.h"
|
2009-07-03 22:34:51 +00:00
|
|
|
|
|
|
|
#define ALIGN_40(x) ROUND_UP(Common::swap32(x), 0x40)
|
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2015-08-31 23:27:18 +00:00
|
|
|
CVolumeWAD::CVolumeWAD(std::unique_ptr<IBlobReader> reader)
|
|
|
|
: m_pReader(std::move(reader)), m_offset(0), m_tmd_offset(0), m_opening_bnr_offset(0),
|
2015-02-24 00:48:25 +00:00
|
|
|
m_hdr_size(0), m_cert_size(0), m_tick_size(0), m_tmd_size(0), m_data_size(0)
|
2009-07-03 22:34:51 +00:00
|
|
|
{
|
2015-02-28 22:24:02 +00:00
|
|
|
// Source: http://wiibrew.org/wiki/WAD_files
|
2014-09-01 19:48:02 +00: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-24 00:48:25 +00: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);
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CVolumeWAD::~CVolumeWAD()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-12-28 09:35:48 +00:00
|
|
|
bool CVolumeWAD::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const
|
2009-07-03 22:34:51 +00:00
|
|
|
{
|
2014-12-28 09:35:48 +00:00
|
|
|
if (decrypt)
|
|
|
|
PanicAlertT("Tried to decrypt data from a non-Wii volume");
|
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
if (m_pReader == nullptr)
|
2009-07-03 22:34:51 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
IVolume::ECountry CVolumeWAD::GetCountry() const
|
|
|
|
{
|
|
|
|
if (!m_pReader)
|
|
|
|
return COUNTRY_UNKNOWN;
|
|
|
|
|
2015-02-24 00:50:19 +00:00
|
|
|
// read the last digit of the titleID in the ticket
|
2015-02-24 01:43:29 +00:00
|
|
|
u8 country_code;
|
|
|
|
Read(m_tmd_offset + 0x0193, 1, &country_code);
|
2015-02-24 00:50:19 +00:00
|
|
|
|
2015-02-24 01:43:29 +00:00
|
|
|
if (country_code == 2) // SYSMENU
|
2015-02-24 00:50:19 +00:00
|
|
|
{
|
2015-03-01 02:42:16 +00:00
|
|
|
u16 title_version = 0;
|
|
|
|
Read(m_tmd_offset + 0x01dc, 2, (u8*)&title_version);
|
|
|
|
country_code = GetSysMenuRegion(Common::swap16(title_version));
|
2015-02-24 00:50:19 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 01:43:29 +00:00
|
|
|
return CountrySwitch(country_code);
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeWAD::GetUniqueID() const
|
|
|
|
{
|
2015-06-18 12:45:26 +00:00
|
|
|
char GameCode[6];
|
2015-02-24 00:48:25 +00:00
|
|
|
if (!Read(m_offset + 0x01E0, 4, (u8*)GameCode))
|
2009-07-03 22:34:51 +00:00
|
|
|
return "0";
|
|
|
|
|
2015-06-18 12:45:26 +00:00
|
|
|
std::string temp = GetMakerID();
|
2009-07-03 22:34:51 +00:00
|
|
|
GameCode[4] = temp.at(0);
|
|
|
|
GameCode[5] = temp.at(1);
|
|
|
|
|
2015-06-18 12:45:26 +00:00
|
|
|
return DecodeString(GameCode);
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeWAD::GetMakerID() const
|
|
|
|
{
|
2015-06-18 12:45:26 +00:00
|
|
|
char temp[2] = {1};
|
2009-07-03 22:34:51 +00:00
|
|
|
// Some weird channels use 0x0000 in place of the MakerID, so we need a check there
|
2015-02-24 00:48:25 +00:00
|
|
|
if (!Read(0x198 + m_tmd_offset, 2, (u8*)temp) || temp[0] == 0 || temp[1] == 0)
|
2009-07-03 22:34:51 +00:00
|
|
|
return "00";
|
|
|
|
|
2015-06-18 12:45:26 +00:00
|
|
|
return DecodeString(temp);
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-09-22 17:25:54 +00:00
|
|
|
bool CVolumeWAD::GetTitleID(u64* buffer) const
|
2009-07-03 22:34:51 +00:00
|
|
|
{
|
2015-09-22 17:25:54 +00:00
|
|
|
if (!Read(m_offset + 0x01DC, sizeof(u64), reinterpret_cast<u8*>(buffer)))
|
2009-07-03 22:34:51 +00:00
|
|
|
return false;
|
|
|
|
|
2015-09-22 17:25:54 +00:00
|
|
|
*buffer = Common::swap64(*buffer);
|
2009-07-03 22:34:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-29 19:14:02 +00:00
|
|
|
u16 CVolumeWAD::GetRevision() const
|
2015-01-31 01:43:48 +00:00
|
|
|
{
|
|
|
|
u16 revision;
|
2015-02-24 00:48:25 +00:00
|
|
|
if (!m_pReader->Read(m_tmd_offset + 0x1dc, 2, (u8*)&revision))
|
2015-01-31 01:43:48 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return Common::swap16(revision);
|
|
|
|
}
|
|
|
|
|
2015-06-04 14:26:36 +00:00
|
|
|
IVolume::EPlatform CVolumeWAD::GetVolumeType() const
|
2015-01-17 12:21:02 +00:00
|
|
|
{
|
2015-06-04 14:26:36 +00:00
|
|
|
return WII_WAD;
|
2015-01-17 12:21:02 +00:00
|
|
|
}
|
|
|
|
|
2015-05-10 17:09:11 +00:00
|
|
|
std::map<IVolume::ELanguage, std::string> CVolumeWAD::GetNames(bool prefer_long) const
|
2011-12-19 05:42:20 +00:00
|
|
|
{
|
2015-04-10 21:18:41 +00:00
|
|
|
std::vector<u8> name_data(NAMES_TOTAL_BYTES);
|
|
|
|
if (!Read(m_opening_bnr_offset + 0x9C, NAMES_TOTAL_BYTES, name_data.data()))
|
|
|
|
return std::map<IVolume::ELanguage, std::string>();
|
|
|
|
return ReadWiiNames(name_data);
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-12-03 16:29:59 +00:00
|
|
|
std::vector<u32> CVolumeWAD::GetBanner(int* width, int* height) const
|
|
|
|
{
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
|
|
|
|
u64 title_id;
|
|
|
|
if (!GetTitleID(&title_id))
|
|
|
|
return std::vector<u32>();
|
|
|
|
|
|
|
|
return GetWiiBanner(width, height, title_id);
|
|
|
|
}
|
|
|
|
|
2015-09-27 12:01:12 +00:00
|
|
|
BlobType CVolumeWAD::GetBlobType() const
|
2015-09-26 13:24:29 +00:00
|
|
|
{
|
2015-09-27 12:01:12 +00:00
|
|
|
return m_pReader ? m_pReader->GetBlobType() : BlobType::PLAIN;
|
2015-09-26 13:24:29 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 22:34:51 +00:00
|
|
|
u64 CVolumeWAD::GetSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
2013-04-09 17:58:56 +00:00
|
|
|
return m_pReader->GetDataSize();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 CVolumeWAD::GetRawSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
|
|
|
return m_pReader->GetRawSize();
|
2009-07-03 22:34:51 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|