PointerWrapSection PointerWrap::Section(const char *title, int minVer, int ver) { char marker[16] = {0}; int foundVersion = ver; // This is strncpy because we rely on its weird non-null-terminating truncation behaviour. // Can't replace it with the more sensible truncate_cpy because that would break savestates. strncpy(marker, title, sizeof(marker)); if (!ExpectVoid(marker, sizeof(marker))) { // Might be before we added name markers for safety. if (foundVersion == 1 && ExpectVoid(&foundVersion, sizeof(foundVersion))) DoMarker(title); // Wasn't found, but maybe we can still load the state. else foundVersion = 0; } else Do(foundVersion); if (error == ERROR_FAILURE || foundVersion < minVer || foundVersion > ver) { WARN_LOG(SAVESTATE, "Savestate failure: wrong version %d found for %s", foundVersion, title); SetError(ERROR_FAILURE); return PointerWrapSection(*this, -1, title); } return PointerWrapSection(*this, foundVersion, title); }
PointerWrapSection PointerWrap::Section(const char *title, int minVer, int ver) { char marker[16] = {0}; int foundVersion = ver; strncpy(marker, title, sizeof(marker)); if (!ExpectVoid(marker, sizeof(marker))) { // Might be before we added name markers for safety. if (foundVersion == 1 && ExpectVoid(&foundVersion, sizeof(foundVersion))) DoMarker(title); // Wasn't found, but maybe we can still load the state. else foundVersion = 0; } else Do(foundVersion); if (error == ERROR_FAILURE || foundVersion < minVer || foundVersion > ver) { WARN_LOG(COMMON, "Savestate failure: wrong version %d found for %s", foundVersion, title); SetError(ERROR_FAILURE); return PointerWrapSection(*this, -1, title); } return PointerWrapSection(*this, foundVersion, title); }
void PointerWrap::Do(tm &t) { // We savestate this separately because some platforms use extra data at the end. // However, old files may have the native tm in them. // Since the first value in the struct is 0-59, we save a funny value and check for it. // If our funny value ('tm' 0x1337) exists, it's a new version savestate. int funnyValue = 0x13376D74; if (ExpectVoid(&funnyValue, sizeof(funnyValue))) { standard_tm stm; if (mode == MODE_READ) { // Null out the extra members, e.g. tm_gmtoff or tm_zone. memset(&t, 0, sizeof(t)); } else { memcpy(&stm, &t, sizeof(stm)); } DoVoid((void *)&stm, sizeof(stm)); memcpy(&t, &stm, sizeof(stm)); } else { DoVoid((void *)&t, sizeof(t)); } }