shithub: choc

Download patch

ref: cb72358ee930b29f4840b04bbb81f8d8444ce481
parent: 9531cdfcfadc0d4c2b767f27238bc9ac742787e0
author: Simon Howard <fraggle@gmail.com>
date: Fri Sep 12 23:55:00 EDT 2014

dehacked: Load Freedoom DEHACKED lump on startup.

If using one of the Freedoom IWADs, detect it by checking for the
FREEDOOM lump, and then load its DEHACKED lump to apply the
cosmetic string changes that it includes. In case we're using an old
version of one of the Freedoom IWADs, don't bomb out with an error
while parsing the DEHACKED lump.

--- a/src/deh_io.c
+++ b/src/deh_io.c
@@ -42,7 +42,6 @@
 
     // If the input comes from a memory buffer, pointer to the memory
     // buffer.
-
     unsigned char *input_buffer;
     size_t input_buffer_len;
     unsigned int input_buffer_pos;
@@ -50,18 +49,18 @@
 
     // If the input comes from a file, the file stream for reading
     // data.
-
     FILE *stream;
 
     // Current line number that we have reached:
-
     int linenum;
 
     // Used by DEH_ReadLine:
-
     boolean last_was_newline;
     char *readbuffer;
     int readbuffer_size;
+
+    // Error handling.
+    boolean had_error;
 };
 
 static deh_context_t *DEH_NewContext(void)
@@ -77,6 +76,8 @@
     context->linenum = 0;
     context->last_was_newline = true;
 
+    context->had_error = false;
+
     return context;
 }
 
@@ -307,7 +308,7 @@
     va_list args;
 
     va_start(args, msg);
-    
+
     fprintf(stderr, "%s:%i: warning: ", context->filename, context->linenum);
     vfprintf(stderr, msg, args);
     fprintf(stderr, "\n");
@@ -320,7 +321,7 @@
     va_list args;
 
     va_start(args, msg);
-    
+
     fprintf(stderr, "%s:%i: ", context->filename, context->linenum);
     vfprintf(stderr, msg, args);
     fprintf(stderr, "\n");
@@ -327,7 +328,11 @@
 
     va_end(args);
 
-    I_Error("Error parsing dehacked file");
+    context->had_error = true;
 }
 
+boolean DEH_HadError(deh_context_t *context)
+{
+    return context->had_error;
+}
 
--- a/src/deh_io.h
+++ b/src/deh_io.h
@@ -27,6 +27,7 @@
 char *DEH_ReadLine(deh_context_t *context, boolean extended);
 void DEH_Error(deh_context_t *context, char *msg, ...);
 void DEH_Warning(deh_context_t *context, char *msg, ...);
+boolean DEH_HadError(deh_context_t *context);
 
 #endif /* #ifndef DEH_IO_H */
 
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -275,7 +275,7 @@
 
     // Read the file
 
-    for (;;)
+    while (!DEH_HadError(context))
     {
         // Read the next line. We only allow the special extended parsing
         // for the BEX [STRINGS] section.
@@ -331,7 +331,7 @@
                 sscanf(line, "%19s", section_name);
 
                 current_section = GetSectionByName(section_name);
-                
+
                 if (current_section != NULL)
                 {
                     tag = current_section->start(context, line);
@@ -379,6 +379,11 @@
 
     DEH_CloseFile(context);
 
+    if (DEH_HadError(context))
+    {
+        I_Error("Error parsing dehacked file");
+    }
+
     return 1;
 }
 
@@ -385,7 +390,7 @@
 // Load dehacked file from WAD lump.
 // If allow_long is set, allow long strings and cheats just for this lump.
 
-int DEH_LoadLump(int lumpnum, boolean allow_long)
+int DEH_LoadLump(int lumpnum, boolean allow_long, boolean allow_error)
 {
     deh_context_t *context;
 
@@ -412,10 +417,17 @@
 
     DEH_CloseFile(context);
 
+    // If there was an error while parsing, abort with an error, but allow
+    // errors to just be ignored if allow_error=true.
+    if (!allow_error && DEH_HadError(context))
+    {
+        I_Error("Error parsing dehacked lump");
+    }
+
     return 1;
 }
 
-int DEH_LoadLumpByName(char *name, boolean allow_long)
+int DEH_LoadLumpByName(char *name, boolean allow_long, boolean allow_error)
 {
     int lumpnum;
 
@@ -427,7 +439,7 @@
         return 0;
     }
 
-    return DEH_LoadLump(lumpnum, allow_long);
+    return DEH_LoadLump(lumpnum, allow_long, allow_error);
 }
 
 // Checks the command line for -deh argument
--- a/src/deh_main.h
+++ b/src/deh_main.h
@@ -32,8 +32,8 @@
 
 void DEH_Init(void);
 int DEH_LoadFile(char *filename);
-int DEH_LoadLump(int lumpnum, boolean allow_long);
-int DEH_LoadLumpByName(char *name, boolean allow_long);
+int DEH_LoadLump(int lumpnum, boolean allow_long, boolean allow_error);
+int DEH_LoadLumpByName(char *name, boolean allow_long, boolean allow_error);
 
 boolean DEH_ParseAssignment(char *line, char **variable_name, char **value);
 
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1066,7 +1066,7 @@
 
     if (gameversion == exe_hacx)
     {
-        if (!DEH_LoadLumpByName("DEHACKED", true))
+        if (!DEH_LoadLumpByName("DEHACKED", true, false))
         {
             I_Error("DEHACKED lump not found.  Please check that this is the "
                     "Hacx v1.2 IWAD.");
@@ -1299,6 +1299,16 @@
 
     W_CheckCorrectIWAD(doom);
 
+    // The Freedoom IWADs have DEHACKED lumps with cosmetic changes to the
+    // in-game messages. Load this.
+    // Old versions of Freedoom (before 2014-09) did not have technically
+    // valid DEHACKED lumps, so ignore errors and just continue if this
+    // is an old IWAD.
+    if (W_CheckNumForName("FREEDOOM") >= 0)
+    {
+        DEH_LoadLumpByName("DEHACKED", false, true);
+    }
+
     // 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
@@ -1461,7 +1471,7 @@
         {
             if (!strncmp(lumpinfo[i].name, "DEHACKED", 8))
             {
-                DEH_LoadLump(i, false);
+                DEH_LoadLump(i, false, false);
                 loaded++;
             }
         }