1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-13 10:21:18 +00:00

ZAPD update: libpng, zroom improvements and others (#811)

* git subrepo pull --force tools/ZAPD

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

* Add `libpng` to readme

* Remove `-ifp` since it doesn't exists anymore in ZAPD

* Remove extra print I added

* Add UNK_09 macro and other minor fixes

* Simplify PNG rules

* simplify gitignore

* Update README.md

Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com>

* Update dockerfile

* basic instructions for cygwin and mac

* git subrepo pull --force tools/ZAPD

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

* Change nanoseconds to seconds in extract_assets.py

Co-authored-by: Roman971 <32455037+Roman971@users.noreply.github.com>
This commit is contained in:
Anghelo Carvajal 2021-05-30 11:09:59 -04:00 committed by GitHub
parent 676ecf06c5
commit 515ebdce9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
142 changed files with 5922 additions and 14735 deletions

View file

@ -4,8 +4,6 @@
#include "Globals.h"
#include "StringHelper.h"
using namespace std;
REGISTER_ZFILENODE(Limb, ZLimb);
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset)
@ -105,12 +103,12 @@ Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawD
void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
{
string entryStr;
std::string entryStr;
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
string unk_8_Str =
std::string unk_8_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
@ -142,7 +140,7 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
if (unk_C != 0)
{
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
string unk_C_Str =
std::string unk_C_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
@ -173,9 +171,9 @@ void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) const
{
string entryStr;
std::string entryStr;
string unk_8_Str = "NULL";
std::string unk_8_Str = "NULL";
if (unk_8 != 0)
{
@ -185,7 +183,7 @@ std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) cons
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
}
string unk_C_Str = "NULL";
std::string unk_C_Str = "NULL";
if (unk_C != 0)
{
@ -242,22 +240,16 @@ Struct_800A5E28::~Struct_800A5E28()
delete unk_8_dlist;
}
ZLimb::~ZLimb()
{
for (auto DL : dLists)
delete DL;
}
void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
{
if (unk_4 != 0)
{
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
string unk_4_Str =
std::string unk_4_Str =
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
string entryStr = "";
std::string entryStr = "";
uint16_t arrayItemCnt = unk_4_arr.size();
size_t i = 0;
@ -294,7 +286,8 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
unk_8_dlist = new ZDisplayList(rawData, unk_8_Offset, dlistLength, parent);
string dListStr = StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
std::string dListStr =
StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
unk_8_dlist->SetName(dListStr);
unk_8_dlist->GetSourceOutputCode(prefix);
}
@ -302,9 +295,9 @@ void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) const
{
string entryStr = "";
std::string entryStr = "";
string unk_4_Str = "NULL";
std::string unk_4_Str = "NULL";
if (unk_4 != 0)
{
@ -323,7 +316,7 @@ std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) cons
}
}
string unk_8_Str = "NULL";
std::string unk_8_Str = "NULL";
if (unk_8 != 0)
{
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
@ -357,66 +350,76 @@ ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent)
{
dListPtr = 0;
dList2Ptr = 0;
RegisterOptionalAttribute("LimbType");
RegisterOptionalAttribute("Type");
}
ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, const std::vector<uint8_t>& nRawData,
uint32_t nRawDataIndex, ZFile* nParent)
: ZResource(nParent)
: ZLimb(nParent)
{
rawData.assign(nRawData.begin(), nRawData.end());
rawDataIndex = nRawDataIndex;
parent = nParent;
type = limbType;
segAddress = nRawDataIndex;
name = StringHelper::Sprintf("%sLimb_%06X", prefix.c_str(), GetFileAddress());
ParseRawData();
}
void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), name, "");
}
void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
// Reading from a <Skeleton/>
const char* limbType = reader->Attribute("LimbType");
if (limbType == nullptr) // Reading from a <Limb/>
limbType = reader->Attribute("Type");
std::string limbType = registeredAttributes.at("LimbType").value;
if (limbType == "") // Reading from a <Limb/>
limbType = registeredAttributes.at("Type").value;
if (limbType == nullptr)
if (limbType == "")
{
fprintf(stderr,
"ZLimb::ParseXML: Warning in '%s'.\n\t Missing 'LimbType' attribute in xml. "
"Defaulting to 'Standard'.\n",
"ZLimb::ParseXML: Warning in '%s'.\n"
"\t Missing 'LimbType' attribute in xml.\n"
"\t Defaulting to 'Standard'.\n",
name.c_str());
type = ZLimbType::Standard;
}
else
{
string limbTypeStr(limbType);
if (limbTypeStr == "Standard")
if (limbType == "Standard")
{
type = ZLimbType::Standard;
}
else if (limbTypeStr == "LOD")
else if (limbType == "LOD")
{
type = ZLimbType::LOD;
}
else if (limbTypeStr == "Skin")
else if (limbType == "Skin")
{
type = ZLimbType::Skin;
}
else if (limbTypeStr == "Curve")
else if (limbType == "Curve")
{
type = ZLimbType::Curve;
}
else
{
fprintf(stderr,
"ZLimb::ParseXML: Warning in '%s'.\n\t Invalid LimbType found: '%s'. "
"Defaulting to 'Standard'.\n",
name.c_str(), limbType);
"ZLimb::ParseXML: Warning in '%s'.\n"
"\t Invalid LimbType found: '%s'.\n"
"\t Defaulting to 'Standard'.\n",
name.c_str(), limbType.c_str());
type = ZLimbType::Standard;
}
}
@ -424,6 +427,8 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
void ZLimb::ParseRawData()
{
ZResource::ParseRawData();
if (type == ZLimbType::Curve)
{
childIndex = rawData.at(rawDataIndex + 0);
@ -445,14 +450,20 @@ void ZLimb::ParseRawData()
{
case ZLimbType::LOD:
dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
// Intended fallthrough
case ZLimbType::Standard:
dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
break;
case ZLimbType::Skin:
skinSegmentType =
static_cast<ZLimbSkinType>(BitConverter::ToInt32BE(rawData, rawDataIndex + 8));
skinSegment = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0)
{
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset);
}
break;
default:
throw std::runtime_error("Invalid ZLimb type");
@ -460,26 +471,7 @@ void ZLimb::ParseRawData()
}
}
void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, const std::vector<uint8_t>& nRawData,
const uint32_t nRawDataIndex, const std::string& nRelPath)
{
ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex, nRelPath);
segAddress = nRawDataIndex;
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
GetSourceTypeName(), name, "");
if (type == ZLimbType::Skin)
{
if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0)
{
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset);
}
}
}
size_t ZLimb::GetRawDataSize()
size_t ZLimb::GetRawDataSize() const
{
switch (type)
{
@ -494,23 +486,14 @@ size_t ZLimb::GetRawDataSize()
return 0x0C;
}
string ZLimb::GetSourceOutputCode(const std::string& prefix)
std::string ZLimb::GetSourceOutputCode(const std::string& prefix)
{
string dListStr = "NULL";
string dListStr2 = "NULL";
std::string limbPrefix = type == ZLimbType::Curve ? "Curve" : "";
std::string dListStr = GetLimbDListSourceOutputCode(prefix, limbPrefix, dListPtr);
limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far";
std::string dListStr2 = GetLimbDListSourceOutputCode(prefix, limbPrefix, dList2Ptr);
if (dListPtr != 0)
{
string limbPrefix = type == ZLimbType::Curve ? "Curve" : "";
dListStr = GetLimbDListSourceOutputCode(prefix, limbPrefix, dListPtr);
}
if (dList2Ptr != 0)
{
string limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far";
dListStr2 = GetLimbDListSourceOutputCode(prefix, limbPrefix, dList2Ptr);
}
string entryStr = "";
std::string entryStr = "";
if (type != ZLimbType::Curve)
{
entryStr += StringHelper::Sprintf("\n { %i, %i, %i },", transX, transY, transZ);
@ -543,12 +526,12 @@ string ZLimb::GetSourceOutputCode(const std::string& prefix)
return "";
}
std::string ZLimb::GetSourceTypeName()
std::string ZLimb::GetSourceTypeName() const
{
return GetSourceTypeName(type);
}
ZResourceType ZLimb::GetResourceType()
ZResourceType ZLimb::GetResourceType() const
{
return ZResourceType::Limb;
}
@ -582,9 +565,10 @@ const char* ZLimb::GetSourceTypeName(ZLimbType limbType)
uint32_t ZLimb::GetFileAddress()
{
return Seg2Filespace(segAddress, parent->baseAddress);
return Seg2Filespace(rawDataIndex, parent->baseAddress);
}
// Returns the ptrname of a dlist. Declares it if it has not been declared yet.
std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix,
const std::string& limbPrefix, segptr_t dListPtr)
{
@ -592,26 +576,42 @@ std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix,
return "NULL";
uint32_t dListOffset = Seg2Filespace(dListPtr, parent->baseAddress);
string dListStr;
// Check if pointing past the object's size
if (dListOffset > parent->GetRawData().size())
return StringHelper::Sprintf("0x%08X", dListPtr);
// Check if it is already declared
Declaration* decl = parent->GetDeclaration(dListOffset);
if (decl == nullptr)
{
dListStr = StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(),
dListOffset);
if (decl != nullptr)
return decl->varName;
int32_t dlistLength = ZDisplayList::GetDListLength(
rawData, dListOffset,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
auto dList = new ZDisplayList(rawData, dListOffset, dlistLength, parent);
dLists.push_back(dList);
dList->SetName(dListStr);
dList->GetSourceOutputCode(prefix);
}
else
// Check if it points to the middle of a DList
decl = parent->GetDeclarationRanged(dListOffset);
if (decl != nullptr)
{
dListStr = decl->varName;
// TODO: Figure out a way to not hardcode the "Gfx" type.
if (decl->varType == "Gfx")
{
uint32_t declAddress = parent->GetDeclarationRangedAddress(dListOffset);
if (dListOffset < declAddress + decl->size)
{
uint32_t index = (dListOffset - declAddress) / 8;
return StringHelper::Sprintf("&%s[%u]", decl->varName.c_str(), index);
}
}
}
// Create the DList
std::string dListStr =
StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), dListOffset);
int32_t dlistLength = ZDisplayList::GetDListLength(
rawData, dListOffset,
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
auto dList = new ZDisplayList(rawData, dListOffset, dlistLength, parent);
dList->SetName(dListStr);
dList->GetSourceOutputCode(prefix);
return dListStr;
}
@ -625,7 +625,7 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
string struct_800A5E28_Str;
std::string struct_800A5E28_Str;
Declaration* decl = parent->GetDeclaration(skinSegmentOffset);
if (decl == nullptr)
{
@ -634,7 +634,7 @@ std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset);
segmentStruct.PreGenSourceFiles(prefix);
string entryStr = segmentStruct.GetSourceOutputCode(prefix);
std::string entryStr = segmentStruct.GetSourceOutputCode(prefix);
parent->AddDeclaration(skinSegmentOffset, DeclarationAlignment::None,
Struct_800A5E28::GetRawDataSize(),
@ -652,7 +652,7 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
{
assert(type == ZLimbType::Skin);
string skinSegmentStr = "NULL";
std::string skinSegmentStr = "NULL";
if (skinSegment != 0)
{
@ -681,7 +681,7 @@ std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
}
}
string entryStr =
std::string entryStr =
StringHelper::Sprintf(" 0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str());
return entryStr;