diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index 6f5078a6a..b3fe45983 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -216,7 +216,8 @@ static bool AreAnyPatchesEnabled(); static void ReloadEnabledLists(); static u32 EnableCheats(const CheatCodeList& patches, const EnableCodeList& enable_list, const char* section, bool hc_mode_active); -static void UpdateActiveCodes(bool reload_enabled_list, bool verbose, bool verbose_if_changed); +static void UpdateActiveCodes(bool reload_enabled_list, bool verbose, bool verbose_if_changed, + bool show_disabled_codes); template bool SearchCheatArchive(CheatArchive& archive, std::string_view serial, std::optional hash, const F& f); @@ -870,7 +871,8 @@ u32 Cheats::EnableCheats(const CheatCodeList& patches, const EnableCodeList& ena return count; } -void Cheats::ReloadCheats(bool reload_files, bool reload_enabled_list, bool verbose, bool verbose_if_changed) +void Cheats::ReloadCheats(bool reload_files, bool reload_enabled_list, bool verbose, bool verbose_if_changed, + bool show_disabled_codes) { for (const CheatCode* code : s_frame_end_codes) code->ApplyOnDisable(); @@ -917,7 +919,7 @@ void Cheats::ReloadCheats(bool reload_files, bool reload_enabled_list, bool verb } } - UpdateActiveCodes(reload_enabled_list, verbose, verbose_if_changed); + UpdateActiveCodes(reload_enabled_list, verbose, verbose_if_changed, show_disabled_codes); } void Cheats::UnloadAll() @@ -969,7 +971,8 @@ void Cheats::ApplySettingOverrides() } } -void Cheats::UpdateActiveCodes(bool reload_enabled_list, bool verbose, bool verbose_if_changed) +void Cheats::UpdateActiveCodes(bool reload_enabled_list, bool verbose, bool verbose_if_changed, + bool show_disabled_codes) { if (reload_enabled_list) ReloadEnabledLists(); @@ -980,9 +983,10 @@ void Cheats::UpdateActiveCodes(bool reload_enabled_list, bool verbose, bool verb s_active_patch_count = 0; s_active_cheat_count = 0; + const bool hc_mode_active = Achievements::IsHardcoreModeActive(); + if (!g_settings.disable_all_enhancements) { - const bool hc_mode_active = Achievements::IsHardcoreModeActive(); s_active_patch_count = EnableCheats(s_patch_codes, s_enabled_patches, "Patches", hc_mode_active); s_active_cheat_count = AreCheatsEnabled() ? EnableCheats(s_cheat_codes, s_enabled_cheats, "Cheats", hc_mode_active) : 0; @@ -1017,6 +1021,33 @@ void Cheats::UpdateActiveCodes(bool reload_enabled_list, bool verbose, bool verb Host::OSD_INFO_DURATION); } } + + if (show_disabled_codes && (hc_mode_active || g_settings.disable_all_enhancements)) + { + const SettingsInterface* sif = Host::Internal::GetGameSettingsLayer(); + const u32 requested_cheat_count = (sif && sif->GetBoolValue("Cheats", "EnableCheats", false)) ? + static_cast(sif->GetStringList("Cheats", "Enable").size()) : + 0; + const u32 requested_patches_count = sif ? static_cast(sif->GetStringList("Patches", "Enable").size()) : 0; + const u32 blocked_cheats = + (s_active_cheat_count < requested_cheat_count) ? requested_cheat_count - s_active_cheat_count : 0; + const u32 blocked_patches = + (s_active_patch_count < requested_patches_count) ? requested_patches_count - s_active_patch_count : 0; + if (blocked_cheats > 0 || blocked_patches > 0) + { + const SmallString blocked_cheats_msg = + TRANSLATE_PLURAL_SSTR("Cheats", "%n cheats", "Cheats blocked by hardcore mode", blocked_cheats); + const SmallString blocked_patches_msg = + TRANSLATE_PLURAL_SSTR("Cheats", "%n patches", "Patches blocked by hardcore mode", blocked_patches); + std::string message = + (blocked_cheats > 0 && blocked_patches > 0) ? + fmt::format(TRANSLATE_FS("Cheats", "{0} and {1} disabled by achievements hardcore mode/safe mode."), + blocked_cheats_msg.view(), blocked_patches_msg.view()) : + fmt::format(TRANSLATE_FS("Cheats", "{} disabled by achievements hardcore mode/safe mode."), + (blocked_cheats > 0) ? blocked_cheats_msg.view() : blocked_patches_msg.view()); + Host::AddIconOSDMessage("CheatsBlocked", ICON_EMOJI_WARNING, std::move(message), Host::OSD_INFO_DURATION); + } + } } void Cheats::ApplyFrameEndCodes() diff --git a/src/core/cheats.h b/src/core/cheats.h index 858827263..0805d6756 100644 --- a/src/core/cheats.h +++ b/src/core/cheats.h @@ -124,7 +124,8 @@ extern void RemoveAllCodes(const std::string_view serial, const std::string_view extern std::string GetChtFilename(const std::string_view serial, std::optional hash, bool cheats); /// Reloads cheats and game patches. The parameters control the degree to which data is reloaded. -extern void ReloadCheats(bool reload_files, bool reload_enabled_list, bool verbose, bool verbose_if_changed); +extern void ReloadCheats(bool reload_files, bool reload_enabled_list, bool verbose, bool verbose_if_changed, + bool show_disabled_codes); /// Releases all cheat-related state. extern void UnloadAll(); diff --git a/src/core/system.cpp b/src/core/system.cpp index 9f4c91287..95b40468a 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1365,7 +1365,7 @@ void System::ReloadGameSettings(bool display_osd_messages) return; if (!IsReplayingGPUDump()) - Cheats::ReloadCheats(false, true, false, true); + Cheats::ReloadCheats(false, true, false, true, true); ApplySettings(display_osd_messages); } @@ -1554,7 +1554,7 @@ void System::ResetSystem() if (Achievements::ResetHardcoreMode(false)) { // Make sure a pre-existing cheat file hasn't been loaded when resetting after enabling HC mode. - Cheats::ReloadCheats(true, true, false, true); + Cheats::ReloadCheats(true, true, false, true, true); ApplySettings(false); } @@ -1929,7 +1929,7 @@ bool System::Initialize(std::unique_ptr disc, DiscRegion disc_region, b if (!IsReplayingGPUDump()) { - Cheats::ReloadCheats(true, true, false, true); + Cheats::ReloadCheats(true, true, false, true, true); if (Cheats::HasAnySettingOverrides()) ApplySettings(true); } @@ -4187,7 +4187,7 @@ void System::UpdateRunningGame(const std::string& path, CDImage* image, bool boo // Cheats are loaded later in Initialize(). if (!booting) - Cheats::ReloadCheats(true, true, false, true); + Cheats::ReloadCheats(true, true, false, true, true); } ApplySettings(true); @@ -4348,7 +4348,7 @@ void System::CheckForSettingsChanges(const Settings& old_settings) ClearMemorySaveStates(false, false); if (g_settings.disable_all_enhancements != old_settings.disable_all_enhancements) - Cheats::ReloadCheats(false, true, false, true); + Cheats::ReloadCheats(false, true, false, true, true); if (g_settings.cpu_overclock_active != old_settings.cpu_overclock_active || (g_settings.cpu_overclock_active && @@ -4813,13 +4813,6 @@ void System::WarnAboutUnsafeSettings() APPEND_SUBMESSAGE(TRANSLATE_SV("System", "Overclock disabled.")); if (g_settings.enable_8mb_ram) APPEND_SUBMESSAGE(TRANSLATE_SV("System", "8MB RAM disabled.")); - if (s_state.game_settings_interface && - s_state.game_settings_interface->GetBoolValue("Cheats", "EnableCheats", false)) - { - APPEND_SUBMESSAGE(TRANSLATE_SV("System", "Cheats disabled.")); - } - if (s_state.game_settings_interface && s_state.game_settings_interface->ContainsValue("Patches", "Enable")) - APPEND_SUBMESSAGE(TRANSLATE_SV("System", "Patches disabled.")); if (g_settings.gpu_resolution_scale != 1) APPEND_SUBMESSAGE(TRANSLATE_SV("System", "Resolution scale set to 1x.")); if (g_settings.gpu_multisamples != 1) diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 26afdeec1..f52ab89a5 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -1251,7 +1251,7 @@ void EmuThread::reloadCheats(bool reload_files, bool reload_enabled_list, bool v // If the reloaded list is being enabled, we also need to reload the gameini file. if (reload_enabled_list) System::ReloadGameSettings(verbose); - Cheats::ReloadCheats(reload_files, reload_enabled_list, verbose, verbose_if_changed); + Cheats::ReloadCheats(reload_files, reload_enabled_list, verbose, verbose_if_changed, verbose); } } diff --git a/src/duckstation-qt/translations/duckstation-qt_en.ts b/src/duckstation-qt/translations/duckstation-qt_en.ts index dd9d49972..c49a0a4a6 100644 --- a/src/duckstation-qt/translations/duckstation-qt_en.ts +++ b/src/duckstation-qt/translations/duckstation-qt_en.ts @@ -16,7 +16,7 @@ Achievements - + You have unlocked {} of %n achievements Achievement popup @@ -25,7 +25,7 @@ - + and earned {} of %n points Achievement popup @@ -34,7 +34,7 @@ - + %n achievements Mastery popup @@ -43,8 +43,8 @@ - - + + %n points Achievement points @@ -53,7 +53,7 @@ - + You have unlocked all achievements and earned %n points! Point count @@ -62,7 +62,7 @@ - + This game has %n leaderboards. Leaderboard count @@ -74,7 +74,7 @@ Cheats - + %n game patches are active. OSD Message @@ -83,7 +83,7 @@ - + %n cheats are enabled. This may crash games. OSD Message @@ -91,6 +91,24 @@ %n cheats are enabled. This may crash games. + + + %n cheats + Cheats blocked by hardcore mode + + %n cheat + %n cheats + + + + + %n patches + Patches blocked by hardcore mode + + %n patch + %n patches + + EmulationSettingsWidget @@ -106,7 +124,7 @@ GPU_HW - + %n replacement textures found. Replacement texture count @@ -118,8 +136,8 @@ GameList - - + + %n hours %n hour @@ -127,8 +145,8 @@ - - + + %n minutes %n minute