From 96499a6120d0d0eb9382685253f69bd9123ddb18 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 22 Aug 2020 17:17:59 -0400 Subject: Decompile sav_system_info --- arm9/src/main.c | 4 +- arm9/src/sav_system_info.c | 123 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 arm9/src/sav_system_info.c (limited to 'arm9/src') diff --git a/arm9/src/main.c b/arm9/src/main.c index e1c8fb38..7baf4c6a 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -262,7 +262,7 @@ THUMB_FUNC void FUN_02000F4C(u32 arg0, u32 arg1) DoSoftReset(arg0); } -extern void FUN_0201265C(struct Unk21C4818 *, struct Unk21C4828 *); +extern void CopyRtcBuffersTo(struct Unk21C4818 *, struct Unk21C4828 *); extern void SetMTRNGSeed(u32); extern void SetLCRNGSeed(u32); @@ -270,7 +270,7 @@ THUMB_FUNC void InitializeMainRNG(void) { struct Unk21C4818 spC; struct Unk21C4828 sp0; - FUN_0201265C(&spC, &sp0); + CopyRtcBuffersTo(&spC, &sp0); { u32 r4 = gMain.unk2C; u32 r5 = ((sp0.unk4 + sp0.unk8) << 24) + (spC.unk0 + ((256 * spC.unk4 * spC.unk8) << 16) + (sp0.unk0 << 16)); diff --git a/arm9/src/sav_system_info.c b/arm9/src/sav_system_info.c new file mode 100644 index 00000000..cb20bd9b --- /dev/null +++ b/arm9/src/sav_system_info.c @@ -0,0 +1,123 @@ +#include "global.h" +#include "save_block_2.h" +#include "MI_memory.h" +#include "OS_ownerInfo.h" +#include "RTC_api.h" +#include "RTC_convert.h" +#include "sav_system_info.h" + +#pragma thumb on + +extern void CopyRtcBuffersTo(RTCDate *, RTCTime *); + +u32 FUN_0202376C(void) +{ + return sizeof(struct UnkSaveStruct_0202376C); +} + +void FUN_02023770(struct UnkSaveStruct_0202376C * unk) +{ + MI_CpuClearFast(unk, sizeof(struct UnkSaveStruct_0202376C)); + FUN_02023840(&unk->rtcInfo); +} + +struct UnkSaveStruct_0202376C * FUN_02023788(struct SaveBlock2 * sav2) +{ + return (struct UnkSaveStruct_0202376C *)SavArray_get(sav2, 0); +} + +struct UnkSaveStruct_0202376C_sub * FUN_02023794(struct SaveBlock2 * sav2) +{ + return &FUN_02023788(sav2)->rtcInfo; +} + +void FUN_020237A0(struct UnkSaveStruct_0202376C * unk) +{ + OSOwnerInfo info; + unk->rtcOffset = OS_GetOwnerRtcOffset(); + OS_GetMacAddress(unk->macAddr); + OS_GetOwnerInfo(&info); + unk->birthMonth = info.birthday.month; + unk->birthDay = info.birthday.day; +} + +BOOL FUN_020237CC(struct UnkSaveStruct_0202376C * unk) +{ + u8 macAddr[6]; + OS_GetMacAddress(macAddr); + for (int i = 0; i < 6; i++) + { + if (macAddr[i] != unk->macAddr[i]) + return FALSE; + } + return TRUE; +} + +BOOL FUN_020237FC(struct UnkSaveStruct_0202376C * unk) +{ + return OS_GetOwnerRtcOffset() == unk->rtcOffset; +} + +u8 FUN_02023818(struct UnkSaveStruct_0202376C * unk) +{ + return unk->birthMonth; +} + +u8 FUN_0202381C(struct UnkSaveStruct_0202376C * unk) +{ + return unk->birthDay; +} + +u8 FUN_02023820(struct UnkSaveStruct_0202376C * unk) +{ + return unk->field_48; +} + +void FUN_02023828(struct UnkSaveStruct_0202376C * unk, u8 val) +{ + unk->field_48 = val; +} + +u32 FUN_02023830(struct UnkSaveStruct_0202376C * unk) +{ + return unk->field_4C; +} + +void FUN_02023834(struct UnkSaveStruct_0202376C * unk, u32 val) +{ + if (unk->field_4C == 0) + unk->field_4C = val; +} + +void FUN_02023840(struct UnkSaveStruct_0202376C_sub * sub) +{ + sub->field_00 = 1; + CopyRtcBuffersTo(&sub->date, &sub->time); + sub->daysSinceNitroEpoch = RTC_ConvertDateToDay(&sub->date); + sub->secondsSinceNitroEpoch = RTC_ConvertDateTimeToSecond(&sub->date, &sub->time); + sub->field_2C = 0; + sub->field_30 = 0; + sub->field_34 = 0; +} + +BOOL FUN_02023874(struct UnkSaveStruct_0202376C_sub * sub) +{ + return sub->field_34 != 0; +} + +void FUN_02023884(struct UnkSaveStruct_0202376C_sub * sub, u32 a1) +{ + if (sub->field_34 > 1440) + sub->field_34 = 1440; + if (sub->field_34 < a1) + sub->field_34 = 0; + else + sub->field_34 -= a1; +} + +void FUN_020238A4(struct UnkSaveStruct_0202376C_sub * sub) +{ + sub->field_34 = 1440; + CopyRtcBuffersTo(&sub->date, &sub->time); + sub->daysSinceNitroEpoch = RTC_ConvertDateToDay(&sub->date); +} -- cgit v1.2.3 From c937f6bd635dcd04af60510746ca4f24254b7e27 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 24 Aug 2020 10:28:30 -0400 Subject: Fix a function prototype in pokemon.c --- arm9/src/pokemon.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'arm9/src') diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c index 3db6796a..97be796b 100644 --- a/arm9/src/pokemon.c +++ b/arm9/src/pokemon.c @@ -2,6 +2,7 @@ #define IN_POKEMON_C #include "proto.h" #include "party.h" +#include "player_data.h" #include "pokemon.h" #include "filesystem.h" #include "heap.h" @@ -41,7 +42,7 @@ BOOL FUN_02069E7C(struct BoxPokemon * boxmon); BOOL FUN_02069E9C(struct BoxPokemon * boxmon); void FUN_02069ECC(struct BoxPokemon * boxmon); void LoadWotbl_HandleAlternateForme(int species, int forme, u16 * wotbl); -void FUN_0206A054(struct BoxPokemon * boxmon, u32 a1, u32 pokeball, u32 a3, u32 encounterType, u32 a5); +void FUN_0206A054(struct BoxPokemon * boxmon, struct PlayerData * a1, u32 pokeball, u32 a3, u32 encounterType, u32 heap_id); BOOL MonHasMove(struct Pokemon * pokemon, u16 move); BOOL FUN_0206A144(struct BoxPokemon * boxmon, u32 a1); BOOL FUN_0206A16C(u16 species, int forme, u32 a2); @@ -3321,10 +3322,10 @@ void FUN_02069FB0(u32 r7, u32 r5, u32 r4, u32 r6, u32 sp18, u32 sp1C, u32 sp20) } } -void FUN_0206A014(struct Pokemon * pokemon, u32 a1, u32 pokeball, u32 a3, u32 encounterType, u32 a5) +void FUN_0206A014(struct Pokemon * pokemon, struct PlayerData * a1, u32 pokeball, u32 a3, u32 encounterType, u32 heap_id) { u32 hp; - FUN_0206A054(&pokemon->box, a1, pokeball, a3, encounterType, a5); + FUN_0206A054(&pokemon->box, a1, pokeball, a3, encounterType, heap_id); if (pokeball == ITEM_HEAL_BALL) { hp = GetMonData(pokemon, MON_DATA_MAXHP, NULL); @@ -3334,9 +3335,9 @@ void FUN_0206A014(struct Pokemon * pokemon, u32 a1, u32 pokeball, u32 a3, u32 en } } -void FUN_0206A054(struct BoxPokemon * boxmon, u32 a1, u32 pokeball, u32 a3, u32 encounterType, u32 a5) +void FUN_0206A054(struct BoxPokemon * boxmon, struct PlayerData * a1, u32 pokeball, u32 a3, u32 encounterType, u32 heap_id) { - FUN_020808AC(boxmon, (int)a1, 0, (int)a3, (int)a5); + FUN_020808AC(boxmon, a1, 0, a3, heap_id); SetBoxMonData(boxmon, MON_DATA_GAME_VERSION, (void *)&gGameVersion); SetBoxMonData(boxmon, MON_DATA_POKEBALL, &pokeball); SetBoxMonData(boxmon, MON_DATA_ENCOUNTER_TYPE, &encounterType); -- cgit v1.2.3 From b55789b64644420add50cf87715a1ab0ade16967 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 24 Aug 2020 16:59:00 -0400 Subject: Rename RTC-related routines --- arm9/src/main.c | 12 ++++++------ arm9/src/sav_system_info.c | 45 ++++++++++++++++++++++----------------------- arm9/src/save_arrays.c | 6 +++--- 3 files changed, 31 insertions(+), 32 deletions(-) (limited to 'arm9/src') diff --git a/arm9/src/main.c b/arm9/src/main.c index 7baf4c6a..4f3b583c 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -27,7 +27,7 @@ extern BOOL FUN_0202FB80(void); extern void InitSystemForTheGame(void); extern void InitGraphicMemory(void); extern void FUN_02022294(void); -extern void FUN_0201259C(void); +extern void GF_InitRTCWork(void); extern void FUN_02002C14(void); extern void FUN_02002C50(int, int); extern struct SaveBlock2 * SaveBlock2_new(void); @@ -40,7 +40,7 @@ extern void FUN_02089D90(int); extern void FUN_0200A2AC(void); extern void FUN_02015E30(void); extern void FUN_0201B5CC(void *); -extern void FUN_020125D4(void); +extern void GF_RTC_UpdateOnFrame(void); extern void FUN_02015E60(void); extern void FUN_020222C4(void); extern void FUN_0200A318(void); @@ -64,7 +64,7 @@ THUMB_FUNC void NitroMain(void) PM_GetBackLight((PMBackLightSwitch *)SDK_STATIC_BSS_START, NULL); FUN_02022294(); - FUN_0201259C(); + GF_InitRTCWork(); FUN_02000DF4(); FUN_02002C14(); FUN_02002C50(0, 3); @@ -125,7 +125,7 @@ THUMB_FUNC void NitroMain(void) gMain.unk2C++; } } - FUN_020125D4(); + GF_RTC_UpdateOnFrame(); FUN_02015E60(); FUN_020222C4(); FUN_0201B5CC(gMain.unk24); @@ -262,7 +262,7 @@ THUMB_FUNC void FUN_02000F4C(u32 arg0, u32 arg1) DoSoftReset(arg0); } -extern void CopyRtcBuffersTo(struct Unk21C4818 *, struct Unk21C4828 *); +extern void GF_RTC_CopyDateTime(struct Unk21C4818 *, struct Unk21C4828 *); extern void SetMTRNGSeed(u32); extern void SetLCRNGSeed(u32); @@ -270,7 +270,7 @@ THUMB_FUNC void InitializeMainRNG(void) { struct Unk21C4818 spC; struct Unk21C4828 sp0; - CopyRtcBuffersTo(&spC, &sp0); + GF_RTC_CopyDateTime(&spC, &sp0); { u32 r4 = gMain.unk2C; u32 r5 = ((sp0.unk4 + sp0.unk8) << 24) + (spC.unk0 + ((256 * spC.unk4 * spC.unk8) << 16) + (sp0.unk0 << 16)); diff --git a/arm9/src/sav_system_info.c b/arm9/src/sav_system_info.c index cb20bd9b..6b532b8d 100644 --- a/arm9/src/sav_system_info.c +++ b/arm9/src/sav_system_info.c @@ -8,30 +8,30 @@ #pragma thumb on -extern void CopyRtcBuffersTo(RTCDate *, RTCTime *); +extern void GF_RTC_CopyDateTime(RTCDate *, RTCTime *); -u32 FUN_0202376C(void) +u32 Sav2_SysInfo_sizeof(void) { - return sizeof(struct UnkSaveStruct_0202376C); + return sizeof(struct SavSysInfo); } -void FUN_02023770(struct UnkSaveStruct_0202376C * unk) +void Sav2_SysInfo_init(struct SavSysInfo * unk) { - MI_CpuClearFast(unk, sizeof(struct UnkSaveStruct_0202376C)); - FUN_02023840(&unk->rtcInfo); + MI_CpuClearFast(unk, sizeof(struct SavSysInfo)); + Sav2_SysInfo_RTC_init(&unk->rtcInfo); } -struct UnkSaveStruct_0202376C * FUN_02023788(struct SaveBlock2 * sav2) +struct SavSysInfo * Sav2_SysInfo_get(struct SaveBlock2 * sav2) { - return (struct UnkSaveStruct_0202376C *)SavArray_get(sav2, 0); + return (struct SavSysInfo *)SavArray_get(sav2, 0); } -struct UnkSaveStruct_0202376C_sub * FUN_02023794(struct SaveBlock2 * sav2) +struct UnkSaveStruct_0202376C_sub * Sav2_SysInfo_RTC_get(struct SaveBlock2 * sav2) { - return &FUN_02023788(sav2)->rtcInfo; + return &Sav2_SysInfo_get(sav2)->rtcInfo; } -void FUN_020237A0(struct UnkSaveStruct_0202376C * unk) +void Sav2_SysInfo_InitFromSystem(struct SavSysInfo * unk) { OSOwnerInfo info; unk->rtcOffset = OS_GetOwnerRtcOffset(); @@ -41,7 +41,7 @@ void FUN_020237A0(struct UnkSaveStruct_0202376C * unk) unk->birthDay = info.birthday.day; } -BOOL FUN_020237CC(struct UnkSaveStruct_0202376C * unk) +BOOL Sav2_SysInfo_MacAddressIsMine(struct SavSysInfo * unk) { u8 macAddr[6]; OS_GetMacAddress(macAddr); @@ -53,50 +53,49 @@ BOOL FUN_020237CC(struct UnkSaveStruct_0202376C * unk) return TRUE; } -BOOL FUN_020237FC(struct UnkSaveStruct_0202376C * unk) +BOOL Sav2_SysInfo_RTCOffsetIsMine(struct SavSysInfo * unk) { return OS_GetOwnerRtcOffset() == unk->rtcOffset; } -u8 FUN_02023818(struct UnkSaveStruct_0202376C * unk) +u8 Sav2_SysInfo_GetBirthMonth(struct SavSysInfo * unk) { return unk->birthMonth; } -u8 FUN_0202381C(struct UnkSaveStruct_0202376C * unk) +u8 Sav2_SysInfo_GetBirthDay(struct SavSysInfo * unk) { return unk->birthDay; } -u8 FUN_02023820(struct UnkSaveStruct_0202376C * unk) +u8 FUN_02023820(struct SavSysInfo * unk) { return unk->field_48; } -void FUN_02023828(struct UnkSaveStruct_0202376C * unk, u8 val) +void FUN_02023828(struct SavSysInfo * unk, u8 val) { unk->field_48 = val; } -u32 FUN_02023830(struct UnkSaveStruct_0202376C * unk) +u32 FUN_02023830(struct SavSysInfo * unk) { return unk->field_4C; } -void FUN_02023834(struct UnkSaveStruct_0202376C * unk, u32 val) +void FUN_02023834(struct SavSysInfo * unk, u32 val) { if (unk->field_4C == 0) unk->field_4C = val; } -void FUN_02023840(struct UnkSaveStruct_0202376C_sub * sub) +void Sav2_SysInfo_RTC_init(struct UnkSaveStruct_0202376C_sub * sub) { sub->field_00 = 1; - CopyRtcBuffersTo(&sub->date, &sub->time); + GF_RTC_CopyDateTime(&sub->date, &sub->time); sub->daysSinceNitroEpoch = RTC_ConvertDateToDay(&sub->date); sub->secondsSinceNitroEpoch = RTC_ConvertDateTimeToSecond(&sub->date, &sub->time); sub->field_2C = 0; - sub->field_30 = 0; sub->field_34 = 0; } @@ -118,6 +117,6 @@ void FUN_02023884(struct UnkSaveStruct_0202376C_sub * sub, u32 a1) void FUN_020238A4(struct UnkSaveStruct_0202376C_sub * sub) { sub->field_34 = 1440; - CopyRtcBuffersTo(&sub->date, &sub->time); + GF_RTC_CopyDateTime(&sub->date, &sub->time); sub->daysSinceNitroEpoch = RTC_ConvertDateToDay(&sub->date); } diff --git a/arm9/src/save_arrays.c b/arm9/src/save_arrays.c index abd09b1c..58e1ff4c 100644 --- a/arm9/src/save_arrays.c +++ b/arm9/src/save_arrays.c @@ -7,7 +7,7 @@ extern u32 FUN_0202B034(void); extern u32 FUN_0202AC20(void); -extern u32 FUN_0202376C(void); +extern u32 Sav2_SysInfo_sizeof(void); extern u32 FUN_0204BE14(void); extern u32 FUN_02034D7C(void); extern u32 FUN_02023D64(void); @@ -40,7 +40,7 @@ extern u32 FUN_02013B28(void); extern u32 PCStorage_sizeof(void); extern void FUN_0202B03C(void *); extern void FUN_0202AC28(void *); -extern void FUN_02023770(void *); +extern void Sav2_SysInfo_init(void *); extern void FUN_0204BE18(void *); extern void FUN_02034D98(void *); extern void FUN_02024378(void *); @@ -78,7 +78,7 @@ const struct SaveChunkHeader UNK_020EE6E0[] = { }; const struct SaveChunkHeader UNK_020EE700[] = { - { 0, 0, (SAVSIZEFN)FUN_0202376C, (SAVINITFN)FUN_02023770 }, + { 0, 0, (SAVSIZEFN)Sav2_SysInfo_sizeof, (SAVINITFN)Sav2_SysInfo_init }, { 1, 0, (SAVSIZEFN)Sav2_PlayerData_sizeof, (SAVINITFN)Sav2_PlayerData_init }, { 2, 0, (SAVSIZEFN)SavArray_Party_sizeof, (SAVINITFN)SavArray_Party_init }, { 3, 0, (SAVSIZEFN)Sav2_Bag_sizeof, (SAVINITFN)Sav2_Bag_init }, -- cgit v1.2.3