summaryrefslogtreecommitdiff
path: root/ZAPD/ZAnimation.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-05-26 22:32:39 -0400
committerGitHub <noreply@github.com>2021-05-26 22:32:39 -0400
commitcd3e9527b185190c5f7826766bf2b4760bd12d5f (patch)
treebb01e372abc6a72511130adcee1d5e27127a5f49 /ZAPD/ZAnimation.cpp
parent4410b554e835ab7844c8eb78fd54fa3842d50f16 (diff)
A few Limbs, Skel and CurveAnimation fixes (#144)
* Detect if a limb is pointing to the middle of a dlist * Fix limbs names being ignored in some cases * Check if pointing past the object's size * Remove unnecesary pointers * Don't try to extract the skel offset declared in a CurveAnimation * Final cleanup * Use GetDeclarationRanged * Always set the rangeEnd to the filesize by default * Revert "Always set the rangeEnd to the filesize by default" This reverts commit f5c135c39a1df3f545c97c0a0becf7808115e06f.
Diffstat (limited to 'ZAPD/ZAnimation.cpp')
-rw-r--r--ZAPD/ZAnimation.cpp40
1 files changed, 13 insertions, 27 deletions
diff --git a/ZAPD/ZAnimation.cpp b/ZAPD/ZAnimation.cpp
index f011a29..5f9f934 100644
--- a/ZAPD/ZAnimation.cpp
+++ b/ZAPD/ZAnimation.cpp
@@ -229,11 +229,6 @@ ZCurveAnimation::ZCurveAnimation(ZFile* nParent) : ZAnimation(nParent)
RegisterOptionalAttribute("SkelOffset");
}
-ZCurveAnimation::~ZCurveAnimation()
-{
- delete skel;
-}
-
void ZCurveAnimation::ParseXML(tinyxml2::XMLElement* reader)
{
ZAnimation::ParseXML(reader);
@@ -259,25 +254,18 @@ void ZCurveAnimation::ParseRawData()
copyValues = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
unk_0C = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
unk_10 = BitConverter::ToInt16BE(rawData, rawDataIndex + 14);
-}
-void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
- const std::vector<uint8_t>& nRawData,
- const uint32_t nRawDataIndex)
-{
- ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
-
- skel = new ZSkeleton(ZSkeletonType::Curve, ZLimbType::Curve, "CurveAnim", nRawData,
- Seg2Filespace(skelOffset, parent->baseAddress), parent);
+ limbCount =
+ BitConverter::ToUInt8BE(rawData, Seg2Filespace(skelOffset, parent->baseAddress) + 4);
size_t transformDataSize = 0;
size_t copyValuesSize = 0;
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
- for (size_t i = 0; i < 3 * 3 * skel->GetLimbCount(); i++)
+ for (size_t i = 0; i < 3 * 3 * limbCount; i++)
{
- uint8_t ref = BitConverter::ToUInt8BE(nRawData, refIndexOffset + i);
+ uint8_t ref = BitConverter::ToUInt8BE(rawData, refIndexOffset + i);
if (ref == 0)
copyValuesSize++;
else
@@ -292,7 +280,7 @@ void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
for (size_t i = 0; i < transformDataSize; i++)
- transformDataArr.emplace_back(parent, nRawData, transformDataOffset, i);
+ transformDataArr.emplace_back(parent, rawData, transformDataOffset, i);
}
if (copyValues != 0)
@@ -300,21 +288,21 @@ void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
for (size_t i = 0; i < copyValuesSize; i++)
- copyValuesArr.emplace_back(BitConverter::ToInt16BE(nRawData, copyValuesOffset + i * 2));
+ copyValuesArr.emplace_back(BitConverter::ToInt16BE(rawData, copyValuesOffset + i * 2));
}
+}
+
+void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader,
+ const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex)
+{
+ ZResource::ExtractFromXML(reader, nRawData, nRawDataIndex);
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(),
GetSourceTypeName(), name, "");
}
-void ZCurveAnimation::PreGenValues(const std::string& prefix)
+void ZCurveAnimation::DeclareReferences(const std::string& prefix)
{
- Declaration* decl = parent->GetDeclaration(skelOffset);
- if (decl == nullptr)
- {
- skel->GetSourceOutputCode(prefix);
- }
-
if (refIndex != 0)
{
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
@@ -413,8 +401,6 @@ std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
std::string bodyStr = "";
uint32_t address = Seg2Filespace(rawDataIndex, parent->baseAddress);
- PreGenValues(prefix);
-
std::string refIndexStr = "NULL";
if (refIndex != 0)
{