diff options
| author | Lywx <kiritodev01@gmail.com> | 2023-11-15 15:11:15 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-15 15:11:15 -0600 |
| commit | eaddecd0b402c12a780831e3139d7a35e78322e6 (patch) | |
| tree | 0c961e1ba2339f52892b54f44b8ff0018b77c382 /src/factories/BlobFactory.cpp | |
| parent | a66b259d7c10c3367a04819c6b55d47fb9a99f5e (diff) | |
Torch v0.1 (#12)
* Splitted version yamls and implemented wip geo and dlist extraction
* Fixed linux compilation
* Added PoC WSL 2 detection
* Add undefined behaviour
* Added gfxdis as submodule
* update
* Removed gfxdis as a submodule
* Code works
* Replace ByteSwap with BSWAP
* Cleanup vertice factory
* readability
* readability 2
* Cleanup gfxfactory
* last one
* Rename name to symbol
* More implementation
* Implemented first PoC of C file generation
* Added output formatting on factories
* changes
* Moved generated dlists onto their respective folder
* Migrated more factories onto the new extractor system
* Fully ported all factories and added header generation
* Some updates
* Added Lights factory
* fix
* Fixed vtx extraction
* Lights work now
* delete old startup_logo yaml
* Generate all sections in single file
* Added support to generate header and code for textures
* Added O3 for release builds
* Added WIP dlist extraction and moved to use f3dold microcode
* Added segment support, autogeneration and fixed C generation
* Added symbol names on display list extraction
* Removed warnings
* Moved back to transform and replace
* Removed unnecesary macros
* Added extraction order and reversed vtx order
* Implemented true backwards sort
* [WIP] Implemented runtime gbi, more headers and a few config features
* Fix CLI11 on WSL and variety of fixes
* Fixes
* Update DisplayListFactory.h
* Update TextureFactory.cpp
* wip lights
* fix
* Correct callback
* Added waypoints
* Update ceremony_data.yml
* Changes
* Update TextureFactory.cpp
* Update commandline args
* Update comment
* Remove printf
* Update couple commands
* Renamed cubeos to torch
* Removed unused stuff and added an example config file
---------
Co-authored-by: KiritoDv <kiritodev01@gmail.com>
Co-authored-by: MegaMech <MegaMech@users.noreply.github.com>
Diffstat (limited to 'src/factories/BlobFactory.cpp')
| -rw-r--r-- | src/factories/BlobFactory.cpp | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/src/factories/BlobFactory.cpp b/src/factories/BlobFactory.cpp index cc66463..886a206 100644 --- a/src/factories/BlobFactory.cpp +++ b/src/factories/BlobFactory.cpp @@ -1,28 +1,43 @@ #include "BlobFactory.h" -#include <cstring> #include "utils/MIODecoder.h" +#include <iomanip> -namespace fs = std::filesystem; +void BlobCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + auto data = std::static_pointer_cast<RawBuffer>(raw)->mBuffer; -bool BlobFactory::process(LUS::BinaryWriter* writer, YAML::Node& data, std::vector<uint8_t>& buffer) { + write << "u8 " << entryName << "[] = {\n" << tab; + for (int i = 0; i < data.size(); i++) { + if ((i % 15 == 0) && i != 0) { + write << "\n" << tab; + } - WRITE_HEADER(LUS::ResourceType::Blob, 0); + write << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int) data[i] << ", "; + } + write << "\n};\n"; +} + +void BlobBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { + auto writer = LUS::BinaryWriter(); + auto data = std::static_pointer_cast<RawBuffer>(raw)->mBuffer; + + WriteHeader(writer, LUS::ResourceType::Blob, 0); + writer.Write((uint32_t) data.size()); + writer.Write((char*) data.data(), data.size()); + writer.Finish(write); +} - auto size = data["size"].as<size_t>(); - auto offset = data["offset"].as<size_t>(); +std::optional<std::shared_ptr<IParsedData>> BlobFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) { + auto size = data["size"].as<uint32_t>(); + auto offset = data["offset"].as<uint32_t>(); + std::shared_ptr<RawBuffer> result; - auto* blob = new uint8_t[size]; if(data["mio0"]){ auto decoded = MIO0Decoder::Decode(buffer, offset); - auto cursor = data["mio0"].as<size_t>(); - memcpy(blob, decoded.data() + cursor, size); + auto cursor = data["mio0"].as<uint32_t>(); + result = std::make_shared<RawBuffer>(decoded.data() + cursor, size); } else { - memcpy(blob, buffer.data() + offset, size); + result = std::make_shared<RawBuffer>(buffer.data() + offset, size); } - WRITE_U32(size); // Blob Data Size - WRITE_ARRAY(blob, size); // Blob Data - - delete[] blob; - return true; -} + return result; +}
\ No newline at end of file |
