2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2013-03-02 01:33:17 +00:00
|
|
|
#include <algorithm>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <cstddef>
|
2014-02-17 10:18:15 +00:00
|
|
|
#include <cstdio>
|
2014-02-21 00:47:53 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/ColorUtil.h"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "Common/CommonFuncs.h"
|
2014-02-19 01:02:01 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
|
|
|
#include "DiscIO/BannerLoaderWii.h"
|
2014-02-21 00:47:53 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2009-03-20 18:13:31 +00:00
|
|
|
|
2013-10-29 05:23:17 +00:00
|
|
|
CBannerLoaderWii::CBannerLoaderWii(DiscIO::IVolume *pVolume)
|
2008-12-08 05:30:24 +00:00
|
|
|
: m_pBannerFile(NULL)
|
|
|
|
, m_IsValid(false)
|
|
|
|
{
|
|
|
|
char Filename[260];
|
2009-04-28 23:47:18 +00:00
|
|
|
u64 TitleID;
|
|
|
|
|
2010-01-17 03:25:42 +00:00
|
|
|
pVolume->GetTitleID((u8*)&TitleID);
|
2009-06-07 02:54:07 +00:00
|
|
|
|
2009-04-28 23:47:18 +00:00
|
|
|
TitleID = Common::swap64(TitleID);
|
|
|
|
|
2010-02-02 21:56:29 +00:00
|
|
|
sprintf(Filename, "%stitle/%08x/%08x/data/banner.bin",
|
2011-02-28 20:40:15 +00:00
|
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
|
2009-03-20 18:13:31 +00:00
|
|
|
|
|
|
|
if (!File::Exists(Filename))
|
|
|
|
{
|
2009-06-06 14:33:52 +00:00
|
|
|
// TODO(XK): Finish the 'commented' code. Turns out the banner.bin
|
|
|
|
// from the savefiles is very different from the banner.bin
|
|
|
|
// inside opening.bnr
|
|
|
|
#if 0
|
|
|
|
char bnrFilename[260], titleFolder[260];
|
|
|
|
|
|
|
|
// Creating title folder
|
2010-02-02 21:56:29 +00:00
|
|
|
sprintf(titleFolder, "%stitle/%08x/%08x/data/",
|
2011-02-28 20:40:15 +00:00
|
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
|
2009-06-06 14:33:52 +00:00
|
|
|
if(!File::Exists(titleFolder))
|
|
|
|
File::CreateFullPath(titleFolder);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2009-06-06 14:33:52 +00:00
|
|
|
// Extracting banner.bin from opening.bnr
|
2010-02-02 21:56:29 +00:00
|
|
|
sprintf(bnrFilename, "%stitle/%08x/%08x/data/opening.bnr",
|
2011-02-28 20:40:15 +00:00
|
|
|
File::GetUserPath(D_WIIUSER_IDX).c_str(), (u32)(TitleID>>32), (u32)TitleID);
|
2009-06-06 14:33:52 +00:00
|
|
|
|
|
|
|
if(!_rFileSystem.ExportFile("opening.bnr", bnrFilename)) {
|
|
|
|
m_IsValid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CARCFile bnrArc (bnrFilename, 0x600);
|
|
|
|
|
|
|
|
if(!bnrArc.ExportFile("meta/banner.bin", Filename)) {
|
|
|
|
m_IsValid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we have an LZ77-compressed file with a short IMD5 header
|
|
|
|
// TODO: Finish the job
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2009-06-06 14:33:52 +00:00
|
|
|
File::Delete(bnrFilename);
|
|
|
|
#else
|
2009-03-20 18:13:31 +00:00
|
|
|
m_IsValid = false;
|
|
|
|
return;
|
2009-06-06 14:33:52 +00:00
|
|
|
#endif
|
2009-03-20 18:13:31 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-06-06 14:33:52 +00:00
|
|
|
// load the banner.bin
|
2008-12-20 18:46:49 +00:00
|
|
|
size_t FileSize = (size_t) File::GetSize(Filename);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
if (FileSize > 0)
|
|
|
|
{
|
|
|
|
m_pBannerFile = new u8[FileSize];
|
2011-03-11 10:21:46 +00:00
|
|
|
File::IOFile pFile(Filename, "rb");
|
2009-03-20 18:13:31 +00:00
|
|
|
if (pFile)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2011-03-11 10:21:46 +00:00
|
|
|
pFile.ReadBytes(m_pBannerFile, FileSize);
|
2008-12-08 05:30:24 +00:00
|
|
|
m_IsValid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CBannerLoaderWii::~CBannerLoaderWii()
|
|
|
|
{
|
|
|
|
if (m_pBannerFile)
|
|
|
|
{
|
|
|
|
delete [] m_pBannerFile;
|
|
|
|
m_pBannerFile = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-20 18:13:31 +00:00
|
|
|
bool CBannerLoaderWii::IsValid()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2009-03-20 18:13:31 +00:00
|
|
|
return m_IsValid;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 07:05:36 +00:00
|
|
|
std::vector<u32> CBannerLoaderWii::GetBanner(int* pWidth, int* pHeight)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2013-09-25 07:05:36 +00:00
|
|
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
|
|
|
std::vector<u32> Buffer;
|
|
|
|
Buffer.resize(192 * 64);
|
2013-10-02 22:18:54 +00:00
|
|
|
ColorUtil::decode5A3image(&Buffer[0], (u16*)pBanner->m_BannerTexture, 192, 64);
|
2013-09-25 07:05:36 +00:00
|
|
|
*pWidth = 192;
|
|
|
|
*pHeight = 64;
|
2013-09-27 01:15:35 +00:00
|
|
|
return Buffer;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2013-03-03 04:57:49 +00:00
|
|
|
bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& result)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2009-02-07 17:31:35 +00:00
|
|
|
if (IsValid())
|
2009-02-03 15:03:34 +00:00
|
|
|
{
|
2013-03-03 04:57:49 +00:00
|
|
|
auto const banner = reinterpret_cast<const SWiiBanner*>(m_pBannerFile);
|
|
|
|
auto const src_ptr = banner->m_Comment[index];
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-03-03 04:57:49 +00:00
|
|
|
// Trim at first NULL
|
|
|
|
auto const length = std::find(src_ptr, src_ptr + COMMENT_SIZE, 0x0) - src_ptr;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-03-03 04:57:49 +00:00
|
|
|
std::wstring src;
|
|
|
|
src.resize(length);
|
|
|
|
std::transform(src_ptr, src_ptr + src.size(), src.begin(), (u16(&)(u16))Common::swap16);
|
|
|
|
result = UTF16ToUTF8(src);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2011-12-19 05:56:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-03-03 04:57:49 +00:00
|
|
|
|
2011-12-19 05:56:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-03 01:46:55 +00:00
|
|
|
std::vector<std::string> CBannerLoaderWii::GetNames()
|
2011-11-28 07:17:10 +00:00
|
|
|
{
|
2013-03-03 01:46:55 +00:00
|
|
|
std::vector<std::string> ret(1);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-03-03 01:46:55 +00:00
|
|
|
if (!GetStringFromComments(NAME_IDX, ret[0]))
|
|
|
|
ret.clear();
|
2011-11-28 07:17:10 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-03 01:46:55 +00:00
|
|
|
std::string CBannerLoaderWii::GetCompany()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2013-03-03 01:46:55 +00:00
|
|
|
return "";
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2013-03-03 01:46:55 +00:00
|
|
|
std::vector<std::string> CBannerLoaderWii::GetDescriptions()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2013-03-03 01:46:55 +00:00
|
|
|
std::vector<std::string> result(1);
|
|
|
|
if (!GetStringFromComments(DESC_IDX, result[0]))
|
|
|
|
result.clear();
|
|
|
|
return result;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2010-12-22 06:45:59 +00:00
|
|
|
} // namespace
|