summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/load_save.c165
-rw-r--r--src/new_game.c2
-rw-r--r--src/rom4.c6
-rw-r--r--src/save.c16
-rw-r--r--src/start_menu.c4
5 files changed, 179 insertions, 14 deletions
diff --git a/src/load_save.c b/src/load_save.c
new file mode 100644
index 000000000..6f12718f0
--- /dev/null
+++ b/src/load_save.c
@@ -0,0 +1,165 @@
+#include "global.h"
+#include "main.h"
+#include "rom4.h"
+#include "pokemon.h"
+
+extern u8 gPlayerPartyCount;
+extern u32 gUnknown_3004820;
+
+struct LoadedSaveData
+{
+ struct ItemSlot items[20];
+ struct ItemSlot keyItems[20];
+ struct ItemSlot pokeBalls[16];
+ struct ItemSlot TMsHMs[64];
+ struct ItemSlot berries[46];
+ struct SaveBlock1_2B4C_Struct unknownSaveData[16];
+};
+
+extern struct LoadedSaveData gLoadedSaveData[];
+
+extern u16 IdentifyFlash(void);
+extern void gpu_sync_bg_hide();
+
+void CheckForFlashMemory(void)
+{
+ if(!IdentifyFlash())
+ {
+ gUnknown_3004820 = 1;
+ InitFlashTimer();
+ }
+ else
+ gUnknown_3004820 = 0;
+}
+
+u8 GetSecretBase2Field_9(void)
+{
+ return gSaveBlock2.specialSaveWarp;
+}
+
+void ClearSecretBase2Field_9(void)
+{
+ gSaveBlock2.specialSaveWarp = 0;
+}
+
+void SetSecretBase2Field_9(void)
+{
+ gSaveBlock2.specialSaveWarp = 1;
+}
+
+void SetSecretBase2Field_9_AndHideBG(void) // note: no other function sets specialSaveWarp to values other than 0 or 1, hence clear and set distinctions.
+{
+ gpu_sync_bg_hide(0); // the function doesn't use the parameter passed to it, but this is necessary to match.
+ gSaveBlock2.specialSaveWarp = 1;
+}
+
+void ClearSecretBase2Field_9_2(void) // duplicate function
+{
+ gSaveBlock2.specialSaveWarp = 0;
+}
+
+void SavePlayerParty(void)
+{
+ int i;
+
+ gSaveBlock1.playerPartyCount = gPlayerPartyCount;
+
+ for (i = 0; i < 6; i++)
+ gSaveBlock1.playerParty[i] = gPlayerParty[i];
+}
+
+void LoadPlayerParty(void)
+{
+ int i;
+
+ gPlayerPartyCount = gSaveBlock1.playerPartyCount;
+
+ for (i = 0; i < 6; i++)
+ gPlayerParty[i] = gSaveBlock1.playerParty[i];
+}
+
+void SaveMapObjects(void)
+{
+ int i;
+
+ for(i = 0; i < 16; i++)
+ gSaveBlock1.mapObjects[i] = gMapObjects[i];
+}
+
+void LoadMapObjects(void)
+{
+ int i;
+
+ for(i = 0; i < 16; i++)
+ gMapObjects[i] = gSaveBlock1.mapObjects[i];
+}
+
+void SaveSerializedGame(void)
+{
+ SavePlayerParty();
+ SaveMapObjects();
+}
+
+void LoadSerializedGame(void)
+{
+ LoadPlayerParty();
+ LoadMapObjects();
+}
+
+void LoadPlayerData(void)
+{
+ int i;
+
+ // load player items.
+ for(i = 0; i < 20; i++)
+ gLoadedSaveData->items[i] = gSaveBlock1.bagPocket_Items[i];
+
+ // load player key items.
+ for(i = 0; i < 20; i++)
+ gLoadedSaveData->keyItems[i] = gSaveBlock1.bagPocket_KeyItems[i];
+
+ // load player pokeballs.
+ for(i = 0; i < 16; i++)
+ gLoadedSaveData->pokeBalls[i] = gSaveBlock1.bagPocket_PokeBalls[i];
+
+ // load player TMs and HMs.
+ for(i = 0; i < 64; i++)
+ gLoadedSaveData->TMsHMs[i] = gSaveBlock1.bagPocket_TMHM[i];
+
+ // load player berries.
+ for(i = 0; i < 46; i++)
+ gLoadedSaveData->berries[i] = gSaveBlock1.bagPocket_Berries[i];
+
+ // load misc data.
+ for(i = 0; i < 16; i++)
+ gLoadedSaveData->unknownSaveData[i] = gSaveBlock1.unkSave[i];
+}
+
+void SavePlayerData(void)
+{
+ int i;
+
+ // save player items.
+ for(i = 0; i < 20; i++)
+ gSaveBlock1.bagPocket_Items[i] = gLoadedSaveData->items[i];
+
+ // save player key items.
+ for(i = 0; i < 20; i++)
+ gSaveBlock1.bagPocket_KeyItems[i] = gLoadedSaveData->keyItems[i];
+
+ // save player pokeballs.
+ for(i = 0; i < 16; i++)
+ gSaveBlock1.bagPocket_PokeBalls[i] = gLoadedSaveData->pokeBalls[i];
+
+ // save player TMs and HMs.
+ for(i = 0; i < 64; i++)
+ gSaveBlock1.bagPocket_TMHM[i] = gLoadedSaveData->TMsHMs[i];
+
+ // save player berries.
+ for(i = 0; i < 46; i++)
+ gSaveBlock1.bagPocket_Berries[i] = gLoadedSaveData->berries[i];
+
+ // save misc data.
+ for(i = 0; i < 16; i++)
+ gSaveBlock1.unkSave[i] = gLoadedSaveData->unknownSaveData[i];
+}
diff --git a/src/new_game.c b/src/new_game.c
index c36337409..d63e50236 100644
--- a/src/new_game.c
+++ b/src/new_game.c
@@ -102,7 +102,7 @@ void NewGameInitData(void)
sub_8052DE4();
memset(&gSaveBlock1, 0, sizeof(gSaveBlock1));
sub_80A2B18();
- gSaveBlock2.sb2_field_9 = 0;
+ gSaveBlock2.specialSaveWarp = 0;
set_player_trainer_id();
PlayTimeCounter_Reset();
sub_8052D78();
diff --git a/src/rom4.c b/src/rom4.c
index a3b0b221d..19f59001b 100644
--- a/src/rom4.c
+++ b/src/rom4.c
@@ -454,7 +454,7 @@ void sub_80537CC(u8 a1)
warp_set(&gSaveBlock1.warp1, warp->group, warp->map, -1, warp->x, warp->y);
}
-void gpu_sync_bg_hide(void)
+void gpu_sync_bg_hide()
{
gSaveBlock1.warp1 = gSaveBlock1.warp2;
}
@@ -1262,9 +1262,9 @@ void CB2_ContinueSavedGame(void)
PlayTimeCounter_Start();
ScriptContext1_Init();
ScriptContext2_Disable();
- if (sub_80479F8() == 1)
+ if (GetSecretBase2Field_9() == 1)
{
- sub_8047A04();
+ ClearSecretBase2Field_9();
sub_8053778();
warp_in();
SetMainCallback2(CB2_LoadMap);
diff --git a/src/save.c b/src/save.c
index a26e0da98..88f19f15c 100644
--- a/src/save.c
+++ b/src/save.c
@@ -550,27 +550,27 @@ u8 sub_8125C3C(u8 a1)
sav12_xor_increment(10);
for (i = 0; i < 2; i++)
sub_81253C8(28 + i, gHallOfFameSaveSectionLocations[i].data, gHallOfFameSaveSectionLocations[i].size);
- save_serialize_game();
+ SaveSerializedGame();
save_write_to_flash(0xFFFF, gSaveSectionLocations);
break;
case 0:
default:
- save_serialize_game();
+ SaveSerializedGame();
save_write_to_flash(0xFFFF, gSaveSectionLocations);
break;
case 1:
- save_serialize_game();
+ SaveSerializedGame();
for (i = 0; i < 5; i++)
save_write_to_flash(i, gSaveSectionLocations);
break;
case 2:
- save_serialize_game();
+ SaveSerializedGame();
save_write_to_flash(0, gSaveSectionLocations);
break;
case 4:
for (i = 28; i < 32; i++)
EraseFlashSector(i);
- save_serialize_game();
+ SaveSerializedGame();
save_write_to_flash(0xFFFF, gSaveSectionLocations);
break;
}
@@ -592,7 +592,7 @@ u8 sub_8125D80(void)
{
if (gUnknown_3004820 != 1)
return 1;
- save_serialize_game();
+ SaveSerializedGame();
sub_812546C(gSaveSectionLocations);
return 0;
}
@@ -629,7 +629,7 @@ u8 sub_8125E2C(void)
if (gUnknown_3004820 != 1)
return 1;
- save_serialize_game();
+ SaveSerializedGame();
sub_81254C8(gSaveSectionLocations);
sub_812556C(gUnknown_03005EB4 + 1, gSaveSectionLocations);
return 0;
@@ -669,7 +669,7 @@ u8 sub_8125EC8(u8 a1)
case 0:
default:
result = sub_812587C(0xFFFF, gSaveSectionLocations);
- save_deserialize_game();
+ LoadSerializedGame();
gSaveFileStatus = result;
gUnknown_03005EBC = 0;
break;
diff --git a/src/start_menu.c b/src/start_menu.c
index 06eb28909..ee941b715 100644
--- a/src/start_menu.c
+++ b/src/start_menu.c
@@ -811,14 +811,14 @@ static void Task_8071B64(u8 taskId)
(*step)++;
break;
case 1:
- sub_8047A1C();
+ SetSecretBase2Field_9_AndHideBG();
sub_8125E2C();
(*step)++;
break;
case 2:
if(!sub_8125E6C())
break;
- sub_8047A34();
+ ClearSecretBase2Field_9_2();
(*step)++;
break;
case 3: