OpenTTD Source  20241120-master-g6d3adc6169
saveload.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef SAVELOAD_H
11 #define SAVELOAD_H
12 
13 #include "saveload_error.hpp"
14 #include "../fileio_type.h"
15 #include "../fios.h"
16 
30 enum SaveLoadVersion : uint16_t {
32 
34  SLV_2,
37  SLV_4,
43  SLV_5,
46  SLV_6,
51 
53  SLV_11,
58 
60  SLV_16,
62  SLV_17,
66 
72 
78 
84 
90 
96 
102 
108 
114 
120 
126 
132 
138 
144 
150 
156 
162 
168 
174 
180 
186 
192 
198 
204 
210 
216 
222 
228 
234 
240 
246 
252 
258 
264 
270 
272  SLV_191,
277 
283 
289 
295 
301 
307 
308  /* Patchpacks for a while considered it a good idea to jump a few versions
309  * above our version for their savegames. But as time continued, this gap
310  * has been closing, up to the point we would start to reuse versions from
311  * their patchpacks. This is not a problem from our perspective: the
312  * savegame will simply fail to load because they all contain chunks we
313  * cannot digest. But, this gives for ugly errors. As we have plenty of
314  * versions anyway, we simply skip the versions we know belong to
315  * patchpacks. This way we can present the user with a clean error
316  * indicate they are loading a savegame from a patchpack.
317  * For future patchpack creators: please follow a system like JGRPP, where
318  * the version is masked with 0x8000, and the true version is stored in
319  * its own chunk with feature toggles.
320  */
323 
327 
333 
339 
345 
351 
357 
363 
369 
375 
381 
387 
393 
396 
398 };
399 
402  SL_OK = 0,
403  SL_ERROR = 1,
404  SL_REINIT = 2,
405 };
406 
412  std::string name;
413  std::string title;
414 
415  void SetMode(FiosType ft);
417  void Set(const FiosItem &item);
418 };
419 
427  SGT_INVALID = 0xFF,
428 };
429 
431 
432 std::string GenerateDefaultSaveName();
433 void SetSaveLoadError(StringID str);
436 SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true);
437 void WaitTillSaved();
439 void DoExitSave();
440 
442 
443 SaveOrLoadResult SaveWithFilter(std::shared_ptr<struct SaveFilter> writer, bool threaded);
444 SaveOrLoadResult LoadWithFilter(std::shared_ptr<struct LoadFilter> reader);
445 
446 typedef void AutolengthProc(int);
447 
449 enum ChunkType {
450  CH_RIFF = 0,
451  CH_ARRAY = 1,
452  CH_SPARSE_ARRAY = 2,
453  CH_TABLE = 3,
454  CH_SPARSE_TABLE = 4,
455 
456  CH_TYPE_MASK = 0xf,
458 };
459 
461 struct ChunkHandler {
462  uint32_t id;
464 
465  ChunkHandler(uint32_t id, ChunkType type) : id(id), type(type) {}
466 
467  virtual ~ChunkHandler() = default;
468 
473  virtual void Save() const { NOT_REACHED(); }
474 
479  virtual void Load() const = 0;
480 
487  virtual void FixPointers() const {}
488 
494  virtual void LoadCheck(size_t len = 0) const;
495 
496  std::string GetName() const
497  {
498  return std::string()
499  + static_cast<char>(this->id >> 24)
500  + static_cast<char>(this->id >> 16)
501  + static_cast<char>(this->id >> 8)
502  + static_cast<char>(this->id);
503  }
504 };
505 
507 using ChunkHandlerRef = std::reference_wrapper<const ChunkHandler>;
508 
510 using ChunkHandlerTable = std::span<const ChunkHandlerRef>;
511 
513 using SaveLoadTable = std::span<const struct SaveLoad>;
514 
516 using SaveLoadCompatTable = std::span<const struct SaveLoadCompat>;
517 
520 public:
521  std::optional<std::vector<SaveLoad>> load_description;
522 
523  virtual ~SaveLoadHandler() = default;
524 
529  virtual void Save([[maybe_unused]] void *object) const {}
530 
535  virtual void Load([[maybe_unused]] void *object) const {}
536 
541  virtual void LoadCheck([[maybe_unused]] void *object) const {}
542 
547  virtual void FixPointers([[maybe_unused]] void *object) const {}
548 
552  virtual SaveLoadTable GetDescription() const = 0;
553 
558 
565 };
566 
578 template <class TImpl, class TObject>
580 public:
581  SaveLoadTable GetDescription() const override { return static_cast<const TImpl *>(this)->description; }
582  SaveLoadCompatTable GetCompatDescription() const override { return static_cast<const TImpl *>(this)->compat_description; }
583 
584  virtual void Save([[maybe_unused]] TObject *object) const {}
585  void Save(void *object) const override { this->Save(static_cast<TObject *>(object)); }
586 
587  virtual void Load([[maybe_unused]] TObject *object) const {}
588  void Load(void *object) const override { this->Load(static_cast<TObject *>(object)); }
589 
590  virtual void LoadCheck([[maybe_unused]] TObject *object) const {}
591  void LoadCheck(void *object) const override { this->LoadCheck(static_cast<TObject *>(object)); }
592 
593  virtual void FixPointers([[maybe_unused]] TObject *object) const {}
594  void FixPointers(void *object) const override { this->FixPointers(static_cast<TObject *>(object)); }
595 };
596 
598 enum SLRefType {
599  REF_ORDER = 0,
602  REF_TOWN = 3,
611 };
612 
621 enum VarTypes {
622  /* 4 bits allocated a maximum of 16 types for NumberType.
623  * NOTE: the SLE_FILE_NNN values are stored in the savegame! */
625  SLE_FILE_I8 = 1,
626  SLE_FILE_U8 = 2,
627  SLE_FILE_I16 = 3,
628  SLE_FILE_U16 = 4,
629  SLE_FILE_I32 = 5,
630  SLE_FILE_U32 = 6,
631  SLE_FILE_I64 = 7,
632  SLE_FILE_U64 = 8,
634  SLE_FILE_STRING = 10,
635  SLE_FILE_STRUCT = 11,
636  /* 4 more possible file-primitives */
637 
640 
641  /* 4 bits allocated a maximum of 16 types for NumberType */
642  SLE_VAR_BL = 0 << 4,
643  SLE_VAR_I8 = 1 << 4,
644  SLE_VAR_U8 = 2 << 4,
645  SLE_VAR_I16 = 3 << 4,
646  SLE_VAR_U16 = 4 << 4,
647  SLE_VAR_I32 = 5 << 4,
648  SLE_VAR_U32 = 6 << 4,
649  SLE_VAR_I64 = 7 << 4,
650  SLE_VAR_U64 = 8 << 4,
651  SLE_VAR_NULL = 9 << 4,
652  SLE_VAR_STR = 12 << 4,
653  SLE_VAR_STRQ = 13 << 4,
654  SLE_VAR_NAME = 14 << 4,
655  /* 1 more possible memory-primitives */
656 
657  /* Shortcut values */
658  SLE_VAR_CHAR = SLE_VAR_I8,
659 
660  /* Default combinations of variables. As savegames change, so can variables
661  * and thus it is possible that the saved value and internal size do not
662  * match and you need to specify custom combo. The defaults are listed here */
663  SLE_BOOL = SLE_FILE_I8 | SLE_VAR_BL,
664  SLE_INT8 = SLE_FILE_I8 | SLE_VAR_I8,
665  SLE_UINT8 = SLE_FILE_U8 | SLE_VAR_U8,
666  SLE_INT16 = SLE_FILE_I16 | SLE_VAR_I16,
667  SLE_UINT16 = SLE_FILE_U16 | SLE_VAR_U16,
668  SLE_INT32 = SLE_FILE_I32 | SLE_VAR_I32,
669  SLE_UINT32 = SLE_FILE_U32 | SLE_VAR_U32,
670  SLE_INT64 = SLE_FILE_I64 | SLE_VAR_I64,
671  SLE_UINT64 = SLE_FILE_U64 | SLE_VAR_U64,
672  SLE_CHAR = SLE_FILE_I8 | SLE_VAR_CHAR,
673  SLE_STRINGID = SLE_FILE_STRINGID | SLE_VAR_U32,
674  SLE_STRING = SLE_FILE_STRING | SLE_VAR_STR,
675  SLE_STRINGQUOTE = SLE_FILE_STRING | SLE_VAR_STRQ,
676  SLE_NAME = SLE_FILE_STRINGID | SLE_VAR_NAME,
677 
678  /* Shortcut values */
679  SLE_UINT = SLE_UINT32,
680  SLE_INT = SLE_INT32,
681  SLE_STR = SLE_STRING,
682  SLE_STRQ = SLE_STRINGQUOTE,
683 
684  /* 8 bits allocated for a maximum of 8 flags
685  * Flags directing saving/loading of a variable */
686  SLF_ALLOW_CONTROL = 1 << 8,
687  SLF_ALLOW_NEWLINE = 1 << 9,
688 };
689 
690 typedef uint32_t VarType;
691 
693 enum SaveLoadType : uint8_t {
694  SL_VAR = 0,
695  SL_REF = 1,
696  SL_STRUCT = 2,
697 
698  SL_STDSTR = 4,
699 
700  SL_ARR = 5,
701  SL_DEQUE = 6,
702  SL_VECTOR = 7,
705 
706  SL_SAVEBYTE = 10,
707  SL_NULL = 11,
708 };
709 
710 typedef void *SaveLoadAddrProc(void *base, size_t extra);
711 
713 struct SaveLoad {
714  std::string name;
716  VarType conv;
717  uint16_t length;
720  SaveLoadAddrProc *address_proc;
721  size_t extra_data;
722  std::shared_ptr<SaveLoadHandler> handler;
723 };
724 
734  std::string name;
736  uint16_t null_length;
739 };
740 
747 inline constexpr VarType GetVarMemType(VarType type)
748 {
749  return GB(type, 4, 4) << 4;
750 }
751 
758 inline constexpr VarType GetVarFileType(VarType type)
759 {
760  return GB(type, 0, 4);
761 }
762 
768 inline constexpr bool IsNumericType(VarType conv)
769 {
770  return GetVarMemType(conv) <= SLE_VAR_U64;
771 }
772 
778 inline constexpr size_t SlVarSize(VarType type)
779 {
780  switch (GetVarMemType(type)) {
781  case SLE_VAR_BL: return sizeof(bool);
782  case SLE_VAR_I8: return sizeof(int8_t);
783  case SLE_VAR_U8: return sizeof(uint8_t);
784  case SLE_VAR_I16: return sizeof(int16_t);
785  case SLE_VAR_U16: return sizeof(uint16_t);
786  case SLE_VAR_I32: return sizeof(int32_t);
787  case SLE_VAR_U32: return sizeof(uint32_t);
788  case SLE_VAR_I64: return sizeof(int64_t);
789  case SLE_VAR_U64: return sizeof(uint64_t);
790  case SLE_VAR_NULL: return sizeof(void *);
791  case SLE_VAR_STR: return sizeof(std::string);
792  case SLE_VAR_STRQ: return sizeof(std::string);
793  case SLE_VAR_NAME: return sizeof(std::string);
794  default: NOT_REACHED();
795  }
796 }
797 
806 inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t length, size_t size)
807 {
808  switch (cmd) {
809  case SL_VAR: return SlVarSize(type) == size;
810  case SL_REF: return sizeof(void *) == size;
811  case SL_STDSTR: return SlVarSize(type) == size;
812  case SL_ARR: return SlVarSize(type) * length <= size; // Partial load of array is permitted.
813  case SL_DEQUE: return sizeof(std::deque<void *>) == size;
814  case SL_VECTOR: return sizeof(std::vector<void *>) == size;
815  case SL_REFLIST: return sizeof(std::list<void *>) == size;
816  case SL_SAVEBYTE: return true;
817  default: NOT_REACHED();
818  }
819 }
820 
834 #define SLE_GENERAL_NAME(cmd, name, base, variable, type, length, from, to, extra) \
835  SaveLoad {name, cmd, type, length, from, to, [] (void *b, size_t) -> void * { \
836  static_assert(SlCheckVarSize(cmd, type, length, sizeof(static_cast<base *>(b)->variable))); \
837  assert(b != nullptr); \
838  return const_cast<void *>(static_cast<const void *>(std::addressof(static_cast<base *>(b)->variable))); \
839  }, extra, nullptr}
840 
853 #define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra) SLE_GENERAL_NAME(cmd, #variable, base, variable, type, length, from, to, extra)
854 
863 #define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to, 0)
864 
874 #define SLE_CONDVARNAME(base, variable, name, type, from, to) SLE_GENERAL_NAME(SL_VAR, name, base, variable, type, 0, from, to, 0)
875 
884 #define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to, 0)
885 
895 #define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to, 0)
896 
907 #define SLE_CONDARRNAME(base, variable, name, type, length, from, to) SLE_GENERAL_NAME(SL_ARR, name, base, variable, type, length, from, to, 0)
908 
918 #define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to, 0)
919 
928 #define SLE_CONDSSTR(base, variable, type, from, to) SLE_GENERAL(SL_STDSTR, base, variable, type, 0, from, to, 0)
929 
939 #define SLE_CONDSSTRNAME(base, variable, name, type, from, to) SLE_GENERAL_NAME(SL_STDSTR, name, base, variable, type, 0, from, to, 0)
940 
949 #define SLE_CONDREFLIST(base, variable, type, from, to) SLE_GENERAL(SL_REFLIST, base, variable, type, 0, from, to, 0)
950 
959 #define SLE_CONDVECTOR(base, variable, type, from, to) SLE_GENERAL(SL_VECTOR, base, variable, type, 0, from, to, 0)
960 
969 #define SLE_CONDDEQUE(base, variable, type, from, to) SLE_GENERAL(SL_DEQUE, base, variable, type, 0, from, to, 0)
970 
979 #define SLE_CONDVECTOR(base, variable, type, from, to) SLE_GENERAL(SL_VECTOR, base, variable, type, 0, from, to, 0)
980 
987 #define SLE_VAR(base, variable, type) SLE_CONDVAR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
988 
996 #define SLE_VARNAME(base, variable, name, type) SLE_CONDVARNAME(base, variable, name, type, SL_MIN_VERSION, SL_MAX_VERSION)
997 
1004 #define SLE_REF(base, variable, type) SLE_CONDREF(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1005 
1013 #define SLE_ARR(base, variable, type, length) SLE_CONDARR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION)
1014 
1023 #define SLE_ARRNAME(base, variable, name, type, length) SLE_CONDARRNAME(base, variable, name, type, length, SL_MIN_VERSION, SL_MAX_VERSION)
1024 
1031 #define SLE_SSTR(base, variable, type) SLE_CONDSSTR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1032 
1040 #define SLE_SSTRNAME(base, variable, name, type) SLE_CONDSSTRNAME(base, variable, name, type, SL_MIN_VERSION, SL_MAX_VERSION)
1041 
1048 #define SLE_REFLIST(base, variable, type) SLE_CONDREFLIST(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1049 
1060 #define SLE_SAVEBYTE(base, variable) SLE_GENERAL(SL_SAVEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0)
1061 
1073 #define SLEG_GENERAL(name, cmd, variable, type, length, from, to, extra) \
1074  SaveLoad {name, cmd, type, length, from, to, [] (void *, size_t) -> void * { \
1075  static_assert(SlCheckVarSize(cmd, type, length, sizeof(variable))); \
1076  return static_cast<void *>(std::addressof(variable)); }, extra, nullptr}
1077 
1086 #define SLEG_CONDVAR(name, variable, type, from, to) SLEG_GENERAL(name, SL_VAR, variable, type, 0, from, to, 0)
1087 
1096 #define SLEG_CONDREF(name, variable, type, from, to) SLEG_GENERAL(name, SL_REF, variable, type, 0, from, to, 0)
1097 
1107 #define SLEG_CONDARR(name, variable, type, length, from, to) SLEG_GENERAL(name, SL_ARR, variable, type, length, from, to, 0)
1108 
1117 #define SLEG_CONDSSTR(name, variable, type, from, to) SLEG_GENERAL(name, SL_STDSTR, variable, type, 0, from, to, 0)
1118 
1126 #define SLEG_CONDSTRUCT(name, handler, from, to) SaveLoad {name, SL_STRUCT, 0, 0, from, to, nullptr, 0, std::make_shared<handler>()}
1127 
1136 #define SLEG_CONDREFLIST(name, variable, type, from, to) SLEG_GENERAL(name, SL_REFLIST, variable, type, 0, from, to, 0)
1137 
1146 #define SLEG_CONDVECTOR(name, variable, type, from, to) SLEG_GENERAL(name, SL_VECTOR, variable, type, 0, from, to, 0)
1147 
1155 #define SLEG_CONDSTRUCTLIST(name, handler, from, to) SaveLoad {name, SL_STRUCTLIST, 0, 0, from, to, nullptr, 0, std::make_shared<handler>()}
1156 
1163 #define SLEG_VAR(name, variable, type) SLEG_CONDVAR(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1164 
1171 #define SLEG_REF(name, variable, type) SLEG_CONDREF(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1172 
1179 #define SLEG_ARR(name, variable, type) SLEG_CONDARR(name, variable, type, lengthof(variable), SL_MIN_VERSION, SL_MAX_VERSION)
1180 
1187 #define SLEG_SSTR(name, variable, type) SLEG_CONDSSTR(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1188 
1194 #define SLEG_STRUCT(name, handler) SLEG_CONDSTRUCT(name, handler, SL_MIN_VERSION, SL_MAX_VERSION)
1195 
1202 #define SLEG_REFLIST(name, variable, type) SLEG_CONDREFLIST(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1203 
1210 #define SLEG_VECTOR(name, variable, type) SLEG_CONDVECTOR(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1211 
1217 #define SLEG_STRUCTLIST(name, handler) SLEG_CONDSTRUCTLIST(name, handler, SL_MIN_VERSION, SL_MAX_VERSION)
1218 
1223 #define SLC_VAR(name) {name, SLE_FILE_U8, 0, SL_MIN_VERSION, SL_MAX_VERSION}
1224 
1231 #define SLC_NULL(length, from, to) {{}, SLE_FILE_U8, length, from, to}
1232 
1239 inline bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor = 0)
1240 {
1242  extern uint8_t _sl_minor_version;
1243  return _sl_version < major || (minor > 0 && _sl_version == major && _sl_minor_version < minor);
1244 }
1245 
1254 {
1256  return _sl_version <= major;
1257 }
1258 
1266 inline bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
1267 {
1268  extern const SaveLoadVersion SAVEGAME_VERSION;
1269  return version_from <= SAVEGAME_VERSION && SAVEGAME_VERSION < version_to;
1270 }
1271 
1277 inline void *GetVariableAddress(const void *object, const SaveLoad &sld)
1278 {
1279  /* Entry is a null-variable, mostly used to read old savegames etc. */
1280  if (GetVarMemType(sld.conv) == SLE_VAR_NULL) {
1281  assert(sld.address_proc == nullptr);
1282  return nullptr;
1283  }
1284 
1285  /* Everything else should be a non-null pointer. */
1286  assert(sld.address_proc != nullptr);
1287  return sld.address_proc(const_cast<void *>(object), sld.extra_data);
1288 }
1289 
1290 int64_t ReadValue(const void *ptr, VarType conv);
1291 void WriteValue(void *ptr, VarType conv, int64_t val);
1292 
1293 void SlSetArrayIndex(uint index);
1294 int SlIterateArray();
1295 
1296 void SlSetStructListLength(size_t length);
1297 size_t SlGetStructListLength(size_t limit);
1298 
1299 void SlAutolength(AutolengthProc *proc, int arg);
1300 size_t SlGetFieldLength();
1301 void SlSetLength(size_t length);
1302 size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld);
1303 size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
1304 
1305 uint8_t SlReadByte();
1306 void SlWriteByte(uint8_t b);
1307 
1308 void SlGlobList(const SaveLoadTable &slt);
1309 void SlCopy(void *object, size_t length, VarType conv);
1310 std::vector<SaveLoad> SlTableHeader(const SaveLoadTable &slt);
1311 std::vector<SaveLoad> SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct);
1312 void SlObject(void *object, const SaveLoadTable &slt);
1313 
1315 
1321 inline void SlSkipBytes(size_t length)
1322 {
1323  for (; length != 0; length--) SlReadByte();
1324 }
1325 
1326 extern std::string _savegame_format;
1327 extern bool _do_autosave;
1328 
1340 template <class TImpl, class TObject, class TElementType, size_t MAX_LENGTH = UINT32_MAX>
1341 class VectorSaveLoadHandler : public DefaultSaveLoadHandler<TImpl, TObject> {
1342 public:
1348  virtual std::vector<TElementType> &GetVector(TObject *object) const = 0;
1349 
1355  virtual size_t GetLength() const { return SlGetStructListLength(MAX_LENGTH); }
1356 
1357  void Save(TObject *object) const override
1358  {
1359  auto &vector = this->GetVector(object);
1360  SlSetStructListLength(vector.size());
1361 
1362  for (auto &item : vector) {
1363  SlObject(&item, this->GetDescription());
1364  }
1365  }
1366 
1367  void Load(TObject *object) const override
1368  {
1369  auto &vector = this->GetVector(object);
1370  size_t count = this->GetLength();
1371 
1372  vector.reserve(count);
1373  while (count-- > 0) {
1374  auto &item = vector.emplace_back();
1375  SlObject(&item, this->GetLoadDescription());
1376  }
1377  }
1378 };
1379 
1380 #endif /* SAVELOAD_H */
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Default handler for saving/loading an object to/from disk.
Definition: saveload.h:579
SaveLoadTable GetDescription() const override
Get the description of the fields in the savegame.
Definition: saveload.h:581
SaveLoadCompatTable GetCompatDescription() const override
Get the pre-header description of the fields in the savegame.
Definition: saveload.h:582
Handler for saving/loading an object to/from disk.
Definition: saveload.h:519
virtual void Load([[maybe_unused]] void *object) const
Load the object from disk.
Definition: saveload.h:535
virtual SaveLoadTable GetDescription() const =0
Get the description of the fields in the savegame.
virtual void LoadCheck([[maybe_unused]] void *object) const
Similar to load, but used only to validate savegames.
Definition: saveload.h:541
virtual SaveLoadCompatTable GetCompatDescription() const =0
Get the pre-header description of the fields in the savegame.
virtual void FixPointers([[maybe_unused]] void *object) const
A post-load callback to fix SL_REF integers into pointers.
Definition: saveload.h:547
virtual void Save([[maybe_unused]] void *object) const
Save the object to disk.
Definition: saveload.h:529
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Definition: saveload.cpp:3293
Default handler for saving/loading a vector to/from disk.
Definition: saveload.h:1341
virtual size_t GetLength() const
Get number of elements to load into vector.
Definition: saveload.h:1355
virtual std::vector< TElementType > & GetVector(TObject *object) const =0
Get instance of vector to load/save.
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:16
FiosType
Elements of a file system that are recognized.
Definition: fileio_type.h:73
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:53
DetailedFileType
Kinds of files in each AbstractFileType.
Definition: fileio_type.h:29
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:115
SaveLoadVersion _sl_version
the major savegame version identifier
Definition: saveload.cpp:63
uint8_t _sl_minor_version
the minor savegame version, DO NOT USE!
Definition: saveload.cpp:64
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
SaveOrLoadResult LoadWithFilter(std::shared_ptr< LoadFilter > reader)
Load the game using a (reader) filter.
Definition: saveload.cpp:3077
SaveOrLoadResult SaveWithFilter(std::shared_ptr< SaveFilter > writer, bool threaded)
Save the game using a (writer) filter.
Definition: saveload.cpp:2917
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded=true)
Main Save or Load function where the high-level saveload functions are handled.
Definition: saveload.cpp:3097
void ProcessAsyncSaveFinish()
Handle async save finishes.
Definition: saveload.cpp:376
std::string _savegame_format
how to compress savegames
Definition: saveload.cpp:65
StringID GetSaveLoadErrorMessage()
Return the description of the error.
Definition: saveload.cpp:2811
constexpr bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
Definition: saveload.h:768
VarTypes
VarTypes is the general bitmasked magic type that tells us certain characteristics about the variable...
Definition: saveload.h:621
@ SLE_VAR_NULL
useful to write zeros in savegame.
Definition: saveload.h:651
@ SLE_FILE_END
Used to mark end-of-header in tables.
Definition: saveload.h:624
@ SLE_FILE_TYPE_MASK
Mask to get the file-type (and not any flags).
Definition: saveload.h:638
@ SLE_FILE_HAS_LENGTH_FIELD
Bit stored in savegame to indicate field has a length field for each entry.
Definition: saveload.h:639
@ SLF_ALLOW_NEWLINE
Allow new lines in the strings.
Definition: saveload.h:687
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition: saveload.h:686
@ SLE_VAR_STR
string pointer
Definition: saveload.h:652
@ SLE_VAR_NAME
old custom name to be converted to a char pointer
Definition: saveload.h:654
@ SLE_VAR_STRQ
string pointer enclosed in quotes
Definition: saveload.h:653
@ SLE_FILE_STRINGID
StringID offset into strings-array.
Definition: saveload.h:633
bool _do_autosave
are we doing an autosave at the moment?
Definition: saveload.cpp:66
StringID GetSaveLoadErrorType()
Return the appropriate initial string for an error depending on whether we are saving or loading.
Definition: saveload.cpp:2805
void SlWriteByte(uint8_t b)
Wrapper for writing a byte to the dumper.
Definition: saveload.cpp:401
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
Definition: saveload.cpp:1689
void * GetVariableAddress(const void *object, const SaveLoad &sld)
Get the address of the variable.
Definition: saveload.h:1277
SaveOrLoadResult
Save or load result codes.
Definition: saveload.h:401
@ SL_ERROR
error that was caught before internal structures were modified
Definition: saveload.h:403
@ SL_OK
completed successfully
Definition: saveload.h:402
@ SL_REINIT
error that was caught in the middle of updating game state, need to clear it. (can only happen during...
Definition: saveload.h:404
void WriteValue(void *ptr, VarType conv, int64_t val)
Write the value of a setting.
Definition: saveload.cpp:817
ChunkType
Type of a chunk.
Definition: saveload.h:449
@ CH_TYPE_MASK
All ChunkType values have to be within this mask.
Definition: saveload.h:456
@ CH_READONLY
Chunk is never saved.
Definition: saveload.h:457
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:658
void SlSkipBytes(size_t length)
Read in bytes from the file/data structure but don't do anything with them, discarding them in effect...
Definition: saveload.h:1321
SavegameType
Types of save games.
Definition: saveload.h:421
@ SGT_TTD
TTD savegame (can be detected incorrectly)
Definition: saveload.h:422
@ SGT_INVALID
broken savegame (used internally)
Definition: saveload.h:427
@ SGT_OTTD
OTTD savegame.
Definition: saveload.h:425
@ SGT_TTDP2
TTDP savegame in new format (data at SE border)
Definition: saveload.h:424
@ SGT_TTO
TTO savegame.
Definition: saveload.h:426
@ SGT_TTDP1
TTDP savegame ( -//- ) (data at NW border)
Definition: saveload.h:423
constexpr size_t SlVarSize(VarType type)
Return expect size in bytes of a VarType.
Definition: saveload.h:778
void SetSaveLoadError(StringID str)
Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friend...
Definition: saveload.cpp:2799
void SlCopy(void *object, size_t length, VarType conv)
Copy a list of SL_VARs to/from a savegame.
Definition: saveload.cpp:1029
size_t SlGetFieldLength()
Get the length of the current object.
Definition: saveload.cpp:781
void DoAutoOrNetsave(FiosNumberedSaveName &counter)
Create an autosave or netsave.
Definition: saveload.cpp:3188
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition: saveload.h:507
constexpr VarType GetVarFileType(VarType type)
Get the FileType of a setting.
Definition: saveload.h:758
constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t length, size_t size)
Check if a saveload cmd/type/length entry matches the size of the variable.
Definition: saveload.h:806
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition: saveload.h:510
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition: saveload.cpp:1893
bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
Checks if some version from/to combination falls within the range of the active savegame version.
Definition: saveload.h:1266
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition: saveload.cpp:1755
SaveLoadType
Type of data saved.
Definition: saveload.h:693
@ SL_NULL
Save null-bytes and load to nowhere.
Definition: saveload.h:707
@ SL_STRUCTLIST
Save/load a list of structs.
Definition: saveload.h:704
@ SL_STDSTR
Save/load a std::string.
Definition: saveload.h:698
@ SL_REF
Save/load a reference.
Definition: saveload.h:695
@ SL_SAVEBYTE
Save (but not load) a byte.
Definition: saveload.h:706
@ SL_DEQUE
Save/load a deque of SL_VAR elements.
Definition: saveload.h:701
@ SL_STRUCT
Save/load a struct.
Definition: saveload.h:696
@ SL_VECTOR
Save/load a vector of SL_VAR elements.
Definition: saveload.h:702
@ SL_REFLIST
Save/load a list of SL_REF elements.
Definition: saveload.h:703
@ SL_ARR
Save/load a fixed-size array of SL_VAR elements.
Definition: saveload.h:700
@ SL_VAR
Save/load a variable.
Definition: saveload.h:694
bool SaveloadCrashWithMissingNewGRFs()
Did loading the savegame cause a crash? If so, were NewGRFs missing?
Definition: afterload.cpp:352
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
Definition: saveload.h:516
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:60
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
Definition: saveload.cpp:712
uint8_t SlReadByte()
Wrapper for reading a byte from the buffer.
Definition: saveload.cpp:392
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:3206
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:1239
constexpr VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
Definition: saveload.h:747
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt)
Calculate the size of an object.
Definition: saveload.cpp:1511
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition: saveload.cpp:1702
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
Definition: saveload.h:30
@ SLV_AI_START_DATE
309 PR#10653 Removal of individual AI start dates and added a generic one.
Definition: saveload.h:350
@ SLV_190
190 26547 Separate order travel and wait times
Definition: saveload.h:271
@ SLV_91
91 12347
Definition: saveload.h:152
@ SLV_196
196 27778 v1.7
Definition: saveload.h:279
@ SLV_49
49 8969
Definition: saveload.h:101
@ SLV_90
90 12293
Definition: saveload.h:151
@ SLV_64
64 10006
Definition: saveload.h:119
@ SLV_69
69 10319
Definition: saveload.h:125
@ SLV_ECONOMY_MODE_TIMEKEEPING_UNITS
327 PR#11341 Mode to display economy measurements in wallclock units.
Definition: saveload.h:372
@ SLV_CUSTOM_SUBSIDY_DURATION
292 PR#9081 Configurable subsidy duration.
Definition: saveload.h:330
@ SLV_29
29 5070
Definition: saveload.h:77
@ SLV_172
172 23947
Definition: saveload.h:249
@ SLV_89
89 12160
Definition: saveload.h:149
@ SLV_67
67 10236
Definition: saveload.h:123
@ SLV_182
182 25115 FS#5492, r25259, r25296 Goal status
Definition: saveload.h:261
@ SLV_186
186 25833 Objects storage
Definition: saveload.h:266
@ SLV_175
175 24136
Definition: saveload.h:253
@ SLV_INDUSTRY_TEXT
289 PR#8576 v1.11.0-RC1 Additional GS text for industries.
Definition: saveload.h:326
@ SLV_16
16.0 2817 16.1 3155
Definition: saveload.h:60
@ SLV_87
87 12129
Definition: saveload.h:147
@ SLV_SERVE_NEUTRAL_INDUSTRIES
210 PR#7234 Company stations can serve industries with attached neutral stations.
Definition: saveload.h:296
@ SLV_147
147 20621
Definition: saveload.h:219
@ SLV_188
188 26169 v1.4 FS#5831 Unify RV travel time
Definition: saveload.h:268
@ SLV_75
75 11107
Definition: saveload.h:133
@ SLV_40
40 7326
Definition: saveload.h:91
@ SLV_129
129 18292
Definition: saveload.h:197
@ SLV_61
61 9892
Definition: saveload.h:116
@ SLV_150
150 20857
Definition: saveload.h:223
@ SLV_73
73 10903
Definition: saveload.h:130
@ SLV_FIX_CARGO_MONITOR
207 PR#7175 v1.9 Cargo monitor data packing fix to support 64 cargotypes.
Definition: saveload.h:292
@ SLV_118
118 16129
Definition: saveload.h:184
@ SLV_66
66 10211
Definition: saveload.h:122
@ SLV_84
84 11822
Definition: saveload.h:143
@ SLV_116
116 15893 0.7.x
Definition: saveload.h:182
@ SLV_25
25 4259
Definition: saveload.h:73
@ SLV_15
15.0 2499
Definition: saveload.h:59
@ SLV_198
198 PR#6763 Switch town growth rate and counter to actual game ticks
Definition: saveload.h:281
@ SLV_36
36 6624
Definition: saveload.h:86
@ SLV_71
71 10567
Definition: saveload.h:128
@ SLV_26
26 4466
Definition: saveload.h:74
@ SLV_96
96 13226
Definition: saveload.h:158
@ SLV_107
107 15027
Definition: saveload.h:171
@ SLV_EXTEND_RAILTYPES
200 PR#6805 Extend railtypes to 64, adding uint16_t to map array.
Definition: saveload.h:284
@ SLV_SCRIPT_INT64
296 PR#9415 SQInteger is 64bit but was saved as 32bit.
Definition: saveload.h:335
@ SLV_ROAD_WAYPOINTS
338 PR#12572 Road waypoints
Definition: saveload.h:385
@ SLV_168
168 23637
Definition: saveload.h:244
@ SLV_39
39 7269
Definition: saveload.h:89
@ SLV_17
17.0 3212 17.1 3218
Definition: saveload.h:62
@ SLV_180
180 24998 1.3.x
Definition: saveload.h:259
@ SLV_174
174 23973 1.2.x
Definition: saveload.h:251
@ SLV_42
42 7573
Definition: saveload.h:93
@ SLV_177
177 24619
Definition: saveload.h:255
@ SLV_79
79 11188
Definition: saveload.h:137
@ SLV_SHIP_CURVE_PENALTY
209 PR#7289 Configurable ship curve penalties.
Definition: saveload.h:294
@ SLV_EXTEND_INDUSTRY_CARGO_SLOTS
202 PR#6867 Increase industry cargo slots to 16 in, 16 out
Definition: saveload.h:286
@ SLV_103
103 14598
Definition: saveload.h:166
@ SLV_100
100 13952
Definition: saveload.h:163
@ SLV_44
44 8144
Definition: saveload.h:95
@ SLV_171
171 23835
Definition: saveload.h:248
@ SLV_GROUP_REPLACE_WAGON_REMOVAL
291 PR#7441 Per-group wagon removal flag.
Definition: saveload.h:329
@ SLV_VELOCITY_NAUTICAL
305 PR#10594 Separation of land and nautical velocity (knots!)
Definition: saveload.h:346
@ SLV_VEHICLE_ECONOMY_AGE
334 PR#12141 v14.0 Add vehicle age in economy year, for profit stats minimum age
Definition: saveload.h:380
@ SLV_4
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
Definition: saveload.h:37
@ SLV_AI_LOCAL_CONFIG
332 PR#12003 Config of running AI is stored inside Company.
Definition: saveload.h:378
@ SLV_TOWN_CARGOGEN
208 PR#6965 New algorithms for town building cargo generation.
Definition: saveload.h:293
@ SLV_ROADVEH_PATH_CACHE
211 PR#7261 Add path cache for road vehicles.
Definition: saveload.h:297
@ SLV_85
85 11874
Definition: saveload.h:145
@ SLV_149
149 20832
Definition: saveload.h:221
@ SLV_83
83 11589
Definition: saveload.h:142
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:46
@ SLV_181
181 25012
Definition: saveload.h:260
@ SLV_34
34 6455
Definition: saveload.h:83
@ SLV_LINKGRAPH_SECONDS
308 PR#10610 Store linkgraph update intervals in seconds instead of days.
Definition: saveload.h:349
@ SLV_114
114 15601
Definition: saveload.h:179
@ SLV_EXTEND_CARGOTYPES
199 PR#6802 Extend cargotypes to 64
Definition: saveload.h:282
@ SLV_60
60 9874
Definition: saveload.h:115
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
Definition: saveload.h:331
@ SLV_137
137 18912
Definition: saveload.h:207
@ SLV_176
176 24446
Definition: saveload.h:254
@ SLV_SAVEGAME_ID
313 PR#10719 Add an unique ID to every savegame (used to deduplicate surveys).
Definition: saveload.h:355
@ SLV_131
131 18481
Definition: saveload.h:200
@ SLV_11
11.0 2033 11.1 2041
Definition: saveload.h:53
@ SLV_65
65 10210
Definition: saveload.h:121
@ SLV_CALENDAR_SUB_DATE_FRACT
328 PR#11428 Add sub_date_fract to measure calendar days.
Definition: saveload.h:373
@ SLV_120
120 16439
Definition: saveload.h:187
@ SLV_DISASTER_VEH_STATE
312 PR#10798 Explicit storage of disaster vehicle state.
Definition: saveload.h:354
@ SLV_99
99 13838
Definition: saveload.h:161
@ SLV_123
123 16909
Definition: saveload.h:190
@ SLV_TIMETABLE_START_TICKS
321 PR#11468 Convert timetable start from a date to ticks.
Definition: saveload.h:365
@ SLV_195
195 27572 v1.6.1
Definition: saveload.h:278
@ SLV_46
46 8705
Definition: saveload.h:98
@ SLV_START_PATCHPACKS
220 First known patchpack to use a version just above ours.
Definition: saveload.h:321
@ SLV_173
173 23967 1.2.0-RC1
Definition: saveload.h:250
@ SLV_122
122 16855
Definition: saveload.h:189
@ SLV_SHIP_ROTATION
204 PR#7065 Add extra rotation stages for ships.
Definition: saveload.h:288
@ SLV_ENDING_YEAR
218 PR#7747 v1.10 Configurable ending year.
Definition: saveload.h:305
@ SLV_191
191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store location...
Definition: saveload.h:272
@ SLV_141
141 19799
Definition: saveload.h:212
@ SLV_80
80 11228
Definition: saveload.h:139
@ SLV_8
8.0 1786
Definition: saveload.h:49
@ SLV_DOCK_DOCKINGTILES
298 PR#9578 All tiles around docks may be docking tiles.
Definition: saveload.h:337
@ SLV_112
112 15290
Definition: saveload.h:177
@ SLV_SHIP_PATH_CACHE
203 PR#7072 Add path cache for ships
Definition: saveload.h:287
@ SLV_47
47 8735
Definition: saveload.h:99
@ SLV_125
125 17113
Definition: saveload.h:193
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
Definition: saveload.h:332
@ SLV_166
166 23415
Definition: saveload.h:242
@ SLV_98
98 13375
Definition: saveload.h:160
@ SLV_PATH_CACHE_FORMAT
346 PR#12345 Vehicle path cache format changed.
Definition: saveload.h:395
@ SLV_WATER_TILE_TYPE
342 PR#13030 Simplify water tile type.
Definition: saveload.h:390
@ SLV_117
117 16037
Definition: saveload.h:183
@ SLV_140
140 19382
Definition: saveload.h:211
@ SLV_126
126 17433
Definition: saveload.h:194
@ SLV_170
170 23826
Definition: saveload.h:247
@ SLV_193
193 26802
Definition: saveload.h:275
@ SLV_13
13.1 2080 0.4.0, 0.4.0.1
Definition: saveload.h:56
@ SLV_138
138 18942 1.0.x
Definition: saveload.h:208
@ SLV_12
12.1 2046
Definition: saveload.h:55
@ SLV_MULTITILE_DOCKS
216 PR#7380 Multiple docks per station.
Definition: saveload.h:303
@ SLV_86
86 12042
Definition: saveload.h:146
@ SLV_ROAD_TYPES
214 PR#6811 NewGRF road types.
Definition: saveload.h:300
@ SLV_LINKGRAPH_EDGES
304 PR#10314 Explicitly store link graph edges destination, PR#10471 int64_t instead of uint64_t leag...
Definition: saveload.h:344
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:397
@ SLV_1
1.0 0.1.x, 0.2.x
Definition: saveload.h:33
@ SLV_GS_INDUSTRY_CONTROL
287 PR#7912 and PR#8115 GS industry control.
Definition: saveload.h:324
@ SLV_164
164 23290
Definition: saveload.h:239
@ SLV_160
160 21974 1.1.x
Definition: saveload.h:235
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:31
@ SLV_VEH_MOTION_COUNTER
288 PR#8591 Desync safe motion counter
Definition: saveload.h:325
@ SLV_3
3.x lost
Definition: saveload.h:36
@ SLV_EXTEND_VEHICLE_RANDOM
310 PR#10701 Extend vehicle random bits.
Definition: saveload.h:352
@ SLV_38
38 7195
Definition: saveload.h:88
@ SLV_51
51 8978
Definition: saveload.h:104
@ SLV_145
145 20376
Definition: saveload.h:217
@ SLV_48
48 8935
Definition: saveload.h:100
@ SLV_TRADING_AGE
217 PR#7780 Configurable company trading age.
Definition: saveload.h:304
@ SLV_63
63 9956
Definition: saveload.h:118
@ SLV_CARGO_TRAVELLED
319 PR#11283 CargoPacket now tracks how far it travelled inside a vehicle.
Definition: saveload.h:362
@ SLV_35
35 6602
Definition: saveload.h:85
@ SLV_57
57 9691
Definition: saveload.h:111
@ SLV_104
104 14735
Definition: saveload.h:167
@ SLV_197
197 27978 v1.8
Definition: saveload.h:280
@ SLV_151
151 20918
Definition: saveload.h:224
@ SLV_52
52 9066
Definition: saveload.h:105
@ SLV_68
68 10266
Definition: saveload.h:124
@ SLV_PRODUCTION_HISTORY
343 PR#10541 Industry production history.
Definition: saveload.h:391
@ SLV_20
20 3403
Definition: saveload.h:67
@ SLV_134
134 18703
Definition: saveload.h:203
@ SLV_165
165 23304
Definition: saveload.h:241
@ SLV_NEWGRF_ROAD_STOPS
303 PR#10144 NewGRF road stops.
Definition: saveload.h:343
@ SLV_144
144 20334
Definition: saveload.h:215
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition: saveload.h:34
@ SLV_22
22 3726
Definition: saveload.h:69
@ SLV_154
154 21426
Definition: saveload.h:227
@ SLV_EXTEND_PERSISTENT_STORAGE
201 PR#6885 Extend NewGRF persistent storages.
Definition: saveload.h:285
@ SLV_187
187 25899 Linkgraph - restricted flows
Definition: saveload.h:267
@ SLV_27
27 4757
Definition: saveload.h:75
@ SLV_143
143 20048
Definition: saveload.h:214
@ SLV_127
127 17439
Definition: saveload.h:195
@ SLV_END_PATCHPACKS
286 Last known patchpack to use a version just above ours.
Definition: saveload.h:322
@ SLV_33
33 6440
Definition: saveload.h:82
@ SLV_157
157 21862
Definition: saveload.h:231
@ SLV_28
28 4987
Definition: saveload.h:76
@ SLV_152
152 21171
Definition: saveload.h:225
@ SLV_LAST_LOADING_TICK
301 PR#9693 Store tick of last loading for vehicles.
Definition: saveload.h:341
@ SLV_GROUP_LIVERIES
205 PR#7108 Livery storage change and group liveries.
Definition: saveload.h:290
@ SLV_105
105 14803
Definition: saveload.h:169
@ SLV_76
76 11139
Definition: saveload.h:134
@ SLV_SCRIPT_RANDOMIZER
333 PR#12063 v14.0-RC1 Save script randomizers.
Definition: saveload.h:379
@ SLV_COMPANY_INAUGURATED_PERIOD
339 PR#12798 Companies show the period inaugurated in wallclock mode.
Definition: saveload.h:386
@ SLV_78
78 11176
Definition: saveload.h:136
@ SLV_106
106 14919
Definition: saveload.h:170
@ SLV_DEPOT_UNBUNCHING
331 PR#11945 Allow unbunching shared order vehicles at a depot.
Definition: saveload.h:377
@ SLV_92
92 12381 0.6.x
Definition: saveload.h:153
@ SLV_119
119 16242
Definition: saveload.h:185
@ SLV_COMPANY_ALLOW_LIST_V2
341 PR#12908 Fixed savegame format for saving of list of client keys that are allowed to join this co...
Definition: saveload.h:389
@ SLV_30
30 5946
Definition: saveload.h:79
@ SLV_139
139 19346
Definition: saveload.h:209
@ SLV_SHIP_ACCELERATION
329 PR#10734 Start using Vehicle's acceleration field for ships too.
Definition: saveload.h:374
@ SLV_10
10.0 2030
Definition: saveload.h:52
@ SLV_115
115 15695
Definition: saveload.h:181
@ SLV_REMOVE_OPF
212 PR#7245 Remove OPF.
Definition: saveload.h:298
@ SLV_135
135 18719
Definition: saveload.h:205
@ SLV_14
14.0 2441
Definition: saveload.h:57
@ SLV_MULTITRACK_LEVEL_CROSSINGS
302 PR#9931 v13.0 Multi-track level crossings.
Definition: saveload.h:342
@ SLV_121
121 16694
Definition: saveload.h:188
@ SLV_192
192 26700 FS#6066 Fix saving of order backups
Definition: saveload.h:274
@ SLV_58
58 9762
Definition: saveload.h:112
@ SLV_COMPANY_ALLOW_LIST
335 PR#12337 Saving of list of client keys that are allowed to join this company.
Definition: saveload.h:382
@ SLV_94
94 12816
Definition: saveload.h:155
@ SLV_153
153 21263
Definition: saveload.h:226
@ SLV_101
101 14233
Definition: saveload.h:164
@ SLV_95
95 12924
Definition: saveload.h:157
@ SLV_158
158 21933
Definition: saveload.h:232
@ SLV_133
133 18674
Definition: saveload.h:202
@ SLV_93
93 12648
Definition: saveload.h:154
@ SLV_81
81 11244
Definition: saveload.h:140
@ SLV_72
72 10601
Definition: saveload.h:129
@ SLV_97
97 13256
Definition: saveload.h:159
@ SLV_43
43 7642
Definition: saveload.h:94
@ SLV_113
113 15340
Definition: saveload.h:178
@ SLV_19
19 3396
Definition: saveload.h:65
@ SLV_55
55 9638
Definition: saveload.h:109
@ SLV_ECONOMY_DATE
326 PR#10700 Split calendar and economy timers and dates.
Definition: saveload.h:371
@ SLV_TIMETABLE_START_TICKS_FIX
322 PR#11557 Fix for missing convert timetable start from a date to ticks.
Definition: saveload.h:366
@ SLV_45
45 8501
Definition: saveload.h:97
@ SLV_128
128 18281
Definition: saveload.h:196
@ SLV_167
167 23504
Definition: saveload.h:243
@ SLV_189
189 26450 Hierarchical vehicle subgroups
Definition: saveload.h:269
@ SLV_TIMETABLE_TICKS_TYPE
323 PR#11435 Convert timetable current order time to ticks.
Definition: saveload.h:367
@ SLV_185
185 25620 Storybooks
Definition: saveload.h:265
@ SLV_LINKGRAPH_TRAVEL_TIME
297 PR#9457 v12.0-RC1 Store travel time in the linkgraph.
Definition: saveload.h:336
@ SLV_GROUP_NUMBERS
336 PR#12297 Add per-company group numbers.
Definition: saveload.h:383
@ SLV_5
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition: saveload.h:43
@ SLV_NEWGRF_LAST_SERVICE
317 PR#11124 Added stable date_of_last_service to avoid NewGRF trouble.
Definition: saveload.h:360
@ SLV_53
53 9316
Definition: saveload.h:106
@ SLV_161
161 22567
Definition: saveload.h:236
@ SLV_STATION_RATING_CHEAT
320 PR#11346 Add cheat to fix station ratings at 100%.
Definition: saveload.h:364
@ SLV_74
74 11030
Definition: saveload.h:131
@ SLV_109
109 15075
Definition: saveload.h:173
@ SLV_184
184 25508 Unit localisation split
Definition: saveload.h:263
@ SLV_INDUSTRY_CARGO_REORGANISE
315 PR#10853 Industry accepts/produced data reorganised.
Definition: saveload.h:358
@ SLV_77
77 11172
Definition: saveload.h:135
@ SLV_INCREASE_STATION_TYPE_FIELD_SIZE
337 PR#12572 Increase size of StationType field in map array
Definition: saveload.h:384
@ SLV_88
88 12134
Definition: saveload.h:148
@ SLV_156
156 21728
Definition: saveload.h:230
@ SLV_WATER_REGIONS
324 PR#10543 Water Regions for ship pathfinder.
Definition: saveload.h:368
@ SLV_NONFLOODING_WATER_TILES
345 PR#13013 Store water tile non-flooding state.
Definition: saveload.h:394
@ SLV_MAPGEN_SETTINGS_REVAMP
290 PR#8891 v1.11 Revamp of some mapgen settings (snow coverage, desert coverage, heightmap height,...
Definition: saveload.h:328
@ SLV_130
130 18404
Definition: saveload.h:199
@ SLV_7
7.0 1770
Definition: saveload.h:48
@ SLV_ROAD_TYPE_LABEL_MAP
344 PR#13021 Add road type label map to allow upgrade/conversion of road types.
Definition: saveload.h:392
@ SLV_163
163 22767
Definition: saveload.h:238
@ SLV_155
155 21453
Definition: saveload.h:229
@ SLV_STRING_GAMELOG
314 PR#10801 Use std::string in gamelog.
Definition: saveload.h:356
@ SLV_62
62 9905
Definition: saveload.h:117
@ SLV_PERIODS_IN_TRANSIT_RENAME
316 PR#11112 Rename days in transit to (cargo) periods in transit.
Definition: saveload.h:359
@ SLV_TABLE_CHUNKS
295 PR#9322 Introduction of CH_TABLE and CH_SPARSE_TABLE.
Definition: saveload.h:334
@ SLV_59
59 9779
Definition: saveload.h:113
@ SLV_54
54 9613
Definition: saveload.h:107
@ SLV_18
18 3227
Definition: saveload.h:64
@ SLV_169
169 23816
Definition: saveload.h:245
@ SLV_82
82 11410
Definition: saveload.h:141
@ SLV_102
102 14332
Definition: saveload.h:165
@ SLV_MORE_CARGO_AGE
307 PR#10596 Track cargo age for a longer period.
Definition: saveload.h:348
@ SLV_110
110 15148
Definition: saveload.h:175
@ SLV_194
194 26881 v1.5
Definition: saveload.h:276
@ SLV_TREES_WATER_CLASS
213 PR#7405 WaterClass update for tree tiles.
Definition: saveload.h:299
@ SLV_REMOVE_LOADED_AT_XY
318 PR#11276 Remove loaded_at_xy variable from CargoPacket.
Definition: saveload.h:361
@ SLV_124
124 16993
Definition: saveload.h:191
@ SLV_159
159 21962
Definition: saveload.h:233
@ SLV_32
32 6001
Definition: saveload.h:81
@ SLV_56
56 9667
Definition: saveload.h:110
@ SLV_162
162 22713
Definition: saveload.h:237
@ SLV_179
179 24810
Definition: saveload.h:257
@ SLV_37
37 7182
Definition: saveload.h:87
@ SLV_SHIPS_STOP_IN_LOCKS
206 PR#7150 Ship/lock movement changes.
Definition: saveload.h:291
@ SLV_132
132 18522
Definition: saveload.h:201
@ SLV_111
111 15190
Definition: saveload.h:176
@ SLV_REMOVE_TOWN_CARGO_CACHE
219 PR#8258 Remove town cargo acceptance and production caches.
Definition: saveload.h:306
@ SLV_108
108 15045
Definition: saveload.h:172
@ SLV_70
70 10541
Definition: saveload.h:127
@ SLV_183
183 25363 Cargodist
Definition: saveload.h:262
@ SLV_31
31 5999
Definition: saveload.h:80
@ SLV_148
148 20659
Definition: saveload.h:220
@ SLV_50
50 8973
Definition: saveload.h:103
@ SLV_REPAIR_OBJECT_DOCKING_TILES
299 PR#9594 v12.0 Fixing issue with docking tiles overlapping objects.
Definition: saveload.h:338
@ SLV_CONSISTENT_PARTIAL_Z
306 PR#10570 Conversion from an inconsistent partial Z calculation for slopes, to one that is (more) ...
Definition: saveload.h:347
@ SLV_142
142 20003
Definition: saveload.h:213
@ SLV_EXTEND_ENTITY_MAPPING
311 PR#10672 Extend entity mapping range.
Definition: saveload.h:353
@ SLV_SCRIPT_MEMLIMIT
215 PR#7516 Limit on AI/GS memory consumption.
Definition: saveload.h:302
@ SLV_21
21 3472 0.4.x
Definition: saveload.h:68
@ SLV_WATER_REGION_EVAL_SIMPLIFIED
325 PR#11750 Simplified Water Region evaluation.
Definition: saveload.h:370
@ SLV_136
136 18764
Definition: saveload.h:206
@ SLV_146
146 20446
Definition: saveload.h:218
@ SLV_41
41 7348 0.5.x
Definition: saveload.h:92
@ SLV_MAX_LOAN_FOR_COMPANY
330 PR#11224 Separate max loan for each company.
Definition: saveload.h:376
@ SLV_ROAD_STOP_TILE_DATA
340 PR#12883 Move storage of road stop tile data, also save for road waypoints.
Definition: saveload.h:388
@ SLV_23
23 3915
Definition: saveload.h:70
@ SLV_U64_TICK_COUNTER
300 PR#10035 Make tick counter 64bit to avoid wrapping.
Definition: saveload.h:340
@ SLV_24
24 4150
Definition: saveload.h:71
@ SLV_178
178 24789
Definition: saveload.h:256
@ SLV_9
9.0 1909
Definition: saveload.h:50
int64_t ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition: saveload.cpp:793
bool IsSavegameVersionBeforeOrAt(SaveLoadVersion major)
Checks whether the savegame is below or at major.
Definition: saveload.h:1253
SLRefType
Type of reference (SLE_REF, SLE_CONDREF).
Definition: saveload.h:598
@ REF_VEHICLE_OLD
Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
Definition: saveload.h:603
@ REF_LINK_GRAPH_JOB
Load/save a reference to a link graph job.
Definition: saveload.h:610
@ REF_TOWN
Load/save a reference to a town.
Definition: saveload.h:602
@ REF_LINK_GRAPH
Load/save a reference to a link graph.
Definition: saveload.h:609
@ REF_CARGO_PACKET
Load/save a reference to a cargo packet.
Definition: saveload.h:606
@ REF_ENGINE_RENEWS
Load/save a reference to an engine renewal (autoreplace).
Definition: saveload.h:605
@ REF_STATION
Load/save a reference to a station.
Definition: saveload.h:601
@ REF_ORDER
Load/save a reference to an order.
Definition: saveload.h:599
@ REF_ORDERLIST
Load/save a reference to an orderlist.
Definition: saveload.h:607
@ REF_STORAGE
Load/save a reference to a persistent storage.
Definition: saveload.h:608
@ REF_VEHICLE
Load/save a reference to a vehicle.
Definition: saveload.h:600
@ REF_ROADSTOPS
Load/save a reference to a bus/truck stop.
Definition: saveload.h:604
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
Definition: saveload.h:513
void SlGlobList(const SaveLoadTable &slt)
Save or Load (a list of) global variables.
Definition: saveload.cpp:1947
std::string GenerateDefaultSaveName()
Get the default name for a savegame or screenshot.
Definition: saveload.cpp:3214
void SlAutolength(AutolengthProc *proc, int arg)
Do something of which I have no idea what it is :P.
Definition: saveload.cpp:1957
void SlSetStructListLength(size_t length)
Set the length of this list.
Definition: saveload.cpp:1673
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Handlers and description of chunk.
Definition: saveload.h:461
virtual void FixPointers() const
Fix the pointers.
Definition: saveload.h:487
ChunkType type
Type of the chunk.
Definition: saveload.h:463
virtual void LoadCheck(size_t len=0) const
Load the chunk for game preview.
Definition: saveload.cpp:1981
virtual void Load() const =0
Load the chunk.
uint32_t id
Unique ID (4 letters).
Definition: saveload.h:462
virtual void Save() const
Save the chunk.
Definition: saveload.h:473
Deals with the type of the savegame, independent of extension.
Definition: saveload.h:408
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition: saveload.h:411
void SetMode(FiosType ft)
Set the mode and file type of the file to save or load based on the type of file entry at the file sy...
Definition: saveload.cpp:3257
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition: saveload.h:410
std::string title
Internal name of the game.
Definition: saveload.h:413
SaveLoadOperation file_op
File operation to perform.
Definition: saveload.h:409
std::string name
Name of the file.
Definition: saveload.h:412
void Set(const FiosItem &item)
Set the title of the file.
Definition: saveload.cpp:3286
Deals with finding savegames.
Definition: fios.h:79
A savegame name automatically numbered.
Definition: fios.h:130
SaveLoad information for backwards compatibility.
Definition: saveload.h:733
VarTypes null_type
The type associated with the NULL field; defaults to SLE_FILE_U8 to just count bytes.
Definition: saveload.h:735
std::string name
Name of the field.
Definition: saveload.h:734
SaveLoadVersion version_to
Save/load the variable before this savegame version.
Definition: saveload.h:738
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
Definition: saveload.h:737
uint16_t null_length
Length of the NULL field.
Definition: saveload.h:736
SaveLoad type struct.
Definition: saveload.h:713
uint16_t length
(Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
Definition: saveload.h:717
std::shared_ptr< SaveLoadHandler > handler
Custom handler for Save/Load procs.
Definition: saveload.h:722
SaveLoadAddrProc * address_proc
Callback proc the get the actual variable address in memory.
Definition: saveload.h:720
SaveLoadVersion version_to
Save/load the variable before this savegame version.
Definition: saveload.h:719
SaveLoadType cmd
The action to take with the saved/loaded type, All types need different action.
Definition: saveload.h:715
std::string name
Name of this field (optional, used for tables).
Definition: saveload.h:714
VarType conv
Type of the variable to be saved; this field combines both FileVarType and MemVarType.
Definition: saveload.h:716
size_t extra_data
Extra data for the callback proc.
Definition: saveload.h:721
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
Definition: saveload.h:718