From ea3de9e8ed5f5b11670341fc2cf3c67e97863d87 Mon Sep 17 00:00:00 2001 From: athrxx Date: Fri, 26 Apr 2024 23:00:39 +0200 Subject: [PATCH] SCUMM: (IMS) - fix regression Player::isFadingOut() was broken by recent fader code changes. The function does not exist in original drivers, but is needed to work around MI2 bug no. 385 (original interpreter bug). --- engines/scumm/imuse/imuse.cpp | 12 ++++++++++++ engines/scumm/imuse/imuse_player.cpp | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/engines/scumm/imuse/imuse.cpp b/engines/scumm/imuse/imuse.cpp index 6b23bc05f2d..e6b20234106 100644 --- a/engines/scumm/imuse/imuse.cpp +++ b/engines/scumm/imuse/imuse.cpp @@ -705,6 +705,18 @@ int IMuseInternal::stopAllSounds_internal() { } int IMuseInternal::getSoundStatus_internal(int sound, bool ignoreFadeouts) const { + if (_game_id != GID_MONKEY2) { + // The whole fadeout checking / ignoring is not present in any of the original + // drivers, but necessary as a WORKAROUND for a bug in Monkey Island 2 that also + // happens with the original interpreter (bug no. 385: "No music if room + // transition is too fast"). The bug is caused by sloppy scripting, but probably + // wouldn't ever be seen on machines of that era, when the loading time for a + // room change would take longer than the fadeout time. + // Since the code is objectively wrong and the workaround is not known to be + // needed elsewhere, we restrict it to Monkey Island 2. + ignoreFadeouts = false; + } + const Player *player = _players; for (int i = ARRAYSIZE(_players); i; i--, player++) { if (player->isActive() && (!ignoreFadeouts || !player->isFadingOut())) { diff --git a/engines/scumm/imuse/imuse_player.cpp b/engines/scumm/imuse/imuse_player.cpp index 134e5f7e3c3..4aa32035d2e 100644 --- a/engines/scumm/imuse/imuse_player.cpp +++ b/engines/scumm/imuse/imuse_player.cpp @@ -135,10 +135,11 @@ int Player::getMusicTimer() const { } bool Player::isFadingOut() const { - int i; - for (i = 0; i < ARRAYSIZE(_parameterFaders); ++i) { - if (_parameterFaders[i].param == ParameterFader::pfVolume && (_parameterFaders[i].incr || _parameterFaders[i].ifrac)) - return true; + for (int i = 0; i < ARRAYSIZE(_parameterFaders); ++i) { + const ParameterFader &p = _parameterFaders[i]; + if (p.param == ParameterFader::pfVolume && + _volume + p.cntdwn * p.incr + ((p.irem + p.cntdwn * p.ifrac) / p.ttime) * p.dir == 0) + return true; } return false; }