#include "STRG.hpp" #include "DNAMP2.hpp" namespace Retro { namespace DNAMP2 { void STRG::_read(Athena::io::IStreamReader& reader) { atUint32 langCount = reader.readUint32(); atUint32 strCount = reader.readUint32(); std::vector readLangs; readLangs.reserve(langCount); for (atUint32 l=0 ; l 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 strs; reader.seek(strCount * 4); 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"); atUint32 version = reader.readUint32(); if (version != 1) Log.report(LogVisor::Error, "invalid STRG version"); _read(reader); } void STRG::write(Athena::io::IStreamWriter& writer) const { writer.setEndian(Athena::BigEndian); writer.writeUint32(0x87654321); writer.writeUint32(1); writer.writeUint32(langs.size()); atUint32 strCount = STRG::count(); writer.writeUint32(strCount); atUint32 offset = 0; for (const std::pair>& lang : langs) { lang.first.write(writer); writer.writeUint32(offset); offset += strCount * 4 + 4; atUint32 langStrCount = lang.second.size(); atUint32 tableSz = strCount * 4; for (atUint32 s=0 ; s& name : names) nameTableSz += name.first.size() + 1; writer.writeUint32(names.size()); writer.writeUint32(nameTableSz); offset = names.size() * 8; for (const std::pair& name : names) { writer.writeUint32(offset); writer.writeInt32(name.second); offset += name.first.size() + 1; } for (const std::pair& name : names) writer.writeString(name.first); for (const std::pair>& lang : langs) { offset = strCount * 4; atUint32 langStrCount = lang.second.size(); for (atUint32 s=0 ; s> wconv; for (const std::pair>& lang : langs) { out << "STRG::Language " << lang.first.toString() << "({"; bool comma = false; unsigned idx = 0; for (const std::wstring& str : lang.second) { if (comma) out << ","; out << "\n/* " << idx++ << " */ \""; out << wconv.to_bytes(str); out << "\""; 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"; } } }