RetroArch
cheat_manager.h
Go to the documentation of this file.
1 /* RetroArch - A frontend for libretro.
2  * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
3  * Copyright (C) 2011-2017 - Daniel De Matteis
4  *
5  * RetroArch is free software: you can redistribute it and/or modify it under the terms
6  * of the GNU General Public License as published by the Free Software Found-
7  * ation, either version 3 of the License, or (at your option) any later version.
8  *
9  * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  * PURPOSE. See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along with RetroArch.
14  * If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef __CHEAT_MANAGER_H
18 #define __CHEAT_MANAGER_H
19 
20 #include <boolean.h>
21 #include <retro_common_api.h>
22 
23 #include "../setting_list.h"
24 
26 
27 
29 {
33 };
34 
36 {
45 };
46 
48 {
58 };
59 
61 {
66 };
67 
69 {
82 };
83 
84 /* Some codes are ridiculously large - over 10000 bytes */
85 #define CHEAT_CODE_SCRATCH_SIZE 16*1024
86 #define CHEAT_DESC_SCRATCH_SIZE 255
87 
88 struct item_cheat
89 {
90  unsigned int idx;
91  char *desc;
92  bool state;
93  char *code;
94  unsigned int handler ;
95  /* Number of bits = 2^memory_search_size
96  * 0=1, 1=2, 2=4, 3=8, 4=16, 5=32
97  */
98  unsigned int memory_search_size ;
99  unsigned int cheat_type ;
100  unsigned int value ;
101  unsigned int address ;
102  /*
103  * address_mask used when memory_search_size <8 bits
104  * if memory_search_size=0, then the number of bits is 1 and this value can be one of the following:
105  * 0 : 00000001
106  * 1 : 00000010
107  * 2 : 00000100
108  * 3 : 00001000
109  * 4 : 00010000
110  * 5 : 00100000
111  * 6 : 01000000
112  * 7 : 10000000
113  * if memory_search_size=1, then the number of bits is 2 and this value can be one of the following:
114  * 0 : 00000011
115  * 1 : 00001100
116  * 2 : 00110000
117  * 3 : 11000000
118  * if memory_search_size=2, then the number of bits is 4 and this value can be one of the following:
119  * 0 : 00001111
120  * 1 : 11110000
121  */
122  unsigned int address_mask ;
123  /* Whether to apply the cheat based on big-endian console memory or not */
124  bool big_endian ;
125  unsigned int rumble_type ;
126  unsigned int rumble_value ;
127  unsigned int rumble_prev_value ;
128  unsigned int rumble_initialized ;
129  unsigned int rumble_port ; /* 0-15 for specific port, anything else means "all ports" */
130  unsigned int rumble_primary_strength ; /* 0-65535 */
131  unsigned int rumble_primary_duration ; /* in milliseconds */
132  retro_time_t rumble_primary_end_time ; /* clock value for when rumbling should stop */
133  unsigned int rumble_secondary_strength ; /* 0-65535 */
134  unsigned int rumble_secondary_duration ; /* in milliseconds */
135  retro_time_t rumble_secondary_end_time ; /* clock value for when rumbling should stop */
136 
137  /*
138  * The repeat_ variables allow for a single cheat code to affect multiple memory addresses.
139  * repeat_count - the number of times the cheat code should be applied
140  * repeat_add_to_value - every iteration of repeat_count will have this amount added to item_cheat.value
141  * repeat_add_to_address - every iteration of repeat_count will have this amount added to item_cheat.address
142  *
143  * Note that repeat_add_to_address represents the number of "memory_search_size" blocks to add to
144  * item_cheat.address. If memory_seach_size is 16-bits and repeat_add_to_address is 2, then item_cheat.address
145  * will be increased by 4 bytes 2*(16-bits) for every iteration.
146  *
147  * This is a cheating structure used for codes like unlocking all levels, giving yourself 1 of every item,etc.
148  */
149  unsigned int repeat_count ;
150  unsigned int repeat_add_to_value ;
151  unsigned int repeat_add_to_address ;
152 
153 };
154 
156 {
158  unsigned ptr;
159  unsigned size;
160  unsigned buf_size;
161  unsigned total_memory_size ;
166  unsigned *memory_size_list ;
169  unsigned match_idx ;
170  unsigned match_action ;
171  unsigned search_bit_size ;
172  unsigned dummy ;
176  unsigned num_matches ;
177  bool big_endian ;
180  unsigned int delete_state ;
181  unsigned browse_address;
184  unsigned int loading_cheat_size;
185  unsigned int loading_cheat_offset;
186 };
187 
189 
191 
192 unsigned cheat_manager_get_size(void);
193 
194 bool cheat_manager_load(const char *path, bool append);
195 
204 bool cheat_manager_save(const char *path, const char *cheat_database, bool overwrite);
205 
206 bool cheat_manager_realloc(unsigned new_size, unsigned default_handler);
207 
208 void cheat_manager_set_code(unsigned index, const char *str);
209 
210 void cheat_manager_free(void);
211 
212 void cheat_manager_index_next(void);
213 
214 void cheat_manager_index_prev(void);
215 
216 void cheat_manager_toggle(void);
217 
218 void cheat_manager_apply_cheats(void);
219 
220 void cheat_manager_update(cheat_manager_t *handle, unsigned handle_idx);
221 
222 void cheat_manager_toggle_index(unsigned i);
223 
224 unsigned cheat_manager_get_buf_size(void);
225 
226 const char *cheat_manager_get_desc(unsigned i);
227 
228 const char *cheat_manager_get_code(unsigned i);
229 
230 bool cheat_manager_get_code_state(unsigned i);
231 
232 void cheat_manager_state_free(void);
233 
235 
237 
239 
241 
243 
244 int cheat_manager_initialize_memory(rarch_setting_t *setting, bool wraparound);
245 
246 int cheat_manager_search_exact(rarch_setting_t *setting, bool wraparound);
247 
248 int cheat_manager_search_lt(rarch_setting_t *setting, bool wraparound);
249 
250 int cheat_manager_search_gt(rarch_setting_t *setting, bool wraparound);
251 
252 int cheat_manager_search_lte(rarch_setting_t *setting, bool wraparound);
253 
254 int cheat_manager_search_gte(rarch_setting_t *setting, bool wraparound);
255 
256 int cheat_manager_search_eq(rarch_setting_t *setting, bool wraparound);
257 
258 int cheat_manager_search_neq(rarch_setting_t *setting, bool wraparound);
259 
260 int cheat_manager_search_eqplus(rarch_setting_t *setting, bool wraparound);
261 
262 int cheat_manager_search_eqminus(rarch_setting_t *setting, bool wraparound);
263 
264 int cheat_manager_add_matches(const char *path,
265  const char *label, unsigned type, size_t idx, size_t entry_idx);
266 
268 
269 int cheat_manager_search(enum cheat_search_type search_type);
270 
271 void cheat_manager_match_action(enum cheat_match_action_type match_action, unsigned int target_match_idx, unsigned int *address, unsigned int *address_mask,
272  unsigned int *prev_value, unsigned int *curr_value);
273 
274 int cheat_manager_copy_match(rarch_setting_t *setting, bool wraparound);
275 
276 int cheat_manager_delete_match(rarch_setting_t *setting, bool wraparound);
278 
279 #endif
unsigned int repeat_add_to_address
Definition: cheat_manager.h:151
int cheat_manager_add_matches(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx)
Definition: cheat_manager.c:1105
unsigned search_eqminus_value
Definition: cheat_manager.h:175
Definition: cheat_manager.h:78
Definition: cheat_manager.h:54
unsigned int loading_cheat_offset
Definition: cheat_manager.h:185
unsigned int value
Definition: cheat_manager.h:100
unsigned cheat_manager_get_size(void)
Definition: cheat_manager.c:61
uint8_t ** memory_buf_list
Definition: cheat_manager.h:165
const char * cheat_manager_get_desc(unsigned i)
Definition: cheat_manager.c:636
unsigned num_matches
Definition: cheat_manager.h:176
int cheat_manager_initialize_memory(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:716
bool cheat_manager_alloc_if_empty(void)
Definition: cheat_manager.c:708
uint8_t * matches
Definition: cheat_manager.h:164
void cheat_manager_free(void)
Definition: cheat_manager.c:520
#define RETRO_BEGIN_DECLS
Definition: retro_common_api.h:41
unsigned int delete_state
Definition: cheat_manager.h:180
int cheat_manager_search_eq(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:938
bool memory_initialized
Definition: cheat_manager.h:178
int cheat_manager_search_neq(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:942
unsigned int rumble_prev_value
Definition: cheat_manager.h:127
Definition: cheat_manager.h:31
int cheat_manager_copy_match(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:1620
bool cheat_manager_save(const char *path, const char *cheat_database, bool overwrite)
Definition: cheat_manager.c:124
bool cheat_manager_load(const char *path, bool append)
Definition: cheat_manager.c:392
GLuint address
Definition: glext.h:10300
GLsizei const GLchar ** path
Definition: glext.h:7901
Definition: cheat_manager.h:77
bool cheat_manager_copy_working_to_idx(unsigned idx)
Definition: cheat_manager.c:254
unsigned dummy
Definition: cheat_manager.h:172
Definition: cheat_manager.h:32
Definition: cheat_manager.h:81
int cheat_manager_delete_match(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:1627
Definition: cheat_manager.h:40
bool big_endian
Definition: cheat_manager.h:177
void cheat_manager_save_game_specific_cheats(void)
Definition: cheat_manager.c:694
unsigned int address
Definition: cheat_manager.h:101
unsigned search_exact_value
Definition: cheat_manager.h:173
unsigned int rumble_secondary_strength
Definition: cheat_manager.h:133
int64_t retro_time_t
Definition: libretro.h:1610
Definition: cheat_manager.h:63
Definition: cheat_manager.h:55
Definition: setting_list.h:92
Definition: cheat_manager.h:71
struct item_cheat * cheats
Definition: cheat_manager.h:157
Definition: cheat_manager.h:53
uint8_t * prev_memory_buf
Definition: cheat_manager.h:163
unsigned int loading_cheat_size
Definition: cheat_manager.h:184
char working_code[CHEAT_CODE_SCRATCH_SIZE]
Definition: cheat_manager.h:183
unsigned int rumble_initialized
Definition: cheat_manager.h:128
unsigned ptr
Definition: cheat_manager.h:158
Definition: cheat_manager.h:76
struct item_cheat working_cheat
Definition: cheat_manager.h:168
GLuint GLsizei const GLchar * label
Definition: glext.h:8583
Definition: cheat_manager.h:88
int cheat_manager_search_lte(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:930
unsigned int repeat_count
Definition: cheat_manager.h:149
Definition: cheat_manager.h:43
int cheat_manager_search_gt(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:926
unsigned int repeat_add_to_value
Definition: cheat_manager.h:150
char * code
Definition: cheat_manager.h:93
int cheat_manager_search_gte(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:934
void cheat_manager_toggle(void)
Definition: cheat_manager.c:596
Definition: cheat_manager.h:74
GLenum type
Definition: glext.h:6233
unsigned cheat_manager_get_buf_size(void)
Definition: cheat_manager.c:56
unsigned browse_address
Definition: cheat_manager.h:181
uint8_t * curr_memory_buf
Definition: cheat_manager.h:162
bool state
Definition: cheat_manager.h:92
Definition: cheat_manager.h:73
unsigned match_idx
Definition: cheat_manager.h:169
void cheat_manager_apply_cheats(void)
Definition: cheat_manager.c:66
cheat_handler_type
Definition: cheat_manager.h:28
unsigned entry_idx
Definition: menu_cbs_ok.c:2308
unsigned buf_size
Definition: cheat_manager.h:160
void cheat_manager_load_game_specific_cheats(void)
Definition: cheat_manager.c:686
Definition: cheat_manager.h:39
Definition: cheat_manager.h:50
Definition: cheat_manager.h:79
bool big_endian
Definition: cheat_manager.h:124
unsigned total_memory_size
Definition: cheat_manager.h:161
cheat_match_action_type
Definition: cheat_manager.h:60
bool cheat_manager_realloc(unsigned new_size, unsigned default_handler)
Definition: cheat_manager.c:465
retro_time_t rumble_primary_end_time
Definition: cheat_manager.h:132
void cheat_manager_set_code(unsigned index, const char *str)
Definition: cheat_manager.c:105
unsigned num_memory_buffers
Definition: cheat_manager.h:167
Definition: cheat_manager.h:155
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 idx
Definition: pixman-arm-neon-asm.h:96
Definition: cheat_manager.h:56
#define CHEAT_DESC_SCRATCH_SIZE
Definition: cheat_manager.h:86
cheat_manager_t cheat_manager_state
Definition: cheat_manager.h:190
#define RETRO_END_DECLS
Definition: retro_common_api.h:42
bool cheat_manager_get_code_state(unsigned i)
Definition: cheat_manager.c:643
retro_time_t rumble_secondary_end_time
Definition: cheat_manager.h:135
int cheat_manager_search_exact(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:918
GLuint index
Definition: glext.h:6671
unsigned search_bit_size
Definition: cheat_manager.h:171
cheat_rumble_type
Definition: cheat_manager.h:68
Definition: cheat_manager.h:51
Definition: cheat_manager.h:42
Definition: cheat_manager.h:41
int cheat_manager_search(enum cheat_search_type search_type)
Definition: cheat_manager.c:955
const char * cheat_manager_get_code(unsigned i)
Definition: cheat_manager.c:629
bool cheat_manager_copy_idx_to_working(unsigned idx)
Definition: cheat_manager.c:236
unsigned int rumble_secondary_duration
Definition: cheat_manager.h:134
Definition: cheat_manager.h:72
unsigned int idx
Definition: cheat_manager.h:90
Definition: cheat_manager.h:30
void cheat_manager_toggle_index(unsigned i)
Definition: cheat_manager.c:580
Definition: cheat_manager.h:62
unsigned size
Definition: cheat_manager.h:159
void cheat_manager_state_free(void)
Definition: cheat_manager.c:703
unsigned int address_mask
Definition: cheat_manager.h:122
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)
Definition: cheat_manager.c:1462
unsigned match_action
Definition: cheat_manager.h:170
Definition: cheat_manager.h:64
void cheat_manager_apply_retro_cheats(void)
Definition: cheat_manager.c:1278
char working_desc[CHEAT_DESC_SCRATCH_SIZE]
Definition: cheat_manager.h:182
unsigned int handler
Definition: cheat_manager.h:94
Definition: cheat_manager.h:75
unsigned search_eqplus_value
Definition: cheat_manager.h:174
void cheat_manager_update(cheat_manager_t *handle, unsigned handle_idx)
Definition: cheat_manager.c:564
#define CHEAT_CODE_SCRATCH_SIZE
Definition: cheat_manager.h:85
unsigned * memory_size_list
Definition: cheat_manager.h:166
Definition: cheat_manager.h:49
Definition: cheat_manager.h:44
unsigned int memory_search_size
Definition: cheat_manager.h:98
bool memory_search_initialized
Definition: cheat_manager.h:179
unsigned int rumble_type
Definition: cheat_manager.h:125
int cheat_manager_search_eqplus(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:946
cheat_type
Definition: cheat_manager.h:35
Definition: cheat_manager.h:80
Definition: cheat_manager.h:57
Definition: cheat_manager.h:52
void cheat_manager_index_prev(void)
Definition: cheat_manager.c:616
unsigned int cheat_type
Definition: cheat_manager.h:99
unsigned int rumble_primary_duration
Definition: cheat_manager.h:131
int cheat_manager_search_lt(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:922
int cheat_manager_search_eqminus(rarch_setting_t *setting, bool wraparound)
Definition: cheat_manager.c:950
unsigned char uint8_t
Definition: stdint.h:124
Definition: cheat_manager.h:65
Definition: cheat_manager.h:37
Definition: cheat_manager.h:38
void cheat_manager_index_next(void)
Definition: cheat_manager.c:607
const char *const str
Definition: portlistingparse.c:18
unsigned int rumble_port
Definition: cheat_manager.h:129
char * desc
Definition: cheat_manager.h:91
Definition: cheat_manager.h:70
unsigned int rumble_value
Definition: cheat_manager.h:126
cheat_search_type
Definition: cheat_manager.h:47
unsigned int rumble_primary_strength
Definition: cheat_manager.h:130