From 41b485aa0ae8e31a94424bf105ef54cb84a22dde Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 2 Jun 2017 20:54:28 -0700 Subject: [PATCH] Core: Refactor repeating disc id homebrew code. --- Core/ELF/ParamSFO.h | 8 ++++++++ Core/System.cpp | 5 +---- Core/TextureReplacer.cpp | 5 +---- GPU/Common/FramebufferCommon.cpp | 4 ---- GPU/GLES/GPU_GLES.cpp | 5 +---- UI/GameSettingsScreen.cpp | 5 +---- UI/NativeApp.cpp | 5 +---- UI/PauseScreen.cpp | 10 ++-------- 8 files changed, 15 insertions(+), 32 deletions(-) diff --git a/Core/ELF/ParamSFO.h b/Core/ELF/ParamSFO.h index ead49feff8..940280bac3 100644 --- a/Core/ELF/ParamSFO.h +++ b/Core/ELF/ParamSFO.h @@ -37,6 +37,14 @@ public: std::vector GetKeys(); std::string GenerateFakeID(std::string filename = ""); + std::string GetDiscID() { + const std::string discID = GetValueString("DISC_ID"); + if (discID.empty()) { + return GenerateFakeID(); + } + return discID; + } + bool ReadSFO(const u8 *paramsfo, size_t size); bool WriteSFO(u8 **paramsfo, size_t *size); diff --git a/Core/System.cpp b/Core/System.cpp index 89a5151edc..05e47333eb 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -242,10 +242,7 @@ void CPU_Init() { // Here we have read the PARAM.SFO, let's see if we need any compatibility overrides. // Homebrew usually has an empty discID, and even if they do have a disc id, it's not // likely to collide with any commercial ones. - std::string discID = g_paramSFO.GetValueString("DISC_ID"); - if (discID.empty()) { - discID = g_paramSFO.GenerateFakeID(); - } + std::string discID = g_paramSFO.GetDiscID(); coreParameter.compat.Load(discID); Memory::Init(); diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index 2889d9b9d7..c19054dccd 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -47,10 +47,7 @@ void TextureReplacer::Init() { } void TextureReplacer::NotifyConfigChanged() { - gameID_ = g_paramSFO.GetValueString("DISC_ID"); - if (gameID_.empty()) { - gameID_ = g_paramSFO.GenerateFakeID(); - } + gameID_ = g_paramSFO.GetDiscID(); enabled_ = g_Config.bReplaceTextures || g_Config.bSaveNewTextures; if (enabled_) { diff --git a/GPU/Common/FramebufferCommon.cpp b/GPU/Common/FramebufferCommon.cpp index 548ffb54d1..d3ffcb3755 100644 --- a/GPU/Common/FramebufferCommon.cpp +++ b/GPU/Common/FramebufferCommon.cpp @@ -119,10 +119,6 @@ FramebufferManagerCommon::~FramebufferManagerCommon() { } void FramebufferManagerCommon::Init() { - std::string gameId = g_paramSFO.GetValueString("DISC_ID"); - if (gameId.empty()) { - gameId = g_paramSFO.GenerateFakeID(); - } BeginFrame(); } diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index 60a00b0e70..7f66c9de42 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -168,10 +168,7 @@ GPU_GLES::GPU_GLES(GraphicsContext *gfxCtx, Draw::DrawContext *draw) textureCacheGL_->NotifyConfigChanged(); // Load shader cache. - std::string discID = g_paramSFO.GetValueString("DISC_ID"); - if (discID.empty()) { - discID = g_paramSFO.GenerateFakeID(); - } + std::string discID = g_paramSFO.GetDiscID(); if (discID.size()) { File::CreateFullPath(GetSysDirectory(DIRECTORY_APP_CACHE)); shaderCachePath_ = GetSysDirectory(DIRECTORY_APP_CACHE) + "/" + discID + ".glshadercache"; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 1f8deb6119..cce054af0f 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1336,10 +1336,7 @@ UI::EventReturn DeveloperToolsScreen::OnLoadLanguageIni(UI::EventParams &e) { } UI::EventReturn DeveloperToolsScreen::OnOpenTexturesIniFile(UI::EventParams &e) { - std::string gameID = g_paramSFO.GetValueString("DISC_ID"); - if (gameID.empty()) { - gameID = g_paramSFO.GenerateFakeID(); - } + std::string gameID = g_paramSFO.GetDiscID(); std::string texturesDirectory = GetSysDirectory(DIRECTORY_TEXTURES) + gameID + "/"; bool enabled_ = !gameID.empty(); if (enabled_) { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index d1e21c9b05..0f293b8831 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -713,10 +713,7 @@ void TakeScreenshot() { // First, find a free filename. int i = 0; - std::string gameId = g_paramSFO.GetValueString("DISC_ID"); - if (gameId.empty()) { - gameId = g_paramSFO.GenerateFakeID(); - } + std::string gameId = g_paramSFO.GetDiscID(); char filename[2048]; while (i < 10000){ diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index 60b7f5a94f..5e45f1e5eb 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -320,10 +320,7 @@ void GamePauseScreen::CreateViews() { root_->SetDefaultFocusView(continueChoice); continueChoice->OnClick.Handle(this, &UIScreen::OnBack); - std::string gameId = g_paramSFO.GetValueString("DISC_ID"); - if (gameId.empty()) { - gameId = g_paramSFO.GenerateFakeID(); - } + std::string gameId = g_paramSFO.GetDiscID(); if (g_Config.hasGameConfig(gameId)) { rightColumnItems->Add(new Choice(pa->T("Game Settings")))->OnClick.Handle(this, &GamePauseScreen::OnGameSettings); rightColumnItems->Add(new Choice(pa->T("Delete Game Config")))->OnClick.Handle(this, &GamePauseScreen::OnDeleteConfig); @@ -424,10 +421,7 @@ void GamePauseScreen::CallbackDeleteConfig(bool yes) UI::EventReturn GamePauseScreen::OnCreateConfig(UI::EventParams &e) { - std::string gameId = g_paramSFO.GetValueString("DISC_ID"); - if (gameId.empty()) { - gameId = g_paramSFO.GenerateFakeID(); - } + std::string gameId = g_paramSFO.GetDiscID(); g_Config.createGameConfig(gameId); g_Config.changeGameSpecific(gameId); g_Config.saveGameConfig(gameId);