From d1ea06ec9ead9049335dec132663008c23f736fb Mon Sep 17 00:00:00 2001 From: MonsterDruide1 <5958456@gmail.com> Date: Thu, 7 Oct 2021 22:33:09 +0200 Subject: [PATCH] byaml/writer: Add ByamlWriterArray --- data/odyssey_functions.csv | 42 ++++++++-------- lib/al/byaml/writer/ByamlWriterData.h | 37 ++++++++++++++ lib/al/util/ByamlUtil.h | 5 ++ src/al/byaml/writer/ByamlWriterData.cpp | 67 +++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 21 deletions(-) diff --git a/data/odyssey_functions.csv b/data/odyssey_functions.csv index 331a0a2..1d53986 100644 --- a/data/odyssey_functions.csv +++ b/data/odyssey_functions.csv @@ -65111,27 +65111,27 @@ Address,Quality,Size,Name 0x0000007100a31ea0,U,000172,_ZNK2al15ByamlWriterHash14writeContainerEPN4sead11WriteStreamE 0x0000007100a31f4c,U,000016,_ZNK2al15ByamlWriterHash5writeEPN4sead11WriteStreamE 0x0000007100a31f5c,U,000088,_ZNK2al15ByamlWriterHash5printEi -0x0000007100a31fb4,U,000040,_ZN2al16ByamlWriterArrayC2EPNS_22ByamlWriterStringTableE -0x0000007100a31fdc,U,000064,_ZN2al16ByamlWriterArrayD2Ev -0x0000007100a3201c,U,000072,_ZN2al16ByamlWriterArrayD0Ev -0x0000007100a32064,U,000116,_ZN2al16ByamlWriterArray10deleteDataEv -0x0000007100a320d8,U,000020,_ZNK2al16ByamlWriterArray12calcPackSizeEv -0x0000007100a320ec,U,000088,_ZN2al16ByamlWriterArray7addDataEPNS_15ByamlWriterDataE -0x0000007100a32144,U,000124,_ZN2al16ByamlWriterArray7addBoolEb -0x0000007100a321c0,U,000120,_ZN2al16ByamlWriterArray6addIntEi -0x0000007100a32238,U,000120,_ZN2al16ByamlWriterArray7addUIntEj -0x0000007100a322b0,U,000128,_ZN2al16ByamlWriterArray8addFloatEf -0x0000007100a32330,U,000156,_ZN2al16ByamlWriterArray8addInt64ElPNS_22ByamlWriterBigDataListE -0x0000007100a323cc,U,000156,_ZN2al16ByamlWriterArray9addUInt64EmPNS_22ByamlWriterBigDataListE -0x0000007100a32468,U,000164,_ZN2al16ByamlWriterArray9addDoubleEdPNS_22ByamlWriterBigDataListE -0x0000007100a3250c,U,000136,_ZN2al16ByamlWriterArray9addStringEPKc -0x0000007100a32594,U,000088,_ZN2al16ByamlWriterArray7addHashEPNS_15ByamlWriterHashE -0x0000007100a325ec,U,000088,_ZN2al16ByamlWriterArray8addArrayEPS0_ -0x0000007100a32644,U,000112,_ZN2al16ByamlWriterArray7addNullEv -0x0000007100a326b4,U,000008,_ZNK2al16ByamlWriterArray11getTypeCodeEv -0x0000007100a326bc,U,000220,_ZNK2al16ByamlWriterArray14writeContainerEPN4sead11WriteStreamE -0x0000007100a32798,U,000016,_ZNK2al16ByamlWriterArray5writeEPN4sead11WriteStreamE -0x0000007100a327a8,U,000084,_ZNK2al16ByamlWriterArray5printEi +0x0000007100a31fb4,O,000040,_ZN2al16ByamlWriterArrayC2EPNS_22ByamlWriterStringTableE +0x0000007100a31fdc,O,000064,_ZN2al16ByamlWriterArrayD1Ev +0x0000007100a3201c,O,000072,_ZN2al16ByamlWriterArrayD0Ev +0x0000007100a32064,M,000116,_ZN2al16ByamlWriterArray10deleteDataEv +0x0000007100a320d8,O,000020,_ZNK2al16ByamlWriterArray12calcPackSizeEv +0x0000007100a320ec,O,000088,_ZN2al16ByamlWriterArray7addDataEPNS_15ByamlWriterDataE +0x0000007100a32144,O,000124,_ZN2al16ByamlWriterArray7addBoolEb +0x0000007100a321c0,O,000120,_ZN2al16ByamlWriterArray6addIntEi +0x0000007100a32238,O,000120,_ZN2al16ByamlWriterArray7addUIntEj +0x0000007100a322b0,O,000128,_ZN2al16ByamlWriterArray8addFloatEf +0x0000007100a32330,O,000156,_ZN2al16ByamlWriterArray8addInt64ElPNS_22ByamlWriterBigDataListE +0x0000007100a323cc,O,000156,_ZN2al16ByamlWriterArray9addUInt64EmPNS_22ByamlWriterBigDataListE +0x0000007100a32468,O,000164,_ZN2al16ByamlWriterArray9addDoubleEdPNS_22ByamlWriterBigDataListE +0x0000007100a3250c,O,000136,_ZN2al16ByamlWriterArray9addStringEPKc +0x0000007100a32594,O,000088,_ZN2al16ByamlWriterArray7addHashEPNS_15ByamlWriterHashE +0x0000007100a325ec,O,000088,_ZN2al16ByamlWriterArray8addArrayEPS0_ +0x0000007100a32644,O,000112,_ZN2al16ByamlWriterArray7addNullEv +0x0000007100a326b4,O,000008,_ZNK2al16ByamlWriterArray11getTypeCodeEv +0x0000007100a326bc,O,000220,_ZNK2al16ByamlWriterArray14writeContainerEPN4sead11WriteStreamE +0x0000007100a32798,O,000016,_ZNK2al16ByamlWriterArray5writeEPN4sead11WriteStreamE +0x0000007100a327a8,m,000084,_ZNK2al16ByamlWriterArray5printEi 0x0000007100a327fc,U,000016,_ZN2al19ByamlWriterHashPairC2EPKcPNS_15ByamlWriterDataE 0x0000007100a3280c,O,000060,_ZN2al17ByamlWriterStringC1EPKcPNS_22ByamlWriterStringTableE 0x0000007100a32848,O,000008,_ZNK2al17ByamlWriterString11getTypeCodeEv diff --git a/lib/al/byaml/writer/ByamlWriterData.h b/lib/al/byaml/writer/ByamlWriterData.h index ce67ca9..6b417b3 100644 --- a/lib/al/byaml/writer/ByamlWriterData.h +++ b/lib/al/byaml/writer/ByamlWriterData.h @@ -171,4 +171,41 @@ public: virtual void deleteData(); }; + + +class ByamlWriterArray : public ByamlWriterContainer { +public: + ByamlWriterArray(ByamlWriterStringTable*); + virtual ~ByamlWriterArray(); + + void deleteData() override; + u32 calcPackSize() const override; + + void addData(al::ByamlWriterData*); + void addBool(bool) override; + void addInt(s32) override; + void addUInt(u32) override; + void addFloat(float) override; + void addInt64(s64, ByamlWriterBigDataList*) override; + void addUInt64(u64, ByamlWriterBigDataList*) override; + void addDouble(double, ByamlWriterBigDataList*) override; + void addString(const char*) override; + void addHash(ByamlWriterHash*) override; + void addArray(ByamlWriterArray*) override; + void addNull() override; + + u8 getTypeCode() const override; + void writeContainer(sead::WriteStream*) const override; + void write(sead::WriteStream*) const override; + void print(int) const override; + bool isArray() const override; + +private: + int gap; + sead::TList mList; + al::ByamlWriterStringTable* mStringTable; + +}; +static_assert(sizeof(ByamlWriterArray) == 0x30); + } diff --git a/lib/al/util/ByamlUtil.h b/lib/al/util/ByamlUtil.h index adf2f64..2e4df9b 100755 --- a/lib/al/util/ByamlUtil.h +++ b/lib/al/util/ByamlUtil.h @@ -3,9 +3,14 @@ #include "al/byaml/ByamlIter.h" #include +namespace sead { + class WriteStream; +} + namespace alByamlLocalUtil { const char* getDataTypeString(int); + void writeU24(sead::WriteStream*, int); }; namespace al diff --git a/src/al/byaml/writer/ByamlWriterData.cpp b/src/al/byaml/writer/ByamlWriterData.cpp index 6207dee..988fa06 100644 --- a/src/al/byaml/writer/ByamlWriterData.cpp +++ b/src/al/byaml/writer/ByamlWriterData.cpp @@ -3,6 +3,7 @@ #include #include "al/byaml/writer/ByamlWriterBigDataList.h" #include "al/byaml/writer/ByamlWriterStringTable.h" +#include "al/util/ByamlUtil.h" namespace al { @@ -110,4 +111,70 @@ bool ByamlWriterContainer::isHash() const {return false;} bool ByamlWriterContainer::isArray() const {return false;} void ByamlWriterContainer::deleteData() {} + + + +ByamlWriterArray::ByamlWriterArray(ByamlWriterStringTable* stringTable) : gap(0), mStringTable(stringTable) {} +ByamlWriterArray::~ByamlWriterArray() { + while(auto* node = mList.popBack()){ + delete node; + } +} +void ByamlWriterArray::deleteData() { //TODO heavy diff + for(auto it = mList.begin(); it != mList.end(); ++it) { + if((*it)->isContainer()) { + auto* node = *it; + reinterpret_cast(node)->deleteData(); + } + } +} +u32 ByamlWriterArray::calcPackSize() const { + return mList.size() * 4 + ((mList.size() + 7) & 0xFFFFFFFC); +} +void ByamlWriterArray::addData(ByamlWriterData* data) { + mList.pushBack(new sead::TListNode(data)); +} + +void ByamlWriterArray::addBool(bool value) {addData(new ByamlWriterBool(value));} +void ByamlWriterArray::addInt(int value) {addData(new ByamlWriterInt(value));} +void ByamlWriterArray::addUInt(u32 value) {addData(new ByamlWriterUInt(value));} +void ByamlWriterArray::addFloat(float value) {addData(new ByamlWriterFloat(value));} +void ByamlWriterArray::addInt64(s64 value, ByamlWriterBigDataList* list) {addData(new ByamlWriterInt64(value, list));} +void ByamlWriterArray::addUInt64(u64 value, ByamlWriterBigDataList* list) {addData(new ByamlWriterUInt64(value, list));} +void ByamlWriterArray::addDouble(double value, ByamlWriterBigDataList* list) {addData(new ByamlWriterDouble(value, list));} +void ByamlWriterArray::addString(const char* value) {addData(new ByamlWriterString(value, mStringTable));} +void ByamlWriterArray::addHash(ByamlWriterHash* hash) {addData(hash);} +void ByamlWriterArray::addArray(ByamlWriterArray* array) {addData(array);} +void ByamlWriterArray::addNull() {addData(new ByamlWriterNull());} + +u8 ByamlWriterArray::getTypeCode() const {return 0xC0;} +void ByamlWriterArray::writeContainer(sead::WriteStream* stream) const { + stream->writeU8(0xC0); + alByamlLocalUtil::writeU24(stream, mList.size()); + + for(auto& node : mList){ + stream->writeU8(node->getTypeCode()); + } + + s32 i = mList.size(); + s32 v12 = i < 0 ? i + 3 : i; + s32 v14 = i - (v12 & 0xFFFFFFFC); + s32 v15 = 4 - v14; + s32 v16 = v14 == 0 ? 0 : v15; + for(s32 j = 0; jwriteU8(0); + } + for(auto& node : mList){ + node->write(stream); + } +} +void ByamlWriterArray::write(sead::WriteStream* stream) const { + stream->writeU32(gap); +} +void ByamlWriterArray::print(int unknown) const { //TODO small diff + for(auto& node : mList){ + node->print(unknown); + } +} + }