From 286c6b8039ebd504b20e5d56dbfd3f8f912057c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Andersson?= Date: Thu, 14 Nov 2024 19:23:40 +0100 Subject: [PATCH] SCUMM: MACGUI: Fall back on using no Mac GUI for unrecognized versions Rather than crashing, allow the user to continue playing the unrecognized Mac version, albeit without the Mac GUI. Certain other Mac aspects may still survive. --- engines/scumm/macgui/macgui.cpp | 4 ++-- engines/scumm/macgui/macgui.h | 2 +- engines/scumm/macgui/macgui_impl.cpp | 7 ++++++- engines/scumm/macgui/macgui_impl.h | 4 ++-- engines/scumm/macgui/macgui_indy3.cpp | 2 -- engines/scumm/macgui/macgui_loom.cpp | 1 - engines/scumm/macgui/macgui_strings.cpp | 8 ++++---- engines/scumm/macgui/macgui_v5.cpp | 1 - engines/scumm/scumm.cpp | 8 ++++++-- 9 files changed, 21 insertions(+), 16 deletions(-) diff --git a/engines/scumm/macgui/macgui.cpp b/engines/scumm/macgui/macgui.cpp index 6ca269c9731a..ae3a0eac1e82 100644 --- a/engines/scumm/macgui/macgui.cpp +++ b/engines/scumm/macgui/macgui.cpp @@ -60,8 +60,8 @@ int MacGui::getNumColors() const { return _impl->getNumColors(); } -void MacGui::initialize() { - _impl->initialize(); +bool MacGui::initialize() { + return _impl->initialize(); } void MacGui::reset() { diff --git a/engines/scumm/macgui/macgui.h b/engines/scumm/macgui/macgui.h index df6bf059e99d..76ab676778c8 100644 --- a/engines/scumm/macgui/macgui.h +++ b/engines/scumm/macgui/macgui.h @@ -48,7 +48,7 @@ class MacGui { int getNumColors() const; - void initialize(); + bool initialize(); void reset(); void update(int delta); void updateWindowManager(); diff --git a/engines/scumm/macgui/macgui_impl.cpp b/engines/scumm/macgui/macgui_impl.cpp index c98f78f035a0..b15fcfa909fc 100644 --- a/engines/scumm/macgui/macgui_impl.cpp +++ b/engines/scumm/macgui/macgui_impl.cpp @@ -163,7 +163,10 @@ void MacGuiImpl::menuCallback(int id, Common::String &name, void *data) { } } -void MacGuiImpl::initialize() { +bool MacGuiImpl::initialize() { + if (!readStrings()) + return false; + uint32 menuMode = Graphics::kWMModeNoDesktop | Graphics::kWMModeAutohideMenu | Graphics::kWMModalMenuMode | Graphics::kWMModeNoCursorOverride | Graphics::kWMModeForceMacFonts; @@ -286,6 +289,8 @@ void MacGuiImpl::initialize() { break; } } + + return true; } bool MacGuiImpl::handleMenu(int id, Common::String &name) { diff --git a/engines/scumm/macgui/macgui_impl.h b/engines/scumm/macgui/macgui_impl.h index 6d4395738788..f369fd15a7a1 100644 --- a/engines/scumm/macgui/macgui_impl.h +++ b/engines/scumm/macgui/macgui_impl.h @@ -226,7 +226,7 @@ class MacGuiImpl { bool runOkCancelDialog(Common::String text); - void readStrings(); + bool readStrings(); void parseSTRSBlock(uint8 *strsData, MacSTRSParsingEntry *parsingTable, int parsingTableSize); // These are non interactable, no point in having them as widgets for now... @@ -708,7 +708,7 @@ class MacGuiImpl { virtual bool handleEvent(Common::Event event); static void menuCallback(int id, Common::String &name, void *data); - virtual void initialize(); + virtual bool initialize(); void updateWindowManager(); const Graphics::Font *getFont(FontId fontId); diff --git a/engines/scumm/macgui/macgui_indy3.cpp b/engines/scumm/macgui/macgui_indy3.cpp index af6e8cd1b6eb..7a42cee5d846 100644 --- a/engines/scumm/macgui/macgui_indy3.cpp +++ b/engines/scumm/macgui/macgui_indy3.cpp @@ -928,8 +928,6 @@ MacIndy3Gui::MacIndy3Gui(ScummEngine *vm, const Common::Path &resourceFile) : _dirtyRects.clear(); _textArea.create(448, 47, Graphics::PixelFormat::createFormatCLUT8()); - - readStrings(); } MacIndy3Gui::~MacIndy3Gui() { diff --git a/engines/scumm/macgui/macgui_loom.cpp b/engines/scumm/macgui/macgui_loom.cpp index c0fe37a8710f..5a040993d68a 100644 --- a/engines/scumm/macgui/macgui_loom.cpp +++ b/engines/scumm/macgui/macgui_loom.cpp @@ -50,7 +50,6 @@ MacLoomGui::MacLoomGui(ScummEngine *vm, const Common::Path &resourceFile) : MacG // a large screen, and it's not saved. _practiceBoxPos = Common::Point(215, 376 + 2 * _vm->_macScreenDrawOffset); - readStrings(); } MacLoomGui::~MacLoomGui() { diff --git a/engines/scumm/macgui/macgui_strings.cpp b/engines/scumm/macgui/macgui_strings.cpp index df43b002e0be..d046c5b7fa77 100644 --- a/engines/scumm/macgui/macgui_strings.cpp +++ b/engines/scumm/macgui/macgui_strings.cpp @@ -602,13 +602,13 @@ static MacGuiImpl::MacSTRSParsingEntry strsIndy4FloppyVariant2Table[] = { #undef SKIP_C #undef SKIP_P -void MacGuiImpl::readStrings() { +bool MacGuiImpl::readStrings() { Common::MacResManager resource; resource.open(_resourceFile); uint32 strsLen = resource.getResLength(MKTAG('S', 'T', 'R', 'S'), 0); if (strsLen <= 0) - return; + return false; Common::SeekableReadStream *strsStream = resource.getResource(MKTAG('S', 'T', 'R', 'S'), 0); uint8 *strsBlock = (uint8 *)malloc(strsLen); @@ -676,8 +676,6 @@ void MacGuiImpl::readStrings() { parsingTableSize = ARRAYSIZE(strsIndy4CDVariant2Table); break; } - } else { - error("MacGuiImpl::readStrings(): String parsing table not defined for this game"); } if (parsingTable) @@ -687,6 +685,8 @@ void MacGuiImpl::readStrings() { free(strsBlock); delete strsStream; + + return parsingTable != nullptr; } void MacGuiImpl::parseSTRSBlock(uint8 *strsData, MacSTRSParsingEntry *parsingTable, int parsingTableSize) { diff --git a/engines/scumm/macgui/macgui_v5.cpp b/engines/scumm/macgui/macgui_v5.cpp index c06a81946856..c33a707c5861 100644 --- a/engines/scumm/macgui/macgui_v5.cpp +++ b/engines/scumm/macgui/macgui_v5.cpp @@ -45,7 +45,6 @@ namespace Scumm { // =========================================================================== MacV5Gui::MacV5Gui(ScummEngine *vm, const Common::Path &resourceFile) : MacGuiImpl(vm, resourceFile) { - readStrings(); } const Graphics::Font *MacV5Gui::getFontByScummId(int32 id) { diff --git a/engines/scumm/scumm.cpp b/engines/scumm/scumm.cpp index 658b9efbe846..919e14336541 100644 --- a/engines/scumm/scumm.cpp +++ b/engines/scumm/scumm.cpp @@ -1335,8 +1335,12 @@ Common::Error ScummEngine::init() { memset(_completeScreenBuffer, 0, 320 * 200); - if (_macGui) - _macGui->initialize(); + if (_macGui) { + if (!_macGui->initialize()) { + delete _macGui; + _macGui = nullptr; + } + } } // Initialize backend