Ticket #8624: dialog_save_tmpfile.patch

File dialog_save_tmpfile.patch, 6.4 KB (added by SF/tobigun, 15 years ago)

Temp-file version

  • engines/scumm/input.cpp

     
    410410        // Fall back to default behavior
    411411        ScummEngine::processKeyboard(lastKeyHit);
    412412
     413        // On Alt-F5 prepare savegame for the original save/load dialog.
     414        if (lastKeyHit.keycode == Common::KEYCODE_F5 && lastKeyHit.flags == Common::KBD_ALT) {
     415                prepareSavegame();
     416        }
     417
    413418        if (VAR_KEYPRESS != 0xFF && _mouseAndKeyboardStat) {            // Key Input
    414419                if (315 <= _mouseAndKeyboardStat && _mouseAndKeyboardStat <= 323) {
    415420                        // Convert F-Keys for V1/V2 games (they start at 1)
     
    424429        // Fall back to default behavior
    425430        ScummEngine::processKeyboard(lastKeyHit);
    426431
    427         // 'i' brings up an IQ dialog in Indy3
    428         if (lastKeyHit.ascii == 'i' && _game.id == GID_INDY3) {
     432        // On Alt-F5 prepare savegame for the original save/load dialog.
     433        if (lastKeyHit.keycode == Common::KEYCODE_F5 && lastKeyHit.flags == Common::KBD_ALT) {
     434                prepareSavegame();
     435        }
     436
     437        // 'i' brings up an IQ dialog in Indy3 (disabled in save/load dialog for input)
     438        if (lastKeyHit.ascii == 'i' && _game.id == GID_INDY3 && _currentRoom != 14) {
    429439                // SCUMM var 244 is the episode score
    430440                // and var 245 is the series score
    431441                char text[50];
  • engines/scumm/saveload.cpp

     
    131131
    132132bool ScummEngine::saveState(int slot, bool compat) {
    133133        Common::String filename;
    134         Common::OutSaveFile *out;
    135         SaveGameHeader hdr;
    136134
    137135        if (_saveLoadSlot == 255) {
    138136                // Allow custom filenames for save game system in HE Games
     
    140138        } else {
    141139                filename = makeSavegameName(slot, compat);
    142140        }
     141
     142        return saveState(filename);
     143}
     144
     145bool ScummEngine::saveState(Common::String filename) {
     146        Common::OutSaveFile *out;
     147        SaveGameHeader hdr;
     148
    143149        if (!(out = _saveFileMan->openForSaving(filename.c_str())))
    144150                return false;
    145151
     
    445451        return true;
    446452}
    447453
     454void ScummEngine::prepareSavegame() {
     455        saveState("savegame.tmp");
     456}
     457
     458bool ScummEngine::savePreparedSavegame(int slot, char *desc) {
     459        return copyPreparedSavegame("savegame.tmp", slot, desc);
     460}
     461
     462bool ScummEngine::copyPreparedSavegame(Common::String prepFilename, int slot, char *desc) {
     463        bool result;
     464        uint32 nread;
     465        byte buffer[1024];
     466        Common::String filename;
     467        Common::InSaveFile *in;
     468        Common::OutSaveFile *out;
     469        SaveGameHeader hdr;
     470
     471        if (!(in = _saveFileMan->openForLoading(prepFilename.c_str())))
     472                return false;
     473
     474        if (!loadSaveGameHeader(in, hdr)) {
     475                warning("Invalid savegame '%s'", prepFilename.c_str());
     476                delete in;
     477                return false;
     478        }
     479
     480        if (hdr.ver != CURRENT_VER) {
     481                warning("Incompatible savegame '%s'", prepFilename.c_str());
     482                delete in;
     483                return false;
     484        }
     485
     486        filename = makeSavegameName(slot, false);
     487        if (!(out = _saveFileMan->openForSaving(filename.c_str()))) {
     488                delete in;
     489                return false;
     490        }
     491
     492        memset(hdr.name, 0, sizeof(hdr.name));
     493        strncpy(hdr.name, desc, sizeof(hdr.name)-1);
     494        saveSaveGameHeader(out, hdr);
     495       
     496        // copy bytes
     497        result = true;
     498        while (nread = in->read(buffer, sizeof(buffer))) {
     499                uint32 nwritten = out->write(buffer, nread);
     500                if (nwritten < nread) {
     501                        result = false;
     502                        break;
     503                }
     504        }
     505
     506        out->finalize();
     507        if (out->ioFailed()) {
     508                result = false;
     509        }
     510        delete in;
     511        delete out;
     512
     513        return result;
     514}
     515
    448516Common::String ScummEngine::makeSavegameName(const Common::String &target, int slot, bool temporary) {
    449517        char extension[6];
    450518        snprintf(extension, sizeof(extension), ".%c%02d", temporary ? 'c' : 's', slot);
  • engines/scumm/script_v5.cpp

     
    869869        // which matches the original Indy3 save/load code. See also the notes
    870870        // on Feature Request #1666521.
    871871        STRINGID_IQ_EPISODE = 7,
    872         STRINGID_IQ_SERIES = 9
     872        STRINGID_IQ_SERIES = 9,
     873        // The string IDs of the first savegame name, used as an offset to determine
     874        // the IDs of all savenames.
     875        // Loom is the only game whose savenames start with a different ID.
     876        STRINGID_SAVENAME1 = 10,
     877        STRINGID_SAVENAME1_LOOM = 9
    873878};
    874879
    875880void ScummEngine_v5::o5_saveLoadVars() {
     
    12351240                result = 100;
    12361241                break;
    12371242        case 0x20: // drive
    1238                 if (_game.id == GID_INDY3) {
    1239                         // 0 = hard drive
    1240                         // 1 = disk drive
    1241                         result = 0;
     1243                if (_game.version <= 3) {
     1244                        // 0 = ???
     1245                        // [1,2] = disk drive [A:,B:]
     1246                        // 3 = hard drive
     1247                        result = 3;
    12421248                } else {
    12431249                        // set current drive
    12441250                        result = 1;
    12451251                }
    12461252                break;
    12471253        case 0x40: // load
    1248                 if (loadState(slot, _saveTemporaryState))
     1254                if (loadState(slot, false))
    12491255                        result = 3; // sucess
    12501256                else
    12511257                        result = 5; // failed to load
    12521258                break;
    12531259        case 0x80: // save
    1254                 //if (saveState(slot, _saveTemporaryState))
    1255                 //      result = 0; // sucess
    1256                 //else
     1260                if (_game.version <= 3) {
     1261                        char name[32];
     1262                        if (_game.version <= 2) {
     1263                                // use generic name
     1264                                sprintf(name, "Game %c", 'A'+slot-1);
     1265                        } else {
     1266                                // use name entered by the user
     1267                                char* ptr;
     1268                                int firstSlot = (_game.id == GID_LOOM) ? STRINGID_SAVENAME1_LOOM : STRINGID_SAVENAME1;
     1269                                ptr = (char*)getStringAddress(slot + firstSlot - 1);
     1270                                strncpy(name, ptr, sizeof(name));
     1271                        }
     1272
     1273                        if(savePreparedSavegame(slot, name))
     1274                                result = 0;
     1275                        else
     1276                                result = 2;
     1277                } else {
    12571278                        result = 2; // failed to save
     1279                }
    12581280                break;
    12591281        case 0xC0: // test if save exists
    12601282                {
  • engines/scumm/scumm.h

     
    626626        char _saveLoadFileName[32];
    627627        char _saveLoadName[32];
    628628
     629        bool saveState(Common::String filename);
    629630        bool saveState(int slot, bool compat);
    630631        bool loadState(int slot, bool compat);
    631632        virtual void saveOrLoad(Serializer *s);
     
    633634        void saveResource(Serializer *ser, int type, int index);
    634635        void loadResource(Serializer *ser, int type, int index);
    635636
     637        void prepareSavegame();
     638        bool savePreparedSavegame(int slot, char *desc);
     639        bool copyPreparedSavegame(Common::String prepFilename, int slot, char *desc);
     640
    636641        Common::String makeSavegameName(int slot, bool temporary) const {
    637642                return makeSavegameName(_targetName, slot, temporary);
    638643        }