From fefe3af58f305a5543e2fe2c20f2415040dc4dd4 Mon Sep 17 00:00:00 2001 From: Elijah Thomas <42302100+elijah-thomas774@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:27:39 -0500 Subject: [PATCH] d_a_obj_flying_clawshot_target OK (fixed) (#102) * d_a_obj_flying_clawshot_target OK * fix tubo symbol --- .../splits.txt | 3 + .../symbols.txt | 31 ++-- config/SOUE01/rels/d_a_obj_tuboNP/symbols.txt | 2 +- config/SOUE01/symbols.txt | 8 +- configure.py | 2 +- include/d/a/d_a_player.h | 9 +- .../d/a/obj/d_a_obj_flying_clawshot_target.h | 17 ++ include/m/m_quat.h | 2 + include/m/m_vec.h | 5 + .../a/obj/d_a_obj_flying_clawshot_target.cpp | 163 ++++++++++++++++++ 10 files changed, 220 insertions(+), 22 deletions(-) diff --git a/config/SOUE01/rels/d_a_obj_flying_clawshot_targetNP/splits.txt b/config/SOUE01/rels/d_a_obj_flying_clawshot_targetNP/splits.txt index 98cab6cc..38a14158 100644 --- a/config/SOUE01/rels/d_a_obj_flying_clawshot_targetNP/splits.txt +++ b/config/SOUE01/rels/d_a_obj_flying_clawshot_targetNP/splits.txt @@ -11,3 +11,6 @@ REL/executor.c: REL/d/a/obj/d_a_obj_flying_clawshot_target.cpp: .text start:0x00000070 end:0x000009B4 + .rodata start:0x00000000 end:0x00000068 + .data start:0x00000000 end:0x000000D8 + .bss start:0x00000008 end:0x00000018 diff --git a/config/SOUE01/rels/d_a_obj_flying_clawshot_targetNP/symbols.txt b/config/SOUE01/rels/d_a_obj_flying_clawshot_targetNP/symbols.txt index 84967d2c..689d8b9c 100644 --- a/config/SOUE01/rels/d_a_obj_flying_clawshot_targetNP/symbols.txt +++ b/config/SOUE01/rels/d_a_obj_flying_clawshot_targetNP/symbols.txt @@ -2,22 +2,23 @@ _prolog = .text:0x00000000; // type:function size:0x2C scope:global _epilog = .text:0x00000030; // type:function size:0x2C scope:global _unresolved = .text:0x00000060; // type:function size:0x4 scope:global dAcOFlyingClawshotTarget_c_classInit__Fv = .text:0x00000070; // type:function size:0x5C -AcOFlyingClawshotTarget__initModels = .text:0x000000D0; // type:function size:0x98 -AcOFlyingClawshotTarget__init1 = .text:0x00000170; // type:function size:0x190 -AcOFlyingClawshotTarget__init2 = .text:0x00000300; // type:function size:0xDC -AcOFlyingClawshotTarget__update = .text:0x000003E0; // type:function size:0x52C -AcOFlyingClawshotTarget__draw = .text:0x00000910; // type:function size:0x28 +createHeap__26dAcOFlyingClawshotTarget_cFv = .text:0x000000D0; // type:function size:0x98 +actorCreate__26dAcOFlyingClawshotTarget_cFv = .text:0x00000170; // type:function size:0x190 +actorPostCreate__26dAcOFlyingClawshotTarget_cFv = .text:0x00000300; // type:function size:0xDC +actorExecute__26dAcOFlyingClawshotTarget_cFv = .text:0x000003E0; // type:function size:0x52C +draw__26dAcOFlyingClawshotTarget_cFv = .text:0x00000910; // type:function size:0x28 __dt__26dAcOFlyingClawshotTarget_cFv = .text:0x00000940; // type:function size:0x74 _ctors = .ctors:0x00000000; // type:label scope:global _dtors = .dtors:0x00000000; // type:label scope:global -lbl_615_rodata_0 = .rodata:0x00000000; // type:object size:0x28 data:float -lbl_615_rodata_28 = .rodata:0x00000028; // type:object size:0x2C data:4byte -lbl_615_rodata_54 = .rodata:0x00000054; // type:object size:0x4 data:float -lbl_615_rodata_58 = .rodata:0x00000058; // type:object size:0x10 data:float +sColSrc__26dAcOFlyingClawshotTarget_c = .rodata:0x00000000; // type:object size:0x28 data:4byte +lbl_615_rodata_28 = .rodata:0x00000028; // type:object size:0x28 scope:local data:4byte +lbl_615_rodata_50 = .rodata:0x00000050; // type:object size:0x4 scope:local data:float +lbl_615_rodata_54 = .rodata:0x00000054; // type:object size:0x4 scope:local data:float +lbl_615_rodata_58 = .rodata:0x00000058; // type:object size:0x10 scope:local data:float g_profile_OBJ_FLYING_CLAWSHOT_TARGET = .data:0x00000000; // type:object size:0x10 -lbl_615_data_10 = .data:0x00000010; // type:object size:0x10 -lbl_615_data_20 = .data:0x00000020; // type:object size:0x28 data:string -lbl_615_data_48 = .data:0x00000048; // type:object size:0x10 -lbl_615_data_58 = .data:0x00000058; // type:object size:0x80 -lbl_615_bss_8 = .bss:0x00000008; // type:object size:0x1 data:byte -lbl_615_bss_C = .bss:0x0000000C; // type:object size:0xC data:float +lbl_615_data_10 = .data:0x00000010; // type:object size:0x10 scope:local +lbl_615_data_20 = .data:0x00000020; // type:object size:0x28 scope:local data:string +lbl_615_data_48 = .data:0x00000048; // type:object size:0x10 scope:local +__vt__26dAcOFlyingClawshotTarget_c = .data:0x00000058; // type:object size:0x80 +@GUARD@actorExecute__26dAcOFlyingClawshotTarget_cFv@vec = .bss:0x00000008; // type:object size:0x1 scope:local data:byte +@LOCAL@actorExecute__26dAcOFlyingClawshotTarget_cFv@vec = .bss:0x0000000C; // type:object size:0xC scope:local data:float diff --git a/config/SOUE01/rels/d_a_obj_tuboNP/symbols.txt b/config/SOUE01/rels/d_a_obj_tuboNP/symbols.txt index 22ffeddf..1c08dfaf 100644 --- a/config/SOUE01/rels/d_a_obj_tuboNP/symbols.txt +++ b/config/SOUE01/rels/d_a_obj_tuboNP/symbols.txt @@ -9,7 +9,7 @@ __dt__23sFState_c<10dAcOtubo_c>Fv = .text:0x00000280; // type:function size:0x58 __dt__26sFStateFct_c<10dAcOtubo_c>Fv = .text:0x000002E0; // type:function size:0x6C __dt__79sStateMgr_c<10dAcOtubo_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>Fv = .text:0x00000350; // type:function size:0xA0 __dt__49sFStateMgr_c<10dAcOtubo_c,20sStateMethodUsr_FI_c>Fv = .text:0x000003F0; // type:function size:0xA4 -fn_272_4A0 = .text:0x000004A0; // type:function size:0x5C +lbl_272_text_4A0 = .text:0x000004A0; // type:label createHeap__10dAcOtubo_cFv = .text:0x00000500; // type:function size:0x90 actorCreate__10dAcOtubo_cFv = .text:0x00000590; // type:function size:0x2B0 changeState__79sStateMgr_c<10dAcOtubo_c,20sStateMethodUsr_FI_c,12sFStateFct_c,13sStateIDChk_c>FRC12sStateIDIf_c = .text:0x00000840; // type:function size:0x10 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index ff7a6174..981f3754 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17863,8 +17863,8 @@ __sinit_\m_pad_cpp = .text:0x802F2260; // type:function size:0x58 scope:local __ct__Q24mPad19PadAdditionalData_tFv = .text:0x802F22C0; // type:function size:0x4 __dt__Q24mPad19PadAdditionalData_tFv = .text:0x802F22D0; // type:function size:0x40 __arraydtor$4414 = .text:0x802F2310; // type:function size:0x1C -mQuat____ct = .text:0x802F2330; // type:function size:0x120 -fn_802F2450 = .text:0x802F2450; // type:function size:0x18C +Set__7mQuat_cFRC7mVec3_cRC7mVec3_c = .text:0x802F2330; // type:function size:0x120 +fn_802F2450__7mQuat_cFRC7mVec3_cRC7mVec3_cf = .text:0x802F2450; // type:function size:0x18C fn_802F25E0 = .text:0x802F25E0; // type:function size:0x19C fn_802F2780__7mQuat_cFRC7mQuat_c = .text:0x802F2780; // type:function size:0x198 fn_802F2920 = .text:0x802F2920; // type:function size:0x48 @@ -17872,9 +17872,9 @@ mVec__createProjectionXZ = .text:0x802F2970; // type:function size:0x110 mVec__fromXY = .text:0x802F2A80; // type:function size:0xF0 normalize__7mVec3_cFv = .text:0x802F2B70; // type:function size:0x78 mVec__normalizeRS = .text:0x802F2BF0; // type:function size:0x84 -mVec__rotX = .text:0x802F2C80; // type:function size:0xA8 +rotX__7mVec3_cFRC4mAng = .text:0x802F2C80; // type:function size:0xA8 rotY__7mVec3_cFRC4mAng = .text:0x802F2D30; // type:function size:0xAC -Vec3f__rotZ = .text:0x802F2DE0; // type:function size:0xA8 +rotZ__7mVec3_cFRC4mAng = .text:0x802F2DE0; // type:function size:0xA8 mVec__sinit = .text:0x802F2E90; // type:function size:0x78 homebutton__FrameController__init = .text:0x802F2F10; // type:function size:0x38 homebutton__FrameController__initFrame = .text:0x802F2F50; // type:function size:0x20 diff --git a/configure.py b/configure.py index 70f0edd6..519a6d24 100644 --- a/configure.py +++ b/configure.py @@ -1389,7 +1389,7 @@ config.libs = [ NonMatching, "d_a_obj_flower_ancient", "REL/d/a/obj/d_a_obj_flower_ancient.cpp" ), Rel( - NonMatching, + Matching, "d_a_obj_flying_clawshot_target", "REL/d/a/obj/d_a_obj_flying_clawshot_target.cpp", ), diff --git a/include/d/a/d_a_player.h b/include/d/a/d_a_player.h index 6fb18530..22036a63 100644 --- a/include/d/a/d_a_player.h +++ b/include/d/a/d_a_player.h @@ -74,7 +74,7 @@ public: /* vt 0x0D0 */ virtual void tryGrabItemWithWhip(); /* vt 0x0D4 */ virtual void someFloatWithWhip(); /* vt 0x0D8 */ virtual void getItemFromClawshotsMaybe(); - /* vt 0x0DC */ virtual void vt_0x0DC(); + /* vt 0x0DC */ virtual void vt_0x0DC(dAcBase_c *, mVec3_c &); /* vt 0x0E0 */ virtual void isUsingBomb(); /* vt 0x0E4 */ virtual void vt_0x0E4(); /* vt 0x0E8 */ virtual void vt_0x0E8(); @@ -246,5 +246,12 @@ public: return mCurrentAction; } + inline bool checkActionFlags(u32 mask) const { + return (mActionFlags & mask) != 0; + } + inline bool checkActionFlagsCont(u32 mask) const { + return (mActionFlagsCont & mask) != 0; + } + static dAcPy_c *LINK; }; diff --git a/include/d/a/obj/d_a_obj_flying_clawshot_target.h b/include/d/a/obj/d_a_obj_flying_clawshot_target.h index 844a720d..9dc1e1ec 100644 --- a/include/d/a/obj/d_a_obj_flying_clawshot_target.h +++ b/include/d/a/obj/d_a_obj_flying_clawshot_target.h @@ -2,13 +2,30 @@ #define D_A_OBJ_FLYING_CLAWSHOT_TARGET_H #include "d/a/obj/d_a_obj_base.h" +#include "d/col/cc/d_cc_d.h" +#include "m/m3d/m_smdl.h" +#include "m/m_quat.h" +#include "m/m_vec.h" class dAcOFlyingClawshotTarget_c : public dAcObjBase_c { public: dAcOFlyingClawshotTarget_c() {} virtual ~dAcOFlyingClawshotTarget_c() {} + virtual int draw() override; + virtual bool createHeap() override; + virtual int actorCreate() override; + virtual int actorPostCreate() override; + virtual int actorExecute() override; + private: + /* 0x330 */ m3d::smdl_c mMdl; + /* 0x34C */ dCcD_Sph mSph; + /* 0x49C */ int mState; + /* 0x4A0 */ mVec3_c mMarkPoint; + /* 0x4AC */ mQuat_c mToLink; + + static const cCcD_SrcGObj sColSrc; }; #endif diff --git a/include/m/m_quat.h b/include/m/m_quat.h index cf845858..5671d4ec 100644 --- a/include/m/m_quat.h +++ b/include/m/m_quat.h @@ -14,7 +14,9 @@ public: return *this; } + bool Set(const mVec3_c &, const mVec3_c &); void fn_802F2780(const mQuat_c &other); + bool fn_802F2450(const mVec3_c &, const mVec3_c &, f32); }; #endif diff --git a/include/m/m_vec.h b/include/m/m_vec.h index 9b25e29c..2eb48793 100644 --- a/include/m/m_vec.h +++ b/include/m/m_vec.h @@ -220,11 +220,16 @@ public: f32 distance(const mVec3_c &to) const { return EGG::Math::sqrt(PSVECSquareDistance(*this, to)); } + f32 squareDistance(const mVec3_c &to) const { + return VEC3DistSq(*this, to); + } f32 squareMagXZ() const { return x * x + z * z; } + void rotX(const mAng &angle); void rotY(const mAng &angle); + void rotZ(const mAng &angle); void CopyTo(nw4r::math::VEC3 *p) { p->x = x; diff --git a/src/REL/d/a/obj/d_a_obj_flying_clawshot_target.cpp b/src/REL/d/a/obj/d_a_obj_flying_clawshot_target.cpp index 9bfd5a8a..ce4fbf31 100644 --- a/src/REL/d/a/obj/d_a_obj_flying_clawshot_target.cpp +++ b/src/REL/d/a/obj/d_a_obj_flying_clawshot_target.cpp @@ -1,5 +1,168 @@ #include "d/a/obj/d_a_obj_flying_clawshot_target.h" +#include "common.h" +#include "d/a/d_a_player.h" +#include "d/a/obj/d_a_obj_base.h" +#include "d/col/c/c_cc_d.h" +#include "d/col/cc/d_cc_d.h" +#include "d/col/cc/d_cc_s.h" +#include "f/f_base.h" +#include "m/m_mtx.h" +#include "m/m_quat.h" +#include "m/m_vec.h" +#include "nw4r/g3d/g3d_resfile.h" +#include "nw4r/g3d/g3d_resmdl.h" +#include "rvl/MTX/mtxvec.h" + SPECIAL_ACTOR_PROFILE( OBJ_FLYING_CLAWSHOT_TARGET, dAcOFlyingClawshotTarget_c, fProfile::OBJ_FLYING_CLAWSHOT_TARGET, 0x142, 0, 2 ); + +bool dAcOFlyingClawshotTarget_c::createHeap() { + void *data = getOarcResFile("BirdObjD3_S"); + + if (!data) { + return false; + } + + nw4r::g3d::ResFile file = data; + if (!file.mFile.IsValid()) { + return false; + } + nw4r::g3d::ResMdl mdl = file.GetResMdl("BirdObjD3_S"); + if (!mdl.IsValid()) { + return false; + } + + return mMdl.create(mdl, &heap_allocator, 0x120, 1, nullptr); +} + +// clang-format off +const cCcD_SrcGObj dAcOFlyingClawshotTarget_c::sColSrc = { + /* mObjAt */ {0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0}, + /* mObjTg */ {~(AT_TYPE_BUGNET | AT_TYPE_BEETLE | AT_TYPE_0x80000 | AT_TYPE_0x8000 | AT_TYPE_WIND), 0x1080111, {6, 0x407}, 0, 0}, + /* mObjCo */ {0x0} +}; +// clang-format on + +int dAcOFlyingClawshotTarget_c::actorCreate() { + initAllocatorWork1Heap(-1, "dAcOFlyingClawshotTarget_c::m_allocator", 0x20); + + mMdl.setPriorityDraw(0x7F, 0x7F); + mWorldMtx.transS(mVec3_c::Zero); + mMdl.setLocalMtx(mWorldMtx); + mMdl.calc(true); + mMdl.getNodeWorldMtxMultVecZero(mMdl.getNodeID("Mark_point"), mMarkPoint); + + mStts.SetRank(0xC); + dCcD_SrcSph src = {sColSrc, 80.f}; + + mSph.Set(src); + mSph.SetStts(mStts); + mSph.SetC(position); + mState = 0; + + mVec3_c min, max; + mMdl.getBounds(&min, &max); + boundingBox.Set(min, max); + + return SUCCEEDED; +} + +int dAcOFlyingClawshotTarget_c::actorPostCreate() { + mVec3_c v = mVec3_c::Ez; + v.rotX(rotation.x); + v.rotY(rotation.y); + mVec3_c diff = dAcPy_c::LINK->position - position; + diff.normalize(); + if (!mToLink.Set(v, diff)) { + mToLink.set(1.f, 0.f, 0.f, 0.f); + } + return SUCCEEDED; +} + +int dAcOFlyingClawshotTarget_c::actorExecute() { + dAcPy_c *player = dAcPy_c::LINK; + + mVec3_c markPoint; + PSMTXMultVec(mWorldMtx, mMarkPoint, markPoint); + + f32 dist_to = markPoint.squareDistance(player->position); + + if (checkObjectProperty(0x4)) { + player->vt_0x0DC(this, mMarkPoint); + } + if (checkObjectProperty(0x4) && dist_to < 2500.f && + (player->checkActionFlagsCont(0x10000000) || player->checkActionFlagsCont(0x20000000))) { + static mVec3_c vec = -mVec3_c::Ey; + mVec3_c v2; + + v2.copyFrom(mToLink.rotateVector(mVec3_c::Ez)); + f32 f = 0.16f; + + mQuat_c q; + if (!q.fn_802F2450(v2, vec, f)) { + q.set(1.f, 0.f, 0.f, 0.f); + } + + mToLink = q * mToLink; + + } else { + mVec3_c vec = player->position - position; + vec.normalize(); + + mVec3_c v2; + v2.copyFrom(mToLink.rotateVector(mVec3_c::Ez)); + f32 f = 0.1f; + + mQuat_c q; + if (!q.fn_802F2450(v2, vec, f)) { + q.set(1.f, 0.f, 0.f, 0.f); + } + + mToLink = q * mToLink; + } + + switch (mState) { + case 0: { + if (checkObjectProperty(0x4)) { + if (player->checkActionFlagsCont(0x10000000) || player->checkActionFlagsCont(0x20000000)) { + mState = 2; + } else { + mState = 1; + } + } + } break; + case 1: { + if (checkObjectProperty(0x4)) { + if (player->checkActionFlagsCont(0x10000000) || player->checkActionFlagsCont(0x20000000)) { + mState = 2; + } + } else { + mState = 0; + } + } break; + case 2: { + if (!checkObjectProperty(0x4)) { + mState = 0; + } + } break; + } + + mMtx_c mtx; + updateMatrix(); + mtx.fromQuat(mToLink); + mWorldMtx += mtx; + mMdl.setLocalMtx(mWorldMtx); + mMdl.calc(false); + mSph.SetC(position); + dCcS::GetInstance()->Set(&mSph); + + return SUCCEEDED; +} + +int dAcOFlyingClawshotTarget_c::draw() { + drawModelType1(&mMdl); + + return SUCCEEDED; +}