uint32 Sword2Engine::saveGame(uint16 slotNo, const byte *desc) { char description[SAVE_DESCRIPTION_LEN]; uint32 bufferSize = findBufferSize(); byte *saveBuffer = (byte *)malloc(bufferSize); ScreenInfo *screenInfo = _screen->getScreenInfo(); memset(description, 0, sizeof(description)); strncpy(description, (const char *)desc, SAVE_DESCRIPTION_LEN - 1); Common::MemoryWriteStream writeS(saveBuffer, bufferSize); byte *globalVars = _resman->openResource(1); byte *objectHub = _resman->openResource(CUR_PLAYER_ID) + ResHeader::size(); // Script no. 7 - 'george_savedata_request' calls fnPassPlayerSaveData _logic->runResScript(CUR_PLAYER_ID, 7); writeS.writeUint32LE(0); // Checksum writeS.write(description, SAVE_DESCRIPTION_LEN); writeS.writeUint32LE(_resman->fetchLen(1)); writeS.writeUint32LE(screenInfo->background_layer_id); writeS.writeUint32LE(_logic->getRunList()); writeS.writeUint32LE(screenInfo->feet_x); writeS.writeUint32LE(screenInfo->feet_y); writeS.writeUint32LE(_sound->getLoopingMusicId()); writeS.write(objectHub, ObjectHub::size()); writeS.write(_logic->_saveLogic, ObjectLogic::size()); writeS.write(_logic->_saveGraphic, ObjectGraphic::size()); writeS.write(_logic->_saveMega, ObjectMega::size()); writeS.write(globalVars, _resman->fetchLen(1)); WRITE_LE_UINT32(saveBuffer, calcChecksum(saveBuffer + 4, bufferSize - 4)); _resman->closeResource(CUR_PLAYER_ID); _resman->closeResource(1); uint32 errorCode = saveData(slotNo, saveBuffer, bufferSize); free(saveBuffer); if (errorCode != SR_OK) { uint32 textId; switch (errorCode) { case SR_ERR_FILEOPEN: textId = TEXT_SAVE_CANT_OPEN; break; default: textId = TEXT_SAVE_FAILED; break; } _screen->displayMsg(fetchTextLine(_resman->openResource(textId / SIZE), textId & 0xffff) + 2, 0); } return errorCode; }
uint32 Sword2Engine::restoreGame(uint16 slotNo) { uint32 bufferSize = findBufferSize(); byte *saveBufferMem = (byte *)malloc(bufferSize); uint32 errorCode = restoreData(slotNo, saveBufferMem, bufferSize); // If it was read in successfully, then restore the game from the // buffer & free the buffer. Note that restoreFromBuffer() frees the // buffer in order to clear it from memory before loading in the new // screen and runlist, so we only need to free it in case of failure. if (errorCode == SR_OK) errorCode = restoreFromBuffer(saveBufferMem, bufferSize); else free(saveBufferMem); if (errorCode != SR_OK) { uint32 textId; switch (errorCode) { case SR_ERR_FILEOPEN: textId = TEXT_RESTORE_CANT_OPEN; break; case SR_ERR_INCOMPATIBLE: textId = TEXT_RESTORE_INCOMPATIBLE; break; default: textId = TEXT_RESTORE_FAILED; break; } _screen->displayMsg(fetchTextLine(_resman->openResource(textId / SIZE), textId & 0xffff) + 2, 0); } else { // Prime system with a game cycle // Reset the graphic 'BuildUnit' list before a new logic list // (see fnRegisterFrame) _screen->resetRenderLists(); // Reset the mouse hot-spot list. See fnRegisterMouse() // and fnRegisterFrame() _mouse->resetMouseList(); if (_logic->processSession()) error("restore 1st cycle failed??"); } // Force the game engine to pick a cursor. This appears to be needed // when using the -x command-line option to restore a game. _mouse->setMouseTouching(1); return errorCode; }
void Sword2Engine::initializeFontResourceFlags() { byte *textFile = _resman->openResource(TEXT_RES); // If language is Polish or Finnish it requires alternate fonts. // Otherwise, use regular fonts // "tallenna" Finnish for "save" // "zapisz" Polish for "save" // Get the text line (& skip the 2 chars containing the wavId) char *textLine = (char *)fetchTextLine(textFile, SAVE_LINE_NO) + 2; if (strcmp(textLine, "tallenna") == 0) initializeFontResourceFlags(FINNISH_TEXT); else if (strcmp(textLine, "zapisz") == 0) initializeFontResourceFlags(POLISH_TEXT); else initializeFontResourceFlags(DEFAULT_TEXT); // Get the game name for the windows application // According to the GetGameName(), which was never called and has // therefore been removed, the name of the game is: // // ENGLISH: "Broken Sword II" // AMERICAN: "Circle of Blood II" // GERMAN: "Baphomet's Fluch II" // default: "Some game or other, part 86" // // But we get it from the text resource instead. if (_logic->readVar(DEMO)) textLine = (char *)fetchTextLine(textFile, 451) + 2; else textLine = (char *)fetchTextLine(textFile, 54) + 2; _system->setWindowCaption(textLine); _resman->closeResource(TEXT_RES); }