Fixed empty files and otr generation

This commit is contained in:
KiritoDv
2023-08-17 02:47:21 -06:00
parent 1c5b3de55c
commit e0cc88e760
4 changed files with 14 additions and 10 deletions
+6 -2
View File
@@ -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();
}
+1 -1
View File
@@ -15,6 +15,6 @@
class RawFactory {
public:
RawFactory() = default;
virtual void process(LUS::BinaryWriter* write, nlohmann::json& data, std::vector<uint8_t>& buffer) = 0;
virtual bool process(LUS::BinaryWriter* write, nlohmann::json& data, std::vector<uint8_t>& buffer) = 0;
void WriteHeader(LUS::BinaryWriter* write, LUS::ResourceType resType, int32_t version);
};
+6 -6
View File
@@ -29,35 +29,34 @@ static const std::unordered_map <std::string, TextureType> gTextureTypes = {
{ ".ia16", TextureType::GrayscaleAlpha16bpp },
};
void TextureFactory::process(LUS::BinaryWriter* writer, nlohmann::json& data, std::vector<uint8_t>& buffer) {
bool TextureFactory::process(LUS::BinaryWriter* writer, nlohmann::json& data, std::vector<uint8_t>& 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;
}
+1 -1
View File
@@ -5,5 +5,5 @@
class TextureFactory : public RawFactory {
public:
TextureFactory() = default;
void process(LUS::BinaryWriter* write, nlohmann::json& data, std::vector<uint8_t>& buffer) override;
bool process(LUS::BinaryWriter* write, nlohmann::json& data, std::vector<uint8_t>& buffer) override;
};