From 9bfd183cec86b2ea129e203c7390a2229e6d8055 Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 27 Apr 2008 06:54:28 +0000 Subject: [PATCH] Negative gamearray access git-svn-id: https://svn.eduke32.com/eduke32@715 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/gamedef.c | 17 +++++------- polymer/eduke32/source/gameexec.c | 33 ++++++++++++++--------- polymer/eduke32/source/gamevars.c | 44 ++++++++++++++++++++----------- 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 4ea04ee15..36462540e 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -1440,24 +1440,21 @@ static void transvartype(int type) skipcomments(); //skip comments and whitespace if ((*textptr == '[')) //read of array as a gamevar { - + f |= (MAXGAMEVARS<<2); // initprintf("got an array"); textptr++; i=GetADefID(label+(labelcnt<<6)); - if (i >= 0) - { - *scriptptr++=i+1+MAXGAMEVARS; - transvartype(0); - - } - else + if (i < 0) { error++; ReportError(ERROR_NOTAGAMEARRAY); return; } + *scriptptr++=(i|f); + transvartype(0); skipcomments(); //skip comments and whitespace + if (*textptr != ']') { error++; @@ -1521,8 +1518,8 @@ static void transvartype(int type) } if (!(error || warning) && g_ScriptDebug > 1) initprintf("%s:%d: debug: accepted gamevar `%s'.\n",compilefile,line_number,label+(labelcnt<<6)); - i |= f; - *scriptptr++=i; + + *scriptptr++=(i|f); } static inline void transvar(void) diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index a787a985a..b57c24f15 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -6333,21 +6333,25 @@ static int parse(void) { if (*insptr==MAXGAMEVARS) // addlogvar for a constant? Har. insptr++; - else if (*insptr&(MAXGAMEVARS<<1)) - { - m = -1; - lVarID ^= (MAXGAMEVARS<<1); - } - else if (*insptr < MAXGAMEVARS+1+MAXGAMEARRAYS) +// else if (*insptr > iGameVarCount && (*insptr < (MAXGAMEVARS<<1)+MAXGAMEVARS+1+MAXGAMEARRAYS)) + else if (*insptr&(MAXGAMEVARS<<2)) { int index; + lVarID ^= (MAXGAMEVARS<<2); + + if (lVarID&(MAXGAMEVARS<<1)) + { + m = -1; + lVarID ^= (MAXGAMEVARS<<1); + } + insptr++; index=GetGameVarID(*insptr++,g_i,g_p); - if ((index < aGameArrays[lVarID-MAXGAMEVARS-1].size)&&(index>=0)) + if ((index < aGameArrays[lVarID].size)&&(index>=0)) { - OSD_Printf("CONLOGVAR: L=%d %s[%d] =%d\n",l, aGameArrays[lVarID-MAXGAMEVARS-1].szLabel,index,aGameArrays[lVarID-MAXGAMEVARS-1].plValues[index]); + OSD_Printf("CONLOGVAR: L=%d %s[%d] =%d\n",l, aGameArrays[lVarID].szLabel,index,m*aGameArrays[lVarID].plValues[index]); break; } else @@ -6356,6 +6360,11 @@ static int parse(void) break; } } + else if (*insptr&(MAXGAMEVARS<<1)) + { + m = -1; + lVarID ^= (MAXGAMEVARS<<1); + } else { // invalid varID @@ -7392,10 +7401,10 @@ void execute(int iActor,int iPlayer,int lDist) return; } -/* Qbix: Changed variables to be aware of the sizeof *insptr - * (wether it is int vs intptr_t), Although it is specificly cast to intptr_t* - * which might be corrected if the code is converted to use offsets */ - if (g_t[4]) + /* Qbix: Changed variables to be aware of the sizeof *insptr + * (wether it is int vs intptr_t), Although it is specificly cast to intptr_t* + * which might be corrected if the code is converted to use offsets */ + if (g_t[4]) { g_sp->lotag += TICSPERFRAME; diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index c059e076c..165abf989 100755 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -532,30 +532,41 @@ int GetGameVarID(int id, int iActor, int iPlayer) { int inv = 0; + if (id == MAXGAMEVARS) + { +// OSD_Printf("GetGameVarID(): reading gamevar constant\n"); + return(*insptr++); + } + if (id == g_iThisActorID) return iActor; if (id<0 || id >= iGameVarCount) { - if (id==MAXGAMEVARS) +// if (id < (MAXGAMEVARS<<1)+MAXGAMEVARS+1+MAXGAMEARRAYS) + if (id&(MAXGAMEVARS<<2)) { -// OSD_Printf("GetGameVarID(): reading gamevar constant\n"); - return(*insptr++); - } - if (id < MAXGAMEVARS+1+MAXGAMEARRAYS) - { - int index=0; -// OSD_Printf("GetGameVarID(): reading from array\n"); - index=GetGameVarID(*insptr++,iActor,iPlayer); - if ((index < aGameArrays[id-MAXGAMEVARS-1].size)&&(index>=0)) - inv =aGameArrays[id-MAXGAMEVARS-1].plValues[index]; - else + int index=GetGameVarID(*insptr++,iActor,iPlayer); + + id ^= (MAXGAMEVARS<<2); + + if (id&(MAXGAMEVARS<<1)) // negative array access { - OSD_Printf("GetGameVarID(): invalid array index (%s[%d])\n",aGameArrays[id-MAXGAMEVARS-1].szLabel,index); + id ^= (MAXGAMEVARS<<1); +// OSD_Printf("GetGameVarID(): reading from array\n"); + if ((index < aGameArrays[id].size)&&(index>=0)) + return(-aGameArrays[id].plValues[index]); + OSD_Printf("GetGameVarID(): invalid array index (%s[%d])\n",aGameArrays[id].szLabel,index); return -1; } - return(inv); + +// OSD_Printf("GetGameVarID(): reading from array\n"); + if ((index < aGameArrays[id].size)&&(index>=0)) + return(aGameArrays[id].plValues[index]); + OSD_Printf("GetGameVarID(): invalid array index (%s[%d])\n",aGameArrays[id].szLabel,index); + return -1; } + if (!(id&(MAXGAMEVARS<<1))) { OSD_Printf("GetGameVarID(): invalid gamevar ID (%d)\n",id); @@ -701,8 +712,9 @@ int GetGameVar(const char *szGameLabel, int lDefault, int iActor, int iPlayer) static intptr_t *GetGameValuePtr(const char *szGameLabel) { - int i; - for (i=0;i