Cheats: Show disabled code count when HC/safe mode is active

This commit is contained in:
Stenzek 2025-02-09 17:45:19 +10:00
parent 4ce48abfc1
commit 46ae3e55ea
No known key found for this signature in database
5 changed files with 76 additions and 33 deletions

View File

@ -216,7 +216,8 @@ static bool AreAnyPatchesEnabled();
static void ReloadEnabledLists(); static void ReloadEnabledLists();
static u32 EnableCheats(const CheatCodeList& patches, const EnableCodeList& enable_list, const char* section, static u32 EnableCheats(const CheatCodeList& patches, const EnableCodeList& enable_list, const char* section,
bool hc_mode_active); 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<typename F> template<typename F>
bool SearchCheatArchive(CheatArchive& archive, std::string_view serial, std::optional<GameHash> hash, const F& f); bool SearchCheatArchive(CheatArchive& archive, std::string_view serial, std::optional<GameHash> hash, const F& f);
@ -870,7 +871,8 @@ u32 Cheats::EnableCheats(const CheatCodeList& patches, const EnableCodeList& ena
return count; 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) for (const CheatCode* code : s_frame_end_codes)
code->ApplyOnDisable(); 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() 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) if (reload_enabled_list)
ReloadEnabledLists(); ReloadEnabledLists();
@ -980,9 +983,10 @@ void Cheats::UpdateActiveCodes(bool reload_enabled_list, bool verbose, bool verb
s_active_patch_count = 0; s_active_patch_count = 0;
s_active_cheat_count = 0; s_active_cheat_count = 0;
const bool hc_mode_active = Achievements::IsHardcoreModeActive();
if (!g_settings.disable_all_enhancements) 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_patch_count = EnableCheats(s_patch_codes, s_enabled_patches, "Patches", hc_mode_active);
s_active_cheat_count = s_active_cheat_count =
AreCheatsEnabled() ? EnableCheats(s_cheat_codes, s_enabled_cheats, "Cheats", hc_mode_active) : 0; 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); 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<u32>(sif->GetStringList("Cheats", "Enable").size()) :
0;
const u32 requested_patches_count = sif ? static_cast<u32>(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() void Cheats::ApplyFrameEndCodes()

View File

@ -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<GameHash> hash, bool cheats); extern std::string GetChtFilename(const std::string_view serial, std::optional<GameHash> hash, bool cheats);
/// Reloads cheats and game patches. The parameters control the degree to which data is reloaded. /// 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. /// Releases all cheat-related state.
extern void UnloadAll(); extern void UnloadAll();

View File

@ -1365,7 +1365,7 @@ void System::ReloadGameSettings(bool display_osd_messages)
return; return;
if (!IsReplayingGPUDump()) if (!IsReplayingGPUDump())
Cheats::ReloadCheats(false, true, false, true); Cheats::ReloadCheats(false, true, false, true, true);
ApplySettings(display_osd_messages); ApplySettings(display_osd_messages);
} }
@ -1554,7 +1554,7 @@ void System::ResetSystem()
if (Achievements::ResetHardcoreMode(false)) if (Achievements::ResetHardcoreMode(false))
{ {
// Make sure a pre-existing cheat file hasn't been loaded when resetting after enabling HC mode. // 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); ApplySettings(false);
} }
@ -1929,7 +1929,7 @@ bool System::Initialize(std::unique_ptr<CDImage> disc, DiscRegion disc_region, b
if (!IsReplayingGPUDump()) if (!IsReplayingGPUDump())
{ {
Cheats::ReloadCheats(true, true, false, true); Cheats::ReloadCheats(true, true, false, true, true);
if (Cheats::HasAnySettingOverrides()) if (Cheats::HasAnySettingOverrides())
ApplySettings(true); ApplySettings(true);
} }
@ -4187,7 +4187,7 @@ void System::UpdateRunningGame(const std::string& path, CDImage* image, bool boo
// Cheats are loaded later in Initialize(). // Cheats are loaded later in Initialize().
if (!booting) if (!booting)
Cheats::ReloadCheats(true, true, false, true); Cheats::ReloadCheats(true, true, false, true, true);
} }
ApplySettings(true); ApplySettings(true);
@ -4348,7 +4348,7 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
ClearMemorySaveStates(false, false); ClearMemorySaveStates(false, false);
if (g_settings.disable_all_enhancements != old_settings.disable_all_enhancements) 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 || if (g_settings.cpu_overclock_active != old_settings.cpu_overclock_active ||
(g_settings.cpu_overclock_active && (g_settings.cpu_overclock_active &&
@ -4813,13 +4813,6 @@ void System::WarnAboutUnsafeSettings()
APPEND_SUBMESSAGE(TRANSLATE_SV("System", "Overclock disabled.")); APPEND_SUBMESSAGE(TRANSLATE_SV("System", "Overclock disabled."));
if (g_settings.enable_8mb_ram) if (g_settings.enable_8mb_ram)
APPEND_SUBMESSAGE(TRANSLATE_SV("System", "8MB RAM disabled.")); 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) if (g_settings.gpu_resolution_scale != 1)
APPEND_SUBMESSAGE(TRANSLATE_SV("System", "Resolution scale set to 1x.")); APPEND_SUBMESSAGE(TRANSLATE_SV("System", "Resolution scale set to 1x."));
if (g_settings.gpu_multisamples != 1) if (g_settings.gpu_multisamples != 1)

View File

@ -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 the reloaded list is being enabled, we also need to reload the gameini file.
if (reload_enabled_list) if (reload_enabled_list)
System::ReloadGameSettings(verbose); 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);
} }
} }

View File

