summaryrefslogtreecommitdiff
path: root/arm9/src/scrcmd_13.c
blob: 3b21facc15ca2ec892feccf7cbe6358d86b25f20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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;
}