Merge pull request #540 from lioncash/banner

Centralize some common banner loader class members.
This commit is contained in:
Lioncash 2014-06-29 16:37:19 -04:00
commit 933358a28c
5 changed files with 98 additions and 120 deletions

View File

@ -17,23 +17,29 @@ class IVolume;
class IBannerLoader class IBannerLoader
{ {
public: public:
IBannerLoader()
: m_pBannerFile(nullptr)
, m_IsValid(false)
{}
IBannerLoader() virtual ~IBannerLoader()
{} {}
virtual std::vector<u32> GetBanner(int* pWidth, int* pHeight) = 0;
virtual ~IBannerLoader() virtual std::vector<std::string> GetNames() = 0;
{} virtual std::string GetCompany() = 0;
virtual std::vector<std::string> GetDescriptions() = 0;
bool IsValid()
{
return m_IsValid;
}
virtual bool IsValid() = 0; protected:
bool m_IsValid;
virtual std::vector<u32> GetBanner(int* pWidth, int* pHeight) = 0; u8* m_pBannerFile;
virtual std::vector<std::string> GetNames() = 0;
virtual std::string GetCompany() = 0;
virtual std::vector<std::string> GetDescriptions() = 0;
}; };
IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume *pVolume); IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume *pVolume);

View File

@ -16,9 +16,7 @@
namespace DiscIO namespace DiscIO
{ {
CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume) CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume)
: m_pBannerFile(nullptr) : m_country(volume->GetCountry())
, m_IsValid(false)
, m_country(volume->GetCountry())
{ {
// load the opening.bnr // load the opening.bnr
size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr"); size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr");
@ -49,12 +47,6 @@ CBannerLoaderGC::~CBannerLoaderGC()
} }
} }
bool CBannerLoaderGC::IsValid()
{
return m_IsValid;
}
std::vector<u32> CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight) std::vector<u32> CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight)
{ {
std::vector<u32> Buffer; std::vector<u32> Buffer;

View File

@ -22,70 +22,65 @@ class IFileSystem;
class CBannerLoaderGC class CBannerLoaderGC
: public IBannerLoader : public IBannerLoader
{ {
public: public:
CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume); CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume);
virtual ~CBannerLoaderGC(); virtual ~CBannerLoaderGC();
virtual bool IsValid() override; virtual std::vector<u32> GetBanner(int* pWidth, int* pHeight) override;
virtual std::vector<u32> GetBanner(int* pWidth, int* pHeight) override; virtual std::vector<std::string> GetNames() override;
virtual std::string GetCompany() override;
virtual std::vector<std::string> GetDescriptions() override;
virtual std::vector<std::string> GetNames() override; private:
virtual std::string GetCompany() override; enum
virtual std::vector<std::string> GetDescriptions() override; {
DVD_BANNER_WIDTH = 96,
DVD_BANNER_HEIGHT = 32
};
private: enum BANNER_TYPE
enum {
{ BANNER_UNKNOWN,
DVD_BANNER_WIDTH = 96, BANNER_BNR1,
DVD_BANNER_HEIGHT = 32 BANNER_BNR2,
}; };
enum BANNER_TYPE // Banner Comment
{ struct DVDBannerComment
BANNER_UNKNOWN, {
BANNER_BNR1, char shortTitle[32]; // Short game title shown in IPL menu
BANNER_BNR2, char shortMaker[32]; // Short developer, publisher names shown in IPL menu
}; char longTitle[64]; // Long game title shown in IPL game start screen
char longMaker[64]; // Long developer, publisher names shown in IPL game start screen
char comment[128]; // Game description shown in IPL game start screen in two lines.
};
// Banner Comment // "opening.bnr" file format for EU console
struct DVDBannerComment struct DVDBanner
{ {
char shortTitle[32]; // Short game title shown in IPL menu u32 id; // 'BNR2'
char shortMaker[32]; // Short developer, publisher names shown in IPL menu u32 padding[7];
char longTitle[64]; // Long game title shown in IPL game start screen u16 image[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT]; // RGB5A3 96x32 texture image
char longMaker[64]; // Long developer, publisher names shown in IPL game start screen DVDBannerComment comment[6]; // Comments in six languages (only 1 for BNR1 type)
char comment[128]; // Game description shown in IPL game start screen in two lines. };
};
// "opening.bnr" file format for EU console static const u32 BNR1_SIZE = sizeof(DVDBanner) - sizeof(DVDBannerComment) * 5;
struct DVDBanner static const u32 BNR2_SIZE = sizeof(DVDBanner);
{
u32 id; // 'BNR2'
u32 padding[7];
u16 image[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT]; // RGB5A3 96x32 texture image
DVDBannerComment comment[6]; // Comments in six languages (only 1 for BNR1 type)
};
static const u32 BNR1_SIZE = sizeof(DVDBanner) - sizeof(DVDBannerComment) * 5; template <u32 N>
static const u32 BNR2_SIZE = sizeof(DVDBanner); std::string GetDecodedString(const char (&data)[N])
{
auto const string_decoder = CVolumeGC::GetStringDecoder(m_country);
template <u32 N> // strnlen to trim NULLs
std::string GetDecodedString(const char (&data)[N]) return string_decoder(std::string(data, strnlen(data, sizeof(data))));
{ }
auto const string_decoder = CVolumeGC::GetStringDecoder(m_country);
// strnlen to trim NULLs BANNER_TYPE m_BNRType;
return string_decoder(std::string(data, strnlen(data, sizeof(data)))); BANNER_TYPE getBannerType();
}
u8* m_pBannerFile; DiscIO::IVolume::ECountry const m_country;
bool m_IsValid;
BANNER_TYPE m_BNRType;
BANNER_TYPE getBannerType();
DiscIO::IVolume::ECountry const m_country;
}; };
} // namespace } // namespace

