This commit is contained in:
Jack Andersen 2016-08-16 20:18:57 -10:00
commit e401a497ef
5 changed files with 71 additions and 16 deletions

View File

@ -6,30 +6,51 @@ namespace DataSpec
namespace DNAMP1 namespace DNAMP1
{ {
const std::vector<FourCC> skLanguages =
{
FOURCC('ENGL'),
FOURCC('FREN'),
FOURCC('GERM'),
FOURCC('SPAN'),
FOURCC('ITAL'),
FOURCC('DUTC'),
FOURCC('JAPN')
};
void STRG::_read(athena::io::IStreamReader& reader) void STRG::_read(athena::io::IStreamReader& reader)
{ {
atUint32 langCount = reader.readUint32Big(); atUint32 langCount = reader.readUint32Big();
atUint32 strCount = reader.readUint32Big(); atUint32 strCount = reader.readUint32Big();
std::vector<FourCC> readLangs; std::vector<std::pair<FourCC, atUint32>> readLangs;
readLangs.reserve(langCount); readLangs.reserve(langCount);
for (atUint32 l=0 ; l<langCount ; ++l) for (atUint32 l=0 ; l<langCount ; ++l)
{ {
DNAFourCC lang; DNAFourCC lang;
lang.read(reader); lang.read(reader);
readLangs.emplace_back(lang); atUint32 off = reader.readUint32Big();
reader.seek(4); readLangs.emplace_back(lang, off);
} }
atUint32 tablesStart = reader.position();
langs.clear(); langs.clear();
langs.reserve(langCount); langs.reserve(skLanguages.size());
for (FourCC& lang : readLangs) for (const std::pair<FourCC, atUint32>& lang : readLangs)
{ {
std::vector<std::wstring> strs; std::vector<std::wstring> strs;
reader.seek(strCount * 4 + 4); reader.seek(tablesStart + lang.second, athena::SeekOrigin::Begin);
reader.readUint32Big(); // table size
atUint32 langStart = reader.position();
for (atUint32 s=0 ; s<strCount ; ++s) for (atUint32 s=0 ; s<strCount ; ++s)
{
atUint32 strOffset = reader.readUint32Big();
atUint32 tmpOffset = reader.position();
reader.seek(langStart + strOffset, athena::SeekOrigin::Begin);
strs.emplace_back(reader.readWStringBig()); strs.emplace_back(reader.readWStringBig());
langs.emplace_back(lang, strs); reader.seek(tmpOffset, athena::SeekOrigin::Begin);
}
langs.emplace_back(lang.first, strs);
} }
langMap.clear(); langMap.clear();
@ -70,7 +91,7 @@ void STRG::write(athena::io::IStreamWriter& writer) const
{ {
atUint32 chCount = lang.second[s].size(); atUint32 chCount = lang.second[s].size();
if (s < langStrCount) if (s < langStrCount)
offset += chCount * 2 + 1; offset += (chCount + 1) * 2;
else else
offset += 1; offset += 1;
} }
@ -83,7 +104,7 @@ void STRG::write(athena::io::IStreamWriter& writer) const
for (atUint32 s=0 ; s<strCount ; ++s) for (atUint32 s=0 ; s<strCount ; ++s)
{ {
if (s < langStrCount) if (s < langStrCount)
tableSz += lang.second[s].size() * 2 + 1; tableSz += (lang.second[s].size() + 1) * 2;
else else
tableSz += 1; tableSz += 1;
} }
@ -94,7 +115,7 @@ void STRG::write(athena::io::IStreamWriter& writer) const
{ {
writer.writeUint32Big(offset); writer.writeUint32Big(offset);
if (s < langStrCount) if (s < langStrCount)
offset += lang.second[s].size() * 2 + 1; offset += (lang.second[s].size() + 1) * 2;
else else
offset += 1; offset += 1;
} }
@ -140,6 +161,9 @@ void STRG::read(athena::io::YAMLDocReader& reader)
{ {
for (const auto& lang : root->m_mapChildren) for (const auto& lang : root->m_mapChildren)
{ {
if (lang.first == "DNAType")
continue;
if (lang.first.size() != 4) if (lang.first.size() != 4)
{ {
Log.report(logvisor::Warning, "STRG language string '%s' must be exactly 4 characters; skipping", lang.first.c_str()); Log.report(logvisor::Warning, "STRG language string '%s' must be exactly 4 characters; skipping", lang.first.c_str());
@ -170,6 +194,9 @@ void STRG::read(athena::io::YAMLDocReader& reader)
langs.clear(); langs.clear();
for (const auto& lang : root->m_mapChildren) for (const auto& lang : root->m_mapChildren)
{ {
if (lang.first == "DNAType")
continue;
std::vector<std::wstring> strs; std::vector<std::wstring> strs;
for (const auto& str : lang.second->m_seqChildren) for (const auto& str : lang.second->m_seqChildren)
strs.emplace_back(hecl::UTF8ToWide(str->m_scalarString)); strs.emplace_back(hecl::UTF8ToWide(str->m_scalarString));

View File

@ -10,6 +10,7 @@
#include "DNAMP1/CMDL.hpp" #include "DNAMP1/CMDL.hpp"
#include "DNAMP1/MREA.hpp" #include "DNAMP1/MREA.hpp"
#include "DNAMP1/ANCS.hpp" #include "DNAMP1/ANCS.hpp"
#include "DNACommon/FONT.hpp"
#include "DNACommon/PART.hpp" #include "DNACommon/PART.hpp"
#include "DNACommon/SWHC.hpp" #include "DNACommon/SWHC.hpp"
#include "DNACommon/ELSC.hpp" #include "DNACommon/ELSC.hpp"
@ -343,6 +344,8 @@ struct SpecMP1 : SpecBase
return true; return true;
else if (!strcmp(classType, DNADGRP::DGRP<UniqueID32>::DNAType())) else if (!strcmp(classType, DNADGRP::DGRP<UniqueID32>::DNAType()))
return true; return true;
else if (!strcmp(classType, DNAFont::FONT<UniqueID32>::DNAType()))
return true;
return false; return false;
}); });
} }
@ -477,6 +480,12 @@ struct SpecMP1 : SpecBase
dgrp.read(reader); dgrp.read(reader);
DNADGRP::WriteDGRP(dgrp, out); DNADGRP::WriteDGRP(dgrp, out);
} }
else if (!classStr.compare(DNAFont::FONT<UniqueID32>::DNAType()))
{
DNAFont::FONT<UniqueID32> font;
font.read(reader);
DNAFont::WriteFONT(font, out);
}
} }
progress(_S("Done")); progress(_S("Done"));
} }

