mirror of
https://github.com/zeldaret/oot
synced 2026-05-22 22:44:26 -04:00
ZAPD update: libpng, zroom improvements and others (#811)
* git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "769f5702a" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "769f5702a" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * Add `libpng` to readme * Remove `-ifp` since it doesn't exists anymore in ZAPD * Remove extra print I added * Add UNK_09 macro and other minor fixes * Simplify PNG rules * simplify gitignore * Update README.md Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com> * Update dockerfile * basic instructions for cygwin and mac * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "86160be69" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "86160be69" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * Change nanoseconds to seconds in extract_assets.py Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com>
This commit is contained in:
+3
-8
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@
|
||||
*.h
|
||||
*.cfg
|
||||
*.vtx.inc
|
||||
*.dlist.inc
|
||||
*.dlist.inc
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
<Scene Name="syotes_scene" Offset="0x0"/>
|
||||
</File>
|
||||
<File Name="syotes_room_0" Segment="3">
|
||||
<Room Name="syotes_room_0" Offset="0x0"/>
|
||||
<Room Name="syotes_room_0" HackMode="syotes_room" Offset="0x0"/>
|
||||
</File>
|
||||
</Root>
|
||||
|
||||
+4
-17
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+28
-10
@@ -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)
|
||||
|
||||
@@ -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`.
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<uint32_t> 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);
|
||||
};
|
||||
@@ -3,7 +3,6 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "StringHelper.h"
|
||||
|
||||
+26
-27
@@ -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<ZFile*>();
|
||||
segments = std::vector<int32_t>();
|
||||
symbolMap = std::map<uint32_t, std::string>();
|
||||
segmentRefs = map<int32_t, string>();
|
||||
segmentRefFiles = map<int32_t, ZFile*>();
|
||||
segmentRefs = std::map<int32_t, std::string>();
|
||||
segmentRefFiles = std::map<int32_t, ZFile*>();
|
||||
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<ZFile*> files = vector<ZFile*>();
|
||||
|
||||
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<std::string> 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<std::string> 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)
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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<uint16_t>();
|
||||
rotationIndices = vector<RotationIndex>();
|
||||
rotationValues = std::vector<uint16_t>();
|
||||
rotationIndices = std::vector<RotationIndex>();
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <tinyxml2.h>
|
||||
#include "../ZAnimation.h"
|
||||
#include "HLFileIntermediette.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
/*
|
||||
* An intermediette format for animations. Going to use XML.
|
||||
|
||||
@@ -12,12 +12,11 @@
|
||||
#include <assimp/scene.h>
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace tinyxml2;
|
||||
|
||||
HLModelIntermediette::HLModelIntermediette()
|
||||
{
|
||||
blocks = vector<HLIntermediette*>();
|
||||
blocks = std::vector<HLIntermediette*>();
|
||||
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<Vertex> finalVerts = vector<Vertex>();
|
||||
std::vector<ZVtx> finalVerts;
|
||||
|
||||
int32_t vStart = -1;
|
||||
|
||||
for (pair<int32_t, vector<Vertex>> 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<uint32_t, ZTexture*> 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 <typename T>
|
||||
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<Vertex>();
|
||||
vertices = std::vector<ZVtx>();
|
||||
}
|
||||
|
||||
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<Vertex> dispListVertices)
|
||||
void HLVerticesIntermediette::InitFromVertices(std::vector<ZVtx> 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<HLVerticesIntermediette>();
|
||||
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<HLDisplayListCommand*>();
|
||||
commands = std::vector<HLDisplayListCommand*>();
|
||||
}
|
||||
|
||||
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<HLMeshCommand*>();
|
||||
commands = std::vector<HLMeshCommand*>();
|
||||
}
|
||||
|
||||
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<HLMaterialIntermediette>(materialName);
|
||||
HLTextureIntermediette* tex = parent->FindByName<HLTextureIntermediette>(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<HLLimbCommand*>();
|
||||
commands = std::vector<HLLimbCommand*>();
|
||||
}
|
||||
|
||||
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<HLMeshIntermediette>(meshName);
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
#include <assimp/scene.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <tinyxml2.h>
|
||||
#include <vector>
|
||||
#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<Vertex> vertices;
|
||||
std::vector<ZVtx> vertices;
|
||||
|
||||
HLVerticesIntermediette();
|
||||
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* verticesElement);
|
||||
void InitFromVertices(std::vector<Vertex> dispListVertices);
|
||||
void InitFromVertices(std::vector<ZVtx> dispListVertices);
|
||||
virtual std::string OutputCode(HLModelIntermediette* parent);
|
||||
virtual std::string OutputOBJ();
|
||||
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
#include "HLTexture.h"
|
||||
#include <stb_image.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,473 @@
|
||||
#include "ImageBackend.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <png.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#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<png_color*>(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<std::vector<RGBAPixel>>& 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<uint8_t**>(malloc(sizeof(uint8_t*) * height));
|
||||
for (size_t y = 0; y < height; y++)
|
||||
{
|
||||
pixelMatrix[y] = static_cast<uint8_t*>(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<uint8_t**>(malloc(sizeof(uint8_t*) * height));
|
||||
for (size_t y = 0; y < height; y++)
|
||||
{
|
||||
pixelMatrix[y] = static_cast<uint8_t*>(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<uint8_t*>(calloc(width * bytePerPixel, sizeof(uint8_t*)));
|
||||
}
|
||||
colorPalette = calloc(paletteSize, sizeof(png_color));
|
||||
alphaPalette = static_cast<uint8_t*>(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<png_color*>(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<png_color*>(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;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#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<std::vector<RGBAPixel>>& 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();
|
||||
};
|
||||
+93
-86
@@ -14,9 +14,11 @@
|
||||
|
||||
#if !defined(_MSC_VER) && !defined(__CYGWIN__)
|
||||
#include <csignal>
|
||||
#include <cstdlib>
|
||||
#include <cxxabi.h> // for __cxa_demangle
|
||||
#include <dlfcn.h> // for dladdr
|
||||
#include <execinfo.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#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<VerbosityLevel>(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<string> split = StringHelper::Split(outPath, "/");
|
||||
std::vector<std::string> 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;
|
||||
|
||||
@@ -4,16 +4,15 @@
|
||||
#include "../Path.h"
|
||||
#include "../StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace ELFIO;
|
||||
|
||||
ZOverlay::ZOverlay()
|
||||
{
|
||||
name = "";
|
||||
entries = vector<RelocationEntry*>();
|
||||
entries = std::vector<RelocationEntry*>();
|
||||
}
|
||||
|
||||
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<string> cfgLines = StringHelper::Split(cfgText, "\n");
|
||||
std::string cfgText = File::ReadAllText(cfgFolderPath + "/overlay.cfg");
|
||||
std::vector<std::string> cfgLines = StringHelper::Split(cfgText, "\n");
|
||||
|
||||
ZOverlay* ovl = new ZOverlay(StringHelper::Strip(cfgLines[0], "\r"));
|
||||
|
||||
vector<string> relSections = {".rel.text", ".rel.data", ".rel.rodata"};
|
||||
vector<string> sections = {".text", ".data", ".rodata"};
|
||||
std::vector<std::string> relSections = {".rel.text", ".rel.data", ".rel.rodata"};
|
||||
std::vector<std::string> sections = {".text", ".data", ".rodata"};
|
||||
|
||||
int32_t sectionOffs[5] = {0};
|
||||
vector<RelocationEntry*> textRelocs;
|
||||
vector<RelocationEntry*> dataRelocs;
|
||||
vector<RelocationEntry*> rodataRelocs;
|
||||
std::vector<RelocationEntry*> textRelocs;
|
||||
std::vector<RelocationEntry*> dataRelocs;
|
||||
std::vector<RelocationEntry*> rodataRelocs;
|
||||
|
||||
// get the elf files
|
||||
vector<elfio*> readers;
|
||||
std::vector<elfio*> 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;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <elfio/elfio.hpp>
|
||||
#include <tinyxml2.h>
|
||||
#include "../ZResource.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
enum SectionType
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <numeric>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
+65
-103
@@ -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<uint16_t>();
|
||||
rotationIndices = vector<RotationIndex>();
|
||||
rotationValues = std::vector<uint16_t>();
|
||||
rotationIndices = std::vector<RotationIndex>();
|
||||
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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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";
|
||||
}
|
||||
|
||||
@@ -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<uint8_t>& 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<uint8_t>& 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<uint8_t> refIndexArr;
|
||||
std::vector<TransformData> 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<uint8_t>& 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
|
||||
|
||||
+42
-34
@@ -1,4 +1,5 @@
|
||||
#include "ZArray.h"
|
||||
#include <cassert>
|
||||
#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<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex, const std::string& nRelPath)
|
||||
ZResourceType ZArray::GetResourceType() const
|
||||
{
|
||||
rawData = nRawData;
|
||||
rawDataIndex = nRawDataIndex;
|
||||
ParseXML(reader);
|
||||
// arr->ParseRawData();
|
||||
return ZResourceType::Array;
|
||||
}
|
||||
|
||||
@@ -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<uint8_t>& 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<uint8_t>& data, const int32_t offset);
|
||||
};
|
||||
std::string childName;
|
||||
std::vector<ZResource*> resList;
|
||||
};
|
||||
|
||||
@@ -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<uint8_t>& 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;
|
||||
}
|
||||
|
||||
@@ -16,22 +16,21 @@ public:
|
||||
void ParseRawData() override;
|
||||
void ParseBinaryFile(const std::string& inFolder, bool appendOutName);
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& 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;
|
||||
};
|
||||
|
||||
+30
-35
@@ -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<uint8_t>& nRawData, uint32_t nRawDataIndex, size_t size,
|
||||
std::string nName, ZFile* nParent)
|
||||
: ZBlob(nParent)
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
rawData =
|
||||
vector<uint8_t>(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size);
|
||||
name = std::move(nName);
|
||||
}
|
||||
|
||||
void ZBlob::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex, const std::string& nRelPath)
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
|
||||
ParseXML(reader);
|
||||
long size = strtol(reader->Attribute("Size"), NULL, 16);
|
||||
rawData =
|
||||
vector<uint8_t>(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;
|
||||
}
|
||||
|
||||
+15
-11
@@ -7,21 +7,25 @@ class ZBlob : public ZResource
|
||||
{
|
||||
public:
|
||||
ZBlob(ZFile* nParent);
|
||||
ZBlob(const std::vector<uint8_t>& nRawData, uint32_t rawDataIndex, size_t size,
|
||||
std::string nName, ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& 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<uint8_t> blobData;
|
||||
size_t blobSize = 0;
|
||||
};
|
||||
|
||||
@@ -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<uint8_t>& 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<uint8_t>& 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<uint8_t>& 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,
|
||||
|
||||
@@ -90,9 +90,9 @@ public:
|
||||
ZCollisionHeader(ZFile* nParent);
|
||||
~ZCollisionHeader();
|
||||
|
||||
ZResourceType GetResourceType() override;
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
|
||||
void ParseRawData() override;
|
||||
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
};
|
||||
|
||||
@@ -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<uint8_t>& 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<CutsceneCommand*>();
|
||||
commands = std::vector<CutsceneCommand*>();
|
||||
|
||||
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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
CutsceneCommand::CutsceneCommand(const std::vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
CutsceneCameraPoint::CutsceneCameraPoint(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
const uint8_t* data = rawData.data();
|
||||
|
||||
@@ -487,7 +484,7 @@ CutsceneCameraPoint::CutsceneCameraPoint(const vector<uint8_t>& rawData, uint32_
|
||||
unused = BitConverter::ToInt16BE(data, rawDataIndex + 14);
|
||||
}
|
||||
|
||||
CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -498,7 +495,7 @@ CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>&
|
||||
endFrame = BitConverter::ToUInt16BE(data, rawDataIndex + 4);
|
||||
unused = BitConverter::ToUInt16BE(data, rawDataIndex + 6);
|
||||
|
||||
entries = vector<CutsceneCameraPoint*>();
|
||||
entries = std::vector<CutsceneCameraPoint*>();
|
||||
|
||||
bool shouldContinue = true;
|
||||
|
||||
@@ -517,17 +514,17 @@ CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>&
|
||||
}
|
||||
|
||||
// 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
MusicFadeEntry::MusicFadeEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0);
|
||||
startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2);
|
||||
@@ -590,7 +587,7 @@ MusicFadeEntry::MusicFadeEntry(const vector<uint8_t>& rawData, uint32_t rawDataI
|
||||
rawDataIndex + 44); // Macro hardcodes it as zero
|
||||
}
|
||||
|
||||
CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -605,14 +602,14 @@ CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
MusicChangeEntry::MusicChangeEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
sequence = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0);
|
||||
startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2);
|
||||
@@ -648,7 +645,7 @@ MusicChangeEntry::MusicChangeEntry(const vector<uint8_t>& rawData, uint32_t rawD
|
||||
unknown7 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 32);
|
||||
}
|
||||
|
||||
CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -663,9 +660,9 @@ CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector<uint8_t>& 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<uint8_t>& rawData,
|
||||
CutsceneCommandStopBGM::CutsceneCommandStopBGM(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -706,9 +703,9 @@ CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
EnvLightingEntry::EnvLightingEntry(const std::vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawD
|
||||
unused7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32);
|
||||
}
|
||||
|
||||
CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -764,9 +761,9 @@ CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
Unknown9Entry::Unknown9Entry(const std::vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataInd
|
||||
;
|
||||
}
|
||||
|
||||
CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandUnknown9::CutsceneCommandUnknown9(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -820,9 +817,9 @@ CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
UnkEntry::UnkEntry(const std::vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
unused11 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 44);
|
||||
}
|
||||
|
||||
CutsceneCommandUnknown::CutsceneCommandUnknown(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandUnknown::CutsceneCommandUnknown(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -878,9 +875,9 @@ CutsceneCommandUnknown::CutsceneCommandUnknown(const vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
DayTimeEntry::DayTimeEntry(const std::vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex
|
||||
unused = rawData[rawDataIndex + 8];
|
||||
}
|
||||
|
||||
CutsceneCommandDayTime::CutsceneCommandDayTime(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandDayTime::CutsceneCommandDayTime(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -931,14 +928,14 @@ CutsceneCommandDayTime::CutsceneCommandDayTime(const vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
TextboxEntry::TextboxEntry(const std::vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex
|
||||
textID2 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
|
||||
}
|
||||
|
||||
CutsceneCommandTextbox::CutsceneCommandTextbox(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandTextbox::CutsceneCommandTextbox(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -982,14 +979,14 @@ CutsceneCommandTextbox::CutsceneCommandTextbox(const vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
ActorAction::ActorAction(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
const uint8_t* data = rawData.data();
|
||||
|
||||
@@ -1038,7 +1035,7 @@ ActorAction::ActorAction(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
normalZ = BitConverter::ToInt32BE(data, rawDataIndex + 44);
|
||||
}
|
||||
|
||||
CutsceneCommandActorAction::CutsceneCommandActorAction(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandActorAction::CutsceneCommandActorAction(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -1053,10 +1050,10 @@ CutsceneCommandActorAction::CutsceneCommandActorAction(const vector<uint8_t>& 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<uint8_t>& rawData,
|
||||
CutsceneCommandTerminator::CutsceneCommandTerminator(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -1106,14 +1103,14 @@ CutsceneCommandTerminator::CutsceneCommandTerminator(const vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
CutsceneCommandEnd::CutsceneCommandEnd(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
|
||||
@@ -1133,16 +1130,16 @@ CutsceneCommandEnd::CutsceneCommandEnd(const vector<uint8_t>& 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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
SpecialActionEntry::SpecialActionEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
const uint8_t* data = rawData.data();
|
||||
|
||||
@@ -1172,7 +1169,7 @@ SpecialActionEntry::SpecialActionEntry(const vector<uint8_t>& rawData, uint32_t
|
||||
unused10 = BitConverter::ToUInt32BE(data, rawDataIndex + 44);
|
||||
}
|
||||
|
||||
CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t>& rawData,
|
||||
CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -1187,9 +1184,9 @@ CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t>
|
||||
}
|
||||
}
|
||||
|
||||
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<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
CutsceneCommandNop::CutsceneCommandNop(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
|
||||
@@ -1225,7 +1222,7 @@ CutsceneCommandNop::CutsceneCommandNop(const vector<uint8_t>& 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<uint8_t>& rawData,
|
||||
CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: CutsceneCommand(rawData, rawDataIndex)
|
||||
{
|
||||
@@ -1246,12 +1243,12 @@ CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector<uint8_t>&
|
||||
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";
|
||||
}
|
||||
|
||||
+12
-12
@@ -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<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
|
||||
const uint32_t nRawDataIndex) override;
|
||||
|
||||
protected:
|
||||
int32_t numCommands;
|
||||
int32_t endFrame;
|
||||
std::vector<CutsceneCommand*> commands;
|
||||
|
||||
void ParseRawData() override;
|
||||
};
|
||||
|
||||
@@ -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<uint8_t>& 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<CutsceneCommand*>();
|
||||
commands = std::vector<CutsceneCommand*>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
|
||||
const uint32_t nRawDataIndex) override;
|
||||
|
||||
protected:
|
||||
int32_t numCommands;
|
||||
|
||||
+275
-437
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
#include "ZResource.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
#include "ZTexture.h"
|
||||
#include "ZVtx.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include <map>
|
||||
@@ -282,25 +283,10 @@ enum class OoTSegments
|
||||
#define FORCE_BL 0x4000
|
||||
#define TEX_EDGE 0x0000
|
||||
|
||||
class Vertex
|
||||
{
|
||||
public:
|
||||
int16_t x, y, z;
|
||||
uint16_t flag;
|
||||
int16_t s, t;
|
||||
uint8_t r, g, b, a;
|
||||
|
||||
Vertex();
|
||||
Vertex(int16_t nX, int16_t nY, int16_t nZ, uint16_t nFlag, int16_t nS, int16_t nT, uint8_t nR,
|
||||
uint8_t nG, uint8_t nB, uint8_t nA);
|
||||
Vertex(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class ZDisplayList : public ZResource
|
||||
{
|
||||
protected:
|
||||
static TextureType TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSizes siz);
|
||||
void ParseRawData() override;
|
||||
|
||||
void ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, std::string prefix, char* line);
|
||||
void ParseF3DEX(F3DEXOpcode opcode, uint64_t data, std::string prefix, char* line);
|
||||
@@ -350,14 +336,12 @@ public:
|
||||
|
||||
DListType dListType;
|
||||
|
||||
// int32_t dListAddress;
|
||||
|
||||
std::map<uint32_t, std::vector<Vertex>> vertices;
|
||||
std::map<uint32_t, std::vector<ZVtx>> vertices;
|
||||
std::map<uint32_t, std::string> vtxDeclarations;
|
||||
std::vector<ZDisplayList*> otherDLists;
|
||||
|
||||
std::map<uint32_t, ZTexture*> textures;
|
||||
std::map<uint32_t, std::string> texDeclarations;
|
||||
ZTexture* lastTexture = nullptr;
|
||||
ZTexture* lastTlut = nullptr;
|
||||
|
||||
std::vector<uint32_t> references;
|
||||
|
||||
@@ -371,31 +355,34 @@ public:
|
||||
~ZDisplayList();
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
|
||||
// static ZDisplayList* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, bool
|
||||
// readFile, ZFile* nParent);
|
||||
const uint32_t nRawDataIndex) override;
|
||||
|
||||
void ParseRawData() override;
|
||||
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
|
||||
void TextureGenCheck(std::string prefix);
|
||||
static bool TextureGenCheck(std::vector<uint8_t> fileData,
|
||||
std::map<uint32_t, ZTexture*>& textures, ZRoom* scene,
|
||||
ZFile* parent, std::string prefix, int32_t texWidth,
|
||||
int32_t texHeight, uint32_t texAddr, uint32_t texSeg,
|
||||
F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded,
|
||||
bool texIsPalette);
|
||||
static bool TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene, ZFile* parent,
|
||||
std::string prefix, int32_t texWidth, int32_t texHeight,
|
||||
uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt,
|
||||
F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette,
|
||||
ZDisplayList* self);
|
||||
static int32_t GetDListLength(std::vector<uint8_t> rawData, uint32_t rawDataIndex,
|
||||
DListType dListType);
|
||||
|
||||
size_t GetRawDataSize() override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetSourceOutputHeader(const std::string& prefix) override;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
std::string ProcessLegacy(const std::string& prefix);
|
||||
std::string ProcessGfxDis(const std::string& prefix);
|
||||
|
||||
void Save(const std::string& outFolder) override;
|
||||
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile) override;
|
||||
bool IsExternalResource() override;
|
||||
virtual std::string GetExternalExtension() override;
|
||||
std::string GetSourceTypeName() override;
|
||||
bool IsExternalResource() const override;
|
||||
virtual std::string GetExternalExtension() const override;
|
||||
std::string GetSourceTypeName() const override;
|
||||
|
||||
ZResourceType GetResourceType() override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
protected:
|
||||
std::vector<uint8_t> dlistRawData;
|
||||
};
|
||||
|
||||
+296
-212
@@ -26,21 +26,20 @@
|
||||
#include "ZVtx.h"
|
||||
|
||||
using namespace tinyxml2;
|
||||
using namespace std;
|
||||
|
||||
ZFile::ZFile()
|
||||
{
|
||||
resources = vector<ZResource*>();
|
||||
resources = std::vector<ZResource*>();
|
||||
basePath = "";
|
||||
outputPath = Directory::GetCurrentDirectory();
|
||||
declarations = map<uint32_t, Declaration*>();
|
||||
declarations = std::map<uint32_t, Declaration*>();
|
||||
defines = "";
|
||||
baseAddress = 0;
|
||||
rangeStart = 0x000000000;
|
||||
rangeEnd = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
ZFile::ZFile(const fs::path& nOutPath, string nName) : ZFile()
|
||||
ZFile::ZFile(const fs::path& nOutPath, std::string nName) : ZFile()
|
||||
{
|
||||
outputPath = nOutPath;
|
||||
name = nName;
|
||||
@@ -63,6 +62,7 @@ ZFile::ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBase
|
||||
outputPath = nOutPath;
|
||||
|
||||
ParseXML(mode, reader, filename, placeholderMode);
|
||||
DeclareResourceSubReferences();
|
||||
}
|
||||
|
||||
ZFile::~ZFile()
|
||||
@@ -85,53 +85,55 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
||||
else
|
||||
name = filename;
|
||||
|
||||
int32_t segment = -1;
|
||||
|
||||
// TODO: This should be a variable on the ZFile, but it is a large change in order to force all
|
||||
// ZResource types to have a parent ZFile.
|
||||
const char* gameStr = reader->Attribute("Game");
|
||||
if (reader->Attribute("Game") != nullptr)
|
||||
{
|
||||
if (string(gameStr) == "MM")
|
||||
if (std::string(gameStr) == "MM")
|
||||
Globals::Instance->game = ZGame::MM_RETAIL;
|
||||
else if (string(gameStr) == "SW97" || string(gameStr) == "OOTSW97")
|
||||
else if (std::string(gameStr) == "SW97" || std::string(gameStr) == "OOTSW97")
|
||||
Globals::Instance->game = ZGame::OOT_SW97;
|
||||
else if (string(gameStr) == "OOT")
|
||||
else if (std::string(gameStr) == "OOT")
|
||||
Globals::Instance->game = ZGame::OOT_RETAIL;
|
||||
else
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Error: Game type %s not supported.", gameStr));
|
||||
}
|
||||
|
||||
if (reader->Attribute("BaseAddress") != NULL)
|
||||
baseAddress = (uint32_t)strtoul(
|
||||
StringHelper::Split(reader->Attribute("BaseAddress"), "0x")[1].c_str(), NULL, 16);
|
||||
if (reader->Attribute("BaseAddress") != nullptr)
|
||||
baseAddress = StringHelper::StrToL(reader->Attribute("BaseAddress"), 16);
|
||||
|
||||
if (reader->Attribute("RangeStart") != NULL)
|
||||
rangeStart = (uint32_t)strtoul(
|
||||
StringHelper::Split(reader->Attribute("RangeStart"), "0x")[1].c_str(), NULL, 16);
|
||||
if (reader->Attribute("RangeStart") != nullptr)
|
||||
rangeStart = StringHelper::StrToL(reader->Attribute("RangeStart"), 16);
|
||||
|
||||
if (reader->Attribute("RangeEnd") != NULL)
|
||||
rangeEnd = (uint32_t)strtoul(
|
||||
StringHelper::Split(reader->Attribute("RangeEnd"), "0x")[1].c_str(), NULL, 16);
|
||||
if (reader->Attribute("RangeEnd") != nullptr)
|
||||
rangeEnd = StringHelper::StrToL(reader->Attribute("RangeEnd"), 16);
|
||||
|
||||
if (reader->Attribute("Segment") != NULL)
|
||||
segment = strtol(reader->Attribute("Segment"), NULL, 10);
|
||||
// Commented until ZArray doesn't use a ZFile to parse it's contents anymore.
|
||||
/*
|
||||
if (reader->Attribute("Segment") == nullptr)
|
||||
throw std::runtime_error(StringHelper::Sprintf(
|
||||
"ZFile::ParseXML: Error in '%s'.\n"
|
||||
"\t Missing 'Segment' attribute in File node. \n",
|
||||
name.c_str()));
|
||||
*/
|
||||
|
||||
if (segment != -1)
|
||||
if (reader->Attribute("Segment") != nullptr)
|
||||
{
|
||||
Globals::Instance->AddSegment(segment);
|
||||
segment = StringHelper::StrToL(reader->Attribute("Segment"), 10);
|
||||
Globals::Instance->AddSegment(segment, this);
|
||||
}
|
||||
|
||||
string folderName = basePath / Path::GetFileNameWithoutExtension(name);
|
||||
std::string folderName = (basePath / Path::GetFileNameWithoutExtension(name)).string();
|
||||
|
||||
if (mode == ZFileMode::Extract)
|
||||
{
|
||||
if (!File::Exists(basePath / name))
|
||||
if (!File::Exists((basePath / name).string()))
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Error! File %s does not exist.", (basePath / name).c_str()));
|
||||
|
||||
rawData = File::ReadAllBytes(basePath / name);
|
||||
rawData = File::ReadAllBytes((basePath / name).string());
|
||||
}
|
||||
|
||||
std::unordered_set<std::string> nameSet;
|
||||
@@ -141,17 +143,18 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
||||
auto nodeMap = *GetNodeMap();
|
||||
uint32_t rawDataIndex = 0;
|
||||
|
||||
for (XMLElement* child = reader->FirstChildElement(); child != NULL;
|
||||
for (XMLElement* child = reader->FirstChildElement(); child != nullptr;
|
||||
child = child->NextSiblingElement())
|
||||
{
|
||||
const char* nameXml = child->Attribute("Name");
|
||||
const char* outNameXml = child->Attribute("OutName");
|
||||
const char* offsetXml = child->Attribute("Offset");
|
||||
|
||||
if (Globals::Instance->verbosity >= VERBOSITY_INFO)
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
printf("%s: 0x%06X\n", nameXml, rawDataIndex);
|
||||
|
||||
if (offsetXml != NULL)
|
||||
// Check for repeated attributes.
|
||||
if (offsetXml != nullptr)
|
||||
{
|
||||
rawDataIndex = strtol(StringHelper::Split(offsetXml, "0x")[1].c_str(), NULL, 16);
|
||||
|
||||
@@ -163,7 +166,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
||||
}
|
||||
offsetSet.insert(offsetXml);
|
||||
}
|
||||
if (outNameXml != NULL)
|
||||
if (outNameXml != nullptr)
|
||||
{
|
||||
if (outNameSet.find(outNameXml) != outNameSet.end())
|
||||
{
|
||||
@@ -173,7 +176,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
||||
}
|
||||
outNameSet.insert(outNameXml);
|
||||
}
|
||||
if (nameXml != NULL)
|
||||
if (nameXml != nullptr)
|
||||
{
|
||||
if (nameSet.find(nameXml) != nameSet.end())
|
||||
{
|
||||
@@ -184,40 +187,24 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
||||
nameSet.insert(nameXml);
|
||||
}
|
||||
|
||||
string nodeName = string(child->Name());
|
||||
std::string nodeName = std::string(child->Name());
|
||||
|
||||
if (nodeMap.find(nodeName) != nodeMap.end())
|
||||
{
|
||||
ZResource* nRes = nodeMap[nodeName]();
|
||||
nRes->parent = this;
|
||||
ZResource* nRes = nodeMap[nodeName](this);
|
||||
|
||||
if (mode == ZFileMode::Extract)
|
||||
nRes->ExtractFromXML(child, rawData, rawDataIndex, folderName);
|
||||
nRes->ExtractFromXML(child, rawData, rawDataIndex);
|
||||
|
||||
// TODO: See if we can make this part of the ZRoom code...
|
||||
if (nRes->GetResourceType() == ZResourceType::Room)
|
||||
{
|
||||
if (nodeName == "Scene")
|
||||
{
|
||||
Globals::Instance->lastScene = (ZRoom*)nRes;
|
||||
auto resType = nRes->GetResourceType();
|
||||
if (resType == ZResourceType::Texture)
|
||||
AddTextureResource(rawDataIndex, static_cast<ZTexture*>(nRes));
|
||||
else
|
||||
resources.push_back(nRes);
|
||||
|
||||
if (segment == -1)
|
||||
segment = SEGMENT_SCENE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (segment == -1)
|
||||
segment = SEGMENT_ROOM;
|
||||
}
|
||||
|
||||
if (segment != -1)
|
||||
Globals::Instance->AddSegment(segment);
|
||||
}
|
||||
|
||||
resources.push_back(nRes);
|
||||
rawDataIndex += nRes->GetRawDataSize();
|
||||
}
|
||||
else if (string(child->Name()) == "File")
|
||||
else if (std::string(child->Name()) == "File")
|
||||
{
|
||||
throw std::runtime_error(StringHelper::Sprintf(
|
||||
"ZFile::ParseXML: Error in '%s'.\n\t Can't declare a File inside a File.\n",
|
||||
@@ -233,19 +220,27 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
||||
}
|
||||
}
|
||||
|
||||
void ZFile::DeclareResourceSubReferences()
|
||||
{
|
||||
for (size_t i = 0; i < resources.size(); i++)
|
||||
{
|
||||
resources.at(i)->DeclareReferences(name);
|
||||
}
|
||||
}
|
||||
|
||||
void ZFile::BuildSourceFile(fs::path outputDir)
|
||||
{
|
||||
string folderName = Path::GetFileNameWithoutExtension(outputPath);
|
||||
std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string());
|
||||
|
||||
if (!Directory::Exists(outputPath))
|
||||
Directory::CreateDirectory(outputPath);
|
||||
if (!Directory::Exists(outputPath.string()))
|
||||
Directory::CreateDirectory(outputPath.string());
|
||||
|
||||
GenerateSourceFiles(outputDir);
|
||||
}
|
||||
|
||||
std::string ZFile::GetVarName(uint32_t address)
|
||||
{
|
||||
for (pair<uint32_t, Declaration*> pair : declarations)
|
||||
for (std::pair<uint32_t, Declaration*> pair : declarations)
|
||||
{
|
||||
if (pair.first == address)
|
||||
return pair.second->varName;
|
||||
@@ -254,20 +249,30 @@ std::string ZFile::GetVarName(uint32_t address)
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZFile::GetName()
|
||||
std::string ZFile::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
const fs::path& ZFile::GetXmlFilePath() const
|
||||
{
|
||||
return xmlFilePath;
|
||||
}
|
||||
|
||||
const std::vector<uint8_t>& ZFile::GetRawData() const
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
|
||||
void ZFile::ExtractResources(fs::path outputDir)
|
||||
{
|
||||
string folderName = Path::GetFileNameWithoutExtension(outputPath);
|
||||
std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string());
|
||||
|
||||
if (!Directory::Exists(outputPath))
|
||||
Directory::CreateDirectory(outputPath);
|
||||
if (!Directory::Exists(outputPath.string()))
|
||||
Directory::CreateDirectory(outputPath.string());
|
||||
|
||||
if (!Directory::Exists(Globals::Instance->sourceOutputPath))
|
||||
Directory::CreateDirectory(Globals::Instance->sourceOutputPath);
|
||||
if (!Directory::Exists(Globals::Instance->sourceOutputPath.string()))
|
||||
Directory::CreateDirectory(Globals::Instance->sourceOutputPath.string());
|
||||
|
||||
for (ZResource* res : resources)
|
||||
res->PreGenSourceFiles();
|
||||
@@ -277,10 +282,9 @@ void ZFile::ExtractResources(fs::path outputDir)
|
||||
|
||||
for (ZResource* res : resources)
|
||||
{
|
||||
if (Globals::Instance->verbosity >= VERBOSITY_INFO)
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
printf("Saving resource %s\n", res->GetName().c_str());
|
||||
|
||||
res->CalcHash(); // TEST
|
||||
res->Save(outputPath);
|
||||
}
|
||||
|
||||
@@ -320,13 +324,7 @@ std::vector<ZResource*> ZFile::GetResourcesOfType(ZResourceType resType)
|
||||
Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, size_t size,
|
||||
std::string varType, std::string varName, std::string body)
|
||||
{
|
||||
#if _DEBUG
|
||||
if (declarations.find(address) != declarations.end())
|
||||
{
|
||||
int32_t bp = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
|
||||
Declaration* decl = new Declaration(alignment, size, varType, varName, false, body);
|
||||
@@ -335,16 +333,10 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm
|
||||
}
|
||||
|
||||
Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment,
|
||||
DeclarationPadding padding, size_t size, string varType,
|
||||
string varName, std::string body)
|
||||
DeclarationPadding padding, size_t size, std::string varType,
|
||||
std::string varName, std::string body)
|
||||
{
|
||||
#if _DEBUG
|
||||
if (declarations.find(address) != declarations.end())
|
||||
{
|
||||
int32_t bp = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
|
||||
declarations[address] =
|
||||
@@ -356,13 +348,7 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
|
||||
size_t size, std::string varType, std::string varName,
|
||||
size_t arrayItemCnt, std::string body)
|
||||
{
|
||||
#if _DEBUG
|
||||
if (declarations.find(address) != declarations.end())
|
||||
{
|
||||
int32_t bp = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
|
||||
declarations[address] =
|
||||
@@ -370,17 +356,23 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
|
||||
return declarations[address];
|
||||
}
|
||||
|
||||
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
|
||||
size_t size, std::string varType, std::string varName,
|
||||
std::string arrayItemCntStr, std::string body)
|
||||
{
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
|
||||
declarations[address] =
|
||||
new Declaration(alignment, size, varType, varName, true, arrayItemCntStr, body);
|
||||
return declarations[address];
|
||||
}
|
||||
|
||||
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
|
||||
size_t size, std::string varType, std::string varName,
|
||||
size_t arrayItemCnt, std::string body, bool isExternal)
|
||||
{
|
||||
#if _DEBUG
|
||||
if (declarations.find(address) != declarations.end())
|
||||
{
|
||||
int32_t bp = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
|
||||
declarations[address] =
|
||||
@@ -389,16 +381,11 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
|
||||
}
|
||||
|
||||
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
|
||||
DeclarationPadding padding, size_t size, string varType,
|
||||
string varName, size_t arrayItemCnt, std::string body)
|
||||
DeclarationPadding padding, size_t size,
|
||||
std::string varType, std::string varName,
|
||||
size_t arrayItemCnt, std::string body)
|
||||
{
|
||||
#if _DEBUG
|
||||
if (declarations.find(address) != declarations.end())
|
||||
{
|
||||
int32_t bp = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
|
||||
declarations[address] =
|
||||
@@ -408,28 +395,44 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
|
||||
|
||||
Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address)
|
||||
{
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
Declaration* decl;
|
||||
|
||||
if (declarations.find(address) == declarations.end())
|
||||
declarations[address] = new Declaration(DeclarationAlignment::None, 0, "", "", false, "");
|
||||
{
|
||||
decl = new Declaration(DeclarationAlignment::None, 0, "", "", false, "");
|
||||
decl->isPlaceholder = true;
|
||||
declarations[address] = decl;
|
||||
}
|
||||
else
|
||||
decl = declarations[address];
|
||||
|
||||
return declarations[address];
|
||||
return decl;
|
||||
}
|
||||
|
||||
Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, string varName)
|
||||
Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, std::string varName)
|
||||
{
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
Declaration* decl;
|
||||
|
||||
if (declarations.find(address) == declarations.end())
|
||||
declarations[address] =
|
||||
new Declaration(DeclarationAlignment::None, 0, "", varName, false, "");
|
||||
{
|
||||
decl = new Declaration(DeclarationAlignment::None, 0, "", varName, false, "");
|
||||
decl->isPlaceholder = true;
|
||||
declarations[address] = decl;
|
||||
}
|
||||
else
|
||||
decl = declarations[address];
|
||||
|
||||
return declarations[address];
|
||||
return decl;
|
||||
}
|
||||
|
||||
Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, size_t size,
|
||||
string varType, string varName)
|
||||
Declaration* ZFile::AddDeclarationInclude(uint32_t address, std::string includePath, size_t size,
|
||||
std::string varType, std::string varName)
|
||||
{
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
|
||||
if (declarations.find(address) == declarations.end())
|
||||
@@ -442,18 +445,7 @@ Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string inc
|
||||
size_t size, std::string varType,
|
||||
std::string varName, size_t arrayItemCnt)
|
||||
{
|
||||
#if _DEBUG
|
||||
if (declarations.find(address) != declarations.end())
|
||||
{
|
||||
int32_t bp = 0;
|
||||
}
|
||||
|
||||
if (address == 0)
|
||||
{
|
||||
int32_t bp = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
AddDeclarationDebugChecks(address);
|
||||
|
||||
if (StringHelper::StartsWith(includePath, "assets/extracted/"))
|
||||
@@ -488,6 +480,7 @@ Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string inc
|
||||
|
||||
void ZFile::AddDeclarationDebugChecks(uint32_t address)
|
||||
{
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
#ifdef _DEBUG
|
||||
if (address == 0x0000)
|
||||
{
|
||||
@@ -496,30 +489,47 @@ void ZFile::AddDeclarationDebugChecks(uint32_t address)
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string ZFile::GetDeclarationName(uint32_t address)
|
||||
std::string ZFile::GetDeclarationName(uint32_t address) const
|
||||
{
|
||||
return GetDeclarationName(address,
|
||||
"ERROR_COULD_NOT_FIND_DECLARATION"); // Note: For now that default
|
||||
// message is just for testing
|
||||
}
|
||||
|
||||
std::string ZFile::GetDeclarationName(uint32_t address, std::string defaultResult)
|
||||
std::string ZFile::GetDeclarationName(uint32_t address, std::string defaultResult) const
|
||||
{
|
||||
if (declarations.find(address) != declarations.end())
|
||||
return declarations[address]->varName;
|
||||
Declaration* decl = GetDeclaration(address);
|
||||
if (decl != nullptr)
|
||||
return decl->varName;
|
||||
|
||||
return defaultResult;
|
||||
}
|
||||
|
||||
Declaration* ZFile::GetDeclaration(uint32_t address)
|
||||
std::string ZFile::GetDeclarationPtrName(segptr_t segAddress) const
|
||||
{
|
||||
if (segAddress == 0)
|
||||
return "NULL";
|
||||
|
||||
Declaration* decl = GetDeclaration(Seg2Filespace(segAddress, baseAddress));
|
||||
|
||||
if (!Globals::Instance->HasSegment(GETSEGNUM(segAddress)) || decl == nullptr)
|
||||
return StringHelper::Sprintf("0x%08X", segAddress);
|
||||
|
||||
if (!decl->isArray)
|
||||
return "&" + decl->varName;
|
||||
|
||||
return decl->varName;
|
||||
}
|
||||
|
||||
Declaration* ZFile::GetDeclaration(uint32_t address) const
|
||||
{
|
||||
if (declarations.find(address) != declarations.end())
|
||||
return declarations[address];
|
||||
return declarations.at(address);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Declaration* ZFile::GetDeclarationRanged(uint32_t address)
|
||||
Declaration* ZFile::GetDeclarationRanged(uint32_t address) const
|
||||
{
|
||||
for (const auto decl : declarations)
|
||||
{
|
||||
@@ -530,7 +540,7 @@ Declaration* ZFile::GetDeclarationRanged(uint32_t address)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t ZFile::GetDeclarationRangedAddress(uint32_t address)
|
||||
uint32_t ZFile::GetDeclarationRangedAddress(uint32_t address) const
|
||||
{
|
||||
for (const auto decl : declarations)
|
||||
{
|
||||
@@ -543,7 +553,7 @@ uint32_t ZFile::GetDeclarationRangedAddress(uint32_t address)
|
||||
|
||||
bool ZFile::HasDeclaration(uint32_t address)
|
||||
{
|
||||
return (declarations.find(address) != declarations.end());
|
||||
return declarations.find(address) != declarations.end();
|
||||
}
|
||||
|
||||
void ZFile::GenerateSourceFiles(fs::path outputDir)
|
||||
@@ -558,32 +568,37 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
|
||||
GeneratePlaceholderDeclarations();
|
||||
|
||||
// Generate Code
|
||||
for (ZResource* res : resources)
|
||||
for (size_t i = 0; i < resources.size(); i++)
|
||||
{
|
||||
string resSrc = res->GetSourceOutputCode(name);
|
||||
ZResource* res = resources.at(i);
|
||||
std::string resSrc = res->GetSourceOutputCode(name);
|
||||
|
||||
if (res->IsExternalResource())
|
||||
{
|
||||
string path = Path::GetFileNameWithoutExtension(res->GetName()).c_str();
|
||||
std::string path = Path::GetFileNameWithoutExtension(res->GetName()).c_str();
|
||||
|
||||
string assetOutDir = outputDir / Path::GetFileNameWithoutExtension(res->GetOutName());
|
||||
string declType = res->GetSourceTypeName();
|
||||
std::string assetOutDir =
|
||||
(outputDir / Path::GetFileNameWithoutExtension(res->GetOutName())).string();
|
||||
std::string declType = res->GetSourceTypeName();
|
||||
|
||||
std::string incStr = StringHelper::Sprintf("%s.%s.inc", assetOutDir.c_str(),
|
||||
res->GetExternalExtension().c_str());
|
||||
|
||||
if (res->GetResourceType() == ZResourceType::Texture)
|
||||
{
|
||||
ZTexture* tex = (ZTexture*)res;
|
||||
ZTexture* tex = static_cast<ZTexture*>(res);
|
||||
|
||||
tex->CalcHash();
|
||||
|
||||
// TEXTURE POOL CHECK
|
||||
if (Globals::Instance->cfg.texturePool.find(tex->hash) !=
|
||||
Globals::Instance->cfg.texturePool.end())
|
||||
if (!Globals::Instance->cfg.texturePool.empty())
|
||||
{
|
||||
incStr = Globals::Instance->cfg.texturePool[tex->hash].path.string() + "." +
|
||||
res->GetExternalExtension() + ".inc";
|
||||
tex->CalcHash();
|
||||
|
||||
// TEXTURE POOL CHECK
|
||||
if (Globals::Instance->cfg.texturePool.find(tex->hash) !=
|
||||
Globals::Instance->cfg.texturePool.end())
|
||||
{
|
||||
incStr = Globals::Instance->cfg.texturePool[tex->hash].path.string() + "." +
|
||||
res->GetExternalExtension() + ".inc";
|
||||
}
|
||||
}
|
||||
|
||||
incStr += ".c";
|
||||
@@ -599,7 +614,6 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
|
||||
}
|
||||
else
|
||||
{
|
||||
// cout << "NOT EXTERN\n";
|
||||
sourceOutput += resSrc;
|
||||
}
|
||||
|
||||
@@ -609,8 +623,9 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
|
||||
|
||||
sourceOutput += ProcessDeclarations();
|
||||
|
||||
string outPath =
|
||||
Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".c");
|
||||
std::string outPath =
|
||||
(Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".c"))
|
||||
.string();
|
||||
|
||||
OutputFormatter formatter;
|
||||
formatter.Write(sourceOutput);
|
||||
@@ -626,7 +641,7 @@ void ZFile::GenerateSourceHeaderFiles()
|
||||
|
||||
for (ZResource* res : resources)
|
||||
{
|
||||
string resSrc = res->GetSourceOutputHeader("");
|
||||
std::string resSrc = res->GetSourceOutputHeader("");
|
||||
formatter.Write(resSrc);
|
||||
|
||||
if (resSrc != "")
|
||||
@@ -638,7 +653,7 @@ void ZFile::GenerateSourceHeaderFiles()
|
||||
fs::path headerFilename =
|
||||
Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".h");
|
||||
|
||||
File::WriteAllText(headerFilename, formatter.GetOutput());
|
||||
File::WriteAllText(headerFilename.string(), formatter.GetOutput());
|
||||
}
|
||||
|
||||
void ZFile::GenerateHLIntermediette()
|
||||
@@ -673,6 +688,24 @@ void ZFile::GeneratePlaceholderDeclarations()
|
||||
}
|
||||
}
|
||||
|
||||
void ZFile::AddTextureResource(uint32_t offset, ZTexture* tex)
|
||||
{
|
||||
for (auto res : resources)
|
||||
assert(res->GetRawDataIndex() != offset);
|
||||
|
||||
resources.push_back(tex);
|
||||
texturesResources[offset] = tex;
|
||||
}
|
||||
|
||||
ZTexture* ZFile::GetTextureResource(uint32_t offset) const
|
||||
{
|
||||
auto tex = texturesResources.find(offset);
|
||||
if (tex != texturesResources.end())
|
||||
return tex->second;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::map<std::string, ZResourceFactoryFunc*>* ZFile::GetNodeMap()
|
||||
{
|
||||
static std::map<std::string, ZResourceFactoryFunc*> nodeMap;
|
||||
@@ -685,13 +718,15 @@ void ZFile::RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc)
|
||||
(*nodeMap)[nodeName] = nodeFunc;
|
||||
}
|
||||
|
||||
string ZFile::ProcessDeclarations()
|
||||
std::string ZFile::ProcessDeclarations()
|
||||
{
|
||||
string output = "";
|
||||
std::string output = "";
|
||||
|
||||
if (declarations.size() == 0)
|
||||
return output;
|
||||
|
||||
defines += ProcessTextureIntersections(name);
|
||||
|
||||
// Account for padding/alignment
|
||||
uint32_t lastAddr = 0;
|
||||
uint32_t lastSize = 0;
|
||||
@@ -699,16 +734,14 @@ string ZFile::ProcessDeclarations()
|
||||
// printf("RANGE START: 0x%06X - RANGE END: 0x%06X\n", rangeStart, rangeEnd);
|
||||
|
||||
// Optimization: See if there are any arrays side by side that can be merged...
|
||||
auto declarationKeys =
|
||||
vector<pair<int32_t, Declaration*>>(declarations.begin(), declarations.end());
|
||||
sort(declarationKeys.begin(), declarationKeys.end(),
|
||||
[](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; });
|
||||
std::vector<std::pair<int32_t, Declaration*>> declarationKeys(declarations.begin(),
|
||||
declarations.end());
|
||||
|
||||
pair<int32_t, Declaration*> lastItem = declarationKeys[0];
|
||||
std::pair<int32_t, Declaration*> lastItem = declarationKeys.at(0);
|
||||
|
||||
for (size_t i = 1; i < declarationKeys.size(); i++)
|
||||
{
|
||||
pair<int32_t, Declaration*> curItem = declarationKeys[i];
|
||||
std::pair<int32_t, Declaration*> curItem = declarationKeys[i];
|
||||
|
||||
if (curItem.second->isArray && lastItem.second->isArray)
|
||||
{
|
||||
@@ -737,10 +770,10 @@ string ZFile::ProcessDeclarations()
|
||||
lastItem = curItem;
|
||||
}
|
||||
|
||||
for (pair<uint32_t, Declaration*> item : declarations)
|
||||
for (std::pair<uint32_t, Declaration*> item : declarations)
|
||||
ProcessDeclarationText(item.second);
|
||||
|
||||
for (pair<uint32_t, Declaration*> item : declarations)
|
||||
for (std::pair<uint32_t, Declaration*> item : declarations)
|
||||
{
|
||||
while (item.second->size % 4 != 0)
|
||||
item.second->size++;
|
||||
@@ -865,7 +898,7 @@ string ZFile::ProcessDeclarations()
|
||||
int diff = currentAddress - unaccountedAddress;
|
||||
bool nonZeroUnaccounted = false;
|
||||
|
||||
string src = " ";
|
||||
std::string src = " ";
|
||||
|
||||
for (int i = 0; i < diff; i++)
|
||||
{
|
||||
@@ -927,20 +960,30 @@ string ZFile::ProcessDeclarations()
|
||||
// Go through include declarations
|
||||
// First, handle the prototypes (static only for now)
|
||||
int32_t protoCnt = 0;
|
||||
for (pair<uint32_t, Declaration*> item : declarations)
|
||||
for (std::pair<uint32_t, Declaration*> item : declarations)
|
||||
{
|
||||
if (StringHelper::StartsWith(item.second->varType, "static ") &&
|
||||
!item.second->isUnaccounted)
|
||||
{
|
||||
if (item.second->isArray)
|
||||
{
|
||||
if (item.second->arrayItemCnt == 0)
|
||||
if (item.second->arrayItemCntStr != "")
|
||||
{
|
||||
output += StringHelper::Sprintf("%s %s[%s];\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str(),
|
||||
item.second->arrayItemCntStr.c_str());
|
||||
}
|
||||
else if (item.second->arrayItemCnt == 0)
|
||||
{
|
||||
output += StringHelper::Sprintf("%s %s[];\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
output += StringHelper::Sprintf("%s %s[%i];\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str(),
|
||||
item.second->arrayItemCnt);
|
||||
}
|
||||
}
|
||||
else
|
||||
output += StringHelper::Sprintf("%s %s;\n", item.second->varType.c_str(),
|
||||
@@ -954,7 +997,7 @@ string ZFile::ProcessDeclarations()
|
||||
output += "\n";
|
||||
|
||||
// Next, output the actual declarations
|
||||
for (pair<uint32_t, Declaration*> item : declarations)
|
||||
for (std::pair<uint32_t, Declaration*> item : declarations)
|
||||
{
|
||||
if (item.first < rangeStart || item.first >= rangeEnd)
|
||||
{
|
||||
@@ -963,11 +1006,6 @@ string ZFile::ProcessDeclarations()
|
||||
|
||||
if (item.second->includePath != "")
|
||||
{
|
||||
// output += StringHelper::Sprintf("#include \"%s\"\n",
|
||||
// item.second->includePath.c_str()); output += StringHelper::Sprintf("%s %s[] =
|
||||
// {\n#include \"%s\"\n};\n\n", item.second->varType.c_str(),
|
||||
// item.second->varName.c_str(), item.second->includePath.c_str());
|
||||
|
||||
if (item.second->isExternal)
|
||||
{
|
||||
// HACK
|
||||
@@ -984,48 +1022,28 @@ string ZFile::ProcessDeclarations()
|
||||
item.second->text);
|
||||
}
|
||||
|
||||
/*if (item.second->varType == "u64")
|
||||
output += StringHelper::Sprintf("#pragma INC_ASSET_U64(\"%s\", \"%s\")\n",
|
||||
item.second->varName.c_str(), item.second->includePath.c_str()); else if
|
||||
(item.second->varType == "Gfx") output += StringHelper::Sprintf("#pragma
|
||||
INC_ASSET_GFX(\"%s\", \"%s\")\n", item.second->varName.c_str(),
|
||||
item.second->includePath.c_str()); else if (item.second->varType == "Vtx" ||
|
||||
item.second->varType == "static Vtx") output += StringHelper::Sprintf("#pragma
|
||||
INC_ASSET_VTX(\"%s\", \"%s\")\n", item.second->varName.c_str(),
|
||||
item.second->includePath.c_str()); else output += StringHelper::Sprintf("#pragma
|
||||
INC_ASSET_U8(\"%s\", \"%s\")\n", item.second->varName.c_str(),
|
||||
item.second->includePath.c_str());*/
|
||||
|
||||
// Do not asm_process vertex arrays. They have no practical use being overridden.
|
||||
// if (item.second->varType == "Vtx" || item.second->varType == "static Vtx")
|
||||
if (item.second->varType != "u64" && item.second->varType != "static u64" &&
|
||||
item.second->varType != "u8" && item.second->varType != "static u8")
|
||||
{
|
||||
// output += StringHelper::Sprintf("%s %s[] = {\n #include \"%s\"\n};\n\n",
|
||||
// item.second->varType.c_str(), item.second->varName.c_str(),
|
||||
// StringHelper::Replace(item.second->includePath, "assets/",
|
||||
// "../assets/extracted/").c_str());
|
||||
output += StringHelper::Sprintf(
|
||||
"%s %s[] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str(),
|
||||
StringHelper::Replace(item.second->includePath, "assets/", "../assets/")
|
||||
.c_str());
|
||||
// output += StringHelper::Sprintf("%s %s[] = {\n #include \"%s\"\n};\n\n",
|
||||
// item.second->varType.c_str(), item.second->varName.c_str(),
|
||||
// Path::GetFileName(item.second->includePath).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// output += StringHelper::Sprintf("%s %s[] = {\n #pragma
|
||||
// INC_ASSET(\"%s\")\n};\n\n", item.second->varType.c_str(),
|
||||
// item.second->varName.c_str(), item.second->includePath.c_str()); output +=
|
||||
// StringHelper::Sprintf("%s %s[] = {\n #include \"%s\"\n};\n\n",
|
||||
// item.second->varType.c_str(), item.second->varName.c_str(),
|
||||
// StringHelper::Replace(item.second->includePath, "assets/",
|
||||
// "assets/extracted/").c_str());
|
||||
output += StringHelper::Sprintf(
|
||||
"%s %s[] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str(), item.second->includePath.c_str());
|
||||
if (item.second->arrayItemCntStr != "")
|
||||
output += StringHelper::Sprintf(
|
||||
"%s %s[%s] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str(), item.second->arrayItemCntStr.c_str(),
|
||||
item.second->includePath.c_str());
|
||||
else
|
||||
output += StringHelper::Sprintf(
|
||||
"%s %s[] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str(), item.second->includePath.c_str());
|
||||
}
|
||||
}
|
||||
else if (item.second->varType != "")
|
||||
@@ -1036,14 +1054,23 @@ string ZFile::ProcessDeclarations()
|
||||
{
|
||||
if (item.second->isArray)
|
||||
{
|
||||
if (item.second->arrayItemCnt == 0)
|
||||
output +=
|
||||
StringHelper::Sprintf("%s %s[] = {\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str());
|
||||
else
|
||||
if (item.second->arrayItemCntStr != "")
|
||||
{
|
||||
output += StringHelper::Sprintf(
|
||||
"%s %s[%i] = {\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str(), item.second->arrayItemCnt);
|
||||
"%s %s[%s];\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str(), item.second->arrayItemCntStr.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (item.second->arrayItemCnt == 0)
|
||||
output +=
|
||||
StringHelper::Sprintf("%s %s[] = {\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str());
|
||||
else
|
||||
output += StringHelper::Sprintf(
|
||||
"%s %s[%i] = {\n", item.second->varType.c_str(),
|
||||
item.second->varName.c_str(), item.second->arrayItemCnt);
|
||||
}
|
||||
|
||||
output += item.second->text + "\n";
|
||||
}
|
||||
@@ -1125,11 +1152,11 @@ void ZFile::ProcessDeclarationText(Declaration* decl)
|
||||
}
|
||||
}
|
||||
|
||||
string ZFile::ProcessExterns()
|
||||
std::string ZFile::ProcessExterns()
|
||||
{
|
||||
string output = "";
|
||||
std::string output = "";
|
||||
|
||||
for (pair<uint32_t, Declaration*> item : declarations)
|
||||
for (std::pair<uint32_t, Declaration*> item : declarations)
|
||||
{
|
||||
if (item.first < rangeStart || item.first >= rangeEnd)
|
||||
{
|
||||
@@ -1161,4 +1188,61 @@ string ZFile::ProcessExterns()
|
||||
output += defines;
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
std::string ZFile::ProcessTextureIntersections(std::string prefix)
|
||||
{
|
||||
if (texturesResources.empty())
|
||||
return "";
|
||||
|
||||
std::string defines = "";
|
||||
std::vector<std::pair<uint32_t, ZTexture*>> texturesSorted(texturesResources.begin(),
|
||||
texturesResources.end());
|
||||
|
||||
for (size_t i = 0; i < texturesSorted.size() - 1; i++)
|
||||
{
|
||||
uint32_t currentOffset = texturesSorted[i].first;
|
||||
uint32_t nextOffset = texturesSorted[i + 1].first;
|
||||
auto& currentTex = texturesResources.at(currentOffset);
|
||||
int texSize = currentTex->GetRawDataSize();
|
||||
|
||||
if (currentTex->WasDeclaredInXml())
|
||||
{
|
||||
// We believe the user is right.
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((currentOffset + texSize) > nextOffset)
|
||||
{
|
||||
uint32_t offsetDiff = nextOffset - currentOffset;
|
||||
if (currentTex->isPalette)
|
||||
{
|
||||
// Shrink palette so it doesn't overlap
|
||||
currentTex->SetDimensions(offsetDiff / currentTex->GetPixelMultiplyer(), 1);
|
||||
declarations.at(currentOffset)->size = currentTex->GetRawDataSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string texName = GetDeclarationPtrName(currentOffset);
|
||||
std::string texNextName;
|
||||
|
||||
Declaration* nextDecl = GetDeclaration(nextOffset);
|
||||
if (nextDecl == nullptr)
|
||||
texNextName = texturesResources.at(nextOffset)->GetName();
|
||||
else
|
||||
texNextName = nextDecl->varName;
|
||||
|
||||
defines += StringHelper::Sprintf("#define %s ((u32)%s + 0x%06X)\n",
|
||||
texNextName.c_str(), texName.c_str(), offsetDiff);
|
||||
|
||||
declarations.erase(nextOffset);
|
||||
texturesResources.erase(nextOffset);
|
||||
texturesSorted.erase(texturesSorted.begin() + i + 1);
|
||||
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return defines;
|
||||
}
|
||||
|
||||
+25
-7
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include "Directory.h"
|
||||
#include "ZResource.h"
|
||||
#include "ZTexture.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
enum class ZFileMode
|
||||
@@ -32,6 +33,7 @@ public:
|
||||
std::map<uint32_t, Declaration*> declarations;
|
||||
std::string defines;
|
||||
std::vector<ZResource*> resources;
|
||||
int32_t segment;
|
||||
uint32_t baseAddress, rangeStart, rangeEnd;
|
||||
|
||||
ZFile(const fs::path& nOutPath, std::string nName);
|
||||
@@ -41,7 +43,9 @@ public:
|
||||
~ZFile();
|
||||
|
||||
std::string GetVarName(uint32_t address);
|
||||
std::string GetName();
|
||||
std::string GetName() const;
|
||||
const fs::path& GetXmlFilePath() const;
|
||||
const std::vector<uint8_t>& GetRawData() const;
|
||||
void ExtractResources(fs::path outputDir);
|
||||
void BuildSourceFile(fs::path outputDir);
|
||||
void AddResource(ZResource* res);
|
||||
@@ -59,6 +63,9 @@ public:
|
||||
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size,
|
||||
std::string varType, std::string varName, size_t arrayItemCnt,
|
||||
std::string body, bool isExternal);
|
||||
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size,
|
||||
std::string varType, std::string varName,
|
||||
std::string arrayItemCntStr, std::string body);
|
||||
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
|
||||
DeclarationPadding padding, size_t size, std::string varType,
|
||||
std::string varName, size_t arrayItemCnt, std::string body);
|
||||
@@ -69,15 +76,19 @@ public:
|
||||
Declaration* AddDeclarationIncludeArray(uint32_t address, std::string includePath, size_t size,
|
||||
std::string varType, std::string varName,
|
||||
size_t arrayItemCnt);
|
||||
std::string GetDeclarationName(uint32_t address);
|
||||
std::string GetDeclarationName(uint32_t address, std::string defaultResult);
|
||||
Declaration* GetDeclaration(uint32_t address);
|
||||
Declaration* GetDeclarationRanged(uint32_t address);
|
||||
uint32_t GetDeclarationRangedAddress(uint32_t address);
|
||||
std::string GetDeclarationName(uint32_t address) const;
|
||||
std::string GetDeclarationName(uint32_t address, std::string defaultResult) const;
|
||||
std::string GetDeclarationPtrName(segptr_t segAddress) const;
|
||||
Declaration* GetDeclaration(uint32_t address) const;
|
||||
Declaration* GetDeclarationRanged(uint32_t address) const;
|
||||
uint32_t GetDeclarationRangedAddress(uint32_t address) const;
|
||||
bool HasDeclaration(uint32_t address);
|
||||
std::string GetHeaderInclude();
|
||||
void GeneratePlaceholderDeclarations();
|
||||
|
||||
void AddTextureResource(uint32_t offset, ZTexture* tex);
|
||||
ZTexture* GetTextureResource(uint32_t offset) const;
|
||||
|
||||
static std::map<std::string, ZResourceFactoryFunc*>* GetNodeMap();
|
||||
static void RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc);
|
||||
|
||||
@@ -87,10 +98,15 @@ protected:
|
||||
fs::path basePath;
|
||||
fs::path outputPath;
|
||||
fs::path xmlFilePath;
|
||||
// Keep track of every texture of this ZFile.
|
||||
// The pointers declared here are "borrowed" (somebody else is the owner),
|
||||
// so ZFile shouldn't delete/free those textures.
|
||||
std::map<uint32_t, ZTexture*> texturesResources;
|
||||
|
||||
ZFile();
|
||||
void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename,
|
||||
bool placeholderMode);
|
||||
void DeclareResourceSubReferences();
|
||||
void GenerateSourceFiles(fs::path outputDir);
|
||||
void GenerateSourceHeaderFiles();
|
||||
void GenerateHLIntermediette();
|
||||
@@ -98,4 +114,6 @@ protected:
|
||||
std::string ProcessDeclarations();
|
||||
void ProcessDeclarationText(Declaration* decl);
|
||||
std::string ProcessExterns();
|
||||
};
|
||||
|
||||
std::string ProcessTextureIntersections(std::string prefix);
|
||||
};
|
||||
|
||||
+95
-95
@@ -4,8 +4,6 @@
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
REGISTER_ZFILENODE(Limb, ZLimb);
|
||||
|
||||
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset)
|
||||
@@ -105,12 +103,12 @@ Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawD
|
||||
|
||||
void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
|
||||
{
|
||||
string entryStr;
|
||||
std::string entryStr;
|
||||
|
||||
if (unk_8 != 0)
|
||||
{
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
string unk_8_Str =
|
||||
std::string unk_8_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
|
||||
|
||||
@@ -142,7 +140,7 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
|
||||
if (unk_C != 0)
|
||||
{
|
||||
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
|
||||
string unk_C_Str =
|
||||
std::string unk_C_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
|
||||
|
||||
@@ -173,9 +171,9 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
|
||||
|
||||
std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) const
|
||||
{
|
||||
string entryStr;
|
||||
std::string entryStr;
|
||||
|
||||
string unk_8_Str = "NULL";
|
||||
std::string unk_8_Str = "NULL";
|
||||
|
||||
if (unk_8 != 0)
|
||||
{
|
||||
@@ -185,7 +183,7 @@ std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) cons
|
||||
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
|
||||
}
|
||||
|
||||
string unk_C_Str = "NULL";
|
||||
std::string unk_C_Str = "NULL";
|
||||
|
||||
if (unk_C != 0)
|
||||
{
|
||||
@@ -242,22 +240,16 @@ Struct_800A5E28::~Struct_800A5E28()
|
||||
delete unk_8_dlist;
|
||||
}
|
||||
|
||||
ZLimb::~ZLimb()
|
||||
{
|
||||
for (auto DL : dLists)
|
||||
delete DL;
|
||||
}
|
||||
|
||||
void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
|
||||
{
|
||||
if (unk_4 != 0)
|
||||
{
|
||||
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
|
||||
string unk_4_Str =
|
||||
std::string unk_4_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
|
||||
|
||||
string entryStr = "";
|
||||
std::string entryStr = "";
|
||||
uint16_t arrayItemCnt = unk_4_arr.size();
|
||||
|
||||
size_t i = 0;
|
||||
@@ -294,7 +286,8 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength, parent);
|
||||
|
||||
string dListStr = StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
|
||||
std::string dListStr =
|
||||
StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
|
||||
unk_8_dlist->SetName(dListStr);
|
||||
unk_8_dlist->GetSourceOutputCode(prefix);
|
||||
}
|
||||
@@ -302,9 +295,9 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
|
||||
|
||||
std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) const
|
||||
{
|
||||
string entryStr = "";
|
||||
std::string entryStr = "";
|
||||
|
||||
string unk_4_Str = "NULL";
|
||||
std::string unk_4_Str = "NULL";
|
||||
|
||||
if (unk_4 != 0)
|
||||
{
|
||||
@@ -323,7 +316,7 @@ std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) cons
|
||||
}
|
||||
}
|
||||
|
||||
string unk_8_Str = "NULL";
|
||||
std::string unk_8_Str = "NULL";
|
||||
if (unk_8 != 0)
|
||||
{
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
@@ -357,66 +350,76 @@ ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
dListPtr = 0;
|
||||
dList2Ptr = 0;
|
||||
RegisterOptionalAttribute("LimbType");
|
||||
RegisterOptionalAttribute("Type");
|
||||
}
|
||||
|
||||
ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent)
|
||||
: ZResource(nParent)
|
||||
: ZLimb(nParent)
|
||||
{
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
type = limbType;
|
||||
|
||||
segAddress = nRawDataIndex;
|
||||
name = StringHelper::Sprintf("%sLimb_%06X", prefix.c_str(), GetFileAddress());
|
||||
|
||||
ParseRawData();
|
||||
}
|
||||
|
||||
void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
|
||||
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
}
|
||||
|
||||
void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
|
||||
{
|
||||
ZResource::ParseXML(reader);
|
||||
|
||||
// Reading from a <Skeleton/>
|
||||
const char* limbType = reader->Attribute("LimbType");
|
||||
if (limbType == nullptr) // Reading from a <Limb/>
|
||||
limbType = reader->Attribute("Type");
|
||||
std::string limbType = registeredAttributes.at("LimbType").value;
|
||||
if (limbType == "") // Reading from a <Limb/>
|
||||
limbType = registeredAttributes.at("Type").value;
|
||||
|
||||
if (limbType == nullptr)
|
||||
if (limbType == "")
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ZLimb::ParseXML: Warning in '%s'.\n\t Missing 'LimbType' attribute in xml. "
|
||||
"Defaulting to 'Standard'.\n",
|
||||
"ZLimb::ParseXML: Warning in '%s'.\n"
|
||||
"\t Missing 'LimbType' attribute in xml.\n"
|
||||
"\t Defaulting to 'Standard'.\n",
|
||||
name.c_str());
|
||||
type = ZLimbType::Standard;
|
||||
}
|
||||
else
|
||||
{
|
||||
string limbTypeStr(limbType);
|
||||
|
||||
if (limbTypeStr == "Standard")
|
||||
if (limbType == "Standard")
|
||||
{
|
||||
type = ZLimbType::Standard;
|
||||
}
|
||||
else if (limbTypeStr == "LOD")
|
||||
else if (limbType == "LOD")
|
||||
{
|
||||
type = ZLimbType::LOD;
|
||||
}
|
||||
else if (limbTypeStr == "Skin")
|
||||
else if (limbType == "Skin")
|
||||
{
|
||||
type = ZLimbType::Skin;
|
||||
}
|
||||
else if (limbTypeStr == "Curve")
|
||||
else if (limbType == "Curve")
|
||||
{
|
||||
type = ZLimbType::Curve;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ZLimb::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. "
|
||||
"Defaulting to 'Standard'.\n",
|
||||
name.c_str(), limbType);
|
||||
"ZLimb::ParseXML: Warning in '%s'.\n"
|
||||
"\t Invalid LimbType found: '%s'.\n"
|
||||
"\t Defaulting to 'Standard'.\n",
|
||||
name.c_str(), limbType.c_str());
|
||||
type = ZLimbType::Standard;
|
||||
}
|
||||
}
|
||||
@@ -424,6 +427,8 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
|
||||
|
||||
void ZLimb::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
if (type == ZLimbType::Curve)
|
||||
{
|
||||
childIndex = rawData.at(rawDataIndex + 0);
|
||||
@@ -445,14 +450,20 @@ void ZLimb::ParseRawData()
|
||||
{
|
||||
case ZLimbType::LOD:
|
||||
dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
|
||||
// Intended fallthrough
|
||||
case ZLimbType::Standard:
|
||||
dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
|
||||
|
||||
break;
|
||||
|
||||
case ZLimbType::Skin:
|
||||
skinSegmentType =
|
||||
static_cast<ZLimbSkinType>(BitConverter::ToInt32BE(rawData, rawDataIndex + 8));
|
||||
skinSegment = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
|
||||
if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0)
|
||||
{
|
||||
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
|
||||
segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Invalid ZLimb type");
|
||||
@@ -460,26 +471,7 @@ void ZLimb::ParseRawData()
|
||||
}
|
||||
}
|
||||
|
||||
void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex, const std::string& nRelPath)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
|
||||
segAddress = nRawDataIndex;
|
||||
|
||||
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
|
||||
if (type == ZLimbType::Skin)
|
||||
{
|
||||
if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0)
|
||||
{
|
||||
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
|
||||
segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t ZLimb::GetRawDataSize()
|
||||
size_t ZLimb::GetRawDataSize() const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@@ -494,23 +486,14 @@ size_t ZLimb::GetRawDataSize()
|
||||
return 0x0C;
|
||||
}
|
||||
|
||||
string ZLimb::GetSourceOutputCode(const std::string& prefix)
|
||||
std::string ZLimb::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
string dListStr = "NULL";
|
||||
string dListStr2 = "NULL";
|
||||
std::string limbPrefix = type == ZLimbType::Curve ? "Curve" : "";
|
||||
std::string dListStr = GetLimbDListSourceOutputCode(prefix, limbPrefix, dListPtr);
|
||||
limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far";
|
||||
std::string dListStr2 = GetLimbDListSourceOutputCode(prefix, limbPrefix, dList2Ptr);
|
||||
|
||||
if (dListPtr != 0)
|
||||
{
|
||||
string limbPrefix = type == ZLimbType::Curve ? "Curve" : "";
|
||||
dListStr = GetLimbDListSourceOutputCode(prefix, limbPrefix, dListPtr);
|
||||
}
|
||||
if (dList2Ptr != 0)
|
||||
{
|
||||
string limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far";
|
||||
dListStr2 = GetLimbDListSourceOutputCode(prefix, limbPrefix, dList2Ptr);
|
||||
}
|
||||
|
||||
string entryStr = "";
|
||||
std::string entryStr = "";
|
||||
if (type != ZLimbType::Curve)
|
||||
{
|
||||
entryStr += StringHelper::Sprintf("\n { %i, %i, %i },", transX, transY, transZ);
|
||||
@@ -543,12 +526,12 @@ string ZLimb::GetSourceOutputCode(const std::string& prefix)
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZLimb::GetSourceTypeName()
|
||||
std::string ZLimb::GetSourceTypeName() const
|
||||
{
|
||||
return GetSourceTypeName(type);
|
||||
}
|
||||
|
||||
ZResourceType ZLimb::GetResourceType()
|
||||
ZResourceType ZLimb::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::Limb;
|
||||
}
|
||||
@@ -582,9 +565,10 @@ const char* ZLimb::GetSourceTypeName(ZLimbType limbType)
|
||||
|
||||
uint32_t ZLimb::GetFileAddress()
|
||||
{
|
||||
return Seg2Filespace(segAddress, parent->baseAddress);
|
||||
return Seg2Filespace(rawDataIndex, parent->baseAddress);
|
||||
}
|
||||
|
||||
// Returns the ptrname of a dlist. Declares it if it has not been declared yet.
|
||||
std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix,
|
||||
const std::string& limbPrefix, segptr_t dListPtr)
|
||||
{
|
||||
@@ -592,26 +576,42 @@ std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix,
|
||||
return "NULL";
|
||||
|
||||
uint32_t dListOffset = Seg2Filespace(dListPtr, parent->baseAddress);
|
||||
string dListStr;
|
||||
|
||||
// Check if pointing past the object's size
|
||||
if (dListOffset > parent->GetRawData().size())
|
||||
return StringHelper::Sprintf("0x%08X", dListPtr);
|
||||
|
||||
// Check if it is already declared
|
||||
Declaration* decl = parent->GetDeclaration(dListOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
dListStr = StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(),
|
||||
dListOffset);
|
||||
if (decl != nullptr)
|
||||
return decl->varName;
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
rawData, dListOffset,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
auto dList = new ZDisplayList(rawData, dListOffset, dlistLength, parent);
|
||||
dLists.push_back(dList);
|
||||
dList->SetName(dListStr);
|
||||
dList->GetSourceOutputCode(prefix);
|
||||
}
|
||||
else
|
||||
// Check if it points to the middle of a DList
|
||||
decl = parent->GetDeclarationRanged(dListOffset);
|
||||
if (decl != nullptr)
|
||||
{
|
||||
dListStr = decl->varName;
|
||||
// TODO: Figure out a way to not hardcode the "Gfx" type.
|
||||
if (decl->varType == "Gfx")
|
||||
{
|
||||
uint32_t declAddress = parent->GetDeclarationRangedAddress(dListOffset);
|
||||
if (dListOffset < declAddress + decl->size)
|
||||
{
|
||||
uint32_t index = (dListOffset - declAddress) / 8;
|
||||
return StringHelper::Sprintf("&%s[%u]", decl->varName.c_str(), index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the DList
|
||||
std::string dListStr =
|
||||
StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), dListOffset);
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
rawData, dListOffset,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
auto dList = new ZDisplayList(rawData, dListOffset, dlistLength, parent);
|
||||
dList->SetName(dListStr);
|
||||
dList->GetSourceOutputCode(prefix);
|
||||
return dListStr;
|
||||
}
|
||||
|
||||
@@ -625,7 +625,7 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
|
||||
|
||||
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
|
||||
|
||||
string struct_800A5E28_Str;
|
||||
std::string struct_800A5E28_Str;
|
||||
Declaration* decl = parent->GetDeclaration(skinSegmentOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
@@ -634,7 +634,7 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
|
||||
Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset);
|
||||
|
||||
segmentStruct.PreGenSourceFiles(prefix);
|
||||
string entryStr = segmentStruct.GetSourceOutputCode(prefix);
|
||||
std::string entryStr = segmentStruct.GetSourceOutputCode(prefix);
|
||||
|
||||
parent->AddDeclaration(skinSegmentOffset, DeclarationAlignment::None,
|
||||
Struct_800A5E28::GetRawDataSize(),
|
||||
@@ -652,7 +652,7 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
|
||||
{
|
||||
assert(type == ZLimbType::Skin);
|
||||
|
||||
string skinSegmentStr = "NULL";
|
||||
std::string skinSegmentStr = "NULL";
|
||||
|
||||
if (skinSegment != 0)
|
||||
{
|
||||
@@ -681,7 +681,7 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
|
||||
}
|
||||
}
|
||||
|
||||
string entryStr =
|
||||
std::string entryStr =
|
||||
StringHelper::Sprintf(" 0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str());
|
||||
|
||||
return entryStr;
|
||||
|
||||
+7
-10
@@ -120,7 +120,6 @@ public:
|
||||
class ZLimb : public ZResource
|
||||
{
|
||||
protected:
|
||||
segptr_t segAddress;
|
||||
ZLimbType type = ZLimbType::Standard;
|
||||
|
||||
ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only
|
||||
@@ -135,27 +134,25 @@ protected:
|
||||
std::string GetSourceOutputCodeSkin_Type_4(const std::string& prefix);
|
||||
|
||||
public:
|
||||
ZDisplayList* dList;
|
||||
segptr_t dListPtr = 0;
|
||||
segptr_t farDListPtr = 0; // LOD only
|
||||
int16_t transX, transY, transZ;
|
||||
uint8_t childIndex, siblingIndex;
|
||||
std::vector<ZDisplayList*> dLists;
|
||||
std::vector<ZLimb*> children;
|
||||
|
||||
ZLimb(ZFile* nParent);
|
||||
ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent);
|
||||
~ZLimb();
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex) override;
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
|
||||
size_t GetRawDataSize() override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
std::string GetSourceTypeName() override;
|
||||
ZResourceType GetResourceType() override;
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
ZLimbType GetLimbType();
|
||||
void SetLimbType(ZLimbType value);
|
||||
|
||||
@@ -14,7 +14,7 @@ ZMtx::ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint
|
||||
: ZResource(nParent)
|
||||
{
|
||||
name = GetDefaultName(prefix.c_str(), rawDataIndex);
|
||||
ExtractFromFile(nRawData, nRawDataIndex, "");
|
||||
ExtractFromFile(nRawData, nRawDataIndex);
|
||||
DeclareVar("", "");
|
||||
}
|
||||
|
||||
@@ -28,18 +28,18 @@ void ZMtx::ParseRawData()
|
||||
}
|
||||
|
||||
void ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, const std::string& nRelPath)
|
||||
uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
DeclareVar("", "");
|
||||
}
|
||||
|
||||
size_t ZMtx::GetRawDataSize()
|
||||
size_t ZMtx::GetRawDataSize() const
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
void ZMtx::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
void ZMtx::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
|
||||
{
|
||||
std::string auxName = name;
|
||||
|
||||
@@ -86,12 +86,12 @@ std::string ZMtx::GetDefaultName(const std::string& prefix, uint32_t address)
|
||||
return StringHelper::Sprintf("%sMtx_%06X", prefix.c_str(), address);
|
||||
}
|
||||
|
||||
std::string ZMtx::GetSourceTypeName()
|
||||
std::string ZMtx::GetSourceTypeName() const
|
||||
{
|
||||
return "Mtx";
|
||||
}
|
||||
|
||||
ZResourceType ZMtx::GetResourceType()
|
||||
ZResourceType ZMtx::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::Mtx;
|
||||
}
|
||||
|
||||
@@ -6,26 +6,26 @@
|
||||
|
||||
class ZMtx : public ZResource
|
||||
{
|
||||
protected:
|
||||
std::array<std::array<int32_t, 4>, 4> mtx;
|
||||
|
||||
public:
|
||||
// ZMtx() = default;
|
||||
ZMtx(ZFile* nParent);
|
||||
ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, const std::string& nRelPath) override;
|
||||
uint32_t nRawDataIndex) override;
|
||||
|
||||
size_t GetRawDataSize() override;
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr) const;
|
||||
|
||||
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;
|
||||
|
||||
protected:
|
||||
std::array<std::array<int32_t, 4>, 4> mtx;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
#include "ZPath.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
REGISTER_ZFILENODE(Path, ZPath);
|
||||
|
||||
ZPath::ZPath(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
numPaths = 1;
|
||||
RegisterOptionalAttribute("NumPaths", "1");
|
||||
}
|
||||
|
||||
void ZPath::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
|
||||
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, pathways.size() * 8,
|
||||
GetSourceTypeName(), name, pathways.size(), "");
|
||||
}
|
||||
|
||||
void ZPath::ParseXML(tinyxml2::XMLElement* reader)
|
||||
{
|
||||
ZResource::ParseXML(reader);
|
||||
|
||||
numPaths = StringHelper::StrToL(registeredAttributes.at("NumPaths").value);
|
||||
|
||||
if (numPaths < 1)
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("ZPath::ParseXML: Fatal error in '%s'.\n"
|
||||
"\t Invalid value for attribute 'NumPaths': '%i'\n",
|
||||
name.c_str(), numPaths));
|
||||
}
|
||||
|
||||
void ZPath::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
uint32_t currentPtr = rawDataIndex;
|
||||
|
||||
for (size_t pathIndex = 0; pathIndex < numPaths; pathIndex++)
|
||||
{
|
||||
PathwayEntry path(parent);
|
||||
path.SetRawDataIndex(currentPtr);
|
||||
path.ParseRawData();
|
||||
|
||||
if (path.GetListAddress() == 0)
|
||||
break;
|
||||
|
||||
currentPtr += path.GetRawDataSize();
|
||||
pathways.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
void ZPath::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
ZResource::DeclareReferences(prefix);
|
||||
|
||||
for (auto& entry : pathways)
|
||||
entry.DeclareReferences(prefix);
|
||||
}
|
||||
|
||||
std::string ZPath::GetBodySourceCode() const
|
||||
{
|
||||
std::string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& entry : pathways)
|
||||
{
|
||||
declaration += StringHelper::Sprintf("\t{ %s },", entry.GetBodySourceCode().c_str());
|
||||
|
||||
if (index < pathways.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return declaration;
|
||||
}
|
||||
|
||||
std::string ZPath::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string declaration = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr || decl->isPlaceholder)
|
||||
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, pathways.size() * 8,
|
||||
GetSourceTypeName(), name, pathways.size(), declaration);
|
||||
else
|
||||
decl->text = declaration;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZPath::GetSourceTypeName() const
|
||||
{
|
||||
return "Path";
|
||||
}
|
||||
|
||||
ZResourceType ZPath::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::Path;
|
||||
}
|
||||
|
||||
size_t ZPath::GetRawDataSize() const
|
||||
{
|
||||
return pathways.size() * pathways.at(0).GetRawDataSize();
|
||||
}
|
||||
|
||||
void ZPath::SetNumPaths(uint32_t nNumPaths)
|
||||
{
|
||||
numPaths = nNumPaths;
|
||||
}
|
||||
|
||||
/* PathwayEntry */
|
||||
|
||||
PathwayEntry::PathwayEntry(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void PathwayEntry::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
auto parentRawData = parent->GetRawData();
|
||||
numPoints = parentRawData.at(rawDataIndex + 0);
|
||||
unk1 = parentRawData.at(rawDataIndex + 1);
|
||||
unk2 = BitConverter::ToInt16BE(parentRawData, rawDataIndex + 2);
|
||||
listSegmentAddress = BitConverter::ToInt32BE(parentRawData, rawDataIndex + 4);
|
||||
|
||||
uint32_t currentPtr = GETSEGOFFSET(listSegmentAddress);
|
||||
|
||||
for (int32_t i = 0; i < numPoints; i++)
|
||||
{
|
||||
ZVector vec(parent);
|
||||
vec.SetRawData(parentRawData);
|
||||
vec.SetRawDataIndex(currentPtr);
|
||||
vec.SetScalarType(ZScalarType::ZSCALAR_S16);
|
||||
vec.SetDimensions(3);
|
||||
vec.ParseRawData();
|
||||
|
||||
currentPtr += vec.GetRawDataSize();
|
||||
points.push_back(vec);
|
||||
}
|
||||
}
|
||||
|
||||
void PathwayEntry::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
ZResource::DeclareReferences(prefix);
|
||||
if (points.empty())
|
||||
return;
|
||||
|
||||
std::string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& point : points)
|
||||
{
|
||||
declaration += StringHelper::Sprintf("\t%s,", point.GetBodySourceCode().c_str());
|
||||
|
||||
if (index < points.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(GETSEGOFFSET(listSegmentAddress));
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(GETSEGOFFSET(listSegmentAddress), DeclarationAlignment::Align4,
|
||||
DeclarationPadding::Pad4, points.size() * 6,
|
||||
points.at(0).GetSourceTypeName(),
|
||||
StringHelper::Sprintf("%sPathwayList0x%06X", prefix.c_str(),
|
||||
GETSEGOFFSET(listSegmentAddress)),
|
||||
points.size(), declaration);
|
||||
}
|
||||
else
|
||||
decl->text = declaration;
|
||||
}
|
||||
|
||||
std::string PathwayEntry::GetBodySourceCode() const
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string listName = parent->GetDeclarationPtrName(listSegmentAddress);
|
||||
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
declaration +=
|
||||
StringHelper::Sprintf("%i, %i, %i, %s", numPoints, unk1, unk2, listName.c_str());
|
||||
else
|
||||
declaration += StringHelper::Sprintf("%i, %s", numPoints, listName.c_str());
|
||||
|
||||
return declaration;
|
||||
}
|
||||
|
||||
std::string PathwayEntry::GetSourceTypeName() const
|
||||
{
|
||||
return "Path";
|
||||
}
|
||||
|
||||
ZResourceType PathwayEntry::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::Path;
|
||||
}
|
||||
|
||||
size_t PathwayEntry::GetRawDataSize() const
|
||||
{
|
||||
return 0x08;
|
||||
}
|
||||
|
||||
segptr_t PathwayEntry::GetListAddress() const
|
||||
{
|
||||
return listSegmentAddress;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include "ZResource.h"
|
||||
#include "ZVector.h"
|
||||
|
||||
class PathwayEntry : public ZResource
|
||||
{
|
||||
public:
|
||||
PathwayEntry(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const;
|
||||
segptr_t GetListAddress() const;
|
||||
|
||||
protected:
|
||||
int32_t numPoints;
|
||||
int8_t unk1; // (MM Only)
|
||||
int16_t unk2; // (MM Only)
|
||||
segptr_t listSegmentAddress;
|
||||
std::vector<ZVector> points;
|
||||
};
|
||||
|
||||
class ZPath : public ZResource
|
||||
{
|
||||
public:
|
||||
ZPath(ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex);
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
void SetNumPaths(uint32_t nNumPaths);
|
||||
|
||||
protected:
|
||||
uint32_t numPaths;
|
||||
std::vector<PathwayEntry> pathways;
|
||||
};
|
||||
+118
-61
@@ -1,87 +1,123 @@
|
||||
#include "ZResource.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <regex>
|
||||
#include "StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
#include "ZFile.h"
|
||||
|
||||
ZResource::ZResource(ZFile* nParent)
|
||||
{
|
||||
// assert(nParent != nullptr);
|
||||
parent = nParent;
|
||||
name = "";
|
||||
outName = "";
|
||||
relativePath = "";
|
||||
sourceOutput = "";
|
||||
rawData = vector<uint8_t>();
|
||||
rawDataIndex = 0;
|
||||
outputDeclaration = true;
|
||||
|
||||
RegisterRequiredAttribute("Name");
|
||||
RegisterOptionalAttribute("OutName");
|
||||
RegisterOptionalAttribute("Offset");
|
||||
RegisterOptionalAttribute("Custom");
|
||||
}
|
||||
|
||||
void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex, const std::string& nRelPath)
|
||||
const uint32_t nRawDataIndex)
|
||||
{
|
||||
rawData = nRawData;
|
||||
rawDataIndex = nRawDataIndex;
|
||||
relativePath = nRelPath;
|
||||
|
||||
if (reader != nullptr)
|
||||
ParseXML(reader);
|
||||
|
||||
ParseRawData();
|
||||
CalcHash();
|
||||
}
|
||||
|
||||
void ZResource::ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
const std::string& nRelPath)
|
||||
void ZResource::ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex)
|
||||
{
|
||||
rawData = nRawData;
|
||||
rawDataIndex = nRawDataIndex;
|
||||
relativePath = nRelPath;
|
||||
|
||||
ParseRawData();
|
||||
CalcHash();
|
||||
}
|
||||
|
||||
void ZResource::ParseXML(tinyxml2::XMLElement* reader)
|
||||
{
|
||||
if (reader != nullptr)
|
||||
{
|
||||
if (reader->Attribute("Name") != nullptr)
|
||||
// If it is an inner node, then 'Name' isn't required
|
||||
if (isInner)
|
||||
{
|
||||
name = reader->Attribute("Name");
|
||||
static std::regex r("[a-zA-Z_]+[a-zA-Z0-9_]*",
|
||||
std::regex::icase | std::regex::optimize);
|
||||
|
||||
if (!std::regex_match(name, r))
|
||||
{
|
||||
throw std::domain_error(
|
||||
StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n\t Resource "
|
||||
"with invalid 'Name' attribute.\n",
|
||||
name.c_str()));
|
||||
}
|
||||
registeredAttributes.at("Name").isRequired = false;
|
||||
}
|
||||
else
|
||||
name = "";
|
||||
|
||||
if (reader->Attribute("OutName") != nullptr)
|
||||
outName = reader->Attribute("OutName");
|
||||
else
|
||||
outName = name;
|
||||
auto attrs = reader->FirstAttribute();
|
||||
while (attrs != nullptr)
|
||||
{
|
||||
std::string attrName = attrs->Name();
|
||||
bool attrDeclared = false;
|
||||
|
||||
if (reader->Attribute("Custom") != nullptr)
|
||||
isCustomAsset = true;
|
||||
else
|
||||
isCustomAsset = false;
|
||||
if (registeredAttributes.find(attrName) != registeredAttributes.end())
|
||||
{
|
||||
registeredAttributes[attrName].value = attrs->Value();
|
||||
registeredAttributes[attrName].wasSet = true;
|
||||
attrDeclared = true;
|
||||
}
|
||||
|
||||
if (!attrDeclared)
|
||||
fprintf(stderr,
|
||||
"ZResource::ParseXML: Warning while parsing '%s'.\n"
|
||||
"\t Unexpected '%s' attribute in resource '%s'.\n",
|
||||
parent->GetName().c_str(), attrName.c_str(), reader->Name());
|
||||
attrs = attrs->Next();
|
||||
}
|
||||
|
||||
if (!canHaveInner && !reader->NoChildren())
|
||||
{
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n\t Resource '%s' "
|
||||
"with inner element/child detected.\n",
|
||||
StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n"
|
||||
"\t Resource '%s' with inner element/child detected.\n",
|
||||
name.c_str(), reader->Name()));
|
||||
}
|
||||
|
||||
for (const auto& attr : registeredAttributes)
|
||||
{
|
||||
if (attr.second.isRequired && attr.second.value == "")
|
||||
throw std::runtime_error(StringHelper::Sprintf(
|
||||
"ZResource::ParseXML: Fatal error while parsing '%s'.\n"
|
||||
"\t Missing required attribute '%s' in resource '%s'.\n"
|
||||
"\t Aborting...",
|
||||
parent->GetName().c_str(), attr.first.c_str(), reader->Name()));
|
||||
}
|
||||
|
||||
name = registeredAttributes.at("Name").value;
|
||||
|
||||
static std::regex r("[a-zA-Z_]+[a-zA-Z0-9_]*", std::regex::icase | std::regex::optimize);
|
||||
|
||||
if (!isInner || (isInner && name != ""))
|
||||
{
|
||||
if (!std::regex_match(name, r))
|
||||
{
|
||||
throw std::domain_error(
|
||||
StringHelper::Sprintf("ZResource::ParseXML: Fatal error in '%s'.\n"
|
||||
"\t Resource with invalid 'Name' attribute.\n",
|
||||
name.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
outName = registeredAttributes.at("OutName").value;
|
||||
if (outName == "")
|
||||
outName = name;
|
||||
|
||||
isCustomAsset = registeredAttributes["Custom"].wasSet;
|
||||
|
||||
declaredInXml = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ZResource::Save(const std::string& outFolder)
|
||||
void ZResource::Save(const fs::path& outFolder)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -89,64 +125,59 @@ void ZResource::PreGenSourceFiles()
|
||||
{
|
||||
}
|
||||
|
||||
string ZResource::GetName()
|
||||
const std::string& ZResource::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string ZResource::GetOutName()
|
||||
const std::string& ZResource::GetOutName() const
|
||||
{
|
||||
return outName;
|
||||
}
|
||||
|
||||
void ZResource::SetOutName(std::string nName)
|
||||
void ZResource::SetOutName(const std::string& nName)
|
||||
{
|
||||
outName = nName;
|
||||
}
|
||||
|
||||
void ZResource::SetName(string nName)
|
||||
void ZResource::SetName(const std::string& nName)
|
||||
{
|
||||
name = std::move(nName);
|
||||
name = nName;
|
||||
}
|
||||
|
||||
bool ZResource::IsExternalResource()
|
||||
bool ZResource::IsExternalResource() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ZResource::DoesSupportArray()
|
||||
bool ZResource::DoesSupportArray() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string ZResource::GetExternalExtension()
|
||||
std::string ZResource::GetExternalExtension() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string ZResource::GetRelativePath()
|
||||
{
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
vector<uint8_t> ZResource::GetRawData()
|
||||
const std::vector<uint8_t>& ZResource::GetRawData() const
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
|
||||
void ZResource::SetRawData(std::vector<uint8_t> nData)
|
||||
void ZResource::SetRawData(const std::vector<uint8_t>& nData)
|
||||
{
|
||||
rawData = nData;
|
||||
}
|
||||
|
||||
uint32_t ZResource::GetRawDataIndex()
|
||||
bool ZResource::WasDeclaredInXml() const
|
||||
{
|
||||
return rawDataIndex;
|
||||
return declaredInXml;
|
||||
}
|
||||
|
||||
size_t ZResource::GetRawDataSize()
|
||||
uint32_t ZResource::GetRawDataIndex() const
|
||||
{
|
||||
return rawData.size();
|
||||
return rawDataIndex;
|
||||
}
|
||||
|
||||
void ZResource::SetRawDataIndex(uint32_t value)
|
||||
@@ -154,12 +185,17 @@ void ZResource::SetRawDataIndex(uint32_t value)
|
||||
rawDataIndex = value;
|
||||
}
|
||||
|
||||
string ZResource::GetSourceOutputCode(const std::string& prefix)
|
||||
std::string ZResource::GetBodySourceCode() const
|
||||
{
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
std::string ZResource::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string ZResource::GetSourceOutputHeader(const std::string& prefix)
|
||||
std::string ZResource::GetSourceOutputHeader(const std::string& prefix)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
@@ -168,16 +204,20 @@ void ZResource::ParseRawData()
|
||||
{
|
||||
}
|
||||
|
||||
void ZResource::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
}
|
||||
|
||||
void ZResource::GenerateHLIntermediette(HLFileIntermediette& hlFile)
|
||||
{
|
||||
}
|
||||
|
||||
std::string ZResource::GetSourceTypeName()
|
||||
std::string ZResource::GetSourceTypeName() const
|
||||
{
|
||||
return "u8";
|
||||
}
|
||||
|
||||
ZResourceType ZResource::GetResourceType()
|
||||
ZResourceType ZResource::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::Error;
|
||||
}
|
||||
@@ -187,6 +227,27 @@ void ZResource::CalcHash()
|
||||
hash = 0;
|
||||
}
|
||||
|
||||
void ZResource::SetInnerNode(bool inner)
|
||||
{
|
||||
isInner = inner;
|
||||
}
|
||||
|
||||
void ZResource::RegisterRequiredAttribute(const std::string& attr)
|
||||
{
|
||||
ResourceAttribute resAtrr;
|
||||
resAtrr.key = attr;
|
||||
resAtrr.isRequired = true;
|
||||
registeredAttributes[attr] = resAtrr;
|
||||
}
|
||||
|
||||
void ZResource::RegisterOptionalAttribute(const std::string& attr, const std::string& defaultValue)
|
||||
{
|
||||
ResourceAttribute resAtrr;
|
||||
resAtrr.key = attr;
|
||||
resAtrr.value = defaultValue;
|
||||
registeredAttributes[attr] = resAtrr;
|
||||
}
|
||||
|
||||
uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress)
|
||||
{
|
||||
uint32_t currentPtr = GETSEGOFFSET(segmentedAddress);
|
||||
@@ -196,7 +257,3 @@ uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress)
|
||||
|
||||
return currentPtr;
|
||||
}
|
||||
|
||||
ZResource::~ZResource()
|
||||
{
|
||||
}
|
||||
+65
-92
@@ -5,8 +5,11 @@
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Declaration.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include "Directory.h"
|
||||
|
||||
#define SEGMENT_SCENE 2
|
||||
#define SEGMENT_ROOM 3
|
||||
#define SEGMENT_KEEP 4
|
||||
@@ -22,151 +25,121 @@ typedef uint32_t segptr_t;
|
||||
class ZFile;
|
||||
class HLFileIntermediette;
|
||||
|
||||
class Declaration;
|
||||
struct CommandSet;
|
||||
|
||||
enum class ZResourceType
|
||||
{
|
||||
Error,
|
||||
Texture,
|
||||
DisplayList,
|
||||
Room,
|
||||
Animation,
|
||||
Cutscene,
|
||||
Array,
|
||||
Background,
|
||||
Blob,
|
||||
CollisionHeader,
|
||||
Cutscene,
|
||||
DisplayList,
|
||||
Limb,
|
||||
Skeleton,
|
||||
Mtx,
|
||||
Path,
|
||||
Room,
|
||||
RoomCommand,
|
||||
Scalar,
|
||||
Skeleton,
|
||||
String,
|
||||
Symbol,
|
||||
Texture,
|
||||
Vector,
|
||||
Vertex,
|
||||
CollisionHeader,
|
||||
Symbol,
|
||||
Mtx,
|
||||
Background,
|
||||
};
|
||||
|
||||
class ResourceAttribute
|
||||
{
|
||||
public:
|
||||
std::string key = "";
|
||||
std::string value = "";
|
||||
bool isRequired = false;
|
||||
bool wasSet = false;
|
||||
};
|
||||
|
||||
class ZResource
|
||||
{
|
||||
public:
|
||||
ZFile* parent;
|
||||
bool outputDeclaration;
|
||||
uint32_t hash;
|
||||
bool outputDeclaration = true;
|
||||
uint32_t hash = 0;
|
||||
|
||||
ZResource(ZFile* nParent);
|
||||
virtual ~ZResource();
|
||||
virtual ~ZResource() = default;
|
||||
|
||||
// Parsing from File
|
||||
virtual void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex,
|
||||
const std::string& nRelPath); // Extract Mode
|
||||
virtual void ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
const std::string& nRelPath);
|
||||
uint32_t nRawDataIndex);
|
||||
virtual void ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex);
|
||||
|
||||
// Misc
|
||||
virtual void ParseXML(tinyxml2::XMLElement* reader);
|
||||
virtual void ParseRawData();
|
||||
virtual void DeclareReferences(const std::string& prefix);
|
||||
virtual std::string GetBodySourceCode() const;
|
||||
|
||||
virtual std::string GetSourceOutputCode(const std::string& prefix);
|
||||
virtual std::string GetSourceOutputHeader(const std::string& prefix);
|
||||
virtual void PreGenSourceFiles();
|
||||
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile);
|
||||
virtual void CalcHash();
|
||||
virtual void Save(const std::string& outFolder);
|
||||
virtual void Save(const fs::path& outFolder);
|
||||
|
||||
// Properties
|
||||
virtual bool IsExternalResource();
|
||||
virtual bool DoesSupportArray(); // Can this type be wrapped in an <Array> node?
|
||||
virtual std::string GetSourceTypeName();
|
||||
virtual ZResourceType GetResourceType();
|
||||
virtual std::string GetExternalExtension();
|
||||
virtual bool IsExternalResource() const;
|
||||
virtual bool DoesSupportArray() const; // Can this type be wrapped in an <Array> node?
|
||||
virtual std::string GetSourceTypeName() const;
|
||||
virtual ZResourceType GetResourceType() const = 0;
|
||||
virtual std::string GetExternalExtension() const;
|
||||
|
||||
// Getters/Setters
|
||||
std::string GetName();
|
||||
void SetName(std::string nName);
|
||||
std::string GetOutName();
|
||||
void SetOutName(std::string nName);
|
||||
std::string GetRelativePath();
|
||||
virtual uint32_t GetRawDataIndex();
|
||||
const std::string& GetName() const;
|
||||
void SetName(const std::string& nName);
|
||||
const std::string& GetOutName() const;
|
||||
void SetOutName(const std::string& nName);
|
||||
virtual uint32_t GetRawDataIndex() const;
|
||||
virtual void SetRawDataIndex(uint32_t value);
|
||||
virtual size_t GetRawDataSize();
|
||||
virtual std::vector<uint8_t> GetRawData();
|
||||
virtual void SetRawData(std::vector<uint8_t> nData);
|
||||
virtual size_t GetRawDataSize() const = 0;
|
||||
virtual const std::vector<uint8_t>& GetRawData() const;
|
||||
virtual void SetRawData(const std::vector<uint8_t>& nData);
|
||||
void SetInnerNode(bool inner);
|
||||
bool WasDeclaredInXml() const;
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
std::string outName;
|
||||
std::string relativePath;
|
||||
std::vector<uint8_t> rawData;
|
||||
uint32_t rawDataIndex;
|
||||
std::string sourceOutput;
|
||||
bool isInner = false; // Is this resource an inner node of another resource? inside of <Array>
|
||||
bool canHaveInner = false; // Can this type have an inner node?
|
||||
bool isCustomAsset; // If set to true, create a reference for the asset in the file, but don't
|
||||
// actually try to extract it from the file
|
||||
};
|
||||
bool declaredInXml = false;
|
||||
|
||||
enum class DeclarationAlignment
|
||||
{
|
||||
None,
|
||||
Align4,
|
||||
Align8,
|
||||
Align16
|
||||
};
|
||||
// Reading from this XMLs attributes should be performed in the overrided `ParseXML` method.
|
||||
std::map<std::string, ResourceAttribute> registeredAttributes;
|
||||
|
||||
enum class DeclarationPadding
|
||||
{
|
||||
None,
|
||||
Pad4,
|
||||
Pad8,
|
||||
Pad16
|
||||
};
|
||||
// XML attributes registers.
|
||||
// Registering XML attributes should be done in constructors.
|
||||
|
||||
class Declaration
|
||||
{
|
||||
public:
|
||||
DeclarationAlignment alignment;
|
||||
DeclarationPadding padding;
|
||||
size_t size;
|
||||
std::string preText;
|
||||
std::string text;
|
||||
std::string rightText;
|
||||
std::string postText;
|
||||
std::string preComment;
|
||||
std::string postComment;
|
||||
std::string varType;
|
||||
std::string varName;
|
||||
std::string includePath;
|
||||
bool isExternal;
|
||||
bool isArray;
|
||||
size_t arrayItemCnt;
|
||||
std::vector<uint32_t> references;
|
||||
bool isUnaccounted = 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, 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);
|
||||
// The resource needs this attribute. If it is not provided, then the program will throw an
|
||||
// exception.
|
||||
void RegisterRequiredAttribute(const std::string& attr);
|
||||
// Optional attribute. The resource has to do manual checks and manual warnings. It may or may
|
||||
// not have a value.
|
||||
void RegisterOptionalAttribute(const std::string& attr, const std::string& defaultValue = "");
|
||||
};
|
||||
|
||||
uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress);
|
||||
|
||||
typedef ZResource*(ZResourceFactoryFunc)();
|
||||
typedef ZResource*(ZResourceFactoryFunc)(ZFile* nParent);
|
||||
|
||||
#define REGISTER_ZFILENODE(nodeName, zResClass) \
|
||||
static ZResource* ZResourceFactory_##zResClass_##nodeName() \
|
||||
static ZResource* ZResourceFactory_##zResClass_##nodeName(ZFile* nParent) \
|
||||
{ \
|
||||
return static_cast<ZResource*>(new zResClass(nullptr)); \
|
||||
return static_cast<ZResource*>(new zResClass(nParent)); \
|
||||
} \
|
||||
\
|
||||
class ZRes_##nodeName \
|
||||
@@ -177,4 +150,4 @@ typedef ZResource*(ZResourceFactoryFunc)();
|
||||
ZFile::RegisterNode(#nodeName, &ZResourceFactory_##zResClass_##nodeName); \
|
||||
} \
|
||||
}; \
|
||||
static ZRes_##nodeName inst_ZRes_##nodeName;
|
||||
static ZRes_##nodeName inst_ZRes_##nodeName
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
#include "EndMarker.h"
|
||||
#include "../../StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
EndMarker::EndMarker(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
EndMarker::EndMarker(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
string EndMarker::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
std::string EndMarker::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str());
|
||||
return "SCENE_CMD_END()";
|
||||
}
|
||||
|
||||
string EndMarker::GetCommandCName()
|
||||
std::string EndMarker::GetCommandCName() const
|
||||
{
|
||||
return "SCmdEndMarker";
|
||||
}
|
||||
|
||||
RoomCommand EndMarker::GetRoomCommand()
|
||||
RoomCommand EndMarker::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::EndMarker;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class EndMarker : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
EndMarker(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
EndMarker(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
|
||||
private:
|
||||
std::string GetBodySourceCode() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
};
|
||||
@@ -1,88 +1,79 @@
|
||||
#include "SetActorCutsceneList.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetActorCutsceneList::SetActorCutsceneList(ZRoom* nZRoom, std::vector<uint8_t> rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetActorCutsceneList::SetActorCutsceneList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
int32_t numCutscenes = rawData[rawDataIndex + 1];
|
||||
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
|
||||
|
||||
cutscenes = vector<ActorCutsceneEntry*>();
|
||||
}
|
||||
|
||||
void SetActorCutsceneList::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
int numCutscenes = cmdArg1;
|
||||
int32_t currentPtr = segmentOffset;
|
||||
|
||||
for (int32_t i = 0; i < numCutscenes; i++)
|
||||
{
|
||||
ActorCutsceneEntry* entry = new ActorCutsceneEntry(rawData, currentPtr);
|
||||
ActorCutsceneEntry entry(parent->GetRawData(), currentPtr);
|
||||
cutscenes.push_back(entry);
|
||||
|
||||
currentPtr += 16;
|
||||
}
|
||||
}
|
||||
|
||||
string declaration = "";
|
||||
|
||||
for (ActorCutsceneEntry* entry : cutscenes)
|
||||
void SetActorCutsceneList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
if (cutscenes.size() > 0)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(
|
||||
" { %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", entry->priority, entry->length,
|
||||
entry->unk4, entry->unk6, entry->additionalCutscene, entry->sound, entry->unkB,
|
||||
entry->unkC, entry->unkE, entry->letterboxSize);
|
||||
std::string declaration = "";
|
||||
|
||||
for (size_t i = 0; i < cutscenes.size(); i++)
|
||||
{
|
||||
const auto& entry = cutscenes.at(i);
|
||||
declaration += StringHelper::Sprintf(" { %s },", entry.GetBodySourceCode().c_str());
|
||||
|
||||
if (i + 1 < cutscenes.size())
|
||||
{
|
||||
declaration += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
std::string typeName = cutscenes.at(0).GetSourceTypeName();
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::Align4, cutscenes.size() * 16, typeName,
|
||||
StringHelper::Sprintf("%s%sList_%06X", prefix.c_str(), typeName.c_str(), segmentOffset),
|
||||
0, declaration);
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, cutscenes.size() * 16, "ActorCutscene",
|
||||
StringHelper::Sprintf("%sActorCutsceneList0x%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
0, declaration);
|
||||
}
|
||||
|
||||
SetActorCutsceneList::~SetActorCutsceneList()
|
||||
std::string SetActorCutsceneList::GetBodySourceCode() const
|
||||
{
|
||||
for (ActorCutsceneEntry* entry : cutscenes)
|
||||
delete entry;
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_LIST(%i, %s)", cutscenes.size(),
|
||||
listName.c_str());
|
||||
}
|
||||
|
||||
string SetActorCutsceneList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0x%02X, (u32)&%sActorCutsceneList0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), cutscenes.size(),
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
}
|
||||
|
||||
string SetActorCutsceneList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t SetActorCutsceneList::GetRawDataSize()
|
||||
size_t SetActorCutsceneList::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + (cutscenes.size() * 16);
|
||||
}
|
||||
|
||||
string SetActorCutsceneList::GenerateExterns()
|
||||
{
|
||||
return StringHelper::Sprintf("extern ActorCutscene %sActorCutsceneList0x%06X[];\n",
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
}
|
||||
|
||||
string SetActorCutsceneList::GetCommandCName()
|
||||
std::string SetActorCutsceneList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdCutsceneActorList";
|
||||
}
|
||||
|
||||
RoomCommand SetActorCutsceneList::GetRoomCommand()
|
||||
RoomCommand SetActorCutsceneList::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetActorCutsceneList;
|
||||
}
|
||||
|
||||
ActorCutsceneEntry::ActorCutsceneEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
ActorCutsceneEntry::ActorCutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: priority(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)),
|
||||
length(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)),
|
||||
unk4(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)),
|
||||
@@ -93,3 +84,14 @@ ActorCutsceneEntry::ActorCutsceneEntry(std::vector<uint8_t> rawData, uint32_t ra
|
||||
letterboxSize(rawData[rawDataIndex + 0xF])
|
||||
{
|
||||
}
|
||||
|
||||
std::string ActorCutsceneEntry::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %i", priority, length, unk4,
|
||||
unk6, additionalCutscene, sound, unkB, unkC, unkE, letterboxSize);
|
||||
}
|
||||
|
||||
std::string ActorCutsceneEntry::GetSourceTypeName() const
|
||||
{
|
||||
return "ActorCutscene";
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class ActorCutsceneEntry
|
||||
{
|
||||
public:
|
||||
protected:
|
||||
int16_t priority;
|
||||
int16_t length;
|
||||
int16_t unk4;
|
||||
@@ -16,23 +16,27 @@ public:
|
||||
uint8_t unkE;
|
||||
uint8_t letterboxSize;
|
||||
|
||||
ActorCutsceneEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
public:
|
||||
ActorCutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
std::string GetSourceTypeName() const;
|
||||
};
|
||||
|
||||
class SetActorCutsceneList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetActorCutsceneList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
~SetActorCutsceneList();
|
||||
SetActorCutsceneList(ZFile* nParent);
|
||||
|
||||
std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
|
||||
std::string GetCommandCName() override;
|
||||
std::string GenerateExterns() override;
|
||||
RoomCommand GetRoomCommand() override;
|
||||
size_t GetRawDataSize() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
private:
|
||||
std::vector<ActorCutsceneEntry*> cutscenes;
|
||||
uint32_t segmentOffset;
|
||||
std::vector<ActorCutsceneEntry> cutscenes;
|
||||
};
|
||||
|
||||
@@ -1,121 +1,77 @@
|
||||
#include "SetActorList.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZNames.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZNames.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetActorList::SetActorList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetActorList::SetActorList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
numActors = rawData[rawDataIndex + 1];
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
|
||||
_rawData = rawData;
|
||||
_rawDataIndex = rawDataIndex;
|
||||
|
||||
if (segmentOffset != 0)
|
||||
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
}
|
||||
|
||||
SetActorList::~SetActorList()
|
||||
void SetActorList::ParseRawData()
|
||||
{
|
||||
for (ActorSpawnEntry* entry : actors)
|
||||
delete entry;
|
||||
ZRoomCommand::ParseRawData();
|
||||
numActors = cmdArg1;
|
||||
|
||||
}
|
||||
|
||||
string SetActorList::GetSourceOutputCode(std::string prefix)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string SetActorList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string SetActorList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
string sourceOutput = "";
|
||||
size_t numActorsReal = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 16;
|
||||
actors = vector<ActorSpawnEntry*>();
|
||||
uint32_t currentPtr = segmentOffset;
|
||||
|
||||
for (size_t i = 0; i < numActorsReal; i++)
|
||||
for (size_t i = 0; i < numActors; i++)
|
||||
{
|
||||
ActorSpawnEntry* entry = new ActorSpawnEntry(_rawData, currentPtr);
|
||||
ActorSpawnEntry entry(parent->GetRawData(), currentPtr);
|
||||
|
||||
currentPtr += entry.GetRawDataSize();
|
||||
actors.push_back(entry);
|
||||
|
||||
currentPtr += 16;
|
||||
}
|
||||
}
|
||||
|
||||
sourceOutput +=
|
||||
StringHelper::Sprintf("\n %s 0x%02X, (u32)%sActorList0x%06X \n};",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
numActors, roomName.c_str(), segmentOffset);
|
||||
|
||||
// zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None,
|
||||
// DeclarationPadding::None, GetRawDataSize(), "SCmdActorList",
|
||||
// ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress), sourceOutput);
|
||||
|
||||
string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
for (ActorSpawnEntry* entry : actors)
|
||||
void SetActorList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
if (!actors.empty())
|
||||
{
|
||||
uint16_t actorNum = entry->actorNum;
|
||||
std::string declaration = "";
|
||||
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
size_t index = 0;
|
||||
for (const auto& entry : actors)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(
|
||||
" { %s, %i, %i, %i, SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X), "
|
||||
"SPAWN_ROT_FLAGS(%i, 0x%04X), 0x%04X }, //0x%06X",
|
||||
ZNames::GetActorName(actorNum).c_str(), entry->posX, entry->posY, entry->posZ,
|
||||
(entry->rotX >> 7) & 0b111111111, entry->rotX & 0b1111111,
|
||||
(entry->rotY >> 7) & 0b111111111, entry->rotY & 0b1111111,
|
||||
(entry->rotZ >> 7) & 0b111111111, entry->rotZ & 0b1111111, (uint16_t)entry->initVar,
|
||||
segmentOffset + (index * 16));
|
||||
}
|
||||
else
|
||||
{
|
||||
declaration += StringHelper::Sprintf(
|
||||
" { %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X",
|
||||
ZNames::GetActorName(actorNum).c_str(), entry->posX, entry->posY, entry->posZ,
|
||||
entry->rotX, entry->rotY, entry->rotZ, (uint16_t)entry->initVar,
|
||||
segmentOffset + (index * 16));
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t{ %s }, // 0x%06X", entry.GetBodySourceCode().c_str(),
|
||||
segmentOffset + (index * 16));
|
||||
|
||||
if (index < actors.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
if (index < actors.size() - 1)
|
||||
declaration += "\n";
|
||||
const auto& entry = actors.front();
|
||||
|
||||
index++;
|
||||
DeclarationPadding padding = DeclarationPadding::Pad16;
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
padding = DeclarationPadding::None;
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::Align4, padding,
|
||||
actors.size() * entry.GetRawDataSize(), entry.GetSourceTypeName(),
|
||||
StringHelper::Sprintf("%sActorList_%06X", prefix.c_str(), segmentOffset),
|
||||
GetActorListArraySize(), declaration);
|
||||
}
|
||||
|
||||
DeclarationPadding padding = DeclarationPadding::Pad16;
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
padding = DeclarationPadding::None;
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, padding, actors.size() * 16, "ActorEntry",
|
||||
StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset),
|
||||
GetActorListArraySize(), declaration);
|
||||
|
||||
return sourceOutput;
|
||||
}
|
||||
|
||||
size_t SetActorList::GetRawDataSize()
|
||||
std::string SetActorList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ACTOR_LIST(%i, %s)", numActors, listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetActorList::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + ((int32_t)actors.size() * 16);
|
||||
}
|
||||
|
||||
size_t SetActorList::GetActorListArraySize()
|
||||
size_t SetActorList::GetActorListArraySize() const
|
||||
{
|
||||
size_t actorCount = 0;
|
||||
|
||||
@@ -126,8 +82,8 @@ size_t SetActorList::GetActorListArraySize()
|
||||
{
|
||||
actorCount = 0;
|
||||
|
||||
for (ActorSpawnEntry* entry : actors)
|
||||
if (entry->actorNum != 0x22)
|
||||
for (const auto& entry : actors)
|
||||
if (entry.GetActorId() != 0x22)
|
||||
actorCount++;
|
||||
}
|
||||
else
|
||||
@@ -138,32 +94,58 @@ size_t SetActorList::GetActorListArraySize()
|
||||
return actorCount;
|
||||
}
|
||||
|
||||
string SetActorList::GenerateExterns()
|
||||
{
|
||||
return StringHelper::Sprintf("extern ActorEntry %sActorList0x%06X[%i];\n",
|
||||
zRoom->GetName().c_str(), segmentOffset, GetActorListArraySize());
|
||||
}
|
||||
|
||||
string SetActorList::GetCommandCName()
|
||||
std::string SetActorList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdActorList";
|
||||
}
|
||||
|
||||
RoomCommand SetActorList::GetRoomCommand()
|
||||
RoomCommand SetActorList::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetActorList;
|
||||
}
|
||||
|
||||
ActorSpawnEntry::ActorSpawnEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
ActorSpawnEntry::ActorSpawnEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
const uint8_t* data = rawData.data();
|
||||
|
||||
actorNum = BitConverter::ToInt16BE(data, rawDataIndex + 0);
|
||||
posX = BitConverter::ToInt16BE(data, rawDataIndex + 2);
|
||||
posY = BitConverter::ToInt16BE(data, rawDataIndex + 4);
|
||||
posZ = BitConverter::ToInt16BE(data, rawDataIndex + 6);
|
||||
rotX = BitConverter::ToInt16BE(data, rawDataIndex + 8);
|
||||
rotY = BitConverter::ToInt16BE(data, rawDataIndex + 10);
|
||||
rotZ = BitConverter::ToInt16BE(data, rawDataIndex + 12);
|
||||
initVar = BitConverter::ToInt16BE(data, rawDataIndex + 14);
|
||||
actorNum = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
|
||||
posX = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
|
||||
posY = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
|
||||
posZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
|
||||
rotX = BitConverter::ToInt16BE(rawData, rawDataIndex + 8);
|
||||
rotY = BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
|
||||
rotZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
|
||||
initVar = BitConverter::ToInt16BE(rawData, rawDataIndex + 14);
|
||||
}
|
||||
|
||||
std::string ActorSpawnEntry::GetBodySourceCode() const
|
||||
{
|
||||
std::string body = "\n";
|
||||
|
||||
body += "\t\t" + ZNames::GetActorName(actorNum) + ",\n";
|
||||
body += StringHelper::Sprintf("\t\t{ %6i, %6i, %6i },\n", posX, posY, posZ);
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
body += StringHelper::Sprintf("\t\t{ SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, "
|
||||
"0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X)},\n",
|
||||
(rotX >> 7) & 0b111111111, rotX & 0b1111111,
|
||||
(rotY >> 7) & 0b111111111, rotY & 0b1111111,
|
||||
(rotZ >> 7) & 0b111111111, rotZ & 0b1111111);
|
||||
else
|
||||
body += StringHelper::Sprintf("\t\t{ %6i, %6i, %6i },\n", rotX, rotY, rotZ);
|
||||
body += StringHelper::Sprintf("\t\t0x%04X\n ", initVar);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
std::string ActorSpawnEntry::GetSourceTypeName() const
|
||||
{
|
||||
return "ActorEntry";
|
||||
}
|
||||
|
||||
int32_t ActorSpawnEntry::GetRawDataSize() const
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
uint16_t ActorSpawnEntry::GetActorId() const
|
||||
{
|
||||
return actorNum;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class ActorSpawnEntry
|
||||
{
|
||||
public:
|
||||
ActorSpawnEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
std::string GetSourceTypeName() const;
|
||||
int32_t GetRawDataSize() const;
|
||||
|
||||
uint16_t GetActorId() const;
|
||||
|
||||
protected:
|
||||
uint16_t actorNum;
|
||||
int16_t posX;
|
||||
int16_t posY;
|
||||
@@ -13,29 +23,25 @@ public:
|
||||
int16_t rotY;
|
||||
int16_t rotZ;
|
||||
uint16_t initVar;
|
||||
|
||||
ActorSpawnEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class SetActorList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetActorList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
~SetActorList();
|
||||
SetActorList(ZFile* nParent);
|
||||
|
||||
std::string GetSourceOutputCode(std::string prefix);
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
virtual size_t GetRawDataSize() override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
private:
|
||||
size_t GetActorListArraySize();
|
||||
int32_t numActors;
|
||||
std::vector<ActorSpawnEntry*> actors;
|
||||
uint32_t segmentOffset;
|
||||
std::vector<uint8_t> _rawData;
|
||||
uint32_t _rawDataIndex;
|
||||
};
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
protected:
|
||||
size_t GetActorListArraySize() const;
|
||||
|
||||
uint8_t numActors;
|
||||
std::vector<ActorSpawnEntry> actors;
|
||||
};
|
||||
|
||||
@@ -1,74 +1,70 @@
|
||||
#include "SetAlternateHeaders.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
SetAlternateHeaders::SetAlternateHeaders(ZRoom* nZRoom, std::vector<uint8_t> rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetAlternateHeaders::SetAlternateHeaders(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
|
||||
if (segmentOffset != 0)
|
||||
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
|
||||
_rawData = rawData;
|
||||
_rawDataIndex = rawDataIndex;
|
||||
}
|
||||
|
||||
string SetAlternateHeaders::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetAlternateHeaders::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
string sourceOutput = "";
|
||||
int32_t numHeaders = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 4;
|
||||
if (segmentOffset != 0)
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
}
|
||||
|
||||
void SetAlternateHeaders::ParseRawDataLate()
|
||||
{
|
||||
int numHeaders = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 4;
|
||||
|
||||
for (int32_t i = 0; i < numHeaders; i++)
|
||||
{
|
||||
int32_t address = BitConverter::ToInt32BE(_rawData, segmentOffset + (i * 4));
|
||||
int32_t address = BitConverter::ToInt32BE(parent->GetRawData(), segmentOffset + (i * 4));
|
||||
headers.push_back(address);
|
||||
|
||||
if (address != 0)
|
||||
zRoom->commandSets.push_back(CommandSet(address));
|
||||
}
|
||||
|
||||
sourceOutput +=
|
||||
StringHelper::Sprintf("%s 0, (u32)&%sAlternateHeaders0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
roomName.c_str(), segmentOffset);
|
||||
|
||||
string declaration = "";
|
||||
|
||||
for (int32_t i = 0; i < numHeaders; i++)
|
||||
{
|
||||
// sprintf(line, " 0x%06X,\n", headers[i]);
|
||||
|
||||
if (headers[i] == 0)
|
||||
declaration += StringHelper::Sprintf(" 0,\n");
|
||||
else
|
||||
declaration += StringHelper::Sprintf(" (u32)&%sSet%04XCmd00,\n", roomName.c_str(),
|
||||
headers[i] & 0x00FFFFFF);
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, headers.size() * 4, "u32",
|
||||
StringHelper::Sprintf("%sAlternateHeaders0x%06X", roomName.c_str(), segmentOffset), 0,
|
||||
declaration);
|
||||
|
||||
return sourceOutput;
|
||||
}
|
||||
|
||||
size_t SetAlternateHeaders::GetRawDataSize()
|
||||
void SetAlternateHeaders::DeclareReferencesLate(const std::string& prefix)
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + 0;
|
||||
if (!headers.empty())
|
||||
{
|
||||
std::string declaration = "";
|
||||
|
||||
for (size_t i = 0; i < headers.size(); i++)
|
||||
{
|
||||
if (headers.at(i) == 0)
|
||||
declaration += StringHelper::Sprintf("\tNULL,");
|
||||
else
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t%sSet%04X,", prefix.c_str(), GETSEGOFFSET(headers[i]));
|
||||
|
||||
if (i + 1 < headers.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, headers.size() * 4, "SCmdBase*",
|
||||
StringHelper::Sprintf("%sAlternateHeaders0x%06X", prefix.c_str(), segmentOffset), 0,
|
||||
declaration);
|
||||
}
|
||||
}
|
||||
|
||||
string SetAlternateHeaders::GetCommandCName()
|
||||
std::string SetAlternateHeaders::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ALTERNATE_HEADER_LIST(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
std::string SetAlternateHeaders::GetCommandCName() const
|
||||
{
|
||||
return "SCmdAltHeaders";
|
||||
}
|
||||
|
||||
RoomCommand SetAlternateHeaders::GetRoomCommand()
|
||||
RoomCommand SetAlternateHeaders::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetAlternateHeaders;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoom.h"
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetAlternateHeaders : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetAlternateHeaders(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetAlternateHeaders(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual size_t GetRawDataSize() override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
void ParseRawDataLate() override;
|
||||
void DeclareReferencesLate(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
int32_t segmentOffset;
|
||||
std::vector<uint32_t> headers;
|
||||
std::vector<uint8_t> _rawData;
|
||||
int32_t _rawDataIndex;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,412 @@
|
||||
#include "SetAnimatedMaterialList.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetAnimatedMaterialList::SetAnimatedMaterialList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void SetAnimatedMaterialList::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
int32_t currentPtr = segmentOffset;
|
||||
bool keepGoing = true;
|
||||
|
||||
do
|
||||
{
|
||||
AnimatedMaterial lastTexture(parent->GetRawData(), currentPtr);
|
||||
keepGoing = (lastTexture.segment != 0) && (lastTexture.segment > -1);
|
||||
currentPtr += 8;
|
||||
textures.push_back(lastTexture);
|
||||
} while (keepGoing);
|
||||
}
|
||||
|
||||
void SetAnimatedMaterialList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
std::string nameStr =
|
||||
StringHelper::Sprintf("%sAnimatedMaterialList0x%06X", prefix.c_str(), segmentOffset);
|
||||
|
||||
for (auto& texture : textures)
|
||||
{
|
||||
size_t declSize = 0;
|
||||
std::string declTypeName = "";
|
||||
std::string declName = StringHelper::Sprintf("%sAnimatedMaterialParams0x%06X",
|
||||
prefix.c_str(), texture.segmentOffset);
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
switch (texture.type)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
for (const auto& param : texture.params)
|
||||
{
|
||||
declaration += param->GenerateSourceCode(zRoom, texture.segmentOffset);
|
||||
|
||||
if (index < texture.params.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
declSize = texture.params.size() * 4;
|
||||
declTypeName = "AnimatedMatTexScrollParams";
|
||||
|
||||
parent->AddDeclarationArray(texture.segmentOffset, DeclarationAlignment::Align4,
|
||||
declSize, declTypeName, declName, texture.params.size(),
|
||||
declaration);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
declSize = texture.params.at(0)->GetParamsSize();
|
||||
declTypeName = "AnimatedMatColorParams";
|
||||
declaration = texture.params.at(0)->GenerateSourceCode(zRoom, texture.segmentOffset);
|
||||
|
||||
parent->AddDeclaration(texture.segmentOffset, DeclarationAlignment::Align4, declSize,
|
||||
declTypeName, declName,
|
||||
StringHelper::Sprintf("\n\t%s\n", declaration.c_str()));
|
||||
break;
|
||||
case 5:
|
||||
declSize = texture.params.at(0)->GetParamsSize();
|
||||
declTypeName = "AnimatedMatTexCycleParams";
|
||||
declaration = texture.params.at(0)->GenerateSourceCode(zRoom, texture.segmentOffset);
|
||||
|
||||
parent->AddDeclaration(texture.segmentOffset, DeclarationAlignment::Align4, declSize,
|
||||
declTypeName, declName,
|
||||
StringHelper::Sprintf("\n\t%s\n", declaration.c_str()));
|
||||
break;
|
||||
case 6:
|
||||
continue;
|
||||
|
||||
default:
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Error in SetAnimatedMaterialList::DeclareReferences (%s)\n"
|
||||
"\t Unknown texture.type: %i\n",
|
||||
nameStr.c_str(), texture.type));
|
||||
}
|
||||
}
|
||||
|
||||
if (!textures.empty())
|
||||
{
|
||||
std::string declaration = "";
|
||||
|
||||
for (size_t i = 0; i < textures.size(); i++)
|
||||
{
|
||||
std::string textureName = parent->GetDeclarationPtrName(textures.at(i).segmentAddress);
|
||||
|
||||
declaration += StringHelper::Sprintf("\t{ %2i, %2i, %s },", textures.at(i).segment,
|
||||
textures.at(i).type, textureName.c_str());
|
||||
|
||||
if (i + 1 < textures.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4,
|
||||
DeclarationPadding::Pad16, textures.size() * 8,
|
||||
"AnimatedMaterial", nameStr, textures.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
std::string SetAnimatedMaterialList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ANIMATED_MATERIAL_LIST(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetAnimatedMaterialList::GetRawDataSize() const
|
||||
{
|
||||
size_t paramsSize = 0;
|
||||
for (const auto& texture : textures)
|
||||
{
|
||||
for (const auto& param : texture.params)
|
||||
{
|
||||
paramsSize += param->GetParamsSize();
|
||||
}
|
||||
}
|
||||
|
||||
return ZRoomCommand::GetRawDataSize() + paramsSize;
|
||||
}
|
||||
|
||||
std::string SetAnimatedMaterialList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdTextureAnimations";
|
||||
}
|
||||
|
||||
RoomCommand SetAnimatedMaterialList::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetAnimatedMaterialList;
|
||||
}
|
||||
|
||||
AnimatedMaterial::AnimatedMaterial(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: segment(rawData.at(rawDataIndex)), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 2))
|
||||
{
|
||||
segmentAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
|
||||
segmentOffset = GETSEGOFFSET(segmentAddress);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
params.push_back(std::make_shared<ScrollingTexture>(rawData, segmentOffset));
|
||||
break;
|
||||
case 1:
|
||||
params.push_back(std::make_shared<ScrollingTexture>(rawData, segmentOffset));
|
||||
params.push_back(std::make_shared<ScrollingTexture>(rawData, segmentOffset + 4));
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
params.push_back(std::make_shared<FlashingTexture>(rawData, segmentOffset, type));
|
||||
break;
|
||||
case 5:
|
||||
params.push_back(std::make_shared<AnimatedMatTexCycleParams>(rawData, segmentOffset));
|
||||
break;
|
||||
case 6: // Some terminator when there are no animated textures?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ScrollingTexture::ScrollingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: xStep(rawData.at(rawDataIndex + 0)), yStep(rawData.at(rawDataIndex + 1)),
|
||||
width(rawData.at(rawDataIndex + 2)), height(rawData.at(rawDataIndex + 3))
|
||||
{
|
||||
}
|
||||
|
||||
std::string ScrollingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
|
||||
{
|
||||
return StringHelper::Sprintf(" { %i, %i, 0x%02X, 0x%02X },", xStep, yStep, width, height);
|
||||
}
|
||||
|
||||
size_t ScrollingTexture::GetParamsSize()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
F3DPrimColor::F3DPrimColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: r(rawData.at(rawDataIndex + 0)), g(rawData.at(rawDataIndex + 1)),
|
||||
b(rawData.at(rawDataIndex + 2)), a(rawData.at(rawDataIndex + 3)),
|
||||
lodFrac(rawData.at(rawDataIndex + 4))
|
||||
{
|
||||
}
|
||||
|
||||
FlashingTextureEnvColor::FlashingTextureEnvColor(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: r(rawData.at(rawDataIndex + 0)), g(rawData.at(rawDataIndex + 1)),
|
||||
b(rawData.at(rawDataIndex + 2)), a(rawData.at(rawDataIndex + 3))
|
||||
{
|
||||
}
|
||||
|
||||
FlashingTexture::FlashingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
|
||||
int32_t type)
|
||||
: cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
|
||||
numKeyFrames(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2))
|
||||
{
|
||||
uint16_t length = (type == 2) ? cycleLength : numKeyFrames;
|
||||
|
||||
primColorSegmentAddr = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
|
||||
envColorSegmentAddr = BitConverter::ToInt32BE(rawData, rawDataIndex + 8);
|
||||
keyFrameSegmentAddr = BitConverter::ToInt32BE(rawData, rawDataIndex + 12);
|
||||
|
||||
primColorSegmentOffset = GETSEGOFFSET(primColorSegmentAddr);
|
||||
envColorSegmentOffset = GETSEGOFFSET(envColorSegmentAddr);
|
||||
keyFrameSegmentOffset = GETSEGOFFSET(keyFrameSegmentAddr);
|
||||
|
||||
int32_t currentPtr = primColorSegmentOffset;
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
primColors.push_back(F3DPrimColor(rawData, currentPtr));
|
||||
currentPtr += 5;
|
||||
}
|
||||
|
||||
currentPtr = envColorSegmentOffset;
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
envColors.push_back(FlashingTextureEnvColor(rawData, currentPtr));
|
||||
currentPtr += 4;
|
||||
}
|
||||
|
||||
currentPtr = keyFrameSegmentOffset;
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
keyFrames.push_back(BitConverter::ToUInt16BE(rawData, currentPtr));
|
||||
currentPtr += 2;
|
||||
}
|
||||
}
|
||||
|
||||
std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
|
||||
{
|
||||
if (primColorSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (F3DPrimColor& color : primColors)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },",
|
||||
color.r, color.g, color.b, color.a, color.lodFrac);
|
||||
|
||||
if (index < primColors.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
primColorSegmentOffset, DeclarationAlignment::Align4, primColors.size() * 5,
|
||||
"F3DPrimColor",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialPrimColor_%06X", zRoom->GetName().c_str(),
|
||||
primColorSegmentOffset),
|
||||
primColors.size(), declaration);
|
||||
}
|
||||
|
||||
if (envColorSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (FlashingTextureEnvColor& color : envColors)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X },", color.r,
|
||||
color.g, color.b, color.a);
|
||||
|
||||
if (index < envColors.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
envColorSegmentOffset, DeclarationAlignment::Align4, envColors.size() * 4,
|
||||
"Color_RGBA8",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialEnvColors0x%06X", zRoom->GetName().c_str(),
|
||||
envColorSegmentOffset),
|
||||
envColors.size(), declaration);
|
||||
}
|
||||
|
||||
if (keyFrameSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (uint16_t keyFrame : keyFrames)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" 0x%02X,", keyFrame);
|
||||
|
||||
if (index < keyFrames.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
keyFrameSegmentOffset, DeclarationAlignment::Align4, keyFrames.size() * 2, "u16",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialKeyFrames0x%06X", zRoom->GetName().c_str(),
|
||||
keyFrameSegmentOffset),
|
||||
keyFrames.size(), declaration);
|
||||
}
|
||||
|
||||
std::string primName = zRoom->parent->GetDeclarationPtrName(primColorSegmentAddr);
|
||||
std::string envName = zRoom->parent->GetDeclarationPtrName(envColorSegmentAddr);
|
||||
std::string keyName = zRoom->parent->GetDeclarationPtrName(keyFrameSegmentAddr);
|
||||
|
||||
return StringHelper::Sprintf("%i, %i, %s, %s, %s", cycleLength, numKeyFrames, primName.c_str(),
|
||||
envName.c_str(), keyName.c_str());
|
||||
}
|
||||
|
||||
size_t FlashingTexture::GetParamsSize()
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
AnimatedMatTexCycleParams::AnimatedMatTexCycleParams(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0))
|
||||
{
|
||||
textureSegmentOffsetsSegmentAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
|
||||
textureIndicesSegmentAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 8);
|
||||
|
||||
textureSegmentOffsetsSegmentOffset = GETSEGOFFSET(textureSegmentOffsetsSegmentAddress);
|
||||
textureIndicesSegmentOffset = GETSEGOFFSET(textureIndicesSegmentAddress);
|
||||
|
||||
int32_t currentPtr = textureIndicesSegmentOffset;
|
||||
int32_t maxIndex = 0;
|
||||
|
||||
for (uint16_t i = 0; i < cycleLength; i++)
|
||||
{
|
||||
uint8_t newIndex = rawData.at(currentPtr);
|
||||
textureIndices.push_back(newIndex);
|
||||
currentPtr++;
|
||||
if (newIndex > maxIndex)
|
||||
maxIndex = newIndex;
|
||||
}
|
||||
|
||||
currentPtr = textureSegmentOffsetsSegmentOffset;
|
||||
for (int32_t i = 0; i < maxIndex + 1; i++)
|
||||
{
|
||||
textureSegmentOffsets.push_back(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr)));
|
||||
currentPtr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
std::string AnimatedMatTexCycleParams::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
|
||||
{
|
||||
if (textureSegmentOffsetsSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (uint32_t offset : textureSegmentOffsets)
|
||||
{
|
||||
declaration +=
|
||||
StringHelper::Sprintf(" %sTex_%06X,", zRoom->GetName().c_str(), offset);
|
||||
|
||||
if (index < textureSegmentOffsets.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
textureSegmentOffsetsSegmentOffset, DeclarationAlignment::Align4,
|
||||
textureSegmentOffsets.size() * 4, "u64*",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialTexSegOffsets0x%06X", zRoom->GetName().c_str(),
|
||||
textureSegmentOffsetsSegmentOffset),
|
||||
textureSegmentOffsets.size(), declaration);
|
||||
}
|
||||
|
||||
if (textureIndicesSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (uint8_t textureIndex : textureIndices)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" 0x%02X,", textureIndex);
|
||||
|
||||
if (index < textureIndices.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
textureIndicesSegmentOffset, DeclarationAlignment::Align4, textureIndices.size(), "u8",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialTexIndices0x%06X", zRoom->GetName().c_str(),
|
||||
textureIndicesSegmentOffset),
|
||||
textureIndices.size(), declaration);
|
||||
}
|
||||
|
||||
std::string segmName = zRoom->parent->GetDeclarationPtrName(textureSegmentOffsetsSegmentAddress);
|
||||
std::string indexesName = zRoom->parent->GetDeclarationPtrName(textureIndicesSegmentAddress);
|
||||
|
||||
return StringHelper::Sprintf("%i, %s, %s", cycleLength, segmName.c_str(), indexesName.c_str());
|
||||
}
|
||||
|
||||
size_t AnimatedMatTexCycleParams::GetParamsSize()
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
+34
-28
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include <memory>
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
// TODO move into header and add all types
|
||||
class AnitmatedTextureParams
|
||||
{
|
||||
public:
|
||||
virtual ~AnitmatedTextureParams();
|
||||
virtual std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) = 0;
|
||||
virtual size_t GetParamsSize() = 0;
|
||||
};
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
class ScrollingTexture : public AnitmatedTextureParams
|
||||
{
|
||||
public:
|
||||
ScrollingTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
ScrollingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
|
||||
size_t GetParamsSize() override;
|
||||
|
||||
@@ -24,10 +24,10 @@ public:
|
||||
uint8_t height;
|
||||
};
|
||||
|
||||
class FlashingTexturePrimColor
|
||||
class F3DPrimColor
|
||||
{
|
||||
public:
|
||||
FlashingTexturePrimColor(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
F3DPrimColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
class FlashingTextureEnvColor
|
||||
{
|
||||
public:
|
||||
FlashingTextureEnvColor(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
FlashingTextureEnvColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
@@ -50,29 +50,37 @@ public:
|
||||
class FlashingTexture : public AnitmatedTextureParams
|
||||
{
|
||||
public:
|
||||
FlashingTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t type);
|
||||
FlashingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex, int32_t type);
|
||||
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
|
||||
size_t GetParamsSize() override;
|
||||
|
||||
uint16_t cycleLength;
|
||||
uint16_t numKeyFrames;
|
||||
|
||||
segptr_t primColorSegmentAddr;
|
||||
segptr_t envColorSegmentAddr;
|
||||
segptr_t keyFrameSegmentAddr;
|
||||
|
||||
uint32_t primColorSegmentOffset;
|
||||
uint32_t envColorSegmentOffset;
|
||||
uint32_t keyFrameSegmentOffset;
|
||||
|
||||
std::vector<FlashingTexturePrimColor> primColors;
|
||||
std::vector<F3DPrimColor> primColors;
|
||||
std::vector<FlashingTextureEnvColor> envColors;
|
||||
std::vector<uint16_t> keyFrames;
|
||||
};
|
||||
|
||||
class CyclingTextureParams : public AnitmatedTextureParams
|
||||
class AnimatedMatTexCycleParams : public AnitmatedTextureParams
|
||||
{
|
||||
public:
|
||||
CyclingTextureParams(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
AnimatedMatTexCycleParams(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
|
||||
size_t GetParamsSize() override;
|
||||
|
||||
uint16_t cycleLength;
|
||||
|
||||
segptr_t textureSegmentOffsetsSegmentAddress;
|
||||
segptr_t textureIndicesSegmentAddress;
|
||||
uint32_t textureSegmentOffsetsSegmentOffset;
|
||||
uint32_t textureIndicesSegmentOffset;
|
||||
|
||||
@@ -80,34 +88,32 @@ public:
|
||||
std::vector<uint8_t> textureIndices;
|
||||
};
|
||||
|
||||
class AnimatedTexture
|
||||
class AnimatedMaterial
|
||||
{
|
||||
public:
|
||||
AnimatedTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
virtual ~AnimatedTexture();
|
||||
AnimatedMaterial(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
int8_t segment;
|
||||
int16_t type;
|
||||
segptr_t segmentAddress;
|
||||
uint32_t segmentOffset;
|
||||
std::vector<AnitmatedTextureParams*> params;
|
||||
std::vector<std::shared_ptr<AnitmatedTextureParams>> params;
|
||||
};
|
||||
|
||||
class SetAnimatedTextureList : public ZRoomCommand
|
||||
class SetAnimatedMaterialList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetAnimatedTextureList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
~SetAnimatedTextureList();
|
||||
SetAnimatedMaterialList(ZFile* nParent);
|
||||
|
||||
std::string GetSourceOutputCode(std::string prefix);
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
virtual size_t GetRawDataSize() override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
uint32_t segmentOffset;
|
||||
std::vector<AnimatedTexture*> textures;
|
||||
std::vector<uint8_t> _rawData;
|
||||
int32_t _rawDataIndex;
|
||||
};
|
||||
std::vector<AnimatedMaterial> textures;
|
||||
};
|
||||
@@ -1,432 +0,0 @@
|
||||
#include "SetAnimatedTextureList.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SetAnimatedTextureList::SetAnimatedTextureList(ZRoom* nZRoom, std::vector<uint8_t> rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
{
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
|
||||
{
|
||||
string declaration = "";
|
||||
|
||||
int32_t currentPtr = segmentOffset;
|
||||
|
||||
AnimatedTexture* lastTexture = nullptr;
|
||||
|
||||
do
|
||||
{
|
||||
if (textures.size() > 0)
|
||||
declaration += "\n";
|
||||
|
||||
lastTexture = new AnimatedTexture(rawData, currentPtr);
|
||||
currentPtr += 8;
|
||||
textures.push_back(lastTexture);
|
||||
|
||||
string textureName =
|
||||
(lastTexture->segmentOffset != 0) ?
|
||||
StringHelper::Sprintf("&%sAnimatedTextureParams0x%06X",
|
||||
zRoom->GetName().c_str(), lastTexture->segmentOffset) :
|
||||
"NULL";
|
||||
|
||||
declaration += StringHelper::Sprintf(" { %i, %i, (u32)%s },", lastTexture->segment,
|
||||
lastTexture->type, textureName.c_str());
|
||||
} while ((lastTexture->segment != 0) && (lastTexture->segment > -1));
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16,
|
||||
textures.size() * 8, "AnimatedTexture",
|
||||
StringHelper::Sprintf("%sAnimatedTextureList0x%06X", zRoom->GetName().c_str(),
|
||||
segmentOffset),
|
||||
textures.size(), declaration);
|
||||
}
|
||||
|
||||
for (AnimatedTexture* texture : textures)
|
||||
{
|
||||
string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
switch (texture->type)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
for (AnitmatedTextureParams* param : texture->params)
|
||||
{
|
||||
declaration += param->GenerateSourceCode(zRoom, texture->segmentOffset);
|
||||
|
||||
if (index < texture->params.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
texture->segmentOffset, DeclarationAlignment::None, DeclarationPadding::None,
|
||||
texture->params.size() * 4, "ScrollingTextureParams",
|
||||
StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(),
|
||||
texture->segmentOffset),
|
||||
texture->params.size(), declaration);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
zRoom->parent->AddDeclaration(
|
||||
texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 16,
|
||||
"FlashingTextureParams",
|
||||
StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(),
|
||||
texture->segmentOffset),
|
||||
texture->params[0]->GenerateSourceCode(zRoom, texture->segmentOffset));
|
||||
break;
|
||||
case 5:
|
||||
zRoom->parent->AddDeclaration(
|
||||
texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 12,
|
||||
"CyclingTextureParams",
|
||||
StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(),
|
||||
texture->segmentOffset),
|
||||
texture->params[0]->GenerateSourceCode(zRoom, texture->segmentOffset));
|
||||
break;
|
||||
case 6:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetAnimatedTextureList::~SetAnimatedTextureList()
|
||||
{
|
||||
for (AnimatedTexture* texture : textures)
|
||||
delete texture;
|
||||
}
|
||||
|
||||
AnitmatedTextureParams::~AnitmatedTextureParams()
|
||||
{
|
||||
}
|
||||
|
||||
string SetAnimatedTextureList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0, (u32)%sAnimatedTextureList0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
}
|
||||
|
||||
size_t SetAnimatedTextureList::GetRawDataSize()
|
||||
{
|
||||
size_t paramsSize = 0;
|
||||
for (AnimatedTexture* texture : textures)
|
||||
{
|
||||
for (AnitmatedTextureParams* param : texture->params)
|
||||
{
|
||||
paramsSize += param->GetParamsSize();
|
||||
}
|
||||
}
|
||||
|
||||
return ZRoomCommand::GetRawDataSize() + paramsSize;
|
||||
}
|
||||
|
||||
string SetAnimatedTextureList::GenerateExterns()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string SetAnimatedTextureList::GetCommandCName()
|
||||
{
|
||||
return "SCmdTextureAnimations";
|
||||
}
|
||||
|
||||
RoomCommand SetAnimatedTextureList::GetRoomCommand()
|
||||
{
|
||||
return RoomCommand::SetAnimatedTextureList;
|
||||
}
|
||||
|
||||
string SetAnimatedTextureList::GetSourceOutputCode(std::string prefix)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
AnimatedTexture::AnimatedTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: segment(rawData[rawDataIndex]), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)),
|
||||
segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)))
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
params.push_back(new ScrollingTexture(rawData, segmentOffset));
|
||||
break;
|
||||
case 1:
|
||||
params.push_back(new ScrollingTexture(rawData, segmentOffset));
|
||||
params.push_back(new ScrollingTexture(rawData, segmentOffset + 4));
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
params.push_back(new FlashingTexture(rawData, segmentOffset, type));
|
||||
break;
|
||||
case 5:
|
||||
params.push_back(new CyclingTextureParams(rawData, segmentOffset));
|
||||
break;
|
||||
case 6: // Some terminator when there are no animated textures?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
AnimatedTexture::~AnimatedTexture()
|
||||
{
|
||||
for (AnitmatedTextureParams* param : params)
|
||||
delete param;
|
||||
}
|
||||
|
||||
ScrollingTexture::ScrollingTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: xStep(rawData[rawDataIndex + 0]), yStep(rawData[rawDataIndex + 1]),
|
||||
width(rawData[rawDataIndex + 2]), height(rawData[rawDataIndex + 3])
|
||||
{
|
||||
}
|
||||
|
||||
std::string ScrollingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
|
||||
{
|
||||
return StringHelper::Sprintf(" { %i, %i, 0x%02X, 0x%02X },", xStep, yStep, width, height);
|
||||
}
|
||||
|
||||
size_t ScrollingTexture::GetParamsSize()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
FlashingTexturePrimColor::FlashingTexturePrimColor(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: r(rawData[rawDataIndex + 0]), g(rawData[rawDataIndex + 1]), b(rawData[rawDataIndex + 2]),
|
||||
a(rawData[rawDataIndex + 3]), lodFrac(rawData[rawDataIndex + 4])
|
||||
{
|
||||
}
|
||||
|
||||
FlashingTextureEnvColor::FlashingTextureEnvColor(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: r(rawData[rawDataIndex + 0]), g(rawData[rawDataIndex + 1]), b(rawData[rawDataIndex + 2]),
|
||||
a(rawData[rawDataIndex + 3])
|
||||
{
|
||||
}
|
||||
|
||||
FlashingTexture::FlashingTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t type)
|
||||
: cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
|
||||
numKeyFrames(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)),
|
||||
primColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))),
|
||||
envColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8))),
|
||||
keyFrameSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 12)))
|
||||
{
|
||||
uint16_t length = (type == 2) ? cycleLength : numKeyFrames;
|
||||
|
||||
int32_t currentPtr = primColorSegmentOffset;
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
primColors.push_back(FlashingTexturePrimColor(rawData, currentPtr));
|
||||
currentPtr += 5;
|
||||
}
|
||||
|
||||
currentPtr = envColorSegmentOffset;
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
envColors.push_back(FlashingTextureEnvColor(rawData, currentPtr));
|
||||
currentPtr += 4;
|
||||
}
|
||||
|
||||
currentPtr = keyFrameSegmentOffset;
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
keyFrames.push_back(BitConverter::ToUInt16BE(rawData, currentPtr));
|
||||
currentPtr += 2;
|
||||
}
|
||||
}
|
||||
|
||||
std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
|
||||
{
|
||||
if (primColorSegmentOffset != 0)
|
||||
{
|
||||
string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (FlashingTexturePrimColor& color : primColors)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },",
|
||||
color.r, color.g, color.b, color.a, color.lodFrac);
|
||||
|
||||
if (index < primColors.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
primColorSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None,
|
||||
primColors.size() * 5, "FlashingTexturePrimColor",
|
||||
StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(),
|
||||
primColorSegmentOffset),
|
||||
primColors.size(), declaration);
|
||||
}
|
||||
|
||||
if (envColorSegmentOffset != 0)
|
||||
{
|
||||
string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (FlashingTextureEnvColor& color : envColors)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X },", color.r,
|
||||
color.g, color.b, color.a);
|
||||
|
||||
if (index < envColors.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
envColorSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None,
|
||||
envColors.size() * 4, "Color_RGBA8",
|
||||
StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(),
|
||||
envColorSegmentOffset),
|
||||
envColors.size(), declaration);
|
||||
}
|
||||
|
||||
if (keyFrameSegmentOffset != 0)
|
||||
{
|
||||
string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (uint16_t keyFrame : keyFrames)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" 0x%02X,", keyFrame);
|
||||
|
||||
if (index < keyFrames.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(keyFrameSegmentOffset, DeclarationAlignment::Align4,
|
||||
DeclarationPadding::None, keyFrames.size() * 2, "u16",
|
||||
StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X",
|
||||
zRoom->GetName().c_str(),
|
||||
keyFrameSegmentOffset),
|
||||
keyFrames.size(), declaration);
|
||||
}
|
||||
|
||||
return StringHelper::Sprintf(
|
||||
"%i, %i, (u32)%s, (u32)%s, (u32)%s", cycleLength, numKeyFrames,
|
||||
(primColorSegmentOffset != 0) ?
|
||||
StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(),
|
||||
primColorSegmentOffset)
|
||||
.c_str() :
|
||||
"NULL",
|
||||
(envColorSegmentOffset != 0) ?
|
||||
StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(),
|
||||
envColorSegmentOffset)
|
||||
.c_str() :
|
||||
"NULL",
|
||||
(keyFrameSegmentOffset != 0) ?
|
||||
StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X", zRoom->GetName().c_str(),
|
||||
keyFrameSegmentOffset)
|
||||
.c_str() :
|
||||
"NULL");
|
||||
}
|
||||
|
||||
size_t FlashingTexture::GetParamsSize()
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
CyclingTextureParams::CyclingTextureParams(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
|
||||
textureSegmentOffsetsSegmentOffset(
|
||||
GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))),
|
||||
textureIndicesSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8)))
|
||||
{
|
||||
int32_t currentPtr = textureIndicesSegmentOffset;
|
||||
int32_t maxIndex = 0;
|
||||
|
||||
for (uint16_t i = 0; i < cycleLength; i++)
|
||||
{
|
||||
int32_t newIndex = rawData[currentPtr];
|
||||
textureIndices.push_back(newIndex);
|
||||
currentPtr++;
|
||||
if (newIndex > maxIndex)
|
||||
maxIndex = newIndex;
|
||||
}
|
||||
|
||||
currentPtr = textureSegmentOffsetsSegmentOffset;
|
||||
for (int32_t i = 0; i < maxIndex + 1; i++)
|
||||
{
|
||||
textureSegmentOffsets.push_back(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr)));
|
||||
currentPtr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
std::string CyclingTextureParams::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
|
||||
{
|
||||
if (textureSegmentOffsetsSegmentOffset != 0)
|
||||
{
|
||||
string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (uint32_t offset : textureSegmentOffsets)
|
||||
{
|
||||
declaration +=
|
||||
StringHelper::Sprintf(" %sTex_%06X,", zRoom->GetName().c_str(), offset);
|
||||
|
||||
if (index < textureSegmentOffsets.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
textureSegmentOffsetsSegmentOffset, DeclarationAlignment::Align4,
|
||||
DeclarationPadding::None, textureSegmentOffsets.size() * 4, "u64*",
|
||||
StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(),
|
||||
textureSegmentOffsetsSegmentOffset),
|
||||
textureSegmentOffsets.size(), declaration);
|
||||
}
|
||||
|
||||
if (textureIndicesSegmentOffset != 0)
|
||||
{
|
||||
string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (uint8_t textureIndex : textureIndices)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" 0x%02X,", textureIndex);
|
||||
|
||||
if (index < textureIndices.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
textureIndicesSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None,
|
||||
textureIndices.size(), "u8",
|
||||
StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(),
|
||||
textureIndicesSegmentOffset),
|
||||
textureIndices.size(), declaration);
|
||||
}
|
||||
|
||||
return StringHelper::Sprintf(
|
||||
"%i, (u32)%s, (u32)%s", cycleLength,
|
||||
(textureSegmentOffsetsSegmentOffset != 0) ?
|
||||
StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(),
|
||||
textureSegmentOffsetsSegmentOffset)
|
||||
.c_str() :
|
||||
"NULL",
|
||||
(textureIndicesSegmentOffset != 0) ?
|
||||
StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(),
|
||||
textureIndicesSegmentOffset)
|
||||
.c_str() :
|
||||
"NULL");
|
||||
}
|
||||
|
||||
size_t CyclingTextureParams::GetParamsSize()
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
@@ -1,29 +1,31 @@
|
||||
#include "SetCameraSettings.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetCameraSettings::SetCameraSettings(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
cameraMovement = rawData[rawDataIndex + 0x01];
|
||||
mapHighlight = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
|
||||
}
|
||||
|
||||
string SetCameraSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetCameraSettings::ParseRawData()
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
cameraMovement, mapHighlight);
|
||||
ZRoomCommand::ParseRawData();
|
||||
cameraMovement = cmdArg1;
|
||||
mapHighlight = BitConverter::ToUInt32BE(parent->GetRawData(), rawDataIndex + 4);
|
||||
}
|
||||
|
||||
string SetCameraSettings::GetCommandCName()
|
||||
std::string SetCameraSettings::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("SCENE_CMD_MISC_SETTINGS(0x%02X, 0x%08X)", cameraMovement,
|
||||
mapHighlight);
|
||||
}
|
||||
|
||||
std::string SetCameraSettings::GetCommandCName() const
|
||||
{
|
||||
return "SCmdMiscSettings";
|
||||
}
|
||||
|
||||
RoomCommand SetCameraSettings::GetRoomCommand()
|
||||
RoomCommand SetCameraSettings::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetCameraSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetCameraSettings : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetCameraSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetCameraSettings(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
|
||||
private:
|
||||
uint8_t cameraMovement;
|
||||
uint32_t mapHighlight;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,48 +1,42 @@
|
||||
#include "SetCollisionHeader.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetCollisionHeader::SetCollisionHeader(ZRoom* nZRoom, std::vector<uint8_t> rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetCollisionHeader::SetCollisionHeader(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
collisionHeader = new ZCollisionHeader(nZRoom->parent);
|
||||
collisionHeader->SetRawData(rawData);
|
||||
}
|
||||
|
||||
void SetCollisionHeader::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
collisionHeader = new ZCollisionHeader(parent);
|
||||
collisionHeader->SetRawData(parent->GetRawData());
|
||||
collisionHeader->SetRawDataIndex(segmentOffset);
|
||||
collisionHeader->SetName(
|
||||
StringHelper::Sprintf("%sCollisionHeader0x%06X", nZRoom->GetName().c_str(), segmentOffset));
|
||||
StringHelper::Sprintf("%sCollisionHeader_%06X", parent->GetName().c_str(), segmentOffset));
|
||||
collisionHeader->ParseRawData();
|
||||
}
|
||||
|
||||
string SetCollisionHeader::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
SetCollisionHeader::~SetCollisionHeader()
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0x00, (u32)&%sCollisionHeader0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
delete collisionHeader;
|
||||
}
|
||||
|
||||
string SetCollisionHeader::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
|
||||
std::string SetCollisionHeader::GetBodySourceCode() const
|
||||
{
|
||||
return "";
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_COL_HEADER(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
string SetCollisionHeader::GetCommandCName()
|
||||
std::string SetCollisionHeader::GetCommandCName() const
|
||||
{
|
||||
return "SCmdColHeader";
|
||||
}
|
||||
|
||||
string SetCollisionHeader::GenerateExterns()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
RoomCommand SetCollisionHeader::GetRoomCommand()
|
||||
RoomCommand SetCollisionHeader::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetCollisionHeader;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../ZCollision.h"
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZCollision.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetCollisionHeader : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetCollisionHeader(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetCollisionHeader(ZFile* nParent);
|
||||
~SetCollisionHeader();
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
|
||||
private:
|
||||
ZCollisionHeader* collisionHeader;
|
||||
uint32_t segmentOffset;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,87 +1,64 @@
|
||||
#include "SetCsCamera.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetCsCamera::SetCsCamera(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetCsCamera::SetCsCamera(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
_rawData = rawData;
|
||||
_rawDataIndex = rawDataIndex;
|
||||
}
|
||||
|
||||
segmentOffset = 0;
|
||||
|
||||
int32_t numCameras = rawData[rawDataIndex + 1];
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
void SetCsCamera::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
int numCameras = cmdArg1;
|
||||
|
||||
uint32_t currentPtr = segmentOffset;
|
||||
int32_t numPoints = 0;
|
||||
|
||||
for (int32_t i = 0; i < numCameras; i++)
|
||||
{
|
||||
CsCameraEntry* entry = new CsCameraEntry(_rawData, currentPtr);
|
||||
CsCameraEntry entry(parent->GetRawData(), currentPtr);
|
||||
numPoints += entry.GetNumPoints();
|
||||
|
||||
currentPtr += entry.GetRawDataSize();
|
||||
cameras.push_back(entry);
|
||||
numPoints += entry->numPoints;
|
||||
|
||||
currentPtr += 8;
|
||||
}
|
||||
|
||||
if (numPoints > 0)
|
||||
{
|
||||
uint32_t currentPtr = cameras[0]->segmentOffset;
|
||||
uint32_t currentPtr = cameras.at(0).GetSegmentOffset();
|
||||
|
||||
for (int32_t i = 0; i < numPoints; i++)
|
||||
{
|
||||
int16_t x = BitConverter::ToInt16BE(rawData, currentPtr + 0);
|
||||
int16_t y = BitConverter::ToInt16BE(rawData, currentPtr + 2);
|
||||
int16_t z = BitConverter::ToInt16BE(rawData, currentPtr + 4);
|
||||
Vec3s p = {x, y, z};
|
||||
points.push_back(p);
|
||||
currentPtr += 6;
|
||||
ZVector vec(parent);
|
||||
vec.SetRawData(parent->GetRawData());
|
||||
vec.SetRawDataIndex(currentPtr);
|
||||
vec.SetScalarType(ZScalarType::ZSCALAR_S16);
|
||||
vec.SetDimensions(3);
|
||||
vec.ParseRawData();
|
||||
|
||||
currentPtr += vec.GetRawDataSize();
|
||||
points.push_back(vec);
|
||||
}
|
||||
}
|
||||
|
||||
if (segmentOffset != 0)
|
||||
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
}
|
||||
|
||||
SetCsCamera::~SetCsCamera()
|
||||
void SetCsCamera::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
for (CsCameraEntry* entry : cameras)
|
||||
delete entry;
|
||||
}
|
||||
|
||||
string SetCsCamera::GetSourceOutputCode(std::string prefix)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string SetCsCamera::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string SetCsCamera::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
string sourceOutput = "";
|
||||
|
||||
sourceOutput +=
|
||||
StringHelper::Sprintf("%s %i, (u32)&%sCsCameraList0x%06X };",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
cameras.size(), roomName.c_str(), segmentOffset);
|
||||
|
||||
if (points.size() > 0)
|
||||
{
|
||||
string declaration = "";
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
for (Vec3s point : points)
|
||||
for (auto& point : points)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", point.x, point.y,
|
||||
point.z, cameras[0]->segmentOffset + (index * 6));
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t%s, //0x%06X", point.GetBodySourceCode().c_str(),
|
||||
cameras.at(0).segmentOffset + (index * 6));
|
||||
|
||||
if (index < points.size() - 1)
|
||||
declaration += "\n";
|
||||
@@ -89,65 +66,97 @@ string SetCsCamera::GenerateSourceCodePass2(string roomName, uint32_t baseAddres
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(cameras[0]->segmentOffset, DeclarationAlignment::None,
|
||||
DeclarationPadding::None, points.size() * 6, "Vec3s",
|
||||
StringHelper::Sprintf("%sCsCameraPoints0x%06X",
|
||||
roomName.c_str(),
|
||||
cameras[0]->segmentOffset),
|
||||
points.size(), declaration);
|
||||
uint32_t segOffset = cameras.at(0).GetSegmentOffset();
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segOffset, DeclarationAlignment::Align4, points.size() * points.at(0).GetRawDataSize(),
|
||||
points.at(0).GetSourceTypeName().c_str(),
|
||||
StringHelper::Sprintf("%sCsCameraPoints_%06X", prefix.c_str(), segOffset),
|
||||
points.size(), declaration);
|
||||
}
|
||||
|
||||
if (!cameras.empty())
|
||||
{
|
||||
string declaration = "";
|
||||
std::string camPointsName = parent->GetDeclarationName(cameras.at(0).GetSegmentOffset());
|
||||
std::string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
size_t pointsIndex = 0;
|
||||
for (CsCameraEntry* entry : cameras)
|
||||
for (const auto& entry : cameras)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" %i, %i, (u32)&%sCsCameraPoints0x%06X[%i],",
|
||||
entry->type, entry->numPoints, roomName.c_str(),
|
||||
cameras[0]->segmentOffset, pointsIndex);
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t{ %i, %i, &%s[%i] },", entry.type, entry.numPoints,
|
||||
camPointsName.c_str(), pointsIndex);
|
||||
|
||||
if (index < cameras.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
pointsIndex += entry->numPoints;
|
||||
pointsIndex += entry.GetNumPoints();
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
const auto& entry = cameras.front();
|
||||
std::string camTypename = entry.GetSourceTypeName();
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::Pad16,
|
||||
cameras.size() * 8, "CsCameraEntry",
|
||||
StringHelper::Sprintf("%sCsCameraList0x%06X", roomName.c_str(), segmentOffset),
|
||||
cameras.size() * entry.GetRawDataSize(), camTypename,
|
||||
StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), camTypename.c_str(), segmentOffset),
|
||||
cameras.size(), declaration);
|
||||
}
|
||||
|
||||
return sourceOutput;
|
||||
}
|
||||
|
||||
size_t SetCsCamera::GetRawDataSize()
|
||||
std::string SetCsCamera::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_CAM_LIST(%i, %s)", cameras.size(),
|
||||
listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetCsCamera::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + (cameras.size() * 8) + (points.size() * 6);
|
||||
}
|
||||
|
||||
string SetCsCamera::GenerateExterns()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string SetCsCamera::GetCommandCName()
|
||||
std::string SetCsCamera::GetCommandCName() const
|
||||
{
|
||||
return "SCmdCsCameraList";
|
||||
}
|
||||
|
||||
RoomCommand SetCsCamera::GetRoomCommand()
|
||||
RoomCommand SetCsCamera::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetCsCamera;
|
||||
}
|
||||
|
||||
CsCameraEntry::CsCameraEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
CsCameraEntry::CsCameraEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: baseOffset(rawDataIndex), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)),
|
||||
numPoints(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)),
|
||||
segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)))
|
||||
numPoints(BitConverter::ToInt16BE(rawData, rawDataIndex + 2))
|
||||
{
|
||||
camAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
|
||||
segmentOffset = GETSEGOFFSET(camAddress);
|
||||
}
|
||||
|
||||
std::string CsCameraEntry::GetSourceTypeName() const
|
||||
{
|
||||
return "CsCameraEntry";
|
||||
}
|
||||
|
||||
int32_t CsCameraEntry::GetRawDataSize() const
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
int16_t CsCameraEntry::GetNumPoints() const
|
||||
{
|
||||
return numPoints;
|
||||
}
|
||||
|
||||
segptr_t CsCameraEntry::GetCamAddress() const
|
||||
{
|
||||
return camAddress;
|
||||
}
|
||||
|
||||
uint32_t CsCameraEntry::GetSegmentOffset() const
|
||||
{
|
||||
return segmentOffset;
|
||||
}
|
||||
|
||||
@@ -1,37 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Vec3s.h"
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
#include "ZVector.h"
|
||||
|
||||
class CsCameraEntry
|
||||
{
|
||||
public:
|
||||
CsCameraEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
CsCameraEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
int32_t baseOffset;
|
||||
int32_t type;
|
||||
int32_t numPoints;
|
||||
std::string GetSourceTypeName() const;
|
||||
int32_t GetRawDataSize() const;
|
||||
|
||||
int16_t GetNumPoints() const;
|
||||
segptr_t GetCamAddress() const;
|
||||
uint32_t GetSegmentOffset() const;
|
||||
|
||||
int baseOffset;
|
||||
int16_t type;
|
||||
int16_t numPoints;
|
||||
segptr_t camAddress;
|
||||
uint32_t segmentOffset;
|
||||
};
|
||||
|
||||
class SetCsCamera : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetCsCamera(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
~SetCsCamera();
|
||||
SetCsCamera(ZFile* nParent);
|
||||
|
||||
std::string GetSourceOutputCode(std::string prefix);
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
virtual size_t GetRawDataSize() override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
uint32_t segmentOffset;
|
||||
std::vector<CsCameraEntry*> cameras;
|
||||
std::vector<Vec3s> points;
|
||||
std::vector<uint8_t> _rawData;
|
||||
int32_t _rawDataIndex;
|
||||
std::vector<CsCameraEntry> cameras;
|
||||
std::vector<ZVector> points;
|
||||
};
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
#include "SetCutscenes.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetCutscenes::SetCutscenes(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
numCutscenes = rawData[rawDataIndex + 1];
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
}
|
||||
|
||||
string output = "";
|
||||
void SetCutscenes::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
std::string output = "";
|
||||
|
||||
numCutscenes = cmdArg1;
|
||||
if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97)
|
||||
{
|
||||
ZCutscene* cutscene = new ZCutscene(nZRoom->parent);
|
||||
cutscene->ExtractFromFile(rawData, segmentOffset, "");
|
||||
ZCutscene* cutscene = new ZCutscene(parent);
|
||||
cutscene->ExtractFromFile(parent->GetRawData(), segmentOffset);
|
||||
|
||||
auto decl = nZRoom->parent->GetDeclaration(segmentOffset);
|
||||
auto decl = parent->GetDeclaration(segmentOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
cutscene->DeclareVar(zRoom->GetName().c_str(), "");
|
||||
@@ -31,41 +32,38 @@ SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t
|
||||
else
|
||||
{
|
||||
int32_t currentPtr = segmentOffset;
|
||||
string declaration = "";
|
||||
std::string declaration = "";
|
||||
|
||||
for (uint8_t i = 0; i < numCutscenes; i++)
|
||||
{
|
||||
CutsceneEntry* entry = new CutsceneEntry(rawData, currentPtr);
|
||||
CutsceneEntry entry(parent->GetRawData(), currentPtr);
|
||||
cutsceneEntries.push_back(entry);
|
||||
currentPtr += 8;
|
||||
|
||||
declaration += StringHelper::Sprintf(
|
||||
" { %sCutsceneData0x%06X, 0x%04X, 0x%02X, 0x%02X },", zRoom->GetName().c_str(),
|
||||
entry->segmentOffset, entry->exit, entry->entrance, entry->flag);
|
||||
entry.segmentOffset, entry.exit, entry.entrance, entry.flag);
|
||||
|
||||
if (i < numCutscenes - 1)
|
||||
declaration += "\n";
|
||||
|
||||
ZCutsceneMM* cutscene = new ZCutsceneMM(nZRoom->parent);
|
||||
cutscene->ExtractFromXML(
|
||||
nullptr, rawData, entry->segmentOffset,
|
||||
""); // TODO: Use ExtractFromFile() here when that gets implemented
|
||||
ZCutsceneMM* cutscene = new ZCutsceneMM(parent);
|
||||
cutscene->ExtractFromFile(parent->GetRawData(), entry.segmentOffset);
|
||||
cutscenes.push_back(cutscene);
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, DeclarationPadding::None,
|
||||
cutsceneEntries.size() * 8, "CutsceneEntry",
|
||||
StringHelper::Sprintf("%sCutsceneEntryList0x%06X", zRoom->GetName().c_str(),
|
||||
segmentOffset),
|
||||
cutsceneEntries.size(), declaration);
|
||||
parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4,
|
||||
cutsceneEntries.size() * 8, "CutsceneEntry",
|
||||
StringHelper::Sprintf("%sCutsceneEntryList_%06X",
|
||||
zRoom->GetName().c_str(), segmentOffset),
|
||||
cutsceneEntries.size(), declaration);
|
||||
}
|
||||
|
||||
for (ZCutsceneBase* cutscene : cutscenes)
|
||||
{
|
||||
if (cutscene->getSegmentOffset() != 0)
|
||||
{
|
||||
Declaration* decl = zRoom->parent->GetDeclaration(cutscene->getSegmentOffset());
|
||||
Declaration* decl = parent->GetDeclaration(cutscene->getSegmentOffset());
|
||||
if (decl == nullptr)
|
||||
{
|
||||
cutscene->GetSourceOutputCode(zRoom->GetName());
|
||||
@@ -82,63 +80,35 @@ SetCutscenes::~SetCutscenes()
|
||||
{
|
||||
for (ZCutsceneBase* cutscene : cutscenes)
|
||||
delete cutscene;
|
||||
|
||||
for (CutsceneEntry* entry : cutsceneEntries)
|
||||
delete entry;
|
||||
}
|
||||
|
||||
string SetCutscenes::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
std::string SetCutscenes::GetBodySourceCode() const
|
||||
{
|
||||
string pass1 = ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress);
|
||||
Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset);
|
||||
if (decl != nullptr)
|
||||
{
|
||||
return StringHelper::Sprintf("%s %i, (u32)%s", pass1.c_str(), numCutscenes,
|
||||
decl->varName.c_str());
|
||||
}
|
||||
return StringHelper::Sprintf("%s %i, (u32)%sCutsceneData0x%06X", pass1.c_str(), numCutscenes,
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
}
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
|
||||
size_t SetCutscenes::GetRawDataSize()
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + (0);
|
||||
}
|
||||
|
||||
string SetCutscenes::GenerateExterns()
|
||||
{
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
{
|
||||
return StringHelper::Sprintf("extern CutsceneEntry %sCutsceneEntryList0x%06X[];\n",
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
}
|
||||
|
||||
Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset);
|
||||
if (decl != nullptr && decl->varName != "")
|
||||
{
|
||||
return StringHelper::Sprintf("extern s32 %s[];\n", decl->varName.c_str());
|
||||
}
|
||||
return StringHelper::Sprintf("extern s32 %sCutsceneData0x%06X[];\n", zRoom->GetName().c_str(),
|
||||
segmentOffset);
|
||||
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_LIST(%i, %s)", numCutscenes,
|
||||
listName.c_str());
|
||||
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_DATA(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
string SetCutscenes::GetCommandCName()
|
||||
size_t SetCutscenes::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize();
|
||||
}
|
||||
|
||||
std::string SetCutscenes::GetCommandCName() const
|
||||
{
|
||||
return "SCmdCutsceneData";
|
||||
}
|
||||
|
||||
RoomCommand SetCutscenes::GetRoomCommand()
|
||||
RoomCommand SetCutscenes::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetCutscenes;
|
||||
}
|
||||
|
||||
string SetCutscenes::GetSourceOutputCode(std::string prefix)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
CutsceneEntry::CutsceneEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: segmentOffset(BitConverter::ToInt32BE(rawData, rawDataIndex + 0) & 0x00FFFFFF),
|
||||
CutsceneEntry::CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 0))),
|
||||
exit(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), entrance(rawData[rawDataIndex + 6]),
|
||||
flag(rawData[rawDataIndex + 7])
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../ZCutscene.h"
|
||||
#include "../../ZCutsceneMM.h"
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZCutscene.h"
|
||||
#include "ZCutsceneMM.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class CutsceneEntry
|
||||
{
|
||||
public:
|
||||
CutsceneEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
uint32_t segmentOffset;
|
||||
uint16_t exit;
|
||||
@@ -18,21 +18,19 @@ public:
|
||||
class SetCutscenes : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetCutscenes(ZFile* nParent);
|
||||
~SetCutscenes();
|
||||
|
||||
std::string GetSourceOutputCode(std::string prefix);
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
virtual size_t GetRawDataSize() override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<ZCutsceneBase*> cutscenes;
|
||||
std::vector<CutsceneEntry*> cutsceneEntries; // (MM Only)
|
||||
uint32_t segmentOffset;
|
||||
uint8_t numCutscenes; // (MM Only)
|
||||
std::vector<uint8_t> _rawData;
|
||||
int32_t _rawDataIndex;
|
||||
};
|
||||
std::vector<CutsceneEntry> cutsceneEntries; // (MM Only)
|
||||
uint8_t numCutscenes; // (MM Only)
|
||||
};
|
||||
|
||||
@@ -1,27 +1,27 @@
|
||||
#include "SetEchoSettings.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SetEchoSettings::SetEchoSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetEchoSettings::SetEchoSettings(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
echo = rawData[rawDataIndex + 0x07];
|
||||
}
|
||||
|
||||
string SetEchoSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetEchoSettings::ParseRawData()
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0, { 0 }, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
echo);
|
||||
ZRoomCommand::ParseRawData();
|
||||
echo = parent->GetRawData().at(rawDataIndex + 0x07);
|
||||
}
|
||||
|
||||
string SetEchoSettings::GetCommandCName()
|
||||
std::string SetEchoSettings::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("SCENE_CMD_ECHO_SETTINGS(%i)", echo);
|
||||
}
|
||||
|
||||
std::string SetEchoSettings::GetCommandCName() const
|
||||
{
|
||||
return "SCmdEchoSettings";
|
||||
}
|
||||
|
||||
RoomCommand SetEchoSettings::GetRoomCommand()
|
||||
RoomCommand SetEchoSettings::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetEchoSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetEchoSettings : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetEchoSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetEchoSettings(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
|
||||
private:
|
||||
uint8_t echo;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,86 +1,83 @@
|
||||
#include "SetEntranceList.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
#include "BitConverter.h"
|
||||
#include "SetStartPositionList.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SetEntranceList::SetEntranceList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetEntranceList::SetEntranceList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
|
||||
entrances = vector<EntranceEntry*>();
|
||||
|
||||
_rawData = rawData;
|
||||
_rawDataIndex = rawDataIndex;
|
||||
}
|
||||
|
||||
SetEntranceList::~SetEntranceList()
|
||||
void SetEntranceList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
for (EntranceEntry* entry : entrances)
|
||||
delete entry;
|
||||
if (segmentOffset != 0)
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
}
|
||||
|
||||
string SetEntranceList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetEntranceList::ParseRawDataLate()
|
||||
{
|
||||
string sourceOutput =
|
||||
StringHelper::Sprintf("%s 0x00, (u32)&%sEntranceList0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
|
||||
// Parse Entrances and Generate Declaration
|
||||
zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined
|
||||
int32_t numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
|
||||
int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
|
||||
uint32_t currentPtr = segmentOffset;
|
||||
|
||||
for (int32_t i = 0; i < numEntrances; i++)
|
||||
{
|
||||
EntranceEntry* entry = new EntranceEntry(_rawData, currentPtr);
|
||||
EntranceEntry entry(parent->GetRawData(), currentPtr);
|
||||
entrances.push_back(entry);
|
||||
|
||||
currentPtr += 2;
|
||||
}
|
||||
|
||||
string declaration = "";
|
||||
|
||||
int32_t index = 0;
|
||||
|
||||
for (EntranceEntry* entry : entrances)
|
||||
{
|
||||
declaration +=
|
||||
StringHelper::Sprintf(" { 0x%02X, 0x%02X }, //0x%06X \n", entry->startPositionIndex,
|
||||
entry->roomToLoad, segmentOffset + (index * 2));
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, entrances.size() * 2, "EntranceEntry",
|
||||
StringHelper::Sprintf("%sEntranceList0x%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
entrances.size(), declaration);
|
||||
|
||||
return sourceOutput;
|
||||
}
|
||||
|
||||
string SetEntranceList::GenerateExterns()
|
||||
void SetEntranceList::DeclareReferencesLate(const std::string& prefix)
|
||||
{
|
||||
return StringHelper::Sprintf("extern EntranceEntry %sEntranceList0x%06X[];\n",
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
if (!entrances.empty())
|
||||
{
|
||||
std::string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& entry : entrances)
|
||||
{
|
||||
declaration +=
|
||||
StringHelper::Sprintf(" { %s }, //0x%06X", entry.GetBodySourceCode().c_str(),
|
||||
segmentOffset + (index * 2));
|
||||
if (index + 1 < entrances.size())
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, entrances.size() * 2, "EntranceEntry",
|
||||
StringHelper::Sprintf("%sEntranceList0x%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
entrances.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
string SetEntranceList::GetCommandCName()
|
||||
std::string SetEntranceList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ENTRANCE_LIST(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
std::string SetEntranceList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdEntranceList";
|
||||
}
|
||||
|
||||
RoomCommand SetEntranceList::GetRoomCommand()
|
||||
RoomCommand SetEntranceList::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetEntranceList;
|
||||
}
|
||||
|
||||
EntranceEntry::EntranceEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
EntranceEntry::EntranceEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
startPositionIndex = rawData[rawDataIndex + 0];
|
||||
roomToLoad = rawData[rawDataIndex + 1];
|
||||
}
|
||||
startPositionIndex = rawData.at(rawDataIndex + 0);
|
||||
roomToLoad = rawData.at(rawDataIndex + 1);
|
||||
}
|
||||
|
||||
std::string EntranceEntry::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("0x%02X, 0x%02X", startPositionIndex, roomToLoad);
|
||||
}
|
||||
|
||||
@@ -1,30 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class EntranceEntry
|
||||
{
|
||||
public:
|
||||
EntranceEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
protected:
|
||||
uint8_t startPositionIndex;
|
||||
uint8_t roomToLoad;
|
||||
|
||||
EntranceEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class SetEntranceList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetEntranceList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
~SetEntranceList();
|
||||
SetEntranceList(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
void ParseRawDataLate() override;
|
||||
void DeclareReferencesLate(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<EntranceEntry*> entrances;
|
||||
uint32_t segmentOffset;
|
||||
std::vector<uint8_t> _rawData;
|
||||
int32_t _rawDataIndex;
|
||||
};
|
||||
std::vector<EntranceEntry> entrances;
|
||||
};
|
||||
|
||||
@@ -1,71 +1,67 @@
|
||||
#include "SetExitList.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetExitList::SetExitList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetExitList::SetExitList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
exits = vector<uint16_t>();
|
||||
|
||||
if (segmentOffset != 0)
|
||||
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
|
||||
_rawData = rawData;
|
||||
_rawDataIndex = rawDataIndex;
|
||||
}
|
||||
|
||||
string SetExitList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetExitList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
string sourceOutput =
|
||||
StringHelper::Sprintf("%s 0x00, (u32)&%sExitList0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
if (segmentOffset != 0)
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
}
|
||||
|
||||
void SetExitList::ParseRawDataLate()
|
||||
{
|
||||
// Parse Entrances and Generate Declaration
|
||||
zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined
|
||||
int32_t numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
|
||||
int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
|
||||
uint32_t currentPtr = segmentOffset;
|
||||
|
||||
for (int32_t i = 0; i < numEntrances; i++)
|
||||
{
|
||||
uint16_t exit = BitConverter::ToInt16BE(_rawData, currentPtr);
|
||||
uint16_t exit = BitConverter::ToUInt16BE(parent->GetRawData(), currentPtr);
|
||||
exits.push_back(exit);
|
||||
|
||||
currentPtr += 2;
|
||||
}
|
||||
|
||||
string declaration = "";
|
||||
|
||||
for (uint16_t exit : exits)
|
||||
declaration += StringHelper::Sprintf(" 0x%04X,\n", exit);
|
||||
;
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, exits.size() * 2, "u16",
|
||||
StringHelper::Sprintf("%sExitList0x%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
exits.size(), declaration);
|
||||
|
||||
return sourceOutput;
|
||||
}
|
||||
|
||||
string SetExitList::GenerateExterns()
|
||||
void SetExitList::DeclareReferencesLate(const std::string& prefix)
|
||||
{
|
||||
return StringHelper::Sprintf("extern u16 %sExitList0x%06X[];\n", zRoom->GetName().c_str(),
|
||||
segmentOffset);
|
||||
;
|
||||
if (!exits.empty())
|
||||
{
|
||||
std::string declaration = "";
|
||||
|
||||
for (size_t i = 0; i < exits.size(); i++)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" 0x%04X,", exits.at(i));
|
||||
if (i + 1 < exits.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::Align4, exits.size() * 2, "u16",
|
||||
StringHelper::Sprintf("%sExitList_%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
exits.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
string SetExitList::GetCommandCName()
|
||||
std::string SetExitList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_EXIT_LIST(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
std::string SetExitList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdExitList";
|
||||
}
|
||||
|
||||
RoomCommand SetExitList::GetRoomCommand()
|
||||
RoomCommand SetExitList::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetExitList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetExitList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetExitList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetExitList(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
void ParseRawDataLate() override;
|
||||
void DeclareReferencesLate(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<uint16_t> exits;
|
||||
uint32_t segmentOffset;
|
||||
std::vector<uint8_t> _rawData;
|
||||
int32_t _rawDataIndex;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,69 +1,94 @@
|
||||
#include "SetLightList.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SetLightList::SetLightList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetLightList::SetLightList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
this->ptrRoom = nZRoom;
|
||||
this->numLights = rawData[rawDataIndex + 1];
|
||||
this->segment = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
|
||||
}
|
||||
|
||||
// std::string declarations = StringHelper::Sprintf("LightInfo %sLightInfo0x%06X[] =\n{\n",
|
||||
// this->ptrRoom->GetName().c_str(), this->segment);
|
||||
string declarations = "";
|
||||
void SetLightList::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
std::string declarations = "";
|
||||
|
||||
int32_t currentPtr = this->segment;
|
||||
for (int32_t i = 0; i < this->numLights; i++)
|
||||
numLights = cmdArg1;
|
||||
int32_t currentPtr = segmentOffset;
|
||||
for (int i = 0; i < this->numLights; i++)
|
||||
{
|
||||
uint8_t type = rawData[currentPtr + 0];
|
||||
int16_t x = BitConverter::ToInt16BE(rawData, currentPtr + 2);
|
||||
int16_t y = BitConverter::ToInt16BE(rawData, currentPtr + 4);
|
||||
int16_t z = BitConverter::ToInt16BE(rawData, currentPtr + 6);
|
||||
uint8_t r = rawData[currentPtr + 8];
|
||||
uint8_t g = rawData[currentPtr + 9];
|
||||
uint8_t b = rawData[currentPtr + 10];
|
||||
uint8_t drawGlow = rawData[currentPtr + 11];
|
||||
int16_t radius = BitConverter::ToInt16BE(rawData, currentPtr + 12);
|
||||
LightInfo light(parent->GetRawData(), currentPtr);
|
||||
|
||||
currentPtr += 14;
|
||||
|
||||
declarations += StringHelper::Sprintf(
|
||||
" { 0x%02X, { %i, %i, %i, { 0x%02X, 0x%02X, 0x%02X }, 0x%02X, 0x%04X } },", type, x,
|
||||
y, z, r, g, b, drawGlow, radius);
|
||||
|
||||
if (i < this->numLights - 1)
|
||||
declarations += "\n";
|
||||
currentPtr += light.GetRawDataSize();
|
||||
lights.push_back(light);
|
||||
}
|
||||
|
||||
this->ptrRoom->parent->AddDeclarationArray(
|
||||
this->segment, DeclarationAlignment::None, this->numLights * 0xE, "LightInfo",
|
||||
StringHelper::Sprintf("%sLightInfo0x%06X", this->ptrRoom->GetName().c_str(), this->segment),
|
||||
this->numLights, declarations);
|
||||
}
|
||||
|
||||
string SetLightList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetLightList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s %i, &%sLightInfo0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), this->numLights,
|
||||
this->ptrRoom->GetName().c_str(), this->segment);
|
||||
if (!lights.empty())
|
||||
{
|
||||
std::string declarations = "";
|
||||
|
||||
for (size_t i = 0; i < lights.size(); i++)
|
||||
{
|
||||
declarations +=
|
||||
StringHelper::Sprintf("\t{ %s },", lights.at(i).GetBodySourceCode().c_str());
|
||||
|
||||
if (i < lights.size() - 1)
|
||||
declarations += "\n";
|
||||
}
|
||||
|
||||
const auto& light = lights.front();
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, lights.size() * light.GetRawDataSize(),
|
||||
light.GetSourceTypeName(),
|
||||
StringHelper::Sprintf("%sLightInfo0x%06X", prefix.c_str(), segmentOffset),
|
||||
lights.size(), declarations);
|
||||
}
|
||||
}
|
||||
|
||||
string SetLightList::GetCommandCName()
|
||||
std::string SetLightList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_LIGHT_LIST(%i, %s)", numLights, listName.c_str());
|
||||
}
|
||||
|
||||
std::string SetLightList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdLightList";
|
||||
}
|
||||
|
||||
string SetLightList::GenerateExterns()
|
||||
{
|
||||
return StringHelper::Sprintf("extern LightInfo %sLightInfo0x%06X[];\n",
|
||||
this->ptrRoom->GetName().c_str(), this->segment);
|
||||
}
|
||||
|
||||
RoomCommand SetLightList::GetRoomCommand()
|
||||
RoomCommand SetLightList::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetLightList;
|
||||
}
|
||||
}
|
||||
|
||||
LightInfo::LightInfo(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
type = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0);
|
||||
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
|
||||
y = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
|
||||
z = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
|
||||
r = BitConverter::ToUInt8BE(rawData, rawDataIndex + 8);
|
||||
g = BitConverter::ToUInt8BE(rawData, rawDataIndex + 9);
|
||||
b = BitConverter::ToUInt8BE(rawData, rawDataIndex + 10);
|
||||
drawGlow = BitConverter::ToUInt8BE(rawData, rawDataIndex + 11);
|
||||
radius = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
|
||||
}
|
||||
|
||||
std::string LightInfo::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"0x%02X, { %i, %i, %i, { 0x%02X, 0x%02X, 0x%02X }, 0x%02X, 0x%04X }", type, x, y, z, r, g,
|
||||
b, drawGlow, radius);
|
||||
}
|
||||
|
||||
std::string LightInfo::GetSourceTypeName() const
|
||||
{
|
||||
return "LightInfo";
|
||||
}
|
||||
|
||||
size_t LightInfo::GetRawDataSize() const
|
||||
{
|
||||
return 0x0E;
|
||||
}
|
||||
|
||||
@@ -2,23 +2,42 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../ZRoom.h"
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class LightInfo
|
||||
{
|
||||
public:
|
||||
LightInfo(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
std::string GetSourceTypeName() const;
|
||||
size_t GetRawDataSize() const;
|
||||
|
||||
protected:
|
||||
uint8_t type;
|
||||
int16_t x, y, z;
|
||||
uint8_t r, g, b;
|
||||
uint8_t drawGlow;
|
||||
int16_t radius;
|
||||
};
|
||||
|
||||
class SetLightList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetLightList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetLightList(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
uint8_t numLights;
|
||||
uint32_t segment;
|
||||
|
||||
ZRoom* ptrRoom;
|
||||
};
|
||||
std::vector<LightInfo> lights;
|
||||
};
|
||||
|
||||
@@ -1,113 +1,103 @@
|
||||
#include "SetLightingSettings.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetLightingSettings::SetLightingSettings(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
uint8_t numLights = rawData[rawDataIndex + 1];
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numLights; i++)
|
||||
settings.push_back(new LightingSettings(rawData, segmentOffset + (i * 22)));
|
||||
void SetLightingSettings::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
uint8_t numLights = cmdArg1;
|
||||
|
||||
if (numLights > 0)
|
||||
for (int i = 0; i < numLights; i++)
|
||||
settings.push_back(LightingSettings(parent->GetRawData(), segmentOffset + (i * 22)));
|
||||
}
|
||||
|
||||
void SetLightingSettings::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
if (settings.size() > 0)
|
||||
{
|
||||
string declaration = "";
|
||||
std::string declaration = "";
|
||||
|
||||
for (int32_t i = 0; i < numLights; i++)
|
||||
for (size_t i = 0; i < settings.size(); i++)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(
|
||||
"\t{ 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, "
|
||||
"0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%04X, "
|
||||
"0x%04X }, // 0x%06X",
|
||||
settings[i]->ambientClrR, settings[i]->ambientClrG, settings[i]->ambientClrB,
|
||||
settings[i]->diffuseClrA_R, settings[i]->diffuseClrA_G, settings[i]->diffuseClrA_B,
|
||||
settings[i]->diffuseDirA_X, settings[i]->diffuseDirA_Y, settings[i]->diffuseDirA_Z,
|
||||
settings[i]->diffuseClrB_R, settings[i]->diffuseClrB_G, settings[i]->diffuseClrB_B,
|
||||
settings[i]->diffuseDirB_X, settings[i]->diffuseDirB_Y, settings[i]->diffuseDirB_Z,
|
||||
settings[i]->fogClrR, settings[i]->fogClrG, settings[i]->fogClrB, settings[i]->unk,
|
||||
settings[i]->drawDistance, segmentOffset + (i * 22));
|
||||
if (i + 1 < numLights)
|
||||
declaration += StringHelper::Sprintf("\t{ %s }, // 0x%06X",
|
||||
settings.at(i).GetBodySourceCode().c_str(),
|
||||
segmentOffset + (i * 22));
|
||||
if (i + 1 < settings.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, numLights * 22,
|
||||
"LightSettings",
|
||||
StringHelper::Sprintf("%sLightSettings_%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
numLights, declaration);
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::Align4,
|
||||
settings.size() * settings.front().GetRawDataSize(), "LightSettings",
|
||||
StringHelper::Sprintf("%sLightSettings0x%06X", prefix.c_str(), segmentOffset),
|
||||
settings.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
SetLightingSettings::~SetLightingSettings()
|
||||
std::string SetLightingSettings::GetBodySourceCode() const
|
||||
{
|
||||
for (LightingSettings* setting : settings)
|
||||
delete setting;
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ENV_LIGHT_SETTINGS(%i, %s)", settings.size(),
|
||||
listName.c_str());
|
||||
}
|
||||
|
||||
string SetLightingSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s %i, (u32)&%sLightSettings_%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), settings.size(),
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
}
|
||||
|
||||
string SetLightingSettings::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string SetLightingSettings::GetCommandCName()
|
||||
std::string SetLightingSettings::GetCommandCName() const
|
||||
{
|
||||
return "SCmdLightSettingList";
|
||||
}
|
||||
|
||||
string SetLightingSettings::GenerateExterns()
|
||||
{
|
||||
return StringHelper::Sprintf("extern LightSettings %sLightSettings_%06X[];\n",
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
}
|
||||
|
||||
RoomCommand SetLightingSettings::GetRoomCommand()
|
||||
RoomCommand SetLightingSettings::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetLightingSettings;
|
||||
}
|
||||
|
||||
LightingSettings::LightingSettings(vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
LightingSettings::LightingSettings(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
const uint8_t* data = rawData.data();
|
||||
ambientClrR = rawData.at(rawDataIndex + 0);
|
||||
ambientClrG = rawData.at(rawDataIndex + 1);
|
||||
ambientClrB = rawData.at(rawDataIndex + 2);
|
||||
|
||||
ambientClrR = data[rawDataIndex + 0];
|
||||
ambientClrG = data[rawDataIndex + 1];
|
||||
ambientClrB = data[rawDataIndex + 2];
|
||||
diffuseClrA_R = rawData.at(rawDataIndex + 3);
|
||||
diffuseClrA_G = rawData.at(rawDataIndex + 4);
|
||||
diffuseClrA_B = rawData.at(rawDataIndex + 5);
|
||||
|
||||
diffuseClrA_R = data[rawDataIndex + 3];
|
||||
diffuseClrA_G = data[rawDataIndex + 4];
|
||||
diffuseClrA_B = data[rawDataIndex + 5];
|
||||
diffuseDirA_X = rawData.at(rawDataIndex + 6);
|
||||
diffuseDirA_Y = rawData.at(rawDataIndex + 7);
|
||||
diffuseDirA_Z = rawData.at(rawDataIndex + 8);
|
||||
|
||||
diffuseDirA_X = data[rawDataIndex + 6];
|
||||
diffuseDirA_Y = data[rawDataIndex + 7];
|
||||
diffuseDirA_Z = data[rawDataIndex + 8];
|
||||
diffuseClrB_R = rawData.at(rawDataIndex + 9);
|
||||
diffuseClrB_G = rawData.at(rawDataIndex + 10);
|
||||
diffuseClrB_B = rawData.at(rawDataIndex + 11);
|
||||
|
||||
diffuseClrB_R = data[rawDataIndex + 9];
|
||||
diffuseClrB_G = data[rawDataIndex + 10];
|
||||
diffuseClrB_B = data[rawDataIndex + 11];
|
||||
diffuseDirB_X = rawData.at(rawDataIndex + 12);
|
||||
diffuseDirB_Y = rawData.at(rawDataIndex + 13);
|
||||
diffuseDirB_Z = rawData.at(rawDataIndex + 14);
|
||||
|
||||
diffuseDirB_X = data[rawDataIndex + 12];
|
||||
diffuseDirB_Y = data[rawDataIndex + 13];
|
||||
diffuseDirB_Z = data[rawDataIndex + 14];
|
||||
fogClrR = rawData.at(rawDataIndex + 15);
|
||||
fogClrG = rawData.at(rawDataIndex + 16);
|
||||
fogClrB = rawData.at(rawDataIndex + 17);
|
||||
|
||||
fogClrR = data[rawDataIndex + 15];
|
||||
fogClrG = data[rawDataIndex + 16];
|
||||
fogClrB = data[rawDataIndex + 17];
|
||||
|
||||
unk = BitConverter::ToInt16BE(data, rawDataIndex + 18);
|
||||
drawDistance = BitConverter::ToInt16BE(data, rawDataIndex + 20);
|
||||
unk = BitConverter::ToInt16BE(rawData, rawDataIndex + 18);
|
||||
drawDistance = BitConverter::ToInt16BE(rawData, rawDataIndex + 20);
|
||||
}
|
||||
|
||||
std::string LightingSettings::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, "
|
||||
"0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%04X, 0x%04X",
|
||||
ambientClrR, ambientClrG, ambientClrB, diffuseClrA_R, diffuseClrA_G, diffuseClrA_B,
|
||||
diffuseDirA_X, diffuseDirA_Y, diffuseDirA_Z, diffuseClrB_R, diffuseClrB_G, diffuseClrB_B,
|
||||
diffuseDirB_X, diffuseDirB_Y, diffuseDirB_Z, fogClrR, fogClrG, fogClrB, unk, drawDistance);
|
||||
}
|
||||
|
||||
size_t LightingSettings::GetRawDataSize() const
|
||||
{
|
||||
return 0x16;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class LightingSettings
|
||||
{
|
||||
public:
|
||||
LightingSettings(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
size_t GetRawDataSize() const;
|
||||
|
||||
protected:
|
||||
uint8_t ambientClrR, ambientClrG, ambientClrB;
|
||||
uint8_t diffuseClrA_R, diffuseClrA_G, diffuseClrA_B;
|
||||
uint8_t diffuseDirA_X, diffuseDirA_Y, diffuseDirA_Z;
|
||||
@@ -13,23 +20,21 @@ public:
|
||||
uint8_t fogClrR, fogClrG, fogClrB;
|
||||
uint16_t unk;
|
||||
uint16_t drawDistance;
|
||||
|
||||
LightingSettings(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class SetLightingSettings : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetLightingSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
~SetLightingSettings();
|
||||
SetLightingSettings(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
uint32_t segmentOffset;
|
||||
std::vector<LightingSettings*> settings;
|
||||
};
|
||||
std::vector<LightingSettings> settings;
|
||||
};
|
||||
|
||||
@@ -1,319 +1,114 @@
|
||||
#include "SetMesh.h"
|
||||
#include <Globals.h>
|
||||
#include <Path.h>
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZBackground.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
void GenDListDeclarations(ZRoom* zRoom, ZFile* parent, ZDisplayList* dList);
|
||||
|
||||
SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex,
|
||||
int32_t segAddressOffset)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetMesh::SetMesh(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
data = rawData[rawDataIndex + 1];
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
|
||||
string declaration = "";
|
||||
meshHeaderType = rawData[segmentOffset + 0];
|
||||
|
||||
if (meshHeaderType == 0)
|
||||
{
|
||||
uint32_t dListStart = Seg2Filespace(BitConverter::ToInt32BE(rawData, segmentOffset + 4),
|
||||
zRoom->parent->baseAddress);
|
||||
uint32_t dListEnd = Seg2Filespace(BitConverter::ToInt32BE(rawData, segmentOffset + 8),
|
||||
zRoom->parent->baseAddress);
|
||||
|
||||
int8_t numEntries = rawData[segmentOffset + 1];
|
||||
uint32_t currentPtr = dListStart;
|
||||
|
||||
// Hack for Syotes
|
||||
for (int32_t i = 0; i < abs(segAddressOffset); i++)
|
||||
{
|
||||
rawData.erase(rawData.begin());
|
||||
segmentOffset--;
|
||||
}
|
||||
|
||||
if (numEntries > 0)
|
||||
{
|
||||
std::string polyGfxBody = "";
|
||||
std::string polyGfxType = "";
|
||||
int32_t polyGfxSize = 0;
|
||||
|
||||
for (int32_t i = 0; i < numEntries; i++)
|
||||
{
|
||||
PolygonDlist polyGfxList(zRoom->GetName(), rawData, currentPtr, zRoom->parent,
|
||||
zRoom);
|
||||
if (polyGfxList.opaDList != nullptr)
|
||||
{
|
||||
GenDListDeclarations(rawData, polyGfxList.opaDList);
|
||||
}
|
||||
if (polyGfxList.xluDList != nullptr)
|
||||
{
|
||||
GenDListDeclarations(rawData, polyGfxList.xluDList);
|
||||
}
|
||||
polyGfxBody += polyGfxList.GetBodySourceCode(true);
|
||||
polyGfxType = polyGfxList.GetSourceTypeName();
|
||||
polyGfxSize = polyGfxList.GetRawDataSize();
|
||||
|
||||
currentPtr += polyGfxList.GetRawDataSize();
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
dListStart, DeclarationAlignment::Align4, numEntries * polyGfxSize, polyGfxType,
|
||||
StringHelper::Sprintf("%s%s0x%06X", zRoom->GetName().c_str(), polyGfxType.c_str(),
|
||||
dListStart),
|
||||
numEntries, polyGfxBody);
|
||||
}
|
||||
|
||||
declaration = "\n ";
|
||||
declaration += StringHelper::Sprintf("{ 0 }, 0x%02X, ", numEntries);
|
||||
declaration += "\n ";
|
||||
|
||||
std::string entriesStr = "NULL";
|
||||
|
||||
if (dListStart != 0)
|
||||
{
|
||||
entriesStr = zRoom->parent->GetDeclaration(dListStart)->varName;
|
||||
}
|
||||
declaration += StringHelper::Sprintf("%s, ", entriesStr.c_str());
|
||||
declaration += "\n ";
|
||||
|
||||
if (dListEnd != 0)
|
||||
declaration += StringHelper::Sprintf("%s + ARRAY_COUNT(%s), ", entriesStr.c_str(),
|
||||
entriesStr.c_str());
|
||||
else
|
||||
declaration += "NULL, ";
|
||||
declaration += "\n";
|
||||
|
||||
zRoom->parent->AddDeclaration(
|
||||
segmentOffset, DeclarationAlignment::Align16, 12, "MeshHeader0",
|
||||
StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
declaration);
|
||||
|
||||
zRoom->parent->AddDeclaration(dListStart + (numEntries * 8), DeclarationAlignment::None,
|
||||
DeclarationPadding::Pad16, 4, "static s32", "terminatorMaybe",
|
||||
"0x01000000");
|
||||
}
|
||||
else if (meshHeaderType == 1)
|
||||
{
|
||||
PolygonType1 polygon1(zRoom->GetName().c_str(), rawData, segmentOffset, zRoom->parent,
|
||||
zRoom);
|
||||
if (polygon1.polyGfxList.opaDList != nullptr)
|
||||
{
|
||||
GenDListDeclarations(rawData, polygon1.polyGfxList.opaDList);
|
||||
}
|
||||
if (polygon1.polyGfxList.xluDList != nullptr)
|
||||
{
|
||||
GenDListDeclarations(rawData, polygon1.polyGfxList.xluDList);
|
||||
}
|
||||
polygon1.DeclareAndGenerateOutputCode();
|
||||
}
|
||||
else if (meshHeaderType == 2)
|
||||
{
|
||||
MeshHeader2* meshHeader2 = new MeshHeader2();
|
||||
meshHeader2->headerType = 2;
|
||||
|
||||
meshHeader2->entries = vector<MeshEntry2*>();
|
||||
meshHeader2->dListStart = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 4));
|
||||
meshHeader2->dListEnd = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 8));
|
||||
|
||||
int8_t numEntries = rawData[segmentOffset + 1];
|
||||
uint32_t currentPtr = meshHeader2->dListStart;
|
||||
|
||||
for (int32_t i = 0; i < numEntries; i++)
|
||||
{
|
||||
MeshEntry2* entry = new MeshEntry2();
|
||||
entry->playerXMax = BitConverter::ToInt16BE(rawData, currentPtr + 0);
|
||||
entry->playerZMax = BitConverter::ToInt16BE(rawData, currentPtr + 2);
|
||||
entry->playerXMin = BitConverter::ToInt16BE(rawData, currentPtr + 4);
|
||||
entry->playerZMin = BitConverter::ToInt16BE(rawData, currentPtr + 6);
|
||||
|
||||
entry->opaqueDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 8));
|
||||
entry->translucentDListAddr =
|
||||
GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 12));
|
||||
|
||||
if (entry->opaqueDListAddr != 0)
|
||||
{
|
||||
entry->opaqueDList = new ZDisplayList(
|
||||
rawData, entry->opaqueDListAddr,
|
||||
ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ?
|
||||
DListType::F3DEX :
|
||||
DListType::F3DZEX),
|
||||
zRoom->parent);
|
||||
entry->opaqueDList->scene = zRoom->scene;
|
||||
GenDListDeclarations(rawData, entry->opaqueDList);
|
||||
}
|
||||
|
||||
if (entry->translucentDListAddr != 0)
|
||||
{
|
||||
entry->translucentDList = new ZDisplayList(
|
||||
rawData, entry->translucentDListAddr,
|
||||
ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ?
|
||||
DListType::F3DEX :
|
||||
DListType::F3DZEX),
|
||||
zRoom->parent);
|
||||
entry->translucentDList->scene = zRoom->scene;
|
||||
GenDListDeclarations(rawData, entry->translucentDList);
|
||||
}
|
||||
|
||||
meshHeader2->entries.push_back(entry);
|
||||
|
||||
currentPtr += 16;
|
||||
}
|
||||
|
||||
declaration += StringHelper::Sprintf("{ 2 }, 0x%02lX, ", meshHeader2->entries.size());
|
||||
|
||||
if (meshHeader2->dListStart != 0)
|
||||
declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ",
|
||||
zRoom->GetName().c_str(), meshHeader2->dListStart);
|
||||
else
|
||||
declaration += "0, ";
|
||||
|
||||
if (meshHeader2->dListEnd != 0)
|
||||
declaration += StringHelper::Sprintf(
|
||||
"(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)",
|
||||
zRoom->GetName().c_str(), meshHeader2->dListStart, zRoom->GetName().c_str(),
|
||||
meshHeader2->dListStart);
|
||||
else
|
||||
declaration += "0";
|
||||
declaration += "\n";
|
||||
|
||||
zRoom->parent->AddDeclaration(
|
||||
segmentOffset, DeclarationAlignment::None, 12, "MeshHeader2",
|
||||
StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
declaration);
|
||||
|
||||
declaration = "";
|
||||
|
||||
for (size_t i = 0; i < meshHeader2->entries.size(); i++)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(
|
||||
" { %i, %i, %i, %i, ", meshHeader2->entries[i]->playerXMax,
|
||||
meshHeader2->entries[i]->playerZMax, meshHeader2->entries[i]->playerXMin,
|
||||
meshHeader2->entries[i]->playerZMin);
|
||||
|
||||
if (meshHeader2->entries[i]->opaqueDListAddr != 0)
|
||||
declaration += StringHelper::Sprintf("(u32)%sDL_%06X, ", zRoom->GetName().c_str(),
|
||||
meshHeader2->entries[i]->opaqueDListAddr);
|
||||
else
|
||||
declaration += "0, ";
|
||||
|
||||
if (meshHeader2->entries[i]->translucentDListAddr != 0)
|
||||
declaration +=
|
||||
StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(),
|
||||
meshHeader2->entries[i]->translucentDListAddr);
|
||||
else
|
||||
declaration += "0 },\n";
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
meshHeader2->dListStart, DeclarationAlignment::None, DeclarationPadding::None,
|
||||
(meshHeader2->entries.size() * 16) + 0, "MeshEntry2",
|
||||
StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(),
|
||||
meshHeader2->dListStart, meshHeader2->entries.size()),
|
||||
meshHeader2->entries.size(), declaration);
|
||||
|
||||
zRoom->parent->AddDeclaration(meshHeader2->dListStart + (meshHeader2->entries.size() * 16),
|
||||
DeclarationAlignment::None, DeclarationPadding::Pad16, 4,
|
||||
"static s32", "terminatorMaybe", "0x01000000");
|
||||
|
||||
meshHeader = meshHeader2;
|
||||
}
|
||||
}
|
||||
|
||||
SetMesh::~SetMesh()
|
||||
void SetMesh::ParseRawData()
|
||||
{
|
||||
if (meshHeader != nullptr)
|
||||
ZRoomCommand::ParseRawData();
|
||||
auto& parentRawData = parent->GetRawData();
|
||||
meshHeaderType = parentRawData.at(segmentOffset);
|
||||
|
||||
switch (meshHeaderType)
|
||||
{
|
||||
delete meshHeader;
|
||||
meshHeader = nullptr;
|
||||
case 0:
|
||||
polyType = std::make_shared<PolygonType2>(parent, parentRawData, segmentOffset, zRoom);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
polyType = std::make_shared<PolygonType1>(parent, parentRawData, segmentOffset, zRoom);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
polyType = std::make_shared<PolygonType2>(parent, parentRawData, segmentOffset, zRoom);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::runtime_error(StringHelper::Sprintf("Error in SetMesh::ParseRawData\n"
|
||||
"\t Unknown meshHeaderType: %i\n",
|
||||
meshHeaderType));
|
||||
}
|
||||
|
||||
polyType->ParseRawData();
|
||||
}
|
||||
|
||||
void SetMesh::GenDListDeclarations(std::vector<uint8_t> rawData, ZDisplayList* dList)
|
||||
void SetMesh::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
string srcVarName =
|
||||
polyType->SetName(polyType->GetDefaultName(prefix));
|
||||
polyType->DeclareReferences(prefix);
|
||||
polyType->DeclareAndGenerateOutputCode(prefix);
|
||||
}
|
||||
|
||||
void GenDListDeclarations(ZRoom* zRoom, ZFile* parent, ZDisplayList* dList)
|
||||
{
|
||||
if (dList == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::string srcVarName =
|
||||
StringHelper::Sprintf("%s%s", zRoom->GetName().c_str(), dList->GetName().c_str());
|
||||
|
||||
dList->SetName(srcVarName);
|
||||
string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName());
|
||||
dList->scene = zRoom->scene;
|
||||
std::string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName());
|
||||
|
||||
for (ZDisplayList* otherDList : dList->otherDLists)
|
||||
GenDListDeclarations(rawData, otherDList);
|
||||
GenDListDeclarations(zRoom, parent, otherDList);
|
||||
|
||||
for (pair<uint32_t, string> vtxEntry : dList->vtxDeclarations)
|
||||
for (const auto& vtxEntry : dList->vtxDeclarations)
|
||||
{
|
||||
DeclarationAlignment alignment = DeclarationAlignment::Align8;
|
||||
DeclarationAlignment alignment = DeclarationAlignment::Align4;
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
alignment = DeclarationAlignment::None;
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
parent->AddDeclarationArray(
|
||||
vtxEntry.first, alignment, dList->vertices[vtxEntry.first].size() * 16, "static Vtx",
|
||||
StringHelper::Sprintf("%sVtx_%06X", zRoom->GetName().c_str(), vtxEntry.first),
|
||||
dList->vertices[vtxEntry.first].size(), vtxEntry.second);
|
||||
}
|
||||
|
||||
for (pair<uint32_t, string> texEntry : dList->texDeclarations)
|
||||
{
|
||||
zRoom->textures[texEntry.first] = dList->textures[texEntry.first];
|
||||
}
|
||||
}
|
||||
|
||||
std::string SetMesh::GenDListExterns(ZDisplayList* dList)
|
||||
{
|
||||
string sourceOutput = "";
|
||||
std::string sourceOutput = "";
|
||||
|
||||
if (Globals::Instance->includeFilePrefix)
|
||||
sourceOutput += StringHelper::Sprintf("extern Gfx %sDL_%06X[];\n", zRoom->GetName().c_str(),
|
||||
dList->GetRawDataIndex());
|
||||
else
|
||||
sourceOutput += StringHelper::Sprintf("extern Gfx DL_%06X[];\n", dList->GetRawDataIndex());
|
||||
sourceOutput += StringHelper::Sprintf("extern Gfx %sDL_%06X[];\n", zRoom->GetName().c_str(),
|
||||
dList->GetRawDataIndex());
|
||||
|
||||
for (ZDisplayList* otherDList : dList->otherDLists)
|
||||
sourceOutput += GenDListExterns(otherDList);
|
||||
|
||||
for (pair<uint32_t, string> texEntry : dList->texDeclarations)
|
||||
sourceOutput += StringHelper::Sprintf("extern u64 %sTex_%06X[];\n",
|
||||
zRoom->GetName().c_str(), texEntry.first);
|
||||
|
||||
sourceOutput += dList->defines;
|
||||
|
||||
return sourceOutput;
|
||||
}
|
||||
|
||||
string SetMesh::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
std::string SetMesh::GetBodySourceCode() const
|
||||
{
|
||||
string sourceOutput = "";
|
||||
|
||||
Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset);
|
||||
|
||||
sourceOutput += StringHelper::Sprintf(
|
||||
"%s %i, &%s", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), data,
|
||||
decl->varName.c_str());
|
||||
|
||||
return sourceOutput;
|
||||
std::string list = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_MESH(%s)", list.c_str());
|
||||
}
|
||||
|
||||
string SetMesh::GenerateExterns()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t SetMesh::GetRawDataSize()
|
||||
size_t SetMesh::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize();
|
||||
}
|
||||
|
||||
string SetMesh::GetCommandCName()
|
||||
std::string SetMesh::GetCommandCName() const
|
||||
{
|
||||
return "SCmdMesh";
|
||||
}
|
||||
|
||||
RoomCommand SetMesh::GetRoomCommand()
|
||||
RoomCommand SetMesh::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetMesh;
|
||||
}
|
||||
@@ -324,20 +119,36 @@ PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector<uint8_t>
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
room = nRoom;
|
||||
zRoom = nRoom;
|
||||
|
||||
name = GetDefaultName(prefix.c_str(), rawDataIndex);
|
||||
|
||||
ParseRawData();
|
||||
|
||||
opaDList = MakeDlist(opa, prefix);
|
||||
xluDList = MakeDlist(xlu, prefix);
|
||||
}
|
||||
|
||||
void PolygonDlist::ParseRawData()
|
||||
{
|
||||
opa = BitConverter::ToUInt32BE(rawData, rawDataIndex);
|
||||
xlu = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
|
||||
switch (polyType)
|
||||
{
|
||||
case 2:
|
||||
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
|
||||
y = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
|
||||
z = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
|
||||
unk_06 = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
|
||||
|
||||
opa = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
|
||||
xlu = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
|
||||
break;
|
||||
|
||||
default:
|
||||
opa = BitConverter::ToUInt32BE(rawData, rawDataIndex);
|
||||
xlu = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PolygonDlist::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
opaDList = MakeDlist(opa, prefix);
|
||||
xluDList = MakeDlist(xlu, prefix);
|
||||
}
|
||||
|
||||
ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, const std::string& prefix)
|
||||
@@ -353,18 +164,26 @@ ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, const std::string& prefix)
|
||||
rawData, dlistAddress,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
ZDisplayList* dlist = new ZDisplayList(rawData, dlistAddress, dlistLength, parent);
|
||||
|
||||
string dListStr = StringHelper::Sprintf("%sPolygonDlist_%06X", prefix.c_str(), dlistAddress);
|
||||
dlist->SetName(dListStr);
|
||||
dlist->scene = room->scene;
|
||||
dlist->GetSourceOutputCode(prefix);
|
||||
GenDListDeclarations(zRoom, parent, dlist);
|
||||
|
||||
return dlist;
|
||||
}
|
||||
|
||||
size_t PolygonDlist::GetRawDataSize()
|
||||
size_t PolygonDlist::GetRawDataSize() const
|
||||
{
|
||||
return 0x08;
|
||||
switch (polyType)
|
||||
{
|
||||
case 2:
|
||||
return 0x10;
|
||||
|
||||
default:
|
||||
return 0x08;
|
||||
}
|
||||
}
|
||||
|
||||
void PolygonDlist::SetPolyType(uint8_t nPolyType)
|
||||
{
|
||||
polyType = nPolyType;
|
||||
}
|
||||
|
||||
void PolygonDlist::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
@@ -381,55 +200,34 @@ void PolygonDlist::DeclareVar(const std::string& prefix, const std::string& body
|
||||
std::string PolygonDlist::GetBodySourceCode(bool arrayElement)
|
||||
{
|
||||
std::string bodyStr = "";
|
||||
std::string opaStr = "NULL";
|
||||
std::string xluStr = "NULL";
|
||||
std::string opaStr = parent->GetDeclarationPtrName(opa);
|
||||
std::string xluStr = parent->GetDeclarationPtrName(xlu);
|
||||
if (arrayElement)
|
||||
{
|
||||
bodyStr += " { \n ";
|
||||
bodyStr += " { ";
|
||||
}
|
||||
else
|
||||
{
|
||||
bodyStr += "\n ";
|
||||
}
|
||||
|
||||
if (polyType == 2)
|
||||
{
|
||||
bodyStr += StringHelper::Sprintf("{ %6i, %6i, %6i }, %6i, ", x, y, z, unk_06);
|
||||
}
|
||||
|
||||
bodyStr += StringHelper::Sprintf("%s, ", opaStr.c_str());
|
||||
bodyStr += StringHelper::Sprintf("%s", xluStr.c_str());
|
||||
|
||||
if (arrayElement)
|
||||
{
|
||||
bodyStr += " },";
|
||||
}
|
||||
else
|
||||
{
|
||||
bodyStr += "\n";
|
||||
}
|
||||
|
||||
if (opa != 0)
|
||||
{
|
||||
Declaration* decl = parent->GetDeclaration(Seg2Filespace(opa, parent->baseAddress));
|
||||
if (decl != nullptr)
|
||||
{
|
||||
opaStr = decl->varName;
|
||||
}
|
||||
else
|
||||
{
|
||||
opaStr = StringHelper::Sprintf("0x%08X", opa);
|
||||
}
|
||||
}
|
||||
if (xlu != 0)
|
||||
{
|
||||
Declaration* decl = parent->GetDeclaration(Seg2Filespace(xlu, parent->baseAddress));
|
||||
if (decl != nullptr)
|
||||
{
|
||||
xluStr = decl->varName;
|
||||
}
|
||||
else
|
||||
{
|
||||
xluStr = StringHelper::Sprintf("0x%08X", xlu);
|
||||
}
|
||||
}
|
||||
|
||||
bodyStr += StringHelper::Sprintf(" %s, \n", opaStr.c_str());
|
||||
if (arrayElement)
|
||||
{
|
||||
bodyStr += " ";
|
||||
}
|
||||
|
||||
bodyStr += StringHelper::Sprintf(" %s, \n", xluStr.c_str());
|
||||
|
||||
if (arrayElement)
|
||||
{
|
||||
bodyStr += " },";
|
||||
}
|
||||
|
||||
return bodyStr;
|
||||
}
|
||||
|
||||
@@ -455,7 +253,14 @@ std::string PolygonDlist::GetDefaultName(const std::string& prefix, uint32_t add
|
||||
|
||||
std::string PolygonDlist::GetSourceTypeName()
|
||||
{
|
||||
return "PolygonDlist";
|
||||
switch (polyType)
|
||||
{
|
||||
case 2:
|
||||
return "PolygonDlist2";
|
||||
|
||||
default:
|
||||
return "PolygonDlist";
|
||||
}
|
||||
}
|
||||
|
||||
std::string PolygonDlist::GetName()
|
||||
@@ -519,12 +324,12 @@ size_t BgImage::GetRawDataSize()
|
||||
return 0x1C;
|
||||
}
|
||||
|
||||
std::string BgImage::GetBodySourceCode(bool arrayElement)
|
||||
std::string BgImage::GetBodySourceCode(bool arrayElement) const
|
||||
{
|
||||
std::string bodyStr = "";
|
||||
std::string bodyStr = " ";
|
||||
if (arrayElement)
|
||||
{
|
||||
bodyStr += " { \n ";
|
||||
bodyStr += "{ \n ";
|
||||
}
|
||||
|
||||
if (!isSubStruct)
|
||||
@@ -538,21 +343,7 @@ std::string BgImage::GetBodySourceCode(bool arrayElement)
|
||||
}
|
||||
}
|
||||
|
||||
std::string backgroundName = "NULL";
|
||||
if (source != 0)
|
||||
{
|
||||
uint32_t address = Seg2Filespace(source, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(address);
|
||||
|
||||
if (decl == nullptr)
|
||||
{
|
||||
backgroundName += StringHelper::Sprintf("0x%08X, ", source);
|
||||
}
|
||||
else
|
||||
{
|
||||
backgroundName = decl->varName;
|
||||
}
|
||||
}
|
||||
std::string backgroundName = parent->GetDeclarationPtrName(source);
|
||||
bodyStr += StringHelper::Sprintf("%s, ", backgroundName.c_str());
|
||||
bodyStr += "\n ";
|
||||
if (arrayElement)
|
||||
@@ -590,6 +381,10 @@ std::string BgImage::GetBodySourceCode(bool arrayElement)
|
||||
{
|
||||
bodyStr += " \n }, ";
|
||||
}
|
||||
else
|
||||
{
|
||||
bodyStr += "\n";
|
||||
}
|
||||
|
||||
return bodyStr;
|
||||
}
|
||||
@@ -609,29 +404,109 @@ std::string BgImage::GetName()
|
||||
return name;
|
||||
}
|
||||
|
||||
PolygonType1::PolygonType1(const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom)
|
||||
/* PolygonType section */
|
||||
|
||||
PolygonTypeBase::PolygonTypeBase(ZFile* nParent, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: rawData{nRawData}, rawDataIndex{nRawDataIndex}, parent{nParent}, zRoom{nRoom}
|
||||
{
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
type = BitConverter::ToUInt8BE(rawData, rawDataIndex);
|
||||
}
|
||||
|
||||
name = GetDefaultName(prefix.c_str(), rawDataIndex);
|
||||
void PolygonTypeBase::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
{
|
||||
std::string auxName = name;
|
||||
if (name == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
ParseRawData();
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, bodyStr);
|
||||
}
|
||||
|
||||
void PolygonTypeBase::DeclareAndGenerateOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string bodyStr = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
DeclareVar(prefix, bodyStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
decl->text = bodyStr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string PolygonTypeBase::GetSourceTypeName() const
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 2:
|
||||
return "PolygonType2";
|
||||
|
||||
case 1:
|
||||
return "PolygonType1";
|
||||
|
||||
default:
|
||||
return "PolygonType0";
|
||||
}
|
||||
}
|
||||
|
||||
std::string PolygonTypeBase::GetName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
void PolygonTypeBase::SetName(const std::string& newName)
|
||||
{
|
||||
name = newName;
|
||||
}
|
||||
|
||||
std::string PolygonTypeBase::GetDefaultName(const std::string& prefix) const
|
||||
{
|
||||
return StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), GetSourceTypeName().c_str(),
|
||||
rawDataIndex);
|
||||
}
|
||||
|
||||
PolygonType1::PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: PolygonTypeBase(nParent, nRawData, nRawDataIndex, nRoom)
|
||||
{
|
||||
}
|
||||
|
||||
void PolygonType1::ParseRawData()
|
||||
{
|
||||
format = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01);
|
||||
dlist = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
|
||||
|
||||
if (format == 2)
|
||||
{
|
||||
count = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08);
|
||||
list = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C);
|
||||
}
|
||||
|
||||
if (dlist != 0)
|
||||
{
|
||||
polyGfxList =
|
||||
PolygonDlist(prefix, rawData, Seg2Filespace(dlist, parent->baseAddress), parent, nRoom);
|
||||
PolygonDlist polyGfxList(zRoom->GetName(), rawData,
|
||||
Seg2Filespace(dlist, parent->baseAddress), parent, zRoom);
|
||||
polyGfxList.SetPolyType(type);
|
||||
polyGfxList.ParseRawData();
|
||||
polyGfxList.DeclareReferences(zRoom->GetName());
|
||||
polyDLists.push_back(polyGfxList);
|
||||
}
|
||||
}
|
||||
|
||||
void PolygonType1::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
polyDLists.at(0).DeclareAndGenerateOutputCode();
|
||||
|
||||
uint32_t listAddress;
|
||||
std::string bgImageArrayBody = "";
|
||||
switch (format)
|
||||
{
|
||||
case 1:
|
||||
single = BgImage(true, prefix, nRawData, nRawDataIndex + 0x08, parent);
|
||||
single = BgImage(true, prefix, rawData, rawDataIndex + 0x08, parent);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
@@ -668,20 +543,7 @@ PolygonType1::PolygonType1(const std::string& prefix, const std::vector<uint8_t>
|
||||
}
|
||||
}
|
||||
|
||||
void PolygonType1::ParseRawData()
|
||||
{
|
||||
type = BitConverter::ToUInt8BE(rawData, rawDataIndex);
|
||||
format = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01);
|
||||
dlist = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
|
||||
|
||||
if (format == 2)
|
||||
{
|
||||
count = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08);
|
||||
list = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C);
|
||||
}
|
||||
}
|
||||
|
||||
size_t PolygonType1::GetRawDataSize()
|
||||
size_t PolygonType1::GetRawDataSize() const
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
@@ -694,40 +556,14 @@ size_t PolygonType1::GetRawDataSize()
|
||||
return 0x20;
|
||||
}
|
||||
|
||||
void PolygonType1::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
{
|
||||
std::string auxName = name;
|
||||
if (name == "")
|
||||
{
|
||||
auxName = GetDefaultName(prefix, rawDataIndex);
|
||||
}
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, bodyStr);
|
||||
}
|
||||
|
||||
std::string PolygonType1::GetBodySourceCode()
|
||||
std::string PolygonType1::GetBodySourceCode() const
|
||||
{
|
||||
std::string bodyStr = "\n ";
|
||||
|
||||
bodyStr += "{ ";
|
||||
bodyStr += StringHelper::Sprintf("%i, %i, ", type, format);
|
||||
|
||||
std::string dlistStr = "NULL";
|
||||
if (dlist != 0)
|
||||
{
|
||||
uint32_t entryRecordAddress = Seg2Filespace(dlist, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(entryRecordAddress);
|
||||
|
||||
if (decl == nullptr)
|
||||
{
|
||||
polyGfxList.DeclareAndGenerateOutputCode();
|
||||
dlistStr = "&" + polyGfxList.GetName();
|
||||
}
|
||||
else
|
||||
{
|
||||
dlistStr = "&" + decl->varName;
|
||||
}
|
||||
}
|
||||
std::string dlistStr = parent->GetDeclarationPtrName(dlist);
|
||||
bodyStr += StringHelper::Sprintf("%s, ", dlistStr.c_str());
|
||||
bodyStr += "}, \n";
|
||||
|
||||
@@ -736,22 +572,10 @@ std::string PolygonType1::GetBodySourceCode()
|
||||
switch (format)
|
||||
{
|
||||
case 1:
|
||||
bodyStr += " " + single.GetBodySourceCode(false) + "\n";
|
||||
bodyStr += single.GetBodySourceCode(false);
|
||||
break;
|
||||
case 2:
|
||||
if (list != 0)
|
||||
{
|
||||
uint32_t listAddress = Seg2Filespace(list, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(listAddress);
|
||||
if (decl != nullptr)
|
||||
{
|
||||
listStr = decl->varName;
|
||||
}
|
||||
else
|
||||
{
|
||||
listStr = StringHelper::Sprintf("0x%08X", list);
|
||||
}
|
||||
}
|
||||
listStr = parent->GetDeclarationPtrName(list);
|
||||
bodyStr += StringHelper::Sprintf(" %i, %s, \n", count, listStr.c_str());
|
||||
break;
|
||||
|
||||
@@ -763,27 +587,7 @@ std::string PolygonType1::GetBodySourceCode()
|
||||
return bodyStr;
|
||||
}
|
||||
|
||||
void PolygonType1::DeclareAndGenerateOutputCode()
|
||||
{
|
||||
std::string bodyStr = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
DeclareVar("", bodyStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
decl->text = bodyStr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string PolygonType1::GetDefaultName(const std::string& prefix, uint32_t address)
|
||||
{
|
||||
return StringHelper::Sprintf("%sPolygonType1_%06X", prefix.c_str(), address);
|
||||
}
|
||||
|
||||
std::string PolygonType1::GetSourceTypeName()
|
||||
std::string PolygonType1::GetSourceTypeName() const
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
@@ -797,7 +601,71 @@ std::string PolygonType1::GetSourceTypeName()
|
||||
// return "PolygonType1";
|
||||
}
|
||||
|
||||
std::string PolygonType1::GetName()
|
||||
PolygonType2::PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: PolygonTypeBase(nParent, nRawData, nRawDataIndex, nRoom)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
void PolygonType2::ParseRawData()
|
||||
{
|
||||
num = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01);
|
||||
|
||||
start = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
|
||||
end = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08);
|
||||
|
||||
uint32_t currentPtr = GETSEGOFFSET(start);
|
||||
for (size_t i = 0; i < num; i++)
|
||||
{
|
||||
PolygonDlist entry(zRoom->GetName(), rawData, currentPtr, parent, zRoom);
|
||||
entry.SetPolyType(type);
|
||||
entry.ParseRawData();
|
||||
entry.DeclareReferences(zRoom->GetName());
|
||||
polyDLists.push_back(entry);
|
||||
currentPtr += entry.GetRawDataSize();
|
||||
}
|
||||
}
|
||||
|
||||
void PolygonType2::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
if (num > 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
|
||||
for (size_t i = 0; i < polyDLists.size(); i++)
|
||||
{
|
||||
declaration += polyDLists.at(i).GetBodySourceCode(true);
|
||||
if (i + 1 < polyDLists.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
std::string polyDlistType = polyDLists.at(0).GetSourceTypeName();
|
||||
std::string polyDListName = "";
|
||||
polyDListName = StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), polyDlistType.c_str(),
|
||||
GETSEGOFFSET(start));
|
||||
|
||||
parent->AddDeclarationArray(GETSEGOFFSET(start), DeclarationAlignment::Align4,
|
||||
polyDLists.size() * polyDLists.at(0).GetRawDataSize(),
|
||||
polyDlistType, polyDListName, polyDLists.size(), declaration);
|
||||
}
|
||||
|
||||
parent->AddDeclaration(GETSEGOFFSET(end), DeclarationAlignment::Align4,
|
||||
DeclarationPadding::Pad16, 4, "static s32", "terminatorMaybe",
|
||||
"0x01000000");
|
||||
}
|
||||
|
||||
std::string PolygonType2::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(start);
|
||||
|
||||
std::string body = StringHelper::Sprintf("\n %i, %i,\n", type, polyDLists.size());
|
||||
body += StringHelper::Sprintf(" %s,\n", listName.c_str());
|
||||
body +=
|
||||
StringHelper::Sprintf(" %s + ARRAY_COUNTU(%s)\n", listName.c_str(), listName.c_str());
|
||||
return body;
|
||||
}
|
||||
|
||||
size_t PolygonType2::GetRawDataSize() const
|
||||
{
|
||||
return 0x0C;
|
||||
}
|
||||
|
||||
@@ -1,57 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../ZDisplayList.h"
|
||||
#include "../ZRoomCommand.h"
|
||||
#include <memory>
|
||||
#include "ZBackground.h"
|
||||
|
||||
class MeshHeaderBase
|
||||
{
|
||||
public:
|
||||
int8_t headerType; // 0x00
|
||||
};
|
||||
|
||||
class MeshEntry2
|
||||
{
|
||||
public:
|
||||
int16_t playerXMax, playerZMax;
|
||||
int16_t playerXMin, playerZMin;
|
||||
|
||||
int32_t opaqueDListAddr;
|
||||
int32_t translucentDListAddr;
|
||||
|
||||
ZDisplayList* opaqueDList;
|
||||
ZDisplayList* translucentDList;
|
||||
};
|
||||
|
||||
class MeshHeader2 : public MeshHeaderBase
|
||||
{
|
||||
public:
|
||||
std::vector<MeshEntry2*> entries;
|
||||
uint32_t dListStart;
|
||||
uint32_t dListEnd;
|
||||
};
|
||||
#include "ZDisplayList.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class PolygonDlist
|
||||
{
|
||||
protected:
|
||||
segptr_t opa = 0; // Gfx*
|
||||
segptr_t xlu = 0; // Gfx*
|
||||
|
||||
std::vector<uint8_t> rawData;
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
ZRoom* room;
|
||||
std::string name;
|
||||
|
||||
void ParseRawData();
|
||||
ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix);
|
||||
|
||||
public:
|
||||
PolygonDlist() = default;
|
||||
PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZFile* nParent, ZRoom* nRoom);
|
||||
PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom);
|
||||
|
||||
size_t GetRawDataSize();
|
||||
void ParseRawData();
|
||||
void DeclareReferences(const std::string& prefix);
|
||||
|
||||
size_t GetRawDataSize() const;
|
||||
void SetPolyType(uint8_t nPolyType);
|
||||
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
|
||||
@@ -62,8 +27,25 @@ public:
|
||||
std::string GetSourceTypeName();
|
||||
std::string GetName();
|
||||
|
||||
protected:
|
||||
int16_t x, y, z; // polyType == 2
|
||||
int16_t unk_06; // polyType == 2
|
||||
|
||||
segptr_t opa = 0; // Gfx*
|
||||
segptr_t xlu = 0; // Gfx*
|
||||
|
||||
uint8_t polyType;
|
||||
|
||||
ZDisplayList* opaDList = nullptr; // Gfx*
|
||||
ZDisplayList* xluDList = nullptr; // Gfx*
|
||||
|
||||
std::vector<uint8_t> rawData;
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
ZRoom* zRoom;
|
||||
std::string name;
|
||||
|
||||
ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix);
|
||||
};
|
||||
|
||||
class BgImage
|
||||
@@ -97,19 +79,51 @@ public:
|
||||
BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent);
|
||||
|
||||
static size_t GetRawDataSize() ;
|
||||
static size_t GetRawDataSize();
|
||||
|
||||
std::string GetBodySourceCode(bool arrayElement);
|
||||
std::string GetBodySourceCode(bool arrayElement) const;
|
||||
|
||||
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
|
||||
static std::string GetSourceTypeName();
|
||||
std::string GetName();
|
||||
};
|
||||
|
||||
class PolygonType1
|
||||
class PolygonTypeBase
|
||||
{
|
||||
public:
|
||||
PolygonTypeBase(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZRoom* nRoom);
|
||||
|
||||
virtual void ParseRawData() = 0;
|
||||
virtual void DeclareReferences(const std::string& prefix) = 0;
|
||||
|
||||
virtual std::string GetBodySourceCode() const = 0;
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
void DeclareAndGenerateOutputCode(const std::string& prefix);
|
||||
|
||||
virtual std::string GetSourceTypeName() const;
|
||||
|
||||
std::string GetName() const;
|
||||
void SetName(const std::string& newName);
|
||||
virtual size_t GetRawDataSize() const = 0;
|
||||
|
||||
std::string GetDefaultName(const std::string& prefix) const;
|
||||
|
||||
protected:
|
||||
uint8_t type;
|
||||
|
||||
std::vector<PolygonDlist> polyDLists;
|
||||
|
||||
std::vector<uint8_t> rawData;
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
ZRoom* zRoom;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class PolygonType1 : public PolygonTypeBase
|
||||
{
|
||||
protected:
|
||||
uint8_t format;
|
||||
segptr_t dlist;
|
||||
|
||||
@@ -121,49 +135,56 @@ protected:
|
||||
segptr_t list; // BgImage*
|
||||
std::vector<BgImage> multiList;
|
||||
|
||||
std::vector<uint8_t> rawData;
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
std::string name;
|
||||
|
||||
void ParseRawData();
|
||||
|
||||
public:
|
||||
PolygonType1(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZFile* nParent, ZRoom* nRoom);
|
||||
PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZRoom* nRoom);
|
||||
|
||||
size_t GetRawDataSize() ;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetBodySourceCode();
|
||||
void DeclareAndGenerateOutputCode();
|
||||
std::string GetSourceTypeName() const override;
|
||||
|
||||
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
|
||||
std::string GetSourceTypeName();
|
||||
std::string GetName();
|
||||
size_t GetRawDataSize() const override;
|
||||
};
|
||||
|
||||
PolygonDlist polyGfxList;
|
||||
class PolygonType2 : public PolygonTypeBase
|
||||
{
|
||||
public:
|
||||
PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZRoom* nRoom);
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
uint8_t num;
|
||||
segptr_t start;
|
||||
segptr_t end;
|
||||
};
|
||||
|
||||
class SetMesh : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t segAddressOffset);
|
||||
~SetMesh();
|
||||
SetMesh(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
virtual size_t GetRawDataSize() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
MeshHeaderBase* meshHeader = nullptr;
|
||||
uint32_t segmentOffset;
|
||||
uint8_t data;
|
||||
uint8_t meshHeaderType;
|
||||
std::shared_ptr<PolygonTypeBase> polyType;
|
||||
|
||||
void GenDListDeclarations(std::vector<uint8_t> rawData, ZDisplayList* dList);
|
||||
std::string GenDListExterns(ZDisplayList* dList);
|
||||
};
|
||||
|
||||
@@ -1,101 +1,85 @@
|
||||
#include "SetMinimapChests.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetMinimapChests::SetMinimapChests(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetMinimapChests::SetMinimapChests(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
int32_t numChests = rawData[rawDataIndex + 1];
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
}
|
||||
|
||||
void SetMinimapChests::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
int numChests = cmdArg1;
|
||||
|
||||
int32_t currentPtr = segmentOffset;
|
||||
|
||||
for (int32_t i = 0; i < numChests; i++)
|
||||
{
|
||||
MinimapChest* chest = new MinimapChest(rawData, currentPtr);
|
||||
MinimapChest chest(parent->GetRawData(), currentPtr);
|
||||
chests.push_back(chest);
|
||||
|
||||
currentPtr += 10;
|
||||
}
|
||||
}
|
||||
|
||||
SetMinimapChests::~SetMinimapChests()
|
||||
void SetMinimapChests::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
for (MinimapChest* chest : chests)
|
||||
delete chest;
|
||||
}
|
||||
|
||||
string SetMinimapChests::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
string SetMinimapChests::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
string sourceOutput = "";
|
||||
|
||||
sourceOutput +=
|
||||
StringHelper::Sprintf("%s 0x%02X, (u32)%sMinimapChests0x%06X };",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
chests.size(), roomName.c_str(), segmentOffset);
|
||||
std::string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& chest : chests)
|
||||
{
|
||||
string declaration = "";
|
||||
declaration += StringHelper::Sprintf(" { %s },", chest.GetBodySourceCode().c_str());
|
||||
|
||||
size_t index = 0;
|
||||
for (MinimapChest* chest : chests)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },",
|
||||
chest->unk0, chest->unk2, chest->unk4, chest->unk6,
|
||||
chest->unk8);
|
||||
if (index < chests.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
if (index < chests.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, chests.size() * 10,
|
||||
"MinimapChest",
|
||||
StringHelper::Sprintf("%sMinimapChests0x%06X", roomName.c_str(), segmentOffset),
|
||||
chests.size(), declaration);
|
||||
index++;
|
||||
}
|
||||
|
||||
return sourceOutput;
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, chests.size() * 10, "MinimapChest",
|
||||
StringHelper::Sprintf("%sMinimapChests0x%06X", prefix.c_str(), segmentOffset),
|
||||
chests.size(), declaration);
|
||||
}
|
||||
|
||||
string SetMinimapChests::GenerateExterns()
|
||||
std::string SetMinimapChests::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("extern MinimapChest %sMinimapChests0x%06X[%i];\n",
|
||||
zRoom->GetName().c_str(), segmentOffset, chests.size());
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_MINIMAP_COMPASS_ICON_INFO(0x%02X, %s)", chests.size(),
|
||||
listName.c_str());
|
||||
}
|
||||
|
||||
string SetMinimapChests::GetCommandCName()
|
||||
std::string SetMinimapChests::GetCommandCName() const
|
||||
{
|
||||
return "SCmdMinimapChests";
|
||||
}
|
||||
|
||||
RoomCommand SetMinimapChests::GetRoomCommand()
|
||||
RoomCommand SetMinimapChests::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetMinimapChests;
|
||||
}
|
||||
|
||||
size_t SetMinimapChests::GetRawDataSize()
|
||||
size_t SetMinimapChests::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + (chests.size() * 10);
|
||||
}
|
||||
|
||||
MinimapChest::MinimapChest(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
MinimapChest::MinimapChest(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
|
||||
unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)),
|
||||
unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)),
|
||||
unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)),
|
||||
unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
std::string MinimapChest::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X", unk0, unk2, unk4, unk6,
|
||||
unk8);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class MinimapChest
|
||||
{
|
||||
public:
|
||||
MinimapChest(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
protected:
|
||||
uint16_t unk0;
|
||||
uint16_t unk2;
|
||||
uint16_t unk4;
|
||||
uint16_t unk6;
|
||||
uint16_t unk8;
|
||||
|
||||
MinimapChest(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class SetMinimapChests : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetMinimapChests(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
~SetMinimapChests();
|
||||
SetMinimapChests(ZFile* nParent);
|
||||
|
||||
std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
|
||||
std::string GetCommandCName() override;
|
||||
std::string GenerateExterns() override;
|
||||
RoomCommand GetRoomCommand() override;
|
||||
size_t GetRawDataSize() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<MinimapChest*> chests;
|
||||
uint32_t segmentOffset;
|
||||
};
|
||||
std::vector<MinimapChest> chests;
|
||||
};
|
||||
|
||||
@@ -1,74 +1,42 @@
|
||||
#include "SetMinimapList.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetMinimapList::SetMinimapList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetMinimapList::SetMinimapList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
listSegmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 0));
|
||||
unk4 = BitConverter::ToInt32BE(rawData, segmentOffset + 4);
|
||||
}
|
||||
|
||||
minimaps = vector<MinimapEntry*>();
|
||||
void SetMinimapList::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
listSegmentAddr = BitConverter::ToInt32BE(parent->GetRawData(), segmentOffset);
|
||||
listSegmentOffset = GETSEGOFFSET(listSegmentAddr);
|
||||
unk4 = BitConverter::ToInt32BE(parent->GetRawData(), segmentOffset + 4);
|
||||
|
||||
int32_t currentPtr = listSegmentOffset;
|
||||
|
||||
for (int32_t i = 0; i < zRoom->roomCount; i++)
|
||||
{
|
||||
MinimapEntry* entry = new MinimapEntry(rawData, currentPtr);
|
||||
MinimapEntry entry(parent->GetRawData(), currentPtr);
|
||||
minimaps.push_back(entry);
|
||||
|
||||
currentPtr += 10;
|
||||
}
|
||||
}
|
||||
|
||||
SetMinimapList::~SetMinimapList()
|
||||
void SetMinimapList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
for (MinimapEntry* entry : minimaps)
|
||||
delete entry;
|
||||
}
|
||||
|
||||
string SetMinimapList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0x%02X, (u32)&%sMinimapList0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), minimaps.size(),
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
}
|
||||
|
||||
string SetMinimapList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
string sourceOutput = "";
|
||||
|
||||
sourceOutput +=
|
||||
StringHelper::Sprintf("%s 0, (u32)&%sMinimapList0x%06X };",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
roomName.c_str(), segmentOffset, unk4);
|
||||
|
||||
{
|
||||
string declaration = StringHelper::Sprintf("(u32)%sMinimapEntryList0x%06X, 0x%08X",
|
||||
roomName.c_str(), listSegmentOffset, unk4);
|
||||
|
||||
zRoom->parent->AddDeclaration(
|
||||
segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 8, "MinimapList",
|
||||
StringHelper::Sprintf("%sMinimapList0x%06X", roomName.c_str(), segmentOffset),
|
||||
declaration);
|
||||
}
|
||||
|
||||
{
|
||||
string declaration = "";
|
||||
std::string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
for (MinimapEntry* entry : minimaps)
|
||||
for (const auto& entry : minimaps)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },",
|
||||
entry->unk0, entry->unk2, entry->unk4, entry->unk6,
|
||||
entry->unk8);
|
||||
declaration += StringHelper::Sprintf(" { %s },", entry.GetBodySourceCode().c_str());
|
||||
|
||||
if (index < minimaps.size() - 1)
|
||||
declaration += "\n";
|
||||
@@ -76,42 +44,55 @@ string SetMinimapList::GenerateSourceCodePass2(string roomName, uint32_t baseAdd
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
listSegmentOffset, DeclarationAlignment::None, DeclarationPadding::None,
|
||||
minimaps.size() * 10, "MinimapEntry",
|
||||
StringHelper::Sprintf("%sMinimapEntryList0x%06X", roomName.c_str(), listSegmentOffset),
|
||||
parent->AddDeclarationArray(
|
||||
listSegmentOffset, DeclarationAlignment::Align4, minimaps.size() * 10, "MinimapEntry",
|
||||
StringHelper::Sprintf("%sMinimapEntryList0x%06X", prefix.c_str(), listSegmentOffset),
|
||||
minimaps.size(), declaration);
|
||||
}
|
||||
|
||||
return sourceOutput;
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(listSegmentAddr);
|
||||
std::string declaration = StringHelper::Sprintf("\n\t%s, 0x%08X\n", listName.c_str(), unk4);
|
||||
|
||||
parent->AddDeclaration(
|
||||
segmentOffset, DeclarationAlignment::Align4, 8, "MinimapList",
|
||||
StringHelper::Sprintf("%sMinimapList0x%06X", prefix.c_str(), segmentOffset),
|
||||
declaration);
|
||||
}
|
||||
}
|
||||
|
||||
string SetMinimapList::GenerateExterns()
|
||||
std::string SetMinimapList::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("extern MinimapList %sMinimapList0x%06X;\n",
|
||||
zRoom->GetName().c_str(), listSegmentOffset);
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_MINIMAP_INFO(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
string SetMinimapList::GetCommandCName()
|
||||
std::string SetMinimapList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdMinimapSettings";
|
||||
}
|
||||
|
||||
RoomCommand SetMinimapList::GetRoomCommand()
|
||||
RoomCommand SetMinimapList::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetMinimapList;
|
||||
}
|
||||
|
||||
size_t SetMinimapList::GetRawDataSize()
|
||||
size_t SetMinimapList::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + (minimaps.size() * 10);
|
||||
}
|
||||
|
||||
MinimapEntry::MinimapEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
MinimapEntry::MinimapEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
|
||||
unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)),
|
||||
unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)),
|
||||
unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)),
|
||||
unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
std::string MinimapEntry::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X", unk0, unk2, unk4, unk6,
|
||||
unk8);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class MinimapEntry
|
||||
{
|
||||
public:
|
||||
MinimapEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
protected:
|
||||
uint16_t unk0;
|
||||
uint16_t unk2;
|
||||
uint16_t unk4;
|
||||
uint16_t unk6;
|
||||
uint16_t unk8;
|
||||
|
||||
MinimapEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class SetMinimapList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetMinimapList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
~SetMinimapList();
|
||||
SetMinimapList(ZFile* nParent);
|
||||
|
||||
std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
|
||||
std::string GetCommandCName() override;
|
||||
std::string GenerateExterns() override;
|
||||
RoomCommand GetRoomCommand() override;
|
||||
size_t GetRawDataSize() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<MinimapEntry*> minimaps;
|
||||
uint32_t segmentOffset;
|
||||
std::vector<MinimapEntry> minimaps;
|
||||
|
||||
segptr_t listSegmentAddr;
|
||||
uint32_t listSegmentOffset;
|
||||
uint32_t unk4;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,77 +1,73 @@
|
||||
#include "SetObjectList.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZNames.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZNames.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetObjectList::SetObjectList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
objects = vector<uint16_t>();
|
||||
uint8_t objectCnt = rawData[rawDataIndex + 1];
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
}
|
||||
|
||||
void SetObjectList::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
uint8_t objectCnt = parent->GetRawData().at(rawDataIndex + 1);
|
||||
uint32_t currentPtr = segmentOffset;
|
||||
|
||||
for (uint8_t i = 0; i < objectCnt; i++)
|
||||
{
|
||||
uint16_t objectIndex = BitConverter::ToInt16BE(rawData, currentPtr);
|
||||
uint16_t objectIndex = BitConverter::ToInt16BE(parent->GetRawData(), currentPtr);
|
||||
objects.push_back(objectIndex);
|
||||
currentPtr += 2;
|
||||
}
|
||||
|
||||
if (segmentOffset != 0)
|
||||
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
}
|
||||
|
||||
string SetObjectList::GenerateExterns()
|
||||
void SetObjectList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
return StringHelper::Sprintf("s16 %sObjectList0x%06X[];\n", zRoom->GetName().c_str(),
|
||||
segmentOffset);
|
||||
}
|
||||
|
||||
string SetObjectList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
string sourceOutput = "";
|
||||
|
||||
sourceOutput +=
|
||||
StringHelper::Sprintf("%s 0x%02X, (u32)%sObjectList0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
objects.size(), zRoom->GetName().c_str(), segmentOffset);
|
||||
|
||||
string declaration = "";
|
||||
|
||||
for (size_t i = 0; i < objects.size(); i++)
|
||||
if (!objects.empty())
|
||||
{
|
||||
uint16_t objectIndex = objects[i];
|
||||
declaration += StringHelper::Sprintf(" %s,", ZNames::GetObjectName(objectIndex).c_str());
|
||||
std::string declaration = "";
|
||||
|
||||
if (i < objects.size() - 1)
|
||||
declaration += "\n";
|
||||
for (size_t i = 0; i < objects.size(); i++)
|
||||
{
|
||||
uint16_t objectIndex = objects[i];
|
||||
declaration +=
|
||||
StringHelper::Sprintf(" %s,", ZNames::GetObjectName(objectIndex).c_str());
|
||||
|
||||
if (i < objects.size() - 1)
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, objects.size() * 2, "s16",
|
||||
StringHelper::Sprintf("%sObjectList_%06X", prefix.c_str(), segmentOffset),
|
||||
objects.size(), declaration);
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, objects.size() * 2, "s16",
|
||||
StringHelper::Sprintf("%sObjectList0x%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
objects.size(), declaration);
|
||||
|
||||
return sourceOutput;
|
||||
}
|
||||
|
||||
size_t SetObjectList::GetRawDataSize()
|
||||
std::string SetObjectList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_OBJECT_LIST(%i, %s)", objects.size(), listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetObjectList::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + (objects.size() * 2);
|
||||
}
|
||||
|
||||
string SetObjectList::GetCommandCName()
|
||||
std::string SetObjectList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdObjectList";
|
||||
}
|
||||
|
||||
RoomCommand SetObjectList::GetRoomCommand()
|
||||
RoomCommand SetObjectList::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetObjectList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetObjectList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetObjectList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetObjectList(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
virtual size_t GetRawDataSize() override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix);
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
private:
|
||||
std::vector<uint16_t> objects;
|
||||
uint32_t segmentOffset;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,241 +1,58 @@
|
||||
#include "SetPathways.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
REGISTER_ZFILENODE(Path, ZSetPathways);
|
||||
|
||||
using namespace std;
|
||||
|
||||
ZSetPathways::ZSetPathways(ZFile* nParent) : ZResource(nParent)
|
||||
SetPathways::SetPathways(ZFile* nParent) : ZRoomCommand(nParent), pathwayList(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
ZSetPathways::ZSetPathways(ZRoom* nZRoom, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
bool nIsFromHeader)
|
||||
: ZResource(nZRoom->parent), ZRoomCommand(nZRoom, nRawData, nRawDataIndex)
|
||||
void SetPathways::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
rawData = nRawData;
|
||||
rawDataIndex = nRawDataIndex;
|
||||
isFromHeader = nIsFromHeader;
|
||||
}
|
||||
|
||||
ZSetPathways::~ZSetPathways()
|
||||
{
|
||||
delete pathwayList;
|
||||
}
|
||||
|
||||
void ZSetPathways::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
{
|
||||
parent->AddDeclaration(cmdAddress, DeclarationAlignment::None, 8,
|
||||
StringHelper::Sprintf("static %s", GetCommandCName().c_str()),
|
||||
StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(),
|
||||
commandSet & 0x00FFFFFF, cmdIndex, cmdID),
|
||||
StringHelper::Sprintf("%s // 0x%04X", bodyStr.c_str(), cmdAddress));
|
||||
}
|
||||
|
||||
string ZSetPathways::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
if (pathwayList != nullptr)
|
||||
pathwayList->GetSourceOutputCode(parent->GetName());
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void ZSetPathways::ParseRawData()
|
||||
{
|
||||
if (isFromHeader)
|
||||
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
|
||||
else
|
||||
segmentOffset = rawDataIndex;
|
||||
|
||||
if (segmentOffset != 0)
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
|
||||
int32_t numPaths = (Globals::Instance->game != ZGame::MM_RETAIL) ?
|
||||
1 :
|
||||
zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 8;
|
||||
|
||||
pathwayList = new PathwayList(parent, rawData, segmentOffset, numPaths);
|
||||
}
|
||||
|
||||
string ZSetPathways::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetPathways::ParseRawDataLate()
|
||||
{
|
||||
ParseRawData();
|
||||
return "";
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
{
|
||||
auto numPaths = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 8;
|
||||
pathwayList.SetNumPaths(numPaths);
|
||||
}
|
||||
|
||||
pathwayList.SetRawDataIndex(segmentOffset);
|
||||
pathwayList.ParseRawData();
|
||||
}
|
||||
|
||||
string ZSetPathways::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
|
||||
void SetPathways::DeclareReferencesLate(const std::string& prefix)
|
||||
{
|
||||
string sourceOutput = "";
|
||||
|
||||
sourceOutput += StringHelper::Sprintf("\n\t%s 0, (u32)%sPathway0x%06X\n};",
|
||||
ZRoomCommand::GenerateSourceCodePass1("", 0).c_str(),
|
||||
parent->GetName().c_str(), segmentOffset);
|
||||
|
||||
if (pathwayList != nullptr)
|
||||
pathwayList->GetSourceOutputCode(parent->GetName());
|
||||
|
||||
return sourceOutput;
|
||||
pathwayList.SetName(StringHelper::Sprintf("%sPathway_%06X", prefix.c_str(), segmentOffset));
|
||||
pathwayList.DeclareReferences(prefix);
|
||||
pathwayList.GetSourceOutputCode(prefix);
|
||||
}
|
||||
|
||||
size_t ZSetPathways::GetRawDataSize()
|
||||
std::string SetPathways::GetBodySourceCode() const
|
||||
{
|
||||
size_t size = 0;
|
||||
if (pathwayList != nullptr)
|
||||
size += pathwayList->GetRawDataSize();
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_PATH_LIST(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetPathways::GetRawDataSize() const
|
||||
{
|
||||
int32_t size = pathwayList.GetRawDataSize();
|
||||
|
||||
return ZRoomCommand::GetRawDataSize() + size;
|
||||
}
|
||||
|
||||
string ZSetPathways::GenerateExterns()
|
||||
{
|
||||
if (pathwayList != nullptr)
|
||||
return pathwayList->GenerateExterns(parent->GetName());
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
string ZSetPathways::GetCommandCName()
|
||||
std::string SetPathways::GetCommandCName() const
|
||||
{
|
||||
return "SCmdPathList";
|
||||
}
|
||||
|
||||
RoomCommand ZSetPathways::GetRoomCommand()
|
||||
RoomCommand SetPathways::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetPathways;
|
||||
}
|
||||
|
||||
PathwayEntry::PathwayEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: numPoints(rawData[rawDataIndex + 0]), unk1(rawData[rawDataIndex + 1]),
|
||||
unk2(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)),
|
||||
listSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)))
|
||||
{
|
||||
uint32_t currentPtr = listSegmentOffset;
|
||||
uint8_t* data = rawData.data();
|
||||
|
||||
for (int32_t i = 0; i < numPoints; i++)
|
||||
{
|
||||
x = BitConverter::ToInt16BE(data, currentPtr + 0);
|
||||
y = BitConverter::ToInt16BE(data, currentPtr + 2);
|
||||
z = BitConverter::ToInt16BE(data, currentPtr + 4);
|
||||
|
||||
Vec3s point = Vec3s(x, y, z);
|
||||
points.push_back(point);
|
||||
|
||||
currentPtr += 6;
|
||||
}
|
||||
|
||||
if (numPoints == 0) // Hack for SharpOcarina
|
||||
{
|
||||
for (int32_t i = 0; i < 3; i++)
|
||||
{
|
||||
Vec3s point = Vec3s(0, 0, 0);
|
||||
points.push_back(point);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PathwayList::PathwayList(ZFile* nParent, std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t length)
|
||||
{
|
||||
parent = nParent;
|
||||
_rawDataIndex = rawDataIndex;
|
||||
|
||||
uint32_t currentPtr = rawDataIndex;
|
||||
|
||||
for (int32_t pathIndex = 0; pathIndex < length; pathIndex++)
|
||||
{
|
||||
PathwayEntry* path = new PathwayEntry(rawData, currentPtr);
|
||||
currentPtr += 8;
|
||||
|
||||
if (path->listSegmentOffset == 0)
|
||||
break;
|
||||
|
||||
pathways.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
PathwayList::~PathwayList()
|
||||
{
|
||||
for (PathwayEntry* path : pathways)
|
||||
delete path;
|
||||
}
|
||||
|
||||
void PathwayList::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
{
|
||||
string declaration = "";
|
||||
size_t index = 0;
|
||||
for (PathwayEntry* entry : pathways)
|
||||
{
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
declaration += StringHelper::Sprintf(" { %i, %i, %i, (u32)%sPathwayList0x%06X },",
|
||||
entry->numPoints, entry->unk1, entry->unk2,
|
||||
prefix.c_str(), entry->listSegmentOffset);
|
||||
else
|
||||
declaration +=
|
||||
StringHelper::Sprintf(" { %i, (u32)%sPathwayList0x%06X },", entry->numPoints,
|
||||
prefix.c_str(), entry->listSegmentOffset);
|
||||
|
||||
if (index < pathways.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
_rawDataIndex, DeclarationAlignment::None, DeclarationPadding::None,
|
||||
pathways.size() * 8, "Path",
|
||||
StringHelper::Sprintf("%sPathway0x%06X", prefix.c_str(), _rawDataIndex),
|
||||
pathways.size(), declaration);
|
||||
}
|
||||
|
||||
for (PathwayEntry* entry : pathways)
|
||||
{
|
||||
string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
for (Vec3s& point : entry->points)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", point.x, point.y,
|
||||
point.z, entry->listSegmentOffset + (index * 6));
|
||||
|
||||
if (index < entry->points.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
entry->listSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::Pad4,
|
||||
entry->points.size() * 6, "Vec3s",
|
||||
StringHelper::Sprintf("%sPathwayList0x%06X", prefix.c_str(), entry->listSegmentOffset),
|
||||
entry->points.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
size_t PathwayList::GetRawDataSize()
|
||||
{
|
||||
size_t pointsSize = 0;
|
||||
|
||||
for (PathwayEntry* entry : pathways)
|
||||
{
|
||||
pointsSize += entry->points.size() * 6;
|
||||
}
|
||||
|
||||
return pathways.size() * 8 + pointsSize;
|
||||
}
|
||||
|
||||
string PathwayList::GenerateExterns(const std::string& prefix)
|
||||
{
|
||||
string declaration = "";
|
||||
for (PathwayEntry* entry : pathways)
|
||||
{
|
||||
declaration += StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n",
|
||||
prefix.c_str(), entry->listSegmentOffset);
|
||||
}
|
||||
|
||||
return declaration;
|
||||
}
|
||||
|
||||
@@ -1,62 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../Vec3s.h"
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "Vec3s.h"
|
||||
#include "ZPath.h"
|
||||
#include "ZResource.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class PathwayEntry
|
||||
class SetPathways : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
int16_t x, y, z;
|
||||
SetPathways(ZFile* nParent);
|
||||
|
||||
PathwayEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
int32_t numPoints;
|
||||
int8_t unk1; // (MM Only)
|
||||
int16_t unk2; // (MM Only)
|
||||
uint32_t listSegmentOffset;
|
||||
std::vector<Vec3s> points;
|
||||
};
|
||||
|
||||
struct PathwayList
|
||||
{
|
||||
public:
|
||||
PathwayList(ZFile* nParent, std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t length);
|
||||
~PathwayList();
|
||||
|
||||
void GetSourceOutputCode(const std::string& prefix) ;
|
||||
size_t GetRawDataSize();
|
||||
std::string GenerateExterns(const std::string& prefix);
|
||||
|
||||
private:
|
||||
ZFile* parent;
|
||||
std::vector<PathwayEntry*> pathways;
|
||||
std::vector<uint8_t> _rawData;
|
||||
uint32_t _rawDataIndex;
|
||||
};
|
||||
|
||||
class ZSetPathways : public ZResource, public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
ZSetPathways(ZFile* nParent);
|
||||
ZSetPathways(ZRoom* nZRoom, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
bool nIsFromHeader);
|
||||
~ZSetPathways();
|
||||
|
||||
void ParseRawData() override;
|
||||
void ParseRawDataLate() override;
|
||||
void DeclareReferencesLate(const std::string& prefix) override;
|
||||
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
|
||||
std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
|
||||
RoomCommand GetRoomCommand() override;
|
||||
size_t GetRawDataSize() override;
|
||||
std::string GetCommandCName() override;
|
||||
std::string GenerateExterns() override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
uint32_t segmentOffset;
|
||||
PathwayList* pathwayList;
|
||||
bool isFromHeader = false;
|
||||
};
|
||||
ZPath pathwayList;
|
||||
};
|
||||
|
||||
@@ -1,30 +1,49 @@
|
||||
#include "SetRoomBehavior.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetRoomBehavior::SetRoomBehavior(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
gameplayFlags = rawData[rawDataIndex + 0x01];
|
||||
gameplayFlags2 = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x04);
|
||||
}
|
||||
|
||||
string SetRoomBehavior::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetRoomBehavior::ParseRawData()
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
|
||||
gameplayFlags, gameplayFlags2);
|
||||
;
|
||||
ZRoomCommand::ParseRawData();
|
||||
gameplayFlags = cmdArg1;
|
||||
gameplayFlags2 = BitConverter::ToInt32BE(parent->GetRawData(), rawDataIndex + 0x04);
|
||||
|
||||
currRoomUnk2 = gameplayFlags2 & 0xFF;
|
||||
|
||||
currRoomUnk5 = showInvisActors = (gameplayFlags2 >> 8) & 1;
|
||||
|
||||
msgCtxUnk = (gameplayFlags2 >> 10) & 1;
|
||||
|
||||
enablePosLights = (gameplayFlags2 >> 11) & 1;
|
||||
kankyoContextUnkE2 = (gameplayFlags2 >> 12) & 1;
|
||||
}
|
||||
|
||||
string SetRoomBehavior::GetCommandCName()
|
||||
std::string SetRoomBehavior::GetBodySourceCode() const
|
||||
{
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
{
|
||||
std::string enableLights = StringHelper::BoolStr(enablePosLights);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ROOM_BEHAVIOR(0x%02X, 0x%02X, %i, %i, %s, %i)",
|
||||
gameplayFlags, currRoomUnk2, currRoomUnk5, msgCtxUnk,
|
||||
enableLights.c_str(), kankyoContextUnkE2);
|
||||
}
|
||||
std::string showInvisible = StringHelper::BoolStr(showInvisActors);
|
||||
std::string disableWarps = StringHelper::BoolStr(msgCtxUnk);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ROOM_BEHAVIOR(0x%02X, 0x%02X, %s, %s)", gameplayFlags,
|
||||
currRoomUnk2, showInvisible.c_str(), disableWarps.c_str());
|
||||
}
|
||||
|
||||
std::string SetRoomBehavior::GetCommandCName() const
|
||||
{
|
||||
return "SCmdRoomBehavior";
|
||||
}
|
||||
|
||||
RoomCommand SetRoomBehavior::GetRoomCommand()
|
||||
RoomCommand SetRoomBehavior::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetRoomBehavior;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetRoomBehavior : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetRoomBehavior(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetRoomBehavior(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void ParseRawData() override;
|
||||
|
||||
private:
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
protected:
|
||||
uint8_t gameplayFlags;
|
||||
uint32_t gameplayFlags2;
|
||||
};
|
||||
|
||||
uint8_t currRoomUnk2;
|
||||
|
||||
uint8_t showInvisActors;
|
||||
uint8_t currRoomUnk5;
|
||||
|
||||
uint8_t msgCtxUnk;
|
||||
|
||||
uint8_t enablePosLights;
|
||||
uint8_t kankyoContextUnkE2;
|
||||
};
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
#include "SetRoomList.h"
|
||||
#include "../../BitConverter.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "../../ZFile.h"
|
||||
#include "../ZRoom.h"
|
||||
|
||||
using namespace std;
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetRoomList::SetRoomList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
int32_t numRooms = rawData[rawDataIndex + 1];
|
||||
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
|
||||
}
|
||||
|
||||
rooms = vector<RoomEntry*>();
|
||||
void SetRoomList::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
int numRooms = cmdArg1;
|
||||
|
||||
int32_t currentPtr = segmentOffset;
|
||||
|
||||
for (int32_t i = 0; i < numRooms; i++)
|
||||
{
|
||||
RoomEntry* entry = new RoomEntry(rawData, currentPtr);
|
||||
RoomEntry entry(parent->GetRawData(), currentPtr);
|
||||
rooms.push_back(entry);
|
||||
|
||||
currentPtr += 8;
|
||||
@@ -28,44 +28,32 @@ SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t r
|
||||
zRoom->roomCount = numRooms;
|
||||
}
|
||||
|
||||
SetRoomList::~SetRoomList()
|
||||
void SetRoomList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
for (RoomEntry* entry : rooms)
|
||||
delete entry;
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, rooms.size() * 8, "RomFile",
|
||||
StringHelper::Sprintf("%sRoomList0x%06X", prefix.c_str(), segmentOffset), 0, "");
|
||||
}
|
||||
|
||||
string SetRoomList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
std::string SetRoomList::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0x%02X, (u32)&%sRoomList0x%06X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), rooms.size(),
|
||||
zRoom->GetName().c_str(), segmentOffset);
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ROOM_LIST(%i, %s)", rooms.size(), listName.c_str());
|
||||
}
|
||||
|
||||
string SetRoomList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
string SetRoomList::GenerateExterns()
|
||||
{
|
||||
return StringHelper::Sprintf("extern RomFile %sRoomList0x%06X[];\n", zRoom->GetName().c_str(),
|
||||
segmentOffset);
|
||||
}
|
||||
|
||||
string SetRoomList::GetCommandCName()
|
||||
std::string SetRoomList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdRoomList";
|
||||
}
|
||||
|
||||
RoomCommand SetRoomList::GetRoomCommand()
|
||||
RoomCommand SetRoomList::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetRoomList;
|
||||
}
|
||||
|
||||
std::string SetRoomList::PreGenSourceFiles()
|
||||
void SetRoomList::PreGenSourceFiles()
|
||||
{
|
||||
string declaration = "";
|
||||
std::string declaration = "";
|
||||
|
||||
for (ZFile* file : Globals::Instance->files)
|
||||
{
|
||||
@@ -73,35 +61,28 @@ std::string SetRoomList::PreGenSourceFiles()
|
||||
{
|
||||
if (res->GetResourceType() == ZResourceType::Room && res != zRoom)
|
||||
{
|
||||
string roomName = res->GetName();
|
||||
declaration += StringHelper::Sprintf(
|
||||
" { (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n", roomName.c_str(),
|
||||
roomName.c_str());
|
||||
std::string roomName = res->GetName();
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t{ (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n",
|
||||
roomName.c_str(), roomName.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, rooms.size() * 8, "RomFile",
|
||||
StringHelper::Sprintf("%sRoomList0x%06X", zRoom->GetName().c_str(), segmentOffset), 0,
|
||||
declaration);
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
std::string SetRoomList::Save()
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
RoomEntry::RoomEntry(int32_t nVAS, int32_t nVAE)
|
||||
RoomEntry::RoomEntry(uint32_t nVAS, uint32_t nVAE)
|
||||
{
|
||||
virtualAddressStart = nVAS;
|
||||
virtualAddressEnd = nVAE;
|
||||
}
|
||||
|
||||
RoomEntry::RoomEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
RoomEntry::RoomEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: RoomEntry(BitConverter::ToInt32BE(rawData, rawDataIndex + 0),
|
||||
BitConverter::ToInt32BE(rawData, rawDataIndex + 4))
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class RoomEntry
|
||||
{
|
||||
public:
|
||||
RoomEntry(uint32_t nVAS, uint32_t nVAE);
|
||||
RoomEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
protected:
|
||||
int32_t virtualAddressStart;
|
||||
int32_t virtualAddressEnd;
|
||||
|
||||
RoomEntry(int32_t nVAS, int32_t nVAE);
|
||||
RoomEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class SetRoomList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetRoomList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
~SetRoomList();
|
||||
SetRoomList(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual std::string GenerateExterns() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
virtual std::string PreGenSourceFiles() override;
|
||||
virtual std::string Save() override;
|
||||
void ParseRawData() override;
|
||||
virtual void DeclareReferences(const std::string& prefix);
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
void PreGenSourceFiles() override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<RoomEntry*> rooms;
|
||||
uint32_t segmentOffset;
|
||||
};
|
||||
std::vector<RoomEntry> rooms;
|
||||
};
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
#include "SetSkyboxModifier.h"
|
||||
#include "../../StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
#include "StringHelper.h"
|
||||
|
||||
SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetSkyboxModifier::SetSkyboxModifier(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
disableSky = rawData[rawDataIndex + 0x04];
|
||||
disableSunMoon = rawData[rawDataIndex + 0x05];
|
||||
}
|
||||
|
||||
string SetSkyboxModifier::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetSkyboxModifier::ParseRawData()
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0, 0, 0, 0x%02X, 0x%02X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), disableSky,
|
||||
disableSunMoon);
|
||||
;
|
||||
ZRoomCommand::ParseRawData();
|
||||
disableSky = parent->GetRawData().at(rawDataIndex + 0x04);
|
||||
disableSunMoon = parent->GetRawData().at(rawDataIndex + 0x05);
|
||||
}
|
||||
|
||||
string SetSkyboxModifier::GetCommandCName()
|
||||
std::string SetSkyboxModifier::GetBodySourceCode() const
|
||||
{
|
||||
std::string sky = StringHelper::BoolStr(disableSky);
|
||||
std::string soonMoon = StringHelper::BoolStr(disableSunMoon);
|
||||
return StringHelper::Sprintf("SCENE_CMD_SKYBOX_DISABLES(%s, %s)", sky.c_str(),
|
||||
soonMoon.c_str());
|
||||
}
|
||||
|
||||
std::string SetSkyboxModifier::GetCommandCName() const
|
||||
{
|
||||
return "SCmdSkyboxDisables";
|
||||
}
|
||||
|
||||
RoomCommand SetSkyboxModifier::GetRoomCommand()
|
||||
RoomCommand SetSkyboxModifier::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetSkyboxModifier;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetSkyboxModifier : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetSkyboxModifier(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetSkyboxModifier(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
|
||||
private:
|
||||
uint8_t disableSky;
|
||||
uint8_t disableSunMoon;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,32 +1,36 @@
|
||||
#include "SetSkyboxSettings.h"
|
||||
#include "../../Globals.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetSkyboxSettings::SetSkyboxSettings(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
unk1 = rawData[rawDataIndex + 0x01];
|
||||
skyboxNumber = rawData[rawDataIndex + 0x04];
|
||||
cloudsType = rawData[rawDataIndex + 0x05];
|
||||
lightingSettingsControl = rawData[rawDataIndex + 0x06];
|
||||
}
|
||||
|
||||
string SetSkyboxSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetSkyboxSettings::ParseRawData()
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0x%02X, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), unk1, skyboxNumber,
|
||||
cloudsType, lightingSettingsControl);
|
||||
ZRoomCommand::ParseRawData();
|
||||
unk1 = cmdArg1;
|
||||
skyboxNumber = parent->GetRawData().at(rawDataIndex + 0x04);
|
||||
cloudsType = parent->GetRawData().at(rawDataIndex + 0x05);
|
||||
isIndoors = parent->GetRawData().at(rawDataIndex + 0x06);
|
||||
}
|
||||
|
||||
string SetSkyboxSettings::GetCommandCName()
|
||||
std::string SetSkyboxSettings::GetBodySourceCode() const
|
||||
{
|
||||
std::string indoors = StringHelper::BoolStr(isIndoors);
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
return StringHelper::Sprintf("SCENE_CMD_SKYBOX_SETTINGS(0x%02X, %i, %i, %s)", unk1,
|
||||
skyboxNumber, cloudsType, indoors.c_str());
|
||||
return StringHelper::Sprintf("SCENE_CMD_SKYBOX_SETTINGS(%i, %i, %s)", skyboxNumber, cloudsType,
|
||||
indoors.c_str());
|
||||
}
|
||||
|
||||
std::string SetSkyboxSettings::GetCommandCName() const
|
||||
{
|
||||
return "SCmdSkyboxSettings";
|
||||
}
|
||||
|
||||
RoomCommand SetSkyboxSettings::GetRoomCommand()
|
||||
RoomCommand SetSkyboxSettings::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetSkyboxSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetSkyboxSettings : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetSkyboxSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetSkyboxSettings(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
|
||||
private:
|
||||
uint8_t unk1; // (MM Only)
|
||||
uint8_t skyboxNumber;
|
||||
uint8_t cloudsType;
|
||||
uint8_t lightingSettingsControl;
|
||||
};
|
||||
uint8_t isIndoors;
|
||||
};
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
#include "SetSoundSettings.h"
|
||||
#include "../../StringHelper.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
|
||||
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
|
||||
SetSoundSettings::SetSoundSettings(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
reverb = rawData[rawDataIndex + 0x01];
|
||||
nightTimeSFX = rawData[rawDataIndex + 0x06];
|
||||
musicSequence = rawData[rawDataIndex + 0x07];
|
||||
}
|
||||
|
||||
string SetSoundSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
|
||||
void SetSoundSettings::ParseRawData()
|
||||
{
|
||||
return StringHelper::Sprintf(
|
||||
"%s 0x%02X, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X",
|
||||
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), reverb, nightTimeSFX,
|
||||
musicSequence);
|
||||
ZRoomCommand::ParseRawData();
|
||||
reverb = cmdArg1;
|
||||
nightTimeSFX = parent->GetRawData().at(rawDataIndex + 0x06);
|
||||
musicSequence = parent->GetRawData().at(rawDataIndex + 0x07);
|
||||
}
|
||||
|
||||
string SetSoundSettings::GetCommandCName()
|
||||
std::string SetSoundSettings::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("SCENE_CMD_SOUND_SETTINGS(%i, %i, %i)", reverb, nightTimeSFX,
|
||||
musicSequence);
|
||||
}
|
||||
|
||||
std::string SetSoundSettings::GetCommandCName() const
|
||||
{
|
||||
return "SCmdSoundSettings";
|
||||
}
|
||||
|
||||
RoomCommand SetSoundSettings::GetRoomCommand()
|
||||
RoomCommand SetSoundSettings::GetRoomCommand() const
|
||||
{
|
||||
return RoomCommand::SetSoundSettings;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ZRoomCommand.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class SetSoundSettings : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
SetSoundSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
|
||||
SetSoundSettings(ZFile* nParent);
|
||||
|
||||
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
|
||||
virtual std::string GetCommandCName() override;
|
||||
virtual RoomCommand GetRoomCommand() override;
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
uint8_t reverb;
|
||||
uint8_t nightTimeSFX;
|
||||
uint8_t musicSequence;
|
||||
};
|
||||
};
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user