shithub: hexen

Download patch

ref: 1b98111171fd71c64c849e1be30ecb8cf9ca76d8
parent: a8de7d9027b678cdc44da8ef85a121c70e6b8c5c
author: Jacob Moody <[email protected]>
date: Sat Feb 4 20:15:24 EST 2023

maybe DOS save compatability?

the _very_ hacky COMPILE_TIME_ASSERT
does indeed work, might as well use it
and it did find some issues. With those
working we can actually ensure our structs
are the right size for saves, which _maybe_
makes us compatible with DOS.

--- a/h2def.h
+++ b/h2def.h
@@ -11,8 +11,6 @@
 #ifndef __H2DEF__
 #define __H2DEF__
 
-#pragma pack on
-
 /* if rangecheck is undefined, most parameter
  * validation debugging code will not be compiled
  */
@@ -288,6 +286,8 @@
 #define	ANG270		0xc0000000
 
 typedef unsigned angle_t;
+
+#pragma pack on
 
 typedef enum
 {
--- a/p_spec.h
+++ b/p_spec.h
@@ -81,7 +81,6 @@
 
 #pragma pack on
 
-
 /* ---- P_LIGHTS ---- */
 
 typedef enum
@@ -465,7 +464,6 @@
 
 typedef struct acs_s acs_t;
 typedef struct acsInfo_s acsInfo_t;
-
 
 struct acsInfo_s
 {
--- a/sv_save.h
+++ b/sv_save.h
@@ -66,10 +66,7 @@
 	byte			special;
 	byte			args[5];
 } save_mobj_t;
-#if !(defined(VERSION10_WAD) || defined(_DOSSAVE_COMPAT))
-/* make sure the struct is of 176 bytes size, so that all our
-   saved games are uniform. */
-#endif
+COMPILE_TIME_ASSERT(save_mobj_t, sizeof(save_mobj_t) == 176);
 
 typedef struct
 {
@@ -78,6 +75,8 @@
 	ticcmd_t	cmd;	/* note: sizeof(ticcmd_t) is
 				   10, not 4 byte aligned. */
 
+	char _pad[2];
+
 	int		playerclass;			/* pclass_t	playerclass */
 
 	fixed_t		viewz;
@@ -125,12 +124,9 @@
 	unsigned int	jumpTics;
 	unsigned int	worldTimer;
 } save_player_t;
-#if !(defined(VERSION10_WAD) || defined(_DOSSAVE_COMPAT))
-/* make sure the struct is of 648 bytes size, so that all our saved
-   games are uniform: Raven's DOS versions seem to have this struct
-   packed, with sizeof(player_t) == 646 and offsetof playerclass at
-   18 instead of 20. */
-#endif
+COMPILE_TIME_ASSERT(ticcmd_double_check, sizeof(ticcmd_t) == 10);
+COMPILE_TIME_ASSERT(save_player_1, sizeof(save_player_t) == 648);
+COMPILE_TIME_ASSERT(save_player_2, offsetof(save_player_t,playerclass) == 20);
 
 typedef struct
 {
@@ -141,6 +137,7 @@
 	int		direction;
 	int		newspecial;
 	short		texture;		/*  */
+	char		_pad[2];
 	fixed_t		floordestheight;
 	fixed_t		speed;
 	int		delayCount;
@@ -151,11 +148,10 @@
 	short		resetDelay;
 	short		resetDelayCount;
 	byte		textureChange;		/*  */
+	char 		_pad2[3];
 } save_floormove_t;
-#if !(defined(VERSION10_WAD) || defined(_DOSSAVE_COMPAT))
-/* make sure the struct is of 72 bytes size, so that all our saved
-   games are uniform. */
-#endif
+COMPILE_TIME_ASSERT(save_floormove_1, sizeof(save_floormove_t) == 72);
+COMPILE_TIME_ASSERT(save_floormove_2, offsetof(save_floormove_t,floordestheight) == 36);
 
 typedef struct
 {
--- a/xddefs.h
+++ b/xddefs.h
@@ -40,6 +40,7 @@
 	short		x;
 	short		y;
 } mapvertex_t;
+COMPILE_TIME_ASSERT(mapvertex_t, sizeof(mapvertex_t) == 4);
 
 typedef struct
 {
@@ -50,6 +51,7 @@
 	char		midtexture[8];
 	short		sector;	/* on viewer's side */
 } mapsidedef_t;
+COMPILE_TIME_ASSERT(mapsidedef_t, sizeof(mapsidedef_t) == 30);
 
 typedef struct
 {
@@ -64,6 +66,7 @@
 	byte		arg5;
 	short		sidenum[2];	/* sidenum[1] will be -1 if one sided */
 } maplinedef_t;
+COMPILE_TIME_ASSERT(maplinedef_t, sizeof(maplinedef_t) == 16);
 
 #define	ML_BLOCKING		0x0001
 #define	ML_BLOCKMONSTERS	0x0002
@@ -97,6 +100,7 @@
 	short		special;
 	short		tag;
 } mapsector_t;
+COMPILE_TIME_ASSERT(mapsector_t, sizeof(mapsector_t) == 26);
 
 typedef struct
 {
@@ -103,6 +107,7 @@
 	short		numsegs;
 	short		firstseg;	/* segs are stored sequentially */
 } mapsubsector_t;
+COMPILE_TIME_ASSERT(mapsubsector_t, sizeof(mapsubsector_t) == 4);
 
 typedef struct
 {
@@ -113,6 +118,7 @@
 	short		side;
 	short		offset;
 } mapseg_t;
+COMPILE_TIME_ASSERT(mapseg_t, sizeof(mapseg_t) == 12);
 
 /* bbox coordinates */
 enum
@@ -130,6 +136,7 @@
 	short		bbox[2][4];	/* bounding box for each child */
 	unsigned short	children[2];	/* if NF_SUBSECTOR its a subsector */
 } mapnode_t;
+COMPILE_TIME_ASSERT(mapnode_t, sizeof(mapnode_t) == 28);
 
 typedef struct
 {
@@ -147,6 +154,7 @@
 	byte		arg4;
 	byte		arg5;
 } mapthing_t;
+COMPILE_TIME_ASSERT(mapthing_t, sizeof(mapthing_t) == 20);
 
 #define MTF_EASY		1
 #define MTF_NORMAL		2
@@ -171,6 +179,7 @@
 	short		stepdir;
 	short		colormap;
 } mappatch_t;
+COMPILE_TIME_ASSERT(mappatch_t, sizeof(mappatch_t) == 10);
 
 typedef struct
 {
@@ -182,8 +191,8 @@
 	short		patchcount;
 	mappatch_t	patches[1];
 } maptexture_t;
+COMPILE_TIME_ASSERT(maptexture_t, sizeof(maptexture_t) == 32);
 
-
 /* ---- Graphics ---- */
 
 /* posts are runs of non masked source pixels */
@@ -193,6 +202,7 @@
 	byte		length;
 	/* length data bytes follows */
 } post_t;
+COMPILE_TIME_ASSERT(post_t, sizeof(post_t) == 2);
 
 /* column_t is a list of 0 or more post_t, (byte)-1 terminated */
 typedef post_t	column_t;
@@ -209,6 +219,7 @@
 	int		columnofs[8];		/* only [width] used */
 							/* the [0] is &columnofs[width] */
 } patch_t;
+COMPILE_TIME_ASSERT(patch_t, sizeof(patch_t) == 40);
 
 #pragma pack off