Ticket #8429: gob-pointers.diff

File gob-pointers.diff, 7.5 KB (added by eriktorbjorn, 19 years ago)

Patch against a May 4 CVS snapshot

  • gob/parse.cpp

    diff -ur --exclude=CVS --exclude=Makefile ScummVM/gob/parse.cpp ScummVM+hack/gob/parse.cpp
    old new  
    2121 */
    2222#include "gob/gob.h"
    2323#include "gob/global.h"
     24#include "gob/game.h"
    2425#include "gob/parse.h"
    2526#include "gob/util.h"
    2627#include "gob/inter.h"
    2728
    2829namespace Gob {
    2930
     31enum PointerType {
     32        kExecPtr = 0,
     33        kInterVar = 1,
     34        kResStr = 2
     35};
     36
     37int32 encodePtr(char *ptr, int type) {
     38        int32 offset;
     39
     40        switch (type) {
     41        case kExecPtr:
     42                offset = ptr - game_totFileData;
     43                break;
     44        case kInterVar:
     45                offset = ptr - inter_variables;
     46                break;
     47        case kResStr:
     48                offset = ptr - inter_resStr;
     49                break;
     50        default:
     51                error("encodePtr: Unknown pointer type");
     52        }
     53        return (type << 28) | offset;
     54}
     55
     56char *decodePtr(int32 n) {
     57        char *ptr;
    3058
     59        switch (n >> 28) {
     60        case kExecPtr:
     61                ptr = game_totFileData;
     62                break;
     63        case kInterVar:
     64                ptr = inter_variables;
     65                break;
     66        case kResStr:
     67                ptr = inter_resStr;
     68                break;
     69        default:
     70                error("decodePtr: Unknown pointer type");
     71        }
     72        return ptr + (n & 0x0FFFFFFF);
     73}
    3174
    3275int16 parse_parseExpr(char arg_0, byte *arg_2) {
    3376        int32 values[20];
     
    73116
    74117                        case 22:
    75118                                *operPtr = 22;
    76                                 *valPtr = (int32)inter_execPtr;
     119                                *valPtr = encodePtr(inter_execPtr, kExecPtr);
    77120                                inter_execPtr += strlen(inter_execPtr) + 1;
    78121                                break;
    79122
     
    85128                        case 25:
    86129                                *operPtr = 22;
    87130                                temp = inter_load16() * 4;
    88                                 *valPtr = (int32)(inter_variables + temp);
     131                                *valPtr = encodePtr(inter_variables + temp, kInterVar);
    89132                                if (*inter_execPtr == 13) {
    90133                                        inter_execPtr++;
    91134                                        temp += parse_parseValExpr();
     
    113156                                        *valPtr = VAR(temp + offset);
    114157                                        break;
    115158                                }
    116                                 *valPtr = (int32)(inter_variables + temp * 4 + offset * inter_animDataSize * 4);
     159                                *valPtr = encodePtr(inter_variables + temp * 4 + offset * inter_animDataSize * 4, kInterVar);
    117160                                if (*inter_execPtr == 13) {
    118161                                        inter_execPtr++;
    119162                                        temp2 = parse_parseValExpr();
     
    181224                        switch (operPtr[-1]) {
    182225                        case 2:
    183226                                if (operPtr[-2] == 22) {
    184                                         if ((char *)valPtr[-2] != inter_resStr) {
    185                                                 strcpy(inter_resStr, (char *)valPtr[-2]);
    186                                                 valPtr[-2] = (int32)inter_resStr;
     227                                        if (decodePtr(valPtr[-2]) != inter_resStr) {
     228                                                strcpy(inter_resStr, decodePtr(valPtr[-2]));
     229                                                valPtr[-2] = encodePtr(inter_resStr, kResStr);
    187230                                        }
    188                                         strcat(inter_resStr, (char *)valPtr[0]);
     231                                        strcat(inter_resStr, decodePtr(valPtr[0]));
    189232                                        stkPos -= 2;
    190233                                        operPtr -= 2;
    191234                                        valPtr -= 2;
     
    301344                                        if (operStack[brackStart] == 20) {
    302345                                                values[brackStart] += valPtr[-1];
    303346                                        } else if (operStack[brackStart] == 22) {
    304                                                 if ((char *)values[brackStart]
    305                                                     != inter_resStr) {
    306                                                         strcpy(inter_resStr, (char *)values[brackStart]);
    307                                                         values[brackStart] = (int32)inter_resStr;
     347                                                if (decodePtr(values[brackStart]) != inter_resStr) {
     348                                                        strcpy(inter_resStr, decodePtr(values[brackStart]));
     349                                                        values[brackStart] = encodePtr(inter_resStr, kResStr);
    308350                                                }
    309                                                 strcat(inter_resStr, (char *)valPtr[-1]);
     351                                                strcat(inter_resStr, decodePtr(valPtr[-1]));
    310352                                        }
    311353                                        stkPos -= 2;
    312354                                        operPtr -= 2;
     
    378420                                                if (valPtr[-3] < valPtr[-1])
    379421                                                        operPtr[-3] = 24;
    380422                                        } else if (var_C == 22) {
    381                                                 if ((char *)valPtr[-3] != inter_resStr) {
    382                                                         strcpy(inter_resStr, (char *)valPtr[-3]);
    383                                                         valPtr[-3] = (int32)inter_resStr;
     423                                                if (decodePtr(valPtr[-3]) != inter_resStr) {
     424                                                        strcpy(inter_resStr, decodePtr(valPtr[-3]));
     425                                                        valPtr[-3] = encodePtr(inter_resStr, kResStr);
    384426                                                }
    385                                                 if (strcmp(inter_resStr, (char *)valPtr[-1]) < 0)
     427                                                if (strcmp(inter_resStr, decodePtr(valPtr[-1])) < 0)
    386428                                                        operPtr[-3] = 24;
    387429                                        }
    388430                                        stkPos -= 2;
     
    397439                                                if (valPtr[-3] <= valPtr[-1])
    398440                                                        operPtr[-3] = 24;
    399441                                        } else if (var_C == 22) {
    400                                                 if ((char *)valPtr[-3] != inter_resStr) {
    401                                                         strcpy(inter_resStr, (char *)valPtr[-3]);
    402                                                         valPtr[-3] = (int32)inter_resStr;
     442                                                if (decodePtr(valPtr[-3]) != inter_resStr) {
     443                                                        strcpy(inter_resStr, decodePtr(valPtr[-3]));
     444                                                        valPtr[-3] = encodePtr(inter_resStr, kResStr);
    403445                                                }
    404                                                 if (strcmp(inter_resStr, (char *)valPtr[-1]) <= 0)
     446                                                if (strcmp(inter_resStr, decodePtr(valPtr[-1])) <= 0)
    405447                                                        operPtr[-3] = 24;
    406448                                        }
    407449                                        stkPos -= 2;
     
    416458                                                if (valPtr[-3] > valPtr[-1])
    417459                                                        operPtr[-3] = 24;
    418460                                        } else if (var_C == 22) {
    419                                                 if ((char *)valPtr[-3] != inter_resStr) {
    420                                                         strcpy(inter_resStr, (char *)valPtr[-3]);
    421                                                         valPtr[-3] = (int32)inter_resStr;
     461                                                if (decodePtr(valPtr[-3]) != inter_resStr) {
     462                                                        strcpy(inter_resStr, decodePtr(valPtr[-3]));
     463                                                        valPtr[-3] = encodePtr(inter_resStr, kResStr);
    422464                                                }
    423                                                 if (strcmp(inter_resStr, (char *)valPtr[-1]) > 0)
     465                                                if (strcmp(inter_resStr, decodePtr(valPtr[-1])) > 0)
    424466                                                        operPtr[-3] = 24;
    425467                                        }
    426468                                        stkPos -= 2;
     
    435477                                                if (valPtr[-3] >= valPtr[-1])
    436478                                                        operPtr[-3] = 24;
    437479                                        } else if (var_C == 22) {
    438                                                 if ((char *)valPtr[-3] != inter_resStr) {
    439                                                         strcpy(inter_resStr, (char *)valPtr[-3]);
    440                                                         valPtr[-3] = (int32)inter_resStr;
     480                                                if (decodePtr(valPtr[-3]) != inter_resStr) {
     481                                                        strcpy(inter_resStr, decodePtr(valPtr[-3]));
     482                                                        valPtr[-3] = encodePtr(inter_resStr, kResStr);
    441483                                                }
    442                                                 if (strcmp(inter_resStr, (char *)valPtr[-1]) >= 0)
     484                                                if (strcmp(inter_resStr, decodePtr(valPtr[-1])) >= 0)
    443485                                                        operPtr[-3] = 24;
    444486                                        }
    445487                                        stkPos -= 2;
     
    454496                                                if (valPtr[-3] == valPtr[-1])
    455497                                                        operPtr[-3] = 24;
    456498                                        } else if (var_C == 22) {
    457                                                 if ((char *)valPtr[-3] != inter_resStr) {
    458                                                         strcpy(inter_resStr, (char *)valPtr[-3]);
    459                                                         valPtr[-3] = (int32)inter_resStr;
     499                                                if (decodePtr(valPtr[-3]) != inter_resStr) {
     500                                                        strcpy(inter_resStr, decodePtr(valPtr[-3]));
     501                                                        valPtr[-3] = encodePtr(inter_resStr, kResStr);
    460502                                                }
    461                                                 if (strcmp(inter_resStr, (char *)valPtr[-1]) == 0)
     503                                                if (strcmp(inter_resStr, decodePtr(valPtr[-1])) == 0)
    462504                                                        operPtr[-3] = 24;
    463505                                        }
    464506                                        stkPos -= 2;
     
    473515                                                if (valPtr[-3] != valPtr[-1])
    474516                                                        operPtr[-3] = 24;
    475517                                        } else if (var_C == 22) {
    476                                                 if ((char *)valPtr[-3] != inter_resStr) {
    477                                                         strcpy(inter_resStr, (char *)valPtr[-3]);
    478                                                         valPtr[-3] = (int32)inter_resStr;
     518                                                if (decodePtr(valPtr[-3]) != inter_resStr) {
     519                                                        strcpy(inter_resStr, decodePtr(valPtr[-3]));
     520                                                        valPtr[-3] = encodePtr(inter_resStr, kResStr);
    479521                                                }
    480                                                 if (strcmp(inter_resStr, (char *)valPtr[-1]) != 0)
     522                                                if (strcmp(inter_resStr, decodePtr(valPtr[-1])) != 0)
    481523                                                        operPtr[-3] = 24;
    482524                                        }
    483525                                        stkPos -= 2;
     
    544586                                break;
    545587
    546588                        case 22:
    547                                 if ((char *)values[0] != inter_resStr)
    548                                         strcpy(inter_resStr,
    549                                             (char *)values[0]);
     589                                if (decodePtr(values[0]) != inter_resStr)
     590                                        strcpy(inter_resStr, decodePtr(values[0]));
    550591                                break;
    551592
    552593                        case 11:
     
    576617                                        if (operPtr[-3] == 20) {
    577618                                                valPtr[-3] += valPtr[-1];
    578619                                        } else if (operPtr[-3] == 22) {
    579                                                 if ((char *)valPtr[-3] != inter_resStr) {
    580                                                         strcpy(inter_resStr, (char *)valPtr[-3]);
    581                                                         valPtr[-3] = (int32)inter_resStr;
     620                                                if (decodePtr(valPtr[-3]) != inter_resStr) {
     621                                                        strcpy(inter_resStr, decodePtr(valPtr[-3]));
     622                                                        valPtr[-3] = encodePtr(inter_resStr, kResStr);
    582623                                                }
    583                                                 strcat(inter_resStr, (char *)valPtr[-1]);
     624                                                strcat(inter_resStr, decodePtr(valPtr[-1]));
    584625                                        }
    585626                                        stkPos -= 2;
    586627                                        operPtr -= 2;