diff --git a/CMakeLists.txt b/CMakeLists.txt index be1a5fec..8c065a71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ add_executable(uking src/KingSystem/Utils/Byaml.h src/KingSystem/Utils/ByamlLocal.cpp src/KingSystem/Utils/ByamlLocal.h + src/KingSystem/Utils/ByamlUtil.cpp src/KingSystem/Utils/Debug.h src/KingSystem/Utils/StrTreeMap.h src/KingSystem/Utils/Types.h diff --git a/data/uking_functions.csv b/data/uking_functions.csv index ead6baef..c80a95ed 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -60421,10 +60421,10 @@ 0x0000007100aacbbc,_ZNK2al13ByamlHashIter12getDataByKeyEPNS_9ByamlDataEi,168, 0x0000007100aacc64,_ZNK2al13ByamlHashIter8findPairEi,92, 0x0000007100aaccc0,_ZNK2al13ByamlHashIter14getPairByIndexEi,80, -0x0000007100aacd10,_ZN2al14tryGetByamlS32EPiRKNS_9ByamlIterEPKc,16, -0x0000007100aacd20,_ZN2al14tryGetByamlU32EPjRKNS_9ByamlIterEPKc,64, -0x0000007100aacd60,_ZN2al14tryGetByamlF32EPfRKNS_9ByamlIterEPKc,72, -0x0000007100aacda8,_ZN2al14tryGetByamlV3fEPN4sead7Vector3IfEERKNS_9ByamlIterEPKc,192, +0x0000007100aacd10,_ZN2al14tryGetByamlS32EPiRKNS_9ByamlIterEPKc,16,_ZN2al14tryGetByamlS32EPiRKNS_9ByamlIterEPKc +0x0000007100aacd20,_ZN2al14tryGetByamlU32EPjRKNS_9ByamlIterEPKc,64,_ZN2al14tryGetByamlU32EPjRKNS_9ByamlIterEPKc +0x0000007100aacd60,_ZN2al14tryGetByamlF32EPfRKNS_9ByamlIterEPKc,72,_ZN2al14tryGetByamlF32EPfRKNS_9ByamlIterEPKc +0x0000007100aacda8,_ZN2al14tryGetByamlV3fEPN4sead7Vector3IfEERKNS_9ByamlIterEPKc,192,_ZN2al14tryGetByamlV3fEPN4sead7Vector3IfEERKNS_9ByamlIterEPKc 0x0000007100aace68,_ZN2nn4init19InitializeAllocatorEPvm,84, 0x0000007100aacebc,malloc,88, 0x0000007100aacf14,free,28, diff --git a/src/KingSystem/Utils/Byaml.h b/src/KingSystem/Utils/Byaml.h index f7fe3d01..c15f0802 100644 --- a/src/KingSystem/Utils/Byaml.h +++ b/src/KingSystem/Utils/Byaml.h @@ -33,7 +33,7 @@ enum class ByamlType { class ByamlIter { public: - ByamlIter() = default; + ByamlIter(); explicit ByamlIter(const u8* data); ByamlIter(const u8* data, const u8* root_node); ByamlIter(const ByamlIter& other); diff --git a/src/KingSystem/Utils/ByamlUtil.cpp b/src/KingSystem/Utils/ByamlUtil.cpp new file mode 100644 index 00000000..6c46fff5 --- /dev/null +++ b/src/KingSystem/Utils/ByamlUtil.cpp @@ -0,0 +1,43 @@ +#include "KingSystem/Utils/Byaml.h" + +namespace al { + +bool tryGetByamlS32(s32* value, const ByamlIter& iter, const char* key) { + return iter.tryGetIntByKey(value, key); +} + +bool tryGetByamlU32(u32* value, const ByamlIter& iter, const char* key) { + s32 v{}; + bool ret = iter.tryGetIntByKey(&v, key); + if (ret) + *value = v; + return ret; +} + +bool tryGetByamlF32(f32* value, const ByamlIter& iter, const char* key) { + f32 v{}; + bool ret = iter.tryGetFloatByKey(&v, key); + if (!ret) + return false; + *value = v; + return true; +} + +bool tryGetByamlV3f(sead::Vector3f* value, const ByamlIter& iter, const char* key) { + f32 x, y, z; + ByamlIter vec_iter; + if (!iter.tryGetIterByKey(&vec_iter, key)) + return false; + + x = 0; + bool ok = vec_iter.tryGetFloatByKey(&x, "X"); + y = 0; + ok |= vec_iter.tryGetFloatByKey(&y, "Y"); + z = 0; + ok |= vec_iter.tryGetFloatByKey(&z, "Z"); + + *value = {x, y, z}; + return ok; +} + +} // namespace al