From b6b39b741200a32275616f2c28646fb074128afe Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Sun, 16 Oct 2022 18:59:40 +0300 Subject: [PATCH] Add CTweakPlayerControl Former-commit-id: eec8e2904451c442d6471de92261f37fe16c6531 --- asm/MetroidPrime/Tweaks/CTweakPlayerControl.s | 12 ++++----- include/MetroidPrime/CControlMapper.hpp | 27 +++++++++++++++++++ .../Tweaks/CTweakPlayerControl.hpp | 26 ++++++++++++++++++ .../Tweaks/CTweakPlayerControl.cpp | 23 ++++++++++++++++ 4 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 include/MetroidPrime/Tweaks/CTweakPlayerControl.hpp create mode 100644 src/MetroidPrime/Tweaks/CTweakPlayerControl.cpp diff --git a/asm/MetroidPrime/Tweaks/CTweakPlayerControl.s b/asm/MetroidPrime/Tweaks/CTweakPlayerControl.s index 8840ae30..3d21008c 100644 --- a/asm/MetroidPrime/Tweaks/CTweakPlayerControl.s +++ b/asm/MetroidPrime/Tweaks/CTweakPlayerControl.s @@ -3,8 +3,8 @@ .section .data .balign 8 -.global lbl_803DA350 -lbl_803DA350: +.global __vt__19CTweakPlayerControl +__vt__19CTweakPlayerControl: # ROM: 0x3D7350 .4byte 0 .4byte 0 @@ -37,9 +37,9 @@ __ct__19CTweakPlayerControlFR12CInputStream: /* 8006F98C 0006C8EC 38 05 9C C4 */ addi r0, r5, __vt__12ITweakObject@l /* 8006F990 0006C8F0 93 E1 01 1C */ stw r31, 0x11c(r1) /* 8006F994 0006C8F4 7C 7F 1B 78 */ mr r31, r3 -/* 8006F998 0006C8F8 3C 60 80 3E */ lis r3, lbl_803DA350@ha +/* 8006F998 0006C8F8 3C 60 80 3E */ lis r3, __vt__19CTweakPlayerControl@ha /* 8006F99C 0006C8FC 90 1F 00 00 */ stw r0, 0(r31) -/* 8006F9A0 0006C900 38 03 A3 50 */ addi r0, r3, lbl_803DA350@l +/* 8006F9A0 0006C900 38 03 A3 50 */ addi r0, r3, __vt__19CTweakPlayerControl@l /* 8006F9A4 0006C904 38 61 00 08 */ addi r3, r1, 8 /* 8006F9A8 0006C908 90 1F 00 00 */ stw r0, 0(r31) /* 8006F9AC 0006C90C 48 00 00 AD */ bl LoadMappings__FR12CInputStream @@ -181,9 +181,9 @@ __dt__19CTweakPlayerControlFv: /* 8006FB74 0006CAD4 93 E1 00 0C */ stw r31, 0xc(r1) /* 8006FB78 0006CAD8 7C 7F 1B 79 */ or. r31, r3, r3 /* 8006FB7C 0006CADC 41 82 00 90 */ beq lbl_8006FC0C -/* 8006FB80 0006CAE0 3C 60 80 3E */ lis r3, lbl_803DA350@ha +/* 8006FB80 0006CAE0 3C 60 80 3E */ lis r3, __vt__19CTweakPlayerControl@ha /* 8006FB84 0006CAE4 34 1F 00 04 */ addic. r0, r31, 4 -/* 8006FB88 0006CAE8 38 03 A3 50 */ addi r0, r3, lbl_803DA350@l +/* 8006FB88 0006CAE8 38 03 A3 50 */ addi r0, r3, __vt__19CTweakPlayerControl@l /* 8006FB8C 0006CAEC 90 1F 00 00 */ stw r0, 0(r31) /* 8006FB90 0006CAF0 41 82 00 58 */ beq lbl_8006FBE8 /* 8006FB94 0006CAF4 80 DF 00 04 */ lwz r6, 4(r31) diff --git a/include/MetroidPrime/CControlMapper.hpp b/include/MetroidPrime/CControlMapper.hpp index 981bfb13..59868003 100644 --- a/include/MetroidPrime/CControlMapper.hpp +++ b/include/MetroidPrime/CControlMapper.hpp @@ -71,6 +71,33 @@ public: kC_MAX }; + enum EFunctionList { + kFL_None, + kFL_LeftStickUp, + kFL_LeftStickDown, + kFL_LeftStickLeft, + kFL_LeftStickRight, + kFL_RightStickUp, + kFL_RightStickDown, + kFL_RightStickLeft, + kFL_RightStickRight, + kFL_LeftTrigger, + kFL_RightTrigger, + kFL_DPadUp, + kFL_DPadDown, + kFL_DPadLeft, + kFL_DPadRight, + kFL_AButton, + kFL_BButton, + kFL_XButton, + kFL_YButton, + kFL_ZButton, + kFL_LeftTriggerPress, + kFL_RightTriggerPress, + kFL_Start, + kFL_MAX // default case + }; + static void SetCommandFiltered(ECommands cmd, bool filtered); }; diff --git a/include/MetroidPrime/Tweaks/CTweakPlayerControl.hpp b/include/MetroidPrime/Tweaks/CTweakPlayerControl.hpp new file mode 100644 index 00000000..7319dc39 --- /dev/null +++ b/include/MetroidPrime/Tweaks/CTweakPlayerControl.hpp @@ -0,0 +1,26 @@ +#ifndef _CTWEAKPLAYERCONTROL +#define _CTWEAKPLAYERCONTROL + +#include "MetroidPrime/Tweaks/ITweakObject.hpp" + +#include "MetroidPrime/CControlMapper.hpp" + +#include "Kyoto/TOneStatic.hpp" + +#include "rstl/reserved_vector.hpp" + +class CInputStream; +class CTweakPlayerControl; + +class CTweakPlayerControl : public ITweakObject, public TOneStatic< CTweakPlayerControl > { +public: + CTweakPlayerControl(CInputStream&); + ~CTweakPlayerControl() override; + + ControlMapper::EFunctionList GetMapping(ControlMapper::ECommands command) const; + +private: + rstl::reserved_vector m_mappings; +}; + +#endif // _CTWEAKPLAYERCONTROL diff --git a/src/MetroidPrime/Tweaks/CTweakPlayerControl.cpp b/src/MetroidPrime/Tweaks/CTweakPlayerControl.cpp new file mode 100644 index 00000000..319796ae --- /dev/null +++ b/src/MetroidPrime/Tweaks/CTweakPlayerControl.cpp @@ -0,0 +1,23 @@ +#include "MetroidPrime/Tweaks/CTweakPlayerControl.hpp" + +#include "Kyoto/Streams/CInputStream.hpp" + +CTweakPlayerControl::~CTweakPlayerControl() {} + +rstl::reserved_vector< ControlMapper::EFunctionList, 67 > LoadMappings(CInputStream& in) { + rstl::reserved_vector< ControlMapper::EFunctionList, 67 > result; + for (int i = 0; i < result.capacity(); ++i) { + result.push_back(static_cast(in.ReadLong())); + } + return result; +} + +CTweakPlayerControl::CTweakPlayerControl(CInputStream& in) : m_mappings(LoadMappings(in)) {} + +ControlMapper::EFunctionList +CTweakPlayerControl::GetMapping(ControlMapper::ECommands command) const { + if (command < ControlMapper::kC_Forward || command > ControlMapper::kC_UNKNOWN - 1) + return m_mappings[0]; + + return m_mappings[command]; +}