2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2014-02-20 17:47:53 -07:00
|
|
|
#include <cstddef>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "Common/ColorUtil.h"
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-09-18 22:17:41 -06:00
|
|
|
#include "Common/MsgHandler.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DiscIO/BannerLoaderGC.h"
|
2014-02-20 17:47:53 -07:00
|
|
|
#include "DiscIO/Filesystem.h"
|
|
|
|
#include "DiscIO/Volume.h"
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2013-03-02 21:57:49 -07:00
|
|
|
CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume)
|
2014-06-29 13:38:48 -06:00
|
|
|
: m_country(volume->GetCountry())
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
|
|
|
// load the opening.bnr
|
2008-12-20 11:46:49 -07:00
|
|
|
size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr");
|
2013-03-02 18:46:55 -07:00
|
|
|
if (FileSize == BNR1_SIZE || FileSize == BNR2_SIZE)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
|
|
|
m_pBannerFile = new u8[FileSize];
|
2009-01-21 09:31:44 -07:00
|
|
|
if (m_pBannerFile)
|
|
|
|
{
|
|
|
|
_rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize);
|
2010-01-10 22:07:56 -07:00
|
|
|
m_BNRType = getBannerType();
|
|
|
|
if (m_BNRType == BANNER_UNKNOWN)
|
2011-01-12 19:05:58 -07:00
|
|
|
PanicAlertT("Invalid opening.bnr found in gcm:\n%s\n You may need to redump this game.",
|
2010-01-10 22:07:56 -07:00
|
|
|
_rFileSystem.GetVolume()->GetName().c_str());
|
|
|
|
else m_IsValid = true;
|
2009-01-21 09:31:44 -07:00
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
2010-12-05 11:22:41 -07:00
|
|
|
else WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx",
|
|
|
|
(unsigned long)FileSize);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CBannerLoaderGC::~CBannerLoaderGC()
|
|
|
|
{
|
2009-01-21 09:31:44 -07:00
|
|
|
if (m_pBannerFile)
|
|
|
|
{
|
|
|
|
delete [] m_pBannerFile;
|
2014-03-09 14:14:26 -06:00
|
|
|
m_pBannerFile = nullptr;
|
2009-01-21 09:31:44 -07:00
|
|
|
}
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2013-09-25 01:05:36 -06:00
|
|
|
std::vector<u32> CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2013-09-25 01:05:36 -06:00
|
|
|
std::vector<u32> Buffer;
|
|
|
|
Buffer.resize(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT);
|
2013-03-02 18:46:55 -07:00
|
|
|
auto const pBanner = (DVDBanner*)m_pBannerFile;
|
2013-10-02 16:18:54 -06:00
|
|
|
ColorUtil::decode5A3image(&Buffer[0], pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT);
|
2013-09-25 01:05:36 -06:00
|
|
|
*pWidth = DVD_BANNER_WIDTH;
|
|
|
|
*pHeight = DVD_BANNER_HEIGHT;
|
2013-09-26 19:15:35 -06:00
|
|
|
return Buffer;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> CBannerLoaderGC::GetNames()
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> names;
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
if (!IsValid())
|
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
return names;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
u32 name_count = 0;
|
|
|
|
|
2009-01-21 09:31:44 -07:00
|
|
|
// find Banner type
|
2010-01-10 22:07:56 -07:00
|
|
|
switch (m_BNRType)
|
2009-01-21 09:31:44 -07:00
|
|
|
{
|
2009-01-22 00:42:17 -07:00
|
|
|
case CBannerLoaderGC::BANNER_BNR1:
|
2013-03-02 18:46:55 -07:00
|
|
|
name_count = 1;
|
2009-01-22 00:42:17 -07:00
|
|
|
break;
|
2013-03-02 18:46:55 -07:00
|
|
|
|
2009-01-22 00:42:17 -07:00
|
|
|
case CBannerLoaderGC::BANNER_BNR2:
|
2013-03-02 18:46:55 -07:00
|
|
|
name_count = 6;
|
|
|
|
break;
|
2009-01-22 00:42:17 -07:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-02-03 08:03:34 -07:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
auto const banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile);
|
|
|
|
|
2013-03-02 21:57:49 -07:00
|
|
|
for (u32 i = 0; i != name_count; ++i)
|
2013-03-02 18:46:55 -07:00
|
|
|
{
|
|
|
|
auto& comment = banner->comment[i];
|
2009-02-03 08:03:34 -07:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
if (comment.longTitle[0])
|
|
|
|
{
|
|
|
|
auto& data = comment.longTitle;
|
|
|
|
names.push_back(GetDecodedString(data));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto& data = comment.shortTitle;
|
|
|
|
names.push_back(GetDecodedString(data));
|
2009-01-21 09:31:44 -07:00
|
|
|
}
|
|
|
|
}
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
return names;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
std::string CBannerLoaderGC::GetCompany()
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
std::string company;
|
2008-12-07 22:30:24 -07:00
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
if (IsValid())
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
auto const pBanner = (DVDBanner*)m_pBannerFile;
|
|
|
|
auto& data = pBanner->comment[0].shortMaker;
|
|
|
|
company = GetDecodedString(data);
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
return company;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> CBannerLoaderGC::GetDescriptions()
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
std::vector<std::string> descriptions;
|
2008-12-07 22:30:24 -07:00
|
|
|
|
|
|
|
if (!IsValid())
|
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
return descriptions;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2013-03-02 18:46:55 -07:00
|
|
|
u32 desc_count = 0;
|
|
|
|
|
2009-01-21 09:31:44 -07:00
|
|
|
// find Banner type
|
2010-01-10 22:07:56 -07:00
|
|
|
switch (m_BNRType)
|
2008-12-07 22:30:24 -07:00
|
|
|
{
|
2009-01-22 00:42:17 -07:00
|
|
|
case CBannerLoaderGC::BANNER_BNR1:
|
2013-03-02 18:46:55 -07:00
|
|
|
desc_count = 1;
|
2009-01-22 00:42:17 -07:00
|
|
|
break;
|
|
|
|
|
2013-09-14 16:07:53 -06:00
|
|
|
// English, German, French, Spanish, Italian, Dutch
|
2013-03-02 18:46:55 -07:00
|
|
|
case CBannerLoaderGC::BANNER_BNR2:
|
|
|
|
desc_count = 6;
|
2009-01-22 00:42:17 -07:00
|
|
|
break;
|
2013-03-02 18:46:55 -07:00
|
|
|
|
2009-03-07 01:07:11 -07:00
|
|
|
default:
|
|
|
|
break;
|
2009-01-21 09:31:44 -07:00
|
|
|
}
|
2013-03-02 18:46:55 -07:00
|
|
|
|
|
|
|
auto banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile);
|
|
|
|
|
2013-03-02 21:57:49 -07:00
|
|
|
for (u32 i = 0; i != desc_count; ++i)
|
2013-03-02 18:46:55 -07:00
|
|
|
{
|
|
|
|
auto& data = banner->comment[i].comment;
|
|
|
|
descriptions.push_back(GetDecodedString(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
return descriptions;
|
2008-12-07 22:30:24 -07:00
|
|
|
}
|
|
|
|
|
2009-01-22 00:42:17 -07:00
|
|
|
CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType()
|
|
|
|
{
|
|
|
|
u32 bannerSignature = *(u32*)m_pBannerFile;
|
|
|
|
CBannerLoaderGC::BANNER_TYPE type = CBannerLoaderGC::BANNER_UNKNOWN;
|
|
|
|
switch (bannerSignature)
|
|
|
|
{
|
2013-03-02 18:46:55 -07:00
|
|
|
// "BNR1"
|
2009-01-22 00:42:17 -07:00
|
|
|
case 0x31524e42:
|
|
|
|
type = CBannerLoaderGC::BANNER_BNR1;
|
|
|
|
break;
|
2013-03-02 18:46:55 -07:00
|
|
|
|
|
|
|
// "BNR2"
|
2009-01-22 00:42:17 -07:00
|
|
|
case 0x32524e42:
|
|
|
|
type = CBannerLoaderGC::BANNER_BNR2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
2013-03-02 18:46:55 -07:00
|
|
|
|
2008-12-07 22:30:24 -07:00
|
|
|
} // namespace
|