shithub: choc

Download patch

ref: d2b34da108fae24c9c70ab00aa261cc9648018c3
parent: 09180d3f73e522c1e0c43993aec28cf339dcf74d
author: Simon Howard <fraggle@gmail.com>
date: Thu Oct 5 18:12:22 EDT 2006

Dehacked information checksum generation

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 687

--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -71,6 +71,7 @@
 m_fixed.c            m_fixed.h             \
 m_menu.c             m_menu.h              \
 m_misc.c             m_misc.h              \
+md5.c                md5.h                 \
 memio.c              memio.h               \
 mus2mid.c            mus2mid.h             \
 m_random.c           m_random.h            \
@@ -125,6 +126,7 @@
 tables.c             tables.h              \
 v_video.c            v_video.h             \
 wi_stuff.c           wi_stuff.h            \
+w_checksum.c         w_checksum.h          \
 w_merge.c            w_merge.h             \
 w_wad.c              w_wad.h               \
 z_zone.c             z_zone.h   
--- a/src/deh_ammo.c
+++ b/src/deh_ammo.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_ammo.c 175 2005-10-08 20:54:16Z fraggle $
+// $Id: deh_ammo.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -106,6 +106,17 @@
     }
 }
 
+static void DEH_AmmoMD5Hash(md5_context_t *context)
+{
+    int i;
+
+    for (i=0; i<NUMAMMO; ++i)
+    {
+        MD5_UpdateInt32(context, clipammo[i]);
+        MD5_UpdateInt32(context, maxammo[i]);
+    }
+}
+
 deh_section_t deh_section_ammo =
 {
     "Ammo",
@@ -113,5 +124,6 @@
     DEH_AmmoStart,
     DEH_AmmoParseLine,
     NULL,
+    DEH_AmmoMD5Hash,
 };
 
--- a/src/deh_cheat.c
+++ b/src/deh_cheat.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_cheat.c 641 2006-09-21 11:13:28Z rtc_marine $
+// $Id: deh_cheat.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -137,6 +137,7 @@
     NULL,
     DEH_CheatStart,
     DEH_CheatParseLine,
+    NULL,
     NULL,
 };
 
--- a/src/deh_defs.h
+++ b/src/deh_defs.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_defs.h 153 2005-10-02 23:49:01Z fraggle $
+// $Id: deh_defs.h 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -34,6 +34,8 @@
 #ifndef DEH_DEFS_H
 #define DEH_DEFS_H
 
+#include "md5.h"
+
 typedef struct deh_context_s deh_context_t;
 typedef struct deh_section_s deh_section_t;
 typedef void (*deh_section_init_t)(void);
@@ -40,6 +42,7 @@
 typedef void *(*deh_section_start_t)(deh_context_t *context, char *line);
 typedef void (*deh_section_end_t)(deh_context_t *context, void *tag);
 typedef void (*deh_line_parser_t)(deh_context_t *context, char *line, void *tag);
+typedef void (*deh_md5_hash_t)(md5_context_t *context);
 
 struct deh_section_s
 {
@@ -61,6 +64,10 @@
     // This is called at the end of the section for any cleanup
 
     deh_section_end_t end;
+
+    // Called when generating an MD5 sum of the dehacked state
+
+    deh_md5_hash_t md5_hash;
 };
 
 #endif /* #ifndef DEH_DEFS_H */
--- a/src/deh_frame.c
+++ b/src/deh_frame.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_frame.c 420 2006-03-15 18:53:06Z fraggle $
+// $Id: deh_frame.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -118,6 +118,16 @@
     DEH_SetMapping(context, &state_mapping, state, variable_name, ivalue);
 }
 
+static void DEH_FrameMD5Sum(md5_context_t *context)
+{
+    int i;
+
+    for (i=0; i<NUMSTATES; ++i)
+    {
+        DEH_StructMD5Sum(context, &state_mapping, &states[i]);
+    }
+}
+
 deh_section_t deh_section_frame =
 {
     "Frame",
@@ -125,5 +135,6 @@
     DEH_FrameStart,
     DEH_FrameParseLine,
     NULL,
+    DEH_FrameMD5Sum,
 };
 
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_main.c 641 2006-09-21 11:13:28Z rtc_marine $
+// $Id: deh_main.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -112,6 +112,24 @@
 };
 
 static int num_section_types = sizeof(section_types) / sizeof(*section_types);
