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
|
2017-12-12 07:55:31 +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/>.
|
|
|
|
*/
|
|
|
|
|
2016-05-09 18:05:09 +00:00
|
|
|
#ifndef __CHEAT_MANAGER_H
|
|
|
|
#define __CHEAT_MANAGER_H
|
2011-04-17 11:30:59 +00:00
|
|
|
|
2014-12-06 14:47:25 +00:00
|
|
|
#include <boolean.h>
|
2016-06-03 03:49:46 +00:00
|
|
|
#include <retro_common_api.h>
|
2014-12-06 14:47:25 +00:00
|
|
|
|
2018-09-26 16:48:30 +00:00
|
|
|
#include "../setting_list.h"
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2016-06-03 03:49:46 +00:00
|
|
|
RETRO_BEGIN_DECLS
|
2014-11-29 20:18:45 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
enum cheat_handler_type
|
|
|
|
{
|
|
|
|
CHEAT_HANDLER_TYPE_EMU = 0,
|
|
|
|
CHEAT_HANDLER_TYPE_RETRO,
|
|
|
|
CHEAT_HANDLER_TYPE_END
|
|
|
|
};
|
|
|
|
|
|
|
|
enum cheat_type
|
|
|
|
{
|
|
|
|
CHEAT_TYPE_DISABLED = 0,
|
|
|
|
CHEAT_TYPE_SET_TO_VALUE,
|
|
|
|
CHEAT_TYPE_INCREASE_VALUE,
|
|
|
|
CHEAT_TYPE_DECREASE_VALUE,
|
|
|
|
CHEAT_TYPE_RUN_NEXT_IF_EQ,
|
|
|
|
CHEAT_TYPE_RUN_NEXT_IF_NEQ,
|
|
|
|
CHEAT_TYPE_RUN_NEXT_IF_LT,
|
|
|
|
CHEAT_TYPE_RUN_NEXT_IF_GT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum cheat_search_type
|
|
|
|
{
|
|
|
|
CHEAT_SEARCH_TYPE_EXACT = 0,
|
|
|
|
CHEAT_SEARCH_TYPE_LT,
|
|
|
|
CHEAT_SEARCH_TYPE_LTE,
|
|
|
|
CHEAT_SEARCH_TYPE_GT,
|
|
|
|
CHEAT_SEARCH_TYPE_GTE,
|
|
|
|
CHEAT_SEARCH_TYPE_EQ,
|
|
|
|
CHEAT_SEARCH_TYPE_NEQ,
|
|
|
|
CHEAT_SEARCH_TYPE_EQPLUS,
|
2018-07-31 23:27:30 +00:00
|
|
|
CHEAT_SEARCH_TYPE_EQMINUS
|
2018-07-25 23:19:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum cheat_match_action_type
|
|
|
|
{
|
|
|
|
CHEAT_MATCH_ACTION_TYPE_VIEW = 0,
|
|
|
|
CHEAT_MATCH_ACTION_TYPE_DELETE,
|
2018-08-03 18:59:33 +00:00
|
|
|
CHEAT_MATCH_ACTION_TYPE_COPY,
|
|
|
|
CHEAT_MATCH_ACTION_TYPE_BROWSE
|
2018-07-25 23:19:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum cheat_rumble_type
|
|
|
|
{
|
|
|
|
RUMBLE_TYPE_DISABLED = 0,
|
|
|
|
RUMBLE_TYPE_CHANGES,
|
|
|
|
RUMBLE_TYPE_DOES_NOT_CHANGE,
|
|
|
|
RUMBLE_TYPE_INCREASE,
|
|
|
|
RUMBLE_TYPE_DECREASE,
|
|
|
|
RUMBLE_TYPE_EQ_VALUE,
|
|
|
|
RUMBLE_TYPE_NEQ_VALUE,
|
|
|
|
RUMBLE_TYPE_LT_VALUE,
|
2018-09-18 21:04:22 +00:00
|
|
|
RUMBLE_TYPE_GT_VALUE,
|
|
|
|
RUMBLE_TYPE_INCREASE_BY_VALUE,
|
2018-10-11 01:26:58 +00:00
|
|
|
RUMBLE_TYPE_DECREASE_BY_VALUE,
|
|
|
|
RUMBLE_TYPE_END_LIST
|
2018-07-25 23:19:14 +00:00
|
|
|
};
|
|
|
|
|
2018-09-23 19:25:51 +00:00
|
|
|
/* Some codes are ridiculously large - over 10000 bytes */
|
|
|
|
#define CHEAT_CODE_SCRATCH_SIZE 16*1024
|
2018-08-04 17:05:05 +00:00
|
|
|
#define CHEAT_DESC_SCRATCH_SIZE 255
|
2018-07-25 23:19:14 +00:00
|
|
|
|
|
|
|
struct item_cheat
|
|
|
|
{
|
2020-08-15 16:30:27 +00:00
|
|
|
/* Clock value for when rumbling should stop */
|
2024-10-02 00:36:33 +00:00
|
|
|
retro_time_t rumble_primary_end_time;
|
|
|
|
retro_time_t rumble_secondary_end_time;
|
2020-08-15 16:30:27 +00:00
|
|
|
|
2018-08-04 17:05:05 +00:00
|
|
|
char *desc;
|
|
|
|
char *code;
|
2020-08-15 16:30:27 +00:00
|
|
|
|
|
|
|
unsigned int idx;
|
2019-08-10 12:23:00 +00:00
|
|
|
unsigned int handler;
|
2018-07-25 23:19:14 +00:00
|
|
|
/* Number of bits = 2^memory_search_size
|
|
|
|
* 0=1, 1=2, 2=4, 3=8, 4=16, 5=32
|
|
|
|
*/
|
2019-08-10 12:23:00 +00:00
|
|
|
unsigned int memory_search_size;
|
|
|
|
unsigned int cheat_type;
|
|
|
|
unsigned int value;
|
|
|
|
unsigned int address;
|
2018-07-25 23:19:14 +00:00
|
|
|
/*
|
|
|
|
* address_mask used when memory_search_size <8 bits
|
|
|
|
* if memory_search_size=0, then the number of bits is 1 and this value can be one of the following:
|
|
|
|
* 0 : 00000001
|
|
|
|
* 1 : 00000010
|
|
|
|
* 2 : 00000100
|
|
|
|
* 3 : 00001000
|
|
|
|
* 4 : 00010000
|
|
|
|
* 5 : 00100000
|
|
|
|
* 6 : 01000000
|
|
|
|
* 7 : 10000000
|
|
|
|
* if memory_search_size=1, then the number of bits is 2 and this value can be one of the following:
|
|
|
|
* 0 : 00000011
|
|
|
|
* 1 : 00001100
|
|
|
|
* 2 : 00110000
|
|
|
|
* 3 : 11000000
|
|
|
|
* if memory_search_size=2, then the number of bits is 4 and this value can be one of the following:
|
|
|
|
* 0 : 00001111
|
|
|
|
* 1 : 11110000
|
|
|
|
*/
|
2019-08-10 12:23:00 +00:00
|
|
|
unsigned int address_mask;
|
|
|
|
unsigned int rumble_type;
|
|
|
|
unsigned int rumble_value;
|
|
|
|
unsigned int rumble_prev_value;
|
|
|
|
unsigned int rumble_initialized;
|
2020-08-15 16:30:27 +00:00
|
|
|
/* 0-15 for specific port, anything else means "all ports" */
|
2024-10-02 00:36:33 +00:00
|
|
|
unsigned int rumble_port;
|
2019-08-10 12:23:00 +00:00
|
|
|
unsigned int rumble_primary_strength; /* 0-65535 */
|
|
|
|
unsigned int rumble_primary_duration; /* in milliseconds */
|
|
|
|
unsigned int rumble_secondary_strength; /* 0-65535 */
|
|
|
|
unsigned int rumble_secondary_duration; /* in milliseconds */
|
2018-09-29 18:52:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The repeat_ variables allow for a single cheat code to affect multiple memory addresses.
|
|
|
|
* repeat_count - the number of times the cheat code should be applied
|
|
|
|
* repeat_add_to_value - every iteration of repeat_count will have this amount added to item_cheat.value
|
|
|
|
* repeat_add_to_address - every iteration of repeat_count will have this amount added to item_cheat.address
|
|
|
|
*
|
|
|
|
* Note that repeat_add_to_address represents the number of "memory_search_size" blocks to add to
|
2024-10-02 00:36:33 +00:00
|
|
|
* item_cheat.address. If memory_search_size is 16-bits and repeat_add_to_address is 2, then item_cheat.address
|
2018-09-29 18:52:10 +00:00
|
|
|
* will be increased by 4 bytes 2*(16-bits) for every iteration.
|
|
|
|
*
|
|
|
|
* This is a cheating structure used for codes like unlocking all levels, giving yourself 1 of every item,etc.
|
|
|
|
*/
|
2019-08-10 12:23:00 +00:00
|
|
|
unsigned int repeat_count;
|
|
|
|
unsigned int repeat_add_to_value;
|
|
|
|
unsigned int repeat_add_to_address;
|
2018-09-29 18:52:10 +00:00
|
|
|
|
2020-08-15 16:30:27 +00:00
|
|
|
bool state;
|
|
|
|
/* Whether to apply the cheat based on big-endian console memory or not */
|
|
|
|
bool big_endian;
|
2018-07-25 23:19:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cheat_manager
|
|
|
|
{
|
2020-08-15 16:30:27 +00:00
|
|
|
struct item_cheat working_cheat; /* retro_time_t alignment */
|
2018-07-25 23:19:14 +00:00
|
|
|
struct item_cheat *cheats;
|
2019-08-10 12:23:00 +00:00
|
|
|
uint8_t *curr_memory_buf;
|
|
|
|
uint8_t *prev_memory_buf;
|
|
|
|
uint8_t *matches;
|
|
|
|
uint8_t **memory_buf_list;
|
|
|
|
unsigned *memory_size_list;
|
2020-08-15 16:30:27 +00:00
|
|
|
unsigned int delete_state;
|
|
|
|
unsigned int loading_cheat_size;
|
|
|
|
unsigned int loading_cheat_offset;
|
|
|
|
unsigned ptr;
|
|
|
|
unsigned size;
|
|
|
|
unsigned buf_size;
|
|
|
|
unsigned total_memory_size;
|
2019-08-10 12:23:00 +00:00
|
|
|
unsigned num_memory_buffers;
|
|
|
|
unsigned match_idx;
|
|
|
|
unsigned match_action;
|
|
|
|
unsigned search_bit_size;
|
|
|
|
unsigned dummy;
|
|
|
|
unsigned search_exact_value;
|
|
|
|
unsigned search_eqplus_value;
|
|
|
|
unsigned search_eqminus_value;
|
|
|
|
unsigned num_matches;
|
2018-08-03 18:59:33 +00:00
|
|
|
unsigned browse_address;
|
2019-08-10 12:23:00 +00:00
|
|
|
char working_desc[CHEAT_DESC_SCRATCH_SIZE];
|
|
|
|
char working_code[CHEAT_CODE_SCRATCH_SIZE];
|
2020-08-15 16:30:27 +00:00
|
|
|
bool big_endian;
|
|
|
|
bool memory_initialized;
|
|
|
|
bool memory_search_initialized;
|
2018-07-25 23:19:14 +00:00
|
|
|
};
|
|
|
|
|
2011-04-17 11:30:59 +00:00
|
|
|
typedef struct cheat_manager cheat_manager_t;
|
|
|
|
|
2019-01-12 20:16:48 +00:00
|
|
|
extern cheat_manager_t cheat_manager_state;
|
2018-07-25 23:19:14 +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
|
|
|
bool cheat_manager_load(const char *path, bool append);
|
2014-12-06 14:47:25 +00:00
|
|
|
|
2015-01-19 18:00:26 +00:00
|
|
|
/**
|
|
|
|
* cheat_manager_save:
|
|
|
|
* @path : Path to cheats file (absolute path).
|
|
|
|
*
|
|
|
|
* Saves cheats to file on disk.
|
|
|
|
*
|
|
|
|
* Returns: true (1) if successful, otherwise false (0).
|
|
|
|
**/
|
2019-09-16 15:04:58 +00:00
|
|
|
bool cheat_manager_save(const char *path,
|
|
|
|
const char *cheat_database, bool overwrite);
|
2015-01-19 18:00:26 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
bool cheat_manager_realloc(unsigned new_size, unsigned default_handler);
|
2014-09-07 03:47:18 +00:00
|
|
|
|
2015-12-01 01:55:07 +00:00
|
|
|
void cheat_manager_set_code(unsigned index, const char *str);
|
2015-09-06 01:51:08 +00:00
|
|
|
|
2017-05-21 11:14:21 +00:00
|
|
|
void cheat_manager_index_next(void);
|
2014-09-07 03:47:18 +00:00
|
|
|
|
2017-05-21 11:14:21 +00:00
|
|
|
void cheat_manager_index_prev(void);
|
2014-09-07 03:47:18 +00:00
|
|
|
|
2017-05-21 11:14:21 +00:00
|
|
|
void cheat_manager_toggle(void);
|
2011-04-17 11:30:59 +00:00
|
|
|
|
2015-12-01 01:43:34 +00:00
|
|
|
void cheat_manager_apply_cheats(void);
|
2014-12-06 14:47:25 +00:00
|
|
|
|
2014-12-16 04:14:22 +00:00
|
|
|
void cheat_manager_update(cheat_manager_t *handle, unsigned handle_idx);
|
2014-12-16 01:20:06 +00:00
|
|
|
|
2020-02-14 13:24:38 +00:00
|
|
|
void cheat_manager_toggle_index(bool apply_cheats_after_toggle,
|
|
|
|
unsigned i);
|
2015-09-06 01:51:08 +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
|
|
|
|
2015-12-01 02:07:16 +00:00
|
|
|
const char *cheat_manager_get_desc(unsigned i);
|
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
|
|
|
|
2015-12-01 01:49:27 +00:00
|
|
|
bool cheat_manager_get_code_state(unsigned i);
|
2015-09-06 01:51:08 +00:00
|
|
|
|
2015-12-01 01:43:34 +00:00
|
|
|
void cheat_manager_state_free(void);
|
|
|
|
|
2023-05-28 21:48:26 +00:00
|
|
|
void cheat_manager_alloc_if_empty(void);
|
2015-12-01 02:07:16 +00:00
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
bool cheat_manager_copy_idx_to_working(unsigned idx);
|
|
|
|
|
|
|
|
bool cheat_manager_copy_working_to_idx(unsigned idx);
|
|
|
|
|
2020-02-14 13:24:38 +00:00
|
|
|
void cheat_manager_load_game_specific_cheats(const char *path_cheat_database);
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2020-02-14 13:24:38 +00:00
|
|
|
void cheat_manager_save_game_specific_cheats(const char *path_cheat_database);
|
2018-07-25 23:19:14 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_initialize_memory(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_search_exact(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_search_lt(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_search_gt(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_search_lte(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_search_gte(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_search_eq(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_search_neq(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_search_eqplus(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_search_eqminus(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-08-24 22:05:58 +00:00
|
|
|
unsigned cheat_manager_get_state_search_size(unsigned search_size);
|
|
|
|
|
2018-07-25 23:19:14 +00:00
|
|
|
int cheat_manager_add_matches(const char *path,
|
|
|
|
const char *label, unsigned type, size_t idx, size_t entry_idx);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2018-08-04 18:02:33 +00:00
|
|
|
void cheat_manager_apply_retro_cheats(void);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2019-09-16 15:04:58 +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,
|
2018-07-25 23:19:14 +00:00
|
|
|
unsigned int *prev_value, unsigned int *curr_value);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_copy_match(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2018-09-26 13:46:27 +00:00
|
|
|
|
2020-06-29 22:05:48 +00:00
|
|
|
int cheat_manager_delete_match(rarch_setting_t *setting, size_t idx, bool wraparound);
|
2019-09-16 15:04:58 +00:00
|
|
|
|
2016-06-03 03:49:46 +00:00
|
|
|
RETRO_END_DECLS
|
2014-11-29 20:18:45 +00:00
|
|
|
|
2011-04-17 11:30:59 +00:00
|
|
|
#endif
|