enable (some of) the original debug passwords

svn-id: r11227
This commit is contained in:
Gregory Montoir 2003-11-09 20:50:03 +00:00
parent 79f84425dd
commit c9feb712bc
7 changed files with 368 additions and 7 deletions

221
queen/debug.cpp Normal file
View File

@ -0,0 +1,221 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2003 The ScummVM project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
#include "stdafx.h"
#include "queen/debug.h"
#include "queen/defs.h"
#include "queen/graphics.h"
#include "queen/logic.h"
#include "queen/resource.h"
#include "queen/structs.h"
namespace Queen {
Debug::Debug(Input *input, Logic *logic, Graphics *graphics)
: _passwordCharCount(0), _stubCount(0), _input(input), _logic(logic), _graphics(graphics) {
memset(_password, 0, sizeof(_password));
registerStub("zeroxpark", &Debug::jumpToRoom);
registerStub("grimley", &Debug::printInfo);
registerStub("kowamori", &Debug::toggleFastMode);
}
void Debug::registerStub(const char *password, DebugFunc debugFunc) {
assert(_stubCount < MAX_STUB);
_stub[_stubCount].password = password;
_stub[_stubCount].function = debugFunc;
++_stubCount;
}
void Debug::update(int c) {
if (c >= 'a' && c <= 'z') {
_password[_passwordCharCount] = (char)c;
++_passwordCharCount;
_passwordCharCount &= 15;
uint k;
for (k = 0; k < _stubCount; ++k) {
const char *pass = _stub[k].password;
int i = strlen(pass) - 1;
int j = _passwordCharCount - 1;
bool match = true;
for (; i >= 0; --i, --j) {
if (_password[j & 15] != pass[i]) {
match = false;
break;
}
}
if (match) {
(this->*(_stub[k].function))();
break;
}
}
}
}
void Debug::jumpToRoom() {
debug(9, "Debug::jumpToRoom()");
_graphics->textCurrentColor(INK_JOE);
_graphics->textSet(0, 142, "Enter new room");
_logic->update();
int room;
_digitTextCount = 0;
if (_input->waitForNumber(room, digitKeyPressed, this)) {
_logic->joeX(0);
_logic->joeY(0);
_logic->newRoom(room);
_logic->entryObj(_logic->roomData(room) + 1);
_graphics->textClear(0, 199);
}
}
void Debug::toggleFastMode() {
debug(9, "Debug::toggleFastMode()");
_input->fastMode(!_input->fastMode());
}
void Debug::printInfo() {
debug(9, "Debug::printInfo()");
_graphics->textClear(0, 199);
_graphics->textCurrentColor(INK_JOE);
char buf[100];
snprintf(buf, sizeof(buf), "Version : %s", _logic->resource()->JASVersion());
_graphics->textSet(110, 20, buf);
snprintf(buf, sizeof(buf), "Room number : %d", _logic->currentRoom());
_graphics->textSet(110, 40, buf);
snprintf(buf, sizeof(buf), "Room name : %s", _logic->roomName(_logic->currentRoom()));
_graphics->textSet(110, 60, buf);
_logic->update();
char c;
if (_input->waitForCharacter(c)) {
switch (c) {
case 'a':
toggleAreasDrawing();
break;
case 's' :
changeGameState();
break;
case 'x' :
printGameState();
break;
case 'i' :
giveAllItems();
break;
}
}
_graphics->textClear(0, 199);
}
void Debug::toggleAreasDrawing() {
debug(9, "Debug::toggleAreasDrawing()");
warning("Debug::toggleAreasDrawing() unimplemented");
}
void Debug::changeGameState() {
debug(9, "Debug::changeGameState()");
_graphics->textSet(0, 142, "Set GAMESTATE");
_logic->update();
int slot, value;
_digitTextCount = 0;
if (_input->waitForNumber(slot, digitKeyPressed, this)) {
_graphics->textClear(0, 199);
_graphics->textSet(0, 142, "to");
_logic->update();
_digitTextCount = 0;
if (_input->waitForNumber(value, digitKeyPressed, this)) {
_logic->gameState(slot, value);
}
}
}
void Debug::printGameState() {
debug(9, "Debug::printGameState()");
_graphics->textSet(0, 142, "Show GAMESTATE");
_logic->update();
int slot;
_digitTextCount = 0;
if (_input->waitForNumber(slot, digitKeyPressed, this)) {
_graphics->textClear(0, 199);
char buf[50];
snprintf(buf, sizeof(buf), "Currently - %d", _logic->gameState(slot));
_graphics->textSet(0, 142, buf);
_logic->update();
char c;
_input->waitForCharacter(c);
}
}
void Debug::giveAllItems() {
debug(9, "Debug::giveAllItems()");
int n = _logic->itemDataCount();
ItemData *item = _logic->itemData(1);
while (n--) {
item->name = ABS(item->name);
++item;
}
}
void Debug::digitKeyPressed(void *refCon, int key) {
Debug *debug = (Debug *)refCon;
if(key != -1 && debug->_digitTextCount < sizeof(debug->_digitText) - 1) {
debug->_digitText[debug->_digitTextCount] = (char)key;
++debug->_digitTextCount;
}
else if (debug->_digitTextCount > 0) {
--debug->_digitTextCount;
}
debug->_digitText[debug->_digitTextCount] = '\0';
debug->_graphics->textSet(0, 151, debug->_digitText);
debug->_logic->update();
}
}

83
queen/debug.h Normal file
View File

@ -0,0 +1,83 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2003 The ScummVM project
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*
*/
#ifndef QUEENDEBUG_H
#define QUEENDEBUG_H
#include "queen/queen.h"
namespace Queen {
class Input;
class Logic;
class Graphics;
class Debug {
public:
typedef void (Debug::*DebugFunc)();
Debug(Input *, Logic *, Graphics *);
void registerStub(const char *password, DebugFunc debugFunc);
void update(int c);
void jumpToRoom();
void toggleFastMode();
void printInfo();
void toggleAreasDrawing();
void changeGameState();
void printGameState();
void giveAllItems();
static void digitKeyPressed(void *refCon, int key);
struct DebugStub {
const char *password;
DebugFunc function;
};
enum {
MAX_STUB = 5
};
private:
char _password[16];
uint _passwordCharCount;
char _digitText[50];
uint _digitTextCount;
DebugStub _stub[MAX_STUB];
uint _stubCount;
Input *_input;
Logic *_logic;
Graphics *_graphics;
};
} // End of namespace Queen
#endif

View File

@ -126,7 +126,7 @@ void Input::delay(uint amount) {
} while (cur < start + amount);
}
void Input::checkKeys() {
int Input::checkKeys() {
if (_inKey)
debug(0, "[Input::checkKeys] _inKey = %i", _inKey);
@ -205,8 +205,48 @@ void Input::checkKeys() {
_keyVerb = Verb(VERB_USE);
break;
}
int inKey = _inKey;
_inKey = 0; //reset
return inKey;
}
bool Input::waitForNumber(int &i, keyPressedCallback callback, void *refCon) {
i = 0;
int key = 0;
do {
delay(DELAY_SHORT);
key = _inKey;
_inKey = 0;
if (key >= '0' && key <= '9') {
i = i * 10 + key - '0';
(*callback)(refCon, key);
}
else if (key == KEY_BACKSPACE) {
i /= 10;
(*callback)(refCon, -1);
}
} while (key != KEY_ESCAPE && key != KEY_RETURN);
return key != KEY_ESCAPE;
}
bool Input::waitForCharacter(char &c) {
int key = 0;
do {
delay(DELAY_SHORT);
if (_inKey >= 'a' && _inKey <= 'z' || _inKey == KEY_ESCAPE) {
key = _inKey;
if (_inKey != KEY_ESCAPE) {
c = (char)_inKey;
}
}
_inKey = 0;
} while (key == 0);
return key != KEY_ESCAPE;
}

View File

@ -34,6 +34,8 @@ class Input {
public:
typedef void (*keyPressedCallback)(void *refCon, int key);
//! Adjust here to change delays!
enum {
DELAY_SHORT = 10,
@ -54,7 +56,7 @@ class Input {
void delay(uint amount);
//! convert input to verb
void checkKeys();
int checkKeys();
//! use instead of KEYVERB=0
void clearKeyVerb() { _keyVerb = Verb(VERB_NONE); }
@ -70,6 +72,7 @@ class Input {
bool talkQuit() const { return _talkQuit; }
void talkQuitReset() { _talkQuit = false; }
bool fastMode() const { return _fastMode; }
void fastMode(bool fm) { _fastMode = fm; }
Verb keyVerb() const { return _keyVerb; }
@ -80,6 +83,9 @@ class Input {
int mouseButton() const { return _mouseButton; }
void clearMouseButton() { _mouseButton = 0; }
bool waitForNumber(int &i, keyPressedCallback callback, void *refCon);
bool waitForCharacter(char &c);
private:
enum KeyCode {
@ -92,7 +98,9 @@ class Input {
KEY_DIGIT_3 = '3',
KEY_DIGIT_4 = '4',
KEY_ESCAPE = 27,
KEY_ESCAPE = 27,
KEY_RETURN = 13,
KEY_BACKSPACE = 8,
KEY_F1 = 282
};

View File

@ -24,6 +24,7 @@
#include "queen/command.h"
#include "queen/cutaway.h"
#include "queen/defs.h"
#include "queen/debug.h"
#include "queen/display.h"
#include "queen/graphics.h"
#include "queen/input.h"
@ -174,8 +175,8 @@ void State::alterDefaultVerb(uint16 *objState, Verb v) {
Common::RandomSource Logic::randomizer;
Logic::Logic(Resource *resource, Graphics *graphics, Display *theDisplay, Input *input, Sound *sound)
: _resource(resource), _graphics(graphics), _display(theDisplay),
Logic::Logic(Resource *theResource, Graphics *graphics, Display *theDisplay, Input *input, Sound *sound)
: _resource(theResource), _graphics(graphics), _display(theDisplay),
_input(input), _sound(sound) {
_settings.talkSpeed = DEFAULT_TALK_SPEED;
_jas = _resource->loadFile("QUEEN.JAS", 20);
@ -183,6 +184,7 @@ Logic::Logic(Resource *resource, Graphics *graphics, Display *theDisplay, Input
_joe.scale = 100;
_walk = new Walk(this, _graphics);
_cmd = new Command(this, _graphics, _input, _walk);
_dbg = new Debug(_input, this, _graphics);
memset(_gameState, 0, sizeof(_gameState));
memset(_talkSelected, 0, sizeof(_talkSelected));
initialise();
@ -192,6 +194,7 @@ Logic::~Logic() {
delete[] _jas;
delete _walk;
delete _cmd;
delete _dbg;
}
void Logic::initialise() {
@ -2317,7 +2320,7 @@ void Logic::update() {
_display->palCustomScroll(_currentRoom);
BobSlot *joe = _graphics->bob(0);
_display->update(joe->active, joe->x, joe->y);
_input->checkKeys();
_dbg->update(_input->checkKeys());
}
void Logic::sceneStart(bool showMouseCursor) {

View File

@ -108,6 +108,7 @@ struct State {
class Command;
class Debug;
class Display;
class Input;
class Graphics;
@ -150,6 +151,7 @@ public:
uint16 objMax(int room);
GraphicData *graphicData(int index);
ItemData *itemData(int index) const { return &_itemData[index]; }
uint16 itemDataCount() const { return _numItems; }
uint16 findBob(uint16 obj);
uint16 findFrame(uint16 obj);
@ -264,6 +266,7 @@ public:
Walk *walk() const { return _walk; }
Display *display() const { return _display; }
Command *command() const { return _cmd; }
Resource *resource() const { return _resource; }
uint16 findObjectRoomNumber(uint16 zoneNum) const;
uint16 findObjectGlobalNumber(uint16 zoneNum) const;
@ -434,6 +437,7 @@ protected:
Resource *_resource;
Graphics *_graphics;
Debug *_dbg;
Display *_display;
Input *_input;
Sound *_sound;
@ -444,6 +448,7 @@ protected:
static const VerbEnum PANEL_VERBS[];
};
} // End of namespace Queen
#endif

View File

@ -3,6 +3,7 @@ MODULE := queen
MODULE_OBJS = \
queen/command.o \
queen/cutaway.o \
queen/debug.o \
queen/display.o \
queen/graphics.o \
queen/input.o \