Library/Yaml: Remove magic numbers (Part 1) (#830)

This commit is contained in:
Narr the Reg 2026-01-14 07:49:23 -06:00 committed by GitHub
parent f996f22802
commit d1b7018193
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 167 additions and 161 deletions

View file

@ -2,12 +2,16 @@
#include <basis/seadTypes.h>
#include "Library/Yaml/ByamlData.h"
namespace al {
class ByamlContainerHeader {
public:
s32 getType() const;
s32 getCount(bool isRev) const;
ByamlDataType getTypeCode() const { return (ByamlDataType)mType; }
private:
u32 mType;
};

View file

@ -5,21 +5,21 @@
namespace al {
class ByamlHashPair;
enum ByamlDataType : const u8 {
TYPE_INVALID = 0,
TYPE_STRING = 0xA0,
TYPE_BINARY = 0xA1,
TYPE_ARRAY = 0xC0,
TYPE_HASH = 0xC1,
TYPE_STRING_TABLE = 0xC2,
TYPE_BOOL = 0xD0,
TYPE_INT = 0xD1,
TYPE_FLOAT = 0xD2,
TYPE_UINT = 0xD3,
TYPE_LONG = 0xD4,
TYPE_ULONG = 0xD5,
TYPE_DOUBLE = 0xD6,
TYPE_NULL = 0xFF
enum class ByamlDataType : const u8 {
None = 0,
String = 0xa0,
Binary = 0xa1,
Array = 0xc0,
Hash = 0xc1,
StringTable = 0xc2,
Bool = 0xd0,
Int = 0xd1,
Float = 0xd2,
UInt = 0xd3,
Int64 = 0xd4,
UInt64 = 0xd5,
Double = 0xd6,
Null = 0xff,
};
class ByamlData {
@ -39,7 +39,7 @@ public:
private:
u32 mValue = 0;
ByamlDataType mType = ByamlDataType::TYPE_INVALID;
ByamlDataType mType = ByamlDataType::None;
};
class ByamlHashPair {

View file

@ -100,33 +100,33 @@ namespace alByamlLocalUtil {
const char* getDataTypeString(s32 type) {
switch (type) {
case al::ByamlDataType::TYPE_INVALID:
case (u8)al::ByamlDataType::None:
return "None";
case al::ByamlDataType::TYPE_STRING:
case (u8)al::ByamlDataType::String:
return "String";
case al::ByamlDataType::TYPE_ARRAY:
case (u8)al::ByamlDataType::Array:
return "Array";
case al::ByamlDataType::TYPE_HASH:
case (u8)al::ByamlDataType::Hash:
return "Hash";
case al::ByamlDataType::TYPE_STRING_TABLE:
case (u8)al::ByamlDataType::StringTable:
return "StringTable";
case al::ByamlDataType::TYPE_BOOL:
case (u8)al::ByamlDataType::Bool:
return "Bool";
case al::ByamlDataType::TYPE_INT:
case (u8)al::ByamlDataType::Int:
return "Int";
case al::ByamlDataType::TYPE_FLOAT:
case (u8)al::ByamlDataType::Float:
return "Float";
case al::ByamlDataType::TYPE_UINT:
case (u8)al::ByamlDataType::UInt:
return "UInt";
case al::ByamlDataType::TYPE_LONG:
case (u8)al::ByamlDataType::Int64:
return "Int64";
case al::ByamlDataType::TYPE_ULONG:
case (u8)al::ByamlDataType::UInt64:
return "UInt64";
case al::ByamlDataType::TYPE_DOUBLE:
case (u8)al::ByamlDataType::Double:
return "Double";
case al::ByamlDataType::TYPE_NULL:
case (u8)al::ByamlDataType::Null:
return "NULL";
case al::ByamlDataType::TYPE_BINARY:
case (u8)al::ByamlDataType::Binary:
default:
return "Unknown";
};
@ -218,7 +218,7 @@ bool verifiByamlStringTable(const u8* data, bool isRev) {
const s32* address_table = reinterpret_cast<const s32*>(data + 4);
u32 type_and_size = *reinterpret_cast<const u32*>(data);
if ((type_and_size & 0xff) != al::ByamlDataType::TYPE_STRING_TABLE)
if ((al::ByamlDataType)type_and_size != al::ByamlDataType::StringTable)
return false;
s32 size = isRev ? bswap_24(type_and_size >> 8) : type_and_size >> 8;
if (size < 1)

View file

@ -5,9 +5,9 @@
#include "Library/Yaml/ByamlHeader.h"
namespace al {
ByamlIter::ByamlIter() : mData(nullptr), mRootNode(nullptr) {}
ByamlIter::ByamlIter() = default;
ByamlIter::ByamlIter(const u8* data) : mData(data), mRootNode(nullptr) {
ByamlIter::ByamlIter(const u8* data) : mData(data) {
if (!data)
return;
if (!alByamlLocalUtil::verifiByaml(data)) {
@ -16,7 +16,7 @@ ByamlIter::ByamlIter(const u8* data) : mData(data), mRootNode(nullptr) {
return;
}
const ByamlHeader* header = mHeader;
const ByamlHeader* header = getHeader();
if (!header->getDataOffset())
return;
@ -30,11 +30,11 @@ bool ByamlIter::isValid() const {
}
bool ByamlIter::isTypeHash() const {
return mRootNode ? mRootNode[0] == ByamlDataType::TYPE_HASH : false;
return mRootNode ? getContainerHeader()->getTypeCode() == ByamlDataType::Hash : false;
}
bool ByamlIter::isTypeArray() const {
return mRootNode ? mRootNode[0] == ByamlDataType::TYPE_ARRAY : false;
return mRootNode ? getContainerHeader()->getTypeCode() == ByamlDataType::Array : false;
}
bool ByamlIter::isTypeContainer() const {
@ -42,7 +42,7 @@ bool ByamlIter::isTypeContainer() const {
}
bool ByamlIter::isExistKey(const char* key) const {
if (!mRootNode || *mRootNode != ByamlDataType::TYPE_HASH)
if (!mRootNode || getContainerHeader()->getTypeCode() != ByamlDataType::Hash)
return false;
s32 index = getKeyIndex(key);
@ -62,16 +62,16 @@ s32 ByamlIter::getKeyIndex(const char* key) const {
}
bool ByamlIter::isInvertOrder() const {
return mHeader->isInvertOrder();
return getHeader()->isInvertOrder();
}
s32 ByamlIter::getSize() const {
if (!mRootNode)
return false;
ByamlContainerHeader* header = (ByamlContainerHeader*)mRootNode;
u32 type = *mRootNode;
if (type == ByamlDataType::TYPE_ARRAY || type == ByamlDataType::TYPE_HASH)
return header->getCount(isInvertOrder());
ByamlDataType type = getContainerHeader()->getTypeCode();
if (type == ByamlDataType::Array || type == ByamlDataType::Hash)
return getContainerHeader()->getCount(isInvertOrder());
return 0;
}
@ -79,8 +79,8 @@ ByamlIter ByamlIter::getIterByIndex(s32 index) const {
ByamlData data;
if (!getByamlDataByIndex(&data, index))
return nullptr;
if (data.getType() != ByamlDataType::TYPE_ARRAY && data.getType() != ByamlDataType::TYPE_HASH) {
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() != ByamlDataType::Array && data.getType() != ByamlDataType::Hash) {
if (data.getType() == ByamlDataType::Null)
return {mData, nullptr};
return {};
}
@ -90,11 +90,11 @@ ByamlIter ByamlIter::getIterByIndex(s32 index) const {
bool ByamlIter::getByamlDataByIndex(ByamlData* data, s32 index) const {
if (!mRootNode)
return false;
if (*mRootNode == ByamlDataType::TYPE_ARRAY) {
if (getContainerHeader()->getTypeCode() == ByamlDataType::Array) {
ByamlArrayIter iter = {mRootNode, isInvertOrder()};
return iter.getDataByIndex(data, index);
}
if (*mRootNode == ByamlDataType::TYPE_HASH) {
if (getContainerHeader()->getTypeCode() == ByamlDataType::Hash) {
ByamlHashIter iter = {mRootNode, isInvertOrder()};
return iter.getDataByIndex(data, index);
}
@ -105,8 +105,8 @@ ByamlIter ByamlIter::getIterByKey(const char* key) const {
ByamlData data;
if (!getByamlDataByKey(&data, key))
return nullptr;
if (data.getType() != ByamlDataType::TYPE_ARRAY && data.getType() != ByamlDataType::TYPE_HASH) {
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() != ByamlDataType::Array && data.getType() != ByamlDataType::Hash) {
if (data.getType() == ByamlDataType::Null)
return {mData, nullptr};
return {};
}
@ -114,7 +114,7 @@ ByamlIter ByamlIter::getIterByKey(const char* key) const {
}
bool ByamlIter::getByamlDataByKey(ByamlData* data, const char* key) const {
if (!mRootNode || *mRootNode != ByamlDataType::TYPE_HASH)
if (!mRootNode || getContainerHeader()->getTypeCode() != ByamlDataType::Hash)
return false;
ByamlStringTableIter hash_table = alByamlLocalUtil::getHashKeyTable(mData);
if (!hash_table.isValidate())
@ -142,7 +142,7 @@ bool ByamlIter::getByamlDataByKey(ByamlData* data, const char* key) const {
}
bool ByamlIter::getByamlDataByKeyIndex(ByamlData* data, s32 index) const {
if (!mRootNode || *mRootNode != ByamlDataType::TYPE_HASH)
if (!mRootNode || getContainerHeader()->getTypeCode() != ByamlDataType::Hash)
return false;
ByamlHashIter iter = {mRootNode, isInvertOrder()};
@ -150,7 +150,7 @@ bool ByamlIter::getByamlDataByKeyIndex(ByamlData* data, s32 index) const {
}
bool ByamlIter::getByamlDataAndKeyName(ByamlData* data, const char** key, s32 index) const {
if (!mRootNode || *mRootNode != ByamlDataType::TYPE_HASH)
if (!mRootNode || getContainerHeader()->getTypeCode() != ByamlDataType::Hash)
return false;
ByamlHashIter iter = {mRootNode, isInvertOrder()};
@ -185,9 +185,9 @@ bool ByamlIter::tryGetIterAndKeyNameByIndex(ByamlIter* iter, const char** key, s
return iter->isValid();
}
if (data.getType() == ByamlDataType::TYPE_ARRAY || data.getType() == ByamlDataType::TYPE_HASH)
if (data.getType() == ByamlDataType::Array || data.getType() == ByamlDataType::Hash)
*iter = {mData, &mData[data.getValue()]};
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
*iter = {mData, nullptr};
return true;
}
@ -198,12 +198,11 @@ bool ByamlIter::tryGetIterByKey(ByamlIter* iter, const char* key) const {
}
bool ByamlIter::tryConvertIter(ByamlIter* iter, const ByamlData* data) const {
if (data->getType() == ByamlDataType::TYPE_ARRAY ||
data->getType() == ByamlDataType::TYPE_HASH) {
if (data->getType() == ByamlDataType::Array || data->getType() == ByamlDataType::Hash) {
*iter = {mData, &mData[data->getValue()]};
return true;
}
if (data->getType() == ByamlDataType::TYPE_NULL) {
if (data->getType() == ByamlDataType::Null) {
*iter = {mData, nullptr};
return true;
}
@ -223,13 +222,13 @@ bool ByamlIter::tryGetStringByKey(const char** value, const char* key) const {
if (!getByamlDataByKey(&data, key))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertString(value, &data);
}
bool ByamlIter::tryConvertString(const char** value, const ByamlData* data) const {
if (data->getType() != ByamlDataType::TYPE_STRING)
if (data->getType() != ByamlDataType::String)
return false;
ByamlStringTableIter string_table = alByamlLocalUtil::getStringTable(mData);
@ -257,7 +256,7 @@ bool ByamlIter::tryGetBinaryByKey(const u8** value, s32* size, const char* key)
}
bool ByamlIter::tryConvertBinary(const u8** value, s32* size, const ByamlData* data) const {
if (data->getType() != ByamlDataType::TYPE_STRING)
if (data->getType() != ByamlDataType::String)
return false;
ByamlStringTableIter string_table = alByamlLocalUtil::getStringTable(mData);
@ -282,13 +281,13 @@ bool ByamlIter::tryGetIntByKey(s32* value, const char* key) const {
if (!getByamlDataByKey(&data, key))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertInt(value, &data);
}
bool ByamlIter::tryConvertInt(s32* value, const ByamlData* data) const {
if (data->getType() != ByamlDataType::TYPE_INT)
if (data->getType() != ByamlDataType::Int)
return false;
*value = data->getValue();
@ -310,19 +309,19 @@ bool ByamlIter::tryGetUIntByKey(u32* value, const char* key) const {
if (!getByamlDataByKey(&data, key))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertUInt(value, &data);
}
bool ByamlIter::tryConvertUInt(u32* value, const ByamlData* data) const {
s32 val = data->getValue<s32>();
if (data->getType() == ByamlDataType::TYPE_INT) {
if (data->getType() == ByamlDataType::Int) {
bool result = val >= 0;
*value = val < 0 ? 0 : val;
return result;
}
if (data->getType() == ByamlDataType::TYPE_UINT) {
if (data->getType() == ByamlDataType::UInt) {
*value = val;
return true;
}
@ -343,13 +342,13 @@ bool ByamlIter::tryGetFloatByKey(f32* value, const char* key) const {
if (!getByamlDataByKey(&data, key))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertFloat(value, &data);
}
bool ByamlIter::tryConvertFloat(f32* value, const ByamlData* data) const {
if (data->getType() != ByamlDataType::TYPE_FLOAT)
if (data->getType() != ByamlDataType::Float)
return false;
*value = data->getValue<f32>();
@ -369,13 +368,13 @@ bool ByamlIter::tryGetBoolByKey(bool* value, const char* key) const {
if (!getByamlDataByKey(&data, key))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertBool(value, &data);
}
bool ByamlIter::tryConvertBool(bool* value, const ByamlData* data) const {
if (data->getType() != ByamlDataType::TYPE_BOOL)
if (data->getType() != ByamlDataType::Bool)
return false;
*value = data->getValue() != 0;
@ -387,7 +386,7 @@ bool ByamlIter::tryGetInt64ByIndex(s64* value, s32 index) const {
if (!getByamlDataByIndex(&data, index))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertInt64(value, &data);
}
@ -397,23 +396,23 @@ bool ByamlIter::tryGetInt64ByKey(s64* value, const char* key) const {
if (!getByamlDataByKey(&data, key))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertInt64(value, &data);
}
bool ByamlIter::tryConvertInt64(s64* value, const ByamlData* data) const {
u32 val = data->getValue();
if (data->getType() == ByamlDataType::TYPE_INT) {
if (data->getType() == ByamlDataType::Int) {
*value = *reinterpret_cast<s32*>(&val);
return true;
}
if (data->getType() == ByamlDataType::TYPE_UINT) {
if (data->getType() == ByamlDataType::UInt) {
*value = val;
return true;
}
if (data->getType() == ByamlDataType::TYPE_LONG) {
*value = alByamlLocalUtil::getData64Bit(mData, val, mHeader->isInvertOrder());
if (data->getType() == ByamlDataType::Int64) {
*value = alByamlLocalUtil::getData64Bit(mData, val, getHeader()->isInvertOrder());
return true;
}
@ -425,7 +424,7 @@ bool ByamlIter::tryGetUInt64ByIndex(u64* value, s32 index) const {
if (!getByamlDataByIndex(&data, index))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertUInt64(value, &data);
}
@ -435,30 +434,30 @@ bool ByamlIter::tryGetUInt64ByKey(u64* value, const char* key) const {
if (!getByamlDataByKey(&data, key))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertUInt64(value, &data);
}
bool ByamlIter::tryConvertUInt64(u64* value, const ByamlData* data) const {
s32 val = data->getValue<s32>();
if (data->getType() == ByamlDataType::TYPE_INT) {
if (data->getType() == ByamlDataType::Int) {
bool result = val >= 0;
*value = val > 0 ? val : 0;
return result;
}
if (data->getType() == ByamlDataType::TYPE_UINT) {
if (data->getType() == ByamlDataType::UInt) {
*value = *reinterpret_cast<u32*>(&val);
return true;
}
s64 realVal = alByamlLocalUtil::getData64Bit(mData, val, mHeader->isInvertOrder());
if (data->getType() == ByamlDataType::TYPE_LONG) {
s64 realVal = alByamlLocalUtil::getData64Bit(mData, val, getHeader()->isInvertOrder());
if (data->getType() == ByamlDataType::Int64) {
bool result = realVal >= 0;
*value = realVal < 0 ? 0 : realVal;
return result;
}
if (data->getType() == ByamlDataType::TYPE_ULONG) {
if (data->getType() == ByamlDataType::UInt64) {
*value = realVal;
return true;
}
@ -471,7 +470,7 @@ bool ByamlIter::tryGetDoubleByIndex(f64* value, s32 index) const {
if (!getByamlDataByIndex(&data, index))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertDouble(value, &data);
}
@ -481,19 +480,19 @@ bool ByamlIter::tryGetDoubleByKey(f64* value, const char* key) const {
if (!getByamlDataByKey(&data, key))
return false;
if (data.getType() == ByamlDataType::TYPE_NULL)
if (data.getType() == ByamlDataType::Null)
return false;
return tryConvertDouble(value, &data);
}
bool ByamlIter::tryConvertDouble(f64* value, const ByamlData* data) const {
u32 val = data->getValue();
if (data->getType() == ByamlDataType::TYPE_FLOAT) {
if (data->getType() == ByamlDataType::Float) {
*value = *reinterpret_cast<f32*>(&val);
return true;
}
if (data->getType() == ByamlDataType::TYPE_DOUBLE) {
u64 bigVal = alByamlLocalUtil::getData64Bit(mData, val, mHeader->isInvertOrder());
if (data->getType() == ByamlDataType::Double) {
u64 bigVal = alByamlLocalUtil::getData64Bit(mData, val, getHeader()->isInvertOrder());
*value = *reinterpret_cast<f64*>(&bigVal);
return true;
}

View file

@ -4,6 +4,8 @@
#include "Library/Yaml/ByamlHeader.h"
namespace al {
class ByamlContainerHeader;
class ByamlIter {
public:
ByamlIter();
@ -58,14 +60,14 @@ public:
bool tryConvertIter(ByamlIter* iter, const ByamlData* data) const;
bool isEqualData(const ByamlIter& other) const;
const ByamlHeader* getHeader() const { return mHeader; }
const ByamlHeader* getHeader() const { return reinterpret_cast<const ByamlHeader*>(mData); }
const ByamlContainerHeader* getContainerHeader() const {
return reinterpret_cast<const ByamlContainerHeader*>(mRootNode);
}
private:
union {
const u8* mData;
const ByamlHeader* mHeader;
};
const u8* mRootNode;
const u8* mData = nullptr;
const u8* mRootNode = nullptr;
};
} // namespace al

View file

@ -308,51 +308,51 @@ void getByamlIterByIndex(ByamlIter* out, const ByamlIter& iter, s32 index) {
}
bool isTypeBoolByIndex(const ByamlIter& iter, s32 index) {
return isTypeByIndex<ByamlDataType::TYPE_BOOL>(iter, index);
return isTypeByIndex<ByamlDataType::Bool>(iter, index);
}
bool isTypeBoolByKey(const ByamlIter& iter, const char* key) {
return isTypeByKey<ByamlDataType::TYPE_BOOL>(iter, key);
return isTypeByKey<ByamlDataType::Bool>(iter, key);
}
bool isTypeIntByIndex(const ByamlIter& iter, s32 index) {
return isTypeByIndex<ByamlDataType::TYPE_INT>(iter, index);
return isTypeByIndex<ByamlDataType::Int>(iter, index);
}
bool isTypeIntByKey(const ByamlIter& iter, const char* key) {
return isTypeByKey<ByamlDataType::TYPE_INT>(iter, key);
return isTypeByKey<ByamlDataType::Int>(iter, key);
}
bool isTypeFloatByIndex(const ByamlIter& iter, s32 index) {
return isTypeByIndex<ByamlDataType::TYPE_FLOAT>(iter, index);
return isTypeByIndex<ByamlDataType::Float>(iter, index);
}
bool isTypeFloatByKey(const ByamlIter& iter, const char* key) {
return isTypeByKey<ByamlDataType::TYPE_FLOAT>(iter, key);
return isTypeByKey<ByamlDataType::Float>(iter, key);
}
bool isTypeStringByIndex(const ByamlIter& iter, s32 index) {
return isTypeByIndex<ByamlDataType::TYPE_STRING>(iter, index);
return isTypeByIndex<ByamlDataType::String>(iter, index);
}
bool isTypeStringByKey(const ByamlIter& iter, const char* key) {
return isTypeByKey<ByamlDataType::TYPE_STRING>(iter, key);
return isTypeByKey<ByamlDataType::String>(iter, key);
}
bool isTypeArrayByIndex(const ByamlIter& iter, s32 index) {
return isTypeByIndex<ByamlDataType::TYPE_ARRAY>(iter, index);
return isTypeByIndex<ByamlDataType::Array>(iter, index);
}
bool isTypeArrayByKey(const ByamlIter& iter, const char* key) {
return isTypeByKey<ByamlDataType::TYPE_ARRAY>(iter, key);
return isTypeByKey<ByamlDataType::Array>(iter, key);
}
bool isTypeHashByIndex(const ByamlIter& iter, s32 index) {
return isTypeByIndex<ByamlDataType::TYPE_HASH>(iter, index);
return isTypeByIndex<ByamlDataType::Hash>(iter, index);
}
bool isTypeHashByKey(const ByamlIter& iter, const char* key) {
return isTypeByKey<ByamlDataType::TYPE_HASH>(iter, key);
return isTypeByKey<ByamlDataType::Hash>(iter, key);
}
s32 getByamlIterDataNum(const ByamlIter& iter) {
@ -380,8 +380,7 @@ void printByamlIter_(const ByamlIter& iter, PrintParams* param) {
const char* data = nullptr;
iter.getByamlDataAndKeyName(&entry, &data, i);
}
if (entry.getType() == ByamlDataType::TYPE_HASH ||
entry.getType() == ByamlDataType::TYPE_ARRAY) {
if (entry.getType() == ByamlDataType::Hash || entry.getType() == ByamlDataType::Array) {
u32 v6 = entry.getValue();
if (param) {
PrintParams* sub_param = param;
@ -399,17 +398,17 @@ void printByamlIter_(const ByamlIter& iter, PrintParams* param) {
printByamlIter_(a1, &new_param);
}
} else {
u8 type = entry.getType();
if (type == ByamlDataType::TYPE_FLOAT) {
ByamlDataType type = entry.getType();
if (type == ByamlDataType::Float) {
f32 data;
iter.tryConvertFloat(&data, &entry);
} else if (type == ByamlDataType::TYPE_INT) {
} else if (type == ByamlDataType::Int) {
s32 data;
iter.tryConvertInt(&data, &entry);
} else if (type == ByamlDataType::TYPE_STRING) {
} else if (type == ByamlDataType::String) {
const char* data;
iter.tryConvertString(&data, &entry);
} else if (type == ByamlDataType::TYPE_BOOL) {
} else if (type == ByamlDataType::Bool) {
bool data;
iter.tryConvertBool(&data, &entry);
}

View file

@ -212,7 +212,7 @@ void ByamlWriter::pushLocalIter(const ByamlIter& iter, const char* iterKey) {
else
iter.getByamlDataByIndex(&data, i);
if (data.getType() == 0xD0) {
if (data.getType() == ByamlDataType::Bool) {
bool value;
if (iter.tryConvertBool(&value, &data)) {
if (key)
@ -221,7 +221,7 @@ void ByamlWriter::pushLocalIter(const ByamlIter& iter, const char* iterKey) {
addBool(value);
}
}
if (data.getType() == 0xD1) {
if (data.getType() == ByamlDataType::Int) {
s32 value;
if (iter.tryConvertInt(&value, &data)) {
if (key)
@ -230,7 +230,7 @@ void ByamlWriter::pushLocalIter(const ByamlIter& iter, const char* iterKey) {
addInt(value);
}
}
if (data.getType() == 0xD2) {
if (data.getType() == ByamlDataType::Float) {
f32 value;
if (iter.tryConvertFloat(&value, &data)) {
if (key)
@ -239,7 +239,7 @@ void ByamlWriter::pushLocalIter(const ByamlIter& iter, const char* iterKey) {
addFloat(value);
}
}
if (data.getType() == 0xD3) {
if (data.getType() == ByamlDataType::UInt) {
u32 value;
if (iter.tryConvertUInt(&value, &data)) {
if (key)
@ -248,7 +248,7 @@ void ByamlWriter::pushLocalIter(const ByamlIter& iter, const char* iterKey) {
addUInt(value);
}
}
if (data.getType() == 0xD4) {
if (data.getType() == ByamlDataType::Int64) {
s64 value;
if (iter.tryConvertInt64(&value, &data)) {
if (key)
@ -257,7 +257,7 @@ void ByamlWriter::pushLocalIter(const ByamlIter& iter, const char* iterKey) {
addInt64(value);
}
}
if (data.getType() == 0xD6) {
if (data.getType() == ByamlDataType::Double) {
f64 value;
if (iter.tryConvertDouble(&value, &data)) {
if (key)
@ -266,7 +266,7 @@ void ByamlWriter::pushLocalIter(const ByamlIter& iter, const char* iterKey) {
addDouble(value);
}
}
if (data.getType() == 0xD5) {
if (data.getType() == ByamlDataType::UInt64) {
u64 value;
if (iter.tryConvertUInt64(&value, &data)) {
if (key)
@ -275,7 +275,7 @@ void ByamlWriter::pushLocalIter(const ByamlIter& iter, const char* iterKey) {
addUInt64(value);
}
}
if (data.getType() == 0xA0) {
if (data.getType() == ByamlDataType::String) {
const char* value;
if (iter.tryConvertString(&value, &data)) {
if (key)
@ -284,13 +284,13 @@ void ByamlWriter::pushLocalIter(const ByamlIter& iter, const char* iterKey) {
addString(value);
}
}
if (data.getType() == 0x00) {
if (data.getType() == ByamlDataType::None) {
if (key)
addNull(key);
else
addNull();
}
if (data.getType() == 0xC0 || data.getType() == 0xC1) {
if (data.getType() == ByamlDataType::Array || data.getType() == ByamlDataType::Hash) {
ByamlIter value;
if (iter.tryConvertIter(&value, &data))
pushLocalIter(value, key);

View file

@ -12,8 +12,8 @@ void ByamlWriterData::printIndent(s32) const {}
ByamlWriterBool::ByamlWriterBool(bool value) : mValue(value) {}
u8 ByamlWriterBool::getTypeCode() const {
return 0xD0;
ByamlDataType ByamlWriterBool::getTypeCode() const {
return ByamlDataType::Bool;
}
void ByamlWriterBool::print(s32 recursionDepth) const {}
@ -24,8 +24,8 @@ void ByamlWriterBool::write(sead::WriteStream* stream) const {
ByamlWriterInt::ByamlWriterInt(s32 value) : mValue(value) {}
u8 ByamlWriterInt::getTypeCode() const {
return 0xD1;
ByamlDataType ByamlWriterInt::getTypeCode() const {
return ByamlDataType::Int;
}
void ByamlWriterInt::print(s32 recursionDepth) const {}
@ -36,8 +36,8 @@ void ByamlWriterInt::write(sead::WriteStream* stream) const {
ByamlWriterFloat::ByamlWriterFloat(f32 value) : mValue(value) {}
u8 ByamlWriterFloat::getTypeCode() const {
return 0xD2;
ByamlDataType ByamlWriterFloat::getTypeCode() const {
return ByamlDataType::Float;
}
void ByamlWriterFloat::print(s32 recursionDepth) const {}
@ -48,8 +48,8 @@ void ByamlWriterFloat::write(sead::WriteStream* stream) const {
ByamlWriterUInt::ByamlWriterUInt(u32 value) : mValue(value) {}
u8 ByamlWriterUInt::getTypeCode() const {
return 0xD3;
ByamlDataType ByamlWriterUInt::getTypeCode() const {
return ByamlDataType::UInt;
}
void ByamlWriterUInt::print(s32 recursionDepth) const {}
@ -60,8 +60,8 @@ void ByamlWriterUInt::write(sead::WriteStream* stream) const {
ByamlWriterNull::ByamlWriterNull() = default;
u8 ByamlWriterNull::getTypeCode() const {
return 0xFF;
ByamlDataType ByamlWriterNull::getTypeCode() const {
return ByamlDataType::Null;
}
void ByamlWriterNull::print(s32 recursionDepth) const {}
@ -75,8 +75,8 @@ ByamlWriterString::ByamlWriterString(const char* string, ByamlWriterStringTable*
mString = mStringTable->tryAdd(string);
}
u8 ByamlWriterString::getTypeCode() const {
return 0xA0;
ByamlDataType ByamlWriterString::getTypeCode() const {
return ByamlDataType::String;
}
void ByamlWriterString::print(s32 recursionDepth) const {}
@ -96,8 +96,8 @@ void ByamlWriterBigData::write(sead::WriteStream* stream) const {
ByamlWriterInt64::ByamlWriterInt64(s64 value, ByamlWriterBigDataList* list)
: ByamlWriterBigData(list), mValue(value) {}
u8 ByamlWriterInt64::getTypeCode() const {
return 0xD4;
ByamlDataType ByamlWriterInt64::getTypeCode() const {
return ByamlDataType::Int64;
}
void ByamlWriterInt64::writeBigData(sead::WriteStream* stream) const {
@ -109,8 +109,8 @@ void ByamlWriterInt64::print(s32 recursionDepth) const {}
ByamlWriterUInt64::ByamlWriterUInt64(u64 value, ByamlWriterBigDataList* list)
: ByamlWriterBigData(list), mValue(value) {}
u8 ByamlWriterUInt64::getTypeCode() const {
return 0xD5;
ByamlDataType ByamlWriterUInt64::getTypeCode() const {
return ByamlDataType::UInt64;
}
void ByamlWriterUInt64::writeBigData(sead::WriteStream* stream) const {
@ -122,8 +122,8 @@ void ByamlWriterUInt64::print(s32 recursionDepth) const {}
ByamlWriterDouble::ByamlWriterDouble(f64 value, ByamlWriterBigDataList* list)
: ByamlWriterBigData(list), mValue(value) {}
u8 ByamlWriterDouble::getTypeCode() const {
return 0xD6;
ByamlDataType ByamlWriterDouble::getTypeCode() const {
return ByamlDataType::Double;
}
void ByamlWriterDouble::writeBigData(sead::WriteStream* stream) const {
@ -201,16 +201,16 @@ void ByamlWriterArray::addNull() {
addData(new ByamlWriterNull());
}
u8 ByamlWriterArray::getTypeCode() const {
return 0xC0;
ByamlDataType ByamlWriterArray::getTypeCode() const {
return ByamlDataType::Array;
}
void ByamlWriterArray::writeContainer(sead::WriteStream* stream) const {
stream->writeU8(ByamlWriterArray::getTypeCode());
stream->writeU8((u8)ByamlWriterArray::getTypeCode());
alByamlLocalUtil::writeU24(stream, mList.size());
for (auto& node : mList)
stream->writeU8(node->getTypeCode());
stream->writeU8((u8)node->getTypeCode());
s32 i = mList.size();
s32 v12 = i < 0 ? i + 3 : i;
@ -314,17 +314,17 @@ void ByamlWriterHash::addNull(const char* key) {
addData(key, new ByamlWriterNull());
}
u8 ByamlWriterHash::getTypeCode() const {
return 0xc1;
ByamlDataType ByamlWriterHash::getTypeCode() const {
return ByamlDataType::Hash;
}
void ByamlWriterHash::writeContainer(sead::WriteStream* stream) const {
stream->writeU8(ByamlWriterHash::getTypeCode());
stream->writeU8((u8)ByamlWriterHash::getTypeCode());
alByamlLocalUtil::writeU24(stream, mList.size());
for (auto it = mList.begin(); it != mList.end(); ++it) {
alByamlLocalUtil::writeU24(stream, mStringTable1->calcIndex((*it)->getKey()));
stream->writeU8((*it)->getValue()->getTypeCode());
stream->writeU8((u8)(*it)->getValue()->getTypeCode());
(*it)->getValue()->write(stream);
}
}

View file

@ -3,6 +3,8 @@
#include <basis/seadTypes.h>
#include <container/seadTList.h>
#include "Library/Yaml/ByamlData.h"
namespace sead {
class WriteStream;
}
@ -17,7 +19,7 @@ public:
virtual u32 calcPackSize() const { return 4; }
virtual u8 getTypeCode() const { return 0; }
virtual ByamlDataType getTypeCode() const { return ByamlDataType::None; }
virtual bool isContainer() const { return false; }
@ -31,7 +33,7 @@ public:
class ByamlWriterBool : public ByamlWriterData {
public:
ByamlWriterBool(bool value);
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void write(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
@ -42,7 +44,7 @@ private:
class ByamlWriterInt : public ByamlWriterData {
public:
ByamlWriterInt(s32 value);
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void write(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
@ -53,7 +55,7 @@ private:
class ByamlWriterFloat : public ByamlWriterData {
public:
ByamlWriterFloat(f32 value);
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void write(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
@ -64,7 +66,7 @@ private:
class ByamlWriterUInt : public ByamlWriterData {
public:
ByamlWriterUInt(u32 value);
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void write(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
@ -75,7 +77,7 @@ private:
class ByamlWriterNull : public ByamlWriterData {
public:
ByamlWriterNull();
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void write(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
};
@ -85,7 +87,7 @@ class ByamlWriterStringTable;
class ByamlWriterString : public ByamlWriterData {
public:
ByamlWriterString(const char* string, ByamlWriterStringTable* stringTable);
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void write(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
@ -117,7 +119,7 @@ class ByamlWriterInt64 : public ByamlWriterBigData {
public:
ByamlWriterInt64(s64 value, ByamlWriterBigDataList* list);
~ByamlWriterInt64() = default;
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void writeBigData(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
@ -129,7 +131,7 @@ class ByamlWriterUInt64 : public ByamlWriterBigData {
public:
ByamlWriterUInt64(u64 value, ByamlWriterBigDataList* list);
~ByamlWriterUInt64() = default;
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void writeBigData(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
@ -141,7 +143,7 @@ class ByamlWriterDouble : public ByamlWriterBigData {
public:
ByamlWriterDouble(f64 value, ByamlWriterBigDataList* list);
~ByamlWriterDouble() = default;
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void writeBigData(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
@ -238,7 +240,7 @@ public:
void addArray(ByamlWriterArray* array) override;
void addNull() override;
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void writeContainer(sead::WriteStream* stream) const override;
void write(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;
@ -288,7 +290,7 @@ public:
void addArray(const char* key, ByamlWriterArray* value) override;
void addNull(const char* key) override;
u8 getTypeCode() const override;
ByamlDataType getTypeCode() const override;
void writeContainer(sead::WriteStream* stream) const override;
void write(sead::WriteStream* stream) const override;
void print(s32 recursionDepth) const override;

View file

@ -82,7 +82,7 @@ u32 ByamlWriterStringTable::calcIndex(const char* string) const {
void ByamlWriterStringTable::write(sead::WriteStream* stream) const {
if (isEmpty())
return;
stream->writeU8(0xC2);
stream->writeU8((u8)ByamlDataType::StringTable);
alByamlLocalUtil::writeU24(stream, mList.size());
s32 i = 4 * (mList.size() + 2);