diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Companion.cpp | 35 | ||||
| -rw-r--r-- | src/Companion.h | 14 | ||||
| -rw-r--r-- | src/factories/TextureFactory.cpp | 35 |
3 files changed, 63 insertions, 21 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp index e2e6f21..0a74658 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -1171,6 +1171,37 @@ std::optional<std::tuple<std::string, YAML::Node>> Companion::GetNodeByAddr(cons return this->gAddrMap[this->gCurrentFile][addr]; } +std::optional<ParseResultData> Companion::GetParseDataByAddr(uint32_t addr) { + if(!this->gParseResults.contains(this->gCurrentFile)){ + return std::nullopt; + } + + for(auto& result : this->gParseResults[this->gCurrentFile]){ + if(result.data.has_value() && result.GetOffset() == addr){ + return result; + } + } + + return std::nullopt; +} + +std::optional<ParseResultData> Companion::GetParseDataBySymbol(const std::string& symbol) { + if(!this->gParseResults.contains(this->gCurrentFile)){ + return std::nullopt; + } + + for(auto& result : this->gParseResults[this->gCurrentFile]){ + auto sym = GetNode<std::string>(result.node, "symbol"); + + if(result.data.has_value() && sym.has_value() && sym.value() == symbol){ + return result; + } + } + + return std::nullopt; + +} + std::optional<std::vector<std::tuple<std::string, YAML::Node>>> Companion::GetNodesByType(const std::string& type){ std::vector<std::tuple<std::string, YAML::Node>> nodes; @@ -1263,8 +1294,4 @@ std::optional<YAML::Node> Companion::AddAsset(YAML::Node asset) { } return std::nullopt; -} - -void Companion::AddTlutTextureMap(std::string index, std::shared_ptr<TextureData> entry) { - this->TlutTextureMap[index] = entry; }
\ No newline at end of file diff --git a/src/Companion.h b/src/Companion.h index 88e23c8..3c58637 100644 --- a/src/Companion.h +++ b/src/Companion.h @@ -80,6 +80,14 @@ struct ParseResultData { std::string type; YAML::Node node; std::optional<std::shared_ptr<IParsedData>> data; + + uint32_t GetOffset() { + return GetSafeNode<uint32_t>(node, "offset"); + } + + std::optional<std::string> GetSymbol() { + return GetSafeNode<std::string>(node, "symbol"); + } }; class Companion { @@ -110,6 +118,9 @@ public: std::unordered_map<std::string, std::vector<YAML::Node>> GetCourseMetadata() { return this->gCourseMetadata; } std::optional<std::string> GetEnumFromValue(const std::string& key, int id); + std::optional<ParseResultData> GetParseDataByAddr(uint32_t addr); + std::optional<ParseResultData> GetParseDataBySymbol(const std::string& symbol); + std::optional<std::uint32_t> GetFileOffsetFromSegmentedAddr(uint8_t segment) const; std::optional<std::tuple<std::string, YAML::Node>> GetNodeByAddr(uint32_t addr); std::optional<std::shared_ptr<BaseFactory>> GetFactory(const std::string& type); @@ -120,8 +131,6 @@ public: CompressionType GetCurrCompressionType(void) const { return this->gCurrentCompressionType; }; CompressionType GetCompressionType(std::vector<uint8_t>& buffer, const uint32_t offset); std::optional<VRAMEntry> GetCurrentVRAM(void) const { return this->gCurrentVram; }; - std::unordered_map<std::string, std::shared_ptr<TextureData>> GetTlutTextureMap() { return this->TlutTextureMap; }; - void AddTlutTextureMap(std::string index, std::shared_ptr<TextureData> entry); std::optional<Table> SearchTable(uint32_t addr); static std::string CalculateHash(const std::vector<uint8_t>& data); @@ -167,7 +176,6 @@ private: std::unordered_map<std::string, std::map<std::string, std::vector<WriteEntry>>> gWriteMap; std::unordered_map<std::string, std::map<std::string, std::pair<YAML::Node, bool>>> gAssetDependencies; std::unordered_map<std::string, std::unordered_map<uint32_t, std::tuple<std::string, YAML::Node>>> gAddrMap; - std::unordered_map<std::string, std::shared_ptr<TextureData>> TlutTextureMap; void ParseEnums(std::string& file); void ParseHash(); diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index d2166d4..2734244 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -255,19 +255,32 @@ ExportResult TextureModdingExporter::Export(std::ostream&write, std::shared_ptr< case TextureType::Palette4bpp: { // This check needed until sf64 has tluts fixed. if (node["tlut_symbol"]) { - auto tlut = GetSafeNode<std::string>(node,"tlut_symbol"); - auto tlutTextureMap = Companion::Instance->GetTlutTextureMap(); - auto palettePtr = tlutTextureMap[tlut]; - - if (palettePtr) { - convert_raw_to_ci8(&raw, &size, texture->mBuffer.data(), (uint8_t *)palettePtr->mBuffer.data(), 0, texture->mWidth, texture->mHeight, texture->mFormat.depth, palettePtr->mFormat.depth); + auto tlut = GetSafeNode<std::string>(node,"tlut_symbol"); + auto palette = Companion::Instance->GetParseDataBySymbol(tlut); + if (palette.has_value()) { + auto palTexture = std::static_pointer_cast<TextureData>(palette.value().data.value()); + convert_raw_to_ci8(&raw, &size, texture->mBuffer.data(), (uint8_t *)palTexture->mBuffer.data(), 0, texture->mWidth, texture->mHeight, texture->mFormat.depth, palTexture->mFormat.depth); } else { auto symbol = GetSafeNode<std::string>(node, "symbol"); throw std::runtime_error("Could not convert ci8 '"+symbol+"' the tlut symbol name is probably wrong for tlut_symbol node"); } break; } + + if (node["tlut"]) { + auto tlut = GetSafeNode<uint32_t>(node,"tlut"); + auto palette = Companion::Instance->GetParseDataByAddr(tlut); + + if (palette.has_value()) { + auto palTexture = std::static_pointer_cast<TextureData>(palette.value().data.value()); + convert_raw_to_ci8(&raw, &size, texture->mBuffer.data(), (uint8_t *)palTexture->mBuffer.data(), 0, texture->mWidth, texture->mHeight, texture->mFormat.depth, palTexture->mFormat.depth); + } else { + auto symbol = GetSafeNode<std::string>(node, "symbol"); + throw std::runtime_error("Could not convert ci8 '"+symbol+"' the address is probably wrong for tlut address node"); + } + break; + } } case TextureType::Grayscale8bpp: case TextureType::Grayscale4bpp: { @@ -351,7 +364,7 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui SPDLOG_INFO("Width: {}", width); SPDLOG_INFO("Height: {}", height); } - SPDLOG_INFO("Size: {}", size); + SPDLOG_INFO("Size: {}", size); SPDLOG_INFO("Offset: 0x{:X}", offset); if(result.size() == 0){ @@ -362,12 +375,6 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse(std::vector<ui return std::nullopt; } - if (fmt.type == TextureType::TLUT) { - auto textureData = std::make_shared<TextureData>(fmt, width, height, result); - Companion::Instance->AddTlutTextureMap(symbol, textureData); - return textureData; - } - return std::make_shared<TextureData>(fmt, width, height, result); } @@ -432,7 +439,7 @@ std::optional<std::shared_ptr<IParsedData>> TextureFactory::parse_modding(std::v // todo: Add wheel palette input // Implement so that it works. - // auto tlut = GetSafeNode<std::string>(node,"tlut_symbol"); + // auto tlut = GetSafeNode<std::string>(node,"tlut_symbol"); // auto tlutTextureMap = Companion::Instance->GetTlutTextureMap(); // auto palettePtr = tlutTextureMap[tlut]; |
