Convert every submodule into subrepo (#170)

* remove ZAPD submodule

* git subrepo clone https://github.com/zeldaret/ZAPD.git tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "ca229f19"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "ca229f19"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* git subrepo clone https://github.com/simonlindholm/decomp-permuter.git tools/decomp-permuter

subrepo:
  subdir:   "tools/decomp-permuter"
  merged:   "1e4b85a7"
upstream:
  origin:   "https://github.com/simonlindholm/decomp-permuter.git"
  branch:   "main"
  commit:   "1e4b85a7"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* Remove asm-differ

* git subrepo clone https://github.com/simonlindholm/asm-differ.git tools/asm-differ

subrepo:
  subdir:   "tools/asm-differ"
  merged:   "eaf72269"
upstream:
  origin:   "https://github.com/simonlindholm/asm-differ.git"
  branch:   "master"
  commit:   "eaf72269"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* remove asm-processor

* git subrepo clone https://github.com/simonlindholm/asm-processor.git tools/asm-processor

subrepo:
  subdir:   "tools/asm-processor"
  merged:   "85288fcd"
upstream:
  origin:   "https://github.com/simonlindholm/asm-processor.git"
  branch:   "master"
  commit:   "85288fcd"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"

* remove .gitmodules file

* Update REAMDE

* Update warnings
This commit is contained in:
Anghelo Carvajal
2021-06-07 18:31:56 -04:00
committed by GitHub
parent 2bf68a5263
commit b6904aa2cc
418 changed files with 113047 additions and 62 deletions
-13
View File
@@ -1,13 +0,0 @@
[submodule "tools/asm-processor"]
path = tools/asm-processor
url = https://github.com/simonlindholm/asm-processor.git
[submodule "tools/asm-differ"]
path = tools/asm-differ
url = https://github.com/simonlindholm/asm-differ.git
[submodule "tools/decomp-permuter"]
path = tools/decomp-permuter
url = https://github.com/simonlindholm/decomp-permuter
branch = main
[submodule "ZAPD"]
path = tools/ZAPD
url = https://github.com/zeldaret/ZAPD.git
-5
View File
@@ -215,11 +215,6 @@ distclean: assetclean clean
## Extraction step
setup:
# Initialize submodules, fetching commit in case it is not on the default branch
-git submodule update --init --recursive
git submodule foreach --recursive 'git fetch origin $$sha1'
git submodule update --recursive
python3 -m pip install -r requirements.txt
$(MAKE) -C tools
./tools/extract_rom.py $(MM_BASEROM)
python3 extract_assets.py
+8 -1
View File
@@ -56,12 +56,19 @@ The build process has the following package requirements:
* binutils-mips-linux-gnu
* python3
* pip3
* libpng-dev
Under Debian / Ubuntu (which we recommend using), you can install them with the following commands:
```bash
sudo apt update
sudo apt install make git build-essential binutils-mips-linux-gnu python3 python3-pip
sudo apt install make git build-essential binutils-mips-linux-gnu python3 python3-pip libpng-dev
```
To install the Python dependencies simply run in a terminal:
```bash
python3 -m pip install -r requirements.txt
```
#### 2. Fork the repository
Submodule tools/ZAPD deleted from ca229f19b9
+84
View File
@@ -0,0 +1,84 @@
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 100
CommentPragmas: '^ (IWYU pragma:|NOLINT)'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ ]
IncludeCategories:
- Regex: '^<[Ww]indows\.h>$'
Priority: 1
- Regex: '^<'
Priority: 2
- Regex: '^"'
Priority: 3
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 4
UseTab: AlignWithSpaces
...
+337
View File
@@ -0,0 +1,337 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
*.out
*.o
*.d
lib/libgfxd/libgfxd.a
.vscode/
ZAPD/BuildInfo.h
+12
View File
@@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
;
[subrepo]
remote = https://github.com/zeldaret/ZAPD.git
branch = master
commit = ca229f19b991c613c29afade3d70b100522cece1
parent = 6ab539cda1870420d07e38e25db09208fd7b21a8
method = merge
cmdver = 0.4.3
+47
View File
@@ -0,0 +1,47 @@
pipeline {
agent {
label "ZAPD"
}
stages {
stage('Build ZAPD') {
steps {
sh 'make -j'
}
}
stage('Checkout oot') {
steps {
dir('oot') {
git url: 'https://github.com/zeldaret/oot.git'
}
}
}
stage('Set up oot') {
steps {
dir('oot') {
sh 'cp /usr/local/etc/roms/baserom_oot.z64 baserom_original.z64'
// Identical to `make setup` except for copying our newer ZAPD.out into oot
sh 'git submodule update --init --recursive'
sh 'make -C tools'
sh 'cp ../ZAPD.out tools/ZAPD/'
sh 'python3 fixbaserom.py'
sh 'python3 extract_baserom.py'
sh 'python3 extract_assets.py'
}
}
}
stage('Build oot') {
steps {
dir('oot') {
sh 'make -j'
}
}
}
}
post {
always {
cleanWs()
}
}
}
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Zelda Reverse Engineering Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+78
View File
@@ -0,0 +1,78 @@
OPTIMIZATION_ON ?= 1
ASAN ?= 0
DEPRECATION_OFF ?= 0
DEBUG ?= 0
CFLAGS ?=
COPYCHECK_ARGS ?=
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 += -fpic -std=c++17 -rdynamic -Wall -fno-omit-frame-pointer
ifneq ($(DEBUG),0)
OPTIMIZATION_ON = 0
DEPRECATION_OFF = 1
CFLAGS += -g3 -DDEVELOPMENT
COPYCHECK_ARGS += --devel
endif
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 -lpng
UNAME := $(shell uname)
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_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
genbuildinfo:
python3 ZAPD/genbuildinfo.py $(COPYCHECK_ARGS)
copycheck: ZAPD.out
python3 copycheck.py
clean:
rm -f $(O_FILES) ZAPD.out
$(MAKE) -C lib/libgfxd 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)
ZAPD/Main.o: genbuildinfo ZAPD/Main.cpp
$(CC) $(CFLAGS) $(INC) -c ZAPD/Main.cpp -o $@ $(LDFLAGS)
lib/libgfxd/libgfxd.a:
$(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)
+109
View File
@@ -0,0 +1,109 @@
# 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` 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`.
- `DEBUG`: If non-zero, ZAPD will be compiled in _development mode_. This implies the following:
- Debugging symbols enabled (`-g3`). They are disabled by default.
- `OPTIMIZATION_ON=0`: Disables optimizations (`-O0`).
- `DEPRECATION_OFF=1`: Disables deprecation warnings.
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`.
Additionally, you can pass the flag `--version` to see the current ZAPD version. If that flag is passed, ZAPD will ignore any other parameter passed.
+46
View File
@@ -0,0 +1,46 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPD", "ZAPD\ZAPD.vcxproj", "{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
MinSizeRel|x64 = MinSizeRel|x64
MinSizeRel|x86 = MinSizeRel|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
RelWithDebInfo|x64 = RelWithDebInfo|x64
RelWithDebInfo|x86 = RelWithDebInfo|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.ActiveCfg = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x64.Build.0 = Debug|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.ActiveCfg = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Debug|x86.Build.0 = Debug|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.MinSizeRel|x64.ActiveCfg = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.MinSizeRel|x64.Build.0 = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.MinSizeRel|x86.ActiveCfg = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.MinSizeRel|x86.Build.0 = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.ActiveCfg = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x64.Build.0 = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.ActiveCfg = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.Release|x86.Build.0 = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x64.Build.0 = Release|x64
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C2E1CC72-7A50-3249-AFD5-DFF6FE25CDCA}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
+159
View File
@@ -0,0 +1,159 @@
#pragma once
#include <limits>
#include <stdint.h>
#include <vector>
class BitConverter
{
public:
static inline int8_t ToInt8BE(const uint8_t* data, int32_t offset)
{
return (uint8_t)data[offset + 0];
}
static inline int8_t ToInt8BE(const std::vector<uint8_t>& data, int32_t offset)
{
return (uint8_t)data[offset + 0];
}
static inline uint8_t ToUInt8BE(const uint8_t* data, int32_t offset)
{
return (uint8_t)data[offset + 0];
}
static inline uint8_t ToUInt8BE(const std::vector<uint8_t>& data, int32_t offset)
{
return (uint8_t)data[offset + 0];
}
static inline int16_t ToInt16BE(const uint8_t* data, int32_t offset)
{
return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1];
}
static inline int16_t ToInt16BE(const std::vector<uint8_t>& data, int32_t offset)
{
return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1];
}
static inline uint16_t ToUInt16BE(const uint8_t* data, int32_t offset)
{
return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1];
}
static inline uint16_t ToUInt16BE(const std::vector<uint8_t>& data, int32_t offset)
{
return ((uint16_t)data[offset + 0] << 8) + (uint16_t)data[offset + 1];
}
static inline int32_t ToInt32BE(const uint8_t* data, int32_t offset)
{
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
}
static inline int32_t ToInt32BE(const std::vector<uint8_t>& data, int32_t offset)
{
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
}
static inline uint32_t ToUInt32BE(const uint8_t* data, int32_t offset)
{
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
}
static inline uint32_t ToUInt32BE(const std::vector<uint8_t>& data, int32_t offset)
{
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
}
static inline int64_t ToInt64BE(const uint8_t* data, int32_t offset)
{
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
}
static inline int64_t ToInt64BE(const std::vector<uint8_t>& data, int32_t offset)
{
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
}
static inline uint64_t ToUInt64BE(const uint8_t* data, int32_t offset)
{
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
}
static inline uint64_t ToUInt64BE(const std::vector<uint8_t>& data, int32_t offset)
{
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
}
static inline float ToFloatBE(const uint8_t* data, int32_t offset)
{
float value;
uint32_t floatData = ((uint32_t)data[offset + 0] << 24) +
((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
static_assert(sizeof(uint32_t) == sizeof(float));
std::memcpy(&value, &floatData, sizeof(value));
return value;
}
static inline float ToFloatBE(const std::vector<uint8_t>& data, int32_t offset)
{
float value;
uint32_t floatData = ((uint32_t)data[offset + 0] << 24) +
((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
static_assert(sizeof(uint32_t) == sizeof(float));
std::memcpy(&value, &floatData, sizeof(value));
return value;
}
static inline double ToDoubleBE(const uint8_t* data, int32_t offset)
{
double value;
uint64_t floatData =
((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
static_assert(sizeof(uint64_t) == sizeof(double));
// Checks if the float format on the platform the ZAPD binary is running on supports the
// same float format as the object file.
static_assert(std::numeric_limits<float>::is_iec559);
std::memcpy(&value, &floatData, sizeof(value));
return value;
}
static inline double ToDoubleBE(const std::vector<uint8_t>& data, int32_t offset)
{
double value;
uint64_t floatData =
((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
static_assert(sizeof(uint64_t) == sizeof(double));
// Checks if the float format on the platform the ZAPD binary is running on supports the
// same float format as the object file.
static_assert(std::numeric_limits<double>::is_iec559);
std::memcpy(&value, &floatData, sizeof(value));
return value;
}
};
+23
View File
@@ -0,0 +1,23 @@
#pragma once
static uint32_t CRC32B(unsigned char* message, int32_t size)
{
int32_t byte, crc;
int32_t mask;
crc = 0xFFFFFFFF;
for (int32_t i = 0; i < size; i++)
{
byte = message[i];
crc = crc ^ byte;
for (int32_t j = 7; j >= 0; j--)
{
mask = -(crc & 1);
crc = (crc >> 1) ^ (0xEDB88320 & mask);
}
}
return ~(uint32_t)(crc);
}
+79
View File
@@ -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;
}
+65
View File
@@ -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);
};
+39
View File
@@ -0,0 +1,39 @@
#pragma once
#include <iostream>
#include <string>
#include <vector>
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif
#include "StringHelper.h"
class Directory
{
public:
static std::string GetCurrentDirectory() { return fs::current_path().u8string(); }
static bool Exists(const std::string& path) { return fs::exists(fs::path(path)); }
static void CreateDirectory(const std::string& path)
{
std::string curPath = "";
std::vector<std::string> split = StringHelper::Split(path, "/");
for (std::string s : split)
{
curPath += s + "/";
if (!Exists(curPath))
fs::create_directory(curPath);
}
// fs::create_directory(path);
}
};
+65
View File
@@ -0,0 +1,65 @@
#pragma once
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include "StringHelper.h"
class File
{
public:
static bool Exists(const std::string& filePath)
{
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
return file.good();
}
static std::vector<uint8_t> ReadAllBytes(const std::string& filePath)
{
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
int32_t fileSize = (int32_t)file.tellg();
file.seekg(0);
char* data = new char[fileSize];
file.read(data, fileSize);
std::vector<uint8_t> result = std::vector<uint8_t>(data, data + fileSize);
delete[] data;
return result;
};
static std::string ReadAllText(const std::string& filePath)
{
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
int32_t fileSize = (int32_t)file.tellg();
file.seekg(0);
char* data = new char[fileSize + 1];
memset(data, 0, fileSize + 1);
file.read(data, fileSize);
std::string str = std::string((const char*)data);
delete[] data;
return str;
};
static std::vector<std::string> ReadAllLines(const std::string& filePath)
{
std::string text = ReadAllText(filePath);
std::vector<std::string> lines = StringHelper::Split(text, "\n");
return lines;
};
static void WriteAllBytes(const std::string& filePath, const std::vector<uint8_t>& data)
{
std::ofstream file(filePath, std::ios::binary);
file.write((char*)data.data(), data.size());
};
static void WriteAllText(const std::string& filePath, const std::string& text)
{
std::ofstream file(filePath, std::ios::out);
file.write(text.c_str(), text.size());
}
};
+186
View File
@@ -0,0 +1,186 @@
#include "Globals.h"
#include <algorithm>
#include "File.h"
#include "Path.h"
#include "tinyxml2.h"
using namespace tinyxml2;
Globals* Globals::Instance;
Globals::Globals()
{
Instance = this;
files = std::vector<ZFile*>();
segments = std::vector<int32_t>();
symbolMap = std::map<uint32_t, std::string>();
segmentRefs = std::map<int32_t, std::string>();
segmentRefFiles = std::map<int32_t, ZFile*>();
game = ZGame::OOT_RETAIL;
genSourceFile = true;
testMode = false;
profile = false;
useLegacyZDList = false;
useExternalResources = true;
lastScene = nullptr;
verbosity = VerbosityLevel::VERBOSITY_SILENT;
}
std::string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
{
if (segmentRefs.find(segNumber) != segmentRefs.end())
{
if (segmentRefFiles.find(segNumber) == segmentRefFiles.end())
{
XMLDocument doc;
std::string filePath = segmentRefs[segNumber];
XMLError eResult = doc.LoadFile(filePath.c_str());
if (eResult != tinyxml2::XML_SUCCESS)
return "ERROR";
XMLNode* root = doc.FirstChild();
if (root == nullptr)
return "ERROR";
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (std::string(child->Name()) == "File")
{
ZFile* file = new ZFile(fileMode, child, "", "", "", filePath, true);
file->GeneratePlaceholderDeclarations();
segmentRefFiles[segNumber] = file;
break;
}
}
}
return segmentRefFiles[segNumber]->GetDeclarationName(symbolAddress, "ERROR");
}
return "ERROR";
}
void Globals::ReadConfigFile(const std::string& configFilePath)
{
XMLDocument doc;
XMLError eResult = doc.LoadFile(configFilePath.c_str());
if (eResult != tinyxml2::XML_SUCCESS)
{
throw std::runtime_error("Error: Unable to read config file.");
return;
}
XMLNode* root = doc.FirstChild();
if (root == nullptr)
return;
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (std::string(child->Name()) == "SymbolMap")
{
std::string fileName = std::string(child->Attribute("File"));
GenSymbolMap(Path::GetDirectoryName(configFilePath) + "/" + fileName);
}
else if (std::string(child->Name()) == "Segment")
{
std::string fileName = std::string(child->Attribute("File"));
int32_t segNumber = child->IntAttribute("Number");
segmentRefs[segNumber] = fileName;
}
else if (std::string(child->Name()) == "ActorList")
{
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 (std::string(child->Name()) == "ObjectList")
{
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 (std::string(child->Name()) == "TexturePool")
{
std::string fileName = std::string(child->Attribute("File"));
ReadTexturePool(Path::GetDirectoryName(configFilePath) + "/" + fileName);
}
else if (std::string(child->Name()) == "BGConfig")
{
cfg.bgScreenWidth = child->IntAttribute("ScreenWidth", 320);
cfg.bgScreenHeight = child->IntAttribute("ScreenHeight", 240);
}
}
}
void Globals::ReadTexturePool(const std::string& texturePoolXmlPath)
{
XMLDocument doc;
XMLError eResult = doc.LoadFile(texturePoolXmlPath.c_str());
if (eResult != tinyxml2::XML_SUCCESS)
{
fprintf(stderr, "Warning: Unable to read texture pool XML with error code %i\n", eResult);
return;
}
XMLNode* root = doc.FirstChild();
if (root == nullptr)
return;
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (std::string(child->Name()) == "Texture")
{
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);
cfg.texturePool[crc].path = texPath;
}
}
}
void Globals::GenSymbolMap(const std::string& symbolMapPath)
{
auto symbolLines = File::ReadAllLines(symbolMapPath);
for (std::string symbolLine : symbolLines)
{
auto split = StringHelper::Split(symbolLine, " ");
uint32_t addr = strtoul(split[0].c_str(), NULL, 16);
std::string symbolName = split[1];
symbolMap[addr] = symbolName;
}
}
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)
{
return std::find(segments.begin(), segments.end(), segment) != segments.end();
}
+87
View File
@@ -0,0 +1,87 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
#include "ZTexture.h"
enum class VerbosityLevel
{
VERBOSITY_SILENT,
VERBOSITY_INFO,
VERBOSITY_DEBUG
};
struct TexturePoolEntry
{
fs::path path = ""; // Path to Shared Texture
};
class GameConfig
{
public:
std::map<int32_t, std::string> segmentRefs;
std::map<int32_t, ZFile*> segmentRefFiles;
std::map<uint32_t, std::string> symbolMap;
std::vector<std::string> actorList;
std::vector<std::string> objectList;
std::map<uint32_t, TexturePoolEntry> texturePool; // Key = CRC
// ZBackground
uint32_t bgScreenWidth = 320, bgScreenHeight = 240;
GameConfig() = default;
};
class Globals
{
public:
static Globals* Instance;
bool genSourceFile; // Used for extraction
bool useExternalResources;
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;
fs::path baseRomPath, inputPath, outputPath, sourceOutputPath, cfgPath;
TextureType texType;
ZGame game;
GameConfig cfg;
bool warnUnaccounted = false;
std::vector<ZFile*> files;
std::vector<int32_t> segments;
std::map<int32_t, std::string> segmentRefs;
std::map<int32_t, ZFile*> segmentRefFiles;
ZRoom* lastScene;
std::map<uint32_t, std::string> symbolMap;
Globals();
std::string FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress);
void ReadConfigFile(const std::string& configFilePath);
void ReadTexturePool(const std::string& texturePoolXmlPath);
void GenSymbolMap(const std::string& symbolMapPath);
void AddSegment(int32_t segment, ZFile* file);
bool HasSegment(int32_t segment);
};
/*
* Note: In being able to track references across files, there are a few major files that make use
* of segments...
* Segment 1: nintendo_rogo_static/title_static
* Segment 2: parameter_static
* Segment 4: gameplay_keep
* Segment 5: gameplay_field_keep, gameplay_dangeon_keep
* Segment 7: link_animetion
* Segment 8: icon_item_static
* Segment 9: icon_item_24_static
* Segment 12: icon_item_field_static, icon_item_dungeon_static
* Segment 13: icon_item_nes_static
*
* I'm thinking a config file could be usable, but I'll have to experiment...
*/
+12
View File
@@ -0,0 +1,12 @@
#pragma once
#include <stdint.h>
/*
* The high level format for animations.
*/
class HLAnimation
{
public:
};
@@ -0,0 +1,110 @@
#include "HLAnimationIntermediette.h"
using namespace tinyxml2;
HLAnimationIntermediette::HLAnimationIntermediette()
{
limit = 0;
limbCount = 0;
frameCount = 0;
rotationValues = std::vector<uint16_t>();
rotationIndices = std::vector<RotationIndex>();
}
HLAnimationIntermediette::~HLAnimationIntermediette()
{
}
HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath)
{
HLAnimationIntermediette* anim = new HLAnimationIntermediette();
XMLDocument doc;
doc.LoadFile(xmlPath.c_str());
XMLElement* root = doc.RootElement();
anim->limit = root->IntAttribute("Limit");
anim->limbCount = root->IntAttribute("LimbCount");
anim->frameCount = root->IntAttribute("FrameCount");
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (std::string(child->Name()) == "RotationValues")
{
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
child2 = child2->NextSiblingElement())
{
std::string value = child2->GetText();
anim->rotationValues.push_back(atoi(value.c_str()));
}
}
else if (std::string(child->Name()) == "RotationIndices")
{
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
child2 = child2->NextSiblingElement())
anim->rotationIndices.push_back(RotationIndex(child2->IntAttribute("X"),
child2->IntAttribute("Y"),
child2->IntAttribute("Z")));
}
}
return anim;
}
HLAnimationIntermediette* HLAnimationIntermediette::FromZAnimation(ZAnimation* zAnim)
{
HLAnimationIntermediette* anim = new HLAnimationIntermediette();
return anim;
}
ZAnimation* HLAnimationIntermediette::ToZAnimation()
{
ZAnimation* zAnim = new ZNormalAnimation(nullptr);
return zAnim;
}
std::string HLAnimationIntermediette::OutputXML()
{
std::string output = "";
XMLDocument doc;
XMLElement* root = doc.NewElement("HLAnimationIntermediette");
root->SetAttribute("Limit", limit);
root->SetAttribute("LimbCount", limbCount);
root->SetAttribute("FrameCount", frameCount);
doc.InsertFirstChild(root);
XMLElement* rotValues = doc.NewElement("RotationValues");
for (size_t i = 0; i < rotationValues.size(); i++)
{
XMLElement* rotValue = doc.NewElement("Value");
rotValue->SetText(rotationValues[i]);
rotValues->InsertEndChild(rotValue);
}
root->InsertEndChild(rotValues);
XMLElement* rotIndices = doc.NewElement("RotationIndices");
for (size_t i = 0; i < rotationIndices.size(); i++)
{
XMLElement* rotIndex = doc.NewElement("Value");
rotIndex->SetAttribute("X", rotationIndices[i].x);
rotIndex->SetAttribute("Y", rotationIndices[i].y);
rotIndex->SetAttribute("Z", rotationIndices[i].z);
rotIndices->InsertEndChild(rotIndex);
}
root->InsertEndChild(rotIndices);
XMLPrinter printer;
doc.Accept(&printer);
return printer.CStr();
}
@@ -0,0 +1,32 @@
#pragma once
#include <stdint.h>
#include "../ZAnimation.h"
#include "HLFileIntermediette.h"
#include "tinyxml2.h"
/*
* An intermediette format for animations. Going to use XML.
* Goes from FBX->XML->C
* Note: At the moment this is a very direct representation of the output format.
* Optimally we can determine where the keyframes are and remove redundant information.
*/
class HLAnimationIntermediette
{
public:
int16_t frameCount;
int16_t limit;
int16_t limbCount;
std::vector<uint16_t> rotationValues;
std::vector<RotationIndex> rotationIndices;
HLAnimationIntermediette();
~HLAnimationIntermediette();
std::string OutputXML();
ZAnimation* ToZAnimation();
static HLAnimationIntermediette* FromXML(std::string xmlPath);
static HLAnimationIntermediette* FromZAnimation(ZAnimation* zAnim);
};
@@ -0,0 +1,5 @@
#pragma once
class HLFileIntermediette
{
};
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,312 @@
#pragma once
#include <Vec3s.h>
#include <assimp/scene.h>
#include <stdint.h>
#include <string>
#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.
*/
class HLModelIntermediette;
class HLIntermediette
{
public:
std::string name;
HLModelIntermediette* parent;
HLIntermediette();
~HLIntermediette();
virtual std::string OutputCode();
virtual std::string OutputOBJ();
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
};
class HLModelObj
{
public:
Vec3s pos;
Vec3s rot;
std::vector<aiVector3D> vertices;
std::vector<int32_t> indices;
HLModelObj() = default;
HLModelObj(Vec3s nPos, Vec3s nRot, std::vector<aiVector3D> nVerts,
std::vector<int32_t> nIndices);
};
class HLModelIntermediette : public HLFileIntermediette
{
public:
std::vector<HLIntermediette*> blocks;
std::vector<Vec3s> meshTranslations;
std::vector<HLModelObj*> objects;
Vec3s lastTrans;
bool hasSkeleton;
bool startsWithPipeSync;
bool startsWithClearGeometryMode;
bool lerpBeforeTextureBlock;
uint32_t startIndex;
uint32_t meshStartIndex;
HLModelIntermediette();
~HLModelIntermediette();
static HLModelIntermediette* FromXML(tinyxml2::XMLElement* root);
static void FromZDisplayList(HLModelIntermediette* model, ZDisplayList* zDisplayList);
static void FromZSkeleton(HLModelIntermediette* model, ZSkeleton* zSkeleton);
static void ProcessZSkeletonLimb(HLModelIntermediette* model, ZSkeleton* zSkeleton,
ZLimb* limb);
std::string ToOBJFile();
std::string ToAssimpFile();
std::string OutputCode();
std::string OutputXML();
template <typename T>
T* FindByName(std::string name);
template <typename T>
T* FindByType();
};
class HLTextureIntermediette : public HLIntermediette
{
public:
ZTexture* tex;
std::string fileName;
HLTextureIntermediette();
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode();
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
};
class HLSetTranslation : public HLIntermediette
{
public:
float transX, transY, transZ;
HLSetTranslation();
HLSetTranslation(float nTransX, float nTransY, float nTransZ);
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
};
class HLTerminator : public HLIntermediette
{
public:
HLTerminator();
~HLTerminator();
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
};
enum class HLMaterialCmt
{
Wrap,
Mirror,
Clamp
};
class HLMaterialIntermediette : public HLIntermediette
{
public:
std::string textureName;
// int32_t repeatH, repeatV;
uint8_t clrR, clrG, clrB, clrA, clrM, clrL;
// bool clampH, clampV;
// bool mirrorH, mirrorV;
HLMaterialCmt cmtH, cmtV;
// TODO: Remember to add lerp params here...
HLMaterialIntermediette();
virtual std::string OutputCode();
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* parent);
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
};
class HLMeshCommand
{
public:
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode(HLModelIntermediette* parent);
virtual std::string OutputOBJ(HLModelIntermediette* parent);
virtual void OutputAssimp(HLModelIntermediette* parent, aiScene* scene, aiMesh* mesh);
virtual void OutputXML(tinyxml2::XMLElement* parent);
};
class HLVerticesIntermediette : public HLIntermediette
{
public:
std::vector<ZVtx> vertices;
HLVerticesIntermediette();
virtual void InitFromXML(tinyxml2::XMLElement* verticesElement);
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);
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
};
class HLMeshCmdTriangle1 : public HLMeshCommand
{
public:
int32_t v0, v1, v2, flag;
HLMeshCmdTriangle1();
HLMeshCmdTriangle1(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag);
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode(HLModelIntermediette* parent);
virtual void OutputAssimp(HLModelIntermediette* parent, aiScene* scene, aiMesh* mesh);
virtual void OutputXML(tinyxml2::XMLElement* parent);
};
class HLMeshCmdTriangle2 : public HLMeshCommand
{
public:
int32_t v0, v1, v2, flag0, v10, v11, v12, flag1;
HLMeshCmdTriangle2();
HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0, int32_t nV10,
int32_t nV11, int32_t nV12, int32_t nFlag1);
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode(HLModelIntermediette* parent);
virtual std::string OutputOBJ(HLModelIntermediette* parent);
virtual void OutputAssimp(HLModelIntermediette* parent, aiScene* scene, aiMesh* mesh);
virtual void OutputXML(tinyxml2::XMLElement* parent);
};
class HLMeshCmdLoadVertices : public HLMeshCommand
{
public:
uint8_t numVerts;
uint8_t startIndex;
HLMeshCmdLoadVertices();
HLMeshCmdLoadVertices(uint8_t nNumVerts, uint8_t nStartIndex);
virtual void OutputXML(tinyxml2::XMLElement* parent);
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputOBJ(HLModelIntermediette* parent);
virtual void OutputAssimp(HLModelIntermediette* parent, aiScene* scene, aiMesh* mesh);
virtual std::string OutputCode(HLModelIntermediette* parent);
};
class HLMeshCmdCull : public HLMeshCommand
{
public:
uint8_t indexStart;
uint8_t indexEnd;
HLMeshCmdCull();
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode(HLModelIntermediette* parent);
};
class HLMeshCmdGeoSettings : public HLMeshCommand
{
public:
std::string on, off;
HLMeshCmdGeoSettings();
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode(HLModelIntermediette* parent);
};
class HLMeshIntermediette : public HLIntermediette
{
public:
std::vector<HLMeshCommand*> commands;
HLMeshIntermediette();
void InitFromXML(tinyxml2::XMLElement* xmlElement);
std::string OutputCode(std::string materialName);
virtual std::string OutputOBJ();
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
};
class HLDisplayListCommand
{
public:
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode();
};
class HLDisplayListCmdDrawMesh : public HLDisplayListCommand
{
public:
std::string meshName, materialName;
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode();
};
class HLDisplayListCmdPipeSync : public HLDisplayListCommand
{
public:
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode();
};
class HLDisplayListIntermediette : public HLIntermediette
{
public:
std::vector<HLDisplayListCommand*> commands;
uint32_t address;
HLDisplayListIntermediette();
virtual std::string OutputCode();
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
};
class HLLimbCommand
{
public:
std::string meshName, materialName;
HLLimbCommand();
HLLimbCommand(std::string nMeshName, std::string nMaterialName);
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual void OutputXML(tinyxml2::XMLElement* parent);
virtual std::string OutputCode(HLModelIntermediette* parent);
};
class HLLimbIntermediette : public HLIntermediette
{
public:
std::vector<HLLimbCommand*> commands;
HLLimbIntermediette();
void InitFromXML(tinyxml2::XMLElement* xmlElement);
std::string OutputCode();
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
};
+13
View File
@@ -0,0 +1,13 @@
#include "HLTexture.h"
#include "../StringHelper.h"
HLTexture* HLTexture::FromPNG(std::string pngFilePath, HLTextureType texType)
{
// 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);
return tex;
}
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include <stdint.h>
#include <string>
#include <vector>
// TODO: This was duplicated from ZTexture. It's probably going to be modified to differentiate from
// ZTexture but if not, we're going to need to have the two share an enum.
enum class HLTextureType
{
RGBA32bpp,
RGBA16bpp,
Palette4bpp,
Palette8bpp,
Grayscale4bpp,
Grayscale8bpp,
GrayscaleAlpha4bpp,
GrayscaleAlpha8bpp,
GrayscaleAlpha16bpp,
Error
};
class HLTexture
{
public:
static HLTexture* FromPNG(std::string pngFilePath, HLTextureType texType);
HLTextureType type;
uint32_t width, height;
uint8_t* bmpRgba;
};
+473
View File
@@ -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;
}
+71
View File
@@ -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();
};
+417
View File
@@ -0,0 +1,417 @@
#include "BuildInfo.h"
#include "Directory.h"
#include "File.h"
#include "Globals.h"
#include "HighLevel/HLAnimationIntermediette.h"
#include "HighLevel/HLModelIntermediette.h"
#include "Overlays/ZOverlay.h"
#include "Path.h"
#include "ZAnimation.h"
#include "ZBackground.h"
#include "ZBlob.h"
#include "ZFile.h"
#include "ZTexture.h"
#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
#include <string>
#include "tinyxml2.h"
using namespace tinyxml2;
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
ZFileMode fileMode);
void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath);
void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath);
void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath);
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];
const size_t nMaxFrames = sizeof(array) / sizeof(array[0]);
size_t size = backtrace(array, nMaxFrames);
char** symbols = backtrace_symbols(array, nMaxFrames);
fprintf(stderr, "\nZAPD crashed. (Signal: %i)\n", sig);
// Feel free to add more crash messages.
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);
std::string functionName(symbols[i]);
if (gotAddress != 0 && info.dli_sname != nullptr)
{
int32_t status;
char* demangled = abi::__cxa_demangle(info.dli_sname, nullptr, nullptr, &status);
const char* nameFound = info.dli_sname;
if (status == 0)
{
nameFound = demangled;
}
functionName = StringHelper::Sprintf("%s (+0x%X)", nameFound,
(char*)array[i] - (char*)info.dli_saddr);
free(demangled);
}
fprintf(stderr, "%-3zd %s\n", i, functionName.c_str());
}
fprintf(stderr, "\n");
free(symbols);
exit(1);
}
#endif
int main(int argc, char* argv[])
{
// Syntax: ZAPD.out [mode (btex/bovl/e)] (Arbritrary Number of Arguments)
if (argc < 2)
{
printf("ZAPD.out (%s) [mode (btex/bovl/bsf/bblb/bmdlintr/bamnintr/e)] ...\n", gBuildHash);
return 1;
}
for (int i = 1; i < argc; i++)
{
if (!strcmp(argv[i], "--version"))
{
printf("ZAPD.out %s\n", gBuildHash);
return 0;
}
else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
{
printf("Congratulations!\n");
printf("You just found the (unimplemented and undocumented) ZAPD's help message.\n");
printf("Feel free to implement it if you want :D\n");
return 0;
}
}
Globals* g = new Globals();
// Parse File Mode
std::string buildMode = argv[1];
ZFileMode fileMode = ZFileMode::Invalid;
if (buildMode == "btex")
fileMode = ZFileMode::BuildTexture;
else if (buildMode == "bren")
fileMode = ZFileMode::BuildBackground;
else if (buildMode == "bovl")
fileMode = ZFileMode::BuildOverlay;
else if (buildMode == "bsf")
fileMode = ZFileMode::BuildSourceFile;
else if (buildMode == "bblb")
fileMode = ZFileMode::BuildBlob;
else if (buildMode == "bmdlintr")
fileMode = ZFileMode::BuildModelIntermediette;
else if (buildMode == "bamnintr")
fileMode = ZFileMode::BuildAnimationIntermediette;
else if (buildMode == "e")
fileMode = ZFileMode::Extract;
if (fileMode == ZFileMode::Invalid)
{
printf("Error: Invalid file mode '%s'\n", buildMode.c_str());
return 1;
}
// Parse other "commands"
for (int32_t i = 2; i < argc; i++)
{
std::string arg = argv[i];
if (arg == "-o" || arg == "--outputpath") // Set output path
{
Globals::Instance->outputPath = argv[i + 1];
if (Globals::Instance->sourceOutputPath == "")
Globals::Instance->sourceOutputPath = Globals::Instance->outputPath;
i++;
}
else if (arg == "-i" || arg == "--inputpath") // Set input path
{
Globals::Instance->inputPath = argv[i + 1];
i++;
}
else if (arg == "-b" || arg == "--baserompath") // Set baserom path
{
Globals::Instance->baseRomPath = argv[i + 1];
i++;
}
else if (arg == "-osf") // Set source output path
{
Globals::Instance->sourceOutputPath = argv[i + 1];
i++;
}
else if (arg == "-gsf") // Generate source file during extraction
{
Globals::Instance->genSourceFile = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-tm") // Test Mode (enables certain experimental features)
{
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 = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-profile") // Enable profiling
{
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 = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-tt") // Set texture type
{
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.
{
Globals::Instance->cfgPath = argv[i + 1];
i++;
}
else if (arg == "-rconf") // Read Config File
{
Globals::Instance->ReadConfigFile(argv[i + 1]);
i++;
}
else if (arg == "-eh") // Enable Error Handler
{
#if !defined(_MSC_VER) && !defined(__CYGWIN__)
signal(SIGSEGV, ErrorHandler);
signal(SIGABRT, ErrorHandler);
#else
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 = static_cast<VerbosityLevel>(strtol(argv[++i], NULL, 16));
}
else if (arg == "-wu" || arg == "--warn-unaccounted") // Warn unaccounted
{
Globals::Instance->warnUnaccounted = true;
}
}
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
printf("ZAPD: Zelda Asset Processor For Decomp: %s\n", gBuildHash);
if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
{
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.string(),
overlay->GetSourceOutputCode(""));
}
delete g;
return 0;
}
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
ZFileMode fileMode)
{
XMLDocument doc;
XMLError eResult = doc.LoadFile(xmlFilePath.string().c_str());
if (eResult != tinyxml2::XML_SUCCESS)
{
fprintf(stderr, "Invalid xml file: '%s'\n", xmlFilePath.c_str());
return false;
}
XMLNode* root = doc.FirstChild();
if (root == nullptr)
{
fprintf(stderr, "Missing Root tag in xml file: '%s'\n", xmlFilePath.c_str());
return false;
}
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (std::string(child->Name()) == "File")
{
ZFile* file = new ZFile(fileMode, child, basePath, outPath, "", xmlFilePath, false);
Globals::Instance->files.push_back(file);
}
else
{
throw std::runtime_error(
StringHelper::Sprintf("Parse: Fatal error in '%s'.\n\t Found a resource outside of "
"a File element: '%s'\n",
xmlFilePath.c_str(), child->Name()));
}
}
for (ZFile* file : Globals::Instance->files)
{
if (fileMode == ZFileMode::BuildSourceFile)
file->BuildSourceFile(outPath);
else
file->ExtractResources(outPath);
}
// All done, free files
for (ZFile* file : Globals::Instance->files)
delete file;
Globals::Instance->files.clear();
return true;
}
void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath)
{
std::string name = outPath.stem().string();
ZTexture tex(nullptr);
tex.FromPNG(pngFilePath, texType);
std::string cfgPath = StringHelper::Split(pngFilePath.string(), ".")[0] + ".cfg";
if (File::Exists(cfgPath))
name = File::ReadAllText(cfgPath);
std::string src = tex.GetBodySourceCode();
File::WriteAllText(outPath.string(), src);
}
void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath)
{
ZBackground background(nullptr);
background.ParseBinaryFile(imageFilePath.string(), false);
File::WriteAllText(outPath.string(), background.GetBodySourceCode());
}
void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath)
{
ZBlob* blob = ZBlob::FromFile(blobFilePath.string());
std::string name = outPath.stem().string(); // filename without extension
std::string src = blob->GetSourceOutputCode(name);
File::WriteAllText(outPath.string(), src);
delete blob;
}
void BuildAssetModelIntermediette(const fs::path& outPath)
{
XMLDocument doc;
HLModelIntermediette* mdl = HLModelIntermediette::FromXML(doc.RootElement());
std::string output = mdl->OutputCode();
File::WriteAllText(outPath.string(), output);
delete mdl;
}
void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath)
{
std::vector<std::string> split = StringHelper::Split(outPath.string(), "/");
ZFile* file = new ZFile("", split[split.size() - 2]);
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]);
std::string output = "";
output += file->declarations[2]->text + "\n";
output += file->declarations[1]->text + "\n";
output += file->declarations[0]->text + "\n";
File::WriteAllText(outPath.string(), output);
delete zAnim;
delete file;
}
+116
View File
@@ -0,0 +1,116 @@
#include "OutputFormatter.h"
void OutputFormatter::Flush()
{
if (col > lineLimit)
{
str.append(1, '\n');
str.append(currentIndent, ' ');
uint32_t newCol = currentIndent + (wordP - word);
for (uint32_t i = 0; i < wordNests; i++)
nestIndent[nest - i] -= col - newCol;
col = newCol;
}
else
{
str.append(space, spaceP - space);
}
spaceP = space;
str.append(word, wordP - word);
wordP = word;
wordNests = 0;
}
int OutputFormatter::Write(const char* buf, int count)
{
for (int i = 0; i < count; i++)
{
char c = buf[i];
if (c == ' ' || c == '\t' || c == '\n')
{
if (wordP - word != 0)
{
Flush();
}
if (c == '\n')
{
col = 0;
*spaceP++ = c;
}
else if (c == '\t')
{
int n = tabSize - (col % tabSize);
col += n;
for (int j = 0; j < n; j++)
*spaceP++ = ' ';
}
else
{
col++;
*spaceP++ = c;
}
currentIndent = nestIndent[nest];
}
else
{
col++;
if (c == '(')
{
nest++;
nestIndent[nest] = col;
wordNests++;
}
else if (c == ')')
{
if (nest > 0)
nest--;
if (wordNests > 0)
wordNests--;
}
*wordP++ = c;
}
}
return count;
}
int OutputFormatter::Write(const std::string& buf)
{
return Write(buf.data(), buf.size());
}
OutputFormatter* OutputFormatter::Instance;
int OutputFormatter::WriteStatic(const char* buf, int count)
{
return Instance->Write(buf, count);
}
int (*OutputFormatter::StaticWriter())(const char* buf, int count)
{
Instance = this;
return &WriteStatic;
}
OutputFormatter::OutputFormatter(uint32_t tabSize, uint32_t defaultIndent, uint32_t lineLimit)
: tabSize{tabSize}, defaultIndent{defaultIndent}, lineLimit{lineLimit}, col{0}, nest{0},
nestIndent{defaultIndent}, currentIndent{defaultIndent},
wordNests(0), wordP{word}, spaceP{space}
{
}
std::string OutputFormatter::GetOutput()
{
Flush();
return std::move(str);
}
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include <map>
#include <string>
#include <vector>
class OutputFormatter
{
private:
const uint32_t tabSize;
const uint32_t defaultIndent;
const uint32_t lineLimit;
uint32_t col;
uint32_t nest;
uint32_t nestIndent[8];
uint32_t currentIndent;
uint32_t wordNests;
char word[128];
char space[128];
char* wordP;
char* spaceP;
std::string str;
void Flush();
static OutputFormatter* Instance;
static int WriteStatic(const char* buf, int count);
public:
OutputFormatter(uint32_t tabSize = 4, uint32_t defaultIndent = 4, uint32_t lineLimit = 120);
int (*StaticWriter())(const char* buf, int count); // Must be `int` due to libgfxd
int Write(const char* buf, int count);
int Write(const std::string& buf);
std::string GetOutput();
};
+236
View File
@@ -0,0 +1,236 @@
#include "ZOverlay.h"
#include "../Directory.h"
#include "../File.h"
#include "../Path.h"
#include "../StringHelper.h"
using namespace ELFIO;
ZOverlay::ZOverlay()
{
name = "";
entries = std::vector<RelocationEntry*>();
}
ZOverlay::ZOverlay(std::string nName) : ZOverlay()
{
name = nName;
}
ZOverlay::~ZOverlay()
{
for (auto entry : entries)
if (entry)
delete entry;
entries.clear();
}
ZOverlay* ZOverlay::FromBuild(std::string buildPath, std::string cfgFolderPath)
{
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"));
std::vector<std::string> relSections = {".rel.text", ".rel.data", ".rel.rodata"};
std::vector<std::string> sections = {".text", ".data", ".rodata"};
int32_t sectionOffs[5] = {0};
std::vector<RelocationEntry*> textRelocs;
std::vector<RelocationEntry*> dataRelocs;
std::vector<RelocationEntry*> rodataRelocs;
// get the elf files
std::vector<elfio*> readers;
for (size_t i = 1; i < cfgLines.size(); i++)
{
std::string elfPath =
buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o";
elfio* reader = new elfio();
if (!reader->load(elfPath))
{
// not all files were compiled
for (auto r : readers)
delete r;
readers.clear();
delete ovl;
return nullptr;
}
readers.push_back(reader);
}
for (auto curReader : readers)
{
Elf_Half sec_num = curReader->sections.size();
for (int32_t i = 0; i < sec_num; i++)
{
section* pSec = curReader->sections[i];
if (pSec->get_type() == SHT_REL && std::find(relSections.begin(), relSections.end(),
pSec->get_name()) != relSections.end())
{
SectionType sectionType = GetSectionTypeFromStr(pSec->get_name());
if (sectionType == SectionType::ERROR)
fprintf(stderr, "WARNING: One of the section types returned ERROR\n");
relocation_section_accessor relocs(*curReader, pSec);
for (Elf_Xword j = 0; j < relocs.get_entries_num(); j++)
{
Elf64_Addr offset = 0;
Elf_Word symbol = 0;
Elf_Word type = 0;
{
Elf_Sxword addend = 0;
relocs.get_entry(j, offset, symbol, type, addend);
}
std::string curSymName;
Elf_Half curSymShndx = SHN_UNDEF;
{
symbol_section_accessor symbols(
*curReader, curReader->sections[(Elf_Half)pSec->get_link()]);
Elf64_Addr value;
Elf_Xword size;
unsigned char bind;
unsigned char type;
unsigned char other;
symbols.get_symbol(symbol, curSymName, value, size, bind, type, curSymShndx,
other);
}
// check symbols outside the elf but within the overlay
if (curSymShndx == SHN_UNDEF)
{
for (auto reader : readers)
{
if (curSymShndx != SHN_UNDEF)
break;
if (reader == curReader)
continue;
auto sectionData = reader->sections[(Elf_Half)pSec->get_link()];
if (sectionData == nullptr)
continue;
symbol_section_accessor symbols(*reader, sectionData);
for (Elf_Xword symIdx = 0; symIdx < symbols.get_symbols_num(); symIdx++)
{
Elf_Half shndx = SHN_UNDEF;
Elf64_Addr value;
std::string name;
Elf_Xword size;
unsigned char bind;
unsigned char type;
unsigned char other;
symbols.get_symbol(symIdx, name, value, size, bind, type, shndx,
other);
if (name == curSymName)
{
curSymShndx = shndx;
break;
}
}
}
}
if (curSymShndx != SHN_UNDEF)
{
RelocationType typeConverted = (RelocationType)type;
offset += sectionOffs[sectionType];
RelocationEntry* reloc =
new RelocationEntry(sectionType, typeConverted, offset);
// this is to keep the correct reloc entry order
if (sectionType == SectionType::Text)
textRelocs.push_back(reloc);
if (sectionType == SectionType::Data)
dataRelocs.push_back(reloc);
if (sectionType == SectionType::RoData)
rodataRelocs.push_back(reloc);
}
}
}
}
// increase section offsets
for (int32_t i = 0; i < sec_num; i++)
{
section* pSec = curReader->sections[i];
if (pSec->get_type() == SHT_PROGBITS &&
std::find(sections.begin(), sections.end(), pSec->get_name()) != sections.end())
{
SectionType sectionType = GetSectionTypeFromStr(pSec->get_name());
sectionOffs[sectionType] += pSec->get_size();
}
}
}
for (auto reloc : textRelocs)
ovl->entries.push_back(reloc);
for (auto reloc : dataRelocs)
ovl->entries.push_back(reloc);
for (auto reloc : rodataRelocs)
ovl->entries.push_back(reloc);
for (auto r : readers)
delete r;
readers.clear();
return ovl;
}
std::string ZOverlay::GetSourceOutputCode(const std::string& prefix)
{
std::string output = "";
output += ".section .ovl\n";
output += StringHelper::Sprintf(".word _%sSegmentTextSize\n", name.c_str());
output += StringHelper::Sprintf(".word _%sSegmentDataSize\n", name.c_str());
output += StringHelper::Sprintf(".word _%sSegmentRoDataSize\n", name.c_str());
output += StringHelper::Sprintf(".word _%sSegmentBssSize\n", name.c_str());
output += StringHelper::Sprintf(".word %i\n", entries.size());
for (size_t i = 0; i < entries.size(); i++)
{
RelocationEntry* reloc = entries[i];
output += StringHelper::Sprintf(".word 0x%08X\n", reloc->CalcRelocationWord());
}
size_t offset = (entries.size() * 4) + 20;
while (offset % 16 != 12)
{
output += ".word 0\n";
offset += 4;
}
output += StringHelper::Sprintf(".word 0x%08X\n", offset + 4);
return output;
}
SectionType ZOverlay::GetSectionTypeFromStr(std::string sectionName)
{
if (sectionName == ".rel.text" || sectionName == ".text")
return SectionType::Text;
else if (sectionName == ".rel.data" || sectionName == ".data")
return SectionType::Data;
else if (sectionName == ".rel.rodata" || sectionName == ".rodata" ||
sectionName == ".rodata.str1.4" || sectionName == ".rodata.cst4")
return SectionType::RoData;
else if (sectionName == ".rel.bss" || sectionName == ".bss")
return SectionType::Bss;
return SectionType::ERROR;
}
+67
View File
@@ -0,0 +1,67 @@
#pragma once
#include <elfio/elfio.hpp>
#include "../ZResource.h"
#include "tinyxml2.h"
enum SectionType
{
Text = 1,
Data = 2,
RoData = 3,
Bss = 4,
ERROR = 255
};
enum RelocationType
{
R_MIPS_32 = 2,
R_MIPS_26 = 4,
R_MIPS_HI16 = 5,
R_MIPS_LO16 = 6,
};
class RelocationEntry
{
public:
SectionType sectionType;
RelocationType relocationType;
int32_t offset;
RelocationEntry(SectionType nSecType, RelocationType nRelType, int32_t nOffset)
{
sectionType = nSecType;
relocationType = nRelType;
offset = nOffset;
}
uint32_t CalcRelocationWord()
{
uint32_t relocationWord = 0;
relocationWord |= sectionType << 30;
relocationWord |= relocationType << 24;
relocationWord |= offset;
return relocationWord;
}
};
class ZOverlay
{
public:
std::string name;
ZOverlay(std::string nName);
~ZOverlay();
static ZOverlay* FromBuild(std::string buildPath, std::string cfgFolderPath);
std::string GetSourceOutputCode(const std::string& prefix);
private:
std::vector<RelocationEntry*> entries;
ZOverlay();
static SectionType GetSectionTypeFromStr(std::string sectionName);
// static std::string GetOverlayNameFromElf(ELFIO::elfio& reader);
};
+53
View File
@@ -0,0 +1,53 @@
#pragma once
#include <iostream>
#include <string>
#include "StringHelper.h"
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif
class Path
{
public:
static std::string GetFileName(const std::string& input)
{
std::vector<std::string> split = StringHelper::Split(input, "/");
return split[split.size() - 1];
};
static std::string GetFileNameWithoutExtension(const std::string& input)
{
std::vector<std::string> split = StringHelper::Split(input, "/");
return split[split.size() - 1].substr(0, split[split.size() - 1].find_last_of("."));
};
static std::string GetFileNameExtension(const std::string& input)
{
return input.substr(input.find_last_of("."), input.length());
};
static std::string GetPath(const std::string& input)
{
std::vector<std::string> split = StringHelper::Split(input, "/");
std::string output = "";
for (std::string str : split)
{
if (str.find_last_of(".") == std::string::npos)
output += str + "/";
}
return output;
};
static std::string GetDirectoryName(const fs::path& path)
{
return path.parent_path().u8string();
};
};
+108
View File
@@ -0,0 +1,108 @@
#pragma once
#include <cstring>
#include <numeric>
#include <stdarg.h>
#include <string>
#include <vector>
#include <algorithm>
class StringHelper
{
public:
static std::vector<std::string> Split(std::string s, const std::string& delimiter)
{
std::vector<std::string> result;
size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos)
{
token = s.substr(0, pos);
result.push_back(token);
s.erase(0, pos + delimiter.length());
}
if (s.length() != 0)
result.push_back(s);
return result;
}
static std::string Strip(std::string s, const std::string& delimiter)
{
size_t pos = 0;
std::string token;
while ((pos = s.find(delimiter)) != std::string::npos)
{
token = s.substr(0, pos);
s.erase(pos, pos + delimiter.length());
}
return s;
}
static std::string Replace(std::string str, const std::string& from, const std::string& to)
{
size_t start_pos = str.find(from);
if (start_pos == std::string::npos)
return str;
str.replace(start_pos, from.length(), to);
return str;
}
static bool StartsWith(const std::string& s, const std::string& input)
{
return s.rfind(input, 0) == 0;
}
static bool Contains(const std::string& s, const std::string& input)
{
return s.find(input) != std::string::npos;
}
static bool EndsWith(const std::string& s, const std::string& input)
{
size_t inputLen = strlen(input.c_str());
return s.rfind(input) == (s.size() - inputLen);
}
static std::string Sprintf(const char* format, ...)
{
char buffer[32768];
// char buffer[2048];
std::string output = "";
va_list va;
va_start(va, format);
vsprintf(buffer, format, va);
va_end(va);
output = buffer;
return output;
}
static std::string Implode(std::vector<std::string>& elements, const char* const separator)
{
return std::accumulate(std::begin(elements), std::end(elements), std::string(),
[separator](std::string& ss, std::string& s) {
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);
}
};
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include <stdint.h>
struct Vec3s
{
int16_t x, y, z;
Vec3s()
{
x = 0;
y = 0;
z = 0;
};
Vec3s(int16_t nX, int16_t nY, int16_t nZ)
{
x = nX;
y = nY;
z = nZ;
};
};
+316
View File
@@ -0,0 +1,316 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}</ProjectGuid>
<RootNamespace>ZAPD</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>ZAPD</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(SolutionDir)lib\tinyxml2;$(SolutionDir)lib\libgfxd;$(SolutionDir)lib\elfio;$(SolutionDir)lib\assimp\include;$(SolutionDir)lib\stb;$(ProjectDir);$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)lib\libgfxd;$(SolutionDir)lib\assimp-built;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<Profile>true</Profile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;USE_ASSIMP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<LanguageStandard_C>stdc11</LanguageStandard_C>
</ClCompile>
<Link>
<Profile>true</Profile>
<AdditionalDependencies>assimp-vc142-mt.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>cd ..
python3 ZAPD/genbuildinfo.py</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\lib\libgfxd\gfxd.c" />
<ClCompile Include="..\lib\libgfxd\uc.c" />
<ClCompile Include="..\lib\libgfxd\uc_f3d.c" />
<ClCompile Include="..\lib\libgfxd\uc_f3db.c" />
<ClCompile Include="..\lib\libgfxd\uc_f3dex.c" />
<ClCompile Include="..\lib\libgfxd\uc_f3dex2.c" />
<ClCompile Include="..\lib\libgfxd\uc_f3dexb.c" />
<ClCompile Include="..\lib\tinyxml2\tinyxml2.cpp" />
<ClCompile Include="Globals.cpp" />
<ClCompile Include="HighLevel\HLAnimationIntermediette.cpp" />
<ClCompile Include="HighLevel\HLModelIntermediette.cpp" />
<ClCompile Include="HighLevel\HLTexture.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="OutputFormatter.cpp" />
<ClCompile Include="Overlays\ZOverlay.cpp" />
<ClCompile Include="ZArray.cpp" />
<ClCompile Include="ZBackground.cpp" />
<ClCompile Include="ZCutsceneMM.cpp" />
<ClCompile Include="ZLimb.cpp" />
<ClCompile Include="ZMtx.cpp" />
<ClCompile Include="ZRoom\Commands\SetActorCutsceneList.cpp" />
<ClCompile Include="ZRoom\Commands\SetAnimatedTextureList.cpp" />
<ClCompile Include="ZRoom\Commands\SetCsCamera.cpp" />
<ClCompile Include="ZRoom\Commands\SetMinimapChests.cpp" />
<ClCompile Include="ZRoom\Commands\SetMinimapList.cpp" />
<ClCompile Include="ZRoom\Commands\SetWorldMapVisited.cpp" />
<ClCompile Include="ZRoom\Commands\Unused1D.cpp" />
<ClCompile Include="ZScalar.cpp" />
<ClCompile Include="ZAnimation.cpp" />
<ClCompile Include="ZBlob.cpp" />
<ClCompile Include="ZCollision.cpp" />
<ClCompile Include="ZCutscene.cpp" />
<ClCompile Include="ZDisplayList.cpp" />
<ClCompile Include="ZFile.cpp" />
<ClCompile Include="ZSkeleton.cpp" />
<ClCompile Include="ZResource.cpp" />
<ClCompile Include="ZRoom\Commands\EndMarker.cpp" />
<ClCompile Include="ZRoom\Commands\SetActorList.cpp" />
<ClCompile Include="ZRoom\Commands\SetAlternateHeaders.cpp" />
<ClCompile Include="ZRoom\Commands\SetCameraSettings.cpp" />
<ClCompile Include="ZRoom\Commands\SetCollisionHeader.cpp" />
<ClCompile Include="ZRoom\Commands\SetCutscenes.cpp" />
<ClCompile Include="ZRoom\Commands\SetEchoSettings.cpp" />
<ClCompile Include="ZRoom\Commands\SetEntranceList.cpp" />
<ClCompile Include="ZRoom\Commands\SetExitList.cpp" />
<ClCompile Include="ZRoom\Commands\SetLightingSettings.cpp" />
<ClCompile Include="ZRoom\Commands\SetLightList.cpp" />
<ClCompile Include="ZRoom\Commands\SetMesh.cpp" />
<ClCompile Include="ZRoom\Commands\SetObjectList.cpp" />
<ClCompile Include="ZRoom\Commands\SetPathways.cpp" />
<ClCompile Include="ZRoom\Commands\SetRoomBehavior.cpp" />
<ClCompile Include="ZRoom\Commands\SetRoomList.cpp" />
<ClCompile Include="ZRoom\Commands\SetSkyboxModifier.cpp" />
<ClCompile Include="ZRoom\Commands\SetSkyboxSettings.cpp" />
<ClCompile Include="ZRoom\Commands\SetSoundSettings.cpp" />
<ClCompile Include="ZRoom\Commands\SetSpecialObjects.cpp" />
<ClCompile Include="ZRoom\Commands\SetStartPositionList.cpp" />
<ClCompile Include="ZRoom\Commands\SetTimeSettings.cpp" />
<ClCompile Include="ZRoom\Commands\SetTransitionActorList.cpp" />
<ClCompile Include="ZRoom\Commands\SetWind.cpp" />
<ClCompile Include="ZRoom\Commands\Unused09.cpp" />
<ClCompile Include="ZRoom\Commands\ZRoomCommandUnk.cpp" />
<ClCompile Include="ZRoom\ZRoom.cpp" />
<ClCompile Include="ZRoom\ZRoomCommand.cpp" />
<ClCompile Include="ZSymbol.cpp" />
<ClCompile Include="ZTexture.cpp" />
<ClCompile Include="ZVector.cpp" />
<ClCompile Include="ZVtx.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\lib\elfio\elfio\elfio.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_dump.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_dynamic.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_header.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_note.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_relocation.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_section.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_segment.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_strings.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_symbols.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elfio_utils.hpp" />
<ClInclude Include="..\lib\elfio\elfio\elf_types.hpp" />
<ClInclude Include="..\lib\json\include\nlohmann\json.hpp" />
<ClInclude Include="..\lib\libgfxd\gbi.h" />
<ClInclude Include="..\lib\libgfxd\gfxd.h" />
<ClInclude Include="..\lib\libgfxd\priv.h" />
<ClInclude Include="..\lib\stb\stb_image.h" />
<ClInclude Include="..\lib\stb\stb_image_write.h" />
<ClInclude Include="..\lib\stb\tinyxml2.h" />
<ClInclude Include="..\lib\tinygtlf\tiny_gltf.h" />
<ClInclude Include="BitConverter.h" />
<ClInclude Include="CRC32.h" />
<ClInclude Include="Directory.h" />
<ClInclude Include="File.h" />
<ClInclude Include="Globals.h" />
<ClInclude Include="HighLevel\HLAnimation.h" />
<ClInclude Include="HighLevel\HLAnimationIntermediette.h" />
<ClInclude Include="HighLevel\HLFileIntermediette.h" />
<ClInclude Include="HighLevel\HLModelIntermediette.h" />
<ClInclude Include="HighLevel\HLTexture.h" />
<ClInclude Include="OutputFormatter.h" />
<ClInclude Include="Overlays\ZOverlay.h" />
<ClInclude Include="Path.h" />
<ClInclude Include="StringHelper.h" />
<ClInclude Include="Vec3s.h" />
<ClInclude Include="ZAnimation.h" />
<ClInclude Include="ZArray.h" />
<ClInclude Include="ZBackground.h" />
<ClInclude Include="ZBlob.h" />
<ClInclude Include="ZCollision.h" />
<ClInclude Include="ZCutscene.h" />
<ClInclude Include="ZCutsceneMM.h" />
<ClInclude Include="ZDisplayList.h" />
<ClInclude Include="ZFile.h" />
<ClInclude Include="ZLimb.h" />
<ClInclude Include="ZMtx.h" />
<ClInclude Include="ZRoom\Commands\SetActorCutsceneList.h" />
<ClInclude Include="ZRoom\Commands\SetAnimatedTextureList.h" />
<ClInclude Include="ZRoom\Commands\SetCsCamera.h" />
<ClInclude Include="ZRoom\Commands\SetMinimapChests.h" />
<ClInclude Include="ZRoom\Commands\SetMinimapList.h" />
<ClInclude Include="ZRoom\Commands\SetWorldMapVisited.h" />
<ClInclude Include="ZRoom\Commands\Unused1D.h" />
<ClInclude Include="ZScalar.h" />
<ClInclude Include="ZSkeleton.h" />
<ClInclude Include="ZResource.h" />
<ClInclude Include="ZRoom\ActorList.h" />
<ClInclude Include="ZRoom\Commands\EndMarker.h" />
<ClInclude Include="ZRoom\Commands\SetActorList.h" />
<ClInclude Include="ZRoom\Commands\SetAlternateHeaders.h" />
<ClInclude Include="ZRoom\Commands\SetCameraSettings.h" />
<ClInclude Include="ZRoom\Commands\SetCollisionHeader.h" />
<ClInclude Include="ZRoom\Commands\SetCutscenes.h" />
<ClInclude Include="ZRoom\Commands\SetEchoSettings.h" />
<ClInclude Include="ZRoom\Commands\SetEntranceList.h" />
<ClInclude Include="ZRoom\Commands\SetExitList.h" />
<ClInclude Include="ZRoom\Commands\SetLightingSettings.h" />
<ClInclude Include="ZRoom\Commands\SetLightList.h" />
<ClInclude Include="ZRoom\Commands\SetMesh.h" />
<ClInclude Include="ZRoom\Commands\SetObjectList.h" />
<ClInclude Include="ZRoom\Commands\SetPathways.h" />
<ClInclude Include="ZRoom\Commands\SetRoomBehavior.h" />
<ClInclude Include="ZRoom\Commands\SetRoomList.h" />
<ClInclude Include="ZRoom\Commands\SetSkyboxModifier.h" />
<ClInclude Include="ZRoom\Commands\SetSkyboxSettings.h" />
<ClInclude Include="ZRoom\Commands\SetSoundSettings.h" />
<ClInclude Include="ZRoom\Commands\SetSpecialObjects.h" />
<ClInclude Include="ZRoom\Commands\SetStartPositionList.h" />
<ClInclude Include="ZRoom\Commands\SetTimeSettings.h" />
<ClInclude Include="ZRoom\Commands\SetTransitionActorList.h" />
<ClInclude Include="ZRoom\Commands\SetWind.h" />
<ClInclude Include="ZRoom\Commands\Unused09.h" />
<ClInclude Include="ZRoom\Commands\ZRoomCommandUnk.h" />
<ClInclude Include="ZRoom\ObjectList.h" />
<ClInclude Include="ZRoom\ZRoom.h" />
<ClInclude Include="ZRoom\ZRoomCommand.h" />
<ClInclude Include="ZSymbol.h" />
<ClInclude Include="ZTexture.h" />
<ClInclude Include="ZVector.h" />
<ClInclude Include="ZVtx.h" />
</ItemGroup>
<ItemGroup>
<Text Include="..\SymbolMap_OoTMqDbg.txt">
<DeploymentContent>true</DeploymentContent>
</Text>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="..\lib\assimp-built\assimp-vc142-mt.dll">
<FileType>Document</FileType>
</CopyFileToFolders>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
+553
View File
@@ -0,0 +1,553 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Source Files\Libraries">
<UniqueIdentifier>{02148456-5068-4613-8478-f10addc58e70}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Libraries">
<UniqueIdentifier>{bcab3136-95ba-4839-833c-43d78ad6e335}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Libraries\elfio">
<UniqueIdentifier>{dc06ed84-f6fe-4277-80f3-d62bd5cdbb98}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Z64">
<UniqueIdentifier>{6049c045-bc38-4221-b29e-ca6d4d8af4aa}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Z64\ZRoom">
<UniqueIdentifier>{490e3a08-047b-48d3-ab53-3a860a3b92aa}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Z64\ZRoom\Commands">
<UniqueIdentifier>{26c06845-8e8e-4b79-ad18-07c4f9c0f801}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Z64">
<UniqueIdentifier>{d45c420d-2378-47ac-92c5-80db9475c195}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Z64\ZRoom">
<UniqueIdentifier>{03cc56a2-e0e8-4167-80a0-98fb900a959a}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Z64\ZRoom\Commands">
<UniqueIdentifier>{73db0879-6df8-4f6a-8cc2-a1f836e9e796}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\HighLevel">
<UniqueIdentifier>{9464ff21-96af-4b7d-a57b-f62bd9b7389a}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\HighLevel\Model">
<UniqueIdentifier>{e9865c34-fd69-413c-8cce-3f51331c3503}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\HighLevel">
<UniqueIdentifier>{0f9980bb-ae46-4891-a39e-275bf255f010}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\HighLevel\Room">
<UniqueIdentifier>{11dbd8e6-d97a-42a5-b40c-e1350389544d}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Libraries\fbx">
<UniqueIdentifier>{be9a5be0-ec6a-4200-8e39-bb58c7da7aa8}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Libraries\libgfxd">
<UniqueIdentifier>{7ee79d97-c6a8-4e82-93ef-37981f4d7838}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Libraries\libgfxd">
<UniqueIdentifier>{85600275-99fe-491d-8189-bcc3dc1a8903}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ZRoom\ZRoom.cpp">
<Filter>Source Files\Z64\ZRoom</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetEchoSettings.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\ZRoomCommand.cpp">
<Filter>Source Files\Z64\ZRoom</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetSoundSettings.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetWind.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetTimeSettings.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetSpecialObjects.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetRoomBehavior.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetSkyboxSettings.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetCameraSettings.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetSkyboxModifier.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetActorList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetEntranceList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetStartPositionList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="Globals.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetAlternateHeaders.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetExitList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\EndMarker.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetCollisionHeader.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetRoomList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetObjectList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetMesh.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\Unused09.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetLightingSettings.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetTransitionActorList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetPathways.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetCutscenes.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="..\lib\tinyxml2\tinyxml2.cpp">
<Filter>Source Files\Libraries</Filter>
</ClCompile>
<ClCompile Include="ZAnimation.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZBlob.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZCutscene.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZDisplayList.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZFile.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZResource.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZTexture.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="Overlays\ZOverlay.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="HighLevel\HLAnimationIntermediette.cpp">
<Filter>Source Files\HighLevel</Filter>
</ClCompile>
<ClCompile Include="HighLevel\HLModelIntermediette.cpp">
<Filter>Source Files\HighLevel</Filter>
</ClCompile>
<ClCompile Include="HighLevel\HLTexture.cpp">
<Filter>Source Files\HighLevel</Filter>
</ClCompile>
<ClCompile Include="ZSkeleton.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetLightList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\ZRoomCommandUnk.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZCollision.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZScalar.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZVector.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZArray.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZVtx.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZLimb.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="OutputFormatter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ZSymbol.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="..\lib\libgfxd\gfxd.c">
<Filter>Source Files\Libraries\libgfxd</Filter>
</ClCompile>
<ClCompile Include="..\lib\libgfxd\uc.c">
<Filter>Source Files\Libraries\libgfxd</Filter>
</ClCompile>
<ClCompile Include="..\lib\libgfxd\uc_f3d.c">
<Filter>Source Files\Libraries\libgfxd</Filter>
</ClCompile>
<ClCompile Include="..\lib\libgfxd\uc_f3db.c">
<Filter>Source Files\Libraries\libgfxd</Filter>
</ClCompile>
<ClCompile Include="..\lib\libgfxd\uc_f3dex.c">
<Filter>Source Files\Libraries\libgfxd</Filter>
</ClCompile>
<ClCompile Include="..\lib\libgfxd\uc_f3dex2.c">
<Filter>Source Files\Libraries\libgfxd</Filter>
</ClCompile>
<ClCompile Include="..\lib\libgfxd\uc_f3dexb.c">
<Filter>Source Files\Libraries\libgfxd</Filter>
</ClCompile>
<ClCompile Include="ZMtx.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetWorldMapVisited.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\Unused1D.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetActorCutsceneList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetAnimatedTextureList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetCsCamera.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetMinimapChests.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZRoom\Commands\SetMinimapList.cpp">
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
</ClCompile>
<ClCompile Include="ZCutsceneMM.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZBackground.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Path.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="File.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Directory.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ZRoom\ZRoom.h">
<Filter>Header Files\Z64\ZRoom</Filter>
</ClInclude>
<ClInclude Include="ZRoom\ZRoomCommand.h">
<Filter>Header Files\Z64\ZRoom</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetEchoSettings.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetSoundSettings.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetWind.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetTimeSettings.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="BitConverter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetSpecialObjects.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetRoomBehavior.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetSkyboxSettings.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetCameraSettings.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetSkyboxModifier.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetActorList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetEntranceList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetStartPositionList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elf_types.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_dump.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_dynamic.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_header.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_note.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_relocation.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_section.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_segment.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_strings.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_symbols.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="..\lib\elfio\elfio\elfio_utils.hpp">
<Filter>Header Files\Libraries\elfio</Filter>
</ClInclude>
<ClInclude Include="StringHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Globals.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetAlternateHeaders.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetExitList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\EndMarker.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetCollisionHeader.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetRoomList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetObjectList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetMesh.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\Unused09.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\ObjectList.h">
<Filter>Header Files\Z64\ZRoom</Filter>
</ClInclude>
<ClInclude Include="ZRoom\ActorList.h">
<Filter>Header Files\Z64\ZRoom</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetLightingSettings.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetTransitionActorList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetPathways.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetCutscenes.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="Vec3s.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\lib\json\include\nlohmann\json.hpp">
<Filter>Header Files\Libraries</Filter>
</ClInclude>
<ClInclude Include="..\lib\stb\stb_image.h">
<Filter>Header Files\Libraries</Filter>
</ClInclude>
<ClInclude Include="..\lib\stb\stb_image_write.h">
<Filter>Header Files\Libraries</Filter>
</ClInclude>
<ClInclude Include="..\lib\tinygtlf\tiny_gltf.h">
<Filter>Header Files\Libraries</Filter>
</ClInclude>
<ClInclude Include="Overlays\ZOverlay.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZTexture.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZAnimation.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZBlob.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZCutscene.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZDisplayList.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZFile.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZResource.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="HighLevel\HLTexture.h">
<Filter>Header Files\HighLevel</Filter>
</ClInclude>
<ClInclude Include="HighLevel\HLAnimation.h">
<Filter>Header Files\HighLevel</Filter>
</ClInclude>
<ClInclude Include="HighLevel\HLAnimationIntermediette.h">
<Filter>Header Files\HighLevel</Filter>
</ClInclude>
<ClInclude Include="HighLevel\HLModelIntermediette.h">
<Filter>Header Files\HighLevel</Filter>
</ClInclude>
<ClInclude Include="ZSkeleton.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="HighLevel\HLFileIntermediette.h">
<Filter>Header Files\HighLevel</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetLightList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\ZRoomCommandUnk.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZCollision.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZScalar.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZVector.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="..\lib\stb\tinyxml2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ZArray.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZVtx.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="CRC32.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ZLimb.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="OutputFormatter.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ZSymbol.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="..\lib\libgfxd\gbi.h">
<Filter>Header Files\Libraries\libgfxd</Filter>
</ClInclude>
<ClInclude Include="..\lib\libgfxd\gfxd.h">
<Filter>Header Files\Libraries\libgfxd</Filter>
</ClInclude>
<ClInclude Include="..\lib\libgfxd\priv.h">
<Filter>Header Files\Libraries\libgfxd</Filter>
</ClInclude>
<ClInclude Include="ZMtx.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetWorldMapVisited.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetActorCutsceneList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\Unused1D.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetAnimatedTextureList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetCsCamera.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetMinimapChests.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZRoom\Commands\SetMinimapList.h">
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
</ClInclude>
<ClInclude Include="ZCutsceneMM.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZBackground.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="..\SymbolMap_OoTMqDbg.txt">
<Filter>Resource Files</Filter>
</Text>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="..\lib\assimp-built\assimp-vc142-mt.dll">
<Filter>Resource Files</Filter>
</CopyFileToFolders>
</ItemGroup>
</Project>
+474
View File
@@ -0,0 +1,474 @@
#include "ZAnimation.h"
#include <utility>
#include "BitConverter.h"
#include "File.h"
#include "Globals.h"
#include "HighLevel/HLAnimationIntermediette.h"
#include "StringHelper.h"
#include "ZFile.h"
REGISTER_ZFILENODE(Animation, ZNormalAnimation);
REGISTER_ZFILENODE(PlayerAnimation, ZLinkAnimation);
REGISTER_ZFILENODE(CurveAnimation, ZCurveAnimation);
ZAnimation::ZAnimation(ZFile* nParent) : ZResource(nParent)
{
frameCount = 0;
}
void ZAnimation::ParseRawData()
{
const uint8_t* data = rawData.data();
// Read the header
frameCount = BitConverter::ToInt16BE(data, rawDataIndex + 0);
}
void ZAnimation::Save(const fs::path& outFolder)
{
if (Globals::Instance->testMode)
{
HLAnimationIntermediette* anim = HLAnimationIntermediette::FromZAnimation(this);
std::string xml = anim->OutputXML();
File::WriteAllText(outFolder / (name + ".anmi"), xml);
delete anim;
}
}
std::string ZAnimation::GetSourceOutputCode(const std::string& prefix)
{
return "";
}
ZResourceType ZAnimation::GetResourceType() const
{
return ZResourceType::Animation;
}
ZNormalAnimation::ZNormalAnimation(ZFile* nParent) : ZAnimation(nParent)
{
rotationValues = std::vector<uint16_t>();
rotationIndices = std::vector<RotationIndex>();
limit = 0;
}
std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
{
std::string defaultPrefix = name.c_str();
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
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);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), StringHelper::Sprintf("%s", name.c_str()),
headerStr);
std::string indicesStr = "";
std::string valuesStr = " ";
const uint8_t lineLength = 14;
const uint8_t offset = 0;
for (size_t i = 0; i < rotationValues.size(); i++)
{
valuesStr += StringHelper::Sprintf("0x%04X, ", rotationValues[i]);
if ((i - offset + 1) % lineLength == 0)
valuesStr += "\n ";
}
for (size_t i = 0; i < rotationIndices.size(); i++)
{
indicesStr +=
StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x,
rotationIndices[i].y, rotationIndices[i].z);
if (i != (rotationIndices.size() - 1))
indicesStr += "\n";
}
parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16,
rotationValues.size() * 2, "static s16",
StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()),
rotationValues.size(), valuesStr);
parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16,
rotationIndices.size() * 6, "static JointIndex",
StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()),
rotationIndices.size(), indicesStr);
}
return "";
}
size_t ZNormalAnimation::GetRawDataSize() const
{
return 16;
}
std::string ZNormalAnimation::GetSourceTypeName() const
{
return "AnimationHeader";
}
void ZNormalAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
const uint8_t* data = rawData.data();
rotationValuesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 4) & 0x00FFFFFF;
rotationIndicesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 8) & 0x00FFFFFF;
limit = BitConverter::ToInt16BE(data, rawDataIndex + 12);
uint32_t currentPtr = rotationValuesSeg;
// Read the Rotation Values
for (uint32_t i = 0; i < ((rotationIndicesSeg - rotationValuesSeg) / 2); i++)
{
rotationValues.push_back(BitConverter::ToInt16BE(data, currentPtr));
currentPtr += 2;
}
currentPtr = rotationIndicesSeg;
// Read the Rotation Indices
for (uint32_t i = 0; i < ((rawDataIndex - rotationIndicesSeg) / 6); i++)
{
rotationIndices.push_back(RotationIndex(BitConverter::ToInt16BE(data, currentPtr),
BitConverter::ToInt16BE(data, currentPtr + 2),
BitConverter::ToInt16BE(data, currentPtr + 4)));
currentPtr += 6;
}
}
ZLinkAnimation::ZLinkAnimation(ZFile* nParent) : ZAnimation(nParent)
{
segmentAddress = 0;
}
std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
{
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()),
headerStr);
}
return "";
}
size_t ZLinkAnimation::GetRawDataSize() const
{
return 8;
}
std::string ZLinkAnimation::GetSourceTypeName() const
{
return "LinkAnimationHeader";
}
void ZLinkAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
const uint8_t* data = rawData.data();
segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4));
}
/* ZCurveAnimation */
TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData,
uint32_t fileOffset)
: parent(parent)
{
unk_00 = BitConverter::ToUInt16BE(rawData, fileOffset + 0);
unk_02 = BitConverter::ToUInt16BE(rawData, fileOffset + 2);
unk_04 = BitConverter::ToInt16BE(rawData, fileOffset + 4);
unk_06 = BitConverter::ToInt16BE(rawData, fileOffset + 6);
unk_08 = BitConverter::ToFloatBE(rawData, fileOffset + 8);
}
TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData,
uint32_t fileOffset, size_t index)
: TransformData(parent, rawData, fileOffset + index * GetRawDataSize())
{
}
std::string TransformData::GetBody(const std::string& prefix) const
{
return StringHelper::Sprintf("0x%04X, 0x%04X, %i, %i, %ff", unk_00, unk_02, unk_04, unk_06,
unk_08);
}
size_t TransformData::GetRawDataSize() const
{
return 0x0C;
}
std::string TransformData::GetSourceTypeName()
{
return "TransformData";
}
ZCurveAnimation::ZCurveAnimation(ZFile* nParent) : ZAnimation(nParent)
{
RegisterOptionalAttribute("SkelOffset");
}
void ZCurveAnimation::ParseXML(tinyxml2::XMLElement* reader)
{
ZAnimation::ParseXML(reader);
std::string skelOffsetXml = registeredAttributes.at("SkelOffset").value;
if (skelOffsetXml == "")
{
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 = StringHelper::StrToL(skelOffsetXml, 0);
}
void ZCurveAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
refIndex = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0);
transformData = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
copyValues = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
unk_0C = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
unk_10 = BitConverter::ToInt16BE(rawData, rawDataIndex + 14);
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 * limbCount; i++)
{
uint8_t ref = BitConverter::ToUInt8BE(rawData, refIndexOffset + i);
if (ref == 0)
copyValuesSize++;
else
transformDataSize += ref;
refIndexArr.emplace_back(ref);
}
}
if (transformData != 0)
{
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
for (size_t i = 0; i < transformDataSize; i++)
transformDataArr.emplace_back(parent, rawData, transformDataOffset, i);
}
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
for (size_t i = 0; i < copyValuesSize; i++)
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::DeclareReferences(const std::string& prefix)
{
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
std::string refIndexStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", refIndexOffset);
std::string entryStr = " ";
uint16_t arrayItemCnt = refIndexArr.size();
size_t i = 0;
for (auto& child : refIndexArr)
{
entryStr += StringHelper::Sprintf("0x%02X, %s", child, (i++ % 8 == 7) ? "\n " : "");
}
Declaration* decl = parent->GetDeclaration(refIndexOffset);
if (decl == nullptr)
{
parent->AddDeclarationArray(refIndexOffset, DeclarationAlignment::None,
arrayItemCnt * 1, "u8", refIndexStr, arrayItemCnt,
entryStr);
}
else
{
decl->text = entryStr;
}
}
if (transformData != 0)
{
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
std::string transformDataStr = StringHelper::Sprintf(
"%sCurveAnime_%s_%06X", prefix.c_str(),
transformDataArr.at(0).GetSourceTypeName().c_str(), transformDataOffset);
std::string entryStr = "";
uint16_t arrayItemCnt = transformDataArr.size();
size_t i = 0;
for (auto& child : transformDataArr)
{
entryStr += StringHelper::Sprintf(" { %s },%s", child.GetBody(prefix).c_str(),
(++i < arrayItemCnt) ? "\n" : "");
}
Declaration* decl = parent->GetDeclaration(transformDataOffset);
if (decl == nullptr)
{
parent->AddDeclarationArray(transformDataOffset, DeclarationAlignment::None,
arrayItemCnt * transformDataArr.at(0).GetRawDataSize(),
transformDataArr.at(0).GetSourceTypeName(),
transformDataStr, arrayItemCnt, entryStr);
}
else
{
decl->text = entryStr;
}
}
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
std::string copyValuesStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", copyValuesOffset);
std::string entryStr = " ";
uint16_t arrayItemCnt = copyValuesArr.size();
size_t i = 0;
for (auto& child : copyValuesArr)
{
entryStr += StringHelper::Sprintf("% 6i, %s", child, (i++ % 8 == 7) ? "\n " : "");
}
Declaration* decl = parent->GetDeclaration(copyValuesOffset);
if (decl == nullptr)
{
parent->AddDeclarationArray(copyValuesOffset, DeclarationAlignment::None,
arrayItemCnt * 2, "s16", copyValuesStr, arrayItemCnt,
entryStr);
}
else
{
decl->text = entryStr;
}
}
}
size_t ZCurveAnimation::GetRawDataSize() const
{
return 0x10;
}
std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
{
std::string bodyStr = "";
uint32_t address = Seg2Filespace(rawDataIndex, parent->baseAddress);
std::string refIndexStr = "NULL";
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(refIndexOffset);
if (decl == nullptr)
{
refIndexStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref",
refIndexOffset);
}
else
{
refIndexStr = decl->varName;
}
}
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(),
transformDataArr.at(0).GetSourceTypeName().c_str(), transformDataOffset);
}
else
{
transformDataStr = decl->varName;
}
}
std::string copyValuesStr = "NULL";
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(copyValuesOffset);
if (decl == nullptr)
{
copyValuesStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy",
copyValuesOffset);
}
else
{
copyValuesStr = decl->varName;
}
}
bodyStr =
StringHelper::Sprintf("\n %s,\n %s,\n %s,\n %i, %i\n", refIndexStr.c_str(),
transformDataStr.c_str(), copyValuesStr.c_str(), unk_0C, unk_10);
Declaration* decl = parent->GetDeclaration(address);
if (decl == nullptr)
{
parent->AddDeclaration(address, DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), name, bodyStr);
}
else
{
decl->text = bodyStr;
}
return "";
}
std::string ZCurveAnimation::GetSourceTypeName() const
{
return "TransformUpdateIndex";
}
+138
View File
@@ -0,0 +1,138 @@
#pragma once
#include <stdint.h>
#include <string>
#include <vector>
#include "Vec3s.h"
#include "ZResource.h"
#include "ZSkeleton.h"
#include "tinyxml2.h"
struct RotationIndex
{
// uint16_t transX, transY, transZ;
uint16_t x, y, z;
RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ)
{
x = nX;
y = nY;
z = nZ;
};
};
class ZAnimation : public ZResource
{
public:
int16_t frameCount;
ZAnimation(ZFile* nParent);
std::string GetSourceOutputCode(const std::string& prefix) override;
ZResourceType GetResourceType() const override;
protected:
void ParseRawData() override;
void Save(const fs::path& outFolder) override;
};
class ZNormalAnimation : public ZAnimation
{
public:
std::vector<uint16_t> rotationValues;
std::vector<RotationIndex> rotationIndices;
uint32_t rotationValuesSeg;
uint32_t rotationIndicesSeg;
int16_t limit;
ZNormalAnimation(ZFile* nParent);
std::string GetSourceOutputCode(const std::string& prefix) override;
size_t GetRawDataSize() const override;
std::string GetSourceTypeName() const override;
protected:
virtual void ParseRawData() override;
};
class ZLinkAnimation : public ZAnimation
{
public:
segptr_t segmentAddress;
ZLinkAnimation(ZFile* nParent);
std::string GetSourceOutputCode(const std::string& prefix) override;
size_t GetRawDataSize() const override;
std::string GetSourceTypeName() const override;
protected:
virtual void ParseRawData() override;
};
class TransformData
{
protected:
ZFile* parent;
///* 0x0000 */ u16 unk_00; // appears to be flags
uint16_t unk_00;
///* 0x0002 */ s16 unk_02;
int16_t unk_02;
///* 0x0004 */ s16 unk_04;
int16_t unk_04;
///* 0x0006 */ s16 unk_06;
int16_t unk_06;
///* 0x0008 */ f32 unk_08;
float unk_08;
public:
TransformData() = default;
TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset);
TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index);
[[nodiscard]] std::string GetBody(const std::string& prefix) const;
size_t GetRawDataSize() const;
std::string GetSourceTypeName();
};
class ZCurveAnimation : public ZAnimation
{
protected:
segptr_t skelOffset = 0;
///* 0x0000 */ u8* refIndex;
segptr_t refIndex = 0;
///* 0x0004 */ TransformData* transformData;
segptr_t transformData = 0;
///* 0x0008 */ s16* copyValues;
segptr_t copyValues = 0;
///* 0x000C */ s16 unk_0C;
int16_t unk_0C;
///* 0x000E */ s16 unk_10;
int16_t unk_10;
uint8_t limbCount = 0;
std::vector<uint8_t> refIndexArr;
std::vector<TransformData> transformDataArr;
std::vector<int16_t> copyValuesArr;
public:
ZCurveAnimation();
ZCurveAnimation(ZFile* nParent);
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex) override;
void DeclareReferences(const std::string& prefix) override;
size_t GetRawDataSize() const override;
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceTypeName() const override;
};
// TransformUpdateIndex
+86
View File
@@ -0,0 +1,86 @@
#include "ZArray.h"
#include <cassert>
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
REGISTER_ZFILENODE(Array, ZArray);
ZArray::ZArray(ZFile* nParent) : ZResource(nParent)
{
canHaveInner = true;
RegisterRequiredAttribute("Count");
}
ZArray::~ZArray()
{
for (auto res : resList)
delete res;
}
void ZArray::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
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);
}
}
std::string ZArray::GetSourceOutputCode(const std::string& prefix)
{
std::string output = "";
for (size_t i = 0; i < arrayCnt; i++)
{
output += resList.at(i)->GetBodySourceCode();
if (i < arrayCnt - 1)
output += ",\n";
}
if (parent != nullptr)
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
resList.at(0)->GetSourceTypeName(), name, arrayCnt, output);
return "";
}
size_t ZArray::GetRawDataSize() const
{
size_t size = 0;
for (auto res : resList)
size += res->GetRawDataSize();
return size;
}
ZResourceType ZArray::GetResourceType() const
{
return ZResourceType::Array;
}
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#include <stdint.h>
#include <string>
#include <vector>
#include "ZResource.h"
#include "tinyxml2.h"
class ZArray : public ZResource
{
public:
ZArray(ZFile* nParent);
~ZArray();
void ParseXML(tinyxml2::XMLElement* reader) override;
std::string GetSourceOutputCode(const std::string& prefix) override;
size_t GetRawDataSize() const override;
ZResourceType GetResourceType() const override;
protected:
size_t arrayCnt;
std::string childName;
std::vector<ZResource*> resList;
};
+209
View File
@@ -0,0 +1,209 @@
#include "ZBackground.h"
#include "BitConverter.h"
#include "File.h"
#include "Globals.h"
#include "Path.h"
#include "StringHelper.h"
#include "ZFile.h"
REGISTER_ZFILENODE(Background, ZBackground);
#define JPEG_MARKER 0xFFD8FFE0
#define MARKER_DQT 0xFFDB
ZBackground::ZBackground(ZFile* nParent) : ZResource(nParent)
{
}
ZBackground::ZBackground(const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent)
: ZResource(nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
name = GetDefaultName(prefix.c_str(), rawDataIndex);
outName = name;
ParseRawData();
}
void ZBackground::ParseRawData()
{
ZResource::ParseRawData();
size_t i = 0;
while (true)
{
uint8_t val = rawData.at(rawDataIndex + i);
data.push_back(val);
if (BitConverter::ToUInt16BE(rawData, rawDataIndex + i) == 0xFFD9)
{
data.push_back(rawData.at(rawDataIndex + i + 1));
break;
}
i++;
}
}
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.
data.insert(data.end(), GetRawDataSize() - data.size(), 0x00);
CheckValidJpeg(filepath.generic_string());
}
void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar("", "");
}
void ZBackground::CheckValidJpeg(const std::string& filepath)
{
std::string filename = outName;
if (filepath != "")
{
filename = filepath;
}
uint32_t jpegMarker = BitConverter::ToUInt32BE(data, 0);
if (jpegMarker != JPEG_MARKER)
{
fprintf(stderr,
"ZBackground::CheckValidJpeg: Warning.\n"
"\t Missing jpeg marker at the beginning of file: '%s'.\n"
"\t The game will skip this jpeg.\n",
filename.c_str());
}
if (data.at(6) != 'J' || data.at(7) != 'F' || data.at(8) != 'I' || data.at(9) != 'F' ||
data.at(10) != '\0')
{
std::string jfifIdentifier(data.begin() + 6, data.begin() + 6 + 5);
fprintf(stderr,
"ZBackground::CheckValidJpeg: Warning.\n"
"\t Missing 'JFIF' identifier. File: '%s'.\n"
"\t This image may be corrupted or not be a jpeg iamge.\n"
"\t The identifier found was '%s'.\n",
filename.c_str(), jfifIdentifier.c_str());
}
uint8_t majorVersion = data.at(11);
uint8_t minorVersion = data.at(12);
if (majorVersion != 0x01 || minorVersion != 0x01)
{
fprintf(stderr,
"ZBackground::CheckValidJpeg: Warning.\n"
"\t Wrong JFIF version '%i.%02i'. File: '%s'.\n"
"\t The expected version is '1.01'. The game may not be able to decode this image "
"properly.\n",
majorVersion, minorVersion, filename.c_str());
}
if (BitConverter::ToUInt16BE(data, 20) != MARKER_DQT)
{
// This may happen when creating a custom image with Exif, XMP, thumbnail, progressive, etc.
// enabled.
fprintf(stderr,
"ZBackground::CheckValidJpeg: Warning.\n"
"\t There seems to be extra data before the image data in file: '%s'.\n"
"\t The game may not be able to decode this image properly.\n",
filename.c_str());
}
if (data.size() > GetRawDataSize())
{
fprintf(stderr,
"ZBackground::CheckValidJpeg: Warning.\n"
"\t The image is bigger than the screen buffer. File: '%s'.\n"
"\t Image size: %zu bytes.\n"
"\t Screen buffer size: %zu bytes.\n",
filename.c_str(), data.size(), 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) const
{
std::string auxName = name;
if (name == "")
auxName = GetDefaultName(prefix, rawDataIndex);
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
GetSourceTypeName(), auxName, "SCREEN_WIDTH * SCREEN_HEIGHT / 4",
bodyStr);
}
bool ZBackground::IsExternalResource() const
{
return true;
}
std::string ZBackground::GetExternalExtension() const
{
return "jpg";
}
void ZBackground::Save(const fs::path& outFolder)
{
fs::path filepath = outFolder / (outName + "." + GetExternalExtension());
File::WriteAllBytes(filepath.string(), data);
}
std::string ZBackground::GetBodySourceCode()
{
std::string bodyStr = " ";
for (size_t i = 0; i < data.size() / 8; ++i)
{
bodyStr += StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(data, i * 8));
if (i % 8 == 7)
bodyStr += "\n ";
}
bodyStr += "\n";
return bodyStr;
}
std::string ZBackground::GetSourceOutputCode(const std::string& prefix)
{
std::string bodyStr = GetBodySourceCode();
Declaration* decl = parent->GetDeclaration(rawDataIndex);
if (decl == nullptr)
DeclareVar(prefix, bodyStr);
else
decl->text = bodyStr;
return "";
}
std::string ZBackground::GetDefaultName(const std::string& prefix, uint32_t address)
{
return StringHelper::Sprintf("%sBackground_%06X", prefix.c_str(), address);
}
std::string ZBackground::GetSourceTypeName() const
{
return "u64";
}
ZResourceType ZBackground::GetResourceType() const
{
return ZResourceType::Background;
}
+36
View File
@@ -0,0 +1,36 @@
#pragma once
#include <cstdint>
#include <vector>
#include "ZResource.h"
class ZBackground : public ZResource
{
protected:
std::vector<uint8_t> data;
public:
ZBackground(ZFile* nParent);
ZBackground(const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent);
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) override;
void CheckValidJpeg(const std::string& filepath);
size_t GetRawDataSize() const 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() const override;
ZResourceType GetResourceType() const override;
};
+107
View File
@@ -0,0 +1,107 @@
#include "ZBlob.h"
#include "BitConverter.h"
#include "File.h"
#include "Path.h"
#include "StringHelper.h"
#include "ZFile.h"
using namespace tinyxml2;
REGISTER_ZFILENODE(Blob, ZBlob);
ZBlob::ZBlob(ZFile* nParent) : ZResource(nParent)
{
RegisterRequiredAttribute("Size");
}
// Build Source File Mode
ZBlob* ZBlob::BuildFromXML(XMLElement* reader, const std::string& inFolder, bool readFile)
{
ZBlob* blob = new ZBlob(nullptr);
blob->ParseXML(reader);
if (readFile)
blob->blobData = File::ReadAllBytes(inFolder + "/" + blob->name + ".bin");
return blob;
}
ZBlob* ZBlob::FromFile(const std::string& filePath)
{
ZBlob* blob = new ZBlob(nullptr);
blob->name = StringHelper::Split(Path::GetFileNameWithoutExtension(filePath), ".")[0];
blob->blobData = File::ReadAllBytes(filePath);
return blob;
}
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 < blobData.size(); i += 1)
{
if (i % 16 == 0)
sourceOutput += " ";
sourceOutput += StringHelper::Sprintf("0x%02X, ", blobData[i]);
if (i % 16 == 15)
sourceOutput += "\n";
}
// Ensure there's always a trailing line feed to prevent dumb warnings.
// Please don't remove this line, unless you somehow made a way to prevent
// that warning when building the OoT repo.
sourceOutput += "\n";
return sourceOutput;
}
std::string ZBlob::GetSourceOutputHeader(const std::string& prefix)
{
return StringHelper::Sprintf("extern u8 %s[];\n", name.c_str());
}
void ZBlob::Save(const fs::path& outFolder)
{
File::WriteAllBytes(outFolder / (name + ".bin"), blobData);
}
bool ZBlob::IsExternalResource() const
{
return true;
}
std::string ZBlob::GetExternalExtension() const
{
return "bin";
}
std::string ZBlob::GetSourceTypeName() const
{
return "u8";
}
ZResourceType ZBlob::GetResourceType() const
{
return ZResourceType::Blob;
}
size_t ZBlob::GetRawDataSize() const
{
return blobSize;
}
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include "ZResource.h"
#include "tinyxml2.h"
class ZBlob : public ZResource
{
public:
ZBlob(ZFile* nParent);
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 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;
};
+330
View File
@@ -0,0 +1,330 @@
#include "ZCollision.h"
#include <stdint.h>
#include <string>
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
REGISTER_ZFILENODE(Collision, ZCollisionHeader);
ZCollisionHeader::ZCollisionHeader(ZFile* nParent) : ZResource(nParent)
{
}
ZCollisionHeader::~ZCollisionHeader()
{
for (WaterBoxHeader* waterBox : waterBoxes)
delete waterBox;
delete camData;
}
void ZCollisionHeader::ParseRawData()
{
const uint8_t* data = rawData.data();
absMinX = BitConverter::ToInt16BE(data, rawDataIndex + 0);
absMinY = BitConverter::ToInt16BE(data, rawDataIndex + 2);
absMinZ = BitConverter::ToInt16BE(data, rawDataIndex + 4);
absMaxX = BitConverter::ToInt16BE(data, rawDataIndex + 6);
absMaxY = BitConverter::ToInt16BE(data, rawDataIndex + 8);
absMaxZ = BitConverter::ToInt16BE(data, rawDataIndex + 10);
numVerts = BitConverter::ToUInt16BE(data, rawDataIndex + 12);
vtxAddress = BitConverter::ToInt32BE(data, rawDataIndex + 16);
numPolygons = BitConverter::ToUInt16BE(data, rawDataIndex + 20);
polyAddress = BitConverter::ToInt32BE(data, rawDataIndex + 24);
polyTypeDefAddress = BitConverter::ToInt32BE(data, rawDataIndex + 28);
camDataAddress = BitConverter::ToInt32BE(data, rawDataIndex + 32);
numWaterBoxes = BitConverter::ToUInt16BE(data, rawDataIndex + 36);
waterBoxAddress = BitConverter::ToInt32BE(data, rawDataIndex + 40);
vtxSegmentOffset = Seg2Filespace(vtxAddress, parent->baseAddress);
polySegmentOffset = Seg2Filespace(polyAddress, parent->baseAddress);
polyTypeDefSegmentOffset = Seg2Filespace(polyTypeDefAddress, parent->baseAddress);
camDataSegmentOffset = Seg2Filespace(camDataAddress, parent->baseAddress);
waterBoxSegmentOffset = Seg2Filespace(waterBoxAddress, parent->baseAddress);
vertices.reserve(numVerts);
polygons.reserve(numPolygons);
for (uint16_t i = 0; i < numVerts; i++)
vertices.push_back(VertexEntry(rawData, vtxSegmentOffset + (i * 6)));
for (uint16_t i = 0; i < numPolygons; i++)
polygons.push_back(PolygonEntry(rawData, polySegmentOffset + (i * 16)));
uint16_t highestPolyType = 0;
for (PolygonEntry poly : polygons)
{
if (poly.type > highestPolyType)
highestPolyType = poly.type;
}
for (uint16_t i = 0; i < highestPolyType + 1; i++)
polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8)));
if (camDataAddress != 0)
camData = new CameraDataList(parent, name, rawData, camDataSegmentOffset,
polyTypeDefSegmentOffset, polygonTypes.size());
for (uint16_t i = 0; i < numWaterBoxes; i++)
waterBoxes.push_back(new WaterBoxHeader(
rawData,
waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16))));
std::string declaration = "";
if (waterBoxes.size() > 0)
{
for (size_t i = 0; i < waterBoxes.size(); i++)
{
declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %i, 0x%08X },",
waterBoxes[i]->xMin, waterBoxes[i]->ySurface,
waterBoxes[i]->zMin, waterBoxes[i]->xLength,
waterBoxes[i]->zLength, waterBoxes[i]->properties);
if (i + 1 < waterBoxes.size())
declaration += "\n";
}
}
if (waterBoxAddress != 0)
parent->AddDeclarationArray(
waterBoxSegmentOffset, DeclarationAlignment::None, 16 * waterBoxes.size(), "WaterBox",
StringHelper::Sprintf("%s_waterBoxes_%06X", name.c_str(), waterBoxSegmentOffset), 0,
declaration);
if (polygons.size() > 0)
{
declaration = "";
for (size_t i = 0; i < polygons.size(); i++)
{
declaration += StringHelper::Sprintf(
"\t{ 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },",
polygons[i].type, polygons[i].vtxA, polygons[i].vtxB, polygons[i].vtxC,
polygons[i].a, polygons[i].b, polygons[i].c, polygons[i].d);
if (i + 1 < polygons.size())
declaration += "\n";
}
if (polyAddress != 0)
{
parent->AddDeclarationArray(
polySegmentOffset, DeclarationAlignment::None, polygons.size() * 16,
"CollisionPoly",
StringHelper::Sprintf("%s_polygons_%08X", name.c_str(), polySegmentOffset), 0,
declaration);
}
}
declaration = "";
for (size_t i = 0; i < polygonTypes.size(); i++)
{
declaration += StringHelper::Sprintf("\t{ 0x%08lX, 0x%08lX },", polygonTypes[i] >> 32,
polygonTypes[i] & 0xFFFFFFFF);
if (i < polygonTypes.size() - 1)
declaration += "\n";
}
if (polyTypeDefAddress != 0)
parent->AddDeclarationArray(
polyTypeDefSegmentOffset, DeclarationAlignment::None, polygonTypes.size() * 8,
"SurfaceType",
StringHelper::Sprintf("%s_surfaceType_%08X", name.c_str(), polyTypeDefSegmentOffset), 0,
declaration);
declaration = "";
if (vertices.size() > 0)
{
declaration = "";
for (size_t i = 0; i < vertices.size(); i++)
{
declaration += StringHelper::Sprintf("\t{ %6i, %6i, %6i },", vertices[i].x,
vertices[i].y, vertices[i].z);
if (i < vertices.size() - 1)
declaration += "\n";
}
if (vtxAddress != 0)
parent->AddDeclarationArray(
vtxSegmentOffset, DeclarationAlignment::None, vertices.size() * 6, "Vec3s",
StringHelper::Sprintf("%s_vtx_%08X", name.c_str(), vtxSegmentOffset), 0,
declaration);
declaration = "";
}
declaration = "";
char waterBoxStr[2048];
if (waterBoxAddress != 0)
sprintf(waterBoxStr, "%s_waterBoxes_%06X", name.c_str(), waterBoxSegmentOffset);
else
sprintf(waterBoxStr, "NULL");
declaration += "\n";
declaration += StringHelper::Sprintf(" { %i, %i, %i },\n { %i, %i, %i },\n", absMinX,
absMinY, absMinZ, absMaxX, absMaxY, absMaxZ);
declaration += StringHelper::Sprintf(
" %i,\n %s_vtx_%08X,\n %i,\n %s_polygons_%08X,\n %s_surfaceType_%08X,\n "
"%s_camDataList_%08X,\n %i,\n %s\n",
numVerts, name.c_str(), vtxSegmentOffset, numPolygons, name.c_str(), polySegmentOffset,
name.c_str(), polyTypeDefSegmentOffset, name.c_str(), camDataSegmentOffset, numWaterBoxes,
waterBoxStr);
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();
type = BitConverter::ToUInt16BE(data, rawDataIndex + 0);
vtxA = BitConverter::ToUInt16BE(data, rawDataIndex + 2);
vtxB = BitConverter::ToUInt16BE(data, rawDataIndex + 4);
vtxC = BitConverter::ToUInt16BE(data, rawDataIndex + 6);
a = BitConverter::ToUInt16BE(data, rawDataIndex + 8);
b = BitConverter::ToUInt16BE(data, rawDataIndex + 10);
c = BitConverter::ToUInt16BE(data, rawDataIndex + 12);
d = BitConverter::ToUInt16BE(data, rawDataIndex + 14);
}
VertexEntry::VertexEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
x = BitConverter::ToInt16BE(data, rawDataIndex + 0);
y = BitConverter::ToInt16BE(data, rawDataIndex + 2);
z = BitConverter::ToInt16BE(data, rawDataIndex + 4);
}
WaterBoxHeader::WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
xMin = BitConverter::ToInt16BE(data, rawDataIndex + 0);
ySurface = BitConverter::ToInt16BE(data, rawDataIndex + 2);
zMin = BitConverter::ToInt16BE(data, rawDataIndex + 4);
xLength = BitConverter::ToInt16BE(data, rawDataIndex + 6);
zLength = BitConverter::ToInt16BE(data, rawDataIndex + 8);
if (Globals::Instance->game == ZGame::OOT_SW97)
properties = BitConverter::ToInt16BE(data, rawDataIndex + 10);
else
properties = BitConverter::ToInt32BE(data, rawDataIndex + 12);
}
CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
uint32_t polyTypeDefSegmentOffset, uint32_t polygonTypesCnt)
{
std::string declaration = "";
// Parse CameraDataEntries
int32_t numElements = (polyTypeDefSegmentOffset - rawDataIndex) / 8;
uint32_t cameraPosDataSeg = rawDataIndex;
for (int32_t i = 0; i < numElements; i++)
{
CameraDataEntry* entry = new CameraDataEntry();
entry->cameraSType =
BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 0);
entry->numData = BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 2);
entry->cameraPosDataSeg =
BitConverter::ToInt32BE(rawData, rawDataIndex + (entries.size() * 8) + 4);
if (entry->cameraPosDataSeg != 0 && GETSEGNUM(entry->cameraPosDataSeg) != 2)
{
cameraPosDataSeg = rawDataIndex + (entries.size() * 8);
break;
}
if (entry->cameraPosDataSeg != 0 && cameraPosDataSeg > (entry->cameraPosDataSeg & 0xFFFFFF))
cameraPosDataSeg = (entry->cameraPosDataSeg & 0xFFFFFF);
entries.push_back(entry);
}
// Setting cameraPosDataAddr to rawDataIndex give a pos list length of 0
uint32_t cameraPosDataOffset = cameraPosDataSeg & 0xFFFFFF;
for (size_t i = 0; i < entries.size(); i++)
{
char camSegLine[2048];
if (entries[i]->cameraPosDataSeg != 0)
{
int32_t index =
((entries[i]->cameraPosDataSeg & 0x00FFFFFF) - cameraPosDataOffset) / 0x6;
sprintf(camSegLine, "&%s_camPosData_%08X[%i]", prefix.c_str(), cameraPosDataOffset,
index);
}
else
sprintf(camSegLine, "NULL");
declaration +=
StringHelper::Sprintf(" { 0x%04X, %i, %s },", entries[i]->cameraSType,
entries[i]->numData, camSegLine, rawDataIndex + (i * 8));
if (i < entries.size() - 1)
declaration += "\n";
}
parent->AddDeclarationArray(
rawDataIndex, DeclarationAlignment::None, entries.size() * 8, "CamData",
StringHelper::Sprintf("%s_camDataList_%08X", prefix.c_str(), rawDataIndex), entries.size(),
declaration);
uint32_t numDataTotal = (rawDataIndex - cameraPosDataOffset) / 0x6;
if (numDataTotal > 0)
{
declaration = "";
for (uint32_t i = 0; i < numDataTotal; i++)
{
CameraPositionData* data =
new CameraPositionData(rawData, cameraPosDataOffset + (i * 6));
cameraPositionData.push_back(data);
declaration += StringHelper::Sprintf("\t{ %6i, %6i, %6i },", data->x, data->y, data->z);
if (i + 1 < numDataTotal)
declaration += "\n";
}
int32_t cameraPosDataIndex = GETSEGOFFSET(cameraPosDataSeg);
uint32_t entrySize = numDataTotal * 0x6;
parent->AddDeclarationArray(
cameraPosDataIndex, DeclarationAlignment::None, entrySize, "Vec3s",
StringHelper::Sprintf("%s_camPosData_%08X", prefix.c_str(), cameraPosDataIndex),
numDataTotal, declaration);
}
}
CameraPositionData::CameraPositionData(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
y = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
z = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
+98
View File
@@ -0,0 +1,98 @@
#pragma once
#include "ZFile.h"
#include "ZResource.h"
#include "ZRoom/ZRoom.h"
class PolygonEntry
{
public:
uint16_t type;
uint16_t vtxA, vtxB, vtxC;
uint16_t a, b, c, d;
PolygonEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class VertexEntry
{
public:
int16_t x, y, z;
VertexEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class WaterBoxHeader
{
public:
int16_t xMin;
int16_t ySurface;
int16_t zMin;
int16_t xLength;
int16_t zLength;
int16_t pad;
int32_t properties;
WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CameraPositionData
{
public:
int16_t x, y, z;
CameraPositionData(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CameraDataEntry
{
public:
int16_t cameraSType;
int16_t numData;
int32_t cameraPosDataSeg;
};
class CameraDataList
{
public:
std::vector<CameraDataEntry*> entries;
std::vector<CameraPositionData*> cameraPositionData;
CameraDataList(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex, uint32_t polyTypeDefSegmentOffset,
uint32_t polygonTypesCnt);
};
class ZCollisionHeader : public ZResource
{
public:
int16_t absMinX, absMinY, absMinZ;
int16_t absMaxX, absMaxY, absMaxZ;
uint16_t numVerts;
segptr_t vtxAddress;
uint16_t numPolygons;
segptr_t polyAddress;
segptr_t polyTypeDefAddress;
segptr_t camDataAddress;
int32_t numWaterBoxes;
segptr_t waterBoxAddress;
uint32_t vtxSegmentOffset, polySegmentOffset, polyTypeDefSegmentOffset, camDataSegmentOffset,
waterBoxSegmentOffset;
std::vector<VertexEntry> vertices;
std::vector<PolygonEntry> polygons;
std::vector<uint64_t> polygonTypes;
std::vector<WaterBoxHeader*> waterBoxes;
CameraDataList* camData;
ZCollisionHeader(ZFile* nParent);
~ZCollisionHeader();
void ParseRawData() override;
ZResourceType GetResourceType() const override;
size_t GetRawDataSize() const override;
};
File diff suppressed because it is too large Load Diff
+444
View File
@@ -0,0 +1,444 @@
#pragma once
#include <stdint.h>
#include <string>
#include <vector>
#include "ZFile.h"
#include "ZResource.h"
#include "tinyxml2.h"
enum class CutsceneCommands
{
Cmd00 = 0x0000,
SetCameraPos = 0x0001,
SetCameraFocus = 0x0002,
SpecialAction = 0x0003,
SetLighting = 0x0004,
SetCameraPosLink = 0x0005,
SetCameraFocusLink = 0x0006,
Cmd07 = 0x0007,
Cmd08 = 0x0008,
Cmd09 = 0x0009,
Unknown = 0x001A,
Textbox = 0x0013,
SetActorAction0 = 0x000A,
SetActorAction1 = 0x000F,
SetActorAction2 = 0x000E,
SetActorAction3 = 0x0019,
SetActorAction4 = 0x001D,
SetActorAction5 = 0x001E,
SetActorAction6 = 0x002C,
SetActorAction7 = 0x001F,
SetActorAction8 = 0x0031,
SetActorAction9 = 0x003E,
SetActorAction10 = 0x008F,
SetSceneTransFX = 0x002D,
Nop = 0x000B,
PlayBGM = 0x0056,
StopBGM = 0x0057,
FadeBGM = 0x007C,
SetTime = 0x008C,
Terminator = 0x03E8,
End = 0xFFFF,
Error = 0xFEAF,
};
class CutsceneCameraPoint
{
public:
int8_t continueFlag;
int8_t cameraRoll;
int16_t nextPointFrame;
uint32_t viewAngle;
int16_t posX, posY, posZ;
int16_t unused;
CutsceneCameraPoint(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommand
{
public:
uint32_t commandID;
uint32_t commandIndex;
virtual ~CutsceneCommand();
CutsceneCommand(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
virtual std::string GetCName();
virtual std::string GenerateSourceCode(uint32_t baseAddress);
virtual size_t GetCommandSize();
};
class CutsceneCommandSetCameraPos : public CutsceneCommand
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
uint16_t unused;
std::vector<CutsceneCameraPoint*> entries;
~CutsceneCommandSetCameraPos();
CutsceneCommandSetCameraPos(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class SpecialActionEntry
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
uint16_t unused0;
uint32_t unused1;
uint32_t unused2;
uint32_t unused3;
uint32_t unused4;
uint32_t unused5;
uint32_t unused6;
uint32_t unused7;
uint32_t unused8;
uint32_t unused9;
uint32_t unused10;
SpecialActionEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommandSpecialAction : public CutsceneCommand
{
public:
std::vector<SpecialActionEntry*> entries;
CutsceneCommandSpecialAction(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandSpecialAction();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class MusicFadeEntry
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
uint16_t unknown0;
uint32_t unknown1;
uint32_t unknown2;
uint32_t unknown3;
uint32_t unknown4;
uint32_t unknown5;
uint32_t unknown6;
uint32_t unknown7;
uint32_t unknown8;
uint32_t unknown9;
uint32_t unknown10;
MusicFadeEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommandFadeBGM : public CutsceneCommand
{
public:
std::vector<MusicFadeEntry*> entries;
CutsceneCommandFadeBGM(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandFadeBGM();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class MusicChangeEntry
{
public:
uint16_t sequence;
uint16_t startFrame;
uint16_t endFrame;
uint16_t unknown0;
uint32_t unknown1;
uint32_t unknown2;
uint32_t unknown3;
uint32_t unknown4;
uint32_t unknown5;
uint32_t unknown6;
uint32_t unknown7;
MusicChangeEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommandPlayBGM : public CutsceneCommand
{
public:
std::vector<MusicChangeEntry*> entries;
CutsceneCommandPlayBGM(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandPlayBGM();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class CutsceneCommandStopBGM : public CutsceneCommand
{
public:
std::vector<MusicChangeEntry*> entries;
CutsceneCommandStopBGM(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandStopBGM();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class EnvLightingEntry
{
public:
uint16_t setting;
uint16_t startFrame;
uint16_t endFrame;
uint16_t unused0;
uint32_t unused1;
uint32_t unused2;
uint32_t unused3;
uint32_t unused4;
uint32_t unused5;
uint32_t unused6;
uint32_t unused7;
EnvLightingEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommandEnvLighting : public CutsceneCommand
{
public:
std::vector<EnvLightingEntry*> entries;
CutsceneCommandEnvLighting(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandEnvLighting();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class CutsceneCommandSceneTransFX : public CutsceneCommand
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
~CutsceneCommandSceneTransFX();
CutsceneCommandSceneTransFX(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class Unknown9Entry
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
uint16_t unk2;
uint16_t unk3;
uint16_t unk4;
uint8_t unused0;
uint8_t unused1;
Unknown9Entry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommandUnknown9 : public CutsceneCommand
{
public:
std::vector<Unknown9Entry*> entries;
CutsceneCommandUnknown9(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandUnknown9();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class UnkEntry
{
public:
uint32_t unused0;
uint32_t unused1;
uint32_t unused2;
uint32_t unused3;
uint32_t unused4;
uint32_t unused5;
uint32_t unused6;
uint32_t unused7;
uint32_t unused8;
uint32_t unused9;
uint32_t unused10;
uint32_t unused11;
UnkEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommandUnknown : public CutsceneCommand
{
public:
std::vector<UnkEntry*> entries;
CutsceneCommandUnknown(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandUnknown();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class DayTimeEntry
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
uint8_t hour;
uint8_t minute;
uint8_t unused;
DayTimeEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommandDayTime : public CutsceneCommand
{
public:
std::vector<DayTimeEntry*> entries;
CutsceneCommandDayTime(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandDayTime();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class TextboxEntry
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
uint16_t type;
uint16_t textID1;
uint16_t textID2;
TextboxEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommandTextbox : public CutsceneCommand
{
public:
std::vector<TextboxEntry*> entries;
CutsceneCommandTextbox(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandTextbox();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class ActorAction
{
public:
uint16_t action;
uint16_t startFrame;
uint16_t endFrame;
int16_t rotX, rotY, rotZ;
int32_t startPosX, startPosY, startPosZ;
int32_t endPosX, endPosY, endPosZ;
int32_t normalX, normalY, normalZ;
ActorAction(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
};
class CutsceneCommandActorAction : public CutsceneCommand
{
public:
std::vector<ActorAction*> entries;
CutsceneCommandActorAction(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
~CutsceneCommandActorAction();
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class CutsceneCommandTerminator : public CutsceneCommand
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
uint16_t unknown;
CutsceneCommandTerminator(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class CutsceneCommandEnd : public CutsceneCommand
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
CutsceneCommandEnd(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetCName();
std::string GenerateSourceCode(uint32_t baseAddress);
size_t GetCommandSize();
};
class CutsceneCommandNop : public CutsceneCommand
{
public:
uint16_t base;
uint16_t startFrame;
uint16_t endFrame;
CutsceneCommandNop(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetCName();
size_t GetCommandSize();
};
class ZCutsceneBase : public ZResource
{
public:
ZCutsceneBase(ZFile* nParent);
virtual std::string GetBodySourceCode() = 0;
virtual void DeclareVar(const std::string& prefix, const std::string& bodyStr) const = 0;
virtual uint32_t getSegmentOffset() const = 0;
};
class ZCutscene : public ZCutsceneBase
{
public:
ZCutscene(ZFile* nParent);
~ZCutscene();
void ParseRawData() 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) override;
protected:
int32_t numCommands;
int32_t endFrame;
std::vector<CutsceneCommand*> commands;
};
+92
View File
@@ -0,0 +1,92 @@
#include "ZCutsceneMM.h"
#include "BitConverter.h"
#include "StringHelper.h"
ZCutsceneMM::ZCutsceneMM(ZFile* nParent) : ZCutsceneBase(nParent)
{
}
ZCutsceneMM::~ZCutsceneMM()
{
for (CutsceneCommand* cmd : commands)
delete cmd;
}
std::string ZCutsceneMM::GetBodySourceCode()
{
std::string output = "";
output += StringHelper::Sprintf(" CS_BEGIN_CUTSCENE(%i, %i),", numCommands, endFrame);
for (size_t i = 0; i < data.size(); i++)
{
if ((i % 4) == 0)
output += "\n ";
output += StringHelper::Sprintf("0x%08X,", data[i]);
}
return output;
}
std::string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
{
std::string bodyStr = GetBodySourceCode();
Declaration* decl = parent->GetDeclaration(rawDataIndex);
if (decl == nullptr)
DeclareVar(prefix, bodyStr);
else
decl->text = bodyStr;
return "";
}
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);
parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4, GetRawDataSize(),
"s32", auxName, 0, bodyStr);
}
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)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar(parent->GetName(), "");
}
void ZCutsceneMM::ParseRawData()
{
segmentOffset = rawDataIndex;
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
commands = std::vector<CutsceneCommand*>();
endFrame = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
uint32_t currentPtr = rawDataIndex + 8;
uint32_t lastData = 0;
// TODO currently cutscenes aren't being parsed, so just consume words until we see an end
// marker.
do
{
lastData = BitConverter::ToInt32BE(rawData, currentPtr);
data.push_back(lastData);
currentPtr += 4;
} while (lastData != 0xFFFFFFFF);
}
ZResourceType ZCutsceneMM::GetResourceType() const
{
return ZResourceType::Cutscene;
}
+36
View File
@@ -0,0 +1,36 @@
#pragma once
#include <stdint.h>
#include <string>
#include <vector>
#include "ZCutscene.h"
#include "ZFile.h"
#include "tinyxml2.h"
class ZCutsceneMM : public ZCutsceneBase
{
public:
uint32_t segmentOffset;
ZCutsceneMM(ZFile* nParent);
virtual ~ZCutsceneMM();
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;
uint32_t getSegmentOffset() const override { return segmentOffset; }
void ParseRawData() override;
ZResourceType GetResourceType() const override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex) override;
protected:
int32_t numCommands;
int32_t endFrame;
std::vector<CutsceneCommand*> commands;
std::vector<uint32_t> data;
};
File diff suppressed because it is too large Load Diff
+388
View File
@@ -0,0 +1,388 @@
#pragma once
#include "ZMtx.h"
#include "ZResource.h"
#include "ZRoom/ZRoom.h"
#include "ZTexture.h"
#include "ZVtx.h"
#include "tinyxml2.h"
#include <map>
#include <string>
#include <vector>
enum class F3DEXOpcode
{
G_SPNOOP = 0x00,
G_MTX = 0x01,
G_MOVEMEM = 0x03,
G_VTX = 0x04,
G_DL = 0x06,
G_LOAD_UCODE = 0xAF,
G_BRANCH_Z = 0xB0,
G_TRI2 = 0xB1,
G_MODIFYVTX = 0xB2,
G_RDPHALF_2 = 0xB3,
G_RDPHALF_1 = 0xB4,
G_QUAD = 0xB5,
G_CLEARGEOMETRYMODE = 0xB6,
G_SETGEOMETRYMODE = 0xB7,
G_ENDDL = 0xB8,
G_SETOTHERMODE_L = 0xB9,
G_SETOTHERMODE_H = 0xBA,
G_TEXTURE = 0xBB,
G_MOVEWORD = 0xBC,
G_POPMTX = 0xBD,
G_CULLDL = 0xBE,
G_TRI1 = 0xBF,
G_NOOP = 0xC0,
G_TEXRECT = 0xE4,
G_TEXRECTFLIP = 0xE5,
G_RDPLOADSYNC = 0xE6,
G_RDPPIPESYNC = 0xE7,
G_RDPTILESYNC = 0xE8,
G_RDPFULLSYNC = 0xE9,
G_SETKEYGB = 0xEA,
G_SETKEYR = 0xEB,
G_SETCONVERT = 0xEC,
G_SETSCISSOR = 0xED,
G_SETPRIMDEPTH = 0xEE,
G_RDPSETOTHERMODE = 0xEF,
G_LOADTLUT = 0xF0,
G_SETTILESIZE = 0xF2,
G_LOADBLOCK = 0xF3,
G_LOADTILE = 0xF4,
G_SETTILE = 0xF5,
G_FILLRECT = 0xF6,
G_SETFILLCOLOR = 0xF7,
G_SETFOGCOLOR = 0xF8,
G_SETBLENDCOLOR = 0xF9,
G_SETPRIMCOLOR = 0xFA,
G_SETENVCOLOR = 0xFB,
G_SETCOMBINE = 0xFC,
G_SETTIMG = 0xFD,
G_SETZIMG = 0xFE,
G_SETCIMG = 0xFF
};
enum class F3DZEXOpcode
{
G_NOOP = 0x00,
G_VTX = 0x01,
G_MODIFYVTX = 0x02,
G_CULLDL = 0x03,
G_BRANCH_Z = 0x04,
G_TRI1 = 0x05,
G_TRI2 = 0x06,
G_QUAD = 0x07,
G_SPECIAL_3 = 0xD3,
G_SPECIAL_2 = 0xD4,
G_SPECIAL_1 = 0xD5,
G_DMA_IO = 0xD6,
G_TEXTURE = 0xD7,
G_POPMTX = 0xD8,
G_GEOMETRYMODE = 0xD9,
G_MTX = 0xDA,
G_MOVEWORD = 0xDB,
G_MOVEMEM = 0xDC,
G_LOAD_UCODE = 0xDD,
G_DL = 0xDE,
G_ENDDL = 0xDF,
G_SPNOOP = 0xE0,
G_RDPHALF_1 = 0xE1,
G_SETOTHERMODE_L = 0xE2,
G_SETOTHERMODE_H = 0xE3,
G_TEXRECT = 0xE4,
G_TEXRECTFLIP = 0xE5,
G_RDPLOADSYNC = 0xE6,
G_RDPPIPESYNC = 0xE7,
G_RDPTILESYNC = 0xE8,
G_RDPFULLSYNC = 0xE9,
G_SETKEYGB = 0xEA,
G_SETKEYR = 0xEB,
G_SETCONVERT = 0xEC,
G_SETSCISSOR = 0xED,
G_SETPRIMDEPTH = 0xEE,
G_RDPSETOTHERMODE = 0xEF,
G_LOADTLUT = 0xF0,
G_RDPHALF_2 = 0xF1,
G_SETTILESIZE = 0xF2,
G_LOADBLOCK = 0xF3,
G_LOADTILE = 0xF4,
G_SETTILE = 0xF5,
G_FILLRECT = 0xF6,
G_SETFILLCOLOR = 0xF7,
G_SETFOGCOLOR = 0xF8,
G_SETBLENDCOLOR = 0xF9,
G_SETPRIMCOLOR = 0xFA,
G_SETENVCOLOR = 0xFB,
G_SETCOMBINE = 0xFC,
G_SETTIMG = 0xFD,
G_SETZIMG = 0xFE,
G_SETCIMG = 0xFF,
};
enum class F3DZEXTexFormats
{
G_IM_FMT_RGBA,
G_IM_FMT_YUV,
G_IM_FMT_CI,
G_IM_FMT_IA,
G_IM_FMT_I
};
enum class F3DZEXTexSizes
{
G_IM_SIZ_4b,
G_IM_SIZ_8b,
G_IM_SIZ_16b,
G_IM_SIZ_32b
};
enum class DListType
{
F3DZEX,
F3DEX,
};
enum class OoTSegments
{
DirectReference = 0,
TitleStatic = 1,
Scene = 2,
Room = 3,
GameplayKeep = 4,
FieldDungeonKeep = 5,
Object = 6,
LinkAnimation = 7,
IconItemStatic = 8,
IconItem24Static = 9,
Unknown10 = 10,
Unknown11 = 11,
Unknown12 = 12,
IconFieldDungeonStatic = 13,
IconItemLanguageStatic = 14,
ZBuffer = 15,
FrameBuffer = 16,
};
#define G_MDSFT_ALPHACOMPARE 0
#define G_MDSFT_ZSRCSEL 2
#define G_MDSFT_RENDERMODE 3
#define G_MDSFT_BLENDER 16
#define G_RM_FOG_SHADE_A 0xC8000000
#define G_RM_FOG_PRIM_A 0xC4000000
#define G_RM_PASS 0x0C080000
#define G_RM_AA_ZB_OPA_SURF 0x442078
#define G_RM_AA_ZB_OPA_SURF2 0x112078
#define G_RM_AA_ZB_XLU_SURF 0x4049D8
#define G_RM_AA_ZB_XLU_SURF2 0x1049D8
#define G_RM_AA_ZB_OPA_DECAL 0x442D58
#define G_RM_AA_ZB_OPA_DECAL2 0x112D58
#define G_RM_AA_ZB_XLU_DECAL 0x404DD8
#define G_RM_AA_ZB_XLU_DECAL2 0x104DD8
#define G_RM_AA_ZB_OPA_INTER 0x442478
#define G_RM_AA_ZB_OPA_INTER2 0x112478
#define G_RM_AA_ZB_XLU_INTER 0x4045D8
#define G_RM_AA_ZB_XLU_INTER2 0x1045D8
#define G_RM_AA_ZB_XLU_LINE 0x407858
#define G_RM_AA_ZB_XLU_LINE2 0x107858
#define G_RM_AA_ZB_DEC_LINE 0x407F58
#define G_RM_AA_ZB_DEC_LINE2 0x107F58
#define G_RM_AA_ZB_TEX_EDGE 0x443078
#define G_RM_AA_ZB_TEX_EDGE2 0x113078
#define G_RM_AA_ZB_TEX_INTER 0x443478
#define G_RM_AA_ZB_TEX_INTER2 0x113478
#define G_RM_AA_ZB_SUB_SURF 0x442878
#define G_RM_AA_ZB_SUB_SURF2 0x112278
#define G_RM_AA_ZB_PCL_SURF 0x40007B
#define G_RM_AA_ZB_PCL_SURF2 0x10007B
#define G_RM_AA_ZB_OPA_TERR 0x402078
#define G_RM_AA_ZB_OPA_TERR2 0x102078
#define G_RM_AA_ZB_TEX_TERR 0x403078
#define G_RM_AA_ZB_TEX_TERR2 0x103078
#define G_RM_AA_ZB_SUB_TERR 0x402278
#define G_RM_AA_ZB_SUB_TERR2 0x102278
#define G_RM_RA_ZB_OPA_SURF 0x442038
#define G_RM_RA_ZB_OPA_SURF2 0x112038
#define G_RM_RA_ZB_OPA_DECAL 0x442D18
#define G_RM_RA_ZB_OPA_DECAL2 0x112D18
#define G_RM_RA_ZB_OPA_INTER 0x442438
#define G_RM_RA_ZB_OPA_INTER2 0x112438
#define G_RM_AA_OPA_SURF 0x442048
#define G_RM_AA_OPA_SURF2 0x112048
#define G_RM_AA_XLU_SURF 0x4041C8
#define G_RM_AA_XLU_SURF2 0x1041C8
#define G_RM_AA_XLU_LINE 0x407048
#define G_RM_AA_XLU_LINE2 0x107048
#define G_RM_AA_DEC_LINE 0x407248
#define G_RM_AA_DEC_LINE2 0x107248
#define G_RM_AA_TEX_EDGE 0x443048
#define G_RM_AA_TEX_EDGE2 0x113048
#define G_RM_AA_SUB_SURF 0x442248
#define G_RM_AA_SUB_SURF2 0x112248
#define G_RM_AA_PCL_SURF 0x40004B
#define G_RM_AA_PCL_SURF2 0x10004B
#define G_RM_AA_OPA_TERR 0x402048
#define G_RM_AA_OPA_TERR2 0x102048
#define G_RM_AA_TEX_TERR 0x403048
#define G_RM_AA_TEX_TERR2 0x103048
#define G_RM_AA_SUB_TERR 0x402248
#define G_RM_AA_SUB_TERR2 0x102248
#define G_RM_RA_OPA_SURF 0x442008
#define G_RM_RA_OPA_SURF2 0x112008
#define G_RM_ZB_OPA_SURF 0x442230
#define G_RM_ZB_OPA_SURF2 0x112230
#define G_RM_ZB_XLU_SURF 0x404A50
#define G_RM_ZB_XLU_SURF2 0x104A50
#define G_RM_ZB_OPA_DECAL 0x442E10
#define G_RM_ZB_OPA_DECAL2 0x112E10
#define G_RM_ZB_XLU_DECAL 0x404E50
#define G_RM_ZB_XLU_DECAL2 0x104E50
#define G_RM_ZB_CLD_SURF 0x404B50
#define G_RM_ZB_CLD_SURF2 0x104B50
#define G_RM_ZB_OVL_SURF 0x404F50
#define G_RM_ZB_OVL_SURF2 0x104F50
#define G_RM_ZB_PCL_SURF 0x0C080233
#define G_RM_ZB_PCL_SURF2 0x03020233
#define G_RM_OPA_SURF 0x0C084000
#define G_RM_OPA_SURF2 0x03024000
#define G_RM_XLU_SURF 0x00404200
#define G_RM_XLU_SURF2 0x00104240
#define G_RM_CLD_SURF 0x00404340
#define G_RM_CLD_SURF2 0x00104340
#define G_RM_TEX_EDGE 0x0C087008
#define G_RM_TEX_EDGE2 0x03027008
#define G_RM_PCL_SURF 0x0C084203
#define G_RM_PCL_SURF2 0x03024203
#define G_RM_ADD 0x04484340
#define G_RM_ADD2 0x01124340
#define G_RM_NOOP 0x00000000
#define G_RM_NOOP2 0x00000000
#define G_RM_VISCVG 0x0C844040
#define G_RM_VISCVG2 0x03214040
#define G_RM_OPA_CI 0x0C080000
#define G_RM_OPA_CI2 0x03020000
#define AA_EN 0x8
#define Z_CMP 0x10
#define Z_UPD 0x20
#define IM_RD 0x40
#define CLR_ON_CVG 0x80
#define CVG_DST_CLAMP 0
#define CVG_DST_WRAP 0x100
#define CVG_DST_FULL 0x200
#define CVG_DST_SAVE 0x300
#define ZMODE_OPA 0
#define ZMODE_INTER 0x400
#define ZMODE_XLU 0x800
#define ZMODE_DEC 0xc00
#define CVG_X_ALPHA 0x1000
#define ALPHA_CVG_SEL 0x2000
#define FORCE_BL 0x4000
#define TEX_EDGE 0x0000
class ZDisplayList : public ZResource
{
protected:
static TextureType TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSizes siz);
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);
// Various Instruction Optimizations
bool SequenceCheck(std::vector<F3DZEXOpcode> sequence, int32_t startIndex);
int32_t OptimizationChecks(int32_t startIndex, std::string& output, std::string prefix);
int32_t OptimizationCheck_LoadTextureBlock(int32_t startIndex, std::string& output,
std::string prefix);
// int32_t OptimizationCheck_LoadMultiBlock(int32_t startIndex, std::string& output, std::string
// prefix);
// F3DEX Specific Opcode Values
void Opcode_F3DEX_G_SETOTHERMODE_L(uint64_t data, char* line);
// Shared Opcodes between F3DZEX and F3DEX
void Opcode_G_DL(uint64_t data, std::string prefix, char* line);
void Opcode_G_MODIFYVTX(uint64_t data, char* line);
void Opcode_G_CULLDL(uint64_t data, char* line);
void Opcode_G_TRI1(uint64_t data, char* line);
void Opcode_G_TRI2(uint64_t data, char* line);
void Opcode_G_MTX(uint64_t data, char* line);
void Opcode_G_VTX(uint64_t data, char* line);
void Opcode_G_TEXTURE(uint64_t data, char* line);
void Opcode_G_SETTIMG(uint64_t data, std::string prefix, char* line);
void Opcode_G_SETTILE(uint64_t data, char* line);
void Opcode_G_SETTILESIZE(uint64_t data, std::string prefix, char* line);
void Opcode_G_LOADBLOCK(uint64_t data, char* line);
void Opcode_G_SETCOMBINE(uint64_t data, char* line);
void Opcode_G_SETPRIMCOLOR(uint64_t data, char* line);
void Opcode_G_SETOTHERMODE_L(uint64_t data, char* line);
void Opcode_G_SETOTHERMODE_H(uint64_t data, char* line);
void Opcode_G_LOADTLUT(uint64_t data, std::string prefix, char* line);
void Opcode_G_ENDDL(std::string prefix, char* line);
public:
std::string sceneSegName;
ZRoom* scene;
std::vector<uint64_t> instructions;
std::string curPrefix;
int32_t lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg;
F3DZEXTexFormats lastTexFmt;
F3DZEXTexSizes lastTexSiz, lastTexSizTest, lastCISiz;
bool lastTexLoaded;
bool lastTexIsPalette;
DListType dListType;
std::map<uint32_t, std::vector<ZVtx>> vertices;
std::map<uint32_t, std::string> vtxDeclarations;
std::vector<ZDisplayList*> otherDLists;
ZTexture* lastTexture = nullptr;
ZTexture* lastTlut = nullptr;
std::vector<uint32_t> references;
std::string defines; // Hack for special cases where vertex arrays intersect...
std::vector<uint8_t> fileData;
std::vector<ZMtx> mtxList;
ZDisplayList(ZFile* nParent);
ZDisplayList(std::vector<uint8_t> nRawData, uint32_t rawDataIndex, int32_t rawDataSize,
ZFile* nParent);
~ZDisplayList();
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
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, 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() 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);
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile) override;
bool IsExternalResource() const override;
virtual std::string GetExternalExtension() const override;
std::string GetSourceTypeName() const override;
ZResourceType GetResourceType() const override;
protected:
std::vector<uint8_t> dlistRawData;
};
File diff suppressed because it is too large Load Diff
+119
View File
@@ -0,0 +1,119 @@
#pragma once
#include <string>
#include <vector>
#include "Directory.h"
#include "ZResource.h"
#include "ZTexture.h"
#include "tinyxml2.h"
enum class ZFileMode
{
BuildTexture,
BuildOverlay,
BuildModelIntermediette,
BuildAnimationIntermediette,
BuildBlob,
BuildSourceFile,
BuildBackground,
Extract,
Invalid
};
enum class ZGame
{
OOT_RETAIL,
OOT_SW97,
MM_RETAIL
};
class ZFile
{
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);
ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBasePath,
const fs::path& nOutPath, std::string filename, const fs::path& nXmlFilePath,
bool placeholderMode);
~ZFile();
std::string GetVarName(uint32_t address);
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);
ZResource* FindResource(uint32_t rawDataIndex);
std::vector<ZResource*> GetResourcesOfType(ZResourceType resType);
Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, size_t size,
std::string varType, std::string varName, std::string body);
Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment,
DeclarationPadding padding, size_t size, std::string varType,
std::string varName, std::string body);
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size,
std::string varType, std::string varName, size_t arrayItemCnt,
std::string body);
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);
Declaration* AddDeclarationPlaceholder(uint32_t address);
Declaration* AddDeclarationPlaceholder(uint32_t address, std::string varName);
Declaration* AddDeclarationInclude(uint32_t address, std::string includePath, size_t size,
std::string varType, std::string varName);
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) 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);
protected:
std::vector<uint8_t> rawData;
std::string name;
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();
void AddDeclarationDebugChecks(uint32_t address);
std::string ProcessDeclarations();
void ProcessDeclarationText(Declaration* decl);
std::string ProcessExterns();
std::string ProcessTextureIntersections(std::string prefix);
};
+688
View File
@@ -0,0 +1,688 @@
#include "ZLimb.h"
#include <cassert>
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
REGISTER_ZFILENODE(Limb, ZLimb);
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset)
{
unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00);
unk_2 = BitConverter::ToInt16BE(rawData, fileOffset + 0x02);
unk_4 = BitConverter::ToInt16BE(rawData, fileOffset + 0x04);
unk_6 = BitConverter::ToInt8BE(rawData, fileOffset + 0x06);
unk_7 = BitConverter::ToInt8BE(rawData, fileOffset + 0x07);
unk_8 = BitConverter::ToInt8BE(rawData, fileOffset + 0x08);
unk_9 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x09);
}
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index)
: Struct_800A57C0(rawData, fileOffset + index * GetRawDataSize())
{
}
std::string Struct_800A57C0::GetSourceOutputCode() const
{
return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X", unk_0, unk_2, unk_4, unk_6,
unk_7, unk_8, unk_9);
}
size_t Struct_800A57C0::GetRawDataSize()
{
return 0x0A;
}
std::string Struct_800A57C0::GetSourceTypeName()
{
return "Struct_800A57C0";
}
Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset)
{
unk_0 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x00);
x = BitConverter::ToInt16BE(rawData, fileOffset + 0x02);
y = BitConverter::ToInt16BE(rawData, fileOffset + 0x04);
z = BitConverter::ToInt16BE(rawData, fileOffset + 0x06);
unk_8 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x08);
}
Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index)
: Struct_800A598C_2(rawData, fileOffset + index * GetRawDataSize())
{
}
std::string Struct_800A598C_2::GetSourceOutputCode() const
{
return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", unk_0, x, y, z, unk_8);
}
size_t Struct_800A598C_2::GetRawDataSize()
{
return 0x0A;
}
std::string Struct_800A598C_2::GetSourceTypeName()
{
return "Struct_800A598C_2";
}
Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData,
uint32_t fileOffset)
: parent(parent)
{
unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00);
unk_2 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x02);
unk_4 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x04);
unk_8 = BitConverter::ToUInt32BE(rawData, fileOffset + 0x08);
unk_C = BitConverter::ToUInt32BE(rawData, fileOffset + 0x0C);
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
for (size_t i = 0; i < unk_0; i++)
{
unk_8_arr.emplace_back(rawData, unk_8_Offset, i);
}
}
if (unk_C != 0)
{
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
for (size_t i = 0; i < unk_2; i++)
{
unk_C_arr.emplace_back(rawData, unk_C_Offset, i);
}
}
}
Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData,
uint32_t fileOffset, size_t index)
: Struct_800A598C(parent, rawData, fileOffset + index * GetRawDataSize())
{
}
void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
{
std::string entryStr;
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
std::string unk_8_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
size_t arrayItemCnt = unk_8_arr.size();
entryStr = "";
size_t i = 0;
for (auto& child : unk_8_arr)
{
entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(),
(++i < arrayItemCnt) ? "\n" : "");
}
Declaration* decl = parent->GetDeclaration(unk_8_Offset);
if (decl == nullptr)
{
parent->AddDeclarationArray(unk_8_Offset, DeclarationAlignment::None,
arrayItemCnt * Struct_800A57C0::GetRawDataSize(),
Struct_800A57C0::GetSourceTypeName(), unk_8_Str,
arrayItemCnt, entryStr);
}
else
{
decl->text = entryStr;
}
}
if (unk_C != 0)
{
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
std::string unk_C_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
size_t arrayItemCnt = unk_C_arr.size();
entryStr = "";
size_t i = 0;
for (auto& child : unk_C_arr)
{
entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(),
(++i < arrayItemCnt) ? "\n" : "");
}
Declaration* decl = parent->GetDeclaration(unk_C_Offset);
if (decl == nullptr)
{
parent->AddDeclarationArray(unk_C_Offset, DeclarationAlignment::None,
arrayItemCnt * Struct_800A598C_2::GetRawDataSize(),
Struct_800A598C_2::GetSourceTypeName(), unk_C_Str,
arrayItemCnt, entryStr);
}
else
{
decl->text = entryStr;
}
}
}
std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) const
{
std::string entryStr;
std::string unk_8_Str = "NULL";
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
unk_8_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
}
std::string unk_C_Str = "NULL";
if (unk_C != 0)
{
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
unk_C_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
}
entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n",
unk_8_Str.c_str(), unk_C_Str.c_str());
entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(),
unk_C_Str.c_str());
entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n",
unk_8_Str.c_str(), unk_C_Str.c_str());
entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(),
unk_C_Str.c_str());
return entryStr;
}
size_t Struct_800A598C::GetRawDataSize()
{
return 0x10;
}
std::string Struct_800A598C::GetSourceTypeName()
{
return "Struct_800A598C";
}
Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& nRawData,
uint32_t fileOffset)
: parent(parent), rawData(nRawData)
{
unk_0 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x00);
unk_2 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x02);
unk_4 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x04);
unk_8 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x08);
if (unk_4 != 0)
{
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
for (size_t i = 0; i < unk_2; i++)
{
unk_4_arr.emplace_back(parent, nRawData, unk_4_Offset, i);
}
}
}
Struct_800A5E28::~Struct_800A5E28()
{
delete unk_8_dlist;
}
void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
{
if (unk_4 != 0)
{
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
std::string unk_4_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
std::string entryStr = "";
uint16_t arrayItemCnt = unk_4_arr.size();
size_t i = 0;
for (auto& child : unk_4_arr)
{
child.PreGenSourceFiles(prefix);
entryStr +=
StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode(prefix).c_str(),
(++i < arrayItemCnt) ? "\n" : "");
}
Declaration* decl = parent->GetDeclaration(unk_4_Offset);
if (decl == nullptr)
{
parent->AddDeclarationArray(unk_4_Offset, DeclarationAlignment::None,
arrayItemCnt * Struct_800A598C::GetRawDataSize(),
Struct_800A598C::GetSourceTypeName(), unk_4_Str,
arrayItemCnt, entryStr);
}
else
{
decl->text = entryStr;
}
}
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
int32_t dlistLength = ZDisplayList::GetDListLength(
rawData, unk_8_Offset,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength, parent);
std::string dListStr =
StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
unk_8_dlist->SetName(dListStr);
unk_8_dlist->GetSourceOutputCode(prefix);
}
}
std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) const
{
std::string entryStr = "";
std::string unk_4_Str = "NULL";
if (unk_4 != 0)
{
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(unk_4_Offset);
if (decl == nullptr)
{
unk_4_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
}
else
{
unk_4_Str = decl->varName;
}
}
std::string unk_8_Str = "NULL";
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(unk_8_Offset);
if (decl == nullptr)
{
// Something went wrong...
unk_8_Str = StringHelper::Sprintf("0x%08X", unk_8);
}
else
{
unk_8_Str = decl->varName;
}
}
return StringHelper::Sprintf("\n %i, ARRAY_COUNTU(%s),\n %s, %s\n", unk_0,
unk_4_Str.c_str(), unk_4_Str.c_str(), unk_8_Str.c_str());
}
size_t Struct_800A5E28::GetRawDataSize()
{
return 0x0C;
}
std::string Struct_800A5E28::GetSourceTypeName()
{
return "Struct_800A5E28";
}
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)
: ZLimb(nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
type = limbType;
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/>
std::string limbType = registeredAttributes.at("LimbType").value;
if (limbType == "") // Reading from a <Limb/>
limbType = registeredAttributes.at("Type").value;
if (limbType == "")
{
fprintf(stderr,
"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
{
if (limbType == "Standard")
{
type = ZLimbType::Standard;
}
else if (limbType == "LOD")
{
type = ZLimbType::LOD;
}
else if (limbType == "Skin")
{
type = ZLimbType::Skin;
}
else if (limbType == "Curve")
{
type = ZLimbType::Curve;
}
else
{
fprintf(stderr,
"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;
}
}
}
void ZLimb::ParseRawData()
{
ZResource::ParseRawData();
if (type == ZLimbType::Curve)
{
childIndex = rawData.at(rawDataIndex + 0);
siblingIndex = rawData.at(rawDataIndex + 1);
dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
return;
}
transX = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
transY = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
transZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
childIndex = rawData.at(rawDataIndex + 6);
siblingIndex = rawData.at(rawDataIndex + 7);
switch (type)
{
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");
break;
}
}
size_t ZLimb::GetRawDataSize() const
{
switch (type)
{
case ZLimbType::Standard:
case ZLimbType::Curve:
return 0x0C;
case ZLimbType::LOD:
case ZLimbType::Skin:
return 0x10;
}
return 0x0C;
}
std::string ZLimb::GetSourceOutputCode(const std::string& prefix)
{
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);
std::string entryStr = "";
if (type != ZLimbType::Curve)
{
entryStr += StringHelper::Sprintf("\n { %i, %i, %i },", transX, transY, transZ);
}
entryStr += StringHelper::Sprintf("\n 0x%02X, 0x%02X,\n", childIndex, siblingIndex);
switch (type)
{
case ZLimbType::Standard:
entryStr += StringHelper::Sprintf(" %s\n", dListStr.c_str());
break;
case ZLimbType::LOD:
case ZLimbType::Curve:
entryStr += StringHelper::Sprintf(" { %s, %s }\n", dListStr.c_str(), dListStr2.c_str());
break;
case ZLimbType::Skin:
entryStr += GetSourceOutputCodeSkin(prefix);
break;
}
Declaration* decl = parent->GetDeclaration(GetFileAddress());
if (decl == nullptr)
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), name, entryStr);
else
decl->text = entryStr;
return "";
}
std::string ZLimb::GetSourceTypeName() const
{
return GetSourceTypeName(type);
}
ZResourceType ZLimb::GetResourceType() const
{
return ZResourceType::Limb;
}
ZLimbType ZLimb::GetLimbType()
{
return type;
}
void ZLimb::SetLimbType(ZLimbType value)
{
type = value;
}
const char* ZLimb::GetSourceTypeName(ZLimbType limbType)
{
switch (limbType)
{
case ZLimbType::Standard:
return "StandardLimb";
case ZLimbType::LOD:
return "LodLimb";
case ZLimbType::Skin:
return "SkinLimb";
case ZLimbType::Curve:
return "SkelCurveLimb";
default:
return "StandardLimb";
}
}
uint32_t ZLimb::GetFileAddress()
{
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)
{
if (dListPtr == 0)
return "NULL";
uint32_t dListOffset = Seg2Filespace(dListPtr, parent->baseAddress);
// 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)
return decl->varName;
// Check if it points to the middle of a DList
decl = parent->GetDeclarationRanged(dListOffset);
if (decl != nullptr)
{
// 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;
}
std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
{
assert(type == ZLimbType::Skin);
assert(skinSegmentType == ZLimbSkinType::SkinType_4);
if (skinSegment == 0)
return "NULL";
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
std::string struct_800A5E28_Str;
Declaration* decl = parent->GetDeclaration(skinSegmentOffset);
if (decl == nullptr)
{
struct_800A5E28_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset);
segmentStruct.PreGenSourceFiles(prefix);
std::string entryStr = segmentStruct.GetSourceOutputCode(prefix);
parent->AddDeclaration(skinSegmentOffset, DeclarationAlignment::None,
Struct_800A5E28::GetRawDataSize(),
Struct_800A5E28::GetSourceTypeName(), struct_800A5E28_Str, entryStr);
}
else
{
struct_800A5E28_Str = decl->varName;
}
return struct_800A5E28_Str;
}
std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
{
assert(type == ZLimbType::Skin);
std::string skinSegmentStr = "NULL";
if (skinSegment != 0)
{
switch (skinSegmentType)
{
case ZLimbSkinType::SkinType_4:
skinSegmentStr = "&" + GetSourceOutputCodeSkin_Type_4(prefix);
break;
case ZLimbSkinType::SkinType_DList:
skinSegmentStr = GetLimbDListSourceOutputCode(prefix, "Skin", skinSegment);
break;
default:
fprintf(stderr,
"ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Unknown segment type "
"for SkinLimb: '%i'. \n\tPlease report this.\n",
name.c_str(), static_cast<int32_t>(skinSegmentType));
break;
case ZLimbSkinType::SkinType_0:
case ZLimbSkinType::SkinType_5:
fprintf(stderr,
"ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Segment type for "
"SkinLimb not implemented: '%i'.\n",
name.c_str(), static_cast<int32_t>(skinSegmentType));
skinSegmentStr = StringHelper::Sprintf("0x%08X", skinSegment);
break;
}
}
std::string entryStr =
StringHelper::Sprintf(" 0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str());
return entryStr;
}
+163
View File
@@ -0,0 +1,163 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include "ZDisplayList.h"
#include "ZFile.h"
enum class ZLimbType
{
Standard,
LOD,
Skin,
Curve,
};
// TODO: check if more types exists
enum class ZLimbSkinType
{
SkinType_0, // Segment = 0
SkinType_4 = 4, // Segment = segmented address // Struct_800A5E28
SkinType_5 = 5, // Segment = 0
SkinType_DList = 11, // Segment = DList address
};
class Struct_800A57C0
{
protected:
uint16_t unk_0;
int16_t unk_2;
int16_t unk_4;
int8_t unk_6;
int8_t unk_7;
int8_t unk_8;
uint8_t unk_9;
public:
Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset);
Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index);
[[nodiscard]] std::string GetSourceOutputCode() const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
};
class Struct_800A598C_2
{
protected:
uint8_t unk_0;
int16_t x;
int16_t y;
int16_t z;
uint8_t unk_8;
public:
Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset);
Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index);
[[nodiscard]] std::string GetSourceOutputCode() const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
};
class Struct_800A598C
{
protected:
ZFile* parent;
uint16_t unk_0; // Length of unk_8
uint16_t unk_2; // Length of unk_C
uint16_t unk_4; // 0 or 1 // Used as an index for unk_C
segptr_t unk_8; // Struct_800A57C0*
segptr_t unk_C; // Struct_800A598C_2*
std::vector<Struct_800A57C0> unk_8_arr;
std::vector<Struct_800A598C_2> unk_C_arr;
public:
Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset);
Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index);
void PreGenSourceFiles(const std::string& prefix);
[[nodiscard]] std::string GetSourceOutputCode(const std::string& prefix) const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
};
class Struct_800A5E28
{
protected:
ZFile* parent;
std::vector<uint8_t> rawData;
uint16_t unk_0; // Vtx count
uint16_t unk_2; // Length of unk_4
segptr_t unk_4; // Struct_800A598C*
segptr_t unk_8; // Gfx*
std::vector<Struct_800A598C> unk_4_arr;
ZDisplayList* unk_8_dlist = nullptr;
public:
Struct_800A5E28() = default;
Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset);
Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index);
~Struct_800A5E28();
void PreGenSourceFiles(const std::string& prefix);
[[nodiscard]] std::string GetSourceOutputCode(const std::string& prefix) const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
};
class ZLimb : public ZResource
{
protected:
ZLimbType type = ZLimbType::Standard;
ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only
segptr_t skinSegment = 0; // Skin only
Struct_800A5E28 segmentStruct; // Skin only
segptr_t dList2Ptr; // LOD and Curve Only
std::string GetLimbDListSourceOutputCode(const std::string& prefix,
const std::string& limbPrefix, segptr_t dListPtr);
std::string GetSourceOutputCodeSkin(const std::string& prefix);
std::string GetSourceOutputCodeSkin_Type_4(const std::string& prefix);
public:
segptr_t dListPtr = 0;
segptr_t farDListPtr = 0; // LOD only
int16_t transX, transY, transZ;
uint8_t childIndex, siblingIndex;
ZLimb(ZFile* nParent);
ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent);
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;
size_t GetRawDataSize() const override;
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceTypeName() const override;
ZResourceType GetResourceType() const override;
ZLimbType GetLimbType();
void SetLimbType(ZLimbType value);
static const char* GetSourceTypeName(ZLimbType limbType);
uint32_t GetFileAddress();
void SetFileAddress(uint32_t nAddress);
};
+97
View File
@@ -0,0 +1,97 @@
#include "ZMtx.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
REGISTER_ZFILENODE(Mtx, ZMtx);
ZMtx::ZMtx(ZFile* nParent) : ZResource(nParent)
{
}
ZMtx::ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
ZFile* nParent)
: ZResource(nParent)
{
name = GetDefaultName(prefix.c_str(), rawDataIndex);
ExtractFromFile(nRawData, nRawDataIndex);
DeclareVar("", "");
}
void ZMtx::ParseRawData()
{
ZResource::ParseRawData();
for (size_t i = 0; i < 4; ++i)
for (size_t j = 0; j < 4; ++j)
mtx[i][j] = BitConverter::ToInt32BE(rawData, rawDataIndex + (i * 4 + j) * 4);
}
void ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar("", "");
}
size_t ZMtx::GetRawDataSize() const
{
return 64;
}
void ZMtx::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
{
std::string auxName = name;
if (name == "")
auxName = GetDefaultName(prefix, rawDataIndex);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
GetSourceTypeName(), auxName, bodyStr);
}
std::string ZMtx::GetBodySourceCode()
{
std::string bodyStr = "\n";
for (const auto& row : mtx)
{
bodyStr += " ";
for (int32_t val : row)
bodyStr += StringHelper::Sprintf("%-11i, ", val);
bodyStr += "\n";
}
return bodyStr;
}
std::string ZMtx::GetSourceOutputCode(const std::string& prefix)
{
std::string bodyStr = GetBodySourceCode();
Declaration* decl = parent->GetDeclaration(rawDataIndex);
if (decl == nullptr)
DeclareVar(prefix, bodyStr);
else
decl->text = bodyStr;
return "";
}
std::string ZMtx::GetDefaultName(const std::string& prefix, uint32_t address)
{
return StringHelper::Sprintf("%sMtx_%06X", prefix.c_str(), address);
}
std::string ZMtx::GetSourceTypeName() const
{
return "Mtx";
}
ZResourceType ZMtx::GetResourceType() const
{
return ZResourceType::Mtx;
}
+31
View File
@@ -0,0 +1,31 @@
#pragma once
#include <array>
#include <cstdint>
#include "ZResource.h"
class ZMtx : public ZResource
{
public:
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) override;
size_t GetRawDataSize() const override;
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() const override;
ZResourceType GetResourceType() const override;
protected:
std::array<std::array<int32_t, 4>, 4> mtx;
};
+214
View File
@@ -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;
}
+54
View File
@@ -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;
};
+259
View File
@@ -0,0 +1,259 @@
#include "ZResource.h"
#include <cassert>
#include <regex>
#include "StringHelper.h"
#include "ZFile.h"
ZResource::ZResource(ZFile* nParent)
{
// assert(nParent != nullptr);
parent = nParent;
name = "";
outName = "";
sourceOutput = "";
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)
{
rawData = nRawData;
rawDataIndex = nRawDataIndex;
if (reader != nullptr)
ParseXML(reader);
ParseRawData();
CalcHash();
}
void ZResource::ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex)
{
rawData = nRawData;
rawDataIndex = nRawDataIndex;
ParseRawData();
CalcHash();
}
void ZResource::ParseXML(tinyxml2::XMLElement* reader)
{
if (reader != nullptr)
{
// If it is an inner node, then 'Name' isn't required
if (isInner)
{
registeredAttributes.at("Name").isRequired = false;
}
auto attrs = reader->FirstAttribute();
while (attrs != nullptr)
{
std::string attrName = attrs->Name();
bool attrDeclared = 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",
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 fs::path& outFolder)
{
}
void ZResource::PreGenSourceFiles()
{
}
const std::string& ZResource::GetName() const
{
return name;
}
const std::string& ZResource::GetOutName() const
{
return outName;
}
void ZResource::SetOutName(const std::string& nName)
{
outName = nName;
}
void ZResource::SetName(const std::string& nName)
{
name = nName;
}
bool ZResource::IsExternalResource() const
{
return false;
}
bool ZResource::DoesSupportArray() const
{
return false;
}
std::string ZResource::GetExternalExtension() const
{
return "";
}
const std::vector<uint8_t>& ZResource::GetRawData() const
{
return rawData;
}
void ZResource::SetRawData(const std::vector<uint8_t>& nData)
{
rawData = nData;
}
bool ZResource::WasDeclaredInXml() const
{
return declaredInXml;
}
uint32_t ZResource::GetRawDataIndex() const
{
return rawDataIndex;
}
void ZResource::SetRawDataIndex(uint32_t value)
{
rawDataIndex = value;
}
std::string ZResource::GetBodySourceCode() const
{
return "ERROR";
}
std::string ZResource::GetSourceOutputCode(const std::string& prefix)
{
return "";
}
std::string ZResource::GetSourceOutputHeader(const std::string& prefix)
{
return "";
}
void ZResource::ParseRawData()
{
}
void ZResource::DeclareReferences(const std::string& prefix)
{
}
void ZResource::GenerateHLIntermediette(HLFileIntermediette& hlFile)
{
}
std::string ZResource::GetSourceTypeName() const
{
return "u8";
}
ZResourceType ZResource::GetResourceType() const
{
return ZResourceType::Error;
}
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);
if (GETSEGNUM(segmentedAddress) == 0x80) // Is defined in code?
currentPtr -= GETSEGOFFSET(parentBaseAddress);
return currentPtr;
}
+153
View File
@@ -0,0 +1,153 @@
#pragma once
#include <map>
#include <stdexcept>
#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
#define SEGMENT_FIELDDANGEON_KEEP 5
#define SEGMENT_OBJECT 6
#define SEGMENT_LINKANIMETION 7
#define GETSEGOFFSET(x) (x & 0x00FFFFFF)
#define GETSEGNUM(x) ((x >> 24) & 0xFF)
typedef uint32_t segptr_t;
class ZFile;
class HLFileIntermediette;
enum class ZResourceType
{
Error,
Animation,
Array,
Background,
Blob,
CollisionHeader,
Cutscene,
DisplayList,
Limb,
Mtx,
Path,
Room,
RoomCommand,
Scalar,
Skeleton,
String,
Symbol,
Texture,
Vector,
Vertex,
};
class ResourceAttribute
{
public:
std::string key = "";
std::string value = "";
bool isRequired = false;
bool wasSet = false;
};
class ZResource
{
public:
ZFile* parent;
bool outputDeclaration = true;
uint32_t hash = 0;
ZResource(ZFile* nParent);
virtual ~ZResource() = default;
// Parsing from File
virtual void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
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 fs::path& outFolder);
// Properties
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
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() 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::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;
// Reading from this XMLs attributes should be performed in the overrided `ParseXML` method.
std::map<std::string, ResourceAttribute> registeredAttributes;
// XML attributes registers.
// Registering XML attributes should be done in constructors.
// 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)(ZFile* nParent);
#define REGISTER_ZFILENODE(nodeName, zResClass) \
static ZResource* ZResourceFactory_##zResClass_##nodeName(ZFile* nParent) \
{ \
return static_cast<ZResource*>(new zResClass(nParent)); \
} \
\
class ZRes_##nodeName \
{ \
public: \
ZRes_##nodeName() \
{ \
ZFile::RegisterNode(#nodeName, &ZResourceFactory_##zResClass_##nodeName); \
} \
}; \
static ZRes_##nodeName inst_ZRes_##nodeName
@@ -0,0 +1,20 @@
#include "EndMarker.h"
EndMarker::EndMarker(ZFile* nParent) : ZRoomCommand(nParent)
{
}
std::string EndMarker::GetBodySourceCode() const
{
return "SCENE_CMD_END()";
}
std::string EndMarker::GetCommandCName() const
{
return "SCmdEndMarker";
}
RoomCommand EndMarker::GetRoomCommand() const
{
return RoomCommand::EndMarker;
}
@@ -0,0 +1,13 @@
#pragma once
#include "ZRoom/ZRoomCommand.h"
class EndMarker : public ZRoomCommand
{
public:
EndMarker(ZFile* nParent);
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
};
@@ -0,0 +1,97 @@
#include "SetActorCutsceneList.h"
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetActorCutsceneList::SetActorCutsceneList(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetActorCutsceneList::ParseRawData()
{
ZRoomCommand::ParseRawData();
int numCutscenes = cmdArg1;
int32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numCutscenes; i++)
{
ActorCutsceneEntry entry(parent->GetRawData(), currentPtr);
cutscenes.push_back(entry);
currentPtr += 16;
}
}
void SetActorCutsceneList::DeclareReferences(const std::string& prefix)
{
if (cutscenes.size() > 0)
{
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);
}
}
std::string SetActorCutsceneList::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_LIST(%i, %s)", cutscenes.size(),
listName.c_str());
}
size_t SetActorCutsceneList::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize() + (cutscenes.size() * 16);
}
std::string SetActorCutsceneList::GetCommandCName() const
{
return "SCmdCutsceneActorList";
}
RoomCommand SetActorCutsceneList::GetRoomCommand() const
{
return RoomCommand::SetActorCutsceneList;
}
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)),
unk6(BitConverter::ToInt16BE(rawData, rawDataIndex + 6)),
additionalCutscene(BitConverter::ToInt16BE(rawData, rawDataIndex + 8)),
sound(rawData[rawDataIndex + 0xA]), unkB(rawData[rawDataIndex + 0xB]),
unkC(BitConverter::ToInt16BE(rawData, rawDataIndex + 0xC)), unkE(rawData[rawDataIndex + 0xE]),
letterboxSize(rawData[rawDataIndex + 0xF])
{
}
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";
}
@@ -0,0 +1,42 @@
#pragma once
#include "ZRoom/ZRoomCommand.h"
class ActorCutsceneEntry
{
protected:
int16_t priority;
int16_t length;
int16_t unk4;
int16_t unk6;
int16_t additionalCutscene;
uint8_t sound;
uint8_t unkB;
int16_t unkC;
uint8_t unkE;
uint8_t letterboxSize;
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(ZFile* nParent);
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;
};
@@ -0,0 +1,151 @@
#include "SetActorList.h"
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZNames.h"
#include "ZRoom/ZRoom.h"
SetActorList::SetActorList(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetActorList::ParseRawData()
{
ZRoomCommand::ParseRawData();
numActors = cmdArg1;
uint32_t currentPtr = segmentOffset;
for (size_t i = 0; i < numActors; i++)
{
ActorSpawnEntry entry(parent->GetRawData(), currentPtr);
currentPtr += entry.GetRawDataSize();
actors.push_back(entry);
}
}
void SetActorList::DeclareReferences(const std::string& prefix)
{
if (!actors.empty())
{
std::string declaration = "";
size_t index = 0;
for (const auto& entry : actors)
{
declaration +=
StringHelper::Sprintf("\t{ %s }, // 0x%06X", entry.GetBodySourceCode().c_str(),
segmentOffset + (index * 16));
if (index < actors.size() - 1)
declaration += "\n";
index++;
}
const auto& entry = actors.front();
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);
}
}
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() const
{
size_t actorCount = 0;
// Doing an else-if here so we only do the loop when the game is SW97.
// Actor 0x22 is removed from SW97, so we need to ensure that we don't increment the actor count
// for it.
if (Globals::Instance->game == ZGame::OOT_SW97)
{
actorCount = 0;
for (const auto& entry : actors)
if (entry.GetActorId() != 0x22)
actorCount++;
}
else
{
actorCount = actors.size();
}
return actorCount;
}
std::string SetActorList::GetCommandCName() const
{
return "SCmdActorList";
}
RoomCommand SetActorList::GetRoomCommand() const
{
return RoomCommand::SetActorList;
}
ActorSpawnEntry::ActorSpawnEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
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;
}
@@ -0,0 +1,47 @@
#pragma once
#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;
int16_t posZ;
int16_t rotX;
int16_t rotY;
int16_t rotZ;
uint16_t initVar;
};
class SetActorList : public ZRoomCommand
{
public:
SetActorList(ZFile* nParent);
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;
protected:
size_t GetActorListArraySize() const;
uint8_t numActors;
std::vector<ActorSpawnEntry> actors;
};
@@ -0,0 +1,70 @@
#include "SetAlternateHeaders.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
SetAlternateHeaders::SetAlternateHeaders(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetAlternateHeaders::DeclareReferences(const std::string& prefix)
{
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(parent->GetRawData(), segmentOffset + (i * 4));
headers.push_back(address);
if (address != 0)
zRoom->commandSets.push_back(CommandSet(address));
}
}
void SetAlternateHeaders::DeclareReferencesLate(const std::string& prefix)
{
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);
}
}
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() const
{
return RoomCommand::SetAlternateHeaders;
}
@@ -0,0 +1,22 @@
#pragma once
#include "ZRoom/ZRoom.h"
#include "ZRoom/ZRoomCommand.h"
class SetAlternateHeaders : public ZRoomCommand
{
public:
SetAlternateHeaders(ZFile* nParent);
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<uint32_t> headers;
};
@@ -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;
}
@@ -0,0 +1,119 @@
#pragma once
#include <memory>
#include "ZRoom/ZRoomCommand.h"
// TODO move into header and add all types
class AnitmatedTextureParams
{
public:
virtual std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) = 0;
virtual size_t GetParamsSize() = 0;
};
class ScrollingTexture : public AnitmatedTextureParams
{
public:
ScrollingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
size_t GetParamsSize() override;
int8_t xStep;
int8_t yStep;
uint8_t width;
uint8_t height;
};
class F3DPrimColor
{
public:
F3DPrimColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
uint8_t lodFrac;
};
class FlashingTextureEnvColor
{
public:
FlashingTextureEnvColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
uint8_t r;
uint8_t g;
uint8_t b;
uint8_t a;
};
class FlashingTexture : public AnitmatedTextureParams
{
public:
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<F3DPrimColor> primColors;
std::vector<FlashingTextureEnvColor> envColors;
std::vector<uint16_t> keyFrames;
};
class AnimatedMatTexCycleParams : public AnitmatedTextureParams
{
public:
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;
std::vector<uint32_t> textureSegmentOffsets;
std::vector<uint8_t> textureIndices;
};
class AnimatedMaterial
{
public:
AnimatedMaterial(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
int8_t segment;
int16_t type;
segptr_t segmentAddress;
uint32_t segmentOffset;
std::vector<std::shared_ptr<AnitmatedTextureParams>> params;
};
class SetAnimatedMaterialList : public ZRoomCommand
{
public:
SetAnimatedMaterialList(ZFile* nParent);
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<AnimatedMaterial> textures;
};
@@ -0,0 +1,31 @@
#include "SetCameraSettings.h"
#include "BitConverter.h"
#include "StringHelper.h"
SetCameraSettings::SetCameraSettings(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetCameraSettings::ParseRawData()
{
ZRoomCommand::ParseRawData();
cameraMovement = cmdArg1;
mapHighlight = BitConverter::ToUInt32BE(parent->GetRawData(), rawDataIndex + 4);
}
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() const
{
return RoomCommand::SetCameraSettings;
}
@@ -0,0 +1,20 @@
#pragma once
#include "ZRoom/ZRoomCommand.h"
class SetCameraSettings : public ZRoomCommand
{
public:
SetCameraSettings(ZFile* nParent);
void ParseRawData() override;
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
private:
uint8_t cameraMovement;
uint32_t mapHighlight;
};
@@ -0,0 +1,42 @@
#include "SetCollisionHeader.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetCollisionHeader::SetCollisionHeader(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetCollisionHeader::ParseRawData()
{
ZRoomCommand::ParseRawData();
collisionHeader = new ZCollisionHeader(parent);
collisionHeader->SetRawData(parent->GetRawData());
collisionHeader->SetRawDataIndex(segmentOffset);
collisionHeader->SetName(
StringHelper::Sprintf("%sCollisionHeader_%06X", parent->GetName().c_str(), segmentOffset));
collisionHeader->ParseRawData();
}
SetCollisionHeader::~SetCollisionHeader()
{
delete collisionHeader;
}
std::string SetCollisionHeader::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_COL_HEADER(%s)", listName.c_str());
}
std::string SetCollisionHeader::GetCommandCName() const
{
return "SCmdColHeader";
}
RoomCommand SetCollisionHeader::GetRoomCommand() const
{
return RoomCommand::SetCollisionHeader;
}
@@ -0,0 +1,21 @@
#pragma once
#include "ZCollision.h"
#include "ZRoom/ZRoomCommand.h"
class SetCollisionHeader : public ZRoomCommand
{
public:
SetCollisionHeader(ZFile* nParent);
~SetCollisionHeader();
void ParseRawData() override;
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
private:
ZCollisionHeader* collisionHeader;
};
@@ -0,0 +1,162 @@
#include "SetCsCamera.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetCsCamera::SetCsCamera(ZFile* nParent) : ZRoomCommand(nParent)
{
}
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(parent->GetRawData(), currentPtr);
numPoints += entry.GetNumPoints();
currentPtr += entry.GetRawDataSize();
cameras.push_back(entry);
}
if (numPoints > 0)
{
uint32_t currentPtr = cameras.at(0).GetSegmentOffset();
for (int32_t i = 0; i < numPoints; i++)
{
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)
parent->AddDeclarationPlaceholder(segmentOffset);
}
void SetCsCamera::DeclareReferences(const std::string& prefix)
{
if (points.size() > 0)
{
std::string declaration = "";
size_t index = 0;
for (auto& point : points)
{
declaration +=
StringHelper::Sprintf("\t%s, //0x%06X", point.GetBodySourceCode().c_str(),
cameras.at(0).segmentOffset + (index * 6));
if (index < points.size() - 1)
declaration += "\n";
index++;
}
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())
{
std::string camPointsName = parent->GetDeclarationName(cameras.at(0).GetSegmentOffset());
std::string declaration = "";
size_t index = 0;
size_t pointsIndex = 0;
for (const auto& entry : cameras)
{
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.GetNumPoints();
}
const auto& entry = cameras.front();
std::string camTypename = entry.GetSourceTypeName();
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::Pad16,
cameras.size() * entry.GetRawDataSize(), camTypename,
StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), camTypename.c_str(), segmentOffset),
cameras.size(), declaration);
}
}
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);
}
std::string SetCsCamera::GetCommandCName() const
{
return "SCmdCsCameraList";
}
RoomCommand SetCsCamera::GetRoomCommand() const
{
return RoomCommand::SetCsCamera;
}
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))
{
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;
}
@@ -0,0 +1,42 @@
#pragma once
#include "ZRoom/ZRoomCommand.h"
#include "ZVector.h"
class CsCameraEntry
{
public:
CsCameraEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
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(ZFile* nParent);
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<CsCameraEntry> cameras;
std::vector<ZVector> points;
};
@@ -0,0 +1,115 @@
#include "SetCutscenes.h"
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetCutscenes::SetCutscenes(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetCutscenes::ParseRawData()
{
ZRoomCommand::ParseRawData();
std::string output = "";
numCutscenes = cmdArg1;
if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97)
{
ZCutscene* cutscene = new ZCutscene(parent);
cutscene->ExtractFromFile(parent->GetRawData(), segmentOffset);
auto decl = parent->GetDeclaration(segmentOffset);
if (decl == nullptr)
{
cutscene->DeclareVar(zRoom->GetName().c_str(), "");
}
cutscenes.push_back(cutscene);
}
else
{
int32_t currentPtr = segmentOffset;
std::string declaration = "";
for (uint8_t i = 0; i < numCutscenes; i++)
{
CutsceneEntry entry(parent->GetRawData(), currentPtr);
cutsceneEntries.push_back(entry);
currentPtr += 8;
declaration += StringHelper::Sprintf(
" { %sCutsceneData0x%06X, 0x%04X, 0x%02X, 0x%02X },", zRoom->GetName().c_str(),
entry.segmentOffset, entry.exit, entry.entrance, entry.flag);
if (i < numCutscenes - 1)
declaration += "\n";
ZCutsceneMM* cutscene = new ZCutsceneMM(parent);
cutscene->ExtractFromFile(parent->GetRawData(), entry.segmentOffset);
cutscenes.push_back(cutscene);
}
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 = parent->GetDeclaration(cutscene->getSegmentOffset());
if (decl == nullptr)
{
cutscene->GetSourceOutputCode(zRoom->GetName());
}
else if (decl->text == "")
{
decl->text = cutscene->GetBodySourceCode();
}
}
}
}
SetCutscenes::~SetCutscenes()
{
for (ZCutsceneBase* cutscene : cutscenes)
delete cutscene;
}
std::string SetCutscenes::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
if (Globals::Instance->game == ZGame::MM_RETAIL)
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_LIST(%i, %s)", numCutscenes,
listName.c_str());
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_DATA(%s)", listName.c_str());
}
size_t SetCutscenes::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize();
}
std::string SetCutscenes::GetCommandCName() const
{
return "SCmdCutsceneData";
}
RoomCommand SetCutscenes::GetRoomCommand() const
{
return RoomCommand::SetCutscenes;
}
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])
{
}
@@ -0,0 +1,36 @@
#pragma once
#include "ZCutscene.h"
#include "ZCutsceneMM.h"
#include "ZRoom/ZRoomCommand.h"
class CutsceneEntry
{
public:
CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
uint32_t segmentOffset;
uint16_t exit;
uint8_t entrance;
uint8_t flag;
};
class SetCutscenes : public ZRoomCommand
{
public:
SetCutscenes(ZFile* nParent);
~SetCutscenes();
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)
uint8_t numCutscenes; // (MM Only)
};
@@ -0,0 +1,27 @@
#include "SetEchoSettings.h"
#include "StringHelper.h"
SetEchoSettings::SetEchoSettings(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetEchoSettings::ParseRawData()
{
ZRoomCommand::ParseRawData();
echo = parent->GetRawData().at(rawDataIndex + 0x07);
}
std::string SetEchoSettings::GetBodySourceCode() const
{
return StringHelper::Sprintf("SCENE_CMD_ECHO_SETTINGS(%i)", echo);
}
std::string SetEchoSettings::GetCommandCName() const
{
return "SCmdEchoSettings";
}
RoomCommand SetEchoSettings::GetRoomCommand() const
{
return RoomCommand::SetEchoSettings;
}
@@ -0,0 +1,19 @@
#pragma once
#include "ZRoom/ZRoomCommand.h"
class SetEchoSettings : public ZRoomCommand
{
public:
SetEchoSettings(ZFile* nParent);
void ParseRawData() override;
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
private:
uint8_t echo;
};
@@ -0,0 +1,83 @@
#include "SetEntranceList.h"
#include "BitConverter.h"
#include "SetStartPositionList.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetEntranceList::SetEntranceList(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetEntranceList::DeclareReferences(const std::string& prefix)
{
if (segmentOffset != 0)
parent->AddDeclarationPlaceholder(segmentOffset);
}
void SetEntranceList::ParseRawDataLate()
{
// Parse Entrances and Generate Declaration
int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
uint32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numEntrances; i++)
{
EntranceEntry entry(parent->GetRawData(), currentPtr);
entrances.push_back(entry);
currentPtr += 2;
}
}
void SetEntranceList::DeclareReferencesLate(const std::string& prefix)
{
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);
}
}
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() const
{
return RoomCommand::SetEntranceList;
}
EntranceEntry::EntranceEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
startPositionIndex = rawData.at(rawDataIndex + 0);
roomToLoad = rawData.at(rawDataIndex + 1);
}
std::string EntranceEntry::GetBodySourceCode() const
{
return StringHelper::Sprintf("0x%02X, 0x%02X", startPositionIndex, roomToLoad);
}
@@ -0,0 +1,33 @@
#pragma once
#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;
};
class SetEntranceList : public ZRoomCommand
{
public:
SetEntranceList(ZFile* nParent);
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;
};
@@ -0,0 +1,67 @@
#include "SetExitList.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetExitList::SetExitList(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetExitList::DeclareReferences(const std::string& prefix)
{
if (segmentOffset != 0)
parent->AddDeclarationPlaceholder(segmentOffset);
}
void SetExitList::ParseRawDataLate()
{
// Parse Entrances and Generate Declaration
int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
uint32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numEntrances; i++)
{
uint16_t exit = BitConverter::ToUInt16BE(parent->GetRawData(), currentPtr);
exits.push_back(exit);
currentPtr += 2;
}
}
void SetExitList::DeclareReferencesLate(const std::string& prefix)
{
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);
}
}
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() const
{
return RoomCommand::SetExitList;
}
@@ -0,0 +1,21 @@
#pragma once
#include "ZRoom/ZRoomCommand.h"
class SetExitList : public ZRoomCommand
{
public:
SetExitList(ZFile* nParent);
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;
};
@@ -0,0 +1,94 @@
#include "SetLightList.h"
#include "BitConverter.h"
#include "StringHelper.h"
SetLightList::SetLightList(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetLightList::ParseRawData()
{
ZRoomCommand::ParseRawData();
std::string declarations = "";
numLights = cmdArg1;
int32_t currentPtr = segmentOffset;
for (int i = 0; i < this->numLights; i++)
{
LightInfo light(parent->GetRawData(), currentPtr);
currentPtr += light.GetRawDataSize();
lights.push_back(light);
}
}
void SetLightList::DeclareReferences(const std::string& prefix)
{
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);
}
}
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";
}
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;
}
@@ -0,0 +1,43 @@
#pragma once
#include <string>
#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(ZFile* nParent);
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;
std::vector<LightInfo> lights;
};
@@ -0,0 +1,103 @@
#include "SetLightingSettings.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetLightingSettings::SetLightingSettings(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetLightingSettings::ParseRawData()
{
ZRoomCommand::ParseRawData();
uint8_t numLights = cmdArg1;
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)
{
std::string declaration = "";
for (size_t i = 0; i < settings.size(); i++)
{
declaration += StringHelper::Sprintf("\t{ %s }, // 0x%06X",
settings.at(i).GetBodySourceCode().c_str(),
segmentOffset + (i * 22));
if (i + 1 < settings.size())
declaration += "\n";
}
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::Align4,
settings.size() * settings.front().GetRawDataSize(), "LightSettings",
StringHelper::Sprintf("%sLightSettings0x%06X", prefix.c_str(), segmentOffset),
settings.size(), declaration);
}
}
std::string SetLightingSettings::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_ENV_LIGHT_SETTINGS(%i, %s)", settings.size(),
listName.c_str());
}
std::string SetLightingSettings::GetCommandCName() const
{
return "SCmdLightSettingList";
}
RoomCommand SetLightingSettings::GetRoomCommand() const
{
return RoomCommand::SetLightingSettings;
}
LightingSettings::LightingSettings(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
ambientClrR = rawData.at(rawDataIndex + 0);
ambientClrG = rawData.at(rawDataIndex + 1);
ambientClrB = rawData.at(rawDataIndex + 2);
diffuseClrA_R = rawData.at(rawDataIndex + 3);
diffuseClrA_G = rawData.at(rawDataIndex + 4);
diffuseClrA_B = rawData.at(rawDataIndex + 5);
diffuseDirA_X = rawData.at(rawDataIndex + 6);
diffuseDirA_Y = rawData.at(rawDataIndex + 7);
diffuseDirA_Z = rawData.at(rawDataIndex + 8);
diffuseClrB_R = rawData.at(rawDataIndex + 9);
diffuseClrB_G = rawData.at(rawDataIndex + 10);
diffuseClrB_B = rawData.at(rawDataIndex + 11);
diffuseDirB_X = rawData.at(rawDataIndex + 12);
diffuseDirB_Y = rawData.at(rawDataIndex + 13);
diffuseDirB_Z = rawData.at(rawDataIndex + 14);
fogClrR = rawData.at(rawDataIndex + 15);
fogClrG = rawData.at(rawDataIndex + 16);
fogClrB = rawData.at(rawDataIndex + 17);
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;
}
@@ -0,0 +1,40 @@
#pragma once
#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;
uint8_t diffuseClrB_R, diffuseClrB_G, diffuseClrB_B;
uint8_t diffuseDirB_X, diffuseDirB_Y, diffuseDirB_Z;
uint8_t fogClrR, fogClrG, fogClrB;
uint16_t unk;
uint16_t drawDistance;
};
class SetLightingSettings : public ZRoomCommand
{
public:
SetLightingSettings(ZFile* nParent);
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:
std::vector<LightingSettings> settings;
};
+671
View File
@@ -0,0 +1,671 @@
#include "SetMesh.h"
#include <Globals.h>
#include <Path.h>
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZBackground.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
void GenDListDeclarations(ZRoom* zRoom, ZFile* parent, ZDisplayList* dList);
SetMesh::SetMesh(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetMesh::ParseRawData()
{
ZRoomCommand::ParseRawData();
auto& parentRawData = parent->GetRawData();
meshHeaderType = parentRawData.at(segmentOffset);
switch (meshHeaderType)
{
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::DeclareReferences(const std::string& prefix)
{
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);
dList->scene = zRoom->scene;
std::string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName());
for (ZDisplayList* otherDList : dList->otherDLists)
GenDListDeclarations(zRoom, parent, otherDList);
for (const auto& vtxEntry : dList->vtxDeclarations)
{
DeclarationAlignment alignment = DeclarationAlignment::Align4;
if (Globals::Instance->game == ZGame::MM_RETAIL)
alignment = DeclarationAlignment::None;
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);
}
}
std::string SetMesh::GenDListExterns(ZDisplayList* dList)
{
std::string sourceOutput = "";
sourceOutput += StringHelper::Sprintf("extern Gfx %sDL_%06X[];\n", zRoom->GetName().c_str(),
dList->GetRawDataIndex());
for (ZDisplayList* otherDList : dList->otherDLists)
sourceOutput += GenDListExterns(otherDList);
sourceOutput += dList->defines;
return sourceOutput;
}
std::string SetMesh::GetBodySourceCode() const
{
std::string list = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_MESH(%s)", list.c_str());
}
size_t SetMesh::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize();
}
std::string SetMesh::GetCommandCName() const
{
return "SCmdMesh";
}
RoomCommand SetMesh::GetRoomCommand() const
{
return RoomCommand::SetMesh;
}
PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
zRoom = nRoom;
name = GetDefaultName(prefix.c_str(), rawDataIndex);
}
void PolygonDlist::ParseRawData()
{
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)
{
if (ptr == 0)
{
return nullptr;
}
uint32_t dlistAddress = Seg2Filespace(ptr, parent->baseAddress);
int32_t dlistLength = ZDisplayList::GetDListLength(
rawData, dlistAddress,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
ZDisplayList* dlist = new ZDisplayList(rawData, dlistAddress, dlistLength, parent);
GenDListDeclarations(zRoom, parent, dlist);
return dlist;
}
size_t PolygonDlist::GetRawDataSize() const
{
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)
{
std::string auxName = name;
if (name == "")
{
auxName = GetDefaultName(prefix, rawDataIndex);
}
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
GetSourceTypeName(), auxName, bodyStr);
}
std::string PolygonDlist::GetBodySourceCode(bool arrayElement)
{
std::string bodyStr = "";
std::string opaStr = parent->GetDeclarationPtrName(opa);
std::string xluStr = parent->GetDeclarationPtrName(xlu);
if (arrayElement)
{
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";
}
return bodyStr;
}
void PolygonDlist::DeclareAndGenerateOutputCode()
{
std::string bodyStr = GetBodySourceCode(false);
Declaration* decl = parent->GetDeclaration(rawDataIndex);
if (decl == nullptr)
{
DeclareVar("", bodyStr);
}
else
{
decl->text = bodyStr;
}
}
std::string PolygonDlist::GetDefaultName(const std::string& prefix, uint32_t address)
{
return StringHelper::Sprintf("%sPolyDlist_%06X", prefix.c_str(), address);
}
std::string PolygonDlist::GetSourceTypeName()
{
switch (polyType)
{
case 2:
return "PolygonDlist2";
default:
return "PolygonDlist";
}
}
std::string PolygonDlist::GetName()
{
return name;
}
BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
isSubStruct = nIsSubStruct;
name = GetDefaultName(prefix.c_str(), rawDataIndex);
ParseRawData();
sourceBackground = MakeBackground(source, prefix);
}
void BgImage::ParseRawData()
{
size_t pad = 0x00;
if (!isSubStruct)
{
pad = 0x04;
unk_00 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00);
id = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x02);
}
source = BitConverter::ToUInt32BE(rawData, rawDataIndex + pad + 0x00);
unk_0C = BitConverter::ToUInt32BE(rawData, rawDataIndex + pad + 0x04);
tlut = BitConverter::ToUInt32BE(rawData, rawDataIndex + pad + 0x08);
width = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x0C);
height = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x0E);
fmt = BitConverter::ToUInt8BE(rawData, rawDataIndex + pad + 0x10);
siz = BitConverter::ToUInt8BE(rawData, rawDataIndex + pad + 0x11);
mode0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x12);
tlutCount = BitConverter::ToUInt16BE(rawData, rawDataIndex + pad + 0x14);
}
ZBackground* BgImage::MakeBackground(segptr_t ptr, const std::string& prefix)
{
if (ptr == 0)
{
return nullptr;
}
uint32_t backAddress = Seg2Filespace(ptr, parent->baseAddress);
ZBackground* background = new ZBackground(prefix, rawData, backAddress, parent);
background->DeclareVar(prefix, "");
parent->resources.push_back(background);
return background;
}
size_t BgImage::GetRawDataSize()
{
return 0x1C;
}
std::string BgImage::GetBodySourceCode(bool arrayElement) const
{
std::string bodyStr = " ";
if (arrayElement)
{
bodyStr += "{ \n ";
}
if (!isSubStruct)
{
bodyStr += StringHelper::Sprintf("0x%04X, ", unk_00);
bodyStr += StringHelper::Sprintf("%i, ", id);
bodyStr += "\n ";
if (arrayElement)
{
bodyStr += " ";
}
}
std::string backgroundName = parent->GetDeclarationPtrName(source);
bodyStr += StringHelper::Sprintf("%s, ", backgroundName.c_str());
bodyStr += "\n ";
if (arrayElement)
{
bodyStr += " ";
}
bodyStr += StringHelper::Sprintf("0x%08X, ", unk_0C);
bodyStr += StringHelper::Sprintf("0x%08X, ", tlut);
bodyStr += "\n ";
if (arrayElement)
{
bodyStr += " ";
}
bodyStr += StringHelper::Sprintf("%i, ", width);
bodyStr += StringHelper::Sprintf("%i, ", height);
bodyStr += "\n ";
if (arrayElement)
{
bodyStr += " ";
}
bodyStr += StringHelper::Sprintf("%i, ", fmt);
bodyStr += StringHelper::Sprintf("%i, ", siz);
bodyStr += "\n ";
if (arrayElement)
{
bodyStr += " ";
}
bodyStr += StringHelper::Sprintf("0x%04X, ", mode0);
bodyStr += StringHelper::Sprintf("0x%04X, ", tlutCount);
if (arrayElement)
{
bodyStr += " \n }, ";
}
else
{
bodyStr += "\n";
}
return bodyStr;
}
std::string BgImage::GetDefaultName(const std::string& prefix, uint32_t address)
{
return StringHelper::Sprintf("%sBgImage_%06X", prefix.c_str(), address);
}
std::string BgImage::GetSourceTypeName()
{
return "BgImage";
}
std::string BgImage::GetName()
{
return name;
}
/* 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}
{
type = BitConverter::ToUInt8BE(rawData, rawDataIndex);
}
void PolygonTypeBase::DeclareVar(const std::string& prefix, const std::string& bodyStr)
{
std::string auxName = name;
if (name == "")
auxName = GetDefaultName(prefix);
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)
{
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, rawData, rawDataIndex + 0x08, parent);
break;
case 2:
if (list != 0)
{
listAddress = Seg2Filespace(list, parent->baseAddress);
for (size_t i = 0; i < count; ++i)
{
BgImage bg(false, prefix, rawData, listAddress + i * BgImage::GetRawDataSize(),
parent);
multiList.push_back(bg);
bgImageArrayBody += bg.GetBodySourceCode(true);
if (i + 1 < count)
{
bgImageArrayBody += "\n";
}
}
Declaration* decl = parent->GetDeclaration(listAddress);
if (decl == nullptr)
{
parent->AddDeclarationArray(
listAddress, DeclarationAlignment::Align4, count * BgImage::GetRawDataSize(),
BgImage::GetSourceTypeName(), multiList.at(0).GetName().c_str(), count,
bgImageArrayBody);
}
}
break;
default:
throw std::runtime_error(StringHelper::Sprintf(
"Error in PolygonType1::PolygonType1\n\t Unknown format: %i\n", format));
break;
}
}
size_t PolygonType1::GetRawDataSize() const
{
switch (format)
{
case 1:
return 0x20;
case 2:
return 0x10;
}
return 0x20;
}
std::string PolygonType1::GetBodySourceCode() const
{
std::string bodyStr = "\n ";
bodyStr += "{ ";
bodyStr += StringHelper::Sprintf("%i, %i, ", type, format);
std::string dlistStr = parent->GetDeclarationPtrName(dlist);
bodyStr += StringHelper::Sprintf("%s, ", dlistStr.c_str());
bodyStr += "}, \n";
std::string listStr = "NULL";
// bodyStr += " { \n";
switch (format)
{
case 1:
bodyStr += single.GetBodySourceCode(false);
break;
case 2:
listStr = parent->GetDeclarationPtrName(list);
bodyStr += StringHelper::Sprintf(" %i, %s, \n", count, listStr.c_str());
break;
default:
break;
}
// bodyStr += " } \n";
return bodyStr;
}
std::string PolygonType1::GetSourceTypeName() const
{
switch (format)
{
case 1:
return "MeshHeader1Single";
case 2:
return "MeshHeader1Multi";
}
return "ERROR";
// return "PolygonType1";
}
PolygonType2::PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZRoom* nRoom)
: PolygonTypeBase(nParent, nRawData, nRawDataIndex, nRoom)
{
}
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;
}
+190
View File
@@ -0,0 +1,190 @@
#pragma once
#include <memory>
#include "ZBackground.h"
#include "ZDisplayList.h"
#include "ZRoom/ZRoomCommand.h"
class PolygonDlist
{
public:
PolygonDlist() = default;
PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom);
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);
std::string GetBodySourceCode(bool arrayElement);
void DeclareAndGenerateOutputCode();
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
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
{
protected:
uint16_t unk_00;
uint8_t id;
segptr_t source;
uint32_t unk_0C;
uint32_t tlut;
uint16_t width;
uint16_t height;
uint8_t fmt;
uint8_t siz;
uint16_t mode0;
uint16_t tlutCount;
ZBackground* sourceBackground;
std::vector<uint8_t> rawData;
uint32_t rawDataIndex;
ZFile* parent;
std::string name;
bool isSubStruct;
void ParseRawData();
ZBackground* MakeBackground(segptr_t ptr, const std::string& prefix);
public:
BgImage() = default;
BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent);
static size_t GetRawDataSize();
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 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;
// single
BgImage single;
// multi
uint8_t count;
segptr_t list; // BgImage*
std::vector<BgImage> multiList;
public:
PolygonType1(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;
std::string GetSourceTypeName() const override;
size_t GetRawDataSize() const override;
};
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(ZFile* nParent);
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:
uint8_t meshHeaderType;
std::shared_ptr<PolygonTypeBase> polyType;
std::string GenDListExterns(ZDisplayList* dList);
};
@@ -0,0 +1,85 @@
#include "SetMinimapChests.h"
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetMinimapChests::SetMinimapChests(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetMinimapChests::ParseRawData()
{
ZRoomCommand::ParseRawData();
int numChests = cmdArg1;
int32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numChests; i++)
{
MinimapChest chest(parent->GetRawData(), currentPtr);
chests.push_back(chest);
currentPtr += 10;
}
}
void SetMinimapChests::DeclareReferences(const std::string& prefix)
{
std::string declaration = "";
size_t index = 0;
for (const auto& chest : chests)
{
declaration += StringHelper::Sprintf(" { %s },", chest.GetBodySourceCode().c_str());
if (index < chests.size() - 1)
declaration += "\n";
index++;
}
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, chests.size() * 10, "MinimapChest",
StringHelper::Sprintf("%sMinimapChests0x%06X", prefix.c_str(), segmentOffset),
chests.size(), declaration);
}
std::string SetMinimapChests::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_MINIMAP_COMPASS_ICON_INFO(0x%02X, %s)", chests.size(),
listName.c_str());
}
std::string SetMinimapChests::GetCommandCName() const
{
return "SCmdMinimapChests";
}
RoomCommand SetMinimapChests::GetRoomCommand() const
{
return RoomCommand::SetMinimapChests;
}
size_t SetMinimapChests::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize() + (chests.size() * 10);
}
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);
}
@@ -0,0 +1,36 @@
#pragma once
#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;
};
class SetMinimapChests : public ZRoomCommand
{
public:
SetMinimapChests(ZFile* nParent);
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;
};
@@ -0,0 +1,98 @@
#include "SetMinimapList.h"
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetMinimapList::SetMinimapList(ZFile* nParent) : ZRoomCommand(nParent)
{
}
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(parent->GetRawData(), currentPtr);
minimaps.push_back(entry);
currentPtr += 10;
}
}
void SetMinimapList::DeclareReferences(const std::string& prefix)
{
{
std::string declaration = "";
size_t index = 0;
for (const auto& entry : minimaps)
{
declaration += StringHelper::Sprintf(" { %s },", entry.GetBodySourceCode().c_str());
if (index < minimaps.size() - 1)
declaration += "\n";
index++;
}
parent->AddDeclarationArray(
listSegmentOffset, DeclarationAlignment::Align4, minimaps.size() * 10, "MinimapEntry",
StringHelper::Sprintf("%sMinimapEntryList0x%06X", prefix.c_str(), listSegmentOffset),
minimaps.size(), declaration);
}
{
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);
}
}
std::string SetMinimapList::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_MINIMAP_INFO(%s)", listName.c_str());
}
std::string SetMinimapList::GetCommandCName() const
{
return "SCmdMinimapSettings";
}
RoomCommand SetMinimapList::GetRoomCommand() const
{
return RoomCommand::SetMinimapList;
}
size_t SetMinimapList::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize() + (minimaps.size() * 10);
}
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);
}
@@ -0,0 +1,40 @@
#pragma once
#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;
};
class SetMinimapList : public ZRoomCommand
{
public:
SetMinimapList(ZFile* nParent);
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;
segptr_t listSegmentAddr;
uint32_t listSegmentOffset;
uint32_t unk4;
};

Some files were not shown because too many files have changed in this diff Show More