1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program 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 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program 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 this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "common/file.h"
24 #include "gui/debugger.h"
25 
26 #include "trecision/console.h"
27 #include "trecision/dialog.h"
28 #include "trecision/pathfinding3d.h"
29 #include "trecision/scheduler.h"
30 #include "trecision/text.h"
31 #include "trecision/trecision.h"
32 
33 namespace Trecision {
34 
Console(TrecisionEngine * vm)35 Console::Console(TrecisionEngine *vm) : GUI::Debugger(), _vm(vm) {
36 	registerCmd("room",			 WRAP_METHOD(Console, Cmd_Room));
37 	registerCmd("dumpanim",		 WRAP_METHOD(Console, Cmd_DumpAnim));
38 	registerCmd("dumpfile",		 WRAP_METHOD(Console, Cmd_DumpFile));
39 	registerCmd("dialog",		 WRAP_METHOD(Console, Cmd_Dialog));
40 	registerCmd("item",			 WRAP_METHOD(Console, Cmd_Item));
41 	registerCmd("say",			 WRAP_METHOD(Console, Cmd_Say));
42 	registerCmd("position",		 WRAP_METHOD(Console, Cmd_Position));
43 	registerCmd("toggle_object", WRAP_METHOD(Console, Cmd_ToggleObject));
44 }
45 
~Console()46 Console::~Console() {
47 }
48 
Cmd_Room(int argc,const char ** argv)49 bool Console::Cmd_Room(int argc, const char **argv) {
50 	if (argc < 2) {
51 		debugPrintf("Current room: %d\n", _vm->_curRoom);
52 		debugPrintf("Use %s <roomId> to teleport\n", argv[0]);
53 		return true;
54 	}
55 
56 	const int newRoom = atoi(argv[1]);
57 	_vm->changeRoom(newRoom);
58 
59 	return false;
60 }
61 
Cmd_DumpAnim(int argc,const char ** argv)62 bool Console::Cmd_DumpAnim(int argc, const char **argv) {
63 	if (argc < 2) {
64 		debugPrintf("Usage: %s <file name>\n", argv[0]);
65 		return true;
66 	}
67 
68 	FastFile animFile;
69 
70 	Common::String fileName = argv[1];
71 
72 	bool found = false;
73 	for (int i = 1; i <= 3; i++) {
74 		Common::String animFileName = Common::String::format("nlanim.cd%d", i);
75 		animFile.open(_vm, animFileName);
76 
77 		if (animFile.hasFile(fileName)) {
78 			found = true;
79 			break;
80 		}
81 	}
82 
83 	if (!found) {
84 		debugPrintf("File not found\n");
85 		animFile.close();
86 		return true;
87 	}
88 
89 	Common::SeekableReadStream *dataFile = animFile.createReadStreamForMember(fileName);
90 
91 	Common::DumpFile *outFile = new Common::DumpFile();
92 	Common::String outName = fileName + ".dump";
93 	outFile->open(outName);
94 	outFile->writeStream(dataFile, dataFile->size());
95 	outFile->finalize();
96 	outFile->close();
97 
98 	animFile.close();
99 
100 	return true;
101 }
102 
Cmd_DumpFile(int argc,const char ** argv)103 bool Console::Cmd_DumpFile(int argc, const char **argv) {
104 	if (argc < 2) {
105 		debugPrintf("Usage: %s <file name>\n", argv[0]);
106 		return true;
107 	}
108 
109 	Common::String fileName = argv[1];
110 
111 	if (!_vm->_dataFile.hasFile(fileName)) {
112 		debugPrintf("File not found\n");
113 		return true;
114 	}
115 
116 	Common::SeekableReadStream *dataFile = fileName.hasSuffix(".cr") ? _vm->_dataFile.createReadStreamForCompressedMember(fileName) : _vm->_dataFile.createReadStreamForMember(fileName);
117 
118 	Common::DumpFile *outFile = new Common::DumpFile();
119 	Common::String outName = fileName + ".dump";
120 	outFile->open(outName);
121 	outFile->writeStream(dataFile, dataFile->size());
122 	outFile->finalize();
123 	outFile->close();
124 
125 	return true;
126 }
127 
Cmd_Dialog(int argc,const char ** argv)128 bool Console::Cmd_Dialog(int argc, const char **argv) {
129 	if (argc < 2) {
130 		debugPrintf("Use %s <dialogId> to start a dialog\n", argv[0]);
131 		return true;
132 	}
133 
134 	const int dialogId = atoi(argv[1]);
135 	_vm->_dialogMgr->playDialog(dialogId);
136 
137 	return false;
138 }
139 
Cmd_Item(int argc,const char ** argv)140 bool Console::Cmd_Item(int argc, const char **argv) {
141 	if (argc < 2) {
142 		debugPrintf("Use %s <itemId> to add an item to the inventory\n", argv[0]);
143 		debugPrintf("Use %s <itemId> remove to remove an item from the inventory\n", argv[0]);
144 		return true;
145 	}
146 
147 	const int itemId = atoi(argv[1]);
148 	if (argc >= 3 && !scumm_stricmp(argv[2], "remove")) {
149 		_vm->removeIcon(itemId);
150 	} else {
151 		_vm->addIcon(itemId);
152 	}
153 
154 	return false;
155 }
156 
Cmd_Say(int argc,const char ** argv)157 bool Console::Cmd_Say(int argc, const char **argv) {
158 	if (argc < 2) {
159 		debugPrintf("Use %s <sentenceId> to hear a sentence from Joshua\n", argv[0]);
160 		return true;
161 	}
162 
163 	const uint16 sentenceId = (uint16)atoi(argv[1]);
164 	_vm->_textMgr->characterSay(sentenceId);
165 
166 	return false;
167 }
168 
Cmd_Position(int argc,const char ** argv)169 bool Console::Cmd_Position(int argc, const char **argv) {
170 	if (argc < 2) {
171 		debugPrintf("Use %s <positionId> to set Joshua's position\n", argv[0]);
172 		return true;
173 	}
174 
175 	const uint16 positionId = (uint16)atoi(argv[1]);
176 	_vm->_pathFind->setPosition(positionId);
177 
178 	return false;
179 }
180 
Cmd_ToggleObject(int argc,const char ** argv)181 bool Console::Cmd_ToggleObject(int argc, const char **argv) {
182 	if (argc < 3) {
183 		debugPrintf("Use %s <objectId> <status> to show or hide an object\n", argv[0]);
184 		debugPrintf("Status can be true (or 1) to show an object, or false (or 0) to hide it\n");
185 		return true;
186 	}
187 
188 	const uint16 objectId = (uint16)atoi(argv[1]);
189 	const bool visible = !strcmp(argv[2], "1") || !scumm_stricmp(argv[2], "true");
190 	_vm->setObjectVisible(objectId, visible);
191 
192 	return false;
193 }
194 
195 } // End of namespace Trecision
196