diff --git a/include/debug_mode.h b/include/debug_mode.h index 7421aab..836c247 100644 --- a/include/debug_mode.h +++ b/include/debug_mode.h @@ -2,7 +2,7 @@ #define DEBUG_MODE_H #define DEBUG_MODE true -#define IGNORE_GAME_PAK true +#define IGNORE_GAME_PAK false #define IGNORE_LINK_CABLE true #define DEBUG_GAME SAPPHIRE_ID #define DEBUG_VERS VERS_1_0 diff --git a/include/flash_mem.h b/include/flash_mem.h index bb01ca7..028e62d 100644 --- a/include/flash_mem.h +++ b/include/flash_mem.h @@ -20,7 +20,7 @@ void initalize_memory_locations(); void print_mem_section(); //bool insert_pokemon(Pokemon party_array[], int num); void reverse_endian(u8 *data, size_t size); -void update_memory_buffer_checksum(); +void update_memory_buffer_checksum(bool hall_of_fame); bool read_flag(u16 flag_id); bool compare_map_and_npc_data(int map_bank, int map_id, int npc_id); diff --git a/source/flash_mem.cpp b/source/flash_mem.cpp index 7441c3b..0cc2ff4 100644 --- a/source/flash_mem.cpp +++ b/source/flash_mem.cpp @@ -43,6 +43,8 @@ void initalize_memory_locations() } mem_id = (mem_id + 1) % TOTAL_SAVE_SECTIONS; } + // Bring the Memory ID back to the first one + mem_id = (mem_id + 1) % TOTAL_SAVE_SECTIONS; if (false) // This will print out a section of the FLASH mem for debugging purposes { @@ -55,9 +57,12 @@ void initalize_memory_locations() tte_write("\n"); for (int i = mem_start; i < (128 + mem_start); i++) { - if (i % 2 == 0){ + if (i % 2 == 0) + { tte_write("#{cx:0xE000}"); - } else { + } + else + { tte_write("#{cx:0xD000}"); } tte_write(std::to_string(global_memory_buffer[i]).c_str()); @@ -170,7 +175,7 @@ bool insert_pokemon(Pokemon party[], int total_num) */ // Updates the checksum in the current memory buffer to match what is expected -void update_memory_buffer_checksum() +void update_memory_buffer_checksum(bool hall_of_fame) { vu32 checksum = 0x00; @@ -186,8 +191,16 @@ void update_memory_buffer_checksum() } vu16 small_checksum = ((checksum & 0xFFFF0000) >> 16) + (checksum & 0x0000FFFF); - global_memory_buffer[0x0FF6] = small_checksum & 0x00FF; - global_memory_buffer[0x0FF7] = (small_checksum & 0xFF00) >> 8; + if (hall_of_fame) + { + global_memory_buffer[0x0FF4] = small_checksum & 0x00FF; + global_memory_buffer[0x0FF5] = (small_checksum & 0xFF00) >> 8; + } + else + { + global_memory_buffer[0x0FF6] = small_checksum & 0x00FF; + global_memory_buffer[0x0FF7] = (small_checksum & 0xFF00) >> 8; + } } bool read_flag(u16 flag_id) diff --git a/source/main.cpp b/source/main.cpp index 26b37cf..a69f527 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -57,7 +57,7 @@ bool skip = true; rom_data curr_rom; /* -int test_main(void) +int test_main(void) Music { irq_init(NULL); @@ -96,7 +96,6 @@ void initalization_script(void) irq_init(NULL); irq_enable(II_VBLANK); - flash_init(FLASH_SIZE_128KB); rand_set_seed(0x1216); add_script_party_var(party); @@ -188,12 +187,10 @@ void game_load_error(void) void first_load_message(void) { - while (key_is_down(KEY_A)) - { - }; // Wait until A is no longer being held tte_set_pos(8, 0); tte_set_ink(10); tte_write("#{cx:0xE000}Hello! Thank you for using\nPok@mon Mirror!\n\nJust as a word of caution- \nPok@mon Mirror WILL modify\nyour generation 3 save file.\nThe program is designed to\nnot corrupt anything, but if\nyou do not wish to modify\nyour save file, please turn\noff your Game Boy Advance.\n\nPlease note that Pok@mon\nMirror is still in beta, so\nsave file backups are HIGHLY\nrecommended before using.\nWith that all out of the\nway, please enjoy!\n\n -The Gears of Progress"); + key_poll(); while (!key_hit(KEY_A)) { key_poll(); @@ -214,13 +211,14 @@ int main(void) } // Initalize memory and save data after loading the game + flash_init(FLASH_SIZE_128KB); initalize_memory_locations(); load_custom_save_data(); if (get_tutorial_flag() == false) { first_load_message(); - initalize_save_data(); + // initalize_save_data(); } // Legal mumbo jumbo @@ -264,11 +262,10 @@ int main(void) int old_lang_btn_num = -1; set_arrow_point(curr_lang_btn_num); -#define CREDITS_ARRAY_SIZE 14 +#define CREDITS_ARRAY_SIZE 13 int curr_credits_num = 0; std::string credits_array[CREDITS_ARRAY_SIZE] = { - "Developed by:\n\n\nThe Gears\nof Progress", - "Developed using\nlibTONC from\ndevkitPro", + "Developed by:\n\n\nThe Gears\nof Progress\n\nusing libTONC from\ndevkitPro", "Inspired by the\nworks of:\n\n-Goppier\n-Lorenzooone\n-im a blissey\n-RETIRE", "Programs used:\n\n\n-HexManiacAdvance\n-PKHeX\n-WC3Tool\n-Usenti\n", "Open Source Code and\nLibraries:\n\n-libtonc-examples\n-libsavgba\n-gba-link-connection\n-awesome-gbadev\n-arduino-poke-gen2", @@ -386,13 +383,4 @@ int main(void) // mmFrame(); //Music global_next_frame(); } -} - -/*Credits: -https://github.com/laqieer/libsavgba -https://github.com/rodri042/gba-link-connection -arduino-boy - -Notes: -- GBA and GBC link cables are different, that's why it didn't work initally on mGBA -*/ +} \ No newline at end of file diff --git a/source/mystery_gift_injector.cpp b/source/mystery_gift_injector.cpp index fcac885..3bed9f1 100644 --- a/source/mystery_gift_injector.cpp +++ b/source/mystery_gift_injector.cpp @@ -62,8 +62,21 @@ bool inject_mystery(Pokemon incoming_party_array[]) { global_memory_buffer[curr_rom.offset_script + 4 + i] = script.get_script_value_at(i); } - update_memory_buffer_checksum(); - flash_write(memory_section_array[4], &global_memory_buffer[0], 0x1000); + update_memory_buffer_checksum(false); +int out = flash_write(memory_section_array[4], &global_memory_buffer[0], 0x1000); + if (out != 0 && DEBUG_MODE) + { + tte_set_pos(0, 0); + tte_write("error writing script data: "); + tte_write(std::to_string(out).c_str()); + key_poll(); + VBlankIntrWait(); + while (!key_hit(KEY_SELECT)) + { + key_poll(); + VBlankIntrWait(); + } + } // Set flags flash_read(memory_section_array[1 + ((curr_rom.offset_flags + (FLAG_ID_START / 8)) / 0xF80)], &global_memory_buffer[0], 0x1000); @@ -76,8 +89,21 @@ bool inject_mystery(Pokemon incoming_party_array[]) } } - update_memory_buffer_checksum(); - flash_write(memory_section_array[1 + ((curr_rom.offset_flags + (FLAG_ID_START / 8)) / 0xF80)], &global_memory_buffer[0], 0x1000); + update_memory_buffer_checksum(false); + out = flash_write(memory_section_array[1 + ((curr_rom.offset_flags + (FLAG_ID_START / 8)) / 0xF80)], &global_memory_buffer[0], 0x1000); + if (out != 0 && DEBUG_MODE) + { + tte_set_pos(0, 0); + tte_write("error writing flags: "); + tte_write(std::to_string(out).c_str()); + key_poll(); + VBlankIntrWait(); + while (!key_hit(KEY_SELECT)) + { + key_poll(); + VBlankIntrWait(); + } + } // Update and save custom save data for (int i = 0; i < 6; i++) diff --git a/source/save_data_manager.cpp b/source/save_data_manager.cpp index ce3b5d2..4b72223 100644 --- a/source/save_data_manager.cpp +++ b/source/save_data_manager.cpp @@ -24,7 +24,21 @@ void write_custom_save_data() { global_memory_buffer[HOF_SECTION + i] = save_data_array[i]; } - flash_write(HALL_OF_FAME + 0x1000, &global_memory_buffer[0], 0x1000); + update_memory_buffer_checksum(true); + int out = flash_write(HALL_OF_FAME + 0x1000, &global_memory_buffer[0], 0x1000); + if (out != 0 && DEBUG_MODE) + { + tte_set_pos(0, 0); + tte_write("error writing custom save data: "); + tte_write(std::to_string(out).c_str()); + key_poll(); + VBlankIntrWait(); + while (!key_hit(KEY_SELECT)) + { + key_poll(); + VBlankIntrWait(); + } + } } bool is_caught(int dex_num) @@ -86,4 +100,4 @@ void initalize_save_data() save_data_array[i] = 0; } write_custom_save_data(); -} +} \ No newline at end of file diff --git a/source/script_array.cpp b/source/script_array.cpp index 9cf2c51..46f1260 100644 --- a/source/script_array.cpp +++ b/source/script_array.cpp @@ -14,18 +14,18 @@ std::string_view dialogue[DIA_SIZE]; void populate_dialogue() { - dialogue[DIA_OPEN] = "Hey there! I'm Professor\nFennel. As you can see, I'm\na scientist.|In fact, the subject I'm \nresearching is Trainers!|My dream is to collect save files of various trainers, \nbut I haven't had any \nbreakthroughs yet...|So in the meantime, I have a\ndifferent project!|In my home region, there's a\nlocation that can make a\nPokemon's dreams into\nreality.|This means that any other\nPokemon they meet in their\ndreams become real!|That's fantastic, but my\ngoal is to do the same-\njust with a trainer's dream\ninstead!|I've successfully been able\nto send a Pokemon into\nand out of a trainer's\ndream...|but I've been unsuccessful\nin pulling out a new Pokemon\nwithout...\ncatastrophic results.|That's when I had a\nbreakthrough- I realized if \nI sent in a DITTO,|it could transform into the\nPokemon found within that\ntrainer's dream!|That's why I need your help!\nI want to bring as many\nPokemon out of your dreams\nas possible!|There's just over 250\nPokemon I want to catalogue\nin my Dream Pokedex-\nor Dream Dex for short.|But I'll let you keep any\nPokemon- they're from your\ndreams after all!|I think that's everything...\nwhenever you're ready to\nstart, just let me know!"; + dialogue[DIA_OPEN] = "Hey there! I'm Professor\nFennel. As you can see, I'm\na scientist.|In fact, the subject I'm \nresearching is Trainers!|My dream is to collect save files of various trainers, \nbut I haven't had any \nbreakthroughs yet...|So in the meantime, I have a\ndifferent project!|In my home region, there's a\nlocation that can make a\nPok@mon's dreams into\nreality.|This means that any other\nPok@mon they meet in their\ndreams become real!|That's fantastic, but my\ngoal is to do the same-\njust with a trainer's dream\ninstead!|I've successfully been able\nto send a Pok@mon into\nand out of a trainer's\ndream...|but I've been unsuccessful\nin pulling out a new Pok@mon\nwithout...\ncatastrophic results.|That's when I had a\nbreakthrough- I realized if \nI sent in a DITTO,|it could transform into the\nPok@mon found within that\ntrainer's dream!|That's why I need your help!\nI want to bring as many\nPok@mon out of your dreams\nas possible!|There's just over 250\nPok@mon I want to catalogue\nin my Dream Pok@Dex-\nor Dream Dex for short.|But I'll let you keep any\nPok@mon- they're from your\ndreams after all!|I think that's everything...\nwhenever you're ready to\nstart, just let me know!"; dialogue[DIA_E4] = "Hi trainer! I'm thrilled\nyou've decided to help with our research, but we need\nthe best of the best!|Come back after you've\nbeaten the Elite Four and\nbecome the Champion!"; dialogue[DIA_MG_FRLGE] = "Sorry trainer, one more\nthing to take care of before\nwe can begin- you need to\nenable MYSTERY GIFT!|Head to the nearest Pok@\nMart and fill out the\nquestionnaire as follows:\nLINK TOGETHER WITH ALL|After that, you should be\nall set to go!|See you soon!"; dialogue[DIA_MG_RS] = "Sorry trainer, one more\nthing to take care of before\nwe can begin- you need to\nenable MYSTERY EVENT!|Head to the PETALBURG\nPok@mon Center and tell the\nman next to the PC:\nMYSTERY EVENT IS EXCITING|After that, you should be\nall set to go!|See you soon!"; dialogue[DIA_LETS_START] = "Let's get started!"; - dialogue[DIA_START] = "On a second Game Boy family\nsystem, please load the Game\nBoy Pok@mon game you wish to\ntransfer from.|In your Game Boy Pok@mon\ngame, put any Pokemon you\nwant to bring out of\nyour dreams into your party.|Then connect this Game Boy\nAdvance to the other Game\nBoy family system using a\nGame Boy Color link cable.|Once you're ready, press A\non this device, talk to the Cable Club attendant, and\nthen initiate a trade."; - dialogue[DIA_TRANS_GOOD] = "Amazing! Fantastic!\nEverything went perfectly!|You may now turn off your Game Boy family system."; - dialogue[DIA_NEW_DEX] = "It looks like there's at\nleast one new Pokemon here\nthat isn't in the Dream Dex!|I'll give them something\nextra sweet as a reward for you both."; + dialogue[DIA_START] = "On a second Game Boy family\nsystem, please load the Game\nBoy Pok@mon game you wish to\ntransfer from.|In your Game Boy Pok@mon\ngame, put any Pok@mon you\nwant to bring out of\nyour dreams into your party.|Then connect this Game Boy\nAdvance to the other Game\nBoy family system using a\nGame Boy Color link cable.|Once you're ready, press A\non this device, talk to the Cable Club attendant, and\nthen initiate a trade."; + dialogue[DIA_TRANS_GOOD] = "Amazing! Fantastic!\nEverything went perfectly!|You may now turn off your\nGame Boy family system."; + dialogue[DIA_NEW_DEX] = "It looks like there's at\nleast one new Pok@mon here\nthat isn't in the Dream Dex!|I'll give them something\nextra sweet as a reward for you both."; dialogue[DIA_NO_NEW_DEX] = "It doesn't look like there's\nanything new for your Dream\nDex, but that's okay!|It's important to confirm\nresearch results with\nmultiple tests!"; - dialogue[DIA_SEND_FRIEND_KANTO] = "I'm going to send these\nPokemon to my friend BILL so\nthat you can pick them up.\nThey live on Route 25!|Did you know they developed the Storage System for the\nKanto region?|My younger sister developed a version of the Storage\nSystem too, so BILL is a\ngood friend of ours!"; - dialogue[DIA_SEND_FRIEND_HOENN] = "I'm going to send these\nPokemon to my friend LANNETE\nso that you can pick them\nup. They live on route 114!|Did you know they developed the Storage System for the\nHoenn region?|My younger sister developed a version of the Storage\nSystem too, so LANNETE is a\ngood friend of ours!"; - dialogue[DIA_THANK] = "Thank you so much for your\nhelp! Whenever you want to\ntransfer more Pokemon, just\nlet me know!|See you around!"; + dialogue[DIA_SEND_FRIEND_KANTO] = "I'm going to send these\nPok@mon to my friend BILL so\nthat you can pick them up.\nThey live on Route 25!|Did you know they developed the Storage System for the\nKanto region?|My younger sister developed a version of the Storage\nSystem too, so BILL is a\ngood friend of ours!"; + dialogue[DIA_SEND_FRIEND_HOENN] = "I'm going to send these\nPok@mon to my friend LANNETE\nso that you can pick them\nup. They live on route 114!|Did you know they developed the Storage System for the\nHoenn region?|My younger sister developed a version of the Storage\nSystem too, so LANNETE is a\ngood friend of ours!"; + dialogue[DIA_THANK] = "Thank you so much for your\nhelp! Whenever you want to\ntransfer more Pok@mon, just\nlet me know!|See you around!"; dialogue[DIA_GET_MON] = "Let's get started! Please connect Load the Game Boy Pok@mon game you want to transfer from, and put the Pok@mon you want to transfer into your party. "; dialogue[DIA_MG_OTHER_EVENT] = "Hi Trainer! It looks like\nyou have a different event\ncurrently loaded.|That's no problem, but it\nwill be overwritten if you\ncontinue.|Turn off the system now if\nyou want to experience your\ncurrent event,\nbut otherwise-"; dialogue[DIA_PKMN_TO_COLLECT] = "Hi Trainer! It looks like\nyou still have Pok@mon to\npick up...|I can send in new ones, but do know that the Pok@mon you\nhaven't picked up yet will\nbe replaced.|Turn off the system now if\nyou want to recieve those\nPok@mon, but otherwise-";