Read opening.bnr to get names from Wii discs

This makes Dolphin display the same names as the Disc Channel.
This commit is contained in:
JosJuice 2015-04-10 23:18:41 +02:00
parent 272f9d3cbc
commit 2d5d5fa83e
4 changed files with 38 additions and 36 deletions

View File

@ -113,6 +113,13 @@ protected:
else
return CP1252ToUTF8(string);
}
static std::map<IVolume::ELanguage, std::string> ReadWiiNames(std::vector<u8>& 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 NAMES_TOTAL_BYTES = NAME_BYTES_LENGTH * NUMBER_OF_LANGUAGES;
};
// Generic Switch function for all volumes

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <algorithm>
#include <map>
#include <string>
#include <utility>
@ -56,6 +57,27 @@ std::vector<u32> IVolume::GetBanner(int* width, int* height) const
return image_buffer;
}
std::map<IVolume::ELanguage, std::string> IVolume::ReadWiiNames(std::vector<u8>& data)
{
std::map<IVolume::ELanguage, 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)
{
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);
if (!name.empty())
names[(IVolume::ELanguage)i] = name;
}
}
return names;
}
// Increment CACHE_REVISION if the code below is modified (ISOFile.cpp & GameFile.cpp)
IVolume::ECountry CountrySwitch(u8 country_code)
{

View File

@ -2,7 +2,6 @@
// Licensed under GPLv2
// Refer to the license.txt file included.
#include <algorithm>
#include <cstddef>
#include <map>
#include <string>
@ -120,37 +119,10 @@ bool CVolumeWAD::IsWadFile() const
std::map<IVolume::ELanguage, std::string> CVolumeWAD::GetNames() const
{
std::map<IVolume::ELanguage, std::string> names;
u32 footer_size;
if (!Read(0x1C, 4, (u8*)&footer_size))
{
return names;
}
footer_size = Common::swap32(footer_size);
//Japanese, English, German, French, Spanish, Italian, Dutch, Simplified Chinese, Traditional Chinese, Korean
for (int i = 0; i < 10; ++i)
{
static const u32 string_length = 42;
static const u32 bytes_length = string_length * sizeof(u16);
u16 temp[string_length];
if (footer_size >= 0xF1 && Read(0x9C + (i * bytes_length) + m_opening_bnr_offset, bytes_length, (u8*)&temp))
{
std::wstring out_temp;
out_temp.resize(string_length);
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);
if (!name.empty())
names[(IVolume::ELanguage)i] = name;
}
}
return names;
std::vector<u8> name_data(NAMES_TOTAL_BYTES);
if (!Read(m_opening_bnr_offset + 0x9C, NAMES_TOTAL_BYTES, name_data.data()))
return std::map<IVolume::ELanguage, std::string>();
return ReadWiiNames(name_data);
}
u64 CVolumeWAD::GetSize() const

View File

@ -16,6 +16,7 @@
#include "Common/Logging/Log.h"
#include "DiscIO/Blob.h"
#include "DiscIO/FileMonitor.h"
#include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeCreator.h"
#include "DiscIO/VolumeGC.h"
@ -203,10 +204,10 @@ std::string CVolumeWiiCrypted::GetName() const
std::map<IVolume::ELanguage, std::string> CVolumeWiiCrypted::GetNames() const
{
// TODO: Read opening.bnr
std::map<IVolume::ELanguage, std::string> names;
names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = GetName();
return names;
std::unique_ptr<IFileSystem> file_system(CreateFileSystem(this));
std::vector<u8> opening_bnr(NAMES_TOTAL_BYTES);
opening_bnr.resize(file_system->ReadFile("opening.bnr", opening_bnr.data(), opening_bnr.size(), 0x5C));
return ReadWiiNames(opening_bnr);
}
u32 CVolumeWiiCrypted::GetFSTSize() const