git subrepo pull --force tools/ZAPD

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "769f5702a"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "769f5702a"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"
This commit is contained in:
angie
2021-05-10 21:32:09 -04:00
parent 58813216fc
commit 5de22b5036
135 changed files with 5362 additions and 14304 deletions
+2 -2
View File
@@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/zeldaret/ZAPD.git
branch = master
commit = b9120803e6094a54192ed67d9585ab046101c816
parent = 81b43ba32e564a00c976dec7d520e6bcb0b122f8
commit = 769f5702a422d14bfb0a60a39319da4b4bf9ec1f
parent = 58813216fc7397a0b7356c2236269c783cf83fce
method = merge
cmdver = 0.4.3
+28 -10
View File
@@ -1,27 +1,40 @@
OPTIMIZATION_ON ?= 1
ASAN ?= 0
DEPRECATION_OFF ?= 0
CFLAGS ?=
CC := g++
INC := -I ZAPD -I lib/assimp/include -I lib/elfio -I lib/json/include -I lib/stb -I lib/tinygltf -I lib/libgfxd -I lib/tinyxml2
CFLAGS += -g3 -ggdb -fpic -std=c++17 -rdynamic -Wall -fno-omit-frame-pointer
CFLAGS := -g3 -fpic -Wl,-export-dynamic -std=c++17 -rdynamic -Wall
ifeq ($(OPTIMIZATION_ON),1)
CFLAGS += -O2
else
ifeq ($(OPTIMIZATION_ON),0)
CFLAGS += -O0
else
CFLAGS += -O2
endif
ifneq ($(ASAN),0)
CFLAGS += -fsanitize=address
endif
ifneq ($(DEPRECATION_OFF),0)
CFLAGS += -DDEPRECATION_OFF
endif
# CFLAGS += -DTEXTURE_DEBUG
LDFLAGS := -ldl
LDFLAGS := -ldl -lpng
UNAME := $(shell uname)
FS_INC =
FS_INC ?=
ifneq ($(UNAME), Darwin)
FS_INC += -lstdc++fs
CFLAGS += -Wl,-export-dynamic
endif
SRC_DIRS := ZAPD ZAPD/ZRoom ZAPD/ZRoom/Commands ZAPD/Overlays ZAPD/HighLevel ZAPD/OpenFBX
SRC_DIRS := ZAPD ZAPD/ZRoom ZAPD/ZRoom/Commands ZAPD/Overlays ZAPD/HighLevel
CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
CPP_FILES += lib/tinyxml2/tinyxml2.cpp
ZAPD_CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
ZAPD_H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))
CPP_FILES += $(ZAPD_CPP_FILES) lib/tinyxml2/tinyxml2.cpp
O_FILES := $(CPP_FILES:.cpp=.o)
all: ZAPD.out copycheck
@@ -38,6 +51,11 @@ clean:
rebuild: clean all
format:
clang-format-11 -i $(ZAPD_CPP_FILES) $(ZAPD_H_FILES)
.PHONY: all genbuildinfo copycheck clean rebuild format
%.o: %.cpp
$(CC) $(CFLAGS) $(INC) -c $< -o $@ $(LDFLAGS)
@@ -45,7 +63,7 @@ ZAPD/Main.o: genbuildinfo ZAPD/Main.cpp
$(CC) $(CFLAGS) $(INC) -c ZAPD/Main.cpp -o $@ $(LDFLAGS)
lib/libgfxd/libgfxd.a:
$(MAKE) -C lib/libgfxd -j
$(MAKE) -C lib/libgfxd
ZAPD.out: $(O_FILES) lib/libgfxd/libgfxd.a
$(CC) $(CFLAGS) $(INC) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC) $(LDFLAGS)
+39
View File
@@ -0,0 +1,39 @@
# ZAPD: Zelda Asset Processor for Decomp
## Compiling
### Dependencies
ZAPD needs a compiler with C++17 support.
ZAPD has the following library dependencies:
- `libpng`
In a Debian/Ubuntu based environment, those could be installed with the following command:
```bash
sudo apt install libpng-dev
```
### Building
#### Linux / *nix
ZAPD uses the clasic `Makefile` approach. To build just run `make` (or even better `make -j` for faster compilations).
You can configure a bit your ZAPD build with the following options:
- `OPTIMIZATION_ON`: If set to `0`, then optimizations will be disabled (compile with `-O0`). Any other value compiles with `-O2`. Defaults to `1`.
- `ASAN`: If it is set to a non-zero then ZAPD will be compiled with Address Sanitizer enabled (`-fsanitize=address`). Defaults to `0`.
- `DEPRECATION_OFF`: If it is set to a non-zero then deprecation warnings will be disabled. Defaults to `0`.
As an example, if you want to build ZAPD with optimizations disabled and use the address sanitizer, you could use the following command:
```bash
make -j OPTIMIZATION_ON=0 ASAN=1
```
#### Windows
This repository contains `vcxproj` files for compiling under Visual Studio environments. See `ZAPD/ZAPD.vcxproj`.
+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);
};
-1
View File
@@ -3,7 +3,6 @@
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include "StringHelper.h"
+26 -27
View File
@@ -5,7 +5,6 @@
#include "tinyxml2.h"
using namespace tinyxml2;
using namespace std;
Globals* Globals::Instance;
@@ -16,27 +15,26 @@ Globals::Globals()
files = std::vector<ZFile*>();
segments = std::vector<int32_t>();
symbolMap = std::map<uint32_t, std::string>();
segmentRefs = map<int32_t, string>();
segmentRefFiles = map<int32_t, ZFile*>();
segmentRefs = std::map<int32_t, std::string>();
segmentRefFiles = std::map<int32_t, ZFile*>();
game = ZGame::OOT_RETAIL;
genSourceFile = true;
testMode = false;
profile = false;
includeFilePrefix = false;
useLegacyZDList = false;
useExternalResources = true;
lastScene = nullptr;
verbosity = VERBOSITY_SILENT;
verbosity = VerbosityLevel::VERBOSITY_SILENT;
}
string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
std::string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
{
if (segmentRefs.find(segNumber) != segmentRefs.end())
{
if (segmentRefFiles.find(segNumber) == segmentRefFiles.end())
{
XMLDocument doc;
string filePath = segmentRefs[segNumber];
std::string filePath = segmentRefs[segNumber];
XMLError eResult = doc.LoadFile(filePath.c_str());
if (eResult != tinyxml2::XML_SUCCESS)
@@ -47,14 +45,12 @@ string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
if (root == nullptr)
return "ERROR";
// vector<ZFile*> files = vector<ZFile*>();
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "File")
if (std::string(child->Name()) == "File")
{
ZFile* file = new ZFile(fileMode, child, "", "", "", "", true);
ZFile* file = new ZFile(fileMode, child, "", "", "", filePath, true);
file->GeneratePlaceholderDeclarations();
segmentRefFiles[segNumber] = file;
break;
@@ -87,41 +83,41 @@ void Globals::ReadConfigFile(const std::string& configFilePath)
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "SymbolMap")
if (std::string(child->Name()) == "SymbolMap")
{
string fileName = string(child->Attribute("File"));
std::string fileName = std::string(child->Attribute("File"));
GenSymbolMap(Path::GetDirectoryName(configFilePath) + "/" + fileName);
}
else if (string(child->Name()) == "Segment")
else if (std::string(child->Name()) == "Segment")
{
string fileName = string(child->Attribute("File"));
std::string fileName = std::string(child->Attribute("File"));
int32_t segNumber = child->IntAttribute("Number");
segmentRefs[segNumber] = fileName;
}
else if (string(child->Name()) == "ActorList")
else if (std::string(child->Name()) == "ActorList")
{
string fileName = string(child->Attribute("File"));
std::string fileName = std::string(child->Attribute("File"));
std::vector<std::string> lines =
File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName);
for (std::string line : lines)
cfg.actorList.push_back(StringHelper::Strip(line, "\r"));
}
else if (string(child->Name()) == "ObjectList")
else if (std::string(child->Name()) == "ObjectList")
{
string fileName = string(child->Attribute("File"));
std::string fileName = std::string(child->Attribute("File"));
std::vector<std::string> lines =
File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName);
for (std::string line : lines)
cfg.objectList.push_back(StringHelper::Strip(line, "\r"));
}
else if (string(child->Name()) == "TexturePool")
else if (std::string(child->Name()) == "TexturePool")
{
string fileName = string(child->Attribute("File"));
std::string fileName = std::string(child->Attribute("File"));
ReadTexturePool(Path::GetDirectoryName(configFilePath) + "/" + fileName);
}
else if (string(child->Name()) == "BGConfig")
else if (std::string(child->Name()) == "BGConfig")
{
cfg.bgScreenWidth = child->IntAttribute("ScreenWidth", 320);
cfg.bgScreenHeight = child->IntAttribute("ScreenHeight", 240);
@@ -148,11 +144,11 @@ void Globals::ReadTexturePool(const std::string& texturePoolXmlPath)
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "Texture")
if (std::string(child->Name()) == "Texture")
{
string crcStr = string(child->Attribute("CRC"));
string texPath = string(child->Attribute("Path"));
string texName = "";
std::string crcStr = std::string(child->Attribute("CRC"));
fs::path texPath = std::string(child->Attribute("Path"));
std::string texName = "";
uint32_t crc = strtoul(crcStr.c_str(), NULL, 16);
@@ -175,10 +171,13 @@ void Globals::GenSymbolMap(const std::string& symbolMapPath)
}
}
void Globals::AddSegment(int32_t segment)
void Globals::AddSegment(int32_t segment, ZFile* file)
{
if (std::find(segments.begin(), segments.end(), segment) == segments.end())
segments.push_back(segment);
segmentRefs[segment] = file->GetXmlFilePath();
segmentRefFiles[segment] = file;
}
bool Globals::HasSegment(int32_t segment)
+5 -5
View File
@@ -7,7 +7,7 @@
#include "ZRoom/ZRoom.h"
#include "ZTexture.h"
enum VerbosityLevel
enum class VerbosityLevel
{
VERBOSITY_SILENT,
VERBOSITY_INFO,
@@ -42,9 +42,9 @@ public:
bool genSourceFile; // Used for extraction
bool useExternalResources;
bool testMode; // Enables certain experimental features
bool profile; // Measure performance of certain operations
bool includeFilePrefix; // Include the file prefix in symbols
bool testMode; // Enables certain experimental features
bool outputCrc = false;
bool profile; // Measure performance of certain operations
bool useLegacyZDList;
VerbosityLevel verbosity; // ZAPD outputs additional information
ZFileMode fileMode;
@@ -66,7 +66,7 @@ public:
void ReadConfigFile(const std::string& configFilePath);
void ReadTexturePool(const std::string& texturePoolXmlPath);
void GenSymbolMap(const std::string& symbolMapPath);
void AddSegment(int32_t segment);
void AddSegment(int32_t segment, ZFile* file);
bool HasSegment(int32_t segment);
};
@@ -1,6 +1,5 @@
#include "HLAnimationIntermediette.h"
using namespace std;
using namespace tinyxml2;
HLAnimationIntermediette::HLAnimationIntermediette()
@@ -8,8 +7,8 @@ HLAnimationIntermediette::HLAnimationIntermediette()
limit = 0;
limbCount = 0;
frameCount = 0;
rotationValues = vector<uint16_t>();
rotationIndices = vector<RotationIndex>();
rotationValues = std::vector<uint16_t>();
rotationIndices = std::vector<RotationIndex>();
}
HLAnimationIntermediette::~HLAnimationIntermediette()
@@ -32,16 +31,16 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath)
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "RotationValues")
if (std::string(child->Name()) == "RotationValues")
{
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
child2 = child2->NextSiblingElement())
{
string value = child2->GetText();
std::string value = child2->GetText();
anim->rotationValues.push_back(atoi(value.c_str()));
}
}
else if (string(child->Name()) == "RotationIndices")
else if (std::string(child->Name()) == "RotationIndices")
{
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
child2 = child2->NextSiblingElement())
@@ -68,9 +67,9 @@ ZAnimation* HLAnimationIntermediette::ToZAnimation()
return zAnim;
}
string HLAnimationIntermediette::OutputXML()
std::string HLAnimationIntermediette::OutputXML()
{
string output = "";
std::string output = "";
XMLDocument doc;
XMLElement* root = doc.NewElement("HLAnimationIntermediette");
@@ -1,9 +1,9 @@
#pragma once
#include <stdint.h>
#include <tinyxml2.h>
#include "../ZAnimation.h"
#include "HLFileIntermediette.h"
#include "tinyxml2.h"
/*
* An intermediette format for animations. Going to use XML.
@@ -12,12 +12,11 @@
#include <assimp/scene.h>
#endif
using namespace std;
using namespace tinyxml2;
HLModelIntermediette::HLModelIntermediette()
{
blocks = vector<HLIntermediette*>();
blocks = std::vector<HLIntermediette*>();
startIndex = 0;
meshStartIndex = 0;
hasSkeleton = false;
@@ -35,7 +34,7 @@ HLModelIntermediette* HLModelIntermediette::FromXML(tinyxml2::XMLElement* root)
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
string childName = child->Name();
std::string childName = child->Name();
HLIntermediette* block = nullptr;
if (childName == "Mesh")
@@ -66,16 +65,16 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
limb->name = zDisplayList->GetName();
// Go through verts
vector<Vertex> finalVerts = vector<Vertex>();
std::vector<ZVtx> finalVerts;
int32_t vStart = -1;
for (pair<int32_t, vector<Vertex>> pair : zDisplayList->vertices)
for (auto& pair : zDisplayList->vertices)
{
if (vStart == -1) // TODO: Find a better way to do this
vStart = pair.first;
for (Vertex v : pair.second)
for (auto& v : pair.second)
finalVerts.push_back(v);
}
@@ -85,14 +84,17 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
model->blocks.push_back(vertIntr);
// Go through textures
// TODO: Textures are now stored directly in ZFile
/*
for (pair<uint32_t, ZTexture*> pair : zDisplayList->textures)
{
HLTextureIntermediette* texIntr = new HLTextureIntermediette();
texIntr->tex = pair.second;
texIntr->name = texIntr->tex->GetName();
HLTextureIntermediette* texIntr = new HLTextureIntermediette();
texIntr->tex = pair.second;
texIntr->name = texIntr->tex->GetName();
model->blocks.push_back(texIntr);
model->blocks.push_back(texIntr);
}
*/
// Analyze display lists to determine components
HLDisplayListIntermediette* dList = new HLDisplayListIntermediette();
@@ -173,9 +175,10 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
lastMat->clrM = lastClrM;
// Bit of a hack here...
int32_t lastData = (int32_t)(zDisplayList->instructions[i - 1]);
string texName = zDisplayList->textures[lastData & 0x00FFFFFF]->GetName();
lastMat->textureName = texName;
// int32_t lastData = (int32_t)(zDisplayList->instructions[i - 1]);
// TODO
// string texName = zDisplayList->textures[lastData & 0x00FFFFFF]->GetName();
// lastMat->textureName = texName;
// --------------------------
model->blocks.push_back(mesh);
@@ -189,10 +192,11 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
}
else if (opcode == F3DZEXOpcode::G_SETTIMG)
{
int32_t texAddress = data & 0x00FFFFFF;
// int32_t texAddress = data & 0x00FFFFFF;
string texName = zDisplayList->textures[texAddress]->GetName();
lastMat->textureName = texName;
// TODO
// string texName = zDisplayList->textures[texAddress]->GetName();
// lastMat->textureName = texName;
}
else if (opcode == F3DZEXOpcode::G_VTX)
{
@@ -264,14 +268,14 @@ void HLModelIntermediette::ProcessZSkeletonLimb(HLModelIntermediette* model, ZSk
}
}
string HLModelIntermediette::ToOBJFile()
std::string HLModelIntermediette::ToOBJFile()
{
string output = "";
std::string output = "";
for (HLIntermediette* block : blocks)
{
block->parent = this;
string code = block->OutputOBJ();
std::string code = block->OutputOBJ();
output += code;
@@ -282,7 +286,7 @@ string HLModelIntermediette::ToOBJFile()
return output;
}
string HLModelIntermediette::ToAssimpFile()
std::string HLModelIntermediette::ToAssimpFile()
{
#ifdef USE_ASSIMP
Assimp::Exporter exporter;
@@ -330,13 +334,13 @@ string HLModelIntermediette::ToAssimpFile()
return "";
}
string HLModelIntermediette::OutputCode()
std::string HLModelIntermediette::OutputCode()
{
string output = "";
std::string output = "";
for (HLIntermediette* block : blocks)
{
string code = block->OutputCode();
std::string code = block->OutputCode();
output += code;
@@ -349,7 +353,7 @@ string HLModelIntermediette::OutputCode()
std::string HLModelIntermediette::OutputXML()
{
string output = "";
std::string output = "";
XMLDocument doc;
XMLElement* root = doc.NewElement("HLModelIntermediette");
@@ -366,7 +370,7 @@ std::string HLModelIntermediette::OutputXML()
}
template <typename T>
inline T* HLModelIntermediette::FindByName(string name)
inline T* HLModelIntermediette::FindByName(std::string name)
{
for (HLIntermediette* block : blocks)
{
@@ -407,12 +411,12 @@ void HLIntermediette::InitFromXML(XMLElement* xmlElement)
name = xmlElement->Attribute("Name");
}
string HLIntermediette::OutputCode()
std::string HLIntermediette::OutputCode()
{
return "";
}
string HLIntermediette::OutputOBJ()
std::string HLIntermediette::OutputOBJ()
{
return "";
}
@@ -429,7 +433,7 @@ void HLMeshCommand::InitFromXML(XMLElement* xmlElement)
{
}
string HLMeshCommand::OutputCode(HLModelIntermediette* parent)
std::string HLMeshCommand::OutputCode(HLModelIntermediette* parent)
{
return "";
}
@@ -449,35 +453,37 @@ void HLMeshCommand::OutputXML(tinyxml2::XMLElement* parent)
HLVerticesIntermediette::HLVerticesIntermediette() : HLIntermediette()
{
vertices = vector<Vertex>();
vertices = std::vector<ZVtx>();
}
void HLVerticesIntermediette::InitFromXML(XMLElement* verticesElement)
{
name = verticesElement->Attribute("Name");
/*
for (XMLElement* child = verticesElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
vertices.push_back(Vertex(child->IntAttribute("X"), child->IntAttribute("Y"),
child->IntAttribute("Z"), child->IntAttribute("Flags"),
child->IntAttribute("S"), child->IntAttribute("T"),
child->IntAttribute("R"), child->IntAttribute("G"),
child->IntAttribute("B"), child->IntAttribute("A")));
vertices.push_back(ZVtx(child->IntAttribute("X"), child->IntAttribute("Y"),
child->IntAttribute("Z"), child->IntAttribute("Flags"),
child->IntAttribute("S"), child->IntAttribute("T"),
child->IntAttribute("R"), child->IntAttribute("G"),
child->IntAttribute("B"), child->IntAttribute("A")));
*/
}
void HLVerticesIntermediette::InitFromVertices(vector<Vertex> dispListVertices)
void HLVerticesIntermediette::InitFromVertices(std::vector<ZVtx> dispListVertices)
{
for (Vertex v : dispListVertices)
for (auto v : dispListVertices)
vertices.push_back(v);
}
string HLVerticesIntermediette::OutputCode(HLModelIntermediette* parent)
std::string HLVerticesIntermediette::OutputCode(HLModelIntermediette* parent)
{
string output = "";
std::string output = "";
output += StringHelper::Sprintf("Vtx %s_verts[] = \n{\n", name.c_str());
for (Vertex v : vertices)
for (auto v : vertices)
{
output += StringHelper::Sprintf(" { %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", v.x,
v.y, v.z, v.flag, v.s, v.t, v.r, v.g, v.b, v.a);
@@ -490,9 +496,9 @@ string HLVerticesIntermediette::OutputCode(HLModelIntermediette* parent)
std::string HLVerticesIntermediette::OutputOBJ()
{
string output = "";
std::string output = "";
for (Vertex v : vertices)
for (auto& v : vertices)
{
output += StringHelper::Sprintf("v %f %f %f %i %i %i %i\n", (float)v.x * 0.1f,
(float)v.y * 0.1f, (float)v.z * 0.1f, v.r, v.g, v.b, v.a);
@@ -517,7 +523,7 @@ void HLVerticesIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XM
element->SetAttribute("Name", name.c_str());
for (Vertex v : vertices)
for (auto& v : vertices)
{
XMLElement* vElem = doc->NewElement("Vertex");
vElem->SetAttribute("X", v.x);
@@ -549,9 +555,9 @@ void HLMeshCmdGeoSettings::InitFromXML(tinyxml2::XMLElement* xmlElement)
off = xmlElement->Attribute("Off");
}
string HLMeshCmdGeoSettings::OutputCode(HLModelIntermediette* parent)
std::string HLMeshCmdGeoSettings::OutputCode(HLModelIntermediette* parent)
{
string output = "";
std::string output = "";
if (off != "")
output +=
@@ -587,7 +593,7 @@ void HLMeshCmdTriangle1::InitFromXML(tinyxml2::XMLElement* xmlElement)
flag = xmlElement->IntAttribute("flag");
}
string HLMeshCmdTriangle1::OutputCode(HLModelIntermediette* parent)
std::string HLMeshCmdTriangle1::OutputCode(HLModelIntermediette* parent)
{
return StringHelper::Sprintf("gsSP1Triangle(%i, %i, %i, %i),", v0, v1, v2, flag);
}
@@ -653,7 +659,7 @@ void HLMeshCmdTriangle2::InitFromXML(tinyxml2::XMLElement* xmlElement)
flag1 = xmlElement->IntAttribute("Flag1");
}
string HLMeshCmdTriangle2::OutputCode(HLModelIntermediette* parent)
std::string HLMeshCmdTriangle2::OutputCode(HLModelIntermediette* parent)
{
return StringHelper::Sprintf("gsSP2Triangles(%i, %i, %i, %i, %i, %i, %i, %i),", v0, v1, v2,
flag0, v10, v11, v12, flag1);
@@ -661,7 +667,7 @@ string HLMeshCmdTriangle2::OutputCode(HLModelIntermediette* parent)
std::string HLMeshCmdTriangle2::OutputOBJ(HLModelIntermediette* parent)
{
string output = "";
std::string output = "";
int32_t startIndex = parent->startIndex;
@@ -753,7 +759,7 @@ void HLMeshCmdLoadVertices::OutputAssimp(HLModelIntermediette* parent, aiScene*
parent->startIndex = startIndex;
}
string HLMeshCmdLoadVertices::OutputCode(HLModelIntermediette* parent)
std::string HLMeshCmdLoadVertices::OutputCode(HLModelIntermediette* parent)
{
HLVerticesIntermediette* verts = parent->FindByType<HLVerticesIntermediette>();
return StringHelper::Sprintf("gsSPVertex(&%s[%i], %i, %i),", verts->name.c_str(), startIndex,
@@ -785,7 +791,7 @@ void HLMaterialIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
clrL = xmlElement->IntAttribute("ClrL");
}
string HLMaterialIntermediette::OutputCode()
std::string HLMaterialIntermediette::OutputCode()
{
return "";
}
@@ -810,10 +816,10 @@ void HLMaterialIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XM
HLDisplayListIntermediette::HLDisplayListIntermediette()
{
commands = vector<HLDisplayListCommand*>();
commands = std::vector<HLDisplayListCommand*>();
}
string HLDisplayListIntermediette::OutputCode()
std::string HLDisplayListIntermediette::OutputCode()
{
return std::string();
}
@@ -823,7 +829,7 @@ void HLDisplayListIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
string name = child->Name();
std::string name = child->Name();
HLDisplayListCommand* cmd = nullptr;
@@ -870,13 +876,15 @@ void HLTextureIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
name = xmlElement->Attribute("Name");
fileName = xmlElement->Attribute("TextureName");
// string format = xmlElement->Attribute("Format");
string format = "rgb5a1"; // TEST
// std::string format = xmlElement->Attribute("Format");
std::string format = "rgb5a1"; // TEST
// tex = HLTexture::FromPNG(fileName,
// (HLTextureType)ZTexture::GetTextureTypeFromString(format));
tex = ZTexture::FromPNG(Path::GetDirectoryName(Globals::Instance->inputPath) + "/" + fileName,
ZTexture::GetTextureTypeFromString(format));
tex = new ZTexture(nullptr);
tex->ZTexture::FromPNG(Path::GetDirectoryName(Globals::Instance->inputPath.string()) + "/" +
fileName,
ZTexture::GetTextureTypeFromString(format));
}
std::string HLTextureIntermediette::OutputCode()
@@ -892,7 +900,7 @@ void HLTextureIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XML
element->SetAttribute("Name", name.c_str());
element->SetAttribute("TextureName",
(name + "." + tex->GetExternalExtension() + ".png").c_str());
tex->Save(Globals::Instance->outputPath);
tex->Save(Globals::Instance->outputPath.string());
root->InsertEndChild(element);
}
@@ -925,7 +933,7 @@ std::string HLMeshCmdCull::OutputCode(HLModelIntermediette* parent)
HLMeshIntermediette::HLMeshIntermediette() : HLIntermediette()
{
commands = vector<HLMeshCommand*>();
commands = std::vector<HLMeshCommand*>();
}
void HLMeshIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
@@ -935,7 +943,7 @@ void HLMeshIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
string name = child->Name();
std::string name = child->Name();
HLMeshCommand* cmd = nullptr;
@@ -958,9 +966,9 @@ void HLMeshIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
}
}
string HLMeshIntermediette::OutputCode(string materialName)
std::string HLMeshIntermediette::OutputCode(std::string materialName)
{
string output = "";
std::string output = "";
HLMaterialIntermediette* mat = parent->FindByName<HLMaterialIntermediette>(materialName);
HLTextureIntermediette* tex = parent->FindByName<HLTextureIntermediette>(mat->textureName);
@@ -982,9 +990,9 @@ string HLMeshIntermediette::OutputCode(string materialName)
return output;
}
string HLMeshIntermediette::OutputOBJ()
std::string HLMeshIntermediette::OutputOBJ()
{
string output = "";
std::string output = "";
output += StringHelper::Sprintf("o %s\n", name.c_str());
@@ -1031,7 +1039,7 @@ void HLMeshIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLEle
HLLimbIntermediette::HLLimbIntermediette()
{
commands = vector<HLLimbCommand*>();
commands = std::vector<HLLimbCommand*>();
}
void HLLimbIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
@@ -1041,7 +1049,7 @@ void HLLimbIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
string name = child->Name();
std::string name = child->Name();
HLLimbCommand* cmd = nullptr;
@@ -1058,7 +1066,7 @@ void HLLimbIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
std::string HLLimbIntermediette::OutputCode()
{
string output = "";
std::string output = "";
output += StringHelper::Sprintf("Gfx %s[] = \n{\n", name.c_str());
@@ -1113,7 +1121,7 @@ void HLLimbCommand::OutputXML(tinyxml2::XMLElement* parent)
std::string HLLimbCommand::OutputCode(HLModelIntermediette* parent)
{
string output = "";
std::string output = "";
// Time to generate the display list...
HLMeshIntermediette* mesh = parent->FindByName<HLMeshIntermediette>(meshName);
@@ -4,11 +4,11 @@
#include <assimp/scene.h>
#include <stdint.h>
#include <string>
#include <tinyxml2.h>
#include <vector>
#include "../ZDisplayList.h"
#include "../ZSkeleton.h"
#include "HLFileIntermediette.h"
#include "tinyxml2.h"
/*
* An intermediette format for models. Goes from FBX<-->Intermediette<-->Display List C Code.
@@ -156,12 +156,12 @@ public:
class HLVerticesIntermediette : public HLIntermediette
{
public:
std::vector<Vertex> vertices;
std::vector<ZVtx> vertices;
HLVerticesIntermediette();
virtual void InitFromXML(tinyxml2::XMLElement* verticesElement);
void InitFromVertices(std::vector<Vertex> dispListVertices);
void InitFromVertices(std::vector<ZVtx> dispListVertices);
virtual std::string OutputCode(HLModelIntermediette* parent);
virtual std::string OutputOBJ();
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
+3 -6
View File
@@ -1,16 +1,13 @@
#include "HLTexture.h"
#include <stb_image.h>
#include "../StringHelper.h"
using namespace std;
HLTexture* HLTexture::FromPNG(std::string pngFilePath, HLTextureType texType)
{
int32_t comp;
// int32_t comp;
HLTexture* tex = new HLTexture();
tex->type = texType;
tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int32_t*)&tex->width,
(int32_t*)&tex->height, &comp, STBI_rgb_alpha);
// tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int32_t*)&tex->width,
// (int32_t*)&tex->height, &comp, STBI_rgb_alpha);
return tex;
}
+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();
};
+86 -86
View File
@@ -24,7 +24,6 @@
#include "tinyxml2.h"
using namespace tinyxml2;
using namespace std;
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
ZFileMode fileMode);
@@ -43,14 +42,20 @@ void ErrorHandler(int sig)
size_t size = backtrace(array, nMaxFrames);
char** symbols = backtrace_symbols(array, nMaxFrames);
// To prevent unused parameter warning
(void)sig;
fprintf(stderr, "\nZAPD crashed. (Signal: %i)\n", sig);
fprintf(stderr, "\n\t\tYou've met with a terrible fate, haven't you?\n\n");
/**
* Other possible options:
* - SEA BEARS FOAM. SLEEP BEARS DREAMS. \n BOTH END IN THE SAME WAY: CRASSSH!
*/
fprintf(stderr, "Traceback:\n");
for (size_t i = 1; i < size; i++)
{
Dl_info info;
uint32_t gotAddress = dladdr(array[i], &info);
string functionName(symbols[i]);
std::string functionName(symbols[i]);
if (gotAddress != 0 && info.dli_sname != nullptr)
{
@@ -71,7 +76,8 @@ void ErrorHandler(int sig)
fprintf(stderr, "%-3zd %s\n", i, functionName.c_str());
}
// backtrace_symbols_fd(array, size, STDERR_FILENO);
fprintf(stderr, "\n");
free(symbols);
exit(1);
}
@@ -90,7 +96,7 @@ int main(int argc, char* argv[])
Globals* g = new Globals();
// Parse File Mode
string buildMode = argv[1];
std::string buildMode = argv[1];
ZFileMode fileMode = ZFileMode::Invalid;
if (buildMode == "btex")
@@ -119,7 +125,7 @@ int main(int argc, char* argv[])
// Parse other "commands"
for (int32_t i = 2; i < argc; i++)
{
string arg = argv[i];
std::string arg = argv[i];
if (arg == "-o" || arg == "--outputpath") // Set output path
{
@@ -147,34 +153,34 @@ int main(int argc, char* argv[])
}
else if (arg == "-gsf") // Generate source file during extraction
{
Globals::Instance->genSourceFile = string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-ifp") // Include file prefix in generated symbols
{
Globals::Instance->includeFilePrefix = string(argv[i + 1]) == "1";
Globals::Instance->genSourceFile = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-tm") // Test Mode (enables certain experimental features)
{
Globals::Instance->testMode = string(argv[i + 1]) == "1";
Globals::Instance->testMode = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-crc" ||
arg == "--output-crc") // Outputs a CRC file for each extracted texture.
{
Globals::Instance->outputCrc = true;
}
else if (arg == "-ulzdl") // Use Legacy ZDisplay List
{
Globals::Instance->useLegacyZDList = string(argv[i + 1]) == "1";
Globals::Instance->useLegacyZDList = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-profile") // Enable profiling
{
Globals::Instance->profile = string(argv[i + 1]) == "1";
Globals::Instance->profile = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg ==
"-uer") // Split resources into their individual components (enabled by default)
// TODO: We may wish to make this a part of the config file...
{
Globals::Instance->useExternalResources = string(argv[i + 1]) == "1";
Globals::Instance->useExternalResources = std::string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-tt") // Set texture type
@@ -182,8 +188,9 @@ int main(int argc, char* argv[])
Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[i + 1]);
i++;
}
else if (arg == "-cfg") // Set cfg path (for overlays)
// TODO: Change the name of this to something else so it doesn't get confused with XML config files.
else if (arg == "-cfg") // Set cfg path (for overlays)
// TODO: Change the name of this to something else so it doesn't
// get confused with XML config files.
{
Globals::Instance->cfgPath = argv[i + 1];
i++;
@@ -199,12 +206,13 @@ int main(int argc, char* argv[])
signal(SIGSEGV, ErrorHandler);
signal(SIGABRT, ErrorHandler);
#else
printf("Warning: Tried to set error handler, but this build lacks support for one.\n");
fprintf(stderr,
"Warning: Tried to set error handler, but this build lacks support for one.\n");
#endif
}
else if (arg == "-v") // Verbose
{
Globals::Instance->verbosity = (VerbosityLevel)strtol(argv[++i], NULL, 16);
Globals::Instance->verbosity = static_cast<VerbosityLevel>(strtol(argv[++i], NULL, 16));
}
else if (arg == "-wu" || arg == "--warn-unaccounted") // Warn unaccounted
{
@@ -212,57 +220,50 @@ int main(int argc, char* argv[])
}
}
if (Globals::Instance->verbosity >= VERBOSITY_INFO)
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
printf("ZAPD: Zelda Asset Processor For Decomp: %s\n", gBuildHash);
try
if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
{
if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
{
bool parseSuccessful =
Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath,
Globals::Instance->outputPath, fileMode);
bool parseSuccessful = Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath,
Globals::Instance->outputPath, fileMode);
if (!parseSuccessful)
return 1;
}
else if (fileMode == ZFileMode::BuildTexture)
{
TextureType texType = Globals::Instance->texType;
BuildAssetTexture(Globals::Instance->inputPath, texType, Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildBackground)
{
BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildBlob)
{
BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildModelIntermediette)
{
BuildAssetModelIntermediette(Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildAnimationIntermediette)
{
BuildAssetAnimationIntermediette(Globals::Instance->inputPath,
Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildOverlay)
{
ZOverlay* overlay =
ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath),
Path::GetDirectoryName(Globals::Instance->cfgPath));
if (overlay)
File::WriteAllText(Globals::Instance->outputPath, overlay->GetSourceOutputCode(""));
}
if (!parseSuccessful)
return 1;
}
catch (std::runtime_error& e)
else if (fileMode == ZFileMode::BuildTexture)
{
printf("Exception occurred: %s\n", e.what());
TextureType texType = Globals::Instance->texType;
BuildAssetTexture(Globals::Instance->inputPath, texType, Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildBackground)
{
BuildAssetBackground(Globals::Instance->inputPath, Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildBlob)
{
BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildModelIntermediette)
{
BuildAssetModelIntermediette(Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildAnimationIntermediette)
{
BuildAssetAnimationIntermediette(Globals::Instance->inputPath,
Globals::Instance->outputPath);
}
else if (fileMode == ZFileMode::BuildOverlay)
{
ZOverlay* overlay =
ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath),
Path::GetDirectoryName(Globals::Instance->cfgPath));
if (overlay)
File::WriteAllText(Globals::Instance->outputPath.string(),
overlay->GetSourceOutputCode(""));
}
delete g;
return 0;
}
@@ -271,7 +272,7 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
ZFileMode fileMode)
{
XMLDocument doc;
XMLError eResult = doc.LoadFile(xmlFilePath.c_str());
XMLError eResult = doc.LoadFile(xmlFilePath.string().c_str());
if (eResult != tinyxml2::XML_SUCCESS)
{
@@ -290,7 +291,7 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "File")
if (std::string(child->Name()) == "File")
{
ZFile* file = new ZFile(fileMode, child, basePath, outPath, "", xmlFilePath, false);
Globals::Instance->files.push_back(file);
@@ -323,37 +324,36 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath)
{
string name = outPath.stem();
std::string name = outPath.stem().string();
ZTexture* tex = ZTexture::FromPNG(pngFilePath, texType);
string cfgPath = StringHelper::Split(pngFilePath, ".")[0] + ".cfg";
ZTexture tex(nullptr);
tex.FromPNG(pngFilePath, texType);
std::string cfgPath = StringHelper::Split(pngFilePath.string(), ".")[0] + ".cfg";
if (File::Exists(cfgPath))
name = File::ReadAllText(cfgPath);
string src = tex->GetSourceOutputCode(name);
std::string src = tex.GetBodySourceCode();
File::WriteAllText(outPath, src);
delete tex;
File::WriteAllText(outPath.string(), src);
}
void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath)
{
ZBackground background(nullptr);
background.ParseBinaryFile(imageFilePath, false);
background.ParseBinaryFile(imageFilePath.string(), false);
File::WriteAllText(outPath, background.GetBodySourceCode());
File::WriteAllText(outPath.string(), background.GetBodySourceCode());
}
void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath)
{
ZBlob* blob = ZBlob::FromFile(blobFilePath);
string name = outPath.stem(); // filename without extension
ZBlob* blob = ZBlob::FromFile(blobFilePath.string());
std::string name = outPath.stem().string(); // filename without extension
string src = blob->GetSourceOutputCode(name);
std::string src = blob->GetSourceOutputCode(name);
File::WriteAllText(outPath, src);
File::WriteAllText(outPath.string(), src);
delete blob;
}
@@ -363,30 +363,30 @@ void BuildAssetModelIntermediette(const fs::path& outPath)
XMLDocument doc;
HLModelIntermediette* mdl = HLModelIntermediette::FromXML(doc.RootElement());
string output = mdl->OutputCode();
std::string output = mdl->OutputCode();
File::WriteAllText(outPath, output);
File::WriteAllText(outPath.string(), output);
delete mdl;
}
void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath)
{
vector<string> split = StringHelper::Split(outPath, "/");
std::vector<std::string> split = StringHelper::Split(outPath.string(), "/");
ZFile* file = new ZFile("", split[split.size() - 2]);
HLAnimationIntermediette* anim = HLAnimationIntermediette::FromXML(animPath);
HLAnimationIntermediette* anim = HLAnimationIntermediette::FromXML(animPath.string());
ZAnimation* zAnim = anim->ToZAnimation();
zAnim->SetName(Path::GetFileNameWithoutExtension(split[split.size() - 1]));
zAnim->parent = file;
zAnim->GetSourceOutputCode(split[split.size() - 2]);
string output = "";
std::string output = "";
output += file->declarations[2]->text + "\n";
output += file->declarations[1]->text + "\n";
output += file->declarations[0]->text + "\n";
File::WriteAllText(outPath, output);
File::WriteAllText(outPath.string(), output);
delete zAnim;
delete file;
+18 -18
View File
@@ -4,16 +4,15 @@
#include "../Path.h"
#include "../StringHelper.h"
using namespace std;
using namespace ELFIO;
ZOverlay::ZOverlay()
{
name = "";
entries = vector<RelocationEntry*>();
entries = std::vector<RelocationEntry*>();
}
ZOverlay::ZOverlay(string nName) : ZOverlay()
ZOverlay::ZOverlay(std::string nName) : ZOverlay()
{
name = nName;
}
@@ -26,26 +25,27 @@ ZOverlay::~ZOverlay()
entries.clear();
}
ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
ZOverlay* ZOverlay::FromBuild(std::string buildPath, std::string cfgFolderPath)
{
string cfgText = File::ReadAllText(cfgFolderPath + "/overlay.cfg");
vector<string> cfgLines = StringHelper::Split(cfgText, "\n");
std::string cfgText = File::ReadAllText(cfgFolderPath + "/overlay.cfg");
std::vector<std::string> cfgLines = StringHelper::Split(cfgText, "\n");
ZOverlay* ovl = new ZOverlay(StringHelper::Strip(cfgLines[0], "\r"));
vector<string> relSections = {".rel.text", ".rel.data", ".rel.rodata"};
vector<string> sections = {".text", ".data", ".rodata"};
std::vector<std::string> relSections = {".rel.text", ".rel.data", ".rel.rodata"};
std::vector<std::string> sections = {".text", ".data", ".rodata"};
int32_t sectionOffs[5] = {0};
vector<RelocationEntry*> textRelocs;
vector<RelocationEntry*> dataRelocs;
vector<RelocationEntry*> rodataRelocs;
std::vector<RelocationEntry*> textRelocs;
std::vector<RelocationEntry*> dataRelocs;
std::vector<RelocationEntry*> rodataRelocs;
// get the elf files
vector<elfio*> readers;
std::vector<elfio*> readers;
for (size_t i = 1; i < cfgLines.size(); i++)
{
string elfPath = buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o";
std::string elfPath =
buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o";
elfio* reader = new elfio();
if (!reader->load(elfPath))
@@ -88,7 +88,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
relocs.get_entry(j, offset, symbol, type, addend);
}
string curSymName;
std::string curSymName;
Elf_Half curSymShndx = SHN_UNDEF;
{
symbol_section_accessor symbols(
@@ -124,7 +124,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
{
Elf_Half shndx = SHN_UNDEF;
Elf64_Addr value;
string name;
std::string name;
Elf_Xword size;
unsigned char bind;
unsigned char type;
@@ -189,9 +189,9 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
return ovl;
}
string ZOverlay::GetSourceOutputCode(const std::string& prefix)
std::string ZOverlay::GetSourceOutputCode(const std::string& prefix)
{
string output = "";
std::string output = "";
output += ".section .ovl\n";
@@ -220,7 +220,7 @@ string ZOverlay::GetSourceOutputCode(const std::string& prefix)
return output;
}
SectionType ZOverlay::GetSectionTypeFromStr(string sectionName)
SectionType ZOverlay::GetSectionTypeFromStr(std::string sectionName)
{
if (sectionName == ".rel.text" || sectionName == ".text")
return SectionType::Text;
+1 -1
View File
@@ -1,8 +1,8 @@
#pragma once
#include <elfio/elfio.hpp>
#include <tinyxml2.h>
#include "../ZResource.h"
#include "tinyxml2.h"
enum SectionType
{
+2 -2
View File
@@ -46,8 +46,8 @@ public:
return output;
};
static std::string GetDirectoryName(const std::string& path)
static std::string GetDirectoryName(const fs::path& path)
{
return fs::path(path).parent_path().u8string();
return path.parent_path().u8string();
};
};
+9 -2
View File
@@ -1,8 +1,8 @@
#pragma once
#include <cstring>
#include <numeric>
#include <stdarg.h>
#include <string.h>
#include <string>
#include <vector>
@@ -66,7 +66,7 @@ public:
static bool EndsWith(const std::string& s, const std::string& input)
{
int32_t inputLen = strlen(input.c_str());
size_t inputLen = strlen(input.c_str());
return s.rfind(input) == (s.size() - inputLen);
}
@@ -92,4 +92,11 @@ public:
return ss.empty() ? s : ss + separator + s;
});
}
static int64_t StrToL(const std::string& str, int32_t base = 10)
{
return std::strtoull(str.c_str(), nullptr, base);
}
static std::string BoolStr(bool b) { return b ? "true" : "false"; }
};
+47 -48
View File
@@ -7,8 +7,6 @@
#include "StringHelper.h"
#include "ZFile.h"
using namespace std;
REGISTER_ZFILENODE(Animation, ZNormalAnimation);
REGISTER_ZFILENODE(PlayerAnimation, ZLinkAnimation);
REGISTER_ZFILENODE(CurveAnimation, ZCurveAnimation);
@@ -26,13 +24,13 @@ void ZAnimation::ParseRawData()
frameCount = BitConverter::ToInt16BE(data, rawDataIndex + 0);
}
void ZAnimation::Save(const std::string& outFolder)
void ZAnimation::Save(const fs::path& outFolder)
{
if (Globals::Instance->testMode)
{
HLAnimationIntermediette* anim = HLAnimationIntermediette::FromZAnimation(this);
string xml = anim->OutputXML();
File::WriteAllText(outFolder + "/" + name + ".anmi", xml);
std::string xml = anim->OutputXML();
File::WriteAllText(outFolder / (name + ".anmi"), xml);
delete anim;
}
@@ -43,20 +41,20 @@ void ZAnimation::ParseXML(tinyxml2::XMLElement* reader)
ZResource::ParseXML(reader);
}
string ZAnimation::GetSourceOutputCode(const std::string& prefix)
std::string ZAnimation::GetSourceOutputCode(const std::string& prefix)
{
return "";
}
ZResourceType ZAnimation::GetResourceType()
ZResourceType ZAnimation::GetResourceType() const
{
return ZResourceType::Animation;
}
ZNormalAnimation::ZNormalAnimation(ZFile* nParent) : ZAnimation(nParent)
{
rotationValues = vector<uint16_t>();
rotationIndices = vector<RotationIndex>();
rotationValues = std::vector<uint16_t>();
rotationIndices = std::vector<RotationIndex>();
limit = 0;
}
@@ -64,10 +62,10 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
{
string defaultPrefix = name.c_str();
std::string defaultPrefix = name.c_str();
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
string headerStr = StringHelper::Sprintf("\n\t{ %i },\n", frameCount);
std::string headerStr = StringHelper::Sprintf("\n\t{ %i },\n", frameCount);
headerStr += StringHelper::Sprintf("\t%sFrameData,\n", defaultPrefix.c_str());
headerStr += StringHelper::Sprintf("\t%sJointIndices,\n", defaultPrefix.c_str());
headerStr += StringHelper::Sprintf("\t%i\n", limit);
@@ -75,8 +73,8 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
GetSourceTypeName(), StringHelper::Sprintf("%s", name.c_str()),
headerStr);
string indicesStr = "";
string valuesStr = " ";
std::string indicesStr = "";
std::string valuesStr = " ";
const uint8_t lineLength = 14;
const uint8_t offset = 0;
@@ -112,19 +110,19 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
return "";
}
size_t ZNormalAnimation::GetRawDataSize()
size_t ZNormalAnimation::GetRawDataSize() const
{
return 16;
}
std::string ZNormalAnimation::GetSourceTypeName()
std::string ZNormalAnimation::GetSourceTypeName() const
{
return "AnimationHeader";
}
void ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
rawData = std::move(nRawData);
rawDataIndex = nRawDataIndex;
@@ -172,12 +170,13 @@ std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
{
string segSymbol = segmentAddress == 0 ?
"NULL" :
parent->GetDeclarationName(
segmentAddress, StringHelper::Sprintf("%sSeg%06X", name.c_str(),
segmentAddress));
string headerStr =
std::string segSymbol =
segmentAddress == 0 ?
"NULL" :
parent->GetDeclarationName(
segmentAddress,
StringHelper::Sprintf("%sSeg%06X", name.c_str(), segmentAddress));
std::string headerStr =
StringHelper::Sprintf("\n\t{ %i },\n\t0x%08X\n", frameCount, segmentAddress);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), StringHelper::Sprintf("%s", name.c_str()),
@@ -187,19 +186,19 @@ std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix)
return "";
}
size_t ZLinkAnimation::GetRawDataSize()
size_t ZLinkAnimation::GetRawDataSize() const
{
return 8;
}
std::string ZLinkAnimation::GetSourceTypeName()
std::string ZLinkAnimation::GetSourceTypeName() const
{
return "LinkAnimationHeader";
}
void ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
rawData = std::move(nRawData);
rawDataIndex = nRawDataIndex;
@@ -240,7 +239,7 @@ std::string TransformData::GetBody(const std::string& prefix) const
unk_08);
}
size_t TransformData::GetRawDataSize()
size_t TransformData::GetRawDataSize() const
{
return 0x0C;
}
@@ -287,9 +286,9 @@ void ZCurveAnimation::ParseRawData()
void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
skel = new ZSkeleton(ZSkeletonType::Curve, ZLimbType::Curve, "CurveAnim", nRawData,
Seg2Filespace(skelOffset, parent->baseAddress), parent);
@@ -342,10 +341,10 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix)
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
string refIndexStr =
std::string refIndexStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", refIndexOffset);
string entryStr = " ";
std::string entryStr = " ";
uint16_t arrayItemCnt = refIndexArr.size();
size_t i = 0;
@@ -370,11 +369,11 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix)
if (transformData != 0)
{
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
string transformDataStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(),
TransformData::GetSourceTypeName().c_str(), transformDataOffset);
std::string transformDataStr = StringHelper::Sprintf(
"%sCurveAnime_%s_%06X", prefix.c_str(),
transformDataArr.at(0).GetSourceTypeName().c_str(), transformDataOffset);
string entryStr = "";
std::string entryStr = "";
uint16_t arrayItemCnt = transformDataArr.size();
size_t i = 0;
@@ -388,9 +387,9 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix)
if (decl == nullptr)
{
parent->AddDeclarationArray(transformDataOffset, DeclarationAlignment::None,
arrayItemCnt * TransformData::GetRawDataSize(),
TransformData::GetSourceTypeName(), transformDataStr,
arrayItemCnt, entryStr);
arrayItemCnt * transformDataArr.at(0).GetRawDataSize(),
transformDataArr.at(0).GetSourceTypeName(),
transformDataStr, arrayItemCnt, entryStr);
}
else
{
@@ -401,10 +400,10 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix)
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
string copyValuesStr =
std::string copyValuesStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", copyValuesOffset);
string entryStr = " ";
std::string entryStr = " ";
uint16_t arrayItemCnt = copyValuesArr.size();
size_t i = 0;
@@ -427,19 +426,19 @@ void ZCurveAnimation::PreGenValues(const std::string& prefix)
}
}
size_t ZCurveAnimation::GetRawDataSize()
size_t ZCurveAnimation::GetRawDataSize() const
{
return 0x10;
}
std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
{
string bodyStr = "";
std::string bodyStr = "";
uint32_t address = Seg2Filespace(rawDataIndex, parent->baseAddress);
PreGenValues(prefix);
string refIndexStr = "NULL";
std::string refIndexStr = "NULL";
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
@@ -455,16 +454,16 @@ std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
}
}
string transformDataStr = "NULL";
std::string transformDataStr = "NULL";
if (transformData != 0)
{
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(transformDataOffset);
if (decl == nullptr)
{
transformDataStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(),
TransformData::GetSourceTypeName().c_str(),
transformDataOffset);
transformDataStr = StringHelper::Sprintf(
"%sCurveAnime_%s_%06X", prefix.c_str(),
transformDataArr.at(0).GetSourceTypeName().c_str(), transformDataOffset);
}
else
{
@@ -472,7 +471,7 @@ std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
}
}
string copyValuesStr = "NULL";
std::string copyValuesStr = "NULL";
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
@@ -506,7 +505,7 @@ std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
return "";
}
std::string ZCurveAnimation::GetSourceTypeName()
std::string ZCurveAnimation::GetSourceTypeName() const
{
return "TransformUpdateIndex";
}
+13 -13
View File
@@ -29,11 +29,11 @@ public:
ZAnimation(ZFile* nParent);
std::string GetSourceOutputCode(const std::string& prefix) override;
ZResourceType GetResourceType() override;
ZResourceType GetResourceType() const override;
protected:
void ParseRawData() override;
void Save(const std::string& outFolder) override;
void Save(const fs::path& outFolder) override;
void ParseXML(tinyxml2::XMLElement* reader) override;
};
@@ -49,11 +49,11 @@ public:
ZNormalAnimation(ZFile* nParent);
std::string GetSourceOutputCode(const std::string& prefix) override;
size_t GetRawDataSize() override;
std::string GetSourceTypeName() override;
size_t GetRawDataSize() const override;
std::string GetSourceTypeName() const override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
const uint32_t nRawDataIndex) override;
protected:
virtual void ParseRawData() override;
@@ -67,11 +67,11 @@ public:
ZLinkAnimation(ZFile* nParent);
std::string GetSourceOutputCode(const std::string& prefix) override;
size_t GetRawDataSize() override;
std::string GetSourceTypeName() override;
size_t GetRawDataSize() const override;
std::string GetSourceTypeName() const override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
const uint32_t nRawDataIndex) override;
protected:
virtual void ParseRawData() override;
@@ -101,8 +101,8 @@ public:
[[nodiscard]] std::string GetBody(const std::string& prefix) const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
size_t GetRawDataSize() const;
std::string GetSourceTypeName();
};
class ZCurveAnimation : public ZAnimation
@@ -134,12 +134,12 @@ public:
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
const uint32_t nRawDataIndex) override;
void PreGenValues(const std::string& prefix);
size_t GetRawDataSize() override;
size_t GetRawDataSize() const override;
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceTypeName() override;
std::string GetSourceTypeName() const override;
};
// TransformUpdateIndex
+2 -2
View File
@@ -63,13 +63,13 @@ std::string ZArray::GetSourceOutputCode(const std::string& prefix)
return "";
}
size_t ZArray::GetRawDataSize()
size_t ZArray::GetRawDataSize() const
{
return arrayCnt * testFile->resources[0]->GetRawDataSize();
}
void ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
rawData = nRawData;
rawDataIndex = nRawDataIndex;
+2 -4
View File
@@ -14,14 +14,12 @@ public:
void ParseXML(tinyxml2::XMLElement* reader) override;
std::string GetSourceOutputCode(const std::string& prefix) override;
size_t GetRawDataSize() override;
size_t GetRawDataSize() const override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
const uint32_t nRawDataIndex) override;
protected:
size_t arrayCnt;
ZFile* testFile;
// void ParseRawData(const std::vector<uint8_t>& data, const int32_t offset);
};
+14 -14
View File
@@ -50,10 +50,10 @@ void ZBackground::ParseRawData()
void ZBackground::ParseBinaryFile(const std::string& inFolder, bool appendOutName)
{
fs::path filepath(inFolder);
if (appendOutName)
{
filepath = filepath / (outName + "." + GetExternalExtension());
}
data = File::ReadAllBytes(filepath.string());
// Add padding.
@@ -62,9 +62,9 @@ void ZBackground::ParseBinaryFile(const std::string& inFolder, bool appendOutNam
}
void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, const std::string& nRelPath)
uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar("", "");
}
@@ -128,13 +128,13 @@ void ZBackground::CheckValidJpeg(const std::string& filepath)
}
}
size_t ZBackground::GetRawDataSize()
size_t ZBackground::GetRawDataSize() const
{
// Jpgs use the whole sceen buffer, which is a u16 matrix.
return Globals::Instance->cfg.bgScreenHeight * Globals::Instance->cfg.bgScreenWidth * 2;
}
void ZBackground::DeclareVar(const std::string& prefix, const std::string& bodyStr)
void ZBackground::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
{
std::string auxName = name;
@@ -142,23 +142,23 @@ void ZBackground::DeclareVar(const std::string& prefix, const std::string& bodyS
auxName = GetDefaultName(prefix, rawDataIndex);
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
GetSourceTypeName(), auxName, 0, bodyStr);
GetSourceTypeName(), auxName, "SCREEN_WIDTH * SCREEN_HEIGHT / 4",
bodyStr);
}
bool ZBackground::IsExternalResource()
bool ZBackground::IsExternalResource() const
{
return true;
}
std::string ZBackground::GetExternalExtension()
std::string ZBackground::GetExternalExtension() const
{
return "jpg";
}
void ZBackground::Save(const std::string& outFolder)
void ZBackground::Save(const fs::path& outFolder)
{
fs::path folder(outFolder);
fs::path filepath = folder / (outName + "." + GetExternalExtension());
fs::path filepath = outFolder / (outName + "." + GetExternalExtension());
File::WriteAllBytes(filepath.string(), data);
}
@@ -198,12 +198,12 @@ std::string ZBackground::GetDefaultName(const std::string& prefix, uint32_t addr
return StringHelper::Sprintf("%sBackground_%06X", prefix.c_str(), address);
}
std::string ZBackground::GetSourceTypeName()
std::string ZBackground::GetSourceTypeName() const
{
return "u64";
}
ZResourceType ZBackground::GetResourceType()
ZResourceType ZBackground::GetResourceType() const
{
return ZResourceType::Background;
}
+8 -9
View File
@@ -16,22 +16,21 @@ public:
void ParseRawData() override;
void ParseBinaryFile(const std::string& inFolder, bool appendOutName);
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, const std::string& nRelPath) override;
uint32_t nRawDataIndex) override;
void CheckValidJpeg(const std::string& filepath);
size_t GetRawDataSize() override;
size_t GetRawDataSize() const override;
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
bool IsExternalResource() override;
std::string GetExternalExtension() override;
void Save(const std::string& outFolder) override;
void DeclareVar(const std::string& prefix, const std::string& bodyStr) const;
bool IsExternalResource() const override;
std::string GetExternalExtension() const override;
void Save(const fs::path& outFolder) override;
std::string GetBodySourceCode();
std::string GetSourceOutputCode(const std::string& prefix) override;
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
std::string GetSourceTypeName() override;
ZResourceType GetResourceType() override;
std::string GetSourceTypeName() const override;
ZResourceType GetResourceType() const override;
};
+11 -13
View File
@@ -6,7 +6,6 @@
#include "ZFile.h"
using namespace tinyxml2;
using namespace std;
REGISTER_ZFILENODE(Blob, ZBlob);
@@ -20,20 +19,19 @@ ZBlob::ZBlob(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, size_
{
rawDataIndex = nRawDataIndex;
rawData =
vector<uint8_t>(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size);
std::vector<uint8_t>(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size);
name = std::move(nName);
}
void ZBlob::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
rawDataIndex = nRawDataIndex;
ParseXML(reader);
long size = strtol(reader->Attribute("Size"), NULL, 16);
rawData =
vector<uint8_t>(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size);
relativePath = std::move(nRelPath);
std::vector<uint8_t>(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size);
}
// Build Source File Mode
@@ -58,7 +56,7 @@ ZBlob* ZBlob::FromFile(const std::string& filePath)
return blob;
}
string ZBlob::GetSourceOutputCode(const std::string& prefix)
std::string ZBlob::GetSourceOutputCode(const std::string& prefix)
{
sourceOutput = "";
@@ -81,32 +79,32 @@ string ZBlob::GetSourceOutputCode(const std::string& prefix)
return sourceOutput;
}
string ZBlob::GetSourceOutputHeader(const std::string& prefix)
std::string ZBlob::GetSourceOutputHeader(const std::string& prefix)
{
return StringHelper::Sprintf("extern u8 %s[];\n", name.c_str());
}
void ZBlob::Save(const std::string& outFolder)
void ZBlob::Save(const fs::path& outFolder)
{
File::WriteAllBytes(outFolder + "/" + name + ".bin", rawData);
File::WriteAllBytes(outFolder / (name + ".bin"), rawData);
}
bool ZBlob::IsExternalResource()
bool ZBlob::IsExternalResource() const
{
return true;
}
string ZBlob::GetExternalExtension()
std::string ZBlob::GetExternalExtension() const
{
return "bin";
}
std::string ZBlob::GetSourceTypeName()
std::string ZBlob::GetSourceTypeName() const
{
return "u8";
}
ZResourceType ZBlob::GetResourceType()
ZResourceType ZBlob::GetResourceType() const
{
return ZResourceType::Blob;
}
+6 -7
View File
@@ -11,17 +11,16 @@ public:
std::string nName, ZFile* nParent);
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex,
const std::string& nRelPath) override; // Extract Mode
const uint32_t nRawDataIndex) override; // Extract Mode
static ZBlob* BuildFromXML(tinyxml2::XMLElement* reader, const std::string& inFolder,
bool readFile);
static ZBlob* FromFile(const std::string& filePath);
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
void Save(const std::string& outFolder) override;
bool IsExternalResource() override;
std::string GetExternalExtension() override;
std::string GetSourceTypeName() override;
ZResourceType GetResourceType() override;
void Save(const fs::path& outFolder) override;
bool IsExternalResource() const override;
std::string GetExternalExtension() const override;
std::string GetSourceTypeName() const override;
ZResourceType GetResourceType() const override;
};
+6 -8
View File
@@ -5,8 +5,6 @@
#include "Globals.h"
#include "StringHelper.h"
using namespace std;
REGISTER_ZFILENODE(Collision, ZCollisionHeader);
ZCollisionHeader::ZCollisionHeader(ZFile* nParent) : ZResource(nParent)
@@ -21,16 +19,16 @@ ZCollisionHeader::~ZCollisionHeader()
delete camData;
}
ZResourceType ZCollisionHeader::GetResourceType()
ZResourceType ZCollisionHeader::GetResourceType() const
{
return ZResourceType::CollisionHeader;
}
void ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
}
void ZCollisionHeader::ParseRawData()
@@ -91,7 +89,7 @@ void ZCollisionHeader::ParseRawData()
rawData,
waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16))));
string declaration = "";
std::string declaration = "";
if (waterBoxes.size() > 0)
{
@@ -245,7 +243,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
uint32_t polyTypeDefSegmentOffset, uint32_t polygonTypesCnt)
{
string declaration = "";
std::string declaration = "";
// Parse CameraDataEntries
int32_t numElements = (polyTypeDefSegmentOffset - rawDataIndex) / 8;
@@ -286,7 +284,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
index);
}
else
sprintf(camSegLine, "0x%08X", entries[i]->cameraPosDataSeg);
sprintf(camSegLine, "NULL");
declaration +=
StringHelper::Sprintf(" { 0x%04X, %i, %s },", entries[i]->cameraSType,
+2 -2
View File
@@ -90,9 +90,9 @@ public:
ZCollisionHeader(ZFile* nParent);
~ZCollisionHeader();
ZResourceType GetResourceType() override;
ZResourceType GetResourceType() const override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
const uint32_t nRawDataIndex) override;
void ParseRawData() override;
};
+83 -86
View File
@@ -3,8 +3,6 @@
#include "StringHelper.h"
#include "ZResource.h"
using namespace std;
REGISTER_ZFILENODE(Cutscene, ZCutscene);
ZCutscene::ZCutscene(ZFile* nParent) : ZCutsceneBase(nParent)
@@ -86,9 +84,9 @@ CutsceneCommandSceneTransFX::~CutsceneCommandSceneTransFX()
{
}
string ZCutscene::GetBodySourceCode()
std::string ZCutscene::GetBodySourceCode()
{
string output = "";
std::string output = "";
size_t size = 0;
uint32_t curPtr = 0;
@@ -107,7 +105,7 @@ string ZCutscene::GetBodySourceCode()
return output;
}
string ZCutscene::GetSourceOutputCode(const std::string& prefix)
std::string ZCutscene::GetSourceOutputCode(const std::string& prefix)
{
std::string bodyStr = GetBodySourceCode();
@@ -121,20 +119,19 @@ string ZCutscene::GetSourceOutputCode(const std::string& prefix)
return "";
}
void ZCutscene::DeclareVar(const std::string& prefix, const std::string& bodyStr)
void ZCutscene::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
{
std::string auxName = name;
if (auxName == "")
auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex);
// auxName = GetDefaultName(prefix, getSegmentOffset());
parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4,
DeclarationPadding::Pad16, GetRawDataSize(), "s32", auxName, 0,
bodyStr);
}
size_t ZCutscene::GetRawDataSize()
size_t ZCutscene::GetRawDataSize() const
{
size_t size = 0;
@@ -155,16 +152,16 @@ size_t ZCutscene::GetRawDataSize()
}
void ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar(parent->GetName(), "");
}
void ZCutscene::ParseRawData()
{
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
commands = vector<CutsceneCommand*>();
commands = std::vector<CutsceneCommand*>();
endFrame = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
uint32_t currentPtr = rawDataIndex + 8;
@@ -442,12 +439,12 @@ CutsceneCommands ZCutscene::GetCommandFromID(int32_t id)
return CutsceneCommands::Error;
}
ZResourceType ZCutscene::GetResourceType()
ZResourceType ZCutscene::GetResourceType() const
{
return ZResourceType::Cutscene;
}
CutsceneCommand::CutsceneCommand(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
CutsceneCommand::CutsceneCommand(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
}
@@ -455,12 +452,12 @@ CutsceneCommand::~CutsceneCommand()
{
}
string CutsceneCommand::GetCName()
std::string CutsceneCommand::GetCName()
{
return "SCmdCutsceneData";
}
string CutsceneCommand::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommand::GenerateSourceCode(uint32_t baseAddress)
{
return StringHelper::Sprintf("%s CutsceneData%04XCmd%02X = { 0x%02X,", GetCName().c_str(),
baseAddress, commandIndex, commandID);
@@ -471,7 +468,7 @@ size_t CutsceneCommand::GetCommandSize()
return 4;
}
CutsceneCameraPoint::CutsceneCameraPoint(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
CutsceneCameraPoint::CutsceneCameraPoint(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
@@ -487,7 +484,7 @@ CutsceneCameraPoint::CutsceneCameraPoint(const vector<uint8_t>& rawData, uint32_
unused = BitConverter::ToInt16BE(data, rawDataIndex + 14);
}
CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>& rawData,
CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -498,7 +495,7 @@ CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>&
endFrame = BitConverter::ToUInt16BE(data, rawDataIndex + 4);
unused = BitConverter::ToUInt16BE(data, rawDataIndex + 6);
entries = vector<CutsceneCameraPoint*>();
entries = std::vector<CutsceneCameraPoint*>();
bool shouldContinue = true;
@@ -517,17 +514,17 @@ CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>&
}
// TODO
string CutsceneCommandSetCameraPos::GetCName()
std::string CutsceneCommandSetCameraPos::GetCName()
{
return "";
}
string CutsceneCommandSetCameraPos::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandSetCameraPos::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
string listStr = "";
string posStr = "";
std::string listStr = "";
std::string posStr = "";
if (commandID == (int32_t)CutsceneCommands::SetCameraFocus)
{
@@ -569,7 +566,7 @@ size_t CutsceneCommandSetCameraPos::GetCommandSize()
return 8 + (entries.size() * 16);
}
MusicFadeEntry::MusicFadeEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
MusicFadeEntry::MusicFadeEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
base = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0);
startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2);
@@ -590,7 +587,7 @@ MusicFadeEntry::MusicFadeEntry(const vector<uint8_t>& rawData, uint32_t rawDataI
rawDataIndex + 44); // Macro hardcodes it as zero
}
CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector<uint8_t>& rawData,
CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -605,14 +602,14 @@ CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector<uint8_t>& rawData,
}
}
string CutsceneCommandFadeBGM::GetCName()
std::string CutsceneCommandFadeBGM::GetCName()
{
return "CsCmdMusicFade";
}
string CutsceneCommandFadeBGM::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandFadeBGM::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_FADE_BGM_LIST(%i),\n", entries.size());
@@ -633,7 +630,7 @@ size_t CutsceneCommandFadeBGM::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 0x30 * entries.size();
}
MusicChangeEntry::MusicChangeEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
MusicChangeEntry::MusicChangeEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
sequence = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0);
startFrame = BitConverter::ToUInt16BE(rawData, rawDataIndex + 2);
@@ -648,7 +645,7 @@ MusicChangeEntry::MusicChangeEntry(const vector<uint8_t>& rawData, uint32_t rawD
unknown7 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 32);
}
CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector<uint8_t>& rawData,
CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -663,9 +660,9 @@ CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector<uint8_t>& rawData,
}
}
string CutsceneCommandPlayBGM::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandPlayBGM::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_PLAY_BGM_LIST(%i),\n", entries.size());
@@ -681,7 +678,7 @@ string CutsceneCommandPlayBGM::GenerateSourceCode(uint32_t baseAddress)
return result;
}
string CutsceneCommandPlayBGM::GetCName()
std::string CutsceneCommandPlayBGM::GetCName()
{
return "CsCmdMusicChange";
}
@@ -691,7 +688,7 @@ size_t CutsceneCommandPlayBGM::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 0x30;
}
CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector<uint8_t>& rawData,
CutsceneCommandStopBGM::CutsceneCommandStopBGM(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -706,9 +703,9 @@ CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector<uint8_t>& rawData,
}
}
string CutsceneCommandStopBGM::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandStopBGM::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_STOP_BGM_LIST(%i),\n", entries.size());
@@ -724,7 +721,7 @@ string CutsceneCommandStopBGM::GenerateSourceCode(uint32_t baseAddress)
return result;
}
string CutsceneCommandStopBGM::GetCName()
std::string CutsceneCommandStopBGM::GetCName()
{
return "CsCmdMusicChange";
}
@@ -734,7 +731,7 @@ size_t CutsceneCommandStopBGM::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 0x30;
}
EnvLightingEntry::EnvLightingEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
EnvLightingEntry::EnvLightingEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
setting = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@@ -749,7 +746,7 @@ EnvLightingEntry::EnvLightingEntry(const vector<uint8_t>& rawData, uint32_t rawD
unused7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32);
}
CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector<uint8_t>& rawData,
CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -764,9 +761,9 @@ CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector<uint8_t>& ra
}
}
string CutsceneCommandEnvLighting::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandEnvLighting::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_LIGHTING_LIST(%i),\n", entries.size());
@@ -782,7 +779,7 @@ string CutsceneCommandEnvLighting::GenerateSourceCode(uint32_t baseAddress)
return result;
}
string CutsceneCommandEnvLighting::GetCName()
std::string CutsceneCommandEnvLighting::GetCName()
{
return "CsCmdEnvLighting";
}
@@ -792,7 +789,7 @@ size_t CutsceneCommandEnvLighting::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (0x30 * entries.size());
}
Unknown9Entry::Unknown9Entry(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
Unknown9Entry::Unknown9Entry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@@ -805,7 +802,7 @@ Unknown9Entry::Unknown9Entry(const vector<uint8_t>& rawData, uint32_t rawDataInd
;
}
CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector<uint8_t>& rawData,
CutsceneCommandUnknown9::CutsceneCommandUnknown9(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -820,9 +817,9 @@ CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector<uint8_t>& rawData,
}
}
string CutsceneCommandUnknown9::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandUnknown9::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_CMD_09_LIST(%i),\n", entries.size());
@@ -837,7 +834,7 @@ string CutsceneCommandUnknown9::GenerateSourceCode(uint32_t baseAddress)
return result;
}
string CutsceneCommandUnknown9::GetCName()
std::string CutsceneCommandUnknown9::GetCName()
{
return "CsCmdUnknown9";
}
@@ -847,7 +844,7 @@ size_t CutsceneCommandUnknown9::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 12);
}
UnkEntry::UnkEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
UnkEntry::UnkEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
unused0 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
unused1 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
@@ -863,7 +860,7 @@ UnkEntry::UnkEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
unused11 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 44);
}
CutsceneCommandUnknown::CutsceneCommandUnknown(const vector<uint8_t>& rawData,
CutsceneCommandUnknown::CutsceneCommandUnknown(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -878,9 +875,9 @@ CutsceneCommandUnknown::CutsceneCommandUnknown(const vector<uint8_t>& rawData,
}
}
string CutsceneCommandUnknown::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandUnknown::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%02X, %i),\n", commandID, entries.size());
@@ -896,7 +893,7 @@ string CutsceneCommandUnknown::GenerateSourceCode(uint32_t baseAddress)
return result;
}
string CutsceneCommandUnknown::GetCName()
std::string CutsceneCommandUnknown::GetCName()
{
return "CsCmdUnknown1A";
}
@@ -906,7 +903,7 @@ size_t CutsceneCommandUnknown::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 0x30);
}
DayTimeEntry::DayTimeEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
DayTimeEntry::DayTimeEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@@ -916,7 +913,7 @@ DayTimeEntry::DayTimeEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex
unused = rawData[rawDataIndex + 8];
}
CutsceneCommandDayTime::CutsceneCommandDayTime(const vector<uint8_t>& rawData,
CutsceneCommandDayTime::CutsceneCommandDayTime(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -931,14 +928,14 @@ CutsceneCommandDayTime::CutsceneCommandDayTime(const vector<uint8_t>& rawData,
}
}
string CutsceneCommandDayTime::GetCName()
std::string CutsceneCommandDayTime::GetCName()
{
return "CsCmdDayTime";
}
string CutsceneCommandDayTime::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandDayTime::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_TIME_LIST(%i),\n", entries.size());
@@ -957,7 +954,7 @@ size_t CutsceneCommandDayTime::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 12);
}
TextboxEntry::TextboxEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
TextboxEntry::TextboxEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@@ -967,7 +964,7 @@ TextboxEntry::TextboxEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex
textID2 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
}
CutsceneCommandTextbox::CutsceneCommandTextbox(const vector<uint8_t>& rawData,
CutsceneCommandTextbox::CutsceneCommandTextbox(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -982,14 +979,14 @@ CutsceneCommandTextbox::CutsceneCommandTextbox(const vector<uint8_t>& rawData,
}
}
string CutsceneCommandTextbox::GetCName()
std::string CutsceneCommandTextbox::GetCName()
{
return "CsCmdTextbox";
}
string CutsceneCommandTextbox::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandTextbox::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_TEXT_LIST(%i),\n", entries.size());
@@ -1017,7 +1014,7 @@ size_t CutsceneCommandTextbox::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 12);
}
ActorAction::ActorAction(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
ActorAction::ActorAction(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
@@ -1038,7 +1035,7 @@ ActorAction::ActorAction(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
normalZ = BitConverter::ToInt32BE(data, rawDataIndex + 44);
}
CutsceneCommandActorAction::CutsceneCommandActorAction(const vector<uint8_t>& rawData,
CutsceneCommandActorAction::CutsceneCommandActorAction(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -1053,10 +1050,10 @@ CutsceneCommandActorAction::CutsceneCommandActorAction(const vector<uint8_t>& ra
}
}
string CutsceneCommandActorAction::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandActorAction::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
string subCommand = "";
std::string result = "";
std::string subCommand = "";
if (commandID == 10)
{
@@ -1084,7 +1081,7 @@ string CutsceneCommandActorAction::GenerateSourceCode(uint32_t baseAddress)
return result;
}
string CutsceneCommandActorAction::GetCName()
std::string CutsceneCommandActorAction::GetCName()
{
return "CsCmdBase";
}
@@ -1094,7 +1091,7 @@ size_t CutsceneCommandActorAction::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 0x30);
}
CutsceneCommandTerminator::CutsceneCommandTerminator(const vector<uint8_t>& rawData,
CutsceneCommandTerminator::CutsceneCommandTerminator(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -1106,14 +1103,14 @@ CutsceneCommandTerminator::CutsceneCommandTerminator(const vector<uint8_t>& rawD
unknown = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); // endFrame duplicate
}
string CutsceneCommandTerminator::GetCName()
std::string CutsceneCommandTerminator::GetCName()
{
return "CsCmdBase";
}
string CutsceneCommandTerminator::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandTerminator::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_TERMINATOR(0x%04X, %i, %i),\n", base, startFrame, endFrame);
@@ -1125,7 +1122,7 @@ size_t CutsceneCommandTerminator::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 8;
}
CutsceneCommandEnd::CutsceneCommandEnd(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
CutsceneCommandEnd::CutsceneCommandEnd(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
@@ -1133,16 +1130,16 @@ CutsceneCommandEnd::CutsceneCommandEnd(const vector<uint8_t>& rawData, uint32_t
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
string CutsceneCommandEnd::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandEnd::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_END(),\n");
return result;
}
string CutsceneCommandEnd::GetCName()
std::string CutsceneCommandEnd::GetCName()
{
return "CsCmdBase";
}
@@ -1152,7 +1149,7 @@ size_t CutsceneCommandEnd::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 6;
}
SpecialActionEntry::SpecialActionEntry(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
SpecialActionEntry::SpecialActionEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
@@ -1172,7 +1169,7 @@ SpecialActionEntry::SpecialActionEntry(const vector<uint8_t>& rawData, uint32_t
unused10 = BitConverter::ToUInt32BE(data, rawDataIndex + 44);
}
CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t>& rawData,
CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -1187,9 +1184,9 @@ CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t>
}
}
string CutsceneCommandSpecialAction::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandSpecialAction::GenerateSourceCode(uint32_t baseAddress)
{
string result = "";
std::string result = "";
result += StringHelper::Sprintf("CS_MISC_LIST(%i),\n", entries.size());
@@ -1207,7 +1204,7 @@ string CutsceneCommandSpecialAction::GenerateSourceCode(uint32_t baseAddress)
return result;
}
string CutsceneCommandSpecialAction::GetCName()
std::string CutsceneCommandSpecialAction::GetCName()
{
return "CsCmdBase";
}
@@ -1217,7 +1214,7 @@ size_t CutsceneCommandSpecialAction::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (0x30 * entries.size());
}
CutsceneCommandNop::CutsceneCommandNop(const vector<uint8_t>& rawData, uint32_t rawDataIndex)
CutsceneCommandNop::CutsceneCommandNop(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
@@ -1225,7 +1222,7 @@ CutsceneCommandNop::CutsceneCommandNop(const vector<uint8_t>& rawData, uint32_t
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
string CutsceneCommandNop::GetCName()
std::string CutsceneCommandNop::GetCName()
{
return "CsCmdBase";
}
@@ -1235,7 +1232,7 @@ size_t CutsceneCommandNop::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 6;
}
CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector<uint8_t>& rawData,
CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const std::vector<uint8_t>& rawData,
uint32_t rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
@@ -1246,12 +1243,12 @@ CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector<uint8_t>&
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
}
string CutsceneCommandSceneTransFX::GenerateSourceCode(uint32_t baseAddress)
std::string CutsceneCommandSceneTransFX::GenerateSourceCode(uint32_t baseAddress)
{
return StringHelper::Sprintf("CS_SCENE_TRANS_FX(%i, %i, %i),\n", base, startFrame, endFrame);
}
string CutsceneCommandSceneTransFX::GetCName()
std::string CutsceneCommandSceneTransFX::GetCName()
{
return "CsCmdBase";
}
+7 -7
View File
@@ -413,8 +413,8 @@ class ZCutsceneBase : public ZResource
public:
ZCutsceneBase(ZFile* nParent);
virtual std::string GetBodySourceCode() = 0;
virtual void DeclareVar(const std::string& prefix, const std::string& bodyStr) = 0;
virtual uint32_t getSegmentOffset() = 0;
virtual void DeclareVar(const std::string& prefix, const std::string& bodyStr) const = 0;
virtual uint32_t getSegmentOffset() const = 0;
};
class ZCutscene : public ZCutsceneBase
@@ -424,16 +424,16 @@ public:
~ZCutscene();
std::string GetBodySourceCode() override;
void DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
void DeclareVar(const std::string& prefix, const std::string& bodyStr) const override;
std::string GetSourceOutputCode(const std::string& prefix) override;
size_t GetRawDataSize() override;
size_t GetRawDataSize() const override;
CutsceneCommands GetCommandFromID(int32_t id);
uint32_t getSegmentOffset() override { return rawDataIndex; }
uint32_t getSegmentOffset() const override { return rawDataIndex; }
ZResourceType GetResourceType() override;
ZResourceType GetResourceType() const override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
const uint32_t nRawDataIndex) override;
protected:
int32_t numCommands;
+9 -12
View File
@@ -2,8 +2,6 @@
#include "BitConverter.h"
#include "StringHelper.h"
using namespace std;
ZCutsceneMM::ZCutsceneMM(ZFile* nParent) : ZCutsceneBase(nParent)
{
}
@@ -14,9 +12,9 @@ ZCutsceneMM::~ZCutsceneMM()
delete cmd;
}
string ZCutsceneMM::GetBodySourceCode()
std::string ZCutsceneMM::GetBodySourceCode()
{
string output = "";
std::string output = "";
output += StringHelper::Sprintf(" CS_BEGIN_CUTSCENE(%i, %i),", numCommands, endFrame);
@@ -30,7 +28,7 @@ string ZCutsceneMM::GetBodySourceCode()
return output;
}
string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
std::string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
{
std::string bodyStr = GetBodySourceCode();
@@ -44,27 +42,26 @@ string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
return "";
}
void ZCutsceneMM::DeclareVar(const std::string& prefix, const std::string& bodyStr)
void ZCutsceneMM::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
{
std::string auxName = name;
if (auxName == "")
auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex);
// auxName = GetDefaultName(prefix, getSegmentOffset());
parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4, GetRawDataSize(),
"s32", auxName, 0, bodyStr);
}
size_t ZCutsceneMM::GetRawDataSize()
size_t ZCutsceneMM::GetRawDataSize() const
{
return 8 + data.size() * 4;
}
void ZCutsceneMM::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar(parent->GetName(), "");
}
@@ -73,7 +70,7 @@ void ZCutsceneMM::ParseRawData()
segmentOffset = rawDataIndex;
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
commands = vector<CutsceneCommand*>();
commands = std::vector<CutsceneCommand*>();
endFrame = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
uint32_t currentPtr = rawDataIndex + 8;
@@ -89,7 +86,7 @@ void ZCutsceneMM::ParseRawData()
} while (lastData != 0xFFFFFFFF);
}
ZResourceType ZCutsceneMM::GetResourceType()
ZResourceType ZCutsceneMM::GetResourceType() const
{
return ZResourceType::Cutscene;
}
+5 -5
View File
@@ -16,16 +16,16 @@ public:
virtual ~ZCutsceneMM();
std::string GetBodySourceCode() override;
void DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
void DeclareVar(const std::string& prefix, const std::string& bodyStr) const override;
std::string GetSourceOutputCode(const std::string& prefix) override;
size_t GetRawDataSize() override;
uint32_t getSegmentOffset() override { return segmentOffset; }
size_t GetRawDataSize() const override;
uint32_t getSegmentOffset() const override { return segmentOffset; }
void ParseRawData() override;
ZResourceType GetResourceType() override;
ZResourceType GetResourceType() const override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
const uint32_t nRawDataIndex) override;
protected:
int32_t numCommands;
File diff suppressed because it is too large Load Diff
+15 -34
View File
@@ -4,6 +4,7 @@
#include "ZResource.h"
#include "ZRoom/ZRoom.h"
#include "ZTexture.h"
#include "ZVtx.h"
#include "tinyxml2.h"
#include <map>
@@ -282,20 +283,6 @@ enum class OoTSegments
#define FORCE_BL 0x4000
#define TEX_EDGE 0x0000
class Vertex
{
public:
int16_t x, y, z;
uint16_t flag;
int16_t s, t;
uint8_t r, g, b, a;
Vertex();
Vertex(int16_t nX, int16_t nY, int16_t nZ, uint16_t nFlag, int16_t nS, int16_t nT, uint8_t nR,
uint8_t nG, uint8_t nB, uint8_t nA);
Vertex(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
};
class ZDisplayList : public ZResource
{
protected:
@@ -350,14 +337,12 @@ public:
DListType dListType;
// int32_t dListAddress;
std::map<uint32_t, std::vector<Vertex>> vertices;
std::map<uint32_t, std::vector<ZVtx>> vertices;
std::map<uint32_t, std::string> vtxDeclarations;
std::vector<ZDisplayList*> otherDLists;
std::map<uint32_t, ZTexture*> textures;
std::map<uint32_t, std::string> texDeclarations;
ZTexture* lastTexture = nullptr;
ZTexture* lastTlut = nullptr;
std::vector<uint32_t> references;
@@ -371,31 +356,27 @@ public:
~ZDisplayList();
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
// static ZDisplayList* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, bool
// readFile, ZFile* nParent);
const uint32_t nRawDataIndex) override;
void TextureGenCheck(std::string prefix);
static bool TextureGenCheck(std::vector<uint8_t> fileData,
std::map<uint32_t, ZTexture*>& textures, ZRoom* scene,
ZFile* parent, std::string prefix, int32_t texWidth,
int32_t texHeight, uint32_t texAddr, uint32_t texSeg,
F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded,
bool texIsPalette);
static bool TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene, ZFile* parent,
std::string prefix, int32_t texWidth, int32_t texHeight,
uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt,
F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette,
ZDisplayList* self);
static int32_t GetDListLength(std::vector<uint8_t> rawData, uint32_t rawDataIndex,
DListType dListType);
size_t GetRawDataSize() override;
size_t GetRawDataSize() const override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string ProcessLegacy(const std::string& prefix);
std::string ProcessGfxDis(const std::string& prefix);
void Save(const std::string& outFolder) override;
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile) override;
bool IsExternalResource() override;
virtual std::string GetExternalExtension() override;
std::string GetSourceTypeName() override;
bool IsExternalResource() const override;
virtual std::string GetExternalExtension() const override;
std::string GetSourceTypeName() const override;
ZResourceType GetResourceType() override;
ZResourceType GetResourceType() const override;
};
+295 -211
View File
@@ -26,21 +26,20 @@
#include "ZVtx.h"
using namespace tinyxml2;
using namespace std;
ZFile::ZFile()
{
resources = vector<ZResource*>();
resources = std::vector<ZResource*>();
basePath = "";
outputPath = Directory::GetCurrentDirectory();
declarations = map<uint32_t, Declaration*>();
declarations = std::map<uint32_t, Declaration*>();
defines = "";
baseAddress = 0;
rangeStart = 0x000000000;
rangeEnd = 0xFFFFFFFF;
}
ZFile::ZFile(const fs::path& nOutPath, string nName) : ZFile()
ZFile::ZFile(const fs::path& nOutPath, std::string nName) : ZFile()
{
outputPath = nOutPath;
name = nName;
@@ -63,6 +62,7 @@ ZFile::ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBase
outputPath = nOutPath;
ParseXML(mode, reader, filename, placeholderMode);
DeclareResourceSubReferences();
}
ZFile::~ZFile()
@@ -85,53 +85,55 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
else
name = filename;
int32_t segment = -1;
// TODO: This should be a variable on the ZFile, but it is a large change in order to force all
// ZResource types to have a parent ZFile.
const char* gameStr = reader->Attribute("Game");
if (reader->Attribute("Game") != nullptr)
{
if (string(gameStr) == "MM")
if (std::string(gameStr) == "MM")
Globals::Instance->game = ZGame::MM_RETAIL;
else if (string(gameStr) == "SW97" || string(gameStr) == "OOTSW97")
else if (std::string(gameStr) == "SW97" || std::string(gameStr) == "OOTSW97")
Globals::Instance->game = ZGame::OOT_SW97;
else if (string(gameStr) == "OOT")
else if (std::string(gameStr) == "OOT")
Globals::Instance->game = ZGame::OOT_RETAIL;
else
throw std::runtime_error(
StringHelper::Sprintf("Error: Game type %s not supported.", gameStr));
}
if (reader->Attribute("BaseAddress") != NULL)
baseAddress = (uint32_t)strtoul(
StringHelper::Split(reader->Attribute("BaseAddress"), "0x")[1].c_str(), NULL, 16);
if (reader->Attribute("BaseAddress") != nullptr)
baseAddress = StringHelper::StrToL(reader->Attribute("BaseAddress"), 16);
if (reader->Attribute("RangeStart") != NULL)
rangeStart = (uint32_t)strtoul(
StringHelper::Split(reader->Attribute("RangeStart"), "0x")[1].c_str(), NULL, 16);
if (reader->Attribute("RangeStart") != nullptr)
rangeStart = StringHelper::StrToL(reader->Attribute("RangeStart"), 16);
if (reader->Attribute("RangeEnd") != NULL)
rangeEnd = (uint32_t)strtoul(
StringHelper::Split(reader->Attribute("RangeEnd"), "0x")[1].c_str(), NULL, 16);
if (reader->Attribute("RangeEnd") != nullptr)
rangeEnd = StringHelper::StrToL(reader->Attribute("RangeEnd"), 16);
if (reader->Attribute("Segment") != NULL)
segment = strtol(reader->Attribute("Segment"), NULL, 10);
// Commented until ZArray doesn't use a ZFile to parse it's contents anymore.
/*
if (reader->Attribute("Segment") == nullptr)
throw std::runtime_error(StringHelper::Sprintf(
"ZFile::ParseXML: Error in '%s'.\n"
"\t Missing 'Segment' attribute in File node. \n",
name.c_str()));
*/
if (segment != -1)
if (reader->Attribute("Segment") != nullptr)
{
Globals::Instance->AddSegment(segment);
segment = StringHelper::StrToL(reader->Attribute("Segment"), 10);
Globals::Instance->AddSegment(segment, this);
}
string folderName = basePath / Path::GetFileNameWithoutExtension(name);
std::string folderName = (basePath / Path::GetFileNameWithoutExtension(name)).string();
if (mode == ZFileMode::Extract)
{
if (!File::Exists(basePath / name))
if (!File::Exists((basePath / name).string()))
throw std::runtime_error(
StringHelper::Sprintf("Error! File %s does not exist.", (basePath / name).c_str()));
rawData = File::ReadAllBytes(basePath / name);
rawData = File::ReadAllBytes((basePath / name).string());
}
std::unordered_set<std::string> nameSet;
@@ -148,10 +150,11 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
const char* outNameXml = child->Attribute("OutName");
const char* offsetXml = child->Attribute("Offset");
if (Globals::Instance->verbosity >= VERBOSITY_INFO)
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
printf("%s: 0x%06X\n", nameXml, rawDataIndex);
if (offsetXml != NULL)
// Check for repeated attributes.
if (offsetXml != nullptr)
{
rawDataIndex = strtol(StringHelper::Split(offsetXml, "0x")[1].c_str(), NULL, 16);
@@ -163,7 +166,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
}
offsetSet.insert(offsetXml);
}
if (outNameXml != NULL)
if (outNameXml != nullptr)
{
if (outNameSet.find(outNameXml) != outNameSet.end())
{
@@ -173,7 +176,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
}
outNameSet.insert(outNameXml);
}
if (nameXml != NULL)
if (nameXml != nullptr)
{
if (nameSet.find(nameXml) != nameSet.end())
{
@@ -184,40 +187,24 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
nameSet.insert(nameXml);
}
string nodeName = string(child->Name());
std::string nodeName = std::string(child->Name());
if (nodeMap.find(nodeName) != nodeMap.end())
{
ZResource* nRes = nodeMap[nodeName]();
nRes->parent = this;
ZResource* nRes = nodeMap[nodeName](this);
if (mode == ZFileMode::Extract)
nRes->ExtractFromXML(child, rawData, rawDataIndex, folderName);
nRes->ExtractFromXML(child, rawData, rawDataIndex);
// TODO: See if we can make this part of the ZRoom code...
if (nRes->GetResourceType() == ZResourceType::Room)
{
if (nodeName == "Scene")
{
Globals::Instance->lastScene = (ZRoom*)nRes;
auto resType = nRes->GetResourceType();
if (resType == ZResourceType::Texture)
AddTextureResource(rawDataIndex, static_cast<ZTexture*>(nRes));
else
resources.push_back(nRes);
if (segment == -1)
segment = SEGMENT_SCENE;
}
else
{
if (segment == -1)
segment = SEGMENT_ROOM;
}
if (segment != -1)
Globals::Instance->AddSegment(segment);
}
resources.push_back(nRes);
rawDataIndex += nRes->GetRawDataSize();
}
else if (string(child->Name()) == "File")
else if (std::string(child->Name()) == "File")
{
throw std::runtime_error(StringHelper::Sprintf(
"ZFile::ParseXML: Error in '%s'.\n\t Can't declare a File inside a File.\n",
@@ -233,19 +220,27 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
}
}
void ZFile::DeclareResourceSubReferences()
{
for (size_t i = 0; i < resources.size(); i++)
{
resources.at(i)->DeclareReferences(name);
}
}
void ZFile::BuildSourceFile(fs::path outputDir)
{
string folderName = Path::GetFileNameWithoutExtension(outputPath);
std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string());
if (!Directory::Exists(outputPath))
Directory::CreateDirectory(outputPath);
if (!Directory::Exists(outputPath.string()))
Directory::CreateDirectory(outputPath.string());
GenerateSourceFiles(outputDir);
}
std::string ZFile::GetVarName(uint32_t address)
{
for (pair<uint32_t, Declaration*> pair : declarations)
for (std::pair<uint32_t, Declaration*> pair : declarations)
{
if (pair.first == address)
return pair.second->varName;
@@ -254,20 +249,30 @@ std::string ZFile::GetVarName(uint32_t address)
return "";
}
std::string ZFile::GetName()
std::string ZFile::GetName() const
{
return name;
}
const fs::path& ZFile::GetXmlFilePath() const
{
return xmlFilePath;
}
const std::vector<uint8_t>& ZFile::GetRawData() const
{
return rawData;
}
void ZFile::ExtractResources(fs::path outputDir)
{
string folderName = Path::GetFileNameWithoutExtension(outputPath);
std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string());
if (!Directory::Exists(outputPath))
Directory::CreateDirectory(outputPath);
if (!Directory::Exists(outputPath.string()))
Directory::CreateDirectory(outputPath.string());
if (!Directory::Exists(Globals::Instance->sourceOutputPath))
Directory::CreateDirectory(Globals::Instance->sourceOutputPath);
if (!Directory::Exists(Globals::Instance->sourceOutputPath.string()))
Directory::CreateDirectory(Globals::Instance->sourceOutputPath.string());
for (ZResource* res : resources)
res->PreGenSourceFiles();
@@ -277,10 +282,9 @@ void ZFile::ExtractResources(fs::path outputDir)
for (ZResource* res : resources)
{
if (Globals::Instance->verbosity >= VERBOSITY_INFO)
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
printf("Saving resource %s\n", res->GetName().c_str());
res->CalcHash(); // TEST
res->Save(outputPath);
}
@@ -320,13 +324,7 @@ std::vector<ZResource*> ZFile::GetResourcesOfType(ZResourceType resType)
Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, size_t size,
std::string varType, std::string varName, std::string body)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
{
int32_t bp = 0;
}
#endif
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
Declaration* decl = new Declaration(alignment, size, varType, varName, false, body);
@@ -335,16 +333,10 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm
}
Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment,
DeclarationPadding padding, size_t size, string varType,
string varName, std::string body)
DeclarationPadding padding, size_t size, std::string varType,
std::string varName, std::string body)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
{
int32_t bp = 0;
}
#endif
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
declarations[address] =
@@ -356,13 +348,7 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
size_t size, std::string varType, std::string varName,
size_t arrayItemCnt, std::string body)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
{
int32_t bp = 0;
}
#endif
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
declarations[address] =
@@ -370,17 +356,23 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
return declarations[address];
}
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
size_t size, std::string varType, std::string varName,
std::string arrayItemCntStr, std::string body)
{
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
declarations[address] =
new Declaration(alignment, size, varType, varName, true, arrayItemCntStr, body);
return declarations[address];
}
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
size_t size, std::string varType, std::string varName,
size_t arrayItemCnt, std::string body, bool isExternal)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
{
int32_t bp = 0;
}
#endif
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
declarations[address] =
@@ -389,16 +381,11 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
}
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
DeclarationPadding padding, size_t size, string varType,
string varName, size_t arrayItemCnt, std::string body)
DeclarationPadding padding, size_t size,
std::string varType, std::string varName,
size_t arrayItemCnt, std::string body)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
{
int32_t bp = 0;
}
#endif
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
declarations[address] =
@@ -408,28 +395,44 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address)
{
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
Declaration* decl;
if (declarations.find(address) == declarations.end())
declarations[address] = new Declaration(DeclarationAlignment::None, 0, "", "", false, "");
{
decl = new Declaration(DeclarationAlignment::None, 0, "", "", false, "");
decl->isPlaceholder = true;
declarations[address] = decl;
}
else
decl = declarations[address];
return declarations[address];
return decl;
}
Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, string varName)
Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, std::string varName)
{
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
Declaration* decl;
if (declarations.find(address) == declarations.end())
declarations[address] =
new Declaration(DeclarationAlignment::None, 0, "", varName, false, "");
{
decl = new Declaration(DeclarationAlignment::None, 0, "", varName, false, "");
decl->isPlaceholder = true;
declarations[address] = decl;
}
else
decl = declarations[address];
return declarations[address];
return decl;
}
Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, size_t size,
string varType, string varName)
Declaration* ZFile::AddDeclarationInclude(uint32_t address, std::string includePath, size_t size,
std::string varType, std::string varName)
{
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
if (declarations.find(address) == declarations.end())
@@ -442,18 +445,7 @@ Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string inc
size_t size, std::string varType,
std::string varName, size_t arrayItemCnt)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
{
int32_t bp = 0;
}
if (address == 0)
{
int32_t bp = 0;
}
#endif
assert(GETSEGNUM(address) == 0);
AddDeclarationDebugChecks(address);
if (StringHelper::StartsWith(includePath, "assets/extracted/"))
@@ -488,6 +480,7 @@ Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string inc
void ZFile::AddDeclarationDebugChecks(uint32_t address)
{
assert(GETSEGNUM(address) == 0);
#ifdef _DEBUG
if (address == 0x0000)
{
@@ -496,30 +489,47 @@ void ZFile::AddDeclarationDebugChecks(uint32_t address)
#endif
}
std::string ZFile::GetDeclarationName(uint32_t address)
std::string ZFile::GetDeclarationName(uint32_t address) const
{
return GetDeclarationName(address,
"ERROR_COULD_NOT_FIND_DECLARATION"); // Note: For now that default
// message is just for testing
}
std::string ZFile::GetDeclarationName(uint32_t address, std::string defaultResult)
std::string ZFile::GetDeclarationName(uint32_t address, std::string defaultResult) const
{
if (declarations.find(address) != declarations.end())
return declarations[address]->varName;
Declaration* decl = GetDeclaration(address);
if (decl != nullptr)
return decl->varName;
return defaultResult;
}
Declaration* ZFile::GetDeclaration(uint32_t address)
std::string ZFile::GetDeclarationPtrName(segptr_t segAddress) const
{
if (segAddress == 0)
return "NULL";
Declaration* decl = GetDeclaration(Seg2Filespace(segAddress, baseAddress));
if (!Globals::Instance->HasSegment(GETSEGNUM(segAddress)) || decl == nullptr)
return StringHelper::Sprintf("0x%08X", segAddress);
if (!decl->isArray)
return "&" + decl->varName;
return decl->varName;
}
Declaration* ZFile::GetDeclaration(uint32_t address) const
{
if (declarations.find(address) != declarations.end())
return declarations[address];
return declarations.at(address);
return nullptr;
}
Declaration* ZFile::GetDeclarationRanged(uint32_t address)
Declaration* ZFile::GetDeclarationRanged(uint32_t address) const
{
for (const auto decl : declarations)
{
@@ -530,7 +540,7 @@ Declaration* ZFile::GetDeclarationRanged(uint32_t address)
return nullptr;
}
uint32_t ZFile::GetDeclarationRangedAddress(uint32_t address)
uint32_t ZFile::GetDeclarationRangedAddress(uint32_t address) const
{
for (const auto decl : declarations)
{
@@ -543,7 +553,7 @@ uint32_t ZFile::GetDeclarationRangedAddress(uint32_t address)
bool ZFile::HasDeclaration(uint32_t address)
{
return (declarations.find(address) != declarations.end());
return declarations.find(address) != declarations.end();
}
void ZFile::GenerateSourceFiles(fs::path outputDir)
@@ -558,32 +568,37 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
GeneratePlaceholderDeclarations();
// Generate Code
for (ZResource* res : resources)
for (size_t i = 0; i < resources.size(); i++)
{
string resSrc = res->GetSourceOutputCode(name);
ZResource* res = resources.at(i);
std::string resSrc = res->GetSourceOutputCode(name);
if (res->IsExternalResource())
{
string path = Path::GetFileNameWithoutExtension(res->GetName()).c_str();
std::string path = Path::GetFileNameWithoutExtension(res->GetName()).c_str();
string assetOutDir = outputDir / Path::GetFileNameWithoutExtension(res->GetOutName());
string declType = res->GetSourceTypeName();
std::string assetOutDir =
(outputDir / Path::GetFileNameWithoutExtension(res->GetOutName())).string();
std::string declType = res->GetSourceTypeName();
std::string incStr = StringHelper::Sprintf("%s.%s.inc", assetOutDir.c_str(),
res->GetExternalExtension().c_str());
if (res->GetResourceType() == ZResourceType::Texture)
{
ZTexture* tex = (ZTexture*)res;
ZTexture* tex = static_cast<ZTexture*>(res);
tex->CalcHash();
// TEXTURE POOL CHECK
if (Globals::Instance->cfg.texturePool.find(tex->hash) !=
Globals::Instance->cfg.texturePool.end())
if (!Globals::Instance->cfg.texturePool.empty())
{
incStr = Globals::Instance->cfg.texturePool[tex->hash].path.string() + "." +
res->GetExternalExtension() + ".inc";
tex->CalcHash();
// TEXTURE POOL CHECK
if (Globals::Instance->cfg.texturePool.find(tex->hash) !=
Globals::Instance->cfg.texturePool.end())
{
incStr = Globals::Instance->cfg.texturePool[tex->hash].path.string() + "." +
res->GetExternalExtension() + ".inc";
}
}
incStr += ".c";
@@ -599,7 +614,6 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
}
else
{
// cout << "NOT EXTERN\n";
sourceOutput += resSrc;
}
@@ -609,8 +623,9 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
sourceOutput += ProcessDeclarations();
string outPath =
Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".c");
std::string outPath =
(Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".c"))
.string();
OutputFormatter formatter;
formatter.Write(sourceOutput);
@@ -626,7 +641,7 @@ void ZFile::GenerateSourceHeaderFiles()
for (ZResource* res : resources)
{
string resSrc = res->GetSourceOutputHeader("");
std::string resSrc = res->GetSourceOutputHeader("");
formatter.Write(resSrc);
if (resSrc != "")
@@ -638,7 +653,7 @@ void ZFile::GenerateSourceHeaderFiles()
fs::path headerFilename =
Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".h");
File::WriteAllText(headerFilename, formatter.GetOutput());
File::WriteAllText(headerFilename.string(), formatter.GetOutput());
}
void ZFile::GenerateHLIntermediette()
@@ -673,6 +688,24 @@ void ZFile::GeneratePlaceholderDeclarations()
}
}
void ZFile::AddTextureResource(uint32_t offset, ZTexture* tex)
{
for (auto res : resources)
assert(res->GetRawDataIndex() != offset);
resources.push_back(tex);
texturesResources[offset] = tex;
}
ZTexture* ZFile::GetTextureResource(uint32_t offset) const
{
auto tex = texturesResources.find(offset);
if (tex != texturesResources.end())
return tex->second;
return nullptr;
}
std::map<std::string, ZResourceFactoryFunc*>* ZFile::GetNodeMap()
{
static std::map<std::string, ZResourceFactoryFunc*> nodeMap;
@@ -685,13 +718,15 @@ void ZFile::RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc)
(*nodeMap)[nodeName] = nodeFunc;
}
string ZFile::ProcessDeclarations()
std::string ZFile::ProcessDeclarations()
{
string output = "";
std::string output = "";
if (declarations.size() == 0)
return output;
defines += ProcessTextureIntersections(name);
// Account for padding/alignment
uint32_t lastAddr = 0;
uint32_t lastSize = 0;
@@ -699,16 +734,14 @@ string ZFile::ProcessDeclarations()
// printf("RANGE START: 0x%06X - RANGE END: 0x%06X\n", rangeStart, rangeEnd);
// Optimization: See if there are any arrays side by side that can be merged...
auto declarationKeys =
vector<pair<int32_t, Declaration*>>(declarations.begin(), declarations.end());
sort(declarationKeys.begin(), declarationKeys.end(),
[](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; });
std::vector<std::pair<int32_t, Declaration*>> declarationKeys(declarations.begin(),
declarations.end());
pair<int32_t, Declaration*> lastItem = declarationKeys[0];
std::pair<int32_t, Declaration*> lastItem = declarationKeys.at(0);
for (size_t i = 1; i < declarationKeys.size(); i++)
{
pair<int32_t, Declaration*> curItem = declarationKeys[i];
std::pair<int32_t, Declaration*> curItem = declarationKeys[i];
if (curItem.second->isArray && lastItem.second->isArray)
{
@@ -737,10 +770,10 @@ string ZFile::ProcessDeclarations()
lastItem = curItem;
}
for (pair<uint32_t, Declaration*> item : declarations)
for (std::pair<uint32_t, Declaration*> item : declarations)
ProcessDeclarationText(item.second);
for (pair<uint32_t, Declaration*> item : declarations)
for (std::pair<uint32_t, Declaration*> item : declarations)
{
while (item.second->size % 4 != 0)
item.second->size++;
@@ -865,7 +898,7 @@ string ZFile::ProcessDeclarations()
int diff = currentAddress - unaccountedAddress;
bool nonZeroUnaccounted = false;
string src = " ";
std::string src = " ";
for (int i = 0; i < diff; i++)
{
@@ -927,20 +960,30 @@ string ZFile::ProcessDeclarations()
// Go through include declarations
// First, handle the prototypes (static only for now)
int32_t protoCnt = 0;
for (pair<uint32_t, Declaration*> item : declarations)
for (std::pair<uint32_t, Declaration*> item : declarations)
{
if (StringHelper::StartsWith(item.second->varType, "static ") &&
!item.second->isUnaccounted)
{
if (item.second->isArray)
{
if (item.second->arrayItemCnt == 0)
if (item.second->arrayItemCntStr != "")
{
output += StringHelper::Sprintf("%s %s[%s];\n", item.second->varType.c_str(),
item.second->varName.c_str(),
item.second->arrayItemCntStr.c_str());
}
else if (item.second->arrayItemCnt == 0)
{
output += StringHelper::Sprintf("%s %s[];\n", item.second->varType.c_str(),
item.second->varName.c_str());
}
else
{
output += StringHelper::Sprintf("%s %s[%i];\n", item.second->varType.c_str(),
item.second->varName.c_str(),
item.second->arrayItemCnt);
}
}
else
output += StringHelper::Sprintf("%s %s;\n", item.second->varType.c_str(),
@@ -954,7 +997,7 @@ string ZFile::ProcessDeclarations()
output += "\n";
// Next, output the actual declarations
for (pair<uint32_t, Declaration*> item : declarations)
for (std::pair<uint32_t, Declaration*> item : declarations)
{
if (item.first < rangeStart || item.first >= rangeEnd)
{
@@ -963,11 +1006,6 @@ string ZFile::ProcessDeclarations()
if (item.second->includePath != "")
{
// output += StringHelper::Sprintf("#include \"%s\"\n",
// item.second->includePath.c_str()); output += StringHelper::Sprintf("%s %s[] =
// {\n#include \"%s\"\n};\n\n", item.second->varType.c_str(),
// item.second->varName.c_str(), item.second->includePath.c_str());
if (item.second->isExternal)
{
// HACK
@@ -984,48 +1022,28 @@ string ZFile::ProcessDeclarations()
item.second->text);
}
/*if (item.second->varType == "u64")
output += StringHelper::Sprintf("#pragma INC_ASSET_U64(\"%s\", \"%s\")\n",
item.second->varName.c_str(), item.second->includePath.c_str()); else if
(item.second->varType == "Gfx") output += StringHelper::Sprintf("#pragma
INC_ASSET_GFX(\"%s\", \"%s\")\n", item.second->varName.c_str(),
item.second->includePath.c_str()); else if (item.second->varType == "Vtx" ||
item.second->varType == "static Vtx") output += StringHelper::Sprintf("#pragma
INC_ASSET_VTX(\"%s\", \"%s\")\n", item.second->varName.c_str(),
item.second->includePath.c_str()); else output += StringHelper::Sprintf("#pragma
INC_ASSET_U8(\"%s\", \"%s\")\n", item.second->varName.c_str(),
item.second->includePath.c_str());*/
// Do not asm_process vertex arrays. They have no practical use being overridden.
// if (item.second->varType == "Vtx" || item.second->varType == "static Vtx")
if (item.second->varType != "u64" && item.second->varType != "static u64" &&
item.second->varType != "u8" && item.second->varType != "static u8")
{
// output += StringHelper::Sprintf("%s %s[] = {\n #include \"%s\"\n};\n\n",
// item.second->varType.c_str(), item.second->varName.c_str(),
// StringHelper::Replace(item.second->includePath, "assets/",
// "../assets/extracted/").c_str());
output += StringHelper::Sprintf(
"%s %s[] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(),
item.second->varName.c_str(),
StringHelper::Replace(item.second->includePath, "assets/", "../assets/")
.c_str());
// output += StringHelper::Sprintf("%s %s[] = {\n #include \"%s\"\n};\n\n",
// item.second->varType.c_str(), item.second->varName.c_str(),
// Path::GetFileName(item.second->includePath).c_str());
}
else
{
// output += StringHelper::Sprintf("%s %s[] = {\n #pragma
// INC_ASSET(\"%s\")\n};\n\n", item.second->varType.c_str(),
// item.second->varName.c_str(), item.second->includePath.c_str()); output +=
// StringHelper::Sprintf("%s %s[] = {\n #include \"%s\"\n};\n\n",
// item.second->varType.c_str(), item.second->varName.c_str(),
// StringHelper::Replace(item.second->includePath, "assets/",
// "assets/extracted/").c_str());
output += StringHelper::Sprintf(
"%s %s[] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(),
item.second->varName.c_str(), item.second->includePath.c_str());
if (item.second->arrayItemCntStr != "")
output += StringHelper::Sprintf(
"%s %s[%s] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(),
item.second->varName.c_str(), item.second->arrayItemCntStr.c_str(),
item.second->includePath.c_str());
else
output += StringHelper::Sprintf(
"%s %s[] = {\n #include \"%s\"\n};\n\n", item.second->varType.c_str(),
item.second->varName.c_str(), item.second->includePath.c_str());
}
}
else if (item.second->varType != "")
@@ -1036,14 +1054,23 @@ string ZFile::ProcessDeclarations()
{
if (item.second->isArray)
{
if (item.second->arrayItemCnt == 0)
output +=
StringHelper::Sprintf("%s %s[] = {\n", item.second->varType.c_str(),
item.second->varName.c_str());
else
if (item.second->arrayItemCntStr != "")
{
output += StringHelper::Sprintf(
"%s %s[%i] = {\n", item.second->varType.c_str(),
item.second->varName.c_str(), item.second->arrayItemCnt);
"%s %s[%s];\n", item.second->varType.c_str(),
item.second->varName.c_str(), item.second->arrayItemCntStr.c_str());
}
else
{
if (item.second->arrayItemCnt == 0)
output +=
StringHelper::Sprintf("%s %s[] = {\n", item.second->varType.c_str(),
item.second->varName.c_str());
else
output += StringHelper::Sprintf(
"%s %s[%i] = {\n", item.second->varType.c_str(),
item.second->varName.c_str(), item.second->arrayItemCnt);
}
output += item.second->text + "\n";
}
@@ -1125,11 +1152,11 @@ void ZFile::ProcessDeclarationText(Declaration* decl)
}
}
string ZFile::ProcessExterns()
std::string ZFile::ProcessExterns()
{
string output = "";
std::string output = "";
for (pair<uint32_t, Declaration*> item : declarations)
for (std::pair<uint32_t, Declaration*> item : declarations)
{
if (item.first < rangeStart || item.first >= rangeEnd)
{
@@ -1161,4 +1188,61 @@ string ZFile::ProcessExterns()
output += defines;
return output;
}
}
std::string ZFile::ProcessTextureIntersections(std::string prefix)
{
if (texturesResources.empty())
return "";
std::string defines = "";
std::vector<std::pair<uint32_t, ZTexture*>> texturesSorted(texturesResources.begin(),
texturesResources.end());
for (size_t i = 0; i < texturesSorted.size() - 1; i++)
{
uint32_t currentOffset = texturesSorted[i].first;
uint32_t nextOffset = texturesSorted[i + 1].first;
auto& currentTex = texturesResources.at(currentOffset);
int texSize = currentTex->GetRawDataSize();
if (currentTex->WasDeclaredInXml())
{
// We believe the user is right.
continue;
}
if ((currentOffset + texSize) > nextOffset)
{
uint32_t offsetDiff = nextOffset - currentOffset;
if (currentTex->isPalette)
{
// Shrink palette so it doesn't overlap
currentTex->SetDimensions(offsetDiff / currentTex->GetPixelMultiplyer(), 1);
declarations.at(currentOffset)->size = currentTex->GetRawDataSize();
}
else
{
std::string texName = GetDeclarationPtrName(currentOffset);
std::string texNextName;
Declaration* nextDecl = GetDeclaration(nextOffset);
if (nextDecl == nullptr)
texNextName = texturesResources.at(nextOffset)->GetName();
else
texNextName = nextDecl->varName;
defines += StringHelper::Sprintf("#define %s ((u32)%s + 0x%06X)\n",
texNextName.c_str(), texName.c_str(), offsetDiff);
declarations.erase(nextOffset);
texturesResources.erase(nextOffset);
texturesSorted.erase(texturesSorted.begin() + i + 1);
i--;
}
}
}
return defines;
}
+25 -7
View File
@@ -4,6 +4,7 @@
#include <vector>
#include "Directory.h"
#include "ZResource.h"
#include "ZTexture.h"
#include "tinyxml2.h"
enum class ZFileMode
@@ -32,6 +33,7 @@ public:
std::map<uint32_t, Declaration*> declarations;
std::string defines;
std::vector<ZResource*> resources;
int32_t segment;
uint32_t baseAddress, rangeStart, rangeEnd;
ZFile(const fs::path& nOutPath, std::string nName);
@@ -41,7 +43,9 @@ public:
~ZFile();
std::string GetVarName(uint32_t address);
std::string GetName();
std::string GetName() const;
const fs::path& GetXmlFilePath() const;
const std::vector<uint8_t>& GetRawData() const;
void ExtractResources(fs::path outputDir);
void BuildSourceFile(fs::path outputDir);
void AddResource(ZResource* res);
@@ -59,6 +63,9 @@ public:
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size,
std::string varType, std::string varName, size_t arrayItemCnt,
std::string body, bool isExternal);
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size,
std::string varType, std::string varName,
std::string arrayItemCntStr, std::string body);
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
DeclarationPadding padding, size_t size, std::string varType,
std::string varName, size_t arrayItemCnt, std::string body);
@@ -69,15 +76,19 @@ public:
Declaration* AddDeclarationIncludeArray(uint32_t address, std::string includePath, size_t size,
std::string varType, std::string varName,
size_t arrayItemCnt);
std::string GetDeclarationName(uint32_t address);
std::string GetDeclarationName(uint32_t address, std::string defaultResult);
Declaration* GetDeclaration(uint32_t address);
Declaration* GetDeclarationRanged(uint32_t address);
uint32_t GetDeclarationRangedAddress(uint32_t address);
std::string GetDeclarationName(uint32_t address) const;
std::string GetDeclarationName(uint32_t address, std::string defaultResult) const;
std::string GetDeclarationPtrName(segptr_t segAddress) const;
Declaration* GetDeclaration(uint32_t address) const;
Declaration* GetDeclarationRanged(uint32_t address) const;
uint32_t GetDeclarationRangedAddress(uint32_t address) const;
bool HasDeclaration(uint32_t address);
std::string GetHeaderInclude();
void GeneratePlaceholderDeclarations();
void AddTextureResource(uint32_t offset, ZTexture* tex);
ZTexture* GetTextureResource(uint32_t offset) const;
static std::map<std::string, ZResourceFactoryFunc*>* GetNodeMap();
static void RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc);
@@ -87,10 +98,15 @@ protected:
fs::path basePath;
fs::path outputPath;
fs::path xmlFilePath;
// Keep track of every texture of this ZFile.
// The pointers declared here are "borrowed" (somebody else is the owner),
// so ZFile shouldn't delete/free those textures.
std::map<uint32_t, ZTexture*> texturesResources;
ZFile();
void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename,
bool placeholderMode);
void DeclareResourceSubReferences();
void GenerateSourceFiles(fs::path outputDir);
void GenerateSourceHeaderFiles();
void GenerateHLIntermediette();
@@ -98,4 +114,6 @@ protected:
std::string ProcessDeclarations();
void ProcessDeclarationText(Declaration* decl);
std::string ProcessExterns();
};
std::string ProcessTextureIntersections(std::string prefix);
};
+32 -32
View File
@@ -4,8 +4,6 @@
#include "Globals.h"
#include "StringHelper.h"
using namespace std;
REGISTER_ZFILENODE(Limb, ZLimb);
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset)
@@ -105,12 +103,12 @@ Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawD
void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
{
string entryStr;
std::string entryStr;
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
string unk_8_Str =
std::string unk_8_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
@@ -142,7 +140,7 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
if (unk_C != 0)
{
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
string unk_C_Str =
std::string unk_C_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
@@ -173,9 +171,9 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) const
{
string entryStr;
std::string entryStr;
string unk_8_Str = "NULL";
std::string unk_8_Str = "NULL";
if (unk_8 != 0)
{
@@ -185,7 +183,7 @@ std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) cons
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
}
string unk_C_Str = "NULL";
std::string unk_C_Str = "NULL";
if (unk_C != 0)
{
@@ -253,11 +251,11 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
if (unk_4 != 0)
{
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
string unk_4_Str =
std::string unk_4_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
string entryStr = "";
std::string entryStr = "";
uint16_t arrayItemCnt = unk_4_arr.size();
size_t i = 0;
@@ -294,7 +292,8 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength, parent);
string dListStr = StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
std::string dListStr =
StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
unk_8_dlist->SetName(dListStr);
unk_8_dlist->GetSourceOutputCode(prefix);
}
@@ -302,9 +301,9 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) const
{
string entryStr = "";
std::string entryStr = "";
string unk_4_Str = "NULL";
std::string unk_4_Str = "NULL";
if (unk_4 != 0)
{
@@ -323,7 +322,7 @@ std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) cons
}
}
string unk_8_Str = "NULL";
std::string unk_8_Str = "NULL";
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
@@ -393,7 +392,7 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
}
else
{
string limbTypeStr(limbType);
std::string limbTypeStr(limbType);
if (limbTypeStr == "Standard")
{
@@ -445,10 +444,11 @@ void ZLimb::ParseRawData()
{
case ZLimbType::LOD:
dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
// Intended fallthrough
case ZLimbType::Standard:
dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
break;
case ZLimbType::Skin:
skinSegmentType =
static_cast<ZLimbSkinType>(BitConverter::ToInt32BE(rawData, rawDataIndex + 8));
@@ -461,9 +461,9 @@ void ZLimb::ParseRawData()
}
void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
segAddress = nRawDataIndex;
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
@@ -479,7 +479,7 @@ void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8
}
}
size_t ZLimb::GetRawDataSize()
size_t ZLimb::GetRawDataSize() const
{
switch (type)
{
@@ -494,23 +494,23 @@ size_t ZLimb::GetRawDataSize()
return 0x0C;
}
string ZLimb::GetSourceOutputCode(const std::string& prefix)
std::string ZLimb::GetSourceOutputCode(const std::string& prefix)
{
string dListStr = "NULL";
string dListStr2 = "NULL";
std::string dListStr = "NULL";
std::string dListStr2 = "NULL";
if (dListPtr != 0)
{
string limbPrefix = type == ZLimbType::Curve ? "Curve" : "";
std::string limbPrefix = type == ZLimbType::Curve ? "Curve" : "";
dListStr = GetLimbDListSourceOutputCode(prefix, limbPrefix, dListPtr);
}
if (dList2Ptr != 0)
{
string limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far";
std::string limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far";
dListStr2 = GetLimbDListSourceOutputCode(prefix, limbPrefix, dList2Ptr);
}
string entryStr = "";
std::string entryStr = "";
if (type != ZLimbType::Curve)
{
entryStr += StringHelper::Sprintf("\n { %i, %i, %i },", transX, transY, transZ);
@@ -543,12 +543,12 @@ string ZLimb::GetSourceOutputCode(const std::string& prefix)
return "";
}
std::string ZLimb::GetSourceTypeName()
std::string ZLimb::GetSourceTypeName() const
{
return GetSourceTypeName(type);
}
ZResourceType ZLimb::GetResourceType()
ZResourceType ZLimb::GetResourceType() const
{
return ZResourceType::Limb;
}
@@ -592,7 +592,7 @@ std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix,
return "NULL";
uint32_t dListOffset = Seg2Filespace(dListPtr, parent->baseAddress);
string dListStr;
std::string dListStr;
Declaration* decl = parent->GetDeclaration(dListOffset);
if (decl == nullptr)
{
@@ -625,7 +625,7 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
string struct_800A5E28_Str;
std::string struct_800A5E28_Str;
Declaration* decl = parent->GetDeclaration(skinSegmentOffset);
if (decl == nullptr)
{
@@ -634,7 +634,7 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset);
segmentStruct.PreGenSourceFiles(prefix);
string entryStr = segmentStruct.GetSourceOutputCode(prefix);
std::string entryStr = segmentStruct.GetSourceOutputCode(prefix);
parent->AddDeclaration(skinSegmentOffset, DeclarationAlignment::None,
Struct_800A5E28::GetRawDataSize(),
@@ -652,7 +652,7 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
{
assert(type == ZLimbType::Skin);
string skinSegmentStr = "NULL";
std::string skinSegmentStr = "NULL";
if (skinSegment != 0)
{
@@ -681,7 +681,7 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
}
}
string entryStr =
std::string entryStr =
StringHelper::Sprintf(" 0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str());
return entryStr;
+4 -4
View File
@@ -151,11 +151,11 @@ public:
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath) override;
size_t GetRawDataSize() override;
const uint32_t nRawDataIndex) override;
size_t GetRawDataSize() const override;
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceTypeName() override;
ZResourceType GetResourceType() override;
std::string GetSourceTypeName() const override;
ZResourceType GetResourceType() const override;
ZLimbType GetLimbType();
void SetLimbType(ZLimbType value);
+7 -7
View File
@@ -14,7 +14,7 @@ ZMtx::ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint
: ZResource(nParent)
{
name = GetDefaultName(prefix.c_str(), rawDataIndex);
ExtractFromFile(nRawData, nRawDataIndex, "");
ExtractFromFile(nRawData, nRawDataIndex);
DeclareVar("", "");
}
@@ -28,18 +28,18 @@ void ZMtx::ParseRawData()
}
void ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, const std::string& nRelPath)
uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
DeclareVar("", "");
}
size_t ZMtx::GetRawDataSize()
size_t ZMtx::GetRawDataSize() const
{
return 64;
}
void ZMtx::DeclareVar(const std::string& prefix, const std::string& bodyStr)
void ZMtx::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
{
std::string auxName = name;
@@ -86,12 +86,12 @@ std::string ZMtx::GetDefaultName(const std::string& prefix, uint32_t address)
return StringHelper::Sprintf("%sMtx_%06X", prefix.c_str(), address);
}
std::string ZMtx::GetSourceTypeName()
std::string ZMtx::GetSourceTypeName() const
{
return "Mtx";
}
ZResourceType ZMtx::GetResourceType()
ZResourceType ZMtx::GetResourceType() const
{
return ZResourceType::Mtx;
}
+5 -5
View File
@@ -16,16 +16,16 @@ public:
ZFile* nParent);
void ParseRawData() override;
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, const std::string& nRelPath) override;
uint32_t nRawDataIndex) override;
size_t GetRawDataSize() override;
size_t GetRawDataSize() const override;
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
void DeclareVar(const std::string& prefix, const std::string& bodyStr) const;
std::string GetBodySourceCode();
std::string GetSourceOutputCode(const std::string& prefix) override;
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
std::string GetSourceTypeName() override;
ZResourceType GetResourceType() override;
std::string GetSourceTypeName() const override;
ZResourceType GetResourceType() const override;
};
+201
View File
@@ -0,0 +1,201 @@
#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;
}
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);
const char* numPathsXml = reader->Attribute("NumPaths");
if (numPathsXml != nullptr)
{
numPaths = StringHelper::StrToL(std::string(numPathsXml));
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 += entry.GetBodySourceCode();
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";
}
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;
}
size_t PathwayEntry::GetRawDataSize() const
{
return 0x08;
}
segptr_t PathwayEntry::GetListAddress() const
{
return listSegmentAddress;
}
+51
View File
@@ -0,0 +1,51 @@
#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;
void DeclareVar();
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;
size_t GetRawDataSize() const override;
void SetNumPaths(uint32_t nNumPaths);
protected:
uint32_t numPaths;
std::vector<PathwayEntry> pathways;
};
+33 -29
View File
@@ -1,43 +1,41 @@
#include "ZResource.h"
#include <cassert>
#include <regex>
#include "StringHelper.h"
using namespace std;
ZResource::ZResource(ZFile* nParent)
{
// assert(nParent != nullptr);
parent = nParent;
name = "";
outName = "";
relativePath = "";
sourceOutput = "";
rawData = vector<uint8_t>();
rawData = std::vector<uint8_t>();
rawDataIndex = 0;
outputDeclaration = true;
}
void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
const uint32_t nRawDataIndex)
{
rawData = nRawData;
rawDataIndex = nRawDataIndex;
relativePath = nRelPath;
if (reader != nullptr)
ParseXML(reader);
ParseRawData();
CalcHash();
}
void ZResource::ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
const std::string& nRelPath)
void ZResource::ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex)
{
rawData = nRawData;
rawDataIndex = nRawDataIndex;
relativePath = nRelPath;
ParseRawData();
CalcHash();
}
void ZResource::ParseXML(tinyxml2::XMLElement* reader)
@@ -78,10 +76,12 @@ void ZResource::ParseXML(tinyxml2::XMLElement* reader)
"with inner element/child detected.\n",
name.c_str(), reader->Name()));
}
declaredInXml = true;
}
}
void ZResource::Save(const std::string& outFolder)
void ZResource::Save(const fs::path& outFolder)
{
}
@@ -89,12 +89,12 @@ void ZResource::PreGenSourceFiles()
{
}
string ZResource::GetName()
std::string ZResource::GetName() const
{
return name;
}
std::string ZResource::GetOutName()
const std::string& ZResource::GetOutName() const
{
return outName;
}
@@ -104,47 +104,47 @@ void ZResource::SetOutName(std::string nName)
outName = nName;
}
void ZResource::SetName(string nName)
void ZResource::SetName(std::string nName)
{
name = std::move(nName);
}
bool ZResource::IsExternalResource()
bool ZResource::IsExternalResource() const
{
return false;
}
bool ZResource::DoesSupportArray()
bool ZResource::DoesSupportArray() const
{
return false;
}
std::string ZResource::GetExternalExtension()
std::string ZResource::GetExternalExtension() const
{
return "";
}
string ZResource::GetRelativePath()
{
return relativePath;
}
vector<uint8_t> ZResource::GetRawData()
const std::vector<uint8_t>& ZResource::GetRawData() const
{
return rawData;
}
void ZResource::SetRawData(std::vector<uint8_t> nData)
void ZResource::SetRawData(const std::vector<uint8_t>& nData)
{
rawData = nData;
}
uint32_t ZResource::GetRawDataIndex()
bool ZResource::WasDeclaredInXml() const
{
return declaredInXml;
}
uint32_t ZResource::GetRawDataIndex() const
{
return rawDataIndex;
}
size_t ZResource::GetRawDataSize()
size_t ZResource::GetRawDataSize() const
{
return rawData.size();
}
@@ -154,12 +154,12 @@ void ZResource::SetRawDataIndex(uint32_t value)
rawDataIndex = value;
}
string ZResource::GetSourceOutputCode(const std::string& prefix)
std::string ZResource::GetSourceOutputCode(const std::string& prefix)
{
return "";
}
string ZResource::GetSourceOutputHeader(const std::string& prefix)
std::string ZResource::GetSourceOutputHeader(const std::string& prefix)
{
return "";
}
@@ -168,16 +168,20 @@ void ZResource::ParseRawData()
{
}
void ZResource::DeclareReferences(const std::string& prefix)
{
}
void ZResource::GenerateHLIntermediette(HLFileIntermediette& hlFile)
{
}
std::string ZResource::GetSourceTypeName()
std::string ZResource::GetSourceTypeName() const
{
return "u8";
}
ZResourceType ZResource::GetResourceType()
ZResourceType ZResource::GetResourceType() const
{
return ZResourceType::Error;
}
+38 -92
View File
@@ -5,8 +5,11 @@
#include <stdint.h>
#include <string>
#include <vector>
#include "Declaration.h"
#include "tinyxml2.h"
#include "Directory.h"
#define SEGMENT_SCENE 2
#define SEGMENT_ROOM 3
#define SEGMENT_KEEP 4
@@ -22,151 +25,94 @@ typedef uint32_t segptr_t;
class ZFile;
class HLFileIntermediette;
class Declaration;
struct CommandSet;
enum class ZResourceType
{
Error,
Texture,
DisplayList,
Room,
Animation,
Cutscene,
Background,
Blob,
CollisionHeader,
Cutscene,
DisplayList,
Limb,
Skeleton,
Mtx,
Path,
Room,
Scalar,
Skeleton,
String,
Symbol,
Texture,
Vector,
Vertex,
CollisionHeader,
Symbol,
Mtx,
Background,
};
class ZResource
{
public:
ZFile* parent;
bool outputDeclaration;
uint32_t hash;
bool outputDeclaration = true;
uint32_t hash = 0;
ZResource(ZFile* nParent);
virtual ~ZResource();
// Parsing from File
virtual void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex,
const std::string& nRelPath); // Extract Mode
virtual void ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
const std::string& nRelPath);
uint32_t nRawDataIndex);
virtual void ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex);
// Misc
virtual void ParseXML(tinyxml2::XMLElement* reader);
virtual void ParseRawData();
virtual void DeclareReferences(const std::string& prefix);
virtual std::string GetSourceOutputCode(const std::string& prefix);
virtual std::string GetSourceOutputHeader(const std::string& prefix);
virtual void PreGenSourceFiles();
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile);
virtual void CalcHash();
virtual void Save(const std::string& outFolder);
virtual void Save(const fs::path& outFolder);
// Properties
virtual bool IsExternalResource();
virtual bool DoesSupportArray(); // Can this type be wrapped in an <Array> node?
virtual std::string GetSourceTypeName();
virtual ZResourceType GetResourceType();
virtual std::string GetExternalExtension();
virtual bool IsExternalResource() const;
virtual bool DoesSupportArray() const; // Can this type be wrapped in an <Array> node?
virtual std::string GetSourceTypeName() const;
virtual ZResourceType GetResourceType() const;
virtual std::string GetExternalExtension() const;
// Getters/Setters
std::string GetName();
std::string GetName() const;
void SetName(std::string nName);
std::string GetOutName();
const std::string& GetOutName() const;
void SetOutName(std::string nName);
std::string GetRelativePath();
virtual uint32_t GetRawDataIndex();
virtual uint32_t GetRawDataIndex() const;
virtual void SetRawDataIndex(uint32_t value);
virtual size_t GetRawDataSize();
virtual std::vector<uint8_t> GetRawData();
virtual void SetRawData(std::vector<uint8_t> nData);
virtual size_t GetRawDataSize() const;
virtual const std::vector<uint8_t>& GetRawData() const;
virtual void SetRawData(const std::vector<uint8_t>& nData);
bool WasDeclaredInXml() const;
protected:
std::string name;
std::string outName;
std::string relativePath;
std::vector<uint8_t> rawData;
uint32_t rawDataIndex;
std::string sourceOutput;
bool 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
};
enum class DeclarationAlignment
{
None,
Align4,
Align8,
Align16
};
enum class DeclarationPadding
{
None,
Pad4,
Pad8,
Pad16
};
class Declaration
{
public:
DeclarationAlignment alignment;
DeclarationPadding padding;
size_t size;
std::string preText;
std::string text;
std::string rightText;
std::string postText;
std::string preComment;
std::string postComment;
std::string varType;
std::string varName;
std::string includePath;
bool isExternal;
bool isArray;
size_t arrayItemCnt;
std::vector<uint32_t> references;
bool isUnaccounted = false;
Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
std::string nVarName, bool nIsArray, std::string nText);
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
std::string nVarType, std::string nVarName, bool nIsArray, std::string nText);
Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText);
Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText,
bool nIsExternal);
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
std::string nVarType, std::string nVarName, bool nIsArray, size_t nArrayItemCnt,
std::string nText);
Declaration(std::string nIncludePath, size_t nSize, std::string nVarType, std::string nVarName);
protected:
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
std::string nText);
bool declaredInXml = false;
};
uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress);
typedef ZResource*(ZResourceFactoryFunc)();
typedef ZResource*(ZResourceFactoryFunc)(ZFile* nParent);
#define REGISTER_ZFILENODE(nodeName, zResClass) \
static ZResource* ZResourceFactory_##zResClass_##nodeName() \
static ZResource* ZResourceFactory_##zResClass_##nodeName(ZFile* nParent) \
{ \
return static_cast<ZResource*>(new zResClass(nullptr)); \
return static_cast<ZResource*>(new zResClass(nParent)); \
} \
\
class ZRes_##nodeName \
@@ -177,4 +123,4 @@ typedef ZResource*(ZResourceFactoryFunc)();
ZFile::RegisterNode(#nodeName, &ZResourceFactory_##zResClass_##nodeName); \
} \
}; \
static ZRes_##nodeName inst_ZRes_##nodeName;
static ZRes_##nodeName inst_ZRes_##nodeName
+6 -11
View File
@@ -1,25 +1,20 @@
#include "EndMarker.h"
#include "../../StringHelper.h"
using namespace std;
EndMarker::EndMarker(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
EndMarker::EndMarker(ZFile* nParent) : ZRoomCommand(nParent)
{
}
string EndMarker::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
std::string EndMarker::GetBodySourceCode() const
{
return StringHelper::Sprintf(
"%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str());
return "SCENE_CMD_END()";
}
string EndMarker::GetCommandCName()
std::string EndMarker::GetCommandCName() const
{
return "SCmdEndMarker";
}
RoomCommand EndMarker::GetRoomCommand()
RoomCommand EndMarker::GetRoomCommand() const
{
return RoomCommand::EndMarker;
}
}
+5 -7
View File
@@ -1,15 +1,13 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class EndMarker : public ZRoomCommand
{
public:
EndMarker(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
EndMarker(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
private:
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
};
@@ -1,88 +1,79 @@
#include "SetActorCutsceneList.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetActorCutsceneList::SetActorCutsceneList(ZRoom* nZRoom, std::vector<uint8_t> rawData,
uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetActorCutsceneList::SetActorCutsceneList(ZFile* nParent) : ZRoomCommand(nParent)
{
int32_t numCutscenes = rawData[rawDataIndex + 1];
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
cutscenes = vector<ActorCutsceneEntry*>();
}
void SetActorCutsceneList::ParseRawData()
{
ZRoomCommand::ParseRawData();
int numCutscenes = cmdArg1;
int32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numCutscenes; i++)
{
ActorCutsceneEntry* entry = new ActorCutsceneEntry(rawData, currentPtr);
ActorCutsceneEntry entry(parent->GetRawData(), currentPtr);
cutscenes.push_back(entry);
currentPtr += 16;
}
}
string declaration = "";
for (ActorCutsceneEntry* entry : cutscenes)
void SetActorCutsceneList::DeclareReferences(const std::string& prefix)
{
if (cutscenes.size() > 0)
{
declaration += StringHelper::Sprintf(
" { %i, %i, %i, %i, %i, %i, %i, %i, %i, %i },\n", entry->priority, entry->length,
entry->unk4, entry->unk6, entry->additionalCutscene, entry->sound, entry->unkB,
entry->unkC, entry->unkE, entry->letterboxSize);
std::string declaration = "";
for (size_t i = 0; i < cutscenes.size(); i++)
{
const auto& entry = cutscenes.at(i);
declaration += StringHelper::Sprintf(" { %s },", entry.GetBodySourceCode().c_str());
if (i + 1 < cutscenes.size())
{
declaration += "\n";
}
}
std::string typeName = cutscenes.at(0).GetSourceTypeName();
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::Align4, cutscenes.size() * 16, typeName,
StringHelper::Sprintf("%s%sList_%06X", prefix.c_str(), typeName.c_str(), segmentOffset),
0, declaration);
}
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, cutscenes.size() * 16, "ActorCutscene",
StringHelper::Sprintf("%sActorCutsceneList0x%06X", zRoom->GetName().c_str(), segmentOffset),
0, declaration);
}
SetActorCutsceneList::~SetActorCutsceneList()
std::string SetActorCutsceneList::GetBodySourceCode() const
{
for (ActorCutsceneEntry* entry : cutscenes)
delete entry;
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_LIST(%i, %s)", cutscenes.size(),
listName.c_str());
}
string SetActorCutsceneList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
{
return StringHelper::Sprintf(
"%s 0x%02X, (u32)&%sActorCutsceneList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), cutscenes.size(),
zRoom->GetName().c_str(), segmentOffset);
}
string SetActorCutsceneList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
{
return "";
}
size_t SetActorCutsceneList::GetRawDataSize()
size_t SetActorCutsceneList::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize() + (cutscenes.size() * 16);
}
string SetActorCutsceneList::GenerateExterns()
{
return StringHelper::Sprintf("extern ActorCutscene %sActorCutsceneList0x%06X[];\n",
zRoom->GetName().c_str(), segmentOffset);
}
string SetActorCutsceneList::GetCommandCName()
std::string SetActorCutsceneList::GetCommandCName() const
{
return "SCmdCutsceneActorList";
}
RoomCommand SetActorCutsceneList::GetRoomCommand()
RoomCommand SetActorCutsceneList::GetRoomCommand() const
{
return RoomCommand::SetActorCutsceneList;
}
ActorCutsceneEntry::ActorCutsceneEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
ActorCutsceneEntry::ActorCutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
: priority(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)),
length(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)),
unk4(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)),
@@ -93,3 +84,14 @@ ActorCutsceneEntry::ActorCutsceneEntry(std::vector<uint8_t> rawData, uint32_t ra
letterboxSize(rawData[rawDataIndex + 0xF])
{
}
std::string ActorCutsceneEntry::GetBodySourceCode() const
{
return StringHelper::Sprintf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %i", priority, length, unk4,
unk6, additionalCutscene, sound, unkB, unkC, unkE, letterboxSize);
}
std::string ActorCutsceneEntry::GetSourceTypeName() const
{
return "ActorCutscene";
}
@@ -1,10 +1,10 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class ActorCutsceneEntry
{
public:
protected:
int16_t priority;
int16_t length;
int16_t unk4;
@@ -16,23 +16,27 @@ public:
uint8_t unkE;
uint8_t letterboxSize;
ActorCutsceneEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
public:
ActorCutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetBodySourceCode() const;
std::string GetSourceTypeName() const;
};
class SetActorCutsceneList : public ZRoomCommand
{
public:
SetActorCutsceneList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetActorCutsceneList();
SetActorCutsceneList(ZFile* nParent);
std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
std::string GetCommandCName() override;
std::string GenerateExterns() override;
RoomCommand GetRoomCommand() override;
size_t GetRawDataSize() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
private:
std::vector<ActorCutsceneEntry*> cutscenes;
uint32_t segmentOffset;
std::vector<ActorCutsceneEntry> cutscenes;
};
+91 -109
View File
@@ -1,121 +1,77 @@
#include "SetActorList.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZNames.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZNames.h"
#include "ZRoom/ZRoom.h"
SetActorList::SetActorList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetActorList::SetActorList(ZFile* nParent) : ZRoomCommand(nParent)
{
numActors = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
_rawData = rawData;
_rawDataIndex = rawDataIndex;
if (segmentOffset != 0)
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
}
SetActorList::~SetActorList()
void SetActorList::ParseRawData()
{
for (ActorSpawnEntry* entry : actors)
delete entry;
ZRoomCommand::ParseRawData();
numActors = cmdArg1;
}
string SetActorList::GetSourceOutputCode(std::string prefix)
{
return "";
}
string SetActorList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
{
return "";
}
string SetActorList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
{
string sourceOutput = "";
size_t numActorsReal = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 16;
actors = vector<ActorSpawnEntry*>();
uint32_t currentPtr = segmentOffset;
for (size_t i = 0; i < numActorsReal; i++)
for (size_t i = 0; i < numActors; i++)
{
ActorSpawnEntry* entry = new ActorSpawnEntry(_rawData, currentPtr);
ActorSpawnEntry entry(parent->GetRawData(), currentPtr);
currentPtr += entry.GetRawDataSize();
actors.push_back(entry);
currentPtr += 16;
}
}
sourceOutput +=
StringHelper::Sprintf("\n %s 0x%02X, (u32)%sActorList0x%06X \n};",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
numActors, roomName.c_str(), segmentOffset);
// zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None,
// DeclarationPadding::None, GetRawDataSize(), "SCmdActorList",
// ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress), sourceOutput);
string declaration = "";
size_t index = 0;
for (ActorSpawnEntry* entry : actors)
void SetActorList::DeclareReferences(const std::string& prefix)
{
if (!actors.empty())
{
uint16_t actorNum = entry->actorNum;
std::string declaration = "";
if (Globals::Instance->game == ZGame::MM_RETAIL)
size_t index = 0;
for (const auto& entry : actors)
{
declaration += StringHelper::Sprintf(
" { %s, %i, %i, %i, SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X), "
"SPAWN_ROT_FLAGS(%i, 0x%04X), 0x%04X }, //0x%06X",
ZNames::GetActorName(actorNum).c_str(), entry->posX, entry->posY, entry->posZ,
(entry->rotX >> 7) & 0b111111111, entry->rotX & 0b1111111,
(entry->rotY >> 7) & 0b111111111, entry->rotY & 0b1111111,
(entry->rotZ >> 7) & 0b111111111, entry->rotZ & 0b1111111, (uint16_t)entry->initVar,
segmentOffset + (index * 16));
}
else
{
declaration += StringHelper::Sprintf(
" { %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X",
ZNames::GetActorName(actorNum).c_str(), entry->posX, entry->posY, entry->posZ,
entry->rotX, entry->rotY, entry->rotZ, (uint16_t)entry->initVar,
segmentOffset + (index * 16));
declaration +=
StringHelper::Sprintf("\t{ %s }, // 0x%06X", entry.GetBodySourceCode().c_str(),
segmentOffset + (index * 16));
if (index < actors.size() - 1)
declaration += "\n";
index++;
}
if (index < actors.size() - 1)
declaration += "\n";
const auto& entry = actors.front();
index++;
DeclarationPadding padding = DeclarationPadding::Pad16;
if (Globals::Instance->game == ZGame::MM_RETAIL)
padding = DeclarationPadding::None;
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::Align4, padding,
actors.size() * entry.GetRawDataSize(), entry.GetSourceTypeName(),
StringHelper::Sprintf("%sActorList_%06X", prefix.c_str(), segmentOffset),
GetActorListArraySize(), declaration);
}
DeclarationPadding padding = DeclarationPadding::Pad16;
if (Globals::Instance->game == ZGame::MM_RETAIL)
padding = DeclarationPadding::None;
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, padding, actors.size() * 16, "ActorEntry",
StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset),
GetActorListArraySize(), declaration);
return sourceOutput;
}
size_t SetActorList::GetRawDataSize()
std::string SetActorList::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_ACTOR_LIST(%i, %s)", numActors, listName.c_str());
}
size_t SetActorList::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize() + ((int32_t)actors.size() * 16);
}
size_t SetActorList::GetActorListArraySize()
size_t SetActorList::GetActorListArraySize() const
{
size_t actorCount = 0;
@@ -126,8 +82,8 @@ size_t SetActorList::GetActorListArraySize()
{
actorCount = 0;
for (ActorSpawnEntry* entry : actors)
if (entry->actorNum != 0x22)
for (const auto& entry : actors)
if (entry.GetActorId() != 0x22)
actorCount++;
}
else
@@ -138,32 +94,58 @@ size_t SetActorList::GetActorListArraySize()
return actorCount;
}
string SetActorList::GenerateExterns()
{
return StringHelper::Sprintf("extern ActorEntry %sActorList0x%06X[%i];\n",
zRoom->GetName().c_str(), segmentOffset, GetActorListArraySize());
}
string SetActorList::GetCommandCName()
std::string SetActorList::GetCommandCName() const
{
return "SCmdActorList";
}
RoomCommand SetActorList::GetRoomCommand()
RoomCommand SetActorList::GetRoomCommand() const
{
return RoomCommand::SetActorList;
}
ActorSpawnEntry::ActorSpawnEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
ActorSpawnEntry::ActorSpawnEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
actorNum = BitConverter::ToInt16BE(data, rawDataIndex + 0);
posX = BitConverter::ToInt16BE(data, rawDataIndex + 2);
posY = BitConverter::ToInt16BE(data, rawDataIndex + 4);
posZ = BitConverter::ToInt16BE(data, rawDataIndex + 6);
rotX = BitConverter::ToInt16BE(data, rawDataIndex + 8);
rotY = BitConverter::ToInt16BE(data, rawDataIndex + 10);
rotZ = BitConverter::ToInt16BE(data, rawDataIndex + 12);
initVar = BitConverter::ToInt16BE(data, rawDataIndex + 14);
actorNum = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
posX = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
posY = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
posZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
rotX = BitConverter::ToInt16BE(rawData, rawDataIndex + 8);
rotY = BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
rotZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
initVar = BitConverter::ToInt16BE(rawData, rawDataIndex + 14);
}
std::string ActorSpawnEntry::GetBodySourceCode() const
{
std::string body = "\n";
body += "\t\t" + ZNames::GetActorName(actorNum) + ",\n";
body += StringHelper::Sprintf("\t\t{ %6i, %6i, %6i },\n", posX, posY, posZ);
if (Globals::Instance->game == ZGame::MM_RETAIL)
body += StringHelper::Sprintf("\t\t{ SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, "
"0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X)},\n",
(rotX >> 7) & 0b111111111, rotX & 0b1111111,
(rotY >> 7) & 0b111111111, rotY & 0b1111111,
(rotZ >> 7) & 0b111111111, rotZ & 0b1111111);
else
body += StringHelper::Sprintf("\t\t{ %6i, %6i, %6i },\n", rotX, rotY, rotZ);
body += StringHelper::Sprintf("\t\t0x%04X\n ", initVar);
return body;
}
std::string ActorSpawnEntry::GetSourceTypeName() const
{
return "ActorEntry";
}
int32_t ActorSpawnEntry::GetRawDataSize() const
{
return 16;
}
uint16_t ActorSpawnEntry::GetActorId() const
{
return actorNum;
}
+26 -20
View File
@@ -1,10 +1,20 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class ActorSpawnEntry
{
public:
ActorSpawnEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetBodySourceCode() const;
std::string GetSourceTypeName() const;
int32_t GetRawDataSize() const;
uint16_t GetActorId() const;
protected:
uint16_t actorNum;
int16_t posX;
int16_t posY;
@@ -13,29 +23,25 @@ public:
int16_t rotY;
int16_t rotZ;
uint16_t initVar;
ActorSpawnEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
};
class SetActorList : public ZRoomCommand
{
public:
SetActorList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetActorList();
SetActorList(ZFile* nParent);
std::string GetSourceOutputCode(std::string prefix);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
virtual RoomCommand GetRoomCommand() override;
virtual size_t GetRawDataSize() override;
virtual std::string GetCommandCName() override;
virtual std::string GenerateExterns() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
private:
size_t GetActorListArraySize();
int32_t numActors;
std::vector<ActorSpawnEntry*> actors;
uint32_t segmentOffset;
std::vector<uint8_t> _rawData;
uint32_t _rawDataIndex;
};
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
std::string GetCommandCName() const override;
protected:
size_t GetActorListArraySize() const;
uint8_t numActors;
std::vector<ActorSpawnEntry> actors;
};
@@ -1,74 +1,70 @@
#include "SetAlternateHeaders.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
using namespace std;
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
SetAlternateHeaders::SetAlternateHeaders(ZRoom* nZRoom, std::vector<uint8_t> rawData,
uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetAlternateHeaders::SetAlternateHeaders(ZFile* nParent) : ZRoomCommand(nParent)
{
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
if (segmentOffset != 0)
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
_rawData = rawData;
_rawDataIndex = rawDataIndex;
}
string SetAlternateHeaders::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetAlternateHeaders::DeclareReferences(const std::string& prefix)
{
string sourceOutput = "";
int32_t numHeaders = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 4;
if (segmentOffset != 0)
parent->AddDeclarationPlaceholder(segmentOffset);
}
void SetAlternateHeaders::ParseRawDataLate()
{
int numHeaders = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 4;
for (int32_t i = 0; i < numHeaders; i++)
{
int32_t address = BitConverter::ToInt32BE(_rawData, segmentOffset + (i * 4));
int32_t address = BitConverter::ToInt32BE(parent->GetRawData(), segmentOffset + (i * 4));
headers.push_back(address);
if (address != 0)
zRoom->commandSets.push_back(CommandSet(address));
}
sourceOutput +=
StringHelper::Sprintf("%s 0, (u32)&%sAlternateHeaders0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
roomName.c_str(), segmentOffset);
string declaration = "";
for (int32_t i = 0; i < numHeaders; i++)
{
// sprintf(line, " 0x%06X,\n", headers[i]);
if (headers[i] == 0)
declaration += StringHelper::Sprintf(" 0,\n");
else
declaration += StringHelper::Sprintf(" (u32)&%sSet%04XCmd00,\n", roomName.c_str(),
headers[i] & 0x00FFFFFF);
}
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, headers.size() * 4, "u32",
StringHelper::Sprintf("%sAlternateHeaders0x%06X", roomName.c_str(), segmentOffset), 0,
declaration);
return sourceOutput;
}
size_t SetAlternateHeaders::GetRawDataSize()
void SetAlternateHeaders::DeclareReferencesLate(const std::string& prefix)
{
return ZRoomCommand::GetRawDataSize() + 0;
if (!headers.empty())
{
std::string declaration = "";
for (size_t i = 0; i < headers.size(); i++)
{
if (headers.at(i) == 0)
declaration += StringHelper::Sprintf("\tNULL,");
else
declaration +=
StringHelper::Sprintf("\t%sSet%04X,", prefix.c_str(), GETSEGOFFSET(headers[i]));
if (i + 1 < headers.size())
declaration += "\n";
}
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, headers.size() * 4, "SCmdBase*",
StringHelper::Sprintf("%sAlternateHeaders0x%06X", prefix.c_str(), segmentOffset), 0,
declaration);
}
}
string SetAlternateHeaders::GetCommandCName()
std::string SetAlternateHeaders::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_ALTERNATE_HEADER_LIST(%s)", listName.c_str());
}
std::string SetAlternateHeaders::GetCommandCName() const
{
return "SCmdAltHeaders";
}
RoomCommand SetAlternateHeaders::GetRoomCommand()
RoomCommand SetAlternateHeaders::GetRoomCommand() const
{
return RoomCommand::SetAlternateHeaders;
}
}
@@ -1,21 +1,22 @@
#pragma once
#include "../ZRoom.h"
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoom.h"
#include "ZRoom/ZRoomCommand.h"
class SetAlternateHeaders : public ZRoomCommand
{
public:
SetAlternateHeaders(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetAlternateHeaders(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual size_t GetRawDataSize() override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void DeclareReferences(const std::string& prefix) override;
void ParseRawDataLate() override;
void DeclareReferencesLate(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
private:
int32_t segmentOffset;
std::vector<uint32_t> headers;
std::vector<uint8_t> _rawData;
int32_t _rawDataIndex;
};
};
@@ -0,0 +1,402 @@
#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).segmentOffset);
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)),
segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)))
{
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)),
primColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))),
envColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8))),
keyFrameSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 12)))
{
uint16_t length = (type == 2) ? cycleLength : numKeyFrames;
int32_t currentPtr = primColorSegmentOffset;
for (uint16_t i = 0; i < length; i++)
{
primColors.push_back(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("%sAnimatedMaterialPrimColor0x%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(primColorSegmentOffset);
std::string envName = zRoom->parent->GetDeclarationPtrName(envColorSegmentOffset);
std::string keyName = zRoom->parent->GetDeclarationPtrName(keyFrameSegmentOffset);
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)),
textureSegmentOffsetsSegmentOffset(
GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))),
textureIndicesSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8)))
{
int32_t currentPtr = textureIndicesSegmentOffset;
int32_t maxIndex = 0;
for (uint16_t i = 0; i < cycleLength; i++)
{
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(textureSegmentOffsetsSegmentOffset);
std::string indexesName = zRoom->parent->GetDeclarationPtrName(textureIndicesSegmentOffset);
return StringHelper::Sprintf("%i, %s, %s", cycleLength, segmName.c_str(), indexesName.c_str());
}
size_t AnimatedMatTexCycleParams::GetParamsSize()
{
return 12;
}
@@ -1,12 +1,12 @@
#pragma once
#include "../ZRoomCommand.h"
#include <memory>
#include "ZRoom/ZRoomCommand.h"
// TODO move into header and add all types
class AnitmatedTextureParams
{
public:
virtual ~AnitmatedTextureParams();
virtual std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) = 0;
virtual size_t GetParamsSize() = 0;
};
@@ -14,7 +14,7 @@ public:
class ScrollingTexture : public AnitmatedTextureParams
{
public:
ScrollingTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
ScrollingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
size_t GetParamsSize() override;
@@ -24,10 +24,10 @@ public:
uint8_t height;
};
class FlashingTexturePrimColor
class F3DPrimColor
{
public:
FlashingTexturePrimColor(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
F3DPrimColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
uint8_t r;
uint8_t g;
@@ -39,7 +39,7 @@ public:
class FlashingTextureEnvColor
{
public:
FlashingTextureEnvColor(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
FlashingTextureEnvColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
uint8_t r;
uint8_t g;
@@ -50,7 +50,7 @@ public:
class FlashingTexture : public AnitmatedTextureParams
{
public:
FlashingTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t type);
FlashingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex, int32_t type);
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
size_t GetParamsSize() override;
@@ -60,15 +60,15 @@ public:
uint32_t envColorSegmentOffset;
uint32_t keyFrameSegmentOffset;
std::vector<FlashingTexturePrimColor> primColors;
std::vector<F3DPrimColor> primColors;
std::vector<FlashingTextureEnvColor> envColors;
std::vector<uint16_t> keyFrames;
};
class CyclingTextureParams : public AnitmatedTextureParams
class AnimatedMatTexCycleParams : public AnitmatedTextureParams
{
public:
CyclingTextureParams(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
AnimatedMatTexCycleParams(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
size_t GetParamsSize() override;
@@ -80,34 +80,31 @@ public:
std::vector<uint8_t> textureIndices;
};
class AnimatedTexture
class AnimatedMaterial
{
public:
AnimatedTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
virtual ~AnimatedTexture();
AnimatedMaterial(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
int8_t segment;
int16_t type;
uint32_t segmentOffset;
std::vector<AnitmatedTextureParams*> params;
std::vector<std::shared_ptr<AnitmatedTextureParams>> params;
};
class SetAnimatedTextureList : public ZRoomCommand
class SetAnimatedMaterialList : public ZRoomCommand
{
public:
SetAnimatedTextureList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetAnimatedTextureList();
SetAnimatedMaterialList(ZFile* nParent);
std::string GetSourceOutputCode(std::string prefix);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual RoomCommand GetRoomCommand() override;
virtual size_t GetRawDataSize() override;
virtual std::string GetCommandCName() override;
virtual std::string GenerateExterns() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
std::string GetCommandCName() const override;
private:
uint32_t segmentOffset;
std::vector<AnimatedTexture*> textures;
std::vector<uint8_t> _rawData;
int32_t _rawDataIndex;
};
std::vector<AnimatedMaterial> textures;
};
@@ -1,432 +0,0 @@
#include "SetAnimatedTextureList.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
SetAnimatedTextureList::SetAnimatedTextureList(ZRoom* nZRoom, std::vector<uint8_t> rawData,
uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
{
string declaration = "";
int32_t currentPtr = segmentOffset;
AnimatedTexture* lastTexture = nullptr;
do
{
if (textures.size() > 0)
declaration += "\n";
lastTexture = new AnimatedTexture(rawData, currentPtr);
currentPtr += 8;
textures.push_back(lastTexture);
string textureName =
(lastTexture->segmentOffset != 0) ?
StringHelper::Sprintf("&%sAnimatedTextureParams0x%06X",
zRoom->GetName().c_str(), lastTexture->segmentOffset) :
"NULL";
declaration += StringHelper::Sprintf(" { %i, %i, (u32)%s },", lastTexture->segment,
lastTexture->type, textureName.c_str());
} while ((lastTexture->segment != 0) && (lastTexture->segment > -1));
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16,
textures.size() * 8, "AnimatedTexture",
StringHelper::Sprintf("%sAnimatedTextureList0x%06X", zRoom->GetName().c_str(),
segmentOffset),
textures.size(), declaration);
}
for (AnimatedTexture* texture : textures)
{
string declaration = "";
size_t index = 0;
switch (texture->type)
{
case 0:
case 1:
for (AnitmatedTextureParams* param : texture->params)
{
declaration += param->GenerateSourceCode(zRoom, texture->segmentOffset);
if (index < texture->params.size() - 1)
declaration += "\n";
index++;
}
zRoom->parent->AddDeclarationArray(
texture->segmentOffset, DeclarationAlignment::None, DeclarationPadding::None,
texture->params.size() * 4, "ScrollingTextureParams",
StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(),
texture->segmentOffset),
texture->params.size(), declaration);
break;
case 2:
case 3:
case 4:
zRoom->parent->AddDeclaration(
texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 16,
"FlashingTextureParams",
StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(),
texture->segmentOffset),
texture->params[0]->GenerateSourceCode(zRoom, texture->segmentOffset));
break;
case 5:
zRoom->parent->AddDeclaration(
texture->segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 12,
"CyclingTextureParams",
StringHelper::Sprintf("%sAnimatedTextureParams0x%06X", zRoom->GetName().c_str(),
texture->segmentOffset),
texture->params[0]->GenerateSourceCode(zRoom, texture->segmentOffset));
break;
case 6:
break;
}
}
}
SetAnimatedTextureList::~SetAnimatedTextureList()
{
for (AnimatedTexture* texture : textures)
delete texture;
}
AnitmatedTextureParams::~AnitmatedTextureParams()
{
}
string SetAnimatedTextureList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
{
return StringHelper::Sprintf(
"%s 0, (u32)%sAnimatedTextureList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
zRoom->GetName().c_str(), segmentOffset);
}
size_t SetAnimatedTextureList::GetRawDataSize()
{
size_t paramsSize = 0;
for (AnimatedTexture* texture : textures)
{
for (AnitmatedTextureParams* param : texture->params)
{
paramsSize += param->GetParamsSize();
}
}
return ZRoomCommand::GetRawDataSize() + paramsSize;
}
string SetAnimatedTextureList::GenerateExterns()
{
return "";
}
string SetAnimatedTextureList::GetCommandCName()
{
return "SCmdTextureAnimations";
}
RoomCommand SetAnimatedTextureList::GetRoomCommand()
{
return RoomCommand::SetAnimatedTextureList;
}
string SetAnimatedTextureList::GetSourceOutputCode(std::string prefix)
{
return "";
}
AnimatedTexture::AnimatedTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: segment(rawData[rawDataIndex]), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)),
segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)))
{
switch (type)
{
case 0:
params.push_back(new ScrollingTexture(rawData, segmentOffset));
break;
case 1:
params.push_back(new ScrollingTexture(rawData, segmentOffset));
params.push_back(new ScrollingTexture(rawData, segmentOffset + 4));
break;
case 2:
case 3:
case 4:
params.push_back(new FlashingTexture(rawData, segmentOffset, type));
break;
case 5:
params.push_back(new CyclingTextureParams(rawData, segmentOffset));
break;
case 6: // Some terminator when there are no animated textures?
break;
}
}
AnimatedTexture::~AnimatedTexture()
{
for (AnitmatedTextureParams* param : params)
delete param;
}
ScrollingTexture::ScrollingTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: xStep(rawData[rawDataIndex + 0]), yStep(rawData[rawDataIndex + 1]),
width(rawData[rawDataIndex + 2]), height(rawData[rawDataIndex + 3])
{
}
std::string ScrollingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
{
return StringHelper::Sprintf(" { %i, %i, 0x%02X, 0x%02X },", xStep, yStep, width, height);
}
size_t ScrollingTexture::GetParamsSize()
{
return 4;
}
FlashingTexturePrimColor::FlashingTexturePrimColor(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: r(rawData[rawDataIndex + 0]), g(rawData[rawDataIndex + 1]), b(rawData[rawDataIndex + 2]),
a(rawData[rawDataIndex + 3]), lodFrac(rawData[rawDataIndex + 4])
{
}
FlashingTextureEnvColor::FlashingTextureEnvColor(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: r(rawData[rawDataIndex + 0]), g(rawData[rawDataIndex + 1]), b(rawData[rawDataIndex + 2]),
a(rawData[rawDataIndex + 3])
{
}
FlashingTexture::FlashingTexture(std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t type)
: cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
numKeyFrames(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)),
primColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))),
envColorSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8))),
keyFrameSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 12)))
{
uint16_t length = (type == 2) ? cycleLength : numKeyFrames;
int32_t currentPtr = primColorSegmentOffset;
for (uint16_t i = 0; i < length; i++)
{
primColors.push_back(FlashingTexturePrimColor(rawData, currentPtr));
currentPtr += 5;
}
currentPtr = envColorSegmentOffset;
for (uint16_t i = 0; i < length; i++)
{
envColors.push_back(FlashingTextureEnvColor(rawData, currentPtr));
currentPtr += 4;
}
currentPtr = keyFrameSegmentOffset;
for (uint16_t i = 0; i < length; i++)
{
keyFrames.push_back(BitConverter::ToUInt16BE(rawData, currentPtr));
currentPtr += 2;
}
}
std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
{
if (primColorSegmentOffset != 0)
{
string declaration = "";
size_t index = 0;
for (FlashingTexturePrimColor& color : primColors)
{
declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },",
color.r, color.g, color.b, color.a, color.lodFrac);
if (index < primColors.size() - 1)
declaration += "\n";
index++;
}
zRoom->parent->AddDeclarationArray(
primColorSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None,
primColors.size() * 5, "FlashingTexturePrimColor",
StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(),
primColorSegmentOffset),
primColors.size(), declaration);
}
if (envColorSegmentOffset != 0)
{
string declaration = "";
size_t index = 0;
for (FlashingTextureEnvColor& color : envColors)
{
declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X },", color.r,
color.g, color.b, color.a);
if (index < envColors.size() - 1)
declaration += "\n";
index++;
}
zRoom->parent->AddDeclarationArray(
envColorSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None,
envColors.size() * 4, "Color_RGBA8",
StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(),
envColorSegmentOffset),
envColors.size(), declaration);
}
if (keyFrameSegmentOffset != 0)
{
string declaration = "";
size_t index = 0;
for (uint16_t keyFrame : keyFrames)
{
declaration += StringHelper::Sprintf(" 0x%02X,", keyFrame);
if (index < keyFrames.size() - 1)
declaration += "\n";
index++;
}
zRoom->parent->AddDeclarationArray(keyFrameSegmentOffset, DeclarationAlignment::Align4,
DeclarationPadding::None, keyFrames.size() * 2, "u16",
StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X",
zRoom->GetName().c_str(),
keyFrameSegmentOffset),
keyFrames.size(), declaration);
}
return StringHelper::Sprintf(
"%i, %i, (u32)%s, (u32)%s, (u32)%s", cycleLength, numKeyFrames,
(primColorSegmentOffset != 0) ?
StringHelper::Sprintf("%sAnimatedTexturePrimColor0x%06X", zRoom->GetName().c_str(),
primColorSegmentOffset)
.c_str() :
"NULL",
(envColorSegmentOffset != 0) ?
StringHelper::Sprintf("%sAnimatedTextureEnvColors0x%06X", zRoom->GetName().c_str(),
envColorSegmentOffset)
.c_str() :
"NULL",
(keyFrameSegmentOffset != 0) ?
StringHelper::Sprintf("%sAnimatedTextureKeyFrames0x%06X", zRoom->GetName().c_str(),
keyFrameSegmentOffset)
.c_str() :
"NULL");
}
size_t FlashingTexture::GetParamsSize()
{
return 16;
}
CyclingTextureParams::CyclingTextureParams(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
textureSegmentOffsetsSegmentOffset(
GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4))),
textureIndicesSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 8)))
{
int32_t currentPtr = textureIndicesSegmentOffset;
int32_t maxIndex = 0;
for (uint16_t i = 0; i < cycleLength; i++)
{
int32_t newIndex = rawData[currentPtr];
textureIndices.push_back(newIndex);
currentPtr++;
if (newIndex > maxIndex)
maxIndex = newIndex;
}
currentPtr = textureSegmentOffsetsSegmentOffset;
for (int32_t i = 0; i < maxIndex + 1; i++)
{
textureSegmentOffsets.push_back(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr)));
currentPtr += 4;
}
}
std::string CyclingTextureParams::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
{
if (textureSegmentOffsetsSegmentOffset != 0)
{
string declaration = "";
size_t index = 0;
for (uint32_t offset : textureSegmentOffsets)
{
declaration +=
StringHelper::Sprintf(" %sTex_%06X,", zRoom->GetName().c_str(), offset);
if (index < textureSegmentOffsets.size() - 1)
declaration += "\n";
index++;
}
zRoom->parent->AddDeclarationArray(
textureSegmentOffsetsSegmentOffset, DeclarationAlignment::Align4,
DeclarationPadding::None, textureSegmentOffsets.size() * 4, "u64*",
StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(),
textureSegmentOffsetsSegmentOffset),
textureSegmentOffsets.size(), declaration);
}
if (textureIndicesSegmentOffset != 0)
{
string declaration = "";
size_t index = 0;
for (uint8_t textureIndex : textureIndices)
{
declaration += StringHelper::Sprintf(" 0x%02X,", textureIndex);
if (index < textureIndices.size() - 1)
declaration += "\n";
index++;
}
zRoom->parent->AddDeclarationArray(
textureIndicesSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None,
textureIndices.size(), "u8",
StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(),
textureIndicesSegmentOffset),
textureIndices.size(), declaration);
}
return StringHelper::Sprintf(
"%i, (u32)%s, (u32)%s", cycleLength,
(textureSegmentOffsetsSegmentOffset != 0) ?
StringHelper::Sprintf("%sAnimatedTextureTexSegOffsets0x%06X", zRoom->GetName().c_str(),
textureSegmentOffsetsSegmentOffset)
.c_str() :
"NULL",
(textureIndicesSegmentOffset != 0) ?
StringHelper::Sprintf("%sAnimatedTextureTexIndices0x%06X", zRoom->GetName().c_str(),
textureIndicesSegmentOffset)
.c_str() :
"NULL");
}
size_t CyclingTextureParams::GetParamsSize()
{
return 12;
}
@@ -1,29 +1,31 @@
#include "SetCameraSettings.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
using namespace std;
#include "BitConverter.h"
#include "StringHelper.h"
SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetCameraSettings::SetCameraSettings(ZFile* nParent) : ZRoomCommand(nParent)
{
cameraMovement = rawData[rawDataIndex + 0x01];
mapHighlight = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
}
string SetCameraSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetCameraSettings::ParseRawData()
{
return StringHelper::Sprintf(
"%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
cameraMovement, mapHighlight);
ZRoomCommand::ParseRawData();
cameraMovement = cmdArg1;
mapHighlight = BitConverter::ToUInt32BE(parent->GetRawData(), rawDataIndex + 4);
}
string SetCameraSettings::GetCommandCName()
std::string SetCameraSettings::GetBodySourceCode() const
{
return StringHelper::Sprintf("SCENE_CMD_MISC_SETTINGS(0x%02X, 0x%08X)", cameraMovement,
mapHighlight);
}
std::string SetCameraSettings::GetCommandCName() const
{
return "SCmdMiscSettings";
}
RoomCommand SetCameraSettings::GetRoomCommand()
RoomCommand SetCameraSettings::GetRoomCommand() const
{
return RoomCommand::SetCameraSettings;
}
}
@@ -1,17 +1,20 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class SetCameraSettings : public ZRoomCommand
{
public:
SetCameraSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetCameraSettings(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void ParseRawData() override;
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
private:
uint8_t cameraMovement;
uint32_t mapHighlight;
};
};
@@ -1,48 +1,42 @@
#include "SetCollisionHeader.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetCollisionHeader::SetCollisionHeader(ZRoom* nZRoom, std::vector<uint8_t> rawData,
uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetCollisionHeader::SetCollisionHeader(ZFile* nParent) : ZRoomCommand(nParent)
{
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
collisionHeader = new ZCollisionHeader(nZRoom->parent);
collisionHeader->SetRawData(rawData);
}
void SetCollisionHeader::ParseRawData()
{
ZRoomCommand::ParseRawData();
collisionHeader = new ZCollisionHeader(parent);
collisionHeader->SetRawData(parent->GetRawData());
collisionHeader->SetRawDataIndex(segmentOffset);
collisionHeader->SetName(
StringHelper::Sprintf("%sCollisionHeader0x%06X", nZRoom->GetName().c_str(), segmentOffset));
StringHelper::Sprintf("%sCollisionHeader_%06X", parent->GetName().c_str(), segmentOffset));
collisionHeader->ParseRawData();
}
string SetCollisionHeader::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
SetCollisionHeader::~SetCollisionHeader()
{
return StringHelper::Sprintf(
"%s 0x00, (u32)&%sCollisionHeader0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
zRoom->GetName().c_str(), segmentOffset);
delete collisionHeader;
}
string SetCollisionHeader::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
std::string SetCollisionHeader::GetBodySourceCode() const
{
return "";
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_COL_HEADER(%s)", listName.c_str());
}
string SetCollisionHeader::GetCommandCName()
std::string SetCollisionHeader::GetCommandCName() const
{
return "SCmdColHeader";
}
string SetCollisionHeader::GenerateExterns()
{
return "";
}
RoomCommand SetCollisionHeader::GetRoomCommand()
RoomCommand SetCollisionHeader::GetRoomCommand() const
{
return RoomCommand::SetCollisionHeader;
}
}
@@ -1,20 +1,21 @@
#pragma once
#include "../../ZCollision.h"
#include "../ZRoomCommand.h"
#include "ZCollision.h"
#include "ZRoom/ZRoomCommand.h"
class SetCollisionHeader : public ZRoomCommand
{
public:
SetCollisionHeader(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetCollisionHeader(ZFile* nParent);
~SetCollisionHeader();
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual std::string GenerateExterns() override;
virtual RoomCommand GetRoomCommand() override;
void ParseRawData() override;
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
private:
ZCollisionHeader* collisionHeader;
uint32_t segmentOffset;
};
};
+90 -81
View File
@@ -1,87 +1,64 @@
#include "SetCsCamera.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetCsCamera::SetCsCamera(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetCsCamera::SetCsCamera(ZFile* nParent) : ZRoomCommand(nParent)
{
_rawData = rawData;
_rawDataIndex = rawDataIndex;
}
segmentOffset = 0;
int32_t numCameras = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
void SetCsCamera::ParseRawData()
{
ZRoomCommand::ParseRawData();
int numCameras = cmdArg1;
uint32_t currentPtr = segmentOffset;
int32_t numPoints = 0;
for (int32_t i = 0; i < numCameras; i++)
{
CsCameraEntry* entry = new CsCameraEntry(_rawData, currentPtr);
CsCameraEntry entry(parent->GetRawData(), currentPtr);
numPoints += entry.GetNumPoints();
currentPtr += entry.GetRawDataSize();
cameras.push_back(entry);
numPoints += entry->numPoints;
currentPtr += 8;
}
if (numPoints > 0)
{
uint32_t currentPtr = cameras[0]->segmentOffset;
uint32_t currentPtr = cameras.at(0).GetSegmentOffset();
for (int32_t i = 0; i < numPoints; i++)
{
int16_t x = BitConverter::ToInt16BE(rawData, currentPtr + 0);
int16_t y = BitConverter::ToInt16BE(rawData, currentPtr + 2);
int16_t z = BitConverter::ToInt16BE(rawData, currentPtr + 4);
Vec3s p = {x, y, z};
points.push_back(p);
currentPtr += 6;
ZVector vec(parent);
vec.SetRawData(parent->GetRawData());
vec.SetRawDataIndex(currentPtr);
vec.SetScalarType(ZScalarType::ZSCALAR_S16);
vec.SetDimensions(3);
vec.ParseRawData();
currentPtr += vec.GetRawDataSize();
points.push_back(vec);
}
}
if (segmentOffset != 0)
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
parent->AddDeclarationPlaceholder(segmentOffset);
}
SetCsCamera::~SetCsCamera()
void SetCsCamera::DeclareReferences(const std::string& prefix)
{
for (CsCameraEntry* entry : cameras)
delete entry;
}
string SetCsCamera::GetSourceOutputCode(std::string prefix)
{
return "";
}
string SetCsCamera::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
{
return "";
}
string SetCsCamera::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
{
string sourceOutput = "";
sourceOutput +=
StringHelper::Sprintf("%s %i, (u32)&%sCsCameraList0x%06X };",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
cameras.size(), roomName.c_str(), segmentOffset);
if (points.size() > 0)
{
string declaration = "";
std::string declaration = "";
size_t index = 0;
for (Vec3s point : points)
for (auto& point : points)
{
declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", point.x, point.y,
point.z, cameras[0]->segmentOffset + (index * 6));
declaration +=
StringHelper::Sprintf("\t%s, //0x%06X", point.GetBodySourceCode().c_str(),
cameras.at(0).segmentOffset + (index * 6));
if (index < points.size() - 1)
declaration += "\n";
@@ -89,65 +66,97 @@ string SetCsCamera::GenerateSourceCodePass2(string roomName, uint32_t baseAddres
index++;
}
zRoom->parent->AddDeclarationArray(cameras[0]->segmentOffset, DeclarationAlignment::None,
DeclarationPadding::None, points.size() * 6, "Vec3s",
StringHelper::Sprintf("%sCsCameraPoints0x%06X",
roomName.c_str(),
cameras[0]->segmentOffset),
points.size(), declaration);
uint32_t segOffset = cameras.at(0).GetSegmentOffset();
parent->AddDeclarationArray(
segOffset, DeclarationAlignment::Align4, points.size() * points.at(0).GetRawDataSize(),
points.at(0).GetSourceTypeName().c_str(),
StringHelper::Sprintf("%sCsCameraPoints_%06X", prefix.c_str(), segOffset),
points.size(), declaration);
}
if (!cameras.empty())
{
string declaration = "";
std::string camPointsName = parent->GetDeclarationName(cameras.at(0).GetSegmentOffset());
std::string declaration = "";
size_t index = 0;
size_t pointsIndex = 0;
for (CsCameraEntry* entry : cameras)
for (const auto& entry : cameras)
{
declaration += StringHelper::Sprintf(" %i, %i, (u32)&%sCsCameraPoints0x%06X[%i],",
entry->type, entry->numPoints, roomName.c_str(),
cameras[0]->segmentOffset, pointsIndex);
declaration +=
StringHelper::Sprintf("\t{ %i, %i, &%s[%i] },", entry.type, entry.numPoints,
camPointsName.c_str(), pointsIndex);
if (index < cameras.size() - 1)
declaration += "\n";
index++;
pointsIndex += entry->numPoints;
pointsIndex += entry.GetNumPoints();
}
zRoom->parent->AddDeclarationArray(
const auto& entry = cameras.front();
std::string camTypename = entry.GetSourceTypeName();
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::Pad16,
cameras.size() * 8, "CsCameraEntry",
StringHelper::Sprintf("%sCsCameraList0x%06X", roomName.c_str(), segmentOffset),
cameras.size() * entry.GetRawDataSize(), camTypename,
StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), camTypename.c_str(), segmentOffset),
cameras.size(), declaration);
}
return sourceOutput;
}
size_t SetCsCamera::GetRawDataSize()
std::string SetCsCamera::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_CAM_LIST(%i, %s)", cameras.size(),
listName.c_str());
}
size_t SetCsCamera::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize() + (cameras.size() * 8) + (points.size() * 6);
}
string SetCsCamera::GenerateExterns()
{
return "";
}
string SetCsCamera::GetCommandCName()
std::string SetCsCamera::GetCommandCName() const
{
return "SCmdCsCameraList";
}
RoomCommand SetCsCamera::GetRoomCommand()
RoomCommand SetCsCamera::GetRoomCommand() const
{
return RoomCommand::SetCsCamera;
}
CsCameraEntry::CsCameraEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
CsCameraEntry::CsCameraEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
: baseOffset(rawDataIndex), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 0)),
numPoints(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)),
segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)))
numPoints(BitConverter::ToInt16BE(rawData, rawDataIndex + 2))
{
camAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
segmentOffset = GETSEGOFFSET(camAddress);
}
std::string CsCameraEntry::GetSourceTypeName() const
{
return "CsCameraEntry";
}
int32_t CsCameraEntry::GetRawDataSize() const
{
return 8;
}
int16_t CsCameraEntry::GetNumPoints() const
{
return numPoints;
}
segptr_t CsCameraEntry::GetCamAddress() const
{
return camAddress;
}
uint32_t CsCameraEntry::GetSegmentOffset() const
{
return segmentOffset;
}
+25 -20
View File
@@ -1,37 +1,42 @@
#pragma once
#include "../../Vec3s.h"
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
#include "ZVector.h"
class CsCameraEntry
{
public:
CsCameraEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
CsCameraEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
int32_t baseOffset;
int32_t type;
int32_t numPoints;
std::string GetSourceTypeName() const;
int32_t GetRawDataSize() const;
int16_t GetNumPoints() const;
segptr_t GetCamAddress() const;
uint32_t GetSegmentOffset() const;
int baseOffset;
int16_t type;
int16_t numPoints;
segptr_t camAddress;
uint32_t segmentOffset;
};
class SetCsCamera : public ZRoomCommand
{
public:
SetCsCamera(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetCsCamera();
SetCsCamera(ZFile* nParent);
std::string GetSourceOutputCode(std::string prefix);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
virtual RoomCommand GetRoomCommand() override;
virtual size_t GetRawDataSize() override;
virtual std::string GetCommandCName() override;
virtual std::string GenerateExterns() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
std::string GetCommandCName() const override;
private:
uint32_t segmentOffset;
std::vector<CsCameraEntry*> cameras;
std::vector<Vec3s> points;
std::vector<uint8_t> _rawData;
int32_t _rawDataIndex;
std::vector<CsCameraEntry> cameras;
std::vector<ZVector> points;
};
+40 -70
View File
@@ -1,26 +1,27 @@
#include "SetCutscenes.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetCutscenes::SetCutscenes(ZFile* nParent) : ZRoomCommand(nParent)
{
numCutscenes = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
}
string output = "";
void SetCutscenes::ParseRawData()
{
ZRoomCommand::ParseRawData();
std::string output = "";
numCutscenes = cmdArg1;
if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97)
{
ZCutscene* cutscene = new ZCutscene(nZRoom->parent);
cutscene->ExtractFromFile(rawData, segmentOffset, "");
ZCutscene* cutscene = new ZCutscene(parent);
cutscene->ExtractFromFile(parent->GetRawData(), segmentOffset);
auto decl = nZRoom->parent->GetDeclaration(segmentOffset);
auto decl = parent->GetDeclaration(segmentOffset);
if (decl == nullptr)
{
cutscene->DeclareVar(zRoom->GetName().c_str(), "");
@@ -31,41 +32,38 @@ SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t
else
{
int32_t currentPtr = segmentOffset;
string declaration = "";
std::string declaration = "";
for (uint8_t i = 0; i < numCutscenes; i++)
{
CutsceneEntry* entry = new CutsceneEntry(rawData, currentPtr);
CutsceneEntry entry(parent->GetRawData(), currentPtr);
cutsceneEntries.push_back(entry);
currentPtr += 8;
declaration += StringHelper::Sprintf(
" { %sCutsceneData0x%06X, 0x%04X, 0x%02X, 0x%02X },", zRoom->GetName().c_str(),
entry->segmentOffset, entry->exit, entry->entrance, entry->flag);
entry.segmentOffset, entry.exit, entry.entrance, entry.flag);
if (i < numCutscenes - 1)
declaration += "\n";
ZCutsceneMM* cutscene = new ZCutsceneMM(nZRoom->parent);
cutscene->ExtractFromXML(
nullptr, rawData, entry->segmentOffset,
""); // TODO: Use ExtractFromFile() here when that gets implemented
ZCutsceneMM* cutscene = new ZCutsceneMM(parent);
cutscene->ExtractFromFile(parent->GetRawData(), entry.segmentOffset);
cutscenes.push_back(cutscene);
}
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, DeclarationPadding::None,
cutsceneEntries.size() * 8, "CutsceneEntry",
StringHelper::Sprintf("%sCutsceneEntryList0x%06X", zRoom->GetName().c_str(),
segmentOffset),
cutsceneEntries.size(), declaration);
parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4,
cutsceneEntries.size() * 8, "CutsceneEntry",
StringHelper::Sprintf("%sCutsceneEntryList_%06X",
zRoom->GetName().c_str(), segmentOffset),
cutsceneEntries.size(), declaration);
}
for (ZCutsceneBase* cutscene : cutscenes)
{
if (cutscene->getSegmentOffset() != 0)
{
Declaration* decl = zRoom->parent->GetDeclaration(cutscene->getSegmentOffset());
Declaration* decl = parent->GetDeclaration(cutscene->getSegmentOffset());
if (decl == nullptr)
{
cutscene->GetSourceOutputCode(zRoom->GetName());
@@ -82,63 +80,35 @@ SetCutscenes::~SetCutscenes()
{
for (ZCutsceneBase* cutscene : cutscenes)
delete cutscene;
for (CutsceneEntry* entry : cutsceneEntries)
delete entry;
}
string SetCutscenes::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
std::string SetCutscenes::GetBodySourceCode() const
{
string pass1 = ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress);
Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset);
if (decl != nullptr)
{
return StringHelper::Sprintf("%s %i, (u32)%s", pass1.c_str(), numCutscenes,
decl->varName.c_str());
}
return StringHelper::Sprintf("%s %i, (u32)%sCutsceneData0x%06X", pass1.c_str(), numCutscenes,
zRoom->GetName().c_str(), segmentOffset);
}
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
size_t SetCutscenes::GetRawDataSize()
{
return ZRoomCommand::GetRawDataSize() + (0);
}
string SetCutscenes::GenerateExterns()
{
if (Globals::Instance->game == ZGame::MM_RETAIL)
{
return StringHelper::Sprintf("extern CutsceneEntry %sCutsceneEntryList0x%06X[];\n",
zRoom->GetName().c_str(), segmentOffset);
}
Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset);
if (decl != nullptr && decl->varName != "")
{
return StringHelper::Sprintf("extern s32 %s[];\n", decl->varName.c_str());
}
return StringHelper::Sprintf("extern s32 %sCutsceneData0x%06X[];\n", zRoom->GetName().c_str(),
segmentOffset);
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_LIST(%i, %s)", numCutscenes,
listName.c_str());
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_DATA(%s)", listName.c_str());
}
string SetCutscenes::GetCommandCName()
size_t SetCutscenes::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize();
}
std::string SetCutscenes::GetCommandCName() const
{
return "SCmdCutsceneData";
}
RoomCommand SetCutscenes::GetRoomCommand()
RoomCommand SetCutscenes::GetRoomCommand() const
{
return RoomCommand::SetCutscenes;
}
string SetCutscenes::GetSourceOutputCode(std::string prefix)
{
return "";
}
CutsceneEntry::CutsceneEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: segmentOffset(BitConverter::ToInt32BE(rawData, rawDataIndex + 0) & 0x00FFFFFF),
CutsceneEntry::CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
: segmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 0))),
exit(BitConverter::ToInt16BE(rawData, rawDataIndex + 4)), entrance(rawData[rawDataIndex + 6]),
flag(rawData[rawDataIndex + 7])
{
+15 -17
View File
@@ -1,13 +1,13 @@
#pragma once
#include "../../ZCutscene.h"
#include "../../ZCutsceneMM.h"
#include "../ZRoomCommand.h"
#include "ZCutscene.h"
#include "ZCutsceneMM.h"
#include "ZRoom/ZRoomCommand.h"
class CutsceneEntry
{
public:
CutsceneEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
CutsceneEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
uint32_t segmentOffset;
uint16_t exit;
@@ -18,21 +18,19 @@ public:
class SetCutscenes : public ZRoomCommand
{
public:
SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetCutscenes(ZFile* nParent);
~SetCutscenes();
std::string GetSourceOutputCode(std::string prefix);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual RoomCommand GetRoomCommand() override;
virtual size_t GetRawDataSize() override;
virtual std::string GetCommandCName() override;
virtual std::string GenerateExterns() override;
void ParseRawData() override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
std::string GetCommandCName() const override;
private:
std::vector<ZCutsceneBase*> cutscenes;
std::vector<CutsceneEntry*> cutsceneEntries; // (MM Only)
uint32_t segmentOffset;
uint8_t numCutscenes; // (MM Only)
std::vector<uint8_t> _rawData;
int32_t _rawDataIndex;
};
std::vector<CutsceneEntry> cutsceneEntries; // (MM Only)
uint8_t numCutscenes; // (MM Only)
};
@@ -1,27 +1,27 @@
#include "SetEchoSettings.h"
#include "../../StringHelper.h"
#include "StringHelper.h"
using namespace std;
SetEchoSettings::SetEchoSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetEchoSettings::SetEchoSettings(ZFile* nParent) : ZRoomCommand(nParent)
{
echo = rawData[rawDataIndex + 0x07];
}
string SetEchoSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetEchoSettings::ParseRawData()
{
return StringHelper::Sprintf(
"%s 0, { 0 }, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
echo);
ZRoomCommand::ParseRawData();
echo = parent->GetRawData().at(rawDataIndex + 0x07);
}
string SetEchoSettings::GetCommandCName()
std::string SetEchoSettings::GetBodySourceCode() const
{
return StringHelper::Sprintf("SCENE_CMD_ECHO_SETTINGS(%i)", echo);
}
std::string SetEchoSettings::GetCommandCName() const
{
return "SCmdEchoSettings";
}
RoomCommand SetEchoSettings::GetRoomCommand()
RoomCommand SetEchoSettings::GetRoomCommand() const
{
return RoomCommand::SetEchoSettings;
}
}
@@ -1,16 +1,19 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class SetEchoSettings : public ZRoomCommand
{
public:
SetEchoSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetEchoSettings(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void ParseRawData() override;
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
private:
uint8_t echo;
};
};
@@ -1,86 +1,83 @@
#include "SetEntranceList.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
#include "BitConverter.h"
#include "SetStartPositionList.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
using namespace std;
SetEntranceList::SetEntranceList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetEntranceList::SetEntranceList(ZFile* nParent) : ZRoomCommand(nParent)
{
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
entrances = vector<EntranceEntry*>();
_rawData = rawData;
_rawDataIndex = rawDataIndex;
}
SetEntranceList::~SetEntranceList()
void SetEntranceList::DeclareReferences(const std::string& prefix)
{
for (EntranceEntry* entry : entrances)
delete entry;
if (segmentOffset != 0)
parent->AddDeclarationPlaceholder(segmentOffset);
}
string SetEntranceList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetEntranceList::ParseRawDataLate()
{
string sourceOutput =
StringHelper::Sprintf("%s 0x00, (u32)&%sEntranceList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
zRoom->GetName().c_str(), segmentOffset);
// Parse Entrances and Generate Declaration
zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined
int32_t numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
uint32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numEntrances; i++)
{
EntranceEntry* entry = new EntranceEntry(_rawData, currentPtr);
EntranceEntry entry(parent->GetRawData(), currentPtr);
entrances.push_back(entry);
currentPtr += 2;
}
string declaration = "";
int32_t index = 0;
for (EntranceEntry* entry : entrances)
{
declaration +=
StringHelper::Sprintf(" { 0x%02X, 0x%02X }, //0x%06X \n", entry->startPositionIndex,
entry->roomToLoad, segmentOffset + (index * 2));
index++;
}
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, entrances.size() * 2, "EntranceEntry",
StringHelper::Sprintf("%sEntranceList0x%06X", zRoom->GetName().c_str(), segmentOffset),
entrances.size(), declaration);
return sourceOutput;
}
string SetEntranceList::GenerateExterns()
void SetEntranceList::DeclareReferencesLate(const std::string& prefix)
{
return StringHelper::Sprintf("extern EntranceEntry %sEntranceList0x%06X[];\n",
zRoom->GetName().c_str(), segmentOffset);
if (!entrances.empty())
{
std::string declaration = "";
size_t index = 0;
for (const auto& entry : entrances)
{
declaration +=
StringHelper::Sprintf(" { %s }, //0x%06X", entry.GetBodySourceCode().c_str(),
segmentOffset + (index * 2));
if (index + 1 < entrances.size())
declaration += "\n";
index++;
}
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, entrances.size() * 2, "EntranceEntry",
StringHelper::Sprintf("%sEntranceList0x%06X", zRoom->GetName().c_str(), segmentOffset),
entrances.size(), declaration);
}
}
string SetEntranceList::GetCommandCName()
std::string SetEntranceList::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_ENTRANCE_LIST(%s)", listName.c_str());
}
std::string SetEntranceList::GetCommandCName() const
{
return "SCmdEntranceList";
}
RoomCommand SetEntranceList::GetRoomCommand()
RoomCommand SetEntranceList::GetRoomCommand() const
{
return RoomCommand::SetEntranceList;
}
EntranceEntry::EntranceEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
EntranceEntry::EntranceEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
startPositionIndex = rawData[rawDataIndex + 0];
roomToLoad = rawData[rawDataIndex + 1];
}
startPositionIndex = rawData.at(rawDataIndex + 0);
roomToLoad = rawData.at(rawDataIndex + 1);
}
std::string EntranceEntry::GetBodySourceCode() const
{
return StringHelper::Sprintf("0x%02X, 0x%02X", startPositionIndex, roomToLoad);
}
@@ -1,30 +1,33 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class EntranceEntry
{
public:
EntranceEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetBodySourceCode() const;
protected:
uint8_t startPositionIndex;
uint8_t roomToLoad;
EntranceEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
};
class SetEntranceList : public ZRoomCommand
{
public:
SetEntranceList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetEntranceList();
SetEntranceList(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GenerateExterns() override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void DeclareReferences(const std::string& prefix) override;
void ParseRawDataLate() override;
void DeclareReferencesLate(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
private:
std::vector<EntranceEntry*> entrances;
uint32_t segmentOffset;
std::vector<uint8_t> _rawData;
int32_t _rawDataIndex;
};
std::vector<EntranceEntry> entrances;
};
+39 -43
View File
@@ -1,71 +1,67 @@
#include "SetExitList.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetExitList::SetExitList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetExitList::SetExitList(ZFile* nParent) : ZRoomCommand(nParent)
{
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
exits = vector<uint16_t>();
if (segmentOffset != 0)
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
_rawData = rawData;
_rawDataIndex = rawDataIndex;
}
string SetExitList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetExitList::DeclareReferences(const std::string& prefix)
{
string sourceOutput =
StringHelper::Sprintf("%s 0x00, (u32)&%sExitList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
zRoom->GetName().c_str(), segmentOffset);
if (segmentOffset != 0)
parent->AddDeclarationPlaceholder(segmentOffset);
}
void SetExitList::ParseRawDataLate()
{
// Parse Entrances and Generate Declaration
zRoom->parent->AddDeclarationPlaceholder(segmentOffset); // Make sure this segment is defined
int32_t numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
int numEntrances = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 2;
uint32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numEntrances; i++)
{
uint16_t exit = BitConverter::ToInt16BE(_rawData, currentPtr);
uint16_t exit = BitConverter::ToUInt16BE(parent->GetRawData(), currentPtr);
exits.push_back(exit);
currentPtr += 2;
}
string declaration = "";
for (uint16_t exit : exits)
declaration += StringHelper::Sprintf(" 0x%04X,\n", exit);
;
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, exits.size() * 2, "u16",
StringHelper::Sprintf("%sExitList0x%06X", zRoom->GetName().c_str(), segmentOffset),
exits.size(), declaration);
return sourceOutput;
}
string SetExitList::GenerateExterns()
void SetExitList::DeclareReferencesLate(const std::string& prefix)
{
return StringHelper::Sprintf("extern u16 %sExitList0x%06X[];\n", zRoom->GetName().c_str(),
segmentOffset);
;
if (!exits.empty())
{
std::string declaration = "";
for (size_t i = 0; i < exits.size(); i++)
{
declaration += StringHelper::Sprintf(" 0x%04X,", exits.at(i));
if (i + 1 < exits.size())
declaration += "\n";
}
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::Align4, exits.size() * 2, "u16",
StringHelper::Sprintf("%sExitList_%06X", zRoom->GetName().c_str(), segmentOffset),
exits.size(), declaration);
}
}
string SetExitList::GetCommandCName()
std::string SetExitList::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_EXIT_LIST(%s)", listName.c_str());
}
std::string SetExitList::GetCommandCName() const
{
return "SCmdExitList";
}
RoomCommand SetExitList::GetRoomCommand()
RoomCommand SetExitList::GetRoomCommand() const
{
return RoomCommand::SetExitList;
}
}
+11 -10
View File
@@ -1,20 +1,21 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class SetExitList : public ZRoomCommand
{
public:
SetExitList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetExitList(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GenerateExterns() override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void DeclareReferences(const std::string& prefix) override;
void ParseRawDataLate() override;
void DeclareReferencesLate(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
private:
std::vector<uint16_t> exits;
uint32_t segmentOffset;
std::vector<uint8_t> _rawData;
int32_t _rawDataIndex;
};
};
+75 -50
View File
@@ -1,69 +1,94 @@
#include "SetLightList.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "BitConverter.h"
#include "StringHelper.h"
using namespace std;
SetLightList::SetLightList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetLightList::SetLightList(ZFile* nParent) : ZRoomCommand(nParent)
{
this->ptrRoom = nZRoom;
this->numLights = rawData[rawDataIndex + 1];
this->segment = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
}
// std::string declarations = StringHelper::Sprintf("LightInfo %sLightInfo0x%06X[] =\n{\n",
// this->ptrRoom->GetName().c_str(), this->segment);
string declarations = "";
void SetLightList::ParseRawData()
{
ZRoomCommand::ParseRawData();
std::string declarations = "";
int32_t currentPtr = this->segment;
for (int32_t i = 0; i < this->numLights; i++)
numLights = cmdArg1;
int32_t currentPtr = segmentOffset;
for (int i = 0; i < this->numLights; i++)
{
uint8_t type = rawData[currentPtr + 0];
int16_t x = BitConverter::ToInt16BE(rawData, currentPtr + 2);
int16_t y = BitConverter::ToInt16BE(rawData, currentPtr + 4);
int16_t z = BitConverter::ToInt16BE(rawData, currentPtr + 6);
uint8_t r = rawData[currentPtr + 8];
uint8_t g = rawData[currentPtr + 9];
uint8_t b = rawData[currentPtr + 10];
uint8_t drawGlow = rawData[currentPtr + 11];
int16_t radius = BitConverter::ToInt16BE(rawData, currentPtr + 12);
LightInfo light(parent->GetRawData(), currentPtr);
currentPtr += 14;
declarations += StringHelper::Sprintf(
" { 0x%02X, { %i, %i, %i, { 0x%02X, 0x%02X, 0x%02X }, 0x%02X, 0x%04X } },", type, x,
y, z, r, g, b, drawGlow, radius);
if (i < this->numLights - 1)
declarations += "\n";
currentPtr += light.GetRawDataSize();
lights.push_back(light);
}
this->ptrRoom->parent->AddDeclarationArray(
this->segment, DeclarationAlignment::None, this->numLights * 0xE, "LightInfo",
StringHelper::Sprintf("%sLightInfo0x%06X", this->ptrRoom->GetName().c_str(), this->segment),
this->numLights, declarations);
}
string SetLightList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetLightList::DeclareReferences(const std::string& prefix)
{
return StringHelper::Sprintf(
"%s %i, &%sLightInfo0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), this->numLights,
this->ptrRoom->GetName().c_str(), this->segment);
if (!lights.empty())
{
std::string declarations = "";
for (size_t i = 0; i < lights.size(); i++)
{
declarations +=
StringHelper::Sprintf("\t{ %s },", lights.at(i).GetBodySourceCode().c_str());
if (i < lights.size() - 1)
declarations += "\n";
}
const auto& light = lights.front();
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, lights.size() * light.GetRawDataSize(),
light.GetSourceTypeName(),
StringHelper::Sprintf("%sLightInfo0x%06X", prefix.c_str(), segmentOffset),
lights.size(), declarations);
}
}
string SetLightList::GetCommandCName()
std::string SetLightList::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_LIGHT_LIST(%i, %s)", numLights, listName.c_str());
}
std::string SetLightList::GetCommandCName() const
{
return "SCmdLightList";
}
string SetLightList::GenerateExterns()
{
return StringHelper::Sprintf("extern LightInfo %sLightInfo0x%06X[];\n",
this->ptrRoom->GetName().c_str(), this->segment);
}
RoomCommand SetLightList::GetRoomCommand()
RoomCommand SetLightList::GetRoomCommand() const
{
return RoomCommand::SetLightList;
}
}
LightInfo::LightInfo(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
type = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0);
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
y = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
z = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
r = BitConverter::ToUInt8BE(rawData, rawDataIndex + 8);
g = BitConverter::ToUInt8BE(rawData, rawDataIndex + 9);
b = BitConverter::ToUInt8BE(rawData, rawDataIndex + 10);
drawGlow = BitConverter::ToUInt8BE(rawData, rawDataIndex + 11);
radius = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
}
std::string LightInfo::GetBodySourceCode() const
{
return StringHelper::Sprintf(
"0x%02X, { %i, %i, %i, { 0x%02X, 0x%02X, 0x%02X }, 0x%02X, 0x%04X }", type, x, y, z, r, g,
b, drawGlow, radius);
}
std::string LightInfo::GetSourceTypeName() const
{
return "LightInfo";
}
size_t LightInfo::GetRawDataSize() const
{
return 0x0E;
}
+30 -11
View File
@@ -2,23 +2,42 @@
#include <string>
#include "../ZRoom.h"
#include "../ZRoomCommand.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
#include "ZRoom/ZRoomCommand.h"
class LightInfo
{
public:
LightInfo(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetBodySourceCode() const;
std::string GetSourceTypeName() const;
size_t GetRawDataSize() const;
protected:
uint8_t type;
int16_t x, y, z;
uint8_t r, g, b;
uint8_t drawGlow;
int16_t radius;
};
class SetLightList : public ZRoomCommand
{
public:
SetLightList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetLightList(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
virtual std::string GenerateExterns() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
private:
uint8_t numLights;
uint32_t segment;
ZRoom* ptrRoom;
};
std::vector<LightInfo> lights;
};
@@ -1,113 +1,103 @@
#include "SetLightingSettings.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
using namespace std;
SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData,
uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetLightingSettings::SetLightingSettings(ZFile* nParent) : ZRoomCommand(nParent)
{
uint8_t numLights = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
}
for (int32_t i = 0; i < numLights; i++)
settings.push_back(new LightingSettings(rawData, segmentOffset + (i * 22)));
void SetLightingSettings::ParseRawData()
{
ZRoomCommand::ParseRawData();
uint8_t numLights = cmdArg1;
if (numLights > 0)
for (int i = 0; i < numLights; i++)
settings.push_back(LightingSettings(parent->GetRawData(), segmentOffset + (i * 22)));
}
void SetLightingSettings::DeclareReferences(const std::string& prefix)
{
if (settings.size() > 0)
{
string declaration = "";
std::string declaration = "";
for (int32_t i = 0; i < numLights; i++)
for (size_t i = 0; i < settings.size(); i++)
{
declaration += StringHelper::Sprintf(
"\t{ 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, "
"0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%04X, "
"0x%04X }, // 0x%06X",
settings[i]->ambientClrR, settings[i]->ambientClrG, settings[i]->ambientClrB,
settings[i]->diffuseClrA_R, settings[i]->diffuseClrA_G, settings[i]->diffuseClrA_B,
settings[i]->diffuseDirA_X, settings[i]->diffuseDirA_Y, settings[i]->diffuseDirA_Z,
settings[i]->diffuseClrB_R, settings[i]->diffuseClrB_G, settings[i]->diffuseClrB_B,
settings[i]->diffuseDirB_X, settings[i]->diffuseDirB_Y, settings[i]->diffuseDirB_Z,
settings[i]->fogClrR, settings[i]->fogClrG, settings[i]->fogClrB, settings[i]->unk,
settings[i]->drawDistance, segmentOffset + (i * 22));
if (i + 1 < numLights)
declaration += StringHelper::Sprintf("\t{ %s }, // 0x%06X",
settings.at(i).GetBodySourceCode().c_str(),
segmentOffset + (i * 22));
if (i + 1 < settings.size())
declaration += "\n";
}
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, numLights * 22,
"LightSettings",
StringHelper::Sprintf("%sLightSettings_%06X", zRoom->GetName().c_str(), segmentOffset),
numLights, declaration);
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::Align4,
settings.size() * settings.front().GetRawDataSize(), "LightSettings",
StringHelper::Sprintf("%sLightSettings0x%06X", prefix.c_str(), segmentOffset),
settings.size(), declaration);
}
}
SetLightingSettings::~SetLightingSettings()
std::string SetLightingSettings::GetBodySourceCode() const
{
for (LightingSettings* setting : settings)
delete setting;
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_ENV_LIGHT_SETTINGS(%i, %s)", settings.size(),
listName.c_str());
}
string SetLightingSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
{
return StringHelper::Sprintf(
"%s %i, (u32)&%sLightSettings_%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), settings.size(),
zRoom->GetName().c_str(), segmentOffset);
}
string SetLightingSettings::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
{
return "";
}
string SetLightingSettings::GetCommandCName()
std::string SetLightingSettings::GetCommandCName() const
{
return "SCmdLightSettingList";
}
string SetLightingSettings::GenerateExterns()
{
return StringHelper::Sprintf("extern LightSettings %sLightSettings_%06X[];\n",
zRoom->GetName().c_str(), segmentOffset);
}
RoomCommand SetLightingSettings::GetRoomCommand()
RoomCommand SetLightingSettings::GetRoomCommand() const
{
return RoomCommand::SetLightingSettings;
}
LightingSettings::LightingSettings(vector<uint8_t> rawData, uint32_t rawDataIndex)
LightingSettings::LightingSettings(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
{
const uint8_t* data = rawData.data();
ambientClrR = rawData.at(rawDataIndex + 0);
ambientClrG = rawData.at(rawDataIndex + 1);
ambientClrB = rawData.at(rawDataIndex + 2);
ambientClrR = data[rawDataIndex + 0];
ambientClrG = data[rawDataIndex + 1];
ambientClrB = data[rawDataIndex + 2];
diffuseClrA_R = rawData.at(rawDataIndex + 3);
diffuseClrA_G = rawData.at(rawDataIndex + 4);
diffuseClrA_B = rawData.at(rawDataIndex + 5);
diffuseClrA_R = data[rawDataIndex + 3];
diffuseClrA_G = data[rawDataIndex + 4];
diffuseClrA_B = data[rawDataIndex + 5];
diffuseDirA_X = rawData.at(rawDataIndex + 6);
diffuseDirA_Y = rawData.at(rawDataIndex + 7);
diffuseDirA_Z = rawData.at(rawDataIndex + 8);
diffuseDirA_X = data[rawDataIndex + 6];
diffuseDirA_Y = data[rawDataIndex + 7];
diffuseDirA_Z = data[rawDataIndex + 8];
diffuseClrB_R = rawData.at(rawDataIndex + 9);
diffuseClrB_G = rawData.at(rawDataIndex + 10);
diffuseClrB_B = rawData.at(rawDataIndex + 11);
diffuseClrB_R = data[rawDataIndex + 9];
diffuseClrB_G = data[rawDataIndex + 10];
diffuseClrB_B = data[rawDataIndex + 11];
diffuseDirB_X = rawData.at(rawDataIndex + 12);
diffuseDirB_Y = rawData.at(rawDataIndex + 13);
diffuseDirB_Z = rawData.at(rawDataIndex + 14);
diffuseDirB_X = data[rawDataIndex + 12];
diffuseDirB_Y = data[rawDataIndex + 13];
diffuseDirB_Z = data[rawDataIndex + 14];
fogClrR = rawData.at(rawDataIndex + 15);
fogClrG = rawData.at(rawDataIndex + 16);
fogClrB = rawData.at(rawDataIndex + 17);
fogClrR = data[rawDataIndex + 15];
fogClrG = data[rawDataIndex + 16];
fogClrB = data[rawDataIndex + 17];
unk = BitConverter::ToInt16BE(data, rawDataIndex + 18);
drawDistance = BitConverter::ToInt16BE(data, rawDataIndex + 20);
unk = BitConverter::ToInt16BE(rawData, rawDataIndex + 18);
drawDistance = BitConverter::ToInt16BE(rawData, rawDataIndex + 20);
}
std::string LightingSettings::GetBodySourceCode() const
{
return StringHelper::Sprintf(
"0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, "
"0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%04X, 0x%04X",
ambientClrR, ambientClrG, ambientClrB, diffuseClrA_R, diffuseClrA_G, diffuseClrA_B,
diffuseDirA_X, diffuseDirA_Y, diffuseDirA_Z, diffuseClrB_R, diffuseClrB_G, diffuseClrB_B,
diffuseDirB_X, diffuseDirB_Y, diffuseDirB_Z, fogClrR, fogClrG, fogClrB, unk, drawDistance);
}
size_t LightingSettings::GetRawDataSize() const
{
return 0x16;
}
@@ -1,10 +1,17 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class LightingSettings
{
public:
LightingSettings(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetBodySourceCode() const;
size_t GetRawDataSize() const;
protected:
uint8_t ambientClrR, ambientClrG, ambientClrB;
uint8_t diffuseClrA_R, diffuseClrA_G, diffuseClrA_B;
uint8_t diffuseDirA_X, diffuseDirA_Y, diffuseDirA_Z;
@@ -13,23 +20,21 @@ public:
uint8_t fogClrR, fogClrG, fogClrB;
uint16_t unk;
uint16_t drawDistance;
LightingSettings(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
};
class SetLightingSettings : public ZRoomCommand
{
public:
SetLightingSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetLightingSettings();
SetLightingSettings(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual std::string GenerateExterns() override;
virtual RoomCommand GetRoomCommand() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
private:
uint32_t segmentOffset;
std::vector<LightingSettings*> settings;
};
std::vector<LightingSettings> settings;
};
+295 -427
View File
@@ -1,319 +1,114 @@
#include "SetMesh.h"
#include <Globals.h>
#include <Path.h>
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZBackground.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
using namespace std;
void GenDListDeclarations(ZRoom* zRoom, ZFile* parent, ZDisplayList* dList);
SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex,
int32_t segAddressOffset)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetMesh::SetMesh(ZFile* nParent) : ZRoomCommand(nParent)
{
data = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
string declaration = "";
meshHeaderType = rawData[segmentOffset + 0];
if (meshHeaderType == 0)
{
uint32_t dListStart = Seg2Filespace(BitConverter::ToInt32BE(rawData, segmentOffset + 4),
zRoom->parent->baseAddress);
uint32_t dListEnd = Seg2Filespace(BitConverter::ToInt32BE(rawData, segmentOffset + 8),
zRoom->parent->baseAddress);
int8_t numEntries = rawData[segmentOffset + 1];
uint32_t currentPtr = dListStart;
// Hack for Syotes
for (int32_t i = 0; i < abs(segAddressOffset); i++)
{
rawData.erase(rawData.begin());
segmentOffset--;
}
if (numEntries > 0)
{
std::string polyGfxBody = "";
std::string polyGfxType = "";
int32_t polyGfxSize = 0;
for (int32_t i = 0; i < numEntries; i++)
{
PolygonDlist polyGfxList(zRoom->GetName(), rawData, currentPtr, zRoom->parent,
zRoom);
if (polyGfxList.opaDList != nullptr)
{
GenDListDeclarations(rawData, polyGfxList.opaDList);
}
if (polyGfxList.xluDList != nullptr)
{
GenDListDeclarations(rawData, polyGfxList.xluDList);
}
polyGfxBody += polyGfxList.GetBodySourceCode(true);
polyGfxType = polyGfxList.GetSourceTypeName();
polyGfxSize = polyGfxList.GetRawDataSize();
currentPtr += polyGfxList.GetRawDataSize();
}
zRoom->parent->AddDeclarationArray(
dListStart, DeclarationAlignment::Align4, numEntries * polyGfxSize, polyGfxType,
StringHelper::Sprintf("%s%s0x%06X", zRoom->GetName().c_str(), polyGfxType.c_str(),
dListStart),
numEntries, polyGfxBody);
}
declaration = "\n ";
declaration += StringHelper::Sprintf("{ 0 }, 0x%02X, ", numEntries);
declaration += "\n ";
std::string entriesStr = "NULL";
if (dListStart != 0)
{
entriesStr = zRoom->parent->GetDeclaration(dListStart)->varName;
}
declaration += StringHelper::Sprintf("%s, ", entriesStr.c_str());
declaration += "\n ";
if (dListEnd != 0)
declaration += StringHelper::Sprintf("%s + ARRAY_COUNT(%s), ", entriesStr.c_str(),
entriesStr.c_str());
else
declaration += "NULL, ";
declaration += "\n";
zRoom->parent->AddDeclaration(
segmentOffset, DeclarationAlignment::Align16, 12, "MeshHeader0",
StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset),
declaration);
zRoom->parent->AddDeclaration(dListStart + (numEntries * 8), DeclarationAlignment::None,
DeclarationPadding::Pad16, 4, "static s32", "terminatorMaybe",
"0x01000000");
}
else if (meshHeaderType == 1)
{
PolygonType1 polygon1(zRoom->GetName().c_str(), rawData, segmentOffset, zRoom->parent,
zRoom);
if (polygon1.polyGfxList.opaDList != nullptr)
{
GenDListDeclarations(rawData, polygon1.polyGfxList.opaDList);
}
if (polygon1.polyGfxList.xluDList != nullptr)
{
GenDListDeclarations(rawData, polygon1.polyGfxList.xluDList);
}
polygon1.DeclareAndGenerateOutputCode();
}
else if (meshHeaderType == 2)
{
MeshHeader2* meshHeader2 = new MeshHeader2();
meshHeader2->headerType = 2;
meshHeader2->entries = vector<MeshEntry2*>();
meshHeader2->dListStart = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 4));
meshHeader2->dListEnd = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 8));
int8_t numEntries = rawData[segmentOffset + 1];
uint32_t currentPtr = meshHeader2->dListStart;
for (int32_t i = 0; i < numEntries; i++)
{
MeshEntry2* entry = new MeshEntry2();
entry->playerXMax = BitConverter::ToInt16BE(rawData, currentPtr + 0);
entry->playerZMax = BitConverter::ToInt16BE(rawData, currentPtr + 2);
entry->playerXMin = BitConverter::ToInt16BE(rawData, currentPtr + 4);
entry->playerZMin = BitConverter::ToInt16BE(rawData, currentPtr + 6);
entry->opaqueDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 8));
entry->translucentDListAddr =
GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 12));
if (entry->opaqueDListAddr != 0)
{
entry->opaqueDList = new ZDisplayList(
rawData, entry->opaqueDListAddr,
ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr,
Globals::Instance->game == ZGame::OOT_SW97 ?
DListType::F3DEX :
DListType::F3DZEX),
zRoom->parent);
entry->opaqueDList->scene = zRoom->scene;
GenDListDeclarations(rawData, entry->opaqueDList);
}
if (entry->translucentDListAddr != 0)
{
entry->translucentDList = new ZDisplayList(
rawData, entry->translucentDListAddr,
ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr,
Globals::Instance->game == ZGame::OOT_SW97 ?
DListType::F3DEX :
DListType::F3DZEX),
zRoom->parent);
entry->translucentDList->scene = zRoom->scene;
GenDListDeclarations(rawData, entry->translucentDList);
}
meshHeader2->entries.push_back(entry);
currentPtr += 16;
}
declaration += StringHelper::Sprintf("{ 2 }, 0x%02lX, ", meshHeader2->entries.size());
if (meshHeader2->dListStart != 0)
declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ",
zRoom->GetName().c_str(), meshHeader2->dListStart);
else
declaration += "0, ";
if (meshHeader2->dListEnd != 0)
declaration += StringHelper::Sprintf(
"(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)",
zRoom->GetName().c_str(), meshHeader2->dListStart, zRoom->GetName().c_str(),
meshHeader2->dListStart);
else
declaration += "0";
declaration += "\n";
zRoom->parent->AddDeclaration(
segmentOffset, DeclarationAlignment::None, 12, "MeshHeader2",
StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset),
declaration);
declaration = "";
for (size_t i = 0; i < meshHeader2->entries.size(); i++)
{
declaration += StringHelper::Sprintf(
" { %i, %i, %i, %i, ", meshHeader2->entries[i]->playerXMax,
meshHeader2->entries[i]->playerZMax, meshHeader2->entries[i]->playerXMin,
meshHeader2->entries[i]->playerZMin);
if (meshHeader2->entries[i]->opaqueDListAddr != 0)
declaration += StringHelper::Sprintf("(u32)%sDL_%06X, ", zRoom->GetName().c_str(),
meshHeader2->entries[i]->opaqueDListAddr);
else
declaration += "0, ";
if (meshHeader2->entries[i]->translucentDListAddr != 0)
declaration +=
StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(),
meshHeader2->entries[i]->translucentDListAddr);
else
declaration += "0 },\n";
}
zRoom->parent->AddDeclarationArray(
meshHeader2->dListStart, DeclarationAlignment::None, DeclarationPadding::None,
(meshHeader2->entries.size() * 16) + 0, "MeshEntry2",
StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(),
meshHeader2->dListStart, meshHeader2->entries.size()),
meshHeader2->entries.size(), declaration);
zRoom->parent->AddDeclaration(meshHeader2->dListStart + (meshHeader2->entries.size() * 16),
DeclarationAlignment::None, DeclarationPadding::Pad16, 4,
"static s32", "terminatorMaybe", "0x01000000");
meshHeader = meshHeader2;
}
}
SetMesh::~SetMesh()
void SetMesh::ParseRawData()
{
if (meshHeader != nullptr)
ZRoomCommand::ParseRawData();
auto& parentRawData = parent->GetRawData();
meshHeaderType = parentRawData.at(segmentOffset);
switch (meshHeaderType)
{
delete meshHeader;
meshHeader = nullptr;
case 0:
polyType = std::make_shared<PolygonType2>(parent, parentRawData, segmentOffset, zRoom);
break;
case 1:
polyType = std::make_shared<PolygonType1>(parent, parentRawData, segmentOffset, zRoom);
break;
case 2:
polyType = std::make_shared<PolygonType2>(parent, parentRawData, segmentOffset, zRoom);
break;
default:
throw std::runtime_error(StringHelper::Sprintf("Error in SetMesh::ParseRawData\n"
"\t Unknown meshHeaderType: %i\n",
meshHeaderType));
}
polyType->ParseRawData();
}
void SetMesh::GenDListDeclarations(std::vector<uint8_t> rawData, ZDisplayList* dList)
void SetMesh::DeclareReferences(const std::string& prefix)
{
string srcVarName =
polyType->SetName(polyType->GetDefaultName(prefix));
polyType->DeclareReferences(prefix);
polyType->DeclareAndGenerateOutputCode(prefix);
}
void GenDListDeclarations(ZRoom* zRoom, ZFile* parent, ZDisplayList* dList)
{
if (dList == nullptr)
{
return;
}
std::string srcVarName =
StringHelper::Sprintf("%s%s", zRoom->GetName().c_str(), dList->GetName().c_str());
dList->SetName(srcVarName);
string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName());
dList->scene = zRoom->scene;
std::string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName());
for (ZDisplayList* otherDList : dList->otherDLists)
GenDListDeclarations(rawData, otherDList);
GenDListDeclarations(zRoom, parent, otherDList);
for (pair<uint32_t, string> vtxEntry : dList->vtxDeclarations)
for (const auto& vtxEntry : dList->vtxDeclarations)
{
DeclarationAlignment alignment = DeclarationAlignment::Align8;
DeclarationAlignment alignment = DeclarationAlignment::Align4;
if (Globals::Instance->game == ZGame::MM_RETAIL)
alignment = DeclarationAlignment::None;
zRoom->parent->AddDeclarationArray(
parent->AddDeclarationArray(
vtxEntry.first, alignment, dList->vertices[vtxEntry.first].size() * 16, "static Vtx",
StringHelper::Sprintf("%sVtx_%06X", zRoom->GetName().c_str(), vtxEntry.first),
dList->vertices[vtxEntry.first].size(), vtxEntry.second);
}
for (pair<uint32_t, string> texEntry : dList->texDeclarations)
{
zRoom->textures[texEntry.first] = dList->textures[texEntry.first];
}
}
std::string SetMesh::GenDListExterns(ZDisplayList* dList)
{
string sourceOutput = "";
std::string sourceOutput = "";
if (Globals::Instance->includeFilePrefix)
sourceOutput += StringHelper::Sprintf("extern Gfx %sDL_%06X[];\n", zRoom->GetName().c_str(),
dList->GetRawDataIndex());
else
sourceOutput += StringHelper::Sprintf("extern Gfx DL_%06X[];\n", dList->GetRawDataIndex());
sourceOutput += StringHelper::Sprintf("extern Gfx %sDL_%06X[];\n", zRoom->GetName().c_str(),
dList->GetRawDataIndex());
for (ZDisplayList* otherDList : dList->otherDLists)
sourceOutput += GenDListExterns(otherDList);
for (pair<uint32_t, string> texEntry : dList->texDeclarations)
sourceOutput += StringHelper::Sprintf("extern u64 %sTex_%06X[];\n",
zRoom->GetName().c_str(), texEntry.first);
sourceOutput += dList->defines;
return sourceOutput;
}
string SetMesh::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
std::string SetMesh::GetBodySourceCode() const
{
string sourceOutput = "";
Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset);
sourceOutput += StringHelper::Sprintf(
"%s %i, &%s", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), data,
decl->varName.c_str());
return sourceOutput;
std::string list = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_MESH(%s)", list.c_str());
}
string SetMesh::GenerateExterns()
{
return "";
}
size_t SetMesh::GetRawDataSize()
size_t SetMesh::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize();
}
string SetMesh::GetCommandCName()
std::string SetMesh::GetCommandCName() const
{
return "SCmdMesh";
}
RoomCommand SetMesh::GetRoomCommand()
RoomCommand SetMesh::GetRoomCommand() const
{
return RoomCommand::SetMesh;
}
@@ -324,20 +119,36 @@ PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector<uint8_t>
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
room = nRoom;
zRoom = nRoom;
name = GetDefaultName(prefix.c_str(), rawDataIndex);
ParseRawData();
opaDList = MakeDlist(opa, prefix);
xluDList = MakeDlist(xlu, prefix);
}
void PolygonDlist::ParseRawData()
{
opa = BitConverter::ToUInt32BE(rawData, rawDataIndex);
xlu = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
switch (polyType)
{
case 2:
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
y = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
z = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
unk_06 = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
opa = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
xlu = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
break;
default:
opa = BitConverter::ToUInt32BE(rawData, rawDataIndex);
xlu = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
break;
}
}
void PolygonDlist::DeclareReferences(const std::string& prefix)
{
opaDList = MakeDlist(opa, prefix);
xluDList = MakeDlist(xlu, prefix);
}
ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, const std::string& prefix)
@@ -353,18 +164,26 @@ ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, const std::string& prefix)
rawData, dlistAddress,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
ZDisplayList* dlist = new ZDisplayList(rawData, dlistAddress, dlistLength, parent);
string dListStr = StringHelper::Sprintf("%sPolygonDlist_%06X", prefix.c_str(), dlistAddress);
dlist->SetName(dListStr);
dlist->scene = room->scene;
dlist->GetSourceOutputCode(prefix);
GenDListDeclarations(zRoom, parent, dlist);
return dlist;
}
size_t PolygonDlist::GetRawDataSize()
size_t PolygonDlist::GetRawDataSize() const
{
return 0x08;
switch (polyType)
{
case 2:
return 0x10;
default:
return 0x08;
}
}
void PolygonDlist::SetPolyType(uint8_t nPolyType)
{
polyType = nPolyType;
}
void PolygonDlist::DeclareVar(const std::string& prefix, const std::string& bodyStr)
@@ -381,55 +200,34 @@ void PolygonDlist::DeclareVar(const std::string& prefix, const std::string& body
std::string PolygonDlist::GetBodySourceCode(bool arrayElement)
{
std::string bodyStr = "";
std::string opaStr = "NULL";
std::string xluStr = "NULL";
std::string opaStr = parent->GetDeclarationPtrName(opa);
std::string xluStr = parent->GetDeclarationPtrName(xlu);
if (arrayElement)
{
bodyStr += " { \n ";
bodyStr += " { ";
}
else
{
bodyStr += "\n ";
}
if (polyType == 2)
{
bodyStr += StringHelper::Sprintf("{ %6i, %6i, %6i }, %6i, ", x, y, z, unk_06);
}
bodyStr += StringHelper::Sprintf("%s, ", opaStr.c_str());
bodyStr += StringHelper::Sprintf("%s", xluStr.c_str());
if (arrayElement)
{
bodyStr += " },";
}
else
{
bodyStr += "\n";
}
if (opa != 0)
{
Declaration* decl = parent->GetDeclaration(Seg2Filespace(opa, parent->baseAddress));
if (decl != nullptr)
{
opaStr = decl->varName;
}
else
{
opaStr = StringHelper::Sprintf("0x%08X", opa);
}
}
if (xlu != 0)
{
Declaration* decl = parent->GetDeclaration(Seg2Filespace(xlu, parent->baseAddress));
if (decl != nullptr)
{
xluStr = decl->varName;
}
else
{
xluStr = StringHelper::Sprintf("0x%08X", xlu);
}
}
bodyStr += StringHelper::Sprintf(" %s, \n", opaStr.c_str());
if (arrayElement)
{
bodyStr += " ";
}
bodyStr += StringHelper::Sprintf(" %s, \n", xluStr.c_str());
if (arrayElement)
{
bodyStr += " },";
}
return bodyStr;
}
@@ -455,7 +253,14 @@ std::string PolygonDlist::GetDefaultName(const std::string& prefix, uint32_t add
std::string PolygonDlist::GetSourceTypeName()
{
return "PolygonDlist";
switch (polyType)
{
case 2:
return "PolygonDlist2";
default:
return "PolygonDlist";
}
}
std::string PolygonDlist::GetName()
@@ -519,12 +324,12 @@ size_t BgImage::GetRawDataSize()
return 0x1C;
}
std::string BgImage::GetBodySourceCode(bool arrayElement)
std::string BgImage::GetBodySourceCode(bool arrayElement) const
{
std::string bodyStr = "";
std::string bodyStr = " ";
if (arrayElement)
{
bodyStr += " { \n ";
bodyStr += "{ \n ";
}
if (!isSubStruct)
@@ -538,21 +343,7 @@ std::string BgImage::GetBodySourceCode(bool arrayElement)
}
}
std::string backgroundName = "NULL";
if (source != 0)
{
uint32_t address = Seg2Filespace(source, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(address);
if (decl == nullptr)
{
backgroundName += StringHelper::Sprintf("0x%08X, ", source);
}
else
{
backgroundName = decl->varName;
}
}
std::string backgroundName = parent->GetDeclarationPtrName(source);
bodyStr += StringHelper::Sprintf("%s, ", backgroundName.c_str());
bodyStr += "\n ";
if (arrayElement)
@@ -590,6 +381,10 @@ std::string BgImage::GetBodySourceCode(bool arrayElement)
{
bodyStr += " \n }, ";
}
else
{
bodyStr += "\n";
}
return bodyStr;
}
@@ -609,29 +404,109 @@ std::string BgImage::GetName()
return name;
}
PolygonType1::PolygonType1(const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom)
/* PolygonType section */
PolygonTypeBase::PolygonTypeBase(ZFile* nParent, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZRoom* nRoom)
: rawData{nRawData}, rawDataIndex{nRawDataIndex}, parent{nParent}, zRoom{nRoom}
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
type = BitConverter::ToUInt8BE(rawData, rawDataIndex);
}
name = GetDefaultName(prefix.c_str(), rawDataIndex);
void PolygonTypeBase::DeclareVar(const std::string& prefix, const std::string& bodyStr)
{
std::string auxName = name;
if (name == "")
auxName = GetDefaultName(prefix);
ParseRawData();
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
GetSourceTypeName(), auxName, bodyStr);
}
void PolygonTypeBase::DeclareAndGenerateOutputCode(const std::string& prefix)
{
std::string bodyStr = GetBodySourceCode();
Declaration* decl = parent->GetDeclaration(rawDataIndex);
if (decl == nullptr)
{
DeclareVar(prefix, bodyStr);
}
else
{
decl->text = bodyStr;
}
}
std::string PolygonTypeBase::GetSourceTypeName() const
{
switch (type)
{
case 2:
return "PolygonType2";
case 1:
return "PolygonType1";
default:
return "PolygonType0";
}
}
std::string PolygonTypeBase::GetName() const
{
return name;
}
void PolygonTypeBase::SetName(const std::string& newName)
{
name = newName;
}
std::string PolygonTypeBase::GetDefaultName(const std::string& prefix) const
{
return StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), GetSourceTypeName().c_str(),
rawDataIndex);
}
PolygonType1::PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZRoom* nRoom)
: PolygonTypeBase(nParent, nRawData, nRawDataIndex, nRoom)
{
}
void PolygonType1::ParseRawData()
{
format = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01);
dlist = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
if (format == 2)
{
count = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08);
list = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C);
}
if (dlist != 0)
{
polyGfxList =
PolygonDlist(prefix, rawData, Seg2Filespace(dlist, parent->baseAddress), parent, nRoom);
PolygonDlist polyGfxList(zRoom->GetName(), rawData,
Seg2Filespace(dlist, parent->baseAddress), parent, zRoom);
polyGfxList.SetPolyType(type);
polyGfxList.ParseRawData();
polyGfxList.DeclareReferences(zRoom->GetName());
polyDLists.push_back(polyGfxList);
}
}
void PolygonType1::DeclareReferences(const std::string& prefix)
{
polyDLists.at(0).DeclareAndGenerateOutputCode();
uint32_t listAddress;
std::string bgImageArrayBody = "";
switch (format)
{
case 1:
single = BgImage(true, prefix, nRawData, nRawDataIndex + 0x08, parent);
single = BgImage(true, prefix, rawData, rawDataIndex + 0x08, parent);
break;
case 2:
@@ -668,20 +543,7 @@ PolygonType1::PolygonType1(const std::string& prefix, const std::vector<uint8_t>
}
}
void PolygonType1::ParseRawData()
{
type = BitConverter::ToUInt8BE(rawData, rawDataIndex);
format = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01);
dlist = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
if (format == 2)
{
count = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08);
list = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C);
}
}
size_t PolygonType1::GetRawDataSize()
size_t PolygonType1::GetRawDataSize() const
{
switch (format)
{
@@ -694,40 +556,14 @@ size_t PolygonType1::GetRawDataSize()
return 0x20;
}
void PolygonType1::DeclareVar(const std::string& prefix, const std::string& bodyStr)
{
std::string auxName = name;
if (name == "")
{
auxName = GetDefaultName(prefix, rawDataIndex);
}
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
GetSourceTypeName(), auxName, bodyStr);
}
std::string PolygonType1::GetBodySourceCode()
std::string PolygonType1::GetBodySourceCode() const
{
std::string bodyStr = "\n ";
bodyStr += "{ ";
bodyStr += StringHelper::Sprintf("%i, %i, ", type, format);
std::string dlistStr = "NULL";
if (dlist != 0)
{
uint32_t entryRecordAddress = Seg2Filespace(dlist, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(entryRecordAddress);
if (decl == nullptr)
{
polyGfxList.DeclareAndGenerateOutputCode();
dlistStr = "&" + polyGfxList.GetName();
}
else
{
dlistStr = "&" + decl->varName;
}
}
std::string dlistStr = parent->GetDeclarationPtrName(dlist);
bodyStr += StringHelper::Sprintf("%s, ", dlistStr.c_str());
bodyStr += "}, \n";
@@ -736,22 +572,10 @@ std::string PolygonType1::GetBodySourceCode()
switch (format)
{
case 1:
bodyStr += " " + single.GetBodySourceCode(false) + "\n";
bodyStr += single.GetBodySourceCode(false);
break;
case 2:
if (list != 0)
{
uint32_t listAddress = Seg2Filespace(list, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(listAddress);
if (decl != nullptr)
{
listStr = decl->varName;
}
else
{
listStr = StringHelper::Sprintf("0x%08X", list);
}
}
listStr = parent->GetDeclarationPtrName(list);
bodyStr += StringHelper::Sprintf(" %i, %s, \n", count, listStr.c_str());
break;
@@ -763,27 +587,7 @@ std::string PolygonType1::GetBodySourceCode()
return bodyStr;
}
void PolygonType1::DeclareAndGenerateOutputCode()
{
std::string bodyStr = GetBodySourceCode();
Declaration* decl = parent->GetDeclaration(rawDataIndex);
if (decl == nullptr)
{
DeclareVar("", bodyStr);
}
else
{
decl->text = bodyStr;
}
}
std::string PolygonType1::GetDefaultName(const std::string& prefix, uint32_t address)
{
return StringHelper::Sprintf("%sPolygonType1_%06X", prefix.c_str(), address);
}
std::string PolygonType1::GetSourceTypeName()
std::string PolygonType1::GetSourceTypeName() const
{
switch (format)
{
@@ -797,7 +601,71 @@ std::string PolygonType1::GetSourceTypeName()
// return "PolygonType1";
}
std::string PolygonType1::GetName()
PolygonType2::PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZRoom* nRoom)
: PolygonTypeBase(nParent, nRawData, nRawDataIndex, nRoom)
{
return name;
}
void PolygonType2::ParseRawData()
{
num = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01);
start = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
end = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08);
uint32_t currentPtr = GETSEGOFFSET(start);
for (size_t i = 0; i < num; i++)
{
PolygonDlist entry(zRoom->GetName(), rawData, currentPtr, parent, zRoom);
entry.SetPolyType(type);
entry.ParseRawData();
entry.DeclareReferences(zRoom->GetName());
polyDLists.push_back(entry);
currentPtr += entry.GetRawDataSize();
}
}
void PolygonType2::DeclareReferences(const std::string& prefix)
{
if (num > 0)
{
std::string declaration = "";
for (size_t i = 0; i < polyDLists.size(); i++)
{
declaration += polyDLists.at(i).GetBodySourceCode(true);
if (i + 1 < polyDLists.size())
declaration += "\n";
}
std::string polyDlistType = polyDLists.at(0).GetSourceTypeName();
std::string polyDListName = "";
polyDListName = StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), polyDlistType.c_str(),
GETSEGOFFSET(start));
parent->AddDeclarationArray(GETSEGOFFSET(start), DeclarationAlignment::Align4,
polyDLists.size() * polyDLists.at(0).GetRawDataSize(),
polyDlistType, polyDListName, polyDLists.size(), declaration);
}
parent->AddDeclaration(GETSEGOFFSET(end), DeclarationAlignment::Align4,
DeclarationPadding::Pad16, 4, "static s32", "terminatorMaybe",
"0x01000000");
}
std::string PolygonType2::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(start);
std::string body = StringHelper::Sprintf("\n %i, %i,\n", type, polyDLists.size());
body += StringHelper::Sprintf(" %s,\n", listName.c_str());
body +=
StringHelper::Sprintf(" %s + ARRAY_COUNTU(%s)\n", listName.c_str(), listName.c_str());
return body;
}
size_t PolygonType2::GetRawDataSize() const
{
return 0x0C;
}
+97 -76
View File
@@ -1,57 +1,22 @@
#pragma once
#include "../../ZDisplayList.h"
#include "../ZRoomCommand.h"
#include <memory>
#include "ZBackground.h"
class MeshHeaderBase
{
public:
int8_t headerType; // 0x00
};
class MeshEntry2
{
public:
int16_t playerXMax, playerZMax;
int16_t playerXMin, playerZMin;
int32_t opaqueDListAddr;
int32_t translucentDListAddr;
ZDisplayList* opaqueDList;
ZDisplayList* translucentDList;
};
class MeshHeader2 : public MeshHeaderBase
{
public:
std::vector<MeshEntry2*> entries;
uint32_t dListStart;
uint32_t dListEnd;
};
#include "ZDisplayList.h"
#include "ZRoom/ZRoomCommand.h"
class PolygonDlist
{
protected:
segptr_t opa = 0; // Gfx*
segptr_t xlu = 0; // Gfx*
std::vector<uint8_t> rawData;
uint32_t rawDataIndex;
ZFile* parent;
ZRoom* room;
std::string name;
void ParseRawData();
ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix);
public:
PolygonDlist() = default;
PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
ZFile* nParent, ZRoom* nRoom);
PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom);
size_t GetRawDataSize();
void ParseRawData();
void DeclareReferences(const std::string& prefix);
size_t GetRawDataSize() const;
void SetPolyType(uint8_t nPolyType);
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
@@ -62,8 +27,25 @@ public:
std::string GetSourceTypeName();
std::string GetName();
protected:
int16_t x, y, z; // polyType == 2
int16_t unk_06; // polyType == 2
segptr_t opa = 0; // Gfx*
segptr_t xlu = 0; // Gfx*
uint8_t polyType;
ZDisplayList* opaDList = nullptr; // Gfx*
ZDisplayList* xluDList = nullptr; // Gfx*
std::vector<uint8_t> rawData;
uint32_t rawDataIndex;
ZFile* parent;
ZRoom* zRoom;
std::string name;
ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix);
};
class BgImage
@@ -97,19 +79,51 @@ public:
BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent);
static size_t GetRawDataSize() ;
static size_t GetRawDataSize();
std::string GetBodySourceCode(bool arrayElement);
std::string GetBodySourceCode(bool arrayElement) const;
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
static std::string GetSourceTypeName();
std::string GetName();
};
class PolygonType1
class PolygonTypeBase
{
public:
PolygonTypeBase(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
ZRoom* nRoom);
virtual void ParseRawData() = 0;
virtual void DeclareReferences(const std::string& prefix) = 0;
virtual std::string GetBodySourceCode() const = 0;
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
void DeclareAndGenerateOutputCode(const std::string& prefix);
virtual std::string GetSourceTypeName() const;
std::string GetName() const;
void SetName(const std::string& newName);
virtual size_t GetRawDataSize() const = 0;
std::string GetDefaultName(const std::string& prefix) const;
protected:
uint8_t type;
std::vector<PolygonDlist> polyDLists;
std::vector<uint8_t> rawData;
uint32_t rawDataIndex;
ZFile* parent;
ZRoom* zRoom;
std::string name;
};
class PolygonType1 : public PolygonTypeBase
{
protected:
uint8_t format;
segptr_t dlist;
@@ -121,49 +135,56 @@ protected:
segptr_t list; // BgImage*
std::vector<BgImage> multiList;
std::vector<uint8_t> rawData;
uint32_t rawDataIndex;
ZFile* parent;
std::string name;
void ParseRawData();
public:
PolygonType1(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
ZFile* nParent, ZRoom* nRoom);
PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
ZRoom* nRoom);
size_t GetRawDataSize() ;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
std::string GetBodySourceCode() const override;
std::string GetBodySourceCode();
void DeclareAndGenerateOutputCode();
std::string GetSourceTypeName() const override;
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
std::string GetSourceTypeName();
std::string GetName();
size_t GetRawDataSize() const override;
};
PolygonDlist polyGfxList;
class PolygonType2 : public PolygonTypeBase
{
public:
PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
ZRoom* nRoom);
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
size_t GetRawDataSize() const override;
protected:
uint8_t num;
segptr_t start;
segptr_t end;
};
class SetMesh : public ZRoomCommand
{
public:
SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t segAddressOffset);
~SetMesh();
SetMesh(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GenerateExterns() override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
virtual size_t GetRawDataSize() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
std::string GetCommandCName() const override;
private:
MeshHeaderBase* meshHeader = nullptr;
uint32_t segmentOffset;
uint8_t data;
uint8_t meshHeaderType;
std::shared_ptr<PolygonTypeBase> polyType;
void GenDListDeclarations(std::vector<uint8_t> rawData, ZDisplayList* dList);
std::string GenDListExterns(ZDisplayList* dList);
};
@@ -1,101 +1,85 @@
#include "SetMinimapChests.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetMinimapChests::SetMinimapChests(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetMinimapChests::SetMinimapChests(ZFile* nParent) : ZRoomCommand(nParent)
{
int32_t numChests = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
}
void SetMinimapChests::ParseRawData()
{
ZRoomCommand::ParseRawData();
int numChests = cmdArg1;
int32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numChests; i++)
{
MinimapChest* chest = new MinimapChest(rawData, currentPtr);
MinimapChest chest(parent->GetRawData(), currentPtr);
chests.push_back(chest);
currentPtr += 10;
}
}
SetMinimapChests::~SetMinimapChests()
void SetMinimapChests::DeclareReferences(const std::string& prefix)
{
for (MinimapChest* chest : chests)
delete chest;
}
string SetMinimapChests::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
{
return std::string();
}
string SetMinimapChests::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
{
string sourceOutput = "";
sourceOutput +=
StringHelper::Sprintf("%s 0x%02X, (u32)%sMinimapChests0x%06X };",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
chests.size(), roomName.c_str(), segmentOffset);
std::string declaration = "";
size_t index = 0;
for (const auto& chest : chests)
{
string declaration = "";
declaration += StringHelper::Sprintf(" { %s },", chest.GetBodySourceCode().c_str());
size_t index = 0;
for (MinimapChest* chest : chests)
{
declaration += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },",
chest->unk0, chest->unk2, chest->unk4, chest->unk6,
chest->unk8);
if (index < chests.size() - 1)
declaration += "\n";
if (index < chests.size() - 1)
declaration += "\n";
index++;
}
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, chests.size() * 10,
"MinimapChest",
StringHelper::Sprintf("%sMinimapChests0x%06X", roomName.c_str(), segmentOffset),
chests.size(), declaration);
index++;
}
return sourceOutput;
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, chests.size() * 10, "MinimapChest",
StringHelper::Sprintf("%sMinimapChests0x%06X", prefix.c_str(), segmentOffset),
chests.size(), declaration);
}
string SetMinimapChests::GenerateExterns()
std::string SetMinimapChests::GetBodySourceCode() const
{
return StringHelper::Sprintf("extern MinimapChest %sMinimapChests0x%06X[%i];\n",
zRoom->GetName().c_str(), segmentOffset, chests.size());
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_MINIMAP_COMPASS_ICON_INFO(0x%02X, %s)", chests.size(),
listName.c_str());
}
string SetMinimapChests::GetCommandCName()
std::string SetMinimapChests::GetCommandCName() const
{
return "SCmdMinimapChests";
}
RoomCommand SetMinimapChests::GetRoomCommand()
RoomCommand SetMinimapChests::GetRoomCommand() const
{
return RoomCommand::SetMinimapChests;
}
size_t SetMinimapChests::GetRawDataSize()
size_t SetMinimapChests::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize() + (chests.size() * 10);
}
MinimapChest::MinimapChest(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
MinimapChest::MinimapChest(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
: unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)),
unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)),
unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)),
unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8))
{
}
}
std::string MinimapChest::GetBodySourceCode() const
{
return StringHelper::Sprintf("0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X", unk0, unk2, unk4, unk6,
unk8);
}
@@ -1,33 +1,36 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class MinimapChest
{
public:
MinimapChest(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetBodySourceCode() const;
protected:
uint16_t unk0;
uint16_t unk2;
uint16_t unk4;
uint16_t unk6;
uint16_t unk8;
MinimapChest(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
};
class SetMinimapChests : public ZRoomCommand
{
public:
SetMinimapChests(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetMinimapChests();
SetMinimapChests(ZFile* nParent);
std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
std::string GetCommandCName() override;
std::string GenerateExterns() override;
RoomCommand GetRoomCommand() override;
size_t GetRawDataSize() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
std::string GetCommandCName() const override;
private:
std::vector<MinimapChest*> chests;
uint32_t segmentOffset;
};
std::vector<MinimapChest> chests;
};
@@ -1,74 +1,42 @@
#include "SetMinimapList.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetMinimapList::SetMinimapList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetMinimapList::SetMinimapList(ZFile* nParent) : ZRoomCommand(nParent)
{
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
listSegmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, segmentOffset + 0));
unk4 = BitConverter::ToInt32BE(rawData, segmentOffset + 4);
}
minimaps = vector<MinimapEntry*>();
void SetMinimapList::ParseRawData()
{
ZRoomCommand::ParseRawData();
listSegmentOffset =
GETSEGOFFSET(BitConverter::ToInt32BE(parent->GetRawData(), segmentOffset + 0));
unk4 = BitConverter::ToInt32BE(parent->GetRawData(), segmentOffset + 4);
int32_t currentPtr = listSegmentOffset;
for (int32_t i = 0; i < zRoom->roomCount; i++)
{
MinimapEntry* entry = new MinimapEntry(rawData, currentPtr);
MinimapEntry entry(parent->GetRawData(), currentPtr);
minimaps.push_back(entry);
currentPtr += 10;
}
}
SetMinimapList::~SetMinimapList()
void SetMinimapList::DeclareReferences(const std::string& prefix)
{
for (MinimapEntry* entry : minimaps)
delete entry;
}
string SetMinimapList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
{
return StringHelper::Sprintf(
"%s 0x%02X, (u32)&%sMinimapList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), minimaps.size(),
zRoom->GetName().c_str(), segmentOffset);
}
string SetMinimapList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
{
string sourceOutput = "";
sourceOutput +=
StringHelper::Sprintf("%s 0, (u32)&%sMinimapList0x%06X };",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
roomName.c_str(), segmentOffset, unk4);
{
string declaration = StringHelper::Sprintf("(u32)%sMinimapEntryList0x%06X, 0x%08X",
roomName.c_str(), listSegmentOffset, unk4);
zRoom->parent->AddDeclaration(
segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::None, 8, "MinimapList",
StringHelper::Sprintf("%sMinimapList0x%06X", roomName.c_str(), segmentOffset),
declaration);
}
{
string declaration = "";
std::string declaration = "";
size_t index = 0;
for (MinimapEntry* entry : minimaps)
for (const auto& entry : minimaps)
{
declaration += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },",
entry->unk0, entry->unk2, entry->unk4, entry->unk6,
entry->unk8);
declaration += StringHelper::Sprintf(" { %s },", entry.GetBodySourceCode().c_str());
if (index < minimaps.size() - 1)
declaration += "\n";
@@ -76,42 +44,56 @@ string SetMinimapList::GenerateSourceCodePass2(string roomName, uint32_t baseAdd
index++;
}
zRoom->parent->AddDeclarationArray(
listSegmentOffset, DeclarationAlignment::None, DeclarationPadding::None,
minimaps.size() * 10, "MinimapEntry",
StringHelper::Sprintf("%sMinimapEntryList0x%06X", roomName.c_str(), listSegmentOffset),
parent->AddDeclarationArray(
listSegmentOffset, DeclarationAlignment::Align4, minimaps.size() * 10, "MinimapEntry",
StringHelper::Sprintf("%sMinimapEntryList0x%06X", prefix.c_str(), listSegmentOffset),
minimaps.size(), declaration);
}
return sourceOutput;
{
std::string listName = parent->GetDeclarationPtrName(listSegmentOffset);
std::string declaration = StringHelper::Sprintf("(u32)%s, 0x%08X", listName.c_str(), unk4);
parent->AddDeclaration(
segmentOffset, DeclarationAlignment::Align4, 8, "MinimapList",
StringHelper::Sprintf("%sMinimapList0x%06X", prefix.c_str(), segmentOffset),
declaration);
}
}
string SetMinimapList::GenerateExterns()
std::string SetMinimapList::GetBodySourceCode() const
{
return StringHelper::Sprintf("extern MinimapList %sMinimapList0x%06X;\n",
zRoom->GetName().c_str(), listSegmentOffset);
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_MINIMAP_INFO(%s)", listName.c_str());
}
string SetMinimapList::GetCommandCName()
std::string SetMinimapList::GetCommandCName() const
{
return "SCmdMinimapSettings";
}
RoomCommand SetMinimapList::GetRoomCommand()
RoomCommand SetMinimapList::GetRoomCommand() const
{
return RoomCommand::SetMinimapList;
}
size_t SetMinimapList::GetRawDataSize()
size_t SetMinimapList::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize() + (minimaps.size() * 10);
}
MinimapEntry::MinimapEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
MinimapEntry::MinimapEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
: unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)),
unk4(BitConverter::ToUInt16BE(rawData, rawDataIndex + 4)),
unk6(BitConverter::ToUInt16BE(rawData, rawDataIndex + 6)),
unk8(BitConverter::ToUInt16BE(rawData, rawDataIndex + 8))
{
}
}
std::string MinimapEntry::GetBodySourceCode() const
{
return StringHelper::Sprintf("0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X", unk0, unk2, unk4, unk6,
unk8);
}
+17 -14
View File
@@ -1,36 +1,39 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class MinimapEntry
{
public:
MinimapEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
std::string GetBodySourceCode() const;
protected:
uint16_t unk0;
uint16_t unk2;
uint16_t unk4;
uint16_t unk6;
uint16_t unk8;
MinimapEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
};
class SetMinimapList : public ZRoomCommand
{
public:
SetMinimapList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetMinimapList();
SetMinimapList(ZFile* nParent);
std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
std::string GetCommandCName() override;
std::string GenerateExterns() override;
RoomCommand GetRoomCommand() override;
size_t GetRawDataSize() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
std::string GetCommandCName() const override;
private:
std::vector<MinimapEntry*> minimaps;
uint32_t segmentOffset;
std::vector<MinimapEntry> minimaps;
uint32_t listSegmentOffset;
uint32_t unk4;
};
};
@@ -1,77 +1,73 @@
#include "SetObjectList.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZNames.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZNames.h"
#include "ZRoom/ZRoom.h"
SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetObjectList::SetObjectList(ZFile* nParent) : ZRoomCommand(nParent)
{
objects = vector<uint16_t>();
uint8_t objectCnt = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
}
void SetObjectList::ParseRawData()
{
ZRoomCommand::ParseRawData();
uint8_t objectCnt = parent->GetRawData().at(rawDataIndex + 1);
uint32_t currentPtr = segmentOffset;
for (uint8_t i = 0; i < objectCnt; i++)
{
uint16_t objectIndex = BitConverter::ToInt16BE(rawData, currentPtr);
uint16_t objectIndex = BitConverter::ToInt16BE(parent->GetRawData(), currentPtr);
objects.push_back(objectIndex);
currentPtr += 2;
}
if (segmentOffset != 0)
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
parent->AddDeclarationPlaceholder(segmentOffset);
}
string SetObjectList::GenerateExterns()
void SetObjectList::DeclareReferences(const std::string& prefix)
{
return StringHelper::Sprintf("s16 %sObjectList0x%06X[];\n", zRoom->GetName().c_str(),
segmentOffset);
}
string SetObjectList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
{
string sourceOutput = "";
sourceOutput +=
StringHelper::Sprintf("%s 0x%02X, (u32)%sObjectList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
objects.size(), zRoom->GetName().c_str(), segmentOffset);
string declaration = "";
for (size_t i = 0; i < objects.size(); i++)
if (!objects.empty())
{
uint16_t objectIndex = objects[i];
declaration += StringHelper::Sprintf(" %s,", ZNames::GetObjectName(objectIndex).c_str());
std::string declaration = "";
if (i < objects.size() - 1)
declaration += "\n";
for (size_t i = 0; i < objects.size(); i++)
{
uint16_t objectIndex = objects[i];
declaration +=
StringHelper::Sprintf(" %s,", ZNames::GetObjectName(objectIndex).c_str());
if (i < objects.size() - 1)
declaration += "\n";
}
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, objects.size() * 2, "s16",
StringHelper::Sprintf("%sObjectList_%06X", prefix.c_str(), segmentOffset),
objects.size(), declaration);
}
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, objects.size() * 2, "s16",
StringHelper::Sprintf("%sObjectList0x%06X", zRoom->GetName().c_str(), segmentOffset),
objects.size(), declaration);
return sourceOutput;
}
size_t SetObjectList::GetRawDataSize()
std::string SetObjectList::GetBodySourceCode() const
{
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_OBJECT_LIST(%i, %s)", objects.size(), listName.c_str());
}
size_t SetObjectList::GetRawDataSize() const
{
return ZRoomCommand::GetRawDataSize() + (objects.size() * 2);
}
string SetObjectList::GetCommandCName()
std::string SetObjectList::GetCommandCName() const
{
return "SCmdObjectList";
}
RoomCommand SetObjectList::GetRoomCommand()
RoomCommand SetObjectList::GetRoomCommand() const
{
return RoomCommand::SetObjectList;
}
}
+11 -9
View File
@@ -1,19 +1,21 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class SetObjectList : public ZRoomCommand
{
public:
SetObjectList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetObjectList(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
virtual size_t GetRawDataSize() override;
virtual std::string GenerateExterns() override;
void ParseRawData() override;
void DeclareReferences(const std::string& prefix);
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
private:
std::vector<uint16_t> objects;
uint32_t segmentOffset;
};
};
+30 -213
View File
@@ -1,241 +1,58 @@
#include "SetPathways.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
REGISTER_ZFILENODE(Path, ZSetPathways);
using namespace std;
ZSetPathways::ZSetPathways(ZFile* nParent) : ZResource(nParent)
SetPathways::SetPathways(ZFile* nParent) : ZRoomCommand(nParent), pathwayList(nParent)
{
}
ZSetPathways::ZSetPathways(ZRoom* nZRoom, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
bool nIsFromHeader)
: ZResource(nZRoom->parent), ZRoomCommand(nZRoom, nRawData, nRawDataIndex)
void SetPathways::DeclareReferences(const std::string& prefix)
{
rawData = nRawData;
rawDataIndex = nRawDataIndex;
isFromHeader = nIsFromHeader;
}
ZSetPathways::~ZSetPathways()
{
delete pathwayList;
}
void ZSetPathways::DeclareVar(const std::string& prefix, const std::string& bodyStr)
{
parent->AddDeclaration(cmdAddress, DeclarationAlignment::None, 8,
StringHelper::Sprintf("static %s", GetCommandCName().c_str()),
StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(),
commandSet & 0x00FFFFFF, cmdIndex, cmdID),
StringHelper::Sprintf("%s // 0x%04X", bodyStr.c_str(), cmdAddress));
}
string ZSetPathways::GetSourceOutputCode(const std::string& prefix)
{
if (pathwayList != nullptr)
pathwayList->GetSourceOutputCode(parent->GetName());
return "";
}
void ZSetPathways::ParseRawData()
{
if (isFromHeader)
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
else
segmentOffset = rawDataIndex;
if (segmentOffset != 0)
parent->AddDeclarationPlaceholder(segmentOffset);
int32_t numPaths = (Globals::Instance->game != ZGame::MM_RETAIL) ?
1 :
zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 8;
pathwayList = new PathwayList(parent, rawData, segmentOffset, numPaths);
}
string ZSetPathways::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetPathways::ParseRawDataLate()
{
ParseRawData();
return "";
if (Globals::Instance->game == ZGame::MM_RETAIL)
{
auto numPaths = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 8;
pathwayList.SetNumPaths(numPaths);
}
pathwayList.SetRawDataIndex(segmentOffset);
pathwayList.ParseRawData();
}
string ZSetPathways::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
void SetPathways::DeclareReferencesLate(const std::string& prefix)
{
string sourceOutput = "";
sourceOutput += StringHelper::Sprintf("\n\t%s 0, (u32)%sPathway0x%06X\n};",
ZRoomCommand::GenerateSourceCodePass1("", 0).c_str(),
parent->GetName().c_str(), segmentOffset);
if (pathwayList != nullptr)
pathwayList->GetSourceOutputCode(parent->GetName());
return sourceOutput;
pathwayList.SetName(StringHelper::Sprintf("%sPathway_%06X", prefix.c_str(), segmentOffset));
pathwayList.DeclareReferences(prefix);
pathwayList.GetSourceOutputCode(prefix);
}
size_t ZSetPathways::GetRawDataSize()
std::string SetPathways::GetBodySourceCode() const
{
size_t size = 0;
if (pathwayList != nullptr)
size += pathwayList->GetRawDataSize();
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_PATH_LIST(%s)", listName.c_str());
}
size_t SetPathways::GetRawDataSize() const
{
int32_t size = pathwayList.GetRawDataSize();
return ZRoomCommand::GetRawDataSize() + size;
}
string ZSetPathways::GenerateExterns()
{
if (pathwayList != nullptr)
return pathwayList->GenerateExterns(parent->GetName());
return "";
}
string ZSetPathways::GetCommandCName()
std::string SetPathways::GetCommandCName() const
{
return "SCmdPathList";
}
RoomCommand ZSetPathways::GetRoomCommand()
RoomCommand SetPathways::GetRoomCommand() const
{
return RoomCommand::SetPathways;
}
PathwayEntry::PathwayEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: numPoints(rawData[rawDataIndex + 0]), unk1(rawData[rawDataIndex + 1]),
unk2(BitConverter::ToInt16BE(rawData, rawDataIndex + 2)),
listSegmentOffset(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)))
{
uint32_t currentPtr = listSegmentOffset;
uint8_t* data = rawData.data();
for (int32_t i = 0; i < numPoints; i++)
{
x = BitConverter::ToInt16BE(data, currentPtr + 0);
y = BitConverter::ToInt16BE(data, currentPtr + 2);
z = BitConverter::ToInt16BE(data, currentPtr + 4);
Vec3s point = Vec3s(x, y, z);
points.push_back(point);
currentPtr += 6;
}
if (numPoints == 0) // Hack for SharpOcarina
{
for (int32_t i = 0; i < 3; i++)
{
Vec3s point = Vec3s(0, 0, 0);
points.push_back(point);
}
}
}
PathwayList::PathwayList(ZFile* nParent, std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t length)
{
parent = nParent;
_rawDataIndex = rawDataIndex;
uint32_t currentPtr = rawDataIndex;
for (int32_t pathIndex = 0; pathIndex < length; pathIndex++)
{
PathwayEntry* path = new PathwayEntry(rawData, currentPtr);
currentPtr += 8;
if (path->listSegmentOffset == 0)
break;
pathways.push_back(path);
}
}
PathwayList::~PathwayList()
{
for (PathwayEntry* path : pathways)
delete path;
}
void PathwayList::GetSourceOutputCode(const std::string& prefix)
{
{
string declaration = "";
size_t index = 0;
for (PathwayEntry* entry : pathways)
{
if (Globals::Instance->game == ZGame::MM_RETAIL)
declaration += StringHelper::Sprintf(" { %i, %i, %i, (u32)%sPathwayList0x%06X },",
entry->numPoints, entry->unk1, entry->unk2,
prefix.c_str(), entry->listSegmentOffset);
else
declaration +=
StringHelper::Sprintf(" { %i, (u32)%sPathwayList0x%06X },", entry->numPoints,
prefix.c_str(), entry->listSegmentOffset);
if (index < pathways.size() - 1)
declaration += "\n";
index++;
}
parent->AddDeclarationArray(
_rawDataIndex, DeclarationAlignment::None, DeclarationPadding::None,
pathways.size() * 8, "Path",
StringHelper::Sprintf("%sPathway0x%06X", prefix.c_str(), _rawDataIndex),
pathways.size(), declaration);
}
for (PathwayEntry* entry : pathways)
{
string declaration = "";
size_t index = 0;
for (Vec3s& point : entry->points)
{
declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", point.x, point.y,
point.z, entry->listSegmentOffset + (index * 6));
if (index < entry->points.size() - 1)
declaration += "\n";
index++;
}
parent->AddDeclarationArray(
entry->listSegmentOffset, DeclarationAlignment::Align4, DeclarationPadding::Pad4,
entry->points.size() * 6, "Vec3s",
StringHelper::Sprintf("%sPathwayList0x%06X", prefix.c_str(), entry->listSegmentOffset),
entry->points.size(), declaration);
}
}
size_t PathwayList::GetRawDataSize()
{
size_t pointsSize = 0;
for (PathwayEntry* entry : pathways)
{
pointsSize += entry->points.size() * 6;
}
return pathways.size() * 8 + pointsSize;
}
string PathwayList::GenerateExterns(const std::string& prefix)
{
string declaration = "";
for (PathwayEntry* entry : pathways)
{
declaration += StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n",
prefix.c_str(), entry->listSegmentOffset);
}
return declaration;
}
+15 -49
View File
@@ -1,62 +1,28 @@
#pragma once
#include "../../Vec3s.h"
#include "../ZRoomCommand.h"
#include "Vec3s.h"
#include "ZPath.h"
#include "ZResource.h"
#include "ZRoom/ZRoomCommand.h"
class PathwayEntry
class SetPathways : public ZRoomCommand
{
public:
int16_t x, y, z;
SetPathways(ZFile* nParent);
PathwayEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
void DeclareReferences(const std::string& prefix) override;
int32_t numPoints;
int8_t unk1; // (MM Only)
int16_t unk2; // (MM Only)
uint32_t listSegmentOffset;
std::vector<Vec3s> points;
};
struct PathwayList
{
public:
PathwayList(ZFile* nParent, std::vector<uint8_t> rawData, uint32_t rawDataIndex, int32_t length);
~PathwayList();
void GetSourceOutputCode(const std::string& prefix) ;
size_t GetRawDataSize();
std::string GenerateExterns(const std::string& prefix);
private:
ZFile* parent;
std::vector<PathwayEntry*> pathways;
std::vector<uint8_t> _rawData;
uint32_t _rawDataIndex;
};
class ZSetPathways : public ZResource, public ZRoomCommand
{
public:
ZSetPathways(ZFile* nParent);
ZSetPathways(ZRoom* nZRoom, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
bool nIsFromHeader);
~ZSetPathways();
void ParseRawData() override;
void ParseRawDataLate() override;
void DeclareReferencesLate(const std::string& prefix) override;
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
RoomCommand GetRoomCommand() override;
size_t GetRawDataSize() override;
std::string GetCommandCName() override;
std::string GenerateExterns() override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
size_t GetRawDataSize() const override;
std::string GetCommandCName() const override;
private:
uint32_t segmentOffset;
PathwayList* pathwayList;
bool isFromHeader = false;
};
ZPath pathwayList;
};
@@ -1,30 +1,49 @@
#include "SetRoomBehavior.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
using namespace std;
SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetRoomBehavior::SetRoomBehavior(ZFile* nParent) : ZRoomCommand(nParent)
{
gameplayFlags = rawData[rawDataIndex + 0x01];
gameplayFlags2 = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x04);
}
string SetRoomBehavior::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetRoomBehavior::ParseRawData()
{
return StringHelper::Sprintf(
"%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
gameplayFlags, gameplayFlags2);
;
ZRoomCommand::ParseRawData();
gameplayFlags = cmdArg1;
gameplayFlags2 = BitConverter::ToInt32BE(parent->GetRawData(), rawDataIndex + 0x04);
currRoomUnk2 = gameplayFlags2 & 0xFF;
currRoomUnk5 = showInvisActors = (gameplayFlags2 >> 8) & 1;
msgCtxUnk = (gameplayFlags2 >> 10) & 1;
enablePosLights = (gameplayFlags2 >> 11) & 1;
kankyoContextUnkE2 = (gameplayFlags2 >> 12) & 1;
}
string SetRoomBehavior::GetCommandCName()
std::string SetRoomBehavior::GetBodySourceCode() const
{
if (Globals::Instance->game == ZGame::MM_RETAIL)
{
std::string enableLights = StringHelper::BoolStr(enablePosLights);
return StringHelper::Sprintf("SCENE_CMD_ROOM_BEHAVIOR(0x%02X, 0x%02X, %i, %i, %s, %i)",
gameplayFlags, currRoomUnk2, currRoomUnk5, msgCtxUnk,
enableLights.c_str(), kankyoContextUnkE2);
}
std::string showInvisible = StringHelper::BoolStr(showInvisActors);
std::string disableWarps = StringHelper::BoolStr(msgCtxUnk);
return StringHelper::Sprintf("SCENE_CMD_ROOM_BEHAVIOR(0x%02X, 0x%02X, %s, %s)", gameplayFlags,
currRoomUnk2, showInvisible.c_str(), disableWarps.c_str());
}
std::string SetRoomBehavior::GetCommandCName() const
{
return "SCmdRoomBehavior";
}
RoomCommand SetRoomBehavior::GetRoomCommand()
RoomCommand SetRoomBehavior::GetRoomCommand() const
{
return RoomCommand::SetRoomBehavior;
}
}
@@ -1,17 +1,30 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class SetRoomBehavior : public ZRoomCommand
{
public:
SetRoomBehavior(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetRoomBehavior(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void ParseRawData() override;
private:
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
protected:
uint8_t gameplayFlags;
uint32_t gameplayFlags2;
};
uint8_t currRoomUnk2;
uint8_t showInvisActors;
uint8_t currRoomUnk5;
uint8_t msgCtxUnk;
uint8_t enablePosLights;
uint8_t kankyoContextUnkE2;
};
+31 -50
View File
@@ -1,25 +1,25 @@
#include "SetRoomList.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetRoomList::SetRoomList(ZFile* nParent) : ZRoomCommand(nParent)
{
int32_t numRooms = rawData[rawDataIndex + 1];
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
}
rooms = vector<RoomEntry*>();
void SetRoomList::ParseRawData()
{
ZRoomCommand::ParseRawData();
int numRooms = cmdArg1;
int32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numRooms; i++)
{
RoomEntry* entry = new RoomEntry(rawData, currentPtr);
RoomEntry entry(parent->GetRawData(), currentPtr);
rooms.push_back(entry);
currentPtr += 8;
@@ -28,44 +28,32 @@ SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t r
zRoom->roomCount = numRooms;
}
SetRoomList::~SetRoomList()
void SetRoomList::DeclareReferences(const std::string& prefix)
{
for (RoomEntry* entry : rooms)
delete entry;
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, rooms.size() * 8, "RomFile",
StringHelper::Sprintf("%sRoomList0x%06X", prefix.c_str(), segmentOffset), 0, "");
}
string SetRoomList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
std::string SetRoomList::GetBodySourceCode() const
{
return StringHelper::Sprintf(
"%s 0x%02X, (u32)&%sRoomList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), rooms.size(),
zRoom->GetName().c_str(), segmentOffset);
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_ROOM_LIST(%i, %s)", rooms.size(), listName.c_str());
}
string SetRoomList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
{
return "";
}
string SetRoomList::GenerateExterns()
{
return StringHelper::Sprintf("extern RomFile %sRoomList0x%06X[];\n", zRoom->GetName().c_str(),
segmentOffset);
}
string SetRoomList::GetCommandCName()
std::string SetRoomList::GetCommandCName() const
{
return "SCmdRoomList";
}
RoomCommand SetRoomList::GetRoomCommand()
RoomCommand SetRoomList::GetRoomCommand() const
{
return RoomCommand::SetRoomList;
}
std::string SetRoomList::PreGenSourceFiles()
void SetRoomList::PreGenSourceFiles()
{
string declaration = "";
std::string declaration = "";
for (ZFile* file : Globals::Instance->files)
{
@@ -73,35 +61,28 @@ std::string SetRoomList::PreGenSourceFiles()
{
if (res->GetResourceType() == ZResourceType::Room && res != zRoom)
{
string roomName = res->GetName();
declaration += StringHelper::Sprintf(
" { (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n", roomName.c_str(),
roomName.c_str());
std::string roomName = res->GetName();
declaration +=
StringHelper::Sprintf("\t{ (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n",
roomName.c_str(), roomName.c_str());
}
}
}
zRoom->parent->AddDeclarationArray(
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, rooms.size() * 8, "RomFile",
StringHelper::Sprintf("%sRoomList0x%06X", zRoom->GetName().c_str(), segmentOffset), 0,
declaration);
return std::string();
}
std::string SetRoomList::Save()
{
return std::string();
}
RoomEntry::RoomEntry(int32_t nVAS, int32_t nVAE)
RoomEntry::RoomEntry(uint32_t nVAS, uint32_t nVAE)
{
virtualAddressStart = nVAS;
virtualAddressEnd = nVAE;
}
RoomEntry::RoomEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex)
RoomEntry::RoomEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
: RoomEntry(BitConverter::ToInt32BE(rawData, rawDataIndex + 0),
BitConverter::ToInt32BE(rawData, rawDataIndex + 4))
{
}
}
+16 -16
View File
@@ -1,32 +1,32 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class RoomEntry
{
public:
RoomEntry(uint32_t nVAS, uint32_t nVAE);
RoomEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
protected:
int32_t virtualAddressStart;
int32_t virtualAddressEnd;
RoomEntry(int32_t nVAS, int32_t nVAE);
RoomEntry(std::vector<uint8_t> rawData, uint32_t rawDataIndex);
};
class SetRoomList : public ZRoomCommand
{
public:
SetRoomList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetRoomList();
SetRoomList(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual std::string GenerateExterns() override;
virtual RoomCommand GetRoomCommand() override;
virtual std::string PreGenSourceFiles() override;
virtual std::string Save() override;
void ParseRawData() override;
virtual void DeclareReferences(const std::string& prefix);
std::string GetBodySourceCode() const override;
void PreGenSourceFiles() override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
private:
std::vector<RoomEntry*> rooms;
uint32_t segmentOffset;
};
std::vector<RoomEntry> rooms;
};
@@ -1,30 +1,32 @@
#include "SetSkyboxModifier.h"
#include "../../StringHelper.h"
using namespace std;
#include "StringHelper.h"
SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetSkyboxModifier::SetSkyboxModifier(ZFile* nParent) : ZRoomCommand(nParent)
{
disableSky = rawData[rawDataIndex + 0x04];
disableSunMoon = rawData[rawDataIndex + 0x05];
}
string SetSkyboxModifier::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetSkyboxModifier::ParseRawData()
{
return StringHelper::Sprintf(
"%s 0, 0, 0, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), disableSky,
disableSunMoon);
;
ZRoomCommand::ParseRawData();
disableSky = parent->GetRawData().at(rawDataIndex + 0x04);
disableSunMoon = parent->GetRawData().at(rawDataIndex + 0x05);
}
string SetSkyboxModifier::GetCommandCName()
std::string SetSkyboxModifier::GetBodySourceCode() const
{
std::string sky = StringHelper::BoolStr(disableSky);
std::string soonMoon = StringHelper::BoolStr(disableSunMoon);
return StringHelper::Sprintf("SCENE_CMD_SKYBOX_DISABLES(%s, %s)", sky.c_str(),
soonMoon.c_str());
}
std::string SetSkyboxModifier::GetCommandCName() const
{
return "SCmdSkyboxDisables";
}
RoomCommand SetSkyboxModifier::GetRoomCommand()
RoomCommand SetSkyboxModifier::GetRoomCommand() const
{
return RoomCommand::SetSkyboxModifier;
}
}
@@ -1,17 +1,20 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class SetSkyboxModifier : public ZRoomCommand
{
public:
SetSkyboxModifier(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetSkyboxModifier(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void ParseRawData() override;
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
private:
uint8_t disableSky;
uint8_t disableSunMoon;
};
};
@@ -1,32 +1,36 @@
#include "SetSkyboxSettings.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "Globals.h"
#include "StringHelper.h"
using namespace std;
SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetSkyboxSettings::SetSkyboxSettings(ZFile* nParent) : ZRoomCommand(nParent)
{
unk1 = rawData[rawDataIndex + 0x01];
skyboxNumber = rawData[rawDataIndex + 0x04];
cloudsType = rawData[rawDataIndex + 0x05];
lightingSettingsControl = rawData[rawDataIndex + 0x06];
}
string SetSkyboxSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetSkyboxSettings::ParseRawData()
{
return StringHelper::Sprintf(
"%s 0x%02X, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), unk1, skyboxNumber,
cloudsType, lightingSettingsControl);
ZRoomCommand::ParseRawData();
unk1 = cmdArg1;
skyboxNumber = parent->GetRawData().at(rawDataIndex + 0x04);
cloudsType = parent->GetRawData().at(rawDataIndex + 0x05);
isIndoors = parent->GetRawData().at(rawDataIndex + 0x06);
}
string SetSkyboxSettings::GetCommandCName()
std::string SetSkyboxSettings::GetBodySourceCode() const
{
std::string indoors = StringHelper::BoolStr(isIndoors);
if (Globals::Instance->game == ZGame::MM_RETAIL)
return StringHelper::Sprintf("SCENE_CMD_SKYBOX_SETTINGS(0x%02X, %i, %i, %s)", unk1,
skyboxNumber, cloudsType, indoors.c_str());
return StringHelper::Sprintf("SCENE_CMD_SKYBOX_SETTINGS(%i, %i, %s)", skyboxNumber, cloudsType,
indoors.c_str());
}
std::string SetSkyboxSettings::GetCommandCName() const
{
return "SCmdSkyboxSettings";
}
RoomCommand SetSkyboxSettings::GetRoomCommand()
RoomCommand SetSkyboxSettings::GetRoomCommand() const
{
return RoomCommand::SetSkyboxSettings;
}
}
@@ -1,19 +1,22 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class SetSkyboxSettings : public ZRoomCommand
{
public:
SetSkyboxSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetSkyboxSettings(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void ParseRawData() override;
std::string GetBodySourceCode() const override;
std::string GetCommandCName() const override;
RoomCommand GetRoomCommand() const override;
private:
uint8_t unk1; // (MM Only)
uint8_t skyboxNumber;
uint8_t cloudsType;
uint8_t lightingSettingsControl;
};
uint8_t isIndoors;
};
@@ -1,30 +1,30 @@
#include "SetSoundSettings.h"
#include "../../StringHelper.h"
#include "StringHelper.h"
using namespace std;
SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetSoundSettings::SetSoundSettings(ZFile* nParent) : ZRoomCommand(nParent)
{
reverb = rawData[rawDataIndex + 0x01];
nightTimeSFX = rawData[rawDataIndex + 0x06];
musicSequence = rawData[rawDataIndex + 0x07];
}
string SetSoundSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetSoundSettings::ParseRawData()
{
return StringHelper::Sprintf(
"%s 0x%02X, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), reverb, nightTimeSFX,
musicSequence);
ZRoomCommand::ParseRawData();
reverb = cmdArg1;
nightTimeSFX = parent->GetRawData().at(rawDataIndex + 0x06);
musicSequence = parent->GetRawData().at(rawDataIndex + 0x07);
}
string SetSoundSettings::GetCommandCName()
std::string SetSoundSettings::GetBodySourceCode() const
{
return StringHelper::Sprintf("SCENE_CMD_SOUND_SETTINGS(%i, %i, %i)", reverb, nightTimeSFX,
musicSequence);
}
std::string SetSoundSettings::GetCommandCName() const
{
return "SCmdSoundSettings";
}
RoomCommand SetSoundSettings::GetRoomCommand()
RoomCommand SetSoundSettings::GetRoomCommand() const
{
return RoomCommand::SetSoundSettings;
}
}
@@ -1,18 +1,21 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class SetSoundSettings : public ZRoomCommand
{
public:
SetSoundSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetSoundSettings(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void ParseRawData() override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
private:
uint8_t reverb;
uint8_t nightTimeSFX;
uint8_t musicSequence;
};
};
@@ -1,29 +1,30 @@
#include "SetSpecialObjects.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "BitConverter.h"
#include "StringHelper.h"
using namespace std;
SetSpecialObjects::SetSpecialObjects(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetSpecialObjects::SetSpecialObjects(ZFile* nParent) : ZRoomCommand(nParent)
{
elfMessage = rawData[rawDataIndex + 0x01];
globalObject = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
}
string SetSpecialObjects::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetSpecialObjects::ParseRawData()
{
return StringHelper::Sprintf(
"%s 0x%02X, 0x%04X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
elfMessage, globalObject);
ZRoomCommand::ParseRawData();
elfMessage = cmdArg1;
globalObject = BitConverter::ToUInt16BE(parent->GetRawData(), rawDataIndex + 0x06);
}
string SetSpecialObjects::GetCommandCName()
std::string SetSpecialObjects::GetBodySourceCode() const
{
return StringHelper::Sprintf("SCENE_CMD_SPECIAL_FILES(0x%02X, 0x%04X)", elfMessage,
globalObject);
}
std::string SetSpecialObjects::GetCommandCName() const
{
return "SCmdSpecialFiles";
}
RoomCommand SetSpecialObjects::GetRoomCommand()
RoomCommand SetSpecialObjects::GetRoomCommand() const
{
return RoomCommand::SetSpecialObjects;
}
}
@@ -1,17 +1,20 @@
#pragma once
#include "../ZRoomCommand.h"
#include "ZRoom/ZRoomCommand.h"
class SetSpecialObjects : public ZRoomCommand
{
public:
SetSpecialObjects(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
SetSpecialObjects(ZFile* nParent);
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual RoomCommand GetRoomCommand() override;
void ParseRawData() override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
private:
uint8_t elfMessage;
uint16_t globalObject;
};
};
@@ -1,84 +1,65 @@
#include "SetStartPositionList.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZNames.h"
#include "../ZRoom.h"
using namespace std;
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZNames.h"
#include "ZRoom/ZRoom.h"
SetStartPositionList::SetStartPositionList(ZRoom* nZRoom, std::vector<uint8_t> rawData,
uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetStartPositionList::SetStartPositionList(ZFile* nParent) : ZRoomCommand(nParent)
{
uint8_t numActors = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
}
if (segmentOffset != 0)
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
actors = vector<ActorSpawnEntry*>();
void SetStartPositionList::ParseRawData()
{
ZRoomCommand::ParseRawData();
uint8_t numActors = cmdArg1;
uint32_t currentPtr = segmentOffset;
for (int32_t i = 0; i < numActors; i++)
{
actors.push_back(new ActorSpawnEntry(rawData, currentPtr));
actors.push_back(ActorSpawnEntry(parent->GetRawData(), currentPtr));
currentPtr += 16;
}
}
SetStartPositionList::~SetStartPositionList()
void SetStartPositionList::DeclareReferences(const std::string& prefix)
{
for (ActorSpawnEntry* entry : actors)
delete entry;
}
string SetStartPositionList::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
{
string sourceOutput = "";
sourceOutput +=
StringHelper::Sprintf("%s 0x%02X, (u32)&%sStartPositionList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
actors.size(), zRoom->GetName().c_str(), segmentOffset);
string declaration = "";
for (ActorSpawnEntry* entry : actors)
if (!actors.empty())
{
declaration += StringHelper::Sprintf(" { %s, %i, %i, %i, %i, %i, %i, 0x%04X },\n",
ZNames::GetActorName(entry->actorNum).c_str(),
entry->posX, entry->posY, entry->posZ, entry->rotX,
entry->rotY, entry->rotZ, entry->initVar);
std::string declaration = "";
size_t index = 0;
for (const auto& entry : actors)
{
declaration += StringHelper::Sprintf(" { %s },", entry.GetBodySourceCode().c_str());
if (index + 1 < actors.size())
declaration += "\n";
index++;
}
parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::Align4, actors.size() * 16, "ActorEntry",
StringHelper::Sprintf("%sStartPositionList0x%06X", prefix.c_str(), segmentOffset), 0,
declaration);
}
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, actors.size() * 16, "ActorEntry",
StringHelper::Sprintf("%sStartPositionList0x%06X", zRoom->GetName().c_str(), segmentOffset),
0, declaration);
return sourceOutput;
}
string SetStartPositionList::GenerateSourceCodePass2(string roomName, uint32_t baseAddress)
std::string SetStartPositionList::GetBodySourceCode() const
{
return "";
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
return StringHelper::Sprintf("SCENE_CMD_SPAWN_LIST(%i, %s)", actors.size(), listName.c_str());
}
string SetStartPositionList::GenerateExterns()
{
return StringHelper::Sprintf("extern ActorEntry %sStartPositionList0x%06X[];\n",
zRoom->GetName().c_str(), segmentOffset);
}
string SetStartPositionList::GetCommandCName()
std::string SetStartPositionList::GetCommandCName() const
{
return "SCmdSpawnList";
}
RoomCommand SetStartPositionList::GetRoomCommand()
RoomCommand SetStartPositionList::GetRoomCommand() const
{
return RoomCommand::SetStartPositionList;
}
}
@@ -1,22 +1,21 @@
#pragma once
#include "../ZRoomCommand.h"
#include "SetActorList.h"
#include "ZRoom/ZRoomCommand.h"
class SetStartPositionList : public ZRoomCommand
{
public:
std::vector<ActorSpawnEntry*> actors;
SetStartPositionList(ZFile* nParent);
SetStartPositionList(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex);
~SetStartPositionList();
void ParseRawData() override;
void DeclareReferences(const std::string& prefix) override;
virtual std::string GenerateSourceCodePass1(std::string roomName, uint32_t baseAddress) override;
virtual std::string GenerateSourceCodePass2(std::string roomName, uint32_t baseAddress) override;
virtual std::string GetCommandCName() override;
virtual std::string GenerateExterns() override;
virtual RoomCommand GetRoomCommand() override;
std::string GetBodySourceCode() const override;
RoomCommand GetRoomCommand() const override;
std::string GetCommandCName() const override;
private:
uint32_t segmentOffset;
};
std::vector<ActorSpawnEntry> actors;
};
@@ -1,30 +1,30 @@
#include "SetTimeSettings.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "BitConverter.h"
#include "StringHelper.h"
using namespace std;
SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, uint32_t rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetTimeSettings::SetTimeSettings(ZFile* nParent) : ZRoomCommand(nParent)
{
hour = rawData[rawDataIndex + 4];
min = rawData[rawDataIndex + 5];
unk = rawData[rawDataIndex + 6];
}
string SetTimeSettings::GenerateSourceCodePass1(string roomName, uint32_t baseAddress)
void SetTimeSettings::ParseRawData()
{
return StringHelper::Sprintf(
"%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), hour, min, unk);
ZRoomCommand::ParseRawData();
hour = parent->GetRawData().at(rawDataIndex + 4);
min = parent->GetRawData().at(rawDataIndex + 5);
unk = parent->GetRawData().at(rawDataIndex + 6);
}
string SetTimeSettings::GetCommandCName()
std::string SetTimeSettings::GetBodySourceCode() const
{
return StringHelper::Sprintf("SCENE_CMD_TIME_SETTINGS(%i, %i, %i)", hour, min, unk);
}
std::string SetTimeSettings::GetCommandCName() const
{
return "SCmdTimeSettings";
}
RoomCommand SetTimeSettings::GetRoomCommand()
RoomCommand SetTimeSettings::GetRoomCommand() const
{
return RoomCommand::SetTimeSettings;
}
}

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