+
+void DEH_Checksum(byte digest[16])
+{
+    md5_context_t md5_context;
+    int i;
+
+    MD5_Init(&md5_context);
+
+    for (i=0; i<num_section_types; ++i)
+    {
+        if (section_types[i]->md5_hash != NULL)
+        {
+            section_types[i]->md5_hash(&md5_context);
+        }
+    }
+
+    MD5_Final(digest, &md5_context);
+}
 
 // Called on startup to call the Init functions
 
--- a/src/deh_main.h
+++ b/src/deh_main.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_main.h 214 2005-10-17 23:48:05Z fraggle $
+// $Id: deh_main.h 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -50,6 +50,8 @@
 void DEH_Init(void);
 
 boolean DEH_ParseAssignment(char *line, char **variable_name, char **value);
+
+void DEH_Checksum(byte digest[16]);
 
 // deh_text.c:
 //
--- a/src/deh_mapping.c
+++ b/src/deh_mapping.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_mapping.c 175 2005-10-08 20:54:16Z fraggle $
+// $Id: deh_mapping.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -44,6 +44,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "i_system.h"
 #include "deh_mapping.h"
 
 //
@@ -85,9 +86,6 @@
                 case 4:
                     * ((unsigned int *) location) = value;
                     break;
-                case 8:
-                    * ((unsigned long long *) location) = value;
-                    break;
                 default:
                     DEH_Error(context, "Unknown field type for '%s' (BUG)", name);
                     return false;
@@ -102,5 +100,47 @@
     DEH_Warning(context, "Field named '%s' not found", name);
 
     return false;
+}
+
+void DEH_StructMD5Sum(md5_context_t *context, deh_mapping_t *mapping,
+                      void *structptr)
+{
+    int i;
+
+    // Go through each mapping
+
+    for (i=0; mapping->entries[i].name != NULL; ++i)
+    {
+        deh_mapping_entry_t *entry = &mapping->entries[i];
+        void *location;
+
+        if (entry->location == NULL)
+        {
+            // Unsupported field
+
+            continue;
+        }
+
+        // Add in data for this field
+
+        location = structptr + (entry->location - mapping->base);
+
+        switch (entry->size)
+        {
+            case 1:
+                MD5_UpdateInt32(context, *((unsigned char *) location));
+                break;
+            case 2:
+                MD5_UpdateInt32(context, *((unsigned short *) location));
+                break;
+            case 4:
+                MD5_UpdateInt32(context, *((unsigned int *) location));
+                break;
+            default:
+                I_Error("Unknown dehacked mapping field type for '%s' (BUG)", 
+                        entry->name);
+                break;
+        }
+    }
 }
 
--- a/src/deh_mapping.h
+++ b/src/deh_mapping.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_mapping.h 420 2006-03-15 18:53:06Z fraggle $
+// $Id: deh_mapping.h 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -45,6 +45,7 @@
 
 #include "doomtype.h"
 #include "deh_io.h"
+#include "md5.h"
 
 #define DEH_BEGIN_MAPPING(mapping_name, structname)           \
     static structname deh_mapping_base;                       \
@@ -96,6 +97,8 @@
 
 boolean DEH_SetMapping(deh_context_t *context, deh_mapping_t *mapping, 
                        void *structptr, char *name, int value);
+void DEH_StructMD5Sum(md5_context_t *context, deh_mapping_t *mapping,
+                      void *structptr);
 
 #endif /* #ifndef DEH_MAPPING_H */
 
--- a/src/deh_misc.c
+++ b/src/deh_misc.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_misc.c 641 2006-09-21 11:13:28Z rtc_marine $
+// $Id: deh_misc.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -253,6 +253,16 @@
     DEH_Warning(context, "Unknown Misc variable '%s'", variable_name);
 }
 
