summaryrefslogtreecommitdiff
path: root/src/i_sdlmusic.c
diff options
context:
space:
mode:
authorSimon Howard2014-04-12 21:02:41 -0400
committerSimon Howard2014-04-12 21:02:41 -0400
commit50742cfc923a5be33398973072818f0c94950809 (patch)
treec43e538a3bafe6bd02717049b32a28d85e480d48 /src/i_sdlmusic.c
parentd70c830b4d089e749ff5aa84a3d479be7911995a (diff)
downloadchocolate-doom-50742cfc923a5be33398973072818f0c94950809.tar.gz
chocolate-doom-50742cfc923a5be33398973072818f0c94950809.tar.bz2
chocolate-doom-50742cfc923a5be33398973072818f0c94950809.zip
music: Fix -dumpsubstconfig for Heretic/Hexen.
The config dumping command line option assumed that music lumps were named like D_MYLUMP, but this is not the case for Heretic and Hexen, where there is no D_ prefix and music lumps can have any name. Change the logic to instead look at the contents of lumps and identify music lumps from the MUS / MIDI header.
Diffstat (limited to 'src/i_sdlmusic.c')
-rw-r--r--src/i_sdlmusic.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/i_sdlmusic.c b/src/i_sdlmusic.c
index e2be3f50..2a714d3d 100644
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -48,6 +48,8 @@
#include "z_zone.h"
#define MAXMIDLENGTH (96 * 1024)
+#define MID_HEADER_MAGIC "MThd"
+#define MUS_HEADER_MAGIC "MUS\x1a"
// Structure for music substitution.
// We store a mapping based on SHA1 checksum -> filename of substitute music
@@ -344,6 +346,31 @@ static void LoadSubstituteConfigs(void)
}
}
+// Returns true if the given lump number is a music lump that should
+// be included in substitute configs.
+// Identifying music lumps by name is not feasible; some games (eg.
+// Heretic, Hexen) don't have a common naming pattern for music lumps.
+
+static boolean IsMusicLump(int lumpnum)
+{
+ byte *data;
+ boolean result;
+
+ if (W_LumpLength(lumpnum) < 4)
+ {
+ return false;
+ }
+
+ data = W_CacheLumpNum(lumpnum, PU_STATIC);
+
+ result = memcmp(data, MUS_HEADER_MAGIC, 4) == 0
+ || memcmp(data, MID_HEADER_MAGIC, 4) == 0;
+
+ W_ReleaseLumpNum(lumpnum);
+
+ return result;
+}
+
// Dump an example config file containing checksums for all MIDI music
// found in the WAD directory.
@@ -372,7 +399,7 @@ static void DumpSubstituteConfig(char *filename)
strncpy(name, lumpinfo[lumpnum].name, 8);
name[8] = '\0';
- if (!M_StringStartsWith(name, "D_"))
+ if (!IsMusicLump(lumpnum))
{
continue;
}