diff options
| author | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-12-31 14:07:57 -0500 |
|---|---|---|
| committer | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-12-31 14:07:57 -0500 |
| commit | 16824d5fd17b43b156706bf02a8063b389604766 (patch) | |
| tree | b0eedc645badbea316ff59c125eaf808b28777ec /Source/Core/DiscIO/BannerLoaderGC.cpp | |
| parent | 43e618682e8093602fc83dfa902ee7ae3fd3a4f6 (diff) | |
| parent | 34692ab826abc8f8faa61bdb2280b742424528f1 (diff) | |
Merge branch 'fuck-you-src-i-hate-you'
Diffstat (limited to 'Source/Core/DiscIO/BannerLoaderGC.cpp')
| -rw-r--r-- | Source/Core/DiscIO/BannerLoaderGC.cpp | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/Source/Core/DiscIO/BannerLoaderGC.cpp b/Source/Core/DiscIO/BannerLoaderGC.cpp new file mode 100644 index 0000000000..ce35258148 --- /dev/null +++ b/Source/Core/DiscIO/BannerLoaderGC.cpp @@ -0,0 +1,183 @@ +// Copyright 2013 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "CommonTypes.h" +#include "ColorUtil.h" +#include "BannerLoaderGC.h" + +namespace DiscIO +{ +CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume) + : m_pBannerFile(NULL) + , m_IsValid(false) + , m_country(volume->GetCountry()) +{ + // load the opening.bnr + size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr"); + if (FileSize == BNR1_SIZE || FileSize == BNR2_SIZE) + { + 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; + } + } + else WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx", + (unsigned long)FileSize); +} + + +CBannerLoaderGC::~CBannerLoaderGC() +{ + if (m_pBannerFile) + { + delete [] m_pBannerFile; + m_pBannerFile = NULL; + } +} + + +bool CBannerLoaderGC::IsValid() +{ + return m_IsValid; +} + +std::vector<u32> CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight) +{ + std::vector<u32> Buffer; + Buffer.resize(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT); + auto const pBanner = (DVDBanner*)m_pBannerFile; + ColorUtil::decode5A3image(&Buffer[0], pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT); + *pWidth = DVD_BANNER_WIDTH; + *pHeight = DVD_BANNER_HEIGHT; + return Buffer; +} + + +std::vector<std::string> CBannerLoaderGC::GetNames() +{ + std::vector<std::string> names; + + if (!IsValid()) + { + return names; + } + + u32 name_count = 0; + + // find Banner type + switch (m_BNRType) + { + case CBannerLoaderGC::BANNER_BNR1: + name_count = 1; + break; + + case CBannerLoaderGC::BANNER_BNR2: + name_count = 6; + break; + + default: + break; + } + + auto const banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile); + + for (u32 i = 0; i != name_count; ++i) + { + 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)); + } + } + + return names; +} + + +std::string CBannerLoaderGC::GetCompany() +{ + std::string company; + + if (IsValid()) + { + auto const pBanner = (DVDBanner*)m_pBannerFile; + auto& data = pBanner->comment[0].shortMaker; + company = GetDecodedString(data); + } + + return company; +} + + +std::vector<std::string> CBannerLoaderGC::GetDescriptions() +{ + std::vector<std::string> descriptions; + + if (!IsValid()) + { + return descriptions; + } + + u32 desc_count = 0; + + // find Banner type + switch (m_BNRType) + { + case CBannerLoaderGC::BANNER_BNR1: + desc_count = 1; + break; + + // English, German, French, Spanish, Italian, Dutch + case CBannerLoaderGC::BANNER_BNR2: + desc_count = 6; + break; + + default: + break; + } + + auto banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile); + + for (u32 i = 0; i != desc_count; ++i) + { + auto& data = banner->comment[i].comment; + descriptions.push_back(GetDecodedString(data)); + } + + return descriptions; +} + +CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType() +{ + u32 bannerSignature = *(u32*)m_pBannerFile; + CBannerLoaderGC::BANNER_TYPE type = CBannerLoaderGC::BANNER_UNKNOWN; + switch (bannerSignature) + { + // "BNR1" + case 0x31524e42: + type = CBannerLoaderGC::BANNER_BNR1; + break; + + // "BNR2" + case 0x32524e42: + type = CBannerLoaderGC::BANNER_BNR2; + break; + } + return type; +} + +} // namespace |
