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 "tinsel/tinsel.h"
24 #include "tinsel/debugger.h"
25 #include "tinsel/dialogs.h"
26 #include "tinsel/pcode.h"
27 #include "tinsel/scene.h"
28 #include "tinsel/sound.h"
29 #include "tinsel/music.h"
30 #include "tinsel/font.h"
31 #include "tinsel/strres.h"
32 
33 namespace Tinsel {
34 
35 //----------------- EXTERNAL FUNCTIONS ---------------------
36 
37 // In PDISPLAY.CPP
38 extern void TogglePathDisplay();
39 // In tinsel.cpp
40 extern void SetNewScene(SCNHANDLE scene, int entrance, int transition);
41 // In scene.cpp
42 extern SCNHANDLE GetSceneHandle();
43 
44 //----------------- SUPPORT FUNCTIONS ---------------------
45 
46 //static
strToInt(const char * s)47 int strToInt(const char *s) {
48 	if (!*s)
49 		// No string at all
50 		return 0;
51 	else if (toupper(s[strlen(s) - 1]) != 'H')
52 		// Standard decimal string
53 		return atoi(s);
54 
55 	// Hexadecimal string
56 	uint tmp;
57 	if (!sscanf(s, "%xh", &tmp))
58 		tmp = 0;
59 	return (int)tmp;
60 }
61 
62 //----------------- CONSOLE CLASS  ---------------------
63 
Console()64 Console::Console() : GUI::Debugger() {
65 	registerCmd("item",		WRAP_METHOD(Console, cmd_item));
66 	registerCmd("scene",		WRAP_METHOD(Console, cmd_scene));
67 	registerCmd("music",		WRAP_METHOD(Console, cmd_music));
68 	registerCmd("sound",		WRAP_METHOD(Console, cmd_sound));
69 	registerCmd("string",		WRAP_METHOD(Console, cmd_string));
70 }
71 
~Console()72 Console::~Console() {
73 }
74 
cmd_item(int argc,const char ** argv)75 bool Console::cmd_item(int argc, const char **argv) {
76 	if (argc < 2) {
77 		debugPrintf("%s item_number\n", argv[0]);
78 		debugPrintf("Sets the currently active 'held' item\n");
79 		return true;
80 	}
81 
82 	HoldItem(INV_NOICON);
83 	HoldItem(strToInt(argv[1]));
84 	return false;
85 }
86 
cmd_scene(int argc,const char ** argv)87 bool Console::cmd_scene(int argc, const char **argv) {
88 	if (argc < 1 || argc > 3) {
89 		debugPrintf("%s [scene_number [entry number]]\n", argv[0]);
90 		debugPrintf("If no parameters are given, prints the current scene.\n");
91 		debugPrintf("Otherwise changes to the specified scene number. Entry number defaults to 1 if none provided\n");
92 		return true;
93 	}
94 
95 	if (argc == 1) {
96 		debugPrintf("Current scene is %d\n", GetSceneHandle() >> SCNHANDLE_SHIFT);
97 		return true;
98 	}
99 
100 	uint32 sceneNumber = (uint32)strToInt(argv[1]) << SCNHANDLE_SHIFT;
101 	int entryNumber = (argc >= 3) ? strToInt(argv[2]) : 1;
102 
103 	SetNewScene(sceneNumber, entryNumber, TRANS_CUT);
104 	return false;
105 }
106 
cmd_music(int argc,const char ** argv)107 bool Console::cmd_music(int argc, const char **argv) {
108 	if (argc < 2) {
109 		debugPrintf("%s track_number or %s -offset\n", argv[0], argv[0]);
110 		debugPrintf("Plays the MIDI track number provided, or the offset inside midi.dat\n");
111 		debugPrintf("A positive number signifies a track number, whereas a negative signifies an offset\n");
112 		return true;
113 	}
114 
115 	int param = strToInt(argv[1]);
116 	if (param == 0) {
117 		debugPrintf("Track number/offset can't be 0!\n");
118 	} else if (param > 0) {
119 		// Track provided
120 		PlayMidiSequence(GetTrackOffset(param - 1), false);
121 	} else if (param < 0) {
122 		// Offset provided
123 		param = param * -1;
124 		PlayMidiSequence(param, false);
125 	}
126 	return true;
127 }
128 
cmd_sound(int argc,const char ** argv)129 bool Console::cmd_sound(int argc, const char **argv) {
130 	if (argc < 2) {
131 		debugPrintf("%s id\n", argv[0]);
132 		debugPrintf("Plays the sound with the given ID\n");
133 		return true;
134 	}
135 
136 	int id = strToInt(argv[1]);
137 	if (_vm->_sound->sampleExists(id)) {
138 		if (!TinselV2)
139 			_vm->_sound->playSample(id, Audio::Mixer::kSpeechSoundType);
140 		else
141 			_vm->_sound->playSample(id, 0, false, 0, 0, PRIORITY_TALK, Audio::Mixer::kSpeechSoundType);
142 	} else {
143 		debugPrintf("Sample %d does not exist!\n", id);
144 	}
145 
146 	return true;
147 }
148 
cmd_string(int argc,const char ** argv)149 bool Console::cmd_string(int argc, const char **argv) {
150 	if (argc < 2) {
151 		debugPrintf("%s id\n", argv[0]);
152 		debugPrintf("Prints the string with the given ID\n");
153 		return true;
154 	}
155 
156 	char tmp[TBUFSZ];
157 	int id = strToInt(argv[1]);
158 	LoadStringRes(id, tmp, TBUFSZ);
159 	debugPrintf("%s\n", tmp);
160 
161 	return true;
162 }
163 
164 } // End of namespace Tinsel
165