shithub: choc

Download patch

ref: 63903f9aac430d321a3063fbc79d61ccae6db22e
parent: 4c4a67ef7ad1b53d5b13e37e2ff3744320a0f1ac
author: James Haley <haleyjd@hotmail.com>
date: Sun Feb 13 21:21:42 EST 2011

Fix to HUlib_drawYellowText (more Hex-Rays code-skipping shenanigans),
and finished ST_drawKeysPopup for drawing keys (TODO: in deathmatch it
draws frags instead). Fix to buffer overflow in V_ScreenShot - *ATTN
fraggle* - needs fix in trunk!

Subversion-branch: /branches/strife-branch
Subversion-revision: 2265

--- a/src/strife/hu_lib.c
+++ b/src/strife/hu_lib.c
@@ -47,7 +47,7 @@
 //
 // HUlib_drawYellowText
 //
-// haleyjd 09/18/10: [STRIFE] New function.
+// haleyjd 20100918: [STRIFE] New function.
 //
 void HUlib_drawYellowText(int x, int y, char *text)
 {
@@ -61,36 +61,42 @@
         {
             x = start_x;
             y += 12;
+            continue;
         }
-        else if(c == '_' || c != ' ' || x != start_x)
+
+        // haleyjd 20110213: found MORE code ignored/misinterpreted by Hex-Rays:
+        // Underscores are replaced by spaces.
+        if(c == '_')
+            c = ' ';
+        else if (c == ' ' && x == start_x) // skip spaces at the start of a line
+            continue;
+
+        c = toupper(c) - HU_FONTSTART;
+
+        if(c >= 0 && c < HU_FONTSIZE)
         {
-            c = toupper(c) - HU_FONTSTART;
+            patch_t *patch = yfont[(int) c];
+            int      width = SHORT(patch->width);
 
-            if(c >= 0 && c < HU_FONTSIZE)
+            if(x + width <= (SCREENWIDTH - 20))
             {
-                patch_t *patch = yfont[(int) c];
-                int      width = SHORT(patch->width);
-
-                if(x + width <= (SCREENWIDTH - 20))
-                {
-                    // haleyjd: STRIFE-TODO: bit different than the exe... for now
-                    if(!D_PatchClipCallback(patch, x + SHORT(patch->leftoffset),
-                                                   y + SHORT(patch->topoffset)))
-                        return;
-                    V_DrawPatchDirect(x, y, patch);
-                    x = x + width;
-                }
-                else
-                {
-                    x = start_x;
-                    --rover;
-                    y += 12;
-                }
+                // haleyjd: STRIFE-TODO: bit different than the exe... for now
+                if(!D_PatchClipCallback(patch, x + SHORT(patch->leftoffset),
+                    y + SHORT(patch->topoffset)))
+                    return;
+                V_DrawPatchDirect(x, y, patch);
+                x = x + width;
             }
             else
             {
-                x += 4;
+                x = start_x;
+                --rover;
+                y += 12;
             }
+        }
+        else
+        {
+            x += 4;
         }
     }
 }
--- a/src/strife/st_stuff.c
+++ b/src/strife/st_stuff.c
@@ -76,7 +76,6 @@
 // STATUS BAR DATA
 //
 
-
 // Palette indices.
 // For damage/bonus red-/gold-shifts
 #define STARTREDPALS            1
@@ -109,36 +108,13 @@
 #define ST_HEALTHX              79
 #define ST_HEALTHY              162
 
-// Weapon pos.
-#define ST_ARMSX		111
-#define ST_ARMSY		172
-#define ST_ARMSBGX		104
-#define ST_ARMSBGY		168
-#define ST_ARMSXSPACE		12
-#define ST_ARMSYSPACE		10
+// [STRIFE]
+// Removed:
+// * Weapon pos.
+// * Frags pos.
+// * ARMOR number pos.
+// * Key icon positions.
 
-// Frags pos.
-#define ST_FRAGSX			138
-#define ST_FRAGSY			171	
-#define ST_FRAGSWIDTH		2
-
-// ARMOR number pos.
-#define ST_ARMORWIDTH		3
-#define ST_ARMORX			221
-#define ST_ARMORY			171
-
-// Key icon positions.
-#define ST_KEY0WIDTH		8
-#define ST_KEY0HEIGHT		5
-#define ST_KEY0X			239
-#define ST_KEY0Y			171
-#define ST_KEY1WIDTH		ST_KEY0WIDTH
-#define ST_KEY1X			239
-#define ST_KEY1Y			181
-#define ST_KEY2WIDTH		ST_KEY0WIDTH
-#define ST_KEY2X			239
-#define ST_KEY2Y			191
-
 // Ammunition counter.
 // haleyjd 20110213 [STRIFE]: ammo counters for the popup widget
 #define ST_POPUPAMMOX       206
@@ -148,42 +124,15 @@
 // Indicate maximum ammunition.
 // Only needed because backpack exists.
 // haleyjd 20110213 [STRIFE]: maxammo counters for the popup widget
-#define ST_POPUPMAXAMMOX    239
+#define ST_POPUPMAXAMMOX        239
 
-// pistol
-#define ST_WEAPON0X			110 
-#define ST_WEAPON0Y			172
+// [STRIFE]
+// Removed:
+// * Doom weapon stuff
+// * DETH title (???)
 
