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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
|
/* 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 "gui/EventRecorder.h"
namespace Common {
DECLARE_SINGLETON(GUI::EventRecorder);
}
#ifdef ENABLE_EVENTRECORDER
#include "common/debug-channels.h"
#include "backends/timer/sdl/sdl-timer.h"
#include "backends/mixer/sdl/sdl-mixer.h"
#include "common/config-manager.h"
#include "common/md5.h"
#include "gui/gui-manager.h"
#include "gui/widget.h"
#include "gui/onscreendialog.h"
#include "common/random.h"
#include "common/savefile.h"
#include "common/textconsole.h"
#include "graphics/thumbnail.h"
#include "graphics/surface.h"
#include "graphics/scaler.h"
namespace GUI {
const int kMaxRecordsNames = 0x64;
const int kDefaultScreenshotPeriod = 60000;
const int kDefaultBPP = 2;
uint32 readTime(Common::ReadStream *inFile) {
uint32 d = inFile->readByte();
if (d == 0xff) {
d = inFile->readUint32LE();
}
return d;
}
void writeTime(Common::WriteStream *outFile, uint32 d) {
//Simple RLE compression
if (d >= 0xff) {
outFile->writeByte(0xff);
outFile->writeUint32LE(d);
} else {
outFile->writeByte(d);
}
}
EventRecorder::EventRecorder() {
_timerManager = NULL;
_recordMode = kPassthrough;
_fakeMixerManager = NULL;
_initialized = false;
_needRedraw = false;
_fastPlayback = false;
DebugMan.addDebugChannel(kDebugLevelEventRec, "EventRec", "Event recorder debug level");
}
EventRecorder::~EventRecorder() {
if (_timerManager != NULL) {
delete _timerManager;
}
}
void EventRecorder::deinit() {
if (!_initialized) {
return;
}
setFileHeader();
_needRedraw = false;
_initialized = false;
_recordMode = kPassthrough;
delete _fakeMixerManager;
_fakeMixerManager = NULL;
controlPanel->close();
delete controlPanel;
debugC(1, kDebugLevelEventRec, "playback:action=stopplayback");
g_system->getEventManager()->getEventDispatcher()->unregisterSource(this);
_recordMode = kPassthrough;
_playbackFile->close();
delete _playbackFile;
switchMixer();
switchTimerManagers();
DebugMan.disableDebugChannel("EventRec");
}
void EventRecorder::processMillis(uint32 &millis, bool skipRecord) {
if (!_initialized) {
return;
}
if (skipRecord) {
millis = _fakeTimer;
return;
}
if (_recordMode == kRecorderPlaybackPause) {
millis = _fakeTimer;
}
uint32 millisDelay;
Common::RecorderEvent timerEvent;
switch (_recordMode) {
case kRecorderRecord:
updateSubsystems();
millisDelay = millis - _lastMillis;
_lastMillis = millis;
_fakeTimer += millisDelay;
controlPanel->setReplayedTime(_fakeTimer);
timerEvent.recordedtype = Common::kRecorderEventTypeTimer;
timerEvent.time = _fakeTimer;
_playbackFile->writeEvent(timerEvent);
takeScreenshot();
_timerManager->handler();
break;
case kRecorderPlayback:
updateSubsystems();
if (_nextEvent.recordedtype == Common::kRecorderEventTypeTimer) {
_fakeTimer = _nextEvent.time;
_nextEvent = _playbackFile->getNextEvent();
_timerManager->handler();
} else {
if (_nextEvent.type == Common::EVENT_RTL) {
error("playback:action=stopplayback");
} else {
uint32 seconds = _fakeTimer / 1000;
Common::String screenTime = Common::String::format("%.2d:%.2d:%.2d", seconds / 3600 % 24, seconds / 60 % 60, seconds % 60);
error("playback:action=error reason=\"synchronization error\" time = %s", screenTime.c_str());
}
}
millis = _fakeTimer;
controlPanel->setReplayedTime(_fakeTimer);
break;
case kRecorderPlaybackPause:
millis = _fakeTimer;
break;
default:
break;
}
}
bool EventRecorder::processDelayMillis() {
return _fastPlayback;
}
void EventRecorder::checkForKeyCode(const Common::Event &event) {
if ((event.type == Common::EVENT_KEYDOWN) && (event.kbd.flags & Common::KBD_CTRL) && (event.kbd.keycode == Common::KEYCODE_p) && (!event.synthetic)) {
togglePause();
}
}
bool EventRecorder::pollEvent(Common::Event &ev) {
if ((_recordMode != kRecorderPlayback) || !_initialized)
return false;
if ((_nextEvent.recordedtype == Common::kRecorderEventTypeTimer) || (_nextEvent.type == Common::EVENT_INVALID)) {
return false;
}
switch (_nextEvent.type) {
case Common::EVENT_MOUSEMOVE:
case Common::EVENT_LBUTTONDOWN:
case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_RBUTTONUP:
case Common::EVENT_WHEELUP:
case Common::EVENT_WHEELDOWN:
g_system->warpMouse(_nextEvent.mouse.x, _nextEvent.mouse.y);
break;
default:
break;
}
ev = _nextEvent;
_nextEvent = _playbackFile->getNextEvent();
return true;
}
void EventRecorder::switchFastMode() {
if (_recordMode == kRecorderPlaybackPause) {
_fastPlayback = !_fastPlayback;
}
}
void EventRecorder::togglePause() {
RecordMode oldState;
switch (_recordMode) {
case kRecorderPlayback:
case kRecorderRecord:
oldState = _recordMode;
_recordMode = kRecorderPlaybackPause;
controlPanel->runModal();
_recordMode = oldState;
_initialized = true;
break;
case kRecorderPlaybackPause:
controlPanel->close();
break;
default:
break;
}
}
void EventRecorder::RegisterEventSource() {
g_system->getEventManager()->getEventDispatcher()->registerMapper(this, false);
}
uint32 EventRecorder::getRandomSeed(const Common::String &name) {
uint32 result = g_system->getMillis();
if (_recordMode == kRecorderRecord) {
_playbackFile->getHeader().randomSourceRecords[name] = result;
} else if (_recordMode == kRecorderPlayback) {
result = _playbackFile->getHeader().randomSourceRecords[name];
}
return result;
}
Common::String EventRecorder::generateRecordFileName(const Common::String &target) {
Common::String pattern(target+".r??");
Common::StringArray files = g_system->getSavefileManager()->listSavefiles(pattern);
for (int i = 0; i < kMaxRecordsNames; ++i) {
Common::String recordName = Common::String::format("%s.r%02d", target.c_str(), i);
if (find(files.begin(), files.end(), recordName) != files.end()) {
continue;
}
return recordName;
}
return "";
}
void EventRecorder::init(Common::String recordFileName, RecordMode mode) {
_fakeMixerManager = new NullSdlMixerManager();
_fakeMixerManager->init();
_fakeMixerManager->suspendAudio();
_fakeTimer = 0;
_lastMillis = g_system->getMillis();
_playbackFile = new Common::PlaybackFile();
_lastScreenshotTime = 0;
_recordMode = mode;
_needcontinueGame = false;
if (ConfMan.hasKey("disable_display")) {
DebugMan.enableDebugChannel("EventRec");
gDebugLevel = 1;
}
if (_recordMode == kRecorderPlayback) {
debugC(1, kDebugLevelEventRec, "playback:action=\"Load file\" filename=%s", recordFileName.c_str());
}
g_system->getEventManager()->getEventDispatcher()->registerSource(this, false);
_screenshotPeriod = ConfMan.getInt("screenshot_period");
if (_screenshotPeriod == 0) {
_screenshotPeriod = kDefaultScreenshotPeriod;
}
if (!openRecordFile(recordFileName)) {
deinit();
error("playback:action=error reason=\"Record file loading error\"");
return;
}
if (_recordMode != kPassthrough) {
controlPanel = new GUI::OnScreenDialog(_recordMode == kRecorderRecord);
}
if (_recordMode == kRecorderPlayback) {
applyPlaybackSettings();
_nextEvent = _playbackFile->getNextEvent();
}
if (_recordMode == kRecorderRecord) {
getConfig();
}
switchMixer();
switchTimerManagers();
_needRedraw = true;
_initialized = true;
}
/**
* Opens or creates file depend of recording mode.
*
*@param id of recording or playing back game
*@return true in case of success, false in case of error
*
*/
bool EventRecorder::openRecordFile(const Common::String &fileName) {
bool result;
switch (_recordMode) {
case kRecorderRecord:
return _playbackFile->openWrite(fileName);
case kRecorderPlayback:
_recordMode = kPassthrough;
result = _playbackFile->openRead(fileName);
_recordMode = kRecorderPlayback;
return result;
default:
return false;
}
return true;
}
bool EventRecorder::checkGameHash(const ADGameDescription *gameDesc) {
if ((gameDesc == NULL) && (_playbackFile->getHeader().hashRecords.size() != 0)) {
warning("Engine doesn't contain description table");
return false;
}
for (const ADGameFileDescription *fileDesc = gameDesc->filesDescriptions; fileDesc->fileName; fileDesc++) {
if (_playbackFile->getHeader().hashRecords.find(fileDesc->fileName) == _playbackFile->getHeader().hashRecords.end()) {
warning("MD5 hash for file %s not found in record file", fileDesc->fileName);
debugC(1, kDebugLevelEventRec, "playback:action=\"Check game hash\" filename=%s filehash=%s storedhash=\"\" result=different", fileDesc->fileName, fileDesc->md5);
return false;
}
if (_playbackFile->getHeader().hashRecords[fileDesc->fileName] != fileDesc->md5) {
warning("Incorrect version of game file %s. Stored MD5 is %s. MD5 of loaded game is %s", fileDesc->fileName, _playbackFile->getHeader().hashRecords[fileDesc->fileName].c_str(), fileDesc->md5);
debugC(1, kDebugLevelEventRec, "playback:action=\"Check game hash\" filename=%s filehash=%s storedhash=%s result=different", fileDesc->fileName, fileDesc->md5, _playbackFile->getHeader().hashRecords[fileDesc->fileName].c_str());
return false;
}
debugC(1, kDebugLevelEventRec, "playback:action=\"Check game hash\" filename=%s filehash=%s storedhash=%s result=equal", fileDesc->fileName, fileDesc->md5, _playbackFile->getHeader().hashRecords[fileDesc->fileName].c_str());
}
return true;
}
void EventRecorder::registerMixerManager(SdlMixerManager *mixerManager) {
_realMixerManager = mixerManager;
}
void EventRecorder::switchMixer() {
if (_recordMode == kPassthrough) {
_realMixerManager->resumeAudio();
} else {
_realMixerManager->suspendAudio();
_fakeMixerManager->resumeAudio();
}
}
SdlMixerManager *EventRecorder::getMixerManager() {
if (_recordMode == kPassthrough) {
return _realMixerManager;
} else {
return _fakeMixerManager;
}
}
void EventRecorder::getConfigFromDomain(Common::ConfigManager::Domain *domain) {
for (Common::ConfigManager::Domain::iterator entry = domain->begin(); entry!= domain->end(); ++entry) {
_playbackFile->getHeader().settingsRecords[entry->_key] = entry->_value;
}
}
void EventRecorder::getConfig() {
getConfigFromDomain(ConfMan.getDomain(ConfMan.kApplicationDomain));
getConfigFromDomain(ConfMan.getActiveDomain());
_playbackFile->getHeader().settingsRecords["save_slot"] = ConfMan.get("save_slot");
}
void EventRecorder::applyPlaybackSettings() {
for (Common::StringMap::iterator i = _playbackFile->getHeader().settingsRecords.begin(); i != _playbackFile->getHeader().settingsRecords.end(); ++i) {
Common::String currentValue = ConfMan.get(i->_key);
if (currentValue != i->_value) {
ConfMan.set(i->_key, i->_value, ConfMan.kTransientDomain);
debugC(1, kDebugLevelEventRec, "playback:action=\"Apply settings\" key=%s storedvalue=%s currentvalue=%s result=different", i->_key.c_str(), i->_value.c_str(), currentValue.c_str());
} else {
debugC(1, kDebugLevelEventRec, "playback:action=\"Apply settings\" key=%s storedvalue=%s currentvalue=%s result=equal", i->_key.c_str(), i->_value.c_str(), currentValue.c_str());
}
}
removeDifferentEntriesInDomain(ConfMan.getDomain(ConfMan.kApplicationDomain));
removeDifferentEntriesInDomain(ConfMan.getActiveDomain());
}
void EventRecorder::removeDifferentEntriesInDomain(Common::ConfigManager::Domain *domain) {
for (Common::ConfigManager::Domain::iterator entry = domain->begin(); entry!= domain->end(); ++entry) {
if (_playbackFile->getHeader().settingsRecords.find(entry->_key) == _playbackFile->getHeader().settingsRecords.end()) {
debugC(1, kDebugLevelEventRec, "playback:action=\"Apply settings\" checksettings:key=%s storedvalue=%s currentvalue="" result=different", entry->_key.c_str(), entry->_value.c_str());
domain->erase(entry->_key);
}
}
}
DefaultTimerManager *EventRecorder::getTimerManager() {
return _timerManager;
}
void EventRecorder::registerTimerManager(DefaultTimerManager *timerManager) {
_timerManager = timerManager;
}
void EventRecorder::switchTimerManagers() {
delete _timerManager;
if (_recordMode == kPassthrough) {
_timerManager = new SdlTimerManager();
} else {
_timerManager = new DefaultTimerManager();
}
}
void EventRecorder::updateSubsystems() {
if (_recordMode == kPassthrough) {
return;
}
RecordMode oldRecordMode = _recordMode;
_recordMode = kPassthrough;
_fakeMixerManager->update();
_recordMode = oldRecordMode;
}
Common::List<Common::Event> EventRecorder::mapEvent(const Common::Event &ev, Common::EventSource *source) {
if ((!_initialized) && (_recordMode != kRecorderPlaybackPause)) {
return DefaultEventMapper::mapEvent(ev, source);
}
checkForKeyCode(ev);
Common::Event evt = ev;
evt.mouse.x = evt.mouse.x * (g_system->getOverlayWidth() / g_system->getWidth());
evt.mouse.y = evt.mouse.y * (g_system->getOverlayHeight() / g_system->getHeight());
switch (_recordMode) {
case kRecorderPlayback:
if (ev.synthetic != true) {
return Common::List<Common::Event>();
}
return Common::DefaultEventMapper::mapEvent(ev, source);
break;
case kRecorderRecord:
g_gui.processEvent(evt, controlPanel);
if (((evt.type == Common::EVENT_LBUTTONDOWN) || (evt.type == Common::EVENT_LBUTTONUP) || (evt.type == Common::EVENT_MOUSEMOVE)) && controlPanel->isMouseOver()) {
return Common::List<Common::Event>();
} else {
Common::RecorderEvent e;
memcpy(&e, &ev, sizeof(ev));
e.recordedtype = Common::kRecorderEventTypeNormal;
e.time = _fakeTimer;
_playbackFile->writeEvent(e);
return DefaultEventMapper::mapEvent(ev, source);
}
break;
case kRecorderPlaybackPause: {
Common::Event dialogEvent;
if (controlPanel->isEditDlgVisible()) {
dialogEvent = ev;
} else {
dialogEvent = evt;
}
g_gui.processEvent(dialogEvent, controlPanel->getActiveDlg());
if (((dialogEvent.type == Common::EVENT_LBUTTONDOWN) || (dialogEvent.type == Common::EVENT_LBUTTONUP) || (dialogEvent.type == Common::EVENT_MOUSEMOVE)) && controlPanel->isMouseOver()) {
return Common::List<Common::Event>();
}
return Common::DefaultEventMapper::mapEvent(dialogEvent, source);
}
break;
default:
return Common::DefaultEventMapper::mapEvent(ev, source);
}
}
void EventRecorder::setGameMd5(const ADGameDescription *gameDesc) {
for (const ADGameFileDescription *fileDesc = gameDesc->filesDescriptions; fileDesc->fileName; fileDesc++) {
if (fileDesc->md5 != NULL) {
_playbackFile->getHeader().hashRecords[fileDesc->fileName] = fileDesc->md5;
}
}
}
void EventRecorder::processGameDescription(const ADGameDescription *desc) {
if (_recordMode == kRecorderRecord) {
setGameMd5(desc);
}
if ((_recordMode == kRecorderPlayback) && !checkGameHash(desc)) {
deinit();
error("playback:action=error reason=\"\"");
}
}
void EventRecorder::deleteRecord(const Common::String& fileName) {
g_system->getSavefileManager()->removeSavefile(fileName);
}
void EventRecorder::takeScreenshot() {
if ((_fakeTimer - _lastScreenshotTime) > _screenshotPeriod) {
Graphics::Surface screen;
uint8 md5[16];
if (grabScreenAndComputeMD5(screen, md5)) {
_lastScreenshotTime = _fakeTimer;
_playbackFile->saveScreenShot(screen, md5);
screen.free();
}
}
}
bool EventRecorder::grabScreenAndComputeMD5(Graphics::Surface &screen, uint8 md5[16]) {
if (!createScreenShot(screen)) {
warning("Can't save screenshot");
return false;
}
Common::MemoryReadStream bitmapStream((const byte*)screen.pixels, screen.w * screen.h * screen.format.bytesPerPixel);
computeStreamMD5(bitmapStream, md5);
return true;
}
Common::SeekableReadStream *EventRecorder::processSaveStream(const Common::String &fileName) {
Common::InSaveFile *saveFile;
switch (_recordMode) {
case kRecorderPlayback:
debugC(1, kDebugLevelEventRec, "playback:action=\"Process save file\" filename=%s len=%d", fileName.c_str(), _playbackFile->getHeader().saveFiles[fileName].size);
return new Common::MemoryReadStream(_playbackFile->getHeader().saveFiles[fileName].buffer, _playbackFile->getHeader().saveFiles[fileName].size);
case kRecorderRecord:
saveFile = _realSaveManager->openForLoading(fileName);
if (saveFile != NULL) {
_playbackFile->addSaveFile(fileName, saveFile);
saveFile->seek(0);
}
return saveFile;
default:
return NULL;
break;
}
}
Common::SaveFileManager *EventRecorder::getSaveManager(Common::SaveFileManager *realSaveManager) {
_realSaveManager = realSaveManager;
if (_recordMode != kPassthrough) {
return &_fakeSaveManager;
} else {
return realSaveManager;
}
}
void EventRecorder::preDrawOverlayGui() {
if ((_initialized) || (_needRedraw)) {
RecordMode oldMode = _recordMode;
_recordMode = kPassthrough;
g_system->showOverlay();
g_gui.theme()->clearAll();
g_gui.theme()->openDialog(true, GUI::ThemeEngine::kShadingNone);
controlPanel->drawDialog();
g_gui.theme()->finishBuffering();
g_gui.theme()->updateScreen();
_recordMode = oldMode;
}
}
void EventRecorder::postDrawOverlayGui() {
if ((_initialized) || (_needRedraw)) {
RecordMode oldMode = _recordMode;
_recordMode = kPassthrough;
g_system->hideOverlay();
_recordMode = oldMode;
}
}
Common::StringArray EventRecorder::listSaveFiles(const Common::String &pattern) {
if (_recordMode == kRecorderPlayback) {
Common::StringArray result;
for (Common::HashMap<Common::String, Common::PlaybackFile::SaveFileBuffer>::iterator i = _playbackFile->getHeader().saveFiles.begin(); i != _playbackFile->getHeader().saveFiles.end(); ++i) {
if (i->_key.matchString(pattern, false, true)) {
result.push_back(i->_key);
}
}
return result;
} else {
return _realSaveManager->listSavefiles(pattern);
}
}
void EventRecorder::setFileHeader() {
if (_recordMode != kRecorderRecord) {
return;
}
TimeDate t;
const EnginePlugin *plugin = 0;
GameDescriptor desc = EngineMan.findGame(ConfMan.getActiveDomainName(), &plugin);
g_system->getTimeAndDate(t);
if (_author.empty()) {
setAuthor("Unknown Author");
}
if (_name.empty()) {
g_eventRec.setName(Common::String::format("%.2d.%.2d.%.4d ", t.tm_mday, t.tm_mon, 1900 + t.tm_year) + desc.description());
}
_playbackFile->getHeader().author = _author;
_playbackFile->getHeader().notes = _desc;
_playbackFile->getHeader().name = _name;
}
SDL_Surface *EventRecorder::getSurface(int width, int height) {
// Create a RGB565 surface of the requested dimensions.
return SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 16, 0xF800, 0x07E0, 0x001F, 0x0000);
}
bool EventRecorder::switchMode() {
const Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0;
EngineMan.findGame(gameId, &plugin);
bool metaInfoSupport = (*plugin)->hasFeature(MetaEngine::kSavesSupportMetaInfo);
bool featuresSupport = metaInfoSupport &&
g_engine->canSaveGameStateCurrently() &&
(*plugin)->hasFeature(MetaEngine::kSupportsListSaves) &&
(*plugin)->hasFeature(MetaEngine::kSupportsDeleteSave);
if (!featuresSupport) {
return false;
}
int emptySlot = 1;
SaveStateList saveList = (*plugin)->listSaves(gameId.c_str());
for (SaveStateList::const_iterator x = saveList.begin(); x != saveList.end(); ++x) {
int saveSlot = x->getSaveSlot();
if (saveSlot == 0) {
continue;
}
if (emptySlot != saveSlot) {
break;
}
emptySlot++;
}
Common::String saveName;
if (emptySlot >= 0) {
saveName = Common::String::format("Save %d", emptySlot + 1);
Common::Error status = g_engine->saveGameState(emptySlot, saveName);
if (status.getCode() == Common::kNoError) {
Common::Event eventRTL;
eventRTL.type = Common::EVENT_RTL;
g_system->getEventManager()->pushEvent(eventRTL);
}
}
ConfMan.set("record_mode", "", Common::ConfigManager::kTransientDomain);
ConfMan.setInt("save_slot", emptySlot, Common::ConfigManager::kTransientDomain);
_needcontinueGame = true;
return true;
}
bool EventRecorder::checkForContinueGame() {
bool result = _needcontinueGame;
_needcontinueGame = false;
return result;
}
void EventRecorder::deleteTemporarySave() {
if (_temporarySlot == -1) return;
const Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0;
EngineMan.findGame(gameId, &plugin);
(*plugin)->removeSaveState(gameId.c_str(), _temporarySlot);
_temporarySlot = -1;
}
} // End of namespace GUI
#endif // ENABLE_EVENTRECORDER
|