diff --git a/include/gb_rom_values/base_gb_rom_struct.h b/include/gb_rom_values/base_gb_rom_struct.h index 935572f..b89d7dc 100644 --- a/include/gb_rom_values/base_gb_rom_struct.h +++ b/include/gb_rom_values/base_gb_rom_struct.h @@ -8,7 +8,7 @@ typedef unsigned int u32, word, uint, eint; typedef unsigned long long u64; #define PAYLOAD_SIZE 672 -#define NUM_PAYLOADS 2 +#define NUM_PAYLOADS 5 #define GB_TILE_WIDTH 20 @@ -26,6 +26,7 @@ public: hword stack_overwrite_location; // The part of the stack that we're overwriting byte short_pkmn_name; // The name of the Pokemon that moves us through RAM byte pointer_pkmn_name; // The name of the Pokemon that overwrites the stack + hword jump_vector_location; // Where we should jump to in gen 2 to save the box and reset the game hword enter_vector_location; // Where we should jump to from the enter vector // This can be a few different places: // wSerialOtherGameboyRandomNumberListBlock: diff --git a/include/gb_rom_values/eng_gb_rom_values.h b/include/gb_rom_values/eng_gb_rom_values.h index 19579fa..b7574a9 100644 --- a/include/gb_rom_values/eng_gb_rom_values.h +++ b/include/gb_rom_values/eng_gb_rom_values.h @@ -127,6 +127,7 @@ const struct GB_ROM ENG_GOLD = { .stack_overwrite_location = 0xDFCB, // Found by seeing where 772C is stored in the stack, 772C is the code that calls PlaceString .short_pkmn_name = 0x4E, + .jump_vector_location = 0xC7B4, .enter_vector_location = 0xC5D6, .clearScreen = 0x000EE2, @@ -172,6 +173,7 @@ const struct GB_ROM ENG_SILVER = { .stack_overwrite_location = 0xDFCB, // Found by seeing where 772C is stored in the stack, 772C is the code that calls PlaceString .short_pkmn_name = 0x4E, + .jump_vector_location = 0xC7B4, .enter_vector_location = 0xC5D6, .clearScreen = 0x000EE2, @@ -213,17 +215,19 @@ const struct GB_ROM ENG_CRYSTAL = { .payload_size = 672, .box_data_size = 0x44E, - .print_string_start = 0xC4AA, - .stack_overwrite_location = 0xC0BB, // Found by seeing where 772C is stored in the stack, 772C is the code that calls PlaceString + .print_string_start = 0xC544, + .stack_overwrite_location = 0xE0BB, // Found by seeing where 7622 is stored in the stack, 7622 is the code that calls PlaceString (PlaceTradePartnerNamesAndParty) .short_pkmn_name = 0x4E, - .enter_vector_location = 0xC7B4, + + .jump_vector_location = 0xD33C, + .enter_vector_location = 0xC6D6, // wOTPatchLists, plus preamble .clearScreen = 0x000FDB, .CableClub_TextBoxBorder = 0x0A4EEF, // LinkTextboxAtHL .placeString = 0x001078, .Serial_ExchangeBytes = 0x075F, ._RemovePokemon = 0x036039, // RemoveMonFromPartyOrBox - .OpenSRAM = 0x0030E1, + .OpenSRAM = 0x002FCB, .SaveBox = 0x054E0C, .SoftReset = 0x0150, // Reset .garbageDataLocation = 0x0770, @@ -235,17 +239,17 @@ const struct GB_ROM ENG_CRYSTAL = { .wBoxDataStart = 0x01AD10, // sBox .wBoxDataEnd = 0x01B15E, // sBoxEnd - .transferWaitString = 0xC67A, - .pkmnTransferArray = 0xC651, - .arrayCounter = 0xC650, + .transferWaitString = 0xC77A, + .pkmnTransferArray = 0xC751, + .arrayCounter = 0xC750, .transferString = {// TRANSFERRING..\n // PLEASE WAIT! 0x93, 0x91, 0x80, 0x8D, 0x92, 0x85, 0x84, 0x91, 0x91, 0x88, 0x8D, 0x86, 0xF2, 0xF2, 0x4E, 0x7F, 0x8F, 0x8B, 0x84, 0x80, 0x92, 0x84, 0x7F, 0x96, 0x80, 0x88, 0x93, 0xE7, 0x7F, 0x50}, .custom_name = {0x85, 0x84, 0x8D, 0x8D, 0x84, 0x8B, 0x50, 0x50, 0x50, 0x50, 0x50}, - .transferStringLocation = 0xC443, - .textBorderUppLeft = 0xC42E, + .transferStringLocation = 0xC543, + .textBorderUppLeft = 0xC52E, .textBorderWidth = 3, .textBorderHeight = 14, }; diff --git a/include/pokemon.h b/include/pokemon.h index 90bb3cb..0000cf8 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -52,6 +52,8 @@ public: u8 get_nature_from_pid(u32 pid); u8 get_gender_from_pid(u32 pid); void set_to_event(); + int num_in_box; + int index_in_box; private: byte gen = 2; diff --git a/include/pokemon_party.h b/include/pokemon_party.h index 66a56e1..e292c9f 100644 --- a/include/pokemon_party.h +++ b/include/pokemon_party.h @@ -22,9 +22,10 @@ public: void show_sprites(); Simplified_Pokemon simple_pkmn_array[30]; Simplified_Pokemon get_simple_pkmn(int index); - void fill_simple_pkmn_array(); + bool fill_simple_pkmn_array(); bool get_contains_mythical(); void set_mythic_stabilization(bool stabilize); + bool contains_valid = false; private: diff --git a/source/gameboy_colour.cpp b/source/gameboy_colour.cpp index 89c640d..d024810 100644 --- a/source/gameboy_colour.cpp +++ b/source/gameboy_colour.cpp @@ -190,7 +190,7 @@ byte handleIncomingByte(byte in, byte *box_data_storage, byte *curr_payload, GB_ state = trade; } data_counter++; - return 0xD4; + return (curr_gb_rom->generation == 1 ? 0xD4 : 0x61); } else if (state == trade) @@ -340,7 +340,7 @@ int loop(byte *box_data_storage, byte *curr_payload, GB_ROM *curr_gb_rom, Simpli } if (zero_count > (5 * 60)) { - return COND_ERROR_COM_ENDED; + //return COND_ERROR_COM_ENDED; } if (connection_state == COLOSSEUM) { diff --git a/source/payload_builder.cpp b/source/payload_builder.cpp index d7e1b20..a869da7 100644 --- a/source/payload_builder.cpp +++ b/source/payload_builder.cpp @@ -792,7 +792,7 @@ byte *generate_payload(GB_ROM curr_rom, bool debug) } payload_storage[offset++] = curr_rom.enter_vector_location & 0xFF; payload_storage[offset++] = (curr_rom.enter_vector_location >> 8) & 0xFF; - payload_storage[offset++] = 0xFF; + payload_storage[offset++] = 0x50; // Opens the PC box and then crashes- only used for debugging // write_call(curr_rom.generation, payload_storage, offset, 0x0363D8); @@ -1017,8 +1017,8 @@ byte *generate_payload(GB_ROM curr_rom, bool debug) // jp pkmn list (because saving the box overwrites the data) payload_storage[offset++] = 0xC3; - payload_storage[offset++] = (0xC7B4 >> 0) & 0xFF; // This will need to not be hard coded for other languages - payload_storage[offset++] = (0xC7B4 >> 8) & 0xFF; // Ditto ^ + payload_storage[offset++] = (curr_rom.jump_vector_location >> 0) & 0xFF; + payload_storage[offset++] = (curr_rom.jump_vector_location >> 8) & 0xFF; // 72 total bytes of string/array stuff @@ -1092,7 +1092,7 @@ int test_main() { freopen("test_payload.txt", "w", stdout); std::cout << std::endl; - byte *payload = generate_payload(ENG_SILVER, true); + byte *payload = generate_payload(ENG_CRYSTAL, true); for (int i = 0; i < PAYLOAD_SIZE; i++) { std::cout << "0x" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned int)payload[i] << ", "; diff --git a/source/pokemon.cpp b/source/pokemon.cpp index b690ab6..dfa29f8 100644 --- a/source/pokemon.cpp +++ b/source/pokemon.cpp @@ -86,6 +86,9 @@ void Pokemon::load_data(int index, byte *party_data, int game, int lang) (ot_size * box_size) + // the ots (nickname_size * index); // the nickname we're looking for + num_in_box = party_data[0]; + index_in_box = index; + switch (gen) { case 1: @@ -133,9 +136,10 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical) species_index_struct = gen_1_index_array[species_index_struct]; } - if (species_index_struct > 251 || // Checks if the Pokemon is beyond Celebi - species_index_struct == 0 || // Checks that the Pokemon isn't a blank party space - species_index_struct != species_index_party) // Checks that the Pokemon isn't a hybrid or an egg + if (species_index_struct > 251 || // Checks if the Pokemon is beyond Celebi + species_index_struct == 0 || // Checks that the Pokemon isn't a blank party space + species_index_struct != species_index_party || // Checks that the Pokemon isn't a hybrid or an egg + index_in_box >= num_in_box) // Checks that we're not reading beyond the Pokemon in the box { is_valid = false; return; @@ -374,7 +378,7 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical) } data_section_G[0] = species_index_struct; - data_section_G[1] = 0x00; // Species Index, check for glitch Pokemon + data_section_G[1] = 0x00; // Species Index, check for glitch Pokemon data_section_G[2] = (is_new ? 0x44 : 0x00); // Rare Candy if new data_section_G[3] = 0x00; copy_from_to(&exp[0], &data_section_G[4], 3, false); diff --git a/source/pokemon_party.cpp b/source/pokemon_party.cpp index 0e35f37..7c50fbf 100644 --- a/source/pokemon_party.cpp +++ b/source/pokemon_party.cpp @@ -12,9 +12,9 @@ const GB_ROM *list_of_gb_roms[NUM_PAYLOADS] = { &ENG_RED_BLUE, &ENG_YELLOW, - //&ENG_GOLD, - //&ENG_SILVER, - //&ENG_CRYSTAL, + &ENG_GOLD, + &ENG_SILVER, + &ENG_CRYSTAL, }; byte gen1_debug_box_data[0x462] = { @@ -241,7 +241,7 @@ Simplified_Pokemon Pokemon_Party::get_simple_pkmn(int index){ return simple_pkmn_array[index]; } -void Pokemon_Party::fill_simple_pkmn_array(){ +bool Pokemon_Party::fill_simple_pkmn_array(){ for (int index = 0; index < 30; index++){ Pokemon converted_mon; converted_mon.load_data(index, box_data_array, game, lang); @@ -250,5 +250,7 @@ void Pokemon_Party::fill_simple_pkmn_array(){ contains_mythical = contains_mythical || converted_mon.get_dex_number() == 151 || converted_mon.get_dex_number() == 251; simple_pkmn_array[index] = converted_mon.get_simple_pkmn(); + contains_valid |= converted_mon.get_validity(); } + return contains_valid; } \ No newline at end of file diff --git a/source/script_array.cpp b/source/script_array.cpp index 64148bd..e343bbf 100644 --- a/source/script_array.cpp +++ b/source/script_array.cpp @@ -40,7 +40,7 @@ void populate_dialogue() 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't send over new\nPok@mon until you pick those\nup.|Come back after you've\nreceived them!"; - dialogue[DIA_NO_VALID_PKMN] = "Sorry Trainer, it doesn't\nlook like you have any valid\nPok@mon in your party right\nnow.|Double check your party and we'll give it another shot!"; + dialogue[DIA_NO_VALID_PKMN] = "Sorry Trainer, it doesn't\nlook like you have any valid\nPok@mon in your current box\nright now.|Go double check your current\nbox and we can give it\nanother shot!"; dialogue[DIA_ASK_QUEST] = "Hi trainer! Before we begin,\nI need to ask you a few\nquestions."; dialogue[DIA_WHAT_GAME] = "And which Game Boy Pok@mon\ngame are you transferring\nfrom?"; dialogue[DIA_WHAT_LANG] = "What language is the Game\nBoy Pok@mon game that you're\ntransferring from?"; @@ -101,7 +101,8 @@ void populate_script() script[DIA_ERROR_DISCONNECT] = script_obj(dialogue[DIA_ERROR_DISCONNECT], DIA_START); // Pause the transfer and show the user their box data - script[CMD_LOAD_SIMP] = script_obj(CMD_LOAD_SIMP, COND_CHECK_MYTHIC); + script[CMD_LOAD_SIMP] = script_obj(CMD_LOAD_SIMP, COND_CHECK_MYTHIC, DIA_NO_VALID_PKMN); + script[DIA_NO_VALID_PKMN] = script_obj(dialogue[DIA_NO_VALID_PKMN], CMD_CANCEL_LINK); script[COND_CHECK_MYTHIC] = script_obj(COND_CHECK_MYTHIC, DIA_MYTHIC_CONVERT, DIA_IN_BOX); script[DIA_MYTHIC_CONVERT] = script_obj(dialogue[DIA_MYTHIC_CONVERT], CMD_MYTHIC_MENU); script[CMD_MYTHIC_MENU] = script_obj(CMD_MYTHIC_MENU, DIA_IN_BOX); @@ -112,8 +113,7 @@ void populate_script() script[CMD_CANCEL_LINK] = script_obj(CMD_CANCEL_LINK, CMD_END_SCRIPT); // Complete the transfer and give messages based on the transfered Pokemon - script[CMD_IMPORT_POKEMON] = script_obj(CMD_IMPORT_POKEMON, DIA_TRANS_GOOD, DIA_NO_VALID_PKMN); - script[DIA_NO_VALID_PKMN] = script_obj(dialogue[DIA_NO_VALID_PKMN], CMD_END_SCRIPT); + script[CMD_IMPORT_POKEMON] = script_obj(CMD_IMPORT_POKEMON, DIA_TRANS_GOOD); script[DIA_TRANS_GOOD] = script_obj(dialogue[DIA_TRANS_GOOD], COND_NEW_POKEMON); script[COND_NEW_POKEMON] = script_obj(COND_NEW_POKEMON, DIA_NEW_DEX, DIA_NO_NEW_DEX); script[DIA_NEW_DEX] = script_obj(dialogue[DIA_NEW_DEX], COND_IS_HOENN); @@ -231,7 +231,8 @@ bool run_conditional(int index) return true; case CMD_IMPORT_POKEMON: - return inject_mystery(party_data); + inject_mystery(party_data); + return true; case CMD_BACK_TO_MENU: set_text_exit(); @@ -316,8 +317,7 @@ bool run_conditional(int index) return true; case CMD_LOAD_SIMP: - party_data.fill_simple_pkmn_array(); - return true; + return party_data.fill_simple_pkmn_array(); case CMD_CANCEL_LINK: party_data.continue_link(true); diff --git a/source/test_payload.txt b/source/test_payload.txt index d1d9d67..7cfc856 100644 --- a/source/test_payload.txt +++ b/source/test_payload.txt @@ -21,13 +21,13 @@ # 0xA0 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, # 0xB0 -0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, +0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x4E, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, # 0xC0 -0x80, 0x80, 0x80, 0xD6, 0xC5, 0xFF, 0x3E, 0x05, 0xD7, 0xCD, 0xF6, 0x4D, 0xC3, 0xB0, 0x05, 0x00, +0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, # 0xD0 -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xD6, 0xC6, 0x50, 0x3E, 0x05, 0xD7, 0xCD, 0x0C, # 0xE0 -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +0x4E, 0xC3, 0x50, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # 0xF0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # 0x100 @@ -57,21 +57,21 @@ # 0x1C0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, # 0x1D0 -0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFF, 0xFF, 0xCD, 0xE2, +0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFD, 0xFD, 0xFD, 0xFD, 0xFD, 0xFF, 0xFF, 0xCD, 0xDB, # 0x1E0 -0x0E, 0x21, 0x2E, 0xC4, 0x06, 0x03, 0x0E, 0x0E, 0x3E, 0x0A, 0xD7, 0xCD, 0x88, 0x4D, 0x21, 0x43, +0x0F, 0x21, 0x2E, 0xC5, 0x06, 0x03, 0x0E, 0x0E, 0x3E, 0x0A, 0xD7, 0xCD, 0xEF, 0x4E, 0x21, 0x43, # 0x1F0 -0xC4, 0x11, 0x7A, 0xC6, 0xCD, 0x74, 0x0F, 0x21, 0xCD, 0xFF, 0x36, 0x02, 0x3E, 0x01, 0xCD, 0xE1, +0xC5, 0x11, 0x7A, 0xC7, 0xCD, 0x78, 0x10, 0x21, 0xCB, 0xFF, 0x36, 0x02, 0x3E, 0x01, 0xCD, 0xCB, # 0x200 -0x30, 0x21, 0x6B, 0xAD, 0x36, 0xFD, 0x11, 0x6A, 0xAD, 0x01, 0x50, 0x04, 0xCD, 0x10, 0x07, 0x21, +0x2F, 0x21, 0x0F, 0xAD, 0x36, 0xFD, 0x11, 0x0E, 0xAD, 0x01, 0x50, 0x04, 0xCD, 0x5F, 0x07, 0x21, # 0x210 -0xCD, 0xFF, 0x36, 0x02, 0x21, 0x54, 0x06, 0x11, 0x51, 0xC6, 0x01, 0x1E, 0x00, 0x00, 0x00, 0x00, +0xCB, 0xFF, 0x36, 0x02, 0x21, 0x70, 0x07, 0x11, 0x51, 0xC7, 0x01, 0x1E, 0x00, 0x00, 0x00, 0x00, # 0x220 -0x21, 0x08, 0xD0, 0x36, 0x01, 0xFA, 0x50, 0xC6, 0x5F, 0x16, 0x00, 0x21, 0x51, 0xC6, 0x19, 0x3C, +0x21, 0x0B, 0xD1, 0x36, 0x01, 0xFA, 0x50, 0xC7, 0x5F, 0x16, 0x00, 0x21, 0x51, 0xC7, 0x19, 0x3C, # 0x230 -0xEA, 0x50, 0xC6, 0xFA, 0x6C, 0xAD, 0x47, 0x2A, 0xFE, 0xFF, 0x28, 0x0F, 0xB8, 0x30, 0xE6, 0x21, +0xEA, 0x50, 0xC7, 0xFA, 0x10, 0xAD, 0x47, 0x2A, 0xFE, 0xFF, 0x28, 0x0F, 0xB8, 0x30, 0xE6, 0x21, # 0x240 -0x05, 0xD0, 0x77, 0x3E, 0x03, 0xD7, 0xCD, 0x3D, 0x60, 0x18, 0xDA, 0xC3, 0xB4, 0xC7, 0x00, 0x00, +0x09, 0xD1, 0x77, 0x3E, 0x03, 0xD7, 0xCD, 0x39, 0x60, 0x18, 0xDA, 0xC3, 0x3C, 0xD3, 0x00, 0x00, # 0x250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x17, # 0x260