# HG changeset patch # User Rubidium # Date 2024-01-15 19:58:24 # Node ID 67f4beeb903db9e607d907be9857a1e280c6b6da # Parent fc1bf0ee732996877d6e7f310ef72bbc9bf3dc1e Fix fbd71a9: for TTO savegames, getting the savegame type left the file pointing to the wrong location diff --git a/src/saveload/oldloader.cpp b/src/saveload/oldloader.cpp --- a/src/saveload/oldloader.cpp +++ b/src/saveload/oldloader.cpp @@ -225,16 +225,17 @@ static bool VerifyOldNameChecksum(char * static std::tuple DetermineOldSavegameTypeAndName(FILE *f) { + long pos = ftell(f); char buffer[std::max(TTO_HEADER_SIZE, TTD_HEADER_SIZE)]; - if (fread(buffer, 1, lengthof(buffer), f) != lengthof(buffer)) { + if (pos < 0 || fread(buffer, 1, lengthof(buffer), f) != lengthof(buffer)) { return { SGT_INVALID, "(broken) Unable to read file" }; } - if (VerifyOldNameChecksum(buffer, TTO_HEADER_SIZE)) { + if (VerifyOldNameChecksum(buffer, TTO_HEADER_SIZE) && fseek(f, pos + TTO_HEADER_SIZE, SEEK_SET) == 0) { return { SGT_TTO, "(TTO)" + StrMakeValid({buffer, TTO_HEADER_SIZE - HEADER_CHECKSUM_SIZE}) }; } - if (VerifyOldNameChecksum(buffer, TTD_HEADER_SIZE)) { + if (VerifyOldNameChecksum(buffer, TTD_HEADER_SIZE) && fseek(f, pos + TTD_HEADER_SIZE, SEEK_SET) == 0) { return { SGT_TTD, "(TTD)" + StrMakeValid({buffer, TTD_HEADER_SIZE - HEADER_CHECKSUM_SIZE}) }; } @@ -267,7 +268,9 @@ bool LoadOldSaveGame(const std::string & switch (type) { case SGT_TTO: proc = &LoadTTOMain; break; case SGT_TTD: proc = &LoadTTDMain; break; - default: break; + default: + Debug(oldloader, 0, "Unknown savegame type; cannot be loaded"); + break; } _savegame_type = type;