@ -16,7 +16,7 @@
<context> <context>
<name>Achievements</name> <name>Achievements</name>
<message numerus="yes"> <message numerus="yes">
<location filename="../../core/achievements.cpp" line="1256"/> <location filename="../../core/achievements.cpp" line="1348"/>
<source>You have unlocked {} of %n achievements</source> <source>You have unlocked {} of %n achievements</source>
<comment>Achievement popup</comment> <comment>Achievement popup</comment>
<translation> <translation>
@ -25,7 +25,7 @@
</translation> </translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../../core/achievements.cpp" line="1259"/> <location filename="../../core/achievements.cpp" line="1351"/>
<source>and earned {} of %n points</source> <source>and earned {} of %n points</source>
<comment>Achievement popup</comment> <comment>Achievement popup</comment>
<translation> <translation>
@ -34,7 +34,7 @@
</translation> </translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../../core/achievements.cpp" line="1351"/> <location filename="../../core/achievements.cpp" line="1443"/>
<source>%n achievements</source> <source>%n achievements</source>
<comment>Mastery popup</comment> <comment>Mastery popup</comment>
<translation> <translation>
@ -43,8 +43,8 @@
</translation> </translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../../core/achievements.cpp" line="1353"/> <location filename="../../core/achievements.cpp" line="1445"/>
<location filename="../../core/achievements.cpp" line="2738"/> <location filename="../../core/achievements.cpp" line="2843"/>
<source>%n points</source> <source>%n points</source>
<comment>Achievement points</comment> <comment>Achievement points</comment>
<translation> <translation>
@ -53,7 +53,7 @@
</translation> </translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../../core/achievements.cpp" line="2557"/> <location filename="../../core/achievements.cpp" line="2661"/>
<source>You have unlocked all achievements and earned %n points!</source> <source>You have unlocked all achievements and earned %n points!</source>
<comment>Point count</comment> <comment>Point count</comment>
<translation> <translation>
@ -62,7 +62,7 @@
</translation> </translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../../core/achievements.cpp" line="2981"/> <location filename="../../core/achievements.cpp" line="3086"/>
<source>This game has %n leaderboards.</source> <source>This game has %n leaderboards.</source>
<comment>Leaderboard count</comment> <comment>Leaderboard count</comment>
<translation> <translation>
@ -74,7 +74,7 @@
<context> <context>
<name>Cheats</name> <name>Cheats</name>
<message numerus="yes"> <message numerus="yes">
<location filename="../../core/cheats.cpp" line="948"/> <location filename="../../core/cheats.cpp" line="1005"/>
<source>%n game patches are active.</source> <source>%n game patches are active.</source>
<comment>OSD Message</comment> <comment>OSD Message</comment>
<translation> <translation>
@ -83,7 +83,7 @@
</translation> </translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../../core/cheats.cpp" line="955"/> <location filename="../../core/cheats.cpp" line="1012"/>
<source>%n cheats are enabled. This may crash games.</source> <source>%n cheats are enabled. This may crash games.</source>
<comment>OSD Message</comment> <comment>OSD Message</comment>
<translation> <translation>
@ -91,6 +91,24 @@
<numerusform>%n cheats are enabled. This may crash games.</numerusform> <numerusform>%n cheats are enabled. This may crash games.</numerusform>
</translation> </translation>
</message> </message>
<message numerus="yes">
<location filename="../../core/cheats.cpp" line="1039"/>
<source>%n cheats</source>
<comment>Cheats blocked by hardcore mode</comment>
<translation>
<numerusform>%n cheat</numerusform>
<numerusform>%n cheats</numerusform>
</translation>
</message>
<message numerus="yes">
<location filename="../../core/cheats.cpp" line="1041"/>
<source>%n patches</source>
<comment>Patches blocked by hardcore mode</comment>
<translation>
<numerusform>%n patch</numerusform>
<numerusform>%n patches</numerusform>
</translation>
</message>
</context> </context>
<context> <context>
<name>EmulationSettingsWidget</name> <name>EmulationSettingsWidget</name>
@ -106,7 +124,7 @@
<context> <context>
<name>GPU_HW</name> <name>GPU_HW</name>
<message numerus="yes"> <message numerus="yes">
<location filename="../../core/gpu_hw_texture_cache.cpp" line="3524"/> <location filename="../../core/gpu_hw_texture_cache.cpp" line="3615"/>
<source>%n replacement textures found.</source> <source>%n replacement textures found.</source>
<comment>Replacement texture count</comment> <comment>Replacement texture count</comment>
<translation> <translation>
@ -118,8 +136,8 @@
<context> <context>
<name>GameList</name> <name>GameList</name>
<message numerus="yes"> <message numerus="yes">
<location filename="../gamelistmodel.cpp" line="258"/> <location filename="../gamelistmodel.cpp" line="343"/>
<location filename="../../core/game_list.cpp" line="1365"/> <location filename="../../core/game_list.cpp" line="1521"/>
<source>%n hours</source> <source>%n hours</source>
<translation> <translation>
<numerusform>%n hour</numerusform> <numerusform>%n hour</numerusform>
@ -127,8 +145,8 @@
</translation> </translation>
</message> </message>
<message numerus="yes"> <message numerus="yes">
<location filename="../gamelistmodel.cpp" line="260"/> <location filename="../gamelistmodel.cpp" line="345"/>
<location filename="../../core/game_list.cpp" line="1367"/> <location filename="../../core/game_list.cpp" line="1523"/>
<source>%n minutes</source> <source>%n minutes</source>
<translation> <translation>
<numerusform>%n minute</numerusform> <numerusform>%n minute</numerusform>