diff --git a/cheats.c b/cheats.c index dd2041a826..9760169727 100644 --- a/cheats.c +++ b/cheats.c @@ -171,13 +171,15 @@ void cheat_manager_free(cheat_manager_t *handle) free(handle); } -static void cheat_manager_update(cheat_manager_t *handle) +void cheat_manager_update(cheat_manager_t *handle) { msg_queue_clear(g_extern.msg_queue); char msg[256]; snprintf(msg, sizeof(msg), "Cheat: #%u [%s]: %s", handle->ptr, handle->cheats[handle->ptr].state ? "ON" : "OFF", - handle->cheats[handle->ptr].desc); + (handle->cheats[handle->ptr].desc) ? + (handle->cheats[handle->ptr].desc) : (handle->cheats[handle->ptr].code) + ); msg_queue_push(g_extern.msg_queue, msg, 1, 180); RARCH_LOG("%s\n", msg); } diff --git a/cheats.h b/cheats.h index bf050c7ec0..a03df9594b 100644 --- a/cheats.h +++ b/cheats.h @@ -55,6 +55,8 @@ void cheat_manager_toggle(cheat_manager_t *handle); void cheat_manager_apply_cheats(cheat_manager_t *handle); +void cheat_manager_update(cheat_manager_t *handle); + #ifdef __cplusplus } #endif diff --git a/menu/menu_entries_cbs.c b/menu/menu_entries_cbs.c index 7dc2c50e18..38d0323815 100644 --- a/menu/menu_entries_cbs.c +++ b/menu/menu_entries_cbs.c @@ -342,8 +342,6 @@ static int action_ok_cheat_file_load(const char *path, fill_pathname_join(cheat_path, menu_path, path, sizeof(cheat_path)); - RARCH_LOG("menu path is: %s\n", menu_path); - if (g_extern.cheat) cheat_manager_free(g_extern.cheat); @@ -927,6 +925,27 @@ static int shader_action_parameter_preset_toggle(unsigned type, const char *labe return 0; } +static int action_toggle_cheat(unsigned type, const char *label, + unsigned action) +{ + cheat_manager_t *cheat = g_extern.cheat; + size_t idx = type - MENU_SETTINGS_CHEAT_BEGIN; + + if (!cheat) + return -1; + + switch (action) + { + case MENU_ACTION_LEFT: + case MENU_ACTION_RIGHT: + cheat->cheats[idx].state = !cheat->cheats[idx].state; + cheat_manager_update(cheat); + break; + } + + return 0; +} + #ifdef HAVE_SHADER_MANAGER extern size_t hack_shader_pass; #endif @@ -2531,6 +2550,9 @@ static void menu_entries_cbs_init_bind_toggle(menu_file_list_cbs_t *cbs, else if (type >= MENU_SETTINGS_SHADER_PRESET_PARAMETER_0 && type <= MENU_SETTINGS_SHADER_PRESET_PARAMETER_LAST) cbs->action_toggle = shader_action_parameter_preset_toggle; + else if (type >= MENU_SETTINGS_CHEAT_BEGIN + && type <= MENU_SETTINGS_CHEAT_END) + cbs->action_toggle = action_toggle_cheat; else if ( !strcmp(label, "core_list") || !strcmp(label, "history_list") || diff --git a/settings_data.c b/settings_data.c index f50458fe50..c085d3dc5f 100644 --- a/settings_data.c +++ b/settings_data.c @@ -2405,10 +2405,11 @@ void setting_data_get_label(char *type_str, { unsigned cheat_index = type - MENU_SETTINGS_CHEAT_BEGIN; if (cheat_index < g_extern.cheat->buf_size) - snprintf(type_str, type_str_size, "%s", - ( + snprintf(type_str, type_str_size, "%s : (%s)", (g_extern.cheat->cheats[cheat_index].code != NULL) - ) ? g_extern.cheat->cheats[cheat_index].code : "N/A"); + ? g_extern.cheat->cheats[cheat_index].code : "N/A", + g_extern.cheat->cheats[cheat_index].state ? "ON" : "OFF" + ); } else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN && type <= MENU_SETTINGS_PERF_COUNTERS_END)