From 374e93821ed87c05e972f9c0c49424a8cb1cf061 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 31 May 2024 12:00:20 +0200 Subject: [PATCH] Document, fixup --- config/SOUE01/splits.txt | 3 +++ config/SOUE01/symbols.txt | 4 ++-- configure.py | 1 + include/d/tg/d_t_tumble_weed.h | 4 ++-- include/f/f_list_nd.h | 8 +++++++- include/f/f_manager.h | 1 + include/s/README.txt | 17 +++++++++++++++++ include/s/s_FState.hpp | 3 +++ include/s/s_FStateFct.hpp | 3 +++ include/s/s_FStateID.hpp | 3 +++ include/s/s_FStateMgr.hpp | 3 +++ include/s/s_Phase.hpp | 3 +++ include/s/s_State.hpp | 3 +++ include/s/s_StateID.hpp | 3 +++ include/s/s_StateIDChk.hpp | 3 +++ include/s/s_StateInterfaces.hpp | 3 +++ include/s/s_StateMethod.hpp | 3 +++ include/s/s_StateMethodUsr_FI.hpp | 3 +++ include/s/s_StateMgr.hpp | 3 +++ src/f/f_base.cpp | 5 ++--- src/s/s_Phase.cpp | 3 +++ src/s/s_StateID.cpp | 3 +++ src/s/s_StateMethod.cpp | 4 ++++ src/s/s_StateMethodUsr_FI.cpp | 3 +++ 24 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 include/s/README.txt diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 393ae007..af8e679c 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -212,6 +212,9 @@ s/s_StateMethod.cpp: s/s_StateMethodUsr_FI.cpp: .text start:0x802DE540 end:0x802DE6EC +s/s_Phase.cpp: + .text start:0x802DEEB0 end:0x802DEF74 + DynamicLink.cpp: .text start:0x802DF100 end:0x802DFD74 .data start:0x805419E8 end:0x80541A70 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 2bcfdfc2..0b0428d6 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17221,8 +17221,8 @@ fn_802DED40 = .text:0x802DED40; // type:function size:0x4 fn_802DED50 = .text:0x802DED50; // type:function size:0x50 fn_802DEDA0 = .text:0x802DEDA0; // type:function size:0x64 fn_802DEE10 = .text:0x802DEE10; // type:function size:0x98 -fn_802DEEB0 = .text:0x802DEEB0; // type:function size:0x14 -fn_802DEED0 = .text:0x802DEED0; // type:function size:0xA4 +__ct__8sPhase_cFPPFPv_Q28sPhase_c15METHOD_RESULT_ei = .text:0x802DEEB0; // type:function size:0x14 +callMethod__8sPhase_cFPv = .text:0x802DEED0; // type:function size:0xA4 fn_802DEF80 = .text:0x802DEF80; // type:function size:0x8 fn_802DEF90 = .text:0x802DEF90; // type:function size:0x4C fn_802DEFE0 = .text:0x802DEFE0; // type:function size:0x80 diff --git a/configure.py b/configure.py index 13218904..4ee79aad 100644 --- a/configure.py +++ b/configure.py @@ -314,6 +314,7 @@ config.libs = [ Object(Matching, "s/s_StateId.cpp"), Object(Matching, "s/s_StateMethod.cpp"), Object(Matching, "s/s_StateMethodUsr_FI.cpp"), + Object(Matching, "s/s_Phase.cpp"), Object(Matching, "DynamicLink.cpp"), # framework (f_name) # d stuff (d_name) diff --git a/include/d/tg/d_t_tumble_weed.h b/include/d/tg/d_t_tumble_weed.h index baf61848..e3a80dd4 100644 --- a/include/d/tg/d_t_tumble_weed.h +++ b/include/d/tg/d_t_tumble_weed.h @@ -6,9 +6,9 @@ #include #include -class fLiNdTumbleweed_c : public fLiNdBa_c { +class fLiNdTumbleweed_c : public fLiNdBaAutoUnlink_c { public: - fLiNdTumbleweed_c(fBase_c *owner) : fLiNdBa_c(owner) {} + fLiNdTumbleweed_c(fBase_c *owner) : fLiNdBaAutoUnlink_c(owner) {} u16 someField; }; diff --git a/include/f/f_list_nd.h b/include/f/f_list_nd.h index 6adb8ea6..cc237048 100644 --- a/include/f/f_list_nd.h +++ b/include/f/f_list_nd.h @@ -12,7 +12,7 @@ class fBase_c; class fLiNdBa_c : public cListNd_c { public: fLiNdBa_c(fBase_c *owner) : p_owner(owner) {} - ~fLiNdBa_c() { unlink(); } + ~fLiNdBa_c() {} inline fLiNdBa_c *getPrev() const { return (fLiNdBa_c *)cListNd_c::getPrev(); @@ -28,4 +28,10 @@ public: fBase_c *p_owner; }; +class fLiNdBaAutoUnlink_c : public fLiNdBa_c { +public: + fLiNdBaAutoUnlink_c(fBase_c *owner) : fLiNdBa_c(owner) {} + ~fLiNdBaAutoUnlink_c() { unlink(); } +}; + #endif diff --git a/include/f/f_manager.h b/include/f/f_manager.h index d54f9acf..e2c18609 100644 --- a/include/f/f_manager.h +++ b/include/f/f_manager.h @@ -29,6 +29,7 @@ public: PROC_FLAG_DRAW = GET_PROC_FLAG(DRAW) }; fManager_c(fBase_c *owner) : connect_node(owner), execute_node(owner), draw_node(owner), search_node(owner) {} + ~fManager_c() {} /* 802e28c0 */ int getSearchTableNum(); /* 802e28d0 */ static fBase_c *searchBaseByID(fBaseID_e id); /* 802e2920 */ static fBase_c *searchBaseByProfName(ProfileName profID, const fBase_c *parent); diff --git a/include/s/README.txt b/include/s/README.txt new file mode 100644 index 00000000..99281a97 --- /dev/null +++ b/include/s/README.txt @@ -0,0 +1,17 @@ +This library was ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +with differences/modifications outlined below: + +## No inline destructors + +The NSMBW code uses inlined destructors. In SS, these destructors are all part of the s_StateID.cpp(?) TU, +and pretty much every generic instantiation of the state manager (which for a large part are in RELs) +will call back into those destructors in the main DOL. + +## s_StateIDChk.hpp + +In order for vtable ordering to match, some classes had to be extracted to a new header. + +## sStateMethodIf_c + +S_StateMethod_c's destructors calls back into another destructors. sStateMethodIf_c follows the example of +the other abstract interface classes and provides this dtor. diff --git a/include/s/s_FState.hpp b/include/s/s_FState.hpp index 2772d3dd..a883d6f3 100644 --- a/include/s/s_FState.hpp +++ b/include/s/s_FState.hpp @@ -2,6 +2,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A state holder for a given class. /// @tparam T The class that this state belongs to. /// @ingroup state diff --git a/include/s/s_FStateFct.hpp b/include/s/s_FStateFct.hpp index 55c1d861..3d349d3e 100644 --- a/include/s/s_FStateFct.hpp +++ b/include/s/s_FStateFct.hpp @@ -3,6 +3,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A state factory for a given class. /// @tparam T The class that this state belongs to. /// @ingroup state diff --git a/include/s/s_FStateID.hpp b/include/s/s_FStateID.hpp index 1100c54b..7ea2295a 100644 --- a/include/s/s_FStateID.hpp +++ b/include/s/s_FStateID.hpp @@ -2,6 +2,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief An implementation of a state ID for a given class. /// @details It adds the ability to call the three state methods on a state owner class. /// @tparam T The class that this state belongs to. diff --git a/include/s/s_FStateMgr.hpp b/include/s/s_FStateMgr.hpp index be2858c4..f154cbb6 100644 --- a/include/s/s_FStateMgr.hpp +++ b/include/s/s_FStateMgr.hpp @@ -5,6 +5,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A wrapper for sStateMgr_c that uses sFStateFct_c and sStateIDChk_c. /// @tparam T The class that this state belongs to. /// @tparam Method The method to use for the state manager. diff --git a/include/s/s_Phase.hpp b/include/s/s_Phase.hpp index d21b2f80..4b3d6403 100644 --- a/include/s/s_Phase.hpp +++ b/include/s/s_Phase.hpp @@ -1,5 +1,8 @@ #pragma once +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A phase is a list of methods to be called in order. /// @ingroup slib dol class sPhase_c { diff --git a/include/s/s_State.hpp b/include/s/s_State.hpp index 1df9c01f..8a7079f9 100644 --- a/include/s/s_State.hpp +++ b/include/s/s_State.hpp @@ -2,6 +2,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + #define STATE_FUNC_DECLARE(class, name) void initializeState_##name(); \ void executeState_##name(); \ void finalizeState_##name(); \ diff --git a/include/s/s_StateID.hpp b/include/s/s_StateID.hpp index cbfaab57..e74d155e 100644 --- a/include/s/s_StateID.hpp +++ b/include/s/s_StateID.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A generic implementation of a state ID. /// @details It simply contains a name string and a unique number. /// @ingroup state diff --git a/include/s/s_StateIDChk.hpp b/include/s/s_StateIDChk.hpp index 41d99213..c808ad8b 100644 --- a/include/s/s_StateIDChk.hpp +++ b/include/s/s_StateIDChk.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A default implementation of a state ID checker. /// @details ::isNormalID always returns true. class sStateIDChk_c : public sStateIDChkIf_c { diff --git a/include/s/s_StateInterfaces.hpp b/include/s/s_StateInterfaces.hpp index cb624230..0acd6f80 100644 --- a/include/s/s_StateInterfaces.hpp +++ b/include/s/s_StateInterfaces.hpp @@ -1,5 +1,8 @@ #pragma once +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @addtogroup state /// @{ diff --git a/include/s/s_StateMethod.hpp b/include/s/s_StateMethod.hpp index 8dadaa9e..4feb0c6a 100644 --- a/include/s/s_StateMethod.hpp +++ b/include/s/s_StateMethod.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief A class that handles state execution and transition. /// @details [Presumably, sStateMethod_c actually means "methods for state interaction", or something like that]. /// @ingroup state diff --git a/include/s/s_StateMethodUsr_FI.hpp b/include/s/s_StateMethodUsr_FI.hpp index 0921f336..8104557f 100644 --- a/include/s/s_StateMethodUsr_FI.hpp +++ b/include/s/s_StateMethodUsr_FI.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /// @brief An extension to sStateMethod_c that implements the remaining abstract methods. /// @details [Name might mean "Functionality implementation"]. /// @ingroup state diff --git a/include/s/s_StateMgr.hpp b/include/s/s_StateMgr.hpp index 3fe4c74c..66d07020 100644 --- a/include/s/s_StateMgr.hpp +++ b/include/s/s_StateMgr.hpp @@ -1,6 +1,9 @@ #pragma once #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + /** * @brief An implementation of sStateMgrIf_c. * diff --git a/src/f/f_base.cpp b/src/f/f_base.cpp index 661ec622..640f83e2 100644 --- a/src/f/f_base.cpp +++ b/src/f/f_base.cpp @@ -24,7 +24,6 @@ void (*fBase_c::sUnloadCallback)(); fBase_c::fBase_c() : unique_ID(m_rootUniqueID), params(m_tmpCtData.params), profile_name(m_tmpCtData.prof_name), group_type(m_tmpCtData.group_type), manager(this) { - fManager_c *mgr = &manager; m_rootUniqueID = (fBaseID_e)(m_rootUniqueID + 1); if (m_rootUniqueID == INVALID) { @@ -33,8 +32,8 @@ fBase_c::fBase_c() } } - fManager_c::m_connectManage.addTreeNode(&mgr->connect_node, m_tmpCtData.connect_parent); - int searchTableIdx = mgr->getSearchTableNum(); + fManager_c::m_connectManage.addTreeNode(&manager.connect_node, m_tmpCtData.connect_parent); + int searchTableIdx = manager.getSearchTableNum(); fManager_c::m_searchManage[searchTableIdx].prepend(&manager.search_node); const fProfile::fBaseProfile_c *profile = (*fProfile::sProfileList)[profile_name]; diff --git a/src/s/s_Phase.cpp b/src/s/s_Phase.cpp index 9418fbe9..734bb35e 100644 --- a/src/s/s_Phase.cpp +++ b/src/s/s_Phase.cpp @@ -1,5 +1,8 @@ #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + sPhase_c::sPhase_c(phaseMethod **methodList, int count) { mpMethodList = methodList; mPhaseLength = count; diff --git a/src/s/s_StateID.cpp b/src/s/s_StateID.cpp index 548a01e7..bf9100ec 100644 --- a/src/s/s_StateID.cpp +++ b/src/s/s_StateID.cpp @@ -4,6 +4,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + sStateID_c::NumberMemo_c sStateID_c::sm_numberMemo; sStateID_c sStateID::null(nullptr); diff --git a/src/s/s_StateMethod.cpp b/src/s/s_StateMethod.cpp index fec04f78..7c59854f 100644 --- a/src/s/s_StateMethod.cpp +++ b/src/s/s_StateMethod.cpp @@ -3,6 +3,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + sStateMethod_c::sStateMethod_c(sStateIDChkIf_c &checker, sStateFctIf_c &factory, const sStateIDIf_c &initialState) : mpStateChk(checker), mpStateFct(factory), @@ -37,6 +40,7 @@ void sStateMethod_c::initializeStateMethod() { void sStateMethod_c::executeStateMethod() { if (!mExecutionLock) { + // Skyward Sword change: Prevent runaway state changes? int i = 2; do { if (mRefreshStateMethod) { diff --git a/src/s/s_StateMethodUsr_FI.cpp b/src/s/s_StateMethodUsr_FI.cpp index cbcb5a54..9e42fc58 100644 --- a/src/s/s_StateMethodUsr_FI.cpp +++ b/src/s/s_StateMethodUsr_FI.cpp @@ -1,6 +1,9 @@ #include #include +// Note: Ported from https://github.com/NSMBW-Community/NSMBW-Decomp/tree/master/include/dol/sLib +// See include/s/README.txt for changes made + sStateMethodUsr_FI_c::sStateMethodUsr_FI_c(sStateIDChkIf_c &check, sStateFctIf_c &factory, const sStateIDIf_c &state) : sStateMethod_c(check, factory, state) { }