mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Removed header, values and indices with just offset
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user