From 2e1174063f3ed6bcf929bc7093cd2d1b05f8518b Mon Sep 17 00:00:00 2001 From: Nicholas Estelami Date: Tue, 19 Jan 2021 15:08:29 -0500 Subject: Added in support for ZArray (WIP) and ZVtx. Also cleaned up some of the virtual functions. (#73) --- ZAPD/ZArray.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 ZAPD/ZArray.cpp (limited to 'ZAPD/ZArray.cpp') diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp new file mode 100644 index 0000000..622aef5 --- /dev/null +++ b/ZAPD/ZArray.cpp @@ -0,0 +1,73 @@ +#include "ZArray.h" +#include "ZFile.h" +#include "Globals.h" +#include "StringHelper.h" + +ZArray::ZArray() +{ + +} + +void ZArray::ParseXML(tinyxml2::XMLElement* reader) +{ + ZResource::ParseXML(reader); + + arrayCnt = reader->IntAttribute("Count", 0); + testFile = new ZFile(ZFileMode::Extract, reader, Globals::Instance->baseRomPath, "", parent->GetName(), true); +} + +// TODO: This is a bit hacky, but until we refactor how ZFile parses the XML, it'll have to do. +std::string ZArray::GetSourceOutputCode(const std::string& prefix) +{ + std::string output = ""; + + if (testFile->resources.size() <= 0) + { + throw StringHelper::Sprintf("Error! Array needs at least one sub-element.\n"); + } + + ZResource* res = testFile->resources[0]; + int resSize = res->GetRawDataSize(); + + if (!res->DoesSupportArray()) + { + throw StringHelper::Sprintf("Error! Resource %s does not support being wrapped in an array!\n", res->GetName().c_str()); + } + + for (int i = 0; i < arrayCnt; i++) + { + int childIndex = rawDataIndex + (i * resSize); + res->SetRawDataIndex(childIndex); + res->ParseRawData(); + std::string test = res->GetSourceOutputCode(""); + //output += " { " + testFile->declarations[childIndex]->text + " }"; + output += testFile->declarations[childIndex]->text; + + if (i < arrayCnt - 1) + output += ",\n"; + + int bp = 0; + } + + if (parent != nullptr) + parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), res->GetSourceTypeName(), name, arrayCnt, output); + + return ""; +} + +int ZArray::GetRawDataSize() +{ + return arrayCnt * testFile->resources[0]->GetRawDataSize(); +} + +ZArray* ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath, ZFile* nParent) +{ + ZArray* arr = new ZArray(); + arr->rawData = nRawData; + arr->rawDataIndex = rawDataIndex; + arr->parent = nParent; + arr->ParseXML(reader); + //arr->ParseRawData(); + + return arr; +} -- cgit v1.2.3 From d698b97d02380b3bf2c898de44941d03e37daff4 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Wed, 17 Mar 2021 19:19:16 -0300 Subject: Add new resource ZSymbol (#92) * ZSymbol Signed-off-by: Angie * Add array support to ZSymbol Signed-off-by: Angie * Export symbol as array Signed-off-by: Angie * Final cleanup Signed-off-by: Angie * Ups, forgot the offset in a constructor Signed-off-by: Angie --- ZAPD/ZArray.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ZAPD/ZArray.cpp') diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp index 622aef5..4be7656 100644 --- a/ZAPD/ZArray.cpp +++ b/ZAPD/ZArray.cpp @@ -31,7 +31,7 @@ std::string ZArray::GetSourceOutputCode(const std::string& prefix) if (!res->DoesSupportArray()) { - throw StringHelper::Sprintf("Error! Resource %s does not support being wrapped in an array!\n", res->GetName().c_str()); + throw std::runtime_error(StringHelper::Sprintf("Error! Resource %s does not support being wrapped in an array!\n", res->GetName().c_str())); } for (int i = 0; i < arrayCnt; i++) -- cgit v1.2.3