The "override_existing" parameter is used only in cheat dialog import. Since the default behaviour will reset numsubcheats to 0 everytime, In game loading, this is absolutely right, but when importing in cheat window, resetting numsubcheats to 0 will override existed cheat items to make them invalid. */
| 186 | invalid. |
| 187 | */ |
| 188 | void FCEU_LoadGameCheats(FILE *override, int override_existing) |
| 189 | { |
| 190 | FILE *fp; |
| 191 | unsigned int addr; |
| 192 | unsigned int val; |
| 193 | unsigned int status; |
| 194 | unsigned int type; |
| 195 | unsigned int compare; |
| 196 | int x; |
| 197 | |
| 198 | char linebuf[2048] = { 0 }; |
| 199 | char namebuf[128] = { 0 }; |
| 200 | int tc = 0; |
| 201 | char *fn; |
| 202 | |
| 203 | if (override_existing) |
| 204 | { |
| 205 | numsubcheats = 0; |
| 206 | if (cheatMap) |
| 207 | FCEUI_RefreshCheatMap(); |
| 208 | } |
| 209 | |
| 210 | if(override) |
| 211 | fp = override; |
| 212 | else |
| 213 | { |
| 214 | fn = strdup(FCEU_MakeFName(FCEUMKF_CHEAT, 0, 0).c_str()); |
| 215 | fp = FCEUD_UTF8fopen(fn, "rb"); |
| 216 | free(fn); |
| 217 | if (!fp) { |
| 218 | return; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | while(fgets(linebuf, 2048, fp) != nullptr) |
| 223 | { |
| 224 | char *tbuf = linebuf; |
| 225 | int doc = 0; |
| 226 | |
| 227 | addr = val = compare = status = type = 0; |
| 228 | |
| 229 | if(tbuf[0] == 'S') |
| 230 | { |
| 231 | tbuf++; |
| 232 | type = 1; |
| 233 | } |
| 234 | else |
| 235 | type = 0; |
| 236 | |
| 237 | if(tbuf[0] == 'C') |
| 238 | { |
| 239 | tbuf++; |
| 240 | doc = 1; |
| 241 | } |
| 242 | |
| 243 | if(tbuf[0] == ':') |
| 244 | { |
| 245 | tbuf++; |
no test coverage detected