Skip to content
Permalink
Browse files

Merge pull request #7816 from JosJuice/titledatabase-edge-cases

Fix edge cases in TitleDatabase, cover downloading, Gecko code downloading
  • Loading branch information...
Tilka committed Feb 26, 2019
2 parents 02f5a75 + 71e6243 commit 19f4772e4772a199ec58e03df23e6e0e8bf003b9
@@ -30,6 +30,8 @@ private GameFile(long pointer)

public native String getGameId();

public native String getGameTdbId();

public native int getDiscNumber();

public native int getRevision();
@@ -43,7 +45,7 @@ private GameFile(long pointer)
public String getCoverPath()
{
return Environment.getExternalStorageDirectory().getPath() +
"/dolphin-emu/Cache/GameCovers/" + getGameId() + ".png";
"/dolphin-emu/Cache/GameCovers/" + getGameTdbId() + ".png";
}

public String getCustomCoverPath()
@@ -12,10 +12,7 @@

public static String buildGameTDBUrl(GameFile game, String region)
{
String gameId = game.getGameId();
if (game.getPlatform() == 2) // WiiWare
gameId = gameId.substring(0, 4);
return String.format(baseUrl, region, gameId);
return String.format(baseUrl, region, game.getGameTdbId());
}

public static String getRegion(GameFile game)
@@ -77,4 +74,4 @@ public static void saveCover(Bitmap cover, String path)
// Do nothing
}
}
}
}
@@ -123,6 +123,12 @@ JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameI
return ToJString(env, GetRef(env, obj)->GetGameID());
}

JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getGameTdbId(JNIEnv* env,
jobject obj)
{
return ToJString(env, GetRef(env, obj)->GetGameTDBID());
}

JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFile_getDiscNumber(JNIEnv* env,
jobject obj)
{
@@ -680,22 +680,22 @@ void SConfig::LoadJitDebugSettings(IniFile& ini)

void SConfig::ResetRunningGameMetadata()
{
SetRunningGameMetadata("00000000", 0, 0, Core::TitleDatabase::TitleType::Other);
SetRunningGameMetadata("00000000", "", 0, 0);
}

void SConfig::SetRunningGameMetadata(const DiscIO::Volume& volume,
const DiscIO::Partition& partition)
{
if (partition == volume.GetGamePartition())
{
SetRunningGameMetadata(volume.GetGameID(), volume.GetTitleID().value_or(0),
volume.GetRevision().value_or(0), Core::TitleDatabase::TitleType::Other);
SetRunningGameMetadata(volume.GetGameID(), volume.GetGameTDBID(),
volume.GetTitleID().value_or(0), volume.GetRevision().value_or(0));
}
else
{
SetRunningGameMetadata(volume.GetGameID(partition), volume.GetTitleID(partition).value_or(0),
volume.GetRevision(partition).value_or(0),
Core::TitleDatabase::TitleType::Other);
SetRunningGameMetadata(volume.GetGameID(partition), volume.GetGameTDBID(),
volume.GetTitleID(partition).value_or(0),
volume.GetRevision(partition).value_or(0));
}
}

@@ -710,16 +710,18 @@ void SConfig::SetRunningGameMetadata(const IOS::ES::TMDReader& tmd)
if (!DVDInterface::UpdateRunningGameMetadata(tmd_title_id))
{
// If not launching a disc game, just read everything from the TMD.
SetRunningGameMetadata(tmd.GetGameID(), tmd_title_id, tmd.GetTitleVersion(),
Core::TitleDatabase::TitleType::Channel);
const std::string game_id = tmd.GetGameID();
SetRunningGameMetadata(game_id, game_id, tmd_title_id, tmd.GetTitleVersion());
}
}

