From 97eb3546724bda5175fcd854326e8427b2365eef Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Mon, 10 Oct 2011 02:12:48 +0300 Subject: AGI: Fixed bug #3420859 - "AGI: SQ0 - Scummvm Crash" The length requested in this case is 250, which overflows a char variable --- engines/agi/text.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines/agi') diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp index 502db4bdba..d5027588f9 100644 --- a/engines/agi/text.cpp +++ b/engines/agi/text.cpp @@ -224,7 +224,8 @@ void AgiEngine::printTextConsole(const char *msg, int x, int y, int len, int fg, * Based on GBAGI implementation with permission from the author */ char *AgiEngine::wordWrapString(const char *s, int *len) { - char *outStr, *msgBuf, maxWidth = *len; + char *outStr, *msgBuf; + int maxWidth = *len; const char *pWord; int lnLen, wLen; -- cgit v1.2.3 From 69c705a0199f2526f2df774e1b2ee5cddaa63f6c Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 16 Oct 2011 01:10:32 +0300 Subject: AGI: Fixed bug #3424066 - "LSL1 AGI: Password Glitch" We should not stop looking when a partial sentence match is found, as a better match might exist later on. In this case, there were two matching sentences, "Ken" (which is wrong in this case) and "Ken sent me" (which is correct, but was never reached as the partial match was returned first) --- engines/agi/words.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/words.cpp b/engines/agi/words.cpp index ec6928f8ed..f6e399245a 100644 --- a/engines/agi/words.cpp +++ b/engines/agi/words.cpp @@ -120,6 +120,7 @@ void AgiEngine::unloadWords() { */ int AgiEngine::findWord(const char *word, int *flen) { int c; + int result = -1; debugC(2, kDebugLevelScripts, "find_word(%s)", word); @@ -130,15 +131,17 @@ int AgiEngine::findWord(const char *word, int *flen) { *flen = 0; Common::Array &a = _game.words[c]; + for (int i = 0; i < (int)a.size(); i++) { int wlen = strlen(a[i]->word); + // Keep looking till we find the word itself, or the whole phrase if (!strncmp(a[i]->word, word, wlen) && (word[wlen] == 0 || word[wlen] == 0x20)) { *flen = wlen; - return a[i]->id; + result = a[i]->id; } } - return -1; + return result; } void AgiEngine::dictionaryWords(char *msg) { -- cgit v1.2.3 From dbd5ffaf34e690559380721e0f132b637b8fce33 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 16 Oct 2011 14:36:38 +0300 Subject: AGI: Refine commit #69c705a to always pick the longest matching phrase Thanks to wjp for his observation in the original commit --- engines/agi/words.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/words.cpp b/engines/agi/words.cpp index f6e399245a..1001c66b20 100644 --- a/engines/agi/words.cpp +++ b/engines/agi/words.cpp @@ -134,8 +134,9 @@ int AgiEngine::findWord(const char *word, int *flen) { for (int i = 0; i < (int)a.size(); i++) { int wlen = strlen(a[i]->word); - // Keep looking till we find the word itself, or the whole phrase - if (!strncmp(a[i]->word, word, wlen) && (word[wlen] == 0 || word[wlen] == 0x20)) { + // Keep looking till we find the word itself, or the whole phrase. + // Try to find the best match (i.e. the longest matching phrase). + if (!strncmp(a[i]->word, word, wlen) && (word[wlen] == 0 || word[wlen] == 0x20) && wlen >= *flen) { *flen = wlen; result = a[i]->id; } -- cgit v1.2.3 From 32972a5ffb180c9e8a6a9eae51d0e7564ce76d9e Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 23 Oct 2011 17:52:43 +0100 Subject: AD: Switched rest of the engines to new GUIO --- engines/agi/detection.cpp | 2 +- engines/agi/detection_tables.h | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp index 21b1831261..982dce8405 100644 --- a/engines/agi/detection.cpp +++ b/engines/agi/detection.cpp @@ -150,7 +150,7 @@ class AgiMetaEngine : public AdvancedMetaEngine { public: AgiMetaEngine() : AdvancedMetaEngine(Agi::gameDescriptions, sizeof(Agi::AGIGameDescription), agiGames) { _singleid = "agi"; - _guioptions = Common::GUIO_NOSPEECH; + _guioptions = GUIO1(GUIO_NOSPEECH); } virtual const char *getName() const { diff --git a/engines/agi/detection_tables.h b/engines/agi/detection_tables.h index f0cd422ed6..081cb39668 100644 --- a/engines/agi/detection_tables.h +++ b/engines/agi/detection_tables.h @@ -22,8 +22,6 @@ namespace Agi { -using Common::GUIO_NONE; - #define GAME_LVFPN(id,extra,fname,md5,size,lang,ver,features,gid,platform,interp) { \ { \ id, \ @@ -32,7 +30,7 @@ using Common::GUIO_NONE; lang, \ platform, \ ADGF_NO_FLAGS, \ - GUIO_NONE \ + GUIO1(GUIO_NONE) \ }, \ gid, \ interp, \ @@ -48,7 +46,7 @@ using Common::GUIO_NONE; lang, \ platform, \ ADGF_USEEXTRAASTITLE, \ - GUIO_NONE \ + GUIO1(GUIO_NONE) \ }, \ gid, \ interp, \ @@ -132,7 +130,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformPC, ADGF_NO_FLAGS, - GUIO_NONE + GUIO1(GUIO_NONE) }, GID_BC, GType_V1, @@ -153,7 +151,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformPC, ADGF_NO_FLAGS, - GUIO_NONE + GUIO1(GUIO_NONE) }, GID_BC, GType_V1, @@ -174,7 +172,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformPC, ADGF_NO_FLAGS, - GUIO_NONE + GUIO1(GUIO_NONE) }, GID_BC, GType_V1, @@ -254,7 +252,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformMacintosh, ADGF_NO_FLAGS, - GUIO_NONE + GUIO1(GUIO_NONE) }, GID_GOLDRUSH, GType_V3, @@ -572,7 +570,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformAmiga, ADGF_NO_FLAGS, - GUIO_NONE + GUIO1(GUIO_NONE) }, GID_SQ2, GType_V2, @@ -861,7 +859,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformPC, ADGF_USEEXTRAASTITLE, - GUIO_NONE + GUIO1(GUIO_NONE) }, GID_FANMADE, GType_V3, @@ -889,7 +887,7 @@ static AGIGameDescription g_fallbackDesc = { Common::UNK_LANG, Common::kPlatformPC, ADGF_NO_FLAGS, - GUIO_NONE + GUIO1(GUIO_NONE) }, GID_FANMADE, GType_V2, -- cgit v1.2.3 From f6a9c6727dc11639a11e17fdcf3d0c0a39b8be96 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 2 Nov 2011 22:20:27 +0000 Subject: AGI: Fix buffer overflow --- engines/agi/opcodes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/opcodes.cpp b/engines/agi/opcodes.cpp index d1baab93e1..29fb860635 100644 --- a/engines/agi/opcodes.cpp +++ b/engines/agi/opcodes.cpp @@ -360,7 +360,7 @@ AgiInstruction insV2[] = { void AgiEngine::setupOpcodes() { if (getVersion() >= 0x2000) { - for (int i = 0; i <= ARRAYSIZE(insV2Test); ++i) + for (int i = 0; i < ARRAYSIZE(insV2Test); ++i) _agiCondCommands[i] = insV2Test[i].func; for (int i = 0; i < ARRAYSIZE(insV2); ++i) _agiCommands[i] = insV2[i].func; @@ -368,7 +368,7 @@ void AgiEngine::setupOpcodes() { logicNamesTest = insV2Test; logicNamesCmd = insV2; } else { - for (int i = 0; i <= ARRAYSIZE(insV1Test); ++i) + for (int i = 0; i < ARRAYSIZE(insV1Test); ++i) _agiCondCommands[i] = insV1Test[i].func; for (int i = 0; i < ARRAYSIZE(insV1); ++i) _agiCommands[i] = insV1[i].func; -- cgit v1.2.3 From d0bb81f5661879f81fb1a17174fa7f2e9085c698 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 2 Nov 2011 22:20:40 +0000 Subject: AGI: Fix warnings --- engines/agi/graphics.cpp | 4 ++-- engines/agi/saveload.cpp | 4 ++-- engines/agi/text.cpp | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/graphics.cpp b/engines/agi/graphics.cpp index 074e5570d5..4bb3877f7d 100644 --- a/engines/agi/graphics.cpp +++ b/engines/agi/graphics.cpp @@ -1083,7 +1083,7 @@ void GfxMgr::putPixelsA(int x, int y, int n, uint8 *p) { // Choose the correct screen to read from. If AGI256 or AGI256-2 is used and we're not trying to show the priority information, // then choose the 256 color screen, otherwise choose the 16 color screen (Which also has the priority information). - p += _vm->getFeatures() & (GF_AGI256 | GF_AGI256_2) && !_vm->_debug.priority ? FROM_SBUF16_TO_SBUF256_OFFSET : 0; + p += ((_vm->getFeatures() & (GF_AGI256 | GF_AGI256_2)) && !_vm->_debug.priority) ? FROM_SBUF16_TO_SBUF256_OFFSET : 0; if (_vm->_renderMode == Common::kRenderCGA) { for (x *= 2; n--; p++, x += 2) { @@ -1091,7 +1091,7 @@ void GfxMgr::putPixelsA(int x, int y, int n, uint8 *p) { *(uint16 *)&_agiScreen[x + y * GFX_WIDTH] = (q >> rShift) & 0x0f0f; } } else { - const uint16 mask = _vm->getFeatures() & (GF_AGI256 | GF_AGI256_2) && !_vm->_debug.priority ? 0xffff : 0x0f0f; + const uint16 mask = ((_vm->getFeatures() & (GF_AGI256 | GF_AGI256_2)) && !_vm->_debug.priority) ? 0xffff : 0x0f0f; for (x *= 2; n--; p++, x += 2) { register uint16 q = ((uint16)*p << 8) | *p; *(uint16 *)&_agiScreen[x + y * GFX_WIDTH] = (q >> rShift) & mask; diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 3cebbf50c8..1bcabd507f 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -300,7 +300,7 @@ int AgiEngine::loadGame(const Common::String &fileName, bool checkId) { _game.state = (State)in->readByte(); in->read(loadId, 8); - if (strcmp(loadId, _game.id) && checkId) { + if (strcmp(loadId, _game.id) != 0 && checkId) { delete in; warning("This save seems to be from a different AGI game (save from %s, running %s), not loaded", loadId, _game.id); return errBadFileOpen; @@ -331,7 +331,7 @@ int AgiEngine::loadGame(const Common::String &fileName, bool checkId) { warning("Since your game was only detected via the fallback detector, there is no possibility to assure the save is compatible with your game version"); debug(0, "The game used for saving is \"%s\".", md5); - } else if (strcmp(md5, getGameMD5())) { + } else if (strcmp(md5, getGameMD5()) != 0) { warning("Game was saved with different gamedata - you may encounter problems"); debug(0, "Your game is \"%s\" and save is \"%s\".", getGameMD5(), md5); diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp index d5027588f9..3247862e32 100644 --- a/engines/agi/text.cpp +++ b/engines/agi/text.cpp @@ -240,7 +240,6 @@ char *AgiEngine::wordWrapString(const char *s, int *len) { while (*s) { pWord = s; - wLen = 0; while (*s != '\0' && *s != ' ' && *s != '\n' && *s != '\r') s++; -- cgit v1.2.3 From 056c3992eb4715c7efa6ac2fb857e21d79d7a450 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 3 Nov 2011 22:36:34 +0200 Subject: AGI: Commented out if statements that always evaluate to true --- engines/agi/cycle.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/cycle.cpp b/engines/agi/cycle.cpp index 9cbab1f3c4..99649fb437 100644 --- a/engines/agi/cycle.cpp +++ b/engines/agi/cycle.cpp @@ -200,10 +200,11 @@ int AgiEngine::mainCycle() { // vars in every interpreter cycle. // // We run AGIMOUSE always as a side effect - if (getFeatures() & GF_AGIMOUSE || true) { + //if (getFeatures() & GF_AGIMOUSE) { _game.vars[28] = _mouse.x / 2; _game.vars[29] = _mouse.y; - } + //} + if (key == KEY_PRIORITY) { _sprites->eraseBoth(); _debug.priority = !_debug.priority; @@ -315,7 +316,7 @@ int AgiEngine::playGame() { _game.lineUserInput = 22; // We run AGIMOUSE always as a side effect - if (getFeatures() & GF_AGIMOUSE || true) + //if (getFeatures() & GF_AGIMOUSE) debug(1, "Using AGI Mouse 1.0 protocol"); if (getFeatures() & GF_AGIPAL) -- cgit v1.2.3 From d3858c359fde79e443d6e61579b400a36dff13e3 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 3 Nov 2011 22:55:22 +0200 Subject: AGI: Commented out if statements that always evaluate to true --- engines/agi/op_cmd.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/op_cmd.cpp b/engines/agi/op_cmd.cpp index 72f60e2516..41d9cc3ac9 100644 --- a/engines/agi/op_cmd.cpp +++ b/engines/agi/op_cmd.cpp @@ -1622,15 +1622,15 @@ void cmdPrintAtV(AgiGame *state, uint8 *p) { void cmdPushScript(AgiGame *state, uint8 *p) { // We run AGIMOUSE always as a side effect - if (getFeatures() & GF_AGIMOUSE || true) { + //if (getFeatures() & GF_AGIMOUSE || true) { state->vars[27] = state->_vm->_mouse.button; state->vars[28] = state->_vm->_mouse.x / 2; state->vars[29] = state->_vm->_mouse.y; - } else { + /*} else { if (getVersion() >= 0x2915) { debug(0, "push.script"); } - } + }*/ } void cmdSetPriBase(AgiGame *state, uint8 *p) { -- cgit v1.2.3 From c5ff6b431b960f599aee562baa1a15e0edcec451 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Wed, 16 Nov 2011 20:25:21 +0100 Subject: AGI: Change two local SharedPtr uses to ScopedPtr. I took the opportunity to add two CHECKMEs to the code, which seems to load a file into memory for no real apparent reason. --- engines/agi/sound_2gs.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/sound_2gs.cpp b/engines/agi/sound_2gs.cpp index c5cfa125d6..b15950f31d 100644 --- a/engines/agi/sound_2gs.cpp +++ b/engines/agi/sound_2gs.cpp @@ -719,7 +719,10 @@ bool SoundGen2GS::loadInstrumentHeaders(Common::String &exePath, const IIgsExeIn } // Read the whole executable file into memory - Common::SharedPtr data(file.readStream(file.size())); + // CHECKME: Why do we read the file into memory first? It does not seem to be + // kept outside of this function. Is the processing of the data too slow + // otherwise? + Common::ScopedPtr data(file.readStream(file.size())); file.close(); // Check that we got enough data to be able to parse the instruments @@ -769,8 +772,11 @@ bool SoundGen2GS::loadWaveFile(Common::String &wavePath, const IIgsExeInfo &exeI Common::File file; // Open the wave file and read it into memory + // CHECKME: Why do we read the file into memory first? It does not seem to be + // kept outside of this function. Is the processing of the data too slow + // otherwise? file.open(wavePath); - Common::SharedPtr uint8Wave(file.readStream(file.size())); + Common::ScopedPtr uint8Wave(file.readStream(file.size())); file.close(); // Check that we got the whole wave file -- cgit v1.2.3 From bab4b6f7295f6fb960ebbf44b009bd6adbd0d33e Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 16 Nov 2011 22:38:58 +0100 Subject: LAUNCHER: Introduce GUIO0() in order to replace GUIO1(GUIO_NONE) --- engines/agi/detection_tables.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'engines/agi') diff --git a/engines/agi/detection_tables.h b/engines/agi/detection_tables.h index 081cb39668..ab0e9a1fe4 100644 --- a/engines/agi/detection_tables.h +++ b/engines/agi/detection_tables.h @@ -30,7 +30,7 @@ namespace Agi { lang, \ platform, \ ADGF_NO_FLAGS, \ - GUIO1(GUIO_NONE) \ + GUIO0() \ }, \ gid, \ interp, \ @@ -46,7 +46,7 @@ namespace Agi { lang, \ platform, \ ADGF_USEEXTRAASTITLE, \ - GUIO1(GUIO_NONE) \ + GUIO0() \ }, \ gid, \ interp, \ @@ -130,7 +130,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformPC, ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) + GUIO0() }, GID_BC, GType_V1, @@ -151,7 +151,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformPC, ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) + GUIO0() }, GID_BC, GType_V1, @@ -172,7 +172,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformPC, ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) + GUIO0() }, GID_BC, GType_V1, @@ -252,7 +252,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformMacintosh, ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) + GUIO0() }, GID_GOLDRUSH, GType_V3, @@ -570,7 +570,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformAmiga, ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) + GUIO0() }, GID_SQ2, GType_V2, @@ -859,7 +859,7 @@ static const AGIGameDescription gameDescriptions[] = { Common::EN_ANY, Common::kPlatformPC, ADGF_USEEXTRAASTITLE, - GUIO1(GUIO_NONE) + GUIO0() }, GID_FANMADE, GType_V3, @@ -887,7 +887,7 @@ static AGIGameDescription g_fallbackDesc = { Common::UNK_LANG, Common::kPlatformPC, ADGF_NO_FLAGS, - GUIO1(GUIO_NONE) + GUIO0() }, GID_FANMADE, GType_V2, -- cgit v1.2.3 From a78b2d777d98e494b988843bfd9694c58c6c6018 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Sat, 26 Nov 2011 13:33:42 +0100 Subject: JANITORIAL: Remove extra semicolons. --- engines/agi/sound_2gs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/agi') diff --git a/engines/agi/sound_2gs.h b/engines/agi/sound_2gs.h index 89ffc3fe11..404f4a47a1 100644 --- a/engines/agi/sound_2gs.h +++ b/engines/agi/sound_2gs.h @@ -247,7 +247,7 @@ private: void midiNoteOff(int channel, int note, int velocity); void midiNoteOn(int channel, int note, int velocity); double midiKeyToFreq(int key, double finetune); - IIgsInstrumentHeader* getInstrument(uint8 program) { return &_instruments[_progToInst->map(program)]; }; + IIgsInstrumentHeader* getInstrument(uint8 program) { return &_instruments[_progToInst->map(program)]; } IIgsGenerator* allocateGenerator() { IIgsGenerator* g = &_generators[_nextGen++]; _nextGen %= 16; return g; } bool _disableMidi; ///< Disable MIDI if loading instruments fail -- cgit v1.2.3