1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-26 14:46:16 +00:00

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

subrepo:
  subdir:   "tools/ZAPD"
  merged:   "2e1174063"
upstream:
  origin:   "https://github.com/zeldaret/ZAPD.git"
  branch:   "master"
  commit:   "2e1174063"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"
This commit is contained in:
fig02 2021-01-22 16:25:08 -05:00 committed by GitHub
parent d739765031
commit 588de66d06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 405 additions and 65 deletions

View file

@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/zeldaret/ZAPD.git
branch = master
commit = 0305ec2c27412557fe831cc8ce23b7d8649809fa
parent = db66460dbb2522a1a9822582f8b7d5205415af93
commit = 2e1174063f3ed6bcf929bc7093cd2d1b05f8518b
parent = d73976503126d10a82016f8f72fac4092dff1932
method = merge
cmdver = 0.4.3

View file

@ -50,7 +50,7 @@ string Globals::FindSymbolSegRef(int segNumber, uint32_t symbolAddress)
{
if (string(child->Name()) == "File")
{
ZFile* file = new ZFile(fileMode, child, "", "", true);
ZFile* file = new ZFile(fileMode, child, "", "", "", true);
file->GeneratePlaceholderDeclarations();
segmentRefFiles[segNumber] = file;
break;

View file

@ -180,9 +180,7 @@ int NewMain(int argc, char* argv[])
}
if (Globals::Instance->verbosity >= VERBOSITY_INFO)
{
printf("ZAPD: Zelda Asset Processor For Decomp\n");
}
if (fileMode == ZFileMode::Build || fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
{
@ -239,7 +237,7 @@ bool Parse(const std::string& xmlFilePath, const std::string& basePath, const st
{
if (string(child->Name()) == "File")
{
ZFile* file = new ZFile(fileMode, child, basePath, outPath, false);
ZFile* file = new ZFile(fileMode, child, basePath, outPath, "", false);
Globals::Instance->files.push_back(file);
}
}

View file

@ -216,6 +216,11 @@ string ZOverlay::GetSourceOutputCode(const std::string& prefix)
return output;
}
ZResourceType ZOverlay::GetResourceType()
{
return ZResourceType::Overlay;
}
SectionType ZOverlay::GetSectionTypeFromStr(string sectionName)
{
if (sectionName == ".rel.text" || sectionName == ".text")

View file

@ -55,7 +55,8 @@ public:
ZOverlay(std::string nName);
~ZOverlay();
static ZOverlay* FromBuild(std::string buildPath, std::string cfgFolderPath);
std::string GetSourceOutputCode(const std::string& prefix);
std::string GetSourceOutputCode(const std::string& prefix) override;
ZResourceType GetResourceType() override;
private:
std::vector<RelocationEntry*> entries;

View file

@ -142,6 +142,7 @@
<ClCompile Include="HighLevel\HLTexture.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="Overlays\ZOverlay.cpp" />
<ClCompile Include="ZArray.cpp" />
<ClCompile Include="ZScalar.cpp" />
<ClCompile Include="ZAnimation.cpp" />
<ClCompile Include="ZBlob.cpp" />
@ -181,6 +182,7 @@
<ClCompile Include="ZRoom\ZRoomCommand.cpp" />
<ClCompile Include="ZTexture.cpp" />
<ClCompile Include="ZVector.cpp" />
<ClCompile Include="ZVtx.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\lib\elfio\elfio\elfio.hpp" />
@ -214,6 +216,7 @@
<ClInclude Include="StringHelper.h" />
<ClInclude Include="Vec3s.h" />
<ClInclude Include="ZAnimation.h" />
<ClInclude Include="ZArray.h" />
<ClInclude Include="ZBlob.h" />
<ClInclude Include="ZCollision.h" />
<ClInclude Include="ZCutscene.h" />
@ -254,6 +257,7 @@
<ClInclude Include="ZRoom\ZRoomCommand.h" />
<ClInclude Include="ZTexture.h" />
<ClInclude Include="ZVector.h" />
<ClInclude Include="ZVtx.h" />
</ItemGroup>
<ItemGroup>
<Text Include="..\SymbolMap_OoTMqDbg.txt">

View file

@ -195,6 +195,12 @@
<ClCompile Include="ZVector.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZArray.cpp">
<Filter>Source Files\Z64</Filter>
</ClCompile>
<ClCompile Include="ZVtx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Path.h">
@ -410,6 +416,12 @@
<ClInclude Include="..\lib\stb\tinyxml2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ZArray.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
<ClInclude Include="ZVtx.h">
<Filter>Header Files\Z64</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="..\SymbolMap_OoTMqDbg.txt">

View file

@ -46,6 +46,11 @@ string ZAnimation::GetSourceOutputCode(const std::string& prefix)
return "";
}
ZResourceType ZAnimation::GetResourceType()
{
return ZResourceType::Animation;
}
ZNormalAnimation::ZNormalAnimation() : ZAnimation()
{
rotationValues = vector<uint16_t>();

View file

@ -23,7 +23,8 @@ public:
ZAnimation();
std::string GetSourceOutputCode(const std::string& prefix);
std::string GetSourceOutputCode(const std::string& prefix) override;
ZResourceType GetResourceType() override;
protected:
virtual void ParseRawData();
@ -43,7 +44,7 @@ public:
ZNormalAnimation();
std::string GetSourceOutputCode(const std::string& prefix);
virtual int GetRawDataSize();
int GetRawDataSize() override;
static ZNormalAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath);
@ -59,7 +60,7 @@ public:
ZLinkAnimation();
std::string GetSourceOutputCode(const std::string& prefix);
virtual int GetRawDataSize();
int GetRawDataSize() override;
static ZLinkAnimation* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, const std::string& nRelPath);

View file

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

25
tools/ZAPD/ZAPD/ZArray.h Normal file
View file

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

View file

@ -98,6 +98,11 @@ string ZBlob::GetExternalExtension()
return "bin";
}
std::string ZBlob::GetSourceTypeName()
{
return "u8";
}
ZResourceType ZBlob::GetResourceType()
{
return ZResourceType::Blob;

View file

@ -11,12 +11,13 @@ public:
static ZBlob* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, int rawDataIndex, std::string nRelPath);
static ZBlob* BuildFromXML(tinyxml2::XMLElement* reader, const std::string& inFolder, bool readFile);
static ZBlob* FromFile(const std::string& filePath);
std::string GetSourceOutputCode(const std::string& prefix);
std::string GetSourceOutputHeader(const std::string& prefix);
void Save(const std::string& outFolder);
bool IsExternalResource();
std::string GetExternalExtension();
ZResourceType GetResourceType();
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
void Save(const std::string& outFolder) override;
bool IsExternalResource() override;
std::string GetExternalExtension() override;
std::string GetSourceTypeName() override;
ZResourceType GetResourceType() override;
private:
ZBlob();

View file

@ -167,6 +167,11 @@ ZCollisionHeader::~ZCollisionHeader()
delete waterBox;
}
ZResourceType ZCollisionHeader::GetResourceType()
{
return ZResourceType::CollisionHeader;
}
ZCollisionHeader* ZCollisionHeader::ExtractFromXML(tinyxml2::XMLElement* reader, vector<uint8_t> nRawData, int rawDataIndex)
{
ZCollisionHeader* col = new ZCollisionHeader();

View file

@ -87,5 +87,7 @@ public:
ZCollisionHeader(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData, int rawDataIndex);
~ZCollisionHeader();
ZResourceType GetResourceType() override;
static ZCollisionHeader* ExtractFromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex);
};

