From 86e0089cc6233964ca8ac858f627e0572078b199 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Mon, 18 Jun 2018 09:36:40 +0200 Subject: [PATCH] MOHAWK: RIVEN: Patch in the load menu for the game versions missing it --- engines/mohawk/riven_card.cpp | 81 +++++++++++++++++---------- engines/mohawk/riven_card.h | 5 +- engines/mohawk/riven_stacks/aspit.cpp | 1 - engines/mohawk/riven_stacks/aspit.h | 3 +- 4 files changed, 56 insertions(+), 34 deletions(-) diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp index d2f8d4f42d7..ffbbc69caee 100644 --- a/engines/mohawk/riven_card.cpp +++ b/engines/mohawk/riven_card.cpp @@ -396,44 +396,63 @@ void RivenCard::applyPropertiesPatchE2E(uint32 globalId) { // The main menu in the Myst 25th anniversary version is patched to include new items: // - Save game if (globalId == 0xE2E) { - uint16 patchData[] = { - 24, // blstId - 0xFFFF, // name - 485, // left - 311, // top - 602, // right - 326, // bottom - 0, // u0 - kRivenMainCursor, // cursor - 4, // index - 0xFFFF, // transition offset - 0, // flags - 2, // script count + addMenuHotspot(23, Common::Rect(485, 283, 602, 300), 3, RivenStacks::ASpit::kExternalRestoreGame, "xarestoregame"); + addMenuHotspot(24, Common::Rect(485, 311, 602, 326), 4, RivenStacks::ASpit::kExternalSaveGame, "xaSaveGame"); + } +} - kMouseDownScript, // script type - 1, // command count - kRivenCommandRunExternal, // command type - 2, // argument count - RivenStacks::ASpit::kExternalSaveGame, // external command name id - 0, // external argument count +void RivenCard::addMenuHotspot(uint16 blstId, const Common::Rect &position, uint16 index, + uint16 externalCommandNameId, const char *externalCommandName) { + RivenHotspot *existingHotspot = getHotspotByBlstId(blstId); + if (existingHotspot) { + return; // Don't add the hotspot if it already exists + } - kMouseInsideScript, // script type - 1, // command count - kRivenCommandChangeCursor, // command type - 1, // argument count - kRivenOpenHandCursor // cursor + // Add the external command id => name mapping if it is missing + int16 existingCommandNameId = _vm->getStack()->getIdFromName(kExternalCommandNames, externalCommandName); + if (existingCommandNameId < 0) { + _vm->getStack()->registerName(kExternalCommandNames, externalCommandNameId, externalCommandName); + } else { + externalCommandNameId = existingCommandNameId; + } + + uint16 patchData[] = { + blstId, + 0xFFFF, // name + (uint16) position.left, + (uint16) position.top, + (uint16) position.right, + (uint16) position.bottom, + 0, // u0 + kRivenMainCursor, // cursor + index, + 0xFFFF, // transition offset + 0, // flags + 2, // script count + + kMouseDownScript, // script type + 1, // command count + kRivenCommandRunExternal, // command type + 2, // argument count + externalCommandNameId, + 0, // external argument count + + kMouseInsideScript, // script type + 1, // command count + kRivenCommandChangeCursor, // command type + 1, // argument count + kRivenOpenHandCursor // cursor }; - // Script data is expected to be in big endian - for (uint i = 0; i < ARRAYSIZE(patchData); i++) { + // Script data is expected to be in big endian + for (uint i = 0; i < ARRAYSIZE(patchData); i++) { patchData[i] = TO_BE_16(patchData[i]); } - // Add the new hotspot to the existing ones - Common::MemoryReadStream patchStream((const byte *)(patchData), ARRAYSIZE(patchData) * sizeof(uint16)); - RivenHotspot *newHotspot = new RivenHotspot(_vm, &patchStream); - _hotspots.push_back(newHotspot); - } + // Add the new hotspot to the existing ones + Common::MemoryReadStream patchStream((const byte *)(patchData), ARRAYSIZE(patchData) * sizeof(uint16)); + RivenHotspot *newHotspot = new RivenHotspot(_vm, &patchStream); + _hotspots.push_back(newHotspot); } void RivenCard::enter(bool unkMovies) { diff --git a/engines/mohawk/riven_card.h b/engines/mohawk/riven_card.h index f285ba1a1b8..acf20faee87 100644 --- a/engines/mohawk/riven_card.h +++ b/engines/mohawk/riven_card.h @@ -152,11 +152,15 @@ private: void loadCardHotspotEnableList(uint16 id); void loadCardWaterEffectList(uint16 id); void applyPatches(uint16 id); + void applyPropertiesPatchE2E(uint32 globalId); void applyPropertiesPatch8EB7(uint32 globalId); void applyPropertiesPatch2E76(uint32 globalId); void applyPropertiesPatch22118(uint32 globalId); void setCurrentCardVariable(); + void addMenuHotspot(uint16 blstId, const Common::Rect &position, uint16 index, + uint16 externalCommandNameId, const char *externalCommandName); + RivenScriptPtr getScript(uint16 scriptType) const; void defaultLoadScript(); @@ -193,7 +197,6 @@ private: Common::Array _hotspotEnableList; Common::Array _waterEffectList; - void applyPropertiesPatchE2E(uint32 globalId); }; struct MLSTRecord { diff --git a/engines/mohawk/riven_stacks/aspit.cpp b/engines/mohawk/riven_stacks/aspit.cpp index c4ae09684cc..de5747cbc25 100644 --- a/engines/mohawk/riven_stacks/aspit.cpp +++ b/engines/mohawk/riven_stacks/aspit.cpp @@ -66,7 +66,6 @@ ASpit::ASpit(MohawkEngine_Riven *vm) : REGISTER_COMMAND(ASpit, xaexittomain); REGISTER_COMMAND(ASpit, xaSaveGame); - registerName(kExternalCommandNames, kExternalSaveGame, "xaSaveGame"); } struct MenuItemText { diff --git a/engines/mohawk/riven_stacks/aspit.h b/engines/mohawk/riven_stacks/aspit.h index 75b9fd3e64c..ba6f3c31f2a 100644 --- a/engines/mohawk/riven_stacks/aspit.h +++ b/engines/mohawk/riven_stacks/aspit.h @@ -36,7 +36,8 @@ public: ASpit(MohawkEngine_Riven *vm); enum PatchedExternalCommandNameId { - kExternalSaveGame = 20 + kExternalSaveGame = 20, + kExternalRestoreGame = 21 }; // External commands - Main Menu