Debian Codegraph @

mednafen/mempatcher.cpp

raw symbols SCIP
1 /* Mednafen - Multi-system Emulator
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 #include "mednafen.h"cxx . . $ `<file>/mednafen/mednafen.h`/
19
20 #include <string.h>
21 #include <ctype.h>
22 #include <errno.h>
23 #include <vector>
24
25 #include "general.h"cxx . . $ `<file>/mednafen/general.h`/
26 #include "mempatcher.h"cxx . . $ `<file>/mednafen/mempatcher.h`/
27
28 #ifdef _WIN32
29 #include "msvc_compat.h"
30 #endif
31
32 static uint8cxx . . $ uint8# **RAMPtrscxx . . $ RAMPtrs. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
33 static uint32cxx . . $ uint32# PageSizecxx . . $ PageSize.;
34 static uint32cxx . . $ uint32# NumPagescxx . . $ NumPages.;
35
36 typedef struct __CHEATFcxx . . $ __CHEATF#
37 {
38 char *namecxx . . $ __CHEATF#name.;
39 char *conditionscxx . . $ __CHEATF#conditions.;
40
41 uint32cxx . . $ uint32# addrcxx . . $ __CHEATF#addr.;
42 uint64cxx . . $ uint64# valcxx . . $ __CHEATF#val.;
43 uint64cxx . . $ uint64# comparecxx . . $ __CHEATF#compare.;
44
45 unsigned int lengthcxx . . $ __CHEATF#length.;
46 bool bigendiancxx . . $ __CHEATF#bigendian.;
47 unsigned int icountcxx . . $ __CHEATF#icount.; // Instance count
48 char typecxx . . $ __CHEATF#type.; /* 'R' for replace, 'S' for substitute(GG), 'C' for substitute with compare */
49 int statuscxx . . $ __CHEATF#status.;
50 } CHEATFcxx . . $ CHEATF#;
51
52 static stdcxx . . $ std/::vectorcxx . . $ std/vector#<CHEATFcxx . . $ CHEATF#> cheatscxx . . $ cheats.;
53 static int savecheatscxx . . $ savecheats.;
54 static uint32cxx . . $ uint32# resultsbytelencxx . . $ resultsbytelen. = 1;
55 static bool resultsbigendiancxx . . $ resultsbigendian. = 0;
56 static bool CheatsActivecxx . . $ CheatsActive. = TRUEcxx . . $ `mednafen/mednafen-types.h:113:9`!;
57
58 bool SubCheatsOncxx . . $ SubCheatsOn. = 0;
59 stdcxx . . $ std/::vectorcxx . . $ std/vector#<SUBCHEATcxx . . $ SUBCHEAT#> SubCheatscxx . . $ SubCheats.[8];
60
61 static void RebuildSubCheatscxx . . $ RebuildSubCheats(49f6e7a06ebc5aa8).(void)
62 {
63 stdcxx . . $ std/::vectorcxx . . $ std/vector#<CHEATF>::iteratorcxx . . $ std/vector#iterator# chitcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ced63f7c635d850d).;
64
65 SubCheatsOncxx . . $ SubCheatsOn. = 0;
66 for(int x = 0; x < 8; x++)
67 SubCheatscxx . . $ SubCheats.[x].clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
68
69 if(!CheatsActivecxx . . $ CheatsActive.) return;
70
71 for(chit =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(328b848e4bb5434c). cheatscxx . . $ cheats..begincxx . . $ std/vector#begin(55a6de06420d4903).(); chit !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). cheatscxx . . $ cheats..endcxx . . $ std/vector#end(55a6de06420d4903).(); chit++cxx . . $ __gnu_cxx/__normal_iterator#operator++(6cefca3db4774be2).)
72 {
73 if(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).statuscxx . . $ __CHEATF#status. && chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).typecxx . . $ __CHEATF#type. != 'R')
74 {
75 for(unsigned int x = 0; x < chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).lengthcxx . . $ __CHEATF#length.; x++)
76 {
77 SUBCHEATcxx . . $ SUBCHEAT# tmpsub;
78 unsigned int shiftie;
79
80 if(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).bigendiancxx . . $ __CHEATF#bigendian.)
81 shiftie = (chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).lengthcxx . . $ __CHEATF#length. - 1 - x) * 8;
82 else
83 shiftie = x * 8;
84
85 tmpsub.addrcxx . . $ __SUBCHEAT#addr. = chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).addrcxx . . $ __CHEATF#addr. + x;
86 tmpsub.valuecxx . . $ __SUBCHEAT#value. = (chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).valcxx . . $ __CHEATF#val. >> shiftie) & 0xFF;
87 if(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).typecxx . . $ __CHEATF#type. == 'C')
88 tmpsub.comparecxx . . $ __SUBCHEAT#compare. = (chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).comparecxx . . $ __CHEATF#compare. >> shiftie) & 0xFF;
89 else
90 tmpsub.comparecxx . . $ __SUBCHEAT#compare. = -1;
91 SubCheatscxx . . $ SubCheats.[(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).addrcxx . . $ __CHEATF#addr. + x) & 0x7].push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(tmpsub);
92 SubCheatsOncxx . . $ SubCheatsOn. = 1;
93 }
94 }
95 }
96 }
97
98 bool MDFNMP_Initcxx . . $ MDFNMP_Init(8e1b545ea3aecce3).(uint32cxx . . $ uint32# ps, uint32cxx . . $ uint32# numpages)
99 {
100 PageSizecxx . . $ PageSize. = ps;
101 NumPagescxx . . $ NumPages. = numpages;
102
103 RAMPtrscxx . . $ RAMPtrs. = (uint8cxx . . $ uint8# **)calloccxx . . $ calloc(95acc9b79bb49189).(numpages, sizeof(uint8cxx . . $ uint8# *));
104
105 CheatsActivecxx . . $ CheatsActive. = MDFN_GetSettingBcxx . . $ MDFN_GetSettingB(c5f7da30cbc0f4e9).("cheats");
106 return(1);
107 }
108
109 void MDFNMP_Killcxx . . $ MDFNMP_Kill(49f6e7a06ebc5aa8).(void)
110 {
111 if(RAMPtrscxx . . $ RAMPtrs.)
112 {
113 freecxx . . $ free(bd21765a0afc8e3c).(RAMPtrscxx . . $ RAMPtrs.);
114 RAMPtrscxx . . $ RAMPtrs. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
115 }
116 }
117
118
119 void MDFNMP_AddRAMcxx . . $ MDFNMP_AddRAM(f9255d7bf06fcbb).(uint32cxx . . $ uint32# size, uint32cxx . . $ uint32# A, uint8cxx . . $ uint8# *RAM)
120 {
121 uint32cxx . . $ uint32# AB = A / PageSizecxx . . $ PageSize.;
122
123 size /= PageSizecxx . . $ PageSize.;
124
125 for(unsigned int x = 0; x < size; x++)
126 {
127 RAMPtrscxx . . $ RAMPtrs.[AB + x] = RAM;
128 if(RAM) // Don't increment the RAM pointer if we're passed a NULL pointer
129 RAM += PageSizecxx . . $ PageSize.;
130 }
131 }
132
133 void MDFNMP_InstallReadPatchescxx . . $ MDFNMP_InstallReadPatches(49f6e7a06ebc5aa8).(void)
134 {
135 if(!CheatsActivecxx . . $ CheatsActive.) return;
136
137 stdcxx . . $ std/::vectorcxx . . $ std/vector#<SUBCHEAT>::iteratorcxx . . $ std/vector#iterator# chitcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ced63f7c635d850d).;
138
139 for(unsigned int x = 0; x < 8; x++)
140 for(chit =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(b49c11a9c429bab). SubCheatscxx . . $ SubCheats.[x].begincxx . . $ std/vector#begin(55a6de06420d4903).(); chit !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). SubCheatscxx . . $ SubCheats.[x].endcxx . . $ std/vector#end(55a6de06420d4903).(); chit++cxx . . $ __gnu_cxx/__normal_iterator#operator++(6cefca3db4774be2).)
141 {
142 if(MDFNGameInfocxx . . $ MDFNGameInfo.->InstallReadPatchcxx . . $ $anonymous_type_643ef407c229d02_12#InstallReadPatch.)
143 MDFNGameInfocxx . . $ MDFNGameInfo.->InstallReadPatchcxx . . $ $anonymous_type_643ef407c229d02_12#InstallReadPatch.(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).addrcxx . . $ __SUBCHEAT#addr.);
144 }
145 }
146
147 void MDFNMP_RemoveReadPatchescxx . . $ MDFNMP_RemoveReadPatches(49f6e7a06ebc5aa8).(void)
148 {
149 if(MDFNGameInfocxx . . $ MDFNGameInfo.->RemoveReadPatchescxx . . $ $anonymous_type_643ef407c229d02_12#RemoveReadPatches.)
150 MDFNGameInfocxx . . $ MDFNGameInfo.->RemoveReadPatchescxx . . $ $anonymous_type_643ef407c229d02_12#RemoveReadPatches.();
151 }
152
153 static void CheatMemErrcxx . . $ CheatMemErr(49f6e7a06ebc5aa8).(void)
154 {
155 MDFN_PrintErrorcxx . . $ MDFN_PrintError(326aeb464d16410c).(_cxx . . $ `mednafen/mednafen.h:9:9`!("Error allocating memory for cheat data."));
156 }
157
158 /* This function doesn't allocate any memory for "name" */
159 static int AddCheatEntrycxx . . $ AddCheatEntry(4d74b56d7f62d11b).(char *name, char *conditions, uint32cxx . . $ uint32# addr, uint64cxx . . $ uint64# val, uint64cxx . . $ uint64# compare, int status, char type, unsigned int length, bool bigendian)
160 {
161 CHEATFcxx . . $ CHEATF# temp;
162
163 memset(&temp, 0, sizeof(CHEATFcxx . . $ CHEATF#));
164
165 temp.namecxx . . $ __CHEATF#name.=name;
166 temp.conditionscxx . . $ __CHEATF#conditions. = conditions;
167 temp.addrcxx . . $ __CHEATF#addr.=addr;
168 temp.valcxx . . $ __CHEATF#val.=val;
169 temp.statuscxx . . $ __CHEATF#status.=status;
170 temp.comparecxx . . $ __CHEATF#compare.=compare;
171 temp.lengthcxx . . $ __CHEATF#length. = length;
172 temp.bigendiancxx . . $ __CHEATF#bigendian. = bigendian;
173 temp.typecxx . . $ __CHEATF#type.=type;
174
175 cheatscxx . . $ cheats..push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(temp);
176 return(1);
177 }
178
179 void MDFN_LoadGameCheatscxx . . $ MDFN_LoadGameCheats(5d22bdacc48458e8).(void *override_ptr)
180 {
181 RebuildSubCheatscxx . . $ RebuildSubCheats(49f6e7a06ebc5aa8).();
182 }
183
184 void MDFN_FlushGameCheatscxx . . $ MDFN_FlushGameCheats(d4f767463ce0a6b3).(int nosave)
185 {
186 stdcxx . . $ std/::vectorcxx . . $ std/vector#<CHEATF>::iteratorcxx . . $ std/vector#iterator# chitcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ced63f7c635d850d).;
187
188 for(chit =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(328b848e4bb5434c). cheatscxx . . $ cheats..begincxx . . $ std/vector#begin(55a6de06420d4903).(); chit !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). cheatscxx . . $ cheats..endcxx . . $ std/vector#end(55a6de06420d4903).(); chit++cxx . . $ __gnu_cxx/__normal_iterator#operator++(6cefca3db4774be2).)
189 {
190 freecxx . . $ free(bd21765a0afc8e3c).(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).namecxx . . $ __CHEATF#name.);
191 if(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).conditionscxx . . $ __CHEATF#conditions.)
192 freecxx . . $ free(bd21765a0afc8e3c).(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).conditionscxx . . $ __CHEATF#conditions.);
193 }
194 cheatscxx . . $ cheats..clearcxx . . $ std/vector#clear(ced63f7c635d850d).();
195
196 RebuildSubCheatscxx . . $ RebuildSubCheats(49f6e7a06ebc5aa8).();
197 }
198
199 int MDFNI_AddCheatcxx . . $ MDFNI_AddCheat(41c94168d8be1ca1).(const char *name, uint32cxx . . $ uint32# addr, uint64cxx . . $ uint64# val, uint64cxx . . $ uint64# compare, char type, unsigned int length, bool bigendian)
200 {
201 char *t;
202
203 if(!(t = strdup(name)))
204 {
205 CheatMemErrcxx . . $ CheatMemErr(49f6e7a06ebc5aa8).();
206 return(0);
207 }
208
209 if(!AddCheatEntrycxx . . $ AddCheatEntry(4d74b56d7f62d11b).(t, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, addr,val,compare,1,type, length, bigendian))
210 {
211 freecxx . . $ free(bd21765a0afc8e3c).(t);
212 return(0);
213 }
214
215 savecheatscxx . . $ savecheats. = 1;
216
217 MDFNMP_RemoveReadPatchescxx . . $ MDFNMP_RemoveReadPatches(49f6e7a06ebc5aa8).();
218 RebuildSubCheatscxx . . $ RebuildSubCheats(49f6e7a06ebc5aa8).();
219 MDFNMP_InstallReadPatchescxx . . $ MDFNMP_InstallReadPatches(49f6e7a06ebc5aa8).();
220
221 return(1);
222 }
223
224 int MDFNI_DelCheatcxx . . $ MDFNI_DelCheat(4c679297bf94b9eb).(uint32cxx . . $ uint32# which)
225 {
226 freecxx . . $ free(bd21765a0afc8e3c).(cheatscxx . . $ cheats.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).which].namecxx . . $ __CHEATF#name.);
227 cheatscxx . . $ cheats..erasecxx . . $ std/vector#erase(351407f384f345bc).(cheatscxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..begincxx . . $ std/vector#begin(55a6de06420d4903).() +cxx . . $ __gnu_cxx/__normal_iterator#operator+(192bf940fa7bb3b2). which);
228
229 savecheatscxx . . $ savecheats.=1;
230
231 MDFNMP_RemoveReadPatchescxx . . $ MDFNMP_RemoveReadPatches(49f6e7a06ebc5aa8).();
232 RebuildSubCheatscxx . . $ RebuildSubCheats(49f6e7a06ebc5aa8).();
233 MDFNMP_InstallReadPatchescxx . . $ MDFNMP_InstallReadPatches(49f6e7a06ebc5aa8).();
234
235 return(1);
236 }
237
238 /*
239 Condition format(ws = white space):
240
241 <variable size><ws><endian><ws><address><ws><operation><ws><value>
242 [,second condition...etc.]
243
244 Value should be unsigned integer, hex(with a 0x prefix) or
245 base-10.
246
247 Operations:
248 >=
249 <=
250 >
251 <
252 ==
253 !=
254 & // Result of AND between two values is nonzero
255 !& // Result of AND between two values is zero
256 ^ // same, XOR
257 !^
258 | // same, OR
259 !|
260
261 Full example:
262
263 2 L 0xADDE == 0xDEAD, 1 L 0xC000 == 0xA0
264
265 */
266
267 static bool TestConditionscxx . . $ TestConditions(c5f7da30cbc0f4e9).(const char *string)
268 {
269 char address[64];
270 char operation[64];
271 char value[64];
272 char endian;
273 unsigned int bytelen;
274 bool passed = 1;
275
276 //printf("TR: %s\n", string);
277 while(sscanf(string, "%u %c %63s %63s %63s", &bytelen, &endian, address, operation, value) == 5 && passed)
278 {
279 uint32cxx . . $ uint32# v_address;
280 uint64cxx . . $ uint64# v_value;
281 uint64cxx . . $ uint64# value_at_address;
282
283 if(address[0] == '0' && address[1] == 'x')
284 v_address = strtoulcxx . . $ strtoul(335a43d87d12a1b6).(address + 2, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 16);
285 else
286 v_address = strtoulcxx . . $ strtoul(335a43d87d12a1b6).(address, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 10);
287
288 if(value[0] == '0' && value[1] == 'x')
289 v_value = strtoull(value + 2, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 16);
290 else
291 v_value = strtoull(value, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0);
292
293 value_at_address = 0;
294 for(unsigned int x = 0; x < bytelen; x++)
295 {
296 unsigned int shiftie;
297
298 if(endian == 'B')
299 shiftie = (bytelen - 1 - x) * 8;
300 else
301 shiftie = x * 8;
302 value_at_address |= MDFNGameInfocxx . . $ MDFNGameInfo.->MemReadcxx . . $ $anonymous_type_643ef407c229d02_12#MemRead.(v_address + x) << shiftie;
303 }
304
305 //printf("A: %08x, V: %08llx, VA: %08llx, OP: %s\n", v_address, v_value, value_at_address, operation);
306 if(!strcmp(operation, ">="))
307 {
308 if(!(value_at_address >= v_value))
309 passed = 0;
310 }
311 else if(!strcmp(operation, "<="))
312 {
313 if(!(value_at_address <= v_value))
314 passed = 0;
315 }
316 else if(!strcmp(operation, ">"))
317 {
318 if(!(value_at_address > v_value))
319 passed = 0;
320 }
321 else if(!strcmp(operation, "<"))
322 {
323 if(!(value_at_address < v_value))
324 passed = 0;
325 }
326 else if(!strcmp(operation, "=="))
327 {
328 if(!(value_at_address == v_value))
329 passed = 0;
330 }
331 else if(!strcmp(operation, "!="))
332 {
333 if(!(value_at_address != v_value))
334 passed = 0;
335 }
336 else if(!strcmp(operation, "&"))
337 {
338 if(!(value_at_address & v_value))
339 passed = 0;
340 }
341 else if(!strcmp(operation, "!&"))
342 {
343 if(value_at_address & v_value)
344 passed = 0;
345 }
346 else if(!strcmp(operation, "^"))
347 {
348 if(!(value_at_address ^ v_value))
349 passed = 0;
350 }
351 else if(!strcmp(operation, "!^"))
352 {
353 if(value_at_address ^ v_value)
354 passed = 0;
355 }
356 else if(!strcmp(operation, "|"))
357 {
358 if(!(value_at_address | v_value))
359 passed = 0;
360 }
361 else if(!strcmp(operation, "!|"))
362 {
363 if(value_at_address | v_value)
364 passed = 0;
365 }
366 else
367 puts("Invalid operation");
368 string = strchr(string, ',');
369 if(string == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!)
370 break;
371 else
372 string++;
373 //printf("Foo: %s\n", string);
374 }
375
376 return(passed);
377 }
378
379 void MDFNMP_ApplyPeriodicCheatscxx . . $ MDFNMP_ApplyPeriodicCheats(49f6e7a06ebc5aa8).(void)
380 {
381 stdcxx . . $ std/::vectorcxx . . $ std/vector#<CHEATF>::iteratorcxx . . $ std/vector#iterator# chitcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ced63f7c635d850d).;
382
383
384 if(!CheatsActivecxx . . $ CheatsActive.)
385 return;
386
387 for(chit =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(328b848e4bb5434c). cheatscxx . . $ cheats..begincxx . . $ std/vector#begin(55a6de06420d4903).(); chit !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). cheatscxx . . $ cheats..endcxx . . $ std/vector#end(55a6de06420d4903).(); chit++cxx . . $ __gnu_cxx/__normal_iterator#operator++(6cefca3db4774be2).)
388 {
389 if(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).statuscxx . . $ __CHEATF#status. && chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).typecxx . . $ __CHEATF#type. == 'R')
390 {
391 if(!chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).conditionscxx . . $ __CHEATF#conditions. || TestConditionscxx . . $ TestConditions(c5f7da30cbc0f4e9).(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).conditionscxx . . $ __CHEATF#conditions.))
392 for(unsigned int x = 0; x < chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).lengthcxx . . $ __CHEATF#length.; x++)
393 {
394 uint32cxx . . $ uint32# page = ((chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).addrcxx . . $ __CHEATF#addr. + x) / PageSizecxx . . $ PageSize.) % NumPagescxx . . $ NumPages.;
395 if(RAMPtrscxx . . $ RAMPtrs.[page])
396 {
397 uint64cxx . . $ uint64# tmpval = chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).valcxx . . $ __CHEATF#val.;
398
399 if(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).bigendiancxx . . $ __CHEATF#bigendian.)
400 tmpval >>= (chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).lengthcxx . . $ __CHEATF#length. - 1 - x) * 8;
401 else
402 tmpval >>= x * 8;
403
404 RAMPtrscxx . . $ RAMPtrs.[page][(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).addrcxx . . $ __CHEATF#addr. + x) % PageSizecxx . . $ PageSize.] = tmpval;
405 }
406 }
407 }
408 }
409 }
410
411
412 void MDFNI_ListCheatscxx . . $ MDFNI_ListCheats(bee3a6b2bc6780fb).(int (*callb)(char *name, uint32cxx . . $ uint32# a, uint64cxx . . $ uint64# v, uint64cxx . . $ uint64# compare, int s, char type, unsigned int length, bool bigendian, void *data), void *data)
413 {
414 stdcxx . . $ std/::vectorcxx . . $ std/vector#<CHEATF>::iteratorcxx . . $ std/vector#iterator# chitcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(ced63f7c635d850d).;
415
416 for(chit =cxx . . $ __gnu_cxx/__normal_iterator#`operator=`(328b848e4bb5434c). cheatscxx . . $ cheats..begincxx . . $ std/vector#begin(55a6de06420d4903).(); chit !=cxx . . $ __gnu_cxx/`operator!=`(30ee64f2df4eef8b). cheatscxx . . $ cheats..endcxx . . $ std/vector#end(55a6de06420d4903).(); chit++cxx . . $ __gnu_cxx/__normal_iterator#operator++(6cefca3db4774be2).)
417 {
418 if(!callb(chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).namecxx . . $ __CHEATF#name., chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).addrcxx . . $ __CHEATF#addr., chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).valcxx . . $ __CHEATF#val., chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).comparecxx . . $ __CHEATF#compare., chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).statuscxx . . $ __CHEATF#status., chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).typecxx . . $ __CHEATF#type., chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).lengthcxx . . $ __CHEATF#length., chit->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).bigendiancxx . . $ __CHEATF#bigendian., data)) break;
419 }
420 }
421
422 int MDFNI_GetCheatcxx . . $ MDFNI_GetCheat(6d1ec47ccc947b34).(uint32cxx . . $ uint32# which, char **name, uint32cxx . . $ uint32# *a, uint64cxx . . $ uint64# *v, uint64cxx . . $ uint64# *compare, int *s, char *type, unsigned int *length, bool *bigendian)
423 {
424 CHEATFcxx . . $ CHEATF# *next = &cheatscxx . . $ cheats.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).which];
425
426 if(name)
427 *name=next->namecxx . . $ __CHEATF#name.;
428 if(a)
429 *a=next->addrcxx . . $ __CHEATF#addr.;
430 if(v)
431 *v=next->valcxx . . $ __CHEATF#val.;
432 if(s)
433 *s=next->statuscxx . . $ __CHEATF#status.;
434 if(compare)
435 *compare=next->comparecxx . . $ __CHEATF#compare.;
436 if(type)
437 *type=next->typecxx . . $ __CHEATF#type.;
438 if(length)
439 *length = next->lengthcxx . . $ __CHEATF#length.;
440 if(bigendian)
441 *bigendian = next->bigendiancxx . . $ __CHEATF#bigendian.;
442 return(1);
443 }
444
445 static uint8cxx . . $ uint8# CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(char thechar)
446 {
447 const char lut[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
448
449 thechar = toupper(thechar);
450
451 for(int x = 0; x < 16; x++)
452 if(lut[x] == thechar)
453 return(x);
454
455 return(0xFF);
456 }
457
458 bool MDFNI_DecodeGBGGcxx . . $ MDFNI_DecodeGBGG(9a5d54bc73705f34).(const char *instr, uint32cxx . . $ uint32# *a, uint8cxx . . $ uint8# *v, uint8cxx . . $ uint8# *c, char *type)
459 {
460 char str[10];
461 int len;
462
463 for(int x = 0; x < 9; x++)
464 {
465 while(*instr && CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(*instr) == 255)
466 instr++;
467 if(!(str[x] = *instr)) break;
468 instr++;
469 }
470 str[9] = 0;
471
472 len = strlen(str);
473
474 if(len != 9 && len != 6)
475 return(0);
476
477 uint32cxx . . $ uint32# tmp_address;
478 uint8cxx . . $ uint8# tmp_value;
479 uint8cxx . . $ uint8# tmp_compare = 0;
480
481 tmp_address = (CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(str[5]) << 12) | (CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(str[2]) << 8) | (CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(str[3]) << 4) | (CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(str[4]) << 0);
482 tmp_address ^= 0xF000;
483 tmp_value = (CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(str[0]) << 4) | (CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(str[1]) << 0);
484
485 if(len == 9)
486 {
487 tmp_compare = (CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(str[6]) << 4) | (CharToNibblecxx . . $ CharToNibble(37bf0c9286c484e9).(str[8]) << 0);
488 tmp_compare = (tmp_compare >> 2) | ((tmp_compare << 6) & 0xC0);
489 tmp_compare ^= 0xBA;
490 }
491
492 *a = tmp_address;
493 *v = tmp_value;
494
495 if(len == 9)
496 {
497 *c = tmp_compare;
498 *type = 'C';
499 }
500 else
501 {
502 *c = 0;
503 *type = 'S';
504 }
505
506 return(1);
507 }
508
509 static int GGtobincxx . . $ GGtobin(784f3405e7e545be).(char c)
510 {
511 static char lets[16]={'A','P','Z','L','G','I','T','Y','E','O','X','U','K','S','V','N'};
512 int x;
513
514 for(x=0;x<16;x++)
515 if(lets[x] == toupper(c)) return(x);
516 return(0);
517 }
518
519 /* Returns 1 on success, 0 on failure. Sets *a,*v,*c. */
520 int MDFNI_DecodeGGcxx . . $ MDFNI_DecodeGG(3a4289f9daa6abb1).(const char *str, uint32cxx . . $ uint32# *a, uint8cxx . . $ uint8# *v, uint8cxx . . $ uint8# *c, char *type)
521 {
522 uint16cxx . . $ uint16# A;
523 uint8cxx . . $ uint8# V,C;
524 uint8cxx . . $ uint8# t;
525 int s;
526
527 A=0x8000;
528 V=0;
529 C=0;
530
531 s=strlen(str);
532 if(s!=6 && s!=8) return(0);
533
534 t=GGtobincxx . . $ GGtobin(784f3405e7e545be).(*str++);
535 V|=(t&0x07);
536 V|=(t&0x08)<<4;
537
538 t=GGtobincxx . . $ GGtobin(784f3405e7e545be).(*str++);
539 V|=(t&0x07)<<4;
540 A|=(t&0x08)<<4;
541
542 t=GGtobincxx . . $ GGtobin(784f3405e7e545be).(*str++);
543 A|=(t&0x07)<<4;
544 //if(t&0x08) return(0); /* 8-character code?! */
545
546 t=GGtobincxx . . $ GGtobin(784f3405e7e545be).(*str++);
547 A|=(t&0x07)<<12;
548 A|=(t&0x08);
549
550 t=GGtobincxx . . $ GGtobin(784f3405e7e545be).(*str++);
551 A|=(t&0x07);
552 A|=(t&0x08)<<8;
553
554 if(s==6)
555 {
556 t=GGtobincxx . . $ GGtobin(784f3405e7e545be).(*str++);
557 A|=(t&0x07)<<8;
558 V|=(t&0x08);
559
560 *a=A;
561 *v=V;
562 *type = 'S';
563 *c = 0;
564 return(1);
565 }
566 else
567 {
568 t=GGtobincxx . . $ GGtobin(784f3405e7e545be).(*str++);
569 A|=(t&0x07)<<8;
570 C|=(t&0x08);
571
572 t=GGtobincxx . . $ GGtobin(784f3405e7e545be).(*str++);
573 C|=(t&0x07);
574 C|=(t&0x08)<<4;
575
576 t=GGtobincxx . . $ GGtobin(784f3405e7e545be).(*str++);
577 C|=(t&0x07)<<4;
578 V|=(t&0x08);
579 *a=A;
580 *v=V;
581 *c=C;
582 *type = 'C';
583 return(1);
584 }
585 return(0);
586 }
587
588 int MDFNI_DecodePARcxx . . $ MDFNI_DecodePAR(3a4289f9daa6abb1).(const char *str, uint32cxx . . $ uint32# *a, uint8cxx . . $ uint8# *v, uint8cxx . . $ uint8# *c, char *type)
589 {
590 int boo[4];
591 if(strlen(str)!=8) return(0);
592
593 sscanf(str,"%02x%02x%02x%02x",boo,boo+1,boo+2,boo+3);
594
595 *c = 0;
596
597 if(1)
598 {
599 *a=(boo[3]<<8)|(boo[2]+0x7F);
600 *v=0;
601 }
602 else
603 {
604 *v=boo[3];
605 *a=boo[2]|(boo[1]<<8);
606 }
607
608 *type = 'S';
609 return(1);
610 }
611
612 /* name can be NULL if the name isn't going to be changed. */
613 int MDFNI_SetCheatcxx . . $ MDFNI_SetCheat(34d2a457eb803bb6).(uint32cxx . . $ uint32# which, const char *name, uint32cxx . . $ uint32# a, uint64cxx . . $ uint64# v, uint64cxx . . $ uint64# compare, int s, char type, unsigned int length, bool bigendian)
614 {
615 CHEATFcxx . . $ CHEATF# *next = &cheatscxx . . $ cheats.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).which];
616
617 if(name)
618 {
619 char *t;
620
621 if((t=(char *)realloccxx . . $ realloc(42b2a9dd8f084bf2).(next->namecxx . . $ __CHEATF#name.,strlen(name+1))))
622 {
623 next->namecxx . . $ __CHEATF#name.=t;
624 strcpy(next->namecxx . . $ __CHEATF#name.,name);
625 }
626 else
627 return(0);
628 }
629 next->addrcxx . . $ __CHEATF#addr.=a;
630 next->valcxx . . $ __CHEATF#val.=v;
631 next->statuscxx . . $ __CHEATF#status.=s;
632 next->comparecxx . . $ __CHEATF#compare.=compare;
633 next->typecxx . . $ __CHEATF#type.=type;
634 next->lengthcxx . . $ __CHEATF#length. = length;
635 next->bigendiancxx . . $ __CHEATF#bigendian. = bigendian;
636
637 RebuildSubCheatscxx . . $ RebuildSubCheats(49f6e7a06ebc5aa8).();
638 savecheatscxx . . $ savecheats.=1;
639
640 return(1);
641 }
642
643 /* Convenience function. */
644 int MDFNI_ToggleCheatcxx . . $ MDFNI_ToggleCheat(4c679297bf94b9eb).(uint32cxx . . $ uint32# which)
645 {
646 cheatscxx . . $ cheats.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).which].statuscxx . . $ __CHEATF#status. = !cheatscxx . . $ cheats.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).which].statuscxx . . $ __CHEATF#status.;
647 savecheatscxx . . $ savecheats. = 1;
648 RebuildSubCheatscxx . . $ RebuildSubCheats(49f6e7a06ebc5aa8).();
649
650 return(cheatscxx . . $ cheats.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).which].statuscxx . . $ __CHEATF#status.);
651 }
652
653 static void SettingChangedcxx . . $ SettingChanged(85c52e162fed56f9).(const char *name)
654 {
655 MDFNMP_RemoveReadPatchescxx . . $ MDFNMP_RemoveReadPatches(49f6e7a06ebc5aa8).();
656
657 CheatsActivecxx . . $ CheatsActive. = MDFN_GetSettingBcxx . . $ MDFN_GetSettingB(c5f7da30cbc0f4e9).("cheats");
658
659 RebuildSubCheatscxx . . $ RebuildSubCheats(49f6e7a06ebc5aa8).();
660
661 MDFNMP_InstallReadPatchescxx . . $ MDFNMP_InstallReadPatches(49f6e7a06ebc5aa8).();
662 }
663
664
665 MDFNSettingcxx . . $ MDFNSetting# MDFNMP_Settingscxx . . $ MDFNMP_Settings.[] =
666 {
667 { "cheats", MDFNSF_NOFLAGScxx . . $ `mednafen/settings-common.h:19:9`!, "Enable cheats.", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, MDFNST_BOOLcxx . . $ MDFNST_BOOL., "1", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, SettingChangedcxx . . $ SettingChanged(85c52e162fed56f9). },
668 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!}
669 };