2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2020-10-21 12:58:08 -06:00
|
|
|
#include "DiscIO/VolumeGC.h"
|
|
|
|
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <cstddef>
|
2015-04-09 09:44:53 -06:00
|
|
|
#include <map>
|
2014-08-31 07:34:58 -06:00
|
|
|
#include <memory>
|
2017-06-04 02:33:14 -06:00
|
|
|
#include <optional>
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <string>
|
2015-08-31 17:27:18 -06:00
|
|
|
#include <utility>
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <vector>
|
|
|
|
|
2020-06-07 14:58:03 -06:00
|
|
|
#include <mbedtls/sha1.h>
|
|
|
|
|
2016-10-30 16:39:12 -06:00
|
|
|
#include "Common/Assert.h"
|
2015-04-10 14:10:49 -06:00
|
|
|
#include "Common/ColorUtil.h"
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2015-04-10 14:10:49 -06:00
|
|
|
#include "Common/Logging/Log.h"
|
2015-09-26 15:13:07 -06:00
|
|
|
#include "Common/MsgHandler.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/StringUtil.h"
|
2017-06-17 04:37:30 -06:00
|
|
|
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "DiscIO/Blob.h"
|
2017-06-17 04:37:30 -06:00
|
|
|
#include "DiscIO/DiscExtractor.h"
|
2021-03-09 12:06:34 -07:00
|
|
|
#include "DiscIO/DiscUtils.h"
|
2016-07-06 12:33:05 -06:00
|
|
|
#include "DiscIO/Enums.h"
|
2017-08-02 10:16:56 -06:00
|
|
|
#include "DiscIO/FileSystemGCWii.h"
|
2015-04-10 14:10:49 -06:00
|
|
|
#include "DiscIO/Filesystem.h"
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "DiscIO/Volume.h"
|
2009-01-03 11:50:01 -07:00
|
|
|
|
2008-07-12 11:40:22 -06:00
|
|
|
namespace DiscIO
|
|
|
|
{
|
2018-05-30 00:37:13 -06:00
|
|
|
VolumeGC::VolumeGC(std::unique_ptr<BlobReader> reader) : m_reader(std::move(reader))
|
2008-07-12 11:40:22 -06:00
|
|
|
{
|
2018-05-30 00:37:13 -06:00
|
|
|
ASSERT(m_reader);
|
2017-08-02 10:16:56 -06: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 11:06:32 -06:00
|
|
|
|
|
|
|
m_converted_banner = [this] { return LoadBannerFile(); };
|
2008-07-12 11:40:22 -06:00
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
VolumeGC::~VolumeGC()
|
2008-07-12 11:40:22 -06:00
|
|
|
{
|
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2018-05-30 00:37:13 -06:00
|
|
|
bool VolumeGC::Read(u64 offset, u64 length, u8* buffer, const Partition& partition) const
|
2008-07-12 11:40:22 -06:00
|
|
|
{
|
2015-06-13 04:51:24 -06:00
|
|
|
if (partition != PARTITION_NONE)
|
|
|
|
return false;
|
2014-12-28 02:35:48 -07:00
|
|
|
|
2018-05-30 00:37:13 -06:00
|
|
|
return m_reader->Read(offset, length, buffer);
|
2008-07-12 11:40:22 -06:00
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2017-08-02 10:16:56 -06:00
|
|
|
const FileSystem* VolumeGC::GetFileSystem(const Partition& partition) const
|
|
|
|
{
|
|
|
|
return m_file_system->get();
|
|
|
|
}
|
|
|
|
|
2019-02-23 09:49:06 -07:00
|
|
|
std::string VolumeGC::GetGameTDBID(const Partition& partition) const
|
|
|
|
{
|
2022-03-15 11:56:49 -06:00
|
|
|
// Datel discs for the GameCube can have one of two different game IDs:
|
|
|
|
//
|
|
|
|
// 1: GNHE5d. (Yes, with a lowercase d.) This game ID is used not only for
|
|
|
|
// all kinds of Datel discs, but also for the licensed release NHL Hitz 2002.
|
|
|
|
//
|
|
|
|
// 2: DTLX01. This game ID is used for a few late Datel releases. Both Action Replay
|
|
|
|
// and FreeLoader are known to have been released under this game ID.
|
|
|
|
//
|
|
|
|
// Since no game ID used for Datel discs uniquely represents one product,
|
|
|
|
// never use the game ID of a Datel disc for looking up the title or cover art.
|
|
|
|
if (IsDatelDisc())
|
|
|
|
return "";
|
|
|
|
|
|
|
|
// Normal case. Just return the usual game ID.
|
|
|
|
return GetGameID(partition);
|
2019-02-23 09:49:06 -07:00
|
|
|
}
|
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
Region VolumeGC::GetRegion() const
|
2008-07-12 11:40:22 -06:00
|
|
|
{
|
2020-06-04 12:33:52 -06:00
|
|
|
return RegionCodeToRegion(m_reader->ReadSwapped<u32>(0x458));
|
2015-04-10 14:10:49 -06:00
|
|
|
}
|
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
std::map<Language, std::string> VolumeGC::GetShortNames() const
|
2008-10-08 23:33:24 -06:00
|
|
|
{
|
2017-08-02 11:06:32 -06:00
|
|
|
return m_converted_banner->short_names;
|
2008-10-08 23:33:24 -06:00
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
std::map<Language, std::string> VolumeGC::GetLongNames() const
|
2015-04-10 14:10:49 -06:00
|
|
|
{
|
2017-08-02 11:06:32 -06:00
|
|
|
return m_converted_banner->long_names;
|
2015-04-10 14:10:49 -06:00
|
|
|
}
|
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
std::map<Language, std::string> VolumeGC::GetShortMakers() const
|
2015-04-10 14:10:49 -06:00
|
|
|
{
|
2017-08-02 11:06:32 -06:00
|
|
|
return m_converted_banner->short_makers;
|
2016-02-29 01:52:15 -07:00
|
|
|
}
|
2015-04-10 14:10:49 -06:00
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
std::map<Language, std::string> VolumeGC::GetLongMakers() const
|
2016-02-29 01:52:15 -07:00
|
|
|
{
|
2017-08-02 11:06:32 -06:00
|
|
|
return m_converted_banner->long_makers;
|
2016-02-29 01:52:15 -07:00
|
|
|
}
|
2015-04-10 14:10:49 -06:00
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
std::map<Language, std::string> VolumeGC::GetDescriptions() const
|
2016-02-29 01:52:15 -07:00
|
|
|
{
|
2017-08-02 11:06:32 -06:00
|
|
|
return m_converted_banner->descriptions;
|
2015-04-10 14:10:49 -06:00
|
|
|
}
|
|
|
|
|
2018-03-10 14:41:49 -07:00
|
|
|
std::vector<u32> VolumeGC::GetBanner(u32* width, u32* height) const
|
2015-04-10 14:10:49 -06:00
|
|
|
{
|
2017-08-02 11:06:32 -06:00
|
|
|
*width = m_converted_banner->image_width;
|
|
|
|
*height = m_converted_banner->image_height;
|
|
|
|
return m_converted_banner->image_buffer;
|
2015-04-10 14:10:49 -06:00
|
|
|
}
|
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
BlobType VolumeGC::GetBlobType() const
|
2015-09-26 07:24:29 -06:00
|
|
|
{
|
2018-05-30 00:37:13 -06:00
|
|
|
return m_reader->GetBlobType();
|
2015-09-26 07:24:29 -06:00
|
|
|
}
|
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
u64 VolumeGC::GetSize() const
|
2008-07-12 11:40:22 -06:00
|
|
|
{
|
2018-05-30 00:37:13 -06:00
|
|
|
return m_reader->GetDataSize();
|
2008-07-12 11:40:22 -06:00
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2019-03-21 15:20:23 -06:00
|
|
|
bool VolumeGC::IsSizeAccurate() const
|
|
|
|
{
|
|
|
|
return m_reader->IsDataSizeAccurate();
|
|
|
|
}
|
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
u64 VolumeGC::GetRawSize() const
|
2013-04-09 11:58:56 -06:00
|
|
|
{
|
2018-05-30 00:37:13 -06:00
|
|
|
return m_reader->GetRawSize();
|
2013-04-09 11:58:56 -06:00
|
|
|
}
|
|
|
|
|
2020-06-07 06:11:00 -06:00
|
|
|
const BlobReader& VolumeGC::GetBlobReader() const
|
|
|
|
{
|
|
|
|
return *m_reader;
|
|
|
|
}
|
|
|
|
|
2017-06-06 03:49:01 -06:00
|
|
|
Platform VolumeGC::GetVolumeType() const
|
2015-06-04 08:26:36 -06:00
|
|
|
{
|
2018-03-31 06:04:13 -06:00
|
|
|
return Platform::GameCubeDisc;
|
2015-06-04 08:26:36 -06:00
|
|
|
}
|
|
|
|
|
2020-07-04 06:51:13 -06:00
|
|
|
bool VolumeGC::IsDatelDisc() const
|
|
|
|
{
|
2022-03-12 14:27:58 -07:00
|
|
|
return GetGameID() == "DTLX01" || !GetBootDOLOffset(*this, PARTITION_NONE).has_value();
|
2020-07-04 06:51:13 -06:00
|
|
|
}
|
|
|
|
|
2020-06-07 14:58:03 -06:00
|
|
|
std::array<u8, 20> VolumeGC::GetSyncHash() const
|
|
|
|
{
|
|
|
|
mbedtls_sha1_context context;
|
|
|
|
mbedtls_sha1_init(&context);
|
|
|
|
mbedtls_sha1_starts_ret(&context);
|
|
|
|
|
|
|
|
AddGamePartitionToSyncHash(&context);
|
|
|
|
|
|
|
|
std::array<u8, 20> hash;
|
|
|
|
mbedtls_sha1_finish_ret(&context, hash.data());
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2017-08-02 11:06:32 -06:00
|
|
|
VolumeGC::ConvertedGCBanner VolumeGC::LoadBannerFile() const
|
2013-03-03 15:51:26 -07:00
|
|
|
{
|
2016-02-29 01:52:15 -07:00
|
|
|
GCBanner banner_file;
|
2017-08-02 10:16:56 -06: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 07:06:23 -06:00
|
|
|
{
|
2020-10-21 12:58:08 -06:00
|
|
|
WARN_LOG_FMT(DISCIO, "Could not read opening.bnr.");
|
2017-08-02 11:06:32 -06:00
|
|
|
return {}; // Return early so that we don't access the uninitialized banner_file.id
|
2015-07-30 07:06:23 -06:00
|
|
|
}
|
2016-02-29 01:52:15 -07:00
|
|
|
|
2017-08-02 10:16:56 -06:00
|
|
|
constexpr u32 BNR1_MAGIC = 0x31524e42;
|
|
|
|
constexpr u32 BNR2_MAGIC = 0x32524e42;
|
2016-02-29 01:52:15 -07: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 14:10:49 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-21 12:58:08 -06:00
|
|
|
WARN_LOG_FMT(DISCIO, "Invalid opening.bnr. Type: {:#0x} Size: {:#0x}", banner_file.id,
|
|
|
|
file_size);
|
2017-08-02 11:06:32 -06:00
|
|
|
return {};
|
2015-04-10 14:10:49 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-08-02 11:06:32 -06:00
|
|
|
return ExtractBannerInformation(banner_file, is_bnr1);
|
2013-03-03 15:51:26 -07:00
|
|
|
}
|
|
|
|
|
2017-08-02 11:06:32 -06:00
|
|
|
VolumeGC::ConvertedGCBanner VolumeGC::ExtractBannerInformation(const GCBanner& banner_file,
|
|
|
|
bool is_bnr1) const
|
2015-05-10 11:09:11 -06:00
|
|
|
{
|
2017-08-02 11:06:32 -06:00
|
|
|
ConvertedGCBanner banner;
|
|
|
|
|
2015-05-10 11:09:11 -06:00
|
|
|
u32 number_of_languages = 0;
|
2018-03-31 06:04:13 -06:00
|
|
|
Language start_language = Language::Unknown;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-02-29 01:52:15 -07:00
|
|
|
if (is_bnr1) // NTSC
|
2015-05-10 11:09:11 -06:00
|
|
|
{
|
|
|
|
number_of_languages = 1;
|
2018-03-31 06:04:13 -06:00
|
|
|
start_language = GetRegion() == Region::NTSC_J ? Language::Japanese : Language::English;
|
2016-02-29 01:52:15 -07:00
|
|
|
}
|
|
|
|
else // PAL
|
|
|
|
{
|
2015-05-10 11:09:11 -06:00
|
|
|
number_of_languages = 6;
|
2018-03-31 06:04:13 -06:00
|
|
|
start_language = Language::English;
|
2015-05-10 11:09:11 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-08-02 11:06:32 -06: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-27 18:58:08 -06:00
|
|
|
Common::Decode5A3Image(banner.image_buffer.data(), banner_file.image, GC_BANNER_WIDTH,
|
2018-05-27 18:55:36 -06:00
|
|
|
GC_BANNER_HEIGHT);
|
2016-02-29 01:52:15 -07:00
|
|
|
|
2015-05-10 11:09:11 -06:00
|
|
|
for (u32 i = 0; i < number_of_languages; ++i)
|
|
|
|
{
|
2016-02-29 01:52:15 -07:00
|
|
|
const GCBannerInformation& info = banner_file.information[i];
|
2016-07-06 12:33:05 -06:00
|
|
|
Language language = static_cast<Language>(static_cast<int>(start_language) + i);
|
2016-02-29 01:52:15 -07:00
|
|
|
|
|
|
|
std::string description = DecodeString(info.description);
|
|
|
|
if (!description.empty())
|
2017-08-02 11:06:32 -06:00
|
|
|
banner.descriptions.emplace(language, description);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-02-29 01:52:15 -07:00
|
|
|
std::string short_name = DecodeString(info.short_name);
|
|
|
|
if (!short_name.empty())
|
2017-08-02 11:06:32 -06:00
|
|
|
banner.short_names.emplace(language, short_name);
|
2016-02-29 01:52:15 -07:00
|
|
|
|
|
|
|
std::string long_name = DecodeString(info.long_name);
|
|
|
|
if (!long_name.empty())
|
2017-08-02 11:06:32 -06:00
|
|
|
banner.long_names.emplace(language, long_name);
|
2016-02-29 01:52:15 -07:00
|
|
|
|
|
|
|
std::string short_maker = DecodeString(info.short_maker);
|
|
|
|
if (!short_maker.empty())
|
2017-08-02 11:06:32 -06:00
|
|
|
banner.short_makers.emplace(language, short_maker);
|
2016-02-29 01:52:15 -07:00
|
|
|
|
|
|
|
std::string long_maker = DecodeString(info.long_maker);
|
|
|
|
if (!long_maker.empty())
|
2017-08-02 11:06:32 -06:00
|
|
|
banner.long_makers.emplace(language, long_maker);
|
2016-02-29 01:52:15 -07:00
|
|
|
}
|
2017-08-02 11:06:32 -06:00
|
|
|
|
|
|
|
return banner;
|
2015-05-10 11:09:11 -06:00
|
|
|
}
|
|
|
|
|
2017-09-15 12:43:19 -06:00
|
|
|
VolumeGC::ConvertedGCBanner::ConvertedGCBanner() = default;
|
|
|
|
VolumeGC::ConvertedGCBanner::~ConvertedGCBanner() = default;
|
2019-05-05 17:48:12 -06:00
|
|
|
} // namespace DiscIO
|