summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2020-08-21 22:21:26 +0200
committerLéo Lam <leo@leolam.fr>2020-08-21 22:21:26 +0200
commitfc306aa5f06ef1d28f6d178dff28d39b9056199a (patch)
tree31190360067a1614ec13af4a89c505e5800f7dc2 /src
parentbad90bc5d87e3729620dd883c039641af83251a8 (diff)
ksys: Decompile ByamlUtil
And fix some declarations in Byaml.h
Diffstat (limited to 'src')
-rw-r--r--src/KingSystem/Utils/Byaml.h2
-rw-r--r--src/KingSystem/Utils/ByamlUtil.cpp43
2 files changed, 44 insertions, 1 deletions
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