From 2de628515feebf7008a6d91ddd448c83d0061715 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Sat, 15 Oct 2022 19:24:27 +0300 Subject: [PATCH] Match and link CScriptMemoryRelay Former-commit-id: 0648bc0e59e2685181ced46eab5ad84251079690 --- .../ScriptObjects/CScriptMemoryRelay.s | 12 +++--- configure.py | 2 +- include/MetroidPrime/CScriptMailbox.hpp | 12 ++++++ include/MetroidPrime/CStateManager.hpp | 2 + .../ScriptObjects/CScriptMemoryRelay.hpp | 18 +++++++++ obj_files.mk | 2 +- .../ScriptObjects/CScriptMemoryRelay.cpp | 38 +++++++++++++++++++ 7 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 include/MetroidPrime/CScriptMailbox.hpp create mode 100644 include/MetroidPrime/ScriptObjects/CScriptMemoryRelay.hpp create mode 100644 src/MetroidPrime/ScriptObjects/CScriptMemoryRelay.cpp diff --git a/asm/MetroidPrime/ScriptObjects/CScriptMemoryRelay.s b/asm/MetroidPrime/ScriptObjects/CScriptMemoryRelay.s index 0b29f45e..63c42619 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptMemoryRelay.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptMemoryRelay.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803E86E8 -lbl_803E86E8: +.global __vt__18CScriptMemoryRelay +__vt__18CScriptMemoryRelay: # ROM: 0x3E56E8 .4byte 0 .4byte 0 @@ -103,9 +103,9 @@ __dt__18CScriptMemoryRelayFv: /* 80241A0C 0023E96C 93 C1 00 08 */ stw r30, 8(r1) /* 80241A10 0023E970 7C 7E 1B 79 */ or. r30, r3, r3 /* 80241A14 0023E974 41 82 00 28 */ beq lbl_80241A3C -/* 80241A18 0023E978 3C A0 80 3F */ lis r5, lbl_803E86E8@ha +/* 80241A18 0023E978 3C A0 80 3F */ lis r5, __vt__18CScriptMemoryRelay@ha /* 80241A1C 0023E97C 38 80 00 00 */ li r4, 0 -/* 80241A20 0023E980 38 05 86 E8 */ addi r0, r5, lbl_803E86E8@l +/* 80241A20 0023E980 38 05 86 E8 */ addi r0, r5, __vt__18CScriptMemoryRelay@l /* 80241A24 0023E984 90 1E 00 00 */ stw r0, 0(r30) /* 80241A28 0023E988 4B E0 F8 4D */ bl __dt__7CEntityFv /* 80241A2C 0023E98C 7F E0 07 35 */ extsh. r0, r31 @@ -142,8 +142,8 @@ lbl_80241A3C: /* 80241A98 0023E9F8 7C 87 23 78 */ mr r7, r4 /* 80241A9C 0023E9FC 38 81 00 08 */ addi r4, r1, 8 /* 80241AA0 0023EA00 4B E0 F8 85 */ bl "__ct__7CEntityF9TUniqueIdRC11CEntityInfobRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>" -/* 80241AA4 0023EA04 3C 60 80 3F */ lis r3, lbl_803E86E8@ha -/* 80241AA8 0023EA08 38 03 86 E8 */ addi r0, r3, lbl_803E86E8@l +/* 80241AA4 0023EA04 3C 60 80 3F */ lis r3, __vt__18CScriptMemoryRelay@ha +/* 80241AA8 0023EA08 38 03 86 E8 */ addi r0, r3, __vt__18CScriptMemoryRelay@l /* 80241AAC 0023EA0C 90 1C 00 00 */ stw r0, 0(r28) /* 80241AB0 0023EA10 7F 83 E3 78 */ mr r3, r28 /* 80241AB4 0023EA14 88 1C 00 34 */ lbz r0, 0x34(r28) diff --git a/configure.py b/configure.py index f01ab13c..8f273a04 100755 --- a/configure.py +++ b/configure.py @@ -339,7 +339,7 @@ LIBS = [ "MetroidPrime/Cameras/CBallCameraFailsafeState", "MetroidPrime/Enemies/CActorContraption", "MetroidPrime/ScriptObjects/CScriptSpindleCamera", - "MetroidPrime/ScriptObjects/CScriptMemoryRelay", + ["MetroidPrime/ScriptObjects/CScriptMemoryRelay", True], "MetroidPrime/CPauseScreenFrame", "MetroidPrime/Enemies/CAtomicAlpha", "MetroidPrime/CLogBookScreen", diff --git a/include/MetroidPrime/CScriptMailbox.hpp b/include/MetroidPrime/CScriptMailbox.hpp new file mode 100644 index 00000000..73cabf16 --- /dev/null +++ b/include/MetroidPrime/CScriptMailbox.hpp @@ -0,0 +1,12 @@ +#ifndef _CSCRIPTMAILBOX +#define _CSCRIPTMAILBOX + +#include "MetroidPrime/TGameTypes.hpp" + +class CScriptMailbox { +public: + void AddRelay(TEditorId id); + void RemoveRelay(TEditorId id); +}; + +#endif // _CSCRIPTMAILBOX diff --git a/include/MetroidPrime/CStateManager.hpp b/include/MetroidPrime/CStateManager.hpp index 9ea2d1f8..aa45b0bc 100644 --- a/include/MetroidPrime/CStateManager.hpp +++ b/include/MetroidPrime/CStateManager.hpp @@ -140,6 +140,8 @@ public: const CPlayerState* GetPlayerState() const { return x8b8_playerState.GetPtr(); } CWorld* World() { return x850_world.get(); } const CWorld* GetWorld() const { return x850_world.get(); } + CScriptMailbox* Mailbox() { return x8bc_mailbox.GetPtr(); } + const CScriptMailbox* GetMailbox() const { return x8bc_mailbox.GetPtr(); } CActorModelParticles* ActorModelParticles() { return x884_actorModelParticles.get(); } const CActorModelParticles* GetActorModelParticles() const { return x884_actorModelParticles.get(); diff --git a/include/MetroidPrime/ScriptObjects/CScriptMemoryRelay.hpp b/include/MetroidPrime/ScriptObjects/CScriptMemoryRelay.hpp new file mode 100644 index 00000000..86908446 --- /dev/null +++ b/include/MetroidPrime/ScriptObjects/CScriptMemoryRelay.hpp @@ -0,0 +1,18 @@ +#ifndef _CSCRIPTMEMORYRELAY +#define _CSCRIPTMEMORYRELAY + +#include "MetroidPrime/CEntity.hpp" + +class CScriptMemoryRelay : public CEntity { + uchar x34_24_defaultActive : 1; + bool x34_25_skipSendActive : 1; + bool x34_26_ignoreMessages : 1; +public: + CScriptMemoryRelay(TUniqueId, const rstl::string&, const CEntityInfo&, bool, bool, bool); + ~CScriptMemoryRelay(); + + void AcceptScriptMsg(EScriptObjectMessage, TUniqueId, CStateManager&); + void Accept(IVisitor& visitor); +}; + +#endif // _CSCRIPTMEMORYRELAY diff --git a/obj_files.mk b/obj_files.mk index fedf9bc1..7c09728a 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -306,7 +306,7 @@ METROIDPRIME :=\ $(BUILD_DIR)/asm/MetroidPrime/Cameras/CBallCameraFailsafeState.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CActorContraption.o\ $(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptSpindleCamera.o\ - $(BUILD_DIR)/asm/MetroidPrime/ScriptObjects/CScriptMemoryRelay.o\ + $(BUILD_DIR)/src/MetroidPrime/ScriptObjects/CScriptMemoryRelay.o\ $(BUILD_DIR)/asm/MetroidPrime/CPauseScreenFrame.o\ $(BUILD_DIR)/asm/MetroidPrime/Enemies/CAtomicAlpha.o\ $(BUILD_DIR)/asm/MetroidPrime/CLogBookScreen.o\ diff --git a/src/MetroidPrime/ScriptObjects/CScriptMemoryRelay.cpp b/src/MetroidPrime/ScriptObjects/CScriptMemoryRelay.cpp new file mode 100644 index 00000000..ef17b025 --- /dev/null +++ b/src/MetroidPrime/ScriptObjects/CScriptMemoryRelay.cpp @@ -0,0 +1,38 @@ +#include "MetroidPrime/ScriptObjects/CScriptMemoryRelay.hpp" + +#include "MetroidPrime/CScriptMailbox.hpp" + +CScriptMemoryRelay::CScriptMemoryRelay(TUniqueId uid, const rstl::string& name, + const CEntityInfo& info, bool defaultActive, + bool skipSendActive, bool ignoreMessages) +: CEntity(uid, info, true, name) +, x34_24_defaultActive(defaultActive) +, x34_25_skipSendActive(skipSendActive) +, x34_26_ignoreMessages(ignoreMessages) {} + +CScriptMemoryRelay::~CScriptMemoryRelay() {} + +void CScriptMemoryRelay::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager& stateMgr) { + if (x34_26_ignoreMessages) { + return; + } + + switch (msg) { + case kSM_Activate: + stateMgr.Mailbox()->AddRelay(GetEditorId()); + if (!x34_25_skipSendActive) { + SendScriptMsgs(kSS_Active, stateMgr, kSM_None); + } + break; + + case kSM_Deactivate: + stateMgr.Mailbox()->RemoveRelay(GetEditorId()); + break; + + default: + CEntity::AcceptScriptMsg(msg, objId, stateMgr); + break; + } +} + +void CScriptMemoryRelay::Accept(IVisitor& visitor) { visitor.Visit(*this); }