diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2021-10-16 18:55:56 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-16 17:55:56 -0400 |
| commit | e7a8a48cf361a7591b88592eb3e333ddf8d3ab34 (patch) | |
| tree | 4f63eac4c2136dd74e05593ea200b2c24c284a3f /ZAPD/ZLimb.cpp | |
| parent | 3e9ed72e202b1165152d42f7d160695f9f2f233a (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/ZLimb.cpp')
| -rw-r--r-- | ZAPD/ZLimb.cpp | 586 |
1 files changed, 96 insertions, 490 deletions
diff --git a/ZAPD/ZLimb.cpp b/ZAPD/ZLimb.cpp index 837160e..77c6687 100644 --- a/ZAPD/ZLimb.cpp +++ b/ZAPD/ZLimb.cpp @@ -8,351 +8,8 @@ REGISTER_ZFILENODE(Limb, ZLimb); -Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset) +ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent), segmentStruct(nParent) { - unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00); - unk_2 = BitConverter::ToInt16BE(rawData, fileOffset + 0x02); - unk_4 = BitConverter::ToInt16BE(rawData, fileOffset + 0x04); - unk_6 = BitConverter::ToInt8BE(rawData, fileOffset + 0x06); - unk_7 = BitConverter::ToInt8BE(rawData, fileOffset + 0x07); - unk_8 = BitConverter::ToInt8BE(rawData, fileOffset + 0x08); - unk_9 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x09); -} -Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset, - size_t index) - : Struct_800A57C0(rawData, fileOffset + index * GetRawDataSize()) -{ -} - -std::string Struct_800A57C0::GetSourceOutputCode() 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); -} - -size_t Struct_800A57C0::GetRawDataSize() -{ - return 0x0A; -} - -std::string Struct_800A57C0::GetSourceTypeName() -{ - return "Struct_800A57C0"; -} - -Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset) -{ - unk_0 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x00); - x = BitConverter::ToInt16BE(rawData, fileOffset + 0x02); - y = BitConverter::ToInt16BE(rawData, fileOffset + 0x04); - z = BitConverter::ToInt16BE(rawData, fileOffset + 0x06); - unk_8 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x08); -} -Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset, - size_t index) - : Struct_800A598C_2(rawData, fileOffset + index * GetRawDataSize()) -{ -} - -std::string Struct_800A598C_2::GetSourceOutputCode() const -{ - return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", unk_0, x, y, z, unk_8); -} - -size_t Struct_800A598C_2::GetRawDataSize() -{ - return 0x0A; -} - -std::string Struct_800A598C_2::GetSourceTypeName() -{ - return "Struct_800A598C_2"; -} - -Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, - uint32_t fileOffset) - : parent(parent) -{ - unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00); - unk_2 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x02); - unk_4 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x04); - unk_8 = BitConverter::ToUInt32BE(rawData, fileOffset + 0x08); - unk_C = BitConverter::ToUInt32BE(rawData, fileOffset + 0x0C); - - if (unk_8 != 0) - { - uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - for (size_t i = 0; i < unk_0; i++) - { - unk_8_arr.emplace_back(rawData, unk_8_Offset, i); - } - } - - if (unk_C != 0) - { - uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress); - for (size_t i = 0; i < unk_2; i++) - { - unk_C_arr.emplace_back(rawData, unk_C_Offset, i); - } - } -} -Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, - uint32_t fileOffset, size_t index) - : Struct_800A598C(parent, rawData, fileOffset + index * GetRawDataSize()) -{ -} - -void Struct_800A598C::DeclareReferences(const std::string& prefix) -{ - std::string entryStr; - - if (unk_8 != 0) - { - uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - std::string unk_8_Str = - StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), - Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset); - - size_t arrayItemCnt = unk_8_arr.size(); - entryStr = ""; - size_t i = 0; - - for (auto& child : unk_8_arr) - { - entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(), - (++i < arrayItemCnt) ? "\n" : ""); - } - - Declaration* decl = parent->GetDeclaration(unk_8_Offset); - - if (decl == nullptr) - { - parent->AddDeclarationArray(unk_8_Offset, DeclarationAlignment::Align4, - arrayItemCnt * Struct_800A57C0::GetRawDataSize(), - Struct_800A57C0::GetSourceTypeName(), unk_8_Str, - arrayItemCnt, entryStr); - } - else - { - decl->text = entryStr; - } - } - - if (unk_C != 0) - { - uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress); - std::string unk_C_Str = - StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), - Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset); - - size_t arrayItemCnt = unk_C_arr.size(); - entryStr = ""; - size_t i = 0; - - for (auto& child : unk_C_arr) - { - entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(), - (++i < arrayItemCnt) ? "\n" : ""); - } - - Declaration* decl = parent->GetDeclaration(unk_C_Offset); - if (decl == nullptr) - { - parent->AddDeclarationArray(unk_C_Offset, DeclarationAlignment::Align4, - arrayItemCnt * Struct_800A598C_2::GetRawDataSize(), - Struct_800A598C_2::GetSourceTypeName(), unk_C_Str, - arrayItemCnt, entryStr); - } - else - { - decl->text = entryStr; - } - } -} - -std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) const -{ - std::string entryStr; - - std::string unk_8_Str = "NULL"; - - if (unk_8 != 0) - { - uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - unk_8_Str = - StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), - Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset); - } - - std::string unk_C_Str = "NULL"; - - if (unk_C != 0) - { - uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress); - unk_C_Str = - StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), - Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset); - } - - entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n", - unk_8_Str.c_str(), unk_C_Str.c_str()); - entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(), - unk_C_Str.c_str()); - entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n", - unk_8_Str.c_str(), unk_C_Str.c_str()); - entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(), - unk_C_Str.c_str()); - - return entryStr; -} - -size_t Struct_800A598C::GetRawDataSize() -{ - return 0x10; -} - -std::string Struct_800A598C::GetSourceTypeName() -{ - return "Struct_800A598C"; -} - -Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& nRawData, - uint32_t fileOffset) - : parent(parent) -{ - unk_0 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x00); - unk_2 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x02); - unk_4 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x04); - unk_8 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x08); - - if (unk_4 != 0) - { - uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); - - for (size_t i = 0; i < unk_2; i++) - { - unk_4_arr.emplace_back(parent, nRawData, unk_4_Offset, i); - } - } -} - -Struct_800A5E28::~Struct_800A5E28() -{ - delete unk_8_dlist; -} - -void Struct_800A5E28::DeclareReferences(const std::string& prefix) -{ - if (unk_4 != 0) - { - uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); - std::string unk_4_Str = - StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), - Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset); - - std::string entryStr; - uint16_t arrayItemCnt = unk_4_arr.size(); - - size_t i = 0; - - for (auto& child : unk_4_arr) - { - child.DeclareReferences(prefix); - entryStr += - StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode(prefix).c_str(), - (++i < arrayItemCnt) ? "\n" : ""); - } - - Declaration* decl = parent->GetDeclaration(unk_4_Offset); - - if (decl == nullptr) - { - parent->AddDeclarationArray(unk_4_Offset, DeclarationAlignment::Align4, - arrayItemCnt * Struct_800A598C::GetRawDataSize(), - Struct_800A598C::GetSourceTypeName(), unk_4_Str, - arrayItemCnt, entryStr); - } - else - { - decl->text = entryStr; - } - } - - if (unk_8 != 0) - { - 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); - unk_8_dlist = new ZDisplayList(parent); - unk_8_dlist->ExtractFromBinary(unk_8_Offset, dlistLength); - - std::string dListStr = - StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset); - unk_8_dlist->SetName(dListStr); - unk_8_dlist->GetSourceOutputCode(prefix); - } -} - -std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) const -{ - std::string entryStr; - - std::string unk_4_Str = "NULL"; - - if (unk_4 != 0) - { - uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress); - Declaration* decl = parent->GetDeclaration(unk_4_Offset); - - if (decl == nullptr) - { - unk_4_Str = - StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), - Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset); - } - else - { - unk_4_Str = decl->varName; - } - } - - std::string unk_8_Str = "NULL"; - if (unk_8 != 0) - { - uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress); - Declaration* decl = parent->GetDeclaration(unk_8_Offset); - if (decl == nullptr) - { - // Something went wrong... - unk_8_Str = StringHelper::Sprintf("0x%08X", unk_8); - } - else - { - unk_8_Str = decl->varName; - } - } - - return StringHelper::Sprintf("\n %i, ARRAY_COUNTU(%s),\n %s, %s\n", unk_0, - unk_4_Str.c_str(), unk_4_Str.c_str(), unk_8_Str.c_str()); -} - -size_t Struct_800A5E28::GetRawDataSize() -{ - return 0x0C; -} - -std::string Struct_800A5E28::GetSourceTypeName() -{ - return "Struct_800A5E28"; -} - -ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent) -{ - dListPtr = 0; - dList2Ptr = 0; RegisterOptionalAttribute("LimbType"); RegisterOptionalAttribute("Type"); } @@ -362,6 +19,10 @@ void ZLimb::ExtractFromBinary(uint32_t nRawDataIndex, ZLimbType nType) rawDataIndex = nRawDataIndex; type = nType; + // Don't parse raw data of external files + if (parent->GetMode() == ZFileMode::ExternalFile) + return; + ParseRawData(); } @@ -376,37 +37,29 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader) if (limbType == "") { - fprintf(stderr, - "ZLimb::ParseXML: Warning in '%s'.\n" - "\t Missing 'LimbType' attribute in xml.\n" - "\t Defaulting to 'Standard'.\n", - name.c_str()); - type = ZLimbType::Standard; + throw std::runtime_error(StringHelper::Sprintf("ZLimb::ParseXML: Error in '%s'.\n" + "\t Missing 'LimbType' attribute in xml.\n", + name.c_str())); } - else + + type = GetTypeByAttributeName(limbType); + if (type == ZLimbType::Invalid) { - type = GetTypeByAttributeName(limbType); - if (type == ZLimbType::Invalid) - { - fprintf(stderr, - "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; - } + throw std::runtime_error(StringHelper::Sprintf("ZLimb::ParseXML: Error in '%s'.\n" + "\t Invalid 'LimbType' found: '%s'.\n", + name.c_str(), limbType.c_str())); } } void ZLimb::ParseRawData() { ZResource::ParseRawData(); - const auto& rawData = parent->GetRawData(); + if (type == ZLimbType::Curve) { - childIndex = rawData.at(rawDataIndex + 0); - siblingIndex = rawData.at(rawDataIndex + 1); + childIndex = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0); + siblingIndex = BitConverter::ToUInt8BE(rawData, rawDataIndex + 1); dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4); dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8); @@ -446,12 +99,16 @@ void ZLimb::ParseRawData() skinSegmentType = static_cast<ZLimbSkinType>(BitConverter::ToInt32BE(rawData, rawDataIndex + 8)); skinSegment = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12); - if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0) + if (skinSegmentType == ZLimbSkinType::SkinType_4) { - uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress); - segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset); + if (skinSegment != 0 && GETSEGNUM(skinSegment) == parent->segment) + { + uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress); + segmentStruct.ExtractFromFile(skinSegmentOffset); + } } break; + default: throw std::runtime_error("Invalid ZLimb type"); break; @@ -460,8 +117,13 @@ void ZLimb::ParseRawData() void ZLimb::DeclareReferences(const std::string& prefix) { - ZResource::DeclareReferences(prefix); + std::string varPrefix = name; + if (varPrefix == "") + varPrefix = prefix; + + ZResource::DeclareReferences(varPrefix); + std::string suffix; switch (type) { case ZLimbType::Legacy: @@ -472,8 +134,8 @@ void ZLimb::DeclareReferences(const std::string& prefix) { ZLimb* child = new ZLimb(parent); child->ExtractFromBinary(childOffset, ZLimbType::Legacy); - child->DeclareVar(prefix, ""); - child->DeclareReferences(prefix); + child->DeclareVar(varPrefix, ""); + child->DeclareReferences(varPrefix); parent->AddResource(child); } } @@ -484,18 +146,45 @@ void ZLimb::DeclareReferences(const std::string& prefix) { ZLimb* sibling = new ZLimb(parent); sibling->ExtractFromBinary(siblingdOffset, ZLimbType::Legacy); - sibling->DeclareVar(prefix, ""); - sibling->DeclareReferences(prefix); + sibling->DeclareVar(varPrefix, ""); + sibling->DeclareReferences(varPrefix); parent->AddResource(sibling); } } break; - // TODO - case ZLimbType::Standard: + case ZLimbType::Curve: case ZLimbType::LOD: + suffix = "Far"; + if (type == ZLimbType::Curve) + suffix = "Curve2"; + DeclareDList(dList2Ptr, varPrefix, suffix); + [[fallthrough]]; + case ZLimbType::Standard: + suffix = ""; + if (type == ZLimbType::Curve) + suffix = "Curve"; + DeclareDList(dListPtr, varPrefix, suffix); + break; + case ZLimbType::Skin: - case ZLimbType::Curve: + switch (skinSegmentType) + { + case ZLimbSkinType::SkinType_4: + if (skinSegment != 0 && GETSEGNUM(skinSegment) == parent->segment) + { + segmentStruct.DeclareReferences(varPrefix); + segmentStruct.GetSourceOutputCode(varPrefix); + } + break; + + case ZLimbSkinType::SkinType_DList: + DeclareDList(skinSegment, varPrefix, ""); + break; + + default: + break; + } break; case ZLimbType::Invalid: @@ -527,14 +216,18 @@ size_t ZLimb::GetRawDataSize() const std::string ZLimb::GetBodySourceCode() const { - std::string dListStr = parent->GetDeclarationPtrName(dListPtr); - std::string dListStr2 = parent->GetDeclarationPtrName(dList2Ptr); + std::string dListStr; + std::string dListStr2; + Globals::Instance->GetSegmentedArrayIndexedName(dListPtr, 8, parent, "Gfx", dListStr); + Globals::Instance->GetSegmentedArrayIndexedName(dList2Ptr, 8, parent, "Gfx", dListStr2); std::string entryStr = "\n\t"; if (type == ZLimbType::Legacy) { - std::string childName = parent->GetDeclarationPtrName(childPtr); - std::string siblingName = parent->GetDeclarationPtrName(siblingPtr); + std::string childName; + std::string siblingName; + Globals::Instance->GetSegmentedPtrName(childPtr, parent, "Gfx", childName); + Globals::Instance->GetSegmentedPtrName(siblingPtr, parent, "Gfx", siblingName); entryStr += StringHelper::Sprintf("%s,\n", dListStr.c_str()); entryStr += @@ -565,7 +258,8 @@ std::string ZLimb::GetBodySourceCode() const case ZLimbType::Skin: { - std::string skinSegmentStr = parent->GetDeclarationPtrName(skinSegment); + std::string skinSegmentStr; + Globals::Instance->GetSegmentedPtrName(skinSegment, parent, "", skinSegmentStr); entryStr += StringHelper::Sprintf("\t0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str()); } @@ -656,122 +350,34 @@ ZLimbType ZLimb::GetTypeByAttributeName(const std::string& attrName) return ZLimbType::Invalid; } -// 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) +void ZLimb::DeclareDList(segptr_t dListSegmentedPtr, const std::string& prefix, + const std::string& limbSuffix) { - if (dListPtr == 0) - return "NULL"; - - uint32_t dListOffset = Seg2Filespace(dListPtr, parent->baseAddress); - - // Check if pointing past the object's size - if (dListOffset > parent->GetRawData().size()) - return StringHelper::Sprintf("0x%08X", dListPtr); + if (dListSegmentedPtr == 0 || GETSEGNUM(dListSegmentedPtr) != parent->segment) + return; - // Check if it is already declared - Declaration* decl = parent->GetDeclaration(dListOffset); - if (decl != nullptr) - return decl->varName; + uint32_t dlistOffset = Seg2Filespace(dListSegmentedPtr, parent->baseAddress); + if (parent->HasDeclaration(dlistOffset)) + return; - // Check if it points to the middle of a DList - decl = parent->GetDeclarationRanged(dListOffset); - if (decl != nullptr) - { - // 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); - } - } - } + if (!parent->IsOffsetInFileRange(dlistOffset) || dlistOffset >= parent->GetRawData().size()) + return; - // Create the DList - std::string dListStr = - StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), dListOffset); + std::string dlistName; + bool declFound = Globals::Instance->GetSegmentedArrayIndexedName(dListSegmentedPtr, 8, parent, + "Gfx", dlistName); + if (declFound) + return; int32_t dlistLength = ZDisplayList::GetDListLength( - parent->GetRawData(), dListOffset, + parent->GetRawData(), dlistOffset, Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX); - auto dList = new ZDisplayList(parent); - dList->ExtractFromBinary(dListOffset, dlistLength); - dList->SetName(dListStr); - dList->GetSourceOutputCode(prefix); - return dListStr; -} - -std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix) -{ - assert(type == ZLimbType::Skin); - assert(skinSegmentType == ZLimbSkinType::SkinType_4); + ZDisplayList* dlist = new ZDisplayList(parent); + dlist->ExtractFromBinary(dlistOffset, dlistLength); - if (skinSegment == 0) - return "NULL"; - - uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress); - - std::string struct_800A5E28_Str; - Declaration* decl = parent->GetDeclaration(skinSegmentOffset); - if (decl == nullptr) - { - struct_800A5E28_Str = - StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(), - Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset); - - segmentStruct.DeclareReferences(prefix); - std::string entryStr = segmentStruct.GetSourceOutputCode(prefix); - - parent->AddDeclaration(skinSegmentOffset, DeclarationAlignment::Align4, - Struct_800A5E28::GetRawDataSize(), - Struct_800A5E28::GetSourceTypeName(), struct_800A5E28_Str, entryStr); - } - else - { - struct_800A5E28_Str = decl->varName; - } - - return struct_800A5E28_Str; -} - -std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix) -{ - assert(type == ZLimbType::Skin); - - std::string skinSegmentStr = "NULL"; - - if (skinSegment != 0) - { - switch (skinSegmentType) - { - case ZLimbSkinType::SkinType_4: - skinSegmentStr = "&" + GetSourceOutputCodeSkin_Type_4(prefix); - break; - case ZLimbSkinType::SkinType_DList: - skinSegmentStr = GetLimbDListSourceOutputCode(prefix, "Skin", skinSegment); - break; - default: - fprintf(stderr, - "ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Unknown segment type " - "for SkinLimb: '%i'. \n\tPlease report this.\n", - name.c_str(), static_cast<int32_t>(skinSegmentType)); - break; - case ZLimbSkinType::SkinType_0: - case ZLimbSkinType::SkinType_5: - fprintf(stderr, - "ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Segment type for " - "SkinLimb not implemented: '%i'.\n", - name.c_str(), static_cast<int32_t>(skinSegmentType)); - skinSegmentStr = StringHelper::Sprintf("0x%08X", skinSegment); - break; - } - } - - std::string entryStr = - StringHelper::Sprintf(" 0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str()); - - return entryStr; + std::string dListStr = + StringHelper::Sprintf("%s%sDL_%06X", prefix.c_str(), limbSuffix.c_str(), dlistOffset); + dlist->SetName(dListStr); + dlist->DeclareVar(prefix, ""); + parent->AddResource(dlist); } |
