xoreos  0.0.5
jade.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/util.h"
26 #include "src/common/filelist.h"
27 #include "src/common/filepath.h"
28 #include "src/common/configman.h"
29 
30 #include "src/aurora/util.h"
31 #include "src/aurora/resman.h"
32 #include "src/aurora/language.h"
33 #include "src/aurora/talkman.h"
35 
36 #include "src/graphics/camera.h"
37 
43 
44 #include "src/sound/sound.h"
45 
46 #include "src/events/events.h"
47 
52 
54 
55 #include "src/engines/jade/jade.h"
58 #include "src/engines/jade/game.h"
59 
60 namespace Engines {
61 
62 namespace Jade {
63 
65  _console.reset(new Console(*this));
66 }
67 
69 }
70 
72 static void findTLKs(const Common::UString &target, Common::FileList &tlks) {
73  Common::FileList files;
74  if (!files.addDirectory(target))
75  return;
76 
77  files.addDirectory(Common::FilePath::findSubDirectory(target, "localizations", true), 1);
78  files.addDirectory(Common::FilePath::findSubDirectory(target, "localized", true), 1);
79 
80  const std::vector<Aurora::Language> gameLanguages = LangMan.getLanguages();
81  for (std::vector<Aurora::Language>::const_iterator l = gameLanguages.begin();
82  l != gameLanguages.end(); ++l)
83  files.addDirectory(Common::FilePath::findSubDirectory(target, LangMan.getLanguageName(*l)), -1);
84 
85  files.addDirectory(Common::FilePath::findSubDirectory(target, "Chinese", true), -1);
86 
87  files.getSubList("/dialog.tlk", true, tlks);
88 }
89 
91 static void addUniqueLanguageIfValid(std::vector<Aurora::Language> &languages, Aurora::Language language) {
92  if ((language == Aurora::kLanguageInvalid) ||
93  (std::find(languages.begin(), languages.end(), language) != languages.end()))
94  return;
95 
96  languages.push_back(language);
97 }
98 
101  const uint32 languageID = Aurora::TalkTable_TLK::getLanguageID(tlk);
102  if (languageID == Aurora::kLanguageInvalid)
104 
105  return LangMan.getLanguage(languageID);
106 }
107 
110  Common::FileList tlks;
111  findTLKs(target, tlks);
112 
113  for (Common::FileList::const_iterator tlk = tlks.begin(); tlk != tlks.end(); ++tlk)
114  if (getTLKLanguage(*tlk) == language)
116 
117  return "";
118 }
119 
121  Aurora::Platform UNUSED(platform),
122  std::vector<Aurora::Language> &languages) const {
123  try {
124  Common::FileList tlks;
125  findTLKs(target, tlks);
126 
127  for (Common::FileList::const_iterator tlk = tlks.begin(); tlk != tlks.end(); ++tlk)
128  addUniqueLanguageIfValid(languages, getTLKLanguage(*tlk));
129 
130  } catch (...) {
131  }
132 
133  return true;
134 }
135 
137  language = _language;
138  return true;
139 }
140 
142  Aurora::Language language;
143  if (!evaluateLanguage(false, language) || (_language != language))
144  return false;
145 
146  return true;
147 }
148 
150  assert(_game);
151 
152  return *_game;
153 }
154 
156  init();
157  if (EventMan.quitRequested())
158  return;
159 
160  CursorMan.hideCursor();
161  CursorMan.set();
162 
163  playIntroVideos();
164  if (EventMan.quitRequested())
165  return;
166 
167  CursorMan.showCursor();
168 
169  _game.reset(new Game(*this, *_console, _platform));
170  _game->run();
171 
172  deinit();
173 }
174 
176  LoadProgress progress(17);
177 
178  progress.step("Declare languages");
180 
181  if (evaluateLanguage(true, _language))
182  status("Setting the language to %s", LangMan.getLanguageName(_language).c_str());
183  else
184  warning("Failed to detect this game's language");
185 
186  LangMan.setCurrentLanguage(_language);
187 
188  progress.step("Loading user game config");
189  initConfig();
190 
191  initResources(progress);
192  if (EventMan.quitRequested())
193  return;
194 
196  progress.step("Loading game cursors");
197  initCursors();
198  if (EventMan.quitRequested())
199  return;
200  }
201 
202  progress.step("Initializing internal game config");
203  initGameConfig();
204 
205  progress.step("Successfully initialized the engine");
206 
208  GfxMan.setGUISize(640, 480);
215 }
216 
218  static const Aurora::LanguageManager::Declaration kLanguageDeclarations[] = {
229  };
230 
231  LangMan.addLanguages(kLanguageDeclarations, ARRAYSIZE(kLanguageDeclarations));
232 }
233 
236  /* Look into all subdirectories of the directory localized (which are all named after
237  * a language). In each, see if there's a sound/vo subdirectory. If there is, return
238  * the subdirectory (i.e the language name). */
239 
240  const Common::UString loc = Common::FilePath::findSubDirectory(target, "localized", true);
241  if (loc.empty())
242  return "";
243 
244  std::list<Common::UString> langs;
246 
247  for (std::list<Common::UString>::const_iterator l = langs.begin(); l != langs.end(); ++l)
248  if (!Common::FilePath::findSubDirectory(*l, "sound/vo", true).empty())
249  return Common::FilePath::relativize(loc, *l);
250 
251  return "";
252 }
253 
255  // Some new file types with the same function as old ones re-use the type ID
260 
261  progress.step("Setting base directory");
262  ResMan.registerDataBase(_target);
263 
264  progress.step("Adding extra archive directories");
265  indexMandatoryDirectory("data", 0, -1, 2);
266 
267  progress.step("Loading main KEY");
268  indexMandatoryArchive("chitin.key", 10);
269 
270  progress.step("Loading global auxiliary resources");
271  indexMandatoryArchive("loadscreens.mod" , 50);
272  indexMandatoryArchive("players.mod" , 51);
273  indexMandatoryArchive("global-a.rim" , 52);
274  indexMandatoryArchive("ingamemenu-a.rim" , 53);
275  indexMandatoryArchive("globalunload-a.rim", 54);
276  indexMandatoryArchive("minigame-a.rim" , 55);
277  indexMandatoryArchive("miniglobal-a.rim" , 56);
278  indexMandatoryArchive("mmenu-a.rim" , 57);
279 
280  progress.step("Indexing extra font resources");
281  indexMandatoryDirectory("fonts" , 0, -1, 100);
282  progress.step("Indexing extra sound resources");
283  indexMandatoryDirectory("sound" , 0, -1, 101);
284  progress.step("Indexing extra movie resources");
285  indexMandatoryDirectory("movies" , 0, -1, 103);
286 
288  progress.step("Indexing extra shader resources");
289  indexMandatoryDirectory("shaderpc", 0, -1, 104);
290  }
291 
292  progress.step("Indexing override files");
293  indexOptionalDirectory("override", 0, 0, 150);
294 
295  progress.step("Indexing extra language files");
296 
297  /* If we're running an Android version, see which language the voices are in.
298  * This should only ever be one language, the native language of the installation.
299  *
300  * If this is the language we want to play the game in, we're indexing the
301  * resources below. If it isn't, index them with a lower priority, as a fallback. */
303  const Aurora::Language androidVOLang = LangMan.parseLanguage(androidVO);
304  if ((androidVOLang != Aurora::kLanguageInvalid) && (androidVOLang != LangMan.getCurrentLanguageText())) {
305  const Common::UString locDir = Common::UString("localized/") + androidVO;
306 
307  indexOptionalDirectory(locDir + "/data", 0, -1, 3);
308  indexOptionalDirectory(locDir + "/sound", 0, -1, 102);
309  }
310 
311  const Common::UString langDir = getTLKDirectory(_target, LangMan.getCurrentLanguageText());
312  if (!langDir.empty()) {
313  indexMandatoryDirectory(langDir, 0, 0, 160);
314 
315  indexOptionalDirectory(langDir + "/data" , 0, -1, 161);
316  indexOptionalDirectory(langDir + "/fonts" , 0, -1, 162);
317  indexOptionalDirectory(langDir + "/sound" , 0, -1, 163);
318  indexOptionalDirectory(langDir + "/movies", 0, -1, 164);
319 
320  indexOptionalDirectory(langDir + "/override", 0, 0, 170);
321  }
322 
323  if (EventMan.quitRequested())
324  return;
325 
326  progress.step("Loading main talk table");
327  TalkMan.addTable("dialog", "dialogf", false, 0);
328 
329  progress.step("Registering file formats");
331  TextureMan.setDeswizzleSBM(_platform == Aurora::kPlatformXbox);
333  FontMan.addAlias("sava" , "eurogui");
334  FontMan.addAlias("cerigo" , "eurodialog");
335  FontMan.addAlias("fnt_gui" , "eurogui");
336  FontMan.addAlias("fnt_console", "eurogui");
337 }
338 
340  CursorMan.add("ui_cursor32", "default");
341 
342  CursorMan.setDefault("default");
343 }
344 
346 }
347 
349  ConfigMan.setString(Common::kConfigRealmGameTemp, "JADE_moduleDir",
351 }
352 
354  _game.reset();
355 }
356 
358  switch (_platform) {
360  playVideo("bwlogo"); // BioWare
361  playVideo("gsl_short"); // Microsoft
362  break;
363 
364  default:
366  playVideo("black"); // One second of black
367  playVideo("publisher"); // 2K Games (original DVD version) or Electronic Arts (GOG version)
368  playVideo("black"); // One second of black
369  playVideo("bwlogo"); // BioWare
370  playVideo("black"); // One second of black
371  playVideo("graymatr"); // Gray Matter
372  break;
373 
376  // TODO: These are Bink 2 videos, they don't actually play in xoreos
377 
378  playVideo("black"); // One second of black
379  playVideo("publisher"); // EA
380  playVideo("black"); // One second of black
381  playVideo("bwlogo"); // BioWare
382  playVideo("black"); // One second of black
383  playVideo("aspyr"); // Aspyr
384  break;
385  }
386 }
387 
388 } // End of namespace Jade
389 
390 } // End of namespace Engines
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Aurora::Platform _platform
Definition: engine.h:84
ABC/SBM font, used by Jade Empire.
Definition: fontman.h:48
void playVideo(const Common::UString &video)
Play this video resource.
Definition: util.cpp:54
GameID
Definition: types.h:393
Generic Aurora engines resource utility functions.
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
Placeable template (BioWare), GFF.
Definition: types.h:108
A class holding an UTF-8 string.
Definition: ustring.h:48
Temporary game settings/properties.
Definition: configman.h:47
#define TextureMan
Shortcut for accessing the texture manager.
Definition: textureman.h:127
Engine class handling Jade Empire.
The global config manager.
static bool getSubDirectories(const UString &directory, std::list< UString > &subDirectories)
Collect all direct subdirectories of a directory in a list.
Definition: filepath.cpp:234
Common::ScopedPtr< Console > _console
Definition: engine.h:87
The Aurora texture manager.
Camera management.
bool evaluateLanguage(bool find, Aurora::Language &language) const
Definition: engine.cpp:198
static Aurora::Language getTLKLanguage(const Common::UString &tlk)
Return the language of a TLK.
Definition: jade.cpp:100
Game & getGame()
Return the context running the actual game.
Definition: jade.cpp:149
Utility functions to handle files used in BioWare&#39;s Aurora engine.
The context handling the gameplay in Jade Empire.
std::list< UString >::const_iterator const_iterator
Definition: filelist.h:37
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
bool changeLanguage()
Change the game&#39;s current language.
Definition: jade.cpp:141
Language
Definition: language.h:46
bool indexOptionalDirectory(const Common::UString &dir, const char *glob, int depth, uint32 priority, Common::ChangeID *changeID)
Add a directory to the resource manager, if it exists.
Definition: resources.cpp:133
Android mobile phones and tablets.
Definition: types.h:437
The Aurora font manager.
void indexMandatoryArchive(const Common::UString &file, uint32 priority, const std::vector< byte > &password, Common::ChangeID *changeID)
Definition: resources.cpp:36
Game save, ERF.
Definition: types.h:123
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
void initResources(LoadProgress &progress)
Definition: jade.cpp:254
Microsoft Xbox.
Definition: types.h:433
The global events manager.
static void findTLKs(const Common::UString &target, Common::FileList &tlks)
Find all language TLKs in this Jade Empire installation.
Definition: jade.cpp:72
Types and functions related to language.
A 3D model of an object.
The Jade Empire main menu.
The global sound manager, handling all sound output.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
Placeable, GFF.
Definition: types.h:337
void run()
Run the game.
Definition: jade.cpp:155
static UString getDirectory(const UString &p)
Return a path&#39;s directory.
Definition: filepath.cpp:107
Trigger, GFF.
Definition: types.h:338
Handling BioWare&#39;s TLK talk tables.
Jade (debug) console.
void warning(const char *s,...)
Definition: util.cpp:33
#define CursorMan
Shortcut for accessing the cursor manager.
Definition: cursorman.h:129
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
The Aurora cursor manager.
Displaying the progress in loading a game.
static void addUniqueLanguageIfValid(std::vector< Aurora::Language > &languages, Aurora::Language language)
Add the language to the vector if it&#39;s a valid language and not yet in the vector.
Definition: jade.cpp:91
Render queue manager.
Trigger template (BioWare), GFF.
Definition: types.h:96
void indexMandatoryDirectory(const Common::UString &dir, const char *glob, int depth, uint32 priority, Common::ChangeID *changeID)
Add a directory to the resource manager, erroring out if it does not exist.
Definition: resources.cpp:112
Creature, GFF.
Definition: types.h:331
Jade Empire model loader.
Common::UString _target
Definition: engine.h:85
bool getSubList(const UString &str, bool caseInsensitive, FileList &subList) const
Add files ending with the given string into another FileList.
Definition: filelist.cpp:149
Dynamic area data, GFF.
Definition: types.h:89
void registerModelLoader(ModelLoader *loader)
Definition: model.cpp:37
bool detectLanguages(Aurora::GameID game, const Common::UString &target, Aurora::Platform platform, std::vector< Aurora::Language > &languages) const
Detect which languages this game instance supports.
Definition: jade.cpp:120
#define LangMan
Shortcut for accessing the language manager.
Definition: language.h:275
static UString relativize(const UString &basePath, const UString &path)
Return the path relative to the base path.
Definition: filepath.cpp:142
uint32_t uint32
Definition: types.h:204
The global talk manager for Aurora strings.
A list of files.
Definition: filelist.h:35
void step(const Common::UString &description)
Take a step in advancing the progress.
Creature template (BioWare), GFF.
Definition: types.h:92
static Common::UString findAndroidVOLanguageDir(const Common::UString &target)
Figure out which localization in an Android installation contains the voices.
Definition: jade.cpp:235
Microsoft Windows.
Definition: types.h:430
void status(const char *s,...)
Definition: util.cpp:52
Windows codepage 1250 (Eastern European, Latin alphabet).
Definition: encoding.h:49
const_iterator begin() const
Return a const_iterator pointing to the beginning of the list.
Definition: filelist.cpp:94
Common::ScopedPtr< Game > _game
Definition: jade.h:66
bool addDirectory(const UString &directory, int recurseDepth=0)
Add a directory to the list.
Definition: filelist.cpp:102
Generic Aurora engines utility functions.
A list of files.
Windows codepage 1251 (Eastern European, Cyrillic alphabet).
Definition: encoding.h:50
static Common::UString getTLKDirectory(const Common::UString &target, Aurora::Language language)
Return the subdirectory of the game path where the TLK for a specific language is in...
Definition: jade.cpp:109
bool getLanguage(Aurora::Language &language) const
Return the game&#39;s current language.
Definition: jade.cpp:136
Windows codepage 1252 (Western European, Latin alphabet).
Definition: encoding.h:51
uint32 getLanguageID() const
Return the language ID (ungendered) of the talk table.
Aurora::Language _language
Definition: jade.h:64
Windows codepage 936 (Simplified Chinese, extended GB2312 with GBK codepoints).
Definition: encoding.h:54
Platform
Definition: types.h:429
iOS, Apple mobile phones and tablets.
Definition: types.h:438
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
The global resource manager for Aurora resources.
Utility class for manipulating file paths.
#define FontMan
Shortcut for accessing the font manager.
Definition: fontman.h:105
const_iterator end() const
Return a const_iterator pointing past the end of the list.
Definition: filelist.cpp:98
static UString findSubDirectory(const UString &directory, const UString &subDirectory, bool caseInsensitive=false)
Find a directory&#39;s subdirectory.
Definition: filepath.cpp:318
#define RenderMan
Shortcut for accessing the render manager.
Definition: renderman.h:84
Generic Aurora engines model functions.