From 33b2c465942d6a1a29bde3b025dbaf8ef9ae3fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 25 Apr 2021 15:29:03 +0200 Subject: [PATCH] ksys/res: Start implementing AttClient --- data/uking_functions.csv | 64 ++++----- .../Resource/resResourceAttCheck.cpp | 2 +- src/KingSystem/Resource/resResourceAttCheck.h | 9 +- .../Resource/resResourceAttClient.cpp | 124 +++++++++++++++++- .../Resource/resResourceAttClient.h | 14 +- 5 files changed, 173 insertions(+), 40 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 3da41102..0912995a 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -31679,10 +31679,10 @@ 0x0000007100525514,_ZNK5uking2ai19PriestBossMakeClone27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE,288,_ZNK5uking2ai19PriestBossMakeClone27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE 0x0000007100525634,_ZNK5uking2ai19PriestBossMakeClone18getRuntimeTypeInfoEv,92,_ZNK5uking2ai19PriestBossMakeClone18getRuntimeTypeInfoEv 0x0000007100525690,_ZN3aal10OutputMode5text_Ei,428, -0x000000710052583c,j__ZdlPv_127,4, -0x0000007100525840,_ZN4sead19FixedSafeStringBaseIcLi90EEaSERKNS_14SafeStringBaseIcEE,240, -0x0000007100525930,j__ZdlPv_128,4, -0x0000007100525934,_ZN4sead15FixedSafeStringILi180EEaSERKNS_14SafeStringBaseIcEE,240, +0x000000710052583c,j__ZdlPv_127,4,_ZN4sead15FixedSafeStringILi54EED0Ev +0x0000007100525840,_ZN4sead15FixedSafeStringILi54EEaSERKNS_14SafeStringBaseIcEE,240,_ZN4sead15FixedSafeStringILi54EEaSERKNS_14SafeStringBaseIcEE +0x0000007100525930,j__ZdlPv_128,4,_ZN4sead19FixedSafeStringBaseIcLi54EED0Ev +0x0000007100525934,_ZN4sead19FixedSafeStringBaseIcLi54EEaSERKNS_14SafeStringBaseIcEE,240,_ZN4sead19FixedSafeStringBaseIcLi54EEaSERKNS_14SafeStringBaseIcEE 0x0000007100525a24,nullsub_1555,4, 0x0000007100525a28,AI_AIPriestBossPhaseOrMetaAIRoot::ctor,56, 0x0000007100525a60,_ZN5uking2ai14PriestBossMetaD1Ev,4,_ZN5uking2ai14PriestBossMetaD1Ev @@ -74506,7 +74506,7 @@ 0x0000007100d72868,sub_7100D72868,404, 0x0000007100d729fc,AttClient::x,436, 0x0000007100d72bb0,AttClient::setCallback,8, -0x0000007100d72bb8,enum_AttClientPriority_toText,428, +0x0000007100d72bb8,enum_AttClientPriority_toText,428,_ZN4ksys3act15AttPriorityType5text_Ei 0x0000007100d72d64,sub_7100D72D64,104, 0x0000007100d72dcc,ActorAttention::make,544, 0x0000007100d72fec,ActorAttention::init,392, @@ -85854,7 +85854,7 @@ 0x000000710100c5f8,sub_710100C5F8,428, 0x000000710100c7a4,sub_710100C7A4,428, 0x000000710100c950,j__ZdlPv_1055,4, -0x000000710100c954,_ZN4sead15FixedSafeStringILi54EEaSERKNS_14SafeStringBaseIcEE,240, +0x000000710100c954,xxx,240, 0x000000710100ca44,j__ZdlPv_1056,4, 0x000000710100ca48,sub_710100CA48,8, 0x000000710100ca50,sub_710100CA50,8, @@ -85862,9 +85862,9 @@ 0x000000710100ca60,sub_710100CA60,16, 0x000000710100ca70,sub_710100CA70,428, 0x000000710100cc1c,j__ZdlPv_1057,4, -0x000000710100cc20,_ZN4sead19FixedSafeStringBaseIcLi54EEaSERKNS_14SafeStringBaseIcEE,240, +0x000000710100cc20,xxx,240, 0x000000710100cd10,j__ZdlPv_1058,4, -0x000000710100cd14,_ZN4sead15FixedSafeStringILi113EEaSERKNS_14SafeStringBaseIcEE,240, +0x000000710100cd14,xxx,240, 0x000000710100ce04,sub_710100CE04,100, 0x000000710100ce68,sub_710100CE68,172, 0x000000710100cf14,sub_710100CF14,12, @@ -87874,33 +87874,33 @@ 0x00000071010931e4,ResourceBatcllist::m6,8, 0x00000071010931ec,sub_71010931EC,372, 0x0000007101093360,sub_7101093360,308, -0x0000007101093494,sub_7101093494,268, -0x00000071010935a0,sub_71010935A0,268, -0x00000071010936ac,sub_71010936AC,280, -0x00000071010937c4,sub_71010937C4,256, -0x00000071010938c4,sub_71010938C4,8, -0x00000071010938cc,sub_71010938CC,8, -0x00000071010938d4,nullsub_4465,4, -0x00000071010938d8,nullsub_4466,4, -0x00000071010938dc,sub_71010938DC,3304, -0x00000071010945c4,sub_71010945C4,8, -0x00000071010945cc,sub_71010945CC,8, +0x0000007101093494,sub_7101093494,268,_ZN4ksys3res9AttClientD1Ev +0x00000071010935a0,sub_71010935A0,268,_ZThn632_N4ksys3res9AttClientD1Ev +0x00000071010936ac,sub_71010936AC,280,_ZThn664_N4ksys3res9AttClientD1Ev +0x00000071010937c4,sub_71010937C4,256,_ZN4ksys3res9AttClientD0Ev +0x00000071010938c4,sub_71010938C4,8,_ZThn632_N4ksys3res9AttClientD0Ev +0x00000071010938cc,sub_71010938CC,8,_ZThn664_N4ksys3res9AttClientD0Ev +0x00000071010938d4,nullsub_4465,4,_ZN4ksys3res9AttClient9doCreate_EPhjPN4sead4HeapE +0x00000071010938d8,nullsub_4466,4,_ZThn632_N4ksys3res9AttClient9doCreate_EPhjPN4sead4HeapE +0x00000071010938dc,sub_71010938DC,3304,_ZN4ksys3res9AttClient6parse_EPhmPN4sead4HeapE +0x00000071010945c4,sub_71010945C4,8,_ZThn632_N4ksys3res9AttClient6parse_EPhmPN4sead4HeapE +0x00000071010945cc,sub_71010945CC,8,_ZNK4ksys3res9AttClient12getNumChecksEv 0x00000071010945d4,sub_71010945D4,156, 0x0000007101094670,sub_7101094670,248, 0x0000007101094768,sub_7101094768,116, -0x00000071010947dc,sub_71010947DC,364, -0x0000007101094948,sub_7101094948,8, -0x0000007101094950,sub_7101094950,92, -0x00000071010949ac,sub_71010949AC,8, -0x00000071010949b4,sub_71010949B4,8, -0x00000071010949bc,sub_71010949BC,92, -0x0000007101094a18,sub_7101094A18,8, -0x0000007101094a20,sub_7101094A20,428, -0x0000007101094bcc,j__ZdlPv_1171,4, -0x0000007101094bd0,_ZN4sead15FixedSafeStringILi147EEaSERKNS_14SafeStringBaseIcEE,240, -0x0000007101094cc0,j__ZdlPv_1172,4, -0x0000007101094cc4,_ZN4sead19FixedSafeStringBaseIcLi147EEaSERKNS_14SafeStringBaseIcEE,240, -0x0000007101094db4,sub_7101094DB4,372, +0x00000071010947dc,sub_71010947DC,364,_ZN4ksys3res9AttClient14appendPriorityEPN4sead22BufferedSafeStringBaseIcEE +0x0000007101094948,sub_7101094948,8,_ZNK4ksys3res9AttClient27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x0000007101094950,sub_7101094950,92,_ZNK4ksys3res9AttClient18getRuntimeTypeInfoEv +0x00000071010949ac,sub_71010949AC,8,_ZNK4ksys3res9AttClient10needsParseEv +0x00000071010949b4,sub_71010949B4,8,_ZThn632_NK4ksys3res9AttClient27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x00000071010949bc,sub_71010949BC,92,_ZThn632_NK4ksys3res9AttClient18getRuntimeTypeInfoEv +0x0000007101094a18,sub_7101094A18,8,_ZThn632_NK4ksys3res9AttClient10needsParseEv +0x0000007101094a20,sub_7101094A20,428,_ZN4ksys3act13AttActionType5text_Ei +0x0000007101094bcc,j__ZdlPv_1171,4,_ZN4sead15FixedSafeStringILi318EED0Ev +0x0000007101094bd0,_ZN4sead15FixedSafeStringILi318EEaSERKNS_14SafeStringBaseIcEE,240,_ZN4sead15FixedSafeStringILi318EEaSERKNS_14SafeStringBaseIcEE +0x0000007101094cc0,j__ZdlPv_1172,4,_ZN4sead19FixedSafeStringBaseIcLi318EED0Ev +0x0000007101094cc4,_ZN4sead19FixedSafeStringBaseIcLi318EEaSERKNS_14SafeStringBaseIcEE,240,_ZN4sead19FixedSafeStringBaseIcLi318EEaSERKNS_14SafeStringBaseIcEE +0x0000007101094db4,sub_7101094DB4,372,_ZN4ksys3res9AttClient33checkDerivedRuntimeTypeInfoStaticEPKN4sead15RuntimeTypeInfo9InterfaceE 0x0000007101094f28,sub_7101094F28,132,_ZN4ksys3res6AttPosC1Ev 0x0000007101094fac,sub_7101094FAC,360,_ZN4ksys3res6AttPos4initEPN3agl3utl13IParameterObjEPKcS7_S7_S7_ 0x0000007101095114,sub_7101095114,396, diff --git a/src/KingSystem/Resource/resResourceAttCheck.cpp b/src/KingSystem/Resource/resResourceAttCheck.cpp index fbe39358..676d19ed 100644 --- a/src/KingSystem/Resource/resResourceAttCheck.cpp +++ b/src/KingSystem/Resource/resResourceAttCheck.cpp @@ -193,7 +193,7 @@ AttCheck* AttCheck::make(const CreateArg& arg) { bool AttCheck::init(const AttCheck::CreateArg& arg) { mList.addObj(&mObj, "Parameters"); - mUserData = arg.user_data; + mClient = arg.client; return parse(arg); } diff --git a/src/KingSystem/Resource/resResourceAttCheck.h b/src/KingSystem/Resource/resResourceAttCheck.h index dbb2678d..5ff8ee65 100644 --- a/src/KingSystem/Resource/resResourceAttCheck.h +++ b/src/KingSystem/Resource/resResourceAttCheck.h @@ -31,13 +31,15 @@ enum class AttCheckType { UnderWater, }; +class AttClient; + class AttCheck { SEAD_RTTI_BASE(AttCheck) public: struct CreateArg { agl::utl::ResParameterList res_list; sead::Heap* heap; - void* user_data; + AttClient* client; }; static AttCheck* make(const CreateArg& arg); @@ -53,10 +55,13 @@ public: virtual bool parse(const CreateArg& arg); + // For internal use by AttClient. + agl::utl::ParameterList& getList_() { return mList; } + protected: bool init(const CreateArg& arg); - void* mUserData = nullptr; + AttClient* mClient = nullptr; AttCheckType mType{}; agl::utl::ParameterObj mObj; agl::utl::ParameterList mList; diff --git a/src/KingSystem/Resource/resResourceAttClient.cpp b/src/KingSystem/Resource/resResourceAttClient.cpp index 9dd52f21..a1e18a8f 100644 --- a/src/KingSystem/Resource/resResourceAttClient.cpp +++ b/src/KingSystem/Resource/resResourceAttClient.cpp @@ -1,12 +1,134 @@ #include "KingSystem/Resource/resResourceAttClient.h" +#include +#include "KingSystem/Resource/resResourceAttCheck.h" namespace ksys::res { AttClient::~AttClient() { - // TODO + for (int i = 0; i < mChecks.size(); ++i) { + if (mChecks[i]) { + delete mChecks[i]; + mChecks[i] = nullptr; + } + } mChecks.freeBuffer(); } void AttClient::doCreate_(u8*, u32, sead::Heap*) {} +namespace { + +// Keep this in sync with ksys::act::AttType! +sead::SafeArray sAttTypes = {{ + "Action", + "Lock", + "SwordSearch", + "Attack", + "Appeal", + "JumpRide", + "NameBalloon", + "LookOnly", +}}; + +void parseAttType(const agl::utl::ResParameterObj& AttClientParams, act::AttType* type) { + const sead::SafeString AttType = + agl::utl::getResParameter(AttClientParams, "AttType").getData(); + + *type = act::AttType::Invalid; + + for (int i = 0; i < sAttTypes.size(); ++i) { + if (AttType == sAttTypes[i]) { + *type = static_cast(i); + break; + } + } + + if (*type == act::AttType::Invalid) + *type = act::AttType::Action; +} + +void parseActionType(const agl::utl::ResParameterObj& AttClientParams, act::AttActionCode* code) { + const sead::SafeString ActionType = + agl::utl::getResParameter(AttClientParams, "ActionType").getData(); + + *code = act::AttActionCode::Dummy; + + for (int i = int(act::AttActionCode::None); i < int(act::AttActionCode::Dummy); ++i) { + if (ActionType == act::AttActionType::text(i - int(act::AttActionCode::None))) { + *code = static_cast(i); + break; + } + } + + if (*code == act::AttActionCode::Dummy) + *code = act::AttActionCode::None; +} + +} // namespace + +bool AttClient::parse_(u8* data, size_t size, sead::Heap* heap) { + if (!data) + return false; + + agl::utl::ResParameterArchive archive{data}; + const auto root = archive.getRootList(); + const auto AttClientParams = root.getResParameterObj(0); + + parseAttType(AttClientParams, &mAttType); + parseActionType(AttClientParams, &mActionCode); + addObj(&mAttClientParamsObj, "AttClientParams"); + + mAttTypeParam.init({sAttTypes[0]}, "AttType", "", &mAttClientParamsObj); + mActionTypeParam.init({act::AttActionType(act::AttActionType::None).text()}, "ActionType", "", + &mAttClientParamsObj); + mPriorityTypeParam.init({act::AttPriorityType(act::AttPriorityType::Obj).text()}, + "PriorityType", "", &mAttClientParamsObj); + + const int num_checks = root.getResParameterListNum(); + if (num_checks != 0) { + mChecks.allocBufferAssert(num_checks, heap); + for (int i = 0; i < num_checks; ++i) + mChecks[i] = nullptr; + + AttCheck::CreateArg arg{}; + arg.heap = heap; + arg.client = this; + + auto it = mChecks.begin(), end = mChecks.end(); + auto res_it = root.listBegin(), res_end = root.listEnd(); + for (; it != end && res_it != res_end; ++res_it, ++it) { + arg.res_list = res_it.getList(); + + auto* check = *it = AttCheck::make(arg); + if (check == nullptr) + return false; + + addList(&check->getList_(), + sead::FormatFixedSafeString<32>("%s%d", "Check_", it.getIndex())); + } + } + + applyResParameterArchive(archive); + + const sead::SafeString PriorityType = mPriorityTypeParam.ref(); + for (auto priority : act::AttPriorityType{}) { + if (PriorityType == priority.text()) { + mPriorityType = priority; + mPriorityTypeStr = PriorityType; + return true; + } + } + mPriorityType = act::AttPriorityType::Obj; + mPriorityTypeStr = mPriorityType.text(); + return true; +} + +int AttClient::getNumChecks() const { + return mChecks.size(); +} + +void AttClient::appendPriority(sead::BufferedSafeString* str) { + str->append(mPriorityTypeStr); +} + } // namespace ksys::res diff --git a/src/KingSystem/Resource/resResourceAttClient.h b/src/KingSystem/Resource/resResourceAttClient.h index eed04a32..4015ad6e 100644 --- a/src/KingSystem/Resource/resResourceAttClient.h +++ b/src/KingSystem/Resource/resResourceAttClient.h @@ -13,11 +13,11 @@ namespace ksys::res { +class AttCheck; + class AttClient : public ParamIO, public Resource { SEAD_RTTI_OVERRIDE(AttClient, Resource) public: - struct Check {}; - AttClient() : ParamIO("atcl", 0) {} ~AttClient() override; @@ -25,7 +25,13 @@ public: act::AttActionCode getActionCode() const { return mActionCode; } act::AttPriorityType getPriorityType() const { return mPriorityType; } const sead::SafeString& getPriorityTypeStr() const { return mPriorityTypeStr; } - const sead::Buffer& getChecks() const { return mChecks; } + const sead::Buffer& getChecks() const { return mChecks; } + + int getNumChecks() const; + + // TODO: check functions + + void appendPriority(sead::BufferedSafeString* str); void doCreate_(u8*, u32, sead::Heap*) override; bool needsParse() const override { return true; } @@ -40,7 +46,7 @@ private: agl::utl::Parameter> mAttTypeParam; agl::utl::Parameter> mActionTypeParam; agl::utl::Parameter> mPriorityTypeParam; - sead::Buffer mChecks; + sead::Buffer mChecks; }; KSYS_CHECK_SIZE_NX150(AttClient, 0x428);