Files
dolphin/Source/Core/DiscIO/Src/BannerLoaderGC.cpp
T

206 lines
3.7 KiB
C++
Raw Normal View History

// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.
2008-12-08 05:30:24 +00:00
// HyperIris: need clean code
#include "../../Core/Src/ConfigManager.h"
#include "ColorUtil.h"
2008-12-08 05:30:24 +00:00
#include "BannerLoaderGC.h"
namespace DiscIO
{
2013-03-02 22:57:49 -06:00
CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume)
: m_pBannerFile(NULL)
, m_IsValid(false)
, m_country(volume->GetCountry())
2008-12-08 05:30:24 +00:00
{
// load the opening.bnr
2008-12-20 18:46:49 +00:00
size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr");
2013-03-02 19:46:55 -06:00
if (FileSize == BNR1_SIZE || FileSize == BNR2_SIZE)
2008-12-08 05:30:24 +00:00
{
m_pBannerFile = new u8[FileSize];
if (m_pBannerFile)
{
_rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize);
m_BNRType = getBannerType();
if (m_BNRType == BANNER_UNKNOWN)
PanicAlertT("Invalid opening.bnr found in gcm:\n%s\n You may need to redump this game.",
_rFileSystem.GetVolume()->GetName().c_str());
else m_IsValid = true;
}
2008-12-08 05:30:24 +00:00
}
else WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx",
(unsigned long)FileSize);
2008-12-08 05:30:24 +00:00
}
CBannerLoaderGC::~CBannerLoaderGC()
{
if (m_pBannerFile)
{
delete [] m_pBannerFile;
m_pBannerFile = NULL;
}
2008-12-08 05:30:24 +00:00
}
bool CBannerLoaderGC::IsValid()
2008-12-08 05:30:24 +00:00
{
return m_IsValid;
2008-12-08 05:30:24 +00:00
}
bool CBannerLoaderGC::GetBanner(u32* _pBannerImage)
2008-12-08 05:30:24 +00:00
{
if (!IsValid())
{
return false;
2008-12-08 05:30:24 +00:00
}
2013-03-02 19:46:55 -06:00
auto const pBanner = (DVDBanner*)m_pBannerFile;
2008-12-08 05:30:24 +00:00
decode5A3image(_pBannerImage, pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT);
return true;
2008-12-08 05:30:24 +00:00
}
2013-03-02 19:46:55 -06:00
std::vector<std::string> CBannerLoaderGC::GetNames()
2008-12-08 05:30:24 +00:00
{
2013-03-02 19:46:55 -06:00
std::vector<std::string> names;
2008-12-08 05:30:24 +00:00
if (!IsValid())
{
2013-03-02 19:46:55 -06:00
return names;
2008-12-08 05:30:24 +00:00
}
2013-03-02 19:46:55 -06:00
u32 name_count = 0;
// find Banner type
switch (m_BNRType)
2008-12-08 05:30:24 +00:00
{
case CBannerLoaderGC::BANNER_BNR1:
2013-03-02 19:46:55 -06:00
name_count = 1;
break;
2013-03-02 19:46:55 -06:00
case CBannerLoaderGC::BANNER_BNR2:
2013-03-02 19:46:55 -06:00
name_count = 6;
break;
2013-03-02 19:46:55 -06:00
2009-03-07 08:07:11 +00:00
default:
break;
}
2013-03-02 19:46:55 -06:00
auto const banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile);
2013-03-02 22:57:49 -06:00
for (u32 i = 0; i != name_count; ++i)
2013-03-02 19:46:55 -06:00
{
auto& comment = banner->comment[i];
if (comment.longTitle[0])
{
auto& data = comment.longTitle;
names.push_back(GetDecodedString(data));
}
else
{
auto& data = comment.shortTitle;
names.push_back(GetDecodedString(data));
}
}
2013-03-02 19:46:55 -06:00
return names;
2008-12-08 05:30:24 +00:00
}
2013-03-02 19:46:55 -06:00
std::string CBannerLoaderGC::GetCompany()
2008-12-08 05:30:24 +00:00
{
2013-03-02 19:46:55 -06:00
std::string company;
2008-12-08 05:30:24 +00:00
2013-03-02 19:46:55 -06:00
if (IsValid())
2008-12-08 05:30:24 +00:00
{
2013-03-02 19:46:55 -06:00
auto const pBanner = (DVDBanner*)m_pBannerFile;
auto& data = pBanner->comment[0].shortMaker;
company = GetDecodedString(data);
2008-12-08 05:30:24 +00:00
}
2013-03-02 19:46:55 -06:00
return company;
2008-12-08 05:30:24 +00:00
}
2013-03-02 19:46:55 -06:00
std::vector<std::string> CBannerLoaderGC::GetDescriptions()
2008-12-08 05:30:24 +00:00
{
2013-03-02 19:46:55 -06:00
std::vector<std::string> descriptions;
2008-12-08 05:30:24 +00:00
if (!IsValid())
{
2013-03-02 19:46:55 -06:00
return descriptions;
2008-12-08 05:30:24 +00:00
}
2013-03-02 19:46:55 -06:00
u32 desc_count = 0;
// find Banner type
switch (m_BNRType)
2008-12-08 05:30:24 +00:00
{
case CBannerLoaderGC::BANNER_BNR1:
2013-03-02 19:46:55 -06:00
desc_count = 1;
break;
2013-03-02 19:46:55 -06:00
case CBannerLoaderGC::BANNER_BNR2:
desc_count = 6;
break;
2013-03-02 19:46:55 -06:00
2009-03-07 08:07:11 +00:00
default:
break;
}
2013-03-02 19:46:55 -06:00
auto banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile);
2013-03-02 22:57:49 -06:00
for (u32 i = 0; i != desc_count; ++i)
2013-03-02 19:46:55 -06:00
{
auto& data = banner->comment[i].comment;
descriptions.push_back(GetDecodedString(data));
}
return descriptions;
2008-12-08 05:30:24 +00:00
}
void CBannerLoaderGC::decode5A3image(u32* dst, u16* src, int width, int height)
2008-12-08 05:30:24 +00:00
{
for (int y = 0; y < height; y += 4)
{
for (int x = 0; x < width; x += 4)
{
for (int iy = 0; iy < 4; iy++, src += 4)
{
for (int ix = 0; ix < 4; ix++)
{
u32 RGBA = ColorUtil::Decode5A3(Common::swap16(src[ix]));
2008-12-08 05:30:24 +00:00
dst[(y + iy) * width + (x + ix)] = RGBA;
}
}
}
}
}
CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType()
{
u32 bannerSignature = *(u32*)m_pBannerFile;
CBannerLoaderGC::BANNER_TYPE type = CBannerLoaderGC::BANNER_UNKNOWN;
switch (bannerSignature)
{
2013-03-02 19:46:55 -06:00
// "BNR1"
case 0x31524e42:
type = CBannerLoaderGC::BANNER_BNR1;
break;
2013-03-02 19:46:55 -06:00
// "BNR2"
case 0x32524e42:
type = CBannerLoaderGC::BANNER_BNR2;
break;
}
return type;
}
2013-03-02 19:46:55 -06:00
2008-12-08 05:30:24 +00:00
} // namespace