From f0e4581e2237630f77d253a823851cafb1ff524f Mon Sep 17 00:00:00 2001 From: Alejandro Asenjo <96613413+sonicdcer@users.noreply.github.com> Date: Fri, 22 Jul 2022 00:57:49 -0300 Subject: [PATCH] ovl_En_Sth2 Decompiled and Documented (#898) * ovl_En_Sth2 Decompiled and Documented * & * enum * space * pr review * warnings * pr review * trailing coma + format * pr review * trailing coma * review * focusOffset --- assets/xml/overlays/ovl_En_Sth2.xml | 14 +++ spec | 3 +- src/overlays/actors/ovl_En_Sth2/z_en_sth2.c | 98 ++++++++++++++++++--- src/overlays/actors/ovl_En_Sth2/z_en_sth2.h | 10 ++- tools/disasm/functions.txt | 10 +-- 5 files changed, 116 insertions(+), 19 deletions(-) create mode 100644 assets/xml/overlays/ovl_En_Sth2.xml diff --git a/assets/xml/overlays/ovl_En_Sth2.xml b/assets/xml/overlays/ovl_En_Sth2.xml new file mode 100644 index 0000000000..23140ad717 --- /dev/null +++ b/assets/xml/overlays/ovl_En_Sth2.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/spec b/spec index dd7177e5f5..52fca49e74 100644 --- a/spec +++ b/spec @@ -4797,8 +4797,7 @@ beginseg name "ovl_En_Sth2" compress include "build/src/overlays/actors/ovl_En_Sth2/z_en_sth2.o" - include "build/data/ovl_En_Sth2/ovl_En_Sth2.data.o" - include "build/data/ovl_En_Sth2/ovl_En_Sth2.reloc.o" + include "build/src/overlays/actors/ovl_En_Sth2/ovl_En_Sth2_reloc.o" endseg beginseg diff --git a/src/overlays/actors/ovl_En_Sth2/z_en_sth2.c b/src/overlays/actors/ovl_En_Sth2/z_en_sth2.c index 4cf9cb5fd2..3ce5ba447a 100644 --- a/src/overlays/actors/ovl_En_Sth2/z_en_sth2.c +++ b/src/overlays/actors/ovl_En_Sth2/z_en_sth2.c @@ -13,8 +13,11 @@ void EnSth2_Init(Actor* thisx, PlayState* play); void EnSth2_Destroy(Actor* thisx, PlayState* play); void EnSth2_Update(Actor* thisx, PlayState* play); +void EnSth2_Draw(Actor* thisx, PlayState* play2); + +void EnSth2_UpdateSkelAnime(EnSth2* this, PlayState* play); +void EnSth2_UpdateActionFunc(Actor* thisx, PlayState* play); -#if 0 const ActorInit En_Sth2_InitVars = { ACTOR_EN_STH2, ACTORCAT_NPC, @@ -27,22 +30,95 @@ const ActorInit En_Sth2_InitVars = { (ActorFunc)NULL, }; -#endif +#include "overlays/ovl_En_Sth2/ovl_En_Sth2.c" -extern UNK_TYPE D_060031F8; +void EnSth2_Init(Actor* thisx, PlayState* play) { + EnSth2* this = THIS; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Sth2/EnSth2_Init.s") + this->objIndex = Object_GetIndex(&play->objectCtx, OBJECT_STH); + Actor_SetScale(&this->actor, 0.01f); + ActorShape_Init(&this->actor.shape, 0.0f, ActorShadow_DrawCircle, 36.0f); + this->unused = 0; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Sth2/EnSth2_Destroy.s") + if (play->actorCtx.unk5 & 2) { + this->actor.flags |= (ACTOR_FLAG_10 | ACTOR_FLAG_20); + } else { + Actor_MarkForDeath(&this->actor); + return; + } + this->actionFunc = EnSth2_UpdateSkelAnime; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Sth2/func_80BF75A0.s") +void EnSth2_Destroy(Actor* thisx, PlayState* play) { +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Sth2/EnSth2_Update.s") +void EnSth2_UpdateSkelAnime(EnSth2* this, PlayState* play) { + SkelAnime_Update(&this->skelAnime); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Sth2/func_80BF7688.s") +void EnSth2_Update(Actor* thisx, PlayState* play) { + s32 pad; + EnSth2* this = THIS; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Sth2/func_80BF76AC.s") + if (Object_IsLoaded(&play->objectCtx, this->objIndex)) { + this->actor.objBankIndex = this->objIndex; + Actor_SetObjectDependency(play, &this->actor); + SkelAnime_InitFlex(play, &this->skelAnime, &object_sth_Skel_0031F8, &gEnSth2WavingHandAnim, this->jointTable, + this->morphTable, OBJECT_STH_LIMB_MAX); + Animation_PlayLoop(&this->skelAnime, &gEnSth2WavingHandAnim); + this->actor.update = EnSth2_UpdateActionFunc; + this->actor.draw = EnSth2_Draw; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Sth2/func_80BF77AC.s") +void EnSth2_UpdateActionFunc(Actor* thisx, PlayState* play) { + EnSth2* this = THIS; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Sth2/func_80BF7814.s") + this->actionFunc(this, play); +} + +s32 EnSth2_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, Actor* thisx) { + s32 pad; + + if (limbIndex == OBJECT_STH_LIMB_0F) { + *dList = gEnSth2HeadDL; + } + if ((limbIndex == OBJECT_STH_LIMB_08) || (limbIndex == OBJECT_STH_LIMB_0A) || (limbIndex == OBJECT_STH_LIMB_0D)) { + rot->y += (s16)(Math_SinS((play->state.frames * ((limbIndex * 50) + 0x814))) * 200.0f); + rot->z += (s16)(Math_CosS((play->state.frames * ((limbIndex * 50) + 0x940))) * 200.0f); + } + return false; +} + +void EnSth2_PostLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3s* rot, Actor* thisx) { + static Vec3f focusOffset = { 700.0f, 400.0f, 0.0f }; + + if (limbIndex == OBJECT_STH_LIMB_0F) { + Matrix_MultVec3f(&focusOffset, &thisx->focus.pos); + + OPEN_DISPS(play->state.gfxCtx); + + gSPDisplayList(POLY_OPA_DISP++, gEnSth2HairDL); + + CLOSE_DISPS(play->state.gfxCtx); + } +} + +void EnSth2_Draw(Actor* thisx, PlayState* play2) { + static Color_RGB8 sEnvColors[] = { + { 190, 110, 0 }, { 0, 180, 110 }, { 0, 255, 80 }, { 255, 160, 60 }, { 190, 230, 250 }, { 240, 230, 120 }, + }; + PlayState* play = play2; + EnSth2* this = THIS; + + OPEN_DISPS(play->state.gfxCtx); + + func_8012C28C(play->state.gfxCtx); + gSPSegment(POLY_OPA_DISP++, 0x08, + Gfx_EnvColor(play->state.gfxCtx, sEnvColors[1].r, sEnvColors[1].g, sEnvColors[1].b, 255)); + gSPSegment(POLY_OPA_DISP++, 0x09, Gfx_EnvColor(play->state.gfxCtx, 90, 110, 130, 255)); + SkelAnime_DrawFlexOpa(play, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, + EnSth2_OverrideLimbDraw, EnSth2_PostLimbDraw, &this->actor); + + CLOSE_DISPS(play->state.gfxCtx); +} diff --git a/src/overlays/actors/ovl_En_Sth2/z_en_sth2.h b/src/overlays/actors/ovl_En_Sth2/z_en_sth2.h index 1788c486cd..1166c9d298 100644 --- a/src/overlays/actors/ovl_En_Sth2/z_en_sth2.h +++ b/src/overlays/actors/ovl_En_Sth2/z_en_sth2.h @@ -2,12 +2,20 @@ #define Z_EN_STH2_H #include "global.h" +#include "objects/object_sth/object_sth.h" struct EnSth2; +typedef void (*EnSth2ActionFunc)(struct EnSth2*, PlayState*); + typedef struct EnSth2 { /* 0x000 */ Actor actor; - /* 0x144 */ char unk_144[0x10C]; + /* 0x144 */ SkelAnime skelAnime; + /* 0x188 */ Vec3s jointTable[OBJECT_STH_LIMB_MAX]; + /* 0x1E8 */ Vec3s morphTable[OBJECT_STH_LIMB_MAX]; + /* 0x248 */ s16 unused; + /* 0x24A */ u8 objIndex; + /* 0x24C */ EnSth2ActionFunc actionFunc; } EnSth2; // size = 0x250 extern const ActorInit En_Sth2_InitVars; diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index c7d6b66f79..88f50c50a3 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -16370,12 +16370,12 @@ 0x80BF6C94:("EnOsk_Draw",), 0x80BF74E0:("EnSth2_Init",), 0x80BF7590:("EnSth2_Destroy",), - 0x80BF75A0:("func_80BF75A0",), + 0x80BF75A0:("EnSth2_UpdateSkelAnime",), 0x80BF75CC:("EnSth2_Update",), - 0x80BF7688:("func_80BF7688",), - 0x80BF76AC:("func_80BF76AC",), - 0x80BF77AC:("func_80BF77AC",), - 0x80BF7814:("func_80BF7814",), + 0x80BF7688:("EnSth2_UpdateActionFunc",), + 0x80BF76AC:("EnSth2_OverrideLimbDraw",), + 0x80BF77AC:("EnSth2_PostLimbDraw",), + 0x80BF7814:("EnSth2_Draw",), 0x80BFA100:("EnYb_Init",), 0x80BFA2D0:("EnYb_Destroy",), 0x80BFA2FC:("func_80BFA2FC",),