sub_8042EC8

This commit is contained in:
DizzyEggg 2024-10-09 15:48:45 +02:00
parent 7141bae241
commit 26ca0efd5c
6 changed files with 168 additions and 390 deletions

View File

@ -5,374 +5,8 @@
.text
thumb_func_start sub_8042CC0
sub_8042CC0:
push {r4-r7,lr}
mov r7, r9
mov r6, r8
push {r6,r7}
sub sp, 0x4
movs r7, 0
ldr r2, _08042D20
ldr r1, [r2]
ldr r0, [r1, 0x4]
cmp r0, 0
beq _08042CDC
movs r7, 0x1
subs r0, 0x1
str r0, [r1, 0x4]
_08042CDC:
movs r5, 0
ldr r0, [r2]
ldr r0, [r0, 0x8]
cmp r5, r0
bge _08042D56
adds r6, r2, 0
movs r0, 0x98
negs r0, r0
mov r9, r0
movs r4, 0
ldr r1, _08042D24
mov r8, r1
_08042CF4:
ldr r3, [r6]
adds r0, r3, r4
adds r2, r0, 0
adds r2, 0x8C
adds r0, r3, 0
adds r0, 0x4C
adds r0, r4
ldr r1, [r0]
ldrh r0, [r2]
subs r0, r1
strh r0, [r2]
lsls r0, 16
asrs r0, 16
cmp r0, r9
bgt _08042D2E
ldr r0, [r3, 0x4]
cmp r0, 0
ble _08042D28
movs r0, 0x98
strh r0, [r2]
b _08042D30
.align 2, 0
_08042D20: .4byte gUnknown_203B414
_08042D24: .4byte 0x0000ff68
_08042D28:
mov r0, r8
strh r0, [r2]
b _08042D30
_08042D2E:
movs r7, 0x1
_08042D30:
ldr r2, [r6]
adds r0, r2, 0
adds r0, 0xC
adds r0, r4
ldr r0, [r0]
adds r1, r4, 0
adds r1, 0x8C
adds r2, r1
movs r1, 0
str r1, [sp]
movs r3, 0
bl sub_800E8AC
adds r4, 0x4
adds r5, 0x1
ldr r0, [r6]
ldr r0, [r0, 0x8]
cmp r5, r0
blt _08042CF4
_08042D56:
ldr r0, _08042D74
ldr r0, [r0]
ldr r1, _08042D78
adds r0, r1
bl sub_800E90C
adds r0, r7, 0
add sp, 0x4
pop {r3,r4}
mov r8, r3
mov r9, r4
pop {r4-r7}
pop {r1}
bx r1
.align 2, 0
_08042D74: .4byte gDungeon
_08042D78: .4byte 0x000181f0
thumb_func_end sub_8042CC0
thumb_func_start sub_8042D7C
sub_8042D7C:
push {r4-r6,lr}
ldr r1, _08042DD0
ldr r0, [r1]
cmp r0, 0
beq _08042DCA
movs r5, 0
ldr r0, [r0, 0x8]
cmp r5, r0
bge _08042DBA
adds r6, r1, 0
_08042D90:
ldr r0, [r6]
lsls r4, r5, 2
adds r0, 0xC
adds r0, r4
ldr r0, [r0]
bl sub_800E9A8
lsls r0, 24
cmp r0, 0
beq _08042DB0
ldr r0, [r6]
adds r0, 0xC
adds r0, r4
ldr r0, [r0]
bl sub_800DC14
_08042DB0:
adds r5, 0x1
ldr r0, [r6]
ldr r0, [r0, 0x8]
cmp r5, r0
blt _08042D90
_08042DBA:
bl sub_800DBBC
ldr r4, _08042DD0
ldr r0, [r4]
bl MemoryFree
movs r0, 0
str r0, [r4]
_08042DCA:
pop {r4-r6}
pop {r0}
bx r0
.align 2, 0
_08042DD0: .4byte gUnknown_203B414
thumb_func_end sub_8042D7C
thumb_func_start sub_8042DD4
sub_8042DD4:
push {r4-r7,lr}
adds r5, r0, 0
adds r6, r1, 0
adds r7, r2, 0
movs r2, 0
ldr r0, _08042E04
mov r12, r0
ldr r3, _08042E08
_08042DE4:
mov r1, r12
ldr r0, [r1]
adds r4, r0, r3
ldr r1, [r4]
movs r0, 0x1
negs r0, r0
cmp r1, r0
bne _08042E0C
str r5, [r4]
str r6, [r4, 0xC]
str r7, [r4, 0x4]
adds r0, r5, 0
bl sub_800E6D8
str r0, [r4, 0x8]
b _08042E14
.align 2, 0
_08042E04: .4byte gDungeon
_08042E08: .4byte 0x000005c4
_08042E0C:
adds r3, 0x10
adds r2, 0x1
cmp r2, 0x2
ble _08042DE4
_08042E14:
pop {r4-r7}
pop {r0}
bx r0
thumb_func_end sub_8042DD4
thumb_func_start sub_8042E1C
sub_8042E1C:
push {r4-r6,lr}
movs r5, 0
ldr r6, _08042E44
ldr r4, _08042E48
_08042E24:
ldr r0, [r6]
adds r0, r4
ldr r1, [r0]
movs r0, 0x1
negs r0, r0
cmp r1, r0
beq _08042E4C
adds r0, r1, 0
bl sub_800E9A8
lsls r0, 24
cmp r0, 0
beq _08042E4C
movs r0, 0x1
b _08042E56
.align 2, 0
_08042E44: .4byte gDungeon
_08042E48: .4byte 0x000005c4
_08042E4C:
adds r4, 0x10
adds r5, 0x1
cmp r5, 0x2
ble _08042E24
movs r0, 0
_08042E56:
pop {r4-r6}
pop {r1}
bx r1
thumb_func_end sub_8042E1C
thumb_func_start sub_8042E5C
sub_8042E5C:
push {r4-r7,lr}
ldr r7, _08042E90
ldr r6, _08042E94
movs r5, 0x2
_08042E64:
ldr r0, [r7]
adds r4, r0, r6
ldr r0, [r4]
cmp r0, 0
blt _08042E82
bl sub_800E9A8
lsls r0, 24
lsrs r1, r0, 24
cmp r1, 0
bne _08042E82
movs r0, 0x1
negs r0, r0
str r0, [r4]
str r1, [r4, 0xC]
_08042E82:
adds r6, 0x10
subs r5, 0x1
cmp r5, 0
bge _08042E64
pop {r4-r7}
pop {r0}
bx r0
.align 2, 0
_08042E90: .4byte gDungeon
_08042E94: .4byte 0x000005c4
thumb_func_end sub_8042E5C
thumb_func_start sub_8042E98
sub_8042E98:
push {r4,r5,lr}
ldr r5, _08042EC0
movs r4, 0x1
negs r4, r4
movs r3, 0
ldr r2, _08042EC4
movs r1, 0x2
_08042EA6:
ldr r0, [r5]
adds r0, r2
str r4, [r0]
str r3, [r0, 0x4]
str r3, [r0, 0xC]
adds r2, 0x10
subs r1, 0x1
cmp r1, 0
bge _08042EA6
pop {r4,r5}
pop {r0}
bx r0
.align 2, 0
_08042EC0: .4byte gDungeon
_08042EC4: .4byte 0x000005c4
thumb_func_end sub_8042E98
thumb_func_start sub_8042EC8
sub_8042EC8:
push {r4-r7,lr}
mov r7, r8
push {r7}
sub sp, 0xC
adds r6, r0, 0
mov r8, r1
movs r7, 0
_08042ED6:
ldr r1, _08042F5C
lsls r0, r7, 4
ldr r2, _08042F60
adds r0, r2
ldr r1, [r1]
adds r4, r1, r0
ldr r0, [r4]
cmp r0, 0
blt _08042F4A
ldr r0, [r4, 0xC]
cmp r0, r6
bne _08042F4A
ldr r0, [r6, 0xC]
cmp r0, 0
bge _08042EF6
adds r0, 0xFF
_08042EF6:
lsls r0, 8
lsrs r0, 16
ldr r1, _08042F64
ldr r2, [sp, 0x8]
ands r2, r1
orrs r2, r0
str r2, [sp, 0x8]
ldr r1, [r6, 0x10]
cmp r1, 0
bge _08042F0C
adds r1, 0xFF
_08042F0C:
lsls r1, 8
lsrs r1, 16
lsls r1, 16
ldr r0, _08042F68
ands r2, r0
orrs r2, r1
str r2, [sp, 0x8]
movs r0, 0
str r0, [sp, 0x4]
ldr r5, [r6, 0x70]
ldr r2, [r4, 0x8]
subs r0, 0x1
cmp r2, r0
beq _08042F36
lsls r2, 24
lsrs r2, 24
add r0, sp, 0x4
adds r1, r6, 0
adds r1, 0x28
bl sub_800569C
_08042F36:
ldr r0, [r4]
adds r1, r5, 0
adds r1, 0x46
ldrb r1, [r1]
str r1, [sp]
add r1, sp, 0x8
add r2, sp, 0x4
mov r3, r8
bl sub_800EB24
_08042F4A:
adds r7, 0x1
cmp r7, 0x2
ble _08042ED6
add sp, 0xC
pop {r3}
mov r8, r3
pop {r4-r7}
pop {r0}
bx r0
.align 2, 0
_08042F5C: .4byte gDungeon
_08042F60: .4byte 0x000005c4
_08042F64: .4byte 0xffff0000
_08042F68: .4byte 0x0000ffff
thumb_func_end sub_8042EC8
thumb_func_start xxx_dungeon_8042F6C
xxx_dungeon_8042F6C:

