diff --git a/Dockerfile b/Dockerfile
index 8d979fc8fa..47ebeca8d4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,15 +12,10 @@ RUN apt-get update && \
unzip \
clang-tidy \
clang-format \
+ clang-format-11 \
nano \
- vbindiff
-
-RUN wget \
- https://github.com/n64decomp/qemu-irix/releases/download/v2.11-deb/qemu-irix-2.11.0-2169-g32ab296eef_amd64.deb \
- -O qemu.deb && \
- echo 8170f37cf03a08cc2d7c1c58f10d650ea0d158f711f6916da9364f6d8c85f741 qemu.deb | sha256sum --check && \
- dpkg -i qemu.deb && \
- rm qemu.deb
+ vbindiff \
+ libpng-dev
RUN python3 -m pip install --user colorama ansiwrap attrs watchdog python-Levenshtein
RUN python3 -m pip install --upgrade attrs pycparser
diff --git a/README.md b/README.md
index de131dbf42..70bc646016 100644
--- a/README.md
+++ b/README.md
@@ -55,12 +55,13 @@ For macOS, use homebrew to install the following dependencies:
* make
* python3
* md5sha1sum
+* libpng
You can install them with the following commands:
```bash
brew update
-brew install coreutils make python3 md5sha1sum
+brew install coreutils make python3 md5sha1sum libpng
```
You'll also need to [build and install mips-linux-binutils](docs/BUILDING_BINUTILS_MACOS.md).
@@ -80,12 +81,13 @@ The build process has the following package requirements:
* build-essential
* binutils-mips-linux-gnu
* python3
+* libpng-dev
Under Debian / Ubuntu (which we recommend using), you can install them with the following commands:
```bash
sudo apt-get update
-sudo apt-get install git build-essential binutils-mips-linux-gnu python3
+sudo apt-get install git build-essential binutils-mips-linux-gnu python3 libpng-dev
```
#### 2. Clone the repository
@@ -142,7 +144,6 @@ This means that the built ROM isn't the same as the base one, so something went
Both of these have the disadvantage that the ordering of the terminal output is scrambled, so for debugging it is best to stick to one thread (i.e. not pass `-j` or `-jN`).
-
### Cygwin
If you want to use Cygwin, you will need to:
@@ -156,6 +157,7 @@ Once mips-linux-binutils is installed you will need to install the following pac
* libiconv
* dos2unix
* python3
+* libpng-devel
Then you can continue from step [step 2](#2-clone-the-repository) of the Linux instructions.
diff --git a/assets/.gitignore b/assets/.gitignore
index 1c09040d40..7e53529fcc 100644
--- a/assets/.gitignore
+++ b/assets/.gitignore
@@ -3,4 +3,4 @@
*.h
*.cfg
*.vtx.inc
-*.dlist.inc
\ No newline at end of file
+*.dlist.inc
diff --git a/assets/xml/scenes/test_levels/syotes.xml b/assets/xml/scenes/test_levels/syotes.xml
index 0d0b2340ca..3a7b594d1a 100644
--- a/assets/xml/scenes/test_levels/syotes.xml
+++ b/assets/xml/scenes/test_levels/syotes.xml
@@ -3,6 +3,6 @@
-
+
diff --git a/extract_assets.py b/extract_assets.py
index add331f57d..5c2d378889 100755
--- a/extract_assets.py
+++ b/extract_assets.py
@@ -14,18 +14,12 @@ def SignalHandler(sig, frame):
mainAbort.set()
# Don't exit immediately to update the extracted assets file.
-def Extract(xmlPath, outputPath, outputSourcePath):
- ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 0)
-
-def ExtractScene(xmlPath, outputPath, outputSourcePath):
- ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 1)
-
-def ExtractFile(xmlPath, outputPath, outputSourcePath, genSrcFile, incFilePrefix):
+def ExtractFile(xmlPath, outputPath, outputSourcePath):
if globalAbort.is_set():
# Don't extract if another file wasn't extracted properly.
return
- execStr = "tools/ZAPD/ZAPD.out e -eh -i %s -b baserom/ -o %s -osf %s -gsf %i -ifp %i -rconf tools/ZAPDConfigs/MqDbg/Config.xml" % (xmlPath, outputPath, outputSourcePath, genSrcFile, incFilePrefix)
+ execStr = "tools/ZAPD/ZAPD.out e -eh -i %s -b baserom/ -o %s -osf %s -gsf 1 -rconf tools/ZAPDConfigs/MqDbg/Config.xml" % (xmlPath, outputPath, outputSourcePath)
if globalUnaccounted:
execStr += " -wu"
@@ -45,10 +39,6 @@ def ExtractFunc(fullPath):
outPath = os.path.join("assets", *pathList[2:], objectName)
outSourcePath = outPath
- isScene = fullPath.startswith("assets/xml/scenes/")
- if isScene:
- objectName += "_scene"
-
if not globalForce:
if fullPath in globalExtractedAssetsTracker:
timestamp = globalExtractedAssetsTracker[fullPath]["timestamp"]
@@ -59,10 +49,7 @@ def ExtractFunc(fullPath):
currentTimeStamp = int(time.time())
- if isScene:
- ExtractScene(fullPath, outPath, outSourcePath)
- else:
- Extract(fullPath, outPath, outSourcePath)
+ ExtractFile(fullPath, outPath, outSourcePath)
if not globalAbort.is_set():
# Only update timestamp on succesful extractions
@@ -96,7 +83,7 @@ def main():
extractedAssetsTracker = manager.dict()
if os.path.exists(EXTRACTED_ASSETS_NAMEFILE):
- with open(EXTRACTED_ASSETS_NAMEFILE) as f:
+ with open(EXTRACTED_ASSETS_NAMEFILE, encoding='utf-8') as f:
extractedAssetsTracker.update(json.load(f, object_hook=manager.dict))
asset_path = args.single
diff --git a/tools/ZAPD/.gitrepo b/tools/ZAPD/.gitrepo
index 73304fd8d3..3202e5a919 100644
--- a/tools/ZAPD/.gitrepo
+++ b/tools/ZAPD/.gitrepo
@@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/zeldaret/ZAPD.git
branch = master
- commit = b9120803e6094a54192ed67d9585ab046101c816
- parent = 81b43ba32e564a00c976dec7d520e6bcb0b122f8
+ commit = 86160be6968c9813fcf359b88a0ac188d87c2772
+ parent = 07c93fd180beb092cb0f50faae04c57c0eff458a
method = merge
cmdver = 0.4.3
diff --git a/tools/ZAPD/Makefile b/tools/ZAPD/Makefile
index f2e9d64741..074e6a9736 100644
--- a/tools/ZAPD/Makefile
+++ b/tools/ZAPD/Makefile
@@ -1,27 +1,40 @@
OPTIMIZATION_ON ?= 1
+ASAN ?= 0
+DEPRECATION_OFF ?= 0
+CFLAGS ?=
CC := g++
INC := -I ZAPD -I lib/assimp/include -I lib/elfio -I lib/json/include -I lib/stb -I lib/tinygltf -I lib/libgfxd -I lib/tinyxml2
+CFLAGS += -g3 -ggdb -fpic -std=c++17 -rdynamic -Wall -fno-omit-frame-pointer
-CFLAGS := -g3 -fpic -Wl,-export-dynamic -std=c++17 -rdynamic -Wall
-ifeq ($(OPTIMIZATION_ON),1)
- CFLAGS += -O2
-else
+ifeq ($(OPTIMIZATION_ON),0)
CFLAGS += -O0
+else
+ CFLAGS += -O2
endif
+ifneq ($(ASAN),0)
+ CFLAGS += -fsanitize=address
+endif
+ifneq ($(DEPRECATION_OFF),0)
+ CFLAGS += -DDEPRECATION_OFF
+endif
+# CFLAGS += -DTEXTURE_DEBUG
-LDFLAGS := -ldl
+LDFLAGS := -ldl -lpng
UNAME := $(shell uname)
-FS_INC =
+FS_INC ?=
ifneq ($(UNAME), Darwin)
FS_INC += -lstdc++fs
+ CFLAGS += -Wl,-export-dynamic
endif
-SRC_DIRS := ZAPD ZAPD/ZRoom ZAPD/ZRoom/Commands ZAPD/Overlays ZAPD/HighLevel ZAPD/OpenFBX
+SRC_DIRS := ZAPD ZAPD/ZRoom ZAPD/ZRoom/Commands ZAPD/Overlays ZAPD/HighLevel
-CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
-CPP_FILES += lib/tinyxml2/tinyxml2.cpp
+ZAPD_CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
+ZAPD_H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))
+
+CPP_FILES += $(ZAPD_CPP_FILES) lib/tinyxml2/tinyxml2.cpp
O_FILES := $(CPP_FILES:.cpp=.o)
all: ZAPD.out copycheck
@@ -38,6 +51,11 @@ clean:
rebuild: clean all
+format:
+ clang-format-11 -i $(ZAPD_CPP_FILES) $(ZAPD_H_FILES)
+
+.PHONY: all genbuildinfo copycheck clean rebuild format
+
%.o: %.cpp
$(CC) $(CFLAGS) $(INC) -c $< -o $@ $(LDFLAGS)
@@ -45,7 +63,7 @@ ZAPD/Main.o: genbuildinfo ZAPD/Main.cpp
$(CC) $(CFLAGS) $(INC) -c ZAPD/Main.cpp -o $@ $(LDFLAGS)
lib/libgfxd/libgfxd.a:
- $(MAKE) -C lib/libgfxd -j
+ $(MAKE) -C lib/libgfxd
ZAPD.out: $(O_FILES) lib/libgfxd/libgfxd.a
$(CC) $(CFLAGS) $(INC) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC) $(LDFLAGS)
diff --git a/tools/ZAPD/README.md b/tools/ZAPD/README.md
new file mode 100644
index 0000000000..22da732f01
--- /dev/null
+++ b/tools/ZAPD/README.md
@@ -0,0 +1,103 @@
+# ZAPD: Zelda Asset Processor for Decomp
+
+## Compiling
+
+### Dependencies
+
+ZAPD needs a compiler with C++17 support.
+
+ZAPD has the following library dependencies:
+
+- `libpng`
+
+In a Debian/Ubuntu based environment, those could be installed with the following command:
+
+```bash
+sudo apt install libpng-dev
+```
+
+### Building
+
+#### Linux / *nix
+
+ZAPD uses the clasic `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:
+
+- `OPTIMIZATION_ON`: If set to `0`, then optimizations will be disabled (compile with `-O0`). Any other value compiles with `-O2`. Defaults to `1`.
+- `ASAN`: If it is set to a non-zero then ZAPD will be compiled with Address Sanitizer enabled (`-fsanitize=address`). Defaults to `0`.
+- `DEPRECATION_OFF`: If it is set to a non-zero then deprecation warnings will be disabled. Defaults to `0`.
+
+As an example, if you want to build ZAPD with optimizations disabled and use the address sanitizer, you could use the following command:
+
+```bash
+make -j OPTIMIZATION_ON=0 ASAN=1
+```
+
+#### Windows
+
+This repository contains `vcxproj` files for compiling under Visual Studio environments. See `ZAPD/ZAPD.vcxproj`.
+
+## Invoking ZAPD
+
+ZAPD needs a _File parsing mode_ to be passed as first parameter. The options are:
+
+- `e`: "Extraction" mode.
+ - In this mode, ZAPD expects a XML file as input, a folder as ouput and a path to the baserom files.
+ - ZAPD will read the XML and use it as a guide to extract the contents of the specified asset file from the baserom folder.
+ - For more info of the format of those XMLs, see the [ZAPD extraction XML reference](docs/zapd_extraction_xml_reference.md).
+- `bsf`: "Build source file" mode.
+ - This is an experimental mode.
+ - It was going to be used to let you have XMLs that aren't just for extraction. Might get used, might not. Still need to experiment on that.
+- `btex`: "Build texture" mode.
+ - In this mode, ZAPD expects a PNG file as input, a filename as ouput and a texture type parameter (`-tt`).
+ - ZAPD will try to convert the given PNG into the contents of a `uint64_t` C array.
+- `bren`: "Build (render) background" mode.
+ - In this mode, ZAPD expects a JPG file as input and a filename as ouput.
+ - ZAPD will try to convert the given JPG into the contents of a `uint64_t` C array.
+- `blb`: "Build blob" mode.
+ - In this mode, ZAPD expects a BIN file as input and a filename as ouput.
+ - ZAPD will try to convert the given BIN into the contents of a `uint8_t` C array.
+- `bovl`: "Build overlay" mode.
+ - In this mode, ZAPD expects an overlay C file as input, a filename as ouput and an overlay configuration path (`-cfg`).
+ - ZAPD will generate a reloc `.s` file.
+
+ZAPD also accepts the following list of extra parameters:
+
+- `-i PATH` / `--inputpath PATH`: Set input path.
+- `-o PATH` / `--outputpath PATH`: Set output path.
+- `-b PATH` / `--baserompath`: Set baserom path.
+ - Can be used only in `e` or `bsf` modes.
+- `-osf PATH`: Set source output path. This is the path where the `.c` and `.h` files will be extracted to. If omitted, it will use the value passed to `--outputpath` parameter.
+- `-gsf MODE`: Generate source file during extraction. If `MODE` is `1`, C source files will be generated.
+ - Can be used only in `e` mode.
+- `-crc` / `--output-crc`: Outputs a CRC file for each extracted texture.
+ - Can be used only in `e` or `bsf` modes.
+- `-ulzdl MODE`: Use "Legacy ZDisplayList" instead of `libgfxd`. Set `MODE` to `1` to enable it.
+ - Can be used only in `e` or `bsf` modes.
+- `-profile MODE`: Enable profiling. Set `MODE` to `1` to enable it.
+- `-uer MODE`: Split resources into their individual components (enabled by default). Set `MODE` to non-`1` to disable it.
+- `-tt TYPE`: Set texture type.
+ - Can be used only in mode `btex`.
+ - Valid values:
+ - `rgba32`
+ - `rgb5a1`
+ - `i4`
+ - `i8`
+ - `ia4`
+ - `ia8`
+ - `ia16`
+ - `ci4`
+ - `ci8`
+- `-cfg PATH`: Set cfg path (for overlays).
+ - Can be used only in `bovl` mode.
+- `-rconf PATH` Read Config File.
+- `-eh`: Enable error handler.
+ - Only available in non-Windows environments.
+- `-v MODE`: Enable verbosity. Currently there are 3 possible values:
+ - `0`: Default. Completely silent (except for warnings and errors).
+ - `1`: Information.
+ - `2` (and higher): Debug.
+- `-wu` / `--warn-unaccounted`: Enable warnings for each unaccounted block of data found.
+ - Can be used only in `e` or `bsf` modes.
+- `-tm MODE`: Test Mode (enables certain experimental features). To enable it, set `MODE` to `1`.
diff --git a/tools/ZAPD/ZAPD/Declaration.cpp b/tools/ZAPD/ZAPD/Declaration.cpp
new file mode 100644
index 0000000000..63a3918050
--- /dev/null
+++ b/tools/ZAPD/ZAPD/Declaration.cpp
@@ -0,0 +1,79 @@
+#include "Declaration.h"
+
+Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
+ std::string nText)
+{
+ alignment = nAlignment;
+ padding = nPadding;
+ size = nSize;
+ text = nText;
+}
+
+Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
+ std::string nVarName, bool nIsArray, std::string nText)
+ : Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
+{
+ varType = nVarType;
+ varName = nVarName;
+ isArray = nIsArray;
+}
+
+Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
+ std::string nVarType, std::string nVarName, bool nIsArray,
+ std::string nText)
+ : Declaration(nAlignment, nPadding, nSize, nText)
+{
+ varType = nVarType;
+ varName = nVarName;
+ isArray = nIsArray;
+}
+
+Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
+ std::string nVarName, bool nIsArray, size_t nArrayItemCnt,
+ std::string nText)
+ : Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
+{
+ varType = nVarType;
+ varName = nVarName;
+ isArray = nIsArray;
+ arrayItemCnt = nArrayItemCnt;
+}
+
+Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
+ std::string nVarName, bool nIsArray, std::string nArrayItemCntStr,
+ std::string nText)
+ : Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
+{
+ varType = nVarType;
+ varName = nVarName;
+ isArray = nIsArray;
+ arrayItemCntStr = nArrayItemCntStr;
+}
+
+Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
+ std::string nVarName, bool nIsArray, size_t nArrayItemCnt,
+ std::string nText, bool nIsExternal)
+ : Declaration(nAlignment, nSize, nVarType, nVarName, nIsArray, nArrayItemCnt, nText)
+{
+ isExternal = nIsExternal;
+}
+
+Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
+ std::string nVarType, std::string nVarName, bool nIsArray,
+ size_t nArrayItemCnt, std::string nText)
+ : Declaration(nAlignment, nPadding, nSize, nText)
+{
+ varType = nVarType;
+ varName = nVarName;
+ isArray = nIsArray;
+ arrayItemCnt = nArrayItemCnt;
+}
+
+Declaration::Declaration(std::string nIncludePath, size_t nSize, std::string nVarType,
+ std::string nVarName)
+ : Declaration(DeclarationAlignment::None, DeclarationPadding::None, nSize, "")
+{
+ includePath = nIncludePath;
+ varType = nVarType;
+ varName = nVarName;
+}
diff --git a/tools/ZAPD/ZAPD/Declaration.h b/tools/ZAPD/ZAPD/Declaration.h
new file mode 100644
index 0000000000..fa8653b858
--- /dev/null
+++ b/tools/ZAPD/ZAPD/Declaration.h
@@ -0,0 +1,65 @@
+#pragma once
+
+#include
+#include
+
+enum class DeclarationAlignment
+{
+ None,
+ Align4,
+ Align8,
+ Align16
+};
+
+enum class DeclarationPadding
+{
+ None,
+ Pad4,
+ Pad8,
+ Pad16
+};
+
+class Declaration
+{
+public:
+ DeclarationAlignment alignment;
+ DeclarationPadding padding;
+ size_t size = 0;
+ 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;
+ bool isExternal = false;
+ bool isArray = false;
+ size_t arrayItemCnt = 0;
+ std::string arrayItemCntStr;
+ std::vector references;
+ bool isUnaccounted = false;
+ bool isPlaceholder = false;
+
+ Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
+ std::string nVarName, bool nIsArray, std::string nText);
+ Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
+ std::string nVarType, std::string nVarName, bool nIsArray, std::string nText);
+ Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
+ std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText);
+ Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
+ std::string nVarName, bool nIsArray, std::string nArrayItemCntStr,
+ std::string nText);
+ Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
+ std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText,
+ bool nIsExternal);
+ Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
+ std::string nVarType, std::string nVarName, bool nIsArray, size_t nArrayItemCnt,
+ std::string nText);
+ Declaration(std::string nIncludePath, size_t nSize, std::string nVarType, std::string nVarName);
+
+protected:
+ Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
+ std::string nText);
+};
diff --git a/tools/ZAPD/ZAPD/File.h b/tools/ZAPD/ZAPD/File.h
index 62806d5f1c..69aa0441dc 100644
--- a/tools/ZAPD/ZAPD/File.h
+++ b/tools/ZAPD/ZAPD/File.h
@@ -3,7 +3,6 @@
#include
#include
#include
-#include
#include
#include
#include "StringHelper.h"
diff --git a/tools/ZAPD/ZAPD/Globals.cpp b/tools/ZAPD/ZAPD/Globals.cpp
index 93e7fdf255..a8676cc639 100644
--- a/tools/ZAPD/ZAPD/Globals.cpp
+++ b/tools/ZAPD/ZAPD/Globals.cpp
@@ -5,7 +5,6 @@
#include "tinyxml2.h"
using namespace tinyxml2;
-using namespace std;
Globals* Globals::Instance;
@@ -16,27 +15,26 @@ Globals::Globals()
files = std::vector();
segments = std::vector();
symbolMap = std::map();
- segmentRefs = map();
- segmentRefFiles = map();
+ segmentRefs = std::map();
+ segmentRefFiles = std::map();
game = ZGame::OOT_RETAIL;
genSourceFile = true;
testMode = false;
profile = false;
- includeFilePrefix = false;
useLegacyZDList = false;
useExternalResources = true;
lastScene = nullptr;
- verbosity = VERBOSITY_SILENT;
+ verbosity = VerbosityLevel::VERBOSITY_SILENT;
}
-string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
+std::string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
{
if (segmentRefs.find(segNumber) != segmentRefs.end())
{
if (segmentRefFiles.find(segNumber) == segmentRefFiles.end())
{
XMLDocument doc;
- string filePath = segmentRefs[segNumber];
+ std::string filePath = segmentRefs[segNumber];
XMLError eResult = doc.LoadFile(filePath.c_str());
if (eResult != tinyxml2::XML_SUCCESS)
@@ -47,14 +45,12 @@ string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
if (root == nullptr)
return "ERROR";
- // vector files = vector();
-
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
- if (string(child->Name()) == "File")
+ if (std::string(child->Name()) == "File")
{
- ZFile* file = new ZFile(fileMode, child, "", "", "", "", true);
+ ZFile* file = new ZFile(fileMode, child, "", "", "", filePath, true);
file->GeneratePlaceholderDeclarations();
segmentRefFiles[segNumber] = file;
break;
@@ -87,41 +83,41 @@ void Globals::ReadConfigFile(const std::string& configFilePath)
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
- if (string(child->Name()) == "SymbolMap")
+ if (std::string(child->Name()) == "SymbolMap")
{
- string fileName = string(child->Attribute("File"));
+ std::string fileName = std::string(child->Attribute("File"));
GenSymbolMap(Path::GetDirectoryName(configFilePath) + "/" + fileName);
}
- else if (string(child->Name()) == "Segment")
+ else if (std::string(child->Name()) == "Segment")
{
- string fileName = string(child->Attribute("File"));
+ std::string fileName = std::string(child->Attribute("File"));
int32_t segNumber = child->IntAttribute("Number");
segmentRefs[segNumber] = fileName;
}
- else if (string(child->Name()) == "ActorList")
+ else if (std::string(child->Name()) == "ActorList")
{
- string fileName = string(child->Attribute("File"));
+ std::string fileName = std::string(child->Attribute("File"));
std::vector lines =
File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName);
for (std::string line : lines)
cfg.actorList.push_back(StringHelper::Strip(line, "\r"));
}
- else if (string(child->Name()) == "ObjectList")
+ else if (std::string(child->Name()) == "ObjectList")
{
- string fileName = string(child->Attribute("File"));
+ std::string fileName = std::string(child->Attribute("File"));
std::vector lines =
File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName);
for (std::string line : lines)
cfg.objectList.push_back(StringHelper::Strip(line, "\r"));
}
- else if (string(child->Name()) == "TexturePool")
+ else if (std::string(child->Name()) == "TexturePool")
{
- string fileName = string(child->Attribute("File"));
+ std::string fileName = std::string(child->Attribute("File"));
ReadTexturePool(Path::GetDirectoryName(configFilePath) + "/" + fileName);
}
- else if (string(child->Name()) == "BGConfig")
+ else if (std::string(child->Name()) == "BGConfig")
{
cfg.bgScreenWidth = child->IntAttribute("ScreenWidth", 320);
cfg.bgScreenHeight = child->IntAttribute("ScreenHeight", 240);
@@ -148,11 +144,11 @@ void Globals::ReadTexturePool(const std::string& texturePoolXmlPath)
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
- if (string(child->Name()) == "Texture")
+ if (std::string(child->Name()) == "Texture")
{
- string crcStr = string(child->Attribute("CRC"));
- string texPath = string(child->Attribute("Path"));
- string texName = "";
+ std::string crcStr = std::string(child->Attribute("CRC"));
+ fs::path texPath = std::string(child->Attribute("Path"));
+ std::string texName = "";
uint32_t crc = strtoul(crcStr.c_str(), NULL, 16);
@@ -175,10 +171,13 @@ void Globals::GenSymbolMap(const std::string& symbolMapPath)
}
}
-void Globals::AddSegment(int32_t segment)
+void Globals::AddSegment(int32_t segment, ZFile* file)
{
if (std::find(segments.begin(), segments.end(), segment) == segments.end())
segments.push_back(segment);
+
+ segmentRefs[segment] = file->GetXmlFilePath();
+ segmentRefFiles[segment] = file;
}
bool Globals::HasSegment(int32_t segment)
diff --git a/tools/ZAPD/ZAPD/Globals.h b/tools/ZAPD/ZAPD/Globals.h
index 5186947243..a7f1fed059 100644
--- a/tools/ZAPD/ZAPD/Globals.h
+++ b/tools/ZAPD/ZAPD/Globals.h
@@ -7,7 +7,7 @@
#include "ZRoom/ZRoom.h"
#include "ZTexture.h"
-enum VerbosityLevel
+enum class VerbosityLevel
{
VERBOSITY_SILENT,
VERBOSITY_INFO,
@@ -42,9 +42,9 @@ public:
bool genSourceFile; // Used for extraction
bool useExternalResources;
- bool testMode; // Enables certain experimental features
- bool profile; // Measure performance of certain operations
- bool includeFilePrefix; // Include the file prefix in symbols
+ bool testMode; // Enables certain experimental features
+ bool outputCrc = false;
+ bool profile; // Measure performance of certain operations
bool useLegacyZDList;
VerbosityLevel verbosity; // ZAPD outputs additional information
ZFileMode fileMode;
@@ -66,7 +66,7 @@ public:
void ReadConfigFile(const std::string& configFilePath);
void ReadTexturePool(const std::string& texturePoolXmlPath);
void GenSymbolMap(const std::string& symbolMapPath);
- void AddSegment(int32_t segment);
+ void AddSegment(int32_t segment, ZFile* file);
bool HasSegment(int32_t segment);
};
diff --git a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp
index 6ae2264db9..a316ddf6f4 100644
--- a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp
+++ b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp
@@ -1,6 +1,5 @@
#include "HLAnimationIntermediette.h"
-using namespace std;
using namespace tinyxml2;
HLAnimationIntermediette::HLAnimationIntermediette()
@@ -8,8 +7,8 @@ HLAnimationIntermediette::HLAnimationIntermediette()
limit = 0;
limbCount = 0;
frameCount = 0;
- rotationValues = vector();
- rotationIndices = vector();
+ rotationValues = std::vector();
+ rotationIndices = std::vector();
}
HLAnimationIntermediette::~HLAnimationIntermediette()
@@ -32,16 +31,16 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath)
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
- if (string(child->Name()) == "RotationValues")
+ if (std::string(child->Name()) == "RotationValues")
{
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
child2 = child2->NextSiblingElement())
{
- string value = child2->GetText();
+ std::string value = child2->GetText();
anim->rotationValues.push_back(atoi(value.c_str()));
}
}
- else if (string(child->Name()) == "RotationIndices")
+ else if (std::string(child->Name()) == "RotationIndices")
{
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
child2 = child2->NextSiblingElement())
@@ -63,14 +62,14 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromZAnimation(ZAnimation* z
ZAnimation* HLAnimationIntermediette::ToZAnimation()
{
- ZAnimation* zAnim = new ZAnimation(nullptr);
+ ZAnimation* zAnim = new ZNormalAnimation(nullptr);
return zAnim;
}
-string HLAnimationIntermediette::OutputXML()
+std::string HLAnimationIntermediette::OutputXML()
{
- string output = "";
+ std::string output = "";
XMLDocument doc;
XMLElement* root = doc.NewElement("HLAnimationIntermediette");
diff --git a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.h b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.h
index 0f5c00b04f..171ac9d4d9 100644
--- a/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.h
+++ b/tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.h
@@ -1,9 +1,9 @@
#pragma once
#include
-#include
#include "../ZAnimation.h"
#include "HLFileIntermediette.h"
+#include "tinyxml2.h"
/*
* An intermediette format for animations. Going to use XML.
diff --git a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp
index db7483a150..88f66a46dd 100644
--- a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp
+++ b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.cpp
@@ -12,12 +12,11 @@
#include
#endif
-using namespace std;
using namespace tinyxml2;
HLModelIntermediette::HLModelIntermediette()
{
- blocks = vector();
+ blocks = std::vector();
startIndex = 0;
meshStartIndex = 0;
hasSkeleton = false;
@@ -35,7 +34,7 @@ HLModelIntermediette* HLModelIntermediette::FromXML(tinyxml2::XMLElement* root)
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
- string childName = child->Name();
+ std::string childName = child->Name();
HLIntermediette* block = nullptr;
if (childName == "Mesh")
@@ -66,16 +65,16 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
limb->name = zDisplayList->GetName();
// Go through verts
- vector finalVerts = vector();
+ std::vector finalVerts;
int32_t vStart = -1;
- for (pair> pair : zDisplayList->vertices)
+ for (auto& pair : zDisplayList->vertices)
{
if (vStart == -1) // TODO: Find a better way to do this
vStart = pair.first;
- for (Vertex v : pair.second)
+ for (auto& v : pair.second)
finalVerts.push_back(v);
}
@@ -85,14 +84,17 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
model->blocks.push_back(vertIntr);
// Go through textures
+ // TODO: Textures are now stored directly in ZFile
+ /*
for (pair pair : zDisplayList->textures)
{
- HLTextureIntermediette* texIntr = new HLTextureIntermediette();
- texIntr->tex = pair.second;
- texIntr->name = texIntr->tex->GetName();
+ HLTextureIntermediette* texIntr = new HLTextureIntermediette();
+ texIntr->tex = pair.second;
+ texIntr->name = texIntr->tex->GetName();
- model->blocks.push_back(texIntr);
+ model->blocks.push_back(texIntr);
}
+ */
// Analyze display lists to determine components
HLDisplayListIntermediette* dList = new HLDisplayListIntermediette();
@@ -173,9 +175,10 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
lastMat->clrM = lastClrM;
// Bit of a hack here...
- int32_t lastData = (int32_t)(zDisplayList->instructions[i - 1]);
- string texName = zDisplayList->textures[lastData & 0x00FFFFFF]->GetName();
- lastMat->textureName = texName;
+ // int32_t lastData = (int32_t)(zDisplayList->instructions[i - 1]);
+ // TODO
+ // string texName = zDisplayList->textures[lastData & 0x00FFFFFF]->GetName();
+ // lastMat->textureName = texName;
// --------------------------
model->blocks.push_back(mesh);
@@ -189,10 +192,11 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
}
else if (opcode == F3DZEXOpcode::G_SETTIMG)
{
- int32_t texAddress = data & 0x00FFFFFF;
+ // int32_t texAddress = data & 0x00FFFFFF;
- string texName = zDisplayList->textures[texAddress]->GetName();
- lastMat->textureName = texName;
+ // TODO
+ // string texName = zDisplayList->textures[texAddress]->GetName();
+ // lastMat->textureName = texName;
}
else if (opcode == F3DZEXOpcode::G_VTX)
{
@@ -246,32 +250,34 @@ void HLModelIntermediette::FromZSkeleton(HLModelIntermediette* model, ZSkeleton*
void HLModelIntermediette::ProcessZSkeletonLimb(HLModelIntermediette* model, ZSkeleton* zSkeleton,
ZLimb* limb)
{
+ /*
if (limb->dList == nullptr && limb->dListPtr != 0)
- limb->dList = (ZDisplayList*)zSkeleton->parent->FindResource(limb->dListPtr);
+ limb->dList = (ZDisplayList*)zSkeleton->parent->FindResource(limb->dListPtr);
if (limb->dList != nullptr)
{
- auto cmdTrans = new HLSetTranslation(limb->transX, limb->transY, limb->transZ);
- cmdTrans->parent = model;
- model->blocks.push_back(cmdTrans);
+ auto cmdTrans = new HLSetTranslation(limb->transX, limb->transY, limb->transZ);
+ cmdTrans->parent = model;
+ model->blocks.push_back(cmdTrans);
- FromZDisplayList(model, limb->dList);
+ FromZDisplayList(model, limb->dList);
}
+ */
- for (ZLimb* childLimb : limb->children)
+ /*for (ZLimb* childLimb : limb->children)
{
- ProcessZSkeletonLimb(model, zSkeleton, childLimb);
- }
+ ProcessZSkeletonLimb(model, zSkeleton, childLimb);
+ }*/
}
-string HLModelIntermediette::ToOBJFile()
+std::string HLModelIntermediette::ToOBJFile()
{
- string output = "";
+ std::string output = "";
for (HLIntermediette* block : blocks)
{
block->parent = this;
- string code = block->OutputOBJ();
+ std::string code = block->OutputOBJ();
output += code;
@@ -282,7 +288,7 @@ string HLModelIntermediette::ToOBJFile()
return output;
}
-string HLModelIntermediette::ToAssimpFile()
+std::string HLModelIntermediette::ToAssimpFile()
{
#ifdef USE_ASSIMP
Assimp::Exporter exporter;
@@ -330,13 +336,13 @@ string HLModelIntermediette::ToAssimpFile()
return "";
}
-string HLModelIntermediette::OutputCode()
+std::string HLModelIntermediette::OutputCode()
{
- string output = "";
+ std::string output = "";
for (HLIntermediette* block : blocks)
{
- string code = block->OutputCode();
+ std::string code = block->OutputCode();
output += code;
@@ -349,7 +355,7 @@ string HLModelIntermediette::OutputCode()
std::string HLModelIntermediette::OutputXML()
{
- string output = "";
+ std::string output = "";
XMLDocument doc;
XMLElement* root = doc.NewElement("HLModelIntermediette");
@@ -366,7 +372,7 @@ std::string HLModelIntermediette::OutputXML()
}
template
-inline T* HLModelIntermediette::FindByName(string name)
+inline T* HLModelIntermediette::FindByName(std::string name)
{
for (HLIntermediette* block : blocks)
{
@@ -407,12 +413,12 @@ void HLIntermediette::InitFromXML(XMLElement* xmlElement)
name = xmlElement->Attribute("Name");
}
-string HLIntermediette::OutputCode()
+std::string HLIntermediette::OutputCode()
{
return "";
}
-string HLIntermediette::OutputOBJ()
+std::string HLIntermediette::OutputOBJ()
{
return "";
}
@@ -429,7 +435,7 @@ void HLMeshCommand::InitFromXML(XMLElement* xmlElement)
{
}
-string HLMeshCommand::OutputCode(HLModelIntermediette* parent)
+std::string HLMeshCommand::OutputCode(HLModelIntermediette* parent)
{
return "";
}
@@ -449,35 +455,37 @@ void HLMeshCommand::OutputXML(tinyxml2::XMLElement* parent)
HLVerticesIntermediette::HLVerticesIntermediette() : HLIntermediette()
{
- vertices = vector();
+ vertices = std::vector();
}
void HLVerticesIntermediette::InitFromXML(XMLElement* verticesElement)
{
name = verticesElement->Attribute("Name");
+ /*
for (XMLElement* child = verticesElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
- vertices.push_back(Vertex(child->IntAttribute("X"), child->IntAttribute("Y"),
- child->IntAttribute("Z"), child->IntAttribute("Flags"),
- child->IntAttribute("S"), child->IntAttribute("T"),
- child->IntAttribute("R"), child->IntAttribute("G"),
- child->IntAttribute("B"), child->IntAttribute("A")));
+ vertices.push_back(ZVtx(child->IntAttribute("X"), child->IntAttribute("Y"),
+ child->IntAttribute("Z"), child->IntAttribute("Flags"),
+ child->IntAttribute("S"), child->IntAttribute("T"),
+ child->IntAttribute("R"), child->IntAttribute("G"),
+ child->IntAttribute("B"), child->IntAttribute("A")));
+ */
}
-void HLVerticesIntermediette::InitFromVertices(vector dispListVertices)
+void HLVerticesIntermediette::InitFromVertices(std::vector dispListVertices)
{
- for (Vertex v : dispListVertices)
+ for (auto v : dispListVertices)
vertices.push_back(v);
}
-string HLVerticesIntermediette::OutputCode(HLModelIntermediette* parent)
+std::string HLVerticesIntermediette::OutputCode(HLModelIntermediette* parent)
{
- string output = "";
+ std::string output = "";
output += StringHelper::Sprintf("Vtx %s_verts[] = \n{\n", name.c_str());
- for (Vertex v : vertices)
+ for (auto v : vertices)
{
output += StringHelper::Sprintf(" { %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", v.x,
v.y, v.z, v.flag, v.s, v.t, v.r, v.g, v.b, v.a);
@@ -490,9 +498,9 @@ string HLVerticesIntermediette::OutputCode(HLModelIntermediette* parent)
std::string HLVerticesIntermediette::OutputOBJ()
{
- string output = "";
+ std::string output = "";
- for (Vertex v : vertices)
+ for (auto& v : vertices)
{
output += StringHelper::Sprintf("v %f %f %f %i %i %i %i\n", (float)v.x * 0.1f,
(float)v.y * 0.1f, (float)v.z * 0.1f, v.r, v.g, v.b, v.a);
@@ -517,7 +525,7 @@ void HLVerticesIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XM
element->SetAttribute("Name", name.c_str());
- for (Vertex v : vertices)
+ for (auto& v : vertices)
{
XMLElement* vElem = doc->NewElement("Vertex");
vElem->SetAttribute("X", v.x);
@@ -549,9 +557,9 @@ void HLMeshCmdGeoSettings::InitFromXML(tinyxml2::XMLElement* xmlElement)
off = xmlElement->Attribute("Off");
}
-string HLMeshCmdGeoSettings::OutputCode(HLModelIntermediette* parent)
+std::string HLMeshCmdGeoSettings::OutputCode(HLModelIntermediette* parent)
{
- string output = "";
+ std::string output = "";
if (off != "")
output +=
@@ -587,7 +595,7 @@ void HLMeshCmdTriangle1::InitFromXML(tinyxml2::XMLElement* xmlElement)
flag = xmlElement->IntAttribute("flag");
}
-string HLMeshCmdTriangle1::OutputCode(HLModelIntermediette* parent)
+std::string HLMeshCmdTriangle1::OutputCode(HLModelIntermediette* parent)
{
return StringHelper::Sprintf("gsSP1Triangle(%i, %i, %i, %i),", v0, v1, v2, flag);
}
@@ -653,7 +661,7 @@ void HLMeshCmdTriangle2::InitFromXML(tinyxml2::XMLElement* xmlElement)
flag1 = xmlElement->IntAttribute("Flag1");
}
-string HLMeshCmdTriangle2::OutputCode(HLModelIntermediette* parent)
+std::string HLMeshCmdTriangle2::OutputCode(HLModelIntermediette* parent)
{
return StringHelper::Sprintf("gsSP2Triangles(%i, %i, %i, %i, %i, %i, %i, %i),", v0, v1, v2,
flag0, v10, v11, v12, flag1);
@@ -661,7 +669,7 @@ string HLMeshCmdTriangle2::OutputCode(HLModelIntermediette* parent)
std::string HLMeshCmdTriangle2::OutputOBJ(HLModelIntermediette* parent)
{
- string output = "";
+ std::string output = "";
int32_t startIndex = parent->startIndex;
@@ -753,7 +761,7 @@ void HLMeshCmdLoadVertices::OutputAssimp(HLModelIntermediette* parent, aiScene*
parent->startIndex = startIndex;
}
-string HLMeshCmdLoadVertices::OutputCode(HLModelIntermediette* parent)
+std::string HLMeshCmdLoadVertices::OutputCode(HLModelIntermediette* parent)
{
HLVerticesIntermediette* verts = parent->FindByType();
return StringHelper::Sprintf("gsSPVertex(&%s[%i], %i, %i),", verts->name.c_str(), startIndex,
@@ -785,7 +793,7 @@ void HLMaterialIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
clrL = xmlElement->IntAttribute("ClrL");
}
-string HLMaterialIntermediette::OutputCode()
+std::string HLMaterialIntermediette::OutputCode()
{
return "";
}
@@ -810,10 +818,10 @@ void HLMaterialIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XM
HLDisplayListIntermediette::HLDisplayListIntermediette()
{
- commands = vector();
+ commands = std::vector();
}
-string HLDisplayListIntermediette::OutputCode()
+std::string HLDisplayListIntermediette::OutputCode()
{
return std::string();
}
@@ -823,7 +831,7 @@ void HLDisplayListIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
- string name = child->Name();
+ std::string name = child->Name();
HLDisplayListCommand* cmd = nullptr;
@@ -870,13 +878,15 @@ void HLTextureIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
name = xmlElement->Attribute("Name");
fileName = xmlElement->Attribute("TextureName");
- // string format = xmlElement->Attribute("Format");
- string format = "rgb5a1"; // TEST
+ // std::string format = xmlElement->Attribute("Format");
+ std::string format = "rgb5a1"; // TEST
// tex = HLTexture::FromPNG(fileName,
// (HLTextureType)ZTexture::GetTextureTypeFromString(format));
- tex = ZTexture::FromPNG(Path::GetDirectoryName(Globals::Instance->inputPath) + "/" + fileName,
- ZTexture::GetTextureTypeFromString(format));
+ tex = new ZTexture(nullptr);
+ tex->ZTexture::FromPNG(Path::GetDirectoryName(Globals::Instance->inputPath.string()) + "/" +
+ fileName,
+ ZTexture::GetTextureTypeFromString(format));
}
std::string HLTextureIntermediette::OutputCode()
@@ -892,7 +902,7 @@ void HLTextureIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XML
element->SetAttribute("Name", name.c_str());
element->SetAttribute("TextureName",
(name + "." + tex->GetExternalExtension() + ".png").c_str());
- tex->Save(Globals::Instance->outputPath);
+ tex->Save(Globals::Instance->outputPath.string());
root->InsertEndChild(element);
}
@@ -925,7 +935,7 @@ std::string HLMeshCmdCull::OutputCode(HLModelIntermediette* parent)
HLMeshIntermediette::HLMeshIntermediette() : HLIntermediette()
{
- commands = vector();
+ commands = std::vector();
}
void HLMeshIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
@@ -935,7 +945,7 @@ void HLMeshIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
- string name = child->Name();
+ std::string name = child->Name();
HLMeshCommand* cmd = nullptr;
@@ -958,9 +968,9 @@ void HLMeshIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
}
}
-string HLMeshIntermediette::OutputCode(string materialName)
+std::string HLMeshIntermediette::OutputCode(std::string materialName)
{
- string output = "";
+ std::string output = "";
HLMaterialIntermediette* mat = parent->FindByName(materialName);
HLTextureIntermediette* tex = parent->FindByName(mat->textureName);
@@ -982,9 +992,9 @@ string HLMeshIntermediette::OutputCode(string materialName)
return output;
}
-string HLMeshIntermediette::OutputOBJ()
+std::string HLMeshIntermediette::OutputOBJ()
{
- string output = "";
+ std::string output = "";
output += StringHelper::Sprintf("o %s\n", name.c_str());
@@ -1031,7 +1041,7 @@ void HLMeshIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLEle
HLLimbIntermediette::HLLimbIntermediette()
{
- commands = vector();
+ commands = std::vector();
}
void HLLimbIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
@@ -1041,7 +1051,7 @@ void HLLimbIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
- string name = child->Name();
+ std::string name = child->Name();
HLLimbCommand* cmd = nullptr;
@@ -1058,7 +1068,7 @@ void HLLimbIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
std::string HLLimbIntermediette::OutputCode()
{
- string output = "";
+ std::string output = "";
output += StringHelper::Sprintf("Gfx %s[] = \n{\n", name.c_str());
@@ -1113,7 +1123,7 @@ void HLLimbCommand::OutputXML(tinyxml2::XMLElement* parent)
std::string HLLimbCommand::OutputCode(HLModelIntermediette* parent)
{
- string output = "";
+ std::string output = "";
// Time to generate the display list...
HLMeshIntermediette* mesh = parent->FindByName(meshName);
diff --git a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h
index 5fda096649..e591e2c8f0 100644
--- a/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h
+++ b/tools/ZAPD/ZAPD/HighLevel/HLModelIntermediette.h
@@ -4,11 +4,11 @@
#include
#include
#include
-#include
#include
#include "../ZDisplayList.h"
#include "../ZSkeleton.h"
#include "HLFileIntermediette.h"
+#include "tinyxml2.h"
/*
* An intermediette format for models. Goes from FBX<-->Intermediette<-->Display List C Code.
@@ -156,12 +156,12 @@ public:
class HLVerticesIntermediette : public HLIntermediette
{
public:
- std::vector vertices;
+ std::vector vertices;
HLVerticesIntermediette();
virtual void InitFromXML(tinyxml2::XMLElement* verticesElement);
- void InitFromVertices(std::vector dispListVertices);
+ void InitFromVertices(std::vector dispListVertices);
virtual std::string OutputCode(HLModelIntermediette* parent);
virtual std::string OutputOBJ();
virtual void OutputAssimp(aiScene* scene, std::vector* verts);
diff --git a/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp b/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp
index 0bf6b36370..b7e3a93e01 100644
--- a/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp
+++ b/tools/ZAPD/ZAPD/HighLevel/HLTexture.cpp
@@ -1,16 +1,13 @@
#include "HLTexture.h"
-#include
#include "../StringHelper.h"
-using namespace std;
-
HLTexture* HLTexture::FromPNG(std::string pngFilePath, HLTextureType texType)
{
- int32_t comp;
+ // int32_t comp;
HLTexture* tex = new HLTexture();
tex->type = texType;
- tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int32_t*)&tex->width,
- (int32_t*)&tex->height, &comp, STBI_rgb_alpha);
+ // tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int32_t*)&tex->width,
+ // (int32_t*)&tex->height, &comp, STBI_rgb_alpha);
return tex;
}
diff --git a/tools/ZAPD/ZAPD/ImageBackend.cpp b/tools/ZAPD/ZAPD/ImageBackend.cpp
new file mode 100644
index 0000000000..0b4bce360a
--- /dev/null
+++ b/tools/ZAPD/ZAPD/ImageBackend.cpp
@@ -0,0 +1,473 @@
+#include "ImageBackend.h"
+
+#include
+#include
+#include
+#include
+
+#include "StringHelper.h"
+
+/* ImageBackend */
+
+ImageBackend::~ImageBackend()
+{
+ FreeImageData();
+}
+
+void ImageBackend::ReadPng(const char* filename)
+{
+ FreeImageData();
+
+ FILE* fp = fopen(filename, "rb");
+ if (fp == nullptr)
+ throw std::runtime_error(StringHelper::Sprintf(
+ "ImageBackend::ReadPng: Error.\n\t Couldn't open file '%s'.", filename));
+
+ png_structp png = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
+ if (!png)
+ throw std::runtime_error("ImageBackend::ReadPng: Error.\n\t Couldn't create png struct.");
+
+ png_infop info = png_create_info_struct(png);
+ if (!info)
+ throw std::runtime_error("ImageBackend::ReadPng: Error.\n\t Couldn't create png info.");
+
+ if (setjmp(png_jmpbuf(png)))
+ throw std::runtime_error("ImageBackend::ReadPng: Error.\n\t setjmp(png_jmpbuf(png)).");
+
+ png_init_io(png, fp);
+
+ png_read_info(png, info);
+
+ width = png_get_image_width(png, info);
+ height = png_get_image_height(png, info);
+ colorType = png_get_color_type(png, info);
+ bitDepth = png_get_bit_depth(png, info);
+
+#ifdef TEXTURE_DEBUG
+ printf("Width: %u\n", width);
+ printf("Height: %u\n", height);
+ printf("ColorType: ");
+ switch (colorType)
+ {
+ case PNG_COLOR_TYPE_RGBA:
+ printf("PNG_COLOR_TYPE_RGBA\n");
+ break;
+
+ case PNG_COLOR_TYPE_RGB:
+ printf("PNG_COLOR_TYPE_RGB\n");
+ break;
+
+ case PNG_COLOR_TYPE_PALETTE:
+ printf("PNG_COLOR_TYPE_PALETTE\n");
+ break;
+
+ default:
+ printf("%u\n", colorType);
+ break;
+ }
+ printf("BitDepth: %u\n", bitDepth);
+ printf("\n");
+#endif
+
+ // Read any color_type into 8bit depth, RGBA format.
+ // See http://www.libpng.org/pub/png/libpng-manual.txt
+
+ if (bitDepth == 16)
+ png_set_strip_16(png);
+
+ if (colorType == PNG_COLOR_TYPE_PALETTE)
+ {
+ // png_set_palette_to_rgb(png);
+ isColorIndexed = true;
+ }
+
+ // PNG_COLOR_TYPE_GRAY_ALPHA is always 8 or 16bit depth.
+ if (colorType == PNG_COLOR_TYPE_GRAY && bitDepth < 8)
+ png_set_expand_gray_1_2_4_to_8(png);
+
+ /*if (png_get_valid(png, info, PNG_INFO_tRNS))
+ png_set_tRNS_to_alpha(png);*/
+
+ // These color_type don't have an alpha channel then fill it with 0xff.
+ /*if(*color_type == PNG_COLOR_TYPE_RGB ||
+ *color_type == PNG_COLOR_TYPE_GRAY ||
+ *color_type == PNG_COLOR_TYPE_PALETTE)
+ png_set_filler(png, 0xFF, PNG_FILLER_AFTER);*/
+
+ if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
+ png_set_gray_to_rgb(png);
+
+ png_read_update_info(png, info);
+
+ size_t rowBytes = png_get_rowbytes(png, info);
+ pixelMatrix = (uint8_t**)malloc(sizeof(uint8_t*) * height);
+ for (size_t y = 0; y < height; y++)
+ {
+ pixelMatrix[y] = (uint8_t*)malloc(rowBytes);
+ }
+
+ png_read_image(png, pixelMatrix);
+
+#ifdef TEXTURE_DEBUG
+ printf("rowBytes: %zu\n", rowBytes);
+
+ size_t bytePerPixel = GetBytesPerPixel();
+ printf("imgData\n");
+ for (size_t y = 0; y < height; y++)
+ {
+ for (size_t x = 0; x < width; x++)
+ {
+ for (size_t z = 0; z < bytePerPixel; z++)
+ {
+ printf("%02X ", pixelMatrix[y][x * bytePerPixel + z]);
+ }
+ printf(" ");
+ }
+ printf("\n");
+ }
+ printf("\n");
+#endif
+
+ fclose(fp);
+
+ png_destroy_read_struct(&png, &info, nullptr);
+
+ hasImageData = true;
+}
+
+void ImageBackend::ReadPng(const fs::path& filename)
+{
+ ReadPng(filename.c_str());
+}
+
+void ImageBackend::WritePng(const char* filename)
+{
+ assert(hasImageData);
+
+ FILE* fp = fopen(filename, "wb");
+ if (!fp)
+ throw std::runtime_error(StringHelper::Sprintf(
+ "ImageBackend::WritePng: Error.\n\t Couldn't open file '%s' in write mode.", filename));
+
+ png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
+ if (!png)
+ throw std::runtime_error("ImageBackend::WritePng: Error.\n\t Couldn't create png struct.");
+
+ png_infop info = png_create_info_struct(png);
+ if (!info)
+ throw std::runtime_error("ImageBackend::WritePng: Error.\n\t Couldn't create png info.");
+
+ if (setjmp(png_jmpbuf(png)))
+ throw std::runtime_error("ImageBackend::WritePng: Error.\n\t setjmp(png_jmpbuf(png)).");
+
+ png_init_io(png, fp);
+
+ png_set_IHDR(png, info, width, height,
+ bitDepth, // 8,
+ colorType, // PNG_COLOR_TYPE_RGBA,
+ PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+
+ if (isColorIndexed)
+ {
+ png_set_PLTE(png, info, static_cast(colorPalette), paletteSize);
+
+#ifdef TEXTURE_DEBUG
+ printf("palette\n");
+ png_color* aux = (png_color*)colorPalette;
+ for (size_t y = 0; y < paletteSize; y++)
+ {
+ printf("#%02X%02X%02X ", aux[y].red, aux[y].green, aux[y].blue);
+ if ((y + 1) % 8 == 0)
+ printf("\n");
+ }
+ printf("\n");
+#endif
+
+ png_set_tRNS(png, info, alphaPalette, paletteSize, nullptr);
+ }
+
+ png_write_info(png, info);
+
+ // To remove the alpha channel for PNG_COLOR_TYPE_RGB format,
+ // Use png_set_filler().
+ // png_set_filler(png, 0, PNG_FILLER_AFTER);
+
+#ifdef TEXTURE_DEBUG
+ size_t bytePerPixel = GetBytesPerPixel();
+ printf("imgData\n");
+ for (size_t y = 0; y < height; y++)
+ {
+ for (size_t x = 0; x < width * bytePerPixel; x++)
+ {
+ printf("%02X ", pixelMatrix[y][x]);
+ }
+ printf("\n");
+ }
+ printf("\n");
+#endif
+
+ png_write_image(png, pixelMatrix);
+ png_write_end(png, nullptr);
+
+ fclose(fp);
+
+ png_destroy_write_struct(&png, &info);
+}
+
+void ImageBackend::WritePng(const fs::path& filename)
+{
+ WritePng(filename.c_str());
+}
+
+void ImageBackend::SetTextureData(const std::vector>& texData,
+ uint32_t nWidth, uint32_t nHeight, uint8_t nColorType,
+ uint8_t nBitDepth)
+{
+ FreeImageData();
+
+ width = nWidth;
+ height = nHeight;
+ colorType = nColorType;
+ bitDepth = nBitDepth;
+
+ size_t bytePerPixel = GetBytesPerPixel();
+
+ pixelMatrix = static_cast(malloc(sizeof(uint8_t*) * height));
+ for (size_t y = 0; y < height; y++)
+ {
+ pixelMatrix[y] = static_cast(malloc(sizeof(uint8_t*) * width * bytePerPixel));
+ for (size_t x = 0; x < width; x++)
+ {
+ pixelMatrix[y][x * bytePerPixel + 0] = texData.at(y).at(x).r;
+ pixelMatrix[y][x * bytePerPixel + 1] = texData.at(y).at(x).g;
+ pixelMatrix[y][x * bytePerPixel + 2] = texData.at(y).at(x).b;
+
+ if (colorType == PNG_COLOR_TYPE_RGBA)
+ pixelMatrix[y][x * bytePerPixel + 3] = texData.at(y).at(x).a;
+ }
+ }
+ hasImageData = true;
+}
+
+void ImageBackend::InitEmptyRGBImage(uint32_t nWidth, uint32_t nHeight, bool alpha)
+{
+ FreeImageData();
+
+ width = nWidth;
+ height = nHeight;
+ colorType = PNG_COLOR_TYPE_RGB;
+ if (alpha)
+ colorType = PNG_COLOR_TYPE_RGBA;
+ bitDepth = 8; // nBitDepth;
+
+ size_t bytePerPixel = GetBytesPerPixel();
+
+ pixelMatrix = static_cast(malloc(sizeof(uint8_t*) * height));
+ for (size_t y = 0; y < height; y++)
+ {
+ pixelMatrix[y] = static_cast(calloc(width * bytePerPixel, sizeof(uint8_t*)));
+ }
+
+ hasImageData = true;
+}
+
+void ImageBackend::InitEmptyPaletteImage(uint32_t nWidth, uint32_t nHeight)
+{
+ FreeImageData();
+
+ width = nWidth;
+ height = nHeight;
+ colorType = PNG_COLOR_TYPE_PALETTE;
+ bitDepth = 8;
+
+ size_t bytePerPixel = GetBytesPerPixel();
+
+ pixelMatrix = (uint8_t**)malloc(sizeof(uint8_t*) * height);
+ for (size_t y = 0; y < height; y++)
+ {
+ pixelMatrix[y] = static_cast(calloc(width * bytePerPixel, sizeof(uint8_t*)));
+ }
+ colorPalette = calloc(paletteSize, sizeof(png_color));
+ alphaPalette = static_cast(calloc(paletteSize, sizeof(uint8_t)));
+
+ hasImageData = true;
+ isColorIndexed = true;
+}
+
+RGBAPixel ImageBackend::GetPixel(size_t y, size_t x) const
+{
+ assert(y < height);
+ assert(x < width);
+ assert(!isColorIndexed);
+
+ RGBAPixel pixel;
+ size_t bytePerPixel = GetBytesPerPixel();
+ pixel.r = pixelMatrix[y][x * bytePerPixel + 0];
+ pixel.g = pixelMatrix[y][x * bytePerPixel + 1];
+ pixel.b = pixelMatrix[y][x * bytePerPixel + 2];
+ if (colorType == PNG_COLOR_TYPE_RGBA)
+ pixel.a = pixelMatrix[y][x * bytePerPixel + 3];
+ return pixel;
+}
+
+uint8_t ImageBackend::GetIndexedPixel(size_t y, size_t x) const
+{
+ assert(y < height);
+ assert(x < width);
+ assert(isColorIndexed);
+
+ return pixelMatrix[y][x];
+}
+
+void ImageBackend::SetRGBPixel(size_t y, size_t x, uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA)
+{
+ assert(hasImageData);
+ assert(y < height);
+ assert(x < width);
+
+ size_t bytePerPixel = GetBytesPerPixel();
+ pixelMatrix[y][x * bytePerPixel + 0] = nR;
+ pixelMatrix[y][x * bytePerPixel + 1] = nG;
+ pixelMatrix[y][x * bytePerPixel + 2] = nB;
+ if (colorType == PNG_COLOR_TYPE_RGBA)
+ pixelMatrix[y][x * bytePerPixel + 3] = nA;
+}
+
+void ImageBackend::SetGrayscalePixel(size_t y, size_t x, uint8_t grayscale, uint8_t alpha)
+{
+ assert(hasImageData);
+ assert(y < height);
+ assert(x < width);
+
+ size_t bytePerPixel = GetBytesPerPixel();
+ pixelMatrix[y][x * bytePerPixel + 0] = grayscale;
+ pixelMatrix[y][x * bytePerPixel + 1] = grayscale;
+ pixelMatrix[y][x * bytePerPixel + 2] = grayscale;
+ if (colorType == PNG_COLOR_TYPE_RGBA)
+ pixelMatrix[y][x * bytePerPixel + 3] = alpha;
+}
+
+void ImageBackend::SetIndexedPixel(size_t y, size_t x, uint8_t index, uint8_t grayscale)
+{
+ assert(hasImageData);
+ assert(y < height);
+ assert(x < width);
+
+ size_t bytePerPixel = GetBytesPerPixel();
+ pixelMatrix[y][x * bytePerPixel + 0] = index;
+
+ assert(index < paletteSize);
+ png_color* pal = static_cast(colorPalette);
+ pal[index].red = grayscale;
+ pal[index].green = grayscale;
+ pal[index].blue = grayscale;
+ alphaPalette[index] = 255;
+}
+
+void ImageBackend::SetPaletteIndex(size_t index, uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA)
+{
+ assert(isColorIndexed);
+ assert(index < paletteSize);
+
+ png_color* pal = static_cast(colorPalette);
+ pal[index].red = nR;
+ pal[index].green = nG;
+ pal[index].blue = nB;
+ alphaPalette[index] = nA;
+}
+
+void ImageBackend::SetPalette(const ImageBackend& pal)
+{
+ assert(isColorIndexed);
+ size_t bytePerPixel = pal.GetBytesPerPixel();
+
+ for (size_t y = 0; y < pal.height; y++)
+ {
+ for (size_t x = 0; x < pal.width; x++)
+ {
+ uint8_t r = pal.pixelMatrix[y][x * bytePerPixel + 0];
+ uint8_t g = pal.pixelMatrix[y][x * bytePerPixel + 1];
+ uint8_t b = pal.pixelMatrix[y][x * bytePerPixel + 2];
+ uint8_t a = pal.pixelMatrix[y][x * bytePerPixel + 3];
+ SetPaletteIndex(y * pal.width + x, r, g, b, a);
+ }
+ }
+}
+
+uint32_t ImageBackend::GetWidth() const
+{
+ return width;
+}
+
+uint32_t ImageBackend::GetHeight() const
+{
+ return height;
+}
+
+uint8_t ImageBackend::GetColorType() const
+{
+ return colorType;
+}
+
+uint8_t ImageBackend::GetBitDepth() const
+{
+ return bitDepth;
+}
+
+double ImageBackend::GetBytesPerPixel() const
+{
+ switch (colorType)
+ {
+ case PNG_COLOR_TYPE_RGBA:
+ return 4 * bitDepth / 8;
+
+ case PNG_COLOR_TYPE_RGB:
+ return 3 * bitDepth / 8;
+
+ case PNG_COLOR_TYPE_PALETTE:
+ return 1 * bitDepth / 8;
+
+ default:
+ throw std::invalid_argument("ImageBackend::GetBytesPerPixel():\n\t Invalid color type.");
+ }
+}
+
+void ImageBackend::FreeImageData()
+{
+ if (hasImageData)
+ {
+ for (size_t y = 0; y < height; y++)
+ free(pixelMatrix[y]);
+ free(pixelMatrix);
+ pixelMatrix = nullptr;
+ }
+
+ if (isColorIndexed)
+ {
+ free(colorPalette);
+ free(alphaPalette);
+ colorPalette = nullptr;
+ alphaPalette = nullptr;
+ isColorIndexed = false;
+ }
+
+ hasImageData = false;
+}
+
+/* RGBAPixel */
+
+void RGBAPixel::SetRGBA(uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA)
+{
+ r = nR;
+ g = nG;
+ b = nB;
+ a = nA;
+}
+
+void RGBAPixel::SetGrayscale(uint8_t grayscale, uint8_t alpha)
+{
+ r = grayscale;
+ g = grayscale;
+ b = grayscale;
+ a = alpha;
+}
diff --git a/tools/ZAPD/ZAPD/ImageBackend.h b/tools/ZAPD/ZAPD/ImageBackend.h
new file mode 100644
index 0000000000..25ab83216f
--- /dev/null
+++ b/tools/ZAPD/ZAPD/ImageBackend.h
@@ -0,0 +1,71 @@
+#pragma once
+
+#include
+#include
+
+#include "Directory.h"
+
+class RGBAPixel
+{
+public:
+ RGBAPixel() = default;
+
+ void SetRGBA(uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA);
+ void SetGrayscale(uint8_t grayscale, uint8_t alpha = 0);
+
+ uint8_t r = 0;
+ uint8_t g = 0;
+ uint8_t b = 0;
+ uint8_t a = 0;
+};
+
+class ImageBackend
+{
+public:
+ ImageBackend() = default;
+ ~ImageBackend();
+
+ void ReadPng(const char* filename);
+ void ReadPng(const fs::path& filename);
+ void WritePng(const char* filename);
+ void WritePng(const fs::path& filename);
+
+ void SetTextureData(const std::vector>& texData, uint32_t nWidth,
+ uint32_t nHeight, uint8_t nColorType, uint8_t nBitDepth);
+ void InitEmptyRGBImage(uint32_t nWidth, uint32_t nHeight, bool alpha);
+ void InitEmptyPaletteImage(uint32_t nWidth, uint32_t nHeight);
+
+ RGBAPixel GetPixel(size_t y, size_t x) const;
+ uint8_t GetIndexedPixel(size_t y, size_t x) const;
+
+ void SetRGBPixel(size_t y, size_t x, uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA = 0);
+ void SetGrayscalePixel(size_t y, size_t x, uint8_t grayscale, uint8_t alpha = 0);
+
+ void SetIndexedPixel(size_t y, size_t x, uint8_t index, uint8_t grayscale);
+ void SetPaletteIndex(size_t index, uint8_t nR, uint8_t nG, uint8_t nB, uint8_t nA);
+ void SetPalette(const ImageBackend& pal);
+
+ uint32_t GetWidth() const;
+ uint32_t GetHeight() const;
+ uint8_t GetColorType() const;
+ uint8_t GetBitDepth() const;
+
+protected:
+ uint8_t** pixelMatrix = nullptr; // height * [width * bytePerPixel]
+
+ void* colorPalette = nullptr;
+ uint8_t* alphaPalette = nullptr;
+ size_t paletteSize = 16 * 16;
+
+ uint32_t width = 0;
+ uint32_t height = 0;
+ uint8_t colorType = 0;
+ uint8_t bitDepth = 0;
+
+ bool hasImageData = false;
+ bool isColorIndexed = false;
+
+ double GetBytesPerPixel() const;
+
+ void FreeImageData();
+};
diff --git a/tools/ZAPD/ZAPD/Main.cpp b/tools/ZAPD/ZAPD/Main.cpp
index a1dfb2155c..21c7c036ef 100644
--- a/tools/ZAPD/ZAPD/Main.cpp
+++ b/tools/ZAPD/ZAPD/Main.cpp
@@ -14,9 +14,11 @@
#if !defined(_MSC_VER) && !defined(__CYGWIN__)
#include
+#include
#include // for __cxa_demangle
#include // for dladdr
#include
+#include
#include
#endif
@@ -24,7 +26,6 @@
#include "tinyxml2.h"
using namespace tinyxml2;
-using namespace std;
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
ZFileMode fileMode);
@@ -36,6 +37,7 @@ void BuildAssetModelIntermediette(const fs::path& outPath);
void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath);
#if !defined(_MSC_VER) && !defined(__CYGWIN__)
+#define ARRAY_COUNT(arr) (sizeof(arr) / sizeof(arr[0]))
void ErrorHandler(int sig)
{
void* array[4096];
@@ -43,14 +45,24 @@ void ErrorHandler(int sig)
size_t size = backtrace(array, nMaxFrames);
char** symbols = backtrace_symbols(array, nMaxFrames);
- // To prevent unused parameter warning
- (void)sig;
+ fprintf(stderr, "\nZAPD crashed. (Signal: %i)\n", sig);
+ const char* crashEasterEgg[] = {
+ "\tYou've met with a terrible fate, haven't you?",
+ "\tSEA BEARS FOAM. SLEEP BEARS DREAMS. \n\tBOTH END IN THE SAME WAY: CRASSSH!",
+ };
+
+ srand(time(nullptr));
+ auto easterIndex = rand() % ARRAY_COUNT(crashEasterEgg);
+
+ fprintf(stderr, "\n%s\n\n", crashEasterEgg[easterIndex]);
+
+ fprintf(stderr, "Traceback:\n");
for (size_t i = 1; i < size; i++)
{
Dl_info info;
uint32_t gotAddress = dladdr(array[i], &info);
- string functionName(symbols[i]);
+ std::string functionName(symbols[i]);
if (gotAddress != 0 && info.dli_sname != nullptr)
{
@@ -71,7 +83,8 @@ void ErrorHandler(int sig)
fprintf(stderr, "%-3zd %s\n", i, functionName.c_str());
}
- // backtrace_symbols_fd(array, size, STDERR_FILENO);
+ fprintf(stderr, "\n");
+
free(symbols);
exit(1);
}
@@ -90,7 +103,7 @@ int main(int argc, char* argv[])
Globals* g = new Globals();
// Parse File Mode
- string buildMode = argv[1];
+ std::string buildMode = argv[1];
ZFileMode fileMode = ZFileMode::Invalid;
if (buildMode == "btex")
@@ -119,7 +132,7 @@ int main(int argc, char* argv[])
// Parse other "commands"
for (int32_t i = 2; i < argc; i++)
{
- string arg = argv[i];
+ std::string arg = argv[i];
if (arg == "-o" || arg == "--outputpath") // Set output path
{
@@ -147,34 +160,34 @@ int main(int argc, char* argv[])
}
else if (arg == "-gsf") // Generate source file during extraction
{
- Globals::Instance->genSourceFile = string(argv[i + 1]) == "1";
- i++;
- }
- else if (arg == "-ifp") // Include file prefix in generated symbols
- {
- Globals::Instance->includeFilePrefix = string(argv[i + 1]) == "1";
+ Globals::Instance->genSourceFile = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-tm") // Test Mode (enables certain experimental features)
{
- Globals::Instance->testMode = string(argv[i + 1]) == "1";
+ Globals::Instance->testMode = std::string(argv[i + 1]) == "1";
i++;
}
+ else if (arg == "-crc" ||
+ arg == "--output-crc") // Outputs a CRC file for each extracted texture.
+ {
+ Globals::Instance->outputCrc = true;
+ }
else if (arg == "-ulzdl") // Use Legacy ZDisplay List
{
- Globals::Instance->useLegacyZDList = string(argv[i + 1]) == "1";
+ Globals::Instance->useLegacyZDList = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-profile") // Enable profiling
{
- Globals::Instance->profile = string(argv[i + 1]) == "1";
+ Globals::Instance->profile = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg ==
"-uer") // Split resources into their individual components (enabled by default)
// TODO: We may wish to make this a part of the config file...
{
- Globals::Instance->useExternalResources = string(argv[i + 1]) == "1";
+ Globals::Instance->useExternalResources = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-tt") // Set texture type
@@ -182,8 +195,9 @@ int main(int argc, char* argv[])
Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[i + 1]);
i++;
}
- else if (arg == "-cfg") // Set cfg path (for overlays)
- // TODO: Change the name of this to something else so it doesn't get confused with XML config files.
+ else if (arg == "-cfg") // Set cfg path (for overlays)
+ // TODO: Change the name of this to something else so it doesn't
+ // get confused with XML config files.
{
Globals::Instance->cfgPath = argv[i + 1];
i++;
@@ -199,12 +213,13 @@ int main(int argc, char* argv[])
signal(SIGSEGV, ErrorHandler);
signal(SIGABRT, ErrorHandler);
#else
- printf("Warning: Tried to set error handler, but this build lacks support for one.\n");
+ fprintf(stderr,
+ "Warning: Tried to set error handler, but this build lacks support for one.\n");
#endif
}
else if (arg == "-v") // Verbose
{
- Globals::Instance->verbosity = (VerbosityLevel)strtol(argv[++i], NULL, 16);
+ Globals::Instance->verbosity = static_cast(strtol(argv[++i], NULL, 16));
}
else if (arg == "-wu" || arg == "--warn-unaccounted") // Warn unaccounted
{
@@ -212,57 +227,50 @@ int main(int argc, char* argv[])
}
}
- if (Globals::Instance->verbosity >= VERBOSITY_INFO)
+ if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
printf("ZAPD: Zelda Asset Processor For Decomp: %s\n", gBuildHash);
- try
+ if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
{
- if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
- {
- bool parseSuccessful =
- Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath,
- Globals::Instance->outputPath, fileMode);
+ bool parseSuccessful = Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath,
+ Globals::Instance->outputPath, fileMode);
- if (!parseSuccessful)
- return 1;
- }
- else if (fileMode == ZFileMode::BuildTexture)
- {
- TextureType texType = Globals::Instance->texType;
-
- BuildAssetTexture(Globals::Instance->inputPath, texType, Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildBackground)
- {
- BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildBlob)
- {
- BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildModelIntermediette)
- {
- BuildAssetModelIntermediette(Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildAnimationIntermediette)
- {
- BuildAssetAnimationIntermediette(Globals::Instance->inputPath,
- Globals::Instance->outputPath);
- }
- else if (fileMode == ZFileMode::BuildOverlay)
- {
- ZOverlay* overlay =
- ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath),
- Path::GetDirectoryName(Globals::Instance->cfgPath));
-
- if (overlay)
- File::WriteAllText(Globals::Instance->outputPath, overlay->GetSourceOutputCode(""));
- }
+ if (!parseSuccessful)
+ return 1;
}
- catch (std::runtime_error& e)
+ else if (fileMode == ZFileMode::BuildTexture)
{
- printf("Exception occurred: %s\n", e.what());
+ TextureType texType = Globals::Instance->texType;
+ BuildAssetTexture(Globals::Instance->inputPath, texType, Globals::Instance->outputPath);
}
+ else if (fileMode == ZFileMode::BuildBackground)
+ {
+ BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath);
+ }
+ else if (fileMode == ZFileMode::BuildBlob)
+ {
+ BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath);
+ }
+ else if (fileMode == ZFileMode::BuildModelIntermediette)
+ {
+ BuildAssetModelIntermediette(Globals::Instance->outputPath);
+ }
+ else if (fileMode == ZFileMode::BuildAnimationIntermediette)
+ {
+ BuildAssetAnimationIntermediette(Globals::Instance->inputPath,
+ Globals::Instance->outputPath);
+ }
+ else if (fileMode == ZFileMode::BuildOverlay)
+ {
+ ZOverlay* overlay =
+ ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath),
+ Path::GetDirectoryName(Globals::Instance->cfgPath));
+
+ if (overlay)
+ File::WriteAllText(Globals::Instance->outputPath.string(),
+ overlay->GetSourceOutputCode(""));
+ }
+
delete g;
return 0;
}
@@ -271,7 +279,7 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
ZFileMode fileMode)
{
XMLDocument doc;
- XMLError eResult = doc.LoadFile(xmlFilePath.c_str());
+ XMLError eResult = doc.LoadFile(xmlFilePath.string().c_str());
if (eResult != tinyxml2::XML_SUCCESS)
{
@@ -290,7 +298,7 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
- if (string(child->Name()) == "File")
+ if (std::string(child->Name()) == "File")
{
ZFile* file = new ZFile(fileMode, child, basePath, outPath, "", xmlFilePath, false);
Globals::Instance->files.push_back(file);
@@ -323,37 +331,36 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath)
{
- string name = outPath.stem();
+ std::string name = outPath.stem().string();
- ZTexture* tex = ZTexture::FromPNG(pngFilePath, texType);
- string cfgPath = StringHelper::Split(pngFilePath, ".")[0] + ".cfg";
+ ZTexture tex(nullptr);
+ tex.FromPNG(pngFilePath, texType);
+ std::string cfgPath = StringHelper::Split(pngFilePath.string(), ".")[0] + ".cfg";
if (File::Exists(cfgPath))
name = File::ReadAllText(cfgPath);
- string src = tex->GetSourceOutputCode(name);
+ std::string src = tex.GetBodySourceCode();
- File::WriteAllText(outPath, src);
-
- delete tex;
+ File::WriteAllText(outPath.string(), src);
}
void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath)
{
ZBackground background(nullptr);
- background.ParseBinaryFile(imageFilePath, false);
+ background.ParseBinaryFile(imageFilePath.string(), false);
- File::WriteAllText(outPath, background.GetBodySourceCode());
+ File::WriteAllText(outPath.string(), background.GetBodySourceCode());
}
void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath)
{
- ZBlob* blob = ZBlob::FromFile(blobFilePath);
- string name = outPath.stem(); // filename without extension
+ ZBlob* blob = ZBlob::FromFile(blobFilePath.string());
+ std::string name = outPath.stem().string(); // filename without extension
- string src = blob->GetSourceOutputCode(name);
+ std::string src = blob->GetSourceOutputCode(name);
- File::WriteAllText(outPath, src);
+ File::WriteAllText(outPath.string(), src);
delete blob;
}
@@ -363,30 +370,30 @@ void BuildAssetModelIntermediette(const fs::path& outPath)
XMLDocument doc;
HLModelIntermediette* mdl = HLModelIntermediette::FromXML(doc.RootElement());
- string output = mdl->OutputCode();
+ std::string output = mdl->OutputCode();
- File::WriteAllText(outPath, output);
+ File::WriteAllText(outPath.string(), output);
delete mdl;
}
void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath)
{
- vector split = StringHelper::Split(outPath, "/");
+ std::vector split = StringHelper::Split(outPath.string(), "/");
ZFile* file = new ZFile("", split[split.size() - 2]);
- HLAnimationIntermediette* anim = HLAnimationIntermediette::FromXML(animPath);
+ HLAnimationIntermediette* anim = HLAnimationIntermediette::FromXML(animPath.string());
ZAnimation* zAnim = anim->ToZAnimation();
zAnim->SetName(Path::GetFileNameWithoutExtension(split[split.size() - 1]));
zAnim->parent = file;
zAnim->GetSourceOutputCode(split[split.size() - 2]);
- string output = "";
+ std::string output = "";
output += file->declarations[2]->text + "\n";
output += file->declarations[1]->text + "\n";
output += file->declarations[0]->text + "\n";
- File::WriteAllText(outPath, output);
+ File::WriteAllText(outPath.string(), output);
delete zAnim;
delete file;
diff --git a/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp b/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp
index d5969f7c04..a30d89ff5c 100644
--- a/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp
+++ b/tools/ZAPD/ZAPD/Overlays/ZOverlay.cpp
@@ -4,16 +4,15 @@
#include "../Path.h"
#include "../StringHelper.h"
-using namespace std;
using namespace ELFIO;
ZOverlay::ZOverlay()
{
name = "";
- entries = vector();
+ entries = std::vector();
}
-ZOverlay::ZOverlay(string nName) : ZOverlay()
+ZOverlay::ZOverlay(std::string nName) : ZOverlay()
{
name = nName;
}
@@ -26,26 +25,27 @@ ZOverlay::~ZOverlay()
entries.clear();
}
-ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
+ZOverlay* ZOverlay::FromBuild(std::string buildPath, std::string cfgFolderPath)
{
- string cfgText = File::ReadAllText(cfgFolderPath + "/overlay.cfg");
- vector cfgLines = StringHelper::Split(cfgText, "\n");
+ std::string cfgText = File::ReadAllText(cfgFolderPath + "/overlay.cfg");
+ std::vector cfgLines = StringHelper::Split(cfgText, "\n");
ZOverlay* ovl = new ZOverlay(StringHelper::Strip(cfgLines[0], "\r"));
- vector relSections = {".rel.text", ".rel.data", ".rel.rodata"};
- vector sections = {".text", ".data", ".rodata"};
+ std::vector relSections = {".rel.text", ".rel.data", ".rel.rodata"};
+ std::vector sections = {".text", ".data", ".rodata"};
int32_t sectionOffs[5] = {0};
- vector textRelocs;
- vector dataRelocs;
- vector rodataRelocs;
+ std::vector textRelocs;
+ std::vector dataRelocs;
+ std::vector rodataRelocs;
// get the elf files
- vector readers;
+ std::vector readers;
for (size_t i = 1; i < cfgLines.size(); i++)
{
- string elfPath = buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o";
+ std::string elfPath =
+ buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o";
elfio* reader = new elfio();
if (!reader->load(elfPath))
@@ -88,7 +88,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
relocs.get_entry(j, offset, symbol, type, addend);
}
- string curSymName;
+ std::string curSymName;
Elf_Half curSymShndx = SHN_UNDEF;
{
symbol_section_accessor symbols(
@@ -124,7 +124,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
{
Elf_Half shndx = SHN_UNDEF;
Elf64_Addr value;
- string name;
+ std::string name;
Elf_Xword size;
unsigned char bind;
unsigned char type;
@@ -189,9 +189,9 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
return ovl;
}
-string ZOverlay::GetSourceOutputCode(const std::string& prefix)
+std::string ZOverlay::GetSourceOutputCode(const std::string& prefix)
{
- string output = "";
+ std::string output = "";
output += ".section .ovl\n";
@@ -220,7 +220,7 @@ string ZOverlay::GetSourceOutputCode(const std::string& prefix)
return output;
}
-SectionType ZOverlay::GetSectionTypeFromStr(string sectionName)
+SectionType ZOverlay::GetSectionTypeFromStr(std::string sectionName)
{
if (sectionName == ".rel.text" || sectionName == ".text")
return SectionType::Text;
diff --git a/tools/ZAPD/ZAPD/Overlays/ZOverlay.h b/tools/ZAPD/ZAPD/Overlays/ZOverlay.h
index f43023092a..08e573de14 100644
--- a/tools/ZAPD/ZAPD/Overlays/ZOverlay.h
+++ b/tools/ZAPD/ZAPD/Overlays/ZOverlay.h
@@ -1,8 +1,8 @@
#pragma once
#include
-#include
#include "../ZResource.h"
+#include "tinyxml2.h"
enum SectionType
{
diff --git a/tools/ZAPD/ZAPD/Path.h b/tools/ZAPD/ZAPD/Path.h
index a5c073c039..68cfaea4bc 100644
--- a/tools/ZAPD/ZAPD/Path.h
+++ b/tools/ZAPD/ZAPD/Path.h
@@ -46,8 +46,8 @@ public:
return output;
};
- static std::string GetDirectoryName(const std::string& path)
+ static std::string GetDirectoryName(const fs::path& path)
{
- return fs::path(path).parent_path().u8string();
+ return path.parent_path().u8string();
};
};
diff --git a/tools/ZAPD/ZAPD/StringHelper.h b/tools/ZAPD/ZAPD/StringHelper.h
index 3d63a749bc..b07a99f0e4 100644
--- a/tools/ZAPD/ZAPD/StringHelper.h
+++ b/tools/ZAPD/ZAPD/StringHelper.h
@@ -1,10 +1,11 @@
#pragma once
+#include
#include
#include
-#include
#include
#include
+#include
class StringHelper
{
@@ -66,7 +67,7 @@ public:
static bool EndsWith(const std::string& s, const std::string& input)
{
- int32_t inputLen = strlen(input.c_str());
+ size_t inputLen = strlen(input.c_str());
return s.rfind(input) == (s.size() - inputLen);
}
@@ -92,4 +93,16 @@ public:
return ss.empty() ? s : ss + separator + s;
});
}
+
+ static int64_t StrToL(const std::string& str, int32_t base = 10)
+ {
+ return std::strtoull(str.c_str(), nullptr, base);
+ }
+
+ static std::string BoolStr(bool b) { return b ? "true" : "false"; }
+
+ static bool HasOnlyDigits(const std::string &str)
+ {
+ return std::all_of(str.begin(), str.end(), ::isdigit);
+ }
};
diff --git a/tools/ZAPD/ZAPD/ZAnimation.cpp b/tools/ZAPD/ZAPD/ZAnimation.cpp
index 2eaeee2378..5f9f93472b 100644
--- a/tools/ZAPD/ZAPD/ZAnimation.cpp
+++ b/tools/ZAPD/ZAPD/ZAnimation.cpp
@@ -7,8 +7,6 @@
#include "StringHelper.h"
#include "ZFile.h"
-using namespace std;
-
REGISTER_ZFILENODE(Animation, ZNormalAnimation);
REGISTER_ZFILENODE(PlayerAnimation, ZLinkAnimation);
REGISTER_ZFILENODE(CurveAnimation, ZCurveAnimation);
@@ -26,37 +24,32 @@ void ZAnimation::ParseRawData()
frameCount = BitConverter::ToInt16BE(data, rawDataIndex + 0);
}
-void ZAnimation::Save(const std::string& outFolder)
+void ZAnimation::Save(const fs::path& outFolder)
{
if (Globals::Instance->testMode)
{
HLAnimationIntermediette* anim = HLAnimationIntermediette::FromZAnimation(this);
- string xml = anim->OutputXML();
- File::WriteAllText(outFolder + "/" + name + ".anmi", xml);
+ std::string xml = anim->OutputXML();
+ File::WriteAllText(outFolder / (name + ".anmi"), xml);
delete anim;
}
}
-void ZAnimation::ParseXML(tinyxml2::XMLElement* reader)
-{
- ZResource::ParseXML(reader);
-}
-
-string ZAnimation::GetSourceOutputCode(const std::string& prefix)
+std::string ZAnimation::GetSourceOutputCode(const std::string& prefix)
{
return "";
}
-ZResourceType ZAnimation::GetResourceType()
+ZResourceType ZAnimation::GetResourceType() const
{
return ZResourceType::Animation;
}
ZNormalAnimation::ZNormalAnimation(ZFile* nParent) : ZAnimation(nParent)
{
- rotationValues = vector();
- rotationIndices = vector();
+ rotationValues = std::vector();
+ rotationIndices = std::vector();
limit = 0;
}
@@ -64,10 +57,10 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
{
- string defaultPrefix = name.c_str();
+ std::string defaultPrefix = name.c_str();
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
- string headerStr = StringHelper::Sprintf("\n\t{ %i },\n", frameCount);
+ std::string headerStr = StringHelper::Sprintf("\n\t{ %i },\n", frameCount);
headerStr += StringHelper::Sprintf("\t%sFrameData,\n", defaultPrefix.c_str());
headerStr += StringHelper::Sprintf("\t%sJointIndices,\n", defaultPrefix.c_str());
headerStr += StringHelper::Sprintf("\t%i\n", limit);
@@ -75,8 +68,8 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
GetSourceTypeName(), StringHelper::Sprintf("%s", name.c_str()),
headerStr);
- string indicesStr = "";
- string valuesStr = " ";
+ std::string indicesStr = "";
+ std::string valuesStr = " ";
const uint8_t lineLength = 14;
const uint8_t offset = 0;
@@ -112,26 +105,16 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
return "";
}
-size_t ZNormalAnimation::GetRawDataSize()
+size_t ZNormalAnimation::GetRawDataSize() const
{
return 16;
}
-std::string ZNormalAnimation::GetSourceTypeName()
+std::string ZNormalAnimation::GetSourceTypeName() const
{
return "AnimationHeader";
}
-void ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
- const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath)
-{
- rawData = std::move(nRawData);
- rawDataIndex = nRawDataIndex;
- ParseXML(reader);
- ParseRawData();
-}
-
void ZNormalAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
@@ -172,12 +155,13 @@ std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
{
- string segSymbol = segmentAddress == 0 ?
- "NULL" :
- parent->GetDeclarationName(
- segmentAddress, StringHelper::Sprintf("%sSeg%06X", name.c_str(),
- segmentAddress));
- string headerStr =
+ std::string segSymbol =
+ segmentAddress == 0 ?
+ "NULL" :
+ parent->GetDeclarationName(
+ segmentAddress,
+ StringHelper::Sprintf("%sSeg%06X", name.c_str(), segmentAddress));
+ std::string headerStr =
StringHelper::Sprintf("\n\t{ %i },\n\t0x%08X\n", frameCount, segmentAddress);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), StringHelper::Sprintf("%s", name.c_str()),
@@ -187,26 +171,16 @@ std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix)
return "";
}
-size_t ZLinkAnimation::GetRawDataSize()
+size_t ZLinkAnimation::GetRawDataSize() const
{
return 8;
}
-std::string ZLinkAnimation::GetSourceTypeName()
+std::string ZLinkAnimation::GetSourceTypeName() const
{
return "LinkAnimationHeader";
}
-void ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
- const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath)
-{
- rawData = std::move(nRawData);
- rawDataIndex = nRawDataIndex;
- ParseXML(reader);
- ParseRawData();
-}
-
void ZLinkAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
@@ -240,7 +214,7 @@ std::string TransformData::GetBody(const std::string& prefix) const
unk_08);
}
-size_t TransformData::GetRawDataSize()
+size_t TransformData::GetRawDataSize() const
{
return 0x0C;
}
@@ -252,26 +226,23 @@ std::string TransformData::GetSourceTypeName()
ZCurveAnimation::ZCurveAnimation(ZFile* nParent) : ZAnimation(nParent)
{
-}
-
-ZCurveAnimation::~ZCurveAnimation()
-{
- delete skel;
+ RegisterOptionalAttribute("SkelOffset");
}
void ZCurveAnimation::ParseXML(tinyxml2::XMLElement* reader)
{
ZAnimation::ParseXML(reader);
- const char* skelOffsetXml = reader->Attribute("SkelOffset");
- if (skelOffsetXml == nullptr)
+ std::string skelOffsetXml = registeredAttributes.at("SkelOffset").value;
+ if (skelOffsetXml == "")
{
- throw std::runtime_error(StringHelper::Sprintf(
- "ZCurveAnimation::ParseXML: Fatal error in '%s'. Missing 'SkelOffset' attribute in "
- "ZCurveAnimation. You need to provide the offset of the curve skeleton.",
- name.c_str()));
+ throw std::runtime_error(
+ StringHelper::Sprintf("ZCurveAnimation::ParseXML: Fatal error in '%s'.\n"
+ "\t Missing 'SkelOffset' attribute in ZCurveAnimation.\n"
+ "\t You need to provide the offset of the curve skeleton.",
+ name.c_str()));
}
- skelOffset = std::strtoul(skelOffsetXml, nullptr, 0);
+ skelOffset = StringHelper::StrToL(skelOffsetXml, 0);
}
void ZCurveAnimation::ParseRawData()
@@ -283,25 +254,18 @@ void ZCurveAnimation::ParseRawData()
copyValues = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
unk_0C = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
unk_10 = BitConverter::ToInt16BE(rawData, rawDataIndex + 14);
-}
-void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
- const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath)
-{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
-
- skel = new ZSkeleton(ZSkeletonType::Curve, ZLimbType::Curve, "CurveAnim", nRawData,
- Seg2Filespace(skelOffset, parent->baseAddress), parent);
+ limbCount =
+ BitConverter::ToUInt8BE(rawData, Seg2Filespace(skelOffset, parent->baseAddress) + 4);
size_t transformDataSize = 0;
size_t copyValuesSize = 0;
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
- for (size_t i = 0; i < 3 * 3 * skel->GetLimbCount(); i++)
+ for (size_t i = 0; i < 3 * 3 * limbCount; i++)
{
- uint8_t ref = BitConverter::ToUInt8BE(nRawData, refIndexOffset + i);
+ uint8_t ref = BitConverter::ToUInt8BE(rawData, refIndexOffset + i);
if (ref == 0)
copyValuesSize++;
else
@@ -316,7 +280,7 @@ void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
for (size_t i = 0; i < transformDataSize; i++)
- transformDataArr.emplace_back(parent, nRawData, transformDataOffset, i);
+ transformDataArr.emplace_back(parent, rawData, transformDataOffset, i);
}
if (copyValues != 0)
@@ -324,28 +288,28 @@ void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
for (size_t i = 0; i < copyValuesSize; i++)
- copyValuesArr.emplace_back(BitConverter::ToInt16BE(nRawData, copyValuesOffset + i * 2));
+ copyValuesArr.emplace_back(BitConverter::ToInt16BE(rawData, copyValuesOffset + i * 2));
}
+}
+
+void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
+ const std::vector& nRawData, uint32_t nRawDataIndex)
+{
+ ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(),
GetSourceTypeName(), name, "");
}
-void ZCurveAnimation::PreGenValues(const std::string& prefix)
+void ZCurveAnimation::DeclareReferences(const std::string& prefix)
{
- Declaration* decl = parent->GetDeclaration(skelOffset);
- if (decl == nullptr)
- {
- skel->GetSourceOutputCode(prefix);
- }
-
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
- string refIndexStr =
+ std::string refIndexStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", refIndexOffset);
- string entryStr = " ";
+ std::string entryStr = " ";
uint16_t arrayItemCnt = refIndexArr.size();
size_t i = 0;
@@ -370,11 +334,11 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix)
if (transformData != 0)
{
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
- string transformDataStr =
- StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(),
- TransformData::GetSourceTypeName().c_str(), transformDataOffset);
+ std::string transformDataStr = StringHelper::Sprintf(
+ "%sCurveAnime_%s_%06X", prefix.c_str(),
+ transformDataArr.at(0).GetSourceTypeName().c_str(), transformDataOffset);
- string entryStr = "";
+ std::string entryStr = "";
uint16_t arrayItemCnt = transformDataArr.size();
size_t i = 0;
@@ -388,9 +352,9 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix)
if (decl == nullptr)
{
parent->AddDeclarationArray(transformDataOffset, DeclarationAlignment::None,
- arrayItemCnt * TransformData::GetRawDataSize(),
- TransformData::GetSourceTypeName(), transformDataStr,
- arrayItemCnt, entryStr);
+ arrayItemCnt * transformDataArr.at(0).GetRawDataSize(),
+ transformDataArr.at(0).GetSourceTypeName(),
+ transformDataStr, arrayItemCnt, entryStr);
}
else
{
@@ -401,10 +365,10 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix)
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
- string copyValuesStr =
+ std::string copyValuesStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", copyValuesOffset);
- string entryStr = " ";
+ std::string entryStr = " ";
uint16_t arrayItemCnt = copyValuesArr.size();
size_t i = 0;
@@ -427,19 +391,17 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix)
}
}
-size_t ZCurveAnimation::GetRawDataSize()
+size_t ZCurveAnimation::GetRawDataSize() const
{
return 0x10;
}
std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
{
- string bodyStr = "";
+ std::string bodyStr = "";
uint32_t address = Seg2Filespace(rawDataIndex, parent->baseAddress);
- PreGenValues(prefix);
-
- string refIndexStr = "NULL";
+ std::string refIndexStr = "NULL";
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
@@ -455,16 +417,16 @@ std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
}
}
- string transformDataStr = "NULL";
+ std::string transformDataStr = "NULL";
if (transformData != 0)
{
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(transformDataOffset);
if (decl == nullptr)
{
- transformDataStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(),
- TransformData::GetSourceTypeName().c_str(),
- transformDataOffset);
+ transformDataStr = StringHelper::Sprintf(
+ "%sCurveAnime_%s_%06X", prefix.c_str(),
+ transformDataArr.at(0).GetSourceTypeName().c_str(), transformDataOffset);
}
else
{
@@ -472,7 +434,7 @@ std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
}
}
- string copyValuesStr = "NULL";
+ std::string copyValuesStr = "NULL";
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
@@ -506,7 +468,7 @@ std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
return "";
}
-std::string ZCurveAnimation::GetSourceTypeName()
+std::string ZCurveAnimation::GetSourceTypeName() const
{
return "TransformUpdateIndex";
}
diff --git a/tools/ZAPD/ZAPD/ZAnimation.h b/tools/ZAPD/ZAPD/ZAnimation.h
index e6dc1e23f3..2d23dddf4b 100644
--- a/tools/ZAPD/ZAPD/ZAnimation.h
+++ b/tools/ZAPD/ZAPD/ZAnimation.h
@@ -29,12 +29,11 @@ public:
ZAnimation(ZFile* nParent);
std::string GetSourceOutputCode(const std::string& prefix) override;
- ZResourceType GetResourceType() override;
+ ZResourceType GetResourceType() const override;
protected:
void ParseRawData() override;
- void Save(const std::string& outFolder) override;
- void ParseXML(tinyxml2::XMLElement* reader) override;
+ void Save(const fs::path& outFolder) override;
};
class ZNormalAnimation : public ZAnimation
@@ -49,11 +48,8 @@ public:
ZNormalAnimation(ZFile* nParent);
std::string GetSourceOutputCode(const std::string& prefix) override;
- size_t GetRawDataSize() override;
- std::string GetSourceTypeName() override;
-
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath) override;
+ size_t GetRawDataSize() const override;
+ std::string GetSourceTypeName() const override;
protected:
virtual void ParseRawData() override;
@@ -67,11 +63,8 @@ public:
ZLinkAnimation(ZFile* nParent);
std::string GetSourceOutputCode(const std::string& prefix) override;
- size_t GetRawDataSize() override;
- std::string GetSourceTypeName() override;
-
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath) override;
+ size_t GetRawDataSize() const override;
+ std::string GetSourceTypeName() const override;
protected:
virtual void ParseRawData() override;
@@ -101,8 +94,8 @@ public:
[[nodiscard]] std::string GetBody(const std::string& prefix) const;
- static size_t GetRawDataSize();
- static std::string GetSourceTypeName();
+ size_t GetRawDataSize() const;
+ std::string GetSourceTypeName();
};
class ZCurveAnimation : public ZAnimation
@@ -121,7 +114,7 @@ protected:
///* 0x000E */ s16 unk_10;
int16_t unk_10;
- ZSkeleton* skel;
+ uint8_t limbCount = 0;
std::vector refIndexArr;
std::vector transformDataArr;
@@ -130,16 +123,16 @@ protected:
public:
ZCurveAnimation();
ZCurveAnimation(ZFile* nParent);
- ~ZCurveAnimation();
+
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath) override;
+ const uint32_t nRawDataIndex) override;
- void PreGenValues(const std::string& prefix);
- size_t GetRawDataSize() override;
+ void DeclareReferences(const std::string& prefix) override;
+ size_t GetRawDataSize() const override;
std::string GetSourceOutputCode(const std::string& prefix) override;
- std::string GetSourceTypeName() override;
+ std::string GetSourceTypeName() const override;
};
// TransformUpdateIndex
diff --git a/tools/ZAPD/ZAPD/ZArray.cpp b/tools/ZAPD/ZAPD/ZArray.cpp
index ac9561b21a..3194eac2d7 100644
--- a/tools/ZAPD/ZAPD/ZArray.cpp
+++ b/tools/ZAPD/ZAPD/ZArray.cpp
@@ -1,4 +1,5 @@
#include "ZArray.h"
+#include
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
@@ -8,49 +9,57 @@ REGISTER_ZFILENODE(Array, ZArray);
ZArray::ZArray(ZFile* nParent) : ZResource(nParent)
{
canHaveInner = true;
+ RegisterRequiredAttribute("Count");
}
ZArray::~ZArray()
{
- delete testFile;
+ for (auto res : resList)
+ delete res;
}
void ZArray::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
- arrayCnt = reader->IntAttribute("Count", 0);
- testFile = new ZFile(ZFileMode::Extract, reader, Globals::Instance->baseRomPath, "",
- parent->GetName(), "ZArray subfile", true);
+ arrayCnt = StringHelper::StrToL(registeredAttributes.at("Count").value, 0);
+ // TODO: do a better check.
+ assert(arrayCnt > 0);
+
+ tinyxml2::XMLElement* child = reader->FirstChildElement();
+ if (child == nullptr)
+ throw std::runtime_error(
+ StringHelper::Sprintf("Error! Array needs at least one sub-element.\n"));
+
+ childName = child->Name();
+
+ auto nodeMap = ZFile::GetNodeMap();
+ size_t childIndex = rawDataIndex;
+ for (size_t i = 0; i < arrayCnt; i++)
+ {
+ ZResource* res = nodeMap->at(childName)(parent);
+ if (!res->DoesSupportArray())
+ {
+ throw std::runtime_error(StringHelper::Sprintf(
+ "Error! Resource %s does not support being wrapped in an array!\n",
+ childName.c_str()));
+ }
+ res->parent = parent;
+ res->SetInnerNode(true);
+ res->ExtractFromXML(child, rawData, childIndex);
+
+ childIndex += res->GetRawDataSize();
+ resList.push_back(res);
+ }
}
-// TODO: This is a bit hacky, but until we refactor how ZFile parses the XML, it'll have to do.
std::string ZArray::GetSourceOutputCode(const std::string& prefix)
{
std::string output = "";
- if (testFile->resources.size() <= 0)
- throw std::runtime_error(
- StringHelper::Sprintf("Error! Array needs at least one sub-element.\n"));
-
- ZResource* res = testFile->resources[0];
- size_t resSize = res->GetRawDataSize();
-
- if (!res->DoesSupportArray())
- {
- throw std::runtime_error(StringHelper::Sprintf(
- "Error! Resource %s does not support being wrapped in an array!\n",
- res->GetName().c_str()));
- }
-
for (size_t i = 0; i < arrayCnt; i++)
{
- size_t childIndex = rawDataIndex + (i * resSize);
- res->SetRawDataIndex(childIndex);
- res->ParseRawData();
- std::string test = res->GetSourceOutputCode("");
- // output += " { " + testFile->declarations[childIndex]->text + " }";
- output += testFile->declarations[childIndex]->text;
+ output += resList.at(i)->GetBodySourceCode();
if (i < arrayCnt - 1)
output += ",\n";
@@ -58,21 +67,20 @@ std::string ZArray::GetSourceOutputCode(const std::string& prefix)
if (parent != nullptr)
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
- res->GetSourceTypeName(), name, arrayCnt, output);
+ resList.at(0)->GetSourceTypeName(), name, arrayCnt, output);
return "";
}
-size_t ZArray::GetRawDataSize()
+size_t ZArray::GetRawDataSize() const
{
- return arrayCnt * testFile->resources[0]->GetRawDataSize();
+ size_t size = 0;
+ for (auto res : resList)
+ size += res->GetRawDataSize();
+ return size;
}
-void ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath)
+ZResourceType ZArray::GetResourceType() const
{
- rawData = nRawData;
- rawDataIndex = nRawDataIndex;
- ParseXML(reader);
- // arr->ParseRawData();
+ return ZResourceType::Array;
}
diff --git a/tools/ZAPD/ZAPD/ZArray.h b/tools/ZAPD/ZAPD/ZArray.h
index ebad2a4bb2..f43dc1242e 100644
--- a/tools/ZAPD/ZAPD/ZArray.h
+++ b/tools/ZAPD/ZAPD/ZArray.h
@@ -13,15 +13,14 @@ public:
~ZArray();
void ParseXML(tinyxml2::XMLElement* reader) override;
- std::string GetSourceOutputCode(const std::string& prefix) override;
- size_t GetRawDataSize() override;
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath) override;
+ std::string GetSourceOutputCode(const std::string& prefix) override;
+ size_t GetRawDataSize() const override;
+
+ ZResourceType GetResourceType() const override;
protected:
size_t arrayCnt;
- ZFile* testFile;
-
- // void ParseRawData(const std::vector& data, const int32_t offset);
-};
\ No newline at end of file
+ std::string childName;
+ std::vector resList;
+};
diff --git a/tools/ZAPD/ZAPD/ZBackground.cpp b/tools/ZAPD/ZAPD/ZBackground.cpp
index 02ff4243df..94388bf28c 100644
--- a/tools/ZAPD/ZAPD/ZBackground.cpp
+++ b/tools/ZAPD/ZAPD/ZBackground.cpp
@@ -50,10 +50,10 @@ void ZBackground::ParseRawData()
void ZBackground::ParseBinaryFile(const std::string& inFolder, bool appendOutName)
{
fs::path filepath(inFolder);
+
if (appendOutName)
- {
filepath = filepath / (outName + "." + GetExternalExtension());
- }
+
data = File::ReadAllBytes(filepath.string());
// Add padding.
@@ -62,9 +62,9 @@ void ZBackground::ParseBinaryFile(const std::string& inFolder, bool appendOutNam
}
void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- uint32_t nRawDataIndex, const std::string& nRelPath)
+ uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
+ ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar("", "");
}
@@ -128,13 +128,13 @@ void ZBackground::CheckValidJpeg(const std::string& filepath)
}
}
-size_t ZBackground::GetRawDataSize()
+size_t ZBackground::GetRawDataSize() const
{
// Jpgs use the whole sceen buffer, which is a u16 matrix.
return Globals::Instance->cfg.bgScreenHeight * Globals::Instance->cfg.bgScreenWidth * 2;
}
-void ZBackground::DeclareVar(const std::string& prefix, const std::string& bodyStr)
+void ZBackground::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
{
std::string auxName = name;
@@ -142,23 +142,23 @@ void ZBackground::DeclareVar(const std::string& prefix, const std::string& bodyS
auxName = GetDefaultName(prefix, rawDataIndex);
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
- GetSourceTypeName(), auxName, 0, bodyStr);
+ GetSourceTypeName(), auxName, "SCREEN_WIDTH * SCREEN_HEIGHT / 4",
+ bodyStr);
}
-bool ZBackground::IsExternalResource()
+bool ZBackground::IsExternalResource() const
{
return true;
}
-std::string ZBackground::GetExternalExtension()
+std::string ZBackground::GetExternalExtension() const
{
return "jpg";
}
-void ZBackground::Save(const std::string& outFolder)
+void ZBackground::Save(const fs::path& outFolder)
{
- fs::path folder(outFolder);
- fs::path filepath = folder / (outName + "." + GetExternalExtension());
+ fs::path filepath = outFolder / (outName + "." + GetExternalExtension());
File::WriteAllBytes(filepath.string(), data);
}
@@ -198,12 +198,12 @@ std::string ZBackground::GetDefaultName(const std::string& prefix, uint32_t addr
return StringHelper::Sprintf("%sBackground_%06X", prefix.c_str(), address);
}
-std::string ZBackground::GetSourceTypeName()
+std::string ZBackground::GetSourceTypeName() const
{
return "u64";
}
-ZResourceType ZBackground::GetResourceType()
+ZResourceType ZBackground::GetResourceType() const
{
return ZResourceType::Background;
}
diff --git a/tools/ZAPD/ZAPD/ZBackground.h b/tools/ZAPD/ZAPD/ZBackground.h
index 55cbf2b613..3df5c794b7 100644
--- a/tools/ZAPD/ZAPD/ZBackground.h
+++ b/tools/ZAPD/ZAPD/ZBackground.h
@@ -16,22 +16,21 @@ public:
void ParseRawData() override;
void ParseBinaryFile(const std::string& inFolder, bool appendOutName);
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- uint32_t nRawDataIndex, const std::string& nRelPath) override;
+ uint32_t nRawDataIndex) override;
void CheckValidJpeg(const std::string& filepath);
- size_t GetRawDataSize() override;
+ size_t GetRawDataSize() const override;
- void DeclareVar(const std::string& prefix, const std::string& bodyStr);
-
- bool IsExternalResource() override;
- std::string GetExternalExtension() override;
- void Save(const std::string& outFolder) override;
+ void DeclareVar(const std::string& prefix, const std::string& bodyStr) const;
+ bool IsExternalResource() const override;
+ std::string GetExternalExtension() const override;
+ void Save(const fs::path& outFolder) override;
std::string GetBodySourceCode();
std::string GetSourceOutputCode(const std::string& prefix) override;
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
- std::string GetSourceTypeName() override;
- ZResourceType GetResourceType() override;
+ std::string GetSourceTypeName() const override;
+ ZResourceType GetResourceType() const override;
};
diff --git a/tools/ZAPD/ZAPD/ZBlob.cpp b/tools/ZAPD/ZAPD/ZBlob.cpp
index 53cd0065a5..e377bcf8c9 100644
--- a/tools/ZAPD/ZAPD/ZBlob.cpp
+++ b/tools/ZAPD/ZAPD/ZBlob.cpp
@@ -6,34 +6,12 @@
#include "ZFile.h"
using namespace tinyxml2;
-using namespace std;
REGISTER_ZFILENODE(Blob, ZBlob);
ZBlob::ZBlob(ZFile* nParent) : ZResource(nParent)
{
-}
-
-ZBlob::ZBlob(const std::vector& nRawData, uint32_t nRawDataIndex, size_t size,
- std::string nName, ZFile* nParent)
- : ZBlob(nParent)
-{
- rawDataIndex = nRawDataIndex;
- rawData =
- vector(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size);
- name = std::move(nName);
-}
-
-void ZBlob::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath)
-{
- rawDataIndex = nRawDataIndex;
-
- ParseXML(reader);
- long size = strtol(reader->Attribute("Size"), NULL, 16);
- rawData =
- vector(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size);
- relativePath = std::move(nRelPath);
+ RegisterRequiredAttribute("Size");
}
// Build Source File Mode
@@ -44,7 +22,7 @@ ZBlob* ZBlob::BuildFromXML(XMLElement* reader, const std::string& inFolder, bool
blob->ParseXML(reader);
if (readFile)
- blob->rawData = File::ReadAllBytes(inFolder + "/" + blob->name + ".bin");
+ blob->blobData = File::ReadAllBytes(inFolder + "/" + blob->name + ".bin");
return blob;
}
@@ -53,21 +31,33 @@ ZBlob* ZBlob::FromFile(const std::string& filePath)
{
ZBlob* blob = new ZBlob(nullptr);
blob->name = StringHelper::Split(Path::GetFileNameWithoutExtension(filePath), ".")[0];
- blob->rawData = File::ReadAllBytes(filePath);
+ blob->blobData = File::ReadAllBytes(filePath);
return blob;
}
-string ZBlob::GetSourceOutputCode(const std::string& prefix)
+void ZBlob::ParseXML(tinyxml2::XMLElement* reader)
+{
+ ZResource::ParseXML(reader);
+
+ blobSize = StringHelper::StrToL(registeredAttributes.at("Size").value, 16);
+}
+
+void ZBlob::ParseRawData()
+{
+ blobData.assign(rawData.data() + rawDataIndex, rawData.data() + rawDataIndex + blobSize);
+}
+
+std::string ZBlob::GetSourceOutputCode(const std::string& prefix)
{
sourceOutput = "";
- for (size_t i = 0; i < rawData.size(); i += 1)
+ for (size_t i = 0; i < blobData.size(); i += 1)
{
if (i % 16 == 0)
sourceOutput += " ";
- sourceOutput += StringHelper::Sprintf("0x%02X, ", rawData[i]);
+ sourceOutput += StringHelper::Sprintf("0x%02X, ", blobData[i]);
if (i % 16 == 15)
sourceOutput += "\n";
@@ -81,32 +71,37 @@ string ZBlob::GetSourceOutputCode(const std::string& prefix)
return sourceOutput;
}
-string ZBlob::GetSourceOutputHeader(const std::string& prefix)
+std::string ZBlob::GetSourceOutputHeader(const std::string& prefix)
{
return StringHelper::Sprintf("extern u8 %s[];\n", name.c_str());
}
-void ZBlob::Save(const std::string& outFolder)
+void ZBlob::Save(const fs::path& outFolder)
{
- File::WriteAllBytes(outFolder + "/" + name + ".bin", rawData);
+ File::WriteAllBytes(outFolder / (name + ".bin"), blobData);
}
-bool ZBlob::IsExternalResource()
+bool ZBlob::IsExternalResource() const
{
return true;
}
-string ZBlob::GetExternalExtension()
+std::string ZBlob::GetExternalExtension() const
{
return "bin";
}
-std::string ZBlob::GetSourceTypeName()
+std::string ZBlob::GetSourceTypeName() const
{
return "u8";
}
-ZResourceType ZBlob::GetResourceType()
+ZResourceType ZBlob::GetResourceType() const
{
return ZResourceType::Blob;
}
+
+size_t ZBlob::GetRawDataSize() const
+{
+ return blobSize;
+}
diff --git a/tools/ZAPD/ZAPD/ZBlob.h b/tools/ZAPD/ZAPD/ZBlob.h
index dda3e4e0a7..2f8d315729 100644
--- a/tools/ZAPD/ZAPD/ZBlob.h
+++ b/tools/ZAPD/ZAPD/ZBlob.h
@@ -7,21 +7,25 @@ class ZBlob : public ZResource
{
public:
ZBlob(ZFile* nParent);
- ZBlob(const std::vector& nRawData, uint32_t rawDataIndex, size_t size,
- std::string nName, ZFile* nParent);
-
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex,
- const std::string& nRelPath) override; // Extract Mode
static ZBlob* BuildFromXML(tinyxml2::XMLElement* reader, const std::string& inFolder,
bool readFile);
static ZBlob* FromFile(const std::string& filePath);
+
+ void ParseXML(tinyxml2::XMLElement* reader) override;
+ void ParseRawData() override;
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
- void Save(const std::string& outFolder) override;
- bool IsExternalResource() override;
- std::string GetExternalExtension() override;
- std::string GetSourceTypeName() override;
- ZResourceType GetResourceType() override;
+ void Save(const fs::path& outFolder) override;
+
+ bool IsExternalResource() const override;
+ std::string GetSourceTypeName() const override;
+ ZResourceType GetResourceType() const override;
+ std::string GetExternalExtension() const override;
+
+ size_t GetRawDataSize() const override;
+
+protected:
+ std::vector blobData;
+ size_t blobSize = 0;
};
diff --git a/tools/ZAPD/ZAPD/ZCollision.cpp b/tools/ZAPD/ZAPD/ZCollision.cpp
index 118ef797fb..34d7ee12d0 100644
--- a/tools/ZAPD/ZAPD/ZCollision.cpp
+++ b/tools/ZAPD/ZAPD/ZCollision.cpp
@@ -5,8 +5,6 @@
#include "Globals.h"
#include "StringHelper.h"
-using namespace std;
-
REGISTER_ZFILENODE(Collision, ZCollisionHeader);
ZCollisionHeader::ZCollisionHeader(ZFile* nParent) : ZResource(nParent)
@@ -21,18 +19,6 @@ ZCollisionHeader::~ZCollisionHeader()
delete camData;
}
-ZResourceType ZCollisionHeader::GetResourceType()
-{
- return ZResourceType::CollisionHeader;
-}
-
-void ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader,
- const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath)
-{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
-}
-
void ZCollisionHeader::ParseRawData()
{
const uint8_t* data = rawData.data();
@@ -91,7 +77,7 @@ void ZCollisionHeader::ParseRawData()
rawData,
waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16))));
- string declaration = "";
+ std::string declaration = "";
if (waterBoxes.size() > 0)
{
@@ -197,11 +183,21 @@ void ZCollisionHeader::ParseRawData()
name.c_str(), polyTypeDefSegmentOffset, name.c_str(), camDataSegmentOffset, numWaterBoxes,
waterBoxStr);
- parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, DeclarationPadding::Pad16, 44,
- "CollisionHeader",
+ parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, DeclarationPadding::Pad16,
+ GetRawDataSize(), "CollisionHeader",
StringHelper::Sprintf("%s", name.c_str(), rawDataIndex), declaration);
}
+ZResourceType ZCollisionHeader::GetResourceType() const
+{
+ return ZResourceType::CollisionHeader;
+}
+
+size_t ZCollisionHeader::GetRawDataSize() const
+{
+ return 44;
+}
+
PolygonEntry::PolygonEntry(const std::vector& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
@@ -245,7 +241,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
const std::vector& rawData, uint32_t rawDataIndex,
uint32_t polyTypeDefSegmentOffset, uint32_t polygonTypesCnt)
{
- string declaration = "";
+ std::string declaration = "";
// Parse CameraDataEntries
int32_t numElements = (polyTypeDefSegmentOffset - rawDataIndex) / 8;
@@ -286,7 +282,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
index);
}
else
- sprintf(camSegLine, "0x%08X", entries[i]->cameraPosDataSeg);
+ sprintf(camSegLine, "NULL");
declaration +=
StringHelper::Sprintf(" { 0x%04X, %i, %s },", entries[i]->cameraSType,
diff --git a/tools/ZAPD/ZAPD/ZCollision.h b/tools/ZAPD/ZAPD/ZCollision.h
index 7626da731b..8b53f25035 100644
--- a/tools/ZAPD/ZAPD/ZCollision.h
+++ b/tools/ZAPD/ZAPD/ZCollision.h
@@ -90,9 +90,9 @@ public:
ZCollisionHeader(ZFile* nParent);
~ZCollisionHeader();
- ZResourceType GetResourceType() override;
-
- void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath) override;
void ParseRawData() override;
+
+ ZResourceType GetResourceType() const override;
+
+ size_t GetRawDataSize() const override;
};
diff --git a/tools/ZAPD/ZAPD/ZCutscene.cpp b/tools/ZAPD/ZAPD/ZCutscene.cpp
index d947f627b3..48e6a46762 100644
--- a/tools/ZAPD/ZAPD/ZCutscene.cpp
+++ b/tools/ZAPD/ZAPD/ZCutscene.cpp
@@ -3,8 +3,6 @@
#include "StringHelper.h"
#include "ZResource.h"
-using namespace std;
-
REGISTER_ZFILENODE(Cutscene, ZCutscene);
ZCutscene::ZCutscene(ZFile* nParent) : ZCutsceneBase(nParent)
@@ -86,9 +84,9 @@ CutsceneCommandSceneTransFX::~CutsceneCommandSceneTransFX()
{
}
-string ZCutscene::GetBodySourceCode()
+std::string ZCutscene::GetBodySourceCode()
{
- string output = "";
+ std::string output = "";
size_t size = 0;
uint32_t curPtr = 0;
@@ -107,7 +105,7 @@ string ZCutscene::GetBodySourceCode()
return output;
}
-string ZCutscene::GetSourceOutputCode(const std::string& prefix)
+std::string ZCutscene::GetSourceOutputCode(const std::string& prefix)
{
std::string bodyStr = GetBodySourceCode();
@@ -121,20 +119,19 @@ string ZCutscene::GetSourceOutputCode(const std::string& prefix)
return "";
}
-void ZCutscene::DeclareVar(const std::string& prefix, const std::string& bodyStr)
+void ZCutscene::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
{
std::string auxName = name;
if (auxName == "")
auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex);
- // auxName = GetDefaultName(prefix, getSegmentOffset());
parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4,
DeclarationPadding::Pad16, GetRawDataSize(), "s32", auxName, 0,
bodyStr);
}
-size_t ZCutscene::GetRawDataSize()
+size_t ZCutscene::GetRawDataSize() const
{
size_t size = 0;
@@ -155,16 +152,16 @@ size_t ZCutscene::GetRawDataSize()
}
void ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath)
+ const uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
+ ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar(parent->GetName(), "");
}
void ZCutscene::ParseRawData()
{
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
- commands = vector();
+ commands = std::vector();
endFrame = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
uint32_t currentPtr = rawDataIndex + 8;
@@ -442,12 +439,12 @@ CutsceneCommands ZCutscene::GetCommandFromID(int32_t id)
return CutsceneCommands::Error;
}
-ZResourceType ZCutscene::GetResourceType()
+ZResourceType ZCutscene::GetResourceType() const
{
return ZResourceType::Cutscene;
}
-CutsceneCommand::CutsceneCommand(const vector& rawData, uint32_t rawDataIndex)
+CutsceneCommand::CutsceneCommand(const std::vector& rawData, uint32_t rawDataIndex)
{
}
@@ -455,12 +452,12 @@ CutsceneCommand::~CutsceneCommand()
{
}
-string CutsceneCommand::GetCName()
+std::string CutsceneCommand::GetCName()
{
return "SCmdCutsceneData";
}
-string CutsceneCommand::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommand::GenerateSourceCode(uint32_t baseAddress)
{
return StringHelper::Sprintf("%s CutsceneData%04XCmd%02X = { 0x%02X,", GetCName().c_str(),
baseAddress, commandIndex, commandID);
@@ -471,7 +468,7 @@ size_t CutsceneCommand::GetCommandSize()
return 4;
}
-CutsceneCameraPoint::CutsceneCameraPoint(const vector& rawData, uint32_t rawDataIndex)
+CutsceneCameraPoint::CutsceneCameraPoint(const std::vector& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
@@ -487,7 +484,7 @@ CutsceneCameraPoint::CutsceneCameraPoint(const vector& rawData, uint32_
unused = BitConverter::ToInt16BE(data, rawDataIndex + 14);
}
-CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector& rawData,
+CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -498,7 +495,7 @@ CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector&
endFrame = BitConverter::ToUInt16BE(data, rawDataIndex + 4);
unused = BitConverter::ToUInt16BE(data, rawDataIndex + 6);
- entries = vector();
+ entries = std::vector();
bool shouldContinue = true;
@@ -517,17 +514,17 @@ CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector&
}
// TODO
-string CutsceneCommandSetCameraPos::GetCName()
+std::string CutsceneCommandSetCameraPos::GetCName()
{
return "";
}
-string CutsceneCommandSetCameraPos::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandSetCameraPos::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
- string listStr = "";
- string posStr = "";
+ std::string listStr = "";
+ std::string posStr = "";
if (commandID == (int32_t)CutsceneCommands::SetCameraFocus)
{
@@ -569,7 +566,7 @@ size_t CutsceneCommandSetCameraPos::GetCommandSize()
return 8 + (entries.size() * 16);
}
-MusicFadeEntry::MusicFadeEntry(const vector& rawData, uint32_t rawDataIndex)
+MusicFadeEntry::MusicFadeEntry(const std::vector& rawData, uint32_t rawDataIndex)
{
base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0);
startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2);
@@ -590,7 +587,7 @@ MusicFadeEntry::MusicFadeEntry(const vector& rawData, uint32_t rawDataI
rawDataIndex + 44); // Macro hardcodes it as zero
}
-CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector& rawData,
+CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -605,14 +602,14 @@ CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector& rawData,
}
}
-string CutsceneCommandFadeBGM::GetCName()
+std::string CutsceneCommandFadeBGM::GetCName()
{
return "CsCmdMusicFade";
}
-string CutsceneCommandFadeBGM::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandFadeBGM::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_FADE_BGM_LIST(%i),\n", entries.size());
@@ -633,7 +630,7 @@ size_t CutsceneCommandFadeBGM::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 0x30 * entries.size();
}
-MusicChangeEntry::MusicChangeEntry(const vector& rawData, uint32_t rawDataIndex)
+MusicChangeEntry::MusicChangeEntry(const std::vector& rawData, uint32_t rawDataIndex)
{
sequence = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0);
startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2);
@@ -648,7 +645,7 @@ MusicChangeEntry::MusicChangeEntry(const vector& rawData, uint32_t rawD
unknown7 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 32);
}
-CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector& rawData,
+CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -663,9 +660,9 @@ CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector& rawData,
}
}
-string CutsceneCommandPlayBGM::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandPlayBGM::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_PLAY_BGM_LIST(%i),\n", entries.size());
@@ -681,7 +678,7 @@ string CutsceneCommandPlayBGM::GenerateSourceCode(uint32_t baseAddress)
return result;
}
-string CutsceneCommandPlayBGM::GetCName()
+std::string CutsceneCommandPlayBGM::GetCName()
{
return "CsCmdMusicChange";
}
@@ -691,7 +688,7 @@ size_t CutsceneCommandPlayBGM::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 0x30;
}
-CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector& rawData,
+CutsceneCommandStopBGM::CutsceneCommandStopBGM(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -706,9 +703,9 @@ CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector& rawData,
}
}
-string CutsceneCommandStopBGM::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandStopBGM::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_STOP_BGM_LIST(%i),\n", entries.size());
@@ -724,7 +721,7 @@ string CutsceneCommandStopBGM::GenerateSourceCode(uint32_t baseAddress)
return result;
}
-string CutsceneCommandStopBGM::GetCName()
+std::string CutsceneCommandStopBGM::GetCName()
{
return "CsCmdMusicChange";
}
@@ -734,7 +731,7 @@ size_t CutsceneCommandStopBGM::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 0x30;
}
-EnvLightingEntry::EnvLightingEntry(const vector& rawData, uint32_t rawDataIndex)
+EnvLightingEntry::EnvLightingEntry(const std::vector& rawData, uint32_t rawDataIndex)
{
setting = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@@ -749,7 +746,7 @@ EnvLightingEntry::EnvLightingEntry(const vector& rawData, uint32_t rawD
unused7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32);
}
-CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector& rawData,
+CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -764,9 +761,9 @@ CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector& ra
}
}
-string CutsceneCommandEnvLighting::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandEnvLighting::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_LIGHTING_LIST(%i),\n", entries.size());
@@ -782,7 +779,7 @@ string CutsceneCommandEnvLighting::GenerateSourceCode(uint32_t baseAddress)
return result;
}
-string CutsceneCommandEnvLighting::GetCName()
+std::string CutsceneCommandEnvLighting::GetCName()
{
return "CsCmdEnvLighting";
}
@@ -792,7 +789,7 @@ size_t CutsceneCommandEnvLighting::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (0x30 * entries.size());
}
-Unknown9Entry::Unknown9Entry(const vector& rawData, uint32_t rawDataIndex)
+Unknown9Entry::Unknown9Entry(const std::vector& rawData, uint32_t rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@@ -805,7 +802,7 @@ Unknown9Entry::Unknown9Entry(const vector& rawData, uint32_t rawDataInd
;
}
-CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector& rawData,
+CutsceneCommandUnknown9::CutsceneCommandUnknown9(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -820,9 +817,9 @@ CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector& rawData,
}
}
-string CutsceneCommandUnknown9::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandUnknown9::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_CMD_09_LIST(%i),\n", entries.size());
@@ -837,7 +834,7 @@ string CutsceneCommandUnknown9::GenerateSourceCode(uint32_t baseAddress)
return result;
}
-string CutsceneCommandUnknown9::GetCName()
+std::string CutsceneCommandUnknown9::GetCName()
{
return "CsCmdUnknown9";
}
@@ -847,7 +844,7 @@ size_t CutsceneCommandUnknown9::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 12);
}
-UnkEntry::UnkEntry(const vector& rawData, uint32_t rawDataIndex)
+UnkEntry::UnkEntry(const std::vector& rawData, uint32_t rawDataIndex)
{
unused0 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
unused1 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
@@ -863,7 +860,7 @@ UnkEntry::UnkEntry(const vector& rawData, uint32_t rawDataIndex)
unused11 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 44);
}
-CutsceneCommandUnknown::CutsceneCommandUnknown(const vector& rawData,
+CutsceneCommandUnknown::CutsceneCommandUnknown(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -878,9 +875,9 @@ CutsceneCommandUnknown::CutsceneCommandUnknown(const vector& rawData,
}
}
-string CutsceneCommandUnknown::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandUnknown::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%02X, %i),\n", commandID, entries.size());
@@ -896,7 +893,7 @@ string CutsceneCommandUnknown::GenerateSourceCode(uint32_t baseAddress)
return result;
}
-string CutsceneCommandUnknown::GetCName()
+std::string CutsceneCommandUnknown::GetCName()
{
return "CsCmdUnknown1A";
}
@@ -906,7 +903,7 @@ size_t CutsceneCommandUnknown::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 0x30);
}
-DayTimeEntry::DayTimeEntry(const vector& rawData, uint32_t rawDataIndex)
+DayTimeEntry::DayTimeEntry(const std::vector& rawData, uint32_t rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@@ -916,7 +913,7 @@ DayTimeEntry::DayTimeEntry(const vector& rawData, uint32_t rawDataIndex
unused = rawData[rawDataIndex + 8];
}
-CutsceneCommandDayTime::CutsceneCommandDayTime(const vector& rawData,
+CutsceneCommandDayTime::CutsceneCommandDayTime(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -931,14 +928,14 @@ CutsceneCommandDayTime::CutsceneCommandDayTime(const vector& rawData,
}
}
-string CutsceneCommandDayTime::GetCName()
+std::string CutsceneCommandDayTime::GetCName()
{
return "CsCmdDayTime";
}
-string CutsceneCommandDayTime::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandDayTime::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_TIME_LIST(%i),\n", entries.size());
@@ -957,7 +954,7 @@ size_t CutsceneCommandDayTime::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 12);
}
-TextboxEntry::TextboxEntry(const vector& rawData, uint32_t rawDataIndex)
+TextboxEntry::TextboxEntry(const std::vector& rawData, uint32_t rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@@ -967,7 +964,7 @@ TextboxEntry::TextboxEntry(const vector& rawData, uint32_t rawDataIndex
textID2 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
}
-CutsceneCommandTextbox::CutsceneCommandTextbox(const vector& rawData,
+CutsceneCommandTextbox::CutsceneCommandTextbox(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -982,14 +979,14 @@ CutsceneCommandTextbox::CutsceneCommandTextbox(const vector& rawData,
}
}
-string CutsceneCommandTextbox::GetCName()
+std::string CutsceneCommandTextbox::GetCName()
{
return "CsCmdTextbox";
}
-string CutsceneCommandTextbox::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandTextbox::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_TEXT_LIST(%i),\n", entries.size());
@@ -1017,7 +1014,7 @@ size_t CutsceneCommandTextbox::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 12);
}
-ActorAction::ActorAction(const vector& rawData, uint32_t rawDataIndex)
+ActorAction::ActorAction(const std::vector& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
@@ -1038,7 +1035,7 @@ ActorAction::ActorAction(const vector& rawData, uint32_t rawDataIndex)
normalZ = BitConverter::ToInt32BE(data, rawDataIndex + 44);
}
-CutsceneCommandActorAction::CutsceneCommandActorAction(const vector& rawData,
+CutsceneCommandActorAction::CutsceneCommandActorAction(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -1053,10 +1050,10 @@ CutsceneCommandActorAction::CutsceneCommandActorAction(const vector& ra
}
}
-string CutsceneCommandActorAction::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandActorAction::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
- string subCommand = "";
+ std::string result = "";
+ std::string subCommand = "";
if (commandID == 10)
{
@@ -1084,7 +1081,7 @@ string CutsceneCommandActorAction::GenerateSourceCode(uint32_t baseAddress)
return result;
}
-string CutsceneCommandActorAction::GetCName()
+std::string CutsceneCommandActorAction::GetCName()
{
return "CsCmdBase";
}
@@ -1094,7 +1091,7 @@ size_t CutsceneCommandActorAction::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 0x30);
}
-CutsceneCommandTerminator::CutsceneCommandTerminator(const vector& rawData,
+CutsceneCommandTerminator::CutsceneCommandTerminator(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -1106,14 +1103,14 @@ CutsceneCommandTerminator::CutsceneCommandTerminator(const vector& rawD
unknown = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); // endFrame duplicate
}
-string CutsceneCommandTerminator::GetCName()
+std::string CutsceneCommandTerminator::GetCName()
{
return "CsCmdBase";
}
-string CutsceneCommandTerminator::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandTerminator::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_TERMINATOR(0x%04X, %i, %i),\n", base, startFrame, endFrame);
@@ -1125,7 +1122,7 @@ size_t CutsceneCommandTerminator::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 8;
}
-CutsceneCommandEnd::CutsceneCommandEnd(const vector& rawData, uint32_t rawDataIndex)
+CutsceneCommandEnd::CutsceneCommandEnd(const std::vector& rawData, uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
@@ -1133,16 +1130,16 @@ CutsceneCommandEnd::CutsceneCommandEnd(const vector& rawData, uint32_t
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
-string CutsceneCommandEnd::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandEnd::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_END(),\n");
return result;
}
-string CutsceneCommandEnd::GetCName()
+std::string CutsceneCommandEnd::GetCName()
{
return "CsCmdBase";
}
@@ -1152,7 +1149,7 @@ size_t CutsceneCommandEnd::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 6;
}
-SpecialActionEntry::SpecialActionEntry(const vector& rawData, uint32_t rawDataIndex)
+SpecialActionEntry::SpecialActionEntry(const std::vector& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
@@ -1172,7 +1169,7 @@ SpecialActionEntry::SpecialActionEntry(const vector& rawData, uint32_t
unused10 = BitConverter::ToUInt32BE(data, rawDataIndex + 44);
}
-CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector& rawData,
+CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -1187,9 +1184,9 @@ CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector
}
}
-string CutsceneCommandSpecialAction::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandSpecialAction::GenerateSourceCode(uint32_t baseAddress)
{
- string result = "";
+ std::string result = "";
result += StringHelper::Sprintf("CS_MISC_LIST(%i),\n", entries.size());
@@ -1207,7 +1204,7 @@ string CutsceneCommandSpecialAction::GenerateSourceCode(uint32_t baseAddress)
return result;
}
-string CutsceneCommandSpecialAction::GetCName()
+std::string CutsceneCommandSpecialAction::GetCName()
{
return "CsCmdBase";
}
@@ -1217,7 +1214,7 @@ size_t CutsceneCommandSpecialAction::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (0x30 * entries.size());
}
-CutsceneCommandNop::CutsceneCommandNop(const vector& rawData, uint32_t rawDataIndex)
+CutsceneCommandNop::CutsceneCommandNop(const std::vector& rawData, uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
@@ -1225,7 +1222,7 @@ CutsceneCommandNop::CutsceneCommandNop(const vector& rawData, uint32_t
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
-string CutsceneCommandNop::GetCName()
+std::string CutsceneCommandNop::GetCName()
{
return "CsCmdBase";
}
@@ -1235,7 +1232,7 @@ size_t CutsceneCommandNop::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 6;
}
-CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector& rawData,
+CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const std::vector& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -1246,12 +1243,12 @@ CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector&
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
-string CutsceneCommandSceneTransFX::GenerateSourceCode(uint32_t baseAddress)
+std::string CutsceneCommandSceneTransFX::GenerateSourceCode(uint32_t baseAddress)
{
return StringHelper::Sprintf("CS_SCENE_TRANS_FX(%i, %i, %i),\n", base, startFrame, endFrame);
}
-string CutsceneCommandSceneTransFX::GetCName()
+std::string CutsceneCommandSceneTransFX::GetCName()
{
return "CsCmdBase";
}
diff --git a/tools/ZAPD/ZAPD/ZCutscene.h b/tools/ZAPD/ZAPD/ZCutscene.h
index f5b68ea83a..4899c82f89 100644
--- a/tools/ZAPD/ZAPD/ZCutscene.h
+++ b/tools/ZAPD/ZAPD/ZCutscene.h
@@ -413,8 +413,8 @@ class ZCutsceneBase : public ZResource
public:
ZCutsceneBase(ZFile* nParent);
virtual std::string GetBodySourceCode() = 0;
- virtual void DeclareVar(const std::string& prefix, const std::string& bodyStr) = 0;
- virtual uint32_t getSegmentOffset() = 0;
+ virtual void DeclareVar(const std::string& prefix, const std::string& bodyStr) const = 0;
+ virtual uint32_t getSegmentOffset() const = 0;
};
class ZCutscene : public ZCutsceneBase
@@ -423,22 +423,22 @@ public:
ZCutscene(ZFile* nParent);
~ZCutscene();
- std::string GetBodySourceCode() override;
- void DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
- std::string GetSourceOutputCode(const std::string& prefix) override;
- size_t GetRawDataSize() override;
- CutsceneCommands GetCommandFromID(int32_t id);
- uint32_t getSegmentOffset() override { return rawDataIndex; }
+ void ParseRawData() override;
- ZResourceType GetResourceType() override;
+ std::string GetBodySourceCode() override;
+ void DeclareVar(const std::string& prefix, const std::string& bodyStr) const override;
+ std::string GetSourceOutputCode(const std::string& prefix) override;
+ size_t GetRawDataSize() const override;
+ CutsceneCommands GetCommandFromID(int32_t id);
+ uint32_t getSegmentOffset() const override { return rawDataIndex; }
+
+ ZResourceType GetResourceType() const override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath) override;
+ const uint32_t nRawDataIndex) override;
protected:
int32_t numCommands;
int32_t endFrame;
std::vector commands;
-
- void ParseRawData() override;
};
diff --git a/tools/ZAPD/ZAPD/ZCutsceneMM.cpp b/tools/ZAPD/ZAPD/ZCutsceneMM.cpp
index 0474b631df..bb6724060c 100644
--- a/tools/ZAPD/ZAPD/ZCutsceneMM.cpp
+++ b/tools/ZAPD/ZAPD/ZCutsceneMM.cpp
@@ -2,8 +2,6 @@
#include "BitConverter.h"
#include "StringHelper.h"
-using namespace std;
-
ZCutsceneMM::ZCutsceneMM(ZFile* nParent) : ZCutsceneBase(nParent)
{
}
@@ -14,9 +12,9 @@ ZCutsceneMM::~ZCutsceneMM()
delete cmd;
}
-string ZCutsceneMM::GetBodySourceCode()
+std::string ZCutsceneMM::GetBodySourceCode()
{
- string output = "";
+ std::string output = "";
output += StringHelper::Sprintf(" CS_BEGIN_CUTSCENE(%i, %i),", numCommands, endFrame);
@@ -30,7 +28,7 @@ string ZCutsceneMM::GetBodySourceCode()
return output;
}
-string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
+std::string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
{
std::string bodyStr = GetBodySourceCode();
@@ -44,27 +42,26 @@ string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
return "";
}
-void ZCutsceneMM::DeclareVar(const std::string& prefix, const std::string& bodyStr)
+void ZCutsceneMM::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
{
std::string auxName = name;
if (auxName == "")
auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex);
- // auxName = GetDefaultName(prefix, getSegmentOffset());
parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4, GetRawDataSize(),
"s32", auxName, 0, bodyStr);
}
-size_t ZCutsceneMM::GetRawDataSize()
+size_t ZCutsceneMM::GetRawDataSize() const
{
return 8 + data.size() * 4;
}
void ZCutsceneMM::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath)
+ const uint32_t nRawDataIndex)
{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
+ ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar(parent->GetName(), "");
}
@@ -73,7 +70,7 @@ void ZCutsceneMM::ParseRawData()
segmentOffset = rawDataIndex;
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
- commands = vector();
+ commands = std::vector();
endFrame = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
uint32_t currentPtr = rawDataIndex + 8;
@@ -89,7 +86,7 @@ void ZCutsceneMM::ParseRawData()
} while (lastData != 0xFFFFFFFF);
}
-ZResourceType ZCutsceneMM::GetResourceType()
+ZResourceType ZCutsceneMM::GetResourceType() const
{
return ZResourceType::Cutscene;
}
diff --git a/tools/ZAPD/ZAPD/ZCutsceneMM.h b/tools/ZAPD/ZAPD/ZCutsceneMM.h
index 97dae93e81..c0438ed726 100644
--- a/tools/ZAPD/ZAPD/ZCutsceneMM.h
+++ b/tools/ZAPD/ZAPD/ZCutsceneMM.h
@@ -16,16 +16,16 @@ public:
virtual ~ZCutsceneMM();
std::string GetBodySourceCode() override;
- void DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
+ void DeclareVar(const std::string& prefix, const std::string& bodyStr) const override;
std::string GetSourceOutputCode(const std::string& prefix) override;
- size_t GetRawDataSize() override;
- uint32_t getSegmentOffset() override { return segmentOffset; }
+ size_t GetRawDataSize() const override;
+ uint32_t getSegmentOffset() const override { return segmentOffset; }
void ParseRawData() override;
- ZResourceType GetResourceType() override;
+ ZResourceType GetResourceType() const override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath) override;
+ const uint32_t nRawDataIndex) override;
protected:
int32_t numCommands;
diff --git a/tools/ZAPD/ZAPD/ZDisplayList.cpp b/tools/ZAPD/ZAPD/ZDisplayList.cpp
index 99abbbe2b0..de041f121c 100644
--- a/tools/ZAPD/ZAPD/ZDisplayList.cpp
+++ b/tools/ZAPD/ZAPD/ZDisplayList.cpp
@@ -11,7 +11,6 @@
#include "StringHelper.h"
#include "gfxd.h"
-using namespace std;
using namespace tinyxml2;
REGISTER_ZFILENODE(DList, ZDisplayList);
@@ -31,23 +30,10 @@ ZDisplayList::ZDisplayList(ZFile* nParent) : ZResource(nParent)
name = "";
scene = nullptr;
dListType = Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX;
-
- fileData = vector();
- instructions = vector();
- vertices = map>();
- vtxDeclarations = map();
- otherDLists = vector();
- textures = map();
- texDeclarations = map();
}
ZDisplayList::~ZDisplayList()
{
- for (auto t : textures)
- {
- delete t.second;
- }
-
for (auto o : otherDLists)
{
delete o;
@@ -57,43 +43,50 @@ ZDisplayList::~ZDisplayList()
// EXTRACT MODE
void ZDisplayList::ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector& nRawData,
- const uint32_t nRawDataIndex, const std::string& nRelPath)
+ const uint32_t nRawDataIndex)
{
+ rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
ParseXML(reader);
- // name = reader->Attribute("Name");
fileData = nRawData;
- relativePath = nRelPath;
int32_t rawDataSize = ZDisplayList::GetDListLength(
nRawData, rawDataIndex,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
- rawData = vector(nRawData.data() + rawDataIndex,
- nRawData.data() + rawDataIndex + rawDataSize);
+ dlistRawData.assign(nRawData.data() + rawDataIndex,
+ nRawData.data() + rawDataIndex + rawDataSize);
ParseRawData();
+
+ DeclareVar("", "");
}
-ZDisplayList::ZDisplayList(vector nRawData, uint32_t nRawDataIndex, int32_t rawDataSize,
- ZFile* nParent)
+ZDisplayList::ZDisplayList(std::vector nRawData, uint32_t nRawDataIndex,
+ int32_t rawDataSize, ZFile* nParent)
: ZDisplayList(nParent)
{
+ rawData.assign(nRawData.begin(), nRawData.end());
fileData = nRawData;
rawDataIndex = nRawDataIndex;
name = StringHelper::Sprintf("DL_%06X", rawDataIndex);
- rawData = vector(nRawData.data() + rawDataIndex,
- nRawData.data() + rawDataIndex + rawDataSize);
+ dlistRawData.assign(nRawData.data() + rawDataIndex,
+ nRawData.data() + rawDataIndex + rawDataSize);
ParseRawData();
}
void ZDisplayList::ParseRawData()
{
- size_t numInstructions = rawData.size() / 8;
- uint8_t* rawDataArr = rawData.data();
+ size_t numInstructions = dlistRawData.size() / 8;
instructions.reserve(numInstructions);
for (size_t i = 0; i < numInstructions; i++)
- instructions.push_back(BitConverter::ToUInt64BE(rawDataArr, (i * 8)));
+ instructions.push_back(BitConverter::ToUInt64BE(dlistRawData, (i * 8)));
+}
+
+Declaration* ZDisplayList::DeclareVar(const std::string& prefix, const std::string& bodyStr)
+{
+ return parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
+ GetSourceTypeName(), name, 0, bodyStr, true);
}
void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, std::string prefix,
@@ -138,7 +131,7 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, st
{
int32_t cccccc = (data & 0x00FFFFFF00000000) >> 32;
int32_t ssssssss = (data & 0xFFFFFFFF);
- string geoModeStr = "G_TEXTURE_ENABLE";
+ std::string geoModeStr = "G_TEXTURE_ENABLE";
int32_t geoModeParam = ~cccccc;
@@ -366,7 +359,7 @@ void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, std::string pre
{
int32_t cccccc = (data & 0x00FFFFFF00000000) >> 32;
int32_t ssssssss = (data & 0xFFFFFFFF);
- string geoModeStr = "G_TEXTURE_ENABLE";
+ std::string geoModeStr = "G_TEXTURE_ENABLE";
int32_t geoModeParam = ~cccccc;
@@ -418,7 +411,7 @@ void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, std::string pre
}
}
-int32_t ZDisplayList::GetDListLength(vector rawData, uint32_t rawDataIndex,
+int32_t ZDisplayList::GetDListLength(std::vector rawData, uint32_t rawDataIndex,
DListType dListType)
{
int32_t i = 0;
@@ -432,7 +425,7 @@ int32_t ZDisplayList::GetDListLength(vector rawData, uint32_t rawDataIn
while (true)
{
- uint8_t opcode = rawData[rawDataIndex + (i * 8)];
+ uint8_t opcode = rawData.at(rawDataIndex + (i * 8));
i++;
if (opcode == endDLOpcode)
@@ -440,7 +433,7 @@ int32_t ZDisplayList::GetDListLength(vector rawData, uint32_t rawDataIn
}
}
-bool ZDisplayList::SequenceCheck(vector sequence, int32_t startIndex)
+bool ZDisplayList::SequenceCheck(std::vector sequence, int32_t startIndex)
{
bool success = true;
@@ -461,7 +454,8 @@ bool ZDisplayList::SequenceCheck(vector sequence, int32_t startInd
return false;
}
-int32_t ZDisplayList::OptimizationChecks(int32_t startIndex, string& output, string prefix)
+int32_t ZDisplayList::OptimizationChecks(int32_t startIndex, std::string& output,
+ std::string prefix)
{
int32_t result = -1;
@@ -473,8 +467,8 @@ int32_t ZDisplayList::OptimizationChecks(int32_t startIndex, string& output, str
return -1;
}
-int32_t ZDisplayList::OptimizationCheck_LoadTextureBlock(int32_t startIndex, string& output,
- string prefix)
+int32_t ZDisplayList::OptimizationCheck_LoadTextureBlock(int32_t startIndex, std::string& output,
+ std::string prefix)
{
if (scene == nullptr)
{
@@ -498,7 +492,7 @@ int32_t ZDisplayList::OptimizationCheck_LoadTextureBlock(int32_t startIndex, str
uint32_t texAddr, tmem, rtile, fmt, siz, sizB, width, height, width2, height2, pal, cms,
cmt, masks, maskt, shifts, shiftt;
- string texStr = "";
+ std::string texStr = "";
// gsDPSetTextureImage
{
@@ -512,36 +506,19 @@ int32_t ZDisplayList::OptimizationCheck_LoadTextureBlock(int32_t startIndex, str
texAddr = Seg2Filespace(data, parent->baseAddress);
int32_t segmentNumber = GETSEGNUM(data);
- lastTexSeg = (data & 0xFF000000);
+ lastTexSeg = segmentNumber;
- Declaration* texDecl = nullptr;
+ ZFile* auxParent = parent;
+ if (parent->segment != segmentNumber && Globals::Instance->HasSegment(segmentNumber))
+ auxParent = Globals::Instance->segmentRefFiles.at(segmentNumber);
- if (parent != nullptr &&
- segmentNumber != 2) // HACK: Until we have declarations use segment addresses,
- // we'll exclude scene references...
- {
- texDecl = parent->GetDeclaration(texAddr);
-
- if (texDecl == nullptr)
- texDecl = parent->GetDeclaration(data);
- }
-
- if (texAddr != 0)
- {
- if (texDecl != nullptr)
- texStr = StringHelper::Sprintf("%s", texDecl->varName.c_str());
- else if (segmentNumber == 2)
- texStr = StringHelper::Sprintf("%sTex_%06X", scene->GetName().c_str(), texAddr);
- else if (!Globals::Instance->HasSegment(
- segmentNumber)) // Probably an external asset we are unable to track
- texStr = StringHelper::Sprintf("0x%06X", data);
- else
- texStr = StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), texAddr);
- }
- else if (segmentNumber != 3)
- texStr = StringHelper::Sprintf("0x%06X", data);
+ Declaration* decl = auxParent->GetDeclaration(texAddr);
+ if (Globals::Instance->HasSegment(segmentNumber) && decl != nullptr)
+ texStr = decl->varName;
+ else if (lastTexture != nullptr)
+ texStr = lastTexture->GetName();
else
- texStr = StringHelper::Sprintf("0");
+ texStr = auxParent->GetDeclarationPtrName(data & 0xFFFFFFFF);
}
// gsDPSetTile
@@ -610,9 +587,9 @@ int32_t ZDisplayList::OptimizationCheck_LoadTextureBlock(int32_t startIndex, str
height2 = (vvv >> 2) + 1;
}
- string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA",
- "G_IM_FMT_I"};
- string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"};
+ std::string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA",
+ "G_IM_FMT_I"};
+ std::string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"};
// output += StringHelper::Sprintf("gsDPLoadTextureBlock(%s, %s, %s, %i, %i, %i, %i, %i, %i,
// %i, %i, %i),", texStr.c_str(), fmtTbl[fmt].c_str(), sizTbl[siz].c_str(), width, height,
@@ -880,12 +857,15 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, char* line)
if (nn > 0)
{
- vector vtxList = vector();
+ std::vector vtxList;
vtxList.reserve(nn);
for (int32_t i = 0; i < nn; i++)
{
- Vertex vtx = Vertex(fileData, currentPtr);
+ ZVtx vtx(parent);
+ vtx.SetRawData(fileData);
+ vtx.SetRawDataIndex(currentPtr);
+ vtx.ParseRawData();
vtxList.push_back(vtx);
currentPtr += 16;
@@ -918,13 +898,14 @@ void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, std::string prefix, char* lin
{
int32_t __ = (data & 0x00FF000000000000) >> 48;
int32_t www = (data & 0x00000FFF00000000) >> 32;
- string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", "G_IM_FMT_I"};
- string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"};
+ std::string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA",
+ "G_IM_FMT_I"};
+ std::string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"};
uint32_t fmt = (__ & 0xE0) >> 5;
uint32_t siz = (__ & 0x18) >> 3;
- if (Globals::Instance->verbosity >= VERBOSITY_DEBUG)
+ if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
printf("TextureGenCheck G_SETTIMG\n");
TextureGenCheck(prefix); // HOTSPOT
@@ -956,9 +937,7 @@ void ZDisplayList::Opcode_G_SETTIMG(uint64_t data, std::string prefix, char* lin
sprintf(texStr, "%sTex_%06X", prefix.c_str(), texAddress);
else
{
- {
- sprintf(texStr, "0x%08lX", data & 0xFFFFFFFF);
- }
+ sprintf(texStr, "0x%08lX", data & 0xFFFFFFFF);
}
sprintf(line, "gsDPSetTextureImage(%s, %s, %i, %s),", fmtTbl[fmt].c_str(),
@@ -991,8 +970,9 @@ void ZDisplayList::Opcode_G_SETTILE(uint64_t data, char* line)
int32_t bbbb = (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4;
int32_t uuuu = (data & 0b0000000000000000000000000000000000000000000000000000000000001111);
- string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA", "G_IM_FMT_I"};
- string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"};
+ std::string fmtTbl[] = {"G_IM_FMT_RGBA", "G_IM_FMT_YUV", "G_IM_FMT_CI", "G_IM_FMT_IA",
+ "G_IM_FMT_I"};
+ std::string sizTbl[] = {"G_IM_SIZ_4b", "G_IM_SIZ_8b", "G_IM_SIZ_16b", "G_IM_SIZ_32b"};
if (fff == (int32_t)F3DZEXTexFormats::G_IM_FMT_CI)
lastCISiz = (F3DZEXTexSizes)ii;
@@ -1031,11 +1011,11 @@ void ZDisplayList::Opcode_G_SETTILESIZE(uint64_t data, std::string prefix, char*
lastTexWidth = (uuu >> shiftAmtW) + 1;
lastTexHeight = (vvv >> shiftAmtH) + 1;
- if (Globals::Instance->verbosity >= VERBOSITY_DEBUG)
+ if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
printf("lastTexWidth: %i lastTexHeight: %i, lastTexSizTest: 0x%x, lastTexFmt: 0x%x\n",
lastTexWidth, lastTexHeight, (uint32_t)lastTexSizTest, (uint32_t)lastTexFmt);
- if (Globals::Instance->verbosity >= VERBOSITY_DEBUG)
+ if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
printf("TextureGenCheck G_SETTILESIZE\n");
TextureGenCheck(prefix);
@@ -1075,51 +1055,51 @@ void ZDisplayList::Opcode_G_SETCOMBINE(uint64_t data, char* line)
int32_t ab1 = (data & 0b00000000000000000000000000000000000000000000000000000000111000) >> 3;
int32_t ad1 = (data & 0b00000000000000000000000000000000000000000000000000000000000111) >> 0;
- string modesA[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT",
- "1", "NOISE", "0", "9", "10", "11",
- "12", "13", "14", "0"};
- string modesB[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT",
- "CENTER", "K4", "8", "9", "10", "11",
- "12", "13", "14", "0"};
- string modesC[] = {"COMBINED",
- "TEXEL0",
- "TEXEL1",
- "PRIMITIVE",
- "SHADE",
- "ENVIRONMENT",
- "1",
- "COMBINED_ALPHA",
- "TEXEL0_ALPHA",
- "TEXEL1_ALPHA",
- "PRIMITIVE_ALPHA",
- "SHADE_ALPHA",
- "ENV_ALPHA",
- "LOD_FRACTION",
- "PRIM_LOD_FRAC",
- "K5",
- "16",
- "17",
- "18",
- "19",
- "20",
- "21",
- "22",
- "23",
- "24",
- "25",
- "26",
- "27",
- "28",
- "29",
- "30",
- "0"};
- string modesD[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE",
- "SHADE", "ENVIRONMENT", "1", "0"};
+ std::string modesA[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT",
+ "1", "NOISE", "0", "9", "10", "11",
+ "12", "13", "14", "0"};
+ std::string modesB[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE", "SHADE", "ENVIRONMENT",
+ "CENTER", "K4", "8", "9", "10", "11",
+ "12", "13", "14", "0"};
+ std::string modesC[] = {"COMBINED",
+ "TEXEL0",
+ "TEXEL1",
+ "PRIMITIVE",
+ "SHADE",
+ "ENVIRONMENT",
+ "1",
+ "COMBINED_ALPHA",
+ "TEXEL0_ALPHA",
+ "TEXEL1_ALPHA",
+ "PRIMITIVE_ALPHA",
+ "SHADE_ALPHA",
+ "ENV_ALPHA",
+ "LOD_FRACTION",
+ "PRIM_LOD_FRAC",
+ "K5",
+ "16",
+ "17",
+ "18",
+ "19",
+ "20",
+ "21",
+ "22",
+ "23",
+ "24",
+ "25",
+ "26",
+ "27",
+ "28",
+ "29",
+ "30",
+ "0"};
+ std::string modesD[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE",
+ "SHADE", "ENVIRONMENT", "1", "0"};
- string modes2[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE",
- "SHADE", "ENVIRONMENT", "1", "0"};
- string modes2C[] = {"LOD_FRACTION", "TEXEL0", "TEXEL1", "PRIMITIVE",
- "SHADE", "ENVIRONMENT", "PRIM_LOD_FRAC", "0"};
+ std::string modes2[] = {"COMBINED", "TEXEL0", "TEXEL1", "PRIMITIVE",
+ "SHADE", "ENVIRONMENT", "1", "0"};
+ std::string modes2C[] = {"LOD_FRACTION", "TEXEL0", "TEXEL1", "PRIMITIVE",
+ "SHADE", "ENVIRONMENT", "PRIM_LOD_FRAC", "0"};
sprintf(line,
"gsDPSetCombineLERP(%s, %s, %s, %s, %s, %s, %s, %s,\n %s, %s, "
@@ -1272,7 +1252,7 @@ void ZDisplayList::Opcode_G_SETOTHERMODE_L(uint64_t data, char* line)
G_RM_VISCVG2,
G_RM_OPA_CI2};
- map