mirror of https://github.com/PrimeDecomp/prime.git
50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
#include "Kyoto/Text/CStringTable.hpp"
|
|
|
|
#include "rstl/pair.hpp"
|
|
#include "rstl/vector.hpp"
|
|
|
|
#include "Kyoto/CFactoryMgr.hpp"
|
|
|
|
static FourCC mCurrentLanguage = 'ENGL';
|
|
static const wchar_t skInvalidString[] = L"Invalid";
|
|
|
|
CStringTable::CStringTable(CInputStream& in) : x0_stringCount(0), x4_data(NULL) {
|
|
in.ReadLong();
|
|
in.ReadLong();
|
|
s32 langCount = in.Get(TType< s32 >());
|
|
x0_stringCount = in.Get(TType< u32 >());
|
|
rstl::vector< rstl::pair< FourCC, u32 > > langOffsets(langCount);
|
|
for (s32 i = 0; i < langCount; ++i) {
|
|
langOffsets.push_back(in.Get(TType< rstl::pair< FourCC, u32 > >()));
|
|
}
|
|
|
|
s32 offset = langOffsets.front().second;
|
|
for (s32 i = 0; i < langCount; ++i) {
|
|
if (langOffsets[i].first == mCurrentLanguage) {
|
|
offset = langOffsets[i].second;
|
|
break;
|
|
}
|
|
}
|
|
for (u32 i = 0; i < offset; ++i) {
|
|
in.ReadChar();
|
|
}
|
|
|
|
u32 dataLen = in.Get(TType< u32 >());
|
|
x4_data = new u8[dataLen];
|
|
in.ReadBytes(x4_data.get(), dataLen);
|
|
}
|
|
|
|
const wchar_t* CStringTable::GetString(s32 idx) const {
|
|
if (idx < 0 || idx >= x0_stringCount) {
|
|
return skInvalidString;
|
|
}
|
|
s32 offset = *(reinterpret_cast< const s32* >(x4_data.get()) + idx);
|
|
return reinterpret_cast< const wchar_t* >(x4_data.get() + offset);
|
|
}
|
|
|
|
template <>
|
|
CFactoryFnReturn::CFactoryFnReturn(CStringTable* ptr)
|
|
: obj(TToken< CStringTable >::GetIObjObjectFor(rstl::auto_ptr< CStringTable >(ptr)).release()) {}
|
|
|
|
CFactoryFnReturn FStringTableFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& xfer) { return new CStringTable(in); }
|