From ee521c4d58898fa41ce24443a752fb710b58834b Mon Sep 17 00:00:00 2001 From: terminx Date: Mon, 24 Apr 2006 00:49:44 +0000 Subject: [PATCH] Dynamically allocate gamevar label space & add null pointer checks for quotes and gamevar labels git-svn-id: https://svn.eduke32.com/eduke32@102 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/duke3d.h | 2 +- polymer/eduke32/source/game.c | 43 +++++++---- polymer/eduke32/source/gamedef.c | 121 +++++++++++++++++++----------- polymer/eduke32/source/gameexec.c | 64 +++++++++++----- polymer/eduke32/source/menus.c | 4 +- polymer/eduke32/source/osdcmds.c | 7 +- 6 files changed, 154 insertions(+), 87 deletions(-) diff --git a/polymer/eduke32/source/duke3d.h b/polymer/eduke32/source/duke3d.h index c48c5de0c..c99ff5364 100644 --- a/polymer/eduke32/source/duke3d.h +++ b/polymer/eduke32/source/duke3d.h @@ -713,7 +713,7 @@ enum gamevarflags { typedef struct { long lValue; - char szLabel[MAXVARLABEL]; + char *szLabel; unsigned long dwFlags; long *plValues; // array of values when 'per-player', or 'per-actor' diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 11a9ef75a..c92cfbf51 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -44,7 +44,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "util_lib.h" -#define VERSION "" +#define VERSION " 1.4.0svn" #define HEAD "EDuke32"VERSION" (shareware mode)" #define HEAD2 "EDuke32"VERSION @@ -172,6 +172,9 @@ int txgametext_(int small, int starttile, int x,int y,char *t,char s,char p,shor newx = 0; oldt = t; + if(t == NULL) + return -1; + if(centre) { while(*t) @@ -2052,6 +2055,12 @@ void operatefta(void) k -= 4; } + if(fta_quotes[ps[screenpeek].ftq] == NULL) + { + OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,ps[screenpeek].ftq); + return; + } + j = ps[screenpeek].fta; if (j > 4) gametext(320>>1,k,fta_quotes[ps[screenpeek].ftq],0,2+8+16); @@ -2063,23 +2072,26 @@ void operatefta(void) void FTA(short q,struct player_struct *p) { - if( ud.fta_on == 1) + if(fta_quotes[p->ftq] != NULL) { - if( p->fta > 0 && q != 115 && q != 116 ) - if( p->ftq == 115 || p->ftq == 116 ) return; - - p->fta = 100; - - if( p->ftq != q || q == 26 ) - // || q == 26 || q == 115 || q ==116 || q == 117 || q == 122 ) + if( ud.fta_on == 1) { - p->ftq = q; - pub = NUMPAGES; - pus = NUMPAGES; - if (p == &ps[screenpeek]) - OSD_Printf("%s\n",fta_quotes[q]); + if( p->fta > 0 && q != 115 && q != 116 ) + if( p->ftq == 115 || p->ftq == 116 ) return; + + p->fta = 100; + + if( p->ftq != q || q == 26 ) + // || q == 26 || q == 115 || q ==116 || q == 117 || q == 122 ) + { + p->ftq = q; + pub = NUMPAGES; + pus = NUMPAGES; + if (p == &ps[screenpeek]) + OSD_Printf("%s\n",fta_quotes[q]); + } } - } + } else OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,p->ftq); } void showtwoscreens(void) @@ -7274,7 +7286,6 @@ FAKE_F3: Bstrcpy(fta_quotes[26],&music_fn[0][music_select][0]); Bstrcat(fta_quotes[26],". USE SHIFT-F5 TO CHANGE."); FTA(26,&ps[myconnectindex]); - } if(KB_KeyPressed( sc_F8 )) diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 783ae63c9..486029e9f 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -1050,13 +1050,14 @@ void ReadGameVars(long fil) for(i=0;i>1,y,fta_quotes[q],shade,pal,orientation,x1,y1,x2,y2); + if (tw == CON_MINITEXT && fta_quotes[q] != NULL) minitextshade(x,y,fta_quotes[q],shade,pal,26); + else if (tw == CON_GAMETEXT && fta_quotes[q] != NULL) txgametext(tilenum,x>>1,y,fta_quotes[q],shade,pal,orientation,x1,y1,x2,y2); else if (tw == CON_DIGITALNUMBER) txdigitalnumber(tilenum,x,y,q,shade,pal,orientation,x1,y1,x2,y2); + if((tw == CON_MINITEXT || tw == CON_GAMETEXT) && fta_quotes[q] == NULL) + OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,q); break; } @@ -5302,13 +5313,19 @@ SKIPJIBS: { long var1, var2, var3, var4; insptr++; - Bstrcpy(tempbuf,fta_quotes[*insptr++]); - var1 = GetGameVarID(*insptr++, g_i, g_p); - var2 = GetGameVarID(*insptr++, g_i, g_p); - var3 = GetGameVarID(*insptr++, g_i, g_p); - var4 = GetGameVarID(*insptr++, g_i, g_p); - Bsprintf(fta_quotes[122],tempbuf,var1,var2,var3,var4); - FTA(122,&ps[g_p]); + if(fta_quotes[*insptr] != NULL) + { + Bstrcpy(tempbuf,fta_quotes[*insptr++]); + var1 = GetGameVarID(*insptr++, g_i, g_p); + var2 = GetGameVarID(*insptr++, g_i, g_p); + var3 = GetGameVarID(*insptr++, g_i, g_p); + var4 = GetGameVarID(*insptr++, g_i, g_p); + Bsprintf(fta_quotes[122],tempbuf,var1,var2,var3,var4); + FTA(122,&ps[g_p]); + } else { + OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,*insptr); + insptr += 5; + } break; } @@ -6523,13 +6540,22 @@ good: case CON_QUOTE: insptr++; - FTA(*insptr++,&ps[g_p]); + if(fta_quotes[*insptr] != NULL) + FTA(*insptr++,&ps[g_p]); + else { + OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,*insptr); + insptr++; + } break; case CON_USERQUOTE: insptr++; - adduserquote(fta_quotes[*insptr]); - insptr++; + if(fta_quotes[*insptr] != NULL) + adduserquote(fta_quotes[*insptr++]); + else { + OSD_Printf("%s %d null quote %d\n",__FILE__,__LINE__,*insptr); + insptr++; + } break; case CON_IFINOUTERSPACE: diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 4e6b38371..e2bc18df9 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -2234,8 +2234,8 @@ cheat_for_port_credits: } enabled = 1; switch (io) { - case 0: if (x==io) ud.crosshair = 1-ud.crosshair; - modval(0,1,(int *)&ud.crosshair,1,probey==io); + case 0: if (x==io) ud.crosshair = (ud.crosshair==3)?0:ud.crosshair+1; + modval(0,3,(int *)&ud.crosshair,1,probey==io); gametextpal(d,yy, ud.crosshair ? "On" : "Off", MENUHIGHLIGHT(io), 0); break; case 1: if (x==io) ud.levelstats = 1-ud.levelstats; modval(0,1,(int *)&ud.levelstats,1,probey==io); diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index 60a5de8e5..5d90a93cb 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -359,10 +359,9 @@ int osdcmd_setvar(const osdfuncparm_t *parm) varval = Batol(parm->parms[1]); for(i=0;i