2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 05:09:55 +02:00
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 06:30:24 +01:00
|
|
|
|
2017-08-02 18:16:56 +02:00
|
|
|
#include <cinttypes>
|
2014-02-21 01:47:53 +01:00
|
|
|
#include <cstddef>
|
2015-04-09 17:44:53 +02:00
|
|
|
#include <map>
|
2014-08-31 15:34:58 +02:00
|
|
|
#include <memory>
|
2017-06-04 10:33:14 +02:00
|
|
|
#include <optional>
|
2014-02-21 01:47:53 +01:00
|
|
|
#include <string>
|
2015-09-01 01:27:18 +02:00
|
|
|
#include <utility>
|
2014-02-21 01:47:53 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2016-10-30 23:39:12 +01:00
|
|
|
#include "Common/Assert.h"
|
2015-04-10 22:10:49 +02:00
|
|
|
#include "Common/ColorUtil.h"
|
2014-09-08 03:06:58 +02:00
|
|
|
#include "Common/CommonTypes.h"
|
2015-04-10 22:10:49 +02:00
|
|
|
#include "Common/Logging/Log.h"
|
2015-09-26 23:13:07 +02:00
|
|
|
#include "Common/MsgHandler.h"
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "Common/StringUtil.h"
|
2017-06-17 12:37:30 +02:00
|
|
|
|
2014-02-21 01:47:53 +01:00
|
|
|
#include "DiscIO/Blob.h"
|
2017-06-17 12:37:30 +02:00
|
|
|
#include "DiscIO/DiscExtractor.h"
|
2016-07-06 20:33:05 +02:00
|
|
|
#include "DiscIO/Enums.h"
|
2017-08-02 18:16:56 +02:00
|
|
|
#include "DiscIO/FileSystemGCWii.h"
|
2015-04-10 22:10:49 +02:00
|
|
|
#include "DiscIO/Filesystem.h"
|
2014-02-21 01:47:53 +01:00
|
|
|
#include "DiscIO/Volume.h"
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "DiscIO/VolumeGC.h"
|
2009-01-03 19:50:01 +01:00
|
|
|
|
2008-12-08 06:30:24 +01:00
|
|
|
namespace DiscIO
|
|
|
|
{
|
2018-05-30 08:37:13 +02:00
|
|
|
VolumeGC::VolumeGC(std::unique_ptr<BlobReader> reader) : m_reader(std::move(reader))
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
2018-05-30 08:37:13 +02:00
|
|
|
ASSERT(m_reader);
|
2017-08-02 18:16:56 +02:00
|
|
|
|
|
|
|
m_file_system = [this]() -> std::unique_ptr<FileSystem> {
|
|
|
|
auto file_system = std::make_unique<FileSystemGCWii>(this, PARTITION_NONE);
|
|
|
|
return file_system->IsValid() ? std::move(file_system) : nullptr;
|
|
|
|
};
|
2017-08-02 19:06:32 +02:00
|
|
|
|
|
|
|
m_converted_banner = [this] { return LoadBannerFile(); };
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
VolumeGC::~VolumeGC()
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-05-30 08:37:13 +02:00
|
|
|
bool VolumeGC::Read(u64 offset, u64 length, u8* buffer, const Partition& partition) const
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
2015-06-13 12:51:24 +02:00
|
|
|
if (partition != PARTITION_NONE)
|
|
|
|
return false;
|
2014-12-28 10:35:48 +01:00
|
|
|
|
2018-05-30 08:37:13 +02:00
|
|
|
return m_reader->Read(offset, length, buffer);
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2017-08-02 18:16:56 +02:00
|
|
|
const FileSystem* VolumeGC::GetFileSystem(const Partition& partition) const
|
|
|
|
{
|
|
|
|
return m_file_system->get();
|
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::string VolumeGC::GetGameID(const Partition& partition) const
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
|
|
|
static const std::string NO_UID("NO_UID");
|
|
|
|
|
2018-05-30 08:37:13 +02:00
|
|
|
char id[6];
|
2011-01-30 18:58:02 +01:00
|
|
|
|
2018-05-30 08:37:13 +02:00
|
|
|
if (!Read(0, sizeof(id), reinterpret_cast<u8*>(id), partition))
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
2011-01-13 03:05:58 +01:00
|
|
|
PanicAlertT("Failed to read unique ID from disc image");
|
2008-12-08 06:30:24 +01:00
|
|
|
return NO_UID;
|
|
|
|
}
|
|
|
|
|
2018-05-30 08:37:13 +02:00
|
|
|
return DecodeString(id);
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2019-02-23 17:49:06 +01:00
|
|
|
std::string VolumeGC::GetGameTDBID(const Partition& partition) const
|
|
|
|
{
|
|
|
|
const std::string game_id = GetGameID(partition);
|
|
|
|
|
|
|
|
// Don't return an ID for Datel discs that are using the game ID of NHL Hitz 2002
|
|
|
|
if (game_id == "GNHE5d" && !GetBootDOLOffset(*this, partition).has_value())
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return game_id;
|
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
Region VolumeGC::GetRegion() const
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
2017-07-16 13:53:22 +02:00
|
|
|
const std::optional<u32> region_code = ReadSwapped<u32>(0x458, PARTITION_NONE);
|
2017-07-16 14:52:17 +02:00
|
|
|
if (!region_code)
|
2018-03-31 14:04:13 +02:00
|
|
|
return Region::Unknown;
|
2017-07-16 14:52:17 +02:00
|
|
|
const Region region = static_cast<Region>(*region_code);
|
2018-03-31 14:04:13 +02:00
|
|
|
return region <= Region::PAL ? region : Region::Unknown;
|
2016-12-23 18:41:21 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
Country VolumeGC::GetCountry(const Partition& partition) const
|
2016-12-23 18:41:21 +01:00
|
|
|
{
|
2018-03-31 14:04:13 +02:00
|
|
|
// The 0 that we use as a default value is mapped to Country::Unknown and Region::Unknown
|
2017-07-16 14:25:55 +02:00
|
|
|
const u8 country = ReadSwapped<u8>(3, partition).value_or(0);
|
2017-07-16 13:53:22 +02:00
|
|
|
const Region region = GetRegion();
|
2019-03-22 20:47:05 +01:00
|
|
|
const std::optional<u16> revision = GetRevision();
|
2017-07-16 13:53:22 +02:00
|
|
|
|
2019-03-22 20:47:05 +01:00
|
|
|
if (CountryCodeToRegion(country, Platform::GameCubeDisc, region, revision) != region)
|
2017-07-16 13:53:22 +02:00
|
|
|
return TypicalCountryForRegion(region);
|
|
|
|
|
2019-03-22 20:47:05 +01:00
|
|
|
return CountryCodeToCountry(country, Platform::GameCubeDisc, region, revision);
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::string VolumeGC::GetMakerID(const Partition& partition) const
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
2018-05-30 08:37:13 +02:00
|
|
|
char maker_id[2];
|
2018-05-30 10:05:47 +02:00
|
|
|
if (!Read(0x4, sizeof(maker_id), reinterpret_cast<u8*>(&maker_id), partition))
|
2010-08-13 21:07:59 +02:00
|
|
|
return std::string();
|
2008-12-08 06:30:24 +01:00
|
|
|
|
2018-05-30 08:37:13 +02:00
|
|
|
return DecodeString(maker_id);
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::optional<u16> VolumeGC::GetRevision(const Partition& partition) const
|
2013-04-17 05:29:01 +02:00
|
|
|
{
|
2017-06-04 10:33:14 +02:00
|
|
|
std::optional<u8> revision = ReadSwapped<u8>(7, partition);
|
|
|
|
return revision ? *revision : std::optional<u16>();
|
2013-04-17 05:29:01 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::string VolumeGC::GetInternalName(const Partition& partition) const
|
2015-04-10 22:10:49 +02:00
|
|
|
{
|
|
|
|
char name[0x60];
|
2018-05-30 10:05:47 +02:00
|
|
|
if (Read(0x20, sizeof(name), reinterpret_cast<u8*>(name), partition))
|
2015-04-10 22:10:49 +02:00
|
|
|
return DecodeString(name);
|
2016-02-29 09:52:15 +01:00
|
|
|
|
|
|
|
return "";
|
2015-04-10 22:10:49 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::map<Language, std::string> VolumeGC::GetShortNames() const
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
2017-08-02 19:06:32 +02:00
|
|
|
return m_converted_banner->short_names;
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::map<Language, std::string> VolumeGC::GetLongNames() const
|
2015-04-10 22:10:49 +02:00
|
|
|
{
|
2017-08-02 19:06:32 +02:00
|
|
|
return m_converted_banner->long_names;
|
2015-04-10 22:10:49 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::map<Language, std::string> VolumeGC::GetShortMakers() const
|
2015-04-10 22:10:49 +02:00
|
|
|
{
|
2017-08-02 19:06:32 +02:00
|
|
|
return m_converted_banner->short_makers;
|
2016-02-29 09:52:15 +01:00
|
|
|
}
|
2015-04-10 22:10:49 +02:00
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::map<Language, std::string> VolumeGC::GetLongMakers() const
|
2016-02-29 09:52:15 +01:00
|
|
|
{
|
2017-08-02 19:06:32 +02:00
|
|
|
return m_converted_banner->long_makers;
|
2016-02-29 09:52:15 +01:00
|
|
|
}
|
2015-04-10 22:10:49 +02:00
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::map<Language, std::string> VolumeGC::GetDescriptions() const
|
2016-02-29 09:52:15 +01:00
|
|
|
{
|
2017-08-02 19:06:32 +02:00
|
|
|
return m_converted_banner->descriptions;
|
2015-04-10 22:10:49 +02:00
|
|
|
}
|
|
|
|
|
2018-03-10 22:41:49 +01:00
|
|
|
std::vector<u32> VolumeGC::GetBanner(u32* width, u32* height) const
|
2015-04-10 22:10:49 +02:00
|
|
|
{
|
2017-08-02 19:06:32 +02:00
|
|
|
*width = m_converted_banner->image_width;
|
|
|
|
*height = m_converted_banner->image_height;
|
|
|
|
return m_converted_banner->image_buffer;
|
2015-04-10 22:10:49 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::string VolumeGC::GetApploaderDate(const Partition& partition) const
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
|
|
|
char date[16];
|
2018-05-30 10:05:47 +02:00
|
|
|
if (!Read(0x2440, sizeof(date), reinterpret_cast<u8*>(&date), partition))
|
2010-08-13 21:07:59 +02:00
|
|
|
return std::string();
|
2008-12-08 06:30:24 +01:00
|
|
|
|
2015-06-18 14:45:26 +02:00
|
|
|
return DecodeString(date);
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
BlobType VolumeGC::GetBlobType() const
|
2015-09-26 15:24:29 +02:00
|
|
|
{
|
2018-05-30 08:37:13 +02:00
|
|
|
return m_reader->GetBlobType();
|
2015-09-26 15:24:29 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
u64 VolumeGC::GetSize() const
|
2008-12-08 06:30:24 +01:00
|
|
|
{
|
2018-05-30 08:37:13 +02:00
|
|
|
return m_reader->GetDataSize();
|
2008-12-08 06:30:24 +01:00
|
|
|
}
|
|
|
|
|
2019-03-21 22:20:23 +01:00
|
|
|
bool VolumeGC::IsSizeAccurate() const
|
|
|
|
{
|
|
|
|
return m_reader->IsDataSizeAccurate();
|
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
u64 VolumeGC::GetRawSize() const
|
2013-04-09 19:58:56 +02:00
|
|
|
{
|
2018-05-30 08:37:13 +02:00
|
|
|
return m_reader->GetRawSize();
|
2013-04-09 19:58:56 +02:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
std::optional<u8> VolumeGC::GetDiscNumber(const Partition& partition) const
|
2013-01-26 03:28:04 +01:00
|
|
|
{
|
2017-06-04 10:33:14 +02:00
|
|
|
return ReadSwapped<u8>(6, partition);
|
2013-01-26 03:28:04 +01:00
|
|
|
}
|
|
|
|
|
2017-06-06 11:49:01 +02:00
|
|
|
Platform VolumeGC::GetVolumeType() const
|
2015-06-04 16:26:36 +02:00
|
|
|
{
|
2018-03-31 14:04:13 +02:00
|
|
|
return Platform::GameCubeDisc;
|
2015-06-04 16:26:36 +02:00
|
|
|
}
|
|
|
|
|
2017-08-02 19:06:32 +02:00
|
|
|
VolumeGC::ConvertedGCBanner VolumeGC::LoadBannerFile() const
|
2013-03-03 23:51:26 +01:00
|
|
|
{
|
2016-02-29 09:52:15 +01:00
|
|
|
GCBanner banner_file;
|
2017-08-02 18:16:56 +02:00
|
|
|
const u64 file_size = ReadFile(*this, PARTITION_NONE, "opening.bnr",
|
|
|
|
reinterpret_cast<u8*>(&banner_file), sizeof(GCBanner));
|
|
|
|
if (file_size < 4)
|
2015-07-30 15:06:23 +02:00
|
|
|
{
|
|
|
|
WARN_LOG(DISCIO, "Could not read opening.bnr.");
|
2017-08-02 19:06:32 +02:00
|
|
|
return {}; // Return early so that we don't access the uninitialized banner_file.id
|
2015-07-30 15:06:23 +02:00
|
|
|
}
|
2016-02-29 09:52:15 +01:00
|
|
|
|
2017-08-02 18:16:56 +02:00
|
|
|
constexpr u32 BNR1_MAGIC = 0x31524e42;
|
|
|
|
constexpr u32 BNR2_MAGIC = 0x32524e42;
|
2016-02-29 09:52:15 +01: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;
|
2015-04-10 22:10:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-19 06:49:47 +01:00
|
|
|
WARN_LOG(DISCIO, "Invalid opening.bnr. Type: %0x Size: %0" PRIx64, banner_file.id, file_size);
|
2017-08-02 19:06:32 +02:00
|
|
|
return {};
|
2015-04-10 22:10:49 +02:00
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-08-02 19:06:32 +02:00
|
|
|
return ExtractBannerInformation(banner_file, is_bnr1);
|
2013-03-03 23:51:26 +01:00
|
|
|
}
|
|
|
|
|
2017-08-02 19:06:32 +02:00
|
|
|
VolumeGC::ConvertedGCBanner VolumeGC::ExtractBannerInformation(const GCBanner& banner_file,
|
|
|
|
bool is_bnr1) const
|
2015-05-10 19:09:11 +02:00
|
|
|
{
|
2017-08-02 19:06:32 +02:00
|
|
|
ConvertedGCBanner banner;
|
|
|
|
|
2015-05-10 19:09:11 +02:00
|
|
|
u32 number_of_languages = 0;
|
2018-03-31 14:04:13 +02:00
|
|
|
Language start_language = Language::Unknown;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2016-02-29 09:52:15 +01:00
|
|
|
if (is_bnr1) // NTSC
|
2015-05-10 19:09:11 +02:00
|
|
|
{
|
|
|
|
number_of_languages = 1;
|
2018-03-31 14:04:13 +02:00
|
|
|
start_language = GetRegion() == Region::NTSC_J ? Language::Japanese : Language::English;
|
2016-02-29 09:52:15 +01:00
|
|
|
}
|
|
|
|
else // PAL
|
|
|
|
{
|
2015-05-10 19:09:11 +02:00
|
|
|
number_of_languages = 6;
|
2018-03-31 14:04:13 +02:00
|
|
|
start_language = Language::English;
|
2015-05-10 19:09:11 +02:00
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-08-02 19:06:32 +02:00
|
|
|
banner.image_width = GC_BANNER_WIDTH;
|
|
|
|
banner.image_height = GC_BANNER_HEIGHT;
|
|
|
|
banner.image_buffer = std::vector<u32>(GC_BANNER_WIDTH * GC_BANNER_HEIGHT);
|
2018-05-28 02:58:08 +02:00
|
|
|
Common::Decode5A3Image(banner.image_buffer.data(), banner_file.image, GC_BANNER_WIDTH,
|
2018-05-28 02:55:36 +02:00
|
|
|
GC_BANNER_HEIGHT);
|
2016-02-29 09:52:15 +01:00
|
|
|
|
2015-05-10 19:09:11 +02:00
|
|
|
for (u32 i = 0; i < number_of_languages; ++i)
|
|
|
|
{
|
2016-02-29 09:52:15 +01:00
|
|
|
const GCBannerInformation& info = banner_file.information[i];
|
2016-07-06 20:33:05 +02:00
|
|
|
Language language = static_cast<Language>(static_cast<int>(start_language) + i);
|
2016-02-29 09:52:15 +01:00
|
|
|
|
|
|
|
std::string description = DecodeString(info.description);
|
|
|
|
if (!description.empty())
|
2017-08-02 19:06:32 +02:00
|
|
|
banner.descriptions.emplace(language, description);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2016-02-29 09:52:15 +01:00
|
|
|
std::string short_name = DecodeString(info.short_name);
|
|
|
|
if (!short_name.empty())
|
2017-08-02 19:06:32 +02:00
|
|
|
banner.short_names.emplace(language, short_name);
|
2016-02-29 09:52:15 +01:00
|
|
|
|
|
|
|
std::string long_name = DecodeString(info.long_name);
|
|
|
|
if (!long_name.empty())
|
2017-08-02 19:06:32 +02:00
|
|
|
banner.long_names.emplace(language, long_name);
|
2016-02-29 09:52:15 +01:00
|
|
|
|
|
|
|
std::string short_maker = DecodeString(info.short_maker);
|
|
|
|
if (!short_maker.empty())
|
2017-08-02 19:06:32 +02:00
|
|
|
banner.short_makers.emplace(language, short_maker);
|
2016-02-29 09:52:15 +01:00
|
|
|
|
|
|
|
std::string long_maker = DecodeString(info.long_maker);
|
|
|
|
if (!long_maker.empty())
|
2017-08-02 19:06:32 +02:00
|
|
|
banner.long_makers.emplace(language, long_maker);
|
2016-02-29 09:52:15 +01:00
|
|
|
}
|
2017-08-02 19:06:32 +02:00
|
|
|
|
|
|
|
return banner;
|
2015-05-10 19:09:11 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 20:43:19 +02:00
|
|
|
VolumeGC::ConvertedGCBanner::ConvertedGCBanner() = default;
|
|
|
|
VolumeGC::ConvertedGCBanner::~ConvertedGCBanner() = default;
|
2019-05-06 01:48:12 +02:00
|
|
|
} // namespace DiscIO
|