From 588de66d0686013e125bd75e9a384c475068fde9 Mon Sep 17 00:00:00 2001 From: fig02 Date: Fri, 22 Jan 2021 16:25:08 -0500 Subject: [PATCH] git subrepo pull --force tools/ZAPD (#653) subrepo: subdir: "tools/ZAPD" merged: "2e1174063" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "2e1174063" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" --- tools/ZAPD/.gitrepo | 4 +- tools/ZAPD/ZAPD/Globals.cpp | 2 +- tools/ZAPD/ZAPD/Main.cpp | 4 +- tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp | 5 ++ tools/ZAPD/ZAPD/Overlays/ZOverlay.h | 3 +- tools/ZAPD/ZAPD/ZAPD.vcxproj | 4 ++ tools/ZAPD/ZAPD/ZAPD.vcxproj.filters | 12 +++++ tools/ZAPD/ZAPD/ZAnimation.cpp | 5 ++ tools/ZAPD/ZAPD/ZAnimation.h | 7 +-- tools/ZAPD/ZAPD/ZArray.cpp | 73 +++++++++++++++++++++++++ tools/ZAPD/ZAPD/ZArray.h | 25 +++++++++ tools/ZAPD/ZAPD/ZBlob.cpp | 5 ++ tools/ZAPD/ZAPD/ZBlob.h | 13 ++--- tools/ZAPD/ZAPD/ZCollision.cpp | 5 ++ tools/ZAPD/ZAPD/ZCollision.h | 2 + tools/ZAPD/ZAPD/ZCutscene.cpp | 5 ++ tools/ZAPD/ZAPD/ZCutscene.h | 8 +-- tools/ZAPD/ZAPD/ZDisplayList.cpp | 5 ++ tools/ZAPD/ZAPD/ZDisplayList.h | 14 ++--- tools/ZAPD/ZAPD/ZFile.cpp | 57 +++++++++++++++++--- tools/ZAPD/ZAPD/ZFile.h | 5 +- tools/ZAPD/ZAPD/ZResource.cpp | 15 +++++- tools/ZAPD/ZAPD/ZResource.h | 8 ++- tools/ZAPD/ZAPD/ZScalar.cpp | 12 +++-- tools/ZAPD/ZAPD/ZScalar.h | 13 ++--- tools/ZAPD/ZAPD/ZSkeleton.cpp | 5 ++ tools/ZAPD/ZAPD/ZSkeleton.h | 13 ++--- tools/ZAPD/ZAPD/ZTexture.h | 16 +++--- tools/ZAPD/ZAPD/ZVector.cpp | 11 +++- tools/ZAPD/ZAPD/ZVector.h | 5 +- tools/ZAPD/ZAPD/ZVtx.cpp | 78 +++++++++++++++++++++++++++ tools/ZAPD/ZAPD/ZVtx.h | 31 +++++++++++ 32 files changed, 405 insertions(+), 65 deletions(-) create mode 100644 tools/ZAPD/ZAPD/ZArray.cpp create mode 100644 tools/ZAPD/ZAPD/ZArray.h create mode 100644 tools/ZAPD/ZAPD/ZVtx.cpp create mode 100644 tools/ZAPD/ZAPD/ZVtx.h diff --git a/tools/ZAPD/.gitrepo b/tools/ZAPD/.gitrepo index 66581a7145..3fbd6a6ddf 100644 --- a/tools/ZAPD/.gitrepo +++ b/tools/ZAPD/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/zeldaret/ZAPD.git branch = master - commit = 0305ec2c27412557fe831cc8ce23b7d8649809fa - parent = db66460dbb2522a1a9822582f8b7d5205415af93 + commit = 2e1174063f3ed6bcf929bc7093cd2d1b05f8518b + parent = d73976503126d10a82016f8f72fac4092dff1932 method = merge cmdver = 0.4.3 diff --git a/tools/ZAPD/ZAPD/Globals.cpp b/tools/ZAPD/ZAPD/Globals.cpp index 50eb17f2b2..16ecd4bc14 100644 --- a/tools/ZAPD/ZAPD/Globals.cpp +++ b/tools/ZAPD/ZAPD/Globals.cpp @@ -50,7 +50,7 @@ string Globals::FindSymbolSegRef(int segNumber, uint32_t symbolAddress) { if (string(child->Name()) == "File") { - ZFile* file = new ZFile(fileMode, child, "", "", true); + ZFile* file = new ZFile(fileMode, child, "", "", "", true); file->GeneratePlaceholderDeclarations(); segmentRefFiles[segNumber] = file; break; diff --git a/tools/ZAPD/ZAPD/Main.cpp b/tools/ZAPD/ZAPD/Main.cpp index fd6fd4cfb2..8d53c979e2 100644 --- a/tools/ZAPD/ZAPD/Main.cpp +++ b/tools/ZAPD/ZAPD/Main.cpp @@ -180,9 +180,7 @@ int NewMain(int argc, char* argv[]) } if (Globals::Instance->verbosity >= VERBOSITY_INFO) - { printf("ZAPD: Zelda Asset Processor For Decomp\n"); - } if (fileMode == ZFileMode::Build || fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile) { @@ -239,7 +237,7 @@ bool Parse(const std::string& xmlFilePath, const std::string& basePath, const st { if (string(child->Name()) == "File") { - ZFile* file = new ZFile(fileMode, child, basePath, outPath, false); + ZFile* file = new ZFile(fileMode, child, basePath, outPath, "", false); Globals::Instance->files.push_back(file); } } diff --git a/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp b/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp index 2554cf6d35..006aa84395 100644 --- a/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp +++ b/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp @@ -216,6 +216,11 @@ string ZOverlay::GetSourceOutputCode(const std::string& prefix) return output; } +ZResourceType ZOverlay::GetResourceType() +{ + return ZResourceType::Overlay; +} + SectionType ZOverlay::GetSectionTypeFromStr(string sectionName) { if (sectionName == ".rel.text" || sectionName == ".text") diff --git a/tools/ZAPD/ZAPD/Overlays/ZOverlay.h b/tools/ZAPD/ZAPD/Overlays/ZOverlay.h index 880adcb295..03dba43c36 100644 --- a/tools/ZAPD/ZAPD/Overlays/ZOverlay.h +++ b/tools/ZAPD/ZAPD/Overlays/ZOverlay.h @@ -55,7 +55,8 @@ public: ZOverlay(std::string nName); ~ZOverlay(); static ZOverlay* FromBuild(std::string buildPath, std::string cfgFolderPath); - std::string GetSourceOutputCode(const std::string& prefix); + std::string GetSourceOutputCode(const std::string& prefix) override; + ZResourceType GetResourceType() override; private: std::vector entries; diff --git a/tools/ZAPD/ZAPD/ZAPD.vcxproj b/tools/ZAPD/ZAPD/ZAPD.vcxproj index 0a7ef483de..654159cb91 100644 --- a/tools/ZAPD/ZAPD/ZAPD.vcxproj +++ b/tools/ZAPD/ZAPD/ZAPD.vcxproj @@ -142,6 +142,7 @@ + @@ -181,6 +182,7 @@ + @@ -214,6 +216,7 @@ + @@ -254,6 +257,7 @@ + diff --git a/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters b/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters index 54f797eaf3..aee2be95fd 100644 --- a/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters +++ b/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters @@ -195,6 +195,12 @@ Source Files\Z64 + + Source Files\Z64 + + + Source Files + @@ -410,6 +416,12 @@ Header Files + + Header Files\Z64 + + + Header Files\Z64 + diff --git a/tools/ZAPD/ZAPD/ZAnimation.cpp b/tools/ZAPD/ZAPD/ZAnimation.cpp index 3a70f0e6a3..f1fccf622e 100644 --- a/tools/ZAPD/ZAPD/ZAnimation.cpp +++ b/tools/ZAPD/ZAPD/ZAnimation.cpp @@ -46,6 +46,11 @@ string ZAnimation::GetSourceOutputCode(const std::string& prefix) return ""; } +ZResourceType ZAnimation::GetResourceType() +{ + return ZResourceType::Animation; +} + ZNormalAnimation::ZNormalAnimation() : ZAnimation() { rotationValues = vector(); diff --git a/tools/ZAPD/ZAPD/ZAnimation.h b/tools/ZAPD/ZAPD/ZAnimation.h index f13c8035f8..25c066a072 100644 --- a/tools/ZAPD/ZAPD/ZAnimation.h +++ b/tools/ZAPD/ZAPD/ZAnimation.h @@ -23,7 +23,8 @@ public: ZAnimation(); - std::string GetSourceOutputCode(const std::string& prefix); + std::string GetSourceOutputCode(const std::string& prefix) override; + ZResourceType GetResourceType() override; protected: virtual void ParseRawData(); @@ -43,7 +44,7 @@ public: ZNormalAnimation(); std::string GetSourceOutputCode(const std::string& prefix); - virtual int GetRawDataSize(); + int GetRawDataSize() override; static ZNormalAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, const std::string& nRelPath); @@ -59,7 +60,7 @@ public: ZLinkAnimation(); std::string GetSourceOutputCode(const std::string& prefix); - virtual int GetRawDataSize(); + int GetRawDataSize() override; static ZLinkAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, const std::string& nRelPath); diff --git a/tools/ZAPD/ZAPD/ZArray.cpp b/tools/ZAPD/ZAPD/ZArray.cpp new file mode 100644 index 0000000000..622aef5a5d --- /dev/null +++ b/tools/ZAPD/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; +} diff --git a/tools/ZAPD/ZAPD/ZArray.h b/tools/ZAPD/ZAPD/ZArray.h new file mode 100644 index 0000000000..8fd2565055 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZArray.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include +#include "ZResource.h" +#include "tinyxml2.h" + +class ZArray : public ZResource +{ +public: + ZArray(); + + void ParseXML(tinyxml2::XMLElement* reader) override; + std::string GetSourceOutputCode(const std::string& prefix) override; + int GetRawDataSize() override; + + static ZArray* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath, ZFile* nParent); + +protected: + int arrayCnt; + ZFile* testFile; + + //void ParseRawData(const std::vector& data, const int offset); +}; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZBlob.cpp b/tools/ZAPD/ZAPD/ZBlob.cpp index 59c9f5bd99..edb0e34c9c 100644 --- a/tools/ZAPD/ZAPD/ZBlob.cpp +++ b/tools/ZAPD/ZAPD/ZBlob.cpp @@ -98,6 +98,11 @@ string ZBlob::GetExternalExtension() return "bin"; } +std::string ZBlob::GetSourceTypeName() +{ + return "u8"; +} + ZResourceType ZBlob::GetResourceType() { return ZResourceType::Blob; diff --git a/tools/ZAPD/ZAPD/ZBlob.h b/tools/ZAPD/ZAPD/ZBlob.h index 5150517371..bb51bb1ff5 100644 --- a/tools/ZAPD/ZAPD/ZBlob.h +++ b/tools/ZAPD/ZAPD/ZBlob.h @@ -11,12 +11,13 @@ public: static ZBlob* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, int rawDataIndex, std::string nRelPath); static ZBlob* BuildFromXML(tinyxml2::XMLElement* reader, const std::string& inFolder, bool readFile); static ZBlob* FromFile(const std::string& filePath); - std::string GetSourceOutputCode(const std::string& prefix); - std::string GetSourceOutputHeader(const std::string& prefix); - void Save(const std::string& outFolder); - bool IsExternalResource(); - std::string GetExternalExtension(); - ZResourceType GetResourceType(); + std::string GetSourceOutputCode(const std::string& prefix) override; + std::string GetSourceOutputHeader(const std::string& prefix) override; + void Save(const std::string& outFolder) override; + bool IsExternalResource() override; + std::string GetExternalExtension() override; + std::string GetSourceTypeName() override; + ZResourceType GetResourceType() override; private: ZBlob(); diff --git a/tools/ZAPD/ZAPD/ZCollision.cpp b/tools/ZAPD/ZAPD/ZCollision.cpp index caaf9e9e40..d6af196780 100644 --- a/tools/ZAPD/ZAPD/ZCollision.cpp +++ b/tools/ZAPD/ZAPD/ZCollision.cpp @@ -167,6 +167,11 @@ ZCollisionHeader::~ZCollisionHeader() delete waterBox; } +ZResourceType ZCollisionHeader::GetResourceType() +{ + return ZResourceType::CollisionHeader; +} + ZCollisionHeader* ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader, vector nRawData, int rawDataIndex) { ZCollisionHeader* col = new ZCollisionHeader(); diff --git a/tools/ZAPD/ZAPD/ZCollision.h b/tools/ZAPD/ZAPD/ZCollision.h index 22402fe805..aa0279d9b3 100644 --- a/tools/ZAPD/ZAPD/ZCollision.h +++ b/tools/ZAPD/ZAPD/ZCollision.h @@ -87,5 +87,7 @@ public: ZCollisionHeader(ZFile* parent, const std::string& prefix, const std::vector& rawData, int rawDataIndex); ~ZCollisionHeader(); + ZResourceType GetResourceType() override; + static ZCollisionHeader* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex); }; diff --git a/tools/ZAPD/ZAPD/ZCutscene.cpp b/tools/ZAPD/ZAPD/ZCutscene.cpp index 9d71a79d94..80ebeffbb6 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.cpp +++ b/tools/ZAPD/ZAPD/ZCutscene.cpp @@ -181,6 +181,11 @@ CutsceneCommands ZCutscene::GetCommandFromID(int id) return CutsceneCommands::Error; } +ZResourceType ZCutscene::GetResourceType() +{ + return ZResourceType::Cutscene; +} + CutsceneCommand::CutsceneCommand(const vector& rawData, int rawDataIndex) { diff --git a/tools/ZAPD/ZAPD/ZCutscene.h b/tools/ZAPD/ZAPD/ZCutscene.h index c57f0613e4..bf26b90280 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.h +++ b/tools/ZAPD/ZAPD/ZCutscene.h @@ -402,12 +402,14 @@ class ZCutscene : public ZResource public: uint32_t segmentOffset; - CutsceneCommands GetCommandFromID(int id); ZCutscene(std::vector nRawData, int rawDataIndex, int rawDataSize); ~ZCutscene(); - std::string GetSourceOutputCode(const std::string& prefix); - int GetRawDataSize(); + std::string GetSourceOutputCode(const std::string& prefix) override; + int GetRawDataSize() override; + CutsceneCommands GetCommandFromID(int id); + + ZResourceType GetResourceType() override; static ZCutscene* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath); protected: diff --git a/tools/ZAPD/ZAPD/ZDisplayList.cpp b/tools/ZAPD/ZAPD/ZDisplayList.cpp index 300c09082f..f1f1eb3e61 100644 --- a/tools/ZAPD/ZAPD/ZDisplayList.cpp +++ b/tools/ZAPD/ZAPD/ZDisplayList.cpp @@ -1367,6 +1367,11 @@ void ZDisplayList::GenerateHLIntermediette(HLFileIntermediette& hlFile) mdl->blocks.push_back(new HLTerminator()); } +ZResourceType ZDisplayList::GetResourceType() +{ + return ZResourceType::DisplayList; +} + vector ZDisplayList::GetRawData() { return rawData; diff --git a/tools/ZAPD/ZAPD/ZDisplayList.h b/tools/ZAPD/ZAPD/ZDisplayList.h index 38bff7d4f6..dcfe6bb39d 100644 --- a/tools/ZAPD/ZAPD/ZDisplayList.h +++ b/tools/ZAPD/ZAPD/ZDisplayList.h @@ -214,14 +214,12 @@ public: class ZDisplayList : public ZResource { protected: - // Test uint32_t lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg; F3DZEXTexFormats lastTexFmt; F3DZEXTexSizes lastTexSiz, lastTexSizTest, lastCISiz; bool lastTexLoaded; bool lastTexIsPalette; - //void ParseXML(tinyxml2::XMLElement* reader); static TextureType TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSizes siz); void ParseRawData(); @@ -260,9 +258,11 @@ public: static int GetDListLength(std::vector rawData, int rawDataIndex); std::vector GetRawData(); - int GetRawDataSize(); - std::string GetSourceOutputHeader(const std::string& prefix); - std::string GetSourceOutputCode(const std::string& prefix); - void Save(const std::string& outFolder); - virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile); + int GetRawDataSize() override; + std::string GetSourceOutputHeader(const std::string& prefix) override; + std::string GetSourceOutputCode(const std::string& prefix) override; + void Save(const std::string& outFolder) override; + virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile) override; + + ZResourceType GetResourceType() override; }; diff --git a/tools/ZAPD/ZAPD/ZFile.cpp b/tools/ZAPD/ZAPD/ZFile.cpp index 98120a8171..aaee5b60fe 100644 --- a/tools/ZAPD/ZAPD/ZFile.cpp +++ b/tools/ZAPD/ZAPD/ZFile.cpp @@ -8,7 +8,9 @@ #include "ZCollision.h" #include "ZScalar.h" #include "ZVector.h" +#include "ZVtx.h" #include "ZCutscene.h" +#include "ZArray.h" #include "Path.h" #include "File.h" #include "Directory.h" @@ -38,7 +40,7 @@ ZFile::ZFile(string nOutPath, string nName) : ZFile() name = nName; } -ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPath, bool placeholderMode) : ZFile() +ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPath, std::string filename, bool placeholderMode) : ZFile() { if (nBasePath == "") basePath = Directory::GetCurrentDirectory(); @@ -50,7 +52,7 @@ ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPa else outputPath = nOutPath; - ParseXML(mode, reader, placeholderMode); + ParseXML(mode, reader, filename, placeholderMode); } ZFile::~ZFile() @@ -59,9 +61,13 @@ ZFile::~ZFile() delete res; } -void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, bool placeholderMode) +void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, bool placeholderMode) { - name = reader->Attribute("Name"); + if (filename == "") + name = reader->Attribute("Name"); + else + name = filename; + int segment = -1; if (reader->Attribute("BaseAddress") != NULL) @@ -289,6 +295,26 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, bool placeholderMode) printf("No ZVector created!!"); } } + else if (string(child->Name()) == "Vtx") + { + ZVtx* vtx = nullptr; + + if (mode == ZFileMode::Extract) + vtx = ZVtx::ExtractFromXML(child, rawData, rawDataIndex, folderName); + + if (vtx != nullptr) + { + vtx->parent = this; + resources.push_back(vtx); + + rawDataIndex += vtx->GetRawDataSize(); + } + else + { + if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) + printf("No ZVtx created!!"); + } + } else if (string(child->Name()) == "Cutscene") { ZCutscene* cs = nullptr; @@ -303,10 +329,24 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, bool placeholderMode) rawDataIndex += cs->GetRawDataSize(); } } + else if (string(child->Name()) == "Array") + { + ZArray* array = nullptr; + + if (mode == ZFileMode::Extract) + array = ZArray::ExtractFromXML(child, rawData, rawDataIndex, folderName, this); + + if (array != nullptr) + { + resources.push_back(array); + rawDataIndex += array->GetRawDataSize(); + } + } else { - if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) - printf("Encountered unknown resource type: %s\n", string(child->Name()).c_str()); + std::cerr << "ERROR bad type\n"; + printf("Encountered unknown resource type: %s on line: %d\n", child->Name(), child->GetLineNum()); + std::exit(EXIT_FAILURE); } } } @@ -359,6 +399,11 @@ std::string ZFile::GetVarName(int address) return ""; } +std::string ZFile::GetName() +{ + return name; +} + void ZFile::ExtractResources(string outputDir) { string folderName = Path::GetFileNameWithoutExtension(outputPath); diff --git a/tools/ZAPD/ZAPD/ZFile.h b/tools/ZAPD/ZAPD/ZFile.h index aa642d810f..89cb02c96d 100644 --- a/tools/ZAPD/ZAPD/ZFile.h +++ b/tools/ZAPD/ZAPD/ZFile.h @@ -27,10 +27,11 @@ public: uint32_t baseAddress, rangeStart, rangeEnd; ZFile(std::string nOutPath, std::string nName); - ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, std::string nBasePath, std::string nOutPath, bool placeholderMode); + ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, std::string nBasePath, std::string nOutPath, std::string filename, bool placeholderMode); ~ZFile(); std::string GetVarName(int address); + std::string GetName(); void ExtractResources(std::string outputDir); void BuildResources(); void BuildSourceFile(std::string outputDir); @@ -61,7 +62,7 @@ protected: std::string sourceOutput; ZFile(); - void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, bool placeholderMode); + void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename, bool placeholderMode); void GenerateSourceFiles(std::string outputDir); void GenerateHLIntermediette(); void AddDeclarationDebugChecks(uint32_t address); diff --git a/tools/ZAPD/ZAPD/ZResource.cpp b/tools/ZAPD/ZAPD/ZResource.cpp index efacafc8ab..153821207c 100644 --- a/tools/ZAPD/ZAPD/ZResource.cpp +++ b/tools/ZAPD/ZAPD/ZResource.cpp @@ -12,7 +12,6 @@ ZResource::ZResource() rawData = vector(); rawDataIndex = 0; outputDeclaration = true; - arrayCnt = -1; } void ZResource::ParseXML(tinyxml2::XMLElement* reader) @@ -54,6 +53,11 @@ bool ZResource::IsExternalResource() return false; } +bool ZResource::DoesSupportArray() +{ + return false; +} + std::string ZResource::GetExternalExtension() { return ""; @@ -94,11 +98,20 @@ string ZResource::GetSourceOutputHeader(const std::string& prefix) return ""; } +void ZResource::ParseRawData() +{ +} + void ZResource::GenerateHLIntermediette(HLFileIntermediette& hlFile) { } +std::string ZResource::GetSourceTypeName() +{ + return ""; +} + ZResourceType ZResource::GetResourceType() { return ZResourceType::Error; diff --git a/tools/ZAPD/ZAPD/ZResource.h b/tools/ZAPD/ZAPD/ZResource.h index ff25bdcfef..02921969fd 100644 --- a/tools/ZAPD/ZAPD/ZResource.h +++ b/tools/ZAPD/ZAPD/ZResource.h @@ -37,7 +37,9 @@ enum class ZResourceType Limb, Skeleton, Scalar, - Vector + Vector, + Vertex, + CollisionHeader }; class ZResource @@ -45,7 +47,6 @@ class ZResource public: ZFile* parent; bool outputDeclaration; - int arrayCnt; ZResource(); virtual void ParseXML(tinyxml2::XMLElement* reader); @@ -57,13 +58,16 @@ public: std::string GetRelativePath(); virtual std::vector GetRawData(); virtual bool IsExternalResource(); + virtual bool DoesSupportArray(); // Can this type be wrapped in an node? virtual std::string GetExternalExtension(); virtual int GetRawDataIndex(); virtual int GetRawDataSize(); virtual void SetRawDataIndex(int value); virtual std::string GetSourceOutputCode(const std::string& prefix); virtual std::string GetSourceOutputHeader(const std::string& prefix); + virtual void ParseRawData(); virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile); + virtual std::string GetSourceTypeName(); virtual ZResourceType GetResourceType(); virtual void CalcHash(); diff --git a/tools/ZAPD/ZAPD/ZScalar.cpp b/tools/ZAPD/ZAPD/ZScalar.cpp index b96d5fed49..10866f1ef4 100644 --- a/tools/ZAPD/ZAPD/ZScalar.cpp +++ b/tools/ZAPD/ZAPD/ZScalar.cpp @@ -31,13 +31,12 @@ void ZScalar::ParseXML(tinyxml2::XMLElement* reader) { ZResource::ParseXML(reader); - name = reader->Attribute("Name"); - std::string type = reader->Attribute("Type"); scalarType = ZScalar::MapOutputTypeToScalarType(type); } -ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type) { +ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type) +{ if (type == "s8") { return ZSCALAR_S8; @@ -228,4 +227,9 @@ std::string ZScalar::GetSourceOutputCode(const std::string& prefix) ZResourceType ZScalar::GetResourceType() { return ZResourceType::Scalar; -} \ No newline at end of file +} + +bool ZScalar::DoesSupportArray() +{ + return true; +} diff --git a/tools/ZAPD/ZAPD/ZScalar.h b/tools/ZAPD/ZAPD/ZScalar.h index 0e49f4e516..26e6a9d8dc 100644 --- a/tools/ZAPD/ZAPD/ZScalar.h +++ b/tools/ZAPD/ZAPD/ZScalar.h @@ -43,12 +43,14 @@ public: ZScalar(); ZScalar(const ZScalarType scalarType); - void ParseXML(tinyxml2::XMLElement* reader); - std::string GetSourceTypeName(); + void ParseXML(tinyxml2::XMLElement* reader) override; + std::string GetSourceTypeName() override; std::string GetSourceValue(); - std::string GetSourceOutputCode(const std::string& prefix); - int GetRawDataSize(); - ZResourceType GetResourceType(); + std::string GetSourceOutputCode(const std::string& prefix) override; + int GetRawDataSize() override; + ZResourceType GetResourceType() override; + bool DoesSupportArray() override; + void ParseRawData() override; static ZScalar* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath); static int MapTypeToSize(const ZScalarType scalarType); @@ -56,6 +58,5 @@ public: static std::string MapScalarTypeToOutputType(const ZScalarType scalarType); protected: - void ParseRawData(); void ParseRawData(const std::vector& data, const int offset); }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZSkeleton.cpp b/tools/ZAPD/ZAPD/ZSkeleton.cpp index d6234d8f9f..f09198f4ed 100644 --- a/tools/ZAPD/ZAPD/ZSkeleton.cpp +++ b/tools/ZAPD/ZAPD/ZSkeleton.cpp @@ -264,6 +264,11 @@ void ZSkeleton::Save(const std::string& outFolder) } +ZResourceType ZSkeleton::GetResourceType() +{ + return ZResourceType::Skeleton; +} + ZLimbLOD::ZLimbLOD() : ZLimbStandard() { farDListPtr = 0; diff --git a/tools/ZAPD/ZAPD/ZSkeleton.h b/tools/ZAPD/ZAPD/ZSkeleton.h index 345469ab45..836251a606 100644 --- a/tools/ZAPD/ZAPD/ZSkeleton.h +++ b/tools/ZAPD/ZAPD/ZSkeleton.h @@ -25,8 +25,8 @@ struct ZLimbStandard : public ZResource ZLimbStandard(); static ZLimbStandard* FromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, std::string nRelPath, ZFile* parent); static ZLimbStandard* FromRawData(std::vector nRawData, int rawDataIndex); - std::string GetSourceOutputCode(const std::string& prefix); - virtual int GetRawDataSize(); + std::string GetSourceOutputCode(const std::string& prefix) override; + int GetRawDataSize() override; }; struct ZLimbLOD : ZLimbStandard @@ -36,8 +36,8 @@ struct ZLimbLOD : ZLimbStandard ZLimbLOD(); //static ZLimbLOD* FromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, std::string nRelPath, ZFile* parent); static ZLimbLOD* FromRawData(std::vector nRawData, int rawDataIndex); - std::string GetSourceOutputCode(const std::string& prefix); - virtual int GetRawDataSize(); + std::string GetSourceOutputCode(const std::string& prefix) override; + int GetRawDataSize() override; }; enum ZSkeletonType @@ -58,7 +58,8 @@ public: ZSkeleton(); virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile); static ZSkeleton* FromXML(tinyxml2::XMLElement* reader, std::vector nRawData, int rawDataIndex, std::string nRelPath, ZFile* nParent); - void Save(const std::string& outFolder); + void Save(const std::string& outFolder) override; + ZResourceType GetResourceType() override; - std::string GetSourceOutputCode(const std::string& prefix); + std::string GetSourceOutputCode(const std::string& prefix) override; }; diff --git a/tools/ZAPD/ZAPD/ZTexture.h b/tools/ZAPD/ZAPD/ZTexture.h index 1e84d47685..faf7d68fdc 100644 --- a/tools/ZAPD/ZAPD/ZTexture.h +++ b/tools/ZAPD/ZAPD/ZTexture.h @@ -29,7 +29,7 @@ protected: uint8_t* bmpRgb; uint8_t* bmpRgba; - virtual void ParseXML(tinyxml2::XMLElement* reader); + void ParseXML(tinyxml2::XMLElement* reader) override; void FixRawData(); void PrepareBitmap(); void PrepareBitmapRGBA16(); @@ -52,9 +52,9 @@ protected: void PrepareRawDataPalette4(std::string palPath); void PrepareRawDataPalette8(std::string palPath); float GetPixelMultiplyer(); - bool IsExternalResource(); - ZResourceType GetResourceType(); - void CalcHash(); + bool IsExternalResource() override; + ZResourceType GetResourceType() override; + void CalcHash() override; public: ZTexture(); @@ -72,8 +72,8 @@ public: std::string GetSourceOutputCode(const std::string& prefix) override; std::string GetSourceOutputHeader(const std::string& prefix) override; - std::vector GetRawData(); - int GetRawDataSize(); + std::vector GetRawData() override; + int GetRawDataSize() override; std::string GetIMFmtFromType(); std::string GetIMSizFromType(); int GetWidth(); @@ -81,6 +81,6 @@ public: void SetWidth(int nWidth); void SetHeight(int nHeight); TextureType GetTextureType(); - void Save(const std::string& outFolder); - std::string GetExternalExtension(); + void Save(const std::string& outFolder) override; + std::string GetExternalExtension() override; }; diff --git a/tools/ZAPD/ZAPD/ZVector.cpp b/tools/ZAPD/ZAPD/ZVector.cpp index c7a6c5293f..e9eba2f449 100644 --- a/tools/ZAPD/ZAPD/ZVector.cpp +++ b/tools/ZAPD/ZAPD/ZVector.cpp @@ -42,7 +42,9 @@ void ZVector::ParseRawData() int currentRawDataIndex = this->rawDataIndex; scalars.clear(); - for (int i = 0; i < this->dimensions; i++) { + + for (int i = 0; i < this->dimensions; i++) + { ZScalar* scalar = new ZScalar(this->scalarType); scalar->rawDataIndex = currentRawDataIndex; scalar->rawData = this->rawData; @@ -64,6 +66,11 @@ int ZVector::GetRawDataSize() return size; } +bool ZVector::DoesSupportArray() +{ + return true; +} + std::string ZVector::GetSourceTypeName() { if (dimensions == 3 && scalarType == ZSCALAR_F32) @@ -94,7 +101,7 @@ std::string ZVector::GetSourceValue() std::vector strings = std::vector(); for (int i = 0; i < this->scalars.size(); i++) strings.push_back(scalars[i]->GetSourceValue()); - return StringHelper::Implode(strings, ", "); + return "{ " + StringHelper::Implode(strings, ", ") + " }"; } std::string ZVector::GetSourceOutputCode(const std::string& prefix) diff --git a/tools/ZAPD/ZAPD/ZVector.h b/tools/ZAPD/ZAPD/ZVector.h index 843eb45d2f..0d6ea06eb3 100644 --- a/tools/ZAPD/ZAPD/ZVector.h +++ b/tools/ZAPD/ZAPD/ZVector.h @@ -17,14 +17,15 @@ public: ZVector(); void ParseXML(tinyxml2::XMLElement* reader); - std::string GetSourceTypeName(); + std::string GetSourceTypeName() override; std::string GetSourceValue(); std::string GetSourceOutputCode(const std::string& prefix); + void ParseRawData() override; int GetRawDataSize(); + bool DoesSupportArray() override; ZResourceType GetResourceType(); static ZVector* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath); protected: - void ParseRawData(); }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZVtx.cpp b/tools/ZAPD/ZAPD/ZVtx.cpp new file mode 100644 index 0000000000..b951310429 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZVtx.cpp @@ -0,0 +1,78 @@ +#include "ZVtx.h" +#include "ZFile.h" +#include "StringHelper.h" +#include "BitConverter.h" + +ZVtx::ZVtx() +{ + x = 0; + y = 0; + z = 0; + flag = 0; + s = 0; + t = 0; + r = 0; + g = 0; + b = 0; + a = 0; +} + +void ZVtx::ParseXML(tinyxml2::XMLElement* reader) +{ +} + +std::string ZVtx::GetSourceTypeName() +{ + return "Vtx"; +} + +std::string ZVtx::GetSourceOutputCode(const std::string& prefix) +{ + std::string output = StringHelper::Sprintf("VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i)", x, y, z, s, t, r, g, b, a); + + if (parent != nullptr) + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(), GetSourceTypeName(), name, output); + + return ""; +} + +void ZVtx::ParseRawData() +{ + const uint8_t* data = rawData.data(); + + x = BitConverter::ToInt16BE(data, rawDataIndex + 0); + y = BitConverter::ToInt16BE(data, rawDataIndex + 2); + z = BitConverter::ToInt16BE(data, rawDataIndex + 4); + flag = BitConverter::ToInt16BE(data, rawDataIndex + 6); + s = BitConverter::ToInt16BE(data, rawDataIndex + 8); + t = BitConverter::ToInt16BE(data, rawDataIndex + 10); + r = data[rawDataIndex + 12]; + g = data[rawDataIndex + 13]; + b = data[rawDataIndex + 14]; + a = data[rawDataIndex + 15]; +} + +int ZVtx::GetRawDataSize() +{ + return 16; +} + +bool ZVtx::DoesSupportArray() +{ + return true; +} + +ZResourceType ZVtx::GetResourceType() +{ + return ZResourceType::Vertex; +} + +ZVtx* ZVtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath) +{ + ZVtx* vtx = new ZVtx(); + vtx->rawData = nRawData; + vtx->rawDataIndex = rawDataIndex; + vtx->ParseRawData(); + + return vtx; +} diff --git a/tools/ZAPD/ZAPD/ZVtx.h b/tools/ZAPD/ZAPD/ZVtx.h new file mode 100644 index 0000000000..83eb734d73 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZVtx.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include +#include "ZResource.h" +#include "ZScalar.h" +#include "tinyxml2.h" + +class ZVtx : public ZResource +{ +public: + int16_t x, y, z; + uint16_t flag; + int16_t s, t; + uint8_t r, g, b, a; + + ZVtx(); + + void ParseXML(tinyxml2::XMLElement* reader); + std::string GetSourceTypeName() override; + std::string GetSourceOutputCode(const std::string& prefix); + void ParseRawData() override; + int GetRawDataSize(); + bool DoesSupportArray() override; + ZResourceType GetResourceType(); + + static ZVtx* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, const int rawDataIndex, const std::string& nRelPath); + +protected: +}; \ No newline at end of file