2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-01-22 12:40:32 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2016-10-27 09:27:02 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-04-17 11:30:59 +00:00
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-04-17 11:30:59 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-04-17 11:30:59 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-09-04 19:11:00 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-12-15 21:40:23 +00:00
|
|
|
#include <file/config_file.h>
|
2015-01-19 18:00:26 +00:00
|
|
|
#include <file/file_path.h>
|
2014-10-21 05:58:58 +00:00
|
|
|
#include <compat/strl.h>
|
|
|
|
#include <compat/posix_string.h>
|
2018-07-29 14:48:41 +00:00
|
|
|
#include <streams/file_stream.h>
|
2017-01-11 06:25:42 +00:00
|
|
|
#include <string/stdstring.h>
|
2017-01-17 18:39:12 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2018-07-25 23:19:14 +00:00
|
|
|
#include <features/features_cpu.h>
|
2011-04-17 11:30:59 +00:00
|
|
|
|
2011-09-05 15:57:30 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2016-05-09 16:20:52 +00:00
|
|
|
#include "../config.h"
|
2011-09-05 15:57:30 +00:00
|
|
|
#endif
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
#ifdef HAVE_MENU
|
2018-07-28 20:11:56 +00:00
|
|
|
#include "../menu/menu_driver.h"
|
|
|
|
#include "../menu/widgets/menu_input_dialog.h"
|
|
|
|
#include "../menu/widgets/menu_input_bind_dialog.h"
|
2018-07-25 23:19:14 +00:00
|
|
|
#endif
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
#ifdef HAVE_CHEEVOS
|
2017-05-07 18:06:03 +00:00
|
|
|
#include "../cheevos/cheevos.h"
|
2015-10-27 17:50:41 +00:00
|
|
|
#endif
|
|
|
|
|
2016-09-08 06:13:09 +00:00
|
|
|
#include "cheat_manager.h"
|
2017-01-17 18:39:12 +00:00
|
|
|
|
|
|
|
#include "../msg_hash.h"
|
2017-05-11 07:11:46 +00:00
|
|
|
#include "../retroarch.h"
|
2016-09-08 06:13:09 +00:00
|
|
|
#include "../dynamic.h"
|
|
|
|
#include "../core.h"
|
|
|
|
#include "../verbosity.h"
|
2018-07-25 23:19:14 +00:00
|
|
|
#include "../input/input_driver.h"
|
2018-07-29 14:48:41 +00:00
|
|
|
#include "../configuration.h"
|
2016-09-08 06:13:09 +00:00
|
|
|
|
2015-12-01 02:29:32 +00:00
|
|
|
|
2015-12-01 01:43:34 +00:00
|
|
|
unsigned cheat_manager_get_buf_size(void)
|
2015-09-06 01:51:08 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
return cheat_manager_state.buf_size;
|
2015-09-06 01:51:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-01 01:55:07 +00:00
|
|
|
unsigned cheat_manager_get_size(void)
|
2015-09-06 01:51:08 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
return cheat_manager_state.size;
|
2015-09-06 01:51:08 +00:00
|
|
|
}
|
2011-04-17 11:30:59 +00:00
|
|
|
|
2015-12-01 01:43:34 +00:00
|
|
|
void cheat_manager_apply_cheats(void)
|
2011-09-05 15:57:30 +00:00
|
|
|
{
|
2016-02-13 05:24:49 +00:00
|
|
|
#ifdef HAVE_CHEEVOS
|
|
|
|
bool data_bool = false;
|
|
|
|
#endif
|
2015-01-09 14:33:58 +00:00
|
|
|
unsigned i, idx = 0;
|
2014-10-20 22:14:38 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
if (!cheat_manager_state.cheats)
|
2015-04-03 17:53:20 +00:00
|
|
|
return;
|
|
|
|
|
2016-05-07 23:33:57 +00:00
|
|
|
core_reset_cheat();
|
2015-01-09 14:33:58 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
for (i = 0; i < cheat_manager_state.size; i++)
|
2011-09-05 15:57:30 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
if (cheat_manager_state.cheats[i].state && cheat_manager_state.cheats[i].handler == CHEAT_HANDLER_TYPE_EMU)
|
2016-01-28 03:34:39 +00:00
|
|
|
{
|
|
|
|
retro_ctx_cheat_info_t cheat_info;
|
|
|
|
|
|
|
|
cheat_info.index = idx++;
|
|
|
|
cheat_info.enabled = true;
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_info.code = cheat_manager_state.cheats[i].code;
|
2016-01-28 03:34:39 +00:00
|
|
|
|
2017-11-13 04:18:11 +00:00
|
|
|
if (!string_is_empty(cheat_info.code))
|
|
|
|
core_set_cheat(&cheat_info);
|
2016-01-28 03:34:39 +00:00
|
|
|
}
|
2011-09-05 15:57:30 +00:00
|
|
|
}
|
2016-12-22 22:36:11 +00:00
|
|
|
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));
|
2016-10-27 09:27:02 +00:00
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
#ifdef HAVE_CHEEVOS
|
2016-02-13 05:24:49 +00:00
|
|
|
data_bool = idx != 0;
|
2016-05-07 22:15:04 +00:00
|
|
|
cheevos_apply_cheats(&data_bool);
|
2015-10-27 17:50:41 +00:00
|
|
|
#endif
|
2011-09-05 15:57:30 +00:00
|
|
|
}
|
|
|
|
|
2015-12-01 01:55:07 +00:00
|
|
|
void cheat_manager_set_code(unsigned i, const char *str)
|
2015-09-06 01:51:08 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
if (!cheat_manager_state.cheats)
|
2015-09-06 01:51:08 +00:00
|
|
|
return;
|
2017-01-11 06:25:42 +00:00
|
|
|
|
|
|
|
if (!string_is_empty(str))
|
2018-07-25 23:19:14 +00:00
|
|
|
strcpy(cheat_manager_state.cheats[i].code,str) ;
|
2017-01-11 06:25:42 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.cheats[i].state = true;
|
2015-09-06 01:51:08 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 18:00:26 +00:00
|
|
|
/**
|
|
|
|
* cheat_manager_save:
|
|
|
|
* @path : Path to cheats file (relative path).
|
|
|
|
*
|
|
|
|
* Saves cheats to file on disk.
|
|
|
|
*
|
|
|
|
* Returns: true (1) if successful, otherwise false (0).
|
|
|
|
**/
|
2018-07-25 23:19:14 +00:00
|
|
|
bool cheat_manager_save(const char *path, const char *cheat_database, bool overwrite)
|
2015-01-19 18:00:26 +00:00
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
unsigned i;
|
2016-10-21 03:57:40 +00:00
|
|
|
char buf[PATH_MAX_LENGTH];
|
|
|
|
char cheats_file[PATH_MAX_LENGTH];
|
2015-06-12 21:14:55 +00:00
|
|
|
config_file_t *conf = NULL;
|
2018-09-29 18:52:10 +00:00
|
|
|
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",
|
|
|
|
};
|
2016-10-21 03:57:40 +00:00
|
|
|
|
|
|
|
buf[0] = cheats_file[0] = '\0';
|
2015-01-19 18:00:26 +00:00
|
|
|
|
2018-07-29 14:48:41 +00:00
|
|
|
if ( (!cheat_manager_state.cheats) || cheat_manager_state.size==0 )
|
|
|
|
return false ;
|
|
|
|
|
2018-08-13 10:10:02 +00:00
|
|
|
if (!cheat_database)
|
|
|
|
strlcpy(cheats_file, path, sizeof(cheats_file));
|
2018-07-25 23:19:14 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fill_pathname_join(buf, cheat_database, path, sizeof(buf));
|
2016-10-27 09:27:02 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
fill_pathname_noext(cheats_file, buf, ".cht", sizeof(cheats_file));
|
|
|
|
}
|
|
|
|
if ( !overwrite )
|
|
|
|
conf = config_file_new(cheats_file);
|
|
|
|
else
|
|
|
|
conf = config_file_new(NULL);
|
2015-01-19 18:00:26 +00:00
|
|
|
|
|
|
|
if (!conf)
|
|
|
|
conf = config_file_new(NULL);
|
|
|
|
|
|
|
|
if (!conf)
|
|
|
|
return false;
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
config_set_int(conf, "cheats", cheat_manager_state.size);
|
2015-01-19 18:00:26 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
for (i = 0; i < cheat_manager_state.size; i++)
|
2015-01-19 18:00:26 +00:00
|
|
|
{
|
2018-07-28 20:11:56 +00:00
|
|
|
unsigned j;
|
2018-07-25 23:19:14 +00:00
|
|
|
char endian_key[100];
|
|
|
|
char key[256];
|
2016-10-21 03:57:40 +00:00
|
|
|
char desc_key[256];
|
|
|
|
char code_key[256];
|
|
|
|
char enable_key[256];
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-07-28 20:11:56 +00:00
|
|
|
key[0] = endian_key[0] = desc_key[0] = code_key[0] = enable_key[0] = '\0';
|
|
|
|
|
|
|
|
snprintf(endian_key, sizeof(endian_key), "cheat%u_big_endian", i);
|
|
|
|
snprintf(desc_key, sizeof(desc_key), "cheat%u_desc", i);
|
|
|
|
snprintf(code_key, sizeof(code_key), "cheat%u_code", i);
|
|
|
|
snprintf(enable_key, sizeof(enable_key), "cheat%u_enable", i);
|
|
|
|
|
|
|
|
if (!string_is_empty(cheat_manager_state.cheats[i].desc))
|
|
|
|
config_set_string(conf, desc_key, cheat_manager_state.cheats[i].desc);
|
|
|
|
else
|
|
|
|
config_set_string(conf, desc_key, cheat_manager_state.cheats[i].code);
|
2018-09-29 18:52:10 +00:00
|
|
|
|
2018-07-28 20:11:56 +00:00
|
|
|
config_set_string(conf, code_key, cheat_manager_state.cheats[i].code);
|
|
|
|
config_set_bool(conf, enable_key, cheat_manager_state.cheats[i].state);
|
|
|
|
config_set_bool(conf, endian_key, cheat_manager_state.cheats[i].big_endian);
|
|
|
|
|
2018-09-29 18:52:10 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
for (j = 0; j < 16; j++)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
key[0] = '\0';
|
2018-08-07 01:50:10 +00:00
|
|
|
snprintf(key, sizeof(key), keys[j], i);
|
2018-07-25 23:19:14 +00:00
|
|
|
config_set_uint(conf, key, *(data_ptrs[j]));
|
|
|
|
}
|
|
|
|
|
2015-01-19 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = config_file_write(conf, cheats_file);
|
|
|
|
config_file_free(conf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
bool cheat_manager_copy_idx_to_working(unsigned idx)
|
|
|
|
{
|
|
|
|
if ( (!cheat_manager_state.cheats) || (cheat_manager_state.size < idx+1))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&(cheat_manager_state.working_cheat), &(cheat_manager_state.cheats[idx]), sizeof(struct item_cheat)) ;
|
2018-08-04 17:05:05 +00:00
|
|
|
if ( cheat_manager_state.cheats[idx].desc != NULL )
|
|
|
|
strlcpy(cheat_manager_state.working_desc, cheat_manager_state.cheats[idx].desc, CHEAT_DESC_SCRATCH_SIZE) ;
|
|
|
|
else
|
|
|
|
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) ;
|
|
|
|
else
|
|
|
|
cheat_manager_state.working_code[0] = '\0' ;
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
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)) ;
|
2018-08-04 17:05:05 +00:00
|
|
|
if ( cheat_manager_state.cheats[idx].desc != NULL )
|
|
|
|
free(cheat_manager_state.cheats[idx].desc) ;
|
|
|
|
|
|
|
|
cheat_manager_state.cheats[idx].desc = strdup(cheat_manager_state.working_desc) ;
|
2018-09-23 19:25:51 +00:00
|
|
|
|
|
|
|
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) ;
|
2018-07-25 23:19:14 +00:00
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
static void cheat_manager_new(unsigned size)
|
2016-03-24 03:51:45 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_free() ;
|
2016-03-24 03:51:45 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.buf_size = size;
|
|
|
|
cheat_manager_state.size = size;
|
|
|
|
cheat_manager_state.search_bit_size = 3;
|
|
|
|
cheat_manager_state.cheats = (struct item_cheat*)
|
|
|
|
calloc(cheat_manager_state.buf_size, sizeof(struct item_cheat));
|
|
|
|
|
|
|
|
if (!cheat_manager_state.cheats)
|
2016-03-24 03:51:45 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.buf_size = 0;
|
|
|
|
cheat_manager_state.size = 0;
|
|
|
|
cheat_manager_state.cheats = NULL;
|
|
|
|
return ;
|
2016-03-24 03:51:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
for (i = 0; i < cheat_manager_state.size; i++)
|
2016-03-24 03:51:45 +00:00
|
|
|
{
|
2018-08-04 17:05:05 +00:00
|
|
|
cheat_manager_state.cheats[i].desc = NULL ;
|
|
|
|
cheat_manager_state.cheats[i].code = NULL ;
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.cheats[i].state = false;
|
2018-09-29 18:52:10 +00:00
|
|
|
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;
|
2016-03-24 03:51:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
return ;
|
2016-03-24 03:51:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
bool cheat_manager_load(const char *path, bool append)
|
2014-12-15 21:40:23 +00:00
|
|
|
{
|
|
|
|
unsigned cheats = 0, i;
|
2015-12-01 02:00:31 +00:00
|
|
|
config_file_t *conf = config_file_new(path);
|
2018-07-25 23:19:14 +00:00
|
|
|
unsigned orig_size ;
|
2018-09-29 18:52:10 +00:00
|
|
|
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",
|
|
|
|
};
|
2014-12-15 21:40:23 +00:00
|
|
|
|
|
|
|
if (!conf)
|
2015-12-01 02:00:31 +00:00
|
|
|
return false;
|
2014-12-15 21:40:23 +00:00
|
|
|
|
|
|
|
config_get_uint(conf, "cheats", &cheats);
|
|
|
|
|
|
|
|
if (cheats == 0)
|
2016-05-24 20:01:43 +00:00
|
|
|
goto error;
|
2014-12-15 21:40:23 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_alloc_if_empty() ;
|
2014-12-15 21:40:23 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
if ( append )
|
|
|
|
{
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
orig_size = 0 ;
|
|
|
|
cheat_manager_new(cheats);
|
|
|
|
}
|
2014-12-15 21:40:23 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
for (i = orig_size; i < cheats; i++)
|
2014-12-15 21:40:23 +00:00
|
|
|
{
|
2018-07-28 20:11:56 +00:00
|
|
|
unsigned j;
|
2018-08-07 01:50:10 +00:00
|
|
|
char desc_key[256];
|
|
|
|
char code_key[256];
|
|
|
|
char enable_key[256];
|
|
|
|
char endian_key[256];
|
|
|
|
char *tmp = NULL;
|
|
|
|
bool tmp_bool = false;
|
2018-09-29 18:52:10 +00:00
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
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;
|
2018-09-29 18:52:10 +00:00
|
|
|
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;
|
2014-12-15 21:40:23 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
endian_key[0] = desc_key[0] = code_key[0] = enable_key[0] = '\0';
|
2016-10-21 03:57:40 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
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 ;
|
|
|
|
|
2018-08-04 17:05:05 +00:00
|
|
|
cheat_manager_state.cheats[i].desc = NULL ;
|
|
|
|
cheat_manager_state.cheats[i].code = NULL ;
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.cheats[i].state = false ;
|
|
|
|
cheat_manager_state.cheats[i].big_endian = false ;
|
2014-12-15 21:40:23 +00:00
|
|
|
|
2017-01-11 06:25:42 +00:00
|
|
|
if (config_get_string(conf, desc_key, &tmp) && !string_is_empty(tmp))
|
2018-08-04 17:05:05 +00:00
|
|
|
cheat_manager_state.cheats[i].desc = strdup(tmp) ;
|
2014-12-15 21:40:23 +00:00
|
|
|
|
2017-01-11 06:25:42 +00:00
|
|
|
if (config_get_string(conf, code_key, &tmp) && !string_is_empty(tmp))
|
2018-08-04 17:05:05 +00:00
|
|
|
cheat_manager_state.cheats[i].code = strdup(tmp) ;
|
2014-12-15 21:40:23 +00:00
|
|
|
|
|
|
|
if (config_get_bool(conf, enable_key, &tmp_bool))
|
2018-07-25 23:19:14 +00:00
|
|
|
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;
|
2015-07-09 18:16:30 +00:00
|
|
|
|
|
|
|
if (tmp)
|
|
|
|
free(tmp);
|
2018-07-25 23:19:14 +00:00
|
|
|
|
|
|
|
cheat_manager_state.cheats[i].cheat_type = CHEAT_TYPE_SET_TO_VALUE ;
|
|
|
|
cheat_manager_state.cheats[i].memory_search_size = 3;
|
2018-09-29 18:52:10 +00:00
|
|
|
for (j = 0 ; j < 16 ; j++ )
|
2018-07-28 20:11:56 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
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 ;
|
|
|
|
}
|
2014-12-15 21:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config_file_free(conf);
|
|
|
|
|
2015-12-01 02:00:31 +00:00
|
|
|
return true;
|
2016-05-24 20:01:43 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
config_file_free(conf);
|
|
|
|
return false;
|
2014-12-15 21:40:23 +00:00
|
|
|
}
|
|
|
|
|
2014-12-06 14:47:25 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
bool cheat_manager_realloc(unsigned new_size, unsigned default_handler)
|
2014-12-06 14:47:25 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2018-07-25 23:19:14 +00:00
|
|
|
unsigned orig_size ;
|
2014-12-06 14:47:25 +00:00
|
|
|
|
2015-04-03 17:53:20 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
if (!cheat_manager_state.cheats)
|
|
|
|
{
|
|
|
|
cheat_manager_state.cheats = (struct item_cheat*)
|
2014-12-06 14:47:25 +00:00
|
|
|
calloc(new_size, sizeof(struct item_cheat));
|
2018-07-25 23:19:14 +00:00
|
|
|
orig_size = 0 ;
|
|
|
|
}
|
2014-12-06 14:47:25 +00:00
|
|
|
else
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
orig_size = cheat_manager_state.size ;
|
2018-08-04 17:05:05 +00:00
|
|
|
|
|
|
|
/* 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) ;
|
|
|
|
if ( cheat_manager_state.cheats[i].desc != NULL )
|
|
|
|
free(cheat_manager_state.cheats[i].desc) ;
|
|
|
|
}
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.cheats = (struct item_cheat*)
|
|
|
|
realloc(cheat_manager_state.cheats, new_size * sizeof(struct item_cheat));
|
|
|
|
}
|
2014-12-06 14:47:25 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
if (!cheat_manager_state.cheats)
|
2014-12-06 14:47:25 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.buf_size = cheat_manager_state.size = 0;
|
|
|
|
cheat_manager_state.cheats = NULL;
|
2014-12-06 14:47:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.buf_size = new_size;
|
|
|
|
cheat_manager_state.size = new_size;
|
2014-12-06 14:47:25 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
for (i = orig_size; i < cheat_manager_state.size; i++)
|
2014-12-06 14:47:25 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
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;
|
2018-09-29 18:52:10 +00:00
|
|
|
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;
|
2014-12-06 14:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-01 02:00:31 +00:00
|
|
|
void cheat_manager_free(void)
|
2011-04-17 11:30:59 +00:00
|
|
|
{
|
2018-08-04 17:05:05 +00:00
|
|
|
unsigned i = 0 ;
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
if (cheat_manager_state.cheats)
|
2018-08-04 17:05:05 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i < cheat_manager_state.size; i++)
|
|
|
|
{
|
|
|
|
if ( cheat_manager_state.cheats[i].desc != NULL )
|
|
|
|
free(cheat_manager_state.cheats[i].desc) ;
|
|
|
|
if ( cheat_manager_state.cheats[i].code != NULL )
|
|
|
|
free(cheat_manager_state.cheats[i].code) ;
|
|
|
|
}
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
free(cheat_manager_state.cheats);
|
2018-08-04 17:05:05 +00:00
|
|
|
}
|
2015-09-28 16:22:27 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
if ( cheat_manager_state.prev_memory_buf )
|
|
|
|
free(cheat_manager_state.prev_memory_buf) ;
|
2011-04-17 11:30:59 +00:00
|
|
|
|
2018-07-30 08:08:50 +00:00
|
|
|
if ( cheat_manager_state.matches )
|
|
|
|
free(cheat_manager_state.matches) ;
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
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 ;
|
2018-07-30 08:08:50 +00:00
|
|
|
cheat_manager_state.matches = NULL ;
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.total_memory_size = 0 ;
|
|
|
|
cheat_manager_state.actual_memory_size = 0 ;
|
|
|
|
cheat_manager_state.memory_initialized = false ;
|
2018-07-30 08:08:50 +00:00
|
|
|
cheat_manager_state.memory_search_initialized = false ;
|
2011-04-17 11:30:59 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-16 04:14:22 +00:00
|
|
|
void cheat_manager_update(cheat_manager_t *handle, unsigned handle_idx)
|
2011-04-17 14:53:19 +00:00
|
|
|
{
|
2015-12-07 14:32:14 +00:00
|
|
|
char msg[256];
|
2015-01-09 14:33:58 +00:00
|
|
|
|
2018-08-07 21:34:46 +00:00
|
|
|
if (!handle || !handle->cheats || handle->size == 0)
|
2015-04-03 17:53:20 +00:00
|
|
|
return;
|
|
|
|
|
2014-09-02 03:32:04 +00:00
|
|
|
snprintf(msg, sizeof(msg), "Cheat: #%u [%s]: %s",
|
2014-12-16 04:14:22 +00:00
|
|
|
handle_idx, handle->cheats[handle_idx].state ? "ON" : "OFF",
|
2018-08-04 17:05:05 +00:00
|
|
|
(handle->cheats[handle_idx].desc!=NULL) ?
|
2014-12-16 04:14:22 +00:00
|
|
|
(handle->cheats[handle_idx].desc) : (handle->cheats[handle_idx].code)
|
2014-12-16 01:20:06 +00:00
|
|
|
);
|
2016-12-22 22:36:11 +00:00
|
|
|
runloop_msg_queue_push(msg, 1, 180, true);
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("%s\n", msg);
|
2011-04-17 14:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-12-01 02:03:33 +00:00
|
|
|
void cheat_manager_toggle_index(unsigned i)
|
2015-09-06 01:51:08 +00:00
|
|
|
{
|
2018-08-03 22:47:52 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2018-08-07 21:34:46 +00:00
|
|
|
if (!cheat_manager_state.cheats || cheat_manager_state.size == 0 )
|
2015-09-06 01:51:08 +00:00
|
|
|
return;
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.cheats[i].state = !cheat_manager_state.cheats[i].state;
|
|
|
|
cheat_manager_update(&cheat_manager_state, i);
|
2018-08-02 14:59:37 +00:00
|
|
|
|
2018-08-03 22:47:52 +00:00
|
|
|
if (!settings)
|
2018-08-02 14:59:37 +00:00
|
|
|
return ;
|
|
|
|
|
2018-08-03 22:47:52 +00:00
|
|
|
if (settings->bools.apply_cheats_after_toggle)
|
2018-08-02 14:59:37 +00:00
|
|
|
cheat_manager_apply_cheats();
|
2015-09-06 01:51:08 +00:00
|
|
|
}
|
2011-09-05 15:57:30 +00:00
|
|
|
|
2017-05-21 11:14:21 +00:00
|
|
|
void cheat_manager_toggle(void)
|
2011-04-17 11:30:59 +00:00
|
|
|
{
|
2017-05-21 11:14:21 +00:00
|
|
|
|
2018-08-07 21:34:46 +00:00
|
|
|
if (!cheat_manager_state.cheats || cheat_manager_state.size == 0)
|
2014-10-03 13:13:37 +00:00
|
|
|
return;
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.cheats[cheat_manager_state.ptr].state ^= true;
|
2015-12-01 01:43:34 +00:00
|
|
|
cheat_manager_apply_cheats();
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_update(&cheat_manager_state, cheat_manager_state.ptr);
|
2011-04-17 14:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-21 11:14:21 +00:00
|
|
|
void cheat_manager_index_next(void)
|
2011-04-17 14:53:19 +00:00
|
|
|
{
|
2018-08-07 21:34:46 +00:00
|
|
|
if (!cheat_manager_state.cheats || cheat_manager_state.size == 0)
|
2014-10-03 13:13:37 +00:00
|
|
|
return;
|
2015-01-09 14:33:58 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.ptr = (cheat_manager_state.ptr + 1) % cheat_manager_state.size;
|
|
|
|
cheat_manager_update(&cheat_manager_state, cheat_manager_state.ptr);
|
2011-04-17 14:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-21 11:14:21 +00:00
|
|
|
void cheat_manager_index_prev(void)
|
2011-04-17 14:53:19 +00:00
|
|
|
{
|
2018-08-07 21:34:46 +00:00
|
|
|
if (!cheat_manager_state.cheats || cheat_manager_state.size == 0)
|
2014-10-03 13:13:37 +00:00
|
|
|
return;
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
if (cheat_manager_state.ptr == 0)
|
|
|
|
cheat_manager_state.ptr = cheat_manager_state.size - 1;
|
2011-04-17 14:53:19 +00:00
|
|
|
else
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_state.ptr--;
|
2011-04-17 14:53:19 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_update(&cheat_manager_state, cheat_manager_state.ptr);
|
2011-04-17 11:30:59 +00:00
|
|
|
}
|
2015-09-06 01:51:08 +00:00
|
|
|
|
2015-12-01 01:49:27 +00:00
|
|
|
const char *cheat_manager_get_code(unsigned i)
|
2015-09-06 01:51:08 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
if (!cheat_manager_state.cheats)
|
2015-09-06 01:51:08 +00:00
|
|
|
return NULL;
|
2018-07-25 23:19:14 +00:00
|
|
|
return cheat_manager_state.cheats[i].code;
|
2015-09-06 01:51:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-01 02:07:16 +00:00
|
|
|
const char *cheat_manager_get_desc(unsigned i)
|
2015-09-06 01:51:08 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
if (!cheat_manager_state.cheats)
|
2015-09-06 01:51:08 +00:00
|
|
|
return NULL;
|
2018-07-25 23:19:14 +00:00
|
|
|
return cheat_manager_state.cheats[i].desc;
|
2015-09-06 01:51:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-01 01:49:27 +00:00
|
|
|
bool cheat_manager_get_code_state(unsigned i)
|
2015-09-06 01:51:08 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
if (!cheat_manager_state.cheats)
|
2015-09-06 01:51:08 +00:00
|
|
|
return false;
|
2018-07-25 23:19:14 +00:00
|
|
|
return cheat_manager_state.cheats[i].state;
|
|
|
|
}
|
|
|
|
|
2018-07-29 14:48:41 +00:00
|
|
|
bool cheat_manager_get_game_specific_filename(char * cheat_filename, size_t max_length)
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
const char *core_name = NULL;
|
|
|
|
const char *game_name = NULL;
|
|
|
|
struct retro_system_info system_info;
|
|
|
|
|
2018-08-16 19:32:14 +00:00
|
|
|
if (!settings || !global || !cheat_filename)
|
2018-07-29 14:48:41 +00:00
|
|
|
return false ;
|
|
|
|
|
|
|
|
if ( !core_get_system_info(&system_info) )
|
|
|
|
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 ;
|
|
|
|
|
|
|
|
cheat_filename[0] = '\0';
|
2018-08-16 16:53:19 +00:00
|
|
|
strlcat(cheat_filename, settings->paths.path_cheat_database, max_length);
|
|
|
|
fill_pathname_slash(cheat_filename, max_length);
|
|
|
|
strlcat(cheat_filename, core_name, max_length);
|
|
|
|
fill_pathname_slash(cheat_filename, max_length);
|
2018-07-29 14:48:41 +00:00
|
|
|
|
|
|
|
if (!filestream_exists(cheat_filename))
|
|
|
|
path_mkdir(cheat_filename);
|
|
|
|
|
2018-08-16 16:53:19 +00:00
|
|
|
strlcat(cheat_filename, game_name, max_length);
|
2018-07-29 14:48:41 +00:00
|
|
|
|
|
|
|
return true ;
|
|
|
|
|
|
|
|
}
|
2018-07-25 23:19:14 +00:00
|
|
|
void cheat_manager_load_game_specific_cheats()
|
|
|
|
{
|
2018-07-29 14:48:41 +00:00
|
|
|
char cheat_file[PATH_MAX_LENGTH] ;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-07-29 14:48:41 +00:00
|
|
|
if (cheat_manager_get_game_specific_filename(cheat_file, PATH_MAX_LENGTH) )
|
|
|
|
cheat_manager_load(cheat_file,true) ;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
void cheat_manager_save_game_specific_cheats()
|
|
|
|
{
|
2018-07-29 14:48:41 +00:00
|
|
|
char cheat_file[PATH_MAX_LENGTH] ;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-07-29 14:48:41 +00:00
|
|
|
if (cheat_manager_get_game_specific_filename(cheat_file, PATH_MAX_LENGTH) )
|
|
|
|
cheat_manager_save(cheat_file, NULL, true) ;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2015-09-06 01:51:08 +00:00
|
|
|
}
|
2015-12-01 01:43:34 +00:00
|
|
|
|
|
|
|
void cheat_manager_state_free(void)
|
|
|
|
{
|
2015-12-01 02:00:31 +00:00
|
|
|
cheat_manager_free();
|
2015-12-01 01:43:34 +00:00
|
|
|
}
|
2015-12-01 02:07:16 +00:00
|
|
|
|
|
|
|
bool cheat_manager_alloc_if_empty(void)
|
|
|
|
{
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
if (!cheat_manager_state.cheats)
|
2015-12-01 02:07:16 +00:00
|
|
|
{
|
2018-07-25 23:19:14 +00:00
|
|
|
cheat_manager_new(0);
|
2015-12-01 02:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_initialize_memory(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-09-26 13:46:27 +00:00
|
|
|
retro_ctx_memory_info_t meminfo;
|
|
|
|
bool refresh = false;
|
|
|
|
bool is_search_initialization = (setting != NULL);
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-09-26 13:46:27 +00:00
|
|
|
meminfo.id = RETRO_MEMORY_SYSTEM_RAM;
|
|
|
|
if (!core_get_memory(&meminfo))
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_FAIL), 1, 180, true);
|
2018-09-26 13:46:27 +00:00
|
|
|
return 0;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 15:44:37 +00:00
|
|
|
if ( meminfo.size == 0 )
|
|
|
|
{
|
|
|
|
return 0 ;
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
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;
|
|
|
|
cheat_manager_state.num_matches = (cheat_manager_state.total_memory_size*8)/((int)pow(2,cheat_manager_state.search_bit_size));
|
2018-08-04 18:02:33 +00:00
|
|
|
/* Ensure we're aligned on 4-byte boundary */
|
|
|
|
#if 0
|
|
|
|
if (meminfo.size % 4 > 0)
|
2018-09-26 13:46:27 +00:00
|
|
|
cheat_manager_state.total_memory_size = cheat_manager_state.total_memory_size + (4 - (meminfo.size%4));
|
2018-08-04 18:02:33 +00:00
|
|
|
#endif
|
2018-09-26 13:46:27 +00:00
|
|
|
if (is_search_initialization)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-07-30 08:08:50 +00:00
|
|
|
cheat_manager_state.prev_memory_buf = (uint8_t*) calloc(cheat_manager_state.total_memory_size, sizeof(uint8_t));
|
2018-09-26 13:46:27 +00:00
|
|
|
if (!cheat_manager_state.prev_memory_buf)
|
2018-07-30 08:08:50 +00:00
|
|
|
{
|
|
|
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_FAIL), 1, 180, true);
|
2018-09-26 13:46:27 +00:00
|
|
|
return 0;
|
2018-07-30 08:08:50 +00:00
|
|
|
}
|
|
|
|
cheat_manager_state.matches = (uint8_t*) calloc(cheat_manager_state.total_memory_size, sizeof(uint8_t));
|
2018-09-26 13:46:27 +00:00
|
|
|
if (!cheat_manager_state.matches)
|
2018-07-30 08:08:50 +00:00
|
|
|
{
|
2018-09-26 13:46:27 +00:00
|
|
|
free(cheat_manager_state.prev_memory_buf);
|
|
|
|
cheat_manager_state.prev_memory_buf = NULL;
|
2018-07-30 08:08:50 +00:00
|
|
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_FAIL), 1, 180, true);
|
2018-09-26 13:46:27 +00:00
|
|
|
return 0;
|
2018-07-30 08:08:50 +00:00
|
|
|
}
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-09-26 13:46:27 +00:00
|
|
|
memset(cheat_manager_state.matches, 0xFF, cheat_manager_state.total_memory_size);
|
2018-07-30 08:08:50 +00:00
|
|
|
memcpy(cheat_manager_state.prev_memory_buf, cheat_manager_state.curr_memory_buf, cheat_manager_state.actual_memory_size);
|
2018-09-26 13:46:27 +00:00
|
|
|
cheat_manager_state.memory_search_initialized = true;
|
2018-07-30 08:08:50 +00:00
|
|
|
}
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-09-26 13:46:27 +00:00
|
|
|
cheat_manager_state.memory_initialized = true;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-07-30 08:08:50 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_INIT_SUCCESS), 1, 180, true);
|
2018-08-14 09:18:24 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
|
|
|
if (!wraparound)
|
2018-07-28 21:45:33 +00:00
|
|
|
{
|
|
|
|
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
|
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
|
|
|
|
}
|
2018-08-14 09:18:24 +00:00
|
|
|
#endif
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-09-26 13:46:27 +00:00
|
|
|
return 0;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cheat_manager_setup_search_meta(unsigned int bitsize, unsigned int *bytes_per_item, unsigned int *mask, unsigned int *bits)
|
|
|
|
{
|
|
|
|
switch( bitsize)
|
|
|
|
{
|
|
|
|
case 0 :
|
|
|
|
{
|
|
|
|
*bytes_per_item = 1 ;
|
|
|
|
*bits = 1 ;
|
|
|
|
*mask = 0x01 ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
case 1 :
|
|
|
|
{
|
|
|
|
*bytes_per_item = 1 ;
|
|
|
|
*bits = 2 ;
|
|
|
|
*mask = 0x03 ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
case 2 :
|
|
|
|
{
|
|
|
|
*bytes_per_item = 1 ;
|
|
|
|
*bits = 4 ;
|
|
|
|
*mask = 0x0F ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
case 3 :
|
|
|
|
{
|
|
|
|
*bytes_per_item = 1 ;
|
|
|
|
*bits = 8 ;
|
|
|
|
*mask = 0xFF ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
case 4 :
|
|
|
|
{
|
|
|
|
*bytes_per_item = 2 ;
|
|
|
|
*bits = 8 ;
|
|
|
|
*mask = 0xFFFF ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
case 5 :
|
|
|
|
{
|
|
|
|
*bytes_per_item = 4 ;
|
|
|
|
*bits = 8 ;
|
|
|
|
*mask = 0xFFFFFFFF ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_search_exact(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cheat_manager_search(CHEAT_SEARCH_TYPE_EXACT) ;
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_search_lt(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cheat_manager_search(CHEAT_SEARCH_TYPE_LT) ;
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_search_gt(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cheat_manager_search(CHEAT_SEARCH_TYPE_GT) ;
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_search_lte(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cheat_manager_search(CHEAT_SEARCH_TYPE_LTE) ;
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_search_gte(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cheat_manager_search(CHEAT_SEARCH_TYPE_GTE) ;
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_search_eq(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cheat_manager_search(CHEAT_SEARCH_TYPE_EQ) ;
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_search_neq(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cheat_manager_search(CHEAT_SEARCH_TYPE_NEQ) ;
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_search_eqplus(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cheat_manager_search(CHEAT_SEARCH_TYPE_EQPLUS) ;
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_search_eqminus(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
return cheat_manager_search(CHEAT_SEARCH_TYPE_EQMINUS) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cheat_manager_search(enum cheat_search_type search_type)
|
|
|
|
{
|
|
|
|
char msg[100];
|
2018-09-26 13:46:27 +00:00
|
|
|
unsigned char *curr = cheat_manager_state.curr_memory_buf;
|
|
|
|
unsigned char *prev = cheat_manager_state.prev_memory_buf;
|
|
|
|
unsigned int idx = 0;
|
|
|
|
unsigned int curr_val = 0;
|
|
|
|
unsigned int prev_val = 0;
|
|
|
|
unsigned int mask = 0;
|
|
|
|
unsigned int bytes_per_item = 1;
|
|
|
|
unsigned int bits = 8;
|
|
|
|
bool refresh = false;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-08-16 19:32:14 +00:00
|
|
|
if (!cheat_manager_state.curr_memory_buf)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_NOT_INITIALIZED), 1, 180, true);
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cheat_manager_setup_search_meta(cheat_manager_state.search_bit_size, &bytes_per_item, &mask, &bits) ;
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
/* little endian FF000000 = 256 */
|
|
|
|
for (idx = 0 ; idx < cheat_manager_state.total_memory_size ; idx = idx + bytes_per_item)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-07-28 20:11:56 +00:00
|
|
|
unsigned byte_part;
|
|
|
|
|
2018-09-26 13:46:27 +00:00
|
|
|
switch (bytes_per_item)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
case 2 :
|
|
|
|
{
|
|
|
|
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) ;
|
|
|
|
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) ;
|
|
|
|
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) ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
2018-07-28 20:11:56 +00:00
|
|
|
|
|
|
|
for (byte_part = 0 ; byte_part < 8/bits ; byte_part++)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
unsigned int curr_subval = (curr_val >> (byte_part*bits) ) & mask ;
|
|
|
|
unsigned int prev_subval = (prev_val >> (byte_part*bits) ) & mask ;
|
|
|
|
unsigned int prev_match ;
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (bits < 8 )
|
2018-07-25 23:19:14 +00:00
|
|
|
prev_match = *(cheat_manager_state.matches+idx) & (mask << (byte_part*bits)) ;
|
|
|
|
else
|
|
|
|
prev_match = *(cheat_manager_state.matches+idx) ;
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (prev_match > 0)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
bool match = false ;
|
2018-08-07 01:50:10 +00:00
|
|
|
switch (search_type)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
case CHEAT_SEARCH_TYPE_EXACT :
|
|
|
|
match = ( curr_subval == cheat_manager_state.search_exact_value) ;
|
|
|
|
break;
|
|
|
|
case CHEAT_SEARCH_TYPE_LT :
|
|
|
|
match = ( curr_subval < prev_subval) ;
|
|
|
|
break;
|
|
|
|
case CHEAT_SEARCH_TYPE_GT :
|
|
|
|
match = ( curr_subval > prev_subval) ;
|
|
|
|
break;
|
|
|
|
case CHEAT_SEARCH_TYPE_LTE :
|
|
|
|
match = ( curr_subval <= prev_subval) ;
|
|
|
|
break;
|
|
|
|
case CHEAT_SEARCH_TYPE_GTE :
|
|
|
|
match = ( curr_subval >= prev_subval) ;
|
|
|
|
break;
|
|
|
|
case CHEAT_SEARCH_TYPE_EQ :
|
|
|
|
match = ( curr_subval == prev_subval) ;
|
|
|
|
break;
|
|
|
|
case CHEAT_SEARCH_TYPE_NEQ :
|
|
|
|
match = ( curr_subval != prev_subval) ;
|
|
|
|
break;
|
|
|
|
case CHEAT_SEARCH_TYPE_EQPLUS :
|
|
|
|
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) ;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!match )
|
|
|
|
{
|
|
|
|
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) ;
|
|
|
|
if ( cheat_manager_state.num_matches > 0 )
|
|
|
|
cheat_manager_state.num_matches-- ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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) ;
|
|
|
|
msg[sizeof(msg) - 1] = 0;
|
|
|
|
|
|
|
|
runloop_msg_queue_push(msg, 1, 180, true);
|
|
|
|
|
2018-08-14 09:18:24 +00:00
|
|
|
#ifdef HAVE_MENU
|
2018-07-25 23:19:14 +00:00
|
|
|
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
|
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
|
2018-08-14 09:18:24 +00:00
|
|
|
#endif
|
2018-07-25 23:19:14 +00:00
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cheat_manager_add_new_code(unsigned int memory_search_size, unsigned int address, unsigned int address_mask,
|
|
|
|
bool big_endian, unsigned int value)
|
|
|
|
{
|
|
|
|
int new_size = cheat_manager_get_size() + 1;
|
|
|
|
|
|
|
|
if ( !cheat_manager_realloc(new_size, CHEAT_HANDLER_TYPE_RETRO) )
|
|
|
|
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 ;
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
int cheat_manager_add_matches(const char *path,
|
|
|
|
const char *label, unsigned type, size_t menuidx, size_t entry_idx)
|
|
|
|
{
|
|
|
|
char msg[100];
|
2018-07-28 20:11:56 +00:00
|
|
|
bool refresh = false;
|
|
|
|
unsigned byte_part = 0;
|
|
|
|
unsigned int idx = 0;
|
|
|
|
unsigned int mask = 0;
|
|
|
|
unsigned int bytes_per_item = 1;
|
|
|
|
unsigned int bits = 8;
|
|
|
|
unsigned int curr_val = 0;
|
|
|
|
unsigned int num_added = 0;
|
|
|
|
unsigned char *curr = cheat_manager_state.curr_memory_buf;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
|
|
|
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 ;
|
|
|
|
}
|
|
|
|
cheat_manager_setup_search_meta(cheat_manager_state.search_bit_size, &bytes_per_item, &mask, &bits) ;
|
|
|
|
|
2018-07-28 20:11:56 +00:00
|
|
|
for (idx = 0 ; idx < cheat_manager_state.total_memory_size ; idx = idx + bytes_per_item)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
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 ;
|
|
|
|
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 ;
|
|
|
|
case 1 :
|
|
|
|
default :
|
|
|
|
curr_val = *(curr+idx) ;
|
|
|
|
break ;
|
|
|
|
}
|
2018-07-28 20:11:56 +00:00
|
|
|
for (byte_part = 0 ; byte_part < 8/bits ; byte_part++)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-07-28 20:11:56 +00:00
|
|
|
unsigned int prev_match;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (bits < 8 )
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
prev_match = *(cheat_manager_state.matches+idx) & (mask << (byte_part*bits)) ;
|
2018-08-07 01:50:10 +00:00
|
|
|
if (prev_match)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!cheat_manager_add_new_code(cheat_manager_state.search_bit_size, idx, (mask << (byte_part*bits)),
|
2018-07-25 23:19:14 +00:00
|
|
|
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 ;
|
|
|
|
}
|
|
|
|
num_added++ ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev_match = *(cheat_manager_state.matches+idx) ;
|
2018-08-07 01:50:10 +00:00
|
|
|
if (prev_match)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!cheat_manager_add_new_code(cheat_manager_state.search_bit_size, idx, 0xFF,
|
|
|
|
cheat_manager_state.big_endian, curr_val))
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_ADDED_MATCHES_FAIL), 1, 180, true);
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
num_added++ ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-08-14 09:18:24 +00:00
|
|
|
#ifdef HAVE_MENU
|
2018-07-25 23:19:14 +00:00
|
|
|
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
|
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
|
2018-08-14 09:18:24 +00:00
|
|
|
#endif
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-08-14 09:18:24 +00:00
|
|
|
return 0;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cheat_manager_apply_rumble(struct item_cheat *cheat, unsigned int curr_value)
|
|
|
|
{
|
2018-08-14 09:18:24 +00:00
|
|
|
bool rumble = false;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
switch (cheat->rumble_type)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-14 09:18:24 +00:00
|
|
|
case RUMBLE_TYPE_DISABLED:
|
2018-08-07 01:50:10 +00:00
|
|
|
return;
|
2018-07-25 23:19:14 +00:00
|
|
|
case RUMBLE_TYPE_CHANGES:
|
|
|
|
rumble = (curr_value != cheat->rumble_prev_value) ;
|
|
|
|
break ;
|
|
|
|
case RUMBLE_TYPE_DOES_NOT_CHANGE:
|
|
|
|
rumble = (curr_value == cheat->rumble_prev_value) ;
|
|
|
|
break ;
|
|
|
|
case RUMBLE_TYPE_INCREASE:
|
|
|
|
rumble = (curr_value > cheat->rumble_prev_value) ;
|
|
|
|
break ;
|
|
|
|
case RUMBLE_TYPE_DECREASE:
|
|
|
|
rumble = (curr_value < cheat->rumble_prev_value) ;
|
|
|
|
break ;
|
|
|
|
case RUMBLE_TYPE_EQ_VALUE:
|
|
|
|
rumble = (curr_value == cheat->rumble_value) ;
|
|
|
|
break ;
|
|
|
|
case RUMBLE_TYPE_NEQ_VALUE:
|
|
|
|
rumble = (curr_value != cheat->rumble_value) ;
|
|
|
|
break ;
|
|
|
|
case RUMBLE_TYPE_LT_VALUE:
|
|
|
|
rumble = (curr_value < cheat->rumble_value) ;
|
|
|
|
break ;
|
|
|
|
case RUMBLE_TYPE_GT_VALUE:
|
|
|
|
rumble = (curr_value > cheat->rumble_value) ;
|
2018-08-14 09:18:24 +00:00
|
|
|
break;
|
2018-09-18 21:04:22 +00:00
|
|
|
case RUMBLE_TYPE_INCREASE_BY_VALUE:
|
|
|
|
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 ;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cheat->rumble_prev_value = curr_value ;
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
/* Give the emulator enough time
|
|
|
|
* to initialize, load state, etc */
|
|
|
|
if (cheat->rumble_initialized > 300)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
if (rumble)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
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++ ;
|
2018-08-07 01:50:10 +00:00
|
|
|
return;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (cheat->rumble_primary_end_time <= cpu_features_get_time_usec() )
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
if (cheat->rumble_primary_end_time != 0)
|
2018-07-25 23:19:14 +00:00
|
|
|
input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_STRONG, 0);
|
|
|
|
cheat->rumble_primary_end_time = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_STRONG, cheat->rumble_primary_strength);
|
|
|
|
}
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (cheat->rumble_secondary_end_time <= cpu_features_get_time_usec())
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
if (cheat->rumble_secondary_end_time != 0)
|
2018-07-25 23:19:14 +00:00
|
|
|
input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_WEAK, 0);
|
|
|
|
cheat->rumble_secondary_end_time = 0 ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
input_driver_set_rumble_state(cheat->rumble_port, RETRO_RUMBLE_WEAK, cheat->rumble_secondary_strength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-28 20:11:56 +00:00
|
|
|
void cheat_manager_apply_retro_cheats(void)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-07-28 20:11:56 +00:00
|
|
|
unsigned i;
|
|
|
|
unsigned int mask = 0;
|
|
|
|
unsigned int bytes_per_item = 1;
|
|
|
|
unsigned int bits = 8;
|
|
|
|
unsigned int curr_val = 0;
|
|
|
|
bool run_cheat = true;
|
|
|
|
|
|
|
|
if ((!cheat_manager_state.cheats))
|
|
|
|
return;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-07-28 20:11:56 +00:00
|
|
|
for (i = 0 ; i < cheat_manager_state.size ; i++ )
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-07-28 20:11:56 +00:00
|
|
|
unsigned char *curr;
|
|
|
|
unsigned int idx;
|
|
|
|
bool set_value = false;
|
|
|
|
unsigned int value_to_set = 0;
|
2018-09-29 18:52:10 +00:00
|
|
|
unsigned int repeat_iter = 0 ;
|
|
|
|
unsigned int address_mask = cheat_manager_state.cheats[i].address_mask ;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
|
|
|
if (cheat_manager_state.cheats[i].handler != CHEAT_HANDLER_TYPE_RETRO || !cheat_manager_state.cheats[i].state)
|
|
|
|
continue ;
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!cheat_manager_state.memory_initialized)
|
2018-07-30 08:08:50 +00:00
|
|
|
cheat_manager_initialize_memory(NULL, false) ;
|
2018-07-28 20:11:56 +00:00
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
/* If we're still not initialized, something
|
|
|
|
* must have gone wrong - just bail */
|
|
|
|
if (!cheat_manager_state.memory_initialized)
|
2018-07-28 20:11:56 +00:00
|
|
|
return;
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!run_cheat)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
run_cheat = true ;
|
|
|
|
continue ;
|
|
|
|
}
|
|
|
|
cheat_manager_setup_search_meta(cheat_manager_state.cheats[i].memory_search_size, &bytes_per_item, &mask, &bits) ;
|
2018-07-28 20:11:56 +00:00
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
curr = cheat_manager_state.curr_memory_buf ;
|
2018-07-28 20:11:56 +00:00
|
|
|
idx = cheat_manager_state.cheats[i].address ;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
switch (bytes_per_item)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
case 2 :
|
|
|
|
{
|
|
|
|
curr_val = cheat_manager_state.big_endian ?
|
|
|
|
(*(curr+idx)*256) + *(curr+idx+1) :
|
|
|
|
*(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 ;
|
|
|
|
}
|
|
|
|
case 1 :
|
|
|
|
default :
|
|
|
|
{
|
|
|
|
curr_val = *(curr+idx) ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cheat_manager_apply_rumble(&cheat_manager_state.cheats[i], curr_val) ;
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
switch (cheat_manager_state.cheats[i].cheat_type )
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
case CHEAT_TYPE_SET_TO_VALUE :
|
|
|
|
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 ;
|
|
|
|
break;
|
|
|
|
case CHEAT_TYPE_DECREASE_VALUE:
|
|
|
|
set_value = true ;
|
|
|
|
value_to_set = curr_val - cheat_manager_state.cheats[i].value ;
|
|
|
|
break;
|
|
|
|
case CHEAT_TYPE_RUN_NEXT_IF_EQ:
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!(curr_val == cheat_manager_state.cheats[i].value))
|
2018-07-25 23:19:14 +00:00
|
|
|
run_cheat = false ;
|
|
|
|
break;
|
|
|
|
case CHEAT_TYPE_RUN_NEXT_IF_NEQ:
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!(curr_val != cheat_manager_state.cheats[i].value ))
|
2018-07-25 23:19:14 +00:00
|
|
|
run_cheat = false ;
|
|
|
|
break;
|
|
|
|
case CHEAT_TYPE_RUN_NEXT_IF_LT:
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!(cheat_manager_state.cheats[i].value < curr_val))
|
2018-07-25 23:19:14 +00:00
|
|
|
run_cheat = false ;
|
|
|
|
break;
|
|
|
|
case CHEAT_TYPE_RUN_NEXT_IF_GT:
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!(cheat_manager_state.cheats[i].value > curr_val))
|
2018-07-25 23:19:14 +00:00
|
|
|
run_cheat = false ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2018-08-07 01:50:10 +00:00
|
|
|
if (set_value)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-09-29 18:52:10 +00:00
|
|
|
for ( repeat_iter = 1 ; repeat_iter <= cheat_manager_state.cheats[i].repeat_count ; repeat_iter++)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-09-29 18:52:10 +00:00
|
|
|
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 ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*(curr+idx) = value_to_set & 0xFF ;
|
|
|
|
*(curr+idx+1) = (value_to_set >> 8) & 0xFF ;
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2018-09-29 18:52:10 +00:00
|
|
|
}
|
|
|
|
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 ;
|
|
|
|
}
|
|
|
|
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 ;
|
2018-07-28 20:11:56 +00:00
|
|
|
|
2018-09-29 18:52:10 +00:00
|
|
|
}
|
|
|
|
break ;
|
|
|
|
case 1 :
|
|
|
|
if (bits < 8)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-09-29 18:52:10 +00:00
|
|
|
unsigned bitpos;
|
|
|
|
unsigned char val = *(curr+idx);
|
|
|
|
|
|
|
|
for (bitpos = 0 ; bitpos < 8 ; bitpos++)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-09-29 18:52:10 +00:00
|
|
|
if ((address_mask>>bitpos)&0x01 )
|
|
|
|
{
|
|
|
|
mask = (~(1<<bitpos)&0xFF) ;
|
|
|
|
/* Clear current bit value */
|
|
|
|
val = val & mask ;
|
|
|
|
/* Inject cheat bit value */
|
|
|
|
val = val | (((value_to_set>>bitpos)&0x01)<<bitpos) ;
|
|
|
|
}
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
2018-09-29 18:52:10 +00:00
|
|
|
*(curr+idx) = val ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*(curr+idx) = value_to_set & 0xFF;
|
|
|
|
break ;
|
|
|
|
default :
|
|
|
|
*(curr+idx) = value_to_set & 0xFF ;
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
value_to_set += cheat_manager_state.cheats[i].repeat_add_to_value ;
|
|
|
|
value_to_set = value_to_set%mask ;
|
|
|
|
|
|
|
|
if ( bits < 8 )
|
|
|
|
{
|
|
|
|
unsigned int bit_iter ;
|
|
|
|
for ( bit_iter = 0 ; bit_iter < cheat_manager_state.cheats[i].repeat_add_to_address ; bit_iter++)
|
|
|
|
{
|
|
|
|
address_mask = (address_mask<<mask)&0xFF ;
|
|
|
|
if ( address_mask == 0 )
|
|
|
|
{
|
|
|
|
address_mask = mask ;
|
|
|
|
idx++ ;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-29 18:52:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx += (cheat_manager_state.cheats[i].repeat_add_to_address*bytes_per_item) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = idx%cheat_manager_state.total_memory_size ;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void cheat_manager_match_action(enum cheat_match_action_type match_action, unsigned int target_match_idx, unsigned int *address, unsigned int *address_mask,
|
|
|
|
unsigned int *prev_value, unsigned int *curr_value)
|
|
|
|
{
|
2018-07-28 20:11:56 +00:00
|
|
|
unsigned int byte_part;
|
|
|
|
unsigned int idx;
|
2018-08-03 18:59:33 +00:00
|
|
|
unsigned int start_idx;
|
2018-07-25 23:19:14 +00:00
|
|
|
unsigned int mask = 0 ;
|
|
|
|
unsigned int bytes_per_item = 1 ;
|
|
|
|
unsigned int bits = 8 ;
|
|
|
|
unsigned int curr_val = 0 ;
|
|
|
|
unsigned int prev_val = 0 ;
|
|
|
|
unsigned char *curr = cheat_manager_state.curr_memory_buf ;
|
|
|
|
unsigned char *prev = cheat_manager_state.prev_memory_buf ;
|
|
|
|
unsigned int curr_match_idx = 0;
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (target_match_idx > cheat_manager_state.num_matches-1)
|
2018-07-29 17:04:53 +00:00
|
|
|
return;
|
2018-07-28 20:11:56 +00:00
|
|
|
|
2018-08-16 19:32:14 +00:00
|
|
|
if (!curr)
|
|
|
|
return;
|
2018-08-03 18:59:33 +00:00
|
|
|
|
2018-07-28 20:11:56 +00:00
|
|
|
cheat_manager_setup_search_meta(cheat_manager_state.search_bit_size, &bytes_per_item, &mask, &bits);
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (match_action == CHEAT_MATCH_ACTION_TYPE_BROWSE)
|
2018-08-03 18:59:33 +00:00
|
|
|
start_idx = *address ;
|
|
|
|
else
|
|
|
|
start_idx = 0 ;
|
|
|
|
|
|
|
|
for (idx = start_idx ; idx < cheat_manager_state.total_memory_size ; idx = idx + bytes_per_item)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
switch (bytes_per_item )
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
case 2 :
|
|
|
|
curr_val = cheat_manager_state.big_endian ?
|
|
|
|
(*(curr+idx)*256) + *(curr+idx+1) :
|
|
|
|
*(curr+idx) + (*(curr+idx+1)*256) ;
|
2018-08-07 01:50:10 +00:00
|
|
|
if (prev != NULL)
|
2018-08-03 18:59:33 +00:00
|
|
|
prev_val = cheat_manager_state.big_endian ?
|
|
|
|
(*(prev+idx)*256) + *(prev+idx+1) :
|
|
|
|
*(prev+idx) + (*(prev+idx+1)*256) ;
|
2018-07-25 23:19:14 +00:00
|
|
|
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) ;
|
2018-08-07 01:50:10 +00:00
|
|
|
if (prev != NULL)
|
2018-08-03 18:59:33 +00:00
|
|
|
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) ;
|
2018-07-25 23:19:14 +00:00
|
|
|
break ;
|
|
|
|
case 1 :
|
|
|
|
default :
|
|
|
|
curr_val = *(curr+idx) ;
|
2018-08-07 01:50:10 +00:00
|
|
|
if (prev != NULL)
|
2018-08-03 18:59:33 +00:00
|
|
|
prev_val = *(prev+idx) ;
|
2018-07-25 23:19:14 +00:00
|
|
|
break ;
|
|
|
|
}
|
2018-08-03 18:59:33 +00:00
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (match_action == CHEAT_MATCH_ACTION_TYPE_BROWSE)
|
2018-08-03 18:59:33 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
*curr_value = curr_val;
|
|
|
|
*prev_value = prev_val;
|
2018-08-03 18:59:33 +00:00
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!prev)
|
|
|
|
return;
|
2018-08-03 18:59:33 +00:00
|
|
|
|
2018-07-28 20:11:56 +00:00
|
|
|
for (byte_part = 0 ; byte_part < 8/bits ; byte_part++)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
unsigned int prev_match ;
|
|
|
|
|
2018-08-07 01:50:10 +00:00
|
|
|
if (bits < 8 )
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
|
|
|
prev_match = *(cheat_manager_state.matches+idx) & (mask << (byte_part*bits)) ;
|
2018-08-07 01:50:10 +00:00
|
|
|
if (prev_match)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
if (target_match_idx == curr_match_idx)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
switch (match_action)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-03 18:59:33 +00:00
|
|
|
case CHEAT_MATCH_ACTION_TYPE_BROWSE :
|
|
|
|
return ;
|
2018-07-25 23:19:14 +00:00
|
|
|
case CHEAT_MATCH_ACTION_TYPE_VIEW :
|
|
|
|
*address = idx ;
|
|
|
|
*address_mask = (mask << (byte_part*bits)) ;
|
|
|
|
*curr_value = curr_val ;
|
|
|
|
*prev_value = prev_val ;
|
2018-08-07 01:50:10 +00:00
|
|
|
return;
|
2018-07-25 23:19:14 +00:00
|
|
|
case CHEAT_MATCH_ACTION_TYPE_COPY :
|
2018-08-07 01:50:10 +00:00
|
|
|
if (!cheat_manager_add_new_code(cheat_manager_state.search_bit_size, idx, (mask << (byte_part*bits)),
|
|
|
|
cheat_manager_state.big_endian, curr_val) )
|
2018-07-25 23:19:14 +00:00
|
|
|
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 ;
|
|
|
|
case CHEAT_MATCH_ACTION_TYPE_DELETE :
|
2018-08-07 01:50:10 +00:00
|
|
|
if (bits < 8)
|
2018-07-25 23:19:14 +00:00
|
|
|
*(cheat_manager_state.matches+idx) = *(cheat_manager_state.matches+idx) &
|
2018-08-07 01:50:10 +00:00
|
|
|
(( ~(mask << (byte_part*bits))) & 0xFF );
|
2018-07-25 23:19:14 +00:00
|
|
|
else
|
|
|
|
memset(cheat_manager_state.matches+idx,0,bytes_per_item) ;
|
|
|
|
if ( cheat_manager_state.num_matches > 0 )
|
|
|
|
cheat_manager_state.num_matches-- ;
|
|
|
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_DELETE_MATCH_SUCCESS), 1, 180, true);
|
2018-08-07 01:50:10 +00:00
|
|
|
return;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
2018-08-07 01:50:10 +00:00
|
|
|
return;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|
|
|
|
curr_match_idx++ ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev_match = *(cheat_manager_state.matches+idx) ;
|
2018-08-07 01:50:10 +00:00
|
|
|
if (prev_match)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
if (target_match_idx == curr_match_idx)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-07 01:50:10 +00:00
|
|
|
switch (match_action)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-03 18:59:33 +00:00
|
|
|
case CHEAT_MATCH_ACTION_TYPE_BROWSE :
|
|
|
|
return ;
|
2018-07-25 23:19:14 +00:00
|
|
|
case CHEAT_MATCH_ACTION_TYPE_VIEW :
|
|
|
|
*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,
|
2018-08-07 01:50:10 +00:00
|
|
|
cheat_manager_state.big_endian, curr_val) )
|
2018-07-25 23:19:14 +00:00
|
|
|
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 ;
|
|
|
|
case CHEAT_MATCH_ACTION_TYPE_DELETE :
|
|
|
|
if ( bits < 8 )
|
|
|
|
*(cheat_manager_state.matches+idx) = *(cheat_manager_state.matches+idx) &
|
2018-08-07 01:50:10 +00:00
|
|
|
(( ~(mask << (byte_part*bits))) & 0xFF );
|
2018-07-25 23:19:14 +00:00
|
|
|
else
|
|
|
|
memset(cheat_manager_state.matches+idx,0,bytes_per_item) ;
|
|
|
|
if ( cheat_manager_state.num_matches > 0 )
|
|
|
|
cheat_manager_state.num_matches-- ;
|
|
|
|
runloop_msg_queue_push(msg_hash_to_str(MSG_CHEAT_SEARCH_DELETE_MATCH_SUCCESS), 1, 180, true);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr_match_idx++ ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_copy_match(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-07-28 20:11:56 +00:00
|
|
|
cheat_manager_match_action(CHEAT_MATCH_ACTION_TYPE_COPY,
|
|
|
|
cheat_manager_state.match_idx, NULL, NULL, NULL, NULL) ;
|
2018-07-25 23:19:14 +00:00
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
|
2018-09-26 13:46:27 +00:00
|
|
|
int cheat_manager_delete_match(rarch_setting_t *setting, bool wraparound)
|
2018-07-25 23:19:14 +00:00
|
|
|
{
|
2018-08-14 09:18:24 +00:00
|
|
|
bool refresh = false;
|
2018-07-28 20:11:56 +00:00
|
|
|
cheat_manager_match_action(CHEAT_MATCH_ACTION_TYPE_DELETE,
|
2018-08-14 09:18:24 +00:00
|
|
|
cheat_manager_state.match_idx, NULL, NULL, NULL, NULL);
|
|
|
|
#ifdef HAVE_MENU
|
2018-07-25 23:19:14 +00:00
|
|
|
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
|
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
|
2018-08-14 09:18:24 +00:00
|
|
|
#endif
|
|
|
|
return 0;
|
2018-07-25 23:19:14 +00:00
|
|
|
}
|