View file

@ -181,6 +181,11 @@ CutsceneCommands ZCutscene::GetCommandFromID(int id)
return CutsceneCommands::Error;
}
ZResourceType ZCutscene::GetResourceType()
{
return ZResourceType::Cutscene;
}
CutsceneCommand::CutsceneCommand(const vector<uint8_t>& rawData, int rawDataIndex)
{

View file

@ -402,12 +402,14 @@ class ZCutscene : public ZResource
public:
uint32_t segmentOffset;
CutsceneCommands GetCommandFromID(int id);
ZCutscene(std::vector<uint8_t> nRawData, int rawDataIndex, int rawDataSize);
~ZCutscene();
std::string GetSourceOutputCode(const std::string& prefix);
int GetRawDataSize();
std::string GetSourceOutputCode(const std::string& prefix) override;
int GetRawDataSize() override;
CutsceneCommands GetCommandFromID(int id);
ZResourceType GetResourceType() override;
static ZCutscene* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath);
protected:

View file

@ -1367,6 +1367,11 @@ void ZDisplayList::GenerateHLIntermediette(HLFileIntermediette& hlFile)
mdl->blocks.push_back(new HLTerminator());
}
ZResourceType ZDisplayList::GetResourceType()
{
return ZResourceType::DisplayList;
}
vector<uint8_t> ZDisplayList::GetRawData()
{
return rawData;

View file

@ -214,14 +214,12 @@ public:
class ZDisplayList : public ZResource
{
protected:
// Test
uint32_t lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg;
F3DZEXTexFormats lastTexFmt;
F3DZEXTexSizes lastTexSiz, lastTexSizTest, lastCISiz;
bool lastTexLoaded;
bool lastTexIsPalette;
//void ParseXML(tinyxml2::XMLElement* reader);
static TextureType TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSizes siz);
void ParseRawData();
@ -260,9 +258,11 @@ public:
static int GetDListLength(std::vector<uint8_t> rawData, int rawDataIndex);
std::vector<uint8_t> GetRawData();
int GetRawDataSize();
std::string GetSourceOutputHeader(const std::string& prefix);
std::string GetSourceOutputCode(const std::string& prefix);
void Save(const std::string& outFolder);
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile);
int GetRawDataSize() override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
std::string GetSourceOutputCode(const std::string& prefix) override;
void Save(const std::string& outFolder) override;
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile) override;
ZResourceType GetResourceType() override;
};

