From 5015af4c57d11553e8058d923384bfb439162c01 Mon Sep 17 00:00:00 2001 From: louist103 <35883445+louist103@users.noreply.github.com> Date: Thu, 2 Jun 2022 18:48:52 -0400 Subject: [PATCH] git subrepo pull --force tools/ZAPD (#1251) subrepo: subdir: "tools/ZAPD" merged: "f54f2fa96" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "f54f2fa96" git-subrepo: version: "0.4.3" origin: "???" commit: "???" --- tools/ZAPD/.gitrepo | 4 +- tools/ZAPD/ExporterTest/CollisionExporter.cpp | 8 +- tools/ZAPD/ExporterTest/ExporterTest.vcxproj | 318 ++--- tools/ZAPD/ZAPD/ImageBackend.cpp | 4 +- tools/ZAPD/ZAPD/ImageBackend.h | 3 +- .../ZAPD/OtherStructs/CutsceneMM_Commands.cpp | 208 +++ .../ZAPD/OtherStructs/CutsceneMM_Commands.h | 140 ++ .../ZAPD/OtherStructs/Cutscene_Commands.cpp | 591 ++++++++ .../ZAPD/OtherStructs/Cutscene_Commands.h | 267 ++++ tools/ZAPD/ZAPD/WarningHandler.cpp | 12 +- tools/ZAPD/ZAPD/ZAPD.vcxproj | 703 +++++----- tools/ZAPD/ZAPD/ZAPD.vcxproj.filters | 1118 +++++++-------- tools/ZAPD/ZAPD/ZAnimation.cpp | 2 +- tools/ZAPD/ZAPD/ZArray.cpp | 1 + tools/ZAPD/ZAPD/ZCollision.cpp | 52 +- tools/ZAPD/ZAPD/ZCollision.h | 5 +- tools/ZAPD/ZAPD/ZCollisionPoly.cpp | 78 ++ tools/ZAPD/ZAPD/ZCollisionPoly.h | 29 + tools/ZAPD/ZAPD/ZCutscene.cpp | 1219 +++-------------- tools/ZAPD/ZAPD/ZCutscene.h | 426 +----- tools/ZAPD/ZAPD/ZCutsceneMM.cpp | 61 - tools/ZAPD/ZAPD/ZCutsceneMM.h | 29 - tools/ZAPD/ZAPD/ZFile.cpp | 15 +- tools/ZAPD/ZAPD/ZFile.h | 8 +- tools/ZAPD/ZAPD/ZLimb.cpp | 29 +- tools/ZAPD/ZAPD/ZLimb.h | 9 + tools/ZAPD/ZAPD/ZResource.cpp | 5 + tools/ZAPD/ZAPD/ZResource.h | 3 + .../ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp | 98 +- tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h | 6 +- .../ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp | 5 +- tools/ZAPD/ZAPD/ZSkeleton.cpp | 217 ++- tools/ZAPD/ZAPD/ZSkeleton.h | 25 +- tools/ZAPD/ZAPD/ZTexture.cpp | 176 +-- tools/ZAPD/ZAPD/ZTexture.h | 20 +- tools/ZAPD/ZAPDUtils/Utils/BitConverter.h | 223 +-- tools/ZAPD/ZAPDUtils/Utils/StringHelper.h | 7 + tools/ZAPD/ZAPDUtils/ZAPDUtils.vcxproj | 334 ++--- .../docs/zapd_extraction_xml_reference.md | 18 + 39 files changed, 3382 insertions(+), 3094 deletions(-) create mode 100644 tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.cpp create mode 100644 tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.h create mode 100644 tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.cpp create mode 100644 tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.h create mode 100644 tools/ZAPD/ZAPD/ZCollisionPoly.cpp create mode 100644 tools/ZAPD/ZAPD/ZCollisionPoly.h delete mode 100644 tools/ZAPD/ZAPD/ZCutsceneMM.cpp delete mode 100644 tools/ZAPD/ZAPD/ZCutsceneMM.h diff --git a/tools/ZAPD/.gitrepo b/tools/ZAPD/.gitrepo index 05be4d0b4a..f831718b1f 100644 --- a/tools/ZAPD/.gitrepo +++ b/tools/ZAPD/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/zeldaret/ZAPD.git branch = master - commit = 0ba78130478ee1272bc0e2f2fec2d162e7f7f995 - parent = 4afee2cfb8bc9cd5c7c217c38138174a9ce1fd99 + commit = f54f2fa96bfc476a15fcc3ebcd6124bc19164fcd + parent = 0a95d17aa89d6a80d3b23c7e706ec4bf845d48c1 method = merge cmdver = 0.4.3 diff --git a/tools/ZAPD/ExporterTest/CollisionExporter.cpp b/tools/ZAPD/ExporterTest/CollisionExporter.cpp index e00f5c1b0b..87b9a05a28 100644 --- a/tools/ZAPD/ExporterTest/CollisionExporter.cpp +++ b/tools/ZAPD/ExporterTest/CollisionExporter.cpp @@ -50,10 +50,10 @@ void ExporterExample_Collision::Save(ZResource* res, [[maybe_unused]] fs::path o writer->Write(col->polygons[i].vtxA); writer->Write(col->polygons[i].vtxB); writer->Write(col->polygons[i].vtxC); - writer->Write(col->polygons[i].a); - writer->Write(col->polygons[i].b); - writer->Write(col->polygons[i].c); - writer->Write(col->polygons[i].d); + writer->Write(col->polygons[i].normX); + writer->Write(col->polygons[i].normY); + writer->Write(col->polygons[i].normZ); + writer->Write(col->polygons[i].dist); } writer->Seek(col->polyTypeDefSegmentOffset, SeekOffsetType::Start); diff --git a/tools/ZAPD/ExporterTest/ExporterTest.vcxproj b/tools/ZAPD/ExporterTest/ExporterTest.vcxproj index 839d451023..5bdfc7aa6d 100644 --- a/tools/ZAPD/ExporterTest/ExporterTest.vcxproj +++ b/tools/ZAPD/ExporterTest/ExporterTest.vcxproj @@ -1,160 +1,160 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {65608eb0-1a47-45ad-ab66-192fb64c762c} - ExporterTest - 10.0 - ExporterExample - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - StaticLibrary - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - false - - - true - $(ProjectDir)..\ZAPD\;$(ProjectDir)..\ZAPDUtils;$(ProjectDir)..\lib\tinyxml2;$(ProjectDir)..\lib\libgfxd;$(ProjectDir)..\lib\elfio;$(ProjectDir)..\lib\stb;$(ProjectDir);$(IncludePath) - - - false - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - true - stdcpp17 - stdc11 - MultiThreadedDebug - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {65608eb0-1a47-45ad-ab66-192fb64c762c} + ExporterTest + 10.0 + ExporterExample + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + StaticLibrary + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + $(ProjectDir)..\ZAPD\;$(ProjectDir)..\ZAPDUtils;$(ProjectDir)..\lib\tinyxml2;$(ProjectDir)..\lib\libgfxd;$(ProjectDir)..\lib\elfio;$(ProjectDir)..\lib\stb;$(ProjectDir);$(IncludePath) + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + stdcpp17 + stdc11 + MultiThreadedDebug + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ImageBackend.cpp b/tools/ZAPD/ZAPD/ImageBackend.cpp index 8accb6b4e1..307945b40e 100644 --- a/tools/ZAPD/ZAPD/ImageBackend.cpp +++ b/tools/ZAPD/ZAPD/ImageBackend.cpp @@ -398,7 +398,7 @@ void ImageBackend::SetPaletteIndex(size_t index, uint8_t nR, uint8_t nG, uint8_t alphaPalette[index] = nA; } -void ImageBackend::SetPalette(const ImageBackend& pal) +void ImageBackend::SetPalette(const ImageBackend& pal, uint32_t offset) { assert(isColorIndexed); size_t bytePerPixel = pal.GetBytesPerPixel(); @@ -422,7 +422,7 @@ void ImageBackend::SetPalette(const ImageBackend& pal) uint8_t g = pal.pixelMatrix[y][x * bytePerPixel + 1]; uint8_t b = pal.pixelMatrix[y][x * bytePerPixel + 2]; uint8_t a = pal.pixelMatrix[y][x * bytePerPixel + 3]; - SetPaletteIndex(index, r, g, b, a); + SetPaletteIndex(index + offset, r, g, b, a); } } } diff --git a/tools/ZAPD/ZAPD/ImageBackend.h b/tools/ZAPD/ZAPD/ImageBackend.h index 9e05a2eed1..0b1f4806c0 100644 --- a/tools/ZAPD/ZAPD/ImageBackend.h +++ b/tools/ZAPD/ZAPD/ImageBackend.h @@ -42,8 +42,9 @@ public: void SetGrayscalePixel(size_t y, size_t x, uint8_t grayscale, uint8_t alpha = 0); void SetIndexedPixel(size_t y, size_t x, uint8_t index, uint8_t grayscale); + void SetIndexedPixel(size_t y, size_t x, uint8_t index, RGBAPixel pixel); void SetPaletteIndex(size_t index, uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA); - void SetPalette(const ImageBackend& pal); + void SetPalette(const ImageBackend& pal, uint32_t offset = 0); uint32_t GetWidth() const; uint32_t GetHeight() const; diff --git a/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.cpp b/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.cpp new file mode 100644 index 0000000000..b69f47321d --- /dev/null +++ b/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.cpp @@ -0,0 +1,208 @@ +#include "CutsceneMM_Commands.h" + +#include +#include + +#include "Utils/BitConverter.h" +#include "Utils/StringHelper.h" + +// Specific for command lists where each entry has size 8 bytes +const std::unordered_map csCommandsDescMM = { + {CutsceneMMCommands::CS_CMD_MISC, {"CS_MISC", "(0x%02X, %i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_SET_LIGHTING, {"CS_LIGHTING", "(0x%02X, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_SCENE_TRANS_FX, {"CS_SCENE_TRANS_FX", "(%i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_MOTIONBLUR, {"CS_MOTIONBLUR", "(%i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_GIVETATL, {"CS_GIVETATL", "(%i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_PLAYSEQ, {"CS_PLAYSEQ", "(0x%04X, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_130, {"CS_SCENE_UNK_130", "(0x%04X, %i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_131, {"CS_SCENE_UNK_131", "(0x%04X, %i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_132, {"CS_SCENE_UNK_132", "(%i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_STOPSEQ, {"CS_STOPSEQ", "(0x%04X, %i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_PLAYAMBIENCE, {"CS_PLAYAMBIENCE", "(0x%04X, %i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_FADEAMBIENCE, {"CS_FADEAMBIENCE", "(0x%04X, %i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_TERMINATOR, {"CS_TERMINATOR", "(%i, %i, %i)"}}, + {CutsceneMMCommands::CS_CMD_CHOOSE_CREDITS_SCENES, + {"CS_CHOOSE_CREDITS_SCENES", "(%i, %i, %i)"}}, +}; + +CutsceneSubCommandEntry_GenericMMCmd::CutsceneSubCommandEntry_GenericMMCmd( + const std::vector& rawData, offset_t rawDataIndex, CutsceneMMCommands cmdId) + : CutsceneSubCommandEntry(rawData, rawDataIndex), commandId(cmdId) +{ +} + +std::string CutsceneSubCommandEntry_GenericMMCmd::GetBodySourceCode() const +{ + const auto& element = csCommandsDescMM.find(commandId); + std::string entryFmt = "CS_UNK_DATA(0x%02X, %i, %i, %i)"; + + if (element != csCommandsDescMM.end()) + { + entryFmt = element->second.cmdMacro; + entryFmt += element->second.args; + } + + return StringHelper::Sprintf(entryFmt.c_str(), base, startFrame, endFrame, pad); +} + +CutsceneMMCommand_GenericCmd::CutsceneMMCommand_GenericCmd(const std::vector& rawData, + offset_t rawDataIndex, + CutsceneMMCommands cmdId) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + commandID = static_cast(cmdId); + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneSubCommandEntry_GenericMMCmd(rawData, rawDataIndex, cmdId); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneMMCommand_GenericCmd::GetCommandMacro() const +{ + const auto& element = csCommandsDescMM.find(static_cast(commandID)); + + if (element != csCommandsDescMM.end()) + { + return StringHelper::Sprintf("%s_LIST(%i)", element->second.cmdMacro, numEntries); + } + + return StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%X, %i)", commandID, numEntries); +} + +CutsceneSubCommandEntry_Camera::CutsceneSubCommandEntry_Camera(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ +} + +std::string CutsceneSubCommandEntry_Camera::GetBodySourceCode() const +{ + return StringHelper::Sprintf("CMD_HH(0x%04X, 0x%04X)", base, startFrame); +} + +size_t CutsceneSubCommandEntry_Camera::GetRawSize() const +{ + return 0x04; +} + +CutsceneMMCommand_Camera::CutsceneMMCommand_Camera(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + for (size_t i = 0; i < numEntries / 4; i++) + { + auto* entry = new CutsceneSubCommandEntry_Camera(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneMMCommand_Camera::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_CAMERA_LIST(%i)", numEntries); +} + +CutsceneSubCommandEntry_FadeScreen::CutsceneSubCommandEntry_FadeScreen( + const std::vector& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + unk_06 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x06); + unk_07 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x07); + unk_08 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08); + unk_09 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x09); + unk_0A = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x0A); + unk_0B = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x0B); +} + +std::string CutsceneSubCommandEntry_FadeScreen::GetBodySourceCode() const +{ + return StringHelper::Sprintf("CS_FADESCREEN(0x%02X, %i, %i, %i, %i, %i)", base, startFrame, + endFrame, unk_06, unk_07, unk_08); +} + +size_t CutsceneSubCommandEntry_FadeScreen::GetRawSize() const +{ + return 0x0C; +} + +CutsceneMMCommand_FadeScreen::CutsceneMMCommand_FadeScreen(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneSubCommandEntry_FadeScreen(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneMMCommand_FadeScreen::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_FADESCREEN_LIST(%i)", numEntries); +} + +CutsceneSubCommandEntry_FadeSeq::CutsceneSubCommandEntry_FadeSeq( + const std::vector& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + unk_08 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); +} + +std::string CutsceneSubCommandEntry_FadeSeq::GetBodySourceCode() const +{ + return StringHelper::Sprintf("CS_FADESEQ(%i, %i, %i)", base, startFrame, endFrame); +} + +size_t CutsceneSubCommandEntry_FadeSeq::GetRawSize() const +{ + return 0x0C; +} + +CutsceneMMCommand_FadeSeq::CutsceneMMCommand_FadeSeq(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneSubCommandEntry_FadeSeq(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneMMCommand_FadeSeq::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_FADESEQ_LIST(%i)", numEntries); +} + +CutsceneSubCommandEntry_NonImplemented::CutsceneSubCommandEntry_NonImplemented( + const std::vector& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ +} + +CutsceneMMCommand_NonImplemented::CutsceneMMCommand_NonImplemented( + const std::vector& rawData, offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneSubCommandEntry_NonImplemented(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} diff --git a/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.h b/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.h new file mode 100644 index 0000000000..c8ae4eb603 --- /dev/null +++ b/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.h @@ -0,0 +1,140 @@ +#pragma once + +#include "Cutscene_Commands.h" + +enum class CutsceneMMCommands +{ + /* 0x00A */ CS_CMD_TEXTBOX = 0xA, + /* 0x05A */ CS_CMD_CAMERA = 0x5A, + /* 0x096 */ CS_CMD_MISC = 0x96, + /* 0x097 */ CS_CMD_SET_LIGHTING, + /* 0x098 */ CS_CMD_SCENE_TRANS_FX, + /* 0x099 */ CS_CMD_MOTIONBLUR, + /* 0x09A */ CS_CMD_GIVETATL, + /* 0x09B */ CS_CMD_FADESCREEN, + /* 0x09C */ CS_CMD_FADESEQ, + /* 0x09D */ CS_CMD_SETTIME, + /* 0x0C8 */ CS_CMD_SET_PLAYER_ACTION = 0xC8, + /* 0x0FA */ CS_CMD_UNK_FA = 0xFA, + /* 0x0FE */ CS_CMD_UNK_FE = 0xFE, + /* 0x0FF */ CS_CMD_UNK_FF, + /* 0x100 */ CS_CMD_UNK_100, + /* 0x101 */ CS_CMD_UNK_101, + /* 0x102 */ CS_CMD_UNK_102, + /* 0x103 */ CS_CMD_UNK_103, + /* 0x104 */ CS_CMD_UNK_104, + /* 0x105 */ CS_CMD_UNK_105, + /* 0x108 */ CS_CMD_UNK_108 = 0x108, + /* 0x109 */ CS_CMD_UNK_109, + /* 0x12C */ CS_CMD_PLAYSEQ = 0x12C, + /* 0x12D */ CS_CMD_UNK_12D, + /* 0x130 */ CS_CMD_130 = 0x130, + /* 0x131 */ CS_CMD_131 = 0x131, + /* 0x132 */ CS_CMD_132 = 0x132, + /* 0x133 */ CS_CMD_STOPSEQ, + /* 0x134 */ CS_CMD_PLAYAMBIENCE, + /* 0x135 */ CS_CMD_FADEAMBIENCE, + /* 0x15E */ CS_CMD_TERMINATOR = 0x15E, + /* 0x15F */ CS_CMD_CHOOSE_CREDITS_SCENES, + /* 0x190 */ CS_CMD_RUMBLE = 0x190, +}; + +class CutsceneSubCommandEntry_GenericMMCmd : public CutsceneSubCommandEntry +{ +public: + CutsceneMMCommands commandId; + + CutsceneSubCommandEntry_GenericMMCmd(const std::vector& rawData, offset_t rawDataIndex, + CutsceneMMCommands cmdId); + + std::string GetBodySourceCode() const override; +}; + +class CutsceneMMCommand_GenericCmd : public CutsceneCommand +{ +public: + CutsceneMMCommand_GenericCmd(const std::vector& rawData, offset_t rawDataIndex, + CutsceneMMCommands cmdId); + + std::string GetCommandMacro() const override; +}; + +// TODO: MM cutscene camera command is implemented as a placeholder until we better understand how +// it works +class CutsceneSubCommandEntry_Camera : public CutsceneSubCommandEntry +{ +public: + uint32_t unk_08; + + CutsceneSubCommandEntry_Camera(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneMMCommand_Camera : public CutsceneCommand +{ +public: + CutsceneMMCommand_Camera(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +class CutsceneSubCommandEntry_FadeScreen : public CutsceneSubCommandEntry +{ +public: + uint8_t unk_06; + uint8_t unk_07; + uint8_t unk_08; + uint8_t unk_09; + uint8_t unk_0A; + uint8_t unk_0B; + + CutsceneSubCommandEntry_FadeScreen(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneMMCommand_FadeScreen : public CutsceneCommand +{ +public: + CutsceneMMCommand_FadeScreen(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +class CutsceneSubCommandEntry_FadeSeq : public CutsceneSubCommandEntry +{ +public: + uint32_t unk_08; + + CutsceneSubCommandEntry_FadeSeq(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneMMCommand_FadeSeq : public CutsceneCommand +{ +public: + CutsceneMMCommand_FadeSeq(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +class CutsceneSubCommandEntry_NonImplemented : public CutsceneSubCommandEntry +{ +public: + CutsceneSubCommandEntry_NonImplemented(const std::vector& rawData, + offset_t rawDataIndex); +}; + +class CutsceneMMCommand_NonImplemented : public CutsceneCommand +{ +public: + CutsceneMMCommand_NonImplemented(const std::vector& rawData, offset_t rawDataIndex); +}; diff --git a/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.cpp b/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.cpp new file mode 100644 index 0000000000..a716176b9b --- /dev/null +++ b/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.cpp @@ -0,0 +1,591 @@ +#include "Cutscene_Commands.h" + +#include +#include + +#include "CutsceneMM_Commands.h" +#include "Globals.h" +#include "Utils/BitConverter.h" +#include "Utils/StringHelper.h" + +/* CutsceneSubCommandEntry */ + +CutsceneSubCommandEntry::CutsceneSubCommandEntry(const std::vector& rawData, + offset_t rawDataIndex) +{ + base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); + startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); + endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); + pad = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); +} + +std::string CutsceneSubCommandEntry::GetBodySourceCode() const +{ + return StringHelper::Sprintf("CMD_HH(0x%04X, 0x%04X), CMD_HH(0x%04X, 0x%04X)", base, startFrame, + endFrame, pad); +} + +size_t CutsceneSubCommandEntry::GetRawSize() const +{ + return 0x08; +} + +/* CutsceneCommand */ + +CutsceneCommand::CutsceneCommand(const std::vector& rawData, offset_t rawDataIndex) +{ + numEntries = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); +} + +CutsceneCommand::~CutsceneCommand() +{ + for (auto& entry : entries) + { + delete entry; + } +} + +std::string CutsceneCommand::GetCommandMacro() const +{ + return StringHelper::Sprintf("CMD_W(0x%08X), CMD_W(0x%08X)", commandID, numEntries); +} + +std::string CutsceneCommand::GenerateSourceCode() const +{ + std::string result; + + result += GetCommandMacro(); + result += ",\n"; + + for (auto& entry : entries) + { + result += " "; + result += entry->GetBodySourceCode(); + result += ",\n"; + } + + return result; +} + +size_t CutsceneCommand::GetCommandSize() const +{ + size_t size = 0; + if (entries.size() > 0) + { + size = entries.at(0)->GetRawSize() * entries.size(); + } + else + { + size = 0x08 * numEntries; + } + return 0x08 + size; +} + +void CutsceneCommand::SetCommandID(uint32_t nCommandID) +{ + commandID = nCommandID; + + for (auto& entry : entries) + { + entry->commandID = commandID; + } +} + +// Specific for command lists where each entry has size 0x30 bytes +const std::unordered_map csCommandsDesc = { + {CutsceneCommands::Misc, + {"CS_MISC", "(0x%04X, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, + {CutsceneCommands::SetLighting, + {"CS_LIGHTING", "(0x%02X, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, + {CutsceneCommands::PlayBGM, {"CS_PLAY_BGM", "(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, + {CutsceneCommands::StopBGM, {"CS_STOP_BGM", "(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, + {CutsceneCommands::FadeBGM, {"CS_FADE_BGM", "(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, +}; + +CutsceneSubCommandEntry_GenericCmd::CutsceneSubCommandEntry_GenericCmd( + const std::vector& rawData, offset_t rawDataIndex, CutsceneCommands cmdId) + : CutsceneSubCommandEntry(rawData, rawDataIndex), commandId(cmdId) +{ + word0 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0); + word1 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x4); + + unused1 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x8); + unused2 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0xC); + unused3 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x10); + unused4 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x14); + unused5 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x18); + unused6 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x1C); + unused7 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x20); + unused8 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x24); + unused9 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x28); + unused10 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x2C); +} + +std::string CutsceneSubCommandEntry_GenericCmd::GetBodySourceCode() const +{ + const auto& element = csCommandsDesc.find(commandId); + + if (element != csCommandsDesc.end()) + { + std::string entryFmt = element->second.cmdMacro; + entryFmt += element->second.args; + + return StringHelper::Sprintf(entryFmt.c_str(), base, startFrame, endFrame, pad, unused1, + unused2, unused3, unused4, unused5, unused6, unused7, unused8, + unused9, unused10); + } + + return StringHelper::Sprintf("CS_UNK_DATA(0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, " + "0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X)", + word0, word1, unused1, unused2, unused3, unused4, unused5, unused6, + unused7, unused8, unused9, unused10); +} + +size_t CutsceneSubCommandEntry_GenericCmd::GetRawSize() const +{ + return 0x30; +} + +CutsceneCommand_GenericCmd::CutsceneCommand_GenericCmd(const std::vector& rawData, + offset_t rawDataIndex, + CutsceneCommands cmdId) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + commandID = static_cast(cmdId); + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneSubCommandEntry_GenericCmd(rawData, rawDataIndex, cmdId); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneCommand_GenericCmd::GetCommandMacro() const +{ + const auto& element = csCommandsDesc.find(static_cast(commandID)); + + if (element != csCommandsDesc.end()) + { + return StringHelper::Sprintf("%s_LIST(%i)", element->second.cmdMacro, numEntries); + } + + return StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%X, %i)", commandID, numEntries); +} + +CutsceneCameraPoint::CutsceneCameraPoint(const std::vector& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + continueFlag = BitConverter::ToInt8BE(rawData, rawDataIndex + 0); + cameraRoll = BitConverter::ToInt8BE(rawData, rawDataIndex + 1); + nextPointFrame = BitConverter::ToInt16BE(rawData, rawDataIndex + 2); + viewAngle = BitConverter::ToFloatBE(rawData, rawDataIndex + 4); + + posX = BitConverter::ToInt16BE(rawData, rawDataIndex + 8); + posY = BitConverter::ToInt16BE(rawData, rawDataIndex + 10); + posZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 12); + + unused = BitConverter::ToInt16BE(rawData, rawDataIndex + 14); +} + +std::string CutsceneCameraPoint::GetBodySourceCode() const +{ + std::string result = ""; + + if (commandID == (int32_t)CutsceneCommands::SetCameraFocus) + { + result += "CS_CAM_FOCUS_POINT"; + } + else if (commandID == (int32_t)CutsceneCommands::SetCameraFocusLink) + { + result += "CS_CAM_FOCUS_POINT_PLAYER"; + } + else if (commandID == (int32_t)CutsceneCommands::SetCameraPosLink) + { + result += "CS_CAM_POS_PLAYER"; + } + else + { + result += "CS_CAM_POS"; + } + + std::string continueMacro = "CS_CMD_CONTINUE"; + if (continueFlag != 0) + continueMacro = "CS_CMD_STOP"; + + result += + StringHelper::Sprintf("(%s, 0x%02X, %i, %ff, %i, %i, %i, 0x%04X)", continueMacro.c_str(), + cameraRoll, nextPointFrame, viewAngle, posX, posY, posZ, unused); + return result; +} + +size_t CutsceneCameraPoint::GetRawSize() const +{ + return 0x10; +} + +CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); + startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); + endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); + unused = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); + + bool shouldContinue = true; + + uint32_t currentPtr = rawDataIndex + 8; + + while (shouldContinue) + { + CutsceneCameraPoint* camPoint = new CutsceneCameraPoint(rawData, currentPtr); + entries.push_back(camPoint); + + if (camPoint->continueFlag == -1) + shouldContinue = false; + + currentPtr += camPoint->GetRawSize(); + } +} + +std::string CutsceneCommandSetCameraPos::GetCommandMacro() const +{ + std::string result; + + std::string listStr; + + if (commandID == (int32_t)CutsceneCommands::SetCameraFocus) + { + listStr = "CS_CAM_FOCUS_POINT_LIST"; + } + else if (commandID == (int32_t)CutsceneCommands::SetCameraFocusLink) + { + listStr = "CS_CAM_FOCUS_POINT_PLAYER_LIST"; + } + else if (commandID == (int32_t)CutsceneCommands::SetCameraPosLink) + { + listStr = "CS_CAM_POS_PLAYER_LIST"; + } + else + { + listStr = "CS_CAM_POS_LIST"; + } + + result += StringHelper::Sprintf("%s(%i, %i)", listStr.c_str(), startFrame, endFrame); + + return result; +} + +size_t CutsceneCommandSetCameraPos::GetCommandSize() const +{ + return 0x0C + entries.at(0)->GetRawSize() * entries.size(); +} + +CutsceneSubCommandEntry_Rumble::CutsceneSubCommandEntry_Rumble(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + unk_06 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x06); + unk_07 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x07); + unk_08 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08); + unk_09 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x09); + unk_0A = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x0A); + unk_0B = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x0B); +} + +std::string CutsceneSubCommandEntry_Rumble::GetBodySourceCode() const +{ + if (Globals::Instance->game == ZGame::MM_RETAIL) + { + return StringHelper::Sprintf("CS_RUMBLE(%i, %i, %i, 0x%02X, 0x%02X, 0x%02X)", base, + startFrame, endFrame, unk_06, unk_07, unk_08); + } + + return StringHelper::Sprintf("CS_CMD_09(%i, %i, %i, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X)", + base, startFrame, endFrame, unk_06, unk_07, unk_08, unk_09, unk_0A, + unk_0B); +} + +size_t CutsceneSubCommandEntry_Rumble::GetRawSize() const +{ + return 0x0C; +} + +CutsceneCommand_Rumble::CutsceneCommand_Rumble(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneSubCommandEntry_Rumble(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneCommand_Rumble::GetCommandMacro() const +{ + if (Globals::Instance->game == ZGame::MM_RETAIL) + { + return StringHelper::Sprintf("CS_RUMBLE_LIST(%i)", numEntries); + } + return StringHelper::Sprintf("CS_CMD_09_LIST(%i)", numEntries); +} + +CutsceneSubCommandEntry_SetTime::CutsceneSubCommandEntry_SetTime( + const std::vector& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + hour = BitConverter::ToUInt8BE(rawData, rawDataIndex + 6); + minute = BitConverter::ToUInt8BE(rawData, rawDataIndex + 7); + unk_08 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); +} + +std::string CutsceneSubCommandEntry_SetTime::GetBodySourceCode() const +{ + return StringHelper::Sprintf("CS_TIME(%i, %i, %i, %i, %i, %i)", base, startFrame, endFrame, + hour, minute, unk_08); +} + +size_t CutsceneSubCommandEntry_SetTime::GetRawSize() const +{ + return 0x0C; +} + +CutsceneCommand_SetTime::CutsceneCommand_SetTime(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneSubCommandEntry_SetTime(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneCommand_SetTime::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_TIME_LIST(%i)", numEntries); +} + +CutsceneSubCommandEntry_TextBox::CutsceneSubCommandEntry_TextBox( + const std::vector& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + type = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x6); + textId1 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x8); + textId2 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0xA); +} + +std::string CutsceneSubCommandEntry_TextBox::GetBodySourceCode() const +{ + if (type == 0xFFFF) + { + return StringHelper::Sprintf("CS_TEXT_NONE(%i, %i)", startFrame, endFrame); + } + if (type == 2) + { + return StringHelper::Sprintf("CS_TEXT_LEARN_SONG(%i, %i, %i, 0x%X)", base, startFrame, + endFrame, textId1); + } + + if (Globals::Instance->game == ZGame::MM_RETAIL) + { + switch (type) + { + case 0: + return StringHelper::Sprintf("CS_TEXT_DEFAULT(0x%X, %i, %i, 0x%X, 0x%X)", base, + startFrame, endFrame, textId1, textId2); + + case 1: + return StringHelper::Sprintf("CS_TEXT_TYPE_1(0x%X, %i, %i, 0x%X, 0x%X)", base, + startFrame, endFrame, textId1, textId2); + + case 3: + return StringHelper::Sprintf("CS_TEXT_TYPE_3(0x%X, %i, %i, 0x%X, 0x%X)", base, + startFrame, endFrame, textId1, textId2); + + case 4: + return StringHelper::Sprintf("CS_TEXT_BOSSES_REMAINS(0x%X, %i, %i, 0x%X)", base, + startFrame, endFrame, textId1); + + case 5: + return StringHelper::Sprintf("CS_TEXT_ALL_NORMAL_MASKS(0x%X, %i, %i, 0x%X)", base, + startFrame, endFrame, textId1); + } + } + + return StringHelper::Sprintf("CS_TEXT_DISPLAY_TEXTBOX(0x%X, %i, %i, %i, 0x%X, 0x%X)", base, + startFrame, endFrame, type, textId1, textId2); +} + +size_t CutsceneSubCommandEntry_TextBox::GetRawSize() const +{ + return 0x0C; +} + +CutsceneCommand_TextBox::CutsceneCommand_TextBox(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneSubCommandEntry_TextBox(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneCommand_TextBox::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_TEXT_LIST(%i)", numEntries); +} + +CutsceneSubCommandEntry_ActorAction::CutsceneSubCommandEntry_ActorAction( + const std::vector& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + rotX = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x6); + rotY = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x8); + rotZ = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0xA); + startPosX = BitConverter::ToInt32BE(rawData, rawDataIndex + 0xC); + startPosY = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x10); + startPosZ = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x14); + endPosX = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x18); + endPosY = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x1C); + endPosZ = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x20); + normalX = BitConverter::ToFloatBE(rawData, rawDataIndex + 0x24); + normalY = BitConverter::ToFloatBE(rawData, rawDataIndex + 0x28); + normalZ = BitConverter::ToFloatBE(rawData, rawDataIndex + 0x2C); +} + +std::string CutsceneSubCommandEntry_ActorAction::GetBodySourceCode() const +{ + std::string result; + + if (Globals::Instance->game == ZGame::MM_RETAIL) + { + if (static_cast(commandID) == + CutsceneMMCommands::CS_CMD_SET_PLAYER_ACTION) + { + result = "CS_PLAYER_ACTION"; + } + else + { + result = "CS_ACTOR_ACTION"; + } + } + else + { + if (static_cast(commandID) == CutsceneCommands::SetPlayerAction) + { + result = "CS_PLAYER_ACTION"; + } + else + { + result = "CS_NPC_ACTION"; + } + } + + result += + StringHelper::Sprintf("(%i, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, " + "%i, %i, %i, %i, %.11ef, %.11ef, %.11ef)", + base, startFrame, endFrame, rotX, rotY, rotZ, startPosX, startPosY, + startPosZ, endPosX, endPosY, endPosZ, normalX, normalY, normalZ); + return result; +} + +size_t CutsceneSubCommandEntry_ActorAction::GetRawSize() const +{ + return 0x30; +} + +CutsceneCommand_ActorAction::CutsceneCommand_ActorAction(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneSubCommandEntry_ActorAction(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneCommand_ActorAction::GetCommandMacro() const +{ + if (Globals::Instance->game == ZGame::MM_RETAIL) + { + if (static_cast(commandID) == + CutsceneMMCommands::CS_CMD_SET_PLAYER_ACTION) + { + return StringHelper::Sprintf("CS_PLAYER_ACTION_LIST(%i)", numEntries); + } + return StringHelper::Sprintf("CS_ACTOR_ACTION_LIST(0x%03X, %i)", commandID, numEntries); + } + + if (static_cast(commandID) == CutsceneCommands::SetPlayerAction) + { + return StringHelper::Sprintf("CS_PLAYER_ACTION_LIST(%i)", entries.size()); + } + return StringHelper::Sprintf("CS_NPC_ACTION_LIST(0x%03X, %i)", commandID, entries.size()); +} + +CutsceneCommand_Terminator::CutsceneCommand_Terminator(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); + startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); + endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); + unknown = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); // endFrame duplicate +} + +std::string CutsceneCommand_Terminator::GenerateSourceCode() const +{ + std::string result; + + result += StringHelper::Sprintf("CS_TERMINATOR(%i, %i, %i),\n", base, startFrame, endFrame); + + return result; +} + +size_t CutsceneCommand_Terminator::GetCommandSize() const +{ + return 0x10; +} + +CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const std::vector& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); + startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); + endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); +} + +std::string CutsceneCommandSceneTransFX::GenerateSourceCode() const +{ + return StringHelper::Sprintf("CS_SCENE_TRANS_FX(%i, %i, %i),\n", base, startFrame, endFrame); +} + +size_t CutsceneCommandSceneTransFX::GetCommandSize() const +{ + return 0x10; +} diff --git a/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.h b/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.h new file mode 100644 index 0000000000..c462735873 --- /dev/null +++ b/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.h @@ -0,0 +1,267 @@ +#pragma once + +#include +#include +#include + +#include "Declaration.h" + +enum class CutsceneCommands +{ + SetCameraPos = 0x0001, + SetCameraFocus = 0x0002, + Misc = 0x0003, + SetLighting = 0x0004, + SetCameraPosLink = 0x0005, + SetCameraFocusLink = 0x0006, + Cmd07 = 0x0007, + Cmd08 = 0x0008, + Cmd09 = 0x0009, // Rumble + Textbox = 0x0013, + SetPlayerAction = 0x000A, + SetActorAction1 = 0x000F, + SetActorAction2 = 0x000E, + SetActorAction3 = 0x0019, + SetActorAction4 = 0x001D, + SetActorAction5 = 0x001E, + SetActorAction6 = 0x002C, + SetActorAction7 = 0x001F, + SetActorAction8 = 0x0031, + SetActorAction9 = 0x003E, + SetActorAction10 = 0x008F, + SetSceneTransFX = 0x002D, + PlayBGM = 0x0056, + StopBGM = 0x0057, + FadeBGM = 0x007C, + SetTime = 0x008C, + Terminator = 0x03E8, +}; + +typedef struct CsCommandListDescriptor +{ + const char* cmdMacro; + const char* args; +} CsCommandListDescriptor; + +class CutsceneSubCommandEntry +{ +public: + uint16_t base; + uint16_t startFrame; + uint16_t endFrame; + uint16_t pad; + + uint32_t commandID; + + CutsceneSubCommandEntry(const std::vector& rawData, offset_t rawDataIndex); + virtual ~CutsceneSubCommandEntry() = default; + + virtual std::string GetBodySourceCode() const; + + virtual size_t GetRawSize() const; +}; + +class CutsceneCommand +{ +public: + uint32_t commandID; + uint32_t commandIndex; + + uint32_t numEntries; + std::vector entries; + + CutsceneCommand(const std::vector& rawData, offset_t rawDataIndex); + virtual ~CutsceneCommand(); + + virtual std::string GetCommandMacro() const; + virtual std::string GenerateSourceCode() const; + virtual size_t GetCommandSize() const; + + virtual void SetCommandID(uint32_t nCommandID); +}; + +class CutsceneSubCommandEntry_GenericCmd : public CutsceneSubCommandEntry +{ +public: + CutsceneCommands commandId; + + uint32_t word0 = 0; + uint32_t word1 = 0; + + uint32_t unused1 = 0; + uint32_t unused2 = 0; + uint32_t unused3 = 0; + uint32_t unused4 = 0; + uint32_t unused5 = 0; + uint32_t unused6 = 0; + uint32_t unused7 = 0; + uint32_t unused8 = 0; + uint32_t unused9 = 0; + uint32_t unused10 = 0; + + CutsceneSubCommandEntry_GenericCmd(const std::vector& rawData, offset_t rawDataIndex, + CutsceneCommands cmdId); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneCommand_GenericCmd : public CutsceneCommand +{ +public: + CutsceneCommand_GenericCmd(const std::vector& rawData, offset_t rawDataIndex, + CutsceneCommands cmdId); + + std::string GetCommandMacro() const override; +}; + +class CutsceneCameraPoint : public CutsceneSubCommandEntry +{ +public: + int8_t continueFlag; + int8_t cameraRoll; + int16_t nextPointFrame; + float viewAngle; + int16_t posX, posY, posZ; + int16_t unused; + + CutsceneCameraPoint(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneCommandSetCameraPos : public CutsceneCommand +{ +public: + uint16_t base; + uint16_t startFrame; + uint16_t endFrame; + uint16_t unused; + + CutsceneCommandSetCameraPos(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; + + size_t GetCommandSize() const override; +}; + +class CutsceneCommandSceneTransFX : public CutsceneCommand +{ +public: + uint16_t base; + uint16_t startFrame; + uint16_t endFrame; + + CutsceneCommandSceneTransFX(const std::vector& rawData, offset_t rawDataIndex); + + std::string GenerateSourceCode() const override; + size_t GetCommandSize() const override; +}; + +class CutsceneSubCommandEntry_Rumble : public CutsceneSubCommandEntry +{ +public: + uint8_t unk_06; + uint8_t unk_07; + uint8_t unk_08; + uint8_t unk_09; + uint8_t unk_0A; + uint8_t unk_0B; + + CutsceneSubCommandEntry_Rumble(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneCommand_Rumble : public CutsceneCommand +{ +public: + CutsceneCommand_Rumble(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +class CutsceneSubCommandEntry_SetTime : public CutsceneSubCommandEntry +{ +public: + uint8_t hour; + uint8_t minute; + uint32_t unk_08; + + CutsceneSubCommandEntry_SetTime(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneCommand_SetTime : public CutsceneCommand +{ +public: + CutsceneCommand_SetTime(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +class CutsceneSubCommandEntry_TextBox : public CutsceneSubCommandEntry +{ +public: + uint16_t type; + uint16_t textId1; + uint16_t textId2; + + CutsceneSubCommandEntry_TextBox(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneCommand_TextBox : public CutsceneCommand +{ +public: + CutsceneCommand_TextBox(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +class CutsceneSubCommandEntry_ActorAction : public CutsceneSubCommandEntry +{ +public: + uint16_t rotX, rotY, rotZ; + int32_t startPosX, startPosY, startPosZ; + int32_t endPosX, endPosY, endPosZ; + float normalX, normalY, normalZ; + + CutsceneSubCommandEntry_ActorAction(const std::vector& rawData, offset_t rawDataIndex); + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneCommand_ActorAction : public CutsceneCommand +{ +public: + CutsceneCommand_ActorAction(const std::vector& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +class CutsceneCommand_Terminator : public CutsceneCommand +{ +public: + uint16_t base; + uint16_t startFrame; + uint16_t endFrame; + uint16_t unknown; + + CutsceneCommand_Terminator(const std::vector& rawData, offset_t rawDataIndex); + + std::string GenerateSourceCode() const override; + size_t GetCommandSize() const override; +}; diff --git a/tools/ZAPD/ZAPD/WarningHandler.cpp b/tools/ZAPD/ZAPD/WarningHandler.cpp index 29f8352a71..163b028b54 100644 --- a/tools/ZAPD/ZAPD/WarningHandler.cpp +++ b/tools/ZAPD/ZAPD/WarningHandler.cpp @@ -199,8 +199,16 @@ bool WarningHandler::WasElevatedToError(WarningType warnType) { * Print file/line/function info for debugging */ void WarningHandler::FunctionPreamble(const char* filename, int32_t line, const char* function) { - if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG) { - fprintf(stderr, "%s:%i: in function %s:\n", filename, line, function); + bool forcePrint = false; + +#ifdef DEVELOPMENT + forcePrint = true; +#endif + + fprintf(stderr, "\n"); + + if (forcePrint || Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG) { + fprintf(stderr, "%s:%i: in function <%s>:\n", filename, line, function); } } diff --git a/tools/ZAPD/ZAPD/ZAPD.vcxproj b/tools/ZAPD/ZAPD/ZAPD.vcxproj index 431abb73b9..26362c40ca 100644 --- a/tools/ZAPD/ZAPD/ZAPD.vcxproj +++ b/tools/ZAPD/ZAPD/ZAPD.vcxproj @@ -1,343 +1,366 @@ - - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36} - ZAPD - 10.0 - ZAPD - - - - Application - true - v142 - MultiByte - - - Application - false - v142 - true - MultiByte - - - Application - true - v142 - MultiByte - - - Application - false - v142 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - $(OutDir);$(ProjectDir)..\lib\libgfxd;$(ProjectDir)..\packages\libpng-v142.1.6.37.2\build\native\lib\x64\v142\Debug\;$(LibraryPath) - $(ProjectDir)..\ZAPDUtils;$(ProjectDir)..\lib\tinyxml2;$(ProjectDir)..\lib\libgfxd;$(ProjectDir)..\lib\elfio;$(ProjectDir)..\lib\stb;$(ProjectDir);$(IncludePath) - - - $(IncludePath) - - - $(SolutionDir)ZAPD\lib\tinyxml2;$(SolutionDir)ZAPD\lib\libgfxd;$(SolutionDir)ZAPD\lib\elfio;$(SolutionDir)ZAPD\lib\stb;$(ProjectDir);$(IncludePath) - $(SolutionDir)ZAPD\lib\libgfxd;$(SolutionDir)x64\Debug;$(SolutionDir)packages\libpng.1.6.28.1\build\native\lib\x64\v140\dynamic\Debug;$(LibraryPath) - - - - Level3 - Disabled - true - true - stdcpp17 - stdc11 - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - - - - - Level3 - Disabled - true - true - stdcpp17 - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - EnableFastChecks - stdc11 - MultiThreadedDebug - - - true - ZAPDUtils.lib;/WHOLEARCHIVE:ExporterExample.lib;%(AdditionalDependencies) - false - - + + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36} + ZAPD + 10.0 + ZAPD + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + $(OutDir);$(ProjectDir)..\lib\libgfxd;$(ProjectDir)..\packages\libpng-v142.1.6.37.2\build\native\lib\x64\v142\Debug\;$(LibraryPath) + $(ProjectDir)..\ZAPDUtils;$(ProjectDir)..\lib\tinyxml2;$(ProjectDir)..\lib\libgfxd;$(ProjectDir)..\lib\elfio;$(ProjectDir)..\lib\stb;$(ProjectDir);$(IncludePath) + + + $(IncludePath) + + + $(SolutionDir)ZAPD\lib\tinyxml2;$(SolutionDir)ZAPD\lib\libgfxd;$(SolutionDir)ZAPD\lib\elfio;$(SolutionDir)ZAPD\lib\stb;$(ProjectDir);$(IncludePath) + $(SolutionDir)ZAPD\lib\libgfxd;$(SolutionDir)x64\Debug;$(SolutionDir)packages\libpng.1.6.28.1\build\native\lib\x64\v140\dynamic\Debug;$(LibraryPath) + + + + Level3 + Disabled + true + true + stdcpp17 + stdc11 + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + + + true + + cd .. mkdir build\ZAPD -python3 ZAPD/genbuildinfo.py - - - - - Level3 - MaxSpeed - true - true - true - true - - - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - stdcpplatest - _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - - - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - - + python ZAPD/genbuildinfo.py + + + + + Level3 + Disabled + true + true + stdcpp17 + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + EnableFastChecks + stdc11 + MultiThreadedDebug + true + + + true + ZAPDUtils.lib;/WHOLEARCHIVE:ExporterExample.lib;%(AdditionalDependencies) + false + + + cd .. +mkdir build\ZAPD + python ZAPD/genbuildinfo.py + + + + + Level3 + MaxSpeed + true + true + true + true + true + + + true + true + + + cd .. +mkdir build\ZAPD + python ZAPD/genbuildinfo.py + + + + + Level3 + MaxSpeed + true + true + true + true + stdcpplatest + _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + + + true + true + + + cd .. +mkdir build\ZAPD + python ZAPD/genbuildinfo.py + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters b/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters index b8a7daaacf..4de236fad4 100644 --- a/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters +++ b/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters @@ -1,554 +1,566 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {02148456-5068-4613-8478-f10addc58e70} - - - {bcab3136-95ba-4839-833c-43d78ad6e335} - - - {dc06ed84-f6fe-4277-80f3-d62bd5cdbb98} - - - {6049c045-bc38-4221-b29e-ca6d4d8af4aa} - - - {490e3a08-047b-48d3-ab53-3a860a3b92aa} - - - {26c06845-8e8e-4b79-ad18-07c4f9c0f801} - - - {d45c420d-2378-47ac-92c5-80db9475c195} - - - {03cc56a2-e0e8-4167-80a0-98fb900a959a} - - - {73db0879-6df8-4f6a-8cc2-a1f836e9e796} - - - {be9a5be0-ec6a-4200-8e39-bb58c7da7aa8} - - - {7ee79d97-c6a8-4e82-93ef-37981f4d7838} - - - {85600275-99fe-491d-8189-bcc3dc1a8903} - - - {ba9990b0-1082-48bb-874c-6108534b5455} - - - {ce9d91b0-ba20-4296-bc2d-8630965bb392} - - - {730beb67-6d59-4849-9d9b-702c4a565fc0} - - - - - Source Files - - - Source Files\Z64\ZRoom - - - Source Files\Z64\ZRoom\Commands - - - Source Files\Z64\ZRoom - - - 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\ZRoom\Commands - - - Source Files\Z64\ZRoom\Commands - - - Source Files\Z64\ZRoom\Commands - - - Source Files\Z64\ZRoom\Commands - - - Source Files - - - 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\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 - - - Source Files\Z64 - - - Source Files\Z64 - - - Source Files\Z64 - - - Source Files\Z64 - - - Source Files\Z64 - - - Source Files\Z64 - - - Source Files\Z64 - - - Source Files\Z64\ZRoom\Commands - - - Source Files\Z64\ZRoom\Commands - - - Source Files\Z64 - - - Source Files\Z64 - - - Source Files\Z64 - - - Source Files\Z64 - - - 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 - - - Source Files\Z64 - - - Source Files\Z64\ZRoom\Commands - - - Source Files\Z64 - - - Source Files - - - Source Files - - - Source Files\Z64 - - - Source Files - - - Source Files\Z64 - - - Source Files\Z64 - - - Source Files - - - Source Files\Z64 - - - Source Files - - - - - Header Files\Z64\ZRoom - - - Header Files\Z64\ZRoom - - - 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\ZRoom\Commands - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files\Libraries\elfio - - - Header Files - - - 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\ZRoom\Commands - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Libraries - - - Header Files\Libraries - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Z64\ZRoom\Commands - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files - - - Header Files\Z64 - - - 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 - - - Header Files\Z64 - - - Header Files\Z64\ZRoom\Commands - - - Header Files - - - Header Files\Z64 - - - Header Files - - - Header Files\Z64 - - - Header Files - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files\Z64 - - - Header Files - - - - - Resource Files - - - any\any - - - NuGet - - - - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {02148456-5068-4613-8478-f10addc58e70} + + + {bcab3136-95ba-4839-833c-43d78ad6e335} + + + {dc06ed84-f6fe-4277-80f3-d62bd5cdbb98} + + + {6049c045-bc38-4221-b29e-ca6d4d8af4aa} + + + {490e3a08-047b-48d3-ab53-3a860a3b92aa} + + + {26c06845-8e8e-4b79-ad18-07c4f9c0f801} + + + {d45c420d-2378-47ac-92c5-80db9475c195} + + + {03cc56a2-e0e8-4167-80a0-98fb900a959a} + + + {73db0879-6df8-4f6a-8cc2-a1f836e9e796} + + + {be9a5be0-ec6a-4200-8e39-bb58c7da7aa8} + + + {7ee79d97-c6a8-4e82-93ef-37981f4d7838} + + + {85600275-99fe-491d-8189-bcc3dc1a8903} + + + {ba9990b0-1082-48bb-874c-6108534b5455} + + + {ce9d91b0-ba20-4296-bc2d-8630965bb392} + + + {730beb67-6d59-4849-9d9b-702c4a565fc0} + + + + + Source Files + + + Source Files\Z64\ZRoom + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom + + + 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\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files + + + 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\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 + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files\Z64 + + + 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 + + + Source Files\Z64\ZRoom\Commands + + + Source Files\Z64 + + + Source Files + + + Source Files + + + Source Files\Z64 + + + Source Files + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files + + + Source Files\Z64 + + + Source Files + + + Source Files\Z64 + + + Source Files\Z64 + + + Source Files\Z64 + + + + + Header Files\Z64\ZRoom + + + Header Files\Z64\ZRoom + + + 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\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files\Libraries\elfio + + + Header Files + + + 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\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Libraries + + + Header Files\Libraries + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64\ZRoom\Commands + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files + + + Header Files\Z64 + + + 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 + + + Header Files\Z64\ZRoom\Commands + + + Header Files + + + Header Files\Z64 + + + Header Files + + + Header Files\Z64 + + + Header Files + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files + + + Header Files\Z64 + + + Header Files\Z64 + + + Header Files\Z64 + + + + + Resource Files + + + any\any + + + NuGet + + + + + \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZAnimation.cpp b/tools/ZAPD/ZAPD/ZAnimation.cpp index 4d9266b091..74b520b501 100644 --- a/tools/ZAPD/ZAPD/ZAnimation.cpp +++ b/tools/ZAPD/ZAPD/ZAnimation.cpp @@ -51,7 +51,7 @@ void ZNormalAnimation::ParseRawData() { ZAnimation::ParseRawData(); - const uint8_t* data = parent->GetRawData().data(); + auto& data = parent->GetRawData(); rotationValuesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 4); rotationIndicesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 8); diff --git a/tools/ZAPD/ZAPD/ZArray.cpp b/tools/ZAPD/ZAPD/ZArray.cpp index b6d9e50e50..d4f55d6c85 100644 --- a/tools/ZAPD/ZAPD/ZArray.cpp +++ b/tools/ZAPD/ZAPD/ZArray.cpp @@ -106,6 +106,7 @@ std::string ZArray::GetBodySourceCode() const case ZResourceType::Pointer: case ZResourceType::Scalar: case ZResourceType::Vertex: + case ZResourceType::CollisionPoly: output += resList.at(i)->GetBodySourceCode(); break; diff --git a/tools/ZAPD/ZAPD/ZCollision.cpp b/tools/ZAPD/ZAPD/ZCollision.cpp index 6554005eca..debf03775e 100644 --- a/tools/ZAPD/ZAPD/ZCollision.cpp +++ b/tools/ZAPD/ZAPD/ZCollision.cpp @@ -63,16 +63,20 @@ void ZCollisionHeader::ParseRawData() } for (uint16_t i = 0; i < numPolygons; i++) - polygons.push_back(PolygonEntry(rawData, polySegmentOffset + (i * 16))); + { + ZCollisionPoly poly(parent); + poly.SetRawDataIndex(polySegmentOffset + (i * 16)); + poly.ParseRawData(); + polygons.push_back(poly); + } uint16_t highestPolyType = 0; - for (PolygonEntry poly : polygons) + for (ZCollisionPoly poly : polygons) { if (poly.type > highestPolyType) highestPolyType = poly.type; } - for (uint16_t i = 0; i < highestPolyType + 1; i++) polygonTypes.push_back( BitConverter::ToUInt64BE(rawData, polyTypeDefSegmentOffset + (i * 8))); @@ -149,17 +153,15 @@ void ZCollisionHeader::DeclareReferences(const std::string& prefix) for (size_t i = 0; i < polygons.size(); i++) { - 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); + declaration += StringHelper::Sprintf("\t%s,", polygons[i].GetBodySourceCode().c_str()); if (i + 1 < polygons.size()) declaration += "\n"; } - parent->AddDeclarationArray( - polySegmentOffset, DeclarationAlignment::Align4, polygons.size() * 16, "CollisionPoly", - StringHelper::Sprintf("%sPolygons", auxName.c_str()), polygons.size(), declaration); + parent->AddDeclarationArray(polySegmentOffset, DeclarationAlignment::Align4, + polygons.size() * 16, polygons[0].GetSourceTypeName().c_str(), + StringHelper::Sprintf("%sPolygons", auxName.c_str()), + polygons.size(), declaration); } declaration.clear(); @@ -254,34 +256,18 @@ size_t ZCollisionHeader::GetRawDataSize() const return 44; } -PolygonEntry::PolygonEntry(const std::vector& rawData, uint32_t rawDataIndex) -{ - const uint8_t* data = rawData.data(); - - 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); -} - WaterBoxHeader::WaterBoxHeader(const std::vector& rawData, uint32_t rawDataIndex) { - const uint8_t* data = rawData.data(); - - xMin = BitConverter::ToInt16BE(data, rawDataIndex + 0); - ySurface = BitConverter::ToInt16BE(data, rawDataIndex + 2); - zMin = BitConverter::ToInt16BE(data, rawDataIndex + 4); - xLength = BitConverter::ToInt16BE(data, rawDataIndex + 6); - zLength = BitConverter::ToInt16BE(data, rawDataIndex + 8); + xMin = BitConverter::ToInt16BE(rawData, rawDataIndex + 0); + ySurface = BitConverter::ToInt16BE(rawData, rawDataIndex + 2); + zMin = BitConverter::ToInt16BE(rawData, rawDataIndex + 4); + xLength = BitConverter::ToInt16BE(rawData, rawDataIndex + 6); + zLength = BitConverter::ToInt16BE(rawData, rawDataIndex + 8); if (Globals::Instance->game == ZGame::OOT_SW97) - properties = BitConverter::ToInt16BE(data, rawDataIndex + 10); + properties = BitConverter::ToInt16BE(rawData, rawDataIndex + 10); else - properties = BitConverter::ToInt32BE(data, rawDataIndex + 12); + properties = BitConverter::ToInt32BE(rawData, rawDataIndex + 12); } std::string WaterBoxHeader::GetBodySourceCode() const diff --git a/tools/ZAPD/ZAPD/ZCollision.h b/tools/ZAPD/ZAPD/ZCollision.h index 222fd25f9a..6a4948485d 100644 --- a/tools/ZAPD/ZAPD/ZCollision.h +++ b/tools/ZAPD/ZAPD/ZCollision.h @@ -1,10 +1,12 @@ #pragma once +#include "ZCollisionPoly.h" #include "ZFile.h" #include "ZResource.h" #include "ZRoom/ZRoom.h" #include "ZVector.h" +#if 0 class PolygonEntry { public: @@ -14,6 +16,7 @@ public: PolygonEntry(const std::vector& rawData, uint32_t rawDataIndex); }; +#endif class WaterBoxHeader { @@ -78,7 +81,7 @@ public: waterBoxSegmentOffset; std::vector vertices; - std::vector polygons; + std::vector polygons; std::vector polygonTypes; std::vector waterBoxes; CameraDataList* camData = nullptr; diff --git a/tools/ZAPD/ZAPD/ZCollisionPoly.cpp b/tools/ZAPD/ZAPD/ZCollisionPoly.cpp new file mode 100644 index 0000000000..c4eb2d461d --- /dev/null +++ b/tools/ZAPD/ZAPD/ZCollisionPoly.cpp @@ -0,0 +1,78 @@ +#include "ZCollisionPoly.h" + +#include "Globals.h" +#include "Utils/BitConverter.h" +#include "Utils/StringHelper.h" + +REGISTER_ZFILENODE(CollisionPoly, ZCollisionPoly); + +ZCollisionPoly::ZCollisionPoly(ZFile* nParent) : ZResource(nParent) +{ +} + +ZCollisionPoly::~ZCollisionPoly() +{ +} + +void ZCollisionPoly::ParseRawData() +{ + const auto& rawData = parent->GetRawData(); + type = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); + + vtxA = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); + vtxB = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); + vtxC = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); + + normX = BitConverter::ToUInt16BE(rawData, rawDataIndex + 8); + normY = BitConverter::ToUInt16BE(rawData, rawDataIndex + 10); + normZ = BitConverter::ToUInt16BE(rawData, rawDataIndex + 12); + + dist = BitConverter::ToUInt16BE(rawData, rawDataIndex + 14); +} + +void ZCollisionPoly::DeclareReferences(const std::string& prefix) +{ + std::string declaration; + std::string auxName = name; + + if (name == "") + auxName = GetDefaultName(prefix); + + parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(), + GetSourceTypeName(), name.c_str(), GetBodySourceCode()); +} + +std::string ZCollisionPoly::GetBodySourceCode() const +{ + std::string declaration; + + declaration += + StringHelper::Sprintf("{0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X}", + type, vtxA, vtxB, vtxC, normX, normY, normZ, dist); + return declaration; +} + +std::string ZCollisionPoly::GetDefaultName(const std::string& prefix) const +{ + return StringHelper::Sprintf("%sCollisionPoly_%06X", prefix.c_str(), rawDataIndex); +} + +ZResourceType ZCollisionPoly::GetResourceType() const +{ + return ZResourceType::CollisionPoly; +} + +size_t ZCollisionPoly::GetRawDataSize() const +{ + return 16; +} + +std::string ZCollisionPoly::GetSourceTypeName() const +{ + return "CollisionPoly"; +} + +bool ZCollisionPoly::DoesSupportArray() const +{ + return true; +} \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZCollisionPoly.h b/tools/ZAPD/ZAPD/ZCollisionPoly.h new file mode 100644 index 0000000000..64b98ba1d9 --- /dev/null +++ b/tools/ZAPD/ZAPD/ZCollisionPoly.h @@ -0,0 +1,29 @@ +#pragma once + +#include "ZFile.h" +#include "ZResource.h" + +class ZCollisionPoly : public ZResource +{ +public: + uint16_t type; + uint16_t vtxA, vtxB, vtxC; + uint16_t normX, normY, normZ; + uint16_t dist; + + ZCollisionPoly(ZFile* nParent); + ~ZCollisionPoly(); + + void ParseRawData() override; + void DeclareReferences(const std::string& prefix) override; + + std::string GetBodySourceCode() const override; + std::string GetDefaultName(const std::string& prefix) const override; + + std::string GetSourceTypeName() const override; + ZResourceType GetResourceType() const override; + + bool DoesSupportArray() const override; + + size_t GetRawDataSize() const override; +}; \ No newline at end of file diff --git a/tools/ZAPD/ZAPD/ZCutscene.cpp b/tools/ZAPD/ZAPD/ZCutscene.cpp index ba8fe89638..62f814b13d 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.cpp +++ b/tools/ZAPD/ZAPD/ZCutscene.cpp @@ -1,5 +1,9 @@ #include "ZCutscene.h" +#include + +#include "Globals.h" +#include "OtherStructs/CutsceneMM_Commands.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" #include "WarningHandler.h" @@ -7,7 +11,7 @@ REGISTER_ZFILENODE(Cutscene, ZCutscene); -ZCutscene::ZCutscene(ZFile* nParent) : ZCutsceneBase(nParent) +ZCutscene::ZCutscene(ZFile* nParent) : ZResource(nParent) { } @@ -16,91 +20,20 @@ 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() -{ -} std::string ZCutscene::GetBodySourceCode() const { std::string output = ""; - 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(); + output += " " + cmd->GenerateSourceCode(); } - output += StringHelper::Sprintf(" CS_END(),\n", commands.size(), endFrame); + output += StringHelper::Sprintf(" CS_END(),", commands.size(), endFrame); return output; } @@ -115,12 +48,19 @@ size_t ZCutscene::GetRawDataSize() const for (size_t i = 0; i < commands.size(); i++) { CutsceneCommand* cmd = commands[i]; + size += cmd->GetCommandSize(); - size += 4; } // End - size += 8; + if (Globals::Instance->game == ZGame::MM_RETAIL) + { + size += 4; + } + else + { + size += 8; + } return size; } @@ -135,153 +75,68 @@ void ZCutscene::ParseRawData() commands = std::vector(); endFrame = BitConverter::ToInt32BE(rawData, rawDataIndex + 4); - uint32_t currentPtr = rawDataIndex + 8; + offset_t currentPtr = rawDataIndex + 8; for (int32_t i = 0; i < numCommands; i++) { - int32_t id = BitConverter::ToInt32BE(rawData, currentPtr); + uint32_t id = BitConverter::ToUInt32BE(rawData, currentPtr); - if (id == -1) + if (id == 0xFFFFFFFF) break; - CutsceneCommands cmdID = (CutsceneCommands)GetCommandFromID(id); + if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG) + { + printf("Cutscene Command: 0x%X (%i)\n", id, id); + } + currentPtr += 4; - int32_t numEntries = 1; + CutsceneCommand* cmd = nullptr; - for (int32_t j = 0; j < numEntries; j++) + if (Globals::Instance->game == ZGame::MM_RETAIL) { - CutsceneCommand* cmd = nullptr; - - switch (cmdID) - { - case CutsceneCommands::Cmd00: - break; - case CutsceneCommands::SetCameraPos: - cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); - break; - case CutsceneCommands::SetCameraFocus: - cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); - break; - case CutsceneCommands::SpecialAction: - cmd = new CutsceneCommandSpecialAction(rawData, currentPtr); - break; - case CutsceneCommands::SetLighting: - cmd = new CutsceneCommandEnvLighting(rawData, currentPtr); - break; - case CutsceneCommands::SetCameraPosLink: - cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); - break; - case CutsceneCommands::SetCameraFocusLink: - cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); - break; - case CutsceneCommands::Cmd07: - break; - case CutsceneCommands::Cmd08: - break; - case CutsceneCommands::Cmd09: - cmd = new CutsceneCommandUnknown9(rawData, currentPtr); - break; - case CutsceneCommands::Textbox: - cmd = new CutsceneCommandTextbox(rawData, currentPtr); - break; - case CutsceneCommands::Unknown: - cmd = new CutsceneCommandUnknown(rawData, currentPtr); - break; - case CutsceneCommands::SetActorAction0: - case CutsceneCommands::SetActorAction1: - case CutsceneCommands::SetActorAction2: - case CutsceneCommands::SetActorAction3: - case CutsceneCommands::SetActorAction4: - case CutsceneCommands::SetActorAction5: - case CutsceneCommands::SetActorAction6: - case CutsceneCommands::SetActorAction7: - case CutsceneCommands::SetActorAction8: - case CutsceneCommands::SetActorAction9: - case CutsceneCommands::SetActorAction10: - cmd = new CutsceneCommandActorAction(rawData, currentPtr); - break; - case CutsceneCommands::SetSceneTransFX: - cmd = new CutsceneCommandSceneTransFX(rawData, currentPtr); - break; - case CutsceneCommands::Nop: - cmd = new CutsceneCommandNop(rawData, currentPtr); - break; - case CutsceneCommands::PlayBGM: - cmd = new CutsceneCommandPlayBGM(rawData, currentPtr); - break; - case CutsceneCommands::StopBGM: - cmd = new CutsceneCommandStopBGM(rawData, currentPtr); - break; - case CutsceneCommands::FadeBGM: - cmd = new CutsceneCommandFadeBGM(rawData, currentPtr); - break; - case CutsceneCommands::SetTime: - cmd = new CutsceneCommandDayTime(rawData, currentPtr); - break; - case CutsceneCommands::Terminator: - cmd = new CutsceneCommandTerminator(rawData, currentPtr); - break; - case CutsceneCommands::End: - cmd = new CutsceneCommandEnd(rawData, currentPtr); - break; - case CutsceneCommands::Error: - HANDLE_WARNING_RESOURCE(WarningType::NotImplemented, parent, this, rawDataIndex, - StringHelper::Sprintf("cutscene command error %d", cmdID), - ""); - break; - } - - cmd->commandIndex = i; - cmd->commandID = (uint32_t)id; - currentPtr += (uint32_t)cmd->GetCommandSize(); - - commands.push_back(cmd); + cmd = GetCommandMM(id, currentPtr); } + else + { + cmd = GetCommandOoT(id, currentPtr); + } + + if (cmd == nullptr) + { + HANDLE_WARNING_RESOURCE( + WarningType::NotImplemented, parent, this, rawDataIndex, + StringHelper::Sprintf("Cutscene command not implemented"), + StringHelper::Sprintf("Command ID: 0x%X\nIndex: %d\ncurrentPtr-rawDataIndex: 0x%X", + id, i, currentPtr - rawDataIndex)); + cmd = new CutsceneMMCommand_NonImplemented(rawData, currentPtr); + } + + assert(cmd != nullptr); + + cmd->commandIndex = i; + cmd->SetCommandID(id); + size_t commmandSize = cmd->GetCommandSize(); + if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG) + { + printf("\t Command size: 0x%zX (%zu)\n", commmandSize, commmandSize); + } + currentPtr += commmandSize - 4; + + commands.push_back(cmd); } } -CutsceneCommands ZCutscene::GetCommandFromID(int32_t id) +CutsceneCommand* ZCutscene::GetCommandOoT(uint32_t id, offset_t currentPtr) const { + CutsceneCommands cmdID = static_cast(id); + + const auto& rawData = parent->GetRawData(); + switch (id) { - case 0x0003: - return CutsceneCommands::SpecialAction; - case 0x0004: - return CutsceneCommands::SetLighting; - case 0x0056: - return CutsceneCommands::PlayBGM; - case 0x0057: - return CutsceneCommands::StopBGM; - case 0x007C: - return CutsceneCommands::FadeBGM; - case 0x0009: - return CutsceneCommands::Cmd09; - case 0x0013: - return CutsceneCommands::Textbox; - case 0x008C: - return CutsceneCommands::SetTime; - case 0x0001: - return CutsceneCommands::SetCameraPos; - case 0x0002: - return CutsceneCommands::SetCameraFocus; - case 0x0005: - return CutsceneCommands::SetCameraPosLink; - case 0x0006: - return CutsceneCommands::SetCameraFocusLink; - case 0x0007: - return CutsceneCommands::Cmd07; - case 0x0008: - return CutsceneCommands::Cmd08; - case 0x03E8: - return CutsceneCommands::Terminator; - case 0xFFFF: - return CutsceneCommands::End; - case 0x002D: - return CutsceneCommands::SetSceneTransFX; - case 10: - return CutsceneCommands::SetActorAction0; - case 15: + case 10: // CutsceneCommands::SetPlayerAction + case 15: // CutsceneCommands::SetActorAction1 case 17: case 18: case 23: @@ -299,8 +154,7 @@ CutsceneCommands ZCutscene::GetCommandFromID(int32_t id) case 138: case 139: case 144: - return CutsceneCommands::SetActorAction1; - case 14: + case 14: // CutsceneCommands::SetActorAction2 case 16: case 24: case 35: @@ -318,8 +172,7 @@ CutsceneCommands ZCutscene::GetCommandFromID(int32_t id) case 125: case 131: case 141: - return CutsceneCommands::SetActorAction2; - case 25: + case 25: // CutsceneCommands::SetActorAction3 case 36: case 41: case 50: @@ -332,8 +185,7 @@ CutsceneCommands ZCutscene::GetCommandFromID(int32_t id) case 121: case 126: case 132: - return CutsceneCommands::SetActorAction3; - case 29: + case 29: // CutsceneCommands::SetActorAction4 case 37: case 42: case 51: @@ -346,8 +198,7 @@ CutsceneCommands ZCutscene::GetCommandFromID(int32_t id) case 108: case 127: case 133: - return CutsceneCommands::SetActorAction4; - case 30: + case 30: // CutsceneCommands::SetActorAction5 case 38: case 43: case 47: @@ -356,16 +207,14 @@ CutsceneCommands ZCutscene::GetCommandFromID(int32_t id) case 83: case 128: case 135: - return CutsceneCommands::SetActorAction5; - case 44: + case 44: // CutsceneCommands::SetActorAction6 case 55: case 77: case 84: case 90: case 129: case 136: - return CutsceneCommands::SetActorAction6; - case 31: + case 31: // CutsceneCommands::SetActorAction7 case 52: case 57: case 58: @@ -373,19 +222,17 @@ CutsceneCommands ZCutscene::GetCommandFromID(int32_t id) case 115: case 130: case 137: - return CutsceneCommands::SetActorAction7; - case 49: + case 49: // CutsceneCommands::SetActorAction8 case 60: case 89: case 111: case 114: case 134: case 142: - return CutsceneCommands::SetActorAction8; - case 62: - return CutsceneCommands::SetActorAction9; - case 143: - return CutsceneCommands::SetActorAction10; + case 62: // CutsceneCommands::SetActorAction9 + case 143: // CutsceneCommands::SetActorAction10 + return new CutsceneCommand_ActorAction(rawData, currentPtr); + case 0x0B: case 0x0D: case 0x1A: @@ -403,843 +250,120 @@ CutsceneCommands ZCutscene::GetCommandFromID(int32_t id) case 0x70: case 0x71: case 0x4A: - return CutsceneCommands::Unknown; + return new CutsceneCommand_GenericCmd(rawData, currentPtr, cmdID); } - HANDLE_WARNING_RESOURCE( - WarningType::NotImplemented, parent, this, rawDataIndex, - StringHelper::Sprintf("could not identify cutscene command. ID 0x%04X", id), ""); - - return CutsceneCommands::Error; -} - -ZResourceType ZCutscene::GetResourceType() const -{ - return ZResourceType::Cutscene; -} - -CutsceneCommand::CutsceneCommand([[maybe_unused]] const std::vector& rawData, - [[maybe_unused]] uint32_t rawDataIndex) -{ -} - -CutsceneCommand::~CutsceneCommand() -{ -} - -std::string CutsceneCommand::GetCName() -{ - return "SCmdCutsceneData"; -} - -std::string CutsceneCommand::GenerateSourceCode(uint32_t baseAddress) -{ - return StringHelper::Sprintf("%s CutsceneData%04XCmd%02X = { 0x%02X,", GetCName().c_str(), - baseAddress, commandIndex, commandID); -} - -size_t CutsceneCommand::GetCommandSize() -{ - return 4; -} - -CutsceneCameraPoint::CutsceneCameraPoint(const std::vector& rawData, uint32_t rawDataIndex) -{ - const uint8_t* data = rawData.data(); - - continueFlag = data[rawDataIndex + 0]; - cameraRoll = data[rawDataIndex + 1]; - nextPointFrame = BitConverter::ToInt16BE(data, rawDataIndex + 2); - viewAngle = BitConverter::ToFloatBE(data, rawDataIndex + 4); - - posX = BitConverter::ToInt16BE(data, rawDataIndex + 8); - posY = BitConverter::ToInt16BE(data, rawDataIndex + 10); - posZ = BitConverter::ToInt16BE(data, rawDataIndex + 12); - - unused = BitConverter::ToInt16BE(data, rawDataIndex + 14); -} - -CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - const uint8_t* data = rawData.data(); - - 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 = std::vector(); - - bool shouldContinue = true; - - uint32_t currentPtr = rawDataIndex + 8; - - while (shouldContinue) + switch (cmdID) { - CutsceneCameraPoint* camPoint = new CutsceneCameraPoint(rawData, currentPtr); - entries.push_back(camPoint); + case CutsceneCommands::Misc: + case CutsceneCommands::SetLighting: + case CutsceneCommands::PlayBGM: + case CutsceneCommands::StopBGM: + case CutsceneCommands::FadeBGM: + return new CutsceneCommand_GenericCmd(rawData, currentPtr, cmdID); - if (camPoint->continueFlag == -1) - shouldContinue = false; + case CutsceneCommands::SetCameraPos: + case CutsceneCommands::SetCameraFocus: + case CutsceneCommands::SetCameraPosLink: + case CutsceneCommands::SetCameraFocusLink: + return new CutsceneCommandSetCameraPos(rawData, currentPtr); - currentPtr += 16; + case CutsceneCommands::Cmd07: + break; + case CutsceneCommands::Cmd08: + break; + case CutsceneCommands::Cmd09: + return new CutsceneCommand_Rumble(rawData, currentPtr); + case CutsceneCommands::Textbox: + return new CutsceneCommand_TextBox(rawData, currentPtr); + + case CutsceneCommands::SetPlayerAction: + case CutsceneCommands::SetActorAction1: + case CutsceneCommands::SetActorAction2: + case CutsceneCommands::SetActorAction3: + case CutsceneCommands::SetActorAction4: + case CutsceneCommands::SetActorAction5: + case CutsceneCommands::SetActorAction6: + case CutsceneCommands::SetActorAction7: + case CutsceneCommands::SetActorAction8: + case CutsceneCommands::SetActorAction9: + case CutsceneCommands::SetActorAction10: + break; + + case CutsceneCommands::SetSceneTransFX: + return new CutsceneCommandSceneTransFX(rawData, currentPtr); + + case CutsceneCommands::SetTime: + return new CutsceneCommand_SetTime(rawData, currentPtr); + case CutsceneCommands::Terminator: + return new CutsceneCommand_Terminator(rawData, currentPtr); } + + return nullptr; } -// TODO -std::string CutsceneCommandSetCameraPos::GetCName() +CutsceneCommand* ZCutscene::GetCommandMM(uint32_t id, offset_t currentPtr) const { - return ""; -} + CutsceneMMCommands cmdID = static_cast(id); -std::string CutsceneCommandSetCameraPos::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; + const auto& rawData = parent->GetRawData(); - std::string listStr; - std::string posStr; - - if (commandID == (int32_t)CutsceneCommands::SetCameraFocus) + if (((id >= 100) && (id < 150)) || (id == 201) || ((id >= 450) && (id < 600))) { - listStr = "CS_CAM_FOCUS_POINT_LIST"; - posStr = "CS_CAM_FOCUS_POINT"; + return new CutsceneCommand_ActorAction(rawData, currentPtr); } - else if (commandID == (int32_t)CutsceneCommands::SetCameraFocusLink) + + switch (cmdID) { - listStr = "CS_CAM_FOCUS_POINT_PLAYER_LIST"; - posStr = "CS_CAM_FOCUS_POINT_PLAYER"; - } - else if (commandID == (int32_t)CutsceneCommands::SetCameraPosLink) - { - listStr = "CS_CAM_POS_PLAYER_LIST"; - posStr = "CS_CAM_POS_PLAYER"; - } - else - { - listStr = "CS_CAM_POS_LIST"; - posStr = "CS_CAM_POS"; + case CutsceneMMCommands::CS_CMD_MISC: + case CutsceneMMCommands::CS_CMD_SET_LIGHTING: + case CutsceneMMCommands::CS_CMD_SCENE_TRANS_FX: + case CutsceneMMCommands::CS_CMD_MOTIONBLUR: + case CutsceneMMCommands::CS_CMD_GIVETATL: + case CutsceneMMCommands::CS_CMD_PLAYSEQ: + case CutsceneMMCommands::CS_CMD_130: + case CutsceneMMCommands::CS_CMD_131: + case CutsceneMMCommands::CS_CMD_132: + case CutsceneMMCommands::CS_CMD_STOPSEQ: + case CutsceneMMCommands::CS_CMD_PLAYAMBIENCE: + case CutsceneMMCommands::CS_CMD_FADEAMBIENCE: + case CutsceneMMCommands::CS_CMD_TERMINATOR: + case CutsceneMMCommands::CS_CMD_CHOOSE_CREDITS_SCENES: + + case CutsceneMMCommands::CS_CMD_UNK_FA: + case CutsceneMMCommands::CS_CMD_UNK_FE: + case CutsceneMMCommands::CS_CMD_UNK_FF: + case CutsceneMMCommands::CS_CMD_UNK_100: + case CutsceneMMCommands::CS_CMD_UNK_101: + case CutsceneMMCommands::CS_CMD_UNK_102: + case CutsceneMMCommands::CS_CMD_UNK_103: + case CutsceneMMCommands::CS_CMD_UNK_104: + case CutsceneMMCommands::CS_CMD_UNK_105: + case CutsceneMMCommands::CS_CMD_UNK_108: + case CutsceneMMCommands::CS_CMD_UNK_109: + case CutsceneMMCommands::CS_CMD_UNK_12D: + return new CutsceneMMCommand_GenericCmd(rawData, currentPtr, cmdID); + + case CutsceneMMCommands::CS_CMD_TEXTBOX: + return new CutsceneCommand_TextBox(rawData, currentPtr); + case CutsceneMMCommands::CS_CMD_CAMERA: + return new CutsceneMMCommand_Camera(rawData, currentPtr); + case CutsceneMMCommands::CS_CMD_FADESCREEN: + return new CutsceneMMCommand_FadeScreen(rawData, currentPtr); + case CutsceneMMCommands::CS_CMD_FADESEQ: + return new CutsceneMMCommand_FadeSeq(rawData, currentPtr); + case CutsceneMMCommands::CS_CMD_SETTIME: + return new CutsceneCommand_SetTime(rawData, currentPtr); + case CutsceneMMCommands::CS_CMD_SET_PLAYER_ACTION: + return new CutsceneCommand_ActorAction(rawData, currentPtr); + case CutsceneMMCommands::CS_CMD_RUMBLE: + return new CutsceneCommand_Rumble(rawData, currentPtr); } - result += StringHelper::Sprintf("%s(%i, %i),\n", listStr.c_str(), startFrame, endFrame); - - for (size_t i = 0; i < entries.size(); i++) - { - std::string continueMacro = "CS_CMD_CONTINUE"; - if (entries[i]->continueFlag != 0) - continueMacro = "CS_CMD_STOP"; - result += StringHelper::Sprintf(" %s(%s, 0x%02X, %i, %ff, %i, %i, %i, 0x%04X),\n", - posStr.c_str(), continueMacro.c_str(), - entries[i]->cameraRoll, entries[i]->nextPointFrame, - entries[i]->viewAngle, entries[i]->posX, entries[i]->posY, - entries[i]->posZ, entries[i]->unused); - } - - return result; -} - -size_t CutsceneCommandSetCameraPos::GetCommandSize() -{ - return 8 + (entries.size() * 16); -} - -MusicFadeEntry::MusicFadeEntry(const std::vector& rawData, uint32_t rawDataIndex) -{ - 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 std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - uint32_t numEntries = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); - - rawDataIndex += 4; - - for (uint32_t i = 0; i < numEntries; i++) - { - entries.push_back(new MusicFadeEntry(rawData, rawDataIndex)); - rawDataIndex += 0x30; - } -} - -std::string CutsceneCommandFadeBGM::GetCName() -{ - return "CsCmdMusicFade"; -} - -std::string CutsceneCommandFadeBGM::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_FADE_BGM_LIST(%i),\n", entries.size()); - - for (size_t i = 0; i < entries.size(); i++) - { - result += StringHelper::Sprintf( - " 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); - } - - return result; -} - -size_t CutsceneCommandFadeBGM::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + 0x30 * entries.size(); -} - -MusicChangeEntry::MusicChangeEntry(const std::vector& rawData, uint32_t rawDataIndex) -{ - 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 std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - uint32_t numEntries = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); - - rawDataIndex += 4; - - for (uint32_t i = 0; i < numEntries; i++) - { - entries.push_back(new MusicChangeEntry(rawData, rawDataIndex)); - rawDataIndex += 0x30; - } -} - -std::string CutsceneCommandPlayBGM::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_PLAY_BGM_LIST(%i),\n", entries.size()); - - for (size_t i = 0; i < entries.size(); i++) - { - result += StringHelper::Sprintf( - " 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; -} - -std::string CutsceneCommandPlayBGM::GetCName() -{ - return "CsCmdMusicChange"; -} - -size_t CutsceneCommandPlayBGM::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + 0x30; -} - -CutsceneCommandStopBGM::CutsceneCommandStopBGM(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - uint32_t numEntries = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); - - rawDataIndex += 4; - - for (uint32_t i = 0; i < numEntries; i++) - { - entries.push_back(new MusicChangeEntry(rawData, rawDataIndex)); - rawDataIndex += 0x30; - } -} - -std::string CutsceneCommandStopBGM::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_STOP_BGM_LIST(%i),\n", entries.size()); - - for (size_t i = 0; i < entries.size(); i++) - { - result += StringHelper::Sprintf( - "\t\tCS_STOP_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; -} - -std::string CutsceneCommandStopBGM::GetCName() -{ - return "CsCmdMusicChange"; -} - -size_t CutsceneCommandStopBGM::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + 0x30; -} - -EnvLightingEntry::EnvLightingEntry(const std::vector& rawData, uint32_t rawDataIndex) -{ - setting = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); - startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); - endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4); - unused0 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); - unused1 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 8); - unused2 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 12); - unused3 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 16); - unused4 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 20); - unused5 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 24); - unused6 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 28); - unused7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32); -} - -CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); - - rawDataIndex += 4; - - for (int32_t i = 0; i < numEntries; i++) - { - entries.push_back(new EnvLightingEntry(rawData, rawDataIndex)); - rawDataIndex += 0x30; - } -} - -std::string CutsceneCommandEnvLighting::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_LIGHTING_LIST(%i),\n", entries.size()); - - for (size_t i = 0; i < entries.size(); i++) - { - result += StringHelper::Sprintf( - "\t\tCS_LIGHTING(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->setting, - 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); - } - - return result; -} - -std::string CutsceneCommandEnvLighting::GetCName() -{ - return "CsCmdEnvLighting"; -} - -size_t CutsceneCommandEnvLighting::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + (0x30 * entries.size()); -} - -Unknown9Entry::Unknown9Entry(const std::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); - unk2 = rawData[rawDataIndex + 6]; - unk3 = rawData[rawDataIndex + 7]; - unk4 = rawData[rawDataIndex + 8]; - unused0 = rawData[rawDataIndex + 10]; - unused1 = rawData[rawDataIndex + 11]; - ; -} - -CutsceneCommandUnknown9::CutsceneCommandUnknown9(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); - - rawDataIndex += 4; - - for (int32_t i = 0; i < numEntries; i++) - { - entries.push_back(new Unknown9Entry(rawData, rawDataIndex)); - rawDataIndex += 0x0C; - } -} - -std::string CutsceneCommandUnknown9::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_CMD_09_LIST(%i),\n", entries.size()); - - for (size_t i = 0; i < entries.size(); i++) - { - result += StringHelper::Sprintf("\t\tCS_CMD_09(%i, %i, %i, %i, %i, %i, %i, %i),\n", - entries[i]->base, entries[i]->startFrame, - entries[i]->endFrame, entries[i]->unk2, entries[i]->unk3, - entries[i]->unk4, entries[i]->unused0, entries[i]->unused1); - } - - return result; -} - -std::string CutsceneCommandUnknown9::GetCName() -{ - return "CsCmdUnknown9"; -} - -size_t CutsceneCommandUnknown9::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + (entries.size() * 12); -} - -UnkEntry::UnkEntry(const std::vector& rawData, uint32_t rawDataIndex) -{ - unused0 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 0); - unused1 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 4); - unused2 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 8); - unused3 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 12); - unused4 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 16); - unused5 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 20); - unused6 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 24); - unused7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 28); - unused8 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32); - unused9 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 36); - unused10 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 40); - unused11 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 44); -} - -CutsceneCommandUnknown::CutsceneCommandUnknown(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); - - rawDataIndex += 4; - - for (int32_t i = 0; i < numEntries; i++) - { - entries.push_back(new UnkEntry(rawData, rawDataIndex)); - rawDataIndex += 0x30; - } -} - -std::string CutsceneCommandUnknown::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%02X, %i),\n", commandID, entries.size()); - - for (size_t i = 0; i < entries.size(); i++) - { - result += StringHelper::Sprintf( - " 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); - } - - return result; -} - -std::string CutsceneCommandUnknown::GetCName() -{ - return "CsCmdUnknown1A"; -} - -size_t CutsceneCommandUnknown::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + (entries.size() * 0x30); -} - -DayTimeEntry::DayTimeEntry(const std::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); - hour = rawData[rawDataIndex + 6]; - minute = rawData[rawDataIndex + 7]; - unused = rawData[rawDataIndex + 8]; -} - -CutsceneCommandDayTime::CutsceneCommandDayTime(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); - - rawDataIndex += 4; - - for (int32_t i = 0; i < numEntries; i++) - { - entries.push_back(new DayTimeEntry(rawData, rawDataIndex)); - rawDataIndex += 12; - } -} - -std::string CutsceneCommandDayTime::GetCName() -{ - return "CsCmdDayTime"; -} - -std::string CutsceneCommandDayTime::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_TIME_LIST(%i),\n", entries.size()); - - for (size_t i = 0; i < entries.size(); i++) - { - 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; -} - -size_t CutsceneCommandDayTime::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + (entries.size() * 12); -} - -TextboxEntry::TextboxEntry(const std::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); - type = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); - textID1 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 8); - textID2 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 10); -} - -CutsceneCommandTextbox::CutsceneCommandTextbox(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); - - rawDataIndex += 4; - - for (int32_t i = 0; i < numEntries; i++) - { - entries.push_back(new TextboxEntry(rawData, rawDataIndex)); - rawDataIndex += 12; - } -} - -std::string CutsceneCommandTextbox::GetCName() -{ - return "CsCmdTextbox"; -} - -std::string CutsceneCommandTextbox::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_TEXT_LIST(%i),\n", entries.size()); - - for (size_t i = 0; i < entries.size(); i++) - { - if (entries[i]->base == 0xFFFF) - { - result += StringHelper::Sprintf(" CS_TEXT_NONE(%i, %i),\n", - entries[i]->startFrame, entries[i]->endFrame); - } - else - { - result += StringHelper::Sprintf( - " 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); - } - } - - return result; -} - -size_t CutsceneCommandTextbox::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + (entries.size() * 12); -} - -ActorAction::ActorAction(const std::vector& rawData, uint32_t rawDataIndex) -{ - const uint8_t* data = rawData.data(); - - action = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 0); - startFrame = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 2); - endFrame = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 4); - rotX = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 6); - rotY = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 8); - rotZ = (uint16_t)BitConverter::ToInt16BE(data, rawDataIndex + 10); - startPosX = BitConverter::ToInt32BE(data, rawDataIndex + 12); - startPosY = BitConverter::ToInt32BE(data, rawDataIndex + 16); - startPosZ = BitConverter::ToInt32BE(data, rawDataIndex + 20); - endPosX = BitConverter::ToInt32BE(data, rawDataIndex + 24); - endPosY = BitConverter::ToInt32BE(data, rawDataIndex + 28); - endPosZ = BitConverter::ToInt32BE(data, rawDataIndex + 32); - normalX = BitConverter::ToFloatBE(data, rawDataIndex + 36); - normalY = BitConverter::ToFloatBE(data, rawDataIndex + 40); - normalZ = BitConverter::ToFloatBE(data, rawDataIndex + 44); -} - -CutsceneCommandActorAction::CutsceneCommandActorAction(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex); - - rawDataIndex += 4; - - for (int32_t i = 0; i < numEntries; i++) - { - entries.push_back(new ActorAction(rawData, rawDataIndex)); - rawDataIndex += 0x30; - } -} - -std::string CutsceneCommandActorAction::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - std::string subCommand; - - if (commandID == 10) - { - result += StringHelper::Sprintf("CS_PLAYER_ACTION_LIST(%i),\n", entries.size()); - subCommand = "CS_PLAYER_ACTION"; - } - else - { - result += StringHelper::Sprintf("CS_NPC_ACTION_LIST(%i, %i),\n", commandID, entries.size()); - subCommand = "CS_NPC_ACTION"; - } - - 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, %.11ef, " - "%.11ef, %.11ef),\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, entries[i]->normalX, entries[i]->normalY, entries[i]->normalZ); - } - - return result; -} - -std::string CutsceneCommandActorAction::GetCName() -{ - return "CsCmdBase"; -} - -size_t CutsceneCommandActorAction::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + (entries.size() * 0x30); -} - -CutsceneCommandTerminator::CutsceneCommandTerminator(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); - startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); - endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4); - unknown = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); // endFrame duplicate -} - -std::string CutsceneCommandTerminator::GetCName() -{ - return "CsCmdBase"; -} - -std::string CutsceneCommandTerminator::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_TERMINATOR(0x%04X, %i, %i),\n", base, startFrame, endFrame); - - return result; -} - -size_t CutsceneCommandTerminator::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + 8; -} - -CutsceneCommandEnd::CutsceneCommandEnd(const std::vector& rawData, uint32_t rawDataIndex) - : CutsceneCommand(rawData, 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); -} - -std::string CutsceneCommandEnd::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_END(),\n"); - - return result; -} - -std::string CutsceneCommandEnd::GetCName() -{ - return "CsCmdBase"; -} - -size_t CutsceneCommandEnd::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + 6; -} - -SpecialActionEntry::SpecialActionEntry(const std::vector& rawData, uint32_t rawDataIndex) -{ - const uint8_t* data = rawData.data(); - - base = BitConverter::ToUInt16BE(data, rawDataIndex + 0); - startFrame = BitConverter::ToUInt16BE(data, rawDataIndex + 2); - endFrame = BitConverter::ToUInt16BE(data, rawDataIndex + 4); - unused0 = BitConverter::ToUInt16BE(data, rawDataIndex + 6); - unused1 = BitConverter::ToUInt32BE(data, rawDataIndex + 8); - unused2 = BitConverter::ToUInt32BE(data, rawDataIndex + 12); - unused3 = BitConverter::ToUInt32BE(data, rawDataIndex + 16); - unused4 = BitConverter::ToUInt32BE(data, rawDataIndex + 20); - unused5 = BitConverter::ToUInt32BE(data, rawDataIndex + 24); - unused6 = BitConverter::ToUInt32BE(data, rawDataIndex + 28); - unused7 = BitConverter::ToUInt32BE(data, rawDataIndex + 32); - unused8 = BitConverter::ToUInt32BE(data, rawDataIndex + 36); - unused9 = BitConverter::ToUInt32BE(data, rawDataIndex + 40); - unused10 = BitConverter::ToUInt32BE(data, rawDataIndex + 44); -} - -CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - int32_t numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); - - rawDataIndex += 4; - - for (int32_t i = 0; i < numEntries; i++) - { - entries.push_back(new SpecialActionEntry(rawData, rawDataIndex)); - rawDataIndex += 0x30; - } -} - -std::string CutsceneCommandSpecialAction::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - std::string result; - - result += StringHelper::Sprintf("CS_MISC_LIST(%i),\n", entries.size()); - - for (size_t i = 0; i < entries.size(); i++) - { - 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", - 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, - entries[i]->unused9, entries[i]->unused10); - } - - return result; -} - -std::string CutsceneCommandSpecialAction::GetCName() -{ - return "CsCmdBase"; -} - -size_t CutsceneCommandSpecialAction::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + (0x30 * entries.size()); -} - -CutsceneCommandNop::CutsceneCommandNop(const std::vector& rawData, uint32_t rawDataIndex) - : CutsceneCommand(rawData, 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); -} - -std::string CutsceneCommandNop::GetCName() -{ - return "CsCmdBase"; -} - -size_t CutsceneCommandNop::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + 6; -} - -CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const std::vector& rawData, - uint32_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0); - startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2); - endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4); -} - -std::string CutsceneCommandSceneTransFX::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress) -{ - return StringHelper::Sprintf("CS_SCENE_TRANS_FX(%i, %i, %i),\n", base, startFrame, endFrame); -} - -std::string CutsceneCommandSceneTransFX::GetCName() -{ - return "CsCmdBase"; -} - -size_t CutsceneCommandSceneTransFX::GetCommandSize() -{ - return CutsceneCommand::GetCommandSize() + 8; -} - -ZCutsceneBase::ZCutsceneBase(ZFile* nParent) : ZResource(nParent) -{ + return nullptr; } -Declaration* ZCutsceneBase::DeclareVar(const std::string& prefix, const std::string& bodyStr) +Declaration* ZCutscene::DeclareVar(const std::string& prefix, const std::string& bodyStr) { std::string auxName = name; @@ -1253,7 +377,12 @@ Declaration* ZCutsceneBase::DeclareVar(const std::string& prefix, const std::str return decl; } -std::string ZCutsceneBase::GetSourceTypeName() const +std::string ZCutscene::GetSourceTypeName() const { return "CutsceneData"; } + +ZResourceType ZCutscene::GetResourceType() const +{ + return ZResourceType::Cutscene; +} diff --git a/tools/ZAPD/ZAPD/ZCutscene.h b/tools/ZAPD/ZAPD/ZCutscene.h index 8e901e3075..098f3ad868 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.h +++ b/tools/ZAPD/ZAPD/ZCutscene.h @@ -3,422 +3,13 @@ #include #include #include -#include "ZFile.h" -#include "ZResource.h" #include "tinyxml2.h" -enum class CutsceneCommands -{ - Cmd00 = 0x0000, - SetCameraPos = 0x0001, - SetCameraFocus = 0x0002, - SpecialAction = 0x0003, - SetLighting = 0x0004, - SetCameraPosLink = 0x0005, - SetCameraFocusLink = 0x0006, - Cmd07 = 0x0007, - Cmd08 = 0x0008, - Cmd09 = 0x0009, - Unknown = 0x001A, - Textbox = 0x0013, - SetActorAction0 = 0x000A, - SetActorAction1 = 0x000F, - SetActorAction2 = 0x000E, - SetActorAction3 = 0x0019, - SetActorAction4 = 0x001D, - SetActorAction5 = 0x001E, - SetActorAction6 = 0x002C, - SetActorAction7 = 0x001F, - SetActorAction8 = 0x0031, - SetActorAction9 = 0x003E, - SetActorAction10 = 0x008F, - SetSceneTransFX = 0x002D, - Nop = 0x000B, - PlayBGM = 0x0056, - StopBGM = 0x0057, - FadeBGM = 0x007C, - SetTime = 0x008C, - Terminator = 0x03E8, - End = 0xFFFF, - Error = 0xFEAF, -}; +#include "OtherStructs/Cutscene_Commands.h" +#include "ZFile.h" +#include "ZResource.h" -class CutsceneCameraPoint -{ -public: - int8_t continueFlag; - int8_t cameraRoll; - int16_t nextPointFrame; - float viewAngle; - int16_t posX, posY, posZ; - int16_t unused; - - CutsceneCameraPoint(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommand -{ -public: - uint32_t commandID; - uint32_t commandIndex; - 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(); -}; - -class CutsceneCommandSetCameraPos : public CutsceneCommand -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint16_t unused; - - std::vector entries; - ~CutsceneCommandSetCameraPos(); - CutsceneCommandSetCameraPos(const std::vector& rawData, uint32_t rawDataIndex); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class SpecialActionEntry -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint16_t unused0; - uint32_t unused1; - uint32_t unused2; - uint32_t unused3; - uint32_t unused4; - uint32_t unused5; - uint32_t unused6; - uint32_t unused7; - uint32_t unused8; - uint32_t unused9; - uint32_t unused10; - - SpecialActionEntry(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommandSpecialAction : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandSpecialAction(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandSpecialAction(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class MusicFadeEntry -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint16_t unknown0; - uint32_t unknown1; - uint32_t unknown2; - uint32_t unknown3; - uint32_t unknown4; - uint32_t unknown5; - uint32_t unknown6; - uint32_t unknown7; - uint32_t unknown8; - uint32_t unknown9; - uint32_t unknown10; - - MusicFadeEntry(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommandFadeBGM : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandFadeBGM(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandFadeBGM(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class MusicChangeEntry -{ -public: - uint16_t sequence; - uint16_t startFrame; - uint16_t endFrame; - uint16_t unknown0; - uint32_t unknown1; - uint32_t unknown2; - uint32_t unknown3; - uint32_t unknown4; - uint32_t unknown5; - uint32_t unknown6; - uint32_t unknown7; - - MusicChangeEntry(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommandPlayBGM : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandPlayBGM(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandPlayBGM(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class CutsceneCommandStopBGM : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandStopBGM(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandStopBGM(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class EnvLightingEntry -{ -public: - uint16_t setting; - uint16_t startFrame; - uint16_t endFrame; - uint16_t unused0; - uint32_t unused1; - uint32_t unused2; - uint32_t unused3; - uint32_t unused4; - uint32_t unused5; - uint32_t unused6; - uint32_t unused7; - - EnvLightingEntry(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommandEnvLighting : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandEnvLighting(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandEnvLighting(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class CutsceneCommandSceneTransFX : public CutsceneCommand -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - ~CutsceneCommandSceneTransFX(); - CutsceneCommandSceneTransFX(const std::vector& rawData, uint32_t rawDataIndex); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class Unknown9Entry -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint16_t unk2; - uint16_t unk3; - uint16_t unk4; - uint8_t unused0; - uint8_t unused1; - - Unknown9Entry(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommandUnknown9 : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandUnknown9(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandUnknown9(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class UnkEntry -{ -public: - uint32_t unused0; - uint32_t unused1; - uint32_t unused2; - uint32_t unused3; - uint32_t unused4; - uint32_t unused5; - uint32_t unused6; - uint32_t unused7; - uint32_t unused8; - uint32_t unused9; - uint32_t unused10; - uint32_t unused11; - - UnkEntry(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommandUnknown : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandUnknown(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandUnknown(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class DayTimeEntry -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint8_t hour; - uint8_t minute; - uint8_t unused; - - DayTimeEntry(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommandDayTime : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandDayTime(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandDayTime(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class TextboxEntry -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint16_t type; - uint16_t textID1; - uint16_t textID2; - - TextboxEntry(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommandTextbox : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandTextbox(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandTextbox(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class ActorAction -{ -public: - uint16_t action; - uint16_t startFrame; - uint16_t endFrame; - int16_t rotX, rotY, rotZ; - int32_t startPosX, startPosY, startPosZ; - int32_t endPosX, endPosY, endPosZ; - float normalX, normalY, normalZ; - - ActorAction(const std::vector& rawData, uint32_t rawDataIndex); -}; - -class CutsceneCommandActorAction : public CutsceneCommand -{ -public: - std::vector entries; - - CutsceneCommandActorAction(const std::vector& rawData, uint32_t rawDataIndex); - ~CutsceneCommandActorAction(); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class CutsceneCommandTerminator : public CutsceneCommand -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint16_t unknown; - - CutsceneCommandTerminator(const std::vector& rawData, uint32_t rawDataIndex); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class CutsceneCommandEnd : public CutsceneCommand -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - - CutsceneCommandEnd(const std::vector& rawData, uint32_t rawDataIndex); - std::string GetCName(); - std::string GenerateSourceCode(uint32_t baseAddress); - size_t GetCommandSize(); -}; - -class CutsceneCommandNop : public CutsceneCommand -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - - CutsceneCommandNop(const std::vector& rawData, uint32_t rawDataIndex); - std::string GetCName(); - size_t GetCommandSize(); -}; - -class ZCutsceneBase : public ZResource -{ -public: - ZCutsceneBase(ZFile* nParent); - - Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override; - - std::string GetSourceTypeName() const override; -}; - -class ZCutscene : public ZCutsceneBase +class ZCutscene : public ZResource { public: ZCutscene(ZFile* nParent); @@ -426,15 +17,20 @@ public: void ParseRawData() override; + Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override; + std::string GetBodySourceCode() const override; size_t GetRawDataSize() const override; + std::string GetSourceTypeName() const override; ZResourceType GetResourceType() const override; - CutsceneCommands GetCommandFromID(int32_t id); - int32_t numCommands; int32_t endFrame; std::vector commands; + +protected: + CutsceneCommand* GetCommandOoT(uint32_t id, offset_t currentPtr) const; + CutsceneCommand* GetCommandMM(uint32_t id, offset_t currentPtr) const; }; diff --git a/tools/ZAPD/ZAPD/ZCutsceneMM.cpp b/tools/ZAPD/ZAPD/ZCutsceneMM.cpp deleted file mode 100644 index d0208bc070..0000000000 --- a/tools/ZAPD/ZAPD/ZCutsceneMM.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "ZCutsceneMM.h" - -#include "Utils/BitConverter.h" -#include "Utils/StringHelper.h" - -ZCutsceneMM::ZCutsceneMM(ZFile* nParent) : ZCutsceneBase(nParent) -{ -} - -ZCutsceneMM::~ZCutsceneMM() -{ - for (CutsceneCommand* cmd : commands) - delete cmd; -} - -std::string ZCutsceneMM::GetBodySourceCode() const -{ - std::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; -} - -size_t ZCutsceneMM::GetRawDataSize() const -{ - return 8 + data.size() * 4; -} - -void ZCutsceneMM::ParseRawData() -{ - const auto& rawData = parent->GetRawData(); - - numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0); - commands = std::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() const -{ - return ZResourceType::Cutscene; -} diff --git a/tools/ZAPD/ZAPD/ZCutsceneMM.h b/tools/ZAPD/ZAPD/ZCutsceneMM.h deleted file mode 100644 index 44b108d6c1..0000000000 --- a/tools/ZAPD/ZAPD/ZCutsceneMM.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include -#include -#include "ZCutscene.h" -#include "ZFile.h" -#include "tinyxml2.h" - -class ZCutsceneMM : public ZCutsceneBase -{ -public: - ZCutsceneMM(ZFile* nParent); - virtual ~ZCutsceneMM(); - - std::string GetBodySourceCode() const override; - - size_t GetRawDataSize() const override; - - void ParseRawData() override; - ZResourceType GetResourceType() const override; - -protected: - int32_t numCommands; - int32_t endFrame; - std::vector commands; - - std::vector data; -}; diff --git a/tools/ZAPD/ZAPD/ZFile.cpp b/tools/ZAPD/ZAPD/ZFile.cpp index 22a6a45058..b81399e2a4 100644 --- a/tools/ZAPD/ZAPD/ZFile.cpp +++ b/tools/ZAPD/ZAPD/ZFile.cpp @@ -406,7 +406,7 @@ void ZFile::AddResource(ZResource* res) resources.push_back(res); } -ZResource* ZFile::FindResource(uint32_t rawDataIndex) +ZResource* ZFile::FindResource(offset_t rawDataIndex) { for (ZResource* res : resources) { @@ -695,7 +695,7 @@ bool ZFile::GetDeclarationArrayIndexedName(segptr_t segAddress, size_t elementSi return true; } -Declaration* ZFile::GetDeclaration(uint32_t address) const +Declaration* ZFile::GetDeclaration(offset_t address) const { if (declarations.find(address) != declarations.end()) return declarations.at(address); @@ -703,7 +703,7 @@ Declaration* ZFile::GetDeclaration(uint32_t address) const return nullptr; } -Declaration* ZFile::GetDeclarationRanged(uint32_t address) const +Declaration* ZFile::GetDeclarationRanged(offset_t address) const { for (const auto decl : declarations) { @@ -714,7 +714,7 @@ Declaration* ZFile::GetDeclarationRanged(uint32_t address) const return nullptr; } -bool ZFile::HasDeclaration(uint32_t address) +bool ZFile::HasDeclaration(offset_t address) { assert(GETSEGNUM(address) == 0); return declarations.find(address) != declarations.end(); @@ -776,6 +776,11 @@ void ZFile::GenerateSourceHeaderFiles() { OutputFormatter formatter; + std::string objectNameUpper = StringHelper::ToUpper(GetName()); + + formatter.Write(StringHelper::Sprintf("#ifndef %s_H\n#define %s_H 1\n\n", + objectNameUpper.c_str(), objectNameUpper.c_str())); + for (ZResource* res : resources) { std::string resSrc = res->GetSourceOutputHeader(""); @@ -792,6 +797,8 @@ void ZFile::GenerateSourceHeaderFiles() formatter.Write(ProcessExterns()); + formatter.Write("#endif\n"); + fs::path headerFilename = GetSourceOutputFolderPath() / outName.stem().concat(".h"); if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO) diff --git a/tools/ZAPD/ZAPD/ZFile.h b/tools/ZAPD/ZAPD/ZFile.h index ac4062d5b1..275e27f1b3 100644 --- a/tools/ZAPD/ZAPD/ZFile.h +++ b/tools/ZAPD/ZAPD/ZFile.h @@ -52,7 +52,7 @@ public: void ExtractResources(); void BuildSourceFile(); void AddResource(ZResource* res); - ZResource* FindResource(uint32_t rawDataIndex); + ZResource* FindResource(offset_t rawDataIndex); std::vector GetResourcesOfType(ZResourceType resType); Declaration* AddDeclaration(offset_t address, DeclarationAlignment alignment, size_t size, @@ -81,9 +81,9 @@ public: const std::string& expectedType, std::string& declName) const; - Declaration* GetDeclaration(uint32_t address) const; - Declaration* GetDeclarationRanged(uint32_t address) const; - bool HasDeclaration(uint32_t address); + Declaration* GetDeclaration(offset_t address) const; + Declaration* GetDeclarationRanged(offset_t address) const; + bool HasDeclaration(offset_t address); std::string GetHeaderInclude() const; std::string GetZRoomHeaderInclude() const; diff --git a/tools/ZAPD/ZAPD/ZLimb.cpp b/tools/ZAPD/ZAPD/ZLimb.cpp index 330fbaf7ce..034d0850bb 100644 --- a/tools/ZAPD/ZAPD/ZLimb.cpp +++ b/tools/ZAPD/ZAPD/ZLimb.cpp @@ -4,12 +4,15 @@ #include "Globals.h" #include "Utils/BitConverter.h" +#include "Utils/StringHelper.h" #include "WarningHandler.h" +#include "ZSkeleton.h" REGISTER_ZFILENODE(Limb, ZLimb); ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent), segmentStruct(nParent) { + RegisterOptionalAttribute("EnumName"); RegisterOptionalAttribute("LimbType"); RegisterOptionalAttribute("Type"); } @@ -30,6 +33,12 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader) { ZResource::ParseXML(reader); + auto& enumNameXml = registeredAttributes.at("EnumName").value; + if (enumNameXml != "") + { + enumName = enumNameXml; + } + // Reading from a std::string limbType = registeredAttributes.at("LimbType").value; if (limbType == "") // Reading from a @@ -240,11 +249,24 @@ std::string ZLimb::GetBodySourceCode() const } else { + std::string childStr; + std::string siblingStr; + if (limbsTable != nullptr) + { + childStr = limbsTable->GetLimbEnumName(childIndex); + siblingStr = limbsTable->GetLimbEnumName(siblingIndex); + } + else + { + childStr = StringHelper::Sprintf("0x%02X", childIndex); + siblingStr = StringHelper::Sprintf("0x%02X", siblingIndex); + } + if (type != ZLimbType::Curve) { entryStr += StringHelper::Sprintf("{ %i, %i, %i }, ", transX, transY, transZ); } - entryStr += StringHelper::Sprintf("0x%02X, 0x%02X,\n", childIndex, siblingIndex); + entryStr += StringHelper::Sprintf("%s, %s,\n", childStr.c_str(), siblingStr.c_str()); switch (type) { @@ -352,6 +374,11 @@ ZLimbType ZLimb::GetTypeByAttributeName(const std::string& attrName) return ZLimbType::Invalid; } +void ZLimb::SetLimbIndex(uint8_t nLimbIndex) +{ + limbIndex = nLimbIndex; +} + void ZLimb::DeclareDList(segptr_t dListSegmentedPtr, const std::string& prefix, const std::string& limbSuffix) { diff --git a/tools/ZAPD/ZAPD/ZLimb.h b/tools/ZAPD/ZAPD/ZLimb.h index 53a4143292..ce31e42958 100644 --- a/tools/ZAPD/ZAPD/ZLimb.h +++ b/tools/ZAPD/ZAPD/ZLimb.h @@ -18,9 +18,14 @@ enum class ZLimbType Legacy, }; +class ZLimbTable; + class ZLimb : public ZResource { public: + std::string enumName; + ZLimbTable* limbsTable = nullptr; // borrowed pointer, do not delete! + ZLimbType type = ZLimbType::Standard; ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only @@ -39,6 +44,8 @@ public: int16_t transX, transY, transZ; uint8_t childIndex, siblingIndex; + uint8_t limbIndex = 0; + ZLimb(ZFile* nParent); void ExtractFromBinary(uint32_t nRawDataIndex, ZLimbType nType); @@ -59,6 +66,8 @@ public: static const char* GetSourceTypeName(ZLimbType limbType); static ZLimbType GetTypeByAttributeName(const std::string& attrName); + void SetLimbIndex(uint8_t nLimbIndex); + protected: void DeclareDList(segptr_t dListSegmentedPtr, const std::string& prefix, const std::string& limbSuffix); diff --git a/tools/ZAPD/ZAPD/ZResource.cpp b/tools/ZAPD/ZAPD/ZResource.cpp index 2dfe6d5eaa..8825cc97bd 100644 --- a/tools/ZAPD/ZAPD/ZResource.cpp +++ b/tools/ZAPD/ZAPD/ZResource.cpp @@ -247,6 +247,11 @@ offset_t ZResource::GetRawDataIndex() const return rawDataIndex; } +void ZResource::SetRawDataIndex(offset_t nRawDataIndex) +{ + rawDataIndex = nRawDataIndex; +} + std::string ZResource::GetBodySourceCode() const { return "ERROR"; diff --git a/tools/ZAPD/ZAPD/ZResource.h b/tools/ZAPD/ZAPD/ZResource.h index c65c3c31b4..35984679c7 100644 --- a/tools/ZAPD/ZAPD/ZResource.h +++ b/tools/ZAPD/ZAPD/ZResource.h @@ -31,6 +31,7 @@ enum class ZResourceType Background, Blob, CollisionHeader, + CollisionPoly, Cutscene, DisplayList, Limb, @@ -150,6 +151,8 @@ public: [[nodiscard]] const std::string& GetOutName() const; void SetOutName(const std::string& nName); [[nodiscard]] offset_t GetRawDataIndex() const; + void SetRawDataIndex(offset_t nRawDataIndex); + /** * The size of the current struct being extracted, not counting data referenced by it */ diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp index e51e550b09..3820203ef8 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp @@ -10,53 +10,65 @@ SetCutscenes::SetCutscenes(ZFile* nParent) : ZRoomCommand(nParent) { } -SetCutscenes::~SetCutscenes() -{ - for (ZCutsceneBase* cutscene : cutscenes) - delete cutscene; -} - void SetCutscenes::ParseRawData() { ZRoomCommand::ParseRawData(); - std::string output; numCutscenes = cmdArg1; - if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97) - { - ZCutscene* cutscene = new ZCutscene(parent); - cutscene->ExtractFromFile(segmentOffset); - auto decl = parent->GetDeclaration(segmentOffset); - if (decl == nullptr) - { - cutscene->DeclareVar(zRoom->GetName().c_str(), ""); - } - - cutscenes.push_back(cutscene); - } - else + if (Globals::Instance->game == ZGame::MM_RETAIL) { int32_t currentPtr = segmentOffset; - std::string declaration; for (uint8_t i = 0; i < numCutscenes; i++) { CutsceneEntry entry(parent->GetRawData(), currentPtr); cutsceneEntries.push_back(entry); currentPtr += 8; + } + } +} - // TODO: don't hardcode %sCutsceneData_%06X, look up for the declared name instead - declaration += StringHelper::Sprintf( - " { %sCutsceneData_%06X, 0x%04X, 0x%02X, 0x%02X },", zRoom->GetName().c_str(), - entry.segmentOffset, entry.exit, entry.entrance, entry.flag); +void SetCutscenes::DeclareReferences(const std::string& prefix) +{ + std::string varPrefix = name; + if (varPrefix == "") + varPrefix = prefix; - if (i < numCutscenes - 1) + if (Globals::Instance->game == ZGame::MM_RETAIL) + { + std::string declaration; + size_t i = 0; + + for (const auto& entry : cutsceneEntries) + { + if (entry.segmentPtr != SEGMENTED_NULL && + GETSEGNUM(entry.segmentPtr) == parent->segment) + { + offset_t csOffset = Seg2Filespace(entry.segmentPtr, parent->baseAddress); + if (!parent->HasDeclaration(csOffset)) + { + auto* cutscene = new ZCutscene(parent); + cutscene->ExtractFromFile(csOffset); + cutscene->SetName(cutscene->GetDefaultName(varPrefix)); + cutscene->DeclareVar(varPrefix, ""); + cutscene->DeclareReferences(varPrefix); + parent->AddResource(cutscene); + } + } + + std::string csName; + Globals::Instance->GetSegmentedPtrName(entry.segmentPtr, parent, "CutsceneData", + csName); + + declaration += + StringHelper::Sprintf(" { %s, 0x%04X, 0x%02X, 0x%02X },", csName.c_str(), + entry.exit, entry.entrance, entry.flag); + + if (i + 1 < numCutscenes) declaration += "\n"; - ZCutsceneMM* cutscene = new ZCutsceneMM(parent); - cutscene->ExtractFromFile(entry.segmentOffset); - cutscenes.push_back(cutscene); + i++; } parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, @@ -65,19 +77,19 @@ void SetCutscenes::ParseRawData() zRoom->GetName().c_str(), segmentOffset), cutsceneEntries.size(), declaration); } - - for (ZCutsceneBase* cutscene : cutscenes) + else { - if (cutscene->GetRawDataIndex() != 0) + if (cmdArg2 != SEGMENTED_NULL && GETSEGNUM(cmdArg2) == parent->segment) { - Declaration* decl = parent->GetDeclaration(cutscene->GetRawDataIndex()); - if (decl == nullptr) + offset_t csOffset = Seg2Filespace(cmdArg2, parent->baseAddress); + if (!parent->HasDeclaration(csOffset)) { - cutscene->GetSourceOutputCode(zRoom->GetName()); - } - else if (decl->text == "") - { - decl->text = cutscene->GetBodySourceCode(); + auto* cutscene = new ZCutscene(parent); + cutscene->ExtractFromFile(csOffset); + cutscene->SetName(cutscene->GetDefaultName(varPrefix)); + cutscene->DeclareVar(varPrefix, ""); + cutscene->DeclareReferences(varPrefix); + parent->AddResource(cutscene); } } } @@ -86,11 +98,15 @@ void SetCutscenes::ParseRawData() std::string SetCutscenes::GetBodySourceCode() const { std::string listName; - Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneData", listName); if (Globals::Instance->game == ZGame::MM_RETAIL) + { + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneEntry", listName); return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_LIST(%i, %s)", numCutscenes, listName.c_str()); + } + + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneData", listName); return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_DATA(%s)", listName.c_str()); } @@ -105,7 +121,7 @@ RoomCommand SetCutscenes::GetRoomCommand() const } CutsceneEntry::CutsceneEntry(const std::vector& rawData, uint32_t rawDataIndex) - : segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 0))), + : segmentPtr(BitConverter::ToInt32BE(rawData, rawDataIndex + 0)), 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 ad032bbe6a..81a622c5b3 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h @@ -1,7 +1,6 @@ #pragma once #include "ZCutscene.h" -#include "ZCutsceneMM.h" #include "ZRoom/ZRoomCommand.h" class CutsceneEntry @@ -9,7 +8,7 @@ class CutsceneEntry public: CutsceneEntry(const std::vector& rawData, uint32_t rawDataIndex); - uint32_t segmentOffset; + segptr_t segmentPtr; uint16_t exit; uint8_t entrance; uint8_t flag; @@ -18,14 +17,13 @@ public: class SetCutscenes : public ZRoomCommand { public: - std::vector cutscenes; std::vector cutsceneEntries; // (MM Only) uint8_t numCutscenes; // (MM Only) SetCutscenes(ZFile* nParent); - ~SetCutscenes(); void ParseRawData() override; + void DeclareReferences(const std::string& prefix) override; std::string GetBodySourceCode() const override; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp index 7027fa1f98..20138dd4d7 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetRoomList.cpp @@ -104,9 +104,8 @@ std::string RomFile::GetBodySourceCode() const if (!isFirst) declaration += "\n"; - declaration += - StringHelper::Sprintf("\t{ (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },", - roomName.c_str(), roomName.c_str()); + declaration += StringHelper::Sprintf("\t{ _%sSegmentRomStart, _%sSegmentRomEnd },", + roomName.c_str(), roomName.c_str()); isFirst = false; } } diff --git a/tools/ZAPD/ZAPD/ZSkeleton.cpp b/tools/ZAPD/ZAPD/ZSkeleton.cpp index 4467c96320..b3f7ce8c01 100644 --- a/tools/ZAPD/ZAPD/ZSkeleton.cpp +++ b/tools/ZAPD/ZAPD/ZSkeleton.cpp @@ -10,10 +10,13 @@ REGISTER_ZFILENODE(Skeleton, ZSkeleton); REGISTER_ZFILENODE(LimbTable, ZLimbTable); -ZSkeleton::ZSkeleton(ZFile* nParent) : ZResource(nParent), limbsTable(nParent) +ZSkeleton::ZSkeleton(ZFile* nParent) : ZResource(nParent) { RegisterRequiredAttribute("Type"); RegisterRequiredAttribute("LimbType"); + RegisterOptionalAttribute("EnumName"); + RegisterOptionalAttribute("LimbNone"); + RegisterOptionalAttribute("LimbMax"); } void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) @@ -42,6 +45,41 @@ void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader) limbTypeXml.c_str()), "Defaulting to 'Standard'."); } + + enumName = registeredAttributes.at("EnumName").value; + limbNoneName = registeredAttributes.at("LimbNone").value; + limbMaxName = registeredAttributes.at("LimbMax").value; + + if (enumName != "") + { + if (limbNoneName == "" || limbMaxName == "") + { + HANDLE_ERROR_RESOURCE(WarningType::MissingAttribute, parent, this, rawDataIndex, + "'EnumName' attribute was used but either 'LimbNone' or " + "'LimbMax' attribute is missing", + ""); + } + } + + if (limbNoneName != "") + { + if (limbMaxName == "") + { + HANDLE_ERROR_RESOURCE( + WarningType::MissingAttribute, parent, this, rawDataIndex, + "'LimbNone' attribute was used but 'LimbMax' attribute is missing", ""); + } + } + + if (limbMaxName != "") + { + if (limbNoneName == "") + { + HANDLE_ERROR_RESOURCE( + WarningType::MissingAttribute, parent, this, rawDataIndex, + "'LimbMax' attribute was used but 'LimbNone' attribute is missing", ""); + } + } } void ZSkeleton::ParseRawData() @@ -56,12 +94,6 @@ void ZSkeleton::ParseRawData() { dListCount = BitConverter::ToUInt8BE(rawData, rawDataIndex + 8); } - - if (limbsArrayAddress != 0 && GETSEGNUM(limbsArrayAddress) == parent->segment) - { - uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress); - limbsTable.ExtractFromBinary(ptr, limbType, limbCount); - } } void ZSkeleton::DeclareReferences(const std::string& prefix) @@ -72,14 +104,33 @@ void ZSkeleton::DeclareReferences(const std::string& prefix) ZResource::DeclareReferences(defaultPrefix); - if (limbsArrayAddress != 0 && GETSEGNUM(limbsArrayAddress) == parent->segment) + if (limbsArrayAddress != SEGMENTED_NULL && GETSEGNUM(limbsArrayAddress) == parent->segment) { - uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress); + offset_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress); + if (!parent->HasDeclaration(ptr)) { - limbsTable.SetName(StringHelper::Sprintf("%sLimbs", defaultPrefix.c_str())); - limbsTable.DeclareReferences(prefix); - limbsTable.GetSourceOutputCode(prefix); + limbsTable = new ZLimbTable(parent); + limbsTable->ExtractFromBinary(ptr, limbType, limbCount); + limbsTable->SetName(StringHelper::Sprintf("%sLimbs", defaultPrefix.c_str())); + parent->AddResource(limbsTable); + } + else + { + limbsTable = static_cast(parent->FindResource(ptr)); + } + + if (limbsTable->enumName == "") + { + limbsTable->enumName = enumName; + } + if (limbsTable->limbNoneName == "") + { + limbsTable->limbNoneName = limbNoneName; + } + if (limbsTable->limbMaxName == "") + { + limbsTable->limbMaxName = limbMaxName; } } } @@ -89,15 +140,27 @@ std::string ZSkeleton::GetBodySourceCode() const std::string limbArrayName; Globals::Instance->GetSegmentedPtrName(limbsArrayAddress, parent, "", limbArrayName); + std::string countStr; + assert(limbsTable != nullptr); + // There are some Skeletons with the wrong limb count on them, so this check is necessary. + if (limbsTable->count == limbCount) + { + countStr = StringHelper::Sprintf("ARRAY_COUNT(%s)", limbArrayName.c_str()); + } + else + { + countStr = StringHelper::Sprintf("%i", limbCount); + } + switch (type) { case ZSkeletonType::Normal: case ZSkeletonType::Curve: - return StringHelper::Sprintf("\n\t%s, %i\n", limbArrayName.c_str(), limbCount); + return StringHelper::Sprintf("\n\t%s, %s\n", limbArrayName.c_str(), countStr.c_str()); case ZSkeletonType::Flex: - return StringHelper::Sprintf("\n\t{ %s, %i }, %i\n", limbArrayName.c_str(), limbCount, - dListCount); + return StringHelper::Sprintf("\n\t{ %s, %s }, %i\n", limbArrayName.c_str(), + countStr.c_str(), dListCount); } // TODO: Throw exception? @@ -153,6 +216,9 @@ ZLimbTable::ZLimbTable(ZFile* nParent) : ZResource(nParent) { RegisterRequiredAttribute("LimbType"); RegisterRequiredAttribute("Count"); + RegisterOptionalAttribute("EnumName"); + RegisterOptionalAttribute("LimbNone"); + RegisterOptionalAttribute("LimbMax"); } void ZLimbTable::ExtractFromBinary(uint32_t nRawDataIndex, ZLimbType nLimbType, size_t nCount) @@ -179,6 +245,40 @@ void ZLimbTable::ParseXML(tinyxml2::XMLElement* reader) } count = StringHelper::StrToL(registeredAttributes.at("Count").value); + + enumName = registeredAttributes.at("EnumName").value; + limbNoneName = registeredAttributes.at("LimbNone").value; + limbMaxName = registeredAttributes.at("LimbMax").value; + + if (enumName != "") + { + if (limbNoneName == "" || limbMaxName == "") + { + HANDLE_ERROR_RESOURCE( + WarningType::MissingAttribute, parent, this, rawDataIndex, + "'EnumName' attribute was used but 'LimbNone'/'LimbMax' attributes is missing", ""); + } + } + + if (limbNoneName != "") + { + if (limbMaxName == "") + { + HANDLE_ERROR_RESOURCE( + WarningType::MissingAttribute, parent, this, rawDataIndex, + "'LimbNone' attribute was used but 'LimbMax' attribute is missing", ""); + } + } + + if (limbMaxName != "") + { + if (limbNoneName == "") + { + HANDLE_ERROR_RESOURCE( + WarningType::MissingAttribute, parent, this, rawDataIndex, + "'LimbMax' attribute was used but 'LimbNone' attribute is missing", ""); + } + } } void ZLimbTable::ParseRawData() @@ -209,15 +309,28 @@ void ZLimbTable::DeclareReferences(const std::string& prefix) if (limbAddress != 0 && GETSEGNUM(limbAddress) == parent->segment) { uint32_t limbOffset = Seg2Filespace(limbAddress, parent->baseAddress); + ZLimb* limb; + if (!parent->HasDeclaration(limbOffset)) { - ZLimb* limb = new ZLimb(parent); + limb = new ZLimb(parent); limb->ExtractFromBinary(limbOffset, limbType); limb->SetName(limb->GetDefaultName(varPrefix)); limb->DeclareVar(varPrefix, ""); limb->DeclareReferences(varPrefix); parent->AddResource(limb); } + else + { + limb = static_cast(parent->FindResource(limbOffset)); + assert(limb != nullptr); + assert(limb->GetResourceType() == ZResourceType::Limb); + } + + limb->limbsTable = this; + limb->SetLimbIndex(i + 1); + + limbsReferences.push_back(limb); } } } @@ -246,6 +359,13 @@ std::string ZLimbTable::GetBodySourceCode() const Globals::Instance->GetSegmentedPtrName(limbsAddresses[i], parent, "", limbName); body += StringHelper::Sprintf("\t%s,", limbName.c_str()); + auto& limb = limbsReferences.at(i); + std::string limbEnumName = limb->enumName; + if (limbEnumName != "") + { + body += StringHelper::Sprintf(" /* %s */", limbEnumName.c_str()); + } + if (i + 1 < count) body += "\n"; } @@ -253,6 +373,46 @@ std::string ZLimbTable::GetBodySourceCode() const return body; } +std::string ZLimbTable::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix) +{ + if (limbNoneName == "" || limbMaxName == "" || enumName == "") + { + // Don't produce a enum of any of those attributes is missing + return ""; + } + + std::string limbEnum = StringHelper::Sprintf("typedef enum %s {\n", enumName.c_str()); + + // This assumes there isn't any skeleton with more than 0x100 limbs + + limbEnum += StringHelper::Sprintf(" /* 0x00 */ %s,\n", limbNoneName.c_str()); + + size_t i = 0; + for (; i < count; i++) + { + auto& limb = limbsReferences.at(i); + std::string limbEnumName = limb->enumName; + + if (limbEnumName == "") + { + HANDLE_ERROR_RESOURCE( + WarningType::MissingAttribute, parent, this, rawDataIndex, + "Skeleton's enum attributes were used but at least one limb is missing its " + "'LimbName' attribute", + StringHelper::Sprintf("When processing limb %02i, named '%s' at offset '0x%X'", + i + 1, limb->GetName().c_str(), limb->GetRawDataIndex())); + } + + limbEnum += StringHelper::Sprintf(" /* 0x%02X */ %s,\n", i + 1, limbEnumName.c_str()); + } + + limbEnum += StringHelper::Sprintf(" /* 0x%02X */ %s\n", i + 1, limbMaxName.c_str()); + + limbEnum += StringHelper::Sprintf("} %s;\n", enumName.c_str()); + + return limbEnum; +} + std::string ZLimbTable::GetSourceTypeName() const { switch (limbType) @@ -283,3 +443,28 @@ size_t ZLimbTable::GetRawDataSize() const { return 4 * limbsAddresses.size(); } + +std::string ZLimbTable::GetLimbEnumName(uint8_t limbIndex) const +{ + if (limbIndex == 0xFF) + { + return "LIMB_DONE"; + } + + if (limbIndex < count) + { + std::string limbEnumName = limbsReferences.at(limbIndex)->enumName; + if (limbEnumName != "") + { + return StringHelper::Sprintf("%s - 1", limbEnumName.c_str()); + } + } + else + { + HANDLE_WARNING_RESOURCE(WarningType::InvalidExtractedData, parent, this, rawDataIndex, + StringHelper::Sprintf("Limb index '%02i' out of range", limbIndex), + ""); + } + + return StringHelper::Sprintf("0x%02X", limbIndex); +} diff --git a/tools/ZAPD/ZAPD/ZSkeleton.h b/tools/ZAPD/ZAPD/ZSkeleton.h index ed003ceafd..c437a8484c 100644 --- a/tools/ZAPD/ZAPD/ZSkeleton.h +++ b/tools/ZAPD/ZAPD/ZSkeleton.h @@ -18,6 +18,17 @@ enum class ZSkeletonType class ZLimbTable : public ZResource { public: + ZLimbType limbType = ZLimbType::Standard; + size_t count = 0; + + std::vector limbsAddresses; + std::vector limbsReferences; // borrowed pointers, do not delete! + + // XML attributes + std::string enumName; + std::string limbNoneName; + std::string limbMaxName; + ZLimbTable(ZFile* nParent); void ExtractFromBinary(uint32_t nRawDataIndex, ZLimbType nLimbType, size_t nCount); @@ -30,16 +41,14 @@ public: std::string GetBodySourceCode() const override; + std::string GetSourceOutputHeader(const std::string& prefix) override; + std::string GetSourceTypeName() const override; ZResourceType GetResourceType() const override; size_t GetRawDataSize() const override; -protected: - ZLimbType limbType = ZLimbType::Standard; - size_t count = 0; - - std::vector limbsAddresses; + std::string GetLimbEnumName(uint8_t limbIndex) const; }; class ZSkeleton : public ZResource @@ -47,6 +56,10 @@ class ZSkeleton : public ZResource public: ZSkeletonType type = ZSkeletonType::Normal; ZLimbType limbType = ZLimbType::Standard; + std::string enumName; + std::string limbNoneName; + std::string limbMaxName; + segptr_t limbsArrayAddress; uint8_t limbCount = 0; uint8_t dListCount = 0; // FLEX SKELETON ONLY @@ -68,5 +81,5 @@ public: uint8_t GetLimbCount(); protected: - ZLimbTable limbsTable; + ZLimbTable* limbsTable = nullptr; // borrowed pointer, do not delete! }; diff --git a/tools/ZAPD/ZAPD/ZTexture.cpp b/tools/ZAPD/ZAPD/ZTexture.cpp index 255d30886e..74b7c7d106 100644 --- a/tools/ZAPD/ZAPD/ZTexture.cpp +++ b/tools/ZAPD/ZAPD/ZTexture.cpp @@ -17,11 +17,15 @@ ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent) width = 0; height = 0; dWordAligned = true; + splitTlut = false; RegisterRequiredAttribute("Width"); RegisterRequiredAttribute("Height"); RegisterRequiredAttribute("Format"); RegisterOptionalAttribute("TlutOffset"); + RegisterOptionalAttribute("ExternalTlut"); + RegisterOptionalAttribute("ExternalTlutOffset"); + RegisterOptionalAttribute("SplitTlut"); } void ZTexture::ExtractFromBinary(uint32_t nRawDataIndex, int32_t nWidth, int32_t nHeight, @@ -56,6 +60,7 @@ void ZTexture::ParseXML(tinyxml2::XMLElement* reader) std::string widthXml = registeredAttributes.at("Width").value; std::string heightXml = registeredAttributes.at("Height").value; + std::string SplitTlutXml = registeredAttributes.at("SplitTlut").value; if (!StringHelper::HasOnlyDigits(widthXml)) { @@ -72,6 +77,27 @@ void ZTexture::ParseXML(tinyxml2::XMLElement* reader) errorHeader, ""); } + if (!registeredAttributes.at("ExternalTlut").wasSet && + registeredAttributes.at("SplitTlut").wasSet) + { + std::string errorHeader = + StringHelper::Sprintf("SplitTlut set without using an external tlut"); + HANDLE_WARNING_RESOURCE(WarningType::InvalidAttributeValue, parent, this, rawDataIndex, + errorHeader, ""); + } + + if (!SplitTlutXml.empty()) + { + if (!tinyxml2::XMLUtil::ToBool(SplitTlutXml.c_str(), &splitTlut)) + { + std::string errorHeader = StringHelper::Sprintf( + "Invalid value passed to SplitTlut: '%s'. Valid values are true, false, 1, 0", + SplitTlutXml.c_str()); + HANDLE_ERROR_RESOURCE(WarningType::InvalidAttributeValue, parent, this, rawDataIndex, + errorHeader, ""); + } + } + width = StringHelper::StrToL(widthXml); height = StringHelper::StrToL(heightXml); @@ -145,6 +171,47 @@ void ZTexture::ParseRawData() } } +void ZTexture::ParseRawDataLate() +{ + if (registeredAttributes["ExternalTlut"].wasSet) + { + const std::string externPalette = registeredAttributes["ExternalTlut"].value; + for (const auto& file : Globals::Instance->files) + { + if (file->GetName() == externPalette) + { + offset_t palOffset = 0; + if (registeredAttributes["ExternalTlutOffset"].wasSet) + { + palOffset = + StringHelper::StrToL(registeredAttributes["ExternalTlutOffset"].value, 16); + } + else + { + HANDLE_WARNING_RESOURCE( + WarningType::MissingOffsets, parent, this, rawDataIndex, + StringHelper::Sprintf( + "No ExternalTlutOffset Given. Assuming offset of 0x0"), + ""); + } + for (const auto& res : file->resources) + { + if (res->GetRawDataIndex() == palOffset) + { + ZTexture* palette = (ZTexture*)res; + ZTexture tlutTemp(file); + + tlut = &tlutTemp; + tlut->ExtractFromBinary(palOffset, palette->width, palette->height, + TextureType::RGBA16bpp, true); + SetTlut(tlut); + } + } + } + } + } +} + void ZTexture::PrepareBitmapRGBA16() { textureData.InitEmptyRGBImage(width, height, true); @@ -350,34 +417,42 @@ void ZTexture::DeclareReferences([[maybe_unused]] const std::string& prefix) void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath) { + textureData.ReadPng(pngFilePath); + + width = textureData.GetWidth(); + height = textureData.GetHeight(); + + textureDataRaw.clear(); + textureDataRaw.resize(ALIGN8(GetRawDataSize())); + switch (format) { case TextureType::RGBA16bpp: - PrepareRawDataRGBA16(pngFilePath); + PrepareRawDataRGBA16(); break; case TextureType::RGBA32bpp: - PrepareRawDataRGBA32(pngFilePath); + PrepareRawDataRGBA32(); break; case TextureType::Grayscale4bpp: - PrepareRawDataGrayscale4(pngFilePath); + PrepareRawDataGrayscale4(); break; case TextureType::Grayscale8bpp: - PrepareRawDataGrayscale8(pngFilePath); + PrepareRawDataGrayscale8(); break; case TextureType::GrayscaleAlpha4bpp: - PrepareRawDataGrayscaleAlpha4(pngFilePath); + PrepareRawDataGrayscaleAlpha4(); break; case TextureType::GrayscaleAlpha8bpp: - PrepareRawDataGrayscaleAlpha8(pngFilePath); + PrepareRawDataGrayscaleAlpha8(); break; case TextureType::GrayscaleAlpha16bpp: - PrepareRawDataGrayscaleAlpha16(pngFilePath); + PrepareRawDataGrayscaleAlpha16(); break; case TextureType::Palette4bpp: - PrepareRawDataPalette4(pngFilePath); + PrepareRawDataPalette4(); break; case TextureType::Palette8bpp: - PrepareRawDataPalette8(pngFilePath); + PrepareRawDataPalette8(); break; case TextureType::Error: HANDLE_ERROR_PROCESS(WarningType::InvalidPNG, "Input PNG file has invalid format type", ""); @@ -385,15 +460,8 @@ void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath) } } -void ZTexture::PrepareRawDataRGBA16(const fs::path& rgbaPath) +void ZTexture::PrepareRawDataRGBA16() { - textureData.ReadPng(rgbaPath); - - width = textureData.GetWidth(); - height = textureData.GetHeight(); - - textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x++) @@ -415,15 +483,8 @@ void ZTexture::PrepareRawDataRGBA16(const fs::path& rgbaPath) } } -void ZTexture::PrepareRawDataRGBA32(const fs::path& rgbaPath) +void ZTexture::PrepareRawDataRGBA32() { - textureData.ReadPng(rgbaPath); - - width = textureData.GetWidth(); - height = textureData.GetHeight(); - - textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x++) @@ -439,15 +500,8 @@ void ZTexture::PrepareRawDataRGBA32(const fs::path& rgbaPath) } } -void ZTexture::PrepareRawDataGrayscale4(const fs::path& grayPath) +void ZTexture::PrepareRawDataGrayscale4() { - textureData.ReadPng(grayPath); - - width = textureData.GetWidth(); - height = textureData.GetHeight(); - - textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x += 2) @@ -461,15 +515,8 @@ void ZTexture::PrepareRawDataGrayscale4(const fs::path& grayPath) } } -void ZTexture::PrepareRawDataGrayscale8(const fs::path& grayPath) +void ZTexture::PrepareRawDataGrayscale8() { - textureData.ReadPng(grayPath); - - width = textureData.GetWidth(); - height = textureData.GetHeight(); - - textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x++) @@ -481,15 +528,8 @@ void ZTexture::PrepareRawDataGrayscale8(const fs::path& grayPath) } } -void ZTexture::PrepareRawDataGrayscaleAlpha4(const fs::path& grayAlphaPath) +void ZTexture::PrepareRawDataGrayscaleAlpha4() { - textureData.ReadPng(grayAlphaPath); - - width = textureData.GetWidth(); - height = textureData.GetHeight(); - - textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x += 2) @@ -514,15 +554,8 @@ void ZTexture::PrepareRawDataGrayscaleAlpha4(const fs::path& grayAlphaPath) } } -void ZTexture::PrepareRawDataGrayscaleAlpha8(const fs::path& grayAlphaPath) +void ZTexture::PrepareRawDataGrayscaleAlpha8() { - textureData.ReadPng(grayAlphaPath); - - width = textureData.GetWidth(); - height = textureData.GetHeight(); - - textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x++) @@ -538,15 +571,8 @@ void ZTexture::PrepareRawDataGrayscaleAlpha8(const fs::path& grayAlphaPath) } } -void ZTexture::PrepareRawDataGrayscaleAlpha16(const fs::path& grayAlphaPath) +void ZTexture::PrepareRawDataGrayscaleAlpha16() { - textureData.ReadPng(grayAlphaPath); - - width = textureData.GetWidth(); - height = textureData.GetHeight(); - - textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x++) @@ -563,15 +589,8 @@ void ZTexture::PrepareRawDataGrayscaleAlpha16(const fs::path& grayAlphaPath) } } -void ZTexture::PrepareRawDataPalette4(const fs::path& palPath) +void ZTexture::PrepareRawDataPalette4() { - textureData.ReadPng(palPath); - - width = textureData.GetWidth(); - height = textureData.GetHeight(); - - textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x += 2) @@ -586,15 +605,8 @@ void ZTexture::PrepareRawDataPalette4(const fs::path& palPath) } } -void ZTexture::PrepareRawDataPalette8(const fs::path& palPath) +void ZTexture::PrepareRawDataPalette8() { - textureData.ReadPng(palPath); - - width = textureData.GetWidth(); - height = textureData.GetHeight(); - - textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); for (uint16_t y = 0; y < height; y++) { for (uint16_t x = 0; x < width; x++) @@ -926,7 +938,7 @@ void ZTexture::SetTlut(ZTexture* nTlut) assert(nTlut->isPalette); tlut = nTlut; - textureData.SetPalette(tlut->textureData); + textureData.SetPalette(tlut->textureData, splitTlut ? 128 : 0); } bool ZTexture::HasTlut() const diff --git a/tools/ZAPD/ZAPD/ZTexture.h b/tools/ZAPD/ZAPD/ZTexture.h index 29c3fbc0a1..8cece3ff24 100644 --- a/tools/ZAPD/ZAPD/ZTexture.h +++ b/tools/ZAPD/ZAPD/ZTexture.h @@ -28,6 +28,7 @@ protected: std::vector textureDataRaw; // When reading from a PNG file. uint32_t tlutOffset = static_cast(-1); ZTexture* tlut = nullptr; + bool splitTlut; void PrepareBitmapRGBA16(); void PrepareBitmapRGBA32(); @@ -40,15 +41,15 @@ protected: void PrepareBitmapPalette8(); void PrepareRawDataFromFile(const fs::path& inFolder); - void PrepareRawDataRGBA16(const fs::path& rgbaPath); - void PrepareRawDataRGBA32(const fs::path& rgbaPath); - void PrepareRawDataGrayscale4(const fs::path& grayPath); - void PrepareRawDataGrayscale8(const fs::path& grayPath); - void PrepareRawDataGrayscaleAlpha4(const fs::path& grayAlphaPath); - void PrepareRawDataGrayscaleAlpha8(const fs::path& grayAlphaPath); - void PrepareRawDataGrayscaleAlpha16(const fs::path& grayAlphaPath); - void PrepareRawDataPalette4(const fs::path& palPath); - void PrepareRawDataPalette8(const fs::path& palPath); + void PrepareRawDataRGBA16(); + void PrepareRawDataRGBA32(); + void PrepareRawDataGrayscale4(); + void PrepareRawDataGrayscale8(); + void PrepareRawDataGrayscaleAlpha4(); + void PrepareRawDataGrayscaleAlpha8(); + void PrepareRawDataGrayscaleAlpha16(); + void PrepareRawDataPalette4(); + void PrepareRawDataPalette8(); public: ZTexture(ZFile* nParent); @@ -88,4 +89,5 @@ public: bool IsColorIndexed() const; void SetTlut(ZTexture* nTlut); bool HasTlut() const; + void ParseRawDataLate() override; }; diff --git a/tools/ZAPD/ZAPDUtils/Utils/BitConverter.h b/tools/ZAPD/ZAPDUtils/Utils/BitConverter.h index e672b97c23..646fa1274c 100644 --- a/tools/ZAPD/ZAPDUtils/Utils/BitConverter.h +++ b/tools/ZAPD/ZAPDUtils/Utils/BitConverter.h @@ -1,155 +1,160 @@ #pragma once +#include #include +#include +#include #include #include +#define ALIGN8(val) (((val) + 7) & ~7) +#define ALIGN16(val) (((val) + 0xF) & ~0xF) +#define ALIGN64(val) (((val) + 0x3F) & ~0x3F) + +#ifdef _MSC_VER +#define __PRETTY_FUNCTION__ __FUNCSIG__ +#endif + class BitConverter { public: - static inline int8_t ToInt8BE(const uint8_t* data, int32_t offset) + static inline int8_t ToInt8BE(const std::vector& data, size_t offset) { - return (uint8_t)data[offset + 0]; + if (offset + 0 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying a out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } + return (int8_t)data.at(offset + 0); } - static inline int8_t ToInt8BE(const std::vector& data, int32_t offset) + static inline uint8_t ToUInt8BE(const std::vector& data, size_t offset) { - return (uint8_t)data[offset + 0]; + if (offset + 0 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying an out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } + return (uint8_t)data.at(offset + 0); } - static inline uint8_t ToUInt8BE(const uint8_t* data, int32_t offset) + static inline int16_t ToInt16BE(const std::vector& data, size_t offset) { - return (uint8_t)data[offset + 0]; + if (offset + 1 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying a out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } + return ((uint16_t)data.at(offset + 0) << 8) + (uint16_t)data.at(offset + 1); } - static inline uint8_t ToUInt8BE(const std::vector& data, int32_t offset) + static inline uint16_t ToUInt16BE(const std::vector& data, size_t offset) { - return (uint8_t)data[offset + 0]; + if (offset + 1 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying a out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } + return ((uint16_t)data.at(offset + 0) << 8) + (uint16_t)data.at(offset + 1); } - static inline int16_t ToInt16BE(const uint8_t* data, int32_t offset) + static inline int32_t ToInt32BE(const std::vector& data, size_t offset) { - return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; + if (offset + 3 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying a out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } + return ((uint32_t)data.at(offset + 0) << 24) + ((uint32_t)data.at(offset + 1) << 16) + + ((uint32_t)data.at(offset + 2) << 8) + (uint32_t)data.at(offset + 3); } - static inline int16_t ToInt16BE(const std::vector& data, int32_t offset) + static inline uint32_t ToUInt32BE(const std::vector& data, size_t offset) { - return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; + if (offset + 3 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying a out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } + return ((uint32_t)data.at(offset + 0) << 24) + ((uint32_t)data.at(offset + 1) << 16) + + ((uint32_t)data.at(offset + 2) << 8) + (uint32_t)data.at(offset + 3); } - static inline uint16_t ToUInt16BE(const uint8_t* data, int32_t offset) + static inline int64_t ToInt64BE(const std::vector& data, size_t offset) { - return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; + if (offset + 7 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying a out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } + return ((uint64_t)data.at(offset + 0) << 56) + ((uint64_t)data.at(offset + 1) << 48) + + ((uint64_t)data.at(offset + 2) << 40) + ((uint64_t)data.at(offset + 3) << 32) + + ((uint64_t)data.at(offset + 4) << 24) + ((uint64_t)data.at(offset + 5) << 16) + + ((uint64_t)data.at(offset + 6) << 8) + ((uint64_t)data.at(offset + 7)); } - static inline uint16_t ToUInt16BE(const std::vector& data, int32_t offset) + static inline uint64_t ToUInt64BE(const std::vector& data, size_t offset) { - return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1]; + if (offset + 7 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying a out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } + return ((uint64_t)data.at(offset + 0) << 56) + ((uint64_t)data.at(offset + 1) << 48) + + ((uint64_t)data.at(offset + 2) << 40) + ((uint64_t)data.at(offset + 3) << 32) + + ((uint64_t)data.at(offset + 4) << 24) + ((uint64_t)data.at(offset + 5) << 16) + + ((uint64_t)data.at(offset + 6) << 8) + ((uint64_t)data.at(offset + 7)); } - 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, 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, 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, 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, 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) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); - } - - 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) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); - } - - 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) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); - } - - 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) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); - } - - static inline float ToFloatBE(const uint8_t* data, int32_t offset) + static inline float ToFloatBE(const std::vector& data, size_t offset) { + if (offset + 3 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying a out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } float value; - uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + - ((uint32_t)data[offset + 1] << 16) + - ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; + uint32_t floatData = ((uint32_t)data.at(offset + 0) << 24) + + ((uint32_t)data.at(offset + 1) << 16) + + ((uint32_t)data.at(offset + 2) << 8) + (uint32_t)data.at(offset + 3); static_assert(sizeof(uint32_t) == sizeof(float), "expected 32-bit float"); std::memcpy(&value, &floatData, sizeof(value)); return value; } - static inline float ToFloatBE(const std::vector& data, int32_t offset) - { - float value; - uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + - ((uint32_t)data[offset + 1] << 16) + - ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3]; - static_assert(sizeof(uint32_t) == sizeof(float), "expected 32-bit float"); - std::memcpy(&value, &floatData, sizeof(value)); - return value; - } - - static inline double ToDoubleBE(const uint8_t* data, int32_t offset) + static inline double ToDoubleBE(const std::vector& data, size_t offset) { + if (offset + 7 > data.size()) + { + fprintf(stderr, "%s\n", __PRETTY_FUNCTION__); + fprintf(stderr, "Error: Trying a out-of-bounds reading from a data buffer\n"); + fprintf(stderr, "\t Buffer size: 0x%zX\n", data.size()); + fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); + } double value; uint64_t floatData = - ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + - ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); - static_assert(sizeof(uint64_t) == sizeof(double), "expected 64-bit double"); - // Checks if the float format on the platform the ZAPD binary is running on supports the - // same float format as the object file. - static_assert(std::numeric_limits::is_iec559, - "expected IEC559 floats on host machine"); - std::memcpy(&value, &floatData, sizeof(value)); - return value; - } - - static inline double ToDoubleBE(const std::vector& data, int32_t offset) - { - double value; - uint64_t floatData = - ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + - ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + - ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + - ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]); + ((uint64_t)data.at(offset + 0) << 56) + ((uint64_t)data.at(offset + 1) << 48) + + ((uint64_t)data.at(offset + 2) << 40) + ((uint64_t)data.at(offset + 3) << 32) + + ((uint64_t)data.at(offset + 4) << 24) + ((uint64_t)data.at(offset + 5) << 16) + + ((uint64_t)data.at(offset + 6) << 8) + ((uint64_t)data.at(offset + 7)); static_assert(sizeof(uint64_t) == sizeof(double), "expected 64-bit double"); // Checks if the float format on the platform the ZAPD binary is running on supports the // same float format as the object file. diff --git a/tools/ZAPD/ZAPDUtils/Utils/StringHelper.h b/tools/ZAPD/ZAPDUtils/Utils/StringHelper.h index 6c9e541190..2289927d86 100644 --- a/tools/ZAPD/ZAPDUtils/Utils/StringHelper.h +++ b/tools/ZAPD/ZAPDUtils/Utils/StringHelper.h @@ -106,6 +106,13 @@ public: return std::all_of(str.begin(), str.end(), ::isdigit); } + static std::string ToUpper(const std::string& str) + { + std::string buff = str; + std::transform(buff.begin(), buff.end(), buff.begin(), ::toupper); + return buff; + } + static bool IEquals(const std::string& a, const std::string& b) { return std::equal(a.begin(), a.end(), b.begin(), b.end(), diff --git a/tools/ZAPD/ZAPDUtils/ZAPDUtils.vcxproj b/tools/ZAPD/ZAPDUtils/ZAPDUtils.vcxproj index 0a09666e03..c0ef260dd7 100644 --- a/tools/ZAPD/ZAPDUtils/ZAPDUtils.vcxproj +++ b/tools/ZAPD/ZAPDUtils/ZAPDUtils.vcxproj @@ -1,168 +1,168 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {a2e01c3e-d647-45d1-9788-043debc1a908} - ZAPDUtils - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - StaticLibrary - true - v142 - MultiByte - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - false - - - true - - - false - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreadedDebug - Default - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {a2e01c3e-d647-45d1-9788-043debc1a908} + ZAPDUtils + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + StaticLibrary + true + v143 + MultiByte + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreadedDebug + Default + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 index b3f5575c15..b2a679c1b8 100644 --- a/tools/ZAPD/docs/zapd_extraction_xml_reference.md +++ b/tools/ZAPD/docs/zapd_extraction_xml_reference.md @@ -155,6 +155,9 @@ u64 gCraterSmokeConeTex[] = { - `Width`: Required. Width in pixels of the image. - `Height`: Required. Height in pixels of the image. - `TlutOffset`: Optional. Specifies the tlut's offset used by this texture. This attribute is only valid if `Format` is either `ci4` or `ci8`, otherwise an exception would be thrown. + - `ExternalTlut`: Optional. Specifies that the texture's tlut is in a different file. Takes the filename of the file that contains the tlut. + - `ExternalTlutOffset`: Optional. Specifies the offset in the `ExternalTlut` of the tlut for the given texture. + - `SplitTlut`: Optional. Specifies that the given texture should take from the upper half of the tlut. Takes a bool, i.e. one of `true`, `false`, `1`, `0`. The following is a list of the texture formats the Nintendo 64 supports, with their gfxdis names and ZAPD format names. @@ -382,6 +385,13 @@ Useful only for the unused `object_human`'s animation data. - `Name`: Required. Suxffixed by `Skel`. - `Type`: Required. Valid values: `Normal`, `Flex` and `Curve`. - `LimbType`: Required. Valid values: `Standard`, `LOD`, `Skin`, `Curve` and `Legacy`. + - `EnumName`: Optional. The name of `typedef`'d limb enum. + - `LimbNone`: Optional. The name of the limb with index zero in the limb enum. + - `LimbMax`: Optional. The name of the max limb index in the limb enum. + +ZAPD is able to generate a limb enum by itself only if all the required data is provided. Providing some but not all the required data would trigger an error and the execution will halt. + +The required data is providing the `EnumName`, `LimbNone` and `LimbMax` attributes in the `Skeleton` or `LimbTable` node and the `EnumName` attribute in every `Limb` of this skeleton. ※ 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. @@ -400,6 +410,11 @@ Useful only for the unused `object_human`'s animation data. - `Name`: Required. Suxffixed by `Skel`. - `LimbType`: Required. Valid values: `Standard`, `LOD`, `Skin`, `Curve` and `Legacy`. - `Count`: Required. Amount of limbs. Integer. + - `EnumName`: Optional. The name of `typedef`'d limb enum. + - `LimbNone`: Optional. The name of the limb with index zero in the limb enum. + - `LimbMax`: Optional. The name of the max limb index in the limb enum. + +See [Skeleton](#skeleton) for info on the limb enum generation. ------------------------- @@ -415,6 +430,9 @@ Useful only for the unused `object_human`'s animation data. - `Name`: Required. Suxffixed by `Limb`. - `LimbType`: Required. Valid values: `Standard`, `LOD`, `Skin`, `Curve` and `Legacy`. + - `EnumName`: Optional. The name used for this limb in the limbs enum. It must be either present in every limb or in none. + +See [Skeleton](#skeleton) for info on the limb enum generation. -------------------------