From 3ab8b60a126038cd1475c53d4c8ca117f771cc52 Mon Sep 17 00:00:00 2001 From: Alejandro Asenjo <96613413+sonicdcer@users.noreply.github.com> Date: Mon, 11 Jul 2022 22:59:29 -0300 Subject: [PATCH] ovl_Elf_Msg decompiled (#880) * ovl_Elf_Msg decompiled * pr review * ELFMSG_GET_SWITCHFLAG --- spec | 3 +- src/overlays/actors/ovl_Elf_Msg/z_elf_msg.c | 118 +++++++++++++++++--- src/overlays/actors/ovl_Elf_Msg/z_elf_msg.h | 8 +- 3 files changed, 111 insertions(+), 18 deletions(-) diff --git a/spec b/spec index 15519ef17d..232655982c 100644 --- a/spec +++ b/spec @@ -1397,8 +1397,7 @@ beginseg name "ovl_Elf_Msg" compress include "build/src/overlays/actors/ovl_Elf_Msg/z_elf_msg.o" - include "build/data/ovl_Elf_Msg/ovl_Elf_Msg.data.o" - include "build/data/ovl_Elf_Msg/ovl_Elf_Msg.reloc.o" + include "build/src/overlays/actors/ovl_Elf_Msg/ovl_Elf_Msg_reloc.o" endseg beginseg diff --git a/src/overlays/actors/ovl_Elf_Msg/z_elf_msg.c b/src/overlays/actors/ovl_Elf_Msg/z_elf_msg.c index 5cd49cbb8f..2dc6f934bf 100644 --- a/src/overlays/actors/ovl_Elf_Msg/z_elf_msg.c +++ b/src/overlays/actors/ovl_Elf_Msg/z_elf_msg.c @@ -5,6 +5,7 @@ */ #include "z_elf_msg.h" +#include "overlays/actors/ovl_En_Elf/z_en_elf.h" #define FLAGS (ACTOR_FLAG_10) @@ -15,8 +16,8 @@ void ElfMsg_Destroy(Actor* thisx, PlayState* play); void ElfMsg_Update(Actor* thisx, PlayState* play); void ElfMsg_SetupAction(ElfMsg* this, ElfMsgActionFunc actionFunc); +void func_8092E284(ElfMsg* this, PlayState* play); -#if 0 const ActorInit Elf_Msg_InitVars = { ACTOR_ELF_MSG, ACTORCAT_ITEMACTION, @@ -29,30 +30,119 @@ const ActorInit Elf_Msg_InitVars = { (ActorFunc)NULL, }; -// static InitChainEntry sInitChain[] = { -static InitChainEntry D_8092E470[] = { +static InitChainEntry sInitChain[] = { ICHAIN_VEC3F_DIV1000(scale, 1000, ICHAIN_CONTINUE), ICHAIN_F32(uncullZoneForward, 1000, ICHAIN_STOP), }; -#endif +void ElfMsg_SetupAction(ElfMsg* this, ElfMsgActionFunc actionFunc) { + this->actionFunc = actionFunc; +} -extern InitChainEntry D_8092E470[]; +s32 func_8092DF9C(ElfMsg* 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 (ELFMSG_GET_SWITCHFLAG(&this->actor) != 0x7F) { + Flags_SetSwitch(play, ELFMSG_GET_SWITCHFLAG(&this->actor)); + } + Actor_MarkForDeath(&this->actor); + return true; + } + if (this->actor.home.rot.y == 0x81) { + if (Flags_GetClear(play, this->actor.room)) { + if (ELFMSG_GET_SWITCHFLAG(&this->actor) != 0x7F) { + Flags_SetSwitch(play, ELFMSG_GET_SWITCHFLAG(&this->actor)); + } + Actor_MarkForDeath(&this->actor); + return true; + } + } + if (ELFMSG_GET_SWITCHFLAG(&this->actor) == 0x7F) { + return false; + } + if (Flags_GetSwitch(play, ELFMSG_GET_SWITCHFLAG(&this->actor))) { + (void)"共倒れ"; // "Collapse together" + Actor_MarkForDeath(&this->actor); + return true; + } + return false; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg/D_8092E480.s") +void ElfMsg_Init(Actor* thisx, PlayState* play) { + ElfMsg* this = THIS; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg/ElfMsg_SetupAction.s") + if (!func_8092DF9C(this, play)) { + Actor_ProcessInitChain(&this->actor, sInitChain); + if (ABS_ALT(this->actor.home.rot.x) == 0) { + this->actor.scale.x = this->actor.scale.z = 0.4f; + } else { + this->actor.scale.x = this->actor.scale.z = ABS_ALT(this->actor.home.rot.x) * 0.04f; + } + if (this->actor.home.rot.z == 0) { + this->actor.scale.y = 0.4f; + } else { + this->actor.scale.y = this->actor.home.rot.z * 0.04f; + } + ElfMsg_SetupAction(this, func_8092E284); + this->actor.shape.rot.x = this->actor.shape.rot.y = this->actor.shape.rot.z = 0; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg/func_8092DF9C.s") +void ElfMsg_Destroy(Actor* thisx, PlayState* play) { +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg/ElfMsg_Init.s") +s32 func_8092E1D0(ElfMsg* this) { + if (ELFMSG_GET_8000(&this->actor) != 0) { + return ELFMSG_GET_FF(&this->actor) + 0x200; + } else { + return -0x200 - ELFMSG_GET_FF(&this->actor); + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg/ElfMsg_Destroy.s") +s32 func_8092E1FC(ElfMsg* this) { + return (this->actor.xzDistToPlayer < (100.0f * this->actor.scale.x)) && (this->actor.playerHeightRel >= 0.0f) && + (this->actor.playerHeightRel < (100.0f * this->actor.scale.y)); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg/func_8092E1D0.s") +void func_8092E284(ElfMsg* this, PlayState* play) { + Player* player = GET_PLAYER(play); + EnElf* tatl = (EnElf*)player->tatlActor; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg/func_8092E1FC.s") + if ((player->tatlActor != NULL) && ((func_8092E1FC(this)))) { + player->tatlTextId = func_8092E1D0(this); + ActorCutscene_SetIntentToPlay(0x7C); + tatl->elfMsg = &this->actor; + if (this->actor.cutscene == -1) { + this->actor.cutscene = 0x7C; + } + if ((player->tatlTextId < 0) && (this->actor.home.rot.x < 0)) { + if (ActorCutscene_GetCurrentIndex() == 0x7D) { + ActorCutscene_Stop(0x7D); + ActorCutscene_SetIntentToPlay(this->actor.cutscene); + } else if (ActorCutscene_GetCanPlayNext(this->actor.cutscene)) { + this->actor.home.rot.x = 0; + ActorCutscene_Start(this->actor.cutscene, &this->actor); + func_800E0348(play->cameraPtrs[0]); + } else { + ActorCutscene_SetIntentToPlay(this->actor.cutscene); + } + } + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg/func_8092E284.s") +void ElfMsg_Update(Actor* thisx, PlayState* play) { + ElfMsg* this = THIS; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_Elf_Msg/ElfMsg_Update.s") + if (func_8092DF9C(this, play) == 0) { + if (Actor_ProcessTalkRequest(&this->actor, &play->state)) { + if (ELFMSG_GET_SWITCHFLAG(thisx) != 0x7F) { + Flags_SetSwitch(play, ELFMSG_GET_SWITCHFLAG(thisx)); + } + Actor_MarkForDeath(&this->actor); + } else if ((this->actor.home.rot.y >= 0) || (this->actor.home.rot.y < -0x80) || + (Flags_GetSwitch(play, -1 - this->actor.home.rot.y))) { + this->actionFunc(this, play); + } + } +} diff --git a/src/overlays/actors/ovl_Elf_Msg/z_elf_msg.h b/src/overlays/actors/ovl_Elf_Msg/z_elf_msg.h index dd9accf937..f335f01584 100644 --- a/src/overlays/actors/ovl_Elf_Msg/z_elf_msg.h +++ b/src/overlays/actors/ovl_Elf_Msg/z_elf_msg.h @@ -3,13 +3,17 @@ #include "global.h" +#define ELFMSG_GET_FF(thisx) ((thisx)->params & 0xFF) +#define ELFMSG_GET_SWITCHFLAG(thisx) (((thisx)->params & 0x7F00) >> 8) +#define ELFMSG_GET_8000(thisx) ((thisx)->params & 0x8000) + struct ElfMsg; typedef void (*ElfMsgActionFunc)(struct ElfMsg*, PlayState*); typedef struct ElfMsg { - /* 0x0000 */ Actor actor; - /* 0x0144 */ ElfMsgActionFunc actionFunc; + /* 0x000 */ Actor actor; + /* 0x144 */ ElfMsgActionFunc actionFunc; } ElfMsg; // size = 0x148 extern const ActorInit Elf_Msg_InitVars;