aboutsummaryrefslogtreecommitdiff
path: root/engines/touche/plugin.cpp
blob: 08c2a49bd9fa4f55e0597e7ef7ae56f23f3d341d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2006 The ScummVM project
 *
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *
 */

#include "common/stdafx.h"
#include "common/config-manager.h"
#include "common/fs.h"
#include "common/md5.h"

#include "base/plugins.h"

#include "touche/touche.h"

struct GameVersion {
	const char *description;
	uint32 filesize;
	const char *md5digest;
	Common::Language language;
	Common::Platform platform;
};

static const GameVersion toucheGameVersionsTable[] = {
	{ // retail version
		"Touche: The Adventures of the Fifth Musketeer",
		26350211,
		"2af0177f8887e3430f345e6b4d8b1414",
		Common::EN_ANY,
		Common::kPlatformPC
	},
	{ // retail version - tracker item #1601818
		"Touche: The Adventures of the Fifth Musketeer",
		26350190,
		"95967f0b51d2e813e99ca00325098340",
		Common::EN_ANY,
		Common::kPlatformWindows
	},
	{ // retail version
		"Touche: Les Aventures du Cinquieme Mousquetaire",
		26558232,
		"1caa20bb4d4fc2ce8eb867b6610082b3",
		Common::FR_FRA,
		Common::kPlatformPC
	},
	{ // retail version - tracker item #1598643
		"Touche - Die Abenteuer des funften Musketiers",
		26625537,
		"be2ae6454b3325e410946f2322547cd4",
		Common::DE_DEU,
		Common::kPlatformPC
	},
	{ // fan-made translation (http://www.iagtg.net/) - tracker item #1602360
		"Touche: The Adventures of the Fifth Musketeer",
		26367792,
		"1f442331d4b327c3488a9f6ffe9bdd25",
		Common::IT_ITA,
		Common::kPlatformPC
	},
	{
		// english demo version
		"Touche: The Adventures of the Fifth Musketeer (Demo)",
		8720683,
		"ddaed436445b2e77294ed19e8ae4aa2c",
		Common::EN_ANY,
		Common::kPlatformPC
	}
};

static const PlainGameDescriptor toucheGameDescriptor = {
	"touche", "Touche: The Adventures of the Fifth Musketeer"
};

static const char *toucheDetectFileName = "TOUCHE.DAT";

static Common::String Engine_TOUCHE_md5digest(const FilesystemNode *file) {
	static const int md5DataSize = 4096;
	uint8 md5digest[16];
	if (Common::md5_file(*file, md5digest, md5DataSize)) {
		char md5sum[32 + 1];
		for (int i = 0; i < 16; ++i) {
			sprintf(md5sum + i * 2, "%02x", (int)md5digest[i]);
		}
		return md5sum;
	}
	return "";
}

static uint32 Engine_TOUCHE_filesize(const FilesystemNode *file) {
	Common::File f;
	if (f.open(file->path().c_str())) {
		return f.size();
	}
	return 0;
}

GameList Engine_TOUCHE_gameIDList() {
	GameList games;
	games.push_back(toucheGameDescriptor);
	return games;
}

GameDescriptor Engine_TOUCHE_findGameID(const char *gameid) {
	if (scumm_stricmp(toucheGameDescriptor.gameid, gameid) == 0) {
		return toucheGameDescriptor;
	}
	return GameDescriptor();
}

GameList Engine_TOUCHE_detectGames(const FSList &fslist) {
	bool foundFile = false;
	FSList::const_iterator file;
	for (file = fslist.begin(); file != fslist.end(); ++file) {
		if (file->isDirectory()) {
			continue;
		}
		for (int i = 0; i < ARRAYSIZE(toucheGameVersionsTable); ++i) {
			if (file->name().equalsIgnoreCase(toucheDetectFileName)) {
				foundFile = true;
				break;
			}
		}
		if (foundFile) {
			break;
		}
	}
	GameList detectedGames;
	if (foundFile) {
		// Currently, the detection code is based on a MD5 checksum. If all known versions
		// have a different file size for TOUCHE.DAT, we may consider using this to do the
		// detection.
		Common::String md5digest = Engine_TOUCHE_md5digest(file);
		if (!md5digest.empty()) {
			for (int i = 0; i < ARRAYSIZE(toucheGameVersionsTable); ++i) {
				const GameVersion *gv = &toucheGameVersionsTable[i];
				if (md5digest.equalsIgnoreCase(gv->md5digest)) {
					GameDescriptor dg(toucheGameDescriptor.gameid, gv->description, gv->language, gv->platform);
					detectedGames.push_back(dg);
					break;
				}
			}
			if (detectedGames.empty()) {
				const uint32 filesize = Engine_TOUCHE_filesize(file);
				printf("Datafile size (%d) and MD5 (%s) are unknown !\n", filesize, md5digest.c_str());
				printf("Please report the details (language, platform, etc.) of this game to the ScummVM team.\n");
				detectedGames.push_back(toucheGameDescriptor);
			}
		}
	}
	return detectedGames;
}

PluginError Engine_TOUCHE_create(OSystem *system, Engine **engine) {
	FSList fslist;
	FilesystemNode dir(ConfMan.get("path"));
	if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) {
		return kInvalidPathError;
	}
	GameList game = Engine_TOUCHE_detectGames(fslist);
	if (game.size() != 1) {
		return kNoGameDataFoundError;
	}
	assert(engine);
	*engine = new Touche::ToucheEngine(system, game[0].language());
	return kNoError;
}

REGISTER_PLUGIN(TOUCHE, "Touche Engine", "Touche: The Adventures of the 5th Musketeer (C) Clipper Software");