#include "DictionaryFactory.h" #include "spdlog/spdlog.h" ExportResult SM64::DictionaryBinaryExporter::Export(std::ostream& write, std::shared_ptr raw, std::string& entryName, YAML::Node& node, std::string* replacement) { auto writer = LUS::BinaryWriter(); const auto data = std::static_pointer_cast(raw); WriteHeader(writer, Torch::ResourceType::Dictionary, 0); writer.Write(static_cast(data->mDictionary.size())); for (auto& [key, value] : data->mDictionary) { writer.Write(key); writer.Write(static_cast(value.size())); writer.Write(reinterpret_cast(value.data()), value.size()); } writer.Finish(write); return std::nullopt; } std::optional> SM64::DictionaryFactory::parse(std::vector& buffer, YAML::Node& data) { std::unordered_map> dictionary; for (auto it = data["keys"].begin(); it != data["keys"].end(); ++it) { auto key = it->first.as(); auto offset = it->second.as(); std::vector text; const auto bytes = buffer.data(); while (bytes[offset] != 0xFF) { auto c = bytes[offset++]; text.push_back(c); } text.push_back(0xFF); dictionary[key] = text; SPDLOG_INFO("Found key: {} at offset {}", key, offset); } return std::make_shared(dictionary); }