View File

@ -7,6 +7,7 @@
#include "Runtime/Particle/CSwooshDescription.hpp" #include "Runtime/Particle/CSwooshDescription.hpp"
#include "Runtime/GuiSys/CGuiFrame.hpp" #include "Runtime/GuiSys/CGuiFrame.hpp"
#include "Runtime/GuiSys/CRasterFont.hpp" #include "Runtime/GuiSys/CRasterFont.hpp"
#include "Runtime/GuiSys/CStringTable.hpp"
#include "Runtime/Graphics/CModel.hpp" #include "Runtime/Graphics/CModel.hpp"
#include "Runtime/Graphics/CTexture.hpp" #include "Runtime/Graphics/CTexture.hpp"
#include "Runtime/Character/CCharLayoutInfo.hpp" #include "Runtime/Character/CCharLayoutInfo.hpp"
@ -44,6 +45,7 @@ ProjectResourceFactoryMP1::ProjectResourceFactoryMP1(hecl::ClientProcess& client
m_factoryMgr.AddFactory(FOURCC('DCLN'), FFactoryFunc(FCollidableOBBTreeGroupFactory)); m_factoryMgr.AddFactory(FOURCC('DCLN'), FFactoryFunc(FCollidableOBBTreeGroupFactory));
m_factoryMgr.AddFactory(FOURCC('DGRP'), FFactoryFunc(FDependencyGroupFactory)); m_factoryMgr.AddFactory(FOURCC('DGRP'), FFactoryFunc(FDependencyGroupFactory));
m_factoryMgr.AddFactory(FOURCC('AGSC'), FMemFactoryFunc(FAudioGroupSetDataFactory)); m_factoryMgr.AddFactory(FOURCC('AGSC'), FMemFactoryFunc(FAudioGroupSetDataFactory));
m_factoryMgr.AddFactory(FOURCC('STRG'), FFactoryFunc(FStringTableFactory));
} }
void ProjectResourceFactoryMP1::IndexMP1Resources(hecl::Database::Project& proj) void ProjectResourceFactoryMP1::IndexMP1Resources(hecl::Database::Project& proj)
@ -131,6 +133,16 @@ SObjectTag ProjectResourceFactoryMP1::TagFromPath(const hecl::ProjectPath& path,
resTag.type = SBIG('DGRP'); resTag.type = SBIG('DGRP');
return true; return true;
} }
else if (!strcmp(className, "urde::DNAMP1::STRG"))
{
resTag.type = SBIG('STRG');
return true;
}
else if (!strcmp(className, "FONT"))
{
resTag.type = SBIG('FONT');
return true;
}
return false; return false;
})) }))
{ {

View File

@ -32,7 +32,7 @@ CRasterFont::CRasterFont(urde::CInputStream& in, urde::IObjectStore& store)
std::string name= in.readString(); std::string name= in.readString();
u32 txtrId = in.readUint32Big(); u32 txtrId = in.readUint32Big();
x30_fontInfo = CFontInfo(tmp1, tmp2, tmp3, tmp4, name.c_str()); x30_fontInfo = CFontInfo(tmp1, tmp2, tmp3, tmp4, name.c_str());
x80_texture = store.GetObj({'TXTR', txtrId}); x80_texture = store.GetObj({FOURCC('TXTR'), txtrId});
x2c_mode = EColorType(in.readUint32Big()); x2c_mode = EColorType(in.readUint32Big());
u32 glyphCount = in.readUint32Big(); u32 glyphCount = in.readUint32Big();
@ -84,7 +84,7 @@ void CRasterFont::SinglePassDrawString(const CDrawStringOptions& opts, int x, in
const wchar_t* chr = str; const wchar_t* chr = str;
const CGlyph* prevGlyph = nullptr; const CGlyph* prevGlyph = nullptr;
while (*chr == '\0') while (*chr != '\0')
{ {
const CGlyph* glyph = GetGlyph(*chr); const CGlyph* glyph = GetGlyph(*chr);
if (glyph) if (glyph)

View File

@ -27,7 +27,7 @@ void CStringTable::LoadStringTable(CInputStream &in)
std::vector<std::pair<FourCC, u32>> langOffsets; std::vector<std::pair<FourCC, u32>> langOffsets;
for (u32 i = 0 ; i<langCount ; ++i) for (u32 i = 0 ; i<langCount ; ++i)
{ {
FourCC fcc(in.readUint32Big()); FourCC fcc(in.readUint32());
u32 off = in.readUint32Big(); u32 off = in.readUint32Big();
langOffsets.emplace_back(fcc,off); langOffsets.emplace_back(fcc,off);
} }
@ -45,6 +45,13 @@ void CStringTable::LoadStringTable(CInputStream &in)
lang++; lang++;
} }
/*
* If we fail to get a language, default to the first in the list
* This way we always display _something_
*/
if (offset == -1)
offset = langOffsets[0].second;
in.seek(offset); in.seek(offset);
u32 dataLen = in.readUint32Big(); u32 dataLen = in.readUint32Big();
@ -58,7 +65,7 @@ void CStringTable::LoadStringTable(CInputStream &in)
} }
for (u32 i = x0_stringCount * 4 ; i<dataLen ; i += 2) for (u32 i = x0_stringCount * 4 ; i<dataLen ; i += 2)
{ {
char16_t* chr = reinterpret_cast<char16_t*>(x4_data.get() + i); u16* chr = reinterpret_cast<u16*>(x4_data.get() + i);
*chr = hecl::SBig(*chr); *chr = hecl::SBig(*chr);
} }
} }