View File

@ -21,8 +21,6 @@ namespace DiscIO
{ {
CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume) CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume)
: m_pBannerFile(nullptr)
, m_IsValid(false)
{ {
u64 TitleID; u64 TitleID;
pVolume->GetTitleID((u8*)&TitleID); pVolume->GetTitleID((u8*)&TitleID);
@ -95,11 +93,6 @@ CBannerLoaderWii::~CBannerLoaderWii()
} }
} }
bool CBannerLoaderWii::IsValid()
{
return m_IsValid;
}
std::vector<u32> CBannerLoaderWii::GetBanner(int* pWidth, int* pHeight) std::vector<u32> CBannerLoaderWii::GetBanner(int* pWidth, int* pHeight)
{ {
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;

View File

@ -18,54 +18,46 @@ class IVolume;
class CBannerLoaderWii class CBannerLoaderWii
: public IBannerLoader : public IBannerLoader
{ {
public: public:
CBannerLoaderWii(DiscIO::IVolume *pVolume);
CBannerLoaderWii(DiscIO::IVolume *pVolume); virtual ~CBannerLoaderWii();
virtual ~CBannerLoaderWii(); virtual std::vector<u32> GetBanner(int* pWidth, int* pHeight) override;
virtual bool IsValid() override; virtual std::vector<std::string> GetNames() override;
virtual std::string GetCompany() override;
virtual std::vector<std::string> GetDescriptions() override;
virtual std::vector<u32> GetBanner(int* pWidth, int* pHeight) override; private:
enum
{
TEXTURE_SIZE = 192 * 64 * 2,
ICON_SIZE = 48 * 48 * 2,
COMMENT_SIZE = 32
};
virtual std::vector<std::string> GetNames() override; enum CommentIndex
virtual std::string GetCompany() override; {
virtual std::vector<std::string> GetDescriptions() override; NAME_IDX,
DESC_IDX
};
private: struct SWiiBanner
{
u32 ID;
enum u32 m_Flag;
{ u16 m_Speed;
TEXTURE_SIZE = 192 * 64 * 2, u8 m_Unknown[22];
ICON_SIZE = 48 * 48 * 2,
COMMENT_SIZE = 32
};
enum CommentIndex // Not null terminated!
{ u16 m_Comment[2][COMMENT_SIZE];
NAME_IDX, u8 m_BannerTexture[TEXTURE_SIZE];
DESC_IDX u8 m_IconTexture[8][ICON_SIZE];
}; };
struct SWiiBanner bool GetStringFromComments(const CommentIndex index, std::string& s);
{
u32 ID;
u32 m_Flag;
u16 m_Speed;
u8 m_Unknown[22];
// Not null terminated!
u16 m_Comment[2][COMMENT_SIZE];
u8 m_BannerTexture[TEXTURE_SIZE];
u8 m_IconTexture[8][ICON_SIZE];
} ;
u8* m_pBannerFile;
bool m_IsValid;
bool GetStringFromComments(const CommentIndex index, std::string& s);
}; };
} // namespace } // namespace