[Scummvm-git-logs] scummvm branch-2-6 -> c6bad368fc01ae182ae8b2f7eee243fef7987e75

NMIError noreply at scummvm.org
Fri Aug 5 20:17:20 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c6bad368fc AGOS: Fix Waxworks crash when playing digital SFX


Commit: c6bad368fc01ae182ae8b2f7eee243fef7987e75
    https://github.com/scummvm/scummvm/commit/c6bad368fc01ae182ae8b2f7eee243fef7987e75
Author: Coen Rampen (crampen at gmail.com)
Date: 2022-08-05T22:17:14+02:00

Commit Message:
AGOS: Fix Waxworks crash when playing digital SFX

Waxworks DOS has both digital and limited MIDI SFX. The game scripts use two
different opcodes for trigging digital and MIDI SFX; if a sound effect has both
a digital and a MIDI version, both opcodes are triggered. When digital SFX are
active, ScummVM would try to handle both the digital and the MIDI opcode by
playing a digital SFX. This would crash the game if the MIDI SFX ID was invalid
as a digital SFX ID. Strangely enough, this bug also seems to affect the Amiga
version. Apparently both opcodes are still in the scripts of this version, even
though it does not support MIDI at all AFAIK.

This commit fixes the issue by only playing the MIDI SFX if digital SFX are
turned off and ignoring them otherwise.

Changed paths:
    engines/agos/agos.h
    engines/agos/res_snd.cpp
    engines/agos/script_e2.cpp
    engines/agos/script_s1.cpp
    engines/agos/vga.cpp
    engines/agos/vga_e2.cpp


diff --git a/engines/agos/agos.h b/engines/agos/agos.h
index 0a2e16f6ccc..3e67fba36ee 100644
--- a/engines/agos/agos.h
+++ b/engines/agos/agos.h
@@ -652,7 +652,7 @@ protected:
 	void decompressPN(Common::Stack<uint32> &dataList, uint8 *&dataOut, int &dataOutSize);
 	void loadOffsets(const char *filename, int number, uint32 &file, uint32 &offset, uint32 &compressedSize, uint32 &size);
 	void loadSound(uint16 sound, int16 pan, int16 vol, uint16 type);
-	void playSfx(uint16 sound, uint16 freq, uint16 flags, bool canUseMidiSfx);
+	void playSfx(uint16 sound, uint16 freq, uint16 flags, bool digitalOnly = false, bool midiOnly = false);
 	void loadSound(uint16 sound, uint16 freq, uint16 flags);
 	void loadMidiSfx();
 	virtual void playMidiSfx(uint16 sound);
diff --git a/engines/agos/res_snd.cpp b/engines/agos/res_snd.cpp
index 097e9413044..af16ab4c41e 100644
--- a/engines/agos/res_snd.cpp
+++ b/engines/agos/res_snd.cpp
@@ -571,10 +571,10 @@ void AGOSEngine::loadSound(uint16 sound, int16 pan, int16 vol, uint16 type) {
 		_sound->playSfx5Data(dst, sound, pan, vol);
 }
 
-void AGOSEngine::playSfx(uint16 sound, uint16 freq, uint16 flags, bool canUseMidiSfx) {
-	if (_useDigitalSfx) {
+void AGOSEngine::playSfx(uint16 sound, uint16 freq, uint16 flags, bool digitalOnly, bool midiOnly) {
+	if (_useDigitalSfx && !midiOnly) {
 		loadSound(sound, freq, flags);
-	} else if (canUseMidiSfx) {
+	} else if (!_useDigitalSfx && !digitalOnly) {
 		playMidiSfx(sound);
 	}
 }
diff --git a/engines/agos/script_e2.cpp b/engines/agos/script_e2.cpp
index eb5183aa215..c9899e05e59 100644
--- a/engines/agos/script_e2.cpp
+++ b/engines/agos/script_e2.cpp
@@ -581,7 +581,7 @@ void AGOSEngine_Elvira2::oe2_ifExitLocked() {
 void AGOSEngine_Elvira2::oe2_playEffect() {
 	// 174: play sound
 	uint soundId = getVarOrWord();
-	playSfx(soundId, 0, 0, true);
+	playSfx(soundId, 0, 0);
 }
 
 void AGOSEngine_Elvira2::oe2_getDollar2() {
diff --git a/engines/agos/script_s1.cpp b/engines/agos/script_s1.cpp
index 875353165a1..a7372e3b79a 100644
--- a/engines/agos/script_s1.cpp
+++ b/engines/agos/script_s1.cpp
@@ -378,7 +378,7 @@ void AGOSEngine_Simon1::os1_playEffect() {
 	uint16 soundId = getVarOrWord();
 
 	if (getGameId() == GID_SIMON1DOS)
-		playSfx(soundId, 0, 0, true);
+		playSfx(soundId, 0, 0);
 	else
 		_sound->playEffects(soundId);
 }
diff --git a/engines/agos/vga.cpp b/engines/agos/vga.cpp
index 4e969f94aab..15eb01c4b91 100644
--- a/engines/agos/vga.cpp
+++ b/engines/agos/vga.cpp
@@ -1161,10 +1161,11 @@ void AGOSEngine::vc28_playSFX() {
 	uint16 flags = vcReadNextWord();
 	debug(0, "vc28_playSFX: (sound %d, channels %d, frequency %d, flags %d)", sound, chans, freq, flags);
 
-	// Waxworks DOS uses 2 opcodes to play SFX: this one for digital SFX and
-	// vc52 for MIDI SFX. If MIDI SFX are used, this opcode should be ignored;
-	// vc52 will play the corresponding MIDI SFX (if available).
-	playSfx(sound, freq, flags, !(getGameType() == GType_WW && getPlatform() == Common::kPlatformDOS));
+	// Waxworks uses 2 opcodes to play SFX: vc28 for digital SFX and vc52
+	// for MIDI SFX. If a sound effect has both a MIDI and a digital
+	// version, both opcodes are triggered. Only one of them should play
+	// a sound effect.
+	playSfx(sound, freq, flags, getGameType() == GType_WW);
 }
 
 void AGOSEngine::vc29_stopAllSounds() {
diff --git a/engines/agos/vga_e2.cpp b/engines/agos/vga_e2.cpp
index 836a1d3145b..496d09b0402 100644
--- a/engines/agos/vga_e2.cpp
+++ b/engines/agos/vga_e2.cpp
@@ -192,7 +192,11 @@ void AGOSEngine::vc52_playSound() {
 	} else if (getFeatures() & GF_TALKIE) {
 		_sound->playEffects(sound);
 	} else {
-		playSfx(sound, 0, 0, true);
+		// Waxworks uses 2 opcodes to play SFX: vc28 for digital SFX and vc52
+		// for MIDI SFX. If a sound effect has both a MIDI and a digital
+		// version, both opcodes are triggered. Only one of them should play
+		// a sound effect.
+		playSfx(sound, 0, 0, false, getGameType() == GType_WW);
 	}
 }
 




More information about the Scummvm-git-logs mailing list