2015-07-10 05:28:08 +00:00
|
|
|
#include "STRG.hpp"
|
2015-07-16 01:57:34 +00:00
|
|
|
#include "DNAMP1.hpp"
|
2015-07-10 05:28:08 +00:00
|
|
|
|
|
|
|
namespace Retro
|
|
|
|
{
|
|
|
|
namespace DNAMP1
|
|
|
|
{
|
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
void STRG::_read(Athena::io::IStreamReader& reader)
|
2015-07-10 05:28:08 +00:00
|
|
|
{
|
2015-08-14 03:00:51 +00:00
|
|
|
atUint32 langCount = reader.readUint32Big();
|
|
|
|
atUint32 strCount = reader.readUint32Big();
|
2015-07-10 05:28:08 +00:00
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
std::vector<FourCC> readLangs;
|
|
|
|
readLangs.reserve(langCount);
|
|
|
|
for (atUint32 l=0 ; l<langCount ; ++l)
|
|
|
|
{
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC lang;
|
2015-07-13 06:29:12 +00:00
|
|
|
lang.read(reader);
|
|
|
|
readLangs.emplace_back(lang);
|
|
|
|
reader.seek(4);
|
|
|
|
}
|
2015-07-10 05:28:08 +00:00
|
|
|
|
|
|
|
langs.clear();
|
|
|
|
langs.reserve(langCount);
|
2015-07-13 06:29:12 +00:00
|
|
|
for (FourCC& lang : readLangs)
|
2015-07-10 05:28:08 +00:00
|
|
|
{
|
2015-07-13 06:29:12 +00:00
|
|
|
std::vector<std::wstring> strs;
|
|
|
|
reader.seek(strCount * 4 + 4);
|
|
|
|
for (atUint32 s=0 ; s<strCount ; ++s)
|
2015-08-14 03:00:51 +00:00
|
|
|
strs.emplace_back(reader.readWStringBig());
|
2015-07-18 04:33:38 +00:00
|
|
|
langs.emplace_back(lang, strs);
|
2015-07-10 05:28:08 +00:00
|
|
|
}
|
2015-07-18 04:33:38 +00:00
|
|
|
|
|
|
|
langMap.clear();
|
|
|
|
langMap.reserve(langCount);
|
|
|
|
for (std::pair<FourCC, std::vector<std::wstring>>& item : langs)
|
|
|
|
langMap.emplace(item.first, &item.second);
|
2015-07-13 06:29:12 +00:00
|
|
|
}
|
2015-07-10 05:28:08 +00:00
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
void STRG::read(Athena::io::IStreamReader& reader)
|
|
|
|
{
|
2015-08-14 03:00:51 +00:00
|
|
|
atUint32 magic = reader.readUint32Big();
|
2015-07-13 06:29:12 +00:00
|
|
|
if (magic != 0x87654321)
|
2015-07-16 01:57:34 +00:00
|
|
|
Log.report(LogVisor::Error, "invalid STRG magic");
|
2015-07-13 06:29:12 +00:00
|
|
|
|
2015-08-14 03:00:51 +00:00
|
|
|
atUint32 version = reader.readUint32Big();
|
2015-07-13 06:29:12 +00:00
|
|
|
if (version != 0)
|
2015-07-16 01:57:34 +00:00
|
|
|
Log.report(LogVisor::Error, "invalid STRG version");
|
2015-07-13 06:29:12 +00:00
|
|
|
|
|
|
|
_read(reader);
|
2015-07-10 05:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void STRG::write(Athena::io::IStreamWriter& writer) const
|
|
|
|
{
|
2015-08-14 03:00:51 +00:00
|
|
|
writer.writeUint32Big(0x87654321);
|
|
|
|
writer.writeUint32Big(0);
|
|
|
|
writer.writeUint32Big(langs.size());
|
2015-07-13 06:29:12 +00:00
|
|
|
atUint32 strCount = STRG::count();
|
2015-08-14 03:00:51 +00:00
|
|
|
writer.writeUint32Big(strCount);
|
2015-07-10 05:28:08 +00:00
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
atUint32 offset = 0;
|
|
|
|
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
|
2015-07-10 05:28:08 +00:00
|
|
|
{
|
2015-08-23 06:42:29 +00:00
|
|
|
DNAFourCC(lang.first).write(writer);
|
2015-08-14 03:00:51 +00:00
|
|
|
writer.writeUint32Big(offset);
|
2015-07-10 05:28:08 +00:00
|
|
|
offset += strCount * 4 + 4;
|
2015-07-13 06:29:12 +00:00
|
|
|
atUint32 langStrCount = lang.second.size();
|
|
|
|
for (atUint32 s=0 ; s<strCount ; ++s)
|
2015-07-10 05:28:08 +00:00
|
|
|
{
|
2015-07-13 06:29:12 +00:00
|
|
|
atUint32 chCount = lang.second[s].size();
|
|
|
|
if (s < langStrCount)
|
|
|
|
offset += chCount * 2 + 1;
|
2015-07-10 05:28:08 +00:00
|
|
|
else
|
|
|
|
offset += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
|
2015-07-10 05:28:08 +00:00
|
|
|
{
|
2015-07-13 06:29:12 +00:00
|
|
|
atUint32 langStrCount = lang.second.size();
|
|
|
|
atUint32 tableSz = strCount * 4;
|
|
|
|
for (atUint32 s=0 ; s<strCount ; ++s)
|
|
|
|
{
|
|
|
|
if (s < langStrCount)
|
|
|
|
tableSz += lang.second[s].size() * 2 + 1;
|
|
|
|
else
|
|
|
|
tableSz += 1;
|
|
|
|
}
|
2015-08-14 03:00:51 +00:00
|
|
|
writer.writeUint32Big(tableSz);
|
2015-07-13 06:29:12 +00:00
|
|
|
|
2015-07-10 05:28:08 +00:00
|
|
|
offset = strCount * 4;
|
2015-07-13 06:29:12 +00:00
|
|
|
for (atUint32 s=0 ; s<strCount ; ++s)
|
2015-07-10 05:28:08 +00:00
|
|
|
{
|
2015-08-14 03:00:51 +00:00
|
|
|
writer.writeUint32Big(offset);
|
2015-07-13 06:29:12 +00:00
|
|
|
if (s < langStrCount)
|
|
|
|
offset += lang.second[s].size() * 2 + 1;
|
2015-07-10 05:28:08 +00:00
|
|
|
else
|
|
|
|
offset += 1;
|
|
|
|
}
|
|
|
|
|
2015-07-13 06:29:12 +00:00
|
|
|
for (atUint32 s=0 ; s<strCount ; ++s)
|
2015-07-10 05:28:08 +00:00
|
|
|
{
|
2015-07-13 06:29:12 +00:00
|
|
|
if (s < langStrCount)
|
2015-08-14 03:00:51 +00:00
|
|
|
writer.writeWStringBig(lang.second[s]);
|
2015-07-10 05:28:08 +00:00
|
|
|
else
|
|
|
|
writer.writeUByte(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-18 04:08:45 +00:00
|
|
|
size_t STRG::binarySize(size_t __isz) const
|
|
|
|
{
|
|
|
|
__isz += 16;
|
|
|
|
__isz += langs.size() * 12;
|
|
|
|
|
|
|
|
size_t strCount = STRG::count();
|
|
|
|
__isz += langs.size() * strCount * 4;
|
|
|
|
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
|
|
|
|
{
|
|
|
|
atUint32 langStrCount = lang.second.size();
|
|
|
|
for (atUint32 s=0 ; s<strCount ; ++s)
|
|
|
|
{
|
|
|
|
if (s < langStrCount)
|
|
|
|
__isz += (lang.second[s].size() + 1) * 2;
|
|
|
|
else
|
|
|
|
__isz += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return __isz;
|
|
|
|
}
|
|
|
|
|
2016-01-04 05:31:02 +00:00
|
|
|
void STRG::read(Athena::io::YAMLDocReader& reader)
|
2015-08-01 00:38:35 +00:00
|
|
|
{
|
|
|
|
const Athena::io::YAMLNode* root = reader.getRootNode();
|
|
|
|
|
|
|
|
/* Validate Pass */
|
|
|
|
if (root->m_type == YAML_MAPPING_NODE)
|
|
|
|
{
|
|
|
|
for (const auto& lang : root->m_mapChildren)
|
|
|
|
{
|
|
|
|
if (lang.first.size() != 4)
|
|
|
|
{
|
|
|
|
Log.report(LogVisor::Warning, "STRG language string '%s' must be exactly 4 characters; skipping", lang.first.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (lang.second->m_type != YAML_SEQUENCE_NODE)
|
|
|
|
{
|
|
|
|
Log.report(LogVisor::Warning, "STRG language string '%s' must contain a sequence; skipping", lang.first.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (const auto& str : lang.second->m_seqChildren)
|
|
|
|
{
|
|
|
|
if (str->m_type != YAML_SCALAR_NODE)
|
|
|
|
{
|
|
|
|
Log.report(LogVisor::Warning, "STRG language '%s' must contain all scalars; skipping", lang.first.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log.report(LogVisor::Warning, "STRG must have a mapping root node; skipping");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read Pass */
|
|
|
|
langs.clear();
|
|
|
|
for (const auto& lang : root->m_mapChildren)
|
|
|
|
{
|
|
|
|
std::vector<std::wstring> strs;
|
|
|
|
for (const auto& str : lang.second->m_seqChildren)
|
2015-08-25 07:04:50 +00:00
|
|
|
strs.emplace_back(HECL::UTF8ToWide(str->m_scalarString));
|
2015-08-01 00:38:35 +00:00
|
|
|
langs.emplace_back(FourCC(lang.first.c_str()), strs);
|
|
|
|
}
|
|
|
|
|
|
|
|
langMap.clear();
|
|
|
|
langMap.reserve(langs.size());
|
2015-08-09 03:55:11 +00:00
|
|
|
for (auto& item : langs)
|
2015-08-01 00:38:35 +00:00
|
|
|
langMap.emplace(item.first, &item.second);
|
|
|
|
}
|
|
|
|
|
2016-01-04 05:31:02 +00:00
|
|
|
void STRG::write(Athena::io::YAMLDocWriter& writer) const
|
2015-08-01 00:38:35 +00:00
|
|
|
{
|
2015-08-09 03:55:11 +00:00
|
|
|
for (const auto& lang : langs)
|
2015-08-01 00:38:35 +00:00
|
|
|
{
|
|
|
|
writer.enterSubVector(lang.first.toString().c_str());
|
|
|
|
for (const std::wstring& str : lang.second)
|
|
|
|
writer.writeWString(nullptr, str);
|
|
|
|
writer.leaveSubVector();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:40:21 +00:00
|
|
|
const char* STRG::DNAType()
|
|
|
|
{
|
|
|
|
return "Retro::DNAMP1::STRG";
|
|
|
|
}
|
|
|
|
|
2015-07-10 05:28:08 +00:00
|
|
|
}
|
|
|
|
}
|