diff --git a/asm/MetroidPrime/ScriptLoader.s b/asm/MetroidPrime/ScriptLoader.s index 56746b88..4d603b39 100644 --- a/asm/MetroidPrime/ScriptLoader.s +++ b/asm/MetroidPrime/ScriptLoader.s @@ -8482,7 +8482,7 @@ lbl_800CCC24: /* 800CCC7C 000C9BDC 93 A1 00 08 */ stw r29, 8(r1) /* 800CCC80 000C9BE0 38 81 00 14 */ addi r4, r1, 0x14 /* 800CCC84 000C9BE4 38 A1 00 18 */ addi r5, r1, 0x18 -/* 800CCC88 000C9BE8 48 10 C2 55 */ bl "__ct__23CScriptControllerActionF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobQ223CScriptControllerAction9ECommandsb" +/* 800CCC88 000C9BE8 48 10 C2 55 */ bl "__ct__23CScriptControllerActionF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobQ213ControlMapper9ECommandsbUib" /* 800CCC8C 000C9BEC 7C 78 1B 78 */ mr r24, r3 lbl_800CCC90: /* 800CCC90 000C9BF0 38 61 00 18 */ addi r3, r1, 0x18 diff --git a/asm/MetroidPrime/ScriptObjects/CScriptControllerAction.s b/asm/MetroidPrime/ScriptObjects/CScriptControllerAction.s index b002fdc8..22122ff6 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptControllerAction.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptControllerAction.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803E5C20 -lbl_803E5C20: +.global __vt__23CScriptControllerAction +__vt__23CScriptControllerAction: # ROM: 0x3E2C20 .4byte 0 .4byte 0 @@ -27,9 +27,9 @@ __dt__23CScriptControllerActionFv: /* 801D8D08 001D5C68 93 C1 00 08 */ stw r30, 8(r1) /* 801D8D0C 001D5C6C 7C 7E 1B 79 */ or. r30, r3, r3 /* 801D8D10 001D5C70 41 82 00 28 */ beq lbl_801D8D38 -/* 801D8D14 001D5C74 3C A0 80 3E */ lis r5, lbl_803E5C20@ha +/* 801D8D14 001D5C74 3C A0 80 3E */ lis r5, __vt__23CScriptControllerAction@ha /* 801D8D18 001D5C78 38 80 00 00 */ li r4, 0 -/* 801D8D1C 001D5C7C 38 05 5C 20 */ addi r0, r5, lbl_803E5C20@l +/* 801D8D1C 001D5C7C 38 05 5C 20 */ addi r0, r5, __vt__23CScriptControllerAction@l /* 801D8D20 001D5C80 90 1E 00 00 */ stw r0, 0(r30) /* 801D8D24 001D5C84 4B E7 85 51 */ bl __dt__7CEntityFv /* 801D8D28 001D5C88 7F E0 07 35 */ extsh. r0, r31 @@ -159,8 +159,8 @@ Accept__23CScriptControllerActionFR8IVisitor: /* 801D8ED4 001D5E34 38 21 00 10 */ addi r1, r1, 0x10 /* 801D8ED8 001D5E38 4E 80 00 20 */ blr -.global "__ct__23CScriptControllerActionF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobQ223CScriptControllerAction9ECommandsb" -"__ct__23CScriptControllerActionF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobQ223CScriptControllerAction9ECommandsb": +.global "__ct__23CScriptControllerActionF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobQ213ControlMapper9ECommandsbUib" +"__ct__23CScriptControllerActionF9TUniqueIdRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>RC11CEntityInfobQ213ControlMapper9ECommandsbUib": /* 801D8EDC 001D5E3C 94 21 FF D0 */ stwu r1, -0x30(r1) /* 801D8EE0 001D5E40 7C 08 02 A6 */ mflr r0 /* 801D8EE4 001D5E44 90 01 00 34 */ stw r0, 0x34(r1) @@ -178,9 +178,9 @@ Accept__23CScriptControllerActionFR8IVisitor: /* 801D8F14 001D5E74 7C 87 23 78 */ mr r7, r4 /* 801D8F18 001D5E78 38 81 00 08 */ addi r4, r1, 8 /* 801D8F1C 001D5E7C 4B E7 84 09 */ bl "__ct__7CEntityF9TUniqueIdRC11CEntityInfobRCQ24rstl66basic_string,Q24rstl17rmemory_allocator>" -/* 801D8F20 001D5E80 3C 60 80 3E */ lis r3, lbl_803E5C20@ha +/* 801D8F20 001D5E80 3C 60 80 3E */ lis r3, __vt__23CScriptControllerAction@ha /* 801D8F24 001D5E84 38 80 00 00 */ li r4, 0 -/* 801D8F28 001D5E88 38 03 5C 20 */ addi r0, r3, lbl_803E5C20@l +/* 801D8F28 001D5E88 38 03 5C 20 */ addi r0, r3, __vt__23CScriptControllerAction@l /* 801D8F2C 001D5E8C 90 1B 00 00 */ stw r0, 0(r27) /* 801D8F30 001D5E90 7F 63 DB 78 */ mr r3, r27 /* 801D8F34 001D5E94 93 9B 00 34 */ stw r28, 0x34(r27) diff --git a/configure.py b/configure.py index 02ecb608..3ef7c2c9 100755 --- a/configure.py +++ b/configure.py @@ -288,7 +288,7 @@ LIBS = [ "MetroidPrime/ScriptObjects/CScriptWorldTeleporter", "MetroidPrime/ScriptObjects/CScriptVisorGoo", "MetroidPrime/Enemies/CJellyZap", - "MetroidPrime/ScriptObjects/CScriptControllerAction", + ["MetroidPrime/ScriptObjects/CScriptControllerAction", False], ["MetroidPrime/Weapons/GunController/CGunMotion", False], ["MetroidPrime/ScriptObjects/CScriptSwitch", True], ["MetroidPrime/BodyState/CABSIdle", True], diff --git a/include/Kyoto/Input/CFinalInput.hpp b/include/Kyoto/Input/CFinalInput.hpp index 1b6113ea..c60da2ff 100644 --- a/include/Kyoto/Input/CFinalInput.hpp +++ b/include/Kyoto/Input/CFinalInput.hpp @@ -237,6 +237,8 @@ private: }; }; +CHECK_SIZEOF(CFinalInput, 48) + #ifdef __MWERKS__ #pragma cpp_extensions reset #endif diff --git a/include/MetroidPrime/CStateManager.hpp b/include/MetroidPrime/CStateManager.hpp index 9cc1fda0..52b8fd98 100644 --- a/include/MetroidPrime/CStateManager.hpp +++ b/include/MetroidPrime/CStateManager.hpp @@ -9,6 +9,7 @@ #include "Kyoto/Math/CVector2i.hpp" #include "Kyoto/TOneStatic.hpp" #include "Kyoto/TToken.hpp" +#include "Kyoto/Input/CFinalInput.hpp" #include "MetroidPrime/CEntityInfo.hpp" #include "MetroidPrime/CObjectList.hpp" @@ -161,6 +162,8 @@ public: CObjectList& GetObjectListById(EGameObjectList id) { return *x808_objectLists[id]; } + const CFinalInput& GetFinalInput() const { return xb54_finalInput; } + CCameraFilterPass& CameraFilterPass(ECameraFilterStage stage) { return xb84_camFilterPasses[size_t(stage)]; } @@ -230,6 +233,8 @@ public: void SetCinematicSkipObject(TUniqueId id) { xf38_skipCineSpecialFunc = id; } void SetInSaveUI(bool b) { xf94_28_inSaveUI = b; } bool GetInSaveUI() const { return xf94_28_inSaveUI; } + void SetInMapScreen(bool b) { xf94_27_inMapScreen = b; } + bool GetInMapScreen() const { return xf94_27_inMapScreen; } void SetIsFullThreat(bool v) { xf94_30_fullThreat = v; } uint GetInputFrameIdx() const { return x8d4_inputFrameIdx; } @@ -271,8 +276,9 @@ private: CRandom16 x8fc_random; CRandom16* x900_random; - uchar x904_pad[0x280]; + uchar x904_pad[0x250]; + CFinalInput xb54_finalInput; rstl::reserved_vector< CCameraFilterPass, kCFS_Max > xb84_camFilterPasses; rstl::reserved_vector< CCameraBlurPass, kCFS_Max > xd14_camBlurPasses; int xeec_hintIdx; diff --git a/include/MetroidPrime/ScriptObjects/CScriptControllerAction.hpp b/include/MetroidPrime/ScriptObjects/CScriptControllerAction.hpp new file mode 100644 index 00000000..eac16cc6 --- /dev/null +++ b/include/MetroidPrime/ScriptObjects/CScriptControllerAction.hpp @@ -0,0 +1,24 @@ +#ifndef _CSCRIPTCONTROLLERACTION +#define _CSCRIPTCONTROLLERACTION + +#include "MetroidPrime/CEntity.hpp" + +#include "MetroidPrime/CControlMapper.hpp" + +class CScriptControllerAction : public CEntity { + ControlMapper::ECommands x34_command; + uint x38_mapScreenSubaction; + bool x3c_24_mapScreenResponse : 1; + bool x3c_25_deactivateOnClose : 1; + bool x3c_26_pressed : 1; + +public: + CScriptControllerAction(TUniqueId uid, const rstl::string& name, const CEntityInfo& info, + bool active, ControlMapper::ECommands command, bool b1, uint w1, bool b2); + ~CScriptControllerAction(); + + void Accept(IVisitor& visitor) override; + void Think(float, CStateManager&) override; +}; + +#endif // _CSCRIPTCONTROLLERACTION diff --git a/src/MetroidPrime/ScriptObjects/CScriptControllerAction.cpp b/src/MetroidPrime/ScriptObjects/CScriptControllerAction.cpp new file mode 100644 index 00000000..cedfbd17 --- /dev/null +++ b/src/MetroidPrime/ScriptObjects/CScriptControllerAction.cpp @@ -0,0 +1,58 @@ +#include "MetroidPrime/ScriptObjects/CScriptControllerAction.hpp" + +#include "MetroidPrime/CStateManager.hpp" + +extern "C" ControlMapper::ECommands nullsub_51(float, ControlMapper::ECommands); + +CScriptControllerAction::CScriptControllerAction(TUniqueId uid, const rstl::string& name, + const CEntityInfo& info, bool active, + ControlMapper::ECommands command, + bool mapScreenResponse, uint w1, + bool deactivateOnClose) +: CEntity(uid, info, active, name) +, x34_command(command) +, x38_mapScreenSubaction(w1) +, x3c_24_mapScreenResponse(mapScreenResponse) +, x3c_25_deactivateOnClose(deactivateOnClose) +, x3c_26_pressed(false) {} + +void CScriptControllerAction::Accept(IVisitor& visitor) { visitor.Visit(*this); } + +void CScriptControllerAction::Think(float dt, CStateManager& stateMgr) { + bool oldPressed = x3c_26_pressed; + if (x3c_24_mapScreenResponse) { + switch (x38_mapScreenSubaction) { + case 0: + if (stateMgr.GetInMapScreen()) { + x3c_26_pressed = true; + } else { + x3c_26_pressed = false; + } + break; + default: + break; + } + } else { + if (ControlMapper::GetDigitalInput(nullsub_51(dt, x34_command), stateMgr.GetFinalInput())) { + x3c_26_pressed = true; + } else { + x3c_26_pressed = false; + } + } + + if (GetActive() && x3c_26_pressed != oldPressed) { + if (x3c_26_pressed) { + SendScriptMsgs(kSS_Open, stateMgr, kSM_None); + } else { + SendScriptMsgs(kSS_Closed, stateMgr, kSM_None); + if (x3c_25_deactivateOnClose) { + SetActive(false); + SendScriptMsgs(kSS_Inactive, stateMgr, kSM_None); + } + } + } +} + +extern "C" ControlMapper::ECommands nullsub_51(float, ControlMapper::ECommands c) { return c; } + +CScriptControllerAction::~CScriptControllerAction() {}