From 08dfb0aa80668b80c4a31bd064f5f2d729e5b7f6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 18 Aug 2017 13:49:00 -0400 Subject: Started working on serializing pokemon data The GBA program now sends serialized data about the first pokemon in the player's party over to the Wii. This data doesn't yet include all of the information that we will eventually want. It does, however, not transfer any private data, specifically IVs, EVs, and the personality value. It does this by deriving the public information (stats, nature, gender, shiny) before sending the pokemon over. Because of this, lookup tables for things such as base stats were needed, and given that these are large tables, it was easier to use the tables already existent in the game's ROM. Thus, the addresses of the three lookup tables that are now used are necessary for each ROM that this tool supports. I derived the addresses for version 1 of English Pokemon LeafGreen by dumping my own copy and searching through it with a text editor. Thus, at the current time, that cartridge is the only one that is supported. I will supplement this soon with addresses for the other four gen 3 carts that I have, but that will still not provide a very large amount of coverage. I have not yet decided how to address this issue. There is one current bug with the serialized data: the Wii doesn't seem to see the original trainer ID. Will fix. --- gba/source/main.c | 86 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 26 deletions(-) (limited to 'gba/source/main.c') diff --git a/gba/source/main.c b/gba/source/main.c index 14d2f1d..aeb05af 100644 --- a/gba/source/main.c +++ b/gba/source/main.c @@ -7,6 +7,7 @@ #include #include "gamedata.h" #include "link.h" +#include "serialize.h" int main(void) { @@ -42,11 +43,9 @@ int main(void) waitForAck(); // Get access to save data. - pSaveBlock1 SaveBlock1; - pSaveBlock2 SaveBlock2; - pSaveBlock3 SaveBlock3; + struct GameData gameData; - if (!initSaveData(&SaveBlock1, &SaveBlock2, &SaveBlock3)) + if (!initSaveData(&gameData)) { // Unsupported game version. sendS32(-1); @@ -63,13 +62,13 @@ int main(void) if (GAME_RS) { - trainerName = SaveBlock2->rs.playerName; + trainerName = gameData.SaveBlock2->rs.playerName; } else if (GAME_FRLG) { - trainerName = SaveBlock2->frlg.playerName; + trainerName = gameData.SaveBlock2->frlg.playerName; } else if (GAME_EM) { - trainerName = SaveBlock2->e.playerName; + trainerName = gameData.SaveBlock2->e.playerName; } u32 tn1 = @@ -94,20 +93,24 @@ int main(void) u8* trainerId = 0; if (GAME_RS) { - trainerId = SaveBlock2->rs.playerTrainerId; + trainerId = gameData.SaveBlock2->rs.playerTrainerId; } else if (GAME_FRLG) { - trainerId = SaveBlock2->frlg.playerTrainerId; + trainerId = gameData.SaveBlock2->frlg.playerTrainerId; } else if (GAME_EM) { - trainerId = SaveBlock2->e.playerTrainerId; + trainerId = gameData.SaveBlock2->e.playerTrainerId; } - u32 tti = + u16 trainerIdNum = (trainerId[1] << 8) | (trainerId[0]); - sendU32(tti); + u16 secretIdNum = + (trainerId[3] << 8) + | (trainerId[2]); + + sendU32(trainerIdNum); waitForAck(); // Does the player want to import this game? @@ -120,22 +123,22 @@ int main(void) u8* pokedexSeen = 0; if (GAME_RS) { - pokedexSeen = SaveBlock2->rs.pokedex.seen; + pokedexSeen = gameData.SaveBlock2->rs.pokedex.seen; } else if (GAME_FRLG) { - pokedexSeen = SaveBlock2->frlg.pokedex.seen; + pokedexSeen = gameData.SaveBlock2->frlg.pokedex.seen; } else if (GAME_EM) { - pokedexSeen = SaveBlock2->e.pokedex.seen; + pokedexSeen = gameData.SaveBlock2->e.pokedex.seen; } for (int i=0; i<13; i++) { u32 psi = - (pokedexSeen[i*4]) - | (pokedexSeen[i*4+1] << 8) - | (pokedexSeen[i*4+2] << 16) - | (pokedexSeen[i*4+3] << 24); + (pokedexSeen[i*4] << 24) + | (pokedexSeen[i*4+1] << 16) + | (pokedexSeen[i*4+2] << 8) + | (pokedexSeen[i*4+3]); directSendU32(psi); } @@ -143,23 +146,54 @@ int main(void) u8* pokedexCaught = 0; if (GAME_RS) { - pokedexCaught = SaveBlock2->rs.pokedex.owned; + pokedexCaught = gameData.SaveBlock2->rs.pokedex.owned; } else if (GAME_FRLG) { - pokedexCaught = SaveBlock2->frlg.pokedex.owned; + pokedexCaught = gameData.SaveBlock2->frlg.pokedex.owned; } else if (GAME_EM) { - pokedexCaught = SaveBlock2->e.pokedex.owned; + pokedexCaught = gameData.SaveBlock2->e.pokedex.owned; } for (int i=0; i<13; i++) { u32 psi = - (pokedexCaught[i*4]) - | (pokedexCaught[i*4+1] << 8) - | (pokedexCaught[i*4+2] << 16) - | (pokedexCaught[i*4+3] << 24); + (pokedexCaught[i*4] << 24) + | (pokedexCaught[i*4+1] << 16) + | (pokedexCaught[i*4+2] << 8) + | (pokedexCaught[i*4+3]); directSendU32(psi); } + + // Start sending over party pokémon. + struct Pokemon* playerParty = 0; + if (GAME_RS) + { + playerParty = gameData.SaveBlock1->rs.playerParty; + } else if (GAME_FRLG) + { + playerParty = gameData.SaveBlock1->frlg.playerParty; + } else if (GAME_EM) + { + playerParty = gameData.SaveBlock1->e.playerParty; + } + + waitForResponse(); + + u32 partyCount = 1; + + sendU32(partyCount); + waitForAck(); + + for (int pki=0; pkibox); + + struct PokemonIntermediate pki; + + PokemonIntermediateInit(&pki, bpkm, trainerIdNum, secretIdNum, &gameData); + PokemonIntermediateStream(&pki); + } } -- cgit 1.4.1