View file

@ -8,7 +8,9 @@
#include "ZCollision.h"
#include "ZScalar.h"
#include "ZVector.h"
#include "ZVtx.h"
#include "ZCutscene.h"
#include "ZArray.h"
#include "Path.h"
#include "File.h"
#include "Directory.h"
@ -38,7 +40,7 @@ ZFile::ZFile(string nOutPath, string nName) : ZFile()
name = nName;
}
ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPath, bool placeholderMode) : ZFile()
ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPath, std::string filename, bool placeholderMode) : ZFile()
{
if (nBasePath == "")
basePath = Directory::GetCurrentDirectory();
@ -50,7 +52,7 @@ ZFile::ZFile(ZFileMode mode, XMLElement* reader, string nBasePath, string nOutPa
else
outputPath = nOutPath;
ParseXML(mode, reader, placeholderMode);
ParseXML(mode, reader, filename, placeholderMode);
}
ZFile::~ZFile()
@ -59,9 +61,13 @@ ZFile::~ZFile()
delete res;
}
void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, bool placeholderMode)
void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, std::string filename, bool placeholderMode)
{
name = reader->Attribute("Name");
if (filename == "")
name = reader->Attribute("Name");
else
name = filename;
int segment = -1;
if (reader->Attribute("BaseAddress") != NULL)
@ -289,6 +295,26 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, bool placeholderMode)
printf("No ZVector created!!");
}
}
else if (string(child->Name()) == "Vtx")
{
ZVtx* vtx = nullptr;
if (mode == ZFileMode::Extract)
vtx = ZVtx::ExtractFromXML(child, rawData, rawDataIndex, folderName);
if (vtx != nullptr)
{
vtx->parent = this;
resources.push_back(vtx);
rawDataIndex += vtx->GetRawDataSize();
}
else
{
if (Globals::Instance->verbosity >= VERBOSITY_DEBUG)
printf("No ZVtx created!!");
}
}
else if (string(child->Name()) == "Cutscene")
{
ZCutscene* cs = nullptr;
@ -303,10 +329,24 @@ void ZFile::ParseXML(ZFileMode mode, XMLElement* reader, bool placeholderMode)
rawDataIndex += cs->GetRawDataSize();
}
}
else if (string(child->Name()) == "Array")
{
ZArray* array = nullptr;
if (mode == ZFileMode::Extract)
array = ZArray::ExtractFromXML(child, rawData, rawDataIndex, folderName, this);
if (array != nullptr)
{
resources.push_back(array);
rawDataIndex += array->GetRawDataSize();
}
}
else
{
if (Globals::Instance->verbosity >= VERBOSITY_DEBUG)
printf("Encountered unknown resource type: %s\n", string(child->Name()).c_str());
std::cerr << "ERROR bad type\n";
printf("Encountered unknown resource type: %s on line: %d\n", child->Name(), child->GetLineNum());
std::exit(EXIT_FAILURE);
}
}
}
@ -359,6 +399,11 @@ std::string ZFile::GetVarName(int address)
return "";
}
std::string ZFile::GetName()
{
return name;
}
void ZFile::ExtractResources(string outputDir)
{
string folderName = Path::GetFileNameWithoutExtension(outputPath);

View file

@ -27,10 +27,11 @@ public:
uint32_t baseAddress, rangeStart, rangeEnd;
ZFile(std::string nOutPath, std::string nName);
ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, std::string nBasePath, std::string nOutPath, bool placeholderMode);
ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, std::string nBasePath, std::string nOutPath, std::string filename, bool placeholderMode);
~ZFile();
std::string GetVarName(int address);
std::string GetName();
void ExtractResources(std::string outputDir);
void BuildResources();
void BuildSourceFile(std::string outputDir);
@ -61,7 +62,7 @@ protected:
std::string sourceOutput;
ZFile();
void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, bool placeholderMode);
void ParseXML(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename, bool placeholderMode);
void GenerateSourceFiles(std::string outputDir);
void GenerateHLIntermediette();
void AddDeclarationDebugChecks(uint32_t address);

