diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index f79d5a30a..662afb334 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -441,12 +441,12 @@ void Cheats::EnumerateChtFiles(const std::string_view serial, std::optional disk_patch_files; if (for_ui || !Achievements::IsHardcoreModeActive()) { - disk_patch_files = FindChtFilesOnDisk(serial, for_ui ? std::nullopt : hash, cheats); + disk_patch_files = FindChtFilesOnDisk(serial, hash, cheats); if (cheats && disk_patch_files.empty()) { // Check if there's an old-format titled file. if (ImportOldChtFile(serial)) - disk_patch_files = FindChtFilesOnDisk(serial, for_ui ? std::nullopt : hash, cheats); + disk_patch_files = FindChtFilesOnDisk(serial, hash, cheats); } } diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index 58b5ebeb2..719bd3426 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -281,7 +281,7 @@ static void SwitchToSettings(); static bool SwitchToGameSettings(); static void SwitchToGameSettings(const GameList::Entry* entry); static bool SwitchToGameSettingsForPath(const std::string& path); -static void SwitchToGameSettingsForSerial(std::string_view serial); +static void SwitchToGameSettingsForSerial(std::string_view serial, GameHash hash); static void DrawSettingsWindow(); static void DrawSummarySettingsPage(); static void DrawInterfaceSettingsPage(); @@ -386,7 +386,7 @@ static void DrawFolderSetting(SettingsInterface* bsi, const char* title, const c static void PopulateGraphicsAdapterList(); static void PopulateGameListDirectoryCache(SettingsInterface* si); -static void PopulatePatchesAndCheatsList(const std::string_view serial); +static void PopulatePatchesAndCheatsList(); static void PopulatePostProcessingChain(SettingsInterface* si, const char* section); static void BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::Type type, std::string_view section, std::string_view key, std::string_view display_name); @@ -491,6 +491,7 @@ struct ALIGN_TO_CACHE_LINE UIState std::string current_game_serial; std::string current_game_path; std::string achievements_user_badge_path; + GameHash current_game_hash = 0; // Resources std::shared_ptr app_icon_texture; @@ -509,6 +510,7 @@ struct ALIGN_TO_CACHE_LINE UIState SettingsPage settings_page = SettingsPage::Interface; std::unique_ptr game_settings_interface; std::string game_settings_serial; + GameHash game_settings_hash = 0; const GameDatabase::Entry* game_settings_db_entry; std::unique_ptr game_settings_entry; std::vector> game_list_directories_cache; @@ -681,7 +683,10 @@ bool FullscreenUI::Initialize() { Host::RunOnCPUThread([]() { if (System::IsValid()) - FullscreenUI::OnRunningGameChanged(System::GetDiscPath(), System::GetGameSerial(), System::GetGameTitle()); + { + FullscreenUI::OnRunningGameChanged(System::GetDiscPath(), System::GetGameSerial(), System::GetGameTitle(), + System::GetGameHash()); + } }); } @@ -772,19 +777,21 @@ void FullscreenUI::OnSystemDestroyed() }); } -void FullscreenUI::OnRunningGameChanged(const std::string& path, const std::string& serial, const std::string& title) +void FullscreenUI::OnRunningGameChanged(const std::string& path, const std::string& serial, const std::string& title, + GameHash hash) { // NOTE: Called on CPU thread. if (!IsInitialized()) return; - GPUThread::RunOnThread([path = path, title = title, serial = serial]() mutable { + GPUThread::RunOnThread([path = path, title = title, serial = serial, hash = hash]() mutable { if (!IsInitialized()) return; s_state.current_game_title = std::move(title); s_state.current_game_serial = std::move(serial); s_state.current_game_path = std::move(path); + s_state.current_game_hash = hash; }); } @@ -896,6 +903,7 @@ void FullscreenUI::Shutdown(bool clear_state) s_state.game_list_directories_cache = {}; s_state.game_settings_db_entry = nullptr; s_state.game_settings_entry.reset(); + s_state.game_settings_hash = 0; s_state.game_settings_serial = {}; s_state.game_settings_interface.reset(); s_state.game_settings_changed = false; @@ -908,6 +916,7 @@ void FullscreenUI::Shutdown(bool clear_state) s_state.fullscreen_mode_list_cache = {}; s_state.graphics_adapter_list_cache = {}; s_state.hotkey_list_cache = {}; + s_state.current_game_hash = 0; s_state.current_game_path = {}; s_state.current_game_serial = {}; s_state.current_game_title = {}; @@ -1007,12 +1016,15 @@ void FullscreenUI::Render() if (s_state.game_settings_interface->IsEmpty()) { - if (FileSystem::FileExists(s_state.game_settings_interface->GetPath().c_str()) && - !FileSystem::DeleteFile(s_state.game_settings_interface->GetPath().c_str(), &error)) + if (FileSystem::FileExists(s_state.game_settings_interface->GetPath().c_str())) { - OpenInfoMessageDialog(FSUI_STR("Error"), - fmt::format(FSUI_FSTR("An error occurred while deleting empty game settings:\n{}"), - error.GetDescription())); + INFO_LOG("Removing empty game settings {}", s_state.game_settings_interface->GetPath()); + if (!FileSystem::DeleteFile(s_state.game_settings_interface->GetPath().c_str(), &error)) + { + OpenInfoMessageDialog(FSUI_STR("Error"), + fmt::format(FSUI_FSTR("An error occurred while deleting empty game settings:\n{}"), + error.GetDescription())); + } } } else @@ -3313,6 +3325,7 @@ void FullscreenUI::SwitchToSettings() s_state.game_settings_entry.reset(); s_state.game_settings_interface.reset(); s_state.game_settings_serial = {}; + s_state.game_settings_hash = 0; s_state.game_settings_db_entry = nullptr; s_state.game_patch_list = {}; s_state.enabled_game_patch_cache = {}; @@ -3328,14 +3341,15 @@ void FullscreenUI::SwitchToSettings() s_state.settings_last_bg_alpha = GetBackgroundAlpha(); } -void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial) +void FullscreenUI::SwitchToGameSettingsForSerial(std::string_view serial, GameHash hash) { s_state.game_settings_serial = serial; + s_state.game_settings_hash = hash; s_state.game_settings_entry.reset(); s_state.game_settings_db_entry = GameDatabase::GetEntryForSerial(serial); s_state.game_settings_interface = System::GetGameSettingsInterface(s_state.game_settings_db_entry, serial, true, false); - PopulatePatchesAndCheatsList(serial); + PopulatePatchesAndCheatsList(); s_state.current_main_window = MainWindowType::Settings; s_state.settings_page = SettingsPage::Summary; QueueResetFocus(FocusResetType::ViewChanged); @@ -3350,7 +3364,7 @@ bool FullscreenUI::SwitchToGameSettings() const GameList::Entry* entry = GameList::GetEntryForPath(s_state.current_game_path); if (!entry) { - SwitchToGameSettingsForSerial(s_state.current_game_serial); + SwitchToGameSettingsForSerial(s_state.current_game_serial, entry->hash); return true; } else @@ -3373,7 +3387,7 @@ bool FullscreenUI::SwitchToGameSettingsForPath(const std::string& path) void FullscreenUI::SwitchToGameSettings(const GameList::Entry* entry) { - SwitchToGameSettingsForSerial(entry->serial); + SwitchToGameSettingsForSerial(entry->serial, entry->hash); s_state.game_settings_entry = std::make_unique(*entry); } @@ -3398,12 +3412,14 @@ void FullscreenUI::PopulateGameListDirectoryCache(SettingsInterface* si) s_state.game_list_directories_cache.emplace_back(std::move(dir), true); } -void FullscreenUI::PopulatePatchesAndCheatsList(const std::string_view serial) +void FullscreenUI::PopulatePatchesAndCheatsList() { - s_state.game_patch_list = Cheats::GetCodeInfoList(serial, std::nullopt, false, true, true); - s_state.game_cheats_list = Cheats::GetCodeInfoList( - serial, std::nullopt, true, s_state.game_settings_interface->GetBoolValue("Cheats", "LoadCheatsFromDatabase", true), - s_state.game_settings_interface->GetBoolValue("Cheats", "SortList", false)); + s_state.game_patch_list = + Cheats::GetCodeInfoList(s_state.game_settings_serial, s_state.game_settings_hash, false, true, true); + s_state.game_cheats_list = + Cheats::GetCodeInfoList(s_state.game_settings_serial, s_state.game_settings_hash, true, + s_state.game_settings_interface->GetBoolValue("Cheats", "LoadCheatsFromDatabase", true), + s_state.game_settings_interface->GetBoolValue("Cheats", "SortList", false)); s_state.game_cheat_groups = Cheats::GetCodeListUniquePrefixes(s_state.game_cheats_list, true); s_state.enabled_game_patch_cache = s_state.game_settings_interface->GetStringList(Cheats::PATCHES_CONFIG_SECTION, Cheats::PATCH_ENABLE_CONFIG_KEY); @@ -6421,7 +6437,7 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) else bsi->SetBoolValue("Cheats", "LoadCheatsFromDatabase", false); SetSettingsChanged(bsi); - PopulatePatchesAndCheatsList(s_state.game_settings_serial); + PopulatePatchesAndCheatsList(); } bool sort_list = bsi->GetBoolValue("Cheats", "SortList", false); @@ -6433,8 +6449,8 @@ void FullscreenUI::DrawPatchesOrCheatsSettingsPage(bool cheats) else bsi->SetBoolValue("Cheats", "SortList", true); SetSettingsChanged(bsi); - s_state.game_cheats_list = - Cheats::GetCodeInfoList(s_state.game_settings_serial, std::nullopt, true, load_database_cheats, sort_list); + s_state.game_cheats_list = Cheats::GetCodeInfoList(s_state.game_settings_serial, s_state.game_settings_hash, true, + load_database_cheats, sort_list); } if (code_list.empty()) diff --git a/src/core/fullscreen_ui.h b/src/core/fullscreen_ui.h index 3f505f265..7a7eb667c 100644 --- a/src/core/fullscreen_ui.h +++ b/src/core/fullscreen_ui.h @@ -1,10 +1,11 @@ -// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #pragma once #include "common/progress_callback.h" -#include "common/types.h" + +#include "types.h" #include #include @@ -23,7 +24,7 @@ void CheckForConfigChanges(const GPUSettings& old_settings); void OnSystemStarting(); void OnSystemResumed(); void OnSystemDestroyed(); -void OnRunningGameChanged(const std::string& path, const std::string& serial, const std::string& title); +void OnRunningGameChanged(const std::string& path, const std::string& serial, const std::string& title, GameHash hash); #ifndef __ANDROID__ void OpenPauseMenu(); diff --git a/src/core/system.cpp b/src/core/system.cpp index b41a503a0..3919b99e6 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -4221,7 +4221,7 @@ void System::UpdateRunningGame(const std::string& path, CDImage* image, bool boo UpdateRichPresence(booting); FullscreenUI::OnRunningGameChanged(s_state.running_game_path, s_state.running_game_serial, - s_state.running_game_title); + s_state.running_game_title, s_state.running_game_hash); Host::OnGameChanged(s_state.running_game_path, s_state.running_game_serial, s_state.running_game_title, s_state.running_game_hash); diff --git a/src/duckstation-qt/gamecheatsettingswidget.cpp b/src/duckstation-qt/gamecheatsettingswidget.cpp index c62b9b7b4..15748a34a 100644 --- a/src/duckstation-qt/gamecheatsettingswidget.cpp +++ b/src/duckstation-qt/gamecheatsettingswidget.cpp @@ -501,8 +501,8 @@ void GameCheatSettingsWidget::setStateRecursively(QStandardItem* parent, bool en void GameCheatSettingsWidget::reloadList() { - // Show all hashes, since the ini is shared. - m_codes = Cheats::GetCodeInfoList(m_dialog->getGameSerial(), std::nullopt, true, shouldLoadFromDatabase(), false); + m_codes = + Cheats::GetCodeInfoList(m_dialog->getGameSerial(), m_dialog->getGameHash(), true, shouldLoadFromDatabase(), false); m_enabled_codes = m_dialog->getSettingsInterface()->GetStringList(Cheats::CHEATS_CONFIG_SECTION, Cheats::PATCH_ENABLE_CONFIG_KEY);