2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 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.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <cstddef>
|
2015-04-09 15:44:53 +00:00
|
|
|
#include <map>
|
2014-08-31 13:34:58 +00:00
|
|
|
#include <memory>
|
2017-06-04 08:33:14 +00:00
|
|
|
#include <optional>
|
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>
|
|
|
|
|
2016-10-30 22:39:12 +00:00
|
|
|
#include "Common/Assert.h"
|
2015-04-10 20:10:49 +00:00
|
|
|
#include "Common/ColorUtil.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"
|
2017-06-17 10:37:30 +00:00
|
|
|
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Blob.h"
|
2017-06-17 10:37:30 +00:00
|
|
|
#include "DiscIO/DiscExtractor.h"
|
2016-07-06 18:33:05 +00:00
|
|
|
#include "DiscIO/Enums.h"
|
2015-04-10 20:10:49 +00:00
|
|
|
#include "DiscIO/Filesystem.h"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DiscIO/VolumeGC.h"
|
2009-01-03 18:50:01 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
namespace DiscIO
|
|
|
|
{
|
2017-06-06 09:49:01 +00:00
|
|
|
VolumeGC::VolumeGC(std::unique_ptr<BlobReader> reader) : m_pReader(std::move(reader))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
_assert_(m_pReader);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
VolumeGC::~VolumeGC()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
bool VolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, const Partition& partition) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2015-06-13 10:51:24 +00:00
|
|
|
if (partition != PARTITION_NONE)
|
|
|
|
return false;
|
2014-12-28 09:35:48 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::string VolumeGC::GetGameID(const Partition& partition) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
static const std::string NO_UID("NO_UID");
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
char ID[6];
|
2011-01-30 17:58:02 +00:00
|
|
|
|
2015-06-13 10:51:24 +00:00
|
|
|
if (!Read(0, sizeof(ID), reinterpret_cast<u8*>(ID), partition))
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
|
|
|
PanicAlertT("Failed to read unique ID from disc image");
|
|
|
|
return NO_UID;
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return DecodeString(ID);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
Region VolumeGC::GetRegion() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2017-07-16 11:53:22 +00:00
|
|
|
const std::optional<u32> region_code = ReadSwapped<u32>(0x458, PARTITION_NONE);
|
2017-07-16 12:52:17 +00:00
|
|
|
if (!region_code)
|
|
|
|
return Region::UNKNOWN_REGION;
|
|
|
|
const Region region = static_cast<Region>(*region_code);
|
|
|
|
return region <= Region::PAL ? region : Region::UNKNOWN_REGION;
|
2016-12-23 17:41:21 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
Country VolumeGC::GetCountry(const Partition& partition) const
|
2016-12-23 17:41:21 +00:00
|
|
|
{
|
2017-07-16 11:53:22 +00:00
|
|
|
// The 0 that we use as a default value is mapped to COUNTRY_UNKNOWN and UNKNOWN_REGION
|
2017-07-16 12:25:55 +00:00
|
|
|
const u8 country = ReadSwapped<u8>(3, partition).value_or(0);
|
2017-07-16 11:53:22 +00:00
|
|
|
const Region region = GetRegion();
|
|
|
|
|
2017-07-16 12:25:55 +00:00
|
|
|
// Korean GC releases use NTSC-J.
|
|
|
|
// E is normally used for America, but it's also used for English-language Korean GC releases.
|
|
|
|
// K is used by games that are in the Korean language.
|
|
|
|
// W means Taiwan for Wii games, but on the GC, it's used for English-language Korean releases.
|
|
|
|
// (There doesn't seem to be any pattern to which of E and W is used for Korean GC releases.)
|
|
|
|
if (region == Region::NTSC_J && (country == 'E' || country == 'K' || country == 'W'))
|
|
|
|
return Country::COUNTRY_KOREA;
|
|
|
|
|
|
|
|
if (RegionSwitchGC(country) != region)
|
2017-07-16 11:53:22 +00:00
|
|
|
return TypicalCountryForRegion(region);
|
|
|
|
|
2017-07-16 12:25:55 +00:00
|
|
|
return CountrySwitch(country);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::string VolumeGC::GetMakerID(const Partition& partition) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
char makerID[2];
|
2015-06-13 10:51:24 +00:00
|
|
|
if (!Read(0x4, 0x2, (u8*)&makerID, partition))
|
2016-06-24 08:43:46 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return DecodeString(makerID);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::optional<u16> VolumeGC::GetRevision(const Partition& partition) const
|
2013-04-17 03:29:01 +00:00
|
|
|
{
|
2017-06-04 08:33:14 +00:00
|
|
|
std::optional<u8> revision = ReadSwapped<u8>(7, partition);
|
|
|
|
return revision ? *revision : std::optional<u16>();
|
2013-04-17 03:29:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::string VolumeGC::GetInternalName(const Partition& partition) const
|
2015-04-10 20:10:49 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
char name[0x60];
|
2015-06-13 10:51:24 +00:00
|
|
|
if (Read(0x20, 0x60, (u8*)name, partition))
|
2016-06-24 08:43:46 +00:00
|
|
|
return DecodeString(name);
|
2016-02-29 08:52:15 +00:00
|
|
|
|
|
|
|
return "";
|
2015-04-10 20:10:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::map<Language, std::string> VolumeGC::GetShortNames() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-02-29 08:52:15 +00:00
|
|
|
LoadBannerFile();
|
|
|
|
return m_short_names;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::map<Language, std::string> VolumeGC::GetLongNames() const
|
2015-04-10 20:10:49 +00:00
|
|
|
{
|
2016-02-29 08:52:15 +00:00
|
|
|
LoadBannerFile();
|
|
|
|
return m_long_names;
|
2015-04-10 20:10:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::map<Language, std::string> VolumeGC::GetShortMakers() const
|
2015-04-10 20:10:49 +00:00
|
|
|
{
|
2016-02-29 08:52:15 +00:00
|
|
|
LoadBannerFile();
|
|
|
|
return m_short_makers;
|
|
|
|
}
|
2015-04-10 20:10:49 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::map<Language, std::string> VolumeGC::GetLongMakers() const
|
2016-02-29 08:52:15 +00:00
|
|
|
{
|
|
|
|
LoadBannerFile();
|
|
|
|
return m_long_makers;
|
|
|
|
}
|
2015-04-10 20:10:49 +00:00
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::map<Language, std::string> VolumeGC::GetDescriptions() const
|
2016-02-29 08:52:15 +00:00
|
|
|
{
|
|
|
|
LoadBannerFile();
|
|
|
|
return m_descriptions;
|
2015-04-10 20:10:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::vector<u32> VolumeGC::GetBanner(int* width, int* height) const
|
2015-04-10 20:10:49 +00:00
|
|
|
{
|
2016-02-29 08:52:15 +00:00
|
|
|
LoadBannerFile();
|
|
|
|
*width = m_image_width;
|
|
|
|
*height = m_image_height;
|
|
|
|
return m_image_buffer;
|
2015-04-10 20:10:49 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::string VolumeGC::GetApploaderDate(const Partition& partition) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
char date[16];
|
2015-06-13 10:51:24 +00:00
|
|
|
if (!Read(0x2440, 0x10, (u8*)&date, partition))
|
2016-06-24 08:43:46 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
return DecodeString(date);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
BlobType VolumeGC::GetBlobType() const
|
2015-09-26 13:24:29 +00:00
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
return m_pReader->GetBlobType();
|
2015-09-26 13:24:29 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
u64 VolumeGC::GetSize() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
return m_pReader->GetDataSize();
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
u64 VolumeGC::GetRawSize() const
|
2013-04-09 17:58:56 +00:00
|
|
|
{
|
2016-10-30 22:39:12 +00:00
|
|
|
return m_pReader->GetRawSize();
|
2013-04-09 17:58:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
std::optional<u8> VolumeGC::GetDiscNumber(const Partition& partition) const
|
2013-01-26 02:28:04 +00:00
|
|
|
{
|
2017-06-04 08:33:14 +00:00
|
|
|
return ReadSwapped<u8>(6, partition);
|
2013-01-26 02:28:04 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
Platform VolumeGC::GetVolumeType() const
|
2015-06-04 14:26:36 +00:00
|
|
|
{
|
2016-07-06 18:33:05 +00:00
|
|
|
return Platform::GAMECUBE_DISC;
|
2015-06-04 14:26:36 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
void VolumeGC::LoadBannerFile() const
|
2013-03-03 22:51:26 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// If opening.bnr has been loaded already, return immediately
|
2016-02-29 08:52:15 +00:00
|
|
|
if (m_banner_loaded)
|
|
|
|
return;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-06-28 16:05:44 +00:00
|
|
|
m_banner_loaded = true;
|
|
|
|
|
2016-02-29 08:52:15 +00:00
|
|
|
GCBanner banner_file;
|
2017-06-06 09:49:01 +00:00
|
|
|
std::unique_ptr<FileSystem> file_system(CreateFileSystem(this, PARTITION_NONE));
|
2015-06-03 11:19:28 +00:00
|
|
|
if (!file_system)
|
|
|
|
return;
|
2016-02-29 08:52:15 +00:00
|
|
|
|
2015-08-08 17:59:33 +00:00
|
|
|
std::unique_ptr<FileInfo> file_info = file_system->FindFileInfo("opening.bnr");
|
2015-07-30 13:06:23 +00:00
|
|
|
if (!file_info)
|
|
|
|
return;
|
|
|
|
|
|
|
|
size_t file_size = static_cast<size_t>(file_info->GetSize());
|
2016-02-29 08:52:15 +00:00
|
|
|
constexpr int BNR1_MAGIC = 0x31524e42;
|
|
|
|
constexpr int BNR2_MAGIC = 0x32524e42;
|
|
|
|
if (file_size != BNR1_SIZE && file_size != BNR2_SIZE)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-02-29 08:52:15 +00:00
|
|
|
WARN_LOG(DISCIO, "Invalid opening.bnr. Size: %0zx", file_size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-17 10:37:30 +00:00
|
|
|
if (file_size != ReadFile(*this, PARTITION_NONE, file_info.get(),
|
|
|
|
reinterpret_cast<u8*>(&banner_file), file_size))
|
2015-07-30 13:06:23 +00:00
|
|
|
{
|
|
|
|
WARN_LOG(DISCIO, "Could not read opening.bnr.");
|
|
|
|
return;
|
|
|
|
}
|
2016-02-29 08:52:15 +00:00
|
|
|
|
|
|
|
bool is_bnr1;
|
|
|
|
if (banner_file.id == BNR1_MAGIC && file_size == BNR1_SIZE)
|
|
|
|
{
|
|
|
|
is_bnr1 = true;
|
|
|
|
}
|
|
|
|
else if (banner_file.id == BNR2_MAGIC && file_size == BNR2_SIZE)
|
|
|
|
{
|
|
|
|
is_bnr1 = false;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-29 08:52:15 +00:00
|
|
|
WARN_LOG(DISCIO, "Invalid opening.bnr. Type: %0x Size: %0zx", banner_file.id, file_size);
|
|
|
|
return;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2016-02-29 08:52:15 +00:00
|
|
|
ExtractBannerInformation(banner_file, is_bnr1);
|
2013-03-03 22:51:26 +00:00
|
|
|
}
|
|
|
|
|
2017-06-06 09:49:01 +00:00
|
|
|
void VolumeGC::ExtractBannerInformation(const GCBanner& banner_file, bool is_bnr1) const
|
2015-05-10 17:09:11 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
u32 number_of_languages = 0;
|
2016-07-06 18:33:05 +00:00
|
|
|
Language start_language = Language::LANGUAGE_UNKNOWN;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-29 08:52:15 +00:00
|
|
|
if (is_bnr1) // NTSC
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2016-12-23 17:41:21 +00:00
|
|
|
bool is_japanese = GetRegion() == Region::NTSC_J;
|
2016-06-24 08:43:46 +00:00
|
|
|
number_of_languages = 1;
|
2016-07-06 18:33:05 +00:00
|
|
|
start_language = is_japanese ? Language::LANGUAGE_JAPANESE : Language::LANGUAGE_ENGLISH;
|
2016-02-29 08:52:15 +00:00
|
|
|
}
|
|
|
|
else // PAL
|
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
number_of_languages = 6;
|
2016-07-06 18:33:05 +00:00
|
|
|
start_language = Language::LANGUAGE_ENGLISH;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2016-02-29 08:52:15 +00:00
|
|
|
m_image_width = GC_BANNER_WIDTH;
|
|
|
|
m_image_height = GC_BANNER_HEIGHT;
|
|
|
|
m_image_buffer = std::vector<u32>(m_image_width * m_image_height);
|
|
|
|
ColorUtil::decode5A3image(m_image_buffer.data(), banner_file.image, m_image_width,
|
|
|
|
m_image_height);
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
for (u32 i = 0; i < number_of_languages; ++i)
|
|
|
|
{
|
2016-02-29 08:52:15 +00:00
|
|
|
const GCBannerInformation& info = banner_file.information[i];
|
2016-07-06 18:33:05 +00:00
|
|
|
Language language = static_cast<Language>(static_cast<int>(start_language) + i);
|
2016-02-29 08:52:15 +00:00
|
|
|
|
|
|
|
std::string description = DecodeString(info.description);
|
|
|
|
if (!description.empty())
|
|
|
|
m_descriptions[language] = description;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-02-29 08:52:15 +00:00
|
|
|
std::string short_name = DecodeString(info.short_name);
|
|
|
|
if (!short_name.empty())
|
|
|
|
m_short_names[language] = short_name;
|
|
|
|
|
|
|
|
std::string long_name = DecodeString(info.long_name);
|
|
|
|
if (!long_name.empty())
|
|
|
|
m_long_names[language] = long_name;
|
|
|
|
|
|
|
|
std::string short_maker = DecodeString(info.short_maker);
|
|
|
|
if (!short_maker.empty())
|
|
|
|
m_short_makers[language] = short_maker;
|
|
|
|
|
|
|
|
std::string long_maker = DecodeString(info.long_maker);
|
|
|
|
if (!long_maker.empty())
|
|
|
|
m_long_makers[language] = long_maker;
|
|
|
|
}
|
2015-05-10 17:09:11 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
} // namespace
|