This commit is contained in:
Jack Andersen 2016-08-16 12:49:57 -10:00
commit d2fca93a8e
3 changed files with 115 additions and 1 deletions

View File

@ -93,6 +93,8 @@ set(GUISYS_SOURCES
CWordBreakTables.hpp
CFontImageDef.cpp
CFontImageDef.hpp
ITweakGui.hpp)
ITweakGui.hpp
CStringTable.cpp
CStringTable.hpp)
runtime_add_list(GuiSys GUISYS_SOURCES)

View File

@ -0,0 +1,86 @@
#include "CStringTable.hpp"
#include "CToken.hpp"
namespace urde
{
const std::vector<FourCC> CStringTable::skLanguages =
{
'ENGL',
'FREN',
'GERM',
'SPAN',
'ITAL',
'DUTC',
'JAPN'
};
FourCC CStringTable::mCurrentLanguage = CStringTable::skLanguages[0];
CStringTable::CStringTable(CInputStream& in) { LoadStringTable(in); }
void CStringTable::LoadStringTable(CInputStream &in)
{
in.readUint32Big();
in.readUint32Big();
u32 langCount = in.readUint32Big();
x0_stringCount = in.readUint32Big();
std::vector<std::pair<FourCC, u32>> langOffsets;
for (u32 i = 0 ; i<langCount ; ++i)
{
FourCC fcc(in.readUint32Big());
u32 off = in.readUint32Big();
langOffsets.emplace_back(fcc,off);
}
u32 lang = 0;
u32 offset = 0;
while((langCount--) > 0)
{
if (langOffsets[lang].first == mCurrentLanguage)
{
offset = langOffsets[lang].second;
break;
}
lang++;
}
in.seek(offset);
u32 dataLen = in.readUint32Big();
m_bufLen = dataLen;
x4_data.reset(new u8[dataLen]);
in.readUBytesToBuf(x4_data.get(), dataLen);
for (u32 i = 0 ; i<x0_stringCount ; i += 4)
{
u32* off = reinterpret_cast<u32*>(x4_data.get() + i);
*off = hecl::SBig(*off);
}
for (u32 i = x0_stringCount * 4 ; i<dataLen ; i += 2)
{
char16_t* chr = reinterpret_cast<char16_t*>(x4_data.get() + i);
*chr = hecl::SBig(*chr);
}
}
std::wstring CStringTable::GetString(s32 str) const
{
if (str < 0 || str >= x0_stringCount)
return L"Invalid";
u32 off = *(reinterpret_cast<u32*>(x4_data.get() + str * 4));
CMemoryInStream tmp(x4_data.get() + off, m_bufLen - off);
return tmp.readWString();
}
void CStringTable::SetLanguage(s32 lang)
{
mCurrentLanguage = skLanguages[lang];
}
CFactoryFnReturn FStringTableFactory(const SObjectTag&, CInputStream& in, const CVParamTransfer&)
{
return TToken<CStringTable>::GetIObjObjectFor(std::make_unique<CStringTable>(in));
}
}

View File

@ -0,0 +1,26 @@
#ifndef __URDE_CSTRINGTABLE_HPP__
#define __URDE_CSTRINGTABLE_HPP__
#include "RetroTypes.hpp"
#include "IFactory.hpp"
namespace urde
{
class CStringTable
{
static const std::vector<FourCC> skLanguages;
static FourCC mCurrentLanguage;
u32 x0_stringCount = 0;
std::unique_ptr<u8[]> x4_data = 0;
u32 m_bufLen;
public:
CStringTable(CInputStream& in);
void LoadStringTable(CInputStream& in);
std::wstring GetString(s32) const;
static void SetLanguage(s32);
};
CFactoryFnReturn FStringTableFactory(const SObjectTag&, CInputStream&, const CVParamTransfer&);
}
#endif // __URDE_CSTRINGTABLE_HPP__