From 6dec68464f68d62376e72999681fc4c539c13140 Mon Sep 17 00:00:00 2001 From: Alejandro Asenjo <96613413+sonicdcer@users.noreply.github.com> Date: Mon, 11 Jul 2022 23:03:04 -0300 Subject: [PATCH] ovl_Elf_Msg2 decompiled (#881) * ovl_Elf_Msg2 decompiled * pr review changes * ELFMSG2_GET_SWITCHFLAG --- spec | 3 +- src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.c | 121 +++++++++++++++--- src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.h | 7 +- 3 files changed, 110 insertions(+), 21 deletions(-) diff --git a/spec b/spec index 232655982c..14791c5e80 100644 --- a/spec +++ b/spec @@ -1688,8 +1688,7 @@ beginseg name "ovl_Elf_Msg2" compress include "build/src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.o" - include "build/data/ovl_Elf_Msg2/ovl_Elf_Msg2.data.o" - include "build/data/ovl_Elf_Msg2/ovl_Elf_Msg2.reloc.o" + include "build/src/overlays/actors/ovl_Elf_Msg2/ovl_Elf_Msg2_reloc.o" endseg beginseg diff --git a/src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.c b/src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.c index 7c244d2553..6e78ef085e 100644 --- a/src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.c +++ b/src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.c @@ -14,11 +14,10 @@ void ElfMsg2_Init(Actor* thisx, PlayState* play); void ElfMsg2_Destroy(Actor* thisx, PlayState* play); void ElfMsg2_Update(Actor* thisx, PlayState* play); +s32 func_8096EE50(ElfMsg2* this); +void func_8096EF98(ElfMsg2* this, PlayState* play); void func_8096EFD0(ElfMsg2* this, PlayState* play); -void ElfMsg2_SetupAction(ElfMsg2* this, ElfMsg2ActionFunc actionFunc); - -#if 0 const ActorInit Elf_Msg2_InitVars = { ACTOR_ELF_MSG2, ACTORCAT_BG, @@ -31,32 +30,120 @@ const ActorInit Elf_Msg2_InitVars = { (ActorFunc)NULL, }; -// static InitChainEntry sInitChain[] = { -static InitChainEntry D_8096F0B0[] = { +static InitChainEntry sInitChain[] = { ICHAIN_VEC3F_DIV1000(scale, 200, ICHAIN_CONTINUE), ICHAIN_F32(uncullZoneForward, 1000, ICHAIN_STOP), }; -#endif +void ElfMsg2_SetupAction(ElfMsg2* this, ElfMsg2ActionFunc actionFunc) { + this->actionFunc = actionFunc; +} -extern InitChainEntry D_8096F0B0[]; +s32 func_8096EC4C(ElfMsg2* this, PlayState* play) { + if ((this->actor.home.rot.y > 0) && (this->actor.home.rot.y < 0x81) && + (Flags_GetSwitch(play, this->actor.home.rot.y - 1))) { + (void)"共倒れ"; // "Collapse together" + if (ELFMSG2_GET_SWITCHFLAG(&this->actor) != 0x7F) { + Flags_SetSwitch(play, ELFMSG2_GET_SWITCHFLAG(&this->actor)); + } + Actor_MarkForDeath(&this->actor); + return true; + } + if (this->actor.home.rot.y == 129) { -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/D_8096F0C0.s") + if (Flags_GetClear(play, this->actor.room)) { + (void)"共倒れ2"; // "Collapse 2" + if (ELFMSG2_GET_SWITCHFLAG(&this->actor) != 0x7F) { + Flags_SetSwitch(play, ELFMSG2_GET_SWITCHFLAG(&this->actor)); + } + Actor_MarkForDeath(&this->actor); + return true; + } + } + if (ELFMSG2_GET_SWITCHFLAG(&this->actor) == 0x7F) { + return false; + } + if (Flags_GetSwitch(play, ELFMSG2_GET_SWITCHFLAG(&this->actor))) { + (void)"共倒れ"; // "Collapse together" + Actor_MarkForDeath(&this->actor); + return true; + } + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/ElfMsg2_SetupAction.s") +void ElfMsg2_Init(Actor* thisx, PlayState* play) { + ElfMsg2* this = THIS; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/func_8096EC4C.s") + if (!func_8096EC4C(this, play)) { + if ((this->actor.home.rot.x > 0) && (this->actor.home.rot.x < 8)) { + this->actor.targetMode = this->actor.home.rot.x - 1; + } + Actor_ProcessInitChain(&this->actor, sInitChain); + if (this->actor.home.rot.y < 0) { + ElfMsg2_SetupAction(this, func_8096EFD0); + } else { + ElfMsg2_SetupAction(this, func_8096EF98); + this->actor.flags |= (ACTOR_FLAG_40000 | ACTOR_FLAG_1); + this->actor.textId = func_8096EE50(this); + } + this->actor.shape.rot.z = 0; + this->actor.shape.rot.x = this->actor.shape.rot.y = this->actor.shape.rot.z; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/ElfMsg2_Init.s") +void ElfMsg2_Destroy(Actor* thisx, PlayState* play) { +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/ElfMsg2_Destroy.s") +s32 func_8096EE50(ElfMsg2* this) { + return ELFMSG2_GET_FF(&this->actor) + 0x200; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/func_8096EE50.s") +void func_8096EE64(ElfMsg2* this, PlayState* play) { + if (Actor_TextboxIsClosing(&this->actor, play)) { + if (this->actor.cutscene != -1) { + if (ActorCutscene_GetCurrentIndex() == this->actor.cutscene) { + ActorCutscene_Stop(this->actor.cutscene); + } + } + if (this->actor.home.rot.z != 1) { + Actor_MarkForDeath(&this->actor); + if (ELFMSG2_GET_SWITCHFLAG(&this->actor) != 0x7F) { + Flags_SetSwitch(play, ELFMSG2_GET_SWITCHFLAG(&this->actor)); + } + } else { + ElfMsg2_SetupAction(this, func_8096EF98); + } + } else if ((this->actor.cutscene != -1) && (ActorCutscene_GetCurrentIndex() != this->actor.cutscene)) { + if (ActorCutscene_GetCurrentIndex() == 0x7C) { + ActorCutscene_Stop(0x7C); + ActorCutscene_SetIntentToPlay(this->actor.cutscene); + } else if (ActorCutscene_GetCanPlayNext(this->actor.cutscene)) { + ActorCutscene_Start(this->actor.cutscene, &this->actor); + } else { + ActorCutscene_SetIntentToPlay(this->actor.cutscene); + } + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/func_8096EE64.s") +void func_8096EF98(ElfMsg2* this, PlayState* play) { + if (Actor_ProcessTalkRequest(&this->actor, &play->state)) { + ElfMsg2_SetupAction(this, func_8096EE64); + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/func_8096EF98.s") +void func_8096EFD0(ElfMsg2* this, PlayState* play) { + if ((this->actor.home.rot.y < 0) && (this->actor.home.rot.y >= -0x80) && + (Flags_GetSwitch(play, -this->actor.home.rot.y - 1))) { + ElfMsg2_SetupAction(this, func_8096EF98); + this->actor.flags |= (ACTOR_FLAG_40000 | ACTOR_FLAG_1); + this->actor.textId = func_8096EE50(this); + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/func_8096EFD0.s") +void ElfMsg2_Update(Actor* thisx, PlayState* play) { + ElfMsg2* this = THIS; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg2/ElfMsg2_Update.s") + if (!func_8096EC4C(this, play)) { + this->actionFunc(this, play); + } +} diff --git a/src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.h b/src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.h index 82194009a2..e8b48dfd78 100644 --- a/src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.h +++ b/src/overlays/actors/ovl_Elf_Msg2/z_elf_msg2.h @@ -3,13 +3,16 @@ #include "global.h" +#define ELFMSG2_GET_SWITCHFLAG(thisx) (((thisx)->params >> 8) & 0x7F) +#define ELFMSG2_GET_FF(thisx) ((thisx)->params & 0xFF) + struct ElfMsg2; typedef void (*ElfMsg2ActionFunc)(struct ElfMsg2*, PlayState*); typedef struct ElfMsg2 { - /* 0x0000 */ Actor actor; - /* 0x0144 */ ElfMsg2ActionFunc actionFunc; + /* 0x000 */ Actor actor; + /* 0x144 */ ElfMsg2ActionFunc actionFunc; } ElfMsg2; // size = 0x148 extern const ActorInit Elf_Msg2_InitVars;