Use 6-char game IDs for NAND tiles (if they are printable)

5.0-2712 made ES's code for setting the game ID use the
title ID converted to hex (except for disc titles) instead
of using a 6-char game ID like before. Then, 5.0-2830 made
us use that code even when loading game INIs. This breaks the
expectations of both users and the game INIs we ship with.

This commit makes Dolphin use 6-char game IDs for all
titles (unless the 6-char ID would contain unprintable
characters, which is the case with e.g. the Wii Menu).

I'm also putting unprintability checks in VolumeWad
for consistency.
This commit is contained in:
JosJuice 2017-03-16 10:28:17 +01:00
parent 1e7dd1ed2d
commit ff7425214a
4 changed files with 36 additions and 14 deletions

View File

@ -766,8 +766,7 @@ void SConfig::SetRunningGameMetadata(const IOS::ES::TMDReader& tmd)
}
// If not launching a disc game, just read everything from the TMD.
SetRunningGameMetadata(StringFromFormat("%016" PRIX64, tmd_title_id), tmd_title_id,
tmd.GetTitleVersion());
SetRunningGameMetadata(tmd.GetGameID(), tmd_title_id, tmd.GetTitleVersion());
}
void SConfig::SetRunningGameMetadata(const std::string& game_id, u64 title_id, u16 revision)

View File

@ -5,14 +5,18 @@
#include "Core/IOS/ES/Formats.h"
#include <algorithm>
#include <cinttypes>
#include <cstddef>
#include <cstring>
#include <locale>
#include <string>
#include <utility>
#include <vector>
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Crypto/AES.h"
#include "Common/StringUtil.h"
#include "Common/Swap.h"
#include "Core/ec_wii.h"
@ -138,6 +142,22 @@ u16 TMDReader::GetGroupId() const
return Common::swap16(m_bytes.data() + offsetof(TMDHeader, group_id));
}
std::string TMDReader::GetGameID() const
{
char game_id[6];
std::memcpy(game_id, m_bytes.data() + offsetof(TMDHeader, title_id) + 4, 4);
std::memcpy(game_id + 4, m_bytes.data() + offsetof(TMDHeader, group_id), 2);
const bool all_printable = std::all_of(std::begin(game_id), std::end(game_id), [](char c) {
return std::isprint(c, std::locale::classic());
});
if (all_printable)
return std::string(game_id, sizeof(game_id));
return StringFromFormat("%016" PRIx64, GetTitleId());
}
u16 TMDReader::GetNumContents() const
{
return Common::swap16(m_bytes.data() + offsetof(TMDHeader, num_contents));

View File

@ -8,6 +8,7 @@
#pragma once
#include <array>
#include <string>
#include <vector>
#include "Common/ChunkFile.h"
@ -142,6 +143,11 @@ public:
u16 GetTitleVersion() const;
u16 GetGroupId() const;
// Constructs a 6-character game ID in the format typically used by Dolphin.
// If the 6-character game ID would contain unprintable characters,
// the title ID converted to hexadecimal is returned instead.
std::string GetGameID() const;
u16 GetNumContents() const;
bool GetContent(u16 index, Content* content) const;
std::vector<Content> GetContents() const;

View File

@ -4,6 +4,7 @@
#include <cstddef>
#include <cstring>
#include <locale>
#include <map>
#include <memory>
#include <string>
@ -89,22 +90,18 @@ IOS::ES::TMDReader CVolumeWAD::GetTMD() const
std::string CVolumeWAD::GetGameID() const
{
char GameCode[6];
if (!Read(m_offset + 0x01E0, 4, (u8*)GameCode))
return "0";
std::string temp = GetMakerID();
GameCode[4] = temp.at(0);
GameCode[5] = temp.at(1);
return DecodeString(GameCode);
return m_tmd.GetGameID();
}
std::string CVolumeWAD::GetMakerID() const
{
char temp[2] = {1};
// Some weird channels use 0x0000 in place of the MakerID, so we need a check there
if (!Read(0x198 + m_tmd_offset, 2, (u8*)temp) || temp[0] == 0 || temp[1] == 0)
char temp[2];
if (!Read(0x198 + m_tmd_offset, 2, (u8*)temp))
return "00";
// Some weird channels use 0x0000 in place of the MakerID, so we need a check here
const std::locale& c_locale = std::locale::classic();
if (!std::isprint(temp[0], c_locale) || !std::isprint(temp[1], c_locale))
return "00";
return DecodeString(temp);