2013-06-09 16:07:45 +03:00
/* 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 .
2014-02-18 02:34:22 +01:00
*
2013-06-09 16:07:45 +03:00
* 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 .
2014-02-18 02:34:22 +01:00
*
2013-06-09 16:07:45 +03:00
* 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 "neverhood/console.h"
# include "gui/debugger.h"
# include "neverhood/neverhood.h"
# include "neverhood/gamemodule.h"
2013-09-14 12:39:12 +03:00
# include "neverhood/navigationscene.h"
2013-06-09 17:13:23 +03:00
# include "neverhood/scene.h"
2013-09-14 12:39:12 +03:00
# include "neverhood/smackerscene.h"
2013-07-03 05:49:25 +03:00
# include "neverhood/sound.h"
2013-06-11 14:03:44 +03:00
# include "neverhood/modules/module1600.h"
2013-10-01 00:54:42 +03:00
# include "neverhood/modules/module3000_sprites.h"
2013-06-09 16:07:45 +03:00
namespace Neverhood {
Console : : Console ( NeverhoodEngine * vm ) : GUI : : Debugger ( ) , _vm ( vm ) {
2014-05-27 02:04:08 +02:00
registerCmd ( " cheat " , WRAP_METHOD ( Console , Cmd_Cheat ) ) ;
registerCmd ( " checkresource " , WRAP_METHOD ( Console , Cmd_CheckResource ) ) ;
registerCmd ( " dumpresource " , WRAP_METHOD ( Console , Cmd_DumpResource ) ) ;
registerCmd ( " dumpvars " , WRAP_METHOD ( Console , Cmd_Dumpvars ) ) ;
registerCmd ( " playsound " , WRAP_METHOD ( Console , Cmd_PlaySound ) ) ;
registerCmd ( " scene " , WRAP_METHOD ( Console , Cmd_Scene ) ) ;
registerCmd ( " surfaces " , WRAP_METHOD ( Console , Cmd_Surfaces ) ) ;
2013-06-09 16:07:45 +03:00
}
Console : : ~ Console ( ) {
}
2013-09-14 12:39:12 +03:00
bool Console : : Cmd_Scene ( int argc , const char * * argv ) {
if ( argc ! = 3 ) {
int currentModule = _vm - > _gameModule - > getCurrentModuleNum ( ) ;
int previousModule = _vm - > _gameModule - > getPreviousModuleNum ( ) ;
int scenenNum = _vm - > gameState ( ) . sceneNum ;
SceneType sceneType = ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > getSceneType ( ) ;
const char * sceneTypes [ ] = { " normal " , " smacker " , " navigation " } ;
2013-06-09 16:07:45 +03:00
2014-10-28 16:18:11 +02:00
debugPrintf ( " Current module: %d, previous module: %d, scene %d (%s scene) \n " , currentModule , previousModule , scenenNum , sceneTypes [ sceneType ] ) ;
2013-06-09 16:07:45 +03:00
2013-09-14 12:39:12 +03:00
if ( sceneType = = kSceneTypeNormal ) {
Scene * scene = ( Scene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
// Normal scenes have a background and a cursor file hash
2014-05-27 02:04:07 +02:00
debugPrintf ( " Background hash: 0x%x, cursor hash: 0x%x \n " , scene - > getBackgroundFileHash ( ) , scene - > getCursorFileHash ( ) ) ;
2013-09-14 12:39:12 +03:00
} else if ( sceneType = = kSceneTypeSmacker ) {
SmackerScene * scene = ( SmackerScene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
// Smacker scenes have a file hash, or a list of hashes
// TODO: Only the first file hash is shown - any additional hashes, found in
// scenes with a list of hashes (two scenes in module 1100 and the making of
// video) aren't shown yet
2014-05-27 02:04:07 +02:00
debugPrintf ( " File hash: 0x%x \n " , scene - > getSmackerFileHash ( ) ) ;
2013-09-14 12:39:12 +03:00
} else if ( sceneType = = kSceneTypeNavigation ) {
NavigationScene * scene = ( NavigationScene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
// Navigation scenes have a navigation list and its index
NavigationList * navigationList = _vm - > _staticData - > getNavigationList ( scene - > getNavigationListId ( ) ) ;
int navigationIndex = scene - > getGlobalVar ( V_NAVIGATION_INDEX ) ;
NavigationItem curNavigation = ( * navigationList ) [ navigationIndex ] ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Navigation list ID: 0x%x, index: %d \n " , scene - > getNavigationListId ( ) , navigationIndex ) ;
debugPrintf ( " File hash: 0x%x, cursor hash: 0x%x, Smacker hashes: [left: 0x%x, middle: 0x%x, right: 0x%x \n " ,
2013-09-14 12:39:12 +03:00
curNavigation . fileHash , curNavigation . mouseCursorFileHash ,
curNavigation . leftSmackerFileHash , curNavigation . middleSmackerFileHash , curNavigation . rightSmackerFileHash ) ;
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " Use %s <module> <scene> to change scenes \n " , argv [ 0 ] ) ;
debugPrintf ( " Modules are incremental by 100, from 1000 to 3000 \n " ) ;
2013-06-09 16:07:45 +03:00
} else {
2013-06-11 11:39:28 +02:00
int newModule = atoi ( argv [ 1 ] ) ;
int newScene = atoi ( argv [ 2 ] ) ;
2013-06-09 16:07:45 +03:00
2013-06-11 11:39:28 +02:00
_vm - > gameState ( ) . sceneNum = newScene ;
_vm - > _gameModule - > createModule ( newModule , - 1 ) ;
2013-06-09 16:07:45 +03:00
}
return true ;
}
2013-06-09 17:13:23 +03:00
bool Console : : Cmd_Surfaces ( int argc , const char * * argv ) {
if ( _vm - > _gameModule - > _childObject ) {
( ( Scene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ) - > printSurfaces ( this ) ;
}
return true ;
}
2013-06-11 14:03:44 +03:00
bool Console : : Cmd_Cheat ( int argc , const char * * argv ) {
if ( argc < 2 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Cheats for various puzzles in the game \n " ) ;
debugPrintf ( " Use %s <cheatname> to use a cheat. \n " , argv [ 0 ] ) ;
debugPrintf ( " Cheats: \n ------- \n " ) ;
debugPrintf ( " buttons - enables all 3 buttons on the door in the purple building, module 3000, scene 9 \n " ) ;
debugPrintf ( " cannon - sets the correct cannon combination in module 3000, scene 8 \n " ) ;
debugPrintf ( " dice - shows the correct dice combination in the teddy bear puzzle, module 1100, scene 6 \n " ) ;
debugPrintf ( " memory - solves the memory puzzle, module 1400, scene 4 \n " ) ;
debugPrintf ( " music - shows the correct index in the radio music puzzle, module 2800, scene 1 \n " ) ;
debugPrintf ( " radio - enables the radio, module 3000, scene 9 - same as pulling the rightmost cord in the flytrap room \n " ) ;
debugPrintf ( " symbols - solves the symbols puzzle, module 1600, scene 8. Only available in that room \n " ) ;
debugPrintf ( " tubes - shows the correct test tube combination in module 2800, scenes 7 and 10 \n " ) ;
2013-06-11 14:03:44 +03:00
return true ;
}
Common : : String cheatName = argv [ 1 ] ;
2013-06-11 18:26:26 +02:00
int moduleNum = _vm - > _gameModule - > getCurrentModuleNum ( ) ;
int sceneNum = _vm - > gameState ( ) . sceneNum ;
2013-06-11 14:03:44 +03:00
if ( cheatName = = " buttons " ) {
Scene * scene = ( Scene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
scene - > setSubVar ( VA_LOCKS_DISABLED , 0x304008D2 , 1 ) ; // kScene3010ButtonNameHashes[0]
scene - > setSubVar ( VA_LOCKS_DISABLED , 0x40119852 , 1 ) ; // kScene3010ButtonNameHashes[1]
scene - > setSubVar ( VA_LOCKS_DISABLED , 0x01180951 , 1 ) ; // kScene3010ButtonNameHashes[2]
2014-05-27 02:04:07 +02:00
debugPrintf ( " All 3 door buttons have been enabled \n " ) ;
2013-06-11 14:03:44 +03:00
} else if ( cheatName = = " cannon " ) {
Scene * scene = ( Scene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
for ( int i = 0 ; i < 3 ; i + + )
scene - > setSubVar ( VA_CURR_CANNON_SYMBOLS , i , scene - > getSubVar ( VA_GOOD_CANNON_SYMBOLS_1 , i ) ) ;
for ( int i = 3 ; i < 6 ; i + + )
scene - > setSubVar ( VA_CURR_CANNON_SYMBOLS , i , scene - > getSubVar ( VA_GOOD_CANNON_SYMBOLS_2 , i - 3 ) ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Puzzle solved \n " ) ;
2013-06-11 14:03:44 +03:00
} else if ( cheatName = = " dice " ) {
Scene * scene = ( Scene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Good: (%d %d %d), current: (%d %d %d) \n " ,
2013-06-11 14:03:44 +03:00
scene - > getSubVar ( VA_GOOD_DICE_NUMBERS , 0 ) , scene - > getSubVar ( VA_GOOD_DICE_NUMBERS , 1 ) , scene - > getSubVar ( VA_GOOD_DICE_NUMBERS , 2 ) ,
scene - > getSubVar ( VA_CURR_DICE_NUMBERS , 0 ) , scene - > getSubVar ( VA_CURR_DICE_NUMBERS , 1 ) , scene - > getSubVar ( VA_CURR_DICE_NUMBERS , 2 )
) ;
} else if ( cheatName = = " memory " ) {
Scene * scene = ( Scene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
// Autosolve all tiles and leave only two matching tiles closed
for ( int i = 0 ; i < 48 ; i + + )
scene - > setSubVar ( VA_IS_TILE_MATCH , i , 1 ) ;
// Close the top left tile
scene - > setSubVar ( VA_IS_TILE_MATCH , 0 , 0 ) ;
// Find and close the pair of the top left tile
for ( int i = 0 ; i < 48 ; i + + ) {
if ( i ! = 0 & & scene - > getSubVar ( VA_TILE_SYMBOLS , i ) = = scene - > getSubVar ( VA_TILE_SYMBOLS , 0 ) ) {
scene - > setSubVar ( VA_IS_TILE_MATCH , i , 0 ) ;
break ;
}
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " Puzzle solved \n " ) ;
2013-06-12 11:18:27 +03:00
} else if ( cheatName = = " music " ) {
Scene * scene = ( Scene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Good music index: %d, current radio music index: %d \n " , scene - > getGlobalVar ( V_CURR_RADIO_MUSIC_INDEX ) , scene - > getGlobalVar ( V_GOOD_RADIO_MUSIC_INDEX ) ) ;
2013-06-11 14:03:44 +03:00
} else if ( cheatName = = " radio " ) {
Scene * scene = ( Scene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
scene - > setGlobalVar ( V_RADIO_ENABLED , 1 ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " The radio has been enabled \n " ) ;
2013-06-11 14:03:44 +03:00
} else if ( cheatName = = " symbols " ) {
2013-06-11 18:26:26 +02:00
if ( moduleNum = = 1600 & & sceneNum = = 8 ) {
2013-06-11 14:03:44 +03:00
Scene1609 * scene = ( ( Scene1609 * ) ( ( Module1600 * ) _vm - > _gameModule - > _childObject ) - > _childObject ) ;
for ( int index = 0 ; index < 12 ; index + + ) {
scene - > _asSymbols [ index ] - > change ( ( int ) scene - > getSubVar ( VA_CODE_SYMBOLS , index ) + 12 , index = = ( int ) scene - > getSubVar ( VA_CODE_SYMBOLS , scene - > _noisySymbolIndex ) ) ;
}
scene - > _changeCurrentSymbol = false ;
scene - > _symbolPosition = 11 ;
2013-06-12 11:25:19 +03:00
scene - > _countdown1 = 36 ;
2013-06-11 14:03:44 +03:00
2014-05-27 02:04:07 +02:00
debugPrintf ( " Puzzle solved \n " ) ;
2013-06-11 14:03:44 +03:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Only available in module 1600, scene 8 \n " ) ;
2013-06-11 14:03:44 +03:00
}
} else if ( cheatName = = " tubes " ) {
Scene * scene = ( Scene * ) ( ( GameModule * ) _vm - > _gameModule - > _childObject ) - > _childObject ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Tube set 1: %d %d %d \n " , scene - > getSubVar ( VA_GOOD_TEST_TUBES_LEVEL_1 , 0 ) , scene - > getSubVar ( VA_GOOD_TEST_TUBES_LEVEL_1 , 1 ) , scene - > getSubVar ( VA_GOOD_TEST_TUBES_LEVEL_1 , 2 ) ) ;
debugPrintf ( " Tube set 2: %d %d %d \n " , scene - > getSubVar ( VA_GOOD_TEST_TUBES_LEVEL_2 , 0 ) , scene - > getSubVar ( VA_GOOD_TEST_TUBES_LEVEL_2 , 1 ) , scene - > getSubVar ( VA_GOOD_TEST_TUBES_LEVEL_2 , 2 ) ) ;
2013-06-11 14:03:44 +03:00
}
return true ;
}
2013-06-12 11:34:49 +03:00
bool Console : : Cmd_Dumpvars ( int argc , const char * * argv ) {
_vm - > _gameVars - > dumpVars ( this ) ;
return true ;
}
2013-07-03 05:49:25 +03:00
bool Console : : Cmd_PlaySound ( int argc , const char * * argv ) {
if ( argc < 2 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Usage: %s <sound hash> \n " , argv [ 0 ] ) ;
2013-07-03 05:49:25 +03:00
} else {
uint32 soundHash = strtol ( argv [ 1 ] , NULL , 0 ) ;
AudioResourceManSoundItem * soundItem = new AudioResourceManSoundItem ( _vm , soundHash ) ;
soundItem - > setVolume ( 100 ) ;
soundItem - > playSound ( false ) ;
while ( soundItem - > isPlaying ( ) ) {
_vm - > _system - > delayMillis ( 10 ) ;
}
delete soundItem ;
}
return true ;
}
2013-09-14 12:34:03 +03:00
bool Console : : Cmd_CheckResource ( int argc , const char * * argv ) {
const char * resourceNames [ ] = { " unknown " , " unknown " , " bitmap " , " palette " , " animation " , " data " , " text " , " sound " , " music " , " unknown " , " video " } ;
if ( argc < 2 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Gets information about a resource \n " ) ;
debugPrintf ( " Usage: %s <resource hash> \n " , argv [ 0 ] ) ;
2013-09-14 12:34:03 +03:00
} else {
uint32 resourceHash = strtol ( argv [ 1 ] , NULL , 0 ) ;
ResourceHandle handle ;
_vm - > _res - > queryResource ( resourceHash , handle ) ;
if ( ! handle . isValid ( ) ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Invalid resource hash \n " ) ;
2013-09-14 12:34:03 +03:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Resource type: %d (%s). Size: %d bytes \n " , handle . type ( ) , resourceNames [ handle . type ( ) ] , handle . size ( ) ) ;
2013-09-14 12:34:03 +03:00
}
}
return true ;
}
bool Console : : Cmd_DumpResource ( int argc , const char * * argv ) {
if ( argc < 3 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Dumps a resource to disk \n " ) ;
debugPrintf ( " Usage: %s <resource hash> <output file> \n " , argv [ 0 ] ) ;
2013-09-14 12:34:03 +03:00
} else {
uint32 resourceHash = strtol ( argv [ 1 ] , NULL , 0 ) ;
const char * outFileName = argv [ 2 ] ;
ResourceHandle handle ;
_vm - > _res - > queryResource ( resourceHash , handle ) ;
if ( ! handle . isValid ( ) ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Invalid resource hash \n " ) ;
2013-09-14 12:34:03 +03:00
} else {
2013-09-26 10:54:30 +03:00
_vm - > _res - > loadResource ( handle , _vm - > applyResourceFixes ( ) ) ;
2013-09-14 12:34:03 +03:00
Common : : DumpFile outFile ;
outFile . open ( outFileName ) ;
outFile . write ( handle . data ( ) , handle . size ( ) ) ;
outFile . finalize ( ) ;
outFile . close ( ) ;
_vm - > _res - > unloadResource ( handle ) ;
}
}
return true ;
}
2013-06-09 16:07:45 +03:00
} // End of namespace Neverhood