diff --git a/data/file_list.yml b/data/file_list.yml index 7e7142e3..bedf9459 100644 --- a/data/file_list.yml +++ b/data/file_list.yml @@ -78309,7 +78309,7 @@ MapObj/OceanWaveActor.o: - offset: 0x2d5b24 size: 4 label: _ZN2al13ParameterBase13afterGetParamEv - status: NotDecompiled + status: Matching lazy: true - offset: 0x2d5b28 size: 8 @@ -288010,27 +288010,27 @@ Library/Yaml/ParameterBase.o: - offset: 0xa3321c size: 192 label: _ZN2al13ParameterBaseC2ERKN4sead14SafeStringBaseIcEES5_S5_PNS_12ParameterObjEb - status: NotDecompiled + status: Matching - offset: 0xa332dc size: 428 label: _ZN2al13ParameterBase18initializeListNodeERKN4sead14SafeStringBaseIcEES5_S5_PNS_12ParameterObjEb - status: NotDecompiled + status: Matching - offset: 0xa33488 size: 192 label: _ZN2al13ParameterBaseC2ERKN4sead14SafeStringBaseIcEES5_S5_PNS_13ParameterListEb - status: NotDecompiled + status: Matching - offset: 0xa33548 size: 436 label: _ZN2al13ParameterBase18initializeListNodeERKN4sead14SafeStringBaseIcEES5_S5_PNS_13ParameterListEb - status: NotDecompiled + status: Matching - offset: 0xa336fc size: 388 label: _ZN2al13ParameterBase10initializeERKN4sead14SafeStringBaseIcEES5_S5_b - status: NotDecompiled + status: Matching - offset: 0xa33880 size: 160 label: _ZN2al13ParameterBase8calcHashERKN4sead14SafeStringBaseIcEE - status: NotDecompiled + status: Matching - offset: 0xa33920 size: 28 label: _ZN2al12ParameterObj16pushBackListNodeEPNS_13ParameterBaseE @@ -288042,33 +288042,31 @@ Library/Yaml/ParameterBase.o: - offset: 0xa33960 size: 920 label: _ZN2al13ParameterBase11tryGetParamERKNS_9ByamlIterE - status: NotDecompiled + status: NonMatchingMajor - offset: 0xa33cf8 size: 68 label: _ZNK2al13ParameterBase8isEqual_IPKcEEbRKS0_ - status: NotDecompiled + status: Matching - offset: 0xa33d3c size: 116 label: _ZN2al13ParameterBase9copyLerp_IfEEvRKS0_S3_f - status: NotDecompiled + status: Matching - offset: 0xa33db0 size: 120 label: _ZN2al13ParameterBase9copyLerp_IN4sead4QuatIfEEEEvRKS0_S6_f - status: NotDecompiled + status: Matching - offset: 0xa33e28 size: 964 label: _ZN2al13ParameterBase7isEqualERKS0_ - status: NotDecompiled + status: Matching - offset: 0xa341ec size: 352 label: _ZN2al13ParameterBase4copyERKS0_ - status: NotDecompiled + status: Matching - offset: 0xa3434c size: 936 label: _ZN2al13ParameterBase8copyLerpERKS0_S2_f - status: NotDecompiled -Library/Yaml/ParameterObj.o: - '.text': + status: Matching - offset: 0xa346f4 size: 116 label: diff --git a/lib/al/Library/Light/DirectionParam.cpp b/lib/al/Library/Light/DirectionParam.cpp index 57a4a4e0..41fb7a46 100644 --- a/lib/al/Library/Light/DirectionParam.cpp +++ b/lib/al/Library/Light/DirectionParam.cpp @@ -8,7 +8,6 @@ #include "Library/Math/MathUtil.h" #include "Library/Placement/PlacementFunction.h" #include "Library/Yaml/ParameterBase.h" -#include "Library/Yaml/ParameterObj.h" namespace al { diff --git a/lib/al/Library/LiveActor/ActorResourceFunction.cpp b/lib/al/Library/LiveActor/ActorResourceFunction.cpp index 0532849f..7d7abfc1 100644 --- a/lib/al/Library/LiveActor/ActorResourceFunction.cpp +++ b/lib/al/Library/LiveActor/ActorResourceFunction.cpp @@ -11,7 +11,7 @@ #include "Library/Resource/Resource.h" #include "Library/Resource/ResourceFunction.h" #include "Library/Yaml/ByamlIter.h" -#include "Library/Yaml/ParameterObj.h" +#include "Library/Yaml/ParameterBase.h" namespace al { diff --git a/lib/al/Library/Screen/ScreenPointKeeper.cpp b/lib/al/Library/Screen/ScreenPointKeeper.cpp index 3f474d53..aaa707a4 100644 --- a/lib/al/Library/Screen/ScreenPointKeeper.cpp +++ b/lib/al/Library/Screen/ScreenPointKeeper.cpp @@ -10,7 +10,6 @@ #include "Library/Screen/ScreenPointTarget.h" #include "Library/Yaml/ByamlIter.h" #include "Library/Yaml/ParameterBase.h" -#include "Library/Yaml/ParameterObj.h" namespace al { diff --git a/lib/al/Library/Yaml/ParameterObj.cpp b/lib/al/Library/Yaml/ParameterBase.cpp similarity index 51% rename from lib/al/Library/Yaml/ParameterObj.cpp rename to lib/al/Library/Yaml/ParameterBase.cpp index 7d07b16c..6642b344 100644 --- a/lib/al/Library/Yaml/ParameterObj.cpp +++ b/lib/al/Library/Yaml/ParameterBase.cpp @@ -1,10 +1,343 @@ -#include "Library/Yaml/ParameterObj.h" +#include "Library/Yaml/ParameterBase.h" + +#include +#include #include "Library/Base/StringUtil.h" #include "Library/Yaml/ByamlIter.h" -#include "Library/Yaml/ParameterBase.h" +#include "Library/Yaml/ByamlUtil.h" namespace al { + +ParameterBase::ParameterBase(const sead::SafeString& name, const sead::SafeString& label, + const sead::SafeString& meta, ParameterObj* obj, bool e) { + initializeListNode(name, label, meta, obj, e); +} + +ParameterBase::ParameterBase(const sead::SafeString& name, const sead::SafeString& label, + const sead::SafeString& meta, ParameterList* list, bool e) { + initializeListNode(name, label, meta, list, e); +} + +void ParameterBase::afterGetParam() {} + +template <> +bool ParameterBase::isEqual_(const ParameterBase& parameter) const { + return isEqualString(getValuePtr(), parameter.getValuePtr()); +} + +template +bool ParameterBase::isEqual_(const ParameterBase& parameter) const { + return *getValuePtr() == *parameter.getValuePtr(); +} + +bool ParameterBase::isEqual(const ParameterBase& parameter) { + if ((s32)getParamType() != (s32)parameter.getParamType()) + return false; + + if (mHash != parameter.getHash()) + return false; + + switch (getParamType()) { + case YamlParamType::Bool: + return isEqual_(parameter); + + case YamlParamType::F32: + return isEqual_(parameter); + + case YamlParamType::S32: + return isEqual_(parameter); + + case YamlParamType::U32: + return isEqual_(parameter); + + case YamlParamType::V2f: + return isEqual_(parameter); + + case YamlParamType::V2s32: + return isEqual_(parameter); + + case YamlParamType::V3f: + return isEqual_(parameter); + + case YamlParamType::V4f: + return isEqual_(parameter); + + case YamlParamType::Q4f: + return isEqual_(parameter); + + case YamlParamType::C4f: + return isEqual_(parameter); + + case YamlParamType::StringRef: + return isEqual_(parameter); + + case YamlParamType::String32: + case YamlParamType::String64: + case YamlParamType::String128: + case YamlParamType::String256: + case YamlParamType::String512: + case YamlParamType::String1024: + case YamlParamType::String2048: + case YamlParamType::String4096: + // TODO: Find isEqual_ equivalent + return isEqualString(getValuePtr()->cstr(), + parameter.getValuePtr()->cstr()); + default: + return false; + } +} + +bool ParameterBase::copy(const ParameterBase& parameter) { + if ((s32)getParamType() != (s32)parameter.getParamType()) + return false; + + if (mHash != parameter.getHash()) + return false; + + switch (parameter.getParamType()) { + case YamlParamType::StringRef: + *getMutableValuePtr() = *parameter.getValuePtr(); + return true; + default: { + u8* dest = getMutableValuePtr(); + const u8* source = parameter.getValuePtr(); + s32 n = size(); + for (s32 i = 0; i < n; i++) { + *dest = *source; + dest++; + source++; + } + return true; + } + } +} + +template <> +void ParameterBase::copyLerp_(const ParameterBase& parameterA, const ParameterBase& parameterB, + f32 rate) { + f32 valueA = *parameterA.getValuePtr(); + f32 valueB = *parameterB.getValuePtr(); + setPtrValue(valueA + (valueB - valueA) * rate); +} + +template <> +void ParameterBase::copyLerp_(const ParameterBase& parameterA, + const ParameterBase& parameterB, f32 rate) { + sead::QuatCalcCommon::slerpTo(*(sead::Quatf*)ptr(), *parameterA.getValuePtr(), + *parameterB.getValuePtr(), rate); +} + +// BUG: N's mistake here. This function never returns true +bool ParameterBase::copyLerp(const ParameterBase& parameterA, const ParameterBase& parameterB, + f32 rate) { + if ((s32)getParamType() != (s32)parameterA.getParamType()) + return false; + + if (mHash != parameterA.getHash()) + return false; + + if ((s32)getParamType() != (s32)parameterB.getParamType()) + return false; + + if (mHash != parameterB.getHash()) + return false; + + switch (getParamType()) { + case YamlParamType::Bool: + case YamlParamType::S32: + case YamlParamType::U32: + case YamlParamType::StringRef: + case YamlParamType::String32: + case YamlParamType::String64: + case YamlParamType::String128: + case YamlParamType::String256: + case YamlParamType::String512: + case YamlParamType::String1024: + case YamlParamType::String2048: + case YamlParamType::String4096: + if (rate >= 0.5f && !(rate == 0.5f)) + copy(parameterB); + else + copy(parameterA); + return false; + + case YamlParamType::F32: + copyLerp_(parameterA, parameterB, rate); + return false; + + // BUG: N's mistake here. This is YamlParamType::V2f + case YamlParamType::V3f: { + sead::Vector2f* val = getMutableValuePtr(); + const sead::Vector2f* valueA = parameterA.getValuePtr(); + const sead::Vector2f* valueB = parameterB.getValuePtr(); + val->x = valueA->x + (valueB->x - valueA->x) * rate; + val->y = valueA->y + (valueB->y - valueA->y) * rate; + return false; + } + // BUG: N's mistake here. This is YamlParamType::V3f + case YamlParamType::V2f: { + sead::Vector3f* val = getMutableValuePtr(); + const sead::Vector3f* valueA = parameterA.getValuePtr(); + const sead::Vector3f* valueB = parameterB.getValuePtr(); + val->x = valueA->x + (valueB->x - valueA->x) * rate; + val->y = valueA->y + (valueB->y - valueA->y) * rate; + val->z = valueA->z + (valueB->z - valueA->z) * rate; + return false; + } + case YamlParamType::V4f: { + sead::Vector4f* val = getMutableValuePtr(); + const sead::Vector4f* valueA = parameterA.getValuePtr(); + const sead::Vector4f* valueB = parameterB.getValuePtr(); + val->x = valueA->x + (valueB->x - valueA->x) * rate; + val->y = valueA->y + (valueB->y - valueA->y) * rate; + val->z = valueA->z + (valueB->z - valueA->z) * rate; + val->w = valueA->w + (valueB->w - valueA->w) * rate; + return false; + } + case YamlParamType::Q4f: + copyLerp_(parameterA, parameterB, rate); + return false; + + case YamlParamType::C4f: + getMutableValuePtr()->setLerp(*parameterA.getValuePtr(), + *parameterB.getValuePtr(), + rate); + return false; + default: + return false; + } +} + +void ParameterBase::initializeListNode(const sead::SafeString& name, const sead::SafeString& label, + const sead::SafeString& meta, ParameterObj* obj, bool e) { + initialize(name, label, meta, e); + + if (obj) + obj->pushBackListNode(this); +} + +void ParameterBase::initializeListNode(const sead::SafeString& name, const sead::SafeString& label, + const sead::SafeString& meta, ParameterList* list, bool e) { + initialize(name, label, meta, e); + + if (list) + list->addParam(this); +} + +void ParameterBase::initialize(const sead::SafeString& name, const sead::SafeString& label, + const sead::SafeString& meta, bool e) { + mNext = nullptr; + mName = name; + mHash = calcHash(name); +} + +u32 ParameterBase::calcHash(const sead::SafeString& key) { + return sead::HashCRC32::calcHash(key.cstr(), key.calcLength()); +} + +// NON-MATCHING: https://decomp.me/scratch/yc1tk +void ParameterBase::tryGetParam(const ByamlIter& iter) { + getParamTypeStr(); + switch (getParamType().value()) { + case YamlParamType::Bool: { + bool value; + if (tryGetByamlBool(&value, iter, mName.cstr())) + setPtrValue(value); + afterGetParam(); + return; + } + case YamlParamType::F32: { + f32 value; + if (tryGetByamlF32(&value, iter, mName.cstr())) + setPtrValue(value); + afterGetParam(); + return; + } + case YamlParamType::S32: { + s32 value; + if (tryGetByamlS32(&value, iter, mName.cstr())) + setPtrValue(value); + afterGetParam(); + return; + } + case YamlParamType::U32: { + u32 value; + if (tryGetByamlU32(&value, iter, mName.cstr())) + setPtrValue(value); + afterGetParam(); + return; + } + + case YamlParamType::V2f: { + sead::Vector2f value; + if (tryGetByamlV2f(&value, iter, mName.cstr())) + setPtrValue(value); + afterGetParam(); + return; + } + + case YamlParamType::V2s32: { + sead::Vector2i value; + if (tryGetByamlV2s32(&value, iter, mName.cstr())) + setPtrValue(value); + afterGetParam(); + return; + } + + case YamlParamType::V3f: { + sead::Vector3f value; + if (tryGetByamlV3f(&value, iter, mName.cstr())) + setPtrValue(value); + afterGetParam(); + return; + } + + case YamlParamType::V4f: + case YamlParamType::Q4f: { + sead::Vector4f value; + if (tryGetByamlV4f(&value, iter, mName.cstr())) + setPtrValue(value); + afterGetParam(); + return; + } + + case YamlParamType::C4f: { + sead::Color4f value; + if (tryGetByamlColor(&value, iter, mName.cstr())) + setPtrValue(value); + afterGetParam(); + return; + } + + case YamlParamType::StringRef: { + const char* value = tryGetByamlKeyStringOrNULL(iter, mName.cstr()); + if (value) + setPtrValue(value); + afterGetParam(); + return; + } + + case YamlParamType::String32: + case YamlParamType::String64: + case YamlParamType::String128: + case YamlParamType::String256: + case YamlParamType::String512: + case YamlParamType::String1024: + case YamlParamType::String2048: + case YamlParamType::String4096: { + const char* value = tryGetByamlKeyStringOrNULL(iter, mName.cstr()); + if (value) + getMutableValuePtr()->format("%s", value); + + afterGetParam(); + return; + } + default: + return; + } +} + ParameterObj::ParameterObj() = default; void ParameterObj::pushBackListNode(ParameterBase* param) { diff --git a/lib/al/Library/Yaml/ParameterBase.h b/lib/al/Library/Yaml/ParameterBase.h index be76274e..69f87328 100644 --- a/lib/al/Library/Yaml/ParameterBase.h +++ b/lib/al/Library/Yaml/ParameterBase.h @@ -1,14 +1,16 @@ #pragma once #include +#include #include #include #include namespace al { class ByamlIter; -class ParameterObj; +class ParameterArray; class ParameterList; +class ParameterObj; // Enum formatted for match purposes SEAD_ENUM(YamlParamType, @@ -106,10 +108,27 @@ public: u32 getHash() const { return mHash; } template - T* getValuePtr() { - return (T*)ptr(); + T* getMutableValuePtr() { + return reinterpret_cast(ptr()); } + template + const T* getValuePtr() const { + return reinterpret_cast(ptr()); + } + + template + void setPtrValue(T value) { + *getMutableValuePtr() = value; + } + +protected: + template + bool isEqual_(const ParameterBase& parameter) const; + + template + void copyLerp_(const ParameterBase& parameterA, const ParameterBase& parameterB, f32 rate); + private: ParameterBase* mNext; sead::FixedSafeString<0x40> mName; @@ -179,6 +198,7 @@ PARAM_TYPE_DEF(U32, u32) PARAM_TYPE_DEF(V2f, sead::Vector2f) PARAM_TYPE_DEF(V3f, sead::Vector3f) PARAM_TYPE_DEF(V4f, sead::Vector4f) +PARAM_TYPE_DEF(Q4f, sead::Quatf) PARAM_TYPE_DEF(C4f, sead::Color4f) PARAM_TYPE_DEF(StringRef, const char*) PARAM_TYPE_DEF(String32, sead::FixedSafeString<32>) @@ -190,4 +210,98 @@ PARAM_TYPE_DEF(String1024, sead::FixedSafeString<1024>) PARAM_TYPE_DEF(String2048, sead::FixedSafeString<2048>) PARAM_TYPE_DEF(String4096, sead::FixedSafeString<4096>) +class ParameterObj { +public: + ParameterObj(); + + void pushBackListNode(ParameterBase* param); + void tryGetParam(const ByamlIter& iter); + void addArray(ParameterArray* array, const sead::SafeString& key); + bool isEqual(const ParameterObj& obj) const; + void copy(const ParameterObj& obj); + void copyLerp(const ParameterObj& objA, const ParameterObj& objB, f32 rate); + ParameterBase* findParameter(const char* name) const; + + ParameterBase* getRootParam() const { return mRootParam; } + + ParameterObj* getNext() const { return mNext; } + + ParameterArray* getParamArray() const { return mParamArray; } + + void setNext(ParameterObj* obj) { mNext = obj; } + + void setKey(const sead::SafeString& key) { mKey = key; } + +private: + ParameterBase* mRootParam = nullptr; + ParameterBase* mTailParam = nullptr; + ParameterObj* mNext = nullptr; + ParameterArray* mParamArray = nullptr; + sead::FixedSafeString<0x40> mKey; +}; + +class ParameterArray { +public: + ParameterArray(); + void tryGetParam(const ByamlIter& iter); + bool isEqual(const ParameterArray& array) const; + void copy(const ParameterArray& array); + void copyLerp(const ParameterArray& arrayA, const ParameterArray& arrayB, f32 rate); + void addObj(ParameterObj* obj); + void clearObj(); + void removeObj(ParameterObj* obj); + bool isExistObj(ParameterObj* obj); + + ParameterObj* getRootObjNode() const { return mRootObjNode; } + + ParameterArray* getNext() const { return mNext; } + + void setNext(ParameterArray* array) { mNext = array; } + + void setKey(const sead::SafeString& key) { mKey = key; } + + s32 getSize() const { return mSize; } + +private: + ParameterObj* mRootObjNode = nullptr; + ParameterArray* mNext = nullptr; + sead::FixedSafeString<0x40> mKey; + s32 mSize = 0; +}; + +class ParameterList { +public: + ParameterList(); + + void addParam(ParameterBase* param); + void addList(ParameterList* list, const sead::SafeString& key); + void addObj(ParameterObj* obj, const sead::SafeString& key); + void addArray(ParameterArray* array, const sead::SafeString& key); + void clearList(); + void clearObj(); + void removeList(ParameterList* list); + void removeObj(ParameterObj* obj); + bool isExistObj(ParameterObj* obj); + void tryGetParam(const ByamlIter& iter); + + ParameterList* getNext() const { return mNext; } + + void setNext(ParameterList* list) { mNext = list; } + + void setKey(const sead::SafeString& key) { mKey = key; } + +private: + ParameterBase* mRootParamNode = nullptr; + ParameterObj* mRootObjNode = nullptr; + ParameterList* mRootListNode = nullptr; + ParameterArray* mRootArrayNode = nullptr; + ParameterList* mNext = nullptr; + sead::FixedSafeString<0x40> mKey; +}; + +class ParameterIo : public ParameterList { +public: + ParameterIo(); +}; + } // namespace al diff --git a/lib/al/Library/Yaml/ParameterObj.h b/lib/al/Library/Yaml/ParameterObj.h deleted file mode 100644 index 4e507183..00000000 --- a/lib/al/Library/Yaml/ParameterObj.h +++ /dev/null @@ -1,105 +0,0 @@ -#pragma once - -#include -#include - -namespace al { -class ParameterBase; -class ByamlIter; -class ParameterArray; - -class ParameterObj { -public: - ParameterObj(); - - void pushBackListNode(ParameterBase* param); - void tryGetParam(const ByamlIter& iter); - void addArray(ParameterArray* array, const sead::SafeString& key); - bool isEqual(const ParameterObj& obj) const; - void copy(const ParameterObj& obj); - void copyLerp(const ParameterObj& objA, const ParameterObj& objB, f32 rate); - ParameterBase* findParameter(const char* name) const; - - ParameterBase* getRootParam() const { return mRootParam; } - - ParameterObj* getNext() const { return mNext; } - - ParameterArray* getParamArray() const { return mParamArray; } - - void setNext(ParameterObj* obj) { mNext = obj; } - - void setKey(const sead::SafeString& key) { mKey = key; } - -private: - ParameterBase* mRootParam = nullptr; - ParameterBase* mTailParam = nullptr; - ParameterObj* mNext = nullptr; - ParameterArray* mParamArray = nullptr; - sead::FixedSafeString<0x40> mKey; -}; - -class ParameterArray { -public: - ParameterArray(); - void tryGetParam(const ByamlIter& iter); - bool isEqual(const ParameterArray& array) const; - void copy(const ParameterArray& array); - void copyLerp(const ParameterArray& arrayA, const ParameterArray& arrayB, f32 rate); - void addObj(ParameterObj* obj); - void clearObj(); - void removeObj(ParameterObj* obj); - bool isExistObj(ParameterObj* obj); - - ParameterObj* getRootObjNode() const { return mRootObjNode; } - - ParameterArray* getNext() const { return mNext; } - - void setNext(ParameterArray* array) { mNext = array; } - - void setKey(const sead::SafeString& key) { mKey = key; } - - s32 getSize() const { return mSize; } - -private: - ParameterObj* mRootObjNode = nullptr; - ParameterArray* mNext = nullptr; - sead::FixedSafeString<0x40> mKey; - s32 mSize = 0; -}; - -class ParameterList { -public: - ParameterList(); - - void addParam(ParameterBase* param); - void addList(ParameterList* list, const sead::SafeString& key); - void addObj(ParameterObj* obj, const sead::SafeString& key); - void addArray(ParameterArray* array, const sead::SafeString& key); - void clearList(); - void clearObj(); - void removeList(ParameterList* list); - void removeObj(ParameterObj* obj); - bool isExistObj(ParameterObj* obj); - void tryGetParam(const ByamlIter& iter); - - ParameterList* getNext() const { return mNext; } - - void setNext(ParameterList* list) { mNext = list; } - - void setKey(const sead::SafeString& key) { mKey = key; } - -private: - ParameterBase* mRootParamNode = nullptr; - ParameterObj* mRootObjNode = nullptr; - ParameterList* mRootListNode = nullptr; - ParameterArray* mRootArrayNode = nullptr; - ParameterList* mNext = nullptr; - sead::FixedSafeString<0x40> mKey; -}; - -class ParameterIo : public ParameterList { -public: - ParameterIo(); -}; - -} // namespace al