From a55cc4479abcec6d8019dfb34c4b1a0610c1682c Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 10 Aug 2008 13:07:07 +0000 Subject: [PATCH] git-svn-id: https://svn.eduke32.com/eduke32@961 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/eduke32.vcproj | 8 -- polymer/eduke32/source/gameexec.c | 84 ++++++++++-------- polymer/eduke32/source/gamevars.c | 140 ++++++++++++++---------------- 3 files changed, 114 insertions(+), 118 deletions(-) diff --git a/polymer/eduke32/eduke32.vcproj b/polymer/eduke32/eduke32.vcproj index 2d53bf9b1..fde883174 100644 --- a/polymer/eduke32/eduke32.vcproj +++ b/polymer/eduke32/eduke32.vcproj @@ -573,10 +573,6 @@ RelativePath=".\source\config.h" > - - @@ -825,10 +821,6 @@ RelativePath=".\source\jmact\control.h" > - - diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 5e958a331..0f4ceaee7 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -5596,19 +5596,13 @@ static int parse(void) { int distvar = *insptr++, xvar = GetGameVarID(*insptr++, g_i, g_p), yvar = GetGameVarID(*insptr++, g_i, g_p), distx=0; - if (xvar > -1 && xvar < MAXSPRITES && yvar > -1 && yvar < MAXSPRITES) + if (xvar < 0 || yvar < 0 || xvar >= MAXSPRITES || yvar >= MAXSPRITES) { - switch (tw) - { - case CON_DIST: - distx = dist(&sprite[xvar],&sprite[yvar]); - break; - case CON_LDIST: - distx = ldist(&sprite[xvar],&sprite[yvar]); - break; - } + OSD_Printf(CON_ERROR "CON_DIST/CON_LDIST: invalid sprite\n",line_num); + break; } - else OSD_Printf(CON_ERROR "CON_DIST/CON_LDIST: invalid sprite\n",line_num); + if (tw == CON_DIST) distx = dist(&sprite[xvar],&sprite[yvar]); + else distx = ldist(&sprite[xvar],&sprite[yvar]); SetGameVarID(distvar, distx, g_i, g_p); break; @@ -5644,12 +5638,11 @@ static int parse(void) case CON_INITTIMER: insptr++; j = GetGameVarID(*insptr++, g_i, g_p); - if (timer != j) - { - uninittimer(); - inittimer(j); - timer = j; - } + if (timer == j) + break; + uninittimer(); + inittimer(j); + timer = j; break; case CON_TIME: @@ -5662,9 +5655,12 @@ static int parse(void) insptr++; { int lIn=GetGameVarID(*insptr++, g_i, g_p); - j = -1; - if (g_sp->sectnum >= 0 && g_sp->sectnum < MAXSECTORS) - j = spawn(g_i, lIn); + if (g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS) + { + OSD_Printf(CON_ERROR "CON_E/Q/EQSPAWNVAR: Invalid sector %d\n",line_num,g_sp->sectnum); + break; + } + j = spawn(g_i, lIn); switch (tw) { case CON_EQSPAWNVAR: @@ -5686,11 +5682,14 @@ static int parse(void) case CON_QSPAWN: insptr++; - j=-1; + if (g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS) + { + OSD_Printf(CON_ERROR "CON_E/Q/EQSPAWN: Invalid sector %d\n",line_num,g_sp->sectnum); + insptr++; + break; + } - if (g_sp->sectnum >= 0 && g_sp->sectnum < MAXSECTORS) - j = spawn(g_i,*insptr++); - else insptr++; + j = spawn(g_i,*insptr++); switch (tw) { @@ -5718,13 +5717,19 @@ static int parse(void) if (hittype[g_i].temp_data[9] == 0) hittype[g_i].temp_data[9] = 1; } - if (g_sp->sectnum >= 0 && g_sp->sectnum < MAXSECTORS) + + if (g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS) { - if (tw == CON_EZSHOOT || tw == CON_ESHOOT) - SetGameVarID(g_iReturnVarID, shoot(g_i,*insptr++), g_i, g_p); - else shoot(g_i,*insptr++); + OSD_Printf(CON_ERROR "CON_E/Z/EZSHOOT: Invalid sector %d\n",line_num,g_sp->sectnum); + insptr++; + hittype[g_i].temp_data[9]=0; + break; } - else insptr++; + + j = shoot(g_i,*insptr++); + + if (tw == CON_EZSHOOT || tw == CON_ESHOOT) + SetGameVarID(g_iReturnVarID, j, g_i, g_p); hittype[g_i].temp_data[9]=0; break; @@ -5745,12 +5750,17 @@ static int parse(void) hittype[g_i].temp_data[9] = 1; } j=GetGameVarID(*insptr++, g_i, g_p); - if (g_sp->sectnum >= 0 && g_sp->sectnum < MAXSECTORS) + + if (g_sp->sectnum < 0 || g_sp->sectnum >= MAXSECTORS) { - lReturn = shoot(g_i, j); - if (tw == CON_ESHOOTVAR || tw == CON_EZSHOOTVAR) - SetGameVarID(g_iReturnVarID, lReturn, g_i, g_p); + OSD_Printf(CON_ERROR "CON_E/Z/EZ/SHOOTVAR: Invalid sector %d\n",line_num,g_sp->sectnum); + hittype[g_i].temp_data[9]=0; + break; } + + lReturn = shoot(g_i, j); + if (tw == CON_ESHOOTVAR || tw == CON_EZSHOOTVAR) + SetGameVarID(g_iReturnVarID, lReturn, g_i, g_p); hittype[g_i].temp_data[9]=0; break; } @@ -5846,7 +5856,7 @@ static int parse(void) if (x1 < 0 || y1 < 0 || x2 > xdim-1 || y2 > ydim-1 || x2-x1 < 2 || y2-y1 < 2) { - OSD_Printf(CON_ERROR "CON_SHOWVIEW: incorrect coordiantes\n",line_num); + OSD_Printf(CON_ERROR "CON_SHOWVIEW: incorrect coordinates\n",line_num); break; } if (sect<0 || sect>=numsectors) @@ -5873,7 +5883,7 @@ static int parse(void) se40code(x,y,z,a,horiz,smoothratio); #endif if (((gotpic[MIRROR>>3]&(1<<(MIRROR&7))) > 0) -#if defined(POLYMOST) && defined(USE_OPENGL) +#if defined(POLYMER) && defined(USE_OPENGL) && (getrendermode() != 4) #endif ) @@ -6725,7 +6735,7 @@ static int parse(void) if (lVarID&(MAXGAMEVARS<<1)) { - m = -1; + m = -m; lVarID ^= (MAXGAMEVARS<<1); } @@ -6746,7 +6756,7 @@ static int parse(void) } else if (*insptr&(MAXGAMEVARS<<1)) { - m = -1; + m = -m; lVarID ^= (MAXGAMEVARS<<1); } else diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index b1ce34aed..675f31381 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -33,41 +33,33 @@ extern void FreeMapState(int mapnum); static void FreeGameVars(void) /* called from ReadGameVars() and ResetGameVars() */ { // call this function as many times as needed. - int i; + int i=(MAXGAMEVARS-1); // AddLog("FreeGameVars"); - for (i=0;i=0;i--) { -// aGameVars[i].lValue=0; -// if (aGameVars[i].szLabel) - //Bfree(aGameVars[i].szLabel); -// aGameVars[i].szLabel=NULL; -// aGameVars[i].dwFlags=0; - if (aGameVars[i].plValues) Bfree(aGameVars[i].plValues); aGameVars[i].plValues=NULL; aGameVars[i].bReset=1; - } - iGameVarCount=0; - for (i=0;i= MAXGAMEARRAYS) + continue; if (aGameArrays[i].plValues) Bfree(aGameArrays[i].plValues); aGameArrays[i].plValues=NULL; aGameArrays[i].bReset=1; } - iGameArrayCount=0; + iGameVarCount=iGameArrayCount=0; return; } static void ClearGameVars(void) { // only call this function ONCE... - int i; + int i=(MAXGAMEVARS-1); //AddLog("ClearGameVars"); - for (i=0;i=0;i--) { aGameVars[i].lValue=0; if (aGameVars[i].szLabel) @@ -79,10 +71,8 @@ static void ClearGameVars(void) Bfree(aGameVars[i].plValues); aGameVars[i].plValues=NULL; aGameVars[i].bReset=1; - } - iGameVarCount=0; - for (i=0;i= MAXGAMEARRAYS) + continue; if (aGameArrays[i].szLabel) Bfree(aGameArrays[i].szLabel); aGameArrays[i].szLabel=NULL; @@ -92,7 +82,7 @@ static void ClearGameVars(void) aGameArrays[i].plValues=NULL; aGameArrays[i].bReset=1; } - iGameArrayCount=0; + iGameVarCount=iGameArrayCount=0; return; } @@ -564,9 +554,9 @@ int AddGameVar(const char *pszLabel, int lValue, unsigned int dwFlags) void ResetActorGameVars(int iActor) { - int i; + int i=(MAXGAMEVARS-1); // OSD_Printf("resetting vars for actor %d\n",iActor); - for (i=0;i=0;i--) if ((aGameVars[i].dwFlags & GAMEVAR_FLAG_PERACTOR) && !(aGameVars[i].dwFlags & GAMEVAR_FLAG_NODEFAULT)) { // OSD_Printf("reset %s (%d) to %s (%d)\n",aGameVars[i].szLabel,aGameVars[i].plValues[iActor],aDefaultGameVars[i].szLabel,aDefaultGameVars[i].lValue); @@ -593,77 +583,81 @@ static int GetGameID(const char *szGameLabel) int GetGameVarID(int id, int iActor, int iPlayer) { - int m = 1; - if (id == MAXGAMEVARS) return(*insptr++); if (id == g_iThisActorID) return iActor; - if (id >= iGameVarCount || id<0) { - if (id&(MAXGAMEVARS<<2)) + int m = 1; + + if (id >= iGameVarCount || id<0) { - int index=GetGameVarID(*insptr++,iActor,iPlayer); - - id &= ~(MAXGAMEVARS<<2); - - if (id&(MAXGAMEVARS<<1)) // negative array access + if (id&(MAXGAMEVARS<<2)) { - m = -1; - id &= ~(MAXGAMEVARS<<1); + int index=GetGameVarID(*insptr++,iActor,iPlayer); + + id &= ~(MAXGAMEVARS<<2); + + if (id&(MAXGAMEVARS<<1)) // negative array access + { + m = -m; + id &= ~(MAXGAMEVARS<<1); + } + + // OSD_Printf("GetGameVarID(): reading from array\n"); + if (index >= aGameArrays[id].size || index < 0) + { + OSD_Printf(OSD_ERROR "GetGameVarID(): invalid array index (%s[%d])\n",aGameArrays[id].szLabel,index); + return -1; + } + return(m * aGameArrays[id].plValues[index]); } -// OSD_Printf("GetGameVarID(): reading from array\n"); - if ((index < aGameArrays[id].size)&&(index>=0)) - return(m * aGameArrays[id].plValues[index]); - OSD_Printf(OSD_ERROR "GetGameVarID(): invalid array index (%s[%d])\n",aGameArrays[id].szLabel,index); - return -1; + if ((id&(MAXGAMEVARS<<1)) == 0) + { + OSD_Printf(OSD_ERROR "GetGameVarID(): invalid gamevar ID (%d)\n",id); + return -1; + } + + m = -m; + id &= ~(MAXGAMEVARS<<1); } - if (!(id&(MAXGAMEVARS<<1))) + if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PERPLAYER) { - OSD_Printf(OSD_ERROR "GetGameVarID(): invalid gamevar ID (%d)\n",id); - return -1; - } - - m = -1; - id &= ~(MAXGAMEVARS<<1); - } - - if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PERPLAYER) - { - // for the current player - if (iPlayer >= 0 && iPlayer < MAXPLAYERS) - { - //Bsprintf(g_szBuf,"GetGameVarID(%d, %d, %d) returns %d\n",id,iActor,iPlayer, aGameVars[id].plValues[iPlayer]); - //AddLog(g_szBuf); + // for the current player + if (iPlayer < 0 || iPlayer >= MAXPLAYERS) + { + OSD_Printf(OSD_ERROR "GetGameVarID(): invalid player ID (%d)\n",iPlayer); + return -1; + } return(m * aGameVars[id].plValues[iPlayer]); } - return(m * aGameVars[id].lValue); - } - - if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PERACTOR) - { - // for the current actor - if (iActor >= 0 && iActor <= MAXSPRITES) + if (aGameVars[id].dwFlags & GAMEVAR_FLAG_PERACTOR) + { + // for the current actor + if (iActor < 0 || iActor >= MAXSPRITES) + { + OSD_Printf(OSD_ERROR "GetGameVarID(): invalid sprite ID (%d)\n",iActor); + return -1; + } return(m * aGameVars[id].plValues[iActor]); + } + + if (aGameVars[id].dwFlags & GAMEVAR_FLAG_INTPTR) + return(m * (*((int*)aGameVars[id].lValue))); + + if (aGameVars[id].dwFlags & GAMEVAR_FLAG_SHORTPTR) + return(m * (*((short*)aGameVars[id].lValue))); + + if (aGameVars[id].dwFlags & GAMEVAR_FLAG_CHARPTR) + return(m * (*((char*)aGameVars[id].lValue))); return(m * aGameVars[id].lValue); } - - if (aGameVars[id].dwFlags & GAMEVAR_FLAG_INTPTR) - return(m * (*((int*)aGameVars[id].lValue))); - - if (aGameVars[id].dwFlags & GAMEVAR_FLAG_SHORTPTR) - return(m * (*((short*)aGameVars[id].lValue))); - - if (aGameVars[id].dwFlags & GAMEVAR_FLAG_CHARPTR) - return(m * (*((char*)aGameVars[id].lValue))); - - return(m * aGameVars[id].lValue); } void SetGameArrayID(int id,int index, int lValue) @@ -1401,7 +1395,7 @@ void InitGameVarPointers(void) //AddLog("InitGameVarPointers"); - for (i=0;i=0;i--) { Bsprintf(aszBuf,"WEAPON%d_CLIP",i); aplWeaponClip[i]=GetGameValuePtr(aszBuf);