+static void DEH_MiscMD5Sum(md5_context_t *context)
+{
+    int i;
+
+    for (i=0; i<sizeof(misc_settings) / sizeof(*misc_settings); ++i)
+    {
+        MD5_UpdateInt32(context, *misc_settings[i].value);
+    }
+}
+
 deh_section_t deh_section_misc =
 {
     "Misc",
@@ -260,5 +270,6 @@
     DEH_MiscStart,
     DEH_MiscParseLine,
     NULL,
+    DEH_MiscMD5Sum,
 };
 
--- a/src/deh_ptr.c
+++ b/src/deh_ptr.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_ptr.c 175 2005-10-08 20:54:16Z fraggle $
+// $Id: deh_ptr.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -54,6 +54,21 @@
 
 static actionf_t codeptrs[NUMSTATES];
 
+static int CodePointerIndex(actionf_t *ptr)
+{
+    int i;
+
+    for (i=0; i<NUMSTATES; ++i)
+    {
+        if (!memcmp(&codeptrs[i], ptr, sizeof(actionf_t)))
+        {
+            return i;
+        }
+    }
+
+    return -1;
+}
+
 static void DEH_PointerInit(void)
 {
     int i;
@@ -131,6 +146,16 @@
     }
 }
 
+static void DEH_PointerMD5Sum(md5_context_t *context)
+{
+    int i;
+
+    for (i=0; i<NUMSTATES; ++i)
+    {
+        MD5_UpdateInt32(context, CodePointerIndex(&states[i].action));
+    }
+}
+
 deh_section_t deh_section_pointer =
 {
     "Pointer",
@@ -138,5 +163,6 @@
     DEH_PointerStart,
     DEH_PointerParseLine,
     NULL,
+    DEH_PointerMD5Sum,
 };
 
--- a/src/deh_sound.c
+++ b/src/deh_sound.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_sound.c 420 2006-03-15 18:53:06Z fraggle $
+// $Id: deh_sound.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -116,6 +116,7 @@
     NULL,
     DEH_SoundStart,
     DEH_SoundParseLine,
+    NULL,
     NULL,
 };
 
--- a/src/deh_text.c
+++ b/src/deh_text.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_text.c 580 2006-08-31 18:12:43Z fraggle $
+// $Id: deh_text.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -266,6 +266,7 @@
     DEH_TextInit,
     DEH_TextStart,
     DEH_TextParseLine,
+    NULL,
     NULL,
 };
 
--- a/src/deh_thing.c
+++ b/src/deh_thing.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_thing.c 188 2005-10-09 23:52:28Z fraggle $
+// $Id: deh_thing.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -139,6 +139,16 @@
     DEH_SetMapping(context, &thing_mapping, mobj, variable_name, ivalue);
 }
 
+static void DEH_ThingMD5Sum(md5_context_t *context)
+{
+    int i;
+
+    for (i=0; i<NUMMOBJTYPES; ++i)
+    {
+        DEH_StructMD5Sum(context, &thing_mapping, &mobjinfo[i]);
+    }
+}
+
 deh_section_t deh_section_thing =
 {
     "Thing",
@@ -146,5 +156,6 @@
     DEH_ThingStart,
     DEH_ThingParseLine,
     NULL,
+    DEH_ThingMD5Sum,
 };
 
--- a/src/deh_weapon.c
+++ b/src/deh_weapon.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: deh_weapon.c 175 2005-10-08 20:54:16Z fraggle $
+// $Id: deh_weapon.c 687 2006-10-05 22:12:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -108,6 +108,16 @@
     DEH_SetMapping(context, &weapon_mapping, weapon, variable_name, ivalue);
 }
 
+static void DEH_WeaponMD5Sum(md5_context_t *context)
+{
+    int i;
+
+    for (i=0; i<NUMWEAPONS ;++i)
+    {
+        DEH_StructMD5Sum(context, &weapon_mapping, &weaponinfo[i]);
+    }
+}
+
 deh_section_t deh_section_weapon =
 {
     "Weapon",
@@ -115,5 +125,6 @@
     DEH_WeaponStart,
     DEH_WeaponParseLine,
     NULL,
+    DEH_WeaponMD5Sum,
 };