aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen/patcher.cpp
blob: f9d9ee77ffe1f00a823603aae14f0a542a35a364 (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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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.
 *
 */

#include "xeen/patcher.h"
#include "xeen/xeen.h"
#include "xeen/map.h"
#include "xeen/party.h"
#include "common/memstream.h"
#include "common/serializer.h"

namespace Xeen {

struct ScriptEntry {
	uint _gameId;
	int _mapId;
	const byte *_data;
};

const byte DS_MAP54_LINE8[] = { 8, 10, 10, DIR_EAST, 8, OP_MoveWallObj, 20, 100, 100 };
const byte SW_MAP53_LINE8[] = { 5, 14, 6, DIR_EAST, 8, OP_Exit };
const byte DS_MAP116[] = { 9, 10, 6, 4, 2, OP_TakeOrGive, 0, 0, 103, 127 };

#define SCRIPT_PATCHES_COUNT 3
static const ScriptEntry SCRIPT_PATCHES[] = {
	{ GType_DarkSide, 54, DS_MAP54_LINE8 },	// Fix curtain on level 2 of Ellinger's Tower
	{ GType_Swords, 53, SW_MAP53_LINE8 },	// Fix chest in Hart having gems, but saying "Nothing Here"
	{ GType_DarkSide, 116, DS_MAP116 }		// Fix statue in Dark Tower setting invalid world flag
};

/*------------------------------------------------------------------------*/

void Patcher::patch() {
	patchScripts();
	patchObjects();
}

void Patcher::patchScripts() {
	FileManager &files = *g_vm->_files;
	Map &map = *g_vm->_map;
	Party &party = *g_vm->_party;
	
	uint gameId = g_vm->getGameID();
	if (gameId == GType_WorldOfXeen)
		gameId = files._ccNum ? GType_DarkSide : GType_Clouds;

	for (int patchIdx = 0; patchIdx < SCRIPT_PATCHES_COUNT; ++patchIdx) {
		const ScriptEntry &se = SCRIPT_PATCHES[patchIdx];
		if (se._gameId != gameId || se._mapId != party._mazeId)
			continue;
		
		MazeEvent evt;
		Common::MemoryReadStream memStream(se._data, se._data[0] + 1);
		Common::Serializer s(&memStream, nullptr);
		evt.synchronize(s);

		// Scan through the events to find a matching line
		int idx = 0;
		while (idx < (int)map._events.size() && (evt._position != map._events[idx]._position
				|| evt._direction != map._events[idx]._direction || evt._line != map._events[idx]._line))
			++idx;

		// Set the event
		if (idx == (int)map._events.size())
			map._events.push_back(evt);
		else
			map._events[idx] = evt;
	}
}

void Patcher::patchObjects() {
	FileManager &files = *g_vm->_files;
	Map &map = *g_vm->_map;
	Party &party = *g_vm->_party;

	if ((g_vm->getGameID() == GType_Clouds || (g_vm->getGameID() == GType_WorldOfXeen && !files._ccNum)) &&
			party._mazeId == 24) {
		// Remove floating statue in the distance off SE corner of Clouds of Xeen map
		map._mobData._objects[15]._position = Common::Point(-128, -128);
	}
}

} // End of namespace Xeen