diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 7dd671b662..0a63e7781a 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -66,7 +66,7 @@ struct config_include_list }; static config_file_t *config_file_new_internal( - const char *path, unsigned depth, config_file_cb_t *cb); + const char *path, unsigned depth); static int config_sort_compare_func(struct config_entry_list *a, struct config_entry_list *b) @@ -267,7 +267,7 @@ static void add_child_list(config_file_t *parent, config_file_t *child) parent->tail = NULL; } -static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb) +static void add_sub_conf(config_file_t *conf, char *path) { char real_path[PATH_MAX_LENGTH]; config_file_t *sub_conf = NULL; @@ -314,7 +314,7 @@ static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb) #endif sub_conf = (config_file_t*) - config_file_new_internal(real_path, conf->include_depth + 1, cb); + config_file_new_internal(real_path, conf->include_depth + 1); if (!sub_conf) return; @@ -324,7 +324,7 @@ static void add_sub_conf(config_file_t *conf, char *path, config_file_cb_t *cb) } static bool parse_line(config_file_t *conf, - struct config_entry_list *list, char *line, config_file_cb_t *cb) + struct config_entry_list *list, char *line) { char *comment = NULL; char *key_tmp = NULL; @@ -351,7 +351,7 @@ static bool parse_line(config_file_t *conf, if (conf->include_depth >= MAX_INCLUDE_DEPTH) fprintf(stderr, "!!! #include depth exceeded for config. Might be a cycle.\n"); else - add_sub_conf(conf, path, cb); + add_sub_conf(conf, path); free(path); } goto error; @@ -396,19 +396,18 @@ error: } static config_file_t *config_file_new_internal( - const char *path, unsigned depth, config_file_cb_t *cb) + const char *path, unsigned depth) { RFILE *file = NULL; struct config_file *conf = (struct config_file*)malloc(sizeof(*conf)); if (!conf) return NULL; - conf->path = NULL; - conf->entries = NULL; - conf->tail = NULL; - conf->includes = NULL; - conf->include_depth = 0; - conf->guaranteed_no_duplicates = false ; + conf->path = NULL; + conf->entries = NULL; + conf->tail = NULL; + conf->includes = NULL; + conf->include_depth = 0; if (!path || !*path) return conf; @@ -456,7 +455,7 @@ static config_file_t *config_file_new_internal( continue; } - if (*line && parse_line(conf, list, line, cb)) + if (*line && parse_line(conf, list, line)) { if (conf->entries) conf->tail->next = list; @@ -464,9 +463,6 @@ static config_file_t *config_file_new_internal( conf->entries = list; conf->tail = list; - - if (cb != NULL && list->key != NULL && list->value != NULL) - cb->config_file_new_entry_cb(list->key, list->value) ; } free(line); @@ -555,12 +551,11 @@ config_file_t *config_file_new_from_string(const char *from_string) if (!from_string) return conf; - conf->path = NULL; - conf->entries = NULL; - conf->tail = NULL; - conf->includes = NULL; - conf->include_depth = 0; - conf->guaranteed_no_duplicates = false ; + conf->path = NULL; + conf->entries = NULL; + conf->tail = NULL; + conf->includes = NULL; + conf->include_depth = 0; lines = string_split(from_string, "\n"); if (!lines) @@ -585,7 +580,7 @@ config_file_t *config_file_new_from_string(const char *from_string) if (line && conf) { - if (*line && parse_line(conf, list, line, NULL)) + if (*line && parse_line(conf, list, line)) { if (conf->entries) conf->tail->next = list; @@ -605,13 +600,9 @@ config_file_t *config_file_new_from_string(const char *from_string) return conf; } -config_file_t *config_file_new_with_callback(const char *path, config_file_cb_t *cb) -{ - return config_file_new_internal(path, 0, cb); -} config_file_t *config_file_new(const char *path) { - return config_file_new_internal(path, 0, NULL); + return config_file_new_internal(path, 0); } static struct config_entry_list *config_get_entry(const config_file_t *conf, @@ -843,7 +834,7 @@ bool config_get_bool(config_file_t *conf, const char *key, bool *in) void config_set_string(config_file_t *conf, const char *key, const char *val) { struct config_entry_list *last = conf->entries; - struct config_entry_list *entry = conf->guaranteed_no_duplicates?NULL:config_get_entry(conf, key, &last); + struct config_entry_list *entry = config_get_entry(conf, key, &last); if (entry && !entry->readonly) { diff --git a/libretro-common/include/file/config_file.h b/libretro-common/include/file/config_file.h index e55430472d..cbeac2ed98 100644 --- a/libretro-common/include/file/config_file.h +++ b/libretro-common/include/file/config_file.h @@ -58,7 +58,6 @@ struct config_file struct config_entry_list *entries; struct config_entry_list *tail; unsigned include_depth; - bool guaranteed_no_duplicates; struct config_include_list *includes; }; @@ -66,13 +65,6 @@ struct config_file typedef struct config_file config_file_t; -struct config_file_cb -{ - void (*config_file_new_entry_cb)(char*, char*); -}; - -typedef struct config_file_cb config_file_cb_t ; - /* Config file format * - # are treated as comments. Rest of the line is ignored. * - Format is: key = value. There can be as many spaces as you like in-between. @@ -87,11 +79,6 @@ typedef struct config_file_cb config_file_cb_t ; * NULL path will create an empty config file. */ config_file_t *config_file_new(const char *path); -/* Loads a config file. Returns NULL if file doesn't exist. - * NULL path will create an empty config file. - * Includes cb callbacks to run custom code during config file processing.*/ -config_file_t *config_file_new_with_callback(const char *path, config_file_cb_t *cb); - /* Load a config file from a string. */ config_file_t *config_file_new_from_string(const char *from_string); @@ -191,4 +178,3 @@ bool config_file_exists(const char *path); RETRO_END_DECLS #endif - diff --git a/managers/cheat_manager.c b/managers/cheat_manager.c index d581e4790d..85296e55e4 100644 --- a/managers/cheat_manager.c +++ b/managers/cheat_manager.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include @@ -89,12 +88,8 @@ void cheat_manager_apply_cheats(void) core_set_cheat(&cheat_info); } } - - if (cheat_manager_state.size > 0) - { - runloop_msg_queue_push(msg_hash_to_str(MSG_APPLYING_CHEAT), 1, 180, true); - RARCH_LOG("%s\n", msg_hash_to_str(MSG_APPLYING_CHEAT)); - } + runloop_msg_queue_push(msg_hash_to_str(MSG_APPLYING_CHEAT), 1, 180, true); + RARCH_LOG("%s\n", msg_hash_to_str(MSG_APPLYING_CHEAT)); #ifdef HAVE_CHEEVOS data_bool = idx != 0; @@ -108,7 +103,7 @@ void cheat_manager_set_code(unsigned i, const char *str) return; if (!string_is_empty(str)) - strcpy(cheat_manager_state.cheats[i].code,str); + strcpy(cheat_manager_state.cheats[i].code,str) ; cheat_manager_state.cheats[i].state = true; } @@ -151,7 +146,7 @@ bool cheat_manager_save(const char *path, const char *cheat_database, bool overw buf[0] = cheats_file[0] = '\0'; if ( (!cheat_manager_state.cheats) || cheat_manager_state.size==0 ) - return false; + return false ; if (!cheat_database) strlcpy(cheats_file, path, sizeof(cheats_file)); @@ -172,8 +167,6 @@ bool cheat_manager_save(const char *path, const char *cheat_database, bool overw if (!conf) return false; - conf->guaranteed_no_duplicates = true; - config_set_int(conf, "cheats", cheat_manager_state.size); for (i = 0; i < cheat_manager_state.size; i++) @@ -240,42 +233,44 @@ bool cheat_manager_copy_idx_to_working(unsigned idx) return false; } - memcpy(&(cheat_manager_state.working_cheat), &(cheat_manager_state.cheats[idx]), sizeof(struct item_cheat)); + memcpy(&(cheat_manager_state.working_cheat), &(cheat_manager_state.cheats[idx]), sizeof(struct item_cheat)) ; if ( cheat_manager_state.cheats[idx].desc != NULL ) - strlcpy(cheat_manager_state.working_desc, cheat_manager_state.cheats[idx].desc, CHEAT_DESC_SCRATCH_SIZE); + strlcpy(cheat_manager_state.working_desc, cheat_manager_state.cheats[idx].desc, CHEAT_DESC_SCRATCH_SIZE) ; else - cheat_manager_state.working_desc[0] = '\0'; + cheat_manager_state.working_desc[0] = '\0' ; if ( cheat_manager_state.cheats[idx].code != NULL ) - strlcpy(cheat_manager_state.working_code, cheat_manager_state.cheats[idx].code, CHEAT_CODE_SCRATCH_SIZE); + strlcpy(cheat_manager_state.working_code, cheat_manager_state.cheats[idx].code, CHEAT_CODE_SCRATCH_SIZE) ; else - cheat_manager_state.working_code[0] = '\0'; + cheat_manager_state.working_code[0] = '\0' ; - return true; + return true ; } bool cheat_manager_copy_working_to_idx(unsigned idx) { if ( (!cheat_manager_state.cheats) || (cheat_manager_state.size < idx+1)) + { return false; + } - memcpy(&(cheat_manager_state.cheats[idx]), &(cheat_manager_state.working_cheat), sizeof(struct item_cheat)); + memcpy(&(cheat_manager_state.cheats[idx]), &(cheat_manager_state.working_cheat), sizeof(struct item_cheat)) ; if ( cheat_manager_state.cheats[idx].desc != NULL ) - free(cheat_manager_state.cheats[idx].desc); + free(cheat_manager_state.cheats[idx].desc) ; - cheat_manager_state.cheats[idx].desc = strdup(cheat_manager_state.working_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); + free(cheat_manager_state.cheats[idx].code) ; - cheat_manager_state.cheats[idx].code = strdup(cheat_manager_state.working_code); - return true; + cheat_manager_state.cheats[idx].code = strdup(cheat_manager_state.working_code) ; + return true ; } static void cheat_manager_new(unsigned size) { unsigned i; - cheat_manager_free(); + cheat_manager_free() ; cheat_manager_state.buf_size = size; cheat_manager_state.size = size; @@ -288,175 +283,147 @@ static void cheat_manager_new(unsigned size) cheat_manager_state.buf_size = 0; cheat_manager_state.size = 0; cheat_manager_state.cheats = NULL; - return; + return ; } for (i = 0; i < cheat_manager_state.size; i++) { - cheat_manager_state.cheats[i].desc = NULL; - cheat_manager_state.cheats[i].code = NULL; + cheat_manager_state.cheats[i].desc = NULL ; + cheat_manager_state.cheats[i].code = NULL ; cheat_manager_state.cheats[i].state = false; cheat_manager_state.cheats[i].repeat_count = 1; cheat_manager_state.cheats[i].repeat_add_to_value = 0; cheat_manager_state.cheats[i].repeat_add_to_address = 1; } - return; -} - -void cheat_manager_load_cb_first_pass(char *key, char *value) -{ - errno = 0; - - if (string_is_equal(key, "cheats")) - { - cheat_manager_state.loading_cheat_size = (unsigned)strtoul(value, NULL, 0); - - if (errno != 0) - cheat_manager_state.loading_cheat_size = 0; - } -} - -void cheat_manager_load_cb_second_pass(char *key, char *value) -{ - char cheat_num_str[20]; - unsigned cheat_num; - unsigned cheat_idx; - int idx = 0; - int key_length; - errno = 0; - - if (strncmp(key, "cheat", 5) != 0) - return; - - idx = 5; - key_length = strlen(key); - - while (idx < key_length && key[idx] >= '0' && key[idx] <= '9' && idx < 24) - { - cheat_num_str[idx-5] = key[idx]; - idx++; - } - - cheat_num_str[idx-5] = '\0'; - - cheat_num = (unsigned)strtoul(cheat_num_str, NULL, 0); - - if (cheat_num+cheat_manager_state.loading_cheat_offset >= cheat_manager_state.size) - return; - - key = key+idx+1; - - cheat_idx = cheat_num+cheat_manager_state.loading_cheat_offset; - - if (string_is_equal(key, "address")) - cheat_manager_state.cheats[cheat_idx].address = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "address_bit_position")) - cheat_manager_state.cheats[cheat_idx].address_mask = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "big_endian")) - cheat_manager_state.cheats[cheat_idx].big_endian = (string_is_equal(value,"true") || string_is_equal(value,"1")); - else if (string_is_equal(key, "cheat_type")) - cheat_manager_state.cheats[cheat_idx].cheat_type = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "code")) - cheat_manager_state.cheats[cheat_idx].code = strdup(value); - else if (string_is_equal(key, "desc")) - cheat_manager_state.cheats[cheat_idx].desc = strdup(value); - else if (string_is_equal(key, "enable")) - cheat_manager_state.cheats[cheat_idx].state = (string_is_equal(value,"true") || string_is_equal(value,"1")); - else if (string_is_equal(key, "handler")) - cheat_manager_state.cheats[cheat_idx].handler = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "memory_search_size")) - cheat_manager_state.cheats[cheat_idx].memory_search_size = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "repeat_add_to_address")) - cheat_manager_state.cheats[cheat_idx].repeat_add_to_address = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "repeat_add_to_value")) - cheat_manager_state.cheats[cheat_idx].repeat_add_to_value = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "repeat_count")) - cheat_manager_state.cheats[cheat_idx].repeat_count = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "rumble_port")) - cheat_manager_state.cheats[cheat_idx].rumble_port = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "rumble_primary_duration")) - cheat_manager_state.cheats[cheat_idx].rumble_primary_duration = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "rumble_primary_strength")) - cheat_manager_state.cheats[cheat_idx].rumble_primary_strength = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "rumble_secondary_duration")) - cheat_manager_state.cheats[cheat_idx].rumble_secondary_duration = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "rumble_secondary_strength")) - cheat_manager_state.cheats[cheat_idx].rumble_secondary_strength = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "rumble_type")) - cheat_manager_state.cheats[cheat_idx].rumble_type = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "rumble_value")) - cheat_manager_state.cheats[cheat_idx].rumble_value = (unsigned)strtoul(value, NULL, 0); - else if (string_is_equal(key, "value")) - cheat_manager_state.cheats[cheat_idx].value = (unsigned)strtoul(value, NULL, 0); - + return ; } bool cheat_manager_load(const char *path, bool append) { - unsigned orig_size; unsigned cheats = 0, i; - config_file_cb_t cb; - config_file_t *conf = NULL; - - cb.config_file_new_entry_cb = cheat_manager_load_cb_first_pass; - - cheat_manager_state.loading_cheat_size = 0; - - conf = config_file_new_with_callback(path, &cb); + config_file_t *conf = config_file_new(path); + unsigned orig_size ; + unsigned int* data_ptrs[16] = { NULL}; + char* keys[16] = { + "cheat%u_handler", + "cheat%u_memory_search_size", + "cheat%u_cheat_type", + "cheat%u_value", + "cheat%u_address", + "cheat%u_address_bit_position", + "cheat%u_rumble_type", + "cheat%u_rumble_value", + "cheat%u_rumble_port", + "cheat%u_rumble_primary_strength", + "cheat%u_rumble_primary_duration", + "cheat%u_rumble_secondary_strength", + "cheat%u_rumble_secondary_duration", + "cheat%u_repeat_count", + "cheat%u_repeat_add_to_value", + "cheat%u_repeat_add_to_address", + }; if (!conf) return false; - cheats = cheat_manager_state.loading_cheat_size; + config_get_uint(conf, "cheats", &cheats); if (cheats == 0) goto error; - config_file_free(conf); - conf = NULL; - - - cheat_manager_alloc_if_empty(); + cheat_manager_alloc_if_empty() ; if ( append ) { - orig_size = cheat_manager_get_size(); + orig_size = cheat_manager_get_size() ; if ( orig_size == 0) { cheat_manager_new(cheats); } else { - cheats = cheats + orig_size; - if (cheat_manager_realloc(cheats, CHEAT_HANDLER_TYPE_EMU)) { } + cheats = cheats + orig_size ; + if (cheat_manager_realloc(cheats, CHEAT_HANDLER_TYPE_EMU)) + { + } } } else { - orig_size = 0; + orig_size = 0 ; cheat_manager_new(cheats); } - for (i = orig_size; i < cheats; i++) { - cheat_manager_state.cheats[i].idx = i; - cheat_manager_state.cheats[i].desc = NULL; - cheat_manager_state.cheats[i].code = NULL; - cheat_manager_state.cheats[i].state = false; - cheat_manager_state.cheats[i].big_endian = false; - cheat_manager_state.cheats[i].cheat_type = CHEAT_TYPE_SET_TO_VALUE; + unsigned j; + char desc_key[256]; + char code_key[256]; + char enable_key[256]; + char endian_key[256]; + char *tmp = NULL; + bool tmp_bool = false; + + data_ptrs[0] = &cheat_manager_state.cheats[i].handler; + data_ptrs[1] = &cheat_manager_state.cheats[i].memory_search_size; + data_ptrs[2] = &cheat_manager_state.cheats[i].cheat_type; + data_ptrs[3] = &cheat_manager_state.cheats[i].value; + data_ptrs[4] = &cheat_manager_state.cheats[i].address; + data_ptrs[5] = &cheat_manager_state.cheats[i].address_mask; + data_ptrs[6] = &cheat_manager_state.cheats[i].rumble_type; + data_ptrs[7] = &cheat_manager_state.cheats[i].rumble_value; + data_ptrs[8] = &cheat_manager_state.cheats[i].rumble_port; + data_ptrs[9] = &cheat_manager_state.cheats[i].rumble_primary_strength; + data_ptrs[10] = &cheat_manager_state.cheats[i].rumble_primary_duration; + data_ptrs[11] = &cheat_manager_state.cheats[i].rumble_secondary_strength; + data_ptrs[12] = &cheat_manager_state.cheats[i].rumble_secondary_duration; + data_ptrs[13] = &cheat_manager_state.cheats[i].repeat_count; + data_ptrs[14] = &cheat_manager_state.cheats[i].repeat_add_to_value; + data_ptrs[15] = &cheat_manager_state.cheats[i].repeat_add_to_address; + + endian_key[0] = desc_key[0] = code_key[0] = enable_key[0] = '\0'; + + snprintf(desc_key, sizeof(desc_key), "cheat%u_desc", i-orig_size); + snprintf(code_key, sizeof(code_key), "cheat%u_code", i-orig_size); + snprintf(enable_key, sizeof(enable_key), "cheat%u_enable", i-orig_size); + snprintf(endian_key, sizeof(endian_key), "cheat%u_endian", i-orig_size); + + cheat_manager_state.cheats[i].idx = i ; + + cheat_manager_state.cheats[i].desc = NULL ; + cheat_manager_state.cheats[i].code = NULL ; + cheat_manager_state.cheats[i].state = false ; + cheat_manager_state.cheats[i].big_endian = false ; + + if (config_get_string(conf, desc_key, &tmp) && !string_is_empty(tmp)) + cheat_manager_state.cheats[i].desc = strdup(tmp) ; + + if (config_get_string(conf, code_key, &tmp) && !string_is_empty(tmp)) + cheat_manager_state.cheats[i].code = strdup(tmp) ; + + if (config_get_bool(conf, enable_key, &tmp_bool)) + cheat_manager_state.cheats[i].state = tmp_bool; + + if (config_get_bool(conf, endian_key, &tmp_bool)) + cheat_manager_state.cheats[i].big_endian = tmp_bool; + + if (tmp) + free(tmp); + + cheat_manager_state.cheats[i].cheat_type = CHEAT_TYPE_SET_TO_VALUE ; cheat_manager_state.cheats[i].memory_search_size = 3; + for (j = 0 ; j < 16 ; j++ ) + { + char key[50] ; + unsigned val = 0; + snprintf(key, sizeof(key), keys[j], i-orig_size); + + if ( config_get_uint(conf, key, &val)) + *(data_ptrs[j]) = val ; + } } - cheat_manager_state.loading_cheat_offset = orig_size; - cb.config_file_new_entry_cb = cheat_manager_load_cb_second_pass; - conf = config_file_new_with_callback(path, &cb); - - if (!conf) - return false; - config_file_free(conf); return true; @@ -470,26 +437,26 @@ error: bool cheat_manager_realloc(unsigned new_size, unsigned default_handler) { unsigned i; - unsigned orig_size; + unsigned orig_size ; if (!cheat_manager_state.cheats) { cheat_manager_state.cheats = (struct item_cheat*) calloc(new_size, sizeof(struct item_cheat)); - orig_size = 0; + orig_size = 0 ; } else { - orig_size = cheat_manager_state.size; + orig_size = cheat_manager_state.size ; /* if size is decreasing, free the items that will be lost */ for (i = new_size; i < orig_size; i++) { if ( cheat_manager_state.cheats[i].code != NULL ) - free(cheat_manager_state.cheats[i].code); + free(cheat_manager_state.cheats[i].code) ; if ( cheat_manager_state.cheats[i].desc != NULL ) - free(cheat_manager_state.cheats[i].desc); + free(cheat_manager_state.cheats[i].desc) ; } cheat_manager_state.cheats = (struct item_cheat*) @@ -508,14 +475,14 @@ bool cheat_manager_realloc(unsigned new_size, unsigned default_handler) for (i = orig_size; i < cheat_manager_state.size; i++) { - memset(&(cheat_manager_state.cheats[i]), 0, sizeof(cheat_manager_state.cheats[i])); - cheat_manager_state.cheats[i].state = false; - cheat_manager_state.cheats[i].handler = default_handler; - cheat_manager_state.cheats[i].cheat_type = CHEAT_TYPE_SET_TO_VALUE; - cheat_manager_state.cheats[i].memory_search_size = 3; - cheat_manager_state.cheats[i].idx = i; - cheat_manager_state.cheats[i].repeat_count = 1; - cheat_manager_state.cheats[i].repeat_add_to_value = 0; + memset(&(cheat_manager_state.cheats[i]), 0, sizeof(cheat_manager_state.cheats[i])) ; + cheat_manager_state.cheats[i].state = false; + cheat_manager_state.cheats[i].handler = default_handler; + cheat_manager_state.cheats[i].cheat_type = CHEAT_TYPE_SET_TO_VALUE ; + cheat_manager_state.cheats[i].memory_search_size = 3; + cheat_manager_state.cheats[i].idx = i; + cheat_manager_state.cheats[i].repeat_count = 1; + cheat_manager_state.cheats[i].repeat_add_to_value = 0; cheat_manager_state.cheats[i].repeat_add_to_address = 1; } @@ -524,37 +491,37 @@ bool cheat_manager_realloc(unsigned new_size, unsigned default_handler) void cheat_manager_free(void) { - unsigned i = 0; + unsigned i = 0 ; if (cheat_manager_state.cheats) { for (i = 0; i < cheat_manager_state.size; i++) { if ( cheat_manager_state.cheats[i].desc != NULL ) - free(cheat_manager_state.cheats[i].desc); + free(cheat_manager_state.cheats[i].desc) ; if ( cheat_manager_state.cheats[i].code != NULL ) - free(cheat_manager_state.cheats[i].code); + free(cheat_manager_state.cheats[i].code) ; } free(cheat_manager_state.cheats); } if ( cheat_manager_state.prev_memory_buf ) - free(cheat_manager_state.prev_memory_buf); + free(cheat_manager_state.prev_memory_buf) ; if ( cheat_manager_state.matches ) - free(cheat_manager_state.matches); + free(cheat_manager_state.matches) ; - cheat_manager_state.cheats = NULL; - cheat_manager_state.size = 0; - cheat_manager_state.buf_size = 0; - cheat_manager_state.prev_memory_buf = NULL; - cheat_manager_state.curr_memory_buf = NULL; - cheat_manager_state.matches = NULL; - cheat_manager_state.total_memory_size = 0; - cheat_manager_state.actual_memory_size = 0; - cheat_manager_state.memory_initialized = false; - cheat_manager_state.memory_search_initialized = false; + cheat_manager_state.cheats = NULL ; + cheat_manager_state.size = 0 ; + cheat_manager_state.buf_size = 0 ; + cheat_manager_state.prev_memory_buf = NULL ; + cheat_manager_state.curr_memory_buf = NULL ; + cheat_manager_state.matches = NULL ; + cheat_manager_state.total_memory_size = 0 ; + cheat_manager_state.actual_memory_size = 0 ; + cheat_manager_state.memory_initialized = false ; + cheat_manager_state.memory_search_initialized = false ; } @@ -584,7 +551,7 @@ void cheat_manager_toggle_index(unsigned i) cheat_manager_update(&cheat_manager_state, i); if (!settings) - return; + return ; if (settings->bools.apply_cheats_after_toggle) cheat_manager_apply_cheats(); @@ -653,17 +620,18 @@ bool cheat_manager_get_game_specific_filename(char * cheat_filename, size_t max_ struct retro_system_info system_info; if (!settings || !global || !cheat_filename) - return false; + return false ; if ( !core_get_system_info(&system_info) ) - return false; + return false ; + core_name = system_info.library_name; game_name = path_basename(global->name.cheatfile); if ( string_is_empty(settings->paths.path_cheat_database) || string_is_empty(core_name) || string_is_empty(game_name) ) - return false; + return false ; cheat_filename[0] = '\0'; strlcat(cheat_filename, settings->paths.path_cheat_database, max_length); @@ -676,23 +644,23 @@ bool cheat_manager_get_game_specific_filename(char * cheat_filename, size_t max_ strlcat(cheat_filename, game_name, max_length); - return true; + return true ; } void cheat_manager_load_game_specific_cheats() { - char cheat_file[PATH_MAX_LENGTH]; + char cheat_file[PATH_MAX_LENGTH] ; if (cheat_manager_get_game_specific_filename(cheat_file, PATH_MAX_LENGTH) ) - cheat_manager_load(cheat_file,true); + cheat_manager_load(cheat_file,true) ; } void cheat_manager_save_game_specific_cheats() { - char cheat_file[PATH_MAX_LENGTH]; + char cheat_file[PATH_MAX_LENGTH] ; if (cheat_manager_get_game_specific_filename(cheat_file, PATH_MAX_LENGTH) ) - cheat_manager_save(cheat_file, NULL, true); + cheat_manager_save(cheat_file, NULL, true) ; } @@ -703,8 +671,11 @@ void cheat_manager_state_free(void) bool cheat_manager_alloc_if_empty(void) { + if (!cheat_manager_state.cheats) + { cheat_manager_new(0); + } return true; } @@ -722,9 +693,6 @@ int cheat_manager_initialize_memory(rarch_setting_t *setting, bool wraparound) return 0; } - if ( meminfo.size == 0 ) - return 0; - cheat_manager_state.actual_memory_size = (unsigned)meminfo.size; cheat_manager_state.curr_memory_buf = meminfo.data; cheat_manager_state.total_memory_size = (unsigned)meminfo.size; @@ -778,84 +746,84 @@ static void cheat_manager_setup_search_meta(unsigned int bitsize, unsigned int * { case 0 : { - *bytes_per_item = 1; - *bits = 1; - *mask = 0x01; - break; + *bytes_per_item = 1 ; + *bits = 1 ; + *mask = 0x01 ; + break ; } case 1 : { - *bytes_per_item = 1; - *bits = 2; - *mask = 0x03; - break; + *bytes_per_item = 1 ; + *bits = 2 ; + *mask = 0x03 ; + break ; } case 2 : { - *bytes_per_item = 1; - *bits = 4; - *mask = 0x0F; - break; + *bytes_per_item = 1 ; + *bits = 4 ; + *mask = 0x0F ; + break ; } case 3 : { - *bytes_per_item = 1; - *bits = 8; - *mask = 0xFF; - break; + *bytes_per_item = 1 ; + *bits = 8 ; + *mask = 0xFF ; + break ; } case 4 : { - *bytes_per_item = 2; - *bits = 8; - *mask = 0xFFFF; - break; + *bytes_per_item = 2 ; + *bits = 8 ; + *mask = 0xFFFF ; + break ; } case 5 : { - *bytes_per_item = 4; - *bits = 8; - *mask = 0xFFFFFFFF; - break; + *bytes_per_item = 4 ; + *bits = 8 ; + *mask = 0xFFFFFFFF ; + break ; } } } int cheat_manager_search_exact(rarch_setting_t *setting, bool wraparound) { - return cheat_manager_search(CHEAT_SEARCH_TYPE_EXACT); + return cheat_manager_search(CHEAT_SEARCH_TYPE_EXACT) ; } int cheat_manager_search_lt(rarch_setting_t *setting, bool wraparound) { - return cheat_manager_search(CHEAT_SEARCH_TYPE_LT); + return cheat_manager_search(CHEAT_SEARCH_TYPE_LT) ; } int cheat_manager_search_gt(rarch_setting_t *setting, bool wraparound) { - return cheat_manager_search(CHEAT_SEARCH_TYPE_GT); + return cheat_manager_search(CHEAT_SEARCH_TYPE_GT) ; } int cheat_manager_search_lte(rarch_setting_t *setting, bool wraparound) { - return cheat_manager_search(CHEAT_SEARCH_TYPE_LTE); + return cheat_manager_search(CHEAT_SEARCH_TYPE_LTE) ; } int cheat_manager_search_gte(rarch_setting_t *setting, bool wraparound) { - return cheat_manager_search(CHEAT_SEARCH_TYPE_GTE); + return cheat_manager_search(CHEAT_SEARCH_TYPE_GTE) ; } int cheat_manager_search_eq(rarch_setting_t *setting, bool wraparound) { - return cheat_manager_search(CHEAT_SEARCH_TYPE_EQ); + return cheat_manager_search(CHEAT_SEARCH_TYPE_EQ) ; } int cheat_manager_search_neq(rarch_setting_t *setting, bool wraparound) { - return cheat_manager_search(CHEAT_SEARCH_TYPE_NEQ); + return cheat_manager_search(CHEAT_SEARCH_TYPE_NEQ) ; } int cheat_manager_search_eqplus(rarch_setting_t *setting, bool wraparound) { - return cheat_manager_search(CHEAT_SEARCH_TYPE_EQPLUS); + return cheat_manager_search(CHEAT_SEARCH_TYPE_EQPLUS) ; } int cheat_manager_search_eqminus(rarch_setting_t *setting, bool wraparound) { - return cheat_manager_search(CHEAT_SEARCH_TYPE_EQMINUS); + return cheat_manager_search(CHEAT_SEARCH_TYPE_EQMINUS) ; } int cheat_manager_search(enum cheat_search_type search_type) @@ -874,14 +842,14 @@ int cheat_manager_search(enum cheat_search_type search_type) if (!cheat_manager_state.curr_memory_buf) { runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_NOT_INITIALIZED), 1, 180, true); - return 0; + return 0 ; } - cheat_manager_setup_search_meta(cheat_manager_state.search_bit_size, &bytes_per_item, &mask, &bits); + cheat_manager_setup_search_meta(cheat_manager_state.search_bit_size, &bytes_per_item, &mask, &bits) ; /* little endian FF000000 = 256 */ - for (idx = 0; idx < cheat_manager_state.total_memory_size; idx = idx + bytes_per_item) + for (idx = 0 ; idx < cheat_manager_state.total_memory_size ; idx = idx + bytes_per_item) { unsigned byte_part; @@ -891,73 +859,73 @@ int cheat_manager_search(enum cheat_search_type search_type) { curr_val = cheat_manager_state.big_endian ? (*(curr+idx)*256) + *(curr+idx+1) : - *(curr+idx) + (*(curr+idx+1)*256); + *(curr+idx) + (*(curr+idx+1)*256) ; prev_val = cheat_manager_state.big_endian ? (*(prev+idx)*256) + *(prev+idx+1) : - *(prev+idx) + (*(prev+idx+1)*256); - break; + *(prev+idx) + (*(prev+idx+1)*256) ; + break ; } case 4 : { curr_val = cheat_manager_state.big_endian ? (*(curr+idx)*256*256*256) + (*(curr+idx+1)*256*256) + (*(curr+idx+2)*256) + *(curr+idx+3) : - *(curr+idx) + (*(curr+idx+1)*256) + (*(curr+idx+2)*256*256) + (*(curr+idx+3)*256*256*256); + *(curr+idx) + (*(curr+idx+1)*256) + (*(curr+idx+2)*256*256) + (*(curr+idx+3)*256*256*256) ; prev_val = cheat_manager_state.big_endian ? (*(prev+idx)*256*256*256) + (*(prev+idx+1)*256*256) + (*(prev+idx+2)*256) + *(prev+idx+3) : - *(prev+idx) + (*(prev+idx+1)*256) + (*(prev+idx+2)*256*256) + (*(prev+idx+3)*256*256*256); - break; + *(prev+idx) + (*(prev+idx+1)*256) + (*(prev+idx+2)*256*256) + (*(prev+idx+3)*256*256*256) ; + break ; } case 1 : default : { - curr_val = *(curr+idx); - prev_val = *(prev+idx); - break; + curr_val = *(curr+idx) ; + prev_val = *(prev+idx) ; + break ; } } - for (byte_part = 0; byte_part < 8/bits; byte_part++) + for (byte_part = 0 ; byte_part < 8/bits ; byte_part++) { - unsigned int curr_subval = (curr_val >> (byte_part*bits) ) & mask; - unsigned int prev_subval = (prev_val >> (byte_part*bits) ) & mask; - unsigned int prev_match; + unsigned int curr_subval = (curr_val >> (byte_part*bits) ) & mask ; + unsigned int prev_subval = (prev_val >> (byte_part*bits) ) & mask ; + unsigned int prev_match ; if (bits < 8 ) - prev_match = *(cheat_manager_state.matches+idx) & (mask << (byte_part*bits)); + prev_match = *(cheat_manager_state.matches+idx) & (mask << (byte_part*bits)) ; else - prev_match = *(cheat_manager_state.matches+idx); + prev_match = *(cheat_manager_state.matches+idx) ; if (prev_match > 0) { - bool match = false; + bool match = false ; switch (search_type) { case CHEAT_SEARCH_TYPE_EXACT : - match = ( curr_subval == cheat_manager_state.search_exact_value); + match = ( curr_subval == cheat_manager_state.search_exact_value) ; break; case CHEAT_SEARCH_TYPE_LT : - match = ( curr_subval < prev_subval); + match = ( curr_subval < prev_subval) ; break; case CHEAT_SEARCH_TYPE_GT : - match = ( curr_subval > prev_subval); + match = ( curr_subval > prev_subval) ; break; case CHEAT_SEARCH_TYPE_LTE : - match = ( curr_subval <= prev_subval); + match = ( curr_subval <= prev_subval) ; break; case CHEAT_SEARCH_TYPE_GTE : - match = ( curr_subval >= prev_subval); + match = ( curr_subval >= prev_subval) ; break; case CHEAT_SEARCH_TYPE_EQ : - match = ( curr_subval == prev_subval); + match = ( curr_subval == prev_subval) ; break; case CHEAT_SEARCH_TYPE_NEQ : - match = ( curr_subval != prev_subval); + match = ( curr_subval != prev_subval) ; break; case CHEAT_SEARCH_TYPE_EQPLUS : - match = ( curr_subval == prev_subval+cheat_manager_state.search_eqplus_value); + match = ( curr_subval == prev_subval+cheat_manager_state.search_eqplus_value) ; break; case CHEAT_SEARCH_TYPE_EQMINUS : - match = ( curr_subval == prev_subval-cheat_manager_state.search_eqminus_value); + match = ( curr_subval == prev_subval-cheat_manager_state.search_eqminus_value) ; break; } if (!match ) @@ -966,9 +934,9 @@ int cheat_manager_search(enum cheat_search_type search_type) *(cheat_manager_state.matches+idx) = *(cheat_manager_state.matches+idx) & (( ~(mask << (byte_part*bits))) & 0xFF ); else - memset(cheat_manager_state.matches+idx,0,bytes_per_item); + memset(cheat_manager_state.matches+idx,0,bytes_per_item) ; if ( cheat_manager_state.num_matches > 0 ) - cheat_manager_state.num_matches--; + cheat_manager_state.num_matches-- ; } } } @@ -976,7 +944,7 @@ int cheat_manager_search(enum cheat_search_type search_type) memcpy(cheat_manager_state.prev_memory_buf, cheat_manager_state.curr_memory_buf, cheat_manager_state.actual_memory_size); - snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_CHEAT_SEARCH_FOUND_MATCHES), cheat_manager_state.num_matches); + snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_CHEAT_SEARCH_FOUND_MATCHES), cheat_manager_state.num_matches) ; msg[sizeof(msg) - 1] = 0; runloop_msg_queue_push(msg, 1, 180, true); @@ -985,7 +953,7 @@ int cheat_manager_search(enum cheat_search_type search_type) menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); #endif - return 0; + return 0 ; } bool cheat_manager_add_new_code(unsigned int memory_search_size, unsigned int address, unsigned int address_mask, @@ -994,15 +962,15 @@ bool cheat_manager_add_new_code(unsigned int memory_search_size, unsigned int ad int new_size = cheat_manager_get_size() + 1; if ( !cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_RETRO) ) - return false; + return false ; - cheat_manager_state.cheats[cheat_manager_state.size-1].address = address; - cheat_manager_state.cheats[cheat_manager_state.size-1].address_mask = address_mask; - cheat_manager_state.cheats[cheat_manager_state.size-1].memory_search_size = memory_search_size; - cheat_manager_state.cheats[cheat_manager_state.size-1].value = value; - cheat_manager_state.cheats[cheat_manager_state.size-1].big_endian = big_endian; + cheat_manager_state.cheats[cheat_manager_state.size-1].address = address ; + cheat_manager_state.cheats[cheat_manager_state.size-1].address_mask = address_mask ; + cheat_manager_state.cheats[cheat_manager_state.size-1].memory_search_size = memory_search_size ; + cheat_manager_state.cheats[cheat_manager_state.size-1].value = value ; + cheat_manager_state.cheats[cheat_manager_state.size-1].big_endian = big_endian ; - return true; + return true ; } int cheat_manager_add_matches(const char *path, const char *label, unsigned type, size_t menuidx, size_t entry_idx) @@ -1021,66 +989,66 @@ int cheat_manager_add_matches(const char *path, if ( cheat_manager_state.num_matches + cheat_manager_state.size > 100 ) { runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_TOO_MANY), 1, 180, true); - return 0; + return 0 ; } - cheat_manager_setup_search_meta(cheat_manager_state.search_bit_size, &bytes_per_item, &mask, &bits); + cheat_manager_setup_search_meta(cheat_manager_state.search_bit_size, &bytes_per_item, &mask, &bits) ; - for (idx = 0; idx < cheat_manager_state.total_memory_size; idx = idx + bytes_per_item) + for (idx = 0 ; idx < cheat_manager_state.total_memory_size ; idx = idx + bytes_per_item) { switch ( bytes_per_item ) { case 2 : curr_val = cheat_manager_state.big_endian ? (*(curr+idx)*256) + *(curr+idx+1) : - *(curr+idx) + (*(curr+idx+1)*256); - break; + *(curr+idx) + (*(curr+idx+1)*256) ; + break ; case 4 : curr_val = cheat_manager_state.big_endian ? (*(curr+idx)*256*256*256) + (*(curr+idx+1)*256*256) + (*(curr+idx+2)*256) + *(curr+idx+3) : - *(curr+idx) + (*(curr+idx+1)*256) + (*(curr+idx+2)*256*256) + (*(curr+idx+3)*256*256*256); - break; + *(curr+idx) + (*(curr+idx+1)*256) + (*(curr+idx+2)*256*256) + (*(curr+idx+3)*256*256*256) ; + break ; case 1 : default : - curr_val = *(curr+idx); - break; + curr_val = *(curr+idx) ; + break ; } - for (byte_part = 0; byte_part < 8/bits; byte_part++) + for (byte_part = 0 ; byte_part < 8/bits ; byte_part++) { unsigned int prev_match; if (bits < 8 ) { - prev_match = *(cheat_manager_state.matches+idx) & (mask << (byte_part*bits)); + prev_match = *(cheat_manager_state.matches+idx) & (mask << (byte_part*bits)) ; if (prev_match) { if (!cheat_manager_add_new_code(cheat_manager_state.search_bit_size, idx, (mask << (byte_part*bits)), cheat_manager_state.big_endian, curr_val) ) { runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_FAIL), 1, 180, true); - return 0; + return 0 ; } - num_added++; + num_added++ ; } } else { - prev_match = *(cheat_manager_state.matches+idx); + prev_match = *(cheat_manager_state.matches+idx) ; if (prev_match) { if (!cheat_manager_add_new_code(cheat_manager_state.search_bit_size, idx, 0xFF, cheat_manager_state.big_endian, curr_val)) { runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_FAIL), 1, 180, true); - return 0; + return 0 ; } - num_added++; + num_added++ ; } } } } - snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_SUCCESS), cheat_manager_state.num_matches); + snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_SUCCESS), cheat_manager_state.num_matches) ; msg[sizeof(msg) - 1] = 0; runloop_msg_queue_push(msg, 1, 180, true); @@ -1102,38 +1070,38 @@ void cheat_manager_apply_rumble(struct item_cheat *cheat, unsigned int curr_valu case RUMBLE_TYPE_DISABLED: return; case RUMBLE_TYPE_CHANGES: - rumble = (curr_value != cheat->rumble_prev_value); - break; + rumble = (curr_value != cheat->rumble_prev_value) ; + break ; case RUMBLE_TYPE_DOES_NOT_CHANGE: - rumble = (curr_value == cheat->rumble_prev_value); - break; + rumble = (curr_value == cheat->rumble_prev_value) ; + break ; case RUMBLE_TYPE_INCREASE: - rumble = (curr_value > cheat->rumble_prev_value); - break; + rumble = (curr_value > cheat->rumble_prev_value) ; + break ; case RUMBLE_TYPE_DECREASE: - rumble = (curr_value < cheat->rumble_prev_value); - break; + rumble = (curr_value < cheat->rumble_prev_value) ; + break ; case RUMBLE_TYPE_EQ_VALUE: - rumble = (curr_value == cheat->rumble_value); - break; + rumble = (curr_value == cheat->rumble_value) ; + break ; case RUMBLE_TYPE_NEQ_VALUE: - rumble = (curr_value != cheat->rumble_value); - break; + rumble = (curr_value != cheat->rumble_value) ; + break ; case RUMBLE_TYPE_LT_VALUE: - rumble = (curr_value < cheat->rumble_value); - break; + rumble = (curr_value < cheat->rumble_value) ; + break ; case RUMBLE_TYPE_GT_VALUE: - rumble = (curr_value > cheat->rumble_value); + rumble = (curr_value > cheat->rumble_value) ; break; case RUMBLE_TYPE_INCREASE_BY_VALUE: - rumble = (curr_value == cheat->rumble_prev_value + cheat->rumble_value); - break; + rumble = (curr_value == cheat->rumble_prev_value + cheat->rumble_value) ; + break ; case RUMBLE_TYPE_DECREASE_BY_VALUE: - rumble = (curr_value == cheat->rumble_prev_value - cheat->rumble_value); - break; + rumble = (curr_value == cheat->rumble_prev_value - cheat->rumble_value) ; + break ; } - cheat->rumble_prev_value = curr_value; + cheat->rumble_prev_value = curr_value ; /* Give the emulator enough time * to initialize, load state, etc */ @@ -1141,15 +1109,15 @@ void cheat_manager_apply_rumble(struct item_cheat *cheat, unsigned int curr_valu { if (rumble) { - cheat->rumble_primary_end_time = cpu_features_get_time_usec() + (cheat->rumble_primary_duration*1000); - cheat->rumble_secondary_end_time = cpu_features_get_time_usec() + (cheat->rumble_secondary_duration*1000); + cheat->rumble_primary_end_time = cpu_features_get_time_usec() + (cheat->rumble_primary_duration*1000) ; + cheat->rumble_secondary_end_time = cpu_features_get_time_usec() + (cheat->rumble_secondary_duration*1000) ; input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_STRONG, cheat->rumble_primary_strength); input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_WEAK, cheat->rumble_secondary_strength); } } else { - cheat->rumble_initialized++; + cheat->rumble_initialized++ ; return; } @@ -1168,7 +1136,7 @@ void cheat_manager_apply_rumble(struct item_cheat *cheat, unsigned int curr_valu { if (cheat->rumble_secondary_end_time != 0) input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_WEAK, 0); - cheat->rumble_secondary_end_time = 0; + cheat->rumble_secondary_end_time = 0 ; } else { @@ -1188,19 +1156,19 @@ void cheat_manager_apply_retro_cheats(void) if ((!cheat_manager_state.cheats)) return; - for (i = 0; i < cheat_manager_state.size; i++ ) + for (i = 0 ; i < cheat_manager_state.size ; i++ ) { unsigned char *curr; unsigned int idx; bool set_value = false; unsigned int value_to_set = 0; - unsigned int repeat_iter = 0; - unsigned int address_mask = cheat_manager_state.cheats[i].address_mask; + unsigned int repeat_iter = 0 ; + unsigned int address_mask = cheat_manager_state.cheats[i].address_mask ; if (cheat_manager_state.cheats[i].handler != CHEAT_HANDLER_TYPE_RETRO || !cheat_manager_state.cheats[i].state) - continue; + continue ; if (!cheat_manager_state.memory_initialized) - cheat_manager_initialize_memory(NULL, false); + cheat_manager_initialize_memory(NULL, false) ; /* If we're still not initialized, something * must have gone wrong - just bail */ @@ -1209,13 +1177,13 @@ void cheat_manager_apply_retro_cheats(void) if (!run_cheat) { - run_cheat = true; - continue; + run_cheat = true ; + continue ; } - cheat_manager_setup_search_meta(cheat_manager_state.cheats[i].memory_search_size, &bytes_per_item, &mask, &bits); + cheat_manager_setup_search_meta(cheat_manager_state.cheats[i].memory_search_size, &bytes_per_item, &mask, &bits) ; - curr = cheat_manager_state.curr_memory_buf; - idx = cheat_manager_state.cheats[i].address; + curr = cheat_manager_state.curr_memory_buf ; + idx = cheat_manager_state.cheats[i].address ; switch (bytes_per_item) { @@ -1223,142 +1191,142 @@ void cheat_manager_apply_retro_cheats(void) { curr_val = cheat_manager_state.big_endian ? (*(curr+idx)*256) + *(curr+idx+1) : - *(curr+idx) + (*(curr+idx+1)*256); - break; + *(curr+idx) + (*(curr+idx+1)*256) ; + break ; } case 4 : { curr_val = cheat_manager_state.big_endian ? (*(curr+idx)*256*256*256) + (*(curr+idx+1)*256*256) + (*(curr+idx+2)*256) + *(curr+idx+3) : - *(curr+idx) + (*(curr+idx+1)*256) + (*(curr+idx+2)*256*256) + (*(curr+idx+3)*256*256*256); - break; + *(curr+idx) + (*(curr+idx+1)*256) + (*(curr+idx+2)*256*256) + (*(curr+idx+3)*256*256*256) ; + break ; } case 1 : default : { - curr_val = *(curr+idx); - break; + curr_val = *(curr+idx) ; + break ; } } - cheat_manager_apply_rumble(&cheat_manager_state.cheats[i], curr_val); + cheat_manager_apply_rumble(&cheat_manager_state.cheats[i], curr_val) ; switch (cheat_manager_state.cheats[i].cheat_type ) { case CHEAT_TYPE_SET_TO_VALUE : - set_value = true; - value_to_set = cheat_manager_state.cheats[i].value; - break; + set_value = true ; + value_to_set = cheat_manager_state.cheats[i].value ; + break ; case CHEAT_TYPE_INCREASE_VALUE: - set_value = true; - value_to_set = curr_val + cheat_manager_state.cheats[i].value; + set_value = true ; + value_to_set = curr_val + cheat_manager_state.cheats[i].value ; break; case CHEAT_TYPE_DECREASE_VALUE: - set_value = true; - value_to_set = curr_val - cheat_manager_state.cheats[i].value; + set_value = true ; + value_to_set = curr_val - cheat_manager_state.cheats[i].value ; break; case CHEAT_TYPE_RUN_NEXT_IF_EQ: if (!(curr_val == cheat_manager_state.cheats[i].value)) - run_cheat = false; + run_cheat = false ; break; case CHEAT_TYPE_RUN_NEXT_IF_NEQ: if (!(curr_val != cheat_manager_state.cheats[i].value )) - run_cheat = false; + run_cheat = false ; break; case CHEAT_TYPE_RUN_NEXT_IF_LT: if (!(cheat_manager_state.cheats[i].value < curr_val)) - run_cheat = false; + run_cheat = false ; break; case CHEAT_TYPE_RUN_NEXT_IF_GT: if (!(cheat_manager_state.cheats[i].value > curr_val)) - run_cheat = false; + run_cheat = false ; break; } if (set_value) { - for ( repeat_iter = 1; repeat_iter <= cheat_manager_state.cheats[i].repeat_count; repeat_iter++) + for ( repeat_iter = 1 ; repeat_iter <= cheat_manager_state.cheats[i].repeat_count ; repeat_iter++) { switch (bytes_per_item) { case 2 : if (cheat_manager_state.cheats[i].big_endian) { - *(curr+idx) = (value_to_set >> 8) & 0xFF; - *(curr+idx+1) = value_to_set & 0xFF; + *(curr+idx) = (value_to_set >> 8) & 0xFF ; + *(curr+idx+1) = value_to_set & 0xFF ; } else { - *(curr+idx) = value_to_set & 0xFF; - *(curr+idx+1) = (value_to_set >> 8) & 0xFF; + *(curr+idx) = value_to_set & 0xFF ; + *(curr+idx+1) = (value_to_set >> 8) & 0xFF ; } - break; + break ; case 4 : if (cheat_manager_state.cheats[i].big_endian) { - *(curr+idx) = (value_to_set >> 24) & 0xFF; - *(curr+idx+1) = (value_to_set >> 16) & 0xFF; - *(curr+idx+2) = (value_to_set >> 8) & 0xFF; - *(curr+idx+3) = value_to_set & 0xFF; + *(curr+idx) = (value_to_set >> 24) & 0xFF ; + *(curr+idx+1) = (value_to_set >> 16) & 0xFF ; + *(curr+idx+2) = (value_to_set >> 8) & 0xFF ; + *(curr+idx+3) = value_to_set & 0xFF ; } else { - *(curr+idx) = value_to_set & 0xFF; - *(curr+idx+1) = (value_to_set >> 8) & 0xFF; - *(curr+idx+2) = (value_to_set >> 16) & 0xFF; - *(curr+idx+3) = (value_to_set >> 24) & 0xFF; + *(curr+idx) = value_to_set & 0xFF ; + *(curr+idx+1) = (value_to_set >> 8) & 0xFF ; + *(curr+idx+2) = (value_to_set >> 16) & 0xFF ; + *(curr+idx+3) = (value_to_set >> 24) & 0xFF ; } - break; + break ; case 1 : if (bits < 8) { unsigned bitpos; unsigned char val = *(curr+idx); - for (bitpos = 0; bitpos < 8; bitpos++) + for (bitpos = 0 ; bitpos < 8 ; bitpos++) { if ((address_mask>>bitpos)&0x01 ) { - mask = (~(1<>bitpos)&0x01)<>bitpos)&0x01)< cheat_manager_state.num_matches-1) @@ -1387,57 +1355,57 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig cheat_manager_setup_search_meta(cheat_manager_state.search_bit_size, &bytes_per_item, &mask, &bits); if (match_action == CHEAT_MATCH_ACTION_TYPE_BROWSE) - start_idx = *address; + start_idx = *address ; else - start_idx = 0; + start_idx = 0 ; - for (idx = start_idx; idx < cheat_manager_state.total_memory_size; idx = idx + bytes_per_item) + for (idx = start_idx ; idx < cheat_manager_state.total_memory_size ; idx = idx + bytes_per_item) { switch (bytes_per_item ) { case 2 : curr_val = cheat_manager_state.big_endian ? (*(curr+idx)*256) + *(curr+idx+1) : - *(curr+idx) + (*(curr+idx+1)*256); + *(curr+idx) + (*(curr+idx+1)*256) ; if (prev != NULL) prev_val = cheat_manager_state.big_endian ? (*(prev+idx)*256) + *(prev+idx+1) : - *(prev+idx) + (*(prev+idx+1)*256); - break; + *(prev+idx) + (*(prev+idx+1)*256) ; + break ; case 4 : curr_val = cheat_manager_state.big_endian ? (*(curr+idx)*256*256*256) + (*(curr+idx+1)*256*256) + (*(curr+idx+2)*256) + *(curr+idx+3) : - *(curr+idx) + (*(curr+idx+1)*256) + (*(curr+idx+2)*256*256) + (*(curr+idx+3)*256*256*256); + *(curr+idx) + (*(curr+idx+1)*256) + (*(curr+idx+2)*256*256) + (*(curr+idx+3)*256*256*256) ; if (prev != NULL) prev_val = cheat_manager_state.big_endian ? (*(prev+idx)*256*256*256) + (*(prev+idx+1)*256*256) + (*(prev+idx+2)*256) + *(prev+idx+3) : - *(prev+idx) + (*(prev+idx+1)*256) + (*(prev+idx+2)*256*256) + (*(prev+idx+3)*256*256*256); - break; + *(prev+idx) + (*(prev+idx+1)*256) + (*(prev+idx+2)*256*256) + (*(prev+idx+3)*256*256*256) ; + break ; case 1 : default : - curr_val = *(curr+idx); + curr_val = *(curr+idx) ; if (prev != NULL) - prev_val = *(prev+idx); - break; + prev_val = *(prev+idx) ; + break ; } if (match_action == CHEAT_MATCH_ACTION_TYPE_BROWSE) { *curr_value = curr_val; *prev_value = prev_val; - return; + return ; } if (!prev) return; - for (byte_part = 0; byte_part < 8/bits; byte_part++) + for (byte_part = 0 ; byte_part < 8/bits ; byte_part++) { - unsigned int prev_match; + unsigned int prev_match ; if (bits < 8 ) { - prev_match = *(cheat_manager_state.matches+idx) & (mask << (byte_part*bits)); + prev_match = *(cheat_manager_state.matches+idx) & (mask << (byte_part*bits)) ; if (prev_match) { if (target_match_idx == curr_match_idx) @@ -1445,12 +1413,12 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig switch (match_action) { case CHEAT_MATCH_ACTION_TYPE_BROWSE : - return; + return ; case CHEAT_MATCH_ACTION_TYPE_VIEW : - *address = idx; - *address_mask = (mask << (byte_part*bits)); - *curr_value = curr_val; - *prev_value = prev_val; + *address = idx ; + *address_mask = (mask << (byte_part*bits)) ; + *curr_value = curr_val ; + *prev_value = prev_val ; return; case CHEAT_MATCH_ACTION_TYPE_COPY : if (!cheat_manager_add_new_code(cheat_manager_state.search_bit_size, idx, (mask << (byte_part*bits)), @@ -1458,26 +1426,26 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_ADD_MATCH_FAIL), 1, 180, true); else runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_ADD_MATCH_SUCCESS), 1, 180, true); - return; + return ; case CHEAT_MATCH_ACTION_TYPE_DELETE : if (bits < 8) *(cheat_manager_state.matches+idx) = *(cheat_manager_state.matches+idx) & (( ~(mask << (byte_part*bits))) & 0xFF ); else - memset(cheat_manager_state.matches+idx,0,bytes_per_item); + memset(cheat_manager_state.matches+idx,0,bytes_per_item) ; if ( cheat_manager_state.num_matches > 0 ) - cheat_manager_state.num_matches--; + cheat_manager_state.num_matches-- ; runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_DELETE_MATCH_SUCCESS), 1, 180, true); return; } return; } - curr_match_idx++; + curr_match_idx++ ; } } else { - prev_match = *(cheat_manager_state.matches+idx); + prev_match = *(cheat_manager_state.matches+idx) ; if (prev_match) { if (target_match_idx == curr_match_idx) @@ -1485,33 +1453,33 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig switch (match_action) { case CHEAT_MATCH_ACTION_TYPE_BROWSE : - return; + return ; case CHEAT_MATCH_ACTION_TYPE_VIEW : - *address = idx; - *address_mask = 0xFF; - *curr_value = curr_val; - *prev_value = prev_val; - return; + *address = idx ; + *address_mask = 0xFF ; + *curr_value = curr_val ; + *prev_value = prev_val ; + return ; case CHEAT_MATCH_ACTION_TYPE_COPY : if ( !cheat_manager_add_new_code(cheat_manager_state.search_bit_size, idx, 0xFF, cheat_manager_state.big_endian, curr_val) ) runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_ADD_MATCH_FAIL), 1, 180, true); else runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_ADD_MATCH_SUCCESS), 1, 180, true); - return; + return ; case CHEAT_MATCH_ACTION_TYPE_DELETE : if ( bits < 8 ) *(cheat_manager_state.matches+idx) = *(cheat_manager_state.matches+idx) & (( ~(mask << (byte_part*bits))) & 0xFF ); else - memset(cheat_manager_state.matches+idx,0,bytes_per_item); + memset(cheat_manager_state.matches+idx,0,bytes_per_item) ; if ( cheat_manager_state.num_matches > 0 ) - cheat_manager_state.num_matches--; + cheat_manager_state.num_matches-- ; runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_DELETE_MATCH_SUCCESS), 1, 180, true); - return; + return ; } } - curr_match_idx++; + curr_match_idx++ ; } } @@ -1521,8 +1489,8 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig int cheat_manager_copy_match(rarch_setting_t *setting, bool wraparound) { cheat_manager_match_action(CHEAT_MATCH_ACTION_TYPE_COPY, - cheat_manager_state.match_idx, NULL, NULL, NULL, NULL); - return 0; + cheat_manager_state.match_idx, NULL, NULL, NULL, NULL) ; + return 0 ; } int cheat_manager_delete_match(rarch_setting_t *setting, bool wraparound) diff --git a/managers/cheat_manager.h b/managers/cheat_manager.h index 1e0737bcbc..917ea711b8 100644 --- a/managers/cheat_manager.h +++ b/managers/cheat_manager.h @@ -77,8 +77,7 @@ enum cheat_rumble_type RUMBLE_TYPE_LT_VALUE, RUMBLE_TYPE_GT_VALUE, RUMBLE_TYPE_INCREASE_BY_VALUE, - RUMBLE_TYPE_DECREASE_BY_VALUE, - RUMBLE_TYPE_END_LIST + RUMBLE_TYPE_DECREASE_BY_VALUE }; /* Some codes are ridiculously large - over 10000 bytes */ @@ -179,8 +178,6 @@ struct cheat_manager unsigned browse_address; char working_desc[CHEAT_DESC_SCRATCH_SIZE] ; char working_code[CHEAT_CODE_SCRATCH_SIZE] ; - unsigned int loading_cheat_size; - unsigned int loading_cheat_offset; }; typedef struct cheat_manager cheat_manager_t; diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 0110f9ef21..dee87c546a 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -45,7 +45,7 @@ RETRO_BEGIN_DECLS #endif #ifndef MAX_CHEAT_COUNTERS -#define MAX_CHEAT_COUNTERS 6000 +#define MAX_CHEAT_COUNTERS 100 #endif #define MENU_SETTINGS_CORE_INFO_NONE 0xffff diff --git a/menu/menu_setting.c b/menu/menu_setting.c index fbf57eab1b..0f6b8e889b 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -4745,7 +4745,7 @@ static bool setting_append_list( config_uint_cbs(cheat_manager_state.working_cheat.rumble_type, CHEAT_RUMBLE_TYPE, setting_uint_action_left_default,setting_uint_action_right_default, MENU_ENUM_LABEL_RUMBLE_TYPE_DISABLED,&setting_get_string_representation_uint_as_enum, - RUMBLE_TYPE_DISABLED,RUMBLE_TYPE_END_LIST-1,1) ; + RUMBLE_TYPE_DISABLED,RUMBLE_TYPE_GT_VALUE,1) ; (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; config_uint_cbs(cheat_manager_state.working_cheat.rumble_value, CHEAT_RUMBLE_VALUE,