diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2023-08-19 23:55:59 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2023-08-19 23:55:59 -0600 |
| commit | 15a0cf5498b60fa1442d049dbe5bb856022b5641 (patch) | |
| tree | 16299bd2cb1613297ffdc99ba0a992ebdd2aeac0 /src | |
| parent | f3402d8c9fe789d3f8a43edbd2a07e06b17a292b (diff) | |
Added support to extract skyboxes and cake
Diffstat (limited to 'src')
| -rw-r--r-- | src/Companion.cpp | 24 | ||||
| -rw-r--r-- | src/factories/BlobFactory.cpp | 34 | ||||
| -rw-r--r-- | src/factories/BlobFactory.h | 12 | ||||
| -rw-r--r-- | src/factories/ResourceType.h | 4 |
4 files changed, 71 insertions, 3 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp index 2391ae2..9b38118 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -3,6 +3,7 @@ #include "storm/SWrapper.h" #include "utils/MIODecoder.h" #include "factories/RawFactory.h" +#include "factories/BlobFactory.h" #include "factories/TextureFactory.h" #include <fstream> @@ -14,7 +15,9 @@ using json = nlohmann::json; namespace fs = std::filesystem; static const std::unordered_map<std::string, RawFactory*> gFactories = { - { ".png", new TextureFactory() } + { ".png", new TextureFactory() }, + { ".bin", new BlobFactory(LUS::ResourceType::Blob) }, + { ".sbox", new BlobFactory(LUS::ResourceType::Blob, true) }, }; void Companion::Start() { @@ -48,14 +51,29 @@ void Companion::ProcessAssets() { { "path", path }, { "offsets", data } }; - if(!gFactories.at(extension)->process(&write, entry, this->gRomData)){ + RawFactory* factory = gFactories.at(extension); + + if(!factory->process(&write, entry, this->gRomData)){ std::cout << "Failed to process " << asset << '\n'; continue; } + std::cout << "Processed " << path << std::endl; + bool isTexture = typeid(*factory) == typeid(TextureFactory); + auto buffer = write.ToVector(); // TODO: Change this that we all know its going to crash with other assets - wrapper.CreateFile(path.substr(0, path.find_last_of('.')), buffer); + wrapper.CreateFile(isTexture ? path.substr(0, path.find_last_of('.')) : path, buffer); + + if(!isTexture) { + // Write to file too + std::string dpath = "debug/" + path; + fs::create_directories(fs::path(dpath).parent_path()); + std::ofstream output(dpath, std::ios::binary); + output.write((char*)buffer.data(), buffer.size()); + output.close(); + } + write.Close(); } diff --git a/src/factories/BlobFactory.cpp b/src/factories/BlobFactory.cpp new file mode 100644 index 0000000..c9e52a9 --- /dev/null +++ b/src/factories/BlobFactory.cpp @@ -0,0 +1,34 @@ +#include "BlobFactory.h" + +#include <iostream> +#include <filesystem> +#include "Companion.h" +#include "utils/MIODecoder.h" + +namespace fs = std::filesystem; + +bool BlobFactory::process(LUS::BinaryWriter* writer, nlohmann::json& data, std::vector<uint8_t>& buffer) { + auto metadata = data["offsets"]; + if(!metadata[1].contains("us")){ + return false; + } + + WRITE_HEADER(this->type, 0); + + size_t size = metadata[0]; + auto offsets = metadata[1]["us"]; + + auto* blob = new uint8_t[size]; + if(this->isMIOChunk){ + auto mio0 = MIO0Decoder::Decode(buffer, offsets[0]); + memcpy(blob, mio0.data() + offsets[1], size); + } else { + memcpy(blob, buffer.data() + offsets[0], size); + } + + WRITE_U32(size); // Blob Data Size + WRITE_ARRAY(blob, size); // Blob Data + + delete[] blob; + return true; +}
\ No newline at end of file diff --git a/src/factories/BlobFactory.h b/src/factories/BlobFactory.h new file mode 100644 index 0000000..0f80c1d --- /dev/null +++ b/src/factories/BlobFactory.h @@ -0,0 +1,12 @@ +#pragma once + +#include "RawFactory.h" + +class BlobFactory : public RawFactory { +public: + BlobFactory(LUS::ResourceType type, bool isMIOChunk = false) : type(type), isMIOChunk(isMIOChunk) {} + bool process(LUS::BinaryWriter* write, nlohmann::json& data, std::vector<uint8_t>& buffer) override; +private: + bool isMIOChunk = false; + LUS::ResourceType type = LUS::ResourceType::Blob; +};
\ No newline at end of file diff --git a/src/factories/ResourceType.h b/src/factories/ResourceType.h index 5f77721..202e732 100644 --- a/src/factories/ResourceType.h +++ b/src/factories/ResourceType.h @@ -14,5 +14,9 @@ enum class ResourceType { Array = 0x4F415252, // OARR Blob = 0x4F424C42, // OBLB Texture = 0x4F544558, // OTEX + + // CubeOS + Demo = 0x44454D4F, // DEMO + Skybox = 0x534B5942, // SKYB }; } // namespace LUS |
