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"
311 inline byte ReadByte()
322 return *this->
bufp++;
445 extern const ChunkHandler _autoreplace_chunk_handlers[];
450 extern const ChunkHandler _persistent_storage_chunk_handlers[];
454 _gamelog_chunk_handlers,
456 _misc_chunk_handlers,
457 _name_chunk_handlers,
458 _cheat_chunk_handlers,
459 _setting_chunk_handlers,
461 _waypoint_chunk_handlers,
462 _depot_chunk_handlers,
463 _order_chunk_handlers,
464 _industry_chunk_handlers,
465 _economy_chunk_handlers,
466 _subsidy_chunk_handlers,
467 _cargomonitor_chunk_handlers,
468 _goal_chunk_handlers,
469 _story_page_chunk_handlers,
470 _engine_chunk_handlers,
471 _town_chunk_handlers,
472 _sign_chunk_handlers,
473 _station_chunk_handlers,
474 _company_chunk_handlers,
476 _game_chunk_handlers,
477 _animated_tile_chunk_handlers,
478 _newgrf_chunk_handlers,
479 _group_chunk_handlers,
480 _cargopacket_chunk_handlers,
481 _autoreplace_chunk_handlers,
482 _labelmaps_chunk_handlers,
483 _linkgraph_chunk_handlers,
484 _airport_chunk_handlers,
485 _object_chunk_handlers,
486 _persistent_storage_chunk_handlers,
494 #define FOR_ALL_CHUNK_HANDLERS(ch) \
495 for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != NULL; chsc++) \
496 for (const ChunkHandler *ch = *chsc; ch != NULL; ch = (ch->flags & CH_LAST) ? NULL : ch + 1)
508 DEBUG(sl, 1,
"Nulling pointers");
511 if (ch->ptrs_proc != NULL) {
512 DEBUG(sl, 2,
"Nulling pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
517 DEBUG(sl, 1,
"All pointers nulled");
548 throw std::exception();
560 SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, msg);
574 if (_exit_game)
return;
575 while (_async_save_finish != NULL) CSleep(10);
577 _async_save_finish = proc;
585 if (_async_save_finish == NULL)
return;
589 _async_save_finish = NULL;
591 if (_save_thread != NULL) {
592 _save_thread->
Join();
604 return _sl.
reader->ReadByte();
616 static inline int SlReadUint16()
622 static inline uint32 SlReadUint32()
624 uint32 x = SlReadUint16() << 16;
625 return x | SlReadUint16();
628 static inline uint64 SlReadUint64()
630 uint32 x = SlReadUint32();
631 uint32 y = SlReadUint32();
632 return (uint64)x << 32 | y;
635 static inline void SlWriteUint16(uint16 v)
641 static inline void SlWriteUint32(uint32 v)
643 SlWriteUint16(
GB(v, 16, 16));
644 SlWriteUint16(
GB(v, 0, 16));
647 static inline void SlWriteUint64(uint64 x)
649 SlWriteUint32((uint32)(x >> 32));
650 SlWriteUint32((uint32)x);
717 if (i >= (1 << 14)) {
718 if (i >= (1 << 21)) {
719 if (i >= (1 << 28)) {
720 assert(i <= UINT32_MAX);
741 return 1 + (i >= (1 << 7)) + (i >= (1 << 14)) + (i >= (1 << 21)) + (i >= (1 << 28));
744 static inline uint SlReadSparseIndex()
749 static inline void SlWriteSparseIndex(uint index)
754 static inline uint SlReadArrayLength()
759 static inline void SlWriteArrayLength(
size_t length)
764 static inline uint SlGetArrayLength(
size_t length)
777 static const byte conv_mem_size[] = {1, 1, 1, 2, 2, 4, 4, 8, 8, 0};
778 byte length =
GB(conv, 4, 4);
780 switch (length << 4) {
785 return SlReadArrayLength();
788 assert(length <
lengthof(conv_mem_size));
789 return conv_mem_size[length];
801 static const byte conv_file_size[] = {1, 1, 2, 2, 4, 4, 8, 8, 2};
802 byte length =
GB(conv, 0, 4);
803 assert(length <
lengthof(conv_file_size));
804 return conv_file_size[length];
813 void SlSetArrayIndex(uint index)
816 _sl.array_index = index;
819 static size_t _next_offs;
834 uint length = SlReadArrayLength();
844 case CH_SPARSE_ARRAY: index = (int)SlReadSparseIndex();
break;
845 case CH_ARRAY: index = _sl.array_index++;
break;
847 DEBUG(sl, 0,
"SlIterateArray error");
851 if (length != 0)
return index;
882 assert(length < (1 << 28));
883 SlWriteUint32((uint32)((length & 0xFFFFFF) | ((length >> 24) << 28)));
888 SlWriteArrayLength(1);
890 SlWriteArrayLength(length + 1);
892 case CH_SPARSE_ARRAY:
893 SlWriteArrayLength(length + 1 + SlGetArrayLength(_sl.array_index));
894 SlWriteSparseIndex(_sl.array_index);
896 default: NOT_REACHED();
904 default: NOT_REACHED();
916 byte *p = (byte *)ptr;
921 for (; length != 0; length--) *p++ =
SlReadByte();
926 default: NOT_REACHED();
946 case SLE_VAR_BL:
return (*(
const bool *)ptr != 0);
947 case SLE_VAR_I8:
return *(
const int8 *)ptr;
948 case SLE_VAR_U8:
return *(
const byte *)ptr;
949 case SLE_VAR_I16:
return *(
const int16 *)ptr;
950 case SLE_VAR_U16:
return *(
const uint16*)ptr;
951 case SLE_VAR_I32:
return *(
const int32 *)ptr;
952 case SLE_VAR_U32:
return *(
const uint32*)ptr;
953 case SLE_VAR_I64:
return *(
const int64 *)ptr;
954 case SLE_VAR_U64:
return *(
const uint64*)ptr;
956 default: NOT_REACHED();
970 case SLE_VAR_BL: *(
bool *)ptr = (val != 0);
break;
971 case SLE_VAR_I8: *(int8 *)ptr = val;
break;
972 case SLE_VAR_U8: *(byte *)ptr = val;
break;
973 case SLE_VAR_I16: *(int16 *)ptr = val;
break;
974 case SLE_VAR_U16: *(uint16*)ptr = val;
break;
975 case SLE_VAR_I32: *(int32 *)ptr = val;
break;
976 case SLE_VAR_U32: *(uint32*)ptr = val;
break;
977 case SLE_VAR_I64: *(int64 *)ptr = val;
break;
978 case SLE_VAR_U64: *(uint64*)ptr = val;
break;
981 default: NOT_REACHED();
1001 case SLE_FILE_I8: assert(x >= -128 && x <= 127);
SlWriteByte(x);
break;
1002 case SLE_FILE_U8: assert(x >= 0 && x <= 255);
SlWriteByte(x);
break;
1003 case SLE_FILE_I16:assert(x >= -32768 && x <= 32767); SlWriteUint16(x);
break;
1005 case SLE_FILE_U16:assert(x >= 0 && x <= 65535); SlWriteUint16(x);
break;
1007 case SLE_FILE_U32: SlWriteUint32((uint32)x);
break;
1009 case SLE_FILE_U64: SlWriteUint64(x);
break;
1010 default: NOT_REACHED();
1019 case SLE_FILE_I8: x = (int8 )
SlReadByte();
break;
1020 case SLE_FILE_U8: x = (byte )
SlReadByte();
break;
1021 case SLE_FILE_I16: x = (int16 )SlReadUint16();
break;
1022 case SLE_FILE_U16: x = (uint16)SlReadUint16();
break;
1023 case SLE_FILE_I32: x = (int32 )SlReadUint32();
break;
1024 case SLE_FILE_U32: x = (uint32)SlReadUint32();
break;
1025 case SLE_FILE_I64: x = (int64 )SlReadUint64();
break;
1026 case SLE_FILE_U64: x = (uint64)SlReadUint64();
break;
1028 default: NOT_REACHED();
1037 default: NOT_REACHED();
1052 if (ptr == NULL)
return 0;
1053 return min(strlen(ptr), length - 1);
1071 default: NOT_REACHED();
1074 str = *(
const char *
const *)ptr;
1079 str = (
const char *)ptr;
1085 return len + SlGetArrayLength(len);
1094 static void SlString(
void *ptr,
size_t length, VarType conv)
1100 default: NOT_REACHED();
1107 ptr = *(
char **)ptr;
1112 SlWriteArrayLength(len);
1118 size_t len = SlReadArrayLength();
1121 default: NOT_REACHED();
1124 if (len >= length) {
1125 DEBUG(sl, 1,
"String length in savegame is bigger than buffer, truncating");
1135 free(*(
char **)ptr);
1137 *(
char **)ptr = NULL;
1140 *(
char **)ptr = MallocT<char>(len + 1);
1141 ptr = *(
char **)ptr;
1147 ((
char *)ptr)[len] =
'\0';
1158 str_validate((
char *)ptr, (
char *)ptr + len, settings);
1163 default: NOT_REACHED();
1183 void SlArray(
void *array,
size_t length, VarType conv)
1198 if (conv == SLE_INT16 || conv == SLE_UINT16 || conv == SLE_STRINGID ||
1199 conv == SLE_INT32 || conv == SLE_UINT32) {
1204 if (conv == (SLE_FILE_I32 | SLE_VAR_I64)) {
1205 for (uint i = 0; i < length; i++) {
1206 ((int64*)array)[i] = (int32)
BSWAP32(SlReadUint32());
1214 if (conv == SLE_INT8 || conv == SLE_UINT8) {
1217 byte *a = (byte*)array;
1220 for (; length != 0; length --) {
1242 if (obj == NULL)
return 0;
1257 default: NOT_REACHED();
1273 assert_compile(
sizeof(
size_t) <=
sizeof(
void *));
1338 default: NOT_REACHED();
1348 const std::list<void *> *l = (
const std::list<void *> *) list;
1353 return l->size() * type_size + type_size;
1371 typedef std::list<void *> PtrList;
1372 PtrList *l = (PtrList *)list;
1376 SlWriteUint32((uint32)l->size());
1378 PtrList::iterator iter;
1379 for (iter = l->begin(); iter != l->end(); ++iter) {
1390 for (
size_t i = 0; i < length; i++) {
1392 l->push_back((
void *)data);
1400 PtrList::iterator iter;
1401 for (iter = temp.begin(); iter != temp.end(); ++iter) {
1410 default: NOT_REACHED();
1450 for (; sld->
cmd != SL_END; sld++) {
1451 length += SlCalcObjMemberLength(
object, sld);
1456 size_t SlCalcObjMemberLength(
const void *
object,
const SaveLoad *sld)
1475 default: NOT_REACHED();
1478 case SL_WRITEBYTE:
return 1;
1481 default: NOT_REACHED();
1497 return sld->
size ==
sizeof(bool);
1500 return sld->
size ==
sizeof(int8);
1503 return sld->
size ==
sizeof(int16);
1506 return sld->
size ==
sizeof(int32);
1509 return sld->
size ==
sizeof(int64);
1511 return sld->
size ==
sizeof(
void *);
1515 return sld->
size ==
sizeof(
void *);
1526 bool SlObjectMember(
void *ptr,
const SaveLoad *sld)
1530 VarType conv =
GB(sld->
conv, 0, 8);
1556 *(
void **)ptr = NULL;
1558 default: NOT_REACHED();
1564 default: NOT_REACHED();
1580 default: NOT_REACHED();
1585 case SL_VEH_INCLUDE:
1593 default: NOT_REACHED();
1611 for (; sld->
cmd != SL_END; sld++) {
1613 SlObjectMember(ptr, sld);
1669 _sl.array_index = 0;
1673 case CH_SPARSE_ARRAY:
1678 if ((m & 0xF) == CH_RIFF) {
1680 len = (
SlReadByte() << 16) | ((m >> 4) << 24);
1681 len += SlReadUint16();
1709 _sl.array_index = 0;
1716 case CH_SPARSE_ARRAY:
1724 if ((m & 0xF) == CH_RIFF) {
1726 len = (
SlReadByte() << 16) | ((m >> 4) << 24);
1727 len += SlReadUint16();
1776 ChunkSaveLoadProc *proc = ch->
save_proc;
1779 if (proc == NULL)
return;
1781 SlWriteUint32(ch->
id);
1782 DEBUG(sl, 2,
"Saving chunk %c%c%c%c", ch->
id >> 24, ch->
id >> 16, ch->
id >> 8, ch->
id);
1784 if (ch->
flags & CH_AUTO_LENGTH) {
1786 _stub_save_proc = proc;
1791 switch (ch->
flags & CH_TYPE_MASK) {
1800 SlWriteArrayLength(0);
1802 case CH_SPARSE_ARRAY:
1805 SlWriteArrayLength(0);
1807 default: NOT_REACHED();
1840 for (
id = SlReadUint32();
id != 0;
id = SlReadUint32()) {
1841 DEBUG(sl, 2,
"Loading chunk %c%c%c%c",
id >> 24,
id >> 16,
id >> 8,
id);
1855 for (
id = SlReadUint32();
id != 0;
id = SlReadUint32()) {
1856 DEBUG(sl, 2,
"Loading chunk %c%c%c%c",
id >> 24,
id >> 16,
id >> 8,
id);
1869 DEBUG(sl, 1,
"Fixing pointers");
1872 if (ch->ptrs_proc != NULL) {
1873 DEBUG(sl, 2,
"Fixing pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
1878 DEBUG(sl, 1,
"All pointers fixed");
1900 if (this->
file != NULL) fclose(this->
file);
1907 size_t Read(byte *buf,
size_t size)
1910 if (this->
file == NULL)
return 0;
1912 return fread(buf, 1, size, this->
file);
1917 clearerr(this->
file);
1918 if (fseek(this->
file, this->
begin, SEEK_SET)) {
1919 DEBUG(sl, 1,
"Could not reset the file reading");
1948 if (this->
file == NULL)
return;
1950 if (fwrite(buf, 1, size, this->
file) != size)
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
1955 if (this->
file != NULL) fclose(this->
file);
1965 #include <lzo/lzo1x.h>
1978 if (lzo_init() != LZO_E_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize decompressor");
1981 size_t Read(byte *buf,
size_t ssize)
1983 assert(ssize >= LZO_BUFFER_SIZE);
1986 byte out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 +
sizeof(uint32) * 2];
1992 if (this->
chain->
Read((byte*)tmp,
sizeof(tmp)) !=
sizeof(tmp))
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE,
"File read failed");
1995 ((uint32*)out)[0] = size = tmp[1];
1998 tmp[0] = TO_BE32(tmp[0]);
1999 size = TO_BE32(size);
2005 if (this->
chain->
Read(out +
sizeof(uint32), size) != size)
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2008 if (tmp[0] != lzo_adler32(0, out, size +
sizeof(uint32)))
SlErrorCorrupt(
"Bad checksum");
2011 lzo1x_decompress_safe(out +
sizeof(uint32) * 1, size, buf, &len, NULL);
2025 if (lzo_init() != LZO_E_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize compressor");
2030 const lzo_bytep in = buf;
2032 byte out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 +
sizeof(uint32) * 2];
2033 byte wrkmem[LZO1X_1_MEM_COMPRESS];
2038 lzo_uint len = size > LZO_BUFFER_SIZE ? LZO_BUFFER_SIZE : (lzo_uint)size;
2039 lzo1x_1_compress(in, len, out +
sizeof(uint32) * 2, &outlen, wrkmem);
2040 ((uint32*)out)[1] = TO_BE32((uint32)outlen);
2041 ((uint32*)out)[0] = TO_BE32(lzo_adler32(0, out +
sizeof(uint32), outlen +
sizeof(uint32)));
2042 this->
chain->
Write(out, outlen +
sizeof(uint32) * 2);
2067 size_t Read(byte *buf,
size_t size)
2094 #if defined(WITH_ZLIB)
2108 memset(&this->
z, 0,
sizeof(this->
z));
2109 if (inflateInit(&this->
z) != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize decompressor");
2115 inflateEnd(&this->
z);
2118 size_t Read(byte *buf,
size_t size)
2120 this->
z.next_out = buf;
2121 this->
z.avail_out = (uint)size;
2125 if (this->
z.avail_in == 0) {
2127 this->
z.avail_in = (uint)this->
chain->
Read(this->fread_buf,
sizeof(this->fread_buf));
2131 int r = inflate(&this->
z, 0);
2132 if (r == Z_STREAM_END)
break;
2134 if (r != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"inflate() failed");
2135 }
while (this->
z.avail_out != 0);
2137 return size - this->
z.avail_out;
2152 memset(&this->
z, 0,
sizeof(this->
z));
2153 if (deflateInit(&this->
z, compression_level) != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize compressor");
2159 deflateEnd(&this->
z);
2172 this->
z.next_in = p;
2173 this->
z.avail_in = (uInt)len;
2175 this->
z.next_out = buf;
2176 this->
z.avail_out =
sizeof(buf);
2185 int r = deflate(&this->
z, mode);
2188 if ((n =
sizeof(buf) - this->
z.avail_out) != 0) {
2191 if (r == Z_STREAM_END)
break;
2193 if (r != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"zlib returned error code");
2194 }
while (this->
z.avail_in || !this->z.avail_out);
2215 #if defined(WITH_LZMA)
2238 if (lzma_auto_decoder(&this->
lzma, 1 << 28, 0) != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize decompressor");
2244 lzma_end(&this->
lzma);
2247 size_t Read(byte *buf,
size_t size)
2249 this->
lzma.next_out = buf;
2250 this->
lzma.avail_out = size;
2254 if (this->
lzma.avail_in == 0) {
2260 lzma_ret r = lzma_code(&this->
lzma, LZMA_RUN);
2261 if (r == LZMA_STREAM_END)
break;
2262 if (r != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"liblzma returned error code");
2263 }
while (this->
lzma.avail_out != 0);
2265 return size - this->
lzma.avail_out;
2280 if (lzma_easy_encoder(&this->
lzma, compression_level, LZMA_CHECK_CRC32) != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize compressor");
2286 lzma_end(&this->
lzma);
2299 this->
lzma.next_in = p;
2300 this->
lzma.avail_in = len;
2302 this->
lzma.next_out = buf;
2303 this->
lzma.avail_out =
sizeof(buf);
2305 lzma_ret r = lzma_code(&this->
lzma, action);
2308 if ((n =
sizeof(buf) - this->
lzma.avail_out) != 0) {
2311 if (r == LZMA_STREAM_END)
break;
2312 if (r != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"liblzma returned error code");
2313 }
while (this->
lzma.avail_in || !this->lzma.avail_out);
2349 #if defined(WITH_LZO)
2351 {
"lzo", TO_BE32X(
'OTTD'), CreateLoadFilter<LZOLoadFilter>, CreateSaveFilter<LZOSaveFilter>, 0, 0, 0},
2353 {
"lzo", TO_BE32X(
'OTTD'), NULL, NULL, 0, 0, 0},
2356 {
"none", TO_BE32X(
'OTTN'), CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0},
2357 #if defined(WITH_ZLIB)
2361 {
"zlib", TO_BE32X(
'OTTZ'), CreateLoadFilter<ZlibLoadFilter>, CreateSaveFilter<ZlibSaveFilter>, 0, 6, 9},
2363 {
"zlib", TO_BE32X(
'OTTZ'), NULL, NULL, 0, 0, 0},
2365 #if defined(WITH_LZMA)
2371 {
"lzma", TO_BE32X(
'OTTX'), CreateLoadFilter<LZMALoadFilter>, CreateSaveFilter<LZMASaveFilter>, 0, 2, 9},
2373 {
"lzma", TO_BE32X(
'OTTX'), NULL, NULL, 0, 0, 0},
2393 char *complevel = strrchr(s,
':');
2394 if (complevel != NULL) *complevel =
'\0';
2396 for (
const SaveLoadFormat *slf = &_saveload_formats[0]; slf !=
endof(_saveload_formats); slf++) {
2397 if (slf->init_write != NULL && strcmp(s, slf->name) == 0) {
2398 *compression_level = slf->default_compression;
2399 if (complevel != NULL) {
2408 long level = strtol(complevel, &end, 10);
2409 if (end == complevel || level !=
Clamp(level, slf->min_compression, slf->max_compression)) {
2413 *compression_level = level;
2425 if (complevel != NULL) *complevel =
':';
2432 void InitializeGame(uint size_x, uint size_y,
bool reset_date,
bool reset_settings);
2434 extern bool LoadOldSaveGame(
const char *file);
2472 if (_game_mode != GM_MENU) _fast_forward = _sl.
ff_state;
2491 static char err_str[512];
2492 GetString(err_str, _sl.
action ==
SLA_SAVE ? STR_ERROR_GAME_SAVE_FAILED : STR_ERROR_GAME_LOAD_FAILED,
lastof(err_str));
2516 _sl.
sf->
Write((byte*)hdr,
sizeof(hdr));
2533 if (_sl.
error_str != STR_NETWORK_ERROR_LOSTCONNECTION) {
2554 void WaitTillSaved()
2556 if (_save_thread == NULL)
return;
2558 _save_thread->
Join();
2560 _save_thread = NULL;
2583 SaveViewportBeforeSaveGame();
2588 if (threaded)
DEBUG(sl, 1,
"Cannot create savegame thread, reverting to single-threaded mode...");
2609 return DoSave(writer, threaded);
2634 if (_sl.
lf->
Read((byte*)hdr,
sizeof(hdr)) !=
sizeof(hdr))
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2640 if (fmt ==
endof(_saveload_formats)) {
2641 DEBUG(sl, 0,
"Unknown savegame type, trying to load it as the buggy format");
2649 if (fmt ==
endof(_saveload_formats)) {
2653 if (fmt->
tag == TO_BE32X(
'OTTD'))
break;
2659 if (fmt->
tag == hdr[0]) {
2681 SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, err_str);
2692 InitializeGame(256, 256,
true,
true);
2764 return DoLoad(reader,
false);
2793 InitializeGame(256, 256,
true,
true);
2801 if (!LoadOldSaveGame(filename))
return SL_REINIT;
2817 default: NOT_REACHED();
2828 SlError(mode ==
SL_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2840 DEBUG(desync, 1,
"load: %s", filename);
2872 FOR_ALL_COMPANIES(c) {
2882 case 0:
SetDParam(1, STR_JUST_DATE_LONG);
break;
2883 case 1:
SetDParam(1, STR_JUST_DATE_TINY);
break;
2884 case 2:
SetDParam(1, STR_JUST_DATE_ISO);
break;
2885 default: NOT_REACHED();
2890 GetString(buf, !
Company::IsValidID(cid) ? STR_SAVEGAME_NAME_SPECTATOR : STR_SAVEGAME_NAME_DEFAULT, last);
2901 int GetSavegameType(
char *file)
2908 f = fopen(file,
"rb");
2909 if (fread(&hdr,
sizeof(hdr), 1, f) != 1) {
2910 DEBUG(sl, 0,
"Savegame is obsolete or invalid format");
2914 for (fmt = _saveload_formats; fmt !=
endof(_saveload_formats); fmt++) {
2915 if (fmt->
tag == hdr) {