| 1 | #pragma once |
| 2 | |
| 3 | #include <basis/seadTypes.h> |
| 4 | |
| 5 | namespace al { |
| 6 | class ByamlHashPair; |
| 7 | |
| 8 | enum ByamlDataType : const u8 { |
| 9 | TYPE_INVALID = 0, |
| 10 | TYPE_STRING = 0xA0, |
| 11 | TYPE_BINARY = 0xA1, |
| 12 | TYPE_ARRAY = 0xC0, |
| 13 | TYPE_HASH = 0xC1, |
| 14 | TYPE_STRING_TABLE = 0xC2, |
| 15 | TYPE_BOOL = 0xD0, |
| 16 | TYPE_INT = 0xD1, |
| 17 | TYPE_FLOAT = 0xD2, |
| 18 | TYPE_UINT = 0xD3, |
| 19 | TYPE_LONG = 0xD4, |
| 20 | TYPE_ULONG = 0xD5, |
| 21 | TYPE_DOUBLE = 0xD6, |
| 22 | TYPE_NULL = 0xFF |
| 23 | }; |
| 24 | |
| 25 | class ByamlData { |
| 26 | public: |
| 27 | ByamlData(); |
| 28 | |
| 29 | void set(const ByamlHashPair* hash_pair, bool isRev); |
| 30 | void set(u8 type, u32 value, bool isRev); |
| 31 | ByamlDataType getType() const; |
| 32 | u32 getValue() const; |
| 33 | |
| 34 | template <typename T = u32> |
| 35 | T getValue() const { |
| 36 | u32 val = getValue(); |
| 37 | return *reinterpret_cast<const T*>(&val); |
| 38 | } |
| 39 | |
| 40 | private: |
| 41 | u32 mValue = 0; |
| 42 | ByamlDataType mType = ByamlDataType::TYPE_INVALID; |
| 43 | }; |
| 44 | |
| 45 | class ByamlHashPair { |
| 46 | public: |
| 47 | s32 getKey(bool isRev) const; |
| 48 | ByamlDataType getType() const; |
| 49 | s32 getValue(bool isRev) const; |
| 50 | |
| 51 | private: |
| 52 | const s32 mData = 0; |
| 53 | const s32 mValue = 0; |
| 54 | }; |
| 55 | |
| 56 | class ByamlHashIter { |
| 57 | public: |
| 58 | ByamlHashIter(const u8* data, bool isRev); |
| 59 | ByamlHashIter(); |
| 60 | |
| 61 | const ByamlHashPair* findPair(s32 key) const; |
| 62 | bool getDataByIndex(ByamlData* data, s32 index) const; |
| 63 | bool getDataByKey(ByamlData* data, s32 key) const; |
| 64 | const u8* getOffsetData(u32 off) const; |
| 65 | const ByamlHashPair* getPairByIndex(s32 index) const; |
| 66 | const ByamlHashPair* getPairTable() const; |
| 67 | u32 getSize() const; |
| 68 | |
| 69 | private: |
| 70 | const u8* mData; |
| 71 | bool mIsRev; |
| 72 | }; |
| 73 | |
| 74 | class ByamlArrayIter { |
| 75 | public: |
| 76 | ByamlArrayIter(const u8* data, bool isRev); |
| 77 | ByamlArrayIter(); |
| 78 | |
| 79 | bool getDataByIndex(ByamlData* data, s32 index) const; |
| 80 | const u32* getDataTable() const; |
| 81 | const u8* getOffsetData(u32 off) const; |
| 82 | u32 getSize() const; |
| 83 | const u8* getTypeTable() const; |
| 84 | |
| 85 | private: |
| 86 | const u8* mData; |
| 87 | bool mIsRev; |
| 88 | }; |
| 89 | } // namespace al |
| 90 | |