summaryrefslogtreecommitdiff
path: root/arm9/src/unk_020254B8.c
blob: ed3239651bb18668d815ea88701a21da3c195bcc (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
#include "global.h"
#include "string_util.h"
#include "save_block_2.h"
#include "heap.h"
#include "unk_020254B8.h"

#pragma thumb on

u32 FUN_020254B8(void)
{
    return 16 * sizeof(struct UnkStruct_020254B8);
}

struct UnkStruct_020254B8 * FUN_020254C0(struct SaveBlock2 * sav2)
{
    return (struct UnkStruct_020254B8 *)SavArray_get(sav2, 9);
}

void FUN_020254CC(struct UnkStruct_020254B8 * arr)
{
    s32 i;

    for (i = 0; i < 16; i++)
    {
        memset(&arr[i], 0, sizeof(struct UnkStruct_020254B8));
        arr[i].field_00[0] = EOS;
    }
}

u16 * FUN_020254F0(struct UnkStruct_020254B8 * arr, s32 i)
{
    return arr[i].field_00;
}

u8 FUN_020254F8(struct UnkStruct_020254B8 * unk, s32 i)
{
    return unk->field_68[i];
}

BOOL FUN_02025500(struct UnkStruct_020254B8 * a, struct UnkStruct_020254B8 * b)
{
    return !StringNotEqual(a->field_00, b->field_00) && a->field_10 == b->field_10;
}

void FUN_02025520(struct UnkStruct_020254B8 * sp0, struct UnkStruct_020254B8 * sp4, s32 n, u32 heap_id)
{
    s32 sp18[5];
    s32 sp14;
    struct UnkStruct_020254B8 * sp10;
    s32 r12;
    s32 spC;
    s32 r4;
    s32 r4_2;

    // auto buffer = new UnkStruct_020254B8[16]
    sp10 = AllocFromHeap(heap_id, 16 * sizeof(struct UnkStruct_020254B8));
    FUN_020254CC(sp10);

    // Look up each element of sp4 in sp0
    for (sp14 = 0; sp14 < n; sp14++)
    {
        sp18[sp14] = -1;
        for (r4_2 = 0; r4_2 < 16; r4_2++)
        {
            if (FUN_02025500(&sp0[r4_2], &sp4[sp14]))
                sp18[sp14] = r4_2;
        }
    }

    // Copy sp4 to buffer and mask matching entries in sp0
    r4 = 0;
    for (spC = 0; spC < n; spC++)
    {
        sp10[r4] = sp4[spC];
        if (sp18[spC] >= 0)
            sp0[sp18[spC]].field_00[0] = EOS;
        r4++;
    }

    // Copy unmasked entries from sp0 to buffer
    for (r12 = 0; r12 < 16; r12++)
    {
        if (sp0[r12].field_00[0] != EOS)
        {
            sp10[r4] = sp0[r12];
            r4++;
            if (r4 >= 16)
                break;
        }
    }
    // Copy buffer to sp0 and destroy buffer
    memcpy(sp0, sp10, 16 * sizeof(struct UnkStruct_020254B8));
    FreeToHeap(sp10);
}

s32 FUN_02025614(struct UnkStruct_020254B8 * a0, u32 a1)
{
    s32 i, j;

    for (i = 0; i < 16; i++)
    {
        if (a1 == a0[i].field_10)
            return 1;
    }
    for (i = 0; i < 16; i++)
    {
        for (j = 0; j < 16; j++)
        {
            if (a1 == a0[i].field_18[j])
                return i + 2;
        }
    }
    return 0;
}