From 28976e9994fcce3deb66dcaeaa30616b79db6e57 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Fri, 4 Nov 2022 00:05:21 +0200 Subject: [PATCH] Match and link CScriptPlayerHint Former-commit-id: 7f414d1d5eec356ddb0aea2b10e6cc69609fe917 --- .../ScriptObjects/CScriptPlayerHint.s | 18 ++-- configure.py | 2 +- .../Enemies/CMetroidPrimeRelay.hpp | 14 +++ include/MetroidPrime/Player/CPlayer.hpp | 7 ++ .../ScriptObjects/CScriptPlayerHint.hpp | 31 ++++++ include/rstl/reserved_vector.hpp | 7 ++ obj_files.mk | 2 +- .../ScriptObjects/CScriptPlayerHint.cpp | 98 +++++++++++++++++++ 8 files changed, 168 insertions(+), 11 deletions(-) create mode 100644 include/MetroidPrime/Enemies/CMetroidPrimeRelay.hpp create mode 100644 include/MetroidPrime/ScriptObjects/CScriptPlayerHint.hpp create mode 100644 src/MetroidPrime/ScriptObjects/CScriptPlayerHint.cpp diff --git a/asm/MetroidPrime/ScriptObjects/CScriptPlayerHint.s b/asm/MetroidPrime/ScriptObjects/CScriptPlayerHint.s index c82d2865..7c7be2eb 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptPlayerHint.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptPlayerHint.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803E32D8 -lbl_803E32D8: +.global __vt__17CScriptPlayerHint +__vt__17CScriptPlayerHint: # ROM: 0x3E02D8 .4byte 0 .4byte 0 @@ -57,9 +57,9 @@ __dt__17CScriptPlayerHintFv: /* 8015B868 001587C8 93 C1 00 08 */ stw r30, 8(r1) /* 8015B86C 001587CC 7C 7E 1B 79 */ or. r30, r3, r3 /* 8015B870 001587D0 41 82 00 88 */ beq lbl_8015B8F8 -/* 8015B874 001587D4 3C 60 80 3E */ lis r3, lbl_803E32D8@ha +/* 8015B874 001587D4 3C 60 80 3E */ lis r3, __vt__17CScriptPlayerHint@ha /* 8015B878 001587D8 34 1E 00 E8 */ addic. r0, r30, 0xe8 -/* 8015B87C 001587DC 38 03 32 D8 */ addi r0, r3, lbl_803E32D8@l +/* 8015B87C 001587DC 38 03 32 D8 */ addi r0, r3, __vt__17CScriptPlayerHint@l /* 8015B880 001587E0 90 1E 00 00 */ stw r0, 0(r30) /* 8015B884 001587E4 41 82 00 58 */ beq lbl_8015B8DC /* 8015B888 001587E8 80 BE 00 E8 */ lwz r5, 0xe8(r30) @@ -219,7 +219,7 @@ lbl_8015BA94: /* 8015BAA0 00158A00 7F 83 E3 78 */ mr r3, r28 /* 8015BAA4 00158A04 38 81 00 20 */ addi r4, r1, 0x20 /* 8015BAA8 00158A08 B0 01 00 20 */ sth r0, 0x20(r1) -/* 8015BAAC 00158A0C 48 00 01 61 */ bl AddToObjectList__17CScriptPlayerHintF9TUniqueIdR13CStateManager +/* 8015BAAC 00158A0C 48 00 01 61 */ bl AddToObjectList__17CScriptPlayerHintF9TUniqueId /* 8015BAB0 00158A10 A0 1C 00 08 */ lhz r0, 8(r28) /* 8015BAB4 00158A14 7F 63 DB 78 */ mr r3, r27 /* 8015BAB8 00158A18 7F E5 FB 78 */ mr r5, r31 @@ -321,8 +321,8 @@ lbl_8015BBE8: /* 8015BC04 00158B64 90 03 00 E8 */ stw r0, 0xe8(r3) /* 8015BC08 00158B68 4E 80 00 20 */ blr -.global AddToObjectList__17CScriptPlayerHintF9TUniqueIdR13CStateManager -AddToObjectList__17CScriptPlayerHintF9TUniqueIdR13CStateManager: +.global AddToObjectList__17CScriptPlayerHintF9TUniqueId +AddToObjectList__17CScriptPlayerHintF9TUniqueId: /* 8015BC0C 00158B6C 80 03 00 E8 */ lwz r0, 0xe8(r3) /* 8015BC10 00158B70 38 C3 00 EC */ addi r6, r3, 0xec /* 8015BC14 00158B74 54 00 08 3C */ slwi r0, r0, 1 @@ -433,9 +433,9 @@ lbl_8015BCB0: /* 8015BD80 00158CE0 38 61 00 88 */ addi r3, r1, 0x88 /* 8015BD84 00158CE4 38 80 FF FF */ li r4, -1 /* 8015BD88 00158CE8 4B FB AC C5 */ bl __dt__10CModelDataFv -/* 8015BD8C 00158CEC 3C 60 80 3E */ lis r3, lbl_803E32D8@ha +/* 8015BD8C 00158CEC 3C 60 80 3E */ lis r3, __vt__17CScriptPlayerHint@ha /* 8015BD90 00158CF0 38 00 00 00 */ li r0, 0 -/* 8015BD94 00158CF4 38 83 32 D8 */ addi r4, r3, lbl_803E32D8@l +/* 8015BD94 00158CF4 38 83 32 D8 */ addi r4, r3, __vt__17CScriptPlayerHint@l /* 8015BD98 00158CF8 7F E3 FB 78 */ mr r3, r31 /* 8015BD9C 00158CFC 90 9F 00 00 */ stw r4, 0(r31) /* 8015BDA0 00158D00 90 1F 00 E8 */ stw r0, 0xe8(r31) diff --git a/configure.py b/configure.py index 36c5b033..6bdfe51c 100755 --- a/configure.py +++ b/configure.py @@ -223,7 +223,7 @@ LIBS = [ "MetroidPrime/Enemies/CSpankWeed", "MetroidPrime/Enemies/CParasite", "MetroidPrime/Player/CSamusFaceReflection", - "MetroidPrime/ScriptObjects/CScriptPlayerHint", + ["MetroidPrime/ScriptObjects/CScriptPlayerHint", True], "MetroidPrime/Enemies/CRipper", "MetroidPrime/Cameras/CCameraShakeData", "MetroidPrime/ScriptObjects/CScriptPickupGenerator", diff --git a/include/MetroidPrime/Enemies/CMetroidPrimeRelay.hpp b/include/MetroidPrime/Enemies/CMetroidPrimeRelay.hpp new file mode 100644 index 00000000..8ec52631 --- /dev/null +++ b/include/MetroidPrime/Enemies/CMetroidPrimeRelay.hpp @@ -0,0 +1,14 @@ +#ifndef _CMETROIDPRIMERELAY +#define _CMETROIDPRIMERELAY + +#include "MetroidPrime/CEntity.hpp" + +class CMetroidPrimeRelay : public CEntity { +public: + TUniqueId GetMetroidPrimeExoId() const { return x34_mpUid; } + +private: + TUniqueId x34_mpUid; +}; + +#endif // _CMETROIDPRIMERELAY diff --git a/include/MetroidPrime/Player/CPlayer.hpp b/include/MetroidPrime/Player/CPlayer.hpp index ec1d5b28..fb77dab4 100644 --- a/include/MetroidPrime/Player/CPlayer.hpp +++ b/include/MetroidPrime/Player/CPlayer.hpp @@ -224,6 +224,13 @@ public: float GetAverageSpeed() const; float GetGravity() const; + // PlayerHint + // bool SetAreaPlayerHint(const CScriptPlayerHint& hint, CStateManager& mgr); + void AddToPlayerHintRemoveList(TUniqueId id, CStateManager& mgr); + void AddToPlayerHintAddList(TUniqueId id, CStateManager& mgr); + // void DeactivatePlayerHint(TUniqueId id, CStateManager& mgr); + // void UpdatePlayerHints(CStateManager& mgr); + private: NPlayer::EPlayerMovementState x258_movementState; rstl::vector< CToken > x25c_ballTransitionsRes; diff --git a/include/MetroidPrime/ScriptObjects/CScriptPlayerHint.hpp b/include/MetroidPrime/ScriptObjects/CScriptPlayerHint.hpp new file mode 100644 index 00000000..b845b83f --- /dev/null +++ b/include/MetroidPrime/ScriptObjects/CScriptPlayerHint.hpp @@ -0,0 +1,31 @@ +#ifndef _CSCRIPTPLAYERHINT +#define _CSCRIPTPLAYERHINT + +#include "MetroidPrime/CActor.hpp" + +class CScriptPlayerHint : public CActor { +public: + CScriptPlayerHint(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, + const CTransform4f& xf, bool active, int priority, int overrideFlags); + ~CScriptPlayerHint(); + + void Accept(IVisitor& visit) override; + void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&) override; + int GetPriority() const { return x100_priority; } + int GetOverrideFlags() const { return x104_overrideFlags; } + TUniqueId GetActorId() const { return x108_mpId; } + void ClearObjectList(); + void SetDeactivated() { xfc_deactivated = true; } + +private: + rstl::reserved_vector< TUniqueId, 8 > xe8_objectList; + bool xfc_deactivated; + int x100_priority; + int x104_overrideFlags; + TUniqueId x108_mpId; + + void AddToObjectList(TUniqueId uid); + void RemoveFromObjectList(TUniqueId uid, CStateManager& mgr); +}; + +#endif // _CSCRIPTPLAYERHINT diff --git a/include/rstl/reserved_vector.hpp b/include/rstl/reserved_vector.hpp index ed733ce6..d0be68eb 100644 --- a/include/rstl/reserved_vector.hpp +++ b/include/rstl/reserved_vector.hpp @@ -81,6 +81,13 @@ public: --x0_count; } } + + iterator find(const T& value) { + rstl::reserved_vector< TUniqueId, 8 >::iterator it = begin(); + for (; it != end() && *it != value; ++it) { + } + return it; + } }; } // namespace rstl diff --git a/obj_files.mk b/obj_files.mk index 4516a64f..5229e977 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -188,7 +188,7 @@ METROIDPRIME :=\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CSpankWeed.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CParasite.o\ $(BUILD_DIR)/asm/MetroidPrime/Player/CSamusFaceReflection.o\ - $(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptPlayerHint.o\ + $(BUILD_DIR)/src/MetroidPrime/ScriptObjects/CScriptPlayerHint.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CRipper.o\ $(BUILD_DIR)/asm/MetroidPrime/Cameras/CCameraShakeData.o\ $(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptPickupGenerator.o\ diff --git a/src/MetroidPrime/ScriptObjects/CScriptPlayerHint.cpp b/src/MetroidPrime/ScriptObjects/CScriptPlayerHint.cpp new file mode 100644 index 00000000..733d3ac7 --- /dev/null +++ b/src/MetroidPrime/ScriptObjects/CScriptPlayerHint.cpp @@ -0,0 +1,98 @@ +#include "MetroidPrime/ScriptObjects/CScriptPlayerHint.hpp" + +#include "MetroidPrime/CActorParameters.hpp" +#include "MetroidPrime/CStateManager.hpp" +#include "MetroidPrime/Enemies/CMetroidPrimeRelay.hpp" +#include "MetroidPrime/Player/CPlayer.hpp" + +CScriptPlayerHint::CScriptPlayerHint(TUniqueId uid, const rstl::string& name, + const CEntityInfo& info, const CTransform4f& xf, bool active, + int priority, int overrideFlags) +: CActor(uid, active, name, info, xf, CModelData::CModelDataNull(), CMaterialList(kMT_NoStepLogic), + CActorParameters::None(), kInvalidUniqueId) +, xfc_deactivated(false) +, x100_priority(priority) +, x104_overrideFlags(overrideFlags) +, x108_mpId(kInvalidUniqueId) {} + +void CScriptPlayerHint::ClearObjectList() { xe8_objectList.clear(); } + +void CScriptPlayerHint::AddToObjectList(TUniqueId uid) { + rstl::reserved_vector< TUniqueId, 8 >::iterator it = xe8_objectList.find(uid); + if (it != xe8_objectList.end()) { + return; + } + xe8_objectList.push_back(uid); +} + +void CScriptPlayerHint::RemoveFromObjectList(TUniqueId uid, CStateManager& mgr) { + if (xe8_objectList.empty()) { + return; + } + + rstl::reserved_vector< TUniqueId, 8 >::iterator it = xe8_objectList.find(uid); + + if (it == xe8_objectList.end()) { + xe8_objectList.erase(xe8_objectList.begin()); + } else { + xe8_objectList.erase(it); + } +} + +void CScriptPlayerHint::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, + CStateManager& mgr) { + + switch (msg) { + case kSM_Deactivate: + case kSM_Deleted: + RemoveFromObjectList(sender, mgr); + CPlayer* player = mgr.Player(); + player->AddToPlayerHintRemoveList(GetUniqueId(), mgr); + xfc_deactivated = true; + break; + case kSM_Increment: + x108_mpId = kInvalidUniqueId; + if ((x104_overrideFlags & 0x4000) != 0) { + rstl::vector< SConnection >::const_iterator it = GetConnectionList().begin(); + for (; it != GetConnectionList().end(); ++it) { + if (it->x0_state != kSS_Play) { + continue; + } + x108_mpId = mgr.GetIdForScript(it->x8_objId); + if (const CMetroidPrimeRelay* mpRelay = + TCastToConstPtr< CMetroidPrimeRelay >(mgr.GetObjectById(x108_mpId))) { + x108_mpId = mpRelay->GetMetroidPrimeExoId(); + break; + } + } + } + break; + default: + break; + } + if (GetActive()) { + CPlayer* player = mgr.Player(); + + switch (msg) { + case kSM_Increment: + AddToObjectList(sender); + player->AddToPlayerHintAddList(GetUniqueId(), mgr); + xfc_deactivated = false; + break; + + case kSM_Decrement: + RemoveFromObjectList(sender, mgr); + player->AddToPlayerHintRemoveList(GetUniqueId(), mgr); + break; + + default: + break; + } + } + + CActor::AcceptScriptMsg(msg, sender, mgr); +} + +void CScriptPlayerHint::Accept(IVisitor& visitor) { visitor.Visit(*this); } + +CScriptPlayerHint::~CScriptPlayerHint() {}