From 622104fbd219117455c7a6776aea1658e36cd888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 22 Nov 2020 12:27:07 +0100 Subject: [PATCH] ksys/act: Add more InfoData functions --- data/uking_functions.csv | 12 +- src/KingSystem/ActorSystem/actActorCreator.h | 2 + src/KingSystem/ActorSystem/actDebug.h | 12 +- src/KingSystem/ActorSystem/actInfoData.cpp | 112 +++++++++++++++++++ src/KingSystem/ActorSystem/actInfoData.h | 5 + src/KingSystem/ActorSystem/actTag.h | 4 + src/KingSystem/Event/CMakeLists.txt | 2 + src/KingSystem/Event/evtEvent.cpp | 1 + src/KingSystem/Event/evtEvent.h | 26 +++++ 9 files changed, 169 insertions(+), 7 deletions(-) create mode 100644 src/KingSystem/Event/evtEvent.cpp create mode 100644 src/KingSystem/Event/evtEvent.h diff --git a/data/uking_functions.csv b/data/uking_functions.csv index e437a427..505c85be 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -73360,7 +73360,7 @@ 0x0000007100d2e2d8,ActorInfoData::init,628,_ZN4ksys3act8InfoData4initEPhPN4sead4HeapES5_ 0x0000007100d2e54c,ActorInfoData::getActorScaleColorModelBfres,820,_ZNK4ksys3act8InfoData12getModelInfoEPKcRNS1_9ModelInfoE 0x0000007100d2e880,ActorInfoData::getActorDataIter,208,_ZNK4ksys3act8InfoData12getActorIterEPN2al9ByamlIterEPKcb -0x0000007100d2e950,ActorInfoData::isNotMergedGrudgeOrArmor50OrWeaponSwordDemoCheck,348, +0x0000007100d2e950,ActorInfoData::isNotMergedGrudgeOrArmor50OrWeaponSwordDemoCheck,348,_ZNK4ksys3act8InfoData10logFailureERKN4sead14SafeStringBaseIcEE 0x0000007100d2eaac,ActorInfoData::x,1484,_ZNK4ksys3act8InfoData13getRecipeInfoEPKcRNS1_10RecipeInfoE 0x0000007100d2f078,act::getActorInfoInt,56,_ZN4ksys3act8InfoData11getIntByKeyERKN2al9ByamlIterEPKci 0x0000007100d2f0b0,bymlGetString,84,_ZN4ksys3act8InfoData14getStringByKeyERKN2al9ByamlIterEPKcRKN4sead14SafeStringBaseIcEE @@ -73402,14 +73402,14 @@ 0x0000007100d30cdc,sub_7100D30CDC,132,_ZNK4ksys3act8InfoData15getAabbNormHalfEPKc 0x0000007100d30d60,ActorInfoData::getIsHasFar,20,_ZNK4ksys3act8InfoData8isHasFarEPKc 0x0000007100d30d74,ActorInfoData::isAmiiboDrop,92,_ZNK4ksys3act8InfoData12hasDropEntryEPKcS3_ -0x0000007100d30dd0,ActorInfoData::getActorInstSize,20, -0x0000007100d30de4,ActorInfoData::getBugMask,20, +0x0000007100d30dd0,ActorInfoData::getActorInstSize,20,_ZNK4ksys3act8InfoData11getInstSizeEPKc +0x0000007100d30de4,ActorInfoData::getBugMask,20,_ZNK4ksys3act8InfoData10getBugMaskEPKc 0x0000007100d30df8,sub_7100D30DF8,64, 0x0000007100d30e38,sub_7100D30E38,408, 0x0000007100d30fd0,sub_7100D30FD0,408, -0x0000007100d31168,ActorInfoData::x_0,712, -0x0000007100d31430,sub_7100D31430,328, -0x0000007100d31578,ActorInfoData::getStringFromByaml,168, +0x0000007100d31168,ActorInfoData::x_0,712,_ZNK4ksys3act8InfoData13getModelFlagsEPKc +0x0000007100d31430,sub_7100D31430,328,_ZNK4ksys3act8InfoData19getVariationMatAnimEPKcPS3_Pf +0x0000007100d31578,ActorInfoData::getStringFromByaml,168,_ZNK4ksys3act8InfoData7getNameEPN2al9ByamlIterEPPKci 0x0000007100d31620,getTimeSubTypeString,428, 0x0000007100d317cc,AI_Action_DemoGetItem::ctor,48, 0x0000007100d317fc,AI_Action_DemoGetItem::dtor,20, diff --git a/src/KingSystem/ActorSystem/actActorCreator.h b/src/KingSystem/ActorSystem/actActorCreator.h index 65a3494b..ef6c229a 100644 --- a/src/KingSystem/ActorSystem/actActorCreator.h +++ b/src/KingSystem/ActorSystem/actActorCreator.h @@ -19,6 +19,8 @@ class ActorCreator { public: void setActorFactory(ActorFactory* factory) { mActorFactory = factory; } + bool get5a() const { return _5a; } + private: sead::Heap* forBaseProcDualHeap; sead::Heap* placementMgrHeap; diff --git a/src/KingSystem/ActorSystem/actDebug.h b/src/KingSystem/ActorSystem/actDebug.h index 5342d341..29495c25 100644 --- a/src/KingSystem/ActorSystem/actDebug.h +++ b/src/KingSystem/ActorSystem/actDebug.h @@ -1,21 +1,31 @@ #pragma once #include +#include #include "KingSystem/Utils/Types.h" namespace ksys::act { class ActorDebug { SEAD_SINGLETON_DISPOSER(ActorDebug) + virtual ~ActorDebug(); + public: + enum class Flag { + _10000000 = 0x10000000, + }; + struct HashUnused { u32 hash = 0; u32 b; }; const char* getNullStr(HashUnused* u); + bool hasFlag(Flag flag) const { return mFlags.isOn(flag); } - u8 TEMP1[0x2F0]; + void* _28; + sead::TypedBitFlag mFlags; + u8 TEMP1[0x2DC]; f32 mDispDistanceMultiplier; u8 TEMP2[0x114]; }; diff --git a/src/KingSystem/ActorSystem/actInfoData.cpp b/src/KingSystem/ActorSystem/actInfoData.cpp index af03b8a3..9d6427cb 100644 --- a/src/KingSystem/ActorSystem/actInfoData.cpp +++ b/src/KingSystem/ActorSystem/actInfoData.cpp @@ -2,6 +2,9 @@ #include #include #include +#include "KingSystem/ActorSystem/actActorCreator.h" +#include "KingSystem/ActorSystem/actDebug.h" +#include "KingSystem/Event/evtEvent.h" #include "KingSystem/Event/evtManager.h" #include "KingSystem/Utils/Byaml/Byaml.h" #include "KingSystem/Utils/Byaml/ByamlArrayIter.h" @@ -144,6 +147,35 @@ bool InfoData::getActorIter(al::ByamlIter* iter, const char* actor, bool x) cons return false; } +bool InfoData::logFailure(const sead::SafeString& actor_name) const { +#ifdef MATCHING_HACK_NX_CLANG + // This is required to prevent LLVM from detecting that 'this' is unused + // and optimizing out the passing of 'this' in callers. + __builtin_assume(mActorsBytes); +#endif + + auto* event = evt::Manager::instance()->getActiveEvent(); + if (event && event->hasFlag(evt::Event::Flag::_80000000000)) + return false; + + if (!ActorCreator::instance()->get5a()) + return false; + + if (ActorDebug::instance() && ActorDebug::instance()->hasFlag(ActorDebug::Flag::_10000000)) + return false; + + if (actor_name.startsWith("MergedGrudge")) + return false; + + if (actor_name.startsWith("Armor_50")) + return false; + + if (actor_name == "Weapon_Sword_DemoCheck") + return false; + + return true; +} + void InfoData::getRecipeInfo(const char* actor, InfoData::RecipeInfo& info) const { al::ByamlIter iter; if (getActorIter(&iter, actor)) { @@ -614,4 +646,84 @@ bool InfoData::hasDropEntry(const char* actor, const char* key) const { return iter.isExistKey(key); } +s32 InfoData::getInstSize(const char* actor) const { + return getInt(actor, "instSize", 0, false); +} + +u32 InfoData::getBugMask(const char* actor) const { + return getInt(actor, "bugMask"); +} + +u32 InfoData::getModelFlags(const char* actor) const { + u32 flags = 0x4000; + if (!actor) + return flags; + + bool is_map_const = false; + + { + const char* profile; + if (getActorProfile(&profile, actor)) { + const sead::SafeString profile_ = profile; + if (profile_ == "MapConstPassive" || profile_ == "MapConstActive") + is_map_const = true; + } + } + + { + al::ByamlIter iter; + if (getActorIter(&iter, actor)) { + if (!hasTag(iter, tags::Tree)) + flags |= 0x1000; + } else { + flags |= 0x1000; + } + } + + s32 type = -1; + { + al::ByamlIter iter; + if (getActorIter(&iter, actor)) { + if (hasTag(iter, tags::Unk_0x4F4E1426)) + type = 0; + else if (hasTag(iter, tags::PasteGrudgeSlime)) + type = 1; + } + } + + if (is_map_const) + flags &= ~0x1000; + + if (type == 0 || (type != 1 && !is_map_const)) + flags |= 0x2000; + + if (is_map_const && type == 1) + flags |= 0x1000; + + return flags; +} + +bool InfoData::getVariationMatAnim(const char* actor, const char** anim, f32* frame) const { + al::ByamlIter iter; + if (!getActorIter(&iter, actor)) + return false; + + *anim = getStringByKey(iter, "variationMatAnim", sead::SafeString::cEmptyString); + *frame = getIntByKey(iter, "variationMatAnimFrame"); + return (*anim)[0] != 0; +} + +bool InfoData::getName(al::ByamlIter* iter, const char** name, s32 idx) const { + if (idx < 0 || idx >= mNumActors) + return false; + + *iter = {mActorsBytes, mActorsBytes + mActorOffsets[idx]}; + al::ByamlHashIter hash_iter{iter->getRootNode()}; + al::ByamlData data; + if (!hash_iter.getDataByKey(&data, mNameIdx)) + return false; + + return iter->tryConvertString(name, &data); +} + } // namespace ksys::act diff --git a/src/KingSystem/ActorSystem/actInfoData.h b/src/KingSystem/ActorSystem/actInfoData.h index a576bc74..1827d0f1 100644 --- a/src/KingSystem/ActorSystem/actInfoData.h +++ b/src/KingSystem/ActorSystem/actInfoData.h @@ -121,6 +121,11 @@ public: f32 getAabbNormHalf(const char* actor) const; bool isHasFar(const char* actor) const; bool hasDropEntry(const char* actor, const char* key) const; + s32 getInstSize(const char* actor) const; + u32 getBugMask(const char* actor) const; + u32 getModelFlags(const char* actor) const; + bool getVariationMatAnim(const char* actor, const char** anim, f32* frame) const; + bool getName(al::ByamlIter* iter, const char** name, s32 idx) const; const char* getString(const char* actor, const char* key, const sead::SafeString& default_, bool x = true) const; diff --git a/src/KingSystem/ActorSystem/actTag.h b/src/KingSystem/ActorSystem/actTag.h index 7581ecaf..db63c04a 100644 --- a/src/KingSystem/ActorSystem/actTag.h +++ b/src/KingSystem/ActorSystem/actTag.h @@ -28,6 +28,7 @@ private: }; #define KSYS_ACT_DEFINE_TAG(NAME) inline constexpr Tag NAME(#NAME) +#define KSYS_ACT_DEFINE_TAG_UNK(HASH) inline constexpr Tag Unk_##HASH(HASH) namespace tags { @@ -396,8 +397,11 @@ KSYS_ACT_DEFINE_TAG(ZukanOther); KSYS_ACT_DEFINE_TAG(ZukanSozai); KSYS_ACT_DEFINE_TAG(ZukanWeapon); +KSYS_ACT_DEFINE_TAG_UNK(0x4F4E1426); + } // namespace tags #undef KSYS_ACT_DEFINE_TAG +#undef KSYS_ACT_DEFINE_TAG_UNK } // namespace ksys::act diff --git a/src/KingSystem/Event/CMakeLists.txt b/src/KingSystem/Event/CMakeLists.txt index 3be2d282..cd1f47d5 100644 --- a/src/KingSystem/Event/CMakeLists.txt +++ b/src/KingSystem/Event/CMakeLists.txt @@ -1,4 +1,6 @@ target_sources(uking PRIVATE + evtEvent.cpp + evtEvent.h evtManager.cpp evtManager.h ) diff --git a/src/KingSystem/Event/evtEvent.cpp b/src/KingSystem/Event/evtEvent.cpp new file mode 100644 index 00000000..9577e6a3 --- /dev/null +++ b/src/KingSystem/Event/evtEvent.cpp @@ -0,0 +1 @@ +#include "KingSystem/Event/evtEvent.h" diff --git a/src/KingSystem/Event/evtEvent.h b/src/KingSystem/Event/evtEvent.h new file mode 100644 index 00000000..ac6a8a94 --- /dev/null +++ b/src/KingSystem/Event/evtEvent.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +namespace ksys::evt { + +// TODO +class Event { +public: + Event(); + virtual ~Event(); + + enum class Flag : u64 { + _80000000000 = 0x80000000000, + }; + + bool hasFlag(Flag flag) const { return mFlags.isOn(flag); } + +private: + u8 TEMP_0[0x338]; + sead::TypedBitFlag mFlags; +}; +// sizeof() = 0x620 + +} // namespace ksys::evt