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>
|
2017-03-16 09:28:17 +00:00
|
|
|
#include <locale>
|
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
|
|
|
|
2016-11-27 10:56:22 +00:00
|
|
|
#include "Common/Align.h"
|
2016-10-30 22:39:12 +00:00
|
|
|
#include "Common/Assert.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2016-06-24 08:43:46 +00:00
|
|
|
#include "Common/Logging/Log.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"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Blob.h"
|
2016-07-06 18:33:05 +00:00
|
|
|
#include "DiscIO/Enums.h"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DiscIO/VolumeWad.h"
|
2009-07-03 22:34:51 +00:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2017-01-23 17:06:08 +00:00
|
|
|
CVolumeWAD::CVolumeWAD(std::unique_ptr<IBlobReader> reader) : m_reader(std::move(reader))
|
2009-07-03 22:34:51 +00:00
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
_assert_(m_reader);
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Source: http://wiibrew.org/wiki/WAD_files
|
2017-05-19 19:31:47 +00:00
|
|
|
m_reader->ReadSwapped(0x00, &m_hdr_size);
|
|
|
|
m_reader->ReadSwapped(0x08, &m_cert_size);
|
|
|
|
m_reader->ReadSwapped(0x10, &m_tick_size);
|
|
|
|
m_reader->ReadSwapped(0x14, &m_tmd_size);
|
|
|
|
m_reader->ReadSwapped(0x18, &m_data_size);
|
2017-01-23 17:33:49 +00:00
|
|
|
|
|
|
|
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);
|
2017-02-11 07:57:47 +00:00
|
|
|
|
2017-05-26 09:23:11 +00:00
|
|
|
if (!IOS::ES::IsValidTMDSize(m_tmd_size))
|
2017-02-11 07:57:47 +00:00
|
|
|
{
|
|
|
|
ERROR_LOG(DISCIO, "TMD is too large: %u bytes", m_tmd_size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<u8> tmd_buffer(m_tmd_size);
|
2015-06-13 10:51:24 +00:00
|
|
|
Read(m_tmd_offset, m_tmd_size, tmd_buffer.data());
|
2017-02-11 07:57:47 +00:00
|
|
|
m_tmd.SetBytes(std::move(tmd_buffer));
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CVolumeWAD::~CVolumeWAD()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-06-13 10:51:24 +00:00
|
|
|
bool CVolumeWAD::Read(u64 offset, u64 length, u8* buffer, const Partition& partition) const
|
2009-07-03 22:34:51 +00:00
|
|
|
{
|
2015-06-13 10:51:24 +00:00
|
|
|
if (partition != PARTITION_NONE)
|
|
|
|
return false;
|
2014-12-28 09:35:48 +00:00
|
|
|
|
2017-01-23 17:06:08 +00:00
|
|
|
return m_reader->Read(offset, length, buffer);
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 17:41:21 +00:00
|
|
|
Region CVolumeWAD::GetRegion() const
|
2009-07-03 22:34:51 +00:00
|
|
|
{
|
2017-02-11 07:57:47 +00:00
|
|
|
if (!m_tmd.IsValid())
|
2016-12-23 17:41:21 +00:00
|
|
|
return Region::UNKNOWN_REGION;
|
2017-02-11 07:57:47 +00:00
|
|
|
return m_tmd.GetRegion();
|
2016-12-23 17:41:21 +00:00
|
|
|
}
|
2009-07-03 22:34:51 +00:00
|
|
|
|
2015-06-13 10:51:24 +00:00
|
|
|
Country CVolumeWAD::GetCountry(const Partition& partition) const
|
2016-12-23 17:41:21 +00:00
|
|
|
{
|
2017-02-11 07:57:47 +00:00
|
|
|
if (!m_tmd.IsValid())
|
2016-12-23 17:41:21 +00:00
|
|
|
return Country::COUNTRY_UNKNOWN;
|
2015-02-24 00:50:19 +00:00
|
|
|
|
2017-02-11 07:57:47 +00:00
|
|
|
u8 country_code = static_cast<u8>(m_tmd.GetTitleId() & 0xff);
|
2016-06-24 08:43:46 +00:00
|
|
|
if (country_code == 2) // SYSMENU
|
2017-03-17 20:16:59 +00:00
|
|
|
return TypicalCountryForRegion(GetSysMenuRegion(m_tmd.GetTitleVersion()));
|
2015-02-24 00:50:19 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return CountrySwitch(country_code);
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 16:33:36 +00:00
|
|
|
const IOS::ES::TMDReader& CVolumeWAD::GetTMD(const Partition& partition) const
|
2017-01-23 17:33:49 +00:00
|
|
|
{
|
2017-02-11 07:57:47 +00:00
|
|
|
return m_tmd;
|
2017-01-23 17:33:49 +00:00
|
|
|
}
|
|
|
|
|
2015-06-13 10:51:24 +00:00
|
|
|
std::string CVolumeWAD::GetGameID(const Partition& partition) const
|
2009-07-03 22:34:51 +00:00
|
|
|
{
|
2017-03-16 09:28:17 +00:00
|
|
|
return m_tmd.GetGameID();
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-06-13 10:51:24 +00:00
|
|
|
std::string CVolumeWAD::GetMakerID(const Partition& partition) const
|
2009-07-03 22:34:51 +00:00
|
|
|
{
|
2017-03-16 09:28:17 +00:00
|
|
|
char temp[2];
|
2015-06-13 10:51:24 +00:00
|
|
|
if (!Read(0x198 + m_tmd_offset, 2, (u8*)temp, partition))
|
2017-03-16 09:28:17 +00:00
|
|
|
return "00";
|
|
|
|
|
|
|
|
// Some weird channels use 0x0000 in place of the MakerID, so we need a check here
|
|
|
|
const std::locale& c_locale = std::locale::classic();
|
|
|
|
if (!std::isprint(temp[0], c_locale) || !std::isprint(temp[1], c_locale))
|
2016-06-24 08:43:46 +00:00
|
|
|
return "00";
|
2009-07-03 22:34:51 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return DecodeString(temp);
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 19:29:08 +00:00
|
|
|
std::optional<u64> CVolumeWAD::GetTitleID(const Partition& partition) const
|
2009-07-03 22:34:51 +00:00
|
|
|
{
|
2017-06-03 19:29:08 +00:00
|
|
|
u64 title_id;
|
|
|
|
if (!ReadSwapped(m_offset + 0x01DC, &title_id, partition))
|
|
|
|
return {};
|
|
|
|
return title_id;
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2015-06-13 10:51:24 +00:00
|
|
|
u16 CVolumeWAD::GetRevision(const Partition& partition) const
|
2015-01-31 01:43:48 +00:00
|
|
|
{
|
2017-02-11 07:57:47 +00:00
|
|
|
if (!m_tmd.IsValid())
|
2016-06-24 08:43:46 +00:00
|
|
|
return 0;
|
2015-01-31 01:43:48 +00:00
|
|
|
|
2017-02-11 07:57:47 +00:00
|
|
|
return m_tmd.GetTitleVersion();
|
2015-01-31 01:43:48 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 18:33:05 +00:00
|
|
|
Platform CVolumeWAD::GetVolumeType() const
|
2015-01-17 12:21:02 +00:00
|
|
|
{
|
2016-07-06 18:33:05 +00:00
|
|
|
return Platform::WII_WAD;
|
2015-01-17 12:21:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-06 18:33:05 +00:00
|
|
|
std::map<Language, std::string> CVolumeWAD::GetLongNames() const
|
2011-12-19 05:42:20 +00:00
|
|
|
{
|
2017-03-18 14:01:03 +00:00
|
|
|
if (!m_tmd.IsValid() || !IOS::ES::IsChannel(m_tmd.GetTitleId()))
|
|
|
|
return {};
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
std::vector<u8> name_data(NAMES_TOTAL_BYTES);
|
|
|
|
if (!Read(m_opening_bnr_offset + 0x9C, NAMES_TOTAL_BYTES, name_data.data()))
|
2016-07-06 18:33:05 +00:00
|
|
|
return std::map<Language, std::string>();
|
2016-06-24 08:43:46 +00:00
|
|
|
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
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
2015-12-03 16:29:59 +00:00
|
|
|
|
2017-06-03 19:29:08 +00:00
|
|
|
const std::optional<u64> title_id = GetTitleID();
|
|
|
|
if (!title_id)
|
2016-06-24 08:43:46 +00:00
|
|
|
return std::vector<u32>();
|
2015-12-03 16:29:59 +00:00
|
|
|
|
2017-06-03 19:29:08 +00:00
|
|
|
return GetWiiBanner(width, height, *title_id);
|
2015-12-03 16:29:59 +00:00
|
|
|
}
|
|
|
|
|
2015-09-27 12:01:12 +00:00
|
|
|
BlobType CVolumeWAD::GetBlobType() const
|
2015-09-26 13:24:29 +00:00
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
return m_reader->GetBlobType();
|
2015-09-26 13:24:29 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 22:34:51 +00:00
|
|
|
u64 CVolumeWAD::GetSize() const
|
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
return m_reader->GetDataSize();
|
2013-04-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 CVolumeWAD::GetRawSize() const
|
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
return m_reader->GetRawSize();
|
2009-07-03 22:34:51 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
} // namespace
|