From b62fa8d9edd44fb23e52a5b7fff46f742008a6d1 Mon Sep 17 00:00:00 2001 From: Sven <40953353+RetroSven@users.noreply.github.com> Date: Sun, 23 Sep 2018 15:25:51 -0400 Subject: [PATCH] add ability to edit emu-style cheat code value ; change default handler to emu --- managers/cheat_manager.c | 5 +++++ managers/cheat_manager.h | 3 ++- menu/cbs/menu_cbs_left.c | 2 +- menu/cbs/menu_cbs_ok.c | 8 ++++---- menu/cbs/menu_cbs_right.c | 2 +- menu/menu_setting.c | 14 ++++++++++++++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/managers/cheat_manager.c b/managers/cheat_manager.c index b8c2c28a72..5bf273b116 100644 --- a/managers/cheat_manager.c +++ b/managers/cheat_manager.c @@ -250,6 +250,11 @@ bool cheat_manager_copy_working_to_idx(unsigned idx) free(cheat_manager_state.cheats[idx].desc) ; cheat_manager_state.cheats[idx].desc = strdup(cheat_manager_state.working_desc) ; + + if ( cheat_manager_state.cheats[idx].code != NULL ) + free(cheat_manager_state.cheats[idx].code) ; + + cheat_manager_state.cheats[idx].code = strdup(cheat_manager_state.working_code) ; return true ; } static void cheat_manager_new(unsigned size) diff --git a/managers/cheat_manager.h b/managers/cheat_manager.h index aadcc05a73..3665ea62fd 100644 --- a/managers/cheat_manager.h +++ b/managers/cheat_manager.h @@ -78,7 +78,8 @@ enum cheat_rumble_type RUMBLE_TYPE_DECREASE_BY_VALUE }; -#define CHEAT_CODE_SCRATCH_SIZE 100 +/* Some codes are ridiculously large - over 10000 bytes */ +#define CHEAT_CODE_SCRATCH_SIZE 16*1024 #define CHEAT_DESC_SCRATCH_SIZE 255 struct item_cheat diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c index 654742e10d..82122151e9 100644 --- a/menu/cbs/menu_cbs_left.c +++ b/menu/cbs/menu_cbs_left.c @@ -574,7 +574,7 @@ static int action_left_cheat_num_passes(unsigned type, const char *label, new_size = cheat_manager_get_size() - 1; menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); - cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_RETRO); + cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_EMU); return 0; } diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 83c6a6f097..ccbe132507 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -2749,7 +2749,7 @@ static int action_ok_cheat_add_top(const char *path, menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); - cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_RETRO); + cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_EMU); memcpy(&tmp, &cheat_manager_state.cheats[cheat_manager_state.size-1], sizeof(struct item_cheat)); tmp.idx = 0 ; @@ -2780,7 +2780,7 @@ static int action_ok_cheat_add_bottom(const char *path, menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); - cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_RETRO); + cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_EMU); msg[0] = '\0'; strlcpy(msg, @@ -2812,7 +2812,7 @@ static int action_ok_cheat_add_new_after(const char *path, bool refresh = false; unsigned int new_size = cheat_manager_get_size() + 1; - cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_RETRO); + cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_EMU); memcpy(&tmp, &cheat_manager_state.cheats[cheat_manager_state.size-1], sizeof(struct item_cheat)); tmp.idx = cheat_manager_state.working_cheat.idx+1 ; @@ -2845,7 +2845,7 @@ static int action_ok_cheat_add_new_before(const char *path, bool refresh = false ; unsigned int new_size = cheat_manager_get_size() + 1; - cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_RETRO); + cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_EMU); memcpy(&tmp, &cheat_manager_state.cheats[cheat_manager_state.size-1], sizeof(struct item_cheat)); tmp.idx = cheat_manager_state.working_cheat.idx ; diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c index 4bda401e98..e5800e17df 100644 --- a/menu/cbs/menu_cbs_right.c +++ b/menu/cbs/menu_cbs_right.c @@ -355,7 +355,7 @@ static int action_right_cheat_num_passes(unsigned type, const char *label, new_size = cheat_manager_get_size() + 1; menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); - cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_RETRO); + cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_EMU); return 0; } diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 629f240197..a2d888b739 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -4029,6 +4029,20 @@ static bool setting_append_list( general_read_handler); settings_data_list_current_add_flags(list, list_info, SD_FLAG_ALLOW_INPUT); + CONFIG_STRING( + list, list_info, + cheat_manager_state.working_code, + sizeof(cheat_manager_state.working_code), + MENU_ENUM_LABEL_CHEAT_CODE, + MENU_ENUM_LABEL_VALUE_CHEAT_CODE, + "", + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler); + settings_data_list_current_add_flags(list, list_info, SD_FLAG_ALLOW_INPUT); + config_uint_cbs(cheat_manager_state.working_cheat.handler, CHEAT_HANDLER, setting_uint_action_left_with_refresh,setting_uint_action_right_with_refresh, MENU_ENUM_LABEL_CHEAT_HANDLER_TYPE_EMU,&setting_get_string_representation_uint_as_enum,