Skip to content

Commit

Permalink
Fix fbd71a9: for TTO savegames, getting the savegame type left the fi…
Browse files Browse the repository at this point in the history
…le pointing to the wrong location
  • Loading branch information
rubidium42 committed Jan 15, 2024
1 parent d5518f6 commit f997935
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/saveload/oldloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,17 @@ static bool VerifyOldNameChecksum(char *title, uint len)

static std::tuple<SavegameType, std::string> 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}) };
}

Expand Down Expand Up @@ -267,7 +268,9 @@ bool LoadOldSaveGame(const std::string &file)
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;
Expand Down

0 comments on commit f997935

Please sign in to comment.