View file

@ -12,7 +12,6 @@ ZResource::ZResource()
rawData = vector<uint8_t>();
rawDataIndex = 0;
outputDeclaration = true;
arrayCnt = -1;
}
void ZResource::ParseXML(tinyxml2::XMLElement* reader)
@ -54,6 +53,11 @@ bool ZResource::IsExternalResource()
return false;
}
bool ZResource::DoesSupportArray()
{
return false;
}
std::string ZResource::GetExternalExtension()
{
return "";
@ -94,11 +98,20 @@ string ZResource::GetSourceOutputHeader(const std::string& prefix)
return "";
}
void ZResource::ParseRawData()
{
}
void ZResource::GenerateHLIntermediette(HLFileIntermediette& hlFile)
{
}
std::string ZResource::GetSourceTypeName()
{
return "";
}
ZResourceType ZResource::GetResourceType()
{
return ZResourceType::Error;

View file

@ -37,7 +37,9 @@ enum class ZResourceType
Limb,
Skeleton,
Scalar,
Vector
Vector,
Vertex,
CollisionHeader
};
class ZResource
@ -45,7 +47,6 @@ class ZResource
public:
ZFile* parent;
bool outputDeclaration;
int arrayCnt;
ZResource();
virtual void ParseXML(tinyxml2::XMLElement* reader);
@ -57,13 +58,16 @@ public:
std::string GetRelativePath();
virtual std::vector<uint8_t> GetRawData();
virtual bool IsExternalResource();
virtual bool DoesSupportArray(); // Can this type be wrapped in an <Array> node?
virtual std::string GetExternalExtension();
virtual int GetRawDataIndex();
virtual int GetRawDataSize();
virtual void SetRawDataIndex(int value);
virtual std::string GetSourceOutputCode(const std::string& prefix);
virtual std::string GetSourceOutputHeader(const std::string& prefix);
virtual void ParseRawData();
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile);
virtual std::string GetSourceTypeName();
virtual ZResourceType GetResourceType();
virtual void CalcHash();

View file

@ -31,13 +31,12 @@ void ZScalar::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
name = reader->Attribute("Name");
std::string type = reader->Attribute("Type");
scalarType = ZScalar::MapOutputTypeToScalarType(type);
}
ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type) {
ZScalarType ZScalar::MapOutputTypeToScalarType(const std::string& type)
{
if (type == "s8")
{
return ZSCALAR_S8;
@ -228,4 +227,9 @@ std::string ZScalar::GetSourceOutputCode(const std::string& prefix)
ZResourceType ZScalar::GetResourceType()
{
return ZResourceType::Scalar;
}
}
bool ZScalar::DoesSupportArray()
{
return true;
}

View file

@ -43,12 +43,14 @@ public:
ZScalar();
ZScalar(const ZScalarType scalarType);
void ParseXML(tinyxml2::XMLElement* reader);
std::string GetSourceTypeName();
void ParseXML(tinyxml2::XMLElement* reader) override;
std::string GetSourceTypeName() override;
std::string GetSourceValue();
std::string GetSourceOutputCode(const std::string& prefix);
int GetRawDataSize();
ZResourceType GetResourceType();
std::string GetSourceOutputCode(const std::string& prefix) override;
int GetRawDataSize() override;
ZResourceType GetResourceType() override;
bool DoesSupportArray() override;
void ParseRawData() override;
static ZScalar* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath);
static int MapTypeToSize(const ZScalarType scalarType);
@ -56,6 +58,5 @@ public:
static std::string MapScalarTypeToOutputType(const ZScalarType scalarType);
protected:
void ParseRawData();
void ParseRawData(const std::vector<uint8_t>& data, const int offset);
};