void SConfig::SetRunningGameMetadata(const std::string& game_id, u64 title_id, u16 revision,
Core::TitleDatabase::TitleType type)
void SConfig::SetRunningGameMetadata(const std::string& game_id, const std::string& gametdb_id,
u64 title_id, u16 revision)
{
const bool was_changed = m_game_id != game_id || m_title_id != title_id || m_revision != revision;
const bool was_changed = m_game_id != game_id || m_gametdb_id != gametdb_id ||
m_title_id != title_id || m_revision != revision;
m_game_id = game_id;
m_gametdb_id = gametdb_id;
m_title_id = title_id;
m_revision = revision;

@@ -747,7 +749,7 @@ void SConfig::SetRunningGameMetadata(const std::string& game_id, u64 title_id, u
}

const Core::TitleDatabase title_database;
m_title_description = title_database.Describe(m_game_id, type);
m_title_description = title_database.Describe(m_gametdb_id, GetCurrentLanguage(bWii));
NOTICE_LOG(CORE, "Active title: %s", m_title_description.c_str());

Config::AddLayer(ConfigLoaders::GenerateGlobalGameConfigLoader(game_id, revision));
@@ -367,12 +367,13 @@ struct SConfig
void LoadAutoUpdateSettings(IniFile& ini);
void LoadJitDebugSettings(IniFile& ini);

void SetRunningGameMetadata(const std::string& game_id, u64 title_id, u16 revision,
Core::TitleDatabase::TitleType type);
void SetRunningGameMetadata(const std::string& game_id, const std::string& gametdb_id,
u64 title_id, u16 revision);

static SConfig* m_Instance;

std::string m_game_id;
std::string m_gametdb_id;
std::string m_title_description;
u64 m_title_id;
u16 m_revision;
@@ -16,21 +16,9 @@

namespace Gecko
{
std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded)
std::vector<GeckoCode> DownloadCodes(std::string gametdb_id, bool* succeeded)
{
switch (gameid[0])
{
case 'R':
case 'S':
case 'G':
break;
default:
// All channels (WiiWare, VirtualConsole, etc) are identified by their first four characters
gameid = gameid.substr(0, 4);
break;
}

std::string endpoint{"https://www.geckocodes.org/txt.php?txt=" + gameid};
std::string endpoint{"https://www.geckocodes.org/txt.php?txt=" + gametdb_id};
Common::HttpRequest http;

// Circumvent high-tech DDOS protection
@@ -13,6 +13,6 @@ class IniFile;
namespace Gecko
{
std::vector<GeckoCode> LoadCodes(const IniFile& globalIni, const IniFile& localIni);
std::vector<GeckoCode> DownloadCodes(std::string gameid, bool* succeeded);
std::vector<GeckoCode> DownloadCodes(std::string gametdb_id, bool* succeeded);
void SaveCodes(IniFile& inifile, const std::vector<GeckoCode>& gcodes);
}
@@ -323,6 +323,20 @@ std::string TMDReader::GetGameID() const
return StringFromFormat("%016" PRIx64, GetTitleId());
}

std::string TMDReader::GetGameTDBID() const
{
const u8* begin = m_bytes.data() + offsetof(TMDHeader, title_id) + 4;
const u8* end = begin + 4;

const bool all_printable =
std::all_of(begin, end, [](char c) { return std::isprint(c, std::locale::classic()); });

if (all_printable)
return std::string(begin, end);

return StringFromFormat("%016" PRIx64, GetTitleId());
}

u16 TMDReader::GetNumContents() const
{
return Common::swap16(m_bytes.data() + offsetof(TMDHeader, num_contents));
@@ -205,9 +205,15 @@ class TMDReader final : public SignedBlobReader

// 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.
// the title ID converted to 16 hexadecimal digits is returned instead.
std::string GetGameID() const;

// Constructs a 4-character game ID in the format typically used by GameTDB.
// If the 4-character game ID would contain unprintable characters,
// the title ID converted to 16 hexadecimal digits is returned instead
// (a format which GameTDB does not actually use).
std::string GetGameTDBID() const;

u16 GetNumContents() const;
bool GetContent(u16 index, Content* content) const;
std::vector<Content> GetContents() const;

0 comments on commit 19f4772

Please sign in to comment.
You can’t perform that action at this time.