summaryrefslogtreecommitdiff
path: root/arm9/src/scrcmd_coins.c
blob: f4fea1def49b18a72dfa232f00911a25d712135c (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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_ShowCoinBox(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_HideCoinBox(struct ScriptContext * ctx)
{
    u16 ** unk = FUN_02039438(ctx->unk80, 0x26);
    MOD05_021E29B4(*unk);

    return FALSE;
}

THUMB_FUNC BOOL ScrCmd_UpdateCoinBox(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;
}