diff --git a/include/z64animation_legacy.h b/include/z64animation_legacy.h index f5f68bfc8c0..f4c222a5cc9 100644 --- a/include/z64animation_legacy.h +++ b/include/z64animation_legacy.h @@ -21,10 +21,6 @@ typedef struct { /* 0x0A */ s16 z; } LegacyJointKey; // size = 0x0C -// ZAPD compatibility typedefs -// TODO: Remove when ZAPD adds support for them -typedef LegacyJointKey JointKey; - typedef struct { /* 0x00 */ s16 frameCount; /* 0x02 */ s16 limbCount; diff --git a/include/z64bgcheck.h b/include/z64bgcheck.h index 2396b9ccbe4..9ff85c55e4b 100644 --- a/include/z64bgcheck.h +++ b/include/z64bgcheck.h @@ -72,10 +72,6 @@ typedef struct { /* 0x4 */ Vec3s* bgCamFuncData; // s16 data grouped in threes (ex. Vec3s), is usually of type `BgCamFuncData`, but can be a list of points of type `Vec3s` for crawlspaces } BgCamInfo; // size = 0x8 -// ZAPD compatibility typedefs -// TODO: Remove when ZAPD adds support for them -typedef BgCamInfo CamData; - // The structure used for all instances of s16 data from `BgCamInfo` with the exception of crawlspaces. // See `Camera_Subj4` for Vec3s data usage in crawlspaces typedef struct { diff --git a/include/z64curve.h b/include/z64curve.h index 1864f2116ef..b150302e9c7 100644 --- a/include/z64curve.h +++ b/include/z64curve.h @@ -59,10 +59,4 @@ s32 SkelCurve_Update(struct PlayState* play, SkelCurve* skelCurve); void SkelCurve_Draw(Actor* actor, struct PlayState* play, SkelCurve* skelCurve, OverrideCurveLimbDraw overrideLimbDraw, PostCurveLimbDraw postLimbDraw, s32 lod, void* data); -// ZAPD compatibility typedefs -// TODO: Remove when ZAPD adds support for them -typedef CurveInterpKnot TransformData; -typedef CurveAnimationHeader TransformUpdateIndex; -typedef CurveSkeletonHeader SkelCurveLimbList; - #endif diff --git a/include/z64cutscene.h b/include/z64cutscene.h index 004bdb6904e..ebd2612203a 100644 --- a/include/z64cutscene.h +++ b/include/z64cutscene.h @@ -494,10 +494,6 @@ typedef union { #define CS_CAM_CONTINUE 0 #define CS_CAM_STOP -1 -// todo: remove after ZAPD is updated -#define CS_CMD_CONTINUE CS_CAM_CONTINUE -#define CS_CMD_STOP CS_CAM_STOP - #define CS_CAM_DATA_NOT_APPLIED 0xFFFF typedef struct { diff --git a/include/z64cutscene_commands.h b/include/z64cutscene_commands.h index f467fc32c47..beaecb79842 100644 --- a/include/z64cutscene_commands.h +++ b/include/z64cutscene_commands.h @@ -271,50 +271,4 @@ CMD_W(unk1), CMD_W(unk2), CMD_W(unk3), CMD_W(unk4), CMD_W(unk5), CMD_W(unk6), \ CMD_W(unk7), CMD_W(unk8), CMD_W(unk9), CMD_W(unk10), CMD_W(unk11), CMD_W(unk12) -// TODO: Fix ZAPD and delete these (everything to the end of the file) -#define CS_CAM_POS_LIST CS_CAM_EYE_SPLINE -#define CS_CAM_POS CS_CAM_POINT -#define CS_CAM_FOCUS_POINT_LIST CS_CAM_AT_SPLINE -#define CS_CAM_FOCUS_POINT CS_CAM_POINT -#define CS_CAM_POS_PLAYER_LIST CS_CAM_EYE_SPLINE_REL_TO_PLAYER -#define CS_CAM_POS_PLAYER CS_CAM_POINT -#define CS_CAM_FOCUS_POINT_PLAYER_LIST CS_CAM_AT_SPLINE_REL_TO_PLAYER -#define CS_CAM_FOCUS_POINT_PLAYER CS_CAM_POINT -#define CS_NPC_ACTION_LIST CS_ACTOR_CUE_LIST -#define CS_NPC_ACTION CS_ACTOR_CUE -#define CS_PLAYER_ACTION_LIST CS_PLAYER_CUE_LIST -#define CS_PLAYER_ACTION CS_PLAYER_CUE -#define CS_LIGHTING_LIST CS_LIGHT_SETTING_LIST -#define CS_CMD_09_LIST CS_RUMBLE_CONTROLLER_LIST -#define CS_CMD_09 CS_RUMBLE_CONTROLLER -#define CS_TEXT_DISPLAY_TEXTBOX CS_TEXT -#define CS_TEXT_LEARN_SONG CS_TEXT_OCARINA_ACTION -#define CS_SCENE_TRANS_FX CS_TRANSITION -#define CS_PLAY_BGM_LIST CS_START_SEQ_LIST -#define CS_STOP_BGM_LIST CS_STOP_SEQ_LIST -#define CS_FADE_BGM_LIST CS_FADE_OUT_SEQ_LIST -#define CS_FADE_BGM CS_FADE_OUT_SEQ -#define CS_TERMINATOR CS_DESTINATION - -// CS_TIME macro: -// The last argument of the macro was removed, but ZAPD isn't aware -// Passing 6 arguments to a 5-arguments macro works fine with IDO, so ignore this hack for IDO -#ifndef __sgi -// Only spot06_scene uses CS_TIME. Limit the hack to that file, so everything else can use the new macro -# ifdef SPOT06_SCENE_H -# undef CS_TIME -# define CS_TIME(unused0, startFrame, endFrame, hour, min, _unusedZapdCompatibilityArg) \ - CMD_HH(unused0, startFrame), CMD_HBB(endFrame, hour, min), CMD_W(0) -# endif -#endif - -#define CS_PLAY_BGM(seqId, startFrame, endFrame, unused0, unused1, unused2, unused3, unused4, unused5, unused6, unused7) \ -CS_START_SEQ((seqId)-1, startFrame, endFrame, unused0, unused1, unused2, unused3, unused4, unused5, unused6, unused7) - -#define CS_STOP_BGM(seqId, frame, unused0, unused1, unused2, unused3, unused4, unused5, unused6, unused7, unused8) \ -CS_STOP_SEQ((seqId)-1, frame, unused0, unused1, unused2, unused3, unused4, unused5, unused6, unused7, unused8) - -#define CS_LIGHTING(lightSetting, frame, unused0, unused1, unused2, unused3, unused4, unused5, unused6, unused7, unused8) \ -CS_LIGHT_SETTING((lightSetting)-1, frame, unused0, unused1, unused2, unused3, unused4, unused5, unused6, unused7, unused8) - #endif diff --git a/include/z64environment.h b/include/z64environment.h index 0269c443d47..922c544258f 100644 --- a/include/z64environment.h +++ b/include/z64environment.h @@ -166,10 +166,6 @@ typedef struct { /* 0x14 */ s16 zFar; } EnvLightSettings; // size = 0x16 -// ZAPD compatibility typedefs -// TODO: Remove when ZAPD adds support for them -typedef EnvLightSettings LightSettings; - typedef struct { /* 0x00 */ char unk_00[0x02]; /* 0x02 */ u16 sceneTimeSpeed; // time speed value from the scene file diff --git a/include/z64scene.h b/include/z64scene.h index 106fd62cb38..a08d438bd97 100644 --- a/include/z64scene.h +++ b/include/z64scene.h @@ -38,9 +38,6 @@ typedef struct { /* 0x01 */ u8 room; } Spawn; -// TODO: ZAPD Compatibility -typedef Spawn EntranceEntry; - typedef struct { /* 0x00 */ u8 count; // number of points in the path /* 0x04 */ Vec3s* points; // Segment Address to the array of points @@ -142,17 +139,6 @@ typedef union { RoomShapeCullable cullable; } RoomShape; // "Ground Shape" -// ZAPD compatibility typedefs -// TODO: Remove when ZAPD adds support for them -typedef RoomShapeDListsEntry PolygonDlist; -typedef RoomShapeNormal PolygonType0; -typedef RoomShapeImageSingle MeshHeader1Single; -typedef RoomShapeImageMultiBgEntry BgImage; -typedef RoomShapeImageMulti MeshHeader1Multi; -typedef RoomShapeCullableEntry PolygonDlist2; -typedef RoomShapeCullable PolygonType2; -#define SCENE_CMD_MESH SCENE_CMD_ROOM_SHAPE - #define ROOM_DRAW_OPA (1 << 0) #define ROOM_DRAW_XLU (1 << 1) @@ -459,7 +445,6 @@ typedef enum { #define SCENE_CAM_TYPE_SHOOTING_GALLERY 0x50 // Unreferenced in code, and used only by the main layer of the shooting gallery scene // navi hints -// TODO: make ZAPD use this enum for `SCENE_CMD_SPECIAL_FILES` typedef enum { NAVI_QUEST_HINTS_NONE, NAVI_QUEST_HINTS_OVERWORLD, diff --git a/include/z64skin.h b/include/z64skin.h index e9d8689d898..a199ed41b1e 100644 --- a/include/z64skin.h +++ b/include/z64skin.h @@ -43,13 +43,6 @@ typedef struct { /* 0x08 */ Gfx* dlist; } SkinAnimatedLimbData; // size = 0xC -// ZAPD compatibility typedefs -// TODO: Remove when ZAPD adds support for them -typedef SkinVertex Struct_800A57C0; -typedef SkinTransformation Struct_800A598C_2; -typedef SkinAnimatedLimbData Struct_800A5E28; -typedef SkinLimbModif Struct_800A598C; - #define SKIN_LIMB_TYPE_ANIMATED 4 #define SKIN_LIMB_TYPE_NORMAL 11 diff --git a/tools/ZAPD/.clang-format b/tools/ZAPD/.clang-format index 784e734e97c..5ba1c4a9552 100644 --- a/tools/ZAPD/.clang-format +++ b/tools/ZAPD/.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/tools/ZAPD/.gitrepo b/tools/ZAPD/.gitrepo index 07fe061d5fa..7255f43aa91 100644 --- a/tools/ZAPD/.gitrepo +++ b/tools/ZAPD/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/zeldaret/ZAPD.git branch = master - commit = dcf56d93ecbd4db3bfd8a4832d7f991467964b98 - parent = 9bad1d108e6311562c8424eefc92f0f1004551c9 + commit = 094e797349c86d0baef4a624962f4287aefdfef2 + parent = 503f6d86d5fca5bd234640ef9de597d413cb91f5 method = merge - cmdver = 0.4.5 + cmdver = 0.4.6 diff --git a/tools/ZAPD/ExporterTest/CollisionExporter.cpp b/tools/ZAPD/ExporterTest/CollisionExporter.cpp index db5ad1a7955..6431a4593c8 100644 --- a/tools/ZAPD/ExporterTest/CollisionExporter.cpp +++ b/tools/ZAPD/ExporterTest/CollisionExporter.cpp @@ -67,9 +67,9 @@ void ExporterExample_Collision::Save(ZResource* res, [[maybe_unused]] fs::path o 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/tools/ZAPD/ExporterTest/Makefile b/tools/ZAPD/ExporterTest/Makefile index 42033b7c0c4..98e04752541 100644 --- a/tools/ZAPD/ExporterTest/Makefile +++ b/tools/ZAPD/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/tools/ZAPD/ExporterTest/RoomExporter.cpp b/tools/ZAPD/ExporterTest/RoomExporter.cpp index 9a5ea19d146..4cc06b76f5d 100644 --- a/tools/ZAPD/ExporterTest/RoomExporter.cpp +++ b/tools/ZAPD/ExporterTest/RoomExporter.cpp @@ -290,7 +290,7 @@ void ExporterExample_Room::Save(ZResource* res, fs::path outPath, BinaryWriter* 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); diff --git a/tools/ZAPD/Makefile b/tools/ZAPD/Makefile index e725f94f8bd..36331937a7d 100644 --- a/tools/ZAPD/Makefile +++ b/tools/ZAPD/Makefile @@ -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 diff --git a/tools/ZAPD/README.md b/tools/ZAPD/README.md index bb96bab1b0d..76dfbd1e952 100644 --- a/tools/ZAPD/README.md +++ b/tools/ZAPD/README.md @@ -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/tools/ZAPD/ZAPD/CRC32.h b/tools/ZAPD/ZAPD/CRC32.h index 4158a552896..1f82c75c589 100644 --- a/tools/ZAPD/ZAPD/CRC32.h +++ b/tools/ZAPD/ZAPD/CRC32.h @@ -1,6 +1,6 @@ #pragma once -static uint32_t CRC32B(unsigned char* message, int32_t size) +static uint32_t CRC32B(const unsigned char* message, int32_t size) { int32_t byte, crc; int32_t mask; diff --git a/tools/ZAPD/ZAPD/CrashHandler.cpp b/tools/ZAPD/ZAPD/CrashHandler.cpp index 35686653651..7ddec5a7e8d 100644 --- a/tools/ZAPD/ZAPD/CrashHandler.cpp +++ b/tools/ZAPD/ZAPD/CrashHandler.cpp @@ -8,6 +8,7 @@ #endif #include +#include #include #include #include diff --git a/tools/ZAPD/ZAPD/Declaration.cpp b/tools/ZAPD/ZAPD/Declaration.cpp index 34ab9535173..30863803a2a 100644 --- a/tools/ZAPD/ZAPD/Declaration.cpp +++ b/tools/ZAPD/ZAPD/Declaration.cpp @@ -4,61 +4,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; } bool Declaration::IsStatic() const @@ -82,9 +100,6 @@ std::string Declaration::GetNormalDeclarationStr() const { std::string output; - if (preText != "") - output += preText + "\n"; - if (IsStatic()) { output += "static "; @@ -92,27 +107,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') @@ -120,14 +136,8 @@ std::string Declaration::GetNormalDeclarationStr() const else output += " };"; - if (rightText != "") - output += " " + rightText + ""; - output += "\n"; - if (postText != "") - output += postText + "\n"; - output += "\n"; return output; @@ -137,41 +147,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 ""; } @@ -180,19 +183,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 @@ -210,15 +222,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/tools/ZAPD/ZAPD/Declaration.h b/tools/ZAPD/ZAPD/Declaration.h index 4a743b50fa7..d079cb8dced 100644 --- a/tools/ZAPD/ZAPD/Declaration.h +++ b/tools/ZAPD/ZAPD/Declaration.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -22,59 +23,160 @@ enum class StaticConfig On }; +/// +/// 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. +/// 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 = ""; + + // 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 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); + /// + /// Creates a regular declaration. + /// + /// The address inside a binary file this declaration will be in when + /// compiled. The alignment of this declaration in the compiled + /// binary file. The size of this declaration when it is compiled + /// to binary data. The C variable type this declaration will be + /// declared as. The C variable name this declaration will be + /// declared as. The contents of the C variable + /// declaration. + static Declaration* Create(offset_t declAddr, DeclarationAlignment declAlign, size_t declSize, + const std::string& declType, const std::string& declName, + const std::string& declBody); + + /// + /// Creates an array declaration. + /// + /// The address inside a binary file this declaration will be in when + /// compiled. The alignment of this declaration in the compiled + /// binary file. The size of this declaration when it is compiled + /// to binary data. The C variable type this declaration will be + /// declared as. The C variable name this declaration will be + /// declared as. The contents of the C variable + /// declaration. The number of items in the + /// array. (Optional) Is this declaration from another + /// segment? + 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); + + /// + /// Creates an array declaration who's size in the C code uses a custom string. + /// + /// The address inside a binary file this declaration will be in when + /// compiled. The alignment of this declaration in the compiled + /// binary file. The size of this declaration when it is compiled + /// to binary data. The C variable type this declaration will be + /// declared as. The C variable name this declaration will be + /// declared as. The contents of the C variable + /// declaration. The string to be put in the C array's + /// size inbetween the brackets. (Optional) Is this + /// declaration from another segment? + 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); - Declaration(offset_t nAddress, const std::string& nIncludePath, size_t nSize, - const std::string& nVarType, const std::string& nVarName); + /// + /// Creates a declaration who's body uses a #include to include another file + /// + /// The address inside a binary file this declaration will be in when + /// compiled. The path to the file this declaration will be + /// #including. The size of this declaration when it is compiled + /// to binary data. The C variable type this declaration will be + /// declared as. The C variable name this declaration will be + /// declared as. (Optional) Any #define's we want to have + /// outputted by this declaration. + 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 = ""); + + /// + /// Creates a placeholder declaration to be replaced later. + /// + /// The address inside a binary file this declaration will be in when + /// compiled. The C variable name this declaration will be + /// declared as. + static Declaration* CreatePlaceholder(offset_t declAddr, const std::string& declName); 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/tools/ZAPD/ZAPD/ExporterSet.h b/tools/ZAPD/ZAPD/ExporterSet.h new file mode 100644 index 00000000000..c4dd93445a6 --- /dev/null +++ b/tools/ZAPD/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 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/tools/ZAPD/ZAPD/GameConfig.cpp b/tools/ZAPD/ZAPD/GameConfig.cpp index 777cf9d49ca..a6e3bdba2f2 100644 --- a/tools/ZAPD/ZAPD/GameConfig.cpp +++ b/tools/ZAPD/ZAPD/GameConfig.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "Utils/Directory.h" #include "Utils/File.h" @@ -124,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) @@ -163,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 ConfigFuncDictionary = { @@ -173,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/tools/ZAPD/ZAPD/GameConfig.h b/tools/ZAPD/ZAPD/GameConfig.h index 2a783d10a81..0eb3f020292 100644 --- a/tools/ZAPD/ZAPD/GameConfig.h +++ b/tools/ZAPD/ZAPD/GameConfig.h @@ -21,6 +21,32 @@ class ExternalFile 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 cutsceneCmd; + std::map miscType; + std::map fadeOutSeqPlayer; + std::map transitionType; + std::map naviQuestHintType; + + // OoT + std::map textType; + std::map destination; + + // MM + std::map modifySeqType; + std::map chooseCreditsSceneType; + std::map destinationType; + std::map motionBlurType; + std::map transitionGeneralType; + std::map rumbleType; + std::map spawnFlag; + std::map endSfx; +}; + class ZFile; class GameConfig @@ -34,9 +60,12 @@ class GameConfig std::vector entranceList; std::vector specialEntranceList; std::map 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 @@ class GameConfig 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/tools/ZAPD/ZAPD/Globals.cpp b/tools/ZAPD/ZAPD/Globals.cpp index a10705e9af3..02380f69024 100644 --- a/tools/ZAPD/ZAPD/Globals.cpp +++ b/tools/ZAPD/ZAPD/Globals.cpp @@ -83,9 +83,10 @@ ExporterSet* Globals::GetExporterSet() } bool Globals::GetSegmentedPtrName(segptr_t segAddress, ZFile* currentFile, - const std::string& expectedType, std::string& declName) + const std::string& expectedType, std::string& declName, + bool warnIfNotFound) { - if (segAddress == 0) + if (segAddress == SEGMENTED_NULL) { declName = "NULL"; return true; @@ -160,14 +161,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) + std::string& declName, bool warnIfNotFound) { - if (segAddress == 0) + if (segAddress == SEGMENTED_NULL) { declName = "NULL"; return true; @@ -197,9 +202,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/tools/ZAPD/ZAPD/Globals.h b/tools/ZAPD/ZAPD/Globals.h index 1ae753e2042..0bfcaeec72e 100644 --- a/tools/ZAPD/ZAPD/Globals.h +++ b/tools/ZAPD/ZAPD/Globals.h @@ -5,6 +5,7 @@ #include #include "GameConfig.h" #include "ZFile.h" +#include "ExporterSet.h" class ZRoom; @@ -15,29 +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 (*ExporterSetResSave)(ZResource* res, BinaryWriter& writer); - -class ExporterSet -{ -public: - ~ExporterSet(); - - std::map 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; -}; - class Globals { public: @@ -86,8 +64,14 @@ class Globals * 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); + const std::string& expectedType, std::string& declName, + bool warnIfNotFound = true); bool GetSegmentedArrayIndexedName(segptr_t segAddress, size_t elementSize, ZFile* currentFile, - const std::string& expectedType, std::string& declName); + const std::string& expectedType, std::string& declName, + bool warnIfNotFound = true); + + // TODO: consider moving to another place + void WarnHardcodedPointer(segptr_t segAddress, ZFile* currentFile, ZResource* res, + offset_t currentOffset); }; diff --git a/tools/ZAPD/ZAPD/Main.cpp b/tools/ZAPD/ZAPD/Main.cpp index 2563154e51a..40a38bc601d 100644 --- a/tools/ZAPD/ZAPD/Main.cpp +++ b/tools/ZAPD/ZAPD/Main.cpp @@ -9,24 +9,52 @@ #include "ZFile.h" #include "ZTexture.h" +#include #include "CrashHandler.h" #include #include #include "tinyxml2.h" +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); +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); extern const char gBuildHash[]; int main(int argc, char* argv[]) { - // Syntax: ZAPD.out [mode (btex/bovl/e)] (Arbritrary Number of Arguments) + int returnCode = 0; if (argc < 2) { @@ -55,112 +83,12 @@ int 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 == "-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(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 - { - 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; - } - } + ParseArgs(argc, argv); // Parse File Mode ExporterSet* exporterSet = Globals::Instance->GetExporterSet(); 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 (exporterSet != nullptr && exporterSet->parseFileModeFunc != nullptr) - exporterSet->parseFileModeFunc(buildMode, fileMode); + ZFileMode fileMode = ParseFileMode(buildMode, exporterSet); if (fileMode == ZFileMode::Invalid) { @@ -170,7 +98,6 @@ int 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++) @@ -181,62 +108,20 @@ int 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) - { - 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; - } - } + 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); - } delete g; - return 0; + return returnCode; } bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath, @@ -339,6 +224,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 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(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) { std::string name = outPath.stem().string(); diff --git a/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.cpp b/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.cpp index edefbc0518f..85fce2215dd 100644 --- a/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.cpp +++ b/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.cpp @@ -1,40 +1,46 @@ #include "CutsceneMM_Commands.h" -#include #include - +#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 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 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& rawData, offset_t rawDataIndex, CutsceneMMCommands cmdId) +CutsceneMMSubCommandEntry_GenericCmd::CutsceneMMSubCommandEntry_GenericCmd( + const std::vector& 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& rawData, offset_t rawDataIndex, - CutsceneMMCommands cmdId) + CutsceneMM_CommandType cmdId) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; @@ -57,7 +100,7 @@ CutsceneMMCommand_GenericCmd::CutsceneMMCommand_GenericCmd(const std::vectorGetRawSize(); } @@ -65,7 +108,7 @@ CutsceneMMCommand_GenericCmd::CutsceneMMCommand_GenericCmd(const std::vector(commandID)); + const auto& element = csCommandsDescMM.find(static_cast(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& rawData, offset_t rawDataIndex) : CutsceneSubCommandEntry(rawData, rawDataIndex) @@ -108,10 +153,12 @@ CutsceneMMCommand_Camera::CutsceneMMCommand_Camera(const std::vector& 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& 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& rawData, - offset_t rawDataIndex) +CutsceneMMCommand_TransitionGeneral::CutsceneMMCommand_TransitionGeneral( + const std::vector& rawData, offset_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; @@ -143,36 +197,45 @@ CutsceneMMCommand_FadeScreen::CutsceneMMCommand_FadeScreen(const std::vectorGetRawSize(); } } -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& 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& rawData, - offset_t rawDataIndex) +CutsceneMMCommand_FadeOutSeq::CutsceneMMCommand_FadeOutSeq(const std::vector& rawData, + offset_t rawDataIndex) : CutsceneCommand(rawData, rawDataIndex) { rawDataIndex += 4; @@ -180,17 +243,19 @@ CutsceneMMCommand_FadeSeq::CutsceneMMCommand_FadeSeq(const std::vector& 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& 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& 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& 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& 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& 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& 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(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& 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(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/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.h b/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.h index c8ae4eb6037..fb2f772752e 100644 --- a/tools/ZAPD/ZAPD/OtherStructs/CutsceneMM_Commands.h +++ b/tools/ZAPD/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& rawData, offset_t rawDataIndex, - CutsceneMMCommands cmdId); + CutsceneMMSubCommandEntry_GenericCmd(const std::vector& 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& 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 @@ class CutsceneMMCommand_Camera : public CutsceneCommand 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 @@ class CutsceneSubCommandEntry_FadeScreen : public CutsceneSubCommandEntry uint8_t unk_0A; uint8_t unk_0B; - CutsceneSubCommandEntry_FadeScreen(const std::vector& rawData, offset_t rawDataIndex); + CutsceneSubCommandEntry_TransitionGeneral(const std::vector& 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& rawData, offset_t rawDataIndex); + CutsceneMMCommand_TransitionGeneral(const std::vector& 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& rawData, offset_t rawDataIndex); + CutsceneSubCommandEntry_FadeOutSeq(const std::vector& 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& rawData, offset_t rawDataIndex); + CutsceneMMCommand_FadeOutSeq(const std::vector& 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& 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& 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& 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& 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& 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& 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& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; diff --git a/tools/ZAPD/ZAPD/OtherStructs/CutsceneOoT_Commands.cpp b/tools/ZAPD/ZAPD/OtherStructs/CutsceneOoT_Commands.cpp new file mode 100644 index 00000000000..e38bfb6e5d5 --- /dev/null +++ b/tools/ZAPD/ZAPD/OtherStructs/CutsceneOoT_Commands.cpp @@ -0,0 +1,456 @@ +#include "CutsceneOoT_Commands.h" + +#include +#include +#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 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& 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& rawData, + offset_t rawDataIndex, + CutsceneOoT_CommandType cmdId) + : CutsceneCommand(rawData, rawDataIndex) +{ + rawDataIndex += 4; + + commandID = static_cast(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(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& 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& 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& 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& 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& 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& 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& 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(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& 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(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& 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& 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/tools/ZAPD/ZAPD/OtherStructs/CutsceneOoT_Commands.h b/tools/ZAPD/ZAPD/OtherStructs/CutsceneOoT_Commands.h new file mode 100644 index 00000000000..ff9b6797c3b --- /dev/null +++ b/tools/ZAPD/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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& 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& rawData, offset_t rawDataIndex); + + std::string GenerateSourceCode() const override; + size_t GetCommandSize() const override; +}; diff --git a/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.cpp b/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.cpp deleted file mode 100644 index 8ae4c69d7d1..00000000000 --- a/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.cpp +++ /dev/null @@ -1,596 +0,0 @@ -#include "Cutscene_Commands.h" - -#include -#include - -#include "CutsceneMM_Commands.h" -#include "Globals.h" -#include "Utils/BitConverter.h" -#include "Utils/StringHelper.h" - -/* CutsceneSubCommandEntry */ - -CutsceneSubCommandEntry::CutsceneSubCommandEntry(const std::vector& rawData, - offset_t rawDataIndex) -{ - base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); - startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); - endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); - pad = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); -} - -std::string CutsceneSubCommandEntry::GetBodySourceCode() const -{ - return StringHelper::Sprintf("CMD_HH(0x%04X, 0x%04X), CMD_HH(0x%04X, 0x%04X)", base, startFrame, - endFrame, pad); -} - -size_t CutsceneSubCommandEntry::GetRawSize() const -{ - return 0x08; -} - -/* CutsceneCommand */ - -CutsceneCommand::CutsceneCommand(const std::vector& rawData, offset_t rawDataIndex) -{ - numEntries = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); -} - -CutsceneCommand::~CutsceneCommand() -{ - for (auto& entry : entries) - { - delete entry; - } -} - -std::string CutsceneCommand::GetCommandMacro() const -{ - return StringHelper::Sprintf("CMD_W(0x%08X), CMD_W(0x%08X)", commandID, numEntries); -} - -std::string CutsceneCommand::GenerateSourceCode() const -{ - std::string result; - - result += GetCommandMacro(); - result += ",\n"; - - for (auto& entry : entries) - { - result += " "; - result += entry->GetBodySourceCode(); - result += ",\n"; - } - - return result; -} - -size_t CutsceneCommand::GetCommandSize() const -{ - size_t size = 0; - if (entries.size() > 0) - { - size = entries.at(0)->GetRawSize() * entries.size(); - } - else - { - size = 0x08 * numEntries; - } - return 0x08 + size; -} - -void CutsceneCommand::SetCommandID(uint32_t nCommandID) -{ - commandID = nCommandID; - - for (auto& entry : entries) - { - entry->commandID = commandID; - } -} - -// Specific for command lists where each entry has size 0x30 bytes -const std::unordered_map csCommandsDesc = { - {CutsceneCommands::Misc, - {"CS_MISC", "(0x%04X, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, - {CutsceneCommands::SetLighting, - {"CS_LIGHTING", "(0x%02X, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, - {CutsceneCommands::PlayBGM, {"CS_PLAY_BGM", "(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, - {CutsceneCommands::StopBGM, {"CS_STOP_BGM", "(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, - {CutsceneCommands::FadeBGM, {"CS_FADE_BGM", "(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i)"}}, -}; - -CutsceneSubCommandEntry_GenericCmd::CutsceneSubCommandEntry_GenericCmd( - const std::vector& rawData, offset_t rawDataIndex, CutsceneCommands cmdId) - : CutsceneSubCommandEntry(rawData, rawDataIndex), commandId(cmdId) -{ - word0 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0); - word1 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x4); - - unused1 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x8); - unused2 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0xC); - unused3 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x10); - unused4 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x14); - unused5 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x18); - unused6 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x1C); - unused7 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x20); - unused8 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x24); - unused9 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x28); - unused10 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x2C); -} - -std::string CutsceneSubCommandEntry_GenericCmd::GetBodySourceCode() const -{ - const auto& element = csCommandsDesc.find(commandId); - - if (element != csCommandsDesc.end()) - { - std::string entryFmt = element->second.cmdMacro; - entryFmt += element->second.args; - - return StringHelper::Sprintf(entryFmt.c_str(), base, startFrame, endFrame, pad, unused1, - unused2, unused3, unused4, unused5, unused6, unused7, unused8, - unused9, unused10); - } - - return StringHelper::Sprintf("CS_UNK_DATA(0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, " - "0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X, 0x%08X)", - word0, word1, unused1, unused2, unused3, unused4, unused5, unused6, - unused7, unused8, unused9, unused10); -} - -size_t CutsceneSubCommandEntry_GenericCmd::GetRawSize() const -{ - return 0x30; -} - -CutsceneCommand_GenericCmd::CutsceneCommand_GenericCmd(const std::vector& rawData, - offset_t rawDataIndex, - CutsceneCommands cmdId) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - commandID = static_cast(cmdId); - 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(commandID)); - - if (element != csCommandsDesc.end()) - { - return StringHelper::Sprintf("%s_LIST(%i)", element->second.cmdMacro, numEntries); - } - - return StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%X, %i)", commandID, numEntries); -} - -CutsceneCameraPoint::CutsceneCameraPoint(const std::vector& rawData, offset_t rawDataIndex) - : CutsceneSubCommandEntry(rawData, rawDataIndex) -{ - continueFlag = BitConverter::ToInt8BE(rawData, rawDataIndex + 0); - cameraRoll = BitConverter::ToInt8BE(rawData, rawDataIndex + 1); - nextPointFrame = BitConverter::ToInt16BE(rawData, rawDataIndex + 2); - viewAngle = BitConverter::ToFloatBE(rawData, rawDataIndex + 4); - - posX = BitConverter::ToInt16BE(rawData, rawDataIndex + 8); - posY = BitConverter::ToInt16BE(rawData, rawDataIndex + 10); - posZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 12); - - unused = BitConverter::ToInt16BE(rawData, rawDataIndex + 14); -} - -std::string CutsceneCameraPoint::GetBodySourceCode() const -{ - std::string result = ""; - - if (commandID == (int32_t)CutsceneCommands::SetCameraFocus) - { - result += "CS_CAM_FOCUS_POINT"; - } - else if (commandID == (int32_t)CutsceneCommands::SetCameraFocusLink) - { - result += "CS_CAM_FOCUS_POINT_PLAYER"; - } - else if (commandID == (int32_t)CutsceneCommands::SetCameraPosLink) - { - result += "CS_CAM_POS_PLAYER"; - } - else - { - result += "CS_CAM_POS"; - } - - std::string continueMacro = "CS_CMD_CONTINUE"; - if (continueFlag != 0) - continueMacro = "CS_CMD_STOP"; - - result += - StringHelper::Sprintf("(%s, 0x%02X, %i, %ff, %i, %i, %i, 0x%04X)", continueMacro.c_str(), - cameraRoll, nextPointFrame, viewAngle, posX, posY, posZ, unused); - return result; -} - -size_t CutsceneCameraPoint::GetRawSize() const -{ - return 0x10; -} - -CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const std::vector& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); - startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); - endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); - unused = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); - - bool shouldContinue = true; - - uint32_t currentPtr = rawDataIndex + 8; - - while (shouldContinue) - { - CutsceneCameraPoint* camPoint = new CutsceneCameraPoint(rawData, currentPtr); - entries.push_back(camPoint); - - if (camPoint->continueFlag == -1) - shouldContinue = false; - - currentPtr += camPoint->GetRawSize(); - } -} - -std::string CutsceneCommandSetCameraPos::GetCommandMacro() const -{ - std::string result; - - std::string listStr; - - if (commandID == (int32_t)CutsceneCommands::SetCameraFocus) - { - listStr = "CS_CAM_FOCUS_POINT_LIST"; - } - else if (commandID == (int32_t)CutsceneCommands::SetCameraFocusLink) - { - listStr = "CS_CAM_FOCUS_POINT_PLAYER_LIST"; - } - else if (commandID == (int32_t)CutsceneCommands::SetCameraPosLink) - { - listStr = "CS_CAM_POS_PLAYER_LIST"; - } - else - { - listStr = "CS_CAM_POS_LIST"; - } - - result += StringHelper::Sprintf("%s(%i, %i)", listStr.c_str(), startFrame, endFrame); - - return result; -} - -size_t CutsceneCommandSetCameraPos::GetCommandSize() const -{ - return 0x0C + entries.at(0)->GetRawSize() * entries.size(); -} - -CutsceneSubCommandEntry_Rumble::CutsceneSubCommandEntry_Rumble(const std::vector& rawData, - offset_t rawDataIndex) - : CutsceneSubCommandEntry(rawData, rawDataIndex) -{ - unk_06 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x06); - unk_07 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x07); - unk_08 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08); - unk_09 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x09); - unk_0A = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x0A); - unk_0B = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x0B); -} - -std::string CutsceneSubCommandEntry_Rumble::GetBodySourceCode() const -{ - if (Globals::Instance->game == ZGame::MM_RETAIL) - { - return StringHelper::Sprintf("CS_RUMBLE(%i, %i, %i, 0x%02X, 0x%02X, 0x%02X)", base, - startFrame, endFrame, unk_06, unk_07, unk_08); - } - - return StringHelper::Sprintf("CS_CMD_09(%i, %i, %i, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X)", - base, startFrame, endFrame, unk_06, unk_07, unk_08, unk_09, unk_0A, - unk_0B); -} - -size_t CutsceneSubCommandEntry_Rumble::GetRawSize() const -{ - return 0x0C; -} - -CutsceneCommand_Rumble::CutsceneCommand_Rumble(const std::vector& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - 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& rawData, offset_t rawDataIndex) - : CutsceneSubCommandEntry(rawData, rawDataIndex) -{ - hour = BitConverter::ToUInt8BE(rawData, rawDataIndex + 6); - minute = BitConverter::ToUInt8BE(rawData, rawDataIndex + 7); - unk_08 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); -} - -std::string CutsceneSubCommandEntry_SetTime::GetBodySourceCode() const -{ - return StringHelper::Sprintf("CS_TIME(%i, %i, %i, %i, %i, %i)", base, startFrame, endFrame, - hour, minute, unk_08); -} - -size_t CutsceneSubCommandEntry_SetTime::GetRawSize() const -{ - return 0x0C; -} - -CutsceneCommand_SetTime::CutsceneCommand_SetTime(const std::vector& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - 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& rawData, offset_t rawDataIndex) - : CutsceneSubCommandEntry(rawData, rawDataIndex) -{ - type = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x6); - textId1 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x8); - textId2 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0xA); -} - -std::string CutsceneSubCommandEntry_TextBox::GetBodySourceCode() const -{ - if (type == 0xFFFF) - { - return StringHelper::Sprintf("CS_TEXT_NONE(%i, %i)", startFrame, endFrame); - } - if (type == 2) - { - return StringHelper::Sprintf("CS_TEXT_LEARN_SONG(%i, %i, %i, 0x%X)", base, startFrame, - endFrame, textId1); - } - - if (Globals::Instance->game == ZGame::MM_RETAIL) - { - switch (type) - { - case 0: - return StringHelper::Sprintf("CS_TEXT_DEFAULT(0x%X, %i, %i, 0x%X, 0x%X)", base, - startFrame, endFrame, textId1, textId2); - - case 1: - return StringHelper::Sprintf("CS_TEXT_TYPE_1(0x%X, %i, %i, 0x%X, 0x%X)", base, - startFrame, endFrame, textId1, textId2); - - case 3: - return StringHelper::Sprintf("CS_TEXT_TYPE_3(0x%X, %i, %i, 0x%X, 0x%X)", base, - startFrame, endFrame, textId1, textId2); - - case 4: - return StringHelper::Sprintf("CS_TEXT_BOSSES_REMAINS(0x%X, %i, %i, 0x%X)", base, - startFrame, endFrame, textId1); - - case 5: - return StringHelper::Sprintf("CS_TEXT_ALL_NORMAL_MASKS(0x%X, %i, %i, 0x%X)", base, - startFrame, endFrame, textId1); - } - } - - return StringHelper::Sprintf("CS_TEXT_DISPLAY_TEXTBOX(0x%X, %i, %i, %i, 0x%X, 0x%X)", base, - startFrame, endFrame, type, textId1, textId2); -} - -size_t CutsceneSubCommandEntry_TextBox::GetRawSize() const -{ - return 0x0C; -} - -CutsceneCommand_TextBox::CutsceneCommand_TextBox(const std::vector& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - 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& rawData, offset_t rawDataIndex) - : CutsceneSubCommandEntry(rawData, rawDataIndex) -{ - rotX = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x6); - rotY = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x8); - rotZ = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0xA); - startPosX = BitConverter::ToInt32BE(rawData, rawDataIndex + 0xC); - startPosY = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x10); - startPosZ = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x14); - endPosX = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x18); - endPosY = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x1C); - endPosZ = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x20); - normalX = BitConverter::ToFloatBE(rawData, rawDataIndex + 0x24); - normalY = BitConverter::ToFloatBE(rawData, rawDataIndex + 0x28); - normalZ = BitConverter::ToFloatBE(rawData, rawDataIndex + 0x2C); -} - -std::string CutsceneSubCommandEntry_ActorAction::GetBodySourceCode() const -{ - std::string result; - - if (Globals::Instance->game == ZGame::MM_RETAIL) - { - if (static_cast(commandID) == - CutsceneMMCommands::CS_CMD_SET_PLAYER_ACTION) - { - result = "CS_PLAYER_ACTION"; - } - else - { - result = "CS_ACTOR_ACTION"; - } - } - else - { - if (static_cast(commandID) == CutsceneCommands::SetPlayerAction) - { - result = "CS_PLAYER_ACTION"; - } - else - { - result = "CS_NPC_ACTION"; - } - } - - result += - StringHelper::Sprintf("(%i, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, " - "%i, %i, %i, %i, %.11ef, %.11ef, %.11ef)", - base, startFrame, endFrame, rotX, rotY, rotZ, startPosX, startPosY, - startPosZ, endPosX, endPosY, endPosZ, normalX, normalY, normalZ); - return result; -} - -size_t CutsceneSubCommandEntry_ActorAction::GetRawSize() const -{ - return 0x30; -} - -CutsceneCommand_ActorAction::CutsceneCommand_ActorAction(const std::vector& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - 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(commandID) == - CutsceneMMCommands::CS_CMD_SET_PLAYER_ACTION) - { - return StringHelper::Sprintf("CS_PLAYER_ACTION_LIST(%i)", numEntries); - } - return StringHelper::Sprintf("CS_ACTOR_ACTION_LIST(0x%03X, %i)", commandID, numEntries); - } - - if (static_cast(commandID) == CutsceneCommands::SetPlayerAction) - { - return StringHelper::Sprintf("CS_PLAYER_ACTION_LIST(%i)", entries.size()); - } - return StringHelper::Sprintf("CS_NPC_ACTION_LIST(0x%03X, %i)", commandID, entries.size()); -} - -CutsceneCommand_Terminator::CutsceneCommand_Terminator(const std::vector& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); - startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); - endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); - unknown = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); // endFrame duplicate -} - -std::string CutsceneCommand_Terminator::GenerateSourceCode() const -{ - std::string result; - - result += StringHelper::Sprintf("CS_TERMINATOR(%i, %i, %i),\n", base, startFrame, endFrame); - - return result; -} - -size_t CutsceneCommand_Terminator::GetCommandSize() const -{ - return 0x10; -} - -CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const std::vector& rawData, - offset_t rawDataIndex) - : CutsceneCommand(rawData, rawDataIndex) -{ - rawDataIndex += 4; - - base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); - startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); - endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); -} - -std::string CutsceneCommandSceneTransFX::GenerateSourceCode() const -{ - return StringHelper::Sprintf("CS_SCENE_TRANS_FX(%i, %i, %i),\n", base, startFrame, endFrame); -} - -size_t CutsceneCommandSceneTransFX::GetCommandSize() const -{ - return 0x10; -} diff --git a/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.h b/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.h deleted file mode 100644 index c4627358739..00000000000 --- a/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Commands.h +++ /dev/null @@ -1,267 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "Declaration.h" - -enum class CutsceneCommands -{ - SetCameraPos = 0x0001, - SetCameraFocus = 0x0002, - Misc = 0x0003, - SetLighting = 0x0004, - SetCameraPosLink = 0x0005, - SetCameraFocusLink = 0x0006, - Cmd07 = 0x0007, - Cmd08 = 0x0008, - Cmd09 = 0x0009, // Rumble - Textbox = 0x0013, - SetPlayerAction = 0x000A, - SetActorAction1 = 0x000F, - SetActorAction2 = 0x000E, - SetActorAction3 = 0x0019, - SetActorAction4 = 0x001D, - SetActorAction5 = 0x001E, - SetActorAction6 = 0x002C, - SetActorAction7 = 0x001F, - SetActorAction8 = 0x0031, - SetActorAction9 = 0x003E, - SetActorAction10 = 0x008F, - SetSceneTransFX = 0x002D, - PlayBGM = 0x0056, - StopBGM = 0x0057, - FadeBGM = 0x007C, - SetTime = 0x008C, - Terminator = 0x03E8, -}; - -typedef struct CsCommandListDescriptor -{ - const char* cmdMacro; - const char* args; -} CsCommandListDescriptor; - -class CutsceneSubCommandEntry -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint16_t pad; - - uint32_t commandID; - - CutsceneSubCommandEntry(const std::vector& rawData, offset_t rawDataIndex); - virtual ~CutsceneSubCommandEntry() = default; - - virtual std::string GetBodySourceCode() const; - - virtual size_t GetRawSize() const; -}; - -class CutsceneCommand -{ -public: - uint32_t commandID; - uint32_t commandIndex; - - uint32_t numEntries; - std::vector entries; - - CutsceneCommand(const std::vector& rawData, offset_t rawDataIndex); - virtual ~CutsceneCommand(); - - virtual std::string GetCommandMacro() const; - virtual std::string GenerateSourceCode() const; - virtual size_t GetCommandSize() const; - - virtual void SetCommandID(uint32_t nCommandID); -}; - -class CutsceneSubCommandEntry_GenericCmd : public CutsceneSubCommandEntry -{ -public: - CutsceneCommands commandId; - - uint32_t word0 = 0; - uint32_t word1 = 0; - - uint32_t unused1 = 0; - uint32_t unused2 = 0; - uint32_t unused3 = 0; - uint32_t unused4 = 0; - uint32_t unused5 = 0; - uint32_t unused6 = 0; - uint32_t unused7 = 0; - uint32_t unused8 = 0; - uint32_t unused9 = 0; - uint32_t unused10 = 0; - - CutsceneSubCommandEntry_GenericCmd(const std::vector& rawData, offset_t rawDataIndex, - CutsceneCommands cmdId); - - std::string GetBodySourceCode() const override; - - size_t GetRawSize() const override; -}; - -class CutsceneCommand_GenericCmd : public CutsceneCommand -{ -public: - CutsceneCommand_GenericCmd(const std::vector& rawData, offset_t rawDataIndex, - CutsceneCommands cmdId); - - std::string GetCommandMacro() const override; -}; - -class CutsceneCameraPoint : public CutsceneSubCommandEntry -{ -public: - int8_t continueFlag; - int8_t cameraRoll; - int16_t nextPointFrame; - float viewAngle; - int16_t posX, posY, posZ; - int16_t unused; - - CutsceneCameraPoint(const std::vector& rawData, offset_t rawDataIndex); - - std::string GetBodySourceCode() const override; - - size_t GetRawSize() const override; -}; - -class CutsceneCommandSetCameraPos : public CutsceneCommand -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint16_t unused; - - CutsceneCommandSetCameraPos(const std::vector& rawData, offset_t rawDataIndex); - - std::string GetCommandMacro() const override; - - size_t GetCommandSize() const override; -}; - -class CutsceneCommandSceneTransFX : public CutsceneCommand -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - - CutsceneCommandSceneTransFX(const std::vector& rawData, offset_t rawDataIndex); - - std::string GenerateSourceCode() const override; - size_t GetCommandSize() const override; -}; - -class CutsceneSubCommandEntry_Rumble : public CutsceneSubCommandEntry -{ -public: - uint8_t unk_06; - uint8_t unk_07; - uint8_t unk_08; - uint8_t unk_09; - uint8_t unk_0A; - uint8_t unk_0B; - - CutsceneSubCommandEntry_Rumble(const std::vector& rawData, offset_t rawDataIndex); - - std::string GetBodySourceCode() const override; - - size_t GetRawSize() const override; -}; - -class CutsceneCommand_Rumble : public CutsceneCommand -{ -public: - CutsceneCommand_Rumble(const std::vector& rawData, offset_t rawDataIndex); - - std::string GetCommandMacro() const override; -}; - -class CutsceneSubCommandEntry_SetTime : public CutsceneSubCommandEntry -{ -public: - uint8_t hour; - uint8_t minute; - uint32_t unk_08; - - CutsceneSubCommandEntry_SetTime(const std::vector& rawData, offset_t rawDataIndex); - - std::string GetBodySourceCode() const override; - - size_t GetRawSize() const override; -}; - -class CutsceneCommand_SetTime : public CutsceneCommand -{ -public: - CutsceneCommand_SetTime(const std::vector& rawData, offset_t rawDataIndex); - - std::string GetCommandMacro() const override; -}; - -class CutsceneSubCommandEntry_TextBox : public CutsceneSubCommandEntry -{ -public: - uint16_t type; - uint16_t textId1; - uint16_t textId2; - - CutsceneSubCommandEntry_TextBox(const std::vector& rawData, offset_t rawDataIndex); - - std::string GetBodySourceCode() const override; - - size_t GetRawSize() const override; -}; - -class CutsceneCommand_TextBox : public CutsceneCommand -{ -public: - CutsceneCommand_TextBox(const std::vector& rawData, offset_t rawDataIndex); - - std::string GetCommandMacro() const override; -}; - -class CutsceneSubCommandEntry_ActorAction : public CutsceneSubCommandEntry -{ -public: - uint16_t rotX, rotY, rotZ; - int32_t startPosX, startPosY, startPosZ; - int32_t endPosX, endPosY, endPosZ; - float normalX, normalY, normalZ; - - CutsceneSubCommandEntry_ActorAction(const std::vector& rawData, offset_t rawDataIndex); - std::string GetBodySourceCode() const override; - - size_t GetRawSize() const override; -}; - -class CutsceneCommand_ActorAction : public CutsceneCommand -{ -public: - CutsceneCommand_ActorAction(const std::vector& rawData, offset_t rawDataIndex); - - std::string GetCommandMacro() const override; -}; - -class CutsceneCommand_Terminator : public CutsceneCommand -{ -public: - uint16_t base; - uint16_t startFrame; - uint16_t endFrame; - uint16_t unknown; - - CutsceneCommand_Terminator(const std::vector& rawData, offset_t rawDataIndex); - - std::string GenerateSourceCode() const override; - size_t GetCommandSize() const override; -}; diff --git a/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Common.cpp b/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Common.cpp new file mode 100644 index 00000000000..a5ea609af82 --- /dev/null +++ b/tools/ZAPD/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& rawData, + offset_t rawDataIndex) +{ + base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0); + startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2); + endFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 4); + pad = BitConverter::ToUInt16BE(rawData, rawDataIndex + 6); +} + +std::string CutsceneSubCommandEntry::GetBodySourceCode() const +{ + return StringHelper::Sprintf("CMD_HH(0x%04X, 0x%04X), CMD_HH(0x%04X, 0x%04X)", base, startFrame, + endFrame, pad); +} + +size_t CutsceneSubCommandEntry::GetRawSize() const +{ + return 0x08; +} + +/* CutsceneCommand */ + +CutsceneCommand::CutsceneCommand(const std::vector& rawData, offset_t rawDataIndex) +{ + numEntries = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0); +} + +CutsceneCommand::~CutsceneCommand() +{ + for (auto entry : entries) + { + delete entry; + } +} + +std::string CutsceneCommand::GetCommandMacro() const +{ + return StringHelper::Sprintf("CMD_W(0x%08X), CMD_W(0x%08X)", commandID, numEntries); +} + +std::string CutsceneCommand::GenerateSourceCode() const +{ + std::string result; + + result += GetCommandMacro(); + result += ",\n"; + + for (auto& entry : entries) + { + result += " "; + result += entry->GetBodySourceCode(); + result += ",\n"; + } + + return result; +} + +size_t CutsceneCommand::GetCommandSize() const +{ + size_t size = 0; + if (entries.size() > 0) + { + size = entries.at(0)->GetRawSize() * entries.size(); + } + else + { + size = 0x08 * numEntries; + } + return 0x08 + size; +} + +void CutsceneCommand::SetCommandID(uint32_t nCommandID) +{ + commandID = nCommandID; + + for (auto& entry : entries) + { + entry->commandID = commandID; + } +} + +/*** TIME ****/ + +CutsceneSubCommandEntry_SetTime::CutsceneSubCommandEntry_SetTime( + const std::vector& rawData, offset_t rawDataIndex) + : CutsceneSubCommandEntry(rawData, rawDataIndex) +{ + hour = BitConverter::ToUInt8BE(rawData, rawDataIndex + 6); + minute = BitConverter::ToUInt8BE(rawData, rawDataIndex + 7); +} + +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& 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/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Common.h b/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Common.h new file mode 100644 index 00000000000..9d8dcf63de7 --- /dev/null +++ b/tools/ZAPD/ZAPD/OtherStructs/Cutscene_Common.h @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include +#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& rawData, offset_t rawDataIndex); + virtual ~CutsceneSubCommandEntry() = default; + + virtual std::string GetBodySourceCode() const; + + virtual size_t GetRawSize() const; +}; + +class CutsceneCommand +{ +public: + uint32_t commandID; + uint32_t commandIndex; + + uint32_t numEntries; + std::vector entries; + + CutsceneCommand(const std::vector& rawData, offset_t rawDataIndex); + virtual ~CutsceneCommand(); + + virtual std::string GetCommandMacro() const; + virtual std::string GenerateSourceCode() const; + virtual size_t GetCommandSize() const; + + virtual void SetCommandID(uint32_t nCommandID); +}; + +/**** TIME ****/ + +class CutsceneSubCommandEntry_SetTime : public CutsceneSubCommandEntry +{ +public: + uint8_t hour; + uint8_t minute; + + CutsceneSubCommandEntry_SetTime(const std::vector& 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& rawData, offset_t rawDataIndex); + + std::string GetCommandMacro() const override; +}; diff --git a/tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.cpp b/tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.cpp index df8bd6d98b3..e85bdefe769 100644 --- a/tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.cpp +++ b/tools/ZAPD/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,73 +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); - Globals::Instance->GetSegmentedPtrName(unk_C, parent, "Struct_800A598C_2", unk_C_Str); + Globals::Instance->GetSegmentedPtrName(skinVertices, parent, "SkinVertex", skinVertices_Str); + Globals::Instance->GetSegmentedPtrName(limbTransformations, parent, "SkinTransformation", + unk_C_Str); 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 != "") @@ -269,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()); @@ -287,63 +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); - ZDisplayList* 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); - Globals::Instance->GetSegmentedPtrName(unk_8, parent, "Gfx", unk_8_Str); + std::string limbModifications_Str; + std::string dlist_Str; + Globals::Instance->GetSegmentedPtrName(limbModifications, parent, "SkinLimbModif", + limbModifications_Str); + Globals::Instance->GetSegmentedPtrName(dlist, parent, "Gfx", dlist_Str); 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/tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.h b/tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.h index 33edd07cae0..5181bc5d85f 100644 --- a/tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.h +++ b/tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.h @@ -6,19 +6,17 @@ #include "ZResource.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; @@ -30,19 +28,19 @@ class Struct_800A57C0 : public ZResource size_t GetRawDataSize() const override; protected: - 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; @@ -54,17 +52,17 @@ class Struct_800A598C_2 : public ZResource size_t GetRawDataSize() const override; protected: - 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; @@ -77,20 +75,20 @@ class Struct_800A598C : public ZResource size_t GetRawDataSize() const override; protected: - 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 unk_8_arr; - std::vector 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 skinVertices_arr; + std::vector 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; @@ -103,11 +101,11 @@ class Struct_800A5E28 : public ZResource size_t GetRawDataSize() const override; protected: - 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 unk_4_arr; + std::vector limbModifications_arr; // ZDisplayList* unk_8_dlist = nullptr; }; diff --git a/tools/ZAPD/ZAPD/OutputFormatter.h b/tools/ZAPD/ZAPD/OutputFormatter.h index 28955b1cd10..ec56b654daa 100644 --- a/tools/ZAPD/ZAPD/OutputFormatter.h +++ b/tools/ZAPD/ZAPD/OutputFormatter.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include diff --git a/tools/ZAPD/ZAPD/WarningHandler.cpp b/tools/ZAPD/ZAPD/WarningHandler.cpp index 163b028b541..f416a5b80c4 100644 --- a/tools/ZAPD/ZAPD/WarningHandler.cpp +++ b/tools/ZAPD/ZAPD/WarningHandler.cpp @@ -84,26 +84,27 @@ typedef struct */ // clang-format off static const std::unordered_map 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(-1)) { + fprintf(stderr, "offset 0x%06X:", offset); + } + fprintf(stderr, "\n\t"); } /** diff --git a/tools/ZAPD/ZAPD/WarningHandler.h b/tools/ZAPD/ZAPD/WarningHandler.h index bb0360a813a..f99330042b8 100644 --- a/tools/ZAPD/ZAPD/WarningHandler.h +++ b/tools/ZAPD/ZAPD/WarningHandler.h @@ -81,6 +81,7 @@ enum class WarningType InvalidExtractedData, MissingSegment, HardcodedPointer, + HardcodedGenericPointer, NotImplemented, Max, }; diff --git a/tools/ZAPD/ZAPD/ZAPD.vcxproj b/tools/ZAPD/ZAPD/ZAPD.vcxproj index 505e411005a..77d0bd16eb5 100644 --- a/tools/ZAPD/ZAPD/ZAPD.vcxproj +++ b/tools/ZAPD/ZAPD/ZAPD.vcxproj @@ -249,6 +249,7 @@ mkdir build\ZAPD + @@ -272,6 +273,7 @@ mkdir build\ZAPD + @@ -339,6 +341,7 @@ mkdir build\ZAPD + diff --git a/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters b/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters index ce89882fedd..eac471961c7 100644 --- a/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters +++ b/tools/ZAPD/ZAPD/ZAPD.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -291,6 +291,12 @@ Source Files\Z64 + + Source Files\Z64 + + + Source Files\Z64 + @@ -554,6 +560,15 @@ Header Files\Z64 + + Header Files + + + Header Files + + + Header Files + diff --git a/tools/ZAPD/ZAPD/ZAnimation.cpp b/tools/ZAPD/ZAPD/ZAnimation.cpp index 74b520b501e..959fff82919 100644 --- a/tools/ZAPD/ZAPD/ZAnimation.cpp +++ b/tools/ZAPD/ZAPD/ZAnimation.cpp @@ -153,7 +153,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() @@ -174,8 +177,8 @@ std::string ZLinkAnimation::GetBodySourceCode() const /* ZCurveAnimation */ -TransformData::TransformData(ZFile* parent, const std::vector& rawData, - uint32_t fileOffset) +CurveInterpKnot::CurveInterpKnot(ZFile* parent, const std::vector& rawData, + uint32_t fileOffset) : parent(parent) { unk_00 = BitConverter::ToUInt16BE(rawData, fileOffset + 0); @@ -185,26 +188,26 @@ TransformData::TransformData(ZFile* parent, const std::vector& rawData, unk_08 = BitConverter::ToFloatBE(rawData, fileOffset + 8); } -TransformData::TransformData(ZFile* parent, const std::vector& rawData, - uint32_t fileOffset, size_t index) - : TransformData(parent, rawData, fileOffset + index * GetRawDataSize()) +CurveInterpKnot::CurveInterpKnot(ZFile* parent, const std::vector& 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) @@ -300,7 +303,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix) } else { - decl->text = entryStr; + decl->declBody = entryStr; } } @@ -331,7 +334,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix) } else { - decl->text = entryStr; + decl->declBody = entryStr; } } @@ -359,7 +362,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix) } else { - decl->text = entryStr; + decl->declBody = entryStr; } } } @@ -369,7 +372,7 @@ std::string ZCurveAnimation::GetBodySourceCode() const std::string refIndexStr; Globals::Instance->GetSegmentedPtrName(refIndex, parent, "u8", refIndexStr); std::string transformDataStr; - Globals::Instance->GetSegmentedPtrName(transformData, parent, "TransformData", + Globals::Instance->GetSegmentedPtrName(transformData, parent, "CurveInterpKnot", transformDataStr); std::string copyValuesStr; Globals::Instance->GetSegmentedPtrName(copyValues, parent, "s16", copyValuesStr); @@ -390,7 +393,7 @@ DeclarationAlignment ZCurveAnimation::GetDeclarationAlignment() const std::string ZCurveAnimation::GetSourceTypeName() const { - return "TransformUpdateIndex"; + return "CurveAnimationHeader"; } /* ZLegacyAnimation */ @@ -423,7 +426,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); @@ -495,7 +498,7 @@ std::string ZLegacyAnimation::GetBodySourceCode() const std::string frameDataName; std::string jointKeyName; Globals::Instance->GetSegmentedPtrName(frameData, parent, "s16", frameDataName); - Globals::Instance->GetSegmentedPtrName(jointKey, parent, "JointKey", jointKeyName); + Globals::Instance->GetSegmentedPtrName(jointKey, parent, "LegacyJointKey", jointKeyName); body += StringHelper::Sprintf("\t%i, %i,\n", frameCount, limbCount); body += StringHelper::Sprintf("\t%s,\n", frameDataName.c_str()); @@ -514,11 +517,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(); @@ -531,23 +534,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/tools/ZAPD/ZAPD/ZAnimation.h b/tools/ZAPD/ZAPD/ZAnimation.h index 2c04b4ff81d..643842b891a 100644 --- a/tools/ZAPD/ZAPD/ZAnimation.h +++ b/tools/ZAPD/ZAPD/ZAnimation.h @@ -67,7 +67,7 @@ class ZLinkAnimation : public ZAnimation void ParseRawData() override; }; -class TransformData +class CurveInterpKnot { protected: ZFile* parent; @@ -84,10 +84,10 @@ class TransformData float unk_08; public: - TransformData() = default; - TransformData(ZFile* parent, const std::vector& rawData, uint32_t fileOffset); - TransformData(ZFile* parent, const std::vector& rawData, uint32_t fileOffset, - size_t index); + CurveInterpKnot() = default; + CurveInterpKnot(ZFile* parent, const std::vector& rawData, uint32_t fileOffset); + CurveInterpKnot(ZFile* parent, const std::vector& rawData, uint32_t fileOffset, + size_t index); [[nodiscard]] std::string GetBody(const std::string& prefix) const; @@ -102,7 +102,7 @@ class ZCurveAnimation : public ZAnimation ///* 0x0000 */ u8* refIndex; segptr_t refIndex = 0; - ///* 0x0004 */ TransformData* transformData; + ///* 0x0004 */ CurveInterpKnot* transformData; segptr_t transformData = 0; ///* 0x0008 */ s16* copyValues; segptr_t copyValues = 0; @@ -114,7 +114,7 @@ class ZCurveAnimation : public ZAnimation uint8_t limbCount = 0; std::vector refIndexArr; - std::vector transformDataArr; + std::vector transformDataArr; std::vector copyValuesArr; public: @@ -132,14 +132,14 @@ class ZCurveAnimation : public ZAnimation 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; @@ -172,8 +172,8 @@ class ZLegacyAnimation : public ZAnimation protected: int16_t limbCount; segptr_t frameData; // s16* - segptr_t jointKey; // JointKey* + segptr_t jointKey; // LegacyJointKey* std::vector frameDataArray; - std::vector jointKeyArray; + std::vector jointKeyArray; }; diff --git a/tools/ZAPD/ZAPD/ZArray.cpp b/tools/ZAPD/ZAPD/ZArray.cpp index 0a9797ba095..62720bc6108 100644 --- a/tools/ZAPD/ZAPD/ZArray.cpp +++ b/tools/ZAPD/ZAPD/ZArray.cpp @@ -56,7 +56,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); @@ -75,11 +75,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 @@ -109,6 +109,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/tools/ZAPD/ZAPD/ZBackground.cpp b/tools/ZAPD/ZAPD/ZBackground.cpp index 0ed1eb7471f..fc725637e7a 100644 --- a/tools/ZAPD/ZAPD/ZBackground.cpp +++ b/tools/ZAPD/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/tools/ZAPD/ZAPD/ZCollision.cpp b/tools/ZAPD/ZAPD/ZCollision.cpp index 5bd3d93a69e..d177e036cbb 100644 --- a/tools/ZAPD/ZAPD/ZCollision.cpp +++ b/tools/ZAPD/ZAPD/ZCollision.cpp @@ -1,4 +1,5 @@ #include "ZCollision.h" +#include "ZWaterbox.h" #include #include @@ -50,6 +51,7 @@ void ZCollisionHeader::ParseRawData() vertices.reserve(numVerts); polygons.reserve(numPolygons); + waterBoxes.reserve(numWaterBoxes); offset_t currentPtr = vtxSegmentOffset; @@ -97,38 +99,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) @@ -149,9 +168,11 @@ void ZCollisionHeader::DeclareReferences(const std::string& prefix) declaration += "\n"; } - 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) @@ -219,23 +240,38 @@ std::string ZCollisionHeader::GetBodySourceCode() const std::string vtxName; Globals::Instance->GetSegmentedPtrName(vtxAddress, parent, "Vec3s", vtxName); - declaration += StringHelper::Sprintf("\t%i, %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); - declaration += StringHelper::Sprintf("\t%i, %s,\n", numPolygons, polyName.c_str()); + + 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); declaration += StringHelper::Sprintf("\t%s,\n", surfaceName.c_str()); std::string camName; - Globals::Instance->GetSegmentedPtrName(camDataAddress, parent, "CamData", camName); + Globals::Instance->GetSegmentedPtrName(camDataAddress, parent, "BgCamInfo", camName); declaration += StringHelper::Sprintf("\t%s,\n", camName.c_str()); std::string waterBoxName; Globals::Instance->GetSegmentedPtrName(waterBoxAddress, parent, "WaterBox", waterBoxName); - declaration += StringHelper::Sprintf("\t%i, %s\n", numWaterBoxes, waterBoxName.c_str()); + + 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; } @@ -260,26 +296,6 @@ size_t ZCollisionHeader::GetRawDataSize() const return 44; } -WaterBoxHeader::WaterBoxHeader(const std::vector& rawData, uint32_t rawDataIndex) -{ - 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); -} - -std::string WaterBoxHeader::GetBodySourceCode() const -{ - return StringHelper::Sprintf("%i, %i, %i, %i, %i, 0x%08X", xMin, ySurface, zMin, xLength, - zLength, properties); -} - CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const std::vector& rawData, offset_t rawDataIndex, offset_t upperCameraBoundary) @@ -291,73 +307,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()), @@ -367,11 +403,6 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, CameraDataList::~CameraDataList() { - for (auto entry : entries) - delete entry; - - for (auto camPosData : cameraPositionData) - delete camPosData; } CameraPositionData::CameraPositionData(const std::vector& rawData, uint32_t rawDataIndex) diff --git a/tools/ZAPD/ZAPD/ZCollision.h b/tools/ZAPD/ZAPD/ZCollision.h index 35c632144c7..8c73d2eaa1e 100644 --- a/tools/ZAPD/ZAPD/ZCollision.h +++ b/tools/ZAPD/ZAPD/ZCollision.h @@ -6,23 +6,7 @@ #include "ZRoom/ZRoom.h" #include "ZSurfaceType.h" #include "ZVector.h" - -class WaterBoxHeader -{ -public: - WaterBoxHeader(const std::vector& rawData, uint32_t rawDataIndex); - - std::string GetBodySourceCode() const; - -protected: - int16_t xMin; - int16_t ySurface; - int16_t zMin; - int16_t xLength; - int16_t zLength; - int16_t pad; - int32_t properties; -}; +#include "ZWaterbox.h" class CameraPositionData { @@ -37,14 +21,14 @@ class CameraDataEntry public: int16_t cameraSType; int16_t numData; - int32_t cameraPosDataSeg; + offset_t cameraPosDataSeg; }; class CameraDataList { public: - std::vector entries; - std::vector cameraPositionData; + std::vector entries; + std::vector cameraPositionData; CameraDataList(ZFile* parent, const std::string& prefix, const std::vector& rawData, offset_t rawDataIndex, offset_t upperCameraBoundary); @@ -72,7 +56,7 @@ class ZCollisionHeader : public ZResource std::vector vertices; std::vector polygons; std::vector polygonTypes; - std::vector waterBoxes; + std::vector waterBoxes; CameraDataList* camData = nullptr; ZCollisionHeader(ZFile* nParent); diff --git a/tools/ZAPD/ZAPD/ZCutscene.cpp b/tools/ZAPD/ZAPD/ZCutscene.cpp index a3bfe0e07d4..ea723b2953e 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.cpp +++ b/tools/ZAPD/ZAPD/ZCutscene.cpp @@ -3,7 +3,6 @@ #include #include "Globals.h" -#include "OtherStructs/CutsceneMM_Commands.h" #include "Utils/BitConverter.h" #include "Utils/StringHelper.h" #include "WarningHandler.h" @@ -129,174 +128,147 @@ void ZCutscene::ParseRawData() CutsceneCommand* ZCutscene::GetCommandOoT(uint32_t id, offset_t currentPtr) const { - CutsceneCommands cmdID = static_cast(id); + CutsceneOoT_CommandType cmdID = static_cast(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; @@ -304,60 +276,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(id); + CutsceneMM_CommandType cmdID = static_cast(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/tools/ZAPD/ZAPD/ZCutscene.h b/tools/ZAPD/ZAPD/ZCutscene.h index 098f3ad868d..5b54426cead 100644 --- a/tools/ZAPD/ZAPD/ZCutscene.h +++ b/tools/ZAPD/ZAPD/ZCutscene.h @@ -5,7 +5,8 @@ #include #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/tools/ZAPD/ZAPD/ZDisplayList.cpp b/tools/ZAPD/ZAPD/ZDisplayList.cpp index 3b50c1fd307..98c4d0e4a4e 100644 --- a/tools/ZAPD/ZAPD/ZDisplayList.cpp +++ b/tools/ZAPD/ZAPD/ZDisplayList.cpp @@ -40,7 +40,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); @@ -708,7 +708,7 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, const std::string& prefix, char* l if (!Globals::Instance->HasSegment(segNum)) 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)); @@ -718,7 +718,7 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, const std::string& prefix, char* l if (!Globals::Instance->HasSegment(segNum)) 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)); @@ -958,7 +958,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)) sprintf(texStr, "%sTex_%06X", prefix.c_str(), texAddress); else @@ -1642,7 +1642,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; } } @@ -1708,17 +1715,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); + bool addressFound = + Globals::Instance->GetSegmentedPtrName(seg, self->parent, "Gfx", dListName, false); - 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()); @@ -1731,21 +1747,31 @@ static int32_t GfxdCallback_Matrix(uint32_t seg) std::string mtxName; ZDisplayList* self = static_cast(gfxd_udata_get()); - bool addressFound = Globals::Instance->GetSegmentedPtrName(seg, self->parent, "Mtx", mtxName); - if (!addressFound && GETSEGNUM(seg) == self->parent->segment) + bool addressFound = + Globals::Instance->GetSegmentedPtrName(seg, self->parent, "Mtx", mtxName, false); + + if (!addressFound) { - Declaration* decl = - self->parent->GetDeclaration(Seg2Filespace(seg, self->parent->baseAddress)); - if (decl == nullptr) + if (GETSEGNUM(seg) == self->parent->segment) { - 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(); + 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()); } } @@ -1870,7 +1896,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.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()); @@ -1954,9 +1981,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>> vertexKeys(vertices.begin(), + vertices.end()); + std::pair> lastItem = vertexKeys.at(0); + + for (size_t i = 1; i < vertexKeys.size(); i++) + { + std::pair> 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/tools/ZAPD/ZAPD/ZDisplayList.h b/tools/ZAPD/ZAPD/ZDisplayList.h index 96808315dc9..356e89a2be5 100644 --- a/tools/ZAPD/ZAPD/ZDisplayList.h +++ b/tools/ZAPD/ZAPD/ZDisplayList.h @@ -346,7 +346,7 @@ class ZDisplayList : public ZResource 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; @@ -367,6 +367,9 @@ class ZDisplayList : public ZResource 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/tools/ZAPD/ZAPD/ZFile.cpp b/tools/ZAPD/ZAPD/ZFile.cpp index 09776505d6c..0b2a4d631c9 100644 --- a/tools/ZAPD/ZAPD/ZFile.cpp +++ b/tools/ZAPD/ZAPD/ZFile.cpp @@ -181,6 +181,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) { if (!File::Exists((basePath / name).string())) @@ -213,14 +219,12 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename) // Check for repeated attributes. if (offsetXml != nullptr) { - std::string offsetStr = StringHelper::Split(offsetXml, "0x")[1]; - if (!StringHelper::HasOnlyHexDigits(offsetStr)) + if (!StringHelper::IsValidOffset(std::string_view(offsetXml))) { HANDLE_ERROR(WarningType::InvalidXML, - StringHelper::Sprintf("Invalid offset %s entered", offsetStr.c_str()), - ""); + StringHelper::Sprintf("Invalid offset %s entered", offsetXml), ""); } - rawDataIndex = strtol(offsetStr.c_str(), NULL, 16); + rawDataIndex = strtol(offsetXml, NULL, 16); if (offsetSet.find(offsetXml) != offsetSet.end()) { @@ -268,7 +272,7 @@ void ZFile::ParseXML(tinyxml2::XMLElement* reader, const std::string& filename) ZResource* nRes = nodeMap[nodeName](this); if (mode == ZFileMode::Extract || mode == ZFileMode::ExternalFile) - nRes->ExtractFromXML(child, rawDataIndex); + nRes->ExtractWithXML(child, rawDataIndex); switch (nRes->GetResourceType()) { @@ -442,24 +446,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; } @@ -468,27 +473,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; @@ -499,41 +506,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 @@ -546,22 +553,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; } @@ -570,7 +577,43 @@ 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; + + 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); + + decl->isArray = true; + decl->arrayItemCnt = arrayItemCnt; + + declarations[address] = decl; + } + else + { + decl->includePath = includePath; + decl->declType = varType; + decl->declName = varName; + decl->size = size; + decl->isArray = true; + decl->arrayItemCnt = arrayItemCnt; + } + return decl; +} + +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; @@ -582,7 +625,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, defines); decl->isArray = true; decl->arrayItemCnt = arrayItemCnt; @@ -592,8 +635,9 @@ 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->defines = defines; decl->size = size; decl->isArray = true; decl->arrayItemCnt = arrayItemCnt; @@ -601,7 +645,7 @@ Declaration* ZFile::AddDeclarationIncludeArray(offset_t address, std::string& in return decl; } -bool ZFile::AddDeclarationChecks(uint32_t address, const std::string& varName) +bool ZFile::DeclarationSanityChecks(uint32_t address, const std::string& varName) { assert(GETSEGNUM(address) == 0); assert(varName != ""); @@ -645,7 +689,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; @@ -653,9 +697,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; } @@ -679,7 +723,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; @@ -688,7 +732,7 @@ bool ZFile::GetDeclarationArrayIndexedName(segptr_t segAddress, size_t elementSi if (decl->address == address) { - declName = decl->varName; + declName = decl->declName; return true; } @@ -699,7 +743,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; } @@ -728,6 +772,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; @@ -817,8 +875,8 @@ void ZFile::GenerateSourceHeaderFiles() std::string ZFile::GetHeaderInclude() const { - std::string headers = StringHelper::Sprintf("#include \"%s.h\"\n", - (outName.parent_path() / outName.stem()).c_str()); + std::string headers = StringHelper::Sprintf( + "#include \"%s.h\"\n", (outName.parent_path() / outName.stem()).string().c_str()); return headers; } @@ -843,16 +901,12 @@ 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.c_str()); + StringHelper::Sprintf("#include \"%s.h\"\n", outputFolderPath.string().c_str()); } } @@ -967,46 +1021,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> declarationKeys(declarations.begin(), - declarations.end()); - - std::pair lastItem = declarationKeys.at(0); - - for (size_t i = 1; i < declarationKeys.size(); i++) - { - std::pair 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; - declarations.erase(curItem.first); - declarationKeys.erase(declarationKeys.begin() + i); - delete curItem.second; - i--; - continue; - } - } - } - } - } - - lastItem = curItem; - } + MergeNeighboringDeclarations(); for (std::pair item : declarations) ProcessDeclarationText(item.second); @@ -1041,20 +1056,20 @@ 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; File::WriteAllText( - StringHelper::Sprintf("%s.%s.inc", filepath.c_str(), extType.c_str()), - item.second->text); + StringHelper::Sprintf("%s.%s.inc", filepath.string().c_str(), extType.c_str()), + item.second->declBody); } output += item.second->GetExternalDeclarationStr(); } - else if (item.second->varType != "") + else if (item.second->declType != "") { output += item.second->GetNormalDeclarationStr(); } @@ -1063,6 +1078,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> declarationKeys(declarations.begin(), + declarations.end()); + + std::pair lastItem = declarationKeys.at(0); + + for (size_t i = 1; i < declarationKeys.size(); i++) + { + std::pair 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; @@ -1070,17 +1129,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); - decl->text.replace(i, 2, vtxName); + decl->declBody.replace(i, 2, vtxName); refIndex++; @@ -1092,7 +1151,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) { @@ -1101,10 +1161,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; @@ -1153,7 +1224,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; defines += StringHelper::Sprintf("#define %s ((u32)%s + 0x%06X)\n", texNextName.c_str(), texName.c_str(), offsetDiff); @@ -1226,8 +1297,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/tools/ZAPD/ZAPD/ZFile.h b/tools/ZAPD/ZAPD/ZFile.h index e4980eb68d6..65b1cc4aa38 100644 --- a/tools/ZAPD/ZAPD/ZFile.h +++ b/tools/ZAPD/ZAPD/ZFile.h @@ -38,6 +38,8 @@ class ZFile 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, @@ -74,6 +76,9 @@ class ZFile 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; @@ -84,6 +89,7 @@ class ZFile 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; @@ -126,8 +132,9 @@ class ZFile 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/tools/ZAPD/ZAPD/ZLimb.cpp b/tools/ZAPD/ZAPD/ZLimb.cpp index 034d0850bb7..b3acb940c1e 100644 --- a/tools/ZAPD/ZAPD/ZLimb.cpp +++ b/tools/ZAPD/ZAPD/ZLimb.cpp @@ -106,7 +106,7 @@ void ZLimb::ParseRawData() skinSegmentType = static_cast(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; @@ -394,7 +394,7 @@ void ZLimb::DeclareDList(segptr_t dListSegmentedPtr, const std::string& prefix, std::string dlistName; bool declFound = Globals::Instance->GetSegmentedArrayIndexedName(dListSegmentedPtr, 8, parent, - "Gfx", dlistName); + "Gfx", dlistName, false); if (declFound) return; diff --git a/tools/ZAPD/ZAPD/ZLimb.h b/tools/ZAPD/ZAPD/ZLimb.h index ce31e429589..52919bed921 100644 --- a/tools/ZAPD/ZAPD/ZLimb.h +++ b/tools/ZAPD/ZAPD/ZLimb.h @@ -28,9 +28,9 @@ class ZLimb : public ZResource ZLimbType type = ZLimbType::Standard; - ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only - segptr_t skinSegment = 0; // Skin only - Struct_800A5E28 segmentStruct; // Skin only + ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_Null; // Skin only + segptr_t skinSegment = 0; // Skin only + SkinAnimatedLimbData segmentStruct; // Skin only // Legacy only float legTransX, legTransY, legTransZ; // Vec3f diff --git a/tools/ZAPD/ZAPD/ZPath.cpp b/tools/ZAPD/ZAPD/ZPath.cpp index 0dac87a1b12..cb8295679f9 100644 --- a/tools/ZAPD/ZAPD/ZPath.cpp +++ b/tools/ZAPD/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) { @@ -144,8 +145,8 @@ void PathwayEntry::DeclareReferences(const std::string& prefix) return; std::string pointsName; - bool addressFound = - Globals::Instance->GetSegmentedPtrName(listSegmentAddress, parent, "Vec3s", pointsName); + bool addressFound = Globals::Instance->GetSegmentedPtrName(listSegmentAddress, parent, "Vec3s", + pointsName, false); if (addressFound) return; @@ -172,7 +173,7 @@ void PathwayEntry::DeclareReferences(const std::string& prefix) points.size(), declaration); } else - decl->text = declaration; + decl->declBody = declaration; } std::string PathwayEntry::GetBodySourceCode() const @@ -185,7 +186,13 @@ std::string PathwayEntry::GetBodySourceCode() const 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/tools/ZAPD/ZAPD/ZPlayerAnimationData.cpp b/tools/ZAPD/ZAPD/ZPlayerAnimationData.cpp index a96604fda06..ce5425d7e17 100644 --- a/tools/ZAPD/ZAPD/ZPlayerAnimationData.cpp +++ b/tools/ZAPD/ZAPD/ZPlayerAnimationData.cpp @@ -32,7 +32,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)); } } @@ -55,14 +55,21 @@ std::string ZPlayerAnimationData::GetBodySourceCode() const std::string declaration = ""; 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/tools/ZAPD/ZAPD/ZPlayerAnimationData.h b/tools/ZAPD/ZAPD/ZPlayerAnimationData.h index 20835f23694..2923117efc7 100644 --- a/tools/ZAPD/ZAPD/ZPlayerAnimationData.h +++ b/tools/ZAPD/ZAPD/ZPlayerAnimationData.h @@ -9,7 +9,7 @@ class ZPlayerAnimationData : public ZResource { public: int16_t frameCount = 0; - std::vector limbRotData; + std::vector limbRotData; ZPlayerAnimationData(ZFile* nParent); diff --git a/tools/ZAPD/ZAPD/ZResource.cpp b/tools/ZAPD/ZAPD/ZResource.cpp index 8825cc97bd5..d991c465395 100644 --- a/tools/ZAPD/ZAPD/ZResource.cpp +++ b/tools/ZAPD/ZAPD/ZResource.cpp @@ -24,7 +24,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; @@ -274,7 +274,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; decl->staticConf = staticConf; } diff --git a/tools/ZAPD/ZAPD/ZResource.h b/tools/ZAPD/ZAPD/ZResource.h index f97b259c6ce..97540139848 100644 --- a/tools/ZAPD/ZAPD/ZResource.h +++ b/tools/ZAPD/ZAPD/ZResource.h @@ -54,6 +54,7 @@ enum class ZResourceType TextureAnimationParams, Vector, Vertex, + Waterbox, }; class ResourceAttribute @@ -79,8 +80,18 @@ class ZResource ZResource(ZFile* nParent); virtual ~ZResource() = default; - // Parsing from File - virtual void ExtractFromXML(tinyxml2::XMLElement* reader, offset_t nRawDataIndex); + /// + /// Extracts/Parsees data from binary file using an XML to provide the needed metadata. + /// + /// XML Node we wish to parse from. + /// The offset within the binary file we are going to parse from as + /// indicated by the "Offset" parameter in the XML. + virtual void ExtractWithXML(tinyxml2::XMLElement* reader, offset_t nRawDataIndex); + + /// + /// Extracts/Parses the needed data straight from a binary without the use of an XML. + /// + /// The offset within the binary file we wish to parse from. virtual void ExtractFromFile(offset_t nRawDataIndex); // Misc diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp index 1687b546200..e64b855374a 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetAlternateHeaders.cpp +++ b/tools/ZAPD/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/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp index ae2d31c81e4..e30e1b682df 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCameraSettings.cpp +++ b/tools/ZAPD/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/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.cpp index ada1a1038f1..302d638d4c2 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.cpp +++ b/tools/ZAPD/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,7 +105,7 @@ void SetCsCamera::DeclareReferences(const std::string& prefix) std::string SetCsCamera::GetBodySourceCode() const { std::string listName; - Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CsCameraEntry", listName); + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "ActorCsCamInfo", listName); return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_CAM_LIST(%i, %s)", cameras.size(), listName.c_str()); } @@ -120,7 +120,7 @@ RoomCommand SetCsCamera::GetRoomCommand() const return RoomCommand::SetCsCamera; } -CsCameraEntry::CsCameraEntry(const std::vector& rawData, uint32_t rawDataIndex) +ActorCsCamInfo::ActorCsCamInfo(const std::vector& rawData, uint32_t rawDataIndex) : baseOffset(rawDataIndex), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), numPoints(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)) { @@ -128,27 +128,27 @@ CsCameraEntry::CsCameraEntry(const std::vector& 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/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.h index 5e0e3c82578..2ce64e4e05c 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCsCamera.h +++ b/tools/ZAPD/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& rawData, uint32_t rawDataIndex); + ActorCsCamInfo(const std::vector& rawData, uint32_t rawDataIndex); std::string GetSourceTypeName() const; int32_t GetRawDataSize() const; @@ -25,7 +25,7 @@ class CsCameraEntry class SetCsCamera : public ZRoomCommand { public: - std::vector cameras; + std::vector cameras; std::vector points; SetCsCamera(ZFile* nParent); diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutsceneEntryList.cpp similarity index 53% rename from tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp rename to tools/ZAPD/ZAPD/ZRoom/Commands/SetCutsceneEntryList.cpp index 15f2c6b4517..96c50c3be2e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.cpp +++ b/tools/ZAPD/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,7 +55,7 @@ void SetActorCutsceneList::DeclareReferences(const std::string& prefix) std::string SetActorCutsceneList::GetBodySourceCode() const { std::string listName; - Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "ActorCutscene", listName); + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneEntry", listName); return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_LIST(%i, %s)", cutscenes.size(), listName.c_str()); } @@ -70,25 +70,34 @@ RoomCommand SetActorCutsceneList::GetRoomCommand() const return RoomCommand::SetActorCutsceneList; } -ActorCutsceneEntry::ActorCutsceneEntry(const std::vector& rawData, uint32_t rawDataIndex) +CutsceneEntry::CutsceneEntry(const std::vector& rawData, uint32_t rawDataIndex) : priority(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)), length(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)), - unk4(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), - unk6(BitConverter::ToInt16BE(rawData, rawDataIndex + 6)), - additionalCutscene(BitConverter::ToInt16BE(rawData, rawDataIndex + 8)), - sound(rawData[rawDataIndex + 0xA]), unkB(rawData[rawDataIndex + 0xB]), - unkC(BitConverter::ToInt16BE(rawData, rawDataIndex + 0xC)), unkE(rawData[rawDataIndex + 0xE]), - letterboxSize(rawData[rawDataIndex + 0xF]) + 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/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutsceneEntryList.h similarity index 66% rename from tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.h rename to tools/ZAPD/ZAPD/ZRoom/Commands/SetCutsceneEntryList.h index 8fd48e425c6..6ba6c23abc7 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetActorCutsceneList.h +++ b/tools/ZAPD/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& rawData, uint32_t rawDataIndex); + CutsceneEntry(const std::vector& rawData, uint32_t rawDataIndex); std::string GetBodySourceCode() const; std::string GetSourceTypeName() const; @@ -26,7 +26,7 @@ class ActorCutsceneEntry class SetActorCutsceneList : public ZRoomCommand { public: - std::vector cutscenes; + std::vector cutscenes; SetActorCutsceneList(ZFile* nParent); diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp index 51df68ca1a9..d2a1c19561e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.cpp @@ -23,7 +23,7 @@ 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; } @@ -32,6 +32,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; @@ -62,10 +63,14 @@ void SetCutscenes::DeclareReferences(const std::string& prefix) Globals::Instance->GetSegmentedPtrName(entry.segmentPtr, parent, "CutsceneData", csName); - declaration += - StringHelper::Sprintf(" { %s, 0x%04X, 0x%02X, 0x%02X },", csName.c_str(), - entry.exit, entry.entrance, entry.flag); - + if (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"; @@ -73,8 +78,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); } @@ -102,8 +107,8 @@ std::string SetCutscenes::GetBodySourceCode() const if (Globals::Instance->game == ZGame::MM_RETAIL) { - Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneEntry", listName); - return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_LIST(%i, %s)", numCutscenes, + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneScriptEntry", listName); + return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_SCRIPT_LIST(%i, %s)", numCutscenes, listName.c_str()); } @@ -121,7 +126,7 @@ RoomCommand SetCutscenes::GetRoomCommand() const return RoomCommand::SetCutscenes; } -CutsceneEntry::CutsceneEntry(const std::vector& rawData, uint32_t rawDataIndex) +CutsceneScriptEntry::CutsceneScriptEntry(const std::vector& 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/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h index 81a622c5b32..e6d979d0f61 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetCutscenes.h +++ b/tools/ZAPD/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& rawData, uint32_t rawDataIndex); + CutsceneScriptEntry(const std::vector& rawData, uint32_t rawDataIndex); segptr_t segmentPtr; uint16_t exit; @@ -17,8 +17,8 @@ class CutsceneEntry class SetCutscenes : public ZRoomCommand { public: - std::vector cutsceneEntries; // (MM Only) - uint8_t numCutscenes; // (MM Only) + std::vector cutsceneEntries; // (MM Only) + uint8_t numCutscenes; // (MM Only) SetCutscenes(ZFile* nParent); diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp index c92f56c4eec..3ffba0ff129 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.cpp +++ b/tools/ZAPD/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,16 +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); + if (Globals::Instance->game != ZGame::MM_RETAIL) + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "Spawn", listName); + else + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "EntranceEntry", listName); return StringHelper::Sprintf("SCENE_CMD_ENTRANCE_LIST(%s)", listName.c_str()); } @@ -78,13 +87,13 @@ RoomCommand SetEntranceList::GetRoomCommand() const return RoomCommand::SetEntranceList; } -EntranceEntry::EntranceEntry(const std::vector& rawData, uint32_t rawDataIndex) +Spawn::Spawn(const std::vector& 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/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.h index e13e9a8ce67..832232e06ba 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetEntranceList.h +++ b/tools/ZAPD/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& rawData, uint32_t rawDataIndex); + Spawn(const std::vector& rawData, uint32_t rawDataIndex); std::string GetBodySourceCode() const; }; @@ -16,7 +16,7 @@ class EntranceEntry class SetEntranceList : public ZRoomCommand { public: - std::vector entrances; + std::vector entrances; SetEntranceList(ZFile* nParent); diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp index 80ccc6b0572..78bbaa87ede 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetExitList.cpp +++ b/tools/ZAPD/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/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp index ba5785cfcb3..eaf01cd4c4c 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetLightingSettings.cpp @@ -34,18 +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); + if (Globals::Instance->game != ZGame::MM_RETAIL) + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "EnvLightSettings", listName); + else + Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "LightSettings", listName); return StringHelper::Sprintf("SCENE_CMD_ENV_LIGHT_SETTINGS(%i, %s)", settings.size(), listName.c_str()); } diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp index 89c8c8c88e6..9a4d30d5164 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.cpp @@ -24,7 +24,7 @@ void SetMesh::ParseRawData() switch (meshHeaderType) { case 0: - polyType = std::make_shared(parent, segmentOffset, zRoom); + polyType = std::make_shared(parent, segmentOffset, zRoom); break; case 1: @@ -32,7 +32,7 @@ void SetMesh::ParseRawData() break; case 2: - polyType = std::make_shared(parent, segmentOffset, zRoom); + polyType = std::make_shared(parent, segmentOffset, zRoom); break; default: @@ -79,7 +79,7 @@ std::string SetMesh::GetBodySourceCode() const { std::string list; Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "", list); - 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); + Globals::Instance->GetSegmentedPtrName(list, parent, "RoomShapeImageMultiBgEntry", listStr); 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,7 +594,7 @@ 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); @@ -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/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h index 9d9037417bf..c0f15da9d38 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMesh.h +++ b/tools/ZAPD/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 @@ class PolygonDlist : public ZResource 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 @@ class PolygonDlist : public ZResource 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 @@ class BgImage : public ZResource 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 polyDLists; + std::vector polyDLists; PolygonTypeBase(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom); @@ -100,12 +101,12 @@ class PolygonType1 : public PolygonTypeBase segptr_t dlist; // single - BgImage single; + RoomShapeImageMultiBgEntry single; // multi uint8_t count; - segptr_t list; // BgImage* - std::vector multiList; + segptr_t list; // RoomShapeImageMultiBgEntry* + std::vector multiList; PolygonType1(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom); @@ -119,14 +120,14 @@ class PolygonType1 : public PolygonTypeBase 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/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.cpp index 370afdf0c1b..a5aac2a543e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.cpp +++ b/tools/ZAPD/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; @@ -54,7 +54,7 @@ void SetMinimapList::DeclareReferences(const std::string& prefix) { std::string listName; Globals::Instance->GetSegmentedPtrName(listSegmentAddr, parent, "MinimapEntry", listName); - std::string declaration = StringHelper::Sprintf("\n\t%s, 0x%08X\n", listName.c_str(), unk4); + std::string declaration = StringHelper::Sprintf("\n\t%s, %d\n", listName.c_str(), scale); parent->AddDeclaration( segmentOffset, DeclarationAlignment::Align4, 8, "MinimapList", diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.h b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.h index 5b18b3dd78d..fcf7ad7a6f4 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.h +++ b/tools/ZAPD/ZAPD/ZRoom/Commands/SetMinimapList.h @@ -35,5 +35,5 @@ class SetMinimapList : public ZRoomCommand private: segptr_t listSegmentAddr; uint32_t listSegmentOffset; - uint32_t unk4; + int16_t scale; }; diff --git a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp index 52d400a848c..967d10b8d5b 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetPathways.cpp +++ b/tools/ZAPD/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/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp index 696a3de0145..34edf5ae633 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetSpecialObjects.cpp +++ b/tools/ZAPD/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/tools/ZAPD/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp b/tools/ZAPD/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp index d20e4a3e29a..fa28547e62e 100644 --- a/tools/ZAPD/ZAPD/ZRoom/Commands/SetWorldMapVisited.cpp +++ b/tools/ZAPD/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/tools/ZAPD/ZAPD/ZRoom/ZNames.h b/tools/ZAPD/ZAPD/ZRoom/ZNames.h index 667407c3631..83c217e9993 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZNames.h +++ b/tools/ZAPD/ZAPD/ZRoom/ZNames.h @@ -48,11 +48,12 @@ class ZNames 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 @@ class ZNames 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/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp b/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp index 5831eaa56b2..a291c36feb2 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoom.cpp @@ -6,7 +6,7 @@ #include #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/tools/ZAPD/ZAPD/ZRoom/ZRoom.h b/tools/ZAPD/ZAPD/ZRoom/ZRoom.h index e837ec70ac5..950dbbb182a 100644 --- a/tools/ZAPD/ZAPD/ZRoom/ZRoom.h +++ b/tools/ZAPD/ZAPD/ZRoom/ZRoom.h @@ -22,7 +22,7 @@ class ZRoom : public ZResource 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 @@ class ZRoom : public ZResource 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 @@ class ZRoom : public ZResource ZResourceType GetResourceType() const override; protected: - void SyotesRoomHack(); + void SyotesRoomFix(); }; diff --git a/tools/ZAPD/ZAPD/ZSkeleton.cpp b/tools/ZAPD/ZAPD/ZSkeleton.cpp index ca680c5f5e4..86b578639f8 100644 --- a/tools/ZAPD/ZAPD/ZSkeleton.cpp +++ b/tools/ZAPD/ZAPD/ZSkeleton.cpp @@ -189,7 +189,7 @@ std::string ZSkeleton::GetSourceTypeName() const case ZSkeletonType::Flex: return "FlexSkeletonHeader"; case ZSkeletonType::Curve: - return "SkelCurveLimbList"; + return "CurveSkeletonHeader"; } return "SkeletonHeader"; diff --git a/tools/ZAPD/ZAPD/ZTexture.cpp b/tools/ZAPD/ZAPD/ZTexture.cpp index 74b7c7d106a..0ecda1a8cea 100644 --- a/tools/ZAPD/ZAPD/ZTexture.cpp +++ b/tools/ZAPD/ZAPD/ZTexture.cpp @@ -137,31 +137,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, @@ -212,10 +212,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++) @@ -227,15 +227,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++) @@ -251,10 +252,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) @@ -269,16 +270,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++) @@ -290,10 +291,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) @@ -308,8 +309,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); } @@ -317,27 +319,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++) @@ -351,10 +358,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) @@ -375,10 +382,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++) @@ -428,31 +435,31 @@ void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath) 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", ""); @@ -460,7 +467,7 @@ void ZTexture::PrepareRawDataFromFile(const fs::path& pngFilePath) } } -void ZTexture::PrepareRawDataRGBA16() +void ZTexture::ConvertBitmapToN64_RGBA16() { for (uint16_t y = 0; y < height; y++) { @@ -469,13 +476,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); @@ -483,7 +490,7 @@ void ZTexture::PrepareRawDataRGBA16() } } -void ZTexture::PrepareRawDataRGBA32() +void ZTexture::ConvertBitmapToN64_RGBA32() { for (uint16_t y = 0; y < height; y++) { @@ -500,7 +507,7 @@ void ZTexture::PrepareRawDataRGBA32() } } -void ZTexture::PrepareRawDataGrayscale4() +void ZTexture::ConvertBitmapToN64_Grayscale4() { for (uint16_t y = 0; y < height; y++) { @@ -515,7 +522,7 @@ void ZTexture::PrepareRawDataGrayscale4() } } -void ZTexture::PrepareRawDataGrayscale8() +void ZTexture::ConvertBitmapToN64_Grayscale8() { for (uint16_t y = 0; y < height; y++) { @@ -528,7 +535,7 @@ void ZTexture::PrepareRawDataGrayscale8() } } -void ZTexture::PrepareRawDataGrayscaleAlpha4() +void ZTexture::ConvertBitmapToN64_GrayscaleAlpha4() { for (uint16_t y = 0; y < height; y++) { @@ -544,9 +551,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; @@ -554,7 +561,7 @@ void ZTexture::PrepareRawDataGrayscaleAlpha4() } } -void ZTexture::PrepareRawDataGrayscaleAlpha8() +void ZTexture::ConvertBitmapToN64_GrayscaleAlpha8() { for (uint16_t y = 0; y < height; y++) { @@ -563,15 +570,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++) { @@ -589,7 +596,7 @@ void ZTexture::PrepareRawDataGrayscaleAlpha16() } } -void ZTexture::PrepareRawDataPalette4() +void ZTexture::ConvertBitmapToN64_Palette4() { for (uint16_t y = 0; y < height; y++) { @@ -605,7 +612,7 @@ void ZTexture::PrepareRawDataPalette4() } } -void ZTexture::PrepareRawDataPalette8() +void ZTexture::ConvertBitmapToN64_Palette8() { for (uint16_t y = 0; y < height; y++) { @@ -770,10 +777,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()) @@ -785,18 +792,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; } @@ -827,6 +847,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; @@ -844,7 +875,7 @@ std::string ZTexture::GetSourceTypeName() const void ZTexture::CalcHash() { - auto parentRawData = parent->GetRawData(); + const auto& parentRawData = parent->GetRawData(); hash = CRC32B(parentRawData.data() + rawDataIndex, GetRawDataSize()); } diff --git a/tools/ZAPD/ZAPD/ZTexture.h b/tools/ZAPD/ZAPD/ZTexture.h index 8cece3ff24b..1461ff95a69 100644 --- a/tools/ZAPD/ZAPD/ZTexture.h +++ b/tools/ZAPD/ZAPD/ZTexture.h @@ -30,26 +30,28 @@ class ZTexture : public ZResource 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 @@ class ZTexture : public ZResource Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override; std::string GetBodySourceCode() const override; + + /// + /// Calculates the hash of this texture, for use with the texture pool. + /// 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 @@ class ZTexture : public ZResource uint32_t GetWidth() const; uint32_t GetHeight() const; void SetDimensions(uint32_t nWidth, uint32_t nHeight); + + /// + /// Returns how many bytes each pixel takes up. + /// + /// float GetPixelMultiplyer() const; + TextureType GetTextureType() const; + + /// + /// Returns the path to the texture pool, taken from the config file. + /// + /// + /// fs::path GetPoolOutPath(const fs::path& defaultValue); + + /// + /// Returns if this texture uses a palette. + /// + /// bool IsColorIndexed() const; + void SetTlut(ZTexture* nTlut); bool HasTlut() const; void ParseRawDataLate() override; diff --git a/tools/ZAPD/ZAPD/ZTextureAnimation.cpp b/tools/ZAPD/ZAPD/ZTextureAnimation.cpp index 698054fa87f..0c55b26097a 100644 --- a/tools/ZAPD/ZAPD/ZTextureAnimation.cpp +++ b/tools/ZAPD/ZAPD/ZTextureAnimation.cpp @@ -569,6 +569,7 @@ void ZTextureAnimation::DeclareReferences(const std::string& prefix) count = 2; } params = new TextureScrollingParams(parent); + params->type = entry.type; params->ExtractFromBinary(paramsOffset, count); break; @@ -582,6 +583,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/tools/ZAPD/ZAPD/ZWaterbox.cpp b/tools/ZAPD/ZAPD/ZWaterbox.cpp new file mode 100644 index 00000000000..9a289db5235 --- /dev/null +++ b/tools/ZAPD/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/tools/ZAPD/ZAPD/ZWaterbox.h b/tools/ZAPD/ZAPD/ZWaterbox.h new file mode 100644 index 00000000000..e190b26a08e --- /dev/null +++ b/tools/ZAPD/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/tools/ZAPD/ZAPD/genbuildinfo.py b/tools/ZAPD/ZAPD/genbuildinfo.py index 91a567d3177..3317c427629 100644 --- a/tools/ZAPD/ZAPD/genbuildinfo.py +++ b/tools/ZAPD/ZAPD/genbuildinfo.py @@ -10,7 +10,13 @@ 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" diff --git a/tools/ZAPD/ZAPDUtils/Makefile b/tools/ZAPD/ZAPDUtils/Makefile index e8941ed773a..c0f818bdff0 100644 --- a/tools/ZAPD/ZAPDUtils/Makefile +++ b/tools/ZAPD/ZAPDUtils/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/tools/ZAPD/ZAPDUtils/Utils/BitConverter.h b/tools/ZAPD/ZAPDUtils/Utils/BitConverter.h index 646fa1274c4..aa41b5b217a 100644 --- a/tools/ZAPD/ZAPDUtils/Utils/BitConverter.h +++ b/tools/ZAPD/ZAPDUtils/Utils/BitConverter.h @@ -76,7 +76,7 @@ class BitConverter fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); } return ((uint32_t)data.at(offset + 0) << 24) + ((uint32_t)data.at(offset + 1) << 16) + - ((uint32_t)data.at(offset + 2) << 8) + (uint32_t)data.at(offset + 3); + ((uint32_t)data.at(offset + 2) << 8) + (uint32_t)data.at(offset + 3); } static inline uint32_t ToUInt32BE(const std::vector& data, size_t offset) @@ -89,7 +89,7 @@ class BitConverter fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); } return ((uint32_t)data.at(offset + 0) << 24) + ((uint32_t)data.at(offset + 1) << 16) + - ((uint32_t)data.at(offset + 2) << 8) + (uint32_t)data.at(offset + 3); + ((uint32_t)data.at(offset + 2) << 8) + (uint32_t)data.at(offset + 3); } static inline int64_t ToInt64BE(const std::vector& data, size_t offset) @@ -102,9 +102,9 @@ class BitConverter fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); } return ((uint64_t)data.at(offset + 0) << 56) + ((uint64_t)data.at(offset + 1) << 48) + - ((uint64_t)data.at(offset + 2) << 40) + ((uint64_t)data.at(offset + 3) << 32) + - ((uint64_t)data.at(offset + 4) << 24) + ((uint64_t)data.at(offset + 5) << 16) + - ((uint64_t)data.at(offset + 6) << 8) + ((uint64_t)data.at(offset + 7)); + ((uint64_t)data.at(offset + 2) << 40) + ((uint64_t)data.at(offset + 3) << 32) + + ((uint64_t)data.at(offset + 4) << 24) + ((uint64_t)data.at(offset + 5) << 16) + + ((uint64_t)data.at(offset + 6) << 8) + ((uint64_t)data.at(offset + 7)); } static inline uint64_t ToUInt64BE(const std::vector& data, size_t offset) @@ -117,9 +117,9 @@ class BitConverter fprintf(stderr, "\t Trying to read at offset: 0x%zX\n", offset); } return ((uint64_t)data.at(offset + 0) << 56) + ((uint64_t)data.at(offset + 1) << 48) + - ((uint64_t)data.at(offset + 2) << 40) + ((uint64_t)data.at(offset + 3) << 32) + - ((uint64_t)data.at(offset + 4) << 24) + ((uint64_t)data.at(offset + 5) << 16) + - ((uint64_t)data.at(offset + 6) << 8) + ((uint64_t)data.at(offset + 7)); + ((uint64_t)data.at(offset + 2) << 40) + ((uint64_t)data.at(offset + 3) << 32) + + ((uint64_t)data.at(offset + 4) << 24) + ((uint64_t)data.at(offset + 5) << 16) + + ((uint64_t)data.at(offset + 6) << 8) + ((uint64_t)data.at(offset + 7)); } static inline float ToFloatBE(const std::vector& data, size_t offset) @@ -133,8 +133,8 @@ class BitConverter } float value; uint32_t floatData = ((uint32_t)data.at(offset + 0) << 24) + - ((uint32_t)data.at(offset + 1) << 16) + - ((uint32_t)data.at(offset + 2) << 8) + (uint32_t)data.at(offset + 3); + ((uint32_t)data.at(offset + 1) << 16) + + ((uint32_t)data.at(offset + 2) << 8) + (uint32_t)data.at(offset + 3); static_assert(sizeof(uint32_t) == sizeof(float), "expected 32-bit float"); std::memcpy(&value, &floatData, sizeof(value)); return value; diff --git a/tools/ZAPD/ZAPDUtils/Utils/Directory.h b/tools/ZAPD/ZAPDUtils/Utils/Directory.h index eaa6a26abb6..d150f17727c 100644 --- a/tools/ZAPD/ZAPDUtils/Utils/Directory.h +++ b/tools/ZAPD/ZAPDUtils/Utils/Directory.h @@ -4,7 +4,10 @@ #include #include -#if __has_include() +#ifdef USE_BOOST_FS +#include +namespace fs = boost::filesystem; +#elif __has_include() #include namespace fs = std::filesystem; #else @@ -17,9 +20,22 @@ namespace fs = std::experimental::filesystem; class Directory { public: - static std::string GetCurrentDirectory() { return fs::current_path().u8string(); } +#ifdef USE_BOOST_FS + static std::string GetCurrentDirectory() + { + return fs::current_path().string(); + } +#else + static std::string GetCurrentDirectory() + { + return fs::current_path().u8string(); + } +#endif - static bool Exists(const fs::path& path) { return fs::exists(path); } + static bool Exists(const fs::path& path) + { + return fs::exists(path); + } static void CreateDirectory(const std::string& path) { diff --git a/tools/ZAPD/ZAPDUtils/Utils/File.h b/tools/ZAPD/ZAPDUtils/Utils/File.h index 7bc5d2950f9..707b1600fcb 100644 --- a/tools/ZAPD/ZAPDUtils/Utils/File.h +++ b/tools/ZAPD/ZAPDUtils/Utils/File.h @@ -1,8 +1,11 @@ #pragma once -#include +#ifdef USE_BOOST_FS +#include +#else #include -#include +#endif + #include #include #include "Directory.h" @@ -10,29 +13,38 @@ class File { +#ifdef USE_BOOST_FS + typedef fs::ifstream ifstream; + typedef fs::ofstream ofstream; +#else + typedef std::ifstream ifstream; + typedef std::ofstream ofstream; +#endif + public: static bool Exists(const fs::path& filePath) { - std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate); + ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate); return file.good(); } static std::vector ReadAllBytes(const fs::path& filePath) { - std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate); + ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate); int32_t fileSize = (int32_t)file.tellg(); file.seekg(0); char* data = new char[fileSize]; file.read(data, fileSize); std::vector result = std::vector(data, data + fileSize); delete[] data; + file.close(); return result; }; static std::string ReadAllText(const fs::path& filePath) { - std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate); + ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate); if (!file.is_open()) return ""; int32_t fileSize = (int32_t)file.tellg(); @@ -42,6 +54,7 @@ class File file.read(data, fileSize); std::string str = std::string((const char*)data); delete[] data; + file.close(); return str; }; @@ -56,25 +69,29 @@ class File static void WriteAllBytes(const fs::path& filePath, const std::vector& data) { - std::ofstream file(filePath, std::ios::binary); + ofstream file(filePath, std::ios::binary); file.write((char*)data.data(), data.size()); + file.close(); }; static void WriteAllBytes(const std::string& filePath, const std::vector& data) { - std::ofstream file(filePath, std::ios::binary); + ofstream file(filePath, std::ios::binary); file.write((char*)data.data(), data.size()); + file.close(); }; static void WriteAllBytes(const std::string& filePath, const char* data, int dataSize) { - std::ofstream file(filePath, std::ios::binary); + ofstream file(filePath, std::ios::binary); file.write((char*)data, dataSize); + file.close(); }; static void WriteAllText(const fs::path& filePath, const std::string& text) { - std::ofstream file(filePath, std::ios::out); + ofstream file(filePath, std::ios::out); file.write(text.c_str(), text.size()); + file.close(); } }; diff --git a/tools/ZAPD/ZAPDUtils/Utils/Path.h b/tools/ZAPD/ZAPDUtils/Utils/Path.h index 0f7ef274310..90f55380b4b 100644 --- a/tools/ZAPD/ZAPDUtils/Utils/Path.h +++ b/tools/ZAPD/ZAPDUtils/Utils/Path.h @@ -4,7 +4,10 @@ #include #include "Utils/StringHelper.h" -#if __has_include() +#ifdef USE_BOOST_FS +#include +namespace fs = boost::filesystem; +#elif __has_include() #include namespace fs = std::filesystem; #else diff --git a/tools/ZAPD/ZAPDUtils/Utils/StringHelper.h b/tools/ZAPD/ZAPDUtils/Utils/StringHelper.h index 8560d6b0942..c4e012eb067 100644 --- a/tools/ZAPD/ZAPDUtils/Utils/StringHelper.h +++ b/tools/ZAPD/ZAPDUtils/Utils/StringHelper.h @@ -106,9 +106,35 @@ class StringHelper return std::all_of(str.begin(), str.end(), ::isdigit); } - static bool HasOnlyHexDigits(const std::string& str) + static bool IsValidHex(std::string_view str) { - return std::all_of(str.begin(), str.end(), ::isxdigit); + if (str.length() < 3) + { + return false; + } + + if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X')) + { + return std::all_of(str.begin() + 2, str.end(), ::isxdigit); + } + + return false; + } + + static bool IsValidOffset(std::string_view str) + { + if (str.length() == 1) + { + // 0 is a valid offset + return isdigit(str[0]); + } + + return IsValidHex(str); + } + + static bool IsValidHex(const std::string& str) + { + return IsValidHex(std::string_view(str.c_str())); } static std::string ToUpper(const std::string& str) @@ -123,4 +149,66 @@ class StringHelper return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](char a, char b) { return tolower(a) == tolower(b); }); } + + /** + * Converts a std::string formatted in camelCase into one in SCREAMING_SNAKE_CASE. Since this + * will mostly be used on symbols that start with either 'g' or 's', an option is included to + * skip these. + */ + static std::string camelCaseTo_SCREAMING_SNAKE_CASE(const std::string& in, bool skipSP) + { + std::string out = ""; + const char* ptr = in.c_str(); + char ch = *ptr; + + // Switch checks for 'g'/'s'/'\0', looks at next character if skipSP enabled and string is + // nonempty. + switch (ch) + { + case 'g': + case 's': + if (skipSP) + { + // Print it anyway if the next character is lowercase, e.g. "gameplay_keep_...". + if (!isupper(ptr[1])) + { + out.push_back(toupper(ch)); + } + if ((ch = *++ptr) == '\0') + { + case '\0': + // This is reached either by the if or the case label, avoiding duplication. + return out; + } + } + [[fallthrough]]; + default: + if (islower(ch)) + { + out.push_back(toupper(ch)); + } + else + { + out.push_back(ch); + } + break; + } + + while ((ch = *++ptr) != '\0') + { + if (islower(ch)) + { + out.push_back(toupper(ch)); + } + else + { + if (isupper(ch) && !(isupper(ptr[1]) && isupper(ptr[-1]))) + { + out.push_back('_'); + } + out.push_back(ch); + } + } + return out; + } }; diff --git a/tools/ZAPD/ZAPDUtils/ZAPDUtils.vcxproj b/tools/ZAPD/ZAPDUtils/ZAPDUtils.vcxproj index 4b91c2aeb63..2abbdc96644 100644 --- a/tools/ZAPD/ZAPDUtils/ZAPDUtils.vcxproj +++ b/tools/ZAPD/ZAPDUtils/ZAPDUtils.vcxproj @@ -118,6 +118,7 @@ true MultiThreadedDebug Default + stdcpp17 Console diff --git a/tools/ZAPDConfigs/MqDbg/Config.xml b/tools/ZAPDConfigs/MqDbg/Config.xml index 5e88889ef12..f9660f90b20 100644 --- a/tools/ZAPDConfigs/MqDbg/Config.xml +++ b/tools/ZAPDConfigs/MqDbg/Config.xml @@ -4,5 +4,6 @@ + diff --git a/tools/ZAPDConfigs/MqDbg/EnumData.xml b/tools/ZAPDConfigs/MqDbg/EnumData.xml new file mode 100644 index 00000000000..53e5f9aeac8 --- /dev/null +++ b/tools/ZAPDConfigs/MqDbg/EnumData.xml @@ -0,0 +1,416 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +