diff options
author | tgsm <doodrabbit@hotmail.com> | 2021-03-31 09:47:13 -0400 |
---|---|---|
committer | tgsm <doodrabbit@hotmail.com> | 2021-04-02 06:42:22 -0400 |
commit | 9bff34f5ed78da1c6dea8e6a5a19458160616029 (patch) | |
tree | 23228f1ce48eb0e4422fca42e47bc78fe4276e3f | |
parent | ffe1c98ccdc3a1dc14297b50b0cee7dd4ec94338 (diff) |
Decompile scrcmd_13
-rw-r--r-- | arm9/asm/scrcmd_13.s | 220 | ||||
-rw-r--r-- | arm9/asm/unk_02038C78.s | 8 | ||||
-rw-r--r-- | arm9/global.inc | 8 | ||||
-rw-r--r-- | arm9/src/scrcmd_13.c | 111 | ||||
-rw-r--r-- | include/scrcmd.h | 6 |
5 files changed, 125 insertions, 228 deletions
diff --git a/arm9/asm/scrcmd_13.s b/arm9/asm/scrcmd_13.s deleted file mode 100644 index 1b31ce71..00000000 --- a/arm9/asm/scrcmd_13.s +++ /dev/null @@ -1,220 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .text - - thumb_func_start FUN_0204387C -FUN_0204387C: ; 0x0204387C - push {r3-r5, lr} - add r5, r0, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - ldr r0, [r0, #0xc] - bl SavArray_Flags_get - add r4, r0, #0x0 - add r0, r5, #0x0 - bl ScriptReadHalfword - add r1, r0, #0x0 - add r0, r5, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - bl VarGet - cmp r0, #0x0 - bne _020438B2 - add r0, r4, #0x0 - bl FUN_0205F224 - add r5, #0x80 - ldr r0, [r5, #0x0] - bl FUN_0204B9EC - b _020438CA -_020438B2: - cmp r0, #0x1 - bne _020438C6 - add r0, r4, #0x0 - bl FUN_0205F234 - add r5, #0x80 - ldr r0, [r5, #0x0] - bl FUN_0204BA1C - b _020438CA -_020438C6: - bl ErrorHandling -_020438CA: - mov r0, #0x0 - pop {r3-r5, pc} - .balign 4 - - thumb_func_start FUN_020438D0 -FUN_020438D0: ; 0x020438D0 - push {r4-r6, lr} - add r4, r0, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - ldr r0, [r0, #0xc] - bl FUN_02022528 - add r6, r0, #0x0 - mov r0, #0x20 - bl AllocMonZeroed - add r5, r0, #0x0 - add r0, r4, #0x0 - bl ScriptReadHalfword - add r4, #0x80 - add r1, r0, #0x0 - ldr r0, [r4, #0x0] - bl GetVarPointer - add r4, r0, #0x0 - add r0, r6, #0x0 - bl FUN_0202C000 - cmp r0, #0x6 - bne _02043908 - mov r0, #0x1 - b _0204390A -_02043908: - mov r0, #0x0 -_0204390A: - strh r0, [r4, #0x0] - add r0, r5, #0x0 - bl FreeToHeap - mov r0, #0x0 - pop {r4-r6, pc} - .balign 4 - - thumb_func_start FUN_02043918 -FUN_02043918: ; 0x02043918 - push {r4-r7, lr} - sub sp, #0xc - add r6, r0, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - ldr r0, [r0, #0xc] - bl FUN_02022528 - add r7, r0, #0x0 - add r0, r6, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - ldr r0, [r0, #0xc] - bl GetStoragePCPointer - str r0, [sp, #0x8] - mov r0, #0x20 - bl AllocMonZeroed - add r4, r0, #0x0 - add r0, r6, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - ldr r0, [r0, #0xc] - bl Sav2_PlayerData_GetProfileAddr - str r0, [sp, #0x4] - add r0, r6, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - ldr r0, [r0, #0xc] - bl Sav2_Pokedex_get - mov r5, #0x0 -_0204395C: - add r0, r7, #0x0 - add r1, r5, #0x0 - add r2, r4, #0x0 - bl FUN_0202BFD8 - mov r0, #0x20 - str r0, [sp, #0x0] - ldr r1, [sp, #0x4] - add r0, r4, #0x0 - mov r2, #0x2 - mov r3, #0x0 - bl FUN_0208089C - add r0, r4, #0x0 - bl FUN_020690E4 - add r1, r0, #0x0 - ldr r0, [sp, #0x8] - bl PCStorage_PlaceMonInFirstEmptySlotInAnyBox - cmp r0, #0x0 - bne _0204398C - bl ErrorHandling -_0204398C: - add r0, r6, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - add r1, r4, #0x0 - ldr r0, [r0, #0xc] - bl FUN_0202C144 - add r5, r5, #0x1 - cmp r5, #0x6 - blt _0204395C - add r0, r4, #0x0 - bl FreeToHeap - add r0, r7, #0x0 - bl FUN_0202BEDC - mov r0, #0x0 - add sp, #0xc - pop {r4-r7, pc} - .balign 4 - - thumb_func_start FUN_020439B4 -FUN_020439B4: ; 0x020439B4 - push {r3-r7, lr} - add r4, r0, #0x0 - bl ScriptReadHalfword - add r1, r0, #0x0 - add r0, r4, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - bl VarGet - add r6, r0, #0x0 - add r0, r4, #0x0 - bl ScriptReadHalfword - add r1, r0, #0x0 - add r0, r4, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - bl GetVarPointer - add r5, r0, #0x0 - cmp r6, #0x3 - bhi _02043A40 - add r0, r6, r6 - add r0, pc - ldrh r0, [r0, #0x6] - lsl r0, r0, #0x10 - asr r0, r0, #0x10 - add pc, r0 -_020439EE: ; jump table (using 16-bit offset) - .short _020439F6 - _020439EE - 2; case 0 - .short _02043A02 - _020439EE - 2; case 1 - .short _02043A0E - _020439EE - 2; case 2 - .short _02043A1A - _020439EE - 2; case 3 -_020439F6: - add r4, #0x80 - ldr r0, [r4, #0x0] - bl FUN_0204BAC4 - strh r0, [r5, #0x0] - b _02043A40 -_02043A02: - add r4, #0x80 - ldr r0, [r4, #0x0] - bl FUN_0204BAD4 - strh r0, [r5, #0x0] - b _02043A40 -_02043A0E: - add r4, #0x80 - ldr r0, [r4, #0x0] - bl FUN_0204BAE4 - strh r0, [r5, #0x0] - b _02043A40 -_02043A1A: - add r0, r4, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - bl FUN_0204BAD4 - add r6, r0, #0x0 - add r0, r4, #0x0 - add r0, #0x80 - ldr r0, [r0, #0x0] - bl FUN_0204BAC4 - add r4, #0x80 - add r7, r0, #0x0 - ldr r0, [r4, #0x0] - bl FUN_0204BAE4 - add r0, r7, r0 - add r0, r6, r0 - strh r0, [r5, #0x0] -_02043A40: - mov r0, #0x0 - pop {r3-r7, pc} diff --git a/arm9/asm/unk_02038C78.s b/arm9/asm/unk_02038C78.s index 4b80024a..a5037d01 100644 --- a/arm9/asm/unk_02038C78.s +++ b/arm9/asm/unk_02038C78.s @@ -744,10 +744,10 @@ gScriptCmdTable: ; 0x020F355C .word FUN_02041340 .word FUN_02040964 .word ScrCmd_pcfreespace - .word FUN_0204387C - .word FUN_020438D0 - .word FUN_02043918 - .word FUN_020439B4 + .word ScrCmd_Unk0253 + .word ScrCmd_Unk0254 + .word ScrCmd_Unk0255 + .word ScrCmd_Unk0256 .word FUN_0203FE80 .word FUN_0203EDA4 .word FUN_0203EDC8 diff --git a/arm9/global.inc b/arm9/global.inc index d5d12155..63ab1566 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -3274,10 +3274,10 @@ .extern FUN_02042C8C .extern FUN_02042CBC .extern FUN_02042D1C -.extern FUN_0204387C -.extern FUN_020438D0 -.extern FUN_02043918 -.extern FUN_020439B4 +.extern ScrCmd_Unk0253 +.extern ScrCmd_Unk0254 +.extern ScrCmd_Unk0255 +.extern ScrCmd_Unk0256 .extern ScrCmd_Unk0075 .extern ScrCmd_Unk0076 .extern ScrCmd_Unk0077 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/include/scrcmd.h b/include/scrcmd.h index dd43e586..4c155f0b 100644 --- a/include/scrcmd.h +++ b/include/scrcmd.h @@ -106,6 +106,12 @@ BOOL ScrCmd_Unk0048(struct ScriptContext *ctx); BOOL ScrCmd_Unk02CF(struct ScriptContext *ctx); BOOL ScrCmd_Unk02D0(struct ScriptContext *ctx); +//scrcmd_13.c +BOOL ScrCmd_Unk0253(struct ScriptContext* ctx); +BOOL ScrCmd_Unk0254(struct ScriptContext* ctx); +BOOL ScrCmd_Unk0255(struct ScriptContext* ctx); +BOOL ScrCmd_Unk0256(struct ScriptContext* ctx); + //scrcmd_coins.c BOOL ScrCmd_Unk0075(struct ScriptContext* ctx); BOOL ScrCmd_Unk0076(struct ScriptContext* ctx); |