diff options
author | Simon Howard | 2014-09-13 03:55:00 -0400 |
---|---|---|
committer | Simon Howard | 2014-09-13 03:55:00 -0400 |
commit | cb72358ee930b29f4840b04bbb81f8d8444ce481 (patch) | |
tree | c2b9865637b9cbd93e53e1cc7c26d4553dc4a203 | |
parent | 9531cdfcfadc0d4c2b767f27238bc9ac742787e0 (diff) | |
download | chocolate-doom-cb72358ee930b29f4840b04bbb81f8d8444ce481.tar.gz chocolate-doom-cb72358ee930b29f4840b04bbb81f8d8444ce481.tar.bz2 chocolate-doom-cb72358ee930b29f4840b04bbb81f8d8444ce481.zip |
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.
-rw-r--r-- | src/deh_io.c | 19 | ||||
-rw-r--r-- | src/deh_io.h | 1 | ||||
-rw-r--r-- | src/deh_main.c | 22 | ||||
-rw-r--r-- | src/deh_main.h | 4 | ||||
-rw-r--r-- | src/doom/d_main.c | 14 |
5 files changed, 44 insertions, 16 deletions
diff --git a/src/deh_io.c b/src/deh_io.c index fa02aa2e..4b264370 100644 --- a/src/deh_io.c +++ b/src/deh_io.c @@ -42,7 +42,6 @@ struct deh_context_s // 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 @@ struct deh_context_s // 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 @@ static deh_context_t *DEH_NewContext(void) context->linenum = 0; context->last_was_newline = true; + context->had_error = false; + return context; } @@ -307,7 +308,7 @@ void DEH_Warning(deh_context_t *context, char *msg, ...) va_list args; va_start(args, msg); - + fprintf(stderr, "%s:%i: warning: ", context->filename, context->linenum); vfprintf(stderr, msg, args); fprintf(stderr, "\n"); @@ -320,14 +321,18 @@ void DEH_Error(deh_context_t *context, char *msg, ...) va_list args; va_start(args, msg); - + fprintf(stderr, "%s:%i: ", context->filename, context->linenum); vfprintf(stderr, msg, args); fprintf(stderr, "\n"); va_end(args); - I_Error("Error parsing dehacked file"); + context->had_error = true; } +boolean DEH_HadError(deh_context_t *context) +{ + return context->had_error; +} diff --git a/src/deh_io.h b/src/deh_io.h index 0995cda1..f7c8263f 100644 --- a/src/deh_io.h +++ b/src/deh_io.h @@ -27,6 +27,7 @@ int DEH_GetChar(deh_context_t *context); 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 */ diff --git a/src/deh_main.c b/src/deh_main.c index a7846975..ff4500aa 100644 --- a/src/deh_main.c +++ b/src/deh_main.c @@ -275,7 +275,7 @@ static void DEH_ParseContext(deh_context_t *context) // 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 @@ static void DEH_ParseContext(deh_context_t *context) sscanf(line, "%19s", section_name); current_section = GetSectionByName(section_name); - + if (current_section != NULL) { tag = current_section->start(context, line); @@ -379,13 +379,18 @@ int DEH_LoadFile(char *filename) DEH_CloseFile(context); + if (DEH_HadError(context)) + { + I_Error("Error parsing dehacked file"); + } + return 1; } // 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 @@ int DEH_LoadLump(int lumpnum, boolean allow_long) 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 @@ int DEH_LoadLumpByName(char *name, boolean allow_long) return 0; } - return DEH_LoadLump(lumpnum, allow_long); + return DEH_LoadLump(lumpnum, allow_long, allow_error); } // Checks the command line for -deh argument diff --git a/src/deh_main.h b/src/deh_main.h index 4b3f9d8a..c9d41bf2 100644 --- 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); diff --git a/src/doom/d_main.c b/src/doom/d_main.c index 4c1092ac..d4859b30 100644 --- a/src/doom/d_main.c +++ b/src/doom/d_main.c @@ -1066,7 +1066,7 @@ static void LoadHacxDeh(void) 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 @@ void D_DoomMain (void) 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 @@ void D_DoomMain (void) { if (!strncmp(lumpinfo[i].name, "DEHACKED", 8)) { - DEH_LoadLump(i, false); + DEH_LoadLump(i, false, false); loaded++; } } |