1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-03 00:38:44 +00:00

add some options to the cheat system to browse emulator memory

This commit is contained in:
Sven 2018-08-03 14:59:33 -04:00
parent c1bba50567
commit 36d16a9c94
9 changed files with 113 additions and 10 deletions

View File

@ -1637,6 +1637,8 @@ MSG_HASH(MENU_ENUM_LABEL_CHEAT_MATCH_IDX,
"cheat_match_idx")
MSG_HASH(MENU_ENUM_LABEL_CHEAT_MATCH,
"cheat_match")
MSG_HASH(MENU_ENUM_LABEL_CHEAT_BROWSE_MEMORY,
"cheat_browse_memory")
MSG_HASH(MENU_ENUM_LABEL_CHEAT_COPY_MATCH,
"cheat_copy_match")
MSG_HASH(MENU_ENUM_LABEL_CHEAT_DELETE_MATCH,

View File

@ -3930,6 +3930,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_CHEAT_COPY_MATCH,
"Create Code Match #")
MSG_HASH(MENU_ENUM_LABEL_VALUE_CHEAT_DELETE_MATCH,
"Delete Match #")
MSG_HASH(MENU_ENUM_LABEL_VALUE_CHEAT_BROWSE_MEMORY,
"Browse Address: %08X")
MSG_HASH(MENU_ENUM_LABEL_VALUE_CHEAT_DESC,
"Description")
MSG_HASH(MENU_ENUM_LABEL_VALUE_CHEAT_STATE,

View File

@ -1327,6 +1327,7 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig
bool refresh = false;
unsigned int byte_part;
unsigned int idx;
unsigned int start_idx;
unsigned int mask = 0 ;
unsigned int bytes_per_item = 1 ;
unsigned int bits = 8 ;
@ -1339,9 +1340,17 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig
if ( target_match_idx > cheat_manager_state.num_matches-1)
return;
if ( curr == NULL )
return ;
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)
if ( match_action == CHEAT_MATCH_ACTION_TYPE_BROWSE)
start_idx = *address ;
else
start_idx = 0 ;
for (idx = start_idx ; idx < cheat_manager_state.total_memory_size ; idx = idx + bytes_per_item)
{
switch ( bytes_per_item )
{
@ -1350,9 +1359,10 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig
curr_val = cheat_manager_state.big_endian ?
(*(curr+idx)*256) + *(curr+idx+1) :
*(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) ;
if ( prev != NULL )
prev_val = cheat_manager_state.big_endian ?
(*(prev+idx)*256) + *(prev+idx+1) :
*(prev+idx) + (*(prev+idx+1)*256) ;
break ;
}
case 4 :
@ -1360,19 +1370,32 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig
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) ;
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) ;
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 ;
}
case 1 :
default :
{
curr_val = *(curr+idx) ;
prev_val = *(prev+idx) ;
if ( prev != NULL )
prev_val = *(prev+idx) ;
break ;
}
}
if ( match_action == CHEAT_MATCH_ACTION_TYPE_BROWSE)
{
*curr_value = curr_val ;
*prev_value = prev_val ;
return ;
}
if ( prev == NULL )
return ;
for (byte_part = 0 ; byte_part < 8/bits ; byte_part++)
{
unsigned int prev_match ;
@ -1386,6 +1409,8 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig
{
switch ( match_action )
{
case CHEAT_MATCH_ACTION_TYPE_BROWSE :
return ;
case CHEAT_MATCH_ACTION_TYPE_VIEW :
{
*address = idx ;
@ -1430,6 +1455,8 @@ void cheat_manager_match_action(enum cheat_match_action_type match_action, unsig
{
switch ( match_action )
{
case CHEAT_MATCH_ACTION_TYPE_BROWSE :
return ;
case CHEAT_MATCH_ACTION_TYPE_VIEW :
{
*address = idx ;

View File

@ -59,7 +59,8 @@ enum cheat_match_action_type
{
CHEAT_MATCH_ACTION_TYPE_VIEW = 0,
CHEAT_MATCH_ACTION_TYPE_DELETE,
CHEAT_MATCH_ACTION_TYPE_COPY
CHEAT_MATCH_ACTION_TYPE_COPY,
CHEAT_MATCH_ACTION_TYPE_BROWSE
};
enum cheat_rumble_type
@ -152,6 +153,7 @@ struct cheat_manager
bool memory_initialized ;
bool memory_search_initialized ;
unsigned int delete_state ;
unsigned browse_address;
};
typedef struct cheat_manager cheat_manager_t;

View File

@ -19,6 +19,7 @@
#include "../menu_driver.h"
#include "../menu_cbs.h"
#include "../../file_path_special.h"
#include "../managers/cheat_manager.h"
#ifndef BIND_ACTION_LABEL
#define BIND_ACTION_LABEL(cbs, name) \
@ -67,6 +68,16 @@ static int action_bind_label_playlist_collection_entry(
return 0;
}
static int action_bind_label_cheat_browse_address(
file_list_t *list,
unsigned type, unsigned i,
const char *label, const char *path,
char *s, size_t len)
{
snprintf(s, len, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CHEAT_BROWSE_MEMORY), cheat_manager_state.browse_address);
return 0;
}
int menu_cbs_init_bind_label(menu_file_list_cbs_t *cbs,
const char *path, const char *label, unsigned type, size_t idx)
{
@ -82,6 +93,9 @@ int menu_cbs_init_bind_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_PLAYLIST_COLLECTION_ENTRY:
BIND_ACTION_LABEL(cbs, action_bind_label_playlist_collection_entry);
break;
case MENU_ENUM_LABEL_CHEAT_BROWSE_MEMORY:
BIND_ACTION_LABEL(cbs, action_bind_label_cheat_browse_address);
break;
case MSG_INTERNAL_STORAGE:
BIND_ACTION_LABEL(cbs, action_bind_label_internal_memory);
break;

View File

@ -848,6 +848,11 @@ int generic_action_ok_displaylist_push(const char *path,
int max_bit_position = cheat_manager_state.working_cheat.memory_search_size<3 ? 7 : 0 ;
setting->max = max_bit_position ;
}
setting = menu_setting_find(msg_hash_to_str(MENU_ENUM_LABEL_CHEAT_ADDRESS));
if ( setting )
{
cheat_manager_state.browse_address = *setting->value.target.unsigned_integer ;
}
action_ok_dl_lbl(action_ok_dl_to_enum(action_type), DISPLAYLIST_GENERIC);
break ;
}

View File

@ -5180,6 +5180,11 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
if ( setting )
setting->max = cheat_manager_state.working_cheat.memory_search_size<3 ? 255 : 0 ;
setting = menu_setting_find(msg_hash_to_str(MENU_ENUM_LABEL_CHEAT_BROWSE_MEMORY));
if ( setting )
setting->max = cheat_manager_state.actual_memory_size>0?cheat_manager_state.actual_memory_size-1:0 ;
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_CHEAT_IDX,
PARSE_ONLY_UINT, false);
@ -5211,6 +5216,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_CHEAT_ADDRESS,
PARSE_ONLY_UINT, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_CHEAT_BROWSE_MEMORY,
PARSE_ONLY_UINT, false);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_CHEAT_ADDRESS_BIT_POSITION,
PARSE_ONLY_UINT, false);
@ -5355,6 +5363,11 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
MSG_UNKNOWN,
MENU_SETTINGS_CHEAT_MATCH, 0, 0);
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_CHEAT_BROWSE_MEMORY,
PARSE_ONLY_UINT, false);
setting = menu_setting_find(msg_hash_to_str(MENU_ENUM_LABEL_CHEAT_DELETE_MATCH));
if ( setting )
@ -5362,6 +5375,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
setting = menu_setting_find(msg_hash_to_str(MENU_ENUM_LABEL_CHEAT_COPY_MATCH));
if ( setting )
setting->max = cheat_manager_state.num_matches-1;
setting = menu_setting_find(msg_hash_to_str(MENU_ENUM_LABEL_CHEAT_BROWSE_MEMORY));
if ( setting )
setting->max = cheat_manager_state.actual_memory_size>0?cheat_manager_state.actual_memory_size-1:0 ;
info->need_refresh = true;
info->need_push = true;

View File

@ -513,6 +513,24 @@ static void setting_get_string_representation_uint_cheat_eqminus(void *data,
*setting->value.target.unsigned_integer, *setting->value.target.unsigned_integer);
}
static void setting_get_string_representation_uint_cheat_browse_address(void *data,
char *s, size_t len)
{
rarch_setting_t *setting = (rarch_setting_t*)data;
if (setting)
snprintf(s, len, msg_hash_to_str(MENU_ENUM_LABEL_CHEAT_SEARCH_EQMINUS_VAL),
*setting->value.target.unsigned_integer, *setting->value.target.unsigned_integer);
unsigned int address = cheat_manager_state.browse_address;
unsigned int address_mask = 0;
unsigned int prev_val = 0;
unsigned int curr_val = 0 ;
cheat_manager_match_action(CHEAT_MATCH_ACTION_TYPE_BROWSE, cheat_manager_state.match_idx, &address, &address_mask, &prev_val, &curr_val) ;
snprintf(s, len, "Prev: %u Curr: %u", prev_val, curr_val) ;
}
static void setting_get_string_representation_uint_video_rotation(void *data,
char *s, size_t len)
{
@ -3403,7 +3421,7 @@ static bool setting_append_list(
0,&setting_get_string_representation_hex_and_uint,0,(int) pow(2,pow((double) 2,cheat_manager_state.working_cheat.memory_search_size))-1,1) ;
config_uint_cbs(cheat_manager_state.working_cheat.address, CHEAT_ADDRESS,
setting_uint_action_left_default,setting_uint_action_right_default,
setting_uint_action_left_with_refresh,setting_uint_action_right_with_refresh,
0,&setting_get_string_representation_hex_and_uint,0,cheat_manager_state.total_memory_size==0?0:cheat_manager_state.total_memory_size-1,1) ;
max_bit_position = cheat_manager_state.working_cheat.memory_search_size<3 ? 255 : 0 ;
@ -3655,6 +3673,22 @@ static bool setting_append_list(
(*list)[list_info->index - 1].action_right = &setting_uint_action_right_with_refresh;
(*list)[list_info->index - 1].action_ok = &cheat_manager_copy_match;
CONFIG_UINT(
list, list_info,
&cheat_manager_state.browse_address,
MENU_ENUM_LABEL_CHEAT_BROWSE_MEMORY,
MENU_ENUM_LABEL_VALUE_CHEAT_BROWSE_MEMORY,
cheat_manager_state.browse_address,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
menu_settings_list_current_add_range(list, list_info, 0, cheat_manager_state.actual_memory_size>0?cheat_manager_state.actual_memory_size-1:0, 1, true, true);
(*list)[list_info->index - 1].action_left = &setting_uint_action_left_with_refresh;
(*list)[list_info->index - 1].action_right = &setting_uint_action_right_with_refresh;
(*list)[list_info->index - 1].get_string_representation = &setting_get_string_representation_uint_cheat_browse_address;
END_SUB_GROUP(list, list_info, parent_group);
END_GROUP(list, list_info, parent_group);

View File

@ -1246,6 +1246,7 @@ enum msg_hash_enums
MENU_LABEL(CHEAT_BIG_ENDIAN),
MENU_LABEL(CHEAT_MATCH_IDX),
MENU_LABEL(CHEAT_MATCH),
MENU_LABEL(CHEAT_BROWSE_MEMORY),
MENU_LABEL(CHEAT_COPY_MATCH),
MENU_LABEL(CHEAT_DELETE_MATCH),
MENU_LABEL(SCREEN_RESOLUTION),