View File

@ -2,6 +2,7 @@
#define GUARD_CODE_800DAC0_H
#include "ground_sprite.h"
#include "structs/str_position.h"
typedef struct unkStruct_80416E0
{
@ -19,7 +20,12 @@ typedef struct unkStruct_80416E0
u32 sub_800E890(unkStruct_80416E0 *);
void sub_800DC14(s32);
bool8 sub_800E9A8(s32);
void sub_800DAC0(u32);
void sub_800DB7C(void);
void sub_800DBBC(void);
void sub_800E90C(Position *);
void sub_800E8AC(s32 a0, void *a1, void *a2, s32 a3, void *a4); // a2 could be Position
#endif // GUARD_CODE_800DAC0_H

View File

@ -190,6 +190,15 @@ struct unkStruct_Dungeon134_sub
u8 unk17A;
};
// size 0x10
struct unkStruct_Dungeon5C4_sub
{
s32 unk0;
s32 unk4;
s32 unk8;
Entity *unkC;
};
// size: 0x1CEDC
typedef struct Dungeon
{
@ -218,7 +227,8 @@ typedef struct Dungeon
Dungeon_sub unk17C[0x100];
/* 0x57C */ u8 fill57C[0x5C0 - 0x57c];
/* 0x5C0 */ s32 unk5C0;
/* 0x5C4 */ u8 fill5C4[0x644 - 0x5C4];
/* 0x5C4 */ struct unkStruct_Dungeon5C4_sub unk5C4[3];
u8 fill5F4[0x644 - 0x5f4];
/* 0x644 */ DungeonLocation dungeonLocation;
/* 0x648 */ DungeonLocation dungeonLocation2;
u8 fill64C[0x654 - 0x64C];

View File

@ -31,7 +31,6 @@ extern struct FileArchive gEffectFileArchive;
extern void sub_800F034(void);
extern void sub_800ED38(u32);
extern void sub_800DC14(u32);
extern void sub_800F078();
extern void sub_800ED64();
extern void sub_800ED80();
@ -42,7 +41,7 @@ void sub_800DAC0(u32 fileSelection)
s32 index;
OpenedFile *filePtr;
struct unkStruct_203B0CC_sub *preload;
if (gUnknown_203B0CC != NULL) {
sub_800DB7C();
}
@ -79,7 +78,7 @@ void sub_800DB7C(void)
{
s32 index;
struct unkStruct_203B0CC_sub *preload;
for(index = 0, preload = &gUnknown_203B0CC->unk0[index]; index < 0x20; index++, preload++)
{
if(preload->unk4 != -1)
@ -102,7 +101,7 @@ void sub_800DBBC(void)
s32 index2;
struct unkStruct_203B0CC_sub *preload;
struct unkStruct_203B0CC_sub *preload2;
for(index1 = 0, preload = &gUnknown_203B0CC->unk0[index1]; index1 < 0x20; index1++, preload++)
{
if(preload->unk4 != -1)
@ -123,14 +122,14 @@ bool8 sub_800DCC0(void)
return gUnknown_203B0CC != NULL;
}
void sub_800DC14(u32 param_1)
void sub_800DC14(s32 param_1)
{
s32 index1;
s32 index2;
struct unkStruct_800F18C *piVar3;
struct unkStruct_800F18C *puVar4;
struct unkStruct_203B0CC_sub *preload;
index1 = sub_800E2C0(param_1);
if (index1 != -1) {
preload = &gUnknown_203B0CC->unk0[index1];

View File

@ -4,13 +4,15 @@
#include "code_803E46C.h"
#include "code_800E9E4.h"
#include "code_800DAC0.h"
#include "code_800E9A8.h"
#include "random.h"
#include "dungeon.h"
extern void sub_800EE5C(s32);
extern void sub_800EF64(void);
extern void sub_800F15C(s32);
struct Sub_UnkStruct_203B414
struct Sub_UnkStruct_203B414 // Maybe Position?
{
s16 a0;
s16 a2;
@ -26,7 +28,7 @@ struct UnkStruct_203B414
struct Sub_UnkStruct_203B414 unk8C[16];
};
extern struct UnkStruct_203B414 *gUnknown_203B414;
static EWRAM_DATA_2 struct UnkStruct_203B414 *sUnknown_203B414 = NULL;
struct UnkStruct_80F6624
{
@ -44,40 +46,168 @@ void sub_8042B34(s32 a0, s32 a1, s32 a2)
s32 i;
s32 r8 = 0;
Entity *leader = xxx_call_GetLeader();
gUnknown_203B414 = MemoryAlloc(sizeof(*gUnknown_203B414), 7);
sUnknown_203B414 = MemoryAlloc(sizeof(*sUnknown_203B414), 7);
gUnknown_203B414->unk0 = a0;
gUnknown_203B414->unk8 = (a1 + 1) * 4;
sUnknown_203B414->unk0 = a0;
sUnknown_203B414->unk8 = (a1 + 1) * 4;
sub_800EE5C(gUnknown_80F6624[a0][0].unk0);
sub_800EF64();
sub_803E46C(0x46);
gUnknown_203B414->unk4 = a2;
for (i = 0; i < gUnknown_203B414->unk8; i++) {
sUnknown_203B414->unk4 = a2;
for (i = 0; i < sUnknown_203B414->unk8; i++) {
s32 rnd;
spStruct.unk0 = gUnknown_80F6624[gUnknown_203B414->unk0][r8].unk0;
spStruct.unk0 = gUnknown_80F6624[sUnknown_203B414->unk0][r8].unk0;
spStruct.unk4 = i;
spStruct.unk8 = 0;
spStruct.x = leader->pixelPos.x / 256;
spStruct.y = leader->pixelPos.y / 256;
rnd = RandInt(2);
gUnknown_203B414->unk4C[i] = (gUnknown_80F6624[gUnknown_203B414->unk0][r8].unk4 * 2) + rnd;
gUnknown_203B414->unk8C[i].a0 = RandInt(240) + 152;
gUnknown_203B414->unk8C[i].a2 = RandInt(8 + (i * 2)) - (((i - (i / 4 * 4)) * 40) - 24);
sUnknown_203B414->unk4C[i] = (gUnknown_80F6624[sUnknown_203B414->unk0][r8].unk4 * 2) + rnd;
sUnknown_203B414->unk8C[i].a0 = RandInt(240) + 152;
sUnknown_203B414->unk8C[i].a2 = RandInt(8 + (i * 2)) - (((i - (i / 4 * 4)) * 40) - 24);
spStruct.unk10 = gUnknown_203B414->unk8C[i].a0;
spStruct.unk12 = gUnknown_203B414->unk8C[i].a2;
spStruct.unk10 = sUnknown_203B414->unk8C[i].a0;
spStruct.unk12 = sUnknown_203B414->unk8C[i].a2;
spStruct.unk14 = 4;
spStruct.unk18 = 0xFFFF;
spStruct.unk1C = gUnknown_80F683C;
gUnknown_203B414->unkC[i] = sub_800E890(&spStruct);
sUnknown_203B414->unkC[i] = sub_800E890(&spStruct);
r8++;
if (r8 >= 3 || gUnknown_80F6624[gUnknown_203B414->unk0][r8].unk0 == 0) {
if (r8 >= 3 || gUnknown_80F6624[sUnknown_203B414->unk0][r8].unk0 == 0) {
r8 = 0;
}
sub_800F15C(sub_800ECA4(spStruct.unk0)->unk4);
}
}
bool8 sub_8042CC0(void)
{
s32 i;
bool8 ret = FALSE;
if (sUnknown_203B414->unk4 != 0) {
ret = TRUE;
sUnknown_203B414->unk4--;
}
for (i = 0; i < sUnknown_203B414->unk8; i++) {
sUnknown_203B414->unk8C[i].a0 -= sUnknown_203B414->unk4C[i];
if (sUnknown_203B414->unk8C[i].a0 <= -152) {
if (sUnknown_203B414->unk4 > 0) {
sUnknown_203B414->unk8C[i].a0 = 152;
}
else {
sUnknown_203B414->unk8C[i].a0 = -152;
}
}
else {
ret = TRUE;
}
sub_800E8AC(sUnknown_203B414->unkC[i], NULL, &sUnknown_203B414->unk8C[i], 0, NULL);
}
sub_800E90C(&gDungeon->unk181e8.cameraPixelPos);
return ret;
}
void sub_8042D7C(void)
{
s32 i;
if (sUnknown_203B414 == NULL)
return;
for (i = 0; i < sUnknown_203B414->unk8; i++) {
if (sub_800E9A8(sUnknown_203B414->unkC[i])) {
sub_800DC14(sUnknown_203B414->unkC[i]);
}
}
sub_800DBBC();
MemoryFree(sUnknown_203B414);
sUnknown_203B414 = NULL;
}
extern s32 sub_800E6D8(s32);
// TODO: Figure out if a new file should start here
void sub_8042DD4(s32 a0, Entity *a1, s32 a2)
{
s32 i;
for (i = 0; i < 3; i++) {
struct unkStruct_Dungeon5C4_sub *strPtr = &gDungeon->unk5C4[i];
if (strPtr->unk0 == -1) {
strPtr->unk0 = a0;
strPtr->unkC = a1;
strPtr->unk4 = a2;
strPtr->unk8 = sub_800E6D8(a0);
return;
}
}
}
UNUSED bool32 sub_8042E1C(void)
{
s32 i;
for (i = 0; i < 3; i++) {
struct unkStruct_Dungeon5C4_sub *strPtr = &gDungeon->unk5C4[i];
if (strPtr->unk0 != -1 && sub_800E9A8(strPtr->unk0)) {
return TRUE;
}
}
return FALSE;
}
void sub_8042E5C(void)
{
s32 i;
for (i = 0; i < 3; i++) {
struct unkStruct_Dungeon5C4_sub *strPtr = &gDungeon->unk5C4[i];
if (strPtr->unk0 >= 0 && !sub_800E9A8(strPtr->unk0)) {
strPtr->unk0 = -1;
strPtr->unkC = NULL;
}
}
}
void sub_8042E98(void)
{
s32 i;
for (i = 0; i < 3; i++) {
struct unkStruct_Dungeon5C4_sub *strPtr = &gDungeon->unk5C4[i];
strPtr->unk0 = -1;
strPtr->unk4 = 0;
strPtr->unkC = NULL;
}
}
extern void sub_800569C(Position *, EntitySpriteInfo *, u8);
extern void sub_800EB24(s32 param_1, Position *param_2, Position *param_3, s32 param_4, s32 param_5);
void sub_8042EC8(Entity *a0, s32 a1)
{
s32 i;
for (i = 0; i < 3; i++) {
struct unkStruct_Dungeon5C4_sub *strPtr = &gDungeon->unk5C4[i];
if (strPtr->unk0 >= 0 && strPtr->unkC == a0) {
Position sp8 = {a0->pixelPos.x / 256, a0->pixelPos.y / 256};
Position sp4 = {0};
EntityInfo *entInfo = GetEntInfo(a0);
if (strPtr->unk8 != -1) {
sub_800569C(&sp4, &a0->spriteInfo, strPtr->unk8);
}
sub_800EB24(strPtr->unk0, &sp8, &sp4,a1, entInfo->action.direction);
}
}
}

View File

@ -228,8 +228,7 @@ gUnknown_203B40D: /* 203B40D (sub_803E250 - sub_807E698) */
gUnknown_203B410: /* 203B410 (sub_8040150 - sub_8082280) */
.space 0x4
gUnknown_203B414: /* 203B414 (sub_8042B34 - sub_8042D7C) */
.space 0x4
.include "src/code_8042B34.o"
gDungeon: /* 203B418 */
.space 0x4