diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2020-08-30 18:23:26 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2020-08-30 18:23:26 -0400 |
commit | 73aecdbbbff398c27734f8ed793bb495a5391a4b (patch) | |
tree | b3060e2576d1572c1a8aeb63f300f43ba0d13131 /arm9/src | |
parent | 550450880645598b327be0e512b48de2c3777a58 (diff) |
Decompile mail-related code
Diffstat (limited to 'arm9/src')
-rw-r--r-- | arm9/src/daycare.c | 4 | ||||
-rw-r--r-- | arm9/src/mail.c | 267 | ||||
-rw-r--r-- | arm9/src/main.c | 4 | ||||
-rw-r--r-- | arm9/src/pokemon.c | 30 | ||||
-rw-r--r-- | arm9/src/save_arrays.c | 4 |
5 files changed, 289 insertions, 20 deletions
diff --git a/arm9/src/daycare.c b/arm9/src/daycare.c index eff25151..b144f0a9 100644 --- a/arm9/src/daycare.c +++ b/arm9/src/daycare.c @@ -1,6 +1,6 @@ #include "global.h" #include "pokemon.h" -#include "seals.h" +#include "mail.h" #include "save_block_2.h" #include "daycare.h" @@ -40,7 +40,7 @@ u32 DayCareMon_GetSteps(struct DayCareMon * dcmon) return dcmon->steps; } -struct SealStruct * DayCareMail_GetCapsule(struct DayCareMail * dcmail) +struct Mail * DayCareMail_GetCapsule(struct DayCareMail * dcmail) { return &dcmail->seal; } diff --git a/arm9/src/mail.c b/arm9/src/mail.c new file mode 100644 index 00000000..96074471 --- /dev/null +++ b/arm9/src/mail.c @@ -0,0 +1,267 @@ +#include "global.h" +#include "mail.h" +#include "heap.h" +#include "string_util.h" +#include "MI_memory.h" +#include "save_block_2.h" +#include "party.h" +#include "player_data.h" + +#pragma thumb on + +extern void FUN_02013724(u16 * ptr); +extern u32 FUN_0206B6C8(struct Pokemon * pokemon); +extern u16 FUN_0206B7BC(u16 species, u32 forme, BOOL is_egg); +extern void FUN_02013960(u16 * dest, const u16 * src); + +void Mail_init(struct Mail * mail) +{ + s32 i; + mail->author_otId = 0; + mail->author_gender = 0; + mail->author_language = (u8)gGameLanguage; + mail->author_version = (u8)gGameVersion; + mail->mail_type = 0xFF; + StringFillEOS(mail->author_name, 8); + for (i = 0; i < 3; i++) + { + mail->unk_18[i].raw = 0xFFFF; + } + for (i = 0; i < 3; i++) + { + FUN_02013724(mail->unk_20[i]); + } +} + +BOOL Mail_TypeIsValid(struct Mail * mail) +{ + return mail->mail_type <= 11; +} + +struct Mail * Mail_new(u32 heap_id) +{ + struct Mail * ret = (struct Mail *)AllocFromHeapAtEnd(heap_id, sizeof(struct Mail)); + Mail_init(ret); + return ret; +} + +void Mail_copy(const struct Mail * src, struct Mail * dest) +{ + MI_CpuCopy8(src, dest, sizeof(struct Mail)); +} + +void Mail_SetNewMessageDetails(struct Mail * mail, u8 type, u8 monIdx, struct SaveBlock2 * sav2) +{ + u32 sp10; + u32 forme; + BOOL is_egg; + u16 species; + struct PlayerParty * party; + struct PlayerData * profile; + struct Pokemon * pokemon; + u16 r7; + u8 i; + + Mail_init(mail); + mail->mail_type = type; + party = SavArray_PlayerParty_get(sav2); + profile = Sav2_PlayerData_GetProfileAddr(sav2); + + CopyU16StringArray(mail->author_name, PlayerProfile_GetNamePtr(profile)); + mail->author_gender = (u8)PlayerProfile_GetTrainerGender(profile); + mail->author_otId = PlayerProfile_GetTrainerID(profile); + for (i = 0; monIdx < GetPartyCount(party); monIdx++) + { + union MailMessage * ptr; + pokemon = GetPartyMonByIndex(party, monIdx); + species = (u16)GetMonData(pokemon, MON_DATA_SPECIES, NULL); + is_egg = (BOOL)GetMonData(pokemon, MON_DATA_IS_EGG, NULL); + forme = GetMonData(pokemon, MON_DATA_FORME, NULL); + sp10 = FUN_0206B6C8(pokemon); + r7 = FUN_0206B7BC(species, forme, is_egg); + ptr = &mail->unk_18[i]; + ptr->bits.unk_0 = sp10; + i++; + ptr->bits.unk_C = r7; + if (i >= 3) + break; + } +} + +u32 Mail_GetOTID(struct Mail * mail) +{ + return mail->author_otId; +} + +u16 * Mail_GetAuthorNamePtr(struct Mail * mail) +{ + return mail->author_name; +} + +u8 Mail_GetAuthorGender(struct Mail * mail) +{ + return mail->author_gender; +} + +u8 Mail_GetType(struct Mail * mail) +{ + return mail->mail_type; +} + +void Mail_SetType(struct Mail * mail, u8 type) +{ + if (type < 12) + mail->mail_type = type; +} + +u8 Mail_GetLanguage(struct Mail * mail) +{ + return mail->author_language; +} + +u8 Mail_GetVersion(struct Mail * mail) +{ + return mail->author_version; +} + +u16 Mail_GetAttrFromUnk18Array(struct Mail * mail, u32 idx, u32 attr) +{ + if (idx < 3) + { + switch (attr) + { + case 0: + return mail->unk_18[idx].bits.unk_0; + case 1: + return mail->unk_18[idx].bits.unk_C; + case 2: + default: + return mail->unk_18[idx].raw; + } + } + return 0; +} + +u16 * Mail_GetUnk20Array(struct Mail * mail, u32 idx) +{ + if (idx < 3) + return mail->unk_20[idx]; + else + return mail->unk_20[0]; +} + +void Mail_CopyToUnk20Array(struct Mail * mail, const u16 * src, u32 idx) +{ + if (idx < 3) + FUN_02013960(mail->unk_20[idx], src); +} + +struct Mail * Sav2_Mailbox_get(struct SaveBlock2 * sav2) +{ + return (struct Mail *)SavArray_get(sav2, 15); +} + +u32 Sav2_Mailbox_sizeof(void) +{ + return 20 * sizeof(struct Mail); +} + +void Sav2_Mailbox_init(struct Mail * mail) +{ + s32 i; + for (i = 0; i < 20; i++) + { + Mail_init(&mail[i]); + } +} + +s32 Mailbox_GetFirstEmptySlotIdx(struct Mail * mail, BOOL r1) +{ + switch (r1) + { + case 0: + return MailArray_GetFirstEmptySlotIdx(mail, 20); + default: + return -1; + } +} + +void Mailbox_DeleteSlotI(struct Mail * mail, BOOL r1, s32 idx) +{ + mail = Mailbox_GetPtrToSlotI(mail, r1, idx); + if (mail != NULL) + Mail_init(mail); +} + +void Mailbox_CopyMailToSlotI(struct Mail * mail, BOOL r1, s32 idx, const struct Mail * src) +{ + mail = Mailbox_GetPtrToSlotI(mail, r1, idx); + if (mail != NULL) + Mail_copy(src, mail); +} + +s32 Mailbox_CountMessages(struct Mail * mail, BOOL r1) +{ + switch (r1) + { + case 0: + return MailArray_CountMessages(mail, 20); + default: + return 0; + } +} + +struct Mail * Mailbox_AllocAndFetchMailI(struct Mail * mail, BOOL r1, s32 idx, u32 heap_id) +{ + struct Mail * ret; + mail = Mailbox_GetPtrToSlotI(mail, r1, idx); + ret = Mail_new(heap_id); + if (mail != NULL) + Mail_copy(mail, ret); + return ret; +} + +void Mailbox_FetchMailIToBuffer(struct Mail * mail, BOOL r1, s32 idx, struct Mail * dest) +{ + mail = Mailbox_GetPtrToSlotI(mail, r1, idx); + if (mail == NULL) + Mail_init(dest); + else + Mail_copy(mail, dest); +} + +s32 MailArray_GetFirstEmptySlotIdx(struct Mail * mail, s32 count) +{ + s32 i; + for (i = 0; i < count; i++) + { + if (!Mail_TypeIsValid(&mail[i])) + return i; + } + return -1; +} + +s32 MailArray_CountMessages(struct Mail * mail, s32 count) +{ + s32 ret = 0; + s32 i; + for (i = 0; i < count; i++) + { + if (Mail_TypeIsValid(&mail[i])) + ret++; + } + return ret; +} + +struct Mail * Mailbox_GetPtrToSlotI(struct Mail * mail, BOOL r1, s32 idx) +{ + struct Mail * ret = NULL; + switch (r1) + { + case 0: + if (idx < 20) + ret = &mail[idx]; + break; + } + return ret; +} diff --git a/arm9/src/main.c b/arm9/src/main.c index 4f3b583c..86f0f6af 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -1,3 +1,5 @@ +#define IN_MAIN_C + #include "global.h" #include "SPI_pm.h" #include "CARD_backup.h" @@ -51,7 +53,7 @@ extern struct Unk21DBE18 MOD52_021D76C8; extern u8 SDK_STATIC_BSS_START[]; -const u8 gGameVersion = GAME_VERSION; +const int gGameVersion = GAME_VERSION; const int gGameLanguage = GAME_LANGUAGE; THUMB_FUNC void NitroMain(void) diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c index 0fb6d121..1f48d0fc 100644 --- a/arm9/src/pokemon.c +++ b/arm9/src/pokemon.c @@ -19,6 +19,8 @@ #pragma thumb on +extern void FUN_02029C74(const u8 *, u8 *); + u32 GetMonDataInternal(struct Pokemon * pokemon, int attr, void * ptr); u32 GetBoxMonDataInternal(struct BoxPokemon * pokemon, int attr, void * ptr); void SetMonDataInternal(struct Pokemon * pokemon, int attr, void * ptr); @@ -255,7 +257,7 @@ BOOL ReleaseBoxMonLock(struct BoxPokemon * mon, BOOL decrypt_result) void CreateMon(struct Pokemon * pokemon, int species, int level, int fixedIV, int hasFixedPersonality, int fixedPersonality, int otIdType, int fixedOtId) { - struct SealStruct * seal; + struct Mail * mail; u32 capsule; u8 seal_coords[0x18]; ZeroMonData(pokemon); @@ -264,9 +266,9 @@ void CreateMon(struct Pokemon * pokemon, int species, int level, int fixedIV, in MonEncryptSegment((u16 *)&pokemon->party, sizeof(pokemon->party), 0); ENCRYPT_PTY(pokemon); SetMonData(pokemon, MON_DATA_LEVEL, &level); - seal = CreateNewSealsObject(0); - SetMonData(pokemon, MON_DATA_SEAL_STRUCT, seal); - FreeToHeap(seal); + mail = Mail_new(0); + SetMonData(pokemon, MON_DATA_MAIL_STRUCT, mail); + FreeToHeap(mail); capsule = 0; SetMonData(pokemon, MON_DATA_CAPSULE, &capsule); MIi_CpuClearFast(0, seal_coords, sizeof(seal_coords)); @@ -558,8 +560,8 @@ u32 GetMonDataInternal(struct Pokemon * pokemon, int attr, void * dest) return pokemon->party.spatk; case MON_DATA_SPDEF: return pokemon->party.spdef; - case MON_DATA_SEAL_STRUCT: - CopySealsObject(&pokemon->party.seal_something, dest); + case MON_DATA_MAIL_STRUCT: + Mail_copy(&pokemon->party.seal_something, dest); return 1; case MON_DATA_SEAL_COORDS: FUN_02029C74(pokemon->party.sealCoords, dest); @@ -1046,8 +1048,8 @@ void SetMonDataInternal(struct Pokemon * pokemon, int attr, void * value) case MON_DATA_SPDEF: pokemon->party.spdef = VALUE(u16); break; - case MON_DATA_SEAL_STRUCT: - CopySealsObject((const struct SealStruct *)value, &pokemon->party.seal_something); + case MON_DATA_MAIL_STRUCT: + Mail_copy((const struct Mail *)value, &pokemon->party.seal_something); break; case MON_DATA_SEAL_COORDS: FUN_02029C74((const u8 *)value, pokemon->party.sealCoords); @@ -1475,7 +1477,7 @@ void AddMonDataInternal(struct Pokemon * pokemon, int attr, int value) case MON_DATA_SPEED: case MON_DATA_SPATK: case MON_DATA_SPDEF: - case MON_DATA_SEAL_STRUCT: + case MON_DATA_MAIL_STRUCT: // case MON_DATA_SEAL_COORDS: GF_ASSERT(0); break; @@ -1756,7 +1758,7 @@ void AddBoxMonData(struct BoxPokemon * boxmon, int attr, int value) case MON_DATA_SPEED: case MON_DATA_SPATK: case MON_DATA_SPDEF: - case MON_DATA_SEAL_STRUCT: + case MON_DATA_MAIL_STRUCT: case MON_DATA_SEAL_COORDS: case MON_DATA_SPECIES_EXISTS: case MON_DATA_SANITY_IS_EGG: @@ -2990,16 +2992,16 @@ void FUN_02069A64(struct BoxPokemon * src, struct Pokemon * dest) { u32 sp0 = 0; u8 sp4[12][2]; - struct SealStruct * seals; + struct Mail * mail; dest->box = *src; if (dest->box.box_lock) dest->box.party_lock = TRUE; SetMonData(dest, MON_DATA_STATUS, &sp0); SetMonData(dest, MON_DATA_HP, &sp0); SetMonData(dest, MON_DATA_MAXHP, &sp0); - seals = CreateNewSealsObject(0); - SetMonData(dest, MON_DATA_SEAL_STRUCT, seals); - FreeToHeap(seals); + mail = Mail_new(0); + SetMonData(dest, MON_DATA_MAIL_STRUCT, mail); + FreeToHeap(mail); SetMonData(dest, MON_DATA_CAPSULE, &sp0); MIi_CpuClearFast(0, sp4, sizeof(sp4)); SetMonData(dest, MON_DATA_SEAL_COORDS, sp4); diff --git a/arm9/src/save_arrays.c b/arm9/src/save_arrays.c index 4ba492b8..43e83403 100644 --- a/arm9/src/save_arrays.c +++ b/arm9/src/save_arrays.c @@ -20,7 +20,6 @@ extern u32 FUN_02034D80(void); extern u32 FUN_02025954(void); extern u32 FUN_02023AC8(void); extern u32 FUN_02026FD8(void); -extern u32 FUN_02025844(void); extern u32 FUN_02028054(void); extern u32 FUN_02028980(void); extern u32 FUN_02029A84(void); @@ -45,7 +44,6 @@ extern void FUN_02034D88(void *); extern void FUN_0202597C(void *); extern void FUN_02023AD8(void *); extern void FUN_02026F60(void *); -extern void FUN_0202584C(void *); extern void FUN_0202805C(void *); extern void FUN_02028994(void *); extern void FUN_02029A8C(void *); @@ -85,7 +83,7 @@ const struct SaveChunkHeader UNK_020EE700[] = { { 12, 0, (SAVSIZEFN)FUN_02025954, (SAVINITFN)FUN_0202597C }, { 13, 0, (SAVSIZEFN)FUN_02023AC8, (SAVINITFN)FUN_02023AD8 }, { 14, 0, (SAVSIZEFN)FUN_02026FD8, (SAVINITFN)FUN_02026F60 }, - { 15, 0, (SAVSIZEFN)FUN_02025844, (SAVINITFN)FUN_0202584C }, + { 15, 0, (SAVSIZEFN)Sav2_Mailbox_sizeof, (SAVINITFN)Sav2_Mailbox_init }, { 16, 0, (SAVSIZEFN)FUN_02028054, (SAVINITFN)FUN_0202805C }, { 17, 0, (SAVSIZEFN)FUN_020286F8, (SAVINITFN)FUN_02028724 }, { 18, 0, (SAVSIZEFN)FUN_02028980, (SAVINITFN)FUN_02028994 }, |