mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Add tkmk00
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
#ifndef TKMK00_H_
|
||||
#define TKMK00_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// decode TKMK00 data in memory
|
||||
// tkmk: buffer containing TKMK00 data
|
||||
// tmp_buf: tempory buffer to load pixel data (must be >= width*height bytes)
|
||||
// rgba: buffer to output decompressed RGBA16 data (must be >= 2*width*height bytes)
|
||||
// alpha_color: RGBA color to set apha to 0
|
||||
void tkmk00_decode(const uint8_t *tkmk, uint8_t *tmp_buf, uint8_t *rgba16, int32_t alpha_color);
|
||||
|
||||
#endif // TKMK00_H_
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
extern "C" {
|
||||
#include <libmio0/mio0.h>
|
||||
#include <libmio0/tkmk00.h>
|
||||
}
|
||||
|
||||
std::unordered_map<uint32_t, DataChunk*> gCachedChunks;
|
||||
@@ -35,6 +36,23 @@ DataChunk* Decompressor::Decode(const std::vector<uint8_t>& buffer, const uint32
|
||||
}
|
||||
}
|
||||
|
||||
DataChunk* Decompressor::DecodeTKMK00(const std::vector<uint8_t>& buffer, const uint32_t offset, const uint32_t size, const uint32_t alpha) {
|
||||
|
||||
if(gCachedChunks.contains(offset)){
|
||||
return gCachedChunks[offset];
|
||||
}
|
||||
|
||||
const uint8_t* in_buf = buffer.data() + offset;
|
||||
|
||||
const auto decompressed = new uint8_t[size];
|
||||
const auto rgba = new uint8_t[size];
|
||||
SPDLOG_INFO("RUN?");
|
||||
tkmk00_decode(in_buf, decompressed, rgba, alpha);
|
||||
SPDLOG_INFO("RUN2?");
|
||||
gCachedChunks[offset] = new DataChunk{ decompressed, size };
|
||||
return gCachedChunks[offset];
|
||||
}
|
||||
|
||||
DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>& buffer, std::optional<size_t> manualSize) {
|
||||
auto offset = GetSafeNode<uint32_t>(node, "offset");
|
||||
|
||||
@@ -58,6 +76,26 @@ DecompressedData Decompressor::AutoDecode(YAML::Node& node, std::vector<uint8_t>
|
||||
};
|
||||
}
|
||||
|
||||
// Extract compressed tkmk00 assets in mk64.
|
||||
if (node["tkmk00"]) {
|
||||
const auto alpha = GetSafeNode<uint32_t>(node, "alpha");
|
||||
const auto width = GetSafeNode<uint32_t>(node, "width");
|
||||
const auto height = GetSafeNode<uint32_t>(node, "height");
|
||||
const auto textureSize = width * height * 2;
|
||||
auto assetPtr = ASSET_PTR(offset);
|
||||
auto gameSize = Companion::Instance->GetRomData().size();
|
||||
|
||||
auto fileOffset = TranslateAddr(offset, true);
|
||||
offset = ASSET_PTR(offset);
|
||||
|
||||
auto decoded = DecodeTKMK00(buffer, fileOffset + offset, textureSize, alpha);
|
||||
auto size = node["size"] ? node["size"].as<size_t>() : manualSize.value_or(decoded->size);
|
||||
return {
|
||||
.root = decoded,
|
||||
.segment = { decoded->data, size }
|
||||
};
|
||||
}
|
||||
|
||||
// Extract compressed files that contain many assets.
|
||||
switch(type) {
|
||||
case CompressionType::MIO0:
|
||||
|
||||
@@ -33,6 +33,7 @@ struct DecompressedData {
|
||||
class Decompressor {
|
||||
public:
|
||||
static DataChunk* Decode(const std::vector<uint8_t>& buffer, uint32_t offset, CompressionType type);
|
||||
static DataChunk* DecodeTKMK00(const std::vector<uint8_t>& buffer, const uint32_t offset, const uint32_t size, const uint32_t alpha);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user