diff --git a/cheevos/cheevos.c b/cheevos/cheevos.c index 2d2daab6d8..3c751f0087 100644 --- a/cheevos/cheevos.c +++ b/cheevos/cheevos.c @@ -288,6 +288,7 @@ static cheevos_locals_t cheevos_locals = bool cheevos_loaded = false; bool cheevos_hardcore_active = false; bool cheevos_hardcore_paused = false; +bool cheevos_state_loaded_flag = false; int cheats_are_enabled = 0; int cheats_were_enabled = 0; @@ -2265,11 +2266,15 @@ bool cheevos_toggle_hardcore_mode(void) return false; /* reset and deinit rewind to avoid cheat the score */ - if (settings->bools.cheevos_hardcore_mode_enable && !cheevos_hardcore_paused) + if (settings->bools.cheevos_hardcore_mode_enable + && !cheevos_hardcore_paused) { const char *msg = msg_hash_to_str( MSG_CHEEVOS_HARDCORE_MODE_ENABLE); + /* reset the state loaded flag in case it was set */ + cheevos_state_loaded_flag = false; + /* send reset core cmd to avoid any user * savestate previusly loaded. */ command_event(CMD_EVENT_RESET, NULL); diff --git a/cheevos/cheevos.h b/cheevos/cheevos.h index 45c799dfe3..c04d63eae0 100644 --- a/cheevos/cheevos.h +++ b/cheevos/cheevos.h @@ -155,8 +155,10 @@ cheevos_console_t cheevos_get_console(void); extern bool cheevos_loaded; extern bool cheevos_hardcore_active; extern bool cheevos_hardcore_paused; +extern bool cheevos_state_loaded_flag; extern int cheats_are_enabled; extern int cheats_were_enabled; +; RETRO_END_DECLS diff --git a/command.c b/command.c index 7e4bf1ff36..956fece2e4 100644 --- a/command.c +++ b/command.c @@ -1675,6 +1675,9 @@ static bool command_event_main_state(unsigned cmd) case CMD_EVENT_LOAD_STATE: if (content_load_state(state_path, false, false)) { +#ifdef HAVE_CHEEVOS + cheevos_state_loaded_flag = true; +#endif ret = true; #ifdef HAVE_NETWORKING netplay_driver_ctl(RARCH_NETPLAY_CTL_LOAD_SAVESTATE, NULL); @@ -1905,6 +1908,8 @@ bool command_event(enum event_command cmd, void *data) command_event_init_controllers(); break; case CMD_EVENT_RESET: + cheevos_state_loaded_flag = false; + cheevos_hardcore_paused = false; RARCH_LOG("%s.\n", msg_hash_to_str(MSG_RESET)); runloop_msg_queue_push(msg_hash_to_str(MSG_RESET), 1, 120, true); diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index df819d8a24..5737f704b4 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -3711,7 +3711,7 @@ MSG_HASH( ) MSG_HASH( MSG_CHEEVOS_HARDCORE_MODE_ENABLE, - "Hardcore Mode Enabled, savestate & rewind were disabled." + "Achievements Hardcore Mode Enabled, savestate & rewind were disabled." ) MSG_HASH( MSG_COMPARING_WITH_KNOWN_MAGIC_NUMBERS, @@ -7542,3 +7542,7 @@ MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_META_STREAMING_TOGGLE, "Streaming toggle" ) +MSG_HASH( + MSG_CHEEVOS_HARDCORE_MODE_DISABLED, + "A savestate was loaded, Achievements Hardcore Mode disabled for the current session. Restart to enable hardcore mode." + ) diff --git a/menu/menu_setting.c b/menu/menu_setting.c index a888d47dab..84aa89ca7a 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -50,6 +50,11 @@ #endif +#ifdef HAVE_CHEEVOS +#include "../cheevos/cheevos.h" +#endif + + #include "../frontend/frontend_driver.h" #include "widgets/menu_input_bind_dialog.h" @@ -1871,6 +1876,23 @@ static void overlay_enable_toggle_change_handler(rarch_setting_t *setting) } #endif +#ifdef HAVE_CHEEVOS +static void achievement_hardcore_mode_write_handler(rarch_setting_t *setting) +{ + settings_t *settings = config_get_ptr(); + + if (!setting) + return; + + if (settings && settings->bools.cheevos_hardcore_mode_enable && cheevos_state_loaded_flag) + { + cheevos_hardcore_paused = true; + runloop_msg_queue_push(msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_DISABLED), 0, 180, true); + return; + } +} +#endif + #ifdef HAVE_LAKKA static void systemd_service_toggle(const char *path, char *unit, bool enable) { @@ -7671,7 +7693,7 @@ static bool setting_append_list( &group_info, &subgroup_info, parent_group, - general_write_handler, + achievement_hardcore_mode_write_handler, general_read_handler, SD_FLAG_NONE ); diff --git a/msg_hash.h b/msg_hash.h index 46e316508b..39b6abfff4 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -2107,6 +2107,7 @@ enum msg_hash_enums MSG_CHEAT_SEARCH_ADD_MATCH_SUCCESS, MSG_CHEAT_SEARCH_ADD_MATCH_FAIL, MSG_CHEAT_SEARCH_DELETE_MATCH_SUCCESS, + MSG_CHEEVOS_HARDCORE_MODE_DISABLED, MSG_LAST }; diff --git a/retroarch.c b/retroarch.c index 5d247c98ba..fed75b385c 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3156,6 +3156,12 @@ static enum runloop_state runloop_check_state( && settings->bools.cheevos_hardcore_mode_enable && cheevos_loaded && !cheevos_hardcore_paused; + if (cheevos_hardcore_active && cheevos_state_loaded_flag) + { + cheevos_hardcore_paused = true; + runloop_msg_queue_push(msg_hash_to_str(MSG_CHEEVOS_HARDCORE_MODE_DISABLED), 0, 180, true); + } + if (!cheevos_hardcore_active) #endif {