foxygit / doom Log in
commit c39b37221169c959dc5746c9d009f8574ff7731e
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sat Oct 28 00:23:11 2006 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sat Oct 28 00:23:11 2006 +0000

    Display a warning when setting dehacked fields that would overflow
    buffers in Vanilla dehacked. This should help pick up bugs like the one
    in Batman Doom.

    Subversion-branch: /trunk/chocolate-doom
    Subversion-revision: 742
---
 src/deh_frame.c | 6 ++++++
 src/deh_main.h  | 7 +++++++
 src/deh_sound.c | 6 ++++++
 3 files changed, 19 insertions(+)

diff --git a/src/deh_frame.c b/src/deh_frame.c
index a2e4dc47..2204579b 100644
--- a/src/deh_frame.c
+++ b/src/deh_frame.c
@@ -62,6 +62,12 @@ static void *DEH_FrameStart(deh_context_t *context, char *line)
         return NULL;
     }

+    if (frame_number >= DEH_VANILLA_NUMSTATES)
+    {
+        DEH_Warning(context, "Attempt to modify frame %i: this will cause "
+                             "problems in Vanilla dehacked.", frame_number);
+    }
+
     state = &states[frame_number];

     return state;
diff --git a/src/deh_main.h b/src/deh_main.h
index 416564d8..b1460a07 100644
--- a/src/deh_main.h
+++ b/src/deh_main.h
@@ -31,6 +31,13 @@
 #include "doomfeatures.h"
 #include "md5.h"

+// These are the limits that dehacked uses (from dheinit.h in the dehacked
+// source).  If these limits are exceeded, it does not generate an error, but
+// a warning is displayed.
+
+#define DEH_VANILLA_NUMSTATES 966
+#define DEH_VANILLA_NUMSFX 107
+
 void DEH_Init(void);

 boolean DEH_ParseAssignment(char *line, char **variable_name, char **value);
diff --git a/src/deh_sound.c b/src/deh_sound.c
index 180108c0..9f99384b 100644
--- a/src/deh_sound.c
+++ b/src/deh_sound.c
@@ -61,6 +61,12 @@ static void *DEH_SoundStart(deh_context_t *context, char *line)
         DEH_Warning(context, "Invalid sound number: %i", sound_number);
         return NULL;
     }
+
+    if (sound_number >= DEH_VANILLA_NUMSFX)
+    {
+        DEH_Warning(context, "Attempt to modify SFX %i.  This will problems "
+                             "in Vanilla dehacked.", sound_number);
+    }

     sfx = &S_sfx[sound_number];