the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "StdAfx.h"
2#include "StringTable.h"
3
4StringTable::StringTable(void)
5{
6
7}
8
9// Load string table from a binary blob, filling out with the current localisation data only
10StringTable::StringTable(PBYTE pbData, DWORD dwSize)
11{
12 src = byteArray(pbData, dwSize);
13
14 ProcessStringTableData();
15}
16
17
18void StringTable::ReloadStringTable()
19{
20 m_stringsMap.clear();
21 m_stringsVec.clear();
22
23 ProcessStringTableData();
24}
25
26void StringTable::ProcessStringTableData(void)
27{
28 ByteArrayInputStream bais(src);
29 DataInputStream dis(&bais);
30
31 int versionNumber = dis.readInt();
32 int languagesCount = dis.readInt();
33
34 vector< pair<wstring, int> > langSizeMap;
35 for(int i = 0; i < languagesCount; ++i)
36 {
37 wstring langId = dis.readUTF();
38 int langSize = dis.readInt();
39
40 langSizeMap.push_back( vector< pair<wstring, int> >::value_type(langId, langSize));
41 }
42
43 vector<wstring> locales;
44 app.getLocale(locales);
45
46 bool foundLang = false;
47 __int64 bytesToSkip = 0;
48 int dataSize = 0;
49
50 //
51 for( AUTO_VAR(it_locales, locales.begin());
52 it_locales!=locales.end() && (!foundLang);
53 it_locales++
54 )
55 {
56 bytesToSkip = 0;
57
58 for(AUTO_VAR(it, langSizeMap.begin()); it != langSizeMap.end(); ++it)
59 {
60 if(it->first.compare(*it_locales) == 0)
61 {
62 app.DebugPrintf("StringTable:: Found language '%ls'.\n", it_locales->c_str());
63 dataSize = it->second;
64 foundLang = true;
65 break;
66 }
67
68 bytesToSkip += it->second;
69 }
70
71 if (!foundLang)
72 app.DebugPrintf("StringTable:: Can't find language '%ls'.\n", it_locales->c_str());
73 }
74
75 if(foundLang)
76 {
77 dis.skip(bytesToSkip);
78
79 byteArray langData(dataSize);
80 dis.read(langData);
81
82 dis.close();
83
84 ByteArrayInputStream bais2(langData);
85 DataInputStream dis2(&bais2);
86
87 // Read the language file for the selected language
88 int langVersion = dis2.readInt();
89
90 isStatic = false; // 4J-JEV: Versions 1 and up could use
91 if (langVersion > 0) // integers rather than wstrings as keys.
92 isStatic = dis2.readBoolean();
93
94 wstring langId = dis2.readUTF();
95 int totalStrings = dis2.readInt();
96
97 app.DebugPrintf("IsStatic=%d totalStrings = %d\n",isStatic?1:0,totalStrings);
98
99 if (!isStatic)
100 {
101 for(int i = 0; i < totalStrings; ++i)
102 {
103 wstring stringId = dis2.readUTF();
104 wstring stringValue = dis2.readUTF();
105
106 m_stringsMap.insert( unordered_map<wstring, wstring>::value_type(stringId, stringValue) );
107 }
108 }
109 else
110 {
111 for(int i = 0; i < totalStrings; ++i)
112 m_stringsVec.push_back( dis2.readUTF() );
113 }
114 dis2.close();
115
116 // We can't delete this data in the dtor, so clear the reference
117 bais2.reset();
118 }
119 else
120 {
121 app.DebugPrintf("Failed to get language\n");
122#ifdef _DEBUG
123 __debugbreak();
124#endif
125
126 isStatic = false;
127 }
128
129 // We can't delete this data in the dtor, so clear the reference
130 bais.reset();
131}
132
133
134StringTable::~StringTable(void)
135{
136 // delete src.data; TODO 4J-JEV: ?
137}
138
139void StringTable::getData(PBYTE *ppData, UINT *pSize)
140{
141 *ppData = src.data;
142 *pSize = src.length;
143}
144
145LPCWSTR StringTable::getString(const wstring &id)
146{
147#ifndef _CONTENT_PACKAGE
148 if (isStatic)
149 {
150 __debugbreak();
151 return L"";
152 }
153#endif
154
155 AUTO_VAR(it, m_stringsMap.find(id) );
156
157 if(it != m_stringsMap.end())
158 {
159 return it->second.c_str();
160 }
161 else
162 {
163 return L"";
164 }
165}
166
167LPCWSTR StringTable::getString(int id)
168{
169#ifndef _CONTENT_PACKAGE
170 if (!isStatic)
171 {
172 __debugbreak();
173 return L"";
174 }
175#endif
176
177 if (id < m_stringsVec.size())
178 {
179 LPCWSTR pwchString=m_stringsVec.at(id).c_str();
180 return pwchString;
181 }
182 else
183 return L"";
184}
185
186
187
188
189