shithub: choc

Download patch

ref: 52cee8eac843c5488cfe03fc1717dea5d2eb307c
parent: ffb988cdecd7c2d0ef84290ecde8da6be539f55b
author: Thomas A. Birkel <capnclever@gmail.com>
date: Fri Oct 28 16:50:14 EDT 2016

Add compatibility options to Heretic/Hexen

Includes unlimited demo support for both games, savegame buffer overrun
suppression for Heretic, and CopyFile allocation fix for Hexen.

--- a/NEWS.md
+++ b/NEWS.md
@@ -52,6 +52,7 @@
 ### Heretic
   * Added map names for Episode 6, fixing a crash after completing a
     level in this episode. (thanks J.Benaim)
+  * Add unlimited demo/savegame support. (thanks CapnClever)
 
 ### Hexen
   * The MRJONES cheat code returns an identical string as vanilla, and
@@ -58,6 +59,7 @@
     enables fully reproducable builds. (thanks Fabian)
   * Fixed an issue where the game crashed while killing the
     Wraithverge in 64-bit builds. (thanks J.Benaim)
+  * Add unlimited demo/savegame support. (thanks CapnClever)
 
 ### Strife
   * Support added for automatic loading of the IWAD from the GOG.com
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -764,6 +764,8 @@
     M_BindIntVariable("music_volume",           &snd_MusicVolume);
     M_BindIntVariable("screenblocks",           &screenblocks);
     M_BindIntVariable("snd_channels",           &snd_Channels);
+    M_BindIntVariable("vanilla_savegame_limit", &vanilla_savegame_limit);
+    M_BindIntVariable("vanilla_demo_limit",     &vanilla_demo_limit);
     M_BindIntVariable("show_endoom",            &show_endoom);
     M_BindIntVariable("graphical_startup",      &graphical_startup);
 
--- a/src/heretic/doomdef.h
+++ b/src/heretic/doomdef.h
@@ -569,6 +569,9 @@
 extern boolean testcontrols;
 extern int testcontrols_mousespeed;
 
