diff --git a/Makefile b/Makefile index b511e33b61..8d0afaa017 100644 --- a/Makefile +++ b/Makefile @@ -167,6 +167,8 @@ build/src/overlays/actors/%.o: CC := python3 tools/asm_processor/build.py $(CC) build/src/overlays/effects/%.o: CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) -- build/src/overlays/gamestates/%.o: CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) -- +build/assets/%.o: CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) -- + #### Main Targets ### all: $(ROM) diff --git a/assets/.gitignore b/assets/.gitignore index 166bd912dd..1c09040d40 100644 --- a/assets/.gitignore +++ b/assets/.gitignore @@ -1,4 +1,6 @@ *.bin *.c *.h -*.cfg \ No newline at end of file +*.cfg +*.vtx.inc +*.dlist.inc \ No newline at end of file diff --git a/extract_assets.py b/extract_assets.py index 820a3c3ce0..e162ae64b4 100755 --- a/extract_assets.py +++ b/extract_assets.py @@ -6,25 +6,26 @@ from shutil import copyfile from multiprocessing import Pool from multiprocessing import cpu_count -def Extract(xmlPath, outputPath): - ExtractFile(xmlPath, outputPath, 1, 0) +def Extract(xmlPath, outputPath, outputSourcePath): + ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 0) -def ExtractScene(xmlPath, outputPath): - ExtractFile(xmlPath, outputPath, 1, 1) +def ExtractScene(xmlPath, outputPath, outputSourcePath): + ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 1) -def ExtractFile(xmlPath, outputPath, genSrcFile, incFilePrefix): - execStr = "tools/ZAPD/ZAPD.out e -eh -i %s -b baserom/ -o %s -gsf %i -ifp %i -sm tools/ZAPD/SymbolMap_OoTMqDbg.txt" % (xmlPath, outputPath, genSrcFile, incFilePrefix) +def ExtractFile(xmlPath, outputPath, outputSourcePath, genSrcFile, incFilePrefix): + execStr = "tools/ZAPD/ZAPD.out e -eh -i %s -b baserom/ -o %s -osf %s -gsf %i -ifp %i -rconf tools/ZAPDConfigs/MqDbg/Config.xml" % (xmlPath, outputPath, outputSourcePath, genSrcFile, incFilePrefix) print(execStr) os.system(execStr) def ExtractFunc(fullPath): outPath = ("assets/" + fullPath.split("assets/xml/")[1]).split(".xml")[0] + outSourcePath = ("assets/" + fullPath.split("assets/xml/")[1]).split(".xml")[0] if (fullPath.startswith("assets/xml/scenes/")): - ExtractScene(fullPath, outPath) + ExtractScene(fullPath, outPath, outSourcePath) else: - Extract(fullPath, outPath) + Extract(fullPath, outPath, outSourcePath) def main(): parser = argparse.ArgumentParser(description="baserom asset extractor") @@ -35,7 +36,7 @@ def main(): if asset_path is not None: if asset_path.endswith("/"): asset_path = asset_path[0:-1] - Extract(f"assets/xml/{asset_path}.xml", f"assets/{asset_path}/") + Extract(f"assets/xml/{asset_path}.xml", f"assets/{asset_path}/", f"assets/{asset_path}/") else: xmlFiles = [] for currentPath, folders, files in os.walk("assets"): diff --git a/tools/ZAPD/.gitrepo b/tools/ZAPD/.gitrepo index a05cb306e6..73304fd8d3 100644 --- a/tools/ZAPD/.gitrepo +++ b/tools/ZAPD/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/zeldaret/ZAPD.git branch = master - commit = c4773301a17a5a9f9c964a3e7ba6dfbf0730a94b - parent = 97f80eeb3f79bafac383fa6dd17765ae291e05d7 + commit = b9120803e6094a54192ed67d9585ab046101c816 + parent = 81b43ba32e564a00c976dec7d520e6bcb0b122f8 method = merge cmdver = 0.4.3 diff --git a/tools/ZAPD/Makefile b/tools/ZAPD/Makefile index 0502cb5d10..f2e9d64741 100644 --- a/tools/ZAPD/Makefile +++ b/tools/ZAPD/Makefile @@ -1,5 +1,16 @@ +OPTIMIZATION_ON ?= 1 + CC := g++ -CFLAGS := -g -std=c++17 -I ZAPD -I lib/assimp/include -I lib/elfio -I lib/json/include -I lib/stb -I lib/tinygltf -I lib/libgfxd -I lib/tinyxml2 -O2 -rdynamic +INC := -I ZAPD -I lib/assimp/include -I lib/elfio -I lib/json/include -I lib/stb -I lib/tinygltf -I lib/libgfxd -I lib/tinyxml2 + +CFLAGS := -g3 -fpic -Wl,-export-dynamic -std=c++17 -rdynamic -Wall +ifeq ($(OPTIMIZATION_ON),1) + CFLAGS += -O2 +else + CFLAGS += -O0 +endif + +LDFLAGS := -ldl UNAME := $(shell uname) FS_INC = @@ -13,22 +24,28 @@ CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp)) CPP_FILES += lib/tinyxml2/tinyxml2.cpp O_FILES := $(CPP_FILES:.cpp=.o) -all: ZAPD.out +all: ZAPD.out copycheck genbuildinfo: python3 ZAPD/genbuildinfo.py +copycheck: ZAPD.out + python3 copycheck.py + clean: rm -f $(O_FILES) ZAPD.out $(MAKE) -C lib/libgfxd clean rebuild: clean all -%.o: %.cpp genbuildinfo - $(CC) $(CFLAGS) -c $< -o $@ +%.o: %.cpp + $(CC) $(CFLAGS) $(INC) -c $< -o $@ $(LDFLAGS) + +ZAPD/Main.o: genbuildinfo ZAPD/Main.cpp + $(CC) $(CFLAGS) $(INC) -c ZAPD/Main.cpp -o $@ $(LDFLAGS) lib/libgfxd/libgfxd.a: $(MAKE) -C lib/libgfxd -j ZAPD.out: $(O_FILES) lib/libgfxd/libgfxd.a - $(CC) $(CFLAGS) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC) + $(CC) $(CFLAGS) $(INC) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC) $(LDFLAGS) diff --git a/tools/ZAPD/ZAPD/BitConverter.h b/tools/ZAPD/ZAPD/BitConverter.h index 9d209f055b..7df68de5e0 100644 --- a/tools/ZAPD/ZAPD/BitConverter.h +++ b/tools/ZAPD/ZAPD/BitConverter.h @@ -7,71 +7,71 @@ class BitConverter { public: - static inline int8_t ToInt8BE(const uint8_t* data, int offset) + static inline int8_t ToInt8BE(const uint8_t* data, int32_t offset) { return (uint8_t)data[offset + 0]; } - static inline int8_t ToInt8BE(const std::vector& data, int offset) + static inline int8_t ToInt8BE(const std::vector& data, int32_t offset) { return (uint8_t)data[offset + 0]; } - static inline uint8_t ToUInt8BE(const uint8_t* data, int offset) + static inline uint8_t ToUInt8BE(const uint8_t* data, int32_t offset) { return (uint8_t)data[offset + 0]; } - static inline uint8_t ToUInt8BE(const std::vector& data, int offset) + static inline uint8_t ToUInt8BE(const std::vector& data, int32_t offset) { return (uint8_t)data[offset + 0]; } - static inline int16_t ToInt16BE(const uint8_t* data, int offset) + static inline int16_t ToInt16BE(const uint8_t* data, int32_t offset) { return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; } - static inline int16_t ToInt16BE(const std::vector& data, int offset) + static inline int16_t ToInt16BE(const std::vector& data, int32_t offset) { return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; } - static inline uint16_t ToUInt16BE(const uint8_t* data, int offset) + static inline uint16_t ToUInt16BE(const uint8_t* data, int32_t offset) { return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; } - static inline uint16_t ToUInt16BE(const std::vector& data, int offset) + static inline uint16_t ToUInt16BE(const std::vector& data, int32_t offset) { return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; } - static inline int32_t ToInt32BE(const uint8_t* data, int offset) + static inline int32_t ToInt32BE(const uint8_t* data, int32_t offset) { return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; } - static inline int32_t ToInt32BE(const std::vector& data, int offset) + static inline int32_t ToInt32BE(const std::vector& data, int32_t offset) { return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; } - static inline uint32_t ToUInt32BE(const uint8_t* data, int offset) + static inline uint32_t ToUInt32BE(const uint8_t* data, int32_t offset) { return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; } - static inline uint32_t ToUInt32BE(const std::vector& data, int offset) + static inline uint32_t ToUInt32BE(const std::vector& data, int32_t offset) { return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; } - static inline int64_t ToInt64BE(const uint8_t* data, int offset) + static inline int64_t ToInt64BE(const uint8_t* data, int32_t offset) { return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + @@ -79,7 +79,7 @@ public: ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); } - static inline int64_t ToInt64BE(const std::vector& data, int offset) + static inline int64_t ToInt64BE(const std::vector& data, int32_t offset) { return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + @@ -87,7 +87,7 @@ public: ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); } - static inline uint64_t ToUInt64BE(const uint8_t* data, int offset) + static inline uint64_t ToUInt64BE(const uint8_t* data, int32_t offset) { return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + @@ -95,7 +95,7 @@ public: ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); } - static inline uint64_t ToUInt64BE(const std::vector& data, int offset) + static inline uint64_t ToUInt64BE(const std::vector& data, int32_t offset) { return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + @@ -103,7 +103,7 @@ public: ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); } - static inline float ToFloatBE(const uint8_t* data, int offset) + static inline float ToFloatBE(const uint8_t* data, int32_t offset) { float value; uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + @@ -114,7 +114,7 @@ public: return value; } - static inline float ToFloatBE(const std::vector& data, int offset) + static inline float ToFloatBE(const std::vector& data, int32_t offset) { float value; uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + @@ -125,7 +125,7 @@ public: return value; } - static inline double ToDoubleBE(const uint8_t* data, int offset) + static inline double ToDoubleBE(const uint8_t* data, int32_t offset) { double value; uint64_t floatData = @@ -141,7 +141,7 @@ public: return value; } - static inline double ToDoubleBE(const std::vector& data, int offset) + static inline double ToDoubleBE(const std::vector& data, int32_t offset) { double value; uint64_t floatData = diff --git a/tools/ZAPD/ZAPD/CRC32.h b/tools/ZAPD/ZAPD/CRC32.h new file mode 100644 index 0000000000..4158a55289 --- /dev/null +++ b/tools/ZAPD/ZAPD/CRC32.h @@ -0,0 +1,23 @@ +#pragma once + +static uint32_t CRC32B(unsigned char* message, int32_t size) +{ + int32_t byte, crc; + int32_t mask; + + crc = 0xFFFFFFFF; + + for (int32_t i = 0; i < size; i++) + { + byte = message[i]; + crc = crc ^ byte; + + for (int32_t j = 7; j >= 0; j--) + { + mask = -(crc & 1); + crc = (crc >> 1) ^ (0xEDB88320 & mask); + } + } + + return ~(uint32_t)(crc); +} \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/File.h b/tools/ZAPD/ZAPD/File.h index 5db466ad9b..62806d5f1c 100644 --- a/tools/ZAPD/ZAPD/File.h +++ b/tools/ZAPD/ZAPD/File.h @@ -20,7 +20,7 @@ public: static std::vector ReadAllBytes(const std::string& filePath) { std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate); - int fileSize = (int)file.tellg(); + int32_t fileSize = (int32_t)file.tellg(); file.seekg(0); char* data = new char[fileSize]; file.read(data, fileSize); @@ -33,7 +33,7 @@ public: static std::string ReadAllText(const std::string& filePath) { std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate); - int fileSize = (int)file.tellg(); + int32_t fileSize = (int32_t)file.tellg(); file.seekg(0); char* data = new char[fileSize + 1]; memset(data, 0, fileSize + 1); diff --git a/tools/ZAPD/ZAPD/Globals.cpp b/tools/ZAPD/ZAPD/Globals.cpp index e6f2458dba..93e7fdf255 100644 --- a/tools/ZAPD/ZAPD/Globals.cpp +++ b/tools/ZAPD/ZAPD/Globals.cpp @@ -1,6 +1,7 @@ #include "Globals.h" #include #include "File.h" +#include "Path.h" #include "tinyxml2.h" using namespace tinyxml2; @@ -13,21 +14,22 @@ Globals::Globals() Instance = this; files = std::vector(); - segments = std::vector(); + segments = std::vector(); symbolMap = std::map(); - segmentRefs = map(); - segmentRefFiles = map(); + segmentRefs = map(); + segmentRefFiles = map(); game = ZGame::OOT_RETAIL; genSourceFile = true; testMode = false; profile = false; includeFilePrefix = false; + useLegacyZDList = false; useExternalResources = true; lastScene = nullptr; verbosity = VERBOSITY_SILENT; } -string Globals::FindSymbolSegRef(int segNumber, uint32_t symbolAddress) +string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress) { if (segmentRefs.find(segNumber) != segmentRefs.end()) { @@ -52,7 +54,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; @@ -72,7 +74,10 @@ void Globals::ReadConfigFile(const std::string& configFilePath) XMLError eResult = doc.LoadFile(configFilePath.c_str()); if (eResult != tinyxml2::XML_SUCCESS) + { + throw std::runtime_error("Error: Unable to read config file."); return; + } XMLNode* root = doc.FirstChild(); @@ -85,14 +90,74 @@ void Globals::ReadConfigFile(const std::string& configFilePath) if (string(child->Name()) == "SymbolMap") { string fileName = string(child->Attribute("File")); - GenSymbolMap(fileName); + GenSymbolMap(Path::GetDirectoryName(configFilePath) + "/" + fileName); } else if (string(child->Name()) == "Segment") { string fileName = string(child->Attribute("File")); - int segNumber = child->IntAttribute("Number"); + int32_t segNumber = child->IntAttribute("Number"); segmentRefs[segNumber] = fileName; } + else if (string(child->Name()) == "ActorList") + { + string fileName = string(child->Attribute("File")); + std::vector lines = + File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName); + + for (std::string line : lines) + cfg.actorList.push_back(StringHelper::Strip(line, "\r")); + } + else if (string(child->Name()) == "ObjectList") + { + string fileName = string(child->Attribute("File")); + std::vector lines = + File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName); + + for (std::string line : lines) + cfg.objectList.push_back(StringHelper::Strip(line, "\r")); + } + else if (string(child->Name()) == "TexturePool") + { + string fileName = string(child->Attribute("File")); + ReadTexturePool(Path::GetDirectoryName(configFilePath) + "/" + fileName); + } + else if (string(child->Name()) == "BGConfig") + { + cfg.bgScreenWidth = child->IntAttribute("ScreenWidth", 320); + cfg.bgScreenHeight = child->IntAttribute("ScreenHeight", 240); + } + } +} + +void Globals::ReadTexturePool(const std::string& texturePoolXmlPath) +{ + XMLDocument doc; + XMLError eResult = doc.LoadFile(texturePoolXmlPath.c_str()); + + if (eResult != tinyxml2::XML_SUCCESS) + { + fprintf(stderr, "Warning: Unable to read texture pool XML with error code %i\n", eResult); + return; + } + + XMLNode* root = doc.FirstChild(); + + if (root == nullptr) + return; + + for (XMLElement* child = root->FirstChildElement(); child != NULL; + child = child->NextSiblingElement()) + { + if (string(child->Name()) == "Texture") + { + string crcStr = string(child->Attribute("CRC")); + string texPath = string(child->Attribute("Path")); + string texName = ""; + + uint32_t crc = strtoul(crcStr.c_str(), NULL, 16); + + cfg.texturePool[crc].path = texPath; + } } } @@ -110,22 +175,13 @@ void Globals::GenSymbolMap(const std::string& symbolMapPath) } } -void Globals::AddSegment(int segment) +void Globals::AddSegment(int32_t segment) { if (std::find(segments.begin(), segments.end(), segment) == segments.end()) segments.push_back(segment); } -bool Globals::HasSegment(int segment) +bool Globals::HasSegment(int32_t segment) { return std::find(segments.begin(), segments.end(), segment) != segments.end(); } - -GameConfig::GameConfig() -{ - segmentRefs = map(); - segmentRefFiles = map(); - symbolMap = std::map(); - actorList = std::vector(); - objectList = std::vector(); -} diff --git a/tools/ZAPD/ZAPD/Globals.h b/tools/ZAPD/ZAPD/Globals.h index 6b7075f492..5186947243 100644 --- a/tools/ZAPD/ZAPD/Globals.h +++ b/tools/ZAPD/ZAPD/Globals.h @@ -7,14 +7,33 @@ #include "ZRoom/ZRoom.h" #include "ZTexture.h" -typedef enum VerbosityLevel +enum VerbosityLevel { VERBOSITY_SILENT, VERBOSITY_INFO, VERBOSITY_DEBUG -} VerbosityLevel; +}; -class GameConfig; +struct TexturePoolEntry +{ + fs::path path = ""; // Path to Shared Texture +}; + +class GameConfig +{ +public: + std::map segmentRefs; + std::map segmentRefFiles; + std::map symbolMap; + std::vector actorList; + std::vector objectList; + std::map texturePool; // Key = CRC + + // ZBackground + uint32_t bgScreenWidth = 320, bgScreenHeight = 240; + + GameConfig() = default; +}; class Globals { @@ -23,42 +42,32 @@ public: bool genSourceFile; // Used for extraction bool useExternalResources; - bool testMode; // Enables certain experimental features - bool profile; // Measure performance of certain operations - bool includeFilePrefix; // Include the file prefix in symbols + bool testMode; // Enables certain experimental features + bool profile; // Measure performance of certain operations + bool includeFilePrefix; // Include the file prefix in symbols + bool useLegacyZDList; VerbosityLevel verbosity; // ZAPD outputs additional information ZFileMode fileMode; - std::string baseRomPath, inputPath, outputPath, cfgPath; + fs::path baseRomPath, inputPath, outputPath, sourceOutputPath, cfgPath; TextureType texType; ZGame game; + GameConfig cfg; + bool warnUnaccounted = false; std::vector files; - std::vector segments; - std::map segmentRefs; - std::map segmentRefFiles; + std::vector segments; + std::map segmentRefs; + std::map segmentRefFiles; ZRoom* lastScene; std::map symbolMap; Globals(); - std::string FindSymbolSegRef(int segNumber, uint32_t symbolAddress); + std::string FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress); void ReadConfigFile(const std::string& configFilePath); + void ReadTexturePool(const std::string& texturePoolXmlPath); void GenSymbolMap(const std::string& symbolMapPath); - void AddSegment(int segment); - bool HasSegment(int segment); -}; - -class GameConfig -{ -public: - std::map segmentRefs; - std::map segmentRefFiles; - std::map symbolMap; - std::vector actorList; - std::vector objectList; - - GameConfig(); - -private: + void AddSegment(int32_t segment); + bool HasSegment(int32_t segment); }; /* diff --git a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp index 7d879c9470..6ae2264db9 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp +++ b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp @@ -58,30 +58,12 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromZAnimation(ZAnimation* z { HLAnimationIntermediette* anim = new HLAnimationIntermediette(); - /*anim->limit = zAnim->limit; - anim->frameCount = zAnim->frameCount; - - for (uint16_t item : zAnim->rotationValues) - anim->rotationValues.push_back(item); - - for (RotationIndex item : zAnim->rotationIndices) - anim->rotationIndices.push_back(item);*/ - return anim; } ZAnimation* HLAnimationIntermediette::ToZAnimation() { - ZAnimation* zAnim = new ZAnimation(); - - /*zAnim->limit = limit; - zAnim->frameCount = frameCount; - - for (uint16_t item : rotationValues) - zAnim->rotationValues.push_back(item); - - for (RotationIndex item : rotationIndices) - zAnim->rotationIndices.push_back(item);*/ + ZAnimation* zAnim = new ZAnimation(nullptr); return zAnim; } diff --git a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp index 25355378f4..db7483a150 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp +++ b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp @@ -21,6 +21,7 @@ HLModelIntermediette::HLModelIntermediette() startIndex = 0; meshStartIndex = 0; hasSkeleton = false; + lastTrans = Vec3s(0, 0, 0); } HLModelIntermediette::~HLModelIntermediette() @@ -61,7 +62,6 @@ HLModelIntermediette* HLModelIntermediette::FromXML(tinyxml2::XMLElement* root) void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDisplayList* zDisplayList) { - // HLModelIntermediette* model = new HLModelIntermediette(); HLLimbIntermediette* limb = new HLLimbIntermediette(); limb->name = zDisplayList->GetName(); @@ -97,15 +97,15 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla // Analyze display lists to determine components HLDisplayListIntermediette* dList = new HLDisplayListIntermediette(); dList->address = zDisplayList->GetRawDataIndex(); - int startIndex = 0; + int32_t startIndex = 0; // Go through the display lists and setup commands - int meshCnt = 0; + int32_t meshCnt = 0; HLMeshIntermediette* mesh = new HLMeshIntermediette(); mesh->name = StringHelper::Sprintf("%s_%i", zDisplayList->GetName().c_str(), meshCnt); - int matCnt = 0; + int32_t matCnt = 0; HLMaterialIntermediette* lastMat = new HLMaterialIntermediette(); lastMat->name = StringHelper::Sprintf("Material_%i", matCnt); @@ -120,26 +120,15 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla if (opcode == F3DZEXOpcode::G_SETOTHERMODE_L) { - int ss = (data & 0x0000FF0000000000) >> 40; - int nn = (data & 0x000000FF00000000) >> 32; - // int dd = (data & 0xFFFFFFFF); - - int sft = 32 - (nn + 1) - ss; - - if (sft == 3) - { - // int mode1 = (dd & 0xCCCC0000) >> 0; - // int mode2 = (dd & 0x33330000) >> 0; - } } else if (opcode == F3DZEXOpcode::G_SETPRIMCOLOR) { - int mm = (data & 0x0000FF0000000000) >> 40; - int ff = (data & 0x000000FF00000000) >> 32; - int rr = (data & 0x00000000FF000000) >> 24; - int gg = (data & 0x0000000000FF0000) >> 16; - int bb = (data & 0x000000000000FF00) >> 8; - int aa = (data & 0x00000000000000FF) >> 0; + int32_t mm = (data & 0x0000FF0000000000) >> 40; + int32_t ff = (data & 0x000000FF00000000) >> 32; + int32_t rr = (data & 0x00000000FF000000) >> 24; + int32_t gg = (data & 0x0000000000FF0000) >> 16; + int32_t bb = (data & 0x000000000000FF00) >> 8; + int32_t aa = (data & 0x00000000000000FF) >> 0; lastClrR = rr; lastClrG = gg; @@ -159,33 +148,17 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla (F3DZEXOpcode)(zDisplayList->instructions[i - 1] >> 56) != F3DZEXOpcode::G_RDPPIPESYNC) { - // int fff = (data & 0b0000000011100000000000000000000000000000000000000000000000000000) - // >> 53; int ii = (data & - // 0b0000000000011000000000000000000000000000000000000000000000000000) >> 51; int - // nnnnnnnnn = (data & - // 0b0000000000000011111111100000000000000000000000000000000000000000) >> 41; int - // mmmmmmmmm = (data & - // 0b0000000000000000000000011111111100000000000000000000000000000000) >> 32; int ttt = - // (data & 0b0000000000000000000000000000000000000111000000000000000000000000) >> 24; int - // pppp = (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >> - // 20; - int cc = + int32_t cc = (data & 0b0000000000000000000000000000000000000000000011000000000000000000) >> 18; - // int aaaa = (data & - // 0b0000000000000000000000000000000000000000000000111100000000000000) >> 14; int ssss = - // (data & 0b0000000000000000000000000000000000000000000000000011110000000000) >> 10; - int dd = + int32_t dd = (data & 0b0000000000000000000000000000000000000000000000000000001100000000) >> 8; - // int bbbb = (data & - // 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; int uuuu = - // (data & 0b0000000000000000000000000000000000000000000000000000000000001111); lastMat->cmtH = (HLMaterialCmt)cc; lastMat->cmtV = (HLMaterialCmt)dd; matCnt++; - if (matCnt > 1) + if (matCnt > 1 && mesh->commands.size() > 0) { model->blocks.push_back(lastMat); limb->commands.push_back(new HLLimbCommand(mesh->name, lastMat->name)); @@ -223,9 +196,9 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla } else if (opcode == F3DZEXOpcode::G_VTX) { - int nn = (data & 0x000FF00000000000ULL) >> 44; - int aa = (data & 0x000000FF00000000ULL) >> 32; - int startIndex = ((aa >> 1) - nn); + int32_t nn = (data & 0x000FF00000000000ULL) >> 44; + int32_t aa = (data & 0x000000FF00000000ULL) >> 32; + int32_t startIndex = ((aa >> 1) - nn); uint32_t vtxAddr = data & 0x00FFFFFF; uint32_t diff = vtxAddr - vStart; @@ -235,46 +208,59 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla } else if (opcode == F3DZEXOpcode::G_TRI1) { - int aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; - int bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; - int cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; + int32_t aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; + int32_t bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; + int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; mesh->commands.push_back(new HLMeshCmdTriangle1(aa, bb, cc, 0)); } else if (opcode == F3DZEXOpcode::G_TRI2) { - int aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; - int bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; - int cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; - int dd = ((data & 0x00000000FF0000ULL) >> 16) / 2; - int ee = ((data & 0x0000000000FF00ULL) >> 8) / 2; - int ff = ((data & 0x000000000000FFULL) >> 0) / 2; + int32_t aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; + int32_t bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; + int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; + int32_t dd = ((data & 0x00000000FF0000ULL) >> 16) / 2; + int32_t ee = ((data & 0x0000000000FF00ULL) >> 8) / 2; + int32_t ff = ((data & 0x000000000000FFULL) >> 0) / 2; mesh->commands.push_back(new HLMeshCmdTriangle2(aa, bb, cc, 0, dd, ee, ff, 0)); } - // int bp = 0; + // int32_t bp = 0; } limb->commands.push_back(new HLLimbCommand(mesh->name, lastMat->name)); model->blocks.push_back(lastMat); model->blocks.push_back(mesh); model->blocks.push_back(limb); - - // return model; } void HLModelIntermediette::FromZSkeleton(HLModelIntermediette* model, ZSkeleton* zSkeleton) { model->hasSkeleton = true; - for (size_t i = 0; i < zSkeleton->limbs.size(); i++) - { - // ZLimb* limb = zSkeleton->limbs[i]; + // Start at the root skeleton node, go down... + ProcessZSkeletonLimb(model, zSkeleton, zSkeleton->limbs[0]); +} - for (size_t j = 0; j < model->blocks.size(); j++) - { - } +void HLModelIntermediette::ProcessZSkeletonLimb(HLModelIntermediette* model, ZSkeleton* zSkeleton, + ZLimb* limb) +{ + if (limb->dList == nullptr && limb->dListPtr != 0) + limb->dList = (ZDisplayList*)zSkeleton->parent->FindResource(limb->dListPtr); + + if (limb->dList != nullptr) + { + auto cmdTrans = new HLSetTranslation(limb->transX, limb->transY, limb->transZ); + cmdTrans->parent = model; + model->blocks.push_back(cmdTrans); + + FromZDisplayList(model, limb->dList); + } + + for (ZLimb* childLimb : limb->children) + { + ProcessZSkeletonLimb(model, zSkeleton, childLimb); } } @@ -296,7 +282,7 @@ string HLModelIntermediette::ToOBJFile() return output; } -string HLModelIntermediette::ToFBXFile() +string HLModelIntermediette::ToAssimpFile() { #ifdef USE_ASSIMP Assimp::Exporter exporter; @@ -307,22 +293,30 @@ string HLModelIntermediette::ToFBXFile() std::vector vertices; + int32_t idx = 0; + for (HLIntermediette* block : blocks) { block->parent = this; block->OutputAssimp(newScene, &vertices); + + idx++; } newScene->mRootNode->mNumChildren += newScene->mNumMeshes; newScene->mRootNode->mChildren = new aiNode*[newScene->mRootNode->mNumChildren]; - for (int i = 0; i < newScene->mNumMeshes; i++) + for (size_t i = 0; i < newScene->mNumMeshes; i++) { aiNode* child = new aiNode(); child->mName = StringHelper::Sprintf("OBJ_%i", i); child->mNumMeshes = 1; - child->mMeshes = new unsigned int[1]; + child->mMeshes = new uint32_t[1]; child->mMeshes[0] = i; + child->mTransformation.Translation(aiVector3D(meshTranslations[i].x * 10, + meshTranslations[i].y * 10, + meshTranslations[i].z * 10), + child->mTransformation); newScene->mRootNode->mChildren[i] = child; } @@ -485,8 +479,8 @@ string HLVerticesIntermediette::OutputCode(HLModelIntermediette* parent) for (Vertex v : vertices) { - output += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", v.x, v.y, - v.z, v.flag, v.s, v.t, v.r, v.g, v.b, v.a); + output += StringHelper::Sprintf(" { %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", v.x, + v.y, v.z, v.flag, v.s, v.t, v.r, v.g, v.b, v.a); } output += StringHelper::Sprintf("};\n"); @@ -502,32 +496,19 @@ std::string HLVerticesIntermediette::OutputOBJ() { output += StringHelper::Sprintf("v %f %f %f %i %i %i %i\n", (float)v.x * 0.1f, (float)v.y * 0.1f, (float)v.z * 0.1f, v.r, v.g, v.b, v.a); - // output += StringHelper::Sprintf("v %f %f %f\n", (float)v.x * 0.1f, (float)v.y * 0.1f, - // (float)v.z * 0.1f); } - // for (Vertex v : vertices) - // output += StringHelper::Sprintf("vt %i %i\n", v.s, v.t); - return output; } void HLVerticesIntermediette::OutputAssimp(aiScene* scene, std::vector* verts) { - // aiVector3D* verts = new aiVector3D[vertices.size()]; - // aiVector3D* normals = new aiVector3D[vertices.size()]; - verts->clear(); for (size_t i = 0; i < vertices.size(); i++) { verts->push_back(aiVector3D(vertices[i].x, vertices[i].y, vertices[i].z)); - // normals[i] = aiVector3D(vertices[i].x, vertices[i].y, vertices[i].z); } - - // mesh->mVertices = verts; - // mesh->mNormals = normals; - // mesh->mNumVertices += vertices.size(); } void HLVerticesIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root) @@ -615,7 +596,7 @@ void HLMeshCmdTriangle1::OutputAssimp(HLModelIntermediette* parent, aiScene* sce { aiFace* face = new aiFace(); face->mNumIndices = 3; - face->mIndices = new unsigned int[3]; + face->mIndices = new uint32_t[3]; face->mIndices[0] = parent->startIndex + v0; face->mIndices[1] = parent->startIndex + v1; face->mIndices[2] = parent->startIndex + v2; @@ -680,10 +661,9 @@ string HLMeshCmdTriangle2::OutputCode(HLModelIntermediette* parent) std::string HLMeshCmdTriangle2::OutputOBJ(HLModelIntermediette* parent) { - // HLVerticesIntermediette* verts = parent->FindByName(""); string output = ""; - int startIndex = parent->startIndex; + int32_t startIndex = parent->startIndex; output += StringHelper::Sprintf("f %i %i %i\n", startIndex + v0 + 1, startIndex + v1 + 1, startIndex + v2 + 1); @@ -698,7 +678,7 @@ void HLMeshCmdTriangle2::OutputAssimp(HLModelIntermediette* parent, aiScene* sce { aiFace* face = new aiFace(); face->mNumIndices = 3; - face->mIndices = new unsigned int[3]; + face->mIndices = new uint32_t[3]; face->mIndices[0] = parent->startIndex + v0; face->mIndices[1] = parent->startIndex + v1; face->mIndices[2] = parent->startIndex + v2; @@ -709,7 +689,7 @@ void HLMeshCmdTriangle2::OutputAssimp(HLModelIntermediette* parent, aiScene* sce { aiFace* face = new aiFace(); face->mNumIndices = 3; - face->mIndices = new unsigned int[3]; + face->mIndices = new uint32_t[3]; face->mIndices[0] = parent->startIndex + v10; face->mIndices[1] = parent->startIndex + v11; face->mIndices[2] = parent->startIndex + v12; @@ -783,18 +763,12 @@ string HLMeshCmdLoadVertices::OutputCode(HLModelIntermediette* parent) HLMaterialIntermediette::HLMaterialIntermediette() { textureName = ""; - // repeatH = false; - // repeatV = false; clrR = 0; clrG = 0; clrB = 0; clrA = 0; clrM = 0; clrL = 0; - // clampH = false; - // clampV = false; - // mirrorH = false; - // mirrorV = false; cmtH = HLMaterialCmt::Wrap; cmtV = HLMaterialCmt::Wrap; } @@ -803,12 +777,6 @@ void HLMaterialIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement) { name = xmlElement->Attribute("Name"); textureName = xmlElement->Attribute("TextureName"); - // repeatH = xmlElement->BoolAttribute("RepeatH"); - // repeatV = xmlElement->BoolAttribute("RepeatV"); - // clampH = xmlElement->BoolAttribute("ClampH"); - // clampV = xmlElement->BoolAttribute("ClampV"); - // mirrorH = xmlElement->BoolAttribute("MirrorH"); - // mirrorV = xmlElement->BoolAttribute("MirrorV"); clrR = xmlElement->IntAttribute("ClrR"); clrG = xmlElement->IntAttribute("ClrG"); clrB = xmlElement->IntAttribute("ClrB"); @@ -834,8 +802,8 @@ void HLMaterialIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XM elem->SetAttribute("ClrA", clrA); elem->SetAttribute("ClrL", clrL); elem->SetAttribute("ClrM", clrM); - elem->SetAttribute("CmtH", (int)cmtH); - elem->SetAttribute("CmtV", (int)cmtV); + elem->SetAttribute("CmtH", (int32_t)cmtH); + elem->SetAttribute("CmtV", (int32_t)cmtV); parent->InsertEndChild(elem); } @@ -997,19 +965,19 @@ string HLMeshIntermediette::OutputCode(string materialName) HLMaterialIntermediette* mat = parent->FindByName(materialName); HLTextureIntermediette* tex = parent->FindByName(mat->textureName); - output += StringHelper::Sprintf("\tgsDPPipeSync(),\n"); - output += StringHelper::Sprintf("\tgsDPSetPrimColor(%i, %i, %i, %i, %i, %i),\n", mat->clrL, + output += StringHelper::Sprintf(" gsDPPipeSync(),\n"); + output += StringHelper::Sprintf(" gsDPSetPrimColor(%i, %i, %i, %i, %i, %i),\n", mat->clrL, mat->clrM, mat->clrR, mat->clrG, mat->clrB, mat->clrA); - output += StringHelper::Sprintf("\tgsDPPipeSync(),\n"); - output += StringHelper::Sprintf("\tgsSPTexture(65535, 65535, 0, 0, G_ON),\n"); + output += StringHelper::Sprintf(" gsDPPipeSync(),\n"); + output += StringHelper::Sprintf(" gsSPTexture(65535, 65535, 0, 0, G_ON),\n"); output += StringHelper::Sprintf( - "\tgsDPLoadMultiBlock(%s, 0, 0, %s, %s, %i, %i, 0, 0, 0, 5, 5, 0, 0),\n", + " gsDPLoadMultiBlock(%s, 0, 0, %s, %s, %i, %i, 0, 0, 0, 5, 5, 0, 0),\n", mat->textureName.c_str(), tex->tex->GetIMFmtFromType().c_str(), tex->tex->GetIMSizFromType().c_str(), tex->tex->GetWidth(), tex->tex->GetHeight()); for (HLMeshCommand* cmd : commands) - output += "\t" + cmd->OutputCode(parent) + "\n"; + output += " " + cmd->OutputCode(parent) + "\n"; return output; } @@ -1041,6 +1009,9 @@ void HLMeshIntermediette::OutputAssimp(aiScene* scene, std::vector* cmd->OutputAssimp(parent, scene, mesh); } + parent->meshTranslations.push_back(parent->lastTrans); + // parent->objects.push_back(new HLModelObj(parent->lastTransX, )) + scene->mMeshes[scene->mNumMeshes++] = mesh; } @@ -1094,7 +1065,7 @@ std::string HLLimbIntermediette::OutputCode() for (HLLimbCommand* cmd : commands) output += cmd->OutputCode(parent); - output += StringHelper::Sprintf("\tgsSPEndDisplayList(),\n"); + output += StringHelper::Sprintf(" gsSPEndDisplayList(),\n"); output += StringHelper::Sprintf("};\n"); return output; @@ -1146,8 +1117,6 @@ std::string HLLimbCommand::OutputCode(HLModelIntermediette* parent) // Time to generate the display list... HLMeshIntermediette* mesh = parent->FindByName(meshName); - // HLMaterialIntermediette* mat = parent->FindByName(materialName); - // HLTextureIntermediette* tex = parent->FindByName(mat->textureName); output += mesh->OutputCode(materialName); @@ -1176,3 +1145,31 @@ void HLTerminator::OutputAssimp(aiScene* scene, std::vector* verts) verts->clear(); } + +HLSetTranslation::HLSetTranslation() +{ + transX = 0; + transY = 0; + transZ = 0; +} + +HLSetTranslation::HLSetTranslation(float nTransX, float nTransY, float nTransZ) +{ + transX = nTransX; + transY = nTransY; + transZ = nTransZ; +} + +void HLSetTranslation::OutputAssimp(aiScene* scene, std::vector* verts) +{ + parent->lastTrans = Vec3s(transX, transY, transZ); +} + +HLModelObj::HLModelObj(Vec3s nPos, Vec3s nRot, std::vector nVerts, + std::vector nIndices) +{ + pos = nPos; + rot = nRot; + vertices = nVerts; + indices = nIndices; +} diff --git a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h index b879974600..5fda096649 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h +++ b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -8,7 +9,6 @@ #include "../ZDisplayList.h" #include "../ZSkeleton.h" #include "HLFileIntermediette.h" -#include "HLTexture.h" /* * An intermediette format for models. Goes from FBX<-->Intermediette<-->Display List C Code. @@ -32,10 +32,26 @@ public: virtual void InitFromXML(tinyxml2::XMLElement* xmlElement); }; +class HLModelObj +{ +public: + Vec3s pos; + Vec3s rot; + std::vector vertices; + std::vector indices; + + HLModelObj() = default; + HLModelObj(Vec3s nPos, Vec3s nRot, std::vector nVerts, + std::vector nIndices); +}; + class HLModelIntermediette : public HLFileIntermediette { public: std::vector blocks; + std::vector meshTranslations; + std::vector objects; + Vec3s lastTrans; bool hasSkeleton; @@ -52,8 +68,10 @@ public: static HLModelIntermediette* FromXML(tinyxml2::XMLElement* root); static void FromZDisplayList(HLModelIntermediette* model, ZDisplayList* zDisplayList); static void FromZSkeleton(HLModelIntermediette* model, ZSkeleton* zSkeleton); + static void ProcessZSkeletonLimb(HLModelIntermediette* model, ZSkeleton* zSkeleton, + ZLimb* limb); std::string ToOBJFile(); - std::string ToFBXFile(); + std::string ToAssimpFile(); std::string OutputCode(); std::string OutputXML(); @@ -78,6 +96,17 @@ public: virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root); }; +class HLSetTranslation : public HLIntermediette +{ +public: + float transX, transY, transZ; + + HLSetTranslation(); + HLSetTranslation(float nTransX, float nTransY, float nTransZ); + + virtual void OutputAssimp(aiScene* scene, std::vector* verts); +}; + class HLTerminator : public HLIntermediette { public: @@ -249,7 +278,7 @@ class HLDisplayListIntermediette : public HLIntermediette { public: std::vector commands; - int address; + uint32_t address; HLDisplayListIntermediette(); diff --git a/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp b/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp index f9b362cfdc..0bf6b36370 100644 --- a/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp +++ b/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp @@ -6,11 +6,11 @@ using namespace std; HLTexture* HLTexture::FromPNG(std::string pngFilePath, HLTextureType texType) { - int comp; + int32_t comp; HLTexture* tex = new HLTexture(); tex->type = texType; - tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int*)&tex->width, (int*)&tex->height, - &comp, STBI_rgb_alpha); + tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int32_t*)&tex->width, + (int32_t*)&tex->height, &comp, STBI_rgb_alpha); return tex; } diff --git a/tools/ZAPD/ZAPD/Main.cpp b/tools/ZAPD/ZAPD/Main.cpp index d771e7a357..a1dfb2155c 100644 --- a/tools/ZAPD/ZAPD/Main.cpp +++ b/tools/ZAPD/ZAPD/Main.cpp @@ -7,13 +7,16 @@ #include "Overlays/ZOverlay.h" #include "Path.h" #include "ZAnimation.h" +#include "ZBackground.h" #include "ZBlob.h" #include "ZFile.h" #include "ZTexture.h" #if !defined(_MSC_VER) && !defined(__CYGWIN__) +#include +#include // for __cxa_demangle +#include // for dladdr #include -#include #include #endif @@ -23,62 +26,77 @@ using namespace tinyxml2; using namespace std; -bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, +bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath, ZFileMode fileMode); -void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, - const std::string& outPath); -void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath); -void BuildAssetModelIntermediette(const std::string& mdlPath, const std::string& outPath); -void BuildAssetAnimationIntermediette(const std::string& animPath, const std::string& outPath); - -int NewMain(int argc, char* argv[]); +void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath); +void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath); +void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath); +void BuildAssetModelIntermediette(const fs::path& outPath); +void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath); #if !defined(_MSC_VER) && !defined(__CYGWIN__) void ErrorHandler(int sig) { void* array[4096]; - char** symbols; - size_t size; - size = backtrace(array, 4096); - symbols = backtrace_symbols(array, 4096); + const size_t nMaxFrames = sizeof(array) / sizeof(array[0]); + size_t size = backtrace(array, nMaxFrames); + char** symbols = backtrace_symbols(array, nMaxFrames); + + // To prevent unused parameter warning + (void)sig; for (size_t i = 1; i < size; i++) { - // size_t len = strlen(symbols[i]); - cout << symbols[i] << "\n"; + Dl_info info; + uint32_t gotAddress = dladdr(array[i], &info); + string functionName(symbols[i]); + + if (gotAddress != 0 && info.dli_sname != nullptr) + { + int32_t status; + char* demangled = abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, &status); + const char* nameFound = info.dli_sname; + + if (status == 0) + { + nameFound = demangled; + } + + functionName = StringHelper::Sprintf("%s (+0x%X)", nameFound, + (char*)array[i] - (char*)info.dli_saddr); + free(demangled); + } + + fprintf(stderr, "%-3zd %s\n", i, functionName.c_str()); } - // cout << "Error: signal " << sig << ":\n"; - backtrace_symbols_fd(array, size, STDERR_FILENO); + // backtrace_symbols_fd(array, size, STDERR_FILENO); + free(symbols); exit(1); } #endif int main(int argc, char* argv[]) { - Globals* g = new Globals(); - return NewMain(argc, argv); -} - -int NewMain(int argc, char* argv[]) -{ - // Syntax: ZAPD.exe [mode (b/btex/bovl/e)] (Arbritrary Number of Arguments) + // Syntax: ZAPD.exe [mode (btex/bovl/e)] (Arbritrary Number of Arguments) if (argc < 2) { - printf("ZAPD.exe [mode (b/btex/bovl/bsf/bblb/bmdlintr/bamnintr/e)] ...\n"); + printf("ZAPD.exe (%s) [mode (btex/bovl/bsf/bblb/bmdlintr/bamnintr/e)] ...\n", gBuildHash); return 1; } + Globals* g = new Globals(); + // Parse File Mode string buildMode = argv[1]; ZFileMode fileMode = ZFileMode::Invalid; - if (buildMode == "b") - fileMode = ZFileMode::Build; - else if (buildMode == "btex") + if (buildMode == "btex") fileMode = ZFileMode::BuildTexture; + else if (buildMode == "bren") + fileMode = ZFileMode::BuildBackground; else if (buildMode == "bovl") fileMode = ZFileMode::BuildOverlay; else if (buildMode == "bsf") @@ -99,13 +117,17 @@ int NewMain(int argc, char* argv[]) } // Parse other "commands" - for (int i = 2; i < argc; i++) + for (int32_t i = 2; i < argc; i++) { string arg = argv[i]; if (arg == "-o" || arg == "--outputpath") // Set output path { Globals::Instance->outputPath = argv[i + 1]; + + if (Globals::Instance->sourceOutputPath == "") + Globals::Instance->sourceOutputPath = Globals::Instance->outputPath; + i++; } else if (arg == "-i" || arg == "--inputpath") // Set input path @@ -118,6 +140,11 @@ int NewMain(int argc, char* argv[]) Globals::Instance->baseRomPath = argv[i + 1]; i++; } + else if (arg == "-osf") // Set source output path + { + Globals::Instance->sourceOutputPath = argv[i + 1]; + i++; + } else if (arg == "-gsf") // Generate source file during extraction { Globals::Instance->genSourceFile = string(argv[i + 1]) == "1"; @@ -128,18 +155,24 @@ int NewMain(int argc, char* argv[]) Globals::Instance->includeFilePrefix = string(argv[i + 1]) == "1"; i++; } - else if (arg == "-tm") // Test Mode + else if (arg == "-tm") // Test Mode (enables certain experimental features) { Globals::Instance->testMode = string(argv[i + 1]) == "1"; i++; } - else if (arg == "-profile") // Profile + else if (arg == "-ulzdl") // Use Legacy ZDisplay List + { + Globals::Instance->useLegacyZDList = string(argv[i + 1]) == "1"; + i++; + } + else if (arg == "-profile") // Enable profiling { Globals::Instance->profile = string(argv[i + 1]) == "1"; i++; } else if (arg == "-uer") // Split resources into their individual components (enabled by default) + // TODO: We may wish to make this a part of the config file... { Globals::Instance->useExternalResources = string(argv[i + 1]) == "1"; i++; @@ -149,93 +182,92 @@ int NewMain(int argc, char* argv[]) Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[i + 1]); i++; } - else if (arg == "-cfg") // Set cfg path + else if (arg == "-cfg") // Set cfg path (for overlays) + // TODO: Change the name of this to something else so it doesn't get confused with XML config files. { Globals::Instance->cfgPath = argv[i + 1]; i++; } - else if (arg == "-sm") // Set symbol map path - { - Globals::Instance->GenSymbolMap(argv[i + 1]); - i++; - } else if (arg == "-rconf") // Read Config File { Globals::Instance->ReadConfigFile(argv[i + 1]); i++; } - else if (arg == "-al") // Set actor list - { - i++; - } - else if (arg == "-ol") // Set object list - { - i++; - } else if (arg == "-eh") // Enable Error Handler { #if !defined(_MSC_VER) && !defined(__CYGWIN__) signal(SIGSEGV, ErrorHandler); signal(SIGABRT, ErrorHandler); +#else + printf("Warning: Tried to set error handler, but this build lacks support for one.\n"); #endif } else if (arg == "-v") // Verbose { Globals::Instance->verbosity = (VerbosityLevel)strtol(argv[++i], NULL, 16); } + else if (arg == "-wu" || arg == "--warn-unaccounted") // Warn unaccounted + { + Globals::Instance->warnUnaccounted = true; + } } if (Globals::Instance->verbosity >= VERBOSITY_INFO) printf("ZAPD: Zelda Asset Processor For Decomp: %s\n", gBuildHash); - if (fileMode == ZFileMode::Build || fileMode == ZFileMode::Extract || - fileMode == ZFileMode::BuildSourceFile) + try { - bool parseSuccessful = Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath, - Globals::Instance->outputPath, fileMode); - if (!parseSuccessful) + if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile) { - return 1; + bool parseSuccessful = + Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath, + Globals::Instance->outputPath, fileMode); + + if (!parseSuccessful) + return 1; + } + else if (fileMode == ZFileMode::BuildTexture) + { + TextureType texType = Globals::Instance->texType; + + BuildAssetTexture(Globals::Instance->inputPath, texType, Globals::Instance->outputPath); + } + else if (fileMode == ZFileMode::BuildBackground) + { + BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath); + } + else if (fileMode == ZFileMode::BuildBlob) + { + BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath); + } + else if (fileMode == ZFileMode::BuildModelIntermediette) + { + BuildAssetModelIntermediette(Globals::Instance->outputPath); + } + else if (fileMode == ZFileMode::BuildAnimationIntermediette) + { + BuildAssetAnimationIntermediette(Globals::Instance->inputPath, + Globals::Instance->outputPath); + } + else if (fileMode == ZFileMode::BuildOverlay) + { + ZOverlay* overlay = + ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath), + Path::GetDirectoryName(Globals::Instance->cfgPath)); + + if (overlay) + File::WriteAllText(Globals::Instance->outputPath, overlay->GetSourceOutputCode("")); } } - else if (fileMode == ZFileMode::BuildTexture) + catch (std::runtime_error& e) { - TextureType texType = Globals::Instance->texType; - string pngFilePath = Globals::Instance->inputPath; - string outFilePath = Globals::Instance->outputPath; - - BuildAssetTexture(pngFilePath, texType, outFilePath); + printf("Exception occurred: %s\n", e.what()); } - else if (fileMode == ZFileMode::BuildBlob) - { - string blobFilePath = Globals::Instance->inputPath; - string outFilePath = Globals::Instance->outputPath; - - BuildAssetBlob(blobFilePath, outFilePath); - } - else if (fileMode == ZFileMode::BuildModelIntermediette) - { - BuildAssetModelIntermediette(Globals::Instance->inputPath, Globals::Instance->outputPath); - } - else if (fileMode == ZFileMode::BuildAnimationIntermediette) - { - BuildAssetAnimationIntermediette(Globals::Instance->inputPath, - Globals::Instance->outputPath); - } - else if (fileMode == ZFileMode::BuildOverlay) - { - ZOverlay* overlay = - ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath), - Path::GetDirectoryName(Globals::Instance->cfgPath)); - - if (overlay) - File::WriteAllText(Globals::Instance->outputPath, overlay->GetSourceOutputCode("")); - } - + delete g; return 0; } -bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, +bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath, ZFileMode fileMode) { XMLDocument doc; @@ -260,16 +292,21 @@ 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, "", xmlFilePath, false); Globals::Instance->files.push_back(file); } + else + { + throw std::runtime_error( + StringHelper::Sprintf("Parse: Fatal error in '%s'.\n\t Found a resource outside of " + "a File element: '%s'\n", + xmlFilePath.c_str(), child->Name())); + } } for (ZFile* file : Globals::Instance->files) { - if (fileMode == ZFileMode::Build) - file->BuildResources(); - else if (fileMode == ZFileMode::BuildSourceFile) + if (fileMode == ZFileMode::BuildSourceFile) file->BuildSourceFile(outPath); else file->ExtractResources(outPath); @@ -284,19 +321,16 @@ bool Parse(const std::string& xmlFilePath, const std::string& basePath, const st return true; } -void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, - const std::string& outPath) +void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath) { - vector split = StringHelper::Split(outPath, "/"); - string name = StringHelper::Split(split[split.size() - 1], ".")[0]; + string name = outPath.stem(); + ZTexture* tex = ZTexture::FromPNG(pngFilePath, texType); string cfgPath = StringHelper::Split(pngFilePath, ".")[0] + ".cfg"; if (File::Exists(cfgPath)) name = File::ReadAllText(cfgPath); - // string src = StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str()) + - // tex->GetSourceOutputCode(name) + "};\n"; string src = tex->GetSourceOutputCode(name); File::WriteAllText(outPath, src); @@ -304,14 +338,19 @@ void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, delete tex; } -void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath) +void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath) { - vector split = StringHelper::Split(outPath, "/"); - ZBlob* blob = ZBlob::FromFile(blobFilePath); - string name = StringHelper::Split(split[split.size() - 1], ".")[0]; + ZBackground background(nullptr); + background.ParseBinaryFile(imageFilePath, false); + + File::WriteAllText(outPath, background.GetBodySourceCode()); +} + +void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath) +{ + ZBlob* blob = ZBlob::FromFile(blobFilePath); + string name = outPath.stem(); // filename without extension - // string src = StringHelper::Sprintf("u8 %s[] = \n{\n", name.c_str()) + - // blob->GetSourceOutputCode(name) + "};\n"; string src = blob->GetSourceOutputCode(name); File::WriteAllText(outPath, src); @@ -319,12 +358,10 @@ void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath) delete blob; } -void BuildAssetModelIntermediette(const std::string& mdlPath, const std::string& outPath) +void BuildAssetModelIntermediette(const fs::path& outPath) { XMLDocument doc; - // XMLError eResult = doc.LoadFile(mdlPath.c_str()); - vector split = StringHelper::Split(outPath, "/"); HLModelIntermediette* mdl = HLModelIntermediette::FromXML(doc.RootElement()); string output = mdl->OutputCode(); @@ -333,7 +370,7 @@ void BuildAssetModelIntermediette(const std::string& mdlPath, const std::string& delete mdl; } -void BuildAssetAnimationIntermediette(const std::string& animPath, const std::string& outPath) +void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath) { vector split = StringHelper::Split(outPath, "/"); ZFile* file = new ZFile("", split[split.size() - 2]); @@ -341,8 +378,6 @@ void BuildAssetAnimationIntermediette(const std::string& animPath, const std::st ZAnimation* zAnim = anim->ToZAnimation(); zAnim->SetName(Path::GetFileNameWithoutExtension(split[split.size() - 1])); zAnim->parent = file; - // zAnim->rotationIndicesSeg = 1; - // zAnim->rotationValuesSeg = 2; zAnim->GetSourceOutputCode(split[split.size() - 2]); string output = ""; diff --git a/tools/ZAPD/ZAPD/OutputFormatter.cpp b/tools/ZAPD/ZAPD/OutputFormatter.cpp index 3a7fbd63d6..65b45f3c3e 100644 --- a/tools/ZAPD/ZAPD/OutputFormatter.cpp +++ b/tools/ZAPD/ZAPD/OutputFormatter.cpp @@ -1,94 +1,116 @@ #include "OutputFormatter.h" -int OutputFormatter::write(const char* buf, int count) +void OutputFormatter::Flush() +{ + if (col > lineLimit) + { + str.append(1, '\n'); + str.append(currentIndent, ' '); + + uint32_t newCol = currentIndent + (wordP - word); + + for (uint32_t i = 0; i < wordNests; i++) + nestIndent[nest - i] -= col - newCol; + + col = newCol; + } + else + { + str.append(space, spaceP - space); + } + spaceP = space; + + str.append(word, wordP - word); + wordP = word; + wordNests = 0; +} + +int OutputFormatter::Write(const char* buf, int count) { for (int i = 0; i < count; i++) { char c = buf[i]; - if (c == '\n') + if (c == ' ' || c == '\t' || c == '\n') { - col = 0; - current_indent = nest_indent[nest]; - } - else if (c == '\t') - { - int n = tab_size - (col % tab_size); - for (int j = 0; j < n - 1; j++) - *space_p++ = ' '; - c = ' '; - col += n; + if (wordP - word != 0) + { + Flush(); + } + + if (c == '\n') + { + col = 0; + *spaceP++ = c; + } + else if (c == '\t') + { + int n = tabSize - (col % tabSize); + col += n; + for (int j = 0; j < n; j++) + *spaceP++ = ' '; + } + else + { + col++; + *spaceP++ = c; + } + + currentIndent = nestIndent[nest]; } else { col++; - } - if (c == '(') - { - nest++; - nest_indent[nest] = col; - current_indent = col; - } - else if (c == ')') - { - nest--; - } - - if (c == ' ' || c == '\t' || c == '\n') - { - str.append(word, word_p - word); - word_p = word; - - *space_p++ = c; - } - else - { - if (col > line_limit) + if (c == '(') { - str.append(1, '\n'); - str.append(current_indent, ' '); - col = current_indent + 1 + (word_p - word); + nest++; + nestIndent[nest] = col; + wordNests++; } - else + else if (c == ')') { - str.append(space, space_p - space); + if (nest > 0) + nest--; + if (wordNests > 0) + wordNests--; } - space_p = space; - *word_p++ = c; + *wordP++ = c; } } return count; } -OutputFormatter* OutputFormatter::static_instance; - -int OutputFormatter::write_static(const char* buf, int count) +int OutputFormatter::Write(const std::string& buf) { - return static_instance->write(buf, count); + return Write(buf.data(), buf.size()); } -int (*OutputFormatter::static_writer())(const char* buf, int count) +OutputFormatter* OutputFormatter::Instance; + +int OutputFormatter::WriteStatic(const char* buf, int count) { - static_instance = this; - return &write_static; + return Instance->Write(buf, count); } -OutputFormatter::OutputFormatter(int tab_size, int default_indent, int line_limit) - : tab_size{tab_size}, default_indent{default_indent}, line_limit{line_limit}, col{0}, nest{0}, - nest_indent{default_indent}, current_indent{default_indent}, word_p{word}, space_p{space} +int (*OutputFormatter::StaticWriter())(const char* buf, int count) +{ + Instance = this; + return &WriteStatic; +} + +OutputFormatter::OutputFormatter(uint32_t tabSize, uint32_t defaultIndent, uint32_t lineLimit) + : tabSize{tabSize}, defaultIndent{defaultIndent}, lineLimit{lineLimit}, col{0}, nest{0}, + nestIndent{defaultIndent}, currentIndent{defaultIndent}, + wordNests(0), wordP{word}, spaceP{space} { } -std::string OutputFormatter::get_output() +std::string OutputFormatter::GetOutput() { - str.append(space, space_p - space); - space_p = space; - - str.append(word, word_p - word); - word_p = word; + Flush(); return std::move(str); } diff --git a/tools/ZAPD/ZAPD/OutputFormatter.h b/tools/ZAPD/ZAPD/OutputFormatter.h index 97edcdd37f..b887b42588 100644 --- a/tools/ZAPD/ZAPD/OutputFormatter.h +++ b/tools/ZAPD/ZAPD/OutputFormatter.h @@ -7,31 +7,35 @@ class OutputFormatter { private: - const int tab_size; - const int default_indent; - const int line_limit; + const uint32_t tabSize; + const uint32_t defaultIndent; + const uint32_t lineLimit; - int col; - int nest; - int nest_indent[8]; - int current_indent; + uint32_t col; + uint32_t nest; + uint32_t nestIndent[8]; + uint32_t currentIndent; + uint32_t wordNests; char word[128]; char space[128]; - char* word_p; - char* space_p; + char* wordP; + char* spaceP; std::string str; - int write(const char* buf, int count); + void Flush(); - static OutputFormatter* static_instance; - static int write_static(const char* buf, int count); + static OutputFormatter* Instance; + static int WriteStatic(const char* buf, int count); public: - OutputFormatter(int tab_size = 4, int default_indent = 4, int line_limit = 120); + OutputFormatter(uint32_t tabSize = 4, uint32_t defaultIndent = 4, uint32_t lineLimit = 120); - int (*static_writer())(const char* buf, int count); + int (*StaticWriter())(const char* buf, int count); // Must be `int` due to libgfxd - std::string get_output(); + int Write(const char* buf, int count); + int Write(const std::string& buf); + + std::string GetOutput(); }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp b/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp index 1179b508f7..d5969f7c04 100644 --- a/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp +++ b/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp @@ -36,7 +36,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) vector relSections = {".rel.text", ".rel.data", ".rel.rodata"}; vector sections = {".text", ".data", ".rodata"}; - int sectionOffs[5] = {0}; + int32_t sectionOffs[5] = {0}; vector textRelocs; vector dataRelocs; vector rodataRelocs; @@ -65,7 +65,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) for (auto curReader : readers) { Elf_Half sec_num = curReader->sections.size(); - for (int i = 0; i < sec_num; i++) + for (int32_t i = 0; i < sec_num; i++) { section* pSec = curReader->sections[i]; @@ -75,16 +75,16 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) SectionType sectionType = GetSectionTypeFromStr(pSec->get_name()); if (sectionType == SectionType::ERROR) - printf("WARNING: One of the section types returned ERROR\n"); + fprintf(stderr, "WARNING: One of the section types returned ERROR\n"); relocation_section_accessor relocs(*curReader, pSec); for (Elf_Xword j = 0; j < relocs.get_entries_num(); j++) { - Elf64_Addr offset; - Elf_Word symbol; - Elf_Word type; + Elf64_Addr offset = 0; + Elf_Word symbol = 0; + Elf_Word type = 0; { - Elf_Sxword addend; + Elf_Sxword addend = 0; relocs.get_entry(j, offset, symbol, type, addend); } @@ -163,7 +163,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath) } // increase section offsets - for (int i = 0; i < sec_num; i++) + for (int32_t i = 0; i < sec_num; i++) { section* pSec = curReader->sections[i]; if (pSec->get_type() == SHT_PROGBITS && @@ -208,7 +208,7 @@ string ZOverlay::GetSourceOutputCode(const std::string& prefix) output += StringHelper::Sprintf(".word 0x%08X\n", reloc->CalcRelocationWord()); } - int offset = ((int)entries.size() * 4) + 20; + size_t offset = (entries.size() * 4) + 20; while (offset % 16 != 12) { @@ -220,11 +220,6 @@ 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 dddae6a747..f43023092a 100644 --- a/tools/ZAPD/ZAPD/Overlays/ZOverlay.h +++ b/tools/ZAPD/ZAPD/Overlays/ZOverlay.h @@ -47,7 +47,7 @@ public: } }; -class ZOverlay : public ZResource +class ZOverlay { public: std::string name; @@ -55,8 +55,7 @@ public: ZOverlay(std::string nName); ~ZOverlay(); static ZOverlay* FromBuild(std::string buildPath, std::string cfgFolderPath); - std::string GetSourceOutputCode(const std::string& prefix) override; - ZResourceType GetResourceType() override; + std::string GetSourceOutputCode(const std::string& prefix); private: std::vector entries; diff --git a/tools/ZAPD/ZAPD/Path.h b/tools/ZAPD/ZAPD/Path.h index 3e45281f6c..a5c073c039 100644 --- a/tools/ZAPD/ZAPD/Path.h +++ b/tools/ZAPD/ZAPD/Path.h @@ -15,10 +15,16 @@ namespace fs = std::experimental::filesystem; class Path { public: + static std::string GetFileName(const std::string& input) + { + std::vector split = StringHelper::Split(input, "/"); + return split[split.size() - 1]; + }; + static std::string GetFileNameWithoutExtension(const std::string& input) { std::vector split = StringHelper::Split(input, "/"); - return split[split.size() - 1].substr(0, input.find_last_of(".")); + return split[split.size() - 1].substr(0, split[split.size() - 1].find_last_of(".")); }; static std::string GetFileNameExtension(const std::string& input) diff --git a/tools/ZAPD/ZAPD/StringHelper.h b/tools/ZAPD/ZAPD/StringHelper.h index b7771fbca4..3d63a749bc 100644 --- a/tools/ZAPD/ZAPD/StringHelper.h +++ b/tools/ZAPD/ZAPD/StringHelper.h @@ -43,6 +43,17 @@ public: return s; } + static std::string Replace(std::string str, const std::string& from, const std::string& to) + { + size_t start_pos = str.find(from); + + if (start_pos == std::string::npos) + return str; + + str.replace(start_pos, from.length(), to); + return str; + } + static bool StartsWith(const std::string& s, const std::string& input) { return s.rfind(input, 0) == 0; @@ -55,7 +66,7 @@ public: static bool EndsWith(const std::string& s, const std::string& input) { - int inputLen = strlen(input.c_str()); + int32_t inputLen = strlen(input.c_str()); return s.rfind(input) == (s.size() - inputLen); } diff --git a/tools/ZAPD/ZAPD/Vec3s.h b/tools/ZAPD/ZAPD/Vec3s.h index 8df39c034d..23e4673b84 100644 --- a/tools/ZAPD/ZAPD/Vec3s.h +++ b/tools/ZAPD/ZAPD/Vec3s.h @@ -6,6 +6,12 @@ struct Vec3s { int16_t x, y, z; + Vec3s() + { + x = 0; + y = 0; + z = 0; + }; Vec3s(int16_t nX, int16_t nY, int16_t nZ) { x = nX; diff --git a/tools/ZAPD/ZAPD/ZAPD.vcxproj b/tools/ZAPD/ZAPD/ZAPD.vcxproj index e270caeb7f..59aaf11473 100644 --- a/tools/ZAPD/ZAPD/ZAPD.vcxproj +++ b/tools/ZAPD/ZAPD/ZAPD.vcxproj @@ -71,8 +71,8 @@ - $(SolutionDir)lib\tinyxml2;$(SolutionDir)lib\elfio;$(SolutionDir)lib\assimp\include;$(SolutionDir)lib\stb;$(ProjectDir);$(IncludePath) - $(SolutionDir)lib\assimp-built;$(LibraryPath) + $(SolutionDir)lib\tinyxml2;$(SolutionDir)lib\libgfxd;$(SolutionDir)lib\elfio;$(SolutionDir)lib\assimp\include;$(SolutionDir)lib\stb;$(ProjectDir);$(IncludePath) + $(SolutionDir)lib\libgfxd;$(SolutionDir)lib\assimp-built;$(LibraryPath) $(IncludePath) @@ -98,6 +98,7 @@ stdcpp17 _CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;USE_ASSIMP;%(PreprocessorDefinitions) EnableFastChecks + stdc11 true @@ -139,14 +140,33 @@ python3 ZAPD/genbuildinfo.py + + + + + + + + + + + + + + + + + + + @@ -184,6 +204,7 @@ python3 ZAPD/genbuildinfo.py + @@ -202,11 +223,15 @@ python3 ZAPD/genbuildinfo.py + + + + @@ -215,17 +240,29 @@ python3 ZAPD/genbuildinfo.py + + + + + + + + + + + + @@ -259,6 +296,7 @@ python3 ZAPD/genbuildinfo.py + diff --git a/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters b/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters index 8f784fd12b..0feff6f205 100644 --- a/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters +++ b/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters @@ -55,6 +55,12 @@ {be9a5be0-ec6a-4200-8e39-bb58c7da7aa8} + + {7ee79d97-c6a8-4e82-93ef-37981f4d7838} + + + {85600275-99fe-491d-8189-bcc3dc1a8903} + @@ -201,6 +207,66 @@ Source Files\Z64 + + Source Files\Z64 + + + Source Files + + + Source Files\Z64 + + + Source Files\Libraries\libgfxd + + + Source Files\Libraries\libgfxd + + + Source Files\Libraries\libgfxd + + + Source Files\Libraries\libgfxd + + + Source Files\Libraries\libgfxd + + + Source Files\Libraries\libgfxd + + + Source Files\Libraries\libgfxd + + + Source Files\Z64 + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64 + + + Source Files\Z64 + @@ -422,6 +488,57 @@ Header Files\Z64 + + Header Files + + + Header Files\Z64 + + + Header Files + + + Header Files\Z64 + + + Header Files\Libraries\libgfxd + + + Header Files\Libraries\libgfxd + + + Header Files\Libraries\libgfxd + + + Header Files\Z64 + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64 + + + Header Files\Z64 + diff --git a/tools/ZAPD/ZAPD/ZAnimation.cpp b/tools/ZAPD/ZAPD/ZAnimation.cpp index 417a26f75c..2eaeee2378 100644 --- a/tools/ZAPD/ZAPD/ZAnimation.cpp +++ b/tools/ZAPD/ZAPD/ZAnimation.cpp @@ -9,7 +9,11 @@ using namespace std; -ZAnimation::ZAnimation() : ZResource() +REGISTER_ZFILENODE(Animation, ZNormalAnimation); +REGISTER_ZFILENODE(PlayerAnimation, ZLinkAnimation); +REGISTER_ZFILENODE(CurveAnimation, ZCurveAnimation); + +ZAnimation::ZAnimation(ZFile* nParent) : ZResource(nParent) { frameCount = 0; } @@ -49,7 +53,7 @@ ZResourceType ZAnimation::GetResourceType() return ZResourceType::Animation; } -ZNormalAnimation::ZNormalAnimation() : ZAnimation() +ZNormalAnimation::ZNormalAnimation(ZFile* nParent) : ZAnimation(nParent) { rotationValues = vector(); rotationIndices = vector(); @@ -63,16 +67,18 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix) string defaultPrefix = name.c_str(); defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables - string headerStr = - StringHelper::Sprintf("{ %i }, %sFrameData, %sJointIndices, %i", frameCount, - defaultPrefix.c_str(), defaultPrefix.c_str(), limit); - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), GetSourceTypeName(), - StringHelper::Sprintf("%s", name.c_str()), headerStr); + string headerStr = StringHelper::Sprintf("\n\t{ %i },\n", frameCount); + headerStr += StringHelper::Sprintf("\t%sFrameData,\n", defaultPrefix.c_str()); + headerStr += StringHelper::Sprintf("\t%sJointIndices,\n", defaultPrefix.c_str()); + headerStr += StringHelper::Sprintf("\t%i\n", limit); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), + GetSourceTypeName(), StringHelper::Sprintf("%s", name.c_str()), + headerStr); string indicesStr = ""; string valuesStr = " "; - const int lineLength = 14; - const int offset = 0; + const uint8_t lineLength = 14; + const uint8_t offset = 0; for (size_t i = 0; i < rotationValues.size(); i++) { @@ -93,12 +99,12 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix) } parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16, - (int)rotationValues.size() * 2, "static s16", + rotationValues.size() * 2, "static s16", StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()), rotationValues.size(), valuesStr); parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16, - (int)rotationIndices.size() * 6, "static JointIndex", + rotationIndices.size() * 6, "static JointIndex", StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()), rotationIndices.size(), indicesStr); } @@ -106,7 +112,7 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix) return ""; } -int ZNormalAnimation::GetRawDataSize() +size_t ZNormalAnimation::GetRawDataSize() { return 16; } @@ -116,17 +122,14 @@ std::string ZNormalAnimation::GetSourceTypeName() return "AnimationHeader"; } -ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, - std::vector nRawData, int rawDataIndex, - const std::string& nRelPath) +void ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZNormalAnimation* anim = new ZNormalAnimation(); - anim->rawData = std::move(nRawData); - anim->rawDataIndex = rawDataIndex; - anim->ParseXML(reader); - anim->ParseRawData(); - - return anim; + rawData = std::move(nRawData); + rawDataIndex = nRawDataIndex; + ParseXML(reader); + ParseRawData(); } void ZNormalAnimation::ParseRawData() @@ -160,7 +163,7 @@ void ZNormalAnimation::ParseRawData() } } -ZLinkAnimation::ZLinkAnimation() : ZAnimation() +ZLinkAnimation::ZLinkAnimation(ZFile* nParent) : ZAnimation(nParent) { segmentAddress = 0; } @@ -174,15 +177,17 @@ std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix) parent->GetDeclarationName( segmentAddress, StringHelper::Sprintf("%sSeg%06X", name.c_str(), segmentAddress)); - string headerStr = StringHelper::Sprintf("{ %i }, 0x%08X", frameCount, segmentAddress); - parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), GetSourceTypeName(), - StringHelper::Sprintf("%s", name.c_str()), headerStr); + string headerStr = + StringHelper::Sprintf("\n\t{ %i },\n\t0x%08X\n", frameCount, segmentAddress); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), + GetSourceTypeName(), StringHelper::Sprintf("%s", name.c_str()), + headerStr); } return ""; } -int ZLinkAnimation::GetRawDataSize() +size_t ZLinkAnimation::GetRawDataSize() { return 8; } @@ -192,17 +197,14 @@ std::string ZLinkAnimation::GetSourceTypeName() return "LinkAnimationHeader"; } -ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, - std::vector nRawData, int rawDataIndex, - const std::string& nRelPath) +void ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZLinkAnimation* anim = new ZLinkAnimation(); - anim->rawData = std::move(nRawData); - anim->rawDataIndex = rawDataIndex; - anim->ParseXML(reader); - anim->ParseRawData(); - - return anim; + rawData = std::move(nRawData); + rawDataIndex = nRawDataIndex; + ParseXML(reader); + ParseRawData(); } void ZLinkAnimation::ParseRawData() @@ -210,8 +212,6 @@ void ZLinkAnimation::ParseRawData() ZAnimation::ParseRawData(); const uint8_t* data = rawData.data(); - - // segmentAddress = GETSEGOFFSET(BitConverter::ToInt32BE(data, rawDataIndex + 4)); segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4)); } @@ -250,56 +250,8 @@ std::string TransformData::GetSourceTypeName() return "TransformData"; } -ZCurveAnimation::ZCurveAnimation(tinyxml2::XMLElement* reader, const std::vector& nRawData, - int nRawDataIndex, ZFile* nParent) +ZCurveAnimation::ZCurveAnimation(ZFile* nParent) : ZAnimation(nParent) { - rawData.assign(nRawData.begin(), nRawData.end()); - rawDataIndex = nRawDataIndex; - parent = nParent; - - ParseXML(reader); - ParseRawData(); - - skel = new ZSkeleton(ZSkeletonType::Curve, ZLimbType::Curve, "CurveAnim", nRawData, - Seg2Filespace(skelOffset, parent->baseAddress), nParent); - - size_t transformDataSize = 0; - size_t copyValuesSize = 0; - if (refIndex != 0) - { - uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress); - for (size_t i = 0; i < 3 * 3 * skel->GetLimbCount(); i++) - { - uint8_t ref = BitConverter::ToUInt8BE(nRawData, refIndexOffset + i); - if (ref == 0) - { - copyValuesSize++; - } - else - { - transformDataSize += ref; - } - refIndexArr.emplace_back(ref); - } - } - - if (transformData != 0) - { - uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress); - for (size_t i = 0; i < transformDataSize; i++) - { - transformDataArr.emplace_back(parent, nRawData, transformDataOffset, i); - } - } - - if (copyValues != 0) - { - uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress); - for (size_t i = 0; i < copyValuesSize; i++) - { - copyValuesArr.emplace_back(BitConverter::ToInt16BE(nRawData, copyValuesOffset + i * 2)); - } - } } ZCurveAnimation::~ZCurveAnimation() @@ -314,9 +266,10 @@ void ZCurveAnimation::ParseXML(tinyxml2::XMLElement* reader) const char* skelOffsetXml = reader->Attribute("SkelOffset"); if (skelOffsetXml == nullptr) { - throw std::runtime_error( + throw std::runtime_error(StringHelper::Sprintf( "ZCurveAnimation::ParseXML: Fatal error in '%s'. Missing 'SkelOffset' attribute in " - "xml. You need to provide the offset of the curve skeleton."); + "ZCurveAnimation. You need to provide the offset of the curve skeleton.", + name.c_str())); } skelOffset = std::strtoul(skelOffsetXml, nullptr, 0); } @@ -332,19 +285,50 @@ void ZCurveAnimation::ParseRawData() unk_10 = BitConverter::ToInt16BE(rawData, rawDataIndex + 14); } -ZCurveAnimation* ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, - const std::vector& nRawData, - int nRawDataIndex, std::string nRelPath, - ZFile* nParent) +void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZCurveAnimation* curve = new ZCurveAnimation(reader, nRawData, nRawDataIndex, nParent); - curve->relativePath = std::move(nRelPath); + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); - curve->parent->AddDeclaration(curve->rawDataIndex, DeclarationAlignment::Align16, - curve->GetRawDataSize(), curve->GetSourceTypeName(), curve->name, - ""); + skel = new ZSkeleton(ZSkeletonType::Curve, ZLimbType::Curve, "CurveAnim", nRawData, + Seg2Filespace(skelOffset, parent->baseAddress), parent); - return curve; + size_t transformDataSize = 0; + size_t copyValuesSize = 0; + if (refIndex != 0) + { + uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress); + for (size_t i = 0; i < 3 * 3 * skel->GetLimbCount(); i++) + { + uint8_t ref = BitConverter::ToUInt8BE(nRawData, refIndexOffset + i); + if (ref == 0) + copyValuesSize++; + else + transformDataSize += ref; + + refIndexArr.emplace_back(ref); + } + } + + if (transformData != 0) + { + uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress); + + for (size_t i = 0; i < transformDataSize; i++) + transformDataArr.emplace_back(parent, nRawData, transformDataOffset, i); + } + + if (copyValues != 0) + { + uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress); + + for (size_t i = 0; i < copyValuesSize; i++) + copyValuesArr.emplace_back(BitConverter::ToInt16BE(nRawData, copyValuesOffset + i * 2)); + } + + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(), + GetSourceTypeName(), name, ""); } void ZCurveAnimation::PreGenValues(const std::string& prefix) @@ -443,7 +427,7 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix) } } -int ZCurveAnimation::GetRawDataSize() +size_t ZCurveAnimation::GetRawDataSize() { return 0x10; } diff --git a/tools/ZAPD/ZAPD/ZAnimation.h b/tools/ZAPD/ZAPD/ZAnimation.h index 2e69d7db04..e6dc1e23f3 100644 --- a/tools/ZAPD/ZAPD/ZAnimation.h +++ b/tools/ZAPD/ZAPD/ZAnimation.h @@ -26,13 +26,13 @@ class ZAnimation : public ZResource public: int16_t frameCount; - ZAnimation(); + ZAnimation(ZFile* nParent); std::string GetSourceOutputCode(const std::string& prefix) override; ZResourceType GetResourceType() override; protected: - virtual void ParseRawData() override; + void ParseRawData() override; void Save(const std::string& outFolder) override; void ParseXML(tinyxml2::XMLElement* reader) override; }; @@ -46,16 +46,14 @@ public: uint32_t rotationIndicesSeg; int16_t limit; - ZNormalAnimation(); + ZNormalAnimation(ZFile* nParent); std::string GetSourceOutputCode(const std::string& prefix) override; - int GetRawDataSize() override; - + size_t GetRawDataSize() override; std::string GetSourceTypeName() override; - static ZNormalAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, - std::vector nRawData, int rawDataIndex, - const std::string& nRelPath); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; protected: virtual void ParseRawData() override; @@ -64,18 +62,16 @@ protected: class ZLinkAnimation : public ZAnimation { public: - uint32_t segmentAddress; + segptr_t segmentAddress; - ZLinkAnimation(); + ZLinkAnimation(ZFile* nParent); std::string GetSourceOutputCode(const std::string& prefix) override; - int GetRawDataSize() override; - + size_t GetRawDataSize() override; std::string GetSourceTypeName() override; - static ZLinkAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, - std::vector nRawData, int rawDataIndex, - const std::string& nRelPath); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; protected: virtual void ParseRawData() override; @@ -132,18 +128,16 @@ protected: std::vector copyValuesArr; public: - ZCurveAnimation() = default; - ZCurveAnimation(tinyxml2::XMLElement* reader, const std::vector& nRawData, - int nRawDataIndex, ZFile* nParent); + ZCurveAnimation(); + ZCurveAnimation(ZFile* nParent); ~ZCurveAnimation(); void ParseXML(tinyxml2::XMLElement* reader) override; void ParseRawData() override; - static ZCurveAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, - const std::vector& nRawData, int nRawDataIndex, - std::string nRelPath, ZFile* nParent); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; void PreGenValues(const std::string& prefix); - int GetRawDataSize() override; + size_t GetRawDataSize() override; std::string GetSourceOutputCode(const std::string& prefix) override; std::string GetSourceTypeName() override; diff --git a/tools/ZAPD/ZAPD/ZArray.cpp b/tools/ZAPD/ZAPD/ZArray.cpp index 74fa9c5af7..ac9561b21a 100644 --- a/tools/ZAPD/ZAPD/ZArray.cpp +++ b/tools/ZAPD/ZAPD/ZArray.cpp @@ -3,8 +3,16 @@ #include "StringHelper.h" #include "ZFile.h" -ZArray::ZArray() +REGISTER_ZFILENODE(Array, ZArray); + +ZArray::ZArray(ZFile* nParent) : ZResource(nParent) { + canHaveInner = true; +} + +ZArray::~ZArray() +{ + delete testFile; } void ZArray::ParseXML(tinyxml2::XMLElement* reader) @@ -13,7 +21,7 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader) arrayCnt = reader->IntAttribute("Count", 0); testFile = new ZFile(ZFileMode::Extract, reader, Globals::Instance->baseRomPath, "", - parent->GetName(), true); + parent->GetName(), "ZArray subfile", true); } // TODO: This is a bit hacky, but until we refactor how ZFile parses the XML, it'll have to do. @@ -22,12 +30,11 @@ 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"); - } + throw std::runtime_error( + StringHelper::Sprintf("Error! Array needs at least one sub-element.\n")); ZResource* res = testFile->resources[0]; - int resSize = res->GetRawDataSize(); + size_t resSize = res->GetRawDataSize(); if (!res->DoesSupportArray()) { @@ -36,9 +43,9 @@ std::string ZArray::GetSourceOutputCode(const std::string& prefix) res->GetName().c_str())); } - for (int i = 0; i < arrayCnt; i++) + for (size_t i = 0; i < arrayCnt; i++) { - int childIndex = rawDataIndex + (i * resSize); + size_t childIndex = rawDataIndex + (i * resSize); res->SetRawDataIndex(childIndex); res->ParseRawData(); std::string test = res->GetSourceOutputCode(""); @@ -56,20 +63,16 @@ std::string ZArray::GetSourceOutputCode(const std::string& prefix) return ""; } -int ZArray::GetRawDataSize() +size_t 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) +void ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZArray* arr = new ZArray(); - arr->rawData = nRawData; - arr->rawDataIndex = rawDataIndex; - arr->parent = nParent; - arr->ParseXML(reader); + rawData = nRawData; + rawDataIndex = nRawDataIndex; + ParseXML(reader); // arr->ParseRawData(); - - return arr; } diff --git a/tools/ZAPD/ZAPD/ZArray.h b/tools/ZAPD/ZAPD/ZArray.h index 8e0092325c..ebad2a4bb2 100644 --- a/tools/ZAPD/ZAPD/ZArray.h +++ b/tools/ZAPD/ZAPD/ZArray.h @@ -9,19 +9,19 @@ class ZArray : public ZResource { public: - ZArray(); + ZArray(ZFile* nParent); + ~ZArray(); void ParseXML(tinyxml2::XMLElement* reader) override; std::string GetSourceOutputCode(const std::string& prefix) override; - int GetRawDataSize() override; + size_t GetRawDataSize() override; - static ZArray* ExtractFromXML(tinyxml2::XMLElement* reader, - const std::vector& nRawData, const int rawDataIndex, - const std::string& nRelPath, ZFile* nParent); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; protected: - int arrayCnt; + size_t arrayCnt; ZFile* testFile; - // void ParseRawData(const std::vector& data, const int offset); + // void ParseRawData(const std::vector& data, const int32_t offset); }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZBackground.cpp b/tools/ZAPD/ZAPD/ZBackground.cpp new file mode 100644 index 0000000000..02ff4243df --- /dev/null +++ b/tools/ZAPD/ZAPD/ZBackground.cpp @@ -0,0 +1,209 @@ +#include "ZBackground.h" +#include "BitConverter.h" +#include "File.h" +#include "Globals.h" +#include "Path.h" +#include "StringHelper.h" +#include "ZFile.h" + +REGISTER_ZFILENODE(Background, ZBackground); + +#define JPEG_MARKER 0xFFD8FFE0 +#define MARKER_DQT 0xFFDB + +ZBackground::ZBackground(ZFile* nParent) : ZResource(nParent) +{ +} + +ZBackground::ZBackground(const std::string& prefix, const std::vector& nRawData, + uint32_t nRawDataIndex, ZFile* nParent) + : ZResource(nParent) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + name = GetDefaultName(prefix.c_str(), rawDataIndex); + outName = name; + + ParseRawData(); +} + +void ZBackground::ParseRawData() +{ + ZResource::ParseRawData(); + + size_t i = 0; + while (true) + { + uint8_t val = rawData.at(rawDataIndex + i); + data.push_back(val); + + if (BitConverter::ToUInt16BE(rawData, rawDataIndex + i) == 0xFFD9) + { + data.push_back(rawData.at(rawDataIndex + i + 1)); + break; + } + + i++; + } +} + +void ZBackground::ParseBinaryFile(const std::string& inFolder, bool appendOutName) +{ + fs::path filepath(inFolder); + if (appendOutName) + { + filepath = filepath / (outName + "." + GetExternalExtension()); + } + data = File::ReadAllBytes(filepath.string()); + + // Add padding. + data.insert(data.end(), GetRawDataSize() - data.size(), 0x00); + CheckValidJpeg(filepath.generic_string()); +} + +void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + uint32_t nRawDataIndex, const std::string& nRelPath) +{ + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); + DeclareVar("", ""); +} + +void ZBackground::CheckValidJpeg(const std::string& filepath) +{ + std::string filename = outName; + if (filepath != "") + { + filename = filepath; + } + + uint32_t jpegMarker = BitConverter::ToUInt32BE(data, 0); + if (jpegMarker != JPEG_MARKER) + { + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t Missing jpeg marker at the beginning of file: '%s'.\n" + "\t The game will skip this jpeg.\n", + filename.c_str()); + } + if (data.at(6) != 'J' || data.at(7) != 'F' || data.at(8) != 'I' || data.at(9) != 'F' || + data.at(10) != '\0') + { + std::string jfifIdentifier(data.begin() + 6, data.begin() + 6 + 5); + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t Missing 'JFIF' identifier. File: '%s'.\n" + "\t This image may be corrupted or not be a jpeg iamge.\n" + "\t The identifier found was '%s'.\n", + filename.c_str(), jfifIdentifier.c_str()); + } + uint8_t majorVersion = data.at(11); + uint8_t minorVersion = data.at(12); + if (majorVersion != 0x01 || minorVersion != 0x01) + { + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t Wrong JFIF version '%i.%02i'. File: '%s'.\n" + "\t The expected version is '1.01'. The game may not be able to decode this image " + "properly.\n", + majorVersion, minorVersion, filename.c_str()); + } + if (BitConverter::ToUInt16BE(data, 20) != MARKER_DQT) + { + // This may happen when creating a custom image with Exif, XMP, thumbnail, progressive, etc. + // enabled. + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t There seems to be extra data before the image data in file: '%s'.\n" + "\t The game may not be able to decode this image properly.\n", + filename.c_str()); + } + if (data.size() > GetRawDataSize()) + { + fprintf(stderr, + "ZBackground::CheckValidJpeg: Warning.\n" + "\t The image is bigger than the screen buffer. File: '%s'.\n" + "\t Image size: %zu bytes.\n" + "\t Screen buffer size: %zu bytes.\n", + filename.c_str(), data.size(), GetRawDataSize()); + } +} + +size_t ZBackground::GetRawDataSize() +{ + // Jpgs use the whole sceen buffer, which is a u16 matrix. + return Globals::Instance->cfg.bgScreenHeight * Globals::Instance->cfg.bgScreenWidth * 2; +} + +void ZBackground::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + + if (name == "") + auxName = GetDefaultName(prefix, rawDataIndex); + + parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(), + GetSourceTypeName(), auxName, 0, bodyStr); +} + +bool ZBackground::IsExternalResource() +{ + return true; +} + +std::string ZBackground::GetExternalExtension() +{ + return "jpg"; +} + +void ZBackground::Save(const std::string& outFolder) +{ + fs::path folder(outFolder); + fs::path filepath = folder / (outName + "." + GetExternalExtension()); + File::WriteAllBytes(filepath.string(), data); +} + +std::string ZBackground::GetBodySourceCode() +{ + std::string bodyStr = " "; + + for (size_t i = 0; i < data.size() / 8; ++i) + { + bodyStr += StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(data, i * 8)); + + if (i % 8 == 7) + bodyStr += "\n "; + } + + bodyStr += "\n"; + + return bodyStr; +} + +std::string ZBackground::GetSourceOutputCode(const std::string& prefix) +{ + std::string bodyStr = GetBodySourceCode(); + + Declaration* decl = parent->GetDeclaration(rawDataIndex); + + if (decl == nullptr) + DeclareVar(prefix, bodyStr); + else + decl->text = bodyStr; + + return ""; +} + +std::string ZBackground::GetDefaultName(const std::string& prefix, uint32_t address) +{ + return StringHelper::Sprintf("%sBackground_%06X", prefix.c_str(), address); +} + +std::string ZBackground::GetSourceTypeName() +{ + return "u64"; +} + +ZResourceType ZBackground::GetResourceType() +{ + return ZResourceType::Background; +} diff --git a/tools/ZAPD/ZAPD/ZBackground.h b/tools/ZAPD/ZAPD/ZBackground.h new file mode 100644 index 0000000000..55cbf2b613 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZBackground.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include +#include "ZResource.h" + +class ZBackground : public ZResource +{ +protected: + std::vector data; + +public: + ZBackground(ZFile* nParent); + ZBackground(const std::string& prefix, const std::vector& nRawData, + uint32_t nRawDataIndex, ZFile* nParent); + void ParseRawData() override; + void ParseBinaryFile(const std::string& inFolder, bool appendOutName); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + uint32_t nRawDataIndex, const std::string& nRelPath) override; + + void CheckValidJpeg(const std::string& filepath); + + size_t GetRawDataSize() override; + + void DeclareVar(const std::string& prefix, const std::string& bodyStr); + + bool IsExternalResource() override; + std::string GetExternalExtension() override; + void Save(const std::string& outFolder) override; + + std::string GetBodySourceCode(); + std::string GetSourceOutputCode(const std::string& prefix) override; + static std::string GetDefaultName(const std::string& prefix, uint32_t address); + + std::string GetSourceTypeName() override; + ZResourceType GetResourceType() override; +}; diff --git a/tools/ZAPD/ZAPD/ZBlob.cpp b/tools/ZAPD/ZAPD/ZBlob.cpp index fb39bd373a..53cd0065a5 100644 --- a/tools/ZAPD/ZAPD/ZBlob.cpp +++ b/tools/ZAPD/ZAPD/ZBlob.cpp @@ -8,12 +8,15 @@ using namespace tinyxml2; using namespace std; -ZBlob::ZBlob() : ZResource() +REGISTER_ZFILENODE(Blob, ZBlob); + +ZBlob::ZBlob(ZFile* nParent) : ZResource(nParent) { } -ZBlob::ZBlob(const std::vector& nRawData, int nRawDataIndex, int size, std::string nName) - : ZBlob() +ZBlob::ZBlob(const std::vector& nRawData, uint32_t nRawDataIndex, size_t size, + std::string nName, ZFile* nParent) + : ZBlob(nParent) { rawDataIndex = nRawDataIndex; rawData = @@ -21,25 +24,22 @@ ZBlob::ZBlob(const std::vector& nRawData, int nRawDataIndex, int size, name = std::move(nName); } -ZBlob* ZBlob::ExtractFromXML(XMLElement* reader, const vector& nRawData, int nRawDataIndex, - string nRelPath) +void ZBlob::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZBlob* blob = new ZBlob(); + rawDataIndex = nRawDataIndex; - blob->rawDataIndex = nRawDataIndex; - - blob->ParseXML(reader); - int size = strtol(reader->Attribute("Size"), NULL, 16); - blob->rawData = vector(nRawData.data() + blob->rawDataIndex, - nRawData.data() + blob->rawDataIndex + size); - blob->relativePath = std::move(nRelPath); - - return blob; + ParseXML(reader); + long size = strtol(reader->Attribute("Size"), NULL, 16); + rawData = + vector(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size); + relativePath = std::move(nRelPath); } +// Build Source File Mode ZBlob* ZBlob::BuildFromXML(XMLElement* reader, const std::string& inFolder, bool readFile) { - ZBlob* blob = new ZBlob(); + ZBlob* blob = new ZBlob(nullptr); blob->ParseXML(reader); @@ -51,7 +51,7 @@ ZBlob* ZBlob::BuildFromXML(XMLElement* reader, const std::string& inFolder, bool ZBlob* ZBlob::FromFile(const std::string& filePath) { - ZBlob* blob = new ZBlob(); + ZBlob* blob = new ZBlob(nullptr); blob->name = StringHelper::Split(Path::GetFileNameWithoutExtension(filePath), ".")[0]; blob->rawData = File::ReadAllBytes(filePath); @@ -61,12 +61,11 @@ ZBlob* ZBlob::FromFile(const std::string& filePath) string ZBlob::GetSourceOutputCode(const std::string& prefix) { sourceOutput = ""; - // sourceOutput += StringHelper::Sprintf("u8 %s_%s[] = \n{\n", prefix.c_str(), name.c_str()); - for (uint32_t i = 0; i < rawData.size(); i += 1) + for (size_t i = 0; i < rawData.size(); i += 1) { if (i % 16 == 0) - sourceOutput += "\t"; + sourceOutput += " "; sourceOutput += StringHelper::Sprintf("0x%02X, ", rawData[i]); @@ -75,10 +74,10 @@ string ZBlob::GetSourceOutputCode(const std::string& prefix) } // Ensure there's always a trailing line feed to prevent dumb warnings. + // Please don't remove this line, unless you somehow made a way to prevent + // that warning when building the OoT repo. sourceOutput += "\n"; - // sourceOutput += "};\n"; - return sourceOutput; } @@ -89,7 +88,6 @@ string ZBlob::GetSourceOutputHeader(const std::string& prefix) void ZBlob::Save(const std::string& outFolder) { - // printf("NAME = %s\n", name.c_str()); File::WriteAllBytes(outFolder + "/" + name + ".bin", rawData); } diff --git a/tools/ZAPD/ZAPD/ZBlob.h b/tools/ZAPD/ZAPD/ZBlob.h index 6b5508846f..dda3e4e0a7 100644 --- a/tools/ZAPD/ZAPD/ZBlob.h +++ b/tools/ZAPD/ZAPD/ZBlob.h @@ -6,10 +6,14 @@ class ZBlob : public ZResource { public: - ZBlob(const std::vector& nRawData, int rawDataIndex, int size, std::string nName); + ZBlob(ZFile* nParent); + ZBlob(const std::vector& nRawData, uint32_t rawDataIndex, size_t size, + std::string nName, ZFile* nParent); + + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, + const std::string& nRelPath) override; // Extract Mode - 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); @@ -20,7 +24,4 @@ public: 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 bb3144a94a..118ef797fb 100644 --- a/tools/ZAPD/ZAPD/ZCollision.cpp +++ b/tools/ZAPD/ZAPD/ZCollision.cpp @@ -7,12 +7,33 @@ using namespace std; -ZCollisionHeader::ZCollisionHeader() +REGISTER_ZFILENODE(Collision, ZCollisionHeader); + +ZCollisionHeader::ZCollisionHeader(ZFile* nParent) : ZResource(nParent) { } -ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, - const std::vector& rawData, int rawDataIndex) +ZCollisionHeader::~ZCollisionHeader() +{ + for (WaterBoxHeader* waterBox : waterBoxes) + delete waterBox; + + delete camData; +} + +ZResourceType ZCollisionHeader::GetResourceType() +{ + return ZResourceType::CollisionHeader; +} + +void ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) +{ + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); +} + +void ZCollisionHeader::ParseRawData() { const uint8_t* data = rawData.data(); @@ -24,80 +45,71 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, absMaxY = BitConverter::ToInt16BE(data, rawDataIndex + 8); absMaxZ = BitConverter::ToInt16BE(data, rawDataIndex + 10); - numVerts = BitConverter::ToInt16BE(data, rawDataIndex + 12); + numVerts = BitConverter::ToUInt16BE(data, rawDataIndex + 12); vtxAddress = BitConverter::ToInt32BE(data, rawDataIndex + 16); - numPolygons = BitConverter::ToInt16BE(data, rawDataIndex + 20); + numPolygons = BitConverter::ToUInt16BE(data, rawDataIndex + 20); polyAddress = BitConverter::ToInt32BE(data, rawDataIndex + 24); polyTypeDefAddress = BitConverter::ToInt32BE(data, rawDataIndex + 28); camDataAddress = BitConverter::ToInt32BE(data, rawDataIndex + 32); - numWaterBoxes = BitConverter::ToInt16BE(data, rawDataIndex + 36); + numWaterBoxes = BitConverter::ToUInt16BE(data, rawDataIndex + 36); waterBoxAddress = BitConverter::ToInt32BE(data, rawDataIndex + 40); - uint32_t vtxSegmentOffset = Seg2Filespace(vtxAddress, parent->baseAddress); - uint32_t polySegmentOffset = Seg2Filespace(polyAddress, parent->baseAddress); - uint32_t polyTypeDefSegmentOffset = Seg2Filespace(polyTypeDefAddress, parent->baseAddress); - uint32_t camDataSegmentOffset = Seg2Filespace(camDataAddress, parent->baseAddress); - uint32_t waterBoxSegmentOffset = Seg2Filespace(waterBoxAddress, parent->baseAddress); + vtxSegmentOffset = Seg2Filespace(vtxAddress, parent->baseAddress); + polySegmentOffset = Seg2Filespace(polyAddress, parent->baseAddress); + polyTypeDefSegmentOffset = Seg2Filespace(polyTypeDefAddress, parent->baseAddress); + camDataSegmentOffset = Seg2Filespace(camDataAddress, parent->baseAddress); + waterBoxSegmentOffset = Seg2Filespace(waterBoxAddress, parent->baseAddress); + + vertices.reserve(numVerts); + polygons.reserve(numPolygons); - // HOTSPOT for (uint16_t i = 0; i < numVerts; i++) - vertices.push_back(new VertexEntry(rawData, vtxSegmentOffset + (i * 6))); + vertices.push_back(VertexEntry(rawData, vtxSegmentOffset + (i * 6))); - // HOTSPOT for (uint16_t i = 0; i < numPolygons; i++) - polygons.push_back(new PolygonEntry(rawData, polySegmentOffset + (i * 16))); + polygons.push_back(PolygonEntry(rawData, polySegmentOffset + (i * 16))); uint16_t highestPolyType = 0; - for (PolygonEntry* poly : polygons) + for (PolygonEntry poly : polygons) { - if (poly->type > highestPolyType) - highestPolyType = poly->type; + if (poly.type > highestPolyType) + highestPolyType = poly.type; } - // if (highestPolyType > 0) - { - for (uint16_t i = 0; i < highestPolyType + 1; i++) - polygonTypes.push_back( - BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8))); - } - // else - //{ - // int polyTypesSize = abs(polyTypeDefSegmentOffset - camDataSegmentOffset) / 8; - - // for (int i = 0; i < polyTypesSize; i++) - // polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8))); - //} + for (uint16_t i = 0; i < highestPolyType + 1; i++) + polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8))); if (camDataAddress != 0) - camData = new CameraDataList(parent, prefix, rawData, camDataSegmentOffset, + camData = new CameraDataList(parent, name, rawData, camDataSegmentOffset, polyTypeDefSegmentOffset, polygonTypes.size()); - for (int i = 0; i < numWaterBoxes; i++) + for (uint16_t i = 0; i < numWaterBoxes; i++) waterBoxes.push_back(new WaterBoxHeader( rawData, waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16)))); string declaration = ""; - char line[2048]; if (waterBoxes.size() > 0) { for (size_t i = 0; i < waterBoxes.size(); i++) { - sprintf(line, " { %i, %i, %i, %i, %i, 0x%08X },\n", waterBoxes[i]->xMin, - waterBoxes[i]->ySurface, waterBoxes[i]->zMin, waterBoxes[i]->xLength, - waterBoxes[i]->zLength, waterBoxes[i]->properties); - declaration += line; + declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %i, 0x%08X },", + waterBoxes[i]->xMin, waterBoxes[i]->ySurface, + waterBoxes[i]->zMin, waterBoxes[i]->xLength, + waterBoxes[i]->zLength, waterBoxes[i]->properties); + if (i + 1 < waterBoxes.size()) + declaration += "\n"; } } if (waterBoxAddress != 0) parent->AddDeclarationArray( waterBoxSegmentOffset, DeclarationAlignment::None, 16 * waterBoxes.size(), "WaterBox", - StringHelper::Sprintf("%s_waterBoxes_%08X", prefix.c_str(), waterBoxSegmentOffset), 0, + StringHelper::Sprintf("%s_waterBoxes_%06X", name.c_str(), waterBoxSegmentOffset), 0, declaration); if (polygons.size() > 0) @@ -106,12 +118,12 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, for (size_t i = 0; i < polygons.size(); i++) { - sprintf( - line, " { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },\n", - (uint16_t)polygons[i]->type, (uint16_t)polygons[i]->vtxA, - (uint16_t)polygons[i]->vtxB, (uint16_t)polygons[i]->vtxC, (uint16_t)polygons[i]->a, - (uint16_t)polygons[i]->b, (uint16_t)polygons[i]->c, (uint16_t)polygons[i]->d); - declaration += line; + declaration += StringHelper::Sprintf( + "\t{ 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },", + polygons[i].type, polygons[i].vtxA, polygons[i].vtxB, polygons[i].vtxC, + polygons[i].a, polygons[i].b, polygons[i].c, polygons[i].d); + if (i + 1 < polygons.size()) + declaration += "\n"; } if (polyAddress != 0) @@ -119,7 +131,7 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, parent->AddDeclarationArray( polySegmentOffset, DeclarationAlignment::None, polygons.size() * 16, "CollisionPoly", - StringHelper::Sprintf("%s_polygons_%08X", prefix.c_str(), polySegmentOffset), 0, + StringHelper::Sprintf("%s_polygons_%08X", name.c_str(), polySegmentOffset), 0, declaration); } } @@ -127,7 +139,7 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, declaration = ""; for (size_t i = 0; i < polygonTypes.size(); i++) { - declaration += StringHelper::Sprintf(" { 0x%08lX, 0x%08lX },", polygonTypes[i] >> 32, + declaration += StringHelper::Sprintf("\t{ 0x%08lX, 0x%08lX },", polygonTypes[i] >> 32, polygonTypes[i] & 0xFFFFFFFF); if (i < polygonTypes.size() - 1) @@ -138,8 +150,8 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, parent->AddDeclarationArray( polyTypeDefSegmentOffset, DeclarationAlignment::None, polygonTypes.size() * 8, "SurfaceType", - StringHelper::Sprintf("%s_surfaceType_%08X", prefix.c_str(), polyTypeDefSegmentOffset), - 0, declaration); + StringHelper::Sprintf("%s_surfaceType_%08X", name.c_str(), polyTypeDefSegmentOffset), 0, + declaration); declaration = ""; @@ -149,8 +161,8 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, for (size_t i = 0; i < vertices.size(); i++) { - declaration += StringHelper::Sprintf(" { %i, %i, %i },", vertices[i]->x, - vertices[i]->y, vertices[i]->z); + declaration += StringHelper::Sprintf("\t{ %6i, %6i, %6i },", vertices[i].x, + vertices[i].y, vertices[i].z); if (i < vertices.size() - 1) declaration += "\n"; @@ -159,7 +171,7 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, if (vtxAddress != 0) parent->AddDeclarationArray( vtxSegmentOffset, DeclarationAlignment::None, vertices.size() * 6, "Vec3s", - StringHelper::Sprintf("%s_vtx_%08X", prefix.c_str(), vtxSegmentOffset), 0, + StringHelper::Sprintf("%s_vtx_%08X", name.c_str(), vtxSegmentOffset), 0, declaration); declaration = ""; @@ -169,7 +181,7 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, char waterBoxStr[2048]; if (waterBoxAddress != 0) - sprintf(waterBoxStr, "%s_waterBoxes_%08X", prefix.c_str(), waterBoxSegmentOffset); + sprintf(waterBoxStr, "%s_waterBoxes_%06X", name.c_str(), waterBoxSegmentOffset); else sprintf(waterBoxStr, "NULL"); @@ -180,56 +192,31 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, declaration += StringHelper::Sprintf( " %i,\n %s_vtx_%08X,\n %i,\n %s_polygons_%08X,\n %s_surfaceType_%08X,\n " - "%s_camDataList_%08X,\n %i,\n %s\n", - numVerts, prefix.c_str(), vtxSegmentOffset, numPolygons, prefix.c_str(), polySegmentOffset, - prefix.c_str(), polyTypeDefSegmentOffset, prefix.c_str(), camDataSegmentOffset, - numWaterBoxes, waterBoxStr); + "%s_camDataList_%08X,\n %i,\n %s\n", + numVerts, name.c_str(), vtxSegmentOffset, numPolygons, name.c_str(), polySegmentOffset, + name.c_str(), polyTypeDefSegmentOffset, name.c_str(), camDataSegmentOffset, numWaterBoxes, + waterBoxStr); parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, DeclarationPadding::Pad16, 44, "CollisionHeader", - StringHelper::Sprintf("%s", prefix.c_str(), rawDataIndex), declaration); + StringHelper::Sprintf("%s", name.c_str(), rawDataIndex), declaration); } -ZCollisionHeader::~ZCollisionHeader() -{ - for (VertexEntry* vtx : vertices) - delete vtx; - - for (PolygonEntry* poly : polygons) - delete poly; - - for (WaterBoxHeader* waterBox : waterBoxes) - delete waterBox; -} - -ZResourceType ZCollisionHeader::GetResourceType() -{ - return ZResourceType::CollisionHeader; -} - -ZCollisionHeader* ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader, - vector nRawData, int rawDataIndex) -{ - ZCollisionHeader* col = new ZCollisionHeader(); - - return col; -} - -PolygonEntry::PolygonEntry(const std::vector& rawData, int rawDataIndex) +PolygonEntry::PolygonEntry(const std::vector& rawData, uint32_t rawDataIndex) { const uint8_t* data = rawData.data(); - type = BitConverter::ToInt16BE(data, rawDataIndex + 0); - vtxA = BitConverter::ToInt16BE(data, rawDataIndex + 2); - vtxB = BitConverter::ToInt16BE(data, rawDataIndex + 4); - vtxC = BitConverter::ToInt16BE(data, rawDataIndex + 6); - a = BitConverter::ToInt16BE(data, rawDataIndex + 8); - b = BitConverter::ToInt16BE(data, rawDataIndex + 10); - c = BitConverter::ToInt16BE(data, rawDataIndex + 12); - d = BitConverter::ToInt16BE(data, rawDataIndex + 14); + type = BitConverter::ToUInt16BE(data, rawDataIndex + 0); + vtxA = BitConverter::ToUInt16BE(data, rawDataIndex + 2); + vtxB = BitConverter::ToUInt16BE(data, rawDataIndex + 4); + vtxC = BitConverter::ToUInt16BE(data, rawDataIndex + 6); + a = BitConverter::ToUInt16BE(data, rawDataIndex + 8); + b = BitConverter::ToUInt16BE(data, rawDataIndex + 10); + c = BitConverter::ToUInt16BE(data, rawDataIndex + 12); + d = BitConverter::ToUInt16BE(data, rawDataIndex + 14); } -VertexEntry::VertexEntry(const std::vector& rawData, int rawDataIndex) +VertexEntry::VertexEntry(const std::vector& rawData, uint32_t rawDataIndex) { const uint8_t* data = rawData.data(); @@ -238,7 +225,7 @@ VertexEntry::VertexEntry(const std::vector& rawData, int rawDataIndex) z = BitConverter::ToInt16BE(data, rawDataIndex + 4); } -WaterBoxHeader::WaterBoxHeader(const std::vector& rawData, int rawDataIndex) +WaterBoxHeader::WaterBoxHeader(const std::vector& rawData, uint32_t rawDataIndex) { const uint8_t* data = rawData.data(); @@ -247,27 +234,23 @@ WaterBoxHeader::WaterBoxHeader(const std::vector& rawData, int rawDataI zMin = BitConverter::ToInt16BE(data, rawDataIndex + 4); xLength = BitConverter::ToInt16BE(data, rawDataIndex + 6); zLength = BitConverter::ToInt16BE(data, rawDataIndex + 8); + if (Globals::Instance->game == ZGame::OOT_SW97) - { properties = BitConverter::ToInt16BE(data, rawDataIndex + 10); - } else - { properties = BitConverter::ToInt32BE(data, rawDataIndex + 12); - } } CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, - const std::vector& rawData, int rawDataIndex, - int polyTypeDefSegmentOffset, int polygonTypesCnt) + const std::vector& rawData, uint32_t rawDataIndex, + uint32_t polyTypeDefSegmentOffset, uint32_t polygonTypesCnt) { string declaration = ""; // Parse CameraDataEntries - int numElements = abs(polyTypeDefSegmentOffset - (rawDataIndex)) / 8; - // int numElements = polygonTypesCnt; + int32_t numElements = (polyTypeDefSegmentOffset - rawDataIndex) / 8; uint32_t cameraPosDataSeg = rawDataIndex; - for (int i = 0; i < numElements; i++) + for (int32_t i = 0; i < numElements; i++) { CameraDataEntry* entry = new CameraDataEntry(); @@ -289,7 +272,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, entries.push_back(entry); } - // setting cameraPosDataAddr to rawDataIndex give a pos list length of 0 + // Setting cameraPosDataAddr to rawDataIndex give a pos list length of 0 uint32_t cameraPosDataOffset = cameraPosDataSeg & 0xFFFFFF; for (size_t i = 0; i < entries.size(); i++) { @@ -297,7 +280,8 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, if (entries[i]->cameraPosDataSeg != 0) { - int index = ((entries[i]->cameraPosDataSeg & 0x00FFFFFF) - cameraPosDataOffset) / 0x6; + int32_t index = + ((entries[i]->cameraPosDataSeg & 0x00FFFFFF) - cameraPosDataOffset) / 0x6; sprintf(camSegLine, "&%s_camPosData_%08X[%i]", prefix.c_str(), cameraPosDataOffset, index); } @@ -317,23 +301,24 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, StringHelper::Sprintf("%s_camDataList_%08X", prefix.c_str(), rawDataIndex), entries.size(), declaration); - int numDataTotal = abs(rawDataIndex - (int)cameraPosDataOffset) / 0x6; + uint32_t numDataTotal = (rawDataIndex - cameraPosDataOffset) / 0x6; if (numDataTotal > 0) { declaration = ""; - for (int i = 0; i < numDataTotal; i++) + for (uint32_t i = 0; i < numDataTotal; i++) { CameraPositionData* data = new CameraPositionData(rawData, cameraPosDataOffset + (i * 6)); cameraPositionData.push_back(data); - declaration += - StringHelper::Sprintf(" { %6i, %6i, %6i },\n", data->x, data->y, data->z); + declaration += StringHelper::Sprintf("\t{ %6i, %6i, %6i },", data->x, data->y, data->z); + if (i + 1 < numDataTotal) + declaration += "\n"; } - int cameraPosDataIndex = cameraPosDataSeg & 0x00FFFFFF; - int entrySize = numDataTotal * 0x6; + int32_t cameraPosDataIndex = GETSEGOFFSET(cameraPosDataSeg); + uint32_t entrySize = numDataTotal * 0x6; parent->AddDeclarationArray( cameraPosDataIndex, DeclarationAlignment::None, entrySize, "Vec3s", StringHelper::Sprintf("%s_camPosData_%08X", prefix.c_str(), cameraPosDataIndex), @@ -341,7 +326,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, } } -CameraPositionData::CameraPositionData(const std::vector& rawData, int rawDataIndex) +CameraPositionData::CameraPositionData(const std::vector& rawData, uint32_t rawDataIndex) { x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0); y = BitConverter::ToInt16BE(rawData, rawDataIndex + 2); diff --git a/tools/ZAPD/ZAPD/ZCollision.h b/tools/ZAPD/ZAPD/ZCollision.h index 1f95e57645..7626da731b 100644 --- a/tools/ZAPD/ZAPD/ZCollision.h +++ b/tools/ZAPD/ZAPD/ZCollision.h @@ -7,11 +7,11 @@ class PolygonEntry { public: - int16_t type; - int16_t vtxA, vtxB, vtxC; - int16_t a, b, c, d; + uint16_t type; + uint16_t vtxA, vtxB, vtxC; + uint16_t a, b, c, d; - PolygonEntry(const std::vector& rawData, int rawDataIndex); + PolygonEntry(const std::vector& rawData, uint32_t rawDataIndex); }; class VertexEntry @@ -19,7 +19,7 @@ class VertexEntry public: int16_t x, y, z; - VertexEntry(const std::vector& rawData, int rawDataIndex); + VertexEntry(const std::vector& rawData, uint32_t rawDataIndex); }; class WaterBoxHeader @@ -33,7 +33,7 @@ public: int16_t pad; int32_t properties; - WaterBoxHeader(const std::vector& rawData, int rawDataIndex); + WaterBoxHeader(const std::vector& rawData, uint32_t rawDataIndex); }; class CameraPositionData @@ -41,7 +41,7 @@ class CameraPositionData public: int16_t x, y, z; - CameraPositionData(const std::vector& rawData, int rawDataIndex); + CameraPositionData(const std::vector& rawData, uint32_t rawDataIndex); }; class CameraDataEntry @@ -59,7 +59,8 @@ public: std::vector cameraPositionData; CameraDataList(ZFile* parent, const std::string& prefix, const std::vector& rawData, - int rawDataIndex, int polyTypeDefSegmentOffset, int polygonTypesCnt); + uint32_t rawDataIndex, uint32_t polyTypeDefSegmentOffset, + uint32_t polygonTypesCnt); }; class ZCollisionHeader : public ZResource @@ -77,20 +78,21 @@ public: int32_t numWaterBoxes; segptr_t waterBoxAddress; - std::vector vertices; - std::vector polygons; + uint32_t vtxSegmentOffset, polySegmentOffset, polyTypeDefSegmentOffset, camDataSegmentOffset, + waterBoxSegmentOffset; + + std::vector vertices; + std::vector polygons; std::vector polygonTypes; std::vector waterBoxes; CameraDataList* camData; - ZCollisionHeader(); - // ZCollisionHeader(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); - ZCollisionHeader(ZFile* parent, const std::string& prefix, const std::vector& rawData, - int rawDataIndex); + ZCollisionHeader(ZFile* nParent); ~ZCollisionHeader(); ZResourceType GetResourceType() override; - static ZCollisionHeader* ExtractFromXML(tinyxml2::XMLElement* reader, - std::vector nRawData, int rawDataIndex); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; + void ParseRawData() override; }; diff --git a/tools/ZAPD/ZAPD/ZCutscene.cpp b/tools/ZAPD/ZAPD/ZCutscene.cpp index f84be295d3..d947f627b3 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.cpp +++ b/tools/ZAPD/ZAPD/ZCutscene.cpp @@ -1,23 +1,177 @@ #include "ZCutscene.h" #include "BitConverter.h" #include "StringHelper.h" +#include "ZResource.h" using namespace std; -ZCutscene::ZCutscene(std::vector nRawData, int rawDataIndex, int rawDataSize) -{ - rawData = std::move(nRawData); - segmentOffset = rawDataIndex; +REGISTER_ZFILENODE(Cutscene, ZCutscene); +ZCutscene::ZCutscene(ZFile* nParent) : ZCutsceneBase(nParent) +{ +} + +ZCutscene::~ZCutscene() +{ + for (CutsceneCommand* cmd : commands) + delete cmd; +} +CutsceneCommandSetCameraPos::~CutsceneCommandSetCameraPos() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandSpecialAction::~CutsceneCommandSpecialAction() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandFadeBGM::~CutsceneCommandFadeBGM() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandPlayBGM::~CutsceneCommandPlayBGM() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandStopBGM::~CutsceneCommandStopBGM() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandEnvLighting::~CutsceneCommandEnvLighting() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandUnknown9::~CutsceneCommandUnknown9() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandUnknown::~CutsceneCommandUnknown() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandDayTime::~CutsceneCommandDayTime() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandTextbox::~CutsceneCommandTextbox() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandActorAction::~CutsceneCommandActorAction() +{ + for (auto e : entries) + delete e; +} + +CutsceneCommandSceneTransFX::~CutsceneCommandSceneTransFX() +{ +} + +string ZCutscene::GetBodySourceCode() +{ + string output = ""; + size_t size = 0; + uint32_t curPtr = 0; + + output += StringHelper::Sprintf(" CS_BEGIN_CUTSCENE(%i, %i),\n", commands.size(), endFrame); + + for (size_t i = 0; i < commands.size(); i++) + { + CutsceneCommand* cmd = commands[i]; + output += " " + cmd->GenerateSourceCode(curPtr); + curPtr += cmd->GetCommandSize(); + size += cmd->GetCommandSize(); + } + + output += StringHelper::Sprintf(" CS_END(),\n", commands.size(), endFrame); + + return output; +} + +string ZCutscene::GetSourceOutputCode(const std::string& prefix) +{ + std::string bodyStr = GetBodySourceCode(); + + Declaration* decl = parent->GetDeclaration(rawDataIndex); + + if (decl == nullptr) + DeclareVar(prefix, bodyStr); + else + decl->text = bodyStr; + + return ""; +} + +void ZCutscene::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + + if (auxName == "") + auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex); + // auxName = GetDefaultName(prefix, getSegmentOffset()); + + parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4, + DeclarationPadding::Pad16, GetRawDataSize(), "s32", auxName, 0, + bodyStr); +} + +size_t ZCutscene::GetRawDataSize() +{ + size_t size = 0; + + // Beginning + size += 8; + + for (size_t i = 0; i < commands.size(); i++) + { + CutsceneCommand* cmd = commands[i]; + size += cmd->GetCommandSize(); + size += 4; + } + + // End + size += 8; + + return size; +} + +void ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) +{ + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); + DeclareVar(parent->GetName(), ""); +} + +void ZCutscene::ParseRawData() +{ numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); commands = vector(); endFrame = BitConverter::ToInt32BE(rawData, rawDataIndex + 4); uint32_t currentPtr = rawDataIndex + 8; - for (int i = 0; i < numCommands; i++) + for (int32_t i = 0; i < numCommands; i++) { - int id = BitConverter::ToInt32BE(rawData, currentPtr); + int32_t id = BitConverter::ToInt32BE(rawData, currentPtr); if (id == -1) break; @@ -25,17 +179,9 @@ ZCutscene::ZCutscene(std::vector nRawData, int rawDataIndex, int rawDat CutsceneCommands cmdID = (CutsceneCommands)GetCommandFromID(id); currentPtr += 4; - int numEntries = 1; + int32_t numEntries = 1; - /*if (cmdID != CutsceneCommands::SetCameraPos && cmdID != CutsceneCommands::SetCameraFocus - && cmdID != CutsceneCommands::SetCameraFocusLink && cmdID != - CutsceneCommands::SetCameraPosLink) - { - numEntries = BitConverter::ToInt32BE(rawData, currentPtr); - currentPtr += 4; - }*/ - - for (int j = 0; j < numEntries; j++) + for (int32_t j = 0; j < numEntries; j++) { CutsceneCommand* cmd = nullptr; @@ -112,7 +258,7 @@ ZCutscene::ZCutscene(std::vector nRawData, int rawDataIndex, int rawDat cmd = new CutsceneCommandEnd(rawData, currentPtr); break; case CutsceneCommands::Error: - fprintf(stderr, "Cutscene command error %d %s %d\n", (int)cmdID, __FILE__, + fprintf(stderr, "Cutscene command error %d %s %d\n", (int32_t)cmdID, __FILE__, __LINE__); break; } @@ -126,72 +272,7 @@ ZCutscene::ZCutscene(std::vector nRawData, int rawDataIndex, int rawDat } } -ZCutscene::~ZCutscene() -{ - for (CutsceneCommand* cmd : commands) - delete cmd; -} - -string ZCutscene::GetSourceOutputCode(const std::string& prefix) -{ - string output = ""; - size_t size = 0; - int32_t curPtr = 0; - - // output += StringHelper::Sprintf("// SIZE = 0x%04X\n", GetRawDataSize()); - output += StringHelper::Sprintf("\tCS_BEGIN_CUTSCENE(%i, %i),\n", commands.size(), endFrame); - - for (size_t i = 0; i < commands.size(); i++) - { - CutsceneCommand* cmd = commands[i]; - output += "\t" + cmd->GenerateSourceCode(prefix, curPtr); - curPtr += (uint32_t)cmd->GetCommandSize(); - size += cmd->GetCommandSize(); - } - - output += StringHelper::Sprintf("\tCS_END(),\n", commands.size(), endFrame); - - return output; -} - -int ZCutscene::GetRawDataSize() -{ - int size = 0; - - // Beginning - size += 8; - - for (size_t i = 0; i < commands.size(); i++) - { - CutsceneCommand* cmd = commands[i]; - size += (int)cmd->GetCommandSize(); - size += 4; - } - - // End - size += 8; - - return size; -} - -ZCutscene* ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, - const std::vector& nRawData, const int rawDataIndex, - const std::string& nRelPath) -{ - ZCutscene* cs = new ZCutscene(nRawData, rawDataIndex, 9999); - cs->rawData = nRawData; - cs->rawDataIndex = rawDataIndex; - cs->ParseXML(reader); - cs->ParseRawData(); - - return cs; -} - -void ZCutscene::ParseRawData() -{ -} - -CutsceneCommands ZCutscene::GetCommandFromID(int id) +CutsceneCommands ZCutscene::GetCommandFromID(int32_t id) { switch (id) { @@ -356,7 +437,7 @@ CutsceneCommands ZCutscene::GetCommandFromID(int id) return CutsceneCommands::Unknown; } - printf("WARNING: Could not identify cutscene command ID 0x%04X\n", id); + fprintf(stderr, "WARNING: Could not identify cutscene command ID 0x%04X\n", id); return CutsceneCommands::Error; } @@ -366,20 +447,23 @@ ZResourceType ZCutscene::GetResourceType() return ZResourceType::Cutscene; } -CutsceneCommand::CutsceneCommand(const vector& rawData, int rawDataIndex) +CutsceneCommand::CutsceneCommand(const vector& rawData, uint32_t rawDataIndex) { } -string CutsceneCommand::GetCName(const std::string& prefix) +CutsceneCommand::~CutsceneCommand() +{ +} + +string CutsceneCommand::GetCName() { return "SCmdCutsceneData"; } -string CutsceneCommand::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommand::GenerateSourceCode(uint32_t baseAddress) { - return StringHelper::Sprintf("%s %sCutsceneData%04XCmd%02X = { 0x%02X,", - GetCName(roomName).c_str(), roomName.c_str(), baseAddress, - commandIndex, commandID); + return StringHelper::Sprintf("%s CutsceneData%04XCmd%02X = { 0x%02X,", GetCName().c_str(), + baseAddress, commandIndex, commandID); } size_t CutsceneCommand::GetCommandSize() @@ -387,7 +471,7 @@ size_t CutsceneCommand::GetCommandSize() return 4; } -CutsceneCameraPoint::CutsceneCameraPoint(const vector& rawData, int rawDataIndex) +CutsceneCameraPoint::CutsceneCameraPoint(const vector& rawData, uint32_t rawDataIndex) { const uint8_t* data = rawData.data(); @@ -404,15 +488,15 @@ CutsceneCameraPoint::CutsceneCameraPoint(const vector& rawData, int raw } CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector& rawData, - int rawDataIndex) + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { const uint8_t* data = rawData.data(); - base = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 0); - startFrame = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 2); - endFrame = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 4); - unused = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 6); + base = BitConverter::ToUInt16BE(data, rawDataIndex + 0); + startFrame = BitConverter::ToUInt16BE(data, rawDataIndex + 2); + endFrame = BitConverter::ToUInt16BE(data, rawDataIndex + 4); + unused = BitConverter::ToUInt16BE(data, rawDataIndex + 6); entries = vector(); @@ -433,29 +517,29 @@ CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector& } // TODO -string CutsceneCommandSetCameraPos::GetCName(const std::string& prefix) +string CutsceneCommandSetCameraPos::GetCName() { return ""; } -string CutsceneCommandSetCameraPos::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandSetCameraPos::GenerateSourceCode(uint32_t baseAddress) { string result = ""; string listStr = ""; string posStr = ""; - if (commandID == (int)CutsceneCommands::SetCameraFocus) + if (commandID == (int32_t)CutsceneCommands::SetCameraFocus) { listStr = "CS_CAM_FOCUS_POINT_LIST"; posStr = "CS_CAM_FOCUS_POINT"; } - else if (commandID == (int)CutsceneCommands::SetCameraFocusLink) + else if (commandID == (int32_t)CutsceneCommands::SetCameraFocusLink) { listStr = "CS_CAM_FOCUS_POINT_PLAYER_LIST"; posStr = "CS_CAM_FOCUS_POINT_PLAYER"; } - else if (commandID == (int)CutsceneCommands::SetCameraPosLink) + else if (commandID == (int32_t)CutsceneCommands::SetCameraPosLink) { listStr = "CS_CAM_POS_PLAYER_LIST"; posStr = "CS_CAM_POS_PLAYER"; @@ -470,7 +554,7 @@ string CutsceneCommandSetCameraPos::GenerateSourceCode(const std::string& roomNa for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("\t\t%s(%i, %i, %i, 0x%06X, %i, %i, %i, %i),\n", + result += StringHelper::Sprintf(" %s(%i, %i, %i, 0x%06X, %i, %i, %i, %i),\n", posStr.c_str(), entries[i]->continueFlag, entries[i]->cameraRoll, entries[i]->nextPointFrame, *(uint32_t*)&entries[i]->viewAngle, entries[i]->posX, @@ -485,47 +569,48 @@ size_t CutsceneCommandSetCameraPos::GetCommandSize() return 8 + (entries.size() * 16); } -MusicFadeEntry::MusicFadeEntry(const vector& rawData, int rawDataIndex) +MusicFadeEntry::MusicFadeEntry(const vector& rawData, uint32_t rawDataIndex) { - base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); - startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); - endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4); - unknown0 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); - unknown1 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 8); - unknown2 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 12); - unknown3 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 16); - unknown4 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 20); - unknown5 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 24); - unknown6 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 28); - unknown7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32); - unknown8 = (uint32_t)BitConverter::ToInt32BE(rawData, - rawDataIndex + 36); // Macro hardcodes it as zero - unknown9 = (uint32_t)BitConverter::ToInt32BE(rawData, - rawDataIndex + 40); // Macro hardcodes it as zero - unknown10 = (uint32_t)BitConverter::ToInt32BE(rawData, - rawDataIndex + 44); // Macro hardcodes it as zero + base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); + startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); + endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); + unknown0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); + unknown1 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); + unknown2 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12); + unknown3 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 16); + unknown4 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 20); + unknown5 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 24); + unknown6 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 28); + unknown7 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 32); + unknown8 = BitConverter::ToUInt32BE(rawData, + rawDataIndex + 36); // Macro hardcodes it as zero + unknown9 = BitConverter::ToUInt32BE(rawData, + rawDataIndex + 40); // Macro hardcodes it as zero + unknown10 = BitConverter::ToUInt32BE(rawData, + rawDataIndex + 44); // Macro hardcodes it as zero } -CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector& rawData, int rawDataIndex) +CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector& rawData, + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); + uint32_t numEntries = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (uint32_t i = 0; i < numEntries; i++) { entries.push_back(new MusicFadeEntry(rawData, rawDataIndex)); rawDataIndex += 0x30; } } -string CutsceneCommandFadeBGM::GetCName(const std::string& prefix) +string CutsceneCommandFadeBGM::GetCName() { return "CsCmdMusicFade"; } -string CutsceneCommandFadeBGM::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandFadeBGM::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -534,7 +619,7 @@ string CutsceneCommandFadeBGM::GenerateSourceCode(const std::string& roomName, i for (size_t i = 0; i < entries.size(); i++) { result += StringHelper::Sprintf( - "\t\tCS_FADE_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, + " CS_FADE_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0, entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7); @@ -548,36 +633,37 @@ size_t CutsceneCommandFadeBGM::GetCommandSize() return CutsceneCommand::GetCommandSize() + 0x30 * entries.size(); } -MusicChangeEntry::MusicChangeEntry(const vector& rawData, int rawDataIndex) +MusicChangeEntry::MusicChangeEntry(const vector& rawData, uint32_t rawDataIndex) { - sequence = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); - startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); - endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4); - unknown0 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); - unknown1 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 8); - unknown2 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 12); - unknown3 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 16); - unknown4 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 20); - unknown5 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 24); - unknown6 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 28); - unknown7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32); + sequence = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); + startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); + endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); + unknown0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); + unknown1 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); + unknown2 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12); + unknown3 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 16); + unknown4 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 20); + unknown5 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 24); + unknown6 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 28); + unknown7 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 32); } -CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector& rawData, int rawDataIndex) +CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector& rawData, + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); + uint32_t numEntries = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (uint32_t i = 0; i < numEntries; i++) { entries.push_back(new MusicChangeEntry(rawData, rawDataIndex)); rawDataIndex += 0x30; } } -string CutsceneCommandPlayBGM::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandPlayBGM::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -586,16 +672,16 @@ string CutsceneCommandPlayBGM::GenerateSourceCode(const std::string& roomName, i for (size_t i = 0; i < entries.size(); i++) { result += StringHelper::Sprintf( - "\t\tCS_PLAY_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->sequence, - entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0, - entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, - entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7); + " CS_PLAY_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", + entries[i]->sequence, entries[i]->startFrame, entries[i]->endFrame, + entries[i]->unknown0, entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, + entries[i]->unknown4, entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7); } return result; } -string CutsceneCommandPlayBGM::GetCName(const std::string& prefix) +string CutsceneCommandPlayBGM::GetCName() { return "CsCmdMusicChange"; } @@ -605,21 +691,22 @@ size_t CutsceneCommandPlayBGM::GetCommandSize() return CutsceneCommand::GetCommandSize() + 0x30; } -CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector& rawData, int rawDataIndex) +CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector& rawData, + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); + uint32_t numEntries = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (uint32_t i = 0; i < numEntries; i++) { entries.push_back(new MusicChangeEntry(rawData, rawDataIndex)); rawDataIndex += 0x30; } } -string CutsceneCommandStopBGM::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandStopBGM::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -637,7 +724,7 @@ string CutsceneCommandStopBGM::GenerateSourceCode(const std::string& roomName, i return result; } -string CutsceneCommandStopBGM::GetCName(const std::string& prefix) +string CutsceneCommandStopBGM::GetCName() { return "CsCmdMusicChange"; } @@ -647,7 +734,7 @@ size_t CutsceneCommandStopBGM::GetCommandSize() return CutsceneCommand::GetCommandSize() + 0x30; } -EnvLightingEntry::EnvLightingEntry(const vector& rawData, int rawDataIndex) +EnvLightingEntry::EnvLightingEntry(const vector& rawData, uint32_t rawDataIndex) { setting = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); @@ -663,21 +750,21 @@ EnvLightingEntry::EnvLightingEntry(const vector& rawData, int rawDataIn } CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector& rawData, - int rawDataIndex) + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); + int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (int32_t i = 0; i < numEntries; i++) { entries.push_back(new EnvLightingEntry(rawData, rawDataIndex)); rawDataIndex += 0x30; } } -string CutsceneCommandEnvLighting::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandEnvLighting::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -695,7 +782,7 @@ string CutsceneCommandEnvLighting::GenerateSourceCode(const std::string& roomNam return result; } -string CutsceneCommandEnvLighting::GetCName(const std::string& prefix) +string CutsceneCommandEnvLighting::GetCName() { return "CsCmdEnvLighting"; } @@ -705,7 +792,7 @@ size_t CutsceneCommandEnvLighting::GetCommandSize() return CutsceneCommand::GetCommandSize() + (0x30 * entries.size()); } -Unknown9Entry::Unknown9Entry(const vector& rawData, int rawDataIndex) +Unknown9Entry::Unknown9Entry(const vector& rawData, uint32_t rawDataIndex) { base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); @@ -718,21 +805,22 @@ Unknown9Entry::Unknown9Entry(const vector& rawData, int rawDataIndex) ; } -CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector& rawData, int rawDataIndex) +CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector& rawData, + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); + int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (int32_t i = 0; i < numEntries; i++) { entries.push_back(new Unknown9Entry(rawData, rawDataIndex)); rawDataIndex += 0x0C; } } -string CutsceneCommandUnknown9::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandUnknown9::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -749,7 +837,7 @@ string CutsceneCommandUnknown9::GenerateSourceCode(const std::string& roomName, return result; } -string CutsceneCommandUnknown9::GetCName(const std::string& prefix) +string CutsceneCommandUnknown9::GetCName() { return "CsCmdUnknown9"; } @@ -759,7 +847,7 @@ size_t CutsceneCommandUnknown9::GetCommandSize() return CutsceneCommand::GetCommandSize() + (entries.size() * 12); } -UnkEntry::UnkEntry(const vector& rawData, int rawDataIndex) +UnkEntry::UnkEntry(const vector& rawData, uint32_t rawDataIndex) { unused0 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 0); unused1 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 4); @@ -775,21 +863,22 @@ UnkEntry::UnkEntry(const vector& rawData, int rawDataIndex) unused11 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 44); } -CutsceneCommandUnknown::CutsceneCommandUnknown(const vector& rawData, int rawDataIndex) +CutsceneCommandUnknown::CutsceneCommandUnknown(const vector& rawData, + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); + int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (int32_t i = 0; i < numEntries; i++) { entries.push_back(new UnkEntry(rawData, rawDataIndex)); rawDataIndex += 0x30; } } -string CutsceneCommandUnknown::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandUnknown::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -798,7 +887,7 @@ string CutsceneCommandUnknown::GenerateSourceCode(const std::string& roomName, i for (size_t i = 0; i < entries.size(); i++) { result += StringHelper::Sprintf( - "\t\tCS_UNK_DATA(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", + " CS_UNK_DATA(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->unused0, entries[i]->unused1, entries[i]->unused2, entries[i]->unused3, entries[i]->unused4, entries[i]->unused5, entries[i]->unused6, entries[i]->unused7, entries[i]->unused8, entries[i]->unused9, entries[i]->unused10, entries[i]->unused11); @@ -807,7 +896,7 @@ string CutsceneCommandUnknown::GenerateSourceCode(const std::string& roomName, i return result; } -string CutsceneCommandUnknown::GetCName(const std::string& prefix) +string CutsceneCommandUnknown::GetCName() { return "CsCmdUnknown1A"; } @@ -817,7 +906,7 @@ size_t CutsceneCommandUnknown::GetCommandSize() return CutsceneCommand::GetCommandSize() + (entries.size() * 0x30); } -DayTimeEntry::DayTimeEntry(const vector& rawData, int rawDataIndex) +DayTimeEntry::DayTimeEntry(const vector& rawData, uint32_t rawDataIndex) { base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); @@ -827,26 +916,27 @@ DayTimeEntry::DayTimeEntry(const vector& rawData, int rawDataIndex) unused = rawData[rawDataIndex + 8]; } -CutsceneCommandDayTime::CutsceneCommandDayTime(const vector& rawData, int rawDataIndex) +CutsceneCommandDayTime::CutsceneCommandDayTime(const vector& rawData, + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); + int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (int32_t i = 0; i < numEntries; i++) { entries.push_back(new DayTimeEntry(rawData, rawDataIndex)); rawDataIndex += 12; } } -string CutsceneCommandDayTime::GetCName(const std::string& prefix) +string CutsceneCommandDayTime::GetCName() { return "CsCmdDayTime"; } -string CutsceneCommandDayTime::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandDayTime::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -854,9 +944,9 @@ string CutsceneCommandDayTime::GenerateSourceCode(const std::string& roomName, i for (size_t i = 0; i < entries.size(); i++) { - result += StringHelper::Sprintf("\t\tCS_TIME(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, - entries[i]->startFrame, entries[i]->endFrame, - entries[i]->hour, entries[i]->minute, entries[i]->unused); + result += StringHelper::Sprintf( + " CS_TIME(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, + entries[i]->endFrame, entries[i]->hour, entries[i]->minute, entries[i]->unused); } return result; @@ -867,7 +957,7 @@ size_t CutsceneCommandDayTime::GetCommandSize() return CutsceneCommand::GetCommandSize() + (entries.size() * 12); } -TextboxEntry::TextboxEntry(const vector& rawData, int rawDataIndex) +TextboxEntry::TextboxEntry(const vector& rawData, uint32_t rawDataIndex) { base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); @@ -877,26 +967,27 @@ TextboxEntry::TextboxEntry(const vector& rawData, int rawDataIndex) textID2 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 10); } -CutsceneCommandTextbox::CutsceneCommandTextbox(const vector& rawData, int rawDataIndex) +CutsceneCommandTextbox::CutsceneCommandTextbox(const vector& rawData, + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); + int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (int32_t i = 0; i < numEntries; i++) { entries.push_back(new TextboxEntry(rawData, rawDataIndex)); rawDataIndex += 12; } } -string CutsceneCommandTextbox::GetCName(const std::string& prefix) +string CutsceneCommandTextbox::GetCName() { return "CsCmdTextbox"; } -string CutsceneCommandTextbox::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandTextbox::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -906,13 +997,13 @@ string CutsceneCommandTextbox::GenerateSourceCode(const std::string& roomName, i { if (entries[i]->base == 0xFFFF) { - result += StringHelper::Sprintf("\t\tCS_TEXT_NONE(%i, %i),\n", entries[i]->startFrame, - entries[i]->endFrame); + result += StringHelper::Sprintf(" CS_TEXT_NONE(%i, %i),\n", + entries[i]->startFrame, entries[i]->endFrame); } else { result += StringHelper::Sprintf( - "\t\tCS_TEXT_DISPLAY_TEXTBOX(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, + " CS_TEXT_DISPLAY_TEXTBOX(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->type, entries[i]->textID1, entries[i]->textID2); } @@ -926,7 +1017,7 @@ size_t CutsceneCommandTextbox::GetCommandSize() return CutsceneCommand::GetCommandSize() + (entries.size() * 12); } -ActorAction::ActorAction(const vector& rawData, int rawDataIndex) +ActorAction::ActorAction(const vector& rawData, uint32_t rawDataIndex) { const uint8_t* data = rawData.data(); @@ -948,21 +1039,21 @@ ActorAction::ActorAction(const vector& rawData, int rawDataIndex) } CutsceneCommandActorAction::CutsceneCommandActorAction(const vector& rawData, - int rawDataIndex) + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); + int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (int32_t i = 0; i < numEntries; i++) { entries.push_back(new ActorAction(rawData, rawDataIndex)); rawDataIndex += 0x30; } } -string CutsceneCommandActorAction::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandActorAction::GenerateSourceCode(uint32_t baseAddress) { string result = ""; string subCommand = ""; @@ -981,18 +1072,19 @@ string CutsceneCommandActorAction::GenerateSourceCode(const std::string& roomNam for (size_t i = 0; i < entries.size(); i++) { result += StringHelper::Sprintf( - "\t\t%s(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", - subCommand.c_str(), entries[i]->action, entries[i]->startFrame, entries[i]->endFrame, - entries[i]->rotX, entries[i]->rotY, entries[i]->rotZ, entries[i]->startPosX, - entries[i]->startPosY, entries[i]->startPosZ, entries[i]->endPosX, entries[i]->endPosY, - entries[i]->endPosZ, *(int32_t*)&entries[i]->normalX, *(int32_t*)&entries[i]->normalY, + " CS_NPC_ACTION(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, " + "%i, %i),\n", + entries[i]->action, entries[i]->startFrame, entries[i]->endFrame, entries[i]->rotX, + entries[i]->rotY, entries[i]->rotZ, entries[i]->startPosX, entries[i]->startPosY, + entries[i]->startPosZ, entries[i]->endPosX, entries[i]->endPosY, entries[i]->endPosZ, + *(int32_t*)&entries[i]->normalX, *(int32_t*)&entries[i]->normalY, *(int32_t*)&entries[i]->normalZ); } return result; } -string CutsceneCommandActorAction::GetCName(const std::string& prefix) +string CutsceneCommandActorAction::GetCName() { return "CsCmdBase"; } @@ -1003,7 +1095,7 @@ size_t CutsceneCommandActorAction::GetCommandSize() } CutsceneCommandTerminator::CutsceneCommandTerminator(const vector& rawData, - int rawDataIndex) + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; @@ -1014,12 +1106,12 @@ CutsceneCommandTerminator::CutsceneCommandTerminator(const vector& rawD unknown = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); // endFrame duplicate } -string CutsceneCommandTerminator::GetCName(const std::string& prefix) +string CutsceneCommandTerminator::GetCName() { return "CsCmdBase"; } -string CutsceneCommandTerminator::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandTerminator::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -1033,7 +1125,7 @@ size_t CutsceneCommandTerminator::GetCommandSize() return CutsceneCommand::GetCommandSize() + 8; } -CutsceneCommandEnd::CutsceneCommandEnd(const vector& rawData, int rawDataIndex) +CutsceneCommandEnd::CutsceneCommandEnd(const vector& rawData, uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); @@ -1041,7 +1133,7 @@ CutsceneCommandEnd::CutsceneCommandEnd(const vector& rawData, int rawDa endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4); } -string CutsceneCommandEnd::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandEnd::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -1050,7 +1142,7 @@ string CutsceneCommandEnd::GenerateSourceCode(const std::string& roomName, int b return result; } -string CutsceneCommandEnd::GetCName(const std::string& prefix) +string CutsceneCommandEnd::GetCName() { return "CsCmdBase"; } @@ -1060,7 +1152,7 @@ size_t CutsceneCommandEnd::GetCommandSize() return CutsceneCommand::GetCommandSize() + 6; } -SpecialActionEntry::SpecialActionEntry(const vector& rawData, int rawDataIndex) +SpecialActionEntry::SpecialActionEntry(const vector& rawData, uint32_t rawDataIndex) { const uint8_t* data = rawData.data(); @@ -1081,22 +1173,21 @@ SpecialActionEntry::SpecialActionEntry(const vector& rawData, int rawDa } CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector& rawData, - int rawDataIndex) + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { - int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); + int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); rawDataIndex += 4; - for (int i = 0; i < numEntries; i++) + for (int32_t i = 0; i < numEntries; i++) { entries.push_back(new SpecialActionEntry(rawData, rawDataIndex)); rawDataIndex += 0x30; } } -string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomName, - int baseAddress) +string CutsceneCommandSpecialAction::GenerateSourceCode(uint32_t baseAddress) { string result = ""; @@ -1106,7 +1197,7 @@ string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomN { result += StringHelper::Sprintf( "\t\tCS_MISC(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, " - "%i),\n", + "%i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->unused0, entries[i]->unused1, entries[i]->unused2, entries[i]->unused3, entries[i]->unused4, entries[i]->unused5, entries[i]->unused6, entries[i]->unused7, entries[i]->unused8, @@ -1116,7 +1207,7 @@ string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomN return result; } -string CutsceneCommandSpecialAction::GetCName(const std::string& prefix) +string CutsceneCommandSpecialAction::GetCName() { return "CsCmdBase"; } @@ -1126,7 +1217,7 @@ size_t CutsceneCommandSpecialAction::GetCommandSize() return CutsceneCommand::GetCommandSize() + (0x30 * entries.size()); } -CutsceneCommandNop::CutsceneCommandNop(const vector& rawData, int rawDataIndex) +CutsceneCommandNop::CutsceneCommandNop(const vector& rawData, uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); @@ -1134,7 +1225,7 @@ CutsceneCommandNop::CutsceneCommandNop(const vector& rawData, int rawDa endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4); } -string CutsceneCommandNop::GetCName(const std::string& prefix) +string CutsceneCommandNop::GetCName() { return "CsCmdBase"; } @@ -1145,7 +1236,7 @@ size_t CutsceneCommandNop::GetCommandSize() } CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector& rawData, - int rawDataIndex) + uint32_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; @@ -1155,12 +1246,12 @@ CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector& endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4); } -string CutsceneCommandSceneTransFX::GenerateSourceCode(const std::string& roomName, int baseAddress) +string CutsceneCommandSceneTransFX::GenerateSourceCode(uint32_t baseAddress) { return StringHelper::Sprintf("CS_SCENE_TRANS_FX(%i, %i, %i),\n", base, startFrame, endFrame); } -string CutsceneCommandSceneTransFX::GetCName(const std::string& prefix) +string CutsceneCommandSceneTransFX::GetCName() { return "CsCmdBase"; } @@ -1169,3 +1260,7 @@ size_t CutsceneCommandSceneTransFX::GetCommandSize() { return CutsceneCommand::GetCommandSize() + 8; } + +ZCutsceneBase::ZCutsceneBase(ZFile* nParent) : ZResource(nParent) +{ +} diff --git a/tools/ZAPD/ZAPD/ZCutscene.h b/tools/ZAPD/ZAPD/ZCutscene.h index 6c97db98e1..f5b68ea83a 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.h +++ b/tools/ZAPD/ZAPD/ZCutscene.h @@ -3,6 +3,7 @@ #include #include #include +#include "ZFile.h" #include "ZResource.h" #include "tinyxml2.h" @@ -52,7 +53,7 @@ public: int16_t posX, posY, posZ; int16_t unused; - CutsceneCameraPoint(const std::vector& rawData, int rawDataIndex); + CutsceneCameraPoint(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommand @@ -60,10 +61,10 @@ class CutsceneCommand public: uint32_t commandID; uint32_t commandIndex; - - CutsceneCommand(const std::vector& rawData, int rawDataIndex); - virtual std::string GetCName(const std::string& prefix); - virtual std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + virtual ~CutsceneCommand(); + CutsceneCommand(const std::vector& rawData, uint32_t rawDataIndex); + virtual std::string GetCName(); + virtual std::string GenerateSourceCode(uint32_t baseAddress); virtual size_t GetCommandSize(); }; @@ -76,10 +77,10 @@ public: uint16_t unused; std::vector entries; - - CutsceneCommandSetCameraPos(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + ~CutsceneCommandSetCameraPos(); + CutsceneCommandSetCameraPos(const std::vector& rawData, uint32_t rawDataIndex); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -101,7 +102,7 @@ public: uint32_t unused9; uint32_t unused10; - SpecialActionEntry(const std::vector& rawData, int rawDataIndex); + SpecialActionEntry(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommandSpecialAction : public CutsceneCommand @@ -109,9 +110,10 @@ class CutsceneCommandSpecialAction : public CutsceneCommand public: std::vector entries; - CutsceneCommandSpecialAction(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandSpecialAction(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandSpecialAction(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -133,7 +135,7 @@ public: uint32_t unknown9; uint32_t unknown10; - MusicFadeEntry(const std::vector& rawData, int rawDataIndex); + MusicFadeEntry(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommandFadeBGM : public CutsceneCommand @@ -141,9 +143,10 @@ class CutsceneCommandFadeBGM : public CutsceneCommand public: std::vector entries; - CutsceneCommandFadeBGM(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandFadeBGM(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandFadeBGM(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -162,7 +165,7 @@ public: uint32_t unknown6; uint32_t unknown7; - MusicChangeEntry(const std::vector& rawData, int rawDataIndex); + MusicChangeEntry(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommandPlayBGM : public CutsceneCommand @@ -170,9 +173,10 @@ class CutsceneCommandPlayBGM : public CutsceneCommand public: std::vector entries; - CutsceneCommandPlayBGM(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandPlayBGM(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandPlayBGM(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -181,9 +185,10 @@ class CutsceneCommandStopBGM : public CutsceneCommand public: std::vector entries; - CutsceneCommandStopBGM(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandStopBGM(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandStopBGM(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -202,7 +207,7 @@ public: uint32_t unused6; uint32_t unused7; - EnvLightingEntry(const std::vector& rawData, int rawDataIndex); + EnvLightingEntry(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommandEnvLighting : public CutsceneCommand @@ -210,9 +215,10 @@ class CutsceneCommandEnvLighting : public CutsceneCommand public: std::vector entries; - CutsceneCommandEnvLighting(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandEnvLighting(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandEnvLighting(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -222,10 +228,10 @@ public: uint16_t base; uint16_t startFrame; uint16_t endFrame; - - CutsceneCommandSceneTransFX(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + ~CutsceneCommandSceneTransFX(); + CutsceneCommandSceneTransFX(const std::vector& rawData, uint32_t rawDataIndex); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -241,7 +247,7 @@ public: uint8_t unused0; uint8_t unused1; - Unknown9Entry(const std::vector& rawData, int rawDataIndex); + Unknown9Entry(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommandUnknown9 : public CutsceneCommand @@ -249,9 +255,10 @@ class CutsceneCommandUnknown9 : public CutsceneCommand public: std::vector entries; - CutsceneCommandUnknown9(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandUnknown9(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandUnknown9(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -271,7 +278,7 @@ public: uint32_t unused10; uint32_t unused11; - UnkEntry(const std::vector& rawData, int rawDataIndex); + UnkEntry(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommandUnknown : public CutsceneCommand @@ -279,9 +286,10 @@ class CutsceneCommandUnknown : public CutsceneCommand public: std::vector entries; - CutsceneCommandUnknown(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandUnknown(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandUnknown(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -295,7 +303,7 @@ public: uint8_t minute; uint8_t unused; - DayTimeEntry(const std::vector& rawData, int rawDataIndex); + DayTimeEntry(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommandDayTime : public CutsceneCommand @@ -303,9 +311,10 @@ class CutsceneCommandDayTime : public CutsceneCommand public: std::vector entries; - CutsceneCommandDayTime(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandDayTime(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandDayTime(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -319,7 +328,7 @@ public: uint16_t textID1; uint16_t textID2; - TextboxEntry(const std::vector& rawData, int rawDataIndex); + TextboxEntry(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommandTextbox : public CutsceneCommand @@ -327,9 +336,10 @@ class CutsceneCommandTextbox : public CutsceneCommand public: std::vector entries; - CutsceneCommandTextbox(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandTextbox(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandTextbox(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -344,7 +354,7 @@ public: int32_t endPosX, endPosY, endPosZ; int32_t normalX, normalY, normalZ; - ActorAction(const std::vector& rawData, int rawDataIndex); + ActorAction(const std::vector& rawData, uint32_t rawDataIndex); }; class CutsceneCommandActorAction : public CutsceneCommand @@ -352,9 +362,10 @@ class CutsceneCommandActorAction : public CutsceneCommand public: std::vector entries; - CutsceneCommandActorAction(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandActorAction(const std::vector& rawData, uint32_t rawDataIndex); + ~CutsceneCommandActorAction(); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -366,9 +377,9 @@ public: uint16_t endFrame; uint16_t unknown; - CutsceneCommandTerminator(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandTerminator(const std::vector& rawData, uint32_t rawDataIndex); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -379,9 +390,9 @@ public: uint16_t startFrame; uint16_t endFrame; - CutsceneCommandEnd(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); - std::string GenerateSourceCode(const std::string& roomName, int baseAddress); + CutsceneCommandEnd(const std::vector& rawData, uint32_t rawDataIndex); + std::string GetCName(); + std::string GenerateSourceCode(uint32_t baseAddress); size_t GetCommandSize(); }; @@ -392,32 +403,41 @@ public: uint16_t startFrame; uint16_t endFrame; - CutsceneCommandNop(const std::vector& rawData, int rawDataIndex); - std::string GetCName(const std::string& prefix); + CutsceneCommandNop(const std::vector& rawData, uint32_t rawDataIndex); + std::string GetCName(); size_t GetCommandSize(); }; -class ZCutscene : public ZResource +class ZCutsceneBase : public ZResource { public: - uint32_t segmentOffset; + ZCutsceneBase(ZFile* nParent); + virtual std::string GetBodySourceCode() = 0; + virtual void DeclareVar(const std::string& prefix, const std::string& bodyStr) = 0; + virtual uint32_t getSegmentOffset() = 0; +}; - ZCutscene(std::vector nRawData, int rawDataIndex, int rawDataSize); +class ZCutscene : public ZCutsceneBase +{ +public: + ZCutscene(ZFile* nParent); ~ZCutscene(); + std::string GetBodySourceCode() override; + void DeclareVar(const std::string& prefix, const std::string& bodyStr) override; std::string GetSourceOutputCode(const std::string& prefix) override; - int GetRawDataSize() override; - CutsceneCommands GetCommandFromID(int id); + size_t GetRawDataSize() override; + CutsceneCommands GetCommandFromID(int32_t id); + uint32_t getSegmentOffset() override { return rawDataIndex; } ZResourceType GetResourceType() override; - static ZCutscene* ExtractFromXML(tinyxml2::XMLElement* reader, - const std::vector& nRawData, const int rawDataIndex, - const std::string& nRelPath); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; protected: - int numCommands; - int endFrame; + int32_t numCommands; + int32_t endFrame; std::vector commands; void ParseRawData() override; diff --git a/tools/ZAPD/ZAPD/ZCutsceneMM.cpp b/tools/ZAPD/ZAPD/ZCutsceneMM.cpp new file mode 100644 index 0000000000..0474b631df --- /dev/null +++ b/tools/ZAPD/ZAPD/ZCutsceneMM.cpp @@ -0,0 +1,95 @@ +#include "ZCutsceneMM.h" +#include "BitConverter.h" +#include "StringHelper.h" + +using namespace std; + +ZCutsceneMM::ZCutsceneMM(ZFile* nParent) : ZCutsceneBase(nParent) +{ +} + +ZCutsceneMM::~ZCutsceneMM() +{ + for (CutsceneCommand* cmd : commands) + delete cmd; +} + +string ZCutsceneMM::GetBodySourceCode() +{ + string output = ""; + + output += StringHelper::Sprintf(" CS_BEGIN_CUTSCENE(%i, %i),", numCommands, endFrame); + + for (size_t i = 0; i < data.size(); i++) + { + if ((i % 4) == 0) + output += "\n "; + output += StringHelper::Sprintf("0x%08X,", data[i]); + } + + return output; +} + +string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix) +{ + std::string bodyStr = GetBodySourceCode(); + + Declaration* decl = parent->GetDeclaration(rawDataIndex); + + if (decl == nullptr) + DeclareVar(prefix, bodyStr); + else + decl->text = bodyStr; + + return ""; +} + +void ZCutsceneMM::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + + if (auxName == "") + auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex); + // auxName = GetDefaultName(prefix, getSegmentOffset()); + + parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4, GetRawDataSize(), + "s32", auxName, 0, bodyStr); +} + +size_t ZCutsceneMM::GetRawDataSize() +{ + return 8 + data.size() * 4; +} + +void ZCutsceneMM::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) +{ + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); + DeclareVar(parent->GetName(), ""); +} + +void ZCutsceneMM::ParseRawData() +{ + segmentOffset = rawDataIndex; + + numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); + commands = vector(); + + endFrame = BitConverter::ToInt32BE(rawData, rawDataIndex + 4); + uint32_t currentPtr = rawDataIndex + 8; + uint32_t lastData = 0; + + // TODO currently cutscenes aren't being parsed, so just consume words until we see an end + // marker. + do + { + lastData = BitConverter::ToInt32BE(rawData, currentPtr); + data.push_back(lastData); + currentPtr += 4; + } while (lastData != 0xFFFFFFFF); +} + +ZResourceType ZCutsceneMM::GetResourceType() +{ + return ZResourceType::Cutscene; +} diff --git a/tools/ZAPD/ZAPD/ZCutsceneMM.h b/tools/ZAPD/ZAPD/ZCutsceneMM.h new file mode 100644 index 0000000000..97dae93e81 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZCutsceneMM.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include +#include "ZCutscene.h" +#include "ZFile.h" +#include "tinyxml2.h" + +class ZCutsceneMM : public ZCutsceneBase +{ +public: + uint32_t segmentOffset; + + ZCutsceneMM(ZFile* nParent); + virtual ~ZCutsceneMM(); + + std::string GetBodySourceCode() override; + void DeclareVar(const std::string& prefix, const std::string& bodyStr) override; + std::string GetSourceOutputCode(const std::string& prefix) override; + size_t GetRawDataSize() override; + uint32_t getSegmentOffset() override { return segmentOffset; } + + void ParseRawData() override; + ZResourceType GetResourceType() override; + + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; + +protected: + int32_t numCommands; + int32_t endFrame; + std::vector commands; + + std::vector data; +}; diff --git a/tools/ZAPD/ZAPD/ZDisplayList.cpp b/tools/ZAPD/ZAPD/ZDisplayList.cpp index c5fd660496..99abbbe2b0 100644 --- a/tools/ZAPD/ZAPD/ZDisplayList.cpp +++ b/tools/ZAPD/ZAPD/ZDisplayList.cpp @@ -14,7 +14,9 @@ using namespace std; using namespace tinyxml2; -ZDisplayList::ZDisplayList() : ZResource() +REGISTER_ZFILENODE(DList, ZDisplayList); + +ZDisplayList::ZDisplayList(ZFile* nParent) : ZResource(nParent) { defines = ""; sceneSegName = ""; @@ -39,37 +41,41 @@ ZDisplayList::ZDisplayList() : ZResource() texDeclarations = map(); } +ZDisplayList::~ZDisplayList() +{ + for (auto t : textures) + { + delete t.second; + } + + for (auto o : otherDLists) + { + delete o; + } +} + // EXTRACT MODE -ZDisplayList* ZDisplayList::ExtractFromXML(XMLElement* reader, vector nRawData, - int nRawDataIndex, int rawDataSize, string nRelPath) +void ZDisplayList::ExtractFromXML(tinyxml2::XMLElement* reader, + const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZDisplayList* dList = new ZDisplayList(); + rawDataIndex = nRawDataIndex; + ParseXML(reader); - dList->ParseXML(reader); - - // dList->name = reader->Attribute("Name"); - - dList->rawData = nRawData; - dList->rawDataIndex = nRawDataIndex; - dList->fileData = dList->rawData; - dList->relativePath = nRelPath; - dList->rawData = vector(dList->rawData.data() + dList->rawDataIndex, - dList->rawData.data() + dList->rawDataIndex + rawDataSize); - dList->ParseRawData(); - - return dList; + // name = reader->Attribute("Name"); + fileData = nRawData; + relativePath = nRelPath; + int32_t rawDataSize = ZDisplayList::GetDListLength( + nRawData, rawDataIndex, + Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); + rawData = vector(nRawData.data() + rawDataIndex, + nRawData.data() + rawDataIndex + rawDataSize); + ParseRawData(); } -ZDisplayList* ZDisplayList::BuildFromXML(XMLElement* reader, string inFolder, bool readFile) -{ - ZDisplayList* dList = new ZDisplayList(); - - dList->SetName(reader->Attribute("Name")); - return dList; -} - -ZDisplayList::ZDisplayList(vector nRawData, int nRawDataIndex, int rawDataSize) - : ZDisplayList() +ZDisplayList::ZDisplayList(vector nRawData, uint32_t nRawDataIndex, int32_t rawDataSize, + ZFile* nParent) + : ZDisplayList(nParent) { fileData = nRawData; rawDataIndex = nRawDataIndex; @@ -81,16 +87,16 @@ ZDisplayList::ZDisplayList(vector nRawData, int nRawDataIndex, int rawD void ZDisplayList::ParseRawData() { - int numInstructions = (int)rawData.size() / 8; + size_t numInstructions = rawData.size() / 8; uint8_t* rawDataArr = rawData.data(); instructions.reserve(numInstructions); - for (int i = 0; i < numInstructions; i++) + for (size_t i = 0; i < numInstructions; i++) instructions.push_back(BitConverter::ToUInt64BE(rawDataArr, (i * 8))); } -void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::string prefix, +void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, std::string prefix, char* line) { switch (opcode) @@ -99,55 +105,42 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s sprintf(line, "gsDPNoOpTag(0x%08lX),", data & 0xFFFFFFFF); break; case F3DZEXOpcode::G_DL: - Opcode_G_DL(data, i, prefix, line); + Opcode_G_DL(data, prefix, line); break; case F3DZEXOpcode::G_MODIFYVTX: - Opcode_G_MODIFYVTX(data, i, prefix, line); + Opcode_G_MODIFYVTX(data, line); break; case F3DZEXOpcode::G_CULLDL: - Opcode_G_CULLDL(data, i, prefix, line); + Opcode_G_CULLDL(data, line); break; - /*case F3DZEXOpcode::G_BRANCH_Z: - { - int aaa = (data & 0x00FFF00000000000) >> 44; - int bbb = (data & 0x00000FFF00000000) >> 32; - int zzzzzzzz = (data & 0x00000000FFFFFFFF); - - sprintf(line, "gsSPBranchLessZraw(%i, %i, %i),", ); - } - break;*/ case F3DZEXOpcode::G_TRI1: - Opcode_G_TRI1(data, i, prefix, line); + Opcode_G_TRI1(data, line); break; case F3DZEXOpcode::G_TRI2: - Opcode_G_TRI2(data, i, prefix, line); + Opcode_G_TRI2(data, line); break; case F3DZEXOpcode::G_QUAD: { - int aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; - int bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; - int cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; - int dd = ((data & 0x000000000000FFULL)) / 2; + int32_t aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; + int32_t bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; + int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; + int32_t dd = ((data & 0x000000000000FFULL)) / 2; sprintf(line, "gsSP1Quadrangle(%i, %i, %i, %i, 0),", aa, bb, cc, dd); } break; case F3DZEXOpcode::G_VTX: - { - Opcode_G_VTX(data, i, prefix, line); - } - break; + Opcode_G_VTX(data, line); + break; case F3DZEXOpcode::G_SETTIMG: // HOTSPOT - { - Opcode_G_SETTIMG(data, i, prefix, line); - } - break; + Opcode_G_SETTIMG(data, prefix, line); + break; case F3DZEXOpcode::G_GEOMETRYMODE: { - int cccccc = (data & 0x00FFFFFF00000000) >> 32; - int ssssssss = (data & 0xFFFFFFFF); + int32_t cccccc = (data & 0x00FFFFFF00000000) >> 32; + int32_t ssssssss = (data & 0xFFFFFFFF); string geoModeStr = "G_TEXTURE_ENABLE"; - int geoModeParam = ~cccccc; + int32_t geoModeParam = ~cccccc; if (ssssssss != 0) geoModeParam = ssssssss; @@ -191,35 +184,33 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s } else sprintf(line, "gsSPClearGeometryMode(%s),", geoModeStr.c_str()); - - // sprintf(line, "gsSPGeometryMode(0x%08X, 0x%08X),", ~cccccc, ssssssss); } break; case F3DZEXOpcode::G_SETPRIMCOLOR: - Opcode_G_SETPRIMCOLOR(data, i, prefix, line); + Opcode_G_SETPRIMCOLOR(data, line); break; case F3DZEXOpcode::G_SETOTHERMODE_L: - Opcode_G_SETOTHERMODE_L(data, i, prefix, line); + Opcode_G_SETOTHERMODE_L(data, line); break; case F3DZEXOpcode::G_SETOTHERMODE_H: - Opcode_G_SETOTHERMODE_H(data, i, prefix, line); + Opcode_G_SETOTHERMODE_H(data, line); break; case F3DZEXOpcode::G_SETTILE: - Opcode_G_SETTILE(data, i, prefix, line); + Opcode_G_SETTILE(data, line); break; case F3DZEXOpcode::G_SETTILESIZE: - Opcode_G_SETTILESIZE(data, i, prefix, line); + Opcode_G_SETTILESIZE(data, prefix, line); break; case F3DZEXOpcode::G_LOADBLOCK: - Opcode_G_LOADBLOCK(data, i, prefix, line); + Opcode_G_LOADBLOCK(data, line); break; case F3DZEXOpcode::G_TEXTURE: - Opcode_G_TEXTURE(data, i, prefix, line); + Opcode_G_TEXTURE(data, line); break; case F3DZEXOpcode::G_RDPSETOTHERMODE: { - int hhhhhh = (data & 0x00FFFFFF00000000) >> 32; - int llllllll = (data & 0x00000000FFFFFFFF); + int32_t hhhhhh = (data & 0x00FFFFFF00000000) >> 32; + int32_t llllllll = (data & 0x00000000FFFFFFFF); sprintf(line, "gsDPSetOtherMode(%i, %i),", hhhhhh, llllllll); } @@ -230,7 +221,7 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s } break; case F3DZEXOpcode::G_LOADTLUT: - Opcode_G_LOADTLUT(data, i, prefix, line); + Opcode_G_LOADTLUT(data, prefix, line); break; case F3DZEXOpcode::G_SETENVCOLOR: { @@ -244,7 +235,7 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s break; case F3DZEXOpcode::G_SETCOMBINE: { - Opcode_G_SETCOMBINE(data, i, prefix, line); + Opcode_G_SETCOMBINE(data, line); } break; case F3DZEXOpcode::G_RDPLOADSYNC: @@ -260,7 +251,7 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s sprintf(line, "gsDPFullSync(),"); break; case F3DZEXOpcode::G_ENDDL: - Opcode_G_ENDDL(data, i, prefix, line); + Opcode_G_ENDDL(prefix, line); break; case F3DZEXOpcode::G_RDPHALF_1: { @@ -278,25 +269,18 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s sprintf(line, "gsSPBranchLessZraw(%sDlist0x%06X, 0x%02X, 0x%02X),", prefix.c_str(), h & 0x00FFFFFF, (a / 5) | (b / 2), z); - ZDisplayList* nList = new ZDisplayList( - fileData, h & 0x00FFFFFF, GetDListLength(fileData, h & 0x00FFFFFF, dListType)); + ZDisplayList* nList = + new ZDisplayList(fileData, h & 0x00FFFFFF, + GetDListLength(fileData, h & 0x00FFFFFF, dListType), parent); nList->scene = scene; - nList->parent = parent; otherDLists.push_back(nList); i++; } } break; - /*case F3DZEXOpcode::G_BRANCH_Z: - { - uint8_t h = (data & 0xFFFFFFFF); - - sprintf(line, "gsSPBranchLessZraw(%i, %i, %i),", h); - } - break;*/ case F3DZEXOpcode::G_MTX: - Opcode_G_MTX(data, i, prefix, line); + Opcode_G_MTX(data, line); break; default: sprintf(line, "// Opcode 0x%02X unimplemented!", (uint32_t)opcode); @@ -304,8 +288,7 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::s } } -void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, int i, std::string prefix, - char* line) +void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, std::string prefix, char* line) { switch (opcode) { @@ -313,28 +296,28 @@ void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, int i, std::str sprintf(line, "gsDPNoOpTag(0x%08lX),", data & 0xFFFFFFFF); break; case F3DEXOpcode::G_VTX: - Opcode_G_VTX(data, i, prefix, line); + Opcode_G_VTX(data, line); break; case F3DEXOpcode::G_DL: - Opcode_G_DL(data, i, prefix, line); + Opcode_G_DL(data, prefix, line); break; case F3DEXOpcode::G_CULLDL: - Opcode_G_CULLDL(data, i, prefix, line); + Opcode_G_CULLDL(data, line); break; case F3DEXOpcode::G_MODIFYVTX: - Opcode_G_MODIFYVTX(data, i, prefix, line); + Opcode_G_MODIFYVTX(data, line); break; case F3DEXOpcode::G_MTX: - Opcode_G_MTX(data, i, prefix, line); + Opcode_G_MTX(data, line); break; case F3DEXOpcode::G_TRI1: - Opcode_G_TRI1(data, i, prefix, line); + Opcode_G_TRI1(data, line); break; case F3DEXOpcode::G_TRI2: - Opcode_G_TRI2(data, i, prefix, line); + Opcode_G_TRI2(data, line); break; case F3DEXOpcode::G_ENDDL: - Opcode_G_ENDDL(data, i, prefix, line); + Opcode_G_ENDDL(prefix, line); break; case F3DEXOpcode::G_RDPLOADSYNC: sprintf(line, "gsDPLoadSync(),"); @@ -349,43 +332,43 @@ void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, int i, std::str sprintf(line, "gsDPFullSync(),"); break; case F3DEXOpcode::G_TEXTURE: - Opcode_G_TEXTURE(data, i, prefix, line); + Opcode_G_TEXTURE(data, line); break; case F3DEXOpcode::G_SETTIMG: - Opcode_G_SETTIMG(data, i, prefix, line); + Opcode_G_SETTIMG(data, prefix, line); break; case F3DEXOpcode::G_SETTILE: - Opcode_G_SETTILE(data, i, prefix, line); + Opcode_G_SETTILE(data, line); break; case F3DEXOpcode::G_SETTILESIZE: - Opcode_G_SETTILESIZE(data, i, prefix, line); + Opcode_G_SETTILESIZE(data, prefix, line); break; case F3DEXOpcode::G_LOADBLOCK: - Opcode_G_LOADBLOCK(data, i, prefix, line); + Opcode_G_LOADBLOCK(data, line); break; case F3DEXOpcode::G_SETCOMBINE: - Opcode_G_SETCOMBINE(data, i, prefix, line); + Opcode_G_SETCOMBINE(data, line); break; case F3DEXOpcode::G_SETPRIMCOLOR: - Opcode_G_SETPRIMCOLOR(data, i, prefix, line); + Opcode_G_SETPRIMCOLOR(data, line); break; case F3DEXOpcode::G_SETOTHERMODE_L: - Opcode_G_SETOTHERMODE_L(data, i, prefix, line); + Opcode_G_SETOTHERMODE_L(data, line); break; case F3DEXOpcode::G_SETOTHERMODE_H: - Opcode_G_SETOTHERMODE_H(data, i, prefix, line); + Opcode_G_SETOTHERMODE_H(data, line); break; case F3DEXOpcode::G_LOADTLUT: - Opcode_G_LOADTLUT(data, i, prefix, line); + Opcode_G_LOADTLUT(data, prefix, line); break; case F3DEXOpcode::G_CLEARGEOMETRYMODE: case F3DEXOpcode::G_SETGEOMETRYMODE: { - int cccccc = (data & 0x00FFFFFF00000000) >> 32; - int ssssssss = (data & 0xFFFFFFFF); + int32_t cccccc = (data & 0x00FFFFFF00000000) >> 32; + int32_t ssssssss = (data & 0xFFFFFFFF); string geoModeStr = "G_TEXTURE_ENABLE"; - int geoModeParam = ~cccccc; + int32_t geoModeParam = ~cccccc; if (ssssssss != 0) geoModeParam = ssssssss; @@ -435,9 +418,10 @@ void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, int i, std::str } } -int ZDisplayList::GetDListLength(vector rawData, int rawDataIndex, DListType dListType) +int32_t ZDisplayList::GetDListLength(vector rawData, uint32_t rawDataIndex, + DListType dListType) { - int i = 0; + int32_t i = 0; uint8_t endDLOpcode; @@ -448,7 +432,7 @@ int ZDisplayList::GetDListLength(vector rawData, int rawDataIndex, DLis while (true) { - uint8_t opcode = (uint8_t)rawData[rawDataIndex + (i * 8)]; + uint8_t opcode = rawData[rawDataIndex + (i * 8)]; i++; if (opcode == endDLOpcode) @@ -456,7 +440,7 @@ int ZDisplayList::GetDListLength(vector rawData, int rawDataIndex, DLis } } -bool ZDisplayList::SequenceCheck(vector sequence, int startIndex) +bool ZDisplayList::SequenceCheck(vector sequence, int32_t startIndex) { bool success = true; @@ -477,9 +461,9 @@ bool ZDisplayList::SequenceCheck(vector sequence, int startIndex) return false; } -int ZDisplayList::OptimizationChecks(int startIndex, string& output, string prefix) +int32_t ZDisplayList::OptimizationChecks(int32_t startIndex, string& output, string prefix) { - int result = -1; + int32_t result = -1; result = OptimizationCheck_LoadTextureBlock(startIndex, output, prefix); @@ -489,7 +473,8 @@ int ZDisplayList::OptimizationChecks(int startIndex, string& output, string pref return -1; } -int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& output, string prefix) +int32_t ZDisplayList::OptimizationCheck_LoadTextureBlock(int32_t startIndex, string& output, + string prefix) { if (scene == nullptr) { @@ -519,13 +504,13 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out { uint64_t data = instructions[startIndex + 0]; - int __ = (data & 0x00FF000000000000) >> 48; - // int www = (data & 0x00000FFF00000000) >> 32; + int32_t __ = (data & 0x00FF000000000000) >> 48; + // int32_t www = (data & 0x00000FFF00000000) >> 32; fmt = (__ & 0xE0) >> 5; siz = (__ & 0x18) >> 3; texAddr = Seg2Filespace(data, parent->baseAddress); - int segmentNumber = GETSEGNUM(data); + int32_t segmentNumber = GETSEGNUM(data); lastTexSeg = (data & 0xFF000000); @@ -590,7 +575,7 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out // gsDPSetTile { uint64_t data = instructions[startIndex + 5]; - int __ = (data & 0x00FF000000000000) >> 48; + int32_t __ = (data & 0x00FF000000000000) >> 48; pal = (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >> 20; // siz = (__ & 0x18) >> 3; rtile = @@ -601,21 +586,21 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out // gsDPSetTileSize { uint64_t data = instructions[startIndex + 6]; - int uuu = (data & 0x0000000000FFF000) >> 12; - int vvv = (data & 0x0000000000000FFF); + int32_t uuu = (data & 0x0000000000FFF000) >> 12; + int32_t vvv = (data & 0x0000000000000FFF); - int shiftAmtW = 2; - int shiftAmtH = 2; + int32_t shiftAmtW = 2; + int32_t shiftAmtH = 2; - if (sizB == (int)F3DZEXTexSizes::G_IM_SIZ_8b && - fmt == (int)F3DZEXTexFormats::G_IM_FMT_IA) + if (sizB == (int32_t)F3DZEXTexSizes::G_IM_SIZ_8b && + fmt == (int32_t)F3DZEXTexFormats::G_IM_FMT_IA) shiftAmtW = 3; - if (sizB == (int)F3DZEXTexSizes::G_IM_SIZ_4b) + if (sizB == (int32_t)F3DZEXTexSizes::G_IM_SIZ_4b) shiftAmtW = 3; - if (sizB == (int)F3DZEXTexSizes::G_IM_SIZ_4b && - fmt == (int)F3DZEXTexFormats::G_IM_FMT_IA) + if (sizB == (int32_t)F3DZEXTexSizes::G_IM_SIZ_4b && + fmt == (int32_t)F3DZEXTexFormats::G_IM_FMT_IA) shiftAmtH = 3; width = (uuu >> shiftAmtW) + 1; @@ -690,16 +675,16 @@ int ZDisplayList::OptimizationCheck_LoadTextureBlock(int startIndex, string& out TextureGenCheck(prefix); - return (int)sequence.size(); + return (int32_t)sequence.size(); } return -1; } -void ZDisplayList::Opcode_G_DL(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_DL(uint64_t data, std::string prefix, char* line) { - int pp = (data & 0x00FF000000000000) >> 56; - int segNum = GETSEGNUM(data); + int32_t pp = (data & 0x00FF000000000000) >> 56; + int32_t segNum = GETSEGNUM(data); Declaration* dListDecl = nullptr; @@ -725,12 +710,9 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, int i, std::string prefix, char* l sprintf(line, "gsSPDisplayList(%sDlist0x%06lX),", prefix.c_str(), GETSEGOFFSET(data)); } - // TODO: This is the same as `segNum`. Consider resuing that variable instead of making a new - // one. - int segmentNumber = GETSEGNUM(data); - - if (segmentNumber == 8 || segmentNumber == 9 || segmentNumber == 10 || segmentNumber == 11 || - segmentNumber == 12 || segmentNumber == 13) // Used for runtime-generated display lists + // if (segNum == 8 || segNum == 9 || segNum == 10 || segNum == 11 || segNum == 12 || segNum == + // 13) // Used for runtime-generated display lists + if (!Globals::Instance->HasSegment(segNum)) { if (pp != 0) sprintf(line, "gsSPBranchList(0x%08lX),", data & 0xFFFFFFFF); @@ -739,61 +721,70 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, int i, std::string prefix, char* l } else { - ZDisplayList* nList = new ZDisplayList( - fileData, data & 0x00FFFFFF, GetDListLength(fileData, data & 0x00FFFFFF, dListType)); - nList->scene = scene; - nList->parent = parent; - otherDLists.push_back(nList); + ZDisplayList* nList = + new ZDisplayList(fileData, GETSEGOFFSET(data), + GetDListLength(fileData, GETSEGOFFSET(data), dListType), parent); + + // if (scene != nullptr) + { + nList->scene = scene; + otherDLists.push_back(nList); + } + // else + //{ + // nList->SetName(StringHelper::Sprintf("%sDlist0x%06lX", prefix.c_str(), + // SEG2FILESPACE(data))); nList->GetSourceOutputCode(prefix); + //} } } -void ZDisplayList::Opcode_G_MODIFYVTX(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_MODIFYVTX(uint64_t data, char* line) { - int ww = (data & 0x00FF000000000000ULL) >> 48; - int nnnn = (data & 0x0000FFFF00000000ULL) >> 32; - int vvvvvvvv = (data & 0x00000000FFFFFFFFULL); + int32_t ww = (data & 0x00FF000000000000ULL) >> 48; + int32_t nnnn = (data & 0x0000FFFF00000000ULL) >> 32; + int32_t vvvvvvvv = (data & 0x00000000FFFFFFFFULL); sprintf(line, "gsSPModifyVertex(%i, %i, %i),", nnnn / 2, ww, vvvvvvvv); } -void ZDisplayList::Opcode_G_CULLDL(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_CULLDL(uint64_t data, char* line) { - int vvvv = (data & 0xFFFF00000000) >> 32; - int wwww = (data & 0x0000FFFF); + int32_t vvvv = (data & 0xFFFF00000000) >> 32; + int32_t wwww = (data & 0x0000FFFF); sprintf(line, "gsSPCullDisplayList(%i, %i),", vvvv / 2, wwww / 2); } -void ZDisplayList::Opcode_G_TRI1(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_TRI1(uint64_t data, char* line) { if (dListType == DListType::F3DZEX) { - int aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; - int bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; - int cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; + int32_t aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; + int32_t bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; + int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; sprintf(line, "gsSP1Triangle(%i, %i, %i, 0),", aa, bb, cc); } else { - int aa = ((data & 0x0000000000FF0000ULL) >> 16) / 2; - int bb = ((data & 0x000000000000FF00ULL) >> 8) / 2; - int cc = ((data & 0x00000000000000FFULL) >> 0) / 2; + int32_t aa = ((data & 0x0000000000FF0000ULL) >> 16) / 2; + int32_t bb = ((data & 0x000000000000FF00ULL) >> 8) / 2; + int32_t cc = ((data & 0x00000000000000FFULL) >> 0) / 2; sprintf(line, "gsSP1Triangle(%i, %i, %i, 0),", aa, bb, cc); } } -void ZDisplayList::Opcode_G_TRI2(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_TRI2(uint64_t data, char* line) { - int aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; - int bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; - int cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; - int dd = ((data & 0x00000000FF0000ULL) >> 16) / 2; - int ee = ((data & 0x0000000000FF00ULL) >> 8) / 2; - int ff = ((data & 0x000000000000FFULL) >> 0) / 2; + int32_t aa = ((data & 0x00FF000000000000ULL) >> 48) / 2; + int32_t bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; + int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; + int32_t dd = ((data & 0x00000000FF0000ULL) >> 16) / 2; + int32_t ee = ((data & 0x0000000000FF00ULL) >> 8) / 2; + int32_t ff = ((data & 0x000000000000FFULL) >> 0) / 2; sprintf(line, "gsSP2Triangles(%i, %i, %i, 0, %i, %i, %i, 0),", aa, bb, cc, dd, ee, ff); } -void ZDisplayList::Opcode_G_MTX(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_MTX(uint64_t data, char* line) { uint32_t pp = 0; uint32_t mm = (data & 0x00000000FFFFFFFF); @@ -829,10 +820,10 @@ void ZDisplayList::Opcode_G_MTX(uint64_t data, int i, std::string prefix, char* push ? "G_MTX_PUSH" : "G_MTX_NOPUSH", load ? "G_MTX_LOAD" : "G_MTX_MUL"); } -void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_VTX(uint64_t data, char* line) { - int nn = (data & 0x000FF00000000000ULL) >> 44; - int aa = (data & 0x000000FF00000000ULL) >> 32; + int32_t nn = (data & 0x000FF00000000000ULL) >> 44; + int32_t aa = (data & 0x000000FF00000000ULL) >> 32; uint32_t vtxAddr = Seg2Filespace(data, parent->baseAddress); @@ -869,7 +860,7 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* { // Declaration* decl = parent->GetDeclarationRanged(vtxAddr + (nn * 16)); uint32_t addr = parent->GetDeclarationRangedAddress(vtxAddr + (nn * 16)); - int diff = addr - vtxAddr; + int32_t diff = addr - vtxAddr; if (diff > 0) nn = diff / 16; else @@ -880,7 +871,7 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* { // Declaration* decl = parent->GetDeclarationRanged(vtxAddr); uint32_t addr = parent->GetDeclarationRangedAddress(vtxAddr); - int diff = addr - vtxAddr; + int32_t diff = addr - vtxAddr; if (diff > 0) nn = diff / 16; else @@ -892,7 +883,7 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* vector vtxList = vector(); vtxList.reserve(nn); - for (int i = 0; i < nn; i++) + for (int32_t i = 0; i < nn; i++) { Vertex vtx = Vertex(fileData, currentPtr); vtxList.push_back(vtx); @@ -905,14 +896,14 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* } } -void ZDisplayList::Opcode_G_TEXTURE(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_TEXTURE(uint64_t data, char* line) { - int ____ = (data & 0x0000FFFF00000000) >> 32; - int ssss = (data & 0x00000000FFFF0000) >> 16; - int tttt = (data & 0x000000000000FFFF); - int lll = (____ & 0x3800) >> 11; - int ddd = (____ & 0x700) >> 8; - int nnnnnnn = 0; + int32_t ____ = (data & 0x0000FFFF00000000) >> 32; + int32_t ssss = (data & 0x00000000FFFF0000) >> 16; + int32_t tttt = (data & 0x000000000000FFFF); + int32_t lll = (____ & 0x3800) >> 11; + int32_t ddd = (____ & 0x700) >> 8; + int32_t nnnnnnn = 0; if (dListType == DListType::F3DEX) nnnnnnn = (____ & 0xFF); @@ -923,10 +914,10 @@ void ZDisplayList::Opcode_G_TEXTURE(uint64_t data, int i, std::string prefix, ch nnnnnnn == 1 ? "G_ON" : "G_OFF"); } -void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, std::string prefix, char* line) { - int __ = (data & 0x00FF000000000000) >> 48; - int www = (data & 0x00000FFF00000000) >> 32; + int32_t __ = (data & 0x00FF000000000000) >> 48; + int32_t www = (data & 0x00000FFF00000000) >> 32; string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", "G_IM_FMT_I"}; string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"}; @@ -943,7 +934,7 @@ void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, int i, std::string prefix, ch lastTexSeg = data; lastTexAddr = Seg2Filespace(data, parent->baseAddress); - int segmentNumber = GETSEGNUM(data); + int32_t segmentNumber = GETSEGNUM(data); if (segmentNumber != 2) { @@ -965,12 +956,6 @@ void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, int i, std::string prefix, ch sprintf(texStr, "%sTex_%06X", prefix.c_str(), texAddress); else { - // TEST: CHECK OTHER FILES FOR REF - // if (segmentNumber == 4) - //{ - // Globals::Instance->FindSymbolSegRef(segmentNumber, texAddress); - //} - // else { sprintf(texStr, "0x%08lX", data & 0xFFFFFFFF); } @@ -978,39 +963,38 @@ void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, int i, std::string prefix, ch sprintf(line, "gsDPSetTextureImage(%s, %s, %i, %s),", fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), www + 1, texStr); - // sprintf(line, "gsDPSetTextureImage(%s, %s, %i, @r),", fmtTbl[fmt].c_str(), - // sizTbl[siz].c_str(), www + 1); references.push_back(data & 0x00FFFFFF); } else { - // sprintf(line, "gsDPSetTextureImage(%s, %s, %i, 0x%08X),", fmtTbl[fmt].c_str(), - // sizTbl[siz].c_str(), www + 1, data & 0xFFFFFFFF); sprintf(line, "gsDPSetTextureImage(%s, %s, %i, %sTex_%06lX),", fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), www + 1, scene->GetName().c_str(), GETSEGOFFSET(data)); } } -void ZDisplayList::Opcode_G_SETTILE(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_SETTILE(uint64_t data, char* line) { - int fff = (data & 0b0000000011100000000000000000000000000000000000000000000000000000) >> 53; - int ii = (data & 0b0000000000011000000000000000000000000000000000000000000000000000) >> 51; - int nnnnnnnnn = + int32_t fff = (data & 0b0000000011100000000000000000000000000000000000000000000000000000) >> 53; + int32_t ii = (data & 0b0000000000011000000000000000000000000000000000000000000000000000) >> 51; + int32_t nnnnnnnnn = (data & 0b0000000000000011111111100000000000000000000000000000000000000000) >> 41; - int mmmmmmmmm = + int32_t mmmmmmmmm = (data & 0b0000000000000000000000011111111100000000000000000000000000000000) >> 32; - int ttt = (data & 0b0000000000000000000000000000000000000111000000000000000000000000) >> 24; - int pppp = (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >> 20; - int cc = (data & 0b0000000000000000000000000000000000000000000011000000000000000000) >> 18; - int aaaa = (data & 0b0000000000000000000000000000000000000000000000111100000000000000) >> 14; - int ssss = (data & 0b0000000000000000000000000000000000000000000000000011110000000000) >> 10; - int dd = (data & 0b0000000000000000000000000000000000000000000000000000001100000000) >> 8; - int bbbb = (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; - int uuuu = (data & 0b0000000000000000000000000000000000000000000000000000000000001111); + int32_t ttt = (data & 0b0000000000000000000000000000000000000111000000000000000000000000) >> 24; + int32_t pppp = + (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >> 20; + int32_t cc = (data & 0b0000000000000000000000000000000000000000000011000000000000000000) >> 18; + int32_t aaaa = + (data & 0b0000000000000000000000000000000000000000000000111100000000000000) >> 14; + int32_t ssss = + (data & 0b0000000000000000000000000000000000000000000000000011110000000000) >> 10; + int32_t dd = (data & 0b0000000000000000000000000000000000000000000000000000001100000000) >> 8; + int32_t bbbb = (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; + int32_t uuuu = (data & 0b0000000000000000000000000000000000000000000000000000000000001111); string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", "G_IM_FMT_I"}; string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"}; - if (fff == (int)F3DZEXTexFormats::G_IM_FMT_CI) + if (fff == (int32_t)F3DZEXTexFormats::G_IM_FMT_CI) lastCISiz = (F3DZEXTexSizes)ii; lastTexSizTest = (F3DZEXTexSizes)ii; @@ -1020,16 +1004,16 @@ void ZDisplayList::Opcode_G_SETTILE(uint64_t data, int i, std::string prefix, ch ssss, dd, bbbb, uuuu); } -void ZDisplayList::Opcode_G_SETTILESIZE(uint64_t data, int index, std::string prefix, char* line) +void ZDisplayList::Opcode_G_SETTILESIZE(uint64_t data, std::string prefix, char* line) { - int sss = (data & 0x00FFF00000000000) >> 44; - int ttt = (data & 0x00000FFF00000000) >> 32; - int uuu = (data & 0x0000000000FFF000) >> 12; - int vvv = (data & 0x0000000000000FFF); - int i = (data & 0x000000000F000000) >> 24; + int32_t sss = (data & 0x00FFF00000000000) >> 44; + int32_t ttt = (data & 0x00000FFF00000000) >> 32; + int32_t uuu = (data & 0x0000000000FFF000) >> 12; + int32_t vvv = (data & 0x0000000000000FFF); + int32_t i = (data & 0x000000000F000000) >> 24; - int shiftAmtW = 2; - int shiftAmtH = 2; + int32_t shiftAmtW = 2; + int32_t shiftAmtH = 2; if (lastTexSizTest == F3DZEXTexSizes::G_IM_SIZ_8b && lastTexFmt == F3DZEXTexFormats::G_IM_FMT_IA) @@ -1059,41 +1043,37 @@ void ZDisplayList::Opcode_G_SETTILESIZE(uint64_t data, int index, std::string pr sprintf(line, "gsDPSetTileSize(%i, %i, %i, %i, %i),", i, sss, ttt, uuu, vvv); } -void ZDisplayList::Opcode_G_LOADBLOCK(uint64_t data, int index, std::string prefix, char* line) +void ZDisplayList::Opcode_G_LOADBLOCK(uint64_t data, char* line) { - int sss = (data & 0x00FFF00000000000) >> 48; - int ttt = (data & 0x00000FFF00000000) >> 36; - int i = (data & 0x000000000F000000) >> 24; - int xxx = (data & 0x0000000000FFF000) >> 12; - int ddd = (data & 0x0000000000000FFF); - - // lastTexHeight = (ddd + 1) / 16; + int32_t sss = (data & 0x00FFF00000000000) >> 48; + int32_t ttt = (data & 0x00000FFF00000000) >> 36; + int32_t i = (data & 0x000000000F000000) >> 24; + int32_t xxx = (data & 0x0000000000FFF000) >> 12; + int32_t ddd = (data & 0x0000000000000FFF); lastTexLoaded = true; - // TextureGenCheck(prefix); - sprintf(line, "gsDPLoadBlock(%i, %i, %i, %i, %i),", i, sss, ttt, xxx, ddd); } -void ZDisplayList::Opcode_G_SETCOMBINE(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_SETCOMBINE(uint64_t data, char* line) { - int a0 = (data & 0b000000011110000000000000000000000000000000000000000000000000000) >> 52; - int c0 = (data & 0b000000000001111100000000000000000000000000000000000000000000000) >> 47; - int aa0 = (data & 0b00000000000000011100000000000000000000000000000000000000000000) >> 44; - int ac0 = (data & 0b00000000000000000011100000000000000000000000000000000000000000) >> 41; - int a1 = (data & 0b000000000000000000000011110000000000000000000000000000000000000) >> 37; - int c1 = (data & 0b000000000000000000000000001111100000000000000000000000000000000) >> 32; - int b0 = (data & 0b000000000000000000000000000000011110000000000000000000000000000) >> 28; - int b1 = (data & 0b000000000000000000000000000000000001111000000000000000000000000) >> 24; - int aa1 = (data & 0b00000000000000000000000000000000000000111000000000000000000000) >> 21; - int ac1 = (data & 0b00000000000000000000000000000000000000000111000000000000000000) >> 18; - int d0 = (data & 0b000000000000000000000000000000000000000000000111000000000000000) >> 15; - int ab0 = (data & 0b00000000000000000000000000000000000000000000000111000000000000) >> 12; - int ad0 = (data & 0b00000000000000000000000000000000000000000000000000111000000000) >> 9; - int d1 = (data & 0b000000000000000000000000000000000000000000000000000000111000000) >> 6; - int ab1 = (data & 0b00000000000000000000000000000000000000000000000000000000111000) >> 3; - int ad1 = (data & 0b00000000000000000000000000000000000000000000000000000000000111) >> 0; + int32_t a0 = (data & 0b000000011110000000000000000000000000000000000000000000000000000) >> 52; + int32_t c0 = (data & 0b000000000001111100000000000000000000000000000000000000000000000) >> 47; + int32_t aa0 = (data & 0b00000000000000011100000000000000000000000000000000000000000000) >> 44; + int32_t ac0 = (data & 0b00000000000000000011100000000000000000000000000000000000000000) >> 41; + int32_t a1 = (data & 0b000000000000000000000011110000000000000000000000000000000000000) >> 37; + int32_t c1 = (data & 0b000000000000000000000000001111100000000000000000000000000000000) >> 32; + int32_t b0 = (data & 0b000000000000000000000000000000011110000000000000000000000000000) >> 28; + int32_t b1 = (data & 0b000000000000000000000000000000000001111000000000000000000000000) >> 24; + int32_t aa1 = (data & 0b00000000000000000000000000000000000000111000000000000000000000) >> 21; + int32_t ac1 = (data & 0b00000000000000000000000000000000000000000111000000000000000000) >> 18; + int32_t d0 = (data & 0b000000000000000000000000000000000000000000000111000000000000000) >> 15; + int32_t ab0 = (data & 0b00000000000000000000000000000000000000000000000111000000000000) >> 12; + int32_t ad0 = (data & 0b00000000000000000000000000000000000000000000000000111000000000) >> 9; + int32_t d1 = (data & 0b000000000000000000000000000000000000000000000000000000111000000) >> 6; + int32_t ab1 = (data & 0b00000000000000000000000000000000000000000000000000000000111000) >> 3; + int32_t ad1 = (data & 0b00000000000000000000000000000000000000000000000000000000000111) >> 0; string modesA[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT", "1", "NOISE", "0", "9", "10", "11", @@ -1150,34 +1130,33 @@ void ZDisplayList::Opcode_G_SETCOMBINE(uint64_t data, int i, std::string prefix, modes2[aa1].c_str(), modes2[ab1].c_str(), modes2C[ac1].c_str(), modes2[ad1].c_str()); } -void ZDisplayList::Opcode_G_SETPRIMCOLOR(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_SETPRIMCOLOR(uint64_t data, char* line) { - int mm = (data & 0x0000FF0000000000) >> 40; - int ff = (data & 0x000000FF00000000) >> 32; - int rr = (data & 0x00000000FF000000) >> 24; - int gg = (data & 0x0000000000FF0000) >> 16; - int bb = (data & 0x000000000000FF00) >> 8; - int aa = (data & 0x00000000000000FF) >> 0; + int32_t mm = (data & 0x0000FF0000000000) >> 40; + int32_t ff = (data & 0x000000FF00000000) >> 32; + int32_t rr = (data & 0x00000000FF000000) >> 24; + int32_t gg = (data & 0x0000000000FF0000) >> 16; + int32_t bb = (data & 0x000000000000FF00) >> 8; + int32_t aa = (data & 0x00000000000000FF) >> 0; sprintf(line, "gsDPSetPrimColor(%i, %i, %i, %i, %i, %i),", mm, ff, rr, gg, bb, aa); } -void ZDisplayList::Opcode_F3DEX_G_SETOTHERMODE_L(uint64_t data, int i, std::string prefix, - char* line) +void ZDisplayList::Opcode_F3DEX_G_SETOTHERMODE_L(uint64_t data, char* line) { - int sft = (data & 0x0000FF0000000000) >> 40; - int len = (data & 0x000000FF00000000) >> 32; - int dat = (data & 0xFFFFFFFF); + int32_t sft = (data & 0x0000FF0000000000) >> 40; + int32_t len = (data & 0x000000FF00000000) >> 32; + int32_t dat = (data & 0xFFFFFFFF); // TODO: Output the correct render modes in data sprintf(line, "gsSPSetOtherMode(0xE2, %i, %i, 0x%08X),", sft, len, dat); } -void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, char* line) { - int dd = (data & 0xFFFFFFFF); - int sft = 0; - int len = 0; + int32_t dd = (data & 0xFFFFFFFF); + int32_t sft = 0; + int32_t len = 0; if (dListType == DListType::F3DEX) { @@ -1186,7 +1165,7 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string pre } else { - int ss = (data & 0x0000FF0000000000) >> 40; + int32_t ss = (data & 0x0000FF0000000000) >> 40; len = ((data & 0x000000FF00000000) >> 32) + 1; sft = 32 - (len)-ss; } @@ -1419,7 +1398,7 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string pre if (mode2Str == "") { - int remainingFlags = mode2; + int32_t remainingFlags = mode2; if (mode2 & AA_EN) { @@ -1475,7 +1454,7 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string pre remainingFlags ^= CVG_DST_SAVE; } - int zMode = mode2 & 0xC00; + int32_t zMode = mode2 & 0xC00; if (zMode == ZMODE_INTER) { @@ -1511,10 +1490,10 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string pre remainingFlags ^= FORCE_BL; } - int bp = (mode2 >> 28) & 0b11; - int ba = (mode2 >> 24) & 0b11; - int bm = (mode2 >> 20) & 0b11; - int bb = (mode2 >> 16) & 0b11; + int32_t bp = (mode2 >> 28) & 0b11; + int32_t ba = (mode2 >> 24) & 0b11; + int32_t bm = (mode2 >> 20) & 0b11; + int32_t bb = (mode2 >> 16) & 0b11; mode2Str += StringHelper::Sprintf("GBL_c2(%i, %i, %i, %i)", bp, ba, bm, bb); // mode2Str = StringHelper::Sprintf("0x%08X", mode2); @@ -1528,13 +1507,13 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string pre } } -void ZDisplayList::Opcode_G_SETOTHERMODE_H(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_SETOTHERMODE_H(uint64_t data, char* line) { - int ss = (data & 0x0000FF0000000000) >> 40; - int nn = (data & 0x000000FF00000000) >> 32; - int dd = (data & 0xFFFFFFFF); + int32_t ss = (data & 0x0000FF0000000000) >> 40; + int32_t nn = (data & 0x000000FF00000000) >> 32; + int32_t dd = (data & 0xFFFFFFFF); - int sft = 32 - (nn + 1) - ss; + int32_t sft = 32 - (nn + 1) - ss; if (sft == 14) // G_MDSFT_TEXTLUT { @@ -1545,10 +1524,10 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_H(uint64_t data, int i, std::string pre sprintf(line, "gsSPSetOtherMode(0xE3, %i, %i, 0x%08X),", sft, nn + 1, dd); } -void ZDisplayList::Opcode_G_LOADTLUT(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_LOADTLUT(uint64_t data, std::string prefix, char* line) { - int t = (data & 0x0000000007000000) >> 24; - int ccc = (data & 0x00000000003FF000) >> 14; + int32_t t = (data & 0x0000000007000000) >> 24; + int32_t ccc = (data & 0x00000000003FF000) >> 14; lastTexWidth = sqrt(ccc + 1); lastTexHeight = sqrt(ccc + 1); @@ -1564,7 +1543,7 @@ void ZDisplayList::Opcode_G_LOADTLUT(uint64_t data, int i, std::string prefix, c sprintf(line, "gsDPLoadTLUTCmd(%i, %i),", t, ccc); } -void ZDisplayList::Opcode_G_ENDDL(uint64_t data, int i, std::string prefix, char* line) +void ZDisplayList::Opcode_G_ENDDL(std::string prefix, char* line) { sprintf(line, "gsSPEndDisplayList(),"); @@ -1579,7 +1558,7 @@ string ZDisplayList::GetSourceOutputHeader(const std::string& prefix) return ""; } -static int GfxdCallback_FormatSingleEntry(void) +static int32_t GfxdCallback_FormatSingleEntry(void) { gfxd_puts("\t"); gfxd_macro_dflt(); @@ -1594,10 +1573,10 @@ static int GfxdCallback_FormatSingleEntry(void) return 0; } -static int GfxdCallback_Vtx(uint32_t seg, int32_t count) +static int32_t GfxdCallback_Vtx(uint32_t seg, int32_t count) { - ZDisplayList* instance = ZDisplayList::static_instance; - uint32_t vtxOffset = Seg2Filespace(seg, instance->parent->baseAddress); + ZDisplayList* self = static_cast(gfxd_udata_get()); + uint32_t vtxOffset = Seg2Filespace(seg, self->parent->baseAddress); string vtxName = ""; if (!Globals::Instance->HasSegment( @@ -1607,15 +1586,15 @@ static int GfxdCallback_Vtx(uint32_t seg, int32_t count) } else { - instance->references.push_back(vtxOffset); + self->references.push_back(vtxOffset); // Check for vertex intersections from other display lists // TODO: These two could probably be condenced to one... - if (instance->parent->GetDeclarationRanged(vtxOffset + (count * 16)) != nullptr) + if (self->parent->GetDeclarationRanged(vtxOffset + (count * 16)) != nullptr) { - // Declaration* decl = instance->parent->GetDeclarationRanged(vtxOffset + (count * 16)); - uint32_t addr = instance->parent->GetDeclarationRangedAddress(vtxOffset + (count * 16)); - int diff = addr - vtxOffset; + // Declaration* decl = self->parent->GetDeclarationRanged(vtxOffset + (count * 16)); + uint32_t addr = self->parent->GetDeclarationRangedAddress(vtxOffset + (count * 16)); + int32_t diff = addr - vtxOffset; if (diff > 0) count = diff / 16; @@ -1623,11 +1602,11 @@ static int GfxdCallback_Vtx(uint32_t seg, int32_t count) count = 0; } - if (instance->parent->GetDeclarationRanged(vtxOffset) != nullptr) + if (self->parent->GetDeclarationRanged(vtxOffset) != nullptr) { - // Declaration* decl = instance->parent->GetDeclarationRanged(vtxOffset); - uint32_t addr = instance->parent->GetDeclarationRangedAddress(vtxOffset); - int diff = addr - vtxOffset; + // Declaration* decl = self->parent->GetDeclarationRanged(vtxOffset); + uint32_t addr = self->parent->GetDeclarationRangedAddress(vtxOffset); + int32_t diff = addr - vtxOffset; if (diff > 0) count = diff / 16; @@ -1641,13 +1620,13 @@ static int GfxdCallback_Vtx(uint32_t seg, int32_t count) vtxList.reserve(count); uint32_t currentPtr = vtxOffset; - for (int i = 0; i < count; i++) + for (int32_t i = 0; i < count; i++) { - Vertex vtx = Vertex(instance->fileData, currentPtr); + Vertex vtx = Vertex(self->fileData, currentPtr); vtxList.push_back(vtx); currentPtr += 16; } - instance->vertices[vtxOffset] = vtxList; + self->vertices[vtxOffset] = vtxList; } vtxName = "@r"; @@ -1658,23 +1637,23 @@ static int GfxdCallback_Vtx(uint32_t seg, int32_t count) return 1; } -static int GfxdCallback_Texture(uint32_t seg, int32_t fmt, int32_t siz, int32_t width, - int32_t height, int32_t pal) +static int32_t GfxdCallback_Texture(segptr_t seg, int32_t fmt, int32_t siz, int32_t width, + int32_t height, int32_t pal) { - ZDisplayList* instance = ZDisplayList::static_instance; - uint32_t texOffset = Seg2Filespace(seg, instance->parent->baseAddress); + ZDisplayList* self = static_cast(gfxd_udata_get()); + uint32_t texOffset = Seg2Filespace(seg, self->parent->baseAddress); uint32_t texSegNum = GETSEGNUM(seg); Declaration* texDecl = nullptr; string texName = ""; - if (instance->parent != nullptr && - texSegNum != 2) // HACK: Until we have declarations use segment addresses, we'll exclude - // scene references... + if (self->parent != nullptr && + texSegNum != SEGMENT_SCENE) // HACK: Until we have declarations use segment addresses, + // we'll exclude scene references... { - texDecl = instance->parent->GetDeclaration(texOffset); + texDecl = self->parent->GetDeclaration(texOffset); if (texDecl == nullptr) - texDecl = instance->parent->GetDeclaration(seg); + texDecl = self->parent->GetDeclaration(seg); } if (!Globals::Instance->HasSegment( @@ -1683,42 +1662,41 @@ static int GfxdCallback_Texture(uint32_t seg, int32_t fmt, int32_t siz, int32_t else if (texDecl != nullptr) texName = StringHelper::Sprintf("%s", texDecl->varName.c_str()); else if (texSegNum == 2) - texName = - StringHelper::Sprintf("%sTex_%06X", instance->scene->GetName().c_str(), texOffset); + texName = StringHelper::Sprintf("%sTex_%06X", self->scene->GetName().c_str(), texOffset); else - texName = StringHelper::Sprintf("%sTex_%06X", instance->curPrefix.c_str(), texOffset); + texName = StringHelper::Sprintf("%sTex_%06X", self->curPrefix.c_str(), texOffset); - instance->lastTexWidth = width; - instance->lastTexHeight = height; - instance->lastTexAddr = texOffset; - instance->lastTexSeg = seg; - instance->lastTexFmt = (F3DZEXTexFormats)fmt; - instance->lastTexSiz = (F3DZEXTexSizes)siz; - instance->lastTexLoaded = true; - instance->lastTexIsPalette = false; + self->lastTexWidth = width; + self->lastTexHeight = height; + self->lastTexAddr = texOffset; + self->lastTexSeg = seg; + self->lastTexFmt = static_cast(fmt); + self->lastTexSiz = static_cast(siz); + self->lastTexLoaded = true; + self->lastTexIsPalette = false; + + self->TextureGenCheck(self->curPrefix); - instance->TextureGenCheck(instance->curPrefix); gfxd_puts(texName.c_str()); return 1; } -static int GfxdCallback_Palette(uint32_t seg, int32_t idx, int32_t count) +static int32_t GfxdCallback_Palette(uint32_t seg, int32_t idx, int32_t count) { - ZDisplayList* instance = ZDisplayList::static_instance; - uint32_t palOffset = Seg2Filespace(seg, instance->parent->baseAddress); + ZDisplayList* self = static_cast(gfxd_udata_get()); + uint32_t palOffset = Seg2Filespace(seg, self->parent->baseAddress); uint32_t palSegNum = GETSEGNUM(seg); Declaration* palDecl = nullptr; string palName = ""; - if (instance->parent != nullptr && - palSegNum != 2) // HACK: Until we have declarations use segment addresses, we'll exclude - // scene references... + if (self->parent != nullptr && palSegNum != 2) // HACK: Until we have declarations use segment + // addresses, we'll exclude scene references... { - palDecl = instance->parent->GetDeclaration(palOffset); + palDecl = self->parent->GetDeclaration(palOffset); if (palDecl == nullptr) - palDecl = instance->parent->GetDeclaration(seg); + palDecl = self->parent->GetDeclaration(seg); } if (!Globals::Instance->HasSegment( @@ -1727,36 +1705,35 @@ static int GfxdCallback_Palette(uint32_t seg, int32_t idx, int32_t count) else if (palDecl != nullptr) palName = StringHelper::Sprintf("%s", palDecl->varName.c_str()); else if (palSegNum == 2) - palName = - StringHelper::Sprintf("%sTex_%06X", instance->scene->GetName().c_str(), palOffset); + palName = StringHelper::Sprintf("%sTex_%06X", self->scene->GetName().c_str(), palOffset); else - palName = StringHelper::Sprintf("%sTex_%06X", instance->curPrefix.c_str(), palOffset); + palName = StringHelper::Sprintf("%sTex_%06X", self->curPrefix.c_str(), palOffset); - instance->lastTexWidth = sqrt(count); - instance->lastTexHeight = sqrt(count); - instance->lastTexAddr = palOffset; - instance->lastTexSeg = seg; - instance->lastTexSiz = F3DZEXTexSizes::G_IM_SIZ_16b; - instance->lastTexFmt = F3DZEXTexFormats::G_IM_FMT_RGBA; - instance->lastTexLoaded = true; - instance->lastTexIsPalette = true; + self->lastTexWidth = sqrt(count); + self->lastTexHeight = sqrt(count); + self->lastTexAddr = palOffset; + self->lastTexSeg = seg; + self->lastTexSiz = F3DZEXTexSizes::G_IM_SIZ_16b; + self->lastTexFmt = F3DZEXTexFormats::G_IM_FMT_RGBA; + self->lastTexLoaded = true; + self->lastTexIsPalette = true; - instance->TextureGenCheck(instance->curPrefix); + self->TextureGenCheck(self->curPrefix); gfxd_puts(palName.c_str()); return 1; } -static int GfxdCallback_DisplayList(uint32_t seg) +static int32_t GfxdCallback_DisplayList(uint32_t seg) { - ZDisplayList* instance = ZDisplayList::static_instance; + ZDisplayList* self = static_cast(gfxd_udata_get()); uint32_t dListOffset = GETSEGOFFSET(seg); uint32_t dListSegNum = GETSEGNUM(seg); Declaration* dListDecl = nullptr; string dListName = ""; - if (instance->parent != nullptr) - dListDecl = instance->parent->GetDeclaration(dListOffset); + if (self->parent != nullptr) + dListDecl = self->parent->GetDeclaration(dListOffset); if (!Globals::Instance->HasSegment( dListSegNum)) // Probably an external asset we are unable to track @@ -1764,16 +1741,16 @@ static int GfxdCallback_DisplayList(uint32_t seg) else if (dListDecl != nullptr) dListName = StringHelper::Sprintf("%s", dListDecl->varName.c_str()); else - dListName = StringHelper::Sprintf("%sDL_%06X", instance->curPrefix.c_str(), dListOffset); + dListName = StringHelper::Sprintf("%sDL_%06X", self->curPrefix.c_str(), dListOffset); - if (dListSegNum <= 6) + if ((dListSegNum <= 6) && Globals::Instance->HasSegment(dListSegNum)) { ZDisplayList* newDList = new ZDisplayList( - instance->fileData, dListOffset, - instance->GetDListLength(instance->fileData, dListOffset, instance->dListType)); - newDList->scene = instance->scene; - newDList->parent = instance->parent; - instance->otherDLists.push_back(newDList); + self->fileData, dListOffset, + self->GetDListLength(self->fileData, dListOffset, self->dListType), self->parent); + newDList->scene = self->scene; + newDList->parent = self->parent; + self->otherDLists.push_back(newDList); } gfxd_puts(dListName.c_str()); @@ -1781,12 +1758,31 @@ static int GfxdCallback_DisplayList(uint32_t seg) return 1; } -static int GfxdCallback_Matrix(uint32_t seg) +static int32_t GfxdCallback_Matrix(uint32_t seg) { string mtxName = ""; + ZDisplayList* self = static_cast(gfxd_udata_get()); if (Globals::Instance->symbolMap.find(seg) != Globals::Instance->symbolMap.end()) mtxName = StringHelper::Sprintf("&%s", Globals::Instance->symbolMap[seg].c_str()); + else if (Globals::Instance->HasSegment(GETSEGNUM(seg))) + { + Declaration* decl = + self->parent->GetDeclaration(Seg2Filespace(seg, self->parent->baseAddress)); + if (decl == nullptr) + { + ZMtx mtx(self->GetName(), self->fileData, Seg2Filespace(seg, self->parent->baseAddress), + self->parent); + + mtx.GetSourceOutputCode(self->GetName()); + self->mtxList.push_back(mtx); + mtxName = "&" + mtx.GetName(); + } + else + { + mtxName = "&" + decl->varName; + } + } else mtxName = StringHelper::Sprintf("0x%08X", seg); @@ -1795,42 +1791,14 @@ static int GfxdCallback_Matrix(uint32_t seg) return 1; } -ZDisplayList* ZDisplayList::static_instance; - string ZDisplayList::GetSourceOutputCode(const std::string& prefix) { - OutputFormatter outputformatter; string sourceOutput = ""; - size_t dListSize = instructions.size() * sizeof(instructions[0]); - gfxd_input_buffer(instructions.data(), dListSize); - gfxd_endian(gfxd_endian_little, sizeof(uint64_t)); // tell gfxdis what format the data is - - gfxd_macro_fn(GfxdCallback_FormatSingleEntry); // format for each command entry - gfxd_vtx_callback(GfxdCallback_Vtx); // handle vertices - gfxd_timg_callback(GfxdCallback_Texture); // handle textures - gfxd_tlut_callback(GfxdCallback_Palette); // handle palettes - gfxd_dl_callback(GfxdCallback_DisplayList); // handle child display lists - gfxd_mtx_callback(GfxdCallback_Matrix); // handle matrices - gfxd_output_callback( - outputformatter.static_writer()); // convert tabs to 4 spaces and enforce 120 line limit - - gfxd_enable(gfxd_emit_dec_color); // use decimal for colors - - // set microcode. see gfxd.h for more options. - if (dListType == DListType::F3DZEX) - { - gfxd_target(gfxd_f3dex2); - } + if (Globals::Instance->useLegacyZDList) + sourceOutput += ProcessLegacy(prefix); else - { - gfxd_target(gfxd_f3dex); - } - - this->curPrefix = prefix; - static_instance = this; - gfxd_execute(); // generate display list - sourceOutput += outputformatter.get_output(); // write formatted display list + sourceOutput += ProcessGfxDis(prefix); // Iterate through our vertex lists, connect intersecting lists. if (vertices.size() > 0) @@ -1842,14 +1810,14 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) for (size_t i = 0; i < verticesSorted.size() - 1; i++) { - // int vtxSize = verticesSorted[i].second.size() * 16; + // int32_t vtxSize = verticesSorted[i].second.size() * 16; size_t vtxSize = vertices[verticesSorted[i].first].size() * 16; - if ((verticesSorted[i].first + (int)vtxSize) > verticesSorted[i + 1].first) + if ((verticesSorted[i].first + (int32_t)vtxSize) > verticesSorted[i + 1].first) { - int intersectAmt = + int32_t intersectAmt = (verticesSorted[i].first + vtxSize) - verticesSorted[i + 1].first; - int intersectIndex = intersectAmt / 16; + int32_t intersectIndex = intersectAmt / 16; for (size_t j = intersectIndex; j < verticesSorted[i + 1].second.size(); j++) { @@ -1860,7 +1828,7 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) // 0x%06X)\n", prefix.c_str(), verticesSorted[i + 1].first, prefix.c_str(), // verticesSorted[i].first, verticesSorted[i + 1].first - verticesSorted[i].first); - // int nSize = (int)vertices[verticesSorted[i].first].size(); + // isize_t nSize = (int32_t)vertices[verticesSorted[i].first].size(); vertices.erase(verticesSorted[i + 1].first); verticesSorted.erase(verticesSorted.begin() + i + 1); @@ -1877,7 +1845,7 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) { string declaration = ""; - int curAddr = item.first; + int32_t curAddr = item.first; for (Vertex vtx : item.second) { @@ -1916,13 +1884,10 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) for (size_t i = 0; i < texturesSorted.size() - 1; i++) { - int texSize = scene->textures[texturesSorted[i].first]->GetRawDataSize(); + int32_t texSize = scene->textures[texturesSorted[i].first]->GetRawDataSize(); if ((texturesSorted[i].first + texSize) > texturesSorted[i + 1].first) { - // int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + - // 1].first; - defines += StringHelper::Sprintf( "#define %sTex_%06X ((u32)%sTex_%06X + 0x%06X)\n", scene->GetName().c_str(), texturesSorted[i + 1].first, scene->GetName().c_str(), @@ -1951,12 +1916,12 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) if (texturesSorted.size() == 0) // ????? break; - int texSize = textures[texturesSorted[i].first]->GetRawDataSize(); + int32_t texSize = textures[texturesSorted[i].first]->GetRawDataSize(); if ((texturesSorted[i].first + texSize) > texturesSorted[i + 1].first) { - // int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + - // 1].first; + // int32_t intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + // + 1].first; // If we're working with a palette, resize it to its "real" dimensions if (texturesSorted[i].second->isPalette) @@ -1993,19 +1958,30 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) { if (parent->GetDeclaration(item.first) == nullptr) { - if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) - printf("SAVING IMAGE TO %s\n", Globals::Instance->outputPath.c_str()); + // TEXTURE POOL CHECK + std::string texOutPath = + item.second->GetPoolOutPath(Globals::Instance->outputPath); + std::string texOutName = item.second->GetName(); - item.second->Save(Globals::Instance->outputPath); + auto start = chrono::steady_clock::now(); + item.second->Save(texOutPath); + auto end = chrono::steady_clock::now(); + auto diff = chrono::duration_cast(end - start).count(); + + if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) + printf("SAVED IMAGE TO %s in %ims\n", Globals::Instance->outputPath.c_str(), + (int32_t)diff); + + auto filepath = Globals::Instance->outputPath / + Path::GetFileNameWithoutExtension(item.second->GetName()); + std::string incStr = + StringHelper::Sprintf("%s.%s.inc.c", filepath.c_str(), + item.second->GetExternalExtension().c_str()); + std::string texName = + StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first); parent->AddDeclarationIncludeArray( - item.first, - StringHelper::Sprintf( - "%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(), - Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(), - item.second->GetExternalExtension().c_str()), - item.second->GetRawDataSize(), "u64", - StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first), 0); + item.first, incStr, item.second->GetRawDataSize(), "u64", texName, 0); } } } @@ -2015,15 +1991,181 @@ string ZDisplayList::GetSourceOutputCode(const std::string& prefix) { Declaration* decl = parent->AddDeclarationArray( rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), "Gfx", - StringHelper::Sprintf("%s", name.c_str()), 0, sourceOutput); + StringHelper::Sprintf("%s", name.c_str()), 0, sourceOutput, true); decl->references = references; + // return ""; + // return sourceOutput; + } + + // Iterate through our vertex lists, connect intersecting lists. + if (vertices.size() > 0) + { + vector>> verticesSorted(vertices.begin(), vertices.end()); + + sort(verticesSorted.begin(), verticesSorted.end(), + [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); + + for (size_t i = 0; i < verticesSorted.size() - 1; i++) + { + // int32_t vtxSize = verticesSorted[i].second.size() * 16; + size_t vtxSize = vertices[verticesSorted[i].first].size() * 16; + + if ((verticesSorted[i].first + vtxSize) > verticesSorted[i + 1].first) + { + int32_t intersectAmt = + (verticesSorted[i].first + vtxSize) - verticesSorted[i + 1].first; + int32_t intersectIndex = intersectAmt / 16; + + for (size_t j = intersectIndex; j < verticesSorted[i + 1].second.size(); j++) + vertices[verticesSorted[i].first].push_back(verticesSorted[i + 1].second[j]); + + vertices.erase(verticesSorted[i + 1].first); + verticesSorted.erase(verticesSorted.begin() + i + 1); + + i--; + } + } + + if (scene == nullptr) // TODO: Bit of a hack but it works for now... + parent->defines += defines; + + // Generate Vertex Declarations + vector vtxKeys; + + for (pair> item : vertices) + vtxKeys.push_back(item.first); + + // for (pair> item : vertices) + for (size_t i = 0; i < vtxKeys.size(); i++) + { + vector item = vertices[vtxKeys[i]]; + + string declaration = ""; + + int32_t curAddr = vtxKeys[i]; + + for (Vertex vtx : item) + { + if (curAddr != vtxKeys[i]) + declaration += "\n"; + + declaration += + StringHelper::Sprintf(" VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i),", vtx.x, + vtx.y, vtx.z, vtx.s, vtx.t, vtx.r, vtx.g, vtx.b, vtx.a); + + curAddr += 16; + } + + // Ensure there's always a trailing line feed to prevent dumb warnings. + // Please don't remove this line, unless you somehow made a way to prevent + // that warning when building the OoT repo. + declaration += "\n"; + + vtxDeclarations[vtxKeys[i]] = declaration; + + if (parent != nullptr) + { + std::string vtxName = + StringHelper::Sprintf("%sVtx_%06X", prefix.c_str(), vtxKeys[i]); + + auto filepath = Globals::Instance->outputPath / vtxName; + std::string incStr = StringHelper::Sprintf("%s.%s.inc", filepath.c_str(), "vtx"); + + parent->AddDeclarationArray(vtxKeys[i], DeclarationAlignment::None, + item.size() * 16, "static Vtx", vtxName, item.size(), + declaration); + + Declaration* vtxDecl = parent->AddDeclarationIncludeArray( + vtxKeys[i], incStr, item.size() * 16, "static Vtx", vtxName, item.size()); + vtxDecl->isExternal = true; + } + } + } + + if (parent != nullptr) return ""; + + return sourceOutput; +} + +std::string ZDisplayList::ProcessLegacy(const std::string& prefix) +{ + char line[4096]; + string sourceOutput = ""; + + for (size_t i = 0; i < instructions.size(); i++) + { + uint8_t opcode = (uint8_t)(instructions[i] >> 56); + uint64_t data = instructions[i]; + sourceOutput += " "; + + auto start = chrono::steady_clock::now(); + + int32_t optimizationResult = OptimizationChecks(i, sourceOutput, prefix); + + if (optimizationResult != -1) + { + i += optimizationResult - 1; + line[0] = '\0'; + } + else + { + if (dListType == DListType::F3DZEX) + ParseF3DZEX((F3DZEXOpcode)opcode, data, i, prefix, line); + else + ParseF3DEX((F3DEXOpcode)opcode, data, prefix, line); + } + + auto end = chrono::steady_clock::now(); + auto diff = chrono::duration_cast(end - start).count(); + + if (Globals::Instance->verbosity >= VERBOSITY_DEBUG && diff > 5) + printf("F3DOP: 0x%02X, TIME: %lims\n", opcode, diff); + + sourceOutput += line; + + if (i < instructions.size() - 1) + sourceOutput += "\n"; } return sourceOutput; } -// HOTSPOT +std::string ZDisplayList::ProcessGfxDis(const std::string& prefix) +{ + string sourceOutput = ""; + + OutputFormatter outputformatter; + int32_t dListSize = instructions.size() * sizeof(instructions[0]); + + gfxd_input_buffer(instructions.data(), dListSize); + gfxd_endian(gfxd_endian_little, sizeof(uint64_t)); // tell gfxdis what format the data is + + gfxd_macro_fn(GfxdCallback_FormatSingleEntry); // format for each command entry + gfxd_vtx_callback(GfxdCallback_Vtx); // handle vertices + gfxd_timg_callback(GfxdCallback_Texture); // handle textures + gfxd_tlut_callback(GfxdCallback_Palette); // handle palettes + gfxd_dl_callback(GfxdCallback_DisplayList); // handle child display lists + gfxd_mtx_callback(GfxdCallback_Matrix); // handle matrices + gfxd_output_callback( + outputformatter.StaticWriter()); // convert tabs to 4 spaces and enforce 120 line limit + + gfxd_enable(gfxd_emit_dec_color); // use decimal for colors + + // set microcode. see gfxd.h for more options. + if (dListType == DListType::F3DZEX) + gfxd_target(gfxd_f3dex2); + else + gfxd_target(gfxd_f3dex); + + this->curPrefix = prefix; + gfxd_udata_set(this); + gfxd_execute(); // generate display list + sourceOutput += outputformatter.GetOutput(); // write formatted display list + + return sourceOutput; +} + void ZDisplayList::TextureGenCheck(string prefix) { if (TextureGenCheck(fileData, textures, scene, parent, prefix, lastTexWidth, lastTexHeight, @@ -2036,30 +2178,29 @@ void ZDisplayList::TextureGenCheck(string prefix) } } -// HOTSPOT bool ZDisplayList::TextureGenCheck(vector fileData, map& textures, - ZRoom* scene, ZFile* parent, string prefix, uint32_t texWidth, - uint32_t texHeight, uint32_t texAddr, uint32_t texSeg, + ZRoom* scene, ZFile* parent, string prefix, int32_t texWidth, + int32_t texHeight, uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette) { - int segmentNumber = GETSEGNUM(texSeg); + int32_t segmentNumber = GETSEGNUM(texSeg); if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) printf("TextureGenCheck seg=%i width=%i height=%i ispal=%i addr=0x%06X\n", segmentNumber, texWidth, texHeight, texIsPalette, texAddr); - if ((texSeg != 0 || texAddr != 0) && texWidth != 0 && texHeight != 0 && texLoaded && + if ((texSeg != 0 || texAddr != 0) && texWidth > 0 && texHeight > 0 && texLoaded && Globals::Instance->HasSegment(segmentNumber)) { - if (segmentNumber != 2) // Not from a scene file + if (segmentNumber != SEGMENT_SCENE) { - ZTexture* tex = ZTexture::FromBinary( - TexFormatToTexType(texFmt, texSiz), fileData, texAddr, - StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), texAddr), texWidth, texHeight); + ZTexture* tex = + ZTexture::FromBinary(TexFormatToTexType(texFmt, texSiz), fileData, texAddr, + StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), texAddr), + texWidth, texHeight, parent); tex->isPalette = texIsPalette; textures[texAddr] = tex; - return true; } else @@ -2068,22 +2209,23 @@ bool ZDisplayList::TextureGenCheck(vector fileData, mapGetRawData(), texAddr, StringHelper::Sprintf("%sTex_%06X", Globals::Instance->lastScene->GetName().c_str(), texAddr), - texWidth, texHeight); + texWidth, texHeight, parent); if (scene != nullptr) { scene->textures[texAddr] = tex; + + auto filepath = Globals::Instance->outputPath / + Path::GetFileNameWithoutExtension(tex->GetName()); scene->parent->AddDeclarationIncludeArray( texAddr, - StringHelper::Sprintf("%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(), - Path::GetFileNameWithoutExtension(tex->GetName()).c_str(), + StringHelper::Sprintf("%s.%s.inc.c", filepath.c_str(), tex->GetExternalExtension().c_str()), tex->GetRawDataSize(), "u64", StringHelper::Sprintf("%sTex_%06X", Globals::Instance->lastScene->GetName().c_str(), texAddr), 0); } - return true; } } @@ -2102,10 +2244,15 @@ TextureType ZDisplayList::TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSize } else if (fmt == F3DZEXTexFormats::G_IM_FMT_CI) { - if (siz == F3DZEXTexSizes::G_IM_SIZ_4b) - return TextureType::Palette4bpp; - else if (siz == F3DZEXTexSizes::G_IM_SIZ_8b) + if (Globals::Instance->useLegacyZDList) return TextureType::Palette8bpp; + else + { + if (siz == F3DZEXTexSizes::G_IM_SIZ_4b) + return TextureType::Palette4bpp; + else if (siz == F3DZEXTexSizes::G_IM_SIZ_8b) + return TextureType::Palette8bpp; + } } else if (fmt == F3DZEXTexFormats::G_IM_FMT_IA) { @@ -2131,19 +2278,6 @@ TextureType ZDisplayList::TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSize void ZDisplayList::Save(const std::string& outFolder) { - // HLModelIntermediette* mdl = HLModelIntermediette::FromZDisplayList(this); - - // For testing purposes only at the moment... - // if (Globals::Instance->testMode) - //{ - // string xml = mdl->OutputXML(); - // string obj = mdl->ToOBJFile(); - // string fbx = mdl->ToFBXFile(); - - // File::WriteAllText(outFolder + "/" + name + ".mdli", xml); - // File::WriteAllText(outFolder + "/" + name + ".obj", obj); - // File::WriteAllText(outFolder + "/" + name + ".fbx", fbx); - //} } void ZDisplayList::GenerateHLIntermediette(HLFileIntermediette& hlFile) @@ -2153,19 +2287,29 @@ void ZDisplayList::GenerateHLIntermediette(HLFileIntermediette& hlFile) mdl->blocks.push_back(new HLTerminator()); } +bool ZDisplayList::IsExternalResource() +{ + return false; +} + +std::string ZDisplayList::GetExternalExtension() +{ + return "dlist"; +} + +std::string ZDisplayList::GetSourceTypeName() +{ + return "Gfx"; +} + ZResourceType ZDisplayList::GetResourceType() { return ZResourceType::DisplayList; } -vector ZDisplayList::GetRawData() +size_t ZDisplayList::GetRawDataSize() { - return rawData; -} - -int ZDisplayList::GetRawDataSize() -{ - return (int)instructions.size() * 8; + return instructions.size() * 8; } Vertex::Vertex() @@ -2197,7 +2341,7 @@ Vertex::Vertex(int16_t nX, int16_t nY, int16_t nZ, uint16_t nFlag, int16_t nS, i a = nA; } -Vertex::Vertex(std::vector rawData, int rawDataIndex) +Vertex::Vertex(std::vector rawData, uint32_t rawDataIndex) { const uint8_t* data = rawData.data(); diff --git a/tools/ZAPD/ZAPD/ZDisplayList.h b/tools/ZAPD/ZAPD/ZDisplayList.h index c3f3f8b1c4..f390720a2b 100644 --- a/tools/ZAPD/ZAPD/ZDisplayList.h +++ b/tools/ZAPD/ZAPD/ZDisplayList.h @@ -1,5 +1,6 @@ #pragma once +#include "ZMtx.h" #include "ZResource.h" #include "ZRoom/ZRoom.h" #include "ZTexture.h" @@ -292,7 +293,7 @@ public: Vertex(); Vertex(int16_t nX, int16_t nY, int16_t nZ, uint16_t nFlag, int16_t nS, int16_t nT, uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA); - Vertex(std::vector rawData, int rawDataIndex); + Vertex(std::vector rawData, uint32_t rawDataIndex); }; class ZDisplayList : public ZResource @@ -301,37 +302,39 @@ protected: static TextureType TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSizes siz); void ParseRawData() override; - void ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::string prefix, char* line); - void ParseF3DEX(F3DEXOpcode opcode, uint64_t data, int i, std::string prefix, char* line); + void ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, std::string prefix, char* line); + void ParseF3DEX(F3DEXOpcode opcode, uint64_t data, std::string prefix, char* line); // Various Instruction Optimizations - bool SequenceCheck(std::vector sequence, int startIndex); - int OptimizationChecks(int startIndex, std::string& output, std::string prefix); - int OptimizationCheck_LoadTextureBlock(int startIndex, std::string& output, std::string prefix); - int OptimizationCheck_LoadMultiBlock(int startIndex, std::string& output, std::string prefix); + bool SequenceCheck(std::vector sequence, int32_t startIndex); + int32_t OptimizationChecks(int32_t startIndex, std::string& output, std::string prefix); + int32_t OptimizationCheck_LoadTextureBlock(int32_t startIndex, std::string& output, + std::string prefix); + // int32_t OptimizationCheck_LoadMultiBlock(int32_t startIndex, std::string& output, std::string + // prefix); // F3DEX Specific Opcode Values - void Opcode_F3DEX_G_SETOTHERMODE_L(uint64_t data, int i, std::string prefix, char* line); + void Opcode_F3DEX_G_SETOTHERMODE_L(uint64_t data, char* line); // Shared Opcodes between F3DZEX and F3DEX - void Opcode_G_DL(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_MODIFYVTX(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_CULLDL(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_TRI1(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_TRI2(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_MTX(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_VTX(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_TEXTURE(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_SETTIMG(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_SETTILE(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_SETTILESIZE(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_LOADBLOCK(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_SETCOMBINE(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_SETPRIMCOLOR(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_SETOTHERMODE_L(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_SETOTHERMODE_H(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_LOADTLUT(uint64_t data, int i, std::string prefix, char* line); - void Opcode_G_ENDDL(uint64_t data, int i, std::string prefix, char* line); + void Opcode_G_DL(uint64_t data, std::string prefix, char* line); + void Opcode_G_MODIFYVTX(uint64_t data, char* line); + void Opcode_G_CULLDL(uint64_t data, char* line); + void Opcode_G_TRI1(uint64_t data, char* line); + void Opcode_G_TRI2(uint64_t data, char* line); + void Opcode_G_MTX(uint64_t data, char* line); + void Opcode_G_VTX(uint64_t data, char* line); + void Opcode_G_TEXTURE(uint64_t data, char* line); + void Opcode_G_SETTIMG(uint64_t data, std::string prefix, char* line); + void Opcode_G_SETTILE(uint64_t data, char* line); + void Opcode_G_SETTILESIZE(uint64_t data, std::string prefix, char* line); + void Opcode_G_LOADBLOCK(uint64_t data, char* line); + void Opcode_G_SETCOMBINE(uint64_t data, char* line); + void Opcode_G_SETPRIMCOLOR(uint64_t data, char* line); + void Opcode_G_SETOTHERMODE_L(uint64_t data, char* line); + void Opcode_G_SETOTHERMODE_H(uint64_t data, char* line); + void Opcode_G_LOADTLUT(uint64_t data, std::string prefix, char* line); + void Opcode_G_ENDDL(std::string prefix, char* line); public: std::string sceneSegName; @@ -339,7 +342,7 @@ public: std::vector instructions; std::string curPrefix; - uint32_t lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg; + int32_t lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg; F3DZEXTexFormats lastTexFmt; F3DZEXTexSizes lastTexSiz, lastTexSizTest, lastCISiz; bool lastTexLoaded; @@ -347,7 +350,7 @@ public: DListType dListType; - // int dListAddress; + // int32_t dListAddress; std::map> vertices; std::map vtxDeclarations; @@ -360,31 +363,39 @@ public: std::string defines; // Hack for special cases where vertex arrays intersect... std::vector fileData; + std::vector mtxList; - ZDisplayList(); - ZDisplayList(std::vector nRawData, int rawDataIndex, int rawDataSize); + ZDisplayList(ZFile* nParent); + ZDisplayList(std::vector nRawData, uint32_t rawDataIndex, int32_t rawDataSize, + ZFile* nParent); + ~ZDisplayList(); - static ZDisplayList* static_instance; - static ZDisplayList* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, - int rawDataIndex, int rawDataSize, std::string nRelPath); - static ZDisplayList* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, - bool readFile); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; + // static ZDisplayList* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, bool + // readFile, ZFile* nParent); void TextureGenCheck(std::string prefix); static bool TextureGenCheck(std::vector fileData, std::map& textures, ZRoom* scene, - ZFile* parent, std::string prefix, uint32_t texWidth, - uint32_t texHeight, uint32_t texAddr, uint32_t texSeg, + ZFile* parent, std::string prefix, int32_t texWidth, + int32_t texHeight, uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette); - static int GetDListLength(std::vector rawData, int rawDataIndex, DListType dListType); + static int32_t GetDListLength(std::vector rawData, uint32_t rawDataIndex, + DListType dListType); - std::vector GetRawData() override; - int GetRawDataSize() override; + size_t GetRawDataSize() override; std::string GetSourceOutputHeader(const std::string& prefix) override; std::string GetSourceOutputCode(const std::string& prefix) override; + std::string ProcessLegacy(const std::string& prefix); + std::string ProcessGfxDis(const std::string& prefix); + void Save(const std::string& outFolder) override; virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile) override; + bool IsExternalResource() override; + virtual std::string GetExternalExtension() override; + std::string GetSourceTypeName() override; ZResourceType GetResourceType() override; }; diff --git a/tools/ZAPD/ZAPD/ZFile.cpp b/tools/ZAPD/ZAPD/ZFile.cpp index 75eb9bc1a3..fa6ad07a41 100644 --- a/tools/ZAPD/ZAPD/ZFile.cpp +++ b/tools/ZAPD/ZAPD/ZFile.cpp @@ -1,18 +1,22 @@ #include "ZFile.h" #include #include +#include #include "Directory.h" #include "File.h" #include "Globals.h" #include "HighLevel/HLModelIntermediette.h" +#include "OutputFormatter.h" #include "Path.h" #include "ZAnimation.h" #include "ZArray.h" +#include "ZBackground.h" #include "ZBlob.h" #include "ZCollision.h" #include "ZCutscene.h" #include "ZDisplayList.h" #include "ZLimb.h" +#include "ZMtx.h" #include "ZRoom/ZRoom.h" #include "ZScalar.h" #include "ZSkeleton.h" @@ -36,16 +40,18 @@ ZFile::ZFile() rangeEnd = 0xFFFFFFFF; } -ZFile::ZFile(string nOutPath, string nName) : ZFile() +ZFile::ZFile(const fs::path& nOutPath, string nName) : ZFile() { outputPath = nOutPath; name = nName; } -ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPath, - std::string filename, bool placeholderMode) +ZFile::ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBasePath, + const fs::path& nOutPath, std::string filename, const fs::path& nXmlFilePath, + bool placeholderMode) : ZFile() { + xmlFilePath = nXmlFilePath; if (nBasePath == "") basePath = Directory::GetCurrentDirectory(); else @@ -62,7 +68,14 @@ ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPa ZFile::~ZFile() { for (ZResource* res : resources) + { delete res; + } + + for (auto d : declarations) + { + delete d.second; + } } void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, bool placeholderMode) @@ -72,7 +85,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b else name = filename; - int segment = -1; + int32_t segment = -1; // TODO: This should be a variable on the ZFile, but it is a large change in order to force all // ZResource types to have a parent ZFile. @@ -80,17 +93,14 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b if (reader->Attribute("Game") != nullptr) { if (string(gameStr) == "MM") - { Globals::Instance->game = ZGame::MM_RETAIL; - } else if (string(gameStr) == "SW97" || string(gameStr) == "OOTSW97") - { Globals::Instance->game = ZGame::OOT_SW97; - } + else if (string(gameStr) == "OOT") + Globals::Instance->game = ZGame::OOT_RETAIL; else - { - // TODO: Error here. - } + throw std::runtime_error( + StringHelper::Sprintf("Error: Game type %s not supported.", gameStr)); } if (reader->Attribute("BaseAddress") != NULL) @@ -110,337 +120,120 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b if (segment != -1) { - // printf("Adding Segment %i\n", segment); Globals::Instance->AddSegment(segment); } - string folderName = basePath + "/" + Path::GetFileNameWithoutExtension(name); + string folderName = basePath / Path::GetFileNameWithoutExtension(name); if (mode == ZFileMode::Extract) { - if (!File::Exists(basePath + "/" + name)) - throw StringHelper::Sprintf("Error! File %s does not exist.", - (basePath + "/" + name).c_str()); + if (!File::Exists(basePath / name)) + throw std::runtime_error( + StringHelper::Sprintf("Error! File %s does not exist.", (basePath / name).c_str())); - rawData = File::ReadAllBytes(basePath + "/" + name); + rawData = File::ReadAllBytes(basePath / name); } - int rawDataIndex = 0; + std::unordered_set nameSet; + std::unordered_set outNameSet; + std::unordered_set offsetSet; + + auto nodeMap = *GetNodeMap(); + uint32_t rawDataIndex = 0; for (XMLElement* child = reader->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) { - if (child->Attribute("Offset") != NULL) - rawDataIndex = - strtol(StringHelper::Split(child->Attribute("Offset"), "0x")[1].c_str(), NULL, 16); + const char* nameXml = child->Attribute("Name"); + const char* outNameXml = child->Attribute("OutName"); + const char* offsetXml = child->Attribute("Offset"); if (Globals::Instance->verbosity >= VERBOSITY_INFO) - printf("%s: 0x%06X\n", child->Attribute("Name"), rawDataIndex); + printf("%s: 0x%06X\n", nameXml, rawDataIndex); - if (string(child->Name()) == "Texture") + if (offsetXml != NULL) { - ZTexture* tex = nullptr; + rawDataIndex = strtol(StringHelper::Split(offsetXml, "0x")[1].c_str(), NULL, 16); - if (mode == ZFileMode::Extract) - tex = ZTexture::ExtractFromXML(child, rawData, rawDataIndex, folderName); - else - tex = ZTexture::BuildFromXML(child, folderName, mode == ZFileMode::Build); - - tex->SetRawDataIndex(rawDataIndex); - - tex->parent = this; - - resources.push_back(tex); - rawDataIndex += tex->GetRawDataSize(); + if (offsetSet.find(offsetXml) != offsetSet.end()) + { + throw std::runtime_error(StringHelper::Sprintf( + "ZFile::ParseXML: Error in '%s'.\n\t Repeated 'Offset' attribute: %s \n", + name.c_str(), offsetXml)); + } + offsetSet.insert(offsetXml); } - else if (string(child->Name()) == "Blob") + if (outNameXml != NULL) { - ZBlob* blob = nullptr; - - if (mode == ZFileMode::Extract) - blob = ZBlob::ExtractFromXML(child, rawData, rawDataIndex, folderName); - else - blob = ZBlob::BuildFromXML(child, folderName, mode == ZFileMode::Build); - - blob->parent = this; - - resources.push_back(blob); - - rawDataIndex += blob->GetRawDataSize(); + if (outNameSet.find(outNameXml) != outNameSet.end()) + { + throw std::runtime_error(StringHelper::Sprintf( + "ZFile::ParseXML: Error in '%s'.\n\t Repeated 'OutName' attribute: %s \n", + name.c_str(), outNameXml)); + } + outNameSet.insert(outNameXml); } - else if (string(child->Name()) == "DList") + if (nameXml != NULL) { - ZResource* dList = nullptr; - - if (mode == ZFileMode::Extract) - dList = ZDisplayList::ExtractFromXML( - child, rawData, rawDataIndex, - ZDisplayList::GetDListLength(rawData, rawDataIndex, - Globals::Instance->game == ZGame::OOT_SW97 ? - DListType::F3DEX : - DListType::F3DZEX), - folderName); - // else - // dList = ZDisplayList::BuildFromXML(child, folderName, mode == ZFileMode::Build); - else - dList = ZBlob::BuildFromXML(child, folderName, mode == ZFileMode::Build); - - dList->parent = this; - - resources.push_back(dList); - - rawDataIndex += dList->GetRawDataSize(); + if (nameSet.find(nameXml) != nameSet.end()) + { + throw std::runtime_error(StringHelper::Sprintf( + "ZFile::ParseXML: Error in '%s'.\n\t Repeated 'Name' attribute: %s \n", + name.c_str(), nameXml)); + } + nameSet.insert(nameXml); } - else if (string(child->Name()) == "Scene" || string(child->Name()) == "Room") + + string nodeName = string(child->Name()); + + if (nodeMap.find(nodeName) != nodeMap.end()) { - ZRoom* room = nullptr; + ZResource* nRes = nodeMap[nodeName](); + nRes->parent = this; if (mode == ZFileMode::Extract) - room = ZRoom::ExtractFromXML(child, rawData, rawDataIndex, folderName, this, - Globals::Instance->lastScene); + nRes->ExtractFromXML(child, rawData, rawDataIndex, folderName); - if (string(child->Name()) == "Scene") + // TODO: See if we can make this part of the ZRoom code... + if (nRes->GetResourceType() == ZResourceType::Room) { - Globals::Instance->lastScene = room; + if (nodeName == "Scene") + { + Globals::Instance->lastScene = (ZRoom*)nRes; - if (segment == -1) - segment = SEGMENT_SCENE; - } - else - { - if (segment == -1) - segment = SEGMENT_ROOM; + if (segment == -1) + segment = SEGMENT_SCENE; + } + else + { + if (segment == -1) + segment = SEGMENT_ROOM; + } + + if (segment != -1) + Globals::Instance->AddSegment(segment); } - if (segment != -1) - Globals::Instance->AddSegment(segment); - - resources.push_back(room); - - rawDataIndex += room->GetRawDataSize(); + resources.push_back(nRes); + rawDataIndex += nRes->GetRawDataSize(); } - else if (string(child->Name()) == "Animation") + else if (string(child->Name()) == "File") { - ZAnimation* anim = nullptr; - - if (mode == ZFileMode::Extract) - anim = ZNormalAnimation::ExtractFromXML(child, rawData, rawDataIndex, folderName); - - anim->parent = this; - resources.push_back(anim); - - rawDataIndex += anim->GetRawDataSize(); - } - else if (string(child->Name()) == "PlayerAnimation") - { - ZLinkAnimation* anim = nullptr; - - if (mode == ZFileMode::Extract) - anim = ZLinkAnimation::ExtractFromXML(child, rawData, rawDataIndex, folderName); - - anim->parent = this; - resources.push_back(anim); - - rawDataIndex += anim->GetRawDataSize(); - } - else if (string(child->Name()) == "CurveAnimation") - { - ZCurveAnimation* anim = nullptr; - - if (mode == ZFileMode::Extract) - { - anim = - ZCurveAnimation::ExtractFromXML(child, rawData, rawDataIndex, folderName, this); - } - - if (anim == nullptr) - { - throw std::runtime_error("Couldn't create ZCurveAnimation."); - } - resources.push_back(anim); - rawDataIndex += anim->GetRawDataSize(); - } - else if (string(child->Name()) == "Skeleton") - { - ZSkeleton* skeleton = nullptr; - - if (mode == ZFileMode::Extract) - skeleton = ZSkeleton::FromXML(child, rawData, rawDataIndex, folderName, this); - - if (skeleton == nullptr) - { - throw std::runtime_error("Couldn't create ZSkeleton."); - } - resources.push_back(skeleton); - rawDataIndex += skeleton->GetRawDataSize(); - } - else if (string(child->Name()) == "Limb") - { - ZLimb* limb = nullptr; - - if (mode == ZFileMode::Extract) - limb = ZLimb::FromXML(child, rawData, rawDataIndex, folderName, this); - - if (limb == nullptr) - { - throw std::runtime_error("Couldn't create ZLimb."); - } - resources.push_back(limb); - rawDataIndex += limb->GetRawDataSize(); - } - else if (string(child->Name()) == "Symbol") - { - ZSymbol* symbol = nullptr; - - if (mode == ZFileMode::Extract) - { - symbol = ZSymbol::ExtractFromXML(child, rawData, rawDataIndex, this); - } - - if (symbol == nullptr) - { - throw std::runtime_error("Couldn't create ZSymbol."); - } - resources.push_back(symbol); - } - else if (string(child->Name()) == "Collision") - { - ZCollisionHeader* res = nullptr; - - if (mode == ZFileMode::Extract) - { - res = new ZCollisionHeader(this, child->Attribute("Name"), rawData, rawDataIndex); - res->SetName(child->Attribute("Name")); - res->SetRawDataIndex(rawDataIndex); - } - - resources.push_back(res); - } - else if (string(child->Name()) == "Scalar") - { - ZScalar* scalar = nullptr; - - if (mode == ZFileMode::Extract) - scalar = ZScalar::ExtractFromXML(child, rawData, rawDataIndex, folderName); - - if (scalar != nullptr) - { - scalar->parent = this; - resources.push_back(scalar); - - rawDataIndex += scalar->GetRawDataSize(); - } - else - { - if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) - printf("No ZScalar created!!"); - } - } - else if (string(child->Name()) == "Vector") - { - ZVector* vector = nullptr; - - if (mode == ZFileMode::Extract) - vector = ZVector::ExtractFromXML(child, rawData, rawDataIndex, folderName); - - if (vector != nullptr) - { - vector->parent = this; - resources.push_back(vector); - - rawDataIndex += vector->GetRawDataSize(); - } - else - { - if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) - 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; - - if (mode == ZFileMode::Extract) - cs = ZCutscene::ExtractFromXML(child, rawData, rawDataIndex, folderName); - - if (cs != nullptr) - { - cs->parent = this; - resources.push_back(cs); - 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(); - } + throw std::runtime_error(StringHelper::Sprintf( + "ZFile::ParseXML: Error in '%s'.\n\t Can't declare a File inside a File.\n", + name.c_str())); } else { - std::cerr << "ERROR bad type\n"; - printf("Encountered unknown resource type: %s on line: %d\n", child->Name(), - child->GetLineNum()); - std::exit(EXIT_FAILURE); + throw std::runtime_error( + StringHelper::Sprintf("ZFile::ParseXML: Error in '%s'.\n\t Unknown element found " + "inside a File element: '%s'.\n", + name.c_str(), nodeName.c_str())); } } } -void ZFile::BuildResources() -{ - cout << "Building resources " << name << "\n"; - - int size = 0; - - for (ZResource* res : resources) - size += res->GetRawDataSize(); - - // Make sure size is 16 byte aligned - if (size % 16 != 0) - size = ((size / 16) + 1) * 16; - - vector file = vector(size); - int fileIndex = 0; - - for (ZResource* res : resources) - { - // Console.WriteLine("Building resource " + res.GetName()); - memcpy(file.data() + fileIndex, res->GetRawData().data(), res->GetRawData().size()); - // Array.Copy(res.GetRawData(), 0, file, fileIndex, res.GetRawData().Length); - fileIndex += res->GetRawData().size(); - } - - File::WriteAllBytes(basePath + "/" + name, file); -} - -void ZFile::BuildSourceFile(string outputDir) +void ZFile::BuildSourceFile(fs::path outputDir) { string folderName = Path::GetFileNameWithoutExtension(outputPath); @@ -450,9 +243,9 @@ void ZFile::BuildSourceFile(string outputDir) GenerateSourceFiles(outputDir); } -std::string ZFile::GetVarName(int address) +std::string ZFile::GetVarName(uint32_t address) { - for (pair pair : declarations) + for (pair pair : declarations) { if (pair.first == address) return pair.second->varName; @@ -466,16 +259,16 @@ std::string ZFile::GetName() return name; } -void ZFile::ExtractResources(string outputDir) +void ZFile::ExtractResources(fs::path outputDir) { string folderName = Path::GetFileNameWithoutExtension(outputPath); - // printf("DIR CHECK: %s\n", folderName.c_str()); - // printf("OUT CHECK: %s\n", outputDir.c_str()); - if (!Directory::Exists(outputPath)) Directory::CreateDirectory(outputPath); + if (!Directory::Exists(Globals::Instance->sourceOutputPath)) + Directory::CreateDirectory(Globals::Instance->sourceOutputPath); + for (ZResource* res : resources) res->PreGenSourceFiles(); @@ -500,13 +293,37 @@ void ZFile::AddResource(ZResource* res) resources.push_back(res); } -Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size, +ZResource* ZFile::FindResource(uint32_t rawDataIndex) +{ + for (ZResource* res : resources) + { + if (res->GetRawDataIndex() == rawDataIndex) + return res; + } + + return nullptr; +} + +std::vector ZFile::GetResourcesOfType(ZResourceType resType) +{ + std::vector resList; + + for (ZResource* res : resources) + { + if (res->GetResourceType() == resType) + resList.push_back(res); + } + + return resList; +} + +Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, size_t size, std::string varType, std::string varName, std::string body) { #if _DEBUG if (declarations.find(address) != declarations.end()) { - int bp = 0; + int32_t bp = 0; } #endif @@ -518,13 +335,13 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm } Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, - DeclarationPadding padding, uint32_t size, string varType, + DeclarationPadding padding, size_t size, string varType, string varName, std::string body) { #if _DEBUG if (declarations.find(address) != declarations.end()) { - int bp = 0; + int32_t bp = 0; } #endif @@ -536,13 +353,13 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm } Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, - uint32_t size, std::string varType, std::string varName, - int arrayItemCnt, std::string body) + size_t size, std::string varType, std::string varName, + size_t arrayItemCnt, std::string body) { #if _DEBUG if (declarations.find(address) != declarations.end()) { - int bp = 0; + int32_t bp = 0; } #endif @@ -554,13 +371,31 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a } Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, - DeclarationPadding padding, uint32_t size, string varType, - string varName, int arrayItemCnt, std::string body) + size_t size, std::string varType, std::string varName, + size_t arrayItemCnt, std::string body, bool isExternal) { #if _DEBUG if (declarations.find(address) != declarations.end()) { - int bp = 0; + int32_t bp = 0; + } +#endif + + AddDeclarationDebugChecks(address); + + declarations[address] = + new Declaration(alignment, size, varType, varName, true, arrayItemCnt, body, isExternal); + return declarations[address]; +} + +Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, + DeclarationPadding padding, size_t size, string varType, + string varName, size_t arrayItemCnt, std::string body) +{ +#if _DEBUG + if (declarations.find(address) != declarations.end()) + { + int32_t bp = 0; } #endif @@ -592,7 +427,7 @@ Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, string varName) return declarations[address]; } -Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, uint32_t size, +Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, size_t size, string varType, string varName) { AddDeclarationDebugChecks(address); @@ -604,33 +439,59 @@ Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, } Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string includePath, - uint32_t size, std::string varType, - std::string varName, int arrayItemCnt) + size_t size, std::string varType, + std::string varName, size_t arrayItemCnt) { #if _DEBUG if (declarations.find(address) != declarations.end()) { - int bp = 0; + int32_t bp = 0; + } + + if (address == 0) + { + int32_t bp = 0; } #endif AddDeclarationDebugChecks(address); - Declaration* decl = new Declaration(includePath, size, varType, varName); + if (StringHelper::StartsWith(includePath, "assets/extracted/")) + includePath = "assets/" + StringHelper::Split(includePath, "assets/extracted/")[1]; + if (StringHelper::StartsWith(includePath, "assets/custom/")) + includePath = "assets/" + StringHelper::Split(includePath, "assets/custom/")[1]; - decl->isArray = true; - decl->arrayItemCnt = arrayItemCnt; + auto declCheck = declarations.find(address); - declarations[address] = decl; - return declarations[address]; + if (declCheck != declarations.end()) + { + declCheck->second->includePath = includePath; + declCheck->second->varType = varType; + declCheck->second->varName = varName; + declCheck->second->size = size; + declCheck->second->isArray = true; + declCheck->second->arrayItemCnt = arrayItemCnt; + + return declCheck->second; + } + else + { + Declaration* decl = new Declaration(includePath, size, varType, varName); + + decl->isArray = true; + decl->arrayItemCnt = arrayItemCnt; + + declarations[address] = decl; + return declarations[address]; + } } void ZFile::AddDeclarationDebugChecks(uint32_t address) { #ifdef _DEBUG - if (address == 0x5600) + if (address == 0x0000) { - int bp = 0; + int32_t bp = 0; } #endif } @@ -685,9 +546,9 @@ bool ZFile::HasDeclaration(uint32_t address) return (declarations.find(address) != declarations.end()); } -void ZFile::GenerateSourceFiles(string outputDir) +void ZFile::GenerateSourceFiles(fs::path outputDir) { - sourceOutput = ""; + std::string sourceOutput = ""; sourceOutput += "#include \"ultra64.h\"\n"; sourceOutput += "#include \"z64.h\"\n"; @@ -703,27 +564,38 @@ void ZFile::GenerateSourceFiles(string outputDir) if (res->IsExternalResource()) { - // cout << "EXTERN\n"; string path = Path::GetFileNameWithoutExtension(res->GetName()).c_str(); - while (StringHelper::EndsWith(outputDir, "/")) - outputDir = outputDir.substr(0, outputDir.length() - 1); + string assetOutDir = outputDir / Path::GetFileNameWithoutExtension(res->GetOutName()); + string declType = res->GetSourceTypeName(); - // HACK - string declType = "u64"; + std::string incStr = StringHelper::Sprintf("%s.%s.inc", assetOutDir.c_str(), + res->GetExternalExtension().c_str()); - if (res->GetResourceType() != ZResourceType::Texture) - declType = "u8"; + if (res->GetResourceType() == ZResourceType::Texture) + { + ZTexture* tex = (ZTexture*)res; - AddDeclarationIncludeArray( - res->GetRawDataIndex(), - StringHelper::Sprintf("%s/%s.%s.inc.c", outputDir.c_str(), - Path::GetFileNameWithoutExtension(res->GetOutName()).c_str(), - res->GetExternalExtension().c_str()), - res->GetRawDataSize(), declType, res->GetName(), 0); + tex->CalcHash(); - // File::WriteAllText("build/" + outputDir + "/" + - // Path::GetFileNameWithoutExtension(res->GetName()) + ".inc.c", resSrc); + // TEXTURE POOL CHECK + if (Globals::Instance->cfg.texturePool.find(tex->hash) != + Globals::Instance->cfg.texturePool.end()) + { + incStr = Globals::Instance->cfg.texturePool[tex->hash].path.string() + "." + + res->GetExternalExtension() + ".inc"; + } + + incStr += ".c"; + } + else if (res->GetResourceType() == ZResourceType::Blob || + res->GetResourceType() == ZResourceType::Background) + { + incStr += ".c"; + } + + AddDeclarationIncludeArray(res->GetRawDataIndex(), incStr, res->GetRawDataSize(), + declType, res->GetName(), 0); } else { @@ -737,38 +609,36 @@ void ZFile::GenerateSourceFiles(string outputDir) sourceOutput += ProcessDeclarations(); - while (StringHelper::EndsWith(outputDir, "/")) - outputDir = outputDir.substr(0, outputDir.length() - 1); + string outPath = + Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".c"); - // string buildPath = "build/" + outputDir + "/" + "basefile.txt"; - string outPath = outputDir + "/" + Path::GetFileNameWithoutExtension(name) + ".c"; - // printf("WRITING %s\n", buildPath.c_str()); + OutputFormatter formatter; + formatter.Write(sourceOutput); - // if (!Directory::Exists(Path::GetPath(outPath))) - // Directory::CreateDirectory(Path::GetPath(outPath)); + File::WriteAllText(outPath, formatter.GetOutput()); - // if (!Directory::Exists(Path::GetPath(buildPath))) - // Directory::CreateDirectory(Path::GetPath(buildPath)); + GenerateSourceHeaderFiles(); +} - File::WriteAllText(outPath, sourceOutput); - // File::WriteAllText(buildPath, outPath); - - // Generate Header - sourceOutput = ""; +void ZFile::GenerateSourceHeaderFiles() +{ + OutputFormatter formatter; for (ZResource* res : resources) { string resSrc = res->GetSourceOutputHeader(""); - sourceOutput += resSrc; + formatter.Write(resSrc); if (resSrc != "") - sourceOutput += "\n"; + formatter.Write("\n"); } - sourceOutput += ProcessExterns(); + formatter.Write(ProcessExterns()); - File::WriteAllText(outputDir + "/" + Path::GetFileNameWithoutExtension(name) + ".h", - sourceOutput); + fs::path headerFilename = + Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".h"); + + File::WriteAllText(headerFilename, formatter.GetOutput()); } void ZFile::GenerateHLIntermediette() @@ -778,12 +648,13 @@ void ZFile::GenerateHLIntermediette() for (ZResource* res : resources) { - if (typeid(ZDisplayList) == typeid(*res) || typeid(ZSkeleton) == typeid(*res)) + if (res->GetResourceType() == ZResourceType::DisplayList || + res->GetResourceType() == ZResourceType::Skeleton) res->GenerateHLIntermediette(*mdl); } - std::string test = mdl->ToOBJFile(); - std::string test2 = mdl->ToFBXFile(); + // std::string test = mdl->ToOBJFile(); + // std::string test2 = mdl->ToAssimpFile(); } std::string ZFile::GetHeaderInclude() @@ -802,6 +673,18 @@ void ZFile::GeneratePlaceholderDeclarations() } } +std::map* ZFile::GetNodeMap() +{ + static std::map nodeMap; + return &nodeMap; +} + +void ZFile::RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc) +{ + std::map* nodeMap = GetNodeMap(); + (*nodeMap)[nodeName] = nodeFunc; +} + string ZFile::ProcessDeclarations() { string output = ""; @@ -816,53 +699,58 @@ string ZFile::ProcessDeclarations() // printf("RANGE START: 0x%06X - RANGE END: 0x%06X\n", rangeStart, rangeEnd); // Optimization: See if there are any arrays side by side that can be merged... - // pair lastItem = declarationKeysSorted[0]; + auto declarationKeys = + vector>(declarations.begin(), declarations.end()); + sort(declarationKeys.begin(), declarationKeys.end(), + [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; }); - // for (int i = 1; i < declarationKeysSorted.size(); i++) - //{ - // pair curItem = declarationKeysSorted[i]; + pair lastItem = declarationKeys[0]; - // if (curItem.second->isArray && lastItem.second->isArray) - // { - // if (curItem.second->varType == lastItem.second->varType) - // { - // // TEST: For now just do Vtx declarations... - // if (lastItem.second->varType == "static Vtx") - // { - // lastItem.second->size += curItem.second->size; - // lastItem.second->arrayItemCnt += curItem.second->arrayItemCnt; - // lastItem.second->text += "\n" + curItem.second->text; - // declarations.erase(curItem.first); - // declarationKeysSorted.erase(declarationKeysSorted.begin() + i); - // i--; - // continue; + for (size_t i = 1; i < declarationKeys.size(); i++) + { + pair curItem = declarationKeys[i]; - // int bp = 0; - // } - // } - // } + if (curItem.second->isArray && lastItem.second->isArray) + { + if (curItem.second->varType == lastItem.second->varType) + { + // TEST: For now just do Vtx declarations... + if (lastItem.second->varType == "static Vtx") + { + int32_t sizeDiff = curItem.first - (lastItem.first + lastItem.second->size); - // lastItem = curItem; - //} + // Make sure there isn't an unaccounted inbetween these two + if (sizeDiff == 0) + { + lastItem.second->size += curItem.second->size; + lastItem.second->arrayItemCnt += curItem.second->arrayItemCnt; + lastItem.second->text += "\n" + curItem.second->text; + declarations.erase(curItem.first); + declarationKeys.erase(declarationKeys.begin() + i); + i--; + continue; + } + } + } + } + + lastItem = curItem; + } + + for (pair item : declarations) + ProcessDeclarationText(item.second); for (pair item : declarations) - { - ProcessDeclarationText(item.second); - } - - for (pair item : declarations) { while (item.second->size % 4 != 0) - { item.second->size++; - } if (lastAddr != 0) { if (item.second->alignment == DeclarationAlignment::Align16) { - // int lastAddrSizeTest = declarations[lastAddr]->size; - int curPtr = lastAddr + declarations[lastAddr]->size; + // int32_t lastAddrSizeTest = declarations[lastAddr]->size; + int32_t curPtr = lastAddr + declarations[lastAddr]->size; while (curPtr % 4 != 0) { @@ -884,7 +772,7 @@ string ZFile::ProcessDeclarations() } else if (item.second->alignment == DeclarationAlignment::Align8) { - int curPtr = lastAddr + declarations[lastAddr]->size; + int32_t curPtr = lastAddr + declarations[lastAddr]->size; while (curPtr % 4 != 0) { @@ -909,7 +797,7 @@ string ZFile::ProcessDeclarations() if (item.second->padding == DeclarationPadding::Pad16) { - int curPtr = item.first + item.second->size; + int32_t curPtr = item.first + item.second->size; while (curPtr % 4 != 0) { @@ -932,97 +820,117 @@ string ZFile::ProcessDeclarations() // Handle unaccounted data lastAddr = 0; lastSize = 0; - for (pair item : declarations) + std::vector declsAddresses; + for (const auto& item : declarations) { - if (item.first >= rangeStart && item.first < rangeEnd) + declsAddresses.push_back(item.first); + } + declsAddresses.push_back(rawData.size()); + + for (uint32_t currentAddress : declsAddresses) + { + if (currentAddress >= rangeEnd) { - if (lastAddr != 0 && declarations.find(lastAddr) != declarations.end() && - lastAddr + declarations[lastAddr]->size > item.first) + break; + } + + if (currentAddress < rangeStart) + { + lastAddr = currentAddress; + continue; + } + + if (currentAddress != lastAddr && declarations.find(lastAddr) != declarations.end()) + { + Declaration* lastDecl = declarations.at(lastAddr); + lastSize = lastDecl->size; + + if (lastAddr + lastSize > currentAddress) { - printf("WARNING: Intersection detected from 0x%06X:0x%06X, conflicts with 0x%06X\n", - lastAddr, lastAddr + declarations[lastAddr]->size, item.first); + Declaration* currentDecl = declarations.at(currentAddress); + + fprintf(stderr, + "WARNING: Intersection detected from 0x%06X:0x%06X (%s), conflicts with " + "0x%06X (%s)\n", + lastAddr, lastAddr + lastSize, lastDecl->varName.c_str(), currentAddress, + currentDecl->varName.c_str()); } + } - uint8_t* rawDataArr = rawData.data(); + uint32_t unaccountedAddress = lastAddr + lastSize; - if (lastAddr + lastSize != item.first && lastAddr >= rangeStart && - lastAddr + lastSize < rangeEnd) + if (unaccountedAddress != currentAddress && lastAddr >= rangeStart && + unaccountedAddress < rangeEnd) + { + int diff = currentAddress - unaccountedAddress; + bool nonZeroUnaccounted = false; + + string src = " "; + + for (int i = 0; i < diff; i++) { - // int diff = item.first - (lastAddr + declarations[lastAddr]->size); - int diff = item.first - (lastAddr + lastSize); - - string src = " "; - - for (int i = 0; i < diff; i++) + uint8_t val = rawData.at(unaccountedAddress + i); + src += StringHelper::Sprintf("0x%02X, ", val); + if (val != 0x00) { - // src += StringHelper::Sprintf("0x%02X, ", rawDataArr[lastAddr + - // declarations[lastAddr]->size + i]); - src += StringHelper::Sprintf("0x%02X, ", rawDataArr[lastAddr + lastSize + i]); - - if ((i % 16 == 15) && (i != (diff - 1))) - src += "\n "; + nonZeroUnaccounted = true; } - if (declarations.find(lastAddr + lastSize) == declarations.end()) + if ((i % 16 == 15) && (i != (diff - 1))) + src += "\n "; + } + + if (declarations.find(unaccountedAddress) == declarations.end()) + { + if (diff > 0) { - if (diff > 0) + std::string unaccountedPrefix = "unaccounted"; + + if (diff < 16 && !nonZeroUnaccounted) + unaccountedPrefix = "possiblePadding"; + + Declaration* decl = AddDeclarationArray( + unaccountedAddress, DeclarationAlignment::None, diff, "static u8", + StringHelper::Sprintf("%s_%06X", unaccountedPrefix.c_str(), + unaccountedAddress), + diff, src); + decl->isUnaccounted = true; + + if (Globals::Instance->warnUnaccounted) { - // AddDeclarationArray(lastAddr + declarations[lastAddr]->size, - // DeclarationAlignment::None, diff, "static u8", - // StringHelper::Sprintf("unaccounted_%06X", lastAddr + - // declarations[lastAddr]->size), diff, src); - AddDeclarationArray( - lastAddr + lastSize, DeclarationAlignment::None, diff, "static u8", - StringHelper::Sprintf("unaccounted_%06X", lastAddr + lastSize), diff, - src); + if (nonZeroUnaccounted) + { + fprintf( + stderr, + "Warning in file: %s (%s)\n" + "\t A non-zero unaccounted block was found at address '0x%06X'.\n" + "\t Block size: '0x%X'.\n", + xmlFilePath.c_str(), name.c_str(), unaccountedAddress, diff); + } + else if (diff >= 16) + { + fprintf(stderr, + "Warning in file: %s (%s)\n" + "\t A big (size>=0x10) zero-only unaccounted block was found " + "at address '0x%06X'.\n" + "\t Block size: '0x%X'.\n", + xmlFilePath.c_str(), name.c_str(), unaccountedAddress, diff); + } } } } } - lastAddr = item.first; - lastSize = item.second->size; - } - - // TODO: THIS CONTAINS REDUNDANCIES. CLEAN THIS UP! - if (lastAddr + declarations[lastAddr]->size < rawData.size() && - lastAddr + declarations[lastAddr]->size >= rangeStart && - lastAddr + declarations[lastAddr]->size < rangeEnd) - { - int diff = (int)(rawData.size() - (lastAddr + declarations[lastAddr]->size)); - - string src = " "; - - for (int i = 0; i < diff; i++) - { - src += StringHelper::Sprintf("0x%02X, ", - rawData[lastAddr + declarations[lastAddr]->size + i]); - - if (i % 16 == 15) - src += "\n "; - } - - if (declarations.find(lastAddr + declarations[lastAddr]->size) == declarations.end()) - { - if (diff > 0) - { - AddDeclarationArray(lastAddr + declarations[lastAddr]->size, - DeclarationAlignment::None, diff, "static u8", - StringHelper::Sprintf("unaccounted_%06X", - lastAddr + declarations[lastAddr]->size), - diff, src); - } - } + lastAddr = currentAddress; } // Go through include declarations // First, handle the prototypes (static only for now) - int protoCnt = 0; - for (pair item : declarations) + int32_t protoCnt = 0; + for (pair item : declarations) { - if (item.second->includePath == "" && - StringHelper::StartsWith(item.second->varType, "static ") && - !StringHelper::StartsWith(item.second->varName, "unaccounted_")) + if (StringHelper::StartsWith(item.second->varType, "static ") && + !item.second->isUnaccounted) { if (item.second->isArray) { @@ -1046,7 +954,7 @@ string ZFile::ProcessDeclarations() output += "\n"; // Next, output the actual declarations - for (pair item : declarations) + for (pair item : declarations) { if (item.first < rangeStart || item.first >= rangeEnd) { @@ -1056,39 +964,101 @@ string ZFile::ProcessDeclarations() if (item.second->includePath != "") { // output += StringHelper::Sprintf("#include \"%s\"\n", - // item.second->includePath.c_str()); - output += StringHelper::Sprintf( - "%s %s[] = {\n#include \"%s\"\n};\n\n", item.second->varType.c_str(), - item.second->varName.c_str(), item.second->includePath.c_str()); + // item.second->includePath.c_str()); output += StringHelper::Sprintf("%s %s[] = + // {\n#include \"%s\"\n};\n\n", item.second->varType.c_str(), + // item.second->varName.c_str(), item.second->includePath.c_str()); + + if (item.second->isExternal) + { + // HACK + std::string extType = ""; + + if (item.second->varType == "Gfx") + extType = "dlist"; + else if (item.second->varType == "Vtx" || item.second->varType == "static Vtx") + extType = "vtx"; + + auto filepath = Globals::Instance->outputPath / item.second->varName; + File::WriteAllText( + StringHelper::Sprintf("%s.%s.inc", filepath.c_str(), extType.c_str()), + item.second->text); + } + + /*if (item.second->varType == "u64") + output += StringHelper::Sprintf("#pragma INC_ASSET_U64(\"%s\", \"%s\")\n", + item.second->varName.c_str(), item.second->includePath.c_str()); else if + (item.second->varType == "Gfx") output += StringHelper::Sprintf("#pragma + INC_ASSET_GFX(\"%s\", \"%s\")\n", item.second->varName.c_str(), + item.second->includePath.c_str()); else if (item.second->varType == "Vtx" || + item.second->varType == "static Vtx") output += StringHelper::Sprintf("#pragma + INC_ASSET_VTX(\"%s\", \"%s\")\n", item.second->varName.c_str(), + item.second->includePath.c_str()); else output += StringHelper::Sprintf("#pragma + INC_ASSET_U8(\"%s\", \"%s\")\n", item.second->varName.c_str(), + item.second->includePath.c_str());*/ + + // Do not asm_process vertex arrays. They have no practical use being overridden. + // if (item.second->varType == "Vtx" || item.second->varType == "static Vtx") + if (item.second->varType != "u64" && item.second->varType != "static u64" && + item.second->varType != "u8" && item.second->varType != "static u8") + { + // output += StringHelper::Sprintf("%s %s[] = {\n #include \"%s\"\n};\n\n", + // item.second->varType.c_str(), item.second->varName.c_str(), + // StringHelper::Replace(item.second->includePath, "assets/", + // "../assets/extracted/").c_str()); + output += StringHelper::Sprintf( + "%s %s[] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(), + item.second->varName.c_str(), + StringHelper::Replace(item.second->includePath, "assets/", "../assets/") + .c_str()); + // output += StringHelper::Sprintf("%s %s[] = {\n #include \"%s\"\n};\n\n", + // item.second->varType.c_str(), item.second->varName.c_str(), + // Path::GetFileName(item.second->includePath).c_str()); + } + else + { + // output += StringHelper::Sprintf("%s %s[] = {\n #pragma + // INC_ASSET(\"%s\")\n};\n\n", item.second->varType.c_str(), + // item.second->varName.c_str(), item.second->includePath.c_str()); output += + // StringHelper::Sprintf("%s %s[] = {\n #include \"%s\"\n};\n\n", + // item.second->varType.c_str(), item.second->varName.c_str(), + // StringHelper::Replace(item.second->includePath, "assets/", + // "assets/extracted/").c_str()); + output += StringHelper::Sprintf( + "%s %s[] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(), + item.second->varName.c_str(), item.second->includePath.c_str()); + } } else if (item.second->varType != "") { if (item.second->preText != "") output += item.second->preText + "\n"; - if (item.second->isArray) { - if (item.second->arrayItemCnt == 0) - output += StringHelper::Sprintf("%s %s[] = {\n", item.second->varType.c_str(), - item.second->varName.c_str()); + if (item.second->isArray) + { + if (item.second->arrayItemCnt == 0) + output += + StringHelper::Sprintf("%s %s[] = {\n", item.second->varType.c_str(), + item.second->varName.c_str()); + else + output += StringHelper::Sprintf( + "%s %s[%i] = {\n", item.second->varType.c_str(), + item.second->varName.c_str(), item.second->arrayItemCnt); + + output += item.second->text + "\n"; + } else - output += StringHelper::Sprintf("%s %s[%i] = {\n", item.second->varType.c_str(), - item.second->varName.c_str(), - item.second->arrayItemCnt); + { + output += StringHelper::Sprintf("%s %s = { ", item.second->varType.c_str(), + item.second->varName.c_str()); + output += item.second->text; + } - output += item.second->text + "\n"; + if (output.back() == '\n') + output += "};"; + else + output += " };"; } - else - { - output += StringHelper::Sprintf("%s %s = { ", item.second->varType.c_str(), - item.second->varName.c_str()); - output += item.second->text; - } - - if (output.back() == '\n') - output += "};"; - else - output += " };"; output += " " + item.second->rightText + "\n\n"; @@ -1127,8 +1097,9 @@ void ZFile::ProcessDeclarationText(Declaration* decl) { if (refDecl->arrayItemCnt != 0) { - int itemSize = refDecl->size / refDecl->arrayItemCnt; - int itemIndex = (decl->references[refIndex] - refDeclAddr) / itemSize; + int32_t itemSize = refDecl->size / refDecl->arrayItemCnt; + int32_t itemIndex = + (decl->references[refIndex] - refDeclAddr) / itemSize; decl->text.replace(i, 2, StringHelper::Sprintf( @@ -1158,7 +1129,7 @@ string ZFile::ProcessExterns() { string output = ""; - for (pair item : declarations) + for (pair item : declarations) { if (item.first < rangeStart || item.first >= rangeEnd) { diff --git a/tools/ZAPD/ZAPD/ZFile.h b/tools/ZAPD/ZAPD/ZFile.h index 668d9c6ea0..80411e0b10 100644 --- a/tools/ZAPD/ZAPD/ZFile.h +++ b/tools/ZAPD/ZAPD/ZFile.h @@ -2,18 +2,19 @@ #include #include +#include "Directory.h" #include "ZResource.h" #include "tinyxml2.h" enum class ZFileMode { - Build, BuildTexture, BuildOverlay, BuildModelIntermediette, BuildAnimationIntermediette, BuildBlob, BuildSourceFile, + BuildBackground, Extract, Invalid }; @@ -33,36 +34,41 @@ public: std::vector resources; uint32_t baseAddress, rangeStart, rangeEnd; - ZFile(std::string nOutPath, std::string nName); - ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, std::string nBasePath, std::string nOutPath, - std::string filename, bool placeholderMode); + ZFile(const fs::path& nOutPath, std::string nName); + ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBasePath, + const fs::path& nOutPath, std::string filename, const fs::path& nXmlFilePath, + bool placeholderMode); ~ZFile(); - std::string GetVarName(int address); + std::string GetVarName(uint32_t address); std::string GetName(); - void ExtractResources(std::string outputDir); - void BuildResources(); - void BuildSourceFile(std::string outputDir); + void ExtractResources(fs::path outputDir); + void BuildSourceFile(fs::path outputDir); void AddResource(ZResource* res); + ZResource* FindResource(uint32_t rawDataIndex); + std::vector GetResourcesOfType(ZResourceType resType); - Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size, + Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, size_t size, std::string varType, std::string varName, std::string body); Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, - DeclarationPadding padding, uint32_t size, std::string varType, + DeclarationPadding padding, size_t size, std::string varType, std::string varName, std::string body); + Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size, + std::string varType, std::string varName, size_t arrayItemCnt, + std::string body); + Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size, + std::string varType, std::string varName, size_t arrayItemCnt, + std::string body, bool isExternal); Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, - uint32_t size, std::string varType, std::string varName, - int arrayItemCnt, std::string body); - Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, - DeclarationPadding padding, uint32_t size, std::string varType, - std::string varName, int arrayItemCnt, std::string body); + DeclarationPadding padding, size_t size, std::string varType, + std::string varName, size_t arrayItemCnt, std::string body); Declaration* AddDeclarationPlaceholder(uint32_t address); Declaration* AddDeclarationPlaceholder(uint32_t address, std::string varName); - Declaration* AddDeclarationInclude(uint32_t address, std::string includePath, uint32_t size, + Declaration* AddDeclarationInclude(uint32_t address, std::string includePath, size_t size, std::string varType, std::string varName); - Declaration* AddDeclarationIncludeArray(uint32_t address, std::string includePath, - uint32_t size, std::string varType, std::string varName, - int arrayItemCnt); + Declaration* AddDeclarationIncludeArray(uint32_t address, std::string includePath, size_t size, + std::string varType, std::string varName, + size_t arrayItemCnt); std::string GetDeclarationName(uint32_t address); std::string GetDeclarationName(uint32_t address, std::string defaultResult); Declaration* GetDeclaration(uint32_t address); @@ -72,17 +78,21 @@ public: std::string GetHeaderInclude(); void GeneratePlaceholderDeclarations(); + static std::map* GetNodeMap(); + static void RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc); + protected: std::vector rawData; std::string name; - std::string basePath; - std::string outputPath; - std::string sourceOutput; + fs::path basePath; + fs::path outputPath; + fs::path xmlFilePath; ZFile(); void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename, bool placeholderMode); - void GenerateSourceFiles(std::string outputDir); + void GenerateSourceFiles(fs::path outputDir); + void GenerateSourceHeaderFiles(); void GenerateHLIntermediette(); void AddDeclarationDebugChecks(uint32_t address); std::string ProcessDeclarations(); diff --git a/tools/ZAPD/ZAPD/ZLimb.cpp b/tools/ZAPD/ZAPD/ZLimb.cpp index 087d496458..d71d16800c 100644 --- a/tools/ZAPD/ZAPD/ZLimb.cpp +++ b/tools/ZAPD/ZAPD/ZLimb.cpp @@ -6,6 +6,8 @@ using namespace std; +REGISTER_ZFILENODE(Limb, ZLimb); + Struct_800A57C0::Struct_800A57C0(const std::vector& rawData, uint32_t fileOffset) { unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00); @@ -115,6 +117,7 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix) size_t arrayItemCnt = unk_8_arr.size(); entryStr = ""; size_t i = 0; + for (auto& child : unk_8_arr) { entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(), @@ -122,6 +125,7 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix) } Declaration* decl = parent->GetDeclaration(unk_8_Offset); + if (decl == nullptr) { parent->AddDeclarationArray(unk_8_Offset, DeclarationAlignment::None, @@ -145,6 +149,7 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix) size_t arrayItemCnt = unk_C_arr.size(); entryStr = ""; size_t i = 0; + for (auto& child : unk_C_arr) { entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(), @@ -171,6 +176,7 @@ std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) cons string entryStr; string unk_8_Str = "NULL"; + if (unk_8 != 0) { uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); @@ -180,6 +186,7 @@ std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) cons } string unk_C_Str = "NULL"; + if (unk_C != 0) { uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress); @@ -188,6 +195,10 @@ std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) cons Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset); } + entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n", + unk_8_Str.c_str(), unk_C_Str.c_str()); + entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(), + unk_C_Str.c_str()); entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n", unk_8_Str.c_str(), unk_C_Str.c_str()); entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(), @@ -218,23 +229,25 @@ Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector& nRaw if (unk_4 != 0) { uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); + for (size_t i = 0; i < unk_2; i++) { unk_4_arr.emplace_back(parent, nRawData, unk_4_Offset, i); } } } -Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector& rawData, - uint32_t fileOffset, size_t index) - : Struct_800A5E28(parent, rawData, fileOffset + index * GetRawDataSize()) -{ -} Struct_800A5E28::~Struct_800A5E28() { delete unk_8_dlist; } +ZLimb::~ZLimb() +{ + for (auto DL : dLists) + delete DL; +} + void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix) { if (unk_4 != 0) @@ -248,16 +261,17 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix) uint16_t arrayItemCnt = unk_4_arr.size(); size_t i = 0; + for (auto& child : unk_4_arr) { child.PreGenSourceFiles(prefix); - entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode(prefix).c_str(), (++i < arrayItemCnt) ? "\n" : ""); } Declaration* decl = parent->GetDeclaration(unk_4_Offset); + if (decl == nullptr) { parent->AddDeclarationArray(unk_4_Offset, DeclarationAlignment::None, @@ -275,11 +289,10 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix) { uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - int dlistLength = ZDisplayList::GetDListLength( + int32_t dlistLength = ZDisplayList::GetDListLength( rawData, unk_8_Offset, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); - unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength); - unk_8_dlist->parent = parent; + unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength, parent); string dListStr = StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset); unk_8_dlist->SetName(dListStr); @@ -292,10 +305,12 @@ std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) cons string entryStr = ""; string unk_4_Str = "NULL"; + if (unk_4 != 0) { uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); Declaration* decl = parent->GetDeclaration(unk_4_Offset); + if (decl == nullptr) { unk_4_Str = @@ -338,30 +353,15 @@ std::string Struct_800A5E28::GetSourceTypeName() return "Struct_800A5E28"; } -ZLimb::ZLimb(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, - ZFile* nParent) +ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent) { - rawData.assign(nRawData.begin(), nRawData.end()); - rawDataIndex = nRawDataIndex; - parent = nParent; - - segAddress = nRawDataIndex; - - ParseXML(reader); - ParseRawData(); - - if (type == ZLimbType::Skin) - { - if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0) - { - uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress); - segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset); - } - } + dListPtr = 0; + dList2Ptr = 0; } ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector& nRawData, - int nRawDataIndex, ZFile* nParent) + uint32_t nRawDataIndex, ZFile* nParent) + : ZResource(nParent) { rawData.assign(nRawData.begin(), nRawData.end()); rawDataIndex = nRawDataIndex; @@ -380,11 +380,8 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader) // Reading from a const char* limbType = reader->Attribute("LimbType"); - if (limbType == nullptr) - { - // Reading from a + if (limbType == nullptr) // Reading from a limbType = reader->Attribute("Type"); - } if (limbType == nullptr) { @@ -397,6 +394,7 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader) else { string limbTypeStr(limbType); + if (limbTypeStr == "Standard") { type = ZLimbType::Standard; @@ -449,28 +447,39 @@ void ZLimb::ParseRawData() dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12); case ZLimbType::Standard: dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); + break; case ZLimbType::Skin: skinSegmentType = static_cast(BitConverter::ToInt32BE(rawData, rawDataIndex + 8)); skinSegment = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12); break; + default: + throw std::runtime_error("Invalid ZLimb type"); + break; } } -ZLimb* ZLimb::FromXML(tinyxml2::XMLElement* reader, vector nRawData, int rawDataIndex, - string nRelPath, ZFile* parent) +void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZLimb* limb = new ZLimb(reader, nRawData, rawDataIndex, parent); - limb->relativePath = std::move(nRelPath); + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); + segAddress = nRawDataIndex; - limb->parent->AddDeclaration(limb->GetFileAddress(), DeclarationAlignment::None, - limb->GetRawDataSize(), limb->GetSourceTypeName(), limb->name, ""); + parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(), + GetSourceTypeName(), name, ""); - return limb; + if (type == ZLimbType::Skin) + { + if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0) + { + uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress); + segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset); + } + } } -int ZLimb::GetRawDataSize() +size_t ZLimb::GetRawDataSize() { switch (type) { @@ -481,6 +490,7 @@ int ZLimb::GetRawDataSize() case ZLimbType::Skin: return 0x10; } + return 0x0C; } @@ -523,15 +533,12 @@ string ZLimb::GetSourceOutputCode(const std::string& prefix) } Declaration* decl = parent->GetDeclaration(GetFileAddress()); + if (decl == nullptr) - { parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(), GetSourceTypeName(), name, entryStr); - } else - { decl->text = entryStr; - } return ""; } @@ -551,6 +558,11 @@ ZLimbType ZLimb::GetLimbType() return type; } +void ZLimb::SetLimbType(ZLimbType value) +{ + type = value; +} + const char* ZLimb::GetSourceTypeName(ZLimbType limbType) { switch (limbType) @@ -563,8 +575,9 @@ const char* ZLimb::GetSourceTypeName(ZLimbType limbType) return "SkinLimb"; case ZLimbType::Curve: return "SkelCurveLimb"; + default: + return "StandardLimb"; } - return "StandardLimb"; } uint32_t ZLimb::GetFileAddress() @@ -576,12 +589,9 @@ std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix, const std::string& limbPrefix, segptr_t dListPtr) { if (dListPtr == 0) - { return "NULL"; - } uint32_t dListOffset = Seg2Filespace(dListPtr, parent->baseAddress); - string dListStr; Declaration* decl = parent->GetDeclaration(dListOffset); if (decl == nullptr) @@ -589,13 +599,13 @@ std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix, dListStr = StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), dListOffset); - int dlistLength = ZDisplayList::GetDListLength( + int32_t dlistLength = ZDisplayList::GetDListLength( rawData, dListOffset, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); - auto& dList = dLists.emplace_back(rawData, dListOffset, dlistLength); - dList.parent = parent; - dList.SetName(dListStr); - dList.GetSourceOutputCode(prefix); + auto dList = new ZDisplayList(rawData, dListOffset, dlistLength, parent); + dLists.push_back(dList); + dList->SetName(dListStr); + dList->GetSourceOutputCode(prefix); } else { @@ -611,9 +621,7 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix) assert(skinSegmentType == ZLimbSkinType::SkinType_4); if (skinSegment == 0) - { return "NULL"; - } uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress); @@ -661,6 +669,7 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix) "ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Unknown segment type " "for SkinLimb: '%i'. \n\tPlease report this.\n", name.c_str(), static_cast(skinSegmentType)); + break; case ZLimbSkinType::SkinType_0: case ZLimbSkinType::SkinType_5: fprintf(stderr, diff --git a/tools/ZAPD/ZAPD/ZLimb.h b/tools/ZAPD/ZAPD/ZLimb.h index edff33542d..b923e6fc05 100644 --- a/tools/ZAPD/ZAPD/ZLimb.h +++ b/tools/ZAPD/ZAPD/ZLimb.h @@ -123,17 +123,10 @@ protected: segptr_t segAddress; ZLimbType type = ZLimbType::Standard; - int16_t transX, transY, transZ; - uint8_t childIndex, siblingIndex; - segptr_t dListPtr = 0; - - std::vector dLists; - - segptr_t dList2Ptr = 0; // LOD and Curve only - ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only segptr_t skinSegment = 0; // Skin only Struct_800A5E28 segmentStruct; // Skin only + segptr_t dList2Ptr; // LOD and Curve Only std::string GetLimbDListSourceOutputCode(const std::string& prefix, const std::string& limbPrefix, segptr_t dListPtr); @@ -142,22 +135,32 @@ protected: std::string GetSourceOutputCodeSkin_Type_4(const std::string& prefix); public: - ZLimb(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, - ZFile* nParent); + ZDisplayList* dList; + segptr_t dListPtr = 0; + segptr_t farDListPtr = 0; // LOD only + int16_t transX, transY, transZ; + uint8_t childIndex, siblingIndex; + std::vector dLists; + std::vector children; + + ZLimb(ZFile* nParent); ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector& nRawData, - int nRawDataIndex, ZFile* nParent); + uint32_t nRawDataIndex, ZFile* nParent); + ~ZLimb(); void ParseXML(tinyxml2::XMLElement* reader) override; void ParseRawData() override; - static ZLimb* FromXML(tinyxml2::XMLElement* reader, std::vector nRawData, - int rawDataIndex, std::string nRelPath, ZFile* parent); - int GetRawDataSize() override; + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; + size_t GetRawDataSize() override; std::string GetSourceOutputCode(const std::string& prefix) override; std::string GetSourceTypeName() override; ZResourceType GetResourceType() override; ZLimbType GetLimbType(); + void SetLimbType(ZLimbType value); static const char* GetSourceTypeName(ZLimbType limbType); uint32_t GetFileAddress(); + void SetFileAddress(uint32_t nAddress); }; diff --git a/tools/ZAPD/ZAPD/ZMtx.cpp b/tools/ZAPD/ZAPD/ZMtx.cpp new file mode 100644 index 0000000000..9a90c29947 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZMtx.cpp @@ -0,0 +1,97 @@ +#include "ZMtx.h" +#include "BitConverter.h" +#include "StringHelper.h" +#include "ZFile.h" + +REGISTER_ZFILENODE(Mtx, ZMtx); + +ZMtx::ZMtx(ZFile* nParent) : ZResource(nParent) +{ +} + +ZMtx::ZMtx(const std::string& prefix, const std::vector& nRawData, uint32_t nRawDataIndex, + ZFile* nParent) + : ZResource(nParent) +{ + name = GetDefaultName(prefix.c_str(), rawDataIndex); + ExtractFromFile(nRawData, nRawDataIndex, ""); + DeclareVar("", ""); +} + +void ZMtx::ParseRawData() +{ + ZResource::ParseRawData(); + + for (size_t i = 0; i < 4; ++i) + for (size_t j = 0; j < 4; ++j) + mtx[i][j] = BitConverter::ToInt32BE(rawData, rawDataIndex + (i * 4 + j) * 4); +} + +void ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + uint32_t nRawDataIndex, const std::string& nRelPath) +{ + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); + DeclareVar("", ""); +} + +size_t ZMtx::GetRawDataSize() +{ + return 64; +} + +void ZMtx::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + + if (name == "") + auxName = GetDefaultName(prefix, rawDataIndex); + + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(), + GetSourceTypeName(), auxName, bodyStr); +} + +std::string ZMtx::GetBodySourceCode() +{ + std::string bodyStr = "\n"; + + for (const auto& row : mtx) + { + bodyStr += " "; + + for (int32_t val : row) + bodyStr += StringHelper::Sprintf("%-11i, ", val); + + bodyStr += "\n"; + } + + return bodyStr; +} + +std::string ZMtx::GetSourceOutputCode(const std::string& prefix) +{ + std::string bodyStr = GetBodySourceCode(); + + Declaration* decl = parent->GetDeclaration(rawDataIndex); + + if (decl == nullptr) + DeclareVar(prefix, bodyStr); + else + decl->text = bodyStr; + + return ""; +} + +std::string ZMtx::GetDefaultName(const std::string& prefix, uint32_t address) +{ + return StringHelper::Sprintf("%sMtx_%06X", prefix.c_str(), address); +} + +std::string ZMtx::GetSourceTypeName() +{ + return "Mtx"; +} + +ZResourceType ZMtx::GetResourceType() +{ + return ZResourceType::Mtx; +} diff --git a/tools/ZAPD/ZAPD/ZMtx.h b/tools/ZAPD/ZAPD/ZMtx.h new file mode 100644 index 0000000000..5888882316 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZMtx.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include "ZResource.h" + +class ZMtx : public ZResource +{ +protected: + std::array, 4> mtx; + +public: + // ZMtx() = default; + ZMtx(ZFile* nParent); + ZMtx(const std::string& prefix, const std::vector& nRawData, uint32_t nRawDataIndex, + ZFile* nParent); + void ParseRawData() override; + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + uint32_t nRawDataIndex, const std::string& nRelPath) override; + + size_t GetRawDataSize() override; + + void DeclareVar(const std::string& prefix, const std::string& bodyStr); + + std::string GetBodySourceCode(); + std::string GetSourceOutputCode(const std::string& prefix) override; + static std::string GetDefaultName(const std::string& prefix, uint32_t address); + + std::string GetSourceTypeName() override; + ZResourceType GetResourceType() override; +}; diff --git a/tools/ZAPD/ZAPD/ZResource.cpp b/tools/ZAPD/ZAPD/ZResource.cpp index 7a8acb417a..9e16f27d6f 100644 --- a/tools/ZAPD/ZAPD/ZResource.cpp +++ b/tools/ZAPD/ZAPD/ZResource.cpp @@ -1,10 +1,13 @@ #include "ZResource.h" +#include +#include "StringHelper.h" + using namespace std; -ZResource::ZResource() +ZResource::ZResource(ZFile* nParent) { - parent = nullptr; + parent = nParent; name = ""; outName = ""; relativePath = ""; @@ -14,17 +17,68 @@ ZResource::ZResource() outputDeclaration = true; } +void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) +{ + rawData = nRawData; + rawDataIndex = nRawDataIndex; + relativePath = nRelPath; + + if (reader != nullptr) + ParseXML(reader); + + ParseRawData(); +} + +void ZResource::ExtractFromFile(const std::vector& nRawData, uint32_t nRawDataIndex, + const std::string& nRelPath) +{ + rawData = nRawData; + rawDataIndex = nRawDataIndex; + relativePath = nRelPath; + + ParseRawData(); +} + void ZResource::ParseXML(tinyxml2::XMLElement* reader) { - if (reader->Attribute("Name") != nullptr) - name = reader->Attribute("Name"); - else - name = ""; + if (reader != nullptr) + { + if (reader->Attribute("Name") != nullptr) + { + name = reader->Attribute("Name"); + static std::regex r("[a-zA-Z_]+[a-zA-Z0-9_]*", + std::regex::icase | std::regex::optimize); - if (reader->Attribute("OutName") != nullptr) - outName = reader->Attribute("OutName"); - else - outName = name; + if (!std::regex_match(name, r)) + { + throw std::domain_error( + StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n\t Resource " + "with invalid 'Name' attribute.\n", + name.c_str())); + } + } + else + name = ""; + + if (reader->Attribute("OutName") != nullptr) + outName = reader->Attribute("OutName"); + else + outName = name; + + if (reader->Attribute("Custom") != nullptr) + isCustomAsset = true; + else + isCustomAsset = false; + + if (!canHaveInner && !reader->NoChildren()) + { + throw std::runtime_error( + StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n\t Resource '%s' " + "with inner element/child detected.\n", + name.c_str(), reader->Name())); + } + } } void ZResource::Save(const std::string& outFolder) @@ -45,6 +99,11 @@ std::string ZResource::GetOutName() return outName; } +void ZResource::SetOutName(std::string nName) +{ + outName = nName; +} + void ZResource::SetName(string nName) { name = std::move(nName); @@ -75,17 +134,22 @@ vector ZResource::GetRawData() return rawData; } -int ZResource::GetRawDataIndex() +void ZResource::SetRawData(std::vector nData) +{ + rawData = nData; +} + +uint32_t ZResource::GetRawDataIndex() { return rawDataIndex; } -int ZResource::GetRawDataSize() +size_t ZResource::GetRawDataSize() { return rawData.size(); } -void ZResource::SetRawDataIndex(int value) +void ZResource::SetRawDataIndex(uint32_t value) { rawDataIndex = value; } @@ -110,7 +174,7 @@ void ZResource::GenerateHLIntermediette(HLFileIntermediette& hlFile) std::string ZResource::GetSourceTypeName() { - return ""; + return "u8"; } ZResourceType ZResource::GetResourceType() @@ -132,3 +196,7 @@ uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress) return currentPtr; } + +ZResource::~ZResource() +{ +} \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZResource.h b/tools/ZAPD/ZAPD/ZResource.h index 78f69a6c82..aa9f86abfe 100644 --- a/tools/ZAPD/ZAPD/ZResource.h +++ b/tools/ZAPD/ZAPD/ZResource.h @@ -31,7 +31,6 @@ enum class ZResourceType Texture, DisplayList, Room, - Overlay, Animation, Cutscene, Blob, @@ -42,6 +41,8 @@ enum class ZResourceType Vertex, CollisionHeader, Symbol, + Mtx, + Background, }; class ZResource @@ -49,38 +50,57 @@ class ZResource public: ZFile* parent; bool outputDeclaration; + uint32_t hash; - ZResource(); + ZResource(ZFile* nParent); + virtual ~ZResource(); + + // Parsing from File + virtual void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, + const std::string& nRelPath); // Extract Mode + virtual void ExtractFromFile(const std::vector& nRawData, uint32_t nRawDataIndex, + const std::string& nRelPath); + + // Misc virtual void ParseXML(tinyxml2::XMLElement* reader); - virtual void Save(const std::string& outFolder); - virtual void PreGenSourceFiles(); - std::string GetName(); - std::string GetOutName(); - void SetName(std::string nName); - 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 void ParseRawData(); virtual std::string GetSourceOutputCode(const std::string& prefix); virtual std::string GetSourceOutputHeader(const std::string& prefix); - virtual void ParseRawData(); + virtual void PreGenSourceFiles(); virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile); + virtual void CalcHash(); + virtual void Save(const std::string& outFolder); + + // Properties + virtual bool IsExternalResource(); + virtual bool DoesSupportArray(); // Can this type be wrapped in an node? virtual std::string GetSourceTypeName(); virtual ZResourceType GetResourceType(); - virtual void CalcHash(); + virtual std::string GetExternalExtension(); + + // Getters/Setters + std::string GetName(); + void SetName(std::string nName); + std::string GetOutName(); + void SetOutName(std::string nName); + std::string GetRelativePath(); + virtual uint32_t GetRawDataIndex(); + virtual void SetRawDataIndex(uint32_t value); + virtual size_t GetRawDataSize(); + virtual std::vector GetRawData(); + virtual void SetRawData(std::vector nData); protected: std::string name; std::string outName; std::string relativePath; std::vector rawData; - int rawDataIndex; + uint32_t rawDataIndex; std::string sourceOutput; - uint64_t hash; + bool canHaveInner = false; // Can this type have an inner node? + bool isCustomAsset; // If set to true, create a reference for the asset in the file, but don't + // actually try to extract it from the file }; enum class DeclarationAlignment @@ -104,7 +124,7 @@ class Declaration public: DeclarationAlignment alignment; DeclarationPadding padding; - uint32_t size; + size_t size; std::string preText; std::string text; std::string rightText; @@ -114,25 +134,47 @@ public: std::string varType; std::string varName; std::string includePath; + bool isExternal; bool isArray; - int arrayItemCnt; + size_t arrayItemCnt; std::vector references; + bool isUnaccounted = false; - Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType, + Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, std::string nText); - Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, + Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, std::string nText); - Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType, - std::string nVarName, bool nIsArray, int nArrayItemCnt, std::string nText); - Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, - std::string nVarType, std::string nVarName, bool nIsArray, int nArrayItemCnt, + Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType, + std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText); + Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType, + std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText, + bool nIsExternal); + Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize, + std::string nVarType, std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText); - Declaration(std::string nIncludePath, uint32_t nSize, std::string nVarType, - std::string nVarName); + Declaration(std::string nIncludePath, size_t nSize, std::string nVarType, std::string nVarName); protected: - Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, + Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize, std::string nText); }; uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress); + +typedef ZResource*(ZResourceFactoryFunc)(); + +#define REGISTER_ZFILENODE(nodeName, zResClass) \ + static ZResource* ZResourceFactory_##zResClass_##nodeName() \ + { \ + return static_cast(new zResClass(nullptr)); \ + } \ + \ + class ZRes_##nodeName \ + { \ + public: \ + ZRes_##nodeName() \ + { \ + ZFile::RegisterNode(#nodeName, &ZResourceFactory_##zResClass_##nodeName); \ + } \ + }; \ + static ZRes_##nodeName inst_ZRes_##nodeName; diff --git a/tools/ZAPD/ZAPD/ZRoom/ActorList.h b/tools/ZAPD/ZAPD/ZRoom/ActorList.h deleted file mode 100644 index 24ba26efa3..0000000000 --- a/tools/ZAPD/ZAPD/ZRoom/ActorList.h +++ /dev/null @@ -1,478 +0,0 @@ -#pragma once - -#include - -static const std::string ActorList[] = { - /* 0x0000 */ "ACTOR_PLAYER", - /* 0x0001 */ "ACTOR_UNSET_1", - /* 0x0002 */ "ACTOR_EN_TEST", - /* 0x0003 */ "ACTOR_UNSET_3", - /* 0x0004 */ "ACTOR_EN_GIRLA", - /* 0x0005 */ "ACTOR_UNSET_5", - /* 0x0006 */ "ACTOR_UNSET_6", - /* 0x0007 */ "ACTOR_EN_PART", - /* 0x0008 */ "ACTOR_EN_LIGHT", - /* 0x0009 */ "ACTOR_EN_DOOR", - /* 0x000A */ "ACTOR_EN_BOX", // Treasure Chest - /* 0x000B */ "ACTOR_BG_DY_YOSEIZO", - /* 0x000C */ "ACTOR_BG_HIDAN_FIREWALL", - /* 0x000D */ "ACTOR_EN_POH", - /* 0x000E */ "ACTOR_EN_OKUTA", - /* 0x000F */ "ACTOR_BG_YDAN_SP", - /* 0x0010 */ "ACTOR_EN_BOM", - /* 0x0011 */ "ACTOR_EN_WALLMAS", - /* 0x0012 */ "ACTOR_EN_DODONGO", - /* 0x0013 */ "ACTOR_EN_FIREFLY", - /* 0x0014 */ "ACTOR_EN_HORSE", - /* 0x0015 */ "ACTOR_EN_ITEM00", - /* 0x0016 */ "ACTOR_EN_ARROW", - /* 0x0017 */ "ACTOR_UNSET_17", - /* 0x0018 */ "ACTOR_EN_ELF", - /* 0x0019 */ "ACTOR_EN_NIW", - /* 0x001A */ "ACTOR_UNSET_1A", - /* 0x001B */ "ACTOR_EN_TITE", - /* 0x001C */ "ACTOR_EN_REEBA", - /* 0x001D */ "ACTOR_EN_PEEHAT", - /* 0x001E */ "ACTOR_EN_BUTTE", - /* 0x001F */ "ACTOR_UNSET_1F", - /* 0x0020 */ "ACTOR_EN_INSECT", - /* 0x0021 */ "ACTOR_EN_FISH", - /* 0x0022 */ "ACTOR_UNSET_22", - /* 0x0023 */ "ACTOR_EN_HOLL", - /* 0x0024 */ "ACTOR_EN_SCENE_CHANGE", - /* 0x0025 */ "ACTOR_EN_ZF", - /* 0x0026 */ "ACTOR_EN_HATA", - /* 0x0027 */ "ACTOR_BOSS_DODONGO", - /* 0x0028 */ "ACTOR_BOSS_GOMA", - /* 0x0029 */ "ACTOR_EN_ZL1", - /* 0x002A */ "ACTOR_EN_VIEWER", - /* 0x002B */ "ACTOR_EN_GOMA", - /* 0x002C */ "ACTOR_BG_PUSHBOX", - /* 0x002D */ "ACTOR_EN_BUBBLE", - /* 0x002E */ "ACTOR_DOOR_SHUTTER", - /* 0x002F */ "ACTOR_EN_DODOJR", - /* 0x0030 */ "ACTOR_EN_BDFIRE", - /* 0x0031 */ "ACTOR_UNSET_31", - /* 0x0032 */ "ACTOR_EN_BOOM", - /* 0x0033 */ "ACTOR_EN_TORCH2", - /* 0x0034 */ "ACTOR_EN_BILI", - /* 0x0035 */ "ACTOR_EN_TP", - /* 0x0036 */ "ACTOR_UNSET_36", - /* 0x0037 */ "ACTOR_EN_ST", - /* 0x0038 */ "ACTOR_EN_BW", - /* 0x0039 */ "ACTOR_EN_A_OBJ", - /* 0x003A */ "ACTOR_EN_EIYER", - /* 0x003B */ "ACTOR_EN_RIVER_SOUND", - /* 0x003C */ "ACTOR_EN_HORSE_NORMAL", - /* 0x003D */ "ACTOR_EN_OSSAN", - /* 0x003E */ "ACTOR_BG_TREEMOUTH", - /* 0x003F */ "ACTOR_BG_DODOAGO", - /* 0x0040 */ "ACTOR_BG_HIDAN_DALM", - /* 0x0041 */ "ACTOR_BG_HIDAN_HROCK", - /* 0x0042 */ "ACTOR_EN_HORSE_GANON", - /* 0x0043 */ "ACTOR_BG_HIDAN_ROCK", - /* 0x0044 */ "ACTOR_BG_HIDAN_RSEKIZOU", - /* 0x0045 */ "ACTOR_BG_HIDAN_SEKIZOU", - /* 0x0046 */ "ACTOR_BG_HIDAN_SIMA", - /* 0x0047 */ "ACTOR_BG_HIDAN_SYOKU", - /* 0x0048 */ "ACTOR_EN_XC", - /* 0x0049 */ "ACTOR_BG_HIDAN_CURTAIN", - /* 0x004A */ "ACTOR_BG_SPOT00_HANEBASI", - /* 0x004B */ "ACTOR_EN_MB", - /* 0x004C */ "ACTOR_EN_BOMBF", - /* 0x004D */ "ACTOR_EN_ZL2", - /* 0x004E */ "ACTOR_BG_HIDAN_FSLIFT", - /* 0x004F */ "ACTOR_EN_OE2", - /* 0x0050 */ "ACTOR_BG_YDAN_HASI", - /* 0x0051 */ "ACTOR_BG_YDAN_MARUTA", - /* 0x0052 */ "ACTOR_BOSS_GANONDROF", - /* 0x0053 */ "ACTOR_UNSET_53", - /* 0x0054 */ "ACTOR_EN_AM", - /* 0x0055 */ "ACTOR_EN_DEKUBABA", - /* 0x0056 */ "ACTOR_EN_M_FIRE1", - /* 0x0057 */ "ACTOR_EN_M_THUNDER", - /* 0x0058 */ "ACTOR_BG_DDAN_JD", - /* 0x0059 */ "ACTOR_BG_BREAKWALL", - /* 0x005A */ "ACTOR_EN_JJ", - /* 0x005B */ "ACTOR_EN_HORSE_ZELDA", - /* 0x005C */ "ACTOR_BG_DDAN_KD", - /* 0x005D */ "ACTOR_DOOR_WARP1", - /* 0x005E */ "ACTOR_OBJ_SYOKUDAI", - /* 0x005F */ "ACTOR_ITEM_B_HEART", - /* 0x0060 */ "ACTOR_EN_DEKUNUTS", - /* 0x0061 */ "ACTOR_BG_MENKURI_KAITEN", - /* 0x0062 */ "ACTOR_BG_MENKURI_EYE", - /* 0x0063 */ "ACTOR_EN_VALI", - /* 0x0064 */ "ACTOR_BG_MIZU_MOVEBG", - /* 0x0065 */ "ACTOR_BG_MIZU_WATER", - /* 0x0066 */ "ACTOR_ARMS_HOOK", - /* 0x0067 */ "ACTOR_EN_FHG", - /* 0x0068 */ "ACTOR_BG_MORI_HINERI", - /* 0x0069 */ "ACTOR_EN_BB", - /* 0x006A */ "ACTOR_BG_TOKI_HIKARI", - /* 0x006B */ "ACTOR_EN_YUKABYUN", - /* 0x006C */ "ACTOR_BG_TOKI_SWD", - /* 0x006D */ "ACTOR_EN_FHG_FIRE", - /* 0x006E */ "ACTOR_BG_MJIN", - /* 0x006F */ "ACTOR_BG_HIDAN_KOUSI", - /* 0x0070 */ "ACTOR_DOOR_TOKI", - /* 0x0071 */ "ACTOR_BG_HIDAN_HAMSTEP", - /* 0x0072 */ "ACTOR_EN_BIRD", - /* 0x0073 */ "ACTOR_UNSET_73", - /* 0x0074 */ "ACTOR_UNSET_74", - /* 0x0075 */ "ACTOR_UNSET_75", - /* 0x0076 */ "ACTOR_UNSET_76", - /* 0x0077 */ "ACTOR_EN_WOOD02", - /* 0x0078 */ "ACTOR_UNSET_78", - /* 0x0079 */ "ACTOR_UNSET_79", - /* 0x007A */ "ACTOR_UNSET_7A", - /* 0x007B */ "ACTOR_UNSET_7B", - /* 0x007C */ "ACTOR_EN_LIGHTBOX", - /* 0x007D */ "ACTOR_EN_PU_BOX", - /* 0x007E */ "ACTOR_UNSET_7E", - /* 0x007F */ "ACTOR_UNSET_7F", - /* 0x0080 */ "ACTOR_EN_TRAP", - /* 0x0081 */ "ACTOR_EN_AROW_TRAP", - /* 0x0082 */ "ACTOR_EN_VASE", - /* 0x0083 */ "ACTOR_UNSET_83", - /* 0x0084 */ "ACTOR_EN_TA", - /* 0x0085 */ "ACTOR_EN_TK", - /* 0x0086 */ "ACTOR_BG_MORI_BIGST", - /* 0x0087 */ "ACTOR_BG_MORI_ELEVATOR", - /* 0x0088 */ "ACTOR_BG_MORI_KAITENKABE", - /* 0x0089 */ "ACTOR_BG_MORI_RAKKATENJO", - /* 0x008A */ "ACTOR_EN_VM", - /* 0x008B */ "ACTOR_DEMO_EFFECT", - /* 0x008C */ "ACTOR_DEMO_KANKYO", - /* 0x008D */ "ACTOR_BG_HIDAN_FWBIG", - /* 0x008E */ "ACTOR_EN_FLOORMAS", - /* 0x008F */ "ACTOR_EN_HEISHI1", - /* 0x0090 */ "ACTOR_EN_RD", - /* 0x0091 */ "ACTOR_EN_PO_SISTERS", - /* 0x0092 */ "ACTOR_BG_HEAVY_BLOCK", - /* 0x0093 */ "ACTOR_BG_PO_EVENT", - /* 0x0094 */ "ACTOR_OBJ_MURE", - /* 0x0095 */ "ACTOR_EN_SW", - /* 0x0096 */ "ACTOR_BOSS_FD", - /* 0x0097 */ "ACTOR_OBJECT_KANKYO", - /* 0x0098 */ "ACTOR_EN_DU", - /* 0x0099 */ "ACTOR_EN_FD", - /* 0x009A */ "ACTOR_EN_HORSE_LINK_CHILD", - /* 0x009B */ "ACTOR_DOOR_ANA", - /* 0x009C */ "ACTOR_BG_SPOT02_OBJECTS", - /* 0x009D */ "ACTOR_BG_HAKA", - /* 0x009E */ "ACTOR_MAGIC_WIND", - /* 0x009F */ "ACTOR_MAGIC_FIRE", - /* 0x00A0 */ "ACTOR_UNSET_A0", - /* 0x00A1 */ "ACTOR_EN_RU1", - /* 0x00A2 */ "ACTOR_BOSS_FD2", - /* 0x00A3 */ "ACTOR_EN_FD_FIRE", - /* 0x00A4 */ "ACTOR_EN_DH", - /* 0x00A5 */ "ACTOR_EN_DHA", - /* 0x00A6 */ "ACTOR_EN_RL", - /* 0x00A7 */ "ACTOR_EN_ENCOUNT1", - /* 0x00A8 */ "ACTOR_DEMO_DU", - /* 0x00A9 */ "ACTOR_DEMO_IM", - /* 0x00AA */ "ACTOR_DEMO_TRE_LGT", - /* 0x00AB */ "ACTOR_EN_FW", - /* 0x00AC */ "ACTOR_BG_VB_SIMA", - /* 0x00AD */ "ACTOR_EN_VB_BALL", - /* 0x00AE */ "ACTOR_BG_HAKA_MEGANE", - /* 0x00AF */ "ACTOR_BG_HAKA_MEGANEBG", - /* 0x00B0 */ "ACTOR_BG_HAKA_SHIP", - /* 0x00B1 */ "ACTOR_BG_HAKA_SGAMI", - /* 0x00B2 */ "ACTOR_UNSET_B2", - /* 0x00B3 */ "ACTOR_EN_HEISHI2", - /* 0x00B4 */ "ACTOR_EN_ENCOUNT2", - /* 0x00B5 */ "ACTOR_EN_FIRE_ROCK", - /* 0x00B6 */ "ACTOR_EN_BROB", - /* 0x00B7 */ "ACTOR_MIR_RAY", - /* 0x00B8 */ "ACTOR_BG_SPOT09_OBJ", - /* 0x00B9 */ "ACTOR_BG_SPOT18_OBJ", - /* 0x00BA */ "ACTOR_BOSS_VA", - /* 0x00BB */ "ACTOR_BG_HAKA_TUBO", - /* 0x00BC */ "ACTOR_BG_HAKA_TRAP", - /* 0x00BD */ "ACTOR_BG_HAKA_HUTA", - /* 0x00BE */ "ACTOR_BG_HAKA_ZOU", - /* 0x00BF */ "ACTOR_BG_SPOT17_FUNEN", - /* 0x00C0 */ "ACTOR_EN_SYATEKI_ITM", - /* 0x00C1 */ "ACTOR_EN_SYATEKI_MAN", - /* 0x00C2 */ "ACTOR_EN_TANA", - /* 0x00C3 */ "ACTOR_EN_NB", - /* 0x00C4 */ "ACTOR_BOSS_MO", - /* 0x00C5 */ "ACTOR_EN_SB", - /* 0x00C6 */ "ACTOR_EN_BIGOKUTA", - /* 0x00C7 */ "ACTOR_EN_KAREBABA", - /* 0x00C8 */ "ACTOR_BG_BDAN_OBJECTS", - /* 0x00C9 */ "ACTOR_DEMO_SA", - /* 0x00CA */ "ACTOR_DEMO_GO", - /* 0x00CB */ "ACTOR_EN_IN", - /* 0x00CC */ "ACTOR_EN_TR", - /* 0x00CD */ "ACTOR_BG_SPOT16_BOMBSTONE", - /* 0x00CE */ "ACTOR_UNSET_CE", - /* 0x00CF */ "ACTOR_BG_HIDAN_KOWARERUKABE", - /* 0x00D0 */ "ACTOR_BG_BOMBWALL", - /* 0x00D1 */ "ACTOR_BG_SPOT08_ICEBLOCK", - /* 0x00D2 */ "ACTOR_EN_RU2", - /* 0x00D3 */ "ACTOR_OBJ_DEKUJR", - /* 0x00D4 */ "ACTOR_BG_MIZU_UZU", - /* 0x00D5 */ "ACTOR_BG_SPOT06_OBJECTS", - /* 0x00D6 */ "ACTOR_BG_ICE_OBJECTS", - /* 0x00D7 */ "ACTOR_BG_HAKA_WATER", - /* 0x00D8 */ "ACTOR_UNSET_D8", - /* 0x00D9 */ "ACTOR_EN_MA2", - /* 0x00DA */ "ACTOR_EN_BOM_CHU", - /* 0x00DB */ "ACTOR_EN_HORSE_GAME_CHECK", - /* 0x00DC */ "ACTOR_BOSS_TW", - /* 0x00DD */ "ACTOR_EN_RR", - /* 0x00DE */ "ACTOR_EN_BA", - /* 0x00DF */ "ACTOR_EN_BX", - /* 0x00E0 */ "ACTOR_EN_ANUBICE", - /* 0x00E1 */ "ACTOR_EN_ANUBICE_FIRE", - /* 0x00E2 */ "ACTOR_BG_MORI_HASHIGO", - /* 0x00E3 */ "ACTOR_BG_MORI_HASHIRA4", - /* 0x00E4 */ "ACTOR_BG_MORI_IDOMIZU", - /* 0x00E5 */ "ACTOR_BG_SPOT16_DOUGHNUT", - /* 0x00E6 */ "ACTOR_BG_BDAN_SWITCH", - /* 0x00E7 */ "ACTOR_EN_MA1", - /* 0x00E8 */ "ACTOR_BOSS_GANON", - /* 0x00E9 */ "ACTOR_BOSS_SST", - /* 0x00EA */ "ACTOR_UNSET_EA", - /* 0x00EB */ "ACTOR_UNSET_EB", - /* 0x00EC */ "ACTOR_EN_NY", - /* 0x00ED */ "ACTOR_EN_FR", - /* 0x00EE */ "ACTOR_ITEM_SHIELD", - /* 0x00EF */ "ACTOR_BG_ICE_SHELTER", - /* 0x00F0 */ "ACTOR_EN_ICE_HONO", - /* 0x00F1 */ "ACTOR_ITEM_OCARINA", - /* 0x00F2 */ "ACTOR_UNSET_F2", - /* 0x00F3 */ "ACTOR_UNSET_F3", - /* 0x00F4 */ "ACTOR_MAGIC_DARK", - /* 0x00F5 */ "ACTOR_DEMO_6K", - /* 0x00F6 */ "ACTOR_EN_ANUBICE_TAG", - /* 0x00F7 */ "ACTOR_BG_HAKA_GATE", - /* 0x00F8 */ "ACTOR_BG_SPOT15_SAKU", - /* 0x00F9 */ "ACTOR_BG_JYA_GOROIWA", - /* 0x00FA */ "ACTOR_BG_JYA_ZURERUKABE", - /* 0x00FB */ "ACTOR_UNSET_FB", - /* 0x00FC */ "ACTOR_BG_JYA_COBRA", - /* 0x00FD */ "ACTOR_BG_JYA_KANAAMI", - /* 0x00FE */ "ACTOR_FISHING", - /* 0x00FF */ "ACTOR_OBJ_OSHIHIKI", - /* 0x0100 */ "ACTOR_BG_GATE_SHUTTER", - /* 0x0101 */ "ACTOR_EFF_DUST", - /* 0x0102 */ "ACTOR_BG_SPOT01_FUSYA", - /* 0x0103 */ "ACTOR_BG_SPOT01_IDOHASHIRA", - /* 0x0104 */ "ACTOR_BG_SPOT01_IDOMIZU", - /* 0x0105 */ "ACTOR_BG_PO_SYOKUDAI", - /* 0x0106 */ "ACTOR_BG_GANON_OTYUKA", - /* 0x0107 */ "ACTOR_BG_SPOT15_RRBOX", - /* 0x0108 */ "ACTOR_BG_UMAJUMP", - /* 0x0109 */ "ACTOR_UNSET_109", - /* 0x010A */ "ACTOR_ARROW_FIRE", - /* 0x010B */ "ACTOR_ARROW_ICE", - /* 0x010C */ "ACTOR_ARROW_LIGHT", - /* 0x010D */ "ACTOR_UNSET_10D", - /* 0x010E */ "ACTOR_UNSET_10E", - /* 0x010F */ "ACTOR_ITEM_ETCETERA", - /* 0x0110 */ "ACTOR_OBJ_KIBAKO", - /* 0x0111 */ "ACTOR_OBJ_TSUBO", - /* 0x0112 */ "ACTOR_EN_WONDER_ITEM", - /* 0x0113 */ "ACTOR_EN_IK", - /* 0x0114 */ "ACTOR_DEMO_IK", - /* 0x0115 */ "ACTOR_EN_SKJ", - /* 0x0116 */ "ACTOR_EN_SKJNEEDLE", - /* 0x0117 */ "ACTOR_EN_G_SWITCH", - /* 0x0118 */ "ACTOR_DEMO_EXT", - /* 0x0119 */ "ACTOR_DEMO_SHD", - /* 0x011A */ "ACTOR_EN_DNS", - /* 0x011B */ "ACTOR_ELF_MSG", - /* 0x011C */ "ACTOR_EN_HONOTRAP", - /* 0x011D */ "ACTOR_EN_TUBO_TRAP", - /* 0x011E */ "ACTOR_OBJ_ICE_POLY", - /* 0x011F */ "ACTOR_BG_SPOT03_TAKI", - /* 0x0120 */ "ACTOR_BG_SPOT07_TAKI", - /* 0x0121 */ "ACTOR_EN_FZ", - /* 0x0122 */ "ACTOR_EN_PO_RELAY", - /* 0x0123 */ "ACTOR_BG_RELAY_OBJECTS", - /* 0x0124 */ "ACTOR_EN_DIVING_GAME", - /* 0x0125 */ "ACTOR_EN_KUSA", - /* 0x0126 */ "ACTOR_OBJ_BEAN", - /* 0x0127 */ "ACTOR_OBJ_BOMBIWA", - /* 0x0128 */ "ACTOR_UNSET_128", - /* 0x0129 */ "ACTOR_UNSET_129", - /* 0x012A */ "ACTOR_OBJ_SWITCH", - /* 0x012B */ "ACTOR_OBJ_ELEVATOR", - /* 0x012C */ "ACTOR_OBJ_LIFT", - /* 0x012D */ "ACTOR_OBJ_HSBLOCK", - /* 0x012E */ "ACTOR_EN_OKARINA_TAG", - /* 0x012F */ "ACTOR_EN_YABUSAME_MARK", - /* 0x0130 */ "ACTOR_EN_GOROIWA", - /* 0x0131 */ "ACTOR_EN_EX_RUPPY", - /* 0x0132 */ "ACTOR_EN_TORYO", - /* 0x0133 */ "ACTOR_EN_DAIKU", - /* 0x0134 */ "ACTOR_UNSET_134", - /* 0x0135 */ "ACTOR_EN_NWC", - /* 0x0136 */ "ACTOR_EN_BLKOBJ", - /* 0x0137 */ "ACTOR_ITEM_INBOX", - /* 0x0138 */ "ACTOR_EN_GE1", - /* 0x0139 */ "ACTOR_OBJ_BLOCKSTOP", - /* 0x013A */ "ACTOR_EN_SDA", - /* 0x013B */ "ACTOR_EN_CLEAR_TAG", - /* 0x013C */ "ACTOR_EN_NIW_LADY", - /* 0x013D */ "ACTOR_EN_GM", - /* 0x013E */ "ACTOR_EN_MS", - /* 0x013F */ "ACTOR_EN_HS", - /* 0x0140 */ "ACTOR_BG_INGATE", - /* 0x0141 */ "ACTOR_EN_KANBAN", - /* 0x0142 */ "ACTOR_EN_HEISHI3", - /* 0x0143 */ "ACTOR_EN_SYATEKI_NIW", - /* 0x0144 */ "ACTOR_EN_ATTACK_NIW", - /* 0x0145 */ "ACTOR_BG_SPOT01_IDOSOKO", - /* 0x0146 */ "ACTOR_EN_SA", - /* 0x0147 */ "ACTOR_EN_WONDER_TALK", - /* 0x0148 */ "ACTOR_BG_GJYO_BRIDGE", - /* 0x0149 */ "ACTOR_EN_DS", - /* 0x014A */ "ACTOR_EN_MK", - /* 0x014B */ "ACTOR_EN_BOM_BOWL_MAN", - /* 0x014C */ "ACTOR_EN_BOM_BOWL_PIT", - /* 0x014D */ "ACTOR_EN_OWL", - /* 0x014E */ "ACTOR_EN_ISHI", - /* 0x014F */ "ACTOR_OBJ_HANA", - /* 0x0150 */ "ACTOR_OBJ_LIGHTSWITCH", - /* 0x0151 */ "ACTOR_OBJ_MURE2", - /* 0x0152 */ "ACTOR_EN_GO", - /* 0x0153 */ "ACTOR_EN_FU", - /* 0x0154 */ "ACTOR_UNSET_154", - /* 0x0155 */ "ACTOR_EN_CHANGER", - /* 0x0156 */ "ACTOR_BG_JYA_MEGAMI", - /* 0x0157 */ "ACTOR_BG_JYA_LIFT", - /* 0x0158 */ "ACTOR_BG_JYA_BIGMIRROR", - /* 0x0159 */ "ACTOR_BG_JYA_BOMBCHUIWA", - /* 0x015A */ "ACTOR_BG_JYA_AMISHUTTER", - /* 0x015B */ "ACTOR_BG_JYA_BOMBIWA", - /* 0x015C */ "ACTOR_BG_SPOT18_BASKET", - /* 0x015D */ "ACTOR_UNSET_15D", - /* 0x015E */ "ACTOR_EN_GANON_ORGAN", - /* 0x015F */ "ACTOR_EN_SIOFUKI", - /* 0x0160 */ "ACTOR_EN_STREAM", - /* 0x0161 */ "ACTOR_UNSET_161", - /* 0x0162 */ "ACTOR_EN_MM", - /* 0x0163 */ "ACTOR_EN_KO", - /* 0x0164 */ "ACTOR_EN_KZ", - /* 0x0165 */ "ACTOR_EN_WEATHER_TAG", - /* 0x0166 */ "ACTOR_BG_SST_FLOOR", - /* 0x0167 */ "ACTOR_EN_ANI", - /* 0x0168 */ "ACTOR_EN_EX_ITEM", - /* 0x0169 */ "ACTOR_BG_JYA_IRONOBJ", - /* 0x016A */ "ACTOR_EN_JS", - /* 0x016B */ "ACTOR_EN_JSJUTAN", - /* 0x016C */ "ACTOR_EN_CS", - /* 0x016D */ "ACTOR_EN_MD", - /* 0x016E */ "ACTOR_EN_HY", - /* 0x016F */ "ACTOR_EN_GANON_MANT", - /* 0x0170 */ "ACTOR_EN_OKARINA_EFFECT", - /* 0x0171 */ "ACTOR_EN_MAG", - /* 0x0172 */ "ACTOR_DOOR_GERUDO", - /* 0x0173 */ "ACTOR_ELF_MSG2", - /* 0x0174 */ "ACTOR_DEMO_GT", - /* 0x0175 */ "ACTOR_EN_PO_FIELD", - /* 0x0176 */ "ACTOR_EFC_ERUPC", - /* 0x0177 */ "ACTOR_BG_ZG", - /* 0x0178 */ "ACTOR_EN_HEISHI4", - /* 0x0179 */ "ACTOR_EN_ZL3", - /* 0x017A */ "ACTOR_BOSS_GANON2", - /* 0x017B */ "ACTOR_EN_KAKASI", - /* 0x017C */ "ACTOR_EN_TAKARA_MAN", - /* 0x017D */ "ACTOR_OBJ_MAKEOSHIHIKI", - /* 0x017E */ "ACTOR_OCEFF_SPOT", - /* 0x017F */ "ACTOR_END_TITLE", - /* 0x0180 */ "ACTOR_UNSET_180", - /* 0x0181 */ "ACTOR_EN_TORCH", - /* 0x0182 */ "ACTOR_DEMO_EC", - /* 0x0183 */ "ACTOR_SHOT_SUN", - /* 0x0184 */ "ACTOR_EN_DY_EXTRA", - /* 0x0185 */ "ACTOR_EN_WONDER_TALK2", - /* 0x0186 */ "ACTOR_EN_GE2", - /* 0x0187 */ "ACTOR_OBJ_ROOMTIMER", - /* 0x0188 */ "ACTOR_EN_SSH", - /* 0x0189 */ "ACTOR_EN_STH", - /* 0x018A */ "ACTOR_OCEFF_WIPE", - /* 0x018B */ "ACTOR_OCEFF_STORM", - /* 0x018C */ "ACTOR_EN_WEIYER", - /* 0x018D */ "ACTOR_BG_SPOT05_SOKO", - /* 0x018E */ "ACTOR_BG_JYA_1FLIFT", - /* 0x018F */ "ACTOR_BG_JYA_HAHENIRON", - /* 0x0190 */ "ACTOR_BG_SPOT12_GATE", - /* 0x0191 */ "ACTOR_BG_SPOT12_SAKU", - /* 0x0192 */ "ACTOR_EN_HINTNUTS", - /* 0x0193 */ "ACTOR_EN_NUTSBALL", - /* 0x0194 */ "ACTOR_BG_SPOT00_BREAK", - /* 0x0195 */ "ACTOR_EN_SHOPNUTS", - /* 0x0196 */ "ACTOR_EN_IT", - /* 0x0197 */ "ACTOR_EN_GELDB", - /* 0x0198 */ "ACTOR_OCEFF_WIPE2", - /* 0x0199 */ "ACTOR_OCEFF_WIPE3", - /* 0x019A */ "ACTOR_EN_NIW_GIRL", - /* 0x019B */ "ACTOR_EN_DOG", - /* 0x019C */ "ACTOR_EN_SI", - /* 0x019D */ "ACTOR_BG_SPOT01_OBJECTS2", - /* 0x019E */ "ACTOR_OBJ_COMB", - /* 0x019F */ "ACTOR_BG_SPOT11_BAKUDANKABE", - /* 0x01A0 */ "ACTOR_OBJ_KIBAKO2", - /* 0x01A1 */ "ACTOR_EN_DNT_DEMO", - /* 0x01A2 */ "ACTOR_EN_DNT_JIJI", - /* 0x01A3 */ "ACTOR_EN_DNT_NOMAL", - /* 0x01A4 */ "ACTOR_EN_GUEST", - /* 0x01A5 */ "ACTOR_BG_BOM_GUARD", - /* 0x01A6 */ "ACTOR_EN_HS2", - /* 0x01A7 */ "ACTOR_DEMO_KEKKAI", - /* 0x01A8 */ "ACTOR_BG_SPOT08_BAKUDANKABE", - /* 0x01A9 */ "ACTOR_BG_SPOT17_BAKUDANKABE", - /* 0x01AA */ "ACTOR_UNSET_1AA", - /* 0x01AB */ "ACTOR_OBJ_MURE3", - /* 0x01AC */ "ACTOR_EN_TG", - /* 0x01AD */ "ACTOR_EN_MU", - /* 0x01AE */ "ACTOR_EN_GO2", - /* 0x01AF */ "ACTOR_EN_WF", - /* 0x01B0 */ "ACTOR_EN_SKB", - /* 0x01B1 */ "ACTOR_DEMO_GJ", - /* 0x01B2 */ "ACTOR_DEMO_GEFF", - /* 0x01B3 */ "ACTOR_BG_GND_FIREMEIRO", - /* 0x01B4 */ "ACTOR_BG_GND_DARKMEIRO", - /* 0x01B5 */ "ACTOR_BG_GND_SOULMEIRO", - /* 0x01B6 */ "ACTOR_BG_GND_NISEKABE", - /* 0x01B7 */ "ACTOR_BG_GND_ICEBLOCK", - /* 0x01B8 */ "ACTOR_EN_GB", - /* 0x01B9 */ "ACTOR_EN_GS", - /* 0x01BA */ "ACTOR_BG_MIZU_BWALL", - /* 0x01BB */ "ACTOR_BG_MIZU_SHUTTER", - /* 0x01BC */ "ACTOR_EN_DAIKU_KAKARIKO", - /* 0x01BD */ "ACTOR_BG_BOWL_WALL", - /* 0x01BE */ "ACTOR_EN_WALL_TUBO", - /* 0x01BF */ "ACTOR_EN_PO_DESERT", - /* 0x01C0 */ "ACTOR_EN_CROW", - /* 0x01C1 */ "ACTOR_DOOR_KILLER", - /* 0x01C2 */ "ACTOR_BG_SPOT11_OASIS", - /* 0x01C3 */ "ACTOR_BG_SPOT18_FUTA", - /* 0x01C4 */ "ACTOR_BG_SPOT18_SHUTTER", - /* 0x01C5 */ "ACTOR_EN_MA3", - /* 0x01C6 */ "ACTOR_EN_COW", - /* 0x01C7 */ "ACTOR_BG_ICE_TURARA", - /* 0x01C8 */ "ACTOR_BG_ICE_SHUTTER", - /* 0x01C9 */ "ACTOR_EN_KAKASI2", - /* 0x01CA */ "ACTOR_EN_KAKASI3", - /* 0x01CB */ "ACTOR_OCEFF_WIPE4", - /* 0x01CC */ "ACTOR_EN_EG", - /* 0x01CD */ "ACTOR_BG_MENKURI_NISEKABE", - /* 0x01CE */ "ACTOR_EN_ZO", - /* 0x01CF */ "ACTOR_OBJ_MAKEKINSUTA", - /* 0x01D0 */ "ACTOR_EN_GE3", - /* 0x01D1 */ "ACTOR_OBJ_TIMEBLOCK", - /* 0x01D2 */ "ACTOR_OBJ_HAMISHI", - /* 0x01D3 */ "ACTOR_EN_ZL4", - /* 0x01D4 */ "ACTOR_EN_MM2", - /* 0x01D5 */ "ACTOR_BG_JYA_BLOCK", - /* 0x01D6 */ "ACTOR_OBJ_WARP2BLOCK", - /* 0x01D7 */ "ACTOR_ID_MAX" // originally "ACTOR_DLF_MAX" -}; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.cpp index 81320a99c4..3eabebf19e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.cpp @@ -3,12 +3,12 @@ using namespace std; -EndMarker::EndMarker(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +EndMarker::EndMarker(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { } -string EndMarker::GenerateSourceCodePass1(string roomName, int baseAddress) +string EndMarker::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str()); diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.h b/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.h index 74aae4ac8c..e63d2729ef 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/EndMarker.h @@ -5,11 +5,11 @@ class EndMarker : public ZRoomCommand { public: - EndMarker(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + EndMarker(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp new file mode 100644 index 0000000000..17846274b9 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp @@ -0,0 +1,95 @@ +#include "SetActorCutsceneList.h" +#include "../../BitConverter.h" +#include "../../Globals.h" +#include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" + +using namespace std; + +SetActorCutsceneList::SetActorCutsceneList(ZRoom* nZRoom, std::vector rawData, + uint32_t rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) +{ + int32_t numCutscenes = rawData[rawDataIndex + 1]; + segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; + + cutscenes = vector(); + + int32_t currentPtr = segmentOffset; + + for (int32_t i = 0; i < numCutscenes; i++) + { + ActorCutsceneEntry* entry = new ActorCutsceneEntry(rawData, currentPtr); + cutscenes.push_back(entry); + + currentPtr += 16; + } + + string declaration = ""; + + for (ActorCutsceneEntry* entry : cutscenes) + { + declaration += StringHelper::Sprintf( + " { %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", entry->priority, entry->length, + entry->unk4, entry->unk6, entry->additionalCutscene, entry->sound, entry->unkB, + entry->unkC, entry->unkE, entry->letterboxSize); + } + + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, cutscenes.size() * 16, "ActorCutscene", + StringHelper::Sprintf("%sActorCutsceneList0x%06X", zRoom->GetName().c_str(), segmentOffset), + 0, declaration); +} + +SetActorCutsceneList::~SetActorCutsceneList() +{ + for (ActorCutsceneEntry* entry : cutscenes) + delete entry; +} + +string SetActorCutsceneList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) +{ + return StringHelper::Sprintf( + "%s 0x%02X, (u32)&%sActorCutsceneList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), cutscenes.size(), + zRoom->GetName().c_str(), segmentOffset); +} + +string SetActorCutsceneList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) +{ + return ""; +} + +size_t SetActorCutsceneList::GetRawDataSize() +{ + return ZRoomCommand::GetRawDataSize() + (cutscenes.size() * 16); +} + +string SetActorCutsceneList::GenerateExterns() +{ + return StringHelper::Sprintf("extern ActorCutscene %sActorCutsceneList0x%06X[];\n", + zRoom->GetName().c_str(), segmentOffset); +} + +string SetActorCutsceneList::GetCommandCName() +{ + return "SCmdCutsceneActorList"; +} + +RoomCommand SetActorCutsceneList::GetRoomCommand() +{ + return RoomCommand::SetActorCutsceneList; +} + +ActorCutsceneEntry::ActorCutsceneEntry(std::vector rawData, uint32_t rawDataIndex) + : priority(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), + length(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), + unk4(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), + unk6(BitConverter::ToInt16BE(rawData, rawDataIndex + 6)), + additionalCutscene(BitConverter::ToInt16BE(rawData, rawDataIndex + 8)), + sound(rawData[rawDataIndex + 0xA]), unkB(rawData[rawDataIndex + 0xB]), + unkC(BitConverter::ToInt16BE(rawData, rawDataIndex + 0xC)), unkE(rawData[rawDataIndex + 0xE]), + letterboxSize(rawData[rawDataIndex + 0xF]) +{ +} diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.h new file mode 100644 index 0000000000..96d7b7653e --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.h @@ -0,0 +1,38 @@ +#pragma once + +#include "../ZRoomCommand.h" + +class ActorCutsceneEntry +{ +public: + int16_t priority; + int16_t length; + int16_t unk4; + int16_t unk6; + int16_t additionalCutscene; + uint8_t sound; + uint8_t unkB; + int16_t unkC; + uint8_t unkE; + uint8_t letterboxSize; + + ActorCutsceneEntry(std::vector rawData, uint32_t rawDataIndex); +}; + +class SetActorCutsceneList : public ZRoomCommand +{ +public: + SetActorCutsceneList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); + ~SetActorCutsceneList(); + + std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + std::string GetCommandCName() override; + std::string GenerateExterns() override; + RoomCommand GetRoomCommand() override; + size_t GetRawDataSize() override; + +private: + std::vector cutscenes; + uint32_t segmentOffset; +}; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.cpp index 762105106e..8d094e7b31 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.cpp @@ -3,12 +3,12 @@ #include "../../Globals.h" #include "../../StringHelper.h" #include "../../ZFile.h" -#include "../ActorList.h" +#include "../ZNames.h" #include "../ZRoom.h" using namespace std; -SetActorList::SetActorList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetActorList::SetActorList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { numActors = rawData[rawDataIndex + 1]; @@ -26,7 +26,6 @@ SetActorList::~SetActorList() for (ActorSpawnEntry* entry : actors) delete entry; - actors.clear(); } string SetActorList::GetSourceOutputCode(std::string prefix) @@ -34,12 +33,12 @@ string SetActorList::GetSourceOutputCode(std::string prefix) return ""; } -string SetActorList::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetActorList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return ""; } -string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress) +string SetActorList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) { string sourceOutput = ""; size_t numActorsReal = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 16; @@ -55,13 +54,13 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress) } sourceOutput += - StringHelper::Sprintf("%s 0x%02X, (u32)%sActorList0x%06X };", + StringHelper::Sprintf("\n %s 0x%02X, (u32)%sActorList0x%06X \n};", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), numActors, roomName.c_str(), segmentOffset); // zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, // DeclarationPadding::None, GetRawDataSize(), "SCmdActorList", - //ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress), sourceOutput); + // ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress), sourceOutput); string declaration = ""; @@ -70,50 +69,50 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress) { uint16_t actorNum = entry->actorNum; - // SW97 Actor 0x22 was removed, so we want to not output a working actor. - if (actorNum == 0x22 && Globals::Instance->game == ZGame::OOT_SW97) + if (Globals::Instance->game == ZGame::MM_RETAIL) + { declaration += StringHelper::Sprintf( - "\t//{ %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", - /*StringHelper::Sprintf("SW_REMOVED_0x%04X", actorNum).c_str()*/ - "ACTOR_DUNGEON_KEEP", entry->posX, entry->posY, entry->posZ, entry->rotX, - entry->rotY, entry->rotZ, (uint16_t)entry->initVar, segmentOffset + (index * 16)); + " { %s, %i, %i, %i, SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X), " + "SPAWN_ROT_FLAGS(%i, 0x%04X), 0x%04X }, //0x%06X", + ZNames::GetActorName(actorNum).c_str(), entry->posX, entry->posY, entry->posZ, + (entry->rotX >> 7) & 0b111111111, entry->rotX & 0b1111111, + (entry->rotY >> 7) & 0b111111111, entry->rotY & 0b1111111, + (entry->rotZ >> 7) & 0b111111111, entry->rotZ & 0b1111111, (uint16_t)entry->initVar, + segmentOffset + (index * 16)); + } else { - // SW97 Actor 0x23 and above are shifted up by one because 0x22 was removed between SW97 - // and retail. We need to shift down by one - if (Globals::Instance->game == ZGame::OOT_SW97 && actorNum >= 0x23) - actorNum--; - - if (actorNum < sizeof(ActorList) / sizeof(ActorList[0])) - declaration += - StringHelper::Sprintf("\t{ %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", - ActorList[actorNum].c_str(), entry->posX, entry->posY, - entry->posZ, entry->rotX, entry->rotY, entry->rotZ, - (uint16_t)entry->initVar, segmentOffset + (index * 16)); - else - declaration += StringHelper::Sprintf( - "\t{ 0x%04X, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", actorNum, entry->posX, - entry->posY, entry->posZ, entry->rotX, entry->rotY, entry->rotZ, - (uint16_t)entry->initVar, segmentOffset + (index * 16)); + declaration += StringHelper::Sprintf( + " { %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", + ZNames::GetActorName(actorNum).c_str(), entry->posX, entry->posY, entry->posZ, + entry->rotX, entry->rotY, entry->rotZ, (uint16_t)entry->initVar, + segmentOffset + (index * 16)); if (index < actors.size() - 1) declaration += "\n"; } + if (index < actors.size() - 1) + declaration += "\n"; + index++; } + DeclarationPadding padding = DeclarationPadding::Pad16; + if (Globals::Instance->game == ZGame::MM_RETAIL) + padding = DeclarationPadding::None; + zRoom->parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, actors.size() * 16, - "ActorEntry", StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset), + segmentOffset, DeclarationAlignment::None, padding, actors.size() * 16, "ActorEntry", + StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset), GetActorListArraySize(), declaration); return sourceOutput; } -int32_t SetActorList::GetRawDataSize() +size_t SetActorList::GetRawDataSize() { - return ZRoomCommand::GetRawDataSize() + ((int)actors.size() * 16); + return ZRoomCommand::GetRawDataSize() + ((int32_t)actors.size() * 16); } size_t SetActorList::GetActorListArraySize() @@ -155,7 +154,7 @@ RoomCommand SetActorList::GetRoomCommand() return RoomCommand::SetActorList; } -ActorSpawnEntry::ActorSpawnEntry(std::vector rawData, int rawDataIndex) +ActorSpawnEntry::ActorSpawnEntry(std::vector rawData, uint32_t rawDataIndex) { const uint8_t* data = rawData.data(); diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.h index d18d6ba06b..34a386ccb8 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorList.h @@ -14,28 +14,28 @@ public: int16_t rotZ; uint16_t initVar; - ActorSpawnEntry(std::vector rawData, int rawDataIndex); + ActorSpawnEntry(std::vector rawData, uint32_t rawDataIndex); }; class SetActorList : public ZRoomCommand { public: - SetActorList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetActorList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); ~SetActorList(); std::string GetSourceOutputCode(std::string prefix); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - virtual RoomCommand GetRoomCommand(); - virtual int32_t GetRawDataSize(); - virtual std::string GetCommandCName(); - virtual std::string GenerateExterns(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + virtual RoomCommand GetRoomCommand() override; + virtual size_t GetRawDataSize() override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; private: size_t GetActorListArraySize(); - int numActors; + int32_t numActors; std::vector actors; uint32_t segmentOffset; std::vector _rawData; - int _rawDataIndex; + uint32_t _rawDataIndex; }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp index 914d2d7da0..d52f423df9 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp @@ -6,7 +6,7 @@ using namespace std; SetAlternateHeaders::SetAlternateHeaders(ZRoom* nZRoom, std::vector rawData, - int rawDataIndex) + uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); @@ -18,12 +18,12 @@ SetAlternateHeaders::SetAlternateHeaders(ZRoom* nZRoom, std::vector raw _rawDataIndex = rawDataIndex; } -string SetAlternateHeaders::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetAlternateHeaders::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { string sourceOutput = ""; - int numHeaders = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 4; + int32_t numHeaders = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 4; - for (int i = 0; i < numHeaders; i++) + for (int32_t i = 0; i < numHeaders; i++) { int32_t address = BitConverter::ToInt32BE(_rawData, segmentOffset + (i * 4)); headers.push_back(address); @@ -39,14 +39,14 @@ string SetAlternateHeaders::GenerateSourceCodePass1(string roomName, int baseAdd string declaration = ""; - for (int i = 0; i < numHeaders; i++) + for (int32_t i = 0; i < numHeaders; i++) { - // sprintf(line, "\t0x%06X,\n", headers[i]); + // sprintf(line, " 0x%06X,\n", headers[i]); if (headers[i] == 0) - declaration += StringHelper::Sprintf("\t0,\n"); + declaration += StringHelper::Sprintf(" 0,\n"); else - declaration += StringHelper::Sprintf("\t(u32)&%sSet%04XCmd00,\n", roomName.c_str(), + declaration += StringHelper::Sprintf(" (u32)&%sSet%04XCmd00,\n", roomName.c_str(), headers[i] & 0x00FFFFFF); } @@ -58,7 +58,7 @@ string SetAlternateHeaders::GenerateSourceCodePass1(string roomName, int baseAdd return sourceOutput; } -int32_t SetAlternateHeaders::GetRawDataSize() +size_t SetAlternateHeaders::GetRawDataSize() { return ZRoomCommand::GetRawDataSize() + 0; } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.h index 15a054312e..b6aafdc7b6 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.h @@ -6,16 +6,16 @@ class SetAlternateHeaders : public ZRoomCommand { public: - SetAlternateHeaders(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetAlternateHeaders(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual int32_t GetRawDataSize(); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual size_t GetRawDataSize() override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: int32_t segmentOffset; std::vector headers; std::vector _rawData; - int _rawDataIndex; + int32_t _rawDataIndex; }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAnimatedTextureList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAnimatedTextureList.cpp new file mode 100644 index 0000000000..9668f08821 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAnimatedTextureList.cpp @@ -0,0 +1,432 @@ +#include "SetAnimatedTextureList.h" +#include "../../BitConverter.h" +#include "../../Globals.h" +#include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" + +using namespace std; + +SetAnimatedTextureList::SetAnimatedTextureList(ZRoom* nZRoom, std::vector rawData, + uint32_t rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) +{ + segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); + + { + string declaration = ""; + + int32_t currentPtr = segmentOffset; + + AnimatedTexture* lastTexture = nullptr; + + do + { + if (textures.size() > 0) + declaration += "\n"; + + lastTexture = new AnimatedTexture(rawData, currentPtr); + currentPtr += 8; + textures.push_back(lastTexture); + + string textureName = + (lastTexture->segmentOffset != 0) ? + StringHelper::Sprintf("&%sAnimatedTextureParams0x%06X", + zRoom->GetName().c_str(), lastTexture->segmentOffset) : + "NULL"; + + declaration += StringHelper::Sprintf(" { %i, %i, (u32)%s },", lastTexture->segment, + lastTexture->type, textureName.c_str()); + } while ((lastTexture->segment != 0) && (lastTexture->segment > -1)); + + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, + textures.size() * 8, "AnimatedTexture", + StringHelper::Sprintf("%sAnimatedTextureList0x%06X", zRoom->GetName().c_str(), + segmentOffset), + textures.size(), declaration); + } + + for (AnimatedTexture* texture : textures) + { + string declaration = ""; + size_t index = 0; + + switch (texture->type) + { + case 0: + case 1: + for (AnitmatedTextureParams* param : texture->params) + { + declaration += param->GenerateSourceCode(zRoom, texture->segmentOffset); + + if (index < texture->params.size() - 1) + declaration += "\n"; + + index++; + } + + zRoom->parent->AddDeclarationArray( + texture->segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, + texture->params.size() * 4, "ScrollingTextureParams", + StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), + texture->segmentOffset), + texture->params.size(), declaration); + break; + case 2: + case 3: + case 4: + zRoom->parent->AddDeclaration( + texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 16, + "FlashingTextureParams", + StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), + texture->segmentOffset), + texture->params[0]->GenerateSourceCode(zRoom, texture->segmentOffset)); + break; + case 5: + zRoom->parent->AddDeclaration( + texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 12, + "CyclingTextureParams", + StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(), + texture->segmentOffset), + texture->params[0]->GenerateSourceCode(zRoom, texture->segmentOffset)); + break; + case 6: + break; + } + } +} + +SetAnimatedTextureList::~SetAnimatedTextureList() +{ + for (AnimatedTexture* texture : textures) + delete texture; +} + +AnitmatedTextureParams::~AnitmatedTextureParams() +{ +} + +string SetAnimatedTextureList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) +{ + return StringHelper::Sprintf( + "%s 0, (u32)%sAnimatedTextureList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + zRoom->GetName().c_str(), segmentOffset); +} + +size_t SetAnimatedTextureList::GetRawDataSize() +{ + size_t paramsSize = 0; + for (AnimatedTexture* texture : textures) + { + for (AnitmatedTextureParams* param : texture->params) + { + paramsSize += param->GetParamsSize(); + } + } + + return ZRoomCommand::GetRawDataSize() + paramsSize; +} + +string SetAnimatedTextureList::GenerateExterns() +{ + return ""; +} + +string SetAnimatedTextureList::GetCommandCName() +{ + return "SCmdTextureAnimations"; +} + +RoomCommand SetAnimatedTextureList::GetRoomCommand() +{ + return RoomCommand::SetAnimatedTextureList; +} + +string SetAnimatedTextureList::GetSourceOutputCode(std::string prefix) +{ + return ""; +} + +AnimatedTexture::AnimatedTexture(std::vector rawData, uint32_t rawDataIndex) + : segment(rawData[rawDataIndex]), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), + segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))) +{ + switch (type) + { + case 0: + params.push_back(new ScrollingTexture(rawData, segmentOffset)); + break; + case 1: + params.push_back(new ScrollingTexture(rawData, segmentOffset)); + params.push_back(new ScrollingTexture(rawData, segmentOffset + 4)); + break; + case 2: + case 3: + case 4: + params.push_back(new FlashingTexture(rawData, segmentOffset, type)); + break; + case 5: + params.push_back(new CyclingTextureParams(rawData, segmentOffset)); + break; + case 6: // Some terminator when there are no animated textures? + break; + } +} + +AnimatedTexture::~AnimatedTexture() +{ + for (AnitmatedTextureParams* param : params) + delete param; +} + +ScrollingTexture::ScrollingTexture(std::vector rawData, uint32_t rawDataIndex) + : xStep(rawData[rawDataIndex + 0]), yStep(rawData[rawDataIndex + 1]), + width(rawData[rawDataIndex + 2]), height(rawData[rawDataIndex + 3]) +{ +} + +std::string ScrollingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) +{ + return StringHelper::Sprintf(" { %i, %i, 0x%02X, 0x%02X },", xStep, yStep, width, height); +} + +size_t ScrollingTexture::GetParamsSize() +{ + return 4; +} + +FlashingTexturePrimColor::FlashingTexturePrimColor(std::vector rawData, uint32_t rawDataIndex) + : r(rawData[rawDataIndex + 0]), g(rawData[rawDataIndex + 1]), b(rawData[rawDataIndex + 2]), + a(rawData[rawDataIndex + 3]), lodFrac(rawData[rawDataIndex + 4]) +{ +} + +FlashingTextureEnvColor::FlashingTextureEnvColor(std::vector rawData, uint32_t rawDataIndex) + : r(rawData[rawDataIndex + 0]), g(rawData[rawDataIndex + 1]), b(rawData[rawDataIndex + 2]), + a(rawData[rawDataIndex + 3]) +{ +} + +FlashingTexture::FlashingTexture(std::vector rawData, uint32_t rawDataIndex, int32_t type) + : cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), + numKeyFrames(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)), + primColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))), + envColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8))), + keyFrameSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 12))) +{ + uint16_t length = (type == 2) ? cycleLength : numKeyFrames; + + int32_t currentPtr = primColorSegmentOffset; + for (uint16_t i = 0; i < length; i++) + { + primColors.push_back(FlashingTexturePrimColor(rawData, currentPtr)); + currentPtr += 5; + } + + currentPtr = envColorSegmentOffset; + for (uint16_t i = 0; i < length; i++) + { + envColors.push_back(FlashingTextureEnvColor(rawData, currentPtr)); + currentPtr += 4; + } + + currentPtr = keyFrameSegmentOffset; + for (uint16_t i = 0; i < length; i++) + { + keyFrames.push_back(BitConverter::ToUInt16BE(rawData, currentPtr)); + currentPtr += 2; + } +} + +std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) +{ + if (primColorSegmentOffset != 0) + { + string declaration = ""; + size_t index = 0; + + for (FlashingTexturePrimColor& color : primColors) + { + declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },", + color.r, color.g, color.b, color.a, color.lodFrac); + + if (index < primColors.size() - 1) + declaration += "\n"; + + index++; + } + + zRoom->parent->AddDeclarationArray( + primColorSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, + primColors.size() * 5, "FlashingTexturePrimColor", + StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(), + primColorSegmentOffset), + primColors.size(), declaration); + } + + if (envColorSegmentOffset != 0) + { + string declaration = ""; + size_t index = 0; + + for (FlashingTextureEnvColor& color : envColors) + { + declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X },", color.r, + color.g, color.b, color.a); + + if (index < envColors.size() - 1) + declaration += "\n"; + + index++; + } + + zRoom->parent->AddDeclarationArray( + envColorSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, + envColors.size() * 4, "Color_RGBA8", + StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(), + envColorSegmentOffset), + envColors.size(), declaration); + } + + if (keyFrameSegmentOffset != 0) + { + string declaration = ""; + size_t index = 0; + + for (uint16_t keyFrame : keyFrames) + { + declaration += StringHelper::Sprintf(" 0x%02X,", keyFrame); + + if (index < keyFrames.size() - 1) + declaration += "\n"; + + index++; + } + + zRoom->parent->AddDeclarationArray(keyFrameSegmentOffset, DeclarationAlignment::Align4, + DeclarationPadding::None, keyFrames.size() * 2, "u16", + StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X", + zRoom->GetName().c_str(), + keyFrameSegmentOffset), + keyFrames.size(), declaration); + } + + return StringHelper::Sprintf( + "%i, %i, (u32)%s, (u32)%s, (u32)%s", cycleLength, numKeyFrames, + (primColorSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(), + primColorSegmentOffset) + .c_str() : + "NULL", + (envColorSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(), + envColorSegmentOffset) + .c_str() : + "NULL", + (keyFrameSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X", zRoom->GetName().c_str(), + keyFrameSegmentOffset) + .c_str() : + "NULL"); +} + +size_t FlashingTexture::GetParamsSize() +{ + return 16; +} + +CyclingTextureParams::CyclingTextureParams(std::vector rawData, uint32_t rawDataIndex) + : cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), + textureSegmentOffsetsSegmentOffset( + GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))), + textureIndicesSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8))) +{ + int32_t currentPtr = textureIndicesSegmentOffset; + int32_t maxIndex = 0; + + for (uint16_t i = 0; i < cycleLength; i++) + { + int32_t newIndex = rawData[currentPtr]; + textureIndices.push_back(newIndex); + currentPtr++; + if (newIndex > maxIndex) + maxIndex = newIndex; + } + + currentPtr = textureSegmentOffsetsSegmentOffset; + for (int32_t i = 0; i < maxIndex + 1; i++) + { + textureSegmentOffsets.push_back(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr))); + currentPtr += 4; + } +} + +std::string CyclingTextureParams::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) +{ + if (textureSegmentOffsetsSegmentOffset != 0) + { + string declaration = ""; + size_t index = 0; + + for (uint32_t offset : textureSegmentOffsets) + { + declaration += + StringHelper::Sprintf(" %sTex_%06X,", zRoom->GetName().c_str(), offset); + + if (index < textureSegmentOffsets.size() - 1) + declaration += "\n"; + + index++; + } + + zRoom->parent->AddDeclarationArray( + textureSegmentOffsetsSegmentOffset, DeclarationAlignment::Align4, + DeclarationPadding::None, textureSegmentOffsets.size() * 4, "u64*", + StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(), + textureSegmentOffsetsSegmentOffset), + textureSegmentOffsets.size(), declaration); + } + + if (textureIndicesSegmentOffset != 0) + { + string declaration = ""; + size_t index = 0; + + for (uint8_t textureIndex : textureIndices) + { + declaration += StringHelper::Sprintf(" 0x%02X,", textureIndex); + + if (index < textureIndices.size() - 1) + declaration += "\n"; + + index++; + } + + zRoom->parent->AddDeclarationArray( + textureIndicesSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, + textureIndices.size(), "u8", + StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(), + textureIndicesSegmentOffset), + textureIndices.size(), declaration); + } + + return StringHelper::Sprintf( + "%i, (u32)%s, (u32)%s", cycleLength, + (textureSegmentOffsetsSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(), + textureSegmentOffsetsSegmentOffset) + .c_str() : + "NULL", + (textureIndicesSegmentOffset != 0) ? + StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(), + textureIndicesSegmentOffset) + .c_str() : + "NULL"); +} + +size_t CyclingTextureParams::GetParamsSize() +{ + return 12; +} diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAnimatedTextureList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAnimatedTextureList.h new file mode 100644 index 0000000000..035ba998ce --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAnimatedTextureList.h @@ -0,0 +1,113 @@ +#pragma once + +#include "../ZRoomCommand.h" + +// TODO move into header and add all types +class AnitmatedTextureParams +{ +public: + virtual ~AnitmatedTextureParams(); + virtual std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) = 0; + virtual size_t GetParamsSize() = 0; +}; + +class ScrollingTexture : public AnitmatedTextureParams +{ +public: + ScrollingTexture(std::vector rawData, uint32_t rawDataIndex); + std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override; + size_t GetParamsSize() override; + + int8_t xStep; + int8_t yStep; + uint8_t width; + uint8_t height; +}; + +class FlashingTexturePrimColor +{ +public: + FlashingTexturePrimColor(std::vector rawData, uint32_t rawDataIndex); + + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; + uint8_t lodFrac; +}; + +class FlashingTextureEnvColor +{ +public: + FlashingTextureEnvColor(std::vector rawData, uint32_t rawDataIndex); + + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; +}; + +class FlashingTexture : public AnitmatedTextureParams +{ +public: + FlashingTexture(std::vector rawData, uint32_t rawDataIndex, int32_t type); + std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override; + size_t GetParamsSize() override; + + uint16_t cycleLength; + uint16_t numKeyFrames; + uint32_t primColorSegmentOffset; + uint32_t envColorSegmentOffset; + uint32_t keyFrameSegmentOffset; + + std::vector primColors; + std::vector envColors; + std::vector keyFrames; +}; + +class CyclingTextureParams : public AnitmatedTextureParams +{ +public: + CyclingTextureParams(std::vector rawData, uint32_t rawDataIndex); + std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override; + size_t GetParamsSize() override; + + uint16_t cycleLength; + uint32_t textureSegmentOffsetsSegmentOffset; + uint32_t textureIndicesSegmentOffset; + + std::vector textureSegmentOffsets; + std::vector textureIndices; +}; + +class AnimatedTexture +{ +public: + AnimatedTexture(std::vector rawData, uint32_t rawDataIndex); + virtual ~AnimatedTexture(); + + int8_t segment; + int16_t type; + uint32_t segmentOffset; + std::vector params; +}; + +class SetAnimatedTextureList : public ZRoomCommand +{ +public: + SetAnimatedTextureList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); + ~SetAnimatedTextureList(); + + std::string GetSourceOutputCode(std::string prefix); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual RoomCommand GetRoomCommand() override; + virtual size_t GetRawDataSize() override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; + +private: + uint32_t segmentOffset; + std::vector textures; + std::vector _rawData; + int32_t _rawDataIndex; +}; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp index 57f0dd71e8..b6894a3695 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp @@ -4,14 +4,14 @@ using namespace std; -SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { cameraMovement = rawData[rawDataIndex + 0x01]; mapHighlight = BitConverter::ToInt32BE(rawData, rawDataIndex + 4); } -string SetCameraSettings::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetCameraSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.h index 3e197e7fa6..894c9a90d1 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.h @@ -5,11 +5,11 @@ class SetCameraSettings : public ZRoomCommand { public: - SetCameraSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetCameraSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: uint8_t cameraMovement; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp index 90b0c595ff..79d2c505d0 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.cpp @@ -7,17 +7,19 @@ using namespace std; SetCollisionHeader::SetCollisionHeader(ZRoom* nZRoom, std::vector rawData, - int rawDataIndex) + uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); - collisionHeader = ZCollisionHeader( - nZRoom->parent, - StringHelper::Sprintf("%sCollisionHeader0x%06X", nZRoom->GetName().c_str(), segmentOffset), - rawData, segmentOffset); + collisionHeader = new ZCollisionHeader(nZRoom->parent); + collisionHeader->SetRawData(rawData); + collisionHeader->SetRawDataIndex(segmentOffset); + collisionHeader->SetName( + StringHelper::Sprintf("%sCollisionHeader0x%06X", nZRoom->GetName().c_str(), segmentOffset)); + collisionHeader->ParseRawData(); } -string SetCollisionHeader::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetCollisionHeader::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x00, (u32)&%sCollisionHeader0x%06X", @@ -25,7 +27,7 @@ string SetCollisionHeader::GenerateSourceCodePass1(string roomName, int baseAddr zRoom->GetName().c_str(), segmentOffset); } -string SetCollisionHeader::GenerateSourceCodePass2(string roomName, int baseAddress) +string SetCollisionHeader::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) { return ""; } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.h index f2b12644af..d1ada1d26b 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCollisionHeader.h @@ -6,15 +6,15 @@ class SetCollisionHeader : public ZRoomCommand { public: - SetCollisionHeader(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetCollisionHeader(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual std::string GenerateExterns(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; + virtual RoomCommand GetRoomCommand() override; private: - ZCollisionHeader collisionHeader; + ZCollisionHeader* collisionHeader; uint32_t segmentOffset; }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.cpp new file mode 100644 index 0000000000..b7bed8aa75 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.cpp @@ -0,0 +1,153 @@ +#include "SetCsCamera.h" +#include "../../BitConverter.h" +#include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" + +using namespace std; + +SetCsCamera::SetCsCamera(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) +{ + _rawData = rawData; + _rawDataIndex = rawDataIndex; + + segmentOffset = 0; + + int32_t numCameras = rawData[rawDataIndex + 1]; + segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); + + uint32_t currentPtr = segmentOffset; + int32_t numPoints = 0; + + for (int32_t i = 0; i < numCameras; i++) + { + CsCameraEntry* entry = new CsCameraEntry(_rawData, currentPtr); + + cameras.push_back(entry); + numPoints += entry->numPoints; + + currentPtr += 8; + } + + if (numPoints > 0) + { + uint32_t currentPtr = cameras[0]->segmentOffset; + + for (int32_t i = 0; i < numPoints; i++) + { + int16_t x = BitConverter::ToInt16BE(rawData, currentPtr + 0); + int16_t y = BitConverter::ToInt16BE(rawData, currentPtr + 2); + int16_t z = BitConverter::ToInt16BE(rawData, currentPtr + 4); + Vec3s p = {x, y, z}; + points.push_back(p); + currentPtr += 6; + } + } + + if (segmentOffset != 0) + zRoom->parent->AddDeclarationPlaceholder(segmentOffset); +} + +SetCsCamera::~SetCsCamera() +{ + for (CsCameraEntry* entry : cameras) + delete entry; +} + +string SetCsCamera::GetSourceOutputCode(std::string prefix) +{ + return ""; +} + +string SetCsCamera::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) +{ + return ""; +} + +string SetCsCamera::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) +{ + string sourceOutput = ""; + + sourceOutput += + StringHelper::Sprintf("%s %i, (u32)&%sCsCameraList0x%06X };", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + cameras.size(), roomName.c_str(), segmentOffset); + + if (points.size() > 0) + { + string declaration = ""; + size_t index = 0; + for (Vec3s point : points) + { + declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", point.x, point.y, + point.z, cameras[0]->segmentOffset + (index * 6)); + + if (index < points.size() - 1) + declaration += "\n"; + + index++; + } + + zRoom->parent->AddDeclarationArray(cameras[0]->segmentOffset, DeclarationAlignment::None, + DeclarationPadding::None, points.size() * 6, "Vec3s", + StringHelper::Sprintf("%sCsCameraPoints0x%06X", + roomName.c_str(), + cameras[0]->segmentOffset), + points.size(), declaration); + } + + { + string declaration = ""; + + size_t index = 0; + size_t pointsIndex = 0; + for (CsCameraEntry* entry : cameras) + { + declaration += StringHelper::Sprintf(" %i, %i, (u32)&%sCsCameraPoints0x%06X[%i],", + entry->type, entry->numPoints, roomName.c_str(), + cameras[0]->segmentOffset, pointsIndex); + + if (index < cameras.size() - 1) + declaration += "\n"; + + index++; + pointsIndex += entry->numPoints; + } + + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::Pad16, + cameras.size() * 8, "CsCameraEntry", + StringHelper::Sprintf("%sCsCameraList0x%06X", roomName.c_str(), segmentOffset), + cameras.size(), declaration); + } + + return sourceOutput; +} + +size_t SetCsCamera::GetRawDataSize() +{ + return ZRoomCommand::GetRawDataSize() + (cameras.size() * 8) + (points.size() * 6); +} + +string SetCsCamera::GenerateExterns() +{ + return ""; +} + +string SetCsCamera::GetCommandCName() +{ + return "SCmdCsCameraList"; +} + +RoomCommand SetCsCamera::GetRoomCommand() +{ + return RoomCommand::SetCsCamera; +} + +CsCameraEntry::CsCameraEntry(std::vector rawData, uint32_t rawDataIndex) + : baseOffset(rawDataIndex), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), + numPoints(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), + segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))) +{ +} diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.h new file mode 100644 index 0000000000..674309ae54 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.h @@ -0,0 +1,37 @@ +#pragma once + +#include "../../Vec3s.h" +#include "../ZRoomCommand.h" + +class CsCameraEntry +{ +public: + CsCameraEntry(std::vector rawData, uint32_t rawDataIndex); + + int32_t baseOffset; + int32_t type; + int32_t numPoints; + uint32_t segmentOffset; +}; + +class SetCsCamera : public ZRoomCommand +{ +public: + SetCsCamera(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); + ~SetCsCamera(); + + std::string GetSourceOutputCode(std::string prefix); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + virtual RoomCommand GetRoomCommand() override; + virtual size_t GetRawDataSize() override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; + +private: + uint32_t segmentOffset; + std::vector cameras; + std::vector points; + std::vector _rawData; + int32_t _rawDataIndex; +}; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp index a253270f17..b342e86cd1 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp @@ -1,69 +1,118 @@ #include "SetCutscenes.h" #include "../../BitConverter.h" +#include "../../Globals.h" #include "../../StringHelper.h" #include "../../ZFile.h" #include "../ZRoom.h" using namespace std; -SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { - segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; + numCutscenes = rawData[rawDataIndex + 1]; + segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); string output = ""; - cutscene = new ZCutscene(rawData, segmentOffset, 9999); - - output += cutscene->GetSourceOutputCode(zRoom->GetName()); - - if (segmentOffset != 0) + if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97) { - Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); + ZCutscene* cutscene = new ZCutscene(nZRoom->parent); + cutscene->ExtractFromFile(rawData, segmentOffset, ""); + + auto decl = nZRoom->parent->GetDeclaration(segmentOffset); if (decl == nullptr) { - zRoom->parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, - cutscene->GetRawDataSize(), "s32", - StringHelper::Sprintf("%sCutsceneData0x%06X", zRoom->GetName().c_str(), - segmentOffset), - 0, output); + cutscene->DeclareVar(zRoom->GetName().c_str(), ""); } - else if (decl->text == "") + + cutscenes.push_back(cutscene); + } + else + { + int32_t currentPtr = segmentOffset; + string declaration = ""; + + for (uint8_t i = 0; i < numCutscenes; i++) { - decl->text = output; + CutsceneEntry* entry = new CutsceneEntry(rawData, currentPtr); + cutsceneEntries.push_back(entry); + currentPtr += 8; + + declaration += StringHelper::Sprintf( + " { %sCutsceneData0x%06X, 0x%04X, 0x%02X, 0x%02X },", zRoom->GetName().c_str(), + entry->segmentOffset, entry->exit, entry->entrance, entry->flag); + + if (i < numCutscenes - 1) + declaration += "\n"; + + ZCutsceneMM* cutscene = new ZCutsceneMM(nZRoom->parent); + cutscene->ExtractFromXML( + nullptr, rawData, entry->segmentOffset, + ""); // TODO: Use ExtractFromFile() here when that gets implemented + cutscenes.push_back(cutscene); + } + + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, + cutsceneEntries.size() * 8, "CutsceneEntry", + StringHelper::Sprintf("%sCutsceneEntryList0x%06X", zRoom->GetName().c_str(), + segmentOffset), + cutsceneEntries.size(), declaration); + } + + for (ZCutsceneBase* cutscene : cutscenes) + { + if (cutscene->getSegmentOffset() != 0) + { + Declaration* decl = zRoom->parent->GetDeclaration(cutscene->getSegmentOffset()); + if (decl == nullptr) + { + cutscene->GetSourceOutputCode(zRoom->GetName()); + } + else if (decl->text == "") + { + decl->text = cutscene->GetBodySourceCode(); + } } } } SetCutscenes::~SetCutscenes() { - if (cutscene != nullptr) - { + for (ZCutsceneBase* cutscene : cutscenes) delete cutscene; - cutscene = nullptr; - } + + for (CutsceneEntry* entry : cutsceneEntries) + delete entry; } -string SetCutscenes::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetCutscenes::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { string pass1 = ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress); Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); if (decl != nullptr) { - return StringHelper::Sprintf("%s 0, (u32)%s", pass1.c_str(), decl->varName.c_str()); + return StringHelper::Sprintf("%s %i, (u32)%s", pass1.c_str(), numCutscenes, + decl->varName.c_str()); } - return StringHelper::Sprintf("%s 0, (u32)%sCutsceneData0x%06X", pass1.c_str(), + return StringHelper::Sprintf("%s %i, (u32)%sCutsceneData0x%06X", pass1.c_str(), numCutscenes, zRoom->GetName().c_str(), segmentOffset); } -int32_t SetCutscenes::GetRawDataSize() +size_t SetCutscenes::GetRawDataSize() { return ZRoomCommand::GetRawDataSize() + (0); } string SetCutscenes::GenerateExterns() { + if (Globals::Instance->game == ZGame::MM_RETAIL) + { + return StringHelper::Sprintf("extern CutsceneEntry %sCutsceneEntryList0x%06X[];\n", + zRoom->GetName().c_str(), segmentOffset); + } + Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); if (decl != nullptr && decl->varName != "") { @@ -87,3 +136,10 @@ string SetCutscenes::GetSourceOutputCode(std::string prefix) { return ""; } + +CutsceneEntry::CutsceneEntry(std::vector rawData, uint32_t rawDataIndex) + : segmentOffset(BitConverter::ToInt32BE(rawData, rawDataIndex + 0) & 0x00FFFFFF), + exit(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), entrance(rawData[rawDataIndex + 6]), + flag(rawData[rawDataIndex + 7]) +{ +} diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h index 5e7e6985a3..6930636d28 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h @@ -1,24 +1,38 @@ #pragma once #include "../../ZCutscene.h" +#include "../../ZCutsceneMM.h" #include "../ZRoomCommand.h" +class CutsceneEntry +{ +public: + CutsceneEntry(std::vector rawData, uint32_t rawDataIndex); + + uint32_t segmentOffset; + uint16_t exit; + uint8_t entrance; + uint8_t flag; +}; + class SetCutscenes : public ZRoomCommand { public: - SetCutscenes(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetCutscenes(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); ~SetCutscenes(); std::string GetSourceOutputCode(std::string prefix); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual RoomCommand GetRoomCommand(); - virtual int32_t GetRawDataSize(); - virtual std::string GetCommandCName(); - virtual std::string GenerateExterns(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual RoomCommand GetRoomCommand() override; + virtual size_t GetRawDataSize() override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; private: - ZCutscene* cutscene; + std::vector cutscenes; + std::vector cutsceneEntries; // (MM Only) uint32_t segmentOffset; + uint8_t numCutscenes; // (MM Only) std::vector _rawData; - int _rawDataIndex; + int32_t _rawDataIndex; }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.cpp index 40a11cfd3c..24f383e108 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.cpp @@ -3,13 +3,13 @@ using namespace std; -SetEchoSettings::SetEchoSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetEchoSettings::SetEchoSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { echo = rawData[rawDataIndex + 0x07]; } -string SetEchoSettings::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetEchoSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0, { 0 }, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.h index 2f952addd8..f3481025b7 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEchoSettings.h @@ -5,11 +5,11 @@ class SetEchoSettings : public ZRoomCommand { public: - SetEchoSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetEchoSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: uint8_t echo; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp index 6e81552450..e4b37912d6 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp @@ -7,7 +7,7 @@ using namespace std; -SetEntranceList::SetEntranceList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetEntranceList::SetEntranceList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; @@ -23,7 +23,7 @@ SetEntranceList::~SetEntranceList() delete entry; } -string SetEntranceList::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetEntranceList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { string sourceOutput = StringHelper::Sprintf("%s 0x00, (u32)&%sEntranceList0x%06X", @@ -32,10 +32,10 @@ string SetEntranceList::GenerateSourceCodePass1(string roomName, int baseAddress // Parse Entrances and Generate Declaration zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined - int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; + int32_t numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; uint32_t currentPtr = segmentOffset; - for (int i = 0; i < numEntrances; i++) + for (int32_t i = 0; i < numEntrances; i++) { EntranceEntry* entry = new EntranceEntry(_rawData, currentPtr); entrances.push_back(entry); @@ -45,12 +45,12 @@ string SetEntranceList::GenerateSourceCodePass1(string roomName, int baseAddress string declaration = ""; - int index = 0; + int32_t index = 0; for (EntranceEntry* entry : entrances) { declaration += - StringHelper::Sprintf("\t{ 0x%02X, 0x%02X }, //0x%06X \n", entry->startPositionIndex, + StringHelper::Sprintf(" { 0x%02X, 0x%02X }, //0x%06X \n", entry->startPositionIndex, entry->roomToLoad, segmentOffset + (index * 2)); index++; } @@ -79,7 +79,7 @@ RoomCommand SetEntranceList::GetRoomCommand() return RoomCommand::SetEntranceList; } -EntranceEntry::EntranceEntry(std::vector rawData, int rawDataIndex) +EntranceEntry::EntranceEntry(std::vector rawData, uint32_t rawDataIndex) { startPositionIndex = rawData[rawDataIndex + 0]; roomToLoad = rawData[rawDataIndex + 1]; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.h index 87ad9059b8..b3c61ca8c8 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.h @@ -8,19 +8,19 @@ public: uint8_t startPositionIndex; uint8_t roomToLoad; - EntranceEntry(std::vector rawData, int rawDataIndex); + EntranceEntry(std::vector rawData, uint32_t rawDataIndex); }; class SetEntranceList : public ZRoomCommand { public: - SetEntranceList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetEntranceList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); ~SetEntranceList(); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateExterns(); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateExterns() override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: std::vector entrances; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp index 23b89e2290..89512dd896 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp @@ -6,7 +6,7 @@ using namespace std; -SetExitList::SetExitList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetExitList::SetExitList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); @@ -19,7 +19,7 @@ SetExitList::SetExitList(ZRoom* nZRoom, std::vector rawData, int rawDat _rawDataIndex = rawDataIndex; } -string SetExitList::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetExitList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { string sourceOutput = StringHelper::Sprintf("%s 0x00, (u32)&%sExitList0x%06X", @@ -28,10 +28,10 @@ string SetExitList::GenerateSourceCodePass1(string roomName, int baseAddress) // Parse Entrances and Generate Declaration zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined - int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; + int32_t numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; uint32_t currentPtr = segmentOffset; - for (int i = 0; i < numEntrances; i++) + for (int32_t i = 0; i < numEntrances; i++) { uint16_t exit = BitConverter::ToInt16BE(_rawData, currentPtr); exits.push_back(exit); @@ -42,7 +42,7 @@ string SetExitList::GenerateSourceCodePass1(string roomName, int baseAddress) string declaration = ""; for (uint16_t exit : exits) - declaration += StringHelper::Sprintf("\t0x%04X,\n", exit); + declaration += StringHelper::Sprintf(" 0x%04X,\n", exit); ; zRoom->parent->AddDeclarationArray( diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.h index 2624dd27cb..ea9277363c 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.h @@ -5,12 +5,12 @@ class SetExitList : public ZRoomCommand { public: - SetExitList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetExitList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateExterns(); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateExterns() override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: std::vector exits; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.cpp index 2018c2e5a6..5966c38207 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.cpp @@ -4,7 +4,7 @@ using namespace std; -SetLightList::SetLightList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetLightList::SetLightList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { this->ptrRoom = nZRoom; @@ -15,23 +15,28 @@ SetLightList::SetLightList(ZRoom* nZRoom, std::vector rawData, int rawD // this->ptrRoom->GetName().c_str(), this->segment); string declarations = ""; - for (int i = 0; i < this->numLights; i++) + int32_t currentPtr = this->segment; + for (int32_t i = 0; i < this->numLights; i++) { - uint8_t type = rawData[this->segment + ((0xE * i) + 0)]; - std::vector params; + uint8_t type = rawData[currentPtr + 0]; + int16_t x = BitConverter::ToInt16BE(rawData, currentPtr + 2); + int16_t y = BitConverter::ToInt16BE(rawData, currentPtr + 4); + int16_t z = BitConverter::ToInt16BE(rawData, currentPtr + 6); + uint8_t r = rawData[currentPtr + 8]; + uint8_t g = rawData[currentPtr + 9]; + uint8_t b = rawData[currentPtr + 10]; + uint8_t drawGlow = rawData[currentPtr + 11]; + int16_t radius = BitConverter::ToInt16BE(rawData, currentPtr + 12); - for (int y = 0; y < 6; y++) - { - params.push_back( - BitConverter::ToInt16BE(rawData, this->segment + ((0xE * i) + 2 + (y * 2)))); - } + currentPtr += 14; declarations += StringHelper::Sprintf( - "\t{ 0x%02X, { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X } },\n", type, params[0], - params[1], params[2], params[3], params[4], params[5]); - } + " { 0x%02X, { %i, %i, %i, { 0x%02X, 0x%02X, 0x%02X }, 0x%02X, 0x%04X } },", type, x, + y, z, r, g, b, drawGlow, radius); - declarations += "};\n"; + if (i < this->numLights - 1) + declarations += "\n"; + } this->ptrRoom->parent->AddDeclarationArray( this->segment, DeclarationAlignment::None, this->numLights * 0xE, "LightInfo", @@ -39,10 +44,10 @@ SetLightList::SetLightList(ZRoom* nZRoom, std::vector rawData, int rawD this->numLights, declarations); } -string SetLightList::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetLightList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( - "%s %i, &%sLightInfo0x%06X};", + "%s %i, &%sLightInfo0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), this->numLights, this->ptrRoom->GetName().c_str(), this->segment); } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.h index b3383aa5ce..13d5e8cecf 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightList.h @@ -9,15 +9,14 @@ class SetLightList : public ZRoomCommand { public: - SetLightList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetLightList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); - virtual std::string GenerateExterns(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; + virtual std::string GenerateExterns() override; private: - uint8_t code; uint8_t numLights; uint32_t segment; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp index 8436feeb53..de9448dac0 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp @@ -7,25 +7,25 @@ using namespace std; SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector rawData, - int rawDataIndex) + uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { uint8_t numLights = rawData[rawDataIndex + 1]; segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); - for (int i = 0; i < numLights; i++) + for (int32_t i = 0; i < numLights; i++) settings.push_back(new LightingSettings(rawData, segmentOffset + (i * 22))); if (numLights > 0) { string declaration = ""; - for (int i = 0; i < numLights; i++) + for (int32_t i = 0; i < numLights; i++) { declaration += StringHelper::Sprintf( "\t{ 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, " - "0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%04X, " - "0x%04X }, // 0x%06X \n", + "0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%04X, " + "0x%04X }, // 0x%06X", settings[i]->ambientClrR, settings[i]->ambientClrG, settings[i]->ambientClrB, settings[i]->diffuseClrA_R, settings[i]->diffuseClrA_G, settings[i]->diffuseClrA_B, settings[i]->diffuseDirA_X, settings[i]->diffuseDirA_Y, settings[i]->diffuseDirA_Z, @@ -33,12 +33,14 @@ SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector raw settings[i]->diffuseDirB_X, settings[i]->diffuseDirB_Y, settings[i]->diffuseDirB_Z, settings[i]->fogClrR, settings[i]->fogClrG, settings[i]->fogClrB, settings[i]->unk, settings[i]->drawDistance, segmentOffset + (i * 22)); + if (i + 1 < numLights) + declaration += "\n"; } zRoom->parent->AddDeclarationArray( segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, numLights * 22, "LightSettings", - StringHelper::Sprintf("%sLightSettings0x%06X", zRoom->GetName().c_str(), segmentOffset), + StringHelper::Sprintf("%sLightSettings_%06X", zRoom->GetName().c_str(), segmentOffset), numLights, declaration); } } @@ -49,15 +51,15 @@ SetLightingSettings::~SetLightingSettings() delete setting; } -string SetLightingSettings::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetLightingSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( - "%s %i, (u32)&%sLightSettings0x%06X", + "%s %i, (u32)&%sLightSettings_%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), settings.size(), zRoom->GetName().c_str(), segmentOffset); } -string SetLightingSettings::GenerateSourceCodePass2(string roomName, int baseAddress) +string SetLightingSettings::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) { return ""; } @@ -69,7 +71,7 @@ string SetLightingSettings::GetCommandCName() string SetLightingSettings::GenerateExterns() { - return StringHelper::Sprintf("extern LightSettings %sLightSettings0x%06X[];\n", + return StringHelper::Sprintf("extern LightSettings %sLightSettings_%06X[];\n", zRoom->GetName().c_str(), segmentOffset); } @@ -78,7 +80,7 @@ RoomCommand SetLightingSettings::GetRoomCommand() return RoomCommand::SetLightingSettings; } -LightingSettings::LightingSettings(vector rawData, int rawDataIndex) +LightingSettings::LightingSettings(vector rawData, uint32_t rawDataIndex) { const uint8_t* data = rawData.data(); diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.h index 4ec1770fc5..889a34395d 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.h @@ -14,20 +14,20 @@ public: uint16_t unk; uint16_t drawDistance; - LightingSettings(std::vector rawData, int rawDataIndex); + LightingSettings(std::vector rawData, uint32_t rawDataIndex); }; class SetLightingSettings : public ZRoomCommand { public: - SetLightingSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetLightingSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); ~SetLightingSettings(); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual std::string GenerateExterns(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; + virtual RoomCommand GetRoomCommand() override; private: uint32_t segmentOffset; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp index 4884e3e50c..62e1b1bc73 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp @@ -5,210 +5,111 @@ #include "../../StringHelper.h" #include "../../ZFile.h" #include "../ZRoom.h" +#include "ZBackground.h" using namespace std; -SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, - int segAddressOffset) +SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex, + int32_t segAddressOffset) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { data = rawData[rawDataIndex + 1]; segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); string declaration = ""; - int8_t meshHeaderType = rawData[segmentOffset + 0]; + meshHeaderType = rawData[segmentOffset + 0]; if (meshHeaderType == 0) { - MeshHeader0* meshHeader0 = new MeshHeader0(); - meshHeader0->headerType = 0; - meshHeader0->entries = vector(); - - meshHeader0->dListStart = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 4)); - meshHeader0->dListEnd = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 8)); + uint32_t dListStart = Seg2Filespace(BitConverter::ToInt32BE(rawData, segmentOffset + 4), + zRoom->parent->baseAddress); + uint32_t dListEnd = Seg2Filespace(BitConverter::ToInt32BE(rawData, segmentOffset + 8), + zRoom->parent->baseAddress); int8_t numEntries = rawData[segmentOffset + 1]; - uint32_t currentPtr = meshHeader0->dListStart; + uint32_t currentPtr = dListStart; // Hack for Syotes - for (int i = 0; i < abs(segAddressOffset); i++) + for (int32_t i = 0; i < abs(segAddressOffset); i++) { rawData.erase(rawData.begin()); segmentOffset--; } - for (int i = 0; i < numEntries; i++) + if (numEntries > 0) { - MeshEntry0* entry = new MeshEntry0(); - entry->opaqueDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 0)); - entry->translucentDListAddr = - GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 4)); + std::string polyGfxBody = ""; + std::string polyGfxType = ""; + int32_t polyGfxSize = 0; - if (entry->opaqueDListAddr != 0) + for (int32_t i = 0; i < numEntries; i++) { - entry->opaqueDList = new ZDisplayList( - rawData, entry->opaqueDListAddr, - ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr, - Globals::Instance->game == ZGame::OOT_SW97 ? - DListType::F3DEX : - DListType::F3DZEX)); - entry->opaqueDList->scene = zRoom->scene; - entry->opaqueDList->parent = zRoom->parent; - GenDListDeclarations(rawData, entry->opaqueDList); + PolygonDlist polyGfxList(zRoom->GetName(), rawData, currentPtr, zRoom->parent, + zRoom); + if (polyGfxList.opaDList != nullptr) + { + GenDListDeclarations(rawData, polyGfxList.opaDList); + } + if (polyGfxList.xluDList != nullptr) + { + GenDListDeclarations(rawData, polyGfxList.xluDList); + } + polyGfxBody += polyGfxList.GetBodySourceCode(true); + polyGfxType = polyGfxList.GetSourceTypeName(); + polyGfxSize = polyGfxList.GetRawDataSize(); + + currentPtr += polyGfxList.GetRawDataSize(); } - if (entry->translucentDListAddr != 0) - { - entry->translucentDList = new ZDisplayList( - rawData, entry->translucentDListAddr, - ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr, - Globals::Instance->game == ZGame::OOT_SW97 ? - DListType::F3DEX : - DListType::F3DZEX)); - entry->translucentDList->scene = zRoom->scene; - entry->translucentDList->parent = zRoom->parent; - GenDListDeclarations(rawData, entry->translucentDList); - } - - meshHeader0->entries.push_back(entry); - - currentPtr += 8; + zRoom->parent->AddDeclarationArray( + dListStart, DeclarationAlignment::Align4, numEntries * polyGfxSize, polyGfxType, + StringHelper::Sprintf("%s%s0x%06X", zRoom->GetName().c_str(), polyGfxType.c_str(), + dListStart), + numEntries, polyGfxBody); } - declaration += StringHelper::Sprintf("{ 0 }, 0x%02X, ", meshHeader0->entries.size()); + declaration = "\n "; + declaration += StringHelper::Sprintf("{ 0 }, 0x%02X, ", numEntries); + declaration += "\n "; - if (meshHeader0->dListStart != 0) - declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ", - zRoom->GetName().c_str(), meshHeader0->dListStart); - else - declaration += "0, "; + std::string entriesStr = "NULL"; - if (meshHeader0->dListEnd != 0) - declaration += StringHelper::Sprintf( - "(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)", - zRoom->GetName().c_str(), meshHeader0->dListStart, zRoom->GetName().c_str(), - meshHeader0->dListStart); + if (dListStart != 0) + { + entriesStr = zRoom->parent->GetDeclaration(dListStart)->varName; + } + declaration += StringHelper::Sprintf("%s, ", entriesStr.c_str()); + declaration += "\n "; + + if (dListEnd != 0) + declaration += StringHelper::Sprintf("%s + ARRAY_COUNT(%s), ", entriesStr.c_str(), + entriesStr.c_str()); else - declaration += "0"; + declaration += "NULL, "; + declaration += "\n"; zRoom->parent->AddDeclaration( segmentOffset, DeclarationAlignment::Align16, 12, "MeshHeader0", StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), declaration); - declaration = ""; - - for (size_t i = 0; i < meshHeader0->entries.size(); i++) - { - if (meshHeader0->entries[i]->opaqueDListAddr != 0) - declaration += - StringHelper::Sprintf("\t{ (u32)%sDL_%06X, ", zRoom->GetName().c_str(), - meshHeader0->entries[i]->opaqueDListAddr); - else - declaration += "\t{ 0, "; - - if (meshHeader0->entries[i]->translucentDListAddr != 0) - declaration += - StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(), - meshHeader0->entries[i]->translucentDListAddr); - else - declaration += "0 },\n"; - } - - zRoom->parent->AddDeclarationArray( - meshHeader0->dListStart, DeclarationAlignment::None, DeclarationPadding::None, - (meshHeader0->entries.size() * 8) + 0, "MeshEntry0", - StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(), - meshHeader0->dListStart), - meshHeader0->entries.size(), declaration); - - zRoom->parent->AddDeclaration(meshHeader0->dListStart + (meshHeader0->entries.size() * 8) + - 0, - DeclarationAlignment::None, DeclarationPadding::Pad16, 4, - "static s32", "terminatorMaybe", " 0x01000000 "); - - meshHeader = meshHeader0; + zRoom->parent->AddDeclaration(dListStart + (numEntries * 8), DeclarationAlignment::None, + DeclarationPadding::Pad16, 4, "static s32", "terminatorMaybe", + "0x01000000"); } else if (meshHeaderType == 1) { - MeshHeader1Base* meshHeader1 = nullptr; - - uint8_t fmt = rawData[segmentOffset + 1]; - - if (fmt == 1) // Single Format + PolygonType1 polygon1(zRoom->GetName().c_str(), rawData, segmentOffset, zRoom->parent, + zRoom); + if (polygon1.polyGfxList.opaDList != nullptr) { - MeshHeader1Single* headerSingle = new MeshHeader1Single(); - - headerSingle->headerType = 1; - headerSingle->format = fmt; - headerSingle->entryRecord = - BitConverter::ToInt32BE(rawData, segmentOffset + 4); // &0x00FFFFFF; - - headerSingle->imagePtr = - BitConverter::ToInt32BE(rawData, segmentOffset + 8); // &0x00FFFFFF; - headerSingle->unknown = BitConverter::ToInt32BE(rawData, segmentOffset + 12); - headerSingle->unknown2 = BitConverter::ToInt32BE(rawData, segmentOffset + 16); - headerSingle->bgWidth = BitConverter::ToInt16BE(rawData, segmentOffset + 20); - headerSingle->bgHeight = BitConverter::ToInt16BE(rawData, segmentOffset + 22); - headerSingle->imageFormat = rawData[segmentOffset + 24]; - headerSingle->imageSize = rawData[segmentOffset + 25]; - headerSingle->imagePal = BitConverter::ToInt16BE(rawData, segmentOffset + 26); - headerSingle->imageFlip = BitConverter::ToInt16BE(rawData, segmentOffset + 28); - - declaration += StringHelper::Sprintf("{ { 1 }, 1, 0x%06X }, 0x%06X, ", - headerSingle->entryRecord, headerSingle->imagePtr); - - declaration += StringHelper::Sprintf("0x%06X, 0x%06X, %i, %i, %i, %i, %i, %i\n", - headerSingle->unknown, headerSingle->unknown2, - headerSingle->bgWidth, headerSingle->bgHeight, - headerSingle->imageFormat, headerSingle->imageSize, - headerSingle->imagePal, headerSingle->imageFlip); - - zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, - DeclarationPadding::Pad16, 0x1E, "MeshHeader1Single", - StringHelper::Sprintf("%sMeshHeader0x%06X", - zRoom->GetName().c_str(), - segmentOffset), - declaration); - - meshHeader1 = headerSingle; + GenDListDeclarations(rawData, polygon1.polyGfxList.opaDList); } - else if (fmt == 2) // Multi-Format + if (polygon1.polyGfxList.xluDList != nullptr) { - MeshHeader1Multi* headerMulti = new MeshHeader1Multi(); - - headerMulti->headerType = 1; - headerMulti->format = fmt; - headerMulti->entryRecord = - BitConverter::ToInt32BE(rawData, segmentOffset + 4); // &0x00FFFFFF; - - headerMulti->bgCnt = rawData[segmentOffset + 8]; - headerMulti->bgRecordPtr = BitConverter::ToInt32BE(rawData, segmentOffset + 12); - - declaration += StringHelper::Sprintf("{ { 1 }, 2, 0x%06X }, 0x%06X, 0x%06X", - headerMulti->entryRecord, headerMulti->bgCnt, - headerMulti->bgRecordPtr); - - zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, - DeclarationPadding::Pad16, 16, "MeshHeader1Multi", - StringHelper::Sprintf("%sMeshHeader0x%06X", - zRoom->GetName().c_str(), - segmentOffset), - declaration); - - meshHeader1 = headerMulti; + GenDListDeclarations(rawData, polygon1.polyGfxList.xluDList); } - else // UH OH - { - if (Globals::Instance->verbosity >= VERBOSITY_INFO) - printf("WARNING: MeshHeader FMT %i not implemented!\n", fmt); - } - - meshHeader1->headerType = 1; - meshHeader1->format = fmt; - meshHeader1->entryRecord = BitConverter::ToInt32BE(rawData, segmentOffset + 4) & 0x00FFFFFF; - - meshHeader = meshHeader1; + polygon1.DeclareAndGenerateOutputCode(); } else if (meshHeaderType == 2) { @@ -222,8 +123,7 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, int8_t numEntries = rawData[segmentOffset + 1]; uint32_t currentPtr = meshHeader2->dListStart; - // HOTSPOT - for (int i = 0; i < numEntries; i++) + for (int32_t i = 0; i < numEntries; i++) { MeshEntry2* entry = new MeshEntry2(); entry->playerXMax = BitConverter::ToInt16BE(rawData, currentPtr + 0); @@ -231,9 +131,9 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, entry->playerXMin = BitConverter::ToInt16BE(rawData, currentPtr + 4); entry->playerZMin = BitConverter::ToInt16BE(rawData, currentPtr + 6); - entry->opaqueDListAddr = BitConverter::ToInt32BE(rawData, currentPtr + 8) & 0x00FFFFFF; + entry->opaqueDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 8)); entry->translucentDListAddr = - BitConverter::ToInt32BE(rawData, currentPtr + 12) & 0x00FFFFFF; + GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 12)); if (entry->opaqueDListAddr != 0) { @@ -242,10 +142,10 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : - DListType::F3DZEX)); + DListType::F3DZEX), + zRoom->parent); entry->opaqueDList->scene = zRoom->scene; - entry->opaqueDList->parent = zRoom->parent; - GenDListDeclarations(rawData, entry->opaqueDList); // HOTSPOT + GenDListDeclarations(rawData, entry->opaqueDList); } if (entry->translucentDListAddr != 0) @@ -255,10 +155,10 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : - DListType::F3DZEX)); + DListType::F3DZEX), + zRoom->parent); entry->translucentDList->scene = zRoom->scene; - entry->translucentDList->parent = zRoom->parent; - GenDListDeclarations(rawData, entry->translucentDList); // HOTSPOT + GenDListDeclarations(rawData, entry->translucentDList); } meshHeader2->entries.push_back(entry); @@ -281,6 +181,7 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, meshHeader2->dListStart); else declaration += "0"; + declaration += "\n"; zRoom->parent->AddDeclaration( segmentOffset, DeclarationAlignment::None, 12, "MeshHeader2", @@ -292,7 +193,7 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, for (size_t i = 0; i < meshHeader2->entries.size(); i++) { declaration += StringHelper::Sprintf( - "\t{ %i, %i, %i, %i, ", meshHeader2->entries[i]->playerXMax, + " { %i, %i, %i, %i, ", meshHeader2->entries[i]->playerXMax, meshHeader2->entries[i]->playerZMax, meshHeader2->entries[i]->playerXMin, meshHeader2->entries[i]->playerZMin); @@ -336,27 +237,22 @@ SetMesh::~SetMesh() void SetMesh::GenDListDeclarations(std::vector rawData, ZDisplayList* dList) { - string srcVarName = ""; - - // if (Globals::Instance->includeFilePrefix) - srcVarName = StringHelper::Sprintf("%s%s", zRoom->GetName().c_str(), dList->GetName().c_str()); - // else - // srcVarName = StringHelper::Sprintf("%s", dList->GetName().c_str()); + string srcVarName = + StringHelper::Sprintf("%s%s", zRoom->GetName().c_str(), dList->GetName().c_str()); dList->SetName(srcVarName); - string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName()); // HOTSPOT - - // zRoom->parent->AddDeclarationArray(dList->GetRawDataIndex(), DeclarationAlignment::None, - // dList->GetRawDataSize(), "static Gfx", srcVarName, dList->GetRawDataSize() / 8, sourceOutput); + string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName()); for (ZDisplayList* otherDList : dList->otherDLists) GenDListDeclarations(rawData, otherDList); for (pair vtxEntry : dList->vtxDeclarations) { + DeclarationAlignment alignment = DeclarationAlignment::Align8; + if (Globals::Instance->game == ZGame::MM_RETAIL) + alignment = DeclarationAlignment::None; zRoom->parent->AddDeclarationArray( - vtxEntry.first, DeclarationAlignment::Align8, - dList->vertices[vtxEntry.first].size() * 16, "static Vtx", + vtxEntry.first, alignment, dList->vertices[vtxEntry.first].size() * 16, "static Vtx", StringHelper::Sprintf("%sVtx_%06X", zRoom->GetName().c_str(), vtxEntry.first), dList->vertices[vtxEntry.first].size(), vtxEntry.second); } @@ -364,23 +260,6 @@ void SetMesh::GenDListDeclarations(std::vector rawData, ZDisplayList* d for (pair texEntry : dList->texDeclarations) { zRoom->textures[texEntry.first] = dList->textures[texEntry.first]; - - if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) - printf("SAVING IMAGE TO %s\n", Globals::Instance->outputPath.c_str()); - - zRoom->textures[texEntry.first]->Save(Globals::Instance->outputPath); - - zRoom->parent->AddDeclarationIncludeArray( - texEntry.first, - StringHelper::Sprintf( - "%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(), - Path::GetFileNameWithoutExtension(zRoom->textures[texEntry.first]->GetName()) - .c_str(), - zRoom->textures[texEntry.first]->GetExternalExtension().c_str()), - zRoom->textures[texEntry.first]->GetRawDataSize(), "u64", - StringHelper::Sprintf("%s", zRoom->textures[texEntry.first]->GetName().c_str(), - texEntry.first), - 0); } } @@ -406,90 +285,25 @@ std::string SetMesh::GenDListExterns(ZDisplayList* dList) return sourceOutput; } -string SetMesh::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetMesh::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { string sourceOutput = ""; - sourceOutput += - StringHelper::Sprintf("%s %i, (u32)&%sMeshHeader0x%06X", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), - data, zRoom->GetName().c_str(), segmentOffset); + Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset); - /*if (meshHeader->headerType == 0) - { - MeshHeader0* meshHeader0 = (MeshHeader0*)meshHeader; + sourceOutput += StringHelper::Sprintf( + "%s %i, &%s", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), data, + decl->varName.c_str()); - } - else - { - sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n"; - } -*/ return sourceOutput; } string SetMesh::GenerateExterns() { - string sourceOutput = ""; - - if (meshHeader->headerType == 0) - { - MeshHeader0* meshHeader0 = (MeshHeader0*)meshHeader; - - sourceOutput += StringHelper::Sprintf("extern MeshHeader0 %sMeshHeader0x%06X;\n", - zRoom->GetName().c_str(), segmentOffset); - sourceOutput += StringHelper::Sprintf("extern MeshEntry0 %sMeshDListEntry0x%06X[%i];\n", - zRoom->GetName().c_str(), meshHeader0->dListStart, - meshHeader0->entries.size()); - - for (MeshEntry0* entry : meshHeader0->entries) - { - if (entry->opaqueDList != nullptr) - sourceOutput += GenDListExterns(entry->opaqueDList); - - if (entry->translucentDList != nullptr) - sourceOutput += GenDListExterns(entry->translucentDList); - } - } - else if (meshHeader->headerType == 1) - { - MeshHeader1Base* meshHeader1 = (MeshHeader1Base*)meshHeader; - - if (meshHeader1->format == 1) - sourceOutput += StringHelper::Sprintf("extern MeshHeader1Single %sMeshHeader0x%06X;\n", - zRoom->GetName().c_str(), segmentOffset); - else if (meshHeader1->format == 2) - sourceOutput += StringHelper::Sprintf("extern MeshHeader1Multi %sMeshHeader0x%06X;\n", - zRoom->GetName().c_str(), segmentOffset); - } - else if (meshHeader->headerType == 2) - { - MeshHeader2* meshHeader2 = (MeshHeader2*)meshHeader; - - sourceOutput += StringHelper::Sprintf("extern MeshHeader2 %sMeshHeader0x%06X;\n", - zRoom->GetName().c_str(), segmentOffset); - sourceOutput += StringHelper::Sprintf("extern MeshEntry2 %sMeshDListEntry0x%06X[%i];\n", - zRoom->GetName().c_str(), meshHeader2->dListStart, - meshHeader2->entries.size()); - - for (MeshEntry2* entry : meshHeader2->entries) - { - if (entry->opaqueDList != nullptr) - sourceOutput += GenDListExterns(entry->opaqueDList); - - if (entry->translucentDList != nullptr) - sourceOutput += GenDListExterns(entry->translucentDList); - } - } - else - { - // sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n"; - } - - return sourceOutput; + return ""; } -int32_t SetMesh::GetRawDataSize() +size_t SetMesh::GetRawDataSize() { return ZRoomCommand::GetRawDataSize(); } @@ -502,4 +316,488 @@ string SetMesh::GetCommandCName() RoomCommand SetMesh::GetRoomCommand() { return RoomCommand::SetMesh; -} \ No newline at end of file +} + +PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector& nRawData, + uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + parent = nParent; + room = nRoom; + + name = GetDefaultName(prefix.c_str(), rawDataIndex); + + ParseRawData(); + + opaDList = MakeDlist(opa, prefix); + xluDList = MakeDlist(xlu, prefix); +} + +void PolygonDlist::ParseRawData() +{ + opa = BitConverter::ToUInt32BE(rawData, rawDataIndex); + xlu = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4); +} + +ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, const std::string& prefix) +{ + if (ptr == 0) + { + return nullptr; + } + + uint32_t dlistAddress = Seg2Filespace(ptr, parent->baseAddress); + + int32_t dlistLength = ZDisplayList::GetDListLength( + rawData, dlistAddress, + Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); + ZDisplayList* dlist = new ZDisplayList(rawData, dlistAddress, dlistLength, parent); + + string dListStr = StringHelper::Sprintf("%sPolygonDlist_%06X", prefix.c_str(), dlistAddress); + dlist->SetName(dListStr); + dlist->scene = room->scene; + dlist->GetSourceOutputCode(prefix); + + return dlist; +} + +size_t PolygonDlist::GetRawDataSize() +{ + return 0x08; +} + +void PolygonDlist::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + if (name == "") + { + auxName = GetDefaultName(prefix, rawDataIndex); + } + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(), + GetSourceTypeName(), auxName, bodyStr); +} + +std::string PolygonDlist::GetBodySourceCode(bool arrayElement) +{ + std::string bodyStr = ""; + std::string opaStr = "NULL"; + std::string xluStr = "NULL"; + if (arrayElement) + { + bodyStr += " { \n "; + } + else + { + bodyStr += "\n"; + } + + if (opa != 0) + { + Declaration* decl = parent->GetDeclaration(Seg2Filespace(opa, parent->baseAddress)); + if (decl != nullptr) + { + opaStr = decl->varName; + } + else + { + opaStr = StringHelper::Sprintf("0x%08X", opa); + } + } + if (xlu != 0) + { + Declaration* decl = parent->GetDeclaration(Seg2Filespace(xlu, parent->baseAddress)); + if (decl != nullptr) + { + xluStr = decl->varName; + } + else + { + xluStr = StringHelper::Sprintf("0x%08X", xlu); + } + } + + bodyStr += StringHelper::Sprintf(" %s, \n", opaStr.c_str()); + if (arrayElement) + { + bodyStr += " "; + } + + bodyStr += StringHelper::Sprintf(" %s, \n", xluStr.c_str()); + + if (arrayElement) + { + bodyStr += " },"; + } + + return bodyStr; +} + +void PolygonDlist::DeclareAndGenerateOutputCode() +{ + std::string bodyStr = GetBodySourceCode(false); + + Declaration* decl = parent->GetDeclaration(rawDataIndex); + if (decl == nullptr) + { + DeclareVar("", bodyStr); + } + else + { + decl->text = bodyStr; + } +} + +std::string PolygonDlist::GetDefaultName(const std::string& prefix, uint32_t address) +{ + return StringHelper::Sprintf("%sPolyDlist_%06X", prefix.c_str(), address); +} + +std::string PolygonDlist::GetSourceTypeName() +{ + return "PolygonDlist"; +} + +std::string PolygonDlist::GetName() +{ + return name; +} + +BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector& nRawData, + uint32_t nRawDataIndex, ZFile* nParent) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + parent = nParent; + isSubStruct = nIsSubStruct; + + name = GetDefaultName(prefix.c_str(), rawDataIndex); + + ParseRawData(); + sourceBackground = MakeBackground(source, prefix); +} + +void BgImage::ParseRawData() +{ + size_t pad = 0x00; + if (!isSubStruct) + { + pad = 0x04; + + unk_00 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00); + id = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x02); + } + source = BitConverter::ToUInt32BE(rawData, rawDataIndex + pad + 0x00); + unk_0C = BitConverter::ToUInt32BE(rawData, rawDataIndex + pad + 0x04); + tlut = BitConverter::ToUInt32BE(rawData, rawDataIndex + pad + 0x08); + width = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x0C); + height = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x0E); + fmt = BitConverter::ToUInt8BE(rawData, rawDataIndex + pad + 0x10); + siz = BitConverter::ToUInt8BE(rawData, rawDataIndex + pad + 0x11); + mode0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x12); + tlutCount = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x14); +} + +ZBackground* BgImage::MakeBackground(segptr_t ptr, const std::string& prefix) +{ + if (ptr == 0) + { + return nullptr; + } + + uint32_t backAddress = Seg2Filespace(ptr, parent->baseAddress); + + ZBackground* background = new ZBackground(prefix, rawData, backAddress, parent); + background->DeclareVar(prefix, ""); + parent->resources.push_back(background); + + return background; +} + +size_t BgImage::GetRawDataSize() +{ + return 0x1C; +} + +std::string BgImage::GetBodySourceCode(bool arrayElement) +{ + std::string bodyStr = ""; + if (arrayElement) + { + bodyStr += " { \n "; + } + + if (!isSubStruct) + { + bodyStr += StringHelper::Sprintf("0x%04X, ", unk_00); + bodyStr += StringHelper::Sprintf("%i, ", id); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + } + + std::string backgroundName = "NULL"; + if (source != 0) + { + uint32_t address = Seg2Filespace(source, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(address); + + if (decl == nullptr) + { + backgroundName += StringHelper::Sprintf("0x%08X, ", source); + } + else + { + backgroundName = decl->varName; + } + } + bodyStr += StringHelper::Sprintf("%s, ", backgroundName.c_str()); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + + bodyStr += StringHelper::Sprintf("0x%08X, ", unk_0C); + bodyStr += StringHelper::Sprintf("0x%08X, ", tlut); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + + bodyStr += StringHelper::Sprintf("%i, ", width); + bodyStr += StringHelper::Sprintf("%i, ", height); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + + bodyStr += StringHelper::Sprintf("%i, ", fmt); + bodyStr += StringHelper::Sprintf("%i, ", siz); + bodyStr += "\n "; + if (arrayElement) + { + bodyStr += " "; + } + + bodyStr += StringHelper::Sprintf("0x%04X, ", mode0); + bodyStr += StringHelper::Sprintf("0x%04X, ", tlutCount); + if (arrayElement) + { + bodyStr += " \n }, "; + } + + return bodyStr; +} + +std::string BgImage::GetDefaultName(const std::string& prefix, uint32_t address) +{ + return StringHelper::Sprintf("%sBgImage_%06X", prefix.c_str(), address); +} + +std::string BgImage::GetSourceTypeName() +{ + return "BgImage"; +} + +std::string BgImage::GetName() +{ + return name; +} + +PolygonType1::PolygonType1(const std::string& prefix, const std::vector& nRawData, + uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom) +{ + rawData.assign(nRawData.begin(), nRawData.end()); + rawDataIndex = nRawDataIndex; + parent = nParent; + + name = GetDefaultName(prefix.c_str(), rawDataIndex); + + ParseRawData(); + + if (dlist != 0) + { + polyGfxList = + PolygonDlist(prefix, rawData, Seg2Filespace(dlist, parent->baseAddress), parent, nRoom); + } + + uint32_t listAddress; + std::string bgImageArrayBody = ""; + switch (format) + { + case 1: + single = BgImage(true, prefix, nRawData, nRawDataIndex + 0x08, parent); + break; + + case 2: + if (list != 0) + { + listAddress = Seg2Filespace(list, parent->baseAddress); + for (size_t i = 0; i < count; ++i) + { + BgImage bg(false, prefix, rawData, listAddress + i * BgImage::GetRawDataSize(), + parent); + multiList.push_back(bg); + bgImageArrayBody += bg.GetBodySourceCode(true); + if (i + 1 < count) + { + bgImageArrayBody += "\n"; + } + } + + Declaration* decl = parent->GetDeclaration(listAddress); + if (decl == nullptr) + { + parent->AddDeclarationArray( + listAddress, DeclarationAlignment::Align4, count * BgImage::GetRawDataSize(), + BgImage::GetSourceTypeName(), multiList.at(0).GetName().c_str(), count, + bgImageArrayBody); + } + } + break; + + default: + throw std::runtime_error(StringHelper::Sprintf( + "Error in PolygonType1::PolygonType1\n\t Unknown format: %i\n", format)); + break; + } +} + +void PolygonType1::ParseRawData() +{ + type = BitConverter::ToUInt8BE(rawData, rawDataIndex); + format = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01); + dlist = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04); + + if (format == 2) + { + count = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08); + list = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C); + } +} + +size_t PolygonType1::GetRawDataSize() +{ + switch (format) + { + case 1: + return 0x20; + + case 2: + return 0x10; + } + return 0x20; +} + +void PolygonType1::DeclareVar(const std::string& prefix, const std::string& bodyStr) +{ + std::string auxName = name; + if (name == "") + { + auxName = GetDefaultName(prefix, rawDataIndex); + } + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(), + GetSourceTypeName(), auxName, bodyStr); +} + +std::string PolygonType1::GetBodySourceCode() +{ + std::string bodyStr = "\n "; + + bodyStr += "{ "; + bodyStr += StringHelper::Sprintf("%i, %i, ", type, format); + + std::string dlistStr = "NULL"; + if (dlist != 0) + { + uint32_t entryRecordAddress = Seg2Filespace(dlist, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(entryRecordAddress); + + if (decl == nullptr) + { + polyGfxList.DeclareAndGenerateOutputCode(); + dlistStr = "&" + polyGfxList.GetName(); + } + else + { + dlistStr = "&" + decl->varName; + } + } + bodyStr += StringHelper::Sprintf("%s, ", dlistStr.c_str()); + bodyStr += "}, \n"; + + std::string listStr = "NULL"; + // bodyStr += " { \n"; + switch (format) + { + case 1: + bodyStr += " " + single.GetBodySourceCode(false) + "\n"; + break; + case 2: + if (list != 0) + { + uint32_t listAddress = Seg2Filespace(list, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(listAddress); + if (decl != nullptr) + { + listStr = decl->varName; + } + else + { + listStr = StringHelper::Sprintf("0x%08X", list); + } + } + bodyStr += StringHelper::Sprintf(" %i, %s, \n", count, listStr.c_str()); + break; + + default: + break; + } + // bodyStr += " } \n"; + + return bodyStr; +} + +void PolygonType1::DeclareAndGenerateOutputCode() +{ + std::string bodyStr = GetBodySourceCode(); + + Declaration* decl = parent->GetDeclaration(rawDataIndex); + if (decl == nullptr) + { + DeclareVar("", bodyStr); + } + else + { + decl->text = bodyStr; + } +} + +std::string PolygonType1::GetDefaultName(const std::string& prefix, uint32_t address) +{ + return StringHelper::Sprintf("%sPolygonType1_%06X", prefix.c_str(), address); +} + +std::string PolygonType1::GetSourceTypeName() +{ + switch (format) + { + case 1: + return "MeshHeader1Single"; + + case 2: + return "MeshHeader1Multi"; + } + return "ERROR"; + // return "PolygonType1"; +} + +std::string PolygonType1::GetName() +{ + return name; +} diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h index 1105e0b59e..62fabd76cc 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h @@ -2,6 +2,7 @@ #include "../../ZDisplayList.h" #include "../ZRoomCommand.h" +#include "ZBackground.h" class MeshHeaderBase { @@ -9,74 +10,6 @@ public: int8_t headerType; // 0x00 }; -class MeshEntry0 -{ -public: - int32_t opaqueDListAddr; - int32_t translucentDListAddr; - - ZDisplayList* opaqueDList; - ZDisplayList* translucentDList; -}; - -class MeshHeader0 : public MeshHeaderBase -{ -public: - std::vector entries; - uint32_t dListStart; - uint32_t dListEnd; -}; - -class MeshHeader1Base : public MeshHeaderBase -{ -public: - int8_t format; // 0x01 - uint32_t entryRecord; // 0x04 -}; - -class MeshHeader1Single : public MeshHeader1Base -{ -public: - uint32_t imagePtr; // 0x08 - - uint32_t unknown; // 0x0C - uint32_t unknown2; // 0x10 - - uint16_t bgWidth; // 0x14 - uint16_t bgHeight; // 0x16 - - uint8_t imageFormat; // 0x18 - uint8_t imageSize; // 0x19 - uint16_t imagePal; // 0x1A - uint16_t imageFlip; // 0x1C -}; - -class MeshHeader1Multi : public MeshHeader1Base -{ -public: - uint8_t bgCnt; // 0x08 - uint32_t bgRecordPtr; // 0x0C -}; - -class BackgroundRecord -{ -public: - uint16_t unknown; // 0x00 - int8_t bgID; // 0x02 - - uint32_t imagePtr; // 0x04 - uint32_t unknown2; // 0x08 - uint32_t unknown3; // 0x0C - - uint16_t bgWidth; // 0x10 - uint16_t bgHeight; // 0x12 - - uint8_t imageFmt; // 0x14 - uint8_t imageSize; // 0x15 - uint16_t imagePal; // 0x16 - uint16_t imageFlip; // 0x18 -}; - class MeshEntry2 { public: @@ -98,25 +31,139 @@ public: uint32_t dListEnd; }; +class PolygonDlist +{ +protected: + segptr_t opa = 0; // Gfx* + segptr_t xlu = 0; // Gfx* + + std::vector rawData; + uint32_t rawDataIndex; + ZFile* parent; + ZRoom* room; + std::string name; + + void ParseRawData(); + ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix); + +public: + PolygonDlist() = default; + PolygonDlist(const std::string& prefix, const std::vector& nRawData, uint32_t nRawDataIndex, + ZFile* nParent, ZRoom* nRoom); + + size_t GetRawDataSize(); + + void DeclareVar(const std::string& prefix, const std::string& bodyStr); + + std::string GetBodySourceCode(bool arrayElement); + void DeclareAndGenerateOutputCode(); + + static std::string GetDefaultName(const std::string& prefix, uint32_t address); + std::string GetSourceTypeName(); + std::string GetName(); + + ZDisplayList* opaDList = nullptr; // Gfx* + ZDisplayList* xluDList = nullptr; // Gfx* +}; + +class BgImage +{ +protected: + uint16_t unk_00; + uint8_t id; + segptr_t source; + uint32_t unk_0C; + uint32_t tlut; + uint16_t width; + uint16_t height; + uint8_t fmt; + uint8_t siz; + uint16_t mode0; + uint16_t tlutCount; + + ZBackground* sourceBackground; + + std::vector rawData; + uint32_t rawDataIndex; + ZFile* parent; + std::string name; + bool isSubStruct; + + void ParseRawData(); + ZBackground* MakeBackground(segptr_t ptr, const std::string& prefix); + +public: + BgImage() = default; + BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector& nRawData, + uint32_t nRawDataIndex, ZFile* nParent); + + static size_t GetRawDataSize() ; + + std::string GetBodySourceCode(bool arrayElement); + + static std::string GetDefaultName(const std::string& prefix, uint32_t address); + static std::string GetSourceTypeName(); + std::string GetName(); +}; + +class PolygonType1 +{ +protected: + uint8_t type; + uint8_t format; + segptr_t dlist; + + // single + BgImage single; + + // multi + uint8_t count; + segptr_t list; // BgImage* + std::vector multiList; + + std::vector rawData; + uint32_t rawDataIndex; + ZFile* parent; + std::string name; + + void ParseRawData(); + +public: + PolygonType1(const std::string& prefix, const std::vector& nRawData, uint32_t nRawDataIndex, + ZFile* nParent, ZRoom* nRoom); + + size_t GetRawDataSize() ; + + void DeclareVar(const std::string& prefix, const std::string& bodyStr); + + std::string GetBodySourceCode(); + void DeclareAndGenerateOutputCode(); + + static std::string GetDefaultName(const std::string& prefix, uint32_t address); + std::string GetSourceTypeName(); + std::string GetName(); + + PolygonDlist polyGfxList; +}; + class SetMesh : public ZRoomCommand { public: - SetMesh(ZRoom* nZRoom, std::vector rawData, int rawDataIndex, int segAddressOffset); + SetMesh(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex, int32_t segAddressOffset); ~SetMesh(); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - // virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - // virtual std::string GenerateSourceCodePass3(std::string roomName); - virtual std::string GenerateExterns(); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); - virtual int32_t GetRawDataSize(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateExterns() override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; + virtual size_t GetRawDataSize() override; private: - MeshHeaderBase* meshHeader; + MeshHeaderBase* meshHeader = nullptr; uint32_t segmentOffset; uint8_t data; + uint8_t meshHeaderType; void GenDListDeclarations(std::vector rawData, ZDisplayList* dList); std::string GenDListExterns(ZDisplayList* dList); -}; \ No newline at end of file +}; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapChests.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapChests.cpp new file mode 100644 index 0000000000..64b1d31762 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapChests.cpp @@ -0,0 +1,101 @@ +#include "SetMinimapChests.h" +#include "../../BitConverter.h" +#include "../../Globals.h" +#include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" + +using namespace std; + +SetMinimapChests::SetMinimapChests(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) +{ + int32_t numChests = rawData[rawDataIndex + 1]; + segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); + + int32_t currentPtr = segmentOffset; + + for (int32_t i = 0; i < numChests; i++) + { + MinimapChest* chest = new MinimapChest(rawData, currentPtr); + chests.push_back(chest); + + currentPtr += 10; + } +} + +SetMinimapChests::~SetMinimapChests() +{ + for (MinimapChest* chest : chests) + delete chest; +} + +string SetMinimapChests::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) +{ + return std::string(); +} + +string SetMinimapChests::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) +{ + string sourceOutput = ""; + + sourceOutput += + StringHelper::Sprintf("%s 0x%02X, (u32)%sMinimapChests0x%06X };", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + chests.size(), roomName.c_str(), segmentOffset); + + { + string declaration = ""; + + size_t index = 0; + for (MinimapChest* chest : chests) + { + declaration += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },", + chest->unk0, chest->unk2, chest->unk4, chest->unk6, + chest->unk8); + + if (index < chests.size() - 1) + declaration += "\n"; + + index++; + } + + zRoom->parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, chests.size() * 10, + "MinimapChest", + StringHelper::Sprintf("%sMinimapChests0x%06X", roomName.c_str(), segmentOffset), + chests.size(), declaration); + } + + return sourceOutput; +} + +string SetMinimapChests::GenerateExterns() +{ + return StringHelper::Sprintf("extern MinimapChest %sMinimapChests0x%06X[%i];\n", + zRoom->GetName().c_str(), segmentOffset, chests.size()); +} + +string SetMinimapChests::GetCommandCName() +{ + return "SCmdMinimapChests"; +} + +RoomCommand SetMinimapChests::GetRoomCommand() +{ + return RoomCommand::SetMinimapChests; +} + +size_t SetMinimapChests::GetRawDataSize() +{ + return ZRoomCommand::GetRawDataSize() + (chests.size() * 10); +} + +MinimapChest::MinimapChest(std::vector rawData, uint32_t rawDataIndex) + : unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), + unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)), + unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)), + unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)), + unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8)) +{ +} \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapChests.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapChests.h new file mode 100644 index 0000000000..37e42708ac --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapChests.h @@ -0,0 +1,33 @@ +#pragma once + +#include "../ZRoomCommand.h" + +class MinimapChest +{ +public: + uint16_t unk0; + uint16_t unk2; + uint16_t unk4; + uint16_t unk6; + uint16_t unk8; + + MinimapChest(std::vector rawData, uint32_t rawDataIndex); +}; + +class SetMinimapChests : public ZRoomCommand +{ +public: + SetMinimapChests(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); + ~SetMinimapChests(); + + std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + std::string GetCommandCName() override; + std::string GenerateExterns() override; + RoomCommand GetRoomCommand() override; + size_t GetRawDataSize() override; + +private: + std::vector chests; + uint32_t segmentOffset; +}; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.cpp new file mode 100644 index 0000000000..0dd19617cf --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.cpp @@ -0,0 +1,117 @@ +#include "SetMinimapList.h" +#include "../../BitConverter.h" +#include "../../Globals.h" +#include "../../StringHelper.h" +#include "../../ZFile.h" +#include "../ZRoom.h" + +using namespace std; + +SetMinimapList::SetMinimapList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) +{ + segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); + listSegmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 0)); + unk4 = BitConverter::ToInt32BE(rawData, segmentOffset + 4); + + minimaps = vector(); + + int32_t currentPtr = listSegmentOffset; + + for (int32_t i = 0; i < zRoom->roomCount; i++) + { + MinimapEntry* entry = new MinimapEntry(rawData, currentPtr); + minimaps.push_back(entry); + + currentPtr += 10; + } +} + +SetMinimapList::~SetMinimapList() +{ + for (MinimapEntry* entry : minimaps) + delete entry; +} + +string SetMinimapList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) +{ + return StringHelper::Sprintf( + "%s 0x%02X, (u32)&%sMinimapList0x%06X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), minimaps.size(), + zRoom->GetName().c_str(), segmentOffset); +} + +string SetMinimapList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) +{ + string sourceOutput = ""; + + sourceOutput += + StringHelper::Sprintf("%s 0, (u32)&%sMinimapList0x%06X };", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), + roomName.c_str(), segmentOffset, unk4); + + { + string declaration = StringHelper::Sprintf("(u32)%sMinimapEntryList0x%06X, 0x%08X", + roomName.c_str(), listSegmentOffset, unk4); + + zRoom->parent->AddDeclaration( + segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 8, "MinimapList", + StringHelper::Sprintf("%sMinimapList0x%06X", roomName.c_str(), segmentOffset), + declaration); + } + + { + string declaration = ""; + + size_t index = 0; + for (MinimapEntry* entry : minimaps) + { + declaration += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },", + entry->unk0, entry->unk2, entry->unk4, entry->unk6, + entry->unk8); + + if (index < minimaps.size() - 1) + declaration += "\n"; + + index++; + } + + zRoom->parent->AddDeclarationArray( + listSegmentOffset, DeclarationAlignment::None, DeclarationPadding::None, + minimaps.size() * 10, "MinimapEntry", + StringHelper::Sprintf("%sMinimapEntryList0x%06X", roomName.c_str(), listSegmentOffset), + minimaps.size(), declaration); + } + + return sourceOutput; +} + +string SetMinimapList::GenerateExterns() +{ + return StringHelper::Sprintf("extern MinimapList %sMinimapList0x%06X;\n", + zRoom->GetName().c_str(), listSegmentOffset); +} + +string SetMinimapList::GetCommandCName() +{ + return "SCmdMinimapSettings"; +} + +RoomCommand SetMinimapList::GetRoomCommand() +{ + return RoomCommand::SetMinimapList; +} + +size_t SetMinimapList::GetRawDataSize() +{ + return ZRoomCommand::GetRawDataSize() + (minimaps.size() * 10); +} + +MinimapEntry::MinimapEntry(std::vector rawData, uint32_t rawDataIndex) + : unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)), + unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)), + unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)), + unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)), + unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8)) +{ +} \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.h new file mode 100644 index 0000000000..f382881e5a --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.h @@ -0,0 +1,36 @@ +#pragma once + +#include "../ZRoomCommand.h" + +class MinimapEntry +{ +public: + uint16_t unk0; + uint16_t unk2; + uint16_t unk4; + uint16_t unk6; + uint16_t unk8; + + MinimapEntry(std::vector rawData, uint32_t rawDataIndex); +}; + +class SetMinimapList : public ZRoomCommand +{ +public: + SetMinimapList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); + ~SetMinimapList(); + + std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + std::string GetCommandCName() override; + std::string GenerateExterns() override; + RoomCommand GetRoomCommand() override; + size_t GetRawDataSize() override; + +private: + std::vector minimaps; + uint32_t segmentOffset; + + uint32_t listSegmentOffset; + uint32_t unk4; +}; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.cpp index f8d00a101e..52e2052215 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.cpp @@ -1,13 +1,14 @@ #include "SetObjectList.h" #include "../../BitConverter.h" +#include "../../Globals.h" #include "../../StringHelper.h" #include "../../ZFile.h" -#include "../ObjectList.h" +#include "../ZNames.h" #include "../ZRoom.h" using namespace std; -SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { objects = vector(); @@ -32,7 +33,7 @@ string SetObjectList::GenerateExterns() segmentOffset); } -string SetObjectList::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetObjectList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { string sourceOutput = ""; @@ -46,7 +47,7 @@ string SetObjectList::GenerateSourceCodePass1(string roomName, int baseAddress) for (size_t i = 0; i < objects.size(); i++) { uint16_t objectIndex = objects[i]; - declaration += StringHelper::Sprintf("\t%s,", ObjectList[objectIndex].c_str()); + declaration += StringHelper::Sprintf(" %s,", ZNames::GetObjectName(objectIndex).c_str()); if (i < objects.size() - 1) declaration += "\n"; @@ -60,7 +61,7 @@ string SetObjectList::GenerateSourceCodePass1(string roomName, int baseAddress) return sourceOutput; } -int32_t SetObjectList::GetRawDataSize() +size_t SetObjectList::GetRawDataSize() { return ZRoomCommand::GetRawDataSize() + (objects.size() * 2); } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.h index 0c43eb6ec1..8bf82f4f60 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetObjectList.h @@ -5,13 +5,13 @@ class SetObjectList : public ZRoomCommand { public: - SetObjectList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetObjectList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); - virtual int32_t GetRawDataSize(); - virtual std::string GenerateExterns(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; + virtual size_t GetRawDataSize() override; + virtual std::string GenerateExterns() override; private: std::vector objects; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp index 9d70e273cf..149f4fa88a 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp @@ -1,101 +1,183 @@ #include "SetPathways.h" #include "../../BitConverter.h" +#include "../../Globals.h" #include "../../StringHelper.h" #include "../../ZFile.h" #include "../ZRoom.h" +REGISTER_ZFILENODE(Path, ZSetPathways); + using namespace std; -SetPathways::SetPathways(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) - : ZRoomCommand(nZRoom, rawData, rawDataIndex) +ZSetPathways::ZSetPathways(ZFile* nParent) : ZResource(nParent) { - _rawData = rawData; - _rawDataIndex = rawDataIndex; - - segmentOffset = 0; - listSegmentOffset = 0; - - InitList(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))); - - if (segmentOffset != 0) - zRoom->parent->AddDeclarationPlaceholder(segmentOffset); } -SetPathways::~SetPathways() +ZSetPathways::ZSetPathways(ZRoom* nZRoom, const std::vector& nRawData, uint32_t nRawDataIndex, + bool nIsFromHeader) + : ZResource(nZRoom->parent), ZRoomCommand(nZRoom, nRawData, nRawDataIndex) { - for (PathwayEntry* entry : pathways) - delete entry; + rawData = nRawData; + rawDataIndex = nRawDataIndex; + isFromHeader = nIsFromHeader; } -void SetPathways::InitList(uint32_t address) +ZSetPathways::~ZSetPathways() { - segmentOffset = address; - listSegmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(_rawData, address + 4)); - numPoints = _rawData[address + 0]; + delete pathwayList; } -string SetPathways::GetSourceOutputCode(std::string prefix) +void ZSetPathways::DeclareVar(const std::string& prefix, const std::string& bodyStr) { + parent->AddDeclaration(cmdAddress, DeclarationAlignment::None, 8, + StringHelper::Sprintf("static %s", GetCommandCName().c_str()), + StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), + commandSet & 0x00FFFFFF, cmdIndex, cmdID), + StringHelper::Sprintf("%s // 0x%04X", bodyStr.c_str(), cmdAddress)); +} + +string ZSetPathways::GetSourceOutputCode(const std::string& prefix) +{ + if (pathwayList != nullptr) + pathwayList->GetSourceOutputCode(parent->GetName()); + return ""; } -string SetPathways::GenerateSourceCodePass1(string roomName, int baseAddress) +void ZSetPathways::ParseRawData() +{ + if (isFromHeader) + segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)); + else + segmentOffset = rawDataIndex; + + if (segmentOffset != 0) + parent->AddDeclarationPlaceholder(segmentOffset); + + int32_t numPaths = (Globals::Instance->game != ZGame::MM_RETAIL) ? + 1 : + zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 8; + + pathwayList = new PathwayList(parent, rawData, segmentOffset, numPaths); +} + +string ZSetPathways::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) +{ + ParseRawData(); + return ""; +} + +string ZSetPathways::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) +{ + string sourceOutput = ""; + + sourceOutput += StringHelper::Sprintf("\n\t%s 0, (u32)%sPathway0x%06X\n};", + ZRoomCommand::GenerateSourceCodePass1("", 0).c_str(), + parent->GetName().c_str(), segmentOffset); + + if (pathwayList != nullptr) + pathwayList->GetSourceOutputCode(parent->GetName()); + + return sourceOutput; +} + +size_t ZSetPathways::GetRawDataSize() +{ + size_t size = 0; + if (pathwayList != nullptr) + size += pathwayList->GetRawDataSize(); + + return ZRoomCommand::GetRawDataSize() + size; +} + +string ZSetPathways::GenerateExterns() +{ + if (pathwayList != nullptr) + return pathwayList->GenerateExterns(parent->GetName()); + + return ""; +} + +string ZSetPathways::GetCommandCName() +{ + return "SCmdPathList"; +} + +RoomCommand ZSetPathways::GetRoomCommand() +{ + return RoomCommand::SetPathways; +} + +PathwayEntry::PathwayEntry(std::vector rawData, uint32_t rawDataIndex) + : numPoints(rawData[rawDataIndex + 0]), unk1(rawData[rawDataIndex + 1]), + unk2(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), + listSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))) { - // int numPathsReal = zRoom->GetDeclarationSizeFromNeighbor(listSegmentOffset) / 6; uint32_t currentPtr = listSegmentOffset; + uint8_t* data = rawData.data(); - uint8_t* data = _rawData.data(); - - for (int i = 0; i < numPoints; i++) + for (int32_t i = 0; i < numPoints; i++) { - PathwayEntry* entry = new PathwayEntry(); - entry->x = BitConverter::ToInt16BE(data, currentPtr + 0); - entry->y = BitConverter::ToInt16BE(data, currentPtr + 2); - entry->z = BitConverter::ToInt16BE(data, currentPtr + 4); + x = BitConverter::ToInt16BE(data, currentPtr + 0); + y = BitConverter::ToInt16BE(data, currentPtr + 2); + z = BitConverter::ToInt16BE(data, currentPtr + 4); - pathways.push_back(entry); + Vec3s point = Vec3s(x, y, z); + points.push_back(point); currentPtr += 6; } if (numPoints == 0) // Hack for SharpOcarina { - for (int i = 0; i < 3; i++) + for (int32_t i = 0; i < 3; i++) { - PathwayEntry* entry = new PathwayEntry(); - pathways.push_back(entry); + Vec3s point = Vec3s(0, 0, 0); + points.push_back(point); } } - - return ""; } -string SetPathways::GenerateSourceCodePass2(string roomName, int baseAddress) +PathwayList::PathwayList(ZFile* nParent, std::vector rawData, uint32_t rawDataIndex, int32_t length) { - string sourceOutput = ""; + parent = nParent; + _rawDataIndex = rawDataIndex; - sourceOutput += - StringHelper::Sprintf("%s 0, (u32)&%sPathway0x%06X };", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), - roomName.c_str(), segmentOffset); + uint32_t currentPtr = rawDataIndex; + for (int32_t pathIndex = 0; pathIndex < length; pathIndex++) { - string declaration = StringHelper::Sprintf("%i, (u32)%sPathwayList0x%06X", numPoints, - roomName.c_str(), listSegmentOffset); + PathwayEntry* path = new PathwayEntry(rawData, currentPtr); + currentPtr += 8; - zRoom->parent->AddDeclaration( - segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, 8, "Path", - StringHelper::Sprintf("%sPathway0x%06X", roomName.c_str(), segmentOffset), declaration); + if (path->listSegmentOffset == 0) + break; + + pathways.push_back(path); } +} +PathwayList::~PathwayList() +{ + for (PathwayEntry* path : pathways) + delete path; +} + +void PathwayList::GetSourceOutputCode(const std::string& prefix) +{ { string declaration = ""; - size_t index = 0; for (PathwayEntry* entry : pathways) { - declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", entry->x, entry->y, - entry->z, listSegmentOffset + (index * 6)); + if (Globals::Instance->game == ZGame::MM_RETAIL) + declaration += StringHelper::Sprintf(" { %i, %i, %i, (u32)%sPathwayList0x%06X },", + entry->numPoints, entry->unk1, entry->unk2, + prefix.c_str(), entry->listSegmentOffset); + else + declaration += + StringHelper::Sprintf(" { %i, (u32)%sPathwayList0x%06X },", entry->numPoints, + prefix.c_str(), entry->listSegmentOffset); if (index < pathways.size() - 1) declaration += "\n"; @@ -103,40 +185,57 @@ string SetPathways::GenerateSourceCodePass2(string roomName, int baseAddress) index++; } - zRoom->parent->AddDeclarationArray( - listSegmentOffset, DeclarationAlignment::None, DeclarationPadding::None, - pathways.size() * 6, "Vec3s", - StringHelper::Sprintf("%sPathwayList0x%06X", roomName.c_str(), listSegmentOffset), + parent->AddDeclarationArray( + _rawDataIndex, DeclarationAlignment::None, DeclarationPadding::None, + pathways.size() * 8, "Path", + StringHelper::Sprintf("%sPathway0x%06X", prefix.c_str(), _rawDataIndex), pathways.size(), declaration); } - return sourceOutput; + for (PathwayEntry* entry : pathways) + { + string declaration = ""; + + size_t index = 0; + for (Vec3s& point : entry->points) + { + declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", point.x, point.y, + point.z, entry->listSegmentOffset + (index * 6)); + + if (index < entry->points.size() - 1) + declaration += "\n"; + + index++; + } + + parent->AddDeclarationArray( + entry->listSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::Pad4, + entry->points.size() * 6, "Vec3s", + StringHelper::Sprintf("%sPathwayList0x%06X", prefix.c_str(), entry->listSegmentOffset), + entry->points.size(), declaration); + } } -int32_t SetPathways::GetRawDataSize() +size_t PathwayList::GetRawDataSize() { - return ZRoomCommand::GetRawDataSize() + (pathways.size() * 6); + size_t pointsSize = 0; + + for (PathwayEntry* entry : pathways) + { + pointsSize += entry->points.size() * 6; + } + + return pathways.size() * 8 + pointsSize; } -string SetPathways::GenerateExterns() +string PathwayList::GenerateExterns(const std::string& prefix) { - return StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n", zRoom->GetName().c_str(), - segmentOffset); -} + string declaration = ""; + for (PathwayEntry* entry : pathways) + { + declaration += StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n", + prefix.c_str(), entry->listSegmentOffset); + } -string SetPathways::GetCommandCName() -{ - return "SCmdPathList"; -} - -RoomCommand SetPathways::GetRoomCommand() -{ - return RoomCommand::SetPathways; -} - -PathwayEntry::PathwayEntry() -{ - x = 0; - y = 0; - z = 0; + return declaration; } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.h index 7c085fbf2c..4468fe9114 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.h @@ -2,35 +2,61 @@ #include "../../Vec3s.h" #include "../ZRoomCommand.h" +#include "ZResource.h" class PathwayEntry { public: int16_t x, y, z; - PathwayEntry(); + PathwayEntry(std::vector rawData, uint32_t rawDataIndex); + + int32_t numPoints; + int8_t unk1; // (MM Only) + int16_t unk2; // (MM Only) + uint32_t listSegmentOffset; + std::vector points; }; -class SetPathways : public ZRoomCommand +struct PathwayList { public: - SetPathways(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); - ~SetPathways(); + PathwayList(ZFile* nParent, std::vector rawData, uint32_t rawDataIndex, int32_t length); + ~PathwayList(); - std::string GetSourceOutputCode(std::string prefix); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - virtual RoomCommand GetRoomCommand(); - virtual int32_t GetRawDataSize(); - virtual std::string GetCommandCName(); - virtual std::string GenerateExterns(); - void InitList(uint32_t address); + void GetSourceOutputCode(const std::string& prefix) ; + size_t GetRawDataSize(); + std::string GenerateExterns(const std::string& prefix); + +private: + ZFile* parent; + std::vector pathways; + std::vector _rawData; + uint32_t _rawDataIndex; +}; + +class ZSetPathways : public ZResource, public ZRoomCommand +{ +public: + ZSetPathways(ZFile* nParent); + ZSetPathways(ZRoom* nZRoom, const std::vector& nRawData, uint32_t nRawDataIndex, + bool nIsFromHeader); + ~ZSetPathways(); + + void ParseRawData() override; + + void DeclareVar(const std::string& prefix, const std::string& bodyStr); + std::string GetSourceOutputCode(const std::string& prefix) override; + + std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + RoomCommand GetRoomCommand() override; + size_t GetRawDataSize() override; + std::string GetCommandCName() override; + std::string GenerateExterns() override; private: uint32_t segmentOffset; - uint32_t listSegmentOffset; - int numPoints; - std::vector pathways; - std::vector _rawData; - int _rawDataIndex; + PathwayList* pathwayList; + bool isFromHeader = false; }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.cpp index 1ae7ae5652..fc9c852a98 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.cpp @@ -4,14 +4,14 @@ using namespace std; -SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { gameplayFlags = rawData[rawDataIndex + 0x01]; gameplayFlags2 = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x04); } -string SetRoomBehavior::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetRoomBehavior::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.h index 9f21662d48..9f89580d29 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomBehavior.h @@ -5,11 +5,11 @@ class SetRoomBehavior : public ZRoomCommand { public: - SetRoomBehavior(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetRoomBehavior(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: uint8_t gameplayFlags; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp index 823ca9a408..38e651472f 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp @@ -7,23 +7,25 @@ using namespace std; -SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { - int numRooms = rawData[rawDataIndex + 1]; + int32_t numRooms = rawData[rawDataIndex + 1]; segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; rooms = vector(); int32_t currentPtr = segmentOffset; - for (int i = 0; i < numRooms; i++) + for (int32_t i = 0; i < numRooms; i++) { RoomEntry* entry = new RoomEntry(rawData, currentPtr); rooms.push_back(entry); currentPtr += 8; } + + zRoom->roomCount = numRooms; } SetRoomList::~SetRoomList() @@ -32,7 +34,7 @@ SetRoomList::~SetRoomList() delete entry; } -string SetRoomList::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetRoomList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x%02X, (u32)&%sRoomList0x%06X", @@ -40,7 +42,7 @@ string SetRoomList::GenerateSourceCodePass1(string roomName, int baseAddress) zRoom->GetName().c_str(), segmentOffset); } -string SetRoomList::GenerateSourceCodePass2(string roomName, int baseAddress) +string SetRoomList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) { return ""; } @@ -72,9 +74,9 @@ std::string SetRoomList::PreGenSourceFiles() if (res->GetResourceType() == ZResourceType::Room && res != zRoom) { string roomName = res->GetName(); - declaration += - StringHelper::Sprintf("\t{ (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n", - roomName.c_str(), roomName.c_str()); + declaration += StringHelper::Sprintf( + " { (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n", roomName.c_str(), + roomName.c_str()); } } } @@ -98,7 +100,7 @@ RoomEntry::RoomEntry(int32_t nVAS, int32_t nVAE) virtualAddressEnd = nVAE; } -RoomEntry::RoomEntry(std::vector rawData, int rawDataIndex) +RoomEntry::RoomEntry(std::vector rawData, uint32_t rawDataIndex) : RoomEntry(BitConverter::ToInt32BE(rawData, rawDataIndex + 0), BitConverter::ToInt32BE(rawData, rawDataIndex + 4)) { diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.h index 604d852372..f198c2f5d5 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.h @@ -9,22 +9,22 @@ public: int32_t virtualAddressEnd; RoomEntry(int32_t nVAS, int32_t nVAE); - RoomEntry(std::vector rawData, int rawDataIndex); + RoomEntry(std::vector rawData, uint32_t rawDataIndex); }; class SetRoomList : public ZRoomCommand { public: - SetRoomList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetRoomList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); ~SetRoomList(); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual std::string GenerateExterns(); - virtual RoomCommand GetRoomCommand(); - virtual std::string PreGenSourceFiles(); - virtual std::string Save(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; + virtual RoomCommand GetRoomCommand() override; + virtual std::string PreGenSourceFiles() override; + virtual std::string Save() override; private: std::vector rooms; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.cpp index a0d03c3155..a5007818d2 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.cpp @@ -3,14 +3,14 @@ using namespace std; -SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { disableSky = rawData[rawDataIndex + 0x04]; disableSunMoon = rawData[rawDataIndex + 0x05]; } -string SetSkyboxModifier::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetSkyboxModifier::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0, 0, 0, 0x%02X, 0x%02X", diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.h index 9d4262fcbb..9306387757 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxModifier.h @@ -5,11 +5,11 @@ class SetSkyboxModifier : public ZRoomCommand { public: - SetSkyboxModifier(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetSkyboxModifier(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: uint8_t disableSky; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp index f5c05e682d..ddbe77a8ca 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.cpp @@ -1,21 +1,23 @@ #include "SetSkyboxSettings.h" +#include "../../Globals.h" #include "../../StringHelper.h" using namespace std; -SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { + unk1 = rawData[rawDataIndex + 0x01]; skyboxNumber = rawData[rawDataIndex + 0x04]; cloudsType = rawData[rawDataIndex + 0x05]; lightingSettingsControl = rawData[rawDataIndex + 0x06]; } -string SetSkyboxSettings::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetSkyboxSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( - "%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X", - ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), skyboxNumber, + "%s 0x%02X, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X", + ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), unk1, skyboxNumber, cloudsType, lightingSettingsControl); } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.h index de23c2a88a..c54cbe9f55 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSkyboxSettings.h @@ -5,13 +5,14 @@ class SetSkyboxSettings : public ZRoomCommand { public: - SetSkyboxSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetSkyboxSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: + uint8_t unk1; // (MM Only) uint8_t skyboxNumber; uint8_t cloudsType; uint8_t lightingSettingsControl; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.cpp index 4668060f90..e1552704bd 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.cpp @@ -3,7 +3,7 @@ using namespace std; -SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { reverb = rawData[rawDataIndex + 0x01]; @@ -11,7 +11,7 @@ SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector rawData, musicSequence = rawData[rawDataIndex + 0x07]; } -string SetSoundSettings::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetSoundSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x%02X, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X", diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.h index 78851affde..24e7168312 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSoundSettings.h @@ -5,11 +5,11 @@ class SetSoundSettings : public ZRoomCommand { public: - SetSoundSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetSoundSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: uint8_t reverb; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp index fccd1bacab..3cbe25219e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp @@ -4,14 +4,14 @@ using namespace std; -SetSpecialObjects::SetSpecialObjects(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetSpecialObjects::SetSpecialObjects(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { elfMessage = rawData[rawDataIndex + 0x01]; globalObject = BitConverter::ToInt16BE(rawData, rawDataIndex + 6); } -string SetSpecialObjects::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetSpecialObjects::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x%02X, 0x%04X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.h index c455fd8e5a..16f0398f97 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.h @@ -5,11 +5,11 @@ class SetSpecialObjects : public ZRoomCommand { public: - SetSpecialObjects(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetSpecialObjects(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: uint8_t elfMessage; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.cpp index be9bb8219a..7d29e232cf 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.cpp @@ -1,14 +1,15 @@ #include "SetStartPositionList.h" #include "../../BitConverter.h" +#include "../../Globals.h" #include "../../StringHelper.h" #include "../../ZFile.h" -#include "../ActorList.h" +#include "../ZNames.h" #include "../ZRoom.h" using namespace std; SetStartPositionList::SetStartPositionList(ZRoom* nZRoom, std::vector rawData, - int rawDataIndex) + uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { uint8_t numActors = rawData[rawDataIndex + 1]; @@ -21,7 +22,7 @@ SetStartPositionList::SetStartPositionList(ZRoom* nZRoom, std::vector r uint32_t currentPtr = segmentOffset; - for (int i = 0; i < numActors; i++) + for (int32_t i = 0; i < numActors; i++) { actors.push_back(new ActorSpawnEntry(rawData, currentPtr)); currentPtr += 16; @@ -34,7 +35,7 @@ SetStartPositionList::~SetStartPositionList() delete entry; } -string SetStartPositionList::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetStartPositionList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { string sourceOutput = ""; @@ -47,10 +48,10 @@ string SetStartPositionList::GenerateSourceCodePass1(string roomName, int baseAd for (ActorSpawnEntry* entry : actors) { - declaration += StringHelper::Sprintf("\t{ %s, %i, %i, %i, %i, %i, %i, 0x%04X },\n", - ActorList[entry->actorNum].c_str(), entry->posX, - entry->posY, entry->posZ, entry->rotX, entry->rotY, - entry->rotZ, entry->initVar); + declaration += StringHelper::Sprintf(" { %s, %i, %i, %i, %i, %i, %i, 0x%04X },\n", + ZNames::GetActorName(entry->actorNum).c_str(), + entry->posX, entry->posY, entry->posZ, entry->rotX, + entry->rotY, entry->rotZ, entry->initVar); } zRoom->parent->AddDeclarationArray( @@ -61,7 +62,7 @@ string SetStartPositionList::GenerateSourceCodePass1(string roomName, int baseAd return sourceOutput; } -string SetStartPositionList::GenerateSourceCodePass2(string roomName, int baseAddress) +string SetStartPositionList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) { return ""; } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.h index 9452ca3db2..414cc3e01f 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetStartPositionList.h @@ -8,14 +8,14 @@ class SetStartPositionList : public ZRoomCommand public: std::vector actors; - SetStartPositionList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetStartPositionList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); ~SetStartPositionList(); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual std::string GenerateExterns(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; + virtual RoomCommand GetRoomCommand() override; private: uint32_t segmentOffset; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.cpp index 6e3272d71d..0f5d449898 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.cpp @@ -4,7 +4,7 @@ using namespace std; -SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { hour = rawData[rawDataIndex + 4]; @@ -12,7 +12,7 @@ SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector rawData, in unk = rawData[rawDataIndex + 6]; } -string SetTimeSettings::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetTimeSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X", diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.h index de5c3bcee5..f1104f2762 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTimeSettings.h @@ -5,11 +5,11 @@ class SetTimeSettings : public ZRoomCommand { public: - SetTimeSettings(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetTimeSettings(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: // uint16_t time; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp index f73664050b..42f53f76e9 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.cpp @@ -1,24 +1,25 @@ #include "SetTransitionActorList.h" #include "../../BitConverter.h" +#include "../../Globals.h" #include "../../StringHelper.h" #include "../../ZFile.h" -#include "../ActorList.h" +#include "../ZNames.h" #include "../ZRoom.h" using namespace std; SetTransitionActorList::SetTransitionActorList(ZRoom* nZRoom, std::vector rawData, - int rawDataIndex) + uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { - int numActors = rawData[rawDataIndex + 1]; + int32_t numActors = rawData[rawDataIndex + 1]; segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF; transitionActors = vector(); uint32_t currentPtr = segmentOffset; - for (int i = 0; i < numActors; i++) + for (int32_t i = 0; i < numActors; i++) { TransitionActorEntry* entry = new TransitionActorEntry(rawData, currentPtr); transitionActors.push_back(entry); @@ -38,7 +39,7 @@ string SetTransitionActorList::GetSourceOutputCode(std::string prefix) return ""; } -string SetTransitionActorList::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetTransitionActorList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { string sourceOutput = StringHelper::Sprintf("%s 0x%02X, (u32)%sTransitionActorList0x%06X", @@ -48,18 +49,13 @@ string SetTransitionActorList::GenerateSourceCodePass1(string roomName, int base for (TransitionActorEntry* entry : transitionActors) { - string actorStr = ""; + string actorStr = ZNames::GetActorName(entry->actorNum); - if (entry->actorNum < sizeof(ActorList) / sizeof(ActorList[0])) - actorStr = ActorList[entry->actorNum]; - else - actorStr = StringHelper::Sprintf("0x%04X", entry->actorNum); - - declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %s, %i, %i, %i, %i, 0x%04X }, \n", - entry->frontObjectRoom, entry->frontTransitionReaction, - entry->backObjectRoom, entry->backTransitionReaction, - actorStr.c_str(), entry->posX, entry->posY, - entry->posZ, entry->rotY, (uint16_t)entry->initVar); + declaration += StringHelper::Sprintf( + " { %i, %i, %i, %i, %s, %i, %i, %i, %i, 0x%04X }, \n", entry->frontObjectRoom, + entry->frontTransitionReaction, entry->backObjectRoom, entry->backTransitionReaction, + actorStr.c_str(), entry->posX, entry->posY, entry->posZ, entry->rotY, + (uint16_t)entry->initVar); } zRoom->parent->AddDeclarationArray( @@ -71,12 +67,12 @@ string SetTransitionActorList::GenerateSourceCodePass1(string roomName, int base return sourceOutput; } -string SetTransitionActorList::GenerateSourceCodePass2(string roomName, int baseAddress) +string SetTransitionActorList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) { return ""; } -int32_t SetTransitionActorList::GetRawDataSize() +size_t SetTransitionActorList::GetRawDataSize() { return ZRoomCommand::GetRawDataSize() + (transitionActors.size() * 16); } @@ -97,7 +93,7 @@ RoomCommand SetTransitionActorList::GetRoomCommand() return RoomCommand::SetTransitionActorList; } -TransitionActorEntry::TransitionActorEntry(std::vector rawData, int rawDataIndex) +TransitionActorEntry::TransitionActorEntry(std::vector rawData, uint32_t rawDataIndex) { frontObjectRoom = rawData[rawDataIndex + 0]; frontTransitionReaction = rawData[rawDataIndex + 1]; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.h index d21b6ca00e..d976ac1c4b 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetTransitionActorList.h @@ -14,22 +14,22 @@ public: int16_t rotY; uint16_t initVar; - TransitionActorEntry(std::vector rawData, int rawDataIndex); + TransitionActorEntry(std::vector rawData, uint32_t rawDataIndex); }; class SetTransitionActorList : public ZRoomCommand { public: - SetTransitionActorList(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetTransitionActorList(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); ~SetTransitionActorList(); std::string GetSourceOutputCode(std::string prefix); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - virtual RoomCommand GetRoomCommand(); - virtual int32_t GetRawDataSize(); - virtual std::string GetCommandCName(); - virtual std::string GenerateExterns(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + virtual RoomCommand GetRoomCommand() override; + virtual size_t GetRawDataSize() override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; private: std::vector transitionActors; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.cpp index 8efbbbc83f..a82a99dafe 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.cpp @@ -3,7 +3,7 @@ using namespace std; -SetWind::SetWind(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +SetWind::SetWind(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { windWest = rawData[rawDataIndex + 0x04]; @@ -12,7 +12,7 @@ SetWind::SetWind(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) clothFlappingStrength = rawData[rawDataIndex + 0x07]; } -string SetWind::GenerateSourceCodePass1(string roomName, int baseAddress) +string SetWind::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X, 0x%02X", diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.h index b7ab2169ea..a1c152cde9 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWind.h @@ -5,11 +5,11 @@ class SetWind : public ZRoomCommand { public: - SetWind(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + SetWind(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: uint8_t windWest; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp new file mode 100644 index 0000000000..cfd994bfb3 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp @@ -0,0 +1,26 @@ +#include "SetWorldMapVisited.h" +#include "../../StringHelper.h" + +using namespace std; + +SetWorldMapVisited::SetWorldMapVisited(ZRoom* nZRoom, std::vector rawData, + uint32_t rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) +{ +} + +string SetWorldMapVisited::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) +{ + return StringHelper::Sprintf( + "%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str()); +} + +string SetWorldMapVisited::GetCommandCName() +{ + return "SCmdWorldMapVisited"; +} + +RoomCommand SetWorldMapVisited::GetRoomCommand() +{ + return RoomCommand::SetWorldMapVisited; +} \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetWorldMapVisited.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWorldMapVisited.h new file mode 100644 index 0000000000..e0546c3863 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWorldMapVisited.h @@ -0,0 +1,15 @@ +#pragma once + +#include "../ZRoomCommand.h" + +class SetWorldMapVisited : public ZRoomCommand +{ +public: + SetWorldMapVisited(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); + + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; + +private: +}; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.cpp index 9dc014d4cf..9bd0f96c99 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.cpp @@ -3,12 +3,12 @@ using namespace std; -Unused09::Unused09(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +Unused09::Unused09(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { } -string Unused09::GenerateSourceCodePass1(string roomName, int baseAddress) +string Unused09::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf( "%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str()); diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.h b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.h index 4a4ee4840b..172ed3cc57 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused09.h @@ -5,11 +5,11 @@ class Unused09 : public ZRoomCommand { public: - Unused09(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + Unused09(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GetCommandCName(); - virtual RoomCommand GetRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; private: }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/Unused1D.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused1D.cpp new file mode 100644 index 0000000000..501a5a8333 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused1D.cpp @@ -0,0 +1,25 @@ +#include "Unused1D.h" +#include "../../StringHelper.h" + +using namespace std; + +Unused1D::Unused1D(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) + : ZRoomCommand(nZRoom, rawData, rawDataIndex) +{ +} + +string Unused1D::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) +{ + return StringHelper::Sprintf( + "%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str()); +} + +string Unused1D::GetCommandCName() +{ + return "SCmdBase"; +} + +RoomCommand Unused1D::GetRoomCommand() +{ + return RoomCommand::Unused1D; +} \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/Unused1D.h b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused1D.h new file mode 100644 index 0000000000..6256e42e79 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/Unused1D.h @@ -0,0 +1,15 @@ +#pragma once + +#include "../ZRoomCommand.h" + +class Unused1D : public ZRoomCommand +{ +public: + Unused1D(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); + + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GetCommandCName() override; + virtual RoomCommand GetRoomCommand() override; + +private: +}; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.cpp index c256b26ed6..a57fd188fc 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.cpp @@ -4,7 +4,7 @@ using namespace std; -ZRoomCommandUnk::ZRoomCommandUnk(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +ZRoomCommandUnk::ZRoomCommandUnk(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex) { cmdID = (RoomCommand)rawData[rawDataIndex]; @@ -15,7 +15,7 @@ ZRoomCommandUnk::ZRoomCommandUnk(ZRoom* nZRoom, std::vector rawData, in data2 = BitConverter::ToInt32BE(rawData, rawDataIndex + 4); } -string ZRoomCommandUnk::GenerateSourceCodePass1(string roomName, int baseAddress) +string ZRoomCommandUnk::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) { return StringHelper::Sprintf("%s %sSet%04XCmd%02X = { 0x%02X, 0x%02X, 0x%06X }; /* WARNING: " "UNIMPLEMENTED ROOM COMMAND */", @@ -23,7 +23,7 @@ string ZRoomCommandUnk::GenerateSourceCodePass1(string roomName, int baseAddress cmdID, data1, data2); } -string ZRoomCommandUnk::GenerateSourceCodePass2(string roomName, int baseAddress) +string ZRoomCommandUnk::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) { return ""; } @@ -38,7 +38,7 @@ string ZRoomCommandUnk::GenerateExterns() return ""; } -int32_t ZRoomCommandUnk::GetRawDataSize() +size_t ZRoomCommandUnk::GetRawDataSize() { return 8; } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.h b/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.h index 53e0929340..a1877e6ac0 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/ZRoomCommandUnk.h @@ -12,15 +12,15 @@ public: uint8_t data1; uint32_t data2; - ZRoomCommandUnk(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); + ZRoomCommandUnk(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass3(std::string roomName); - virtual RoomCommand GetRoomCommand(); - virtual int32_t GetRawDataSize(); - virtual std::string GetCommandCName(); - virtual std::string GenerateExterns(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override; + virtual std::string GenerateSourceCodePass3(std::string roomName) override; + virtual RoomCommand GetRoomCommand() override; + virtual size_t GetRawDataSize() override; + virtual std::string GetCommandCName() override; + virtual std::string GenerateExterns() override; protected: ZRoom* zRoom; diff --git a/tools/ZAPD/ZAPD/ZRoom/ObjectList.h b/tools/ZAPD/ZAPD/ZRoom/ObjectList.h deleted file mode 100644 index 5b40cada52..0000000000 --- a/tools/ZAPD/ZAPD/ZRoom/ObjectList.h +++ /dev/null @@ -1,408 +0,0 @@ -#pragma once - -#include - -static const std::string ObjectList[] = { - /* 0x0000 */ "OBJECT_UNSET_0", - /* 0x0001 */ "OBJECT_GAMEPLAY_KEEP", - /* 0x0002 */ "OBJECT_GAMEPLAY_FIELD_KEEP", - /* 0x0003 */ "OBJECT_GAMEPLAY_DANGEON_KEEP", - /* 0x0004 */ "OBJECT_UNSET_4", - /* 0x0005 */ "OBJECT_UNSET_5", - /* 0x0006 */ "OBJECT_HUMAN", - /* 0x0007 */ "OBJECT_OKUTA", - /* 0x0008 */ "OBJECT_CROW", - /* 0x0009 */ "OBJECT_POH", - /* 0x000A */ "OBJECT_DY_OBJ", - /* 0x000B */ "OBJECT_WALLMASTER", - /* 0x000C */ "OBJECT_DODONGO", - /* 0x000D */ "OBJECT_FIREFLY", - /* 0x000E */ "OBJECT_BOX", - /* 0x000F */ "OBJECT_FIRE", - /* 0x0010 */ "OBJECT_UNSET_10", - /* 0x0011 */ "OBJECT_UNSET_11", - /* 0x0012 */ "OBJECT_BUBBLE", - /* 0x0013 */ "OBJECT_NIW", - /* 0x0014 */ "OBJECT_LINK_BOY", - /* 0x0015 */ "OBJECT_LINK_CHILD", - /* 0x0016 */ "OBJECT_TITE", - /* 0x0017 */ "OBJECT_REEBA", - /* 0x0018 */ "OBJECT_PEEHAT", - /* 0x0019 */ "OBJECT_KINGDODONGO", - /* 0x001A */ "OBJECT_HORSE", - /* 0x001B */ "OBJECT_ZF", - /* 0x001C */ "OBJECT_GOMA", - /* 0x001D */ "OBJECT_ZL1", - /* 0x001E */ "OBJECT_GOL", - /* 0x001F */ "OBJECT_DODOJR", - /* 0x0020 */ "OBJECT_TORCH2", - /* 0x0021 */ "OBJECT_BL", - /* 0x0022 */ "OBJECT_TP", - /* 0x0023 */ "OBJECT_OA1", - /* 0x0024 */ "OBJECT_ST", - /* 0x0025 */ "OBJECT_BW", - /* 0x0026 */ "OBJECT_EI", - /* 0x0027 */ "OBJECT_HORSE_NORMAL", - /* 0x0028 */ "OBJECT_OB1", - /* 0x0029 */ "OBJECT_O_ANIME", - /* 0x002A */ "OBJECT_SPOT04_OBJECTS", - /* 0x002B */ "OBJECT_DDAN_OBJECTS", - /* 0x002C */ "OBJECT_HIDAN_OBJECTS", - /* 0x002D */ "OBJECT_HORSE_GANON", - /* 0x002E */ "OBJECT_OA2", - /* 0x002F */ "OBJECT_SPOT00_OBJECTS", - /* 0x0030 */ "OBJECT_MB", - /* 0x0031 */ "OBJECT_BOMBF", - /* 0x0032 */ "OBJECT_SK2", - /* 0x0033 */ "OBJECT_OE1", - /* 0x0034 */ "OBJECT_OE_ANIME", - /* 0x0035 */ "OBJECT_OE2", - /* 0x0036 */ "OBJECT_YDAN_OBJECTS", - /* 0x0037 */ "OBJECT_GND", - /* 0x0038 */ "OBJECT_AM", - /* 0x0039 */ "OBJECT_DEKUBABA", - /* 0x003A */ "OBJECT_UNSET_3A", - /* 0x003B */ "OBJECT_OA3", - /* 0x003C */ "OBJECT_OA4", - /* 0x003D */ "OBJECT_OA5", - /* 0x003E */ "OBJECT_OA6", - /* 0x003F */ "OBJECT_OA7", - /* 0x0040 */ "OBJECT_JJ", - /* 0x0041 */ "OBJECT_OA8", - /* 0x0042 */ "OBJECT_OA9", - /* 0x0043 */ "OBJECT_OB2", - /* 0x0044 */ "OBJECT_OB3", - /* 0x0045 */ "OBJECT_OB4", - /* 0x0046 */ "OBJECT_HORSE_ZELDA", - /* 0x0047 */ "OBJECT_OPENING_DEMO1", - /* 0x0048 */ "OBJECT_WARP1", - /* 0x0049 */ "OBJECT_B_HEART", - /* 0x004A */ "OBJECT_DEKUNUTS", - /* 0x004B */ "OBJECT_OE3", - /* 0x004C */ "OBJECT_OE4", - /* 0x004D */ "OBJECT_MENKURI_OBJECTS", - /* 0x004E */ "OBJECT_OE5", - /* 0x004F */ "OBJECT_OE6", - /* 0x0050 */ "OBJECT_OE7", - /* 0x0051 */ "OBJECT_OE8", - /* 0x0052 */ "OBJECT_OE9", - /* 0x0053 */ "OBJECT_OE10", - /* 0x0054 */ "OBJECT_OE11", - /* 0x0055 */ "OBJECT_OE12", - /* 0x0056 */ "OBJECT_VALI", - /* 0x0057 */ "OBJECT_OA10", - /* 0x0058 */ "OBJECT_OA11", - /* 0x0059 */ "OBJECT_MIZU_OBJECTS", - /* 0x005A */ "OBJECT_FHG", - /* 0x005B */ "OBJECT_OSSAN", - /* 0x005C */ "OBJECT_MORI_HINERI1", - /* 0x005D */ "OBJECT_BB", - /* 0x005E */ "OBJECT_TOKI_OBJECTS", - /* 0x005F */ "OBJECT_YUKABYUN", - /* 0x0060 */ "OBJECT_ZL2", - /* 0x0061 */ "OBJECT_MJIN", - /* 0x0062 */ "OBJECT_MJIN_FLASH", - /* 0x0063 */ "OBJECT_MJIN_DARK", - /* 0x0064 */ "OBJECT_MJIN_FLAME", - /* 0x0065 */ "OBJECT_MJIN_ICE", - /* 0x0066 */ "OBJECT_MJIN_SOUL", - /* 0x0067 */ "OBJECT_MJIN_WIND", - /* 0x0068 */ "OBJECT_MJIN_OKA", - /* 0x0069 */ "OBJECT_HAKA_OBJECTS", - /* 0x006A */ "OBJECT_SPOT06_OBJECTS", - /* 0x006B */ "OBJECT_ICE_OBJECTS", - /* 0x006C */ "OBJECT_RELAY_OBJECTS", - /* 0x006D */ "OBJECT_PO_FIELD", - /* 0x006E */ "OBJECT_PO_COMPOSER", - /* 0x006F */ "OBJECT_MORI_HINERI1A", - /* 0x0070 */ "OBJECT_MORI_HINERI2", - /* 0x0071 */ "OBJECT_MORI_HINERI2A", - /* 0x0072 */ "OBJECT_MORI_OBJECTS", - /* 0x0073 */ "OBJECT_MORI_TEX", - /* 0x0074 */ "OBJECT_SPOT08_OBJ", - /* 0x0075 */ "OBJECT_WARP2", - /* 0x0076 */ "OBJECT_HATA", - /* 0x0077 */ "OBJECT_BIRD", - /* 0x0078 */ "OBJECT_UNSET_78", - /* 0x0079 */ "OBJECT_UNSET_79", - /* 0x007A */ "OBJECT_UNSET_7A", - /* 0x007B */ "OBJECT_UNSET_7B", - /* 0x007C */ "OBJECT_WOOD02", - /* 0x007D */ "OBJECT_UNSET_7D", - /* 0x007E */ "OBJECT_UNSET_7E", - /* 0x007F */ "OBJECT_UNSET_7F", - /* 0x0080 */ "OBJECT_UNSET_80", - /* 0x0081 */ "OBJECT_LIGHTBOX", - /* 0x0082 */ "OBJECT_PU_BOX", - /* 0x0083 */ "OBJECT_UNSET_83", - /* 0x0084 */ "OBJECT_UNSET_84", - /* 0x0085 */ "OBJECT_TRAP", - /* 0x0086 */ "OBJECT_VASE", - /* 0x0087 */ "OBJECT_IM", - /* 0x0088 */ "OBJECT_TA", - /* 0x0089 */ "OBJECT_TK", - /* 0x008A */ "OBJECT_XC", - /* 0x008B */ "OBJECT_VM", - /* 0x008C */ "OBJECT_BV", - /* 0x008D */ "OBJECT_HAKACH_OBJECTS", - /* 0x008E */ "OBJECT_EFC_CRYSTAL_LIGHT", - /* 0x008F */ "OBJECT_EFC_FIRE_BALL", - /* 0x0090 */ "OBJECT_EFC_FLASH", - /* 0x0091 */ "OBJECT_EFC_LGT_SHOWER", - /* 0x0092 */ "OBJECT_EFC_STAR_FIELD", - /* 0x0093 */ "OBJECT_GOD_LGT", - /* 0x0094 */ "OBJECT_LIGHT_RING", - /* 0x0095 */ "OBJECT_TRIFORCE_SPOT", - /* 0x0096 */ "OBJECT_BDAN_OBJECTS", - /* 0x0097 */ "OBJECT_SD", - /* 0x0098 */ "OBJECT_RD", - /* 0x0099 */ "OBJECT_PO_SISTERS", - /* 0x009A */ "OBJECT_HEAVY_OBJECT", - /* 0x009B */ "OBJECT_GNDD", - /* 0x009C */ "OBJECT_FD", - /* 0x009D */ "OBJECT_DU", - /* 0x009E */ "OBJECT_FW", - /* 0x009F */ "OBJECT_MEDAL", - /* 0x00A0 */ "OBJECT_HORSE_LINK_CHILD", - /* 0x00A1 */ "OBJECT_SPOT02_OBJECTS", - /* 0x00A2 */ "OBJECT_HAKA", - /* 0x00A3 */ "OBJECT_RU1", - /* 0x00A4 */ "OBJECT_SYOKUDAI", - /* 0x00A5 */ "OBJECT_FD2", - /* 0x00A6 */ "OBJECT_DH", - /* 0x00A7 */ "OBJECT_RL", - /* 0x00A8 */ "OBJECT_EFC_TW", - /* 0x00A9 */ "OBJECT_DEMO_TRE_LGT", - /* 0x00AA */ "OBJECT_GI_KEY", - /* 0x00AB */ "OBJECT_MIR_RAY", - /* 0x00AC */ "OBJECT_BROB", - /* 0x00AD */ "OBJECT_GI_JEWEL", - /* 0x00AE */ "OBJECT_SPOT09_OBJ", - /* 0x00AF */ "OBJECT_SPOT18_OBJ", - /* 0x00B0 */ "OBJECT_BDOOR", - /* 0x00B1 */ "OBJECT_SPOT17_OBJ", - /* 0x00B2 */ "OBJECT_SHOP_DUNGEN", - /* 0x00B3 */ "OBJECT_NB", - /* 0x00B4 */ "OBJECT_MO", - /* 0x00B5 */ "OBJECT_SB", - /* 0x00B6 */ "OBJECT_GI_MELODY", - /* 0x00B7 */ "OBJECT_GI_HEART", - /* 0x00B8 */ "OBJECT_GI_COMPASS", - /* 0x00B9 */ "OBJECT_GI_BOSSKEY", - /* 0x00BA */ "OBJECT_GI_MEDAL", - /* 0x00BB */ "OBJECT_GI_NUTS", - /* 0x00BC */ "OBJECT_SA", - /* 0x00BD */ "OBJECT_GI_HEARTS", - /* 0x00BE */ "OBJECT_GI_ARROWCASE", - /* 0x00BF */ "OBJECT_GI_BOMBPOUCH", - /* 0x00C0 */ "OBJECT_IN", - /* 0x00C1 */ "OBJECT_TR", - /* 0x00C2 */ "OBJECT_SPOT16_OBJ", - /* 0x00C3 */ "OBJECT_OE1S", - /* 0x00C4 */ "OBJECT_OE4S", - /* 0x00C5 */ "OBJECT_OS_ANIME", - /* 0x00C6 */ "OBJECT_GI_BOTTLE", - /* 0x00C7 */ "OBJECT_GI_STICK", - /* 0x00C8 */ "OBJECT_GI_MAP", - /* 0x00C9 */ "OBJECT_OF1D_MAP", - /* 0x00CA */ "OBJECT_RU2", - /* 0x00CB */ "OBJECT_GI_SHIELD_1", - /* 0x00CC */ "OBJECT_DEKUJR", - /* 0x00CD */ "OBJECT_GI_MAGICPOT", - /* 0x00CE */ "OBJECT_GI_BOMB_1", - /* 0x00CF */ "OBJECT_OF1S", - /* 0x00D0 */ "OBJECT_MA2", - /* 0x00D1 */ "OBJECT_GI_PURSE", - /* 0x00D2 */ "OBJECT_HNI", - /* 0x00D3 */ "OBJECT_TW", - /* 0x00D4 */ "OBJECT_RR", - /* 0x00D5 */ "OBJECT_BXA", - /* 0x00D6 */ "OBJECT_ANUBICE", - /* 0x00D7 */ "OBJECT_GI_GERUDO", - /* 0x00D8 */ "OBJECT_GI_ARROW", - /* 0x00D9 */ "OBJECT_GI_BOMB_2", - /* 0x00DA */ "OBJECT_GI_EGG", - /* 0x00DB */ "OBJECT_GI_SCALE", - /* 0x00DC */ "OBJECT_GI_SHIELD_2", - /* 0x00DD */ "OBJECT_GI_HOOKSHOT", - /* 0x00DE */ "OBJECT_GI_OCARINA", - /* 0x00DF */ "OBJECT_GI_MILK", - /* 0x00E0 */ "OBJECT_MA1", - /* 0x00E1 */ "OBJECT_GANON", - /* 0x00E2 */ "OBJECT_SST", - /* 0x00E3 */ "OBJECT_NY_UNUSED", - /* 0x00E4 */ "OBJECT_UNSET_E4", - /* 0x00E5 */ "OBJECT_NY", - /* 0x00E6 */ "OBJECT_FR", - /* 0x00E7 */ "OBJECT_GI_PACHINKO", - /* 0x00E8 */ "OBJECT_GI_BOOMERANG", - /* 0x00E9 */ "OBJECT_GI_BOW", - /* 0x00EA */ "OBJECT_GI_GLASSES", - /* 0x00EB */ "OBJECT_GI_LIQUID", - /* 0x00EC */ "OBJECT_ANI", - /* 0x00ED */ "OBJECT_DEMO_6K", - /* 0x00EE */ "OBJECT_GI_SHIELD_3", - /* 0x00EF */ "OBJECT_GI_LETTER", - /* 0x00F0 */ "OBJECT_SPOT15_OBJ", - /* 0x00F1 */ "OBJECT_JYA_OBJ", - /* 0x00F2 */ "OBJECT_GI_CLOTHES", - /* 0x00F3 */ "OBJECT_GI_BEAN", - /* 0x00F4 */ "OBJECT_GI_FISH", - /* 0x00F5 */ "OBJECT_GI_SAW", - /* 0x00F6 */ "OBJECT_GI_HAMMER", - /* 0x00F7 */ "OBJECT_GI_GRASS", - /* 0x00F8 */ "OBJECT_GI_LONGSWORD", - /* 0x00F9 */ "OBJECT_SPOT01_OBJECTS", - /* 0x00FA */ "OBJECT_MD_UNUSED", - /* 0x00FB */ "OBJECT_MD", - /* 0x00FC */ "OBJECT_KM1", - /* 0x00FD */ "OBJECT_KW1", - /* 0x00FE */ "OBJECT_ZO", - /* 0x00FF */ "OBJECT_KZ", - /* 0x0100 */ "OBJECT_UMAJUMP", - /* 0x0101 */ "OBJECT_MASTERKOKIRI", - /* 0x0102 */ "OBJECT_MASTERKOKIRIHEAD", - /* 0x0103 */ "OBJECT_MASTERGOLON", - /* 0x0104 */ "OBJECT_MASTERZOORA", - /* 0x0105 */ "OBJECT_AOB", - /* 0x0106 */ "OBJECT_IK", - /* 0x0107 */ "OBJECT_AHG", - /* 0x0108 */ "OBJECT_CNE", - /* 0x0109 */ "OBJECT_GI_NIWATORI", - /* 0x010A */ "OBJECT_SKJ", - /* 0x010B */ "OBJECT_GI_BOTTLE_LETTER", - /* 0x010C */ "OBJECT_BJI", - /* 0x010D */ "OBJECT_BBA", - /* 0x010E */ "OBJECT_GI_OCARINA_0", - /* 0x010F */ "OBJECT_DS", - /* 0x0110 */ "OBJECT_ANE", - /* 0x0111 */ "OBJECT_BOJ", - /* 0x0112 */ "OBJECT_SPOT03_OBJECT", - /* 0x0113 */ "OBJECT_SPOT07_OBJECT", - /* 0x0114 */ "OBJECT_FZ", - /* 0x0115 */ "OBJECT_BOB", - /* 0x0116 */ "OBJECT_GE1", - /* 0x0117 */ "OBJECT_YABUSAME_POINT", - /* 0x0118 */ "OBJECT_GI_BOOTS_2", - /* 0x0119 */ "OBJECT_GI_SEED", - /* 0x011A */ "OBJECT_GND_MAGIC", - /* 0x011B */ "OBJECT_D_ELEVATOR", - /* 0x011C */ "OBJECT_D_HSBLOCK", - /* 0x011D */ "OBJECT_D_LIFT", - /* 0x011E */ "OBJECT_MAMENOKI", - /* 0x011F */ "OBJECT_GOROIWA", - /* 0x0120 */ "OBJECT_UNSET_120", - /* 0x0121 */ "OBJECT_TORYO", - /* 0x0122 */ "OBJECT_DAIKU", - /* 0x0123 */ "OBJECT_UNSET_123", - /* 0x0124 */ "OBJECT_NWC", - /* 0x0125 */ "OBJECT_BLKOBJ", - /* 0x0126 */ "OBJECT_GM", - /* 0x0127 */ "OBJECT_MS", - /* 0x0128 */ "OBJECT_HS", - /* 0x0129 */ "OBJECT_INGATE", - /* 0x012A */ "OBJECT_LIGHTSWITCH", - /* 0x012B */ "OBJECT_KUSA", - /* 0x012C */ "OBJECT_TSUBO", - /* 0x012D */ "OBJECT_GI_GLOVES", - /* 0x012E */ "OBJECT_GI_COIN", - /* 0x012F */ "OBJECT_KANBAN", - /* 0x0130 */ "OBJECT_GJYO_OBJECTS", - /* 0x0131 */ "OBJECT_OWL", - /* 0x0132 */ "OBJECT_MK", - /* 0x0133 */ "OBJECT_FU", - /* 0x0134 */ "OBJECT_GI_KI_TAN_MASK", - /* 0x0135 */ "OBJECT_GI_REDEAD_MASK", - /* 0x0136 */ "OBJECT_GI_SKJ_MASK", - /* 0x0137 */ "OBJECT_GI_RABIT_MASK", - /* 0x0138 */ "OBJECT_GI_TRUTH_MASK", - /* 0x0139 */ "OBJECT_GANON_OBJECTS", - /* 0x013A */ "OBJECT_SIOFUKI", - /* 0x013B */ "OBJECT_STREAM", - /* 0x013C */ "OBJECT_MM", - /* 0x013D */ "OBJECT_FA", - /* 0x013E */ "OBJECT_OS", - /* 0x013F */ "OBJECT_GI_EYE_LOTION", - /* 0x0140 */ "OBJECT_GI_POWDER", - /* 0x0141 */ "OBJECT_GI_MUSHROOM", - /* 0x0142 */ "OBJECT_GI_TICKETSTONE", - /* 0x0143 */ "OBJECT_GI_BROKENSWORD", - /* 0x0144 */ "OBJECT_JS", - /* 0x0145 */ "OBJECT_CS", - /* 0x0146 */ "OBJECT_GI_PRESCRIPTION", - /* 0x0147 */ "OBJECT_GI_BRACELET", - /* 0x0148 */ "OBJECT_GI_SOLDOUT", - /* 0x0149 */ "OBJECT_GI_FROG", - /* 0x014A */ "OBJECT_MAG", - /* 0x014B */ "OBJECT_DOOR_GERUDO", - /* 0x014C */ "OBJECT_GT", - /* 0x014D */ "OBJECT_EFC_ERUPC", - /* 0x014E */ "OBJECT_ZL2_ANIME1", - /* 0x014F */ "OBJECT_ZL2_ANIME2", - /* 0x0150 */ "OBJECT_GI_GOLONMASK", - /* 0x0151 */ "OBJECT_GI_ZORAMASK", - /* 0x0152 */ "OBJECT_GI_GERUDOMASK", - /* 0x0153 */ "OBJECT_GANON2", - /* 0x0154 */ "OBJECT_KA", - /* 0x0155 */ "OBJECT_TS", - /* 0x0156 */ "OBJECT_ZG", - /* 0x0157 */ "OBJECT_GI_HOVERBOOTS", - /* 0x0158 */ "OBJECT_GI_M_ARROW", - /* 0x0159 */ "OBJECT_DS2", - /* 0x015A */ "OBJECT_EC", - /* 0x015B */ "OBJECT_FISH", - /* 0x015C */ "OBJECT_GI_SUTARU", - /* 0x015D */ "OBJECT_GI_GODDESS", - /* 0x015E */ "OBJECT_SSH", - /* 0x015F */ "OBJECT_BIGOKUTA", - /* 0x0160 */ "OBJECT_BG", - /* 0x0161 */ "OBJECT_SPOT05_OBJECTS", - /* 0x0162 */ "OBJECT_SPOT12_OBJ", - /* 0x0163 */ "OBJECT_BOMBIWA", - /* 0x0164 */ "OBJECT_HINTNUTS", - /* 0x0165 */ "OBJECT_RS", - /* 0x0166 */ "OBJECT_SPOT00_BREAK", - /* 0x0167 */ "OBJECT_GLA", - /* 0x0168 */ "OBJECT_SHOPNUTS", - /* 0x0169 */ "OBJECT_GELDB", - /* 0x016A */ "OBJECT_GR", - /* 0x016B */ "OBJECT_DOG", - /* 0x016C */ "OBJECT_JYA_IRON", - /* 0x016D */ "OBJECT_JYA_DOOR", - /* 0x016E */ "OBJECT_UNSET_16E", - /* 0x016F */ "OBJECT_SPOT11_OBJ", - /* 0x0170 */ "OBJECT_KIBAKO2", - /* 0x0171 */ "OBJECT_DNS", - /* 0x0172 */ "OBJECT_DNK", - /* 0x0173 */ "OBJECT_GI_FIRE", - /* 0x0174 */ "OBJECT_GI_INSECT", - /* 0x0175 */ "OBJECT_GI_BUTTERFLY", - /* 0x0176 */ "OBJECT_GI_GHOST", - /* 0x0177 */ "OBJECT_GI_SOUL", - /* 0x0178 */ "OBJECT_BOWL", - /* 0x0179 */ "OBJECT_DEMO_KEKKAI", - /* 0x017A */ "OBJECT_EFC_DOUGHNUT", - /* 0x017B */ "OBJECT_GI_DEKUPOUCH", - /* 0x017C */ "OBJECT_GANON_ANIME1", - /* 0x017D */ "OBJECT_GANON_ANIME2", - /* 0x017E */ "OBJECT_GANON_ANIME3", - /* 0x017F */ "OBJECT_GI_RUPY", - /* 0x0180 */ "OBJECT_SPOT01_MATOYA", - /* 0x0181 */ "OBJECT_SPOT01_MATOYAB", - /* 0x0182 */ "OBJECT_MU", - /* 0x0183 */ "OBJECT_WF", - /* 0x0184 */ "OBJECT_SKB", - /* 0x0185 */ "OBJECT_GJ", - /* 0x0186 */ "OBJECT_GEFF", - /* 0x0187 */ "OBJECT_HAKA_DOOR", - /* 0x0188 */ "OBJECT_GS", - /* 0x0189 */ "OBJECT_PS", - /* 0x018A */ "OBJECT_BWALL", - /* 0x018B */ "OBJECT_COW", - /* 0x018C */ "OBJECT_COB", - /* 0x018D */ "OBJECT_GI_SWORD_1", - /* 0x018E */ "OBJECT_DOOR_KILLER", - /* 0x018F */ "OBJECT_OUKE_HAKA", - /* 0x0190 */ "OBJECT_TIMEBLOCK", - /* 0x0191 */ "OBJECT_ZL4", -}; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZRoom/ZNames.h b/tools/ZAPD/ZAPD/ZRoom/ZNames.h new file mode 100644 index 0000000000..6b99cd3e8e --- /dev/null +++ b/tools/ZAPD/ZAPD/ZRoom/ZNames.h @@ -0,0 +1,49 @@ +#pragma once + +#include "../Globals.h" +#include "../StringHelper.h" + +#include + +class ZNames +{ +public: + static std::string GetObjectName(size_t id) + { + if (id >= Globals::Instance->cfg.objectList.size()) + return StringHelper::Sprintf("0x%04X", id); + return Globals::Instance->cfg.objectList.at(id); + } + + static std::string GetActorName(int32_t id) + { + switch (Globals::Instance->game) + { + case ZGame::OOT_RETAIL: + case ZGame::OOT_SW97: + if (id < ZNames::GetNumActors()) + return Globals::Instance->cfg.actorList.at(id); + else + return StringHelper::Sprintf("0x%04X", id); + case ZGame::MM_RETAIL: + { + int32_t flags = id & 0xF000; + id &= 0xFFF; + std::string name = ""; + if (id < ZNames::GetNumActors()) + name = Globals::Instance->cfg.actorList.at(id); + else + name = StringHelper::Sprintf("0x%04X", id); + + if (flags == 0) + return name; + else + return StringHelper::Sprintf("%s | 0x%04X", name.c_str(), flags); + } + } + + return ""; + } + + static int32_t GetNumActors() { return Globals::Instance->cfg.actorList.size(); } +}; diff --git a/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp b/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp index 9d8528c870..e280f3876b 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp @@ -7,10 +7,13 @@ #include "../StringHelper.h" #include "../ZBlob.h" #include "Commands/EndMarker.h" +#include "Commands/SetActorCutsceneList.h" #include "Commands/SetActorList.h" #include "Commands/SetAlternateHeaders.h" +#include "Commands/SetAnimatedTextureList.h" #include "Commands/SetCameraSettings.h" #include "Commands/SetCollisionHeader.h" +#include "Commands/SetCsCamera.h" #include "Commands/SetCutscenes.h" #include "Commands/SetEchoSettings.h" #include "Commands/SetEntranceList.h" @@ -18,6 +21,8 @@ #include "Commands/SetLightList.h" #include "Commands/SetLightingSettings.h" #include "Commands/SetMesh.h" +#include "Commands/SetMinimapChests.h" +#include "Commands/SetMinimapList.h" #include "Commands/SetObjectList.h" #include "Commands/SetPathways.h" #include "Commands/SetRoomBehavior.h" @@ -30,157 +35,108 @@ #include "Commands/SetTimeSettings.h" #include "Commands/SetTransitionActorList.h" #include "Commands/SetWind.h" +#include "Commands/SetWorldMapVisited.h" #include "Commands/Unused09.h" +#include "Commands/Unused1D.h" #include "Commands/ZRoomCommandUnk.h" -#include "ObjectList.h" #include "ZCutscene.h" #include "ZFile.h" using namespace std; using namespace tinyxml2; -ZRoom::ZRoom() : ZResource() +REGISTER_ZFILENODE(Room, ZRoom); +REGISTER_ZFILENODE(Scene, ZRoom); + +ZRoom::ZRoom(ZFile* nParent) : ZResource(nParent) { textures = map(); commands = vector(); commandSets = vector(); extDefines = ""; scene = nullptr; + roomCount = -1; + canHaveInner = true; } ZRoom::~ZRoom() { for (ZRoomCommand* cmd : commands) delete cmd; + + for(auto t : textures) + delete t.second; } -ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int rawDataIndex, - string nRelPath, ZFile* nParent, ZRoom* nScene) +void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZRoom* room = new ZRoom(); + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); - room->parent = nParent; - room->rawData = nRawData; - room->name = reader->Attribute("Name"); - - // printf("ZRoom: %s\n", name.c_str()); - - room->scene = nScene; + // room->scene = nScene; + scene = Globals::Instance->lastScene; if (string(reader->Name()) == "Scene") { - room->scene = room; - Globals::Instance->lastScene = room; + scene = this; + Globals::Instance->lastScene = this; } Globals::Instance->AddSegment(SEGMENT_ROOM); Globals::Instance->AddSegment(SEGMENT_SCENE); - // GenDefinitions(); + uint32_t cmdCount = UINT32_MAX; - int cmdCount = 999999; - - if (room->name == "syotes_room_0") + if (name == "syotes_room_0") { - room->SyotesRoomHack(); + SyotesRoomHack(); cmdCount = 0; } for (XMLElement* child = reader->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) { + string childName = child->Attribute("Name") == NULL ? "" : string(child->Attribute("Name")); + string childComment = child->Attribute("Comment") == NULL ? + "" : + "// " + string(child->Attribute("Comment")) + "\n"; + // TODO: Bunch of repeated code between all of these that needs to be combined. if (string(child->Name()) == "DListHint") { - string name = ""; - string comment = ""; - - if (child->Attribute("Comment") != NULL) - comment = "// " + string(child->Attribute("Comment")) + "\n"; - string addressStr = child->Attribute("Offset"); - int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); + int32_t address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); ZDisplayList* dList = new ZDisplayList( - room->rawData, address, - ZDisplayList::GetDListLength(room->rawData, address, + rawData, address, + ZDisplayList::GetDListLength(rawData, address, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : - DListType::F3DZEX)); - - if (child->Attribute("Name") != NULL) - name = string(child->Attribute("Name")); - else - name = room->name; + DListType::F3DZEX), + parent); dList->GetSourceOutputCode(name); delete dList; } - else if (string(child->Name()) == "BlobHint") - { - string name = ""; - string comment = ""; - - if (child->Attribute("Comment") != NULL) - comment = "// " + string(child->Attribute("Comment")) + "\n"; - - string addressStr = child->Attribute("Offset"); - int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); - - string sizeStr = child->Attribute("Size"); - int size = strtol(StringHelper::Split(sizeStr, "0x")[1].c_str(), NULL, 16); - - ZBlob* blob = - new ZBlob(room->rawData, address, size, - StringHelper::Sprintf("%sBlob0x%06X", room->name.c_str(), address)); - - if (child->Attribute("Name") != NULL) - name = string(child->Attribute("Name")); - else - name = StringHelper::Sprintf("%s_%s", room->name.c_str(), blob->GetName().c_str()); - - room->parent->AddDeclarationArray(address, DeclarationAlignment::None, - blob->GetRawDataSize(), "u8", name, 0, - blob->GetSourceOutputCode(room->name)); - delete blob; - } else if (string(child->Name()) == "CutsceneHint") { - string name = ""; - string comment = ""; - - if (child->Attribute("Comment") != NULL) - comment = "// " + string(child->Attribute("Comment")) + "\n"; - string addressStr = child->Attribute("Offset"); - int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); + int32_t address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); - ZCutscene* cutscene = new ZCutscene(room->rawData, address, 9999); + // ZCutscene* cutscene = new ZCutscene(rawData, address, 9999, parent); + ZCutscene* cutscene = new ZCutscene(parent); + cutscene->ExtractFromXML(child, rawData, address, ""); - if (child->Attribute("Name") != NULL) - name = string(child->Attribute("Name")); - else - name = StringHelper::Sprintf("%sCutsceneData0x%06X", room->name.c_str(), - cutscene->segmentOffset); + cutscene->GetSourceOutputCode(name); - room->parent->AddDeclarationArray(address, DeclarationAlignment::None, - DeclarationPadding::Pad16, cutscene->GetRawDataSize(), - "s32", name, 0, - cutscene->GetSourceOutputCode(room->name)); delete cutscene; } else if (string(child->Name()) == "AltHeaderHint") { - string name = ""; - string comment = ""; - - if (child->Attribute("Comment") != NULL) - comment = "// " + string(child->Attribute("Comment")) + "\n"; - string addressStr = child->Attribute("Offset"); - int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); + int32_t address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); - int commandsCount = 99999999; + uint32_t commandsCount = UINT32_MAX; if (child->FindAttribute("Count") != NULL) { @@ -188,64 +144,40 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector nRawData, int r commandsCount = strtol(commandCountStr.c_str(), NULL, 10); } - room->commandSets.push_back(CommandSet(address, commandsCount)); + commandSets.push_back(CommandSet(address, commandsCount)); } else if (string(child->Name()) == "PathHint") { - string comment = ""; - - if (child->Attribute("Comment") != NULL) - comment = "// " + string(child->Attribute("Comment")) + "\n"; - string addressStr = child->Attribute("Offset"); - int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); + int32_t address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); - SetPathways* pathway = new SetPathways(room, room->rawData, address); - pathway->InitList(address); - pathway->GenerateSourceCodePass1(room->name, 0); - pathway->GenerateSourceCodePass2(room->name, 0); + ZSetPathways* pathway = new ZSetPathways(this, rawData, address, false); + pathway->GenerateSourceCodePass1(name, 0); + pathway->GenerateSourceCodePass2(name, 0); delete pathway; } - else if (string(child->Name()) == "TextureHint") - { - string comment = ""; - if (child->Attribute("Comment") != NULL) - comment = "// " + string(child->Attribute("Comment")) + "\n"; - - string addressStr = child->Attribute("Offset"); - int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16); - - string typeStr = child->Attribute("Type"); - int width = strtol(string(child->Attribute("Width")).c_str(), NULL, 10); - int height = strtol(string(child->Attribute("Height")).c_str(), NULL, 10); - - ZTexture* tex = ZTexture::FromBinary( - ZTexture::GetTextureTypeFromString(typeStr), room->rawData, address, - StringHelper::Sprintf("%sTex_%06X", room->name.c_str(), address), width, height); - room->parent->AddDeclarationArray(address, DeclarationAlignment::None, - tex->GetRawDataSize(), "u64", - StringHelper::Sprintf("%s", tex->GetName().c_str()), - 0, tex->GetSourceOutputCode(room->name)); - delete tex; - } + fprintf(stderr, + "ZRoom::ExtractFromXML: Deprecation warning in '%s'.\n" + "\t The resource '%s' is currently deprecated, and will be removed in a future " + "version.\n" + "\t Use the non-hint version instead.\n", + name.c_str(), child->Name()); } // ParseCommands(rawDataIndex); - room->commandSets.push_back(CommandSet(rawDataIndex, cmdCount)); - room->ProcessCommandSets(); - - return room; + commandSets.push_back(CommandSet(rawDataIndex, cmdCount)); + ProcessCommandSets(); } void ZRoom::ParseCommands(std::vector& commandList, CommandSet commandSet) { bool shouldContinue = true; - int currentIndex = 0; - int rawDataIndex = commandSet.address & 0x00FFFFFF; + uint32_t currentIndex = 0; + uint32_t rawDataIndex = GETSEGOFFSET(commandSet.address); - int32_t commandsLeft = commandSet.commandCount; + uint32_t commandsLeft = commandSet.commandCount; while (shouldContinue) { @@ -266,6 +198,9 @@ void ZRoom::ParseCommands(std::vector& commandList, CommandSet co case RoomCommand::SetActorList: cmd = new SetActorList(this, rawData, rawDataIndex); break; // 0x01 + case RoomCommand::SetCsCamera: + cmd = new SetCsCamera(this, rawData, rawDataIndex); + break; // 0x02 (MM-ONLY) case RoomCommand::SetCollisionHeader: cmd = new SetCollisionHeader(this, rawData, rawDataIndex); break; // 0x03 @@ -297,7 +232,7 @@ void ZRoom::ParseCommands(std::vector& commandList, CommandSet co cmd = new SetLightList(this, rawData, rawDataIndex); break; // 0x0C (MM-ONLY) case RoomCommand::SetPathways: - cmd = new SetPathways(this, rawData, rawDataIndex); + cmd = new ZSetPathways(this, rawData, rawDataIndex, true); break; // 0x0D case RoomCommand::SetTransitionActorList: cmd = new SetTransitionActorList(this, rawData, rawDataIndex); @@ -333,8 +268,26 @@ void ZRoom::ParseCommands(std::vector& commandList, CommandSet co cmd = new SetAlternateHeaders(this, rawData, rawDataIndex); break; // 0x18 case RoomCommand::SetCameraSettings: - cmd = new SetCameraSettings(this, rawData, rawDataIndex); + if (Globals::Instance->game == ZGame::MM_RETAIL) + cmd = new SetWorldMapVisited(this, rawData, rawDataIndex); + else + cmd = new SetCameraSettings(this, rawData, rawDataIndex); break; // 0x19 + case RoomCommand::SetAnimatedTextureList: + cmd = new SetAnimatedTextureList(this, rawData, rawDataIndex); + break; // 0x1A (MM-ONLY) + case RoomCommand::SetActorCutsceneList: + cmd = new SetActorCutsceneList(this, rawData, rawDataIndex); + break; // 0x1B (MM-ONLY) + case RoomCommand::SetMinimapList: + cmd = new SetMinimapList(this, rawData, rawDataIndex); + break; // 0x1C (MM-ONLY) + case RoomCommand::Unused1D: + cmd = new Unused1D(this, rawData, rawDataIndex); + break; // 0x1D + case RoomCommand::SetMinimapChests: + cmd = new SetMinimapChests(this, rawData, rawDataIndex); + break; // 0x1E (MM-ONLY) default: cmd = new ZRoomCommandUnk(this, rawData, rawDataIndex); } @@ -387,7 +340,7 @@ void ZRoom::ProcessCommandSets() StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()), StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), commandSet & 0x00FFFFFF, cmd->cmdIndex, cmd->cmdID), - StringHelper::Sprintf("%s", pass1.c_str())); + StringHelper::Sprintf("\n %s\n", pass1.c_str())); decl->rightText = StringHelper::Sprintf("// 0x%04X", cmd->cmdAddress); } @@ -446,7 +399,7 @@ ZRoomCommand* ZRoom::FindCommandOfType(RoomCommand cmdType) return nullptr; } -size_t ZRoom::GetDeclarationSizeFromNeighbor(int declarationAddress) +size_t ZRoom::GetDeclarationSizeFromNeighbor(int32_t declarationAddress) { size_t declarationIndex = -1; @@ -467,7 +420,7 @@ size_t ZRoom::GetDeclarationSizeFromNeighbor(int declarationAddress) } } - if ((int)declarationIndex != -1) + if ((int32_t)declarationIndex != -1) { if (declarationIndex + 1 < declarationKeysSorted.size()) return declarationKeysSorted[declarationIndex + 1].first - @@ -481,7 +434,7 @@ size_t ZRoom::GetDeclarationSizeFromNeighbor(int declarationAddress) size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd) { - size_t cmdIndex = -1; + int32_t cmdIndex = -1; for (size_t i = 0; i < commands.size(); i++) { @@ -492,9 +445,9 @@ size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd) } } - if ((int)cmdIndex != -1) + if (cmdIndex != -1) { - if (cmdIndex + 1 < commands.size()) + if (cmdIndex + 1 < (int32_t)commands.size()) return commands[cmdIndex + 1]->cmdAddress - commands[cmdIndex]->cmdAddress; else return rawData.size() - commands[cmdIndex]->cmdAddress; @@ -522,7 +475,6 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix) { sourceOutput = ""; - // sourceOutput += "#include \n"; sourceOutput += "#include \"segment_symbols.h\"\n"; sourceOutput += "#include \"command_macros_base.h\"\n"; sourceOutput += "#include \"z64cutscene_commands.h\"\n"; @@ -547,11 +499,11 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix) for (size_t i = 0; i < texturesSorted.size() - 1; i++) { - int texSize = textures[texturesSorted[i].first]->GetRawDataSize(); + int32_t texSize = textures[texturesSorted[i].first]->GetRawDataSize(); if ((texturesSorted[i].first + texSize) > texturesSorted[i + 1].first) { - // int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + + // int32_t intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + // 1].first; defines += StringHelper::Sprintf( @@ -569,7 +521,6 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix) } parent->defines += defines; - // parent->externs[0xFFFFFFFF] = defines; } for (pair item : textures) @@ -578,33 +529,27 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix) declaration += item.second->GetSourceOutputCode(prefix); + std::string outPath = item.second->GetPoolOutPath(Globals::Instance->outputPath); + if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) - printf("SAVING IMAGE TO %s\n", Globals::Instance->outputPath.c_str()); + printf("SAVING IMAGE TO %s\n", outPath.c_str()); - item.second->Save(Globals::Instance->outputPath); + item.second->Save(outPath); + auto filepath = Globals::Instance->outputPath / Path::GetFileNameWithoutExtension(item.second->GetName()); parent->AddDeclarationIncludeArray( item.first, - StringHelper::Sprintf("%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(), - Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(), - item.second->GetExternalExtension().c_str()), + StringHelper::Sprintf("%s.%s.inc.c", filepath.c_str(), item.second->GetExternalExtension().c_str()), item.second->GetRawDataSize(), "u64", StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first), 0); } - // sourceOutput += "\n"; - return sourceOutput; } -vector ZRoom::GetRawData() +size_t ZRoom::GetRawDataSize() { - return rawData; -} - -int ZRoom::GetRawDataSize() -{ - int32_t size = 0; + size_t size = 0; for (ZRoomCommand* cmd : commands) size += cmd->GetRawDataSize(); @@ -630,7 +575,7 @@ void ZRoom::PreGenSourceFiles() } Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, - uint32_t nSize, string nText) + size_t nSize, string nText) { alignment = nAlignment; padding = nPadding; @@ -646,10 +591,11 @@ Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPa isArray = false; arrayItemCnt = 0; includePath = ""; + isExternal = false; references = vector(); } -Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType, +Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, string nVarType, string nVarName, bool nIsArray, string nText) : Declaration(nAlignment, DeclarationPadding::None, nSize, nText) { @@ -659,7 +605,7 @@ Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string } Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, - uint32_t nSize, string nVarType, string nVarName, bool nIsArray, + size_t nSize, string nVarType, string nVarName, bool nIsArray, string nText) : Declaration(nAlignment, nPadding, nSize, nText) { @@ -668,8 +614,8 @@ Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPa isArray = nIsArray; } -Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType, - string nVarName, bool nIsArray, int nArrayItemCnt, string nText) +Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, string nVarType, + string nVarName, bool nIsArray, size_t nArrayItemCnt, string nText) : Declaration(nAlignment, DeclarationPadding::None, nSize, nText) { varType = nVarType; @@ -678,9 +624,17 @@ Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string arrayItemCnt = nArrayItemCnt; } +Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType, + std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText, + bool nIsExternal) + : Declaration(nAlignment, nSize, nVarType, nVarName, nIsArray, nArrayItemCnt, nText) +{ + isExternal = nIsExternal; +} + Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, - uint32_t nSize, string nVarType, string nVarName, bool nIsArray, - int nArrayItemCnt, string nText) + size_t nSize, string nVarType, string nVarName, bool nIsArray, + size_t nArrayItemCnt, string nText) : Declaration(nAlignment, nPadding, nSize, nText) { varType = nVarType; @@ -689,7 +643,7 @@ Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPa arrayItemCnt = nArrayItemCnt; } -Declaration::Declaration(std::string nIncludePath, uint32_t nSize, string nVarType, string nVarName) +Declaration::Declaration(std::string nIncludePath, size_t nSize, string nVarType, string nVarName) : Declaration(DeclarationAlignment::None, DeclarationPadding::None, nSize, "") { includePath = nIncludePath; @@ -703,7 +657,7 @@ CommandSet::CommandSet(int32_t nAddress) commandCount = 9999999; } -CommandSet::CommandSet(int32_t nAddress, int32_t nCommandCount) +CommandSet::CommandSet(int32_t nAddress, uint32_t nCommandCount) { address = nAddress; commandCount = nCommandCount; diff --git a/tools/ZAPD/ZAPD/ZRoom/ZRoom.h b/tools/ZAPD/ZAPD/ZRoom/ZRoom.h index b0b4a503e3..b1fe869be2 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoom.h +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoom.h @@ -14,40 +14,39 @@ class ZRoom : public ZResource protected: std::vector commands; - std::string GetSourceOutputHeader(const std::string& prefix); - std::string GetSourceOutputCode(const std::string& prefix); + std::string GetSourceOutputHeader(const std::string& prefix) override; + std::string GetSourceOutputCode(const std::string& prefix) override; void ProcessCommandSets(); void SyotesRoomHack(); - ZRoom(); - ~ZRoom(); - public: ZRoom* scene; std::map textures; std::vector commandSets; + int32_t roomCount; // Only valid for scenes std::string extDefines; - static ZRoom* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, - int rawDataIndex, std::string nRelPath, ZFile* nParent, - ZRoom* nScene); + ZRoom(ZFile* nParent); + virtual ~ZRoom(); + + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; void ParseCommands(std::vector& commandList, CommandSet commandSet); - size_t GetDeclarationSizeFromNeighbor(int declarationAddress); + size_t GetDeclarationSizeFromNeighbor(int32_t declarationAddress); size_t GetCommandSizeFromNeighbor(ZRoomCommand* cmd); ZRoomCommand* FindCommandOfType(RoomCommand cmdType); - std::vector GetRawData(); - int GetRawDataSize(); - virtual ZResourceType GetResourceType(); - virtual void Save(const std::string& outFolder); - virtual void PreGenSourceFiles(); + size_t GetRawDataSize() override; + virtual ZResourceType GetResourceType() override; + virtual void Save(const std::string& outFolder) override; + virtual void PreGenSourceFiles() override; }; struct CommandSet { int32_t address; - int32_t commandCount; // Only used if explicitly specified in the XML + uint32_t commandCount; // Only used if explicitly specified in the XML CommandSet(int32_t nAddress); - CommandSet(int32_t nAddress, int32_t nCommandCount); + CommandSet(int32_t nAddress, uint32_t nCommandCount); }; diff --git a/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.cpp b/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.cpp index 8d3baeb728..cf70de084b 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.cpp @@ -1,26 +1,25 @@ #include "ZRoomCommand.h" +#include "StringHelper.h" using namespace std; -ZRoomCommand::ZRoomCommand(ZRoom* nZRoom, std::vector rawData, int rawDataIndex) +ZRoomCommand::ZRoomCommand(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex) { cmdID = (RoomCommand)rawData[rawDataIndex]; cmdAddress = rawDataIndex; zRoom = nZRoom; } -string ZRoomCommand::GenerateSourceCodePass1(string roomName, int baseAddress) +ZRoomCommand::~ZRoomCommand() { - char line[2048]; - - // sprintf(line, "%s _%s_set%04X_cmd%02X = { 0x%02X,", GetCommandCName().c_str(), - // roomName.c_str(), baseAddress, cmdIndex, cmdID); - sprintf(line, " 0x%02X,", (uint8_t)cmdID); - - return string(line); } -string ZRoomCommand::GenerateSourceCodePass2(string roomName, int baseAddress) +string ZRoomCommand::GenerateSourceCodePass1(string roomName, uint32_t baseAddress) +{ + return StringHelper::Sprintf("0x%02X,", (uint8_t)cmdID); +} + +string ZRoomCommand::GenerateSourceCodePass2(string roomName, uint32_t baseAddress) { return ""; } @@ -45,7 +44,7 @@ std::string ZRoomCommand::PreGenSourceFiles() return std::string(); } -int32_t ZRoomCommand::GetRawDataSize() +size_t ZRoomCommand::GetRawDataSize() { return 8; } diff --git a/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.h b/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.h index 3389d9e121..82049c9289 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.h +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoomCommand.h @@ -11,7 +11,7 @@ enum class RoomCommand : uint8_t { SetStartPositionList = 0x00, SetActorList = 0x01, - SetCameraSomething = 0x02, + SetCsCamera = 0x02, SetCollisionHeader = 0x03, SetRoomList = 0x04, SetWind = 0x05, @@ -36,6 +36,14 @@ enum class RoomCommand : uint8_t SetAlternateHeaders = 0x18, SetCameraSettings = 0x19, + // MM Commands + SetWorldMapVisited = 0x19, + SetAnimatedTextureList = 0x1A, + SetActorCutsceneList = 0x1B, + SetMinimapList = 0x1C, + Unused1D = 0x1D, + SetMinimapChests = 0x1E, + Error = 0xFF }; @@ -44,17 +52,18 @@ class ZRoomCommand public: RoomCommand cmdID; int32_t cmdAddress; - int32_t cmdIndex; + uint32_t cmdIndex; int32_t cmdSet; uint32_t commandSet; - ZRoomCommand(ZRoom* nZRoom, std::vector rawData, int rawDataIndex); - - virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress); - virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress); + ZRoomCommand() = default; + ZRoomCommand(ZRoom* nZRoom, std::vector rawData, uint32_t rawDataIndex); + virtual ~ZRoomCommand(); + virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress); + virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress); virtual std::string GenerateSourceCodePass3(std::string roomName); virtual RoomCommand GetRoomCommand(); - virtual int32_t GetRawDataSize(); + virtual size_t GetRawDataSize(); virtual std::string GetCommandCName(); virtual std::string GenerateExterns(); virtual std::string Save(); diff --git a/tools/ZAPD/ZAPD/ZScalar.cpp b/tools/ZAPD/ZAPD/ZScalar.cpp index e523562ee9..af48dc3305 100644 --- a/tools/ZAPD/ZAPD/ZScalar.cpp +++ b/tools/ZAPD/ZAPD/ZScalar.cpp @@ -5,29 +5,25 @@ #include "StringHelper.h" #include "ZFile.h" -ZScalar* ZScalar::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, - const int rawDataIndex, const std::string& nRelPath) -{ - ZScalar* scalar = new ZScalar(); - scalar->rawData = nRawData; - scalar->rawDataIndex = rawDataIndex; - scalar->ParseXML(reader); - scalar->ParseRawData(); +REGISTER_ZFILENODE(Scalar, ZScalar); - return scalar; -} - -ZScalar::ZScalar() : ZResource() +ZScalar::ZScalar(ZFile* nParent) : ZResource(nParent) { memset(&scalarData, 0, sizeof(ZScalarData)); scalarType = ZSCALAR_NONE; } -ZScalar::ZScalar(const ZScalarType scalarType) : ZScalar() +ZScalar::ZScalar(const ZScalarType scalarType, ZFile* nParent) : ZScalar(nParent) { this->scalarType = scalarType; } +void ZScalar::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) +{ + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); +} + void ZScalar::ParseXML(tinyxml2::XMLElement* reader) { ZResource::ParseXML(reader); @@ -111,7 +107,7 @@ std::string ZScalar::MapScalarTypeToOutputType(const ZScalarType scalarType) } } -int ZScalar::MapTypeToSize(const ZScalarType scalarType) +size_t ZScalar::MapTypeToSize(const ZScalarType scalarType) { switch (scalarType) { @@ -140,7 +136,7 @@ int ZScalar::MapTypeToSize(const ZScalarType scalarType) } } -int ZScalar::GetRawDataSize() +size_t ZScalar::GetRawDataSize() { return ZScalar::MapTypeToSize(scalarType); } @@ -150,7 +146,7 @@ void ZScalar::ParseRawData() ZScalar::ParseRawData(rawData, rawDataIndex); } -void ZScalar::ParseRawData(const std::vector& data, const int offset) +void ZScalar::ParseRawData(const std::vector& data, const uint32_t offset) { switch (scalarType) { @@ -185,8 +181,8 @@ void ZScalar::ParseRawData(const std::vector& data, const int offset) scalarData.f64 = BitConverter::ToDoubleBE(data, offset); break; case ZSCALAR_NONE: - fprintf(stderr, "Warning in ZScalar: Invalid type. %d %s %d\n", (int)scalarType, __FILE__, - __LINE__); + fprintf(stderr, "Warning in ZScalar: Invalid type. %d %s %d\n", (int32_t)scalarType, + __FILE__, __LINE__); break; } } diff --git a/tools/ZAPD/ZAPD/ZScalar.h b/tools/ZAPD/ZAPD/ZScalar.h index e5109ca16e..92d6365844 100644 --- a/tools/ZAPD/ZAPD/ZScalar.h +++ b/tools/ZAPD/ZAPD/ZScalar.h @@ -43,25 +43,24 @@ public: ZScalarData scalarData; ZScalarType scalarType; - ZScalar(); - ZScalar(const ZScalarType scalarType); + ZScalar(ZFile* nParent); + ZScalar(const ZScalarType scalarType, ZFile* nParent); void ParseXML(tinyxml2::XMLElement* reader) override; std::string GetSourceTypeName() override; std::string GetSourceValue(); std::string GetSourceOutputCode(const std::string& prefix) override; - int GetRawDataSize() override; + size_t 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); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; + static size_t MapTypeToSize(const ZScalarType scalarType); static ZScalarType MapOutputTypeToScalarType(const std::string& type); static std::string MapScalarTypeToOutputType(const ZScalarType scalarType); protected: - void ParseRawData(const std::vector& data, const int offset); + void ParseRawData(const std::vector& data, const uint32_t offset); }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZSkeleton.cpp b/tools/ZAPD/ZAPD/ZSkeleton.cpp index 85e22fbcb6..a635be597d 100644 --- a/tools/ZAPD/ZAPD/ZSkeleton.cpp +++ b/tools/ZAPD/ZAPD/ZSkeleton.cpp @@ -5,35 +5,18 @@ using namespace std; -ZSkeleton::ZSkeleton(tinyxml2::XMLElement* reader, const std::vector& nRawData, - int nRawDataIndex, ZFile* nParent) +REGISTER_ZFILENODE(Skeleton, ZSkeleton); + +ZSkeleton::ZSkeleton(ZFile* nParent) : ZResource(nParent) { - rawData.assign(nRawData.begin(), nRawData.end()); - rawDataIndex = nRawDataIndex; - parent = nParent; - - ParseXML(reader); - ParseRawData(); - - string defaultPrefix = name; - defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables - uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress); - - for (size_t i = 0; i < limbCount; i++) - { - uint32_t ptr2 = Seg2Filespace(BitConverter::ToUInt32BE(rawData, ptr), parent->baseAddress); - - ZLimb* limb = new ZLimb(reader, rawData, ptr2, parent); - limb->SetName( - StringHelper::Sprintf("%sLimb_%06X", defaultPrefix.c_str(), limb->GetFileAddress())); - limbs.push_back(limb); - - ptr += 4; - } + type = ZSkeletonType::Normal; + limbType = ZLimbType::Standard; + dListCount = 0; } ZSkeleton::ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix, - const std::vector& nRawData, int nRawDataIndex, ZFile* nParent) + const std::vector& nRawData, uint32_t nRawDataIndex, ZFile* nParent) + : ZResource(nParent) { rawData.assign(nRawData.begin(), nRawData.end()); rawDataIndex = nRawDataIndex; @@ -63,9 +46,7 @@ ZSkeleton::ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string ZSkeleton::~ZSkeleton() { for (auto& limb : limbs) - { delete limb; - } } void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) @@ -73,6 +54,7 @@ void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) ZResource::ParseXML(reader); const char* skelTypeXml = reader->Attribute("Type"); + if (skelTypeXml == nullptr) { fprintf(stderr, @@ -84,15 +66,12 @@ void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) else { string skelTypeStr(skelTypeXml); + if (skelTypeStr == "Flex") - { type = ZSkeletonType::Flex; - } else if (skelTypeStr == "Curve") - { type = ZSkeletonType::Curve; - } - else if (skelTypeStr != "Normal" && skelTypeStr != "Standard") + else if (skelTypeStr != "Normal") { fprintf(stderr, "ZSkeleton::ParseXML: Warning in '%s'.\n\t Invalid Type found: '%s'. " @@ -103,6 +82,7 @@ void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) } const char* limbTypeXml = reader->Attribute("LimbType"); + if (limbTypeXml == nullptr) { fprintf(stderr, @@ -114,22 +94,15 @@ void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) else { string limbTypeStr(limbTypeXml); + if (limbTypeStr == "Standard") - { limbType = ZLimbType::Standard; - } else if (limbTypeStr == "LOD") - { limbType = ZLimbType::LOD; - } else if (limbTypeStr == "Skin") - { limbType = ZLimbType::Skin; - } else if (limbTypeStr == "Curve") - { limbType = ZLimbType::Curve; - } else { fprintf(stderr, @@ -150,17 +123,31 @@ void ZSkeleton::ParseRawData() dListCount = BitConverter::ToUInt8BE(rawData, rawDataIndex + 8); } -ZSkeleton* ZSkeleton::FromXML(tinyxml2::XMLElement* reader, vector nRawData, - int rawDataIndex, string nRelPath, ZFile* nParent) +void ZSkeleton::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZSkeleton* skeleton = new ZSkeleton(reader, nRawData, rawDataIndex, nParent); - skeleton->relativePath = std::move(nRelPath); + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); - skeleton->parent->AddDeclaration(skeleton->rawDataIndex, DeclarationAlignment::Align16, - skeleton->GetRawDataSize(), skeleton->GetSourceTypeName(), - skeleton->name, ""); + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(), + GetSourceTypeName(), name, ""); - return skeleton; + string defaultPrefix = name; + defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables + uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress); + + for (size_t i = 0; i < limbCount; i++) + { + uint32_t ptr2 = Seg2Filespace(BitConverter::ToUInt32BE(rawData, ptr), parent->baseAddress); + + // ZLimb* limb = new ZLimb(reader, rawData, ptr2, parent); + ZLimb* limb = new ZLimb(parent); + limb->SetLimbType(limbType); + limb->SetName(StringHelper::Sprintf("%sLimb_%06X", defaultPrefix.c_str(), ptr2)); + limb->ExtractFromXML(nullptr, rawData, ptr2, nRelPath); + limbs.push_back(limb); + + ptr += 4; + } } void ZSkeleton::Save(const std::string& outFolder) @@ -171,10 +158,10 @@ void ZSkeleton::GenerateHLIntermediette(HLFileIntermediette& hlFile) { HLModelIntermediette* mdl = (HLModelIntermediette*)&hlFile; HLModelIntermediette::FromZSkeleton(mdl, this); - // mdl->blocks.push_back(new HLTerminator()); + mdl->blocks.push_back(new HLTerminator()); } -int ZSkeleton::GetRawDataSize() +size_t ZSkeleton::GetRawDataSize() { switch (type) { @@ -190,17 +177,13 @@ int ZSkeleton::GetRawDataSize() std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix) { if (parent == nullptr) - { return ""; - } string defaultPrefix = name.c_str(); defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables for (auto& limb : limbs) - { limb->GetSourceOutputCode(defaultPrefix); - } uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress); if (!parent->HasDeclaration(ptr)) @@ -208,8 +191,10 @@ std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix) // Table string tblStr = ""; string limbArrTypeStr = "static void*"; - if (limbType == ZLimbType::Curve) { - limbArrTypeStr = StringHelper::Sprintf("static %s*", ZLimb::GetSourceTypeName(limbType)); + if (limbType == ZLimbType::Curve) + { + limbArrTypeStr = + StringHelper::Sprintf("static %s*", ZLimb::GetSourceTypeName(limbType)); } for (size_t i = 0; i < limbs.size(); i++) @@ -245,6 +230,7 @@ std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix) } Declaration* decl = parent->GetDeclaration(GetAddress()); + if (decl == nullptr) { parent->AddDeclaration(GetAddress(), DeclarationAlignment::Align16, GetRawDataSize(), @@ -269,6 +255,7 @@ std::string ZSkeleton::GetSourceTypeName() case ZSkeletonType::Curve: return "SkelCurveLimbList"; } + return "SkeletonHeader"; } diff --git a/tools/ZAPD/ZAPD/ZSkeleton.h b/tools/ZAPD/ZAPD/ZSkeleton.h index 06ad628412..d93014448a 100644 --- a/tools/ZAPD/ZAPD/ZSkeleton.h +++ b/tools/ZAPD/ZAPD/ZSkeleton.h @@ -7,7 +7,7 @@ #include "ZFile.h" #include "ZLimb.h" -enum ZSkeletonType +enum class ZSkeletonType { Normal, Flex, @@ -17,27 +17,25 @@ enum ZSkeletonType class ZSkeleton : public ZResource { public: - ZSkeletonType type = ZSkeletonType::Normal; - ZLimbType limbType = ZLimbType::Standard; + ZSkeletonType type; + ZLimbType limbType; std::vector limbs; segptr_t limbsArrayAddress; uint8_t limbCount; uint8_t dListCount; // FLEX SKELETON ONLY - ZSkeleton() = default; - ZSkeleton(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, - ZFile* nParent); + ZSkeleton(ZFile* nParent); ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix, - const std::vector& nRawData, int nRawDataIndex, ZFile* nParent); + const std::vector& nRawData, uint32_t nRawDataIndex, ZFile* nParent); ~ZSkeleton(); void ParseXML(tinyxml2::XMLElement* reader) override; void ParseRawData() override; - static ZSkeleton* FromXML(tinyxml2::XMLElement* reader, std::vector nRawData, - int rawDataIndex, std::string nRelPath, ZFile* nParent); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; void Save(const std::string& outFolder) override; void GenerateHLIntermediette(HLFileIntermediette& hlFile) override; - int GetRawDataSize() override; + size_t GetRawDataSize() override; std::string GetSourceOutputCode(const std::string& prefix) override; std::string GetSourceTypeName() override; diff --git a/tools/ZAPD/ZAPD/ZSymbol.cpp b/tools/ZAPD/ZAPD/ZSymbol.cpp index 44613c545a..811c759dd9 100644 --- a/tools/ZAPD/ZAPD/ZSymbol.cpp +++ b/tools/ZAPD/ZAPD/ZSymbol.cpp @@ -1,30 +1,17 @@ #include "ZSymbol.h" #include "StringHelper.h" +#include "ZFile.h" -ZSymbol::ZSymbol(const std::string& nName, int nRawDataIndex, const std::string& nType, - uint32_t nTypeSize, bool nIsArray, uint32_t nCount) - : type(nType), typeSize(nTypeSize), isArray(nIsArray), count(nCount) +REGISTER_ZFILENODE(Symbol, ZSymbol); + +ZSymbol::ZSymbol(ZFile* nParent) : ZResource(nParent) { - name = nName; - rawDataIndex = nRawDataIndex; } -ZSymbol::ZSymbol(tinyxml2::XMLElement* reader, const std::vector& nRawData, - int nRawDataIndex, ZFile* nParent) +void ZSymbol::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - rawData.assign(nRawData.begin(), nRawData.end()); - rawDataIndex = nRawDataIndex; - parent = nParent; - - ParseXML(reader); -} - -ZSymbol* ZSymbol::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, - int nRawDataIndex, ZFile* parent) -{ - ZSymbol* symbol = new ZSymbol(reader, nRawData, nRawDataIndex, parent); - - return symbol; + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); } void ZSymbol::ParseXML(tinyxml2::XMLElement* reader) @@ -32,6 +19,7 @@ void ZSymbol::ParseXML(tinyxml2::XMLElement* reader) ZResource::ParseXML(reader); const char* typeXml = reader->Attribute("Type"); + if (typeXml == nullptr) { fprintf(stderr, @@ -63,19 +51,17 @@ void ZSymbol::ParseXML(tinyxml2::XMLElement* reader) if (countXml != nullptr) { isArray = true; + if (!std::string(countXml).empty()) - { count = std::strtoul(countXml, nullptr, 0); - } } } -int ZSymbol::GetRawDataSize() +size_t ZSymbol::GetRawDataSize() { if (isArray) - { return count * typeSize; - } + return typeSize; } @@ -84,13 +70,13 @@ std::string ZSymbol::GetSourceOutputHeader(const std::string& prefix) if (isArray) { if (count == 0) - { return StringHelper::Sprintf("extern %s %s%s[];\n", type.c_str(), prefix.c_str(), name.c_str()); - } - return StringHelper::Sprintf("extern %s %s%s[%i];\n", type.c_str(), prefix.c_str(), - name.c_str(), count); + else + return StringHelper::Sprintf("extern %s %s%s[%i];\n", type.c_str(), prefix.c_str(), + name.c_str(), count); } + return StringHelper::Sprintf("extern %s %s%s;\n", type.c_str(), prefix.c_str(), name.c_str()); } diff --git a/tools/ZAPD/ZAPD/ZSymbol.h b/tools/ZAPD/ZAPD/ZSymbol.h index 4513f8ff30..1ad906f3bf 100644 --- a/tools/ZAPD/ZAPD/ZSymbol.h +++ b/tools/ZAPD/ZAPD/ZSymbol.h @@ -7,24 +7,19 @@ class ZSymbol : public ZResource { protected: std::string type; - uint32_t typeSize; + size_t typeSize; bool isArray = false; uint32_t count = 0; public: - ZSymbol() = default; - ZSymbol(const std::string& nName, int nRawDataIndex, const std::string& nType, - uint32_t nTypeSize, bool nIsArray, uint32_t nCount); - ZSymbol(tinyxml2::XMLElement* reader, const std::vector& nRawData, int nRawDataIndex, - ZFile* nParent); + ZSymbol(ZFile* nParent); - static ZSymbol* ExtractFromXML(tinyxml2::XMLElement* reader, - const std::vector& nRawData, int nRawDataIndex, - ZFile* parent); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; void ParseXML(tinyxml2::XMLElement* reader) override; - int GetRawDataSize() override; + size_t GetRawDataSize() override; std::string GetSourceOutputHeader(const std::string& prefix) override; diff --git a/tools/ZAPD/ZAPD/ZTexture.cpp b/tools/ZAPD/ZAPD/ZTexture.cpp index ab2ee55461..72ccf67902 100644 --- a/tools/ZAPD/ZAPD/ZTexture.cpp +++ b/tools/ZAPD/ZAPD/ZTexture.cpp @@ -4,17 +4,21 @@ #include "ZTexture.h" #include "BitConverter.h" +#include "CRC32.h" #include "File.h" +#include "Globals.h" #include "Path.h" -#include "StringHelper.h" +#include #include "stb_image.h" #include "stb_image_write.h" using namespace std; using namespace tinyxml2; -ZTexture::ZTexture() : ZResource() +REGISTER_ZFILENODE(Texture, ZTexture); + +ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent) { bmpRgb = nullptr; bmpRgba = nullptr; @@ -22,6 +26,7 @@ ZTexture::ZTexture() : ZResource() height = 0; type = TextureType::Error; isPalette = false; + isRawDataFixed = false; } ZTexture::~ZTexture() @@ -43,29 +48,25 @@ ZTexture::~ZTexture() type = TextureType::Error; } -// EXTRACT MODE -ZTexture* ZTexture::ExtractFromXML(XMLElement* reader, vector nRawData, int nRawDataIndex, - string nRelPath) +void ZTexture::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) { - ZTexture* tex = new ZTexture(); + ParseXML(reader); + rawDataIndex = nRawDataIndex; + rawData = vector(nRawData.data() + rawDataIndex, + nRawData.data() + rawDataIndex + GetRawDataSize()); - tex->ParseXML(reader); - tex->rawDataIndex = nRawDataIndex; - tex->rawData = vector(nRawData.data() + tex->rawDataIndex, - nRawData.data() + tex->rawDataIndex + tex->GetRawDataSize()); + relativePath = nRelPath; - tex->relativePath = nRelPath; - - tex->FixRawData(); - tex->PrepareBitmap(); - - return tex; + FixRawData(); + PrepareBitmap(); } -ZTexture* ZTexture::FromBinary(TextureType nType, std::vector nRawData, int nRawDataIndex, - std::string nName, int nWidth, int nHeight) +ZTexture* ZTexture::FromBinary(TextureType nType, std::vector nRawData, + uint32_t nRawDataIndex, std::string nName, int32_t nWidth, + int32_t nHeight, ZFile* nParent) { - ZTexture* tex = new ZTexture(); + ZTexture* tex = new ZTexture(nParent); tex->width = nWidth; tex->height = nHeight; @@ -74,19 +75,20 @@ ZTexture* ZTexture::FromBinary(TextureType nType, std::vector nRawData, tex->outName = nName; tex->rawDataIndex = nRawDataIndex; - int dataEnd = tex->rawDataIndex + tex->GetRawDataSize(); + size_t dataEnd = tex->rawDataIndex + tex->GetRawDataSize(); tex->rawData = vector(nRawData.data() + tex->rawDataIndex, nRawData.data() + dataEnd); tex->FixRawData(); + tex->CalcHash(); tex->PrepareBitmap(); return tex; } -// BUILD MODE +// Build Source File Mode ZTexture* ZTexture::BuildFromXML(XMLElement* reader, string inFolder, bool readFile) { - ZTexture* tex = new ZTexture(); + ZTexture* tex = new ZTexture(nullptr); tex->ParseXML(reader); @@ -98,13 +100,13 @@ ZTexture* ZTexture::BuildFromXML(XMLElement* reader, string inFolder, bool readF ZTexture* ZTexture::FromPNG(string pngFilePath, TextureType texType) { - int comp; - ZTexture* tex = new ZTexture(); + int32_t comp; + ZTexture* tex = new ZTexture(nullptr); tex->type = texType; tex->name = StringHelper::Split(Path::GetFileNameWithoutExtension(pngFilePath), ".")[0]; - tex->bmpRgb = - (uint8_t*)stbi_load((pngFilePath).c_str(), &tex->width, &tex->height, &comp, STBI_rgb); + tex->bmpRgb = (uint8_t*)stbi_load((pngFilePath).c_str(), (int*)&tex->width, (int*)&tex->height, + &comp, STBI_rgb); stbi_image_free(tex->bmpRgb); tex->bmpRgb = nullptr; tex->rawData = vector(tex->GetRawDataSize()); @@ -149,7 +151,7 @@ ZTexture* ZTexture::FromPNG(string pngFilePath, TextureType texType) ZTexture* ZTexture::FromHLTexture(HLTexture* hlTex) { - ZTexture* tex = new ZTexture(); + ZTexture* tex = new ZTexture(nullptr); tex->width = hlTex->width; tex->height = hlTex->height; @@ -163,10 +165,23 @@ void ZTexture::ParseXML(XMLElement* reader) ZResource::ParseXML(reader); if (reader->Attribute("Width") != nullptr) + { width = atoi(reader->Attribute("Width")); + } + else + { + throw std::runtime_error("Width == nullptr for asset " + (string)reader->Attribute("Name")); + } if (reader->Attribute("Height") != nullptr) + { height = atoi(reader->Attribute("Height")); + } + else + { + throw std::runtime_error("Height == nullptr for asset " + + (string)reader->Attribute("Name")); + } string formatStr = reader->Attribute("Format"); @@ -196,12 +211,25 @@ void ZTexture::FixRawData() rawData[i + 1] = tmp; } } + + isRawDataFixed = !isRawDataFixed; } void ZTexture::PrepareBitmap() { - bmpRgb = new uint8_t[width * height * 3]; - bmpRgba = new uint8_t[width * height * 4]; + switch (type) + { + case TextureType::RGBA16bpp: + case TextureType::RGBA32bpp: + case TextureType::GrayscaleAlpha4bpp: + case TextureType::GrayscaleAlpha8bpp: + case TextureType::GrayscaleAlpha16bpp: + bmpRgba = new uint8_t[width * height * 4]; + break; + default: + bmpRgb = new uint8_t[width * height * 3]; + break; + } switch (type) { @@ -239,11 +267,11 @@ void ZTexture::PrepareBitmap() void ZTexture::PrepareBitmapRGBA16() { - for (int y = 0; y < height; y++) + for (int32_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (int32_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 2; + int32_t pos = ((y * width) + x) * 2; short data = (short)((rawData[pos + 1] << 8) + rawData[pos]); uint8_t r = (uint8_t)((data & 0xF800) >> 11); uint8_t g = (uint8_t)((data & 0x07C0) >> 6); @@ -260,11 +288,11 @@ void ZTexture::PrepareBitmapRGBA16() void ZTexture::PrepareBitmapRGBA32() { - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 4; + uint16_t pos = ((y * width) + x) * 4; bmpRgba[(((y * width) + x) * 4) + 0] = rawData[pos + 2]; bmpRgba[(((y * width) + x) * 4) + 1] = rawData[pos + 1]; @@ -276,19 +304,19 @@ void ZTexture::PrepareBitmapRGBA32() void ZTexture::PrepareBitmapGrayscale4() { - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x += 2) + for (uint16_t x = 0; x < width; x += 2) { - for (int i = 0; i < 2; i++) + for (uint8_t i = 0; i < 2; i++) { - int pos = ((y * width) + x) / 2; + uint16_t pos = ((y * width) + x) / 2; uint8_t grayscale = 0; if (i == 0) - grayscale = (uint8_t)(rawData[pos] & 0xF0); + grayscale = rawData[pos] & 0xF0; else - grayscale = (uint8_t)((rawData[pos] & 0x0F) << 4); + grayscale = (rawData[pos] & 0x0F) << 4; bmpRgb[(((y * width) + x + i) * 3) + 0] = grayscale; bmpRgb[(((y * width) + x + i) * 3) + 1] = grayscale; @@ -300,11 +328,11 @@ void ZTexture::PrepareBitmapGrayscale4() void ZTexture::PrepareBitmapGrayscale8() { - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 1; + uint16_t pos = ((y * width) + x) * 1; bmpRgb[(((y * width) + x) * 3) + 0] = rawData[pos]; bmpRgb[(((y * width) + x) * 3) + 1] = rawData[pos]; @@ -315,22 +343,22 @@ void ZTexture::PrepareBitmapGrayscale8() void ZTexture::PrepareBitmapGrayscaleAlpha4() { - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x += 2) + for (uint16_t x = 0; x < width; x += 2) { - for (int i = 0; i < 2; i++) + for (uint16_t i = 0; i < 2; i++) { - int pos = ((y * width) + x) / 2; + uint16_t pos = ((y * width) + x) / 2; uint8_t data = 0; if (i == 0) - data = (uint8_t)((rawData[pos] & 0xF0) >> 4); + data = (rawData[pos] & 0xF0) >> 4; else - data = (uint8_t)(rawData[pos] & 0x0F); + data = rawData[pos] & 0x0F; - uint8_t grayscale = (uint8_t)(((data & 0x0E) >> 1) * 32); - uint8_t alpha = (uint8_t)((data & 0x01) * 255); + uint8_t grayscale = ((data & 0x0E) >> 1) * 32; + uint8_t alpha = (data & 0x01) * 255; bmpRgba[(((y * width) + x + i) * 4) + 0] = grayscale; bmpRgba[(((y * width) + x + i) * 4) + 1] = grayscale; @@ -343,13 +371,13 @@ void ZTexture::PrepareBitmapGrayscaleAlpha4() void ZTexture::PrepareBitmapGrayscaleAlpha8() { - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 1; - uint8_t grayscale = (uint8_t)(rawData[pos] & 0xF0); - uint8_t alpha = (uint8_t)((rawData[pos] & 0x0F) << 4); + uint16_t pos = ((y * width) + x) * 1; + uint8_t grayscale = rawData[pos] & 0xF0; + uint8_t alpha = (rawData[pos] & 0x0F) << 4; bmpRgba[(((y * width) + x) * 4) + 0] = grayscale; bmpRgba[(((y * width) + x) * 4) + 1] = grayscale; @@ -361,11 +389,11 @@ void ZTexture::PrepareBitmapGrayscaleAlpha8() void ZTexture::PrepareBitmapGrayscaleAlpha16() { - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 2; + uint16_t pos = ((y * width) + x) * 2; uint8_t grayscale = rawData[pos + 0]; uint8_t alpha = rawData[pos + 1]; @@ -379,19 +407,19 @@ void ZTexture::PrepareBitmapGrayscaleAlpha16() void ZTexture::PrepareBitmapPalette4() { - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x += 2) + for (uint16_t x = 0; x < width; x += 2) { - for (int i = 0; i < 2; i++) + for (uint16_t i = 0; i < 2; i++) { - int pos = ((y * width) + x) / 2; + uint16_t pos = ((y * width) + x) / 2; uint8_t paletteIndex = 0; if (i == 0) - paletteIndex = (uint8_t)((rawData[pos] & 0xF0) >> 4); + paletteIndex = (rawData[pos] & 0xF0) >> 4; else - paletteIndex = (uint8_t)((rawData[pos] & 0x0F)); + paletteIndex = (rawData[pos] & 0x0F); bmpRgb[(((y * width) + x + i) * 3) + 0] = paletteIndex * 16; bmpRgb[(((y * width) + x + i) * 3) + 1] = paletteIndex * 16; @@ -403,11 +431,11 @@ void ZTexture::PrepareBitmapPalette4() void ZTexture::PrepareBitmapPalette8() { - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 1; + uint16_t pos = ((y * width) + x) * 1; bmpRgb[(((y * width) + x) * 3) + 0] = rawData[pos]; bmpRgb[(((y * width) + x) * 3) + 1] = rawData[pos]; @@ -456,45 +484,45 @@ void ZTexture::PrepareRawData(string inFolder) void ZTexture::PrepareRawDataRGBA16(string rgbaPath) { - int width; - int height; - int comp; + int32_t width; + int32_t height; + int32_t comp; bmpRgba = (uint8_t*)stbi_load(rgbaPath.c_str(), &width, &height, &comp, STBI_rgb_alpha); - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 2; + uint16_t pos = ((y * width) + x) * 2; - uint8_t r = (uint8_t)(bmpRgba[(((y * width) + x) * 4) + 0] / 8); - uint8_t g = (uint8_t)(bmpRgba[(((y * width) + x) * 4) + 1] / 8); - uint8_t b = (uint8_t)(bmpRgba[(((y * width) + x) * 4) + 2] / 8); + uint8_t r = bmpRgba[(((y * width) + x) * 4) + 0] / 8; + uint8_t g = bmpRgba[(((y * width) + x) * 4) + 1] / 8; + uint8_t b = bmpRgba[(((y * width) + x) * 4) + 2] / 8; - uint8_t alphaBit = (bmpRgba[(((y * width) + x) * 4) + 3] != 0); + uint8_t alphaBit = bmpRgba[(((y * width) + x) * 4) + 3] != 0; - uint16_t data = (uint16_t)((r << 11) + (g << 6) + (b << 1) + alphaBit); + uint16_t data = (r << 11) + (g << 6) + (b << 1) + alphaBit; - rawData[pos + 0] = (uint8_t)((data & 0xFF00) >> 8); - rawData[pos + 1] = (uint8_t)((data & 0x00FF)); + rawData[pos + 0] = (data & 0xFF00) >> 8; + rawData[pos + 1] = (data & 0x00FF); } } } void ZTexture::PrepareRawDataRGBA32(string rgbaPath) { - int width; - int height; - int comp; + int32_t width; + int32_t height; + int32_t comp; bmpRgba = (uint8_t*)stbi_load(rgbaPath.c_str(), &width, &height, &comp, STBI_rgb_alpha); - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 4; + uint16_t pos = ((y * width) + x) * 4; rawData[pos + 0] = bmpRgba[(((y * width) + x) * 4) + 0]; rawData[pos + 1] = bmpRgba[(((y * width) + x) * 4) + 1]; @@ -506,19 +534,19 @@ void ZTexture::PrepareRawDataRGBA32(string rgbaPath) void ZTexture::PrepareRawDataGrayscale4(string grayPath) { - int width; - int height; - int comp; + int32_t width; + int32_t height; + int32_t comp; bmpRgb = (uint8_t*)stbi_load(grayPath.c_str(), &width, &height, &comp, STBI_rgb); - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x += 2) + for (uint16_t x = 0; x < width; x += 2) { - int pos = ((y * width) + x) / 2; - uint8_t r1 = (uint8_t)(bmpRgb[(((y * width) + x) * 3) + 0]); - uint8_t r2 = (uint8_t)(bmpRgb[(((y * width) + x + 1) * 3) + 0]); + uint16_t pos = ((y * width) + x) / 2; + uint8_t r1 = bmpRgb[(((y * width) + x) * 3) + 0]; + uint8_t r2 = bmpRgb[(((y * width) + x + 1) * 3) + 0]; rawData[pos] = (uint8_t)(((r1 / 16) << 4) + (r2 / 16)); } @@ -527,17 +555,17 @@ void ZTexture::PrepareRawDataGrayscale4(string grayPath) void ZTexture::PrepareRawDataGrayscale8(string grayPath) { - int width; - int height; - int comp; + int32_t width; + int32_t height; + int32_t comp; bmpRgb = (uint8_t*)stbi_load(grayPath.c_str(), &width, &height, &comp, STBI_rgb); - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x); + uint16_t pos = (y * width) + x; rawData[pos] = bmpRgb[(((y * width) + x) * 3) + 0]; } } @@ -545,28 +573,28 @@ void ZTexture::PrepareRawDataGrayscale8(string grayPath) void ZTexture::PrepareRawDataGrayscaleAlpha4(string grayAlphaPath) { - int width; - int height; - int comp; + int32_t width; + int32_t height; + int32_t comp; bmpRgba = (uint8_t*)stbi_load(grayAlphaPath.c_str(), &width, &height, &comp, STBI_rgb_alpha); - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x += 2) + for (uint16_t x = 0; x < width; x += 2) { - int pos = ((y * width) + x) / 2; + uint16_t pos = ((y * width) + x) / 2; uint8_t data = 0; - for (int i = 0; i < 2; i++) + for (uint16_t i = 0; i < 2; i++) { uint8_t cR = bmpRgba[(((y * width) + x + i) * 4) + 0]; - uint8_t alphaBit = (bmpRgba[(((y * width) + x + i) * 4) + 3] != 0); + uint8_t alphaBit = bmpRgba[(((y * width) + x + i) * 4) + 3] != 0; if (i == 0) - data += (uint8_t)((((cR / 32) << 1) + alphaBit) << 4); + data += (((cR / 32) << 1) + alphaBit) << 4; else - data += (uint8_t)(((cR / 32) << 1) + alphaBit); + data += ((cR / 32) << 1) + alphaBit; } rawData[pos] = data; @@ -576,84 +604,84 @@ void ZTexture::PrepareRawDataGrayscaleAlpha4(string grayAlphaPath) void ZTexture::PrepareRawDataGrayscaleAlpha8(string grayAlphaPath) { - int width; - int height; - int comp; + int32_t width; + int32_t height; + int32_t comp; bmpRgba = (uint8_t*)stbi_load(grayAlphaPath.c_str(), &width, &height, &comp, STBI_rgb_alpha); - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 1; + uint16_t pos = ((y * width) + x) * 1; - uint8_t r = (uint8_t)(bmpRgba[(((y * width) + x) * 4) + 0]); - uint8_t a = (uint8_t)(bmpRgba[(((y * width) + x) * 4) + 3]); + uint8_t r = bmpRgba[(((y * width) + x) * 4) + 0]; + uint8_t a = bmpRgba[(((y * width) + x) * 4) + 3]; - rawData[pos] = (uint8_t)(((r / 16) << 4) + (a / 16)); + rawData[pos] = ((r / 16) << 4) + (a / 16); } } } void ZTexture::PrepareRawDataGrayscaleAlpha16(string grayAlphaPath) { - int width; - int height; - int comp; + int32_t width; + int32_t height; + int32_t comp; bmpRgba = (uint8_t*)stbi_load(grayAlphaPath.c_str(), &width, &height, &comp, STBI_rgb_alpha); - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x) * 2; + uint16_t pos = ((y * width) + x) * 2; uint8_t cR = bmpRgba[(((y * width) + x) * 4) + 0]; uint8_t aR = bmpRgba[(((y * width) + x) * 4) + 3]; - rawData[pos + 0] = (uint8_t)(cR); - rawData[pos + 1] = (uint8_t)(aR); + rawData[pos + 0] = cR; + rawData[pos + 1] = aR; } } } void ZTexture::PrepareRawDataPalette4(string palPath) { - int width; - int height; - int comp; + int32_t width; + int32_t height; + int32_t comp; bmpRgb = (uint8_t*)stbi_load(palPath.c_str(), &width, &height, &comp, STBI_rgb); - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x += 2) + for (uint16_t x = 0; x < width; x += 2) { - int pos = ((y * width) + x) / 2; + uint16_t pos = ((y * width) + x) / 2; uint8_t cR1 = bmpRgb[(((y * width) + x) * 3) + 0]; uint8_t cR2 = bmpRgb[(((y * width) + x + 1) * 3) + 0]; - rawData[pos] = (uint8_t)(((cR1 / 16) << 4) + (cR2 / 16)); + rawData[pos] = ((cR1 / 16) << 4) + (cR2 / 16); } } } void ZTexture::PrepareRawDataPalette8(string palPath) { - int width; - int height; - int comp; + int32_t width; + int32_t height; + int32_t comp; bmpRgb = (uint8_t*)stbi_load(palPath.c_str(), &width, &height, &comp, STBI_rgb); - for (int y = 0; y < height; y++) + for (uint16_t y = 0; y < height; y++) { - for (int x = 0; x < width; x++) + for (uint16_t x = 0; x < width; x++) { - int pos = ((y * width) + x); + uint16_t pos = ((y * width) + x); uint8_t cR = bmpRgb[(((y * width) + x) * 3) + 0]; rawData[pos] = cR; @@ -683,14 +711,9 @@ float ZTexture::GetPixelMultiplyer() } } -vector ZTexture::GetRawData() +size_t ZTexture::GetRawDataSize() { - return rawData; -} - -int ZTexture::GetRawDataSize() -{ - return (int)(width * height * GetPixelMultiplyer()); + return (width * height * GetPixelMultiplyer()); } std::string ZTexture::GetIMFmtFromType() @@ -736,22 +759,22 @@ std::string ZTexture::GetIMSizFromType() } } -int ZTexture::GetWidth() +uint16_t ZTexture::GetWidth() { return width; } -int ZTexture::GetHeight() +uint16_t ZTexture::GetHeight() { return height; } -void ZTexture::SetWidth(int nWidth) +void ZTexture::SetWidth(uint16_t nWidth) { width = nWidth; } -void ZTexture::SetHeight(int nHeight) +void ZTexture::SetHeight(uint16_t nHeight) { height = nHeight; } @@ -763,58 +786,70 @@ TextureType ZTexture::GetTextureType() void ZTexture::Save(const std::string& outFolder) { + // Optionally generate text file containing CRC information. This is going to be a one time + // process for generating the Texture Pool XML. + if (Globals::Instance->testMode) + { + if (hash != 0) + { + File::WriteAllText(StringHelper::Sprintf("%s/%s.txt", + Globals::Instance->outputPath.c_str(), + outName.c_str()), + StringHelper::Sprintf("%08lX", hash)); + hash = 0; + } + } + + std::string outPath = GetPoolOutPath(outFolder); + + if (!Directory::Exists(outPath)) + Directory::CreateDirectory(outPath); + if (type == TextureType::RGBA32bpp) - stbi_write_png((outFolder + "/" + outName + ".rgba32.png").c_str(), width, height, 4, - bmpRgba, width * 4); + stbi_write_png((outPath + "/" + outName + ".rgba32.png").c_str(), width, height, 4, bmpRgba, + width * 4); else if (type == TextureType::RGBA16bpp) - stbi_write_png((outFolder + "/" + outName + ".rgb5a1.png").c_str(), width, height, 4, - bmpRgba, width * 4); + stbi_write_png((outPath + "/" + outName + ".rgb5a1.png").c_str(), width, height, 4, bmpRgba, + width * 4); else if (type == TextureType::Grayscale8bpp) - stbi_write_png((outFolder + "/" + outName + ".i8.png").c_str(), width, height, 3, bmpRgb, + stbi_write_png((outPath + "/" + outName + ".i8.png").c_str(), width, height, 3, bmpRgb, width * 3); else if (type == TextureType::Grayscale4bpp) - stbi_write_png((outFolder + "/" + outName + ".i4.png").c_str(), width, height, 3, bmpRgb, + stbi_write_png((outPath + "/" + outName + ".i4.png").c_str(), width, height, 3, bmpRgb, width * 3); else if (type == TextureType::GrayscaleAlpha16bpp) - stbi_write_png((outFolder + "/" + outName + ".ia16.png").c_str(), width, height, 4, bmpRgba, + stbi_write_png((outPath + "/" + outName + ".ia16.png").c_str(), width, height, 4, bmpRgba, width * 4); else if (type == TextureType::GrayscaleAlpha8bpp) - stbi_write_png((outFolder + "/" + outName + ".ia8.png").c_str(), width, height, 4, bmpRgba, + stbi_write_png((outPath + "/" + outName + ".ia8.png").c_str(), width, height, 4, bmpRgba, width * 4); else if (type == TextureType::GrayscaleAlpha4bpp) - stbi_write_png((outFolder + "/" + outName + ".ia4.png").c_str(), width, height, 4, bmpRgba, + stbi_write_png((outPath + "/" + outName + ".ia4.png").c_str(), width, height, 4, bmpRgba, width * 4); else if (type == TextureType::Palette4bpp) - stbi_write_png((outFolder + "/" + outName + ".ci4.png").c_str(), width, height, 3, bmpRgb, + stbi_write_png((outPath + "/" + outName + ".ci4.png").c_str(), width, height, 3, bmpRgb, width * 3); else if (type == TextureType::Palette8bpp) - stbi_write_png((outFolder + "/" + outName + ".ci8.png").c_str(), width, height, 3, bmpRgb, + stbi_write_png((outPath + "/" + outName + ".ci8.png").c_str(), width, height, 3, bmpRgb, width * 3); // if (outName != name && outName != "") // File::WriteAllText(outFolder + "/" + outName + ".cfg", name.c_str()); } -// HOTSPOT string ZTexture::GetSourceOutputCode(const std::string& prefix) { sourceOutput = ""; - // sprintf(line, "%s:\n", name.c_str()); - // sourceOutput += line; - - // TODO: TEMP relativePath = "build/assets/" + relativePath; FixRawData(); - // sourceOutput += StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str()); - uint8_t* rawDataArr = rawData.data(); for (size_t i = 0; i < rawData.size(); i += 8) { if (i % 32 == 0) - sourceOutput += "\t"; + sourceOutput += " "; sourceOutput += StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(rawDataArr, i)); @@ -824,10 +859,10 @@ string ZTexture::GetSourceOutputCode(const std::string& prefix) } // Ensure there's always a trailing line feed to prevent dumb warnings. + // Please don't remove this line, unless you somehow made a way to prevent + // that warning when building the OoT repo. sourceOutput += "\n"; - // sourceOutput += "};\n"; - return sourceOutput; } @@ -841,9 +876,23 @@ ZResourceType ZTexture::GetResourceType() return ZResourceType::Texture; } +std::string ZTexture::GetSourceTypeName() +{ + return "u64"; +} + void ZTexture::CalcHash() { - hash = 0; + // Make sure raw data is fixed before we calc the hash... + bool fixFlag = !isRawDataFixed; + + if (fixFlag) + FixRawData(); + + hash = CRC32B(rawData.data(), GetRawDataSize()); + + if (fixFlag) + FixRawData(); } std::string ZTexture::GetExternalExtension() @@ -873,9 +922,16 @@ std::string ZTexture::GetExternalExtension() } } +std::string ZTexture::GetPoolOutPath(std::string defaultValue) +{ + if (Globals::Instance->cfg.texturePool.find(hash) != Globals::Instance->cfg.texturePool.end()) + return Path::GetDirectoryName(Globals::Instance->cfg.texturePool[hash].path); + + return defaultValue; +} + string ZTexture::GetSourceOutputHeader(const std::string& prefix) { - // return StringHelper::Sprintf("extern u64 %s[];\n", name.c_str()); return ""; } diff --git a/tools/ZAPD/ZAPD/ZTexture.h b/tools/ZAPD/ZAPD/ZTexture.h index 3b66d083be..b0a5a85949 100644 --- a/tools/ZAPD/ZAPD/ZTexture.h +++ b/tools/ZAPD/ZAPD/ZTexture.h @@ -24,13 +24,18 @@ class ZTexture : public ZResource { protected: TextureType type; - int width, height; + uint16_t width, height; uint8_t* bmpRgb; uint8_t* bmpRgba; + bool isRawDataFixed; void ParseXML(tinyxml2::XMLElement* reader) override; void FixRawData(); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, + const std::string& nRelPath) override; // Extract Mode + void PrepareBitmap(); void PrepareBitmapRGBA16(); void PrepareBitmapRGBA32(); @@ -52,22 +57,20 @@ protected: void PrepareRawDataPalette4(std::string palPath); void PrepareRawDataPalette8(std::string palPath); float GetPixelMultiplyer(); - bool IsExternalResource() override; - ZResourceType GetResourceType() override; - void CalcHash() override; public: - ZTexture(); + ZTexture(ZFile* nParent); ~ZTexture(); bool isPalette; static ZTexture* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, bool readFile); - static ZTexture* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, - int rawDataIndex, std::string nRelPath); - static ZTexture* FromBinary(TextureType nType, std::vector nRawData, int rawDataIndex, - std::string nName, int nWidth, int nHeight); + // static ZTexture* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector nRawData, + // uint32_t rawDataIndex, std::string nRelPath, ZFile* nParent); + static ZTexture* FromBinary(TextureType nType, std::vector nRawData, + uint32_t rawDataIndex, std::string nName, int32_t nWidth, + int32_t nHeight, ZFile* nParent); static ZTexture* FromPNG(std::string pngFilePath, TextureType texType); static ZTexture* FromHLTexture(HLTexture* hlTex); static TextureType GetTextureTypeFromString(std::string str); @@ -75,15 +78,20 @@ public: std::string GetSourceOutputCode(const std::string& prefix) override; std::string GetSourceOutputHeader(const std::string& prefix) override; - std::vector GetRawData() override; - int GetRawDataSize() override; + size_t GetRawDataSize() override; std::string GetIMFmtFromType(); std::string GetIMSizFromType(); - int GetWidth(); - int GetHeight(); - void SetWidth(int nWidth); - void SetHeight(int nHeight); + uint16_t GetWidth(); + uint16_t GetHeight(); + void SetWidth(uint16_t nWidth); + void SetHeight(uint16_t nHeight); TextureType GetTextureType(); void Save(const std::string& outFolder) override; std::string GetExternalExtension() override; + std::string GetPoolOutPath(std::string defaultValue); + void CalcHash() override; + + bool IsExternalResource() override; + std::string GetSourceTypeName() override; + ZResourceType GetResourceType() override; }; diff --git a/tools/ZAPD/ZAPD/ZVector.cpp b/tools/ZAPD/ZAPD/ZVector.cpp index 68f3739e73..160d2aa80d 100644 --- a/tools/ZAPD/ZAPD/ZVector.cpp +++ b/tools/ZAPD/ZAPD/ZVector.cpp @@ -6,23 +6,32 @@ #include "StringHelper.h" #include "ZFile.h" -ZVector::ZVector() : ZResource() +REGISTER_ZFILENODE(Vector, ZVector); + +ZVector::ZVector(ZFile* nParent) : ZResource(nParent) { scalars = std::vector(); this->scalarType = ZSCALAR_NONE; this->dimensions = 0; } -ZVector* ZVector::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, - const int rawDataIndex, const std::string& nRelPath) +ZVector::~ZVector() { - ZVector* vector = new ZVector(); - vector->rawData = nRawData; - vector->rawDataIndex = rawDataIndex; - vector->ParseXML(reader); - vector->ParseRawData(); + ClearScalars(); +} - return vector; +void ZVector::ClearScalars() +{ + for (auto s : scalars) + delete s; + + scalars.clear(); +} + +void ZVector::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) +{ + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); } void ZVector::ParseXML(tinyxml2::XMLElement* reader) @@ -38,13 +47,13 @@ void ZVector::ParseXML(tinyxml2::XMLElement* reader) void ZVector::ParseRawData() { - int currentRawDataIndex = this->rawDataIndex; + int32_t currentRawDataIndex = this->rawDataIndex; - scalars.clear(); + ClearScalars(); for (uint32_t i = 0; i < this->dimensions; i++) { - ZScalar* scalar = new ZScalar(this->scalarType); + ZScalar* scalar = new ZScalar(this->scalarType, this->parent); scalar->rawDataIndex = currentRawDataIndex; scalar->rawData = this->rawData; scalar->ParseRawData(); @@ -57,11 +66,13 @@ void ZVector::ParseRawData() assert(this->scalars.size() == this->dimensions); } -int ZVector::GetRawDataSize() +size_t ZVector::GetRawDataSize() { - int size = 0; + size_t size = 0; + for (size_t i = 0; i < this->scalars.size(); i++) size += this->scalars[i]->GetRawDataSize(); + return size; } @@ -73,17 +84,11 @@ bool ZVector::DoesSupportArray() std::string ZVector::GetSourceTypeName() { if (dimensions == 3 && scalarType == ZSCALAR_F32) - { return "Vec3f"; - } else if (dimensions == 3 && scalarType == ZSCALAR_S16) - { return "Vec3s"; - } else if (dimensions == 3 && scalarType == ZSCALAR_S32) - { return "Vec3i"; - } else { std::string output = StringHelper::Sprintf( @@ -93,15 +98,17 @@ std::string ZVector::GetSourceTypeName() if (Globals::Instance->verbosity >= VERBOSITY_DEBUG) printf("%s\n", output.c_str()); - throw output; + throw std::runtime_error(output); } } std::string ZVector::GetSourceValue() { std::vector strings = std::vector(); + for (size_t i = 0; i < this->scalars.size(); i++) strings.push_back(scalars[i]->GetSourceValue()); + return "{ " + StringHelper::Implode(strings, ", ") + " }"; } diff --git a/tools/ZAPD/ZAPD/ZVector.h b/tools/ZAPD/ZAPD/ZVector.h index a12ee47a5b..50dd4784c0 100644 --- a/tools/ZAPD/ZAPD/ZVector.h +++ b/tools/ZAPD/ZAPD/ZVector.h @@ -14,20 +14,21 @@ public: ZScalarType scalarType; uint32_t dimensions; - ZVector(); + ZVector(ZFile* nParent); + ~ZVector(); void ParseXML(tinyxml2::XMLElement* reader) override; std::string GetSourceTypeName() override; std::string GetSourceValue(); std::string GetSourceOutputCode(const std::string& prefix) override; void ParseRawData() override; - int GetRawDataSize() override; + size_t GetRawDataSize() override; bool DoesSupportArray() override; ZResourceType GetResourceType() override; - static ZVector* ExtractFromXML(tinyxml2::XMLElement* reader, - const std::vector& nRawData, const int rawDataIndex, - const std::string& nRelPath); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; -protected: +private: + void ClearScalars(); }; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZVtx.cpp b/tools/ZAPD/ZAPD/ZVtx.cpp index c551e0d573..b48015d2d1 100644 --- a/tools/ZAPD/ZAPD/ZVtx.cpp +++ b/tools/ZAPD/ZAPD/ZVtx.cpp @@ -3,7 +3,9 @@ #include "StringHelper.h" #include "ZFile.h" -ZVtx::ZVtx() +REGISTER_ZFILENODE(Vtx, ZVtx); + +ZVtx::ZVtx(ZFile* nParent) : ZResource(nParent) { x = 0; y = 0; @@ -32,8 +34,12 @@ std::string ZVtx::GetSourceOutputCode(const std::string& prefix) 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); + { + Declaration* decl = + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(), + GetSourceTypeName(), name, output); + decl->isExternal = true; + } return ""; } @@ -54,7 +60,7 @@ void ZVtx::ParseRawData() a = data[rawDataIndex + 15]; } -int ZVtx::GetRawDataSize() +size_t ZVtx::GetRawDataSize() { return 16; } @@ -69,13 +75,18 @@ ZResourceType ZVtx::GetResourceType() return ZResourceType::Vertex; } -ZVtx* ZVtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, - const int rawDataIndex, const std::string& nRelPath) +bool ZVtx::IsExternalResource() { - ZVtx* vtx = new ZVtx(); - vtx->rawData = nRawData; - vtx->rawDataIndex = rawDataIndex; - vtx->ParseRawData(); - - return vtx; + return true; +} + +std::string ZVtx::GetExternalExtension() +{ + return "vtx"; +} + +void ZVtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) +{ + ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath); } diff --git a/tools/ZAPD/ZAPD/ZVtx.h b/tools/ZAPD/ZAPD/ZVtx.h index bd40b07e93..dadf838020 100644 --- a/tools/ZAPD/ZAPD/ZVtx.h +++ b/tools/ZAPD/ZAPD/ZVtx.h @@ -15,18 +15,20 @@ public: int16_t s, t; uint8_t r, g, b, a; - ZVtx(); + ZVtx(ZFile* nParent); void ParseXML(tinyxml2::XMLElement* reader) override; std::string GetSourceTypeName() override; std::string GetSourceOutputCode(const std::string& prefix) override; void ParseRawData() override; - int GetRawDataSize() override; + size_t GetRawDataSize() override; bool DoesSupportArray() override; ZResourceType GetResourceType() override; + bool IsExternalResource() override; + virtual std::string GetExternalExtension() override; - static ZVtx* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, - const int rawDataIndex, const std::string& nRelPath); + void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData, + const uint32_t nRawDataIndex, const std::string& nRelPath) override; protected: }; \ No newline at end of file diff --git a/tools/ZAPD/copycheck.py b/tools/ZAPD/copycheck.py new file mode 100644 index 0000000000..a911e877f7 --- /dev/null +++ b/tools/ZAPD/copycheck.py @@ -0,0 +1,7 @@ +import os +from shutil import copyfile + +if (os.environ.get('ZAPD_COPYDIR') != None): + print("Copying ZAPD.out to OoT repo...") + #print(os.environ.get('ZAPD_COPYDIR')) + copyfile("ZAPD.out", os.environ.get('ZAPD_COPYDIR') + "/ZAPD.out") \ No newline at end of file diff --git a/tools/ZAPD/docs/zapd_extraction_xml_reference.md b/tools/ZAPD/docs/zapd_extraction_xml_reference.md new file mode 100644 index 0000000000..86e64fb4c9 --- /dev/null +++ b/tools/ZAPD/docs/zapd_extraction_xml_reference.md @@ -0,0 +1,463 @@ +# ZAPD extraction xml reference + +This document aims to be a small reference of how to create a compatible xml file for ZAPD. + +## Table of contents + +- [ZAPD extraction xml reference](#zapd-extraction-xml-reference) + - [Table of contents](#table-of-contents) + - [Basic XML](#basic-xml) + - [Resources types](#resources-types) + - [File](#file) + - [Texture](#texture) + - [Background](#background) + - [Blob](#blob) + - [DList](#dlist) + - [Scene and Room](#scene-and-room) + - [Animation](#animation) + - [PlayerAnimation](#playeranimation) + - [CurveAnimation](#curveanimation) + - [Skeleton](#skeleton) + - [Limb](#limb) + - [Symbol](#symbol) + - [Collision](#collision) + - [Scalar](#scalar) + - [Vector](#vector) + - [Vtx](#vtx) + - [Mtx](#mtx) + - [Cutscene](#cutscene) + - [Array](#array) + +## Basic XML + +An example of an object xml: + +```xml + + + + + + + + + + + + + + + + + + + +``` + +Every xml must have a `` tag. It must have at least one `` child. + +## Resources types + +The following is a list of the resources/tags supported by ZAPD, and the attributes needed by each one. + +For most resources inside a `` tag **you should also set an `Offset` attribute**. This is the offset (within the file) of the resource you are exporting. The `Offset` attribute is expected to be in hexadecimal, for example `Offset="0x41F0"`. + +It's worth noting that every tag expects a `Name="gNameOfTheAsset"`. This is will be the name of the extracted variable in the output C code. Every asset must be prefixed with `g` and the suffix should represent the type of the variable. + +------------------------- + +### File + +- Example of this tag: + +```xml + +``` + +- Attributes: + + - `Name`: Required. The name of the file in `baserom/` which will be extracted. + - `Segment`: Required. This is the segment number of the current file. Expects a decimal number, usually 6 if it is an object, or 128 for overlays (It's kinda a whacky hack to get around of the `0x80` addresses). + - `BaseAddress`: Optional. RAM address of the file. Expects a hex number (with `0x` prefix). Default value: `0`. + - `RangeStart`: Optional. File offset where the extraction will begin. Hex. Default value: `0x000000000`. + - `RangeEnd`: Optional. File offset where the extraction will end. Hex. Default value: `0xFFFFFFFF`. + - `Game`: Optional. Valid values: `OOT`, `MM`, `SW97` and `OOTSW97`. Default value: `OOT`. + +------------------------- + +### Texture + +Textures are extracted as `.png` files. + +- Example: + +```xml + +``` + +Will be defined as: + +```c +u64 gCraterSmokeConeTex[] = { +#include "assets/objects/object_spot17_obj/crater_smoke_cone.ia8.inc.c" +}; +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Tex`, unless it is a palette, in that case it is suffixed by `TLUT`. + - `OutName`: Required. The filename of the extracted `.png` file. + - `Format`: Required. The format of the image. Valid values: `rgba32`, `rgb5a1`, `i4`, `i8`, `ia4`, `ia8`, `ia16`, `ci4` and `ci8`. + - `Width`: Required. Width in pixels of the image. + - `Height`: Required. Height in pixels of the image. + +The following is a list of the texture formats the Nintendo 64 supports, with their gfxdis names and ZAPD format names. + +| Format name | Typing in `gsDPLoadTextureBlock` | "Format" in xml | +| ----------------------------------------------- | -------------------------------- | --------------- | +| 4-bit intensity (I) | `G_IM_FMT_I, G_IM_SIZ_4b` | `i4` | +| 4-bit intensity with alpha (I/A) (3/1) | `G_IM_FMT_IA, G_IM_SIZ_4b` | `ia4` | +| 4-bit color index (CI) | `G_IM_FMT_CI, G_IM_SIZ_4b` | `ci4` | +| 8-bit I | `G_IM_FMT_I, G_IM_SIZ_8b` | `i8` | +| 8-bit IA (4/4) | `G_IM_FMT_IA, G_IM_SIZ_8b` | `ia8` | +| 8-bit CI | `G_IM_FMT_CI, G_IM_SIZ_8b` | `ci8` | +| 16-bit red, green, blue, alpha (RGBA) (5/5/5/1) | `G_IM_FMT_RGBA, G_IM_SIZ_16b` | `rgb5a1` | +| 16-bit IA (8/8) | `G_IM_FMT_IA, G_IM_SIZ_16b` | `ia16` | +| 16-bit YUV (Luminance, Blue-Y, Red-Y) | `G_IM_FMT_YUV, G_IM_SIZ_16b` | (not used) | +| 32-bit RGBA (8/8/8/8) | `G_IM_FMT_RGBA, G_IM_SIZ_32b` | `rgba8` | + +If you want to know more about this formats, you can check [`gsDPLoadTextureBlock`](http://n64devkit.square7.ch/n64man/gdp/gDPLoadTextureBlock.htm) for most formats, or [`gDPLoadTextureBlock_4b`](http://n64devkit.square7.ch/n64man/gdp/gDPLoadTextureBlock_4b.htm) for the 4-bit formats. + +------------------------- + +### Background + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Background`. + - `OutName`: Required. The filename of the extracted `.jpg` file. + +※ Explicit use of this tag isn't often necesary because it would probably be extracted automatically by another extracted element. You can use this to name them if you don't like the autogenerated name. + +------------------------- + +### Blob + +Blob are binary data that will be extracted as `.bin` files. + +- Example: + +```xml + +``` + +Will be defined as: + +```c + +u8 gFireTempleBlob_00CCC0[] = { +#include "assets/objects/object_hidan_objects/gFireTempleBlob_00CCC0.bin.inc.c" +}; +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Blob`. + - `Size`: Required. Amount of bytes to extract. Hex. + +※ We usually use blobs when we can't figure out the content's type of chunk of data. + +------------------------- + +### DList + +A.k.a. Display list, or Gfx. + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `DL`. + +------------------------- + +### Scene and Room + +TODO. I'm hoping somebody else will do this. + +------------------------- + +### Animation + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Anim`. + +------------------------- + +### PlayerAnimation + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Anim`. + +------------------------- + +### CurveAnimation + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Anim`. + - `SkelOffset`: Required. Offset of the `CurveSkeleton` (I.e. a [`Skeleton`](#skeleton) resource with `Type="Curve"`) related to this animation. + +------------------------- + +### Skeleton + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Skel`. + - `Type`: Required. Valid values: `Normal`, `Flex` and `Curve`. + - `LimbType`: Required. Valid values: `Standard`, `LOD`, `Skin` and `Curve`. + +※ There are no restrictions in the `Type` and `LimbType` attributes besides the valid values, so any skeleton type can be combined with any limb type. + +------------------------- + +### Limb + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Limb`. + - `LimbType`: Required. Valid values: `Standard`, `LOD`, `Skin` and `Curve`. + +------------------------- + +### Symbol + +A special element that allows declaring a variable without actually extracting it from the current file. Useful when a resource references an element from another file. The symbol will be declared as `extern`. + +- Example: + +```xml + +``` + +Will be declared as: + +```c +extern u8 gJsjutanShadowTex[2048]; +``` + +- Attributes: + + - `Type`: The type of the declared variable. If missing, it will default to `void*`. + - `TypeSize`: The size in bytes of the type. If missing, it will default to `4` (the size of a word and a pointer). Integer or hex value. + - `Count`: Optional. If it is present, the variable will be declared as an array instead of a plain variable. The value of this attribute specifies the length of the array. If `Count` is present but it has no value (`Count=""`), then the length of the array will not be specified either in the declared variable. Integer or hex value. + +------------------------- + +### Collision + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Col`. + +------------------------- + +### Scalar + +Allows the extraction of a single number. + +- Example: + +```xml + +``` + +Will be extracted as: + +```c +u64 pad34F8 = { 0 }; +``` + +- Attributes: + + - `Name`: Required. Suxffixed by ~~`TBD`~~. + - `Type`: Required. Valid values: `s8`, `u8`, `s16`, `u16`, `s32`, `u32`, `s64`, `u64`, `f32` and `f64`. + +※ Can be wrapped in an [`Array`](#array) tag. + +------------------------- + +### Vector + +Extracts a vector. + +Current supported types are `Vec3s`, `Vec3i` or `Vec3f`. + +- Example: + +```xml + + + +``` + +Will be extracted as: + +```c +Vec3s D_04002040[24] = { + { -37, 2346, 93 }, + { 0, 11995, 0 }, + { -16385, -305, -16333 }, + { 0, 51, 12 }, + { 3761, 2263, -384 }, + { 0, 0, 3786 }, + { 1594, 1384, -18344 }, + { -2288, -2428, -1562 }, + { 0, 0, 3219 }, + { -2148, -5, -16840 }, + { 15365, -1708, 15611 }, + { 1761, 8365, 17711 }, + { 0, 0, 18859 }, + { 0, 0, 0 }, + { -9392, -9579, 28686 }, + { 0, 0, -7093 }, + { -2748, 685, -14092 }, + { 213, 6553, -32212 }, + { 0, 0, -1877 }, + { 3267, 3309, -16090 }, + { -18101, 25946, -2670 }, + { -104, 0, 0 }, + { 0, 0, 0 }, + { 0, 0, 0 } +}; +``` + +- Attributes: + + - `Name`: Required. Suxffixed by ~~`TBD`~~. + - `Type`: Required. Specifies the vector's type (`Vec3s`, `Vec3i` and `Vec3f`). Valid values: `s16`, `s32` and `f32`. + - `Dimensions`: Required. The amount of dimensions of the vector. Valid values: `3`. + +※ Can be wrapped in an [`Array`](#array) tag. + +------------------------- + +### Vtx + +- Example: + +```xml + + + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Vtx`. + +※ Can be wrapped in an [`Array`](#array) tag. + +------------------------- + +### Mtx + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Mtx`. + +※ Explicit use of this tag isn't often necesary because it would probably be extracted automatically by another extracted element. + +------------------------- + +### Cutscene + +- Example: + +```xml + +``` + +- Attributes: + + - `Name`: Required. Suxffixed by `Cs`. + +※ Explicit use of this tag isn't often necesary because it would probably be extracted automatically by another extracted element. + +------------------------- + +### Array + +The `Array` element is special, because it needs an inner element to work. It will declare an array of its inner element. + +Currently, only [`Scalar`](#scalar), [`Vector`](#vector) and [`Vtx`](#vtx) support being wrapped in an array. + +- Example: + +```xml + + + +``` + +- Attributes: + + - `Name`: Required. How the variable will be named. By our convention it should be prefixed by `g`. The sufix is mandated by the element contained. + - `Count`: Required. Amount of elements. Integer. + +------------------------- diff --git a/tools/ZAPD/lib/json/include/nlohmann/json.hpp b/tools/ZAPD/lib/json/include/nlohmann/json.hpp index c9af0bed36..d989ebb908 100644 --- a/tools/ZAPD/lib/json/include/nlohmann/json.hpp +++ b/tools/ZAPD/lib/json/include/nlohmann/json.hpp @@ -6390,7 +6390,7 @@ class output_stream_adapter : public output_adapter_protocol void write_characters(const CharType* s, std::size_t length) override { - stream.write(s, static_cast(length)); + stream.Write(s, static_cast(length)); } private: @@ -10974,7 +10974,7 @@ class serializer void dump(const BasicJsonType& val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, - const unsigned int current_indent = 0) + const unsigned int currentIndent = 0) { switch (val.m_type) { @@ -10991,7 +10991,7 @@ class serializer o->write_characters("{\n", 2); // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; + const auto new_indent = currentIndent + indent_step; if (JSON_UNLIKELY(indent_string.size() < new_indent)) { indent_string.resize(indent_string.size() * 2, ' '); @@ -11019,7 +11019,7 @@ class serializer dump(i->second, true, ensure_ascii, indent_step, new_indent); o->write_character('\n'); - o->write_characters(indent_string.c_str(), current_indent); + o->write_characters(indent_string.c_str(), currentIndent); o->write_character('}'); } else @@ -11033,7 +11033,7 @@ class serializer o->write_character('\"'); dump_escaped(i->first, ensure_ascii); o->write_characters("\":", 2); - dump(i->second, false, ensure_ascii, indent_step, current_indent); + dump(i->second, false, ensure_ascii, indent_step, currentIndent); o->write_character(','); } @@ -11043,7 +11043,7 @@ class serializer o->write_character('\"'); dump_escaped(i->first, ensure_ascii); o->write_characters("\":", 2); - dump(i->second, false, ensure_ascii, indent_step, current_indent); + dump(i->second, false, ensure_ascii, indent_step, currentIndent); o->write_character('}'); } @@ -11064,7 +11064,7 @@ class serializer o->write_characters("[\n", 2); // variable to hold indentation for recursive calls - const auto new_indent = current_indent + indent_step; + const auto new_indent = currentIndent + indent_step; if (JSON_UNLIKELY(indent_string.size() < new_indent)) { indent_string.resize(indent_string.size() * 2, ' '); @@ -11085,7 +11085,7 @@ class serializer dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent); o->write_character('\n'); - o->write_characters(indent_string.c_str(), current_indent); + o->write_characters(indent_string.c_str(), currentIndent); o->write_character(']'); } else @@ -11096,13 +11096,13 @@ class serializer for (auto i = val.m_value.array->cbegin(); i != val.m_value.array->cend() - 1; ++i) { - dump(*i, false, ensure_ascii, indent_step, current_indent); + dump(*i, false, ensure_ascii, indent_step, currentIndent); o->write_character(','); } // last element assert(not val.m_value.array->empty()); - dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent); + dump(val.m_value.array->back(), false, ensure_ascii, indent_step, currentIndent); o->write_character(']'); } diff --git a/tools/ZAPD/lib/libgfxd/uc_macrofn.c b/tools/ZAPD/lib/libgfxd/uc_macrofn.c index 7baeb707b6..2c70eeed50 100644 --- a/tools/ZAPD/lib/libgfxd/uc_macrofn.c +++ b/tools/ZAPD/lib/libgfxd/uc_macrofn.c @@ -2016,6 +2016,10 @@ UCFUNC int c_DPLoadTLUT(gfxd_macro_t *m, int n_macro) return 0; } +#ifdef _MSC_VER +#pragma warning(disable:4146) +#endif + #if defined(F3DEX_GBI) || defined(F3DEX_GBI_2) UCFUNC int d_BranchZ(gfxd_macro_t *m, uint32_t hi, uint32_t lo) { diff --git a/tools/ZAPDConfigs/MqDbg/ActorList_OoTMqDbg.txt b/tools/ZAPDConfigs/MqDbg/ActorList_OoTMqDbg.txt new file mode 100644 index 0000000000..a0395eb277 --- /dev/null +++ b/tools/ZAPDConfigs/MqDbg/ActorList_OoTMqDbg.txt @@ -0,0 +1,472 @@ +ACTOR_PLAYER +ACTOR_UNSET_1 +ACTOR_EN_TEST +ACTOR_UNSET_3 +ACTOR_EN_GIRLA +ACTOR_UNSET_5 +ACTOR_UNSET_6 +ACTOR_EN_PART +ACTOR_EN_LIGHT +ACTOR_EN_DOOR +ACTOR_EN_BOX +ACTOR_BG_DY_YOSEIZO +ACTOR_BG_HIDAN_FIREWALL +ACTOR_EN_POH +ACTOR_EN_OKUTA +ACTOR_BG_YDAN_SP +ACTOR_EN_BOM +ACTOR_EN_WALLMAS +ACTOR_EN_DODONGO +ACTOR_EN_FIREFLY +ACTOR_EN_HORSE +ACTOR_EN_ITEM00 +ACTOR_EN_ARROW +ACTOR_UNSET_17 +ACTOR_EN_ELF +ACTOR_EN_NIW +ACTOR_UNSET_1A +ACTOR_EN_TITE +ACTOR_EN_REEBA +ACTOR_EN_PEEHAT +ACTOR_EN_BUTTE +ACTOR_UNSET_1F +ACTOR_EN_INSECT +ACTOR_EN_FISH +ACTOR_UNSET_22 +ACTOR_EN_HOLL +ACTOR_EN_SCENE_CHANGE +ACTOR_EN_ZF +ACTOR_EN_HATA +ACTOR_BOSS_DODONGO +ACTOR_BOSS_GOMA +ACTOR_EN_ZL1 +ACTOR_EN_VIEWER +ACTOR_EN_GOMA +ACTOR_BG_PUSHBOX +ACTOR_EN_BUBBLE +ACTOR_DOOR_SHUTTER +ACTOR_EN_DODOJR +ACTOR_EN_BDFIRE +ACTOR_UNSET_31 +ACTOR_EN_BOOM +ACTOR_EN_TORCH2 +ACTOR_EN_BILI +ACTOR_EN_TP +ACTOR_UNSET_36 +ACTOR_EN_ST +ACTOR_EN_BW +ACTOR_EN_A_OBJ +ACTOR_EN_EIYER +ACTOR_EN_RIVER_SOUND +ACTOR_EN_HORSE_NORMAL +ACTOR_EN_OSSAN +ACTOR_BG_TREEMOUTH +ACTOR_BG_DODOAGO +ACTOR_BG_HIDAN_DALM +ACTOR_BG_HIDAN_HROCK +ACTOR_EN_HORSE_GANON +ACTOR_BG_HIDAN_ROCK +ACTOR_BG_HIDAN_RSEKIZOU +ACTOR_BG_HIDAN_SEKIZOU +ACTOR_BG_HIDAN_SIMA +ACTOR_BG_HIDAN_SYOKU +ACTOR_EN_XC +ACTOR_BG_HIDAN_CURTAIN +ACTOR_BG_SPOT00_HANEBASI +ACTOR_EN_MB +ACTOR_EN_BOMBF +ACTOR_EN_ZL2 +ACTOR_BG_HIDAN_FSLIFT +ACTOR_EN_OE2 +ACTOR_BG_YDAN_HASI +ACTOR_BG_YDAN_MARUTA +ACTOR_BOSS_GANONDROF +ACTOR_UNSET_53 +ACTOR_EN_AM +ACTOR_EN_DEKUBABA +ACTOR_EN_M_FIRE1 +ACTOR_EN_M_THUNDER +ACTOR_BG_DDAN_JD +ACTOR_BG_BREAKWALL +ACTOR_EN_JJ +ACTOR_EN_HORSE_ZELDA +ACTOR_BG_DDAN_KD +ACTOR_DOOR_WARP1 +ACTOR_OBJ_SYOKUDAI +ACTOR_ITEM_B_HEART +ACTOR_EN_DEKUNUTS +ACTOR_BG_MENKURI_KAITEN +ACTOR_BG_MENKURI_EYE +ACTOR_EN_VALI +ACTOR_BG_MIZU_MOVEBG +ACTOR_BG_MIZU_WATER +ACTOR_ARMS_HOOK +ACTOR_EN_FHG +ACTOR_BG_MORI_HINERI +ACTOR_EN_BB +ACTOR_BG_TOKI_HIKARI +ACTOR_EN_YUKABYUN +ACTOR_BG_TOKI_SWD +ACTOR_EN_FHG_FIRE +ACTOR_BG_MJIN +ACTOR_BG_HIDAN_KOUSI +ACTOR_DOOR_TOKI +ACTOR_BG_HIDAN_HAMSTEP +ACTOR_EN_BIRD +ACTOR_UNSET_73 +ACTOR_UNSET_74 +ACTOR_UNSET_75 +ACTOR_UNSET_76 +ACTOR_EN_WOOD02 +ACTOR_UNSET_78 +ACTOR_UNSET_79 +ACTOR_UNSET_7A +ACTOR_UNSET_7B +ACTOR_EN_LIGHTBOX +ACTOR_EN_PU_BOX +ACTOR_UNSET_7E +ACTOR_UNSET_7F +ACTOR_EN_TRAP +ACTOR_EN_AROW_TRAP +ACTOR_EN_VASE +ACTOR_UNSET_83 +ACTOR_EN_TA +ACTOR_EN_TK +ACTOR_BG_MORI_BIGST +ACTOR_BG_MORI_ELEVATOR +ACTOR_BG_MORI_KAITENKABE +ACTOR_BG_MORI_RAKKATENJO +ACTOR_EN_VM +ACTOR_DEMO_EFFECT +ACTOR_DEMO_KANKYO +ACTOR_BG_HIDAN_FWBIG +ACTOR_EN_FLOORMAS +ACTOR_EN_HEISHI1 +ACTOR_EN_RD +ACTOR_EN_PO_SISTERS +ACTOR_BG_HEAVY_BLOCK +ACTOR_BG_PO_EVENT +ACTOR_OBJ_MURE +ACTOR_EN_SW +ACTOR_BOSS_FD +ACTOR_OBJECT_KANKYO +ACTOR_EN_DU +ACTOR_EN_FD +ACTOR_EN_HORSE_LINK_CHILD +ACTOR_DOOR_ANA +ACTOR_BG_SPOT02_OBJECTS +ACTOR_BG_HAKA +ACTOR_MAGIC_WIND +ACTOR_MAGIC_FIRE +ACTOR_UNSET_A0 +ACTOR_EN_RU1 +ACTOR_BOSS_FD2 +ACTOR_EN_FD_FIRE +ACTOR_EN_DH +ACTOR_EN_DHA +ACTOR_EN_RL +ACTOR_EN_ENCOUNT1 +ACTOR_DEMO_DU +ACTOR_DEMO_IM +ACTOR_DEMO_TRE_LGT +ACTOR_EN_FW +ACTOR_BG_VB_SIMA +ACTOR_EN_VB_BALL +ACTOR_BG_HAKA_MEGANE +ACTOR_BG_HAKA_MEGANEBG +ACTOR_BG_HAKA_SHIP +ACTOR_BG_HAKA_SGAMI +ACTOR_UNSET_B2 +ACTOR_EN_HEISHI2 +ACTOR_EN_ENCOUNT2 +ACTOR_EN_FIRE_ROCK +ACTOR_EN_BROB +ACTOR_MIR_RAY +ACTOR_BG_SPOT09_OBJ +ACTOR_BG_SPOT18_OBJ +ACTOR_BOSS_VA +ACTOR_BG_HAKA_TUBO +ACTOR_BG_HAKA_TRAP +ACTOR_BG_HAKA_HUTA +ACTOR_BG_HAKA_ZOU +ACTOR_BG_SPOT17_FUNEN +ACTOR_EN_SYATEKI_ITM +ACTOR_EN_SYATEKI_MAN +ACTOR_EN_TANA +ACTOR_EN_NB +ACTOR_BOSS_MO +ACTOR_EN_SB +ACTOR_EN_BIGOKUTA +ACTOR_EN_KAREBABA +ACTOR_BG_BDAN_OBJECTS +ACTOR_DEMO_SA +ACTOR_DEMO_GO +ACTOR_EN_IN +ACTOR_EN_TR +ACTOR_BG_SPOT16_BOMBSTONE +ACTOR_UNSET_CE +ACTOR_BG_HIDAN_KOWARERUKABE +ACTOR_BG_BOMBWALL +ACTOR_BG_SPOT08_ICEBLOCK +ACTOR_EN_RU2 +ACTOR_OBJ_DEKUJR +ACTOR_BG_MIZU_UZU +ACTOR_BG_SPOT06_OBJECTS +ACTOR_BG_ICE_OBJECTS +ACTOR_BG_HAKA_WATER +ACTOR_UNSET_D8 +ACTOR_EN_MA2 +ACTOR_EN_BOM_CHU +ACTOR_EN_HORSE_GAME_CHECK +ACTOR_BOSS_TW +ACTOR_EN_RR +ACTOR_EN_BA +ACTOR_EN_BX +ACTOR_EN_ANUBICE +ACTOR_EN_ANUBICE_FIRE +ACTOR_BG_MORI_HASHIGO +ACTOR_BG_MORI_HASHIRA4 +ACTOR_BG_MORI_IDOMIZU +ACTOR_BG_SPOT16_DOUGHNUT +ACTOR_BG_BDAN_SWITCH +ACTOR_EN_MA1 +ACTOR_BOSS_GANON +ACTOR_BOSS_SST +ACTOR_UNSET_EA +ACTOR_UNSET_EB +ACTOR_EN_NY +ACTOR_EN_FR +ACTOR_ITEM_SHIELD +ACTOR_BG_ICE_SHELTER +ACTOR_EN_ICE_HONO +ACTOR_ITEM_OCARINA +ACTOR_UNSET_F2 +ACTOR_UNSET_F3 +ACTOR_MAGIC_DARK +ACTOR_DEMO_6K +ACTOR_EN_ANUBICE_TAG +ACTOR_BG_HAKA_GATE +ACTOR_BG_SPOT15_SAKU +ACTOR_BG_JYA_GOROIWA +ACTOR_BG_JYA_ZURERUKABE +ACTOR_UNSET_FB +ACTOR_BG_JYA_COBRA +ACTOR_BG_JYA_KANAAMI +ACTOR_FISHING +ACTOR_OBJ_OSHIHIKI +ACTOR_BG_GATE_SHUTTER +ACTOR_EFF_DUST +ACTOR_BG_SPOT01_FUSYA +ACTOR_BG_SPOT01_IDOHASHIRA +ACTOR_BG_SPOT01_IDOMIZU +ACTOR_BG_PO_SYOKUDAI +ACTOR_BG_GANON_OTYUKA +ACTOR_BG_SPOT15_RRBOX +ACTOR_BG_UMAJUMP +ACTOR_UNSET_109 +ACTOR_ARROW_FIRE +ACTOR_ARROW_ICE +ACTOR_ARROW_LIGHT +ACTOR_UNSET_10D +ACTOR_UNSET_10E +ACTOR_ITEM_ETCETERA +ACTOR_OBJ_KIBAKO +ACTOR_OBJ_TSUBO +ACTOR_EN_WONDER_ITEM +ACTOR_EN_IK +ACTOR_DEMO_IK +ACTOR_EN_SKJ +ACTOR_EN_SKJNEEDLE +ACTOR_EN_G_SWITCH +ACTOR_DEMO_EXT +ACTOR_DEMO_SHD +ACTOR_EN_DNS +ACTOR_ELF_MSG +ACTOR_EN_HONOTRAP +ACTOR_EN_TUBO_TRAP +ACTOR_OBJ_ICE_POLY +ACTOR_BG_SPOT03_TAKI +ACTOR_BG_SPOT07_TAKI +ACTOR_EN_FZ +ACTOR_EN_PO_RELAY +ACTOR_BG_RELAY_OBJECTS +ACTOR_EN_DIVING_GAME +ACTOR_EN_KUSA +ACTOR_OBJ_BEAN +ACTOR_OBJ_BOMBIWA +ACTOR_UNSET_128 +ACTOR_UNSET_129 +ACTOR_OBJ_SWITCH +ACTOR_OBJ_ELEVATOR +ACTOR_OBJ_LIFT +ACTOR_OBJ_HSBLOCK +ACTOR_EN_OKARINA_TAG +ACTOR_EN_YABUSAME_MARK +ACTOR_EN_GOROIWA +ACTOR_EN_EX_RUPPY +ACTOR_EN_TORYO +ACTOR_EN_DAIKU +ACTOR_UNSET_134 +ACTOR_EN_NWC +ACTOR_EN_BLKOBJ +ACTOR_ITEM_INBOX +ACTOR_EN_GE1 +ACTOR_OBJ_BLOCKSTOP +ACTOR_EN_SDA +ACTOR_EN_CLEAR_TAG +ACTOR_EN_NIW_LADY +ACTOR_EN_GM +ACTOR_EN_MS +ACTOR_EN_HS +ACTOR_BG_INGATE +ACTOR_EN_KANBAN +ACTOR_EN_HEISHI3 +ACTOR_EN_SYATEKI_NIW +ACTOR_EN_ATTACK_NIW +ACTOR_BG_SPOT01_IDOSOKO +ACTOR_EN_SA +ACTOR_EN_WONDER_TALK +ACTOR_BG_GJYO_BRIDGE +ACTOR_EN_DS +ACTOR_EN_MK +ACTOR_EN_BOM_BOWL_MAN +ACTOR_EN_BOM_BOWL_PIT +ACTOR_EN_OWL +ACTOR_EN_ISHI +ACTOR_OBJ_HANA +ACTOR_OBJ_LIGHTSWITCH +ACTOR_OBJ_MURE2 +ACTOR_EN_GO +ACTOR_EN_FU +ACTOR_UNSET_154 +ACTOR_EN_CHANGER +ACTOR_BG_JYA_MEGAMI +ACTOR_BG_JYA_LIFT +ACTOR_BG_JYA_BIGMIRROR +ACTOR_BG_JYA_BOMBCHUIWA +ACTOR_BG_JYA_AMISHUTTER +ACTOR_BG_JYA_BOMBIWA +ACTOR_BG_SPOT18_BASKET +ACTOR_UNSET_15D +ACTOR_EN_GANON_ORGAN +ACTOR_EN_SIOFUKI +ACTOR_EN_STREAM +ACTOR_UNSET_161 +ACTOR_EN_MM +ACTOR_EN_KO +ACTOR_EN_KZ +ACTOR_EN_WEATHER_TAG +ACTOR_BG_SST_FLOOR +ACTOR_EN_ANI +ACTOR_EN_EX_ITEM +ACTOR_BG_JYA_IRONOBJ +ACTOR_EN_JS +ACTOR_EN_JSJUTAN +ACTOR_EN_CS +ACTOR_EN_MD +ACTOR_EN_HY +ACTOR_EN_GANON_MANT +ACTOR_EN_OKARINA_EFFECT +ACTOR_EN_MAG +ACTOR_DOOR_GERUDO +ACTOR_ELF_MSG2 +ACTOR_DEMO_GT +ACTOR_EN_PO_FIELD +ACTOR_EFC_ERUPC +ACTOR_BG_ZG +ACTOR_EN_HEISHI4 +ACTOR_EN_ZL3 +ACTOR_BOSS_GANON2 +ACTOR_EN_KAKASI +ACTOR_EN_TAKARA_MAN +ACTOR_OBJ_MAKEOSHIHIKI +ACTOR_OCEFF_SPOT +ACTOR_END_TITLE +ACTOR_UNSET_180 +ACTOR_EN_TORCH +ACTOR_DEMO_EC +ACTOR_SHOT_SUN +ACTOR_EN_DY_EXTRA +ACTOR_EN_WONDER_TALK2 +ACTOR_EN_GE2 +ACTOR_OBJ_ROOMTIMER +ACTOR_EN_SSH +ACTOR_EN_STH +ACTOR_OCEFF_WIPE +ACTOR_OCEFF_STORM +ACTOR_EN_WEIYER +ACTOR_BG_SPOT05_SOKO +ACTOR_BG_JYA_1FLIFT +ACTOR_BG_JYA_HAHENIRON +ACTOR_BG_SPOT12_GATE +ACTOR_BG_SPOT12_SAKU +ACTOR_EN_HINTNUTS +ACTOR_EN_NUTSBALL +ACTOR_BG_SPOT00_BREAK +ACTOR_EN_SHOPNUTS +ACTOR_EN_IT +ACTOR_EN_GELDB +ACTOR_OCEFF_WIPE2 +ACTOR_OCEFF_WIPE3 +ACTOR_EN_NIW_GIRL +ACTOR_EN_DOG +ACTOR_EN_SI +ACTOR_BG_SPOT01_OBJECTS2 +ACTOR_OBJ_COMB +ACTOR_BG_SPOT11_BAKUDANKABE +ACTOR_OBJ_KIBAKO2 +ACTOR_EN_DNT_DEMO +ACTOR_EN_DNT_JIJI +ACTOR_EN_DNT_NOMAL +ACTOR_EN_GUEST +ACTOR_BG_BOM_GUARD +ACTOR_EN_HS2 +ACTOR_DEMO_KEKKAI +ACTOR_BG_SPOT08_BAKUDANKABE +ACTOR_BG_SPOT17_BAKUDANKABE +ACTOR_UNSET_1AA +ACTOR_OBJ_MURE3 +ACTOR_EN_TG +ACTOR_EN_MU +ACTOR_EN_GO2 +ACTOR_EN_WF +ACTOR_EN_SKB +ACTOR_DEMO_GJ +ACTOR_DEMO_GEFF +ACTOR_BG_GND_FIREMEIRO +ACTOR_BG_GND_DARKMEIRO +ACTOR_BG_GND_SOULMEIRO +ACTOR_BG_GND_NISEKABE +ACTOR_BG_GND_ICEBLOCK +ACTOR_EN_GB +ACTOR_EN_GS +ACTOR_BG_MIZU_BWALL +ACTOR_BG_MIZU_SHUTTER +ACTOR_EN_DAIKU_KAKARIKO +ACTOR_BG_BOWL_WALL +ACTOR_EN_WALL_TUBO +ACTOR_EN_PO_DESERT +ACTOR_EN_CROW +ACTOR_DOOR_KILLER +ACTOR_BG_SPOT11_OASIS +ACTOR_BG_SPOT18_FUTA +ACTOR_BG_SPOT18_SHUTTER +ACTOR_EN_MA3 +ACTOR_EN_COW +ACTOR_BG_ICE_TURARA +ACTOR_BG_ICE_SHUTTER +ACTOR_EN_KAKASI2 +ACTOR_EN_KAKASI3 +ACTOR_OCEFF_WIPE4 +ACTOR_EN_EG +ACTOR_BG_MENKURI_NISEKABE +ACTOR_EN_ZO +ACTOR_OBJ_MAKEKINSUTA +ACTOR_EN_GE3 +ACTOR_OBJ_TIMEBLOCK +ACTOR_OBJ_HAMISHI +ACTOR_EN_ZL4 +ACTOR_EN_MM2 +ACTOR_BG_JYA_BLOCK +ACTOR_OBJ_WARP2BLOCK +ACTOR_ID_MAX \ No newline at end of file diff --git a/tools/ZAPDConfigs/MqDbg/Config.xml b/tools/ZAPDConfigs/MqDbg/Config.xml new file mode 100644 index 0000000000..8ab4df57df --- /dev/null +++ b/tools/ZAPDConfigs/MqDbg/Config.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/tools/ZAPDConfigs/MqDbg/ObjectList_OoTMqDbg.txt b/tools/ZAPDConfigs/MqDbg/ObjectList_OoTMqDbg.txt new file mode 100644 index 0000000000..e5ba0331b5 --- /dev/null +++ b/tools/ZAPDConfigs/MqDbg/ObjectList_OoTMqDbg.txt @@ -0,0 +1,402 @@ +OBJECT_UNSET_0 +OBJECT_GAMEPLAY_KEEP +OBJECT_GAMEPLAY_FIELD_KEEP +OBJECT_GAMEPLAY_DANGEON_KEEP +OBJECT_UNSET_4 +OBJECT_UNSET_5 +OBJECT_HUMAN +OBJECT_OKUTA +OBJECT_CROW +OBJECT_POH +OBJECT_DY_OBJ +OBJECT_WALLMASTER +OBJECT_DODONGO +OBJECT_FIREFLY +OBJECT_BOX +OBJECT_FIRE +OBJECT_UNSET_10 +OBJECT_UNSET_11 +OBJECT_BUBBLE +OBJECT_NIW +OBJECT_LINK_BOY +OBJECT_LINK_CHILD +OBJECT_TITE +OBJECT_REEBA +OBJECT_PEEHAT +OBJECT_KINGDODONGO +OBJECT_HORSE +OBJECT_ZF +OBJECT_GOMA +OBJECT_ZL1 +OBJECT_GOL +OBJECT_DODOJR +OBJECT_TORCH2 +OBJECT_BL +OBJECT_TP +OBJECT_OA1 +OBJECT_ST +OBJECT_BW +OBJECT_EI +OBJECT_HORSE_NORMAL +OBJECT_OB1 +OBJECT_O_ANIME +OBJECT_SPOT04_OBJECTS +OBJECT_DDAN_OBJECTS +OBJECT_HIDAN_OBJECTS +OBJECT_HORSE_GANON +OBJECT_OA2 +OBJECT_SPOT00_OBJECTS +OBJECT_MB +OBJECT_BOMBF +OBJECT_SK2 +OBJECT_OE1 +OBJECT_OE_ANIME +OBJECT_OE2 +OBJECT_YDAN_OBJECTS +OBJECT_GND +OBJECT_AM +OBJECT_DEKUBABA +OBJECT_UNSET_3A +OBJECT_OA3 +OBJECT_OA4 +OBJECT_OA5 +OBJECT_OA6 +OBJECT_OA7 +OBJECT_JJ +OBJECT_OA8 +OBJECT_OA9 +OBJECT_OB2 +OBJECT_OB3 +OBJECT_OB4 +OBJECT_HORSE_ZELDA +OBJECT_OPENING_DEMO1 +OBJECT_WARP1 +OBJECT_B_HEART +OBJECT_DEKUNUTS +OBJECT_OE3 +OBJECT_OE4 +OBJECT_MENKURI_OBJECTS +OBJECT_OE5 +OBJECT_OE6 +OBJECT_OE7 +OBJECT_OE8 +OBJECT_OE9 +OBJECT_OE10 +OBJECT_OE11 +OBJECT_OE12 +OBJECT_VALI +OBJECT_OA10 +OBJECT_OA11 +OBJECT_MIZU_OBJECTS +OBJECT_FHG +OBJECT_OSSAN +OBJECT_MORI_HINERI1 +OBJECT_BB +OBJECT_TOKI_OBJECTS +OBJECT_YUKABYUN +OBJECT_ZL2 +OBJECT_MJIN +OBJECT_MJIN_FLASH +OBJECT_MJIN_DARK +OBJECT_MJIN_FLAME +OBJECT_MJIN_ICE +OBJECT_MJIN_SOUL +OBJECT_MJIN_WIND +OBJECT_MJIN_OKA +OBJECT_HAKA_OBJECTS +OBJECT_SPOT06_OBJECTS +OBJECT_ICE_OBJECTS +OBJECT_RELAY_OBJECTS +OBJECT_PO_FIELD +OBJECT_PO_COMPOSER +OBJECT_MORI_HINERI1A +OBJECT_MORI_HINERI2 +OBJECT_MORI_HINERI2A +OBJECT_MORI_OBJECTS +OBJECT_MORI_TEX +OBJECT_SPOT08_OBJ +OBJECT_WARP2 +OBJECT_HATA +OBJECT_BIRD +OBJECT_UNSET_78 +OBJECT_UNSET_79 +OBJECT_UNSET_7A +OBJECT_UNSET_7B +OBJECT_WOOD02 +OBJECT_UNSET_7D +OBJECT_UNSET_7E +OBJECT_UNSET_7F +OBJECT_UNSET_80 +OBJECT_LIGHTBOX +OBJECT_PU_BOX +OBJECT_UNSET_83 +OBJECT_UNSET_84 +OBJECT_TRAP +OBJECT_VASE +OBJECT_IM +OBJECT_TA +OBJECT_TK +OBJECT_XC +OBJECT_VM +OBJECT_BV +OBJECT_HAKACH_OBJECTS +OBJECT_EFC_CRYSTAL_LIGHT +OBJECT_EFC_FIRE_BALL +OBJECT_EFC_FLASH +OBJECT_EFC_LGT_SHOWER +OBJECT_EFC_STAR_FIELD +OBJECT_GOD_LGT +OBJECT_LIGHT_RING +OBJECT_TRIFORCE_SPOT +OBJECT_BDAN_OBJECTS +OBJECT_SD +OBJECT_RD +OBJECT_PO_SISTERS +OBJECT_HEAVY_OBJECT +OBJECT_GNDD +OBJECT_FD +OBJECT_DU +OBJECT_FW +OBJECT_MEDAL +OBJECT_HORSE_LINK_CHILD +OBJECT_SPOT02_OBJECTS +OBJECT_HAKA +OBJECT_RU1 +OBJECT_SYOKUDAI +OBJECT_FD2 +OBJECT_DH +OBJECT_RL +OBJECT_EFC_TW +OBJECT_DEMO_TRE_LGT +OBJECT_GI_KEY +OBJECT_MIR_RAY +OBJECT_BROB +OBJECT_GI_JEWEL +OBJECT_SPOT09_OBJ +OBJECT_SPOT18_OBJ +OBJECT_BDOOR +OBJECT_SPOT17_OBJ +OBJECT_SHOP_DUNGEN +OBJECT_NB +OBJECT_MO +OBJECT_SB +OBJECT_GI_MELODY +OBJECT_GI_HEART +OBJECT_GI_COMPASS +OBJECT_GI_BOSSKEY +OBJECT_GI_MEDAL +OBJECT_GI_NUTS +OBJECT_SA +OBJECT_GI_HEARTS +OBJECT_GI_ARROWCASE +OBJECT_GI_BOMBPOUCH +OBJECT_IN +OBJECT_TR +OBJECT_SPOT16_OBJ +OBJECT_OE1S +OBJECT_OE4S +OBJECT_OS_ANIME +OBJECT_GI_BOTTLE +OBJECT_GI_STICK +OBJECT_GI_MAP +OBJECT_OF1D_MAP +OBJECT_RU2 +OBJECT_GI_SHIELD_1 +OBJECT_DEKUJR +OBJECT_GI_MAGICPOT +OBJECT_GI_BOMB_1 +OBJECT_OF1S +OBJECT_MA2 +OBJECT_GI_PURSE +OBJECT_HNI +OBJECT_TW +OBJECT_RR +OBJECT_BXA +OBJECT_ANUBICE +OBJECT_GI_GERUDO +OBJECT_GI_ARROW +OBJECT_GI_BOMB_2 +OBJECT_GI_EGG +OBJECT_GI_SCALE +OBJECT_GI_SHIELD_2 +OBJECT_GI_HOOKSHOT +OBJECT_GI_OCARINA +OBJECT_GI_MILK +OBJECT_MA1 +OBJECT_GANON +OBJECT_SST +OBJECT_NY_UNUSED +OBJECT_UNSET_E4 +OBJECT_NY +OBJECT_FR +OBJECT_GI_PACHINKO +OBJECT_GI_BOOMERANG +OBJECT_GI_BOW +OBJECT_GI_GLASSES +OBJECT_GI_LIQUID +OBJECT_ANI +OBJECT_DEMO_6K +OBJECT_GI_SHIELD_3 +OBJECT_GI_LETTER +OBJECT_SPOT15_OBJ +OBJECT_JYA_OBJ +OBJECT_GI_CLOTHES +OBJECT_GI_BEAN +OBJECT_GI_FISH +OBJECT_GI_SAW +OBJECT_GI_HAMMER +OBJECT_GI_GRASS +OBJECT_GI_LONGSWORD +OBJECT_SPOT01_OBJECTS +OBJECT_MD_UNUSED +OBJECT_MD +OBJECT_KM1 +OBJECT_KW1 +OBJECT_ZO +OBJECT_KZ +OBJECT_UMAJUMP +OBJECT_MASTERKOKIRI +OBJECT_MASTERKOKIRIHEAD +OBJECT_MASTERGOLON +OBJECT_MASTERZOORA +OBJECT_AOB +OBJECT_IK +OBJECT_AHG +OBJECT_CNE +OBJECT_GI_NIWATORI +OBJECT_SKJ +OBJECT_GI_BOTTLE_LETTER +OBJECT_BJI +OBJECT_BBA +OBJECT_GI_OCARINA_0 +OBJECT_DS +OBJECT_ANE +OBJECT_BOJ +OBJECT_SPOT03_OBJECT +OBJECT_SPOT07_OBJECT +OBJECT_FZ +OBJECT_BOB +OBJECT_GE1 +OBJECT_YABUSAME_POINT +OBJECT_GI_BOOTS_2 +OBJECT_GI_SEED +OBJECT_GND_MAGIC +OBJECT_D_ELEVATOR +OBJECT_D_HSBLOCK +OBJECT_D_LIFT +OBJECT_MAMENOKI +OBJECT_GOROIWA +OBJECT_UNSET_120 +OBJECT_TORYO +OBJECT_DAIKU +OBJECT_UNSET_123 +OBJECT_NWC +OBJECT_BLKOBJ +OBJECT_GM +OBJECT_MS +OBJECT_HS +OBJECT_INGATE +OBJECT_LIGHTSWITCH +OBJECT_KUSA +OBJECT_TSUBO +OBJECT_GI_GLOVES +OBJECT_GI_COIN +OBJECT_KANBAN +OBJECT_GJYO_OBJECTS +OBJECT_OWL +OBJECT_MK +OBJECT_FU +OBJECT_GI_KI_TAN_MASK +OBJECT_GI_REDEAD_MASK +OBJECT_GI_SKJ_MASK +OBJECT_GI_RABIT_MASK +OBJECT_GI_TRUTH_MASK +OBJECT_GANON_OBJECTS +OBJECT_SIOFUKI +OBJECT_STREAM +OBJECT_MM +OBJECT_FA +OBJECT_OS +OBJECT_GI_EYE_LOTION +OBJECT_GI_POWDER +OBJECT_GI_MUSHROOM +OBJECT_GI_TICKETSTONE +OBJECT_GI_BROKENSWORD +OBJECT_JS +OBJECT_CS +OBJECT_GI_PRESCRIPTION +OBJECT_GI_BRACELET +OBJECT_GI_SOLDOUT +OBJECT_GI_FROG +OBJECT_MAG +OBJECT_DOOR_GERUDO +OBJECT_GT +OBJECT_EFC_ERUPC +OBJECT_ZL2_ANIME1 +OBJECT_ZL2_ANIME2 +OBJECT_GI_GOLONMASK +OBJECT_GI_ZORAMASK +OBJECT_GI_GERUDOMASK +OBJECT_GANON2 +OBJECT_KA +OBJECT_TS +OBJECT_ZG +OBJECT_GI_HOVERBOOTS +OBJECT_GI_M_ARROW +OBJECT_DS2 +OBJECT_EC +OBJECT_FISH +OBJECT_GI_SUTARU +OBJECT_GI_GODDESS +OBJECT_SSH +OBJECT_BIGOKUTA +OBJECT_BG +OBJECT_SPOT05_OBJECTS +OBJECT_SPOT12_OBJ +OBJECT_BOMBIWA +OBJECT_HINTNUTS +OBJECT_RS +OBJECT_SPOT00_BREAK +OBJECT_GLA +OBJECT_SHOPNUTS +OBJECT_GELDB +OBJECT_GR +OBJECT_DOG +OBJECT_JYA_IRON +OBJECT_JYA_DOOR +OBJECT_UNSET_16E +OBJECT_SPOT11_OBJ +OBJECT_KIBAKO2 +OBJECT_DNS +OBJECT_DNK +OBJECT_GI_FIRE +OBJECT_GI_INSECT +OBJECT_GI_BUTTERFLY +OBJECT_GI_GHOST +OBJECT_GI_SOUL +OBJECT_BOWL +OBJECT_DEMO_KEKKAI +OBJECT_EFC_DOUGHNUT +OBJECT_GI_DEKUPOUCH +OBJECT_GANON_ANIME1 +OBJECT_GANON_ANIME2 +OBJECT_GANON_ANIME3 +OBJECT_GI_RUPY +OBJECT_SPOT01_MATOYA +OBJECT_SPOT01_MATOYAB +OBJECT_MU +OBJECT_WF +OBJECT_SKB +OBJECT_GJ +OBJECT_GEFF +OBJECT_HAKA_DOOR +OBJECT_GS +OBJECT_PS +OBJECT_BWALL +OBJECT_COW +OBJECT_COB +OBJECT_GI_SWORD_1 +OBJECT_DOOR_KILLER +OBJECT_OUKE_HAKA +OBJECT_TIMEBLOCK +OBJECT_ZL4 \ No newline at end of file diff --git a/tools/ZAPD/SymbolMap_OoTMqDbg.txt b/tools/ZAPDConfigs/MqDbg/SymbolMap_OoTMqDbg.txt similarity index 100% rename from tools/ZAPD/SymbolMap_OoTMqDbg.txt rename to tools/ZAPDConfigs/MqDbg/SymbolMap_OoTMqDbg.txt