about summary refs log tree commit diff stats
path: root/gba/source/gamedata.c
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-07-11 19:19:49 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-07-11 19:19:49 -0400
commitd4eb5af332ce518baa552c886caa0bf3b2864f75 (patch)
tree469b3881a6fae4a203d97a4a00fec3b6b0f1d6ef /gba/source/gamedata.c
parentec66a022a8879a5300f2ae64cd86a5d8cfbd1a36 (diff)
downloadgen3uploader-d4eb5af332ce518baa552c886caa0bf3b2864f75.tar.gz
gen3uploader-d4eb5af332ce518baa552c886caa0bf3b2864f75.tar.bz2
gen3uploader-d4eb5af332ce518baa552c886caa0bf3b2864f75.zip
Major reformatting, cleaning up black magic
Diffstat (limited to 'gba/source/gamedata.c')
-rw-r--r--gba/source/gamedata.c56
1 files changed, 17 insertions, 39 deletions
diff --git a/gba/source/gamedata.c b/gba/source/gamedata.c index 8e63232..6868b2b 100644 --- a/gba/source/gamedata.c +++ b/gba/source/gamedata.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * Pokemon Gen III Data Extractor by hatkirby 2017. 2 * Copyright (C) 2017 hatkirby
3 * Copyright (C) 2017 slipstream/RoL
3 * 4 *
4 * This software may be modified and distributed under the terms 5 * This software may be modified and distributed under the terms
5 * of the MIT license. See the LICENSE file for details. 6 * of the MIT license. See the LICENSE file for details.
6 *
7 */ 7 */
8#include "gamedata.h" 8#include "gamedata.h"
9 9
@@ -245,9 +245,10 @@ bool initSaveData(
245 } 245 }
246 246
247 /// --- FR/LG --- 247 /// --- FR/LG ---
248 // In FR/LG, the function that initialises the save-block pointers to default does not set up saveblock3. 248 // In FR/LG, the function that initialises the save-block pointers to
249 // Which will need to be set up before loading the save if we want boxed Pokémon to not disappear. 249 // default does not set up saveblock3. Which will need to be set up before
250 // Oh, and loadsave() offset is different between FR and LG... 250 // loading the save if we want boxed Pokémon to not disappear. Oh, and
251 // loadsave() offset is different between FR and LG...
251 252
252 case 'DRPB': // FireRed German 253 case 'DRPB': // FireRed German
253 case 'DGPB': // LeafGreen German 254 case 'DGPB': // LeafGreen German
@@ -376,12 +377,14 @@ bool initSaveData(
376 { 377 {
377 // LeafGreen v1.1 Japanese is undumped. 378 // LeafGreen v1.1 Japanese is undumped.
378 // Therefore, it is unsupported. 379 // Therefore, it is unsupported.
379 // I will make guesses at the offsets in the comments, but I will not actually implement them until LeafGreen v1.1 is dumped. 380 // I will make guesses at the offsets in the comments, but I will
381 // not actually implement them until LeafGreen v1.1 is dumped.
380 382
381 return false; 383 return false;
382 } 384 }
383 385
384 loadsave = (void(*)(char)) 0x80db529; // potential LG1.1 address: 0x80db4fd 386 loadsave = (void(*)(char)) 0x80db529;
387 // potential LG1.1 address: 0x80db4fd
385 //mainloop = (void(*)()) 0x8000417; 388 //mainloop = (void(*)()) 0x8000417;
386 //titlemid = 0x8078987; 389 //titlemid = 0x8078987;
387 //load_pokemon = (void(*)()) 0x804b9c5; 390 //load_pokemon = (void(*)()) 0x804b9c5;
@@ -399,8 +402,10 @@ bool initSaveData(
399 } 402 }
400 403
401 /// --- Emerald --- 404 /// --- Emerald ---
402 // In Emerald, the saveblock pointer that isn't set up is saveblock1 (in FR/LG it was saveblock3). 405 // In Emerald, the saveblock pointer that isn't set up is saveblock1 (in
403 // The initial save loading code after the copyright screen is also updated, now it sets up ASLR/crypto here before loading the save. 406 // FR/LG it was saveblock3). The initial save loading code after the
407 // copyright screen is also updated, now it sets up ASLR/crypto here before
408 // loading the save.
404 409
405 case 'DEPB': // Emerald German 410 case 'DEPB': // Emerald German
406 { 411 {
@@ -493,42 +498,15 @@ bool initSaveData(
493 } 498 }
494 499
495 loadsave(0); 500 loadsave(0);
496// sendS32(-1); 501
497 // now the save is loaded, we can do what we want with the loaded blocks. 502 // now the save is loaded, we can do what we want with the loaded blocks.
498 // first, we're going to want to decrypt the parts that are crypted, if applicable. 503 // first, we're going to want to decrypt the parts that are crypted, if
504 // applicable.
499 decryptSaveStructures(gSaveBlock1,gSaveBlock2,gSaveBlock3); 505 decryptSaveStructures(gSaveBlock1,gSaveBlock2,gSaveBlock3);
500 506
501 *SaveBlock1 = gSaveBlock1; 507 *SaveBlock1 = gSaveBlock1;
502 *SaveBlock2 = gSaveBlock2; 508 *SaveBlock2 = gSaveBlock2;
503 *SaveBlock3 = gSaveBlock3; 509 *SaveBlock3 = gSaveBlock3;
504 510
505 /*
506 // time to call the payload.
507 payload(gSaveBlock1,gSaveBlock2,gSaveBlock3);
508 // Now, we better call the function that sets the pokemon-related stuff from the structure elements of the loaded save again.
509 // Just in case the payload did something with that.
510 load_pokemon();
511 // In FR/LG/Emerald, just returning to the game is unwise.
512 // The game reloads the savefile.
513 // In FR/LG, this is done at the title screen after setting ASLR/saveblock-crypto up. (probably because at initial save-load, SaveBlock3 ptr isn't set up lol)
514 // So, better bypass the title screen and get the game to return directly to the Continue/New Game screen.
515 // In Emerald, the save reload happens after the Continue option was chosen, so we have no choice but to bypass everything and get the game to go straight to the overworld.
516 // Easiest way to do this is to call into the middle of the function we want, using an ASM wrapper to set up the stack.
517 // Here goes...
518 if (titlemid) {
519 // Function reserves an extra 4 bytes of stack space in FireRed/LeafGreen, and none in Emerald.
520 call_into_middle_of_titlescreen_func(titlemid,(GAME_EM ? 0 : 4));
521 }
522 // Now we've done what we want, time to return to the game.
523 // Can't just return, the game will reload the save.
524 // So let's just call the main-loop directly ;)
525 // turn the sound back on before we head back to the game
526 *(vu16 *)(REG_BASE + 0x84) = 0x8f;
527 // re-enable interrupts
528 REG_IME = 1;
529 mainloop();
530 // Anything past here will not be executed.
531 return 0;
532 */
533 return true; 511 return true;
534} 512}