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