summaryrefslogtreecommitdiff
path: root/arm9/src/bag_view.c
blob: 31d53861433bbd8ca518bbac413161869c9ce613 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "global.h"
#include "bag_view.h"
#include "coins.h"
#include "constants/items.h"
#include "heap.h"
#include "msgdata.h"
#include "player_data.h"
#include "script_buffers.h"
#include "seal.h"
#include "unk_0202A1E0.h"

extern u32 *FUN_0202708C(u32 *);
extern u32 FUN_02027168(u32 *);
extern u16 FUN_02027184(u32 *);
extern u32 *FUN_02027E24(struct SaveBlock2 *sav2);
extern u8 FUN_02029E2C(struct SealCase *, u32);

THUMB_FUNC struct BagView *BagView_New(u8 heap_id)
{
    struct BagView *ptr = AllocFromHeap(heap_id, sizeof(struct BagView));

    memset(ptr, 0, sizeof(struct BagView));

    return ptr;
}

THUMB_FUNC u32 BagView_sizeof()
{
    return sizeof(struct BagView);
}

THUMB_FUNC void FUN_0206E30C(struct BagView *bag_view, u8 r1)
{
    bag_view->unk65 = r1;
}

THUMB_FUNC void FUN_0206E314(
    struct BagView *bag_view, struct SaveBlock2 *sav2, u8 r2, struct UnkStruct_0206F164 *r3)
{
    FUN_0206E30C(bag_view, r2);

    bag_view->sav2 = sav2;
    bag_view->unk6C = r3;
    bag_view->unk66 = 0;
}

THUMB_FUNC void BagView_SetItem(struct BagView *bag_view, struct ItemSlot *slot, u8 pocket, u8 idx)
{
    bag_view->slots[idx].slot = slot;
    bag_view->slots[idx].pocket = pocket;
}

THUMB_FUNC void FUN_0206E340(struct BagView *bag_view)
{
    bag_view->unk76 = 1;
}

THUMB_FUNC void FUN_0206E354(struct BagView *bag_view, u32 r1)
{
    bag_view->unk70 = r1;
}

THUMB_FUNC void FUN_0206E358(struct BagView *bag_view, u8 r1)
{
    bag_view->unk74 = r1;
}

THUMB_FUNC void FUN_0206E360(struct BagView *bag_view, u16 r1)
{
    bag_view->unk76_2 = r1;
}

THUMB_FUNC u16 FUN_0206E37C(struct BagView *bag_view)
{
    return bag_view->unk66;
}

THUMB_FUNC u16 FUN_0206E384(struct BagView *bag_view)
{
    return bag_view->unk68;
}

THUMB_FUNC u8 FUN_0206E38C(struct BagView *bag_view)
{
    return bag_view->unk74;
}

THUMB_FUNC u8 FUN_0206E394(struct BagView *bag_view)
{
    return bag_view->unk75;
}

THUMB_FUNC u32 FUN_0206E39C(struct SaveBlock2 *sav2)
{
    return (u32)CheckCoins(Sav2_PlayerData_GetCoinsAddr(sav2));
}

THUMB_FUNC u32 FUN_0206E3A8(struct SaveBlock2 *sav2)
{
    struct SealCase *seal_case = Sav2_SealCase_get(sav2);
    u32 i;
    u32 count = 0;

    for (i = 1; i <= 0x50; ++i)
    {
        count += FUN_02029E2C(seal_case, i);
    }

    return count;
}

THUMB_FUNC u32 FUN_0206E3C8(struct SaveBlock2 *sav2)
{
    return FUN_02027168(FUN_0202708C(FUN_02027E24(sav2)));
}

THUMB_FUNC u32 FUN_0206E3D8(struct SaveBlock2 *sav2)
{
    return FUN_02027184(FUN_0202708C(FUN_02027E24(sav2)));
}

THUMB_FUNC u32 FUN_0206E3E8(struct SaveBlock2 *sav2)
{
    return SaveStruct23_Substruct2_SetField_0x0(SaveStruct23_GetSubstruct2(sav2), 0, DATA_GET);
}

THUMB_FUNC BOOL FUN_0206E3F8(struct SaveBlock2 *sav2, struct String *dest, u32 item_id, u32 heap_id)
{
    struct MsgData *msgData = NewMsgDataFromNarc(0, NARC_MSGDATA_MSG, 7, heap_id);
    struct ScrStrBufs *scrStrBufs = ScrStrBufs_new(heap_id);
    struct String *string;

    if (item_id == ITEM_NONE)
    {
        string = NewString_ReadMsgData(msgData, 0x63);
    }
    else if (item_id == ITEM_POINT_CARD)
    {
        string = NewString_ReadMsgData(msgData, 0x61);

        BufferIntegerAsString(scrStrBufs, 0, FUN_0206E3E8(sav2), 4, 0, TRUE);
    }
    else if (item_id == ITEM_SEAL_CASE)
    {
        string = NewString_ReadMsgData(msgData, 0x5C);

        BufferIntegerAsString(scrStrBufs, 0, FUN_0206E3A8(sav2), 4, 0, TRUE);
    }
    else if (item_id == ITEM_FASHION_CASE)
    {
        string = NewString_ReadMsgData(msgData, 0x5D);

        BufferIntegerAsString(scrStrBufs, 0, FUN_0206E3C8(sav2), 3, 0, TRUE);
        BufferIntegerAsString(scrStrBufs, 1, FUN_0206E3D8(sav2), 2, 0, TRUE);
    }
    else if (item_id == ITEM_COIN_CASE)
    {
        string = NewString_ReadMsgData(msgData, 0x39);

        BufferIntegerAsString(scrStrBufs, 0, FUN_0206E39C(sav2), 5, 0, TRUE);
    }
    else
    {
        ScrStrBufs_delete(scrStrBufs);
        DestroyMsgData(msgData);

        return FALSE;
    }

    StringExpandPlaceholders(scrStrBufs, dest, string);
    String_dtor(string);
    ScrStrBufs_delete(scrStrBufs);
    DestroyMsgData(msgData);

    return TRUE;
}

THUMB_FUNC void FUN_0206E51C(
    struct PlayerData *playerData, struct String *dest, u32 r2, u32 r3, u32 heap_id)
{
#pragma unused(r2)
    struct MsgData *msgData;

    switch (r3)
    {
    case 1:
        msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 7, heap_id);

        ReadMsgDataIntoString(msgData, 0x38, dest);
        DestroyMsgData(msgData);
        return;
    case 2:
        msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 7, heap_id);

        ReadMsgDataIntoString(msgData, 0x6F, dest);
        DestroyMsgData(msgData);
        return;
    default:
        msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 0xC7, heap_id);
        struct ScrStrBufs *scrStrBufs = ScrStrBufs_new(heap_id);
        struct String *src = NewString_ReadMsgData(msgData, 0x24);

        BufferPlayersName(scrStrBufs, 0, playerData);
        StringExpandPlaceholders(scrStrBufs, dest, src);
        String_dtor(src);
        ScrStrBufs_delete(scrStrBufs);
        DestroyMsgData(msgData);
        return;
    }
}