foxygit / doom Log in
commit 4f5b2b8a2f45229114e66e546d0795e6373afd88
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Thu Nov 24 20:20:28 2016 -0500
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Thu Nov 24 20:20:28 2016 -0500

    hexen: Forbid demo extensions in WAD files.

    Save and restore of these extension bits is a convenience for demo
    playback purposes and not intended as an editing feature. If a demo
    with such bits set is found inside a WAD file, we ignore them as
    Vanilla Hexen would do.

    Part of #817.
---
 src/hexen/g_game.c | 41 ++++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/src/hexen/g_game.c b/src/hexen/g_game.c
index 67e6586a..7fe370f4 100644
--- a/src/hexen/g_game.c
+++ b/src/hexen/g_game.c
@@ -2046,23 +2046,50 @@ void G_DeferedPlayDemo(char *name)
     gameaction = ga_playdemo;
 }

+// Returns true if the given lump number corresponds to data from a .lmp
+// file, as opposed to a WAD.
+static boolean IsDemoFile(int lumpnum)
+{
+    char *lower;
+    boolean result;
+
+    lower = M_StringDuplicate(lumpinfo[lumpnum]->wad_file->path);
+    M_ForceLowercase(lower);
+    result = M_StringEndsWith(lower, ".lmp");
+    free(lower);
+
+    return result;
+}
+
 void G_DoPlayDemo(void)
 {
     skill_t skill;
-    int i, episode, map;
+    int i, lumpnum, episode, map;

     gameaction = ga_nothing;
-    demobuffer = demo_p = W_CacheLumpName(defdemoname, PU_STATIC);
+    lumpnum = W_GetNumForName(defdemoname);
+    demobuffer = W_CacheLumpNum(lumpnum, PU_STATIC);
+    demo_p = demobuffer;
     skill = *demo_p++;
     episode = *demo_p++;
     map = *demo_p++;

-    // Read special parameter bits: see G_RecordDemo() for details.
-    longtics = (*demo_p & DEMOHEADER_LONGTICS) != 0;
+    // When recording we store some extra options inside the upper bits
+    // of the player 1 present byte; this is equivalent to what vvHeretic
+    // does. However, only recognize these bits if they are in a demo file
+    // being played manually by the user; we ignore them (as is Vanilla
+    // behavior) if they are inside a WAD file.
+    // These extra bits are a convenience feature for demo playback, not
+    // an editing extension for WAD authors.
+    if (IsDemoFile(lumpnum))
+    {
+        // Read special parameter bits: see G_RecordDemo() for details.
+        longtics = (*demo_p & DEMOHEADER_LONGTICS) != 0;

-    // don't overwrite arguments from the command line
-    respawnparm |= (*demo_p & DEMOHEADER_RESPAWN) != 0;
-    nomonsters  |= (*demo_p & DEMOHEADER_NOMONSTERS) != 0;
+        // don't overwrite arguments from the command line
+        respawnparm |= (*demo_p & DEMOHEADER_RESPAWN) != 0;
+        nomonsters |= (*demo_p & DEMOHEADER_NOMONSTERS) != 0;
+    }

     for (i = 0; i < maxplayers; i++)
     {