shithub: choc

Download patch

ref: d368801835fb910b5e642fa9d89ad7673f4bea27
parent: 9cc55c7f015836cfb7172d9be4c93b52597df8e1
parent: dba0583c05de16762c133c3198a9ef4e94c39253
author: Fabian Greffrath <fabian@greffrath.com>
date: Thu Nov 12 08:07:50 EST 2015

Merge pull request #640 from chocolate-doom/de-obfuscate

De-obfuscate some numerical constants found in the source code

--- a/src/doom/am_map.c
+++ b/src/doom/am_map.c
@@ -99,8 +99,8 @@
 #define M_ZOOMOUT       ((int) (FRACUNIT/1.02))
 
 // translates between frame-buffer and map distances
-#define FTOM(x) FixedMul(((x)<<16),scale_ftom)
-#define MTOF(x) (FixedMul((x),scale_mtof)>>16)
+#define FTOM(x) FixedMul(((x)<<FRACBITS),scale_ftom)
+#define MTOF(x) (FixedMul((x),scale_mtof)>>FRACBITS)
 // translates between frame-buffer and map coordinates
 #define CXMTOF(x)  (f_x + MTOF((x)-m_x))
 #define CYMTOF(y)  (f_y + (f_h - MTOF((y)-m_y)))
@@ -199,7 +199,7 @@
 
 boolean    	automapactive = false;
 static int 	finit_width = SCREENWIDTH;
-static int 	finit_height = SCREENHEIGHT - 32;
+static int 	finit_height = SCREENHEIGHT - ST_HEIGHT;
 
 // location of window on screen
 static int 	f_x;
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -217,12 +217,12 @@
 	    break;
 	if (automapactive)
 	    AM_Drawer ();
-	if (wipe || (viewheight != 200 && fullscreen) || disk_indicator == disk_dirty)
+	if (wipe || (viewheight != SCREENHEIGHT && fullscreen) || disk_indicator == disk_dirty)
 	    redrawsbar = true;
 	if (inhelpscreensstate && !inhelpscreens)
 	    redrawsbar = true;              // just put away the help screen
-	ST_Drawer (viewheight == 200, redrawsbar );
-	fullscreen = viewheight == 200;
+	ST_Drawer (viewheight == SCREENHEIGHT, redrawsbar );
+	fullscreen = viewheight == SCREENHEIGHT;
 	break;
 
       case GS_INTERMISSION:
@@ -260,7 +260,7 @@
     }
 
     // see if the border needs to be updated to the screen
-    if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != 320)
+    if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != SCREENWIDTH)
     {
 	if (menuactive || menuactivestate || !viewactivestate)
 	    borderdrawcount = 3;
--- a/src/doom/f_finale.c
+++ b/src/doom/f_finale.c
@@ -512,7 +512,7 @@
     }
     
     // draw it
-    cx = 160-width/2;
+    cx = SCREENWIDTH/2-width/2;
     ch = text;
     while (ch)
     {
@@ -559,9 +559,9 @@
 			
     patch = W_CacheLumpNum (lump+firstspritelump, PU_CACHE);
     if (flip)
-	V_DrawPatchFlipped(160, 170, patch);
+	V_DrawPatchFlipped(SCREENWIDTH/2, 170, patch);
     else
-	V_DrawPatch(160, 170, patch);
+	V_DrawPatch(SCREENWIDTH/2, 170, patch);
 }
 
 
@@ -618,18 +618,18 @@
 
     V_MarkRect (0, 0, SCREENWIDTH, SCREENHEIGHT);
 	
-    scrolled = (320 - ((signed int) finalecount-230)/2);
-    if (scrolled > 320)
-	scrolled = 320;
+    scrolled = (SCREENWIDTH - ((signed int) finalecount-230)/2);
+    if (scrolled > SCREENWIDTH)
+	scrolled = SCREENWIDTH;
     if (scrolled < 0)
 	scrolled = 0;
 		
     for ( x=0 ; x<SCREENWIDTH ; x++)
     {
-	if (x+scrolled < 320)
+	if (x+scrolled < SCREENWIDTH)
 	    F_DrawPatchCol (x, p1, x+scrolled);
 	else
-	    F_DrawPatchCol (x, p2, x+scrolled - 320);		
+	    F_DrawPatchCol (x, p2, x+scrolled - SCREENWIDTH);		
     }
 	
     if (finalecount < 1130)
--- a/src/doom/f_wipe.c
+++ b/src/doom/f_wipe.c
@@ -49,13 +49,13 @@
     int		y;
     short*	dest;
 
-    dest = (short*) Z_Malloc(width*height*2, PU_STATIC, 0);
+    dest = (short*) Z_Malloc(width*height*sizeof(*dest), PU_STATIC, 0);
 
     for(y=0;y<height;y++)
 	for(x=0;x<width;x++)
 	    dest[x*height+y] = array[y*width+x];
 
-    memcpy(array, dest, width*height*2);
+    memcpy(array, dest, width*height*sizeof(*dest));
 
     Z_Free(dest);
 
--- a/src/doom/m_menu.c
+++ b/src/doom/m_menu.c
@@ -1962,7 +1962,7 @@
     if (messageToPrint)
     {
 	start = 0;
-	y = 100 - M_StringHeight(messageString) / 2;
+	y = SCREENHEIGHT/2 - M_StringHeight(messageString) / 2;
 	while (messageString[start] != '\0')
 	{
 	    int foundnewline = 0;
@@ -1990,7 +1990,7 @@
                 start += strlen(string);
             }
 
-	    x = 160 - M_StringWidth(string) / 2;
+	    x = SCREENWIDTH/2 - M_StringWidth(string) / 2;
 	    M_WriteText(x, y, string);
 	    y += SHORT(hu_font[0]->height);
 	}
