1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-04 23:14:37 +00:00

git subrepo pull --force tools/ZAPD (#727)

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "4751db5c9"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "4751db5c9"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"
This commit is contained in:
fig02 2021-03-20 12:02:12 -04:00 committed by GitHub
parent 77ec4d4916
commit 493bdbc3c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
115 changed files with 16370 additions and 2789 deletions

84
tools/ZAPD/.clang-format Normal file
View file

@ -0,0 +1,84 @@
---
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 100
CommentPragmas: '^ (IWYU pragma:|NOLINT)'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ ]
IncludeCategories:
- Regex: '^<[Ww]indows\.h>$'
Priority: 1
- Regex: '^<'
Priority: 2
- Regex: '^"'
Priority: 3
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 4
UseTab: AlignWithSpaces
...

View file

@ -332,5 +332,6 @@ ASALocalRun/
*.out
*.o
*.d
lib/libgfxd/libgfxd.a
.vscode/
ZAPD/BuildInfo.h

View file

@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/zeldaret/ZAPD.git
branch = master
commit = 4bf6600a3b67223d5e28d6a1fccfeb54e37d7a77
parent = 8e0fa07a7e03730951ba98a377cf7738e8f26295
commit = 4751db5c9ee0a25a26379ca5b44efad72215d256
parent = 77ec4d491610620338e592a0f853b7c59af7fba5
method = merge
cmdver = 0.4.3

View file

@ -1,5 +1,7 @@
pipeline {
agent any
agent {
label "ZAPD"
}
stages {
stage('Build ZAPD') {

View file

@ -1,11 +1,5 @@
CC := g++
ifneq (, $(shell which ccache))
CC := ccache $(CC)
endif
CFLAGS := -g -std=c++17 -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 -O2 -rdynamic
UNAME := $(shell uname)
FS_INC =
@ -19,18 +13,22 @@ CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
CPP_FILES += lib/tinyxml2/tinyxml2.cpp
O_FILES := $(CPP_FILES:.cpp=.o)
all: genbuildinfo ZAPD.out
all: ZAPD.out
genbuildinfo:
python3 ZAPD/genbuildinfo.py
clean:
rm -f $(O_FILES) ZAPD.out
$(MAKE) -C lib/libgfxd clean
rebuild: clean all
%.o: %.cpp
%.o: %.cpp genbuildinfo
$(CC) $(CFLAGS) -c $< -o $@
ZAPD.out: $(O_FILES)
lib/libgfxd/libgfxd.a:
$(MAKE) -C lib/libgfxd -j
ZAPD.out: $(O_FILES) lib/libgfxd/libgfxd.a
$(CC) $(CFLAGS) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC)

View file

@ -49,48 +49,66 @@ public:
static inline int32_t ToInt32BE(const uint8_t* data, int offset)
{
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
}
static inline int32_t ToInt32BE(const std::vector<uint8_t>& data, int offset)
{
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
}
static inline uint32_t ToUInt32BE(const uint8_t* data, int offset)
{
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
}
static inline uint32_t ToUInt32BE(const std::vector<uint8_t>& data, int offset)
{
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
return ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
}
static inline int64_t ToInt64BE(const uint8_t* data, int offset)
{
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
}
static inline int64_t ToInt64BE(const std::vector<uint8_t>& data, int offset)
{
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
}
static inline uint64_t ToUInt64BE(const uint8_t* data, int offset)
{
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
}
static inline uint64_t ToUInt64BE(const std::vector<uint8_t>& data, int offset)
{
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
return ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
}
static inline float ToFloatBE(const uint8_t* data, int offset)
{
float value;
uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
uint32_t floatData = ((uint32_t)data[offset + 0] << 24) +
((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
static_assert(sizeof(uint32_t) == sizeof(float));
std::memcpy(&value, &floatData, sizeof(value));
return value;
@ -99,7 +117,9 @@ public:
static inline float ToFloatBE(const std::vector<uint8_t>& data, int offset)
{
float value;
uint32_t floatData = ((uint32_t)data[offset + 0] << 24) + ((uint32_t)data[offset + 1] << 16) + ((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
uint32_t floatData = ((uint32_t)data[offset + 0] << 24) +
((uint32_t)data[offset + 1] << 16) +
((uint32_t)data[offset + 2] << 8) + (uint32_t)data[offset + 3];
static_assert(sizeof(uint32_t) == sizeof(float));
std::memcpy(&value, &floatData, sizeof(value));
return value;
@ -108,9 +128,14 @@ public:
static inline double ToDoubleBE(const uint8_t* data, int offset)
{
double value;
uint64_t floatData = ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
uint64_t floatData =
((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
static_assert(sizeof(uint64_t) == sizeof(double));
// Checks if the float format on the platform the ZAPD binary is running on supports the same float format as the object file.
// Checks if the float format on the platform the ZAPD binary is running on supports the
// same float format as the object file.
static_assert(std::numeric_limits<float>::is_iec559);
std::memcpy(&value, &floatData, sizeof(value));
return value;
@ -119,9 +144,14 @@ public:
static inline double ToDoubleBE(const std::vector<uint8_t>& data, int offset)
{
double value;
uint64_t floatData = ((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) + ((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) + ((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) + ((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
uint64_t floatData =
((uint64_t)data[offset + 0] << 56) + ((uint64_t)data[offset + 1] << 48) +
((uint64_t)data[offset + 2] << 40) + ((uint64_t)data[offset + 3] << 32) +
((uint64_t)data[offset + 4] << 24) + ((uint64_t)data[offset + 5] << 16) +
((uint64_t)data[offset + 6] << 8) + ((uint64_t)data[offset + 7]);
static_assert(sizeof(uint64_t) == sizeof(double));
// Checks if the float format on the platform the ZAPD binary is running on supports the same float format as the object file.
// Checks if the float format on the platform the ZAPD binary is running on supports the
// same float format as the object file.
static_assert(std::numeric_limits<double>::is_iec559);
std::memcpy(&value, &floatData, sizeof(value));
return value;

View file

@ -1,7 +1,8 @@
#pragma once
#include <string>
#include <iostream>
#include <string>
#include <vector>
#if __has_include(<filesystem>)
#include <filesystem>
@ -11,18 +12,14 @@ namespace fs = std::filesystem;
namespace fs = std::experimental::filesystem;
#endif
#include "StringHelper.h"
class Directory
{
public:
static std::string GetCurrentDirectory()
{
return fs::current_path().u8string();
}
static std::string GetCurrentDirectory() { return fs::current_path().u8string(); }
static bool Exists(const std::string& path)
{
return fs::exists(fs::path(path));
}
static bool Exists(const std::string& path) { return fs::exists(fs::path(path)); }
static void CreateDirectory(const std::string& path)
{
@ -37,6 +34,6 @@ public:
fs::create_directory(curPath);
}
//fs::create_directory(path);
// fs::create_directory(path);
}
};

View file

@ -1,11 +1,11 @@
#pragma once
#include <string>
#include <fstream>
#include <vector>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include "StringHelper.h"
class File
@ -25,7 +25,7 @@ public:
char* data = new char[fileSize];
file.read(data, fileSize);
std::vector<uint8_t> result = std::vector<uint8_t>(data, data + fileSize);
delete data;
delete[] data;
return result;
};
@ -35,11 +35,11 @@ public:
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
int fileSize = (int)file.tellg();
file.seekg(0);
char* data = new char[fileSize+1];
char* data = new char[fileSize + 1];
memset(data, 0, fileSize + 1);
file.read(data, fileSize);
std::string str = std::string((const char*)data);
delete data;
delete[] data;
return str;
};

View file

@ -1,7 +1,7 @@
#include "Globals.h"
#include <algorithm>
#include "File.h"
#include "tinyxml2.h"
#include <algorithm>
using namespace tinyxml2;
using namespace std;
@ -14,7 +14,7 @@ Globals::Globals()
files = std::vector<ZFile*>();
segments = std::vector<int>();
symbolMap = std::map <uint32_t, std::string>();
symbolMap = std::map<uint32_t, std::string>();
segmentRefs = map<int, string>();
segmentRefFiles = map<int, ZFile*>();
game = ZGame::OOT_RETAIL;
@ -45,9 +45,10 @@ string Globals::FindSymbolSegRef(int segNumber, uint32_t symbolAddress)
if (root == nullptr)
return "ERROR";
//vector<ZFile*> files = vector<ZFile*>();
// vector<ZFile*> files = vector<ZFile*>();
for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "File")
{
@ -78,7 +79,8 @@ void Globals::ReadConfigFile(const std::string& configFilePath)
if (root == nullptr)
return;
for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "SymbolMap")
{

View file

@ -4,10 +4,11 @@
#include <string>
#include <vector>
#include "ZFile.h"
#include "ZTexture.h"
#include "ZRoom/ZRoom.h"
#include "ZTexture.h"
typedef enum VerbosityLevel {
typedef enum VerbosityLevel
{
VERBOSITY_SILENT,
VERBOSITY_INFO,
VERBOSITY_DEBUG
@ -58,11 +59,11 @@ public:
GameConfig();
private:
};
/*
* Note: In being able to track references across files, there are a few major files that make use of segments...
* Note: In being able to track references across files, there are a few major files that make use
* of segments...
* Segment 1: nintendo_rogo_static/title_static
* Segment 2: parameter_static
* Segment 4: gameplay_keep

View file

@ -9,5 +9,4 @@
class HLAnimation
{
public:
};

View file

@ -14,7 +14,6 @@ HLAnimationIntermediette::HLAnimationIntermediette()
HLAnimationIntermediette::~HLAnimationIntermediette()
{
}
HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath)
@ -30,11 +29,13 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath)
anim->limbCount = root->IntAttribute("LimbCount");
anim->frameCount = root->IntAttribute("FrameCount");
for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "RotationValues")
{
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL; child2 = child2->NextSiblingElement())
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
child2 = child2->NextSiblingElement())
{
string value = child2->GetText();
anim->rotationValues.push_back(atoi(value.c_str()));
@ -42,8 +43,11 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath)
}
else if (string(child->Name()) == "RotationIndices")
{
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL; child2 = child2->NextSiblingElement())
anim->rotationIndices.push_back(RotationIndex(child2->IntAttribute("X"), child2->IntAttribute("Y"), child2->IntAttribute("Z")));
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
child2 = child2->NextSiblingElement())
anim->rotationIndices.push_back(RotationIndex(child2->IntAttribute("X"),
child2->IntAttribute("Y"),
child2->IntAttribute("Z")));
}
}
@ -96,7 +100,7 @@ string HLAnimationIntermediette::OutputXML()
XMLElement* rotValues = doc.NewElement("RotationValues");
for (int i = 0; i < rotationValues.size(); i++)
for (size_t i = 0; i < rotationValues.size(); i++)
{
XMLElement* rotValue = doc.NewElement("Value");
rotValue->SetText(rotationValues[i]);
@ -107,7 +111,7 @@ string HLAnimationIntermediette::OutputXML()
XMLElement* rotIndices = doc.NewElement("RotationIndices");
for (int i = 0; i < rotationIndices.size(); i++)
for (size_t i = 0; i < rotationIndices.size(); i++)
{
XMLElement* rotIndex = doc.NewElement("Value");
rotIndex->SetAttribute("X", rotationIndices[i].x);

View file

@ -1,8 +1,8 @@
#pragma once
#include <stdint.h>
#include "../ZAnimation.h"
#include <tinyxml2.h>
#include "../ZAnimation.h"
#include "HLFileIntermediette.h"
/*

View file

@ -2,5 +2,4 @@
class HLFileIntermediette
{
};

View file

@ -1,15 +1,15 @@
#include "HLModelIntermediette.h"
#include "../ZDisplayList.h"
#include "../StringHelper.h"
#include "../File.h"
#include "../Globals.h"
#include "../Path.h"
#include "../File.h"
#include "../StringHelper.h"
#include "../ZDisplayList.h"
#ifdef USE_ASSIMP
#include <assimp/Importer.hpp>
#include <assimp/Exporter.hpp>
#include <assimp/scene.h>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <assimp/scene.h>
#endif
using namespace std;
@ -31,7 +31,8 @@ HLModelIntermediette* HLModelIntermediette::FromXML(tinyxml2::XMLElement* root)
{
HLModelIntermediette* model = new HLModelIntermediette();
for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
string childName = child->Name();
HLIntermediette* block = nullptr;
@ -60,16 +61,16 @@ HLModelIntermediette* HLModelIntermediette::FromXML(tinyxml2::XMLElement* root)
void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDisplayList* zDisplayList)
{
//HLModelIntermediette* model = new HLModelIntermediette();
// HLModelIntermediette* model = new HLModelIntermediette();
HLLimbIntermediette* limb = new HLLimbIntermediette();
limb->name = zDisplayList->GetName();
// Go through verts
vector<Vertex> finalVerts = vector<Vertex>();
uint32_t vStart = -1;
int32_t vStart = -1;
for (pair<uint32_t, vector<Vertex>> pair : zDisplayList->vertices)
for (pair<int32_t, vector<Vertex>> pair : zDisplayList->vertices)
{
if (vStart == -1) // TODO: Find a better way to do this
vStart = pair.first;
@ -112,7 +113,7 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
startIndex = 0;
for (int i = startIndex; i < zDisplayList->instructions.size(); i++)
for (size_t i = startIndex; i < zDisplayList->instructions.size(); i++)
{
uint64_t data = zDisplayList->instructions[i];
F3DZEXOpcode opcode = (F3DZEXOpcode)(data >> 56);
@ -121,15 +122,14 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
{
int ss = (data & 0x0000FF0000000000) >> 40;
int nn = (data & 0x000000FF00000000) >> 32;
int dd = (data & 0xFFFFFFFF);
// int dd = (data & 0xFFFFFFFF);
int sft = 32 - (nn + 1) - ss;
if (sft == 3)
{
int mode1 = (dd & 0xCCCC0000) >> 0;
int mode2 = (dd & 0x33330000) >> 0;
// int mode1 = (dd & 0xCCCC0000) >> 0;
// int mode2 = (dd & 0x33330000) >> 0;
}
}
else if (opcode == F3DZEXOpcode::G_SETPRIMCOLOR)
@ -155,20 +155,30 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
lastMat->clrL = ff;
lastMat->clrM = mm;
}
else if (opcode == F3DZEXOpcode::G_SETTILE && (F3DZEXOpcode)(zDisplayList->instructions[i - 1] >> 56) != F3DZEXOpcode::G_RDPPIPESYNC)
else if (opcode == F3DZEXOpcode::G_SETTILE &&
(F3DZEXOpcode)(zDisplayList->instructions[i - 1] >> 56) !=
F3DZEXOpcode::G_RDPPIPESYNC)
{
int fff = (data & 0b0000000011100000000000000000000000000000000000000000000000000000) >> 53;
int ii = (data & 0b0000000000011000000000000000000000000000000000000000000000000000) >> 51;
int nnnnnnnnn = (data & 0b0000000000000011111111100000000000000000000000000000000000000000) >> 41;
int mmmmmmmmm = (data & 0b0000000000000000000000011111111100000000000000000000000000000000) >> 32;
int ttt = (data & 0b0000000000000000000000000000000000000111000000000000000000000000) >> 24;
int pppp = (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >> 20;
int cc = (data & 0b0000000000000000000000000000000000000000000011000000000000000000) >> 18;
int aaaa = (data & 0b0000000000000000000000000000000000000000000000111100000000000000) >> 14;
int ssss = (data & 0b0000000000000000000000000000000000000000000000000011110000000000) >> 10;
int dd = (data & 0b0000000000000000000000000000000000000000000000000000001100000000) >> 8;
int bbbb = (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4;
int uuuu = (data & 0b0000000000000000000000000000000000000000000000000000000000001111);
// int fff = (data & 0b0000000011100000000000000000000000000000000000000000000000000000)
// >> 53; int ii = (data &
// 0b0000000000011000000000000000000000000000000000000000000000000000) >> 51; int
// nnnnnnnnn = (data &
// 0b0000000000000011111111100000000000000000000000000000000000000000) >> 41; int
// mmmmmmmmm = (data &
// 0b0000000000000000000000011111111100000000000000000000000000000000) >> 32; int ttt =
// (data & 0b0000000000000000000000000000000000000111000000000000000000000000) >> 24; int
// pppp = (data & 0b0000000000000000000000000000000000000000111100000000000000000000) >>
// 20;
int cc =
(data & 0b0000000000000000000000000000000000000000000011000000000000000000) >> 18;
// int aaaa = (data &
// 0b0000000000000000000000000000000000000000000000111100000000000000) >> 14; int ssss =
// (data & 0b0000000000000000000000000000000000000000000000000011110000000000) >> 10;
int dd =
(data & 0b0000000000000000000000000000000000000000000000000000001100000000) >> 8;
// int bbbb = (data &
// 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; int uuuu =
// (data & 0b0000000000000000000000000000000000000000000000000000000000001111);
lastMat->cmtH = (HLMaterialCmt)cc;
lastMat->cmtV = (HLMaterialCmt)dd;
@ -200,7 +210,8 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
meshCnt++;
mesh = new HLMeshIntermediette();
mesh->name = StringHelper::Sprintf("%s_%i", zDisplayList->GetName().c_str(), meshCnt);
mesh->name =
StringHelper::Sprintf("%s_%i", zDisplayList->GetName().c_str(), meshCnt);
}
}
else if (opcode == F3DZEXOpcode::G_SETTIMG)
@ -242,7 +253,7 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
mesh->commands.push_back(new HLMeshCmdTriangle2(aa, bb, cc, 0, dd, ee, ff, 0));
}
int bp = 0;
// int bp = 0;
}
limb->commands.push_back(new HLLimbCommand(mesh->name, lastMat->name));
@ -250,18 +261,18 @@ void HLModelIntermediette::FromZDisplayList(HLModelIntermediette* model, ZDispla
model->blocks.push_back(mesh);
model->blocks.push_back(limb);
//return model;
// return model;
}
void HLModelIntermediette::FromZSkeleton(HLModelIntermediette* model, ZSkeleton* zSkeleton)
{
model->hasSkeleton = true;
for (int i = 0; i < zSkeleton->limbs.size(); i++)
for (size_t i = 0; i < zSkeleton->limbs.size(); i++)
{
ZLimb* limb = zSkeleton->limbs[i];
// ZLimb* limb = zSkeleton->limbs[i];
for (int j = 0; j < model->blocks.size(); j++)
for (size_t j = 0; j < model->blocks.size(); j++)
{
}
}
@ -360,8 +371,7 @@ std::string HLModelIntermediette::OutputXML()
return printer.CStr();
}
template<typename T>
template <typename T>
inline T* HLModelIntermediette::FindByName(string name)
{
for (HLIntermediette* block : blocks)
@ -376,7 +386,7 @@ inline T* HLModelIntermediette::FindByName(string name)
return nullptr;
}
template<typename T>
template <typename T>
inline T* HLModelIntermediette::FindByType()
{
for (HLIntermediette* block : blocks)
@ -415,17 +425,14 @@ string HLIntermediette::OutputOBJ()
void HLIntermediette::OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts)
{
}
void HLIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root)
{
}
void HLMeshCommand::InitFromXML(XMLElement* xmlElement)
{
}
string HLMeshCommand::OutputCode(HLModelIntermediette* parent)
@ -446,7 +453,6 @@ void HLMeshCommand::OutputXML(tinyxml2::XMLElement* parent)
{
}
HLVerticesIntermediette::HLVerticesIntermediette() : HLIntermediette()
{
vertices = vector<Vertex>();
@ -456,10 +462,13 @@ 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"),
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")));
child->IntAttribute("R"), child->IntAttribute("G"),
child->IntAttribute("B"), child->IntAttribute("A")));
}
void HLVerticesIntermediette::InitFromVertices(vector<Vertex> dispListVertices)
@ -476,8 +485,8 @@ string HLVerticesIntermediette::OutputCode(HLModelIntermediette* parent)
for (Vertex v : vertices)
{
output += StringHelper::Sprintf("\t{ %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);
output += StringHelper::Sprintf("\t{ %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);
}
output += StringHelper::Sprintf("};\n");
@ -491,32 +500,34 @@ std::string HLVerticesIntermediette::OutputOBJ()
for (Vertex 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);
//output += StringHelper::Sprintf("v %f %f %f\n", (float)v.x * 0.1f, (float)v.y * 0.1f, (float)v.z * 0.1f);
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);
// output += StringHelper::Sprintf("v %f %f %f\n", (float)v.x * 0.1f, (float)v.y * 0.1f,
// (float)v.z * 0.1f);
}
//for (Vertex v : vertices)
//output += StringHelper::Sprintf("vt %i %i\n", v.s, v.t);
// for (Vertex v : vertices)
// output += StringHelper::Sprintf("vt %i %i\n", v.s, v.t);
return output;
}
void HLVerticesIntermediette::OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts)
{
//aiVector3D* verts = new aiVector3D[vertices.size()];
//aiVector3D* normals = new aiVector3D[vertices.size()];
// aiVector3D* verts = new aiVector3D[vertices.size()];
// aiVector3D* normals = new aiVector3D[vertices.size()];
verts->clear();
for (int i = 0; i < vertices.size(); i++)
for (size_t i = 0; i < vertices.size(); i++)
{
verts->push_back(aiVector3D(vertices[i].x, vertices[i].y, vertices[i].z));
//normals[i] = aiVector3D(vertices[i].x, vertices[i].y, vertices[i].z);
// normals[i] = aiVector3D(vertices[i].x, vertices[i].y, vertices[i].z);
}
//mesh->mVertices = verts;
//mesh->mNormals = normals;
//mesh->mNumVertices += vertices.size();
// mesh->mVertices = verts;
// mesh->mNormals = normals;
// mesh->mNumVertices += vertices.size();
}
void HLVerticesIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root)
@ -562,7 +573,8 @@ string HLMeshCmdGeoSettings::OutputCode(HLModelIntermediette* parent)
string output = "";
if (off != "")
output += StringHelper::Sprintf("gsSPClearGeometryMode(G_TEXTURE_ENABLE | %s),\n", off.c_str());
output +=
StringHelper::Sprintf("gsSPClearGeometryMode(G_TEXTURE_ENABLE | %s),\n", off.c_str());
if (on != "")
output += StringHelper::Sprintf("gsSPSetGeometryMode(G_TEXTURE_ENABLE | %s),", on.c_str());
@ -635,7 +647,8 @@ HLMeshCmdTriangle2::HLMeshCmdTriangle2()
flag1 = 0;
}
HLMeshCmdTriangle2::HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0, int32_t nV10, int32_t nV11, int32_t nV12, int32_t nFlag1)
HLMeshCmdTriangle2::HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0,
int32_t nV10, int32_t nV11, int32_t nV12, int32_t nFlag1)
{
v0 = nV0;
v1 = nV1;
@ -661,18 +674,21 @@ void HLMeshCmdTriangle2::InitFromXML(tinyxml2::XMLElement* xmlElement)
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);
return StringHelper::Sprintf("gsSP2Triangles(%i, %i, %i, %i, %i, %i, %i, %i),", v0, v1, v2,
flag0, v10, v11, v12, flag1);
}
std::string HLMeshCmdTriangle2::OutputOBJ(HLModelIntermediette* parent)
{
HLVerticesIntermediette* verts = parent->FindByName<HLVerticesIntermediette>("");
// HLVerticesIntermediette* verts = parent->FindByName<HLVerticesIntermediette>("");
string output = "";
int startIndex = parent->startIndex;
output += StringHelper::Sprintf("f %i %i %i\n", startIndex+v0+1, startIndex + v1+1, startIndex + v2+1);
output += StringHelper::Sprintf("f %i %i %i\n", startIndex + v10+1, startIndex + v11+1, startIndex + v12+1);
output += StringHelper::Sprintf("f %i %i %i\n", startIndex + v0 + 1, startIndex + v1 + 1,
startIndex + v2 + 1);
output += StringHelper::Sprintf("f %i %i %i\n", startIndex + v10 + 1, startIndex + v11 + 1,
startIndex + v12 + 1);
return output;
}
@ -760,24 +776,25 @@ void HLMeshCmdLoadVertices::OutputAssimp(HLModelIntermediette* parent, aiScene*
string HLMeshCmdLoadVertices::OutputCode(HLModelIntermediette* parent)
{
HLVerticesIntermediette* verts = parent->FindByType<HLVerticesIntermediette>();
return StringHelper::Sprintf("gsSPVertex(&%s[%i], %i, %i),", verts->name.c_str(), startIndex, numVerts, 0);
return StringHelper::Sprintf("gsSPVertex(&%s[%i], %i, %i),", verts->name.c_str(), startIndex,
numVerts, 0);
}
HLMaterialIntermediette::HLMaterialIntermediette()
{
textureName = "";
//repeatH = false;
//repeatV = false;
// repeatH = false;
// repeatV = false;
clrR = 0;
clrG = 0;
clrB = 0;
clrA = 0;
clrM = 0;
clrL = 0;
//clampH = false;
//clampV = false;
//mirrorH = false;
//mirrorV = false;
// clampH = false;
// clampV = false;
// mirrorH = false;
// mirrorV = false;
cmtH = HLMaterialCmt::Wrap;
cmtV = HLMaterialCmt::Wrap;
}
@ -786,12 +803,12 @@ void HLMaterialIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
{
name = xmlElement->Attribute("Name");
textureName = xmlElement->Attribute("TextureName");
//repeatH = xmlElement->BoolAttribute("RepeatH");
//repeatV = xmlElement->BoolAttribute("RepeatV");
//clampH = xmlElement->BoolAttribute("ClampH");
//clampV = xmlElement->BoolAttribute("ClampV");
//mirrorH = xmlElement->BoolAttribute("MirrorH");
//mirrorV = xmlElement->BoolAttribute("MirrorV");
// repeatH = xmlElement->BoolAttribute("RepeatH");
// repeatV = xmlElement->BoolAttribute("RepeatV");
// clampH = xmlElement->BoolAttribute("ClampH");
// clampV = xmlElement->BoolAttribute("ClampV");
// mirrorH = xmlElement->BoolAttribute("MirrorH");
// mirrorV = xmlElement->BoolAttribute("MirrorV");
clrR = xmlElement->IntAttribute("ClrR");
clrG = xmlElement->IntAttribute("ClrG");
clrB = xmlElement->IntAttribute("ClrB");
@ -835,7 +852,8 @@ string HLDisplayListIntermediette::OutputCode()
void HLDisplayListIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
{
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
string name = child->Name();
@ -867,7 +885,6 @@ void HLDisplayListCmdDrawMesh::InitFromXML(tinyxml2::XMLElement* xmlElement)
{
meshName = xmlElement->Attribute("Mesh");
materialName = xmlElement->Attribute("Material");
}
std::string HLDisplayListCmdDrawMesh::OutputCode()
@ -885,16 +902,19 @@ void HLTextureIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
name = xmlElement->Attribute("Name");
fileName = xmlElement->Attribute("TextureName");
//string format = xmlElement->Attribute("Format");
// string format = xmlElement->Attribute("Format");
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 = HLTexture::FromPNG(fileName,
// (HLTextureType)ZTexture::GetTextureTypeFromString(format));
tex = ZTexture::FromPNG(Path::GetDirectoryName(Globals::Instance->inputPath) + "/" + fileName,
ZTexture::GetTextureTypeFromString(format));
}
std::string HLTextureIntermediette::OutputCode()
{
return StringHelper::Sprintf("#include <../%s/%s.inc.c>", Globals::Instance->outputPath.c_str(), name.c_str());
return StringHelper::Sprintf("#include <../%s/%s.inc.c>", Globals::Instance->outputPath.c_str(),
name.c_str());
}
void HLTextureIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root)
@ -902,7 +922,8 @@ void HLTextureIntermediette::OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XML
XMLElement* element = doc->NewElement("Texture");
element->SetAttribute("Name", name.c_str());
element->SetAttribute("TextureName", (name + "." + tex->GetExternalExtension() + ".png").c_str());
element->SetAttribute("TextureName",
(name + "." + tex->GetExternalExtension() + ".png").c_str());
tex->Save(Globals::Instance->outputPath);
root->InsertEndChild(element);
@ -943,7 +964,8 @@ void HLMeshIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
{
name = xmlElement->Attribute("Name");
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
string name = child->Name();
@ -976,13 +998,15 @@ string HLMeshIntermediette::OutputCode(string materialName)
HLTextureIntermediette* tex = parent->FindByName<HLTextureIntermediette>(mat->textureName);
output += StringHelper::Sprintf("\tgsDPPipeSync(),\n");
output += StringHelper::Sprintf("\tgsDPSetPrimColor(%i, %i, %i, %i, %i, %i),\n", mat->clrL, mat->clrM, mat->clrR, mat->clrG, mat->clrB, mat->clrA);
output += StringHelper::Sprintf("\tgsDPSetPrimColor(%i, %i, %i, %i, %i, %i),\n", mat->clrL,
mat->clrM, mat->clrR, mat->clrG, mat->clrB, mat->clrA);
output += StringHelper::Sprintf("\tgsDPPipeSync(),\n");
output += StringHelper::Sprintf("\tgsSPTexture(65535, 65535, 0, 0, G_ON),\n");
output += StringHelper::Sprintf("\tgsDPLoadMultiBlock(%s, 0, 0, %s, %s, %i, %i, 0, 0, 0, 5, 5, 0, 0),\n", mat->textureName.c_str(),
tex->tex->GetIMFmtFromType().c_str(), tex->tex->GetIMSizFromType().c_str(), tex->tex->GetWidth(), tex->tex->GetHeight());
output += StringHelper::Sprintf(
"\tgsDPLoadMultiBlock(%s, 0, 0, %s, %s, %i, %i, 0, 0, 0, 5, 5, 0, 0),\n",
mat->textureName.c_str(), tex->tex->GetIMFmtFromType().c_str(),
tex->tex->GetIMSizFromType().c_str(), tex->tex->GetWidth(), tex->tex->GetHeight());
for (HLMeshCommand* cmd : commands)
output += "\t" + cmd->OutputCode(parent) + "\n";
@ -1005,7 +1029,8 @@ string HLMeshIntermediette::OutputOBJ()
void HLMeshIntermediette::OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts)
{
aiMesh* mesh = new aiMesh();
mesh->mVertices = new aiVector3D[8192]; // TODO: Replace these hardcoded counts with the actual count
mesh->mVertices =
new aiVector3D[8192]; // TODO: Replace these hardcoded counts with the actual count
mesh->mNormals = new aiVector3D[8192];
mesh->mFaces = new aiFace[8192];
mesh->mPrimitiveTypes = 8;
@ -1042,7 +1067,8 @@ void HLLimbIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
{
name = xmlElement->Attribute("Name");
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = xmlElement->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
string name = child->Name();
@ -1120,8 +1146,8 @@ std::string HLLimbCommand::OutputCode(HLModelIntermediette* parent)
// Time to generate the display list...
HLMeshIntermediette* mesh = parent->FindByName<HLMeshIntermediette>(meshName);
HLMaterialIntermediette* mat = parent->FindByName<HLMaterialIntermediette>(materialName);
HLTextureIntermediette* tex = parent->FindByName<HLTextureIntermediette>(mat->textureName);
// HLMaterialIntermediette* mat = parent->FindByName<HLMaterialIntermediette>(materialName);
// HLTextureIntermediette* tex = parent->FindByName<HLTextureIntermediette>(mat->textureName);
output += mesh->OutputCode(materialName);
@ -1138,11 +1164,11 @@ HLTerminator::~HLTerminator()
void HLTerminator::OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts)
{
for (int i = parent->meshStartIndex; i < scene->mNumMeshes; i++)
for (uint32_t i = parent->meshStartIndex; i < scene->mNumMeshes; i++)
{
scene->mMeshes[i]->mNumVertices = verts->size();
for (int j = 0; j < verts->size(); j++)
for (uint32_t j = 0; j < verts->size(); j++)
scene->mMeshes[i]->mVertices[j] = verts[0][j];
parent->meshStartIndex++;

View file

@ -1,14 +1,14 @@
#pragma once
#include <assimp/scene.h>
#include <stdint.h>
#include <vector>
#include <string>
#include "HLTexture.h"
#include "HLFileIntermediette.h"
#include <tinyxml2.h>
#include <vector>
#include "../ZDisplayList.h"
#include "../ZSkeleton.h"
#include <tinyxml2.h>
#include <assimp/scene.h>
#include "HLFileIntermediette.h"
#include "HLTexture.h"
/*
* An intermediette format for models. Goes from FBX<-->Intermediette<-->Display List C Code.
@ -43,8 +43,8 @@ public:
bool startsWithClearGeometryMode;
bool lerpBeforeTextureBlock;
int startIndex;
int meshStartIndex;
uint32_t startIndex;
uint32_t meshStartIndex;
HLModelIntermediette();
~HLModelIntermediette();
@ -98,10 +98,10 @@ class HLMaterialIntermediette : public HLIntermediette
{
public:
std::string textureName;
//int32_t repeatH, repeatV;
// int32_t repeatH, repeatV;
uint8_t clrR, clrG, clrB, clrA, clrM, clrL;
//bool clampH, clampV;
//bool mirrorH, mirrorV;
// bool clampH, clampV;
// bool mirrorH, mirrorV;
HLMaterialCmt cmtH, cmtV;
// TODO: Remember to add lerp params here...
@ -159,7 +159,8 @@ public:
int32_t v0, v1, v2, flag0, v10, v11, v12, flag1;
HLMeshCmdTriangle2();
HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0, int32_t nV10, int32_t nV11, int32_t nV12, int32_t nFlag1);
HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0, int32_t nV10,
int32_t nV11, int32_t nV12, int32_t nFlag1);
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
virtual std::string OutputCode(HLModelIntermediette* parent);

View file

@ -1,6 +1,6 @@
#include "HLTexture.h"
#include "../StringHelper.h"
#include <stb_image.h>
#include "../StringHelper.h"
using namespace std;
@ -9,7 +9,8 @@ HLTexture* HLTexture::FromPNG(std::string pngFilePath, HLTextureType texType)
int comp;
HLTexture* tex = new HLTexture();
tex->type = texType;
tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int*)&tex->width, (int*)&tex->height, &comp, STBI_rgb_alpha);
tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int*)&tex->width, (int*)&tex->height,
&comp, STBI_rgb_alpha);
return tex;
}

View file

@ -1,10 +1,11 @@
#pragma once
#include <stdint.h>
#include <vector>
#include <string>
#include <vector>
// TODO: This was duplicated from ZTexture. It's probably going to be modified to differentiate from ZTexture but if not, we're going to need to have the two share an enum.
// TODO: This was duplicated from ZTexture. It's probably going to be modified to differentiate from
// ZTexture but if not, we're going to need to have the two share an enum.
enum class HLTextureType
{
RGBA32bpp,
@ -19,7 +20,6 @@ enum class HLTextureType
Error
};
class HLTexture
{
public:

View file

@ -1,20 +1,20 @@
#include "ZFile.h"
#include "ZTexture.h"
#include "ZBlob.h"
#include "ZAnimation.h"
#include "HighLevel/HLModelIntermediette.h"
#include "BuildInfo.h"
#include "Directory.h"
#include "File.h"
#include "Globals.h"
#include "HighLevel/HLAnimationIntermediette.h"
#include "HighLevel/HLModelIntermediette.h"
#include "Overlays/ZOverlay.h"
#include "Path.h"
#include "File.h"
#include "Directory.h"
#include "Globals.h"
#include "BuildInfo.h"
#include "ZAnimation.h"
#include "ZBlob.h"
#include "ZFile.h"
#include "ZTexture.h"
#if !defined(_MSC_VER) && !defined(__CYGWIN__)
#include <execinfo.h>
#include <unistd.h>
#include <signal.h>
#include <unistd.h>
#endif
#include <string>
@ -23,9 +23,11 @@
using namespace tinyxml2;
using namespace std;
bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, ZFileMode fileMode);
bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath,
ZFileMode fileMode);
void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, const std::string& outPath);
void BuildAssetTexture(const std::string& pngFilePath, TextureType texType,
const std::string& outPath);
void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath);
void BuildAssetModelIntermediette(const std::string& mdlPath, const std::string& outPath);
void BuildAssetAnimationIntermediette(const std::string& animPath, const std::string& outPath);
@ -41,13 +43,13 @@ void ErrorHandler(int sig)
size = backtrace(array, 4096);
symbols = backtrace_symbols(array, 4096);
for (int i = 1; i < size; i++)
for (size_t i = 1; i < size; i++)
{
size_t len = strlen(symbols[i]);
// size_t len = strlen(symbols[i]);
cout << symbols[i] << "\n";
}
//cout << "Error: signal " << sig << ":\n";
// cout << "Error: signal " << sig << ":\n";
backtrace_symbols_fd(array, size, STDERR_FILENO);
exit(1);
}
@ -136,7 +138,8 @@ int NewMain(int argc, char* argv[])
Globals::Instance->profile = string(argv[i + 1]) == "1";
i++;
}
else if (arg == "-uer") // Split resources into their individual components (enabled by default)
else if (arg ==
"-uer") // Split resources into their individual components (enabled by default)
{
Globals::Instance->useExternalResources = string(argv[i + 1]) == "1";
i++;
@ -185,9 +188,15 @@ int NewMain(int argc, char* argv[])
if (Globals::Instance->verbosity >= VERBOSITY_INFO)
printf("ZAPD: Zelda Asset Processor For Decomp: %s\n", gBuildHash);
if (fileMode == ZFileMode::Build || fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
if (fileMode == ZFileMode::Build || fileMode == ZFileMode::Extract ||
fileMode == ZFileMode::BuildSourceFile)
{
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)
{
@ -210,11 +219,14 @@ int NewMain(int argc, char* argv[])
}
else if (fileMode == ZFileMode::BuildAnimationIntermediette)
{
BuildAssetAnimationIntermediette(Globals::Instance->inputPath, Globals::Instance->outputPath);
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));
ZOverlay* overlay =
ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath),
Path::GetDirectoryName(Globals::Instance->cfgPath));
if (overlay)
File::WriteAllText(Globals::Instance->outputPath, overlay->GetSourceOutputCode(""));
@ -223,20 +235,28 @@ int NewMain(int argc, char* argv[])
return 0;
}
bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath, ZFileMode fileMode)
bool Parse(const std::string& xmlFilePath, const std::string& basePath, const std::string& outPath,
ZFileMode fileMode)
{
XMLDocument doc;
XMLError eResult = doc.LoadFile(xmlFilePath.c_str());
if (eResult != tinyxml2::XML_SUCCESS)
{
fprintf(stderr, "Invalid xml file: '%s'\n", xmlFilePath.c_str());
return false;
}
XMLNode* root = doc.FirstChild();
if (root == nullptr)
{
fprintf(stderr, "Missing Root tag in xml file: '%s'\n", xmlFilePath.c_str());
return false;
}
for (XMLElement* child = root->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "File")
{
@ -264,7 +284,8 @@ bool Parse(const std::string& xmlFilePath, const std::string& basePath, const st
return true;
}
void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, const std::string& outPath)
void BuildAssetTexture(const std::string& pngFilePath, TextureType texType,
const std::string& outPath)
{
vector<string> split = StringHelper::Split(outPath, "/");
string name = StringHelper::Split(split[split.size() - 1], ".")[0];
@ -274,7 +295,8 @@ void BuildAssetTexture(const std::string& pngFilePath, TextureType texType, cons
if (File::Exists(cfgPath))
name = File::ReadAllText(cfgPath);
//string src = StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str()) + tex->GetSourceOutputCode(name) + "};\n";
// string src = StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str()) +
// tex->GetSourceOutputCode(name) + "};\n";
string src = tex->GetSourceOutputCode(name);
File::WriteAllText(outPath, src);
@ -288,7 +310,8 @@ void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath)
ZBlob* blob = ZBlob::FromFile(blobFilePath);
string name = StringHelper::Split(split[split.size() - 1], ".")[0];
//string src = StringHelper::Sprintf("u8 %s[] = \n{\n", name.c_str()) + blob->GetSourceOutputCode(name) + "};\n";
// string src = StringHelper::Sprintf("u8 %s[] = \n{\n", name.c_str()) +
// blob->GetSourceOutputCode(name) + "};\n";
string src = blob->GetSourceOutputCode(name);
File::WriteAllText(outPath, src);
@ -299,7 +322,7 @@ void BuildAssetBlob(const std::string& blobFilePath, const std::string& outPath)
void BuildAssetModelIntermediette(const std::string& mdlPath, const std::string& outPath)
{
XMLDocument doc;
XMLError eResult = doc.LoadFile(mdlPath.c_str());
// XMLError eResult = doc.LoadFile(mdlPath.c_str());
vector<string> split = StringHelper::Split(outPath, "/");
HLModelIntermediette* mdl = HLModelIntermediette::FromXML(doc.RootElement());
@ -318,8 +341,8 @@ void BuildAssetAnimationIntermediette(const std::string& animPath, const std::st
ZAnimation* zAnim = anim->ToZAnimation();
zAnim->SetName(Path::GetFileNameWithoutExtension(split[split.size() - 1]));
zAnim->parent = file;
//zAnim->rotationIndicesSeg = 1;
//zAnim->rotationValuesSeg = 2;
// zAnim->rotationIndicesSeg = 1;
// zAnim->rotationValuesSeg = 2;
zAnim->GetSourceOutputCode(split[split.size() - 2]);
string output = "";

View file

@ -1,6 +1,6 @@
#include "OutputFormatter.h"
int OutputFormatter::write(const char *buf, int count)
int OutputFormatter::write(const char* buf, int count)
{
for (int i = 0; i < count; i++)
{
@ -65,29 +65,20 @@ int OutputFormatter::write(const char *buf, int count)
OutputFormatter* OutputFormatter::static_instance;
int OutputFormatter::write_static(const char *buf, int count)
int OutputFormatter::write_static(const char* buf, int count)
{
return static_instance->write(buf, count);
}
int (*OutputFormatter::static_writer())(const char *buf, int count)
int (*OutputFormatter::static_writer())(const char* buf, int count)
{
static_instance = this;
return &write_static;
}
OutputFormatter::OutputFormatter(int tab_size , int default_indent,
int line_limit)
:
tab_size{tab_size},
default_indent{default_indent},
line_limit{line_limit},
col{0},
nest{0},
nest_indent{default_indent},
current_indent{default_indent},
word_p{word},
space_p{space}
OutputFormatter::OutputFormatter(int tab_size, int default_indent, int line_limit)
: tab_size{tab_size}, default_indent{default_indent}, line_limit{line_limit}, col{0}, nest{0},
nest_indent{default_indent}, current_indent{default_indent}, word_p{word}, space_p{space}
{
}

View file

@ -1,8 +1,8 @@
#pragma once
#include <vector>
#include <map>
#include <string>
#include <vector>
class OutputFormatter
{
@ -18,21 +18,20 @@ private:
char word[128];
char space[128];
char *word_p;
char *space_p;
char* word_p;
char* space_p;
std::string str;
int write(const char *buf, int count);
int write(const char* buf, int count);
static OutputFormatter *static_instance;
static int write_static(const char *buf, int count);
static OutputFormatter* static_instance;
static int write_static(const char* buf, int count);
public:
OutputFormatter(int tab_size = 4, int default_indent = 4,
int line_limit = 120);
OutputFormatter(int tab_size = 4, int default_indent = 4, int line_limit = 120);
int (*static_writer())(const char *buf, int count);
int (*static_writer())(const char* buf, int count);
std::string get_output();
};

View file

@ -1,7 +1,7 @@
#include "ZOverlay.h"
#include "../Directory.h"
#include "../File.h"
#include "../Path.h"
#include "../Directory.h"
#include "../StringHelper.h"
using namespace std;
@ -20,7 +20,7 @@ ZOverlay::ZOverlay(string nName) : ZOverlay()
ZOverlay::~ZOverlay()
{
for (auto entry: entries)
for (auto entry : entries)
if (entry)
delete entry;
entries.clear();
@ -33,26 +33,25 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
ZOverlay* ovl = new ZOverlay(StringHelper::Strip(cfgLines[0], "\r"));
vector<string> relSections = {".rel.text", ".rel.data" , ".rel.rodata"};
vector<string> sections = {".text", ".data" , ".rodata"};
vector<string> relSections = {".rel.text", ".rel.data", ".rel.rodata"};
vector<string> sections = {".text", ".data", ".rodata"};
int sectionOffs[5] = {0};
vector<RelocationEntry*> textRelocs;
vector<RelocationEntry*> dataRelocs;
vector<RelocationEntry*> rodataRelocs;
// get the elf files
vector<elfio*> readers;
for (int i = 1; i < cfgLines.size(); i++)
for (size_t i = 1; i < cfgLines.size(); i++)
{
string elfPath = buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size()-2) + ".o";
string elfPath = buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o";
elfio* reader = new elfio();
if (!reader->load(elfPath))
{
// not all files were compiled
for (auto r: readers)
for (auto r : readers)
delete r;
readers.clear();
@ -66,11 +65,12 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
for (auto curReader : readers)
{
Elf_Half sec_num = curReader->sections.size();
for(int i = 0; i < sec_num; i++)
for (int i = 0; i < sec_num; i++)
{
section* pSec = curReader->sections[i];
if (pSec->get_type() == SHT_REL && std::find(relSections.begin(), relSections.end(), pSec->get_name()) != relSections.end())
if (pSec->get_type() == SHT_REL && std::find(relSections.begin(), relSections.end(),
pSec->get_name()) != relSections.end())
{
SectionType sectionType = GetSectionTypeFromStr(pSec->get_name());
@ -91,16 +91,17 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
string curSymName;
Elf_Half curSymShndx = SHN_UNDEF;
{
symbol_section_accessor symbols(*curReader, curReader->sections[(Elf_Half)pSec->get_link()]);
symbol_section_accessor symbols(
*curReader, curReader->sections[(Elf_Half)pSec->get_link()]);
Elf64_Addr value;
Elf_Xword size;
unsigned char bind;
unsigned char type;
unsigned char other;
symbols.get_symbol(symbol, curSymName, value, size, bind, type, curSymShndx, other);
symbols.get_symbol(symbol, curSymName, value, size, bind, type, curSymShndx,
other);
}
// check symbols outside the elf but within the overlay
if (curSymShndx == SHN_UNDEF)
{
@ -129,7 +130,8 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
unsigned char type;
unsigned char other;
symbols.get_symbol(symIdx, name, value, size, bind, type, shndx, other);
symbols.get_symbol(symIdx, name, value, size, bind, type, shndx,
other);
if (name == curSymName)
{
@ -145,7 +147,8 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
RelocationType typeConverted = (RelocationType)type;
offset += sectionOffs[sectionType];
RelocationEntry* reloc = new RelocationEntry(sectionType, typeConverted, offset);
RelocationEntry* reloc =
new RelocationEntry(sectionType, typeConverted, offset);
// this is to keep the correct reloc entry order
if (sectionType == SectionType::Text)
@ -163,7 +166,8 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
for (int i = 0; i < sec_num; i++)
{
section* pSec = curReader->sections[i];
if (pSec->get_type() == SHT_PROGBITS && std::find(sections.begin(), sections.end(), pSec->get_name()) != sections.end())
if (pSec->get_type() == SHT_PROGBITS &&
std::find(sections.begin(), sections.end(), pSec->get_name()) != sections.end())
{
SectionType sectionType = GetSectionTypeFromStr(pSec->get_name());
sectionOffs[sectionType] += pSec->get_size();
@ -178,7 +182,7 @@ ZOverlay* ZOverlay::FromBuild(string buildPath, string cfgFolderPath)
for (auto reloc : rodataRelocs)
ovl->entries.push_back(reloc);
for (auto r: readers)
for (auto r : readers)
delete r;
readers.clear();
@ -198,7 +202,7 @@ string ZOverlay::GetSourceOutputCode(const std::string& prefix)
output += StringHelper::Sprintf(".word %i\n", entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
RelocationEntry* reloc = entries[i];
output += StringHelper::Sprintf(".word 0x%08X\n", reloc->CalcRelocationWord());
@ -227,7 +231,8 @@ SectionType ZOverlay::GetSectionTypeFromStr(string sectionName)
return SectionType::Text;
else if (sectionName == ".rel.data" || sectionName == ".data")
return SectionType::Data;
else if (sectionName == ".rel.rodata" || sectionName == ".rodata" || sectionName == ".rodata.str1.4" || sectionName == ".rodata.cst4")
else if (sectionName == ".rel.rodata" || sectionName == ".rodata" ||
sectionName == ".rodata.str1.4" || sectionName == ".rodata.cst4")
return SectionType::RoData;
else if (sectionName == ".rel.bss" || sectionName == ".bss")
return SectionType::Bss;

View file

@ -1,8 +1,8 @@
#pragma once
#include "../ZResource.h"
#include <tinyxml2.h>
#include <elfio/elfio.hpp>
#include <tinyxml2.h>
#include "../ZResource.h"
enum SectionType
{
@ -64,5 +64,5 @@ private:
ZOverlay();
static SectionType GetSectionTypeFromStr(std::string sectionName);
//static std::string GetOverlayNameFromElf(ELFIO::elfio& reader);
// static std::string GetOverlayNameFromElf(ELFIO::elfio& reader);
};

View file

@ -1,7 +1,7 @@
#pragma once
#include <string>
#include <iostream>
#include <string>
#include "StringHelper.h"
#if __has_include(<filesystem>)

View file

@ -1,10 +1,10 @@
#pragma once
#include <string>
#include <vector>
#include <numeric>
#include <stdarg.h>
#include <string.h>
#include <string>
#include <vector>
class StringHelper
{
@ -62,7 +62,7 @@ public:
static std::string Sprintf(const char* format, ...)
{
char buffer[32768];
//char buffer[2048];
// char buffer[2048];
std::string output = "";
va_list va;
@ -77,8 +77,7 @@ public:
static std::string Implode(std::vector<std::string>& elements, const char* const separator)
{
return std::accumulate(std::begin(elements), std::end(elements), std::string(),
[separator](std::string& ss, std::string& s)
{
[separator](std::string& ss, std::string& s) {
return ss.empty() ? s : ss + separator + s;
});
}

View file

@ -6,5 +6,10 @@ struct Vec3s
{
int16_t x, y, z;
Vec3s(int16_t nX, int16_t nY, int16_t nZ) { x = nX; y = nY; z = nZ; };
Vec3s(int16_t nX, int16_t nY, int16_t nZ)
{
x = nX;
y = nY;
z = nZ;
};
};

View file

@ -1,11 +1,11 @@
#include "ZAnimation.h"
#include <utility>
#include "ZFile.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "File.h"
#include "HighLevel/HLAnimationIntermediette.h"
#include "Globals.h"
#include "HighLevel/HLAnimationIntermediette.h"
#include "StringHelper.h"
#include "ZFile.h"
using namespace std;
@ -63,16 +63,18 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
string defaultPrefix = name.c_str();
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
string headerStr = StringHelper::Sprintf("{ %i }, %sFrameData, %sJointIndices, %i",
frameCount, defaultPrefix.c_str(), defaultPrefix.c_str(), limit);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "AnimationHeader", StringHelper::Sprintf("%s", name.c_str()), headerStr);
string headerStr =
StringHelper::Sprintf("{ %i }, %sFrameData, %sJointIndices, %i", frameCount,
defaultPrefix.c_str(), defaultPrefix.c_str(), limit);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "AnimationHeader",
StringHelper::Sprintf("%s", name.c_str()), headerStr);
string indicesStr = "";
string valuesStr = " ";
const int lineLength = 14;
const int offset = 0;
for (int i = 0; i < rotationValues.size(); i++)
for (size_t i = 0; i < rotationValues.size(); i++)
{
valuesStr += StringHelper::Sprintf("0x%04X, ", rotationValues[i]);
@ -80,19 +82,25 @@ std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
valuesStr += "\n ";
}
for (int i = 0; i < rotationIndices.size(); i++)
for (size_t i = 0; i < rotationIndices.size(); i++)
{
indicesStr += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x, rotationIndices[i].y, rotationIndices[i].z);
indicesStr +=
StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x,
rotationIndices[i].y, rotationIndices[i].z);
if (i != (rotationIndices.size() - 1))
indicesStr += "\n";
}
parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16, (int)rotationValues.size() * 2, "static s16",
StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()), rotationValues.size(), valuesStr);
parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16,
(int)rotationValues.size() * 2, "static s16",
StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()),
rotationValues.size(), valuesStr);
parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16, (int)rotationIndices.size() * 6, "static JointIndex",
StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()), rotationIndices.size(), indicesStr);
parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16,
(int)rotationIndices.size() * 6, "static JointIndex",
StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()),
rotationIndices.size(), indicesStr);
}
return "";
@ -103,7 +111,9 @@ int ZNormalAnimation::GetRawDataSize()
return 16;
}
ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath)
ZNormalAnimation* ZNormalAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
std::vector<uint8_t> nRawData, int rawDataIndex,
const std::string& nRelPath)
{
ZNormalAnimation* anim = new ZNormalAnimation();
anim->rawData = std::move(nRawData);
@ -127,7 +137,7 @@ void ZNormalAnimation::ParseRawData()
uint32_t currentPtr = rotationValuesSeg;
// Read the Rotation Values
for (int i = 0; i < ((rotationIndicesSeg - rotationValuesSeg) / 2); i++)
for (uint32_t i = 0; i < ((rotationIndicesSeg - rotationValuesSeg) / 2); i++)
{
rotationValues.push_back(BitConverter::ToInt16BE(data, currentPtr));
currentPtr += 2;
@ -136,9 +146,11 @@ void ZNormalAnimation::ParseRawData()
currentPtr = rotationIndicesSeg;
// Read the Rotation Indices
for (int i = 0; i < ((rawDataIndex - rotationIndicesSeg) / 6); i++)
for (uint32_t i = 0; i < ((rawDataIndex - rotationIndicesSeg) / 6); i++)
{
rotationIndices.push_back(RotationIndex(BitConverter::ToInt16BE(data, currentPtr), BitConverter::ToInt16BE(data, currentPtr + 2), BitConverter::ToInt16BE(data, currentPtr + 4)));
rotationIndices.push_back(RotationIndex(BitConverter::ToInt16BE(data, currentPtr),
BitConverter::ToInt16BE(data, currentPtr + 2),
BitConverter::ToInt16BE(data, currentPtr + 4)));
currentPtr += 6;
}
}
@ -152,10 +164,14 @@ 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 = StringHelper::Sprintf("{ %i }, 0x%08X",
frameCount, segmentAddress);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "LinkAnimationHeader", StringHelper::Sprintf("%s", name.c_str()), headerStr);
string segSymbol = segmentAddress == 0 ?
"NULL" :
parent->GetDeclarationName(
segmentAddress, StringHelper::Sprintf("%sSeg%06X", name.c_str(),
segmentAddress));
string headerStr = StringHelper::Sprintf("{ %i }, 0x%08X", frameCount, segmentAddress);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, 16, "LinkAnimationHeader",
StringHelper::Sprintf("%s", name.c_str()), headerStr);
}
return "";
@ -166,7 +182,9 @@ int ZLinkAnimation::GetRawDataSize()
return 8;
}
ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath)
ZLinkAnimation* ZLinkAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
std::vector<uint8_t> nRawData, int rawDataIndex,
const std::string& nRelPath)
{
ZLinkAnimation* anim = new ZLinkAnimation();
anim->rawData = std::move(nRawData);
@ -183,6 +201,318 @@ void ZLinkAnimation::ParseRawData()
const uint8_t* data = rawData.data();
//segmentAddress = GETSEGOFFSET(BitConverter::ToInt32BE(data, rawDataIndex + 4));
// segmentAddress = GETSEGOFFSET(BitConverter::ToInt32BE(data, rawDataIndex + 4));
segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4));
}
/* ZCurveAnimation */
TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData,
uint32_t fileOffset)
: parent(parent)
{
unk_00 = BitConverter::ToUInt16BE(rawData, fileOffset + 0);
unk_02 = BitConverter::ToUInt16BE(rawData, fileOffset + 2);
unk_04 = BitConverter::ToInt16BE(rawData, fileOffset + 4);
unk_06 = BitConverter::ToInt16BE(rawData, fileOffset + 6);
unk_08 = BitConverter::ToFloatBE(rawData, fileOffset + 8);
}
TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData,
uint32_t fileOffset, size_t index)
: TransformData(parent, rawData, fileOffset + index * GetRawDataSize())
{
}
std::string TransformData::GetBody(const std::string& prefix) const
{
return StringHelper::Sprintf("0x%04X, 0x%04X, %i, %i, %ff", unk_00, unk_02, unk_04, unk_06,
unk_08);
}
size_t TransformData::GetRawDataSize()
{
return 0x0C;
}
std::string TransformData::GetSourceTypeName()
{
return "TransformData";
}
ZCurveAnimation::ZCurveAnimation(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
int nRawDataIndex, ZFile* nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
ParseXML(reader);
ParseRawData();
skel = new ZSkeleton(ZSkeletonType::Curve, ZLimbType::Curve, "CurveAnim", nRawData,
Seg2Filespace(skelOffset, parent->baseAddress), nParent);
size_t transformDataSize = 0;
size_t copyValuesSize = 0;
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
for (size_t i = 0; i < 3 * 3 * skel->GetLimbCount(); i++)
{
uint8_t ref = BitConverter::ToUInt8BE(nRawData, refIndexOffset + i);
if (ref == 0)
{
copyValuesSize++;
}
else
{
transformDataSize += ref;
}
refIndexArr.emplace_back(ref);
}
}
if (transformData != 0)
{
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
for (size_t i = 0; i < transformDataSize; i++)
{
transformDataArr.emplace_back(parent, nRawData, transformDataOffset, i);
}
}
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
for (size_t i = 0; i < copyValuesSize; i++)
{
copyValuesArr.emplace_back(BitConverter::ToInt16BE(nRawData, copyValuesOffset + i * 2));
}
}
}
ZCurveAnimation::~ZCurveAnimation()
{
delete skel;
}
void ZCurveAnimation::ParseXML(tinyxml2::XMLElement* reader)
{
ZAnimation::ParseXML(reader);
const char* skelOffsetXml = reader->Attribute("SkelOffset");
if (skelOffsetXml == nullptr)
{
throw std::runtime_error(
"ZCurveAnimation::ParseXML: Fatal error in '%s'. Missing 'SkelOffset' attribute in "
"xml. You need to provide the offset of the curve skeleton.");
}
skelOffset = std::strtoul(skelOffsetXml, nullptr, 0);
}
void ZCurveAnimation::ParseRawData()
{
ZAnimation::ParseRawData();
refIndex = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0);
transformData = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
copyValues = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
unk_0C = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
unk_10 = BitConverter::ToInt16BE(rawData, rawDataIndex + 14);
}
ZCurveAnimation* ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData,
int nRawDataIndex, std::string nRelPath,
ZFile* nParent)
{
ZCurveAnimation* curve = new ZCurveAnimation(reader, nRawData, nRawDataIndex, nParent);
curve->relativePath = std::move(nRelPath);
curve->parent->AddDeclaration(curve->rawDataIndex, DeclarationAlignment::Align16,
curve->GetRawDataSize(), curve->GetSourceTypeName(), curve->name,
"");
return curve;
}
void ZCurveAnimation::PreGenValues(const std::string& prefix)
{
Declaration* decl = parent->GetDeclaration(skelOffset);
if (decl == nullptr)
{
skel->GetSourceOutputCode(prefix);
}
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
string refIndexStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref", refIndexOffset);
string entryStr = " ";
uint16_t arrayItemCnt = refIndexArr.size();
size_t i = 0;
for (auto& child : refIndexArr)
{
entryStr += StringHelper::Sprintf("0x%02X, %s", child, (i++ % 8 == 7) ? "\n " : "");
}
Declaration* decl = parent->GetDeclaration(refIndexOffset);
if (decl == nullptr)
{
parent->AddDeclarationArray(refIndexOffset, DeclarationAlignment::None,
arrayItemCnt * 1, "u8", refIndexStr, arrayItemCnt,
entryStr);
}
else
{
decl->text = entryStr;
}
}
if (transformData != 0)
{
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
string transformDataStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(),
TransformData::GetSourceTypeName().c_str(), transformDataOffset);
string entryStr = "";
uint16_t arrayItemCnt = transformDataArr.size();
size_t i = 0;
for (auto& child : transformDataArr)
{
entryStr += StringHelper::Sprintf(" { %s },%s", child.GetBody(prefix).c_str(),
(++i < arrayItemCnt) ? "\n" : "");
}
Declaration* decl = parent->GetDeclaration(transformDataOffset);
if (decl == nullptr)
{
parent->AddDeclarationArray(transformDataOffset, DeclarationAlignment::None,
arrayItemCnt * TransformData::GetRawDataSize(),
TransformData::GetSourceTypeName(), transformDataStr,
arrayItemCnt, entryStr);
}
else
{
decl->text = entryStr;
}
}
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
string copyValuesStr =
StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy", copyValuesOffset);
string entryStr = " ";
uint16_t arrayItemCnt = copyValuesArr.size();
size_t i = 0;
for (auto& child : copyValuesArr)
{
entryStr += StringHelper::Sprintf("% 6i, %s", child, (i++ % 8 == 7) ? "\n " : "");
}
Declaration* decl = parent->GetDeclaration(copyValuesOffset);
if (decl == nullptr)
{
parent->AddDeclarationArray(copyValuesOffset, DeclarationAlignment::None,
arrayItemCnt * 2, "s16", copyValuesStr, arrayItemCnt,
entryStr);
}
else
{
decl->text = entryStr;
}
}
}
int ZCurveAnimation::GetRawDataSize()
{
return 0x10;
}
std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
{
string bodyStr = "";
uint32_t address = Seg2Filespace(rawDataIndex, parent->baseAddress);
PreGenValues(prefix);
string refIndexStr = "NULL";
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(refIndexOffset);
if (decl == nullptr)
{
refIndexStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref",
refIndexOffset);
}
else
{
refIndexStr = decl->varName;
}
}
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);
}
else
{
transformDataStr = decl->varName;
}
}
string copyValuesStr = "NULL";
if (copyValues != 0)
{
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(copyValuesOffset);
if (decl == nullptr)
{
copyValuesStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy",
copyValuesOffset);
}
else
{
copyValuesStr = decl->varName;
}
}
bodyStr =
StringHelper::Sprintf("\n %s,\n %s,\n %s,\n %i, %i\n", refIndexStr.c_str(),
transformDataStr.c_str(), copyValuesStr.c_str(), unk_0C, unk_10);
Declaration* decl = parent->GetDeclaration(address);
if (decl == nullptr)
{
parent->AddDeclaration(address, DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), name, bodyStr);
}
else
{
decl->text = bodyStr;
}
return "";
}
std::string ZCurveAnimation::GetSourceTypeName()
{
return "TransformUpdateIndex";
}

View file

@ -1,35 +1,40 @@
#pragma once
#include <vector>
#include <string>
#include <stdint.h>
#include "ZResource.h"
#include <string>
#include <vector>
#include "Vec3s.h"
#include "ZResource.h"
#include "ZSkeleton.h"
#include "tinyxml2.h"
struct RotationIndex
{
//uint16_t transX, transY, transZ;
// uint16_t transX, transY, transZ;
uint16_t x, y, z;
RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) { x = nX; y = nY; z = nZ; };
RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ)
{
x = nX;
y = nY;
z = nZ;
};
};
class ZAnimation : public ZResource
{
public:
int16_t frameCount;
ZAnimation();
std::string GetSourceOutputCode(const std::string& prefix) override;
ZResourceType GetResourceType() override;
protected:
virtual void ParseRawData();
void Save(const std::string& outFolder);
void ParseXML(tinyxml2::XMLElement* reader);
protected:
virtual void ParseRawData() override;
void Save(const std::string& outFolder) override;
void ParseXML(tinyxml2::XMLElement* reader) override;
};
class ZNormalAnimation : public ZAnimation
@ -43,13 +48,15 @@ public:
ZNormalAnimation();
std::string GetSourceOutputCode(const std::string& prefix);
std::string GetSourceOutputCode(const std::string& prefix) override;
int GetRawDataSize() override;
static ZNormalAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath);
static ZNormalAnimation* ExtractFromXML(tinyxml2::XMLElement* reader,
std::vector<uint8_t> nRawData, int rawDataIndex,
const std::string& nRelPath);
protected:
virtual void ParseRawData();
virtual void ParseRawData() override;
};
class ZLinkAnimation : public ZAnimation
@ -59,11 +66,82 @@ public:
ZLinkAnimation();
std::string GetSourceOutputCode(const std::string& prefix);
std::string GetSourceOutputCode(const std::string& prefix) override;
int GetRawDataSize() override;
static ZLinkAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath);
static ZLinkAnimation* ExtractFromXML(tinyxml2::XMLElement* reader,
std::vector<uint8_t> nRawData, int rawDataIndex,
const std::string& nRelPath);
protected:
virtual void ParseRawData();
virtual void ParseRawData() override;
};
class TransformData
{
protected:
ZFile* parent;
///* 0x0000 */ u16 unk_00; // appears to be flags
uint16_t unk_00;
///* 0x0002 */ s16 unk_02;
int16_t unk_02;
///* 0x0004 */ s16 unk_04;
int16_t unk_04;
///* 0x0006 */ s16 unk_06;
int16_t unk_06;
///* 0x0008 */ f32 unk_08;
float unk_08;
public:
TransformData() = default;
TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset);
TransformData(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index);
[[nodiscard]] std::string GetBody(const std::string& prefix) const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
};
class ZCurveAnimation : public ZAnimation
{
protected:
segptr_t skelOffset = 0;
///* 0x0000 */ u8* refIndex;
segptr_t refIndex = 0;
///* 0x0004 */ TransformData* transformData;
segptr_t transformData = 0;
///* 0x0008 */ s16* copyValues;
segptr_t copyValues = 0;
///* 0x000C */ s16 unk_0C;
int16_t unk_0C;
///* 0x000E */ s16 unk_10;
int16_t unk_10;
ZSkeleton* skel;
std::vector<uint8_t> refIndexArr;
std::vector<TransformData> transformDataArr;
std::vector<int16_t> copyValuesArr;
public:
ZCurveAnimation() = default;
ZCurveAnimation(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
int nRawDataIndex, ZFile* nParent);
~ZCurveAnimation();
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
static ZCurveAnimation* ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData, int nRawDataIndex,
std::string nRelPath, ZFile* nParent);
void PreGenValues(const std::string& prefix);
int GetRawDataSize() override;
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceTypeName() override;
};
// TransformUpdateIndex

View file

@ -1,11 +1,10 @@
#include "ZArray.h"
#include "ZFile.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
ZArray::ZArray()
{
}
void ZArray::ParseXML(tinyxml2::XMLElement* reader)
@ -13,7 +12,8 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader)
ZResource::ParseXML(reader);
arrayCnt = reader->IntAttribute("Count", 0);
testFile = new ZFile(ZFileMode::Extract, reader, Globals::Instance->baseRomPath, "", parent->GetName(), true);
testFile = new ZFile(ZFileMode::Extract, reader, Globals::Instance->baseRomPath, "",
parent->GetName(), true);
}
// TODO: This is a bit hacky, but until we refactor how ZFile parses the XML, it'll have to do.
@ -31,7 +31,9 @@ std::string ZArray::GetSourceOutputCode(const std::string& prefix)
if (!res->DoesSupportArray())
{
throw StringHelper::Sprintf("Error! Resource %s does not support being wrapped in an array!\n", res->GetName().c_str());
throw std::runtime_error(StringHelper::Sprintf(
"Error! Resource %s does not support being wrapped in an array!\n",
res->GetName().c_str()));
}
for (int i = 0; i < arrayCnt; i++)
@ -40,17 +42,16 @@ std::string ZArray::GetSourceOutputCode(const std::string& prefix)
res->SetRawDataIndex(childIndex);
res->ParseRawData();
std::string test = res->GetSourceOutputCode("");
//output += " { " + testFile->declarations[childIndex]->text + " }";
// output += " { " + testFile->declarations[childIndex]->text + " }";
output += testFile->declarations[childIndex]->text;
if (i < arrayCnt - 1)
output += ",\n";
int bp = 0;
}
if (parent != nullptr)
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), res->GetSourceTypeName(), name, arrayCnt, output);
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
res->GetSourceTypeName(), name, arrayCnt, output);
return "";
}
@ -60,14 +61,15 @@ int ZArray::GetRawDataSize()
return arrayCnt * testFile->resources[0]->GetRawDataSize();
}
ZArray* ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath, ZFile* nParent)
ZArray* ZArray::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const int rawDataIndex, const std::string& nRelPath, ZFile* nParent)
{
ZArray* arr = new ZArray();
arr->rawData = nRawData;
arr->rawDataIndex = rawDataIndex;
arr->parent = nParent;
arr->ParseXML(reader);
//arr->ParseRawData();
// arr->ParseRawData();
return arr;
}

View file

@ -1,8 +1,8 @@
#pragma once
#include <vector>
#include <string>
#include <stdint.h>
#include <string>
#include <vector>
#include "ZResource.h"
#include "tinyxml2.h"
@ -15,11 +15,13 @@ public:
std::string GetSourceOutputCode(const std::string& prefix) override;
int GetRawDataSize() override;
static ZArray* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath, ZFile* nParent);
static ZArray* ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData, const int rawDataIndex,
const std::string& nRelPath, ZFile* nParent);
protected:
int arrayCnt;
ZFile* testFile;
//void ParseRawData(const std::vector<uint8_t>& data, const int offset);
// void ParseRawData(const std::vector<uint8_t>& data, const int offset);
};

View file

@ -1,26 +1,28 @@
#include "ZBlob.h"
#include "File.h"
#include "ZFile.h"
#include "BitConverter.h"
#include "File.h"
#include "Path.h"
#include "StringHelper.h"
#include "ZFile.h"
using namespace tinyxml2;
using namespace std;
ZBlob::ZBlob() : ZResource()
{
}
ZBlob::ZBlob(const std::vector<uint8_t>& nRawData, int nRawDataIndex, int size, std::string nName) : ZBlob()
ZBlob::ZBlob(const std::vector<uint8_t>& nRawData, int nRawDataIndex, int size, std::string nName)
: ZBlob()
{
rawDataIndex = nRawDataIndex;
rawData = vector<uint8_t>(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size);
rawData =
vector<uint8_t>(nRawData.data() + rawDataIndex, nRawData.data() + rawDataIndex + size);
name = std::move(nName);
}
ZBlob* ZBlob::ExtractFromXML(XMLElement* reader, const vector<uint8_t>& nRawData, int nRawDataIndex, string nRelPath)
ZBlob* ZBlob::ExtractFromXML(XMLElement* reader, const vector<uint8_t>& nRawData, int nRawDataIndex,
string nRelPath)
{
ZBlob* blob = new ZBlob();
@ -28,7 +30,8 @@ ZBlob* ZBlob::ExtractFromXML(XMLElement* reader, const vector<uint8_t>& nRawData
blob->ParseXML(reader);
int size = strtol(reader->Attribute("Size"), NULL, 16);
blob->rawData = vector<uint8_t>(nRawData.data() + blob->rawDataIndex, nRawData.data() + blob->rawDataIndex + size);
blob->rawData = vector<uint8_t>(nRawData.data() + blob->rawDataIndex,
nRawData.data() + blob->rawDataIndex + size);
blob->relativePath = std::move(nRelPath);
return blob;
@ -48,7 +51,6 @@ ZBlob* ZBlob::BuildFromXML(XMLElement* reader, const std::string& inFolder, bool
ZBlob* ZBlob::FromFile(const std::string& filePath)
{
int comp;
ZBlob* blob = new ZBlob();
blob->name = StringHelper::Split(Path::GetFileNameWithoutExtension(filePath), ".")[0];
blob->rawData = File::ReadAllBytes(filePath);
@ -59,9 +61,9 @@ ZBlob* ZBlob::FromFile(const std::string& filePath)
string ZBlob::GetSourceOutputCode(const std::string& prefix)
{
sourceOutput = "";
//sourceOutput += StringHelper::Sprintf("u8 %s_%s[] = \n{\n", prefix.c_str(), name.c_str());
// sourceOutput += StringHelper::Sprintf("u8 %s_%s[] = \n{\n", prefix.c_str(), name.c_str());
for (int i = 0; i < rawData.size(); i += 1)
for (uint32_t i = 0; i < rawData.size(); i += 1)
{
if (i % 16 == 0)
sourceOutput += "\t";
@ -72,7 +74,10 @@ string ZBlob::GetSourceOutputCode(const std::string& prefix)
sourceOutput += "\n";
}
//sourceOutput += "};\n";
// Ensure there's always a trailing line feed to prevent dumb warnings.
sourceOutput += "\n";
// sourceOutput += "};\n";
return sourceOutput;
}
@ -84,7 +89,7 @@ string ZBlob::GetSourceOutputHeader(const std::string& prefix)
void ZBlob::Save(const std::string& outFolder)
{
//printf("NAME = %s\n", name.c_str());
// printf("NAME = %s\n", name.c_str());
File::WriteAllBytes(outFolder + "/" + name + ".bin", rawData);
}

View file

@ -8,8 +8,10 @@ class ZBlob : public ZResource
public:
ZBlob(const std::vector<uint8_t>& nRawData, int rawDataIndex, int size, std::string nName);
static ZBlob* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int rawDataIndex, std::string nRelPath);
static ZBlob* BuildFromXML(tinyxml2::XMLElement* reader, const std::string& inFolder, bool readFile);
static ZBlob* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
int rawDataIndex, std::string nRelPath);
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;

View file

@ -1,18 +1,18 @@
#include "ZCollision.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "Globals.h"
#include <stdint.h>
#include <string>
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
using namespace std;
ZCollisionHeader::ZCollisionHeader()
{
}
ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData, int rawDataIndex)
ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix,
const std::vector<uint8_t>& rawData, int rawDataIndex)
{
const uint8_t* data = rawData.data();
@ -42,14 +42,14 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con
uint32_t waterBoxSegmentOffset = Seg2Filespace(waterBoxAddress, parent->baseAddress);
// HOTSPOT
for (int i = 0; i < numVerts; i++)
for (uint16_t i = 0; i < numVerts; i++)
vertices.push_back(new VertexEntry(rawData, vtxSegmentOffset + (i * 6)));
// HOTSPOT
for (int i = 0; i < numPolygons; i++)
for (uint16_t i = 0; i < numPolygons; i++)
polygons.push_back(new PolygonEntry(rawData, polySegmentOffset + (i * 16)));
int highestPolyType = 0;
uint16_t highestPolyType = 0;
for (PolygonEntry* poly : polygons)
{
@ -57,70 +57,89 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con
highestPolyType = poly->type;
}
//if (highestPolyType > 0)
// if (highestPolyType > 0)
{
for (int i = 0; i < highestPolyType + 1; i++)
polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8)));
for (uint16_t i = 0; i < highestPolyType + 1; i++)
polygonTypes.push_back(
BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8)));
}
//else
// else
//{
//int polyTypesSize = abs(polyTypeDefSegmentOffset - camDataSegmentOffset) / 8;
// int polyTypesSize = abs(polyTypeDefSegmentOffset - camDataSegmentOffset) / 8;
//for (int i = 0; i < polyTypesSize; i++)
//polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8)));
// for (int i = 0; i < polyTypesSize; i++)
// polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8)));
//}
if (camDataAddress != 0)
camData = new CameraDataList(parent, prefix, rawData, camDataSegmentOffset, polyTypeDefSegmentOffset, polygonTypes.size());
camData = new CameraDataList(parent, prefix, rawData, camDataSegmentOffset,
polyTypeDefSegmentOffset, polygonTypes.size());
for (int i = 0; i < numWaterBoxes; i++)
waterBoxes.push_back(new WaterBoxHeader(rawData, waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16))));
waterBoxes.push_back(new WaterBoxHeader(
rawData,
waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16))));
string declaration = "";
char line[2048];
if (waterBoxes.size() > 0)
{
for (int i = 0; i < waterBoxes.size(); i++)
for (size_t i = 0; i < waterBoxes.size(); i++)
{
sprintf(line, " { %i, %i, %i, %i, %i, 0x%08X },\n", waterBoxes[i]->xMin, waterBoxes[i]->ySurface, waterBoxes[i]->zMin, waterBoxes[i]->xLength, waterBoxes[i]->zLength, waterBoxes[i]->properties);
sprintf(line, " { %i, %i, %i, %i, %i, 0x%08X },\n", waterBoxes[i]->xMin,
waterBoxes[i]->ySurface, waterBoxes[i]->zMin, waterBoxes[i]->xLength,
waterBoxes[i]->zLength, waterBoxes[i]->properties);
declaration += line;
}
}
if (waterBoxAddress != 0)
parent->AddDeclarationArray(waterBoxSegmentOffset, DeclarationAlignment::None, 16 * waterBoxes.size(), "WaterBox",
StringHelper::Sprintf("%s_waterBoxes_%08X", prefix.c_str(), waterBoxSegmentOffset), 0, declaration);
parent->AddDeclarationArray(
waterBoxSegmentOffset, DeclarationAlignment::None, 16 * waterBoxes.size(), "WaterBox",
StringHelper::Sprintf("%s_waterBoxes_%08X", prefix.c_str(), waterBoxSegmentOffset), 0,
declaration);
if (polygons.size() > 0)
{
declaration = "";
for (int i = 0; i < polygons.size(); i++)
for (size_t i = 0; i < polygons.size(); i++)
{
sprintf(line, " { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },\n",
(uint16_t)polygons[i]->type, (uint16_t)polygons[i]->vtxA, (uint16_t)polygons[i]->vtxB, (uint16_t)polygons[i]->vtxC,
(uint16_t)polygons[i]->a, (uint16_t)polygons[i]->b, (uint16_t)polygons[i]->c, (uint16_t)polygons[i]->d);
sprintf(
line, " { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X },\n",
(uint16_t)polygons[i]->type, (uint16_t)polygons[i]->vtxA,
(uint16_t)polygons[i]->vtxB, (uint16_t)polygons[i]->vtxC, (uint16_t)polygons[i]->a,
(uint16_t)polygons[i]->b, (uint16_t)polygons[i]->c, (uint16_t)polygons[i]->d);
declaration += line;
}
if (polyAddress != 0) {
parent->AddDeclarationArray(polySegmentOffset, DeclarationAlignment::None, polygons.size() * 16, "CollisionPoly", StringHelper::Sprintf("%s_polygons_%08X", prefix.c_str(), polySegmentOffset), 0, declaration);
if (polyAddress != 0)
{
parent->AddDeclarationArray(
polySegmentOffset, DeclarationAlignment::None, polygons.size() * 16,
"CollisionPoly",
StringHelper::Sprintf("%s_polygons_%08X", prefix.c_str(), polySegmentOffset), 0,
declaration);
}
}
declaration = "";
for (int i = 0; i < polygonTypes.size(); i++)
for (size_t i = 0; i < polygonTypes.size(); i++)
{
declaration += StringHelper::Sprintf(" { 0x%08lX, 0x%08lX },", polygonTypes[i] >> 32, polygonTypes[i] & 0xFFFFFFFF);
declaration += StringHelper::Sprintf(" { 0x%08lX, 0x%08lX },", polygonTypes[i] >> 32,
polygonTypes[i] & 0xFFFFFFFF);
if (i < polygonTypes.size() - 1)
declaration += "\n";
}
if (polyTypeDefAddress != 0)
parent->AddDeclarationArray(polyTypeDefSegmentOffset, DeclarationAlignment::None, polygonTypes.size() * 8,
"SurfaceType", StringHelper::Sprintf("%s_surfaceType_%08X", prefix.c_str(), polyTypeDefSegmentOffset), 0, declaration);
parent->AddDeclarationArray(
polyTypeDefSegmentOffset, DeclarationAlignment::None, polygonTypes.size() * 8,
"SurfaceType",
StringHelper::Sprintf("%s_surfaceType_%08X", prefix.c_str(), polyTypeDefSegmentOffset),
0, declaration);
declaration = "";
@ -128,17 +147,20 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con
{
declaration = "";
for (int i = 0; i < vertices.size(); i++)
for (size_t i = 0; i < vertices.size(); i++)
{
declaration += StringHelper::Sprintf(" { %i, %i, %i },", vertices[i]->x, vertices[i]->y, vertices[i]->z);
declaration += StringHelper::Sprintf(" { %i, %i, %i },", vertices[i]->x,
vertices[i]->y, vertices[i]->z);
if (i < vertices.size() - 1)
declaration += "\n";
}
if (vtxAddress != 0)
parent->AddDeclarationArray(vtxSegmentOffset, DeclarationAlignment::None, vertices.size() * 6,
"Vec3s", StringHelper::Sprintf("%s_vtx_%08X", prefix.c_str(), vtxSegmentOffset), 0, declaration);
parent->AddDeclarationArray(
vtxSegmentOffset, DeclarationAlignment::None, vertices.size() * 6, "Vec3s",
StringHelper::Sprintf("%s_vtx_%08X", prefix.c_str(), vtxSegmentOffset), 0,
declaration);
declaration = "";
}
@ -153,16 +175,18 @@ ZCollisionHeader::ZCollisionHeader(ZFile* parent, const std::string& prefix, con
declaration += "\n";
declaration += StringHelper::Sprintf(" { %i, %i, %i },\n { %i, %i, %i },\n",
absMinX, absMinY, absMinZ,
absMaxX, absMaxY, absMaxZ);
declaration += StringHelper::Sprintf(" { %i, %i, %i },\n { %i, %i, %i },\n", absMinX,
absMinY, absMinZ, absMaxX, absMaxY, absMaxZ);
declaration += StringHelper::Sprintf(" %i,\n %s_vtx_%08X,\n %i,\n %s_polygons_%08X,\n %s_surfaceType_%08X,\n &%s_camDataList_%08X,\n %i,\n %s\n",
numVerts, prefix.c_str(), vtxSegmentOffset, numPolygons,
prefix.c_str(), polySegmentOffset, prefix.c_str(), polyTypeDefSegmentOffset,
prefix.c_str(), camDataSegmentOffset, numWaterBoxes, waterBoxStr);
declaration += StringHelper::Sprintf(
" %i,\n %s_vtx_%08X,\n %i,\n %s_polygons_%08X,\n %s_surfaceType_%08X,\n "
"%s_camDataList_%08X,\n %i,\n %s\n",
numVerts, prefix.c_str(), vtxSegmentOffset, numPolygons, prefix.c_str(), polySegmentOffset,
prefix.c_str(), polyTypeDefSegmentOffset, prefix.c_str(), camDataSegmentOffset,
numWaterBoxes, waterBoxStr);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, DeclarationPadding::Pad16, 44, "CollisionHeader",
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, DeclarationPadding::Pad16, 44,
"CollisionHeader",
StringHelper::Sprintf("%s", prefix.c_str(), rawDataIndex), declaration);
}
@ -183,12 +207,11 @@ ZResourceType ZCollisionHeader::GetResourceType()
return ZResourceType::CollisionHeader;
}
ZCollisionHeader* ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader, vector<uint8_t> nRawData, int rawDataIndex)
ZCollisionHeader* ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader,
vector<uint8_t> nRawData, int rawDataIndex)
{
ZCollisionHeader* col = new ZCollisionHeader();
return col;
}
@ -234,21 +257,25 @@ WaterBoxHeader::WaterBoxHeader(const std::vector<uint8_t>& rawData, int rawDataI
}
}
CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData, int rawDataIndex, int polyTypeDefSegmentOffset, int polygonTypesCnt)
CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
const std::vector<uint8_t>& rawData, int rawDataIndex,
int polyTypeDefSegmentOffset, int polygonTypesCnt)
{
string declaration = "";
// Parse CameraDataEntries
int numElements = abs(polyTypeDefSegmentOffset - (rawDataIndex)) / 8;
//int numElements = polygonTypesCnt;
// int numElements = polygonTypesCnt;
uint32_t cameraPosDataSeg = rawDataIndex;
for (int i = 0; i < numElements; i++)
{
CameraDataEntry* entry = new CameraDataEntry();
entry->cameraSType = BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 0);
entry->cameraSType =
BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 0);
entry->numData = BitConverter::ToInt16BE(rawData, rawDataIndex + (entries.size() * 8) + 2);
entry->cameraPosDataSeg = BitConverter::ToInt32BE(rawData, rawDataIndex + (entries.size() * 8) + 4);
entry->cameraPosDataSeg =
BitConverter::ToInt32BE(rawData, rawDataIndex + (entries.size() * 8) + 4);
if (entry->cameraPosDataSeg != 0 && GETSEGNUM(entry->cameraPosDataSeg) != 2)
{
@ -262,27 +289,33 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const s
entries.push_back(entry);
}
//setting cameraPosDataAddr to rawDataIndex give a pos list length of 0
// setting cameraPosDataAddr to rawDataIndex give a pos list length of 0
uint32_t cameraPosDataOffset = cameraPosDataSeg & 0xFFFFFF;
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
char camSegLine[2048];
if (entries[i]->cameraPosDataSeg != 0)
{
int index = ((entries[i]->cameraPosDataSeg & 0x00FFFFFF) - cameraPosDataOffset) / 0x6;
sprintf(camSegLine, "&%s_camPosData_%08X[%i]", prefix.c_str(), cameraPosDataOffset, index);
sprintf(camSegLine, "&%s_camPosData_%08X[%i]", prefix.c_str(), cameraPosDataOffset,
index);
}
else
sprintf(camSegLine, "0x%08X", entries[i]->cameraPosDataSeg);
declaration += StringHelper::Sprintf(" { 0x%04X, %i, %s },", entries[i]->cameraSType, entries[i]->numData, camSegLine, rawDataIndex + (i * 8));
declaration +=
StringHelper::Sprintf(" { 0x%04X, %i, %s },", entries[i]->cameraSType,
entries[i]->numData, camSegLine, rawDataIndex + (i * 8));
if (i < entries.size() - 1)
declaration += "\n";
}
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, entries.size() * 8, "CamData", StringHelper::Sprintf("%s_camDataList_%08X", prefix.c_str(), rawDataIndex), entries.size(), declaration);
parent->AddDeclarationArray(
rawDataIndex, DeclarationAlignment::None, entries.size() * 8, "CamData",
StringHelper::Sprintf("%s_camDataList_%08X", prefix.c_str(), rawDataIndex), entries.size(),
declaration);
int numDataTotal = abs(rawDataIndex - (int)cameraPosDataOffset) / 0x6;
@ -291,15 +324,20 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix, const s
declaration = "";
for (int i = 0; i < numDataTotal; i++)
{
CameraPositionData* data = new CameraPositionData(rawData, cameraPosDataOffset + (i * 6));
CameraPositionData* data =
new CameraPositionData(rawData, cameraPosDataOffset + (i * 6));
cameraPositionData.push_back(data);
declaration += StringHelper::Sprintf(" { %6i, %6i, %6i },\n", data->x, data->y, data->z);
declaration +=
StringHelper::Sprintf(" { %6i, %6i, %6i },\n", data->x, data->y, data->z);
}
int cameraPosDataIndex = cameraPosDataSeg & 0x00FFFFFF;
int entrySize = numDataTotal * 0x6;
parent->AddDeclarationArray(cameraPosDataIndex, DeclarationAlignment::None, entrySize, "Vec3s", StringHelper::Sprintf("%s_camPosData_%08X", prefix.c_str(), cameraPosDataIndex), numDataTotal, declaration);
parent->AddDeclarationArray(
cameraPosDataIndex, DeclarationAlignment::None, entrySize, "Vec3s",
StringHelper::Sprintf("%s_camPosData_%08X", prefix.c_str(), cameraPosDataIndex),
numDataTotal, declaration);
}
}

View file

@ -1,7 +1,7 @@
#pragma once
#include "ZResource.h"
#include "ZFile.h"
#include "ZResource.h"
#include "ZRoom/ZRoom.h"
class PolygonEntry
@ -58,7 +58,8 @@ public:
std::vector<CameraDataEntry*> entries;
std::vector<CameraPositionData*> cameraPositionData;
CameraDataList(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData, int rawDataIndex, int polyTypeDefSegmentOffset, int polygonTypesCnt);
CameraDataList(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData,
int rawDataIndex, int polyTypeDefSegmentOffset, int polygonTypesCnt);
};
class ZCollisionHeader : public ZResource
@ -66,9 +67,9 @@ class ZCollisionHeader : public ZResource
public:
int16_t absMinX, absMinY, absMinZ;
int16_t absMaxX, absMaxY, absMaxZ;
int16_t numVerts;
uint16_t numVerts;
segptr_t vtxAddress;
int16_t numPolygons;
uint16_t numPolygons;
segptr_t polyAddress;
segptr_t polyTypeDefAddress;
segptr_t camDataAddress;
@ -83,11 +84,13 @@ public:
CameraDataList* camData;
ZCollisionHeader();
//ZCollisionHeader(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex);
ZCollisionHeader(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData, int rawDataIndex);
// ZCollisionHeader(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex);
ZCollisionHeader(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData,
int rawDataIndex);
~ZCollisionHeader();
ZResourceType GetResourceType() override;
static ZCollisionHeader* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex);
static ZCollisionHeader* ExtractFromXML(tinyxml2::XMLElement* reader,
std::vector<uint8_t> nRawData, int rawDataIndex);
};

View file

@ -27,7 +27,9 @@ ZCutscene::ZCutscene(std::vector<uint8_t> nRawData, int rawDataIndex, int rawDat
int numEntries = 1;
/*if (cmdID != CutsceneCommands::SetCameraPos && cmdID != CutsceneCommands::SetCameraFocus && cmdID != CutsceneCommands::SetCameraFocusLink && cmdID != CutsceneCommands::SetCameraPosLink)
/*if (cmdID != CutsceneCommands::SetCameraPos && cmdID != CutsceneCommands::SetCameraFocus
&& cmdID != CutsceneCommands::SetCameraFocusLink && cmdID !=
CutsceneCommands::SetCameraPosLink)
{
numEntries = BitConverter::ToInt32BE(rawData, currentPtr);
currentPtr += 4;
@ -39,15 +41,39 @@ ZCutscene::ZCutscene(std::vector<uint8_t> nRawData, int rawDataIndex, int rawDat
switch (cmdID)
{
case CutsceneCommands::SetCameraPos: cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); break;
case CutsceneCommands::SetCameraFocus: cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); break;
case CutsceneCommands::SpecialAction: cmd = new CutsceneCommandSpecialAction(rawData, currentPtr); break;
case CutsceneCommands::SetLighting: cmd = new CutsceneCommandEnvLighting(rawData, currentPtr); break;
case CutsceneCommands::SetCameraPosLink: cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); break;
case CutsceneCommands::SetCameraFocusLink: cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr); break;
case CutsceneCommands::Textbox: cmd = new CutsceneCommandTextbox(rawData, currentPtr); break;
case CutsceneCommands::Cmd09: cmd = new CutsceneCommandUnknown9(rawData, currentPtr); break;
case CutsceneCommands::Unknown: cmd = new CutsceneCommandUnknown(rawData, currentPtr); break;
case CutsceneCommands::Cmd00:
break;
case CutsceneCommands::SetCameraPos:
cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr);
break;
case CutsceneCommands::SetCameraFocus:
cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr);
break;
case CutsceneCommands::SpecialAction:
cmd = new CutsceneCommandSpecialAction(rawData, currentPtr);
break;
case CutsceneCommands::SetLighting:
cmd = new CutsceneCommandEnvLighting(rawData, currentPtr);
break;
case CutsceneCommands::SetCameraPosLink:
cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr);
break;
case CutsceneCommands::SetCameraFocusLink:
cmd = new CutsceneCommandSetCameraPos(rawData, currentPtr);
break;
case CutsceneCommands::Cmd07:
break;
case CutsceneCommands::Cmd08:
break;
case CutsceneCommands::Cmd09:
cmd = new CutsceneCommandUnknown9(rawData, currentPtr);
break;
case CutsceneCommands::Textbox:
cmd = new CutsceneCommandTextbox(rawData, currentPtr);
break;
case CutsceneCommands::Unknown:
cmd = new CutsceneCommandUnknown(rawData, currentPtr);
break;
case CutsceneCommands::SetActorAction0:
case CutsceneCommands::SetActorAction1:
case CutsceneCommands::SetActorAction2:
@ -58,15 +84,37 @@ ZCutscene::ZCutscene(std::vector<uint8_t> nRawData, int rawDataIndex, int rawDat
case CutsceneCommands::SetActorAction7:
case CutsceneCommands::SetActorAction8:
case CutsceneCommands::SetActorAction9:
case CutsceneCommands::SetActorAction10: cmd = new CutsceneCommandActorAction(rawData, currentPtr); break;
case CutsceneCommands::SetSceneTransFX: cmd = new CutsceneCommandSceneTransFX(rawData, currentPtr); break;
case CutsceneCommands::Nop: cmd = new CutsceneCommandNop(rawData, currentPtr); break;
case CutsceneCommands::PlayBGM: cmd = new CutsceneCommandPlayBGM(rawData, currentPtr); break;
case CutsceneCommands::StopBGM: cmd = new CutsceneCommandStopBGM(rawData, currentPtr); break;
case CutsceneCommands::FadeBGM: cmd = new CutsceneCommandFadeBGM(rawData, currentPtr); break;
case CutsceneCommands::SetTime: cmd = new CutsceneCommandDayTime(rawData, currentPtr); break;
case CutsceneCommands::Terminator: cmd = new CutsceneCommandTerminator(rawData, currentPtr); break;
case CutsceneCommands::End: cmd = new CutsceneCommandEnd(rawData, currentPtr); break;
case CutsceneCommands::SetActorAction10:
cmd = new CutsceneCommandActorAction(rawData, currentPtr);
break;
case CutsceneCommands::SetSceneTransFX:
cmd = new CutsceneCommandSceneTransFX(rawData, currentPtr);
break;
case CutsceneCommands::Nop:
cmd = new CutsceneCommandNop(rawData, currentPtr);
break;
case CutsceneCommands::PlayBGM:
cmd = new CutsceneCommandPlayBGM(rawData, currentPtr);
break;
case CutsceneCommands::StopBGM:
cmd = new CutsceneCommandStopBGM(rawData, currentPtr);
break;
case CutsceneCommands::FadeBGM:
cmd = new CutsceneCommandFadeBGM(rawData, currentPtr);
break;
case CutsceneCommands::SetTime:
cmd = new CutsceneCommandDayTime(rawData, currentPtr);
break;
case CutsceneCommands::Terminator:
cmd = new CutsceneCommandTerminator(rawData, currentPtr);
break;
case CutsceneCommands::End:
cmd = new CutsceneCommandEnd(rawData, currentPtr);
break;
case CutsceneCommands::Error:
fprintf(stderr, "Cutscene command error %d %s %d\n", (int)cmdID, __FILE__,
__LINE__);
break;
}
cmd->commandIndex = i;
@ -87,18 +135,18 @@ ZCutscene::~ZCutscene()
string ZCutscene::GetSourceOutputCode(const std::string& prefix)
{
string output = "";
int size = 0;
size_t size = 0;
int32_t curPtr = 0;
//output += StringHelper::Sprintf("// SIZE = 0x%04X\n", GetRawDataSize());
// output += StringHelper::Sprintf("// SIZE = 0x%04X\n", GetRawDataSize());
output += StringHelper::Sprintf("\tCS_BEGIN_CUTSCENE(%i, %i),\n", commands.size(), endFrame);
for (int i = 0; i < commands.size(); i++)
for (size_t i = 0; i < commands.size(); i++)
{
CutsceneCommand* cmd = commands[i];
output += "\t" + cmd->GenerateSourceCode(prefix, curPtr);
curPtr += (uint32_t)cmd->GetCommandSize();
size += (int)cmd->GetCommandSize();
size += cmd->GetCommandSize();
}
output += StringHelper::Sprintf("\tCS_END(),\n", commands.size(), endFrame);
@ -113,7 +161,7 @@ int ZCutscene::GetRawDataSize()
// Beginning
size += 8;
for (int i = 0; i < commands.size(); i++)
for (size_t i = 0; i < commands.size(); i++)
{
CutsceneCommand* cmd = commands[i];
size += (int)cmd->GetCommandSize();
@ -126,7 +174,9 @@ int ZCutscene::GetRawDataSize()
return size;
}
ZCutscene* ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath)
ZCutscene* ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData, const int rawDataIndex,
const std::string& nRelPath)
{
ZCutscene* cs = new ZCutscene(nRawData, rawDataIndex, 9999);
cs->rawData = nRawData;
@ -145,35 +195,165 @@ CutsceneCommands ZCutscene::GetCommandFromID(int id)
{
switch (id)
{
case 0x0003: return CutsceneCommands::SpecialAction;
case 0x0004: return CutsceneCommands::SetLighting;
case 0x0056: return CutsceneCommands::PlayBGM;
case 0x0057: return CutsceneCommands::StopBGM;
case 0x007C: return CutsceneCommands::FadeBGM;
case 0x0009: return CutsceneCommands::Cmd09;
case 0x0013: return CutsceneCommands::Textbox;
case 0x008C: return CutsceneCommands::SetTime;
case 0x0001: return CutsceneCommands::SetCameraPos;
case 0x0002: return CutsceneCommands::SetCameraFocus;
case 0x0005: return CutsceneCommands::SetCameraPosLink;
case 0x0006: return CutsceneCommands::SetCameraFocusLink;
case 0x0007: return CutsceneCommands::Cmd07;
case 0x0008: return CutsceneCommands::Cmd08;
case 0x03E8: return CutsceneCommands::Terminator;
case 0xFFFF: return CutsceneCommands::End;
case 0x002D: return CutsceneCommands::SetSceneTransFX;
case 10: return CutsceneCommands::SetActorAction0;
case 15: case 17: case 18: case 23: case 34: case 39: case 46: case 76: case 85: case 93: case 105: case 107: case 110: case 119: case 123: case 138: case 139: case 144: return CutsceneCommands::SetActorAction1;
case 14: case 16: case 24: case 35: case 40: case 48: case 64: case 68: case 70: case 78: case 80: case 94: case 116: case 118: case 120: case 125: case 131: case 141: return CutsceneCommands::SetActorAction2;
case 25: case 36: case 41: case 50: case 67: case 69: case 72: case 81: case 106: case 117: case 121: case 126: case 132: return CutsceneCommands::SetActorAction3;
case 29: case 37: case 42: case 51: case 53: case 63: case 65: case 66: case 75: case 82: case 108: case 127: case 133: return CutsceneCommands::SetActorAction4;
case 30: case 38: case 43: case 47: case 54: case 79: case 83: case 128: case 135: return CutsceneCommands::SetActorAction5;
case 44: case 55: case 77: case 84: case 90: case 129: case 136: return CutsceneCommands::SetActorAction6;
case 31: case 52: case 57: case 58: case 88: case 115: case 130: case 137: return CutsceneCommands::SetActorAction7;
case 49: case 60: case 89: case 111: case 114: case 134: case 142: return CutsceneCommands::SetActorAction8;
case 62: return CutsceneCommands::SetActorAction9;
case 143: return CutsceneCommands::SetActorAction10;
case 0x0B: case 0x0D: case 0x1A: case 0x1B: case 0x1C: case 0x20: case 0x21: case 0x3B: case 0x3D: case 0x47: case 0x49: case 0x6D: case 0x15: case 0x16: case 0x70: case 0x71: case 0x4A: return CutsceneCommands::Unknown;
case 0x0003:
return CutsceneCommands::SpecialAction;
case 0x0004:
return CutsceneCommands::SetLighting;
case 0x0056:
return CutsceneCommands::PlayBGM;
case 0x0057:
return CutsceneCommands::StopBGM;
case 0x007C:
return CutsceneCommands::FadeBGM;
case 0x0009:
return CutsceneCommands::Cmd09;
case 0x0013:
return CutsceneCommands::Textbox;
case 0x008C:
return CutsceneCommands::SetTime;
case 0x0001:
return CutsceneCommands::SetCameraPos;
case 0x0002:
return CutsceneCommands::SetCameraFocus;
case 0x0005:
return CutsceneCommands::SetCameraPosLink;
case 0x0006:
return CutsceneCommands::SetCameraFocusLink;
case 0x0007:
return CutsceneCommands::Cmd07;
case 0x0008:
return CutsceneCommands::Cmd08;
case 0x03E8:
return CutsceneCommands::Terminator;
case 0xFFFF:
return CutsceneCommands::End;
case 0x002D:
return CutsceneCommands::SetSceneTransFX;
case 10:
return CutsceneCommands::SetActorAction0;
case 15:
case 17:
case 18:
case 23:
case 34:
case 39:
case 46:
case 76:
case 85:
case 93:
case 105:
case 107:
case 110:
case 119:
case 123:
case 138:
case 139:
case 144:
return CutsceneCommands::SetActorAction1;
case 14:
case 16:
case 24:
case 35:
case 40:
case 48:
case 64:
case 68:
case 70:
case 78:
case 80:
case 94:
case 116:
case 118:
case 120:
case 125:
case 131:
case 141:
return CutsceneCommands::SetActorAction2;
case 25:
case 36:
case 41:
case 50:
case 67:
case 69:
case 72:
case 81:
case 106:
case 117:
case 121:
case 126:
case 132:
return CutsceneCommands::SetActorAction3;
case 29:
case 37:
case 42:
case 51:
case 53:
case 63:
case 65:
case 66:
case 75:
case 82:
case 108:
case 127:
case 133:
return CutsceneCommands::SetActorAction4;
case 30:
case 38:
case 43:
case 47:
case 54:
case 79:
case 83:
case 128:
case 135:
return CutsceneCommands::SetActorAction5;
case 44:
case 55:
case 77:
case 84:
case 90:
case 129:
case 136:
return CutsceneCommands::SetActorAction6;
case 31:
case 52:
case 57:
case 58:
case 88:
case 115:
case 130:
case 137:
return CutsceneCommands::SetActorAction7;
case 49:
case 60:
case 89:
case 111:
case 114:
case 134:
case 142:
return CutsceneCommands::SetActorAction8;
case 62:
return CutsceneCommands::SetActorAction9;
case 143:
return CutsceneCommands::SetActorAction10;
case 0x0B:
case 0x0D:
case 0x1A:
case 0x1B:
case 0x1C:
case 0x20:
case 0x21:
case 0x3B:
case 0x3D:
case 0x47:
case 0x49:
case 0x6D:
case 0x15:
case 0x16:
case 0x70:
case 0x71:
case 0x4A:
return CutsceneCommands::Unknown;
}
printf("WARNING: Could not identify cutscene command ID 0x%04X\n", id);
@ -188,7 +368,6 @@ ZResourceType ZCutscene::GetResourceType()
CutsceneCommand::CutsceneCommand(const vector<uint8_t>& rawData, int rawDataIndex)
{
}
string CutsceneCommand::GetCName(const std::string& prefix)
@ -198,7 +377,9 @@ string CutsceneCommand::GetCName(const std::string& prefix)
string CutsceneCommand::GenerateSourceCode(const std::string& roomName, int baseAddress)
{
return StringHelper::Sprintf("%s %sCutsceneData%04XCmd%02X = { 0x%02X,", GetCName(roomName).c_str(), roomName.c_str(), baseAddress, commandIndex, commandID);
return StringHelper::Sprintf("%s %sCutsceneData%04XCmd%02X = { 0x%02X,",
GetCName(roomName).c_str(), roomName.c_str(), baseAddress,
commandIndex, commandID);
}
size_t CutsceneCommand::GetCommandSize()
@ -222,7 +403,9 @@ CutsceneCameraPoint::CutsceneCameraPoint(const vector<uint8_t>& rawData, int raw
unused = BitConverter::ToInt16BE(data, rawDataIndex + 14);
}
CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandSetCameraPos::CutsceneCommandSetCameraPos(const vector<uint8_t>& rawData,
int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
const uint8_t* data = rawData.data();
@ -285,10 +468,13 @@ string CutsceneCommandSetCameraPos::GenerateSourceCode(const std::string& roomNa
result += StringHelper::Sprintf("%s(%i, %i),\n", listStr.c_str(), startFrame, endFrame);
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf("\t\t%s(%i, %i, %i, 0x%06X, %i, %i, %i, %i),\n", posStr.c_str(), entries[i]->continueFlag, entries[i]->cameraRoll, entries[i]->nextPointFrame,
*(uint32_t*)&entries[i]->viewAngle, entries[i]->posX, entries[i]->posY, entries[i]->posZ, entries[i]->unused);
result += StringHelper::Sprintf("\t\t%s(%i, %i, %i, 0x%06X, %i, %i, %i, %i),\n",
posStr.c_str(), entries[i]->continueFlag,
entries[i]->cameraRoll, entries[i]->nextPointFrame,
*(uint32_t*)&entries[i]->viewAngle, entries[i]->posX,
entries[i]->posY, entries[i]->posZ, entries[i]->unused);
}
return result;
@ -312,12 +498,16 @@ MusicFadeEntry::MusicFadeEntry(const vector<uint8_t>& rawData, int rawDataIndex)
unknown5 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 24);
unknown6 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 28);
unknown7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32);
unknown8 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 36);
unknown9 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 40);
unknown10 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 44);
unknown8 = (uint32_t)BitConverter::ToInt32BE(rawData,
rawDataIndex + 36); // Macro hardcodes it as zero
unknown9 = (uint32_t)BitConverter::ToInt32BE(rawData,
rawDataIndex + 40); // Macro hardcodes it as zero
unknown10 = (uint32_t)BitConverter::ToInt32BE(rawData,
rawDataIndex + 44); // Macro hardcodes it as zero
}
CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandFadeBGM::CutsceneCommandFadeBGM(const vector<uint8_t>& rawData, int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
@ -341,11 +531,13 @@ string CutsceneCommandFadeBGM::GenerateSourceCode(const std::string& roomName, i
result += StringHelper::Sprintf("CS_FADE_BGM_LIST(%i),\n", entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf("\t\tCS_FADE_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame,
entries[i]->unknown0, entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7,
entries[i]->unknown8, entries[i]->unknown9, entries[i]->unknown10);
result += StringHelper::Sprintf(
"\t\tCS_FADE_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base,
entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0,
entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4,
entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7);
}
return result;
@ -353,7 +545,7 @@ string CutsceneCommandFadeBGM::GenerateSourceCode(const std::string& roomName, i
size_t CutsceneCommandFadeBGM::GetCommandSize()
{
return CutsceneCommand::GetCommandSize() + 0x30;
return CutsceneCommand::GetCommandSize() + 0x30 * entries.size();
}
MusicChangeEntry::MusicChangeEntry(const vector<uint8_t>& rawData, int rawDataIndex)
@ -371,7 +563,8 @@ MusicChangeEntry::MusicChangeEntry(const vector<uint8_t>& rawData, int rawDataIn
unknown7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32);
}
CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const vector<uint8_t>& rawData, int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
@ -390,11 +583,13 @@ string CutsceneCommandPlayBGM::GenerateSourceCode(const std::string& roomName, i
result += StringHelper::Sprintf("CS_PLAY_BGM_LIST(%i),\n", entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf("\t\tCS_PLAY_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->sequence, entries[i]->startFrame,
entries[i]->endFrame, entries[i]->unknown0, entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, entries[i]->unknown5,
entries[i]->unknown6, entries[i]->unknown7);
result += StringHelper::Sprintf(
"\t\tCS_PLAY_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->sequence,
entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0,
entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4,
entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7);
}
return result;
@ -410,7 +605,8 @@ size_t CutsceneCommandPlayBGM::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 0x30;
}
CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandStopBGM::CutsceneCommandStopBGM(const vector<uint8_t>& rawData, int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
@ -429,11 +625,13 @@ string CutsceneCommandStopBGM::GenerateSourceCode(const std::string& roomName, i
result += StringHelper::Sprintf("CS_STOP_BGM_LIST(%i),\n", entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf("CS_STOP_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->sequence, entries[i]->startFrame,
entries[i]->endFrame, entries[i]->unknown0, entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4, entries[i]->unknown5,
entries[i]->unknown6, entries[i]->unknown7);
result += StringHelper::Sprintf(
"\t\tCS_STOP_BGM(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->sequence,
entries[i]->startFrame, entries[i]->endFrame, entries[i]->unknown0,
entries[i]->unknown1, entries[i]->unknown2, entries[i]->unknown3, entries[i]->unknown4,
entries[i]->unknown5, entries[i]->unknown6, entries[i]->unknown7);
}
return result;
@ -464,7 +662,9 @@ EnvLightingEntry::EnvLightingEntry(const vector<uint8_t>& rawData, int rawDataIn
unused7 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 32);
}
CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const vector<uint8_t>& rawData,
int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
@ -483,10 +683,12 @@ string CutsceneCommandEnvLighting::GenerateSourceCode(const std::string& roomNam
result += StringHelper::Sprintf("CS_LIGHTING_LIST(%i),\n", entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf("CS_LIGHTING(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->setting, entries[i]->startFrame,
entries[i]->endFrame, entries[i]->unused0, entries[i]->unused1, entries[i]->unused2, entries[i]->unused3, entries[i]->unused4, entries[i]->unused5,
result += StringHelper::Sprintf(
"\t\tCS_LIGHTING(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->setting,
entries[i]->startFrame, entries[i]->endFrame, entries[i]->unused0, entries[i]->unused1,
entries[i]->unused2, entries[i]->unused3, entries[i]->unused4, entries[i]->unused5,
entries[i]->unused6, entries[i]->unused7);
}
@ -512,10 +714,12 @@ Unknown9Entry::Unknown9Entry(const vector<uint8_t>& rawData, int rawDataIndex)
unk3 = rawData[rawDataIndex + 7];
unk4 = rawData[rawDataIndex + 8];
unused0 = rawData[rawDataIndex + 10];
unused1 = rawData[rawDataIndex + 11];;
unused1 = rawData[rawDataIndex + 11];
;
}
CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandUnknown9::CutsceneCommandUnknown9(const vector<uint8_t>& rawData, int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex);
@ -534,10 +738,12 @@ string CutsceneCommandUnknown9::GenerateSourceCode(const std::string& roomName,
result += StringHelper::Sprintf("CS_CMD_09_LIST(%i),\n", entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf("CS_CMD_09(%i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->unk2,
entries[i]->unk3, entries[i]->unk4, entries[i]->unused0, entries[i]->unused1);
result += StringHelper::Sprintf("\t\tCS_CMD_09(%i, %i, %i, %i, %i, %i, %i, %i),\n",
entries[i]->base, entries[i]->startFrame,
entries[i]->endFrame, entries[i]->unk2, entries[i]->unk3,
entries[i]->unk4, entries[i]->unused0, entries[i]->unused1);
}
return result;
@ -569,7 +775,8 @@ UnkEntry::UnkEntry(const vector<uint8_t>& rawData, int rawDataIndex)
unused11 = (uint32_t)BitConverter::ToInt32BE(rawData, rawDataIndex + 44);
}
CutsceneCommandUnknown::CutsceneCommandUnknown(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandUnknown::CutsceneCommandUnknown(const vector<uint8_t>& rawData, int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex);
@ -588,11 +795,13 @@ string CutsceneCommandUnknown::GenerateSourceCode(const std::string& roomName, i
result += StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%02X, %i),\n", commandID, entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf("\tCS_UNK_DATA(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->unused0, entries[i]->unused1, entries[i]->unused2,
entries[i]->unused3, entries[i]->unused4, entries[i]->unused5, entries[i]->unused6,
entries[i]->unused7, entries[i]->unused8, entries[i]->unused9, entries[i]->unused10, entries[i]->unused11);
result += StringHelper::Sprintf(
"\t\tCS_UNK_DATA(%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n",
entries[i]->unused0, entries[i]->unused1, entries[i]->unused2, entries[i]->unused3,
entries[i]->unused4, entries[i]->unused5, entries[i]->unused6, entries[i]->unused7,
entries[i]->unused8, entries[i]->unused9, entries[i]->unused10, entries[i]->unused11);
}
return result;
@ -618,7 +827,8 @@ DayTimeEntry::DayTimeEntry(const vector<uint8_t>& rawData, int rawDataIndex)
unused = rawData[rawDataIndex + 8];
}
CutsceneCommandDayTime::CutsceneCommandDayTime(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandDayTime::CutsceneCommandDayTime(const vector<uint8_t>& rawData, int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex);
@ -642,9 +852,10 @@ string CutsceneCommandDayTime::GenerateSourceCode(const std::string& roomName, i
result += StringHelper::Sprintf("CS_TIME_LIST(%i),\n", entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf("\t\tCS_TIME(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame,
result += StringHelper::Sprintf("\t\tCS_TIME(%i, %i, %i, %i, %i, %i),\n", entries[i]->base,
entries[i]->startFrame, entries[i]->endFrame,
entries[i]->hour, entries[i]->minute, entries[i]->unused);
}
@ -666,7 +877,8 @@ TextboxEntry::TextboxEntry(const vector<uint8_t>& rawData, int rawDataIndex)
textID2 = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
}
CutsceneCommandTextbox::CutsceneCommandTextbox(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandTextbox::CutsceneCommandTextbox(const vector<uint8_t>& rawData, int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex);
@ -690,16 +902,19 @@ string CutsceneCommandTextbox::GenerateSourceCode(const std::string& roomName, i
result += StringHelper::Sprintf("CS_TEXT_LIST(%i),\n", entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
if (entries[i]->base == 0xFFFF)
{
result += StringHelper::Sprintf("\t\tCS_TEXT_NONE(%i, %i),\n", entries[i]->startFrame, entries[i]->endFrame);
result += StringHelper::Sprintf("\t\tCS_TEXT_NONE(%i, %i),\n", entries[i]->startFrame,
entries[i]->endFrame);
}
else
{
result += StringHelper::Sprintf("\t\tCS_TEXT_DISPLAY_TEXTBOX(%i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->type,
entries[i]->textID1, entries[i]->textID2);
result += StringHelper::Sprintf(
"\t\tCS_TEXT_DISPLAY_TEXTBOX(%i, %i, %i, %i, %i, %i),\n", entries[i]->base,
entries[i]->startFrame, entries[i]->endFrame, entries[i]->type, entries[i]->textID1,
entries[i]->textID2);
}
}
@ -732,7 +947,9 @@ ActorAction::ActorAction(const vector<uint8_t>& rawData, int rawDataIndex)
normalZ = BitConverter::ToInt32BE(data, rawDataIndex + 44);
}
CutsceneCommandActorAction::CutsceneCommandActorAction(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandActorAction::CutsceneCommandActorAction(const vector<uint8_t>& rawData,
int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex);
@ -748,14 +965,28 @@ CutsceneCommandActorAction::CutsceneCommandActorAction(const vector<uint8_t>& ra
string CutsceneCommandActorAction::GenerateSourceCode(const std::string& roomName, int baseAddress)
{
string result = "";
string subCommand = "";
result += StringHelper::Sprintf("CS_NPC_ACTION_LIST(%i, %i),\n", commandID, entries.size());
for (int i = 0; i < entries.size(); i++)
if (commandID == 10)
{
result += StringHelper::Sprintf("\tCS_NPC_ACTION(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->action, entries[i]->startFrame, entries[i]->endFrame,
entries[i]->rotX, entries[i]->rotY, entries[i]->rotZ, entries[i]->startPosX, entries[i]->startPosY, entries[i]->startPosZ, entries[i]->endPosX, entries[i]->endPosY, entries[i]->endPosZ,
*(int32_t*)&entries[i]->normalX, *(int32_t*)&entries[i]->normalY, *(int32_t*)&entries[i]->normalZ);
result += StringHelper::Sprintf("CS_PLAYER_ACTION_LIST(%i),\n", entries.size());
subCommand = "CS_PLAYER_ACTION";
}
else
{
result += StringHelper::Sprintf("CS_NPC_ACTION_LIST(%i, %i),\n", commandID, entries.size());
subCommand = "CS_NPC_ACTION";
}
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf(
"\t\t%s(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, %i, %i),\n",
subCommand.c_str(), entries[i]->action, entries[i]->startFrame, entries[i]->endFrame,
entries[i]->rotX, entries[i]->rotY, entries[i]->rotZ, entries[i]->startPosX,
entries[i]->startPosY, entries[i]->startPosZ, entries[i]->endPosX, entries[i]->endPosY,
entries[i]->endPosZ, *(int32_t*)&entries[i]->normalX, *(int32_t*)&entries[i]->normalY,
*(int32_t*)&entries[i]->normalZ);
}
return result;
@ -771,14 +1002,16 @@ size_t CutsceneCommandActorAction::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (entries.size() * 0x30);
}
CutsceneCommandTerminator::CutsceneCommandTerminator(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandTerminator::CutsceneCommandTerminator(const vector<uint8_t>& rawData,
int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
rawDataIndex += 4;
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
unknown = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
unknown = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 6); // endFrame duplicate
}
string CutsceneCommandTerminator::GetCName(const std::string& prefix)
@ -790,7 +1023,7 @@ string CutsceneCommandTerminator::GenerateSourceCode(const std::string& roomName
{
string result = "";
result += StringHelper::Sprintf("CS_TERMINATOR(0x%04X, %i, %i, 0x%04X),\n", base, startFrame, endFrame, unknown);
result += StringHelper::Sprintf("CS_TERMINATOR(0x%04X, %i, %i),\n", base, startFrame, endFrame);
return result;
}
@ -800,7 +1033,8 @@ size_t CutsceneCommandTerminator::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 8;
}
CutsceneCommandEnd::CutsceneCommandEnd(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandEnd::CutsceneCommandEnd(const vector<uint8_t>& rawData, int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@ -846,7 +1080,9 @@ SpecialActionEntry::SpecialActionEntry(const vector<uint8_t>& rawData, int rawDa
unused10 = BitConverter::ToUInt32BE(data, rawDataIndex + 44);
}
CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t>& rawData,
int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
int numEntries = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
@ -859,17 +1095,22 @@ CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const vector<uint8_t>
}
}
string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomName, int baseAddress)
string CutsceneCommandSpecialAction::GenerateSourceCode(const std::string& roomName,
int baseAddress)
{
string result = "";
result += StringHelper::Sprintf("CS_MISC_LIST(%i),\n", entries.size());
for (int i = 0; i < entries.size(); i++)
for (size_t i = 0; i < entries.size(); i++)
{
result += StringHelper::Sprintf("\t\tCS_MISC(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, %i),\n", entries[i]->base, entries[i]->startFrame, entries[i]->endFrame,
entries[i]->unused0, entries[i]->unused1, entries[i]->unused2, entries[i]->unused3, entries[i]->unused4, entries[i]->unused5, entries[i]->unused6,
entries[i]->unused7, entries[i]->unused8, entries[i]->unused9, entries[i]->unused10);
result += StringHelper::Sprintf(
"\t\tCS_MISC(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, "
"%i),\n",
entries[i]->base, entries[i]->startFrame, entries[i]->endFrame, entries[i]->unused0,
entries[i]->unused1, entries[i]->unused2, entries[i]->unused3, entries[i]->unused4,
entries[i]->unused5, entries[i]->unused6, entries[i]->unused7, entries[i]->unused8,
entries[i]->unused9, entries[i]->unused10);
}
return result;
@ -885,7 +1126,8 @@ size_t CutsceneCommandSpecialAction::GetCommandSize()
return CutsceneCommand::GetCommandSize() + (0x30 * entries.size());
}
CutsceneCommandNop::CutsceneCommandNop(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandNop::CutsceneCommandNop(const vector<uint8_t>& rawData, int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
base = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
startFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
@ -902,7 +1144,9 @@ size_t CutsceneCommandNop::GetCommandSize()
return CutsceneCommand::GetCommandSize() + 6;
}
CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector<uint8_t>& rawData, int rawDataIndex) : CutsceneCommand(rawData, rawDataIndex)
CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const vector<uint8_t>& rawData,
int rawDataIndex)
: CutsceneCommand(rawData, rawDataIndex)
{
rawDataIndex += 4;

View file

@ -1,8 +1,8 @@
#pragma once
#include <vector>
#include <string>
#include <stdint.h>
#include <string>
#include <vector>
#include "ZResource.h"
#include "tinyxml2.h"
@ -141,7 +141,7 @@ class CutsceneCommandFadeBGM : public CutsceneCommand
public:
std::vector<MusicFadeEntry*> entries;
CutsceneCommandFadeBGM( const std::vector<uint8_t>& rawData, int rawDataIndex);
CutsceneCommandFadeBGM(const std::vector<uint8_t>& rawData, int rawDataIndex);
std::string GetCName(const std::string& prefix);
std::string GenerateSourceCode(const std::string& roomName, int baseAddress);
size_t GetCommandSize();
@ -411,11 +411,14 @@ public:
ZResourceType GetResourceType() override;
static ZCutscene* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath);
static ZCutscene* ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData, const int rawDataIndex,
const std::string& nRelPath);
protected:
int numCommands;
int endFrame;
std::vector<CutsceneCommand*> commands;
void ParseRawData();
void ParseRawData() override;
};

File diff suppressed because it is too large Load diff

View file

@ -1,13 +1,13 @@
#pragma once
#include "ZResource.h"
#include "ZTexture.h"
#include "ZRoom/ZRoom.h"
#include "ZTexture.h"
#include "tinyxml2.h"
#include <vector>
#include <map>
#include <string>
#include <vector>
enum class F3DEXOpcode
{
@ -290,7 +290,8 @@ public:
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(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, int rawDataIndex);
};
@ -298,7 +299,7 @@ class ZDisplayList : public ZResource
{
protected:
static TextureType TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSizes siz);
void ParseRawData();
void ParseRawData() override;
void ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int i, std::string prefix, char* line);
void ParseF3DEX(F3DEXOpcode opcode, uint64_t data, int i, std::string prefix, char* line);
@ -331,6 +332,7 @@ protected:
void Opcode_G_SETOTHERMODE_H(uint64_t data, int i, std::string prefix, char* line);
void Opcode_G_LOADTLUT(uint64_t data, int i, std::string prefix, char* line);
void Opcode_G_ENDDL(uint64_t data, int i, std::string prefix, char* line);
public:
std::string sceneSegName;
ZRoom* scene;
@ -345,7 +347,7 @@ public:
DListType dListType;
//int dListAddress;
// int dListAddress;
std::map<uint32_t, std::vector<Vertex>> vertices;
std::map<uint32_t, std::string> vtxDeclarations;
@ -363,14 +365,21 @@ public:
ZDisplayList(std::vector<uint8_t> nRawData, int rawDataIndex, int rawDataSize);
static ZDisplayList* static_instance;
static ZDisplayList* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, int rawDataSize, std::string nRelPath);
static ZDisplayList* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, bool readFile);
static ZDisplayList* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData,
int rawDataIndex, int rawDataSize, std::string nRelPath);
static ZDisplayList* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder,
bool readFile);
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, uint32_t texWidth, uint32_t texHeight, uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette);
static bool TextureGenCheck(std::vector<uint8_t> fileData,
std::map<uint32_t, ZTexture*>& textures, ZRoom* scene,
ZFile* parent, std::string prefix, uint32_t texWidth,
uint32_t texHeight, uint32_t texAddr, uint32_t texSeg,
F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded,
bool texIsPalette);
static int GetDListLength(std::vector<uint8_t> rawData, int rawDataIndex, DListType dListType);
std::vector<uint8_t> GetRawData();
std::vector<uint8_t> GetRawData() override;
int GetRawDataSize() override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
std::string GetSourceOutputCode(const std::string& prefix) override;

View file

@ -1,24 +1,25 @@
#include "ZFile.h"
#include "ZBlob.h"
#include "ZDisplayList.h"
#include "ZRoom/ZRoom.h"
#include "ZTexture.h"
#include "ZAnimation.h"
#include "ZLimb.h"
#include "ZSkeleton.h"
#include "ZCollision.h"
#include "ZScalar.h"
#include "ZVector.h"
#include "ZVtx.h"
#include "ZCutscene.h"
#include "ZArray.h"
#include "Path.h"
#include "File.h"
#include "Directory.h"
#include "Globals.h"
#include "HighLevel/HLModelIntermediette.h"
#include <algorithm>
#include <cassert>
#include "Directory.h"
#include "File.h"
#include "Globals.h"
#include "HighLevel/HLModelIntermediette.h"
#include "Path.h"
#include "ZAnimation.h"
#include "ZArray.h"
#include "ZBlob.h"
#include "ZCollision.h"
#include "ZCutscene.h"
#include "ZDisplayList.h"
#include "ZLimb.h"
#include "ZRoom/ZRoom.h"
#include "ZScalar.h"
#include "ZSkeleton.h"
#include "ZSymbol.h"
#include "ZTexture.h"
#include "ZVector.h"
#include "ZVtx.h"
using namespace tinyxml2;
using namespace std;
@ -28,7 +29,7 @@ ZFile::ZFile()
resources = vector<ZResource*>();
basePath = "";
outputPath = Directory::GetCurrentDirectory();
declarations = map<int32_t, Declaration*>();
declarations = map<uint32_t, Declaration*>();
defines = "";
baseAddress = 0;
rangeStart = 0x000000000;
@ -41,7 +42,9 @@ ZFile::ZFile(string nOutPath, string nName) : ZFile()
name = nName;
}
ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPath, std::string filename, bool placeholderMode) : ZFile()
ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPath,
std::string filename, bool placeholderMode)
: ZFile()
{
if (nBasePath == "")
basePath = Directory::GetCurrentDirectory();
@ -71,7 +74,8 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
int 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.
// 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)
{
@ -90,20 +94,23 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
}
if (reader->Attribute("BaseAddress") != NULL)
baseAddress = (uint32_t)strtoul(StringHelper::Split(reader->Attribute("BaseAddress"), "0x")[1].c_str(), NULL, 16);
baseAddress = (uint32_t)strtoul(
StringHelper::Split(reader->Attribute("BaseAddress"), "0x")[1].c_str(), NULL, 16);
if (reader->Attribute("RangeStart") != NULL)
rangeStart = (uint32_t)strtoul(StringHelper::Split(reader->Attribute("RangeStart"), "0x")[1].c_str(), NULL, 16);
rangeStart = (uint32_t)strtoul(
StringHelper::Split(reader->Attribute("RangeStart"), "0x")[1].c_str(), NULL, 16);
if (reader->Attribute("RangeEnd") != NULL)
rangeEnd = (uint32_t)strtoul(StringHelper::Split(reader->Attribute("RangeEnd"), "0x")[1].c_str(), NULL, 16);
rangeEnd = (uint32_t)strtoul(
StringHelper::Split(reader->Attribute("RangeEnd"), "0x")[1].c_str(), NULL, 16);
if (reader->Attribute("Segment") != NULL)
segment = strtol(reader->Attribute("Segment"), NULL, 10);
if (segment != -1)
{
//printf("Adding Segment %i\n", segment);
// printf("Adding Segment %i\n", segment);
Globals::Instance->AddSegment(segment);
}
@ -112,17 +119,20 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
if (mode == ZFileMode::Extract)
{
if (!File::Exists(basePath + "/" + name))
throw StringHelper::Sprintf("Error! File %s does not exist.", (basePath + "/" + name).c_str());
throw StringHelper::Sprintf("Error! File %s does not exist.",
(basePath + "/" + name).c_str());
rawData = File::ReadAllBytes(basePath + "/" + name);
}
int rawDataIndex = 0;
for (XMLElement* child = reader->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = reader->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (child->Attribute("Offset") != NULL)
rawDataIndex = strtol(StringHelper::Split(child->Attribute("Offset"), "0x")[1].c_str(), NULL, 16);
rawDataIndex =
strtol(StringHelper::Split(child->Attribute("Offset"), "0x")[1].c_str(), NULL, 16);
if (Globals::Instance->verbosity >= VERBOSITY_INFO)
printf("%s: 0x%06X\n", child->Attribute("Name"), rawDataIndex);
@ -163,9 +173,15 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
ZResource* dList = nullptr;
if (mode == ZFileMode::Extract)
dList = ZDisplayList::ExtractFromXML(child, rawData, rawDataIndex, ZDisplayList::GetDListLength(rawData, rawDataIndex, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX), folderName);
//else
//dList = ZDisplayList::BuildFromXML(child, folderName, mode == ZFileMode::Build);
dList = ZDisplayList::ExtractFromXML(
child, rawData, rawDataIndex,
ZDisplayList::GetDListLength(rawData, rawDataIndex,
Globals::Instance->game == ZGame::OOT_SW97 ?
DListType::F3DEX :
DListType::F3DZEX),
folderName);
// else
// dList = ZDisplayList::BuildFromXML(child, folderName, mode == ZFileMode::Build);
else
dList = ZBlob::BuildFromXML(child, folderName, mode == ZFileMode::Build);
@ -180,7 +196,8 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
ZRoom* room = nullptr;
if (mode == ZFileMode::Extract)
room = ZRoom::ExtractFromXML(child, rawData, rawDataIndex, folderName, this, Globals::Instance->lastScene);
room = ZRoom::ExtractFromXML(child, rawData, rawDataIndex, folderName, this,
Globals::Instance->lastScene);
if (string(child->Name()) == "Scene")
{
@ -226,6 +243,23 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
rawDataIndex += anim->GetRawDataSize();
}
else if (string(child->Name()) == "CurveAnimation")
{
ZCurveAnimation* anim = nullptr;
if (mode == ZFileMode::Extract)
{
anim =
ZCurveAnimation::ExtractFromXML(child, rawData, rawDataIndex, folderName, this);
}
if (anim == nullptr)
{
throw std::runtime_error("Couldn't create ZCurveAnimation.");
}
resources.push_back(anim);
rawDataIndex += anim->GetRawDataSize();
}
else if (string(child->Name()) == "Skeleton")
{
ZSkeleton* skeleton = nullptr;
@ -233,6 +267,10 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
if (mode == ZFileMode::Extract)
skeleton = ZSkeleton::FromXML(child, rawData, rawDataIndex, folderName, this);
if (skeleton == nullptr)
{
throw std::runtime_error("Couldn't create ZSkeleton.");
}
resources.push_back(skeleton);
rawDataIndex += skeleton->GetRawDataSize();
}
@ -243,23 +281,27 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
if (mode == ZFileMode::Extract)
limb = ZLimb::FromXML(child, rawData, rawDataIndex, folderName, this);
if (limb == nullptr)
{
throw std::runtime_error("Couldn't create ZLimb.");
}
resources.push_back(limb);
rawDataIndex += limb->GetRawDataSize();
}
else if (string(child->Name()) == "Symbol")
{
ZResource* res = nullptr;
ZSymbol* symbol = nullptr;
if (mode == ZFileMode::Extract)
{
res = new ZResource();
res->SetName(child->Attribute("Name"));
res->SetRawDataIndex(rawDataIndex);
res->outputDeclaration = false;
symbol = ZSymbol::ExtractFromXML(child, rawData, rawDataIndex, this);
}
resources.push_back(res);
if (symbol == nullptr)
{
throw std::runtime_error("Couldn't create ZSymbol.");
}
resources.push_back(symbol);
}
else if (string(child->Name()) == "Collision")
{
@ -364,7 +406,8 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
else
{
std::cerr << "ERROR bad type\n";
printf("Encountered unknown resource type: %s on line: %d\n", child->Name(), child->GetLineNum());
printf("Encountered unknown resource type: %s on line: %d\n", child->Name(),
child->GetLineNum());
std::exit(EXIT_FAILURE);
}
}
@ -388,9 +431,9 @@ void ZFile::BuildResources()
for (ZResource* res : resources)
{
//Console.WriteLine("Building resource " + res.GetName());
// Console.WriteLine("Building resource " + res.GetName());
memcpy(file.data() + fileIndex, res->GetRawData().data(), res->GetRawData().size());
//Array.Copy(res.GetRawData(), 0, file, fileIndex, res.GetRawData().Length);
// Array.Copy(res.GetRawData(), 0, file, fileIndex, res.GetRawData().Length);
fileIndex += res->GetRawData().size();
}
@ -427,8 +470,8 @@ void ZFile::ExtractResources(string outputDir)
{
string folderName = Path::GetFileNameWithoutExtension(outputPath);
//printf("DIR CHECK: %s\n", folderName.c_str());
//printf("OUT CHECK: %s\n", outputDir.c_str());
// printf("DIR CHECK: %s\n", folderName.c_str());
// printf("OUT CHECK: %s\n", outputDir.c_str());
if (!Directory::Exists(outputPath))
Directory::CreateDirectory(outputPath);
@ -457,7 +500,8 @@ void ZFile::AddResource(ZResource* res)
resources.push_back(res);
}
Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size, std::string varType, std::string varName, std::string body)
Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size,
std::string varType, std::string varName, std::string body)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
@ -473,7 +517,9 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm
return decl;
}
Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment, DeclarationPadding padding, uint32_t size, string varType, string varName, std::string body)
Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignment,
DeclarationPadding padding, uint32_t size, string varType,
string varName, std::string body)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
@ -484,11 +530,14 @@ Declaration* ZFile::AddDeclaration(uint32_t address, DeclarationAlignment alignm
AddDeclarationDebugChecks(address);
declarations[address] = new Declaration(alignment, padding, size, varType, varName, false, body);
declarations[address] =
new Declaration(alignment, padding, size, varType, varName, false, body);
return declarations[address];
}
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, uint32_t size, std::string varType, std::string varName, int arrayItemCnt, std::string body)
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
uint32_t size, std::string varType, std::string varName,
int arrayItemCnt, std::string body)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
@ -499,12 +548,14 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
AddDeclarationDebugChecks(address);
declarations[address] = new Declaration(alignment, size, varType, varName, true, arrayItemCnt, body);
declarations[address] =
new Declaration(alignment, size, varType, varName, true, arrayItemCnt, body);
return declarations[address];
}
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, DeclarationPadding padding, uint32_t size, string varType, string varName, int arrayItemCnt, std::string body)
Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
DeclarationPadding padding, uint32_t size, string varType,
string varName, int arrayItemCnt, std::string body)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
@ -515,11 +566,11 @@ Declaration* ZFile::AddDeclarationArray(uint32_t address, DeclarationAlignment a
AddDeclarationDebugChecks(address);
declarations[address] = new Declaration(alignment, padding, size, varType, varName, true, arrayItemCnt, body);
declarations[address] =
new Declaration(alignment, padding, size, varType, varName, true, arrayItemCnt, body);
return declarations[address];
}
Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address)
{
AddDeclarationDebugChecks(address);
@ -535,12 +586,14 @@ Declaration* ZFile::AddDeclarationPlaceholder(uint32_t address, string varName)
AddDeclarationDebugChecks(address);
if (declarations.find(address) == declarations.end())
declarations[address] = new Declaration(DeclarationAlignment::None, 0, "", varName, false, "");
declarations[address] =
new Declaration(DeclarationAlignment::None, 0, "", varName, false, "");
return declarations[address];
}
Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, uint32_t size, string varType, string varName)
Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath, uint32_t size,
string varType, string varName)
{
AddDeclarationDebugChecks(address);
@ -550,7 +603,9 @@ Declaration* ZFile::AddDeclarationInclude(uint32_t address, string includePath,
return declarations[address];
}
Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string includePath, uint32_t size, std::string varType, std::string varName, int arrayItemCnt)
Declaration* ZFile::AddDeclarationIncludeArray(uint32_t address, std::string includePath,
uint32_t size, std::string varType,
std::string varName, int arrayItemCnt)
{
#if _DEBUG
if (declarations.find(address) != declarations.end())
@ -582,7 +637,9 @@ void ZFile::AddDeclarationDebugChecks(uint32_t address)
std::string ZFile::GetDeclarationName(uint32_t address)
{
return GetDeclarationName(address, "ERROR_COULD_NOT_FIND_DECLARATION"); // Note: For now that default message is just for testing
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)
@ -646,7 +703,7 @@ void ZFile::GenerateSourceFiles(string outputDir)
if (res->IsExternalResource())
{
//cout << "EXTERN\n";
// cout << "EXTERN\n";
string path = Path::GetFileNameWithoutExtension(res->GetName()).c_str();
while (StringHelper::EndsWith(outputDir, "/"))
@ -658,16 +715,19 @@ void ZFile::GenerateSourceFiles(string outputDir)
if (res->GetResourceType() != ZResourceType::Texture)
declType = "u8";
AddDeclarationIncludeArray(res->GetRawDataIndex(), StringHelper::Sprintf("%s/%s.%s.inc.c",
outputDir.c_str(), Path::GetFileNameWithoutExtension(res->GetOutName()).c_str(), res->GetExternalExtension().c_str()), res->GetRawDataSize(),
declType, res->GetName(), 0);
AddDeclarationIncludeArray(
res->GetRawDataIndex(),
StringHelper::Sprintf("%s/%s.%s.inc.c", outputDir.c_str(),
Path::GetFileNameWithoutExtension(res->GetOutName()).c_str(),
res->GetExternalExtension().c_str()),
res->GetRawDataSize(), declType, res->GetName(), 0);
//File::WriteAllText("build/" + outputDir + "/" + Path::GetFileNameWithoutExtension(res->GetName()) + ".inc.c", resSrc);
// File::WriteAllText("build/" + outputDir + "/" +
// Path::GetFileNameWithoutExtension(res->GetName()) + ".inc.c", resSrc);
}
else
{
//cout << "NOT EXTERN\n";
// cout << "NOT EXTERN\n";
sourceOutput += resSrc;
}
@ -680,18 +740,18 @@ void ZFile::GenerateSourceFiles(string outputDir)
while (StringHelper::EndsWith(outputDir, "/"))
outputDir = outputDir.substr(0, outputDir.length() - 1);
//string buildPath = "build/" + outputDir + "/" + "basefile.txt";
// string buildPath = "build/" + outputDir + "/" + "basefile.txt";
string outPath = outputDir + "/" + Path::GetFileNameWithoutExtension(name) + ".c";
//printf("WRITING %s\n", buildPath.c_str());
// printf("WRITING %s\n", buildPath.c_str());
//if (!Directory::Exists(Path::GetPath(outPath)))
//Directory::CreateDirectory(Path::GetPath(outPath));
// if (!Directory::Exists(Path::GetPath(outPath)))
// Directory::CreateDirectory(Path::GetPath(outPath));
//if (!Directory::Exists(Path::GetPath(buildPath)))
//Directory::CreateDirectory(Path::GetPath(buildPath));
// if (!Directory::Exists(Path::GetPath(buildPath)))
// Directory::CreateDirectory(Path::GetPath(buildPath));
File::WriteAllText(outPath, sourceOutput);
//File::WriteAllText(buildPath, outPath);
// File::WriteAllText(buildPath, outPath);
// Generate Header
sourceOutput = "";
@ -707,7 +767,8 @@ void ZFile::GenerateSourceFiles(string outputDir)
sourceOutput += ProcessExterns();
File::WriteAllText(outputDir + "/" + Path::GetFileNameWithoutExtension(name) + ".h", sourceOutput);
File::WriteAllText(outputDir + "/" + Path::GetFileNameWithoutExtension(name) + ".h",
sourceOutput);
}
void ZFile::GenerateHLIntermediette()
@ -727,7 +788,8 @@ void ZFile::GenerateHLIntermediette()
std::string ZFile::GetHeaderInclude()
{
return StringHelper::Sprintf("#include \"%s\"\n\n", (Path::GetFileNameWithoutExtension(name) + ".h").c_str());
return StringHelper::Sprintf("#include \"%s\"\n\n",
(Path::GetFileNameWithoutExtension(name) + ".h").c_str());
}
void ZFile::GeneratePlaceholderDeclarations()
@ -747,22 +809,16 @@ string ZFile::ProcessDeclarations()
if (declarations.size() == 0)
return output;
auto declarationKeysSorted = vector<pair<int32_t, Declaration*>>(declarations.begin(), declarations.end());
sort(declarationKeysSorted.begin(), declarationKeysSorted.end(), [](const auto& lhs, const auto& rhs)
{
return lhs.first < rhs.first;
});
// Account for padding/alignment
int lastAddr = 0;
int lastSize = 0;
uint32_t lastAddr = 0;
uint32_t lastSize = 0;
//printf("RANGE START: 0x%06X - RANGE END: 0x%06X\n", rangeStart, rangeEnd);
// 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...
//pair<int32_t, Declaration*> lastItem = declarationKeysSorted[0];
// pair<int32_t, Declaration*> lastItem = declarationKeysSorted[0];
//for (int i = 1; i < declarationKeysSorted.size(); i++)
// for (int i = 1; i < declarationKeysSorted.size(); i++)
//{
// pair<int32_t, Declaration*> curItem = declarationKeysSorted[i];
@ -789,29 +845,29 @@ string ZFile::ProcessDeclarations()
// lastItem = curItem;
//}
for (pair<int32_t, Declaration*> item : declarations)
for (pair<uint32_t, Declaration*> item : declarations)
{
ProcessDeclarationText(item.second);
}
for (pair<int32_t, Declaration*> item : declarationKeysSorted)
for (pair<int32_t, Declaration*> item : declarations)
{
while (declarations[item.first]->size % 4 != 0)
while (item.second->size % 4 != 0)
{
declarations[item.first]->size++;
item.second->size++;
}
if (lastAddr != 0)
{
if (item.second->alignment == DeclarationAlignment::Align16)
{
int lastAddrSizeTest = declarations[lastAddr]->size;
// int lastAddrSizeTest = declarations[lastAddr]->size;
int curPtr = lastAddr + declarations[lastAddr]->size;
while (curPtr % 4 != 0)
{
declarations[lastAddr]->size++;
//declarations[item.first]->size++;
// item.second->size++;
curPtr++;
}
@ -820,7 +876,7 @@ string ZFile::ProcessDeclarations()
char buffer[2048];
sprintf(buffer, "static u32 align%02X = 0;\n", curPtr);
declarations[item.first]->text = buffer + declarations[item.first]->text;
item.second->text = buffer + item.second->text;
declarations[lastAddr]->size += 4;
curPtr += 4;
@ -833,8 +889,7 @@ string ZFile::ProcessDeclarations()
while (curPtr % 4 != 0)
{
declarations[lastAddr]->size++;
//item.second->size++;
//declarations[item.first]->size++;
// item.second->size++;
curPtr++;
}
@ -843,11 +898,10 @@ string ZFile::ProcessDeclarations()
char buffer[2048];
sprintf(buffer, "static u32 align%02X = 0;\n", curPtr);
declarations[item.first]->preText = buffer + declarations[item.first]->preText;
item.second->preText = buffer + item.second->preText;
declarations[lastAddr]->size += 4;
//item.second->size += 4;
//declarations[item.first]->size += 4;
// item.second->size += 4;
curPtr += 4;
}
}
@ -865,7 +919,7 @@ string ZFile::ProcessDeclarations()
while (curPtr % 16 != 0)
{
declarations[item.first]->postText += StringHelper::Sprintf("static u32 pad%02X = 0;\n", curPtr);
item.second->postText += StringHelper::Sprintf("static u32 pad%02X = 0;\n", curPtr);
item.second->size += 4;
curPtr += 4;
@ -878,27 +932,31 @@ string ZFile::ProcessDeclarations()
// Handle unaccounted data
lastAddr = 0;
lastSize = 0;
for (pair<int32_t, Declaration*> item : declarationKeysSorted)
for (pair<int32_t, Declaration*> item : declarations)
{
if (item.first >= rangeStart && item.first < rangeEnd)
{
if (lastAddr != 0 && declarations.find(lastAddr) != declarations.end() && lastAddr + declarations[lastAddr]->size > item.first)
if (lastAddr != 0 && declarations.find(lastAddr) != declarations.end() &&
lastAddr + declarations[lastAddr]->size > item.first)
{
printf("WARNING: Intersection detected from 0x%06X:0x%06X, conflicts with 0x%06X\n", lastAddr, lastAddr + declarations[lastAddr]->size, item.first);
printf("WARNING: Intersection detected from 0x%06X:0x%06X, conflicts with 0x%06X\n",
lastAddr, lastAddr + declarations[lastAddr]->size, item.first);
}
uint8_t* rawDataArr = rawData.data();
if (lastAddr + lastSize != item.first && lastAddr >= rangeStart && lastAddr + lastSize < rangeEnd)
if (lastAddr + lastSize != item.first && lastAddr >= rangeStart &&
lastAddr + lastSize < rangeEnd)
{
//int diff = item.first - (lastAddr + declarations[lastAddr]->size);
// int diff = item.first - (lastAddr + declarations[lastAddr]->size);
int diff = item.first - (lastAddr + lastSize);
string src = " ";
for (int i = 0; i < diff; i++)
{
//src += StringHelper::Sprintf("0x%02X, ", rawDataArr[lastAddr + declarations[lastAddr]->size + i]);
// src += StringHelper::Sprintf("0x%02X, ", rawDataArr[lastAddr +
// declarations[lastAddr]->size + i]);
src += StringHelper::Sprintf("0x%02X, ", rawDataArr[lastAddr + lastSize + i]);
if ((i % 16 == 15) && (i != (diff - 1)))
@ -909,8 +967,14 @@ string ZFile::ProcessDeclarations()
{
if (diff > 0)
{
//AddDeclarationArray(lastAddr + declarations[lastAddr]->size, DeclarationAlignment::None, diff, "static u8", StringHelper::Sprintf("unaccounted_%06X", lastAddr + declarations[lastAddr]->size), diff, src);
AddDeclarationArray(lastAddr + lastSize, DeclarationAlignment::None, diff, "static u8", StringHelper::Sprintf("unaccounted_%06X", lastAddr + lastSize), diff, src);
// AddDeclarationArray(lastAddr + declarations[lastAddr]->size,
// DeclarationAlignment::None, diff, "static u8",
// StringHelper::Sprintf("unaccounted_%06X", lastAddr +
// declarations[lastAddr]->size), diff, src);
AddDeclarationArray(
lastAddr + lastSize, DeclarationAlignment::None, diff, "static u8",
StringHelper::Sprintf("unaccounted_%06X", lastAddr + lastSize), diff,
src);
}
}
}
@ -921,7 +985,9 @@ string ZFile::ProcessDeclarations()
}
// TODO: THIS CONTAINS REDUNDANCIES. CLEAN THIS UP!
if (lastAddr + declarations[lastAddr]->size < rawData.size() && lastAddr + declarations[lastAddr]->size >= rangeStart && lastAddr + declarations[lastAddr]->size < rangeEnd)
if (lastAddr + declarations[lastAddr]->size < rawData.size() &&
lastAddr + declarations[lastAddr]->size >= rangeStart &&
lastAddr + declarations[lastAddr]->size < rangeEnd)
{
int diff = (int)(rawData.size() - (lastAddr + declarations[lastAddr]->size));
@ -929,7 +995,8 @@ string ZFile::ProcessDeclarations()
for (int i = 0; i < diff; i++)
{
src += StringHelper::Sprintf("0x%02X, ", rawData[lastAddr + declarations[lastAddr]->size + i]);
src += StringHelper::Sprintf("0x%02X, ",
rawData[lastAddr + declarations[lastAddr]->size + i]);
if (i % 16 == 15)
src += "\n ";
@ -939,34 +1006,37 @@ string ZFile::ProcessDeclarations()
{
if (diff > 0)
{
AddDeclarationArray(lastAddr + declarations[lastAddr]->size, DeclarationAlignment::None, diff, "static u8", StringHelper::Sprintf("unaccounted_%06X", lastAddr + declarations[lastAddr]->size),
AddDeclarationArray(lastAddr + declarations[lastAddr]->size,
DeclarationAlignment::None, diff, "static u8",
StringHelper::Sprintf("unaccounted_%06X",
lastAddr + declarations[lastAddr]->size),
diff, src);
}
}
}
// Go through include declarations
declarationKeysSorted = vector<pair<int32_t, Declaration*>>(declarations.begin(), declarations.end());
sort(declarationKeysSorted.begin(), declarationKeysSorted.end(), [](const auto& lhs, const auto& rhs)
{
return lhs.first < rhs.first;
});
// First, handle the prototypes (static only for now)
int protoCnt = 0;
for (pair<int32_t, Declaration*> item : declarationKeysSorted)
for (pair<int32_t, Declaration*> item : declarations)
{
if (item.second->includePath == "" && StringHelper::StartsWith(item.second->varType, "static ") && !StringHelper::StartsWith(item.second->varName, "unaccounted_"))
if (item.second->includePath == "" &&
StringHelper::StartsWith(item.second->varType, "static ") &&
!StringHelper::StartsWith(item.second->varName, "unaccounted_"))
{
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());
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 += 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(), item.second->varName.c_str());
output += StringHelper::Sprintf("%s %s;\n", item.second->varType.c_str(),
item.second->varName.c_str());
protoCnt++;
}
@ -976,16 +1046,20 @@ string ZFile::ProcessDeclarations()
output += "\n";
// Next, output the actual declarations
for (pair<int32_t, Declaration*> item : declarationKeysSorted)
for (pair<int32_t, Declaration*> item : declarations)
{
if (item.first < rangeStart || item.first >= rangeEnd)
{
if (item.first < rangeStart || item.first >= rangeEnd) {
continue;
}
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());
// 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());
}
else if (item.second->varType != "")
{
@ -995,15 +1069,19 @@ 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());
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 += StringHelper::Sprintf("%s %s[%i] = {\n", item.second->varType.c_str(),
item.second->varName.c_str(),
item.second->arrayItemCnt);
output += item.second->text + "\n";
}
else
{
output += StringHelper::Sprintf("%s %s = { ", item.second->varType.c_str(), item.second->varName.c_str());
output += StringHelper::Sprintf("%s %s = { ", item.second->varType.c_str(),
item.second->varName.c_str());
output += item.second->text;
}
@ -1026,11 +1104,11 @@ string ZFile::ProcessDeclarations()
void ZFile::ProcessDeclarationText(Declaration* decl)
{
int refIndex = 0;
size_t refIndex = 0;
if (decl->references.size() > 0)
{
for (int i = 0; i < decl->text.size() - 1; i++)
for (size_t i = 0; i < decl->text.size() - 1; i++)
{
char c = decl->text[i];
char c2 = decl->text[i + 1];
@ -1052,11 +1130,14 @@ void ZFile::ProcessDeclarationText(Declaration* decl)
int itemSize = refDecl->size / refDecl->arrayItemCnt;
int itemIndex = (decl->references[refIndex] - refDeclAddr) / itemSize;
decl->text.replace(i, 2, StringHelper::Sprintf("&%s[%i]", refDecl->varName.c_str(), itemIndex));
decl->text.replace(i, 2,
StringHelper::Sprintf(
"&%s[%i]", refDecl->varName.c_str(), itemIndex));
}
else
{
decl->text.replace(i, 2, StringHelper::Sprintf("ERROR ARRAYITEMCNT = 0"));
decl->text.replace(i, 2,
StringHelper::Sprintf("ERROR ARRAYITEMCNT = 0"));
}
}
else
@ -1077,29 +1158,30 @@ string ZFile::ProcessExterns()
{
string output = "";
auto declarationKeysSorted = vector<pair<int32_t, Declaration*>>(declarations.begin(), declarations.end());
sort(declarationKeysSorted.begin(), declarationKeysSorted.end(), [](const auto& lhs, const auto& rhs)
for (pair<int32_t, Declaration*> item : declarations)
{
return lhs.first < rhs.first;
});
for (pair<int32_t, Declaration*> item : declarationKeysSorted)
if (item.first < rangeStart || item.first >= rangeEnd)
{
if (item.first < rangeStart || item.first >= rangeEnd) {
continue;
}
if (!StringHelper::StartsWith(item.second->varType, "static ") && item.second->varType != "")// && item.second->includePath == "")
if (!StringHelper::StartsWith(item.second->varType, "static ") &&
item.second->varType != "") // && item.second->includePath == "")
{
if (item.second->isArray)
{
if (item.second->arrayItemCnt == 0)
output += StringHelper::Sprintf("extern %s %s[];\n", item.second->varType.c_str(), item.second->varName.c_str());
output +=
StringHelper::Sprintf("extern %s %s[];\n", item.second->varType.c_str(),
item.second->varName.c_str());
else
output += StringHelper::Sprintf("extern %s %s[%i];\n", item.second->varType.c_str(), item.second->varName.c_str(), item.second->arrayItemCnt);
output += StringHelper::Sprintf(
"extern %s %s[%i];\n", item.second->varType.c_str(),
item.second->varName.c_str(), item.second->arrayItemCnt);
}
else
output += StringHelper::Sprintf("extern %s %s;\n", item.second->varType.c_str(), item.second->varName.c_str());
output += StringHelper::Sprintf("extern %s %s;\n", item.second->varType.c_str(),
item.second->varName.c_str());
}
}

View file

@ -1,9 +1,9 @@
#pragma once
#include <vector>
#include <string>
#include "tinyxml2.h"
#include <vector>
#include "ZResource.h"
#include "tinyxml2.h"
enum class ZFileMode
{
@ -28,13 +28,14 @@ enum class ZGame
class ZFile
{
public:
std::map<int32_t, Declaration*> declarations;
std::map<uint32_t, Declaration*> declarations;
std::string defines;
std::vector<ZResource*> resources;
uint32_t baseAddress, rangeStart, rangeEnd;
ZFile(std::string nOutPath, std::string nName);
ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, std::string nBasePath, std::string nOutPath, std::string filename, bool placeholderMode);
ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, std::string nBasePath, std::string nOutPath,
std::string filename, bool placeholderMode);
~ZFile();
std::string GetVarName(int address);
@ -44,14 +45,24 @@ public:
void BuildSourceFile(std::string outputDir);
void AddResource(ZResource* res);
Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size, std::string varType, std::string varName, std::string body);
Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, DeclarationPadding padding, uint32_t size, std::string varType, std::string varName, std::string body);
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, uint32_t size, std::string varType, std::string varName, int arrayItemCnt, std::string body);
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, DeclarationPadding padding, uint32_t size, std::string varType, std::string varName, int arrayItemCnt, std::string body);
Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, uint32_t size,
std::string varType, std::string varName, std::string body);
Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment,
DeclarationPadding padding, uint32_t size, std::string varType,
std::string varName, std::string body);
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
uint32_t size, std::string varType, std::string varName,
int arrayItemCnt, std::string body);
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
DeclarationPadding padding, uint32_t size, std::string varType,
std::string varName, int arrayItemCnt, std::string body);
Declaration* AddDeclarationPlaceholder(uint32_t address);
Declaration* AddDeclarationPlaceholder(uint32_t address, std::string varName);
Declaration* AddDeclarationInclude(uint32_t address, std::string includePath, uint32_t size, std::string varType, std::string varName);
Declaration* AddDeclarationIncludeArray(uint32_t address, std::string includePath, uint32_t size, std::string varType, std::string varName, int arrayItemCnt);
Declaration* AddDeclarationInclude(uint32_t address, std::string includePath, uint32_t size,
std::string varType, std::string varName);
Declaration* AddDeclarationIncludeArray(uint32_t address, std::string includePath,
uint32_t size, std::string varType, std::string varName,
int arrayItemCnt);
std::string GetDeclarationName(uint32_t address);
std::string GetDeclarationName(uint32_t address, std::string defaultResult);
Declaration* GetDeclaration(uint32_t address);
@ -69,7 +80,8 @@ protected:
std::string sourceOutput;
ZFile();
void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename, bool placeholderMode);
void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename,
bool placeholderMode);
void GenerateSourceFiles(std::string outputDir);
void GenerateHLIntermediette();
void AddDeclarationDebugChecks(uint32_t address);

View file

@ -1,12 +1,11 @@
#include "ZLimb.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "Globals.h"
#include <cassert>
#include "BitConverter.h"
#include "Globals.h"
#include "StringHelper.h"
using namespace std;
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset)
{
unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00);
@ -17,15 +16,16 @@ Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t f
unk_8 = BitConverter::ToInt8BE(rawData, fileOffset + 0x08);
unk_9 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x09);
}
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index)
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index)
: Struct_800A57C0(rawData, fileOffset + index * GetRawDataSize())
{
}
std::string Struct_800A57C0::GetSourceOutputCode() const
{
return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X",
unk_0, unk_2, unk_4, unk_6, unk_7, unk_8, unk_9);
return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X", unk_0, unk_2, unk_4, unk_6,
unk_7, unk_8, unk_9);
}
size_t Struct_800A57C0::GetRawDataSize()
@ -38,7 +38,6 @@ std::string Struct_800A57C0::GetSourceTypeName()
return "Struct_800A57C0";
}
Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset)
{
unk_0 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x00);
@ -47,15 +46,15 @@ Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32
z = BitConverter::ToInt16BE(rawData, fileOffset + 0x06);
unk_8 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x08);
}
Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index)
Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index)
: Struct_800A598C_2(rawData, fileOffset + index * GetRawDataSize())
{
}
std::string Struct_800A598C_2::GetSourceOutputCode() const
{
return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X",
unk_0, x, y, z, unk_8);
return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", unk_0, x, y, z, unk_8);
}
size_t Struct_800A598C_2::GetRawDataSize()
@ -68,8 +67,8 @@ std::string Struct_800A598C_2::GetSourceTypeName()
return "Struct_800A598C_2";
}
Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset)
Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData,
uint32_t fileOffset)
: parent(parent)
{
unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00);
@ -78,21 +77,26 @@ Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawD
unk_8 = BitConverter::ToUInt32BE(rawData, fileOffset + 0x08);
unk_C = BitConverter::ToUInt32BE(rawData, fileOffset + 0x0C);
if (unk_8 != 0) {
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
for (size_t i = 0; i < unk_0; i++) {
for (size_t i = 0; i < unk_0; i++)
{
unk_8_arr.emplace_back(rawData, unk_8_Offset, i);
}
}
if (unk_C != 0) {
if (unk_C != 0)
{
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
for (size_t i = 0; i < unk_2; i++) {
for (size_t i = 0; i < unk_2; i++)
{
unk_C_arr.emplace_back(rawData, unk_C_Offset, i);
}
}
}
Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index)
Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData,
uint32_t fileOffset, size_t index)
: Struct_800A598C(parent, rawData, fileOffset + index * GetRawDataSize())
{
}
@ -101,52 +105,62 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
{
string entryStr;
if (unk_8 != 0) {
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
string unk_8_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
string unk_8_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
size_t arrayItemCnt = unk_8_arr.size();
entryStr = "";
size_t i = 0;
for (auto& child: unk_8_arr) {
entryStr += StringHelper::Sprintf(" { %s },%s",
child.GetSourceOutputCode().c_str(),
for (auto& child : unk_8_arr)
{
entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(),
(++i < arrayItemCnt) ? "\n" : "");
}
Declaration* decl = parent->GetDeclaration(unk_8_Offset);
if (decl == nullptr) {
parent->AddDeclarationArray(
unk_8_Offset, DeclarationAlignment::None,
arrayItemCnt * Struct_800A57C0::GetRawDataSize(), Struct_800A57C0::GetSourceTypeName(),
unk_8_Str, arrayItemCnt, entryStr);
if (decl == nullptr)
{
parent->AddDeclarationArray(unk_8_Offset, DeclarationAlignment::None,
arrayItemCnt * Struct_800A57C0::GetRawDataSize(),
Struct_800A57C0::GetSourceTypeName(), unk_8_Str,
arrayItemCnt, entryStr);
}
else {
else
{
decl->text = entryStr;
}
}
if (unk_C != 0) {
if (unk_C != 0)
{
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
string unk_C_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
string unk_C_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
size_t arrayItemCnt = unk_C_arr.size();
entryStr = "";
size_t i = 0;
for (auto& child: unk_C_arr) {
entryStr += StringHelper::Sprintf(" { %s },%s",
child.GetSourceOutputCode().c_str(),
for (auto& child : unk_C_arr)
{
entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(),
(++i < arrayItemCnt) ? "\n" : "");
}
Declaration* decl = parent->GetDeclaration(unk_C_Offset);
if (decl == nullptr) {
parent->AddDeclarationArray(
unk_C_Offset, DeclarationAlignment::None,
arrayItemCnt * Struct_800A598C_2::GetRawDataSize(), Struct_800A598C_2::GetSourceTypeName(),
unk_C_Str, arrayItemCnt, entryStr);
if (decl == nullptr)
{
parent->AddDeclarationArray(unk_C_Offset, DeclarationAlignment::None,
arrayItemCnt * Struct_800A598C_2::GetRawDataSize(),
Struct_800A598C_2::GetSourceTypeName(), unk_C_Str,
arrayItemCnt, entryStr);
}
else {
else
{
decl->text = entryStr;
}
}
@ -157,21 +171,27 @@ std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) cons
string entryStr;
string unk_8_Str = "NULL";
if (unk_8 != 0) {
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
unk_8_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
unk_8_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
}
string unk_C_Str = "NULL";
if (unk_C != 0) {
if (unk_C != 0)
{
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
unk_C_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
unk_C_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
}
entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n",
unk_8_Str.c_str(), unk_C_Str.c_str());
entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4,
unk_8_Str.c_str(), unk_C_Str.c_str());
entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(),
unk_C_Str.c_str());
return entryStr;
}
@ -186,8 +206,8 @@ std::string Struct_800A598C::GetSourceTypeName()
return "Struct_800A598C";
}
Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& nRawData, uint32_t fileOffset)
Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& nRawData,
uint32_t fileOffset)
: parent(parent), rawData(nRawData)
{
unk_0 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x00);
@ -195,14 +215,17 @@ Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& nRaw
unk_4 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x04);
unk_8 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x08);
if (unk_4 != 0) {
if (unk_4 != 0)
{
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
for (size_t i = 0; i < unk_2; i++) {
for (size_t i = 0; i < unk_2; i++)
{
unk_4_arr.emplace_back(parent, nRawData, unk_4_Offset, i);
}
}
}
Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index)
Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& rawData,
uint32_t fileOffset, size_t index)
: Struct_800A5E28(parent, rawData, fileOffset + index * GetRawDataSize())
{
}
@ -214,38 +237,47 @@ Struct_800A5E28::~Struct_800A5E28()
void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
{
if (unk_4 != 0) {
if (unk_4 != 0)
{
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
string unk_4_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
string unk_4_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
string entryStr = "";
uint16_t arrayItemCnt = unk_4_arr.size();
size_t i = 0;
for (auto& child: unk_4_arr) {
for (auto& child : unk_4_arr)
{
child.PreGenSourceFiles(prefix);
entryStr += StringHelper::Sprintf(" { %s },%s",
child.GetSourceOutputCode(prefix).c_str(),
entryStr +=
StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode(prefix).c_str(),
(++i < arrayItemCnt) ? "\n" : "");
}
Declaration* decl = parent->GetDeclaration(unk_4_Offset);
if (decl == nullptr) {
parent->AddDeclarationArray(
unk_4_Offset, DeclarationAlignment::None,
arrayItemCnt * Struct_800A598C::GetRawDataSize(), Struct_800A598C::GetSourceTypeName(),
unk_4_Str, arrayItemCnt, entryStr);
if (decl == nullptr)
{
parent->AddDeclarationArray(unk_4_Offset, DeclarationAlignment::None,
arrayItemCnt * Struct_800A598C::GetRawDataSize(),
Struct_800A598C::GetSourceTypeName(), unk_4_Str,
arrayItemCnt, entryStr);
}
else {
else
{
decl->text = entryStr;
}
}
if (unk_8 != 0) {
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
int dlistLength = ZDisplayList::GetDListLength(rawData, unk_8_Offset, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
int dlistLength = ZDisplayList::GetDListLength(
rawData, unk_8_Offset,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength);
unk_8_dlist->parent = parent;
@ -260,33 +292,40 @@ std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) cons
string entryStr = "";
string unk_4_Str = "NULL";
if (unk_4 != 0) {
if (unk_4 != 0)
{
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(unk_4_Offset);
if (decl == nullptr) {
unk_4_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
if (decl == nullptr)
{
unk_4_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
}
else {
else
{
unk_4_Str = decl->varName;
}
}
string unk_8_Str = "NULL";
if (unk_8 != 0) {
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(unk_8_Offset);
if (decl == nullptr) {
if (decl == nullptr)
{
// Something went wrong...
unk_8_Str = StringHelper::Sprintf("0x%08X", unk_8);
}
else {
else
{
unk_8_Str = decl->varName;
}
}
return StringHelper::Sprintf("\n %i, ARRAY_COUNTU(%s),\n %s, %s\n",
unk_0, unk_4_Str.c_str(),
unk_4_Str.c_str(), unk_8_Str.c_str());
return StringHelper::Sprintf("\n %i, ARRAY_COUNTU(%s),\n %s, %s\n", unk_0,
unk_4_Str.c_str(), unk_4_Str.c_str(), unk_8_Str.c_str());
}
size_t Struct_800A5E28::GetRawDataSize()
@ -299,8 +338,8 @@ std::string Struct_800A5E28::GetSourceTypeName()
return "Struct_800A5E28";
}
ZLimb::ZLimb(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex, ZFile* nParent)
ZLimb::ZLimb(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex,
ZFile* nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
@ -311,15 +350,18 @@ ZLimb::ZLimb(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
ParseXML(reader);
ParseRawData();
if (type == ZLimbType::Skin) {
if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0) {
if (type == ZLimbType::Skin)
{
if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0)
{
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset);
}
}
}
ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData, int nRawDataIndex, ZFile* nParent)
ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
int nRawDataIndex, ZFile* nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
@ -338,28 +380,45 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
// Reading from a <Skeleton/>
const char* limbType = reader->Attribute("LimbType");
if (limbType == nullptr) {
if (limbType == nullptr)
{
// Reading from a <Limb/>
limbType = reader->Attribute("Type");
}
if (limbType == nullptr) {
fprintf(stderr, "ZLimb::ParseXML: Warning in '%s'.\n\t Missing 'LimbType' attribute in xml. Defaulting to 'Standard'.\n", name.c_str());
if (limbType == nullptr)
{
fprintf(stderr,
"ZLimb::ParseXML: Warning in '%s'.\n\t Missing 'LimbType' attribute in xml. "
"Defaulting to 'Standard'.\n",
name.c_str());
type = ZLimbType::Standard;
}
else {
else
{
string limbTypeStr(limbType);
if (limbTypeStr == "Standard") {
if (limbTypeStr == "Standard")
{
type = ZLimbType::Standard;
}
else if(limbTypeStr == "LOD") {
else if (limbTypeStr == "LOD")
{
type = ZLimbType::LOD;
}
else if(limbTypeStr == "Skin") {
else if (limbTypeStr == "Skin")
{
type = ZLimbType::Skin;
}
else {
fprintf(stderr, "ZLimb::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. Defaulting to 'Standard'.\n", name.c_str(), limbType);
else if (limbTypeStr == "Curve")
{
type = ZLimbType::Curve;
}
else
{
fprintf(stderr,
"ZLimb::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. "
"Defaulting to 'Standard'.\n",
name.c_str(), limbType);
type = ZLimbType::Standard;
}
}
@ -367,6 +426,16 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
void ZLimb::ParseRawData()
{
if (type == ZLimbType::Curve)
{
childIndex = rawData.at(rawDataIndex + 0);
siblingIndex = rawData.at(rawDataIndex + 1);
dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
return;
}
transX = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
transY = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
transZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
@ -374,36 +443,39 @@ void ZLimb::ParseRawData()
childIndex = rawData.at(rawDataIndex + 6);
siblingIndex = rawData.at(rawDataIndex + 7);
switch (type) {
switch (type)
{
case ZLimbType::LOD:
farDListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
case ZLimbType::Standard:
dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
break;
case ZLimbType::Skin:
skinSegmentType = static_cast<ZLimbSkinType>(BitConverter::ToInt32BE(rawData, rawDataIndex + 8));
skinSegmentType =
static_cast<ZLimbSkinType>(BitConverter::ToInt32BE(rawData, rawDataIndex + 8));
skinSegment = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
break;
}
}
ZLimb* ZLimb::FromXML(tinyxml2::XMLElement* reader, vector<uint8_t> nRawData, int rawDataIndex, string nRelPath, ZFile* parent)
ZLimb* ZLimb::FromXML(tinyxml2::XMLElement* reader, vector<uint8_t> nRawData, int rawDataIndex,
string nRelPath, ZFile* parent)
{
ZLimb* limb = new ZLimb(reader, nRawData, rawDataIndex, parent);
limb->relativePath = std::move(nRelPath);
limb->parent->AddDeclaration(
limb->GetFileAddress(), DeclarationAlignment::None, limb->GetRawDataSize(),
limb->GetSourceTypeName(), limb->name, "");
limb->parent->AddDeclaration(limb->GetFileAddress(), DeclarationAlignment::None,
limb->GetRawDataSize(), limb->GetSourceTypeName(), limb->name, "");
return limb;
}
int ZLimb::GetRawDataSize()
{
switch (type) {
switch (type)
{
case ZLimbType::Standard:
case ZLimbType::Curve:
return 0x0C;
case ZLimbType::LOD:
case ZLimbType::Skin:
@ -417,23 +489,33 @@ string ZLimb::GetSourceOutputCode(const std::string& prefix)
string dListStr = "NULL";
string dListStr2 = "NULL";
if (dListPtr != 0) {
dListStr = GetLimbDListSourceOutputCode(prefix, "", dListPtr);
if (dListPtr != 0)
{
string limbPrefix = type == ZLimbType::Curve ? "Curve" : "";
dListStr = GetLimbDListSourceOutputCode(prefix, limbPrefix, dListPtr);
}
if (farDListPtr != 0) {
dListStr2 = GetLimbDListSourceOutputCode(prefix, "Far", farDListPtr);
if (dList2Ptr != 0)
{
string limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far";
dListStr2 = GetLimbDListSourceOutputCode(prefix, limbPrefix, dList2Ptr);
}
string entryStr = StringHelper::Sprintf("\n { %i, %i, %i },\n 0x%02X, 0x%02X,\n",
transX, transY, transZ, childIndex, siblingIndex);
string entryStr = "";
if (type != ZLimbType::Curve)
{
entryStr += StringHelper::Sprintf("\n { %i, %i, %i },", transX, transY, transZ);
}
switch (type) {
entryStr += StringHelper::Sprintf("\n 0x%02X, 0x%02X,\n", childIndex, siblingIndex);
switch (type)
{
case ZLimbType::Standard:
entryStr += StringHelper::Sprintf(" %s\n", dListStr.c_str());
break;
case ZLimbType::LOD:
entryStr += StringHelper::Sprintf(" { %s, %s }\n",
dListStr.c_str(), dListStr2.c_str());
case ZLimbType::Curve:
entryStr += StringHelper::Sprintf(" { %s, %s }\n", dListStr.c_str(), dListStr2.c_str());
break;
case ZLimbType::Skin:
entryStr += GetSourceOutputCodeSkin(prefix);
@ -441,10 +523,13 @@ string ZLimb::GetSourceOutputCode(const std::string& prefix)
}
Declaration* decl = parent->GetDeclaration(GetFileAddress());
if (decl == nullptr) {
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(), GetSourceTypeName(), name, entryStr);
if (decl == nullptr)
{
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), name, entryStr);
}
else {
else
{
decl->text = entryStr;
}
@ -468,13 +553,16 @@ ZLimbType ZLimb::GetLimbType()
const char* ZLimb::GetSourceTypeName(ZLimbType limbType)
{
switch (limbType) {
switch (limbType)
{
case ZLimbType::Standard:
return "StandardLimb";
case ZLimbType::LOD:
return "LodLimb";
case ZLimbType::Skin:
return "SkinLimb";
case ZLimbType::Curve:
return "SkelCurveLimb";
}
return "StandardLimb";
}
@ -484,9 +572,11 @@ uint32_t ZLimb::GetFileAddress()
return Seg2Filespace(segAddress, parent->baseAddress);
}
std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix, const std::string& limbPrefix, segptr_t dListPtr)
std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix,
const std::string& limbPrefix, segptr_t dListPtr)
{
if (dListPtr == 0) {
if (dListPtr == 0)
{
return "NULL";
}
@ -494,16 +584,21 @@ std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix, const
string dListStr;
Declaration* decl = parent->GetDeclaration(dListOffset);
if (decl == nullptr) {
dListStr = StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), dListOffset);
if (decl == nullptr)
{
dListStr = StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(),
dListOffset);
int dlistLength = ZDisplayList::GetDListLength(rawData, dListOffset, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
int dlistLength = ZDisplayList::GetDListLength(
rawData, dListOffset,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
auto& dList = dLists.emplace_back(rawData, dListOffset, dlistLength);
dList.parent = parent;
dList.SetName(dListStr);
dList.GetSourceOutputCode(prefix);
}
else {
else
{
dListStr = decl->varName;
}
@ -515,7 +610,8 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
assert(type == ZLimbType::Skin);
assert(skinSegmentType == ZLimbSkinType::SkinType_4);
if (skinSegment == 0) {
if (skinSegment == 0)
{
return "NULL";
}
@ -523,18 +619,21 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
string struct_800A5E28_Str;
Declaration* decl = parent->GetDeclaration(skinSegmentOffset);
if (decl == nullptr) {
struct_800A5E28_Str = StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset);
if (decl == nullptr)
{
struct_800A5E28_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset);
segmentStruct.PreGenSourceFiles(prefix);
string entryStr = segmentStruct.GetSourceOutputCode(prefix);
parent->AddDeclaration(
skinSegmentOffset, DeclarationAlignment::None,
Struct_800A5E28::GetRawDataSize(), Struct_800A5E28::GetSourceTypeName(),
struct_800A5E28_Str, entryStr);
parent->AddDeclaration(skinSegmentOffset, DeclarationAlignment::None,
Struct_800A5E28::GetRawDataSize(),
Struct_800A5E28::GetSourceTypeName(), struct_800A5E28_Str, entryStr);
}
else {
else
{
struct_800A5E28_Str = decl->varName;
}
@ -547,8 +646,10 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
string skinSegmentStr = "NULL";
if (skinSegment != 0) {
switch (skinSegmentType) {
if (skinSegment != 0)
{
switch (skinSegmentType)
{
case ZLimbSkinType::SkinType_4:
skinSegmentStr = "&" + GetSourceOutputCodeSkin_Type_4(prefix);
break;
@ -556,17 +657,23 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
skinSegmentStr = GetLimbDListSourceOutputCode(prefix, "Skin", skinSegment);
break;
default:
fprintf(stderr, "ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Unknown segment type for SkinLimb: '%i'. \n\tPlease report this.\n", name.c_str(), static_cast<int32_t>(skinSegmentType));
fprintf(stderr,
"ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Unknown segment type "
"for SkinLimb: '%i'. \n\tPlease report this.\n",
name.c_str(), static_cast<int32_t>(skinSegmentType));
case ZLimbSkinType::SkinType_0:
case ZLimbSkinType::SkinType_5:
fprintf(stderr, "ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Segment type for SkinLimb not implemented: '%i'.\n", name.c_str(), static_cast<int32_t>(skinSegmentType));
fprintf(stderr,
"ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Segment type for "
"SkinLimb not implemented: '%i'.\n",
name.c_str(), static_cast<int32_t>(skinSegmentType));
skinSegmentStr = StringHelper::Sprintf("0x%08X", skinSegment);
break;
}
}
string entryStr = StringHelper::Sprintf(" 0x%02X, %s\n",
skinSegmentType, skinSegmentStr.c_str());
string entryStr =
StringHelper::Sprintf(" 0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str());
return entryStr;
}

View file

@ -1,17 +1,17 @@
#pragma once
#include <vector>
#include <string>
#include <cstdint>
#include "ZFile.h"
#include <string>
#include <vector>
#include "ZDisplayList.h"
#include "ZFile.h"
enum class ZLimbType
{
Standard,
LOD,
Skin
Skin,
Curve,
};
// TODO: check if more types exists
@ -23,7 +23,6 @@ enum class ZLimbSkinType
SkinType_DList = 11, // Segment = DList address
};
class Struct_800A57C0
{
protected:
@ -39,14 +38,12 @@ public:
Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset);
Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index);
[[nodiscard]]
std::string GetSourceOutputCode() const;
[[nodiscard]] std::string GetSourceOutputCode() const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
};
class Struct_800A598C_2
{
protected:
@ -60,14 +57,12 @@ public:
Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset);
Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index);
[[nodiscard]]
std::string GetSourceOutputCode() const;
[[nodiscard]] std::string GetSourceOutputCode() const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
};
class Struct_800A598C
{
protected:
@ -84,17 +79,16 @@ protected:
public:
Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset);
Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index);
Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index);
void PreGenSourceFiles(const std::string& prefix);
[[nodiscard]]
std::string GetSourceOutputCode(const std::string& prefix) const;
[[nodiscard]] std::string GetSourceOutputCode(const std::string& prefix) const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
};
class Struct_800A5E28
{
protected:
@ -112,18 +106,17 @@ protected:
public:
Struct_800A5E28() = default;
Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset);
Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index);
Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset,
size_t index);
~Struct_800A5E28();
void PreGenSourceFiles(const std::string& prefix);
[[nodiscard]]
std::string GetSourceOutputCode(const std::string& prefix) const;
[[nodiscard]] std::string GetSourceOutputCode(const std::string& prefix) const;
static size_t GetRawDataSize();
static std::string GetSourceTypeName();
};
class ZLimb : public ZResource
{
protected:
@ -136,24 +129,28 @@ protected:
std::vector<ZDisplayList> dLists;
segptr_t farDListPtr = 0; // LOD only
segptr_t dList2Ptr = 0; // LOD and Curve only
ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only
segptr_t skinSegment = 0; // Skin only
Struct_800A5E28 segmentStruct; // Skin only
std::string GetLimbDListSourceOutputCode(const std::string& prefix, const std::string& limbPrefix, segptr_t dListPtr);
std::string GetLimbDListSourceOutputCode(const std::string& prefix,
const std::string& limbPrefix, segptr_t dListPtr);
std::string GetSourceOutputCodeSkin(const std::string& prefix);
std::string GetSourceOutputCodeSkin_Type_4(const std::string& prefix);
public:
ZLimb(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex, ZFile* nParent);
ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData, int nRawDataIndex, ZFile* nParent);
ZLimb(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex,
ZFile* nParent);
ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
int nRawDataIndex, ZFile* nParent);
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
static ZLimb* FromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nRelPath, ZFile* parent);
static ZLimb* FromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData,
int rawDataIndex, std::string nRelPath, ZFile* parent);
int GetRawDataSize() override;
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceTypeName() override;

View file

@ -29,7 +29,6 @@ void ZResource::ParseXML(tinyxml2::XMLElement* reader)
void ZResource::Save(const std::string& outFolder)
{
}
void ZResource::PreGenSourceFiles()
@ -107,7 +106,6 @@ void ZResource::ParseRawData()
void ZResource::GenerateHLIntermediette(HLFileIntermediette& hlFile)
{
}
std::string ZResource::GetSourceTypeName()
@ -125,7 +123,6 @@ void ZResource::CalcHash()
hash = 0;
}
uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress)
{
uint32_t currentPtr = GETSEGOFFSET(segmentedAddress);

View file

@ -1,9 +1,10 @@
#pragma once
#include <map>
#include <stdexcept>
#include <stdint.h>
#include <string>
#include <vector>
#include <stdint.h>
#include "tinyxml2.h"
#define SEGMENT_SCENE 2
@ -39,7 +40,8 @@ enum class ZResourceType
Scalar,
Vector,
Vertex,
CollisionHeader
CollisionHeader,
Symbol,
};
class ZResource
@ -116,15 +118,21 @@ public:
int arrayItemCnt;
std::vector<uint32_t> references;
Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, std::string nText);
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, std::string nText);
Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, int nArrayItemCnt, std::string nText);
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, std::string nVarType, std::string nVarName, bool nIsArray, int nArrayItemCnt, std::string nText);
Declaration(std::string nIncludePath, uint32_t nSize, std::string nVarType, std::string nVarName);
Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType,
std::string nVarName, bool nIsArray, std::string nText);
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize,
std::string nVarType, std::string nVarName, bool nIsArray, std::string nText);
Declaration(DeclarationAlignment nAlignment, uint32_t nSize, std::string nVarType,
std::string nVarName, bool nIsArray, int nArrayItemCnt, std::string nText);
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize,
std::string nVarType, std::string nVarName, bool nIsArray, int nArrayItemCnt,
std::string nText);
Declaration(std::string nIncludePath, uint32_t nSize, std::string nVarType,
std::string nVarName);
protected:
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, std::string nText);
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize,
std::string nText);
};
uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress);

View file

@ -2,8 +2,7 @@
#include <string>
static const std::string ActorList[] =
{
static const std::string ActorList[] = {
/* 0x0000 */ "ACTOR_PLAYER",
/* 0x0001 */ "ACTOR_UNSET_1",
/* 0x0002 */ "ACTOR_EN_TEST",

View file

@ -3,13 +3,15 @@
using namespace std;
EndMarker::EndMarker(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
EndMarker::EndMarker(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
}
string EndMarker::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str());
return StringHelper::Sprintf(
"%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str());
}
string EndMarker::GetCommandCName()

View file

@ -1,14 +1,15 @@
#include "SetActorList.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
#include "../ActorList.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ActorList.h"
#include "../ZRoom.h"
using namespace std;
SetActorList::SetActorList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetActorList::SetActorList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
numActors = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
@ -38,15 +39,14 @@ string SetActorList::GenerateSourceCodePass1(string roomName, int baseAddress)
return "";
}
string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress)
{
string sourceOutput = "";
int numActorsReal = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 16;
size_t numActorsReal = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 16;
actors = vector<ActorSpawnEntry*>();
uint32_t currentPtr = segmentOffset;
for (int i = 0; i < numActorsReal; i++)
for (size_t i = 0; i < numActorsReal; i++)
{
ActorSpawnEntry* entry = new ActorSpawnEntry(_rawData, currentPtr);
actors.push_back(entry);
@ -54,32 +54,47 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress)
currentPtr += 16;
}
sourceOutput += StringHelper::Sprintf("%s 0x%02X, (u32)%sActorList0x%06X };", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), numActors, roomName.c_str(), segmentOffset);
sourceOutput +=
StringHelper::Sprintf("%s 0x%02X, (u32)%sActorList0x%06X };",
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);
// zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None,
// DeclarationPadding::None, GetRawDataSize(), "SCmdActorList",
//ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress), sourceOutput);
string declaration = "";
int index = 0;
size_t index = 0;
for (ActorSpawnEntry* entry : actors)
{
uint16_t actorNum = entry->actorNum;
// SW97 Actor 0x22 was removed, so we want to not output a working actor.
if (actorNum == 0x22 && Globals::Instance->game == ZGame::OOT_SW97)
declaration += StringHelper::Sprintf("\t//{ %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", /*StringHelper::Sprintf("SW_REMOVED_0x%04X", actorNum).c_str()*/ "ACTOR_DUNGEON_KEEP", entry->posX, entry->posY, entry->posZ, entry->rotX, entry->rotY, entry->rotZ, (uint16_t)entry->initVar, segmentOffset + (index * 16));
declaration += StringHelper::Sprintf(
"\t//{ %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X",
/*StringHelper::Sprintf("SW_REMOVED_0x%04X", actorNum).c_str()*/
"ACTOR_DUNGEON_KEEP", entry->posX, entry->posY, entry->posZ, entry->rotX,
entry->rotY, entry->rotZ, (uint16_t)entry->initVar, segmentOffset + (index * 16));
else
{
// SW97 Actor 0x23 and above are shifted up by one because 0x22 was removed between SW97 and retail.
// We need to shift down by one
// SW97 Actor 0x23 and above are shifted up by one because 0x22 was removed between SW97
// and retail. We need to shift down by one
if (Globals::Instance->game == ZGame::OOT_SW97 && actorNum >= 0x23)
actorNum--;
if (actorNum < sizeof(ActorList) / sizeof(ActorList[0]))
declaration += StringHelper::Sprintf("\t{ %s, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", ActorList[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, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X",
ActorList[actorNum].c_str(), entry->posX, entry->posY,
entry->posZ, entry->rotX, entry->rotY, entry->rotZ,
(uint16_t)entry->initVar, segmentOffset + (index * 16));
else
declaration += StringHelper::Sprintf("\t{ 0x%04X, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", actorNum, entry->posX, entry->posY, entry->posZ, entry->rotX, entry->rotY, entry->rotZ, (uint16_t)entry->initVar, segmentOffset + (index * 16));
declaration += StringHelper::Sprintf(
"\t{ 0x%04X, %i, %i, %i, %i, %i, %i, 0x%04X }, //0x%06X", actorNum, entry->posX,
entry->posY, entry->posZ, entry->rotX, entry->rotY, entry->rotZ,
(uint16_t)entry->initVar, segmentOffset + (index * 16));
if (index < actors.size() - 1)
declaration += "\n";
@ -88,8 +103,10 @@ string SetActorList::GenerateSourceCodePass2(string roomName, int baseAddress)
index++;
}
zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, actors.size() * 16,
"ActorEntry", StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset), GetActorListArraySize(), declaration);
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, actors.size() * 16,
"ActorEntry", StringHelper::Sprintf("%sActorList0x%06X", roomName.c_str(), segmentOffset),
GetActorListArraySize(), declaration);
return sourceOutput;
}
@ -99,12 +116,13 @@ int32_t SetActorList::GetRawDataSize()
return ZRoomCommand::GetRawDataSize() + ((int)actors.size() * 16);
}
int SetActorList::GetActorListArraySize()
size_t SetActorList::GetActorListArraySize()
{
int actorCount = 0;
size_t actorCount = 0;
// Doing an else-if here so we only do the loop when the game is SW97.
// Actor 0x22 is removed from SW97, so we need to ensure that we don't increment the actor count for it.
// Actor 0x22 is removed from SW97, so we need to ensure that we don't increment the actor count
// for it.
if (Globals::Instance->game == ZGame::OOT_SW97)
{
actorCount = 0;
@ -115,7 +133,7 @@ int SetActorList::GetActorListArraySize()
}
else
{
actorCount = (int)actors.size();
actorCount = actors.size();
}
return actorCount;
@ -123,7 +141,8 @@ int SetActorList::GetActorListArraySize()
string SetActorList::GenerateExterns()
{
return StringHelper::Sprintf("extern ActorEntry %sActorList0x%06X[%i];\n", zRoom->GetName().c_str(), segmentOffset, GetActorListArraySize());
return StringHelper::Sprintf("extern ActorEntry %sActorList0x%06X[%i];\n",
zRoom->GetName().c_str(), segmentOffset, GetActorListArraySize());
}
string SetActorList::GetCommandCName()

View file

@ -32,7 +32,7 @@ public:
virtual std::string GenerateExterns();
private:
int GetActorListArraySize();
size_t GetActorListArraySize();
int numActors;
std::vector<ActorSpawnEntry*> actors;
uint32_t segmentOffset;

View file

@ -1,11 +1,13 @@
#include "SetAlternateHeaders.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
using namespace std;
SetAlternateHeaders::SetAlternateHeaders(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetAlternateHeaders::SetAlternateHeaders(ZRoom* nZRoom, std::vector<uint8_t> rawData,
int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
@ -30,22 +32,28 @@ string SetAlternateHeaders::GenerateSourceCodePass1(string roomName, int baseAdd
zRoom->commandSets.push_back(CommandSet(address));
}
sourceOutput += StringHelper::Sprintf("%s 0, (u32)&%sAlternateHeaders0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), roomName.c_str(), segmentOffset);
sourceOutput +=
StringHelper::Sprintf("%s 0, (u32)&%sAlternateHeaders0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
roomName.c_str(), segmentOffset);
string declaration = "";
for (int i = 0; i < numHeaders; i++)
{
//sprintf(line, "\t0x%06X,\n", headers[i]);
// sprintf(line, "\t0x%06X,\n", headers[i]);
if (headers[i] == 0)
declaration += StringHelper::Sprintf("\t0,\n");
else
declaration += StringHelper::Sprintf("\t(u32)&%sSet%04XCmd00,\n", roomName.c_str(), headers[i] & 0x00FFFFFF);
declaration += StringHelper::Sprintf("\t(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);
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, headers.size() * 4, "u32",
StringHelper::Sprintf("%sAlternateHeaders0x%06X", roomName.c_str(), segmentOffset), 0,
declaration);
return sourceOutput;
}

View file

@ -1,7 +1,7 @@
#pragma once
#include "../ZRoomCommand.h"
#include "../ZRoom.h"
#include "../ZRoomCommand.h"
class SetAlternateHeaders : public ZRoomCommand
{

View file

@ -4,7 +4,8 @@
using namespace std;
SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
cameraMovement = rawData[rawDataIndex + 0x01];
mapHighlight = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
@ -12,7 +13,9 @@ SetCameraSettings::SetCameraSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData
string SetCameraSettings::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), cameraMovement, mapHighlight);
return StringHelper::Sprintf(
"%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
cameraMovement, mapHighlight);
}
string SetCameraSettings::GetCommandCName()

View file

@ -1,20 +1,28 @@
#include "SetCollisionHeader.h"
#include "../ZRoom.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
SetCollisionHeader::SetCollisionHeader(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetCollisionHeader::SetCollisionHeader(ZRoom* nZRoom, std::vector<uint8_t> rawData,
int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
collisionHeader = ZCollisionHeader(nZRoom->parent, StringHelper::Sprintf("%sCollisionHeader0x%06X", nZRoom->GetName().c_str(), segmentOffset), rawData, segmentOffset);
collisionHeader = ZCollisionHeader(
nZRoom->parent,
StringHelper::Sprintf("%sCollisionHeader0x%06X", nZRoom->GetName().c_str(), segmentOffset),
rawData, segmentOffset);
}
string SetCollisionHeader::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x00, (u32)&%sCollisionHeader0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf(
"%s 0x00, (u32)&%sCollisionHeader0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
zRoom->GetName().c_str(), segmentOffset);
}
string SetCollisionHeader::GenerateSourceCodePass2(string roomName, int baseAddress)

View file

@ -1,7 +1,7 @@
#pragma once
#include "../ZRoomCommand.h"
#include "../../ZCollision.h"
#include "../ZRoomCommand.h"
class SetCollisionHeader : public ZRoomCommand
{

View file

@ -1,16 +1,16 @@
#include "SetCutscenes.h"
#include "../ZRoom.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
uint32_t curPtr = segmentOffset;
string output = "";
cutscene = new ZCutscene(rawData, segmentOffset, 9999);
@ -18,8 +18,22 @@ SetCutscenes::SetCutscenes(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawD
output += cutscene->GetSourceOutputCode(zRoom->GetName());
if (segmentOffset != 0)
zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, cutscene->GetRawDataSize(), "s32",
StringHelper::Sprintf("%sCutsceneData0x%06X", zRoom->GetName().c_str(), segmentOffset), 0, output);
{
Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset);
if (decl == nullptr)
{
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16,
cutscene->GetRawDataSize(), "s32",
StringHelper::Sprintf("%sCutsceneData0x%06X", zRoom->GetName().c_str(),
segmentOffset),
0, output);
}
else if (decl->text == "")
{
decl->text = output;
}
}
}
SetCutscenes::~SetCutscenes()
@ -33,7 +47,14 @@ SetCutscenes::~SetCutscenes()
string SetCutscenes::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0, (u32)%sCutsceneData0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), zRoom->GetName().c_str(), segmentOffset);
string pass1 = ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress);
Declaration* decl = zRoom->parent->GetDeclaration(segmentOffset);
if (decl != nullptr)
{
return StringHelper::Sprintf("%s 0, (u32)%s", pass1.c_str(), decl->varName.c_str());
}
return StringHelper::Sprintf("%s 0, (u32)%sCutsceneData0x%06X", pass1.c_str(),
zRoom->GetName().c_str(), segmentOffset);
}
int32_t SetCutscenes::GetRawDataSize()
@ -43,7 +64,13 @@ int32_t SetCutscenes::GetRawDataSize()
string SetCutscenes::GenerateExterns()
{
return StringHelper::Sprintf("extern s32 %sCutsceneData0x%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);
}
string SetCutscenes::GetCommandCName()

View file

@ -1,7 +1,7 @@
#pragma once
#include "../ZRoomCommand.h"
#include "../../ZCutscene.h"
#include "../ZRoomCommand.h"
class SetCutscenes : public ZRoomCommand
{

View file

@ -3,14 +3,17 @@
using namespace std;
SetEchoSettings::SetEchoSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetEchoSettings::SetEchoSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
echo = rawData[rawDataIndex + 0x07];
}
string SetEchoSettings::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0, { 0 }, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), echo);
return StringHelper::Sprintf(
"%s 0, { 0 }, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
echo);
}
string SetEchoSettings::GetCommandCName()

View file

@ -1,13 +1,14 @@
#include "SetEntranceList.h"
#include "SetStartPositionList.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
#include "SetStartPositionList.h"
using namespace std;
SetEntranceList::SetEntranceList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetEntranceList::SetEntranceList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
entrances = vector<EntranceEntry*>();
@ -24,7 +25,10 @@ SetEntranceList::~SetEntranceList()
string SetEntranceList::GenerateSourceCodePass1(string roomName, int baseAddress)
{
string sourceOutput = StringHelper::Sprintf("%s 0x00, (u32)&%sEntranceList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), zRoom->GetName().c_str(), segmentOffset);
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
@ -45,19 +49,24 @@ string SetEntranceList::GenerateSourceCodePass1(string roomName, int baseAddress
for (EntranceEntry* entry : entrances)
{
declaration += StringHelper::Sprintf("\t{ 0x%02X, 0x%02X }, //0x%06X \n", entry->startPositionIndex, entry->roomToLoad, segmentOffset + (index * 2));
declaration +=
StringHelper::Sprintf("\t{ 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);
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()
{
return StringHelper::Sprintf("extern EntranceEntry %sEntranceList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf("extern EntranceEntry %sEntranceList0x%06X[];\n",
zRoom->GetName().c_str(), segmentOffset);
}
string SetEntranceList::GetCommandCName()

View file

@ -1,12 +1,13 @@
#include "SetExitList.h"
#include "../ZRoom.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
SetExitList::SetExitList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetExitList::SetExitList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
exits = vector<uint16_t>();
@ -20,7 +21,10 @@ SetExitList::SetExitList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDat
string SetExitList::GenerateSourceCodePass1(string roomName, int baseAddress)
{
string sourceOutput = StringHelper::Sprintf("%s 0x00, (u32)&%sExitList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), zRoom->GetName().c_str(), segmentOffset);
string sourceOutput =
StringHelper::Sprintf("%s 0x00, (u32)&%sExitList0x%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
@ -38,9 +42,12 @@ string SetExitList::GenerateSourceCodePass1(string roomName, int baseAddress)
string declaration = "";
for (uint16_t exit : exits)
declaration += StringHelper::Sprintf("\t0x%04X,\n", exit);;
declaration += StringHelper::Sprintf("\t0x%04X,\n", exit);
;
zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, exits.size() * 2, "u16", StringHelper::Sprintf("%sExitList0x%06X", zRoom->GetName().c_str(), segmentOffset),
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, exits.size() * 2, "u16",
StringHelper::Sprintf("%sExitList0x%06X", zRoom->GetName().c_str(), segmentOffset),
exits.size(), declaration);
return sourceOutput;
@ -48,7 +55,9 @@ string SetExitList::GenerateSourceCodePass1(string roomName, int baseAddress)
string SetExitList::GenerateExterns()
{
return StringHelper::Sprintf("extern u16 %sExitList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);;
return StringHelper::Sprintf("extern u16 %sExitList0x%06X[];\n", zRoom->GetName().c_str(),
segmentOffset);
;
}
string SetExitList::GetCommandCName()

View file

@ -4,13 +4,15 @@
using namespace std;
SetLightList::SetLightList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetLightList::SetLightList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
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);
// std::string declarations = StringHelper::Sprintf("LightInfo %sLightInfo0x%06X[] =\n{\n",
// this->ptrRoom->GetName().c_str(), this->segment);
string declarations = "";
for (int i = 0; i < this->numLights; i++)
@ -20,21 +22,29 @@ SetLightList::SetLightList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawD
for (int y = 0; y < 6; y++)
{
params.push_back(BitConverter::ToInt16BE(rawData, this->segment + ((0xE * i) + 2 + (y * 2))));
params.push_back(
BitConverter::ToInt16BE(rawData, this->segment + ((0xE * i) + 2 + (y * 2))));
}
declarations += StringHelper::Sprintf("\t{ 0x%02X, { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X } },\n", type, params[0], params[1], params[2], params[3], params[4], params[5]);
declarations += StringHelper::Sprintf(
"\t{ 0x%02X, { 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X, 0x%04X } },\n", type, params[0],
params[1], params[2], params[3], params[4], params[5]);
}
declarations += "};\n";
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);
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, int baseAddress)
{
return StringHelper::Sprintf("%s %i, &%sLightInfo0x%06X};", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), this->numLights, this->ptrRoom->GetName().c_str(), this->segment);
return StringHelper::Sprintf(
"%s %i, &%sLightInfo0x%06X};",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), this->numLights,
this->ptrRoom->GetName().c_str(), this->segment);
}
string SetLightList::GetCommandCName()
@ -44,7 +54,8 @@ string SetLightList::GetCommandCName()
string SetLightList::GenerateExterns()
{
return StringHelper::Sprintf("extern LightInfo %sLightInfo0x%06X[];\n", this->ptrRoom->GetName().c_str(), this->segment);
return StringHelper::Sprintf("extern LightInfo %sLightInfo0x%06X[];\n",
this->ptrRoom->GetName().c_str(), this->segment);
}
RoomCommand SetLightList::GetRoomCommand()

View file

@ -2,9 +2,9 @@
#include <string>
#include "ZFile.h"
#include "../ZRoom.h"
#include "../ZRoomCommand.h"
#include "ZFile.h"
class SetLightList : public ZRoomCommand
{

View file

@ -1,12 +1,14 @@
#include "SetLightingSettings.h"
#include "../ZRoom.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData,
int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
uint8_t numLights = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
@ -20,18 +22,24 @@ SetLightingSettings::SetLightingSettings(ZRoom* nZRoom, std::vector<uint8_t> raw
for (int i = 0; i < numLights; 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 \n",
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 \n",
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));
settings[i]->fogClrR, settings[i]->fogClrG, settings[i]->fogClrB, settings[i]->unk,
settings[i]->drawDistance, segmentOffset + (i * 22));
}
zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, numLights * 22, "LightSettings",
StringHelper::Sprintf("%sLightSettings0x%06X", zRoom->GetName().c_str(), segmentOffset), numLights, declaration);
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, numLights * 22,
"LightSettings",
StringHelper::Sprintf("%sLightSettings0x%06X", zRoom->GetName().c_str(), segmentOffset),
numLights, declaration);
}
}
@ -43,7 +51,10 @@ SetLightingSettings::~SetLightingSettings()
string SetLightingSettings::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s %i, (u32)&%sLightSettings0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), settings.size(), zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf(
"%s %i, (u32)&%sLightSettings0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), settings.size(),
zRoom->GetName().c_str(), segmentOffset);
}
string SetLightingSettings::GenerateSourceCodePass2(string roomName, int baseAddress)
@ -58,7 +69,8 @@ string SetLightingSettings::GetCommandCName()
string SetLightingSettings::GenerateExterns()
{
return StringHelper::Sprintf("extern LightSettings %sLightSettings0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf("extern LightSettings %sLightSettings0x%06X[];\n",
zRoom->GetName().c_str(), segmentOffset);
}
RoomCommand SetLightingSettings::GetRoomCommand()

View file

@ -1,14 +1,16 @@
#include "SetMesh.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
#include <Globals.h>
#include <Path.h>
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include <Path.h>
#include <Globals.h>
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex, int segAddressOffset) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
int segAddressOffset)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
data = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
@ -39,11 +41,17 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
{
MeshEntry0* entry = new MeshEntry0();
entry->opaqueDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 0));
entry->translucentDListAddr = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 4));
entry->translucentDListAddr =
GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr + 4));
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));
entry->opaqueDList = new ZDisplayList(
rawData, entry->opaqueDListAddr,
ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr,
Globals::Instance->game == ZGame::OOT_SW97 ?
DListType::F3DEX :
DListType::F3DZEX));
entry->opaqueDList->scene = zRoom->scene;
entry->opaqueDList->parent = zRoom->parent;
GenDListDeclarations(rawData, entry->opaqueDList);
@ -51,7 +59,12 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
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));
entry->translucentDList = new ZDisplayList(
rawData, entry->translucentDListAddr,
ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr,
Globals::Instance->game == ZGame::OOT_SW97 ?
DListType::F3DEX :
DListType::F3DZEX));
entry->translucentDList->scene = zRoom->scene;
entry->translucentDList->parent = zRoom->parent;
GenDListDeclarations(rawData, entry->translucentDList);
@ -65,38 +78,54 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
declaration += StringHelper::Sprintf("{ 0 }, 0x%02X, ", meshHeader0->entries.size());
if (meshHeader0->dListStart != 0)
declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ", zRoom->GetName().c_str(), meshHeader0->dListStart);
declaration += StringHelper::Sprintf("(u32)&%sMeshDListEntry0x%06X, ",
zRoom->GetName().c_str(), meshHeader0->dListStart);
else
declaration += "0, ";
if (meshHeader0->dListEnd != 0)
declaration += StringHelper::Sprintf("(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)", zRoom->GetName().c_str(), meshHeader0->dListStart, zRoom->GetName().c_str(), meshHeader0->dListStart);
declaration += StringHelper::Sprintf(
"(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)",
zRoom->GetName().c_str(), meshHeader0->dListStart, zRoom->GetName().c_str(),
meshHeader0->dListStart);
else
declaration += "0";
zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::Align16, 12, "MeshHeader0", StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset),
zRoom->parent->AddDeclaration(
segmentOffset, DeclarationAlignment::Align16, 12, "MeshHeader0",
StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset),
declaration);
declaration = "";
for (int i = 0; i < meshHeader0->entries.size(); i++)
for (size_t i = 0; i < meshHeader0->entries.size(); i++)
{
if (meshHeader0->entries[i]->opaqueDListAddr != 0)
declaration += StringHelper::Sprintf("\t{ (u32)%sDL_%06X, ", zRoom->GetName().c_str(), meshHeader0->entries[i]->opaqueDListAddr);
declaration +=
StringHelper::Sprintf("\t{ (u32)%sDL_%06X, ", zRoom->GetName().c_str(),
meshHeader0->entries[i]->opaqueDListAddr);
else
declaration += "\t{ 0, ";
if (meshHeader0->entries[i]->translucentDListAddr != 0)
declaration += StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(), meshHeader0->entries[i]->translucentDListAddr);
declaration +=
StringHelper::Sprintf("(u32)%sDL_%06X },\n", zRoom->GetName().c_str(),
meshHeader0->entries[i]->translucentDListAddr);
else
declaration += "0 },\n";
}
zRoom->parent->AddDeclarationArray(meshHeader0->dListStart, DeclarationAlignment::None, DeclarationPadding::None, (meshHeader0->entries.size() * 8) + 0, "MeshEntry0",
StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(), meshHeader0->dListStart), meshHeader0->entries.size(), declaration);
zRoom->parent->AddDeclarationArray(
meshHeader0->dListStart, DeclarationAlignment::None, DeclarationPadding::None,
(meshHeader0->entries.size() * 8) + 0, "MeshEntry0",
StringHelper::Sprintf("%sMeshDListEntry0x%06X", zRoom->GetName().c_str(),
meshHeader0->dListStart),
meshHeader0->entries.size(), declaration);
zRoom->parent->AddDeclaration(meshHeader0->dListStart + (meshHeader0->entries.size() * 8) + 0, DeclarationAlignment::None, DeclarationPadding::Pad16, 4, "static s32",
"terminatorMaybe", " 0x01000000 ");
zRoom->parent->AddDeclaration(meshHeader0->dListStart + (meshHeader0->entries.size() * 8) +
0,
DeclarationAlignment::None, DeclarationPadding::Pad16, 4,
"static s32", "terminatorMaybe", " 0x01000000 ");
meshHeader = meshHeader0;
}
@ -112,9 +141,11 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
headerSingle->headerType = 1;
headerSingle->format = fmt;
headerSingle->entryRecord = BitConverter::ToInt32BE(rawData, segmentOffset + 4);// &0x00FFFFFF;
headerSingle->entryRecord =
BitConverter::ToInt32BE(rawData, segmentOffset + 4); // &0x00FFFFFF;
headerSingle->imagePtr = BitConverter::ToInt32BE(rawData, segmentOffset + 8);// &0x00FFFFFF;
headerSingle->imagePtr =
BitConverter::ToInt32BE(rawData, segmentOffset + 8); // &0x00FFFFFF;
headerSingle->unknown = BitConverter::ToInt32BE(rawData, segmentOffset + 12);
headerSingle->unknown2 = BitConverter::ToInt32BE(rawData, segmentOffset + 16);
headerSingle->bgWidth = BitConverter::ToInt16BE(rawData, segmentOffset + 20);
@ -128,10 +159,17 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
headerSingle->entryRecord, headerSingle->imagePtr);
declaration += StringHelper::Sprintf("0x%06X, 0x%06X, %i, %i, %i, %i, %i, %i\n",
headerSingle->unknown, headerSingle->unknown2, headerSingle->bgWidth, headerSingle->bgHeight, headerSingle->imageFormat, headerSingle->imageSize, headerSingle->imagePal, headerSingle->imageFlip);
headerSingle->unknown, headerSingle->unknown2,
headerSingle->bgWidth, headerSingle->bgHeight,
headerSingle->imageFormat, headerSingle->imageSize,
headerSingle->imagePal, headerSingle->imageFlip);
zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, 0x1E, "MeshHeader1Single",
StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), declaration);
zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None,
DeclarationPadding::Pad16, 0x1E, "MeshHeader1Single",
StringHelper::Sprintf("%sMeshHeader0x%06X",
zRoom->GetName().c_str(),
segmentOffset),
declaration);
meshHeader1 = headerSingle;
}
@ -141,16 +179,22 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
headerMulti->headerType = 1;
headerMulti->format = fmt;
headerMulti->entryRecord = BitConverter::ToInt32BE(rawData, segmentOffset + 4);// &0x00FFFFFF;
headerMulti->entryRecord =
BitConverter::ToInt32BE(rawData, segmentOffset + 4); // &0x00FFFFFF;
headerMulti->bgCnt = rawData[segmentOffset + 8];
headerMulti->bgRecordPtr = BitConverter::ToInt32BE(rawData, segmentOffset + 12);
declaration += StringHelper::Sprintf("{ { 1 }, 2, 0x%06X }, 0x%06X, 0x%06X",
headerMulti->entryRecord, headerMulti->bgCnt, headerMulti->bgRecordPtr);
headerMulti->entryRecord, headerMulti->bgCnt,
headerMulti->bgRecordPtr);
zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, DeclarationPadding::Pad16, 16, "MeshHeader1Multi",
StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), declaration);
zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None,
DeclarationPadding::Pad16, 16, "MeshHeader1Multi",
StringHelper::Sprintf("%sMeshHeader0x%06X",
zRoom->GetName().c_str(),
segmentOffset),
declaration);
meshHeader1 = headerMulti;
}
@ -164,7 +208,6 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
meshHeader1->format = fmt;
meshHeader1->entryRecord = BitConverter::ToInt32BE(rawData, segmentOffset + 4) & 0x00FFFFFF;
meshHeader = meshHeader1;
}
else if (meshHeaderType == 2)
@ -189,11 +232,17 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
entry->playerZMin = BitConverter::ToInt16BE(rawData, currentPtr + 6);
entry->opaqueDListAddr = BitConverter::ToInt32BE(rawData, currentPtr + 8) & 0x00FFFFFF;
entry->translucentDListAddr = BitConverter::ToInt32BE(rawData, currentPtr + 12) & 0x00FFFFFF;
entry->translucentDListAddr =
BitConverter::ToInt32BE(rawData, currentPtr + 12) & 0x00FFFFFF;
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));
entry->opaqueDList = new ZDisplayList(
rawData, entry->opaqueDListAddr,
ZDisplayList::GetDListLength(rawData, entry->opaqueDListAddr,
Globals::Instance->game == ZGame::OOT_SW97 ?
DListType::F3DEX :
DListType::F3DZEX));
entry->opaqueDList->scene = zRoom->scene;
entry->opaqueDList->parent = zRoom->parent;
GenDListDeclarations(rawData, entry->opaqueDList); // HOTSPOT
@ -201,7 +250,12 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
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));
entry->translucentDList = new ZDisplayList(
rawData, entry->translucentDListAddr,
ZDisplayList::GetDListLength(rawData, entry->translucentDListAddr,
Globals::Instance->game == ZGame::OOT_SW97 ?
DListType::F3DEX :
DListType::F3DZEX));
entry->translucentDList->scene = zRoom->scene;
entry->translucentDList->parent = zRoom->parent;
GenDListDeclarations(rawData, entry->translucentDList); // HOTSPOT
@ -215,40 +269,57 @@ SetMesh::SetMesh(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex,
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);
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);
declaration += StringHelper::Sprintf(
"(u32)&(%sMeshDListEntry0x%06X) + sizeof(%sMeshDListEntry0x%06X)",
zRoom->GetName().c_str(), meshHeader2->dListStart, zRoom->GetName().c_str(),
meshHeader2->dListStart);
else
declaration += "0";
zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, 12, "MeshHeader2",
StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset), declaration);
zRoom->parent->AddDeclaration(
segmentOffset, DeclarationAlignment::None, 12, "MeshHeader2",
StringHelper::Sprintf("%sMeshHeader0x%06X", zRoom->GetName().c_str(), segmentOffset),
declaration);
declaration = "";
for (int i = 0; i < meshHeader2->entries.size(); i++)
for (size_t i = 0; i < meshHeader2->entries.size(); i++)
{
declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, ", meshHeader2->entries[i]->playerXMax, meshHeader2->entries[i]->playerZMax, meshHeader2->entries[i]->playerXMin, meshHeader2->entries[i]->playerZMin);
declaration += StringHelper::Sprintf(
"\t{ %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);
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);
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->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");
zRoom->parent->AddDeclaration(meshHeader2->dListStart + (meshHeader2->entries.size() * 16),
DeclarationAlignment::None, DeclarationPadding::Pad16, 4,
"static s32", "terminatorMaybe", "0x01000000");
meshHeader = meshHeader2;
}
@ -267,23 +338,27 @@ void SetMesh::GenDListDeclarations(std::vector<uint8_t> rawData, ZDisplayList* d
{
string srcVarName = "";
//if (Globals::Instance->includeFilePrefix)
// if (Globals::Instance->includeFilePrefix)
srcVarName = StringHelper::Sprintf("%s%s", zRoom->GetName().c_str(), dList->GetName().c_str());
//else
//srcVarName = StringHelper::Sprintf("%s", dList->GetName().c_str());
// else
// srcVarName = StringHelper::Sprintf("%s", dList->GetName().c_str());
dList->SetName(srcVarName);
string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName()); // HOTSPOT
//zRoom->parent->AddDeclarationArray(dList->GetRawDataIndex(), DeclarationAlignment::None, dList->GetRawDataSize(), "static Gfx", srcVarName, dList->GetRawDataSize() / 8, sourceOutput);
// zRoom->parent->AddDeclarationArray(dList->GetRawDataIndex(), DeclarationAlignment::None,
// dList->GetRawDataSize(), "static Gfx", srcVarName, dList->GetRawDataSize() / 8, sourceOutput);
for (ZDisplayList* otherDList : dList->otherDLists)
GenDListDeclarations(rawData, otherDList);
for (pair<uint32_t, string> vtxEntry : dList->vtxDeclarations)
{
zRoom->parent->AddDeclarationArray(vtxEntry.first, DeclarationAlignment::Align8, 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);
zRoom->parent->AddDeclarationArray(
vtxEntry.first, DeclarationAlignment::Align8,
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)
@ -295,9 +370,17 @@ void SetMesh::GenDListDeclarations(std::vector<uint8_t> rawData, ZDisplayList* d
zRoom->textures[texEntry.first]->Save(Globals::Instance->outputPath);
zRoom->parent->AddDeclarationIncludeArray(texEntry.first, StringHelper::Sprintf("%s/%s.%s.inc.c",
Globals::Instance->outputPath.c_str(), Path::GetFileNameWithoutExtension(zRoom->textures[texEntry.first]->GetName()).c_str(), zRoom->textures[texEntry.first]->GetExternalExtension().c_str()),
zRoom->textures[texEntry.first]->GetRawDataSize(), "u64", StringHelper::Sprintf("%s", zRoom->textures[texEntry.first]->GetName().c_str(), texEntry.first), 0);
zRoom->parent->AddDeclarationIncludeArray(
texEntry.first,
StringHelper::Sprintf(
"%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(),
Path::GetFileNameWithoutExtension(zRoom->textures[texEntry.first]->GetName())
.c_str(),
zRoom->textures[texEntry.first]->GetExternalExtension().c_str()),
zRoom->textures[texEntry.first]->GetRawDataSize(), "u64",
StringHelper::Sprintf("%s", zRoom->textures[texEntry.first]->GetName().c_str(),
texEntry.first),
0);
}
}
@ -306,7 +389,8 @@ std::string SetMesh::GenDListExterns(ZDisplayList* dList)
string sourceOutput = "";
if (Globals::Instance->includeFilePrefix)
sourceOutput += StringHelper::Sprintf("extern Gfx %sDL_%06X[];\n", zRoom->GetName().c_str(), dList->GetRawDataIndex());
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());
@ -314,7 +398,8 @@ std::string SetMesh::GenDListExterns(ZDisplayList* dList)
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 += StringHelper::Sprintf("extern u64 %sTex_%06X[];\n",
zRoom->GetName().c_str(), texEntry.first);
sourceOutput += dList->defines;
@ -325,7 +410,10 @@ string SetMesh::GenerateSourceCodePass1(string roomName, int baseAddress)
{
string sourceOutput = "";
sourceOutput += StringHelper::Sprintf("%s %i, (u32)&%sMeshHeader0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), data, zRoom->GetName().c_str(), segmentOffset);
sourceOutput +=
StringHelper::Sprintf("%s %i, (u32)&%sMeshHeader0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
data, zRoom->GetName().c_str(), segmentOffset);
/*if (meshHeader->headerType == 0)
{
@ -348,8 +436,11 @@ string SetMesh::GenerateExterns()
{
MeshHeader0* meshHeader0 = (MeshHeader0*)meshHeader;
sourceOutput += StringHelper::Sprintf("extern MeshHeader0 %sMeshHeader0x%06X;\n", zRoom->GetName().c_str(), segmentOffset);
sourceOutput += StringHelper::Sprintf("extern MeshEntry0 %sMeshDListEntry0x%06X[%i];\n", zRoom->GetName().c_str(), meshHeader0->dListStart, meshHeader0->entries.size());
sourceOutput += StringHelper::Sprintf("extern MeshHeader0 %sMeshHeader0x%06X;\n",
zRoom->GetName().c_str(), segmentOffset);
sourceOutput += StringHelper::Sprintf("extern MeshEntry0 %sMeshDListEntry0x%06X[%i];\n",
zRoom->GetName().c_str(), meshHeader0->dListStart,
meshHeader0->entries.size());
for (MeshEntry0* entry : meshHeader0->entries)
{
@ -365,16 +456,21 @@ string SetMesh::GenerateExterns()
MeshHeader1Base* meshHeader1 = (MeshHeader1Base*)meshHeader;
if (meshHeader1->format == 1)
sourceOutput += StringHelper::Sprintf("extern MeshHeader1Single %sMeshHeader0x%06X;\n", zRoom->GetName().c_str(), segmentOffset);
sourceOutput += StringHelper::Sprintf("extern MeshHeader1Single %sMeshHeader0x%06X;\n",
zRoom->GetName().c_str(), segmentOffset);
else if (meshHeader1->format == 2)
sourceOutput += StringHelper::Sprintf("extern MeshHeader1Multi %sMeshHeader0x%06X;\n", zRoom->GetName().c_str(), segmentOffset);
sourceOutput += StringHelper::Sprintf("extern MeshHeader1Multi %sMeshHeader0x%06X;\n",
zRoom->GetName().c_str(), segmentOffset);
}
else if (meshHeader->headerType == 2)
{
MeshHeader2* meshHeader2 = (MeshHeader2*)meshHeader;
sourceOutput += StringHelper::Sprintf("extern MeshHeader2 %sMeshHeader0x%06X;\n", zRoom->GetName().c_str(), segmentOffset);
sourceOutput += StringHelper::Sprintf("extern MeshEntry2 %sMeshDListEntry0x%06X[%i];\n", zRoom->GetName().c_str(), meshHeader2->dListStart, meshHeader2->entries.size());
sourceOutput += StringHelper::Sprintf("extern MeshHeader2 %sMeshHeader0x%06X;\n",
zRoom->GetName().c_str(), segmentOffset);
sourceOutput += StringHelper::Sprintf("extern MeshEntry2 %sMeshDListEntry0x%06X[%i];\n",
zRoom->GetName().c_str(), meshHeader2->dListStart,
meshHeader2->entries.size());
for (MeshEntry2* entry : meshHeader2->entries)
{
@ -387,7 +483,7 @@ string SetMesh::GenerateExterns()
}
else
{
//sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n";
// sourceOutput += "// SetMesh UNIMPLEMENTED HEADER TYPE!\n";
}
return sourceOutput;

View file

@ -1,7 +1,7 @@
#pragma once
#include "../ZRoomCommand.h"
#include "../../ZDisplayList.h"
#include "../ZRoomCommand.h"
class MeshHeaderBase
{
@ -105,8 +105,8 @@ public:
~SetMesh();
virtual std::string GenerateSourceCodePass1(std::string roomName, int baseAddress);
//virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress);
//virtual std::string GenerateSourceCodePass3(std::string roomName);
// virtual std::string GenerateSourceCodePass2(std::string roomName, int baseAddress);
// virtual std::string GenerateSourceCodePass3(std::string roomName);
virtual std::string GenerateExterns();
virtual std::string GetCommandCName();
virtual RoomCommand GetRoomCommand();

View file

@ -1,20 +1,21 @@
#include "SetObjectList.h"
#include "../ZRoom.h"
#include "../ObjectList.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ObjectList.h"
#include "../ZRoom.h"
using namespace std;
SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
objects = vector<uint16_t>();
uint8_t objectCnt = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
uint32_t currentPtr = segmentOffset;
for (int i = 0; i < objectCnt; i++)
for (uint8_t i = 0; i < objectCnt; i++)
{
uint16_t objectIndex = BitConverter::ToInt16BE(rawData, currentPtr);
objects.push_back(objectIndex);
@ -27,18 +28,22 @@ SetObjectList::SetObjectList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int ra
string SetObjectList::GenerateExterns()
{
return StringHelper::Sprintf("s16 %sObjectList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf("s16 %sObjectList0x%06X[];\n", zRoom->GetName().c_str(),
segmentOffset);
}
string SetObjectList::GenerateSourceCodePass1(string roomName, int 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);
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 (int i = 0; i < objects.size(); i++)
for (size_t i = 0; i < objects.size(); i++)
{
uint16_t objectIndex = objects[i];
declaration += StringHelper::Sprintf("\t%s,", ObjectList[objectIndex].c_str());
@ -47,8 +52,10 @@ string SetObjectList::GenerateSourceCodePass1(string roomName, int baseAddress)
declaration += "\n";
}
zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, objects.size() * 2, "s16",
StringHelper::Sprintf("%sObjectList0x%06X", zRoom->GetName().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;
}

View file

@ -1,12 +1,13 @@
#include "SetPathways.h"
#include "../ZRoom.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
SetPathways::SetPathways(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetPathways::SetPathways(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
_rawData = rawData;
_rawDataIndex = rawDataIndex;
@ -16,8 +17,6 @@ SetPathways::SetPathways(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDat
InitList(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4)));
uint32_t currentPtr = listSegmentOffset;
if (segmentOffset != 0)
zRoom->parent->AddDeclarationPlaceholder(segmentOffset);
}
@ -42,7 +41,7 @@ string SetPathways::GetSourceOutputCode(std::string prefix)
string SetPathways::GenerateSourceCodePass1(string roomName, int baseAddress)
{
//int numPathsReal = zRoom->GetDeclarationSizeFromNeighbor(listSegmentOffset) / 6;
// int numPathsReal = zRoom->GetDeclarationSizeFromNeighbor(listSegmentOffset) / 6;
uint32_t currentPtr = listSegmentOffset;
uint8_t* data = _rawData.data();
@ -71,27 +70,32 @@ string SetPathways::GenerateSourceCodePass1(string roomName, int baseAddress)
return "";
}
string SetPathways::GenerateSourceCodePass2(string roomName, int baseAddress)
{
string sourceOutput = "";
sourceOutput += StringHelper::Sprintf("%s 0, (u32)&%sPathway0x%06X };", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), roomName.c_str(), segmentOffset);
sourceOutput +=
StringHelper::Sprintf("%s 0, (u32)&%sPathway0x%06X };",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
roomName.c_str(), segmentOffset);
{
string declaration = StringHelper::Sprintf("%i, (u32)%sPathwayList0x%06X", numPoints, roomName.c_str(), listSegmentOffset);
string declaration = StringHelper::Sprintf("%i, (u32)%sPathwayList0x%06X", numPoints,
roomName.c_str(), listSegmentOffset);
zRoom->parent->AddDeclaration(segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, 8, "Path",
zRoom->parent->AddDeclaration(
segmentOffset, DeclarationAlignment::None, DeclarationPadding::None, 8, "Path",
StringHelper::Sprintf("%sPathway0x%06X", roomName.c_str(), segmentOffset), declaration);
}
{
string declaration = "";
int index = 0;
size_t index = 0;
for (PathwayEntry* entry : pathways)
{
declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", entry->x, entry->y, entry->z, listSegmentOffset + (index * 6));
declaration += StringHelper::Sprintf(" { %i, %i, %i }, //0x%06X", entry->x, entry->y,
entry->z, listSegmentOffset + (index * 6));
if (index < pathways.size() - 1)
declaration += "\n";
@ -99,8 +103,11 @@ string SetPathways::GenerateSourceCodePass2(string roomName, int baseAddress)
index++;
}
zRoom->parent->AddDeclarationArray(listSegmentOffset, DeclarationAlignment::None, DeclarationPadding::None, pathways.size() * 6,
"Vec3s", StringHelper::Sprintf("%sPathwayList0x%06X", roomName.c_str(), listSegmentOffset), pathways.size(), declaration);
zRoom->parent->AddDeclarationArray(
listSegmentOffset, DeclarationAlignment::None, DeclarationPadding::None,
pathways.size() * 6, "Vec3s",
StringHelper::Sprintf("%sPathwayList0x%06X", roomName.c_str(), listSegmentOffset),
pathways.size(), declaration);
}
return sourceOutput;
@ -113,7 +120,8 @@ int32_t SetPathways::GetRawDataSize()
string SetPathways::GenerateExterns()
{
return StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf("extern Vec3s %sPathwayList0x%06X[];\n", zRoom->GetName().c_str(),
segmentOffset);
}
string SetPathways::GetCommandCName()

View file

@ -1,7 +1,7 @@
#pragma once
#include "../ZRoomCommand.h"
#include "../../Vec3s.h"
#include "../ZRoomCommand.h"
class PathwayEntry
{

View file

@ -4,7 +4,8 @@
using namespace std;
SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
gameplayFlags = rawData[rawDataIndex + 0x01];
gameplayFlags2 = BitConverter::ToInt32BE(rawData, rawDataIndex + 0x04);
@ -12,7 +13,10 @@ SetRoomBehavior::SetRoomBehavior(ZRoom* nZRoom, std::vector<uint8_t> rawData, in
string SetRoomBehavior::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), gameplayFlags, gameplayFlags2);;
return StringHelper::Sprintf(
"%s 0x%02X, 0x%08X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
gameplayFlags, gameplayFlags2);
;
}
string SetRoomBehavior::GetCommandCName()

View file

@ -1,13 +1,14 @@
#include "SetRoomList.h"
#include "../ZRoom.h"
#include "../../ZFile.h"
#include "../../Globals.h"
#include "../../BitConverter.h"
#include "../../Globals.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ZRoom.h"
using namespace std;
SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetRoomList::SetRoomList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
int numRooms = rawData[rawDataIndex + 1];
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
@ -33,7 +34,10 @@ SetRoomList::~SetRoomList()
string SetRoomList::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x%02X, (u32)&%sRoomList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), rooms.size(), zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf(
"%s 0x%02X, (u32)&%sRoomList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), rooms.size(),
zRoom->GetName().c_str(), segmentOffset);
}
string SetRoomList::GenerateSourceCodePass2(string roomName, int baseAddress)
@ -43,7 +47,8 @@ string SetRoomList::GenerateSourceCodePass2(string roomName, int baseAddress)
string SetRoomList::GenerateExterns()
{
return StringHelper::Sprintf("extern RomFile %sRoomList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf("extern RomFile %sRoomList0x%06X[];\n", zRoom->GetName().c_str(),
segmentOffset);
}
string SetRoomList::GetCommandCName()
@ -67,13 +72,17 @@ std::string SetRoomList::PreGenSourceFiles()
if (res->GetResourceType() == ZResourceType::Room && res != zRoom)
{
string roomName = res->GetName();
declaration += StringHelper::Sprintf("\t{ (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n", roomName.c_str(), roomName.c_str());
declaration +=
StringHelper::Sprintf("\t{ (u32)_%sSegmentRomStart, (u32)_%sSegmentRomEnd },\n",
roomName.c_str(), roomName.c_str());
}
}
}
zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, rooms.size() * 8,
"RomFile", StringHelper::Sprintf("%sRoomList0x%06X", zRoom->GetName().c_str(), segmentOffset), 0, declaration);
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, rooms.size() * 8, "RomFile",
StringHelper::Sprintf("%sRoomList0x%06X", zRoom->GetName().c_str(), segmentOffset), 0,
declaration);
return std::string();
}
@ -89,6 +98,8 @@ RoomEntry::RoomEntry(int32_t nVAS, int32_t nVAE)
virtualAddressEnd = nVAE;
}
RoomEntry::RoomEntry(std::vector<uint8_t> rawData, int rawDataIndex) : RoomEntry(BitConverter::ToInt32BE(rawData, rawDataIndex + 0), BitConverter::ToInt32BE(rawData, rawDataIndex + 4))
RoomEntry::RoomEntry(std::vector<uint8_t> rawData, int rawDataIndex)
: RoomEntry(BitConverter::ToInt32BE(rawData, rawDataIndex + 0),
BitConverter::ToInt32BE(rawData, rawDataIndex + 4))
{
}

View file

@ -3,7 +3,8 @@
using namespace std;
SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
disableSky = rawData[rawDataIndex + 0x04];
disableSunMoon = rawData[rawDataIndex + 0x05];
@ -11,7 +12,11 @@ SetSkyboxModifier::SetSkyboxModifier(ZRoom* nZRoom, std::vector<uint8_t> rawData
string SetSkyboxModifier::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0, 0, 0, 0x%02X, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), disableSky, disableSunMoon);;
return StringHelper::Sprintf(
"%s 0, 0, 0, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), disableSky,
disableSunMoon);
;
}
string SetSkyboxModifier::GetCommandCName()

View file

@ -3,7 +3,8 @@
using namespace std;
SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
skyboxNumber = rawData[rawDataIndex + 0x04];
cloudsType = rawData[rawDataIndex + 0x05];
@ -12,8 +13,10 @@ SetSkyboxSettings::SetSkyboxSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData
string SetSkyboxSettings::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), skyboxNumber, cloudsType, lightingSettingsControl);
return StringHelper::Sprintf(
"%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), skyboxNumber,
cloudsType, lightingSettingsControl);
}
string SetSkyboxSettings::GetCommandCName()

View file

@ -3,7 +3,8 @@
using namespace std;
SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
reverb = rawData[rawDataIndex + 0x01];
nightTimeSFX = rawData[rawDataIndex + 0x06];
@ -12,7 +13,10 @@ SetSoundSettings::SetSoundSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData,
string SetSoundSettings::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x%02X, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), reverb, nightTimeSFX, musicSequence);
return StringHelper::Sprintf(
"%s 0x%02X, 0x00, 0x00, 0x00, 0x00, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), reverb, nightTimeSFX,
musicSequence);
}
string SetSoundSettings::GetCommandCName()

View file

@ -4,7 +4,8 @@
using namespace std;
SetSpecialObjects::SetSpecialObjects(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetSpecialObjects::SetSpecialObjects(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
elfMessage = rawData[rawDataIndex + 0x01];
globalObject = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
@ -12,7 +13,9 @@ SetSpecialObjects::SetSpecialObjects(ZRoom* nZRoom, std::vector<uint8_t> rawData
string SetSpecialObjects::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x%02X, 0x%04X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), elfMessage, globalObject);
return StringHelper::Sprintf(
"%s 0x%02X, 0x%04X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
elfMessage, globalObject);
}
string SetSpecialObjects::GetCommandCName()

View file

@ -1,15 +1,17 @@
#include "SetStartPositionList.h"
#include "../ZRoom.h"
#include "../ActorList.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ActorList.h"
#include "../ZRoom.h"
using namespace std;
SetStartPositionList::SetStartPositionList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetStartPositionList::SetStartPositionList(ZRoom* nZRoom, std::vector<uint8_t> rawData,
int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
int numActors = rawData[rawDataIndex + 1];
uint8_t numActors = rawData[rawDataIndex + 1];
segmentOffset = GETSEGOFFSET(BitConverter::ToInt32BE(rawData, rawDataIndex + 4));
if (segmentOffset != 0)
@ -35,20 +37,26 @@ SetStartPositionList::~SetStartPositionList()
string SetStartPositionList::GenerateSourceCodePass1(string roomName, int baseAddress)
{
string sourceOutput = "";
char line[2048];
sourceOutput += StringHelper::Sprintf("%s 0x%02X, (u32)&%sStartPositionList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), actors.size(), zRoom->GetName().c_str(), segmentOffset);
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)
{
declaration += StringHelper::Sprintf("\t{ %s, %i, %i, %i, %i, %i, %i, 0x%04X },\n", ActorList[entry->actorNum].c_str(), entry->posX, entry->posY, entry->posZ,
entry->rotX, entry->rotY, entry->rotZ, entry->initVar);
declaration += StringHelper::Sprintf("\t{ %s, %i, %i, %i, %i, %i, %i, 0x%04X },\n",
ActorList[entry->actorNum].c_str(), entry->posX,
entry->posY, entry->posZ, entry->rotX, entry->rotY,
entry->rotZ, entry->initVar);
}
zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, actors.size() * 16, "ActorEntry",
StringHelper::Sprintf("%sStartPositionList0x%06X", zRoom->GetName().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;
}
@ -60,7 +68,8 @@ string SetStartPositionList::GenerateSourceCodePass2(string roomName, int baseAd
string SetStartPositionList::GenerateExterns()
{
return StringHelper::Sprintf("extern ActorEntry %sStartPositionList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf("extern ActorEntry %sStartPositionList0x%06X[];\n",
zRoom->GetName().c_str(), segmentOffset);
}
string SetStartPositionList::GetCommandCName()

View file

@ -3,7 +3,6 @@
#include "../ZRoomCommand.h"
#include "SetActorList.h"
class SetStartPositionList : public ZRoomCommand
{
public:
@ -17,7 +16,7 @@ public:
virtual std::string GetCommandCName();
virtual std::string GenerateExterns();
virtual RoomCommand GetRoomCommand();
private:
private:
uint32_t segmentOffset;
};

View file

@ -4,7 +4,8 @@
using namespace std;
SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
hour = rawData[rawDataIndex + 4];
min = rawData[rawDataIndex + 5];
@ -13,7 +14,9 @@ SetTimeSettings::SetTimeSettings(ZRoom* nZRoom, std::vector<uint8_t> rawData, in
string SetTimeSettings::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), hour, min, unk);
return StringHelper::Sprintf(
"%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), hour, min, unk);
}
string SetTimeSettings::GetCommandCName()

View file

@ -12,8 +12,8 @@ public:
virtual RoomCommand GetRoomCommand();
private:
//uint16_t time;
//int8_t speed;
// uint16_t time;
// int8_t speed;
uint8_t hour;
uint8_t min;

View file

@ -1,13 +1,15 @@
#include "SetTransitionActorList.h"
#include "../ZRoom.h"
#include "../ActorList.h"
#include "../../ZFile.h"
#include "../../BitConverter.h"
#include "../../StringHelper.h"
#include "../../ZFile.h"
#include "../ActorList.h"
#include "../ZRoom.h"
using namespace std;
SetTransitionActorList::SetTransitionActorList(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetTransitionActorList::SetTransitionActorList(ZRoom* nZRoom, std::vector<uint8_t> rawData,
int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
int numActors = rawData[rawDataIndex + 1];
segmentOffset = BitConverter::ToInt32BE(rawData, rawDataIndex + 4) & 0x00FFFFFF;
@ -38,7 +40,10 @@ string SetTransitionActorList::GetSourceOutputCode(std::string prefix)
string SetTransitionActorList::GenerateSourceCodePass1(string roomName, int baseAddress)
{
string sourceOutput = StringHelper::Sprintf("%s 0x%02X, (u32)%sTransitionActorList0x%06X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), transitionActors.size(), roomName.c_str(), segmentOffset);
string sourceOutput =
StringHelper::Sprintf("%s 0x%02X, (u32)%sTransitionActorList0x%06X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(),
transitionActors.size(), roomName.c_str(), segmentOffset);
string declaration = "";
for (TransitionActorEntry* entry : transitionActors)
@ -50,16 +55,22 @@ string SetTransitionActorList::GenerateSourceCodePass1(string roomName, int base
else
actorStr = StringHelper::Sprintf("0x%04X", entry->actorNum);
declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %s, %i, %i, %i, %i, 0x%04X }, \n", entry->frontObjectRoom, entry->frontTransitionReaction, entry->backObjectRoom, entry->backTransitionReaction, actorStr.c_str(), entry->posX, entry->posY, entry->posZ, entry->rotY, (uint16_t)entry->initVar);
declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %s, %i, %i, %i, %i, 0x%04X }, \n",
entry->frontObjectRoom, entry->frontTransitionReaction,
entry->backObjectRoom, entry->backTransitionReaction,
actorStr.c_str(), entry->posX, entry->posY,
entry->posZ, entry->rotY, (uint16_t)entry->initVar);
}
zRoom->parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::None, transitionActors.size() * 16, "TransitionActorEntry",
StringHelper::Sprintf("%sTransitionActorList0x%06X", roomName.c_str(), segmentOffset), 0, declaration);
zRoom->parent->AddDeclarationArray(
segmentOffset, DeclarationAlignment::None, transitionActors.size() * 16,
"TransitionActorEntry",
StringHelper::Sprintf("%sTransitionActorList0x%06X", roomName.c_str(), segmentOffset), 0,
declaration);
return sourceOutput;
}
string SetTransitionActorList::GenerateSourceCodePass2(string roomName, int baseAddress)
{
return "";
@ -72,7 +83,8 @@ int32_t SetTransitionActorList::GetRawDataSize()
string SetTransitionActorList::GenerateExterns()
{
return StringHelper::Sprintf("extern TransitionActorEntry %sTransitionActorList0x%06X[];\n", zRoom->GetName().c_str(), segmentOffset);
return StringHelper::Sprintf("extern TransitionActorEntry %sTransitionActorList0x%06X[];\n",
zRoom->GetName().c_str(), segmentOffset);
}
string SetTransitionActorList::GetCommandCName()

View file

@ -3,7 +3,8 @@
using namespace std;
SetWind::SetWind(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
SetWind::SetWind(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
windWest = rawData[rawDataIndex + 0x04];
windVertical = rawData[rawDataIndex + 0x05];
@ -13,7 +14,10 @@ SetWind::SetWind(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
string SetWind::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X, 0x%02X", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), windWest, windVertical, windSouth, clothFlappingStrength);
return StringHelper::Sprintf(
"%s 0x00, 0x00, 0x00, 0x%02X, 0x%02X, 0x%02X, 0x%02X",
ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str(), windWest,
windVertical, windSouth, clothFlappingStrength);
}
string SetWind::GetCommandCName()

View file

@ -3,13 +3,15 @@
using namespace std;
Unused09::Unused09(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
Unused09::Unused09(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
}
string Unused09::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str());
return StringHelper::Sprintf(
"%s 0x00, 0x00", ZRoomCommand::GenerateSourceCodePass1(roomName, baseAddress).c_str());
}
string Unused09::GetCommandCName()

View file

@ -1,10 +1,11 @@
#include "ZRoomCommandUnk.h"
#include "BitConverter.h"
#include "../../StringHelper.h"
#include "BitConverter.h"
using namespace std;
ZRoomCommandUnk::ZRoomCommandUnk(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex) : ZRoomCommand(nZRoom, rawData, rawDataIndex)
ZRoomCommandUnk::ZRoomCommandUnk(ZRoom* nZRoom, std::vector<uint8_t> rawData, int rawDataIndex)
: ZRoomCommand(nZRoom, rawData, rawDataIndex)
{
cmdID = (RoomCommand)rawData[rawDataIndex];
cmdAddress = rawDataIndex;
@ -16,7 +17,10 @@ ZRoomCommandUnk::ZRoomCommandUnk(ZRoom* nZRoom, std::vector<uint8_t> rawData, in
string ZRoomCommandUnk::GenerateSourceCodePass1(string roomName, int baseAddress)
{
return StringHelper::Sprintf("%s %sSet%04XCmd%02X = { 0x%02X, 0x%02X, 0x%06X }; /* WARNING: UNIMPLEMENTED ROOM COMMAND */", GetCommandCName().c_str(), roomName.c_str(), baseAddress, data2, cmdID, data1, data2);
return StringHelper::Sprintf("%s %sSet%04XCmd%02X = { 0x%02X, 0x%02X, 0x%06X }; /* WARNING: "
"UNIMPLEMENTED ROOM COMMAND */",
GetCommandCName().c_str(), roomName.c_str(), baseAddress, data2,
cmdID, data1, data2);
}
string ZRoomCommandUnk::GenerateSourceCodePass2(string roomName, int baseAddress)

View file

@ -2,8 +2,7 @@
#include <string>
static const std::string ObjectList[] =
{
static const std::string ObjectList[] = {
/* 0x0000 */ "OBJECT_UNSET_0",
/* 0x0001 */ "OBJECT_GAMEPLAY_KEEP",
/* 0x0002 */ "OBJECT_GAMEPLAY_FIELD_KEEP",

View file

@ -1,40 +1,40 @@
#include "ZRoom.h"
#include <Path.h>
#include <algorithm>
#include <chrono>
#include "ZRoom.h"
#include "ZFile.h"
#include "ZCutscene.h"
#include "../ZBlob.h"
#include "ObjectList.h"
#include "../File.h"
#include "../StringHelper.h"
#include "../Globals.h"
#include "Commands/SetRoomList.h"
#include "Commands/SetEchoSettings.h"
#include "Commands/SetSoundSettings.h"
#include "Commands/SetWind.h"
#include "Commands/SetTimeSettings.h"
#include "Commands/SetSpecialObjects.h"
#include "Commands/SetSkyboxSettings.h"
#include "Commands/SetSkyboxModifier.h"
#include "Commands/SetRoomBehavior.h"
#include "Commands/SetCameraSettings.h"
#include "Commands/SetStartPositionList.h"
#include "../StringHelper.h"
#include "../ZBlob.h"
#include "Commands/EndMarker.h"
#include "Commands/SetActorList.h"
#include "Commands/SetTransitionActorList.h"
#include "Commands/SetAlternateHeaders.h"
#include "Commands/SetCameraSettings.h"
#include "Commands/SetCollisionHeader.h"
#include "Commands/SetCutscenes.h"
#include "Commands/SetEchoSettings.h"
#include "Commands/SetEntranceList.h"
#include "Commands/SetExitList.h"
#include "Commands/SetAlternateHeaders.h"
#include "Commands/SetCollisionHeader.h"
#include "Commands/SetObjectList.h"
#include "Commands/SetMesh.h"
#include "Commands/SetLightingSettings.h"
#include "Commands/SetPathways.h"
#include "Commands/Unused09.h"
#include "Commands/SetCutscenes.h"
#include "Commands/EndMarker.h"
#include "Commands/SetLightList.h"
#include "Commands/SetLightingSettings.h"
#include "Commands/SetMesh.h"
#include "Commands/SetObjectList.h"
#include "Commands/SetPathways.h"
#include "Commands/SetRoomBehavior.h"
#include "Commands/SetRoomList.h"
#include "Commands/SetSkyboxModifier.h"
#include "Commands/SetSkyboxSettings.h"
#include "Commands/SetSoundSettings.h"
#include "Commands/SetSpecialObjects.h"
#include "Commands/SetStartPositionList.h"
#include "Commands/SetTimeSettings.h"
#include "Commands/SetTransitionActorList.h"
#include "Commands/SetWind.h"
#include "Commands/Unused09.h"
#include "Commands/ZRoomCommandUnk.h"
#include <Path.h>
#include "ObjectList.h"
#include "ZCutscene.h"
#include "ZFile.h"
using namespace std;
using namespace tinyxml2;
@ -54,7 +54,8 @@ ZRoom::~ZRoom()
delete cmd;
}
ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int rawDataIndex, string nRelPath, ZFile* nParent, ZRoom* nScene)
ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int rawDataIndex,
string nRelPath, ZFile* nParent, ZRoom* nScene)
{
ZRoom* room = new ZRoom();
@ -62,7 +63,7 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int r
room->rawData = nRawData;
room->name = reader->Attribute("Name");
//printf("ZRoom: %s\n", name.c_str());
// printf("ZRoom: %s\n", name.c_str());
room->scene = nScene;
@ -75,7 +76,7 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int r
Globals::Instance->AddSegment(SEGMENT_ROOM);
Globals::Instance->AddSegment(SEGMENT_SCENE);
//GenDefinitions();
// GenDefinitions();
int cmdCount = 999999;
@ -85,7 +86,8 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int r
cmdCount = 0;
}
for (XMLElement* child = reader->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
for (XMLElement* child = reader->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
// TODO: Bunch of repeated code between all of these that needs to be combined.
if (string(child->Name()) == "DListHint")
@ -99,7 +101,12 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int r
string addressStr = child->Attribute("Offset");
int address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16);
ZDisplayList* dList = new ZDisplayList(room->rawData, address, ZDisplayList::GetDListLength(room->rawData, address, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX));
ZDisplayList* dList = new ZDisplayList(
room->rawData, address,
ZDisplayList::GetDListLength(room->rawData, address,
Globals::Instance->game == ZGame::OOT_SW97 ?
DListType::F3DEX :
DListType::F3DZEX));
if (child->Attribute("Name") != NULL)
name = string(child->Attribute("Name"));
@ -123,14 +130,18 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int r
string sizeStr = child->Attribute("Size");
int size = strtol(StringHelper::Split(sizeStr, "0x")[1].c_str(), NULL, 16);
ZBlob* blob = new ZBlob(room->rawData, address, size, StringHelper::Sprintf("%sBlob0x%06X", room->name.c_str(), address));
ZBlob* blob =
new ZBlob(room->rawData, address, size,
StringHelper::Sprintf("%sBlob0x%06X", room->name.c_str(), address));
if (child->Attribute("Name") != NULL)
name = string(child->Attribute("Name"));
else
name = StringHelper::Sprintf("%s_%s", room->name.c_str(), blob->GetName().c_str());
room->parent->AddDeclarationArray(address, DeclarationAlignment::None, blob->GetRawDataSize(), "u8", name, 0, blob->GetSourceOutputCode(room->name));
room->parent->AddDeclarationArray(address, DeclarationAlignment::None,
blob->GetRawDataSize(), "u8", name, 0,
blob->GetSourceOutputCode(room->name));
delete blob;
}
else if (string(child->Name()) == "CutsceneHint")
@ -149,10 +160,13 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int r
if (child->Attribute("Name") != NULL)
name = string(child->Attribute("Name"));
else
name = StringHelper::Sprintf("%sCutsceneData0x%06X", room->name.c_str(), cutscene->segmentOffset);
name = StringHelper::Sprintf("%sCutsceneData0x%06X", room->name.c_str(),
cutscene->segmentOffset);
room->parent->AddDeclarationArray(address, DeclarationAlignment::None, DeclarationPadding::Pad16, cutscene->GetRawDataSize(), "s32",
name, 0, cutscene->GetSourceOutputCode(room->name));
room->parent->AddDeclarationArray(address, DeclarationAlignment::None,
DeclarationPadding::Pad16, cutscene->GetRawDataSize(),
"s32", name, 0,
cutscene->GetSourceOutputCode(room->name));
delete cutscene;
}
else if (string(child->Name()) == "AltHeaderHint")
@ -207,14 +221,18 @@ ZRoom* ZRoom::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int r
int width = strtol(string(child->Attribute("Width")).c_str(), NULL, 10);
int height = strtol(string(child->Attribute("Height")).c_str(), NULL, 10);
ZTexture* tex = ZTexture::FromBinary(ZTexture::GetTextureTypeFromString(typeStr), room->rawData, address, StringHelper::Sprintf("%sTex_%06X", room->name.c_str(), address), width, height);
room->parent->AddDeclarationArray(address, DeclarationAlignment::None, tex->GetRawDataSize(), "u64", StringHelper::Sprintf("%s", tex->GetName().c_str()), 0,
tex->GetSourceOutputCode(room->name));
ZTexture* tex = ZTexture::FromBinary(
ZTexture::GetTextureTypeFromString(typeStr), room->rawData, address,
StringHelper::Sprintf("%sTex_%06X", room->name.c_str(), address), width, height);
room->parent->AddDeclarationArray(address, DeclarationAlignment::None,
tex->GetRawDataSize(), "u64",
StringHelper::Sprintf("%s", tex->GetName().c_str()),
0, tex->GetSourceOutputCode(room->name));
delete tex;
}
}
//ParseCommands(rawDataIndex);
// ParseCommands(rawDataIndex);
room->commandSets.push_back(CommandSet(rawDataIndex, cmdCount));
room->ProcessCommandSets();
@ -242,32 +260,83 @@ void ZRoom::ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet co
switch (opcode)
{
case RoomCommand::SetStartPositionList: cmd = new SetStartPositionList(this, rawData, rawDataIndex); break; // 0x00
case RoomCommand::SetActorList: cmd = new SetActorList(this, rawData, rawDataIndex); break; // 0x01
case RoomCommand::SetCollisionHeader: cmd = new SetCollisionHeader(this, rawData, rawDataIndex); break; // 0x03
case RoomCommand::SetRoomList: cmd = new SetRoomList(this, rawData, rawDataIndex); break; // 0x04
case RoomCommand::SetWind: cmd = new SetWind(this, rawData, rawDataIndex); break; // 0x05
case RoomCommand::SetEntranceList: cmd = new SetEntranceList(this, rawData, rawDataIndex); break; // 0x06
case RoomCommand::SetSpecialObjects: cmd = new SetSpecialObjects(this, rawData, rawDataIndex); break; // 0x07
case RoomCommand::SetRoomBehavior: cmd = new SetRoomBehavior(this, rawData, rawDataIndex); break; // 0x08
case RoomCommand::Unused09: cmd = new Unused09(this, rawData, rawDataIndex); break; // 0x09
case RoomCommand::SetMesh: cmd = new SetMesh(this, rawData, rawDataIndex, 0); break; // 0x0A
case RoomCommand::SetObjectList: cmd = new SetObjectList(this, rawData, rawDataIndex); break; // 0x0B
case RoomCommand::SetLightList: cmd = new SetLightList(this, rawData, rawDataIndex); break; // 0x0C (MM-ONLY)
case RoomCommand::SetPathways: cmd = new SetPathways(this, rawData, rawDataIndex); break; // 0x0D
case RoomCommand::SetTransitionActorList: cmd = new SetTransitionActorList(this, rawData, rawDataIndex); break; // 0x0E
case RoomCommand::SetLightingSettings: cmd = new SetLightingSettings(this, rawData, rawDataIndex); break; // 0x0F
case RoomCommand::SetTimeSettings: cmd = new SetTimeSettings(this, rawData, rawDataIndex); break; // 0x10
case RoomCommand::SetSkyboxSettings: cmd = new SetSkyboxSettings(this, rawData, rawDataIndex); break; // 0x11
case RoomCommand::SetSkyboxModifier: cmd = new SetSkyboxModifier(this, rawData, rawDataIndex); break; // 0x12
case RoomCommand::SetExitList: cmd = new SetExitList(this, rawData, rawDataIndex); break; // 0x13
case RoomCommand::EndMarker: cmd = new EndMarker(this, rawData, rawDataIndex); break; // 0x14
case RoomCommand::SetSoundSettings: cmd = new SetSoundSettings(this, rawData, rawDataIndex); break; // 0x15
case RoomCommand::SetEchoSettings: cmd = new SetEchoSettings(this, rawData, rawDataIndex); break; // 0x16
case RoomCommand::SetCutscenes: cmd = new SetCutscenes(this, rawData, rawDataIndex); break; // 0x17
case RoomCommand::SetAlternateHeaders: cmd = new SetAlternateHeaders(this, rawData, rawDataIndex); break; // 0x18
case RoomCommand::SetCameraSettings: cmd = new SetCameraSettings(this, rawData, rawDataIndex); break; // 0x19
default: cmd = new ZRoomCommandUnk(this, rawData, rawDataIndex);
case RoomCommand::SetStartPositionList:
cmd = new SetStartPositionList(this, rawData, rawDataIndex);
break; // 0x00
case RoomCommand::SetActorList:
cmd = new SetActorList(this, rawData, rawDataIndex);
break; // 0x01
case RoomCommand::SetCollisionHeader:
cmd = new SetCollisionHeader(this, rawData, rawDataIndex);
break; // 0x03
case RoomCommand::SetRoomList:
cmd = new SetRoomList(this, rawData, rawDataIndex);
break; // 0x04
case RoomCommand::SetWind:
cmd = new SetWind(this, rawData, rawDataIndex);
break; // 0x05
case RoomCommand::SetEntranceList:
cmd = new SetEntranceList(this, rawData, rawDataIndex);
break; // 0x06
case RoomCommand::SetSpecialObjects:
cmd = new SetSpecialObjects(this, rawData, rawDataIndex);
break; // 0x07
case RoomCommand::SetRoomBehavior:
cmd = new SetRoomBehavior(this, rawData, rawDataIndex);
break; // 0x08
case RoomCommand::Unused09:
cmd = new Unused09(this, rawData, rawDataIndex);
break; // 0x09
case RoomCommand::SetMesh:
cmd = new SetMesh(this, rawData, rawDataIndex, 0);
break; // 0x0A
case RoomCommand::SetObjectList:
cmd = new SetObjectList(this, rawData, rawDataIndex);
break; // 0x0B
case RoomCommand::SetLightList:
cmd = new SetLightList(this, rawData, rawDataIndex);
break; // 0x0C (MM-ONLY)
case RoomCommand::SetPathways:
cmd = new SetPathways(this, rawData, rawDataIndex);
break; // 0x0D
case RoomCommand::SetTransitionActorList:
cmd = new SetTransitionActorList(this, rawData, rawDataIndex);
break; // 0x0E
case RoomCommand::SetLightingSettings:
cmd = new SetLightingSettings(this, rawData, rawDataIndex);
break; // 0x0F
case RoomCommand::SetTimeSettings:
cmd = new SetTimeSettings(this, rawData, rawDataIndex);
break; // 0x10
case RoomCommand::SetSkyboxSettings:
cmd = new SetSkyboxSettings(this, rawData, rawDataIndex);
break; // 0x11
case RoomCommand::SetSkyboxModifier:
cmd = new SetSkyboxModifier(this, rawData, rawDataIndex);
break; // 0x12
case RoomCommand::SetExitList:
cmd = new SetExitList(this, rawData, rawDataIndex);
break; // 0x13
case RoomCommand::EndMarker:
cmd = new EndMarker(this, rawData, rawDataIndex);
break; // 0x14
case RoomCommand::SetSoundSettings:
cmd = new SetSoundSettings(this, rawData, rawDataIndex);
break; // 0x15
case RoomCommand::SetEchoSettings:
cmd = new SetEchoSettings(this, rawData, rawDataIndex);
break; // 0x16
case RoomCommand::SetCutscenes:
cmd = new SetCutscenes(this, rawData, rawDataIndex);
break; // 0x17
case RoomCommand::SetAlternateHeaders:
cmd = new SetAlternateHeaders(this, rawData, rawDataIndex);
break; // 0x18
case RoomCommand::SetCameraSettings:
cmd = new SetCameraSettings(this, rawData, rawDataIndex);
break; // 0x19
default:
cmd = new ZRoomCommandUnk(this, rawData, rawDataIndex);
}
auto end = chrono::steady_clock::now();
@ -279,7 +348,7 @@ void ZRoom::ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet co
printf("OP: %s, TIME: %lims\n", cmd->GetCommandCName().c_str(), diff);
}
//printf("OP: %s\n", cmd->GetCommandCName().c_str());
// printf("OP: %s\n", cmd->GetCommandCName().c_str());
cmd->cmdIndex = currentIndex;
cmd->cmdSet = rawDataIndex;
@ -306,14 +375,18 @@ void ZRoom::ProcessCommandSets()
ParseCommands(setCommands, commandSets[0]);
commandSets.erase(commandSets.begin());
for (int i = 0; i < setCommands.size(); i++)
for (size_t i = 0; i < setCommands.size(); i++)
{
ZRoomCommand* cmd = setCommands[i];
cmd->commandSet = commandSet & 0x00FFFFFF;
string pass1 = cmd->GenerateSourceCodePass1(name, cmd->commandSet);
Declaration* decl = parent->AddDeclaration(cmd->cmdAddress, i == 0 ? DeclarationAlignment::Align16 : DeclarationAlignment::None, 8, StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()),
StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), commandSet & 0x00FFFFFF, cmd->cmdIndex, cmd->cmdID),
Declaration* decl = parent->AddDeclaration(
cmd->cmdAddress,
i == 0 ? DeclarationAlignment::Align16 : DeclarationAlignment::None, 8,
StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()),
StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), commandSet & 0x00FFFFFF,
cmd->cmdIndex, cmd->cmdID),
StringHelper::Sprintf("%s", pass1.c_str()));
decl->rightText = StringHelper::Sprintf("// 0x%04X", cmd->cmdAddress);
@ -330,27 +403,30 @@ void ZRoom::ProcessCommandSets()
string pass2 = cmd->GenerateSourceCodePass2(name, cmd->commandSet);
if (pass2 != "")
parent->AddDeclaration(cmd->cmdAddress, DeclarationAlignment::None, 8, StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()), StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(), cmd->commandSet & 0x00FFFFFF, cmd->cmdIndex, cmd->cmdID), StringHelper::Sprintf("%s // 0x%04X", pass2.c_str(), cmd->cmdAddress));
parent->AddDeclaration(
cmd->cmdAddress, DeclarationAlignment::None, 8,
StringHelper::Sprintf("static %s", cmd->GetCommandCName().c_str()),
StringHelper::Sprintf("%sSet%04XCmd%02X", name.c_str(),
cmd->commandSet & 0x00FFFFFF, cmd->cmdIndex, cmd->cmdID),
StringHelper::Sprintf("%s // 0x%04X", pass2.c_str(), cmd->cmdAddress));
}
}
/*
* There is one room in Ocarina of Time that lacks a header. Room 120, "Syotes", dates back to very early in the game's development.
* Since this room is a special case, this hack adds back a header so that the room can be processed properly.
* There is one room in Ocarina of Time that lacks a header. Room 120, "Syotes", dates back to very
* early in the game's development. Since this room is a special case, this hack adds back a header
* so that the room can be processed properly.
*/
void ZRoom::SyotesRoomHack()
{
char headerData[] =
{
0x0A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08
};
char headerData[] = {0x0A, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08};
for (int i = 0; i < sizeof(headerData); i++)
for (size_t i = 0; i < sizeof(headerData); i++)
rawData.insert(rawData.begin() + i, headerData[i]);
SetMesh* cmdSetMesh = new SetMesh(this, rawData, 0, -8);
for (int i = 0; i < sizeof(headerData); i++)
for (size_t i = 0; i < sizeof(headerData); i++)
rawData.erase(rawData.begin());
cmdSetMesh->cmdIndex = 0;
@ -361,7 +437,7 @@ void ZRoom::SyotesRoomHack()
ZRoomCommand* ZRoom::FindCommandOfType(RoomCommand cmdType)
{
for (int i = 0; i < commands.size(); i++)
for (size_t i = 0; i < commands.size(); i++)
{
if (commands[i]->cmdID == cmdType)
return commands[i];
@ -372,15 +448,17 @@ ZRoomCommand* ZRoom::FindCommandOfType(RoomCommand cmdType)
size_t ZRoom::GetDeclarationSizeFromNeighbor(int declarationAddress)
{
int declarationIndex = -1;
size_t declarationIndex = -1;
// Copy it into a vector.
vector<pair<int32_t, Declaration*>> declarationKeysSorted(parent->declarations.begin(), parent->declarations.end());
vector<pair<int32_t, Declaration*>> declarationKeysSorted(parent->declarations.begin(),
parent->declarations.end());
// Sort the vector according to the word count in descending order.
sort(declarationKeysSorted.begin(), declarationKeysSorted.end(), [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; });
sort(declarationKeysSorted.begin(), declarationKeysSorted.end(),
[](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; });
for (int i = 0; i < declarationKeysSorted.size(); i++)
for (size_t i = 0; i < declarationKeysSorted.size(); i++)
{
if (declarationKeysSorted[i].first == declarationAddress)
{
@ -389,10 +467,11 @@ size_t ZRoom::GetDeclarationSizeFromNeighbor(int declarationAddress)
}
}
if (declarationIndex != -1)
if ((int)declarationIndex != -1)
{
if (declarationIndex + 1 < declarationKeysSorted.size())
return declarationKeysSorted[declarationIndex + 1].first - declarationKeysSorted[declarationIndex].first;
return declarationKeysSorted[declarationIndex + 1].first -
declarationKeysSorted[declarationIndex].first;
else
return rawData.size() - declarationKeysSorted[declarationIndex].first;
}
@ -402,9 +481,9 @@ size_t ZRoom::GetDeclarationSizeFromNeighbor(int declarationAddress)
size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd)
{
int cmdIndex = -1;
size_t cmdIndex = -1;
for (int i = 0; i < commands.size(); i++)
for (size_t i = 0; i < commands.size(); i++)
{
if (commands[i] == cmd)
{
@ -413,7 +492,7 @@ size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd)
}
}
if (cmdIndex != -1)
if ((int)cmdIndex != -1)
{
if (cmdIndex + 1 < commands.size())
return commands[cmdIndex + 1]->cmdAddress - commands[cmdIndex]->cmdAddress;
@ -443,7 +522,7 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix)
{
sourceOutput = "";
//sourceOutput += "#include <z64.h>\n";
// sourceOutput += "#include <z64.h>\n";
sourceOutput += "#include \"segment_symbols.h\"\n";
sourceOutput += "#include \"command_macros_base.h\"\n";
sourceOutput += "#include \"z64cutscene_commands.h\"\n";
@ -452,7 +531,7 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix)
if (scene != nullptr)
sourceOutput += scene->parent->GetHeaderInclude();
//sourceOutput += "\n";
// sourceOutput += "\n";
ProcessCommandSets();
@ -463,21 +542,22 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix)
{
vector<pair<uint32_t, ZTexture*>> texturesSorted(textures.begin(), textures.end());
sort(texturesSorted.begin(), texturesSorted.end(), [](const auto& lhs, const auto& rhs)
{
return lhs.first < rhs.first;
});
sort(texturesSorted.begin(), texturesSorted.end(),
[](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; });
for (int i = 0; i < texturesSorted.size() - 1; i++)
for (size_t i = 0; i < texturesSorted.size() - 1; i++)
{
int texSize = textures[texturesSorted[i].first]->GetRawDataSize();
if ((texturesSorted[i].first + texSize) > texturesSorted[i + 1].first)
{
int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i + 1].first;
// int intersectAmt = (texturesSorted[i].first + texSize) - texturesSorted[i +
// 1].first;
defines += StringHelper::Sprintf("#define %sTex_%06X ((u32)%sTex_%06X + 0x%06X)\n", prefix.c_str(), texturesSorted[i + 1].first, prefix.c_str(),
texturesSorted[i].first, texturesSorted[i + 1].first - texturesSorted[i].first);
defines += StringHelper::Sprintf(
"#define %sTex_%06X ((u32)%sTex_%06X + 0x%06X)\n", prefix.c_str(),
texturesSorted[i + 1].first, prefix.c_str(), texturesSorted[i].first,
texturesSorted[i + 1].first - texturesSorted[i].first);
parent->declarations.erase(texturesSorted[i + 1].first);
textures.erase(texturesSorted[i + 1].first);
@ -489,7 +569,7 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix)
}
parent->defines += defines;
//parent->externs[0xFFFFFFFF] = defines;
// parent->externs[0xFFFFFFFF] = defines;
}
for (pair<int32_t, ZTexture*> item : textures)
@ -503,12 +583,16 @@ string ZRoom::GetSourceOutputCode(const std::string& prefix)
item.second->Save(Globals::Instance->outputPath);
parent->AddDeclarationIncludeArray(item.first, StringHelper::Sprintf("%s/%s.%s.inc.c",
Globals::Instance->outputPath.c_str(), Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(), item.second->GetExternalExtension().c_str()), item.second->GetRawDataSize(),
"u64", StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first), 0);
parent->AddDeclarationIncludeArray(
item.first,
StringHelper::Sprintf("%s/%s.%s.inc.c", Globals::Instance->outputPath.c_str(),
Path::GetFileNameWithoutExtension(item.second->GetName()).c_str(),
item.second->GetExternalExtension().c_str()),
item.second->GetRawDataSize(), "u64",
StringHelper::Sprintf("%sTex_%06X", prefix.c_str(), item.first), 0);
}
//sourceOutput += "\n";
// sourceOutput += "\n";
return sourceOutput;
}
@ -545,7 +629,8 @@ void ZRoom::PreGenSourceFiles()
cmd->PreGenSourceFiles();
}
Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, string nText)
Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding,
uint32_t nSize, string nText)
{
alignment = nAlignment;
padding = nPadding;
@ -564,21 +649,28 @@ Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPa
references = vector<uint32_t>();
}
Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType, string nVarName, bool nIsArray, string nText) : Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType,
string nVarName, bool nIsArray, string nText)
: Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
{
varType = nVarType;
varName = nVarName;
isArray = nIsArray;
}
Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, string nVarType, string nVarName, bool nIsArray, string nText) : Declaration(nAlignment, nPadding, nSize, nText)
Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding,
uint32_t nSize, string nVarType, string nVarName, bool nIsArray,
string nText)
: Declaration(nAlignment, nPadding, nSize, nText)
{
varType = nVarType;
varName = nVarName;
isArray = nIsArray;
}
Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType, string nVarName, bool nIsArray, int nArrayItemCnt, string nText) : Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string nVarType,
string nVarName, bool nIsArray, int nArrayItemCnt, string nText)
: Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
{
varType = nVarType;
varName = nVarName;
@ -586,7 +678,10 @@ Declaration::Declaration(DeclarationAlignment nAlignment, uint32_t nSize, string
arrayItemCnt = nArrayItemCnt;
}
Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, uint32_t nSize, string nVarType, string nVarName, bool nIsArray, int nArrayItemCnt, string nText) : Declaration(nAlignment, nPadding, nSize, nText)
Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding,
uint32_t nSize, string nVarType, string nVarName, bool nIsArray,
int nArrayItemCnt, string nText)
: Declaration(nAlignment, nPadding, nSize, nText)
{
varType = nVarType;
varName = nVarName;
@ -594,7 +689,8 @@ Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPa
arrayItemCnt = nArrayItemCnt;
}
Declaration::Declaration(std::string nIncludePath, uint32_t nSize, string nVarType, string nVarName) : Declaration(DeclarationAlignment::None, DeclarationPadding::None, nSize, "")
Declaration::Declaration(std::string nIncludePath, uint32_t nSize, string nVarType, string nVarName)
: Declaration(DeclarationAlignment::None, DeclarationPadding::None, nSize, "")
{
includePath = nIncludePath;
varType = nVarType;

View file

@ -1,13 +1,13 @@
#pragma once
#include <tinyxml2.h>
#include "../ZResource.h"
#include "ZRoomCommand.h"
#include "ZTexture.h"
#include <tinyxml2.h>
#include <vector>
#include <map>
#include <string>
#include <vector>
class ZRoom : public ZResource
{
@ -29,7 +29,9 @@ public:
std::string extDefines;
static ZRoom* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nRelPath, ZFile* nParent, ZRoom* nScene);
static ZRoom* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData,
int rawDataIndex, std::string nRelPath, ZFile* nParent,
ZRoom* nScene);
void ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet commandSet);
size_t GetDeclarationSizeFromNeighbor(int declarationAddress);
size_t GetCommandSizeFromNeighbor(ZRoomCommand* cmd);

View file

@ -13,7 +13,8 @@ string ZRoomCommand::GenerateSourceCodePass1(string roomName, int baseAddress)
{
char line[2048];
//sprintf(line, "%s _%s_set%04X_cmd%02X = { 0x%02X,", GetCommandCName().c_str(), roomName.c_str(), baseAddress, cmdIndex, cmdID);
// sprintf(line, "%s _%s_set%04X_cmd%02X = { 0x%02X,", GetCommandCName().c_str(),
// roomName.c_str(), baseAddress, cmdIndex, cmdID);
sprintf(line, " 0x%02X,", (uint8_t)cmdID);
return string(line);

View file

@ -2,8 +2,8 @@
#include <tinyxml2.h>
#include <vector>
#include <string>
#include <vector>
class ZRoom;

View file

@ -1,11 +1,12 @@
#include "ZScalar.h"
#include "ZFile.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "File.h"
#include "Globals.h"
#include "StringHelper.h"
#include "ZFile.h"
ZScalar* ZScalar::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath)
ZScalar* ZScalar::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const int rawDataIndex, const std::string& nRelPath)
{
ZScalar* scalar = new ZScalar();
scalar->rawData = nRawData;
@ -83,7 +84,8 @@ ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type)
std::string ZScalar::MapScalarTypeToOutputType(const ZScalarType scalarType)
{
switch (scalarType) {
switch (scalarType)
{
case ZSCALAR_S8:
return "s8";
case ZSCALAR_U8:
@ -111,7 +113,8 @@ std::string ZScalar::MapScalarTypeToOutputType(const ZScalarType scalarType)
int ZScalar::MapTypeToSize(const ZScalarType scalarType)
{
switch (scalarType) {
switch (scalarType)
{
case ZSCALAR_S8:
return sizeof(scalarData.s8);
case ZSCALAR_U8:
@ -149,7 +152,8 @@ void ZScalar::ParseRawData()
void ZScalar::ParseRawData(const std::vector<uint8_t>& data, const int offset)
{
switch (scalarType) {
switch (scalarType)
{
case ZSCALAR_S8:
scalarData.s8 = BitConverter::ToInt8BE(data, offset);
break;
@ -180,6 +184,10 @@ void ZScalar::ParseRawData(const std::vector<uint8_t>& data, const int offset)
case ZSCALAR_F64:
scalarData.f64 = BitConverter::ToDoubleBE(data, offset);
break;
case ZSCALAR_NONE:
fprintf(stderr, "Warning in ZScalar: Invalid type. %d %s %d\n", (int)scalarType, __FILE__,
__LINE__);
break;
}
}
@ -190,7 +198,8 @@ std::string ZScalar::GetSourceTypeName()
std::string ZScalar::GetSourceValue()
{
switch (scalarType) {
switch (scalarType)
{
case ZSCALAR_S8:
return StringHelper::Sprintf("%hhd", scalarData.s8);
case ZSCALAR_U8:
@ -219,7 +228,8 @@ std::string ZScalar::GetSourceValue()
std::string ZScalar::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), GetSourceTypeName(), GetName(), GetSourceValue());
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), GetName(), GetSourceValue());
return "";
}

View file

@ -1,12 +1,13 @@
#pragma once
#include <vector>
#include <string>
#include <stdint.h>
#include <string>
#include <vector>
#include "ZResource.h"
#include "tinyxml2.h"
typedef enum ZScalarType {
typedef enum ZScalarType
{
ZSCALAR_NONE,
ZSCALAR_S8,
ZSCALAR_U8,
@ -20,7 +21,8 @@ typedef enum ZScalarType {
ZSCALAR_F64
} ZScalarType;
typedef union ZScalarData {
typedef union ZScalarData
{
uint8_t u8;
int8_t s8;
uint16_t u16;
@ -35,7 +37,8 @@ typedef union ZScalarData {
class ZScalar : public ZResource
{
friend class ZVector;
friend class ZVector;
public:
ZScalarData scalarData;
ZScalarType scalarType;
@ -52,7 +55,9 @@ public:
bool DoesSupportArray() override;
void ParseRawData() override;
static ZScalar* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath);
static ZScalar* ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData, const int rawDataIndex,
const std::string& nRelPath);
static int MapTypeToSize(const ZScalarType scalarType);
static ZScalarType MapOutputTypeToScalarType(const std::string& type);
static std::string MapScalarTypeToOutputType(const ZScalarType scalarType);

View file

@ -1,12 +1,12 @@
#include "ZSkeleton.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "HighLevel/HLModelIntermediette.h"
#include "StringHelper.h"
using namespace std;
ZSkeleton::ZSkeleton(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex, ZFile* nParent)
ZSkeleton::ZSkeleton(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
int nRawDataIndex, ZFile* nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
@ -19,11 +19,41 @@ ZSkeleton::ZSkeleton(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& n
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress);
for (size_t i = 0; i < limbCount; i++) {
for (size_t i = 0; i < limbCount; i++)
{
uint32_t ptr2 = Seg2Filespace(BitConverter::ToUInt32BE(rawData, ptr), parent->baseAddress);
ZLimb* limb = new ZLimb(reader, rawData, ptr2, parent);
limb->SetName(StringHelper::Sprintf("%sLimb_%06X", defaultPrefix.c_str(), limb->GetFileAddress()));
limb->SetName(
StringHelper::Sprintf("%sLimb_%06X", defaultPrefix.c_str(), limb->GetFileAddress()));
limbs.push_back(limb);
ptr += 4;
}
}
ZSkeleton::ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix,
const std::vector<uint8_t>& nRawData, int nRawDataIndex, ZFile* nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
name = StringHelper::Sprintf("%sSkel_%06X", prefix.c_str(), rawDataIndex);
type = nType;
limbType = nLimbType;
ParseRawData();
string defaultPrefix = name;
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress);
for (size_t i = 0; i < limbCount; i++)
{
uint32_t ptr2 = Seg2Filespace(BitConverter::ToUInt32BE(rawData, ptr), parent->baseAddress);
ZLimb* limb = new ZLimb(limbType, prefix, rawData, ptr2, parent);
limbs.push_back(limb);
ptr += 4;
@ -32,7 +62,8 @@ ZSkeleton::ZSkeleton(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& n
ZSkeleton::~ZSkeleton()
{
for (auto& limb: limbs) {
for (auto& limb : limbs)
{
delete limb;
}
}
@ -42,39 +73,69 @@ void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader)
ZResource::ParseXML(reader);
const char* skelTypeXml = reader->Attribute("Type");
if (skelTypeXml == nullptr) {
fprintf(stderr, "ZSkeleton::ParseXML: Warning in '%s'.\n\t Type not found found. Defaulting to 'Normal'.\n", name.c_str());
if (skelTypeXml == nullptr)
{
fprintf(stderr,
"ZSkeleton::ParseXML: Warning in '%s'.\n\t Type not found found. Defaulting to "
"'Normal'.\n",
name.c_str());
type = ZSkeletonType::Normal;
}
else {
else
{
string skelTypeStr(skelTypeXml);
if (skelTypeStr == "Flex") {
if (skelTypeStr == "Flex")
{
type = ZSkeletonType::Flex;
}
else if (skelTypeStr != "Normal") {
fprintf(stderr, "ZSkeleton::ParseXML: Warning in '%s'.\n\t Invalid Type found: '%s'. Defaulting to 'Normal'.\n", name.c_str(), skelTypeXml);
else if (skelTypeStr == "Curve")
{
type = ZSkeletonType::Curve;
}
else if (skelTypeStr != "Normal" && skelTypeStr != "Standard")
{
fprintf(stderr,
"ZSkeleton::ParseXML: Warning in '%s'.\n\t Invalid Type found: '%s'. "
"Defaulting to 'Normal'.\n",
name.c_str(), skelTypeXml);
type = ZSkeletonType::Normal;
}
}
const char* limbTypeXml = reader->Attribute("LimbType");
if (limbTypeXml == nullptr) {
fprintf(stderr, "ZSkeleton::ParseXML: Warning in '%s'.\n\t LimbType not found found. Defaulting to 'Standard'.\n", name.c_str());
if (limbTypeXml == nullptr)
{
fprintf(stderr,
"ZSkeleton::ParseXML: Warning in '%s'.\n\t LimbType not found found. Defaulting to "
"'Standard'.\n",
name.c_str());
limbType = ZLimbType::Standard;
}
else {
else
{
string limbTypeStr(limbTypeXml);
if (limbTypeStr == "Standard") {
if (limbTypeStr == "Standard")
{
limbType = ZLimbType::Standard;
}
else if (limbTypeStr == "LOD") {
else if (limbTypeStr == "LOD")
{
limbType = ZLimbType::LOD;
}
else if (limbTypeStr == "Skin") {
else if (limbTypeStr == "Skin")
{
limbType = ZLimbType::Skin;
}
else {
fprintf(stderr, "ZSkeleton::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. Defaulting to 'Standard'.\n", name.c_str(), limbTypeXml);
else if (limbTypeStr == "Curve")
{
limbType = ZLimbType::Curve;
}
else
{
fprintf(stderr,
"ZSkeleton::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. "
"Defaulting to 'Standard'.\n",
name.c_str(), limbTypeXml);
limbType = ZLimbType::Standard;
}
}
@ -89,14 +150,15 @@ void ZSkeleton::ParseRawData()
dListCount = BitConverter::ToUInt8BE(rawData, rawDataIndex + 8);
}
ZSkeleton* ZSkeleton::FromXML(tinyxml2::XMLElement* reader, vector<uint8_t> nRawData, int rawDataIndex, string nRelPath, ZFile* nParent)
ZSkeleton* ZSkeleton::FromXML(tinyxml2::XMLElement* reader, vector<uint8_t> nRawData,
int rawDataIndex, string nRelPath, ZFile* nParent)
{
ZSkeleton* skeleton = new ZSkeleton(reader, nRawData, rawDataIndex, nParent);
skeleton->relativePath = std::move(nRelPath);
skeleton->parent->AddDeclaration(
skeleton->rawDataIndex, DeclarationAlignment::Align16, skeleton->GetRawDataSize(),
skeleton->GetSourceTypeName(), skeleton->name, "");
skeleton->parent->AddDeclaration(skeleton->rawDataIndex, DeclarationAlignment::Align16,
skeleton->GetRawDataSize(), skeleton->GetSourceTypeName(),
skeleton->name, "");
return skeleton;
}
@ -109,16 +171,17 @@ void ZSkeleton::GenerateHLIntermediette(HLFileIntermediette& hlFile)
{
HLModelIntermediette* mdl = (HLModelIntermediette*)&hlFile;
HLModelIntermediette::FromZSkeleton(mdl, this);
//mdl->blocks.push_back(new HLTerminator());
// mdl->blocks.push_back(new HLTerminator());
}
int ZSkeleton::GetRawDataSize()
{
switch (type) {
case ZSkeletonType::Normal:
return 0x8;
switch (type)
{
case ZSkeletonType::Flex:
return 0xC;
case ZSkeletonType::Normal:
case ZSkeletonType::Curve:
default:
return 0x8;
}
@ -126,14 +189,16 @@ int ZSkeleton::GetRawDataSize()
std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix)
{
if (parent == nullptr) {
if (parent == nullptr)
{
return "";
}
string defaultPrefix = name.c_str();
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
for (auto& limb: limbs) {
for (auto& limb : limbs)
{
limb->GetSourceOutputCode(defaultPrefix);
}
@ -147,35 +212,42 @@ std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix)
{
ZLimb* limb = limbs.at(i);
string decl = StringHelper::Sprintf(" &%s,", parent->GetDeclarationName(limb->GetFileAddress()).c_str());
if (i != (limbs.size() - 1)) {
string decl = StringHelper::Sprintf(
" &%s,", parent->GetDeclarationName(limb->GetFileAddress()).c_str());
if (i != (limbs.size() - 1))
{
decl += "\n";
}
tblStr += decl;
}
parent->AddDeclarationArray(ptr, DeclarationAlignment::None, 4 * limbCount,
StringHelper::Sprintf("static %s*", ZLimb::GetSourceTypeName(limbType)),
StringHelper::Sprintf("%sLimbs", defaultPrefix.c_str()), limbCount, tblStr);
parent->AddDeclarationArray(ptr, DeclarationAlignment::None, 4 * limbCount, "static void*",
StringHelper::Sprintf("%sLimbs", defaultPrefix.c_str()),
limbCount, tblStr);
}
string headerStr;
switch (type) {
switch (type)
{
case ZSkeletonType::Normal:
case ZSkeletonType::Curve:
headerStr = StringHelper::Sprintf("%sLimbs, %i", defaultPrefix.c_str(), limbCount);
break;
case ZSkeletonType::Flex:
headerStr = StringHelper::Sprintf("%sLimbs, %i, %i", defaultPrefix.c_str(), limbCount, dListCount);
headerStr =
StringHelper::Sprintf("%sLimbs, %i, %i", defaultPrefix.c_str(), limbCount, dListCount);
break;
}
Declaration* decl = parent->GetDeclaration(GetAddress());
if (decl == nullptr) {
parent->AddDeclaration(GetAddress(), DeclarationAlignment::Align16,
GetRawDataSize(), GetSourceTypeName(), name, headerStr);
if (decl == nullptr)
{
parent->AddDeclaration(GetAddress(), DeclarationAlignment::Align16, GetRawDataSize(),
GetSourceTypeName(), name, headerStr);
}
else {
else
{
decl->text = headerStr;
}
@ -184,11 +256,14 @@ std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix)
std::string ZSkeleton::GetSourceTypeName()
{
switch (type) {
switch (type)
{
case ZSkeletonType::Normal:
return "SkeletonHeader";
case ZSkeletonType::Flex:
return "FlexSkeletonHeader";
case ZSkeletonType::Curve:
return "SkelCurveLimbList";
}
return "SkeletonHeader";
}
@ -202,3 +277,8 @@ segptr_t ZSkeleton::GetAddress()
{
return rawDataIndex;
}
uint8_t ZSkeleton::GetLimbCount()
{
return limbCount;
}

View file

@ -1,16 +1,17 @@
#pragma once
#include <vector>
#include <string>
#include <cstdint>
#include "ZFile.h"
#include <string>
#include <vector>
#include "ZDisplayList.h"
#include "ZFile.h"
#include "ZLimb.h"
enum ZSkeletonType
{
Normal,
Flex
Flex,
Curve,
};
class ZSkeleton : public ZResource
@ -23,11 +24,16 @@ public:
uint8_t limbCount;
uint8_t dListCount; // FLEX SKELETON ONLY
ZSkeleton(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex, ZFile* nParent);
ZSkeleton() = default;
ZSkeleton(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex,
ZFile* nParent);
ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix,
const std::vector<uint8_t>& nRawData, int nRawDataIndex, ZFile* nParent);
~ZSkeleton();
void ParseXML(tinyxml2::XMLElement* reader) override;
void ParseRawData() override;
static ZSkeleton* FromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nRelPath, ZFile* nParent);
static ZSkeleton* FromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData,
int rawDataIndex, std::string nRelPath, ZFile* nParent);
void Save(const std::string& outFolder) override;
void GenerateHLIntermediette(HLFileIntermediette& hlFile) override;
@ -38,4 +44,5 @@ public:
ZResourceType GetResourceType() override;
segptr_t GetAddress();
uint8_t GetLimbCount();
};

105
tools/ZAPD/ZAPD/ZSymbol.cpp Normal file
View file

@ -0,0 +1,105 @@
#include "ZSymbol.h"
#include "StringHelper.h"
ZSymbol::ZSymbol(const std::string& nName, int nRawDataIndex, const std::string& nType,
uint32_t nTypeSize, bool nIsArray, uint32_t nCount)
: type(nType), typeSize(nTypeSize), isArray(nIsArray), count(nCount)
{
name = nName;
rawDataIndex = nRawDataIndex;
}
ZSymbol::ZSymbol(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
int nRawDataIndex, ZFile* nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
ParseXML(reader);
}
ZSymbol* ZSymbol::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
int nRawDataIndex, ZFile* parent)
{
ZSymbol* symbol = new ZSymbol(reader, nRawData, nRawDataIndex, parent);
return symbol;
}
void ZSymbol::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
const char* typeXml = reader->Attribute("Type");
if (typeXml == nullptr)
{
fprintf(stderr,
"ZSymbol::ParseXML: Warning in '%s'.\n\t Missing 'Type' attribute in xml. "
"Defaulting to 'void*'.\n",
name.c_str());
type = "void*";
}
else
{
type = std::string(typeXml);
}
const char* typeSizeXml = reader->Attribute("TypeSize");
if (typeSizeXml == nullptr)
{
fprintf(stderr,
"ZSymbol::ParseXML: Warning in '%s'.\n\t Missing 'TypeSize' attribute in xml. "
"Defaulting to '4'.\n",
name.c_str());
typeSize = 4; // Size of a word.
}
else
{
typeSize = std::strtoul(typeSizeXml, nullptr, 0);
}
const char* countXml = reader->Attribute("Count");
if (countXml != nullptr)
{
isArray = true;
if (!std::string(countXml).empty())
{
count = std::strtoul(countXml, nullptr, 0);
}
}
}
int ZSymbol::GetRawDataSize()
{
if (isArray)
{
return count * typeSize;
}
return typeSize;
}
std::string ZSymbol::GetSourceOutputHeader(const std::string& prefix)
{
if (isArray)
{
if (count == 0)
{
return StringHelper::Sprintf("extern %s %s%s[];\n", type.c_str(), prefix.c_str(),
name.c_str());
}
return StringHelper::Sprintf("extern %s %s%s[%i];\n", type.c_str(), prefix.c_str(),
name.c_str(), count);
}
return StringHelper::Sprintf("extern %s %s%s;\n", type.c_str(), prefix.c_str(), name.c_str());
}
std::string ZSymbol::GetSourceTypeName()
{
return type;
}
ZResourceType ZSymbol::GetResourceType()
{
return ZResourceType::Symbol;
}

33
tools/ZAPD/ZAPD/ZSymbol.h Normal file
View file

@ -0,0 +1,33 @@
#pragma once
#include "ZResource.h"
#include "tinyxml2.h"
class ZSymbol : public ZResource
{
protected:
std::string type;
uint32_t typeSize;
bool isArray = false;
uint32_t count = 0;
public:
ZSymbol() = default;
ZSymbol(const std::string& nName, int nRawDataIndex, const std::string& nType,
uint32_t nTypeSize, bool nIsArray, uint32_t nCount);
ZSymbol(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int nRawDataIndex,
ZFile* nParent);
static ZSymbol* ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData, int nRawDataIndex,
ZFile* parent);
void ParseXML(tinyxml2::XMLElement* reader) override;
int GetRawDataSize() override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
std::string GetSourceTypeName() override;
ZResourceType GetResourceType() override;
};

View file

@ -3,10 +3,10 @@
#define TINYGLTF_IMPLEMENTATION
#include "ZTexture.h"
#include "StringHelper.h"
#include "BitConverter.h"
#include "Path.h"
#include "File.h"
#include "Path.h"
#include "StringHelper.h"
#include "stb_image.h"
#include "stb_image_write.h"
@ -44,13 +44,15 @@ ZTexture::~ZTexture()
}
// EXTRACT MODE
ZTexture* ZTexture::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int nRawDataIndex, string nRelPath)
ZTexture* ZTexture::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData, int nRawDataIndex,
string nRelPath)
{
ZTexture* tex = new ZTexture();
tex->ParseXML(reader);
tex->rawDataIndex = nRawDataIndex;
tex->rawData = vector<uint8_t>(nRawData.data() + tex->rawDataIndex, nRawData.data() + tex->rawDataIndex + tex->GetRawDataSize());
tex->rawData = vector<uint8_t>(nRawData.data() + tex->rawDataIndex,
nRawData.data() + tex->rawDataIndex + tex->GetRawDataSize());
tex->relativePath = nRelPath;
@ -60,7 +62,8 @@ ZTexture* ZTexture::ExtractFromXML(XMLElement* reader, vector<uint8_t> nRawData,
return tex;
}
ZTexture* ZTexture::FromBinary(TextureType nType, std::vector<uint8_t> nRawData, int nRawDataIndex, std::string nName, int nWidth, int nHeight)
ZTexture* ZTexture::FromBinary(TextureType nType, std::vector<uint8_t> nRawData, int nRawDataIndex,
std::string nName, int nWidth, int nHeight)
{
ZTexture* tex = new ZTexture();
@ -100,22 +103,43 @@ ZTexture* ZTexture::FromPNG(string pngFilePath, TextureType texType)
tex->type = texType;
tex->name = StringHelper::Split(Path::GetFileNameWithoutExtension(pngFilePath), ".")[0];
tex->bmpRgb = (uint8_t*)stbi_load((pngFilePath).c_str(), &tex->width, &tex->height, &comp, STBI_rgb);
tex->bmpRgb =
(uint8_t*)stbi_load((pngFilePath).c_str(), &tex->width, &tex->height, &comp, STBI_rgb);
stbi_image_free(tex->bmpRgb);
tex->bmpRgb = nullptr;
tex->rawData = vector<uint8_t>(tex->GetRawDataSize());
switch (texType)
{
case TextureType::RGBA16bpp: tex->PrepareRawDataRGBA16(pngFilePath); break;
case TextureType::RGBA32bpp: tex->PrepareRawDataRGBA32(pngFilePath); break;
case TextureType::Grayscale4bpp: tex->PrepareRawDataGrayscale4(pngFilePath); break;
case TextureType::Grayscale8bpp: tex->PrepareRawDataGrayscale8(pngFilePath); break;
case TextureType::GrayscaleAlpha4bpp: tex->PrepareRawDataGrayscaleAlpha4(pngFilePath); break;
case TextureType::GrayscaleAlpha8bpp: tex->PrepareRawDataGrayscaleAlpha8(pngFilePath); break;
case TextureType::GrayscaleAlpha16bpp: tex->PrepareRawDataGrayscaleAlpha16(pngFilePath); break;
case TextureType::Palette4bpp: tex->PrepareRawDataPalette4(pngFilePath); break;
case TextureType::Palette8bpp: tex->PrepareRawDataPalette8(pngFilePath); break;
case TextureType::RGBA16bpp:
tex->PrepareRawDataRGBA16(pngFilePath);
break;
case TextureType::RGBA32bpp:
tex->PrepareRawDataRGBA32(pngFilePath);
break;
case TextureType::Grayscale4bpp:
tex->PrepareRawDataGrayscale4(pngFilePath);
break;
case TextureType::Grayscale8bpp:
tex->PrepareRawDataGrayscale8(pngFilePath);
break;
case TextureType::GrayscaleAlpha4bpp:
tex->PrepareRawDataGrayscaleAlpha4(pngFilePath);
break;
case TextureType::GrayscaleAlpha8bpp:
tex->PrepareRawDataGrayscaleAlpha8(pngFilePath);
break;
case TextureType::GrayscaleAlpha16bpp:
tex->PrepareRawDataGrayscaleAlpha16(pngFilePath);
break;
case TextureType::Palette4bpp:
tex->PrepareRawDataPalette4(pngFilePath);
break;
case TextureType::Palette8bpp:
tex->PrepareRawDataPalette8(pngFilePath);
break;
default:
throw std::runtime_error("Format is not supported!");
}
tex->FixRawData();
@ -149,23 +173,23 @@ void ZTexture::ParseXML(XMLElement* reader)
type = GetTextureTypeFromString(formatStr);
if (type == TextureType::Error)
throw "Format " + formatStr + " is not supported!";
throw std::runtime_error("Format " + formatStr + " is not supported!");
}
void ZTexture::FixRawData()
{
if (type == TextureType::RGBA32bpp)
{
for (int i = 0; i < rawData.size(); i += 4)
for (size_t i = 0; i < rawData.size(); i += 4)
{
uint8_t tmp = rawData[i];
rawData[i] = rawData[i + 2];
rawData[i + 2] = tmp;
}
}
else if (type == TextureType::RGBA16bpp)// || type == TextureType::GrayscaleAlpha16bpp)
else if (type == TextureType::RGBA16bpp) // || type == TextureType::GrayscaleAlpha16bpp)
{
for (int i = 0; i < rawData.size(); i += 2)
for (size_t i = 0; i < rawData.size(); i += 2)
{
uint8_t tmp = rawData[i];
rawData[i] = rawData[i + 1];
@ -181,15 +205,35 @@ void ZTexture::PrepareBitmap()
switch (type)
{
case TextureType::RGBA16bpp: PrepareBitmapRGBA16(); break;
case TextureType::RGBA32bpp: PrepareBitmapRGBA32(); break;
case TextureType::Grayscale4bpp: PrepareBitmapGrayscale4(); break;
case TextureType::Grayscale8bpp: PrepareBitmapGrayscale8(); break;
case TextureType::GrayscaleAlpha4bpp: PrepareBitmapGrayscaleAlpha4(); break;
case TextureType::GrayscaleAlpha8bpp: PrepareBitmapGrayscaleAlpha8(); break;
case TextureType::GrayscaleAlpha16bpp: PrepareBitmapGrayscaleAlpha16(); break;
case TextureType::Palette4bpp: PrepareBitmapPalette4(); break;
case TextureType::Palette8bpp: PrepareBitmapPalette8(); break;
case TextureType::RGBA16bpp:
PrepareBitmapRGBA16();
break;
case TextureType::RGBA32bpp:
PrepareBitmapRGBA32();
break;
case TextureType::Grayscale4bpp:
PrepareBitmapGrayscale4();
break;
case TextureType::Grayscale8bpp:
PrepareBitmapGrayscale8();
break;
case TextureType::GrayscaleAlpha4bpp:
PrepareBitmapGrayscaleAlpha4();
break;
case TextureType::GrayscaleAlpha8bpp:
PrepareBitmapGrayscaleAlpha8();
break;
case TextureType::GrayscaleAlpha16bpp:
PrepareBitmapGrayscaleAlpha16();
break;
case TextureType::Palette4bpp:
PrepareBitmapPalette4();
break;
case TextureType::Palette8bpp:
PrepareBitmapPalette8();
break;
default:
throw std::runtime_error("Format is not supported!");
}
}
@ -378,17 +422,35 @@ void ZTexture::PrepareRawData(string inFolder)
switch (type)
{
case TextureType::RGBA16bpp: PrepareRawDataRGBA16(inFolder + "/" + outName + ".rgba5a1.png"); break;
case TextureType::RGBA32bpp: PrepareRawDataRGBA32(inFolder + "/" + outName + ".rgba32.png"); break;
case TextureType::Grayscale4bpp: PrepareRawDataGrayscale4(inFolder + "/" + outName + ".i4.png"); break;
case TextureType::Grayscale8bpp: PrepareRawDataGrayscale8(inFolder + "/" + outName + ".i8.png"); break;
case TextureType::GrayscaleAlpha4bpp: PrepareRawDataGrayscaleAlpha4(inFolder + "/" + outName + ".ia4.png"); break;
case TextureType::GrayscaleAlpha8bpp: PrepareRawDataGrayscaleAlpha8(inFolder + "/" + outName + ".ia8.png"); break;
case TextureType::GrayscaleAlpha16bpp: PrepareRawDataGrayscaleAlpha16(inFolder + "/" + outName + ".ia16.png"); break;
case TextureType::Palette4bpp: PrepareRawDataPalette4(inFolder + "/" + outName + ".ci4.png"); break;
case TextureType::Palette8bpp: PrepareRawDataPalette8(inFolder + "/" + outName + ".ci8.png"); break;
case TextureType::RGBA16bpp:
PrepareRawDataRGBA16(inFolder + "/" + outName + ".rgba5a1.png");
break;
case TextureType::RGBA32bpp:
PrepareRawDataRGBA32(inFolder + "/" + outName + ".rgba32.png");
break;
case TextureType::Grayscale4bpp:
PrepareRawDataGrayscale4(inFolder + "/" + outName + ".i4.png");
break;
case TextureType::Grayscale8bpp:
PrepareRawDataGrayscale8(inFolder + "/" + outName + ".i8.png");
break;
case TextureType::GrayscaleAlpha4bpp:
PrepareRawDataGrayscaleAlpha4(inFolder + "/" + outName + ".ia4.png");
break;
case TextureType::GrayscaleAlpha8bpp:
PrepareRawDataGrayscaleAlpha8(inFolder + "/" + outName + ".ia8.png");
break;
case TextureType::GrayscaleAlpha16bpp:
PrepareRawDataGrayscaleAlpha16(inFolder + "/" + outName + ".ia16.png");
break;
case TextureType::Palette4bpp:
PrepareRawDataPalette4(inFolder + "/" + outName + ".ci4.png");
break;
case TextureType::Palette8bpp:
PrepareRawDataPalette8(inFolder + "/" + outName + ".ci8.png");
break;
default:
throw "Build Mode: Format is not supported!";
throw std::runtime_error("Build Mode: Format is not supported!");
}
}
@ -603,13 +665,22 @@ float ZTexture::GetPixelMultiplyer()
{
switch (type)
{
case TextureType::Grayscale4bpp: case TextureType::GrayscaleAlpha4bpp: case TextureType::Palette4bpp: return 0.5f;
case TextureType::Grayscale8bpp: case TextureType::GrayscaleAlpha8bpp: case TextureType::Palette8bpp: return 1;
case TextureType::GrayscaleAlpha16bpp: case TextureType::RGBA16bpp: return 2;
case TextureType::RGBA32bpp: return 4;
}
case TextureType::Grayscale4bpp:
case TextureType::GrayscaleAlpha4bpp:
case TextureType::Palette4bpp:
return 0.5f;
case TextureType::Grayscale8bpp:
case TextureType::GrayscaleAlpha8bpp:
case TextureType::Palette8bpp:
return 1;
case TextureType::GrayscaleAlpha16bpp:
case TextureType::RGBA16bpp:
return 2;
case TextureType::RGBA32bpp:
return 4;
default:
return -1;
}
}
vector<uint8_t> ZTexture::GetRawData()
@ -626,26 +697,43 @@ std::string ZTexture::GetIMFmtFromType()
{
switch (type)
{
case TextureType::RGBA32bpp: case TextureType::RGBA16bpp: return "G_IM_FMT_RGBA";
case TextureType::Grayscale4bpp: case TextureType::Grayscale8bpp: return "G_IM_FMT_I";
case TextureType::Palette4bpp: case TextureType::Palette8bpp: return "G_IM_FMT_CI";
case TextureType::GrayscaleAlpha4bpp: case TextureType::GrayscaleAlpha8bpp: case TextureType::GrayscaleAlpha16bpp: return "G_IM_FMT_IA";
}
case TextureType::RGBA32bpp:
case TextureType::RGBA16bpp:
return "G_IM_FMT_RGBA";
case TextureType::Grayscale4bpp:
case TextureType::Grayscale8bpp:
return "G_IM_FMT_I";
case TextureType::Palette4bpp:
case TextureType::Palette8bpp:
return "G_IM_FMT_CI";
case TextureType::GrayscaleAlpha4bpp:
case TextureType::GrayscaleAlpha8bpp:
case TextureType::GrayscaleAlpha16bpp:
return "G_IM_FMT_IA";
default:
return "ERROR";
}
}
std::string ZTexture::GetIMSizFromType()
{
switch (type)
{
case TextureType::Grayscale4bpp: case TextureType::Palette4bpp: case TextureType::GrayscaleAlpha4bpp: return "G_IM_SIZ_4b";
case TextureType::Palette8bpp: case TextureType::Grayscale8bpp: return "G_IM_SIZ_8b";
case TextureType::GrayscaleAlpha16bpp: case TextureType::RGBA16bpp: return "G_IM_SIZ_16b";
case TextureType::RGBA32bpp: return "G_IM_SIZ_32b";
}
case TextureType::Grayscale4bpp:
case TextureType::Palette4bpp:
case TextureType::GrayscaleAlpha4bpp:
return "G_IM_SIZ_4b";
case TextureType::Palette8bpp:
case TextureType::Grayscale8bpp:
return "G_IM_SIZ_8b";
case TextureType::GrayscaleAlpha16bpp:
case TextureType::RGBA16bpp:
return "G_IM_SIZ_16b";
case TextureType::RGBA32bpp:
return "G_IM_SIZ_32b";
default:
return "ERROR";
}
}
int ZTexture::GetWidth()
@ -676,26 +764,35 @@ TextureType ZTexture::GetTextureType()
void ZTexture::Save(const std::string& outFolder)
{
if (type == TextureType::RGBA32bpp)
stbi_write_png((outFolder + "/" + outName + ".rgba32.png").c_str(), width, height, 4, bmpRgba, width * 4);
stbi_write_png((outFolder + "/" + outName + ".rgba32.png").c_str(), width, height, 4,
bmpRgba, width * 4);
else if (type == TextureType::RGBA16bpp)
stbi_write_png((outFolder + "/" + outName + ".rgb5a1.png").c_str(), width, height, 4, bmpRgba, width * 4);
stbi_write_png((outFolder + "/" + outName + ".rgb5a1.png").c_str(), width, height, 4,
bmpRgba, width * 4);
else if (type == TextureType::Grayscale8bpp)
stbi_write_png((outFolder + "/" + outName + ".i8.png").c_str(), width, height, 3, bmpRgb, width * 3);
stbi_write_png((outFolder + "/" + outName + ".i8.png").c_str(), width, height, 3, bmpRgb,
width * 3);
else if (type == TextureType::Grayscale4bpp)
stbi_write_png((outFolder + "/" + outName + ".i4.png").c_str(), width, height, 3, bmpRgb, width * 3);
stbi_write_png((outFolder + "/" + outName + ".i4.png").c_str(), width, height, 3, bmpRgb,
width * 3);
else if (type == TextureType::GrayscaleAlpha16bpp)
stbi_write_png((outFolder + "/" + outName + ".ia16.png").c_str(), width, height, 4, bmpRgba, width * 4);
stbi_write_png((outFolder + "/" + outName + ".ia16.png").c_str(), width, height, 4, bmpRgba,
width * 4);
else if (type == TextureType::GrayscaleAlpha8bpp)
stbi_write_png((outFolder + "/" + outName + ".ia8.png").c_str(), width, height, 4, bmpRgba, width * 4);
stbi_write_png((outFolder + "/" + outName + ".ia8.png").c_str(), width, height, 4, bmpRgba,
width * 4);
else if (type == TextureType::GrayscaleAlpha4bpp)
stbi_write_png((outFolder + "/" + outName + ".ia4.png").c_str(), width, height, 4, bmpRgba, width * 4);
stbi_write_png((outFolder + "/" + outName + ".ia4.png").c_str(), width, height, 4, bmpRgba,
width * 4);
else if (type == TextureType::Palette4bpp)
stbi_write_png((outFolder + "/" + outName + ".ci4.png").c_str(), width, height, 3, bmpRgb, width * 3);
stbi_write_png((outFolder + "/" + outName + ".ci4.png").c_str(), width, height, 3, bmpRgb,
width * 3);
else if (type == TextureType::Palette8bpp)
stbi_write_png((outFolder + "/" + outName + ".ci8.png").c_str(), width, height, 3, bmpRgb, width * 3);
stbi_write_png((outFolder + "/" + outName + ".ci8.png").c_str(), width, height, 3, bmpRgb,
width * 3);
//if (outName != name && outName != "")
//File::WriteAllText(outFolder + "/" + outName + ".cfg", name.c_str());
// if (outName != name && outName != "")
// File::WriteAllText(outFolder + "/" + outName + ".cfg", name.c_str());
}
// HOTSPOT
@ -703,29 +800,33 @@ string ZTexture::GetSourceOutputCode(const std::string& prefix)
{
sourceOutput = "";
//sprintf(line, "%s:\n", name.c_str());
//sourceOutput += line;
// sprintf(line, "%s:\n", name.c_str());
// sourceOutput += line;
// TODO: TEMP
relativePath = "build/assets/" + relativePath;
FixRawData();
//sourceOutput += StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str());
// sourceOutput += StringHelper::Sprintf("u64 %s[] = \n{\n", name.c_str());
uint8_t* rawDataArr = rawData.data();
for (int i = 0; i < rawData.size(); i += 8)
for (size_t i = 0; i < rawData.size(); i += 8)
{
if (i % 32 == 0)
sourceOutput += "\t";
sourceOutput += StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(rawDataArr, i));
sourceOutput +=
StringHelper::Sprintf("0x%016llX, ", BitConverter::ToUInt64BE(rawDataArr, i));
if (i % 32 == 24)
sourceOutput += StringHelper::Sprintf(" // 0x%06X \n", rawDataIndex + ((i / 32) * 32));
}
//sourceOutput += "};\n";
// Ensure there's always a trailing line feed to prevent dumb warnings.
sourceOutput += "\n";
// sourceOutput += "};\n";
return sourceOutput;
}
@ -749,24 +850,32 @@ std::string ZTexture::GetExternalExtension()
{
switch (type)
{
case TextureType::RGBA32bpp: return "rgba32";
case TextureType::RGBA16bpp: return "rgb5a1";
case TextureType::Grayscale4bpp: return "i4";
case TextureType::Grayscale8bpp: return "i8";
case TextureType::GrayscaleAlpha4bpp: return "ia4";
case TextureType::GrayscaleAlpha8bpp: return "ia8";
case TextureType::GrayscaleAlpha16bpp: return "ia16";
case TextureType::Palette4bpp: return "ci4";
case TextureType::Palette8bpp: return "ci8";
case TextureType::RGBA32bpp:
return "rgba32";
case TextureType::RGBA16bpp:
return "rgb5a1";
case TextureType::Grayscale4bpp:
return "i4";
case TextureType::Grayscale8bpp:
return "i8";
case TextureType::GrayscaleAlpha4bpp:
return "ia4";
case TextureType::GrayscaleAlpha8bpp:
return "ia8";
case TextureType::GrayscaleAlpha16bpp:
return "ia16";
case TextureType::Palette4bpp:
return "ci4";
case TextureType::Palette8bpp:
return "ci8";
default:
return "ERROR";
}
return "";
}
string ZTexture::GetSourceOutputHeader(const std::string& prefix)
{
//return StringHelper::Sprintf("extern u64 %s[];\n", name.c_str());
// return StringHelper::Sprintf("extern u64 %s[];\n", name.c_str());
return "";
}
@ -793,6 +902,6 @@ TextureType ZTexture::GetTextureTypeFromString(string str)
else if (str == "ci8")
texType = TextureType::Palette8bpp;
else
printf("Encountered Unknown Texture Type %s \n",str.c_str());
fprintf(stderr, "Encountered Unknown Texture Type %s \n", str.c_str());
return texType;
}

View file

@ -1,7 +1,7 @@
#pragma once
#include "ZResource.h"
#include "HighLevel/HLTexture.h"
#include "ZResource.h"
#include "tinyxml2.h"
#include <vector>
@ -62,9 +62,12 @@ public:
bool isPalette;
static ZTexture* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder, bool readFile);
static ZTexture* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nRelPath);
static ZTexture* FromBinary(TextureType nType, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nName, int nWidth, int nHeight);
static ZTexture* BuildFromXML(tinyxml2::XMLElement* reader, std::string inFolder,
bool readFile);
static ZTexture* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData,
int rawDataIndex, std::string nRelPath);
static ZTexture* FromBinary(TextureType nType, std::vector<uint8_t> nRawData, int rawDataIndex,
std::string nName, int nWidth, int nHeight);
static ZTexture* FromPNG(std::string pngFilePath, TextureType texType);
static ZTexture* FromHLTexture(HLTexture* hlTex);
static TextureType GetTextureTypeFromString(std::string str);

View file

@ -1,10 +1,10 @@
#include "ZVector.h"
#include "ZFile.h"
#include <assert.h>
#include "BitConverter.h"
#include "StringHelper.h"
#include "File.h"
#include "Globals.h"
#include <assert.h>
#include "StringHelper.h"
#include "ZFile.h"
ZVector::ZVector() : ZResource()
{
@ -13,7 +13,8 @@ ZVector::ZVector() : ZResource()
this->dimensions = 0;
}
ZVector* ZVector::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath)
ZVector* ZVector::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const int rawDataIndex, const std::string& nRelPath)
{
ZVector* vector = new ZVector();
vector->rawData = nRawData;
@ -41,7 +42,7 @@ void ZVector::ParseRawData()
scalars.clear();
for (int i = 0; i < this->dimensions; i++)
for (uint32_t i = 0; i < this->dimensions; i++)
{
ZScalar* scalar = new ZScalar(this->scalarType);
scalar->rawDataIndex = currentRawDataIndex;
@ -59,7 +60,7 @@ void ZVector::ParseRawData()
int ZVector::GetRawDataSize()
{
int size = 0;
for (int i = 0; i < this->scalars.size(); i++)
for (size_t i = 0; i < this->scalars.size(); i++)
size += this->scalars[i]->GetRawDataSize();
return size;
}
@ -85,7 +86,9 @@ std::string ZVector::GetSourceTypeName()
}
else
{
std::string output = StringHelper::Sprintf("Encountered unsupported vector type: %d dimensions, %s type", dimensions, ZScalar::MapScalarTypeToOutputType(scalarType).c_str());
std::string output = StringHelper::Sprintf(
"Encountered unsupported vector type: %d dimensions, %s type", dimensions,
ZScalar::MapScalarTypeToOutputType(scalarType).c_str());
if (Globals::Instance->verbosity >= VERBOSITY_DEBUG)
printf("%s\n", output.c_str());
@ -97,7 +100,7 @@ std::string ZVector::GetSourceTypeName()
std::string ZVector::GetSourceValue()
{
std::vector<std::string> strings = std::vector<std::string>();
for (int i = 0; i < this->scalars.size(); i++)
for (size_t i = 0; i < this->scalars.size(); i++)
strings.push_back(scalars[i]->GetSourceValue());
return "{ " + StringHelper::Implode(strings, ", ") + " }";
}
@ -105,7 +108,8 @@ std::string ZVector::GetSourceValue()
std::string ZVector::GetSourceOutputCode(const std::string& prefix)
{
if (parent != nullptr)
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(), GetSourceTypeName(), GetName(), GetSourceValue());
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), GetName(), GetSourceValue());
return "";
}

View file

@ -1,8 +1,8 @@
#pragma once
#include <vector>
#include <string>
#include <stdint.h>
#include <string>
#include <vector>
#include "ZResource.h"
#include "ZScalar.h"
#include "tinyxml2.h"
@ -16,16 +16,18 @@ public:
ZVector();
void ParseXML(tinyxml2::XMLElement* reader);
void ParseXML(tinyxml2::XMLElement* reader) override;
std::string GetSourceTypeName() override;
std::string GetSourceValue();
std::string GetSourceOutputCode(const std::string& prefix);
std::string GetSourceOutputCode(const std::string& prefix) override;
void ParseRawData() override;
int GetRawDataSize();
int GetRawDataSize() override;
bool DoesSupportArray() override;
ZResourceType GetResourceType();
ZResourceType GetResourceType() override;
static ZVector* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath);
static ZVector* ExtractFromXML(tinyxml2::XMLElement* reader,
const std::vector<uint8_t>& nRawData, const int rawDataIndex,
const std::string& nRelPath);
protected:
};

View file

@ -1,7 +1,7 @@
#include "ZVtx.h"
#include "ZFile.h"
#include "StringHelper.h"
#include "BitConverter.h"
#include "StringHelper.h"
#include "ZFile.h"
ZVtx::ZVtx()
{
@ -28,10 +28,12 @@ std::string ZVtx::GetSourceTypeName()
std::string ZVtx::GetSourceOutputCode(const std::string& prefix)
{
std::string output = StringHelper::Sprintf("VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i)", x, y, z, s, t, r, g, b, a);
std::string output =
StringHelper::Sprintf("VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i)", x, y, z, s, t, r, g, b, a);
if (parent != nullptr)
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(), GetSourceTypeName(), name, output);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(),
GetSourceTypeName(), name, output);
return "";
}
@ -67,7 +69,8 @@ ZResourceType ZVtx::GetResourceType()
return ZResourceType::Vertex;
}
ZVtx* ZVtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath)
ZVtx* ZVtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const int rawDataIndex, const std::string& nRelPath)
{
ZVtx* vtx = new ZVtx();
vtx->rawData = nRawData;

View file

@ -1,8 +1,8 @@
#pragma once
#include <vector>
#include <string>
#include <stdint.h>
#include <string>
#include <vector>
#include "ZResource.h"
#include "ZScalar.h"
#include "tinyxml2.h"
@ -17,15 +17,16 @@ public:
ZVtx();
void ParseXML(tinyxml2::XMLElement* reader);
void ParseXML(tinyxml2::XMLElement* reader) override;
std::string GetSourceTypeName() override;
std::string GetSourceOutputCode(const std::string& prefix);
std::string GetSourceOutputCode(const std::string& prefix) override;
void ParseRawData() override;
int GetRawDataSize();
int GetRawDataSize() override;
bool DoesSupportArray() override;
ZResourceType GetResourceType();
ZResourceType GetResourceType() override;
static ZVtx* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath);
static ZVtx* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const int rawDataIndex, const std::string& nRelPath);
protected:
};

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016-2021 glank (glankk@github.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,25 @@
CFLAGS = -Wall -O2 -g
UC_OBJ = uc_f3d.o uc_f3db.o uc_f3dex.o uc_f3dexb.o uc_f3dex2.o
OBJ = gfxd.o $(UC_OBJ)
LIB = libgfxd.a
CPPFLAGS-$(MT) += -DCONFIG_MT
CPPFLAGS += $(CPPFLAGS-y)
.PHONY: all
all: $(LIB)
.PHONY: clean
clean:
rm -f $(OBJ) $(LIB)
.INTERMEDIATE: $(OBJ)
$(OBJ): gbi.h gfxd.h priv.h
$(UC_OBJ): uc.c uc_argfn.c uc_argtbl.c uc_macrofn.c uc_macrotbl.c
$(LIB): $(OBJ)
$(AR) rcs $@ $^
%.o: %.c
$(COMPILE.c) $(OUTPUT_OPTION) $<

View file

@ -0,0 +1,478 @@
## Installing
Run `make` for a single-threaded build, or `make MT=y` for a multi-threaded
build. Copy `libgfxd.a` to your lib directory, and `gfxd.h` to your include
directory.
## Example usage
Example source code:
```
#include <stdio.h>
#include <gfxd.h>
static int macro_fn(void)
{
/* Print a tab before each macro, and a comma and newline after each
macro */
gfxd_puts("\t");
gfxd_macro_dflt(); /* Execute the default macro handler */
gfxd_puts(",\n");
return 0;
}
int main()
{
/* Read from stdin and write to stdout */
gfxd_input_fd(fileno(stdin));
gfxd_output_fd(fileno(stdout));
/* Override the default macro handler to make the output prettier */
gfxd_macro_fn(macro_fn);
/* Select F3DEX as the target microcode */
gfxd_target(gfxd_f3dex);
/* Set the input endianness to big endian, and the word size to 4 */
gfxd_endian(gfxd_endian_big, 4);
/* Print an opening brace */
gfxd_puts("{\n");
/* Execute until the end of input, or until encountering an invalid
command */
gfxd_execute();
/* Print a closing brace */
gfxd_puts("}\n");
}
```
Example input (binary):
```
0xe7000000, 0x00000000,
0xfc127e03, 0xfffffdf8,
0xb900031d, 0xc8112078,
0xb6000000, 0x000e0000,
0xb7000000, 0x00012000,
0xfa000000, 0xffffffff,
0x040030bf, 0x000002e0,
0xb1000204, 0x00020604,
0xb1080a0c, 0x000a0e0c,
0xb10a1012, 0x000a120e,
0xb1140200, 0x00140016,
0xb8000000, 0x00000000,
```
Example output:
```
{
gsDPPipeSync(),
gsDPSetCombineLERP(TEXEL0, 0, SHADE, 0, 0, 0, 0, 1, COMBINED, 0, PRIMITIVE, 0, 0, 0, 0, COMBINED),
gsDPSetRenderMode(G_RM_FOG_SHADE_A, G_RM_AA_ZB_OPA_SURF2),
gsSPClearGeometryMode(G_LIGHTING | G_TEXTURE_GEN | G_TEXTURE_GEN_LINEAR),
gsSPSetGeometryMode(G_CULL_BACK | G_FOG),
gsDPSetPrimColor(0, 0, 0xFF, 0xFF, 0xFF, 0xFF),
gsSPVertex(0x000002E0, 12, 0),
gsSP2Triangles(0, 1, 2, 0, 1, 3, 2, 0),
gsSP2Triangles(4, 5, 6, 0, 5, 7, 6, 0),
gsSP1Quadrangle(5, 8, 9, 7, 0),
gsSP1Quadrangle(10, 1, 0, 11, 0),
gsSPEndDisplayList(),
}
```
## Input/output methods
The input consists of any number of `Gfx` packets, and the output is the
decompiled macros in plain-text. The endianness and microcode type of the input
can be set using `gfxd_endian` and `gfxd_target`.
Several methods of doing I/O are available. No method is selected by default,
meaning there will be no input, and any output will be discarded.
---
##### `void gfxd_input_buffer(const void *buf, int size)`
##### `void gfxd_output_buffer(char *buf, int size)`
Use the buffer pointed to by `buf`, of `size` bytes.
---
##### `void gfxd_input_fd(int fd)`
##### `void gfxd_output_fd(int fd)`
Use `read()` / `write()` with the provided file descriptor, `fd`.
---
##### `typedef int gfxd_input_fn_t(void *buf, int count)`
##### `typedef int gfxd_output_fn_t(const char *buf, int count)`
##### `void gfxd_input_callback(gfxd_input_fn_t *fn)`
##### `void gfxd_output_callback(gfxd_output_fn_t *fn)`
Use the provided callback function, `fn`. `fn` should copy at most `count`
bytes to/from `buf`, and return the number of bytes actually copied. The input
callback should return 0 to signal end of input.
## Handlers
The macro handler function is responsible for writing the output of each
decompiled macro. The default macro handler is `gfxd_macro_dflt`, but this can
be changed with `gfxd_macro_fn`. The new handler can extend the default
function by calling `gfxd_macro_dflt` within it, or it can override it
completely.
---
##### `int gfxd_macro_dflt()`
The default macro handler. Outputs the macro name, dynamic display list pointer
if one has been specified, and then each argument in order using the function
registered using `gfxd_arg_fn` (`gfxd_arg_dflt` by default), and returns zero.
Because it is designed to be extended, it only outputs the macro text, without
any whitespace or punctuation before or after. When this function is used as
the sole macro handler, it will output the entire display list on one line
without any separation between macros, which is probably not what you want.
---
##### `void gfxd_macro_fn(gfxd_macro_fn_t *fn)`
Set `fn` to be the macro handler function. `fn` can be null, in which case the
handler is reset to the default.
---
##### `void gfxd_arg_dflt(int arg_num)`
The default argument handler for `gfxd_macro_dflt`. For the argument with index
`arg_num`, calls `gfxd_arg_callbacks`, and prints the argument value if the
callback returns zero, or if there is no callback for the given argument.
---
##### `void gfxd_arg_fn(gfxd_arg_fn_t *fn)`
Set `fn` to be the argument handler function, called by `gfxd_macro_dflt`,
for each argument in the current macro, not counting the dynamic display list
pointer if one has been specified. `fn` can be null, in which case the handler
is reset to the default. This only affects the output of `gfxd_macro_dflt`, and
has no observable effect if `gfxd_macro_dflt` is overridden (not extended).
## Argument callbacks
Callbacks can be registered that will be executed when an argument of a certain
type is encountered. The default argument handler `gfxd_arg_dflt` will execute
callbacks as needed using `gfxd_arg_callbacks`. If a callback returns non-zero,
`gfxd_arg_dflt` will not output anything. This is to allow callbacks to
override the default argument output. Otherwise, `gfxd_arg_dflt` will output
the argument value after the callback function's output.
---
##### `int gfxd_arg_callbacks(int arg_num)`
Examines the argument with index `arg_num` and executes the callback function
for that argument type, if such a callback is supported and has been
registered. This function returns the value that was returned by the callback
function. If no callback function has been registered for the argument type,
zero is returned.
Most argument callbacks have some extra parameters containing information that
might be relevant to the argument that triggered the callback. The extra
information is extracted only from the current macro, as gfxd does not retain
any context information from previous or subsequent macros. If any of the extra
parameter values is not available in the current macro, the value for that
parameter is substituted with `-1` for signed parameters, and zero for unsigned
parameters.
---
##### `typedef int gfxd_tlut_fn_t(uint32_t tlut, int32_t idx, int32_t count)`
##### `void gfxd_tlut_callback(gfxd_tlut_fn_t *fn)`
Set the callback function for palette arguments. The argument type is
`gfxd_Tlut`. The palette index is in `idx` and the number of colors in `count`.
---
##### `typedef int gfxd_timg_fn_t(uint32_t timg, int32_t fmt, int32_t siz, int32_t width, int32_t height, int32_t pal)`
##### `void gfxd_timg_callback(gfxd_timg_fn_t *fn)`
Set the callback function for texture arguments. The argument type is
`gfxd_Timg`. The image format is in `fmt` and `siz`, the dimensions in `width`
and `height`, and the palette index in `pal`.
---
##### `typedef int gfxd_cimg_fn_t(uint32_t cimg, int32_t fmt, int32_t siz, int32_t width)`
##### `void gfxd_cimg_callback(gfxd_cimg_fn_t *fn)`
Set the callback function for frame buffer arguments. The argument type is
`gfxd_Cimg`. The image format is in `fmt` and `siz`, and the horizontal
resolution in `width`.
---
##### `typedef int gfxd_zimg_fn_t(uint32_t zimg)`
##### `void gfxd_zimg_callback(gfxd_zimg_fn_t *fn)`
Set the callback function for depth buffer arguments. The argument type is
`gfxd_Zimg`.
---
##### `typedef int gfxd_dl_fn_t(uint32_t dl)`
##### `void gfxd_dl_callback(gfxd_dl_fn_t *fn)`
Set the callback function for display list arguments. The argument type is
`gfxd_Dl`.
---
##### `typedef int gfxd_mtx_fn_t(uint32_t mtx)`
##### `void gfxd_mtx_callback(gfxd_mtx_fn_t *fn)`
Set the callback function for matrix arguments. The argument type is
`gfxd_Mtxptr`.
---
##### `typedef int gfxd_lookat_fn_t(uint32_t lookat, int32_t count)`
##### `void gfxd_lookat_callback(gfxd_lookat_fn_t *fn)`
Set the callback function for lookat array arguments. The argument type is
`gfxd_Lookatptr`. The number of lookat structures (1 or 2) is in `count`.
---
##### `typedef int gfxd_light_fn_t(uint32_t light, int32_t count)`
##### `void gfxd_light_callback(gfxd_light_fn_t *fn)`
Set the callback function for light array arguments. The argument type is
`gfxd_Lightptr`. The number of light structures is in `count`.
---
##### `typedef int gfxd_seg_fn_t(uint32_t seg, int32_t num)`
##### `void gfxd_seg_callback(gfxd_seg_fn_t *fn)`
Set the callback function for segment base arguments. The argument type is
`gfxd_Segptr`. The segment number is in `num`.
---
##### `typedef int gfxd_vtx_fn_t(uint32_t vtx, int32_t num)`
##### `void gfxd_vtx_callback(gfxd_vtx_fn_t *fn)`
Set the callback function for vertex array arguments. The argument type is
`gfxd_Vtxptr`. The number of vertex structures is in `num`.
---
##### `typedef int gfxd_vp_fn_t(uint32_t vp)`
##### `void gfxd_vp_callback(gfxd_vp_fn_t *fn)`
Set the callback function for viewport arguments. The argument type is
`gfxd_Vp`.
---
##### `typedef int gfxd_uctext_fn_t(uint32_t text, uint32_t size)`
##### `void gfxd_uctext_callback(gfxd_uctext_fn_t *fn)`
Set the callback function for microcode text arguments. The argument type is
`gfxd_Uctext`. The size of the text segment is in `size`.
---
##### `typedef int gfxd_ucdata_fn_t(uint32_t data, uint32_t size)`
##### `void gfxd_ucdata_callback(gfxd_ucdata_fn_t *fn)`
Set the callback function for microcode data arguments. The argument type is
`gfxd_Ucdata`. The size of the data segment is in `size`.
---
##### `typedef int gfxd_dram_fn_t(uint32_t dram, uint32_t size)`
##### `void gfxd_dram_callback(gfxd_dram_fn_t *fn)`
Set the callback function for generic pointer arguments. The argument type is
`gfxd_Dram`. The size of the data is in `size`.
## General settings
These functions control general input and output settings.
---
##### `void gfxd_target(gfxd_ucode_t ucode)`
Select `ucode` as the target microcode. `ucode` can be `gfxd_f3d`, `gfxd_f3db`,
`gfxd_f3dex`, `gfxd_f3dexb`, or `gfxd_f3dex2`. The microcode must be selected
before `gfxd_execute`, as no microcode is selected by default.
---
##### `void gfxd_endian(int endian, int wordsize)`
Select `endian` as the endianness of the input, and `wordsize` as the size of
each word in number of bytes. `endian` can be `gfxd_endian_big`,
`gfxd_endian_little`, or `gfxd_endian_host` (the endianness of the host
machine). `wordsize` can be 1, 2, 4, or 8. Big endian is selected by default,
with a word size of 4.
---
##### `void gfxd_dynamic(const char *arg)`
Enable or disable the use of dynamic `g` macros instead of static `gs` macros,
and select the dynamic display list pointer argument to be used. `arg` will be
used by `gfxd_macro_dflt` as the first argument to dynamic macros. If `arg` is
null, dynamic macros are disabled, and `gs` macros are used. Also affects the
result of `gfxd_macro_name`, as it will return either the dynamic or static
version of the macro name as selected by this setting.
---
##### `void gfxd_enable(int cap)`
##### `void gfxd_disable(int cap)`
Enable or disable the feature specified by `cap`. Can be one of the following;
- `gfxd_stop_on_invalid`: Stop execution when encountering an invalid macro.
Enabled by default.
- `gfxd_stop_on_end`: Stop execution when encountering a `SPBranchList` or
`SPEndDisplayList`. Enabled by default.
- `gfxd_emit_dec_color`: Print color components as decimal instead of
hexadecimal. Disabled by default.
- `gfxd_emit_q_macro`: Print fixed-point conversion `q` macros for fixed-point
values. Disabled by default.
- `gfxd_emit_ext_macro`: Emit non-standard macros. Some commands are valid
(though possibly meaningless), but have no macros associated with them, such as
a standalone `G_RDPHALF_1`. When this feature is enabled, such a command will
produce a non-standard `gsDPHalf1` macro instead of a raw hexadecimal command.
Also enables some non-standard multi-packet texture loading macros. Disabled by
default.
---
##### `void gfxd_udata_set(void *ptr)`
##### `void *gfxd_udata_get(void)`
Set or get a generic pointer that can be used to pass user-defined data in and
out of callback functions.
## Execution
Decompilation is started using the `gfxd_execute` function. When gfxd is
executing (i.e. after `gfxd_execute` has been entered, and before it returns),
the general settings and the I/O settings should not be changed.
---
##### `int gfxd_execute()`
Start executing gfxd with the current settings. For each macro, the macro
handler registered with `gfxd_macro_fn` is called. Execution ends when the
input ends, the macro handler returns non-zero, when an invalid macro is
encountered and `gfxd_stop_on_invalid` is enabled, or when `SPBranchList` or
`SPEndDisplayList` is encountered and `gfxd_stop_on_end` is enabled. If
execution ends due to an invalid macro, `-1` is returned. If execution ends
because the macro handler returns non-zero, the return value from the macro
handler is returned. Otherwise zero is returned.
## Macro information
The following functions can be used to obtain information about the current
macro and its arguments. They should only be used in custom handlers and
callbacks from within `gfxd_execute`. If used elsewhere, their behavior is
undefined.
---
##### `int gfxd_macro_offset()`
Returns the offset in the input data of the current macro. The offset starts
at zero when `gfxd_execute` is called.
---
##### `int gfxd_macro_packets()`
Returns the number of `Gfx` packets within the current macro.
---
##### `const void *gfxd_macro_data()`
Returns a pointer to the input data for the current macro. The data is not
byte-swapped. The data has a length of `sizeof(Gfx) * gfxd_macro_packets()`.
---
##### `int gfxd_macro_id()`
Returns a number that uniquely identifies the current macro. The number will
be one of the constants in `gfxd.h`.
---
##### `const char *gfxd_macro_name()`
Returns the name of the current macro. If the macro does not have a name (i.e.
it's invalid), null is returned. If a dynamic display list pointer has been
specified, the dynamic `g` version is returned. Otherwise the static `gs`
version is returned. The returned pointer is invalidated by a subsequent call
to `gfxd_macro_name`.
---
##### `int gfxd_arg_count()`
Returns the number of arguments to the current macro, not including a dynamic
display list pointer if one has been specified.
---
##### `int gfxd_arg_type(int arg_num)`
Returns a number that identifies the type of the argument with index `arg_num`.
The number will be one of the constants in `gfxd.h`.
---
##### `const char *gfxd_arg_name(int arg_num)`
Returns the name of the argument with index `arg_num`. Argument names are not
canonical, nor are they needed for macro disassembly, but they can be useful
for informational and diagnostic purposes.
---
##### `int gfxd_arg_fmt(int arg_num)`
Returns the data format of the argument with index `arg_num`. The return value
will be `gfxd_argfmt_i` for `int32_t`, `gfxd_argfmt_u` for `uint32_t`, or
`gfxd_argfmt_f` for `float`. When accessing the value of the argument with
`gfxd_arg_value`, the member with the corresponding type should be used.
---
##### `const gfxd_value_t *gfxd_arg_value(int arg_num)`
Returns a pointer to the value of the argument with index `arg_num`. The value
is a union of type `gfxd_value_t` with the following layout;
```
typedef union
{
int32_t i;
uint32_t u;
float f;
} gfxd_value_t
```
---
##### `const gfxd_value_t *gfxd_value_by_type(int type, int idx)`
Returns a pointer to the value of the argument that is of `type`, and has order
`idx` in all arguments of that type. An `idx` of zero returns the first
argument that has the specified type. If there is no argument with the given
type and order, null is returned.
---
##### `int gfxd_arg_valid(int arg_num)`
Returns non-zero if the argument with index `arg_num` is "valid", for some
definition of valid. An invalid argument generally means that the disassembler
found inconsistencies in the input data, or that the data can not be reproduced
by the current macro type. The argument still has a value that can be printed,
though the value is not guaranteed to make any sense.
## Custom output
When the default handlers are overridden or extended, the custom handler
functions will want to do some output of their own. The following methods are
available for inserting custom text into the gfxd output.
---
##### `int gfxd_write(const void *buf, int count)`
Insert `count` bytes from the buffer at `buf` into the output. The number of
characters written is returned.
---
##### `int gfxd_puts(const char *str)`
Insert the null-terminated string at `str` into the output. The number of
characters written is returned.
---
##### `int gfxd_printf(const char *fmt, ...)`
Insert the printf-formatted string described by `fmt` and additional arguments
into the output. Limited to 255 characters. The number of characters written is
returned.
---
##### `int gfxd_print_value(int type, const gfxd_value_t *value)`
Insert the type-formatted value into the output. The type should be one of the
constants in `gfxd.h`. The number of characters written is returned. The
macro argument with index `n` can be printed with
`gfxd_print_value(gfxd_arg_type(n), gfxd_arg_value(n))`.

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