mirror of
https://github.com/libretro/RetroArch
synced 2025-04-17 20:43:10 +00:00
fix strncat size warnings ; only consume additional cheat memory when performing searching - no need to alloc additional memory when applying cheats ; bugfix address mask max value
This commit is contained in:
parent
3d862bbdb4
commit
c2825cb7c5
@ -455,14 +455,19 @@ void cheat_manager_free(void)
|
|||||||
if ( cheat_manager_state.prev_memory_buf )
|
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) ;
|
||||||
|
|
||||||
cheat_manager_state.cheats = NULL ;
|
cheat_manager_state.cheats = NULL ;
|
||||||
cheat_manager_state.size = 0 ;
|
cheat_manager_state.size = 0 ;
|
||||||
cheat_manager_state.buf_size = 0 ;
|
cheat_manager_state.buf_size = 0 ;
|
||||||
cheat_manager_state.prev_memory_buf = NULL ;
|
cheat_manager_state.prev_memory_buf = NULL ;
|
||||||
cheat_manager_state.curr_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.total_memory_size = 0 ;
|
||||||
cheat_manager_state.actual_memory_size = 0 ;
|
cheat_manager_state.actual_memory_size = 0 ;
|
||||||
cheat_manager_state.memory_initialized = false ;
|
cheat_manager_state.memory_initialized = false ;
|
||||||
|
cheat_manager_state.memory_search_initialized = false ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,15 +573,15 @@ bool cheat_manager_get_game_specific_filename(char * cheat_filename, size_t max_
|
|||||||
return false ;
|
return false ;
|
||||||
|
|
||||||
cheat_filename[0] = '\0';
|
cheat_filename[0] = '\0';
|
||||||
strncat(cheat_filename, settings->paths.path_cheat_database, max_length) ;
|
strlcat(cheat_filename, settings->paths.path_cheat_database, max_length-1) ;
|
||||||
fill_pathname_slash(cheat_filename, max_length) ;
|
fill_pathname_slash(cheat_filename, max_length) ;
|
||||||
strncat(cheat_filename, core_name, max_length-strlen(cheat_filename)) ;
|
strlcat(cheat_filename, core_name, max_length-strlen(cheat_filename)-1) ;
|
||||||
fill_pathname_slash(cheat_filename, max_length) ;
|
fill_pathname_slash(cheat_filename, max_length) ;
|
||||||
|
|
||||||
if (!filestream_exists(cheat_filename))
|
if (!filestream_exists(cheat_filename))
|
||||||
path_mkdir(cheat_filename);
|
path_mkdir(cheat_filename);
|
||||||
|
|
||||||
strncat(cheat_filename, game_name, max_length-strlen(cheat_filename)) ;
|
strlcat(cheat_filename, game_name, max_length-strlen(cheat_filename)-1) ;
|
||||||
|
|
||||||
return true ;
|
return true ;
|
||||||
|
|
||||||
@ -614,10 +619,11 @@ bool cheat_manager_alloc_if_empty(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cheat_manager_initialize_search(void *data, bool wraparound)
|
int cheat_manager_initialize_memory(void *data, bool wraparound)
|
||||||
{
|
{
|
||||||
retro_ctx_memory_info_t meminfo ;
|
retro_ctx_memory_info_t meminfo ;
|
||||||
bool refresh = false;
|
bool refresh = false;
|
||||||
|
bool is_search_initialization = (data != NULL) ;
|
||||||
|
|
||||||
meminfo.id = RETRO_MEMORY_SYSTEM_RAM ;
|
meminfo.id = RETRO_MEMORY_SYSTEM_RAM ;
|
||||||
if (! core_get_memory(&meminfo) )
|
if (! core_get_memory(&meminfo) )
|
||||||
@ -629,32 +635,36 @@ int cheat_manager_initialize_search(void *data, bool wraparound)
|
|||||||
cheat_manager_state.actual_memory_size = meminfo.size ;
|
cheat_manager_state.actual_memory_size = meminfo.size ;
|
||||||
cheat_manager_state.curr_memory_buf = meminfo.data ;
|
cheat_manager_state.curr_memory_buf = meminfo.data ;
|
||||||
cheat_manager_state.total_memory_size = meminfo.size ;
|
cheat_manager_state.total_memory_size = meminfo.size ;
|
||||||
cheat_manager_state.num_matches = 0 ;
|
cheat_manager_state.num_matches = (cheat_manager_state.total_memory_size*8)/((int)pow(2,cheat_manager_state.search_bit_size)) ;
|
||||||
//ensure we're aligned on 4-byte boundary
|
//ensure we're aligned on 4-byte boundary
|
||||||
//if ( meminfo.size % 4 > 0 ) {
|
//if ( meminfo.size % 4 > 0 ) {
|
||||||
//cheat_manager_state.total_memory_size = cheat_manager_state.total_memory_size + (4 - (meminfo.size%4)) ;
|
//cheat_manager_state.total_memory_size = cheat_manager_state.total_memory_size + (4 - (meminfo.size%4)) ;
|
||||||
//}
|
//}
|
||||||
cheat_manager_state.prev_memory_buf = (uint8_t*) calloc(cheat_manager_state.total_memory_size, sizeof(uint8_t));
|
if ( is_search_initialization )
|
||||||
if (!cheat_manager_state.prev_memory_buf )
|
|
||||||
{
|
{
|
||||||
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_FAIL), 1, 180, true);
|
cheat_manager_state.prev_memory_buf = (uint8_t*) calloc(cheat_manager_state.total_memory_size, sizeof(uint8_t));
|
||||||
return 0 ;
|
if (!cheat_manager_state.prev_memory_buf )
|
||||||
}
|
{
|
||||||
cheat_manager_state.matches = (uint8_t*) calloc(cheat_manager_state.total_memory_size, sizeof(uint8_t));
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_FAIL), 1, 180, true);
|
||||||
if (!cheat_manager_state.matches )
|
return 0 ;
|
||||||
{
|
}
|
||||||
free(cheat_manager_state.prev_memory_buf) ;
|
cheat_manager_state.matches = (uint8_t*) calloc(cheat_manager_state.total_memory_size, sizeof(uint8_t));
|
||||||
cheat_manager_state.prev_memory_buf = NULL ;
|
if (!cheat_manager_state.matches )
|
||||||
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_FAIL), 1, 180, true);
|
{
|
||||||
return 0 ;
|
free(cheat_manager_state.prev_memory_buf) ;
|
||||||
}
|
cheat_manager_state.prev_memory_buf = NULL ;
|
||||||
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_FAIL), 1, 180, true);
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
memset(cheat_manager_state.matches, 0xFF, cheat_manager_state.total_memory_size) ;
|
memset(cheat_manager_state.matches, 0xFF, cheat_manager_state.total_memory_size) ;
|
||||||
memcpy(cheat_manager_state.prev_memory_buf, cheat_manager_state.curr_memory_buf, cheat_manager_state.actual_memory_size);
|
memcpy(cheat_manager_state.prev_memory_buf, cheat_manager_state.curr_memory_buf, cheat_manager_state.actual_memory_size);
|
||||||
cheat_manager_state.num_matches = (cheat_manager_state.total_memory_size*8)/((int)pow(2,cheat_manager_state.search_bit_size)) ;
|
cheat_manager_state.memory_search_initialized = true ;
|
||||||
|
}
|
||||||
|
|
||||||
cheat_manager_state.memory_initialized = true ;
|
cheat_manager_state.memory_initialized = true ;
|
||||||
|
|
||||||
|
|
||||||
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_SUCCESS), 1, 180, true);
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_SUCCESS), 1, 180, true);
|
||||||
if ( !wraparound )
|
if ( !wraparound )
|
||||||
{
|
{
|
||||||
@ -1135,7 +1145,7 @@ void cheat_manager_apply_retro_cheats(void)
|
|||||||
if (cheat_manager_state.cheats[i].handler != CHEAT_HANDLER_TYPE_RETRO || !cheat_manager_state.cheats[i].state)
|
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 )
|
if ( !cheat_manager_state.memory_initialized )
|
||||||
cheat_manager_initialize_search(NULL, false) ;
|
cheat_manager_initialize_memory(NULL, false) ;
|
||||||
|
|
||||||
/* If we're still not initialized, something must have gone wrong - just bail */
|
/* If we're still not initialized, something must have gone wrong - just bail */
|
||||||
if ( !cheat_manager_state.memory_initialized )
|
if ( !cheat_manager_state.memory_initialized )
|
||||||
|
@ -150,6 +150,7 @@ struct cheat_manager
|
|||||||
unsigned num_matches ;
|
unsigned num_matches ;
|
||||||
bool big_endian ;
|
bool big_endian ;
|
||||||
bool memory_initialized ;
|
bool memory_initialized ;
|
||||||
|
bool memory_search_initialized ;
|
||||||
unsigned int delete_state ;
|
unsigned int delete_state ;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -209,7 +210,7 @@ void cheat_manager_load_game_specific_cheats();
|
|||||||
|
|
||||||
void cheat_manager_save_game_specific_cheats();
|
void cheat_manager_save_game_specific_cheats();
|
||||||
|
|
||||||
int cheat_manager_initialize_search(void *data, bool wraparound);
|
int cheat_manager_initialize_memory(void *data, bool wraparound);
|
||||||
int cheat_manager_search_exact(void *data, bool wraparound);
|
int cheat_manager_search_exact(void *data, bool wraparound);
|
||||||
int cheat_manager_search_lt(void *data, bool wraparound);
|
int cheat_manager_search_lt(void *data, bool wraparound);
|
||||||
int cheat_manager_search_gt(void *data, bool wraparound);
|
int cheat_manager_search_gt(void *data, bool wraparound);
|
||||||
|
@ -5167,12 +5167,16 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
|
|||||||
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);
|
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);
|
||||||
|
|
||||||
if ( !cheat_manager_state.memory_initialized)
|
if ( !cheat_manager_state.memory_initialized)
|
||||||
cheat_manager_initialize_search(NULL,true) ;
|
cheat_manager_initialize_memory(NULL,true) ;
|
||||||
|
|
||||||
setting = menu_setting_find(msg_hash_to_str(MENU_ENUM_LABEL_CHEAT_ADDRESS));
|
setting = menu_setting_find(msg_hash_to_str(MENU_ENUM_LABEL_CHEAT_ADDRESS));
|
||||||
if ( setting )
|
if ( setting )
|
||||||
setting->max = cheat_manager_state.total_memory_size==0?0:cheat_manager_state.total_memory_size-1;
|
setting->max = cheat_manager_state.total_memory_size==0?0:cheat_manager_state.total_memory_size-1;
|
||||||
|
|
||||||
|
setting = menu_setting_find(msg_hash_to_str(MENU_ENUM_LABEL_CHEAT_ADDRESS_BIT_POSITION));
|
||||||
|
if ( setting )
|
||||||
|
setting->max = cheat_manager_state.working_cheat.memory_search_size<3 ? 255 : 0 ;
|
||||||
|
|
||||||
menu_displaylist_parse_settings_enum(menu, info,
|
menu_displaylist_parse_settings_enum(menu, info,
|
||||||
MENU_ENUM_LABEL_CHEAT_IDX,
|
MENU_ENUM_LABEL_CHEAT_IDX,
|
||||||
PARSE_ONLY_UINT, false);
|
PARSE_ONLY_UINT, false);
|
||||||
|
@ -3449,7 +3449,7 @@ static bool setting_append_list(
|
|||||||
setting_uint_action_left_with_refresh,setting_uint_action_right_with_refresh,
|
setting_uint_action_left_with_refresh,setting_uint_action_right_with_refresh,
|
||||||
MENU_ENUM_LABEL_CHEAT_MEMORY_SIZE_1,&setting_get_string_representation_uint_as_enum,
|
MENU_ENUM_LABEL_CHEAT_MEMORY_SIZE_1,&setting_get_string_representation_uint_as_enum,
|
||||||
0,5,1) ;
|
0,5,1) ;
|
||||||
(*list)[list_info->index - 1].action_ok = &cheat_manager_initialize_search;
|
(*list)[list_info->index - 1].action_ok = &cheat_manager_initialize_memory;
|
||||||
|
|
||||||
CONFIG_BOOL(
|
CONFIG_BOOL(
|
||||||
list, list_info,
|
list, list_info,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user