--- a/src/doom/p_enemy.c
+++ b/src/doom/p_enemy.c
@@ -212,7 +212,7 @@
     if (!actor->info->meleestate)
 	dist -= 128*FRACUNIT;	// no melee attack, so fire more
 
-    dist >>= 16;
+    dist >>= FRACBITS;
 
     if (actor->type == MT_VILE)
     {
--- a/src/doom/p_map.c
+++ b/src/doom/p_map.c
@@ -1083,8 +1083,8 @@
     shootz = t1->z + (t1->height>>1) + 8*FRACUNIT;
 
     // can't shoot outside view angles
-    topslope = 100*FRACUNIT/160;	
-    bottomslope = -100*FRACUNIT/160;
+    topslope = (SCREENHEIGHT/2)*FRACUNIT/(SCREENWIDTH/2);	
+    bottomslope = -(SCREENHEIGHT/2)*FRACUNIT/(SCREENWIDTH/2);
     
     attackrange = distance;
     linetarget = NULL;
--- a/src/doom/p_pspr.c
+++ b/src/doom/p_pspr.c
@@ -726,7 +726,7 @@
     {
 	damage = 5*(P_Random ()%3+1);
 	angle = player->mo->angle;
-	angle += (P_Random()-P_Random())<<19;
+	angle += (P_Random()-P_Random())<<ANGLETOFINESHIFT;
 	P_LineAttack (player->mo,
 		      angle,
 		      MISSILERANGE,
--- a/src/doom/p_setup.c
+++ b/src/doom/p_setup.c
@@ -192,8 +192,8 @@
 	li->v1 = &vertexes[SHORT(ml->v1)];
 	li->v2 = &vertexes[SHORT(ml->v2)];
 
-	li->angle = (SHORT(ml->angle))<<16;
-	li->offset = (SHORT(ml->offset))<<16;
+	li->angle = (SHORT(ml->angle))<<FRACBITS;
+	li->offset = (SHORT(ml->offset))<<FRACBITS;
 	linedef = SHORT(ml->linedef);
 	ldef = &lines[linedef];
 	li->linedef = ldef;
--- a/src/doom/p_user.c
+++ b/src/doom/p_user.c
@@ -144,7 +144,7 @@
 	
     cmd = &player->cmd;
 	
-    player->mo->angle += (cmd->angleturn<<16);
+    player->mo->angle += (cmd->angleturn<<FRACBITS);
 
     // Do not let the player control movement
     //  if not onground.
--- a/src/doom/r_main.c
+++ b/src/doom/r_main.c
@@ -482,7 +482,7 @@
     num = FixedMul(projection,sineb)<<detailshift;
     den = FixedMul(rw_distance,sinea);
 
-    if (den > num>>16)
+    if (den > num>>FRACBITS)
     {
 	scale = FixedDiv (num, den);
 
@@ -841,7 +841,7 @@
     {
 	fixedcolormap =
 	    colormaps
-	    + player->fixedcolormap*256*sizeof(lighttable_t);
+	    + player->fixedcolormap*256;
 	
 	walllights = scalelightfixed;
 
--- a/src/doom/r_segs.c
+++ b/src/doom/r_segs.c
@@ -715,7 +715,7 @@
     if ( ((ds_p->silhouette & SIL_TOP) || maskedtexture)
 	 && !ds_p->sprtopclip)
     {
-	memcpy (lastopening, ceilingclip+start, 2*(rw_stopx-start));
+	memcpy (lastopening, ceilingclip+start, sizeof(*lastopening)*(rw_stopx-start));
 	ds_p->sprtopclip = lastopening - start;
 	lastopening += rw_stopx - start;
     }
@@ -723,7 +723,7 @@
     if ( ((ds_p->silhouette & SIL_BOTTOM) || maskedtexture)
 	 && !ds_p->sprbottomclip)
     {
-	memcpy (lastopening, floorclip+start, 2*(rw_stopx-start));
+	memcpy (lastopening, floorclip+start, sizeof(*lastopening)*(rw_stopx-start));
 	ds_p->sprbottomclip = lastopening - start;
 	lastopening += rw_stopx - start;	
     }
--- a/src/doom/r_sky.c
+++ b/src/doom/r_sky.c
@@ -47,6 +47,6 @@
 void R_InitSkyMap (void)
 {
   // skyflatnum = R_FlatNumForName ( SKYFLATNAME );
-    skytexturemid = 100*FRACUNIT;
+    skytexturemid = SCREENHEIGHT/2*FRACUNIT;
 }
 
--- a/src/doom/r_things.c
+++ b/src/doom/r_things.c
@@ -38,7 +38,7 @@
 
 
 #define MINZ				(FRACUNIT*4)
-#define BASEYCENTER			100
+#define BASEYCENTER			(SCREENHEIGHT/2)
 
 //void R_DrawColumn (void);
 //void R_DrawFuzzColumn (void);
@@ -665,7 +665,7 @@
     flip = (boolean)sprframe->flip[0];
     
     // calculate edges of the shape
-    tx = psp->sx-160*FRACUNIT;
+    tx = psp->sx-(SCREENWIDTH/2)*FRACUNIT;
 	
     tx -= spriteoffset[lump];	
     x1 = (centerxfrac + FixedMul (tx,pspritescale) ) >>FRACBITS;
--- a/src/m_fixed.c
+++ b/src/m_fixed.c
@@ -54,7 +54,7 @@
     {
 	int64_t result;
 
-	result = ((int64_t) a << 16) / b;
+	result = ((int64_t) a << FRACBITS) / b;
 
 	return (fixed_t) result;
     }