diff options
| author | briaguya <70942617+briaguya-ai@users.noreply.github.com> | 2023-10-18 00:09:24 -0400 |
|---|---|---|
| committer | briaguya <70942617+briaguya-ai@users.noreply.github.com> | 2023-10-18 00:09:24 -0400 |
| commit | 3f878d401fdcff6e7f898524f3bcf5cf4c2b2532 (patch) | |
| tree | 2f0a7e29ec2dd17d0cbe70e8ee52c96f88608bfa | |
| parent | e9f4fc638ed904cc0dcdac24ea7708c9a220a702 (diff) | |
| parent | 094e797349c86d0baef4a624962f4287aefdfef2 (diff) | |
Merge branch 'JackMaster' into mergeJackOntoSquash
Conflicts:
ZAPD/Declaration.h
ZAPD/Globals.cpp
ZAPD/Globals.h
ZAPD/Main.cpp
ZAPD/OtherStructs/SkinLimbStructs.cpp
ZAPD/OtherStructs/SkinLimbStructs.h
ZAPD/ZAnimation.cpp
ZAPD/ZCollision.cpp
ZAPD/ZCollision.h
ZAPD/ZDisplayList.cpp
ZAPD/ZFile.cpp
ZAPD/ZLimb.cpp
ZAPD/ZLimb.h
ZAPD/ZPath.cpp
ZAPD/ZResource.h
ZAPD/ZRoom/Commands/SetCsCamera.cpp
ZAPD/ZRoom/Commands/SetCutsceneEntryList.cpp
ZAPD/ZRoom/Commands/SetCutscenes.cpp
ZAPD/ZRoom/Commands/SetCutscenes.h
ZAPD/ZRoom/Commands/SetEntranceList.cpp
ZAPD/ZRoom/Commands/SetLightingSettings.cpp
ZAPD/ZRoom/Commands/SetMesh.cpp
ZAPD/ZRoom/Commands/SetMinimapList.cpp
ZAPD/ZTexture.cpp
ZAPDUtils/Makefile
ZAPDUtils/Utils/BitConverter.h
ZAPDUtils/Utils/Directory.h
ZAPDUtils/Utils/File.h
ZAPDUtils/Utils/Path.h
ZAPDUtils/Utils/StringHelper.h
ZAPDUtils/ZAPDUtils.vcxproj
78 files changed, 3660 insertions, 2302 deletions
diff --git a/.clang-format b/.clang-format index 784e734..5ba1c4a 100644 --- a/.clang-format +++ b/.clang-format @@ -66,7 +66,7 @@ PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 PointerAlignment: Left ReflowComments: true -SortIncludes: true +SortIncludes: false SpaceAfterCStyleCast: false SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements diff --git a/ExporterTest/CollisionExporter.cpp b/ExporterTest/CollisionExporter.cpp index c216718..f7501b2 100644 --- a/ExporterTest/CollisionExporter.cpp +++ b/ExporterTest/CollisionExporter.cpp @@ -67,9 +67,9 @@ void ExporterExample_Collision::Save(ZResource* res, [[maybe_unused]] const fs:: for (auto entry : col->camData->entries) { - writer->Write(entry->cameraSType); - writer->Write(entry->numData); - writer->Write(entry->cameraPosDataSeg); + writer->Write(entry.cameraSType); + writer->Write(entry.numData); + writer->Write(entry.cameraPosDataSeg); } writer->Seek(oldOffset, SeekOffsetType::Start); diff --git a/ExporterTest/Makefile b/ExporterTest/Makefile index 42033b7..98e0475 100644 --- a/ExporterTest/Makefile +++ b/ExporterTest/Makefile @@ -17,7 +17,7 @@ clean: rm -rf build $(LIB) format: - clang-format-11 -i $(CPP_FILES) $(H_FILES) + clang-format-14 -i $(CPP_FILES) $(H_FILES) .PHONY: all clean format diff --git a/ExporterTest/RoomExporter.cpp b/ExporterTest/RoomExporter.cpp index e77f264..56b3153 100644 --- a/ExporterTest/RoomExporter.cpp +++ b/ExporterTest/RoomExporter.cpp @@ -290,7 +290,7 @@ void ExporterExample_Room::Save(ZResource* res, const fs::path& outPath, BinaryW uint32_t oldOffset = writer->GetBaseAddress(); writer->Seek(baseStreamEnd, SeekOffsetType::Start); - for (EntranceEntry entry : cmdEntrance->entrances) + for (Spawn entry : cmdEntrance->entrances) { writer->Write((uint8_t)entry.startPositionIndex); writer->Write((uint8_t)entry.roomToLoad); @@ -8,6 +8,18 @@ COPYCHECK_ARGS ?= LLD ?= 0 WERROR ?= 0 +# On MacOS 10.14, use boost::filesystem, because +# the system doesn't supply std::filesystem. +ifneq ($(OS),Windows_NT) + ifeq ($(shell uname -s),Darwin) + MACOS_VERSION := $(shell sw_vers -productVersion | cut -d . -f 1,2) + ifeq ($(MACOS_VERSION),10.14) + USE_BOOST_FS ?= 1 + endif + endif +endif +USE_BOOST_FS ?= 0 + # Use clang++ if available, else use g++ ifeq ($(shell command -v clang++ >/dev/null 2>&1; echo $$?),0) CXX := clang++ @@ -46,6 +58,11 @@ endif LDFLAGS := -lm -ldl -lpng +ifneq ($(USE_BOOST_FS),0) + CXXFLAGS += -DUSE_BOOST_FS + LDFLAGS += -lboost_filesystem +endif + # Use LLD if available. Set LLD=0 to not use it ifeq ($(shell command -v ld.lld >/dev/null 2>&1; echo $$?),0) LLD := 1 @@ -106,7 +123,7 @@ clean: rebuild: clean all format: - clang-format-11 -i $(ZAPD_CPP_FILES) $(ZAPD_H_FILES) + clang-format-14 -i $(ZAPD_CPP_FILES) $(ZAPD_H_FILES) $(MAKE) -C ZAPDUtils format $(MAKE) -C ExporterTest format @@ -28,7 +28,7 @@ to install it via Homebrew. #### Linux / *nix -ZAPD uses the clasic `Makefile` approach. To build just run `make` (or even better `make -j` for faster compilations). +ZAPD uses the classic `Makefile` approach. To build just run `make` (or even better `make -j` for faster compilations). You can configure a bit your ZAPD build with the following options: @@ -139,22 +139,23 @@ Each warning type uses one of these by default, but can be modified with flags, All warning types currently implemented, with their default levels: -| Warning type | Default level | Description | -| --------------------------- | ------------- | ------------------------------------------------------------------------ | -| `-Wdeprecated` | Warn | Deprecated features | -| `-Whardcoded-pointer` | Warn | ZAPD lacks the info to make a symbol, so must output a hardcoded pointer | -| `-Wintersection` | Warn | Two assets intersect | -| `-Winvalid-attribute-value` | Err | Attribute declared in XML is wrong | -| `-Winvalid-extracted-data` | Err | Extracted data does not have correct form | -| `-Winvalid-jpeg` | Err | JPEG file does not conform to the game's format requirements | -| `-Winvalid-png` | Err | Issues arising when processing PNG data | -| `-Winvalid-xml` | Err | XML has syntax errors | -| `-Wmissing-attribute` | Warn | Required attribute missing in XML tag | -| `-Wmissing-offsets` | Warn | Offset attribute missing in XML tag | -| `-Wmissing-segment` | Warn | Segment not given in File tag in XML | -| `-Wnot-implemented` | Warn | ZAPD does not currently support this feature | -| `-Wunaccounted` | Off | Large blocks of unaccounted | -| `-Wunknown-attribute` | Warn | Unknown attribute in XML entry tag | +| Warning type | Default level | Description | +| ----------------------------- | ------------- | ------------------------------------------------------------------------ | +| `-Wdeprecated` | Warn | Deprecated features | +| `-Whardcoded-generic-pointer` | Off | A generic segmented pointer must be produced | +| `-Whardcoded-pointer` | Warn | ZAPD lacks the info to make a symbol, so must output a hardcoded pointer | +| `-Wintersection` | Warn | Two assets intersect | +| `-Winvalid-attribute-value` | Err | Attribute declared in XML is wrong | +| `-Winvalid-extracted-data` | Err | Extracted data does not have correct form | +| `-Winvalid-jpeg` | Err | JPEG file does not conform to the game's format requirements | +| `-Winvalid-png` | Err | Issues arising when processing PNG data | +| `-Winvalid-xml` | Err | XML has syntax errors | +| `-Wmissing-attribute` | Warn | Required attribute missing in XML tag | +| `-Wmissing-offsets` | Warn | Offset attribute missing in XML tag | +| `-Wmissing-segment` | Warn | Segment not given in File tag in XML | +| `-Wnot-implemented` | Warn | ZAPD does not currently support this feature | +| `-Wunaccounted` | Off | Large blocks of unaccounted | +| `-Wunknown-attribute` | Warn | Unknown attribute in XML entry tag | There are also errors that do not have a type, and cannot be disabled. diff --git a/ZAPD/CrashHandler.cpp b/ZAPD/CrashHandler.cpp index 3568665..7ddec5a 100644 --- a/ZAPD/CrashHandler.cpp +++ b/ZAPD/CrashHandler.cpp @@ -8,6 +8,7 @@ #endif #include <array> +#include <cstdint> #include <cstdio> #include <cstdlib> #include <ctime> diff --git a/ZAPD/Declaration.cpp b/ZAPD/Declaration.cpp index 3f0c0ad..e4f91d8 100644 --- a/ZAPD/Declaration.cpp +++ b/ZAPD/Declaration.cpp @@ -5,61 +5,79 @@ #include "Utils/StringHelper.h" Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nText) + const std::string& nBody) { address = nAddress; alignment = nAlignment; size = nSize; - text = nText; + declBody = nBody; } -Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nVarType, const std::string& nVarName, bool nIsArray, - const std::string& nText) - : Declaration(nAddress, nAlignment, nSize, nText) +Declaration* Declaration::Create(offset_t declAddr, DeclarationAlignment declAlign, size_t declSize, + const std::string& declType, const std::string& declName, + const std::string& declBody) { - varType = nVarType; - varName = nVarName; - isArray = nIsArray; + Declaration* decl = new Declaration(declAddr, declAlign, declSize, declBody); + + decl->declType = declType; + decl->declName = declName; + decl->declBody = declBody; + + return decl; } -Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nVarType, const std::string& nVarName, bool nIsArray, - size_t nArrayItemCnt, const std::string& nText) - : Declaration(nAddress, nAlignment, nSize, nText) +Declaration* Declaration::CreateArray(offset_t declAddr, DeclarationAlignment declAlign, + size_t declSize, const std::string& declType, + const std::string& declName, const std::string& declBody, + size_t declArrayItemCnt, bool isDeclExternal) { - varType = nVarType; - varName = nVarName; - isArray = nIsArray; - arrayItemCnt = nArrayItemCnt; + Declaration* decl = new Declaration(declAddr, declAlign, declSize, declBody); + + decl->declName = declName; + decl->declType = declType; + decl->arrayItemCnt = declArrayItemCnt; + decl->isExternal = isDeclExternal; + decl->isArray = true; + + return decl; } -Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nVarType, const std::string& nVarName, bool nIsArray, - const std::string& nArrayItemCntStr, const std::string& nText) - : Declaration(nAddress, nAlignment, nSize, nText) +Declaration* Declaration::CreateArray(offset_t declAddr, DeclarationAlignment declAlign, + size_t declSize, const std::string& declType, + const std::string& declName, const std::string& declBody, + const std::string& declArrayItemCntStr, bool isDeclExternal) { - varType = nVarType; - varName = nVarName; - isArray = nIsArray; - arrayItemCntStr = nArrayItemCntStr; + Declaration* decl = new Declaration(declAddr, declAlign, declSize, declBody); + + decl->declName = declName; + decl->declType = declType; + decl->arrayItemCntStr = declArrayItemCntStr; + decl->isExternal = isDeclExternal; + decl->isArray = true; + + return decl; } -Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nVarType, const std::string& nVarName, bool nIsArray, - size_t nArrayItemCnt, const std::string& nText, bool nIsExternal) - : Declaration(nAddress, nAlignment, nSize, nVarType, nVarName, nIsArray, nArrayItemCnt, nText) +Declaration* Declaration::CreateInclude(offset_t declAddr, const std::string& includePath, + size_t declSize, const std::string& declType, + const std::string& declName, const std::string& defines) { - isExternal = nIsExternal; + Declaration* decl = new Declaration(declAddr, DeclarationAlignment::Align4, declSize, ""); + decl->includePath = includePath; + decl->declType = declType; + decl->declName = declName; + decl->defines = defines; + + return decl; } -Declaration::Declaration(offset_t nAddress, const std::string& nIncludePath, size_t nSize, - const std::string& nVarType, const std::string& nVarName) - : Declaration(nAddress, DeclarationAlignment::Align4, nSize, "") +Declaration* Declaration::CreatePlaceholder(offset_t declAddr, const std::string& declName) { - includePath = nIncludePath; - varType = nVarType; - varName = nVarName; + Declaration* decl = new Declaration(declAddr, DeclarationAlignment::Align4, 0, ""); + decl->declName = declName; + decl->isPlaceholder = true; + + return decl; } Declaration::~Declaration() @@ -89,9 +107,6 @@ std::string Declaration::GetNormalDeclarationStr() const { std::string output; - if (preText != "") - output += preText + "\n"; - if (IsStatic()) { output += "static "; @@ -99,27 +114,28 @@ std::string Declaration::GetNormalDeclarationStr() const if (isArray) { - if (arrayItemCntStr != "" && (IsStatic() || forceArrayCnt)) - { - output += StringHelper::Sprintf("%s %s[%s];\n", varType.c_str(), varName.c_str(), - arrayItemCntStr.c_str()); - } - else if (arrayItemCnt != 0 && (IsStatic() || forceArrayCnt)) + bool includeArraySize = (IsStatic() || forceArrayCnt); + + if (includeArraySize) { - output += StringHelper::Sprintf("%s %s[%i] = {\n", varType.c_str(), varName.c_str(), - arrayItemCnt); + if (arrayItemCntStr != "") + output += StringHelper::Sprintf("%s %s[%s];\n", declType.c_str(), declName.c_str(), + arrayItemCntStr.c_str()); + else + output += StringHelper::Sprintf("%s %s[%i] = {\n", declType.c_str(), + declName.c_str(), arrayItemCnt); } else { - output += StringHelper::Sprintf("%s %s[] = {\n", varType.c_str(), varName.c_str()); + output += StringHelper::Sprintf("%s %s[] = {\n", declType.c_str(), declName.c_str()); } - output += text + "\n"; + output += declBody + "\n"; } else { - output += StringHelper::Sprintf("%s %s = { ", varType.c_str(), varName.c_str()); - output += text; + output += StringHelper::Sprintf("%s %s = { ", declType.c_str(), declName.c_str()); + output += declBody; } if (output.back() == '\n') @@ -127,14 +143,8 @@ std::string Declaration::GetNormalDeclarationStr() const else output += " };"; - if (rightText != "") - output += " " + rightText + ""; - output += "\n"; - if (postText != "") - output += postText + "\n"; - output += "\n"; return output; @@ -144,41 +154,34 @@ std::string Declaration::GetExternalDeclarationStr() const { std::string output; - if (preText != "") - output += preText + "\n"; - if (IsStatic()) - { output += "static "; - } - if (arrayItemCntStr != "" && (IsStatic() || forceArrayCnt)) - output += StringHelper::Sprintf("%s %s[%s] = ", varType.c_str(), varName.c_str(), - arrayItemCntStr.c_str()); - else if (arrayItemCnt != 0 && (IsStatic() || forceArrayCnt)) - output += - StringHelper::Sprintf("%s %s[%i] = ", varType.c_str(), varName.c_str(), arrayItemCnt); + bool includeArraySize = (IsStatic() || forceArrayCnt); + + if (includeArraySize) + { + if (arrayItemCntStr != "") + output += StringHelper::Sprintf("%s %s[%s] = ", declType.c_str(), declName.c_str(), + arrayItemCntStr.c_str()); + else + output += StringHelper::Sprintf("%s %s[%i] = ", declType.c_str(), declName.c_str(), + arrayItemCnt); + } else - output += StringHelper::Sprintf("%s %s[] = ", varType.c_str(), varName.c_str()); + { + output += StringHelper::Sprintf("%s %s[] = ", declType.c_str(), declName.c_str()); + } output += StringHelper::Sprintf("{\n#include \"%s\"\n};", includePath.c_str()); - - if (rightText != "") - output += " " + rightText + ""; - - output += "\n"; - - if (postText != "") - output += postText + "\n"; - - output += "\n"; + output += "\n\n"; return output; } std::string Declaration::GetExternStr() const { - if (IsStatic() || varType == "" || isUnaccounted) + if (IsStatic() || declType == "" || isUnaccounted) { return ""; } @@ -192,19 +195,28 @@ std::string Declaration::GetExternStr() const { if (arrayItemCntStr != "" && (IsStatic() || forceArrayCnt)) { - return StringHelper::Sprintf("extern %s %s[%s];\n", varType.c_str(), varName.c_str(), + return StringHelper::Sprintf("extern %s %s[%s];\n", declType.c_str(), declName.c_str(), arrayItemCntStr.c_str()); } else if (arrayItemCnt != 0 && (IsStatic() || forceArrayCnt)) { - return StringHelper::Sprintf("extern %s %s[%i];\n", varType.c_str(), varName.c_str(), + return StringHelper::Sprintf("extern %s %s[%i];\n", declType.c_str(), declName.c_str(), arrayItemCnt); } else - return StringHelper::Sprintf("extern %s %s[];\n", varType.c_str(), varName.c_str()); + return StringHelper::Sprintf("extern %s %s[];\n", declType.c_str(), declName.c_str()); } - return StringHelper::Sprintf("extern %s %s;\n", varType.c_str(), varName.c_str()); + return StringHelper::Sprintf("extern %s %s;\n", declType.c_str(), declName.c_str()); +} + +std::string Declaration::GetDefinesStr() const +{ + if (IsStatic() || (declType == "")) + { + return ""; + } + return StringHelper::Sprintf("%s", defines.c_str()); } std::string Declaration::GetStaticForwardDeclarationStr() const @@ -222,15 +234,15 @@ std::string Declaration::GetStaticForwardDeclarationStr() const if (arrayItemCntStr != "") { - return StringHelper::Sprintf("static %s %s[%s];\n", varType.c_str(), varName.c_str(), + return StringHelper::Sprintf("static %s %s[%s];\n", declType.c_str(), declName.c_str(), arrayItemCntStr.c_str()); } else { - return StringHelper::Sprintf("static %s %s[%i];\n", varType.c_str(), varName.c_str(), + return StringHelper::Sprintf("static %s %s[%i];\n", declType.c_str(), declName.c_str(), arrayItemCnt); } } - return StringHelper::Sprintf("static %s %s;\n", varType.c_str(), varName.c_str()); + return StringHelper::Sprintf("static %s %s;\n", declType.c_str(), declName.c_str()); } diff --git a/ZAPD/Declaration.h b/ZAPD/Declaration.h index 64712d8..0a504e9 100644 --- a/ZAPD/Declaration.h +++ b/ZAPD/Declaration.h @@ -1,8 +1,8 @@ #pragma once +#include <cstdint> #include <string> #include <vector> -#include <cstdint> // TODO: should we drop the `_t` suffix because of UNIX compliance? typedef uint32_t segptr_t; @@ -25,63 +25,164 @@ enum class StaticConfig class ZVtx; +/// <summary> +/// A declaration is contains the C contents of a symbol for a file. +/// It contains at a minimum the address where the symbol would be in the binary file, alignment +/// settings, the size of the binary data, and the C code that makes it up. Optionally it can also +/// contain comments. +/// </summary> class Declaration { public: - offset_t address; - DeclarationAlignment alignment; - size_t size; - std::string preText; - std::string text; - std::string rightText; - std::string postText; - std::string preComment; - std::string postComment; - std::string varType; - std::string varName; - std::string includePath; + // Where in the binary file (segment) will this C code end up being? + offset_t address = 0; + + // How is this C code aligned? + DeclarationAlignment alignment = DeclarationAlignment::Align4; + + // How many bytes will this C code take up in the resulting binary when compiled? + size_t size = 0; + + // The C type of this declaration + std::string declType = ""; + + // The C variable name of this declaration + std::string declName = ""; + + // The body of the declaration containing the data. + // In "int j = 7;", "7" would be text. + std::string declBody = ""; + + // #define's to be included in the header + std::string defines = ""; + + std::string includePath = ""; std::vector<ZVtx*> vertexHack; + // Is this declaration in an external file? (ie. a gameplay_keep reference being found in + // another file that wishes to use its data) bool isExternal = false; + bool isArray = false; + + // If true, will ensure that the arrays size is included in the declaration bool forceArrayCnt = false; + + // If this declaration is an array, how many items make it up? size_t arrayItemCnt = 0; + + // Overrides the brackets for the arrays size with a custom string std::string arrayItemCntStr = ""; + std::vector<segptr_t> references; + + // If true, this declaration represents data inside the file which we do not understand it's + // purpose for. It will be outputted as just a byte array. bool isUnaccounted = false; + + // Is this declaration a placeholder that will be replaced later? bool isPlaceholder = false; + + // Does this declaration come straight from the XML? + // If false, this means that the declaration was created by ZAPD when it was parsing the + // resources. bool declaredInXml = false; - StaticConfig staticConf = StaticConfig::Global; - Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nVarType, const std::string& nVarName, bool nIsArray, - const std::string& nText); - Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nVarType, const std::string& nVarName, bool nIsArray, - size_t nArrayItemCnt, const std::string& nText); - Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nVarType, const std::string& nVarName, bool nIsArray, - const std::string& nArrayItemCntStr, const std::string& nText); - Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nVarType, const std::string& nVarName, bool nIsArray, - size_t nArrayItemCnt, const std::string& nText, bool nIsExternal); + StaticConfig staticConf = StaticConfig::Global; - Declaration(offset_t nAddress, const std::string& nIncludePath, size_t nSize, - const std::string& nVarType, const std::string& nVarName); + /// <summary> + /// Creates a regular declaration. + /// </summary> + /// <param name="declAddr">The address inside a binary file this declaration will be in when + /// compiled.</param> <param name="declAlign">The alignment of this declaration in the compiled + /// binary file.</param> <param name="declSize">The size of this declaration when it is compiled + /// to binary data.</param> <param name="declType">The C variable type this declaration will be + /// declared as.</param> <param name="declName">The C variable name this declaration will be + /// declared as.</param> <param name="declBody">The contents of the C variable + /// declaration.</param> <returns></returns> + static Declaration* Create(offset_t declAddr, DeclarationAlignment declAlign, size_t declSize, + const std::string& declType, const std::string& declName, + const std::string& declBody); + + /// <summary> + /// Creates an array declaration. + /// </summary> + /// <param name="declAddr">The address inside a binary file this declaration will be in when + /// compiled.</param> <param name="declAlign">The alignment of this declaration in the compiled + /// binary file.</param> <param name="declSize">The size of this declaration when it is compiled + /// to binary data.</param> <param name="declType">The C variable type this declaration will be + /// declared as.</param> <param name="declName">The C variable name this declaration will be + /// declared as.</param> <param name="declBody">The contents of the C variable + /// declaration.</param> <param name="declArrayItemCnt">The number of items in the + /// array.</param> <param name="isDeclExternal">(Optional) Is this declaration from another + /// segment?</param> <returns></returns> + static Declaration* CreateArray(offset_t declAddr, DeclarationAlignment declAlign, + size_t declSize, const std::string& declType, + const std::string& declName, const std::string& declBody, + size_t declArrayItemCnt = 0, bool isDeclExternal = false); + + /// <summary> + /// Creates an array declaration who's size in the C code uses a custom string. + /// </summary> + /// <param name="declAddr">The address inside a binary file this declaration will be in when + /// compiled.</param> <param name="declAlign">The alignment of this declaration in the compiled + /// binary file.</param> <param name="declSize">The size of this declaration when it is compiled + /// to binary data.</param> <param name="declType">The C variable type this declaration will be + /// declared as.</param> <param name="declName">The C variable name this declaration will be + /// declared as.</param> <param name="declBody">The contents of the C variable + /// declaration.</param> <param name="declArrayItemCntStr">The string to be put in the C array's + /// size inbetween the brackets.</param> <param name="isDeclExternal">(Optional) Is this + /// declaration from another segment?</param> <returns></returns> + static Declaration* CreateArray(offset_t declAddr, DeclarationAlignment declAlign, + size_t declSize, const std::string& declType, + const std::string& declName, const std::string& declBody, + const std::string& declArrayItemCntStr, + bool isDeclExternal = false); + + /// <summary> + /// Creates a declaration who's body uses a #include to include another file + /// </summary> + /// <param name="declAddr">The address inside a binary file this declaration will be in when + /// compiled.</param> <param name="includePath">The path to the file this declaration will be + /// #including.</param> <param name="declSize">The size of this declaration when it is compiled + /// to binary data.</param> <param name="declType">The C variable type this declaration will be + /// declared as.</param> <param name="declName">The C variable name this declaration will be + /// declared as.</param> <param name="defines">(Optional) Any #define's we want to have + /// outputted by this declaration.</param> <returns></returns> + static Declaration* CreateInclude(offset_t declAddr, const std::string& includePath, + size_t declSize, const std::string& declType, + const std::string& declName, const std::string& defines = ""); + + /// <summary> + /// Creates a placeholder declaration to be replaced later. + /// </summary> + /// <param name="declAddr">The address inside a binary file this declaration will be in when + /// compiled.</param> <param name="declName">The C variable name this declaration will be + /// declared as.</param> <returns></returns> + static Declaration* CreatePlaceholder(offset_t declAddr, const std::string& declName); ~Declaration(); bool IsStatic() const; + // Returns the declaration as C code as it would be in the code file when the body contains the + // needed data std::string GetNormalDeclarationStr() const; + + // Returns the declaration as C code as it would be in the code file when the body #include's + // another file std::string GetExternalDeclarationStr() const; + // Generates the extern for this item to be placed in header files. std::string GetExternStr() const; + // Generates any #define's needed + std::string GetDefinesStr() const; + std::string GetStaticForwardDeclarationStr() const; protected: Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize, - const std::string& nText); + const std::string& nBody); }; diff --git a/ZAPD/ExporterSet.h b/ZAPD/ExporterSet.h new file mode 100644 index 0000000..c4dd934 --- /dev/null +++ b/ZAPD/ExporterSet.h @@ -0,0 +1,24 @@ +#pragma once + +typedef void (*ExporterSetFunc)(ZFile*); +typedef bool (*ExporterSetFuncBool)(ZFileMode fileMode); +typedef void (*ExporterSetFuncVoid)(int argc, char* argv[], int& i); +typedef void (*ExporterSetFuncVoid2)(const std::string& buildMode, ZFileMode& fileMode); +typedef void (*ExporterSetFuncVoid3)(); +typedef void (*ExporterSetResSave)(ZResource* res, BinaryWriter& writer); + +class ExporterSet +{ +public: + ~ExporterSet(); + + std::map<ZResourceType, ZResourceExporter*> exporters; + ExporterSetFuncVoid parseArgsFunc = nullptr; + ExporterSetFuncVoid2 parseFileModeFunc = nullptr; + ExporterSetFuncBool processFileModeFunc = nullptr; + ExporterSetFunc beginFileFunc = nullptr; + ExporterSetFunc endFileFunc = nullptr; + ExporterSetFuncVoid3 beginXMLFunc = nullptr; + ExporterSetFuncVoid3 endXMLFunc = nullptr; + ExporterSetResSave resSaveFunc = nullptr; +};
\ No newline at end of file diff --git a/ZAPD/GameConfig.cpp b/ZAPD/GameConfig.cpp index 9a2e889..6068280 100644 --- a/ZAPD/GameConfig.cpp +++ b/ZAPD/GameConfig.cpp @@ -125,6 +125,7 @@ void GameConfig::ConfigFunc_BGConfig(const tinyxml2::XMLElement& element) { bgScreenWidth = element.IntAttribute("ScreenWidth", 320); bgScreenHeight = element.IntAttribute("ScreenHeight", 240); + useScreenWidthHeightConstants = element.BoolAttribute("UseScreenWidthHeightConstants", true); } void GameConfig::ConfigFunc_ExternalXMLFolder(const tinyxml2::XMLElement& element) @@ -164,6 +165,83 @@ void GameConfig::ConfigFunc_ExternalFile(const tinyxml2::XMLElement& element) externalFiles.push_back(ExternalFile(fs::path(xmlPathValue), fs::path(outPathValue))); } +void GameConfig::ConfigFunc_EnumData(const tinyxml2::XMLElement& element) +{ + std::string path = Path::GetDirectoryName(configFilePath); + path = path.append("/").append(element.Attribute("File")); + tinyxml2::XMLDocument doc; + tinyxml2::XMLError eResult = doc.LoadFile(path.c_str()); + + if (eResult != tinyxml2::XML_SUCCESS) + { + throw std::runtime_error("Error: Unable to read enum data."); + } + + tinyxml2::XMLNode* root = doc.FirstChild(); + + if (root == nullptr) + return; + + for (tinyxml2::XMLElement* csEnum = root->FirstChildElement(); csEnum != nullptr; + csEnum = csEnum->NextSiblingElement()) + { + for (tinyxml2::XMLElement* item = csEnum->FirstChildElement(); item != nullptr; + item = item->NextSiblingElement()) + { + std::string enumKey = csEnum->Attribute("Key"); + uint16_t itemIndex = atoi(item->Attribute("Index")); + const char* itemID = item->Attribute("ID"); + + // Common + if (enumKey == "cmd") + enumData.cutsceneCmd[itemIndex] = itemID; + + else if (enumKey == "miscType") + enumData.miscType[itemIndex] = itemID; + + else if (enumKey == "textType") + enumData.textType[itemIndex] = itemID; + + else if (enumKey == "fadeOutSeqPlayer") + enumData.fadeOutSeqPlayer[itemIndex] = itemID; + + else if (enumKey == "transitionType") + enumData.transitionType[itemIndex] = itemID; + + else if (enumKey == "destination") + enumData.destination[itemIndex] = itemID; + + else if (enumKey == "naviQuestHintType") + enumData.naviQuestHintType[itemIndex] = itemID; + + // MM + else if (enumKey == "modifySeqType") + enumData.modifySeqType[itemIndex] = itemID; + + else if (enumKey == "chooseCreditsSceneType") + enumData.chooseCreditsSceneType[itemIndex] = itemID; + + else if (enumKey == "destinationType") + enumData.destinationType[itemIndex] = itemID; + + else if (enumKey == "motionBlurType") + enumData.motionBlurType[itemIndex] = itemID; + + else if (enumKey == "transitionGeneralType") + enumData.transitionGeneralType[itemIndex] = itemID; + + else if (enumKey == "rumbleType") + enumData.rumbleType[itemIndex] = itemID; + + else if (enumKey == "spawnFlag") + enumData.spawnFlag[itemIndex] = itemID; + + else if (enumKey == "endSfx") + enumData.endSfx[itemIndex] = itemID; + } + } +} + void GameConfig::ReadConfigFile(const fs::path& argConfigFilePath) { static const std::unordered_map<std::string, ConfigFunc> ConfigFuncDictionary = { @@ -174,6 +252,7 @@ void GameConfig::ReadConfigFile(const fs::path& argConfigFilePath) {"SpecialEntranceList", &GameConfig::ConfigFunc_specialEntranceList}, {"TexturePool", &GameConfig::ConfigFunc_TexturePool}, {"BGConfig", &GameConfig::ConfigFunc_BGConfig}, + {"EnumData", &GameConfig::ConfigFunc_EnumData}, {"ExternalXMLFolder", &GameConfig::ConfigFunc_ExternalXMLFolder}, {"ExternalFile", &GameConfig::ConfigFunc_ExternalFile}, }; diff --git a/ZAPD/GameConfig.h b/ZAPD/GameConfig.h index 2a783d1..0eb3f02 100644 --- a/ZAPD/GameConfig.h +++ b/ZAPD/GameConfig.h @@ -21,6 +21,32 @@ public: ExternalFile(fs::path nXmlPath, fs::path nOutPath); }; +// Stores data from the XML file, the integer is the index (via ATOI) and the string is the value +class EnumData +{ +public: + // Common + std::map<uint16_t, std::string> cutsceneCmd; + std::map<uint16_t, std::string> miscType; + std::map<uint16_t, std::string> fadeOutSeqPlayer; + std::map<uint16_t, std::string> transitionType; + std::map<uint16_t, std::string> naviQuestHintType; + + // OoT + std::map<uint16_t, std::string> textType; + std::map<uint16_t, std::string> destination; + + // MM + std::map<uint16_t, std::string> modifySeqType; + std::map<uint16_t, std::string> chooseCreditsSceneType; + std::map<uint16_t, std::string> destinationType; + std::map<uint16_t, std::string> motionBlurType; + std::map<uint16_t, std::string> transitionGeneralType; + std::map<uint16_t, std::string> rumbleType; + std::map<uint8_t, std::string> spawnFlag; + std::map<uint8_t, std::string> endSfx; +}; + class ZFile; class GameConfig @@ -34,9 +60,12 @@ public: std::vector<std::string> entranceList; std::vector<std::string> specialEntranceList; std::map<uint32_t, TexturePoolEntry> texturePool; // Key = CRC + EnumData enumData; // ZBackground uint32_t bgScreenWidth = 320, bgScreenHeight = 240; + bool useScreenWidthHeightConstants = true; // If true, ZBackground's will be declared with + // SCREEN_WIDTH * SCREEN_HEIGHT in the C file // ExternalFile fs::path externalXmlFolder; @@ -57,6 +86,7 @@ public: void ConfigFunc_BGConfig(const tinyxml2::XMLElement& element); void ConfigFunc_ExternalXMLFolder(const tinyxml2::XMLElement& element); void ConfigFunc_ExternalFile(const tinyxml2::XMLElement& element); + void ConfigFunc_EnumData(const tinyxml2::XMLElement& element); void ReadConfigFile(const fs::path& configFilePath); }; diff --git a/ZAPD/Globals.cpp b/ZAPD/Globals.cpp index a6b22cf..7167905 100644 --- a/ZAPD/Globals.cpp +++ b/ZAPD/Globals.cpp @@ -190,9 +190,10 @@ std::vector<uint8_t> Globals::GetBaseromFile(std::string fileName) } bool Globals::GetSegmentedPtrName(segptr_t segAddress, ZFile* currentFile, - const std::string& expectedType, std::string& declName, int workerID) + const std::string& expectedType, std::string& declName, + int workerID, bool warnIfNotFound) { - if (segAddress == 0) + if (segAddress == SEGMENTED_NULL) { declName = "NULL"; return true; @@ -269,14 +270,18 @@ bool Globals::GetSegmentedPtrName(segptr_t segAddress, ZFile* currentFile, } declName = StringHelper::Sprintf("0x%08X", segAddress); + if (warnIfNotFound) + { + WarnHardcodedPointer(segAddress, currentFile, nullptr, -1); + } return false; } bool Globals::GetSegmentedArrayIndexedName(segptr_t segAddress, size_t elementSize, ZFile* currentFile, const std::string& expectedType, - std::string& declName, int workerID) + std::string& declName, int workerID, bool warnIfNotFound) { - if (segAddress == 0) + if (segAddress == SEGMENTED_NULL) { declName = "NULL"; return true; @@ -308,9 +313,36 @@ bool Globals::GetSegmentedArrayIndexedName(segptr_t segAddress, size_t elementSi } declName = StringHelper::Sprintf("0x%08X", segAddress); + if (warnIfNotFound) + { + WarnHardcodedPointer(segAddress, currentFile, nullptr, -1); + } return false; } +void Globals::WarnHardcodedPointer(segptr_t segAddress, ZFile* currentFile, ZResource* res, + offset_t currentOffset) +{ + uint8_t segment = GETSEGNUM(segAddress); + + if ((segment >= 2 && segment <= 6) || segment == 0x80) + { + std::string errorHeader = "A hardcoded pointer was found"; + std::string errorBody = StringHelper::Sprintf("Pointer: 0x%08X", segAddress); + + HANDLE_WARNING_RESOURCE(WarningType::HardcodedPointer, currentFile, res, currentOffset, + errorHeader, errorBody); + } + else + { + std::string errorHeader = "A general purpose hardcoded pointer was found"; + std::string errorBody = StringHelper::Sprintf("Pointer: 0x%08X", segAddress); + + HANDLE_WARNING_RESOURCE(WarningType::HardcodedGenericPointer, currentFile, res, + currentOffset, errorHeader, errorBody); + } +} + ExternalFile::ExternalFile(fs::path nXmlPath, fs::path nOutPath) : xmlPath{nXmlPath}, outPath{nOutPath} { diff --git a/ZAPD/Globals.h b/ZAPD/Globals.h index 0fe8e05..c707c54 100644 --- a/ZAPD/Globals.h +++ b/ZAPD/Globals.h @@ -5,8 +5,7 @@ #include <vector> #include "GameConfig.h" #include "ZFile.h" -#include <ZRom.h> -#include <FileWorker.h> +#include "ExporterSet.h" class ZRoom; @@ -17,33 +16,6 @@ enum class VerbosityLevel VERBOSITY_DEBUG }; -typedef void (*ExporterSetFunc)(ZFile*); -typedef bool (*ExporterSetFuncBool)(ZFileMode fileMode); -typedef void (*ExporterSetFuncVoid)(int argc, char* argv[], int& i); -typedef void (*ExporterSetFuncVoid2)(const std::string& buildMode, ZFileMode& fileMode); -typedef void (*ExporterSetFuncVoid3)(); -typedef void (*ExporterSetFuncVoid4)(tinyxml2::XMLElement* reader); -typedef void (*ExporterSetResSave)(ZResource* res, BinaryWriter& writer); - -class ExporterSet -{ -public: - ~ExporterSet(); - - std::map<ZResourceType, ZResourceExporter*> exporters; - ExporterSetFuncVoid parseArgsFunc = nullptr; - ExporterSetFuncVoid2 parseFileModeFunc = nullptr; - ExporterSetFuncBool processFileModeFunc = nullptr; - ExporterSetFunc beginFileFunc = nullptr; - ExporterSetFunc endFileFunc = nullptr; - ExporterSetFuncVoid3 beginXMLFunc = nullptr; - ExporterSetFuncVoid3 endXMLFunc = nullptr; - ExporterSetResSave resSaveFunc = nullptr; - ExporterSetFuncVoid3 endProgramFunc = nullptr; - - ExporterSetFuncVoid4 processCompilableFunc = nullptr; -}; - class Globals { public: @@ -106,8 +78,14 @@ public: * in which case `declName` will be set to the address formatted as a pointer. */ bool GetSegmentedPtrName(segptr_t segAddress, ZFile* currentFile, - const std::string& expectedType, std::string& declName, int workerID); + const std::string& expectedType, std::string& declName, + int workerID, bool warnIfNotFound = true); bool GetSegmentedArrayIndexedName(segptr_t segAddress, size_t elementSize, ZFile* currentFile, - const std::string& expectedType, std::string& declName, int workerID); + const std::string& expectedType, std::string& declName, + int workerID, bool warnIfNotFound = true); + + // TODO: consider moving to another place + void WarnHardcodedPointer(segptr_t segAddress, ZFile* currentFile, ZResource* res, + offset_t currentOffset); }; diff --git a/ZAPD/Main.cpp b/ZAPD/Main.cpp index a2030aa..47f949e 100644 --- a/ZAPD/Main.cpp +++ b/ZAPD/Main.cpp @@ -1,9 +1,10 @@ #include "Globals.h" #include "Utils/Directory.h" -#include <Utils/DiskFile.h> +#include "Utils/File.h" #include "Utils/Path.h" #include "WarningHandler.h" +// Linker Hacks Begin #include "ZAnimation.h" ZNormalAnimation nAnim(nullptr); ZCurveAnimation cAnim(nullptr); @@ -67,10 +68,12 @@ ZVtx vtx(nullptr); #include "ZRoom/ZRoom.h" ZRoom room(nullptr); +// Linker Hacks End #include "ZFile.h" #include "ZTexture.h" +#include <functional> #include "CrashHandler.h" #include <string> @@ -78,24 +81,52 @@ ZRoom room(nullptr); #include "tinyxml2.h" #include <ctpl_stl.h> -//extern const char gBuildHash[]; const char gBuildHash[] = ""; +using ArgFunc = void (*)(int&, char**); + +void Arg_SetOutputPath(int& i, char* argv[]); +void Arg_SetInputPath(int& i, char* argv[]); +void Arg_SetBaseromPath(int& i, char* argv[]); +void Arg_SetSourceOutputPath(int& i, char* argv[]); +void Arg_GenerateSourceFile(int& i, char* argv[]); +void Arg_TestMode(int& i, char* argv[]); +void Arg_LegacyDList(int& i, char* argv[]); +void Arg_EnableProfiling(int& i, char* argv[]); +void Arg_UseExternalResources(int& i, char* argv[]); +void Arg_SetTextureType(int& i, char* argv[]); +void Arg_ReadConfigFile(int& i, char* argv[]); +void Arg_EnableErrorHandler(int& i, char* argv[]); +void Arg_SetVerbosity(int& i, char* argv[]); +void Arg_VerboseUnaccounted(int& i, char* argv[]); +void Arg_SetExporter(int& i, char* argv[]); +void Arg_EnableGCCCompat(int& i, char* argv[]); +void Arg_ForceStatic(int& i, char* argv[]); +void Arg_ForceUnaccountedStatic(int& i, char* argv[]); + +int main(int argc, char* argv[]); + bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath, ZFileMode fileMode, int workerID); +void ParseArgs(int& argc, char* argv[]); + void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath); void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath); void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath); +ZFileMode ParseFileMode(const std::string& buildMode, ExporterSet* exporterSet); +int HandleExtract(ZFileMode fileMode, ExporterSet* exporterSet); int ExtractFunc(int workerID, int fileListSize, std::string fileListItem, ZFileMode fileMode); volatile int numWorkersLeft = 0; +extern const char gBuildHash[]; + extern void ImportExporters(); extern "C" int zapd_main(int argc, char* argv[]) { - // Syntax: ZAPD.out [mode (btex/bovl/e)] (Arbritrary Number of Arguments) + int returnCode = 0; if (argc < 2) { @@ -124,108 +155,7 @@ extern "C" int zapd_main(int argc, char* argv[]) } } - // Parse other "commands" - for (int32_t i = 2; i < argc; i++) - { - std::string arg = argv[i]; - - if (arg == "-o" || arg == "--outputpath") // Set output path - { - Globals::Instance->outputPath = argv[++i]; - - if (Globals::Instance->sourceOutputPath == "") - Globals::Instance->sourceOutputPath = Globals::Instance->outputPath; - } - else if (arg == "-i" || arg == "--inputpath") // Set input path - { - Globals::Instance->inputPath = argv[++i]; - } - else if (arg == "-b" || arg == "--baserompath") // Set baserom path - { - Globals::Instance->baseRomPath = argv[++i]; - } - else if (arg == "-osf") // Set source output path - { - Globals::Instance->sourceOutputPath = argv[++i]; - } - else if (arg == "-gsf") // Generate source file during extraction - { - Globals::Instance->genSourceFile = std::string_view(argv[++i]) == "1"; - } - else if (arg == "-tm") // Test Mode (enables certain experimental features) - { - Globals::Instance->testMode = std::string_view(argv[++i]) == "1"; - } - else if (arg == "-crc" || - arg == "--output-crc") // Outputs a CRC file for each extracted texture. - { - Globals::Instance->testMode = std::string_view(argv[++i]) == "1"; - } - else if (arg == "-ulzdl") // Use Legacy ZDisplay List - { - Globals::Instance->useLegacyZDList = std::string_view(argv[++i]) == "1"; - } - else if (arg == "-profile") // Enable profiling - { - Globals::Instance->profile = std::string_view(argv[++i]) == "1"; - } - else if (arg == - "-uer") // Split resources into their individual components (enabled by default) - // TODO: We may wish to make this a part of the config file... - { - Globals::Instance->useExternalResources = std::string_view(argv[++i]) == "1"; - } - else if (arg == "-tt") // Set texture type - { - Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[++i]); - } - else if (arg == "-fl") // Set baserom filelist path - { - Globals::Instance->fileListPath = argv[++i]; - } - else if (arg == "-rconf") // Read Config File - { - Globals::Instance->cfg.ReadConfigFile(argv[++i]); - } - else if (arg == "-eh") // Enable Error Handler - { - CrashHandler_Init(); - } - else if (arg == "-v") // Verbose - { - Globals::Instance->verbosity = static_cast<VerbosityLevel>(strtol(argv[++i], NULL, 16)); - } - else if (arg == "-vu" || arg == "--verbose-unaccounted") // Verbose unaccounted - { - Globals::Instance->verboseUnaccounted = true; - } - else if (arg == "-se" || arg == "--set-exporter") // Set Current Exporter - { - ImportExporters(); - Globals::Instance->currentExporter = argv[++i]; - } - else if (arg == "--gcc-compat") // GCC compatibility - { - Globals::Instance->gccCompat = true; - } - else if (arg == "-s" || arg == "--static") - { - Globals::Instance->forceStatic = true; - } - else if (arg == "-us" || arg == "--unaccounted-static") - { - Globals::Instance->forceUnaccountedStatic = true; - } - else if (arg == "-brt" || arg == "--build-raw-texture") - { - Globals::Instance->buildRawTexture = true; - } - else if (arg == "--norom") - { - Globals::Instance->onlyGenSohOtr = true; - } - } - + ParseArgs(argc, argv); // Parse File Mode ExporterSet* exporterSet = Globals::Instance->GetExporterSet(); @@ -238,22 +168,7 @@ extern "C" int zapd_main(int argc, char* argv[]) } std::string buildMode = argv[1]; - ZFileMode fileMode = ZFileMode::Invalid; - - if (buildMode == "btex") - fileMode = ZFileMode::BuildTexture; - else if (buildMode == "bren") - fileMode = ZFileMode::BuildBackground; - else if (buildMode == "bsf") - fileMode = ZFileMode::BuildSourceFile; - else if (buildMode == "bblb") - fileMode = ZFileMode::BuildBlob; - else if (buildMode == "e") - fileMode = ZFileMode::Extract; - else if (buildMode == "ed") - fileMode = ZFileMode::ExtractDirectory; - else if (exporterSet != nullptr && exporterSet->parseFileModeFunc != nullptr) - exporterSet->parseFileModeFunc(buildMode, fileMode); + ZFileMode fileMode = ParseFileMode(buildMode, exporterSet); if (fileMode == ZFileMode::Invalid) { @@ -268,7 +183,6 @@ extern "C" int zapd_main(int argc, char* argv[]) // We've parsed through our commands once. If an exporter exists, it's been set by now. // Now we'll parse through them again but pass them on to our exporter if one is available. - if (exporterSet != nullptr && exporterSet->parseArgsFunc != nullptr) { for (int32_t i = 2; i < argc; i++) @@ -279,125 +193,20 @@ extern "C" int zapd_main(int argc, char* argv[]) printf("ZAPD: Zelda Asset Processor For Decomp: %s\n", gBuildHash); if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG) - { WarningHandler::PrintWarningsDebugInfo(); - } - // TODO: switch if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile || fileMode == ZFileMode::ExtractDirectory) - { - bool procFileModeSuccess = false; - - if (exporterSet != nullptr && exporterSet->processFileModeFunc != nullptr) - procFileModeSuccess = exporterSet->processFileModeFunc(fileMode); - - if (!procFileModeSuccess) - { - if (fileMode == ZFileMode::ExtractDirectory) - { - std::vector<std::string> fileList = - Directory::ListFiles(Globals::Instance->inputPath.string()); - - const int num_threads = std::thread::hardware_concurrency(); - ctpl::thread_pool pool(num_threads > 1 ? num_threads / 2 : 1); - - bool parseSuccessful; - - auto start = std::chrono::steady_clock::now(); - int fileListSize = fileList.size(); - Globals::Instance->singleThreaded = false; - - for (int i = 0; i < fileListSize; i++) - Globals::Instance->workerData[i] = new FileWorker(); - - numWorkersLeft = fileListSize; - - for (int i = 0; i < fileListSize; i++) - { - if (Globals::Instance->singleThreaded) - { - ExtractFunc(i, fileList.size(), fileList[i], fileMode); - } - else - { - std::string fileListItem = fileList[i]; - pool.push([i, fileListSize, fileListItem, fileMode](int) { - ExtractFunc(i, fileListSize, fileListItem, fileMode); - }); - } - } - - if (!Globals::Instance->singleThreaded) - { - while (true) - { - if (numWorkersLeft <= 0) - break; - - std::this_thread::sleep_for(std::chrono::milliseconds(250)); - } - } - - auto end = std::chrono::steady_clock::now(); - auto diff = - std::chrono::duration_cast<std::chrono::seconds>(end - start).count(); - - printf("Generated OTR File Data in %i seconds\n", diff); - } - else - { - bool parseSuccessful; - - for (auto& extFile : Globals::Instance->cfg.externalFiles) - { - fs::path externalXmlFilePath = - Globals::Instance->cfg.externalXmlFolder / extFile.xmlPath; - - if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO) - { - printf("Parsing external file from config: '%s'\n", - externalXmlFilePath.c_str()); - } - - parseSuccessful = Parse(externalXmlFilePath, Globals::Instance->baseRomPath, - extFile.outPath, ZFileMode::ExternalFile, 0); - - if (!parseSuccessful) - return 1; - } - - parseSuccessful = - Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath, - Globals::Instance->outputPath, fileMode, 0); - if (!parseSuccessful) - return 1; - } - } - } + returnCode = HandleExtract(fileMode, exporterSet); else if (fileMode == ZFileMode::BuildTexture) - { - TextureType texType = Globals::Instance->texType; - BuildAssetTexture(Globals::Instance->inputPath, texType, Globals::Instance->outputPath); - } + BuildAssetTexture(Globals::Instance->inputPath, Globals::Instance->texType, + Globals::Instance->outputPath); else if (fileMode == ZFileMode::BuildBackground) - { BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath); - } else if (fileMode == ZFileMode::BuildBlob) - { BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath); - } - - if (exporterSet != nullptr && exporterSet->endProgramFunc != nullptr) - exporterSet->endProgramFunc(); - -end: - delete exporterSet; - - //Globals::Instance->GetExporterSet() = nullptr; //TODO NULL this out. Compiler complains about lvalue assignment. delete g; - return 0; + return returnCode; } int ExtractFunc(int workerID, int fileListSize, std::string fileListItem, ZFileMode fileMode) @@ -568,6 +377,209 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path return true; } +void ParseArgs(int& argc, char* argv[]) +{ + static const std::unordered_map<std::string, ArgFunc> ArgFuncDictionary = { + {"-o", &Arg_SetOutputPath}, + {"--outputpath", &Arg_SetOutputPath}, + {"-i", &Arg_SetInputPath}, + {"--inputpath", &Arg_SetInputPath}, + {"-b", &Arg_SetBaseromPath}, + {"--baserompath", &Arg_SetBaseromPath}, + {"-osf", &Arg_SetSourceOutputPath}, + {"-gsf", &Arg_GenerateSourceFile}, + {"-tm", &Arg_TestMode}, + {"-ulzdl", &Arg_LegacyDList}, + {"-profile", &Arg_EnableProfiling}, + {"-uer", &Arg_UseExternalResources}, + {"-tt", &Arg_SetTextureType}, + {"-rconf", &Arg_ReadConfigFile}, + {"-eh", &Arg_EnableErrorHandler}, + {"-v", &Arg_SetVerbosity}, + {"-vu", &Arg_VerboseUnaccounted}, + {"--verbose-unaccounted", &Arg_VerboseUnaccounted}, + {"-se", &Arg_SetExporter}, + {"--set-exporter", &Arg_SetExporter}, + {"--gcc-compat", &Arg_EnableGCCCompat}, + {"-s", &Arg_ForceStatic}, + {"--static", &Arg_ForceStatic}, + {"-us", &Arg_ForceUnaccountedStatic}, + {"--unaccounted-static", &Arg_ForceUnaccountedStatic}, + }; + + for (int32_t i = 2; i < argc; i++) + { + std::string arg = argv[i]; + + // Ignore warning args as they have already been parsed + if (arg.length() > 2 && arg[0] == '-' && arg[1] == 'W' && arg[2] != '\0') + { + continue; + } + + auto it = ArgFuncDictionary.find(arg); + if (it == ArgFuncDictionary.end()) + { + fprintf(stderr, "Unsupported argument: %s\n", arg.c_str()); + continue; + } + + std::invoke(it->second, i, argv); + } +} + +ZFileMode ParseFileMode(const std::string& buildMode, ExporterSet* exporterSet) +{ + ZFileMode fileMode = ZFileMode::Invalid; + + if (buildMode == "btex") + fileMode = ZFileMode::BuildTexture; + else if (buildMode == "bren") + fileMode = ZFileMode::BuildBackground; + else if (buildMode == "bsf") + fileMode = ZFileMode::BuildSourceFile; + else if (buildMode == "bblb") + fileMode = ZFileMode::BuildBlob; + else if (buildMode == "e") + fileMode = ZFileMode::Extract; + else if (exporterSet != nullptr && exporterSet->parseFileModeFunc != nullptr) + exporterSet->parseFileModeFunc(buildMode, fileMode); + + return fileMode; +} + +void Arg_SetOutputPath(int& i, [[maybe_unused]] char* argv[]) +{ + Globals::Instance->outputPath = argv[++i]; + + if (Globals::Instance->sourceOutputPath == "") + Globals::Instance->sourceOutputPath = Globals::Instance->outputPath; +} + +void Arg_SetInputPath(int& i, char* argv[]) +{ + Globals::Instance->inputPath = argv[++i]; +} + +void Arg_SetBaseromPath(int& i, char* argv[]) +{ + Globals::Instance->baseRomPath = argv[++i]; +} + +void Arg_SetSourceOutputPath(int& i, char* argv[]) +{ + Globals::Instance->sourceOutputPath = argv[++i]; +} + +void Arg_GenerateSourceFile(int& i, char* argv[]) +{ + // Generate source file during extraction + Globals::Instance->genSourceFile = std::string_view(argv[++i]) == "1"; +} + +void Arg_TestMode(int& i, char* argv[]) +{ + // Test Mode (enables certain experimental features) + Globals::Instance->testMode = std::string_view(argv[++i]) == "1"; +} + +void Arg_LegacyDList(int& i, char* argv[]) +{ + Globals::Instance->useLegacyZDList = std::string_view(argv[++i]) == "1"; +} + +void Arg_EnableProfiling(int& i, char* argv[]) +{ + Globals::Instance->profile = std::string_view(argv[++i]) == "1"; +} + +void Arg_UseExternalResources(int& i, char* argv[]) +{ + // Split resources into their individual components(enabled by default) + // TODO: We may wish to make this a part of the config file... + Globals::Instance->useExternalResources = std::string_view(argv[++i]) == "1"; +} + +void Arg_SetTextureType(int& i, char* argv[]) +{ + Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[++i]); +} + +void Arg_ReadConfigFile(int& i, char* argv[]) +{ + Globals::Instance->cfg.ReadConfigFile(argv[++i]); +} + +void Arg_EnableErrorHandler([[maybe_unused]] int& i, [[maybe_unused]] char* argv[]) +{ + CrashHandler_Init(); +} + +void Arg_SetVerbosity(int& i, char* argv[]) +{ + Globals::Instance->verbosity = static_cast<VerbosityLevel>(strtol(argv[++i], NULL, 16)); +} + +void Arg_VerboseUnaccounted([[maybe_unused]] int& i, [[maybe_unused]] char* argv[]) +{ + Globals::Instance->verboseUnaccounted = true; +} + +void Arg_SetExporter(int& i, char* argv[]) +{ + Globals::Instance->currentExporter = argv[++i]; +} + +void Arg_EnableGCCCompat([[maybe_unused]] int& i, [[maybe_unused]] char* argv[]) +{ + Globals::Instance->gccCompat = true; +} + +void Arg_ForceStatic([[maybe_unused]] int& i, [[maybe_unused]] char* argv[]) +{ + Globals::Instance->forceStatic = true; +} + +void Arg_ForceUnaccountedStatic([[maybe_unused]] int& i, [[maybe_unused]] char* argv[]) +{ + Globals::Instance->forceUnaccountedStatic = true; +} + +int HandleExtract(ZFileMode fileMode, ExporterSet* exporterSet) +{ + bool procFileModeSuccess = false; + + if (exporterSet != nullptr && exporterSet->processFileModeFunc != nullptr) + procFileModeSuccess = exporterSet->processFileModeFunc(fileMode); + + if (!procFileModeSuccess) + { + bool parseSuccessful; + + for (auto& extFile : Globals::Instance->cfg.externalFiles) + { + fs::path externalXmlFilePath = + Globals::Instance->cfg.externalXmlFolder / extFile.xmlPath; + + if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO) + printf("Parsing external file from config: '%s'\n", externalXmlFilePath.c_str()); + + parseSuccessful = Parse(externalXmlFilePath, Globals::Instance->baseRomPath, + extFile.outPath, ZFileMode::ExternalFile); + + if (!parseSuccessful) + return 1; + } + + parseSuccessful = Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath, + Globals::Instance->outputPath, fileMode); + if (!parseSuccessful) + return 1; + } + + return 0; +} + void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath) { return Globals::Instance->BuildAssetTexture(pngFilePath, texType, outPath); diff --git a/ZAPD/OtherStructs/CutsceneMM_Commands.cpp b/ZAPD/OtherStructs/CutsceneMM_Commands.cpp index edefbc0..85fce22 100644 --- a/ZAPD/OtherStructs/CutsceneMM_Commands.cpp +++ b/ZAPD/OtherStructs/CutsceneMM_Commands.cpp @@ -1,40 +1,46 @@ #include "CutsceneMM_Commands.h" -#include <cassert> #include <unordered_map> - +#include "Globals.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" +/**** GENERIC ****/ + // Specific for command lists where each entry has size 8 bytes -const std::unordered_map<CutsceneMMCommands, CsCommandListDescriptor> 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)"}}, +const std::unordered_map<CutsceneMM_CommandType, CsCommandListDescriptor> csCommandsDescMM = { + {CutsceneMM_CommandType::CS_CMD_MISC, {"CS_MISC", "(%s, %i, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_LIGHT_SETTING, {"CS_LIGHT_SETTING", "(0x%02X, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_TRANSITION, {"CS_TRANSITION", "(%s, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_MOTION_BLUR, {"CS_MOTION_BLUR", "(%s, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_GIVE_TATL, {"CS_GIVE_TATL", "(%s, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_START_SEQ, {"CS_START_SEQ", "(0x%04X, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_SFX_REVERB_INDEX_2, + {"CS_SFX_REVERB_INDEX_2", "(0x%04X, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_SFX_REVERB_INDEX_1, + {"CS_SFX_REVERB_INDEX_1", "(0x%04X, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_MODIFY_SEQ, {"CS_MODIFY_SEQ", "(%s, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_STOP_SEQ, {"CS_STOP_SEQ", "(0x%04X, %i, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_START_AMBIENCE, {"CS_START_AMBIENCE", "(0x%04X, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_FADE_OUT_AMBIENCE, + {"CS_FADE_OUT_AMBIENCE", "(0x%04X, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_DESTINATION, {"CS_DESTINATION", "(%s, %i, %i)"}}, + {CutsceneMM_CommandType::CS_CMD_CHOOSE_CREDITS_SCENES, + {"CS_CHOOSE_CREDITS_SCENES", "(%s, %i, %i)"}}, }; -CutsceneSubCommandEntry_GenericMMCmd::CutsceneSubCommandEntry_GenericMMCmd( - const std::vector<uint8_t>& rawData, offset_t rawDataIndex, CutsceneMMCommands cmdId) +CutsceneMMSubCommandEntry_GenericCmd::CutsceneMMSubCommandEntry_GenericCmd( + const std::vector<uint8_t>& rawData, offset_t rawDataIndex, CutsceneMM_CommandType cmdId) : CutsceneSubCommandEntry(rawData, rawDataIndex), commandId(cmdId) { } -std::string CutsceneSubCommandEntry_GenericMMCmd::GetBodySourceCode() const +std::string CutsceneMMSubCommandEntry_GenericCmd::GetBodySourceCode() const { + EnumData* enumData = &Globals::Instance->cfg.enumData; const auto& element = csCommandsDescMM.find(commandId); std::string entryFmt = "CS_UNK_DATA(0x%02X, %i, %i, %i)"; + std::string type = ""; if (element != csCommandsDescMM.end()) { @@ -42,12 +48,49 @@ std::string CutsceneSubCommandEntry_GenericMMCmd::GetBodySourceCode() const entryFmt += element->second.args; } + if (commandId == CutsceneMM_CommandType::CS_CMD_MISC && + enumData->miscType.find(base) != enumData->miscType.end()) + type = enumData->miscType[base]; + + else if (commandId == CutsceneMM_CommandType::CS_CMD_TRANSITION && + enumData->transitionType.find(base) != enumData->transitionType.end()) + type = enumData->transitionType[base]; + + else if (commandId == CutsceneMM_CommandType::CS_CMD_MOTION_BLUR && + enumData->motionBlurType.find(base) != enumData->motionBlurType.end()) + type = enumData->motionBlurType[base]; + + else if (commandId == CutsceneMM_CommandType::CS_CMD_MODIFY_SEQ && + enumData->modifySeqType.find(base) != enumData->modifySeqType.end()) + type = enumData->modifySeqType[base]; + + else if (commandId == CutsceneMM_CommandType::CS_CMD_DESTINATION && + enumData->destinationType.find(base) != enumData->destinationType.end()) + type = enumData->destinationType[base]; + + else if (commandId == CutsceneMM_CommandType::CS_CMD_CHOOSE_CREDITS_SCENES && + enumData->chooseCreditsSceneType.find(base) != enumData->chooseCreditsSceneType.end()) + type = enumData->chooseCreditsSceneType[base]; + + else if (commandId == CutsceneMM_CommandType::CS_CMD_GIVE_TATL) + type = base ? "true" : "false"; + + if (type != "") + return StringHelper::Sprintf(entryFmt.c_str(), type.c_str(), startFrame, endFrame, pad); + + if (commandId == CutsceneMM_CommandType::CS_CMD_LIGHT_SETTING || + commandId == CutsceneMM_CommandType::CS_CMD_START_SEQ || + commandId == CutsceneMM_CommandType::CS_CMD_STOP_SEQ) + { + return StringHelper::Sprintf(entryFmt.c_str(), base - 1, startFrame, endFrame, pad); + } + return StringHelper::Sprintf(entryFmt.c_str(), base, startFrame, endFrame, pad); } CutsceneMMCommand_GenericCmd::CutsceneMMCommand_GenericCmd(const std::vector<uint8_t>& rawData, offset_t rawDataIndex, - CutsceneMMCommands cmdId) + CutsceneMM_CommandType cmdId) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; @@ -57,7 +100,7 @@ CutsceneMMCommand_GenericCmd::CutsceneMMCommand_GenericCmd(const std::vector<uin entries.reserve(numEntries); for (size_t i = 0; i < numEntries; i++) { - auto* entry = new CutsceneSubCommandEntry_GenericMMCmd(rawData, rawDataIndex, cmdId); + auto* entry = new CutsceneMMSubCommandEntry_GenericCmd(rawData, rawDataIndex, cmdId); entries.push_back(entry); rawDataIndex += entry->GetRawSize(); } @@ -65,7 +108,7 @@ CutsceneMMCommand_GenericCmd::CutsceneMMCommand_GenericCmd(const std::vector<uin std::string CutsceneMMCommand_GenericCmd::GetCommandMacro() const { - const auto& element = csCommandsDescMM.find(static_cast<CutsceneMMCommands>(commandID)); + const auto& element = csCommandsDescMM.find(static_cast<CutsceneMM_CommandType>(commandID)); if (element != csCommandsDescMM.end()) { @@ -75,6 +118,8 @@ std::string CutsceneMMCommand_GenericCmd::GetCommandMacro() const return StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%X, %i)", commandID, numEntries); } +/**** CAMERA ****/ + CutsceneSubCommandEntry_Camera::CutsceneSubCommandEntry_Camera(const std::vector<uint8_t>& rawData, offset_t rawDataIndex) : CutsceneSubCommandEntry(rawData, rawDataIndex) @@ -108,10 +153,12 @@ CutsceneMMCommand_Camera::CutsceneMMCommand_Camera(const std::vector<uint8_t>& r std::string CutsceneMMCommand_Camera::GetCommandMacro() const { - return StringHelper::Sprintf("CS_CAMERA_LIST(%i)", numEntries); + return StringHelper::Sprintf("CS_CAM_SPLINE_LIST(%i)", numEntries); } -CutsceneSubCommandEntry_FadeScreen::CutsceneSubCommandEntry_FadeScreen( +/**** TRANSITION GENERAL ****/ + +CutsceneSubCommandEntry_TransitionGeneral::CutsceneSubCommandEntry_TransitionGeneral( const std::vector<uint8_t>& rawData, offset_t rawDataIndex) : CutsceneSubCommandEntry(rawData, rawDataIndex) { @@ -123,19 +170,26 @@ CutsceneSubCommandEntry_FadeScreen::CutsceneSubCommandEntry_FadeScreen( unk_0B = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x0B); } -std::string CutsceneSubCommandEntry_FadeScreen::GetBodySourceCode() const +std::string CutsceneSubCommandEntry_TransitionGeneral::GetBodySourceCode() const { - return StringHelper::Sprintf("CS_FADESCREEN(0x%02X, %i, %i, %i, %i, %i)", base, startFrame, - endFrame, unk_06, unk_07, unk_08); + EnumData* enumData = &Globals::Instance->cfg.enumData; + + if (enumData->transitionGeneralType.find(base) != enumData->transitionGeneralType.end()) + return StringHelper::Sprintf("CS_TRANSITION_GENERAL(%s, %i, %i, %i, %i, %i)", + enumData->transitionGeneralType[base].c_str(), startFrame, + endFrame, unk_06, unk_07, unk_08); + + return StringHelper::Sprintf("CS_TRANSITION_GENERAL(0x%02X, %i, %i, %i, %i, %i)", base, + startFrame, endFrame, unk_06, unk_07, unk_08); } -size_t CutsceneSubCommandEntry_FadeScreen::GetRawSize() const +size_t CutsceneSubCommandEntry_TransitionGeneral::GetRawSize() const { return 0x0C; } -CutsceneMMCommand_FadeScreen::CutsceneMMCommand_FadeScreen(const std::vector<uint8_t>& rawData, - offset_t rawDataIndex) +CutsceneMMCommand_TransitionGeneral::CutsceneMMCommand_TransitionGeneral( + const std::vector<uint8_t>& rawData, offset_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; @@ -143,36 +197,45 @@ CutsceneMMCommand_FadeScreen::CutsceneMMCommand_FadeScreen(const std::vector<uin entries.reserve(numEntries); for (size_t i = 0; i < numEntries; i++) { - auto* entry = new CutsceneSubCommandEntry_FadeScreen(rawData, rawDataIndex); + auto* entry = new CutsceneSubCommandEntry_TransitionGeneral(rawData, rawDataIndex); entries.push_back(entry); rawDataIndex += entry->GetRawSize(); } } -std::string CutsceneMMCommand_FadeScreen::GetCommandMacro() const +std::string CutsceneMMCommand_TransitionGeneral::GetCommandMacro() const { - return StringHelper::Sprintf("CS_FADESCREEN_LIST(%i)", numEntries); + return StringHelper::Sprintf("CS_TRANSITION_GENERAL_LIST(%i)", numEntries); } -CutsceneSubCommandEntry_FadeSeq::CutsceneSubCommandEntry_FadeSeq( +CutsceneSubCommandEntry_FadeOutSeq::CutsceneSubCommandEntry_FadeOutSeq( const std::vector<uint8_t>& rawData, offset_t rawDataIndex) : CutsceneSubCommandEntry(rawData, rawDataIndex) { unk_08 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); } -std::string CutsceneSubCommandEntry_FadeSeq::GetBodySourceCode() const +/**** FADE OUT SEQUENCE ****/ + +std::string CutsceneSubCommandEntry_FadeOutSeq::GetBodySourceCode() const { - return StringHelper::Sprintf("CS_FADESEQ(%i, %i, %i)", base, startFrame, endFrame); + EnumData* enumData = &Globals::Instance->cfg.enumData; + + if (enumData->fadeOutSeqPlayer.find(base) != enumData->fadeOutSeqPlayer.end()) + return StringHelper::Sprintf("CS_FADE_OUT_SEQ(%s, %i, %i)", + enumData->fadeOutSeqPlayer[base].c_str(), startFrame, + endFrame); + + return StringHelper::Sprintf("CS_FADE_OUT_SEQ(%i, %i, %i)", base, startFrame, endFrame); } -size_t CutsceneSubCommandEntry_FadeSeq::GetRawSize() const +size_t CutsceneSubCommandEntry_FadeOutSeq::GetRawSize() const { return 0x0C; } -CutsceneMMCommand_FadeSeq::CutsceneMMCommand_FadeSeq(const std::vector<uint8_t>& rawData, - offset_t rawDataIndex) +CutsceneMMCommand_FadeOutSeq::CutsceneMMCommand_FadeOutSeq(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; @@ -180,17 +243,19 @@ CutsceneMMCommand_FadeSeq::CutsceneMMCommand_FadeSeq(const std::vector<uint8_t>& entries.reserve(numEntries); for (size_t i = 0; i < numEntries; i++) { - auto* entry = new CutsceneSubCommandEntry_FadeSeq(rawData, rawDataIndex); + auto* entry = new CutsceneSubCommandEntry_FadeOutSeq(rawData, rawDataIndex); entries.push_back(entry); rawDataIndex += entry->GetRawSize(); } } -std::string CutsceneMMCommand_FadeSeq::GetCommandMacro() const +std::string CutsceneMMCommand_FadeOutSeq::GetCommandMacro() const { - return StringHelper::Sprintf("CS_FADESEQ_LIST(%i)", numEntries); + return StringHelper::Sprintf("CS_FADE_OUT_SEQ_LIST(%i)", numEntries); } +/**** NON IMPLEMENTED ****/ + CutsceneSubCommandEntry_NonImplemented::CutsceneSubCommandEntry_NonImplemented( const std::vector<uint8_t>& rawData, offset_t rawDataIndex) : CutsceneSubCommandEntry(rawData, rawDataIndex) @@ -211,3 +276,207 @@ CutsceneMMCommand_NonImplemented::CutsceneMMCommand_NonImplemented( rawDataIndex += entry->GetRawSize(); } } + +/**** RUMBLE ****/ + +CutsceneMMSubCommandEntry_Rumble::CutsceneMMSubCommandEntry_Rumble( + const std::vector<uint8_t>& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + intensity = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x06); + decayTimer = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x07); + decayStep = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08); +} + +std::string CutsceneMMSubCommandEntry_Rumble::GetBodySourceCode() const +{ + EnumData* enumData = &Globals::Instance->cfg.enumData; + + if (enumData->rumbleType.find(base) != enumData->rumbleType.end()) + return StringHelper::Sprintf("CS_RUMBLE(%s, %i, %i, 0x%02X, 0x%02X, 0x%02X)", + enumData->rumbleType[base].c_str(), startFrame, endFrame, + intensity, decayTimer, decayStep); + + return StringHelper::Sprintf("CS_RUMBLE(0x%04X, %i, %i, 0x%02X, 0x%02X, 0x%02X)", base, + startFrame, endFrame, intensity, decayTimer, decayStep); +} + +size_t CutsceneMMSubCommandEntry_Rumble::GetRawSize() const +{ + return 0x0C; +} + +CutsceneMMCommand_Rumble::CutsceneMMCommand_Rumble(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + entries.reserve(numEntries); + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneMMSubCommandEntry_Rumble(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneMMCommand_Rumble::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_RUMBLE_LIST(%i)", numEntries); +} + +/**** TEXT ****/ + +CutsceneMMSubCommandEntry_Text::CutsceneMMSubCommandEntry_Text(const std::vector<uint8_t>& 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 CutsceneMMSubCommandEntry_Text::GetBodySourceCode() const +{ + if (type == 0xFFFF) + { + return StringHelper::Sprintf("CS_TEXT_NONE(%i, %i)", startFrame, endFrame); + } + + if (type == 2) + { + // TODO: set the enum name when it will be documented + // (https://github.com/Decompollaborate/mm/blob/3e1c568c084671c17836ced904714ea49d989621/include/z64ocarina.h#L35-L118) + return StringHelper::Sprintf("CS_TEXT_OCARINA_ACTION(%i, %i, %i, 0x%X)", base, startFrame, + endFrame, textId1); + } + + 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 nullptr; +} + +size_t CutsceneMMSubCommandEntry_Text::GetRawSize() const +{ + return 0x0C; +} + +CutsceneMMCommand_Text::CutsceneMMCommand_Text(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + entries.reserve(numEntries); + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneMMSubCommandEntry_Text(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneMMCommand_Text::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_TEXT_LIST(%i)", numEntries); +} + +/**** ACTOR CUE ****/ + +CutsceneMMSubCommandEntry_ActorCue::CutsceneMMSubCommandEntry_ActorCue( + const std::vector<uint8_t>& 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 CutsceneMMSubCommandEntry_ActorCue::GetBodySourceCode() const +{ + std::string result; + + if (static_cast<CutsceneMM_CommandType>(commandID) == CutsceneMM_CommandType::CS_CMD_PLAYER_CUE) + { + result = "CS_PLAYER_CUE"; + } + else + { + result = "CS_ACTOR_CUE"; + } + + result += + StringHelper::Sprintf("(%i, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, " + "%i, %i, %i, %i, %.8ef, %.8ef, %.8ef)", + base, startFrame, endFrame, rotX, rotY, rotZ, startPosX, startPosY, + startPosZ, endPosX, endPosY, endPosZ, normalX, normalY, normalZ); + return result; +} + +size_t CutsceneMMSubCommandEntry_ActorCue::GetRawSize() const +{ + return 0x30; +} + +CutsceneMMCommand_ActorCue::CutsceneMMCommand_ActorCue(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + entries.reserve(numEntries); + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneMMSubCommandEntry_ActorCue(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneMMCommand_ActorCue::GetCommandMacro() const +{ + EnumData* enumData = &Globals::Instance->cfg.enumData; + + if (static_cast<CutsceneMM_CommandType>(commandID) == CutsceneMM_CommandType::CS_CMD_PLAYER_CUE) + { + return StringHelper::Sprintf("CS_PLAYER_CUE_LIST(%i)", numEntries); + } + + if (enumData->cutsceneCmd.find(commandID) != enumData->cutsceneCmd.end()) + { + return StringHelper::Sprintf("CS_ACTOR_CUE_LIST(%s, %i)", + enumData->cutsceneCmd[commandID].c_str(), numEntries); + } + return StringHelper::Sprintf("CS_ACTOR_CUE_LIST(0x%03X, %i)", commandID, numEntries); +} diff --git a/ZAPD/OtherStructs/CutsceneMM_Commands.h b/ZAPD/OtherStructs/CutsceneMM_Commands.h index c8ae4eb..fb2f772 100644 --- a/ZAPD/OtherStructs/CutsceneMM_Commands.h +++ b/ZAPD/OtherStructs/CutsceneMM_Commands.h @@ -1,51 +1,256 @@ #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, +#include "Cutscene_Common.h" + +// https://github.com/zeldaret/mm/blob/0c7b90cf97f26483c8b6a98ae099a295f61e72ab/include/z64cutscene.h#L294-530 +enum class CutsceneMM_CommandType +{ + /* -2 */ CS_CMD_ACTOR_CUE_POST_PROCESS = -2, + /* -1 */ CS_CAM_STOP, + /* 0x00A */ CS_CMD_TEXT = 10, + /* 0x05A */ CS_CMD_CAMERA_SPLINE = 90, + /* 0x064 */ CS_CMD_ACTOR_CUE_100 = 100, + /* 0x065 */ CS_CMD_ACTOR_CUE_101, + /* 0x066 */ CS_CMD_ACTOR_CUE_102, + /* 0x067 */ CS_CMD_ACTOR_CUE_103, + /* 0x068 */ CS_CMD_ACTOR_CUE_104, + /* 0x069 */ CS_CMD_ACTOR_CUE_105, + /* 0x06A */ CS_CMD_ACTOR_CUE_106, + /* 0x06B */ CS_CMD_ACTOR_CUE_107, + /* 0x06C */ CS_CMD_ACTOR_CUE_108, + /* 0x06D */ CS_CMD_ACTOR_CUE_109, + /* 0x06E */ CS_CMD_ACTOR_CUE_110, + /* 0x06F */ CS_CMD_ACTOR_CUE_111, + /* 0x070 */ CS_CMD_ACTOR_CUE_112, + /* 0x071 */ CS_CMD_ACTOR_CUE_113, + /* 0x072 */ CS_CMD_ACTOR_CUE_114, + /* 0x073 */ CS_CMD_ACTOR_CUE_115, + /* 0x074 */ CS_CMD_ACTOR_CUE_116, + /* 0x075 */ CS_CMD_ACTOR_CUE_117, + /* 0x076 */ CS_CMD_ACTOR_CUE_118, + /* 0x077 */ CS_CMD_ACTOR_CUE_119, + /* 0x078 */ CS_CMD_ACTOR_CUE_120, + /* 0x079 */ CS_CMD_ACTOR_CUE_121, + /* 0x07A */ CS_CMD_ACTOR_CUE_122, + /* 0x07B */ CS_CMD_ACTOR_CUE_123, + /* 0x07C */ CS_CMD_ACTOR_CUE_124, + /* 0x07D */ CS_CMD_ACTOR_CUE_125, + /* 0x07E */ CS_CMD_ACTOR_CUE_126, + /* 0x07F */ CS_CMD_ACTOR_CUE_127, + /* 0x080 */ CS_CMD_ACTOR_CUE_128, + /* 0x081 */ CS_CMD_ACTOR_CUE_129, + /* 0x082 */ CS_CMD_ACTOR_CUE_130, + /* 0x083 */ CS_CMD_ACTOR_CUE_131, + /* 0x084 */ CS_CMD_ACTOR_CUE_132, + /* 0x085 */ CS_CMD_ACTOR_CUE_133, + /* 0x086 */ CS_CMD_ACTOR_CUE_134, + /* 0x087 */ CS_CMD_ACTOR_CUE_135, + /* 0x088 */ CS_CMD_ACTOR_CUE_136, + /* 0x089 */ CS_CMD_ACTOR_CUE_137, + /* 0x08A */ CS_CMD_ACTOR_CUE_138, + /* 0x08B */ CS_CMD_ACTOR_CUE_139, + /* 0x08C */ CS_CMD_ACTOR_CUE_140, + /* 0x08D */ CS_CMD_ACTOR_CUE_141, + /* 0x08E */ CS_CMD_ACTOR_CUE_142, + /* 0x08F */ CS_CMD_ACTOR_CUE_143, + /* 0x090 */ CS_CMD_ACTOR_CUE_144, + /* 0x091 */ CS_CMD_ACTOR_CUE_145, + /* 0x092 */ CS_CMD_ACTOR_CUE_146, + /* 0x093 */ CS_CMD_ACTOR_CUE_147, + /* 0x094 */ CS_CMD_ACTOR_CUE_148, + /* 0x095 */ CS_CMD_ACTOR_CUE_149, + /* 0x096 */ CS_CMD_MISC, + /* 0x097 */ CS_CMD_LIGHT_SETTING, + /* 0x098 */ CS_CMD_TRANSITION, + /* 0x099 */ CS_CMD_MOTION_BLUR, + /* 0x09A */ CS_CMD_GIVE_TATL, + /* 0x09B */ CS_CMD_TRANSITION_GENERAL, + /* 0x09C */ CS_CMD_FADE_OUT_SEQ, + /* 0x09D */ CS_CMD_TIME, + /* 0x0C8 */ CS_CMD_PLAYER_CUE = 200, + /* 0x0C9 */ CS_CMD_ACTOR_CUE_201, + /* 0x0FA */ CS_CMD_UNK_DATA_FA = 0xFA, + /* 0x0FE */ CS_CMD_UNK_DATA_FE = 0xFE, + /* 0x0FF */ CS_CMD_UNK_DATA_FF, + /* 0x100 */ CS_CMD_UNK_DATA_100, + /* 0x101 */ CS_CMD_UNK_DATA_101, + /* 0x102 */ CS_CMD_UNK_DATA_102, + /* 0x103 */ CS_CMD_UNK_DATA_103, + /* 0x104 */ CS_CMD_UNK_DATA_104, + /* 0x105 */ CS_CMD_UNK_DATA_105, + /* 0x108 */ CS_CMD_UNK_DATA_108 = 0x108, + /* 0x109 */ CS_CMD_UNK_DATA_109, + /* 0x12C */ CS_CMD_START_SEQ = 300, + /* 0x12D */ CS_CMD_STOP_SEQ, + /* 0x12E */ CS_CMD_START_AMBIENCE, + /* 0x12F */ CS_CMD_FADE_OUT_AMBIENCE, + /* 0x130 */ CS_CMD_SFX_REVERB_INDEX_2, + /* 0x131 */ CS_CMD_SFX_REVERB_INDEX_1, + /* 0x132 */ CS_CMD_MODIFY_SEQ, + /* 0x15E */ CS_CMD_DESTINATION = 350, /* 0x15F */ CS_CMD_CHOOSE_CREDITS_SCENES, - /* 0x190 */ CS_CMD_RUMBLE = 0x190, + /* 0x190 */ CS_CMD_RUMBLE = 400, + /* 0x1C2 */ CS_CMD_ACTOR_CUE_450 = 450, + /* 0x1C3 */ CS_CMD_ACTOR_CUE_451, + /* 0x1C4 */ CS_CMD_ACTOR_CUE_452, + /* 0x1C5 */ CS_CMD_ACTOR_CUE_453, + /* 0x1C6 */ CS_CMD_ACTOR_CUE_454, + /* 0x1C7 */ CS_CMD_ACTOR_CUE_455, + /* 0x1C8 */ CS_CMD_ACTOR_CUE_456, + /* 0x1C9 */ CS_CMD_ACTOR_CUE_457, + /* 0x1CA */ CS_CMD_ACTOR_CUE_458, + /* 0x1CB */ CS_CMD_ACTOR_CUE_459, + /* 0x1CC */ CS_CMD_ACTOR_CUE_460, + /* 0x1CD */ CS_CMD_ACTOR_CUE_461, + /* 0x1CE */ CS_CMD_ACTOR_CUE_462, + /* 0x1CF */ CS_CMD_ACTOR_CUE_463, + /* 0x1D0 */ CS_CMD_ACTOR_CUE_464, + /* 0x1D1 */ CS_CMD_ACTOR_CUE_465, + /* 0x1D2 */ CS_CMD_ACTOR_CUE_466, + /* 0x1D3 */ CS_CMD_ACTOR_CUE_467, + /* 0x1D4 */ CS_CMD_ACTOR_CUE_468, + /* 0x1D5 */ CS_CMD_ACTOR_CUE_469, + /* 0x1D6 */ CS_CMD_ACTOR_CUE_470, + /* 0x1D7 */ CS_CMD_ACTOR_CUE_471, + /* 0x1D8 */ CS_CMD_ACTOR_CUE_472, + /* 0x1D9 */ CS_CMD_ACTOR_CUE_473, + /* 0x1DA */ CS_CMD_ACTOR_CUE_474, + /* 0x1DB */ CS_CMD_ACTOR_CUE_475, + /* 0x1DC */ CS_CMD_ACTOR_CUE_476, + /* 0x1DD */ CS_CMD_ACTOR_CUE_477, + /* 0x1DE */ CS_CMD_ACTOR_CUE_478, + /* 0x1DF */ CS_CMD_ACTOR_CUE_479, + /* 0x1E0 */ CS_CMD_ACTOR_CUE_480, + /* 0x1E1 */ CS_CMD_ACTOR_CUE_481, + /* 0x1E2 */ CS_CMD_ACTOR_CUE_482, + /* 0x1E3 */ CS_CMD_ACTOR_CUE_483, + /* 0x1E4 */ CS_CMD_ACTOR_CUE_484, + /* 0x1E5 */ CS_CMD_ACTOR_CUE_485, + /* 0x1E6 */ CS_CMD_ACTOR_CUE_486, + /* 0x1E7 */ CS_CMD_ACTOR_CUE_487, + /* 0x1E8 */ CS_CMD_ACTOR_CUE_488, + /* 0x1E9 */ CS_CMD_ACTOR_CUE_489, + /* 0x1EA */ CS_CMD_ACTOR_CUE_490, + /* 0x1EB */ CS_CMD_ACTOR_CUE_491, + /* 0x1EC */ CS_CMD_ACTOR_CUE_492, + /* 0x1ED */ CS_CMD_ACTOR_CUE_493, + /* 0x1EE */ CS_CMD_ACTOR_CUE_494, + /* 0x1EF */ CS_CMD_ACTOR_CUE_495, + /* 0x1F0 */ CS_CMD_ACTOR_CUE_496, + /* 0x1F1 */ CS_CMD_ACTOR_CUE_497, + /* 0x1F2 */ CS_CMD_ACTOR_CUE_498, + /* 0x1F3 */ CS_CMD_ACTOR_CUE_499, + /* 0x1F4 */ CS_CMD_ACTOR_CUE_500, + /* 0x1F5 */ CS_CMD_ACTOR_CUE_501, + /* 0x1F6 */ CS_CMD_ACTOR_CUE_502, + /* 0x1F7 */ CS_CMD_ACTOR_CUE_503, + /* 0x1F8 */ CS_CMD_ACTOR_CUE_504, + /* 0x1F9 */ CS_CMD_ACTOR_CUE_SOTCS, + /* 0x1FA */ CS_CMD_ACTOR_CUE_506, + /* 0x1FB */ CS_CMD_ACTOR_CUE_507, + /* 0x1FC */ CS_CMD_ACTOR_CUE_508, + /* 0x1FD */ CS_CMD_ACTOR_CUE_509, + /* 0x1FE */ CS_CMD_ACTOR_CUE_510, + /* 0x1FF */ CS_CMD_ACTOR_CUE_511, + /* 0x200 */ CS_CMD_ACTOR_CUE_512, + /* 0x201 */ CS_CMD_ACTOR_CUE_513, + /* 0x202 */ CS_CMD_ACTOR_CUE_514, + /* 0x203 */ CS_CMD_ACTOR_CUE_515, + /* 0x204 */ CS_CMD_ACTOR_CUE_516, + /* 0x205 */ CS_CMD_ACTOR_CUE_517, + /* 0x206 */ CS_CMD_ACTOR_CUE_518, + /* 0x207 */ CS_CMD_ACTOR_CUE_519, + /* 0x208 */ CS_CMD_ACTOR_CUE_520, + /* 0x209 */ CS_CMD_ACTOR_CUE_521, + /* 0x20A */ CS_CMD_ACTOR_CUE_522, + /* 0x20B */ CS_CMD_ACTOR_CUE_523, + /* 0x20C */ CS_CMD_ACTOR_CUE_524, + /* 0x20D */ CS_CMD_ACTOR_CUE_525, + /* 0x20E */ CS_CMD_ACTOR_CUE_526, + /* 0x20F */ CS_CMD_ACTOR_CUE_527, + /* 0x210 */ CS_CMD_ACTOR_CUE_528, + /* 0x211 */ CS_CMD_ACTOR_CUE_529, + /* 0x212 */ CS_CMD_ACTOR_CUE_530, + /* 0x213 */ CS_CMD_ACTOR_CUE_531, + /* 0x214 */ CS_CMD_ACTOR_CUE_532, + /* 0x215 */ CS_CMD_ACTOR_CUE_533, + /* 0x216 */ CS_CMD_ACTOR_CUE_534, + /* 0x217 */ CS_CMD_ACTOR_CUE_535, + /* 0x218 */ CS_CMD_ACTOR_CUE_536, + /* 0x219 */ CS_CMD_ACTOR_CUE_537, + /* 0x21A */ CS_CMD_ACTOR_CUE_538, + /* 0x21B */ CS_CMD_ACTOR_CUE_539, + /* 0x21C */ CS_CMD_ACTOR_CUE_540, + /* 0x21D */ CS_CMD_ACTOR_CUE_541, + /* 0x21E */ CS_CMD_ACTOR_CUE_542, + /* 0x21F */ CS_CMD_ACTOR_CUE_543, + /* 0x220 */ CS_CMD_ACTOR_CUE_544, + /* 0x221 */ CS_CMD_ACTOR_CUE_545, + /* 0x222 */ CS_CMD_ACTOR_CUE_546, + /* 0x223 */ CS_CMD_ACTOR_CUE_547, + /* 0x224 */ CS_CMD_ACTOR_CUE_548, + /* 0x225 */ CS_CMD_ACTOR_CUE_549, + /* 0x226 */ CS_CMD_ACTOR_CUE_550, + /* 0x227 */ CS_CMD_ACTOR_CUE_551, + /* 0x228 */ CS_CMD_ACTOR_CUE_552, + /* 0x229 */ CS_CMD_ACTOR_CUE_553, + /* 0x22A */ CS_CMD_ACTOR_CUE_554, + /* 0x22B */ CS_CMD_ACTOR_CUE_555, + /* 0x22C */ CS_CMD_ACTOR_CUE_556, + /* 0x22D */ CS_CMD_ACTOR_CUE_557, + /* 0x22E */ CS_CMD_ACTOR_CUE_558, + /* 0x22F */ CS_CMD_ACTOR_CUE_559, + /* 0x230 */ CS_CMD_ACTOR_CUE_560, + /* 0x231 */ CS_CMD_ACTOR_CUE_561, + /* 0x232 */ CS_CMD_ACTOR_CUE_562, + /* 0x233 */ CS_CMD_ACTOR_CUE_563, + /* 0x234 */ CS_CMD_ACTOR_CUE_564, + /* 0x235 */ CS_CMD_ACTOR_CUE_565, + /* 0x236 */ CS_CMD_ACTOR_CUE_566, + /* 0x237 */ CS_CMD_ACTOR_CUE_567, + /* 0x238 */ CS_CMD_ACTOR_CUE_568, + /* 0x239 */ CS_CMD_ACTOR_CUE_569, + /* 0x23A */ CS_CMD_ACTOR_CUE_570, + /* 0x23B */ CS_CMD_ACTOR_CUE_571, + /* 0x23C */ CS_CMD_ACTOR_CUE_572, + /* 0x23D */ CS_CMD_ACTOR_CUE_573, + /* 0x23E */ CS_CMD_ACTOR_CUE_574, + /* 0x23F */ CS_CMD_ACTOR_CUE_575, + /* 0x240 */ CS_CMD_ACTOR_CUE_576, + /* 0x241 */ CS_CMD_ACTOR_CUE_577, + /* 0x242 */ CS_CMD_ACTOR_CUE_578, + /* 0x243 */ CS_CMD_ACTOR_CUE_579, + /* 0x244 */ CS_CMD_ACTOR_CUE_580, + /* 0x245 */ CS_CMD_ACTOR_CUE_581, + /* 0x246 */ CS_CMD_ACTOR_CUE_582, + /* 0x247 */ CS_CMD_ACTOR_CUE_583, + /* 0x248 */ CS_CMD_ACTOR_CUE_584, + /* 0x249 */ CS_CMD_ACTOR_CUE_585, + /* 0x24A */ CS_CMD_ACTOR_CUE_586, + /* 0x24B */ CS_CMD_ACTOR_CUE_587, + /* 0x24C */ CS_CMD_ACTOR_CUE_588, + /* 0x24D */ CS_CMD_ACTOR_CUE_589, + /* 0x24E */ CS_CMD_ACTOR_CUE_590, + /* 0x24F */ CS_CMD_ACTOR_CUE_591, + /* 0x250 */ CS_CMD_ACTOR_CUE_592, + /* 0x251 */ CS_CMD_ACTOR_CUE_593, + /* 0x252 */ CS_CMD_ACTOR_CUE_594, + /* 0x253 */ CS_CMD_ACTOR_CUE_595, + /* 0x254 */ CS_CMD_ACTOR_CUE_596, + /* 0x255 */ CS_CMD_ACTOR_CUE_597, + /* 0x256 */ CS_CMD_ACTOR_CUE_598, + /* 0x257 */ CS_CMD_ACTOR_CUE_599 }; -class CutsceneSubCommandEntry_GenericMMCmd : public CutsceneSubCommandEntry +/**** GENERIC ****/ + +class CutsceneMMSubCommandEntry_GenericCmd : public CutsceneSubCommandEntry { public: - CutsceneMMCommands commandId; + CutsceneMM_CommandType commandId; - CutsceneSubCommandEntry_GenericMMCmd(const std::vector<uint8_t>& rawData, offset_t rawDataIndex, - CutsceneMMCommands cmdId); + CutsceneMMSubCommandEntry_GenericCmd(const std::vector<uint8_t>& rawData, offset_t rawDataIndex, + CutsceneMM_CommandType cmdId); std::string GetBodySourceCode() const override; }; @@ -54,11 +259,13 @@ class CutsceneMMCommand_GenericCmd : public CutsceneCommand { public: CutsceneMMCommand_GenericCmd(const std::vector<uint8_t>& rawData, offset_t rawDataIndex, - CutsceneMMCommands cmdId); + CutsceneMM_CommandType cmdId); std::string GetCommandMacro() const override; }; +/**** CAMERA ****/ + // TODO: MM cutscene camera command is implemented as a placeholder until we better understand how // it works class CutsceneSubCommandEntry_Camera : public CutsceneSubCommandEntry @@ -81,7 +288,9 @@ public: std::string GetCommandMacro() const override; }; -class CutsceneSubCommandEntry_FadeScreen : public CutsceneSubCommandEntry +/**** TRANSITION GENERAL ****/ + +class CutsceneSubCommandEntry_TransitionGeneral : public CutsceneSubCommandEntry { public: uint8_t unk_06; @@ -91,41 +300,46 @@ public: uint8_t unk_0A; uint8_t unk_0B; - CutsceneSubCommandEntry_FadeScreen(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + CutsceneSubCommandEntry_TransitionGeneral(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex); std::string GetBodySourceCode() const override; size_t GetRawSize() const override; }; -class CutsceneMMCommand_FadeScreen : public CutsceneCommand +class CutsceneMMCommand_TransitionGeneral : public CutsceneCommand { public: - CutsceneMMCommand_FadeScreen(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + CutsceneMMCommand_TransitionGeneral(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); std::string GetCommandMacro() const override; }; -class CutsceneSubCommandEntry_FadeSeq : public CutsceneSubCommandEntry +/**** FADE OUT SEQUENCE ****/ + +class CutsceneSubCommandEntry_FadeOutSeq : public CutsceneSubCommandEntry { public: uint32_t unk_08; - CutsceneSubCommandEntry_FadeSeq(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + CutsceneSubCommandEntry_FadeOutSeq(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); std::string GetBodySourceCode() const override; size_t GetRawSize() const override; }; -class CutsceneMMCommand_FadeSeq : public CutsceneCommand +class CutsceneMMCommand_FadeOutSeq : public CutsceneCommand { public: - CutsceneMMCommand_FadeSeq(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + CutsceneMMCommand_FadeOutSeq(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); std::string GetCommandMacro() const override; }; +/**** NON IMPLEMENTED ****/ + class CutsceneSubCommandEntry_NonImplemented : public CutsceneSubCommandEntry { public: @@ -138,3 +352,75 @@ class CutsceneMMCommand_NonImplemented : public CutsceneCommand public: CutsceneMMCommand_NonImplemented(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); }; + +/**** RUMBLE ****/ + +class CutsceneMMSubCommandEntry_Rumble : public CutsceneSubCommandEntry +{ +public: + uint8_t intensity; + uint8_t decayTimer; + uint8_t decayStep; + + CutsceneMMSubCommandEntry_Rumble(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneMMCommand_Rumble : public CutsceneCommand +{ +public: + CutsceneMMCommand_Rumble(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +/**** TEXT ****/ + +class CutsceneMMSubCommandEntry_Text : public CutsceneSubCommandEntry +{ +public: + uint16_t type; + uint16_t textId1; + uint16_t textId2; + + CutsceneMMSubCommandEntry_Text(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneMMCommand_Text : public CutsceneCommand +{ +public: + CutsceneMMCommand_Text(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +/**** ACTOR CUE ****/ + +class CutsceneMMSubCommandEntry_ActorCue : public CutsceneSubCommandEntry +{ +public: + uint16_t rotX, rotY, rotZ; + int32_t startPosX, startPosY, startPosZ; + int32_t endPosX, endPosY, endPosZ; + float normalX, normalY, normalZ; + + CutsceneMMSubCommandEntry_ActorCue(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneMMCommand_ActorCue : public CutsceneCommand +{ +public: + CutsceneMMCommand_ActorCue(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; diff --git a/ZAPD/OtherStructs/CutsceneOoT_Commands.cpp b/ZAPD/OtherStructs/CutsceneOoT_Commands.cpp new file mode 100644 index 0000000..e38bfb6 --- /dev/null +++ b/ZAPD/OtherStructs/CutsceneOoT_Commands.cpp @@ -0,0 +1,456 @@ +#include "CutsceneOoT_Commands.h" + +#include <cassert> +#include <unordered_map> +#include "Globals.h" +#include "Utils/BitConverter.h" +#include "Utils/StringHelper.h" + +/**** GENERIC ****/ + +// Specific for command lists where each entry has size 0x30 bytes +const std::unordered_map<CutsceneOoT_CommandType, CsCommandListDescriptor> csCommandsDesc = { + {CutsceneOoT_CommandType::CS_CMD_MISC, + {"CS_MISC", "(%s, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, + {CutsceneOoT_CommandType::CS_CMD_LIGHT_SETTING, + {"CS_LIGHT_SETTING", "(0x%02X, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, + {CutsceneOoT_CommandType::CS_CMD_START_SEQ, + {"CS_START_SEQ", "(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, + {CutsceneOoT_CommandType::CS_CMD_STOP_SEQ, + {"CS_STOP_SEQ", "(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, + {CutsceneOoT_CommandType::CS_CMD_FADE_OUT_SEQ, + {"CS_FADE_OUT_SEQ", "(%s, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, +}; + +CutsceneOoTSubCommandEntry_GenericCmd::CutsceneOoTSubCommandEntry_GenericCmd( + const std::vector<uint8_t>& rawData, offset_t rawDataIndex, CutsceneOoT_CommandType 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 CutsceneOoTSubCommandEntry_GenericCmd::GetBodySourceCode() const +{ + EnumData* enumData = &Globals::Instance->cfg.enumData; + const auto& element = csCommandsDesc.find(commandId); + + if (element != csCommandsDesc.end()) + { + bool isIndexInMisc = enumData->miscType.find(base) != enumData->miscType.end(); + bool isIndexInFade = + enumData->fadeOutSeqPlayer.find(base) != enumData->fadeOutSeqPlayer.end(); + std::string entryFmt = element->second.cmdMacro; + std::string firstArg; + entryFmt += element->second.args; + + if (commandId == CutsceneOoT_CommandType::CS_CMD_MISC && isIndexInMisc) + firstArg = enumData->miscType[base]; + else if (commandId == CutsceneOoT_CommandType::CS_CMD_FADE_OUT_SEQ && isIndexInFade) + firstArg = enumData->fadeOutSeqPlayer[base]; + else + { + bool baseOne = (commandId == CutsceneOoT_CommandType::CS_CMD_LIGHT_SETTING || + commandId == CutsceneOoT_CommandType::CS_CMD_START_SEQ || + commandId == CutsceneOoT_CommandType::CS_CMD_STOP_SEQ); + return StringHelper::Sprintf(entryFmt.c_str(), baseOne ? base - 1 : base, startFrame, + endFrame, pad, unused1, unused2, unused3, unused4, unused5, + unused6, unused7, unused8, unused9, unused10); + } + return StringHelper::Sprintf(entryFmt.c_str(), firstArg.c_str(), 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 CutsceneOoTSubCommandEntry_GenericCmd::GetRawSize() const +{ + return 0x30; +} + +CutsceneOoTCommand_GenericCmd::CutsceneOoTCommand_GenericCmd(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex, + CutsceneOoT_CommandType cmdId) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + commandID = static_cast<uint32_t>(cmdId); + entries.reserve(numEntries); + + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneOoTSubCommandEntry_GenericCmd(rawData, rawDataIndex, cmdId); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneOoTCommand_GenericCmd::GetCommandMacro() const +{ + const auto& element = csCommandsDesc.find(static_cast<CutsceneOoT_CommandType>(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); +} + +/**** CAMERA ****/ + +CutsceneOoTCommand_CameraPoint::CutsceneOoTCommand_CameraPoint(const std::vector<uint8_t>& 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 CutsceneOoTCommand_CameraPoint::GetBodySourceCode() const +{ + std::string continueMacro = "CS_CAM_CONTINUE"; + if (continueFlag != 0) + continueMacro = "CS_CAM_STOP"; + + return StringHelper::Sprintf("CS_CAM_POINT(%s, 0x%02X, %i, %ff, %i, %i, %i, 0x%04X)", + continueMacro.c_str(), cameraRoll, nextPointFrame, viewAngle, posX, + posY, posZ, unused); +} + +size_t CutsceneOoTCommand_CameraPoint::GetRawSize() const +{ + return 0x10; +} + +CutsceneOoTCommand_GenericCameraCmd::CutsceneOoTCommand_GenericCameraCmd( + const std::vector<uint8_t>& 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) + { + CutsceneOoTCommand_CameraPoint* camPoint = + new CutsceneOoTCommand_CameraPoint(rawData, currentPtr); + entries.push_back(camPoint); + + if (camPoint->continueFlag == -1) + shouldContinue = false; + + currentPtr += camPoint->GetRawSize(); + } +} + +std::string CutsceneOoTCommand_GenericCameraCmd::GetCommandMacro() const +{ + std::string result; + const char* listStr; + + if (commandID == (uint32_t)CutsceneOoT_CommandType::CS_CMD_CAM_AT_SPLINE) + { + listStr = "CS_CAM_AT_SPLINE"; + } + else if (commandID == (uint32_t)CutsceneOoT_CommandType::CS_CMD_CAM_AT_SPLINE_REL_TO_PLAYER) + { + listStr = "CS_CAM_AT_SPLINE_REL_TO_PLAYER"; + } + else if (commandID == (uint32_t)CutsceneOoT_CommandType::CS_CMD_CAM_EYE_SPLINE_REL_TO_PLAYER) + { + listStr = "CS_CAM_EYE_SPLINE_REL_TO_PLAYER"; + } + else + { + listStr = "CS_CAM_EYE_SPLINE"; + } + + result += StringHelper::Sprintf("%s(%i, %i)", listStr, startFrame, endFrame); + + return result; +} + +size_t CutsceneOoTCommand_GenericCameraCmd::GetCommandSize() const +{ + return 0x0C + entries.at(0)->GetRawSize() * entries.size(); +} + +/**** RUMBLE ****/ + +CutsceneOoTSubCommandEntry_Rumble::CutsceneOoTSubCommandEntry_Rumble( + const std::vector<uint8_t>& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + sourceStrength = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x06); + duration = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x07); + decreaseRate = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08); + unk_09 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x09); + unk_0A = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x0A); +} + +std::string CutsceneOoTSubCommandEntry_Rumble::GetBodySourceCode() const +{ + // Note: the first argument is unused + return StringHelper::Sprintf("CS_RUMBLE_CONTROLLER(%i, %i, %i, %i, %i, %i, 0x%02X, 0x%02X)", + base, startFrame, endFrame, sourceStrength, duration, decreaseRate, + unk_09, unk_0A); +} + +size_t CutsceneOoTSubCommandEntry_Rumble::GetRawSize() const +{ + return 0x0C; +} + +CutsceneOoTCommand_Rumble::CutsceneOoTCommand_Rumble(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + entries.reserve(numEntries); + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneOoTSubCommandEntry_Rumble(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneOoTCommand_Rumble::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_RUMBLE_CONTROLLER_LIST(%i)", numEntries); +} + +/**** TEXT ****/ + +CutsceneOoTSubCommandEntry_Text::CutsceneOoTSubCommandEntry_Text( + const std::vector<uint8_t>& 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 CutsceneOoTSubCommandEntry_Text::GetBodySourceCode() const +{ + EnumData* enumData = &Globals::Instance->cfg.enumData; + + if (type == 0xFFFF) + { + return StringHelper::Sprintf("CS_TEXT_NONE(%i, %i)", startFrame, endFrame); + } + if (type == 2) + { + return StringHelper::Sprintf("CS_TEXT_OCARINA_ACTION(%i, %i, %i, 0x%X)", base, startFrame, + endFrame, textId1); + } + + if (enumData->textType.find(type) != enumData->textType.end()) + { + return StringHelper::Sprintf("CS_TEXT(0x%X, %i, %i, %s, 0x%X, 0x%X)", base, startFrame, + endFrame, enumData->textType[type].c_str(), textId1, textId2); + } + + return StringHelper::Sprintf("CS_TEXT(0x%X, %i, %i, %i, 0x%X, 0x%X)", base, startFrame, + endFrame, type, textId1, textId2); +} + +size_t CutsceneOoTSubCommandEntry_Text::GetRawSize() const +{ + return 0x0C; +} + +CutsceneOoTCommand_Text::CutsceneOoTCommand_Text(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + entries.reserve(numEntries); + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneOoTSubCommandEntry_Text(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneOoTCommand_Text::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_TEXT_LIST(%i)", numEntries); +} + +/**** ACTOR CUE ****/ + +CutsceneOoTSubCommandEntry_ActorCue::CutsceneOoTSubCommandEntry_ActorCue( + const std::vector<uint8_t>& 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 CutsceneOoTSubCommandEntry_ActorCue::GetBodySourceCode() const +{ + std::string result; + + if (static_cast<CutsceneOoT_CommandType>(commandID) == + CutsceneOoT_CommandType::CS_CMD_PLAYER_CUE) + { + result = "CS_PLAYER_CUE"; + } + else + { + result = "CS_ACTOR_CUE"; + } + + result += + StringHelper::Sprintf("(%i, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, " + "%i, %i, %i, %i, %.8ef, %.8ef, %.8ef)", + base, startFrame, endFrame, rotX, rotY, rotZ, startPosX, startPosY, + startPosZ, endPosX, endPosY, endPosZ, normalX, normalY, normalZ); + return result; +} + +size_t CutsceneOoTSubCommandEntry_ActorCue::GetRawSize() const +{ + return 0x30; +} + +CutsceneOoTCommand_ActorCue::CutsceneOoTCommand_ActorCue(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + entries.reserve(numEntries); + for (size_t i = 0; i < numEntries; i++) + { + auto* entry = new CutsceneOoTSubCommandEntry_ActorCue(rawData, rawDataIndex); + entries.push_back(entry); + rawDataIndex += entry->GetRawSize(); + } +} + +std::string CutsceneOoTCommand_ActorCue::GetCommandMacro() const +{ + EnumData* enumData = &Globals::Instance->cfg.enumData; + + if (static_cast<CutsceneOoT_CommandType>(commandID) == + CutsceneOoT_CommandType::CS_CMD_PLAYER_CUE) + { + return StringHelper::Sprintf("CS_PLAYER_CUE_LIST(%i)", entries.size()); + } + + if (enumData->cutsceneCmd.find(commandID) != enumData->cutsceneCmd.end()) + { + return StringHelper::Sprintf("CS_ACTOR_CUE_LIST(%s, %i)", + enumData->cutsceneCmd[commandID].c_str(), entries.size()); + } + + return StringHelper::Sprintf("CS_ACTOR_CUE_LIST(0x%04X, %i)", commandID, entries.size()); +} + +/**** DESTINATION ****/ + +CutsceneOoTCommand_Destination::CutsceneOoTCommand_Destination(const std::vector<uint8_t>& 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 CutsceneOoTCommand_Destination::GenerateSourceCode() const +{ + EnumData* enumData = &Globals::Instance->cfg.enumData; + + if (enumData->destination.find(base) != enumData->destination.end()) + { + return StringHelper::Sprintf("CS_DESTINATION(%s, %i, %i),\n", + enumData->destination[base].c_str(), startFrame, endFrame); + } + + return StringHelper::Sprintf("CS_DESTINATION(%i, %i, %i),\n", base, startFrame, endFrame); +} + +size_t CutsceneOoTCommand_Destination::GetCommandSize() const +{ + return 0x10; +} + +/**** TRANSITION ****/ + +CutsceneOoTCommand_Transition::CutsceneOoTCommand_Transition(const std::vector<uint8_t>& 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 CutsceneOoTCommand_Transition::GenerateSourceCode() const +{ + EnumData* enumData = &Globals::Instance->cfg.enumData; + + if (enumData->transitionType.find(base) != enumData->transitionType.end()) + { + return StringHelper::Sprintf("CS_TRANSITION(%s, %i, %i),\n", + enumData->transitionType[base].c_str(), startFrame, endFrame); + } + + return StringHelper::Sprintf("CS_TRANSITION(%i, %i, %i),\n", base, startFrame, endFrame); +} + +size_t CutsceneOoTCommand_Transition::GetCommandSize() const +{ + return 0x10; +} diff --git a/ZAPD/OtherStructs/CutsceneOoT_Commands.h b/ZAPD/OtherStructs/CutsceneOoT_Commands.h new file mode 100644 index 0000000..ff9b679 --- /dev/null +++ b/ZAPD/OtherStructs/CutsceneOoT_Commands.h @@ -0,0 +1,314 @@ +#pragma once + +#include "Cutscene_Common.h" + +// https://github.com/zeldaret/oot/blob/7235af2249843fb68740111b70089bad827a4730/include/z64cutscene.h#L35-L165 +enum class CutsceneOoT_CommandType +{ + CS_CMD_CAM_EYE_SPLINE = 0x01, + CS_CMD_CAM_AT_SPLINE, + CS_CMD_MISC, + CS_CMD_LIGHT_SETTING, + CS_CMD_CAM_EYE_SPLINE_REL_TO_PLAYER, + CS_CMD_CAM_AT_SPLINE_REL_TO_PLAYER, + CS_CMD_CAM_EYE, + CS_CMD_CAM_AT, + CS_CMD_RUMBLE_CONTROLLER, + CS_CMD_PLAYER_CUE, + CS_CMD_UNIMPLEMENTED_B, + CS_CMD_UNIMPLEMENTED_D = 0x0D, + CS_CMD_ACTOR_CUE_1_0, + CS_CMD_ACTOR_CUE_0_0, + CS_CMD_ACTOR_CUE_1_1, + CS_CMD_ACTOR_CUE_0_1, + CS_CMD_ACTOR_CUE_0_2, + CS_CMD_TEXT, + CS_CMD_UNIMPLEMENTED_15 = 0x15, + CS_CMD_UNIMPLEMENTED_16, + CS_CMD_ACTOR_CUE_0_3, + CS_CMD_ACTOR_CUE_1_2, + CS_CMD_ACTOR_CUE_2_0, + CS_CMD_UNIMPLEMENTED_1B = 0x1B, + CS_CMD_UNIMPLEMENTED_1C, + CS_CMD_ACTOR_CUE_3_0, + CS_CMD_ACTOR_CUE_4_0, + CS_CMD_ACTOR_CUE_6_0, + CS_CMD_UNIMPLEMENTED_20, + CS_CMD_UNIMPLEMENTED_21, + CS_CMD_ACTOR_CUE_0_4, + CS_CMD_ACTOR_CUE_1_3, + CS_CMD_ACTOR_CUE_2_1, + CS_CMD_ACTOR_CUE_3_1, + CS_CMD_ACTOR_CUE_4_1, + CS_CMD_ACTOR_CUE_0_5, + CS_CMD_ACTOR_CUE_1_4, + CS_CMD_ACTOR_CUE_2_2, + CS_CMD_ACTOR_CUE_3_2, + CS_CMD_ACTOR_CUE_4_2, + CS_CMD_ACTOR_CUE_5_0, + CS_CMD_TRANSITION, + CS_CMD_ACTOR_CUE_0_6, + CS_CMD_ACTOR_CUE_4_3, + CS_CMD_ACTOR_CUE_1_5, + CS_CMD_ACTOR_CUE_7_0, + CS_CMD_ACTOR_CUE_2_3, + CS_CMD_ACTOR_CUE_3_3, + CS_CMD_ACTOR_CUE_6_1, + CS_CMD_ACTOR_CUE_3_4, + CS_CMD_ACTOR_CUE_4_4, + CS_CMD_ACTOR_CUE_5_1, + CS_CMD_ACTOR_CUE_6_2 = 0x39, + CS_CMD_ACTOR_CUE_6_3, + CS_CMD_UNIMPLEMENTED_3B, + CS_CMD_ACTOR_CUE_7_1, + CS_CMD_UNIMPLEMENTED_3D, + CS_CMD_ACTOR_CUE_8_0, + CS_CMD_ACTOR_CUE_3_5, + CS_CMD_ACTOR_CUE_1_6, + CS_CMD_ACTOR_CUE_3_6, + CS_CMD_ACTOR_CUE_3_7, + CS_CMD_ACTOR_CUE_2_4, + CS_CMD_ACTOR_CUE_1_7, + CS_CMD_ACTOR_CUE_2_5, + CS_CMD_ACTOR_CUE_1_8, + CS_CMD_UNIMPLEMENTED_47, + CS_CMD_ACTOR_CUE_2_6, + CS_CMD_UNIMPLEMENTED_49, + CS_CMD_ACTOR_CUE_2_7, + CS_CMD_ACTOR_CUE_3_8, + CS_CMD_ACTOR_CUE_0_7, + CS_CMD_ACTOR_CUE_5_2, + CS_CMD_ACTOR_CUE_1_9, + CS_CMD_ACTOR_CUE_4_5, + CS_CMD_ACTOR_CUE_1_10, + CS_CMD_ACTOR_CUE_2_8, + CS_CMD_ACTOR_CUE_3_9, + CS_CMD_ACTOR_CUE_4_6, + CS_CMD_ACTOR_CUE_5_3, + CS_CMD_ACTOR_CUE_0_8, + CS_CMD_START_SEQ, + CS_CMD_STOP_SEQ, + CS_CMD_ACTOR_CUE_6_4, + CS_CMD_ACTOR_CUE_7_2, + CS_CMD_ACTOR_CUE_5_4, + CS_CMD_ACTOR_CUE_0_9 = 0x5D, + CS_CMD_ACTOR_CUE_1_11, + CS_CMD_ACTOR_CUE_0_10 = 0x69, + CS_CMD_ACTOR_CUE_2_9, + CS_CMD_ACTOR_CUE_0_11, + CS_CMD_ACTOR_CUE_3_10, + CS_CMD_UNIMPLEMENTED_6D, + CS_CMD_ACTOR_CUE_0_12, + CS_CMD_ACTOR_CUE_7_3, + CS_CMD_UNIMPLEMENTED_70, + CS_CMD_UNIMPLEMENTED_71, + CS_CMD_ACTOR_CUE_7_4, + CS_CMD_ACTOR_CUE_6_5, + CS_CMD_ACTOR_CUE_1_12, + CS_CMD_ACTOR_CUE_2_10, + CS_CMD_ACTOR_CUE_1_13, + CS_CMD_ACTOR_CUE_0_13, + CS_CMD_ACTOR_CUE_1_14, + CS_CMD_ACTOR_CUE_2_11, + CS_CMD_ACTOR_CUE_0_14 = 0x7B, + CS_CMD_FADE_OUT_SEQ, + CS_CMD_ACTOR_CUE_1_15, + CS_CMD_ACTOR_CUE_2_12, + CS_CMD_ACTOR_CUE_3_11, + CS_CMD_ACTOR_CUE_4_7, + CS_CMD_ACTOR_CUE_5_5, + CS_CMD_ACTOR_CUE_6_6, + CS_CMD_ACTOR_CUE_1_16, + CS_CMD_ACTOR_CUE_2_13, + CS_CMD_ACTOR_CUE_3_12, + CS_CMD_ACTOR_CUE_7_5, + CS_CMD_ACTOR_CUE_4_8, + CS_CMD_ACTOR_CUE_5_6, + CS_CMD_ACTOR_CUE_6_7, + CS_CMD_ACTOR_CUE_0_15, + CS_CMD_ACTOR_CUE_0_16, + CS_CMD_TIME, + CS_CMD_ACTOR_CUE_1_17, + CS_CMD_ACTOR_CUE_7_6, + CS_CMD_ACTOR_CUE_9_0, + CS_CMD_ACTOR_CUE_0_17, + CS_CMD_DESTINATION = 0x03E8, + CS_CMD_END = 0xFFFF +}; + +/**** GENERIC ****/ + +class CutsceneOoTSubCommandEntry_GenericCmd : public CutsceneSubCommandEntry +{ +public: + CutsceneOoT_CommandType 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; + + CutsceneOoTSubCommandEntry_GenericCmd(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex, CutsceneOoT_CommandType cmdId); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneOoTCommand_GenericCmd : public CutsceneCommand +{ +public: + CutsceneOoTCommand_GenericCmd(const std::vector<uint8_t>& rawData, offset_t rawDataIndex, + CutsceneOoT_CommandType cmdId); + + std::string GetCommandMacro() const override; +}; + +/**** CAMERA ****/ + +class CutsceneOoTCommand_CameraPoint : public CutsceneSubCommandEntry +{ +public: + int8_t continueFlag; + int8_t cameraRoll; + int16_t nextPointFrame; + float viewAngle; + int16_t posX, posY, posZ; + int16_t unused; + + CutsceneOoTCommand_CameraPoint(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneOoTCommand_GenericCameraCmd : public CutsceneCommand +{ +public: + uint16_t base; + uint16_t startFrame; + uint16_t endFrame; + uint16_t unused; + + CutsceneOoTCommand_GenericCameraCmd(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; + + size_t GetCommandSize() const override; +}; + +/**** TRANSITION ****/ + +class CutsceneOoTCommand_Transition : public CutsceneCommand +{ +public: + uint16_t base; + uint16_t startFrame; + uint16_t endFrame; + + CutsceneOoTCommand_Transition(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GenerateSourceCode() const override; + size_t GetCommandSize() const override; +}; + +/**** RUMBLE ****/ + +class CutsceneOoTSubCommandEntry_Rumble : public CutsceneSubCommandEntry +{ +public: + uint8_t sourceStrength; + uint8_t duration; + uint8_t decreaseRate; + uint8_t unk_09; + uint8_t unk_0A; + + CutsceneOoTSubCommandEntry_Rumble(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneOoTCommand_Rumble : public CutsceneCommand +{ +public: + CutsceneOoTCommand_Rumble(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +/**** TEXT ****/ + +class CutsceneOoTSubCommandEntry_Text : public CutsceneSubCommandEntry +{ +public: + uint16_t type; + uint16_t textId1; + uint16_t textId2; + + CutsceneOoTSubCommandEntry_Text(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneOoTCommand_Text : public CutsceneCommand +{ +public: + CutsceneOoTCommand_Text(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +/**** ACTOR CUE ****/ + +class CutsceneOoTSubCommandEntry_ActorCue : public CutsceneSubCommandEntry +{ +public: + uint16_t rotX, rotY, rotZ; + int32_t startPosX, startPosY, startPosZ; + int32_t endPosX, endPosY, endPosZ; + float normalX, normalY, normalZ; + + CutsceneOoTSubCommandEntry_ActorCue(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneOoTCommand_ActorCue : public CutsceneCommand +{ +public: + CutsceneOoTCommand_ActorCue(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; + +/**** DESTINATION ****/ + +class CutsceneOoTCommand_Destination : public CutsceneCommand +{ +public: + uint16_t base; + uint16_t startFrame; + uint16_t endFrame; + uint16_t unknown; + + CutsceneOoTCommand_Destination(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GenerateSourceCode() const override; + size_t GetCommandSize() const override; +}; diff --git a/ZAPD/OtherStructs/Cutscene_Commands.cpp b/ZAPD/OtherStructs/Cutscene_Commands.cpp deleted file mode 100644 index 8ae4c69..0000000 --- a/ZAPD/OtherStructs/Cutscene_Commands.cpp +++ /dev/null @@ -1,596 +0,0 @@ -#include "Cutscene_Commands.h" - -#include <cassert> -#include <unordered_map> - -#include "CutsceneMM_Commands.h" -#include "Globals.h" -#include "Utils/BitConverter.h" -#include "Utils/StringHelper.h" - -/* CutsceneSubCommandEntry */ - -CutsceneSubCommandEntry::CutsceneSubCommandEntry(const std::vector<uint8_t>& 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<uint8_t>& 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<CutsceneCommands, CsCommandListDescriptor> 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<uint8_t>& 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<uint8_t>& rawData, - offset_t rawDataIndex, - CutsceneCommands cmdId) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - commandID = static_cast<uint32_t>(cmdId); - entries.reserve(numEntries); - - 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<CutsceneCommands>(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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - entries.reserve(numEntries); - 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<uint8_t>& 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<uint8_t>& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - entries.reserve(numEntries); - 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<uint8_t>& 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<uint8_t>& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - entries.reserve(numEntries); - 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<uint8_t>& 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<CutsceneMMCommands>(commandID) == - CutsceneMMCommands::CS_CMD_SET_PLAYER_ACTION) - { - result = "CS_PLAYER_ACTION"; - } - else - { - result = "CS_ACTOR_ACTION"; - } - } - else - { - if (static_cast<CutsceneCommands>(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<uint8_t>& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - entries.reserve(numEntries); - 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<CutsceneMMCommands>(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<CutsceneCommands>(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<uint8_t>& 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<uint8_t>& 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/ZAPD/OtherStructs/Cutscene_Commands.h b/ZAPD/OtherStructs/Cutscene_Commands.h deleted file mode 100644 index c462735..0000000 --- a/ZAPD/OtherStructs/Cutscene_Commands.h +++ /dev/null @@ -1,267 +0,0 @@ -#pragma once - -#include <cstdint> -#include <string> -#include <vector> - -#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<uint8_t>& 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<CutsceneSubCommandEntry*> entries; - - CutsceneCommand(const std::vector<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& rawData, offset_t rawDataIndex); - - std::string GenerateSourceCode() const override; - size_t GetCommandSize() const override; -}; diff --git a/ZAPD/OtherStructs/Cutscene_Common.cpp b/ZAPD/OtherStructs/Cutscene_Common.cpp new file mode 100644 index 0000000..a5ea609 --- /dev/null +++ b/ZAPD/OtherStructs/Cutscene_Common.cpp @@ -0,0 +1,128 @@ +#include "Cutscene_Common.h" +#include "Utils/BitConverter.h" +#include "Utils/StringHelper.h" + +/* CutsceneSubCommandEntry */ + +CutsceneSubCommandEntry::CutsceneSubCommandEntry(const std::vector<uint8_t>& 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<uint8_t>& 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; + } +} + +/*** TIME ****/ + +CutsceneSubCommandEntry_SetTime::CutsceneSubCommandEntry_SetTime( + const std::vector<uint8_t>& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + hour = BitConverter::ToUInt8BE(rawData, rawDataIndex + 6); + minute = BitConverter::ToUInt8BE(rawData, rawDataIndex + 7); +} + +std::string CutsceneSubCommandEntry_SetTime::GetBodySourceCode() const +{ + // Note: Both OoT and MM have the first argument unused + return StringHelper::Sprintf("CS_TIME(%i, %i, %i, %i, %i)", base, startFrame, endFrame, hour, + minute); +} + +size_t CutsceneSubCommandEntry_SetTime::GetRawSize() const +{ + return 0x0C; +} + +CutsceneCommand_Time::CutsceneCommand_Time(const std::vector<uint8_t>& rawData, + offset_t rawDataIndex) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + entries.reserve(numEntries); + 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_Time::GetCommandMacro() const +{ + return StringHelper::Sprintf("CS_TIME_LIST(%i)", numEntries); +} diff --git a/ZAPD/OtherStructs/Cutscene_Common.h b/ZAPD/OtherStructs/Cutscene_Common.h new file mode 100644 index 0000000..9d8dcf6 --- /dev/null +++ b/ZAPD/OtherStructs/Cutscene_Common.h @@ -0,0 +1,72 @@ +#pragma once + +#include <cstdint> +#include <string> +#include <vector> +#include "Declaration.h" + +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<uint8_t>& 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<CutsceneSubCommandEntry*> entries; + + CutsceneCommand(const std::vector<uint8_t>& 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); +}; + +/**** TIME ****/ + +class CutsceneSubCommandEntry_SetTime : public CutsceneSubCommandEntry +{ +public: + uint8_t hour; + uint8_t minute; + + CutsceneSubCommandEntry_SetTime(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetBodySourceCode() const override; + + size_t GetRawSize() const override; +}; + +class CutsceneCommand_Time : public CutsceneCommand +{ +public: + CutsceneCommand_Time(const std::vector<uint8_t>& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; diff --git a/ZAPD/OtherStructs/SkinLimbStructs.cpp b/ZAPD/OtherStructs/SkinLimbStructs.cpp index 8a0e49c..430cc66 100644 --- a/ZAPD/OtherStructs/SkinLimbStructs.cpp +++ b/ZAPD/OtherStructs/SkinLimbStructs.cpp @@ -6,149 +6,149 @@ #include "ZDisplayList.h" #include "ZFile.h" -/* Struct_800A57C0 */ +/* SkinVertex */ -Struct_800A57C0::Struct_800A57C0(ZFile* nParent) : ZResource(nParent) +SkinVertex::SkinVertex(ZFile* nParent) : ZResource(nParent) { } -void Struct_800A57C0::ParseRawData() +void SkinVertex::ParseRawData() { const auto& rawData = parent->GetRawData(); - unk_0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00); - unk_2 = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x02); - unk_4 = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x04); - unk_6 = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x06); - unk_7 = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x07); - unk_8 = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x08); - unk_9 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x09); + index = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00); + s = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x02); + t = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x04); + normX = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x06); + normY = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x07); + normZ = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x08); + alpha = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x09); } -std::string Struct_800A57C0::GetBodySourceCode() const +std::string SkinVertex::GetBodySourceCode() const { - return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X", unk_0, unk_2, unk_4, unk_6, - unk_7, unk_8, unk_9); + return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X", index, s, t, normX, normY, + normZ, alpha); } -std::string Struct_800A57C0::GetSourceTypeName() const +std::string SkinVertex::GetSourceTypeName() const { - return "Struct_800A57C0"; + return "SkinVertex"; } -ZResourceType Struct_800A57C0::GetResourceType() const +ZResourceType SkinVertex::GetResourceType() const { // TODO return ZResourceType::Error; } -size_t Struct_800A57C0::GetRawDataSize() const +size_t SkinVertex::GetRawDataSize() const { return 0x0A; } -/* Struct_800A598C_2 */ +/* SkinTransformation */ -Struct_800A598C_2::Struct_800A598C_2(ZFile* nParent) : ZResource(nParent) +SkinTransformation::SkinTransformation(ZFile* nParent) : ZResource(nParent) { } -void Struct_800A598C_2::ParseRawData() +void SkinTransformation::ParseRawData() { const auto& rawData = parent->GetRawData(); - unk_0 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x00); + limbIndex = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x00); x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x02); y = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x04); z = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x06); - unk_8 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08); + scale = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08); } -std::string Struct_800A598C_2::GetBodySourceCode() const +std::string SkinTransformation::GetBodySourceCode() const { - return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", unk_0, x, y, z, unk_8); + return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", limbIndex, x, y, z, scale); } -std::string Struct_800A598C_2::GetSourceTypeName() const +std::string SkinTransformation::GetSourceTypeName() const { - return "Struct_800A598C_2"; + return "SkinTransformation"; } -ZResourceType Struct_800A598C_2::GetResourceType() const +ZResourceType SkinTransformation::GetResourceType() const { // TODO return ZResourceType::Error; } -size_t Struct_800A598C_2::GetRawDataSize() const +size_t SkinTransformation::GetRawDataSize() const { return 0x0A; } -/* Struct_800A598C */ +/* SkinLimbModif */ -Struct_800A598C::Struct_800A598C(ZFile* nParent) : ZResource(nParent) +SkinLimbModif::SkinLimbModif(ZFile* nParent) : ZResource(nParent) { } -void Struct_800A598C::ParseRawData() +void SkinLimbModif::ParseRawData() { const auto& rawData = parent->GetRawData(); - unk_0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00); - unk_2 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x02); + vtxCount = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00); + transformCount = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x02); unk_4 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x04); - unk_8 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08); - unk_C = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C); + skinVertices = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08); + limbTransformations = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C); - if (unk_8 != 0 && GETSEGNUM(unk_8) == parent->segment) + if (skinVertices != 0 && GETSEGNUM(skinVertices) == parent->segment) { - uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); + uint32_t unk_8_Offset = Seg2Filespace(skinVertices, parent->baseAddress); - unk_8_arr.reserve(unk_0); - for (size_t i = 0; i < unk_0; i++) + skinVertices_arr.reserve(vtxCount); + for (size_t i = 0; i < vtxCount; i++) { - Struct_800A57C0 unk8_data(parent); - unk8_data.ExtractFromFile(unk_8_Offset); - unk_8_arr.push_back(unk8_data); + SkinVertex skinVertices_data(parent); + skinVertices_data.ExtractFromFile(unk_8_Offset); + skinVertices_arr.push_back(skinVertices_data); - unk_8_Offset += unk8_data.GetRawDataSize(); + unk_8_Offset += skinVertices_data.GetRawDataSize(); } } - if (unk_C != 0 && GETSEGNUM(unk_8) == parent->segment) + if (limbTransformations != 0 && GETSEGNUM(skinVertices) == parent->segment) { - uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress); + uint32_t unk_C_Offset = Seg2Filespace(limbTransformations, parent->baseAddress); - unk_C_arr.reserve(unk_2); - for (size_t i = 0; i < unk_2; i++) + limbTransformations_arr.reserve(transformCount); + for (size_t i = 0; i < transformCount; i++) { - Struct_800A598C_2 unkC_data(parent); - unkC_data.ExtractFromFile(unk_C_Offset); - unk_C_arr.push_back(unkC_data); + SkinTransformation limbTransformations_data(parent); + limbTransformations_data.ExtractFromFile(unk_C_Offset); + limbTransformations_arr.push_back(limbTransformations_data); - unk_C_Offset += unkC_data.GetRawDataSize(); + unk_C_Offset += limbTransformations_data.GetRawDataSize(); } } } -void Struct_800A598C::DeclareReferences(const std::string& prefix) +void SkinLimbModif::DeclareReferences(const std::string& prefix) { std::string varPrefix = prefix; if (name != "") varPrefix = name; - if (unk_8 != 0 && GETSEGNUM(unk_8) == parent->segment) + if (skinVertices != 0 && GETSEGNUM(skinVertices) == parent->segment) { - const auto& res = unk_8_arr.at(0); + const auto& res = skinVertices_arr.at(0); std::string unk_8_Str = res.GetDefaultName(varPrefix); - size_t arrayItemCnt = unk_8_arr.size(); + size_t arrayItemCnt = skinVertices_arr.size(); std::string entryStr = ""; for (size_t i = 0; i < arrayItemCnt; i++) { - auto& child = unk_8_arr[i]; + auto& child = skinVertices_arr[i]; child.DeclareReferences(varPrefix); entryStr += StringHelper::Sprintf("\t{ %s },", child.GetBodySourceCode().c_str()); @@ -156,29 +156,29 @@ void Struct_800A598C::DeclareReferences(const std::string& prefix) entryStr += "\n"; } - uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - Declaration* decl = parent->GetDeclaration(unk_8_Offset); + uint32_t skinVertices_Offset = Seg2Filespace(skinVertices, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(skinVertices_Offset); if (decl == nullptr) { - parent->AddDeclarationArray(unk_8_Offset, res.GetDeclarationAlignment(), + parent->AddDeclarationArray(skinVertices_Offset, res.GetDeclarationAlignment(), arrayItemCnt * res.GetRawDataSize(), res.GetSourceTypeName(), unk_8_Str, arrayItemCnt, entryStr); } else - decl->text = entryStr; + decl->declBody = entryStr; } - if (unk_C != 0 && GETSEGNUM(unk_C) == parent->segment) + if (limbTransformations != 0 && GETSEGNUM(limbTransformations) == parent->segment) { - const auto& res = unk_C_arr.at(0); + const auto& res = limbTransformations_arr.at(0); std::string unk_C_Str = res.GetDefaultName(varPrefix); - size_t arrayItemCnt = unk_C_arr.size(); + size_t arrayItemCnt = limbTransformations_arr.size(); std::string entryStr = ""; for (size_t i = 0; i < arrayItemCnt; i++) { - auto& child = unk_C_arr[i]; + auto& child = limbTransformations_arr[i]; child.DeclareReferences(varPrefix); entryStr += StringHelper::Sprintf("\t{ %s },", child.GetBodySourceCode().c_str()); @@ -186,7 +186,7 @@ void Struct_800A598C::DeclareReferences(const std::string& prefix) entryStr += "\n"; } - uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress); + uint32_t unk_C_Offset = Seg2Filespace(limbTransformations, parent->baseAddress); Declaration* decl = parent->GetDeclaration(unk_C_Offset); if (decl == nullptr) { @@ -195,75 +195,74 @@ void Struct_800A598C::DeclareReferences(const std::string& prefix) res.GetSourceTypeName(), unk_C_Str, arrayItemCnt, entryStr); } else - decl->text = entryStr; + decl->declBody = entryStr; } } -std::string Struct_800A598C::GetBodySourceCode() const +std::string SkinLimbModif::GetBodySourceCode() const { - std::string unk_8_Str; + std::string skinVertices_Str; std::string unk_C_Str; - Globals::Instance->GetSegmentedPtrName(unk_8, parent, "Struct_800A57C0", unk_8_Str, - parent->workerID); - Globals::Instance->GetSegmentedPtrName(unk_C, parent, "Struct_800A598C_2", unk_C_Str, - parent->workerID); + Globals::Instance->GetSegmentedPtrName(skinVertices, parent, "SkinVertex", skinVertices_Str, parent->workerID); + Globals::Instance->GetSegmentedPtrName(limbTransformations, parent, "SkinTransformation", + unk_C_Str, parent->workerID); std::string entryStr = StringHelper::Sprintf("\n\t\tARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n", - unk_8_Str.c_str(), unk_C_Str.c_str()); - entryStr += - StringHelper::Sprintf("\t\t%i, %s, %s\n\t", unk_4, unk_8_Str.c_str(), unk_C_Str.c_str()); + skinVertices_Str.c_str(), unk_C_Str.c_str()); + entryStr += StringHelper::Sprintf("\t\t%i, %s, %s\n\t", unk_4, skinVertices_Str.c_str(), + unk_C_Str.c_str()); return entryStr; } -std::string Struct_800A598C::GetSourceTypeName() const +std::string SkinLimbModif::GetSourceTypeName() const { - return "Struct_800A598C"; + return "SkinLimbModif"; } -ZResourceType Struct_800A598C::GetResourceType() const +ZResourceType SkinLimbModif::GetResourceType() const { // TODO return ZResourceType::Error; } -size_t Struct_800A598C::GetRawDataSize() const +size_t SkinLimbModif::GetRawDataSize() const { return 0x10; } -/* Struct_800A5E28 */ +/* SkinAnimatedLimbData */ -Struct_800A5E28::Struct_800A5E28(ZFile* nParent) : ZResource(nParent) +SkinAnimatedLimbData::SkinAnimatedLimbData(ZFile* nParent) : ZResource(nParent) { } -void Struct_800A5E28::ParseRawData() +void SkinAnimatedLimbData::ParseRawData() { const auto& rawData = parent->GetRawData(); - unk_0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00); - unk_2 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x02); - unk_4 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04); - unk_8 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08); + totalVtxCount = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00); + limbModifCount = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x02); + limbModifications = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04); + dlist = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08); - if (unk_4 != 0 && GETSEGNUM(unk_4) == parent->segment) + if (limbModifications != 0 && GETSEGNUM(limbModifications) == parent->segment) { - uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); + uint32_t limbModifications_Offset = Seg2Filespace(limbModifications, parent->baseAddress); - unk_4_arr.reserve(unk_2); - for (size_t i = 0; i < unk_2; i++) + limbModifications_arr.reserve(limbModifCount); + for (size_t i = 0; i < limbModifCount; i++) { - Struct_800A598C unk_4_data(parent); - unk_4_data.ExtractFromFile(unk_4_Offset); - unk_4_arr.push_back(unk_4_data); + SkinLimbModif limbModifications_data(parent); + limbModifications_data.ExtractFromFile(limbModifications_Offset); + limbModifications_arr.push_back(limbModifications_data); - unk_4_Offset += unk_4_data.GetRawDataSize(); + limbModifications_Offset += limbModifications_data.GetRawDataSize(); } } } -void Struct_800A5E28::DeclareReferences(const std::string& prefix) +void SkinAnimatedLimbData::DeclareReferences(const std::string& prefix) { std::string varPrefix = prefix; if (name != "") @@ -271,17 +270,17 @@ void Struct_800A5E28::DeclareReferences(const std::string& prefix) ZResource::DeclareReferences(varPrefix); - if (unk_4 != SEGMENTED_NULL && GETSEGNUM(unk_4) == parent->segment) + if (limbModifications != SEGMENTED_NULL && GETSEGNUM(limbModifications) == parent->segment) { - const auto& res = unk_4_arr.at(0); - std::string unk_4_Str = res.GetDefaultName(varPrefix); + const auto& res = limbModifications_arr.at(0); + std::string limbModifications_Str = res.GetDefaultName(varPrefix); - size_t arrayItemCnt = unk_4_arr.size(); + size_t arrayItemCnt = limbModifications_arr.size(); std::string entryStr = ""; for (size_t i = 0; i < arrayItemCnt; i++) { - auto& child = unk_4_arr[i]; + auto& child = limbModifications_arr[i]; child.DeclareReferences(varPrefix); entryStr += StringHelper::Sprintf("\t{ %s },", child.GetBodySourceCode().c_str()); @@ -289,64 +288,67 @@ void Struct_800A5E28::DeclareReferences(const std::string& prefix) entryStr += "\n"; } - uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); - Declaration* decl = parent->GetDeclaration(unk_4_Offset); + uint32_t limbModifications_Offset = Seg2Filespace(limbModifications, parent->baseAddress); + Declaration* decl = parent->GetDeclaration(limbModifications_Offset); if (decl == nullptr) { - parent->AddDeclarationArray(unk_4_Offset, res.GetDeclarationAlignment(), + parent->AddDeclarationArray(limbModifications_Offset, res.GetDeclarationAlignment(), arrayItemCnt * res.GetRawDataSize(), - res.GetSourceTypeName(), unk_4_Str, arrayItemCnt, entryStr); + res.GetSourceTypeName(), limbModifications_Str, + arrayItemCnt, entryStr); } else - decl->text = entryStr; + decl->declBody = entryStr; } - if (unk_8 != SEGMENTED_NULL && GETSEGNUM(unk_8) == parent->segment) + if (dlist != SEGMENTED_NULL && GETSEGNUM(dlist) == parent->segment) { - uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); + uint32_t dlist_Offset = Seg2Filespace(dlist, parent->baseAddress); int32_t dlistLength = ZDisplayList::GetDListLength( - parent->GetRawData(), unk_8_Offset, + parent->GetRawData(), dlist_Offset, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); - unk_8_dlist = new ZDisplayList(parent); - unk_8_dlist->ExtractFromBinary(unk_8_Offset, dlistLength); + ZDisplayList* dlist_data = new ZDisplayList(parent); + dlist_data->ExtractFromBinary(dlist_Offset, dlistLength); std::string dListStr = - StringHelper::Sprintf("%sSkinLimbDL_%06X", varPrefix.c_str(), unk_8_Offset); - unk_8_dlist->SetName(dListStr); - unk_8_dlist->DeclareVar(varPrefix, ""); - unk_8_dlist->DeclareReferences(varPrefix); - parent->AddResource(unk_8_dlist); + StringHelper::Sprintf("%sSkinLimbDL_%06X", varPrefix.c_str(), dlist_Offset); + dlist_data->SetName(dListStr); + dlist_data->DeclareVar(varPrefix, ""); + dlist_data->DeclareReferences(varPrefix); + parent->AddResource(dlist_data); } } -std::string Struct_800A5E28::GetBodySourceCode() const +std::string SkinAnimatedLimbData::GetBodySourceCode() const { - std::string unk_4_Str; - std::string unk_8_Str; - Globals::Instance->GetSegmentedPtrName(unk_4, parent, "Struct_800A598C", unk_4_Str, - parent->workerID); - Globals::Instance->GetSegmentedPtrName(unk_8, parent, "Gfx", unk_8_Str, parent->workerID); + std::string limbModifications_Str; + std::string dlist_Str; + Globals::Instance->GetSegmentedPtrName(limbModifications, parent, "SkinLimbModif", + limbModifications_Str, parent->workerID); + Globals::Instance->GetSegmentedPtrName(dlist, parent, "Gfx", dlist_Str, parent->workerID); std::string entryStr = "\n"; - entryStr += StringHelper::Sprintf("\t%i, ARRAY_COUNTU(%s),\n", unk_0, unk_4_Str.c_str()); - entryStr += StringHelper::Sprintf("\t%s, %s\n", unk_4_Str.c_str(), unk_8_Str.c_str()); + entryStr += StringHelper::Sprintf("\t%i, ARRAY_COUNTU(%s),\n", totalVtxCount, + limbModifications_Str.c_str()); + entryStr += + StringHelper::Sprintf("\t%s, %s\n", limbModifications_Str.c_str(), dlist_Str.c_str()); return entryStr; } -std::string Struct_800A5E28::GetSourceTypeName() const +std::string SkinAnimatedLimbData::GetSourceTypeName() const { - return "Struct_800A5E28"; + return "SkinAnimatedLimbData"; } -ZResourceType Struct_800A5E28::GetResourceType() const +ZResourceType SkinAnimatedLimbData::GetResourceType() const { // TODO return ZResourceType::Error; } -size_t Struct_800A5E28::GetRawDataSize() const +size_t SkinAnimatedLimbData::GetRawDataSize() const { return 0x0C; } diff --git a/ZAPD/OtherStructs/SkinLimbStructs.h b/ZAPD/OtherStructs/SkinLimbStructs.h index ce842ae..1358316 100644 --- a/ZAPD/OtherStructs/SkinLimbStructs.h +++ b/ZAPD/OtherStructs/SkinLimbStructs.h @@ -7,19 +7,17 @@ #include "ZResource.h" #include "ZDisplayList.h" -// TODO: check if more types exists enum class ZLimbSkinType { - SkinType_0, // Segment = 0 - SkinType_4 = 4, // Segment = segmented address // Struct_800A5E28 - SkinType_5 = 5, // Segment = 0 - SkinType_DList = 11, // Segment = DList address + SkinType_Null, // SkinLimb segment = NULL + SkinType_Animated = 4, // SkinLimb segment = SkinAnimatedLimbData* + SkinType_Normal = 11, // SkinLimb segment = Gfx* }; -class Struct_800A57C0 : public ZResource +class SkinVertex : public ZResource { public: - Struct_800A57C0(ZFile* nParent); + SkinVertex(ZFile* nParent); void ParseRawData() override; @@ -31,19 +29,19 @@ public: size_t GetRawDataSize() const override; public: - uint16_t unk_0; - int16_t unk_2; - int16_t unk_4; - int8_t unk_6; - int8_t unk_7; - int8_t unk_8; - uint8_t unk_9; + uint16_t index; + int16_t s; + int16_t t; + int8_t normX; + int8_t normY; + int8_t normZ; + uint8_t alpha; }; -class Struct_800A598C_2 : public ZResource +class SkinTransformation : public ZResource { public: - Struct_800A598C_2(ZFile* nParent); + SkinTransformation(ZFile* nParent); void ParseRawData() override; @@ -55,17 +53,17 @@ public: size_t GetRawDataSize() const override; public: - uint8_t unk_0; + uint8_t limbIndex; int16_t x; int16_t y; int16_t z; - uint8_t unk_8; + uint8_t scale; }; -class Struct_800A598C : public ZResource +class SkinLimbModif : public ZResource { public: - Struct_800A598C(ZFile* nParent); + SkinLimbModif(ZFile* nParent); void ParseRawData() override; void DeclareReferences(const std::string& prefix) override; @@ -78,20 +76,20 @@ public: size_t GetRawDataSize() const override; public: - uint16_t unk_0; // Length of unk_8 - uint16_t unk_2; // Length of unk_C - uint16_t unk_4; // 0 or 1 // Used as an index for unk_C - segptr_t unk_8; // Struct_800A57C0* - segptr_t unk_C; // Struct_800A598C_2* - - std::vector<Struct_800A57C0> unk_8_arr; - std::vector<Struct_800A598C_2> unk_C_arr; + uint16_t vtxCount; // Number of vertices in this modif entry + uint16_t transformCount; // Length of limbTransformations + uint16_t unk_4; // 0 or 1, used as an index for limbTransformations + segptr_t skinVertices; // SkinVertex* + segptr_t limbTransformations; // SkinTransformation* + + std::vector<SkinVertex> skinVertices_arr; + std::vector<SkinTransformation> limbTransformations_arr; }; -class Struct_800A5E28 : public ZResource +class SkinAnimatedLimbData : public ZResource { public: - Struct_800A5E28(ZFile* nParent); + SkinAnimatedLimbData(ZFile* nParent); void ParseRawData() override; void DeclareReferences(const std::string& prefix) override; @@ -104,11 +102,11 @@ public: size_t GetRawDataSize() const override; public: - uint16_t unk_0; // Vtx count - uint16_t unk_2; // Length of unk_4 - segptr_t unk_4; // Struct_800A598C* - segptr_t unk_8; // Gfx* + uint16_t totalVtxCount; + uint16_t limbModifCount; // Length of limbModifications + segptr_t limbModifications; // SkinLimbModif* + segptr_t dlist; // Gfx* - std::vector<Struct_800A598C> unk_4_arr; - ZDisplayList* unk_8_dlist = nullptr; + std::vector<SkinLimbModif> limbModifications_arr; + // ZDisplayList* unk_8_dlist = nullptr; }; diff --git a/ZAPD/OutputFormatter.h b/ZAPD/OutputFormatter.h index 391f410..2fa7a78 100644 --- a/ZAPD/OutputFormatter.h +++ b/ZAPD/OutputFormatter.h @@ -1,5 +1,6 @@ #pragma once +#include <cstdint> #include <map> #include <string> #include <vector> diff --git a/ZAPD/WarningHandler.cpp b/ZAPD/WarningHandler.cpp index 163b028..f416a5b 100644 --- a/ZAPD/WarningHandler.cpp +++ b/ZAPD/WarningHandler.cpp @@ -84,26 +84,27 @@ typedef struct */ // clang-format off static const std::unordered_map<std::string, WarningInfoInit> warningStringToInitMap = { - {"deprecated", {WarningType::Deprecated, + {"deprecated", {WarningType::Deprecated, #ifdef DEPRECATION_ON WarningLevel::Warn, #else WarningLevel::Off, #endif "Deprecated features"}}, - {"unaccounted", {WarningType::Unaccounted, WarningLevel::Off, "Large blocks of unaccounted"}}, - {"missing-offsets", {WarningType::MissingOffsets, WarningLevel::Warn, "Offset attribute missing in XML tag"}}, - {"intersection", {WarningType::Intersection, WarningLevel::Warn, "Two assets intersect"}}, - {"missing-attribute", {WarningType::MissingAttribute, WarningLevel::Warn, "Required attribute missing in XML tag"}}, - {"invalid-attribute-value", {WarningType::InvalidAttributeValue, WarningLevel::Err, "Attribute declared in XML is wrong"}}, - {"unknown-attribute", {WarningType::UnknownAttribute, WarningLevel::Warn, "Unknown attribute in XML entry tag"}}, - {"invalid-xml", {WarningType::InvalidXML, WarningLevel::Err, "XML has syntax errors"}}, - {"invalid-jpeg", {WarningType::InvalidJPEG, WarningLevel::Err, "JPEG file does not conform to the game's format requirements"}}, - {"invalid-png", {WarningType::InvalidPNG, WarningLevel::Err, "Issues arising when processing PNG data"}}, - {"invalid-extracted-data", {WarningType::InvalidExtractedData, WarningLevel::Err, "Extracted data does not have correct form"}}, - {"missing-segment", {WarningType::MissingSegment, WarningLevel::Warn, "Segment not given in File tag in XML"}}, - {"hardcoded-pointer", {WarningType::HardcodedPointer, WarningLevel::Warn, "ZAPD lacks the info to make a symbol, so must output a hardcoded pointer"}}, - {"not-implemented", {WarningType::NotImplemented, WarningLevel::Warn, "ZAPD does not currently support this feature"}}, + {"unaccounted", {WarningType::Unaccounted, WarningLevel::Off, "Large blocks of unaccounted"}}, + {"missing-offsets", {WarningType::MissingOffsets, WarningLevel::Warn, "Offset attribute missing in XML tag"}}, + {"intersection", {WarningType::Intersection, WarningLevel::Warn, "Two assets intersect"}}, + {"missing-attribute", {WarningType::MissingAttribute, WarningLevel::Warn, "Required attribute missing in XML tag"}}, + {"invalid-attribute-value", {WarningType::InvalidAttributeValue, WarningLevel::Err, "Attribute declared in XML is wrong"}}, + {"unknown-attribute", {WarningType::UnknownAttribute, WarningLevel::Warn, "Unknown attribute in XML entry tag"}}, + {"invalid-xml", {WarningType::InvalidXML, WarningLevel::Err, "XML has syntax errors"}}, + {"invalid-jpeg", {WarningType::InvalidJPEG, WarningLevel::Err, "JPEG file does not conform to the game's format requirements"}}, + {"invalid-png", {WarningType::InvalidPNG, WarningLevel::Err, "Issues arising when processing PNG data"}}, + {"invalid-extracted-data", {WarningType::InvalidExtractedData, WarningLevel::Err, "Extracted data does not have correct form"}}, + {"missing-segment", {WarningType::MissingSegment, WarningLevel::Warn, "Segment not given in File tag in XML"}}, + {"hardcoded-generic-pointer", {WarningType::HardcodedGenericPointer, WarningLevel::Off, "A generic segmented pointer must be produced"}}, + {"hardcoded-pointer", {WarningType::HardcodedPointer, WarningLevel::Warn, "ZAPD lacks the info to make a symbol, so must output a hardcoded pointer"}}, + {"not-implemented", {WarningType::NotImplemented, WarningLevel::Warn, "ZAPD does not currently support this feature"}}, }; /** @@ -229,7 +230,10 @@ void WarningHandler::ExtractedFilePreamble(const ZFile *parent, const ZResource* if (res != nullptr) { fprintf(stderr, "resource '%s' at ", res->GetName().c_str()); } - fprintf(stderr, "offset 0x%06X: \n\t", offset); + if (offset != static_cast<uint32_t>(-1)) { + fprintf(stderr, "offset 0x%06X:", offset); + } + fprintf(stderr, "\n\t"); } /** diff --git a/ZAPD/WarningHandler.h b/ZAPD/WarningHandler.h index bb0360a..f993300 100644 --- a/ZAPD/WarningHandler.h +++ b/ZAPD/WarningHandler.h @@ -81,6 +81,7 @@ enum class WarningType InvalidExtractedData, MissingSegment, HardcodedPointer, + HardcodedGenericPointer, NotImplemented, Max, }; diff --git a/ZAPD/ZAPD.vcxproj b/ZAPD/ZAPD.vcxproj index 505e411..77d0bd1 100644 --- a/ZAPD/ZAPD.vcxproj +++ b/ZAPD/ZAPD.vcxproj @@ -249,6 +249,7 @@ mkdir build\ZAPD <ClCompile Include="ZTextureAnimation.cpp" />
<ClCompile Include="ZVector.cpp" />
<ClCompile Include="ZVtx.cpp" />
+ <ClCompile Include="ZWaterbox.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\lib\elfio\elfio\elfio.hpp" />
@@ -272,6 +273,7 @@ mkdir build\ZAPD <ClInclude Include="CrashHandler.h" />
<ClInclude Include="CRC32.h" />
<ClInclude Include="Declaration.h" />
+ <ClInclude Include="ExporterSet.h" />
<ClInclude Include="GameConfig.h" />
<ClInclude Include="Globals.h" />
<ClInclude Include="ImageBackend.h" />
@@ -339,6 +341,7 @@ mkdir build\ZAPD <ClInclude Include="ZTextureAnimation.h" />
<ClInclude Include="ZVector.h" />
<ClInclude Include="ZVtx.h" />
+ <ClInclude Include="ZWaterbox.h" />
</ItemGroup>
<ItemGroup>
<Text Include="..\SymbolMap_OoTMqDbg.txt">
diff --git a/ZAPD/ZAPD.vcxproj.filters b/ZAPD/ZAPD.vcxproj.filters index ce89882..eac4719 100644 --- a/ZAPD/ZAPD.vcxproj.filters +++ b/ZAPD/ZAPD.vcxproj.filters @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
@@ -291,6 +291,12 @@ <ClCompile Include="ZSurfaceType.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
+ <ClCompile Include="ZActorList.cpp">
+ <Filter>Source Files\Z64</Filter>
+ </ClCompile>
+ <ClCompile Include="ZWaterbox.cpp">
+ <Filter>Source Files\Z64</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ZRoom\ZRoom.h">
@@ -554,6 +560,15 @@ <ClInclude Include="ZSurfaceType.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
+ <ClInclude Include="ZActorList.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="ExporterSet.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="ZWaterbox.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="..\SymbolMap_OoTMqDbg.txt">
diff --git a/ZAPD/ZAnimation.cpp b/ZAPD/ZAnimation.cpp index 1998514..c00fa4b 100644 --- a/ZAPD/ZAnimation.cpp +++ b/ZAPD/ZAnimation.cpp @@ -132,9 +132,8 @@ void ZNormalAnimation::DeclareReferences(const std::string& prefix) { for (size_t i = 0; i < rotationIndices.size(); i++) { - indicesStr += - StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x, - rotationIndices[i].y, rotationIndices[i].z); + indicesStr += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x, + rotationIndices[i].y, rotationIndices[i].z); if (i != (rotationIndices.size() - 1)) indicesStr += "\n"; @@ -177,7 +176,10 @@ size_t ZLinkAnimation::GetRawDataSize() const std::string ZLinkAnimation::GetSourceTypeName() const { - return "LinkAnimationHeader"; + if (Globals::Instance->game == ZGame::MM_RETAIL) + return "PlayerAnimationHeader"; + else + return "LinkAnimationHeader"; } void ZLinkAnimation::ParseRawData() @@ -198,8 +200,8 @@ std::string ZLinkAnimation::GetBodySourceCode() const /* ZCurveAnimation */ -TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, - uint32_t fileOffset) +CurveInterpKnot::CurveInterpKnot(ZFile* parent, const std::vector<uint8_t>& rawData, + uint32_t fileOffset) : parent(parent) { unk_00 = BitConverter::ToUInt16BE(rawData, fileOffset + 0); @@ -209,26 +211,26 @@ TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, unk_08 = BitConverter::ToFloatBE(rawData, fileOffset + 8); } -TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, - uint32_t fileOffset, size_t index) - : TransformData(parent, rawData, fileOffset + index * GetRawDataSize()) +CurveInterpKnot::CurveInterpKnot(ZFile* parent, const std::vector<uint8_t>& rawData, + uint32_t fileOffset, size_t index) + : CurveInterpKnot(parent, rawData, fileOffset + index * GetRawDataSize()) { } -std::string TransformData::GetBody([[maybe_unused]] const std::string& prefix) const +std::string CurveInterpKnot::GetBody([[maybe_unused]] const std::string& prefix) const { return StringHelper::Sprintf("0x%04X, 0x%04X, %i, %i, %ff", unk_00, unk_02, unk_04, unk_06, unk_08); } -size_t TransformData::GetRawDataSize() const +size_t CurveInterpKnot::GetRawDataSize() const { return 0x0C; } -std::string TransformData::GetSourceTypeName() +std::string CurveInterpKnot::GetSourceTypeName() { - return "TransformData"; + return "CurveInterpKnot"; } ZCurveAnimation::ZCurveAnimation(ZFile* nParent) : ZAnimation(nParent) @@ -324,7 +326,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix) } else { - decl->text = entryStr; + decl->declBody = entryStr; } } @@ -355,7 +357,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix) } else { - decl->text = entryStr; + decl->declBody = entryStr; } } @@ -383,7 +385,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix) } else { - decl->text = entryStr; + decl->declBody = entryStr; } } } @@ -393,7 +395,7 @@ std::string ZCurveAnimation::GetBodySourceCode() const std::string refIndexStr; Globals::Instance->GetSegmentedPtrName(refIndex, parent, "u8", refIndexStr, parent->workerID); std::string transformDataStr; - Globals::Instance->GetSegmentedPtrName(transformData, parent, "TransformData", + Globals::Instance->GetSegmentedPtrName(transformData, parent, "CurveInterpKnot", transformDataStr, parent->workerID); std::string copyValuesStr; Globals::Instance->GetSegmentedPtrName(copyValues, parent, "s16", copyValuesStr, @@ -415,7 +417,7 @@ DeclarationAlignment ZCurveAnimation::GetDeclarationAlignment() const std::string ZCurveAnimation::GetSourceTypeName() const { - return "TransformUpdateIndex"; + return "CurveAnimationHeader"; } /* ZLegacyAnimation */ @@ -448,7 +450,7 @@ void ZLegacyAnimation::ParseRawData() ptr = jointKeyOffset; for (int32_t i = 0; i < limbCount + 1; i++) { - JointKey key(parent); + LegacyJointKey key(parent); key.ExtractFromFile(ptr); jointKeyArray.push_back(key); @@ -519,10 +521,8 @@ std::string ZLegacyAnimation::GetBodySourceCode() const std::string frameDataName; std::string jointKeyName; - Globals::Instance->GetSegmentedPtrName(frameData, parent, "s16", frameDataName, - parent->workerID); - Globals::Instance->GetSegmentedPtrName(jointKey, parent, "JointKey", jointKeyName, - parent->workerID); + Globals::Instance->GetSegmentedPtrName(frameData, parent, "s16", frameDataName, parent->workerID); + Globals::Instance->GetSegmentedPtrName(jointKey, parent, "LegacyJointKey", jointKeyName, parent->workerID); body += StringHelper::Sprintf("\t%i, %i,\n", frameCount, limbCount); body += StringHelper::Sprintf("\t%s,\n", frameDataName.c_str()); @@ -541,11 +541,11 @@ size_t ZLegacyAnimation::GetRawDataSize() const return 0x0C; } -JointKey::JointKey(ZFile* nParent) : ZResource(nParent) +LegacyJointKey::LegacyJointKey(ZFile* nParent) : ZResource(nParent) { } -void JointKey::ParseRawData() +void LegacyJointKey::ParseRawData() { ZResource::ParseRawData(); @@ -558,23 +558,23 @@ void JointKey::ParseRawData() z = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x0A); } -std::string JointKey::GetBodySourceCode() const +std::string LegacyJointKey::GetBodySourceCode() const { return StringHelper::Sprintf("%6i, %6i, %6i, %6i, %6i, %6i", xMax, x, yMax, y, zMax, z); } -std::string JointKey::GetSourceTypeName() const +std::string LegacyJointKey::GetSourceTypeName() const { - return "JointKey"; + return "LegacyJointKey"; } -ZResourceType JointKey::GetResourceType() const +ZResourceType LegacyJointKey::GetResourceType() const { // TODO return ZResourceType::Error; } -size_t JointKey::GetRawDataSize() const +size_t LegacyJointKey::GetRawDataSize() const { return 0x0C; } diff --git a/ZAPD/ZAnimation.h b/ZAPD/ZAnimation.h index 956e7fa..157fb34 100644 --- a/ZAPD/ZAnimation.h +++ b/ZAPD/ZAnimation.h @@ -68,7 +68,7 @@ public: void ParseRawData() override; }; -class TransformData +class CurveInterpKnot { public: ZFile* parent; @@ -85,10 +85,10 @@ public: float unk_08; public: - TransformData() = default; - TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset); - TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset, - size_t index); + CurveInterpKnot() = default; + CurveInterpKnot(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset); + CurveInterpKnot(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset, + size_t index); [[nodiscard]] std::string GetBody(const std::string& prefix) const; @@ -103,7 +103,7 @@ public: ///* 0x0000 */ u8* refIndex; segptr_t refIndex = 0; - ///* 0x0004 */ TransformData* transformData; + ///* 0x0004 */ CurveInterpKnot* transformData; segptr_t transformData = 0; ///* 0x0008 */ s16* copyValues; segptr_t copyValues = 0; @@ -115,7 +115,7 @@ public: uint8_t limbCount = 0; std::vector<uint8_t> refIndexArr; - std::vector<TransformData> transformDataArr; + std::vector<CurveInterpKnot> transformDataArr; std::vector<int16_t> copyValuesArr; public: @@ -133,14 +133,14 @@ public: std::string GetSourceTypeName() const override; }; -// TransformUpdateIndex +// CurveAnimationHeader /* ZLegacyAnimation */ -class JointKey : public ZResource +class LegacyJointKey : public ZResource { public: - JointKey(ZFile* nParent); + LegacyJointKey(ZFile* nParent); void ParseRawData() override; std::string GetBodySourceCode() const override; @@ -173,8 +173,8 @@ public: protected: int16_t limbCount; segptr_t frameData; // s16* - segptr_t jointKey; // JointKey* + segptr_t jointKey; // LegacyJointKey* std::vector<uint16_t> frameDataArray; - std::vector<JointKey> jointKeyArray; + std::vector<LegacyJointKey> jointKeyArray; }; diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp index 8725e28..417f154 100644 --- a/ZAPD/ZArray.cpp +++ b/ZAPD/ZArray.cpp @@ -57,7 +57,7 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader) } res->parent = parent; res->SetInnerNode(true); - res->ExtractFromXML(child, childIndex); + res->ExtractWithXML(child, childIndex); childIndex += res->GetRawDataSize(); resList.push_back(res); @@ -76,11 +76,11 @@ Declaration* ZArray::DeclareVar(const std::string& prefix, const std::string& bo if (res->IsExternalResource()) { auto filepath = Globals::Instance->outputPath / name; - std::string includePath = StringHelper::Sprintf("%s.%s.inc", filepath.c_str(), + std::string includePath = StringHelper::Sprintf("%s.%s.inc", filepath.string().c_str(), res->GetExternalExtension().c_str()); decl = parent->AddDeclarationIncludeArray(rawDataIndex, includePath, GetRawDataSize(), GetSourceTypeName(), name, arrayCnt); - decl->text = bodyStr; + decl->declBody = bodyStr; decl->isExternal = true; } else @@ -110,6 +110,7 @@ std::string ZArray::GetBodySourceCode() const case ZResourceType::Vertex: case ZResourceType::CollisionPoly: case ZResourceType::SurfaceType: + case ZResourceType::Waterbox: output += resList.at(i)->GetBodySourceCode(); break; diff --git a/ZAPD/ZBackground.cpp b/ZAPD/ZBackground.cpp index 026002d..920945b 100644 --- a/ZAPD/ZBackground.cpp +++ b/ZAPD/ZBackground.cpp @@ -132,8 +132,13 @@ Declaration* ZBackground::DeclareVar(const std::string& prefix, Declaration* decl = parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(), GetSourceTypeName(), auxName, 0); - decl->arrayItemCntStr = "SCREEN_WIDTH * SCREEN_HEIGHT / 4"; - decl->forceArrayCnt = true; + + if (Globals::Instance->cfg.useScreenWidthHeightConstants) + { + decl->arrayItemCntStr = "SCREEN_WIDTH * SCREEN_HEIGHT / 4"; + decl->forceArrayCnt = true; + } + decl->staticConf = staticConf; return decl; } diff --git a/ZAPD/ZCollision.cpp b/ZAPD/ZCollision.cpp index e75cfe2..3424783 100644 --- a/ZAPD/ZCollision.cpp +++ b/ZAPD/ZCollision.cpp @@ -1,4 +1,5 @@ #include "ZCollision.h" +#include "ZWaterbox.h" #include <cassert> #include <cstdint> @@ -51,6 +52,7 @@ void ZCollisionHeader::ParseRawData() vertices.reserve(numVerts); polygons.reserve(numPolygons); + waterBoxes.reserve(numWaterBoxes); offset_t currentPtr = vtxSegmentOffset; @@ -84,7 +86,7 @@ void ZCollisionHeader::ParseRawData() ZSurfaceType surfaceType(parent); surfaceType.SetRawDataIndex(polyTypeDefSegmentOffset + (i * 8)); surfaceType.ParseRawData(); - PolygonTypes.push_back(surfaceType); + polygonTypes.push_back(surfaceType); } // polygonTypes.push_back( // BitConverter::ToUInt64BE(rawData, polyTypeDefSegmentOffset + (i * 8))); @@ -98,38 +100,55 @@ void ZCollisionHeader::ParseRawData() // usually ordered. If for some reason the data was in some other funny // order, this would probably break. // The most common ordering is: - // - *CamData* + // - *BgCamInfo* // - SurfaceType // - CollisionPoly // - Vertices // - WaterBoxes // - CollisionHeader offset_t upperCameraBoundary = polyTypeDefSegmentOffset; - if (upperCameraBoundary == 0) + if (upperCameraBoundary == SEGMENTED_NULL) { upperCameraBoundary = polySegmentOffset; } - if (upperCameraBoundary == 0) + if (upperCameraBoundary == SEGMENTED_NULL) { upperCameraBoundary = vtxSegmentOffset; } - if (upperCameraBoundary == 0) + if (upperCameraBoundary == SEGMENTED_NULL) { upperCameraBoundary = waterBoxSegmentOffset; } - if (upperCameraBoundary == 0) + if (upperCameraBoundary == SEGMENTED_NULL) { upperCameraBoundary = rawDataIndex; } + // Sharp Ocarina places the CamDataEntries above the list so we need to calculate the number + // of cameras differently. + if (upperCameraBoundary < camDataSegmentOffset) + { + offset_t offset = camDataSegmentOffset; + while (rawData[offset] == 0x00 && rawData[offset + 0x4] == 0x02) + { + offset += 0x08; + } + upperCameraBoundary = offset; + } + camData = new CameraDataList(parent, name, rawData, camDataSegmentOffset, upperCameraBoundary); } - for (uint16_t i = 0; i < numWaterBoxes; i++) - waterBoxes.push_back(WaterBoxHeader( - rawData, - waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16)))); + for (int32_t i = 0; i < numWaterBoxes; i++) + { + ZWaterbox waterbox(parent); + + waterbox.SetRawDataIndex(waterBoxSegmentOffset + + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16))); + waterbox.ParseRawData(); + waterBoxes.emplace_back(waterbox); + } } void ZCollisionHeader::DeclareReferences(const std::string& prefix) @@ -153,9 +172,11 @@ void ZCollisionHeader::DeclareReferences(const std::string& prefix) } } - parent->AddDeclarationArray( - waterBoxSegmentOffset, DeclarationAlignment::Align4, 16 * waterBoxes.size(), "WaterBox", - StringHelper::Sprintf("%sWaterBoxes", auxName.c_str()), waterBoxes.size(), declaration); + parent->AddDeclarationArray(waterBoxSegmentOffset, DeclarationAlignment::Align4, + waterBoxes[0].GetRawDataSize() * waterBoxes.size(), + waterBoxes[0].GetSourceTypeName().c_str(), + StringHelper::Sprintf("%sWaterBoxes", auxName.c_str()), + waterBoxes.size(), declaration); } if (polygons.size() > 0) @@ -166,8 +187,7 @@ void ZCollisionHeader::DeclareReferences(const std::string& prefix) { for (size_t i = 0; i < polygons.size(); i++) { - declaration += - StringHelper::Sprintf("\t%s,", polygons[i].GetBodySourceCode().c_str()); + declaration += StringHelper::Sprintf("\t%s,", polygons[i].GetBodySourceCode().c_str()); if (i + 1 < polygons.size()) declaration += "\n"; } @@ -180,17 +200,17 @@ void ZCollisionHeader::DeclareReferences(const std::string& prefix) } declaration.clear(); - for (const auto& polyType : PolygonTypes) + for (const auto& polyType : polygonTypes) { declaration += StringHelper::Sprintf("\t%s,", polyType.GetBodySourceCode().c_str()); } if (polyTypeDefAddress != SEGMENTED_NULL) parent->AddDeclarationArray(polyTypeDefSegmentOffset, DeclarationAlignment::Align4, - PolygonTypes.size() * 8, - PolygonTypes[0].GetSourceTypeName().c_str(), + polygonTypes.size() * 8, + polygonTypes[0].GetSourceTypeName().c_str(), StringHelper::Sprintf("%sSurfaceType", auxName.c_str()), - PolygonTypes.size(), declaration); + polygonTypes.size(), declaration); declaration.clear(); @@ -233,27 +253,38 @@ std::string ZCollisionHeader::GetBodySourceCode() const std::string vtxName; Globals::Instance->GetSegmentedPtrName(vtxAddress, parent, "Vec3s", vtxName, parent->workerID); - declaration += StringHelper::Sprintf("\t%i,\n\t%s,\n", numVerts, vtxName.c_str()); + + if (numVerts > 0) + declaration += + StringHelper::Sprintf("\tARRAY_COUNT(%s), %s,\n", vtxName.c_str(), vtxName.c_str()); + else + declaration += StringHelper::Sprintf("\t%i, %s,\n", numVerts, vtxName.c_str()); std::string polyName; - Globals::Instance->GetSegmentedPtrName(polyAddress, parent, "CollisionPoly", polyName, - parent->workerID); - declaration += StringHelper::Sprintf("\t%i,\n\t%s,\n", numPolygons, polyName.c_str()); + Globals::Instance->GetSegmentedPtrName(polyAddress, parent, "CollisionPoly", polyName, parent->workerID); + + if (numPolygons > 0) + declaration += + StringHelper::Sprintf("\tARRAY_COUNT(%s), %s,\n", polyName.c_str(), polyName.c_str()); + else + declaration += StringHelper::Sprintf("\t%i, %s,\n", numPolygons, polyName.c_str()); std::string surfaceName; - Globals::Instance->GetSegmentedPtrName(polyTypeDefAddress, parent, "SurfaceType", surfaceName, - parent->workerID); + Globals::Instance->GetSegmentedPtrName(polyTypeDefAddress, parent, "SurfaceType", surfaceName, parent->workerID); declaration += StringHelper::Sprintf("\t%s,\n", surfaceName.c_str()); std::string camName; - Globals::Instance->GetSegmentedPtrName(camDataAddress, parent, "CamData", camName, - parent->workerID); + Globals::Instance->GetSegmentedPtrName(camDataAddress, parent, "BgCamInfo", camName, parent->workerID); declaration += StringHelper::Sprintf("\t%s,\n", camName.c_str()); std::string waterBoxName; - Globals::Instance->GetSegmentedPtrName(waterBoxAddress, parent, "WaterBox", waterBoxName, - parent->workerID); - declaration += StringHelper::Sprintf("\t%i,\n\t%s\n", numWaterBoxes, waterBoxName.c_str()); + Globals::Instance->GetSegmentedPtrName(waterBoxAddress, parent, "WaterBox", waterBoxName, parent->workerID); + + if (numWaterBoxes > 0) + declaration += StringHelper::Sprintf("\tARRAY_COUNT(%s), %s\n", waterBoxName.c_str(), + waterBoxName.c_str()); + else + declaration += StringHelper::Sprintf("\t%i, %s\n", numWaterBoxes, waterBoxName.c_str()); return declaration; } @@ -309,73 +340,93 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, assert(numElements < 10000); offset_t cameraPosDataSeg = rawDataIndex; + uint32_t numDataTotal; + uint32_t cameraPosDataSegEnd = rawDataIndex; + bool isSharpOcarina = false; + for (size_t i = 0; i < numElements; i++) { - CameraDataEntry* entry = new CameraDataEntry(); + CameraDataEntry entry; - entry->cameraSType = + entry.cameraSType = BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 0); - entry->numData = BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 2); - entry->cameraPosDataSeg = + entry.numData = BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 2); + entry.cameraPosDataSeg = BitConverter::ToInt32BE(rawData, rawDataIndex + (entries.size() * 8) + 4); - if (entry->cameraPosDataSeg != 0 && GETSEGNUM(entry->cameraPosDataSeg) != SEGMENT_SCENE) + if (entry.cameraPosDataSeg != 0 && GETSEGNUM(entry.cameraPosDataSeg) != SEGMENT_SCENE) { cameraPosDataSeg = rawDataIndex + (entries.size() * 8); break; } - if (entry->cameraPosDataSeg != 0 && cameraPosDataSeg > (entry->cameraPosDataSeg & 0xFFFFFF)) - cameraPosDataSeg = (entry->cameraPosDataSeg & 0xFFFFFF); + if (rawDataIndex > GETSEGOFFSET(entry.cameraPosDataSeg)) + { + if (entry.cameraPosDataSeg != 0 && + cameraPosDataSeg > GETSEGOFFSET(entry.cameraPosDataSeg)) + cameraPosDataSeg = GETSEGOFFSET(entry.cameraPosDataSeg); + } + else + { + // Sharp Ocarina will place the cam data after the list as opposed to the original maps + // which have it before. + isSharpOcarina = true; + cameraPosDataSeg = rawDataIndex + (numElements * 0x8); + if (cameraPosDataSegEnd < GETSEGOFFSET(entry.cameraPosDataSeg)) + cameraPosDataSegEnd = GETSEGOFFSET(entry.cameraPosDataSeg); + } - entries.push_back(entry); + entries.emplace_back(entry); } // Setting cameraPosDataAddr to rawDataIndex give a pos list length of 0 - uint32_t cameraPosDataOffset = cameraPosDataSeg & 0xFFFFFF; + uint32_t cameraPosDataOffset = GETSEGOFFSET(cameraPosDataSeg); for (size_t i = 0; i < entries.size(); i++) { char camSegLine[2048]; - if (entries[i]->cameraPosDataSeg != 0) + if (entries[i].cameraPosDataSeg != 0) { - int32_t index = - ((entries[i]->cameraPosDataSeg & 0x00FFFFFF) - cameraPosDataOffset) / 0x6; - sprintf(camSegLine, "&%sCamPosData[%i]", prefix.c_str(), index); + uint32_t index = + (GETSEGOFFSET(entries[i].cameraPosDataSeg) - cameraPosDataOffset) / 0x6; + snprintf(camSegLine, 2048, "&%sCamPosData[%i]", prefix.c_str(), index); } else - sprintf(camSegLine, "NULL"); + snprintf(camSegLine, 2048, "NULL"); declaration += - StringHelper::Sprintf(" { 0x%04X, %i, %s },", entries[i]->cameraSType, - entries[i]->numData, camSegLine, rawDataIndex + (i * 8)); + StringHelper::Sprintf(" { 0x%04X, %i, %s },", entries[i].cameraSType, + entries[i].numData, camSegLine, rawDataIndex + (i * 8)); if (i < entries.size() - 1) declaration += "\n"; } parent->AddDeclarationArray( - rawDataIndex, DeclarationAlignment::Align4, entries.size() * 8, "CamData", + rawDataIndex, DeclarationAlignment::Align4, entries.size() * 8, "BgCamInfo", StringHelper::Sprintf("%sCamDataList", prefix.c_str(), rawDataIndex), entries.size(), declaration); - uint32_t numDataTotal = (rawDataIndex - cameraPosDataOffset) / 0x6; + if (!isSharpOcarina) + numDataTotal = (rawDataIndex - cameraPosDataOffset) / 0x6; + else + numDataTotal = ((cameraPosDataSegEnd - cameraPosDataSeg) + 18) / 0x6; if (numDataTotal > 0) { declaration.clear(); + cameraPositionData.reserve(numDataTotal); for (uint32_t i = 0; i < numDataTotal; i++) { - CameraPositionData* data = - new CameraPositionData(rawData, cameraPosDataOffset + (i * 6)); - cameraPositionData.push_back(data); + CameraPositionData data = CameraPositionData(rawData, cameraPosDataOffset + (i * 6)); - declaration += StringHelper::Sprintf("\t{ %6i, %6i, %6i },", data->x, data->y, data->z); + declaration += StringHelper::Sprintf("\t{ %6i, %6i, %6i },", data.x, data.y, data.z); + cameraPositionData.emplace_back(data); if (i + 1 < numDataTotal) declaration += "\n"; } - int32_t cameraPosDataIndex = GETSEGOFFSET(cameraPosDataSeg); + uint32_t cameraPosDataIndex = GETSEGOFFSET(cameraPosDataSeg); uint32_t entrySize = numDataTotal * 0x6; parent->AddDeclarationArray(cameraPosDataIndex, DeclarationAlignment::Align4, entrySize, "Vec3s", StringHelper::Sprintf("%sCamPosData", prefix.c_str()), diff --git a/ZAPD/ZCollision.h b/ZAPD/ZCollision.h index 7db03bf..8c73d2e 100644 --- a/ZAPD/ZCollision.h +++ b/ZAPD/ZCollision.h @@ -6,22 +6,7 @@ #include "ZRoom/ZRoom.h" #include "ZSurfaceType.h" #include "ZVector.h" - -class WaterBoxHeader -{ -public: - int16_t xMin; - int16_t ySurface; - int16_t zMin; - int16_t xLength; - int16_t zLength; - int16_t pad; - int32_t properties; - - WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); - - std::string GetBodySourceCode() const; -}; +#include "ZWaterbox.h" class CameraPositionData { @@ -34,16 +19,16 @@ public: class CameraDataEntry { public: - uint16_t cameraSType; + int16_t cameraSType; int16_t numData; - int32_t cameraPosDataSeg; + offset_t cameraPosDataSeg; }; class CameraDataList { public: - std::vector<CameraDataEntry*> entries; - std::vector<CameraPositionData*> cameraPositionData; + std::vector<CameraDataEntry> entries; + std::vector<CameraPositionData> cameraPositionData; CameraDataList(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData, offset_t rawDataIndex, offset_t upperCameraBoundary); @@ -70,8 +55,8 @@ public: std::vector<ZVector> vertices; std::vector<ZCollisionPoly> polygons; - std::vector<ZSurfaceType> PolygonTypes; - std::vector<WaterBoxHeader> waterBoxes; + std::vector<ZSurfaceType> polygonTypes; + std::vector<ZWaterbox> waterBoxes; CameraDataList* camData = nullptr; ZCollisionHeader(ZFile* nParent); diff --git a/ZAPD/ZCutscene.cpp b/ZAPD/ZCutscene.cpp index 6058949..56f53f7 100644 --- a/ZAPD/ZCutscene.cpp +++ b/ZAPD/ZCutscene.cpp @@ -3,7 +3,6 @@ #include <cassert> #include "Globals.h" -#include "OtherStructs/CutsceneMM_Commands.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" #include "WarningHandler.h" @@ -130,174 +129,147 @@ void ZCutscene::ParseRawData() CutsceneCommand* ZCutscene::GetCommandOoT(uint32_t id, offset_t currentPtr) const { - CutsceneCommands cmdID = static_cast<CutsceneCommands>(id); + CutsceneOoT_CommandType cmdID = static_cast<CutsceneOoT_CommandType>(id); const auto& rawData = parent->GetRawData(); - switch (id) - { - case 10: // CutsceneCommands::SetPlayerAction - case 15: // CutsceneCommands::SetActorAction1 - case 17: - case 18: - case 23: - case 34: - case 39: - case 46: - case 76: - case 85: - case 93: - case 105: - case 107: - case 110: - case 119: - case 123: - case 138: - case 139: - case 144: - case 14: // CutsceneCommands::SetActorAction2 - case 16: - case 24: - case 35: - case 40: - case 48: - case 64: - case 68: - case 70: - case 78: - case 80: - case 94: - case 116: - case 118: - case 120: - case 125: - case 131: - case 141: - case 25: // CutsceneCommands::SetActorAction3 - case 36: - case 41: - case 50: - case 67: - case 69: - case 72: - case 81: - case 106: - case 117: - case 121: - case 126: - case 132: - case 29: // CutsceneCommands::SetActorAction4 - case 37: - case 42: - case 51: - case 53: - case 63: - case 65: - case 66: - case 75: - case 82: - case 108: - case 127: - case 133: - case 30: // CutsceneCommands::SetActorAction5 - case 38: - case 43: - case 47: - case 54: - case 79: - case 83: - case 128: - case 135: - case 44: // CutsceneCommands::SetActorAction6 - case 55: - case 77: - case 84: - case 90: - case 129: - case 136: - case 31: // CutsceneCommands::SetActorAction7 - case 52: - case 57: - case 58: - case 88: - case 115: - case 130: - case 137: - case 49: // CutsceneCommands::SetActorAction8 - case 60: - case 89: - case 111: - case 114: - case 134: - case 142: - case 62: // CutsceneCommands::SetActorAction9 - case 143: // CutsceneCommands::SetActorAction10 - return new CutsceneCommand_ActorAction(rawData, currentPtr); - - case 0x0B: - case 0x0D: - case 0x1A: - case 0x1B: - case 0x1C: - case 0x20: - case 0x21: - case 0x3B: - case 0x3D: - case 0x47: - case 0x49: - case 0x6D: - case 0x15: - case 0x16: - case 0x70: - case 0x71: - case 0x4A: - return new CutsceneCommand_GenericCmd(rawData, currentPtr, cmdID); - } - switch (cmdID) { - case CutsceneCommands::Misc: - case CutsceneCommands::SetLighting: - case CutsceneCommands::PlayBGM: - case CutsceneCommands::StopBGM: - case CutsceneCommands::FadeBGM: - return new CutsceneCommand_GenericCmd(rawData, currentPtr, cmdID); - - case CutsceneCommands::SetCameraPos: - case CutsceneCommands::SetCameraFocus: - case CutsceneCommands::SetCameraPosLink: - case CutsceneCommands::SetCameraFocusLink: - return new CutsceneCommandSetCameraPos(rawData, currentPtr); - - case CutsceneCommands::Cmd07: - break; - case CutsceneCommands::Cmd08: + case CutsceneOoT_CommandType::CS_CMD_PLAYER_CUE: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_1: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_1: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_2: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_3: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_2: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_4_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_6_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_4: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_3: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_1: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_1: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_4_1: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_5: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_4: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_2: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_2: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_4_2: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_5_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_6: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_4_3: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_5: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_7_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_3: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_3: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_6_1: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_4: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_4_4: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_5_1: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_6_2: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_6_3: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_7_1: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_8_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_5: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_6: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_6: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_7: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_4: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_7: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_5: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_8: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_6: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_7: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_8: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_7: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_5_2: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_9: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_4_5: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_10: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_8: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_9: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_4_6: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_5_3: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_8: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_6_4: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_7_2: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_5_4: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_9: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_11: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_10: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_9: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_11: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_10: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_12: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_7_3: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_7_4: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_6_5: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_12: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_10: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_13: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_13: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_14: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_11: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_14: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_15: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_12: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_11: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_4_7: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_5_5: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_6_6: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_16: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_2_13: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_3_12: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_7_5: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_4_8: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_5_6: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_6_7: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_15: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_16: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_1_17: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_7_6: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_9_0: + case CutsceneOoT_CommandType::CS_CMD_ACTOR_CUE_0_17: + return new CutsceneOoTCommand_ActorCue(rawData, currentPtr); + + case CutsceneOoT_CommandType::CS_CMD_MISC: + case CutsceneOoT_CommandType::CS_CMD_LIGHT_SETTING: + case CutsceneOoT_CommandType::CS_CMD_START_SEQ: + case CutsceneOoT_CommandType::CS_CMD_STOP_SEQ: + case CutsceneOoT_CommandType::CS_CMD_FADE_OUT_SEQ: + return new CutsceneOoTCommand_GenericCmd(rawData, currentPtr, cmdID); + + case CutsceneOoT_CommandType::CS_CMD_CAM_EYE_SPLINE: + case CutsceneOoT_CommandType::CS_CMD_CAM_AT_SPLINE: + case CutsceneOoT_CommandType::CS_CMD_CAM_EYE_SPLINE_REL_TO_PLAYER: + case CutsceneOoT_CommandType::CS_CMD_CAM_AT_SPLINE_REL_TO_PLAYER: + return new CutsceneOoTCommand_GenericCameraCmd(rawData, currentPtr); + + case CutsceneOoT_CommandType::CS_CMD_RUMBLE_CONTROLLER: + return new CutsceneOoTCommand_Rumble(rawData, currentPtr); + + case CutsceneOoT_CommandType::CS_CMD_TEXT: + return new CutsceneOoTCommand_Text(rawData, currentPtr); + + case CutsceneOoT_CommandType::CS_CMD_TRANSITION: + return new CutsceneOoTCommand_Transition(rawData, currentPtr); + + case CutsceneOoT_CommandType::CS_CMD_TIME: + return new CutsceneCommand_Time(rawData, currentPtr); + + case CutsceneOoT_CommandType::CS_CMD_DESTINATION: + return new CutsceneOoTCommand_Destination(rawData, currentPtr); + + case CutsceneOoT_CommandType::CS_CMD_CAM_EYE: + case CutsceneOoT_CommandType::CS_CMD_CAM_AT: 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); + default: + std::string errorHeader = + StringHelper::Sprintf("Warning: Invalid cutscene command ID: '0x%04X'", cmdID); + return new CutsceneOoTCommand_GenericCmd(rawData, currentPtr, cmdID); } return nullptr; @@ -305,60 +277,74 @@ CutsceneCommand* ZCutscene::GetCommandOoT(uint32_t id, offset_t currentPtr) cons CutsceneCommand* ZCutscene::GetCommandMM(uint32_t id, offset_t currentPtr) const { - CutsceneMMCommands cmdID = static_cast<CutsceneMMCommands>(id); + CutsceneMM_CommandType cmdID = static_cast<CutsceneMM_CommandType>(id); const auto& rawData = parent->GetRawData(); - if (((id >= 100) && (id < 150)) || (id == 201) || ((id >= 450) && (id < 600))) + if (((id >= (uint32_t)CutsceneMM_CommandType::CS_CMD_ACTOR_CUE_100) && + (id <= (uint32_t)CutsceneMM_CommandType::CS_CMD_ACTOR_CUE_149)) || + (id == (uint32_t)CutsceneMM_CommandType::CS_CMD_ACTOR_CUE_201) || + ((id >= (uint32_t)CutsceneMM_CommandType::CS_CMD_ACTOR_CUE_450) && + (id <= (uint32_t)CutsceneMM_CommandType::CS_CMD_ACTOR_CUE_599))) { - return new CutsceneCommand_ActorAction(rawData, currentPtr); + return new CutsceneMMCommand_ActorCue(rawData, currentPtr); } switch (cmdID) { - 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: + case CutsceneMM_CommandType::CS_CMD_MISC: + case CutsceneMM_CommandType::CS_CMD_LIGHT_SETTING: + case CutsceneMM_CommandType::CS_CMD_TRANSITION: + case CutsceneMM_CommandType::CS_CMD_MOTION_BLUR: + case CutsceneMM_CommandType::CS_CMD_GIVE_TATL: + case CutsceneMM_CommandType::CS_CMD_START_SEQ: + case CutsceneMM_CommandType::CS_CMD_SFX_REVERB_INDEX_2: + case CutsceneMM_CommandType::CS_CMD_SFX_REVERB_INDEX_1: + case CutsceneMM_CommandType::CS_CMD_MODIFY_SEQ: + case CutsceneMM_CommandType::CS_CMD_STOP_SEQ: + case CutsceneMM_CommandType::CS_CMD_START_AMBIENCE: + case CutsceneMM_CommandType::CS_CMD_FADE_OUT_AMBIENCE: + case CutsceneMM_CommandType::CS_CMD_DESTINATION: + case CutsceneMM_CommandType::CS_CMD_CHOOSE_CREDITS_SCENES: + + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_FA: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_FE: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_FF: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_100: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_101: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_102: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_103: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_104: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_105: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_108: + case CutsceneMM_CommandType::CS_CMD_UNK_DATA_109: return new CutsceneMMCommand_GenericCmd(rawData, currentPtr, cmdID); - case CutsceneMMCommands::CS_CMD_TEXTBOX: - return new CutsceneCommand_TextBox(rawData, currentPtr); - case CutsceneMMCommands::CS_CMD_CAMERA: + case CutsceneMM_CommandType::CS_CMD_TEXT: + return new CutsceneMMCommand_Text(rawData, currentPtr); + + case CutsceneMM_CommandType::CS_CMD_CAMERA_SPLINE: 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); + + case CutsceneMM_CommandType::CS_CMD_TRANSITION_GENERAL: + return new CutsceneMMCommand_TransitionGeneral(rawData, currentPtr); + + case CutsceneMM_CommandType::CS_CMD_FADE_OUT_SEQ: + return new CutsceneMMCommand_FadeOutSeq(rawData, currentPtr); + + case CutsceneMM_CommandType::CS_CMD_TIME: + return new CutsceneCommand_Time(rawData, currentPtr); + + case CutsceneMM_CommandType::CS_CMD_PLAYER_CUE: + return new CutsceneMMCommand_ActorCue(rawData, currentPtr); + + case CutsceneMM_CommandType::CS_CMD_RUMBLE: + return new CutsceneMMCommand_Rumble(rawData, currentPtr); + + default: + std::string errorHeader = + StringHelper::Sprintf("Warning: Invalid cutscene command ID: '0x%04X'", cmdID); + return new CutsceneMMCommand_GenericCmd(rawData, currentPtr, cmdID); } return nullptr; diff --git a/ZAPD/ZCutscene.h b/ZAPD/ZCutscene.h index 098f3ad..5b54426 100644 --- a/ZAPD/ZCutscene.h +++ b/ZAPD/ZCutscene.h @@ -5,7 +5,8 @@ #include <vector> #include "tinyxml2.h" -#include "OtherStructs/Cutscene_Commands.h" +#include "OtherStructs/CutsceneOoT_Commands.h" +#include "OtherStructs/CutsceneMM_Commands.h" #include "ZFile.h" #include "ZResource.h" diff --git a/ZAPD/ZDisplayList.cpp b/ZAPD/ZDisplayList.cpp index 9a43a2a..cad2769 100644 --- a/ZAPD/ZDisplayList.cpp +++ b/ZAPD/ZDisplayList.cpp @@ -159,7 +159,7 @@ ZDisplayList::~ZDisplayList() } // EXTRACT MODE -void ZDisplayList::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) +void ZDisplayList::ExtractWithXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) { rawDataIndex = nRawDataIndex; ParseXML(reader); @@ -828,7 +828,7 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, const std::string& prefix, char* l if (!Globals::Instance->HasSegment(segNum, parent->workerID)) sprintf(line, "gsSPBranchList(0x%08" PRIX64 "),", data & 0xFFFFFFFF); else if (dListDecl != nullptr) - sprintf(line, "gsSPBranchList(%s),", dListDecl->varName.c_str()); + sprintf(line, "gsSPBranchList(%s),", dListDecl->declName.c_str()); else sprintf(line, "gsSPBranchList(%sDlist0x%06" PRIX64 "),", prefix.c_str(), GETSEGOFFSET(data)); @@ -838,7 +838,7 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, const std::string& prefix, char* l if (!Globals::Instance->HasSegment(segNum, parent->workerID)) sprintf(line, "gsSPDisplayList(0x%08" PRIX64 "),", data & 0xFFFFFFFF); else if (dListDecl != nullptr) - sprintf(line, "gsSPDisplayList(%s),", dListDecl->varName.c_str()); + sprintf(line, "gsSPDisplayList(%s),", dListDecl->declName.c_str()); else sprintf(line, "gsSPDisplayList(%sDlist0x%06" PRIX64 "),", prefix.c_str(), GETSEGOFFSET(data)); @@ -1078,7 +1078,7 @@ void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, const std::string& prefix, ch } if (texDecl != nullptr) - sprintf(texStr, "%s", texDecl->varName.c_str()); + sprintf(texStr, "%s", texDecl->declName.c_str()); else if (data != 0 && Globals::Instance->HasSegment(segmentNumber, parent->workerID)) sprintf(texStr, "%sTex_%06X", prefix.c_str(), texAddress); else @@ -1762,7 +1762,14 @@ static int32_t GfxdCallback_Vtx(uint32_t seg, int32_t count) vtxList.push_back(vtx); currentPtr += 16; } - self->vertices[vtxOffset] = vtxList; + + bool keyAlreadyOccupied = self->vertices.find(vtxOffset) != self->vertices.end(); + + // In some cases a vtxList already exists at vtxOffset. Only override the existing list + // if the new one is bigger. + if (!keyAlreadyOccupied || + (keyAlreadyOccupied && vtxList.size() > self->vertices[vtxOffset].size())) + self->vertices[vtxOffset] = vtxList; } } @@ -1830,18 +1837,26 @@ static int32_t GfxdCallback_DisplayList(uint32_t seg) uint32_t dListSegNum = GETSEGNUM(seg); std::string dListName = ""; - bool addressFound = Globals::Instance->GetSegmentedPtrName(seg, self->parent, "Gfx", dListName, - self->parent->workerID); + bool addressFound = + Globals::Instance->GetSegmentedPtrName(seg, self->parent, "Gfx", dListName, false, self->parent->workerID); - if (!addressFound && self->parent->segment == dListSegNum) + if (!addressFound) { - ZDisplayList* newDList = new ZDisplayList(self->parent); - newDList->ExtractFromBinary( - dListOffset, - self->GetDListLength(self->parent->GetRawData(), dListOffset, self->dListType)); - newDList->SetName(newDList->GetDefaultName(self->parent->GetName())); - self->otherDLists.push_back(newDList); - dListName = newDList->GetName(); + if (self->parent->segment == dListSegNum) + { + ZDisplayList* newDList = new ZDisplayList(self->parent); + newDList->ExtractFromBinary( + dListOffset, + self->GetDListLength(self->parent->GetRawData(), dListOffset, self->dListType)); + newDList->SetName(newDList->GetDefaultName(self->parent->GetName())); + self->otherDLists.push_back(newDList); + dListName = newDList->GetName(); + } + else + { + Globals::Instance->WarnHardcodedPointer(seg, self->parent, self, + self->GetRawDataIndex()); + } } gfxd_puts(dListName.c_str()); @@ -1854,23 +1869,31 @@ static int32_t GfxdCallback_Matrix(uint32_t seg) std::string mtxName; ZDisplayList* self = static_cast<ZDisplayList*>(gfxd_udata_get()); - bool addressFound = Globals::Instance->GetSegmentedPtrName(seg, self->parent, "Mtx", mtxName, - self->parent->workerID); - if (!addressFound && GETSEGNUM(seg) == self->parent->segment) + bool addressFound = + Globals::Instance->GetSegmentedPtrName(seg, self->parent, "Mtx", mtxName, false, self->parent->workerID); + + if (!addressFound) { - Declaration* decl = - self->parent->GetDeclaration(Seg2Filespace(seg, self->parent->baseAddress)); - if (decl == nullptr) + if (GETSEGNUM(seg) == self->parent->segment) { - ZMtx* mtx = new ZMtx(self->parent); - mtx->SetName(mtx->GetDefaultName(self->GetName())); - mtx->ExtractFromFile(Seg2Filespace(seg, self->parent->baseAddress)); - mtx->DeclareVar(self->GetName(), ""); - - mtx->GetSourceOutputCode(self->GetName()); - self->mtxList.push_back(*mtx); - self->parent->resources.push_back(mtx); - mtxName = "&" + mtx->GetName(); + Declaration* decl = + self->parent->GetDeclaration(Seg2Filespace(seg, self->parent->baseAddress)); + if (decl == nullptr) + { + ZMtx mtx(self->parent); + mtx.SetName(mtx.GetDefaultName(self->GetName())); + mtx.ExtractFromFile(Seg2Filespace(seg, self->parent->baseAddress)); + mtx.DeclareVar(self->GetName(), ""); + + mtx.GetSourceOutputCode(self->GetName()); + self->mtxList.push_back(mtx); + mtxName = "&" + mtx.GetName(); + } + } + else + { + Globals::Instance->WarnHardcodedPointer(seg, self->parent, self, + self->GetRawDataIndex()); } } @@ -2012,7 +2035,8 @@ void ZDisplayList::DeclareReferences(const std::string& prefix) vtxName = StringHelper::Sprintf("%sVtx_%06X", prefix.c_str(), vtxKeys[i]); auto filepath = Globals::Instance->outputPath / vtxName; - std::string incStr = StringHelper::Sprintf("%s.%s.inc", filepath.string().c_str(), "vtx"); + std::string incStr = + StringHelper::Sprintf("%s.%s.inc", filepath.string().c_str(), "vtx"); Declaration* vtxDecl = parent->AddDeclarationIncludeArray( vtxKeys[i], incStr, item.size() * 16, "Vtx", vtxName, item.size()); @@ -2096,9 +2120,46 @@ std::string ZDisplayList::ProcessGfxDis([[maybe_unused]] const std::string& pref gfxd_execute(); // generate display list sourceOutput += outputformatter.GetOutput(); // write formatted display list + MergeConnectingVertexLists(); + return sourceOutput; } +void ZDisplayList::MergeConnectingVertexLists() +{ + if (vertices.size() > 0) + { + std::vector<std::pair<uint32_t, std::vector<ZVtx>>> vertexKeys(vertices.begin(), + vertices.end()); + std::pair<uint32_t, std::vector<ZVtx>> lastItem = vertexKeys.at(0); + + for (size_t i = 1; i < vertexKeys.size(); i++) + { + std::pair<uint32_t, std::vector<ZVtx>> curItem = vertexKeys[i]; + + size_t lastItemEnd = lastItem.first + (lastItem.second.size() * 16); + bool lastItemIntersects = lastItemEnd >= curItem.first; + + if (lastItemIntersects) + { + int intersectedVtxStart = (lastItemEnd - curItem.first) / 16; + + for (size_t j = intersectedVtxStart; j < curItem.second.size(); j++) + vertices[lastItem.first].push_back(curItem.second[j]); + + vertices.erase(curItem.first); + vertexKeys.erase(vertexKeys.begin() + i); + + lastItem.second = vertices[lastItem.first]; + + i--; + } + else + lastItem = curItem; + } + } +} + void ZDisplayList::TextureGenCheck() { if (TextureGenCheck(lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg, lastTexFmt, diff --git a/ZAPD/ZDisplayList.h b/ZAPD/ZDisplayList.h index f3828cc..09c7c05 100644 --- a/ZAPD/ZDisplayList.h +++ b/ZAPD/ZDisplayList.h @@ -230,7 +230,7 @@ public: ZDisplayList(ZFile* nParent); ~ZDisplayList(); - void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override; + void ExtractWithXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override; void ExtractFromBinary(uint32_t nRawDataIndex, int32_t rawDataSize); void ParseRawData() override; @@ -251,6 +251,9 @@ public: std::string ProcessLegacy(const std::string& prefix); std::string ProcessGfxDis(const std::string& prefix); + // Combines vertex lists from the vertices map which touch or intersect + void MergeConnectingVertexLists(); + bool IsExternalResource() const override; std::string GetExternalExtension() const override; std::string GetSourceTypeName() const override; diff --git a/ZAPD/ZFile.cpp b/ZAPD/ZFile.cpp index 04032e5..2f455b1 100644 --- a/ZAPD/ZFile.cpp +++ b/ZAPD/ZFile.cpp @@ -186,6 +186,12 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename) } } + const char* segmentDefines = reader->Attribute("Defines"); + if (segmentDefines != NULL) + { + makeDefines = true; + } + if (mode == ZFileMode::Extract || mode == ZFileMode::ExternalFile || mode == ZFileMode::ExtractDirectory) { if (Globals::Instance->fileMode != ZFileMode::ExtractDirectory) @@ -193,7 +199,7 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename) if (!DiskFile::Exists((basePath / name).string())) { std::string errorHeader = StringHelper::Sprintf("binary file '%s' does not exist.", - (basePath / name).c_str()); + (basePath / name).c_str()); HANDLE_ERROR_PROCESS(WarningType::Always, errorHeader, ""); } } @@ -269,7 +275,7 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename) } nameSet.insert(nameXml); } - + std::string nodeName = std::string(child->Name()); if (nodeMap.find(nodeName) != nodeMap.end()) @@ -280,7 +286,7 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename) mode == ZFileMode::ExtractDirectory) { if (!isCompilable) - nRes->ExtractFromXML(child, rawDataIndex); + nRes->ExtractWithXML(child, rawDataIndex); } switch (nRes->GetResourceType()) { @@ -467,24 +473,25 @@ Declaration* ZFile::AddDeclaration(offset_t address, DeclarationAlignment alignm const std::string& varType, const std::string& varName, const std::string& body) { - bool validOffset = AddDeclarationChecks(address, varName); + bool validOffset = DeclarationSanityChecks(address, varName); if (!validOffset) return nullptr; Declaration* decl = GetDeclaration(address); if (decl == nullptr) { - decl = new Declaration(address, alignment, size, varType, varName, false, body); + decl = Declaration::Create(address, alignment, size, varType, varName, body); declarations[address] = decl; } else { decl->alignment = alignment; decl->size = size; - decl->varType = varType; - decl->varName = varName; - decl->text = body; + decl->declType = varType; + decl->declName = varName; + decl->declBody = body; } + return decl; } @@ -493,27 +500,29 @@ Declaration* ZFile::AddDeclarationArray(offset_t address, DeclarationAlignment a const std::string& varName, size_t arrayItemCnt, const std::string& body) { - bool validOffset = AddDeclarationChecks(address, varName); + bool validOffset = DeclarationSanityChecks(address, varName); if (!validOffset) return nullptr; Declaration* decl = GetDeclaration(address); if (decl == nullptr) { - decl = - new Declaration(address, alignment, size, varType, varName, true, arrayItemCnt, body); + decl = Declaration::CreateArray(address, alignment, size, varType, varName, body, + arrayItemCnt); + declarations[address] = decl; } else { if (decl->isPlaceholder) - decl->varName = varName; + decl->declName = varName; + decl->alignment = alignment; decl->size = size; - decl->varType = varType; + decl->declType = varType; decl->isArray = true; decl->arrayItemCnt = arrayItemCnt; - decl->text = body; + decl->declBody = body; } return decl; @@ -524,41 +533,41 @@ Declaration* ZFile::AddDeclarationArray(offset_t address, DeclarationAlignment a const std::string& varName, const std::string& arrayItemCntStr, const std::string& body) { - bool validOffset = AddDeclarationChecks(address, varName); + bool validOffset = DeclarationSanityChecks(address, varName); if (!validOffset) return nullptr; Declaration* decl = GetDeclaration(address); if (decl == nullptr) { - decl = new Declaration(address, alignment, size, varType, varName, true, arrayItemCntStr, - body); + decl = Declaration::CreateArray(address, alignment, size, varType, varName, body, + arrayItemCntStr); + declarations[address] = decl; } else { decl->alignment = alignment; decl->size = size; - decl->varType = varType; - decl->varName = varName; + decl->declType = varType; + decl->declName = varName; decl->isArray = true; decl->arrayItemCntStr = arrayItemCntStr; - decl->text = body; + decl->declBody = body; } return decl; } Declaration* ZFile::AddDeclarationPlaceholder(offset_t address, const std::string& varName) { - bool validOffset = AddDeclarationChecks(address, varName); + bool validOffset = DeclarationSanityChecks(address, varName); if (!validOffset) return nullptr; Declaration* decl; if (declarations.find(address) == declarations.end()) { - decl = new Declaration(address, DeclarationAlignment::Align4, 0, "", varName, false, ""); - decl->isPlaceholder = true; + decl = Declaration::CreatePlaceholder(address, varName); declarations[address] = decl; } else @@ -571,22 +580,22 @@ Declaration* ZFile::AddDeclarationInclude(offset_t address, const std::string& i size_t size, const std::string& varType, const std::string& varName) { - bool validOffset = AddDeclarationChecks(address, varName); + bool validOffset = DeclarationSanityChecks(address, varName); if (!validOffset) return nullptr; Declaration* decl = GetDeclaration(address); if (decl == nullptr) { - decl = new Declaration(address, includePath, size, varType, varName); + decl = Declaration::CreateInclude(address, includePath, size, varType, varName); declarations[address] = decl; } else { decl->includePath = includePath; decl->size = size; - decl->varType = varType; - decl->varName = varName; + decl->declType = varType; + decl->declName = varName; } return decl; } @@ -595,7 +604,7 @@ Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& in size_t size, const std::string& varType, const std::string& varName, size_t arrayItemCnt) { - bool validOffset = AddDeclarationChecks(address, varName); + bool validOffset = DeclarationSanityChecks(address, varName); if (!validOffset) return nullptr; @@ -607,7 +616,7 @@ Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& in Declaration* decl = GetDeclaration(address); if (decl == nullptr) { - decl = new Declaration(address, includePath, size, varType, varName); + decl = Declaration::CreateInclude(address, includePath, size, varType, varName); decl->isArray = true; decl->arrayItemCnt = arrayItemCnt; @@ -617,8 +626,8 @@ Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& in else { decl->includePath = includePath; - decl->varType = varType; - decl->varName = varName; + decl->declType = varType; + decl->declName = varName; decl->size = size; decl->isArray = true; decl->arrayItemCnt = arrayItemCnt; @@ -626,7 +635,44 @@ Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& in return decl; } -bool ZFile::AddDeclarationChecks(uint32_t address, const std::string& varName) +Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& includePath, + size_t size, const std::string& varType, + const std::string& varName, + const std::string& defines, size_t arrayItemCnt) +{ + bool validOffset = DeclarationSanityChecks(address, varName); + if (!validOffset) + return nullptr; + + if (StringHelper::StartsWith(includePath, "assets/extracted/")) + includePath = "assets/" + StringHelper::Split(includePath, "assets/extracted/")[1]; + if (StringHelper::StartsWith(includePath, "assets/custom/")) + includePath = "assets/" + StringHelper::Split(includePath, "assets/custom/")[1]; + + Declaration* decl = GetDeclaration(address); + if (decl == nullptr) + { + decl = Declaration::CreateInclude(address, includePath, size, varType, varName, defines); + + decl->isArray = true; + decl->arrayItemCnt = arrayItemCnt; + + declarations[address] = decl; + } + else + { + decl->includePath = includePath; + decl->declType = varType; + decl->declName = varName; + decl->defines = defines; + decl->size = size; + decl->isArray = true; + decl->arrayItemCnt = arrayItemCnt; + } + return decl; +} + +bool ZFile::DeclarationSanityChecks(uint32_t address, const std::string& varName) { assert(GETSEGNUM(address) == 0); assert(varName != ""); @@ -670,7 +716,7 @@ bool ZFile::GetDeclarationPtrName(segptr_t segAddress, const std::string& expect if (expectedType != "" && expectedType != "void*") { - if (expectedType != decl->varType && "static " + expectedType != decl->varType) + if (expectedType != decl->declType && "static " + expectedType != decl->declType) { declName = StringHelper::Sprintf("0x%08X", segAddress); return false; @@ -678,9 +724,9 @@ bool ZFile::GetDeclarationPtrName(segptr_t segAddress, const std::string& expect } if (!decl->isArray) - declName = "&" + decl->varName; + declName = "&" + decl->declName; else - declName = decl->varName; + declName = decl->declName; return true; } @@ -704,7 +750,7 @@ bool ZFile::GetDeclarationArrayIndexedName(segptr_t segAddress, size_t elementSi if (expectedType != "" && expectedType != "void*") { - if (expectedType != decl->varType && "static " + expectedType != decl->varType) + if (expectedType != decl->declType && "static " + expectedType != decl->declType) { declName = StringHelper::Sprintf("0x%08X", segAddress); return false; @@ -713,7 +759,7 @@ bool ZFile::GetDeclarationArrayIndexedName(segptr_t segAddress, size_t elementSi if (decl->address == address) { - declName = decl->varName; + declName = decl->declName; return true; } @@ -724,7 +770,7 @@ bool ZFile::GetDeclarationArrayIndexedName(segptr_t segAddress, size_t elementSi } uint32_t index = (address - decl->address) / elementSize; - declName = StringHelper::Sprintf("&%s[%u]", decl->varName.c_str(), index); + declName = StringHelper::Sprintf("&%s[%u]", decl->declName.c_str(), index); return true; } @@ -753,6 +799,20 @@ bool ZFile::HasDeclaration(offset_t address) return declarations.find(address) != declarations.end(); } +size_t ZFile::GetDeclarationSizeFromNeighbor(uint32_t declarationAddress) +{ + auto currentDecl = declarations.find(declarationAddress); + if (currentDecl == declarations.end()) + return 0; + + auto nextDecl = currentDecl; + std::advance(nextDecl, 1); + if (nextDecl == declarations.end()) + return GetRawData().size() - currentDecl->first; + + return nextDecl->first - currentDecl->first; +} + void ZFile::GenerateSourceFiles() { std::string sourceOutput; @@ -879,8 +939,8 @@ void ZFile::GenerateSourceHeaderFiles() std::string ZFile::GetHeaderInclude() const { - std::string headers = StringHelper::Sprintf("#include \"%s.h\"\n", - (outName.parent_path() / outName.stem()).string().c_str()); + std::string headers = StringHelper::Sprintf( + "#include \"%s.h\"\n", (outName.parent_path() / outName.stem()).string().c_str()); return headers; } @@ -905,13 +965,9 @@ std::string ZFile::GetExternalFileHeaderInclude() const { fs::path outputFolderPath = externalFile->GetSourceOutputFolderPath(); if (outputFolderPath == this->GetSourceOutputFolderPath()) - { outputFolderPath = externalFile->outName.stem(); - } else - { outputFolderPath /= externalFile->outName.stem(); - } externalFilesIncludes += StringHelper::Sprintf("#include \"%s.h\"\n", outputFolderPath.string().c_str()); @@ -1033,50 +1089,7 @@ std::string ZFile::ProcessDeclarations() // printf("RANGE START: 0x%06X - RANGE END: 0x%06X\n", rangeStart, rangeEnd); - // Optimization: See if there are any arrays side by side that can be merged... - std::vector<std::pair<int32_t, Declaration*>> declarationKeys(declarations.begin(), - declarations.end()); - - std::pair<int32_t, Declaration*> lastItem = declarationKeys.at(0); - - for (size_t i = 1; i < declarationKeys.size(); i++) - { - std::pair<int32_t, Declaration*> curItem = declarationKeys[i]; - - if (curItem.second->isArray && lastItem.second->isArray) - { - if (curItem.second->varType == lastItem.second->varType) - { - if (!curItem.second->declaredInXml && !lastItem.second->declaredInXml) - { - // TEST: For now just do Vtx declarations... - if (lastItem.second->varType == "Vtx") - { - int32_t sizeDiff = curItem.first - (lastItem.first + lastItem.second->size); - - // Make sure there isn't an unaccounted inbetween these two - if (sizeDiff == 0) - { - lastItem.second->size += curItem.second->size; - lastItem.second->arrayItemCnt += curItem.second->arrayItemCnt; - lastItem.second->text += "\n" + curItem.second->text; - - for (auto vtx : curItem.second->vertexHack) - lastItem.second->vertexHack.push_back(vtx); - - declarations.erase(curItem.first); - declarationKeys.erase(declarationKeys.begin() + i); - delete curItem.second; - i--; - continue; - } - } - } - } - } - - lastItem = curItem; - } + MergeNeighboringDeclarations(); for (std::pair<uint32_t, Declaration*> item : declarations) ProcessDeclarationText(item.second); @@ -1113,21 +1126,21 @@ std::string ZFile::ProcessDeclarations() // HACK std::string extType; - if (item.second->varType == "Gfx") + if (item.second->declType == "Gfx") extType = "dlist"; - else if (item.second->varType == "Vtx") + else if (item.second->declType == "Vtx") extType = "vtx"; - auto filepath = outputPath / item.second->varName; + auto filepath = outputPath / item.second->declName; DiskFile::WriteAllText( StringHelper::Sprintf("%s.%s.inc", filepath.string().c_str(), extType.c_str()), - item.second->text); + item.second->declBody); } } output += item.second->GetExternalDeclarationStr(); } - else if (item.second->varType != "") + else if (item.second->declType != "") { output += item.second->GetNormalDeclarationStr(); } @@ -1136,6 +1149,50 @@ std::string ZFile::ProcessDeclarations() return output; } +void ZFile::MergeNeighboringDeclarations() +{ + // Optimization: See if there are any arrays side by side that can be merged... + std::vector<std::pair<int32_t, Declaration*>> declarationKeys(declarations.begin(), + declarations.end()); + + std::pair<int32_t, Declaration*> lastItem = declarationKeys.at(0); + + for (size_t i = 1; i < declarationKeys.size(); i++) + { + std::pair<int32_t, Declaration*> curItem = declarationKeys[i]; + + if (curItem.second->isArray && lastItem.second->isArray) + { + if (curItem.second->declType == lastItem.second->declType) + { + if (!curItem.second->declaredInXml && !lastItem.second->declaredInXml) + { + // TEST: For now just do Vtx declarations... + if (lastItem.second->declType == "Vtx") + { + int32_t sizeDiff = curItem.first - (lastItem.first + lastItem.second->size); + + // Make sure there isn't an unaccounted inbetween these two + if (sizeDiff == 0) + { + lastItem.second->size += curItem.second->size; + lastItem.second->arrayItemCnt += curItem.second->arrayItemCnt; + lastItem.second->declBody += "\n" + curItem.second->declBody; + declarations.erase(curItem.first); + declarationKeys.erase(declarationKeys.begin() + i); + delete curItem.second; + i--; + continue; + } + } + } + } + } + + lastItem = curItem; + } +} + void ZFile::ProcessDeclarationText(Declaration* decl) { size_t refIndex = 0; @@ -1143,17 +1200,17 @@ void ZFile::ProcessDeclarationText(Declaration* decl) if (!(decl->references.size() > 0)) return; - for (size_t i = 0; i < decl->text.size() - 1; i++) + for (size_t i = 0; i < decl->declBody.size() - 1; i++) { - char c = decl->text[i]; - char c2 = decl->text[i + 1]; + char c = decl->declBody[i]; + char c2 = decl->declBody[i + 1]; if (c == '@' && c2 == 'r') { std::string vtxName; Globals::Instance->GetSegmentedArrayIndexedName(decl->references[refIndex], 0x10, this, "Vtx", vtxName, workerID); - decl->text.replace(i, 2, vtxName); + decl->declBody.replace(i, 2, vtxName); refIndex++; @@ -1165,7 +1222,8 @@ void ZFile::ProcessDeclarationText(Declaration* decl) std::string ZFile::ProcessExterns() { - std::string output; + std::string output = ""; + bool hadDefines = true; // Previous declaration included defines. for (const auto& item : declarations) { @@ -1174,10 +1232,21 @@ std::string ZFile::ProcessExterns() continue; } + std::string itemDefines = item.second->GetDefinesStr(); + // Add a newline above if previous has no defines and this one does. + if (!hadDefines && (itemDefines.length() > 0)) + { + output.push_back('\n'); + } output += item.second->GetExternStr(); - } + output += itemDefines; - output += "\n"; + // Newline below if this one has defines. + if ((hadDefines = (itemDefines.length() > 0))) + { + output.push_back('\n'); + } + } output += defines; @@ -1216,7 +1285,6 @@ std::string ZFile::ProcessTextureIntersections([[maybe_unused]] const std::strin if (declarations.find(currentOffset) != declarations.end()) declarations.at(currentOffset)->size = currentTex->GetRawDataSize(); - currentTex->DeclareVar(GetName(), ""); } else @@ -1229,7 +1297,7 @@ std::string ZFile::ProcessTextureIntersections([[maybe_unused]] const std::strin if (nextDecl == nullptr) texNextName = texturesResources.at(nextOffset)->GetName(); else - texNextName = nextDecl->varName; + texNextName = nextDecl->declName; #if 0 defines += StringHelper::Sprintf("#define %s ((u32)%s + 0x%06X)\n", @@ -1259,9 +1327,6 @@ void ZFile::HandleUnaccountedData() return; declsAddresses.reserve(declarations.size()); - if (Globals::Instance->otrMode) - return; - for (const auto& item : declarations) { declsAddresses.push_back(item.first); @@ -1310,8 +1375,8 @@ bool ZFile::HandleUnaccountedAddress(offset_t currentAddress, offset_t lastAddr, std::string intersectionInfo = StringHelper::Sprintf( "Resource from 0x%06X:0x%06X (%s) conflicts with 0x%06X (%s).", lastAddr, - lastAddr + lastSize, lastDecl->varName.c_str(), currentAddress, - currentDecl->varName.c_str()); + lastAddr + lastSize, lastDecl->declName.c_str(), currentAddress, + currentDecl->declName.c_str()); HANDLE_WARNING_RESOURCE(WarningType::Intersection, this, nullptr, currentAddress, "intersection detected", intersectionInfo); } diff --git a/ZAPD/ZFile.h b/ZAPD/ZFile.h index 0433454..53cb2e0 100644 --- a/ZAPD/ZFile.h +++ b/ZAPD/ZFile.h @@ -42,6 +42,8 @@ public: uint32_t segment = 0x80; uint32_t baseAddress, rangeStart, rangeEnd; bool isExternalFile = false; + // Whether to make defines for texture dimensions, and possibly more in future + bool makeDefines = false; ZFile(const fs::path& nOutPath, const std::string& nName); ZFile(ZFileMode nMode, tinyxml2::XMLElement* reader, const fs::path& nBasePath, @@ -78,6 +80,9 @@ public: Declaration* AddDeclarationIncludeArray(offset_t address, std::string& includePath, size_t size, const std::string& varType, const std::string& varName, size_t arrayItemCnt); + Declaration* AddDeclarationIncludeArray(offset_t address, std::string& includePath, size_t size, + const std::string& varType, const std::string& varName, + const std::string& defines, size_t arrayItemCnt); bool GetDeclarationPtrName(segptr_t segAddress, const std::string& expectedType, std::string& declName) const; @@ -88,6 +93,7 @@ public: Declaration* GetDeclaration(offset_t address) const; Declaration* GetDeclarationRanged(offset_t address) const; bool HasDeclaration(offset_t address); + size_t GetDeclarationSizeFromNeighbor(uint32_t declarationAddress); std::string GetHeaderInclude() const; std::string GetZRoomHeaderInclude() const; @@ -130,8 +136,9 @@ protected: void DeclareResourceSubReferences(); void GenerateSourceFiles(); void GenerateSourceHeaderFiles(); - bool AddDeclarationChecks(uint32_t address, const std::string& varName); + bool DeclarationSanityChecks(uint32_t address, const std::string& varName); std::string ProcessDeclarations(); + void MergeNeighboringDeclarations(); void ProcessDeclarationText(Declaration* decl); std::string ProcessExterns(); diff --git a/ZAPD/ZLimb.cpp b/ZAPD/ZLimb.cpp index d0c3ffe..736f2de 100644 --- a/ZAPD/ZLimb.cpp +++ b/ZAPD/ZLimb.cpp @@ -106,7 +106,7 @@ void ZLimb::ParseRawData() skinSegmentType = static_cast<ZLimbSkinType>(BitConverter::ToInt32BE(rawData, rawDataIndex + 8)); skinSegment = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12); - if (skinSegmentType == ZLimbSkinType::SkinType_4) + if (skinSegmentType == ZLimbSkinType::SkinType_Animated) { if (skinSegment != 0 && GETSEGNUM(skinSegment) == parent->segment) { @@ -181,7 +181,7 @@ void ZLimb::DeclareReferences(const std::string& prefix) case ZLimbType::Skin: switch (skinSegmentType) { - case ZLimbSkinType::SkinType_4: + case ZLimbSkinType::SkinType_Animated: if (skinSegment != 0 && GETSEGNUM(skinSegment) == parent->segment) { segmentStruct.DeclareReferences(varPrefix); @@ -189,7 +189,7 @@ void ZLimb::DeclareReferences(const std::string& prefix) } break; - case ZLimbSkinType::SkinType_DList: + case ZLimbSkinType::SkinType_Normal: DeclareDList(skinSegment, varPrefix, ""); break; @@ -402,7 +402,7 @@ void ZLimb::DeclareDList(segptr_t dListSegmentedPtr, const std::string& prefix, std::string dlistName; bool declFound = Globals::Instance->GetSegmentedArrayIndexedName(dListSegmentedPtr, 8, parent, - "Gfx", dlistName, parent->workerID); + "Gfx", dlistName, false, parent->workerID); if (declFound) return; diff --git a/ZAPD/ZLimb.h b/ZAPD/ZLimb.h index b75236f..2da9341 100644 --- a/ZAPD/ZLimb.h +++ b/ZAPD/ZLimb.h @@ -28,9 +28,9 @@ public: ZLimbType type = ZLimbType::Standard; - ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only + ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_Null; // Skin only segptr_t skinSegment = 0; // Skin only - Struct_800A5E28 segmentStruct = {0}; // Skin only + SkinAnimatedLimbData segmentStruct; // Skin only // Legacy only float legTransX = 0, legTransY = 0, legTransZ = 0; // Vec3f diff --git a/ZAPD/ZPath.cpp b/ZAPD/ZPath.cpp index 849b4ed..8ea6d29 100644 --- a/ZAPD/ZPath.cpp +++ b/ZAPD/ZPath.cpp @@ -6,7 +6,8 @@ #include "WarningHandler.h" #include "ZFile.h" -REGISTER_ZFILENODE(Path, ZPath); +REGISTER_ZFILENODE(Path, ZPath); // Old name that is being kept for backwards compatability +REGISTER_ZFILENODE(PathList, ZPath); // New name that may be used in future XMLs ZPath::ZPath(ZFile* nParent) : ZResource(nParent) { @@ -145,7 +146,7 @@ void PathwayEntry::DeclareReferences(const std::string& prefix) std::string pointsName; bool addressFound = Globals::Instance->GetSegmentedPtrName(listSegmentAddress, parent, "Vec3s", - pointsName, parent->workerID); + pointsName, false, parent->workerID); if (addressFound) return; @@ -172,21 +173,26 @@ void PathwayEntry::DeclareReferences(const std::string& prefix) points.size(), declaration); } else - decl->text = declaration; + decl->declBody = declaration; } std::string PathwayEntry::GetBodySourceCode() const { std::string declaration; std::string listName; - Globals::Instance->GetSegmentedPtrName(listSegmentAddress, parent, "Vec3s", listName, - parent->workerID); + Globals::Instance->GetSegmentedPtrName(listSegmentAddress, parent, "Vec3s", listName, parent->workerID); if (Globals::Instance->game == ZGame::MM_RETAIL) declaration += StringHelper::Sprintf("%i, %i, %i, %s", numPoints, unk1, unk2, listName.c_str()); else - declaration += StringHelper::Sprintf("%i, %s", numPoints, listName.c_str()); + { + if (numPoints > 0) + declaration += + StringHelper::Sprintf("ARRAY_COUNT(%s), %s", listName.c_str(), listName.c_str()); + else + declaration += StringHelper::Sprintf("%i, %s", numPoints, listName.c_str()); + } return declaration; } diff --git a/ZAPD/ZPlayerAnimationData.cpp b/ZAPD/ZPlayerAnimationData.cpp index ab633c1..d3bcb10 100644 --- a/ZAPD/ZPlayerAnimationData.cpp +++ b/ZAPD/ZPlayerAnimationData.cpp @@ -33,7 +33,7 @@ void ZPlayerAnimationData::ParseRawData() for (size_t i = 0; i < totalSize; i += 2) { - limbRotData.push_back(BitConverter::ToUInt16BE(rawData, rawDataIndex + i)); + limbRotData.push_back(BitConverter::ToInt16BE(rawData, rawDataIndex + i)); } } @@ -59,14 +59,21 @@ std::string ZPlayerAnimationData::GetBodySourceCode() const return ""; size_t index = 0; - for (const auto& entry : limbRotData) + for (const auto entry : limbRotData) { if (index % 8 == 0) { declaration += "\t"; } - declaration += StringHelper::Sprintf("0x%04X, ", entry); + if (entry < 0) + { + declaration += StringHelper::Sprintf("-0x%04X, ", -entry); + } + else + { + declaration += StringHelper::Sprintf("0x%04X, ", entry); + } if ((index + 1) % 8 == 0) { diff --git a/ZAPD/ZPlayerAnimationData.h b/ZAPD/ZPlayerAnimationData.h index 20835f2..2923117 100644 --- a/ZAPD/ZPlayerAnimationData.h +++ b/ZAPD/ZPlayerAnimationData.h @@ -9,7 +9,7 @@ class ZPlayerAnimationData : public ZResource { public: int16_t frameCount = 0; - std::vector<uint16_t> limbRotData; + std::vector<int16_t> limbRotData; ZPlayerAnimationData(ZFile* nParent); diff --git a/ZAPD/ZResource.cpp b/ZAPD/ZResource.cpp index aacc7af..394abd4 100644 --- a/ZAPD/ZResource.cpp +++ b/ZAPD/ZResource.cpp @@ -29,7 +29,7 @@ ZResource::ZResource(ZFile* nParent) RegisterOptionalAttribute("Static", "Global"); } -void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, offset_t nRawDataIndex) +void ZResource::ExtractWithXML(tinyxml2::XMLElement* reader, offset_t nRawDataIndex) { rawDataIndex = nRawDataIndex; declaredInXml = true; @@ -288,7 +288,7 @@ void ZResource::GetSourceOutputCode([[maybe_unused]] const std::string& prefix) if (decl == nullptr || decl->isPlaceholder) decl = DeclareVar(prefix, bodyStr); else - decl->text = bodyStr; + decl->declBody = bodyStr; // OTRTODO: This is a hack and we need something more elegant in the future... if (GetResourceType() == ZResourceType::Array) diff --git a/ZAPD/ZResource.h b/ZAPD/ZResource.h index 05c35a2..ac8f266 100644 --- a/ZAPD/ZResource.h +++ b/ZAPD/ZResource.h @@ -26,12 +26,14 @@ class ZFile; enum class ZResourceType { Error, + ActorList, Animation, Array, AltHeader, Background, Blob, CollisionHeader, + CollisionPoly, Cutscene, DisplayList, Limb, @@ -39,24 +41,23 @@ enum class ZResourceType Mtx, Path, PlayerAnimationData, + Pointer, Room, RoomCommand, Scalar, Scene, Skeleton, String, + SurfaceType, Symbol, Texture, TextureAnimation, TextureAnimationParams, Vector, Vertex, + Waterbox, Text, Audio, - ActorList, - CollisionPoly, - Pointer, - SurfaceType, }; class ResourceAttribute @@ -83,8 +84,18 @@ public: ZResource(ZFile* nParent); virtual ~ZResource() = default; - // Parsing from File - virtual void ExtractFromXML(tinyxml2::XMLElement* reader, offset_t nRawDataIndex); + /// <summary> + /// Extracts/Parsees data from binary file using an XML to provide the needed metadata. + /// </summary> + /// <param name="reader">XML Node we wish to parse from.</param> + /// <param name="nRawDataIndex">The offset within the binary file we are going to parse from as + /// indicated by the "Offset" parameter in the XML.</param> + virtual void ExtractWithXML(tinyxml2::XMLElement* reader, offset_t nRawDataIndex); + + /// <summary> + /// Extracts/Parses the needed data straight from a binary without the use of an XML. + /// </summary> + /// <param name="nRawDataIndex">The offset within the binary file we wish to parse from.</param> virtual void ExtractFromFile(offset_t nRawDataIndex); // Misc diff --git a/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp b/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp index 9e61c6a..7418f29 100644 --- a/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp +++ b/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp @@ -21,7 +21,7 @@ void SetAlternateHeaders::DeclareReferences([[maybe_unused]] const std::string& void SetAlternateHeaders::ParseRawDataLate() { - size_t numHeaders = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 4; + size_t numHeaders = zRoom->parent->GetDeclarationSizeFromNeighbor(segmentOffset) / 4; headers.reserve(numHeaders); for (uint32_t i = 0; i < numHeaders; i++) diff --git a/ZAPD/ZRoom/Commands/SetCameraSettings.cpp b/ZAPD/ZRoom/Commands/SetCameraSettings.cpp index ae2d31c..e30e1b6 100644 --- a/ZAPD/ZRoom/Commands/SetCameraSettings.cpp +++ b/ZAPD/ZRoom/Commands/SetCameraSettings.cpp @@ -2,6 +2,7 @@ #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" +#include "Globals.h" SetCameraSettings::SetCameraSettings(ZFile* nParent) : ZRoomCommand(nParent) { @@ -16,8 +17,12 @@ void SetCameraSettings::ParseRawData() std::string SetCameraSettings::GetBodySourceCode() const { - return StringHelper::Sprintf("SCENE_CMD_MISC_SETTINGS(0x%02X, 0x%08X)", cameraMovement, - mapHighlight); + if (Globals::Instance->game == ZGame::MM_RETAIL) + return StringHelper::Sprintf("SCENE_CMD_SET_REGION_VISITED(0x%02X, 0x%08X)", cameraMovement, + mapHighlight); + else + return StringHelper::Sprintf("SCENE_CMD_MISC_SETTINGS(0x%02X, 0x%08X)", cameraMovement, + mapHighlight); } std::string SetCameraSettings::GetCommandCName() const diff --git a/ZAPD/ZRoom/Commands/SetCsCamera.cpp b/ZAPD/ZRoom/Commands/SetCsCamera.cpp index 5a9ae12..7e36f3e 100644 --- a/ZAPD/ZRoom/Commands/SetCsCamera.cpp +++ b/ZAPD/ZRoom/Commands/SetCsCamera.cpp @@ -21,7 +21,7 @@ void SetCsCamera::ParseRawData() cameras.reserve(numCameras); for (int32_t i = 0; i < numCameras; i++) { - CsCameraEntry entry(parent->GetRawData(), currentPtr); + ActorCsCamInfo entry(parent->GetRawData(), currentPtr); numPoints += entry.GetNumPoints(); currentPtr += entry.GetRawDataSize(); @@ -105,8 +105,7 @@ void SetCsCamera::DeclareReferences(const std::string& prefix) std::string SetCsCamera::GetBodySourceCode() const { std::string listName; - Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CsCameraEntry", listName, - parent->workerID); + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "ActorCsCamInfo", listName, parent->workerID); return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_CAM_LIST(%i, %s)", cameras.size(), listName.c_str()); } @@ -121,7 +120,7 @@ RoomCommand SetCsCamera::GetRoomCommand() const return RoomCommand::SetCsCamera; } -CsCameraEntry::CsCameraEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) +ActorCsCamInfo::ActorCsCamInfo(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) : baseOffset(rawDataIndex), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), numPoints(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)) { @@ -129,27 +128,27 @@ CsCameraEntry::CsCameraEntry(const std::vector<uint8_t>& rawData, uint32_t rawDa segmentOffset = GETSEGOFFSET(camAddress); } -std::string CsCameraEntry::GetSourceTypeName() const +std::string ActorCsCamInfo::GetSourceTypeName() const { - return "CsCameraEntry"; + return "ActorCsCamInfo"; } -int32_t CsCameraEntry::GetRawDataSize() const +int32_t ActorCsCamInfo::GetRawDataSize() const { return 8; } -int16_t CsCameraEntry::GetNumPoints() const +int16_t ActorCsCamInfo::GetNumPoints() const { return numPoints; } -segptr_t CsCameraEntry::GetCamAddress() const +segptr_t ActorCsCamInfo::GetCamAddress() const { return camAddress; } -uint32_t CsCameraEntry::GetSegmentOffset() const +uint32_t ActorCsCamInfo::GetSegmentOffset() const { return segmentOffset; } diff --git a/ZAPD/ZRoom/Commands/SetCsCamera.h b/ZAPD/ZRoom/Commands/SetCsCamera.h index 5e0e3c8..2ce64e4 100644 --- a/ZAPD/ZRoom/Commands/SetCsCamera.h +++ b/ZAPD/ZRoom/Commands/SetCsCamera.h @@ -3,10 +3,10 @@ #include "ZRoom/ZRoomCommand.h" #include "ZVector.h" -class CsCameraEntry +class ActorCsCamInfo { public: - CsCameraEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); + ActorCsCamInfo(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); std::string GetSourceTypeName() const; int32_t GetRawDataSize() const; @@ -25,7 +25,7 @@ public: class SetCsCamera : public ZRoomCommand { public: - std::vector<CsCameraEntry> cameras; + std::vector<ActorCsCamInfo> cameras; std::vector<ZVector> points; SetCsCamera(ZFile* nParent); diff --git a/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp b/ZAPD/ZRoom/Commands/SetCutsceneEntryList.cpp index ee01837..ac64a64 100644 --- a/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp +++ b/ZAPD/ZRoom/Commands/SetCutsceneEntryList.cpp @@ -1,4 +1,4 @@ -#include "SetActorCutsceneList.h" +#include "SetCutsceneEntryList.h" #include "Globals.h" #include "Utils/BitConverter.h" @@ -19,7 +19,7 @@ void SetActorCutsceneList::ParseRawData() cutscenes.reserve(numCutscenes); for (int32_t i = 0; i < numCutscenes; i++) { - ActorCutsceneEntry entry(parent->GetRawData(), currentPtr); + CutsceneEntry entry(parent->GetRawData(), currentPtr); cutscenes.push_back(entry); currentPtr += 16; @@ -55,8 +55,7 @@ void SetActorCutsceneList::DeclareReferences(const std::string& prefix) std::string SetActorCutsceneList::GetBodySourceCode() const { std::string listName; - Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "ActorCutscene", listName, - parent->workerID); + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneEntry", listName, parent->workerID); return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_LIST(%i, %s)", cutscenes.size(), listName.c_str()); } @@ -71,25 +70,34 @@ RoomCommand SetActorCutsceneList::GetRoomCommand() const return RoomCommand::SetActorCutsceneList; } -ActorCutsceneEntry::ActorCutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) +CutsceneEntry::CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) : priority(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), length(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), - unk4(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), - unk6(BitConverter::ToInt16BE(rawData, rawDataIndex + 6)), - additionalCutscene(BitConverter::ToInt16BE(rawData, rawDataIndex + 8)), - sound(rawData[rawDataIndex + 0xA]), unkB(rawData[rawDataIndex + 0xB]), - unkC(BitConverter::ToInt16BE(rawData, rawDataIndex + 0xC)), unkE(rawData[rawDataIndex + 0xE]), - letterboxSize(rawData[rawDataIndex + 0xF]) + csCamId(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), + scriptIndex(BitConverter::ToInt16BE(rawData, rawDataIndex + 6)), + additionalCsId(BitConverter::ToInt16BE(rawData, rawDataIndex + 8)), + endSfx(rawData[rawDataIndex + 0xA]), customValue(rawData[rawDataIndex + 0xB]), + hudVisibility(BitConverter::ToInt16BE(rawData, rawDataIndex + 0xC)), + endCam(rawData[rawDataIndex + 0xE]), letterboxSize(rawData[rawDataIndex + 0xF]) { } -std::string ActorCutsceneEntry::GetBodySourceCode() const +std::string CutsceneEntry::GetBodySourceCode() const { - return StringHelper::Sprintf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %i", priority, length, unk4, - unk6, additionalCutscene, sound, unkB, unkC, unkE, letterboxSize); + EnumData* enumData = &Globals::Instance->cfg.enumData; + + if (enumData->endSfx.find(endSfx) != enumData->endSfx.end()) + return StringHelper::Sprintf("%i, %i, %i, %i, %i, %s, %i, %i, %i, %i", priority, length, + csCamId, scriptIndex, additionalCsId, + enumData->endSfx[endSfx].c_str(), customValue, hudVisibility, + endCam, letterboxSize); + else + return StringHelper::Sprintf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %i", priority, length, + csCamId, scriptIndex, additionalCsId, endSfx, customValue, + hudVisibility, endCam, letterboxSize); } -std::string ActorCutsceneEntry::GetSourceTypeName() const +std::string CutsceneEntry::GetSourceTypeName() const { - return "ActorCutscene"; + return "CutsceneEntry"; } diff --git a/ZAPD/ZRoom/Commands/SetActorCutsceneList.h b/ZAPD/ZRoom/Commands/SetCutsceneEntryList.h index 8fd48e4..6ba6c23 100644 --- a/ZAPD/ZRoom/Commands/SetActorCutsceneList.h +++ b/ZAPD/ZRoom/Commands/SetCutsceneEntryList.h @@ -2,22 +2,22 @@ #include "ZRoom/ZRoomCommand.h" -class ActorCutsceneEntry +class CutsceneEntry { protected: int16_t priority; int16_t length; - int16_t unk4; - int16_t unk6; - int16_t additionalCutscene; - uint8_t sound; - uint8_t unkB; - int16_t unkC; - uint8_t unkE; + int16_t csCamId; + int16_t scriptIndex; + int16_t additionalCsId; + uint8_t endSfx; + uint8_t customValue; + int16_t hudVisibility; + uint8_t endCam; uint8_t letterboxSize; public: - ActorCutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); + CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); std::string GetBodySourceCode() const; std::string GetSourceTypeName() const; @@ -26,7 +26,7 @@ public: class SetActorCutsceneList : public ZRoomCommand { public: - std::vector<ActorCutsceneEntry> cutscenes; + std::vector<CutsceneEntry> cutscenes; SetActorCutsceneList(ZFile* nParent); diff --git a/ZAPD/ZRoom/Commands/SetCutscenes.cpp b/ZAPD/ZRoom/Commands/SetCutscenes.cpp index 68ff58c..e9192f0 100644 --- a/ZAPD/ZRoom/Commands/SetCutscenes.cpp +++ b/ZAPD/ZRoom/Commands/SetCutscenes.cpp @@ -23,11 +23,11 @@ void SetCutscenes::ParseRawData() cutsceneEntries.reserve(numCutscenes); for (uint8_t i = 0; i < numCutscenes; i++) { - CutsceneEntry entry(parent->GetRawData(), currentPtr); + CutsceneScriptEntry entry(parent->GetRawData(), currentPtr); cutsceneEntries.push_back(entry); currentPtr += 8; } - } + } else if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97) { ZCutscene* cutscene = new ZCutscene(parent); @@ -45,6 +45,7 @@ void SetCutscenes::ParseRawData() void SetCutscenes::DeclareReferences(const std::string& prefix) { + EnumData* enumData = &Globals::Instance->cfg.enumData; std::string varPrefix = name; if (varPrefix == "") varPrefix = prefix; @@ -75,10 +76,14 @@ void SetCutscenes::DeclareReferences(const std::string& prefix) Globals::Instance->GetSegmentedPtrName(entry.segmentPtr, parent, "CutsceneData", csName, parent->workerID); - declaration += - StringHelper::Sprintf(" { %s, 0x%04X, 0x%02X, 0x%02X },", csName.c_str(), - entry.exit, entry.entrance, entry.flag); - + if (enumData->spawnFlag.find(entry.flag) != enumData->spawnFlag.end()) + declaration += StringHelper::Sprintf(" { %s, 0x%04X, 0x%02X, %s },", + csName.c_str(), entry.exit, entry.entrance, + enumData->spawnFlag[entry.flag].c_str()); + else + 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"; @@ -86,8 +91,8 @@ void SetCutscenes::DeclareReferences(const std::string& prefix) } parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, - cutsceneEntries.size() * 8, "CutsceneEntry", - StringHelper::Sprintf("%sCutsceneEntryList_%06X", + cutsceneEntries.size() * 8, "CutsceneScriptEntry", + StringHelper::Sprintf("%sCutsceneScriptEntryList_%06X", zRoom->GetName().c_str(), segmentOffset), cutsceneEntries.size(), declaration); } @@ -117,9 +122,8 @@ std::string SetCutscenes::GetBodySourceCode() const if (Globals::Instance->game == ZGame::MM_RETAIL) { - Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneEntry", listName, - parent->workerID); - return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_LIST(%i, %s)", numCutscenes, + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneScriptEntry", listName, parent->workerID); + return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_SCRIPT_LIST(%i, %s)", numCutscenes, listName.c_str()); } @@ -138,7 +142,7 @@ RoomCommand SetCutscenes::GetRoomCommand() const return RoomCommand::SetCutscenes; } -CutsceneEntry::CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) +CutsceneScriptEntry::CutsceneScriptEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) : segmentPtr(BitConverter::ToInt32BE(rawData, rawDataIndex + 0)), exit(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), entrance(rawData[rawDataIndex + 6]), flag(rawData[rawDataIndex + 7]) diff --git a/ZAPD/ZRoom/Commands/SetCutscenes.h b/ZAPD/ZRoom/Commands/SetCutscenes.h index b1d175f..69ef236 100644 --- a/ZAPD/ZRoom/Commands/SetCutscenes.h +++ b/ZAPD/ZRoom/Commands/SetCutscenes.h @@ -3,10 +3,10 @@ #include "ZCutscene.h" #include "ZRoom/ZRoomCommand.h" -class CutsceneEntry +class CutsceneScriptEntry { public: - CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); + CutsceneScriptEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); segptr_t segmentPtr; uint16_t exit; @@ -18,8 +18,8 @@ class SetCutscenes : public ZRoomCommand { public: std::vector<ZCutscene*> cutscenes; - std::vector<CutsceneEntry> cutsceneEntries; // (MM Only) - uint8_t numCutscenes; // (MM Only) + std::vector<CutsceneScriptEntry> cutsceneEntries; // (MM Only) + uint8_t numCutscenes; // (MM Only) SetCutscenes(ZFile* nParent); diff --git a/ZAPD/ZRoom/Commands/SetEntranceList.cpp b/ZAPD/ZRoom/Commands/SetEntranceList.cpp index 6749e17..c5d57df 100644 --- a/ZAPD/ZRoom/Commands/SetEntranceList.cpp +++ b/ZAPD/ZRoom/Commands/SetEntranceList.cpp @@ -24,13 +24,13 @@ void SetEntranceList::DeclareReferences([[maybe_unused]] const std::string& pref void SetEntranceList::ParseRawDataLate() { // Parse Entrances and Generate Declaration - uint32_t numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; + uint32_t numEntrances = zRoom->parent->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; uint32_t currentPtr = segmentOffset; entrances.reserve(numEntrances); for (uint32_t i = 0; i < numEntrances; i++) { - EntranceEntry entry(parent->GetRawData(), currentPtr); + Spawn entry(parent->GetRawData(), currentPtr); entrances.push_back(entry); currentPtr += 2; @@ -55,17 +55,25 @@ void SetEntranceList::DeclareReferencesLate([[maybe_unused]] const std::string& std::string varName = StringHelper::Sprintf("%sEntranceList0x%06X", prefix.c_str(), segmentOffset); - parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, - entrances.size() * 2, "EntranceEntry", varName, - entrances.size(), declaration); + + if (Globals::Instance->game != ZGame::MM_RETAIL) + parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, + entrances.size() * 2, "Spawn", varName, entrances.size(), + declaration); + else + parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, + entrances.size() * 2, "EntranceEntry", varName, + entrances.size(), declaration); } } std::string SetEntranceList::GetBodySourceCode() const { std::string listName; - Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "EntranceEntry", listName, - parent->workerID); + if (Globals::Instance->game != ZGame::MM_RETAIL) + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "Spawn", listName, parent->workerID); + else + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "EntranceEntry", listName, parent->workerID); return StringHelper::Sprintf("SCENE_CMD_ENTRANCE_LIST(%s)", listName.c_str()); } @@ -79,13 +87,13 @@ RoomCommand SetEntranceList::GetRoomCommand() const return RoomCommand::SetEntranceList; } -EntranceEntry::EntranceEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) +Spawn::Spawn(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex) { startPositionIndex = rawData.at(rawDataIndex + 0); roomToLoad = rawData.at(rawDataIndex + 1); } -std::string EntranceEntry::GetBodySourceCode() const +std::string Spawn::GetBodySourceCode() const { return StringHelper::Sprintf("0x%02X, 0x%02X", startPositionIndex, roomToLoad); } diff --git a/ZAPD/ZRoom/Commands/SetEntranceList.h b/ZAPD/ZRoom/Commands/SetEntranceList.h index e13e9a8..832232e 100644 --- a/ZAPD/ZRoom/Commands/SetEntranceList.h +++ b/ZAPD/ZRoom/Commands/SetEntranceList.h @@ -2,13 +2,13 @@ #include "ZRoom/ZRoomCommand.h" -class EntranceEntry +class Spawn { public: uint8_t startPositionIndex; uint8_t roomToLoad; - EntranceEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); + Spawn(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex); std::string GetBodySourceCode() const; }; @@ -16,7 +16,7 @@ public: class SetEntranceList : public ZRoomCommand { public: - std::vector<EntranceEntry> entrances; + std::vector<Spawn> entrances; SetEntranceList(ZFile* nParent); diff --git a/ZAPD/ZRoom/Commands/SetExitList.cpp b/ZAPD/ZRoom/Commands/SetExitList.cpp index 3b9ce2d..3068d5c 100644 --- a/ZAPD/ZRoom/Commands/SetExitList.cpp +++ b/ZAPD/ZRoom/Commands/SetExitList.cpp @@ -24,7 +24,7 @@ void SetExitList::DeclareReferences([[maybe_unused]] const std::string& prefix) void SetExitList::ParseRawDataLate() { // Parse Entrances and Generate Declaration - uint32_t numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; + uint32_t numEntrances = zRoom->parent->GetDeclarationSizeFromNeighbor(segmentOffset) / 2; uint32_t currentPtr = segmentOffset; exits.reserve(numEntrances); diff --git a/ZAPD/ZRoom/Commands/SetLightingSettings.cpp b/ZAPD/ZRoom/Commands/SetLightingSettings.cpp index 547862a..796e267 100644 --- a/ZAPD/ZRoom/Commands/SetLightingSettings.cpp +++ b/ZAPD/ZRoom/Commands/SetLightingSettings.cpp @@ -34,19 +34,28 @@ void SetLightingSettings::DeclareReferences(const std::string& prefix) declaration += "\n"; } - parent->AddDeclarationArray( - segmentOffset, DeclarationAlignment::Align4, - settings.size() * settings.front().GetRawDataSize(), "LightSettings", - StringHelper::Sprintf("%sLightSettings0x%06X", prefix.c_str(), segmentOffset), - settings.size(), declaration); + if (Globals::Instance->game != ZGame::MM_RETAIL) + parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::Align4, + settings.size() * settings.front().GetRawDataSize(), "EnvLightSettings", + StringHelper::Sprintf("%sLightSettings0x%06X", prefix.c_str(), segmentOffset), + settings.size(), declaration); + else + parent->AddDeclarationArray( + segmentOffset, DeclarationAlignment::Align4, + settings.size() * settings.front().GetRawDataSize(), "LightSettings", + StringHelper::Sprintf("%sLightSettings0x%06X", prefix.c_str(), segmentOffset), + settings.size(), declaration); } } std::string SetLightingSettings::GetBodySourceCode() const { std::string listName; - Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "LightSettings", listName, - parent->workerID); + if (Globals::Instance->game != ZGame::MM_RETAIL) + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "EnvLightSettings", listName, parent->workerID); + else + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "LightSettings", listName, parent->workerID); return StringHelper::Sprintf("SCENE_CMD_ENV_LIGHT_SETTINGS(%i, %s)", settings.size(), listName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetMesh.cpp b/ZAPD/ZRoom/Commands/SetMesh.cpp index c6f2d7d..68a8ab9 100644 --- a/ZAPD/ZRoom/Commands/SetMesh.cpp +++ b/ZAPD/ZRoom/Commands/SetMesh.cpp @@ -24,7 +24,7 @@ void SetMesh::ParseRawData() switch (meshHeaderType) { case 0: - polyType = std::make_shared<PolygonType2>(parent, segmentOffset, zRoom); + polyType = std::make_shared<RoomShapeCullable>(parent, segmentOffset, zRoom); break; case 1: @@ -32,7 +32,7 @@ void SetMesh::ParseRawData() break; case 2: - polyType = std::make_shared<PolygonType2>(parent, segmentOffset, zRoom); + polyType = std::make_shared<RoomShapeCullable>(parent, segmentOffset, zRoom); break; default: @@ -79,7 +79,7 @@ std::string SetMesh::GetBodySourceCode() const { std::string list; Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "", list, parent->workerID); - return StringHelper::Sprintf("SCENE_CMD_MESH(%s)", list.c_str()); + return StringHelper::Sprintf("SCENE_CMD_ROOM_SHAPE(%s)", list.c_str()); } std::string SetMesh::GetCommandCName() const @@ -92,11 +92,11 @@ RoomCommand SetMesh::GetRoomCommand() const return RoomCommand::SetMesh; } -PolygonDlist::PolygonDlist(ZFile* nParent) : ZResource(nParent) +RoomShapeDListsEntry::RoomShapeDListsEntry(ZFile* nParent) : ZResource(nParent) { } -void PolygonDlist::ParseRawData() +void RoomShapeDListsEntry::ParseRawData() { const auto& rawData = parent->GetRawData(); switch (polyType) @@ -118,13 +118,13 @@ void PolygonDlist::ParseRawData() } } -void PolygonDlist::DeclareReferences(const std::string& prefix) +void RoomShapeDListsEntry::DeclareReferences(const std::string& prefix) { opaDList = MakeDlist(opa, prefix); xluDList = MakeDlist(xlu, prefix); } -std::string PolygonDlist::GetBodySourceCode() const +std::string RoomShapeDListsEntry::GetBodySourceCode() const { std::string bodyStr; std::string opaStr; @@ -142,7 +142,7 @@ std::string PolygonDlist::GetBodySourceCode() const return bodyStr; } -void PolygonDlist::GetSourceOutputCode(const std::string& prefix) +void RoomShapeDListsEntry::GetSourceOutputCode(const std::string& prefix) { std::string bodyStr = StringHelper::Sprintf("\n\t%s\n", GetBodySourceCode().c_str()); @@ -151,28 +151,28 @@ void PolygonDlist::GetSourceOutputCode(const std::string& prefix) if (decl == nullptr) DeclareVar(prefix, bodyStr); else - decl->text = bodyStr; + decl->declBody = bodyStr; } -std::string PolygonDlist::GetSourceTypeName() const +std::string RoomShapeDListsEntry::GetSourceTypeName() const { switch (polyType) { case 2: - return "PolygonDlist2"; + return "RoomShapeCullableEntry"; default: - return "PolygonDlist"; + return "RoomShapeDListsEntry"; } } -ZResourceType PolygonDlist::GetResourceType() const +ZResourceType RoomShapeDListsEntry::GetResourceType() const { // TODO return ZResourceType::Error; } -size_t PolygonDlist::GetRawDataSize() const +size_t RoomShapeDListsEntry::GetRawDataSize() const { switch (polyType) { @@ -184,12 +184,13 @@ size_t PolygonDlist::GetRawDataSize() const } } -void PolygonDlist::SetPolyType(uint8_t nPolyType) +void RoomShapeDListsEntry::SetPolyType(uint8_t nPolyType) { polyType = nPolyType; } -ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, [[maybe_unused]] const std::string& prefix) +ZDisplayList* RoomShapeDListsEntry::MakeDlist(segptr_t ptr, + [[maybe_unused]] const std::string& prefix) { if (ptr == 0) { @@ -210,15 +211,15 @@ ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, [[maybe_unused]] const std:: return dlist; } -/* BgImage */ +/* RoomShapeImageMultiBgEntry */ -BgImage::BgImage(ZFile* nParent) : ZResource(nParent) +RoomShapeImageMultiBgEntry::RoomShapeImageMultiBgEntry(ZFile* nParent) : ZResource(nParent) { } -BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, uint32_t nRawDataIndex, - ZFile* nParent) - : BgImage(nParent) +RoomShapeImageMultiBgEntry::RoomShapeImageMultiBgEntry(bool nIsSubStruct, const std::string& prefix, + uint32_t nRawDataIndex, ZFile* nParent) + : RoomShapeImageMultiBgEntry(nParent) { rawDataIndex = nRawDataIndex; parent = nParent; @@ -230,7 +231,7 @@ BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, uint32_t nRawData sourceBackground = MakeBackground(source, prefix); } -void BgImage::ParseRawData() +void RoomShapeImageMultiBgEntry::ParseRawData() { size_t pad = 0x00; const auto& rawData = parent->GetRawData(); @@ -252,7 +253,7 @@ void BgImage::ParseRawData() tlutCount = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x14); } -ZBackground* BgImage::MakeBackground(segptr_t ptr, const std::string& prefix) +ZBackground* RoomShapeImageMultiBgEntry::MakeBackground(segptr_t ptr, const std::string& prefix) { if (ptr == 0) return nullptr; @@ -272,12 +273,12 @@ ZBackground* BgImage::MakeBackground(segptr_t ptr, const std::string& prefix) return background; } -size_t BgImage::GetRawDataSize() const +size_t RoomShapeImageMultiBgEntry::GetRawDataSize() const { return 0x1C; } -std::string BgImage::GetBodySourceCode() const +std::string RoomShapeImageMultiBgEntry::GetBodySourceCode() const { std::string bodyStr = " "; if (!isSubStruct) @@ -340,12 +341,12 @@ std::string BgImage::GetBodySourceCode() const return bodyStr; } -std::string BgImage::GetSourceTypeName() const +std::string RoomShapeImageMultiBgEntry::GetSourceTypeName() const { - return "BgImage"; + return "RoomShapeImageMultiBgEntry"; } -ZResourceType BgImage::GetResourceType() const +ZResourceType RoomShapeImageMultiBgEntry::GetResourceType() const { // TODO return ZResourceType::Error; @@ -371,7 +372,7 @@ void PolygonTypeBase::DeclareAndGenerateOutputCode(const std::string& prefix) } else { - decl->text = bodyStr; + decl->declBody = bodyStr; } } @@ -380,13 +381,13 @@ std::string PolygonTypeBase::GetSourceTypeName() const switch (type) { case 2: - return "PolygonType2"; + return "RoomShapeCullable"; case 1: return "PolygonType1"; default: - return "PolygonType0"; + return "RoomShapeNormal"; } } @@ -416,7 +417,7 @@ void PolygonType1::ParseRawData() if (dlist != 0) { - PolygonDlist polyGfxList(parent); + RoomShapeDListsEntry polyGfxList(parent); polyGfxList.zRoom = zRoom; polyGfxList.SetPolyType(type); polyGfxList.ExtractFromFile(Seg2Filespace(dlist, parent->baseAddress)); @@ -434,7 +435,7 @@ void PolygonType1::DeclareReferences(const std::string& prefix) switch (format) { case 1: - single = BgImage(true, prefix, rawDataIndex + 0x08, parent); + single = RoomShapeImageMultiBgEntry(true, prefix, rawDataIndex + 0x08, parent); break; case 2: @@ -446,7 +447,7 @@ void PolygonType1::DeclareReferences(const std::string& prefix) multiList.reserve(count); for (size_t i = 0; i < count; ++i) { - BgImage bg(false, prefix, auxPtr, parent); + RoomShapeImageMultiBgEntry bg(false, prefix, auxPtr, parent); multiList.push_back(bg); auxPtr += bg.GetRawDataSize(); bgImageArrayBody += bg.GetBodySourceCode(); @@ -507,7 +508,7 @@ std::string PolygonType1::GetBodySourceCode() const bodyStr += single.GetBodySourceCode(); break; case 2: - Globals::Instance->GetSegmentedPtrName(list, parent, "BgImage", listStr, parent->workerID); + Globals::Instance->GetSegmentedPtrName(list, parent, "RoomShapeImageMultiBgEntry", listStr, parent->workerID); bodyStr += StringHelper::Sprintf(" %i, %s, \n", count, listStr.c_str()); break; @@ -523,21 +524,21 @@ std::string PolygonType1::GetSourceTypeName() const switch (format) { case 1: - return "MeshHeader1Single"; + return "RoomShapeImageSingle"; case 2: - return "MeshHeader1Multi"; + return "RoomShapeImageMulti"; } return "ERROR"; // return "PolygonType1"; } -PolygonType2::PolygonType2(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom) +RoomShapeCullable::RoomShapeCullable(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom) : PolygonTypeBase(nParent, nRawDataIndex, nRoom) { } -void PolygonType2::ParseRawData() +void RoomShapeCullable::ParseRawData() { const auto& rawData = parent->GetRawData(); @@ -551,7 +552,7 @@ void PolygonType2::ParseRawData() polyDLists.reserve(num); for (size_t i = 0; i < num; i++) { - PolygonDlist entry(parent); + RoomShapeDListsEntry entry(parent); entry.zRoom = zRoom; entry.SetPolyType(type); entry.ExtractFromFile(currentPtr); @@ -561,7 +562,7 @@ void PolygonType2::ParseRawData() } } -void PolygonType2::DeclareReferences(const std::string& prefix) +void RoomShapeCullable::DeclareReferences(const std::string& prefix) { if (num > 0) { @@ -593,10 +594,10 @@ void PolygonType2::DeclareReferences(const std::string& prefix) "0x01000000"); } -std::string PolygonType2::GetBodySourceCode() const +std::string RoomShapeCullable::GetBodySourceCode() const { std::string listName; - Globals::Instance->GetSegmentedPtrName(start, parent, "", listName, parent->workerID); + Globals::Instance->GetSegmentedPtrName(start, parent, "", listName); std::string body = StringHelper::Sprintf("\n %i, %i,\n", type, polyDLists.size()); body += StringHelper::Sprintf(" %s,\n", listName.c_str()); @@ -605,12 +606,12 @@ std::string PolygonType2::GetBodySourceCode() const return body; } -size_t PolygonType2::GetRawDataSize() const +size_t RoomShapeCullable::GetRawDataSize() const { return 0x0C; } -DeclarationAlignment PolygonType2::GetDeclarationAlignment() const +DeclarationAlignment RoomShapeCullable::GetDeclarationAlignment() const { return DeclarationAlignment::Align4; } diff --git a/ZAPD/ZRoom/Commands/SetMesh.h b/ZAPD/ZRoom/Commands/SetMesh.h index 9d90374..c0f15da 100644 --- a/ZAPD/ZRoom/Commands/SetMesh.h +++ b/ZAPD/ZRoom/Commands/SetMesh.h @@ -5,7 +5,7 @@ #include "ZDisplayList.h" #include "ZRoom/ZRoomCommand.h" -class PolygonDlist : public ZResource +class RoomShapeDListsEntry : public ZResource { public: ZRoom* zRoom; @@ -21,7 +21,7 @@ public: ZDisplayList* opaDList = nullptr; // Gfx* ZDisplayList* xluDList = nullptr; // Gfx* - PolygonDlist(ZFile* nParent); + RoomShapeDListsEntry(ZFile* nParent); void ParseRawData() override; void DeclareReferences(const std::string& prefix) override; @@ -41,7 +41,7 @@ protected: ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix); }; -class BgImage : public ZResource +class RoomShapeImageMultiBgEntry : public ZResource { public: uint16_t unk_00; @@ -60,8 +60,9 @@ public: bool isSubStruct; - BgImage(ZFile* nParent); - BgImage(bool nIsSubStruct, const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent); + RoomShapeImageMultiBgEntry(ZFile* nParent); + RoomShapeImageMultiBgEntry(bool nIsSubStruct, const std::string& prefix, uint32_t nRawDataIndex, + ZFile* nParent); void ParseRawData() override; @@ -80,7 +81,7 @@ class PolygonTypeBase : public ZResource { public: uint8_t type; - std::vector<PolygonDlist> polyDLists; + std::vector<RoomShapeDListsEntry> polyDLists; PolygonTypeBase(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom); @@ -100,12 +101,12 @@ public: segptr_t dlist; // single - BgImage single; + RoomShapeImageMultiBgEntry single; // multi uint8_t count; - segptr_t list; // BgImage* - std::vector<BgImage> multiList; + segptr_t list; // RoomShapeImageMultiBgEntry* + std::vector<RoomShapeImageMultiBgEntry> multiList; PolygonType1(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom); @@ -119,14 +120,14 @@ public: size_t GetRawDataSize() const override; }; -class PolygonType2 : public PolygonTypeBase +class RoomShapeCullable : public PolygonTypeBase { public: uint8_t num; segptr_t start; segptr_t end; - PolygonType2(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom); + RoomShapeCullable(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom); void ParseRawData() override; void DeclareReferences(const std::string& prefix) override; diff --git a/ZAPD/ZRoom/Commands/SetMinimapList.cpp b/ZAPD/ZRoom/Commands/SetMinimapList.cpp index e02e1a9..68f2771 100644 --- a/ZAPD/ZRoom/Commands/SetMinimapList.cpp +++ b/ZAPD/ZRoom/Commands/SetMinimapList.cpp @@ -15,7 +15,7 @@ void SetMinimapList::ParseRawData() ZRoomCommand::ParseRawData(); listSegmentAddr = BitConverter::ToInt32BE(parent->GetRawData(), segmentOffset); listSegmentOffset = GETSEGOFFSET(listSegmentAddr); - unk4 = BitConverter::ToInt32BE(parent->GetRawData(), segmentOffset + 4); + scale = BitConverter::ToInt16BE(parent->GetRawData(), segmentOffset + 4); uint32_t currentPtr = listSegmentOffset; @@ -53,9 +53,8 @@ void SetMinimapList::DeclareReferences(const std::string& prefix) { std::string listName; - Globals::Instance->GetSegmentedPtrName(listSegmentAddr, parent, "MinimapEntry", listName, - parent->workerID); - std::string declaration = StringHelper::Sprintf("\n\t%s, 0x%08X\n", listName.c_str(), unk4); + Globals::Instance->GetSegmentedPtrName(listSegmentAddr, parent, "MinimapEntry", listName, parent->workerID); + std::string declaration = StringHelper::Sprintf("\n\t%s, %d\n", listName.c_str(), scale); parent->AddDeclaration( segmentOffset, DeclarationAlignment::Align4, 8, "MinimapList", diff --git a/ZAPD/ZRoom/Commands/SetMinimapList.h b/ZAPD/ZRoom/Commands/SetMinimapList.h index 5b18b3d..fcf7ad7 100644 --- a/ZAPD/ZRoom/Commands/SetMinimapList.h +++ b/ZAPD/ZRoom/Commands/SetMinimapList.h @@ -35,5 +35,5 @@ public: private: segptr_t listSegmentAddr; uint32_t listSegmentOffset; - uint32_t unk4; + int16_t scale; }; diff --git a/ZAPD/ZRoom/Commands/SetPathways.cpp b/ZAPD/ZRoom/Commands/SetPathways.cpp index f3bdb08..429a369 100644 --- a/ZAPD/ZRoom/Commands/SetPathways.cpp +++ b/ZAPD/ZRoom/Commands/SetPathways.cpp @@ -24,7 +24,7 @@ void SetPathways::ParseRawDataLate() { if (Globals::Instance->game == ZGame::MM_RETAIL) { - auto numPaths = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 8; + auto numPaths = zRoom->parent->GetDeclarationSizeFromNeighbor(segmentOffset) / 8; pathwayList.SetNumPaths(numPaths); } diff --git a/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp b/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp index 696a3de..34edf5a 100644 --- a/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp +++ b/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp @@ -17,8 +17,14 @@ void SetSpecialObjects::ParseRawData() std::string SetSpecialObjects::GetBodySourceCode() const { + EnumData* enumData = &Globals::Instance->cfg.enumData; std::string objectName = ZNames::GetObjectName(globalObject); + if (enumData->naviQuestHintType.find(elfMessage) != enumData->naviQuestHintType.end()) + return StringHelper::Sprintf("SCENE_CMD_SPECIAL_FILES(%s, %s)", + enumData->naviQuestHintType[elfMessage].c_str(), + objectName.c_str()); + return StringHelper::Sprintf("SCENE_CMD_SPECIAL_FILES(0x%02X, %s)", elfMessage, objectName.c_str()); } diff --git a/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp b/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp index d20e4a3..fa28547 100644 --- a/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp +++ b/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp @@ -1,6 +1,7 @@ #include "SetWorldMapVisited.h" #include "Utils/StringHelper.h" +#include "Globals.h" SetWorldMapVisited::SetWorldMapVisited(ZFile* nParent) : ZRoomCommand(nParent) { @@ -8,7 +9,10 @@ SetWorldMapVisited::SetWorldMapVisited(ZFile* nParent) : ZRoomCommand(nParent) std::string SetWorldMapVisited::GetBodySourceCode() const { - return "SCENE_CMD_MISC_SETTINGS()"; + if (Globals::Instance->game == ZGame::MM_RETAIL) + return "SCENE_CMD_SET_REGION_VISITED()"; + else + return "SCENE_CMD_MISC_SETTINGS()"; } std::string SetWorldMapVisited::GetCommandCName() const diff --git a/ZAPD/ZRoom/ZNames.h b/ZAPD/ZRoom/ZNames.h index 667407c..83c217e 100644 --- a/ZAPD/ZRoom/ZNames.h +++ b/ZAPD/ZRoom/ZNames.h @@ -48,11 +48,12 @@ public: static std::string GetEntranceName(uint16_t id) { if (ZNames::GetNumEntrances() == 0 || ZNames::GetNumSpecialEntrances() == 0) - return StringHelper::Sprintf("0x%04X", id); - + return StringHelper::Sprintf("0x%04X", id); + if (id < ZNames::GetNumEntrances()) return Globals::Instance->cfg.entranceList[id]; - else if ((id >= 0x7FF9 && id <= 0x7FFF) && !((id - 0x7FF9U) > GetNumSpecialEntrances())) // Special entrances + else if ((id >= 0x7FF9 && id <= 0x7FFF) && + !((id - 0x7FF9U) > GetNumSpecialEntrances())) // Special entrances return Globals::Instance->cfg.specialEntranceList[id - 0x7FF9]; else return StringHelper::Sprintf("0x%04X", id); @@ -60,5 +61,8 @@ public: static size_t GetNumActors() { return Globals::Instance->cfg.actorList.size(); } static size_t GetNumEntrances() { return Globals::Instance->cfg.entranceList.size(); } - static size_t GetNumSpecialEntrances() { return Globals::Instance->cfg.specialEntranceList.size(); } + static size_t GetNumSpecialEntrances() + { + return Globals::Instance->cfg.specialEntranceList.size(); + } }; diff --git a/ZAPD/ZRoom/ZRoom.cpp b/ZAPD/ZRoom/ZRoom.cpp index 11dd706..9b5f310 100644 --- a/ZAPD/ZRoom/ZRoom.cpp +++ b/ZAPD/ZRoom/ZRoom.cpp @@ -6,7 +6,7 @@ #include <string_view> #include "Commands/EndMarker.h" -#include "Commands/SetActorCutsceneList.h" +#include "Commands/SetCutsceneEntryList.h" #include "Commands/SetActorList.h" #include "Commands/SetAlternateHeaders.h" #include "Commands/SetAnimatedMaterialList.h" @@ -64,18 +64,14 @@ ZRoom::~ZRoom() delete cmd; } -void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) +void ZRoom::ExtractWithXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) { - ZResource::ExtractFromXML(reader, nRawDataIndex); + ZResource::ExtractWithXML(reader, nRawDataIndex); if (hackMode == "syotes_room") - { - SyotesRoomHack(); - } + SyotesRoomFix(); else - { DeclareVar(name, ""); - } } void ZRoom::ExtractFromBinary(uint32_t nRawDataIndex, ZResourceType parentType) @@ -338,9 +334,9 @@ std::string ZRoom::GetDefaultName(const std::string& prefix) const * back to very early in the game's development. Since this room is a special case, * declare automatically the data its contains whitout the need of a header. */ -void ZRoom::SyotesRoomHack() +void ZRoom::SyotesRoomFix() { - PolygonType2 poly(parent, 0, this); + RoomShapeCullable poly(parent, 0, this); poly.ParseRawData(); poly.DeclareReferences(GetName()); @@ -360,20 +356,6 @@ ZRoomCommand* ZRoom::FindCommandOfType(RoomCommand cmdType) return nullptr; } -size_t ZRoom::GetDeclarationSizeFromNeighbor(uint32_t declarationAddress) -{ - auto currentDecl = parent->declarations.find(declarationAddress); - if (currentDecl == parent->declarations.end()) - return 0; - - auto nextDecl = currentDecl; - std::advance(nextDecl, 1); - if (nextDecl == parent->declarations.end()) - return parent->GetRawData().size() - currentDecl->first; - - return nextDecl->first - currentDecl->first; -} - size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd) { int32_t cmdIndex = -1; diff --git a/ZAPD/ZRoom/ZRoom.h b/ZAPD/ZRoom/ZRoom.h index e837ec7..950dbbb 100644 --- a/ZAPD/ZRoom/ZRoom.h +++ b/ZAPD/ZRoom/ZRoom.h @@ -22,7 +22,7 @@ public: ZRoom(ZFile* nParent); virtual ~ZRoom(); - void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override; + void ExtractWithXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override; void ExtractFromBinary(uint32_t nRawDataIndex, ZResourceType parentType); void ParseXML(tinyxml2::XMLElement* reader) override; @@ -37,7 +37,6 @@ public: void GetSourceOutputCode(const std::string& prefix) override; std::string GetDefaultName(const std::string& prefix) const override; - size_t GetDeclarationSizeFromNeighbor(uint32_t declarationAddress); size_t GetCommandSizeFromNeighbor(ZRoomCommand* cmd); ZRoomCommand* FindCommandOfType(RoomCommand cmdType); @@ -46,5 +45,5 @@ public: ZResourceType GetResourceType() const override; protected: - void SyotesRoomHack(); + void SyotesRoomFix(); }; diff --git a/ZAPD/ZSkeleton.cpp b/ZAPD/ZSkeleton.cpp index a071209..21fe92e 100644 --- a/ZAPD/ZSkeleton.cpp +++ b/ZAPD/ZSkeleton.cpp @@ -194,7 +194,7 @@ std::string ZSkeleton::GetSourceTypeName() const case ZSkeletonType::Flex: return "FlexSkeletonHeader"; case ZSkeletonType::Curve: - return "SkelCurveLimbList"; + return "CurveSkeletonHeader"; } return "SkeletonHeader"; diff --git a/ZAPD/ZTexture.cpp b/ZAPD/ZTexture.cpp index 5184b83..cd37e72 100644 --- a/ZAPD/ZTexture.cpp +++ b/ZAPD/ZTexture.cpp @@ -145,31 +145,31 @@ void ZTexture::ParseRawData() switch (format) { case TextureType::RGBA16bpp: - PrepareBitmapRGBA16(); + ConvertN64ToBitmap_RGBA16(); break; case TextureType::RGBA32bpp: - PrepareBitmapRGBA32(); + ConvertN64ToBitmap_RGBA32(); break; case TextureType::Grayscale4bpp: - PrepareBitmapGrayscale4(); + ConvertN64ToBitmap_Grayscale4(); break; case TextureType::Grayscale8bpp: - PrepareBitmapGrayscale8(); + ConvertN64ToBitmap_Grayscale8(); break; case TextureType::GrayscaleAlpha4bpp: - PrepareBitmapGrayscaleAlpha4(); + ConvertN64ToBitmap_GrayscaleAlpha4(); break; case TextureType::GrayscaleAlpha8bpp: - PrepareBitmapGrayscaleAlpha8(); + ConvertN64ToBitmap_GrayscaleAlpha8(); break; case TextureType::GrayscaleAlpha16bpp: - PrepareBitmapGrayscaleAlpha16(); + ConvertN64ToBitmap_GrayscaleAlpha16(); break; case TextureType::Palette4bpp: - PrepareBitmapPalette4(); + ConvertN64ToBitmap_Palette4(); break; case TextureType::Palette8bpp: - PrepareBitmapPalette8(); + ConvertN64ToBitmap_Palette8(); break; case TextureType::Error: HANDLE_ERROR_RESOURCE(WarningType::InvalidAttributeValue, parent, this, rawDataIndex, @@ -220,10 +220,10 @@ void ZTexture::ParseRawDataLate() } } -void ZTexture::PrepareBitmapRGBA16() +void ZTexture::ConvertN64ToBitmap_RGBA16() { textureData.InitEmptyRGBImage(width, height, true); - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) @@ -235,15 +235,16 @@ void ZTexture::PrepareBitmapRGBA16() uint8_t b = (data & 0x003E) >> 1; uint8_t alpha = data & 0x01; - textureData.SetRGBPixel(y, x, r * 8, g * 8, b * 8, alpha * 255); + textureData.SetRGBPixel(y, x, (r << 3) | (r >> 2), (g << 3) | (g >> 2), + (b << 3) | (b >> 2), alpha * 255); } } } -void ZTexture::PrepareBitmapRGBA32() +void ZTexture::ConvertN64ToBitmap_RGBA32() { textureData.InitEmptyRGBImage(width, height, true); - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) @@ -259,10 +260,10 @@ void ZTexture::PrepareBitmapRGBA32() } } -void ZTexture::PrepareBitmapGrayscale4() +void ZTexture::ConvertN64ToBitmap_Grayscale4() { textureData.InitEmptyRGBImage(width, height, false); - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x += 2) @@ -277,16 +278,16 @@ void ZTexture::PrepareBitmapGrayscale4() else grayscale = (parentRawData.at(pos) & 0x0F) << 4; - textureData.SetGrayscalePixel(y, x + i, grayscale); + textureData.SetGrayscalePixel(y, x + i, (grayscale << 4) | grayscale); } } } } -void ZTexture::PrepareBitmapGrayscale8() +void ZTexture::ConvertN64ToBitmap_Grayscale8() { textureData.InitEmptyRGBImage(width, height, false); - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) @@ -298,10 +299,10 @@ void ZTexture::PrepareBitmapGrayscale8() } } -void ZTexture::PrepareBitmapGrayscaleAlpha4() +void ZTexture::ConvertN64ToBitmap_GrayscaleAlpha4() { textureData.InitEmptyRGBImage(width, height, true); - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x += 2) @@ -316,8 +317,9 @@ void ZTexture::PrepareBitmapGrayscaleAlpha4() else data = parentRawData.at(pos) & 0x0F; - uint8_t grayscale = ((data & 0x0E) >> 1) * 32; - uint8_t alpha = (data & 0x01) * 255; + uint8_t grayscale = data & 0b1110; + grayscale = (grayscale << 4) | (grayscale << 1) | (grayscale >> 2); + uint8_t alpha = (data & 0x01) ? 255 : 0; textureData.SetGrayscalePixel(y, x + i, grayscale, alpha); } @@ -325,27 +327,32 @@ void ZTexture::PrepareBitmapGrayscaleAlpha4() } } -void ZTexture::PrepareBitmapGrayscaleAlpha8() +void ZTexture::ConvertN64ToBitmap_GrayscaleAlpha8() { textureData.InitEmptyRGBImage(width, height, true); - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) { size_t pos = rawDataIndex + ((y * width) + x) * 1; - uint8_t grayscale = parentRawData.at(pos) & 0xF0; - uint8_t alpha = (parentRawData.at(pos) & 0x0F) << 4; + uint8_t pixel = parentRawData.at(pos); + uint8_t data = (pixel >> 4) & 0xF; + + data = (data << 4) | data; + uint8_t grayscale = data; + uint8_t alpha = (pixel & 0xF); + alpha = (alpha << 4) | alpha; textureData.SetGrayscalePixel(y, x, grayscale, alpha); } } } -void ZTexture::PrepareBitmapGrayscaleAlpha16() +void ZTexture::ConvertN64ToBitmap_GrayscaleAlpha16() { textureData.InitEmptyRGBImage(width, height, true); - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) @@ -359,10 +366,10 @@ void ZTexture::PrepareBitmapGrayscaleAlpha16() } } -void ZTexture::PrepareBitmapPalette4() +void ZTexture::ConvertN64ToBitmap_Palette4() { textureData.InitEmptyPaletteImage(width, height); - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x += 2) @@ -383,10 +390,10 @@ void ZTexture::PrepareBitmapPalette4() } } -void ZTexture::PrepareBitmapPalette8() +void ZTexture::ConvertN64ToBitmap_Palette8() { textureData.InitEmptyPaletteImage(width, height); - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); for (size_t y = 0; y < height; y++) { for (size_t x = 0; x < width; x++) @@ -431,36 +438,36 @@ void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath) height = textureData.GetHeight(); textureDataRaw.clear(); - textureDataRaw.resize(GetRawDataSize()); + textureDataRaw.resize(ALIGN8(GetRawDataSize())); switch (format) { case TextureType::RGBA16bpp: - PrepareRawDataRGBA16(); + ConvertBitmapToN64_RGBA16(); break; case TextureType::RGBA32bpp: - PrepareRawDataRGBA32(); + ConvertBitmapToN64_RGBA32(); break; case TextureType::Grayscale4bpp: - PrepareRawDataGrayscale4(); + ConvertBitmapToN64_Grayscale4(); break; case TextureType::Grayscale8bpp: - PrepareRawDataGrayscale8(); + ConvertBitmapToN64_Grayscale8(); break; case TextureType::GrayscaleAlpha4bpp: - PrepareRawDataGrayscaleAlpha4(); + ConvertBitmapToN64_GrayscaleAlpha4(); break; case TextureType::GrayscaleAlpha8bpp: - PrepareRawDataGrayscaleAlpha8(); + ConvertBitmapToN64_GrayscaleAlpha8(); break; case TextureType::GrayscaleAlpha16bpp: - PrepareRawDataGrayscaleAlpha16(); + ConvertBitmapToN64_GrayscaleAlpha16(); break; case TextureType::Palette4bpp: - PrepareRawDataPalette4(); + ConvertBitmapToN64_Palette4(); break; case TextureType::Palette8bpp: - PrepareRawDataPalette8(); + ConvertBitmapToN64_Palette8(); break; case TextureType::Error: HANDLE_ERROR_PROCESS(WarningType::InvalidPNG, "Input PNG file has invalid format type", ""); @@ -468,7 +475,7 @@ void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath) } } -void ZTexture::PrepareRawDataRGBA16() +void ZTexture::ConvertBitmapToN64_RGBA16() { for (uint16_t y = 0; y < height; y++) { @@ -477,13 +484,13 @@ void ZTexture::PrepareRawDataRGBA16() size_t pos = ((y * width) + x) * 2; RGBAPixel pixel = textureData.GetPixel(y, x); - uint8_t r = pixel.r / 8; - uint8_t g = pixel.g / 8; - uint8_t b = pixel.b / 8; + uint8_t r = pixel.r >> 3; + uint8_t g = pixel.g >> 3; + uint8_t b = pixel.b >> 3; uint8_t alphaBit = pixel.a != 0; - uint16_t data = (r << 11) + (g << 6) + (b << 1) + alphaBit; + uint16_t data = (r << 11) | (g << 6) | (b << 1) | alphaBit; textureDataRaw[pos + 0] = (data & 0xFF00) >> 8; textureDataRaw[pos + 1] = (data & 0x00FF); @@ -491,7 +498,7 @@ void ZTexture::PrepareRawDataRGBA16() } } -void ZTexture::PrepareRawDataRGBA32() +void ZTexture::ConvertBitmapToN64_RGBA32() { for (uint16_t y = 0; y < height; y++) { @@ -508,7 +515,7 @@ void ZTexture::PrepareRawDataRGBA32() } } -void ZTexture::PrepareRawDataGrayscale4() +void ZTexture::ConvertBitmapToN64_Grayscale4() { for (uint16_t y = 0; y < height; y++) { @@ -523,7 +530,7 @@ void ZTexture::PrepareRawDataGrayscale4() } } -void ZTexture::PrepareRawDataGrayscale8() +void ZTexture::ConvertBitmapToN64_Grayscale8() { for (uint16_t y = 0; y < height; y++) { @@ -536,7 +543,7 @@ void ZTexture::PrepareRawDataGrayscale8() } } -void ZTexture::PrepareRawDataGrayscaleAlpha4() +void ZTexture::ConvertBitmapToN64_GrayscaleAlpha4() { for (uint16_t y = 0; y < height; y++) { @@ -552,9 +559,9 @@ void ZTexture::PrepareRawDataGrayscaleAlpha4() uint8_t alphaBit = pixel.a != 0; if (i == 0) - data |= (((cR / 32) << 1) + alphaBit) << 4; + data = (((cR >> 5) << 1) | alphaBit) << 4; else - data |= ((cR / 32) << 1) + alphaBit; + data |= ((cR >> 5) << 1) | alphaBit; } textureDataRaw[pos] = data; @@ -562,7 +569,7 @@ void ZTexture::PrepareRawDataGrayscaleAlpha4() } } -void ZTexture::PrepareRawDataGrayscaleAlpha8() +void ZTexture::ConvertBitmapToN64_GrayscaleAlpha8() { for (uint16_t y = 0; y < height; y++) { @@ -571,15 +578,15 @@ void ZTexture::PrepareRawDataGrayscaleAlpha8() size_t pos = ((y * width) + x) * 1; RGBAPixel pixel = textureData.GetPixel(y, x); - uint8_t r = pixel.r; - uint8_t a = pixel.a; + uint8_t r = (pixel.r >> 4) & 0xF; + uint8_t a = (pixel.a >> 4) & 0xF; - textureDataRaw[pos] = ((r / 16) << 4) + (a / 16); + textureDataRaw[pos] = (r << 4) | a; } } } -void ZTexture::PrepareRawDataGrayscaleAlpha16() +void ZTexture::ConvertBitmapToN64_GrayscaleAlpha16() { for (uint16_t y = 0; y < height; y++) { @@ -597,7 +604,7 @@ void ZTexture::PrepareRawDataGrayscaleAlpha16() } } -void ZTexture::PrepareRawDataPalette4() +void ZTexture::ConvertBitmapToN64_Palette4() { for (uint16_t y = 0; y < height; y++) { @@ -613,7 +620,7 @@ void ZTexture::PrepareRawDataPalette4() } } -void ZTexture::PrepareRawDataPalette8() +void ZTexture::ConvertBitmapToN64_Palette8() { for (uint16_t y = 0; y < height; y++) { @@ -727,7 +734,6 @@ TextureType ZTexture::GetTextureType() const return format; } - void ZTexture::Save(const fs::path& outFolder) { // Optionally generate text file containing CRC information. This is going to be a one time @@ -787,10 +793,10 @@ Declaration* ZTexture::DeclareVar(const std::string& prefix, auto filepath = Globals::Instance->outputPath / fs::path(auxOutName).stem(); if (dWordAligned) - incStr = - StringHelper::Sprintf("%s.%s.inc.c", filepath.c_str(), GetExternalExtension().c_str()); + incStr = StringHelper::Sprintf("%s.%s.inc.c", filepath.string().c_str(), + GetExternalExtension().c_str()); else - incStr = StringHelper::Sprintf("%s.u32.%s.inc.c", filepath.c_str(), + incStr = StringHelper::Sprintf("%s.u32.%s.inc.c", filepath.string().c_str(), GetExternalExtension().c_str()); if (!Globals::Instance->cfg.texturePool.empty()) @@ -802,18 +808,31 @@ Declaration* ZTexture::DeclareVar(const std::string& prefix, if (poolEntry != Globals::Instance->cfg.texturePool.end()) { if (dWordAligned) - incStr = StringHelper::Sprintf("%s.%s.inc.c", poolEntry->second.path.c_str(), - GetExternalExtension().c_str()); + incStr = + StringHelper::Sprintf("%s.%s.inc.c", poolEntry->second.path.string().c_str(), + GetExternalExtension().c_str()); else - incStr = StringHelper::Sprintf("%s.u32.%s.inc.c", poolEntry->second.path.c_str(), + incStr = StringHelper::Sprintf("%s.u32.%s.inc.c", + poolEntry->second.path.string().c_str(), GetExternalExtension().c_str()); } } size_t texSizeDivisor = (dWordAligned) ? 8 : 4; - Declaration* decl = parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(), - GetSourceTypeName(), auxName, - GetRawDataSize() / texSizeDivisor); + Declaration* decl; + + if (parent->makeDefines) + { + decl = parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(), + GetSourceTypeName(), auxName, GetHeaderDefines(), + GetRawDataSize() / texSizeDivisor); + } + else + { + decl = parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(), + GetSourceTypeName(), auxName, + GetRawDataSize() / texSizeDivisor); + } decl->staticConf = staticConf; return decl; } @@ -830,14 +849,13 @@ std::string ZTexture::GetBodySourceCode() const if (i % 32 == 0) sourceOutput += " "; if (dWordAligned) - sourceOutput += StringHelper::Sprintf("0x%016llX, ", - BitConverter::ToUInt64BE(textureDataRaw, i)); + sourceOutput += + StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(textureDataRaw, i)); else - sourceOutput += StringHelper::Sprintf("0x%08llX, ", - BitConverter::ToUInt32BE(textureDataRaw, i)); - if (i % 32 == 24) sourceOutput += - StringHelper::Sprintf(" // 0x%06X \n", rawDataIndex + ((i / 32) * 32)); + StringHelper::Sprintf("0x%08llX, ", BitConverter::ToUInt32BE(textureDataRaw, i)); + if (i % 32 == 24) + sourceOutput += StringHelper::Sprintf(" // 0x%06X \n", rawDataIndex + ((i / 32) * 32)); } // Ensure there's always a trailing line feed to prevent dumb warnings. @@ -851,6 +869,17 @@ std::string ZTexture::GetBodySourceCode() const return sourceOutput; } +std::string ZTexture::GetHeaderDefines() const +{ + std::string definePrefix = StringHelper::camelCaseTo_SCREAMING_SNAKE_CASE(name.c_str(), true); + std::string ret = StringHelper::Sprintf("#define %s_WIDTH %d\n", definePrefix.c_str(), width); + + ret += StringHelper::Sprintf("#define %s_HEIGHT %d\n", definePrefix.c_str(), height); + ret += StringHelper::Sprintf("#define %s_SIZE 0x%zX\n", definePrefix.c_str(), GetRawDataSize()); + + return ret; +} + bool ZTexture::IsExternalResource() const { return true; diff --git a/ZAPD/ZTexture.h b/ZAPD/ZTexture.h index 8cece3f..1461ff9 100644 --- a/ZAPD/ZTexture.h +++ b/ZAPD/ZTexture.h @@ -30,26 +30,28 @@ protected: ZTexture* tlut = nullptr; bool splitTlut; - void PrepareBitmapRGBA16(); - void PrepareBitmapRGBA32(); - void PrepareBitmapGrayscale8(); - void PrepareBitmapGrayscaleAlpha8(); - void PrepareBitmapGrayscale4(); - void PrepareBitmapGrayscaleAlpha4(); - void PrepareBitmapGrayscaleAlpha16(); - void PrepareBitmapPalette4(); - void PrepareBitmapPalette8(); + // The following functions convert from N64 binary data to a bitmap to be saved to a PNG. + void ConvertN64ToBitmap_RGBA16(); + void ConvertN64ToBitmap_RGBA32(); + void ConvertN64ToBitmap_Grayscale8(); + void ConvertN64ToBitmap_GrayscaleAlpha8(); + void ConvertN64ToBitmap_Grayscale4(); + void ConvertN64ToBitmap_GrayscaleAlpha4(); + void ConvertN64ToBitmap_GrayscaleAlpha16(); + void ConvertN64ToBitmap_Palette4(); + void ConvertN64ToBitmap_Palette8(); + // The following functions convert from a bitmap to N64 binary data. void PrepareRawDataFromFile(const fs::path& inFolder); - void PrepareRawDataRGBA16(); - void PrepareRawDataRGBA32(); - void PrepareRawDataGrayscale4(); - void PrepareRawDataGrayscale8(); - void PrepareRawDataGrayscaleAlpha4(); - void PrepareRawDataGrayscaleAlpha8(); - void PrepareRawDataGrayscaleAlpha16(); - void PrepareRawDataPalette4(); - void PrepareRawDataPalette8(); + void ConvertBitmapToN64_RGBA16(); + void ConvertBitmapToN64_RGBA32(); + void ConvertBitmapToN64_Grayscale4(); + void ConvertBitmapToN64_Grayscale8(); + void ConvertBitmapToN64_GrayscaleAlpha4(); + void ConvertBitmapToN64_GrayscaleAlpha8(); + void ConvertBitmapToN64_GrayscaleAlpha16(); + void ConvertBitmapToN64_Palette4(); + void ConvertBitmapToN64_Palette8(); public: ZTexture(ZFile* nParent); @@ -68,9 +70,15 @@ public: Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override; std::string GetBodySourceCode() const override; + + /// <summary> + /// Calculates the hash of this texture, for use with the texture pool. + /// </summary> void CalcHash() override; + void Save(const fs::path& outFolder) override; + std::string GetHeaderDefines() const; bool IsExternalResource() const override; std::string GetSourceTypeName() const override; ZResourceType GetResourceType() const override; @@ -83,10 +91,28 @@ public: uint32_t GetWidth() const; uint32_t GetHeight() const; void SetDimensions(uint32_t nWidth, uint32_t nHeight); + + /// <summary> + /// Returns how many bytes each pixel takes up. + /// </summary> + /// <returns></returns> float GetPixelMultiplyer() const; + TextureType GetTextureType() const; + + /// <summary> + /// Returns the path to the texture pool, taken from the config file. + /// </summary> + /// <param name="defaultValue"></param> + /// <returns></returns> fs::path GetPoolOutPath(const fs::path& defaultValue); + + /// <summary> + /// Returns if this texture uses a palette. + /// </summary> + /// <returns></returns> bool IsColorIndexed() const; + void SetTlut(ZTexture* nTlut); bool HasTlut() const; void ParseRawDataLate() override; diff --git a/ZAPD/ZTextureAnimation.cpp b/ZAPD/ZTextureAnimation.cpp index 233a54d..e254635 100644 --- a/ZAPD/ZTextureAnimation.cpp +++ b/ZAPD/ZTextureAnimation.cpp @@ -574,6 +574,7 @@ void ZTextureAnimation::DeclareReferences(const std::string& prefix) count = 2; } params = new TextureScrollingParams(parent); + params->type = entry.type; params->ExtractFromBinary(paramsOffset, count); break; @@ -587,6 +588,7 @@ void ZTextureAnimation::DeclareReferences(const std::string& prefix) case TextureAnimationParamsType::TextureCycle: params = new TextureCyclingParams(parent); + params->type = entry.type; params->ExtractFromBinary(paramsOffset); break; diff --git a/ZAPD/ZWaterbox.cpp b/ZAPD/ZWaterbox.cpp new file mode 100644 index 0000000..9a289db --- /dev/null +++ b/ZAPD/ZWaterbox.cpp @@ -0,0 +1,74 @@ +#include "ZWaterbox.h" + +#include "Globals.h" +#include "Utils/BitConverter.h" +#include "Utils/StringHelper.h" + +REGISTER_ZFILENODE(Waterbox, ZWaterbox); + +ZWaterbox::ZWaterbox(ZFile* nParent) : ZResource(nParent) +{ +} + +ZWaterbox::~ZWaterbox() +{ +} + +void ZWaterbox::ParseRawData() +{ + const auto& rawData = parent->GetRawData(); + + 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(rawData, rawDataIndex + 10); + else + properties = BitConverter::ToInt32BE(rawData, rawDataIndex + 12); +} + +void ZWaterbox::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 ZWaterbox::GetBodySourceCode() const +{ + return StringHelper::Sprintf("%i, %i, %i, %i, %i, 0x%08X", xMin, ySurface, zMin, xLength, + zLength, properties); +} + +std::string ZWaterbox::GetDefaultName(const std::string& prefix) const +{ + return StringHelper::Sprintf("%sWaterBoxes_%06X", prefix.c_str(), rawDataIndex); +} + +ZResourceType ZWaterbox::GetResourceType() const +{ + return ZResourceType::Waterbox; +} + +size_t ZWaterbox::GetRawDataSize() const +{ + return 16; +} + +std::string ZWaterbox::GetSourceTypeName() const +{ + return "WaterBox"; +} + +bool ZWaterbox::DoesSupportArray() const +{ + return true; +} diff --git a/ZAPD/ZWaterbox.h b/ZAPD/ZWaterbox.h new file mode 100644 index 0000000..e190b26 --- /dev/null +++ b/ZAPD/ZWaterbox.h @@ -0,0 +1,30 @@ +#pragma once + +#include "ZFile.h" +#include "ZResource.h" + +class ZWaterbox : public ZResource +{ +public: + int16_t xMin; + int16_t ySurface; + int16_t zMin; + int16_t xLength; + int16_t zLength; + int32_t properties; + + ZWaterbox(ZFile* nParent); + ~ZWaterbox(); + + 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; +}; diff --git a/ZAPD/genbuildinfo.py b/ZAPD/genbuildinfo.py index 91a567d..3317c42 100644 --- a/ZAPD/genbuildinfo.py +++ b/ZAPD/genbuildinfo.py @@ -10,7 +10,13 @@ parser.add_argument("--devel", action="store_true") args = parser.parse_args() with open("build/ZAPD/BuildInfo.cpp", "w+") as buildFile: - label = subprocess.check_output(["git", "describe", "--always"]).strip().decode("utf-8") + # Get commit hash from git + # If git fails due to a missing .git directory, a default label will be used instead. + try: + label = subprocess.check_output(["git", "describe", "--always"]).strip().decode("utf-8") + except: + label = "GIT_NOT_FOUND" + now = datetime.now() if args.devel: label += " ~ Development version" |
