24 #include "../stdafx.h"
26 #include "../station_base.h"
27 #include "../thread/thread.h"
29 #include "../network/network.h"
30 #include "../window_func.h"
31 #include "../strings_func.h"
32 #include "../core/endian_func.hpp"
33 #include "../vehicle_base.h"
34 #include "../company_func.h"
35 #include "../date_func.h"
36 #include "../autoreplace_base.h"
37 #include "../roadstop_base.h"
38 #include "../linkgraph/linkgraph.h"
39 #include "../linkgraph/linkgraphjob.h"
40 #include "../statusbar_gui.h"
41 #include "../fileio_func.h"
42 #include "../gamelog.h"
43 #include "../string_func.h"
47 #include "table/strings.h"
52 #include "../safeguards.h"
313 inline byte ReadByte()
324 return *this->
bufp++;
447 extern const ChunkHandler _autoreplace_chunk_handlers[];
452 extern const ChunkHandler _persistent_storage_chunk_handlers[];
456 _gamelog_chunk_handlers,
458 _misc_chunk_handlers,
459 _name_chunk_handlers,
460 _cheat_chunk_handlers,
461 _setting_chunk_handlers,
463 _waypoint_chunk_handlers,
464 _depot_chunk_handlers,
465 _order_chunk_handlers,
466 _industry_chunk_handlers,
467 _economy_chunk_handlers,
468 _subsidy_chunk_handlers,
469 _cargomonitor_chunk_handlers,
470 _goal_chunk_handlers,
471 _story_page_chunk_handlers,
472 _engine_chunk_handlers,
473 _town_chunk_handlers,
474 _sign_chunk_handlers,
475 _station_chunk_handlers,
476 _company_chunk_handlers,
478 _game_chunk_handlers,
479 _animated_tile_chunk_handlers,
480 _newgrf_chunk_handlers,
481 _group_chunk_handlers,
482 _cargopacket_chunk_handlers,
483 _autoreplace_chunk_handlers,
484 _labelmaps_chunk_handlers,
485 _linkgraph_chunk_handlers,
486 _airport_chunk_handlers,
487 _object_chunk_handlers,
488 _persistent_storage_chunk_handlers,
496 #define FOR_ALL_CHUNK_HANDLERS(ch) \
497 for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != NULL; chsc++) \
498 for (const ChunkHandler *ch = *chsc; ch != NULL; ch = (ch->flags & CH_LAST) ? NULL : ch + 1)
510 DEBUG(sl, 1,
"Nulling pointers");
513 if (ch->ptrs_proc != NULL) {
514 DEBUG(sl, 2,
"Nulling pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
519 DEBUG(sl, 1,
"All pointers nulled");
550 throw std::exception();
562 SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, msg);
576 if (_exit_game)
return;
577 while (_async_save_finish != NULL) CSleep(10);
579 _async_save_finish = proc;
587 if (_async_save_finish == NULL)
return;
591 _async_save_finish = NULL;
593 if (_save_thread != NULL) {
594 _save_thread->
Join();
606 return _sl.
reader->ReadByte();
618 static inline int SlReadUint16()
624 static inline uint32 SlReadUint32()
626 uint32 x = SlReadUint16() << 16;
627 return x | SlReadUint16();
630 static inline uint64 SlReadUint64()
632 uint32 x = SlReadUint32();
633 uint32 y = SlReadUint32();
634 return (uint64)x << 32 | y;
637 static inline void SlWriteUint16(uint16 v)
643 static inline void SlWriteUint32(uint32 v)
645 SlWriteUint16(
GB(v, 16, 16));
646 SlWriteUint16(
GB(v, 0, 16));
649 static inline void SlWriteUint64(uint64 x)
651 SlWriteUint32((uint32)(x >> 32));
652 SlWriteUint32((uint32)x);
719 if (i >= (1 << 14)) {
720 if (i >= (1 << 21)) {
721 if (i >= (1 << 28)) {
722 assert(i <= UINT32_MAX);
743 return 1 + (i >= (1 << 7)) + (i >= (1 << 14)) + (i >= (1 << 21)) + (i >= (1 << 28));
746 static inline uint SlReadSparseIndex()
751 static inline void SlWriteSparseIndex(uint index)
756 static inline uint SlReadArrayLength()
761 static inline void SlWriteArrayLength(
size_t length)
766 static inline uint SlGetArrayLength(
size_t length)
779 static const byte conv_mem_size[] = {1, 1, 1, 2, 2, 4, 4, 8, 8, 0};
780 byte length =
GB(conv, 4, 4);
782 switch (length << 4) {
787 return SlReadArrayLength();
790 assert(length <
lengthof(conv_mem_size));
791 return conv_mem_size[length];
803 static const byte conv_file_size[] = {1, 1, 2, 2, 4, 4, 8, 8, 2};
804 byte length =
GB(conv, 0, 4);
805 assert(length <
lengthof(conv_file_size));
806 return conv_file_size[length];
815 void SlSetArrayIndex(uint index)
818 _sl.array_index = index;
821 static size_t _next_offs;
836 uint length = SlReadArrayLength();
846 case CH_SPARSE_ARRAY: index = (int)SlReadSparseIndex();
break;
847 case CH_ARRAY: index = _sl.array_index++;
break;
849 DEBUG(sl, 0,
"SlIterateArray error");
853 if (length != 0)
return index;
884 assert(length < (1 << 28));
885 SlWriteUint32((uint32)((length & 0xFFFFFF) | ((length >> 24) << 28)));
890 SlWriteArrayLength(1);
892 SlWriteArrayLength(length + 1);
894 case CH_SPARSE_ARRAY:
895 SlWriteArrayLength(length + 1 + SlGetArrayLength(_sl.array_index));
896 SlWriteSparseIndex(_sl.array_index);
898 default: NOT_REACHED();
906 default: NOT_REACHED();
918 byte *p = (byte *)ptr;
923 for (; length != 0; length--) *p++ =
SlReadByte();
928 default: NOT_REACHED();
948 case SLE_VAR_BL:
return (*(
const bool *)ptr != 0);
949 case SLE_VAR_I8:
return *(
const int8 *)ptr;
950 case SLE_VAR_U8:
return *(
const byte *)ptr;
951 case SLE_VAR_I16:
return *(
const int16 *)ptr;
952 case SLE_VAR_U16:
return *(
const uint16*)ptr;
953 case SLE_VAR_I32:
return *(
const int32 *)ptr;
954 case SLE_VAR_U32:
return *(
const uint32*)ptr;
955 case SLE_VAR_I64:
return *(
const int64 *)ptr;
956 case SLE_VAR_U64:
return *(
const uint64*)ptr;
958 default: NOT_REACHED();
972 case SLE_VAR_BL: *(
bool *)ptr = (val != 0);
break;
973 case SLE_VAR_I8: *(int8 *)ptr = val;
break;
974 case SLE_VAR_U8: *(byte *)ptr = val;
break;
975 case SLE_VAR_I16: *(int16 *)ptr = val;
break;
976 case SLE_VAR_U16: *(uint16*)ptr = val;
break;
977 case SLE_VAR_I32: *(int32 *)ptr = val;
break;
978 case SLE_VAR_U32: *(uint32*)ptr = val;
break;
979 case SLE_VAR_I64: *(int64 *)ptr = val;
break;
980 case SLE_VAR_U64: *(uint64*)ptr = val;
break;
983 default: NOT_REACHED();
1003 case SLE_FILE_I8: assert(x >= -128 && x <= 127);
SlWriteByte(x);
break;
1004 case SLE_FILE_U8: assert(x >= 0 && x <= 255);
SlWriteByte(x);
break;
1005 case SLE_FILE_I16:assert(x >= -32768 && x <= 32767); SlWriteUint16(x);
break;
1007 case SLE_FILE_U16:assert(x >= 0 && x <= 65535); SlWriteUint16(x);
break;
1009 case SLE_FILE_U32: SlWriteUint32((uint32)x);
break;
1011 case SLE_FILE_U64: SlWriteUint64(x);
break;
1012 default: NOT_REACHED();
1021 case SLE_FILE_I8: x = (int8 )
SlReadByte();
break;
1022 case SLE_FILE_U8: x = (byte )
SlReadByte();
break;
1023 case SLE_FILE_I16: x = (int16 )SlReadUint16();
break;
1024 case SLE_FILE_U16: x = (uint16)SlReadUint16();
break;
1025 case SLE_FILE_I32: x = (int32 )SlReadUint32();
break;
1026 case SLE_FILE_U32: x = (uint32)SlReadUint32();
break;
1027 case SLE_FILE_I64: x = (int64 )SlReadUint64();
break;
1028 case SLE_FILE_U64: x = (uint64)SlReadUint64();
break;
1030 default: NOT_REACHED();
1039 default: NOT_REACHED();
1054 if (ptr == NULL)
return 0;
1055 return min(strlen(ptr), length - 1);
1073 default: NOT_REACHED();
1076 str = *(
const char *
const *)ptr;
1081 str = (
const char *)ptr;
1087 return len + SlGetArrayLength(len);
1096 static void SlString(
void *ptr,
size_t length, VarType conv)
1102 default: NOT_REACHED();
1109 ptr = *(
char **)ptr;
1114 SlWriteArrayLength(len);
1120 size_t len = SlReadArrayLength();
1123 default: NOT_REACHED();
1126 if (len >= length) {
1127 DEBUG(sl, 1,
"String length in savegame is bigger than buffer, truncating");
1137 free(*(
char **)ptr);
1139 *(
char **)ptr = NULL;
1142 *(
char **)ptr = MallocT<char>(len + 1);
1143 ptr = *(
char **)ptr;
1149 ((
char *)ptr)[len] =
'\0';
1160 str_validate((
char *)ptr, (
char *)ptr + len, settings);
1165 default: NOT_REACHED();
1185 void SlArray(
void *array,
size_t length, VarType conv)
1200 if (conv == SLE_INT16 || conv == SLE_UINT16 || conv == SLE_STRINGID ||
1201 conv == SLE_INT32 || conv == SLE_UINT32) {
1206 if (conv == (SLE_FILE_I32 | SLE_VAR_I64)) {
1207 for (uint i = 0; i < length; i++) {
1208 ((int64*)array)[i] = (int32)
BSWAP32(SlReadUint32());
1216 if (conv == SLE_INT8 || conv == SLE_UINT8) {
1219 byte *a = (byte*)array;
1222 for (; length != 0; length --) {
1244 if (obj == NULL)
return 0;
1259 default: NOT_REACHED();
1275 assert_compile(
sizeof(
size_t) <=
sizeof(
void *));
1340 default: NOT_REACHED();
1350 const std::list<void *> *l = (
const std::list<void *> *) list;
1355 return l->size() * type_size + type_size;
1373 typedef std::list<void *> PtrList;
1374 PtrList *l = (PtrList *)list;
1378 SlWriteUint32((uint32)l->size());
1380 PtrList::iterator iter;
1381 for (iter = l->begin(); iter != l->end(); ++iter) {
1392 for (
size_t i = 0; i < length; i++) {
1394 l->push_back((
void *)data);
1402 PtrList::iterator iter;
1403 for (iter = temp.begin(); iter != temp.end(); ++iter) {
1412 default: NOT_REACHED();
1452 for (; sld->
cmd != SL_END; sld++) {
1453 length += SlCalcObjMemberLength(
object, sld);
1458 size_t SlCalcObjMemberLength(
const void *
object,
const SaveLoad *sld)
1477 default: NOT_REACHED();
1480 case SL_WRITEBYTE:
return 1;
1483 default: NOT_REACHED();
1501 return sld->
size ==
sizeof(bool);
1504 return sld->
size ==
sizeof(int8);
1507 return sld->
size ==
sizeof(int16);
1510 return sld->
size ==
sizeof(int32);
1513 return sld->
size ==
sizeof(int64);
1515 return sld->
size ==
sizeof(
void *);
1519 return sld->
size ==
sizeof(
void *);
1532 bool SlObjectMember(
void *ptr,
const SaveLoad *sld)
1538 VarType conv =
GB(sld->
conv, 0, 8);
1564 *(
void **)ptr = NULL;
1566 default: NOT_REACHED();
1572 default: NOT_REACHED();
1588 default: NOT_REACHED();
1593 case SL_VEH_INCLUDE:
1601 default: NOT_REACHED();
1619 for (; sld->
cmd != SL_END; sld++) {
1621 SlObjectMember(ptr, sld);
1677 _sl.array_index = 0;
1681 case CH_SPARSE_ARRAY:
1686 if ((m & 0xF) == CH_RIFF) {
1688 len = (
SlReadByte() << 16) | ((m >> 4) << 24);
1689 len += SlReadUint16();
1717 _sl.array_index = 0;
1724 case CH_SPARSE_ARRAY:
1732 if ((m & 0xF) == CH_RIFF) {
1734 len = (
SlReadByte() << 16) | ((m >> 4) << 24);
1735 len += SlReadUint16();
1784 ChunkSaveLoadProc *proc = ch->
save_proc;
1787 if (proc == NULL)
return;
1789 SlWriteUint32(ch->
id);
1790 DEBUG(sl, 2,
"Saving chunk %c%c%c%c", ch->
id >> 24, ch->
id >> 16, ch->
id >> 8, ch->
id);
1792 if (ch->
flags & CH_AUTO_LENGTH) {
1794 _stub_save_proc = proc;
1799 switch (ch->
flags & CH_TYPE_MASK) {
1808 SlWriteArrayLength(0);
1810 case CH_SPARSE_ARRAY:
1813 SlWriteArrayLength(0);
1815 default: NOT_REACHED();
1848 for (
id = SlReadUint32();
id != 0;
id = SlReadUint32()) {
1849 DEBUG(sl, 2,
"Loading chunk %c%c%c%c",
id >> 24,
id >> 16,
id >> 8,
id);
1863 for (
id = SlReadUint32();
id != 0;
id = SlReadUint32()) {
1864 DEBUG(sl, 2,
"Loading chunk %c%c%c%c",
id >> 24,
id >> 16,
id >> 8,
id);
1877 DEBUG(sl, 1,
"Fixing pointers");
1880 if (ch->ptrs_proc != NULL) {
1881 DEBUG(sl, 2,
"Fixing pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
1886 DEBUG(sl, 1,
"All pointers fixed");
1908 if (this->
file != NULL) fclose(this->
file);
1915 size_t Read(byte *buf,
size_t size)
1918 if (this->
file == NULL)
return 0;
1920 return fread(buf, 1, size, this->
file);
1925 clearerr(this->
file);
1926 if (fseek(this->
file, this->
begin, SEEK_SET)) {
1927 DEBUG(sl, 1,
"Could not reset the file reading");
1956 if (this->
file == NULL)
return;
1958 if (fwrite(buf, 1, size, this->
file) != size)
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
1963 if (this->
file != NULL) fclose(this->
file);
1973 #include <lzo/lzo1x.h>
1986 if (lzo_init() != LZO_E_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize decompressor");
1989 size_t Read(byte *buf,
size_t ssize)
1991 assert(ssize >= LZO_BUFFER_SIZE);
1994 byte out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 +
sizeof(uint32) * 2];
1997 lzo_uint len = ssize;
2000 if (this->
chain->
Read((byte*)tmp,
sizeof(tmp)) !=
sizeof(tmp))
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE,
"File read failed");
2003 ((uint32*)out)[0] = size = tmp[1];
2006 tmp[0] = TO_BE32(tmp[0]);
2007 size = TO_BE32(size);
2013 if (this->
chain->
Read(out +
sizeof(uint32), size) != size)
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2016 if (tmp[0] != lzo_adler32(0, out, size +
sizeof(uint32)))
SlErrorCorrupt(
"Bad checksum");
2019 int ret = lzo1x_decompress_safe(out +
sizeof(uint32) * 1, size, buf, &len, NULL);
2020 if (ret != LZO_E_OK)
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2034 if (lzo_init() != LZO_E_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize compressor");
2039 const lzo_bytep in = buf;
2041 byte out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 +
sizeof(uint32) * 2];
2042 byte wrkmem[LZO1X_1_MEM_COMPRESS];
2047 lzo_uint len = size > LZO_BUFFER_SIZE ? LZO_BUFFER_SIZE : (lzo_uint)size;
2048 lzo1x_1_compress(in, len, out +
sizeof(uint32) * 2, &outlen, wrkmem);
2049 ((uint32*)out)[1] = TO_BE32((uint32)outlen);
2050 ((uint32*)out)[0] = TO_BE32(lzo_adler32(0, out +
sizeof(uint32), outlen +
sizeof(uint32)));
2051 this->
chain->
Write(out, outlen +
sizeof(uint32) * 2);
2076 size_t Read(byte *buf,
size_t size)
2103 #if defined(WITH_ZLIB)
2117 memset(&this->
z, 0,
sizeof(this->
z));
2118 if (inflateInit(&this->
z) != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize decompressor");
2124 inflateEnd(&this->
z);
2127 size_t Read(byte *buf,
size_t size)
2129 this->
z.next_out = buf;
2130 this->
z.avail_out = (uint)size;
2134 if (this->
z.avail_in == 0) {
2136 this->
z.avail_in = (uint)this->
chain->
Read(this->fread_buf,
sizeof(this->fread_buf));
2140 int r = inflate(&this->
z, 0);
2141 if (r == Z_STREAM_END)
break;
2143 if (r != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"inflate() failed");
2144 }
while (this->
z.avail_out != 0);
2146 return size - this->
z.avail_out;
2161 memset(&this->
z, 0,
sizeof(this->
z));
2162 if (deflateInit(&this->
z, compression_level) != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize compressor");
2168 deflateEnd(&this->
z);
2181 this->
z.next_in = p;
2182 this->
z.avail_in = (uInt)len;
2184 this->
z.next_out = buf;
2185 this->
z.avail_out =
sizeof(buf);
2194 int r = deflate(&this->
z, mode);
2197 if ((n =
sizeof(buf) - this->
z.avail_out) != 0) {
2200 if (r == Z_STREAM_END)
break;
2202 if (r != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"zlib returned error code");
2203 }
while (this->
z.avail_in || !this->z.avail_out);
2224 #if defined(WITH_LZMA)
2247 if (lzma_auto_decoder(&this->
lzma, 1 << 28, 0) != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize decompressor");
2253 lzma_end(&this->
lzma);
2256 size_t Read(byte *buf,
size_t size)
2258 this->
lzma.next_out = buf;
2259 this->
lzma.avail_out = size;
2263 if (this->
lzma.avail_in == 0) {
2269 lzma_ret r = lzma_code(&this->
lzma, LZMA_RUN);
2270 if (r == LZMA_STREAM_END)
break;
2271 if (r != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"liblzma returned error code");
2272 }
while (this->
lzma.avail_out != 0);
2274 return size - this->
lzma.avail_out;
2289 if (lzma_easy_encoder(&this->
lzma, compression_level, LZMA_CHECK_CRC32) != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize compressor");
2295 lzma_end(&this->
lzma);
2308 this->
lzma.next_in = p;
2309 this->
lzma.avail_in = len;
2311 this->
lzma.next_out = buf;
2312 this->
lzma.avail_out =
sizeof(buf);
2314 lzma_ret r = lzma_code(&this->
lzma, action);
2317 if ((n =
sizeof(buf) - this->
lzma.avail_out) != 0) {
2320 if (r == LZMA_STREAM_END)
break;
2321 if (r != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"liblzma returned error code");
2322 }
while (this->
lzma.avail_in || !this->lzma.avail_out);
2358 #if defined(WITH_LZO)
2360 {
"lzo", TO_BE32X(
'OTTD'), CreateLoadFilter<LZOLoadFilter>, CreateSaveFilter<LZOSaveFilter>, 0, 0, 0},
2362 {
"lzo", TO_BE32X(
'OTTD'), NULL, NULL, 0, 0, 0},
2365 {
"none", TO_BE32X(
'OTTN'), CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0},
2366 #if defined(WITH_ZLIB)
2370 {
"zlib", TO_BE32X(
'OTTZ'), CreateLoadFilter<ZlibLoadFilter>, CreateSaveFilter<ZlibSaveFilter>, 0, 6, 9},
2372 {
"zlib", TO_BE32X(
'OTTZ'), NULL, NULL, 0, 0, 0},
2374 #if defined(WITH_LZMA)
2380 {
"lzma", TO_BE32X(
'OTTX'), CreateLoadFilter<LZMALoadFilter>, CreateSaveFilter<LZMASaveFilter>, 0, 2, 9},
2382 {
"lzma", TO_BE32X(
'OTTX'), NULL, NULL, 0, 0, 0},
2402 char *complevel = strrchr(s,
':');
2403 if (complevel != NULL) *complevel =
'\0';
2405 for (
const SaveLoadFormat *slf = &_saveload_formats[0]; slf !=
endof(_saveload_formats); slf++) {
2406 if (slf->init_write != NULL && strcmp(s, slf->name) == 0) {
2407 *compression_level = slf->default_compression;
2408 if (complevel != NULL) {
2417 long level = strtol(complevel, &end, 10);
2418 if (end == complevel || level !=
Clamp(level, slf->min_compression, slf->max_compression)) {
2422 *compression_level = level;
2434 if (complevel != NULL) *complevel =
':';
2441 void InitializeGame(uint size_x, uint size_y,
bool reset_date,
bool reset_settings);
2443 extern bool LoadOldSaveGame(
const char *file);
2481 if (_game_mode != GM_MENU) _fast_forward = _sl.
ff_state;
2500 static char err_str[512];
2501 GetString(err_str, _sl.
action ==
SLA_SAVE ? STR_ERROR_GAME_SAVE_FAILED : STR_ERROR_GAME_LOAD_FAILED,
lastof(err_str));
2525 _sl.
sf->
Write((byte*)hdr,
sizeof(hdr));
2542 if (_sl.
error_str != STR_NETWORK_ERROR_LOSTCONNECTION) {
2563 void WaitTillSaved()
2565 if (_save_thread == NULL)
return;
2567 _save_thread->
Join();
2569 _save_thread = NULL;
2592 SaveViewportBeforeSaveGame();
2597 if (threaded)
DEBUG(sl, 1,
"Cannot create savegame thread, reverting to single-threaded mode...");
2618 return DoSave(writer, threaded);
2643 if (_sl.
lf->
Read((byte*)hdr,
sizeof(hdr)) !=
sizeof(hdr))
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2649 if (fmt ==
endof(_saveload_formats)) {
2650 DEBUG(sl, 0,
"Unknown savegame type, trying to load it as the buggy format");
2658 if (fmt ==
endof(_saveload_formats)) {
2662 if (fmt->
tag == TO_BE32X(
'OTTD'))
break;
2668 if (fmt->
tag == hdr[0]) {
2690 SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, err_str);
2701 InitializeGame(256, 256,
true,
true);
2773 return DoLoad(reader,
false);
2802 InitializeGame(256, 256,
true,
true);
2810 if (!LoadOldSaveGame(filename))
return SL_REINIT;
2836 default: NOT_REACHED();
2847 SlError(fop ==
SLO_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2859 DEBUG(desync, 1,
"load: %s", filename);
2892 FOR_ALL_COMPANIES(c) {
2902 case 0:
SetDParam(1, STR_JUST_DATE_LONG);
break;
2903 case 1:
SetDParam(1, STR_JUST_DATE_TINY);
break;
2904 case 2:
SetDParam(1, STR_JUST_DATE_ISO);
break;
2905 default: NOT_REACHED();
2910 GetString(buf, !
Company::IsValidID(cid) ? STR_SAVEGAME_NAME_SPECTATOR : STR_SAVEGAME_NAME_DEFAULT, last);
2968 int GetSavegameType(
char *file)
2973 int mode = SL_OLD_LOAD;
2975 f = fopen(file,
"rb");
2976 if (fread(&hdr,
sizeof(hdr), 1, f) != 1) {
2977 DEBUG(sl, 0,
"Savegame is obsolete or invalid format");
2981 for (fmt = _saveload_formats; fmt !=
endof(_saveload_formats); fmt++) {
2982 if (fmt->
tag == hdr) {