2004-04-12 21:40:49 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2004-2006 The ScummVM project
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* The ReInherit Engine is (C)2000-2003 by Daniel Balsom.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 09:07:31 +00:00
|
|
|
// Game detection, general game parameters
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
2004-12-22 19:34:41 +00:00
|
|
|
|
2004-04-23 11:40:51 +00:00
|
|
|
#include "common/file.h"
|
2004-12-22 19:34:41 +00:00
|
|
|
#include "common/md5.h"
|
2006-04-08 11:38:41 +00:00
|
|
|
#include "common/hashmap.h"
|
2005-10-14 04:28:20 +00:00
|
|
|
#include "common/config-manager.h"
|
2004-05-01 23:42:22 +00:00
|
|
|
#include "base/plugins.h"
|
|
|
|
#include "backends/fs/fs.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
#include "saga/rscfile.h"
|
2004-08-06 01:39:17 +00:00
|
|
|
#include "saga/interface.h"
|
2004-08-11 23:42:02 +00:00
|
|
|
#include "saga/scene.h"
|
2006-05-13 10:30:38 +00:00
|
|
|
#include "saga/sagaresnames.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-08-10 18:27:18 +00:00
|
|
|
|
2006-03-09 14:33:07 +00:00
|
|
|
namespace Saga {
|
2006-03-27 16:56:08 +00:00
|
|
|
static DetectedGameList GAME_detectGames(const FSList &fslist);
|
2006-03-09 14:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const PlainGameDescriptor saga_games[] = {
|
|
|
|
{"ite", "Inherit the Earth: Quest for the Orb"},
|
|
|
|
{"ihnm", "I Have No Mouth and I Must Scream"},
|
|
|
|
{0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
GameList Engine_SAGA_gameIDList() {
|
|
|
|
GameList games;
|
|
|
|
const PlainGameDescriptor *g = saga_games;
|
|
|
|
|
|
|
|
while (g->gameid) {
|
|
|
|
games.push_back(*g);
|
|
|
|
g++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return games;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameDescriptor Engine_SAGA_findGameID(const char *gameid) {
|
|
|
|
const PlainGameDescriptor *g = saga_games;
|
|
|
|
while (g->gameid) {
|
|
|
|
if (0 == scumm_stricmp(gameid, g->gameid))
|
|
|
|
break;
|
|
|
|
g++;
|
|
|
|
}
|
|
|
|
return *g;
|
|
|
|
}
|
|
|
|
|
|
|
|
DetectedGameList Engine_SAGA_detectGames(const FSList &fslist) {
|
2006-03-27 16:56:08 +00:00
|
|
|
return Saga::GAME_detectGames(fslist);
|
2006-03-09 14:33:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-29 00:27:20 +00:00
|
|
|
PluginError Engine_SAGA_create(OSystem *syst, Engine **engine) {
|
|
|
|
assert(engine);
|
|
|
|
*engine = new Saga::SagaEngine(syst);
|
|
|
|
return kNoError;
|
2006-03-09 14:33:07 +00:00
|
|
|
}
|
|
|
|
|
2006-04-08 12:06:07 +00:00
|
|
|
REGISTER_PLUGIN(SAGA, "SAGA Engine");
|
2006-03-09 14:33:07 +00:00
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
namespace Saga {
|
2006-05-13 10:30:38 +00:00
|
|
|
#include "sagagame.cpp"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2006-04-16 13:12:23 +00:00
|
|
|
DetectedGame toDetectedGame(const GameDescription &g) {
|
2006-03-27 16:56:08 +00:00
|
|
|
const char *title;
|
2006-04-16 13:12:23 +00:00
|
|
|
title = saga_games[g.gameType].description;
|
|
|
|
DetectedGame dg(g.name, title, g.language, g.platform);
|
|
|
|
dg.updateDesc(g.extra);
|
2006-03-14 13:28:28 +00:00
|
|
|
return dg;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
static int detectGame(const FSList *fslist, Common::Language language, Common::Platform platform, int*& returnMatches) {
|
|
|
|
int gamesCount = ARRAYSIZE(gameDescriptions);
|
|
|
|
int filesCount;
|
2005-10-14 04:28:20 +00:00
|
|
|
|
2006-04-08 11:38:41 +00:00
|
|
|
typedef Common::HashMap<Common::String, bool> StringSet;
|
2006-03-27 16:56:08 +00:00
|
|
|
StringSet filesList;
|
2005-10-14 04:28:20 +00:00
|
|
|
|
2006-04-08 11:38:41 +00:00
|
|
|
typedef Common::HashMap<Common::String, Common::String> StringMap;
|
2006-03-27 16:56:08 +00:00
|
|
|
StringMap filesMD5;
|
2004-05-01 23:42:22 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
Common::String tstr;
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
char md5str[32+1];
|
|
|
|
uint8 md5sum[16];
|
2005-10-14 04:28:20 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
int matched[ARRAYSIZE(gameDescriptions)];
|
|
|
|
int matchedCount = 0;
|
|
|
|
bool fileMissing;
|
|
|
|
GameFileDescription *fileDesc;
|
2005-10-14 04:28:20 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
// First we compose list of files which we need MD5s for
|
|
|
|
for (i = 0; i < gamesCount; i++) {
|
|
|
|
for (j = 0; j < gameDescriptions[i].filesCount; j++) {
|
|
|
|
tstr = Common::String(gameDescriptions[i].filesDescriptions[j].fileName);
|
|
|
|
tstr.toLowercase();
|
|
|
|
filesList[tstr] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fslist != NULL) {
|
|
|
|
for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) {
|
|
|
|
if (file->isDirectory()) continue;
|
|
|
|
tstr = file->displayName();
|
|
|
|
tstr.toLowercase();
|
|
|
|
|
|
|
|
if (!filesList.contains(tstr)) continue;
|
|
|
|
|
2006-04-16 12:50:39 +00:00
|
|
|
if (!Common::md5_file(file->path().c_str(), md5sum, FILE_MD5_BYTES)) continue;
|
2006-03-27 16:56:08 +00:00
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
|
|
|
|
}
|
|
|
|
filesMD5[tstr] = Common::String(md5str);
|
2005-10-14 04:28:20 +00:00
|
|
|
}
|
2006-03-27 16:56:08 +00:00
|
|
|
} else {
|
|
|
|
Common::File testFile;
|
2005-10-14 04:28:20 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
for (StringSet::const_iterator file = filesList.begin(); file != filesList.end(); ++file) {
|
|
|
|
tstr = file->_key;
|
|
|
|
tstr.toLowercase();
|
2005-10-14 04:28:20 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
if(!filesMD5.contains(tstr)) {
|
2006-04-14 01:48:51 +00:00
|
|
|
if (testFile.open(file->_key)) {
|
2006-03-27 16:56:08 +00:00
|
|
|
testFile.close();
|
|
|
|
|
2006-04-16 12:50:39 +00:00
|
|
|
if (Common::md5_file(file->_key.c_str(), md5sum, FILE_MD5_BYTES)) {
|
2006-03-27 16:56:08 +00:00
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
|
|
|
|
}
|
|
|
|
filesMD5[tstr] = Common::String(md5str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
for (i = 0; i < gamesCount; i++) {
|
|
|
|
filesCount = gameDescriptions[i].filesCount;
|
|
|
|
fileMissing = false;
|
2005-10-16 16:50:05 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
// Try to open all files for this game
|
|
|
|
for (j = 0; j < filesCount; j++) {
|
|
|
|
fileDesc = &gameDescriptions[i].filesDescriptions[j];
|
|
|
|
tstr = fileDesc->fileName;
|
|
|
|
tstr.toLowercase();
|
2005-06-04 12:25:25 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
if (!filesMD5.contains(tstr)) {
|
|
|
|
|
|
|
|
if ((fileDesc->fileType & (GAME_SOUNDFILE | GAME_VOICEFILE | GAME_MUSICFILE)) != 0) {
|
|
|
|
//TODO: find recompressed files
|
|
|
|
}
|
|
|
|
fileMissing = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (strcmp(fileDesc->md5, filesMD5[tstr].c_str())) {
|
|
|
|
fileMissing = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!fileMissing) {
|
2006-04-16 13:12:23 +00:00
|
|
|
debug(2, "Found game: %s", toDetectedGame(gameDescriptions[i]).description.c_str());
|
2006-03-27 16:56:08 +00:00
|
|
|
matched[matchedCount++] = i;
|
|
|
|
}
|
2005-06-04 12:25:25 +00:00
|
|
|
}
|
|
|
|
|
2006-03-28 09:42:54 +00:00
|
|
|
if (!filesMD5.empty() && (matchedCount == 0)) {
|
2006-03-27 16:56:08 +00:00
|
|
|
printf("MD5s of your game version are unknown. Please, report following data to\n");
|
|
|
|
printf("ScummVM team along with your game name and version:\n");
|
|
|
|
|
|
|
|
for (StringMap::const_iterator file = filesMD5.begin(); file != filesMD5.end(); ++file)
|
|
|
|
printf("%s: %s\n", file->_key.c_str(), file->_value.c_str());
|
2005-10-14 04:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have some resource sets which are superpositions of other
|
|
|
|
// Particularly it is ite-demo-linux vs ite-demo-win
|
|
|
|
// Now remove lesser set if bigger matches too
|
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
if (matchedCount > 1) {
|
2005-10-14 04:28:20 +00:00
|
|
|
// Search max number
|
|
|
|
int maxcount = 0;
|
2006-03-27 16:56:08 +00:00
|
|
|
for (i = 0; i < matchedCount; i++) {
|
|
|
|
maxcount = MAX(gameDescriptions[matched[i]].filesCount, maxcount);
|
2005-10-14 04:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now purge targets with number of files lesser than max
|
2006-03-27 16:56:08 +00:00
|
|
|
for (i = 0; i < matchedCount; i++) {
|
|
|
|
if ((gameDescriptions[matched[i]].language != language && language != Common::UNK_LANG) ||
|
|
|
|
(gameDescriptions[matched[i]].platform != platform && platform != Common::kPlatformUnknown)) {
|
2006-04-16 13:12:23 +00:00
|
|
|
debug(2, "Purged %s", toDetectedGame(gameDescriptions[matched[i]]).description.c_str());
|
2006-03-27 16:56:08 +00:00
|
|
|
matched[i] = -1;
|
|
|
|
continue;
|
2005-10-14 04:28:20 +00:00
|
|
|
}
|
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
if (gameDescriptions[matched[i]].filesCount < maxcount) {
|
2006-04-16 13:12:23 +00:00
|
|
|
debug(2, "Purged: %s", toDetectedGame(gameDescriptions[matched[i]]).description.c_str());
|
2006-03-27 16:56:08 +00:00
|
|
|
matched[i] = -1;
|
|
|
|
}
|
2006-03-09 01:42:56 +00:00
|
|
|
}
|
2005-07-19 21:15:56 +00:00
|
|
|
}
|
2004-12-25 16:55:13 +00:00
|
|
|
|
2004-12-24 13:01:47 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
returnMatches = (int *)malloc(matchedCount * sizeof(int));
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < matchedCount; i++)
|
|
|
|
if (matched[i] != -1)
|
|
|
|
returnMatches[j++] = matched[i];
|
|
|
|
return j;
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
bool SagaEngine::initGame() {
|
|
|
|
uint16 gameCount = ARRAYSIZE(gameDescriptions);
|
|
|
|
int gameNumber = -1;
|
|
|
|
|
|
|
|
DetectedGameList detectedGames;
|
|
|
|
int count;
|
|
|
|
int* matches;
|
|
|
|
Common::Language language = Common::UNK_LANG;
|
|
|
|
Common::Platform platform = Common::kPlatformUnknown;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
if (ConfMan.hasKey("language"))
|
|
|
|
language = Common::parseLanguage(ConfMan.get("language"));
|
|
|
|
if (ConfMan.hasKey("platform"))
|
|
|
|
platform = Common::parsePlatform(ConfMan.get("platform"));
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-01-02 20:29:27 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
count = detectGame(NULL, language, platform, matches);
|
2004-05-01 23:42:22 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
if (count == 0) {
|
|
|
|
warning("No valid games were found in the specified directory.");
|
|
|
|
return false;
|
2004-12-24 13:01:47 +00:00
|
|
|
}
|
2004-05-01 23:42:22 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
if (count != 1)
|
|
|
|
warning("Conflicting targets detected (%d)", count);
|
2004-05-01 23:42:22 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
gameNumber = matches[0];
|
2004-12-24 13:01:47 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
free(matches);
|
2004-12-24 13:01:47 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
if (gameNumber >= gameCount || gameNumber == -1) {
|
|
|
|
error("SagaEngine::loadGame wrong gameNumber");
|
|
|
|
}
|
2004-12-24 13:01:47 +00:00
|
|
|
|
2006-04-16 13:12:23 +00:00
|
|
|
_gameTitle = toDetectedGame(gameDescriptions[gameNumber]).description;
|
2006-03-27 16:56:08 +00:00
|
|
|
debug(2, "Running %s", _gameTitle.c_str());
|
2004-12-24 13:01:47 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
_gameNumber = gameNumber;
|
|
|
|
_gameDescription = &gameDescriptions[gameNumber];
|
|
|
|
_gameDisplayInfo = *_gameDescription->gameDisplayInfo;
|
|
|
|
_displayClip.right = _gameDisplayInfo.logicalWidth;
|
|
|
|
_displayClip.bottom = _gameDisplayInfo.logicalHeight;
|
2004-12-24 13:01:47 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
if (!_resource->createContexts()) {
|
|
|
|
return false;
|
2004-05-01 23:42:22 +00:00
|
|
|
}
|
2006-03-27 16:56:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-05-01 23:42:22 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
DetectedGameList GAME_detectGames(const FSList &fslist) {
|
|
|
|
DetectedGameList detectedGames;
|
|
|
|
int count;
|
|
|
|
int* matches;
|
|
|
|
count = detectGame(&fslist, Common::UNK_LANG, Common::kPlatformUnknown, matches);
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2006-03-27 16:56:08 +00:00
|
|
|
for (int i = 0; i < count; i++)
|
2006-04-16 13:12:23 +00:00
|
|
|
detectedGames.push_back(toDetectedGame(gameDescriptions[matches[i]]));
|
2006-03-27 16:56:08 +00:00
|
|
|
free(matches);
|
|
|
|
return detectedGames;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|