mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 00:27:42 +00:00
initial MLVL and STRG trilogy integration
This commit is contained in:
@@ -6,84 +6,100 @@ namespace Retro
|
||||
namespace DNAMP1
|
||||
{
|
||||
|
||||
const HECL::FourCC ENGLfcc("ENGL");
|
||||
const HECL::FourCC FRENfcc("FREN");
|
||||
const HECL::FourCC GERMfcc("GERM");
|
||||
const HECL::FourCC SPANfcc("SPAN");
|
||||
const HECL::FourCC ITALfcc("ITAL");
|
||||
const HECL::FourCC JAPNfcc("JAPN");
|
||||
void STRG::_read(Athena::io::IStreamReader& reader)
|
||||
{
|
||||
atUint32 langCount = reader.readUint32();
|
||||
atUint32 strCount = reader.readUint32();
|
||||
|
||||
std::vector<FourCC> readLangs;
|
||||
readLangs.reserve(langCount);
|
||||
for (atUint32 l=0 ; l<langCount ; ++l)
|
||||
{
|
||||
FourCC lang;
|
||||
lang.read(reader);
|
||||
readLangs.emplace_back(lang);
|
||||
reader.seek(4);
|
||||
}
|
||||
|
||||
langs.clear();
|
||||
langs.reserve(langCount);
|
||||
for (FourCC& lang : readLangs)
|
||||
{
|
||||
std::vector<std::wstring> strs;
|
||||
reader.seek(strCount * 4 + 4);
|
||||
for (atUint32 s=0 ; s<strCount ; ++s)
|
||||
strs.emplace_back(reader.readWString());
|
||||
langs.emplace(std::make_pair(lang, strs));
|
||||
}
|
||||
}
|
||||
|
||||
void STRG::read(Athena::io::IStreamReader& reader)
|
||||
{
|
||||
reader.setEndian(Athena::BigEndian);
|
||||
uint32_t magic = reader.readUint32();
|
||||
atUint32 magic = reader.readUint32();
|
||||
if (magic != 0x87654321)
|
||||
LogModule.report(LogVisor::FatalError, "invalid STRG magic");
|
||||
LogModule.report(LogVisor::Error, "invalid STRG magic");
|
||||
|
||||
version = reader.readUint32();
|
||||
langCount = reader.readUint32();
|
||||
strCount = reader.readUint32();
|
||||
atUint32 version = reader.readUint32();
|
||||
if (version != 0)
|
||||
LogModule.report(LogVisor::Error, "invalid STRG version");
|
||||
|
||||
langs.clear();
|
||||
langs.reserve(langCount);
|
||||
for (uint32_t l=0 ; l<langCount ; ++l)
|
||||
{
|
||||
langs.emplace_back();
|
||||
Language& lang = langs.back();
|
||||
lang.lang.read(reader);
|
||||
reader.readUint32();
|
||||
}
|
||||
|
||||
for (uint32_t l=0 ; l<langCount ; ++l)
|
||||
{
|
||||
Language& lang = langs[l];
|
||||
reader.readUint32();
|
||||
for (uint32_t s=0 ; s<strCount ; ++s)
|
||||
reader.readUint32();
|
||||
for (uint32_t s=0 ; s<strCount ; ++s)
|
||||
lang.strings.push_back(reader.readWString());
|
||||
}
|
||||
_read(reader);
|
||||
}
|
||||
|
||||
void STRG::write(Athena::io::IStreamWriter& writer) const
|
||||
{
|
||||
writer.setEndian(Athena::BigEndian);
|
||||
writer.writeUint32(0x87654321);
|
||||
writer.writeUint32(version);
|
||||
writer.writeUint32(0);
|
||||
writer.writeUint32(langs.size());
|
||||
atUint32 strCount = STRG::count();
|
||||
writer.writeUint32(strCount);
|
||||
|
||||
uint32_t offset = 0;
|
||||
for (const Language& lang : langs)
|
||||
atUint32 offset = 0;
|
||||
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
|
||||
{
|
||||
lang.lang.write(writer);
|
||||
lang.first.write(writer);
|
||||
writer.writeUint32(offset);
|
||||
offset += strCount * 4 + 4;
|
||||
for (uint32_t s=0 ; s<strCount ; ++s)
|
||||
atUint32 langStrCount = lang.second.size();
|
||||
for (atUint32 s=0 ; s<strCount ; ++s)
|
||||
{
|
||||
if (s < lang.strings.size())
|
||||
offset += lang.strings[s].size() * 2 + 1;
|
||||
atUint32 chCount = lang.second[s].size();
|
||||
if (s < langStrCount)
|
||||
offset += chCount * 2 + 1;
|
||||
else
|
||||
offset += 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (const Language& lang : langs)
|
||||
for (const std::pair<FourCC, std::vector<std::wstring>>& lang : langs)
|
||||
{
|
||||
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;
|
||||
}
|
||||
writer.writeUint32(tableSz);
|
||||
|
||||
offset = strCount * 4;
|
||||
for (uint32_t s=0 ; s<strCount ; ++s)
|
||||
for (atUint32 s=0 ; s<strCount ; ++s)
|
||||
{
|
||||
writer.writeUint32(offset);
|
||||
if (s < lang.strings.size())
|
||||
offset += lang.strings[s].size() * 2 + 1;
|
||||
if (s < langStrCount)
|
||||
offset += lang.second[s].size() * 2 + 1;
|
||||
else
|
||||
offset += 1;
|
||||
}
|
||||
|
||||
for (uint32_t s=0 ; s<strCount ; ++s)
|
||||
for (atUint32 s=0 ; s<strCount ; ++s)
|
||||
{
|
||||
if (s < lang.strings.size())
|
||||
writer.writeWString(lang.strings[s]);
|
||||
if (s < langStrCount)
|
||||
writer.writeWString(lang.second[s]);
|
||||
else
|
||||
writer.writeUByte(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user