summaryrefslogtreecommitdiff
path: root/src/deh_main.c
diff options
context:
space:
mode:
authorSimon Howard2014-09-13 01:29:27 -0400
committerSimon Howard2014-09-13 01:30:54 -0400
commiteb1ea531fdba58cddfd583a6e7cef81a10f87242 (patch)
tree440bd1ed864f28983f87e5ff8a12921e66676b38 /src/deh_main.c
parent204814c7bb16a8ad45435a15328072681978ea57 (diff)
parent78ca3a89b94dea261c88441df044709dd4ca8e7a (diff)
downloadchocolate-doom-eb1ea531fdba58cddfd583a6e7cef81a10f87242.tar.gz
chocolate-doom-eb1ea531fdba58cddfd583a6e7cef81a10f87242.tar.bz2
chocolate-doom-eb1ea531fdba58cddfd583a6e7cef81a10f87242.zip
Add support for the BEX extended string syntax.
Boom added an alternate method for overriding Dehacked strings, using the [STRINGS] section with special symbolic names for each of the strings that can possibly be replaced. This format is used in the Freedoom DEHACKED lump (deliberately, so that the Freedoom WAD does not include the original text to be replaced). As we want to have support for the Freedoom IWADs with Chocolate Doom, add support for the BEX [STRINGS] section, but protected by a magic comment that must be included in Dehacked/BEX files that use it. Thanks to Fabian Greffrath for implementing this.
Diffstat (limited to 'src/deh_main.c')
-rw-r--r--src/deh_main.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/deh_main.c b/src/deh_main.c
index c98962a9..be1e5611 100644
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -33,6 +33,10 @@ extern char *deh_signatures[];
static boolean deh_initialized = false;
+// If true, we can parse [STRINGS] sections in BEX format.
+
+boolean deh_allow_extended_strings = false;
+
// If true, we can do long string replacements.
boolean deh_allow_long_strings = false;
@@ -84,6 +88,14 @@ static deh_section_t *GetSectionByName(char *name)
{
unsigned int i;
+ // we explicitely do not recognize [STRINGS] sections at all
+ // if extended strings are not allowed
+
+ if (!deh_allow_extended_strings && !strncasecmp("[STRINGS]", name, 9))
+ {
+ return NULL;
+ }
+
for (i=0; deh_section_types[i] != NULL; ++i)
{
if (!strcasecmp(deh_section_types[i]->name, name))
@@ -175,7 +187,7 @@ static boolean CheckSignatures(deh_context_t *context)
// Read the first line
- line = DEH_ReadLine(context);
+ line = DEH_ReadLine(context, false);
if (line == NULL)
{
@@ -220,6 +232,16 @@ static void DEH_ParseComment(char *comment)
{
deh_allow_long_cheats = true;
}
+
+ // Allow magic comments to allow parsing [STRINGS] section
+ // that are usually only found in BEX format files. This allows
+ // for substitution of map and episode names when loading
+ // Freedoom/FreeDM IWADs.
+
+ if (strstr(comment, "*allow-extended-strings*") != NULL)
+ {
+ deh_allow_extended_strings = true;
+ }
}
// Parses a dehacked file by reading from the context
@@ -230,6 +252,7 @@ static void DEH_ParseContext(deh_context_t *context)
char section_name[20];
void *tag = NULL;
char *line;
+ deh_section_t *bexstr;
// Read the header and check it matches the signature
@@ -238,13 +261,17 @@ static void DEH_ParseContext(deh_context_t *context)
DEH_Error(context, "This is not a valid dehacked patch file!");
}
+ // extended string support required?
+
+ bexstr = GetSectionByName("[STRINGS]");
+
// Read the file
for (;;)
{
// read a new line
- line = DEH_ReadLine(context);
+ line = DEH_ReadLine(context, bexstr && current_section == bexstr);
// end of file?