Permalink
Browse files

WINTERMUTE: Add FoxTail timestamp getting method

FoxTail requires Game.GetSaveSlotDescriptionTimestamp(idx) method to return a struct with save slot timestamp and description.
Wrote some crappy code I'm not proud of to support this...
  • Loading branch information...
lolbot-iichan committed Aug 26, 2018
1 parent 64868c0 commit b0ace0702d2806a621ad39af76eab7efe45db309
@@ -1357,6 +1357,45 @@ bool BaseGame::scCallMethod(ScScript *script, ScStack *stack, ScStack *thisStack
return STATUS_OK;
}

#ifdef ENABLE_FOXTAIL
//////////////////////////////////////////////////////////////////////////
// [FoxTail] GetSaveSlotDescriptionTimestamp
// Return struct with "Timestamp" and "Description" fields
// Timestamps should be comparable types
// Used to sort saved games by timestamps at save.script & load.script
//////////////////////////////////////////////////////////////////////////
else if (strcmp(name, "GetSaveSlotDescriptionTimestamp") == 0) {
stack->correctParams(1);
int slot = stack->pop()->getInt();

char desc[512];
desc[0] = '\0';
SaveLoad::getSaveSlotDescription(slot, desc);
stack->pushString(desc);

TimeDate time;
SaveLoad::getSaveSlotTimestamp(slot, &time);
stack->pushInt(time.tm_sec);
stack->pushInt(time.tm_min);
stack->pushInt(time.tm_hour);
stack->pushInt(time.tm_mday);
stack->pushInt(time.tm_mon+1);
stack->pushInt(time.tm_year+1900);
stack->pushInt(6);
BaseScriptable* date = makeSXDate(_gameRef, stack);
stack->pushNative(date, false);

stack->pushInt(0);
BaseScriptable* obj = makeSXObject(_gameRef, stack);
obj->scSetProperty("Timestamp", stack->pop());
obj->scSetProperty("Description", stack->pop());

stack->pushNative(obj, false);

return STATUS_OK;
}
#endif

//////////////////////////////////////////////////////////////////////////
// EmptySaveSlot
//////////////////////////////////////////////////////////////////////////
@@ -45,6 +45,7 @@ class BaseGame;
class BasePersistenceManager {
public:
char *_savedDescription;
TimeDate _savedTimestamp;
Common::String _savePrefix;
Common::String _savedName;
bool saveFile(const Common::String &filename);
@@ -102,7 +103,6 @@ class BasePersistenceManager {
bool putTimeDate(const TimeDate &t);
Common::WriteStream *_saveStream;
Common::SeekableReadStream *_loadStream;
TimeDate _savedTimestamp;
uint32 _savedPlayTime;
byte _savedVerMajor;
byte _savedVerMinor;
@@ -185,6 +185,29 @@ bool SaveLoad::getSaveSlotDescription(int slot, char *buffer) {
return true;
}

#ifdef ENABLE_FOXTAIL
bool SaveLoad::getSaveSlotTimestamp(int slot, TimeDate *time) {
memset(time, 0, sizeof(TimeDate));

Common::String filename = getSaveSlotFilename(slot);
BasePersistenceManager *pm = new BasePersistenceManager();
if (!pm) {
return false;
}

if (!(pm->initLoad(filename))) {
delete pm;
return false;
}

const TimeDate* timestamp = &(pm->_savedTimestamp);
memcpy(time, timestamp, sizeof(TimeDate));
delete pm;

return true;
}
#endif

bool SaveLoad::isSaveSlotUsed(int slot) {
Common::String filename = getSaveSlotFilename(slot);
BasePersistenceManager *pm = new BasePersistenceManager();
@@ -38,6 +38,9 @@ class SaveLoad {
static bool emptySaveSlot(int slot);
static bool isSaveSlotUsed(int slot);
static bool getSaveSlotDescription(int slot, char *buffer);
#ifdef ENABLE_FOXTAIL
static bool getSaveSlotTimestamp(int slot, TimeDate *time);
#endif
static Common::String getSaveSlotFilename(int slot);

static bool loadGame(const Common::String &filename, BaseGame *gameRef);

0 comments on commit b0ace07

Please sign in to comment.