View file

@ -264,6 +264,11 @@ void ZSkeleton::Save(const std::string& outFolder)
}
ZResourceType ZSkeleton::GetResourceType()
{
return ZResourceType::Skeleton;
}
ZLimbLOD::ZLimbLOD() : ZLimbStandard()
{
farDListPtr = 0;

View file

@ -25,8 +25,8 @@ struct ZLimbStandard : public ZResource
ZLimbStandard();
static ZLimbStandard* FromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nRelPath, ZFile* parent);
static ZLimbStandard* FromRawData(std::vector<uint8_t> nRawData, int rawDataIndex);
std::string GetSourceOutputCode(const std::string& prefix);
virtual int GetRawDataSize();
std::string GetSourceOutputCode(const std::string& prefix) override;
int GetRawDataSize() override;
};
struct ZLimbLOD : ZLimbStandard
@ -36,8 +36,8 @@ struct ZLimbLOD : ZLimbStandard
ZLimbLOD();
//static ZLimbLOD* FromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nRelPath, ZFile* parent);
static ZLimbLOD* FromRawData(std::vector<uint8_t> nRawData, int rawDataIndex);
std::string GetSourceOutputCode(const std::string& prefix);
virtual int GetRawDataSize();
std::string GetSourceOutputCode(const std::string& prefix) override;
int GetRawDataSize() override;
};
enum ZSkeletonType
@ -58,7 +58,8 @@ public:
ZSkeleton();
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile);
static ZSkeleton* FromXML(tinyxml2::XMLElement* reader, std::vector<uint8_t> nRawData, int rawDataIndex, std::string nRelPath, ZFile* nParent);
void Save(const std::string& outFolder);
void Save(const std::string& outFolder) override;
ZResourceType GetResourceType() override;
std::string GetSourceOutputCode(const std::string& prefix);
std::string GetSourceOutputCode(const std::string& prefix) override;
};

View file

@ -29,7 +29,7 @@ protected:
uint8_t* bmpRgb;
uint8_t* bmpRgba;
virtual void ParseXML(tinyxml2::XMLElement* reader);
void ParseXML(tinyxml2::XMLElement* reader) override;
void FixRawData();
void PrepareBitmap();
void PrepareBitmapRGBA16();
@ -52,9 +52,9 @@ protected:
void PrepareRawDataPalette4(std::string palPath);
void PrepareRawDataPalette8(std::string palPath);
float GetPixelMultiplyer();
bool IsExternalResource();
ZResourceType GetResourceType();
void CalcHash();
bool IsExternalResource() override;
ZResourceType GetResourceType() override;
void CalcHash() override;
public:
ZTexture();
@ -72,8 +72,8 @@ public:
std::string GetSourceOutputCode(const std::string& prefix) override;
std::string GetSourceOutputHeader(const std::string& prefix) override;
std::vector<uint8_t> GetRawData();
int GetRawDataSize();
std::vector<uint8_t> GetRawData() override;
int GetRawDataSize() override;
std::string GetIMFmtFromType();
std::string GetIMSizFromType();
int GetWidth();
@ -81,6 +81,6 @@ public:
void SetWidth(int nWidth);
void SetHeight(int nHeight);
TextureType GetTextureType();
void Save(const std::string& outFolder);
std::string GetExternalExtension();
void Save(const std::string& outFolder) override;
std::string GetExternalExtension() override;
};

View file

