From 13450924c26ce367ef3f5bff10fa03dcb4869da4 Mon Sep 17 00:00:00 2001 From: Remnants of Forgotten Disney Date: Fri, 29 Mar 2024 23:39:58 -0500 Subject: [PATCH] Implementing new payload system --- include/debug_mode.h | 4 +- include/gameboy_colour.h | 7 +- include/payload.h | 10 -- include/payloads/base_payload_struct.h | 18 ++++ include/payloads/eng_payloads.h | 98 ++++++++++++++++++ include/pokemon_data.h | 9 +- include/pokemon_party.h | 3 + .../{rom_values_eng.h => eng_rom_values.h} | 0 include/script_array.h | 6 +- source/gameboy_colour.cpp | 21 ++-- source/main.cpp | 1 + source/payload.cpp | 99 ------------------- source/pokemon.cpp | 14 ++- source/pokemon_party.cpp | 20 +++- source/rom_data.cpp | 2 +- source/script_array.cpp | 72 ++++++++------ 16 files changed, 214 insertions(+), 170 deletions(-) delete mode 100644 include/payload.h create mode 100644 include/payloads/base_payload_struct.h create mode 100644 include/payloads/eng_payloads.h rename include/rom_values/{rom_values_eng.h => eng_rom_values.h} (100%) delete mode 100644 source/payload.cpp diff --git a/include/debug_mode.h b/include/debug_mode.h index da1355e..5430df2 100644 --- a/include/debug_mode.h +++ b/include/debug_mode.h @@ -2,8 +2,8 @@ #define DEBUG_MODE_H #define DEBUG_MODE true -#define IGNORE_GAME_PAK true -#define IGNORE_LINK_CABLE true +#define IGNORE_GAME_PAK false +#define IGNORE_LINK_CABLE false #define IGNORE_MG_E4_FLAGS true #define DEBUG_GAME RUBY_ID diff --git a/include/gameboy_colour.h b/include/gameboy_colour.h index 204dcd9..fcbdc3f 100644 --- a/include/gameboy_colour.h +++ b/include/gameboy_colour.h @@ -6,6 +6,7 @@ #include #include #include "libraries/gba-link-connection/LinkSPI.hpp" +#include "pokemon_party.h" /* #define LINK_SPI_NO_DATA 0xffffffff @@ -31,12 +32,12 @@ #define SLOW_SPEED 1000 void setup(); -byte handleIncomingByte(byte in, byte* party_data); +byte handleIncomingByte(byte in, byte *box_data_storage, PAYLOAD *curr_payload); int transferBit(byte *party_data); -int loop(byte *party_data); +int loop(byte *box_data_storage, PAYLOAD *curr_payload); std::string outHexStr(vu8 inputNum); void updateFrames(); -byte exchange_parties(byte); +byte exchange_parties(byte curr_in, PAYLOAD *curr_payload); byte exchange_boxes(byte curr_in, byte *party_data); #endif /* GAMEBOY_COLOUR_H_ */ diff --git a/include/payload.h b/include/payload.h deleted file mode 100644 index f7e8ef4..0000000 --- a/include/payload.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef PAYLOAD_H -#define PAYLOAD_H - -#include -#include "output.h" - -#define PAYLOAD_SIZE 637 -extern byte gen1_eng_payload[637]; - -#endif \ No newline at end of file diff --git a/include/payloads/base_payload_struct.h b/include/payloads/base_payload_struct.h new file mode 100644 index 0000000..23276de --- /dev/null +++ b/include/payloads/base_payload_struct.h @@ -0,0 +1,18 @@ +#ifndef PAYLOAD_H +#define PAYLOAD_H + +#include +#include "output.h" + +#define PAYLOAD_SIZE 637 +#define NUM_PAYLOADS 1 + +struct PAYLOAD +{ +public: + int language; + int version; + byte payload_array[PAYLOAD_SIZE]; +}; + +#endif \ No newline at end of file diff --git a/include/payloads/eng_payloads.h b/include/payloads/eng_payloads.h new file mode 100644 index 0000000..3d37177 --- /dev/null +++ b/include/payloads/eng_payloads.h @@ -0,0 +1,98 @@ +#include + +#include "payloads/base_payload_struct.h" +#include "pokemon_data.h" + +const struct PAYLOAD ENG_RED_BLUE = { + .language = ENG_ID, + .version = RED_BLUE_ID, + .payload_array = { + // RNG Seed + 0, 0, 0, 0, 0, 0xCD, 0x87, 0xD8, 184, 165, + + // Preamble + 253, 253, 253, 253, 253, 253, 253, 253, + + // Party (bootstrap) + //// Rival name + 248, 0, 54, 253, 1, 62, 88, 197, 195, 214, 197, + // num of Pokemon + 6, + // Pokemon list + 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE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54, 17, 24, 218, 33, 89, 196, 205, 85, 25, 195, 21, 218, 139, 142, 128, 131, 136, 141, 134, 232, 232, 232, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 64, 0, 0, + + // Patchlist preamble + 253, 253, 253, 253, 253, 255, 255, + + // Patchlist (code storage) + // Test string: 62, 99, 245, 33, 160, 195, 1, 136, 1, 205, 224, 54, 17, 255, 197, 33, 87, 196, 205, 85, 25, 118, 118, 118, 118, 118, 118, 118, 241, 60, 14, 108, 185, 194, 216, 197, 62, 99, 195, 216, 197, 127, 0x8E, 0x8C, 0x86, 127, 0x92, 0x8E, 0x91, 0x80, 0xE6, 0xE7, 0xE6, 0xE7, 127, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, + + // call ClearScreen + 0xCD, 0x0F, 0x19, + // hlcoord 2, 7 + 0x21, 0x2E, 0xC4, + // ld b, 3 [height] + 0x06, 0x03, + // ld c, 14 [width] + 0x0E, 0x0E, + // call CableClub_TextBoxBoarder + 0xCD, 0xB3, 0x5A, + // hlcoord 3, 8 + 0x21, 0x43, 0xC4, + // ld de, TransferWaitString + 0x11, 0x7A, 0xC6, + // call PlaceString + 0xCD, 0x55, 0x19, + + // ld hl, hSerialConnectionStatus + 0x21, 0xAA, 0xFF, + // ld [hl], 0x01 [Make sure GB is the slave] + 0x36, 0x01, + // ld hl, (wBoxDataStart - 1) [data to send] + 0x21, 0x7F, 0xDA, + // ld [hl], 0xFD [set the start of the data to 0xFD so Serial_ExchangeBytes is happy] + 0x36, 0xFD, + // ld de, (wBoxDataStart - 3) [location to put stored data] + 0x11, 0x7D, 0xDA, + // ld bc, (wBoxDataEnd - wBoxDataStart) + 2 + 0x01, 0x64, 0x04, + // call Serial_ExchangeBytes + 0xCD, 0x6F, 0x21, + + // ld hl, SaveSAVtoSRAM1 + 0x21, 0xE2, 0x77, + // ld b, 0x1C [memory bank of SaveSAVtoSRAM1] + 0x06, 0x1C, + // call Bankswitch + 0xCD, 0xD6, 0x35, + // jp SoftReset + 0xC3, 0x49, 0x1F, + + // TransferWaitString 0xC67A + // 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, + + // 0x00, 0x00 // The last two bites are not used + + // This payload works by placing Pokemon ID 0xFC's name in the stack, and causing a return to CD8E, + // which is part of the RNG seed. From there we can jump anywhere- and we choose to jump to D887, + // which is the rival's name. This code fixes the stack and jumps to the patchlist, which is where + // our final code is. + }}; \ No newline at end of file diff --git a/include/pokemon_data.h b/include/pokemon_data.h index 509a953..af25ec6 100644 --- a/include/pokemon_data.h +++ b/include/pokemon_data.h @@ -20,13 +20,12 @@ #define SPA_ID 7 #define KOR_ID 8 -#define GREEN_ID 0 -#define RED_ID 1 +#define RED_GREEN_ID 0 +#define RED_BLUE_ID 1 #define BLUE_ID 2 #define YELLOW_ID 3 -#define GOLD_ID 4 -#define SILVER_ID 5 -#define CRYSTAL_ID 6 +#define GOLD_SILVER_ID 4 +#define CRYSTAL_ID 5 #define MAX_PKMN_IN_BOX 30 diff --git a/include/pokemon_party.h b/include/pokemon_party.h index c76bc2d..41dde5f 100644 --- a/include/pokemon_party.h +++ b/include/pokemon_party.h @@ -3,6 +3,7 @@ #include #include "pokemon.h" +#include "payloads/eng_payloads.h" #define BOX_DATA_ARRAY_SIZE 0x462 @@ -17,6 +18,8 @@ public: void set_game(int nGame); void set_lang(int nLang); int get_lang(); + bool load_payload(); + PAYLOAD curr_payload; private: byte box_data_array[0x462]; diff --git a/include/rom_values/rom_values_eng.h b/include/rom_values/eng_rom_values.h similarity index 100% rename from include/rom_values/rom_values_eng.h rename to include/rom_values/eng_rom_values.h diff --git a/include/script_array.h b/include/script_array.h index 5947d4e..53f9f97 100644 --- a/include/script_array.h +++ b/include/script_array.h @@ -33,8 +33,9 @@ #define DIA_WHAT_GAME 24 #define DIA_WHAT_LANG 25 #define DIA_ASK_QUEST 26 +#define DIA_NO_PAYLOAD 27 -#define DIA_SIZE 27 +#define DIA_SIZE 28 #define DIA_END DIA_SIZE // Commands @@ -68,8 +69,9 @@ #define COND_IS_FRLGE CMDS_END + 10 #define COND_MG_OTHER_EVENT CMDS_END + 11 #define COND_PKMN_TO_COLLECT CMDS_END + 12 +#define COND_PAYLOAD_EXISTS CMDS_END + 13 -#define COND_SIZE 13 +#define COND_SIZE 14 #define COND_END CMDS_END + COND_SIZE // Ends diff --git a/source/gameboy_colour.cpp b/source/gameboy_colour.cpp index 07fa27c..a1119e2 100644 --- a/source/gameboy_colour.cpp +++ b/source/gameboy_colour.cpp @@ -8,10 +8,10 @@ #include "output.h" #include "script_array.h" #include "debug_mode.h" -#include "payload.h" #include "interrupt.h" #include "text_engine.h" #include "global_frame_controller.h" +#include "payloads/base_payload_struct.h" #define TIMEOUT 2 #define TIMEOUT_ONE_LENGTH 1000000 // Maybe keep a 10:1 ratio between ONE and TWO? @@ -50,7 +50,7 @@ int FF_count; int zero_count; int state; -int mosi_delay = 3; // inital delay, speeds up once sending PKMN +int mosi_delay = 4; // inital delay, speeds up once sending PKMN std::string out_array[10]; @@ -104,7 +104,7 @@ void setup() } } -byte handleIncomingByte(byte in, byte *box_data_storage) +byte handleIncomingByte(byte in, byte *box_data_storage, PAYLOAD *curr_payload) { if (state == hs) { @@ -142,7 +142,6 @@ byte handleIncomingByte(byte in, byte *box_data_storage) if (in == 0xfd) { state = party_preamble; - mosi_delay = 0; } return in; } @@ -152,7 +151,7 @@ byte handleIncomingByte(byte in, byte *box_data_storage) if (in != 0xfd) { state = trade_data; - return exchange_parties(in); + return exchange_parties(in, curr_payload); } return in; } @@ -163,7 +162,7 @@ byte handleIncomingByte(byte in, byte *box_data_storage) { state = box_preamble; } - return exchange_parties(in); + return exchange_parties(in, curr_payload); } else if (state == box_preamble) @@ -190,7 +189,7 @@ byte handleIncomingByte(byte in, byte *box_data_storage) return in; } -int loop(byte *box_data_storage) +int loop(byte *box_data_storage, PAYLOAD *curr_payload) { int counter = 0; while (true) @@ -207,7 +206,7 @@ int loop(byte *box_data_storage) std::to_string(in_data) + "][" + std::to_string(out_data) + "]\n"); } - out_data = handleIncomingByte(in_data, box_data_storage); + out_data = handleIncomingByte(in_data, box_data_storage, curr_payload); if (FF_count > 25) { @@ -244,9 +243,9 @@ int loop(byte *box_data_storage) } }; -byte exchange_parties(byte curr_in) +byte exchange_parties(byte curr_in, PAYLOAD *curr_payload) { - int ret = gen1_eng_payload[data_counter]; + int ret = curr_payload->payload_array[data_counter]; data_counter += 1; return ret; }; @@ -256,4 +255,4 @@ byte exchange_boxes(byte curr_in, byte *box_data_storage) box_data_storage[data_counter] = curr_in; data_counter += 1; return curr_in; -}; +}; \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 1ae0cda..e8dded5 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -98,6 +98,7 @@ void load_graphics() load_eternal_sprites(); // Set up main menu + main_menu.clear_vector(); main_menu.add_button(Button(btn_t_l, btn_t_r, 48), BTN_TRANSFER); main_menu.add_button(Button(btn_p_l, btn_p_r, 48), BTN_POKEDEX); //main_menu.add_button(Button(btn_d_l, btn_d_r), BTN_LANGUAGE); diff --git a/source/payload.cpp b/source/payload.cpp deleted file mode 100644 index 399d987..0000000 --- a/source/payload.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include - -#include "payload.h" - -byte gen1_eng_payload[PAYLOAD_SIZE] = { - // RNG Seed - 0, 0, 0, 0, 0, 0xCD, 0x87, 0xD8, 184, 165, - - // Preamble - 253, 253, 253, 253, 253, 253, 253, 253, - - // Party (bootstrap) - //// Rival name - 248, 0, 54, 253, 1, 62, 88, 197, 195, 214, 197, - // num of Pokemon - 6, - // Pokemon list - 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0xE3, 0x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 62, 0, 205, 224, 54, 17, 24, 218, 33, 89, 196, 205, 85, 25, 195, 21, 218, 139, 142, 128, 131, 136, 141, 134, 232, 232, 232, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 64, 0, 0, - - // Patchlist preamble - 253, 253, 253, 253, 253, 255, 255, - - // Patchlist (code storage) - // Test string: 62, 99, 245, 33, 160, 195, 1, 136, 1, 205, 224, 54, 17, 255, 197, 33, 87, 196, 205, 85, 25, 118, 118, 118, 118, 118, 118, 118, 241, 60, 14, 108, 185, 194, 216, 197, 62, 99, 195, 216, 197, 127, 0x8E, 0x8C, 0x86, 127, 0x92, 0x8E, 0x91, 0x80, 0xE6, 0xE7, 0xE6, 0xE7, 127, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, - - - - - - - // call ClearScreen - 0xCD, 0x0F, 0x19, - // hlcoord 2, 7 - 0x21, 0x2E, 0xC4, - // ld b, 3 [height] - 0x06, 0x03, - // ld c, 14 [width] - 0x0E, 0x0E, - // call CableClub_TextBoxBoarder - 0xCD, 0xB3, 0x5A, - // hlcoord 3, 8 - 0x21, 0x43, 0xC4, - // ld de, TransferWaitString - 0x11, 0x7A, 0xC6, - // call PlaceString - 0xCD, 0x55, 0x19, - - // ld hl, hSerialConnectionStatus - 0x21, 0xAA , 0xFF, - // ld [hl], 0x01 [Make sure GB is the slave] - 0x36, 0x01, - // ld hl, (wBoxDataStart - 1) [data to send] - 0x21, 0x7F, 0xDA, - // ld [hl], 0xFD [set the start of the data to 0xFD so Serial_ExchangeBytes is happy] - 0x36, 0xFD, - // ld de, (wBoxDataStart - 3) [location to put stored data] - 0x11, 0x7D, 0xDA, - // ld bc, (wBoxDataEnd - wBoxDataStart) + 2 - 0x01, 0x64, 0x04, - // call Serial_ExchangeBytes - 0xCD, 0x6F, 0x21, - - // ld hl, SaveSAVtoSRAM1 - 0x21, 0xE2, 0x77, - // ld b, 0x1C [memory bank of SaveSAVtoSRAM1] - 0x06, 0x1C, - // call Bankswitch - 0xCD, 0xD6, 0x35, - // jp SoftReset - 0xC3, 0x49, 0x1F, - - // TransferWaitString 0xC67A - // 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, - - //0x00, 0x00 // The last two bites are not used - - // This payload works by placing Pokemon ID 0xFC's name in the stack, and causing a return to CD8E, - // which is part of the RNG seed. From there we can jump anywhere- and we choose to jump to D887, - // which is the rival's name. This code fixes the stack and jumps to the patchlist, which is where - // our final code is. -}; \ No newline at end of file diff --git a/source/pokemon.cpp b/source/pokemon.cpp index 15d3665..4e2816f 100644 --- a/source/pokemon.cpp +++ b/source/pokemon.cpp @@ -16,8 +16,8 @@ void Pokemon::load_data(int index, byte *party_data, int game, int lang) { switch (game) { - case GREEN_ID: - case RED_ID: + case RED_GREEN_ID: + case RED_BLUE_ID: case BLUE_ID: case YELLOW_ID: gen = 1; @@ -26,8 +26,7 @@ void Pokemon::load_data(int index, byte *party_data, int game, int lang) nickname_size = 6; box_size = 30; break; - case GOLD_ID: - case SILVER_ID: + case GOLD_SILVER_ID: case CRYSTAL_ID: gen = 2; pkmn_size = 48; @@ -41,8 +40,8 @@ void Pokemon::load_data(int index, byte *party_data, int game, int lang) { switch (game) { - case GREEN_ID: - case RED_ID: + case RED_GREEN_ID: + case RED_BLUE_ID: case BLUE_ID: case YELLOW_ID: gen = 1; @@ -51,8 +50,7 @@ void Pokemon::load_data(int index, byte *party_data, int game, int lang) nickname_size = 11; box_size = 20; break; - case GOLD_ID: - case SILVER_ID: + case GOLD_SILVER_ID: case CRYSTAL_ID: gen = 2; pkmn_size = 48; diff --git a/source/pokemon_party.cpp b/source/pokemon_party.cpp index 293c6f8..23fcb73 100644 --- a/source/pokemon_party.cpp +++ b/source/pokemon_party.cpp @@ -4,6 +4,11 @@ #include "flash_mem.h" #include "debug_mode.h" #include "mystery_gift_injector.h" +#include "payloads/base_payload_struct.h" + +const PAYLOAD *list_of_payloads[NUM_PAYLOADS] = { + &ENG_RED_BLUE + }; byte debug_box_data[0x462] = { // Preamble @@ -90,7 +95,7 @@ void Pokemon_Party::start_link() else { setup(); - last_error = loop(&box_data_array[0]); + last_error = loop(&box_data_array[0], &curr_payload); } } @@ -125,4 +130,17 @@ void Pokemon_Party::set_lang(int nLang) int Pokemon_Party::get_lang(){ return lang; +} + +bool Pokemon_Party::load_payload(){ + for (int i = 0; i < NUM_PAYLOADS; i++) + { + if (lang == list_of_payloads[i]->language && + game == list_of_payloads[i]->version) + { + curr_payload = *list_of_payloads[i]; + return true; + } + } + return false; } \ No newline at end of file diff --git a/source/rom_data.cpp b/source/rom_data.cpp index 1e87716..8003fc4 100644 --- a/source/rom_data.cpp +++ b/source/rom_data.cpp @@ -2,7 +2,7 @@ #include "mystery_gift_builder.h" #include "pokemon_party.h" #include "pokemon_data.h" -#include "rom_values/rom_values_eng.h" +#include "rom_values/eng_rom_values.h" rom_data::rom_data() {} bool rom_data::load_rom() diff --git a/source/script_array.cpp b/source/script_array.cpp index c83bffb..6543fd9 100644 --- a/source/script_array.cpp +++ b/source/script_array.cpp @@ -13,7 +13,9 @@ int last_error; Pokemon_Party party_data = Pokemon_Party(); Button_Menu lang_select(2, 4, 40, 24, false); -Button_Menu game_select(2, 2, 72, 32, true); +Button_Menu game_select_def(2, 2, 72, 32, true); +Button_Menu game_select_jpn(3, 2, 72, 32, true); +Button_Menu game_select_kor(1, 1, 72, 32, true); script_obj script[SCRIPT_SIZE]; std::string_view dialogue[DIA_SIZE]; @@ -37,8 +39,9 @@ void populate_dialogue() 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-"; 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_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 transfering\nfrom?"; - dialogue[DIA_WHAT_LANG] = "What language is the Game\nBoy Pok@mon game that you're\ntransfering from?"; + 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?"; + dialogue[DIA_NO_PAYLOAD] = "I'm sorry, but that version\nin that language is not\ncurrently supported."; dialogue[DIA_ERROR_COLOSSEUM] = "It looks like you went to\nthe colosseum instead of the\ntrading room!|Let's try that again!"; dialogue[DIA_ERROR_COM_ENDED] = "Communication with the other\ndevice was terminated.|Let's try that again!"; @@ -70,12 +73,14 @@ void populate_script() script[DIA_START] = script_obj(dialogue[DIA_START], CMD_START_LINK); script[CMD_START_LINK] = script_obj(CMD_START_LINK, COND_ERROR_TIMEOUT_ONE); script[DIA_WHAT_GAME] = script_obj(dialogue[DIA_WHAT_GAME], CMD_GAME_MENU); - script[CMD_GAME_MENU] = script_obj(CMD_GAME_MENU, CMD_SLIDE_PROF_RIGHT, DIA_WHAT_LANG); + script[CMD_GAME_MENU] = script_obj(CMD_GAME_MENU, COND_PAYLOAD_EXISTS, DIA_WHAT_LANG); script[DIA_WHAT_LANG] = script_obj(dialogue[DIA_WHAT_LANG], CMD_LANG_MENU); script[CMD_LANG_MENU] = script_obj(CMD_LANG_MENU, DIA_WHAT_GAME); script[DIA_ASK_QUEST] = script_obj(dialogue[DIA_ASK_QUEST], CMD_SLIDE_PROF_LEFT); script[CMD_SLIDE_PROF_LEFT] = script_obj(CMD_SLIDE_PROF_LEFT, DIA_WHAT_LANG); script[CMD_SLIDE_PROF_RIGHT] = script_obj(CMD_SLIDE_PROF_RIGHT, DIA_LETS_START); + script[COND_PAYLOAD_EXISTS] = script_obj(COND_PAYLOAD_EXISTS, CMD_SLIDE_PROF_RIGHT, DIA_NO_PAYLOAD); + script[DIA_NO_PAYLOAD] = script_obj(dialogue[DIA_NO_PAYLOAD], DIA_WHAT_LANG); // Initiate the transfer and check for errors script[COND_ERROR_TIMEOUT_ONE] = script_obj(COND_ERROR_TIMEOUT_ONE, COND_ERROR_TIMEOUT_TWO, DIA_ERROR_TIME_ONE); @@ -118,31 +123,28 @@ void populate_lang_buttons() lang_select.add_button(Button(btn_lang_spa), SPA_ID); lang_select.add_button(Button(btn_lang_kor), KOR_ID); } + void populate_game_buttons() { - game_select.clear_vector(); - switch (party_data.get_lang()) - { - case JPN_ID: - game_select.set_rows_and_columns(3, 2); - game_select.add_button(Button(button_red_green_left, button_red_green_right, 64), 0); - game_select.add_button(Button(button_blue_left, button_blue_right, 64), 0); - game_select.add_button(Button(button_yellow_left, button_yellow_right, 64), 0); - game_select.add_button(Button(button_gold_silver_left, button_gold_silver_right, 64), 0); - game_select.add_button(Button(button_crystal_left, button_crystal_right, 64), 0); - break; - case KOR_ID: - game_select.set_rows_and_columns(1, 1); - game_select.add_button(Button(button_gold_silver_left, button_gold_silver_right, 64), 0); - break; - default: - game_select.set_rows_and_columns(2, 2); - game_select.add_button(Button(button_red_blue_left, button_red_blue_right, 64), 0); - game_select.add_button(Button(button_yellow_left, button_yellow_right, 64), 0); - game_select.add_button(Button(button_gold_silver_left, button_gold_silver_right, 64), 0); - game_select.add_button(Button(button_crystal_left, button_crystal_right, 64), 0); - } - game_select.set_xy_min_max(48, 240, 0, 120); + game_select_jpn.clear_vector(); + game_select_jpn.add_button(Button(button_red_green_left, button_red_green_right, 64), RED_GREEN_ID); + game_select_jpn.add_button(Button(button_blue_left, button_blue_right, 64), BLUE_ID); + game_select_jpn.add_button(Button(button_yellow_left, button_yellow_right, 64), YELLOW_ID); + game_select_jpn.add_button(Button(button_gold_silver_left, button_gold_silver_right, 64), GOLD_SILVER_ID); + game_select_jpn.add_button(Button(button_crystal_left, button_crystal_right, 64), CRYSTAL_ID); + game_select_jpn.set_xy_min_max(48, 240, 0, 120); + + game_select_kor.clear_vector(); + game_select_kor.add_button(Button(button_gold_silver_left, button_gold_silver_right, 64), GOLD_SILVER_ID); + game_select_kor.set_xy_min_max(48, 240, 0, 120); + + game_select_def.clear_vector(); + game_select_def.set_rows_and_columns(2, 2); + game_select_def.add_button(Button(button_red_blue_left, button_red_blue_right, 64), RED_BLUE_ID); + game_select_def.add_button(Button(button_yellow_left, button_yellow_right, 64), YELLOW_ID); + game_select_def.add_button(Button(button_gold_silver_left, button_gold_silver_right, 64), GOLD_SILVER_ID); + game_select_def.add_button(Button(button_crystal_left, button_crystal_right, 64), CRYSTAL_ID); + game_select_def.set_xy_min_max(48, 240, 0, 120); } bool run_conditional(int index) @@ -231,7 +233,18 @@ bool run_conditional(int index) case CMD_GAME_MENU: load_temp_sprites(SPRITE_BATCH_GAMES); populate_game_buttons(); - game = game_select.button_main(); + switch (party_data.get_lang()) + { + case JPN_ID: + game = game_select_jpn.button_main(); + break; + case KOR_ID: + game = game_select_kor.button_main(); + break; + default: + game = game_select_def.button_main(); + break; + } if (game == BUTTON_CANCEL) { return false; @@ -255,6 +268,9 @@ bool run_conditional(int index) } return true; + case COND_PAYLOAD_EXISTS: + return party_data.load_payload(); + default: tte_set_pos(0, 0); tte_write("ERROR! No conditional found.");