From d21e39060f74769183fd66315a99906ed539a0a5 Mon Sep 17 00:00:00 2001 From: Ibot02 Date: Sat, 8 Aug 2020 02:18:04 +0200 Subject: [PATCH 1/2] manager6.c ok --- asm/manager6.s | 87 ------------------------------------------ linker.ld | 2 +- src/manager/manager6.c | 49 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 88 deletions(-) delete mode 100644 asm/manager6.s create mode 100644 src/manager/manager6.c diff --git a/asm/manager6.s b/asm/manager6.s deleted file mode 100644 index 34066ffa..00000000 --- a/asm/manager6.s +++ /dev/null @@ -1,87 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start sub_08057CB4 -sub_08057CB4: @ 0x08057CB4 - push {r4, r5, r6, lr} - adds r4, r0, #0 - ldrb r0, [r4, #0xc] - cmp r0, #0 - bne _08057CD6 - movs r0, #1 - strb r0, [r4, #0xc] - ldrb r0, [r4, #0xa] - bl GetCurrentRoomProperty - str r0, [r4, #0x20] - cmp r0, #0 - bne _08057CD6 - adds r0, r4, #0 - bl sub_0805E900 - b _08057D42 -_08057CD6: - ldrb r0, [r4, #0xe] - cmp r0, #0 - beq _08057CE4 - ldr r0, _08057D44 @ =gLinkState - ldrb r0, [r0, #0x12] - cmp r0, #0x1e - bne _08057D42 -_08057CE4: - ldr r4, [r4, #0x20] - ldrh r0, [r4] - ldr r1, _08057D48 @ =0x0000FFFF - cmp r0, r1 - beq _08057D42 - ldr r5, _08057D4C @ =gLinkEntity - adds r6, r1, #0 -_08057CF2: - ldrb r2, [r4, #7] - movs r0, #3 - ands r0, r2 - adds r1, r5, #0 - adds r1, #0x38 - ldrb r1, [r1] - ands r0, r1 - cmp r0, #0 - beq _08057D3A - ldr r0, _08057D44 @ =gLinkState - ldr r0, [r0, #0x30] - movs r1, #0x80 - ands r0, r1 - cmp r0, #0 - bne _08057D18 - movs r0, #0x10 - ands r0, r2 - cmp r0, #0 - beq _08057D3A -_08057D18: - ldrh r0, [r4] - ldrh r1, [r4, #2] - ldrb r2, [r4, #4] - ldrb r3, [r4, #5] - bl CheckPlayerInRegion - cmp r0, #0 - beq _08057D3A - movs r1, #0x36 - ldrsh r0, [r5, r1] - cmp r0, #0 - bne _08057D3A - ldrb r0, [r4, #6] - bl GetCurrentRoomProperty - bl DoExitTransition -_08057D3A: - adds r4, #8 - ldrh r0, [r4] - cmp r0, r6 - bne _08057CF2 -_08057D42: - pop {r4, r5, r6, pc} - .align 2, 0 -_08057D44: .4byte gLinkState -_08057D48: .4byte 0x0000FFFF -_08057D4C: .4byte gLinkEntity diff --git a/linker.ld b/linker.ld index 024820ac..24d6147c 100644 --- a/linker.ld +++ b/linker.ld @@ -472,7 +472,7 @@ SECTIONS { asm/manager3.o(.text); asm/manager4.o(.text); asm/manager5.o(.text); - asm/manager6.o(.text); + src/manager/manager6.o(.text); asm/manager7.o(.text); asm/manager8.o(.text); asm/manager9.o(.text); diff --git a/src/manager/manager6.c b/src/manager/manager6.c new file mode 100644 index 00000000..4532cce1 --- /dev/null +++ b/src/manager/manager6.c @@ -0,0 +1,49 @@ +#include "global.h" +#include "entity.h" +#include "link.h" + +extern void* GetCurrentRoomProperty(u8); +extern u32 CheckPlayerInRegion(u16, u16, u8, u8); +extern void DoExitTransition(void*); +extern void sub_0805E900(Entity*); + +typedef struct { + u16 field_0x00; + u16 field_0x02; + u8 field_0x04; + u8 field_0x05; + u8 field_0x06; + union { + u8 all; + struct { + u8 layer : 2; + u8 unk1 : 2; + u8 unk2 : 1; + u8 unk3 : 3; + } PACKED b; + } PACKED field_0x07; +} unknownStruct; + +void sub_08057CB4(Entity * this) { + u32 tmp; + unknownStruct* i; + if (this->action == 0){ + this->action = 1; + this->field_0x20 = (s32) GetCurrentRoomProperty(this->entityType.form); + if (this->field_0x20 == 0) { + sub_0805E900(this); + return; + } + } + if (this->actionDelay == 0 || gLinkState.field_0x10[2] == 0x1e) { + for (i = ((unknownStruct*) this->field_0x20);i->field_0x00 != 0xFFFF; i++) { + tmp = (i->field_0x07.all & 0x3); + if (((tmp & (gLinkEntity.collisionLayer)) != 0) && + (((gLinkState.flags.all & 0x80) != 0) || ((i->field_0x07.b.unk2) != 0)) && + (CheckPlayerInRegion(i->field_0x00,i->field_0x02,i->field_0x04,i->field_0x05) != 0) && + (gLinkEntity.height.HALF.HI == 0)) { + DoExitTransition(GetCurrentRoomProperty(i->field_0x06)); + } + } + } +} From 6bf6cc2d6a7f4753ea2559cc6d6b8d1dd146ba44 Mon Sep 17 00:00:00 2001 From: Ibot02 Date: Sat, 8 Aug 2020 02:57:52 +0200 Subject: [PATCH 2/2] Added manager.h Moved the unknown struct from manager6.c to new header manager.h --- include/manager.h | 23 +++++++++++++++++++++++ src/manager/manager6.c | 22 +++------------------- 2 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 include/manager.h diff --git a/include/manager.h b/include/manager.h new file mode 100644 index 00000000..66b1c363 --- /dev/null +++ b/include/manager.h @@ -0,0 +1,23 @@ +#ifndef MANAGER_H +#define MANAGER_H + +#include "global.h" + +typedef struct { + u16 field_0x00; + u16 field_0x02; + u8 field_0x04; + u8 field_0x05; + u8 field_0x06; + union { + u8 all; + struct { + u8 layer : 2; + u8 unk1 : 2; + u8 unk2 : 1; + u8 unk3 : 3; + } PACKED b; + } PACKED field_0x07; +} UnkManagerHelperStruct; + +#endif diff --git a/src/manager/manager6.c b/src/manager/manager6.c index 4532cce1..deb44026 100644 --- a/src/manager/manager6.c +++ b/src/manager/manager6.c @@ -1,32 +1,16 @@ #include "global.h" #include "entity.h" #include "link.h" +#include "manager.h" extern void* GetCurrentRoomProperty(u8); extern u32 CheckPlayerInRegion(u16, u16, u8, u8); extern void DoExitTransition(void*); extern void sub_0805E900(Entity*); -typedef struct { - u16 field_0x00; - u16 field_0x02; - u8 field_0x04; - u8 field_0x05; - u8 field_0x06; - union { - u8 all; - struct { - u8 layer : 2; - u8 unk1 : 2; - u8 unk2 : 1; - u8 unk3 : 3; - } PACKED b; - } PACKED field_0x07; -} unknownStruct; - void sub_08057CB4(Entity * this) { u32 tmp; - unknownStruct* i; + UnkManagerHelperStruct* i; if (this->action == 0){ this->action = 1; this->field_0x20 = (s32) GetCurrentRoomProperty(this->entityType.form); @@ -36,7 +20,7 @@ void sub_08057CB4(Entity * this) { } } if (this->actionDelay == 0 || gLinkState.field_0x10[2] == 0x1e) { - for (i = ((unknownStruct*) this->field_0x20);i->field_0x00 != 0xFFFF; i++) { + for (i = ((UnkManagerHelperStruct*) this->field_0x20);i->field_0x00 != 0xFFFF; i++) { tmp = (i->field_0x07.all & 0x3); if (((tmp & (gLinkEntity.collisionLayer)) != 0) && (((gLinkState.flags.all & 0x80) != 0) || ((i->field_0x07.b.unk2) != 0)) &&