diff options
-rw-r--r-- | source/cheats2.cpp | 6 | ||||
-rw-r--r-- | source/nds/gcheat.c | 12 | ||||
-rw-r--r-- | source/nds/gui.c | 13 |
3 files changed, 17 insertions, 14 deletions
diff --git a/source/cheats2.cpp b/source/cheats2.cpp index 1423637..8d81d6d 100644 --- a/source/cheats2.cpp +++ b/source/cheats2.cpp @@ -105,17 +105,19 @@ void S9xInitCheatData () void S9xAddCheat (bool8 enable, bool8 save_current_value, uint32 address, uint8 byte) { - if (Cheat.num_cheats < sizeof (Cheat.c) / sizeof (Cheat. c [0])) + if (Cheat.num_cheats < sizeof (Cheat.c) / sizeof (Cheat.c [0])) { Cheat.c [Cheat.num_cheats].address = address; Cheat.c [Cheat.num_cheats].byte = byte; - Cheat.c [Cheat.num_cheats].enabled = TRUE; + Cheat.c [Cheat.num_cheats].enabled = enable; if (save_current_value) { Cheat.c [Cheat.num_cheats].saved_byte = S9xGetByte (address); Cheat.c [Cheat.num_cheats].saved = TRUE; } Cheat.num_cheats++; + if (enable) + S9xApplyCheat(Cheat.num_cheats - 1); } } diff --git a/source/nds/gcheat.c b/source/nds/gcheat.c index 648bfda..e3d0e8d 100644 --- a/source/nds/gcheat.c +++ b/source/nds/gcheat.c @@ -72,8 +72,8 @@ int NDSSFCLoadCheatFile(const char* filename) fclose(fp); return -2; } + *ptr = '\0'; // End the codes there *ptr++; // Past the comma - *(ptr - 1) = '\0'; // End the codes there uint32 i = 0; description = ptr; // Skip starting " in description @@ -86,19 +86,21 @@ int NDSSFCLoadCheatFile(const char* filename) } *ptr = '\0'; - uint32 n = 0, c; + uint32 c; // n is the number of cheat codes. Beware of MAX_CHEATS_T. // List of cheat codes having the same description. ptr = codes_ptr; while (*ptr && !(*ptr == ',' || *ptr == '"')) { - if (n >= MAX_CHEATS_T) { + if (Cheat.num_cheats >= MAX_CHEATS_T) { fclose(fp); return 0; } i = 0; - while (*ptr && *ptr != '+' && i < sizeof(code) - 1) + while (*ptr && !(*ptr == '+' || *ptr == ',' || *ptr == '"') && i < sizeof(code) - 1) code[i++] = *ptr++; + if (*ptr) + ptr++; // Go past the + , or " code[i] = '\0'; if (!S9xGameGenieToRaw (code, &address, &byte)) { S9xAddCheat (FALSE, TRUE, address, byte); @@ -112,7 +114,7 @@ int NDSSFCLoadCheatFile(const char* filename) { for (c = 0; c < num_bytes; c++) { S9xAddCheat (FALSE, TRUE, address + c, bytes[c]); - strncpy (Cheat.c[Cheat.num_cheats - 1].name, description, 22); + strncpy (Cheat.c[Cheat.num_cheats - 1].name, description, MAX_SFCCHEAT_NAME); } } else { diff --git a/source/nds/gui.c b/source/nds/gui.c index 84f522f..1b265b6 100644 --- a/source/nds/gui.c +++ b/source/nds/gui.c @@ -2618,10 +2618,12 @@ u32 menu(u16 *screen) if(load_file(file_ext, tmp_filename, DEFAULT_CHEAT_DIR) != -1) { - strcpy(line_buffer, DEFAULT_CHEAT_DIR); - strcat(line_buffer, "/"); - strcat(line_buffer, tmp_filename); + sprintf(line_buffer, "%s/%s", DEFAULT_CHEAT_DIR, tmp_filename); flag = NDSSFCLoadCheatFile(line_buffer); + + strcpy(line_buffer, (char *) S9xGetFilename (".chb")); + S9xSaveCheatFile (line_buffer); // cheat binary + if(0 != flag) { //load cheat file failure S9xDeleteCheats(); @@ -2630,12 +2632,9 @@ u32 menu(u16 *screen) return; } - strcpy(line_buffer, (char *) S9xGetFilename (".chb")); - - S9xSaveCheatFile (line_buffer); // cheat binary - menu_cheat_page = 0; cheat_menu_init(); + } } |