1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "gob/save/saveload.h"
#include "gob/save/saveconverter.h"
#include "gob/inter.h"
#include "gob/variables.h"
namespace Gob {
SaveLoad_Geisha::SaveFile SaveLoad_Geisha::_saveFiles[] = {
{"save.inf", kSaveModeSave, 0, "savegame"}
};
SaveLoad_Geisha::GameHandler::File::File(GobEngine *vm, const Common::String &base) :
SlotFileIndexed(vm, SaveLoad_Geisha::kSlotCount, base, "s") {
}
SaveLoad_Geisha::GameHandler::File::~File() {
}
int SaveLoad_Geisha::GameHandler::File::getSlot(int32 offset) const {
return 0;
}
int SaveLoad_Geisha::GameHandler::File::getSlotRemainder(int32 offset) const {
return 0;
}
SaveLoad_Geisha::GameHandler::GameHandler(GobEngine *vm, const Common::String &target) :
SaveHandler(vm), _file(vm, target) {
}
SaveLoad_Geisha::GameHandler::~GameHandler() {
}
int32 SaveLoad_Geisha::GameHandler::getSize() {
if (_file.getSlotMax() == 0)
return -1;
return SaveLoad_Geisha::kSaveFileSize;
}
bool SaveLoad_Geisha::GameHandler::load(int16 dataVar, int32 size, int32 offset) {
if ((size != 0) || (offset != 0)) {
warning("Invalid loading procedure: %d, %d, %d", dataVar, size, offset);
return false;
}
memset(_vm->_inter->_variables->getAddressOff8(dataVar), 0, SaveLoad_Geisha::kSaveFileSize);
for (uint32 slot = 0; slot < SaveLoad_Geisha::kSlotCount;
slot++, dataVar += SaveLoad_Geisha::kSlotSize) {
if (!_file.exists(slot))
continue;
Common::String slotFile = _file.build(slot);
if (slotFile.empty())
return false;
SaveReader reader(2, slot, slotFile);
if (!reader.load()) {
warning("Save slot %d contains corrupted save", slot);
continue;
}
SavePartInfo info(20, (uint32) _vm->getGameType(), 0,
_vm->getEndianness(), _vm->_inter->_variables->getSize());
SavePartVars vars(_vm, SaveLoad_Geisha::kSlotSize);
if (!reader.readPart(0, &info) || !reader.readPart(1, &vars)) {
warning("Save slot %d contains corrupted save", slot);
continue;
}
if (!vars.writeInto(dataVar, 0, SaveLoad_Geisha::kSlotSize)) {
warning("Save slot %d contains corrupted save", slot);
continue;
}
}
return true;
}
bool SaveLoad_Geisha::GameHandler::save(int16 dataVar, int32 size, int32 offset) {
if (((uint32)size != SaveLoad_Geisha::kSaveFileSize) || (offset != 0)) {
warning("Invalid saving procedure: %d, %d, %d", dataVar, size, offset);
return false;
}
for (uint32 slot = 0; slot < SaveLoad_Geisha::kSlotCount;
slot++, dataVar += SaveLoad_Geisha::kSlotSize) {
const byte *slotData = _vm->_inter->_variables->getAddressOff8(dataVar);
// Check of the slot's data is empty
bool empty = true;
for (uint32 j = 0; j < SaveLoad_Geisha::kSlotSize; j++) {
if (slotData[j] != 0) {
empty = false;
break;
}
}
// Don't save empty slots
if (empty)
continue;
Common::String slotFile = _file.build(slot);
if (slotFile.empty())
return false;
SaveWriter writer(2, slot, slotFile);
SavePartInfo info(20, (uint32) _vm->getGameType(), 0,
_vm->getEndianness(), _vm->_inter->_variables->getSize());
SavePartVars vars(_vm, SaveLoad_Geisha::kSlotSize);
info.setDesc(Common::String::format("Geisha, slot %d", slot).c_str());
if (!vars.readFrom(dataVar, 0, SaveLoad_Geisha::kSlotSize))
return false;
if (!writer.writePart(0, &info))
return false;
if (!writer.writePart(1, &vars))
return false;
}
return true;
}
SaveLoad_Geisha::SaveLoad_Geisha(GobEngine *vm, const char *targetName) :
SaveLoad(vm) {
_saveFiles[0].handler = new GameHandler(vm, targetName);
}
SaveLoad_Geisha::~SaveLoad_Geisha() {
for (int i = 0; i < ARRAYSIZE(_saveFiles); i++)
delete _saveFiles[i].handler;
}
const SaveLoad_Geisha::SaveFile *SaveLoad_Geisha::getSaveFile(const char *fileName) const {
fileName = stripPath(fileName);
for (int i = 0; i < ARRAYSIZE(_saveFiles); i++)
if (!scumm_stricmp(fileName, _saveFiles[i].sourceName))
return &_saveFiles[i];
return 0;
}
SaveLoad_Geisha::SaveFile *SaveLoad_Geisha::getSaveFile(const char *fileName) {
fileName = stripPath(fileName);
for (int i = 0; i < ARRAYSIZE(_saveFiles); i++)
if (!scumm_stricmp(fileName, _saveFiles[i].sourceName))
return &_saveFiles[i];
return 0;
}
SaveHandler *SaveLoad_Geisha::getHandler(const char *fileName) const {
const SaveFile *saveFile = getSaveFile(fileName);
if (saveFile)
return saveFile->handler;
return 0;
}
const char *SaveLoad_Geisha::getDescription(const char *fileName) const {
const SaveFile *saveFile = getSaveFile(fileName);
if (saveFile)
return saveFile->description;
return 0;
}
SaveLoad::SaveMode SaveLoad_Geisha::getSaveMode(const char *fileName) const {
const SaveFile *saveFile = getSaveFile(fileName);
if (saveFile)
return saveFile->mode;
return kSaveModeNone;
}
} // End of namespace Gob
|