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"
310 inline byte ReadByte()
321 return *this->
bufp++;
444 extern const ChunkHandler _autoreplace_chunk_handlers[];
449 extern const ChunkHandler _persistent_storage_chunk_handlers[];
453 _gamelog_chunk_handlers,
455 _misc_chunk_handlers,
456 _name_chunk_handlers,
457 _cheat_chunk_handlers,
458 _setting_chunk_handlers,
460 _waypoint_chunk_handlers,
461 _depot_chunk_handlers,
462 _order_chunk_handlers,
463 _industry_chunk_handlers,
464 _economy_chunk_handlers,
465 _subsidy_chunk_handlers,
466 _cargomonitor_chunk_handlers,
467 _goal_chunk_handlers,
468 _story_page_chunk_handlers,
469 _engine_chunk_handlers,
470 _town_chunk_handlers,
471 _sign_chunk_handlers,
472 _station_chunk_handlers,
473 _company_chunk_handlers,
475 _game_chunk_handlers,
476 _animated_tile_chunk_handlers,
477 _newgrf_chunk_handlers,
478 _group_chunk_handlers,
479 _cargopacket_chunk_handlers,
480 _autoreplace_chunk_handlers,
481 _labelmaps_chunk_handlers,
482 _linkgraph_chunk_handlers,
483 _airport_chunk_handlers,
484 _object_chunk_handlers,
485 _persistent_storage_chunk_handlers,
493 #define FOR_ALL_CHUNK_HANDLERS(ch) \
494 for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != NULL; chsc++) \
495 for (const ChunkHandler *ch = *chsc; ch != NULL; ch = (ch->flags & CH_LAST) ? NULL : ch + 1)
507 DEBUG(sl, 1,
"Nulling pointers");
510 if (ch->ptrs_proc != NULL) {
511 DEBUG(sl, 2,
"Nulling pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
516 DEBUG(sl, 1,
"All pointers nulled");
547 throw std::exception();
559 SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, msg);
573 if (_exit_game)
return;
574 while (_async_save_finish != NULL) CSleep(10);
576 _async_save_finish = proc;
584 if (_async_save_finish == NULL)
return;
588 _async_save_finish = NULL;
590 if (_save_thread != NULL) {
591 _save_thread->
Join();
603 return _sl.
reader->ReadByte();
615 static inline int SlReadUint16()
621 static inline uint32 SlReadUint32()
623 uint32 x = SlReadUint16() << 16;
624 return x | SlReadUint16();
627 static inline uint64 SlReadUint64()
629 uint32 x = SlReadUint32();
630 uint32 y = SlReadUint32();
631 return (uint64)x << 32 | y;
634 static inline void SlWriteUint16(uint16 v)
640 static inline void SlWriteUint32(uint32 v)
642 SlWriteUint16(
GB(v, 16, 16));
643 SlWriteUint16(
GB(v, 0, 16));
646 static inline void SlWriteUint64(uint64 x)
648 SlWriteUint32((uint32)(x >> 32));
649 SlWriteUint32((uint32)x);
716 if (i >= (1 << 14)) {
717 if (i >= (1 << 21)) {
718 if (i >= (1 << 28)) {
719 assert(i <= UINT32_MAX);
740 return 1 + (i >= (1 << 7)) + (i >= (1 << 14)) + (i >= (1 << 21)) + (i >= (1 << 28));
743 static inline uint SlReadSparseIndex()
748 static inline void SlWriteSparseIndex(uint index)
753 static inline uint SlReadArrayLength()
758 static inline void SlWriteArrayLength(
size_t length)
763 static inline uint SlGetArrayLength(
size_t length)
776 static const byte conv_mem_size[] = {1, 1, 1, 2, 2, 4, 4, 8, 8, 0};
777 byte length =
GB(conv, 4, 4);
779 switch (length << 4) {
784 return SlReadArrayLength();
787 assert(length <
lengthof(conv_mem_size));
788 return conv_mem_size[length];
800 static const byte conv_file_size[] = {1, 1, 2, 2, 4, 4, 8, 8, 2};
801 byte length =
GB(conv, 0, 4);
802 assert(length <
lengthof(conv_file_size));
803 return conv_file_size[length];
812 void SlSetArrayIndex(uint index)
815 _sl.array_index = index;
818 static size_t _next_offs;
833 uint length = SlReadArrayLength();
843 case CH_SPARSE_ARRAY: index = (int)SlReadSparseIndex();
break;
844 case CH_ARRAY: index = _sl.array_index++;
break;
846 DEBUG(sl, 0,
"SlIterateArray error");
850 if (length != 0)
return index;
881 assert(length < (1 << 28));
882 SlWriteUint32((uint32)((length & 0xFFFFFF) | ((length >> 24) << 28)));
887 SlWriteArrayLength(1);
889 SlWriteArrayLength(length + 1);
891 case CH_SPARSE_ARRAY:
892 SlWriteArrayLength(length + 1 + SlGetArrayLength(_sl.array_index));
893 SlWriteSparseIndex(_sl.array_index);
895 default: NOT_REACHED();
903 default: NOT_REACHED();
915 byte *p = (byte *)ptr;
920 for (; length != 0; length--) *p++ =
SlReadByte();
925 default: NOT_REACHED();
945 case SLE_VAR_BL:
return (*(
const bool *)ptr != 0);
946 case SLE_VAR_I8:
return *(
const int8 *)ptr;
947 case SLE_VAR_U8:
return *(
const byte *)ptr;
948 case SLE_VAR_I16:
return *(
const int16 *)ptr;
949 case SLE_VAR_U16:
return *(
const uint16*)ptr;
950 case SLE_VAR_I32:
return *(
const int32 *)ptr;
951 case SLE_VAR_U32:
return *(
const uint32*)ptr;
952 case SLE_VAR_I64:
return *(
const int64 *)ptr;
953 case SLE_VAR_U64:
return *(
const uint64*)ptr;
955 default: NOT_REACHED();
969 case SLE_VAR_BL: *(
bool *)ptr = (val != 0);
break;
970 case SLE_VAR_I8: *(int8 *)ptr = val;
break;
971 case SLE_VAR_U8: *(byte *)ptr = val;
break;
972 case SLE_VAR_I16: *(int16 *)ptr = val;
break;
973 case SLE_VAR_U16: *(uint16*)ptr = val;
break;
974 case SLE_VAR_I32: *(int32 *)ptr = val;
break;
975 case SLE_VAR_U32: *(uint32*)ptr = val;
break;
976 case SLE_VAR_I64: *(int64 *)ptr = val;
break;
977 case SLE_VAR_U64: *(uint64*)ptr = val;
break;
980 default: NOT_REACHED();
1000 case SLE_FILE_I8: assert(x >= -128 && x <= 127);
SlWriteByte(x);
break;
1001 case SLE_FILE_U8: assert(x >= 0 && x <= 255);
SlWriteByte(x);
break;
1002 case SLE_FILE_I16:assert(x >= -32768 && x <= 32767); SlWriteUint16(x);
break;
1004 case SLE_FILE_U16:assert(x >= 0 && x <= 65535); SlWriteUint16(x);
break;
1006 case SLE_FILE_U32: SlWriteUint32((uint32)x);
break;
1008 case SLE_FILE_U64: SlWriteUint64(x);
break;
1009 default: NOT_REACHED();
1018 case SLE_FILE_I8: x = (int8 )
SlReadByte();
break;
1019 case SLE_FILE_U8: x = (byte )
SlReadByte();
break;
1020 case SLE_FILE_I16: x = (int16 )SlReadUint16();
break;
1021 case SLE_FILE_U16: x = (uint16)SlReadUint16();
break;
1022 case SLE_FILE_I32: x = (int32 )SlReadUint32();
break;
1023 case SLE_FILE_U32: x = (uint32)SlReadUint32();
break;
1024 case SLE_FILE_I64: x = (int64 )SlReadUint64();
break;
1025 case SLE_FILE_U64: x = (uint64)SlReadUint64();
break;
1027 default: NOT_REACHED();
1036 default: NOT_REACHED();
1051 if (ptr == NULL)
return 0;
1052 return min(strlen(ptr), length - 1);
1070 default: NOT_REACHED();
1073 str = *(
const char *
const *)ptr;
1078 str = (
const char *)ptr;
1084 return len + SlGetArrayLength(len);
1093 static void SlString(
void *ptr,
size_t length, VarType conv)
1099 default: NOT_REACHED();
1106 ptr = *(
char **)ptr;
1111 SlWriteArrayLength(len);
1117 size_t len = SlReadArrayLength();
1120 default: NOT_REACHED();
1123 if (len >= length) {
1124 DEBUG(sl, 1,
"String length in savegame is bigger than buffer, truncating");
1134 free(*(
char **)ptr);
1136 *(
char **)ptr = NULL;
1139 *(
char **)ptr = MallocT<char>(len + 1);
1140 ptr = *(
char **)ptr;
1146 ((
char *)ptr)[len] =
'\0';
1157 str_validate((
char *)ptr, (
char *)ptr + len, settings);
1162 default: NOT_REACHED();
1182 void SlArray(
void *array,
size_t length, VarType conv)
1197 if (conv == SLE_INT16 || conv == SLE_UINT16 || conv == SLE_STRINGID ||
1198 conv == SLE_INT32 || conv == SLE_UINT32) {
1203 if (conv == (SLE_FILE_I32 | SLE_VAR_I64)) {
1204 for (uint i = 0; i < length; i++) {
1205 ((int64*)array)[i] = (int32)
BSWAP32(SlReadUint32());
1213 if (conv == SLE_INT8 || conv == SLE_UINT8) {
1216 byte *a = (byte*)array;
1219 for (; length != 0; length --) {
1241 if (obj == NULL)
return 0;
1256 default: NOT_REACHED();
1272 assert_compile(
sizeof(
size_t) <=
sizeof(
void *));
1337 default: NOT_REACHED();
1347 const std::list<void *> *l = (
const std::list<void *> *) list;
1352 return l->size() * type_size + type_size;
1370 typedef std::list<void *> PtrList;
1371 PtrList *l = (PtrList *)list;
1375 SlWriteUint32((uint32)l->size());
1377 PtrList::iterator iter;
1378 for (iter = l->begin(); iter != l->end(); ++iter) {
1389 for (
size_t i = 0; i < length; i++) {
1391 l->push_back((
void *)data);
1399 PtrList::iterator iter;
1400 for (iter = temp.begin(); iter != temp.end(); ++iter) {
1409 default: NOT_REACHED();
1449 for (; sld->
cmd != SL_END; sld++) {
1450 length += SlCalcObjMemberLength(
object, sld);
1455 size_t SlCalcObjMemberLength(
const void *
object,
const SaveLoad *sld)
1474 default: NOT_REACHED();
1477 case SL_WRITEBYTE:
return 1;
1480 default: NOT_REACHED();
1496 return sld->
size ==
sizeof(bool);
1499 return sld->
size ==
sizeof(int8);
1502 return sld->
size ==
sizeof(int16);
1505 return sld->
size ==
sizeof(int32);
1508 return sld->
size ==
sizeof(int64);
1510 return sld->
size ==
sizeof(
void *);
1514 return sld->
size ==
sizeof(
void *);
1525 bool SlObjectMember(
void *ptr,
const SaveLoad *sld)
1529 VarType conv =
GB(sld->
conv, 0, 8);
1555 *(
void **)ptr = NULL;
1557 default: NOT_REACHED();
1563 default: NOT_REACHED();
1579 default: NOT_REACHED();
1584 case SL_VEH_INCLUDE:
1592 default: NOT_REACHED();
1610 for (; sld->
cmd != SL_END; sld++) {
1612 SlObjectMember(ptr, sld);
1668 _sl.array_index = 0;
1672 case CH_SPARSE_ARRAY:
1677 if ((m & 0xF) == CH_RIFF) {
1679 len = (
SlReadByte() << 16) | ((m >> 4) << 24);
1680 len += SlReadUint16();
1708 _sl.array_index = 0;
1715 case CH_SPARSE_ARRAY:
1723 if ((m & 0xF) == CH_RIFF) {
1725 len = (
SlReadByte() << 16) | ((m >> 4) << 24);
1726 len += SlReadUint16();
1775 ChunkSaveLoadProc *proc = ch->
save_proc;
1778 if (proc == NULL)
return;
1780 SlWriteUint32(ch->
id);
1781 DEBUG(sl, 2,
"Saving chunk %c%c%c%c", ch->
id >> 24, ch->
id >> 16, ch->
id >> 8, ch->
id);
1783 if (ch->
flags & CH_AUTO_LENGTH) {
1785 _stub_save_proc = proc;
1790 switch (ch->
flags & CH_TYPE_MASK) {
1799 SlWriteArrayLength(0);
1801 case CH_SPARSE_ARRAY:
1804 SlWriteArrayLength(0);
1806 default: NOT_REACHED();
1839 for (
id = SlReadUint32();
id != 0;
id = SlReadUint32()) {
1840 DEBUG(sl, 2,
"Loading chunk %c%c%c%c",
id >> 24,
id >> 16,
id >> 8,
id);
1854 for (
id = SlReadUint32();
id != 0;
id = SlReadUint32()) {
1855 DEBUG(sl, 2,
"Loading chunk %c%c%c%c",
id >> 24,
id >> 16,
id >> 8,
id);
1868 DEBUG(sl, 1,
"Fixing pointers");
1871 if (ch->ptrs_proc != NULL) {
1872 DEBUG(sl, 2,
"Fixing pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
1877 DEBUG(sl, 1,
"All pointers fixed");
1899 if (this->
file != NULL) fclose(this->
file);
1906 size_t Read(byte *buf,
size_t size)
1909 if (this->
file == NULL)
return 0;
1911 return fread(buf, 1, size, this->
file);
1916 clearerr(this->
file);
1917 if (fseek(this->
file, this->
begin, SEEK_SET)) {
1918 DEBUG(sl, 1,
"Could not reset the file reading");
1947 if (this->
file == NULL)
return;
1949 if (fwrite(buf, 1, size, this->
file) != size)
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
1954 if (this->
file != NULL) fclose(this->
file);
1964 #include <lzo/lzo1x.h>
1977 if (lzo_init() != LZO_E_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize decompressor");
1980 size_t Read(byte *buf,
size_t ssize)
1982 assert(ssize >= LZO_BUFFER_SIZE);
1985 byte out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 +
sizeof(uint32) * 2];
1991 if (this->
chain->
Read((byte*)tmp,
sizeof(tmp)) !=
sizeof(tmp))
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE,
"File read failed");
1994 ((uint32*)out)[0] = size = tmp[1];
1997 tmp[0] = TO_BE32(tmp[0]);
1998 size = TO_BE32(size);
2004 if (this->
chain->
Read(out +
sizeof(uint32), size) != size)
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2007 if (tmp[0] != lzo_adler32(0, out, size +
sizeof(uint32)))
SlErrorCorrupt(
"Bad checksum");
2010 lzo1x_decompress_safe(out +
sizeof(uint32) * 1, size, buf, &len, NULL);
2024 if (lzo_init() != LZO_E_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize compressor");
2029 const lzo_bytep in = buf;
2031 byte out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 +
sizeof(uint32) * 2];
2032 byte wrkmem[LZO1X_1_MEM_COMPRESS];
2037 lzo_uint len = size > LZO_BUFFER_SIZE ? LZO_BUFFER_SIZE : (lzo_uint)size;
2038 lzo1x_1_compress(in, len, out +
sizeof(uint32) * 2, &outlen, wrkmem);
2039 ((uint32*)out)[1] = TO_BE32((uint32)outlen);
2040 ((uint32*)out)[0] = TO_BE32(lzo_adler32(0, out +
sizeof(uint32), outlen +
sizeof(uint32)));
2041 this->
chain->
Write(out, outlen +
sizeof(uint32) * 2);
2066 size_t Read(byte *buf,
size_t size)
2093 #if defined(WITH_ZLIB)
2107 memset(&this->
z, 0,
sizeof(this->
z));
2108 if (inflateInit(&this->
z) != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize decompressor");
2114 inflateEnd(&this->
z);
2117 size_t Read(byte *buf,
size_t size)
2119 this->
z.next_out = buf;
2120 this->
z.avail_out = (uint)size;
2124 if (this->
z.avail_in == 0) {
2126 this->
z.avail_in = (uint)this->
chain->
Read(this->fread_buf,
sizeof(this->fread_buf));
2130 int r = inflate(&this->
z, 0);
2131 if (r == Z_STREAM_END)
break;
2133 if (r != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"inflate() failed");
2134 }
while (this->
z.avail_out != 0);
2136 return size - this->
z.avail_out;
2151 memset(&this->
z, 0,
sizeof(this->
z));
2152 if (deflateInit(&this->
z, compression_level) != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize compressor");
2158 deflateEnd(&this->
z);
2171 this->
z.next_in = p;
2172 this->
z.avail_in = (uInt)len;
2174 this->
z.next_out = buf;
2175 this->
z.avail_out =
sizeof(buf);
2184 int r = deflate(&this->
z, mode);
2187 if ((n =
sizeof(buf) - this->
z.avail_out) != 0) {
2190 if (r == Z_STREAM_END)
break;
2192 if (r != Z_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"zlib returned error code");
2193 }
while (this->
z.avail_in || !this->z.avail_out);
2214 #if defined(WITH_LZMA)
2237 if (lzma_auto_decoder(&this->
lzma, 1 << 28, 0) != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize decompressor");
2243 lzma_end(&this->
lzma);
2246 size_t Read(byte *buf,
size_t size)
2248 this->
lzma.next_out = buf;
2249 this->
lzma.avail_out = size;
2253 if (this->
lzma.avail_in == 0) {
2259 lzma_ret r = lzma_code(&this->
lzma, LZMA_RUN);
2260 if (r == LZMA_STREAM_END)
break;
2261 if (r != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"liblzma returned error code");
2262 }
while (this->
lzma.avail_out != 0);
2264 return size - this->
lzma.avail_out;
2279 if (lzma_easy_encoder(&this->
lzma, compression_level, LZMA_CHECK_CRC32) != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"cannot initialize compressor");
2285 lzma_end(&this->
lzma);
2298 this->
lzma.next_in = p;
2299 this->
lzma.avail_in = len;
2301 this->
lzma.next_out = buf;
2302 this->
lzma.avail_out =
sizeof(buf);
2304 lzma_ret r = lzma_code(&this->
lzma, action);
2307 if ((n =
sizeof(buf) - this->
lzma.avail_out) != 0) {
2310 if (r == LZMA_STREAM_END)
break;
2311 if (r != LZMA_OK)
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR,
"liblzma returned error code");
2312 }
while (this->
lzma.avail_in || !this->lzma.avail_out);
2348 #if defined(WITH_LZO)
2350 {
"lzo", TO_BE32X(
'OTTD'), CreateLoadFilter<LZOLoadFilter>, CreateSaveFilter<LZOSaveFilter>, 0, 0, 0},
2352 {
"lzo", TO_BE32X(
'OTTD'), NULL, NULL, 0, 0, 0},
2355 {
"none", TO_BE32X(
'OTTN'), CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0},
2356 #if defined(WITH_ZLIB)
2360 {
"zlib", TO_BE32X(
'OTTZ'), CreateLoadFilter<ZlibLoadFilter>, CreateSaveFilter<ZlibSaveFilter>, 0, 6, 9},
2362 {
"zlib", TO_BE32X(
'OTTZ'), NULL, NULL, 0, 0, 0},
2364 #if defined(WITH_LZMA)
2370 {
"lzma", TO_BE32X(
'OTTX'), CreateLoadFilter<LZMALoadFilter>, CreateSaveFilter<LZMASaveFilter>, 0, 2, 9},
2372 {
"lzma", TO_BE32X(
'OTTX'), NULL, NULL, 0, 0, 0},
2392 char *complevel = strrchr(s,
':');
2393 if (complevel != NULL) *complevel =
'\0';
2395 for (
const SaveLoadFormat *slf = &_saveload_formats[0]; slf !=
endof(_saveload_formats); slf++) {
2396 if (slf->init_write != NULL && strcmp(s, slf->name) == 0) {
2397 *compression_level = slf->default_compression;
2398 if (complevel != NULL) {
2407 long level = strtol(complevel, &end, 10);
2408 if (end == complevel || level !=
Clamp(level, slf->min_compression, slf->max_compression)) {
2412 *compression_level = level;
2424 if (complevel != NULL) *complevel =
':';
2431 void InitializeGame(uint size_x, uint size_y,
bool reset_date,
bool reset_settings);
2433 extern bool LoadOldSaveGame(
const char *file);
2471 if (_game_mode != GM_MENU) _fast_forward = _sl.
ff_state;
2490 static char err_str[512];
2491 GetString(err_str, _sl.
action ==
SLA_SAVE ? STR_ERROR_GAME_SAVE_FAILED : STR_ERROR_GAME_LOAD_FAILED,
lastof(err_str));
2515 _sl.
sf->
Write((byte*)hdr,
sizeof(hdr));
2532 if (_sl.
error_str != STR_NETWORK_ERROR_LOSTCONNECTION) {
2553 void WaitTillSaved()
2555 if (_save_thread == NULL)
return;
2557 _save_thread->
Join();
2559 _save_thread = NULL;
2582 SaveViewportBeforeSaveGame();
2587 if (threaded)
DEBUG(sl, 1,
"Cannot create savegame thread, reverting to single-threaded mode...");
2608 return DoSave(writer, threaded);
2633 if (_sl.
lf->
Read((byte*)hdr,
sizeof(hdr)) !=
sizeof(hdr))
SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2639 if (fmt ==
endof(_saveload_formats)) {
2640 DEBUG(sl, 0,
"Unknown savegame type, trying to load it as the buggy format");
2648 if (fmt ==
endof(_saveload_formats)) {
2652 if (fmt->
tag == TO_BE32X(
'OTTD'))
break;
2658 if (fmt->
tag == hdr[0]) {
2680 SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, err_str);
2691 InitializeGame(256, 256,
true,
true);
2763 return DoLoad(reader,
false);
2792 InitializeGame(256, 256,
true,
true);
2800 if (!LoadOldSaveGame(filename))
return SL_REINIT;
2816 default: NOT_REACHED();
2827 SlError(mode ==
SL_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
2839 DEBUG(desync, 1,
"load: %s", filename);
2871 FOR_ALL_COMPANIES(c) {
2881 case 0:
SetDParam(1, STR_JUST_DATE_LONG);
break;
2882 case 1:
SetDParam(1, STR_JUST_DATE_TINY);
break;
2883 case 2:
SetDParam(1, STR_JUST_DATE_ISO);
break;
2884 default: NOT_REACHED();
2889 GetString(buf, !
Company::IsValidID(cid) ? STR_SAVEGAME_NAME_SPECTATOR : STR_SAVEGAME_NAME_DEFAULT, last);
2900 int GetSavegameType(
char *file)
2907 f = fopen(file,
"rb");
2908 if (fread(&hdr,
sizeof(hdr), 1, f) != 1) {
2909 DEBUG(sl, 0,
"Savegame is obsolete or invalid format");
2913 for (fmt = _saveload_formats; fmt !=
endof(_saveload_formats); fmt++) {
2914 if (fmt->
tag == hdr) {