shithub: choc

Download patch

ref: 48e96443151db631e1153d459e850c49a96ccb29
parent: b86a383c6fdc394ef995a8e88324c89408f01c05
author: Simon Howard <[email protected]>
date: Fri Apr 18 23:32:38 EDT 2014

Exit with error on startup if using the wrong IWAD.

Having multiple binaries can cause some confusion - some users try to
run chocolate-doom with hexen.wad, thinking it is supported. Add a
startup check that makes sure the user is not trying to start the game
using the wrong IWAD file for the binary being run.

This fixes #382.

--- a/src/d_iwad.c
+++ b/src/d_iwad.c
@@ -39,7 +39,7 @@
 #include "w_wad.h"
 #include "z_zone.h"
 
-static iwad_t iwads[] =
+static const iwad_t iwads[] =
 {
     { "doom2.wad",    doom2,     commercial, "Doom II" },
     { "plutonia.wad", pack_plut, commercial, "Final Doom: Plutonia Experiment" },
@@ -749,9 +749,9 @@
 
 // Find all IWADs in the IWAD search path matching the given mask.
 
-iwad_t **D_FindAllIWADs(int mask)
+const iwad_t **D_FindAllIWADs(int mask)
 {
-    iwad_t **result;
+    const iwad_t **result;
     int result_len;
     char *filename;
     int i;
@@ -833,7 +833,8 @@
 
     for (i = 0; i < arrlen(iwads); ++i)
     {
-        if (iwads[i].mission == mission && iwads[i].mode == mode)
+        if (iwads[i].mission == mission
+         && (mode == indetermined || iwads[i].mode == mode))
         {
             return iwads[i].description;
         }
--- a/src/d_iwad.h
+++ b/src/d_iwad.h
@@ -50,10 +50,11 @@
 char *D_FindWADByName(char *filename);
 char *D_TryFindWADByName(char *filename);
 char *D_FindIWAD(int mask, GameMission_t *mission);
-iwad_t **D_FindAllIWADs(int mask);
+const iwad_t **D_FindAllIWADs(int mask);
 char *D_SaveGameIWADName(GameMission_t gamemission);
 char *D_SuggestIWADName(GameMission_t mission, GameMode_t mode);
 char *D_SuggestGameName(GameMission_t mission, GameMode_t mode);
+void D_CheckCorrectIWAD(GameMission_t mission);
 
 #endif
 
--- a/src/d_mode.c
+++ b/src/d_mode.c
@@ -187,3 +187,30 @@
     }
 }
 
+char *D_GameMissionString(GameMission_t mission)
+{
+    switch (mission)
+    {
+        case none:
+            return "none";
+        case doom:
+            return "doom";
+        case doom2:
+            return "doom2";
+        case pack_tnt:
+            return "tnt";
+        case pack_plut:
+            return "plutonia";
+        case pack_hacx:
+            return "hacx";
+        case pack_chex:
+            return "chex";
+        case heretic:
+            return "heretic";
+        case hexen:
+            return "hexen";
+        case strife:
+            return "strife";
+    }
+}
+
--- a/src/d_mode.h
+++ b/src/d_mode.h
@@ -100,6 +100,7 @@
                           int episode, int map);
 int D_GetNumEpisodes(GameMission_t mission, GameMode_t mode);
 boolean D_IsEpisodeMap(GameMission_t mission);
+char *D_GameMissionString(GameMission_t mission);
 
 #endif /* #ifndef __D_MODE__ */
 
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1305,6 +1305,8 @@
     DEH_printf("W_Init: Init WADfiles.\n");
     D_AddFile(iwadfile);
 
+    W_CheckCorrectIWAD(doom);
+
     // Doom 3: BFG Edition includes modified versions of the classic
     // IWADs which can be identified by an additional DMENUPIC lump.
     // Furthermore, the M_GDHIGH lumps have been modified in a way that
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -979,6 +979,7 @@
     }
 
     D_AddFile(iwadfile);
+    W_CheckCorrectIWAD(heretic);
     W_ParseCommandLine();
 
     //!
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -304,6 +304,7 @@
     }
 
     D_AddFile(iwadfile);
+    W_CheckCorrectIWAD(hexen);
 
     HandleArgs();
 
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -1560,6 +1560,7 @@
     if(devparm) // [STRIFE] Devparm only
         DEH_printf("W_Init: Init WADfiles.\n");
     D_AddFile(iwadfile);
+    W_CheckCorrectIWAD(strife);
     modifiedgame = W_ParseCommandLine();
 
     // [STRIFE] serial number output
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -34,6 +34,8 @@
 
 #include "doomtype.h"
 
+#include "config.h"
+#include "d_iwad.h"
 #include "i_swap.h"
 #include "i_system.h"
 #include "i_video.h"
@@ -535,5 +537,46 @@
     }
 
     // All done!
+}
+
+// Lump names that are unique to particular game types. This lets us check
+// the user is not trying to play with the wrong executable, eg.
+// chocolate-doom -iwad hexen.wad.
+static const struct
+{
+    GameMission_t mission;
+    char *lumpname;
+} unique_lumps[] = {
+    { doom,    "POSSA1" },
+    { heretic, "IMPXA1" },
+    { hexen,   "ETTNA1" },
+    { strife,  "AGRDA1" },
+};
+
+void W_CheckCorrectIWAD(GameMission_t mission)
+{
+    int i;
+    int lumpnum;
+
+    for (i = 0; i < arrlen(unique_lumps); ++i)
+    {
+        if (mission != unique_lumps[i].mission)
+        {
+            lumpnum = W_CheckNumForName(unique_lumps[i].lumpname);
+
+            if (lumpnum >= 0)
+            {
+                I_Error("\nYou are trying to use a %s IWAD file with "
+                        "the %s%s binary.\nThis isn't going to work.\n"
+                        "You probably want to use the %s%s binary.",
+                        D_SuggestGameName(unique_lumps[i].mission,
+                                          indetermined),
+                        PROGRAM_PREFIX,
+                        D_GameMissionString(mission),
+                        PROGRAM_PREFIX,
+                        D_GameMissionString(unique_lumps[i].mission));
+            }
+        }
+    }
 }
 
--- a/src/w_wad.h
+++ b/src/w_wad.h
@@ -31,6 +31,7 @@
 #include <stdio.h>
 
 #include "doomtype.h"
+#include "d_mode.h"
 
 #include "w_file.h"
 
@@ -80,5 +81,6 @@
 void    W_ReleaseLumpNum(int lump);
 void    W_ReleaseLumpName(char *name);
 
+void W_CheckCorrectIWAD(GameMission_t mission);
 
 #endif