From e0cc88e760322823cd1cbe44612ac82059d43fd7 Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Thu, 17 Aug 2023 02:47:21 -0600 Subject: [PATCH] Fixed empty files and otr generation --- src/Companion.cpp | 8 ++++++-- src/factories/RawFactory.h | 2 +- src/factories/TextureFactory.cpp | 12 ++++++------ src/factories/TextureFactory.h | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Companion.cpp b/src/Companion.cpp index a5fcb1b..2391ae2 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -48,10 +48,14 @@ void Companion::ProcessAssets() { { "path", path }, { "offsets", data } }; - gFactories.at(extension)->process(&write, entry, this->gRomData); + if(!gFactories.at(extension)->process(&write, entry, this->gRomData)){ + std::cout << "Failed to process " << asset << '\n'; + continue; + } auto buffer = write.ToVector(); - wrapper.CreateFile(path, buffer); + // TODO: Change this that we all know its going to crash with other assets + wrapper.CreateFile(path.substr(0, path.find_last_of('.')), buffer); write.Close(); } diff --git a/src/factories/RawFactory.h b/src/factories/RawFactory.h index 1a1c363..05909fb 100644 --- a/src/factories/RawFactory.h +++ b/src/factories/RawFactory.h @@ -15,6 +15,6 @@ class RawFactory { public: RawFactory() = default; - virtual void process(LUS::BinaryWriter* write, nlohmann::json& data, std::vector& buffer) = 0; + virtual bool process(LUS::BinaryWriter* write, nlohmann::json& data, std::vector& buffer) = 0; void WriteHeader(LUS::BinaryWriter* write, LUS::ResourceType resType, int32_t version); }; \ No newline at end of file diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index 1a4c597..8bacc2f 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -29,35 +29,34 @@ static const std::unordered_map gTextureTypes = { { ".ia16", TextureType::GrayscaleAlpha16bpp }, }; -void TextureFactory::process(LUS::BinaryWriter* writer, nlohmann::json& data, std::vector& buffer) { +bool TextureFactory::process(LUS::BinaryWriter* writer, nlohmann::json& data, std::vector& buffer) { std::string path = data["path"]; std::string ext = fs::path(path).extension().string(); bool isTileTexture = path.find("cake") != std::string::npos || path.find("skyboxes") != std::string::npos; if(isTileTexture) { - return; + return false; } if(!gTextureTypes.contains(ext)) { - throw std::runtime_error("Invalid texture type: " + ext); + return false; } auto metadata = data["offsets"]; if(!metadata[3].contains("us")){ - return; + return false; } // Path: [Width, Height, Size, { Country : [Rom Offset, MIO0 Size] }], TextureType type = isTileTexture ? TextureType::RGBA32bpp : gTextureTypes.at(ext); - WRITE_HEADER(LUS::ResourceType::Texture, 1); + WRITE_HEADER(LUS::ResourceType::Texture, 0); WRITE_U32(type); // Texture Type WRITE_U32(metadata[0]); // Width WRITE_U32(metadata[1]); // Height - size_t size = metadata[2]; auto offsets = metadata[3]["us"]; @@ -75,4 +74,5 @@ void TextureFactory::process(LUS::BinaryWriter* writer, nlohmann::json& data, st delete[] texture; std::cout << "Processed " << path << '\n'; + return true; } \ No newline at end of file diff --git a/src/factories/TextureFactory.h b/src/factories/TextureFactory.h index 7d78259..88ebbdf 100644 --- a/src/factories/TextureFactory.h +++ b/src/factories/TextureFactory.h @@ -5,5 +5,5 @@ class TextureFactory : public RawFactory { public: TextureFactory() = default; - void process(LUS::BinaryWriter* write, nlohmann::json& data, std::vector& buffer) override; + bool process(LUS::BinaryWriter* write, nlohmann::json& data, std::vector& buffer) override; }; \ No newline at end of file