mirror of
https://github.com/zeldaret/oot.git
synced 2025-08-15 03:20:35 +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
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue