Ticket #8784: savehack.patch

File savehack.patch, 3.6 KB (added by SF/next_ghost, 12 years ago)

CinE savegame fix

  • engines/cine/various.cpp

     
    390390bool CineEngine::makeLoad(char *saveName) {
    391391        int16 i;
    392392        int16 size;
     393        bool oldSave = false;
    393394        Common::InSaveFile *fHandle;
    394395
    395396        fHandle = g_saveFileMan->openForLoading(saveName);
     
    539540
    540541        fHandle->readUint16BE();
    541542        fHandle->readUint16BE();
     543       
     544        animDataTable[0].width = fHandle->readUint16BE();
     545        animDataTable[0].var1 = fHandle->readUint16BE();
     546        animDataTable[0].bpp = fHandle->readUint16BE();
     547        animDataTable[0].height = fHandle->readUint16BE();
     548        animDataTable[0].ptr1 = NULL;
     549        animDataTable[0].ptr2 = NULL;
     550        animDataTable[0].fileIdx = fHandle->readSint16BE();
     551        animDataTable[0].frameIdx = fHandle->readSint16BE();
     552        fHandle->read(animDataTable[0].name, 10);
    542553
    543         for (i = 0; i < NUM_MAX_ANIMDATA; i++) {
     554        // ugly hack that may not work
     555        // guess whether we're loading 0.10.0 buggy save or original save
     556        // original save has 8 extra almost meaningless bytes before fileIdx,
     557        // therefore name[8] will be non-zero
     558        // 9-character part name in 0.10.0 means BIG trouble, luckily
     559        // that can't happen in unmodified game
     560        if (animDataTable[0].name[8] != 0) {
     561                oldSave = true;
     562                animDataTable[0].refresh = (animDataTable[0].fileIdx ||
     563                        animDataTable[0].frameIdx) ? 1 : 0;
     564                Common::MemoryReadStream readS((byte*)animDataTable[0].name+4, 10);
     565                animDataTable[0].fileIdx = readS.readUint16BE();
     566                animDataTable[0].frameIdx = readS.readUint16BE();
     567                animDataTable[0].name[0] = animDataTable[0].name[8];
     568                animDataTable[0].name[1] = animDataTable[0].name[9];
     569                fHandle->read(animDataTable[0].name+2, 8);
     570        } else {
     571                animDataTable[0].refresh = (fHandle->readByte() != 0);
     572        }
     573
     574        for (i = 1; i < NUM_MAX_ANIMDATA; i++) {
    544575                animDataTable[i].width = fHandle->readUint16BE();
    545576                animDataTable[i].var1 = fHandle->readUint16BE();
    546577                animDataTable[i].bpp = fHandle->readUint16BE();
    547578                animDataTable[i].height = fHandle->readUint16BE();
     579                if(oldSave) {
     580                        animDataTable[i].refresh = (fHandle->readUint32BE() != 0);
     581                        fHandle->readUint32BE();
     582                }
    548583                animDataTable[i].ptr1 = NULL;
    549584                animDataTable[i].ptr2 = NULL;
    550585                animDataTable[i].fileIdx = fHandle->readSint16BE();
    551586                animDataTable[i].frameIdx = fHandle->readSint16BE();
    552587                fHandle->read(animDataTable[i].name, 10);
    553                 animDataTable[i].refresh = (fHandle->readByte() != 0);
     588                if(!oldSave) {
     589                        animDataTable[i].refresh = (fHandle->readByte() != 0);
     590                }
    554591        }
    555592
    556593        // TODO: handle screen params (really required ?)
     
    706743                fHandle->writeUint16BE(animDataTable[i].var1);
    707744                fHandle->writeUint16BE(animDataTable[i].bpp);
    708745                fHandle->writeUint16BE(animDataTable[i].height);
     746                // This file format looks like Delphine guys
     747                // hacked it together 10 minutes before release deadline...
     748                // Just because I write pointers to a file doesn't mean
     749                // anyone should actually read those values back!
     750                fHandle->writeUint32BE((uint32)animDataTable[i].ptr1);
     751                fHandle->writeUint32BE((uint32)animDataTable[i].ptr2);
    709752                fHandle->writeSint16BE(animDataTable[i].fileIdx);
    710753                fHandle->writeSint16BE(animDataTable[i].frameIdx);
    711754                fHandle->write(animDataTable[i].name, 10);
    712 
    713                 // Horrifyingly, cinE used to dump the entire struct to the
    714                 // save file, including the data pointers. While these pointers
    715                 // would be invalid after loading, the loadResourcesFromSave()
    716                 // function would still test if ptr1 was non-NULL, presumably
    717                 // to see if the object was present in the room.
    718 
    719                 fHandle->writeByte(animDataTable[i].ptr1 ? 1 : 0);
    720755        }
    721756
    722757        fHandle->writeUint16BE(0);  // Screen params, unhandled