From ec1f0aa45a0c54030cbacd6c299a70c6bd7925e4 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 1 Dec 2023 19:06:03 -0500 Subject: [PATCH 1/7] Through sub_0202DC2C --- asm/unk_0202DBA8.s | 159 ++--------------------------------------- include/mystery_gift.h | 49 +++++++------ main.lsf | 1 + src/mystery_gift.c | 66 +++++++++++++++++ 4 files changed, 100 insertions(+), 175 deletions(-) create mode 100644 src/mystery_gift.c diff --git a/asm/unk_0202DBA8.s b/asm/unk_0202DBA8.s index e8617c5f60..f5960bc9f3 100644 --- a/asm/unk_0202DBA8.s +++ b/asm/unk_0202DBA8.s @@ -2,168 +2,17 @@ .include "unk_0202DBA8.inc" .include "global.inc" + .public MysteryGiftTagIsValid + .public SaveMysteryGift_GetByIdx + .bss + .public sMysteryGiftData sMysteryGiftData: .space 0x4 .text - thumb_func_start Save_MysteryGift_sizeof -Save_MysteryGift_sizeof: ; 0x0202DBA8 - mov r0, #0x5a - lsl r0, r0, #6 - bx lr - .balign 4, 0 - thumb_func_end Save_MysteryGift_sizeof - - thumb_func_start Save_MysteryGift_Init -Save_MysteryGift_Init: ; 0x0202DBB0 - ldr r3, _0202DBB8 ; =SaveSubstruct_UpdateCRC - mov r0, #0x1b - bx r3 - nop -_0202DBB8: .word SaveSubstruct_UpdateCRC - thumb_func_end Save_MysteryGift_Init - - thumb_func_start MysteryGiftTagIsValid -MysteryGiftTagIsValid: ; 0x0202DBBC - cmp r0, #0 - beq _0202DBC8 - cmp r0, #0x10 - bhs _0202DBC8 - mov r0, #1 - bx lr -_0202DBC8: - mov r0, #0 - bx lr - thumb_func_end MysteryGiftTagIsValid - - thumb_func_start SaveMysteryGift_GetByIdx -SaveMysteryGift_GetByIdx: ; 0x0202DBCC - push {r3, r4, r5, lr} - cmp r1, #0 - blt _0202DBF0 - cmp r1, #8 - bge _0202DBF0 - mov r2, #1 - lsl r2, r2, #8 - add r4, r0, r2 - lsl r0, r1, #6 - add r0, r1, r0 - lsl r5, r0, #2 - ldrh r0, [r4, r5] - bl MysteryGiftTagIsValid - cmp r0, #0 - beq _0202DBF0 - add r0, r4, r5 - pop {r3, r4, r5, pc} -_0202DBF0: - mov r0, #0 - pop {r3, r4, r5, pc} - thumb_func_end SaveMysteryGift_GetByIdx - - thumb_func_start SaveMysteryGift_CardGetByIdx -SaveMysteryGift_CardGetByIdx: ; 0x0202DBF4 - push {r3, r4, r5, lr} - cmp r1, #0 - blt _0202DC1A - cmp r1, #3 - bge _0202DC1A - mov r2, #0x92 - lsl r2, r2, #4 - add r4, r0, r2 - mov r0, #0xd6 - lsl r0, r0, #2 - add r5, r1, #0 - mul r5, r0 - ldrh r0, [r4, r5] - bl MysteryGiftTagIsValid - cmp r0, #0 - beq _0202DC24 - add r0, r4, r5 - pop {r3, r4, r5, pc} -_0202DC1A: - cmp r1, #4 - bne _0202DC24 - ldr r1, _0202DC28 ; =0x00001328 - add r0, r0, r1 - pop {r3, r4, r5, pc} -_0202DC24: - mov r0, #0 - pop {r3, r4, r5, pc} - .balign 4, 0 -_0202DC28: .word 0x00001328 - thumb_func_end SaveMysteryGift_CardGetByIdx - - thumb_func_start sub_0202DC2C -sub_0202DC2C: ; 0x0202DC2C - push {r3, r4, r5, r6, r7, lr} - sub sp, #0x10 - str r1, [sp, #4] - mov r1, #0 - str r0, [sp] - str r2, [sp, #8] - str r1, [sp, #0xc] - bl SaveMysteryGift_FindAvailable - cmp r0, #0 - bne _0202DC48 - add sp, #0x10 - mov r0, #0 - pop {r3, r4, r5, r6, r7, pc} -_0202DC48: - mov r7, #0x41 - lsl r7, r7, #2 - ldr r5, [sp] - mov r4, #0 - sub r6, r7, #4 -_0202DC52: - ldrh r0, [r5, r6] - bl MysteryGiftTagIsValid - cmp r0, #0 - bne _0202DC94 - lsl r0, r4, #6 - mov r2, #1 - add r0, r4, r0 - lsl r4, r0, #2 - ldr r1, [sp] - lsl r2, r2, #8 - add r1, r1, r2 - ldr r0, [sp, #4] - add r1, r1, r4 - add r2, r2, #4 - bl MI_CpuCopy8 - ldr r1, _0202DCA8 ; =0x00000102 - ldr r0, [sp] - mov r2, #3 - add r1, r0, r1 - ldrh r0, [r1, r4] - bic r0, r2 - ldr r2, [sp, #8] - lsl r2, r2, #0x10 - lsr r3, r2, #0x10 - mov r2, #3 - and r2, r3 - orr r0, r2 - strh r0, [r1, r4] - mov r0, #1 - str r0, [sp, #0xc] - b _0202DC9C -_0202DC94: - add r4, r4, #1 - add r5, r5, r7 - cmp r4, #8 - blt _0202DC52 -_0202DC9C: - mov r0, #0x1b - bl SaveSubstruct_UpdateCRC - ldr r0, [sp, #0xc] - add sp, #0x10 - pop {r3, r4, r5, r6, r7, pc} - .balign 4, 0 -_0202DCA8: .word 0x00000102 - thumb_func_end sub_0202DC2C - thumb_func_start sub_0202DCAC sub_0202DCAC: ; 0x0202DCAC push {r4, r5, r6, r7, lr} diff --git a/include/mystery_gift.h b/include/mystery_gift.h index c1540b6f31..43d9780f9e 100644 --- a/include/mystery_gift.h +++ b/include/mystery_gift.h @@ -4,23 +4,27 @@ #include "pokemon_types_def.h" #include "photo_album.h" -enum MysteryGiftTag { - MG_TAG_pokemon, - MG_TAG_egg, - MG_TAG_item, - MG_TAG_battle_rules, - MG_TAG_secret_base_deco, // disabled in hgss - MG_TAG_mon_deco, - MG_TAG_manaphy_egg, - MG_TAG_member_card, // disabled in hgss - MG_TAG_oaks_letter, // disabled in hgss - MG_TAG_azure_flute, // disabled in hgss - MG_TAG_poketch_app, // disabled in hgss - MG_TAG_secret_key, // disabled in hgss - MG_TAG_pokemon_movie, - MG_TAG_pokewalker_course, - MG_TAG_memorial_photo, -}; +#define MG_TAG_invalid 0 +#define MG_TAG_pokemon 1 +#define MG_TAG_egg 2 +#define MG_TAG_item 3 +#define MG_TAG_battle_rules 4 +#define MG_TAG_secret_base_deco 5 // disabled in hgss +#define MG_TAG_mon_deco 6 +#define MG_TAG_manaphy_egg 7 +#define MG_TAG_member_card 8 // disabled in hgss +#define MG_TAG_oaks_letter 9 // disabled in hgss +#define MG_TAG_azure_flute 10 // disabled in hgss +#define MG_TAG_poketch_app 11 // disabled in hgss +#define MG_TAG_secret_key 12 // disabled in hgss +#define MG_TAG_pokemon_movie 13 +#define MG_TAG_pokewalker_course 14 +#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 typedef struct MG_POKEMON_TAG { BOOL fixedOT; @@ -35,7 +39,8 @@ typedef struct MG_MON_DECO_TAG { typedef struct { u16 tag; - u16 flag; + u16 flag : 2; + u16 dummy : 14; union { MG_POKEMON_TAG pokemon; Pokemon egg; @@ -59,11 +64,15 @@ typedef struct { typedef struct { u8 filler_000[0x100]; // 0000 - MysteryGift gifts[8]; // 0100 - WonderCard cards[4]; // 920 + MysteryGift gifts[NUM_SAVED_MYSTERY_GIFTS]; // 0100 + WonderCard cards[NUM_SAVED_WONDER_CARDS]; // 920 + WonderCard receivedCard; // 1328 } MYSTERY_GIFT_SAVE; // size = 0x1680 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 sub_0202DC2C(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag); #endif //POKEHEARTGOLD_MYSTERY_GIFT_H diff --git a/main.lsf b/main.lsf index efa6006939..8edd947df4 100644 --- a/main.lsf +++ b/main.lsf @@ -120,6 +120,7 @@ Static main Object src/save_special_ribbons.o Object src/roamer.o Object asm/unk_0202DB34.o + Object src/mystery_gift.o Object asm/unk_0202DBA8.o Object src/hall_of_fame.o Object asm/unk_0202E41C.o diff --git a/src/mystery_gift.c b/src/mystery_gift.c new file mode 100644 index 0000000000..95280733d3 --- /dev/null +++ b/src/mystery_gift.c @@ -0,0 +1,66 @@ +#include "global.h" +#include "mystery_gift.h" +#include "save.h" +#include "constants/save_arrays.h" + +extern MYSTERY_GIFT_SAVE* sMysteryGiftData; + +BOOL MysteryGiftTagIsValid(u32 tag); +MysteryGift* SaveMysteryGift_GetByIdx(MYSTERY_GIFT_SAVE* mg, int index); + +u32 Save_MysteryGift_sizeof(void) { + return sizeof(MYSTERY_GIFT_SAVE); +} + +void Save_MysteryGift_Init(MYSTERY_GIFT_SAVE* mg) { + SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); +} + +BOOL MysteryGiftTagIsValid(u32 tag) { + return tag != MG_TAG_invalid && tag < MG_TAG_max; +} + +MysteryGift* SaveMysteryGift_GetByIdx(MYSTERY_GIFT_SAVE* mg, int index) { + if (index >= 0 && index < NUM_SAVED_MYSTERY_GIFTS) { + MysteryGift* ret = &mg->gifts[index]; + if (MysteryGiftTagIsValid(ret->tag)) { + return ret; + } + } + + return NULL; +} + +WonderCard* SaveMysteryGift_CardGetByIdx(MYSTERY_GIFT_SAVE* mg, int index) { + if (index >= 0 && index < NUM_SAVED_WONDER_CARDS) { + WonderCard* ret = &mg->cards[index]; + if (MysteryGiftTagIsValid(ret->tag)) { + return ret; + } + } else if (index == RECEIVED_WONDER_CARD_IDX) { + return &mg->receivedCard; + } + + return NULL; +} + +BOOL sub_0202DC2C(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag) { + BOOL ret = FALSE; + int i; + + if (!SaveMysteryGift_FindAvailable(mg)) { + return FALSE; + } + + 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; + ret = TRUE; + break; + } + } + + SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); + return ret; +} From f8c138d3215813c58b909daa9e6d6630acca59b2 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 6 Dec 2023 20:08:53 -0500 Subject: [PATCH 2/7] Finish mystery_gift.c --- asm/unk_0202DBA8.s | 631 ----------------------------------------- include/mystery_gift.h | 69 ++++- main.lsf | 1 - src/mystery_gift.c | 231 ++++++++++++++- 4 files changed, 283 insertions(+), 649 deletions(-) delete mode 100644 asm/unk_0202DBA8.s diff --git a/asm/unk_0202DBA8.s b/asm/unk_0202DBA8.s deleted file mode 100644 index f5960bc9f3..0000000000 --- a/asm/unk_0202DBA8.s +++ /dev/null @@ -1,631 +0,0 @@ - .include "asm/macros.inc" - .include "unk_0202DBA8.inc" - .include "global.inc" - - .public MysteryGiftTagIsValid - .public SaveMysteryGift_GetByIdx - - .bss - - .public sMysteryGiftData -sMysteryGiftData: - .space 0x4 - - .text - - thumb_func_start sub_0202DCAC -sub_0202DCAC: ; 0x0202DCAC - push {r4, r5, r6, r7, lr} - sub sp, #0xc - str r1, [sp, #4] - mov r1, #0 - str r0, [sp] - str r1, [sp, #8] - bl SaveMysteryGift_CardFindAvailable - cmp r0, #0 - bne _0202DCC6 - add sp, #0xc - mov r0, #0 - pop {r4, r5, r6, r7, pc} -_0202DCC6: - ldr r1, _0202DD44 ; =0x00000152 - ldr r0, [sp, #4] - ldrb r0, [r0, r1] - lsl r0, r0, #0x1c - lsr r0, r0, #0x1f - cmp r0, #1 - bne _0202DCE4 - ldr r0, [sp] - bl SaveMysteryGift_FindAvailable - cmp r0, #0 - bne _0202DCE4 - add sp, #0xc - mov r0, #0 - pop {r4, r5, r6, r7, pc} -_0202DCE4: - mov r7, #0xd6 - mov r6, #0x92 - ldr r5, [sp] - mov r4, #0 - lsl r7, r7, #2 - lsl r6, r6, #4 -_0202DCF0: - ldrh r0, [r5, r6] - bl MysteryGiftTagIsValid - cmp r0, #0 - bne _0202DD30 - mov r2, #0x92 - ldr r1, [sp] - lsl r2, r2, #4 - add r3, r1, r2 - mov r2, #0xd6 - lsl r2, r2, #2 - add r1, r4, #0 - mul r1, r2 - ldr r0, [sp, #4] - add r1, r3, r1 - bl MI_CpuCopy8 - ldr r1, _0202DD44 ; =0x00000152 - ldr r0, [sp, #4] - ldrb r0, [r0, r1] - lsl r0, r0, #0x1c - lsr r0, r0, #0x1f - cmp r0, #1 - bne _0202DD2A - ldr r0, [sp] - ldr r1, [sp, #4] - add r2, r4, #0 - bl sub_0202DC2C -_0202DD2A: - mov r0, #1 - str r0, [sp, #8] - b _0202DD38 -_0202DD30: - add r4, r4, #1 - add r5, r5, r7 - cmp r4, #3 - blt _0202DCF0 -_0202DD38: - mov r0, #0x1b - bl SaveSubstruct_UpdateCRC - ldr r0, [sp, #8] - add sp, #0xc - pop {r4, r5, r6, r7, pc} - .balign 4, 0 -_0202DD44: .word 0x00000152 - thumb_func_end sub_0202DCAC - - thumb_func_start sub_0202DD48 -sub_0202DD48: ; 0x0202DD48 - push {r3, r4, r5, lr} - add r5, r0, #0 - ldr r0, _0202DD78 ; =0x00001328 - add r4, r1, #0 - ldrh r0, [r5, r0] - bl MysteryGiftTagIsValid - cmp r0, #1 - bne _0202DD5E - mov r0, #0 - pop {r3, r4, r5, pc} -_0202DD5E: - ldr r1, _0202DD78 ; =0x00001328 - mov r2, #0xd6 - add r0, r4, #0 - add r1, r5, r1 - lsl r2, r2, #2 - bl MI_CpuCopy8 - mov r0, #0x1b - bl SaveSubstruct_UpdateCRC - mov r0, #0 - pop {r3, r4, r5, pc} - nop -_0202DD78: .word 0x00001328 - thumb_func_end sub_0202DD48 - - thumb_func_start SaveMysteryGiftI_SetReceived -SaveMysteryGiftI_SetReceived: ; 0x0202DD7C - push {r3, r4, r5, lr} - add r5, r1, #0 - add r4, r0, #0 - cmp r5, #8 - blt _0202DD8A - bl GF_AssertFail -_0202DD8A: - lsl r0, r5, #6 - add r0, r5, r0 - lsl r0, r0, #2 - mov r1, #1 - mov r3, #0 - add r2, r4, r0 - lsl r1, r1, #8 - strh r3, [r2, r1] - add r1, r1, #2 - add r3, r4, r1 - ldrh r2, [r3, r0] - mov r1, #3 - bic r2, r1 - strh r2, [r3, r0] - mov r0, #0x1b - bl SaveSubstruct_UpdateCRC - mov r0, #1 - pop {r3, r4, r5, pc} - thumb_func_end SaveMysteryGiftI_SetReceived - - thumb_func_start sub_0202DDB0 -sub_0202DDB0: ; 0x0202DDB0 - push {r3, r4, r5, lr} - add r4, r1, #0 - add r5, r0, #0 - cmp r4, #3 - blt _0202DDBE - bl GF_AssertFail -_0202DDBE: - mov r0, #0xd6 - lsl r0, r0, #2 - mul r0, r4 - add r2, r5, r0 - mov r0, #0x92 - mov r1, #0 - lsl r0, r0, #4 - strh r1, [r2, r0] - mov r1, #0xa7 - lsl r1, r1, #4 - ldrh r1, [r2, r1] - add r0, r5, #0 - bl sub_0202DFDC - add r0, r5, #0 - add r1, r4, #0 - bl sub_0202DF38 - mov r0, #0x1b - bl SaveSubstruct_UpdateCRC - mov r0, #1 - pop {r3, r4, r5, pc} - thumb_func_end sub_0202DDB0 - - thumb_func_start sub_0202DDEC -sub_0202DDEC: ; 0x0202DDEC - push {r3, r4, r5, lr} - add r4, r1, #0 - add r5, r0, #0 - cmp r4, #3 - blt _0202DDFA - bl GF_AssertFail -_0202DDFA: - mov r0, #0xd6 - lsl r0, r0, #2 - mul r0, r4 - add r1, r5, r0 - mov r0, #0x92 - mov r2, #0 - lsl r0, r0, #4 - strh r2, [r1, r0] - mov r0, #0x1b - bl SaveSubstruct_UpdateCRC - mov r0, #1 - pop {r3, r4, r5, pc} - thumb_func_end sub_0202DDEC - - thumb_func_start SaveMysteryGift_FindAvailable -SaveMysteryGift_FindAvailable: ; 0x0202DE14 - push {r3, r4, r5, r6, r7, lr} - mov r7, #0x41 - lsl r7, r7, #2 - add r5, r0, #0 - mov r4, #0 - sub r6, r7, #4 -_0202DE20: - ldrh r0, [r5, r6] - bl MysteryGiftTagIsValid - cmp r0, #0 - bne _0202DE2E - mov r0, #1 - pop {r3, r4, r5, r6, r7, pc} -_0202DE2E: - add r4, r4, #1 - add r5, r5, r7 - cmp r4, #8 - blt _0202DE20 - mov r0, #0 - pop {r3, r4, r5, r6, r7, pc} - .balign 4, 0 - thumb_func_end SaveMysteryGift_FindAvailable - - thumb_func_start SaveMysteryGift_CardFindAvailable -SaveMysteryGift_CardFindAvailable: ; 0x0202DE3C - push {r3, r4, r5, r6, r7, lr} - mov r7, #0xd6 - mov r6, #0x92 - add r5, r0, #0 - mov r4, #0 - lsl r7, r7, #2 - lsl r6, r6, #4 -_0202DE4A: - ldrh r0, [r5, r6] - bl MysteryGiftTagIsValid - cmp r0, #0 - bne _0202DE58 - mov r0, #1 - pop {r3, r4, r5, r6, r7, pc} -_0202DE58: - add r4, r4, #1 - add r5, r5, r7 - cmp r4, #3 - blt _0202DE4A - mov r0, #0 - pop {r3, r4, r5, r6, r7, pc} - thumb_func_end SaveMysteryGift_CardFindAvailable - - thumb_func_start SaveMysteryGiftI_TagIsValid -SaveMysteryGiftI_TagIsValid: ; 0x0202DE64 - push {r3, r4, r5, lr} - add r4, r1, #0 - add r5, r0, #0 - cmp r4, #8 - blt _0202DE72 - bl GF_AssertFail -_0202DE72: - lsl r0, r4, #6 - add r0, r4, r0 - lsl r0, r0, #2 - add r1, r5, r0 - mov r0, #1 - lsl r0, r0, #8 - ldrh r0, [r1, r0] - bl MysteryGiftTagIsValid - cmp r0, #0 - beq _0202DE8C - mov r0, #1 - pop {r3, r4, r5, pc} -_0202DE8C: - mov r0, #0 - pop {r3, r4, r5, pc} - thumb_func_end SaveMysteryGiftI_TagIsValid - - thumb_func_start sub_0202DE90 -sub_0202DE90: ; 0x0202DE90 - push {r3, r4, r5, lr} - add r4, r1, #0 - add r5, r0, #0 - cmp r4, #3 - blt _0202DE9E - bl GF_AssertFail -_0202DE9E: - mov r0, #0xd6 - lsl r0, r0, #2 - mul r0, r4 - add r1, r5, r0 - mov r0, #0x92 - lsl r0, r0, #4 - ldrh r0, [r1, r0] - bl MysteryGiftTagIsValid - cmp r0, #0 - beq _0202DEB8 - mov r0, #1 - pop {r3, r4, r5, pc} -_0202DEB8: - mov r0, #0 - pop {r3, r4, r5, pc} - thumb_func_end sub_0202DE90 - - thumb_func_start sub_0202DEBC -sub_0202DEBC: ; 0x0202DEBC - push {r3, lr} - ldr r1, _0202DED4 ; =0x00001328 - ldrh r0, [r0, r1] - bl MysteryGiftTagIsValid - cmp r0, #0 - beq _0202DECE - mov r0, #1 - pop {r3, pc} -_0202DECE: - mov r0, #0 - pop {r3, pc} - nop -_0202DED4: .word 0x00001328 - thumb_func_end sub_0202DEBC - - thumb_func_start sub_0202DED8 -sub_0202DED8: ; 0x0202DED8 - push {r3, r4, r5, lr} - add r5, r0, #0 - mov r4, #0 -_0202DEDE: - add r0, r5, #0 - add r1, r4, #0 - bl sub_0202DE90 - cmp r0, #1 - bne _0202DEEE - mov r0, #1 - pop {r3, r4, r5, pc} -_0202DEEE: - add r4, r4, #1 - cmp r4, #3 - blt _0202DEDE - mov r0, #0 - pop {r3, r4, r5, pc} - thumb_func_end sub_0202DED8 - - thumb_func_start sub_0202DEF8 -sub_0202DEF8: ; 0x0202DEF8 - push {r3, r4, r5, r6, r7, lr} - add r5, r0, #0 - ldr r0, _0202DF34 ; =0x00000102 - add r7, r1, #0 - mov r6, #0 - add r4, r5, r0 -_0202DF04: - mov r0, #1 - lsl r0, r0, #8 - ldrh r0, [r5, r0] - bl MysteryGiftTagIsValid - cmp r0, #0 - beq _0202DF20 - ldrh r0, [r4] - lsl r0, r0, #0x1e - lsr r0, r0, #0x1e - cmp r7, r0 - bne _0202DF20 - mov r0, #1 - pop {r3, r4, r5, r6, r7, pc} -_0202DF20: - mov r0, #0x41 - lsl r0, r0, #2 - add r6, r6, #1 - add r5, r5, r0 - add r4, r4, r0 - cmp r6, #8 - blt _0202DF04 - mov r0, #0 - pop {r3, r4, r5, r6, r7, pc} - nop -_0202DF34: .word 0x00000102 - thumb_func_end sub_0202DEF8 - - thumb_func_start sub_0202DF38 -sub_0202DF38: ; 0x0202DF38 - push {r3, r4, r5, r6, r7, lr} - add r7, r1, #0 - ldr r1, _0202DF78 ; =0x00000102 - str r0, [sp] - mov r6, #0 - add r4, r0, #0 - add r5, r0, r1 -_0202DF46: - mov r0, #1 - lsl r0, r0, #8 - ldrh r0, [r4, r0] - bl MysteryGiftTagIsValid - cmp r0, #0 - beq _0202DF68 - ldrh r0, [r5] - lsl r0, r0, #0x1e - lsr r0, r0, #0x1e - cmp r7, r0 - bne _0202DF68 - ldr r0, [sp] - add r1, r6, #0 - bl SaveMysteryGiftI_SetReceived - pop {r3, r4, r5, r6, r7, pc} -_0202DF68: - mov r0, #0x41 - lsl r0, r0, #2 - add r6, r6, #1 - add r4, r4, r0 - add r5, r5, r0 - cmp r6, #8 - blt _0202DF46 - pop {r3, r4, r5, r6, r7, pc} - .balign 4, 0 -_0202DF78: .word 0x00000102 - thumb_func_end sub_0202DF38 - - thumb_func_start sub_0202DF7C -sub_0202DF7C: ; 0x0202DF7C - push {r3, r4, r5, lr} - add r5, r0, #0 - mov r0, #2 - add r4, r1, #0 - lsl r0, r0, #0xa - cmp r4, r0 - blt _0202DF8E - bl GF_AssertFail -_0202DF8E: - mov r0, #1 - mov r1, #7 - add r2, r4, #0 - and r2, r1 - add r1, r0, #0 - lsl r1, r2 - asr r2, r4, #2 - lsr r2, r2, #0x1d - add r2, r4, r2 - asr r2, r2, #3 - ldrb r2, [r5, r2] - tst r1, r2 - bne _0202DFAA - mov r0, #0 -_0202DFAA: - pop {r3, r4, r5, pc} - thumb_func_end sub_0202DF7C - - thumb_func_start sub_0202DFAC -sub_0202DFAC: ; 0x0202DFAC - push {r3, r4, r5, lr} - add r5, r0, #0 - mov r0, #2 - add r4, r1, #0 - lsl r0, r0, #0xa - cmp r4, r0 - blt _0202DFBE - bl GF_AssertFail -_0202DFBE: - asr r0, r4, #2 - lsr r0, r0, #0x1d - add r0, r4, r0 - asr r1, r0, #3 - mov r2, #7 - ldrb r0, [r5, r1] - mov r3, #1 - and r2, r4 - lsl r3, r2 - orr r0, r3 - strb r0, [r5, r1] - mov r0, #0x1b - bl SaveSubstruct_UpdateCRC - pop {r3, r4, r5, pc} - thumb_func_end sub_0202DFAC - - thumb_func_start sub_0202DFDC -sub_0202DFDC: ; 0x0202DFDC - push {r4, r5, r6, lr} - add r5, r0, #0 - add r4, r1, #0 - mov r1, #1 - mov r0, #7 - and r0, r4 - add r2, r1, #0 - lsl r2, r0 - mvn r0, r2 - lsl r0, r0, #0x18 - lsr r6, r0, #0x18 - lsl r0, r1, #0xb - cmp r4, r0 - blt _0202DFFC - bl GF_AssertFail -_0202DFFC: - asr r0, r4, #2 - lsr r0, r0, #0x1d - add r0, r4, r0 - asr r1, r0, #3 - ldrb r0, [r5, r1] - and r0, r6 - strb r0, [r5, r1] - mov r0, #0x1b - bl SaveSubstruct_UpdateCRC - pop {r4, r5, r6, pc} - .balign 4, 0 - thumb_func_end sub_0202DFDC - - thumb_func_start sub_0202E014 -sub_0202E014: ; 0x0202E014 - ldr r3, _0202E01C ; =sub_0202DF7C - ldr r1, _0202E020 ; =0x000007FF - bx r3 - nop -_0202E01C: .word sub_0202DF7C -_0202E020: .word 0x000007FF - thumb_func_end sub_0202E014 - - thumb_func_start sub_0202E024 -sub_0202E024: ; 0x0202E024 - ldr r3, _0202E02C ; =sub_0202DFAC - ldr r1, _0202E030 ; =0x000007FF - bx r3 - nop -_0202E02C: .word sub_0202DFAC -_0202E030: .word 0x000007FF - thumb_func_end sub_0202E024 - - thumb_func_start GetStaticPointerToSaveMysteryGift -GetStaticPointerToSaveMysteryGift: ; 0x0202E034 - push {r3, lr} - ldr r1, _0202E050 ; =sMysteryGiftData - ldr r1, [r1] - cmp r1, #0 - bne _0202E046 - bl Save_MysteryGift_Get - ldr r1, _0202E050 ; =sMysteryGiftData - str r0, [r1] -_0202E046: - mov r0, #0x1b - bl SaveSubstruct_UpdateCRC - pop {r3, pc} - nop -_0202E050: .word sMysteryGiftData - thumb_func_end GetStaticPointerToSaveMysteryGift - - thumb_func_start DeleteStaticPointerToMysteryGift -DeleteStaticPointerToMysteryGift: ; 0x0202E054 - ldr r0, _0202E064 ; =sMysteryGiftData - ldr r1, [r0] - cmp r1, #0 - beq _0202E060 - mov r1, #0 - str r1, [r0] -_0202E060: - bx lr - nop -_0202E064: .word sMysteryGiftData - thumb_func_end DeleteStaticPointerToMysteryGift - - thumb_func_start GetFirstQueuedMysteryGiftIdx -GetFirstQueuedMysteryGiftIdx: ; 0x0202E068 - push {r3, r4, r5, lr} - ldr r4, _0202E08C ; =sMysteryGiftData - mov r5, #0 -_0202E06E: - ldr r0, [r4] - add r1, r5, #0 - bl SaveMysteryGiftI_TagIsValid - cmp r0, #1 - bne _0202E07E - add r0, r5, #0 - pop {r3, r4, r5, pc} -_0202E07E: - add r5, r5, #1 - cmp r5, #8 - blt _0202E06E - mov r0, #0 - mvn r0, r0 - pop {r3, r4, r5, pc} - nop -_0202E08C: .word sMysteryGiftData - thumb_func_end GetFirstQueuedMysteryGiftIdx - - thumb_func_start GetMysteryGiftTagByIdx -GetMysteryGiftTagByIdx: ; 0x0202E090 - push {r3, lr} - add r1, r0, #0 - ldr r0, _0202E0A8 ; =sMysteryGiftData - ldr r0, [r0] - bl SaveMysteryGift_GetByIdx - cmp r0, #0 - beq _0202E0A4 - ldrh r0, [r0] - pop {r3, pc} -_0202E0A4: - mov r0, #0 - pop {r3, pc} - .balign 4, 0 -_0202E0A8: .word sMysteryGiftData - thumb_func_end GetMysteryGiftTagByIdx - - thumb_func_start GetMysteryGiftDataByIdx -GetMysteryGiftDataByIdx: ; 0x0202E0AC - push {r3, lr} - add r1, r0, #0 - ldr r0, _0202E0C4 ; =sMysteryGiftData - ldr r0, [r0] - bl SaveMysteryGift_GetByIdx - cmp r0, #0 - beq _0202E0C0 - add r0, r0, #4 - pop {r3, pc} -_0202E0C0: - mov r0, #0 - pop {r3, pc} - .balign 4, 0 -_0202E0C4: .word sMysteryGiftData - thumb_func_end GetMysteryGiftDataByIdx - - thumb_func_start SetMysteryGiftReceivedByIdx -SetMysteryGiftReceivedByIdx: ; 0x0202E0C8 - add r1, r0, #0 - ldr r0, _0202E0D4 ; =sMysteryGiftData - ldr r3, _0202E0D8 ; =SaveMysteryGiftI_SetReceived - ldr r0, [r0] - bx r3 - nop -_0202E0D4: .word sMysteryGiftData -_0202E0D8: .word SaveMysteryGiftI_SetReceived - thumb_func_end SetMysteryGiftReceivedByIdx diff --git a/include/mystery_gift.h b/include/mystery_gift.h index 43d9780f9e..acf3bc4283 100644 --- a/include/mystery_gift.h +++ b/include/mystery_gift.h @@ -37,30 +37,49 @@ typedef struct MG_MON_DECO_TAG { int id; } MG_MON_DECO_TAG; +typedef union { + MG_POKEMON_TAG pokemon; + Pokemon egg; + u32 item; + u16 ruleset[24]; + int base_decoration; + MG_MON_DECO_TAG mon_decoration; + u8 pokewalkerCourse; + PHOTO photo; + u8 raw[256]; +} MysteryGiftTag; + +typedef struct { + u16 name[36]; + u32 version; // 88 + u16 id; // 8C + u8 unique:1; // 8E + u8 unk8E_1:1; + u8 unk8E_2:1; + u8 unk8E_3:1; + u8 unk8E_4:1; + u8 unk8E_5:1; + u8 unk8E_6:2; +} UnkWonderCardSubstruct_104; + typedef struct { u16 tag; u16 flag : 2; u16 dummy : 14; - union { - MG_POKEMON_TAG pokemon; - Pokemon egg; - u32 item; - u16 ruleset[24]; - int base_decoration; - MG_MON_DECO_TAG mon_decoration; - u8 pokewalkerCourse; - PHOTO photo; - u8 raw[256]; - }; + MysteryGiftTag data; } MysteryGift; typedef struct { u16 tag; u16 flag; - union { - u8 raw[852]; - }; -} WonderCard; + MysteryGiftTag data; + UnkWonderCardSubstruct_104 unk104; + u16 text[250]; + u8 shareMax; + u16 monIcon[3]; + u8 shareCount; + s32 receiveDate; +} WonderCard; // size: 0x358 typedef struct { u8 filler_000[0x100]; // 0000 @@ -74,5 +93,25 @@ 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 sub_0202DC2C(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag); +BOOL sub_0202DCAC(MYSTERY_GIFT_SAVE* mg, const WonderCard* src); +BOOL sub_0202DD48(MYSTERY_GIFT_SAVE* mg, const WonderCard* src); +BOOL sub_0202DDB0(MYSTERY_GIFT_SAVE* mg, int index); +BOOL sub_0202DDEC(MYSTERY_GIFT_SAVE* mg, int index); +BOOL SaveMysteryGift_CardFindAvailable(MYSTERY_GIFT_SAVE* mg); +BOOL sub_0202DE90(MYSTERY_GIFT_SAVE* mg, int index); +BOOL sub_0202DEBC(MYSTERY_GIFT_SAVE* mg); +BOOL sub_0202DED8(MYSTERY_GIFT_SAVE* mg); +BOOL sub_0202DEF8(MYSTERY_GIFT_SAVE* mg, int a1); +BOOL sub_0202DF7C(MYSTERY_GIFT_SAVE* mg, int a1); +void sub_0202DFAC(MYSTERY_GIFT_SAVE* mg, int a1); +BOOL sub_0202E014(MYSTERY_GIFT_SAVE* mg); +void sub_0202E024(MYSTERY_GIFT_SAVE* mg); +void GetStaticPointerToSaveMysteryGift(SaveData* saveData); +void DeleteStaticPointerToMysteryGift(void); +int GetFirstQueuedMysteryGiftIdx(void); +u16 GetMysteryGiftTagByIdx(int index); +MysteryGiftTag* GetMysteryGiftDataByIdx(int index); +MysteryGiftTag* GetMysteryGiftDataByIdx(int index); +void SetMysteryGiftReceivedByIdx(int index); #endif //POKEHEARTGOLD_MYSTERY_GIFT_H diff --git a/main.lsf b/main.lsf index 8edd947df4..37b82645bc 100644 --- a/main.lsf +++ b/main.lsf @@ -121,7 +121,6 @@ Static main Object src/roamer.o Object asm/unk_0202DB34.o Object src/mystery_gift.o - Object asm/unk_0202DBA8.o Object src/hall_of_fame.o Object asm/unk_0202E41C.o Object asm/unk_0202E4B0.o diff --git a/src/mystery_gift.c b/src/mystery_gift.c index 95280733d3..b2bcfd58b3 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -1,12 +1,16 @@ #include "global.h" #include "mystery_gift.h" #include "save.h" +#include "save_arrays.h" #include "constants/save_arrays.h" -extern MYSTERY_GIFT_SAVE* sMysteryGiftData; - BOOL MysteryGiftTagIsValid(u32 tag); MysteryGift* SaveMysteryGift_GetByIdx(MYSTERY_GIFT_SAVE* mg, int index); +BOOL SaveMysteryGiftI_SetReceived(MYSTERY_GIFT_SAVE* mg, int index); +void sub_0202DFDC(MYSTERY_GIFT_SAVE* mg, int index); +void sub_0202DF38(MYSTERY_GIFT_SAVE* mg, int index); +BOOL SaveMysteryGiftI_TagIsValid(MYSTERY_GIFT_SAVE* mg, int index); +void sub_0202DFDC(MYSTERY_GIFT_SAVE* mg, int a1); u32 Save_MysteryGift_sizeof(void) { return sizeof(MYSTERY_GIFT_SAVE); @@ -64,3 +68,226 @@ BOOL sub_0202DC2C(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag) { SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); return ret; } + +BOOL sub_0202DCAC(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) { + BOOL ret = FALSE; + int i; + + if (!SaveMysteryGift_CardFindAvailable(mg)) { + return FALSE; + } + + if (src->unk104.unk8E_3 == 1 && !SaveMysteryGift_FindAvailable(mg)) { + return FALSE; + } + + for (i = 0; i < NUM_SAVED_WONDER_CARDS; ++i) { + if (!MysteryGiftTagIsValid(mg->cards[i].tag)) { + MI_CpuCopy8(src, &mg->cards[i], sizeof(WonderCard)); + if (src->unk104.unk8E_3 == 1) { + sub_0202DC2C(mg, (const MysteryGift*)src, i); + } + ret = TRUE; + break; + } + } + + SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); + return ret; +} + +BOOL sub_0202DD48(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) { + if (MysteryGiftTagIsValid(mg->receivedCard.tag) == TRUE) { + return FALSE; + } + + MI_CpuCopy8(src, &mg->receivedCard, sizeof(WonderCard)); + SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); + return FALSE; +} + +BOOL SaveMysteryGiftI_SetReceived(MYSTERY_GIFT_SAVE* mg, int index) { + GF_ASSERT(index < NUM_SAVED_MYSTERY_GIFTS); + mg->gifts[index].tag = MG_TAG_invalid; + mg->gifts[index].flag = 0; + SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); + return TRUE; +} + +BOOL sub_0202DDB0(MYSTERY_GIFT_SAVE* mg, int index) { + GF_ASSERT(index < NUM_SAVED_WONDER_CARDS); + mg->cards[index].tag = MG_TAG_invalid; + sub_0202DFDC(mg, mg->cards[index].unk104.id); + sub_0202DF38(mg, index); + SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); + return TRUE; +} + +BOOL sub_0202DDEC(MYSTERY_GIFT_SAVE* 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) { + int i; + + for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) { + if (!MysteryGiftTagIsValid(mg->gifts[i].tag)) { + return TRUE; + } + } + + return FALSE; +} + +BOOL SaveMysteryGift_CardFindAvailable(MYSTERY_GIFT_SAVE* mg) { + int i; + + for (i = 0; i < NUM_SAVED_WONDER_CARDS; ++i) { + if (!MysteryGiftTagIsValid(mg->cards[i].tag)) { + return TRUE; + } + } + + return FALSE; +} + +BOOL SaveMysteryGiftI_TagIsValid(MYSTERY_GIFT_SAVE* mg, int index) { + GF_ASSERT(index < NUM_SAVED_MYSTERY_GIFTS); + + if (MysteryGiftTagIsValid(mg->gifts[index].tag)) { + return TRUE; + } else { + return FALSE; + } +} + +BOOL sub_0202DE90(MYSTERY_GIFT_SAVE* mg, int index) { + GF_ASSERT(index < NUM_SAVED_WONDER_CARDS); + + if (MysteryGiftTagIsValid(mg->cards[index].tag)) { + return TRUE; + } else { + return FALSE; + } +} + +BOOL sub_0202DEBC(MYSTERY_GIFT_SAVE* mg) { + if (MysteryGiftTagIsValid(mg->receivedCard.tag)) { + return TRUE; + } else { + return FALSE; + } +} + +BOOL sub_0202DED8(MYSTERY_GIFT_SAVE* mg) { + int i; + + for (i = 0; i < NUM_SAVED_WONDER_CARDS; ++i) { + if (sub_0202DE90(mg, i) == TRUE) { + return TRUE; + } + } + + return FALSE; +} + +BOOL sub_0202DEF8(MYSTERY_GIFT_SAVE* 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) { + return TRUE; + } + } + + return FALSE; +} + +void sub_0202DF38(MYSTERY_GIFT_SAVE* 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); + break; + } + } +} + +BOOL sub_0202DF7C(MYSTERY_GIFT_SAVE* mg, int a1) { + GF_ASSERT(a1 < 2048); + return mg->filler_000[a1 / 8] & (1 << (a1 & 7)) ? TRUE : FALSE; +} + +void sub_0202DFAC(MYSTERY_GIFT_SAVE* mg, int a1) { + GF_ASSERT(a1 < 2048); + mg->filler_000[a1 / 8] |= (1 << (a1 & 7)); + SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); +} + +void sub_0202DFDC(MYSTERY_GIFT_SAVE* mg, int a1) { + u8 mask = ~(1 << (a1 & 7)); + GF_ASSERT(a1 < 2048); + mg->filler_000[a1 / 8] &= mask; + SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); +} + +BOOL sub_0202E014(MYSTERY_GIFT_SAVE* mg) { + return sub_0202DF7C(mg, 0x7FF); +} + +void sub_0202E024(MYSTERY_GIFT_SAVE* mg) { + sub_0202DFAC(mg, 0x7FF); +} + +static MYSTERY_GIFT_SAVE* sMysteryGiftData; + +void GetStaticPointerToSaveMysteryGift(SaveData* saveData) { + if (sMysteryGiftData == NULL) { + sMysteryGiftData = Save_MysteryGift_Get(saveData); + } + SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); +} + +void DeleteStaticPointerToMysteryGift(void) { + if (sMysteryGiftData != NULL) { + sMysteryGiftData = NULL; + } +} + +int GetFirstQueuedMysteryGiftIdx(void) { + int i; + + for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) { + if (SaveMysteryGiftI_TagIsValid(sMysteryGiftData, i) == TRUE) { + return i; + } + } + + return -1; +} + +u16 GetMysteryGiftTagByIdx(int index) { + MysteryGift* gift = SaveMysteryGift_GetByIdx(sMysteryGiftData, index); + if (gift != NULL) { + return gift->tag; + } + + return MG_TAG_invalid; +} + +MysteryGiftTag* GetMysteryGiftDataByIdx(int index) { + MysteryGift* gift = SaveMysteryGift_GetByIdx(sMysteryGiftData, index); + if (gift != NULL) { + return &gift->data; + } + + return NULL; +} + +void SetMysteryGiftReceivedByIdx(int index) { + SaveMysteryGiftI_SetReceived(sMysteryGiftData, index); +} From 2ffd8f2a1b94df36d12a6248b6b0b084d413f9e2 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 6 Dec 2023 20:19:46 -0500 Subject: [PATCH 3/7] Rename mystery_gift.c functions --- asm/include/overlay_74_thumb.inc | 26 +++++++-------- asm/include/unk_0202DBA8.inc | 26 +++++++-------- asm/overlay_74_thumb.s | 36 ++++++++++---------- include/mystery_gift.h | 28 ++++++++-------- src/mystery_gift.c | 56 ++++++++++++++++---------------- 5 files changed, 86 insertions(+), 86 deletions(-) diff --git a/asm/include/overlay_74_thumb.inc b/asm/include/overlay_74_thumb.inc index bc1ef2b770..dcd1748ca3 100644 --- a/asm/include/overlay_74_thumb.inc +++ b/asm/include/overlay_74_thumb.inc @@ -213,21 +213,21 @@ .public GetIGTMinutes .public Save_MysteryGift_Init .public SaveMysteryGift_CardGetByIdx -.public sub_0202DC2C -.public sub_0202DCAC -.public sub_0202DD48 -.public sub_0202DDB0 -.public sub_0202DDEC +.public SaveMysteryGift_TryInsertGift +.public SaveMysteryGift_TryInsertCard +.public SaveMysteryGift_TrySetSpecialCard +.public SaveMysteryGift_ReceiveGiftAndClearCardByIndex +.public SaveMysteryGift_DeleteWonderCardByIndex .public SaveMysteryGift_FindAvailable .public SaveMysteryGift_CardFindAvailable -.public sub_0202DE90 -.public sub_0202DEBC -.public sub_0202DED8 -.public sub_0202DEF8 -.public sub_0202DF7C -.public sub_0202DFAC -.public sub_0202E014 -.public sub_0202E024 +.public SaveMysteryGift_CardTagIsValid +.public SaveMysteryGift_SpecialCardTagIsValid +.public SaveMysteryGift_HasAnyCard +.public SaveMysteryGift_HasAnyGift +.public SaveMysteryGift_ReceivedFlagTest +.public SaveMysteryGift_ReceivedFlagSet +.public SaveMysteryGift_TestFlagx7FF +.public SaveMysteryGift_SetFlagx7FF .public sub_0202EC14 .public sub_0202EC28 .public sub_0202EC98 diff --git a/asm/include/unk_0202DBA8.inc b/asm/include/unk_0202DBA8.inc index 8ad339c81d..7381052f96 100644 --- a/asm/include/unk_0202DBA8.inc +++ b/asm/include/unk_0202DBA8.inc @@ -6,21 +6,21 @@ .public Save_MysteryGift_sizeof .public Save_MysteryGift_Init .public SaveMysteryGift_CardGetByIdx -.public sub_0202DC2C -.public sub_0202DCAC -.public sub_0202DD48 -.public sub_0202DDB0 -.public sub_0202DDEC +.public SaveMysteryGift_TryInsertGift +.public SaveMysteryGift_TryInsertCard +.public SaveMysteryGift_TrySetSpecialCard +.public SaveMysteryGift_ReceiveGiftAndClearCardByIndex +.public SaveMysteryGift_DeleteWonderCardByIndex .public SaveMysteryGift_FindAvailable .public SaveMysteryGift_CardFindAvailable -.public sub_0202DE90 -.public sub_0202DEBC -.public sub_0202DED8 -.public sub_0202DEF8 -.public sub_0202DF7C -.public sub_0202DFAC -.public sub_0202E014 -.public sub_0202E024 +.public SaveMysteryGift_CardTagIsValid +.public SaveMysteryGift_SpecialCardTagIsValid +.public SaveMysteryGift_HasAnyCard +.public SaveMysteryGift_HasAnyGift +.public SaveMysteryGift_ReceivedFlagTest +.public SaveMysteryGift_ReceivedFlagSet +.public SaveMysteryGift_TestFlagx7FF +.public SaveMysteryGift_SetFlagx7FF .public GetStaticPointerToSaveMysteryGift .public DeleteStaticPointerToMysteryGift .public GetFirstQueuedMysteryGiftIdx diff --git a/asm/overlay_74_thumb.s b/asm/overlay_74_thumb.s index 3c2a4d51ec..a7cff2f589 100644 --- a/asm/overlay_74_thumb.s +++ b/asm/overlay_74_thumb.s @@ -892,7 +892,7 @@ _022276D8: mov r0, #0 str r0, [r4, #0x40] ldr r0, [r4, #0x14] - bl sub_0202E014 + bl SaveMysteryGift_TestFlagx7FF cmp r0, #1 bne _0222779A ldr r1, [r4, #0x40] @@ -2120,7 +2120,7 @@ ov74_MainMenu_PrintMysteryGiftButton: ; 0x022280B4 cmp r0, #0 bne _022280FC ldr r0, [r5, #0x14] - bl sub_0202E014 + bl SaveMysteryGift_TestFlagx7FF cmp r0, #1 bne _022280D4 mov r0, #1 @@ -2179,7 +2179,7 @@ _0222810C: orr r0, r1 str r0, [r5, #0x38] ldr r0, [r5, #0x14] - bl sub_0202E024 + bl SaveMysteryGift_SetFlagx7FF add sp, #8 mov r0, #1 pop {r3, r4, r5, r6, r7, pc} @@ -4656,7 +4656,7 @@ ov74_0222947C: ; 0x0222947C add r1, r4, #0 ldr r0, [r5, r0] mov r2, #3 - bl sub_0202DC2C + bl SaveMysteryGift_TryInsertGift mov r0, #1 mov r1, #0 bl GfGfx_EngineBTogglePlanes @@ -6258,7 +6258,7 @@ _0222A1CE: add r1, #0x4c ldrh r1, [r1] add r7, r0, #0 - bl sub_0202DFAC + bl SaveMysteryGift_ReceivedFlagSet add r4, #0x4e ldrb r0, [r4] lsl r0, r0, #0x1d @@ -6274,7 +6274,7 @@ _0222A1CE: bne _0222A204 add r0, r7, #0 add r1, r5, #0 - bl sub_0202DD48 + bl SaveMysteryGift_TrySetSpecialCard b _0222A21C _0222A204: cmp r6, #0 @@ -6282,12 +6282,12 @@ _0222A204: add r0, r7, #0 add r1, r5, #0 mov r2, #3 - bl sub_0202DC2C + bl SaveMysteryGift_TryInsertGift b _0222A21C _0222A214: add r0, r7, #0 add r1, r5, #0 - bl sub_0202DCAC + bl SaveMysteryGift_TryInsertCard _0222A21C: ldr r0, [sp] bl ov74_022360A0 @@ -7229,7 +7229,7 @@ ov74_0222A94C: ; 0x0222A94C add r5, r5, #1 str r2, [sp, #0x24] str r1, [sp, #0x28] - bl sub_0202DED8 + bl SaveMysteryGift_HasAnyCard cmp r0, #0 beq _0222A992 lsl r6, r5, #3 @@ -7244,7 +7244,7 @@ ov74_0222A94C: ; 0x0222A94C str r2, [r1, #4] _0222A992: ldr r0, [sp, #0x18] - bl sub_0202DEBC + bl SaveMysteryGift_SpecialCardTagIsValid cmp r0, #0 beq _0222A9B0 lsl r6, r5, #3 @@ -12330,7 +12330,7 @@ ov74_0222D308: ; 0x0222D308 ldr r0, [r4, r1] add r1, #0x20 ldr r1, [r4, r1] - bl sub_0202DEF8 + bl SaveMysteryGift_HasAnyGift cmp r0, #1 ldr r0, _0222D350 ; =0x00002BD0 bne _0222D330 @@ -12378,20 +12378,20 @@ ov74_0222D358: ; 0x0222D358 ldr r0, [r4, r1] add r1, #0x20 ldr r1, [r4, r1] - bl sub_0202DEF8 + bl SaveMysteryGift_HasAnyGift cmp r0, #1 ldr r1, _0222D408 ; =0x00002BA0 bne _0222D39A ldr r0, [r4, r1] add r1, #0x20 ldr r1, [r4, r1] - bl sub_0202DDB0 + bl SaveMysteryGift_ReceiveGiftAndClearCardByIndex b _0222D3A4 _0222D39A: ldr r0, [r4, r1] add r1, #0x20 ldr r1, [r4, r1] - bl sub_0202DDEC + bl SaveMysteryGift_DeleteWonderCardByIndex _0222D3A4: ldr r0, _0222D40C ; =0x00002BA4 ldr r0, [r4, r0] @@ -12401,7 +12401,7 @@ _0222D3A4: bl sub_0200F450 ldr r0, _0222D408 ; =0x00002BA0 ldr r0, [r4, r0] - bl sub_0202DED8 + bl SaveMysteryGift_HasAnyCard cmp r0, #0 bne _0222D3C4 mov r0, #0x1b @@ -12571,7 +12571,7 @@ _0222D50C: ldr r0, [r4, r0] cmp r0, #0 beq _0222D51C - bl sub_0202DEF8 + bl SaveMysteryGift_HasAnyGift cmp r0, #1 bne _0222D520 _0222D51C: @@ -13346,7 +13346,7 @@ _0222DB14: ldr r0, _0222DB2C ; =0x00002BA0 add r1, r4, #0 ldr r0, [r5, r0] - bl sub_0202DE90 + bl SaveMysteryGift_CardTagIsValid cmp r0, #0 beq _0222DB02 _0222DB26: @@ -17618,7 +17618,7 @@ _0222FDF2: cmp r0, #1 bne _0222FE0E add r0, r6, #0 - bl sub_0202DF7C + bl SaveMysteryGift_ReceivedFlagTest cmp r0, #1 bne _0222FE0E mov r0, #2 diff --git a/include/mystery_gift.h b/include/mystery_gift.h index acf3bc4283..b807cd1a67 100644 --- a/include/mystery_gift.h +++ b/include/mystery_gift.h @@ -85,27 +85,27 @@ typedef struct { u8 filler_000[0x100]; // 0000 MysteryGift gifts[NUM_SAVED_MYSTERY_GIFTS]; // 0100 WonderCard cards[NUM_SAVED_WONDER_CARDS]; // 920 - WonderCard receivedCard; // 1328 + WonderCard specialWonderCard; // 1328 } MYSTERY_GIFT_SAVE; // size = 0x1680 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 sub_0202DC2C(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag); -BOOL sub_0202DCAC(MYSTERY_GIFT_SAVE* mg, const WonderCard* src); -BOOL sub_0202DD48(MYSTERY_GIFT_SAVE* mg, const WonderCard* src); -BOOL sub_0202DDB0(MYSTERY_GIFT_SAVE* mg, int index); -BOOL sub_0202DDEC(MYSTERY_GIFT_SAVE* mg, int index); +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 sub_0202DE90(MYSTERY_GIFT_SAVE* mg, int index); -BOOL sub_0202DEBC(MYSTERY_GIFT_SAVE* mg); -BOOL sub_0202DED8(MYSTERY_GIFT_SAVE* mg); -BOOL sub_0202DEF8(MYSTERY_GIFT_SAVE* mg, int a1); -BOOL sub_0202DF7C(MYSTERY_GIFT_SAVE* mg, int a1); -void sub_0202DFAC(MYSTERY_GIFT_SAVE* mg, int a1); -BOOL sub_0202E014(MYSTERY_GIFT_SAVE* mg); -void sub_0202E024(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 GetStaticPointerToSaveMysteryGift(SaveData* saveData); void DeleteStaticPointerToMysteryGift(void); int GetFirstQueuedMysteryGiftIdx(void); diff --git a/src/mystery_gift.c b/src/mystery_gift.c index b2bcfd58b3..40da59edb9 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -7,10 +7,10 @@ BOOL MysteryGiftTagIsValid(u32 tag); MysteryGift* SaveMysteryGift_GetByIdx(MYSTERY_GIFT_SAVE* mg, int index); BOOL SaveMysteryGiftI_SetReceived(MYSTERY_GIFT_SAVE* mg, int index); -void sub_0202DFDC(MYSTERY_GIFT_SAVE* mg, int index); -void sub_0202DF38(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 sub_0202DFDC(MYSTERY_GIFT_SAVE* mg, int a1); +void SaveMysteryGift_ReceivedFlagClear(MYSTERY_GIFT_SAVE* mg, int a1); u32 Save_MysteryGift_sizeof(void) { return sizeof(MYSTERY_GIFT_SAVE); @@ -42,13 +42,13 @@ WonderCard* SaveMysteryGift_CardGetByIdx(MYSTERY_GIFT_SAVE* mg, int index) { return ret; } } else if (index == RECEIVED_WONDER_CARD_IDX) { - return &mg->receivedCard; + return &mg->specialWonderCard; } return NULL; } -BOOL sub_0202DC2C(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag) { +BOOL SaveMysteryGift_TryInsertGift(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag) { BOOL ret = FALSE; int i; @@ -69,7 +69,7 @@ BOOL sub_0202DC2C(MYSTERY_GIFT_SAVE* mg, const MysteryGift* src, int flag) { return ret; } -BOOL sub_0202DCAC(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) { +BOOL SaveMysteryGift_TryInsertCard(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) { BOOL ret = FALSE; int i; @@ -85,7 +85,7 @@ BOOL sub_0202DCAC(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) { if (!MysteryGiftTagIsValid(mg->cards[i].tag)) { MI_CpuCopy8(src, &mg->cards[i], sizeof(WonderCard)); if (src->unk104.unk8E_3 == 1) { - sub_0202DC2C(mg, (const MysteryGift*)src, i); + SaveMysteryGift_TryInsertGift(mg, (const MysteryGift*)src, i); } ret = TRUE; break; @@ -96,12 +96,12 @@ BOOL sub_0202DCAC(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) { return ret; } -BOOL sub_0202DD48(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) { - if (MysteryGiftTagIsValid(mg->receivedCard.tag) == TRUE) { +BOOL SaveMysteryGift_TrySetSpecialCard(MYSTERY_GIFT_SAVE* mg, const WonderCard* src) { + if (MysteryGiftTagIsValid(mg->specialWonderCard.tag) == TRUE) { return FALSE; } - MI_CpuCopy8(src, &mg->receivedCard, sizeof(WonderCard)); + MI_CpuCopy8(src, &mg->specialWonderCard, sizeof(WonderCard)); SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); return FALSE; } @@ -114,16 +114,16 @@ BOOL SaveMysteryGiftI_SetReceived(MYSTERY_GIFT_SAVE* mg, int index) { return TRUE; } -BOOL sub_0202DDB0(MYSTERY_GIFT_SAVE* mg, int index) { +BOOL SaveMysteryGift_ReceiveGiftAndClearCardByIndex(MYSTERY_GIFT_SAVE* mg, int index) { GF_ASSERT(index < NUM_SAVED_WONDER_CARDS); mg->cards[index].tag = MG_TAG_invalid; - sub_0202DFDC(mg, mg->cards[index].unk104.id); - sub_0202DF38(mg, index); + SaveMysteryGift_ReceivedFlagClear(mg, mg->cards[index].unk104.id); + SaveMysteryGift_SetReceivedByCardId(mg, index); SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); return TRUE; } -BOOL sub_0202DDEC(MYSTERY_GIFT_SAVE* mg, int index) { +BOOL SaveMysteryGift_DeleteWonderCardByIndex(MYSTERY_GIFT_SAVE* mg, int index) { GF_ASSERT(index < NUM_SAVED_WONDER_CARDS); mg->cards[index].tag = MG_TAG_invalid; SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); @@ -164,7 +164,7 @@ BOOL SaveMysteryGiftI_TagIsValid(MYSTERY_GIFT_SAVE* mg, int index) { } } -BOOL sub_0202DE90(MYSTERY_GIFT_SAVE* mg, int index) { +BOOL SaveMysteryGift_CardTagIsValid(MYSTERY_GIFT_SAVE* mg, int index) { GF_ASSERT(index < NUM_SAVED_WONDER_CARDS); if (MysteryGiftTagIsValid(mg->cards[index].tag)) { @@ -174,19 +174,19 @@ BOOL sub_0202DE90(MYSTERY_GIFT_SAVE* mg, int index) { } } -BOOL sub_0202DEBC(MYSTERY_GIFT_SAVE* mg) { - if (MysteryGiftTagIsValid(mg->receivedCard.tag)) { +BOOL SaveMysteryGift_SpecialCardTagIsValid(MYSTERY_GIFT_SAVE* mg) { + if (MysteryGiftTagIsValid(mg->specialWonderCard.tag)) { return TRUE; } else { return FALSE; } } -BOOL sub_0202DED8(MYSTERY_GIFT_SAVE* mg) { +BOOL SaveMysteryGift_HasAnyCard(MYSTERY_GIFT_SAVE* mg) { int i; for (i = 0; i < NUM_SAVED_WONDER_CARDS; ++i) { - if (sub_0202DE90(mg, i) == TRUE) { + if (SaveMysteryGift_CardTagIsValid(mg, i) == TRUE) { return TRUE; } } @@ -194,7 +194,7 @@ BOOL sub_0202DED8(MYSTERY_GIFT_SAVE* mg) { return FALSE; } -BOOL sub_0202DEF8(MYSTERY_GIFT_SAVE* mg, int a1) { +BOOL SaveMysteryGift_HasAnyGift(MYSTERY_GIFT_SAVE* mg, int a1) { int i; for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) { @@ -206,7 +206,7 @@ BOOL sub_0202DEF8(MYSTERY_GIFT_SAVE* mg, int a1) { return FALSE; } -void sub_0202DF38(MYSTERY_GIFT_SAVE* mg, int a1) { +void SaveMysteryGift_SetReceivedByCardId(MYSTERY_GIFT_SAVE* mg, int a1) { int i; for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) { @@ -217,30 +217,30 @@ void sub_0202DF38(MYSTERY_GIFT_SAVE* mg, int a1) { } } -BOOL sub_0202DF7C(MYSTERY_GIFT_SAVE* mg, int a1) { +BOOL SaveMysteryGift_ReceivedFlagTest(MYSTERY_GIFT_SAVE* mg, int a1) { GF_ASSERT(a1 < 2048); return mg->filler_000[a1 / 8] & (1 << (a1 & 7)) ? TRUE : FALSE; } -void sub_0202DFAC(MYSTERY_GIFT_SAVE* mg, int a1) { +void SaveMysteryGift_ReceivedFlagSet(MYSTERY_GIFT_SAVE* mg, int a1) { GF_ASSERT(a1 < 2048); mg->filler_000[a1 / 8] |= (1 << (a1 & 7)); SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); } -void sub_0202DFDC(MYSTERY_GIFT_SAVE* mg, int a1) { +void SaveMysteryGift_ReceivedFlagClear(MYSTERY_GIFT_SAVE* mg, int a1) { u8 mask = ~(1 << (a1 & 7)); GF_ASSERT(a1 < 2048); mg->filler_000[a1 / 8] &= mask; SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); } -BOOL sub_0202E014(MYSTERY_GIFT_SAVE* mg) { - return sub_0202DF7C(mg, 0x7FF); +BOOL SaveMysteryGift_TestFlagx7FF(MYSTERY_GIFT_SAVE* mg) { + return SaveMysteryGift_ReceivedFlagTest(mg, 0x7FF); } -void sub_0202E024(MYSTERY_GIFT_SAVE* mg) { - sub_0202DFAC(mg, 0x7FF); +void SaveMysteryGift_SetFlagx7FF(MYSTERY_GIFT_SAVE* mg) { + SaveMysteryGift_ReceivedFlagSet(mg, 0x7FF); } static MYSTERY_GIFT_SAVE* sMysteryGiftData; From ac98817004994f2e5ae6915b7ad7804933020309 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 6 Dec 2023 21:08:07 -0500 Subject: [PATCH 4/7] Update fn names; document public routines --- include/mystery_gift.h | 127 ++++++++++++++++++++++++++++++++--------- include/save_arrays.h | 2 +- src/mystery_gift.c | 84 +++++++++++++-------------- src/save_arrays.c | 2 +- 4 files changed, 144 insertions(+), 71 deletions(-) diff --git a/include/mystery_gift.h b/include/mystery_gift.h index b807cd1a67..9b2c2610f5 100644 --- a/include/mystery_gift.h +++ b/include/mystery_gift.h @@ -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 diff --git a/include/save_arrays.h b/include/save_arrays.h index 49bdc4d48f..2ba9cfb87b 100644 --- a/include/save_arrays.h +++ b/include/save_arrays.h @@ -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); diff --git a/src/mystery_gift.c b/src/mystery_gift.c index 40da59edb9..a6508d6c72 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -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); } diff --git a/src/save_arrays.c b/src/save_arrays.c index 498a568a9d..01c6969040 100644 --- a/src/save_arrays.c +++ b/src/save_arrays.c @@ -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); } From 6bd2b0a7dfdb371d7e41c9d703e8070163e31b0a Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 6 Dec 2023 22:45:59 -0500 Subject: [PATCH 5/7] capitalize MG_TAG_* defines --- include/mystery_gift.h | 34 +++++++++++++++++----------------- src/mystery_gift.c | 10 +++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/include/mystery_gift.h b/include/mystery_gift.h index 9b2c2610f5..9c8308ce02 100644 --- a/include/mystery_gift.h +++ b/include/mystery_gift.h @@ -4,23 +4,23 @@ #include "pokemon_types_def.h" #include "photo_album.h" -#define MG_TAG_invalid 0 -#define MG_TAG_pokemon 1 -#define MG_TAG_egg 2 -#define MG_TAG_item 3 -#define MG_TAG_battle_rules 4 -#define MG_TAG_secret_base_deco 5 // disabled in hgss -#define MG_TAG_mon_deco 6 -#define MG_TAG_manaphy_egg 7 -#define MG_TAG_member_card 8 // disabled in hgss -#define MG_TAG_oaks_letter 9 // disabled in hgss -#define MG_TAG_azure_flute 10 // disabled in hgss -#define MG_TAG_poketch_app 11 // disabled in hgss -#define MG_TAG_secret_key 12 // disabled in hgss -#define MG_TAG_pokemon_movie 13 -#define MG_TAG_pokewalker_course 14 -#define MG_TAG_memorial_photo 15 -#define MG_TAG_max 16 +#define MG_TAG_INVALID 0 +#define MG_TAG_POKEMON 1 +#define MG_TAG_EGG 2 +#define MG_TAG_ITEM 3 +#define MG_TAG_BATTLE_RULES 4 +#define MG_TAG_SECRET_BASE_DECO 5 // disabled in hgss +#define MG_TAG_MON_DECO 6 +#define MG_TAG_MANAPHY_EGG 7 +#define MG_TAG_MEMBER_CARD 8 // disabled in hgss +#define MG_TAG_OAKS_LETTER 9 // disabled in hgss +#define MG_TAG_AZURE_FLUTE 10 // disabled in hgss +#define MG_TAG_POKETCH_APP 11 // disabled in hgss +#define MG_TAG_SECRET_KEY 12 // disabled in hgss +#define MG_TAG_POKEMON_MOVIE 13 +#define MG_TAG_POKEWALKER_COURSE 14 +#define MG_TAG_MEMORIAL_PHOTO 15 +#define MG_TAG_MAX 16 #define NUM_SAVED_MYSTERY_GIFTS 8 #define NUM_SAVED_WONDER_CARDS 3 diff --git a/src/mystery_gift.c b/src/mystery_gift.c index a6508d6c72..619753b7ba 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -21,7 +21,7 @@ void Save_MysteryGift_Init(MysteryGiftSave* mg) { } BOOL MysteryGiftTagIsValid(u32 tag) { - return tag != MG_TAG_invalid && tag < MG_TAG_max; + return tag != MG_TAG_INVALID && tag < MG_TAG_MAX; } MysteryGift* SaveMysteryGift_GetByIdx(MysteryGiftSave* mg, int index) { @@ -108,7 +108,7 @@ BOOL SaveMysteryGift_TrySetSpecialCard(MysteryGiftSave* mg, const WonderCard* sr BOOL SaveMysteryGift_SetReceivedByIdx(MysteryGiftSave* mg, int index) { GF_ASSERT(index < NUM_SAVED_MYSTERY_GIFTS); - mg->gifts[index].tag = MG_TAG_invalid; + mg->gifts[index].tag = MG_TAG_INVALID; mg->gifts[index].flag = 0; SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); return TRUE; @@ -116,7 +116,7 @@ BOOL SaveMysteryGift_SetReceivedByIdx(MysteryGiftSave* mg, int index) { BOOL SaveMysteryGift_ReceiveGiftAndClearCardByIndex(MysteryGiftSave* mg, int index) { GF_ASSERT(index < NUM_SAVED_WONDER_CARDS); - mg->cards[index].tag = MG_TAG_invalid; + mg->cards[index].tag = MG_TAG_INVALID; SaveMysteryGift_ReceivedFlagClear(mg, mg->cards[index].unk104.id); SaveMysteryGift_SetReceivedByCardId(mg, index); SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); @@ -125,7 +125,7 @@ BOOL SaveMysteryGift_ReceiveGiftAndClearCardByIndex(MysteryGiftSave* mg, int ind BOOL SaveMysteryGift_DeleteWonderCardByIndex(MysteryGiftSave* mg, int index) { GF_ASSERT(index < NUM_SAVED_WONDER_CARDS); - mg->cards[index].tag = MG_TAG_invalid; + mg->cards[index].tag = MG_TAG_INVALID; SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); return TRUE; } @@ -276,7 +276,7 @@ u16 GetMysteryGiftTagByIdx(int index) { return gift->tag; } - return MG_TAG_invalid; + return MG_TAG_INVALID; } MysteryGiftData* GetMysteryGiftDataByIdx(int index) { From 4c6aa458b06a5f7a49be90e9eb3032f2eefedfd9 Mon Sep 17 00:00:00 2001 From: pikalaxalt Date: Mon, 11 Dec 2023 17:54:22 -0500 Subject: [PATCH 6/7] Update some names; simplify some statements --- src/mystery_gift.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/src/mystery_gift.c b/src/mystery_gift.c index 619753b7ba..d90375de7d 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -51,7 +51,7 @@ WonderCard* SaveMysteryGift_CardGetByIdx(MysteryGiftSave* mg, int index) { BOOL SaveMysteryGift_TryInsertGift(MysteryGiftSave* mg, const MysteryGift* src, int cardIdx) { BOOL ret = FALSE; int i; - + if (!SaveMysteryGift_FindAvailable(mg)) { return FALSE; } @@ -156,30 +156,18 @@ BOOL SaveMysteryGift_CardFindAvailable(const MysteryGiftSave* mg) { BOOL SaveMysteryGift_TagAtIndexIsValid(const MysteryGiftSave* mg, int index) { GF_ASSERT(index < NUM_SAVED_MYSTERY_GIFTS); - - if (MysteryGiftTagIsValid(mg->gifts[index].tag)) { - return TRUE; - } else { - return FALSE; - } + + return MysteryGiftTagIsValid(mg->gifts[index].tag) != FALSE; } BOOL SaveMysteryGift_CardTagIsValid(const MysteryGiftSave* mg, int index) { GF_ASSERT(index < NUM_SAVED_WONDER_CARDS); - - if (MysteryGiftTagIsValid(mg->cards[index].tag)) { - return TRUE; - } else { - return FALSE; - } + + return MysteryGiftTagIsValid(mg->cards[index].tag) != FALSE; } BOOL SaveMysteryGift_SpecialCardTagIsValid(const MysteryGiftSave* mg) { - if (MysteryGiftTagIsValid(mg->specialWonderCard.tag)) { - return TRUE; - } else { - return FALSE; - } + return MysteryGiftTagIsValid(mg->specialWonderCard.tag) != FALSE; } BOOL SaveMysteryGift_HasAnyCard(const MysteryGiftSave* mg) { @@ -243,18 +231,20 @@ void SaveMysteryGift_SetFlagx7FF(MysteryGiftSave* mg) { SaveMysteryGift_ReceivedFlagSet(mg, 0x7FF); } -static MysteryGiftSave* sMysteryGiftData; +// ====================================== + +static MysteryGiftSave* sMysteryGiftSaveData; void GetStaticPointerToSaveMysteryGift(SaveData* saveData) { - if (sMysteryGiftData == NULL) { - sMysteryGiftData = Save_MysteryGift_Get(saveData); + if (sMysteryGiftSaveData == NULL) { + sMysteryGiftSaveData = Save_MysteryGift_Get(saveData); } SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); } void DeleteStaticPointerToMysteryGift(void) { - if (sMysteryGiftData != NULL) { - sMysteryGiftData = NULL; + if (sMysteryGiftSaveData != NULL) { + sMysteryGiftSaveData = NULL; } } @@ -262,7 +252,7 @@ int GetFirstQueuedMysteryGiftIdx(void) { int i; for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) { - if (SaveMysteryGift_TagAtIndexIsValid(sMysteryGiftData, i) == TRUE) { + if (SaveMysteryGift_TagAtIndexIsValid(sMysteryGiftSaveData, i) == TRUE) { return i; } } @@ -271,7 +261,7 @@ int GetFirstQueuedMysteryGiftIdx(void) { } u16 GetMysteryGiftTagByIdx(int index) { - MysteryGift* gift = SaveMysteryGift_GetByIdx(sMysteryGiftData, index); + MysteryGift* gift = SaveMysteryGift_GetByIdx(sMysteryGiftSaveData, index); if (gift != NULL) { return gift->tag; } @@ -280,7 +270,7 @@ u16 GetMysteryGiftTagByIdx(int index) { } MysteryGiftData* GetMysteryGiftDataByIdx(int index) { - MysteryGift* gift = SaveMysteryGift_GetByIdx(sMysteryGiftData, index); + MysteryGift* gift = SaveMysteryGift_GetByIdx(sMysteryGiftSaveData, index); if (gift != NULL) { return &gift->data; } @@ -289,5 +279,5 @@ MysteryGiftData* GetMysteryGiftDataByIdx(int index) { } void SetMysteryGiftReceivedByIdx(int index) { - SaveMysteryGift_SetReceivedByIdx(sMysteryGiftData, index); + SaveMysteryGift_SetReceivedByIdx(sMysteryGiftSaveData, index); } From 7334c8e35691b088d3c3dbd31562d097df116cf3 Mon Sep 17 00:00:00 2001 From: pikalaxalt Date: Sat, 16 Dec 2023 20:51:34 -0500 Subject: [PATCH 7/7] Address other review comments --- asm/include/scrcmd_11.inc | 12 ++++++------ asm/scrcmd_11.s | 18 +++++++++--------- include/mystery_gift.h | 28 ++++++++++++++-------------- src/mystery_gift.c | 12 ++++++------ 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/asm/include/scrcmd_11.inc b/asm/include/scrcmd_11.inc index 13b581ea28..872e6a3885 100644 --- a/asm/include/scrcmd_11.inc +++ b/asm/include/scrcmd_11.inc @@ -30,12 +30,12 @@ .public GiveOrTakeSeal .public SealCase_CheckSealQuantity .public Save_SpecialRibbons_Get -.public GetStaticPointerToSaveMysteryGift -.public DeleteStaticPointerToMysteryGift -.public GetFirstQueuedMysteryGiftIdx -.public GetMysteryGiftTagByIdx -.public GetMysteryGiftDataByIdx -.public SetMysteryGiftReceivedByIdx +.public SaveMGDataPtr_Begin +.public SaveMGDataPtr_End +.public SaveMGDataPtr_GetFirstGiftIndex +.public SaveMGDataPtr_GetTagByIndex +.public SaveMGDataPtr_GetDataByIndex +.public SaveMGDataPtr_SetReceivedByIndex .public UpdatePokedexWithReceivedSpecies .public Save_PhotoAlbum_Get .public PhotoAlbum_GetIndexOfFirstEmptySlot diff --git a/asm/scrcmd_11.s b/asm/scrcmd_11.s index 9507ef1084..555d9453f8 100644 --- a/asm/scrcmd_11.s +++ b/asm/scrcmd_11.s @@ -37,24 +37,24 @@ FieldSystem_InitGetMysteryGiftGmmState: ; 0x0204BD78 thumb_func_start FieldSystem_GetTagOfNextMG FieldSystem_GetTagOfNextMG: ; 0x0204BD80 push {r3, lr} - bl GetFirstQueuedMysteryGiftIdx - bl GetMysteryGiftTagByIdx + bl SaveMGDataPtr_GetFirstGiftIndex + bl SaveMGDataPtr_GetTagByIndex pop {r3, pc} thumb_func_end FieldSystem_GetTagOfNextMG thumb_func_start FieldSystem_GetDataOfNextMG FieldSystem_GetDataOfNextMG: ; 0x0204BD8C push {r3, lr} - bl GetFirstQueuedMysteryGiftIdx - bl GetMysteryGiftDataByIdx + bl SaveMGDataPtr_GetFirstGiftIndex + bl SaveMGDataPtr_GetDataByIndex pop {r3, pc} thumb_func_end FieldSystem_GetDataOfNextMG thumb_func_start FieldSystem_SetQueuedMGReceived FieldSystem_SetQueuedMGReceived: ; 0x0204BD98 push {r3, lr} - bl GetFirstQueuedMysteryGiftIdx - bl SetMysteryGiftReceivedByIdx + bl SaveMGDataPtr_GetFirstGiftIndex + bl SaveMGDataPtr_SetReceivedByIndex pop {r3, pc} thumb_func_end FieldSystem_SetQueuedMGReceived @@ -90,7 +90,7 @@ _0204BDD2: ldr r0, [r4] mov r1, #0x20 ldr r0, [r0, #0xc] - bl GetStaticPointerToSaveMysteryGift + bl SaveMGDataPtr_Begin b _0204BF8C _0204BDE0: ; End @@ -98,7 +98,7 @@ _0204BDE0: ldr r0, [r4] mov r1, #0 ldr r0, [r0, #0xc] - bl DeleteStaticPointerToMysteryGift + bl SaveMGDataPtr_End b _0204BF8C _0204BDEE: ; End.2 @@ -106,7 +106,7 @@ _0204BDEE: ldr r0, [r4] mov r1, #1 ldr r0, [r0, #0xc] - bl DeleteStaticPointerToMysteryGift + bl SaveMGDataPtr_End b _0204BF8C _0204BDFC: ; Check bool diff --git a/include/mystery_gift.h b/include/mystery_gift.h index 9c8308ce02..861b9340fe 100644 --- a/include/mystery_gift.h +++ b/include/mystery_gift.h @@ -27,30 +27,30 @@ #define RECEIVED_WONDER_CARD_IDX 4 #define NUM_MYSTERY_GIFT_RECV_FLAGS 2048 -typedef struct MG_POKEMON_TAG { +typedef struct MysteryGiftPokemonTag { BOOL fixedOT; Pokemon mon; u8 ribbons[10]; -} MG_POKEMON_TAG; +} MysteryGiftPokemonTag; -typedef struct MG_MON_DECO_TAG { +typedef struct MysteryGiftMonDecorationTag { int kind; // 1 = seal, 2 = fashion, 3 = background int id; -} MG_MON_DECO_TAG; +} MysteryGiftMonDecorationTag; typedef union { - MG_POKEMON_TAG pokemon; + MysteryGiftPokemonTag pokemon; Pokemon egg; u32 item; u16 ruleset[24]; - int base_decoration; - MG_MON_DECO_TAG mon_decoration; + int baseDecoration; + MysteryGiftMonDecorationTag monDecoration; u8 pokewalkerCourse; PHOTO photo; u8 raw[256]; } MysteryGiftData; -typedef struct { +typedef struct UnkWonderCardSubstruct_104 { u16 name[36]; u32 version; // 88 u16 id; // 8C @@ -166,25 +166,25 @@ void SaveMysteryGift_SetFlagx7FF(MysteryGiftSave* mg); // commands. // Loads the internal MysteryGiftSave pointer. -void GetStaticPointerToSaveMysteryGift(SaveData* saveData); +void SaveMGDataPtr_Begin(SaveData* saveData); // Unloads the internal MysteryGiftSave pointer. -void DeleteStaticPointerToMysteryGift(void); +void SaveMGDataPtr_End(void); // Gets the index of the first occupied // Mystery Gift slot. -int GetFirstQueuedMysteryGiftIdx(void); +int SaveMGDataPtr_GetFirstGiftIndex(void); // Returns the Mystery Gift type at the // given slot index. -u16 GetMysteryGiftTagByIdx(int index); +u16 SaveMGDataPtr_GetTagByIndex(int index); // Retrieves a pointer to the Mystery Gift data // at the given slot index. -MysteryGiftData* GetMysteryGiftDataByIdx(int index); +MysteryGiftData* SaveMGDataPtr_GetDataByIndex(int index); // Flag the Mystery Gift at the given slot index // as received. -void SetMysteryGiftReceivedByIdx(int index); +void SaveMGDataPtr_SetReceivedByIndex(int index); #endif //POKEHEARTGOLD_MYSTERY_GIFT_H diff --git a/src/mystery_gift.c b/src/mystery_gift.c index d90375de7d..042c9f9392 100644 --- a/src/mystery_gift.c +++ b/src/mystery_gift.c @@ -235,20 +235,20 @@ void SaveMysteryGift_SetFlagx7FF(MysteryGiftSave* mg) { static MysteryGiftSave* sMysteryGiftSaveData; -void GetStaticPointerToSaveMysteryGift(SaveData* saveData) { +void SaveMGDataPtr_Begin(SaveData* saveData) { if (sMysteryGiftSaveData == NULL) { sMysteryGiftSaveData = Save_MysteryGift_Get(saveData); } SaveSubstruct_UpdateCRC(SAVE_MYSTERY_GIFT); } -void DeleteStaticPointerToMysteryGift(void) { +void SaveMGDataPtr_End(void) { if (sMysteryGiftSaveData != NULL) { sMysteryGiftSaveData = NULL; } } -int GetFirstQueuedMysteryGiftIdx(void) { +int SaveMGDataPtr_GetFirstGiftIndex(void) { int i; for (i = 0; i < NUM_SAVED_MYSTERY_GIFTS; ++i) { @@ -260,7 +260,7 @@ int GetFirstQueuedMysteryGiftIdx(void) { return -1; } -u16 GetMysteryGiftTagByIdx(int index) { +u16 SaveMGDataPtr_GetTagByIndex(int index) { MysteryGift* gift = SaveMysteryGift_GetByIdx(sMysteryGiftSaveData, index); if (gift != NULL) { return gift->tag; @@ -269,7 +269,7 @@ u16 GetMysteryGiftTagByIdx(int index) { return MG_TAG_INVALID; } -MysteryGiftData* GetMysteryGiftDataByIdx(int index) { +MysteryGiftData* SaveMGDataPtr_GetDataByIndex(int index) { MysteryGift* gift = SaveMysteryGift_GetByIdx(sMysteryGiftSaveData, index); if (gift != NULL) { return &gift->data; @@ -278,6 +278,6 @@ MysteryGiftData* GetMysteryGiftDataByIdx(int index) { return NULL; } -void SetMysteryGiftReceivedByIdx(int index) { +void SaveMGDataPtr_SetReceivedByIndex(int index) { SaveMysteryGift_SetReceivedByIdx(sMysteryGiftSaveData, index); }