diff --git a/include/debug_mode.h b/include/debug_mode.h index ca59217..7ab039c 100644 --- a/include/debug_mode.h +++ b/include/debug_mode.h @@ -7,7 +7,7 @@ #define DEBUG_MODE false #define PRINT_LINK_DATA (false && DEBUG_MODE) // This is currently broken... not sure why -#define INSTANT_TEXT_SPEED (false && DEBUG_MODE) +#define INSTANT_TEXT_SPEED (true && DEBUG_MODE) #define IGNORE_GAME_PAK (true && DEBUG_MODE) #define IGNORE_LINK_CABLE (true && DEBUG_MODE) #define IGNORE_MG_E4_FLAGS (true && DEBUG_MODE) diff --git a/include/gb_rom_values/base_gb_rom_struct.h b/include/gb_rom_values/base_gb_rom_struct.h index 4ce5398..296e42a 100644 --- a/include/gb_rom_values/base_gb_rom_struct.h +++ b/include/gb_rom_values/base_gb_rom_struct.h @@ -51,38 +51,11 @@ public: word wSerialEnemyDataBlock; // location of wSerialEnemyDataBlock in RAM word wSerialEnemyMonsPatchList; // location of wSerialEnemyMonsPatchList in RAM word wEnemyMonSpecies; // location of wEnemyMonSpecies in RAM - - hword transferStringLocation; // location in VRAM to start writing the transfer string to - hword textBorderUppLeft; // location in VRAM to put the upper left corner of the border - byte textBorderWidth; // the width of the text box border - byte textBorderHeight; // the height of the text box border -}; - -struct BASE_OFFSETS_STRUCT -{ - // This data is used to help determine where a Pokemon starts in the box data - int pkmn_size; - int ot_and_party; - int ot_size; - int nickname_size; - int box_size; - - // This is data for both gens: - u8 species_index; - u8 level; - u8 moves[4]; - u8 OT_ID; - u8 exp; - // HP, Atk, Def, Spe, Spc - u8 evs[5]; - u8 dvs; - u8 pp_values[4]; - - // The rest of these are gen 2 only: - u8 item; - u8 friendship; - u8 pokerus; - u8 caught_data; + + hword transferStringLocation; // location in VRAM to start writing the transfer string to + hword textBorderUppLeft; // location in VRAM to put the upper left corner of the border + byte textBorderWidth; // the width of the text box border + byte textBorderHeight; // the height of the text box border }; #endif \ No newline at end of file diff --git a/include/gb_rom_values/eng_gb_rom_values.h b/include/gb_rom_values/eng_gb_rom_values.h index 2237a53..1eb1399 100644 --- a/include/gb_rom_values/eng_gb_rom_values.h +++ b/include/gb_rom_values/eng_gb_rom_values.h @@ -260,40 +260,4 @@ const struct GB_ROM ENG_CRYSTAL = { .textBorderHeight = 1, }; -const struct BASE_OFFSETS_STRUCT ITL_GEN1_OFFSETS = { - .pkmn_size = 33, - .ot_size = 11, - .nickname_size = 11, - .box_size = 20, - - .species_index = 0x00, - .level = 0x03, - .moves = {0x08, 0x09, 0x0A, 0x0B}, - .OT_ID = 0x0C, - .exp = 0x0E, - .evs = {0x11, 0x13, 0x15, 0x17, 0x19}, - .dvs = 0x1B, - .pp_values = {0x1D, 0x1E, 0x1F, 0x20}, -}; - -const struct BASE_OFFSETS_STRUCT ITL_GEN2_OFFSETS = { - .pkmn_size = 32, - .ot_size = 11, - .nickname_size = 11, - .box_size = 20, - - .species_index = 0x00, - .level = 0x1F, - .moves = {0x02, 0x03, 0x04, 0x05}, - .OT_ID = 0x06, - .exp = 0x08, - .evs = {0x0B, 0x0D, 0x0F, 0x11, 0x13}, - .dvs = 0x15, - .pp_values = {0x17, 0x18, 0x19, 0x1A}, - .item = 0x01, - .friendship = 0x1B, - .pokerus = 0x1C, - .caught_data = 0x1D, -}; - #endif \ No newline at end of file diff --git a/include/pokemon.h b/include/pokemon.h index b7fe2ef..7ed141e 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -4,12 +4,15 @@ #include #include "random.h" #include "global_frame_controller.h" -#include "gb_rom_values/eng_gb_rom_values.h" #define POKEMON_SIZE 80 // How much trade data is sent for each langauge and generation, // sarts at OT name and ends after the 3 buffer bytes +#define GEN1_JPN_SIZE 353 +#define GEN1_INT_SIZE 418 +#define GEN2_JPN_SIZE 383 +#define GEN2_INT_SIZE 444 struct Simplified_Pokemon { @@ -26,13 +29,18 @@ struct Simplified_Pokemon class Pokemon { public: + int pkmn_size = 0; + int ot_and_party = 0; + int ot_size = 0; + int nickname_size = 0; + int nature_mod = 0; + int unown_letter = -1; Pokemon(); - void generate_pkmn(int index, byte *party_data, const GB_ROM curr_rom); - // void load_data(int index, const byte *party_data, int game, int lang); - void convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ROM curr_rom); - // void copy_from_to(const byte *source, byte *destination, int size, bool reverse_endian); - void alocate_data_chunks(byte *G, byte *A, byte *E, byte *M, byte *gen_3_data); - void insert_data(byte *first, byte *second, byte *third, byte *fourth, byte *gen_3_pkmn); + void load_data(int index, const byte *party_data, int game, int lang); + void convert_to_gen_three(bool simplified, bool stabilize_mythical); + void copy_from_to(const byte *source, byte *destination, int size, bool reverse_endian); + void alocate_data_chunks(byte *G, byte *A, byte *E, byte *M); + void insert_data(byte *first, byte *second, byte *third, byte *fourth); byte get_gen_3_data(int index); byte *get_full_gen_3_array(); byte get_unencrypted_data(int index); @@ -78,20 +86,19 @@ private: byte data_section_E[12]; byte data_section_M[12]; hword checksum; - // u8 encryption_key[4]; + byte encryption_key[4]; hword origin_info = 0; bool is_shiny = false; - u8 pp_values[4]; - u8 pp_bonus[4]; - u8 pure_pp_values[4]; - u8 dvs[2]; - u8 ivs[6]; - u32 ribbons; + byte pp_values[4]; + byte pp_bonus[4]; + byte pure_pp_values[4]; + byte dvs[2]; + byte ivs[6]; + byte ribbons[4] = {0, 0, 0, 0}; u32 iv_egg_ability; - u8 unown_letter = -1; bool is_valid; bool is_new = false; - // int box_size; + int box_size; }; #endif diff --git a/include/pokemon_party.h b/include/pokemon_party.h index 8d7e09d..38a8930 100644 --- a/include/pokemon_party.h +++ b/include/pokemon_party.h @@ -20,7 +20,8 @@ public: bool load_gb_rom(); GB_ROM curr_gb_rom; void show_sprites(); - Pokemon pkmn_array[30]; + Simplified_Pokemon simple_pkmn_array[30]; + Simplified_Pokemon get_simple_pkmn(int index); bool fill_simple_pkmn_array(); bool get_contains_mythical(); void set_mythic_stabilization(bool stabilize); diff --git a/source/global_frame_controller.cpp b/source/global_frame_controller.cpp index 4b0712b..1da469b 100644 --- a/source/global_frame_controller.cpp +++ b/source/global_frame_controller.cpp @@ -229,7 +229,8 @@ void determine_fennel_blink() void set_missingno(bool val) { missingno_enabled = val; - if (val == false){ + if (val == false) + { set_background_pal(curr_rom.gamecode, false, false); fennel_blink_timer = 0; } @@ -239,9 +240,8 @@ bool get_missingno_enabled() { return missingno_enabled; } - // FNV-1a 32-bit hash function for byte arrays -u32 fnv1a_hash(unsigned char* data, size_t length) +u32 fnv1a_hash(unsigned char *data, size_t length) { const uint32_t fnv_prime = 0x01000193; const uint32_t fnv_offset_basis = 0x811C9DC5; @@ -252,6 +252,5 @@ u32 fnv1a_hash(unsigned char* data, size_t length) hash ^= data[i]; hash *= fnv_prime; } - return hash; } \ No newline at end of file diff --git a/source/pokemon.cpp b/source/pokemon.cpp index c3af3b0..8e29bf1 100644 --- a/source/pokemon.cpp +++ b/source/pokemon.cpp @@ -12,67 +12,79 @@ Pokemon::Pokemon() {}; // A lot of the event Pokemon script is reused. Really should be split into many different functions // Endian-ness too is all over the place... :/ -void Pokemon::generate_pkmn(int index, byte *party_data, GB_ROM curr_rom) +void Pokemon::load_data(int index, const byte *party_data, int game, int lang) { - // Start off by determining the section of data that is the current Pokemon - BASE_OFFSETS_STRUCT curr_offsets; - - if (curr_rom.language == JPN_ID) + language = lang; + if (lang == JPN_ID) { - if (curr_rom.generation == 1) + switch (game) { - /* - gen = 1; - pkmn_size = 44; - ot_size = 6; - nickname_size = 6; - box_size = 30; - */ - } - else - { - /* - gen = 2; - pkmn_size = 32; - ot_size = 6; - nickname_size = 6; - box_size = 30; - */ + case GREEN_ID: + case RED_ID: + case BLUE_ID: + case YELLOW_ID: + gen = 1; + pkmn_size = 44; + ot_size = 6; + nickname_size = 6; + box_size = 30; + break; + case GOLD_ID: + case SILVER_ID: + case CRYSTAL_ID: + gen = 2; + pkmn_size = 32; + ot_size = 6; + nickname_size = 6; + box_size = 30; + break; } } else { - if (curr_rom.generation = 1) + switch (game) { - curr_offsets = ITL_GEN1_OFFSETS; - } - else - { - curr_offsets = ITL_GEN2_OFFSETS; + case RED_ID: + case BLUE_ID: + case YELLOW_ID: + gen = 1; + pkmn_size = 33; + ot_size = 11; + nickname_size = 11; + box_size = 20; + break; + case GOLD_ID: + case SILVER_ID: + case CRYSTAL_ID: + gen = 2; + pkmn_size = 32; + ot_size = 11; + nickname_size = 11; + box_size = 20; + break; } } - int party_species_offset = 1 + // the num pkmn byte (1 * index); // the pkmn index we're looking for int box_struct_offset = - 1 + // the num of pkmn byte - (1 * curr_offsets.box_size) + 1 + // list of pkmn in box and terminator - (curr_offsets.pkmn_size * index); // the pokemon we're looking for + 1 + // the num of pkmn byte + (1 * box_size) + 1 + // list of pkmn in box and terminator + (pkmn_size * index); // the pokemon we're looking for int ot_offset = - 1 + // the num of pkmn byte - (1 * curr_offsets.box_size) + 1 + // list of pkmn in box and terminator - (curr_offsets.pkmn_size * curr_offsets.box_size) + // the pokemon structs - (curr_offsets.ot_size * index); // the ot we're looking for + 1 + // the num of pkmn byte + (1 * box_size) + 1 + // list of pkmn in box and terminator + (pkmn_size * box_size) + // the pokemon structs + (ot_size * index); // the ot we're looking for int nickname_offset = - 1 + // the num of pkmn byte - (1 * curr_offsets.box_size) + 1 + // list of pkmn in box and terminator - (curr_offsets.pkmn_size * curr_offsets.box_size) + // the pokemon structs - (curr_offsets.ot_size * curr_offsets.box_size) + // the ots - (curr_offsets.nickname_size * index); // the nickname we're looking for + 1 + // the num of pkmn byte + (1 * box_size) + 1 + // list of pkmn in box and terminator + (pkmn_size * box_size) + // the pokemon structs + (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; @@ -131,13 +143,13 @@ void Pokemon::generate_pkmn(int index, byte *party_data, GB_ROM curr_rom) tte_write("struct offset: "); tte_write(std::to_string(box_struct_offset).c_str()); tte_write("\nbox_size: "); - tte_write(std::to_string(curr_offsets.box_size).c_str()); + tte_write(std::to_string(box_size).c_str()); tte_write("\npkmn_size: "); - tte_write(std::to_string(curr_offsets.pkmn_size).c_str()); + tte_write(std::to_string(pkmn_size).c_str()); tte_write("\nindex: "); tte_write(std::to_string(index).c_str()); tte_write(", game: "); - tte_write(std::to_string(curr_rom.version).c_str()); + tte_write(std::to_string(game).c_str()); while (!key_hit(KEY_A)) { global_next_frame(); @@ -145,13 +157,10 @@ void Pokemon::generate_pkmn(int index, byte *party_data, GB_ROM curr_rom) global_next_frame(); } } - -void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ROM curr_rom) +void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical) { - byte gen_3_pkmn[80]; - // Convert the species indexes - if (curr_rom.generation == 1) + if (gen == 1) { if (species_index_struct > 190) { @@ -185,7 +194,6 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ is_valid = true; nature_mod = exp % 25; // save the nature mod in case the level is changed - // Update dex if not simple if (!simplified && !is_caught(species_index_struct)) { @@ -205,7 +213,7 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ new_nickname[i] = get_gen_3_char(JPN_NAMES[species_index_struct][i], true); } - if (curr_rom.generation == 1) + if (gen == 1) { // レッド (Red) new_ot[0] = 0x7A; // レ @@ -215,7 +223,7 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ } else { - if (((origin_info & 0b1000000000000000) >> 15) == 1) // Checks if the Gen 2 player is male or female + if (((caught_data[1] & 0b10000000) >> 7) == 1) // Checks if the Gen 2 player is male or female { // クリス (Kurisu) new_ot[0] = 0x58; // ク @@ -232,26 +240,14 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ new_ot[3] = 0xFF; } } - for (int i = 0; i < 10; i++) - { - gen_3_pkmn[8 + i] = new_nickname[i]; // Nickname - } - for (int i = 0; i < 7; i++) - { - gen_3_pkmn[20 + i] = new_ot[i]; // OT Name - } + copy_from_to(&new_nickname[0], &gen_3_pkmn[8], 10, false); // Nickname + copy_from_to(&new_ot[0], &gen_3_pkmn[20], 7, false); // OT Name } else { - gen_3_pkmn[18] = language; // Language - for (int i = 0; i < 10; i++) - { - gen_3_pkmn[8 + i] = *convert_text(&nickname[i], 1, curr_rom.generation, curr_rom.language); // Nickname - } - for (int i = 0; i < 7; i++) - { - gen_3_pkmn[20 + i] = *convert_text(&trainer_name[i], 1, curr_rom.generation, curr_rom.language); // OT Name - } + gen_3_pkmn[18] = language; // Language + copy_from_to(convert_text(&nickname[0], 10, gen, language), &gen_3_pkmn[8], 10, false); // Nickname + copy_from_to(convert_text(&trainer_name[0], 7, gen, language), &gen_3_pkmn[20], 7, false); // OT Name } // Make sure Level is not over 100 based on EXP @@ -417,15 +413,15 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ } for (int i = 0; i < 4; i++) { - pid = n_pid; + pid[i] = (n_pid >> (i * 8)) & 0xFF; } enable_auto_random(); // Determine and set Ability - iv_egg_ability |= ((pid & 0x00000000000000000000000000000001) ? get_num_abilities(species_index_struct) : 0) << 31; + iv_egg_ability |= ((pid[0] & 0x1) ? get_num_abilities(species_index_struct) : 0) << 31; // Origin info - origin_info |= ((origin_info & 0b1000000000000000) << 8); // OT gender - We would shift left 15 bits, but the bit is already shifted over 7 + origin_info |= ((caught_data[1] & 0b10000000) << 8); // OT gender - We would shift left 15 bits, but the bit is already shifted over 7 if (is_missingno) { origin_info |= (1 << 11); // Master Ball @@ -434,72 +430,58 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ { origin_info |= (4 << 11); // Ball } - origin_info |= (((curr_rom.generation == 1) ? 4 : 7) << 7); // Game - origin_info |= met_level; // Level met + origin_info |= (((gen == 1) ? 4 : 7) << 7); // Game + origin_info |= met_level; // Level met // Ribbons and Obedience // ribbons[2] |= 0b00000100; // Artist Ribbon if (species_index_struct == 151 || species_index_struct == 251) // Pokemon is Mew or Celebi { - ribbons |= 0b10000000000000000000000000000000; // Fateful Encounter flag + ribbons[3] |= 0b10000000; // Fateful Encounter flag } else if (is_missingno) { - ribbons |= 0b10000000000000000000000000000000; // Fateful Encounter flag + ribbons[3] |= 0b10000000; // Fateful Encounter flag // ribbons[3] |= 0b00000100; // World Ribbon } // Personality Value - for (int i = 0; i < 4; i++) - { - gen_3_pkmn[0 + i] = pid << (i * 8); - } + copy_from_to(&pid[0], &gen_3_pkmn[0], 4, false); // Trainer ID - for (int i = 0; i < 2; i++) - { - gen_3_pkmn[4 + i] = trainer_id << (i * 8); - } + copy_from_to(&trainer_id[0], &gen_3_pkmn[4], 2, true); + // Check if the Pokemon is shiny - byte secret_arr[2]; - byte trainer_arr[2] = { - trainer_id << 0, - trainer_id << 8, - }; - byte pid_arr[4] = { - pid << 0, - pid << 8, - pid << 16, - pid << 24, - }; if (is_shiny) { - - secret_arr[0] = trainer_arr[1] ^ pid_arr[0] ^ pid_arr[2] ^ 0x0; // This value at the end should be random between 0 - 15, if that is to be implemented - secret_arr[1] = trainer_arr[0] ^ pid_arr[1] ^ pid_arr[3] ^ 0x0; + secret_id[0] = trainer_id[1] ^ pid[0] ^ pid[2] ^ 0x0; // This value at the end should be random between 0 - 15, if that is to be implemented + secret_id[1] = trainer_id[0] ^ pid[1] ^ pid[3] ^ 0x0; // Randomly shift by 16 (maybe) } else // Not shiny, make sure it isn't { - secret_arr[0] = dvs[0]; - secret_arr[1] = dvs[1]; + secret_id[0] = dvs[0]; + secret_id[1] = dvs[1]; - if (((trainer_arr[0] ^ secret_arr[0] ^ pid_arr[0] ^ pid_arr[2]) == 0) && - ((trainer_arr[1] ^ secret_arr[1] ^ pid_arr[1] ^ pid_arr[3]) < 8)) + if (((trainer_id[0] ^ secret_id[0] ^ pid[0] ^ pid[2]) == 0) && + ((trainer_id[1] ^ secret_id[1] ^ pid[1] ^ pid[3]) < 8)) { - secret_id += 0x80000; + secret_id[1] += 8; } } - gen_3_pkmn[6] = secret_arr[0]; // Set SID - gen_3_pkmn[7] = secret_arr[1]; // Set SID + copy_from_to(&secret_id[0], &gen_3_pkmn[6], 2, false); // Set SID gen_3_pkmn[19] = 0b00000010; // Egg Name (has species sanity flag) gen_3_pkmn[27] = 0b00000000; // Markings // Data: - u8 data_section_G[12] = {}; - u8 data_section_A[12] = {}; - u8 data_section_E[12] = {}; - u8 data_section_M[12] = {}; + // Reset the data sections (in case the player runs the program twice) + for (int i = 0; i < 12; i++) + { + data_section_G[i] = 0; + data_section_A[i] = 0; + data_section_E[i] = 0; + data_section_M[i] = 0; + } data_section_G[0] = species_index_struct; data_section_G[1] = 0x00; // Species Index, check for glitch Pokemon @@ -511,14 +493,11 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ } data_section_G[8] = (pp_bonus[0] << 0 | pp_bonus[1] << 2 | pp_bonus[2] << 4 | pp_bonus[3] << 6); - data_section_A[0] = moves[0]; // Move 1 - data_section_A[2] = moves[1]; // Move 2 - data_section_A[4] = moves[2]; // Move 3 - data_section_A[6] = moves[3]; // Move 4 - for (int i = 0; i < 4; i++) - { - data_section_A[8 + i] = pure_pp_values[i]; // PP Values - } + data_section_A[0] = moves[0]; // Move 1 + data_section_A[2] = moves[1]; // Move 2 + data_section_A[4] = moves[2]; // Move 3 + data_section_A[6] = moves[3]; // Move 4 + copy_from_to(&pure_pp_values[0], &data_section_A[8], 4, false); // PP Values // Data section E is all zero (EVs and Contest Stats) @@ -530,10 +509,7 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ { data_section_M[i + 4] = (iv_egg_ability >> (i * 8) & 0xFF); // Set IVs, Egg, and Ability } - for (int i = 0; i < 4; i++) - { - data_section_M[8 + i] = ribbons << 8; // Ribbons and Fateful Encounter - } + copy_from_to(&ribbons[0], &data_section_M[8], 4, false); // Ribbons and Fateful Encounter // Checksum: checksum = 0x0000; @@ -548,122 +524,145 @@ void Pokemon::convert_to_gen_three(bool simplified, bool stabilize_mythical, GB_ gen_3_pkmn[28] = checksum & 0xFF; gen_3_pkmn[29] = (checksum & 0xFF00) >> 8; - u32 encryption_key = (trainer_id << 16 | secret_id) ^ pid; // XOR SID and TID with PID + for (int i = 0; i < 4; i++) + { + encryption_key[i] = gen_3_pkmn[4 + i] ^ pid[i]; // XOR SID and TID with PID + } for (int i = 0; i < 12; i++) { unencrypted_data[i] = data_section_G[i]; - data_section_G[i] ^= encryption_key << ((i % 4) * 8); + data_section_G[i] ^= encryption_key[i % 4]; unencrypted_data[12 + i] = data_section_A[i]; - data_section_A[i] ^= encryption_key << ((i % 4) * 8); + data_section_A[i] ^= encryption_key[i % 4]; unencrypted_data[24 + i] = data_section_E[i]; - data_section_E[i] ^= encryption_key << ((i % 4) * 8); + data_section_E[i] ^= encryption_key[i % 4]; unencrypted_data[36 + i] = data_section_M[i]; - data_section_M[i] ^= encryption_key << ((i % 4) * 8); + data_section_M[i] ^= encryption_key[i % 4]; } // Puts the four data chunks into their correct locations based on the PID - alocate_data_chunks(data_section_G, data_section_A, data_section_E, data_section_M, gen_3_pkmn); + alocate_data_chunks(data_section_G, data_section_A, data_section_E, data_section_M); global_next_frame(); } -void Pokemon::alocate_data_chunks(byte *G, byte *A, byte *E, byte *M, byte *gen_3_data) +void Pokemon::copy_from_to(const byte *source, byte *destination, int size, bool reverse_endian) { - word full_pid = pid; + if (reverse_endian) + { + for (int i = 0; i < size; i++) + { + destination[(size - 1) - i] = source[i]; + } + } + else + { + for (int i = 0; i < size; i++) + { + destination[i] = source[i]; + } + } +} + +void Pokemon::alocate_data_chunks(byte *G, byte *A, byte *E, byte *M) +{ + word full_pid = (pid[3] << 24 | pid[2] << 16 | pid[1] << 8 | pid[0]); byte mod_pid = full_pid % 24; unencrypted_data[48] = mod_pid; // This is such a stupid way to do this, but I can't for the life of me find a formula for the permutation table. switch (mod_pid) { case 0: - insert_data(G, A, E, M, gen_3_data); + insert_data(G, A, E, M); break; case 1: - insert_data(G, A, M, E, gen_3_data); + insert_data(G, A, M, E); break; case 2: - insert_data(G, E, A, M, gen_3_data); + insert_data(G, E, A, M); break; case 3: - insert_data(G, E, M, A, gen_3_data); + insert_data(G, E, M, A); break; case 4: - insert_data(G, M, A, E, gen_3_data); + insert_data(G, M, A, E); break; case 5: - insert_data(G, M, E, A, gen_3_data); + insert_data(G, M, E, A); break; case 6: - insert_data(A, G, E, M, gen_3_data); + insert_data(A, G, E, M); break; case 7: - insert_data(A, G, M, E, gen_3_data); + insert_data(A, G, M, E); break; case 8: - insert_data(A, E, G, M, gen_3_data); + insert_data(A, E, G, M); break; case 9: - insert_data(A, E, M, G, gen_3_data); + insert_data(A, E, M, G); break; case 10: - insert_data(A, M, G, E, gen_3_data); + insert_data(A, M, G, E); break; case 11: - insert_data(A, M, E, G, gen_3_data); + insert_data(A, M, E, G); break; case 12: - insert_data(E, G, A, M, gen_3_data); + insert_data(E, G, A, M); break; case 13: - insert_data(E, G, M, A, gen_3_data); + insert_data(E, G, M, A); break; case 14: - insert_data(E, A, G, M, gen_3_data); + insert_data(E, A, G, M); break; case 15: - insert_data(E, A, M, G, gen_3_data); + insert_data(E, A, M, G); break; case 16: - insert_data(E, M, G, A, gen_3_data); + insert_data(E, M, G, A); break; case 17: - insert_data(E, M, A, G, gen_3_data); + insert_data(E, M, A, G); break; case 18: - insert_data(M, G, A, E, gen_3_data); + insert_data(M, G, A, E); break; case 19: - insert_data(M, G, E, A, gen_3_data); + insert_data(M, G, E, A); break; case 20: - insert_data(M, A, G, E, gen_3_data); + insert_data(M, A, G, E); break; case 21: - insert_data(M, A, E, G, gen_3_data); + insert_data(M, A, E, G); break; case 22: - insert_data(M, E, G, A, gen_3_data); + insert_data(M, E, G, A); break; case 23: - insert_data(M, E, A, G, gen_3_data); + insert_data(M, E, A, G); break; } } -void Pokemon::insert_data(byte *first, byte *second, byte *third, byte *fourth, byte *gen_3_pkmn) +void Pokemon::insert_data(byte *first, byte *second, byte *third, byte *fourth) { - for (int i = 0; i < 12; i++){ - gen_3_pkmn[32 + i] = first[i]; - } - for (int i = 0; i < 12; i++){ - gen_3_pkmn[44 + i] = second[i]; - } - for (int i = 0; i < 12; i++){ - gen_3_pkmn[56 + i] = third[i]; - } - for (int i = 0; i < 12; i++){ - gen_3_pkmn[68 + i] = fourth[i]; - } + copy_from_to(&first[0], &gen_3_pkmn[32], 12, false); + copy_from_to(&second[0], &gen_3_pkmn[44], 12, false); + copy_from_to(&third[0], &gen_3_pkmn[56], 12, false); + copy_from_to(&fourth[0], &gen_3_pkmn[68], 12, false); +} + +byte Pokemon::get_gen_3_data(int index) +{ + return gen_3_pkmn[index]; +} + +byte *Pokemon::get_full_gen_3_array() +{ + return gen_3_pkmn; } byte Pokemon::get_unencrypted_data(int index) @@ -868,7 +867,6 @@ Simplified_Pokemon Pokemon::get_simple_pkmn() return curr_pkmn; } -/* void Pokemon::set_to_event(byte nature) { int event_id = 0; @@ -984,7 +982,7 @@ void Pokemon::set_to_event(byte nature) } // Determine and set OT gender - data_section_M[3] |= (origins_info[1] & 0b10000000); + data_section_M[3] |= (caught_data[1] & 0b10000000); // Check the level if (exp < 560) // Minimum EXP for level 10 @@ -1030,4 +1028,3 @@ void Pokemon::set_to_event(byte nature) alocate_data_chunks(data_section_G, data_section_A, data_section_E, data_section_M); return; } -*/ \ No newline at end of file