summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/player_data.h2
-rw-r--r--include/pokemon_storage_system.h48
-rw-r--r--include/save_block_2.h128
3 files changed, 167 insertions, 11 deletions
diff --git a/include/player_data.h b/include/player_data.h
index bd9cd3b9..b4c7ce41 100644
--- a/include/player_data.h
+++ b/include/player_data.h
@@ -36,5 +36,7 @@ struct Options * Sav2_PlayerData_GetOptionsAddr(struct SaveBlock2 *);
struct String * PlayerProfile_GetPlayerName_NewString(struct PlayerData *, u32 heap_id);
u32 PlayerProfile_GetTrainerID(struct PlayerData *);
u32 PlayerProfile_GetTrainerGender(struct PlayerData *);
+u32 Sav2_PlayerData_sizeof(void);
+void Sav2_PlayerData_init(struct PlayerDataSav *);
#endif //POKEDIAMOND_PLAYER_DATA_H
diff --git a/include/pokemon_storage_system.h b/include/pokemon_storage_system.h
new file mode 100644
index 00000000..c9dc6f29
--- /dev/null
+++ b/include/pokemon_storage_system.h
@@ -0,0 +1,48 @@
+#ifndef POKEDIAMOND_POKEMON_STORAGE_SYSTEM_H
+#define POKEDIAMOND_POKEMON_STORAGE_SYSTEM_H
+
+#include "pokemon.h"
+
+#define NUM_BOXES 18u
+#define MONS_PER_BOX 30u
+#define BOX_NAME_LENGTH 20u
+#define NUM_DEFAULT_WALLPAPERS 16u
+#define NUM_BONUS_WALLPAPERS 8u
+#define NUM_WALLPAPERS ((u32)(NUM_DEFAULT_WALLPAPERS + NUM_BONUS_WALLPAPERS))
+
+struct PCStorage
+{
+ /* 0x00000 */ u32 curBox;
+ /* 0x00004 */ struct BoxPokemon boxes[NUM_BOXES][MONS_PER_BOX];
+ /* 0x11EE4 */ u16 names[NUM_BOXES][BOX_NAME_LENGTH];
+ /* 0x121B4 */ u8 wallpapers[NUM_BOXES];
+ /* 0x121C6 */ u8 unlockedWallpapers;
+ /* 0x121C7 */ u8 pad_byte; // suppresses mwcc warning
+};
+
+void PCStorage_init(struct PCStorage * pc);
+u32 PCStorage_sizeof(void);
+void PCStorage_InitializeBoxes(struct PCStorage * pc);
+BOOL PCStorage_PlaceMonInFirstEmptySlotInAnyBox(struct PCStorage * pc, struct BoxPokemon * boxmon);
+BOOL PCStorage_PlaceMonInBoxFirstEmptySlot(struct PCStorage * pc, int boxno, struct BoxPokemon * boxmon);
+BOOL PCStorage_PlaceMonInBoxByIndexPair(struct PCStorage * pc, int boxno, int slotno, struct BoxPokemon * boxmon);
+void PCStorage_DeleteBoxMonByIndexPair(struct PCStorage * pc, int boxno, int slotno);
+int PCStorage_GetActiveBox(struct PCStorage * pc);
+int PCStorage_FindFirstBoxWithEmptySlot(struct PCStorage * pc);
+BOOL PCStorage_FindFirstEmptySlot(struct PCStorage * pc, int * boxno, int * slotno);
+int PCStorage_CountMonsAndEggsInAllBoxes(struct PCStorage * pc);
+void PCStorage_SetActiveBox(struct PCStorage * pc, int boxno);
+u8 PCStorage_GetBoxWallpaper(struct PCStorage * pc, int boxno);
+void PCStorage_SetBoxWallpaper(struct PCStorage * pc, int boxno, u8 wallpaper);
+void PCStorage_GetBoxName(struct PCStorage * pc, int boxno, struct String * ret);
+void PCStorage_SetBoxName(struct PCStorage * pc, int boxno, struct String * src);
+int PCStorage_CountMonsAndEggsInBox(struct PCStorage * pc, int boxno);
+int PCStorage_CountMonsInBox(struct PCStorage * pc, int boxno);
+int PCStorage_CountMonsInAllBoxes(struct PCStorage * pc);
+void PCStorage_SetBoxMonDataByIndexPair(struct PCStorage * pc, int boxno, int slotno, u32 attr, void * value);
+struct BoxPokemon * PCStorage_GetMonByIndexPair(struct PCStorage * pc, int boxno, int slotno);
+void PCStorage_UnlockBonusWallpaper(struct PCStorage * pc, int wallpaper);
+BOOL PCStorage_IsBonusWallpaperUnlocked(struct PCStorage * pc, int wallpaper);
+int PCStorage_CountUnlockedBonusWallpapers(struct PCStorage * pc);
+
+#endif //POKEDIAMOND_POKEMON_STORAGE_SYSTEM_H
diff --git a/include/save_block_2.h b/include/save_block_2.h
index 304469c7..f54e556e 100644
--- a/include/save_block_2.h
+++ b/include/save_block_2.h
@@ -5,7 +5,7 @@
struct SavArrayHeader
{
- u32 id;
+ int id;
u32 size;
u32 offset;
u16 field_C;
@@ -15,38 +15,144 @@ struct SavArrayHeader
struct SavArrayFooter
{
u32 magic;
- u32 next;
+ u32 unk_4;
+ u32 unk_8;
+ u16 unk_C;
+ u16 crc;
+};
+
+struct SaveChunkFooter
+{
+ u32 unk_0;
+ u32 offset;
u32 size;
- u16 id;
+ u32 magic;
+ u8 unk_10;
+ u8 padding_11;
u16 crc;
};
struct SaveBlock2_Sub_20464 {
- u32 unk_0;
+ u8 unk_0;
+ u8 unk_1;
+ u8 unk_2;
+ u8 padding_3;
+ u32 offset;
+ u32 size;
+};
+
+struct UnkSavSub_2047C
+{
+ int unk_0;
+ int unk_4;
+ int unk_8;
+ int unk_C;
+ int unk_10;
+ u32 unk_14;
+ u32 unk_18;
+ u32 unk_1C[2];
+};
+
+struct UnkStruct_0202288C
+{
+ BOOL unk_0;
u32 offset;
u32 size;
};
struct SaveBlock2
{
- /* 0x00000 */ int flashType;
+ /* 0x00000 */ BOOL flashOkay;
/* 0x00004 */ int unk_00004;
/* 0x00008 */ int unk_00008;
- /* 0x0000C */ int unk_0000C;
+ /* 0x0000C */ int largeSectorChanged;
/* 0x00010 */ int unk_00010;
/* 0x00014 */ struct MATHCRC16Table crcTable;
/* 0x00214 */ u8 dynamic_region[0x20000];
- /* 0x20214 */ int unk_20214;
- /* 0x20218 */ u8 unk_20218[8];
+ /* 0x20214 */ u32 unk_20214;
+ /* 0x20218 */ u32 unk_20218[2];
/* 0x20220 */ u8 unk_20220[2];
/* 0x20222 */ u8 filler_20222[2];
/* 0x20224 */ struct SavArrayHeader arrayHeaders[36];
/* 0x20464 */ struct SaveBlock2_Sub_20464 saveSlotSpecs[2];
- /* 0x2047C */ u8 filler_2047C[0x28];
- /* 0x204A4 */ int unk_204A4;
+ /* 0x2047C */ struct UnkSavSub_2047C unk_2047C;
+ /* 0x204A0 */ u32 unk_204A0;
+ /* 0x204A4 */ u32 unk_204A4;
// TODO: finish this struct
}; // size: 0x204A8
-void * SavArray_get(struct SaveBlock2 *, int);
+typedef u32 (*SAVSIZEFN)(void);
+typedef void (*SAVINITFN)(void *);
+
+struct SaveChunkHeader
+{
+ int id;
+ int linkedId;
+ SAVSIZEFN sizeFunc;
+ SAVINITFN initFunc;
+};
+
+extern const struct SaveChunkHeader UNK_020EE6E0[];
+extern const struct SaveChunkHeader UNK_020EE700[];
+extern const int UNK_020EE6DC;
+extern const int UNK_020EE6D8;
+
+struct SaveBlock2 * SaveBlock2_new(void);
+struct SaveBlock2 * FUN_020225F8(void);
+void * SavArray_get(struct SaveBlock2 * sav2, int idx);
+void * FUN_02022634(struct SaveBlock2 * sav2, int idx);
+BOOL FUN_0202263C(struct SaveBlock2 * sav2);
+BOOL FUN_020226FC(struct SaveBlock2 * sav2);
+int FUN_02022720(struct SaveBlock2 * sav2);
+void FUN_020227A0(struct SaveBlock2 * sav2, int a1);
+void Sav2_InitDynamicRegion(struct SaveBlock2 * sav2);
+int FUN_020227FC(struct SaveBlock2 * sav2);
+int FUN_02022800(struct SaveBlock2 * sav2);
+int FUN_02022804(struct SaveBlock2 * sav2);
+int FUN_02022808(struct SaveBlock2 * sav2);
+BOOL FUN_0202280C(struct SaveBlock2 * sav2);
+int SaveGetDirtyBit(struct SaveBlock2 * sav2);
+void SaveSetDirtyBit(void);
+void FUN_02022840(struct SaveBlock2 * sav2, int a1);
+int FUN_02022854(struct SaveBlock2 * sav2);
+void FUN_0202287C(struct SaveBlock2 * sav2);
+void FUN_0202288C(struct UnkStruct_0202288C * header);
+u16 FUN_02022898(struct SaveBlock2 * sav2, void * data, u32 size);
+u32 GetChunkOffsetFromCurrentSaveSlot(u32 slot, struct SaveBlock2_Sub_20464 * header);
+struct SaveChunkFooter * FUN_020228B8(struct SaveBlock2 * sav2, u8 * offset, int idx);
+BOOL FUN_020228E0(struct SaveBlock2 * sav2, void * data, int idx);
+void FUN_0202293C(struct UnkStruct_0202288C * r5, struct SaveBlock2 * sav2, void * data, int idx);
+void FUN_02022968(struct SaveBlock2 * sav2, void * data, int idx);
+int FUN_020229B8(u32 x, u32 y);
+int FUN_020229F0(struct UnkStruct_0202288C * r7, struct UnkStruct_0202288C * r6, u32 * r5, u32 * r4);
+void FUN_02022AA0(struct SaveBlock2 * sav2, struct UnkStruct_0202288C * a1, struct UnkStruct_0202288C * a2, u32 a3, u32 a4);
+int FUN_02022AD8(struct SaveBlock2 * sav2);
+BOOL FlashLoadChunkIntoDynamicRegionFromHeader(u32 slot, struct SaveBlock2_Sub_20464 * header, u8 * dest);
+BOOL Sav2_LoadDynamicRegion(struct SaveBlock2 * sav2);
+int FUN_02022D54(struct SaveBlock2 * sav2, int chunk, u8 slot);
+int FUN_02022D94(struct SaveBlock2 * sav2, int chunk, u8 slot);
+int FUN_02022DC8(struct SaveBlock2 * sav2, int chunk, u8 slot);
+void FUN_02022DFC(struct SaveBlock2 * sav2, struct UnkSavSub_2047C * a1, int a2);
+int FUN_02022E78(struct SaveBlock2 * sav2, struct UnkSavSub_2047C * a1);
+void FUN_02022F80(struct SaveBlock2 * sav2, struct UnkSavSub_2047C * a1, int a2);
+void FUN_02022FF0(struct SaveBlock2 * sav2, struct UnkSavSub_2047C * a1);
+int FUN_02023044(struct SaveBlock2 * sav2);
+int FlashClobberChunkFooter(struct SaveBlock2 * sav2, int x, u32 y);
+u32 SavArray_sizeof(int idx);
+void SaveBlock2_InitSubstructs(struct SavArrayHeader * headers);
+void FUN_02023160(struct SaveBlock2_Sub_20464 * spec, struct SavArrayHeader * headers);
+void Sav2_InitDynamicRegion_Internal(u8 * dynamic_region, struct SavArrayHeader * headers);
+void CreateChunkFooter(struct SaveBlock2 * sav2, u8 * data, int id, u32 size);
+BOOL ValidateChunk(struct SaveBlock2 * sav2, u8 * data, int id, u32 size);
+u32 FUN_020232B4(u8 * data, u32 size);
+int WriteSaveFileToFlash(struct SaveBlock2 * sav2, int idx, u8 * data);
+u8 * ReadSaveFileFromFlash(struct SaveBlock2 * sav2, u32 heap_id, int idx, int * ret_p);
+BOOL SaveDetectFlash(void);
+int FlashWriteChunk(u32 offset, u8 * data, u32 size);
+BOOL FlashLoadChunk(u32 src, void * dest, u32 size);
+void FlashWriteCommandCallback(void * arg);
+int FlashWriteChunkInternal(u32 dest, void * src, u32 size);
+BOOL WaitFlashWrite(int lock, BOOL * res);
+void SaveErrorHandling(int lock, int errno);
#endif //POKEDIAMOND_SAVE_BLOCK_2_H