Merge pull request #6162 from JosJuice/nand-check-save-game-name

When NAND is damaged, show title names from save files
This commit is contained in:
Anthony
2017-11-06 23:11:34 -08:00
committed by GitHub
16 changed files with 213 additions and 77 deletions

View File

@ -18,6 +18,7 @@ set(SRCS
VolumeGC.cpp
VolumeWad.cpp
VolumeWii.cpp
WiiSaveBanner.cpp
WiiWad.cpp
)

View File

@ -55,6 +55,7 @@
<ClCompile Include="VolumeWad.cpp" />
<ClCompile Include="VolumeWii.cpp" />
<ClCompile Include="WbfsBlob.cpp" />
<ClCompile Include="WiiSaveBanner.cpp" />
<ClCompile Include="WiiWad.cpp" />
</ItemGroup>
<ItemGroup>
@ -77,6 +78,7 @@
<ClInclude Include="VolumeWad.h" />
<ClInclude Include="VolumeWii.h" />
<ClInclude Include="WbfsBlob.h" />
<ClInclude Include="WiiSaveBanner.h" />
<ClInclude Include="WiiWad.h" />
</ItemGroup>
<ItemGroup>
@ -96,4 +98,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>

View File

@ -81,6 +81,9 @@
<ClCompile Include="DiscExtractor.cpp">
<Filter>DiscExtractor</Filter>
</ClCompile>
<ClCompile Include="WiiSaveBanner.cpp">
<Filter>NAND</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="DiscScrubber.h">
@ -143,8 +146,11 @@
<ClInclude Include="DiscExtractor.h">
<Filter>DiscExtractor</Filter>
</ClInclude>
<ClInclude Include="WiiSaveBanner.h">
<Filter>NAND</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
</Project>
</Project>

View File

@ -12,13 +12,8 @@
#include <utility>
#include <vector>
#include "Common/ColorUtil.h"
#include "Common/CommonTypes.h"
#include "Common/File.h"
#include "Common/FileUtil.h"
#include "Common/NandPaths.h"
#include "Common/StringUtil.h"
#include "Common/Swap.h"
#include "DiscIO/Blob.h"
#include "DiscIO/Enums.h"
@ -28,56 +23,18 @@
namespace DiscIO
{
static const unsigned int WII_BANNER_WIDTH = 192;
static const unsigned int WII_BANNER_HEIGHT = 64;
static const unsigned int WII_BANNER_SIZE = WII_BANNER_WIDTH * WII_BANNER_HEIGHT * 2;
static const unsigned int WII_BANNER_OFFSET = 0xA0;
const IOS::ES::TicketReader Volume::INVALID_TICKET{};
const IOS::ES::TMDReader Volume::INVALID_TMD{};
std::vector<u32> Volume::GetWiiBanner(int* width, int* height, u64 title_id)
{
*width = 0;
*height = 0;
const std::string file_name =
Common::GetTitleDataPath(title_id, Common::FROM_CONFIGURED_ROOT) + "banner.bin";
File::IOFile file(file_name, "rb");
if (file.GetSize() < WII_BANNER_OFFSET + WII_BANNER_SIZE)
return std::vector<u32>();
if (!file.Seek(WII_BANNER_OFFSET, SEEK_SET))
return std::vector<u32>();
std::vector<u8> banner_file(WII_BANNER_SIZE);
if (!file.ReadBytes(banner_file.data(), banner_file.size()))
return std::vector<u32>();
std::vector<u32> image_buffer(WII_BANNER_WIDTH * WII_BANNER_HEIGHT);
ColorUtil::decode5A3image(image_buffer.data(), (u16*)banner_file.data(), WII_BANNER_WIDTH,
WII_BANNER_HEIGHT);
*width = WII_BANNER_WIDTH;
*height = WII_BANNER_HEIGHT;
return image_buffer;
}
std::map<Language, std::string> Volume::ReadWiiNames(const std::vector<u8>& data)
std::map<Language, std::string> Volume::ReadWiiNames(const std::vector<char16_t>& data)
{
std::map<Language, std::string> names;
for (size_t i = 0; i < NUMBER_OF_LANGUAGES; ++i)
{
size_t name_start = NAME_BYTES_LENGTH * i;
size_t name_end = name_start + NAME_BYTES_LENGTH;
if (data.size() >= name_end)
const size_t name_start = NAME_CHARS_LENGTH * i;
if (name_start + NAME_CHARS_LENGTH <= data.size())
{
u16* temp = (u16*)(data.data() + name_start);
std::wstring out_temp(NAME_STRING_LENGTH, '\0');
std::transform(temp, temp + out_temp.size(), out_temp.begin(), (u16(&)(u16))Common::swap16);
out_temp.erase(std::find(out_temp.begin(), out_temp.end(), 0x00), out_temp.end());
std::string name = UTF16ToUTF8(out_temp);
const std::string name = UTF16BEToUTF8(data.data() + name_start, NAME_CHARS_LENGTH);
if (!name.empty())
names[static_cast<Language>(i)] = name;
}

View File

@ -102,8 +102,6 @@ public:
// Size on disc (compressed size)
virtual u64 GetRawSize() const = 0;
static std::vector<u32> GetWiiBanner(int* width, int* height, u64 title_id);
protected:
template <u32 N>
std::string DecodeString(const char (&data)[N]) const
@ -118,11 +116,12 @@ protected:
}
virtual u32 GetOffsetShift() const { return 0; }
static std::map<Language, std::string> ReadWiiNames(const std::vector<u8>& data);
static std::map<Language, std::string> ReadWiiNames(const std::vector<char16_t>& data);
static const size_t NUMBER_OF_LANGUAGES = 10;
static const size_t NAME_STRING_LENGTH = 42;
static const size_t NAME_BYTES_LENGTH = NAME_STRING_LENGTH * sizeof(u16);
static const size_t NAME_CHARS_LENGTH = 42;
static const size_t NAME_BYTES_LENGTH = NAME_CHARS_LENGTH * sizeof(char16_t);
static const size_t NAMES_TOTAL_CHARS = NAME_CHARS_LENGTH * NUMBER_OF_LANGUAGES;
static const size_t NAMES_TOTAL_BYTES = NAME_BYTES_LENGTH * NUMBER_OF_LANGUAGES;
static const IOS::ES::TicketReader INVALID_TICKET;

View File

@ -22,6 +22,7 @@
#include "DiscIO/Enums.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeWad.h"
#include "DiscIO/WiiSaveBanner.h"
namespace DiscIO
{
@ -137,10 +138,10 @@ std::map<Language, std::string> VolumeWAD::GetLongNames() const
if (!m_tmd.IsValid() || !IOS::ES::IsChannel(m_tmd.GetTitleId()))
return {};
std::vector<u8> name_data(NAMES_TOTAL_BYTES);
if (!Read(m_opening_bnr_offset + 0x9C, NAMES_TOTAL_BYTES, name_data.data()))
std::vector<char16_t> names(NAMES_TOTAL_CHARS);
if (!Read(m_opening_bnr_offset + 0x9C, NAMES_TOTAL_BYTES, reinterpret_cast<u8*>(names.data())))
return std::map<Language, std::string>();
return ReadWiiNames(name_data);
return ReadWiiNames(names);
}
std::vector<u32> VolumeWAD::GetBanner(int* width, int* height) const
@ -152,7 +153,7 @@ std::vector<u32> VolumeWAD::GetBanner(int* width, int* height) const
if (!title_id)
return std::vector<u32>();
return GetWiiBanner(width, height, *title_id);
return WiiSaveBanner(*title_id).GetBanner(width, height);
}
BlobType VolumeWAD::GetBlobType() const

View File

@ -29,6 +29,7 @@
#include "DiscIO/FileSystemGCWii.h"
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
#include "DiscIO/WiiSaveBanner.h"
namespace DiscIO
{
@ -301,10 +302,10 @@ std::string VolumeWii::GetInternalName(const Partition& partition) const
std::map<Language, std::string> VolumeWii::GetLongNames() const
{
std::vector<u8> opening_bnr(NAMES_TOTAL_BYTES);
opening_bnr.resize(ReadFile(*this, GetGamePartition(), "opening.bnr", opening_bnr.data(),
opening_bnr.size(), 0x5C));
return ReadWiiNames(opening_bnr);
std::vector<char16_t> names(NAMES_TOTAL_CHARS);
names.resize(ReadFile(*this, GetGamePartition(), "opening.bnr",
reinterpret_cast<u8*>(names.data()), NAMES_TOTAL_BYTES, 0x5C));
return ReadWiiNames(names);
}
std::vector<u32> VolumeWii::GetBanner(int* width, int* height) const
@ -316,7 +317,7 @@ std::vector<u32> VolumeWii::GetBanner(int* width, int* height) const
if (!title_id)
return std::vector<u32>();
return GetWiiBanner(width, height, *title_id);
return WiiSaveBanner(*title_id).GetBanner(width, height);
}
std::string VolumeWii::GetApploaderDate(const Partition& partition) const

View File

@ -0,0 +1,78 @@
// Copyright 2009 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DiscIO/WiiSaveBanner.h"
#include <string>
#include <vector>
#include "Common/ColorUtil.h"
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/File.h"
#include "Common/NandPaths.h"
#include "Common/StringUtil.h"
namespace DiscIO
{
constexpr unsigned int BANNER_WIDTH = 192;
constexpr unsigned int BANNER_HEIGHT = 64;
constexpr unsigned int BANNER_SIZE = BANNER_WIDTH * BANNER_HEIGHT * 2;
constexpr unsigned int ICON_WIDTH = 48;
constexpr unsigned int ICON_HEIGHT = 48;
constexpr unsigned int ICON_SIZE = ICON_WIDTH * ICON_HEIGHT * 2;
WiiSaveBanner::WiiSaveBanner(u64 title_id)
: WiiSaveBanner(Common::GetTitleDataPath(title_id, Common::FROM_CONFIGURED_ROOT) + "banner.bin")
{
}
WiiSaveBanner::WiiSaveBanner(const std::string& path) : m_path(path), m_valid(true)
{
constexpr size_t MINIMUM_SIZE = sizeof(Header) + BANNER_SIZE + ICON_SIZE;
File::IOFile file(path, "rb");
if (!file.ReadArray(&m_header, 1))
{
m_header = {};
m_valid = false;
}
else if (file.GetSize() < MINIMUM_SIZE)
{
m_valid = false;
}
}
std::string WiiSaveBanner::GetName() const
{
return UTF16BEToUTF8(m_header.name, ArraySize(m_header.name));
}
std::string WiiSaveBanner::GetDescription() const
{
return UTF16BEToUTF8(m_header.description, ArraySize(m_header.description));
}
std::vector<u32> WiiSaveBanner::GetBanner(int* width, int* height) const
{
*width = 0;
*height = 0;
File::IOFile file(m_path, "rb");
if (!file.Seek(sizeof(Header), SEEK_SET))
return std::vector<u32>();
std::vector<u16> banner_data(BANNER_WIDTH * BANNER_HEIGHT);
if (!file.ReadArray(banner_data.data(), banner_data.size()))
return std::vector<u32>();
std::vector<u32> image_buffer(BANNER_WIDTH * BANNER_HEIGHT);
ColorUtil::decode5A3image(image_buffer.data(), banner_data.data(), BANNER_WIDTH, BANNER_HEIGHT);
*width = BANNER_WIDTH;
*height = BANNER_HEIGHT;
return image_buffer;
}
} // namespace DiscIO

View File

@ -0,0 +1,41 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include <vector>
#include "Common/CommonTypes.h"
namespace DiscIO
{
class WiiSaveBanner
{
public:
explicit WiiSaveBanner(u64 title_id);
explicit WiiSaveBanner(const std::string& path);
bool IsValid() const { return m_valid; }
const std::string& GetPath() const { return m_path; }
std::string GetName() const;
std::string GetDescription() const;
std::vector<u32> GetBanner(int* width, int* height) const;
private:
struct Header
{
char magic[4]; // "WIBN"
u32 flags;
u16 animation_speed;
u8 unused[22];
char16_t name[32];
char16_t description[32];
} m_header;
bool m_valid;
std::string m_path;
};
}