mirror of
https://github.com/zeldaret/oot.git
synced 2025-08-12 09:50:50 +00:00
ZAPD update: Gotta go fast! (#877)
* copy over the xml * Rename anims * A bunch of renames * minor extract_assets fixes * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "820678b4e" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "820678b4e" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * Change rgb5a1 to rgba16 * eye and eyebrows * some dlists * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "6be9af65d" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "6be9af65d" git-subrepo: version: "0.4.3" origin: "???" commit: "???"
This commit is contained in:
parent
d1a5ea5110
commit
5c147e5e03
226 changed files with 2350 additions and 1492 deletions
|
@ -109,7 +109,7 @@ public:
|
|||
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));
|
||||
static_assert(sizeof(uint32_t) == sizeof(float), "expected 32-bit float");
|
||||
std::memcpy(&value, &floatData, sizeof(value));
|
||||
return value;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public:
|
|||
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));
|
||||
static_assert(sizeof(uint32_t) == sizeof(float), "expected 32-bit float");
|
||||
std::memcpy(&value, &floatData, sizeof(value));
|
||||
return value;
|
||||
}
|
||||
|
@ -133,10 +133,10 @@ public:
|
|||
((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));
|
||||
static_assert(sizeof(uint64_t) == sizeof(double), "expected 64-bit double");
|
||||
// Checks if the float format on the platform the ZAPD binary is running on supports the
|
||||
// same float format as the object file.
|
||||
static_assert(std::numeric_limits<float>::is_iec559);
|
||||
static_assert(std::numeric_limits<float>::is_iec559, "expected IEC559 floats on host machine");
|
||||
std::memcpy(&value, &floatData, sizeof(value));
|
||||
return value;
|
||||
}
|
||||
|
@ -149,10 +149,10 @@ public:
|
|||
((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));
|
||||
static_assert(sizeof(uint64_t) == sizeof(double), "expected 64-bit double");
|
||||
// Checks if the float format on the platform the ZAPD binary is running on supports the
|
||||
// same float format as the object file.
|
||||
static_assert(std::numeric_limits<double>::is_iec559);
|
||||
static_assert(std::numeric_limits<double>::is_iec559, "expected IEC559 doubles on host machine");
|
||||
std::memcpy(&value, &floatData, sizeof(value));
|
||||
return value;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class Directory
|
|||
public:
|
||||
static std::string GetCurrentDirectory() { return fs::current_path().u8string(); }
|
||||
|
||||
static bool Exists(const std::string& path) { return fs::exists(fs::path(path)); }
|
||||
static bool Exists(const fs::path& path) { return fs::exists(path); }
|
||||
|
||||
static void CreateDirectory(const std::string& path)
|
||||
{
|
||||
|
|
|
@ -5,18 +5,19 @@
|
|||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Directory.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
static bool Exists(const std::string& filePath)
|
||||
static bool Exists(const fs::path& filePath)
|
||||
{
|
||||
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
|
||||
return file.good();
|
||||
}
|
||||
|
||||
static std::vector<uint8_t> ReadAllBytes(const std::string& filePath)
|
||||
static std::vector<uint8_t> ReadAllBytes(const fs::path& filePath)
|
||||
{
|
||||
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
|
||||
int32_t fileSize = (int32_t)file.tellg();
|
||||
|
@ -29,7 +30,7 @@ public:
|
|||
return result;
|
||||
};
|
||||
|
||||
static std::string ReadAllText(const std::string& filePath)
|
||||
static std::string ReadAllText(const fs::path& filePath)
|
||||
{
|
||||
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
|
||||
int32_t fileSize = (int32_t)file.tellg();
|
||||
|
@ -43,7 +44,7 @@ public:
|
|||
return str;
|
||||
};
|
||||
|
||||
static std::vector<std::string> ReadAllLines(const std::string& filePath)
|
||||
static std::vector<std::string> ReadAllLines(const fs::path& filePath)
|
||||
{
|
||||
std::string text = ReadAllText(filePath);
|
||||
std::vector<std::string> lines = StringHelper::Split(text, "\n");
|
||||
|
@ -51,13 +52,13 @@ public:
|
|||
return lines;
|
||||
};
|
||||
|
||||
static void WriteAllBytes(const std::string& filePath, const std::vector<uint8_t>& data)
|
||||
static void WriteAllBytes(const fs::path& filePath, const std::vector<uint8_t>& data)
|
||||
{
|
||||
std::ofstream file(filePath, std::ios::binary);
|
||||
file.write((char*)data.data(), data.size());
|
||||
};
|
||||
|
||||
static void WriteAllText(const std::string& filePath, const std::string& text)
|
||||
static void WriteAllText(const fs::path& filePath, const std::string& text)
|
||||
{
|
||||
std::ofstream file(filePath, std::ios::out);
|
||||
file.write(text.c_str(), text.size());
|
||||
|
|
|
@ -25,6 +25,7 @@ Globals::Globals()
|
|||
useExternalResources = true;
|
||||
lastScene = nullptr;
|
||||
verbosity = VerbosityLevel::VERBOSITY_SILENT;
|
||||
outputPath = Directory::GetCurrentDirectory();
|
||||
}
|
||||
|
||||
std::string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
|
||||
|
@ -50,7 +51,7 @@ std::string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
|
|||
{
|
||||
if (std::string(child->Name()) == "File")
|
||||
{
|
||||
ZFile* file = new ZFile(fileMode, child, "", "", "", filePath, true);
|
||||
ZFile* file = new ZFile(fileMode, child, "", "", filePath, true);
|
||||
file->GeneratePlaceholderDeclarations();
|
||||
segmentRefFiles[segNumber] = file;
|
||||
break;
|
||||
|
|
|
@ -53,6 +53,9 @@ public:
|
|||
ZGame game;
|
||||
GameConfig cfg;
|
||||
bool warnUnaccounted = false;
|
||||
bool warnNoOffset = false;
|
||||
bool errorNoOffset = false;
|
||||
bool verboseUnaccounted = false;
|
||||
|
||||
std::vector<ZFile*> files;
|
||||
std::vector<int32_t> segments;
|
||||
|
|
|
@ -244,7 +244,7 @@ void HLModelIntermediette::FromZSkeleton(HLModelIntermediette* model, ZSkeleton*
|
|||
model->hasSkeleton = true;
|
||||
|
||||
// Start at the root skeleton node, go down...
|
||||
ProcessZSkeletonLimb(model, zSkeleton, zSkeleton->limbs[0]);
|
||||
// ProcessZSkeletonLimb(model, zSkeleton, zSkeleton->limbs[0]);
|
||||
}
|
||||
|
||||
void HLModelIntermediette::ProcessZSkeletonLimb(HLModelIntermediette* model, ZSkeleton* zSkeleton,
|
||||
|
@ -879,7 +879,7 @@ void HLTextureIntermediette::InitFromXML(tinyxml2::XMLElement* xmlElement)
|
|||
|
||||
fileName = xmlElement->Attribute("TextureName");
|
||||
// std::string format = xmlElement->Attribute("Format");
|
||||
std::string format = "rgb5a1"; // TEST
|
||||
std::string format = "rgba16"; // TEST
|
||||
|
||||
// tex = HLTexture::FromPNG(fileName,
|
||||
// (HLTextureType)ZTexture::GetTextureTypeFromString(format));
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
|
||||
using namespace tinyxml2;
|
||||
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
|
||||
ZFileMode fileMode);
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, ZFileMode fileMode);
|
||||
|
||||
void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath);
|
||||
void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath);
|
||||
|
@ -47,6 +46,7 @@ void ErrorHandler(int sig)
|
|||
|
||||
fprintf(stderr, "\nZAPD crashed. (Signal: %i)\n", sig);
|
||||
|
||||
// Feel free to add more crash messages.
|
||||
const char* crashEasterEgg[] = {
|
||||
"\tYou've met with a terrible fate, haven't you?",
|
||||
"\tSEA BEARS FOAM. SLEEP BEARS DREAMS. \n\tBOTH END IN THE SAME WAY: CRASSSH!",
|
||||
|
@ -92,14 +92,30 @@ void ErrorHandler(int sig)
|
|||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Syntax: ZAPD.exe [mode (btex/bovl/e)] (Arbritrary Number of Arguments)
|
||||
// Syntax: ZAPD.out [mode (btex/bovl/e)] (Arbritrary Number of Arguments)
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
printf("ZAPD.exe (%s) [mode (btex/bovl/bsf/bblb/bmdlintr/bamnintr/e)] ...\n", gBuildHash);
|
||||
printf("ZAPD.out (%s) [mode (btex/bovl/bsf/bblb/bmdlintr/bamnintr/e)] ...\n", gBuildHash);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
if (!strcmp(argv[i], "--version"))
|
||||
{
|
||||
printf("ZAPD.out %s\n", gBuildHash);
|
||||
return 0;
|
||||
}
|
||||
else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
|
||||
{
|
||||
printf("Congratulations!\n");
|
||||
printf("You just found the (unimplemented and undocumented) ZAPD's help message.\n");
|
||||
printf("Feel free to implement it if you want :D\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Globals* g = new Globals();
|
||||
|
||||
// Parse File Mode
|
||||
|
@ -225,6 +241,18 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
Globals::Instance->warnUnaccounted = true;
|
||||
}
|
||||
else if (arg == "-wno" || arg == "--warn-no-offset")
|
||||
{
|
||||
Globals::Instance->warnNoOffset = true;
|
||||
}
|
||||
else if (arg == "-eno" || arg == "--error-no-offset")
|
||||
{
|
||||
Globals::Instance->errorNoOffset = true;
|
||||
}
|
||||
else if (arg == "-vu" || arg == "--verbose-unaccounted") // Verbose unaccounted
|
||||
{
|
||||
Globals::Instance->verboseUnaccounted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
|
@ -232,8 +260,8 @@ int main(int argc, char* argv[])
|
|||
|
||||
if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
|
||||
{
|
||||
bool parseSuccessful = Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath,
|
||||
Globals::Instance->outputPath, fileMode);
|
||||
bool parseSuccessful =
|
||||
Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath, fileMode);
|
||||
|
||||
if (!parseSuccessful)
|
||||
return 1;
|
||||
|
@ -270,13 +298,11 @@ int main(int argc, char* argv[])
|
|||
File::WriteAllText(Globals::Instance->outputPath.string(),
|
||||
overlay->GetSourceOutputCode(""));
|
||||
}
|
||||
|
||||
delete g;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
|
||||
ZFileMode fileMode)
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, ZFileMode fileMode)
|
||||
{
|
||||
XMLDocument doc;
|
||||
XMLError eResult = doc.LoadFile(xmlFilePath.string().c_str());
|
||||
|
@ -300,7 +326,7 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
|
|||
{
|
||||
if (std::string(child->Name()) == "File")
|
||||
{
|
||||
ZFile* file = new ZFile(fileMode, child, basePath, outPath, "", xmlFilePath, false);
|
||||
ZFile* file = new ZFile(fileMode, child, basePath, "", xmlFilePath, false);
|
||||
Globals::Instance->files.push_back(file);
|
||||
}
|
||||
else
|
||||
|
@ -315,9 +341,9 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path
|
|||
for (ZFile* file : Globals::Instance->files)
|
||||
{
|
||||
if (fileMode == ZFileMode::BuildSourceFile)
|
||||
file->BuildSourceFile(outPath);
|
||||
file->BuildSourceFile();
|
||||
else
|
||||
file->ExtractResources(outPath);
|
||||
file->ExtractResources();
|
||||
}
|
||||
|
||||
// All done, free files
|
||||
|
@ -380,7 +406,7 @@ void BuildAssetModelIntermediette(const fs::path& outPath)
|
|||
void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath)
|
||||
{
|
||||
std::vector<std::string> split = StringHelper::Split(outPath.string(), "/");
|
||||
ZFile* file = new ZFile("", split[split.size() - 2]);
|
||||
ZFile* file = new ZFile(split[split.size() - 2]);
|
||||
HLAnimationIntermediette* anim = HLAnimationIntermediette::FromXML(animPath.string());
|
||||
ZAnimation* zAnim = anim->ToZAnimation();
|
||||
zAnim->SetName(Path::GetFileNameWithoutExtension(split[split.size() - 1]));
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <numeric>
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#ifndef __PRETTY_FUNCTION__
|
||||
#ifdef _MSC_VER
|
||||
#define __PRETTY_FUNCTION__ __FUNCSIG__
|
||||
#else
|
||||
#define __PRETTY_FUNCTION__ __func__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
class StringHelper
|
||||
{
|
||||
|
@ -101,7 +109,7 @@ public:
|
|||
|
||||
static std::string BoolStr(bool b) { return b ? "true" : "false"; }
|
||||
|
||||
static bool HasOnlyDigits(const std::string &str)
|
||||
static bool HasOnlyDigits(const std::string& str)
|
||||
{
|
||||
return std::all_of(str.begin(), str.end(), ::isdigit);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
REGISTER_ZFILENODE(Animation, ZNormalAnimation);
|
||||
REGISTER_ZFILENODE(PlayerAnimation, ZLinkAnimation);
|
||||
REGISTER_ZFILENODE(CurveAnimation, ZCurveAnimation);
|
||||
REGISTER_ZFILENODE(LegacyAnimation, ZLegacyAnimation);
|
||||
|
||||
ZAnimation::ZAnimation(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
|
@ -18,10 +19,9 @@ ZAnimation::ZAnimation(ZFile* nParent) : ZResource(nParent)
|
|||
|
||||
void ZAnimation::ParseRawData()
|
||||
{
|
||||
const uint8_t* data = rawData.data();
|
||||
ZResource::ParseRawData();
|
||||
|
||||
// Read the header
|
||||
frameCount = BitConverter::ToInt16BE(data, rawDataIndex + 0);
|
||||
frameCount = BitConverter::ToInt16BE(parent->GetRawData(), rawDataIndex + 0);
|
||||
}
|
||||
|
||||
void ZAnimation::Save(const fs::path& outFolder)
|
||||
|
@ -119,7 +119,7 @@ void ZNormalAnimation::ParseRawData()
|
|||
{
|
||||
ZAnimation::ParseRawData();
|
||||
|
||||
const uint8_t* data = rawData.data();
|
||||
const uint8_t* data = parent->GetRawData().data();
|
||||
|
||||
rotationValuesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 4) & 0x00FFFFFF;
|
||||
rotationIndicesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 8) & 0x00FFFFFF;
|
||||
|
@ -185,7 +185,7 @@ void ZLinkAnimation::ParseRawData()
|
|||
{
|
||||
ZAnimation::ParseRawData();
|
||||
|
||||
const uint8_t* data = rawData.data();
|
||||
const uint8_t* data = parent->GetRawData().data();
|
||||
segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4));
|
||||
}
|
||||
|
||||
|
@ -249,6 +249,7 @@ void ZCurveAnimation::ParseRawData()
|
|||
{
|
||||
ZAnimation::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
refIndex = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0);
|
||||
transformData = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
|
||||
copyValues = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
|
||||
|
@ -292,10 +293,9 @@ void ZCurveAnimation::ParseRawData()
|
|||
}
|
||||
}
|
||||
|
||||
void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
|
||||
const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex)
|
||||
void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
|
@ -472,3 +472,182 @@ std::string ZCurveAnimation::GetSourceTypeName() const
|
|||
{
|
||||
return "TransformUpdateIndex";
|
||||
}
|
||||
|
||||
/* ZLegacyAnimation */
|
||||
|
||||
ZLegacyAnimation::ZLegacyAnimation(ZFile* nParent) : ZAnimation(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void ZLegacyAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZAnimation::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
}
|
||||
|
||||
void ZLegacyAnimation::ParseRawData()
|
||||
{
|
||||
ZAnimation::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
limbCount = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x02);
|
||||
frameData = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
|
||||
jointKey = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08);
|
||||
|
||||
if (GETSEGNUM(frameData) == parent->segment && GETSEGNUM(jointKey) == parent->segment)
|
||||
{
|
||||
uint32_t frameDataOffset = Seg2Filespace(frameData, parent->baseAddress);
|
||||
uint32_t jointKeyOffset = Seg2Filespace(jointKey, parent->baseAddress);
|
||||
|
||||
uint32_t ptr = frameDataOffset;
|
||||
for (size_t i = 0; i < (jointKeyOffset - frameDataOffset) / 2; i++)
|
||||
{
|
||||
frameDataArray.push_back(BitConverter::ToUInt16BE(rawData, ptr));
|
||||
ptr += 2;
|
||||
}
|
||||
|
||||
ptr = jointKeyOffset;
|
||||
for (int32_t i = 0; i < limbCount + 1; i++)
|
||||
{
|
||||
JointKey key(parent);
|
||||
key.ExtractFromFile(ptr);
|
||||
|
||||
jointKeyArray.push_back(key);
|
||||
ptr += key.GetRawDataSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ZLegacyAnimation::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
std::string varPrefix = prefix;
|
||||
if (name != "")
|
||||
varPrefix = name;
|
||||
|
||||
ZAnimation::DeclareReferences(varPrefix);
|
||||
|
||||
if (!frameDataArray.empty())
|
||||
{
|
||||
uint32_t frameDataOffset = Seg2Filespace(frameData, parent->baseAddress);
|
||||
if (GETSEGNUM(frameData) == parent->segment && !parent->HasDeclaration(frameDataOffset))
|
||||
{
|
||||
std::string frameDataBody = "\t";
|
||||
|
||||
for (size_t i = 0; i < frameDataArray.size(); i++)
|
||||
{
|
||||
frameDataBody += StringHelper::Sprintf("0x%04X, ", frameDataArray[i]);
|
||||
|
||||
if (i % 8 == 7 && i + 1 < frameDataArray.size())
|
||||
frameDataBody += "\n\t";
|
||||
}
|
||||
|
||||
std::string frameDataName = StringHelper::Sprintf("%sFrameData", varPrefix.c_str());
|
||||
parent->AddDeclarationArray(frameDataOffset, DeclarationAlignment::Align4,
|
||||
frameDataArray.size() * 2, "s16", frameDataName,
|
||||
frameDataArray.size(), frameDataBody);
|
||||
}
|
||||
}
|
||||
|
||||
if (!jointKeyArray.empty())
|
||||
{
|
||||
uint32_t jointKeyOffset = Seg2Filespace(jointKey, parent->baseAddress);
|
||||
if (GETSEGNUM(jointKey) == parent->segment && !parent->HasDeclaration(jointKeyOffset))
|
||||
{
|
||||
const auto res = jointKeyArray.at(0);
|
||||
std::string jointKeyBody = "";
|
||||
|
||||
for (size_t i = 0; i < jointKeyArray.size(); i++)
|
||||
{
|
||||
jointKeyBody += StringHelper::Sprintf("\t{ %s },",
|
||||
jointKeyArray[i].GetBodySourceCode().c_str());
|
||||
|
||||
if (i + 1 < jointKeyArray.size())
|
||||
jointKeyBody += "\n";
|
||||
}
|
||||
|
||||
std::string jointKeyName = StringHelper::Sprintf("%sJointKey", varPrefix.c_str());
|
||||
parent->AddDeclarationArray(jointKeyOffset, DeclarationAlignment::Align4,
|
||||
jointKeyArray.size() * res.GetRawDataSize(),
|
||||
res.GetSourceTypeName(), jointKeyName, jointKeyArray.size(),
|
||||
jointKeyBody);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ZLegacyAnimation::GetBodySourceCode() const
|
||||
{
|
||||
std::string body = "\n";
|
||||
|
||||
std::string frameDataName = parent->GetDeclarationPtrName(frameData);
|
||||
std::string jointKeyName = parent->GetDeclarationPtrName(jointKey);
|
||||
|
||||
body += StringHelper::Sprintf("\t%i, %i,\n", frameCount, limbCount);
|
||||
body += StringHelper::Sprintf("\t%s,\n", frameDataName.c_str());
|
||||
body += StringHelper::Sprintf("\t%s\n", jointKeyName.c_str());
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
std::string ZLegacyAnimation::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string body = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr || decl->isPlaceholder)
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, body);
|
||||
else
|
||||
decl->text = body;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZLegacyAnimation::GetSourceTypeName() const
|
||||
{
|
||||
return "LegacyAnimationHeader";
|
||||
}
|
||||
|
||||
size_t ZLegacyAnimation::GetRawDataSize() const
|
||||
{
|
||||
return 0x0C;
|
||||
}
|
||||
|
||||
JointKey::JointKey(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void JointKey::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
xMax = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x00);
|
||||
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x02);
|
||||
yMax = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x04);
|
||||
y = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x06);
|
||||
zMax = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x08);
|
||||
z = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x0A);
|
||||
}
|
||||
|
||||
std::string JointKey::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("%6i, %6i, %6i, %6i, %6i, %6i", xMax, x, yMax, y, zMax, z);
|
||||
}
|
||||
|
||||
std::string JointKey::GetSourceTypeName() const
|
||||
{
|
||||
return "JointKey";
|
||||
}
|
||||
|
||||
ZResourceType JointKey::GetResourceType() const
|
||||
{
|
||||
// TODO
|
||||
return ZResourceType::Error;
|
||||
}
|
||||
|
||||
size_t JointKey::GetRawDataSize() const
|
||||
{
|
||||
return 0x0C;
|
||||
}
|
||||
|
|
|
@ -126,8 +126,7 @@ public:
|
|||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex) override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
size_t GetRawDataSize() const override;
|
||||
|
@ -136,3 +135,50 @@ public:
|
|||
std::string GetSourceTypeName() const override;
|
||||
};
|
||||
// TransformUpdateIndex
|
||||
|
||||
/* ZLegacyAnimation */
|
||||
|
||||
class JointKey : public ZResource
|
||||
{
|
||||
public:
|
||||
JointKey(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
int16_t xMax, x;
|
||||
int16_t yMax, y;
|
||||
int16_t zMax, z;
|
||||
};
|
||||
|
||||
class ZLegacyAnimation : public ZAnimation
|
||||
{
|
||||
public:
|
||||
ZLegacyAnimation(ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
int16_t limbCount;
|
||||
segptr_t frameData; // s16*
|
||||
segptr_t jointKey; // JointKey*
|
||||
|
||||
std::vector<uint16_t> frameDataArray;
|
||||
std::vector<JointKey> jointKeyArray;
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader)
|
|||
{
|
||||
ZResource::ParseXML(reader);
|
||||
|
||||
arrayCnt = StringHelper::StrToL(registeredAttributes.at("Count").value, 0);
|
||||
arrayCnt = reader->IntAttribute("Count", 0);
|
||||
// TODO: do a better check.
|
||||
assert(arrayCnt > 0);
|
||||
|
||||
|
@ -46,7 +46,7 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader)
|
|||
}
|
||||
res->parent = parent;
|
||||
res->SetInnerNode(true);
|
||||
res->ExtractFromXML(child, rawData, childIndex);
|
||||
res->ExtractFromXML(child, childIndex);
|
||||
|
||||
childIndex += res->GetRawDataSize();
|
||||
resList.push_back(res);
|
||||
|
|
|
@ -15,11 +15,9 @@ ZBackground::ZBackground(ZFile* nParent) : ZResource(nParent)
|
|||
{
|
||||
}
|
||||
|
||||
ZBackground::ZBackground(const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent)
|
||||
ZBackground::ZBackground(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent)
|
||||
: ZResource(nParent)
|
||||
{
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
rawDataIndex = nRawDataIndex;
|
||||
name = GetDefaultName(prefix.c_str(), rawDataIndex);
|
||||
outName = name;
|
||||
|
@ -31,6 +29,7 @@ void ZBackground::ParseRawData()
|
|||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
size_t i = 0;
|
||||
while (true)
|
||||
{
|
||||
|
@ -61,10 +60,9 @@ void ZBackground::ParseBinaryFile(const std::string& inFolder, bool appendOutNam
|
|||
CheckValidJpeg(filepath.generic_string());
|
||||
}
|
||||
|
||||
void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex)
|
||||
void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
DeclareVar("", "");
|
||||
}
|
||||
|
||||
|
|
|
@ -11,12 +11,11 @@ protected:
|
|||
|
||||
public:
|
||||
ZBackground(ZFile* nParent);
|
||||
ZBackground(const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent);
|
||||
ZBackground(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
void ParseBinaryFile(const std::string& inFolder, bool appendOutName);
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex) override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void CheckValidJpeg(const std::string& filepath);
|
||||
|
||||
|
|
|
@ -45,7 +45,8 @@ void ZBlob::ParseXML(tinyxml2::XMLElement* reader)
|
|||
|
||||
void ZBlob::ParseRawData()
|
||||
{
|
||||
blobData.assign(rawData.data() + rawDataIndex, rawData.data() + rawDataIndex + blobSize);
|
||||
blobData.assign(parent->GetRawData().begin() + rawDataIndex,
|
||||
parent->GetRawData().begin() + rawDataIndex + blobSize);
|
||||
}
|
||||
|
||||
std::string ZBlob::GetSourceOutputCode(const std::string& prefix)
|
||||
|
|
|
@ -21,26 +21,26 @@ ZCollisionHeader::~ZCollisionHeader()
|
|||
|
||||
void ZCollisionHeader::ParseRawData()
|
||||
{
|
||||
const uint8_t* data = rawData.data();
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
absMinX = BitConverter::ToInt16BE(data, rawDataIndex + 0);
|
||||
absMinY = BitConverter::ToInt16BE(data, rawDataIndex + 2);
|
||||
absMinZ = BitConverter::ToInt16BE(data, rawDataIndex + 4);
|
||||
absMinX = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
|
||||
absMinY = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
|
||||
absMinZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
|
||||
|
||||
absMaxX = BitConverter::ToInt16BE(data, rawDataIndex + 6);
|
||||
absMaxY = BitConverter::ToInt16BE(data, rawDataIndex + 8);
|
||||
absMaxZ = BitConverter::ToInt16BE(data, rawDataIndex + 10);
|
||||
absMaxX = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
|
||||
absMaxY = BitConverter::ToInt16BE(rawData, rawDataIndex + 8);
|
||||
absMaxZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
|
||||
|
||||
numVerts = BitConverter::ToUInt16BE(data, rawDataIndex + 12);
|
||||
vtxAddress = BitConverter::ToInt32BE(data, rawDataIndex + 16);
|
||||
numVerts = BitConverter::ToUInt16BE(rawData, rawDataIndex + 12);
|
||||
vtxAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 16);
|
||||
|
||||
numPolygons = BitConverter::ToUInt16BE(data, rawDataIndex + 20);
|
||||
polyAddress = BitConverter::ToInt32BE(data, rawDataIndex + 24);
|
||||
polyTypeDefAddress = BitConverter::ToInt32BE(data, rawDataIndex + 28);
|
||||
camDataAddress = BitConverter::ToInt32BE(data, rawDataIndex + 32);
|
||||
numPolygons = BitConverter::ToUInt16BE(rawData, rawDataIndex + 20);
|
||||
polyAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 24);
|
||||
polyTypeDefAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 28);
|
||||
camDataAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 32);
|
||||
|
||||
numWaterBoxes = BitConverter::ToUInt16BE(data, rawDataIndex + 36);
|
||||
waterBoxAddress = BitConverter::ToInt32BE(data, rawDataIndex + 40);
|
||||
numWaterBoxes = BitConverter::ToUInt16BE(rawData, rawDataIndex + 36);
|
||||
waterBoxAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 40);
|
||||
|
||||
vtxSegmentOffset = Seg2Filespace(vtxAddress, parent->baseAddress);
|
||||
polySegmentOffset = Seg2Filespace(polyAddress, parent->baseAddress);
|
||||
|
@ -66,7 +66,8 @@ void ZCollisionHeader::ParseRawData()
|
|||
}
|
||||
|
||||
for (uint16_t i = 0; i < highestPolyType + 1; i++)
|
||||
polygonTypes.push_back(BitConverter::ToUInt64BE(data, polyTypeDefSegmentOffset + (i * 8)));
|
||||
polygonTypes.push_back(
|
||||
BitConverter::ToUInt64BE(rawData, polyTypeDefSegmentOffset + (i * 8)));
|
||||
|
||||
if (camDataAddress != 0)
|
||||
camData = new CameraDataList(parent, name, rawData, camDataSegmentOffset,
|
||||
|
|
|
@ -151,15 +151,18 @@ size_t ZCutscene::GetRawDataSize() const
|
|||
return size;
|
||||
}
|
||||
|
||||
void ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
void ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
DeclareVar(parent->GetName(), "");
|
||||
}
|
||||
|
||||
void ZCutscene::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
|
||||
commands = std::vector<CutsceneCommand*>();
|
||||
|
||||
|
|
|
@ -434,8 +434,7 @@ public:
|
|||
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex) override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
protected:
|
||||
int32_t numCommands;
|
||||
|
|
|
@ -58,16 +58,16 @@ size_t ZCutsceneMM::GetRawDataSize() const
|
|||
return 8 + data.size() * 4;
|
||||
}
|
||||
|
||||
void ZCutsceneMM::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
void ZCutsceneMM::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
DeclareVar(parent->GetName(), "");
|
||||
}
|
||||
|
||||
void ZCutsceneMM::ParseRawData()
|
||||
{
|
||||
segmentOffset = rawDataIndex;
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
|
||||
commands = std::vector<CutsceneCommand*>();
|
||||
|
|
|
@ -24,8 +24,7 @@ public:
|
|||
void ParseRawData() override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex) override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
protected:
|
||||
int32_t numCommands;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "ZDisplayList.h"
|
||||
|
||||
#include <File.h>
|
||||
#include <Path.h>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <math.h>
|
||||
#include "BitConverter.h"
|
||||
|
@ -41,46 +43,40 @@ ZDisplayList::~ZDisplayList()
|
|||
}
|
||||
|
||||
// EXTRACT MODE
|
||||
void ZDisplayList::ExtractFromXML(tinyxml2::XMLElement* reader,
|
||||
const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
void ZDisplayList::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
rawDataIndex = nRawDataIndex;
|
||||
ParseXML(reader);
|
||||
|
||||
fileData = nRawData;
|
||||
int32_t rawDataSize = ZDisplayList::GetDListLength(
|
||||
nRawData, rawDataIndex,
|
||||
parent->GetRawData(), rawDataIndex,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
dlistRawData.assign(nRawData.data() + rawDataIndex,
|
||||
nRawData.data() + rawDataIndex + rawDataSize);
|
||||
numInstructions = rawDataSize / 8;
|
||||
ParseRawData();
|
||||
|
||||
DeclareVar("", "");
|
||||
}
|
||||
|
||||
ZDisplayList::ZDisplayList(std::vector<uint8_t> nRawData, uint32_t nRawDataIndex,
|
||||
int32_t rawDataSize, ZFile* nParent)
|
||||
ZDisplayList::ZDisplayList(uint32_t nRawDataIndex, int32_t rawDataSize, ZFile* nParent)
|
||||
: ZDisplayList(nParent)
|
||||
{
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
fileData = nRawData;
|
||||
rawDataIndex = nRawDataIndex;
|
||||
name = StringHelper::Sprintf("DL_%06X", rawDataIndex);
|
||||
dlistRawData.assign(nRawData.data() + rawDataIndex,
|
||||
nRawData.data() + rawDataIndex + rawDataSize);
|
||||
numInstructions = rawDataSize / 8;
|
||||
ParseRawData();
|
||||
}
|
||||
|
||||
void ZDisplayList::ParseRawData()
|
||||
{
|
||||
size_t numInstructions = dlistRawData.size() / 8;
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
instructions.reserve(numInstructions);
|
||||
uint32_t ptr = rawDataIndex;
|
||||
|
||||
for (size_t i = 0; i < numInstructions; i++)
|
||||
instructions.push_back(BitConverter::ToUInt64BE(dlistRawData, (i * 8)));
|
||||
{
|
||||
instructions.push_back(BitConverter::ToUInt64BE(rawData, ptr));
|
||||
ptr += 8;
|
||||
}
|
||||
}
|
||||
|
||||
Declaration* ZDisplayList::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
|
@ -262,9 +258,9 @@ void ZDisplayList::ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, st
|
|||
sprintf(line, "gsSPBranchLessZraw(%sDlist0x%06X, 0x%02X, 0x%02X),", prefix.c_str(),
|
||||
h & 0x00FFFFFF, (a / 5) | (b / 2), z);
|
||||
|
||||
ZDisplayList* nList =
|
||||
new ZDisplayList(fileData, h & 0x00FFFFFF,
|
||||
GetDListLength(fileData, h & 0x00FFFFFF, dListType), parent);
|
||||
ZDisplayList* nList = new ZDisplayList(
|
||||
h & 0x00FFFFFF, GetDListLength(parent->GetRawData(), h & 0x00FFFFFF, dListType),
|
||||
parent);
|
||||
nList->scene = scene;
|
||||
otherDLists.push_back(nList);
|
||||
|
||||
|
@ -411,11 +407,9 @@ void ZDisplayList::ParseF3DEX(F3DEXOpcode opcode, uint64_t data, std::string pre
|
|||
}
|
||||
}
|
||||
|
||||
int32_t ZDisplayList::GetDListLength(std::vector<uint8_t> rawData, uint32_t rawDataIndex,
|
||||
int32_t ZDisplayList::GetDListLength(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
|
||||
DListType dListType)
|
||||
{
|
||||
int32_t i = 0;
|
||||
|
||||
uint8_t endDLOpcode;
|
||||
|
||||
if (dListType == DListType::F3DZEX)
|
||||
|
@ -423,13 +417,25 @@ int32_t ZDisplayList::GetDListLength(std::vector<uint8_t> rawData, uint32_t rawD
|
|||
else
|
||||
endDLOpcode = (uint8_t)F3DEXOpcode::G_ENDDL;
|
||||
|
||||
uint32_t ptr = rawDataIndex;
|
||||
size_t rawDataSize = rawData.size();
|
||||
while (true)
|
||||
{
|
||||
uint8_t opcode = rawData.at(rawDataIndex + (i * 8));
|
||||
i++;
|
||||
if (ptr > rawDataSize)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("%s: Fatal error.\n"
|
||||
"\t End of file found when trying to find the end of the "
|
||||
"DisplayList at offset: '0x%X'.\n",
|
||||
__PRETTY_FUNCTION__, rawDataIndex));
|
||||
throw std::runtime_error("");
|
||||
}
|
||||
|
||||
uint8_t opcode = rawData.at(ptr);
|
||||
ptr += 8;
|
||||
|
||||
if (opcode == endDLOpcode)
|
||||
return i * 8;
|
||||
return ptr - rawDataIndex;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -504,7 +510,7 @@ int32_t ZDisplayList::OptimizationCheck_LoadTextureBlock(int32_t startIndex, std
|
|||
fmt = (__ & 0xE0) >> 5;
|
||||
siz = (__ & 0x18) >> 3;
|
||||
texAddr = Seg2Filespace(data, parent->baseAddress);
|
||||
int32_t segmentNumber = GETSEGNUM(data);
|
||||
uint32_t segmentNumber = GETSEGNUM(data);
|
||||
|
||||
lastTexSeg = segmentNumber;
|
||||
|
||||
|
@ -698,9 +704,9 @@ void ZDisplayList::Opcode_G_DL(uint64_t data, std::string prefix, char* line)
|
|||
}
|
||||
else
|
||||
{
|
||||
ZDisplayList* nList =
|
||||
new ZDisplayList(fileData, GETSEGOFFSET(data),
|
||||
GetDListLength(fileData, GETSEGOFFSET(data), dListType), parent);
|
||||
ZDisplayList* nList = new ZDisplayList(
|
||||
GETSEGOFFSET(data), GetDListLength(parent->GetRawData(), GETSEGOFFSET(data), dListType),
|
||||
parent);
|
||||
|
||||
// if (scene != nullptr)
|
||||
{
|
||||
|
@ -863,7 +869,6 @@ void ZDisplayList::Opcode_G_VTX(uint64_t data, char* line)
|
|||
for (int32_t i = 0; i < nn; i++)
|
||||
{
|
||||
ZVtx vtx(parent);
|
||||
vtx.SetRawData(fileData);
|
||||
vtx.SetRawDataIndex(currentPtr);
|
||||
vtx.ParseRawData();
|
||||
vtxList.push_back(vtx);
|
||||
|
@ -1633,7 +1638,6 @@ static int32_t GfxdCallback_Vtx(uint32_t seg, int32_t count)
|
|||
for (int32_t i = 0; i < count; i++)
|
||||
{
|
||||
ZVtx vtx(self->parent);
|
||||
vtx.SetRawData(self->fileData);
|
||||
vtx.SetRawDataIndex(currentPtr);
|
||||
vtx.ParseRawData();
|
||||
|
||||
|
@ -1656,7 +1660,7 @@ static int32_t GfxdCallback_Texture(segptr_t seg, int32_t fmt, int32_t siz, int3
|
|||
{
|
||||
ZDisplayList* self = static_cast<ZDisplayList*>(gfxd_udata_get());
|
||||
uint32_t texOffset = Seg2Filespace(seg, self->parent->baseAddress);
|
||||
int32_t texSegNum = GETSEGNUM(seg);
|
||||
uint32_t texSegNum = GETSEGNUM(seg);
|
||||
|
||||
self->lastTexWidth = width;
|
||||
self->lastTexHeight = height;
|
||||
|
@ -1692,7 +1696,7 @@ static int32_t GfxdCallback_Palette(uint32_t seg, int32_t idx, int32_t count)
|
|||
{
|
||||
ZDisplayList* self = static_cast<ZDisplayList*>(gfxd_udata_get());
|
||||
uint32_t palOffset = Seg2Filespace(seg, self->parent->baseAddress);
|
||||
int32_t palSegNum = GETSEGNUM(seg);
|
||||
uint32_t palSegNum = GETSEGNUM(seg);
|
||||
|
||||
self->lastTexWidth = sqrt(count);
|
||||
self->lastTexHeight = sqrt(count);
|
||||
|
@ -1728,13 +1732,14 @@ static int32_t GfxdCallback_DisplayList(uint32_t seg)
|
|||
{
|
||||
ZDisplayList* self = static_cast<ZDisplayList*>(gfxd_udata_get());
|
||||
uint32_t dListOffset = GETSEGOFFSET(seg);
|
||||
int32_t dListSegNum = GETSEGNUM(seg);
|
||||
uint32_t dListSegNum = GETSEGNUM(seg);
|
||||
|
||||
if ((dListSegNum <= 6) && Globals::Instance->HasSegment(dListSegNum))
|
||||
{
|
||||
ZDisplayList* newDList = new ZDisplayList(
|
||||
self->fileData, dListOffset,
|
||||
self->GetDListLength(self->fileData, dListOffset, self->dListType), self->parent);
|
||||
dListOffset,
|
||||
self->GetDListLength(self->parent->GetRawData(), dListOffset, self->dListType),
|
||||
self->parent);
|
||||
newDList->scene = self->scene;
|
||||
newDList->parent = self->parent;
|
||||
self->otherDLists.push_back(newDList);
|
||||
|
@ -1764,8 +1769,7 @@ static int32_t GfxdCallback_Matrix(uint32_t seg)
|
|||
self->parent->GetDeclaration(Seg2Filespace(seg, self->parent->baseAddress));
|
||||
if (decl == nullptr)
|
||||
{
|
||||
ZMtx mtx(self->GetName(), self->fileData, Seg2Filespace(seg, self->parent->baseAddress),
|
||||
self->parent);
|
||||
ZMtx mtx(self->GetName(), Seg2Filespace(seg, self->parent->baseAddress), self->parent);
|
||||
|
||||
mtx.GetSourceOutputCode(self->GetName());
|
||||
self->mtxList.push_back(mtx);
|
||||
|
@ -2032,8 +2036,8 @@ std::string ZDisplayList::ProcessGfxDis(const std::string& prefix)
|
|||
|
||||
void ZDisplayList::TextureGenCheck(std::string prefix)
|
||||
{
|
||||
if (TextureGenCheck(fileData, scene, parent, prefix, lastTexWidth, lastTexHeight, lastTexAddr,
|
||||
lastTexSeg, lastTexFmt, lastTexSiz, lastTexLoaded, lastTexIsPalette, this))
|
||||
if (TextureGenCheck(scene, parent, prefix, lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg,
|
||||
lastTexFmt, lastTexSiz, lastTexLoaded, lastTexIsPalette, this))
|
||||
{
|
||||
lastTexAddr = 0;
|
||||
lastTexLoaded = false;
|
||||
|
@ -2041,11 +2045,10 @@ void ZDisplayList::TextureGenCheck(std::string prefix)
|
|||
}
|
||||
}
|
||||
|
||||
bool ZDisplayList::TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene, ZFile* parent,
|
||||
std::string prefix, int32_t texWidth, int32_t texHeight,
|
||||
uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt,
|
||||
F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette,
|
||||
ZDisplayList* self)
|
||||
bool ZDisplayList::TextureGenCheck(ZRoom* scene, ZFile* parent, std::string prefix,
|
||||
int32_t texWidth, int32_t texHeight, uint32_t texAddr,
|
||||
uint32_t texSeg, F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz,
|
||||
bool texLoaded, bool texIsPalette, ZDisplayList* self)
|
||||
{
|
||||
int32_t segmentNumber = GETSEGNUM(texSeg);
|
||||
|
||||
|
@ -2071,7 +2074,7 @@ bool ZDisplayList::TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene,
|
|||
else
|
||||
{
|
||||
tex = new ZTexture(parent);
|
||||
tex->FromBinary(fileData, texAddr, texWidth, texHeight,
|
||||
tex->FromBinary(texAddr, texWidth, texHeight,
|
||||
TexFormatToTexType(texFmt, texSiz), texIsPalette);
|
||||
parent->AddTextureResource(texAddr, tex);
|
||||
}
|
||||
|
@ -2094,7 +2097,7 @@ bool ZDisplayList::TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene,
|
|||
else
|
||||
{
|
||||
tex = new ZTexture(scene->parent);
|
||||
tex->FromBinary(scene->GetRawData(), texAddr, texWidth, texHeight,
|
||||
tex->FromBinary(texAddr, texWidth, texHeight,
|
||||
TexFormatToTexType(texFmt, texSiz), texIsPalette);
|
||||
|
||||
scene->parent->AddTextureResource(texAddr, tex);
|
||||
|
@ -2144,7 +2147,7 @@ TextureType ZDisplayList::TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSize
|
|||
else if (fmt == F3DZEXTexFormats::G_IM_FMT_IA)
|
||||
{
|
||||
if (siz == F3DZEXTexSizes::G_IM_SIZ_4b)
|
||||
return TextureType::Grayscale4bpp;
|
||||
return TextureType::GrayscaleAlpha4bpp;
|
||||
else if (siz == F3DZEXTexSizes::G_IM_SIZ_8b)
|
||||
return TextureType::GrayscaleAlpha8bpp;
|
||||
else if (siz == F3DZEXTexSizes::G_IM_SIZ_16b)
|
||||
|
|
|
@ -346,28 +346,24 @@ public:
|
|||
std::vector<uint32_t> references;
|
||||
|
||||
std::string defines; // Hack for special cases where vertex arrays intersect...
|
||||
std::vector<uint8_t> fileData;
|
||||
std::vector<ZMtx> mtxList;
|
||||
|
||||
ZDisplayList(ZFile* nParent);
|
||||
ZDisplayList(std::vector<uint8_t> nRawData, uint32_t rawDataIndex, int32_t rawDataSize,
|
||||
ZFile* nParent);
|
||||
ZDisplayList(uint32_t rawDataIndex, int32_t rawDataSize, ZFile* nParent);
|
||||
~ZDisplayList();
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex) override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void ParseRawData() override;
|
||||
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
|
||||
void TextureGenCheck(std::string prefix);
|
||||
static bool TextureGenCheck(std::vector<uint8_t> fileData, ZRoom* scene, ZFile* parent,
|
||||
std::string prefix, int32_t texWidth, int32_t texHeight,
|
||||
uint32_t texAddr, uint32_t texSeg, F3DZEXTexFormats texFmt,
|
||||
F3DZEXTexSizes texSiz, bool texLoaded, bool texIsPalette,
|
||||
ZDisplayList* self);
|
||||
static int32_t GetDListLength(std::vector<uint8_t> rawData, uint32_t rawDataIndex,
|
||||
static bool TextureGenCheck(ZRoom* scene, ZFile* parent, std::string prefix, int32_t texWidth,
|
||||
int32_t texHeight, uint32_t texAddr, uint32_t texSeg,
|
||||
F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded,
|
||||
bool texIsPalette, ZDisplayList* self);
|
||||
static int32_t GetDListLength(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
|
||||
DListType dListType);
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
@ -384,5 +380,5 @@ public:
|
|||
ZResourceType GetResourceType() const override;
|
||||
|
||||
protected:
|
||||
std::vector<uint8_t> dlistRawData;
|
||||
size_t numInstructions;
|
||||
};
|
||||
|
|
|
@ -31,7 +31,6 @@ ZFile::ZFile()
|
|||
{
|
||||
resources = std::vector<ZResource*>();
|
||||
basePath = "";
|
||||
outputPath = Directory::GetCurrentDirectory();
|
||||
declarations = std::map<uint32_t, Declaration*>();
|
||||
defines = "";
|
||||
baseAddress = 0;
|
||||
|
@ -39,15 +38,13 @@ ZFile::ZFile()
|
|||
rangeEnd = 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
ZFile::ZFile(const fs::path& nOutPath, std::string nName) : ZFile()
|
||||
ZFile::ZFile(std::string nName) : ZFile()
|
||||
{
|
||||
outputPath = nOutPath;
|
||||
name = nName;
|
||||
}
|
||||
|
||||
ZFile::ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBasePath,
|
||||
const fs::path& nOutPath, std::string filename, const fs::path& nXmlFilePath,
|
||||
bool placeholderMode)
|
||||
std::string filename, const fs::path& nXmlFilePath, bool placeholderMode)
|
||||
: ZFile()
|
||||
{
|
||||
xmlFilePath = nXmlFilePath;
|
||||
|
@ -56,11 +53,6 @@ ZFile::ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBase
|
|||
else
|
||||
basePath = nBasePath;
|
||||
|
||||
if (nOutPath == "")
|
||||
outputPath = Directory::GetCurrentDirectory();
|
||||
else
|
||||
outputPath = nOutPath;
|
||||
|
||||
ParseXML(mode, reader, filename, placeholderMode);
|
||||
DeclareResourceSubReferences();
|
||||
}
|
||||
|
@ -85,6 +77,11 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
|||
else
|
||||
name = filename;
|
||||
|
||||
outName = name;
|
||||
const char* outNameXml = reader->Attribute("OutName");
|
||||
if (outNameXml != nullptr)
|
||||
outName = outNameXml;
|
||||
|
||||
// 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");
|
||||
|
@ -125,8 +122,6 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
|||
Globals::Instance->AddSegment(segment, this);
|
||||
}
|
||||
|
||||
std::string folderName = (basePath / Path::GetFileNameWithoutExtension(name)).string();
|
||||
|
||||
if (mode == ZFileMode::Extract)
|
||||
{
|
||||
if (!File::Exists((basePath / name).string()))
|
||||
|
@ -166,6 +161,15 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
|||
}
|
||||
offsetSet.insert(offsetXml);
|
||||
}
|
||||
else if (Globals::Instance->warnNoOffset)
|
||||
{
|
||||
fprintf(stderr, "Warning No offset specified for: %s", nameXml);
|
||||
}
|
||||
else if (Globals::Instance->errorNoOffset)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Error no offset specified for %s", nameXml));
|
||||
}
|
||||
if (outNameXml != nullptr)
|
||||
{
|
||||
if (outNameSet.find(outNameXml) != outNameSet.end())
|
||||
|
@ -194,7 +198,7 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, b
|
|||
ZResource* nRes = nodeMap[nodeName](this);
|
||||
|
||||
if (mode == ZFileMode::Extract)
|
||||
nRes->ExtractFromXML(child, rawData, rawDataIndex);
|
||||
nRes->ExtractFromXML(child, rawDataIndex);
|
||||
|
||||
auto resType = nRes->GetResourceType();
|
||||
if (resType == ZResourceType::Texture)
|
||||
|
@ -228,14 +232,12 @@ void ZFile::DeclareResourceSubReferences()
|
|||
}
|
||||
}
|
||||
|
||||
void ZFile::BuildSourceFile(fs::path outputDir)
|
||||
void ZFile::BuildSourceFile()
|
||||
{
|
||||
std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string());
|
||||
if (!Directory::Exists(Globals::Instance->outputPath))
|
||||
Directory::CreateDirectory(Globals::Instance->outputPath);
|
||||
|
||||
if (!Directory::Exists(outputPath.string()))
|
||||
Directory::CreateDirectory(outputPath.string());
|
||||
|
||||
GenerateSourceFiles(outputDir);
|
||||
GenerateSourceFiles(Globals::Instance->outputPath);
|
||||
}
|
||||
|
||||
std::string ZFile::GetVarName(uint32_t address)
|
||||
|
@ -264,28 +266,26 @@ const std::vector<uint8_t>& ZFile::GetRawData() const
|
|||
return rawData;
|
||||
}
|
||||
|
||||
void ZFile::ExtractResources(fs::path outputDir)
|
||||
void ZFile::ExtractResources()
|
||||
{
|
||||
std::string folderName = Path::GetFileNameWithoutExtension(outputPath.string());
|
||||
if (!Directory::Exists(Globals::Instance->outputPath))
|
||||
Directory::CreateDirectory(Globals::Instance->outputPath);
|
||||
|
||||
if (!Directory::Exists(outputPath.string()))
|
||||
Directory::CreateDirectory(outputPath.string());
|
||||
|
||||
if (!Directory::Exists(Globals::Instance->sourceOutputPath.string()))
|
||||
Directory::CreateDirectory(Globals::Instance->sourceOutputPath.string());
|
||||
if (!Directory::Exists(GetSourceOutputFolderPath().string()))
|
||||
Directory::CreateDirectory(GetSourceOutputFolderPath().string());
|
||||
|
||||
for (ZResource* res : resources)
|
||||
res->PreGenSourceFiles();
|
||||
|
||||
if (Globals::Instance->genSourceFile)
|
||||
GenerateSourceFiles(outputDir);
|
||||
GenerateSourceFiles(Globals::Instance->outputPath);
|
||||
|
||||
for (ZResource* res : resources)
|
||||
{
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
printf("Saving resource %s\n", res->GetName().c_str());
|
||||
|
||||
res->Save(outputPath);
|
||||
res->Save(Globals::Instance->outputPath);
|
||||
}
|
||||
|
||||
if (Globals::Instance->testMode)
|
||||
|
@ -553,6 +553,7 @@ uint32_t ZFile::GetDeclarationRangedAddress(uint32_t address) const
|
|||
|
||||
bool ZFile::HasDeclaration(uint32_t address)
|
||||
{
|
||||
assert(GETSEGNUM(address) == 0);
|
||||
return declarations.find(address) != declarations.end();
|
||||
}
|
||||
|
||||
|
@ -597,7 +598,7 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
|
|||
Globals::Instance->cfg.texturePool.end())
|
||||
{
|
||||
incStr = Globals::Instance->cfg.texturePool[tex->hash].path.string() + "." +
|
||||
res->GetExternalExtension() + ".inc";
|
||||
res->GetExternalExtension() + ".inc";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -623,9 +624,10 @@ void ZFile::GenerateSourceFiles(fs::path outputDir)
|
|||
|
||||
sourceOutput += ProcessDeclarations();
|
||||
|
||||
std::string outPath =
|
||||
(Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".c"))
|
||||
.string();
|
||||
fs::path outPath = GetSourceOutputFolderPath() / outName.stem().concat(".c");
|
||||
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
printf("Writing C file: %s\n", outPath.c_str());
|
||||
|
||||
OutputFormatter formatter;
|
||||
formatter.Write(sourceOutput);
|
||||
|
@ -650,10 +652,12 @@ void ZFile::GenerateSourceHeaderFiles()
|
|||
|
||||
formatter.Write(ProcessExterns());
|
||||
|
||||
fs::path headerFilename =
|
||||
Globals::Instance->sourceOutputPath / (Path::GetFileNameWithoutExtension(name) + ".h");
|
||||
fs::path headerFilename = GetSourceOutputFolderPath() / outName.stem().concat(".h");
|
||||
|
||||
File::WriteAllText(headerFilename.string(), formatter.GetOutput());
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
printf("Writing H file: %s\n", headerFilename.c_str());
|
||||
|
||||
File::WriteAllText(headerFilename, formatter.GetOutput());
|
||||
}
|
||||
|
||||
void ZFile::GenerateHLIntermediette()
|
||||
|
@ -675,7 +679,7 @@ void ZFile::GenerateHLIntermediette()
|
|||
std::string ZFile::GetHeaderInclude()
|
||||
{
|
||||
return StringHelper::Sprintf("#include \"%s\"\n\n",
|
||||
(Path::GetFileNameWithoutExtension(name) + ".h").c_str());
|
||||
(outName.parent_path() / outName.stem().concat(".h")).c_str());
|
||||
}
|
||||
|
||||
void ZFile::GeneratePlaceholderDeclarations()
|
||||
|
@ -706,6 +710,11 @@ ZTexture* ZFile::GetTextureResource(uint32_t offset) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
fs::path ZFile::GetSourceOutputFolderPath() const
|
||||
{
|
||||
return Globals::Instance->sourceOutputPath / outName.parent_path();
|
||||
}
|
||||
|
||||
std::map<std::string, ZResourceFactoryFunc*>* ZFile::GetNodeMap()
|
||||
{
|
||||
static std::map<std::string, ZResourceFactoryFunc*> nodeMap;
|
||||
|
@ -909,8 +918,22 @@ std::string ZFile::ProcessDeclarations()
|
|||
nonZeroUnaccounted = true;
|
||||
}
|
||||
|
||||
if ((i % 16 == 15) && (i != (diff - 1)))
|
||||
src += "\n ";
|
||||
if (Globals::Instance->verboseUnaccounted)
|
||||
{
|
||||
if ((i % 4 == 3))
|
||||
{
|
||||
src += StringHelper::Sprintf(" // 0x%06X", unaccountedAddress + i - 3);
|
||||
if (i != (diff - 1))
|
||||
{
|
||||
src += "\n\t";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((i % 16 == 15) && (i != (diff - 1)))
|
||||
src += "\n ";
|
||||
}
|
||||
}
|
||||
|
||||
if (declarations.find(unaccountedAddress) == declarations.end())
|
||||
|
@ -920,8 +943,14 @@ std::string ZFile::ProcessDeclarations()
|
|||
std::string unaccountedPrefix = "unaccounted";
|
||||
|
||||
if (diff < 16 && !nonZeroUnaccounted)
|
||||
{
|
||||
unaccountedPrefix = "possiblePadding";
|
||||
|
||||
// Strip unnecessary padding at the end of the file.
|
||||
if (unaccountedAddress + diff >= rawData.size())
|
||||
break;
|
||||
}
|
||||
|
||||
Declaration* decl = AddDeclarationArray(
|
||||
unaccountedAddress, DeclarationAlignment::None, diff, "static u8",
|
||||
StringHelper::Sprintf("%s_%06X", unaccountedPrefix.c_str(),
|
||||
|
|
|
@ -33,21 +33,20 @@ public:
|
|||
std::map<uint32_t, Declaration*> declarations;
|
||||
std::string defines;
|
||||
std::vector<ZResource*> resources;
|
||||
int32_t segment;
|
||||
uint32_t segment;
|
||||
uint32_t baseAddress, rangeStart, rangeEnd;
|
||||
|
||||
ZFile(const fs::path& nOutPath, std::string nName);
|
||||
ZFile(std::string nName);
|
||||
ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBasePath,
|
||||
const fs::path& nOutPath, std::string filename, const fs::path& nXmlFilePath,
|
||||
bool placeholderMode);
|
||||
std::string filename, const fs::path& nXmlFilePath, bool placeholderMode);
|
||||
~ZFile();
|
||||
|
||||
std::string GetVarName(uint32_t address);
|
||||
std::string GetName() const;
|
||||
const fs::path& GetXmlFilePath() const;
|
||||
const std::vector<uint8_t>& GetRawData() const;
|
||||
void ExtractResources(fs::path outputDir);
|
||||
void BuildSourceFile(fs::path outputDir);
|
||||
void ExtractResources();
|
||||
void BuildSourceFile();
|
||||
void AddResource(ZResource* res);
|
||||
ZResource* FindResource(uint32_t rawDataIndex);
|
||||
std::vector<ZResource*> GetResourcesOfType(ZResourceType resType);
|
||||
|
@ -89,14 +88,16 @@ public:
|
|||
void AddTextureResource(uint32_t offset, ZTexture* tex);
|
||||
ZTexture* GetTextureResource(uint32_t offset) const;
|
||||
|
||||
fs::path GetSourceOutputFolderPath() const;
|
||||
|
||||
static std::map<std::string, ZResourceFactoryFunc*>* GetNodeMap();
|
||||
static void RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc);
|
||||
|
||||
protected:
|
||||
std::vector<uint8_t> rawData;
|
||||
std::string name;
|
||||
fs::path outName = "";
|
||||
fs::path basePath;
|
||||
fs::path outputPath;
|
||||
fs::path xmlFilePath;
|
||||
// Keep track of every texture of this ZFile.
|
||||
// The pointers declared here are "borrowed" (somebody else is the owner),
|
||||
|
|
|
@ -217,7 +217,7 @@ std::string Struct_800A598C::GetSourceTypeName()
|
|||
|
||||
Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t fileOffset)
|
||||
: parent(parent), rawData(nRawData)
|
||||
: parent(parent)
|
||||
{
|
||||
unk_0 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x00);
|
||||
unk_2 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x02);
|
||||
|
@ -282,9 +282,9 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
|
|||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
rawData, unk_8_Offset,
|
||||
parent->GetRawData(), unk_8_Offset,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength, parent);
|
||||
unk_8_dlist = new ZDisplayList(unk_8_Offset, dlistLength, parent);
|
||||
|
||||
std::string dListStr =
|
||||
StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
|
||||
|
@ -354,11 +354,9 @@ ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent)
|
|||
RegisterOptionalAttribute("Type");
|
||||
}
|
||||
|
||||
ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent)
|
||||
ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent)
|
||||
: ZLimb(nParent)
|
||||
{
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
type = limbType;
|
||||
|
@ -368,10 +366,9 @@ ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<ui
|
|||
ParseRawData();
|
||||
}
|
||||
|
||||
void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
|
@ -397,23 +394,8 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (limbType == "Standard")
|
||||
{
|
||||
type = ZLimbType::Standard;
|
||||
}
|
||||
else if (limbType == "LOD")
|
||||
{
|
||||
type = ZLimbType::LOD;
|
||||
}
|
||||
else if (limbType == "Skin")
|
||||
{
|
||||
type = ZLimbType::Skin;
|
||||
}
|
||||
else if (limbType == "Curve")
|
||||
{
|
||||
type = ZLimbType::Curve;
|
||||
}
|
||||
else
|
||||
type = GetTypeByAttributeName(limbType);
|
||||
if (type == ZLimbType::Invalid)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ZLimb::ParseXML: Warning in '%s'.\n"
|
||||
|
@ -429,6 +411,7 @@ void ZLimb::ParseRawData()
|
|||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
if (type == ZLimbType::Curve)
|
||||
{
|
||||
childIndex = rawData.at(rawDataIndex + 0);
|
||||
|
@ -438,6 +421,19 @@ void ZLimb::ParseRawData()
|
|||
dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
|
||||
return;
|
||||
}
|
||||
if (type == ZLimbType::Legacy)
|
||||
{
|
||||
dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x00);
|
||||
legTransX = BitConverter::ToFloatBE(rawData, rawDataIndex + 0x04);
|
||||
legTransY = BitConverter::ToFloatBE(rawData, rawDataIndex + 0x08);
|
||||
legTransZ = BitConverter::ToFloatBE(rawData, rawDataIndex + 0x0C);
|
||||
rotX = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x10);
|
||||
rotY = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x12);
|
||||
rotZ = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x14);
|
||||
childPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x18);
|
||||
siblingPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x1C);
|
||||
return;
|
||||
}
|
||||
|
||||
transX = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
|
||||
transY = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
|
||||
|
@ -471,6 +467,47 @@ void ZLimb::ParseRawData()
|
|||
}
|
||||
}
|
||||
|
||||
void ZLimb::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
ZResource::DeclareReferences(prefix);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ZLimbType::Legacy:
|
||||
if (childPtr != 0 && GETSEGNUM(childPtr) == parent->segment)
|
||||
{
|
||||
uint32_t childOffset = Seg2Filespace(childPtr, parent->baseAddress);
|
||||
if (!parent->HasDeclaration(childOffset))
|
||||
{
|
||||
ZLimb* child = new ZLimb(ZLimbType::Legacy, prefix, childOffset, parent);
|
||||
child->GetSourceOutputCode(prefix);
|
||||
parent->AddResource(child);
|
||||
}
|
||||
}
|
||||
if (siblingPtr != 0 && GETSEGNUM(siblingPtr) == parent->segment)
|
||||
{
|
||||
uint32_t siblingdOffset = Seg2Filespace(siblingPtr, parent->baseAddress);
|
||||
if (!parent->HasDeclaration(siblingdOffset))
|
||||
{
|
||||
ZLimb* sibling = new ZLimb(ZLimbType::Legacy, prefix, siblingdOffset, parent);
|
||||
sibling->GetSourceOutputCode(prefix);
|
||||
parent->AddResource(sibling);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// TODO
|
||||
case ZLimbType::Standard:
|
||||
case ZLimbType::LOD:
|
||||
case ZLimbType::Skin:
|
||||
case ZLimbType::Curve:
|
||||
break;
|
||||
|
||||
case ZLimbType::Invalid:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ZLimb::GetRawDataSize() const
|
||||
{
|
||||
switch (type)
|
||||
|
@ -478,9 +515,16 @@ size_t ZLimb::GetRawDataSize() const
|
|||
case ZLimbType::Standard:
|
||||
case ZLimbType::Curve:
|
||||
return 0x0C;
|
||||
|
||||
case ZLimbType::LOD:
|
||||
case ZLimbType::Skin:
|
||||
return 0x10;
|
||||
|
||||
case ZLimbType::Legacy:
|
||||
return 0x20;
|
||||
|
||||
case ZLimbType::Invalid:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0x0C;
|
||||
|
@ -493,26 +537,50 @@ std::string ZLimb::GetSourceOutputCode(const std::string& prefix)
|
|||
limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far";
|
||||
std::string dListStr2 = GetLimbDListSourceOutputCode(prefix, limbPrefix, dList2Ptr);
|
||||
|
||||
std::string entryStr = "";
|
||||
if (type != ZLimbType::Curve)
|
||||
std::string entryStr = "\n\t";
|
||||
if (type == ZLimbType::Legacy)
|
||||
{
|
||||
entryStr += StringHelper::Sprintf("\n { %i, %i, %i },", transX, transY, transZ);
|
||||
std::string childName = parent->GetDeclarationPtrName(childPtr);
|
||||
std::string siblingName = parent->GetDeclarationPtrName(siblingPtr);
|
||||
|
||||
entryStr += StringHelper::Sprintf("%s,\n", dListStr.c_str());
|
||||
entryStr +=
|
||||
StringHelper::Sprintf("\t{ %ff, %ff, %ff },\n", legTransX, legTransY, legTransZ);
|
||||
entryStr += StringHelper::Sprintf("\t{ 0x%04X, 0x%04X, 0x%04X },\n", rotX, rotY, rotZ);
|
||||
entryStr += StringHelper::Sprintf("\t%s,\n", childName.c_str());
|
||||
entryStr += StringHelper::Sprintf("\t%s\n", siblingName.c_str());
|
||||
}
|
||||
|
||||
entryStr += StringHelper::Sprintf("\n 0x%02X, 0x%02X,\n", childIndex, siblingIndex);
|
||||
|
||||
switch (type)
|
||||
else
|
||||
{
|
||||
case ZLimbType::Standard:
|
||||
entryStr += StringHelper::Sprintf(" %s\n", dListStr.c_str());
|
||||
break;
|
||||
case ZLimbType::LOD:
|
||||
case ZLimbType::Curve:
|
||||
entryStr += StringHelper::Sprintf(" { %s, %s }\n", dListStr.c_str(), dListStr2.c_str());
|
||||
break;
|
||||
case ZLimbType::Skin:
|
||||
entryStr += GetSourceOutputCodeSkin(prefix);
|
||||
break;
|
||||
if (type != ZLimbType::Curve)
|
||||
{
|
||||
entryStr += StringHelper::Sprintf("{ %i, %i, %i }, ", transX, transY, transZ);
|
||||
}
|
||||
|
||||
entryStr += StringHelper::Sprintf("0x%02X, 0x%02X,\n", childIndex, siblingIndex);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ZLimbType::Standard:
|
||||
entryStr += StringHelper::Sprintf(" %s\n", dListStr.c_str());
|
||||
break;
|
||||
|
||||
case ZLimbType::LOD:
|
||||
case ZLimbType::Curve:
|
||||
entryStr +=
|
||||
StringHelper::Sprintf(" { %s, %s }\n", dListStr.c_str(), dListStr2.c_str());
|
||||
break;
|
||||
|
||||
case ZLimbType::Skin:
|
||||
entryStr += GetSourceOutputCodeSkin(prefix);
|
||||
break;
|
||||
|
||||
case ZLimbType::Legacy:
|
||||
break;
|
||||
|
||||
case ZLimbType::Invalid:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(GetFileAddress());
|
||||
|
@ -552,17 +620,49 @@ const char* ZLimb::GetSourceTypeName(ZLimbType limbType)
|
|||
{
|
||||
case ZLimbType::Standard:
|
||||
return "StandardLimb";
|
||||
|
||||
case ZLimbType::LOD:
|
||||
return "LodLimb";
|
||||
|
||||
case ZLimbType::Skin:
|
||||
return "SkinLimb";
|
||||
|
||||
case ZLimbType::Curve:
|
||||
return "SkelCurveLimb";
|
||||
|
||||
case ZLimbType::Legacy:
|
||||
return "LegacyLimb";
|
||||
|
||||
default:
|
||||
return "StandardLimb";
|
||||
}
|
||||
}
|
||||
|
||||
ZLimbType ZLimb::GetTypeByAttributeName(const std::string& attrName)
|
||||
{
|
||||
if (attrName == "Standard")
|
||||
{
|
||||
return ZLimbType::Standard;
|
||||
}
|
||||
if (attrName == "LOD")
|
||||
{
|
||||
return ZLimbType::LOD;
|
||||
}
|
||||
if (attrName == "Skin")
|
||||
{
|
||||
return ZLimbType::Skin;
|
||||
}
|
||||
if (attrName == "Curve")
|
||||
{
|
||||
return ZLimbType::Curve;
|
||||
}
|
||||
if (attrName == "Legacy")
|
||||
{
|
||||
return ZLimbType::Legacy;
|
||||
}
|
||||
return ZLimbType::Invalid;
|
||||
}
|
||||
|
||||
uint32_t ZLimb::GetFileAddress()
|
||||
{
|
||||
return Seg2Filespace(rawDataIndex, parent->baseAddress);
|
||||
|
@ -607,9 +707,9 @@ std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix,
|
|||
StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), dListOffset);
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
rawData, dListOffset,
|
||||
parent->GetRawData(), dListOffset,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
auto dList = new ZDisplayList(rawData, dListOffset, dlistLength, parent);
|
||||
auto dList = new ZDisplayList(dListOffset, dlistLength, parent);
|
||||
dList->SetName(dListStr);
|
||||
dList->GetSourceOutputCode(prefix);
|
||||
return dListStr;
|
||||
|
|
|
@ -8,10 +8,12 @@
|
|||
|
||||
enum class ZLimbType
|
||||
{
|
||||
Invalid,
|
||||
Standard,
|
||||
LOD,
|
||||
Skin,
|
||||
Curve,
|
||||
Legacy,
|
||||
};
|
||||
|
||||
// TODO: check if more types exists
|
||||
|
@ -93,7 +95,6 @@ class Struct_800A5E28
|
|||
{
|
||||
protected:
|
||||
ZFile* parent;
|
||||
std::vector<uint8_t> rawData;
|
||||
|
||||
uint16_t unk_0; // Vtx count
|
||||
uint16_t unk_2; // Length of unk_4
|
||||
|
@ -127,6 +128,12 @@ protected:
|
|||
Struct_800A5E28 segmentStruct; // Skin only
|
||||
segptr_t dList2Ptr; // LOD and Curve Only
|
||||
|
||||
// Legacy only
|
||||
float legTransX, legTransY, legTransZ; // Vec3f
|
||||
uint16_t rotX, rotY, rotZ; // Vec3s
|
||||
segptr_t childPtr; // LegacyLimb*
|
||||
segptr_t siblingPtr; // LegacyLimb*
|
||||
|
||||
std::string GetLimbDListSourceOutputCode(const std::string& prefix,
|
||||
const std::string& limbPrefix, segptr_t dListPtr);
|
||||
|
||||
|
@ -140,14 +147,13 @@ public:
|
|||
uint8_t childIndex, siblingIndex;
|
||||
|
||||
ZLimb(ZFile* nParent);
|
||||
ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent);
|
||||
ZLimb(ZLimbType limbType, const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex) override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
|
@ -157,6 +163,7 @@ public:
|
|||
ZLimbType GetLimbType();
|
||||
void SetLimbType(ZLimbType value);
|
||||
static const char* GetSourceTypeName(ZLimbType limbType);
|
||||
static ZLimbType GetTypeByAttributeName(const std::string& attrName);
|
||||
|
||||
uint32_t GetFileAddress();
|
||||
void SetFileAddress(uint32_t nAddress);
|
||||
|
|
|
@ -9,12 +9,10 @@ ZMtx::ZMtx(ZFile* nParent) : ZResource(nParent)
|
|||
{
|
||||
}
|
||||
|
||||
ZMtx::ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZFile* nParent)
|
||||
: ZResource(nParent)
|
||||
ZMtx::ZMtx(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
name = GetDefaultName(prefix.c_str(), rawDataIndex);
|
||||
ExtractFromFile(nRawData, nRawDataIndex);
|
||||
ExtractFromFile(nRawDataIndex);
|
||||
DeclareVar("", "");
|
||||
}
|
||||
|
||||
|
@ -22,15 +20,15 @@ void ZMtx::ParseRawData()
|
|||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
for (size_t j = 0; j < 4; ++j)
|
||||
mtx[i][j] = BitConverter::ToInt32BE(rawData, rawDataIndex + (i * 4 + j) * 4);
|
||||
}
|
||||
|
||||
void ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex)
|
||||
void ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
DeclareVar("", "");
|
||||
}
|
||||
|
||||
|
|
|
@ -8,12 +8,10 @@ class ZMtx : public ZResource
|
|||
{
|
||||
public:
|
||||
ZMtx(ZFile* nParent);
|
||||
ZMtx(const std::string& prefix, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZFile* nParent);
|
||||
ZMtx(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex) override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
|
|
|
@ -13,10 +13,9 @@ ZPath::ZPath(ZFile* nParent) : ZResource(nParent)
|
|||
RegisterOptionalAttribute("NumPaths", "1");
|
||||
}
|
||||
|
||||
void ZPath::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
void ZPath::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, pathways.size() * 8,
|
||||
GetSourceTypeName(), name, pathways.size(), "");
|
||||
|
@ -135,7 +134,6 @@ void PathwayEntry::ParseRawData()
|
|||
for (int32_t i = 0; i < numPoints; i++)
|
||||
{
|
||||
ZVector vec(parent);
|
||||
vec.SetRawData(parentRawData);
|
||||
vec.SetRawDataIndex(currentPtr);
|
||||
vec.SetScalarType(ZScalarType::ZSCALAR_S16);
|
||||
vec.SetDimensions(3);
|
||||
|
|
|
@ -32,8 +32,7 @@ class ZPath : public ZResource
|
|||
public:
|
||||
ZPath(ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex);
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex);
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
|
|
|
@ -21,10 +21,8 @@ ZResource::ZResource(ZFile* nParent)
|
|||
RegisterOptionalAttribute("Custom");
|
||||
}
|
||||
|
||||
void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
rawData = nRawData;
|
||||
rawDataIndex = nRawDataIndex;
|
||||
|
||||
if (reader != nullptr)
|
||||
|
@ -34,9 +32,8 @@ void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<u
|
|||
CalcHash();
|
||||
}
|
||||
|
||||
void ZResource::ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex)
|
||||
void ZResource::ExtractFromFile(uint32_t nRawDataIndex)
|
||||
{
|
||||
rawData = nRawData;
|
||||
rawDataIndex = nRawDataIndex;
|
||||
|
||||
ParseRawData();
|
||||
|
@ -160,16 +157,6 @@ std::string ZResource::GetExternalExtension() const
|
|||
return "";
|
||||
}
|
||||
|
||||
const std::vector<uint8_t>& ZResource::GetRawData() const
|
||||
{
|
||||
return rawData;
|
||||
}
|
||||
|
||||
void ZResource::SetRawData(const std::vector<uint8_t>& nData)
|
||||
{
|
||||
rawData = nData;
|
||||
}
|
||||
|
||||
bool ZResource::WasDeclaredInXml() const
|
||||
{
|
||||
return declaredInXml;
|
||||
|
|
|
@ -36,6 +36,7 @@ enum class ZResourceType
|
|||
Cutscene,
|
||||
DisplayList,
|
||||
Limb,
|
||||
LimbTable,
|
||||
Mtx,
|
||||
Path,
|
||||
Room,
|
||||
|
@ -69,9 +70,8 @@ public:
|
|||
virtual ~ZResource() = default;
|
||||
|
||||
// Parsing from File
|
||||
virtual void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex);
|
||||
virtual void ExtractFromFile(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex);
|
||||
virtual void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex);
|
||||
virtual void ExtractFromFile(uint32_t nRawDataIndex);
|
||||
|
||||
// Misc
|
||||
virtual void ParseXML(tinyxml2::XMLElement* reader);
|
||||
|
@ -101,15 +101,12 @@ public:
|
|||
virtual uint32_t GetRawDataIndex() const;
|
||||
virtual void SetRawDataIndex(uint32_t value);
|
||||
virtual size_t GetRawDataSize() const = 0;
|
||||
virtual const std::vector<uint8_t>& GetRawData() const;
|
||||
virtual void SetRawData(const std::vector<uint8_t>& nData);
|
||||
void SetInnerNode(bool inner);
|
||||
bool WasDeclaredInXml() const;
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
std::string outName;
|
||||
std::vector<uint8_t> rawData;
|
||||
uint32_t rawDataIndex;
|
||||
std::string sourceOutput;
|
||||
bool isInner = false; // Is this resource an inner node of another resource? inside of <Array>
|
||||
|
|
|
@ -255,12 +255,12 @@ std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddre
|
|||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
primColorSegmentOffset, DeclarationAlignment::Align4, primColors.size() * 5,
|
||||
"F3DPrimColor",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialPrimColor_%06X", zRoom->GetName().c_str(),
|
||||
primColorSegmentOffset),
|
||||
primColors.size(), declaration);
|
||||
zRoom->parent->AddDeclarationArray(primColorSegmentOffset, DeclarationAlignment::Align4,
|
||||
primColors.size() * 5, "F3DPrimColor",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialPrimColor_%06X",
|
||||
zRoom->GetName().c_str(),
|
||||
primColorSegmentOffset),
|
||||
primColors.size(), declaration);
|
||||
}
|
||||
|
||||
if (envColorSegmentOffset != 0)
|
||||
|
@ -281,7 +281,7 @@ std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddre
|
|||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
envColorSegmentOffset, DeclarationAlignment::Align4, envColors.size() * 4,
|
||||
"Color_RGBA8",
|
||||
"F3DEnvColor",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialEnvColors0x%06X", zRoom->GetName().c_str(),
|
||||
envColorSegmentOffset),
|
||||
envColors.size(), declaration);
|
||||
|
@ -400,7 +400,8 @@ std::string AnimatedMatTexCycleParams::GenerateSourceCode(ZRoom* zRoom, uint32_t
|
|||
textureIndices.size(), declaration);
|
||||
}
|
||||
|
||||
std::string segmName = zRoom->parent->GetDeclarationPtrName(textureSegmentOffsetsSegmentAddress);
|
||||
std::string segmName =
|
||||
zRoom->parent->GetDeclarationPtrName(textureSegmentOffsetsSegmentAddress);
|
||||
std::string indexesName = zRoom->parent->GetDeclarationPtrName(textureIndicesSegmentAddress);
|
||||
|
||||
return StringHelper::Sprintf("%i, %s, %s", cycleLength, segmName.c_str(), indexesName.c_str());
|
||||
|
|
|
@ -13,7 +13,6 @@ void SetCollisionHeader::ParseRawData()
|
|||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
collisionHeader = new ZCollisionHeader(parent);
|
||||
collisionHeader->SetRawData(parent->GetRawData());
|
||||
collisionHeader->SetRawDataIndex(segmentOffset);
|
||||
collisionHeader->SetName(
|
||||
StringHelper::Sprintf("%sCollisionHeader_%06X", parent->GetName().c_str(), segmentOffset));
|
||||
|
|
|
@ -33,7 +33,6 @@ void SetCsCamera::ParseRawData()
|
|||
for (int32_t i = 0; i < numPoints; i++)
|
||||
{
|
||||
ZVector vec(parent);
|
||||
vec.SetRawData(parent->GetRawData());
|
||||
vec.SetRawDataIndex(currentPtr);
|
||||
vec.SetScalarType(ZScalarType::ZSCALAR_S16);
|
||||
vec.SetDimensions(3);
|
||||
|
|
|
@ -19,7 +19,7 @@ void SetCutscenes::ParseRawData()
|
|||
if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97)
|
||||
{
|
||||
ZCutscene* cutscene = new ZCutscene(parent);
|
||||
cutscene->ExtractFromFile(parent->GetRawData(), segmentOffset);
|
||||
cutscene->ExtractFromFile(segmentOffset);
|
||||
|
||||
auto decl = parent->GetDeclaration(segmentOffset);
|
||||
if (decl == nullptr)
|
||||
|
@ -48,7 +48,7 @@ void SetCutscenes::ParseRawData()
|
|||
declaration += "\n";
|
||||
|
||||
ZCutsceneMM* cutscene = new ZCutsceneMM(parent);
|
||||
cutscene->ExtractFromFile(parent->GetRawData(), entry.segmentOffset);
|
||||
cutscene->ExtractFromFile(entry.segmentOffset);
|
||||
cutscenes.push_back(cutscene);
|
||||
}
|
||||
|
||||
|
|
|
@ -116,7 +116,6 @@ RoomCommand SetMesh::GetRoomCommand() const
|
|||
PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom)
|
||||
{
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
zRoom = nRoom;
|
||||
|
@ -126,6 +125,7 @@ PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector<uint8_t>
|
|||
|
||||
void PolygonDlist::ParseRawData()
|
||||
{
|
||||
const auto& rawData = parent->GetRawData();
|
||||
switch (polyType)
|
||||
{
|
||||
case 2:
|
||||
|
@ -161,9 +161,9 @@ ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, const std::string& prefix)
|
|||
uint32_t dlistAddress = Seg2Filespace(ptr, parent->baseAddress);
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
rawData, dlistAddress,
|
||||
parent->GetRawData(), dlistAddress,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
ZDisplayList* dlist = new ZDisplayList(rawData, dlistAddress, dlistLength, parent);
|
||||
ZDisplayList* dlist = new ZDisplayList(dlistAddress, dlistLength, parent);
|
||||
GenDListDeclarations(zRoom, parent, dlist);
|
||||
|
||||
return dlist;
|
||||
|
@ -271,7 +271,6 @@ std::string PolygonDlist::GetName()
|
|||
BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent)
|
||||
{
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
isSubStruct = nIsSubStruct;
|
||||
|
@ -285,6 +284,7 @@ BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector
|
|||
void BgImage::ParseRawData()
|
||||
{
|
||||
size_t pad = 0x00;
|
||||
const auto& rawData = parent->GetRawData();
|
||||
if (!isSubStruct)
|
||||
{
|
||||
pad = 0x04;
|
||||
|
@ -312,7 +312,7 @@ ZBackground* BgImage::MakeBackground(segptr_t ptr, const std::string& prefix)
|
|||
|
||||
uint32_t backAddress = Seg2Filespace(ptr, parent->baseAddress);
|
||||
|
||||
ZBackground* background = new ZBackground(prefix, rawData, backAddress, parent);
|
||||
ZBackground* background = new ZBackground(prefix, backAddress, parent);
|
||||
background->DeclareVar(prefix, "");
|
||||
parent->resources.push_back(background);
|
||||
|
||||
|
@ -408,9 +408,9 @@ std::string BgImage::GetName()
|
|||
|
||||
PolygonTypeBase::PolygonTypeBase(ZFile* nParent, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: rawData{nRawData}, rawDataIndex{nRawDataIndex}, parent{nParent}, zRoom{nRoom}
|
||||
: rawDataIndex{nRawDataIndex}, parent{nParent}, zRoom{nRoom}
|
||||
{
|
||||
type = BitConverter::ToUInt8BE(rawData, rawDataIndex);
|
||||
type = BitConverter::ToUInt8BE(parent->GetRawData(), rawDataIndex);
|
||||
}
|
||||
|
||||
void PolygonTypeBase::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
|
@ -477,6 +477,8 @@ PolygonType1::PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData,
|
|||
|
||||
void PolygonType1::ParseRawData()
|
||||
{
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
format = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01);
|
||||
dlist = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
|
||||
|
||||
|
@ -506,7 +508,7 @@ void PolygonType1::DeclareReferences(const std::string& prefix)
|
|||
switch (format)
|
||||
{
|
||||
case 1:
|
||||
single = BgImage(true, prefix, rawData, rawDataIndex + 0x08, parent);
|
||||
single = BgImage(true, prefix, parent->GetRawData(), rawDataIndex + 0x08, parent);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
@ -515,8 +517,8 @@ void PolygonType1::DeclareReferences(const std::string& prefix)
|
|||
listAddress = Seg2Filespace(list, parent->baseAddress);
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
BgImage bg(false, prefix, rawData, listAddress + i * BgImage::GetRawDataSize(),
|
||||
parent);
|
||||
BgImage bg(false, prefix, parent->GetRawData(),
|
||||
listAddress + i * BgImage::GetRawDataSize(), parent);
|
||||
multiList.push_back(bg);
|
||||
bgImageArrayBody += bg.GetBodySourceCode(true);
|
||||
if (i + 1 < count)
|
||||
|
@ -609,6 +611,8 @@ PolygonType2::PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData,
|
|||
|
||||
void PolygonType2::ParseRawData()
|
||||
{
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
num = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x01);
|
||||
|
||||
start = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
|
||||
|
|
|
@ -39,7 +39,6 @@ protected:
|
|||
ZDisplayList* opaDList = nullptr; // Gfx*
|
||||
ZDisplayList* xluDList = nullptr; // Gfx*
|
||||
|
||||
std::vector<uint8_t> rawData;
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
ZRoom* zRoom;
|
||||
|
@ -65,7 +64,6 @@ protected:
|
|||
|
||||
ZBackground* sourceBackground;
|
||||
|
||||
std::vector<uint8_t> rawData;
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
std::string name;
|
||||
|
@ -114,7 +112,6 @@ protected:
|
|||
|
||||
std::vector<PolygonDlist> polyDLists;
|
||||
|
||||
std::vector<uint8_t> rawData;
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
ZRoom* zRoom;
|
||||
|
|
|
@ -60,10 +60,9 @@ ZRoom::~ZRoom()
|
|||
delete cmd;
|
||||
}
|
||||
|
||||
void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
scene = Globals::Instance->lastScene;
|
||||
|
||||
|
@ -97,8 +96,8 @@ void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8
|
|||
int32_t address = strtol(StringHelper::Split(addressStr, "0x")[1].c_str(), NULL, 16);
|
||||
|
||||
ZDisplayList* dList = new ZDisplayList(
|
||||
rawData, address,
|
||||
ZDisplayList::GetDListLength(rawData, address,
|
||||
address,
|
||||
ZDisplayList::GetDListLength(parent->GetRawData(), address,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ?
|
||||
DListType::F3DEX :
|
||||
DListType::F3DZEX),
|
||||
|
@ -115,7 +114,7 @@ void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8
|
|||
|
||||
ZCutscene* cutscene = new ZCutscene(parent);
|
||||
cutscene->SetInnerNode(true);
|
||||
cutscene->ExtractFromXML(child, rawData, address);
|
||||
cutscene->ExtractFromXML(child, address);
|
||||
|
||||
cutscene->GetSourceOutputCode(name);
|
||||
|
||||
|
@ -152,7 +151,7 @@ void ZRoom::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8
|
|||
delete pathway;
|
||||
}
|
||||
|
||||
#ifndef DEPRECATION_OFF
|
||||
#ifdef DEPRECATION_ON
|
||||
fprintf(stderr,
|
||||
"ZRoom::ExtractFromXML: Deprecation warning in '%s'.\n"
|
||||
"\t The resource '%s' is currently deprecated, and will be removed in a future "
|
||||
|
@ -174,6 +173,7 @@ void ZRoom::ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet co
|
|||
|
||||
uint32_t commandsLeft = commandSet.commandCount;
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
while (shouldContinue)
|
||||
{
|
||||
if (commandsLeft <= 0)
|
||||
|
@ -392,7 +392,7 @@ size_t ZRoom::GetDeclarationSizeFromNeighbor(uint32_t declarationAddress)
|
|||
auto nextDecl = currentDecl;
|
||||
std::advance(nextDecl, 1);
|
||||
if (nextDecl == parent->declarations.end())
|
||||
return rawData.size() - currentDecl->first;
|
||||
return parent->GetRawData().size() - currentDecl->first;
|
||||
|
||||
return nextDecl->first - currentDecl->first;
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ size_t ZRoom::GetCommandSizeFromNeighbor(ZRoomCommand* cmd)
|
|||
if (cmdIndex + 1 < (int32_t)commands.size())
|
||||
return commands[cmdIndex + 1]->cmdAddress - commands[cmdIndex]->cmdAddress;
|
||||
else
|
||||
return rawData.size() - commands[cmdIndex]->cmdAddress;
|
||||
return parent->GetRawData().size() - commands[cmdIndex]->cmdAddress;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -36,8 +36,7 @@ public:
|
|||
ZRoom(ZFile* nParent);
|
||||
virtual ~ZRoom();
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex) override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void ParseCommands(std::vector<ZRoomCommand*>& commandList, CommandSet commandSet);
|
||||
size_t GetDeclarationSizeFromNeighbor(uint32_t declarationAddress);
|
||||
|
|
|
@ -36,6 +36,10 @@ ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type)
|
|||
{
|
||||
return ZScalarType::ZSCALAR_U8;
|
||||
}
|
||||
else if (type == "x8")
|
||||
{
|
||||
return ZScalarType::ZSCALAR_X8;
|
||||
}
|
||||
else if (type == "s16")
|
||||
{
|
||||
return ZScalarType::ZSCALAR_S16;
|
||||
|
@ -44,6 +48,10 @@ ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type)
|
|||
{
|
||||
return ZScalarType::ZSCALAR_U16;
|
||||
}
|
||||
else if (type == "x16")
|
||||
{
|
||||
return ZScalarType::ZSCALAR_X16;
|
||||
}
|
||||
else if (type == "s32")
|
||||
{
|
||||
return ZScalarType::ZSCALAR_S32;
|
||||
|
@ -52,6 +60,10 @@ ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type)
|
|||
{
|
||||
return ZScalarType::ZSCALAR_U32;
|
||||
}
|
||||
else if (type == "x32")
|
||||
{
|
||||
return ZScalarType::ZSCALAR_X32;
|
||||
}
|
||||
else if (type == "s64")
|
||||
{
|
||||
return ZScalarType::ZSCALAR_S64;
|
||||
|
@ -60,6 +72,10 @@ ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type)
|
|||
{
|
||||
return ZScalarType::ZSCALAR_U64;
|
||||
}
|
||||
else if (type == "x64")
|
||||
{
|
||||
return ZScalarType::ZSCALAR_X64;
|
||||
}
|
||||
else if (type == "f32")
|
||||
{
|
||||
return ZScalarType::ZSCALAR_F32;
|
||||
|
@ -79,18 +95,22 @@ std::string ZScalar::MapScalarTypeToOutputType(const ZScalarType scalarType)
|
|||
case ZScalarType::ZSCALAR_S8:
|
||||
return "s8";
|
||||
case ZScalarType::ZSCALAR_U8:
|
||||
case ZScalarType::ZSCALAR_X8:
|
||||
return "u8";
|
||||
case ZScalarType::ZSCALAR_S16:
|
||||
return "s16";
|
||||
case ZScalarType::ZSCALAR_U16:
|
||||
case ZScalarType::ZSCALAR_X16:
|
||||
return "u16";
|
||||
case ZScalarType::ZSCALAR_S32:
|
||||
return "s32";
|
||||
case ZScalarType::ZSCALAR_U32:
|
||||
case ZScalarType::ZSCALAR_X32:
|
||||
return "u32";
|
||||
case ZScalarType::ZSCALAR_S64:
|
||||
return "s64";
|
||||
case ZScalarType::ZSCALAR_U64:
|
||||
case ZScalarType::ZSCALAR_X64:
|
||||
return "u64";
|
||||
case ZScalarType::ZSCALAR_F32:
|
||||
return "f32";
|
||||
|
@ -108,18 +128,22 @@ size_t ZScalar::MapTypeToSize(const ZScalarType scalarType)
|
|||
case ZScalarType::ZSCALAR_S8:
|
||||
return sizeof(scalarData.s8);
|
||||
case ZScalarType::ZSCALAR_U8:
|
||||
case ZScalarType::ZSCALAR_X8:
|
||||
return sizeof(scalarData.u8);
|
||||
case ZScalarType::ZSCALAR_S16:
|
||||
return sizeof(scalarData.s16);
|
||||
case ZScalarType::ZSCALAR_U16:
|
||||
case ZScalarType::ZSCALAR_X16:
|
||||
return sizeof(scalarData.u16);
|
||||
case ZScalarType::ZSCALAR_S32:
|
||||
return sizeof(scalarData.s32);
|
||||
case ZScalarType::ZSCALAR_U32:
|
||||
case ZScalarType::ZSCALAR_X32:
|
||||
return sizeof(scalarData.u32);
|
||||
case ZScalarType::ZSCALAR_S64:
|
||||
return sizeof(scalarData.s64);
|
||||
case ZScalarType::ZSCALAR_U64:
|
||||
case ZScalarType::ZSCALAR_X64:
|
||||
return sizeof(scalarData.u64);
|
||||
case ZScalarType::ZSCALAR_F32:
|
||||
return sizeof(scalarData.f32);
|
||||
|
@ -137,30 +161,35 @@ size_t ZScalar::GetRawDataSize() const
|
|||
|
||||
void ZScalar::ParseRawData()
|
||||
{
|
||||
const auto& rawData = parent->GetRawData();
|
||||
switch (scalarType)
|
||||
{
|
||||
case ZScalarType::ZSCALAR_S8:
|
||||
scalarData.s8 = BitConverter::ToInt8BE(rawData, rawDataIndex);
|
||||
break;
|
||||
case ZScalarType::ZSCALAR_U8:
|
||||
case ZScalarType::ZSCALAR_X8:
|
||||
scalarData.u8 = BitConverter::ToUInt8BE(rawData, rawDataIndex);
|
||||
break;
|
||||
case ZScalarType::ZSCALAR_S16:
|
||||
scalarData.s16 = BitConverter::ToInt16BE(rawData, rawDataIndex);
|
||||
break;
|
||||
case ZScalarType::ZSCALAR_U16:
|
||||
case ZScalarType::ZSCALAR_X16:
|
||||
scalarData.u16 = BitConverter::ToUInt16BE(rawData, rawDataIndex);
|
||||
break;
|
||||
case ZScalarType::ZSCALAR_S32:
|
||||
scalarData.s32 = BitConverter::ToInt32BE(rawData, rawDataIndex);
|
||||
break;
|
||||
case ZScalarType::ZSCALAR_U32:
|
||||
case ZScalarType::ZSCALAR_X32:
|
||||
scalarData.u32 = BitConverter::ToUInt32BE(rawData, rawDataIndex);
|
||||
break;
|
||||
case ZScalarType::ZSCALAR_S64:
|
||||
scalarData.s64 = BitConverter::ToInt64BE(rawData, rawDataIndex);
|
||||
break;
|
||||
case ZScalarType::ZSCALAR_U64:
|
||||
case ZScalarType::ZSCALAR_X64:
|
||||
scalarData.u64 = BitConverter::ToUInt64BE(rawData, rawDataIndex);
|
||||
break;
|
||||
case ZScalarType::ZSCALAR_F32:
|
||||
|
@ -189,18 +218,26 @@ std::string ZScalar::GetBodySourceCode() const
|
|||
return StringHelper::Sprintf("%hhd", scalarData.s8);
|
||||
case ZScalarType::ZSCALAR_U8:
|
||||
return StringHelper::Sprintf("%hhu", scalarData.u8);
|
||||
case ZScalarType::ZSCALAR_X8:
|
||||
return StringHelper::Sprintf("0x%02X", scalarData.u8);
|
||||
case ZScalarType::ZSCALAR_S16:
|
||||
return StringHelper::Sprintf("%hd", scalarData.s16);
|
||||
case ZScalarType::ZSCALAR_U16:
|
||||
return StringHelper::Sprintf("%hu", scalarData.u16);
|
||||
case ZScalarType::ZSCALAR_X16:
|
||||
return StringHelper::Sprintf("0x%04X", scalarData.u16);
|
||||
case ZScalarType::ZSCALAR_S32:
|
||||
return StringHelper::Sprintf("%d", scalarData.s32);
|
||||
case ZScalarType::ZSCALAR_U32:
|
||||
return StringHelper::Sprintf("%u", scalarData.u32);
|
||||
case ZScalarType::ZSCALAR_X32:
|
||||
return StringHelper::Sprintf("0x%08X", scalarData.u32);
|
||||
case ZScalarType::ZSCALAR_S64:
|
||||
return StringHelper::Sprintf("%lld", scalarData.s64);
|
||||
case ZScalarType::ZSCALAR_U64:
|
||||
return StringHelper::Sprintf("%llu", scalarData.u64);
|
||||
case ZScalarType::ZSCALAR_X64:
|
||||
return StringHelper::Sprintf("0x%016X", scalarData.u64);
|
||||
case ZScalarType::ZSCALAR_F32:
|
||||
return StringHelper::Sprintf("%f", scalarData.f32);
|
||||
case ZScalarType::ZSCALAR_F64:
|
||||
|
|
|
@ -11,12 +11,16 @@ enum class ZScalarType
|
|||
ZSCALAR_NONE,
|
||||
ZSCALAR_S8,
|
||||
ZSCALAR_U8,
|
||||
ZSCALAR_X8,
|
||||
ZSCALAR_S16,
|
||||
ZSCALAR_U16,
|
||||
ZSCALAR_X16,
|
||||
ZSCALAR_S32,
|
||||
ZSCALAR_U32,
|
||||
ZSCALAR_X32,
|
||||
ZSCALAR_S64,
|
||||
ZSCALAR_U64,
|
||||
ZSCALAR_X64,
|
||||
ZSCALAR_F32,
|
||||
ZSCALAR_F64
|
||||
};
|
||||
|
|
|
@ -1,53 +1,25 @@
|
|||
#include "ZSkeleton.h"
|
||||
|
||||
#include <cassert>
|
||||
#include "BitConverter.h"
|
||||
#include "HighLevel/HLModelIntermediette.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
REGISTER_ZFILENODE(Skeleton, ZSkeleton);
|
||||
REGISTER_ZFILENODE(LimbTable, ZLimbTable);
|
||||
|
||||
ZSkeleton::ZSkeleton(ZFile* nParent) : ZResource(nParent)
|
||||
ZSkeleton::ZSkeleton(ZFile* nParent) : ZResource(nParent), limbsTable(nParent)
|
||||
{
|
||||
type = ZSkeletonType::Normal;
|
||||
limbType = ZLimbType::Standard;
|
||||
dListCount = 0;
|
||||
|
||||
RegisterRequiredAttribute("Type");
|
||||
RegisterRequiredAttribute("LimbType");
|
||||
}
|
||||
|
||||
ZSkeleton::ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix,
|
||||
const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, ZFile* nParent)
|
||||
: ZSkeleton(nParent)
|
||||
void ZSkeleton::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
name = StringHelper::Sprintf("%sSkel_%06X", prefix.c_str(), rawDataIndex);
|
||||
type = nType;
|
||||
limbType = nLimbType;
|
||||
|
||||
ParseRawData();
|
||||
|
||||
std::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;
|
||||
}
|
||||
}
|
||||
|
||||
ZSkeleton::~ZSkeleton()
|
||||
{
|
||||
for (auto& limb : limbs)
|
||||
delete limb;
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
}
|
||||
|
||||
void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader)
|
||||
|
@ -71,16 +43,8 @@ void ZSkeleton::ParseXML(tinyxml2::XMLElement* reader)
|
|||
}
|
||||
|
||||
std::string limbTypeXml = registeredAttributes.at("LimbType").value;
|
||||
|
||||
if (limbTypeXml == "Standard")
|
||||
limbType = ZLimbType::Standard;
|
||||
else if (limbTypeXml == "LOD")
|
||||
limbType = ZLimbType::LOD;
|
||||
else if (limbTypeXml == "Skin")
|
||||
limbType = ZLimbType::Skin;
|
||||
else if (limbTypeXml == "Curve")
|
||||
limbType = ZLimbType::Curve;
|
||||
else
|
||||
limbType = ZLimb::GetTypeByAttributeName(limbTypeXml);
|
||||
if (limbType == ZLimbType::Invalid)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ZSkeleton::ParseXML: Warning in '%s'.\n"
|
||||
|
@ -95,42 +59,56 @@ void ZSkeleton::ParseRawData()
|
|||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
limbsArrayAddress = BitConverter::ToUInt32BE(rawData, rawDataIndex);
|
||||
limbCount = BitConverter::ToUInt8BE(rawData, rawDataIndex + 4);
|
||||
dListCount = BitConverter::ToUInt8BE(rawData, rawDataIndex + 8);
|
||||
|
||||
if (limbsArrayAddress != 0 && GETSEGNUM(limbsArrayAddress) == parent->segment)
|
||||
{
|
||||
uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress);
|
||||
limbsTable.ExtractFromBinary(ptr, limbType, limbCount);
|
||||
}
|
||||
}
|
||||
|
||||
void ZSkeleton::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
void ZSkeleton::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
|
||||
std::string defaultPrefix = name;
|
||||
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
|
||||
uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress);
|
||||
if (defaultPrefix == "")
|
||||
defaultPrefix = prefix;
|
||||
|
||||
for (size_t i = 0; i < limbCount; i++)
|
||||
if (limbsArrayAddress != 0 && GETSEGNUM(limbsArrayAddress) == parent->segment)
|
||||
{
|
||||
uint32_t ptr2 = Seg2Filespace(BitConverter::ToUInt32BE(rawData, ptr), parent->baseAddress);
|
||||
|
||||
std::string limbName = StringHelper::Sprintf("%sLimb_%06X", defaultPrefix.c_str(), ptr2);
|
||||
Declaration* decl = parent->GetDeclaration(ptr2);
|
||||
if (decl != nullptr)
|
||||
limbName = decl->varName;
|
||||
|
||||
ZLimb* limb = new ZLimb(parent);
|
||||
limb->SetLimbType(limbType);
|
||||
limb->SetName(limbName);
|
||||
limb->ExtractFromXML(nullptr, rawData, ptr2);
|
||||
limbs.push_back(limb);
|
||||
|
||||
ptr += 4;
|
||||
uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress);
|
||||
if (!parent->HasDeclaration(ptr))
|
||||
{
|
||||
limbsTable.SetName(StringHelper::Sprintf("%sLimbs", defaultPrefix.c_str()));
|
||||
limbsTable.DeclareReferences(prefix);
|
||||
limbsTable.GetSourceOutputCode(prefix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ZSkeleton::GetBodySourceCode() const
|
||||
{
|
||||
std::string limbTableName = parent->GetDeclarationPtrName(limbsArrayAddress);
|
||||
|
||||
std::string headerStr;
|
||||
switch (type)
|
||||
{
|
||||
case ZSkeletonType::Normal:
|
||||
case ZSkeletonType::Curve:
|
||||
headerStr = StringHelper::Sprintf("\n\t%s, %i\n", limbTableName.c_str(), limbCount);
|
||||
break;
|
||||
case ZSkeletonType::Flex:
|
||||
headerStr = StringHelper::Sprintf("\n\t{ %s, %i }, %i\n", limbTableName.c_str(), limbCount,
|
||||
dListCount);
|
||||
break;
|
||||
}
|
||||
|
||||
return headerStr;
|
||||
}
|
||||
|
||||
void ZSkeleton::GenerateHLIntermediette(HLFileIntermediette& hlFile)
|
||||
{
|
||||
HLModelIntermediette* mdl = (HLModelIntermediette*)&hlFile;
|
||||
|
@ -153,58 +131,7 @@ size_t ZSkeleton::GetRawDataSize() const
|
|||
|
||||
std::string ZSkeleton::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
if (parent == nullptr)
|
||||
return "";
|
||||
|
||||
std::string defaultPrefix = name.c_str();
|
||||
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
|
||||
|
||||
for (auto& limb : limbs)
|
||||
limb->GetSourceOutputCode(defaultPrefix);
|
||||
|
||||
uint32_t ptr = Seg2Filespace(limbsArrayAddress, parent->baseAddress);
|
||||
if (!parent->HasDeclaration(ptr))
|
||||
{
|
||||
// Table
|
||||
std::string tblStr = "";
|
||||
std::string limbArrTypeStr = "static void*";
|
||||
if (limbType == ZLimbType::Curve)
|
||||
{
|
||||
limbArrTypeStr =
|
||||
StringHelper::Sprintf("static %s*", ZLimb::GetSourceTypeName(limbType));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < limbs.size(); i++)
|
||||
{
|
||||
ZLimb* limb = limbs.at(i);
|
||||
|
||||
std::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, limbArrTypeStr,
|
||||
StringHelper::Sprintf("%sLimbs", defaultPrefix.c_str()),
|
||||
limbCount, tblStr);
|
||||
}
|
||||
|
||||
std::string headerStr;
|
||||
switch (type)
|
||||
{
|
||||
case ZSkeletonType::Normal:
|
||||
case ZSkeletonType::Curve:
|
||||
headerStr = StringHelper::Sprintf("\n\t%sLimbs, %i\n", defaultPrefix.c_str(), limbCount);
|
||||
break;
|
||||
case ZSkeletonType::Flex:
|
||||
headerStr = StringHelper::Sprintf("\n\t{ %sLimbs, %i }, %i\n", defaultPrefix.c_str(),
|
||||
limbCount, dListCount);
|
||||
break;
|
||||
}
|
||||
std::string headerStr = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(GetAddress());
|
||||
|
||||
|
@ -250,3 +177,146 @@ uint8_t ZSkeleton::GetLimbCount()
|
|||
{
|
||||
return limbCount;
|
||||
}
|
||||
|
||||
/* ZLimbTable */
|
||||
|
||||
ZLimbTable::ZLimbTable(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
RegisterRequiredAttribute("LimbType");
|
||||
RegisterRequiredAttribute("Count");
|
||||
}
|
||||
|
||||
void ZLimbTable::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, limbsAddresses.size(), "");
|
||||
}
|
||||
|
||||
void ZLimbTable::ExtractFromBinary(uint32_t nRawDataIndex, ZLimbType nLimbType, size_t nCount)
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
limbType = nLimbType;
|
||||
count = nCount;
|
||||
|
||||
ParseRawData();
|
||||
}
|
||||
|
||||
void ZLimbTable::ParseXML(tinyxml2::XMLElement* reader)
|
||||
{
|
||||
ZResource::ParseXML(reader);
|
||||
|
||||
std::string limbTypeXml = registeredAttributes.at("LimbType").value;
|
||||
limbType = ZLimb::GetTypeByAttributeName(limbTypeXml);
|
||||
if (limbType == ZLimbType::Invalid)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ZLimbTable::ParseXML: Warning in '%s'.\n"
|
||||
"\t Invalid LimbType found: '%s'.\n"
|
||||
"\t Defaulting to 'Standard'.\n",
|
||||
name.c_str(), limbTypeXml.c_str());
|
||||
limbType = ZLimbType::Standard;
|
||||
}
|
||||
|
||||
count = StringHelper::StrToL(registeredAttributes.at("Count").value);
|
||||
}
|
||||
|
||||
void ZLimbTable::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
uint32_t ptr = rawDataIndex;
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
limbsAddresses.push_back(BitConverter::ToUInt32BE(rawData, ptr));
|
||||
ptr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
void ZLimbTable::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
std::string varPrefix = prefix;
|
||||
if (name != "")
|
||||
varPrefix = name;
|
||||
|
||||
ZResource::DeclareReferences(varPrefix);
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
segptr_t limbAddress = limbsAddresses[i];
|
||||
|
||||
if (limbAddress != 0 && GETSEGNUM(limbAddress) == parent->segment)
|
||||
{
|
||||
uint32_t limbOffset = Seg2Filespace(limbAddress, parent->baseAddress);
|
||||
if (!parent->HasDeclaration(limbOffset))
|
||||
{
|
||||
ZLimb* limb = new ZLimb(limbType, varPrefix, limbOffset, parent);
|
||||
limb->DeclareReferences(varPrefix);
|
||||
limb->GetSourceOutputCode(varPrefix);
|
||||
parent->AddResource(limb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ZLimbTable::GetBodySourceCode() const
|
||||
{
|
||||
std::string body = "";
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
{
|
||||
std::string limbName = parent->GetDeclarationPtrName(limbsAddresses[i]);
|
||||
body += StringHelper::Sprintf("\t%s,", limbName.c_str());
|
||||
|
||||
if (i + 1 < count)
|
||||
body += "\n";
|
||||
}
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
std::string ZLimbTable::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string body = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr || decl->isPlaceholder)
|
||||
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, limbsAddresses.size(), body);
|
||||
else
|
||||
decl->text = body;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZLimbTable::GetSourceTypeName() const
|
||||
{
|
||||
switch (limbType)
|
||||
{
|
||||
case ZLimbType::Standard:
|
||||
case ZLimbType::LOD:
|
||||
case ZLimbType::Skin:
|
||||
return "void*";
|
||||
|
||||
case ZLimbType::Curve:
|
||||
case ZLimbType::Legacy:
|
||||
return StringHelper::Sprintf("%s*", ZLimb::GetSourceTypeName(limbType));
|
||||
|
||||
case ZLimbType::Invalid:
|
||||
assert("Invalid limb type.\n");
|
||||
}
|
||||
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
ZResourceType ZLimbTable::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::LimbTable;
|
||||
}
|
||||
|
||||
size_t ZLimbTable::GetRawDataSize() const
|
||||
{
|
||||
return 4 * limbsAddresses.size();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ZDisplayList.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZLimb.h"
|
||||
|
@ -14,26 +15,51 @@ enum class ZSkeletonType
|
|||
Curve,
|
||||
};
|
||||
|
||||
class ZSkeleton : public ZResource
|
||||
class ZLimbTable : public ZResource
|
||||
{
|
||||
public:
|
||||
ZSkeletonType type;
|
||||
ZLimbType limbType;
|
||||
std::vector<ZLimb*> limbs;
|
||||
segptr_t limbsArrayAddress;
|
||||
uint8_t limbCount;
|
||||
uint8_t dListCount; // FLEX SKELETON ONLY
|
||||
ZLimbTable(ZFile* nParent);
|
||||
|
||||
ZSkeleton(ZFile* nParent);
|
||||
ZSkeleton(ZSkeletonType nType, ZLimbType nLimbType, const std::string& prefix,
|
||||
const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, ZFile* nParent);
|
||||
~ZSkeleton();
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex) override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
void ExtractFromBinary(uint32_t nRawDataIndex, ZLimbType nLimbType, size_t nCount);
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
ZLimbType limbType = ZLimbType::Standard;
|
||||
size_t count = 0;
|
||||
|
||||
std::vector<segptr_t> limbsAddresses;
|
||||
};
|
||||
|
||||
class ZSkeleton : public ZResource
|
||||
{
|
||||
public:
|
||||
ZSkeletonType type = ZSkeletonType::Normal;
|
||||
ZLimbType limbType = ZLimbType::Standard;
|
||||
segptr_t limbsArrayAddress;
|
||||
uint8_t limbCount = 0;
|
||||
uint8_t dListCount = 0; // FLEX SKELETON ONLY
|
||||
|
||||
ZSkeleton(ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
void GenerateHLIntermediette(HLFileIntermediette& hlFile) override;
|
||||
|
||||
|
@ -46,4 +72,5 @@ public:
|
|||
uint8_t GetLimbCount();
|
||||
|
||||
protected:
|
||||
ZLimbTable limbsTable;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,8 @@ ZString::ZString(ZFile* nParent) : ZResource(nParent)
|
|||
void ZString::ParseRawData()
|
||||
{
|
||||
size_t size = 0;
|
||||
uint8_t* rawDataArr = rawData.data();
|
||||
const auto& rawData = parent->GetRawData();
|
||||
const auto& rawDataArr = rawData.data();
|
||||
size_t rawDataSize = rawData.size();
|
||||
for (size_t i = rawDataIndex; i < rawDataSize; ++i)
|
||||
{
|
||||
|
@ -43,7 +44,7 @@ std::string ZString::GetSourceOutputCode(const std::string& prefix)
|
|||
|
||||
std::string ZString::GetSourceOutputHeader(const std::string& prefix)
|
||||
{
|
||||
return StringHelper::Sprintf("#define %s_macro \"%s\"", name.c_str(), rawData.data());
|
||||
return StringHelper::Sprintf("#define %s_macro \"%s\"", name.c_str(), strData.data());
|
||||
}
|
||||
|
||||
std::string ZString::GetSourceTypeName() const
|
||||
|
|
|
@ -11,12 +11,6 @@ ZSymbol::ZSymbol(ZFile* nParent) : ZResource(nParent)
|
|||
RegisterOptionalAttribute("Count");
|
||||
}
|
||||
|
||||
void ZSymbol::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
}
|
||||
|
||||
void ZSymbol::ParseXML(tinyxml2::XMLElement* reader)
|
||||
{
|
||||
ZResource::ParseXML(reader);
|
||||
|
|
|
@ -14,9 +14,6 @@ protected:
|
|||
public:
|
||||
ZSymbol(ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
const uint32_t nRawDataIndex) override;
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
|
|
@ -21,10 +21,9 @@ ZTexture::ZTexture(ZFile* nParent) : ZResource(nParent)
|
|||
RegisterOptionalAttribute("TlutOffset");
|
||||
}
|
||||
|
||||
void ZTexture::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex)
|
||||
void ZTexture::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
auto filepath = Globals::Instance->outputPath / fs::path(name).stem();
|
||||
|
||||
|
@ -35,8 +34,8 @@ void ZTexture::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<ui
|
|||
name, 0);
|
||||
}
|
||||
|
||||
void ZTexture::FromBinary(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
int32_t nWidth, int32_t nHeight, TextureType nType, bool nIsPalette)
|
||||
void ZTexture::FromBinary(uint32_t nRawDataIndex, int32_t nWidth, int32_t nHeight,
|
||||
TextureType nType, bool nIsPalette)
|
||||
{
|
||||
width = nWidth;
|
||||
height = nHeight;
|
||||
|
@ -46,8 +45,6 @@ void ZTexture::FromBinary(const std::vector<uint8_t>& nRawData, uint32_t nRawDat
|
|||
name = GetDefaultName(parent->GetName());
|
||||
outName = name;
|
||||
|
||||
rawData.assign(nRawData.begin(), nRawData.end());
|
||||
|
||||
ParseRawData();
|
||||
CalcHash();
|
||||
}
|
||||
|
@ -75,17 +72,17 @@ void ZTexture::ParseXML(tinyxml2::XMLElement* reader)
|
|||
|
||||
if (!StringHelper::HasOnlyDigits(widthXml))
|
||||
{
|
||||
throw std::runtime_error(StringHelper::Sprintf(
|
||||
"ZTexture::ParseXML: Error in %s\n"
|
||||
"\t Value of 'Width' attribute has non-decimal digits: '%s'.\n",
|
||||
name.c_str(), widthXml.c_str()));
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("ZTexture::ParseXML: Error in %s\n"
|
||||
"\t Value of 'Width' attribute has non-decimal digits: '%s'.\n",
|
||||
name.c_str(), widthXml.c_str()));
|
||||
}
|
||||
if (!StringHelper::HasOnlyDigits(heightXml))
|
||||
{
|
||||
throw std::runtime_error(StringHelper::Sprintf(
|
||||
"ZTexture::ParseXML: Error in %s\n"
|
||||
"\t Value of 'Height' attribute has non-decimal digits: '%s'.\n",
|
||||
name.c_str(), heightXml.c_str()));
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("ZTexture::ParseXML: Error in %s\n"
|
||||
"\t Value of 'Height' attribute has non-decimal digits: '%s'.\n",
|
||||
name.c_str(), heightXml.c_str()));
|
||||
}
|
||||
|
||||
width = StringHelper::StrToL(widthXml);
|
||||
|
@ -348,7 +345,7 @@ void ZTexture::DeclareReferences(const std::string& prefix)
|
|||
GetExternalExtension().c_str());
|
||||
|
||||
tlut = new ZTexture(parent);
|
||||
tlut->FromBinary(rawData, tlutOffset, tlutDim, tlutDim, TextureType::RGBA16bpp, true);
|
||||
tlut->FromBinary(tlutOffset, tlutDim, tlutDim, TextureType::RGBA16bpp, true);
|
||||
parent->AddTextureResource(tlutOffset, tlut);
|
||||
parent->AddDeclarationIncludeArray(tlutOffset, incStr, tlut->GetRawDataSize(),
|
||||
tlut->GetSourceTypeName(), tlut->GetName(), 0);
|
||||
|
@ -802,7 +799,7 @@ std::string ZTexture::GetExternalExtension() const
|
|||
case TextureType::RGBA32bpp:
|
||||
return "rgba32";
|
||||
case TextureType::RGBA16bpp:
|
||||
return "rgb5a1";
|
||||
return "rgba16";
|
||||
case TextureType::Grayscale4bpp:
|
||||
return "i4";
|
||||
case TextureType::Grayscale8bpp:
|
||||
|
@ -836,8 +833,19 @@ TextureType ZTexture::GetTextureTypeFromString(std::string str)
|
|||
|
||||
if (str == "rgba32")
|
||||
texType = TextureType::RGBA32bpp;
|
||||
else if (str == "rgb5a1")
|
||||
else if (str == "rgba16")
|
||||
texType = TextureType::RGBA16bpp;
|
||||
else if (str == "rgb5a1")
|
||||
{
|
||||
texType = TextureType::RGBA16bpp;
|
||||
#ifdef DEPRECATION_ON
|
||||
fprintf(stderr,
|
||||
"ZTexture::GetTextureTypeFromString: Deprecation warning.\n"
|
||||
"\t The texture format 'rgb5a1' is currently deprecated, and will be removed in a future "
|
||||
"version.\n"
|
||||
"\t Use the format 'rgba16' instead.\n");
|
||||
#endif
|
||||
}
|
||||
else if (str == "i4")
|
||||
texType = TextureType::Grayscale4bpp;
|
||||
else if (str == "i8")
|
||||
|
|
|
@ -58,10 +58,9 @@ public:
|
|||
|
||||
bool isPalette = false;
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex) override;
|
||||
void FromBinary(const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex, int32_t nWidth,
|
||||
int32_t nHeight, TextureType nType, bool nIsPalette);
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
void FromBinary(uint32_t nRawDataIndex, int32_t nWidth, int32_t nHeight, TextureType nType,
|
||||
bool nIsPalette);
|
||||
void FromPNG(const fs::path& pngFilePath, TextureType texType);
|
||||
void FromHLTexture(HLTexture* hlTex);
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@ void ZVector::ParseRawData()
|
|||
{
|
||||
ZScalar scalar(scalarType, parent);
|
||||
scalar.rawDataIndex = currentRawDataIndex;
|
||||
scalar.rawData = rawData;
|
||||
scalar.ParseRawData();
|
||||
currentRawDataIndex += scalar.GetRawDataSize();
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@ ZVtx::ZVtx(ZFile* nParent) : ZResource(nParent)
|
|||
|
||||
void ZVtx::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
|
||||
y = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
|
||||
z = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
from datetime import datetime
|
||||
import getpass
|
||||
import subprocess
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--devel", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
with open("ZAPD/BuildInfo.h", "w+") as buildFile:
|
||||
label = subprocess.check_output(["git", "describe", "--always"]).strip().decode("utf-8")
|
||||
now = datetime.now()
|
||||
if args.devel:
|
||||
label += " ~ Development version"
|
||||
buildFile.write("const char gBuildHash[] = \"" + label + "\";\n")
|
||||
#buildFile.write("const char gBuildDate[] = \"" + now.strftime("%Y-%m-%d %H:%M:%S") + "\";\n")
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue