From 306ae916d55c49ba3c1c1d0367a2af9e1acbc60d Mon Sep 17 00:00:00 2001 From: elijah-thomas774 Date: Sun, 23 Nov 2025 13:55:01 -0500 Subject: [PATCH] init for d_t_barrel --- .../rels/d_a_obj_stage_sinkNP/symbols.txt | 2 +- config/SOUE01/rels/d_t_barrelNP/symbols.txt | 26 +-- include/d/a/obj/d_a_obj_stage_sink.h | 5 +- include/d/t/d_t_barrel.h | 31 +++- include/d/t/d_t_barrel_pos.h | 14 +- src/REL/d/t/d_t_barrel.cpp | 162 +++++++++++++++++- 6 files changed, 218 insertions(+), 22 deletions(-) diff --git a/config/SOUE01/rels/d_a_obj_stage_sinkNP/symbols.txt b/config/SOUE01/rels/d_a_obj_stage_sinkNP/symbols.txt index 8f334956..61479d7c 100644 --- a/config/SOUE01/rels/d_a_obj_stage_sinkNP/symbols.txt +++ b/config/SOUE01/rels/d_a_obj_stage_sinkNP/symbols.txt @@ -25,7 +25,7 @@ finalizeState_Wait__15dAcOstageSink_cFv = .text:0x00000AA0; // type:function siz initializeState_Move__15dAcOstageSink_cFv = .text:0x00000AB0; // type:function size:0x4 executeState_Move__15dAcOstageSink_cFv = .text:0x00000AC0; // type:function size:0x23C finalizeState_Move__15dAcOstageSink_cFv = .text:0x00000D00; // type:function size:0x4 -fn_383_D10 = .text:0x00000D10; // type:function size:0xC +GetInstance__15dAcOstageSink_cFv = .text:0x00000D10; // type:function size:0xC fn_383_D20 = .text:0x00000D20; // type:function size:0xA0 fn_383_DC0 = .text:0x00000DC0; // type:function size:0x18 __dt__15dAcOstageSink_cFv = .text:0x00000DE0; // type:function size:0x100 diff --git a/config/SOUE01/rels/d_t_barrelNP/symbols.txt b/config/SOUE01/rels/d_t_barrelNP/symbols.txt index a56a2e20..fe6cee1f 100644 --- a/config/SOUE01/rels/d_t_barrelNP/symbols.txt +++ b/config/SOUE01/rels/d_t_barrelNP/symbols.txt @@ -4,31 +4,31 @@ _unresolved = .text:0x00000060; // type:function size:0x4 scope:global __register_global_object = .text:0x00000070; // type:function size:0x1C scope:global __destroy_global_chain = .text:0x00000090; // type:function size:0x54 scope:global dTgBarrel_c_classInit__Fv = .text:0x000000F0; // type:function size:0x100 -__dt__11dTgBarrel_cFv = .text:0x000001F0; // type:function size:0x58 +__dt__5dTg_cFv = .text:0x000001F0; // type:function size:0x58 __dt__24sFState_c<11dTgBarrel_c>Fv = .text:0x00000250; // type:function size:0x58 __dt__27sFStateFct_c<11dTgBarrel_c>Fv = .text:0x000002B0; // type:function size:0x6C __dt__80sStateMgr_c<11dTgBarrel_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000320; // type:function size:0xA0 __dt__50sFStateMgr_c<11dTgBarrel_c,20sStateMethodUsr_FI_c>Fv = .text:0x000003C0; // type:function size:0xA4 -fn_442_470 = .text:0x00000470; // type:function size:0x14 -fn_442_490 = .text:0x00000490; // type:function size:0x58 -fn_442_4F0 = .text:0x000004F0; // type:function size:0x14 -fn_442_510 = .text:0x00000510; // type:function size:0x58 -TgBarrel__init1 = .text:0x00000570; // type:function size:0xC0 +__ct__24dAcRef_c<12dAcOBarrel_c>Fv = .text:0x00000470; // type:function size:0x14 +__dt__24dAcRef_c<12dAcOBarrel_c>Fv = .text:0x00000490; // type:function size:0x58 +__ct__26dAcRef_c<14dTgBarrelPos_c>Fv = .text:0x000004F0; // type:function size:0x14 +__dt__26dAcRef_c<14dTgBarrelPos_c>Fv = .text:0x00000510; // type:function size:0x58 +actorCreate__11dTgBarrel_cFv = .text:0x00000570; // type:function size:0xC0 changeState__80sStateMgr_c<11dTgBarrel_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>FRC12sStateIDIf_c = .text:0x00000630; // type:function size:0x10 -TgBarrel__init2 = .text:0x00000640; // type:function size:0x9C -fn_442_6E0 = .text:0x000006E0; // type:function size:0x8 -TgBarrel__update = .text:0x000006F0; // type:function size:0x30 +actorPostCreate__11dTgBarrel_cFv = .text:0x00000640; // type:function size:0x9C +doDelete__11dTgBarrel_cFv = .text:0x000006E0; // type:function size:0x8 +actorExecute__11dTgBarrel_cFv = .text:0x000006F0; // type:function size:0x30 executeState__80sStateMgr_c<11dTgBarrel_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000720; // type:function size:0x10 -fn_442_730 = .text:0x00000730; // type:function size:0x8 +draw__11dTgBarrel_cFv = .text:0x00000730; // type:function size:0x8 initializeState_Wait__11dTgBarrel_cFv = .text:0x00000740; // type:function size:0x4 executeState_Wait__11dTgBarrel_cFv = .text:0x00000750; // type:function size:0x2E0 -fn_442_A30 = .text:0x00000A30; // type:function size:0x1C +calcTimer__4sLibFPUc_Uc = .text:0x00000A30; // type:function size:0x1C finalizeState_Wait__11dTgBarrel_cFv = .text:0x00000A50; // type:function size:0x4 initializeState_Stop__11dTgBarrel_cFv = .text:0x00000A60; // type:function size:0x4 executeState_Stop__11dTgBarrel_cFv = .text:0x00000A70; // type:function size:0x74 finalizeState_Stop__11dTgBarrel_cFv = .text:0x00000AF0; // type:function size:0x4 -fn_442_B00 = .text:0x00000B00; // type:function size:0x21C -fn_442_D20 = .text:0x00000D20; // type:function size:0x108 +checkPlayerPos__11dTgBarrel_cFRC7mVec3_c = .text:0x00000B00; // type:function size:0x21C +__dt__11dTgBarrel_cFv = .text:0x00000D20; // type:function size:0x108 getStateID__80sStateMgr_c<11dTgBarrel_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>CFv = .text:0x00000E30; // type:function size:0x10 build__27sFStateFct_c<11dTgBarrel_c>FRC12sStateIDIf_c = .text:0x00000E40; // type:function size:0x60 dispose__27sFStateFct_c<11dTgBarrel_c>FRP10sStateIf_c = .text:0x00000EA0; // type:function size:0xC diff --git a/include/d/a/obj/d_a_obj_stage_sink.h b/include/d/a/obj/d_a_obj_stage_sink.h index c8da109e..7a0340b4 100644 --- a/include/d/a/obj/d_a_obj_stage_sink.h +++ b/include/d/a/obj/d_a_obj_stage_sink.h @@ -3,7 +3,6 @@ #include "d/a/obj/d_a_obj_base.h" #include "s/s_State.hpp" -#include "s/s_StateMgr.hpp" class dAcOstageSink_c : public dAcObjBase_c { public: @@ -13,8 +12,12 @@ public: STATE_FUNC_DECLARE(dAcOstageSink_c, Wait); STATE_FUNC_DECLARE(dAcOstageSink_c, Move); + static dAcOstageSink_c *GetInstance(); + private: /* 0x??? */ STATE_MGR_DECLARE(dAcOstageSink_c); + + static dAcOstageSink_c *sInstance; }; #endif diff --git a/include/d/t/d_t_barrel.h b/include/d/t/d_t_barrel.h index a1255eb4..b122a196 100644 --- a/include/d/t/d_t_barrel.h +++ b/include/d/t/d_t_barrel.h @@ -1,20 +1,45 @@ #ifndef D_T_BARREL_H #define D_T_BARREL_H +#include "common.h" #include "d/a/d_a_base.h" +#include "d/t/d_tg.h" +#include "m/m_vec.h" #include "s/s_State.hpp" -#include "s/s_StateMgr.hpp" -class dTgBarrel_c : public dAcBase_c { +class dTgBarrelPos_c; +class dAcOBarrel_c; +class dAcOstageSink_c; + +class dTgBarrel_c : public dTg_c { public: dTgBarrel_c() : mStateMgr(*this, sStateID::null) {} virtual ~dTgBarrel_c() {} + virtual int doDelete() override; + virtual int draw() override; + virtual int actorCreate() override; + virtual int actorPostCreate() override; + virtual int actorExecute() override; + STATE_FUNC_DECLARE(dTgBarrel_c, Wait); STATE_FUNC_DECLARE(dTgBarrel_c, Stop); + bool checkPlayerPos(const mVec3_c &playerPos); + private: - /* 0x??? */ STATE_MGR_DECLARE(dTgBarrel_c); + /* 0x0FC */ STATE_MGR_DECLARE(dTgBarrel_c); + /* 0x138 */ dAcRef_c mStageRef; + /* 0x144 */ dAcRef_c mTgBarrelPosArr[10]; + /* 0x1BC */ dAcRef_c mBarrelArr[10]; + /* 0x234 */ mVec3_c mSpawnPosition; + /* 0x240 */ u8 field_0x240; ///< Stop Sceneflag + /* 0x241 */ u8 field_0x241; ///< Barrel Spawn Interval in Seconds + /* 0x242 */ u8 field_0x242; ///< Barrel Spawn Timer + /* 0x243 */ u8 field_0x243; + /* 0x244 */ u8 field_0x244; + /* 0x245 */ u8 field_0x245; + /* 0x246 */ u8 field_0x246; }; #endif diff --git a/include/d/t/d_t_barrel_pos.h b/include/d/t/d_t_barrel_pos.h index 2c0ac8f0..7685cde8 100644 --- a/include/d/t/d_t_barrel_pos.h +++ b/include/d/t/d_t_barrel_pos.h @@ -1,14 +1,24 @@ #ifndef D_T_BARREL_POS_H #define D_T_BARREL_POS_H -#include "d/a/d_a_base.h" +#include "d/t/d_tg.h" -class dTgBarrelPos_c : public dAcBase_c { +class dTgBarrelPos_c : public dTg_c { public: dTgBarrelPos_c() {} virtual ~dTgBarrelPos_c() {} + u8 getLinkIndex() const { + return mLinkIndex; + } + u8 getLinkId() const { + return mLinkId; + } + private: + /* 0x0FC */ u8 _0xFC[0x114 - 0xFC]; + /* 0x114 */ u8 mLinkIndex; + /* 0x115 */ u8 mLinkId; }; #endif diff --git a/src/REL/d/t/d_t_barrel.cpp b/src/REL/d/t/d_t_barrel.cpp index 40a232ef..3161ce50 100644 --- a/src/REL/d/t/d_t_barrel.cpp +++ b/src/REL/d/t/d_t_barrel.cpp @@ -1,13 +1,171 @@ #include "d/t/d_t_barrel.h" +#include "common.h" +#include "d/a/d_a_base.h" +#include "d/a/d_a_player.h" +#include "d/a/obj/d_a_obj_barrel.h" +#include "d/a/obj/d_a_obj_base.h" +#include "d/a/obj/d_a_obj_stage_sink.h" +#include "d/flag/sceneflag_manager.h" +#include "d/t/d_t_barrel_pos.h" +#include "f/f_base.h" +#include "f/f_manager.h" +#include "f/f_profile_name.h" +#include "m/m_angle.h" +#include "m/m_mtx.h" +#include "m/m_vec.h" +#include "s/s_Math.h" + SPECIAL_ACTOR_PROFILE(TAG_BARREL, dTgBarrel_c, fProfile::TAG_BARREL, 0x221, 0, 0); STATE_DEFINE(dTgBarrel_c, Wait); STATE_DEFINE(dTgBarrel_c, Stop); +// Weak function ordering issue of the ctor and dtpr of the objects +// for the following in the member arrays +// dAcRef_c +// dAcRef_c + +int dTgBarrel_c::actorCreate() { + field_0x240 = getFromParams(0, 0xFF); + field_0x245 = getFromParams(16, 0xF); + field_0x241 = getFromParams(8, 0xFF); + field_0x242 = 1; + + mStageRef.link(dAcOstageSink_c::GetInstance()); + mSpawnPosition = mPosition; + + for (int i = 0; i < (int)ARRAY_LENGTH(mBarrelArr); ++i) { + mBarrelArr[i].unlink(); + } + + mStateMgr.changeState(StateID_Wait); + + return SUCCEEDED; +} + +int dTgBarrel_c::actorPostCreate() { + dTgBarrelPos_c *pTgBarrelPos = nullptr; + do { + pTgBarrelPos = + static_cast(fManager_c::searchBaseByProfName(fProfile::TAG_BARREL_POS, pTgBarrelPos)); + + if (pTgBarrelPos != nullptr) { + u8 index = pTgBarrelPos->getLinkIndex(); + if (field_0x245 == pTgBarrelPos->getLinkId()) { + mTgBarrelPosArr[index].link(pTgBarrelPos); + if (index >= field_0x243) { + field_0x243 = index + 1; + } + } + } + + } while (pTgBarrelPos != nullptr); + + return SUCCEEDED; +} + +int dTgBarrel_c::doDelete() { + return SUCCEEDED; +} + +int dTgBarrel_c::actorExecute() { + mStateMgr.executeState(); + return SUCCEEDED; +} + +int dTgBarrel_c::draw() { + return SUCCEEDED; +} + void dTgBarrel_c::initializeState_Wait() {} -void dTgBarrel_c::executeState_Wait() {} +void dTgBarrel_c::executeState_Wait() { + if (SceneflagManager::sInstance->checkBoolFlag(mRoomID, field_0x240)) { + mStateMgr.changeState(StateID_Stop); + return; + } + dAcOstageSink_c *pStage = mStageRef.get(); + + mVec3_c pos = pStage->mPosition; + mAng3_c rot = pStage->mRotation; + + mVec3_c stageDist = mSpawnPosition - pos; + mMtx_c m; + m.transS(pos); + m.ZXYrotM(rot); + m.multVecSR(stageDist, mPosition); + + mPosition += pos; + + if (checkPlayerPos(dAcPy_c::GetLink()->mPosition)) { + if (0 == sLib::calcTimer(&field_0x242)) { + field_0x246 = 1; + + u8 idx = 0xFF; + for (int i = 0; i < (int)ARRAY_LENGTH(mBarrelArr); ++i) { + if (!mBarrelArr[i].isLinked()) { + idx = i; + // I think they forgor a break here + } + } + + if (idx != 0xFF) { + dTgBarrelPos_c *pTgBarrelPos = mTgBarrelPosArr[field_0x244].get(); + if (pTgBarrelPos != nullptr) { + mVec3_c spawnPos = pTgBarrelPos->mPosition; + mAng3_c spawnRot(0, 0x4000, 0); + dAcObjBase_c *pObj = dAcObjBase_c::create( + fProfile::OBJ_BARREL, mRoomID, 0xFF00FF2, &spawnPos, &spawnRot, nullptr, 0xFFFFFFFF + ); + mBarrelArr[idx].link(static_cast(pObj)); + } + if (++field_0x244 >= field_0x243) { + field_0x244 = 0; + } + } + field_0x242 = field_0x241 * 30; + } + } else { + if (field_0x246) { + field_0x242 = field_0x241 * 30; + } + } +} void dTgBarrel_c::finalizeState_Wait() {} + void dTgBarrel_c::initializeState_Stop() {} -void dTgBarrel_c::executeState_Stop() {} +void dTgBarrel_c::executeState_Stop() { + if (!SceneflagManager::sInstance->checkBoolFlag(mRoomID, field_0x240)) { + mStateMgr.changeState(StateID_Wait); + } +} void dTgBarrel_c::finalizeState_Stop() {} + +bool dTgBarrel_c::checkPlayerPos(const mVec3_c &playerPos) { + // NONMATCHING + // https://decomp.me/scratch/TM82x + f32 scale = 0.5f; + + mAng rot = mStageRef.get()->mRotation.y; + + mVec3_c pos = mPosition; + pos += mVec3_c::Ey * (mScale.y * 0.5f); + pos.x = (playerPos.x - pos.x) / mScale.x; + pos.y = (playerPos.y - pos.y) / mScale.y; + pos.z = (playerPos.z - pos.z) / mScale.z; + + f32 cos = rot.cos(); + if (rot.cos() != 0.f) { + scale = mScale.x * ((pos.x * rot.sin()) / rot.cos()) / mScale.y; + } + + bool ret = false; + + if ((pos.x <= cos * 0.5f && -(cos * 0.5f) <= pos.x) // + && pos.y <= scale + 0.5f + 1e-6f && pos.y + -0.5f - 1e-6f <= pos.y // + && pos.z <= 0.5f && pos.z >= -0.5f) { + ret = true; + } + + return ret; +}