Update fn names; document public routines

This commit is contained in:
PikalaxALT 2023-12-06 21:08:07 -05:00
parent 2ffd8f2a1b
commit ac98817004
No known key found for this signature in database
GPG Key ID: C7E3D40F3BAC7AEB
4 changed files with 144 additions and 71 deletions

View File

@ -22,9 +22,10 @@
#define MG_TAG_memorial_photo 15
#define MG_TAG_max 16
#define NUM_SAVED_MYSTERY_GIFTS 8
#define NUM_SAVED_WONDER_CARDS 3
#define RECEIVED_WONDER_CARD_IDX 4
#define NUM_SAVED_MYSTERY_GIFTS 8
#define NUM_SAVED_WONDER_CARDS 3
#define RECEIVED_WONDER_CARD_IDX 4
#define NUM_MYSTERY_GIFT_RECV_FLAGS 2048
typedef struct MG_POKEMON_TAG {
BOOL fixedOT;
@ -47,7 +48,7 @@ typedef union {
u8 pokewalkerCourse;
PHOTO photo;
u8 raw[256];
} MysteryGiftTag;
} MysteryGiftData;
typedef struct {
u16 name[36];
@ -66,13 +67,13 @@ typedef struct {
u16 tag;
u16 flag : 2;
u16 dummy : 14;
MysteryGiftTag data;
MysteryGiftData data;
} MysteryGift;
typedef struct {
u16 tag;
u16 flag;
MysteryGiftTag data;
MysteryGiftData data;
UnkWonderCardSubstruct_104 unk104;
u16 text[250];
u8 shareMax;
@ -82,36 +83,108 @@ typedef struct {
} WonderCard; // size: 0x358
typedef struct {
u8 filler_000[0x100]; // 0000
u8 receivedFlags[NUM_MYSTERY_GIFT_RECV_FLAGS / 8]; // 0000
MysteryGift gifts[NUM_SAVED_MYSTERY_GIFTS]; // 0100
WonderCard cards[NUM_SAVED_WONDER_CARDS]; // 920
WonderCard specialWonderCard; // 1328
} MYSTERY_GIFT_SAVE; // size = 0x1680
} MysteryGiftSave; // size = 0x1680
// Save block API
u32 Save_MysteryGift_sizeof(void);
void Save_MysteryGift_Init(MYSTERY_GIFT_SAVE *mg);
WonderCard* SaveMysteryGift_CardGetByIdx(MYSTERY_GIFT_SAVE* mg, int index);
BOOL SaveMysteryGift_FindAvailable(MYSTERY_GIFT_SAVE* mg);
BOOL SaveMysteryGift_TryInsertGift(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag);
BOOL SaveMysteryGift_TryInsertCard(MYSTERY_GIFT_SAVE* mg, const WonderCard* src);
BOOL SaveMysteryGift_TrySetSpecialCard(MYSTERY_GIFT_SAVE* mg, const WonderCard* src);
BOOL SaveMysteryGift_ReceiveGiftAndClearCardByIndex(MYSTERY_GIFT_SAVE* mg, int index);
BOOL SaveMysteryGift_DeleteWonderCardByIndex(MYSTERY_GIFT_SAVE* mg, int index);
BOOL SaveMysteryGift_CardFindAvailable(MYSTERY_GIFT_SAVE* mg);
BOOL SaveMysteryGift_CardTagIsValid(MYSTERY_GIFT_SAVE* mg, int index);
BOOL SaveMysteryGift_SpecialCardTagIsValid(MYSTERY_GIFT_SAVE* mg);
BOOL SaveMysteryGift_HasAnyCard(MYSTERY_GIFT_SAVE* mg);
BOOL SaveMysteryGift_HasAnyGift(MYSTERY_GIFT_SAVE* mg, int a1);
BOOL SaveMysteryGift_ReceivedFlagTest(MYSTERY_GIFT_SAVE* mg, int a1);
void SaveMysteryGift_ReceivedFlagSet(MYSTERY_GIFT_SAVE* mg, int a1);
BOOL SaveMysteryGift_TestFlagx7FF(MYSTERY_GIFT_SAVE* mg);
void SaveMysteryGift_SetFlagx7FF(MYSTERY_GIFT_SAVE* mg);
void Save_MysteryGift_Init(MysteryGiftSave *mg);
// Returns a pointer to the requested Wonder Card.
// If the index is 0, 1, or 2, will return a
// pointer to the corresponding Wonder Card slot,
// or NULL if that card slot is unoccupied or
// corrupted. Otherwise, if the index is 4,
// will return a non-nullable pointer to a
// special Wonder Card slot that's exclusive
// to HGSS. Otherwise, returns NULL.
WonderCard* SaveMysteryGift_CardGetByIdx(MysteryGiftSave* mg, int index);
// Returns TRUE if there is an open slot
// to receive a gift. The capacity is 8.
BOOL SaveMysteryGift_FindAvailable(const MysteryGiftSave* mg);
// Attempts to insert a Mystery Gift into an
// open slot. Returns TRUE on success.
BOOL SaveMysteryGift_TryInsertGift(MysteryGiftSave* mg, const MysteryGift* src, int cardIdx);
// Attempts to insert a Wonder Card into an
// open slot. Returns TRUE on success.
BOOL SaveMysteryGift_TryInsertCard(MysteryGiftSave* mg, const WonderCard* src);
// Attempts to set the special Wonder Card slot
// with the given data. Returns TRUE on success.
BOOL SaveMysteryGift_TrySetSpecialCard(MysteryGiftSave* mg, const WonderCard* src);
// Deletes the Wonder Card at the given slot,
// clears the corresponding event flag, and
// removes the corresponding gift. Returns TRUE.
BOOL SaveMysteryGift_ReceiveGiftAndClearCardByIndex(MysteryGiftSave* mg, int index);
// Deletes the Wonder Card at the given slot.
// Returns TRUE.
BOOL SaveMysteryGift_DeleteWonderCardByIndex(MysteryGiftSave* mg, int index);
// Returns TRUE if there is an open slot to add a
// new Wonder Card
BOOL SaveMysteryGift_CardFindAvailable(const MysteryGiftSave* mg);
// Returns TRUE if the given Wonder Card slot is
// occupied.
BOOL SaveMysteryGift_CardTagIsValid(const MysteryGiftSave* mg, int index);
// Returns TRUE if the special Wonder Card slot
// is occupied.
BOOL SaveMysteryGift_SpecialCardTagIsValid(const MysteryGiftSave* mg);
// Returns TRUE if any Wonder Card slot is
// occupied, excluding the special slot.
BOOL SaveMysteryGift_HasAnyCard(const MysteryGiftSave* mg);
// Returns TRUE if any Mystery Gift slot is
// occupied.
BOOL SaveMysteryGift_HasAnyGift(const MysteryGiftSave* mg, int index);
// Checks the event flag by index. Returns
// TRUE if set.
BOOL SaveMysteryGift_ReceivedFlagTest(const MysteryGiftSave* mg, int index);
// Sets the event flag by index.
void SaveMysteryGift_ReceivedFlagSet(MysteryGiftSave* mg, int index);
// Checks whether flag 0x7FF (2047) is set.
// Returns TRUE if so.
BOOL SaveMysteryGift_TestFlagx7FF(const MysteryGiftSave* mg);
// Sets flag 0x7FF (2047).
void SaveMysteryGift_SetFlagx7FF(MysteryGiftSave* mg);
// The following functions are used by script
// commands.
// Loads the internal MysteryGiftSave pointer.
void GetStaticPointerToSaveMysteryGift(SaveData* saveData);
// Unloads the internal MysteryGiftSave pointer.
void DeleteStaticPointerToMysteryGift(void);
// Gets the index of the first occupied
// Mystery Gift slot.
int GetFirstQueuedMysteryGiftIdx(void);
// Returns the Mystery Gift type at the
// given slot index.
u16 GetMysteryGiftTagByIdx(int index);
MysteryGiftTag* GetMysteryGiftDataByIdx(int index);
MysteryGiftTag* GetMysteryGiftDataByIdx(int index);
// Retrieves a pointer to the Mystery Gift data
// at the given slot index.
MysteryGiftData* GetMysteryGiftDataByIdx(int index);
// Flag the Mystery Gift at the given slot index
// as received.
void SetMysteryGiftReceivedByIdx(int index);
#endif //POKEHEARTGOLD_MYSTERY_GIFT_H

View File

@ -34,7 +34,7 @@ extern const int gNumExtraSaveChunkHeaders;
struct UnkStruct_0202E474 *sub_020270C4(SaveData *saveData);
PCStorage *SaveArray_PCStorage_Get(SaveData *saveData);
MYSTERY_GIFT_SAVE *Save_MysteryGift_Get(SaveData *saveData);
MysteryGiftSave *Save_MysteryGift_Get(SaveData *saveData);
struct MigratedPokemonSav *Save_MigratedPokemon_Get(SaveData *saveData);
HALL_OF_FAME *LoadHallOfFame(SaveData *saveData, HeapID heapId, int *ret_p);
int SaveHallOfFame(SaveData *saveData, HALL_OF_FAME *hallOfFame);

View File

@ -5,18 +5,18 @@
#include "constants/save_arrays.h"
BOOL MysteryGiftTagIsValid(u32 tag);
MysteryGift* SaveMysteryGift_GetByIdx(MYSTERY_GIFT_SAVE* mg, int index);
BOOL SaveMysteryGiftI_SetReceived(MYSTERY_GIFT_SAVE* mg, int index);
void SaveMysteryGift_ReceivedFlagClear(MYSTERY_GIFT_SAVE* mg, int index);
void SaveMysteryGift_SetReceivedByCardId(MYSTERY_GIFT_SAVE* mg, int index);
BOOL SaveMysteryGiftI_TagIsValid(MYSTERY_GIFT_SAVE* mg, int index);
void SaveMysteryGift_ReceivedFlagClear(MYSTERY_GIFT_SAVE* mg, int a1);
MysteryGift* SaveMysteryGift_GetByIdx(MysteryGiftSave* mg, int index);
BOOL SaveMysteryGift_SetReceivedByIdx(MysteryGiftSave* mg, int index);
void SaveMysteryGift_ReceivedFlagClear(MysteryGiftSave* mg, int index);
void SaveMysteryGift_SetReceivedByCardId(MysteryGiftSave* mg, int index);
BOOL SaveMysteryGift_TagAtIndexIsValid(const MysteryGiftSave* mg, int index);
void SaveMysteryGift_ReceivedFlagClear(MysteryGiftSave* mg, int index);
u32 Save_MysteryGift_sizeof(void) {
return sizeof(MYSTERY_GIFT_SAVE);
return sizeof(MysteryGiftSave);
}
void Save_MysteryGift_Init(MYSTERY_GIFT_SAVE* mg) {
void Save_MysteryGift_Init(MysteryGiftSave* mg) {
SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT);
}
@ -24,7 +24,7 @@ BOOL MysteryGiftTagIsValid(u32 tag) {
return tag != MG_TAG_invalid && tag < MG_TAG_max;
}
MysteryGift* SaveMysteryGift_GetByIdx(MYSTERY_GIFT_SAVE* mg, int index) {
MysteryGift* SaveMysteryGift_GetByIdx(MysteryGiftSave* mg, int index) {
if (index >= 0 && index < NUM_SAVED_MYSTERY_GIFTS) {
MysteryGift* ret = &mg->gifts[index];
if (MysteryGiftTagIsValid(ret->tag)) {
@ -35,7 +35,7 @@ MysteryGift* SaveMysteryGift_GetByIdx(MYSTERY_GIFT_SAVE* mg, int index) {
return NULL;
}
WonderCard* SaveMysteryGift_CardGetByIdx(MYSTERY_GIFT_SAVE* mg, int index) {
WonderCard* SaveMysteryGift_CardGetByIdx(MysteryGiftSave* mg, int index) {
if (index >= 0 && index < NUM_SAVED_WONDER_CARDS) {
WonderCard* ret = &mg->cards[index];
if (MysteryGiftTagIsValid(ret->tag)) {
@ -48,7 +48,7 @@ WonderCard* SaveMysteryGift_CardGetByIdx(MYSTERY_GIFT_SAVE* mg, int index) {
return NULL;
}
BOOL SaveMysteryGift_TryInsertGift(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag) {
BOOL SaveMysteryGift_TryInsertGift(MysteryGiftSave* mg, const MysteryGift* src, int cardIdx) {
BOOL ret = FALSE;
int i;
@ -59,7 +59,7 @@ BOOL SaveMysteryGift_TryInsertGift(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src
for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) {
if (!MysteryGiftTagIsValid(mg->gifts[i].tag)) {
MI_CpuCopy8(src, &mg->gifts[i], sizeof(MysteryGift));
mg->gifts[i].flag = flag;
mg->gifts[i].flag = cardIdx;
ret = TRUE;
break;
}
@ -69,7 +69,7 @@ BOOL SaveMysteryGift_TryInsertGift(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src
return ret;
}
BOOL SaveMysteryGift_TryInsertCard(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) {
BOOL SaveMysteryGift_TryInsertCard(MysteryGiftSave* mg, const WonderCard* src) {
BOOL ret = FALSE;
int i;
@ -96,7 +96,7 @@ BOOL SaveMysteryGift_TryInsertCard(MYSTERY_GIFT_SAVE* mg, const WonderCard* src)
return ret;
}
BOOL SaveMysteryGift_TrySetSpecialCard(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) {
BOOL SaveMysteryGift_TrySetSpecialCard(MysteryGiftSave* mg, const WonderCard* src) {
if (MysteryGiftTagIsValid(mg->specialWonderCard.tag) == TRUE) {
return FALSE;
}
@ -106,7 +106,7 @@ BOOL SaveMysteryGift_TrySetSpecialCard(MYSTERY_GIFT_SAVE* mg, const WonderCard*
return FALSE;
}
BOOL SaveMysteryGiftI_SetReceived(MYSTERY_GIFT_SAVE* mg, int index) {
BOOL SaveMysteryGift_SetReceivedByIdx(MysteryGiftSave* mg, int index) {
GF_ASSERT(index < NUM_SAVED_MYSTERY_GIFTS);
mg->gifts[index].tag = MG_TAG_invalid;
mg->gifts[index].flag = 0;
@ -114,7 +114,7 @@ BOOL SaveMysteryGiftI_SetReceived(MYSTERY_GIFT_SAVE* mg, int index) {
return TRUE;
}
BOOL SaveMysteryGift_ReceiveGiftAndClearCardByIndex(MYSTERY_GIFT_SAVE* mg, int index) {
BOOL SaveMysteryGift_ReceiveGiftAndClearCardByIndex(MysteryGiftSave* mg, int index) {
GF_ASSERT(index < NUM_SAVED_WONDER_CARDS);
mg->cards[index].tag = MG_TAG_invalid;
SaveMysteryGift_ReceivedFlagClear(mg, mg->cards[index].unk104.id);
@ -123,14 +123,14 @@ BOOL SaveMysteryGift_ReceiveGiftAndClearCardByIndex(MYSTERY_GIFT_SAVE* mg, int i
return TRUE;
}
BOOL SaveMysteryGift_DeleteWonderCardByIndex(MYSTERY_GIFT_SAVE* mg, int index) {
BOOL SaveMysteryGift_DeleteWonderCardByIndex(MysteryGiftSave* mg, int index) {
GF_ASSERT(index < NUM_SAVED_WONDER_CARDS);
mg->cards[index].tag = MG_TAG_invalid;
SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT);
return TRUE;
}
BOOL SaveMysteryGift_FindAvailable(MYSTERY_GIFT_SAVE* mg) {
BOOL SaveMysteryGift_FindAvailable(const MysteryGiftSave* mg) {
int i;
for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) {
@ -142,7 +142,7 @@ BOOL SaveMysteryGift_FindAvailable(MYSTERY_GIFT_SAVE* mg) {
return FALSE;
}
BOOL SaveMysteryGift_CardFindAvailable(MYSTERY_GIFT_SAVE* mg) {
BOOL SaveMysteryGift_CardFindAvailable(const MysteryGiftSave* mg) {
int i;
for (i = 0; i < NUM_SAVED_WONDER_CARDS; ++i) {
@ -154,7 +154,7 @@ BOOL SaveMysteryGift_CardFindAvailable(MYSTERY_GIFT_SAVE* mg) {
return FALSE;
}
BOOL SaveMysteryGiftI_TagIsValid(MYSTERY_GIFT_SAVE* mg, int index) {
BOOL SaveMysteryGift_TagAtIndexIsValid(const MysteryGiftSave* mg, int index) {
GF_ASSERT(index < NUM_SAVED_MYSTERY_GIFTS);
if (MysteryGiftTagIsValid(mg->gifts[index].tag)) {
@ -164,7 +164,7 @@ BOOL SaveMysteryGiftI_TagIsValid(MYSTERY_GIFT_SAVE* mg, int index) {
}
}
BOOL SaveMysteryGift_CardTagIsValid(MYSTERY_GIFT_SAVE* mg, int index) {
BOOL SaveMysteryGift_CardTagIsValid(const MysteryGiftSave* mg, int index) {
GF_ASSERT(index < NUM_SAVED_WONDER_CARDS);
if (MysteryGiftTagIsValid(mg->cards[index].tag)) {
@ -174,7 +174,7 @@ BOOL SaveMysteryGift_CardTagIsValid(MYSTERY_GIFT_SAVE* mg, int index) {
}
}
BOOL SaveMysteryGift_SpecialCardTagIsValid(MYSTERY_GIFT_SAVE* mg) {
BOOL SaveMysteryGift_SpecialCardTagIsValid(const MysteryGiftSave* mg) {
if (MysteryGiftTagIsValid(mg->specialWonderCard.tag)) {
return TRUE;
} else {
@ -182,7 +182,7 @@ BOOL SaveMysteryGift_SpecialCardTagIsValid(MYSTERY_GIFT_SAVE* mg) {
}
}
BOOL SaveMysteryGift_HasAnyCard(MYSTERY_GIFT_SAVE* mg) {
BOOL SaveMysteryGift_HasAnyCard(const MysteryGiftSave* mg) {
int i;
for (i = 0; i < NUM_SAVED_WONDER_CARDS; ++i) {
@ -194,7 +194,7 @@ BOOL SaveMysteryGift_HasAnyCard(MYSTERY_GIFT_SAVE* mg) {
return FALSE;
}
BOOL SaveMysteryGift_HasAnyGift(MYSTERY_GIFT_SAVE* mg, int a1) {
BOOL SaveMysteryGift_HasAnyGift(const MysteryGiftSave* mg, int a1) {
int i;
for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) {
@ -206,44 +206,44 @@ BOOL SaveMysteryGift_HasAnyGift(MYSTERY_GIFT_SAVE* mg, int a1) {
return FALSE;
}
void SaveMysteryGift_SetReceivedByCardId(MYSTERY_GIFT_SAVE* mg, int a1) {
void SaveMysteryGift_SetReceivedByCardId(MysteryGiftSave* mg, int a1) {
int i;
for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) {
if (MysteryGiftTagIsValid(mg->gifts[i].tag) && a1 == mg->gifts[i].flag) {
SaveMysteryGiftI_SetReceived(mg, i);
SaveMysteryGift_SetReceivedByIdx(mg, i);
break;
}
}
}
BOOL SaveMysteryGift_ReceivedFlagTest(MYSTERY_GIFT_SAVE* mg, int a1) {
GF_ASSERT(a1 < 2048);
return mg->filler_000[a1 / 8] & (1 << (a1 & 7)) ? TRUE : FALSE;
BOOL SaveMysteryGift_ReceivedFlagTest(const MysteryGiftSave* mg, int index) {
GF_ASSERT(index < NUM_MYSTERY_GIFT_RECV_FLAGS);
return mg->receivedFlags[index / 8] & (1 << (index & 7)) ? TRUE : FALSE;
}
void SaveMysteryGift_ReceivedFlagSet(MYSTERY_GIFT_SAVE* mg, int a1) {
GF_ASSERT(a1 < 2048);
mg->filler_000[a1 / 8] |= (1 << (a1 & 7));
void SaveMysteryGift_ReceivedFlagSet(MysteryGiftSave* mg, int index) {
GF_ASSERT(index < NUM_MYSTERY_GIFT_RECV_FLAGS);
mg->receivedFlags[index / 8] |= (1 << (index & 7));
SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT);
}
void SaveMysteryGift_ReceivedFlagClear(MYSTERY_GIFT_SAVE* mg, int a1) {
u8 mask = ~(1 << (a1 & 7));
GF_ASSERT(a1 < 2048);
mg->filler_000[a1 / 8] &= mask;
void SaveMysteryGift_ReceivedFlagClear(MysteryGiftSave* mg, int index) {
u8 mask = ~(1 << (index & 7));
GF_ASSERT(index < NUM_MYSTERY_GIFT_RECV_FLAGS);
mg->receivedFlags[index / 8] &= mask;
SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT);
}
BOOL SaveMysteryGift_TestFlagx7FF(MYSTERY_GIFT_SAVE* mg) {
BOOL SaveMysteryGift_TestFlagx7FF(const MysteryGiftSave* mg) {
return SaveMysteryGift_ReceivedFlagTest(mg, 0x7FF);
}
void SaveMysteryGift_SetFlagx7FF(MYSTERY_GIFT_SAVE* mg) {
void SaveMysteryGift_SetFlagx7FF(MysteryGiftSave* mg) {
SaveMysteryGift_ReceivedFlagSet(mg, 0x7FF);
}
static MYSTERY_GIFT_SAVE* sMysteryGiftData;
static MysteryGiftSave* sMysteryGiftData;
void GetStaticPointerToSaveMysteryGift(SaveData* saveData) {
if (sMysteryGiftData == NULL) {
@ -262,7 +262,7 @@ int GetFirstQueuedMysteryGiftIdx(void) {
int i;
for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) {
if (SaveMysteryGiftI_TagIsValid(sMysteryGiftData, i) == TRUE) {
if (SaveMysteryGift_TagAtIndexIsValid(sMysteryGiftData, i) == TRUE) {
return i;
}
}
@ -279,7 +279,7 @@ u16 GetMysteryGiftTagByIdx(int index) {
return MG_TAG_invalid;
}
MysteryGiftTag* GetMysteryGiftDataByIdx(int index) {
MysteryGiftData* GetMysteryGiftDataByIdx(int index) {
MysteryGift* gift = SaveMysteryGift_GetByIdx(sMysteryGiftData, index);
if (gift != NULL) {
return &gift->data;
@ -289,5 +289,5 @@ MysteryGiftTag* GetMysteryGiftDataByIdx(int index) {
}
void SetMysteryGiftReceivedByIdx(int index) {
SaveMysteryGiftI_SetReceived(sMysteryGiftData, index);
SaveMysteryGift_SetReceivedByIdx(sMysteryGiftData, index);
}

View File

@ -271,7 +271,7 @@ PCStorage *SaveArray_PCStorage_Get(SaveData *saveData) {
return SaveArray_Get(saveData, SAVE_PCSTORAGE);
}
MYSTERY_GIFT_SAVE *Save_MysteryGift_Get(SaveData *saveData) {
MysteryGiftSave *Save_MysteryGift_Get(SaveData *saveData) {
SaveSubstruct_AssertCRC(SAVE_MYSTERY_GIFT);
return SaveArray_Get(saveData, SAVE_MYSTERY_GIFT);
}