diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2024-04-02 08:32:39 -0600 |
|---|---|---|
| committer | Lywx <kiritodev01@gmail.com> | 2024-04-02 09:00:56 -0600 |
| commit | 3eebd9d5aaeef4adfa62d95cd6f4f60b917a48c2 (patch) | |
| tree | f6bf05a1e5a81bf254662484ada4ee90d4f1c3e9 /src | |
| parent | 4e53fac09cd92ddad447d4f73dc828d90537622d (diff) | |
Removed header, values and indices with just offset
Diffstat (limited to 'src')
| -rw-r--r-- | src/factories/sm64/AnimationFactory.cpp | 23 | ||||
| -rw-r--r-- | src/utils/Decompressor.cpp | 7 | ||||
| -rw-r--r-- | src/utils/Decompressor.h | 6 |
3 files changed, 25 insertions, 11 deletions
diff --git a/src/factories/sm64/AnimationFactory.cpp b/src/factories/sm64/AnimationFactory.cpp index 1b4070d..690263d 100644 --- a/src/factories/sm64/AnimationFactory.cpp +++ b/src/factories/sm64/AnimationFactory.cpp @@ -1,5 +1,8 @@ #include "AnimationFactory.h" #include "spdlog/spdlog.h" +#include <Decompressor.h> + +#define ANIMINDEX_COUNT(boneCount) (sizeof(boneCount) + 1) * 6 * sizeof(uint16_t) ExportResult SM64::AnimationBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { auto writer = LUS::BinaryWriter(); @@ -29,11 +32,9 @@ ExportResult SM64::AnimationBinaryExporter::Export(std::ostream &write, std::sha } std::optional<std::shared_ptr<IParsedData>> SM64::AnimationFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) { - auto headerNode = GetSafeNode<YAML::Node>(node, "header"); - auto valuesNode = GetSafeNode<YAML::Node>(node, "values"); - auto indexNode = GetSafeNode<YAML::Node>(node, "indices"); + auto offset = node["offset"]; - LUS::BinaryReader header(reinterpret_cast<char *>(buffer.data()) + GetSafeNode<uint32_t>(headerNode, "offset"), GetSafeNode<uint32_t>(headerNode, "size")); + LUS::BinaryReader header = Decompressor::AutoDecode(node, buffer).GetReader(); header.SetEndianness(LUS::Endianness::Big); auto flags = header.ReadInt16(); @@ -42,23 +43,23 @@ std::optional<std::shared_ptr<IParsedData>> SM64::AnimationFactory::parse(std::v auto loopStart = header.ReadInt16(); auto loopEnd = header.ReadInt16(); auto unusedBoneCount = header.ReadInt16(); - header.ReadUInt32(); - header.ReadUInt32(); + auto valuesAddr = header.ReadUInt32(); + auto indexAddr = header.ReadUInt32(); auto length = header.ReadUInt32(); - LUS::BinaryReader indices(reinterpret_cast<char*>(buffer.data()) + GetSafeNode<uint32_t>(indexNode, "offset"), GetSafeNode<uint32_t>(indexNode, "size")); + size_t indexLength = ANIMINDEX_COUNT(unusedBoneCount); + LUS::BinaryReader indices = Decompressor::AutoDecode(indexAddr, indexLength * sizeof(uint16_t), buffer).GetReader(); indices.SetEndianness(LUS::Endianness::Big); - size_t indexLength = GetSafeNode<uint32_t>(indexNode, "size") / sizeof(int16_t); std::vector<int16_t> indicesData; for (size_t i = 0; i < indexLength; i++) { indicesData.push_back(indices.ReadInt16()); } - LUS::BinaryReader values(reinterpret_cast<char*>(buffer.data()) + GetSafeNode<uint32_t>(valuesNode, "offset"), GetSafeNode<uint32_t>(valuesNode, "size")); + size_t valuesSize = (indexAddr - valuesAddr); + LUS::BinaryReader values = Decompressor::AutoDecode(valuesAddr, valuesSize, buffer).GetReader(); values.SetEndianness(LUS::Endianness::Big); - size_t entries = GetSafeNode<uint32_t>(valuesNode, "size") / sizeof(uint16_t); std::vector<uint16_t> valuesData; - for (size_t i = 0; i < entries; i++) { + for (size_t i = 0; i < valuesSize / sizeof(uint16_t); i++) { valuesData.push_back(values.ReadUInt16()); } diff --git a/src/utils/Decompressor.cpp b/src/utils/Decompressor.cpp index 0fc806e..9570ab3 100644 --- a/src/utils/Decompressor.cpp +++ b/src/utils/Decompressor.cpp @@ -78,6 +78,13 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t> throw std::runtime_error("Auto decode could not find a compression type nor uncompressed segment.\nThis is one of those issues that should never really happen."); } +DecompressedData Decompressor::AutoDecode(uint32_t offset, std::optional<size_t> size, std::vector<uint8_t>& buffer) { + YAML::Node node; + node["offset"] = offset; + + return AutoDecode(node, buffer, size); +} + uint32_t Decompressor::TranslateAddr(uint32_t addr, bool baseAddress){ if(IS_SEGMENTED(addr)){ const auto segment = Companion::Instance->GetFileOffsetFromSegmentedAddr(SEGMENT_NUMBER(addr)); diff --git a/src/utils/Decompressor.h b/src/utils/Decompressor.h index 0cb5a01..d7671a4 100644 --- a/src/utils/Decompressor.h +++ b/src/utils/Decompressor.h @@ -6,6 +6,7 @@ #include <yaml-cpp/yaml.h> #include <optional> #include <cstdint> +#include "BinaryReader.h" enum class CompressionType { None, @@ -23,12 +24,17 @@ struct DataChunk { struct DecompressedData { DataChunk* root; DataChunk segment; + + LUS::BinaryReader GetReader() { + return LUS::BinaryReader(reinterpret_cast<char*>(segment.data), segment.size); + } }; class Decompressor { public: static DataChunk* Decode(const std::vector<uint8_t>& buffer, uint32_t offset, CompressionType type); static DecompressedData AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer, std::optional<size_t> size = std::nullopt); + static DecompressedData AutoDecode(uint32_t offset, std::optional<size_t> size, std::vector<uint8_t>& buffer); static uint32_t TranslateAddr(uint32_t addr, bool baseAddress = false); static bool IsSegmented(uint32_t addr); |
