#include "STRG.hpp" #include "DNAMP3.hpp" namespace Retro { namespace DNAMP3 { void STRG::_read(Athena::io::IStreamReader& reader) { atUint32 langCount = reader.readUint32(); atUint32 strCount = reader.readUint32(); atUint32 nameCount = reader.readUint32(); atUint32 nameTableSz = reader.readUint32(); if (nameTableSz) { std::unique_ptr nameTableBuf(new uint8_t[nameTableSz]); reader.readUBytesToBuf(nameTableBuf.get(), nameTableSz); struct NameIdxEntry { atUint32 nameOff; atUint32 strIdx; }* nameIndex = (NameIdxEntry*)nameTableBuf.get(); for (atUint32 n=0 ; n readLangs; readLangs.reserve(langCount); for (atUint32 l=0 ; l strOffs(new atUint32[langCount * strCount]); for (atUint32 l=0 ; l strs; for (atUint32 s=0 ; s>& item : langs) langMap.emplace(item.first, &item.second); } void STRG::read(Athena::io::IStreamReader& reader) { reader.setEndian(Athena::BigEndian); atUint32 magic = reader.readUint32(); if (magic != 0x87654321) { Log.report(LogVisor::Error, "invalid STRG magic"); return; } atUint32 version = reader.readUint32(); if (version != 3) { Log.report(LogVisor::Error, "invalid STRG version"); return; } _read(reader); } void STRG::write(Athena::io::IStreamWriter& writer) const { writer.setEndian(Athena::BigEndian); writer.writeUint32(0x87654321); writer.writeUint32(3); writer.writeUint32(langs.size()); atUint32 strCount = STRG::count(); writer.writeUint32(strCount); atUint32 nameTableSz = names.size() * 8; for (const auto& name : names) nameTableSz += name.first.size() + 1; writer.writeUint32(names.size()); writer.writeUint32(nameTableSz); atUint32 offset = names.size() * 8; for (const auto& name : names) { writer.writeUint32(offset); writer.writeInt32(name.second); offset += name.first.size() + 1; } for (const auto& name : names) writer.writeString(name.first); for (const auto& lang : langs) lang.first.write(writer); offset = 0; for (const auto& lang : langs) { atUint32 langSz = 0; for (const std::string& str : lang.second) langSz += str.size() + 5; writer.writeUint32(langSz); for (const std::string& str : lang.second) { writer.writeUint32(offset); offset += str.size() + 5; } } for (atUint32 s=0 ; s= lang.second.size()) { writer.writeUint32(1); writer.writeUByte(0); } else { const std::string& str = lang.second[s]; writer.writeUint32(str.size() + 1); writer.writeString(str); } } } } bool STRG::readAngelScript(const AngelScript::asIScriptModule& in) { } void STRG::writeAngelScript(std::ofstream& out) const { for (const std::pair>& lang : langs) { out << "STRG::Language " << lang.first.toString() << "({"; bool comma = false; unsigned idx = 0; for (const std::string& str : lang.second) { if (comma) out << ","; out << "\n/* " << idx++ << " */ \""; out << str << "\""; comma = true; } out << "\n});\n"; } out << "STRG::Names NAMES({"; bool comma = false; for (const std::pair& name : names) { if (comma) out << ","; out << "\n "; comma = true; out << "{\"" << name.first << "\", " << name.second << "}"; } out << "\n});\n"; } } }