diff options
| author | Anghelo Carvajal <angheloalf95@gmail.com> | 2022-01-11 21:55:18 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-11 19:55:18 -0500 |
| commit | bf16ff7c4c409358a53793b72260b1d8e474cf0c (patch) | |
| tree | fa4d2d0169b5485f990112642df9b57b388af14b | |
| parent | 16b53763423c6830a6fecef5579a2013c54abbd1 (diff) | |
ZPointer (#232)
* ZPointer
* Add docs
* format
* jenkins file for mm
* whoops
* Rewrite as a switch
* a
| -rw-r--r-- | ZAPD/ZArray.cpp | 13 | ||||
| -rw-r--r-- | ZAPD/ZPointer.cpp | 57 | ||||
| -rw-r--r-- | ZAPD/ZPointer.h | 22 | ||||
| -rw-r--r-- | ZAPD/ZResource.h | 1 | ||||
| -rw-r--r-- | docs/zapd_extraction_xml_reference.md | 25 |
5 files changed, 114 insertions, 4 deletions
diff --git a/ZAPD/ZArray.cpp b/ZAPD/ZArray.cpp index ebfb13e..b6d9e50 100644 --- a/ZAPD/ZArray.cpp +++ b/ZAPD/ZArray.cpp @@ -101,11 +101,18 @@ std::string ZArray::GetBodySourceCode() const const auto& res = resList[i]; output += "\t"; - if (res->GetResourceType() == ZResourceType::Scalar || - res->GetResourceType() == ZResourceType::Vertex) + switch (res->GetResourceType()) + { + case ZResourceType::Pointer: + case ZResourceType::Scalar: + case ZResourceType::Vertex: output += resList.at(i)->GetBodySourceCode(); - else + break; + + default: output += StringHelper::Sprintf("{ %s }", resList.at(i)->GetBodySourceCode().c_str()); + break; + } if (i < arrayCnt - 1 || res->IsExternalResource()) output += ",\n"; diff --git a/ZAPD/ZPointer.cpp b/ZAPD/ZPointer.cpp new file mode 100644 index 0000000..6e6945c --- /dev/null +++ b/ZAPD/ZPointer.cpp @@ -0,0 +1,57 @@ +#include "ZPointer.h" + +#include "Globals.h" +#include "Utils/BitConverter.h" +#include "Utils/StringHelper.h" +#include "WarningHandler.h" +#include "ZFile.h" + +REGISTER_ZFILENODE(Pointer, ZPointer); + +ZPointer::ZPointer(ZFile* nParent) : ZResource(nParent) +{ + RegisterRequiredAttribute("Type"); +} + +void ZPointer::ParseXML(tinyxml2::XMLElement* reader) +{ + ZResource::ParseXML(reader); + + type = registeredAttributes.at("Type").value; +} + +void ZPointer::ParseRawData() +{ + auto& rawData = parent->GetRawData(); + + ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex); +} + +std::string ZPointer::GetBodySourceCode() const +{ + std::string ptrName; + + Globals::Instance->GetSegmentedPtrName(ptr, parent, "", ptrName); + + return ptrName; +} + +bool ZPointer::DoesSupportArray() const +{ + return true; +} + +std::string ZPointer::GetSourceTypeName() const +{ + return type + "*"; +} + +ZResourceType ZPointer::GetResourceType() const +{ + return ZResourceType::Pointer; +} + +size_t ZPointer::GetRawDataSize() const +{ + return 0x04; +} diff --git a/ZAPD/ZPointer.h b/ZAPD/ZPointer.h new file mode 100644 index 0000000..8fb5889 --- /dev/null +++ b/ZAPD/ZPointer.h @@ -0,0 +1,22 @@ +#pragma once + +#include "ZResource.h" + +class ZPointer : public ZResource +{ +public: + segptr_t ptr = SEGMENTED_NULL; + std::string type; + + ZPointer(ZFile* nParent); + + void ParseXML(tinyxml2::XMLElement* reader) override; + void ParseRawData() override; + std::string GetBodySourceCode() const override; + + bool DoesSupportArray() const override; + std::string GetSourceTypeName() const override; + ZResourceType GetResourceType() const override; + + size_t GetRawDataSize() const override; +}; diff --git a/ZAPD/ZResource.h b/ZAPD/ZResource.h index 4dad398..c65c3c3 100644 --- a/ZAPD/ZResource.h +++ b/ZAPD/ZResource.h @@ -38,6 +38,7 @@ enum class ZResourceType Mtx, Path, PlayerAnimationData, + Pointer, Room, RoomCommand, Scalar, diff --git a/docs/zapd_extraction_xml_reference.md b/docs/zapd_extraction_xml_reference.md index 06b95bb..b3f5575 100644 --- a/docs/zapd_extraction_xml_reference.md +++ b/docs/zapd_extraction_xml_reference.md @@ -9,6 +9,7 @@ This document aims to be a small reference of how to create a compatible xml fil - [Basic XML](#basic-xml) - [Resources types](#resources-types) - [File](#file) + - [ExternalFile](#externalfile) - [Texture](#texture) - [Background](#background) - [Blob](#blob) @@ -33,6 +34,7 @@ This document aims to be a small reference of how to create a compatible xml fil - [Array](#array) - [Path](#path) - [PlayerAnimationData](#playeranimationdata) + - [Pointer](#pointer) ## Basic XML @@ -589,7 +591,7 @@ Vec3s D_04002040[24] = { The `Array` element is special, because it needs an inner element to work. It will declare an array of its inner element. -Currently, only [`Scalar`](#scalar), [`Vector`](#vector) and [`Vtx`](#vtx) support being wrapped in an array. +Currently, only [`Pointer`](#pointer), [`Scalar`](#scalar), [`Vector`](#vector) and [`Vtx`](#vtx) support being wrapped in an array. - Example: @@ -637,3 +639,24 @@ Allows the extraction of the specific data of the player animations which are fo - `FrameCount`: Required. The length of the animation in frames. It must be a positive integer. ------------------------- + +### Pointer + +Allows the extraction of a variable that contains a pointer + +- Example: + +```xml +<Array Name="object_hanareyama_obj_DLArray_004638" Count="54" Offset="0x4638"> + <Pointer Type="Gfx"/> +</Array> +``` + +- Attributes: + + - `Name`: Required. + - `Type`: Required. The type of the extracted pointer. + +※ Can be wrapped in an [`Array`](#array) tag. + +------------------------- |