+extern int vanilla_savegame_limit;
+extern int vanilla_demo_limit;
+
 /*
 ===============================================================================
 
--- a/src/heretic/g_game.c
+++ b/src/heretic/g_game.c
@@ -198,6 +198,8 @@
 int savegameslot;
 char savedescription[32];
 
+int vanilla_demo_limit = 1;
+
 int inventoryTics;
 
 // haleyjd: removed WATCOMC
@@ -1683,6 +1685,38 @@
     cmd->arti = (unsigned char) *demo_p++;
 }
 
+// Increase the size of the demo buffer to allow unlimited demos
+
+static void IncreaseDemoBuffer(void)
+{
+    int current_length;
+    byte *new_demobuffer;
+    byte *new_demop;
+    int new_length;
+
+    // Find the current size
+
+    current_length = demoend - demobuffer;
+
+    // Generate a new buffer twice the size
+    new_length = current_length * 2;
+
+    new_demobuffer = Z_Malloc(new_length, PU_STATIC, 0);
+    new_demop = new_demobuffer + (demo_p - demobuffer);
+
+    // Copy over the old data
+
+    memcpy(new_demobuffer, demobuffer, current_length);
+
+    // Free the old buffer and point the demo pointers at the new buffer.
+
+    Z_Free(demobuffer);
+
+    demobuffer = new_demobuffer;
+    demo_p = new_demop;
+    demoend = demobuffer + new_length;
+}
+
 void G_WriteDemoTiccmd(ticcmd_t * cmd)
 {
     byte *demo_start;
@@ -1716,9 +1750,19 @@
 
     if (demo_p > demoend - 16)
     {
-        // no more space
-        G_CheckDemoStatus();
-        return;
+        if (vanilla_demo_limit)
+        {
+            // no more space
+            G_CheckDemoStatus();
+            return;
+        }
+        else
+        {
+            // Vanilla demo limit disabled: unlimited
+            // demo lengths!
+
+            IncreaseDemoBuffer();
+        }
     }
 
     G_ReadDemoTiccmd(cmd);      // make SURE it is exactly the same
--- a/src/heretic/p_saveg.c
+++ b/src/heretic/p_saveg.c
@@ -31,7 +31,9 @@
 static FILE *SaveGameFP;
 static byte *savebuffer, *save_p;
 
+int vanilla_savegame_limit = 1;
 
+
 //==========================================================================
 //
 // SV_Filename
@@ -82,7 +84,7 @@
 
     // Enforce the same savegame size limit as in Vanilla Heretic
 
-    if (ftell(SaveGameFP) > SAVEGAMESIZE)
+    if (vanilla_savegame_limit && ftell(SaveGameFP) > SAVEGAMESIZE)
     {
         I_Error("Savegame buffer overrun");
     }
--- a/src/hexen/g_game.c
+++ b/src/hexen/g_game.c
@@ -165,6 +165,8 @@
 int savegameslot;
 char savedescription[32];
 
+int vanilla_demo_limit = 1;
+
 int inventoryTics;
 
 // haleyjd: removed externdriver crap
@@ -1842,6 +1844,38 @@
     cmd->arti = (unsigned char) *demo_p++;
 }
 
+// Increase the size of the demo buffer to allow unlimited demos
+
+static void IncreaseDemoBuffer(void)
+{
+    int current_length;
+    byte *new_demobuffer;
+    byte *new_demop;
+    int new_length;
+
+    // Find the current size
+
+    current_length = demoend - demobuffer;
+
+    // Generate a new buffer twice the size
+    new_length = current_length * 2;
+
+    new_demobuffer = Z_Malloc(new_length, PU_STATIC, 0);
+    new_demop = new_demobuffer + (demo_p - demobuffer);
+
+    // Copy over the old data
+
+    memcpy(new_demobuffer, demobuffer, current_length);
+
+    // Free the old buffer and point the demo pointers at the new buffer.
+
+    Z_Free(demobuffer);
+
+    demobuffer = new_demobuffer;
+    demo_p = new_demop;
+    demoend = demobuffer + new_length;
+}
+
 void G_WriteDemoTiccmd(ticcmd_t * cmd)
 {
     byte *demo_start;
@@ -1875,9 +1909,19 @@
 
     if (demo_p > demoend - 16)
     {
-        // no more space
-        G_CheckDemoStatus();
-        return;
+        if (vanilla_demo_limit)
+        {
+            // no more space
+            G_CheckDemoStatus();
+            return;
+        }
+        else
+        {
+            // Vanilla demo limit disabled: unlimited
+            // demo lengths!
+
+            IncreaseDemoBuffer();
+        }
     }
 
     G_ReadDemoTiccmd(cmd);      // make SURE it is exactly the same
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -161,6 +161,8 @@
     M_BindIntVariable("messageson",             &messageson);
     M_BindIntVariable("screenblocks",           &screenblocks);
     M_BindIntVariable("snd_channels",           &snd_Channels);
+    M_BindIntVariable("vanilla_savegame_limit", &vanilla_savegame_limit);
+    M_BindIntVariable("vanilla_demo_limit",     &vanilla_demo_limit);
 
     M_BindStringVariable("savedir", &SavePath);
 
--- a/src/hexen/h2def.h
+++ b/src/hexen/h2def.h
@@ -682,6 +682,9 @@
 extern boolean testcontrols;
 extern int testcontrols_mousespeed;
 
+extern int vanilla_savegame_limit;
+extern int vanilla_demo_limit;
+
 /*
 ===============================================================================
 
--- a/src/hexen/sv_save.c
+++ b/src/hexen/sv_save.c
@@ -142,6 +142,8 @@
 
 char *SavePath = DEFAULT_SAVEPATH;
 
+int vanilla_savegame_limit = 1;
+
 // PRIVATE DATA DEFINITIONS ------------------------------------------------
 
 static int MobjCount;
@@ -3270,8 +3272,11 @@
     // in memory: Chocolate Hexen should force an allocation error here
     // whenever it's appropriate.
 
-    buffer = Z_Malloc(file_length, PU_STATIC, NULL);
-    Z_Free(buffer);
+    if (vanilla_savegame_limit)
+    {
+        buffer = Z_Malloc(file_length, PU_STATIC, NULL);
+        Z_Free(buffer);
+    }
 
     write_handle = fopen(dest_name, "wb");
     if (write_handle == NULL)
--- a/src/setup/compatibility.c
+++ b/src/setup/compatibility.c
@@ -45,10 +45,7 @@
 
 void BindCompatibilityVariables(void)
 {
-    if (gamemission == doom || gamemission == strife)
-    {
-        M_BindIntVariable("vanilla_savegame_limit", &vanilla_savegame_limit);
-        M_BindIntVariable("vanilla_demo_limit",     &vanilla_demo_limit);
-    }
+    M_BindIntVariable("vanilla_savegame_limit", &vanilla_savegame_limit);
+    M_BindIntVariable("vanilla_demo_limit",     &vanilla_demo_limit);
 }
 
--- a/src/setup/mainmenu.c
+++ b/src/setup/mainmenu.c
@@ -226,20 +226,9 @@
                          (TxtWidgetSignalFunc) ConfigMouse, NULL),
           TXT_NewButton2("Configure Gamepad/Joystick",
                          (TxtWidgetSignalFunc) ConfigJoystick, NULL),
+          TXT_NewButton2("Compatibility",
+                         (TxtWidgetSignalFunc) CompatibilitySettings, NULL),
           NULL);
-
-    // The compatibility window is only appropriate for Doom/Strife.
-
-    if (gamemission == doom || gamemission == strife)
-    {
-        txt_button_t *button;
-
-        button = TXT_NewButton2("Compatibility", 
-                                (TxtWidgetSignalFunc) CompatibilitySettings,
-                                NULL);
-
-        TXT_AddWidget(window, button);
-    }
 
     TXT_AddWidgets(window,
           GetLaunchButton(),