@ -42,7 +42,9 @@ void ZVector::ParseRawData()
int currentRawDataIndex = this->rawDataIndex;
scalars.clear();
for (int i = 0; i < this->dimensions; i++) {
for (int i = 0; i < this->dimensions; i++)
{
ZScalar* scalar = new ZScalar(this->scalarType);
scalar->rawDataIndex = currentRawDataIndex;
scalar->rawData = this->rawData;
@ -64,6 +66,11 @@ int ZVector::GetRawDataSize()
return size;
}
bool ZVector::DoesSupportArray()
{
return true;
}
std::string ZVector::GetSourceTypeName()
{
if (dimensions == 3 && scalarType == ZSCALAR_F32)
@ -94,7 +101,7 @@ std::string ZVector::GetSourceValue()
std::vector<std::string> strings = std::vector<std::string>();
for (int i = 0; i < this->scalars.size(); i++)
strings.push_back(scalars[i]->GetSourceValue());
return StringHelper::Implode(strings, ", ");
return "{ " + StringHelper::Implode(strings, ", ") + " }";
}
std::string ZVector::GetSourceOutputCode(const std::string& prefix)

View file

@ -17,14 +17,15 @@ public:
ZVector();
void ParseXML(tinyxml2::XMLElement* reader);
std::string GetSourceTypeName();
std::string GetSourceTypeName() override;
std::string GetSourceValue();
std::string GetSourceOutputCode(const std::string& prefix);
void ParseRawData() override;
int GetRawDataSize();
bool DoesSupportArray() override;
ZResourceType GetResourceType();
static ZVector* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath);
protected:
void ParseRawData();
};

78
tools/ZAPD/ZAPD/ZVtx.cpp Normal file
View file

@ -0,0 +1,78 @@
#include "ZVtx.h"
#include "ZFile.h"
#include "StringHelper.h"
#include "BitConverter.h"
ZVtx::ZVtx()
{
x = 0;
y = 0;
z = 0;
flag = 0;
s = 0;
t = 0;
r = 0;
g = 0;
b = 0;
a = 0;
}
void ZVtx::ParseXML(tinyxml2::XMLElement* reader)
{
}
std::string ZVtx::GetSourceTypeName()
{
return "Vtx";
}
std::string ZVtx::GetSourceOutputCode(const std::string& prefix)
{
std::string output = StringHelper::Sprintf("VTX(%i, %i, %i, %i, %i, %i, %i, %i, %i)", x, y, z, s, t, r, g, b, a);
if (parent != nullptr)
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(), GetSourceTypeName(), name, output);
return "";
}
void ZVtx::ParseRawData()
{
const uint8_t* data = rawData.data();
x = BitConverter::ToInt16BE(data, rawDataIndex + 0);
y = BitConverter::ToInt16BE(data, rawDataIndex + 2);
z = BitConverter::ToInt16BE(data, rawDataIndex + 4);
flag = BitConverter::ToInt16BE(data, rawDataIndex + 6);
s = BitConverter::ToInt16BE(data, rawDataIndex + 8);
t = BitConverter::ToInt16BE(data, rawDataIndex + 10);
r = data[rawDataIndex + 12];
g = data[rawDataIndex + 13];
b = data[rawDataIndex + 14];
a = data[rawDataIndex + 15];
}
int ZVtx::GetRawDataSize()
{
return 16;
}
bool ZVtx::DoesSupportArray()
{
return true;
}
ZResourceType ZVtx::GetResourceType()
{
return ZResourceType::Vertex;
}
ZVtx* ZVtx::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath)
{
ZVtx* vtx = new ZVtx();
vtx->rawData = nRawData;
vtx->rawDataIndex = rawDataIndex;
vtx->ParseRawData();
return vtx;
}

31
tools/ZAPD/ZAPD/ZVtx.h Normal file
View file

@ -0,0 +1,31 @@
#pragma once
#include <vector>
#include <string>
#include <stdint.h>
#include "ZResource.h"
#include "ZScalar.h"
#include "tinyxml2.h"
class ZVtx : public ZResource
{
public:
int16_t x, y, z;
uint16_t flag;
int16_t s, t;
uint8_t r, g, b, a;
ZVtx();
void ParseXML(tinyxml2::XMLElement* reader);
std::string GetSourceTypeName() override;
std::string GetSourceOutputCode(const std::string& prefix);
void ParseRawData() override;
int GetRawDataSize();
bool DoesSupportArray() override;
ZResourceType GetResourceType();
static ZVtx* ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData, const int rawDataIndex, const std::string& nRelPath);
protected:
};