diff options
author | who-knows-who <j.williams97@outlook.com> | 2021-04-17 12:48:19 +0100 |
---|---|---|
committer | who-knows-who <j.williams97@outlook.com> | 2021-04-17 12:48:19 +0100 |
commit | 996d9d78106cf4ab601815550ba77a92ab678328 (patch) | |
tree | 9a92b4f792a11466cdee719b18ed449dee2e27fc /arm9/src | |
parent | 267cb812e827604d4829d3afe28a82b0970d3706 (diff) | |
parent | 85a8a2bd43633e11af094d66a35f3c32dc7c8bfe (diff) |
Merge branch 'master' into 0202A1E0
Diffstat (limited to 'arm9/src')
34 files changed, 6873 insertions, 156 deletions
diff --git a/arm9/src/GX_layers.c b/arm9/src/GX_layers.c new file mode 100644 index 00000000..ce188876 --- /dev/null +++ b/arm9/src/GX_layers.c @@ -0,0 +1,110 @@ +#include "GX_layers.h" + + +struct GX_LayerData layer_data; + +THUMB_FUNC void GX_SetBanks(const struct GraphicsBanks *banks) +{ + GX_ResetBankForBG(); + GX_ResetBankForBGExtPltt(); + GX_ResetBankForSubBG(); + FUN_020C6034(); + GX_ResetBankForOBJ(); + GX_ResetBankForOBJExtPltt(); + FUN_020C605C(); + GX_ResetBankForSubOBJ(); + GX_ResetBankForTex(); + GX_ResetBankForTexPltt(); + + GX_SetBankForBG(banks->bg); + GX_SetBankForBGExtPltt(banks->bgextpltt); + GX_SetBankForSubBG(banks->subbg); + GX_SetBankForSubBGExtPltt(banks->subbgextpltt); + GX_SetBankForOBJ(banks->obj); + GX_SetBankForOBJExtPltt(banks->objextpltt); + GX_SetBankForSubOBJ(banks->subobj); + GX_SetBankForSubOBJExtPltt(banks->subobjextpltt); + GX_SetBankForTex(banks->tex); + GX_SetBankForTexPltt(banks->texpltt); +} + + +THUMB_FUNC void GX_DisableEngineALayers() +{ + layer_data.EngineA_DISPCNT_LayerMask = 0; +} + +THUMB_FUNC void GX_EngineAToggleLayers(u32 layer_mask, GX_LayerToggle layer_toggle) +{ + if (layer_toggle == GX_LAYER_TOGGLE_ON) + { + if ((layer_data.EngineA_DISPCNT_LayerMask & layer_mask) != 0) + { + return; + } + } + else + { + if ((layer_data.EngineA_DISPCNT_LayerMask & layer_mask) == 0) + { + return; + } + } + + reg_GX_DISPCNT = (reg_GX_DISPCNT & 0xFFFFE0FF) | (layer_data.EngineA_DISPCNT_LayerMask ^= layer_mask) << 8; +} + +THUMB_FUNC void GX_SetEngineALayers(u32 layer_mask) +{ + layer_data.EngineA_DISPCNT_LayerMask = layer_mask; + reg_GX_DISPCNT = (reg_GX_DISPCNT & 0xFFFFE0FF) | layer_mask << 8; +} + +THUMB_FUNC void GX_DisableEngineBLayers() +{ + layer_data.EngineB_DISPCNT_LayerMask = 0; +} + +THUMB_FUNC void GX_EngineBToggleLayers(u32 layer_mask, GX_LayerToggle layer_toggle) +{ + if (layer_toggle == GX_LAYER_TOGGLE_ON) + { + if ((layer_data.EngineB_DISPCNT_LayerMask & layer_mask) != 0) + { + return; + } + } + else + { + if ((layer_data.EngineB_DISPCNT_LayerMask & layer_mask) == 0) + { + return; + } + } + + reg_GXS_DB_DISPCNT = (reg_GXS_DB_DISPCNT & 0xFFFFE0FF) | (layer_data.EngineB_DISPCNT_LayerMask ^= layer_mask) << 8; +} + +THUMB_FUNC void GX_BothDispOn() +{ + GX_DispOn(); + + reg_GXS_DB_DISPCNT |= 0x10000; +} + +THUMB_FUNC void GX_SwapDisplay() +{ + if (gMain.unk65 == 0) + { + reg_GX_POWCNT |= 0x8000; //send display A to lower screen + } + else + { + reg_GX_POWCNT &= 0xFFFF7FFF; // sned display A to upper screen + } +} + +THUMB_FUNC u32 GX_GetEngineALayers() +{ + return layer_data.EngineA_DISPCNT_LayerMask; +} diff --git a/arm9/src/error_handling.c b/arm9/src/error_handling.c index 9052773f..a01894f6 100644 --- a/arm9/src/error_handling.c +++ b/arm9/src/error_handling.c @@ -1,8 +1,8 @@ #include "global.h" #include "error_handling.h" +#include "error_message_reset.h" extern u32 FUN_02031810(void); -extern void PrintErrorMessageAndReset(void); THUMB_FUNC void ErrorHandling(void) { diff --git a/arm9/src/error_message_reset.c b/arm9/src/error_message_reset.c new file mode 100644 index 00000000..3a727924 --- /dev/null +++ b/arm9/src/error_message_reset.c @@ -0,0 +1,142 @@ +#include "error_message_reset.h" +#include "GX_layers.h" + +const u32 UNK_020FF49C[2] = { 0x1a030300, 0x00230112 }; + +const u32 UNK_020FF4A4[2] = { 0x00020000, 0x00000000 }; + +const struct GraphicsModes UNK_020FF4AC = { mode1 : 1 }; + +const u32 UNK_020FF4BC[7] = { 0x00, 0x00, 0x0800, 0x00, 0x06000001, 0x0100, 0x00 }; + +const struct GraphicsBanks UNK_020FF4D8 = { bg : 3 }; + +u32 sErrorMessagePrinterLock; + +extern void FUN_0200E3A0(PMLCDTarget, int); +extern u32 *FUN_02016B94(u32 param0); +extern void FUN_02016BBC(const struct GraphicsModes *modes); +extern void FUN_02016C18(u32 *param0, u32 param1, void *param2, u32 param3); +extern void FUN_02018744(u32 *param0, u32 param1); +extern void FUN_0200CB00(u32 *param0, u32 param1, u32 param2, u32 param3, u8 param4, u32 param5); +extern void FUN_02002ED0(u32 param0, u32 param1, u32 param2); +extern void FUN_02017F18(u32 param0, u32 param1, u32 param2, u32 param3); +extern void FUN_02017FE4(u32 param0, u32 param1); +extern void FUN_02019150(u32 *param0, u32 *param1, const u32 *param2); +extern void FUN_020196F4(u32 *, u8, u16, u16, u16, u16); +extern void FUN_0200CCA4(u32 *param0, u32 param1, u32 param2, u32 param3); +extern void FUN_0200E394(u32 param0); +extern void FUN_0200A274(u32 param0, u32 param1, u32 param2); +extern BOOL FUN_02032DAC(void); +extern BOOL FUN_0202FB80(void); +extern BOOL FUN_02033678(void); +extern void FUN_02019178(u32 *param0); + +THUMB_FUNC void VBlankHandler() +{ + *(vu32 *)HW_INTR_CHECK_BUF |= 1; + + MI_WaitDma(3); +} + +THUMB_FUNC void PrintErrorMessageAndReset() +{ + + u32 *ptr; + u32 buf[4]; + + if (sErrorMessagePrinterLock != 1) + { + sErrorMessagePrinterLock = 1; + OS_SetArenaHi(OS_ARENA_MAIN, OS_GetInitArenaHi(OS_ARENA_MAIN)); + OS_SetArenaLo(OS_ARENA_MAIN, OS_GetInitArenaLo(OS_ARENA_MAIN)); + + FUN_020166C8((u32 *)UNK_020FF4A4, 1, 1, 0); + FUN_0200E3A0(PM_LCD_TOP, 0); + FUN_0200E3A0(PM_LCD_BOTTOM, 0); + + OS_DisableIrqMask(1); + OS_SetIrqFunction(1, &VBlankHandler); + OS_EnableIrqMask(1); + + Main_SetVBlankIntrCB(NULL, NULL); + + FUN_02015F34(NULL, NULL); + GX_DisableEngineALayers(); + GX_DisableEngineBLayers(); + + reg_GX_DISPCNT &= 0xFFFFE0FF; + reg_GXS_DB_DISPCNT &= 0xFFFFE0FF; + + FUN_0201669C(4, 8); + + gMain.unk65 = 0; + GX_SwapDisplay(); + + reg_G2_BLDCNT = 0; + reg_G2S_DB_BLDCNT = 0; + reg_GX_DISPCNT &= 0xFFFF1FFF; + reg_GXS_DB_DISPCNT &= 0xFFFF1FFF; + + GX_SetBanks(&UNK_020FF4D8); + ptr = FUN_02016B94(0); + FUN_02016BBC(&UNK_020FF4AC); + + FUN_02016C18(ptr, 0, UNK_020FF4BC, 0); + FUN_02018744(ptr, 0); + + FUN_0200CB00(ptr, 0, 503, 2, 0, 0); + + FUN_02002ED0(0, 0x20, 0); + FUN_02017F18(0, 0x20, 0, 0); + FUN_02017FE4(0, 0x6C21); + FUN_02017FE4(4, 0x6C21); + + struct MsgData *msg_data = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 0xc8, 0); + struct String *str = String_ctor(6 << 6, 0); + + FUN_0201BD5C(); + FUN_02019150(ptr, buf, UNK_020FF49C); + FUN_020196F4(buf, 15, 0, 0, 0xd0, 0x90); + FUN_0200CCA4(buf, 0, 0x1f7, 2); + + ReadMsgDataIntoString(msg_data, 3, str); + + AddTextPrinterParameterized((u32)buf, 0, (const u16 *)str, 0, 0, 0, NULL); // wtf + + String_dtor(str); + GX_BothDispOn(); + FUN_0200E394(0); + FUN_0200E394(1); + FUN_0200A274(0, 0x3f, 3); + FUN_02032DAC(); + + lid: + HandleDSLidAction(); + FUN_0202FB80(); + if (!FUN_02033678()) + { + OS_WaitIrq(1, 1); + goto lid; + } + + + lid2: + HandleDSLidAction(); + if (!((u16)(((reg_PAD_KEYINPUT | *(vu16 *)HW_BUTTON_XY_BUF) ^ 0x2FFF) & 0x2FFF) & 1)) + { + OS_WaitIrq(1, 1); + goto lid2; + } + + FUN_0200E3A0(PM_LCD_TOP, 0x7FFF); + FUN_0200E3A0(PM_LCD_BOTTOM, 0x7FFF); + + FUN_02019178(buf); + + DestroyMsgData(msg_data); + FreeToHeap(ptr); + + OS_ResetSystem(0); + } +} diff --git a/arm9/src/game_init.c b/arm9/src/game_init.c index 327c66c6..a7508fab 100644 --- a/arm9/src/game_init.c +++ b/arm9/src/game_init.c @@ -4,16 +4,15 @@ #include "main.h" #include "FS_rom.h" #include "PAD_pad.h" -#include "heap.h" #include "MWC_string.h" #include "tp.h" #include "unk_0201B4E8.h" #include "game_init.h" #include "registers.h" +#include "heap.h" #pragma thumb on -extern void FUN_020166C8(const u32 (*)[2], int, int, int); extern void FUN_02022450(void); typedef volatile struct @@ -142,7 +141,7 @@ void FUN_02015FC8(void) { csum++; } - FUN_020166C8(UNK_020EDB10, 4, 92, (int)csum); + FUN_020166C8((u32 *)UNK_020EDB10, 4, 92, (int)csum); } void InitSystemForTheGame(void) diff --git a/arm9/src/heap.c b/arm9/src/heap.c new file mode 100644 index 00000000..84abc834 --- /dev/null +++ b/arm9/src/heap.c @@ -0,0 +1,380 @@ +#include "heap.h" +#include "error_message_reset.h" + +extern void *tempName_NNS_FndCreateExpHeapEx(void *param0, u32 param1, u32 param2); +extern void *tempName_NNS_FndAllocFromExpHeapEx(void *param0, u32 param1, s32 param2); +extern void thunk_FUN_020adc8c(); +extern void FUN_020ADDF0(void *ptr1, void *ptr2); +extern u32 FUN_02031810(void); +extern u32 FUN_020ADDC8(void *param0); +extern void FUN_020AE82C(u32 param0, void *param1, u32 param2); +extern u32 FUN_020ADDC0(void *param0); +extern void FUN_020ADE2C(void *ptr1, void *ptr2, u32 param2); + + +struct UnkStruct_020166C8 UNK_021C4D28; + + +THUMB_FUNC void FUN_020166C8(u32 *param0, u32 param1, u32 param2, u32 pre_size) +{ + u32 unk_size = param1 + 24; + + if (param2 < unk_size) + { + param2 = unk_size; + } + if (pre_size != 0) + { + while (pre_size % 4 != 0) + { + pre_size++; + } + + OS_AllocFromArenaLo(OS_ARENA_MAIN, pre_size, 4); + } + + u32 r7 = param2 * 2; + + void *ptr = OS_AllocFromArenaLo(OS_ARENA_MAIN, (unk_size * 3 + 1) * sizeof(u32) + r7 + param2, 4); + UNK_021C4D28.unk00 = ptr; + ptr += (unk_size + 1) * 4; + UNK_021C4D28.unk04 = ptr; + ptr += unk_size * 4; + UNK_021C4D28.unk08 = ptr; + ptr += unk_size * 4; + UNK_021C4D28.unk0c = ptr; + ptr += r7; + UNK_021C4D28.unk10 = ptr; + UNK_021C4D28.unk14 = (u16)param2; + UNK_021C4D28.unk16 = (u16)param1; + + r7 = 0; + UNK_021C4D28.unk1a = (u16)unk_size; + UNK_021C4D28.unk18 = (u16)unk_size; + + while (r7 < param1) + { + void *ptr; + if (param0[1] == 0 || param0[1] != 2) + { + ptr = OS_AllocFromArenaLo(OS_ARENA_MAIN, param0[0], 4); + } + else + { + ptr = OS_AllocFromArenaHi(OS_ARENA_MAINEX, param0[0], 4); + } + + if (ptr != 0) + { + + UNK_021C4D28.unk00[r7] = tempName_NNS_FndCreateExpHeapEx(ptr, param0[0], 0); + UNK_021C4D28.unk10[r7] = (u8)r7; + } + else + { + ErrorHandling(); + } + + param0 += 2; + r7++; + } + + while (param1 < unk_size + 1) + { + UNK_021C4D28.unk00[param1] = 0; + UNK_021C4D28.unk10[param1] = (u8)UNK_021C4D28.unk1a; + + param1++; + } + + while (param1 < param2) + { + UNK_021C4D28.unk10[param1] = (u8)UNK_021C4D28.unk1a; + + param1++; + } + + for (param1 = 0; param1 < param2; param1++) + { + UNK_021C4D28.unk0c[param1] = 0; + } +} + +THUMB_FUNC s32 FUN_020167F4() +{ + s32 i = UNK_021C4D28.unk16; + s32 j = UNK_021C4D28.unk18; + + if (i < j) + { + void **ptr = UNK_021C4D28.unk00 + i; + do + { + if (*ptr == 0) + { + return i; + } + i++; + ptr++; + } while (i < j); + } + + return -1; +} + +THUMB_FUNC u32 FUN_0201681C(u32 param0, u32 param1, u32 param2) +{ + return FUN_02016834(param0, param1, param2, 4); +} + +THUMB_FUNC u32 FUN_02016828(u32 param0, u32 param1, u32 param2) +{ + return FUN_02016834(param0, param1, param2, -4); +} + +THUMB_FUNC u32 FUN_02016834(u32 param0, u32 param1, u32 param2, s32 param3) +{ + GF_ASSERT(OS_GetProcMode() != OS_PROCMODE_IRQ); + + u8 *ptr = UNK_021C4D28.unk10; + if (UNK_021C4D28.unk1a == ptr[param1]) + { + void *ptr2 = UNK_021C4D28.unk00[ptr[param0]]; + if (ptr2 != 0) + { + void *ptr3 = tempName_NNS_FndAllocFromExpHeapEx(ptr2, param2, param3); + if (ptr3 != 0) + { + param3 = FUN_020167F4(); + if (param3 >= 0) + { + UNK_021C4D28.unk00[param3] = tempName_NNS_FndCreateExpHeapEx(ptr3, param2, 0); + + + if (UNK_021C4D28.unk00[param3] != 0) + { + UNK_021C4D28.unk04[param3] = ptr2; + UNK_021C4D28.unk08[param3] = ptr3; + UNK_021C4D28.unk10[param1] = (u8)param3; + + return 1; + } + else + { + ErrorHandling(); + } + } + else + { + ErrorHandling(); + } + } + else + { + ErrorHandling(); + } + } + else + { + ErrorHandling(); + } + } + else + { + ErrorHandling(); + } + return 0; +} + +THUMB_FUNC void FUN_020168D0(u32 heap_id) +{ + GF_ASSERT (OS_GetProcMode() != OS_PROCMODE_IRQ); + + if (UNK_021C4D28.unk00[UNK_021C4D28.unk10[heap_id]] != 0) + { + thunk_FUN_020adc8c(); + + u8 index = UNK_021C4D28.unk10[heap_id]; + void *ptr1 = UNK_021C4D28.unk04[index]; + void *ptr2 = UNK_021C4D28.unk08[index]; + if (ptr1 != 0 && ptr2 != 0) + { + FUN_020ADDF0(ptr1, ptr2); + } + else + { + ErrorHandling(); + } + + UNK_021C4D28.unk00[UNK_021C4D28.unk10[heap_id]] = 0; + UNK_021C4D28.unk04[UNK_021C4D28.unk10[heap_id]] = 0; + UNK_021C4D28.unk08[UNK_021C4D28.unk10[heap_id]] = 0; + + UNK_021C4D28.unk10[heap_id] = (u8)UNK_021C4D28.unk1a; + } +} + +THUMB_FUNC u32 *FUN_02016944(void *param0, u32 param1, s32 param2, u32 param3) +{ + GF_ASSERT(param0); + + OSIntrMode intr_mode = OS_DisableInterrupts(); + param1 += 16; + u32 *ptr = (u32 *)tempName_NNS_FndAllocFromExpHeapEx(param0, param1, param2); + + OS_RestoreInterrupts(intr_mode); + if (ptr != 0) + { + ptr[3] = (ptr[3] & ~0xff) | (param3 & 0xff); + + ptr += 4; + } + + return ptr; +} + +THUMB_FUNC void FUN_02016988() +{ + if (FUN_02031810() != 0) + { + PrintErrorMessageAndReset(); + } +} + +void *AllocFromHeap(u32 heap_id, u32 size) +{ + void *ptr = 0; + if (heap_id < UNK_021C4D28.unk14) + { + u8 index = UNK_021C4D28.unk10[heap_id]; + ptr = FUN_02016944(UNK_021C4D28.unk00[index], size, 4, heap_id); + } + if (ptr != 0) + { + UNK_021C4D28.unk0c[heap_id]++; + } + else + { + FUN_02016988(); + } + + return ptr; +} + +void *AllocFromHeapAtEnd(u32 heap_id, u32 size) +{ + void *ptr = 0; + if (heap_id < UNK_021C4D28.unk14) + { + u8 index = UNK_021C4D28.unk10[heap_id]; + ptr = FUN_02016944(UNK_021C4D28.unk00[index], size, -4, heap_id); + } + + if (ptr != 0) + { + UNK_021C4D28.unk0c[heap_id]++; + } + else + { + FUN_02016988(); + } + + return ptr; +} + +void FreeToHeap(void *ptr) +{ + u8 heap_id = (u8)((u32 *)ptr)[-1]; + + if ((u16)heap_id < UNK_021C4D28.unk14) + { + u8 index = UNK_021C4D28.unk10[heap_id]; + void *ptr2 = UNK_021C4D28.unk00[index]; + GF_ASSERT(ptr2); + + if (UNK_021C4D28.unk0c[heap_id] == 0) + { + FUN_02016B90(heap_id); + } + GF_ASSERT(UNK_021C4D28.unk0c[heap_id]); + + UNK_021C4D28.unk0c[heap_id]--; + OSIntrMode intr_mode = OS_DisableInterrupts(); + FUN_020ADDF0(ptr2, ptr - 16); + OS_RestoreInterrupts(intr_mode); + return; + } + + ErrorHandling(); +} + +void FUN_02016A8C(u32 param0, void *param1) +{ + GF_ASSERT (OS_GetProcMode() != OS_PROCMODE_IRQ); + + if (param0 < UNK_021C4D28.unk14) + { + u8 index = UNK_021C4D28.unk10[param0]; + void *ptr = UNK_021C4D28.unk00[index]; + GF_ASSERT (ptr ); + + u8 heap_id = (u8)((u32 *)param1)[-1]; + GF_ASSERT (heap_id == param0); + + FUN_020ADDF0(ptr, param1 - 16); + GF_ASSERT (UNK_021C4D28.unk0c[param0]); + + UNK_021C4D28.unk0c[param0]--; + return; + } + + ErrorHandling(); +} + +THUMB_FUNC u32 FUN_02016AF8(u32 param0) +{ + if (param0 < UNK_021C4D28.unk14) + { + u8 index = UNK_021C4D28.unk10[param0]; + return FUN_020ADDC8(UNK_021C4D28.unk00[index]); + } + + ErrorHandling(); + return 0; +} + +THUMB_FUNC void FUN_02016B20(u32 param0, u32 param1, u32 param2) +{ + if (param1 < UNK_021C4D28.unk14) + { + + u8 index = UNK_021C4D28.unk10[param1]; + FUN_020AE82C(param0, UNK_021C4D28.unk00[index], param2); + return; + } + + ErrorHandling(); +} + +THUMB_FUNC void FUN_02016B44(void *ptr, u32 param1) +{ + GF_ASSERT (OS_GetProcMode() != OS_PROCMODE_IRQ); + + param1 += 16; + if (FUN_020ADDC0(ptr - 16) >= param1) + { + u8 heap_id = (u8)((u32 *)ptr)[-1]; + + u8 index = UNK_021C4D28.unk10[heap_id]; + + FUN_020ADE2C(UNK_021C4D28.unk00[index], ptr - 16, param1); + return; + } + ErrorHandling(); +} + +THUMB_FUNC u32 FUN_02016B90(u32 param0) +{ +#pragma unused(param0) + return 1; +} diff --git a/arm9/src/main.c b/arm9/src/main.c index 86f0f6af..c50fbaff 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -11,6 +11,7 @@ #include "poke_overlay.h" #include "player_data.h" #include "sound.h" +#include "timer3.h" FS_EXTERN_OVERLAY(MODULE_52); FS_EXTERN_OVERLAY(MODULE_63); @@ -34,7 +35,6 @@ extern void FUN_02002C14(void); extern void FUN_02002C50(int, int); extern struct SaveBlock2 * SaveBlock2_new(void); extern void * FUN_02029EF8(struct SaveBlock2 *); -extern void FUN_02020AFC(void); extern int FUN_020337E8(int); extern void FUN_02034188(int, int); extern int FUN_020227FC(struct SaveBlock2 *); @@ -75,7 +75,7 @@ THUMB_FUNC void NitroMain(void) gBacklightTop.unk18 = -1; gBacklightTop.unk20 = SaveBlock2_new(); InitSoundData(FUN_02029EF8(gBacklightTop.unk20), Sav2_PlayerData_GetOptionsAddr(gBacklightTop.unk20)); - FUN_02020AFC(); + Init_Timer3(); if (FUN_020337E8(3) == 3) FUN_02034188(3, 0); if (FUN_020227FC(gBacklightTop.unk20) == 0) diff --git a/arm9/src/map_header.c b/arm9/src/map_header.c index 0a5b8987..644a590b 100644 --- a/arm9/src/map_header.c +++ b/arm9/src/map_header.c @@ -605,23 +605,23 @@ u32 MapNumberBoundsCheck(u32 mapno) return mapno; } -u8 FUN_02034724(u32 mapno) +u8 MapHeader_GetAreaDataBank(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk0; + return sMapHeaders[mapno].area_data_bank; } -u8 FUN_02034738(u32 mapno) +u8 MapHeader_GetField1(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); return sMapHeaders[mapno].unk1; } -u16 FUN_0203474C(u32 mapno) +u16 MapHeader_GetMatrixId(u32 mapno) { u16 ret; mapno = MapNumberBoundsCheck(mapno); - ret = sMapHeaders[mapno].unk2; + ret = sMapHeaders[mapno].matrix_id; // Spear Pillar if (ret == 22 && gGameVersion == VERSION_PEARL) ret = 23; @@ -631,94 +631,94 @@ u16 FUN_0203474C(u32 mapno) u16 MapHeader_GetMsgBank(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk8; + return sMapHeaders[mapno].msg_bank; } -u16 MapHeader_GetScrSeqReleaseNo(u32 mapno) +u16 MapHeader_GetScriptsBank(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk4; + return sMapHeaders[mapno].scripts_bank; } -u16 FUN_0203479C(u32 mapno) +u16 MapHeader_GetLevelScriptsBank(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk6; + return sMapHeaders[mapno].level_scripts_bank; } -u16 FUN_020347B0(u32 mapno) +u16 MapHeader_GetDayMusicId(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unkA; + return sMapHeaders[mapno].day_music_id; } -u16 FUN_020347C4(u32 mapno) +u16 MapHeader_GetNightMusicId(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unkC; + return sMapHeaders[mapno].night_music_id; } -BOOL FUN_020347D8(u32 mapno) +BOOL MapHeader_HasWildEncounters(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unkE != 0xFFFF; + return sMapHeaders[mapno].wild_encounter_bank != 0xFFFF; } -u16 FUN_020347FC(u32 mapno) +u16 MapHeader_GetWildEncounterBank(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unkE; + return sMapHeaders[mapno].wild_encounter_bank; } -u16 FUN_02034810(u32 mapno) +u16 MapHeader_GetEventsBank(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk10; + return sMapHeaders[mapno].events_bank; } -u16 FUN_02034824(u32 mapno) +u16 MapHeader_GetMapSec(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); return sMapHeaders[mapno].mapsec; } -u8 FUN_02034838(u32 mapno) +u8 MapHeader_GetWeatherType(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk14; + return sMapHeaders[mapno].weather_type; } -u8 FUN_0203484C(u32 mapno) +u8 MapHeader_GetCameraType(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk15; + return sMapHeaders[mapno].camera_type; } -u8 FUN_02034860(u32 mapno) +u8 MapHeader_GetField17_0(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); return sMapHeaders[mapno].unk17_0; } -u8 FUN_0203487C(u32 mapno) +u8 MapHeader_GetField17_6(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); return sMapHeaders[mapno].unk17_6; } -u8 FUN_02034898(u32 mapno) +u8 MapHeader_IsFlyAllowed(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk17_7; + return sMapHeaders[mapno].is_fly_allowed; } -u8 FUN_020348B4(u32 mapno) +u8 MapHeader_IsBikeAllowed(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); - return sMapHeaders[mapno].unk17_4; + return sMapHeaders[mapno].is_bike_allowed; } -u8 FUN_020348D0(u32 mapno) +u8 MapHeader_GetField16(u32 mapno) { mapno = MapNumberBoundsCheck(mapno); return sMapHeaders[mapno].unk16; @@ -726,36 +726,36 @@ u8 FUN_020348D0(u32 mapno) BOOL FUN_020348E4(u32 mapno) { - if (!FUN_02034898(mapno)) + if (!MapHeader_IsFlyAllowed(mapno)) return FALSE; - if (FUN_020348D0(mapno) != 1) + if (MapHeader_GetField16(mapno) != 1) return TRUE; return FALSE; } -BOOL FUN_02034908(u32 mapno) +BOOL MapHeader_MapIsOnOverworldMatrix(u32 mapno) { - return !FUN_0203474C(mapno); + return MapHeader_GetMatrixId(mapno) == 0; } BOOL FUN_0203491C(u32 mapno) { - return FUN_020348D0(mapno) == 5; + return MapHeader_GetField16(mapno) == 5; } BOOL FUN_02034930(u32 mapno) { - return FUN_020348D0(mapno) == 3; + return MapHeader_GetField16(mapno) == 3; } BOOL FUN_02034944(u32 mapno) { - return FUN_020348D0(mapno) == 4 || FUN_020348D0(mapno) == 5; + return MapHeader_GetField16(mapno) == 4 || MapHeader_GetField16(mapno) == 5; } BOOL FUN_02034964(u32 mapno) { - return FUN_020348D0(mapno) == 1 || FUN_020348D0(mapno) == 2; + return MapHeader_GetField16(mapno) == 1 || MapHeader_GetField16(mapno) == 2; } BOOL FUN_02034984(u32 mapno) diff --git a/arm9/src/save_arrays.c b/arm9/src/save_arrays.c index 397f1f69..8520f2c1 100644 --- a/arm9/src/save_arrays.c +++ b/arm9/src/save_arrays.c @@ -14,10 +14,10 @@ #include "pokedex.h" #include "seal.h" #include "unk_020139D8.h" +#include "unk_02024E64.h" extern u32 FUN_0202AC20(void); extern u32 FUN_02034D7C(void); -extern u32 FUN_02024E64(void); extern u32 FUN_02034D80(void); extern u32 FUN_02025954(void); extern u32 FUN_02023AC8(void); @@ -39,7 +39,6 @@ extern u32 FUN_0202BE98(void); extern u32 FUN_0202C0E0(void); extern void FUN_0202AC28(void *); extern void FUN_02034D98(void *); -extern void FUN_02024E6C(void *); extern void FUN_02034D88(void *); extern void FUN_0202597C(void *); extern void FUN_02023AD8(void *); diff --git a/arm9/src/scrcmd.c b/arm9/src/scrcmd.c new file mode 100644 index 00000000..4ad17e51 --- /dev/null +++ b/arm9/src/scrcmd.c @@ -0,0 +1,1300 @@ +#include "scrcmd.h" +#include "unk_0204639C.h" +#include "main.h" +#include "options.h" +#include "player_data.h" +#include "text.h" + +extern void *FUN_02039438(struct UnkSavStruct80* arg, u32 id); +extern void *CreateScriptContext(struct UnkSavStruct80* arg, u16 id); +extern u8 FUN_02058448(u32 param0); +extern void FlagSet(struct UnkSavStruct80 *arg, u16 flag); +extern void FlagClear(struct UnkSavStruct80 *arg, u16 flag); +extern u8 FlagCheck(struct UnkSavStruct80 *arg, u16 flag); +extern void TrainerFlagSet(struct UnkSavStruct80 *arg, u16 flag); +extern void TrainerFlagClear(struct UnkSavStruct80 *arg, u16 flag); +extern u8 TrainerFlagCheck(struct UnkSavStruct80 *arg, u16 flag); +extern void MOD05_ShowMessageInField(struct ScriptContext *ctx, struct MsgData *msgData, u16 id); +extern void MOD05_021E2BD0(struct ScriptContext *ctx, struct MsgData *msgData, u16 msgId, u32 param4, void *param5); +extern void MOD05_021E2C58(struct ScriptContext *ctx, u16 typ, u16 id, u16 word1, s16 word2, u8 param5); +extern struct ScrStrBufs *MOD06_02244210(struct SaveBlock2 *sav, u16 poke, u16 sex, u8 flag, u8 *unk); +extern void MOD05_021E2CBC(struct ScriptContext *ctx, struct ScrStrBufs *str, u8 param2, u32 param3); +extern void MOD05_021E2BB8(void *param0, struct ScriptContext *ctx); +extern BOOL FUN_020546C8(u8 param0); +extern u32 FUN_02058488(u32 param0); +extern BOOL FUN_02030F40(void); +extern void FUN_02055304(u32 param0, u32 param1); +extern void FUN_02039460(struct UnkSavStruct80 *arg); +extern void FUN_020545B8(u32 param0, u8 *param1, u32 param2); +extern void FUN_02054608(u8 *param0, struct Options *options); +extern void FUN_0200D0E0(u32 *param0, u32 param1); +extern void FUN_02019178(u32 *param0); +extern void FUN_020179E0(u32 param0, u32 param1, u32 param2, u16 val); +extern u32 FUN_02058510(u32 param0, u32 param1); +extern void MOD05_021E8128(u32 param0, u8 type, u16 map); +extern void MOD05_021E8130(u32 param0, u32 param1); +extern void MOD05_021E8158(struct UnkSavStruct80 *unk80); +extern u32 MOD05_021E8140(u32 param0); +extern BOOL MOD05_021E8148(u32 param0); +extern u8 FUN_02054658(u32 param0, struct String *str, struct Options *opt, u32 param3); +extern void MOD05_021E8144(u32 param0); +extern void FUN_0200CB00(u32 param0, u32 param1, u32 param2, u32 param3, u32 param4, u32 param5); +extern u32 Std_CreateYesNoMenu(u32 param0, u8 **param1, u32 param2, u32 param3, u32 param4); +extern u32 FUN_020021AC(u32 param0, u32 param1); +extern u32 FUN_0200D858(u32 *param0, u32 param1); +extern void FUN_0200DBFC(u32 param0); +extern u32 MOD05_021E1BF8(struct UnkSavStruct80 *arg, u8 param1, u8 param2, u8 param3, u8 param4, u16 *param5, u32 param6, u32 *param7, struct MsgData *msgData); +extern void MOD05_021E1C4C(u32 param0, u32 param1, u32 param2); +extern void MOD05_021E1C54(u32 param0); +extern u32 FUN_02052714(u32 param0); +extern void MOD05_021E1ECC(u32 param0); +extern u32 MOD05_021E1F34(struct UnkSavStruct80 *arg, u8 param1, u8 param2, u8 param3, u8 param4, u16 *param5, u32 param6, u32 *param7, struct MsgData *msgData); +extern void MOD05_021E1F58(u32 param0, u8 param1, u8 param2, u8 param3); +extern void MOD05_021E1F60(u32 param0); +extern void MOD05_021E26CC(u32 param0, u8 param1); +extern void MOD05_021E2B80(u32 param0, u8 param1); +extern void MOD05_021E2B9C(u32 param0, u8 param1); + +extern u8 *UNK_020F34E0; + +static BOOL RunPauseTimer(struct ScriptContext *ctx); +static u32 Compare(u16 a, u16 b); +static BOOL FUN_02039CC8(struct ScriptContext *ctx); +/*static*/ BOOL FUN_0203A2F0(struct ScriptContext *ctx); +static BOOL FUN_0203A46C(struct ScriptContext *ctx); +static BOOL FUN_0203A4AC(struct ScriptContext *ctx); +static BOOL FUN_0203A4E0(struct ScriptContext *ctx); +static BOOL FUN_0203A570(struct ScriptContext *ctx); +static BOOL FUN_0203A6C8(struct ScriptContext *ctx); +static BOOL FUN_0203A8A0(struct ScriptContext *ctx); +static BOOL FUN_0203A94C(struct ScriptContext *ctx); +static BOOL FUN_0203AA0C(struct ScriptContext *ctx); +static BOOL FUN_0203AB00(struct ScriptContext *ctx); +static BOOL FUN_0203AD2C(struct ScriptContext *ctx); +static BOOL FUN_0203AD78(struct ScriptContext *ctx); + +extern u8 sScriptConditionTable[6][3]; + +THUMB_FUNC BOOL ScrCmd_Nop(struct ScriptContext *ctx) +{ +#pragma unused(ctx) + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Dummy(struct ScriptContext *ctx) +{ +#pragma unused(ctx) + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_End(struct ScriptContext *ctx) +{ + StopScript(ctx); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Wait(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *arg = ctx->unk80; + u16 num = ScriptReadHalfword(ctx); + u16 wk = ScriptReadHalfword(ctx); + u16* VarPointer = GetVarPointer(arg, wk); + *VarPointer = num; + ctx->data[0] = wk; + SetupNativeScript(ctx, RunPauseTimer); + return TRUE; +} + +THUMB_FUNC static BOOL RunPauseTimer(struct ScriptContext *ctx) +{ + u16* VarPointer = GetVarPointer(ctx->unk80, (u16)ctx->data[0]); + *VarPointer = (u16)(*VarPointer - 1); + return !(*VarPointer); +} + +THUMB_FUNC BOOL ScrCmd_DebugWatch(struct ScriptContext *ctx) +{ + u16 wk = ScriptReadHalfword(ctx); + VarGet(ctx->unk80, wk); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_LoadByte(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + ctx->data[index] = ScriptReadByte(ctx); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_LoadWord(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + ctx->data[index] = ScriptReadWord(ctx); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_LoadByteFromAddr(struct ScriptContext *ctx) +{ + u8 index = ScriptReadByte(ctx); + ctx->data[index] = *(u8 *)ScriptReadWord(ctx); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_WriteByteToAddr(struct ScriptContext *ctx) +{ + u8* ptr = (u8*)ScriptReadWord(ctx); + *ptr = ScriptReadByte(ctx); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_SetPtrByte(struct ScriptContext *ctx) +{ + u8* ptr = (u8*)ScriptReadWord(ctx); + *ptr = (u8)ctx->data[ScriptReadByte(ctx)]; + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CopyLocal(struct ScriptContext *ctx) +{ + u8 index_store = ScriptReadByte(ctx); + u8 index_load = ScriptReadByte(ctx); + ctx->data[index_store] = ctx->data[index_load]; + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CopyByte(struct ScriptContext *ctx) +{ + u8 *target = (u8 *)ScriptReadWord(ctx); + u8 *source = (u8 *)ScriptReadWord(ctx); + *target = *source; + return FALSE; +} + +THUMB_FUNC static u32 Compare(u16 a, u16 b) +{ + if (a < b) + { + return 0; + } + else if (a == b) + { + return 1; + } + else + { + return 2; + } +} + +THUMB_FUNC BOOL ScrCmd_CompareLocalToLocal(struct ScriptContext *ctx) +{ + u8 a = (u8)ctx->data[ScriptReadByte(ctx)]; + u8 b = (u8)ctx->data[ScriptReadByte(ctx)]; + ctx->comparisonResult = (u8)Compare(a, b); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CompareLocalToValue(struct ScriptContext *ctx) +{ + u8 a = (u8)ctx->data[ScriptReadByte(ctx)]; + u8 b = ScriptReadByte(ctx); + ctx->comparisonResult = (u8)Compare(a, b); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CompareLocalToAddr(struct ScriptContext *ctx) +{ + u8 a = (u8)ctx->data[ScriptReadByte(ctx)]; + u8 b = *(u8*)ScriptReadWord(ctx); + ctx->comparisonResult = (u8)Compare(a, b); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CompareAddrToLocal(struct ScriptContext *ctx) +{ + u8 a = *(u8*)ScriptReadWord(ctx); + u8 b = (u8)ctx->data[ScriptReadByte(ctx)]; + ctx->comparisonResult = (u8)Compare(a, b); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CompareAddrToValue(struct ScriptContext *ctx) +{ + u8 a = *(u8*)ScriptReadWord(ctx); + u8 b = (u8)ScriptReadByte(ctx); + ctx->comparisonResult = (u8)Compare(a, b); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CompareAddrToAddr(struct ScriptContext *ctx) +{ + u8 a = *(u8*)ScriptReadWord(ctx); + u8 b = *(u8*)ScriptReadWord(ctx); + ctx->comparisonResult = (u8)Compare(a, b); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CompareVarToValue(struct ScriptContext *ctx) +{ + u16 a = *GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 b = ScriptReadHalfword(ctx); + ctx->comparisonResult = (u8)Compare(a, b); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CompareVarToVar(struct ScriptContext *ctx) +{ + u16 *a = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 *b = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + ctx->comparisonResult = (u8)Compare(*a, *b); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_RunScript(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u8 *unk1 = (u8 *)FUN_02039438(unk80, 0x7); + u32 **unk2 = (u32 **)FUN_02039438(unk80, 0xe); + u16 id = ScriptReadHalfword(ctx); + + *unk2 = CreateScriptContext(unk80, id); + *unk1 = (u8)(*unk1 + 1); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_RunScriptWait(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u8 *unk1 = (u8 *)FUN_02039438(unk80, 0x5); + u8 *unk2 = (u8 *)FUN_02039438(unk80, 0x7); + u32 **unk3 = (u32 **)FUN_02039438(unk80, 0xe); + + u16 id = ScriptReadHalfword(ctx); + *unk1 = 1; + *unk3 = CreateScriptContext(unk80, id); + *unk2 = (u8)(*unk2 + 1); + + SetupNativeScript(ctx, FUN_02039CC8); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_02039CC8(struct ScriptContext *ctx) +{ + u8* unk = FUN_02039438(ctx->unk80, 0x5); + + if (*unk == 0) + { + return TRUE; + } + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_RestartCurrentScript(struct ScriptContext *ctx) +{ + u8* unk = (u8 *)FUN_02039438(ctx->unk80, 0x5); + + *unk = 0; + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GoTo(struct ScriptContext *ctx) +{ + s32 offset = (s32)ScriptReadWord(ctx); + ScriptJump(ctx, ctx->scriptPtr + offset); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_ObjectGoTo(struct ScriptContext *ctx) +{ + u32* unk = FUN_02039438(ctx->unk80, 0xa); + u8 id = ScriptReadByte(ctx); + s32 offset = (s32)ScriptReadWord(ctx); + if (FUN_02058448(*unk) == id) + { + ScriptJump(ctx, ctx->scriptPtr + offset); + } + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_BgGoTo(struct ScriptContext *ctx) +{ + u32 bgId = FUN_02046534(ctx->unk74); + u8 id = ScriptReadByte(ctx); + s32 offset = (s32)ScriptReadWord(ctx); + + if (bgId == id) + { + ScriptJump(ctx, ctx->scriptPtr + offset); + } + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_DirectionGoTo(struct ScriptContext *ctx) +{ + u32 *playerDirection = FUN_02039438(ctx->unk80, 0x9); + u8 dir = ScriptReadByte(ctx); + s32 offset = (s32)ScriptReadWord(ctx); + + if (*playerDirection == dir) + { + ScriptJump(ctx, ctx->scriptPtr + offset); + } + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Call(struct ScriptContext *ctx) +{ + s32 offset = (s32)ScriptReadWord(ctx); + ScriptCall(ctx, ctx->scriptPtr + offset); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Return(struct ScriptContext *ctx) +{ + ScriptReturn(ctx); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GoToIf(struct ScriptContext *ctx) +{ + u8 compareType = ScriptReadByte(ctx); + s32 offset = (s32)ScriptReadWord(ctx); + + if (sScriptConditionTable[compareType][ctx->comparisonResult] == TRUE) + { + ScriptJump(ctx, ctx->scriptPtr + offset); + } + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CallIf(struct ScriptContext *ctx) +{ + u8 compareType = ScriptReadByte(ctx); + s32 offset = (s32)ScriptReadWord(ctx); + + if (sScriptConditionTable[compareType][ctx->comparisonResult] == TRUE) + { + ScriptCall(ctx, ctx->scriptPtr + offset); + } + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_SetFlag(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 flag = ScriptReadHalfword(ctx); + FlagSet(unk80, flag); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_ClearFlag(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 flag = ScriptReadHalfword(ctx); + FlagClear(unk80, flag); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CheckFlag(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 flag = ScriptReadHalfword(ctx); + ctx->comparisonResult = FlagCheck(unk80, flag); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CheckFlagVar(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 *wk2 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + *wk2 = FlagCheck(unk80, *wk1); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_SetFlagVar(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 *wk = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + FlagSet(unk80, *wk); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_SetTrainerFlag(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 flag = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + TrainerFlagSet(unk80, flag); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_ClearTrainerFlag(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 flag = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + TrainerFlagClear(unk80, flag); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CheckTrainerFlag(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 flag = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + ctx->comparisonResult = TrainerFlagCheck(unk80, flag); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_AddVar(struct ScriptContext *ctx) +{ + u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 wk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + *wk1 = (u16)(*wk1 + wk2); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_SubVar(struct ScriptContext *ctx) +{ + u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 wk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + *wk1 = (u16)(*wk1 - wk2); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_SetVar(struct ScriptContext *ctx) +{ + u16 *wk = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + *wk = ScriptReadHalfword(ctx); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CopyVar(struct ScriptContext *ctx) +{ + u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 *wk2 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + *wk1 = *wk2; + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_SetOrCopyVar(struct ScriptContext *ctx) +{ + u16 *wk1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 wk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + *wk1 = wk2; + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Message(struct ScriptContext *ctx) +{ + u8 id = ScriptReadByte(ctx); + MOD05_ShowMessageInField(ctx, ctx->msgData, id); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_MessageFrom(struct ScriptContext *ctx) +{ + u16 arc = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 msg = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct MsgData *msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, arc, 32); + MOD05_ShowMessageInField(ctx, msgData, msg); + DestroyMsgData(msgData); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_MessageFrom2(struct ScriptContext *ctx) +{ + u16 arc = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 msg = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct MsgData *msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, arc, 32); + MOD05_021E2BD0(ctx, msgData, msg, 1, NULL); + DestroyMsgData(msgData); + SetupNativeScript(ctx, FUN_0203A2F0); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01FC(struct ScriptContext *ctx) +{ + u16 typ = ScriptReadHalfword(ctx); + u16 id = ScriptReadHalfword(ctx); + u16 word1 = ScriptReadHalfword(ctx); + s16 word2 = (s16)ScriptReadHalfword(ctx); + + MOD05_021E2C58(ctx, typ, id, word1, word2, 0xff); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01FD(struct ScriptContext *ctx) +{ + u16 typ = ScriptReadHalfword(ctx); + u16 id = ScriptReadHalfword(ctx); + u16 word1 = ScriptReadHalfword(ctx); + s16 word2 = (s16)ScriptReadHalfword(ctx); + + MOD05_021E2C58(ctx, typ, id, word1, word2, 1); + SetupNativeScript(ctx, FUN_0203A2F0); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01FE(struct ScriptContext *ctx) +{ + u8 id = ScriptReadByte(ctx); + + if (ctx->unk80->unkA8 == NULL) + { + return FALSE; + } + + u16 *unkArr = ctx->unk80->unkA8->unk90[id].unk0; + if (unkArr[0] == 0xFFFF) + { + struct MsgData *msgdata = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 0x22b, 32); + MOD05_021E2BD0(ctx, msgdata, unkArr[1], 1, NULL); + DestroyMsgData(msgdata); + } + else + { + MOD05_021E2C58(ctx, unkArr[0], unkArr[1], unkArr[2], (s16)unkArr[3], 1); + } + SetupNativeScript(ctx, FUN_0203A2F0); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01FF(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u8 msg = ScriptReadByte(ctx); + u16 poke = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 sex = ScriptReadHalfword(ctx); + u8 flag = ScriptReadByte(ctx); + u8 unk = 0; + + struct ScrStrBufs *str = MOD06_02244210(unk80->saveBlock2, poke, sex, flag, &unk); + MOD05_021E2CBC(ctx, str, (u8)(msg + unk), 1); + ScrStrBufs_delete(str); + + SetupNativeScript(ctx, FUN_0203A2F0); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk026D(struct ScriptContext *ctx) //message unown font? +{ + struct UnkStruct_0203A288 myLocalStruct; + u16 msg = ScriptReadHalfword(ctx); + + MOD05_021E2BB8(&myLocalStruct, ctx); + myLocalStruct.unk2 = 3; + + MOD05_021E2BD0(ctx, ctx->msgData, msg, 0, &myLocalStruct); + SetupNativeScript(ctx, FUN_0203A2F0); + + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk002C(struct ScriptContext *ctx) +{ + u8 msg = ScriptReadByte(ctx); + MOD05_021E2BD0(ctx, ctx->msgData, msg, 1, NULL); + SetupNativeScript(ctx, FUN_0203A2F0); + return TRUE; +} + +THUMB_FUNC /*static*/ BOOL FUN_0203A2F0(struct ScriptContext *ctx) +{ + u8 *unk = (u8 *)FUN_02039438(ctx->unk80, 3); + return FUN_020546C8(*unk); +} + +THUMB_FUNC BOOL ScrCmd_Unk002D(struct ScriptContext *ctx) +{ + u16 msg = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + MOD05_021E2BD0(ctx, ctx->msgData, (u8)msg, 1, NULL); + SetupNativeScript(ctx, FUN_0203A2F0); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk02C0(struct ScriptContext *ctx) +{ + struct UnkStruct_0203A288 myLocalStruct; + u16 msg = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + MOD05_021E2BB8(&myLocalStruct, ctx); + myLocalStruct.unk1 = 1; + + MOD05_021E2BD0(ctx, ctx->msgData, (u8)msg, 1, &myLocalStruct); + SetupNativeScript(ctx, FUN_0203A2F0); + + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk002E(struct ScriptContext *ctx) +{ + u16 msg = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + MOD05_021E2BD0(ctx, ctx->msgData, (u8)msg, 0, NULL); + SetupNativeScript(ctx, FUN_0203A2F0); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk020C(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 0xa); + u8 msg = (u8)FUN_02058488(*unk); + MOD05_021E2BD0(ctx, ctx->msgData, msg, 1, NULL); + SetupNativeScript(ctx, FUN_0203A2F0); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk002F(struct ScriptContext *ctx) +{ + u8 msg = ScriptReadByte(ctx); + + if (!FUN_02030F40()) + { + MOD05_021E2BD0(ctx, ctx->msgData, msg, 1, NULL); + } + else + { + struct UnkStruct_0203A288 myLocalStruct; + MOD05_021E2BB8(&myLocalStruct, ctx); + myLocalStruct.unk0 = 1; + myLocalStruct.unk1 = 1; + MOD05_021E2BD0(ctx, ctx->msgData, msg, 0, &myLocalStruct); + } + + SetupNativeScript(ctx, FUN_0203A2F0); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_WaitButtonAB(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, FUN_0203A46C); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203A46C(struct ScriptContext *ctx) +{ +#pragma unused(ctx) + if (gMain.unk48 & 0x3) // Mask (A | B) ? + { + return TRUE; + } + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_WaitButtonABTime(struct ScriptContext *ctx) +{ + ctx->data[0] = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + SetupNativeScript(ctx, FUN_0203A4AC); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203A4AC(struct ScriptContext *ctx) +{ + if (gMain.unk48 & 0x3) // Mask (A | B) ? + { + return TRUE; + } + ctx->data[0] = ctx->data[0] - 1; + + if (ctx->data[0] == 0) + { + return TRUE; + } + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_WaitButton(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, FUN_0203A4E0); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203A4E0(struct ScriptContext *ctx) +{ + if (gMain.unk48 & 3) + { + return TRUE; + } + else if (gMain.unk48 & 0x40) + { + FUN_02055304(ctx->unk80->unk38, 0); + } + else if (gMain.unk48 & 0x80) + { + FUN_02055304(ctx->unk80->unk38, 1); + } + else if (gMain.unk48 & 0x20) + { + FUN_02055304(ctx->unk80->unk38, 2); + } + else if (gMain.unk48 & 0x10) + { + FUN_02055304(ctx->unk80->unk38, 3); + } + else if (gMain.unk48 & 0x400) + { + FUN_02039460(ctx->unk80); + } + else + { + return FALSE; + } + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0032(struct ScriptContext *ctx) +{ + SetupNativeScript(ctx, FUN_0203A570); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203A570(struct ScriptContext *ctx) +{ +#pragma unused(ctx) + if (gMain.unk48 & 0x3) + { + return TRUE; + } + else if (gMain.unk48 & 0xf0) + { + return TRUE; + } + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0033(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u8 *unk = (u8 *)FUN_02039438(unk80, 6); + FUN_020545B8(unk80->unk08, FUN_02039438(unk80, 1), 3); + FUN_02054608(FUN_02039438(unk80, 1), Sav2_PlayerData_GetOptionsAddr(ctx->unk80->saveBlock2)); + *unk = 1; + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0034(struct ScriptContext* ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u32 *unk = FUN_02039438(unk80, 0x1); //windowID? + u8 *unk2 = FUN_02039438(unk80, 0x6); + FUN_0200D0E0(unk, 0); //clear window? + FUN_02019178(unk); + *unk2 = 0; + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0035(struct ScriptContext* ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u32 *unk = FUN_02039438(unk80, 0x1); //windowID? + u8 *unk2 = FUN_02039438(unk80, 0x6); + FUN_02019178(unk); + *unk2 = 0; + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_ScrollBg(struct ScriptContext* ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 *xval = FUN_02039438(unk80, 0x31); + u16 *xcnt = FUN_02039438(unk80, 0x2d); + u16 *xdir = FUN_02039438(unk80, 0x32); + u16 *yval = FUN_02039438(unk80, 0x33); + u16 *ycnt = FUN_02039438(unk80, 0x2e); + u16 *ydir = FUN_02039438(unk80, 0x34); + + *xval = ScriptReadByte(ctx); + *xcnt = ScriptReadByte(ctx); + *xdir = ScriptReadByte(ctx); + *yval = ScriptReadByte(ctx); + *ycnt = ScriptReadByte(ctx); + *ydir = ScriptReadByte(ctx); + + SetupNativeScript(ctx, FUN_0203A6C8); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203A6C8(struct ScriptContext* ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 *xval = FUN_02039438(unk80, 0x31); + u16 *xdir = FUN_02039438(unk80, 0x32); + u16 *yval = FUN_02039438(unk80, 0x33); + u16 *ydir = FUN_02039438(unk80, 0x34); + u16 *xcnt = FUN_02039438(unk80, 0x2d); + u16 *ycnt = FUN_02039438(unk80, 0x2e); + + if (*xcnt == 0 && *ycnt == 0) + { + return TRUE; + } + + if (*xval != 0) + { + if (*xdir == 0) + { + FUN_020179E0(unk80->unk08, 3, 1, *xval); + } + else + { + FUN_020179E0(unk80->unk08, 3, 2, *xval); + } + } + + if (*yval != 0) + { + if (*ydir == 0) + { + FUN_020179E0(unk80->unk08, 3, 4, *yval); + } + else + { + FUN_020179E0(unk80->unk08, 3, 5, *yval); + } + } + + if (*xcnt != 0) + { + *xcnt = (u16)(*xcnt - 1); + } + + if (*ycnt != 0) + { + *ycnt = (u16)(*ycnt - 1); + } + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CreateMessageBox(struct ScriptContext* ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + struct String **unk1 = FUN_02039438(unk80, 0x11); + struct String **unk2 = FUN_02039438(unk80, 0x10); + struct ScrStrBufs **unk3 = FUN_02039438(unk80, 0x0f); + u8 typ, msg; + u16 wk, map; + + msg = ScriptReadByte(ctx); + typ = ScriptReadByte(ctx); + map = ScriptReadHalfword(ctx); + wk = ScriptReadHalfword(ctx); + + if (map == 0) + { + u32 *unk4 = FUN_02039438(unk80, 10); + map = (u16)FUN_02058510(*unk4, 0); + } + + MOD05_021E8128(unk80->unk60, typ, map); + MOD05_021E8130(unk80->unk60, 1); + MOD05_021E8158(unk80); + ReadMsgDataIntoString(ctx->msgData, msg, *unk1); + StringExpandPlaceholders(*unk3, *unk2, *unk1); + AddTextPrinterParameterized(MOD05_021E8140(unk80->unk60), 1, (u16 *)*unk2, 0, 0, 0, NULL); + + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0037(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u8 typ = ScriptReadByte(ctx); + u16 map = ScriptReadHalfword(ctx); + + MOD05_021E8128(unk80->unk60, typ, map); + MOD05_021E8130(unk80->unk60, 1); + + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0038(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u8 req = ScriptReadByte(ctx); + MOD05_021E8130(unk80->unk60, req); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0039(struct ScriptContext *ctx) +{ + if (MOD05_021E8148(ctx->unk80->unk60) == TRUE) + { + return FALSE; + } + + SetupNativeScript(ctx, FUN_0203A8A0); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203A8A0(struct ScriptContext *ctx) +{ + if (MOD05_021E8148(ctx->unk80->unk60) == TRUE) + { + return TRUE; + } + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk003A(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u8 *unk1 = FUN_02039438(unk80, 3); + struct String **unk2 = FUN_02039438(unk80, 17); + struct String **unk3 = FUN_02039438(unk80, 16); + struct ScrStrBufs **unk4 = FUN_02039438(unk80, 15); + + u8 msg = ScriptReadByte(ctx); + u16 wk = ScriptReadHalfword(ctx); + + ReadMsgDataIntoString(ctx->msgData, msg, *unk2); + StringExpandPlaceholders(*unk4, *unk3, *unk2); + + *unk1 = FUN_02054658(MOD05_021E8140(unk80->unk60), *unk3, Sav2_PlayerData_GetOptionsAddr(ctx->unk80->saveBlock2), 1); + ctx->data[0] = wk; + SetupNativeScript(ctx, FUN_0203A94C); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203A94C(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u8 *unk1 = FUN_02039438(unk80, 3); + u16 *varPtr = GetVarPointer(unk80, (u16)ctx->data[0]); + MOD05_021E8144(unk80->unk60); + + u32 tmp = 0xFFFF; + if (FUN_020546C8(*unk1) == TRUE) + { + *varPtr = 2; + return TRUE; + } + + if (gMain.unk48 & 0x40) + { + tmp = 0; + } + else if (gMain.unk48 & 0x80) + { + tmp = 1; + } + else if (gMain.unk48 & 0x20) + { + tmp = 2; + } + else if (gMain.unk48 & 0x10) + { + tmp = 3; + } + + if (tmp != 0xFFFF) + { + FUN_0201BD7C(*unk1); + FUN_02055304(ctx->unk80->unk38, tmp); + *varPtr = 0; + return TRUE; + } + else + { + if (gMain.unk48 & 0x400) + { + FUN_0201BD7C(*unk1); + *varPtr = 1; + return TRUE; + } + return FALSE; + } +} + +THUMB_FUNC BOOL ScrCmd_Unk003B(struct ScriptContext *ctx) +{ + ctx->data[0] = ScriptReadHalfword(ctx); + + SetupNativeScript(ctx, FUN_0203AA0C); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203AA0C(struct ScriptContext *ctx) +{ + u16 *unk = GetVarPointer(ctx->unk80, (u16)ctx->data[0]); + + u32 tmp = 0xFFFF; + if (gMain.unk48 & 0x3) + { + *unk = 0; + return TRUE; + } + else if (gMain.unk48 & 0x40) + { + tmp = 0; + } + else if (gMain.unk48 & 0x80) + { + tmp = 1; + } + else if (gMain.unk48 & 0x20) + { + tmp = 2; + } + else if (gMain.unk48 & 0x10) + { + tmp = 3; + } + + if (tmp != 0xFFFF) + { + FUN_02055304(ctx->unk80->unk38, tmp); + *unk = 0; + return TRUE; + } + else + { + if (gMain.unk48 & 0x400) + { + *unk = 1; + return TRUE; + } + else + { + return FALSE; + } + } +} + +THUMB_FUNC BOOL ScrCmd_Menu(struct ScriptContext *ctx) +{ + FUN_02039460(ctx->unk80); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_YesNoMenu(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u32 *unk = FUN_02039438(unk80, 2); + u16 wk = ScriptReadHalfword(ctx); + FUN_0200CB00(unk80->unk08, 3, 985, 11, 0, 4); + *unk = Std_CreateYesNoMenu(unk80->unk08, &UNK_020F34E0, 985, 11, 4); + ctx->data[0] = wk; + SetupNativeScript(ctx, FUN_0203AB00); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203AB00(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u32 *unk = FUN_02039438(unk80, 2); + u16 *ptr = GetVarPointer(unk80, (u16)ctx->data[0]); + u32 unk2 = FUN_020021AC(*unk, 4); + + if (unk2 == -1) + { + return FALSE; + } + + if (unk2 == 0) + { + *ptr = 0; + } + else + { + *ptr = 1; + } + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_ShowSaveClock(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 1); + u32 *unk2 = FUN_02039438(ctx->unk80, 18); + *unk2 = FUN_0200D858(unk, 994); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_HideSaveClock(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 18); + FUN_0200DBFC(*unk); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0040(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u32 *unk = FUN_02039438(unk80, 0); + u32 *unk2 = FUN_02039438(unk80, 15); + u8 unk3 = ScriptReadByte(ctx); + u8 unk4 = ScriptReadByte(ctx); + u8 unk5 = ScriptReadByte(ctx); + u8 unk6 = ScriptReadByte(ctx); + u16 unk7 = ScriptReadHalfword(ctx); + u16 *ptr = GetVarPointer(unk80, unk7); + u32 *unk8 = FUN_02039438(ctx->unk80, 1); + *unk = MOD05_021E1BF8(unk80, unk3, unk4, unk5, unk6, ptr, *unk2, unk8, NULL); + ctx->data[0] = unk7; + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0041(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u32 *unk = FUN_02039438(unk80, 0); + u32 *unk2 = FUN_02039438(unk80, 15); + u8 unk3 = ScriptReadByte(ctx); + u8 unk4 = ScriptReadByte(ctx); + u8 unk5 = ScriptReadByte(ctx); + u8 unk6 = ScriptReadByte(ctx); + u16 unk7 = ScriptReadHalfword(ctx); + u16 *ptr = GetVarPointer(unk80, unk7); + u32 *unk8 = FUN_02039438(ctx->unk80, 1); + *unk = MOD05_021E1BF8(unk80, unk3, unk4, unk5, unk6, ptr, *unk2, unk8, ctx->msgData); + ctx->data[0] = unk7; + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0042(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 0); + u8 unk2 = ScriptReadByte(ctx); + u8 unk3 = ScriptReadByte(ctx); + MOD05_021E1C4C(*unk, unk2, unk3); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk029D(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u32 *unk = FUN_02039438(unk80, 0); + u16 unk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unk3 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + MOD05_021E1C4C(*unk, unk2, unk3); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0043(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 0); + MOD05_021E1C54(*unk); + SetupNativeScript(ctx, FUN_0203AD2C); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203AD2C(struct ScriptContext *ctx) +{ + u16 *varPtr = GetVarPointer(ctx->unk80, (u16)ctx->data[0]); + if (*varPtr == 0xEEEE) + { + return FALSE; + } + else + { + return TRUE; + } +} + +THUMB_FUNC BOOL ScrCmd_Unk02B9(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 0); + MOD05_021E1C54(*unk); + SetupNativeScript(ctx, FUN_0203AD78); + return TRUE; +} + +THUMB_FUNC static BOOL FUN_0203AD78(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u16 *varPtr = GetVarPointer(unk80, (u16)ctx->data[0]); + u32 *unk = FUN_02039438(unk80, 0); + + if (*varPtr == 0xEEEE) + { + if (FUN_02052714(unk80->unk78)) + { + *varPtr = 8; + MOD05_021E1ECC(*unk); + return TRUE; + } + else + { + return FALSE; + } + } + else + { + return TRUE; + } +} + +THUMB_FUNC BOOL ScrCmd_Unk0044(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u32 *unk = FUN_02039438(unk80, 0); + u32 *unk2 = FUN_02039438(unk80, 15); + u8 unk3 = ScriptReadByte(ctx); + u8 unk4 = ScriptReadByte(ctx); + u8 unk5 = ScriptReadByte(ctx); + u8 unk6 = ScriptReadByte(ctx); + + u16 halfWord = ScriptReadHalfword(ctx); + u16 *varPtr = GetVarPointer(unk80, halfWord); + u32 *unk7 = FUN_02039438(ctx->unk80, 1); + *unk = MOD05_021E1F34(unk80, unk3, unk4, unk5, unk6, varPtr, *unk2, unk7, NULL); + ctx->data[0] = halfWord; + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0045(struct ScriptContext *ctx) +{ + struct UnkSavStruct80 *unk80 = ctx->unk80; + u32 *unk = FUN_02039438(unk80, 0); + u32 *unk2 = FUN_02039438(unk80, 15); + u8 unk3 = ScriptReadByte(ctx); + u8 unk4 = ScriptReadByte(ctx); + u8 unk5 = ScriptReadByte(ctx); + u8 unk6 = ScriptReadByte(ctx); + + u16 halfWord = ScriptReadHalfword(ctx); + u16 *varPtr = GetVarPointer(unk80, halfWord); + u32 *unk7 = FUN_02039438(ctx->unk80, 1); + *unk = MOD05_021E1F34(unk80, unk3, unk4, unk5, unk6, varPtr, *unk2, unk7, ctx->msgData); + ctx->data[0] = halfWord; + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0046(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 0); + u16 unk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unk3 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unk4 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + MOD05_021E1F58(*unk, (u8)unk2, (u8)unk3, (u8)unk4); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0047(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 0); + MOD05_021E1F60(*unk); + SetupNativeScript(ctx, FUN_0203AD2C); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0048(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 0); + MOD05_021E26CC(*unk, ScriptReadByte(ctx)); + SetupNativeScript(ctx, FUN_0203AD2C); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk02CF(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 0); + MOD05_021E2B80(*unk, ScriptReadByte(ctx)); + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk02D0(struct ScriptContext *ctx) +{ + u32 *unk = FUN_02039438(ctx->unk80, 0); + MOD05_021E2B9C(*unk, ScriptReadByte(ctx)); + return TRUE; +} diff --git a/arm9/src/scrcmd_11.c b/arm9/src/scrcmd_11.c new file mode 100644 index 00000000..8553adfa --- /dev/null +++ b/arm9/src/scrcmd_11.c @@ -0,0 +1,120 @@ +#include "scrcmd.h" +#include "unk_02029FB0.h" + +extern void* FUN_02039438(struct UnkSavStruct80*, int idx); + +extern void FUN_0202A0E8(struct UnkStruct_02029FB0*, int); +extern void FUN_0202A170(struct UnkStruct_02029FB0*, int); +extern u8 FUN_0204B5FC(struct UnkSavStruct80*, void*); +extern void FUN_0204B57C(struct UnkSavStruct80*, void*, int); +extern u16 FUN_0204B63C(struct UnkSavStruct80*, void*); +extern u16 FUN_0204B660(struct UnkSavStruct80*, void*); +extern u16 FUN_0204B684(struct UnkSavStruct80*, void*); +extern u16 FUN_0204B6A4(struct UnkSavStruct80*, void*); +extern void FUN_0204B9CC(struct UnkSavStruct80*); +extern void FUN_0204B5A8(struct UnkSavStruct80*, void*, u16); +extern void FUN_0204B9A0(struct UnkSavStruct80*); +extern void FUN_0204B4FC(struct UnkSavStruct80*, void*); + +THUMB_FUNC BOOL ScrCmd_Unk017D(struct ScriptContext* ctx) +{ + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + void** unk = FUN_02039438(ctx->unk80, 10); + + *ret_ptr = FUN_0204B5FC(ctx->unk80, *unk); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk017E(struct ScriptContext* ctx) +{ + void** unk = FUN_02039438(ctx->unk80, 10); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + *ret_ptr = FUN_0204B63C(ctx->unk80, *unk); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk017F(struct ScriptContext* ctx) +{ + void** unk = FUN_02039438(ctx->unk80, 10); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + *ret_ptr = FUN_0204B660(ctx->unk80, *unk); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0180(struct ScriptContext* ctx) +{ + void** unk = FUN_02039438(ctx->unk80, 10); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + *ret_ptr = FUN_0204B684(ctx->unk80, *unk); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0181(struct ScriptContext* ctx) +{ + void** unk = FUN_02039438(ctx->unk80, 10); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + *ret_ptr = FUN_0204B6A4(ctx->unk80, *unk); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0182(struct ScriptContext* ctx) +{ + void** unk = FUN_02039438(ctx->unk80, 10); + u16 unk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + FUN_0204B57C(ctx->unk80, *unk, unk2); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0183(struct ScriptContext* ctx) +{ + void** unk = FUN_02039438(ctx->unk80, 10); + struct UnkStruct_02029FB0* unk2 = FUN_02029FC8(ctx->unk80->saveBlock2); + u16 unk3 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + FUN_0204B5A8(ctx->unk80, *unk, unk3); + FUN_0202A0E8(unk2, 3); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0184(struct ScriptContext* ctx) +{ + u16 unk = ScriptReadHalfword(ctx); + + switch (unk) + { + case 0: + FUN_0204B9A0(ctx->unk80); + break; + case 1: + FUN_0204B9CC(ctx->unk80); + break; + default: + GF_ASSERT(FALSE); + break; + } + + return TRUE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0185(struct ScriptContext* ctx) +{ + struct UnkStruct_02029FB0* unk = FUN_02029FC8(ctx->unk80->saveBlock2); + void** unk2 = FUN_02039438(ctx->unk80, 10); + + FUN_0204B4FC(ctx->unk80, *unk2); + FUN_0202A170(unk, 0); + + return FALSE; +} diff --git a/arm9/src/scrcmd_13.c b/arm9/src/scrcmd_13.c new file mode 100644 index 00000000..3b21facc --- /dev/null +++ b/arm9/src/scrcmd_13.c @@ -0,0 +1,111 @@ +#include "scrcmd.h" +#include "event_data.h" +#include "heap.h" +#include "pokedex.h" +#include "pokemon_storage_system.h" +#include "unk_0202C144.h" + +extern struct PCStorage* GetStoragePCPointer(struct SaveBlock2* sav2); +extern void* FUN_02022528(struct SaveBlock2* sav2); +extern void FUN_0202BEDC(struct Pokemon* pokemon); +extern void FUN_0202BFD8(void* a0, s32 a1, struct Pokemon* pokemon); +extern u16 FUN_0202C000(struct Pokemon* pokemon); +extern void FUN_0204B9EC(struct UnkSavStruct80*); +extern u32 FUN_0204BA1C(struct UnkSavStruct80*); +extern u16 FUN_0204BAC4(struct UnkSavStruct80*); +extern u16 FUN_0204BAD4(struct UnkSavStruct80*); +extern u16 FUN_0204BAE4(struct UnkSavStruct80*); +extern void FUN_0205F224(struct ScriptState* state); +extern void FUN_0205F234(struct ScriptState* state); +extern void FUN_0208089C(struct Pokemon* pokemon, struct PlayerData* player, u32 a2, u32 a3, u32 heap_id); + +THUMB_FUNC BOOL ScrCmd_Unk0253(struct ScriptContext* ctx) +{ + struct ScriptState* state = SavArray_Flags_get(ctx->unk80->saveBlock2); + u16 unk = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + if (unk == 0) + { + FUN_0205F224(state); + FUN_0204B9EC(ctx->unk80); + } + else if (unk == 1) + { + FUN_0205F234(state); + FUN_0204BA1C(ctx->unk80); + } + else + { + GF_ASSERT(FALSE); + } + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0254(struct ScriptContext* ctx) +{ + void* unk = FUN_02022528(ctx->unk80->saveBlock2); + struct Pokemon* pokemon = AllocMonZeroed(32); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + u16 eggs = FUN_0202C000(unk); + if (eggs == 6) { + *ret_ptr = 1; + } else { + *ret_ptr = 0; + } + + FreeToHeap(pokemon); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0255(struct ScriptContext* ctx) +{ + void* unk = FUN_02022528(ctx->unk80->saveBlock2); + struct PCStorage* pc = GetStoragePCPointer(ctx->unk80->saveBlock2); + struct Pokemon* pokemon = AllocMonZeroed(32); + struct PlayerData* player = Sav2_PlayerData_GetProfileAddr(ctx->unk80->saveBlock2); + struct Pokedex* pokedex = Sav2_Pokedex_get(ctx->unk80->saveBlock2); // unused + + for (s32 i = 0; i < PARTY_SIZE; i++) + { + FUN_0202BFD8(unk, i, pokemon); + FUN_0208089C(pokemon, player, 2, 0, 32); + + struct BoxPokemon* box_mon = FUN_020690E4(pokemon); + GF_ASSERT(PCStorage_PlaceMonInFirstEmptySlotInAnyBox(pc, box_mon)); + + FUN_0202C144(ctx->unk80->saveBlock2, pokemon); + } + + FreeToHeap(pokemon); + FUN_0202BEDC(unk); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0256(struct ScriptContext* ctx) +{ + u16 unk = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + switch (unk) + { + case 0: + *ret_ptr = FUN_0204BAC4(ctx->unk80); + break; + case 1: + *ret_ptr = FUN_0204BAD4(ctx->unk80); + break; + case 2: + *ret_ptr = FUN_0204BAE4(ctx->unk80); + break; + case 3: + // For some reason, mwcc puts the FUN_0204BAD4 call before the FUN_0204BAC4 and FUN_0204BAE4 calls. + *ret_ptr = (u16)(FUN_0204BAC4(ctx->unk80) + FUN_0204BAE4(ctx->unk80) + FUN_0204BAD4(ctx->unk80)); + break; + } + + return FALSE; +} diff --git a/arm9/src/scrcmd_18_c.c b/arm9/src/scrcmd_18_c.c index b8bbbcdd..d4437c5f 100644 --- a/arm9/src/scrcmd_18_c.c +++ b/arm9/src/scrcmd_18_c.c @@ -6,19 +6,17 @@ #include "map_header.h"
#include "scrcmd.h"
-extern u16 VarGet(struct UnkStruct_0204639C* arg, u16 wk);
-extern u16 *GetVarPointer(struct UnkStruct_0204639C* arg, u16);
extern BOOL GiveMon(u32 heap_id, struct SaveBlock2 * sav2, u16 species, u8 level, u16 item, u32 mapSec, u8 encounterType);
-THUMB_FUNC BOOL ScrCmd_givemon(struct ScriptContext* ctx)
+THUMB_FUNC BOOL ScrCmd_GiveMon(struct ScriptContext* ctx)
{
- u32 mapSec = FUN_02034824(*(ctx->unk80->unk1C));
- struct UnkStruct_0204639C *savePtr = ctx->unk80;
+ u32 mapSec = MapHeader_GetMapSec(*(ctx->unk80->mapId));
+ struct UnkSavStruct80 *savePtr = ctx->unk80;
u16 species = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
u16 level = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
u16 item = VarGet(ctx->unk80, ScriptReadHalfword(ctx));
u16 * varPtr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx));
- struct PlayerParty * party = SavArray_PlayerParty_get((struct SaveBlock2 *) savePtr->unkC);
- *varPtr = (u16)GiveMon(11, (struct SaveBlock2 *) savePtr->unkC, species, (u8)level, item, mapSec, 12);
+ struct PlayerParty * party = SavArray_PlayerParty_get(savePtr->saveBlock2);
+ *varPtr = (u16)GiveMon(11, savePtr->saveBlock2, species, (u8)level, item, mapSec, 12);
return FALSE;
}
diff --git a/arm9/src/scrcmd_19.c b/arm9/src/scrcmd_19.c new file mode 100644 index 00000000..b0a201b7 --- /dev/null +++ b/arm9/src/scrcmd_19.c @@ -0,0 +1,86 @@ +#include "scrcmd.h" +#include "bag.h" + +const u16 UNK_020F450C[7][2] = { + { 0x0067, 0x008E }, + { 0x0065, 0x008A }, + { 0x0066, 0x008C }, + { 0x0063, 0x0159 }, + { 0x0064, 0x015B }, + { 0x0068, 0x019A }, + { 0x0069, 0x0198 }, +}; + +THUMB_FUNC BOOL ScrCmd_Unk01F1(struct ScriptContext * ctx) +{ + struct UnkSavStruct80 * sav_ptr = ctx->unk80; + + u16 * ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + u8 i; + u16 total; + for (i = 0, total = 0; i < 7; i++) + { + total += Bag_GetQuantity(Sav2_Bag_get(sav_ptr->saveBlock2), UNK_020F450C[i][0], 4); + } + + *ret_ptr = total; + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01F4(struct ScriptContext * ctx) +{ + u16 * ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unk = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + *ret_ptr = 0; + + for (u16 i = 0; i < 7; i++) + { + if (UNK_020F450C[i][0] == unk) + { + *ret_ptr = UNK_020F450C[i][1]; + break; + } + } + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01F5(struct ScriptContext * ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + u16 * ret_ptr1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 * ret_ptr2 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 needed_amount = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + *ret_ptr1 = 0; + *ret_ptr2 = 0; + + u8 i = 0; + u16 total = 0; + for (; i < 7; i++) + { + total += Bag_GetQuantity(Sav2_Bag_get(sav_ptr->saveBlock2), UNK_020F450C[i][0], 4); + if (total >= needed_amount) + { + *ret_ptr1 = UNK_020F450C[i][0]; + *ret_ptr2 = i; + break; + } + } + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01F2(struct ScriptContext * ctx) +{ +#pragma unused(ctx) + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01F3(struct ScriptContext * ctx) +{ +#pragma unused(ctx) + return FALSE; +} diff --git a/arm9/src/scrcmd_20.c b/arm9/src/scrcmd_20.c new file mode 100644 index 00000000..882126a0 --- /dev/null +++ b/arm9/src/scrcmd_20.c @@ -0,0 +1,35 @@ +#include "scrcmd.h" + +const u16 UNK_020F452A[19][2] = { + { 0x00FB, 0x03E8 }, + { 0x0109, 0x03E8 }, + { 0x0114, 0x03E8 }, + { 0x0115, 0x03E8 }, + { 0x01A1, 0x07D0 }, + { 0x0181, 0x07D0 }, + { 0x0192, 0x0FA0 }, + { 0x0167, 0x0FA0 }, + { 0x0173, 0x1770 }, + { 0x01A0, 0x1770 }, + { 0x0151, 0x1770 }, + { 0x0162, 0x1F40 }, + { 0x015C, 0x1F40 }, + { 0x016A, 0x2710 }, + { 0x015F, 0x2710 }, + { 0x0154, 0x2710 }, + { 0x0164, 0x2710 }, + { 0x0191, 0x3A98 }, + { 0x018B, 0x4E20 }, +}; + +THUMB_FUNC BOOL ScrCmd_Unk02A6(struct ScriptContext * ctx) +{ + u16 idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 * ret_ptr1 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 * ret_ptr2 = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + *ret_ptr1 = UNK_020F452A[idx][0]; + *ret_ptr2 = UNK_020F452A[idx][1]; + + return FALSE; +} diff --git a/arm9/src/scrcmd_23.c b/arm9/src/scrcmd_23.c new file mode 100644 index 00000000..0c9907a5 --- /dev/null +++ b/arm9/src/scrcmd_23.c @@ -0,0 +1,169 @@ +#include "scrcmd.h" + +extern BOOL FUN_02025D6C(void*, u16); +extern BOOL FUN_02025D94(void*, u16); +extern BOOL FUN_02026298(void*, u16); +extern void* FUN_02026CC4(struct SaveBlock2* sav2); +extern BOOL FUN_020260C4(void*, u16, u16); + +THUMB_FUNC BOOL ScrCmd_Unk0083(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + u16 unk1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + void* unk2 = FUN_02026CC4(sav2); + + *ret_ptr = (u16)FUN_02025D6C(unk2, unk1); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0084(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0085(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + u16 unk1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + void* unk2 = FUN_02026CC4(sav2); + + *ret_ptr = (u16)FUN_02025D94(unk2, unk1); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0086(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0087(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + u16 unk1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + void* unk2 = FUN_02026CC4(sav2); + + *ret_ptr = (u16)FUN_02026298(unk2, unk1); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0088(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0089(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk008A(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk008B(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + void* unused3 = FUN_02026CC4(sav2); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk008C(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk008D(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk008E(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk008F(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + u16 unk1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + void* unk3 = FUN_02026CC4(sav2); + + *ret_ptr = (u16)FUN_020260C4(unk3, unk1, unk2); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0090(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0091(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0092(struct ScriptContext* ctx) +{ + u16 unused1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + return FALSE; +} diff --git a/arm9/src/scrcmd_25.c b/arm9/src/scrcmd_25.c new file mode 100644 index 00000000..5124ad9a --- /dev/null +++ b/arm9/src/scrcmd_25.c @@ -0,0 +1,27 @@ +#include "scrcmd.h" + +THUMB_FUNC BOOL ScrCmd_Unk023F(struct ScriptContext * ctx) +{ +#pragma unused(ctx) + GF_ASSERT(FALSE); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0240(struct ScriptContext * ctx) +{ +#pragma unused(ctx) + GF_ASSERT(FALSE); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0241(struct ScriptContext * ctx) +{ +#pragma unused(ctx) + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0242(struct ScriptContext * ctx) +{ +#pragma unused(ctx) + return FALSE; +} diff --git a/arm9/src/scrcmd_coins.c b/arm9/src/scrcmd_coins.c new file mode 100644 index 00000000..59638c83 --- /dev/null +++ b/arm9/src/scrcmd_coins.c @@ -0,0 +1,136 @@ +#include "scrcmd.h" +#include "coins.h" + +extern void * FUN_02039438(struct UnkSavStruct80* arg, u8 idx); + +extern u32 MOD05_021E2950(struct UnkSavStruct80* arg, u8, u8); +extern MOD05_021E29B4(); +extern MOD05_021E29C8(); + +THUMB_FUNC BOOL ScrCmd_Unk0075(struct ScriptContext * ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + u32 unk1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u32 unk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 ** unk_ret_ptr = FUN_02039438(sav_ptr, 0x26); + + u32 unk3 = MOD05_021E2950(ctx->unk80, (u8)unk1, (u8)unk2); + *unk_ret_ptr = (u16 *)unk3; + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0076(struct ScriptContext * ctx) +{ + u16 ** unk = FUN_02039438(ctx->unk80, 0x26); + MOD05_021E29B4(*unk); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0077(struct ScriptContext * ctx) +{ + u16 ** unk = FUN_02039438(ctx->unk80, 0x26); + MOD05_021E29C8(ctx->unk80, *unk); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetCoins(struct ScriptContext * ctx) +{ + u16 * coins_ptr = Sav2_PlayerData_GetCoinsAddr(ctx->unk80->saveBlock2); + u16 * ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + *ret_ptr = CheckCoins(coins_ptr); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GiveCoins(struct ScriptContext * ctx) +{ + u16 * coins_ptr = Sav2_PlayerData_GetCoinsAddr(ctx->unk80->saveBlock2); + u16 amount = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + GiveCoins(coins_ptr, amount); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_TakeCoinsImmediate(struct ScriptContext * ctx) +{ + u16 * coins_ptr = Sav2_PlayerData_GetCoinsAddr(ctx->unk80->saveBlock2); + u16 amount = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + TakeCoins(coins_ptr, amount); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_TakeCoinsAddress(struct ScriptContext * ctx) +{ + u16 * coins_ptr = Sav2_PlayerData_GetCoinsAddr(ctx->unk80->saveBlock2); + u16 * amount = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + TakeCoins(coins_ptr, *amount); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_HasEnoughCoinsImmediate(struct ScriptContext * ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct SaveBlock2 * sav2 = ScriptEnvironment_GetSav2Ptr(sav_ptr); + // Created, but discarded. + struct PlayerData * player = Sav2_PlayerData_GetProfileAddr(sav2); + u16 * coins_ptr = Sav2_PlayerData_GetCoinsAddr(sav_ptr->saveBlock2); + u16 * ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + u32 amount = ScriptReadWord(ctx); + u16 coins = CheckCoins(coins_ptr); + + if (coins < amount) + { + *ret_ptr = 0; + } + else + { + *ret_ptr = 1; + } + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_HasEnoughCoinsAddress(struct ScriptContext * ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct SaveBlock2 * sav2 = ScriptEnvironment_GetSav2Ptr(sav_ptr); + // Created, but discarded + struct PlayerData * player = Sav2_PlayerData_GetProfileAddr(sav2); + u16 * coins_ptr = Sav2_PlayerData_GetCoinsAddr(sav_ptr->saveBlock2); + u16 * ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + u16 amount = *(u16*)GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 coins = CheckCoins(coins_ptr); + + if (coins < amount) + { + *ret_ptr = 0; + } + else + { + *ret_ptr = 1; + } + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CanGiveCoins(struct ScriptContext * ctx) +{ + u16 * coins_ptr = Sav2_PlayerData_GetCoinsAddr(ctx->unk80->saveBlock2); + u16 * ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 amount = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + *ret_ptr = (u16)CanGiveCoins(coins_ptr, amount); + + return FALSE; +} diff --git a/arm9/src/scrcmd_daycare.c b/arm9/src/scrcmd_daycare.c new file mode 100644 index 00000000..4e2f925e --- /dev/null +++ b/arm9/src/scrcmd_daycare.c @@ -0,0 +1,192 @@ +#include "scrcmd.h" +#include "daycare.h" +#include "party.h" +#include "script_buffers.h" + +extern void* FUN_02039438(struct UnkSavStruct80*, int idx); + +extern void MOD05_021EC57C(struct PlayerParty* party, u8 idx, struct DayCare* daycare, struct SaveBlock2* sav2); +extern u16 MOD05_021EC71C(struct PlayerParty* party, struct ScrStrBufs* mgr, struct DayCare* daycare, u8 idx); +extern u16 MOD05_021EC854(struct DayCare* daycare, u8 idx, struct ScrStrBufs* mgr); +extern u8 MOD05_021EC864(struct DayCare* daycare, int idx, struct ScrStrBufs* mgr); +extern void MOD05_021ECD64(struct DayCare* daycare); +extern void MOD05_DayCare_GiveEggToPlayer(struct DayCare* daycare, struct PlayerParty* party, struct PlayerData* player); +extern void MOD05_021ED4E0(struct DayCare* daycare, struct ScrStrBufs* mgr); +extern void MOD05_021ED52C(struct DayCare* daycare, u8 idx1, u8 idx2, u8 idx3, u8 idx4, struct ScrStrBufs* mgr); +extern u16 MOD05_021ED5C4(struct PlayerParty* party, int idx, struct ScrStrBufs* mgr); +extern u16 MOD05_021ED5EC(struct DayCare* daycare); +extern u32 MOD05_021ED644(struct DayCare* daycare); + +THUMB_FUNC BOOL ScrCmd_Unk016D(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + struct DayCare* daycare = Sav2_DayCare_get(sav2); + + MOD05_021ED4E0(daycare, *mgr); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk016E(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct SaveBlock2* sav2 = sav_ptr->saveBlock2; + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + struct DayCare* daycare = SavArray_get(sav2, 8); + + *ret_ptr = MOD05_021ED5EC(daycare); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01A8(struct ScriptContext* ctx) +{ + struct DayCare* daycare = SavArray_get(ctx->unk80->saveBlock2, 8); + MOD05_021ECD64(daycare); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01A9(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct DayCare* daycare = SavArray_get(sav_ptr->saveBlock2, 8); + struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2); + struct SaveBlock2* sav2 = ScriptEnvironment_GetSav2Ptr(ctx->unk80); + struct PlayerData* player = Sav2_PlayerData_GetProfileAddr(sav2); + + MOD05_DayCare_GiveEggToPlayer(daycare, party, player); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01A4(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + struct SaveBlock2* sav2 = sav_ptr->saveBlock2; + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct DayCare* daycare = SavArray_get(sav2, 8); + struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2); + + *ret_ptr = MOD05_021EC71C(party, *mgr, daycare, (u8)idx); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01AA(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + struct SaveBlock2* sav2 = sav_ptr->saveBlock2; + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct DayCare* daycare = SavArray_get(sav2, 8); + + *ret_ptr = MOD05_021EC854(daycare, (u8)idx, *mgr); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01AE(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + u16 idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct DayCare* daycare = SavArray_get(sav2, 8); + + *ret_ptr = MOD05_021EC864(daycare, idx, *mgr); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01AF(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u16 unused = ScriptReadHalfword(ctx); + u16 idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2); + + *ret_ptr = MOD05_021ED5C4(party, idx, *mgr); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01B0(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct SaveBlock2* sav2 = sav_ptr->saveBlock2; + u16 idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2); + struct DayCare* daycare = SavArray_get(sav2, 8); + + MOD05_021EC57C(party, (u8)idx, daycare, sav2); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01BC(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u16 idx1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 idx2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 idx3 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 idx4 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct DayCare* daycare = Sav2_DayCare_get(sav2); + + MOD05_021ED52C(daycare, (u8)idx1, (u8)idx2, (u8)idx3, (u8)idx4, *mgr); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01BE(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + struct DayCare* daycare = SavArray_get(sav2, 8); + + *ret_ptr = (u16)MOD05_021ED644(daycare); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01BF(struct ScriptContext* ctx) +{ + struct SaveBlock2* sav2 = ctx->unk80->saveBlock2; + u16* ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + struct DayCare* daycare = SavArray_get(sav2, 8); + + *ret_ptr = (u16)Sav2_DayCare_GetEggPID(daycare); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01A5(struct ScriptContext* ctx) +{ + u16* unused = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01A6(struct ScriptContext* ctx) +{ +#pragma unused(ctx) + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01A7(struct ScriptContext* ctx) +{ +#pragma unused(ctx) + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk01AD(struct ScriptContext* ctx) +{ + u16* unused = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + return FALSE; +} diff --git a/arm9/src/scrcmd_items.c b/arm9/src/scrcmd_items.c new file mode 100644 index 00000000..0184d02e --- /dev/null +++ b/arm9/src/scrcmd_items.c @@ -0,0 +1,96 @@ +#include "scrcmd.h" +#include "bag.h" + +extern BOOL FUN_02054CB0(u16 item_id); + +THUMB_FUNC BOOL ScrCmd_GiveItem(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + + u16 item_id = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* item_was_added = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + struct Bag* bag = Sav2_Bag_get(sav_ptr->saveBlock2); + + *item_was_added = (u16)Bag_AddItem(bag, item_id, quantity, 4); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_TakeItem(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + + u16 item_id = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* item_was_taken = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + struct Bag* bag = Sav2_Bag_get(sav_ptr->saveBlock2); + + *item_was_taken = (u16)Bag_TakeItem(bag, item_id, quantity, 4); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_HasSpaceForItem(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + + u16 item_id = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* has_space = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + struct Bag* bag = Sav2_Bag_get(sav_ptr->saveBlock2); + + *has_space = (u16)Bag_HasSpaceForItem(bag, item_id, quantity, 4); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_HasItem(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + + u16 item_id = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 quantity = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* has_item = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + struct Bag* bag = Sav2_Bag_get(sav_ptr->saveBlock2); + + *has_item = (u16)Bag_HasItem(bag, item_id, quantity, 11); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_ItemIdIsTMOrHM(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + + u16 item_id = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* is_tm_or_hm = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + *is_tm_or_hm = (u16)FUN_02054CB0(item_id); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetItemPocketId(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + + u16 item_id = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16* pocket = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + *pocket = (u16)GetItemAttr(item_id, ITEMATTR_POCKET, 11); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0081(struct ScriptContext* ctx) +{ +#pragma unused(ctx) + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0082(struct ScriptContext* ctx) +{ +#pragma unused(ctx) + return FALSE; +} diff --git a/arm9/src/scrcmd_money.c b/arm9/src/scrcmd_money.c new file mode 100644 index 00000000..d2254844 --- /dev/null +++ b/arm9/src/scrcmd_money.c @@ -0,0 +1,111 @@ +#include "scrcmd.h" +#include "player_data.h" + +extern void * FUN_02039438(struct UnkSavStruct80* arg, u8 idx); + +extern u32 MOD05_021E27E8(struct UnkSavStruct80* arg, u8, u8); +extern void MOD05_021E288C(u32 *); +extern void MOD05_021E28A0(struct UnkSavStruct80* arg, u32 *); + +THUMB_FUNC BOOL ScrCmd_GiveMoney(struct ScriptContext * ctx) +{ + struct SaveBlock2 * sav2 = ScriptEnvironment_GetSav2Ptr(ctx->unk80); + struct PlayerData * player = Sav2_PlayerData_GetProfileAddr(sav2); + + u32 amount = ScriptReadWord(ctx); + PlayerProfile_AddMoney(player, amount); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_TakeMoneyImmediate(struct ScriptContext * ctx) +{ + struct SaveBlock2 * sav2 = ScriptEnvironment_GetSav2Ptr(ctx->unk80); + struct PlayerData * player = Sav2_PlayerData_GetProfileAddr(sav2); + + u32 amount = ScriptReadWord(ctx); + PlayerProfile_SubMoney(player, amount); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_TakeMoneyAddress(struct ScriptContext * ctx) +{ + struct SaveBlock2 * sav2 = ScriptEnvironment_GetSav2Ptr(ctx->unk80); + struct PlayerData * player = Sav2_PlayerData_GetProfileAddr(sav2); + + u32 amount = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + PlayerProfile_SubMoney(player, amount); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_HasEnoughMoneyImmediate(struct ScriptContext * ctx) +{ + struct SaveBlock2 * sav2 = ScriptEnvironment_GetSav2Ptr(ctx->unk80); + struct PlayerData * player = Sav2_PlayerData_GetProfileAddr(sav2); + u16 * ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + u32 amount = ScriptReadWord(ctx); + u32 money = PlayerProfile_GetMoney(player); + + if (money < amount) + { + *ret_ptr = 0; + } + else + { + *ret_ptr = 1; + } + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_HasEnoughMoneyAddress(struct ScriptContext * ctx) +{ + struct SaveBlock2 * sav2 = ScriptEnvironment_GetSav2Ptr(ctx->unk80); + struct PlayerData * player = Sav2_PlayerData_GetProfileAddr(sav2); + u16 * ret_ptr = GetVarPointer(ctx->unk80, ScriptReadHalfword(ctx)); + + u32 amount = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u32 money = PlayerProfile_GetMoney(player); + + if (money < amount) + { + *ret_ptr = 0; + } + else + { + *ret_ptr = 1; + } + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0072(struct ScriptContext * ctx) +{ + struct UnkSavStruct80 * sav_ptr = ctx->unk80; + u32 unk1 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u32 unk2 = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u32 *unk_ret_ptr = FUN_02039438(sav_ptr, 0x27); + + *unk_ret_ptr = MOD05_021E27E8(ctx->unk80, (u8)unk1, (u8)unk2); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0073(struct ScriptContext * ctx) +{ + u32 ** unk = FUN_02039438(ctx->unk80, 0x27); + MOD05_021E288C(*unk); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0074(struct ScriptContext * ctx) +{ + u32 ** unk = FUN_02039438(ctx->unk80, 0x27); + MOD05_021E28A0(ctx->unk80, *unk); + + return FALSE; +} diff --git a/arm9/src/scrcmd_names.c b/arm9/src/scrcmd_names.c new file mode 100644 index 00000000..cf721328 --- /dev/null +++ b/arm9/src/scrcmd_names.c @@ -0,0 +1,540 @@ +#include "scrcmd.h" +#include "event_data.h" +#include "itemtool.h" +#include "nutdata.h" +#include "party.h" +#include "player_data.h" +#include "script_buffers.h" +#include "unk_02024E64.h" +#include "unk_02064E4C.h" +#include "unk_0207FC5C.h" + +extern void* FUN_02039438(struct UnkSavStruct80* sav_ptr, int idx); + +extern u32 FUN_020536D0(u32 gender, u32 avatar, u32 a2); +extern u32 FUN_0205F388(struct ScriptState* state); +extern u32 FUN_0205F398(struct ScriptState* state); +extern struct PCStorage* GetStoragePCPointer(struct SaveBlock2* sav2); +extern u32 FUN_0205F3C0(struct ScriptState* state); +extern u32 FUN_02054C14(u32 number); + +THUMB_FUNC BOOL ScrCmd_GetPlayerName(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + struct SaveBlock2* sav2 = ScriptEnvironment_GetSav2Ptr(sav_ptr); + struct PlayerData* player = Sav2_PlayerData_GetProfileAddr(sav2); + + BufferPlayersName(*mgr, idx, player); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetRivalName(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + + BufferRivalsName(*mgr, idx, sav_ptr->saveBlock2); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetFriendName(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + + BufferFriendsName(*mgr, idx, sav_ptr->saveBlock2); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk00D0(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + u16 mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2); + struct Pokemon* mon = GetPartyMonByIndex(party, mon_idx); + + BufferBoxMonSpeciesName(*mgr, idx, &mon->box); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetItemName(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + u16 item = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferItemName(*mgr, idx, item); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetPocketName(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + u16 pocket = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferPocketName(*mgr, idx, pocket); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetTMHMMoveName(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + u16 tmhm = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 move = TMHMGetMove(tmhm); + + BufferMoveName(*mgr, idx, move); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetMoveName(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + u16 move = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferMoveName(*mgr, idx, move); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk00D5(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 unk = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u32 digits = FUN_02054C14(unk); + + BufferIntegerAsString(*mgr, idx, unk, digits, 1, TRUE); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0280(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 unk = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u8 unk2 = ScriptReadByte(ctx); + u8 digits = ScriptReadByte(ctx); + if (unk2 == 0) + { + digits = (u8)FUN_02054C14(unk); + } + + BufferIntegerAsString(*mgr, idx, unk, digits, unk2, TRUE); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk00D6(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + u16 mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2); + struct Pokemon* pokemon = GetPartyMonByIndex(party, mon_idx); + + BufferBoxMonNickname(*mgr, idx, &pokemon->box); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0251(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct PCStorage* pc = GetStoragePCPointer(sav_ptr->saveBlock2); + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + u16 box_mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + s32 box_no = box_mon_idx / 30; + s32 slot_no = box_mon_idx % 30; + struct BoxPokemon* box_mon = PCStorage_GetMonByIndexPair(pc, box_no, slot_no); + + BufferBoxMonNickname(*mgr, idx, box_mon); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetPoketchAppName(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 app = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferPoketchAppName(*mgr, idx, app); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetTrainerClassName(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 trainer_class = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferTrainerClassName(*mgr, idx, trainer_class); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk00D9(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct SaveBlock2* sav2 = ScriptEnvironment_GetSav2Ptr(sav_ptr); + struct PlayerData* player = Sav2_PlayerData_GetProfileAddr(sav2); + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + u32 gender = PlayerProfile_GetTrainerGender(player); + u32 avatar = PlayerProfile_GetAvatar(player); + u32 trainer_class = FUN_020536D0(gender, avatar, 2); + + BufferTrainerClassNameWithArticle(*mgr, idx, trainer_class); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk00DA(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 msg_no = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unk1 = ScriptReadHalfword(ctx); + u8 unk2 = ScriptReadByte(ctx); + struct String* str = FUN_02040AE4(msg_no, 4); + + BufferString(*mgr, idx, str, unk1, unk2, 2); + String_dtor(str); + + return FALSE; +} + +THUMB_FUNC struct String* FUN_02040AE4(u32 msg_no, u32 heap_id) +{ + struct MsgData* msg_data = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 362, heap_id); + struct String* ret = NewString_ReadMsgData(msg_data, msg_no); + DestroyMsgData(msg_data); + + return ret; +} + +THUMB_FUNC BOOL ScrCmd_Unk00DB(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + struct ScriptState* state = SavArray_Flags_get(ctx->unk80->saveBlock2); + u32 msg_no = FUN_0205F388(state); + struct String* str = FUN_02040AE4(msg_no, 4); + + BufferString(*mgr, idx, str, 0, 1, 2); + String_dtor(str); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk00DC(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + struct ScriptState* state = SavArray_Flags_get(ctx->unk80->saveBlock2); + u32 msg_no = FUN_0205F398(state); + struct String* str = FUN_02040AE4(msg_no, 4); + + BufferString(*mgr, idx, str, 0, 1, 2); + String_dtor(str); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk00DD(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + struct ScriptState* state = SavArray_Flags_get(ctx->unk80->saveBlock2); + u32 msg_no = FUN_0205F3C0(state); + struct String* str = FUN_02040AE4(msg_no, 4); + + BufferString(*mgr, idx, str, 0, 1, 2); + String_dtor(str); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetDecorationName(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 decoration = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferDecorationName(*mgr, idx, decoration); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetUndergroundTrapName(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 underground_trap = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferUndergroundTrapName(*mgr, idx, underground_trap); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetUndergroundItemName(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 underground_item = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferUndergroundItemName(*mgr, idx, underground_item); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk00E2(struct ScriptContext* ctx) +{ + struct String* str = String_ctor(22, 4); + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 map_no = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + FUN_02064E60(map_no, 4, str); + BufferString(*mgr, idx, str, 0, 1, 2); + String_dtor(str); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk017B(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 berry = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unk = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct String* nut_name = GetNutName((u16)(berry - FIRST_BERRY_IDX), 32); + + BufferString(*mgr, idx, nut_name, 0, unk < 2, 2); + String_dtor(nut_name); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetNatureName(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 nature = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferNatureName(*mgr, idx, nature); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetFashionName(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 fashion = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferFashionName(*mgr, idx, fashion); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0272(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + struct String* str = String_ctor(11, 11); + struct UnkStruct_02024E64* unk = FUN_02024EB4(ctx->unk80->saveBlock2); + u16* unk_buffer = FUN_02024F0C(unk); + + CopyU16ArrayToString(str, unk_buffer); + BufferString(*mgr, idx, str, 0, 0, gGameLanguage); + String_dtor(str); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetPokemonMoveName(struct ScriptContext* ctx) +{ + struct UnkSavStruct80* sav_ptr = ctx->unk80; + struct ScrStrBufs** mgr = FUN_02039438(sav_ptr, 15); + u8 idx = ScriptReadByte(ctx); + u16 mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 mon_move_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + struct PlayerParty* party = SavArray_PlayerParty_get(sav_ptr->saveBlock2); + struct Pokemon* pokemon = GetPartyMonByIndex(party, mon_idx); + u16 move = (u16)GetMonData(pokemon, MON_DATA_MOVE1 + mon_move_idx, NULL); + + BufferMoveName(*mgr, idx, move); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk0232(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u8 unk = (u8)VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 ribbon = (u16)FUN_0207FC5C(unk, 3); + + BufferRibbonNameOrDesc(*mgr, idx, ribbon); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetSealName(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 seal = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferSealName(*mgr, idx, (u16)(seal - 1)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetItemNameWithIndefArticle(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 item = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferItemNameWithIndefArticle(*mgr, idx, item); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetItemNamePlural(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 item = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferItemNamePlural(*mgr, idx, item); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetDecorationNameWithArticle(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 decoration = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferDecorationNameWithArticle(*mgr, idx, decoration); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetUndergroundTrapNameWithArticle(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 underground_trap = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferUndergroundTrapNameWithArticle(*mgr, idx, underground_trap); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetUndergroundItemNameWithArticle(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 underground_item = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferUndergroundItemNameWithArticle(*mgr, idx, underground_item); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk02C9(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 species = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + u16 unused1 = ScriptReadHalfword(ctx); + u8 unused2 = ScriptReadByte(ctx); + + BufferSpeciesNameWithArticle(*mgr, idx, species); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk02CA(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + struct ScriptState* state = SavArray_Flags_get(ctx->unk80->saveBlock2); + u32 species = FUN_0205F3C0(state); + + BufferSpeciesNameWithArticle(*mgr, idx, species); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetFashionNameWithArticle(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 fashion = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferFashionNameWithArticle(*mgr, idx, fashion); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_Unk02CC(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 trainer_class = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferTrainerClassNameWithArticle(*mgr, idx, trainer_class); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_GetSealNamePlural(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + u16 seal = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); + + BufferSealNamePlural(*mgr, idx, (u16)(seal - 1)); + + return FALSE; +} + +THUMB_FUNC BOOL ScrCmd_CapitalizeFirstChar(struct ScriptContext* ctx) +{ + struct ScrStrBufs** mgr = FUN_02039438(ctx->unk80, 15); + u8 idx = ScriptReadByte(ctx); + + ScrStrBufs_UpperFirstChar(*mgr, idx); + + return FALSE; +} diff --git a/arm9/src/script.c b/arm9/src/script.c index a5a5a6e4..2fa80058 100644 --- a/arm9/src/script.c +++ b/arm9/src/script.c @@ -17,7 +17,7 @@ THUMB_FUNC void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, u32 for (i = 0; i < NELEMS(ctx->stack); i++)
ctx->stack[i] = NULL;
- ctx->unk74 = 0;
+ ctx->unk74 = NULL;
}
THUMB_FUNC u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr)
@@ -27,7 +27,7 @@ THUMB_FUNC u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr) return 1;
}
-THUMB_FUNC void SetupNativeScript(struct ScriptContext *ctx, u8 (*ptr)(struct ScriptContext *))
+THUMB_FUNC void SetupNativeScript(struct ScriptContext *ctx, BOOL (*ptr)(struct ScriptContext *))
{
ctx->mode = 2;
ctx->nativePtr = ptr;
@@ -39,9 +39,9 @@ THUMB_FUNC void StopScript(struct ScriptContext *ctx) ctx->scriptPtr = 0;
}
-THUMB_FUNC void FUN_02038B6C(struct ScriptContext *ctx, s32 r1)
+THUMB_FUNC void FUN_02038B6C(struct ScriptContext *ctx, struct UnkStruct_0204639C *r1)
{
- ctx->unk74 = (u32)r1;
+ ctx->unk74 = r1;
}
THUMB_FUNC u8 RunScriptCommand(struct ScriptContext *ctx)
diff --git a/arm9/src/script_buffers.c b/arm9/src/script_buffers.c index 431f63b4..e9a55051 100644 --- a/arm9/src/script_buffers.c +++ b/arm9/src/script_buffers.c @@ -11,11 +11,10 @@ #include "unk_0201B8B8.h" #include "trainer_data.h" #include "script_buffers.h" +#include "unk_02024E64.h" #pragma thumb on -extern void * FUN_02024EC0(struct SaveBlock2 * sav2); -extern u16 * FUN_02024EE8(void *); extern u32 GetCityNamesMsgdataIdByCountry(u32); extern void GetECWordIntoStringByIndex(u32 a0, struct String * a1); extern void StringCat_HandleTrainerName(struct String * dest, const struct String * src); @@ -131,7 +130,7 @@ void BufferPlayersName(struct ScrStrBufs * mgr, u32 idx, struct PlayerData * dat void BufferRivalsName(struct ScrStrBufs * mgr, u32 idx, struct SaveBlock2 * sav2) { - u16 * name = FUN_02024EE8(FUN_02024EC0(sav2)); + u16 * name = GetRivalNamePtr(FUN_02024EC0(sav2)); CopyU16ArrayToString(mgr->tmpbuf, name); SetStringAsPlaceholder(mgr, idx, mgr->tmpbuf, NULL); } diff --git a/arm9/src/text.c b/arm9/src/text.c index 6207d913..aadb84c0 100644 --- a/arm9/src/text.c +++ b/arm9/src/text.c @@ -416,93 +416,7 @@ THUMB_FUNC void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadow *(current++) = (shadow12) | temp; } #else -THUMB_FUNC void GenerateFontHalfRowLookupTable(u8 fgColor, u8 bgColor, u8 shadowColor) //TODO use asm preprocessor -{ - asm { - // push {r3-r7, lr} - sub sp, #0x30 - ldr r3, =UNK_021C570C - mov r5, #0x0 - str r5, [sp, #0x20] - str r0, [sp, #0x24] - str r2, [sp, #0x28] - str r1, [sp, #0x2c] - strh r1, [r3, #0x6] - strh r0, [r3, #0x2] - add r0, sp, #0x20 - strh r2, [r3, #0x4] - str r5, [sp, #0x14] - str r0, [sp, #0x8] - mov r12, r0 - mov lr, r0 - str r0, [sp, #0x18] - _0201C07E: - mov r0, #0x0 - str r0, [sp, #0x10] - ldr r0, [sp, #0x18] - str r0, [sp, #0x4] - ldr r0, [sp, #0x8] - ldr r0, [r0, #0x0] - str r0, [sp, #0x1c] - _0201C08C: - mov r0, #0x0 - str r0, [sp, #0xc] - mov r0, lr - str r0, [sp, #0x0] - ldr r0, [sp, #0x4] - ldr r0, [r0, #0x0] - lsl r7, r0, #0x4 - _0201C09A: - ldr r0, [sp, #0x0] - mov r3, #0x0 - ldr r0, [r0, #0x0] - mov r4, r12 - lsl r6, r0, #0x8 - _0201C0A4: - ldr r0, [r4, #0x0] - add r1, r7, #0x0 - lsl r0, r0, #0xc - orr r0, r6 - orr r1, r0 - ldr r0, [sp, #0x1c] - add r3, r3, #0x1 - add r2, r0, #0x0 - orr r2, r1 - lsl r1, r5, #0x1 - ldr r0, =UNK_021C5734 - add r5, r5, #0x1 - add r4, r4, #0x4 - strh r2, [r0, r1] - cmp r3, #0x4 - blt _0201C0A4 - ldr r0, [sp, #0x0] - add r0, r0, #0x4 - str r0, [sp, #0x0] - ldr r0, [sp, #0xc] - add r0, r0, #0x1 - str r0, [sp, #0xc] - cmp r0, #0x4 - blt _0201C09A - ldr r0, [sp, #0x4] - add r0, r0, #0x4 - str r0, [sp, #0x4] - ldr r0, [sp, #0x10] - add r0, r0, #0x1 - str r0, [sp, #0x10] - cmp r0, #0x4 - blt _0201C08C - ldr r0, [sp, #0x8] - add r0, r0, #0x4 - str r0, [sp, #0x8] - ldr r0, [sp, #0x14] - add r0, r0, #0x1 - str r0, [sp, #0x14] - cmp r0, #0x4 - blt _0201C07E - add sp, #0x30 - // pop {r3-r7, pc} - } -} +GLOBAL_ASM("asm/nonmatchings/GenerateFontHalfRowLookupTable.s") #endif THUMB_FUNC void DecompressGlyphTile(const u16 *src, u16 *dst) diff --git a/arm9/src/timer3.c b/arm9/src/timer3.c new file mode 100644 index 00000000..1799fd24 --- /dev/null +++ b/arm9/src/timer3.c @@ -0,0 +1,66 @@ +#include "timer3.h" + +struct Timer3Data timer3_data; + + +THUMB_FUNC void Init_Timer3() +{ + timer3_data.Timer3Counter = 0; + timer3_data.NeedReset = FALSE; + + reg_OS_TM3CNT_H = 0; + reg_OS_TM3CNT_L = 0; + reg_OS_TM3CNT_H = 0xc1; // start timer3 with f/64 and irq enable + + OS_SetIrqFunction(0x40, &CountUpTimer3); + OS_EnableIrqMask(0x40); // irq on timer3 overflow +} + + +THUMB_FUNC void CountUpTimer3() +{ + timer3_data.Timer3Counter++; + + if (timer3_data.NeedReset) + { + reg_OS_TM3CNT_H = 0; + reg_OS_TM3CNT_L = 0; + reg_OS_TM3CNT_H = 0xc1; + timer3_data.NeedReset = FALSE; + } + + *(vu32 *)HW_INTR_CHECK_BUF |= 0x40; + + OS_SetIrqFunction(0x40, &CountUpTimer3); +} + +THUMB_FUNC u64 internal_GetTimer3Count() +{ + OSIntrMode intr_mode = OS_DisableInterrupts(); + + vu16 timer3 = reg_OS_TM3CNT_L; + vu64 timer3_counter = timer3_data.Timer3Counter & 0x0000ffffffffffff; + + if (reg_OS_IF & 0x40 && !(timer3 & 0x8000)) + { + timer3_counter++; + } + + OS_RestoreInterrupts(intr_mode); + return (timer3_counter << 16) | timer3; +} + +THUMB_FUNC u64 GetTimer3Count() +{ + return internal_GetTimer3Count(); +} + +THUMB_FUNC u64 Timer3CountToMilliSeconds(u64 count) +{ + return (count *64) / 33514; +} + +THUMB_FUNC u64 Timer3CountToSeconds(u64 count) +{ + return (count *64) / HW_SYSTEM_CLOCK; +} diff --git a/arm9/src/trainer_data.c b/arm9/src/trainer_data.c index 7af4b2ce..f161b302 100644 --- a/arm9/src/trainer_data.c +++ b/arm9/src/trainer_data.c @@ -6,11 +6,10 @@ #include "proto.h" #include "msgdata.h" #include "constants/trainer_classes.h" +#include "unk_02024E64.h" #pragma thumb on -extern void * FUN_02024EC0(struct SaveBlock2 *); -extern u16 * FUN_02024EE8(void *); // Loads all battle opponents, including multi-battle partner if exists. void EnemyTrainerSet_Init(struct BattleSetupStruct * enemies, struct SaveBlock2 * sav2, u32 heap_id) @@ -23,7 +22,7 @@ void EnemyTrainerSet_Init(struct BattleSetupStruct * enemies, struct SaveBlock2 // FIXME: String formatting in files/msgdata/msg/narc_0559.txt is abnormal. msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 559, heap_id); - rivalName = FUN_02024EE8(FUN_02024EC0(sav2)); + rivalName = GetRivalNamePtr(FUN_02024EC0(sav2)); for (i = 0; i < 4; i++) { if (enemies->trainer_idxs[i] != 0) diff --git a/arm9/src/unk_02015E30.c b/arm9/src/unk_02015E30.c new file mode 100644 index 00000000..8be466fb --- /dev/null +++ b/arm9/src/unk_02015E30.c @@ -0,0 +1,35 @@ + +#include "unk_02015E30.h" + +struct UnkStruct_02015E30 UNK_021C4898; + +THUMB_FUNC void FUN_02015E30() +{ + UNK_021C4898.unk00 = 0; +} + +THUMB_FUNC void FUN_02015E3C(struct IGT *igt) +{ + struct UnkStruct_02015E30 *unk1 = &UNK_021C4898; + UNK_021C4898.unk00 = 1; + UNK_021C4898.unk10 = 0; + UNK_021C4898.unk14 = 0; + UNK_021C4898.unk08 = 0; + UNK_021C4898.unk04 = igt; + + UNK_021C4898.unk18 = GetTimer3Count(); +} + +THUMB_FUNC void FUN_02015E60() +{ + if (UNK_021C4898.unk00 != 0) + { + u64 res = Timer3CountToSeconds(GetTimer3Count() - UNK_021C4898.unk18); + + if (UNK_021C4898.unk08 < res) + { + AddIGTSeconds(UNK_021C4898.unk04, (u32)(res - UNK_021C4898.unk08)); + UNK_021C4898.unk08 = res; + } + } +} diff --git a/arm9/src/unk_02024E64.c b/arm9/src/unk_02024E64.c new file mode 100644 index 00000000..d8682531 --- /dev/null +++ b/arm9/src/unk_02024E64.c @@ -0,0 +1,62 @@ +#include "unk_02024E64.h" + +extern void FUN_020250A4(void *param0); +extern void FUN_02025484(void *param0); + +THUMB_FUNC u32 FUN_02024E64() +{ + return sizeof(struct UnkStruct_02024E64); +} + +THUMB_FUNC void FUN_02024E6C(struct UnkStruct_02024E64 *param0) +{ + MIi_CpuClearFast(0, param0, sizeof(struct UnkStruct_02024E64)); + + FUN_020250A4(param0->unk0); + + FUN_02025484(param0->unk700); + + MIi_CpuClear16(0xFFFF, param0->rival_name_buf, sizeof(param0->rival_name_buf) / sizeof(u16)); + MIi_CpuClear16(0xFFFF, param0->unk734, sizeof(param0->unk734) / sizeof(u16)); +} + +THUMB_FUNC struct UnkStruct_02024E64 *FUN_02024EB4(struct SaveBlock2 *sav2) +{ + return SavArray_get(sav2, 0xa); +} + +THUMB_FUNC void *FUN_02024EC0(struct SaveBlock2 *sav2) +{ + return FUN_02022634(sav2, 0xa); +} + +THUMB_FUNC struct UnkStruct_02024E64 *FUN_02024ECC(struct SaveBlock2 *sav2) +{ + return SavArray_get(sav2, 0xa); +} + +THUMB_FUNC void *FUN_02024ED8(struct SaveBlock2 *sav2) +{ + struct UnkStruct_02024E64 *res = SavArray_get(sav2, 0xa); + return res->unk700; +} + +THUMB_FUNC u16 *GetRivalNamePtr(struct UnkStruct_02024E64 *unk) +{ + return unk->rival_name_buf; +} + +THUMB_FUNC void RivalsNameToU16Array(struct UnkStruct_02024E64 *unk, struct String *str) +{ + CopyStringToU16Array(str, unk->rival_name_buf, sizeof(unk->rival_name_buf) / sizeof(u16)); +} + +THUMB_FUNC u16 *FUN_02024F0C(struct UnkStruct_02024E64 *unk) +{ + return unk->unk734; +} + +THUMB_FUNC void FUN_02024F18(struct UnkStruct_02024E64 *unk, struct String *str) +{ + CopyStringToU16Array(str, unk->unk734, sizeof(unk->unk734) / sizeof(u16)); +} diff --git a/arm9/src/unk_02025484.c b/arm9/src/unk_02025484.c new file mode 100644 index 00000000..733ac23a --- /dev/null +++ b/arm9/src/unk_02025484.c @@ -0,0 +1,27 @@ +#include "global.h" +#include "MI_memory.h" +#include "error_handling.h" +#include "unk_02025484.h" + +THUMB_FUNC void FUN_02025484(struct unk_2025484 *r0, u32 r1) +{ + MI_CpuFill8(r0, 0, sizeof(struct unk_2025484)); +} + +THUMB_FUNC u32 *FUN_02025490(struct unk_2025484 *r0, u32 r1) +{ + FUN_02025484(r0, r1); + r0->unk0 = r1; + return &r0->unk4; +} + +THUMB_FUNC u32 *FUN_020254A0(struct unk_2025484 *r0, u32 r1) +{ + GF_ASSERT(r0->unk0 == r1); + return &r0->unk4; +} + +THUMB_FUNC u32 FUN_020254B4(struct unk_2025484 *r0) +{ + return r0->unk0; +} diff --git a/arm9/src/unk_0202F150.c b/arm9/src/unk_0202F150.c new file mode 100644 index 00000000..23a7de85 --- /dev/null +++ b/arm9/src/unk_0202F150.c @@ -0,0 +1,2478 @@ +#include "unk_0202F150.h" +struct +{ + u8 unk00; + struct UnkStruct0202F150 *unk04; +} UNK_021C59F4; + +vu8 UNK_02105D58 = 4; +vu8 UNK_02105D59 = 4; + +extern int FUN_02033534(); +extern u32 FUN_0202D858(u16 param0); +extern void FUN_02031480(u32 param0); +extern void FUN_0202D7D8(u8 *param0, u32 param1, struct UnkStruct0202F150_sub1 *param2); +extern u32 FUN_0200CA60(void (*param0)(), u32 param1, u32 param2); +extern void FUN_0202D394(struct UnkStruct0202F150_sub1 *param0, u8 *param1, u32 param2); +extern void FUN_0202D804(u8 *param0); +extern u32 FUN_0202E5F8(u32 param0, u32 param1, u32 param2); +extern void FUN_0202D330(void (*param0)(int)); +extern u32 FUN_0202E66C(u32 param0, u32 param1); +extern void MOD04_021D83C0(); +extern u32 FUN_0202E784(); +extern void FUN_020314D0(); +extern void FUN_0202DBA4(); +extern void FUN_0200CAB4(u32 param0); +extern void FUN_0202D824(u8 *param0); +extern u32 FUN_0202E9E8(u32 param0); +extern u32 FUN_0202F03C(); +extern u32 FUN_0202EE24(); +extern void FUN_02031CDC(); +extern void FUN_0202EBD0(u16 param0); +extern void FUN_0202ED70(u32 param0); +extern void FUN_020335F4(u32 param0); +extern void FUN_020315A4(); +extern void FUN_0202E538(); +extern u32 MOD04_021D78FC(void *param0, u32 param1); +extern u32 FUN_0202CBD4(); +extern void FUN_0202D4BC(void *param0); +extern int FUN_0202D400(struct UnkStruct0202F150_sub1 *param0, void *param1, u32 param2); +extern u32 FUN_0202D0D0(u8 *param0, u16 param1, u32 param2, void (*param3)(u32)); +extern u32 MOD04_021D79B4(void *param0, u32 param1); +extern void FUN_0202D3A4(struct UnkStruct0202F150_sub1 *param0, u8 *param1, u32 param2, u32 param3); +extern int FUN_0202D498(void *param0); +extern u16 FUN_0202CB8C(); +extern s64 _ll_mul(s64, s64); +extern u32 FUN_0202D4E4(u8 *param0); +extern u32 FUN_0202D760(u8 *param0, int *param1, u32 param2); +extern u32 FUN_0202D684(u8 *param0, u32 param1, u8 *param2, u32 param3, u32 param4, u32 param5); +extern void FUN_0202D934(u32 param0, u32 param1, u32 param2, void *param3); +extern int FUN_0202D478(struct UnkStruct0202F150_sub1 *param0); +extern u32 FUN_0202D41C(struct UnkStruct0202F150_sub1 *param0); +extern s16 FUN_0202D9A0(u32 param0); +extern u32 FUN_0202DA04(u32 param0); +extern void *FUN_0202DA40(u32 param0, u32 param1, u16 param2); +extern u32 MOD04_021D8018(); +extern u32 FUN_0202EDF8(); +extern u16 FUN_0202D19C(); +extern void FUN_020334E8(u32 param0, u32 param1); +extern u32 FUN_0202EE60(); +extern u32 FUN_0202D884(u16 param0); +extern void FUN_0202F05C(); +extern void GF_RTC_CopyDateTime(RTCDate *, RTCTime *); +extern void FUN_0202D830(u8 *param0, u32 param1); +extern u32 MOD04_021D8624(); + +THUMB_FUNC u32 FUN_0202F150(u32 param0, u32 param1) +{ + u32 r4 = 0; + UNK_021C59F4.unk00 = 0; + if (param0 != 0) + { + u32 res = FUN_0202D858((u16)FUN_02033534()) + 1; + + if (UNK_021C59F4.unk04 != 0) + { + return 1; + } + + FUN_02031480(0xf); + struct UnkStruct0202F150 *ptr = + (struct UnkStruct0202F150 *)AllocFromHeap(0xf, sizeof(struct UnkStruct0202F150)); + UNK_021C59F4.unk04 = ptr; + MI_CpuFill8(ptr, 0, 0x68C); + + UNK_021C59F4.unk04->unk658 = param1 + 0x40; + UNK_021C59F4.unk04->unk67D = 0; + UNK_021C59F4.unk04->unk67E = 0x1b; + + UNK_021C59F4.unk04->unk45C = AllocFromHeap(0xf, UNK_021C59F4.unk04->unk658 << 1); + + UNK_021C59F4.unk04->unk460 = AllocFromHeap(0xf, UNK_021C59F4.unk04->unk658); + + UNK_021C59F4.unk04->unk458 = AllocFromHeap(0xf, res * UNK_021C59F4.unk04->unk658); + + UNK_021C59F4.unk04->unk454 = AllocFromHeap(0xf, res * UNK_021C59F4.unk04->unk658); + + if (FUN_02033534() == 0xa) + { + FUN_0202D7D8(UNK_021C59F4.unk04->unk54C, 0x64, &UNK_021C59F4.unk04->unk464); + FUN_0202D7D8(UNK_021C59F4.unk04->unk56C, 0x32 << 4, &UNK_021C59F4.unk04->unk4DC); + } + else + { + FUN_0202D7D8(UNK_021C59F4.unk04->unk54C, 0x14, &UNK_021C59F4.unk04->unk464); + FUN_0202D7D8(UNK_021C59F4.unk04->unk56C, 0x1b + 0xfd, &UNK_021C59F4.unk04->unk4DC); + } + } + else + { + + r4 = 1; + if (UNK_021C59F4.unk04 == 0) + { + ErrorHandling(); + } + } + + UNK_021C59F4.unk04->unk65C = 0; + + for (int i = 0; i < 4; i++) + { + UNK_021C59F4.unk04->unk677[i] = 0xff; + } + + if (r4 == 0) + { + FUN_0202F2F0(); + } + + FUN_020312BC(UNK_021C59F4.unk04->unk5F8); + + if (r4 == 0) + { + u32 res2 = FUN_0200CA60(FUN_0202FB20, 0, 0); + + UNK_021C59F4.unk04->unk548 = res2; + } + + UNK_021C59F4.unk04->unk687 = 0; + + return 1; +} + +THUMB_FUNC void FUN_0202F2F0() +{ + UNK_021C59F4.unk04->unk62C = 0; + UNK_021C59F4.unk04->unk62D = 0; + UNK_021C59F4.unk04->unk67F = 0; + UNK_021C59F4.unk04->unk680 = 0; + + int res = (int)FUN_0202D858((u16)FUN_02033534()) + 1; + + MI_CpuFill8(UNK_021C59F4.unk04->unk458, 0, UNK_021C59F4.unk04->unk658 * res); + + int i; + for (i = 0; i < res; i++) + { + FUN_0202D394(&UNK_021C59F4.unk04->unk4E8[i], + UNK_021C59F4.unk04->unk458 + i * UNK_021C59F4.unk04->unk658, + UNK_021C59F4.unk04->unk658); + } + + MI_CpuFill8(UNK_021C59F4.unk04->unk454, 0, UNK_021C59F4.unk04->unk658 * res); + + for (i = 0; i < res; i++) + { + FUN_0202D394(&UNK_021C59F4.unk04->unk47C[i], + UNK_021C59F4.unk04->unk454 + i * UNK_021C59F4.unk04->unk658, + UNK_021C59F4.unk04->unk658); + } + + MI_CpuFill8(&UNK_021C59F4.unk04->unk2D4, 0, 6 << 6); + FUN_0202D394(&UNK_021C59F4.unk04->unk4DC, UNK_021C59F4.unk04->unk2D4, 6 << 6); + + for (i = 0; i < 0xc0; i++) + { + UNK_021C59F4.unk04->unk154[0][i] = 0xee; + UNK_021C59F4.unk04->unk154[1][i] = 0xee; + } + + MI_CpuFill8(&UNK_021C59F4.unk04->unk04c, 0, 0x42 << 2); + FUN_0202D394(&UNK_021C59F4.unk04->unk464, UNK_021C59F4.unk04->unk04c, 0x42 << 2); + + UNK_021C59F4.unk04->unk000[0][0] = 0xff; + UNK_021C59F4.unk04->unk000[1][0] = 0xff; + + for (i = 1; i < 0x26; i++) + { + UNK_021C59F4.unk04->unk000[0][i] = 0xee; + UNK_021C59F4.unk04->unk000[1][i] = 0xee; + } + + MI_CpuFill8(UNK_021C59F4.unk04->unk45C, 0, UNK_021C59F4.unk04->unk658 << 1); + + FUN_0202D394( + &UNK_021C59F4.unk04->unk470, UNK_021C59F4.unk04->unk45C, UNK_021C59F4.unk04->unk658 * 2); + + UNK_021C59F4.unk04->unk684 = 0; + UNK_021C59F4.unk04->unk685 = 0; + + for (i = 0; i < 8; i++) + { + UNK_021C59F4.unk04->unk65F[i] = 0; + UNK_021C59F4.unk04->unk667[i] = 1; + UNK_021C59F4.unk04->unk66F[i] = 1; + UNK_021C59F4.unk04->unk610[i] = 0; + + UNK_021C59F4.unk04->unk58C[i].unk0a = 0xee; + UNK_021C59F4.unk04->unk58C[i].unk08 = 0xffff; + UNK_021C59F4.unk04->unk58C[i].unk04 = 0; + UNK_021C59F4.unk04->unk58C[i].unk00 = 0; + + UNK_021C59F4.unk04->unk638[i] = 0; + } + + UNK_021C59F4.unk04->unk634 = 0; + UNK_021C59F4.unk04->unk630 = 1; + UNK_021C59F4.unk04->unk5F6 = 0xee; + UNK_021C59F4.unk04->unk5F4 = 0xffff; + UNK_021C59F4.unk04->unk5F0 = 0; + UNK_021C59F4.unk04->unk5EC = 0; + UNK_021C59F4.unk04->unk682 = 1; + UNK_021C59F4.unk04->unk683 = 1; + + UNK_02105D59 = 4; + UNK_02105D58 = 4; + + FUN_0202D804(UNK_021C59F4.unk04->unk54C); + FUN_0202D804(UNK_021C59F4.unk04->unk56C); + + UNK_021C59F4.unk04->unk688 = 0; +} + +THUMB_FUNC void FUN_0202F5A4() +{ + UNK_021C59F4.unk04->unk62C = 0; + UNK_021C59F4.unk04->unk62D = 0; + + int res = (int)FUN_0202D858((u16)FUN_02033534()) + 1; + + MI_CpuFill8(UNK_021C59F4.unk04->unk458, 0, UNK_021C59F4.unk04->unk658 * res); + + int i; + for (i = 0; i < res; i++) + { + FUN_0202D394(&UNK_021C59F4.unk04->unk4E8[i], + UNK_021C59F4.unk04->unk458 + i * UNK_021C59F4.unk04->unk658, + UNK_021C59F4.unk04->unk658); + } + + MI_CpuFill8(UNK_021C59F4.unk04->unk454, 0, UNK_021C59F4.unk04->unk658 * res); + + for (i = 0; i < res; i++) + { + FUN_0202D394(&UNK_021C59F4.unk04->unk47C[i], + UNK_021C59F4.unk04->unk454 + i * UNK_021C59F4.unk04->unk658, + UNK_021C59F4.unk04->unk658); + } + + MI_CpuFill8(&UNK_021C59F4.unk04->unk2D4, 0, 6 << 6); + FUN_0202D394(&UNK_021C59F4.unk04->unk4DC, UNK_021C59F4.unk04->unk2D4, 6 << 6); + + for (i = 0; i < 0xc0; i++) + { + UNK_021C59F4.unk04->unk154[0][i] = 0xee; + UNK_021C59F4.unk04->unk154[1][i] = 0xee; + } + + MI_CpuFill8(&UNK_021C59F4.unk04->unk04c, 0, 0x42 << 2); + FUN_0202D394(&UNK_021C59F4.unk04->unk464, UNK_021C59F4.unk04->unk04c, 0x42 << 2); + + UNK_021C59F4.unk04->unk000[0][0] = 0xff; + UNK_021C59F4.unk04->unk000[1][0] = 0xff; + + for (i = 1; i < 0x26; i++) + { + UNK_021C59F4.unk04->unk000[0][i] = 0xee; + UNK_021C59F4.unk04->unk000[1][i] = 0xee; + } + + MI_CpuFill8(UNK_021C59F4.unk04->unk45C, 0, UNK_021C59F4.unk04->unk658 << 1); + FUN_0202D394( + &UNK_021C59F4.unk04->unk470, UNK_021C59F4.unk04->unk45C, UNK_021C59F4.unk04->unk658 * 2); + + UNK_021C59F4.unk04->unk684 = 0; + UNK_021C59F4.unk04->unk685 = 0; + + for (i = 0; i < 8; i++) + { + UNK_021C59F4.unk04->unk65F[i] = 0; + UNK_021C59F4.unk04->unk667[i] = 1; + UNK_021C59F4.unk04->unk66F[i] = 1; + UNK_021C59F4.unk04->unk610[i] = 0; + + UNK_021C59F4.unk04->unk58C[i].unk0a = 0xee; + UNK_021C59F4.unk04->unk58C[i].unk08 = 0xffff; + UNK_021C59F4.unk04->unk58C[i].unk04 = 0; + UNK_021C59F4.unk04->unk58C[i].unk00 = 0; + } + + UNK_021C59F4.unk04->unk630 = 1; + UNK_021C59F4.unk04->unk5F6 = 0xee; + UNK_021C59F4.unk04->unk5F4 = 0xffff; + UNK_021C59F4.unk04->unk5F0 = 0; + UNK_021C59F4.unk04->unk5EC = 0; + UNK_021C59F4.unk04->unk682 = 1; + UNK_021C59F4.unk04->unk683 = 1; + + FUN_0202D804(UNK_021C59F4.unk04->unk54C); + FUN_0202D804(UNK_021C59F4.unk04->unk56C); + + UNK_021C59F4.unk04->unk688 = 0; +} + +THUMB_FUNC void FUN_0202F820(int param0) +{ + UNK_021C59F4.unk04->unk65F[param0] = 0; + + UNK_021C59F4.unk04->unk667[param0] = 1; + + UNK_021C59F4.unk04->unk638[param0] = 0; + + UNK_021C59F4.unk04->unk66F[param0] = 1; + + FUN_0202D394(&UNK_021C59F4.unk04->unk47C[param0], + UNK_021C59F4.unk04->unk454 + param0 * UNK_021C59F4.unk04->unk658, + UNK_021C59F4.unk04->unk658); + + FUN_0202D394(&UNK_021C59F4.unk04->unk4E8[param0], + UNK_021C59F4.unk04->unk458 + param0 * UNK_021C59F4.unk04->unk658, + UNK_021C59F4.unk04->unk658); + + UNK_021C59F4.unk04->unk58C[param0].unk0a = 0xee; + UNK_021C59F4.unk04->unk58C[param0].unk08 = 0xffff; + UNK_021C59F4.unk04->unk58C[param0].unk04 = 0; + UNK_021C59F4.unk04->unk58C[param0].unk00 = 0; +} + +THUMB_FUNC void FUN_0202F8D4() +{ + for (int i = 1; i < 8; i++) + { + if (FUN_02030E7C((u16)i) == 0 && UNK_021C59F4.unk04->unk667[i] == 0 && FUN_02031280() == 0) + { + FUN_0202F820(i); + } + } +} + +THUMB_FUNC void FUN_0202F910(int param0) +{ + FUN_0202F820(param0); +} + +THUMB_FUNC u32 FUN_0202F918(u32 param0, u32 param1, u32 param2, u32 param3) +{ + u32 ret = 1; + if (FUN_02033534() < 0x13) + { + ret = FUN_0202E5F8(param0, param1, param3); + FUN_0202D330(FUN_0202F910); + } + + FUN_0202F150(param0, param2); + + return ret; +} + +THUMB_FUNC u32 FUN_0202F950(u32 param0, u32 param1, u32 param2) +{ + u32 ret = 1; + if (FUN_02033534() < 0x13) + { + ret = FUN_0202E66C(param0, param1); + } + + FUN_0202F150(param0, param2); + + UNK_02105D58 = 4; + + return ret; +} + +THUMB_FUNC void FUN_0202F984() +{ + u32 r4 = 0; + if (FUN_02031190() == 0) + { + if (UNK_02105D59 != 4) + { + return; + } + } + else + { + if (UNK_02105D58 != 4) + { + return; + } + } + + if (UNK_021C59F4.unk04->unk67D == 2) + { + UNK_021C59F4.unk04->unk67D = 0; + r4 = 1; + } + + if (UNK_021C59F4.unk04->unk67D == 3) + { + UNK_021C59F4.unk04->unk67D = 1; + r4 = 1; + } + + if (r4 != 0) + { + FUN_0202F5A4(); + } + FUN_02031088(); +} + +THUMB_FUNC void FUN_0202F9E0(u32 param0) +{ + u8 r2 = UNK_021C59F4.unk04->unk67D; + if (r2 == 0 && param0 == 1) + { + UNK_021C59F4.unk04->unk67D = 3; + } + else if (r2 == 1 && param0 == 0) + { + UNK_021C59F4.unk04->unk67D = 2; + } +} + +THUMB_FUNC void FUN_0202FA10() +{ + FUN_0202F9E0(1); +} + +THUMB_FUNC void FUN_0202FA1C() +{ + FUN_0202F9E0(0); +} + +THUMB_FUNC u8 FUN_0202FA28() +{ + u8 ret = UNK_021C59F4.unk04->unk67D; + if (ret == 2) + { + return 1; + } + else if (ret == 3) + { + return 0; + } + + return ret; +} + +THUMB_FUNC u32 FUN_0202FA48() +{ + if (FUN_0202FA28() == 1) + { + return 1; + } + + return 0; +} + +THUMB_FUNC void FUN_0202FA5C() +{ + u32 r4 = 0; + if (UNK_021C59F4.unk04 != 0) + { + if (FUN_02033534() >= 0x13) + { + MOD04_021D83C0(); + r4 = 1; + } + else + { + if (FUN_0202E784() != 0) + { + r4 = 1; + } + } + } + + if (r4 != 0) + { + FUN_020314D0(); + FUN_0202DBA4(); + UNK_021C59F4.unk00 = 0; + + FUN_0200CAB4(UNK_021C59F4.unk04->unk548); + UNK_021C59F4.unk04->unk548 = 0; + FreeToHeap(UNK_021C59F4.unk04->unk45C); + FreeToHeap(UNK_021C59F4.unk04->unk460); + FreeToHeap(UNK_021C59F4.unk04->unk458); + FreeToHeap(UNK_021C59F4.unk04->unk454); + FUN_0202D824(UNK_021C59F4.unk04->unk56C); + FUN_0202D824(UNK_021C59F4.unk04->unk54C); + FreeToHeap(UNK_021C59F4.unk04); + UNK_021C59F4.unk04 = NULL; + } +} + +THUMB_FUNC u32 FUN_0202FB18(u32 param0) +{ + return FUN_0202E9E8(param0); +} + +THUMB_FUNC void FUN_0202FB20() +{ + if (UNK_021C59F4.unk00 != 0) + { + FUN_0203050C(); + if ((FUN_02031190() == 0 && FUN_02030E7C(0) != 0) || FUN_02031280() != 0) + { + FUN_0202FEEC(); + } + + UNK_021C59F4.unk00 = 0; + } +} + +THUMB_FUNC void FUN_0202FB58() +{ + if (FUN_0202F03C() != 0) + { + if (FUN_02031190() == 0) + { + if (FUN_0202EE24() == 0) + { + FUN_0202FA5C(); + } + } + else + { + FUN_0202FA5C(); + } + } +} + +THUMB_FUNC u32 FUN_0202FB80() +{ + FUN_02031CDC(); + + if (UNK_021C59F4.unk04 != NULL) + { + if (UNK_021C59F4.unk04->unk68A == 0) + { + UNK_021C59F4.unk00 = 0; + FUN_0202F984(); + UNK_021C59F4.unk04->unk628 |= gMain.unk44 & 0x7FFF; + FUN_02030674(); + FUN_0202FCCC(); + + UNK_021C59F4.unk04->unk628 &= 2 << 0xe; + if (FUN_0202FA28() == 0) + { + FUN_02030DA4(); + } + + if ((FUN_02031190() == 0 && FUN_02030E7C(0) != 0) || FUN_02031280() != 0) + { + FUN_02030074(); + } + + if (FUN_02031190() == 0 || FUN_0202FA28() == 1 || FUN_02031280() != 0) + { + FUN_02030DFC(); + } + + UNK_021C59F4.unk00 = 1; + } + + FUN_0202ED70(UNK_021C59F4.unk04->unk65C); + + if (FUN_02031190() == 0) + { + FUN_0202F8D4(); + } + + FUN_0202FB58(); + } + else + { + FUN_0202ED70(0); + } + + FUN_020335F4(0); + FUN_020315A4(); + + return 1; +} + +THUMB_FUNC void FUN_0202FC60() +{ + u8 r4 = UNK_021C59F4.unk00; + + UNK_021C59F4.unk00 = 0; + + if (UNK_021C59F4.unk04 != NULL) + { + FUN_0202F2F0(); + } + + UNK_021C59F4.unk00 = r4; +} + +THUMB_FUNC void FUN_0202FC80() +{ + u8 r4 = UNK_021C59F4.unk00; + + UNK_021C59F4.unk00 = 0; + + if (UNK_021C59F4.unk04 != NULL) + { + UNK_021C59F4.unk04->unk67D = 1; + FUN_0202F2F0(); + } + + UNK_021C59F4.unk00 = r4; +} + +THUMB_FUNC void FUN_0202FCA8() +{ + u8 r4 = UNK_021C59F4.unk00; + + UNK_021C59F4.unk00 = 0; + + if (UNK_021C59F4.unk04 != NULL) + { + FUN_0202F2F0(); + FUN_0202E538(); + } + + UNK_021C59F4.unk00 = r4; +} + +THUMB_FUNC void FUN_0202FCCC() +{ + if (UNK_021C59F4.unk04->unk683 != 0) + { + if (FUN_02033534() >= 0x13) + { + if (UNK_021C59F4.unk04->unk687 == 0 || MOD04_021D78FC(UNK_021C59F4.unk04, 0x26) == 0) + { + return; + } + + UNK_021C59F4.unk04->unk683 = 0; + return; + } + + if (FUN_0202CBD4() != 4 || FUN_02030E7C(FUN_02031190()) == 0) + { + if (FUN_02031280() == 0) + { + return; + } + } + + UNK_02105D58 = 0; + FUN_0203050C(); + if (UNK_02105D58 == 0) + { + return; + } + + UNK_021C59F4.unk04->unk683 = 0; + return; + } + + if (FUN_02033534() >= 0x13) + { + if (UNK_021C59F4.unk04->unk687 == 0) + { + return; + } + + if (UNK_021C59F4.unk04->unk630 != 0) + { + if ((int)UNK_021C59F4.unk04->unk634 > 3) + { + return; + } + + if (UNK_02105D58 == 4) + { + FUN_02030930(UNK_021C59F4.unk04->unk000[0]); + UNK_02105D58 = 2; + } + } + else + { + if (UNK_02105D58 == 4) + { + if (FUN_02030930(UNK_021C59F4.unk04->unk000[0]) == 0) + { + return; + } + + UNK_02105D58 = 2; + } + } + + if (MOD04_021D78FC(UNK_021C59F4.unk04, 0x26) == 0) + { + return; + } + + UNK_02105D58 = 4; + UNK_021C59F4.unk04->unk634++; + return; + } + + if (FUN_0202CBD4() != 4 || FUN_02030E7C(FUN_02031190()) == 0) + { + if (FUN_02031280() == 0) + { + return; + } + } + + if (UNK_02105D58 != 4) + { + return; + } + + // nonmatching + if ((int)UNK_021C59F4.unk04->unk634 > 3) + { + return; + } + + FUN_02030930(UNK_021C59F4.unk04->unk000[UNK_021C59F4.unk04->unk67F]); + + FUN_02030930(UNK_021C59F4.unk04->unk000[1 - UNK_021C59F4.unk04->unk67F]); + + UNK_02105D58 = 0; + FUN_0203050C(); +} + +#ifdef NONMATCHING +THUMB_FUNC u32 FUN_0202FE2C(int param0) +{ + + // these 3 variables are shuffled on the stack, everything else matches + int st4 = 0; + int stc = FUN_02031228(FUN_02033534()); + int st8 = FUN_0202D858(FUN_02033534()) + 1; + + for (int r7 = 0; r7 < st8; r7++) + { + + FUN_0202D4BC(&UNK_021C59F4.unk04->unk47C[r7]); + + if (FUN_02030E7C(r7) != 0) + { + UNK_021C59F4.unk04->unk154[param0][r7 * stc] = 0xe; + } + + FUN_0202D400( + &UNK_021C59F4.unk04->unk47C[r7], &UNK_021C59F4.unk04->unk154[param0][r7 * stc], stc); + + if (UNK_021C59F4.unk04->unk154[param0][r7 * stc] == 0xe) + { + st4++; + } + } + + if (st4 == st8) + { + return 0; + } + + return 1; +} +#else +THUMB_FUNC asm u32 FUN_0202FE2C(int param0) +{ + // clang-format off + push {r3-r7, lr} + sub sp, #0x10 + str r0, [sp, #0x0] + mov r0, #0x0 + str r0, [sp, #0x4] + bl FUN_02033534 + lsl r0, r0, #0x10 + lsr r0, r0, #0x10 + bl FUN_02031228 + str r0, [sp, #0xc] + bl FUN_02033534 + lsl r0, r0, #0x10 + lsr r0, r0, #0x10 + bl FUN_0202D858 + add r0, r0, #0x1 + mov r7, #0x0 + str r0, [sp, #0x8] + cmp r0, #0x0 + ble _0202FED0 + ldr r0, [sp, #0x0] + mov r1, #0xc0 + add r6, r0, #0x0 + add r4, r7, #0x0 + add r5, r7, #0x0 + mul r6, r1 +_0202FE66: + ldr r0, =UNK_021C59F4 + ldr r1, [r0, #0x4] + ldr r0, =0x0000047C + add r0, r1, r0 + add r0, r0, r4 + bl FUN_0202D4BC + lsl r0, r7, #0x10 + lsr r0, r0, #0x10 + bl FUN_02030E7C + cmp r0, #0x0 + beq _0202FE90 + ldr r0, =UNK_021C59F4 + mov r1, #0xe + ldr r0, [r0, #0x4] + add r0, r6, r0 + add r2, r5, r0 + mov r0, #0x55 + lsl r0, r0, #0x2 + strb r1, [r2, r0] +_0202FE90: + ldr r0, =UNK_021C59F4 + mov r2, #0x55 + ldr r1, [r0, #0x4] + ldr r0, =0x0000047C + lsl r2, r2, #0x2 + add r0, r1, r0 + add r1, r1, r2 + add r1, r1, r6 + ldr r2, [sp, #0xc] + add r0, r0, r4 + add r1, r1, r5 + bl FUN_0202D400 + ldr r0, =UNK_021C59F4 + ldr r0, [r0, #0x4] + add r0, r6, r0 + add r1, r5, r0 + mov r0, #0x55 + lsl r0, r0, #0x2 + ldrb r0, [r1, r0] + cmp r0, #0xe + bne _0202FEC2 + ldr r0, [sp, #0x4] + add r0, r0, #0x1 + str r0, [sp, #0x4] +_0202FEC2: + ldr r0, [sp, #0xc] + add r7, r7, #0x1 + add r5, r5, r0 + ldr r0, [sp, #0x8] + add r4, #0xc + cmp r7, r0 + blt _0202FE66 +_0202FED0: + ldr r1, [sp, #0x4] + ldr r0, [sp, #0x8] + cmp r1, r0 + bne _0202FEDE + add sp, #0x10 + mov r0, #0x0 + pop {r3-r7, pc} +_0202FEDE: + mov r0, #0x1 + add sp, #0x10 + pop {r3-r7, pc} + // clang-format on +} +#endif + +THUMB_FUNC void FUN_0202FEEC() +{ + if (UNK_021C59F4.unk04 == NULL || FUN_02033534() >= 0x13) + { + return; + } + + int st0 = FUN_02031228((u16)FUN_02033534()); + int r6 = (int)FUN_0202D858((u16)FUN_02033534()) + 1; + + if (UNK_02105D59 == 2 || UNK_02105D59 == 0) + { + + UNK_02105D59++; + + if (FUN_0202FA28() == 1) + { + FUN_0202FE2C(UNK_021C59F4.unk04->unk680); + } + + if (FUN_0202CBD4() == 4 && FUN_02031280() == 0) + { + + if (FUN_0202D0D0(UNK_021C59F4.unk04->unk154[UNK_021C59F4.unk04->unk680], + 0xc0, + 0xe, + FUN_020304F0) == 0) + { + UNK_02105D59--; + } + } + + int i; + if (UNK_02105D59 == 1 || UNK_02105D59 == 3) + { + for (i = 0; i < r6; i++) + { + if (FUN_02030E7C((u16)i) != 0) + { + UNK_021C59F4.unk04->unk638[i]++; + } + else if (FUN_02031280() != 0 && i == 0) + { + UNK_021C59F4.unk04->unk638[i]++; + } + } + + FUN_0203026C(0, UNK_021C59F4.unk04->unk154[UNK_021C59F4.unk04->unk680], 0xc0); + + UNK_021C59F4.unk04->unk680 = (u8)(1 - UNK_021C59F4.unk04->unk680); + } + + for (i = 0; i < r6; i++) + { + if (FUN_02030E7C((u16)i) == 0 && FUN_0202FA28() == 1) + { + UNK_021C59F4.unk04->unk154[UNK_021C59F4.unk04->unk680][i * st0] = 0xff; + } + } + + if (FUN_0202CBD4() != 4 || FUN_02031280() != 0) + { + UNK_02105D59++; + } + } +} + +THUMB_FUNC void FUN_02030074() +{ + if (UNK_021C59F4.unk04->unk683 != 0) + { + if (FUN_02033534() >= 0x13) + { + if (FUN_02030E7C(0) != 0 && MOD04_021D79B4(UNK_021C59F4.unk04->unk154, 0x4c) != 0) + { + UNK_021C59F4.unk04->unk683 = 0; + return; + } + } + else if (FUN_0202CBD4() == 4 || FUN_02031280() != 0) + { + FUN_0202FEEC(); + if (UNK_02105D59 == 2) + { + UNK_021C59F4.unk04->unk683 = 0; + return; + } + } + } + + if (FUN_02033534() >= 0x13) + { + if (FUN_02030E7C(0) != 0) + { + if (UNK_021C59F4.unk04->unk630 != 0) + { + if ((int)UNK_021C59F4.unk04->unk638[1] > 3 || + (int)UNK_021C59F4.unk04->unk638[0] > 3) + { + return; + } + + if (UNK_02105D59 == 4) + { + if (FUN_0202FA28() == 1) + { + FUN_0202FE2C(0); + } + + UNK_02105D59 = 2; + } + } + else + { + if (UNK_02105D59 == 4) + { + if (FUN_0202FA28() == 1) + { + if (FUN_0202FE2C(0) == 0) + { + return; + } + } + } + + UNK_02105D59 = 2; + } + + if (MOD04_021D79B4(UNK_021C59F4.unk04->unk154, 0x4c) == 0) + { + return; + } + + UNK_02105D59 = 4; + UNK_021C59F4.unk04->unk638[0]++; + UNK_021C59F4.unk04->unk638[1]++; + } + } + else if (FUN_0202CBD4() == 4 || FUN_02031280() != 0) + { + if (UNK_02105D59 == 4) + { + for (int r4 = 1; r4 < 8; r4++) + { + if (FUN_02030E7C((u16)r4) != 0) + { + if ((int)UNK_021C59F4.unk04->unk638[r4] > 3) + { + return; + } + } + else if (r4 == 0) + { + if (FUN_02031280() != 0) + { + if ((int)UNK_021C59F4.unk04->unk638[0] > 3) + { + return; + } + } + } + } + + if (FUN_0202FA28() == 0) + { + FUN_02030A00(UNK_021C59F4.unk04->unk154[UNK_021C59F4.unk04->unk680]); + FUN_02030A00(UNK_021C59F4.unk04->unk154[1 - UNK_021C59F4.unk04->unk680]); + } + + UNK_02105D59 = 0; + FUN_0202FEEC(); + } + } +} + +THUMB_FUNC void FUN_02030238(u32 param0, void *param1, u32 param2) +{ + if (UNK_021C59F4.unk04->unk66F[0] != 0) + { + UNK_021C59F4.unk04->unk634--; + UNK_021C59F4.unk04->unk66F[0] = 0; + return; + } + + FUN_0203026C(param0, param1, param2); +} + +THUMB_FUNC void FUN_0203026C(u32 param0, u8 *param1, u32 param2) +{ +#pragma unused(param0) +#pragma unused(param2) + UNK_021C59F4.unk04->unk634--; + if (param1 == 0) + { + return; + } + + if (param1[0] == 0xb) + { + if (FUN_0202FA28() == 1) + { + return; + } + param1++; + } + else + { + if (FUN_0202FA28() == 0) + { + return; + } + } + + if (UNK_021C59F4.unk04->unk682 != 0) + { + if ((param1[0] & 1) != 0) + { + return; + } + } + + UNK_021C59F4.unk04->unk682 = 0; + if (FUN_0202FA28() == 1) + { + int r6 = FUN_02031228((u16)FUN_02033534()); + int st4 = (int)FUN_0202D858((u16)FUN_02033534()) + 1; + + int r4 = 0; + while (r4 < st4) + { + + if (param1[0] == 0xff) + { + UNK_021C59F4.unk04->unk65C &= ~(1 << r4); + } + else + { + UNK_021C59F4.unk04->unk65C |= (1 << r4); + } + + if (param1[0] == 0xff) + { + param1 += r6; + } + else if (param1[0] == 0xe) + { + param1 += r6; + } + else if (UNK_021C59F4.unk04->unk667[r4] != 0 && (param1[0] & 1) != 0) + { + param1 += r6; + } + else + { + param1++; + FUN_0202D3A4(&UNK_021C59F4.unk04->unk4E8[r4], param1, (u32)(r6 - 1), 0x5E6); + + param1 += r6 - 1; + UNK_021C59F4.unk04->unk667[r4] = 0; + } + + r4++; + } + + return; + } + + UNK_021C59F4.unk04->unk65C = param1[1]; + UNK_021C59F4.unk04->unk65C <<= 8; + + UNK_021C59F4.unk04->unk65C += param1[2]; + FUN_0202D3A4(&UNK_021C59F4.unk04->unk470, param1 + 4, param1[3], 0x5FF); +} + +THUMB_FUNC void FUN_020303BC(u32 param0, u8 *param1, u16 param2) +{ + if (UNK_021C59F4.unk04->unk66F[param0] != 0) + { + + UNK_021C59F4.unk04->unk638[param0]--; + UNK_021C59F4.unk04->unk66F[param0] = 0; + return; + } + + FUN_020303F4(param0, param1, param2); +} + +THUMB_FUNC void FUN_020303F4(u32 param0, u8 *param1, u16 param2) +{ +#pragma unused(param2) + UNK_021C59F4.unk04->unk638[param0]--; + if (param1 == 0) + { + return; + } + + if (UNK_021C59F4.unk04->unk667[param0] != 0 && (param1[0] & 1) != 0) + { + return; + } + + UNK_021C59F4.unk04->unk667[param0] = 0; + if (FUN_0202FA28() == 1) + { + int r6 = FUN_02031228((u16)FUN_02033534()); + FUN_0202D858((u16)FUN_02033534()); + + if ((param1[0] & 2) == 0) + { + FUN_0202D3A4(&UNK_021C59F4.unk04->unk47C[param0], param1, (u32)r6, 0x65E); + } + + UNK_021C59F4.unk04->unk65F[param0]++; + return; + } + + FUN_020307E4(param1, param0); + + if ((param1[0] & 2) == 0 && FUN_0202D498(&UNK_021C59F4.unk04->unk4E8[param0]) >= 0xb) + { + FUN_0202D3A4(&UNK_021C59F4.unk04->unk4E8[param0], param1 + 1, 0xb, 0x66E); + } +} + +THUMB_FUNC void FUN_020304D4(u32 param0) +{ + if (param0 != 0) + { + UNK_02105D58++; + return; + } + + ErrorHandling(); +} + +THUMB_FUNC void FUN_020304F0(u32 param0) +{ + if (param0 != 0) + { + UNK_02105D59++; + return; + } + + ErrorHandling(); +} + +THUMB_FUNC void FUN_0203050C() +{ + if (UNK_021C59F4.unk04 == 0 || FUN_02033534() >= 0x13) + { + return; + } + + int r4 = FUN_02031228((u16)FUN_02033534()); + FUN_0202D858((u16)FUN_02033534()); + + if (FUN_02031280() != 0 && (UNK_02105D58 == 2 || UNK_02105D58 == 0)) + { + UNK_02105D58++; + FUN_020304D4(1); + + FUN_020303F4(0, UNK_021C59F4.unk04->unk000[UNK_021C59F4.unk04->unk67F], (u16)r4); + + UNK_021C59F4.unk04->unk67F = (u8)(1 - UNK_021C59F4.unk04->unk67F); + UNK_021C59F4.unk04->unk634++; + return; + } + + if (FUN_0202CBD4() != 4) + { + return; + } + + if (FUN_02030E7C(FUN_02031190()) == 0) + { + FUN_02031190(); + return; + } + + if (UNK_02105D58 != 2 && UNK_02105D58 != 0) + { + return; + } + + if (FUN_02031190() != 0) + { + UNK_02105D58++; + + if (FUN_0202D0D0(UNK_021C59F4.unk04->unk000[UNK_021C59F4.unk04->unk67F], + (u16)r4, + 0xe, + FUN_020304D4) == 0) + { + UNK_02105D58--; + return; + } + + UNK_021C59F4.unk04->unk67F = (u8)(1 - UNK_021C59F4.unk04->unk67F); + UNK_021C59F4.unk04->unk634++; + return; + } + + if ((FUN_0202CB8C() & 0xFFFE) != 0) + { + UNK_02105D58++; + FUN_020304D4(1); + + FUN_020303F4(0, UNK_021C59F4.unk04->unk000[UNK_021C59F4.unk04->unk67F], (u16)r4); + + UNK_021C59F4.unk04->unk67F = (u8)(1 - UNK_021C59F4.unk04->unk67F); + UNK_021C59F4.unk04->unk634++; + } +} + +#ifdef NONMATCHING +THUMB_FUNC void FUN_02030674() +{ + u16 r4 = 0; + if (UNK_021C59F4.unk04->unk62C == 0 || (UNK_021C59F4.unk04->unk628 & 0xf0) == 0) + { + return; + } + + if (UNK_021C59F4.unk04->unk62C == 2) + { + if ((UNK_021C59F4.unk04->unk628 & 0x20) != 0) + { + r4 = r4 | 0x10; + } + + if ((UNK_021C59F4.unk04->unk628 & 0x10) != 0) + { + r4 = r4 | 0x20; + } + + if ((UNK_021C59F4.unk04->unk628 & 0x40) != 0) + { + r4 = r4 | 0x80; + } + + if ((UNK_021C59F4.unk04->unk628 & 0x80) != 0) + { + r4 = r4 | 0x40; + } + } + else + { + if (UNK_021C59F4.unk04->unk62E != 0) + { + r4 = UNK_021C59F4.unk04->unk62E; + UNK_021C59F4.unk04->unk62D--; + + if (UNK_021C59F4.unk04->unk62D < 0) + { + UNK_021C59F4.unk04->unk62E = 0; + } + } + else + { + UNK_021C59F4.unk04->unk5F8[0] = + UNK_021C59F4.unk04->unk5F8[1] * UNK_021C59F4.unk04->unk5F8[0] + + UNK_021C59F4.unk04->unk5F8[2]; + + switch ((u32)(UNK_021C59F4.unk04->unk5F8[0] >> 0x3E) | (0 << 2)) + { + case 0: + r4 = 0x20; + break; + case 1: + r4 = 0x10; + break; + case 2: + r4 = 0x40; + break; + case 3: + r4 = 0x80; + break; + } + + UNK_021C59F4.unk04->unk5F8[0] = + UNK_021C59F4.unk04->unk5F8[2] + + UNK_021C59F4.unk04->unk5F8[1] * UNK_021C59F4.unk04->unk5F8[0]; + UNK_021C59F4.unk04->unk62D = UNK_021C59F4.unk04->unk5F8[0] >> 0x3c | (0 << 4); + UNK_021C59F4.unk04->unk62E = r4; + } + } + + UNK_021C59F4.unk04->unk628 &= ~0xf0; + UNK_021C59F4.unk04->unk628 += r4; +} +#else +THUMB_FUNC asm void FUN_02030674() +{ + // clang-format off + push {r3-r7, lr} + ldr r7, =UNK_021C59F4 + mov r6, #0x0 + ldr r5, [r7, #0x4] + ldr r2, =0x0000062C + add r4, r6, #0x0 + ldrb r0, [r5, r2] + cmp r0, #0x0 + beq _02030690 + sub r1, r2, #0x4 + ldrh r1, [r5, r1] + mov r3, #0xf0 + tst r3, r1 + bne _02030692 +_02030690: + b _02030794 +_02030692: + cmp r0, #0x2 + bne _020306D0 + mov r0, #0x20 + tst r0, r1 + beq _020306A4 + mov r0, #0x10 + orr r0, r6 + lsl r0, r0, #0x10 + lsr r4, r0, #0x10 +_020306A4: + mov r0, #0x10 + tst r0, r1 + beq _020306B2 + mov r0, #0x20 + orr r0, r4 + lsl r0, r0, #0x10 + lsr r4, r0, #0x10 +_020306B2: + mov r0, #0x40 + tst r0, r1 + beq _020306C0 + mov r0, #0x80 + orr r0, r4 + lsl r0, r0, #0x10 + lsr r4, r0, #0x10 +_020306C0: + mov r0, #0x80 + tst r0, r1 + beq _0203077E + mov r0, #0x40 + orr r0, r4 + lsl r0, r0, #0x10 + lsr r4, r0, #0x10 + b _0203077E +_020306D0: + add r0, r2, #0x2 + ldrh r0, [r5, r0] + cmp r0, #0x0 + beq _020306F2 + add r4, r0, #0x0 + add r0, r2, #0x1 + ldrsb r0, [r5, r0] + sub r1, r0, #0x1 + add r0, r2, #0x1 + strb r1, [r5, r0] + ldr r1, [r7, #0x4] + ldrsb r0, [r1, r0] + cmp r0, #0x0 + bge _0203077E + add r0, r2, #0x2 + strh r6, [r1, r0] + b _0203077E +_020306F2: + add r0, r2, #0x0 + sub r0, #0x34 + add r6, r5, r0 + sub r2, #0x34 + ldr r0, [r6, #0x8] + ldr r1, [r6, #0xc] + ldr r2, [r5, r2] + ldr r3, [r6, #0x4] + bl _ll_mul + add r3, r0, #0x0 + add r2, r1, #0x0 + ldr r0, [r6, #0x10] + ldr r1, [r6, #0x14] + add r0, r0, r3 + adc r1, r2 + ldr r2, =0x000005F8 + str r0, [r5, r2] + mov r2, #0x0 + str r1, [r6, #0x4] + lsr r0, r1, #0x1e + lsl r1, r2, #0x2 + orr r1, r0 + cmp r1, #0x3 + bhi _02030746 + add r0, r1, r1 + add r0, pc + ldrh r0, [r0, #0x6] + lsl r0, r0, #0x10 + asr r0, r0, #0x10 + add pc, r0 +_02030730: // jump table (using 16-bit offset) + // huge hack to get the correct jump offset. Is there a way to write constants? + lsl r6, r0, #0x0 // case 0 + lsl r2, r1, #0x0 // case 1 + lsl r6, r1, #0x0 // case 2 + lsl r2, r2, #0x0 // case 3 + + // intended jump offset + // .short _02030738 - _02030730 - 2; case 0 + // .short _0203073C - _02030730 - 2; case 1 + // .short _02030740 - _02030730 - 2; case 2 + // .short _02030744 - _02030730 - 2; case 3 +_02030738: + mov r4, #0x20 + b _02030746 +_0203073C: + mov r4, #0x10 + b _02030746 +_02030740: + mov r4, #0x40 + b _02030746 +_02030744: + mov r4, #0x80 +_02030746: + ldr r0, =UNK_021C59F4 + ldr r5, [r0, #0x4] + ldr r0, =0x000005F8 + add r6, r5, r0 + ldr r0, [r6, #0x8] + ldr r1, [r6, #0xc] + ldr r2, [r6, #0x0] + ldr r3, [r6, #0x4] + bl _ll_mul + ldr r3, [r6, #0x10] + ldr r2, [r6, #0x14] + add r0, r3, r0 + adc r2, r1 + ldr r1, =0x000005F8 + mov r3, #0x0 + str r0, [r5, r1] + str r2, [r6, #0x4] + lsr r0, r2, #0x1c + lsl r2, r3, #0x4 + orr r2, r0 + add r0, r1, #0x0 + add r0, #0x35 + strb r2, [r5, r0] + ldr r0, =UNK_021C59F4 + add r1, #0x36 + ldr r0, [r0, #0x4] + strh r4, [r0, r1] +_0203077E: + ldr r2, =UNK_021C59F4 + ldr r1, =0x00000628 + ldr r5, [r2, #0x4] + mov r0, #0xf0 + ldrh r3, [r5, r1] + bic r3, r0 + strh r3, [r5, r1] + ldr r2, [r2, #0x4] + ldrh r0, [r2, r1] + add r0, r0, r4 + strh r0, [r2, r1] +_02030794: + pop {r3-r7, pc} + // clang-format on +} +#endif + +THUMB_FUNC void FUN_020307A8() +{ + UNK_021C59F4.unk04->unk62C = 1; +} + +THUMB_FUNC void FUN_020307BC() +{ + UNK_021C59F4.unk04->unk62C = 2; +} + +THUMB_FUNC void FUN_020307D0() +{ + UNK_021C59F4.unk04->unk62C = 0; +} + +THUMB_FUNC u32 FUN_020307E4(u8 *param0, u32 param1) +{ + UNK_021C59F4.unk04->unk610[param1] = 0; + + int r7 = param0[0] & 0x10; + if (r7 == 0x10) + { + + u8 r5 = (u8)(param0[0] & 0xc); + if (r5 == 0) + { + UNK_021C59F4.unk04->unk610[param1] |= 0x40; + } + else if (r5 == 4) + { + UNK_021C59F4.unk04->unk610[param1] |= 0x80; + } + else if (r5 == 8) + { + UNK_021C59F4.unk04->unk610[param1] |= 0x20; + } + else if (r5 == 0xc) + { + UNK_021C59F4.unk04->unk610[param1] |= 0x10; + } + + UNK_021C59F4.unk04->unk620[param1] = (u8)((param0[0] >> 5) & 0x7); + } + + return 1; +} + +THUMB_FUNC void FUN_0203086C() +{ +} + +THUMB_FUNC u32 FUN_02030870(u8 *param0) +{ + if (UNK_021C59F4.unk04->unk62A != 0) + { + return 0; + } + + if (FUN_02030FE0() == 0) + { + return 0; + } + + if (UNK_021C59F4.unk04->unk681 != 0) + { + UNK_021C59F4.unk04->unk681--; + } + + if ((UNK_021C59F4.unk04->unk628 & 0x40) != 0) + { + param0[0] |= 0x10; + UNK_021C59F4.unk04->unk681 = 8; + } + else if ((UNK_021C59F4.unk04->unk628 & 0x80) != 0) + { + param0[0] |= 0x14; + UNK_021C59F4.unk04->unk681 = 8; + } + else if ((UNK_021C59F4.unk04->unk628 & 0x20) != 0) + { + param0[0] |= 0x18; + UNK_021C59F4.unk04->unk681 = 8; + } + else if ((UNK_021C59F4.unk04->unk628 & 0x10) != 0) + { + param0[0] |= 0x1c; + UNK_021C59F4.unk04->unk681 = 8; + } + + param0[0] |= UNK_021C59F4.unk04->unk62B << 5; + + return 0; +} + +THUMB_FUNC u32 FUN_02030930(u8 *param0) +{ + int r5 = FUN_02031228((u16)FUN_02033534()); + FUN_0202D858((u16)FUN_02033534()); + + if (UNK_021C59F4.unk04->unk684 == 0) + { + param0[0] = 0; + } + else + { + param0[0] = 1; + } + + if (FUN_0202FA28() == 0) + { + FUN_02030870(param0); + } + + UNK_021C59F4.unk04->unk684 = 0; + + if (FUN_0202D4E4(UNK_021C59F4.unk04->unk54C) != 0) + { + param0[0] |= 2; + if (param0[0] == 2) + { + return 0; + } + } + else + { + int st0[2]; + st0[1] = r5 - 1; + st0[0] = (int)param0 + 1; + if (FUN_0202D760(UNK_021C59F4.unk04->unk54C, st0, 1) == 0) + { + UNK_021C59F4.unk04->unk684 = 1; + } + + if (FUN_0202FA28() == 1) + { + UNK_021C59F4.unk04->unk65E++; + + param0[0] |= UNK_021C59F4.unk04->unk65E << 4 & 0xf0; + } + } + + return 1; +} + +THUMB_FUNC void FUN_02030A00(u8 *param0) +{ + param0[0] = 0xb; + if (UNK_021C59F4.unk04->unk685 == 0) + { + param0[1] = 0; + } + else + { + param0[1] = 1; + } + + u16 res = FUN_0202CB8C(); + param0[2] = (u8)(res >> 8); + param0[3] = (u8)res; + + int st0[2]; + st0[1] = 0xbb; + st0[0] = (int)param0 + 5; + if (FUN_0202D760(UNK_021C59F4.unk04->unk56C, st0, 0) != 0) + { + UNK_021C59F4.unk04->unk685 = 0; + param0[4] = (u8)(0xbb - st0[1]); + + return; + } + + UNK_021C59F4.unk04->unk685 = 1; + param0[4] = 0xbb; +} + +THUMB_FUNC u32 FUN_02030A78(u32 param0, u8 *param1, u32 param2) +{ + if (FUN_02030E7C(FUN_02031190()) == 0 && FUN_02031280() == 0) + { + return 0; + } + + if (FUN_0202D684(UNK_021C59F4.unk04->unk54C, param0, param1, param2, 1, 0) != 0) + { + return 1; + } + + if (FUN_02033534() == 0xa) + { + FUN_02031454(); + } + + return 0; +} + +THUMB_FUNC u32 FUN_02030ADC(u32 param0, u8 *param1, u32 param2) +{ + if (FUN_02030E7C(FUN_02031190()) == 0 && FUN_02031280() == 0) + { + return 0; + } + + if (FUN_0202D684(UNK_021C59F4.unk04->unk54C, param0, param1, param2, 1, 1) != 0) + { + return 1; + } + + if (FUN_02033534() == 0xa) + { + FUN_02031454(); + } + + return 0; +} + +THUMB_FUNC u32 FUN_02030B3C(u32 param0, u8 *param1, u32 param2) +{ + if (FUN_02031190() != 0) + { + ErrorHandling(); + return 0; + } + + if (FUN_02030E7C(0) == 0 && FUN_02031280() == 0) + { + return 0; + } + + if (FUN_0202FA28() == 1) + { + return FUN_02030A78(param0, param1, param2); + } + + if (FUN_0202D684(UNK_021C59F4.unk04->unk56C, param0, param1, param2, 1, 0) != 0) + { + return 1; + } + + if (FUN_02033534() == 0xa) + { + FUN_02031454(); + } + + return 0; +} + +THUMB_FUNC u32 FUN_02030BC4(u32 param0, u8 *param1, u32 param2) +{ + if (FUN_02031190() != 0) + { + FUN_02031454(); + return 0; + } + + if (FUN_02030E7C(0) == 0 && FUN_02031280() == 0) + { + return 0; + } + + if (FUN_0202FA28() == 1) + { + return FUN_02030ADC(param0, param1, param2); + } + + if (FUN_0202D684(UNK_021C59F4.unk04->unk56C, param0, param1, param2, 1, 1) != 0) + { + return 1; + } + + if (FUN_02033534() == 0xa) + { + FUN_02031454(); + } + + return 0; +} + +THUMB_FUNC u32 FUN_02030C4C(u32 param0, u8 *param1) +{ + return FUN_02030BC4(param0, param1, 0); +} + +THUMB_FUNC int FUN_02030C58() +{ + return FUN_0202D498(&UNK_021C59F4.unk04->unk464); +} + +THUMB_FUNC void FUN_02030C70( + u32 param0, u32 param1, u32 param2, void *param3, struct UnkStruct0202F150_sub2 *param4) +{ + FUN_0202D934(param0, param1, param2, param3); + param4->unk0a = 0xee; + param4->unk08 = 0xffff; + param4->unk04 = 0; + param4->unk00 = 0; +} + +THUMB_FUNC void FUN_02030C8C(struct UnkStruct0202F150_sub1 *param0, + u32 param1, + void *param2, + u32 param3, + struct UnkStruct0202F150_sub2 *param4) +{ +#pragma unused(param3) + while (FUN_0202D478(param0) != 0) + { + + u32 r7 = param4->unk0a; + if (r7 == 0xee) + { + r7 = FUN_0202D41C(param0); + if (r7 == 0xee) + { + continue; + } + } + + int st10 = param0->unk04; + param4->unk0a = (u8)r7; + int r4 = param4->unk08; + if (r4 == 0xffff) + { + r4 = FUN_0202D9A0(r7); + + if (UNK_021C59F4.unk04->unk689 != 0) + { + return; + } + + if (r4 == 0xffff) + { + if (FUN_0202D478(param0) < 1) + { + param0->unk04 = (s16)st10; + return; + } + + r4 = (int)FUN_0202D41C(param0) << 8; + r4 += FUN_0202D41C(param0); + + st10 = param0->unk04; + } + + param4->unk08 = (u16)r4; + } + + if (FUN_0202DA04(r7) != 0) + { + if (param4->unk04 == 0) + { + param4->unk04 = FUN_0202DA40(r7, param1, param4->unk08); + } + + int stc = FUN_0202D400(param0, param2, r4 - param4->unk00); + + if (param4->unk04 != 0) + { + MI_CpuCopy8(param2, param4->unk04 + param4->unk00, (u32)stc); + } + + if ((int)(param4->unk00 += stc) < (int)r4) + { + continue; + } + + FUN_02030C70(param1, r7, (u32)r4, param4->unk04, param4); + } + else + { + if (FUN_0202D478(param0) >= r4) + { + FUN_0202D400(param0, param2, (u32)r4); + FUN_02030C70(param1, r7, (u32)r4, param2, param4); + } + else + { + param0->unk04 = (s16)st10; + return; + } + } + } +} + +THUMB_FUNC void FUN_02030DA4() +{ + if (UNK_021C59F4.unk04 != NULL) + { + if (UNK_021C59F4.unk04->unk68B == 0) + { + FUN_0202D4BC(&UNK_021C59F4.unk04->unk470); + if (FUN_0202D478(&UNK_021C59F4.unk04->unk470) > 0) + { + FUN_02030C8C(&UNK_021C59F4.unk04->unk470, + 0, + UNK_021C59F4.unk04->unk460, + 1, + (struct UnkStruct0202F150_sub2 *)&UNK_021C59F4.unk04->unk5EC); + } + } + } +} + +THUMB_FUNC void FUN_02030DFC() +{ + if (UNK_021C59F4.unk04 != NULL) + { + if (UNK_021C59F4.unk04->unk68B == 0) + { + int r7 = (int)FUN_0202D858((u16)FUN_02033534()) + 1; + int r4; + for (r4 = 0; r4 < r7; r4++) + { + FUN_0202D4BC(&UNK_021C59F4.unk04->unk4E8[r4]); + if (FUN_0202D478(&UNK_021C59F4.unk04->unk4E8[r4]) > 0) + { + + FUN_02030C8C(&UNK_021C59F4.unk04->unk4E8[r4], + (u32)r4, + UNK_021C59F4.unk04->unk460, + 0, + &UNK_021C59F4.unk04->unk58C[r4]); + } + } + } + } +} + +THUMB_FUNC u32 FUN_02030E7C(u16 param0) +{ + if (UNK_021C59F4.unk04 == NULL) + { + return 0; + } + + if (FUN_02033534() >= 0x13) + { + if (UNK_021C59F4.unk04->unk687 != 0 && MOD04_021D8018() != 0xffffffff) + { + if (param0 == 0) + { + return 1; + } + + if (param0 == 1) + { + return 1; + } + } + + return 0; + } + + if (FUN_02030F40() == 0) + { + return 0; + } + + if (FUN_0202CBD4() != 4) + { + return 0; + } + + if (FUN_02031190() == param0) + { + return 1; + } + + if (FUN_02031190() == 0) + { + u16 r0 = FUN_0202CB8C(); + + if ((r0 & (1 << param0)) != 0) + { + return 1; + } + } + else + { + if ((UNK_021C59F4.unk04->unk65C & (1 << param0)) != 0) + { + return 1; + } + } + + return 0; +} + +THUMB_FUNC u32 FUN_02030F20() +{ + u32 r4 = 0; + for (int i = 0; i < 8; i++) + { + if (FUN_02030E7C((u16)i) != 0) + { + r4++; + } + } + + return r4; +} + +THUMB_FUNC u32 FUN_02030F40() +{ + if (UNK_021C59F4.unk04 != NULL && FUN_02033534() >= 0x13) + { + return 1; + } + + return FUN_0202EDF8(); +} + +THUMB_FUNC void FUN_02030F60(u8 param0) +{ + UNK_021C59F4.unk04->unk62B = param0; +} + +THUMB_FUNC u8 FUN_02030F74(u32 param0) +{ + return UNK_021C59F4.unk04->unk620[param0]; +} + +THUMB_FUNC u32 FUN_02030F88(u32 param0) +{ + if (UNK_021C59F4.unk04 == NULL) + { + return 0; + } + + u32 ret = UNK_021C59F4.unk04->unk610[param0]; + UNK_021C59F4.unk04->unk610[param0] = 0; + + return ret; +} + +THUMB_FUNC void FUN_02030FA8() +{ + if (UNK_021C59F4.unk04 != NULL) + { + UNK_021C59F4.unk04->unk628 |= 0x8000; + } +} + +THUMB_FUNC void FUN_02030FC8() +{ + if (UNK_021C59F4.unk04 != NULL) + { + UNK_021C59F4.unk04->unk628 = 0; + } +} + +THUMB_FUNC u32 FUN_02030FE0() +{ + if (UNK_021C59F4.unk04 != NULL) + { + return (u32)(UNK_021C59F4.unk04->unk628 & 0x8000); + } + + return 1; +} + +THUMB_FUNC void FUN_02031000(u32 param0, u8 *param1, u32 param2) +{ + if (FUN_0202FA28() == 1) + { + FUN_0202D684(UNK_021C59F4.unk04->unk54C, param0, param1, param2, 1, 0); + return; + } + + FUN_0202D684(UNK_021C59F4.unk04->unk56C, param0, param1, param2, 1, 0); +} + +THUMB_FUNC void FUN_0203105C(u32 param0, u8 *param1, u32 param2) +{ + FUN_0202D684(UNK_021C59F4.unk04->unk54C, param0, param1, param2, 0, 0); +} + +THUMB_FUNC void FUN_02031088() +{ + if (UNK_021C59F4.unk04 != NULL) + { + if (UNK_021C59F4.unk04->unk67B != 1) + { + if (UNK_021C59F4.unk04->unk67B != 3) + { + return; + } + } + else + { + u32 res; + if (FUN_0202FA28() == 1) + { + res = FUN_020311D0(0xb, &UNK_021C59F4.unk04->unk67C); + } + else + { + res = FUN_02030BC4(0xb, &UNK_021C59F4.unk04->unk67C, 1); + } + + if (res == 0) + { + return; + } + UNK_021C59F4.unk04->unk67B = 2; + return; + } + + if (FUN_020311D0(0xc, &UNK_021C59F4.unk04->unk67C) != 0) + { + FUN_0202F9E0(UNK_021C59F4.unk04->unk67C); + UNK_021C59F4.unk04->unk67B = 0; + } + } +} + +THUMB_FUNC void FUN_0203110C(u32 param0, u32 param1, u8 *param2) +{ +#pragma unused(param0) +#pragma unused(param1) + if (FUN_02031190() == 0) + { + UNK_021C59F4.unk04->unk67B = 1; + UNK_021C59F4.unk04->unk67C = param2[0]; + } +} + +THUMB_FUNC void FUN_02031134(u32 param0, u32 param1, u8 *param2) +{ +#pragma unused(param0) +#pragma unused(param1) + if (FUN_02031190() != 0) + { + UNK_021C59F4.unk04->unk67C = param2[0]; + UNK_021C59F4.unk04->unk67B = 3; + } +} + +THUMB_FUNC void FUN_0203115C(u32 param0, u32 param1, u8 *param2) +{ +#pragma unused(param0) +#pragma unused(param1) + if (FUN_02031190() == 0 && UNK_021C59F4.unk04->unk67B == 2) + { + FUN_0202F9E0(*param2); + UNK_021C59F4.unk04->unk67B = 0; + } +} + +THUMB_FUNC u16 FUN_02031190() +{ + if (UNK_021C59F4.unk04 != NULL) + { + if (FUN_02033534() >= 0x13) + { + u32 res = MOD04_021D8018(); + if (res != 0xffffffff) + { + return (u16)res; + } + } + else + { + if (FUN_02031280() != 0) + { + return 0; + } + + return FUN_0202D19C(); + } + } + + return 0; +} + +THUMB_FUNC u32 FUN_020311D0(u32 param0, u8 *param1) +{ + return FUN_02030ADC(param0, param1, 0); +} + +THUMB_FUNC u32 FUN_020311DC(u32 param0) +{ + return FUN_02030ADC(param0, 0, 0); +} + +THUMB_FUNC u32 FUN_020311E8() +{ + return FUN_0202EE24(); +} + +THUMB_FUNC u32 FUN_020311F0() +{ + if (FUN_02031280() != 0) + { + return 0; + } + + if (UNK_021C59F4.unk04 != NULL && UNK_021C59F4.unk04->unk689 != 0) + { + FUN_020334E8(1, 1); + return 1; + } + + return FUN_0202EE60(); +} + +THUMB_FUNC int FUN_02031228(u16 param0) +{ + if (FUN_0202D858(param0) >= 5) + { + return 0xc; + } + + if (FUN_0202FA28() == 0) + { + return 0xc; + } + + return 0x26; +} + +THUMB_FUNC u32 FUN_02031248(u32 param0) +{ + return FUN_0202D858((u16)param0) + 1; +} + +THUMB_FUNC u32 FUN_02031258(u32 param0) +{ + return FUN_0202D884((u16)param0) + 1; +} + +THUMB_FUNC void FUN_02031268(u8 param0) +{ + if (UNK_021C59F4.unk04 != NULL) + { + UNK_021C59F4.unk04->unk686 = param0; + } +} + +THUMB_FUNC u8 FUN_02031280() +{ + if (UNK_021C59F4.unk04 != NULL) + { + return UNK_021C59F4.unk04->unk686; + } + + return 0; +} + +THUMB_FUNC void FUN_0203129C() +{ + if (FUN_0202F03C() == 0 && FUN_02031190() == 0) + { + u8 st0; + FUN_02030C4C(2, &st0); + } + + FUN_0202F05C(); +} + +#ifdef NONMATCHING +THUMB_FUNC void FUN_020312BC(s64 *param0) +{ + RTCDate st10; + RTCTime st4; + GF_RTC_CopyDateTime(&st10, &st4); + + gMain.unk2C + st4.second; + u32 r6 = st10.year << 4 + st10.month; + u32 r5 = 0 << 4 | st10.year >> 0x1c; + st4.second; + + u32 st0 = st10.day; + st4.hour; + st4.minute; + + 0x00000000; + (0x00000000 + r5) << 5; +} +#else +THUMB_FUNC asm void FUN_020312BC(s64 *param0) +{ + // clang-format off + push {r3-r7, lr} + sub sp, #0x20 + add r4, r0, #0x0 + add r0, sp, #0x10 + add r1, sp, #0x4 + bl GF_RTC_CopyDateTime + ldr r0, =gMain + ldr r6, [sp, #0x10] + mov r5, #0x0 + lsr r7, r6, #0x1c + lsl r5, r5, #0x4 + ldr r1, [sp, #0xc] + ldr r0, [r0, #0x2c] + lsl r6, r6, #0x4 + add r3, r1, r0 + ldr r0, [sp, #0x18] + orr r5, r7 + str r0, [sp, #0x0] + ldr r0, [sp, #0x14] + ldr r1, [sp, #0x4] + add r6, r0, r6 + ldr r0, =0x00000000 + ldr r2, [sp, #0x8] + adc r0, r5 + lsr r5, r6, #0x1b + lsl r0, r0, #0x5 + orr r0, r5 + ldr r5, [sp, #0x0] + lsl r6, r6, #0x5 + add r6, r5, r6 + ldr r5, =0x00000000 + adc r5, r0 + lsr r0, r6, #0x1b + lsl r5, r5, #0x5 + orr r5, r0 + lsl r0, r6, #0x5 + add r6, r1, r0 + ldr r1, =0x00000000 + adc r1, r5 + lsr r0, r6, #0x1a + lsl r1, r1, #0x6 + orr r1, r0 + lsl r0, r6, #0x6 + add r5, r2, r0 + ldr r2, =0x00000000 + adc r2, r1 + lsr r0, r5, #0x1a + lsl r1, r2, #0x6 + orr r1, r0 + lsl r0, r5, #0x6 + add r2, r3, r0 + ldr r0, =0x00000000 + str r2, [r4, #0x0] + adc r0, r1 + str r0, [r4, #0x4] + ldr r1, =0x6C078965 + ldr r0, =0x5D588B65 + str r1, [r4, #0x8] + str r0, [r4, #0xc] + ldr r0, =0x00269EC3 + str r0, [r4, #0x10] + mov r0, #0x0 + str r0, [r4, #0x14] + add sp, #0x20 + pop {r3-r7, pc} + // clang-format on +} +#endif + +THUMB_FUNC void FUN_02031354(u32 param0) +{ + FUN_0202D830(UNK_021C59F4.unk04->unk56C, param0); +} + +THUMB_FUNC u32 FUN_02031370() +{ + return FUN_0202D4E4(UNK_021C59F4.unk04->unk56C); +} + +THUMB_FUNC u32 FUN_02031388() +{ + return FUN_0202D4E4(UNK_021C59F4.unk04->unk54C); +} + +THUMB_FUNC void FUN_020313A0(u8 param0) +{ + UNK_021C59F4.unk04->unk687 = param0; +} + +THUMB_FUNC void FUN_020313B4(u8 param0, u32 param1) +{ + if (UNK_021C59F4.unk04 != NULL) + { + UNK_021C59F4.unk04->unk677[param1] = param0; + } +} + +THUMB_FUNC u32 FUN_020313CC(u32 param0) +{ + if (UNK_021C59F4.unk04 != NULL) + { + if (UNK_021C59F4.unk04->unk677[param0] != 0xff) + { + return UNK_021C59F4.unk04->unk677[param0]; + } + } + + return param0; +} + +THUMB_FUNC u32 FUN_020313EC() +{ + if (FUN_02033534() < 0x13) + { + return 0; + } + + return MOD04_021D8624(); +} + +THUMB_FUNC void FUN_02031400(u32 param0) +{ + if (FUN_02033534() >= 0x13) + { + UNK_021C59F4.unk04->unk630 = param0; + if (param0 != 0) + { + UNK_021C59F4.unk04->unk634 = 0; + UNK_021C59F4.unk04->unk638[0] = 0; + UNK_021C59F4.unk04->unk638[1] = 0; + } + } +} + +THUMB_FUNC u32 FUN_02031438() +{ + if (UNK_021C59F4.unk04->unk681 != 0) + { + return 1; + } + + return 0; +} + +THUMB_FUNC void FUN_02031454() +{ + UNK_021C59F4.unk04->unk689 = 1; +} + +THUMB_FUNC void FUN_02031468() +{ + if (UNK_021C59F4.unk04 != NULL) + { + UNK_021C59F4.unk04->unk68A = 1; + } +}
\ No newline at end of file diff --git a/arm9/src/unk_0204AEA8.c b/arm9/src/unk_0204AEA8.c new file mode 100644 index 00000000..9c572a8e --- /dev/null +++ b/arm9/src/unk_0204AEA8.c @@ -0,0 +1,43 @@ +#include "global.h" +#include "heap.h" +#include "unk_0204639C.h" +#include "unk_0204AEA8.h" + +extern void MOD05_021E3444(u32, struct UnkStruct_0204639C *, u32); +extern void FUN_0200433C(u32, u16, u32); + +THUMB_FUNC BOOL FUN_0204AEA8(struct UnkStruct_0204639C *a0) +{ + struct UnkStruct_0204639C *v0 = FUN_02046528(a0); + u32 *v1 = FUN_0204652C(a0); + + switch (v1[0]) + { + case 0: + MOD05_021E3444(v1[2], v0, (u32)v1 + 4); + FUN_0200433C(5, (u16)v1[3], 1); + v1[0]++; + break; + case 1: + if (v1[1] == 1) + { + FreeToHeap(v1); + return TRUE; + } + break; + } + + return FALSE; +} + +THUMB_FUNC void FUN_0204AEF8(struct UnkStruct_0204639C *a0, u32 a1, u32 a2) +{ + u32 *v0 = AllocFromHeapAtEnd(11, 4 * sizeof(u32)); + + v0[0] = 0; + v0[1] = 0; + v0[2] = a1; + v0[3] = a2; + + FUN_0204640C(a0, FUN_0204AEA8, v0); +} diff --git a/arm9/src/unk_0205FA2C.c b/arm9/src/unk_0205FA2C.c new file mode 100644 index 00000000..7bcdf950 --- /dev/null +++ b/arm9/src/unk_0205FA2C.c @@ -0,0 +1,543 @@ +#include "unk_0205FA2C.h" + +extern void *UNK_020F96DC; +extern void *UNK_020FA6E8; +extern u32 FUN_02079C70(struct SaveBlock2 *sav2); +extern void FUN_0207B000(struct UnkPlayerStruct2_0205FA2C *ptr, const u8 param1[12]); +extern void FUN_0207C2A4(struct UnkPlayerStruct2_0205FA2C *ptr, struct PlayerData *player_data); +extern u32 FUN_0203384C(u32 *param0); +extern u32 *FUN_02038790(struct UnkStruct_0204639C *param0, u16 param1, u16 param2); +extern u16 *GetVarPointer(struct UnkSavStruct80 *arg, u16); +extern u32 FUN_02031190(); +extern u32 FUN_020316E0(u32 param0); +extern u16 MOD06_02244660(struct UnkStruct_0204639C *param0, u32 param1); +extern u16 MOD06_022446BC(struct UnkStruct_0204639C *param0, u32 param1); +extern u16 MOD06_022446E0(struct UnkStruct_0204639C *param0, u32 param1); +extern void FUN_0202A5CC(u32 param0, u32 param1); +extern u32 FUN_0202A5D0(u32 param0); +extern u32 FUN_0202A150(struct UnkStruct_02029FB0 *param0, u32 param1); +extern u32 FUN_0202A8D8(struct SaveBlock2 *sav2); +extern u32 FUN_0202A578(u32 param0, u32 param1, u32 param2); +extern u32 FUN_02026CC4(struct SaveBlock2 *sav2); +extern u32 FUN_02025D94(u32 param0, u32 param1); +extern u32 FUN_0202A8CC(struct SaveBlock2 *sav2); +extern void FUN_0202A2C4(u32 param0, u32 param1, u32 *param2); +extern u32 FUN_0202A240(u32 param0, u32 param1, u32 param2); +extern int FUN_0202A538(u32 param0, u16 param1, u32 param2); + +const u8 UNK_020F7454[] = { + 0x00, + 0x01, + 0x02, + 0x04, + 0x03, + 0x05, + 0x06, + 0x07, + 0x08, +}; + +THUMB_FUNC u32 FUN_0205FA2C( + struct UnkCallbackStruct1_0205FA2C *param0, struct UnkStruct_0204639C *param1, u32 heap_id) +{ + struct UnkPlayerStruct1_0205FA2C *ptr = (struct UnkPlayerStruct1_0205FA2C *)AllocFromHeapAtEnd( + heap_id, sizeof(struct UnkPlayerStruct1_0205FA2C)); + + struct SaveBlock2 *sav2 = (struct SaveBlock2 *)(param1->unkC); + MI_CpuFill8(ptr, 0, sizeof(struct UnkPlayerStruct1_0205FA2C)); + + ptr->options = Sav2_PlayerData_GetOptionsAddr(sav2); + + ptr->player_party = SavArray_PlayerParty_get(sav2); + + ptr->bag = Sav2_Bag_get(sav2); + + ptr->unk21 = 0; + ptr->unk20 = param0->unk08; + ptr->unk32 = param0->unk0a; + ptr->unk322 = param0->unk0b; + ptr->unk33 = param0->unk0c; + ptr->unk22 = param0->unk0d; + + for (u8 i = 0; i < 6; i++) + { + ptr->unk2c[i] = param0->unk0e[i]; + } + + FUN_020373D4(param1, (u32)&UNK_020F96DC, (u32)ptr); + + *param0->unk14 = ptr; + + return 1; +} + +THUMB_FUNC u32 FUN_0205FAD8( + struct UnkCallbackStruct1_0205FA2C *param0, struct UnkStruct_0204639C *param1) +{ + if (FUN_0204647C(param1)) + { + return 1; + } + + struct UnkPlayerStruct1_0205FA2C *ptr = (struct UnkPlayerStruct1_0205FA2C *)*param0->unk14; + + u8 r1 = ptr->unk22; + if (r1 != 6) + { + if (r1 == 7) + { + param0->unk00 = 0; + return 4; + } + } + else + { + param0->unk00 = 1; + return 4; + } + + MI_CpuCopy8(ptr->unk2c, param0->unk0e, 6); + + param0->unk0d = ptr->unk22; + FreeToHeap(ptr); + + *param0->unk14 = NULL; + + return 2; +} + +THUMB_FUNC u32 FUN_0205FB34( + struct UnkCallbackStruct1_0205FA2C *param0, struct UnkStruct_0204639C *param1, u32 heap_id) +{ + struct SaveBlock2 *sav2 = (struct SaveBlock2 *)(param1->unkC); + + struct UnkPlayerStruct2_0205FA2C *ptr = (struct UnkPlayerStruct2_0205FA2C *)AllocFromHeapAtEnd( + heap_id, sizeof(struct UnkPlayerStruct2_0205FA2C)); + MI_CpuFill8(ptr, 0, sizeof(struct UnkPlayerStruct2_0205FA2C)); + + ptr->options = Sav2_PlayerData_GetOptionsAddr(sav2); + ptr->player_party = SavArray_PlayerParty_get(sav2); + ptr->IsNatDex = SavArray_IsNatDexEnabled(sav2); + ptr->unk2c = FUN_02079C70(sav2); + + ptr->unk11 = 1; + ptr->unk14 = param0->unk0d; + + ptr->party_count = (u8)GetPartyCount(ptr->player_party); + + ptr->unk18 = 0; + ptr->unk12 = param0->unk09; + + ptr->unk20 = FUN_0202A918(sav2); + + FUN_0207B000(ptr, UNK_020F7454); + + FUN_0207C2A4(ptr, Sav2_PlayerData_GetProfileAddr(sav2)); + + FUN_020373D4(param1, (u32)&UNK_020FA6E8, (u32)ptr); + + *param0->unk14 = ptr; + + return 3; +} + +THUMB_FUNC u32 FUN_0205FBC0( + struct UnkCallbackStruct1_0205FA2C *param0, struct UnkStruct_0204639C *param1) +{ + if (FUN_0204647C(param1)) + { + return 3; + } + + struct UnkPlayerStruct2_0205FA2C *ptr = (struct UnkPlayerStruct2_0205FA2C *)*param0->unk14; + param0->unk0d = ptr->unk14; + FreeToHeap(ptr); + + *param0->unk14 = NULL; + + return 0; +} + +THUMB_FUNC int FUN_0205FBE8(struct UnkStruct_0204639C *param0) +{ + struct UnkStruct_0204639C *res = FUN_02046528(param0); + struct UnkCallbackStruct1_0205FA2C *res2 = + (struct UnkCallbackStruct1_0205FA2C *)FUN_0204652C(param0); + switch (res2->unk04) + { + case 0: + res2->unk04 = FUN_0205FA2C(res2, res, 0xb); + break; + case 1: + res2->unk04 = FUN_0205FAD8(res2, res); + break; + case 2: + res2->unk04 = FUN_0205FB34(res2, res, 0xb); + break; + case 3: + res2->unk04 = FUN_0205FBC0(res2, res); + break; + case 4: + FreeToHeap(res2); + return 1; + } + + return 0; +} + +THUMB_FUNC void FUN_0205FC50(struct UnkStruct_0204639C *param0, + void **param1, + u8 param2, + u8 param3, + u8 param4, + u8 param5, + u8 param6, + u8 param7) +{ + struct UnkStruct_0204639C *res = FUN_02046528(param0); + + struct UnkCallbackStruct1_0205FA2C *ptr = (struct UnkCallbackStruct1_0205FA2C *)AllocFromHeap( + 0xb, sizeof(struct UnkCallbackStruct1_0205FA2C)); + MI_CpuFill8(ptr, 0, sizeof(struct UnkCallbackStruct1_0205FA2C)); + + ptr->unk08 = param2; + ptr->unk09 = param3; + ptr->unk0a = param4; + ptr->unk0b = param5; + ptr->unk0c = param6; + ptr->unk0d = param7; + ptr->unk14 = param1; + + FUN_0204640C(res->unk10, &FUN_0205FBE8, (u32 *)ptr); +} + +THUMB_FUNC u32 FUN_0205FC9C( + struct UnkCallbackStruct2_0205FA2C *param0, struct UnkStruct_0204639C *param1) +{ + if (FUN_0203384C(param1->unkC)) + { + + param0->unk08 = FUN_02038790(param1, param0->unk12, param0->unk14); + return 1; + } + + param0->unk00 = 1; + return 2; +} + +THUMB_FUNC u32 FUN_0205FCC4( + struct UnkCallbackStruct2_0205FA2C *param0, struct UnkStruct_0204639C *param1) +{ + if (FUN_0204647C(param1)) + { + return 1; + } + + param0->unk00 = param0->unk08[8]; + FreeToHeap(param0->unk08); + + return 2; +} + +THUMB_FUNC int FUN_0205FCE8(struct UnkStruct_0204639C *param0) +{ + struct UnkStruct_0204639C *res = FUN_02046528(param0); + struct UnkCallbackStruct2_0205FA2C *res2 = + (struct UnkCallbackStruct2_0205FA2C *)FUN_0204652C(param0); + + switch (res2->unk04) + { + case 0: + res2->unk04 = FUN_0205FC9C(res2, res); + break; + case 1: + res2->unk04 = FUN_0205FCC4(res2, res); + break; + case 2: + u16 *var = GetVarPointer((struct UnkSavStruct80 *)res, res2->unk10); + *var = (u16)res2->unk00; + FreeToHeap(res2); + + return 1; + } + + return 0; +} + +THUMB_FUNC void FUN_0205FD38(struct UnkStruct_0204639C *param0, u16 param1, u16 param2, u16 param3) +{ + struct UnkStruct_0204639C *res = FUN_02046528(param0); + struct UnkCallbackStruct2_0205FA2C *ptr = (struct UnkCallbackStruct2_0205FA2C *)AllocFromHeap( + 0xb, sizeof(struct UnkCallbackStruct2_0205FA2C)); + MI_CpuFill8(ptr, 0, sizeof(struct UnkCallbackStruct2_0205FA2C)); + + ptr->unk12 = param1; + ptr->unk14 = param3; + ptr->unk10 = param2; + + FUN_0204640C(res->unk10, &FUN_0205FCE8, (u32 *)ptr); +} + +THUMB_FUNC int FUN_0205FD70(struct UnkStruct_0204639C *param0) +{ + struct UnkStruct_0204639C *res = FUN_02046528(param0); + u16 *res2 = (u16 *)FUN_0204652C(param0); + u32 res3 = FUN_020316E0(1 - FUN_02031190()); + if (res3 == 0) + { + return 0; + } + + u16 *var = GetVarPointer((struct UnkSavStruct80 *)res, res2[1]); + switch (res2[0]) + { + case 0: + *var = MOD06_02244660(res, res3); + break; + case 1: + *var = MOD06_022446BC(res, res3); + + break; + case 2: + *var = MOD06_022446E0(res, res3); + + break; + } + + FreeToHeap(res2); + + return 1; +} + +THUMB_FUNC void FUN_0205FDDC(struct UnkStruct_0204639C *param0, u16 param1, u16 param2) +{ + struct UnkStruct_0204639C *res = FUN_02046528(param0); + + u16 *ptr = AllocFromHeap(0xb, 2 * sizeof(u16)); + MI_CpuFill8(ptr, 0, 2 * sizeof(u16)); + + ptr[0] = param1; + ptr[1] = param2; + + FUN_0204640C(res->unk10, &FUN_0205FD70, (u32 *)ptr); +} + +THUMB_FUNC u32 FUN_0205FE10(struct SaveBlock2 *sav2) +{ + + u16 res = (u16)FUN_0202A150(FUN_02029FC8(sav2), 0x35); + if (res < 20) + { + return 0; + } + + u32 res2 = FUN_0202A8D8(sav2); + + u8 res3 = (u8)FUN_0202A578(res2, 0xd, 0); + u8 res4 = (u8)FUN_0202A578(res2, 0, 0); + u8 res5 = (u8)FUN_0202A578(res2, 1, 0); + + u8 res6 = (u8)FUN_0202A578(res2, 0xe, 0); + u8 res7 = (u8)FUN_0202A578(res2, 2, 0); + u8 res8 = (u8)FUN_0202A578(res2, 3, 0); + + if (res3 != 0 && res4 != 0 && res5 != 0) + { + return 0; + } + + u32 res9 = FUN_02026CC4(sav2); + if (res3 == 0) + { + if (FUN_02025D94(res9, 0x55) != 0) + { + FUN_0202A578(res2, 0xd, 1); + return 1; + } + + if (res6 == 0) + { + FUN_0202A578(res2, 0xe, 1); + } + + return 4; + } + + if (res < 50) + { + return 0; + } + + if (res4 == 0) + { + if (FUN_02025D94(res9, 0x56) != 0) + { + FUN_0202A578(res2, 0, 1); + return 2; + } + + if (res7 == 0) + { + FUN_0202A578(res2, 2, 1); + } + + return 4; + } + + if (res < 100 || res5 != 0) + { + return 0; + } + + if (FUN_02025D94(res9, 0x57) != 0) + { + FUN_0202A578(res2, 1, 1); + return 3; + } + + if (res8 == 0) + { + FUN_0202A578(res2, 3, 1); + } + + return 4; +} + +THUMB_FUNC u32 FUN_0205FF5C(struct SaveBlock2 *sav2) +{ + u16 res = (u16)FUN_0202A150(FUN_02029FC8(sav2), 0x35); + if (res < 20) + { + return 0; + } + + u32 res2 = FUN_0202A8D8(sav2); + + u8 res3 = (u8)FUN_0202A578(res2, 0xd, 0); + u8 res4 = (u8)FUN_0202A578(res2, 0, 0); + u8 res5 = (u8)FUN_0202A578(res2, 1, 0); + + u8 res6 = (u8)FUN_0202A578(res2, 0xe, 0); + u8 res7 = (u8)FUN_0202A578(res2, 2, 0); + u8 res8 = (u8)FUN_0202A578(res2, 3, 0); + + if (res3 != 0 && res4 != 0 && res5 != 0) + { + return 0; + } + + if (res3 == 0) + { + if (res6 != 0) + { + return 4; + } + + return 1; + } + + if (res < 50) + { + return 0; + } + + if (res4 == 0) + { + if (res7 != 0) + { + return 5; + } + + return 2; + } + + if (res < 100) + { + return 0; + } + + if (res5 != 0) + { + return 0; + } + + if (res8 != 0) + { + return 6; + } + + return 3; +} + +THUMB_FUNC void FUN_02060044(u16 **param0, u32 *param1) +{ + u16 *ptr = param0[42]; + + ptr[18] += param1[0]; + ptr[20] += param1[1]; + ptr[19] += param1[2]; +} + +THUMB_FUNC u32 FUN_02060064(u32 param0) +{ + return param0 * 0x02E90EDD + 1; +} + +THUMB_FUNC u32 FUN_02060070(u32 param0) +{ + return param0 * 0x5D588B65 + 1; +} + +THUMB_FUNC u32 FUN_0206007C(struct SaveBlock2 *sav2) +{ + u32 res = FUN_02060070(FUN_020287A4(FUN_0202881C(sav2))); + + FUN_0202A5CC(FUN_0202A8D8(sav2), res); + + return res; +} + +THUMB_FUNC u32 FUN_020600A0(struct SaveBlock2 *sav2) +{ + u32 res = FUN_0202A8D8(sav2); + + u32 res2 = FUN_02060070(FUN_0202A5D0(res)); + + FUN_0202A5CC(res, res2); + u32 res3 = FUN_02060064(res2); + + FUN_0202A2C4(FUN_0202A8CC(sav2), 0xa, &res3); + + return res3; +} + +THUMB_FUNC u32 FUN_020600DC(struct SaveBlock2 *sav2) +{ + u32 res = FUN_0202A8D8(sav2); + + u32 res2 = FUN_0202A8CC(sav2); + + u32 res3 = FUN_02060064(FUN_0202A5D0(res)); + + int i = 0; + int res4 = FUN_0202A538(res, (u16)FUN_0202A240(res2, 0, 0), 0) * 0x18; + + for (i = 0; i < res4; i++) + { + res3 = FUN_02060064(res3); + } + + FUN_0202A2C4(FUN_0202A8CC(sav2), 0xa, &res3); + + return res3; +} + +THUMB_FUNC BOOL FUN_02060144(u32 **param0) +{ + if (param0[7][0] == SPECIES_ARCEUS) + { + return TRUE; + } + + return FALSE; +} diff --git a/arm9/src/unk_02064E4C.c b/arm9/src/unk_02064E4C.c index 1e9f8515..90ff8340 100644 --- a/arm9/src/unk_02064E4C.c +++ b/arm9/src/unk_02064E4C.c @@ -16,7 +16,7 @@ void FUN_02064E4C(struct MsgData * msgData, u16 map_sec, struct String * dest) void FUN_02064E60(u32 map_no, u32 heap_id, struct String * dest) { struct MsgData * msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 382, heap_id); - u16 map_sec = FUN_02034824(map_no); + u16 map_sec = MapHeader_GetMapSec(map_no); FUN_02064E4C(msgData, map_sec, dest); diff --git a/arm9/src/unk_0206BB28.c b/arm9/src/unk_0206BB28.c index baaecc6a..e7c12793 100644 --- a/arm9/src/unk_0206BB28.c +++ b/arm9/src/unk_0206BB28.c @@ -6,12 +6,12 @@ #pragma thumb on -BOOL FUN_0206BB28(struct SaveBlock2 * sav2) +BOOL SavArray_IsNatDexEnabled(struct SaveBlock2 * sav2) { - return FUN_0206BB34(Sav2_Pokedex_get(sav2)); + return Pokedex_IsNatDexEnabled(Sav2_Pokedex_get(sav2)); } -BOOL FUN_0206BB34(struct Pokedex * pokedex) +BOOL Pokedex_IsNatDexEnabled(struct Pokedex * pokedex) { return Pokedex_GetNatDexFlag(pokedex) == TRUE; } |