diff --git a/linker_scripts/us/symbol_addrs.txt b/linker_scripts/us/symbol_addrs.txt index 3ab3ee1..c15da9c 100644 --- a/linker_scripts/us/symbol_addrs.txt +++ b/linker_scripts/us/symbol_addrs.txt @@ -252,7 +252,8 @@ D_87B000F2 = 0x87B000F2; D_87B000F4 = 0x87B000F4; D_86402848 = 0x86402848; gCurrentGameState = 0x80075668; // size:0x4 -D_800AE540 = 0x800AE540; // size:0x1200 +D_800AE540 = 0x800AE540; // size:0x11F8 +D_800AF738 = 0x800AF738; D_80068080 = 0x80068080; D_8007ED20 = 0x8007ED20; D_800A60C0 = 0x800A60C0; diff --git a/src/1C720.c b/src/1C720.c index 7ac630a..a4746cc 100644 --- a/src/1C720.c +++ b/src/1C720.c @@ -6,6 +6,7 @@ #include "18140.h" #include "32D10.h" #include "22630.h" +#include "19840.h" #include "dp_intro.h" #include "hal_libc.h" diff --git a/src/22630.c b/src/22630.c index 2c7dcd5..a69cc28 100644 --- a/src/22630.c +++ b/src/22630.c @@ -2,24 +2,11 @@ #include "include/string.h" #include "src/22630.h" #include "src/26820.h" -#include "src/29BA0.h" #include "src/2E110.h" #include "src/gb_tower.h" #include "src/hal_libc.h" #include "src/util.h" -typedef struct unk_D_80070F84 { - /* 0x00 */ char unk00[0x6]; - /* 0x06 */ u8 unk_06; - /* 0x07 */ u8 unk_07; - /* 0x08 */ u8 unk_08; - /* 0x09 */ u8 unk_09; - /* 0x0A */ u8 unk_0A; - /* 0x0B */ char unk0B[0x8]; - /* 0x13 */ u8 unk_13; - /* 0x14 */ char unk14[0x3]; -} unk_D_80070F84; // size = 0x17 - typedef struct unk_D_800AC910_50 { /* 0x000 */ char unk000[0x18]; /* 0x018 */ u8 unk_018[11]; @@ -152,7 +139,7 @@ char* func_80021C80(char* arg0, char* arg1) { return arg0; } -char* func_80021CA4(char* arg0, u32 arg1) { +char* func_80021CA4(char* arg0, s32 arg1) { func_80021C80(arg0, (char*)*(u32*)D_8006FEE8[arg1]); return arg0; } diff --git a/src/22630.h b/src/22630.h index 94dcfd7..853a877 100644 --- a/src/22630.h +++ b/src/22630.h @@ -3,6 +3,7 @@ #include "global.h" #include "memory.h" +#include "29BA0.h" typedef enum { POKEMON_ROM_NONE = 0, @@ -12,39 +13,21 @@ typedef enum { POKEMON_ROM_YELLOW = 7, } PokemonRomType; -typedef struct unk_func_80026268_arg0 { - /* 0x00 */ u8 unk_00; - /* 0x01 */ u8 unk_01; - /* 0x02 */ u16 unk_02; - /* 0x04 */ u8 unk_04; +typedef struct unk_D_80070F84 { + /* 0x00 */ char unk00[0x5]; /* 0x05 */ u8 unk_05; /* 0x06 */ u8 unk_06; /* 0x07 */ u8 unk_07; /* 0x08 */ u8 unk_08; - /* 0x09 */ u8 unk_09[4]; - /* 0x0E */ u16 unk_0E; - /* 0x10 */ u32 unk_10; - /* 0x14 */ u16 unk_14; - /* 0x16 */ u16 unk_16; - /* 0x18 */ u16 unk_18; - /* 0x1A */ u16 unk_1A; - /* 0x1C */ u16 unk_1C; - /* 0x1E */ u16 unk_1E; - /* 0x20 */ u8 unk_20[4]; - /* 0x24 */ u8 unk_24; - /* 0x25 */ u8 unk_25; - /* 0x26 */ u16 unk_26; - /* 0x28 */ u16 unk_28; - /* 0x2A */ u16 unk_2A; - /* 0x2C */ u16 unk_2C; - /* 0x2E */ u16 unk_2E; - /* 0x30 */ u8 unk_30[11]; - /* 0x3B */ u8 unk_3B[11]; - /* 0x46 */ u8 unk_46[11]; - /* 0x51 */ char unk51[0x1]; - /* 0x52 */ u8 unk_52; - /* 0x52 */ u8 unk_53; -} unk_func_80026268_arg0; // size >= 0x54 + /* 0x09 */ u8 unk_09; + /* 0x0A */ u8 unk_0A; + /* 0x0B */ char unk0B[0x8]; + /* 0x13 */ u8 unk_13; + /* 0x14 */ char unk14[0x3]; +} unk_D_80070F84; // size = 0x17 + +extern unk_D_80070F84 D_80070F84[]; +extern unk_D_80070F84 D_80070FA0[]; typedef struct unk_D_800AE4E8_004_1_000_010 { /* 0x00 */ u8 unk_00; @@ -73,10 +56,12 @@ u32 func_80021A48(u8* arg0); void func_80021A68(u8* arg0, s32 arg1); void func_80021A78(u8* arg0, s32 arg1); char* func_80021A90(char* arg0, char* arg1); +void func_80021B5C(char*, char*); char* func_80021B7C(char* arg0, char* arg1); +void func_80021C20(char*, char*); void func_80021C40(char* arg0, char* arg1); char* func_80021C80(char* arg0, char* arg1); -char* func_80021CA4(char* arg0, u32 arg1); +char* func_80021CA4(char* arg0, s32 arg1); char* func_80021CE0(s32 arg0, s8* arg1); void func_80021D9C(unk_func_80026268_arg0* arg0, unk_D_800AE4E8_004_1_000_010* arg1); void func_80021F04(unk_func_80026268_arg0* arg0, unk_D_800AE4E8_004_1_000_010* arg1); @@ -88,6 +73,9 @@ u32 func_800224B8(s32 arg0, u16 arg1); u16 func_800226C0(s32 arg0, u32 arg1); u8 func_80022A38(s32 arg0); u8 func_80022A60(s32 arg0); +s32 func_80022C28(s32, s32, s32, s32); +void func_80022D8C(void*); +s32 func_80022E18(unk_func_80026268_arg0*, s32, void*); void func_80023068(void); char* func_8002311C(s32 arg0); s32 func_80023130(u8* arg0); @@ -97,10 +85,12 @@ s32 func_80023480(s32 arg0); void func_800238D8(UNUSED MainPoolBlock* arg0, u32 arg1); void func_80023990(s32 arg0); s32 func_80023A04(s32 arg0); +void func_80023AF8(s32); void func_80023F78(s32 arg0); void func_80024040(s32 arg0); s32 func_800240A0(void); s32 func_80024FB0(s32 arg0); +void func_800251B0(s32, s8*); #endif // _6BC0_H_ diff --git a/src/26820.h b/src/26820.h index da4a16d..653e772 100644 --- a/src/26820.h +++ b/src/26820.h @@ -2,6 +2,7 @@ #define _26820_H_ #include "global.h" +#include "29BA0.h" typedef struct unk_func_8002A728 { /* 0x00 */ s16 unk_00; @@ -14,6 +15,18 @@ typedef struct unk_func_80027FA0 { /* 0x07 */ u8 unk_07; } unk_func_80027FA0; // size = 0x8 +typedef struct unk_func_800281D4 { + /* 0x00 */ u8 unk_00; + /* 0x01 */ u8 unk_01; + /* 0x02 */ u8 unk_02; + /* 0x03 */ u8 unk_03; + /* 0x04 */ u8 unk_04; + /* 0x05 */ u8 unk_05[2][4]; + /* 0x0D */ u8 unk_0D; + /* 0x0E */ u16 unk_0E; + /* 0x10 */ char unk_10[16]; +} unk_func_800281D4; // size >= 0x20 + void func_80026684(s32, s32); void func_8002707C(s32 arg0, s32 arg1); void func_80027F24(unk_func_8002A728*); @@ -21,6 +34,8 @@ void func_80027F40(unk_func_8002A728*); void func_80027FA0(unk_func_80027FA0*, s16); void func_80028070(u16*); void func_800280D4(u8); +void func_800281D4(unk_func_800281D4*, unk_func_80026268_arg0*, u8); +s32 func_80028320(unk_func_800281D4*, unk_func_80026268_arg0*); s32 func_800284B4(s16); s32 func_80028AFC(s16); diff --git a/src/29BA0.c b/src/29BA0.c index 61c8c33..73f5897 100644 --- a/src/29BA0.c +++ b/src/29BA0.c @@ -32,7 +32,9 @@ static s16 D_80075678 = 0; static s16 D_8007567C = 0; unk_D_800AE520 D_800AE520; +s32 pad_D_800AE534[2]; unk_D_800AE540 D_800AE540; +BinArchive* D_800AF738; s32 Game_DoCopyProtection(s32 state) { u32 intr = osSetIntMask(1); diff --git a/src/29BA0.h b/src/29BA0.h index d255711..eea1bdb 100644 --- a/src/29BA0.h +++ b/src/29BA0.h @@ -2,10 +2,7 @@ #define _29BA0_H_ #include "global.h" - -typedef struct unk_D_800AE540_0004 { - /* 0x000 */ char unk000[0x21C]; -} unk_D_800AE540_0004; // size = 0x21C +#include "3FB0.h" typedef struct unk_D_800AE520 { /* 0x00 */ s16 unk_00; @@ -14,26 +11,110 @@ typedef struct unk_D_800AE520 { /* 0x08 */ u8* rom_end; /* 0x0C */ s32 arg0; /* 0x10 */ s32 arg1; - /* 0x14 */ s32 pad14[3]; } unk_D_800AE520; // size >= 0x14 +typedef struct unk_func_80026268_arg0 { + /* 0x00 */ u8 unk_00; + /* 0x01 */ u8 unk_01; + /* 0x02 */ u16 unk_02; + /* 0x04 */ u8 unk_04; + /* 0x05 */ u8 unk_05; + /* 0x06 */ u8 unk_06; + /* 0x07 */ u8 unk_07; + /* 0x08 */ u8 unk_08; + /* 0x09 */ u8 unk_09[4]; + /* 0x0E */ u16 unk_0E; + /* 0x10 */ u32 unk_10; + /* 0x14 */ u16 unk_14; + /* 0x16 */ u16 unk_16; + /* 0x18 */ u16 unk_18; + /* 0x1A */ u16 unk_1A; + /* 0x1C */ u16 unk_1C; + /* 0x1E */ u16 unk_1E; + /* 0x20 */ u8 unk_20[4]; + /* 0x24 */ u8 unk_24; + /* 0x25 */ u8 unk_25; + /* 0x26 */ u16 unk_26; + /* 0x28 */ u16 unk_28; + /* 0x2A */ u16 unk_2A; + /* 0x2C */ u16 unk_2C; + /* 0x2E */ u16 unk_2E; + /* 0x30 */ u8 unk_30[11]; + /* 0x3B */ u8 unk_3B[11]; + /* 0x46 */ u8 unk_46[11]; + /* 0x51 */ char unk51[0x1]; + /* 0x52 */ u8 unk_52; + /* 0x52 */ u8 unk_53; +} unk_func_80026268_arg0; // size = 0x54 + +typedef struct unk_D_800AE540_0874 { + /* 0x000 */ u16 unk_000; + /* 0x002 */ u8 unk_002; + /* 0x003 */ u8 unk_003; + /* 0x004 */ char unk004[0x10]; + /* 0x014 */ char unk_014[0x4]; + /* 0x018 */ char unk018[0x10]; + /* 0x028 */ unk_func_80026268_arg0 unk_028[1]; + /* 0x07C */ char unk07C[0x1A4]; + /* 0x220 */ char unk_220[0x4]; + /* 0x224 */ char unk224[0x24]; +} unk_D_800AE540_0874; // size = 0x248 + +typedef struct unk_D_800AE540_0004 { + /* 0x000 */ u8 unk_000; + /* 0x001 */ u8 unk_001; + /* 0x002 */ u8 unk_002; + /* 0x004 */ struct Controller* controller; + /* 0x008 */ char unk_008[0x4]; + /* 0x00C */ char unk00C[0xC]; + /* 0x018 */ s32 unk_018; + /* 0x01C */ unk_func_80026268_arg0 unk_01C[1]; + /* 0x070 */ char unk070[0x1A4]; + /* 0x214 */ unk_D_800AE540_0874* unk_214; + /* 0x218 */ char unk218[0x4]; +} unk_D_800AE540_0004; // size = 0x21C + +typedef struct unk_D_800AE540_1194 { + /* 0x00 */ u8 unk_00; + /* 0x01 */ u8 unk_01; + /* 0x02 */ u16 unk_02; + /* 0x04 */ s32 unk_04; + /* 0x04 */ unk_D_800AE540_0004* unk_08[2]; + /* 0x04 */ char unk10[0x4]; + /* 0x04 */ s32 unk_14; + /* 0x04 */ char unk18[0x5]; + /* 0x1D */ u8 unk_1D; + /* 0x1E */ u8 unk_1E; + /* 0x20 */ s32 unk_20; + /* 0x24 */ char unk24[0x4]; +} unk_D_800AE540_1194; // size = 0x28 + typedef struct unk_D_800AE540 { /* 0x0000 */ s8 unk_0000; /* 0x0001 */ s8 unk_0001; /* 0x0002 */ s8 unk_0002; /* 0x0003 */ s8 unk_0003; - /* 0x0004 */ unk_D_800AE540_0004 unk_0004[1]; - /* 0x0220 */ char unk0220[0xFD2]; + /* 0x0004 */ unk_D_800AE540_0004 unk_0004[4]; + /* 0x0874 */ unk_D_800AE540_0874 unk_0874[4]; + /* 0x1194 */ unk_D_800AE540_1194 unk_1194[2]; + /* 0x11E4 */ u8 unk_11E4[2][4]; + /* 0x11EC */ u8 unk_11EC; + /* 0x11EC */ u8 unk_11ED; + /* 0x11EC */ u8 unk_11EE; + /* 0x11EC */ u8 unk_11EF; + /* 0x11F0 */ u8 unk_11F0; + /* 0x11F1 */ char unk11F1[0x1]; /* 0x11F2 */ u8 unk_11F2; - /* 0x11F3 */ char unk11F3[0x2]; + /* 0x11F3 */ u8 unk_11F3; + /* 0x11F4 */ u8 unk_11F4; /* 0x11F5 */ u8 unk_11F5; /* 0x11F6 */ u16 unk_11F6; - /* 0x11F8 */ char pad11F8[0x8]; -} unk_D_800AE540; // size = 0x1200 +} unk_D_800AE540; // size = 0x11F8 extern s32 gCurrentGameState; extern unk_D_800AE520 D_800AE520; extern unk_D_800AE540 D_800AE540; +extern BinArchive* D_800AF738; s32 Game_DoCopyProtection(s32 state); s32 func_80029008(s32 arg0, u8* romStart, u8* romEnd, u32 arg3, u32 arg4); diff --git a/src/2C1C0.c b/src/2C1C0.c index 8e45d0a..8e4c5d4 100644 --- a/src/2C1C0.c +++ b/src/2C1C0.c @@ -1,39 +1,574 @@ #include "2C1C0.h" +#include "src/22630.h" +#include "src/26820.h" +#include "src/2C1C0.h" +#include "src/3FB0.h" +#include "src/hal_libc.h" +#include "src/math_util.h" +#include "src/memory.h" +#include "src/controller.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002B5C0.s") +u8 D_80075680[3] = { 1, 15, 30 }; +static s16 D_80075684 = 0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002B5EC.s") +void func_8002B5C0(unk_D_800AE540_1194* arg0) { + arg0->unk_00 = 0; + arg0->unk_01 = 0; + arg0->unk_02 = 0; + arg0->unk_04 = 0; + arg0->unk_14 = 0; + arg0->unk_08[0] = 0; + arg0->unk_08[1] = 0; + arg0->unk_1D = 0; + arg0->unk_20 = 0; + arg0->unk_1E = 0; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002B6BC.s") +void func_8002B5EC(s32 arg0, s32 arg1, s32 arg2) { + s32 i; + s32 j; -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002B700.s") + func_8002B5C0(&D_800AE540.unk_1194[0]); + func_8002B5C0(&D_800AE540.unk_1194[1]); -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002B840.s") + D_800AE540.unk_0000 = arg0; + D_800AE540.unk_0001 = arg1; + D_800AE540.unk_0002 = arg2; + D_800AE540.unk_0003 = 1; -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002B888.s") + D_800AE540.unk_11ED = 0; + D_800AE540.unk_11EE = 0; + D_800AE540.unk_11EF = 0; + D_800AE540.unk_11F4 = 0; + D_800AE540.unk_11F5 = 0; + D_800AE540.unk_11F3 = 0; + D_800AE540.unk_11F6 = 0; + D_800AE540.unk_11EC = 0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002B924.s") + for (i = 0; i < 4; i++) { + D_800AE540.unk_0004[i].unk_000 = 0; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002BA34.s") + for (i = 0; i < 2; i++) { + if (1) { + for (j = 0; j < 4; j++) { + D_800AE540.unk_11E4[i][j] = 0xFF; + } + } + } +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002BB7C.s") +void func_8002B6BC(void) { + s32 i; + s32 j; -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002BC64.s") + for (i = 0; i < 2; i++) { + for (j = 0; j < 4; j++) { + D_800AE540.unk_11E4[i][j] = 0xFF; + } + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002BD14.s") + D_800AE540.unk_0003 = 1; + D_800AE540.unk_11F3 = 0; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002BD60.s") +unk_D_800AE540_0004* func_8002B700(s32 arg0, s16 arg1, char* arg2, char* arg3) { + s32 i; + unk_D_800AE540_0874* sp20; + unk_D_800AE540_0004* sp1C = NULL; -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002BE70.s") + for (i = 0; i < 4; i++) { + if ((D_800AE540.unk_0004 + i)->unk_000 == 0) { + sp1C = &D_800AE540.unk_0004[i]; + sp20 = &D_800AE540.unk_0874[i]; + break; + } + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002BEC8.s") + if (sp1C != NULL) { + if (arg0 == -1) { + sp1C->unk_000 = 3; + sp1C->unk_001 = 1; + sp1C->controller = &gControllers[0]; + } else { + sp1C->unk_000 = 1; + sp1C->unk_001 = arg0; + sp1C->controller = &gControllers[arg0]; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002BFC4.s") + sp1C->unk_018 = 0; + sp1C->unk_214 = sp20; + sp1C->unk_002 = 0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002C128.s") + sp20->unk_000 = 0; + sp20->unk_002 = 0; + sp20->unk_003 = 1; -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002C394.s") + HAL_Strcpy(sp1C->unk_008, arg2); + HAL_Strcpy(sp20->unk_014, arg2); + HAL_Strcpy(sp20->unk_220, arg3); + } + return sp1C; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002C538.s") +void func_8002B840(s32 arg0, s32 arg1) { + unk_D_800AE540_1194* temp_v0 = &D_800AE540.unk_1194[arg0]; + u8 idx = temp_v0->unk_01; -#pragma GLOBAL_ASM("asm/us/nonmatchings/2C1C0/func_8002C5E8.s") + if (idx < 2) { + temp_v0->unk_08[idx] = arg1; + temp_v0->unk_01++; + } +} + +void func_8002B888(unk_D_800AE540_0004* arg0, unk_func_80026268_arg0* arg1) { + unk_D_800AE540_0874* ptr = arg0->unk_214; + s32 tmp = arg0->unk_002; + + if (tmp < 6) { + arg0->unk_01C[tmp] = *arg1; + ptr->unk_028[tmp] = *arg1; + + arg0->unk_002 = tmp + 1; + ptr->unk_002 = tmp + 1; + } +} + +unk_func_80026268_arg0* func_8002B924(unk_func_80026268_arg0* arg0, u8 arg1, s16 arg2) { + arg0->unk_00 = arg1; + arg0->unk_04 = 0; + arg0->unk_05 = 0; + + arg0->unk_06 = D_80070FA0[arg1 - 1].unk_06; + arg0->unk_07 = D_80070FA0[arg1 - 1].unk_07; + + arg0->unk_14 = 0x6400; + arg0->unk_16 = 0x6400; + arg0->unk_18 = 0x6400; + arg0->unk_1A = 0x6400; + arg0->unk_1C = 0x6400; + + arg0->unk_08 = 0; + + arg0->unk_09[0] = 0; + arg0->unk_09[1] = 0; + arg0->unk_09[2] = 0; + arg0->unk_09[3] = 0; + + arg0->unk_0E = 0x7CF; + arg0->unk_1E = 0xFFFF; + + arg0->unk_20[0] = 5; + arg0->unk_20[1] = 5; + arg0->unk_20[2] = 5; + arg0->unk_20[3] = 5; + + arg0->unk_52 = 0; + arg0->unk_53 = 0; + arg0->unk_10 = func_800224B8(arg1, arg2); + + func_80022338(arg0); + + arg0->unk_02 = arg0->unk_26; + + func_80021CA4(arg0->unk_30, arg1); + HAL_Strcpy(arg0->unk_3B, func_8002311C(0)); + return arg0; +} + +void func_8002BA34(s16 arg0, s16 arg1, s16 arg2, s16 arg3) { + s16 spD6; + s32 spD0; + s32 spCC; + unk_func_80026268_arg0 sp78; + unk_func_80026268_arg0 sp24; + + switch (arg0) { + case 0: + spD6 = 0x32; + break; + + case 3: + spD6 = 0x32; + break; + + case 4: + spD6 = 0x1E; + break; + + case 5: + spD6 = 0x19; + break; + + case 6: + spD6 = 0x64; + break; + + case 7: + spD6 = 0x64; + break; + } + + func_8002B5EC(0x10, arg0, arg1); + + spD0 = func_8002B700(0, 0, func_8002311C(1), func_8002311C(2)); + spCC = func_8002B700(1, 0, func_8002311C(1), func_8002311C(2)); + + func_8002B888(spD0, func_8002B924(&sp78, arg2, spD6)); + func_8002B888(spCC, func_8002B924(&sp24, arg3, spD6)); + + func_8002B840(0, spD0); + func_8002B840(1, spCC); +} + +void func_8002BB7C(s32 arg0, s32 arg1, s32 arg2) { + s32 i; + unk_func_80026268_arg0 sp48; + void* temp_v0; + unk_D_800AE540_0004* temp_s4; + char sp34[11]; + + func_80023AF8(arg2); + func_800251B0(arg2, &sp34); + + temp_s4 = func_8002B700(arg1, 0, &sp34, func_8002311C(1)); + temp_v0 = func_80022C28(0x20, arg2, 0, 0); + + if (temp_v0 != NULL) { + for (i = 0; i < 6; i++) { + if (func_80022E18(&sp48, 1, temp_v0) == 0) { + break; + } + + func_8002B888(temp_s4, &sp48); + } + + func_80022D8C(temp_v0); + } + + func_8002B840(arg0, temp_s4); +} + +void func_8002BC64(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + main_pool_push_state('RIVL'); + + func_8002B5EC(0, 3, 0); + + if (arg0 > 0) { + func_8002BB7C(0, arg0 - 1, arg0 - 1); + } + + if (arg1 > 0) { + func_8002BB7C(0, arg1 - 1, arg1 - 1); + } + + if (arg2 > 0) { + func_8002BB7C(1, arg2 - 1, arg2 - 1); + } + + if (arg3 > 0) { + func_8002BB7C(1, arg3 - 1, arg3 - 1); + } + + main_pool_pop_state('RIVL'); +} + +s32 func_8002BD14(s32 arg0) { + s32 i; + + for (i = 0; i < D_800AE540.unk_0003 - 1; i++) { + if (arg0 == D_800AE540.unk_11E4[0][i]) { + return 1; + } + } + + return 0; +} + +s32 func_8002BD60(s32 arg0) { + s32 var_s0; + s32 var_s1; + s32 sp24; + u8 temp_v1; + + var_s0 = -1; + + sp24 = (arg0 - D_800AE540.unk_0003) + 1; + if (D_800AE540.unk_0003 == 1) { + return 0; + } + + temp_v1 = D_800AE540.unk_11E4[0][D_800AE540.unk_0003 - 1]; + if (temp_v1 != 0xFF) { + return temp_v1; + } + + var_s1 = osGetCount() & 0xF; + while (var_s1 > 0) { + MathUtil_Random16(); + var_s1--; + } + + var_s1 = MathUtil_Random16() % sp24; + while (var_s1 >= 0) { + var_s0++; + while (func_8002BD14(var_s0) != 0) { + var_s0++; + } + var_s1--; + } + + return var_s0; +} + +s16 func_8002BE70(void) { + s16 i; + s16 var_v1 = 0; + unk_func_80026268_arg0* var_v0; + + var_v0 = &D_800AE540.unk_1194[0].unk_08[0]->unk_214->unk_028[0]; + + for (i = 0; i < D_800AE540.unk_1194[0].unk_08[0]->unk_214->unk_002; i++, var_v0++) { + if (var_v1 < var_v0->unk_24) { + var_v1 = var_v0->unk_24; + } + } + + return var_v1; +} + +void func_8002BEC8(s16 arg0) { + s16 i; + unk_func_80026268_arg0* var_s0; + unk_func_80026268_arg0* var_s1; + + if (arg0 < 0x33) { + return; + } + + var_s0 = D_800AE540.unk_1194[1].unk_08[0]->unk_01C; + var_s1 = D_800AE540.unk_1194[1].unk_08[0]->unk_214->unk_028; + + for (i = 0; i < D_800AE540.unk_1194[1].unk_08[0]->unk_002; i++, var_s1++, var_s0++) { + var_s0->unk_24 = arg0; + var_s0->unk_10 = func_800224B8(var_s0->unk_00, arg0); + func_80022338(var_s0); + var_s0->unk_02 = var_s0->unk_26; + + *var_s1 = *var_s0; + } +} + +typedef struct unk_func_8002BFC4_004 { + /* 0x000 */ char unk_00[0x4]; + /* 0x004 */ char unk04[0x8]; + /* 0x00C */ char unk_0C[0x4]; + /* 0x010 */ char unk10[0x24]; + /* 0x034 */ u16 unk_34; + /* 0x036 */ u16 unk_36; + /* 0x038 */ unk_func_80026268_arg0 unk_38[1]; + /* 0x08C */ +} unk_func_8002BFC4_004; + +typedef struct unk_func_8002BFC4 { + /* 0x000 */ s32 unk_00; + /* 0x004 */ unk_func_8002BFC4_004 unk_004; + /* 0x090 */ char unk090[0x1A0]; +} unk_func_8002BFC4; // size = 0x230 + +void func_8002BFC4(s16 arg0, s16 arg1, s16 arg2, s32 arg3) { + s32 i; + s16 var_a1; + unk_D_800AE540_0004* temp_s3; + s32 var_s0; + unk_func_8002BFC4_004* temp_s2; + unk_func_80026268_arg0* var_s1; + unk_func_8002BFC4* ptr; + unk_func_8002BFC4* temp_v1; + + temp_s3 = D_800AE540.unk_1194[arg0].unk_08[0]; + if (D_800AE540.unk_11F2 != 0) { + arg1 += 0x1F; + } + + ptr = func_8000484C(D_800AF738, arg1); + ptr += arg2; + + temp_s2 = &ptr->unk_004; + + D_800AE540.unk_11E4[0][D_800AE540.unk_0003 - 1] = arg2; + + temp_s3->unk_018 = temp_s2->unk_34; + temp_s3->unk_002 = 0; + + for (i = 0; i < temp_s2->unk_36; i++) { + func_8002B888(temp_s3, &temp_s2->unk_38[i]); + } + + HAL_Strcpy(temp_s3->unk_008, temp_s2->unk_00); + HAL_Strcpy(temp_s3->unk_214->unk_014, temp_s2->unk_00); + HAL_Strcpy(temp_s3->unk_214->unk_220, temp_s2->unk_0C); + + temp_s3->unk_214->unk_003 = (temp_s2->unk_34 >> 8) & 0xFF; + + if (arg3 != 0) { + func_8002BEC8(func_8002BE70()); + } +} + +void func_8002C128(void) { + s16 var_s0 = D_800AE540.unk_0003 - 1; + s16 sp24 = D_800AE540.unk_0002; + + if ((D_800AE540.unk_0000 == 2) && (D_800AE540.unk_11F2 != 0)) { + var_s0 = func_8002BD60(8); + } else if ((D_800AE540.unk_0000 == 7) && (sp24 == 9)) { + switch (D_800AE540.unk_11F0) { + case 0x1: + var_s0 = 4; + break; + + case 0x2: + var_s0 = 5; + break; + + case 0x3: + var_s0 = 3; + break; + + case 0x99: + var_s0 = 0; + break; + + case 0xB0: + var_s0 = 2; + break; + + case 0xB1: + var_s0 = 1; + break; + + default: + var_s0 = 6; + break; + } + } + + main_pool_push_state('RIVL'); + + D_800AF738 = func_800044F4(0x898000, NULL, 1, 0); + + switch (D_800AE540.unk_0000) { + case 1: + func_8002BFC4(1, 6, var_s0, 0); + break; + + case 2: + func_8002BFC4(1, 7, var_s0, 0); + break; + + case 3: + func_8002BFC4(1, sp24 + 8, var_s0, 0); + break; + + case 4: + func_8002BFC4(1, 0, var_s0, 0); + break; + + case 5: + func_8002BFC4(1, 1, var_s0, 0); + break; + + case 6: + func_8002BFC4(1, sp24 + 2, var_s0, 0); + break; + + case 7: + func_8002BFC4(1, sp24 + 0xC, var_s0, 1); + break; + + case 8: + func_8002BFC4(1, 0x16, var_s0, 0); + break; + } + + main_pool_pop_state('RIVL'); +} + +void func_8002C394(s16 arg0) { + main_pool_push_state('RIVL'); + + D_800AF738 = func_800044F4(0x898000, NULL, 1, 0); + func_8002B5EC(9, 6, 0); + + if (arg0 == 1) { + func_8002B840(0, func_8002B700(0, 0, "1P", func_8002311C(1))); + func_8002B840(1, func_8002B700(-1, 0, "COM", func_8002311C(3))); + } else { + func_8002B840(0, func_8002B700(0, 0, "1P", func_8002311C(1))); + func_8002B840(1, func_8002B700(1, 0, "2P", func_8002311C(1))); + } + + if (D_80075684 == 0) { + func_8002BFC4(0, 0x1D, 0, 0); + func_8002BFC4(1, 0x1D, 1, 0); + } else { + func_8002BFC4(0, 0x1D, 1, 0); + func_8002BFC4(1, 0x1D, 0, 0); + } + + D_80075684 ^= 1; + + main_pool_pop_state('RIVL'); +} + +void func_8002C538(void) { + unk_func_800281D4 sp20; + unk_D_800AE540_0874* sp1C = D_800AE540.unk_1194[0].unk_08[0]->unk_214; + + sp20.unk_00 = D_800AE540.unk_0000; + sp20.unk_01 = D_800AE540.unk_0002; + sp20.unk_02 = D_800AE540.unk_0003; + sp20.unk_04 = D_800AE540.unk_11F3; + sp20.unk_03 = D_800AE540.unk_11F2; + + sp20.unk_0D = D_800AE540.unk_11F0; + sp20.unk_0E = D_800AE540.unk_1194[0].unk_08[0]->unk_018; + + _bcopy(D_800AE540.unk_11E4[0], &sp20.unk_05, 8); + func_80021C20(&sp20.unk_10, &D_800AE540.unk_1194[0].unk_08[0]->unk_008); + func_800281D4(&sp20, sp1C->unk_028, sp1C->unk_002); + func_80026684(0x15, 0); +} + +s32 func_8002C5E8(void) { + unk_func_800281D4 sp250; + unk_func_80026268_arg0 sp58[6]; + s32 i; + char sp44[0x10]; + s32 temp_v0; + u16 tmp; + + temp_v0 = func_80028320(&sp250, sp58); + if (temp_v0 != -1) { + func_8002B5EC(sp250.unk_00, sp250.unk_00, sp250.unk_01); + + _bcopy(sp250.unk_05, D_800AE540.unk_11E4[0], 8); + D_800AE540.unk_0003 = sp250.unk_02; + D_800AE540.unk_11F3 = sp250.unk_04; + D_800AE540.unk_11F2 = sp250.unk_03; + D_800AE540.unk_11F0 = sp250.unk_0D; + tmp = sp250.unk_0E; + + func_80021B5C(sp44, sp250.unk_10); + func_8002B840(0, func_8002B700(0, tmp, sp44, sp44)); + func_8002B840(1, func_8002B700(-1, tmp, "COM", func_8002311C(3))); + + for (i = 0; i < temp_v0; i++) { + func_8002B888(D_800AE540.unk_1194[0].unk_08[0], &sp58[i]); + } + + D_800AE540.unk_11F5 |= 3; + } + return (temp_v0 + 1) != 0; +} diff --git a/src/2C1C0.h b/src/2C1C0.h index 0c54788..7231193 100644 --- a/src/2C1C0.h +++ b/src/2C1C0.h @@ -2,12 +2,28 @@ #define _2C1C0_H_ #include "global.h" +#include "29BA0.h" -void func_8002B5EC(s32, s32, s32); -s32 func_8002B700(s32, s32, const char*, s32); -void func_8002B840(s32, s32); -void func_8002BA34(u8, u8, s16, s16); -void func_8002BC64(s32, s32, s32, s32); -void func_8002C394(s16); +extern u8 D_80075680[3]; + +void func_8002B5C0(unk_D_800AE540_1194* arg0); +void func_8002B5EC(s32 arg0, s32 arg1, s32 arg2); +void func_8002B6BC(void); +unk_D_800AE540_0004* func_8002B700(s32 arg0, s16 arg1, char* arg2, char* arg3); +void func_8002B840(s32 arg0, s32 arg1); +void func_8002B888(unk_D_800AE540_0004* arg0, unk_func_80026268_arg0* arg1); +unk_func_80026268_arg0* func_8002B924(unk_func_80026268_arg0* arg0, u8 arg1, s16 arg2); +void func_8002BA34(s16 arg0, s16 arg1, s16 arg2, s16 arg3); +void func_8002BB7C(s32 arg0, s32 arg1, s32 arg2); +void func_8002BC64(s32 arg0, s32 arg1, s32 arg2, s32 arg3); +s32 func_8002BD14(s32 arg0); +s32 func_8002BD60(s32 arg0); +s16 func_8002BE70(void); +void func_8002BEC8(s16 arg0); +void func_8002BFC4(s16 arg0, s16 arg1, s16 arg2, s32 arg3); +void func_8002C128(void); +void func_8002C394(s16 arg0); +void func_8002C538(void); +s32 func_8002C5E8(void); #endif // _2C1C0_H_ diff --git a/src/3FB0.c b/src/3FB0.c index cd9c877..39ce865 100644 --- a/src/3FB0.c +++ b/src/3FB0.c @@ -542,8 +542,8 @@ void* func_800044A8(s32 arg0, s32 arg1, s32 arg2) { return sp2C; } -void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { - u32* ret = NULL; +BinArchive* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { + BinArchive* ret = NULL; u32 sp28; u32 sp28_2; u16* newaddr; @@ -561,7 +561,7 @@ void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { newaddr = func_80003DC4(romStart, romStart + 0x20, 0, 0); ret = newaddr; if (newaddr != NULL) { - sp28 = (ret[3] * 0x10) + 0x10; + sp28 = (ret->num_files * 0x10) + 0x10; main_pool_try_free(ret); newaddr = func_80003DC4(romStart, romStart + sp28, 0, 0); ret = newaddr; @@ -578,7 +578,7 @@ void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { newaddr = func_80003DC4(romStart, romStart + 0x20, 1, 0); ret = newaddr; if (newaddr != NULL) { - sp28_2 = (ret[3] * 0x10) + 0x10; + sp28_2 = (ret->num_files * 0x10) + 0x10; main_pool_try_free(ret); newaddr = func_80003DC4(romStart, romStart + sp28_2, 1, 0); ret = newaddr; @@ -590,7 +590,7 @@ void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3) { } if (ret != NULL) { - ret[1] = romStart; + ret->unk_04 = romStart; } return ret; diff --git a/src/3FB0.h b/src/3FB0.h index d1eb3f8..fc3256b 100644 --- a/src/3FB0.h +++ b/src/3FB0.h @@ -107,7 +107,7 @@ void func_80004364(u32 base_addr, u32 addr); void func_800043BC(s32 arg0, Fragment* addr); ret_func_80004454 func_80004454(s32 arg0, u8* romStart, u8* romEnd); void* func_800044A8(s32 arg0, s32 arg1, s32 arg2); -void* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3); +BinArchive* func_800044F4(u8* romStart, u8* romEnd, s32 arg2, s32 arg3); void* func_80004660(s32 arg0, s32 arg1, s32 arg2, s32 arg3); void func_800047A4(void* arg0); Fragment* func_800047C4(BinArchive* arg0, BinArchiveFile* arg1); diff --git a/yamls/us/rom.yaml b/yamls/us/rom.yaml index 0d0badd..33982a0 100644 --- a/yamls/us/rom.yaml +++ b/yamls/us/rom.yaml @@ -348,7 +348,8 @@ - [0x703E0, data, rom_data_703E0] - [0x74260, data, rom_data_74260] - [0x76260, .data, 29BA0] - - [0x76280, data, rom_data_76280] + - [0x76280, .data, 2C1C0] + - [0x76290, data, rom_data_76290] - [0x78570, .data, 373A0] - [0x78890, .data, 38BB0] - [0x78990, data, rom_data_78990] @@ -417,7 +418,7 @@ - [0x7CD10, rodata, rom_rodata_7CD10] - [0x7CD40, .rodata, 26820] - [0x7CEC0, .rodata, 29BA0] - - [0x7CFD0, rodata, rom_rodata_7CFD0] + - [0x7CFD0, .rodata, 2C1C0] - [0x7D030, rodata, rom_rodata_7D030] - [0x7D040, rodata, rom_rodata_7D040] - [0x7D0F0, .rodata, 30640]