From c021759ad2f0fdb723f98a62739bdf6d5de9c350 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 22 Oct 2014 20:43:22 -0400 Subject: MADS: Add md5 checks for the asound.00* sound drivers The implementation of the sound driver code relies on the data for each sound being at specific locations in the files, so this ensures that if any language version changes the sound files, we'll know about it --- engines/mads/nebular/sound_nebular.cpp | 28 ++++++++++++++++++++++++++++ engines/mads/nebular/sound_nebular.h | 5 +++++ engines/mads/sound.cpp | 9 +++++++++ 3 files changed, 42 insertions(+) (limited to 'engines') diff --git a/engines/mads/nebular/sound_nebular.cpp b/engines/mads/nebular/sound_nebular.cpp index c540eb4382..a6dce74bba 100644 --- a/engines/mads/nebular/sound_nebular.cpp +++ b/engines/mads/nebular/sound_nebular.cpp @@ -24,6 +24,7 @@ #include "audio/decoders/raw.h" #include "common/algorithm.h" #include "common/debug.h" +#include "common/md5.h" #include "common/memstream.h" #include "mads/sound.h" #include "mads/nebular/sound_nebular.h" @@ -218,6 +219,33 @@ ASound::~ASound() { _mixer->stopHandle(_soundHandle); } +void ASound::validate() { + byte digest[16]; + Common::File f; + static const char *const MD5[] = { + "205398468de2c8873b7d4d73d5be8ddc", + "f9b2d944a2fb782b1af5c0ad592306d3", + "7431f8dad77d6ddfc24e6f3c0c4ac7df", + "eb1f3f5a4673d3e73d8ac1818c957cf4", + "f936dd853073fa44f3daac512e91c476", + "3dc139d3e02437a6d9b732072407c366", + "af0edab2934947982e9a405476702e03", + "8cbc25570b50ba41c9b5361cad4fbedc", + "a31e4783e098f633cbb6689adb41dd4f" + }; + + for (int i = 1; i <= 9; ++i) { + Common::String filename = Common::String::format("ASOUND.00%d", i); + if (!f.open(filename)) + error("Could not process - %s", filename.c_str()); + Common::String md5str = Common::computeStreamMD5AsString(f, 8192); + f.close(); + + if (md5str != MD5[i - 1]) + error("Invalid sound file - %s", filename.c_str()); + } +} + void ASound::adlibInit() { write(4, 0x60); write(4, 0x80); diff --git a/engines/mads/nebular/sound_nebular.h b/engines/mads/nebular/sound_nebular.h index abb6516030..ccfd40ad52 100644 --- a/engines/mads/nebular/sound_nebular.h +++ b/engines/mads/nebular/sound_nebular.h @@ -317,6 +317,11 @@ public: */ virtual ~ASound(); + /** + * Validates the Adlib sound files + */ + static void validate(); + /** * Execute a player command. Most commands represent sounds to play, but some * low number commands also provide control operations. diff --git a/engines/mads/sound.cpp b/engines/mads/sound.cpp index d0aa770a4d..1652550ba3 100644 --- a/engines/mads/sound.cpp +++ b/engines/mads/sound.cpp @@ -39,6 +39,15 @@ SoundManager::SoundManager(MADSEngine *vm, Audio::Mixer *mixer) { _opl = OPL::Config::create(); _opl->init(11025); + + // Validate sound files + switch (_vm->getGameID()) { + case GType_RexNebular: + Nebular::ASound::validate(); + break; + default: + break; + } } SoundManager::~SoundManager() { -- cgit v1.2.3