-// shotgun
-#define ST_WEAPON1X			122 
-#define ST_WEAPON1Y			172
-
-// chain gun
-#define ST_WEAPON2X			134 
-#define ST_WEAPON2Y			172
-
-// missile launcher
-#define ST_WEAPON3X			110 
-#define ST_WEAPON3Y			181
-
-// plasma gun
-#define ST_WEAPON4X			122 
-#define ST_WEAPON4Y			181
-
- // bfg
-#define ST_WEAPON5X			134
-#define ST_WEAPON5Y			181
-
-// WPNS title
-#define ST_WPNSX			109 
-#define ST_WPNSY			191
-
- // DETH title
-#define ST_DETHX			109
-#define ST_DETHY			191
-
 // Dimensions given in characters.
-#define ST_MSGWIDTH			52
+#define ST_MSGWIDTH             52
 
 // haleyjd 08/31/10: [STRIFE] 
 // * Removed faces.
@@ -332,7 +281,7 @@
 void ST_Stop(void);
 
 // [STRIFE]
-static char st_msgbuf[52];
+static char st_msgbuf[ST_MSGWIDTH];
 
 // Respond to keyboard input events,
 //  intercept cheats.
@@ -1212,7 +1161,106 @@
     HUlib_drawYellowText(x, y, string);
 }
 
+#define ST_KEYSPERPAGE   10
+#define ST_KEYS_X        20
+#define ST_KEYS_Y        63
+#define ST_KEYNAME_X     17
+#define ST_KEYNAME_Y      4
+#define ST_KEYS_YSTEP    17
+#define ST_KEYS_NUMROWS   4
+#define ST_KEYS_COL2X   160
+
 //
+// ST_drawKeysPopup
+//
+// haleyjd 20110213: [STRIFE] New function
+// This has taken the longest out of almost everything to get working properly.
+//
+static boolean ST_drawKeysPopup(void)
+{
+    int x, y, key, keycount;
+    mobjinfo_t *info;
+
+    V_DrawXlaPatch(0, 56, invpbak2);
+    V_DrawPatchDirect(0, 56, invpop2);
+
+    if(deathmatch)
+    {
+        // STRIFE-TODO: In deathmatch, the keys popup is replaced by a chart
+        // of frag counts
+    }
+    else
+    {
+        // Bounds-check page number
+        if(st_keypage < 0 || st_keypage > 2)
+        {
+            st_keypage = -1;
+            st_popupdisplaytics = 0;
+            st_displaypopup = false;
+
+            return false;
+        }
+
+        // Are there any keys to display on this page?
+        if(st_keypage > 0)
+        {
+            boolean haskeyinrange = false;
+
+            for(key = ST_KEYSPERPAGE * st_keypage, keycount = 0;
+                keycount < ST_KEYSPERPAGE && key < NUMCARDS;
+                ++key, ++keycount)
+            {
+                if(plyr->cards[key])
+                    haskeyinrange = true;
+            }
+
+            if(!haskeyinrange)
+            {
+                st_displaypopup = false;
+                st_showkeys = false;
+                st_keypage = -1;
+                
+                return false;
+            }
+        }
+
+        // Draw the keys for the current page
+        key = ST_KEYSPERPAGE * st_keypage;
+        keycount = 0;
+        x = ST_KEYS_X;
+        y = ST_KEYS_Y;
+        info = &mobjinfo[MT_KEY_BASE + key];
+
+        for(; keycount < ST_KEYSPERPAGE && key < NUMCARDS; ++key, ++keycount, ++info)
+        {
+            char sprname[8];
+            patch_t *patch;
+            memset(sprname, 0, sizeof(sprname));
+
+            if(plyr->cards[key])
+            {
+                // Get spawnstate sprite name and load corresponding icon
+                DEH_snprintf(sprname, sizeof(sprname), "I_%s",
+                    sprnames[states[info->spawnstate].sprite]);
+                patch = W_CacheLumpName(sprname, PU_CACHE);
+                V_DrawPatchDirect(x, y, patch);
+                HUlib_drawYellowText(x + ST_KEYNAME_X, y + ST_KEYNAME_Y, info->name);
+            }
+
+            if(keycount != ST_KEYS_NUMROWS)
+                y += ST_KEYS_YSTEP;
+            else
+            {
+                x = ST_KEYS_COL2X;
+                y = ST_KEYS_Y;
+            }
+        }
+    }
+
+    return true;
+}
+
+//
 // ST_DrawExternal
 //
 // haleyjd 09/01/10: [STRIFE] New function.
@@ -1254,10 +1302,9 @@
     {
         int keys = 0;
 
-        // villsa [STRIFE] TODO
+        // villsa [STRIFE] keys popup
         if(st_showkeys || st_popupdisplaytics)
-            return true; // temp
-            //return ST_drawKeysPopup();
+            return ST_drawKeysPopup();
 
         V_DrawXlaPatch(0, 56, invpbak);
         V_DrawPatchDirect(0, 56, invpop);
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -653,7 +653,7 @@
 void V_ScreenShot(char *format)
 {
     int i;
-    char lbmname[12];
+    char lbmname[16]; // haleyjd 20110213: BUG FIX - 12 is too small!
     
     // find a file name to save it to