2007-05-30 21:56:52 +00: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 .
2005-12-09 14:52:31 +00:00
*
* 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:21 +01:00
*
2005-12-09 14:52:31 +00:00
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
2008-01-05 12:45:14 +00:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
2005-12-09 14:52:31 +00:00
* GNU General Public License for more details .
2014-02-18 02:34:21 +01:00
*
2005-12-09 14:52:31 +00: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 "kyra/debugger.h"
2008-05-11 22:32:37 +00:00
# include "kyra/kyra_lok.h"
2008-05-02 14:46:30 +00:00
# include "kyra/kyra_hof.h"
2007-07-29 16:33:11 +00:00
# include "kyra/timer.h"
2008-03-27 15:27:31 +00:00
# include "kyra/resource.h"
2009-06-01 22:03:27 +00:00
# include "kyra/lol.h"
2011-11-06 17:53:52 +01:00
# include "kyra/eobcommon.h"
2005-12-09 14:52:31 +00:00
2011-04-28 15:39:17 +02:00
# include "common/system.h"
2012-01-15 01:13:03 +01:00
# include "common/config-manager.h"
# include "gui/message.h"
2011-04-28 15:39:17 +02:00
2005-12-09 14:52:31 +00:00
namespace Kyra {
2008-05-11 23:16:50 +00:00
Debugger : : Debugger ( KyraEngine_v1 * vm )
2011-11-18 03:47:51 +01:00
: : : GUI : : Debugger ( ) , _vm ( vm ) {
}
2007-09-23 23:37:01 +00:00
2011-11-18 03:47:51 +01:00
void Debugger : : initialize ( ) {
2014-05-27 02:04:08 +02:00
registerCmd ( " continue " , WRAP_METHOD ( Debugger , cmdExit ) ) ;
2014-05-27 02:04:08 +02:00
registerCmd ( " screen_debug_mode " , WRAP_METHOD ( Debugger , cmdSetScreenDebug ) ) ;
registerCmd ( " load_palette " , WRAP_METHOD ( Debugger , cmdLoadPalette ) ) ;
registerCmd ( " facings " , WRAP_METHOD ( Debugger , cmdShowFacings ) ) ;
registerCmd ( " gamespeed " , WRAP_METHOD ( Debugger , cmdGameSpeed ) ) ;
registerCmd ( " flags " , WRAP_METHOD ( Debugger , cmdListFlags ) ) ;
registerCmd ( " toggleflag " , WRAP_METHOD ( Debugger , cmdToggleFlag ) ) ;
registerCmd ( " queryflag " , WRAP_METHOD ( Debugger , cmdQueryFlag ) ) ;
registerCmd ( " timers " , WRAP_METHOD ( Debugger , cmdListTimers ) ) ;
registerCmd ( " settimercountdown " , WRAP_METHOD ( Debugger , cmdSetTimerCountdown ) ) ;
}
bool Debugger : : cmdSetScreenDebug ( int argc , const char * * argv ) {
2007-09-23 23:37:01 +00:00
if ( argc > 1 ) {
if ( scumm_stricmp ( argv [ 1 ] , " enable " ) = = 0 )
_vm - > screen ( ) - > enableScreenDebug ( true ) ;
else if ( scumm_stricmp ( argv [ 1 ] , " disable " ) = = 0 )
_vm - > screen ( ) - > enableScreenDebug ( false ) ;
else
2014-05-27 02:04:07 +02:00
debugPrintf ( " Use screen_debug_mode <enable/disable> to enable or disable it. \n " ) ;
2007-09-23 23:37:01 +00:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Screen debug mode is %s. \n " , ( _vm - > screen ( ) - > queryScreenDebug ( ) ? " enabled " : " disabled " ) ) ;
debugPrintf ( " Use screen_debug_mode <enable/disable> to enable or disable it. \n " ) ;
2007-09-23 23:37:01 +00:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger : : cmdLoadPalette ( int argc , const char * * argv ) {
2009-06-22 02:36:54 +00:00
Palette palette ( _vm - > screen ( ) - > getPalette ( 0 ) . getNumColors ( ) ) ;
2008-03-27 15:27:31 +00:00
if ( argc < = 1 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Use load_palette <file> [start_col] [end_col] \n " ) ;
2008-03-27 15:27:31 +00:00
return true ;
}
2010-08-24 13:41:24 +00:00
if ( _vm - > game ( ) ! = GI_KYRA1 & & _vm - > resource ( ) - > getFileSize ( argv [ 1 ] ) ! = 768 ) {
2011-07-01 17:05:39 +02:00
uint8 * buffer = new uint8 [ 320 * 200 * sizeof ( uint8 ) ] ;
2011-06-06 01:14:48 +08:00
if ( ! buffer ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " ERROR: Cannot allocate buffer for screen region! \n " ) ;
2011-06-06 01:14:48 +08:00
return true ;
}
2008-04-12 23:17:21 +00:00
_vm - > screen ( ) - > copyRegionToBuffer ( 5 , 0 , 0 , 320 , 200 , buffer ) ;
2008-03-27 15:27:31 +00:00
_vm - > screen ( ) - > loadBitmap ( argv [ 1 ] , 5 , 5 , 0 ) ;
2009-06-22 02:36:54 +00:00
palette . copy ( _vm - > screen ( ) - > getCPagePtr ( 5 ) , 0 , 256 ) ;
2008-04-12 23:17:21 +00:00
_vm - > screen ( ) - > copyBlockToPage ( 5 , 0 , 0 , 320 , 200 , buffer ) ;
2011-06-06 01:14:48 +08:00
2011-07-01 17:05:39 +02:00
delete [ ] buffer ;
2009-06-22 02:37:41 +00:00
} else if ( ! _vm - > screen ( ) - > loadPalette ( argv [ 1 ] , palette ) ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " ERROR: Palette '%s' not found! \n " , argv [ 1 ] ) ;
2008-03-27 15:27:31 +00:00
return true ;
}
int startCol = 0 ;
2009-06-22 02:36:54 +00:00
int endCol = palette . getNumColors ( ) ;
2008-03-27 15:27:31 +00:00
if ( argc > 2 )
2009-06-22 02:36:54 +00:00
startCol = MIN ( palette . getNumColors ( ) , MAX ( 0 , atoi ( argv [ 2 ] ) ) ) ;
2008-03-27 15:27:31 +00:00
if ( argc > 3 )
2009-06-22 02:36:54 +00:00
endCol = MIN ( palette . getNumColors ( ) , MAX ( 0 , atoi ( argv [ 3 ] ) ) ) ;
2008-03-27 15:27:31 +00:00
if ( startCol > 0 )
2009-06-22 02:36:54 +00:00
palette . copy ( _vm - > screen ( ) - > getPalette ( 0 ) , 0 , startCol ) ;
if ( endCol < palette . getNumColors ( ) )
palette . copy ( _vm - > screen ( ) - > getPalette ( 0 ) , endCol ) ;
2008-03-27 15:27:31 +00:00
_vm - > screen ( ) - > setScreenPalette ( palette ) ;
_vm - > screen ( ) - > updateScreen ( ) ;
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger : : cmdShowFacings ( int argc , const char * * argv ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Facing directions: \n " ) ;
debugPrintf ( " 7 0 1 \n " ) ;
debugPrintf ( " \\ | / \n " ) ;
debugPrintf ( " 6--*--2 \n " ) ;
debugPrintf ( " / | \\ \n " ) ;
debugPrintf ( " 5 4 3 \n " ) ;
2007-09-24 21:58:11 +00:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger : : cmdGameSpeed ( int argc , const char * * argv ) {
2008-03-27 16:12:48 +00:00
if ( argc = = 2 ) {
int val = atoi ( argv [ 1 ] ) ;
if ( val < 1 | | val > 1000 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " speed must lie between 1 and 1000 (default: 60) \n " ) ;
2008-03-27 16:12:48 +00:00
return true ;
}
_vm - > _tickLength = ( uint8 ) ( 1000.0 / val ) ;
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: gamespeed <value> \n " ) ;
2008-03-27 16:12:48 +00:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger : : cmdListFlags ( int argc , const char * * argv ) {
2011-12-26 21:19:29 +01:00
for ( int i = 0 , p = 0 ; i < ( int ) sizeof ( _vm - > _flagsTable ) * 8 ; i + + , + + p ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " (%-3i): %-2i " , i , _vm - > queryGameFlag ( i ) ) ;
2009-06-01 22:03:27 +00:00
if ( p = = 5 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n " ) ;
2009-06-01 22:03:27 +00:00
p - = 6 ;
}
2008-03-27 22:05:13 +00:00
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n " ) ;
2008-03-27 22:05:13 +00:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger : : cmdToggleFlag ( int argc , const char * * argv ) {
2008-03-27 22:05:13 +00:00
if ( argc > 1 ) {
uint flag = atoi ( argv [ 1 ] ) ;
if ( _vm - > queryGameFlag ( flag ) )
_vm - > resetGameFlag ( flag ) ;
else
_vm - > setGameFlag ( flag ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Flag %i is now %i \n " , flag , _vm - > queryGameFlag ( flag ) ) ;
2008-03-27 22:05:13 +00:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: toggleflag <flag> \n " ) ;
2008-03-27 22:05:13 +00:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger : : cmdQueryFlag ( int argc , const char * * argv ) {
2008-03-27 22:05:13 +00:00
if ( argc > 1 ) {
uint flag = atoi ( argv [ 1 ] ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Flag %i is %i \n " , flag , _vm - > queryGameFlag ( flag ) ) ;
2008-03-27 22:05:13 +00:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: queryflag <flag> \n " ) ;
2008-03-27 22:05:13 +00:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger : : cmdListTimers ( int argc , const char * * argv ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Current time: %-8u \n " , g_system - > getMillis ( ) ) ;
2008-03-27 22:05:13 +00:00
for ( int i = 0 ; i < _vm - > timer ( ) - > count ( ) ; i + + )
2014-05-27 02:04:07 +02:00
debugPrintf ( " Timer %-2i: Active: %-3s Countdown: %-6i %-8u \n " , i , _vm - > timer ( ) - > isEnabled ( i ) ? " Yes " : " No " , _vm - > timer ( ) - > getDelay ( i ) , _vm - > timer ( ) - > getNextRun ( i ) ) ;
2008-03-27 22:05:13 +00:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger : : cmdSetTimerCountdown ( int argc , const char * * argv ) {
2008-03-27 22:05:13 +00:00
if ( argc > 2 ) {
uint timer = atoi ( argv [ 1 ] ) ;
uint countdown = atoi ( argv [ 2 ] ) ;
_vm - > timer ( ) - > setCountdown ( timer , countdown ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Timer %i now has countdown %i \n " , timer , _vm - > timer ( ) - > getDelay ( timer ) ) ;
2008-03-27 22:05:13 +00:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: settimercountdown <timer> <countdown> \n " ) ;
2008-03-27 22:05:13 +00:00
}
return true ;
}
2007-09-23 23:37:01 +00:00
# pragma mark -
2008-05-11 22:32:37 +00:00
Debugger_LoK : : Debugger_LoK ( KyraEngine_LoK * vm )
2008-04-25 16:02:20 +00:00
: Debugger ( vm ) , _vm ( vm ) {
2011-11-18 03:47:51 +01:00
}
void Debugger_LoK : : initialize ( ) {
2014-05-27 02:04:08 +02:00
registerCmd ( " enter " , WRAP_METHOD ( Debugger_LoK , cmdEnterRoom ) ) ;
registerCmd ( " scenes " , WRAP_METHOD ( Debugger_LoK , cmdListScenes ) ) ;
registerCmd ( " give " , WRAP_METHOD ( Debugger_LoK , cmdGiveItem ) ) ;
registerCmd ( " birthstones " , WRAP_METHOD ( Debugger_LoK , cmdListBirthstones ) ) ;
2012-01-14 16:39:24 +01:00
Debugger : : initialize ( ) ;
2005-12-09 14:52:31 +00:00
}
2014-05-27 02:04:08 +02:00
bool Debugger_LoK : : cmdEnterRoom ( int argc , const char * * argv ) {
2005-12-09 14:52:31 +00:00
uint direction = 0 ;
if ( argc > 1 ) {
2006-01-01 10:49:27 +00:00
int room = atoi ( argv [ 1 ] ) ;
2005-12-09 14:52:31 +00:00
2005-12-31 15:41:37 +00:00
// game will crash if entering a non-existent room
if ( room > = _vm - > _roomTableSize ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " room number must be any value between (including) 0 and %d \n " , _vm - > _roomTableSize - 1 ) ;
2005-12-31 15:41:37 +00:00
return true ;
}
if ( argc > 2 ) {
2005-12-09 14:52:31 +00:00
direction = atoi ( argv [ 2 ] ) ;
2005-12-31 15:41:37 +00:00
} else {
2007-09-24 21:58:11 +00:00
if ( _vm - > _roomTable [ room ] . northExit ! = 0xFFFF )
2005-12-09 14:52:31 +00:00
direction = 3 ;
2007-09-24 21:58:11 +00:00
else if ( _vm - > _roomTable [ room ] . eastExit ! = 0xFFFF )
2005-12-09 14:52:31 +00:00
direction = 4 ;
2007-09-24 21:58:11 +00:00
else if ( _vm - > _roomTable [ room ] . southExit ! = 0xFFFF )
2005-12-09 14:52:31 +00:00
direction = 1 ;
2007-09-24 21:58:11 +00:00
else if ( _vm - > _roomTable [ room ] . westExit ! = 0xFFFF )
2005-12-09 14:52:31 +00:00
direction = 2 ;
}
_vm - > _system - > hideOverlay ( ) ;
_vm - > _currentCharacter - > facing = direction ;
2007-09-19 08:40:12 +00:00
2005-12-09 14:52:31 +00:00
_vm - > enterNewScene ( room , _vm - > _currentCharacter - > facing , 0 , 0 , 1 ) ;
2008-04-25 16:02:20 +00:00
while ( ! _vm - > _screen - > isMouseVisible ( ) )
_vm - > _screen - > showMouse ( ) ;
2006-01-10 02:43:30 +00:00
2010-07-17 18:38:42 +00:00
detach ( ) ;
2005-12-09 14:52:31 +00:00
return false ;
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: room <roomnum> <direction> \n " ) ;
2005-12-09 14:52:31 +00:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_LoK : : cmdListScenes ( int argc , const char * * argv ) {
2005-12-09 14:52:31 +00:00
for ( int i = 0 ; i < _vm - > _roomTableSize ; i + + ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " %-3i: %-10s " , i , _vm - > _roomFilenameTable [ _vm - > _roomTable [ i ] . nameIndex ] ) ;
2007-09-19 08:40:12 +00:00
if ( ! ( i % 8 ) )
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n " ) ;
2005-12-09 14:52:31 +00:00
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n " ) ;
debugPrintf ( " Current room: %i \n " , _vm - > _currentRoom ) ;
2005-12-09 14:52:31 +00:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_LoK : : cmdGiveItem ( int argc , const char * * argv ) {
2005-12-31 15:41:37 +00:00
if ( argc = = 2 ) {
2005-12-09 23:02:16 +00:00
int item = atoi ( argv [ 1 ] ) ;
2005-12-31 15:41:37 +00:00
// Kyrandia 1 has only 108 items (-1 to 106), otherwise it will crash
if ( item < - 1 | | item > 106 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " 'itemid' must be any value between (including) -1 and 106 \n " ) ;
2005-12-31 15:41:37 +00:00
return true ;
}
2005-12-09 23:02:16 +00:00
_vm - > setMouseItem ( item ) ;
_vm - > _itemInHand = item ;
2007-04-15 16:41:20 +00:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: give <itemid> \n " ) ;
2007-04-15 16:41:20 +00:00
}
2007-09-19 08:40:12 +00:00
2005-12-09 23:02:16 +00:00
return true ;
}
2007-09-23 23:00:54 +00:00
2014-05-27 02:04:08 +02:00
bool Debugger_LoK : : cmdListBirthstones ( int argc , const char * * argv ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Needed birthstone gems: \n " ) ;
2007-09-23 23:00:54 +00:00
for ( int i = 0 ; i < ARRAYSIZE ( _vm - > _birthstoneGemTable ) ; + + i )
2014-05-27 02:04:07 +02:00
debugPrintf ( " %-3d '%s' \n " , _vm - > _birthstoneGemTable [ i ] , _vm - > _itemList [ _vm - > _birthstoneGemTable [ i ] ] ) ;
2007-09-23 23:00:54 +00:00
return true ;
}
2007-09-24 20:02:08 +00:00
# pragma mark -
2008-05-04 15:56:28 +00:00
Debugger_v2 : : Debugger_v2 ( KyraEngine_v2 * vm ) : Debugger ( vm ) , _vm ( vm ) {
2011-11-18 03:47:51 +01:00
}
void Debugger_v2 : : initialize ( ) {
2014-05-27 02:04:08 +02:00
registerCmd ( " character_info " , WRAP_METHOD ( Debugger_v2 , cmdCharacterInfo ) ) ;
registerCmd ( " enter " , WRAP_METHOD ( Debugger_v2 , cmdEnterScene ) ) ;
registerCmd ( " scenes " , WRAP_METHOD ( Debugger_v2 , cmdListScenes ) ) ;
registerCmd ( " scene_info " , WRAP_METHOD ( Debugger_v2 , cmdSceneInfo ) ) ;
registerCmd ( " scene_to_facing " , WRAP_METHOD ( Debugger_v2 , cmdSceneToFacing ) ) ;
registerCmd ( " give " , WRAP_METHOD ( Debugger_v2 , cmdGiveItem ) ) ;
2012-01-14 16:39:24 +01:00
Debugger : : initialize ( ) ;
2007-09-24 21:58:11 +00:00
}
2014-05-27 02:04:08 +02:00
bool Debugger_v2 : : cmdEnterScene ( int argc , const char * * argv ) {
2007-09-24 21:58:11 +00:00
uint direction = 0 ;
if ( argc > 1 ) {
int scene = atoi ( argv [ 1 ] ) ;
2008-01-27 19:47:41 +00:00
// game will crash if entering a non-existent scene
2007-09-24 21:58:11 +00:00
if ( scene > = _vm - > _sceneListSize ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " scene number must be any value between (including) 0 and %d \n " , _vm - > _sceneListSize - 1 ) ;
2007-09-24 21:58:11 +00:00
return true ;
}
if ( argc > 2 ) {
direction = atoi ( argv [ 2 ] ) ;
} else {
if ( _vm - > _sceneList [ scene ] . exit1 ! = 0xFFFF )
direction = 4 ;
else if ( _vm - > _sceneList [ scene ] . exit2 ! = 0xFFFF )
direction = 6 ;
else if ( _vm - > _sceneList [ scene ] . exit3 ! = 0xFFFF )
direction = 0 ;
else if ( _vm - > _sceneList [ scene ] . exit4 ! = 0xFFFF )
direction = 2 ;
}
_vm - > _system - > hideOverlay ( ) ;
_vm - > _mainCharacter . facing = direction ;
_vm - > enterNewScene ( scene , _vm - > _mainCharacter . facing , 0 , 0 , 1 ) ;
2008-05-04 15:56:28 +00:00
while ( ! _vm - > screen_v2 ( ) - > isMouseVisible ( ) )
_vm - > screen_v2 ( ) - > showMouse ( ) ;
2007-09-24 21:58:11 +00:00
2010-07-17 18:38:42 +00:00
detach ( ) ;
2007-09-24 21:58:11 +00:00
return false ;
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: %s <scenenum> <direction> \n " , argv [ 0 ] ) ;
2007-09-24 21:58:11 +00:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_v2 : : cmdListScenes ( int argc , const char * * argv ) {
2007-09-24 21:58:11 +00:00
int shown = 1 ;
for ( int i = 0 ; i < _vm - > _sceneListSize ; + + i ) {
2008-05-02 14:46:30 +00:00
if ( _vm - > _sceneList [ i ] . filename1 [ 0 ] ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " %-2i: %-10s " , i , _vm - > _sceneList [ i ] . filename1 ) ;
2007-09-24 21:58:11 +00:00
if ( ! ( shown % 5 ) )
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n " ) ;
2007-09-24 21:58:11 +00:00
+ + shown ;
}
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n " ) ;
debugPrintf ( " Current scene: %i \n " , _vm - > _currentScene ) ;
2007-09-24 21:58:11 +00:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_v2 : : cmdSceneInfo ( int argc , const char * * argv ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Current scene: %d '%s' \n " , _vm - > _currentScene , _vm - > _sceneList [ _vm - > _currentScene ] . filename1 ) ;
debugPrintf ( " \n " ) ;
debugPrintf ( " Exit information: \n " ) ;
debugPrintf ( " Exit1: leads to %d, position %dx%d \n " , int16 ( _vm - > _sceneExit1 ) , _vm - > _sceneEnterX1 , _vm - > _sceneEnterY1 ) ;
debugPrintf ( " Exit2: leads to %d, position %dx%d \n " , int16 ( _vm - > _sceneExit2 ) , _vm - > _sceneEnterX2 , _vm - > _sceneEnterY2 ) ;
debugPrintf ( " Exit3: leads to %d, position %dx%d \n " , int16 ( _vm - > _sceneExit3 ) , _vm - > _sceneEnterX3 , _vm - > _sceneEnterY3 ) ;
debugPrintf ( " Exit4: leads to %d, position %dx%d \n " , int16 ( _vm - > _sceneExit4 ) , _vm - > _sceneEnterX4 , _vm - > _sceneEnterY4 ) ;
debugPrintf ( " Special exit information: \n " ) ;
2007-09-24 21:58:11 +00:00
if ( ! _vm - > _specialExitCount ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " No special exits. \n " ) ;
2007-09-24 21:58:11 +00:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " This scene has %d special exits. \n " , _vm - > _specialExitCount ) ;
2007-09-24 21:58:11 +00:00
for ( int i = 0 ; i < _vm - > _specialExitCount ; + + i ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " SpecialExit%d: facing %d, position (x1/y1/x2/y2): %d/%d/%d/%d \n " , i ,
2011-12-26 21:19:29 +01:00
_vm - > _specialExitTable [ 20 + i ] , _vm - > _specialExitTable [ 0 + i ] , _vm - > _specialExitTable [ 5 + i ] ,
_vm - > _specialExitTable [ 10 + i ] , _vm - > _specialExitTable [ 15 + i ] ) ;
2007-09-24 21:58:11 +00:00
}
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_v2 : : cmdCharacterInfo ( int argc , const char * * argv ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Main character is in scene: %d '%s' \n " , _vm - > _mainCharacter . sceneId , _vm - > _sceneList [ _vm - > _mainCharacter . sceneId ] . filename1 ) ;
debugPrintf ( " Position: %dx%d \n " , _vm - > _mainCharacter . x1 , _vm - > _mainCharacter . y1 ) ;
debugPrintf ( " Facing: %d \n " , _vm - > _mainCharacter . facing ) ;
debugPrintf ( " Inventory: \n " ) ;
2007-09-24 21:58:11 +00:00
for ( int i = 0 ; i < 20 ; + + i ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " %-2d " , int8 ( _vm - > _mainCharacter . inventory [ i ] ) ) ;
2007-09-24 21:58:11 +00:00
if ( i = = 9 | | i = = 19 )
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n " ) ;
2007-09-24 21:58:11 +00:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_v2 : : cmdSceneToFacing ( int argc , const char * * argv ) {
2007-09-24 21:58:11 +00:00
if ( argc = = 2 ) {
int facing = atoi ( argv [ 1 ] ) ;
int16 exit = - 1 ;
switch ( facing ) {
case 0 : case 1 : case 7 :
exit = _vm - > _sceneList [ _vm - > _currentScene ] . exit1 ;
break ;
case 6 :
exit = _vm - > _sceneList [ _vm - > _currentScene ] . exit2 ;
break ;
case 3 : case 4 : case 5 :
exit = _vm - > _sceneList [ _vm - > _currentScene ] . exit3 ;
break ;
case 2 :
exit = _vm - > _sceneList [ _vm - > _currentScene ] . exit4 ;
break ;
default :
break ;
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " Exit to facing %d leads to room %d. \n " , facing , exit ) ;
2007-09-24 21:58:11 +00:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Usage: %s <facing> \n " , argv [ 0 ] ) ;
2007-09-24 21:58:11 +00:00
}
return true ;
2007-09-24 20:02:08 +00:00
}
2014-05-27 02:04:08 +02:00
bool Debugger_v2 : : cmdGiveItem ( int argc , const char * * argv ) {
2008-03-09 14:46:24 +00:00
if ( argc = = 2 ) {
int item = atoi ( argv [ 1 ] ) ;
2008-05-06 20:55:33 +00:00
if ( item < - 1 | | item > _vm - > engineDesc ( ) . maxItemId ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " itemid must be any value between (including) -1 and %d \n " , _vm - > engineDesc ( ) . maxItemId ) ;
2008-03-09 14:46:24 +00:00
return true ;
}
_vm - > setHandItem ( item ) ;
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: give <itemid> \n " ) ;
2008-03-09 14:46:24 +00:00
}
return true ;
}
2008-05-04 15:56:28 +00:00
# pragma mark -
Debugger_HoF : : Debugger_HoF ( KyraEngine_HoF * vm ) : Debugger_v2 ( vm ) , _vm ( vm ) {
2011-11-18 03:47:51 +01:00
}
void Debugger_HoF : : initialize ( ) {
2014-05-27 02:04:08 +02:00
registerCmd ( " pass_codes " , WRAP_METHOD ( Debugger_HoF , cmdPasscodes ) ) ;
2012-01-14 16:39:24 +01:00
Debugger_v2 : : initialize ( ) ;
2008-05-04 15:56:28 +00:00
}
2014-05-27 02:04:08 +02:00
bool Debugger_HoF : : cmdPasscodes ( int argc , const char * * argv ) {
2008-03-17 01:34:24 +00:00
if ( argc = = 2 ) {
int val = atoi ( argv [ 1 ] ) ;
if ( val < 0 | | val > 1 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " value must be either 1 (on) or 0 (off) \n " ) ;
2008-03-17 01:34:24 +00:00
return true ;
}
2009-01-01 15:06:43 +00:00
_vm - > _dbgPass = val ;
2008-03-17 01:34:24 +00:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: pass_codes <0/1> \n " ) ;
2008-03-17 01:34:24 +00:00
}
return true ;
}
2009-06-01 22:03:27 +00:00
# pragma mark -
2009-06-02 11:58:30 +00:00
# ifdef ENABLE_LOL
2009-06-01 22:03:27 +00:00
Debugger_LoL : : Debugger_LoL ( LoLEngine * vm ) : Debugger ( vm ) , _vm ( vm ) {
}
2009-06-02 11:58:30 +00:00
# endif // ENABLE_LOL
2009-06-01 22:03:27 +00:00
2011-11-06 17:53:52 +01:00
# ifdef ENABLE_EOB
2011-12-12 16:23:01 +01:00
Debugger_EoB : : Debugger_EoB ( EoBCoreEngine * vm ) : Debugger ( vm ) , _vm ( vm ) {
2011-11-06 17:53:52 +01:00
}
2012-01-15 01:13:03 +01:00
void Debugger_EoB : : initialize ( ) {
2014-05-27 02:04:08 +02:00
registerCmd ( " import_savefile " , WRAP_METHOD ( Debugger_EoB , cmdImportSaveFile ) ) ;
registerCmd ( " save_original " , WRAP_METHOD ( Debugger_EoB , cmdSaveOriginal ) ) ;
registerCmd ( " list_monsters " , WRAP_METHOD ( Debugger_EoB , cmdListMonsters ) ) ;
registerCmd ( " show_position " , WRAP_METHOD ( Debugger_EoB , cmdShowPosition ) ) ;
registerCmd ( " set_position " , WRAP_METHOD ( Debugger_EoB , cmdSetPosition ) ) ;
registerCmd ( " open_door " , WRAP_METHOD ( Debugger_EoB , cmdOpenDoor ) ) ;
registerCmd ( " close_door " , WRAP_METHOD ( Debugger_EoB , cmdCloseDoor ) ) ;
registerCmd ( " list_flags " , WRAP_METHOD ( Debugger_EoB , cmdListFlags ) ) ;
registerCmd ( " set_flag " , WRAP_METHOD ( Debugger_EoB , cmdSetFlag ) ) ;
registerCmd ( " clear_flag " , WRAP_METHOD ( Debugger_EoB , cmdClearFlag ) ) ;
}
bool Debugger_EoB : : cmdImportSaveFile ( int argc , const char * * argv ) {
2012-01-16 16:18:26 +01:00
if ( ! _vm - > _allowImport ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " This command only works from the main menu. \n " ) ;
2012-01-16 16:18:26 +01:00
return true ;
}
2012-01-15 01:13:03 +01:00
if ( argc = = 3 ) {
int slot = atoi ( argv [ 1 ] ) ;
if ( slot < - 1 | | slot > 989 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " slot must be between (including) -1 and 989 \n " ) ;
2012-01-15 01:13:03 +01:00
return true ;
}
2014-05-27 02:04:07 +02:00
debugPrintf ( _vm - > importOriginalSaveFile ( slot , argv [ 2 ] ) ? " Success. \n " : " Failure. \n " ) ;
2012-01-15 01:13:03 +01:00
_vm - > loadItemDefs ( ) ;
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: import_savefile <dest slot> <source file> \n (Imports source save game file to dest slot.) \n import_savefile -1 \n (Imports all original save game files found and puts them into the first available slots.) \n \n " ) ;
2012-01-15 01:13:03 +01:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_EoB : : cmdSaveOriginal ( int argc , const char * * argv ) {
2013-04-07 22:38:25 +02:00
if ( ! _vm - > _runFlag ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " This command doesn't work during intro or outro sequences, \n from the main menu or from the character generation. \n " ) ;
2013-04-07 22:38:25 +02:00
return true ;
}
Common : : String dir = ConfMan . get ( " savepath " ) ;
if ( dir = = " None " )
dir . clear ( ) ;
Common : : FSNode nd ( dir ) ;
if ( ! nd . isDirectory ( ) )
return false ;
if ( _vm - > game ( ) = = GI_EOB1 ) {
if ( argc = = 1 ) {
if ( _vm - > saveAsOriginalSaveFile ( ) ) {
Common : : FSNode nf = nd . getChild ( Common : : String : : format ( " EOBDATA.SAV " ) ) ;
if ( nf . isReadable ( ) )
2014-05-27 02:04:07 +02:00
debugPrintf ( " Saved to file: %s \n \n " , nf . getPath ( ) . c_str ( ) ) ;
2013-04-07 22:38:25 +02:00
else
2014-05-27 02:04:07 +02:00
debugPrintf ( " Failure. \n " ) ;
2013-04-07 22:38:25 +02:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Failure. \n " ) ;
2013-04-07 22:38:25 +02:00
}
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: save_original \n (Saves game in original file format to a file which can be used with the orginal game executable.) \n \n " ) ;
2013-04-07 22:38:25 +02:00
}
return true ;
} else if ( argc = = 2 ) {
int slot = atoi ( argv [ 1 ] ) ;
if ( slot < 0 | | slot > 5 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Slot must be between (including) 0 and 5. \n " ) ;
2013-04-07 22:38:25 +02:00
} else if ( _vm - > saveAsOriginalSaveFile ( slot ) ) {
Common : : FSNode nf = nd . getChild ( Common : : String : : format ( " EOBDATA%d.SAV " , slot ) ) ;
if ( nf . isReadable ( ) )
2014-05-27 02:04:07 +02:00
debugPrintf ( " Saved to file: %s \n \n " , nf . getPath ( ) . c_str ( ) ) ;
2013-04-07 22:38:25 +02:00
else
2014-05-27 02:04:07 +02:00
debugPrintf ( " Failure. \n " ) ;
2013-04-07 22:38:25 +02:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Failure. \n " ) ;
2013-04-07 22:38:25 +02:00
}
return true ;
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: save_original <slot> \n (Saves game in original file format to a file which can be used with the orginal game executable. \n A save slot between 0 and 5 must be specified.) \n \n " ) ;
2013-04-07 22:38:25 +02:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_EoB : : cmdListMonsters ( int , const char * * ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n Current level: %d \n ---------------------- \n \n " , _vm - > _currentLevel ) ;
debugPrintf ( " Id Type Unit Block Position Direction Sub Level Mode Dst.block HP Flags \n -------------------------------------------------------------------------------------------------------------- \n " ) ;
2013-04-20 22:25:17 +02:00
for ( int i = 0 ; i < 30 ; i + + ) {
EoBMonsterInPlay * m = & _vm - > _monsters [ i ] ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " %.02d %.02d %.02d 0x%.04x %d %d %d %.02d 0x%.04x %.03d/%.03d 0x%.02x \n " , i , m - > type , m - > unit , m - > block , m - > pos , m - > dir , m - > sub , m - > mode , m - > dest , m - > hitPointsCur , m - > hitPointsMax , m - > flags ) ;
2013-04-20 22:25:17 +02:00
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n " ) ;
2013-04-20 22:25:17 +02:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_EoB : : cmdShowPosition ( int , const char * * ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n Current level: %d \n Current Sub Level: %d \n Current block: %d (0x%.04x) \n Next block: %d (0x%.04x) \n Current direction: %d \n \n " , _vm - > _currentLevel , _vm - > _currentSub , _vm - > _currentBlock , _vm - > _currentBlock , _vm - > calcNewBlockPosition ( _vm - > _currentBlock , _vm - > _currentDirection ) , _vm - > calcNewBlockPosition ( _vm - > _currentBlock , _vm - > _currentDirection ) , _vm - > _currentDirection ) ;
2013-04-22 00:57:38 +02:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_EoB : : cmdSetPosition ( int argc , const char * * argv ) {
2013-04-22 00:57:38 +02:00
if ( argc = = 4 ) {
_vm - > _currentBlock = atoi ( argv [ 3 ] ) ;
int sub = atoi ( argv [ 2 ] ) ;
int level = atoi ( argv [ 1 ] ) ;
int maxLevel = ( _vm - > game ( ) = = GI_EOB1 ) ? 12 : 16 ;
if ( level < 1 | | level > maxLevel ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " <level> must be a value from 1 to %d. \n \n " , maxLevel ) ;
2013-04-22 00:57:38 +02:00
return true ;
}
if ( level ! = _vm - > _currentLevel | | sub ! = _vm - > _currentSub ) {
_vm - > completeDoorOperations ( ) ;
_vm - > generateTempData ( ) ;
_vm - > txt ( ) - > removePageBreakFlag ( ) ;
_vm - > screen ( ) - > setScreenDim ( 7 ) ;
_vm - > loadLevel ( level , sub ) ;
if ( _vm - > _dialogueField )
_vm - > restoreAfterDialogueSequence ( ) ;
}
_vm - > moveParty ( _vm - > _currentBlock ) ;
_vm - > _sceneUpdateRequired = true ;
_vm - > gui_drawAllCharPortraitsWithStats ( ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Success. \n \n " ) ;
2013-04-22 00:57:38 +02:00
} else {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: set_position <level>, <sub level>, <block> \n " ) ;
debugPrintf ( " (Warning: The sub level and block position parameters will not be checked. Invalid parameters may cause problems.) \n \n " ) ;
2013-04-22 00:57:38 +02:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_EoB : : cmdOpenDoor ( int , const char * * ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Warning: Using this command may cause glitches. \n " ) ;
2013-04-22 20:29:17 +02:00
uint16 block = _vm - > calcNewBlockPosition ( _vm - > _currentBlock , _vm - > _currentDirection ) ;
int c = ( _vm - > _wllWallFlags [ _vm - > _levelBlockProperties [ block ] . walls [ 0 ] ] & 8 ) ? 0 : 1 ;
int v = _vm - > _levelBlockProperties [ block ] . walls [ c ] ;
int flg = ( _vm - > _flags . gameID = = GI_EOB1 ) ? 1 : 0x10 ;
if ( _vm - > _wllWallFlags [ v ] & flg ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Couldn't open any door. Make sure you're facing the door you wish to open and standing right in front of it. \n \n " ) ;
2013-04-22 20:29:17 +02:00
} else {
_vm - > openDoor ( block ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Trying to open door at block %d. \n \n " , block ) ;
2013-04-22 20:29:17 +02:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_EoB : : cmdCloseDoor ( int , const char * * ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Warning: Using this command may cause glitches. \n " ) ;
2013-04-22 20:29:17 +02:00
uint16 block = _vm - > calcNewBlockPosition ( _vm - > _currentBlock , _vm - > _currentDirection ) ;
int c = ( _vm - > _wllWallFlags [ _vm - > _levelBlockProperties [ block ] . walls [ 0 ] ] & 8 ) ? 0 : 1 ;
int v = _vm - > _levelBlockProperties [ block ] . walls [ c ] ;
if ( ( _vm - > _flags . gameID = = GI_EOB1 & & ! ( _vm - > _wllWallFlags [ v ] & 1 ) ) | | ( _vm - > _flags . gameID = = GI_EOB2 & & ( _vm - > _wllWallFlags [ v ] & 0x20 ) ) ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Couldn't close any door. Make sure you're facing the door you wish to close and standing right in front of it. \n \n " ) ;
2013-04-22 20:29:17 +02:00
} else {
_vm - > closeDoor ( block ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Trying to close door at block %d. \n \n " , block ) ;
2013-04-22 20:29:17 +02:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_EoB : : cmdListFlags ( int , const char * * ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Flag Status \n ---------------------- \n \n " ) ;
2013-04-27 21:43:47 +02:00
for ( int i = 0 ; i < 32 ; i + + ) {
uint32 flag = 1 < < i ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " %.2d %s \n " , i , _vm - > checkScriptFlags ( flag ) ? " TRUE " : " FALSE " ) ;
2013-04-27 21:43:47 +02:00
}
2014-05-27 02:04:07 +02:00
debugPrintf ( " \n " ) ;
2013-04-27 21:43:47 +02:00
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_EoB : : cmdSetFlag ( int argc , const char * * argv ) {
2013-04-27 21:43:47 +02:00
if ( argc ! = 2 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: set_flag <flag> \n \n " ) ;
2013-04-27 21:43:47 +02:00
return true ;
}
int flag = atoi ( argv [ 1 ] ) ;
if ( flag < 0 | | flag > 31 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " <flag> must be a value from 0 to 31. \n \n " ) ;
2013-04-27 21:43:47 +02:00
} else {
_vm - > setScriptFlags ( 1 < < flag ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Flag '%.2d' has been set. \n \n " , flag ) ;
2013-04-27 21:43:47 +02:00
}
return true ;
}
2014-05-27 02:04:08 +02:00
bool Debugger_EoB : : cmdClearFlag ( int argc , const char * * argv ) {
2013-04-27 21:43:47 +02:00
if ( argc ! = 2 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " Syntax: clear_flag <flag> \n \n " ) ;
2013-04-27 21:43:47 +02:00
return true ;
}
int flag = atoi ( argv [ 1 ] ) ;
if ( flag < 0 | | flag > 31 ) {
2014-05-27 02:04:07 +02:00
debugPrintf ( " <flag> must be a value from 0 to 31. \n \n " ) ;
2013-04-27 21:43:47 +02:00
} else {
_vm - > clearScriptFlags ( 1 < < flag ) ;
2014-05-27 02:04:07 +02:00
debugPrintf ( " Flag '%.2d' has been cleared. \n \n " , flag ) ;
2013-04-27 21:43:47 +02:00
}
return true ;
}
2011-11-06 17:53:52 +01:00
# endif // ENABLE_EOB
2005-12-09 14:52:31 +00:00
} // End of namespace Kyra