foxygit / doom Log in
commit 42faefce1fd03f5d613bf709d3c14925ee560064
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sun Mar 23 22:04:22 2014 -0400
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Mar 23 22:04:22 2014 -0400

    Autodetect GUS patches installed with BFG Edition.

    Doom 3: BFG Edition installs copies of the GUS instrument files
    (patches) that can be used for the GUS pseudo-emulation. Detect these
    on startup if no GUS patch path has been configured and configure
    gus_patch_path config variable automatically.

    This fixes #333.
---
 src/d_iwad.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/d_iwad.c b/src/d_iwad.c
index bfef4859..0d3e5e48 100644
--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -32,6 +32,7 @@
 #include "deh_str.h"
 #include "doomkeys.h"
 #include "d_iwad.h"
+#include "gusconf.h"
 #include "i_system.h"
 #include "m_argv.h"
 #include "m_config.h"
@@ -193,6 +194,9 @@ static char *steam_install_subdirs[] =
     "steamapps\\common\\DOOM 3 BFG Edition\\base\\wads",
 };

+#define STEAM_BFG_GUS_PATCHES \
+    "steamapps\\common\\DOOM 3 BFG Edition\\base\\classicmusic\\instruments"
+
 static char *GetRegistryString(registry_value_t *reg_val)
 {
     HKEY key;
@@ -327,6 +331,48 @@ static void CheckSteamEdition(void)
     free(install_path);
 }

+// The BFG edition ships with a full set of GUS patches. If we find them,
+// we can autoconfigure to use them.
+
+static void CheckSteamGUSPatches(void)
+{
+    char *install_path;
+    char *patch_path;
+    int len;
+
+    // Already configured? Don't stomp on the user's choices.
+    if (gus_patch_path != NULL && strlen(gus_patch_path) > 0)
+    {
+        return;
+    }
+
+    install_path = GetRegistryString(&steam_install_location);
+
+    if (install_path == NULL)
+    {
+        return;
+    }
+
+    len = strlen(install_path) + strlen(STEAM_BFG_GUS_PATCHES) + 20;
+    patch_path = malloc(len);
+    snprintf(patch_path, len, "%s\\%s\\ACBASS.PAT",
+             install_path, STEAM_BFG_GUS_PATCHES);
+
+    // Does acbass.pat exist? If so, then set gus_patch_path.
+    if (M_FileExists(patch_path))
+    {
+        snprintf(patch_path, len, "%s\\%s",
+                 install_path, STEAM_BFG_GUS_PATCHES);
+        gus_patch_path = patch_path;
+    }
+    else
+    {
+        free(patch_path);
+    }
+
+    free(install_path);
+}
+
 // Default install directories for DOS Doom

 static void CheckDOSDefaults(void)
@@ -565,6 +611,10 @@ static void BuildIWADDirList(void)
     CheckSteamEdition();
     CheckDOSDefaults();

+    // Check for GUS patches installed with the BFG edition!
+
+    CheckSteamGUSPatches();
+
 #else

     // Standard places where IWAD files are installed under Unix.