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>
|
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>
|
|
|
|
|
2015-04-10 20:10:49 +00:00
|
|
|
#include "Common/ColorUtil.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2015-04-10 20:10:49 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Blob.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DiscIO/FileMonitor.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
|
|
|
|
{
|
2015-08-31 23:27:18 +00:00
|
|
|
CVolumeGC::CVolumeGC(std::unique_ptr<IBlobReader> reader)
|
|
|
|
: m_pReader(std::move(reader))
|
2008-12-08 05:30:24 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
CVolumeGC::~CVolumeGC()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-12-28 09:35:48 +00:00
|
|
|
bool CVolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const
|
2008-12-08 05:30:24 +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)
|
2008-12-08 05:30:24 +00:00
|
|
|
return false;
|
2009-07-03 03:26:23 +00:00
|
|
|
|
2009-09-03 20:00:09 +00:00
|
|
|
FileMon::FindFilename(_Offset);
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
return m_pReader->Read(_Offset, _Length, _pBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeGC::GetUniqueID() const
|
|
|
|
{
|
|
|
|
static const std::string NO_UID("NO_UID");
|
2014-03-09 20:14:26 +00:00
|
|
|
if (m_pReader == nullptr)
|
2008-12-08 05:30:24 +00:00
|
|
|
return NO_UID;
|
|
|
|
|
2015-06-18 12:45:26 +00:00
|
|
|
char ID[6];
|
2011-01-30 17:58:02 +00:00
|
|
|
|
|
|
|
if (!Read(0, sizeof(ID), reinterpret_cast<u8*>(ID)))
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2011-01-13 02:05:58 +00:00
|
|
|
PanicAlertT("Failed to read unique ID from disc image");
|
2008-12-08 05:30:24 +00:00
|
|
|
return NO_UID;
|
|
|
|
}
|
|
|
|
|
2015-06-18 12:45:26 +00:00
|
|
|
return DecodeString(ID);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IVolume::ECountry CVolumeGC::GetCountry() const
|
|
|
|
{
|
|
|
|
if (!m_pReader)
|
|
|
|
return COUNTRY_UNKNOWN;
|
|
|
|
|
2015-02-24 01:43:29 +00:00
|
|
|
u8 country_code;
|
|
|
|
m_pReader->Read(3, 1, &country_code);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2015-02-24 01:43:29 +00:00
|
|
|
return CountrySwitch(country_code);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeGC::GetMakerID() const
|
|
|
|
{
|
2014-03-09 20:14:26 +00:00
|
|
|
if (m_pReader == nullptr)
|
2010-08-13 19:07:59 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2015-06-18 12:45:26 +00:00
|
|
|
char makerID[2];
|
2008-12-08 05:30:24 +00:00
|
|
|
if (!Read(0x4, 0x2, (u8*)&makerID))
|
2010-08-13 19:07:59 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2015-06-18 12:45:26 +00:00
|
|
|
return DecodeString(makerID);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-05-29 19:14:02 +00:00
|
|
|
u16 CVolumeGC::GetRevision() const
|
2013-04-17 03:29:01 +00:00
|
|
|
{
|
|
|
|
if (!m_pReader)
|
|
|
|
return 0;
|
|
|
|
|
2014-11-15 01:59:39 +00:00
|
|
|
u8 revision;
|
|
|
|
if (!Read(7, 1, &revision))
|
2013-04-17 03:29:01 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-11-15 01:59:39 +00:00
|
|
|
return revision;
|
2013-04-17 03:29:01 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 09:19:30 +00:00
|
|
|
std::string CVolumeGC::GetInternalName() const
|
2015-04-10 20:10:49 +00:00
|
|
|
{
|
|
|
|
char name[0x60];
|
|
|
|
if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name))
|
|
|
|
return DecodeString(name);
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-05-10 17:09:11 +00:00
|
|
|
std::map<IVolume::ELanguage, std::string> CVolumeGC::GetNames(bool prefer_long) const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2015-05-10 17:09:11 +00:00
|
|
|
return ReadMultiLanguageStrings(false, prefer_long);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2015-04-10 20:10:49 +00:00
|
|
|
std::map<IVolume::ELanguage, std::string> CVolumeGC::GetDescriptions() const
|
|
|
|
{
|
2015-05-10 17:09:11 +00:00
|
|
|
return ReadMultiLanguageStrings(true);
|
2015-04-10 20:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeGC::GetCompany() const
|
|
|
|
{
|
|
|
|
if (!LoadBannerFile())
|
|
|
|
return "";
|
|
|
|
|
|
|
|
auto const pBanner = (GCBanner*)m_banner_file.data();
|
|
|
|
std::string company = DecodeString(pBanner->comment[0].longMaker);
|
|
|
|
|
|
|
|
if (company.empty())
|
|
|
|
company = DecodeString(pBanner->comment[0].shortMaker);
|
|
|
|
|
|
|
|
return company;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<u32> CVolumeGC::GetBanner(int* width, int* height) const
|
|
|
|
{
|
|
|
|
if (!LoadBannerFile())
|
|
|
|
{
|
|
|
|
*width = 0;
|
|
|
|
*height = 0;
|
|
|
|
return std::vector<u32>();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<u32> image_buffer(GC_BANNER_WIDTH * GC_BANNER_HEIGHT);
|
|
|
|
auto const pBanner = (GCBanner*)m_banner_file.data();
|
|
|
|
ColorUtil::decode5A3image(image_buffer.data(), pBanner->image, GC_BANNER_WIDTH, GC_BANNER_HEIGHT);
|
|
|
|
*width = GC_BANNER_WIDTH;
|
|
|
|
*height = GC_BANNER_HEIGHT;
|
|
|
|
return image_buffer;
|
|
|
|
}
|
|
|
|
|
2015-08-10 14:35:23 +00:00
|
|
|
u64 CVolumeGC::GetFSTSize() const
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2014-03-09 20:14:26 +00:00
|
|
|
if (m_pReader == nullptr)
|
2010-08-13 19:07:59 +00:00
|
|
|
return 0;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
u32 size;
|
|
|
|
if (!Read(0x428, 0x4, (u8*)&size))
|
2010-08-13 19:07:59 +00:00
|
|
|
return 0;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
return Common::swap32(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CVolumeGC::GetApploaderDate() const
|
|
|
|
{
|
2014-03-09 20:14:26 +00:00
|
|
|
if (m_pReader == nullptr)
|
2010-08-13 19:07:59 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
char date[16];
|
|
|
|
if (!Read(0x2440, 0x10, (u8*)&date))
|
2010-08-13 19:07:59 +00:00
|
|
|
return std::string();
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2015-06-18 12:45:26 +00:00
|
|
|
return DecodeString(date);
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 CVolumeGC::GetSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
2010-12-03 12:42:01 +00:00
|
|
|
return m_pReader->GetDataSize();
|
2008-12-08 05:30:24 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-09 17:58:56 +00:00
|
|
|
u64 CVolumeGC::GetRawSize() const
|
|
|
|
{
|
|
|
|
if (m_pReader)
|
|
|
|
return m_pReader->GetRawSize();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-05-29 19:14:02 +00:00
|
|
|
u8 CVolumeGC::GetDiscNumber() const
|
2013-01-26 02:28:04 +00:00
|
|
|
{
|
2015-05-29 19:14:02 +00:00
|
|
|
u8 disc_number;
|
|
|
|
Read(6, 1, &disc_number);
|
|
|
|
return disc_number;
|
2013-01-26 02:28:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-04 14:26:36 +00:00
|
|
|
IVolume::EPlatform CVolumeGC::GetVolumeType() const
|
|
|
|
{
|
|
|
|
return GAMECUBE_DISC;
|
|
|
|
}
|
|
|
|
|
2015-05-10 17:09:11 +00:00
|
|
|
// Returns true if the loaded banner file is valid,
|
|
|
|
// regardless of whether it was loaded by the current call
|
2015-04-10 20:10:49 +00:00
|
|
|
bool CVolumeGC::LoadBannerFile() const
|
2013-03-03 22:51:26 +00:00
|
|
|
{
|
2015-05-10 17:09:11 +00:00
|
|
|
// The methods ReadMultiLanguageStrings, GetCompany and GetBanner
|
|
|
|
// need to access the opening.bnr file. These methods are
|
|
|
|
// usually called one after another. The file is cached in
|
|
|
|
// RAM to avoid reading it from the disc several times, but
|
2015-04-10 20:10:49 +00:00
|
|
|
// if none of these methods are called, the file is never loaded.
|
|
|
|
|
2015-05-10 17:09:11 +00:00
|
|
|
// If opening.bnr has been loaded already, return immediately
|
2015-04-10 20:10:49 +00:00
|
|
|
if (m_banner_file_type != BANNER_NOT_LOADED)
|
|
|
|
return m_banner_file_type != BANNER_INVALID;
|
|
|
|
|
|
|
|
std::unique_ptr<IFileSystem> file_system(CreateFileSystem(this));
|
|
|
|
size_t file_size = (size_t)file_system->GetFileSize("opening.bnr");
|
|
|
|
if (file_size == BNR1_SIZE || file_size == BNR2_SIZE)
|
|
|
|
{
|
|
|
|
m_banner_file.resize(file_size);
|
|
|
|
file_system->ReadFile("opening.bnr", m_banner_file.data(), m_banner_file.size());
|
|
|
|
|
|
|
|
u32 bannerSignature = *(u32*)m_banner_file.data();
|
2015-06-03 09:35:05 +00:00
|
|
|
if (file_size == BNR1_SIZE && bannerSignature == 0x31524e42) // "BNR1"
|
2015-04-10 20:10:49 +00:00
|
|
|
{
|
|
|
|
m_banner_file_type = BANNER_BNR1;
|
2015-06-03 09:35:05 +00:00
|
|
|
}
|
|
|
|
else if (file_size == BNR2_SIZE && bannerSignature == 0x32524e42) // "BNR2"
|
|
|
|
{
|
2015-04-10 20:10:49 +00:00
|
|
|
m_banner_file_type = BANNER_BNR2;
|
2015-06-03 09:35:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-10 20:10:49 +00:00
|
|
|
m_banner_file_type = BANNER_INVALID;
|
2015-09-08 05:44:37 +00:00
|
|
|
WARN_LOG(DISCIO, "Invalid opening.bnr. Type: %0x Size: %0zx", bannerSignature, file_size);
|
2015-04-10 20:10:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_banner_file_type = BANNER_INVALID;
|
2015-09-08 05:44:37 +00:00
|
|
|
WARN_LOG(DISCIO, "Invalid opening.bnr. Size: %0zx", file_size);
|
2015-04-10 20:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_banner_file_type != BANNER_INVALID;
|
2013-03-03 22:51:26 +00:00
|
|
|
}
|
|
|
|
|
2015-05-10 17:09:11 +00:00
|
|
|
std::map<IVolume::ELanguage, std::string> CVolumeGC::ReadMultiLanguageStrings(bool description, bool prefer_long) const
|
|
|
|
{
|
|
|
|
std::map<ELanguage, std::string> strings;
|
|
|
|
|
|
|
|
if (!LoadBannerFile())
|
|
|
|
return strings;
|
|
|
|
|
|
|
|
u32 number_of_languages = 0;
|
2015-09-06 03:05:26 +00:00
|
|
|
ELanguage start_language = LANGUAGE_UNKNOWN;
|
2015-05-10 17:09:11 +00:00
|
|
|
bool is_japanese = GetCountry() == ECountry::COUNTRY_JAPAN;
|
|
|
|
|
|
|
|
switch (m_banner_file_type)
|
|
|
|
{
|
|
|
|
case BANNER_BNR1: // NTSC
|
|
|
|
number_of_languages = 1;
|
|
|
|
start_language = is_japanese ? ELanguage::LANGUAGE_JAPANESE : ELanguage::LANGUAGE_ENGLISH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BANNER_BNR2: // PAL
|
|
|
|
number_of_languages = 6;
|
|
|
|
start_language = ELanguage::LANGUAGE_ENGLISH;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Shouldn't happen
|
|
|
|
case BANNER_INVALID:
|
|
|
|
case BANNER_NOT_LOADED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto const banner = reinterpret_cast<const GCBanner*>(m_banner_file.data());
|
|
|
|
|
|
|
|
for (u32 i = 0; i < number_of_languages; ++i)
|
|
|
|
{
|
|
|
|
GCBannerComment comment = banner->comment[i];
|
|
|
|
std::string string;
|
|
|
|
|
|
|
|
if (description)
|
|
|
|
{
|
|
|
|
string = DecodeString(comment.comment);
|
|
|
|
}
|
|
|
|
else // Title
|
|
|
|
{
|
|
|
|
if (prefer_long)
|
|
|
|
string = DecodeString(comment.longTitle);
|
|
|
|
|
|
|
|
if (string.empty())
|
|
|
|
string = DecodeString(comment.shortTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!string.empty())
|
|
|
|
strings[(ELanguage)(start_language + i)] = string;
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings;
|
|
|
|
}
|
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
} // namespace
|