summaryrefslogtreecommitdiff
path: root/ZAPD/OtherStructs/SkinLimbStructs.cpp
diff options
context:
space:
mode:
authorAnghelo Carvajal <angheloalf95@gmail.com>2021-10-16 18:55:56 -0300
committerGitHub <noreply@github.com>2021-10-16 17:55:56 -0400
commite7a8a48cf361a7591b88592eb3e333ddf8d3ab34 (patch)
tree4f63eac4c2136dd74e05593ea200b2c24c284a3f /ZAPD/OtherStructs/SkinLimbStructs.cpp
parent3e9ed72e202b1165152d42f7d160695f9f2f233a (diff)
`ExternalFile`: Expose other XML's declarations during extraction (#151)
* proof of concept * fix header include paths * GetDeclarationAlignment and others * this should fix this * minor * DeclareVar in ExtractFromXML * fix vtx intersections * Fix segmented vtxs * --version * zcollision changes * Use GetSegmentedPtrName a lot more * memory related stuff * minor style fixes and use the actual symbol for zlinkanimation instead of the hex address * Simplify lots of GetSourceOutputCode * ZSkeleton cleanup and other changes * Elevate unknown types in skeleton to errors * ZAnimation cleanup * Add ExternalFile to config * delete some code * Remove unused code * fix conflicts * format * remove redundant constructors * minor fixes * fix vtx warnings * extract every vtx as standalone files * format * uups * Bugfix: don't create extra blank files * Fix some Vtx warnings and remove "defaulting to normal" in skeleton error * Refactor ZLimb * Make each limb to look up in every file for dlists * Use GetSegmentedArrayIndexedName in VTX references in dlists * simplify simple condition * search by type * run format * Revert "search by type" This reverts commit a049bdfc94c4ab04613b354f466dee836a20508a. * Add range checks * uups * Always set rangeEnd * special case zsymbol * Revert "Revert "search by type"" This reverts commit 3f6e77c780bd30dc7000614304021a0940168316. * symbol fix and IsOffsetInFileRange * Bugfix and minor checks * run format * Don't extract data from external files * Fix extraction of overly big tluts * Minor changes * More minor fixes * Fix clang warnings * Remove unused parameter * Fix merge issues * Fix ZLimbTable::DeclareVar * Fix limbs not naming properly their DLists * Remove segment number check * Fix merge problems * Run formatter * Maybe fix? * path * empty commit * Fix a typo * Fix merge issues * Fix null ptr dereferencing * Fix merge issues and some clang warnings * Format * Fix not-matching * Format * Fix merge issues * Fix exporter * Last fixes I hope * Fix merge issues * format * fix * fix * I'm dumb * format * static fix * Whoops * fix asan * Fix? * fix * reduce artificial changes * reduce artificial changes 2 * reorder more stuff * format * fix borken thing * Remove redundant stuff in zfile * fix * Format * Fix conflict issues * format * cleanup header includes * format * Add error checks in for ExternalXMLFolder * format
Diffstat (limited to 'ZAPD/OtherStructs/SkinLimbStructs.cpp')
-rw-r--r--ZAPD/OtherStructs/SkinLimbStructs.cpp341
1 files changed, 341 insertions, 0 deletions
diff --git a/ZAPD/OtherStructs/SkinLimbStructs.cpp b/ZAPD/OtherStructs/SkinLimbStructs.cpp
new file mode 100644
index 0000000..9d16de4
--- /dev/null
+++ b/ZAPD/OtherStructs/SkinLimbStructs.cpp
@@ -0,0 +1,341 @@
+#include "SkinLimbStructs.h"
+
+#include "Globals.h"
+#include "Utils/BitConverter.h"
+#include "Utils/StringHelper.h"
+#include "ZDisplayList.h"
+#include "ZFile.h"
+
+/* Struct_800A57C0 */
+
+Struct_800A57C0::Struct_800A57C0(ZFile* nParent) : ZResource(nParent)
+{
+}
+
+void Struct_800A57C0::ParseRawData()
+{
+ const auto& rawData = parent->GetRawData();
+
+ unk_0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00);
+ unk_2 = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x02);
+ unk_4 = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x04);
+ unk_6 = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x06);
+ unk_7 = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x07);
+ unk_8 = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x08);
+ unk_9 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x09);
+}
+
+std::string Struct_800A57C0::GetBodySourceCode() const
+{
+ return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X", unk_0, unk_2, unk_4, unk_6,
+ unk_7, unk_8, unk_9);
+}
+
+std::string Struct_800A57C0::GetSourceTypeName() const
+{
+ return "Struct_800A57C0";
+}
+
+ZResourceType Struct_800A57C0::GetResourceType() const
+{
+ // TODO
+ return ZResourceType::Error;
+}
+
+size_t Struct_800A57C0::GetRawDataSize() const
+{
+ return 0x0A;
+}
+
+/* Struct_800A598C_2 */
+
+Struct_800A598C_2::Struct_800A598C_2(ZFile* nParent) : ZResource(nParent)
+{
+}
+
+void Struct_800A598C_2::ParseRawData()
+{
+ const auto& rawData = parent->GetRawData();
+
+ unk_0 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x00);
+ x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x02);
+ y = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x04);
+ z = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x06);
+ unk_8 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08);
+}
+
+std::string Struct_800A598C_2::GetBodySourceCode() const
+{
+ return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", unk_0, x, y, z, unk_8);
+}
+
+std::string Struct_800A598C_2::GetSourceTypeName() const
+{
+ return "Struct_800A598C_2";
+}
+
+ZResourceType Struct_800A598C_2::GetResourceType() const
+{
+ // TODO
+ return ZResourceType::Error;
+}
+
+size_t Struct_800A598C_2::GetRawDataSize() const
+{
+ return 0x0A;
+}
+
+/* Struct_800A598C */
+
+Struct_800A598C::Struct_800A598C(ZFile* nParent) : ZResource(nParent)
+{
+}
+
+void Struct_800A598C::ParseRawData()
+{
+ const auto& rawData = parent->GetRawData();
+
+ unk_0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00);
+ unk_2 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x02);
+ unk_4 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x04);
+ unk_8 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08);
+ unk_C = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C);
+
+ if (unk_8 != 0 && GETSEGNUM(unk_8) == parent->segment)
+ {
+ uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
+ for (size_t i = 0; i < unk_0; i++)
+ {
+ Struct_800A57C0 unk8_data(parent);
+ unk8_data.ExtractFromFile(unk_8_Offset);
+ unk_8_arr.push_back(unk8_data);
+
+ unk_8_Offset += unk8_data.GetRawDataSize();
+ }
+ }
+
+ if (unk_C != 0 && GETSEGNUM(unk_8) == parent->segment)
+ {
+ uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
+ for (size_t i = 0; i < unk_2; i++)
+ {
+ Struct_800A598C_2 unkC_data(parent);
+ unkC_data.ExtractFromFile(unk_C_Offset);
+ unk_C_arr.push_back(unkC_data);
+
+ unk_C_Offset += unkC_data.GetRawDataSize();
+ }
+ }
+}
+
+void Struct_800A598C::DeclareReferences(const std::string& prefix)
+{
+ std::string varPrefix = prefix;
+ if (name != "")
+ varPrefix = name;
+
+ if (unk_8 != 0 && GETSEGNUM(unk_8) == parent->segment)
+ {
+ const auto& res = unk_8_arr.at(0);
+ std::string unk_8_Str = res.GetDefaultName(varPrefix);
+
+ size_t arrayItemCnt = unk_8_arr.size();
+ std::string entryStr = "";
+
+ for (size_t i = 0; i < arrayItemCnt; i++)
+ {
+ auto& child = unk_8_arr[i];
+ child.DeclareReferences(varPrefix);
+ entryStr += StringHelper::Sprintf("\t{ %s },", child.GetBodySourceCode().c_str());
+
+ if (i < arrayItemCnt - 1)
+ entryStr += "\n";
+ }
+
+ uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
+ Declaration* decl = parent->GetDeclaration(unk_8_Offset);
+ if (decl == nullptr)
+ {
+ parent->AddDeclarationArray(unk_8_Offset, res.GetDeclarationAlignment(),
+ arrayItemCnt * res.GetRawDataSize(),
+ res.GetSourceTypeName(), unk_8_Str, arrayItemCnt, entryStr);
+ }
+ else
+ decl->text = entryStr;
+ }
+
+ if (unk_C != 0 && GETSEGNUM(unk_C) == parent->segment)
+ {
+ const auto& res = unk_C_arr.at(0);
+ std::string unk_C_Str = res.GetDefaultName(varPrefix);
+
+ size_t arrayItemCnt = unk_C_arr.size();
+ std::string entryStr = "";
+
+ for (size_t i = 0; i < arrayItemCnt; i++)
+ {
+ auto& child = unk_C_arr[i];
+ child.DeclareReferences(varPrefix);
+ entryStr += StringHelper::Sprintf("\t{ %s },", child.GetBodySourceCode().c_str());
+
+ if (i < arrayItemCnt - 1)
+ entryStr += "\n";
+ }
+
+ uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
+ Declaration* decl = parent->GetDeclaration(unk_C_Offset);
+ if (decl == nullptr)
+ {
+ parent->AddDeclarationArray(unk_C_Offset, res.GetDeclarationAlignment(),
+ arrayItemCnt * res.GetRawDataSize(),
+ res.GetSourceTypeName(), unk_C_Str, arrayItemCnt, entryStr);
+ }
+ else
+ decl->text = entryStr;
+ }
+}
+
+std::string Struct_800A598C::GetBodySourceCode() const
+{
+ std::string unk_8_Str;
+ std::string unk_C_Str;
+ Globals::Instance->GetSegmentedPtrName(unk_8, parent, "Struct_800A57C0", unk_8_Str);
+ Globals::Instance->GetSegmentedPtrName(unk_C, parent, "Struct_800A598C_2", unk_C_Str);
+
+ std::string entryStr = StringHelper::Sprintf("\n\t\tARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n",
+ unk_8_Str.c_str(), unk_C_Str.c_str());
+ entryStr +=
+ StringHelper::Sprintf("\t\t%i, %s, %s\n\t", unk_4, unk_8_Str.c_str(), unk_C_Str.c_str());
+
+ return entryStr;
+}
+
+std::string Struct_800A598C::GetSourceTypeName() const
+{
+ return "Struct_800A598C";
+}
+
+ZResourceType Struct_800A598C::GetResourceType() const
+{
+ // TODO
+ return ZResourceType::Error;
+}
+
+size_t Struct_800A598C::GetRawDataSize() const
+{
+ return 0x10;
+}
+
+/* Struct_800A5E28 */
+
+Struct_800A5E28::Struct_800A5E28(ZFile* nParent) : ZResource(nParent)
+{
+}
+
+void Struct_800A5E28::ParseRawData()
+{
+ const auto& rawData = parent->GetRawData();
+
+ unk_0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00);
+ unk_2 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x02);
+ unk_4 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
+ unk_8 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08);
+
+ if (unk_4 != 0 && GETSEGNUM(unk_4) == parent->segment)
+ {
+ uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
+ for (size_t i = 0; i < unk_2; i++)
+ {
+ Struct_800A598C unk_4_data(parent);
+ unk_4_data.ExtractFromFile(unk_4_Offset);
+ unk_4_arr.push_back(unk_4_data);
+
+ unk_4_Offset += unk_4_data.GetRawDataSize();
+ }
+ }
+}
+
+void Struct_800A5E28::DeclareReferences(const std::string& prefix)
+{
+ std::string varPrefix = prefix;
+ if (name != "")
+ varPrefix = name;
+
+ ZResource::DeclareReferences(varPrefix);
+
+ if (unk_4 != 0 && GETSEGNUM(unk_4) == parent->segment)
+ {
+ const auto& res = unk_4_arr.at(0);
+ std::string unk_4_Str = res.GetDefaultName(varPrefix);
+
+ size_t arrayItemCnt = unk_4_arr.size();
+ std::string entryStr = "";
+
+ for (size_t i = 0; i < arrayItemCnt; i++)
+ {
+ auto& child = unk_4_arr[i];
+ child.DeclareReferences(varPrefix);
+ entryStr += StringHelper::Sprintf("\t{ %s },", child.GetBodySourceCode().c_str());
+
+ if (i < arrayItemCnt - 1)
+ entryStr += "\n";
+ }
+
+ uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
+ Declaration* decl = parent->GetDeclaration(unk_4_Offset);
+ if (decl == nullptr)
+ {
+ parent->AddDeclarationArray(unk_4_Offset, res.GetDeclarationAlignment(),
+ arrayItemCnt * res.GetRawDataSize(),
+ res.GetSourceTypeName(), unk_4_Str, arrayItemCnt, entryStr);
+ }
+ else
+ decl->text = entryStr;
+ }
+
+ if (unk_8 != 0 && GETSEGNUM(unk_8) == parent->segment)
+ {
+ uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
+
+ int32_t dlistLength = ZDisplayList::GetDListLength(
+ parent->GetRawData(), unk_8_Offset,
+ Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
+ ZDisplayList* unk_8_dlist = new ZDisplayList(parent);
+ unk_8_dlist->ExtractFromBinary(unk_8_Offset, dlistLength);
+
+ std::string dListStr =
+ StringHelper::Sprintf("%sSkinLimbDL_%06X", varPrefix.c_str(), unk_8_Offset);
+ unk_8_dlist->SetName(dListStr);
+ parent->AddResource(unk_8_dlist);
+ }
+}
+
+std::string Struct_800A5E28::GetBodySourceCode() const
+{
+ std::string unk_4_Str;
+ std::string unk_8_Str;
+ Globals::Instance->GetSegmentedPtrName(unk_4, parent, "Struct_800A598C", unk_4_Str);
+ Globals::Instance->GetSegmentedPtrName(unk_8, parent, "Gfx", unk_8_Str);
+
+ std::string entryStr = "\n";
+ entryStr += StringHelper::Sprintf("\t%i, ARRAY_COUNTU(%s),\n", unk_0, unk_4_Str.c_str());
+ entryStr += StringHelper::Sprintf("\t%s, %s\n", unk_4_Str.c_str(), unk_8_Str.c_str());
+
+ return entryStr;
+}
+
+std::string Struct_800A5E28::GetSourceTypeName() const
+{
+ return "Struct_800A5E28";
+}
+
+ZResourceType Struct_800A5E28::GetResourceType() const
+{
+ // TODO
+ return ZResourceType::Error;
+}
+
+size_t Struct_800A5E28::GetRawDataSize() const
+{
+ return 0x0C;
+}