OpenTTD Source: src/saveload/saveload.h Source File

OpenTTD Source 12.2

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 "../fileio_type.h"
14 #include "../fios.h"
15 #include "../strings_type.h"
16 #include "../core/span_type.hpp"
17 #include <optional>
18 #include <string>
19 #include <vector>
20
34 enum SaveLoadVersion : uint16 {
35 SL_MIN_VERSION,
36
37 SLV_1,
38 SLV_2,
40 SLV_3,
41 SLV_4,
47 SLV_5,
50 SLV_6,
52 SLV_7,
53 SLV_8,
54 SLV_9,
55
56 SLV_10,
57 SLV_11,
59 SLV_12,
60 SLV_13,
61 SLV_14,
62
63 SLV_15,
64 SLV_16,
66 SLV_17,
68 SLV_18,
69 SLV_19,
70
71 SLV_20,
72 SLV_21,
73 SLV_22,
74 SLV_23,
75 SLV_24,
76
77 SLV_25,
78 SLV_26,
79 SLV_27,
80 SLV_28,
81 SLV_29,
82
83 SLV_30,
84 SLV_31,
85 SLV_32,
86 SLV_33,
87 SLV_34,
88
89 SLV_35,
90 SLV_36,
91 SLV_37,
92 SLV_38,
93 SLV_39,
94
95 SLV_40,
96 SLV_41,
97 SLV_42,
98 SLV_43,
99 SLV_44,
100
101 SLV_45,
102 SLV_46,
103 SLV_47,
104 SLV_48,
105 SLV_49,
106
107 SLV_50,
108 SLV_51,
109 SLV_52,
110 SLV_53,
111 SLV_54,
112
113 SLV_55,
114 SLV_56,
115 SLV_57,
116 SLV_58,
117 SLV_59,
118
119 SLV_60,
120 SLV_61,
121 SLV_62,
122 SLV_63,
123 SLV_64,
124
125 SLV_65,
126 SLV_66,
127 SLV_67,
128 SLV_68,
129 SLV_69,
130
131 SLV_70,
132 SLV_71,
133 SLV_72,
134 SLV_73,
135 SLV_74,
136
137 SLV_75,
138 SLV_76,
139 SLV_77,
140 SLV_78,
141 SLV_79,
142
143 SLV_80,
144 SLV_81,
145 SLV_82,
146 SLV_83,
147 SLV_84,
148
149 SLV_85,
150 SLV_86,
151 SLV_87,
152 SLV_88,
153 SLV_89,
154
155 SLV_90,
156 SLV_91,
157 SLV_92,
158 SLV_93,
159 SLV_94,
160
161 SLV_95,
162 SLV_96,
163 SLV_97,
164 SLV_98,
165 SLV_99,
166
167 SLV_100,
168 SLV_101,
169 SLV_102,
170 SLV_103,
171 SLV_104,
172
173 SLV_105,
174 SLV_106,
175 SLV_107,
176 SLV_108,
177 SLV_109,
178
179 SLV_110,
180 SLV_111,
181 SLV_112,
182 SLV_113,
183 SLV_114,
184
185 SLV_115,
186 SLV_116,
187 SLV_117,
188 SLV_118,
189 SLV_119,
190
191 SLV_120,
192 SLV_121,
193 SLV_122,
194 SLV_123,
195 SLV_124,
196
197 SLV_125,
198 SLV_126,
199 SLV_127,
200 SLV_128,
201 SLV_129,
202
203 SLV_130,
204 SLV_131,
205 SLV_132,
206 SLV_133,
207 SLV_134,
208
209 SLV_135,
210 SLV_136,
211 SLV_137,
212 SLV_138,
213 SLV_139,
214
215 SLV_140,
216 SLV_141,
217 SLV_142,
218 SLV_143,
219 SLV_144,
220
221 SLV_145,
222 SLV_146,
223 SLV_147,
224 SLV_148,
225 SLV_149,
226
227 SLV_150,
228 SLV_151,
229 SLV_152,
230 SLV_153,
231 SLV_154,
232
233 SLV_155,
234 SLV_156,
235 SLV_157,
236 SLV_158,
237 SLV_159,
238
239 SLV_160,
240 SLV_161,
241 SLV_162,
242 SLV_163,
243 SLV_164,
244
245 SLV_165,
246 SLV_166,
247 SLV_167,
248 SLV_168,
249 SLV_169,
250
251 SLV_170,
252 SLV_171,
253 SLV_172,
254 SLV_173,
255 SLV_174,
256
257 SLV_175,
258 SLV_176,
259 SLV_177,
260 SLV_178,
261 SLV_179,
262
263 SLV_180,
264 SLV_181,
265 SLV_182,
266 SLV_183,
267 SLV_184,
268
269 SLV_185,
270 SLV_186,
271 SLV_187,
272 SLV_188,
273 SLV_189,
274
275 SLV_190,
276 SLV_191,
277 SLV_192,
279 SLV_193,
280 SLV_194,
281
282 SLV_195,
283 SLV_196,
284 SLV_197,
285 SLV_198,
286 SLV_EXTEND_CARGOTYPES,
287
288 SLV_EXTEND_RAILTYPES,
289 SLV_EXTEND_PERSISTENT_STORAGE,
290 SLV_EXTEND_INDUSTRY_CARGO_SLOTS,
291 SLV_SHIP_PATH_CACHE,
292 SLV_SHIP_ROTATION,
293
294 SLV_GROUP_LIVERIES,
295 SLV_SHIPS_STOP_IN_LOCKS,
296 SLV_FIX_CARGO_MONITOR,
297 SLV_TOWN_CARGOGEN,
298 SLV_SHIP_CURVE_PENALTY,
299
300 SLV_SERVE_NEUTRAL_INDUSTRIES,
301 SLV_ROADVEH_PATH_CACHE,
302 SLV_REMOVE_OPF,
303 SLV_TREES_WATER_CLASS,
304 SLV_ROAD_TYPES,
305
306 SLV_SCRIPT_MEMLIMIT,
307 SLV_MULTITILE_DOCKS,
308 SLV_TRADING_AGE,
309 SLV_ENDING_YEAR,
310 SLV_REMOVE_TOWN_CARGO_CACHE,
311
312 /* Patchpacks for a while considered it a good idea to jump a few versions
313 * above our version for their savegames. But as time continued, this gap
314 * has been closing, up to the point we would start to reuse versions from
315 * their patchpacks. This is not a problem from our perspective: the
316 * savegame will simply fail to load because they all contain chunks we
317 * cannot digest. But, this gives for ugly errors. As we have plenty of
318 * versions anyway, we simply skip the versions we know belong to
319 * patchpacks. This way we can present the user with a clean error
320 * indicate they are loading a savegame from a patchpack.
321 * For future patchpack creators: please follow a system like JGRPP, where
322 * the version is masked with 0x8000, and the true version is stored in
323 * its own chunk with feature toggles.
324 */
325 SLV_START_PATCHPACKS,
326 SLV_END_PATCHPACKS = 286,
327
328 SLV_GS_INDUSTRY_CONTROL,
329 SLV_VEH_MOTION_COUNTER,
330 SLV_INDUSTRY_TEXT,
331
332 SLV_MAPGEN_SETTINGS_REVAMP,
333 SLV_GROUP_REPLACE_WAGON_REMOVAL,
334 SLV_CUSTOM_SUBSIDY_DURATION,
335 SLV_SAVELOAD_LIST_LENGTH,
336 SLV_RIFF_TO_ARRAY,
337
338 SLV_TABLE_CHUNKS,
339 SLV_SCRIPT_INT64,
340 SLV_LINKGRAPH_TRAVEL_TIME,
341 SLV_DOCK_DOCKINGTILES,
342 SLV_REPAIR_OBJECT_DOCKING_TILES,
343
344 SL_MAX_VERSION,
345 };
346
348 enum SaveOrLoadResult {
349 SL_OK = 0,
350 SL_ERROR = 1,
351 SL_REINIT = 2,
352 };
353
355 struct FileToSaveLoad {
356 SaveLoadOperation file_op;
357 DetailedFileType detail_ftype;
358 AbstractFileType abstract_ftype;
359 std::string name;
360 char title[255];
361
362 void SetMode(FiosType ft);
363 void SetMode(SaveLoadOperation fop, AbstractFileType aft, DetailedFileType dft);
364 void SetName(const char *name);
365 void SetTitle(const char *title);
366 };
367
369 enum SavegameType {
370 SGT_TTD,
371 SGT_TTDP1,
372 SGT_TTDP2,
373 SGT_OTTD,
374 SGT_TTO,
375 SGT_INVALID = 0xFF,
376 };
377
378 extern FileToSaveLoad _file_to_saveload;
379
380 void GenerateDefaultSaveName(char *buf, const char *last);
381 void SetSaveLoadError(StringID str);
382 const char *GetSaveLoadErrorString();
383 SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true);
384 void WaitTillSaved();
385 void ProcessAsyncSaveFinish();
386 void DoExitSave();
387
388 void DoAutoOrNetsave(FiosNumberedSaveName &counter);
389
390 SaveOrLoadResult SaveWithFilter(struct SaveFilter *writer, bool threaded);
391 SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader);
392
393 typedef void AutolengthProc(void *arg);
394
396 enum ChunkType {
397 CH_RIFF = 0,
398 CH_ARRAY = 1,
399 CH_SPARSE_ARRAY = 2,
400 CH_TABLE = 3,
401 CH_SPARSE_TABLE = 4,
402
403 CH_TYPE_MASK = 0xf,
404 CH_READONLY,
405 };
406
408 struct ChunkHandler {
409 uint32 id;
410 ChunkType type;
411
412 ChunkHandler(uint32 id, ChunkType type) : id(id), type(type) {}
413
414 virtual ~ChunkHandler() {}
415
420 virtual void Save() const { NOT_REACHED(); }
421
426 virtual void Load() const = 0;
427
434 virtual void FixPointers() const {}
435
441 virtual void LoadCheck(size_t len = 0) const;
442 };
443
445 using ChunkHandlerRef = std::reference_wrapper<const ChunkHandler>;
446
448 using ChunkHandlerTable = span<const ChunkHandlerRef>;
449
451 using SaveLoadTable = span<const struct SaveLoad>;
452
454 using SaveLoadCompatTable = span<const struct SaveLoadCompat>;
455
457 class SaveLoadHandler {
458 public:
459 std::optional<std::vector<SaveLoad>> load_description;
460
461 virtual ~SaveLoadHandler() {}
462
467 virtual void Save(void *object) const {}
468
473 virtual void Load(void *object) const {}
474
479 virtual void LoadCheck(void *object) const {}
480
485 virtual void FixPointers(void *object) const {}
486
490 virtual SaveLoadTable GetDescription() const = 0;
491
495 virtual SaveLoadCompatTable GetCompatDescription() const = 0;
496
502 SaveLoadTable GetLoadDescription() const;
503 };
504
516 template <class TImpl, class TObject>
517 class DefaultSaveLoadHandler : public SaveLoadHandler {
518 public:
519 SaveLoadTable GetDescription() const override { return static_cast<const TImpl *>(this)->description; }
520 SaveLoadCompatTable GetCompatDescription() const override { return static_cast<const TImpl *>(this)->compat_description; }
521
522 virtual void Save(TObject *object) const {}
523 void Save(void *object) const override { this->Save(static_cast<TObject *>(object)); }
524
525 virtual void Load(TObject *object) const {}
526 void Load(void *object) const override { this->Load(static_cast<TObject *>(object)); }
527
528 virtual void LoadCheck(TObject *object) const {}
529 void LoadCheck(void *object) const override { this->LoadCheck(static_cast<TObject *>(object)); }
530
531 virtual void FixPointers(TObject *object) const {}
532 void FixPointers(void *object) const override { this->FixPointers(static_cast<TObject *>(object)); }
533 };
534
536 enum SLRefType {
537 REF_ORDER = 0,
538 REF_VEHICLE = 1,
539 REF_STATION = 2,
540 REF_TOWN = 3,
541 REF_VEHICLE_OLD = 4,
542 REF_ROADSTOPS = 5,
543 REF_ENGINE_RENEWS = 6,
544 REF_CARGO_PACKET = 7,
545 REF_ORDERLIST = 8,
546 REF_STORAGE = 9,
547 REF_LINK_GRAPH = 10,
548 REF_LINK_GRAPH_JOB = 11,
549 };
550
559 enum VarTypes {
560 /* 4 bits allocated a maximum of 16 types for NumberType.
561 * NOTE: the SLE_FILE_NNN values are stored in the savegame! */
562 SLE_FILE_END = 0,
563 SLE_FILE_I8 = 1,
564 SLE_FILE_U8 = 2,
565 SLE_FILE_I16 = 3,
566 SLE_FILE_U16 = 4,
567 SLE_FILE_I32 = 5,
568 SLE_FILE_U32 = 6,
569 SLE_FILE_I64 = 7,
570 SLE_FILE_U64 = 8,
571 SLE_FILE_STRINGID = 9,
572 SLE_FILE_STRING = 10,
573 SLE_FILE_STRUCT = 11,
574 /* 4 more possible file-primitives */
575
576 SLE_FILE_TYPE_MASK = 0xf,
577 SLE_FILE_HAS_LENGTH_FIELD = 1 << 4,
578
579 /* 4 bits allocated a maximum of 16 types for NumberType */
580 SLE_VAR_BL = 0 << 4,
581 SLE_VAR_I8 = 1 << 4,
582 SLE_VAR_U8 = 2 << 4,
583 SLE_VAR_I16 = 3 << 4,
584 SLE_VAR_U16 = 4 << 4,
585 SLE_VAR_I32 = 5 << 4,
586 SLE_VAR_U32 = 6 << 4,
587 SLE_VAR_I64 = 7 << 4,
588 SLE_VAR_U64 = 8 << 4,
589 SLE_VAR_NULL = 9 << 4,
590 SLE_VAR_STRB = 10 << 4,
591 SLE_VAR_STR = 12 << 4,
592 SLE_VAR_STRQ = 13 << 4,
593 SLE_VAR_NAME = 14 << 4,
594 /* 1 more possible memory-primitives */
595
596 /* Shortcut values */
597 SLE_VAR_CHAR = SLE_VAR_I8,
598
599 /* Default combinations of variables. As savegames change, so can variables
600 * and thus it is possible that the saved value and internal size do not
601 * match and you need to specify custom combo. The defaults are listed here */
602 SLE_BOOL = SLE_FILE_I8 | SLE_VAR_BL,
603 SLE_INT8 = SLE_FILE_I8 | SLE_VAR_I8,
604 SLE_UINT8 = SLE_FILE_U8 | SLE_VAR_U8,
605 SLE_INT16 = SLE_FILE_I16 | SLE_VAR_I16,
606 SLE_UINT16 = SLE_FILE_U16 | SLE_VAR_U16,
607 SLE_INT32 = SLE_FILE_I32 | SLE_VAR_I32,
608 SLE_UINT32 = SLE_FILE_U32 | SLE_VAR_U32,
609 SLE_INT64 = SLE_FILE_I64 | SLE_VAR_I64,
610 SLE_UINT64 = SLE_FILE_U64 | SLE_VAR_U64,
611 SLE_CHAR = SLE_FILE_I8 | SLE_VAR_CHAR,
612 SLE_STRINGID = SLE_FILE_STRINGID | SLE_VAR_U32,
613 SLE_STRINGBUF = SLE_FILE_STRING | SLE_VAR_STRB,
614 SLE_STRING = SLE_FILE_STRING | SLE_VAR_STR,
615 SLE_STRINGQUOTE = SLE_FILE_STRING | SLE_VAR_STRQ,
616 SLE_NAME = SLE_FILE_STRINGID | SLE_VAR_NAME,
617
618 /* Shortcut values */
619 SLE_UINT = SLE_UINT32,
620 SLE_INT = SLE_INT32,
621 SLE_STRB = SLE_STRINGBUF,
622 SLE_STR = SLE_STRING,
623 SLE_STRQ = SLE_STRINGQUOTE,
624
625 /* 8 bits allocated for a maximum of 8 flags
626 * Flags directing saving/loading of a variable */
627 SLF_ALLOW_CONTROL = 1 << 8,
628 SLF_ALLOW_NEWLINE = 1 << 9,
629 };
630
631 typedef uint32 VarType;
632
634 enum SaveLoadType : byte {
635 SL_VAR = 0,
636 SL_REF = 1,
637 SL_STRUCT = 2,
638
639 SL_STR = 3,
640 SL_STDSTR = 4,
641
642 SL_ARR = 5,
643 SL_DEQUE = 6,
644 SL_VECTOR = 7,
645 SL_REFLIST = 8,
646 SL_STRUCTLIST = 9,
647
648 SL_SAVEBYTE = 10,
649 SL_NULL = 11,
650 };
651
652 typedef void *SaveLoadAddrProc(void *base, size_t extra);
653
655 struct SaveLoad {
656 std::string name;
657 SaveLoadType cmd;
658 VarType conv;
659 uint16 length;
660 SaveLoadVersion version_from;
661 SaveLoadVersion version_to;
662 size_t size;
663 SaveLoadAddrProc *address_proc;
664 size_t extra_data;
665 std::shared_ptr<SaveLoadHandler> handler;
666 };
667
676 struct SaveLoadCompat {
677 std::string name;
678 uint16 length;
679 SaveLoadVersion version_from;
680 SaveLoadVersion version_to;
681 };
682
694 #define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra) SaveLoad {#variable, cmd, type, length, from, to, cpp_sizeof(base, variable), [] (void *b, size_t) -> void * { assert(b != nullptr); return const_cast<void *>(static_cast<const void *>(std::addressof(static_cast<base *>(b)->variable))); }, extra, nullptr}
695
704 #define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to, 0)
705
714 #define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to, 0)
715
725 #define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to, 0)
726
736 #define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to, 0)
737
746 #define SLE_CONDSSTR(base, variable, type, from, to) SLE_GENERAL(SL_STDSTR, base, variable, type, 0, from, to, 0)
747
756 #define SLE_CONDREFLIST(base, variable, type, from, to) SLE_GENERAL(SL_REFLIST, base, variable, type, 0, from, to, 0)
757
766 #define SLE_CONDDEQUE(base, variable, type, from, to) SLE_GENERAL(SL_DEQUE, base, variable, type, 0, from, to, 0)
767
774 #define SLE_VAR(base, variable, type) SLE_CONDVAR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
775
782 #define SLE_REF(base, variable, type) SLE_CONDREF(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
783
791 #define SLE_ARR(base, variable, type, length) SLE_CONDARR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION)
792
800 #define SLE_STR(base, variable, type, length) SLE_CONDSTR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION)
801
808 #define SLE_SSTR(base, variable, type) SLE_CONDSSTR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
809
816 #define SLE_REFLIST(base, variable, type) SLE_CONDREFLIST(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
817
828 #define SLE_SAVEBYTE(base, variable) SLE_GENERAL(SL_SAVEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0)
829
841 #define SLEG_GENERAL(name, cmd, variable, type, length, from, to, extra) SaveLoad {name, cmd, type, length, from, to, sizeof(variable), [] (void *, size_t) -> void * { return static_cast<void *>(std::addressof(variable)); }, extra, nullptr}
842
851 #define SLEG_CONDVAR(name, variable, type, from, to) SLEG_GENERAL(name, SL_VAR, variable, type, 0, from, to, 0)
852
861 #define SLEG_CONDREF(name, variable, type, from, to) SLEG_GENERAL(name, SL_REF, variable, type, 0, from, to, 0)
862
872 #define SLEG_CONDARR(name, variable, type, length, from, to) SLEG_GENERAL(name, SL_ARR, variable, type, length, from, to, 0)
873
883 #define SLEG_CONDSTR(name, variable, type, length, from, to) SLEG_GENERAL(name, SL_STR, variable, type, length, from, to, 0)
884
893 #define SLEG_CONDSSTR(name, variable, type, from, to) SLEG_GENERAL(name, SL_STDSTR, variable, type, 0, from, to, 0)
894
902 #define SLEG_CONDSTRUCT(name, handler, from, to) SaveLoad {name, SL_STRUCT, 0, 0, from, to, 0, nullptr, 0, std::make_shared<handler>()}
903
912 #define SLEG_CONDREFLIST(name, variable, type, from, to) SLEG_GENERAL(name, SL_REFLIST, variable, type, 0, from, to, 0)
913
922 #define SLEG_CONDVECTOR(name, variable, type, from, to) SLEG_GENERAL(name, SL_VECTOR, variable, type, 0, from, to, 0)
923
931 #define SLEG_CONDSTRUCTLIST(name, handler, from, to) SaveLoad {name, SL_STRUCTLIST, 0, 0, from, to, 0, nullptr, 0, std::make_shared<handler>()}
932
939 #define SLEG_VAR(name, variable, type) SLEG_CONDVAR(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
940
947 #define SLEG_REF(name, variable, type) SLEG_CONDREF(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
948
955 #define SLEG_ARR(name, variable, type) SLEG_CONDARR(name, variable, type, lengthof(variable), SL_MIN_VERSION, SL_MAX_VERSION)
956
963 #define SLEG_STR(name, variable, type) SLEG_CONDSTR(name, variable, type, sizeof(variable), SL_MIN_VERSION, SL_MAX_VERSION)
964
971 #define SLEG_SSTR(name, variable, type) SLEG_CONDSSTR(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
972
978 #define SLEG_STRUCT(name, handler) SLEG_CONDSTRUCT(name, handler, SL_MIN_VERSION, SL_MAX_VERSION)
979
986 #define SLEG_REFLIST(name, variable, type) SLEG_CONDREFLIST(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
987
994 #define SLEG_VECTOR(name, variable, type) SLEG_CONDVECTOR(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
995
1001 #define SLEG_STRUCTLIST(name, handler) SLEG_CONDSTRUCTLIST(name, handler, SL_MIN_VERSION, SL_MAX_VERSION)
1002
1007 #define SLC_VAR(name) {name, 0, SL_MIN_VERSION, SL_MAX_VERSION}
1008
1015 #define SLC_NULL(length, from, to) {{}, length, from, to}
1016
1018 #define SLC_END() {{}, 0, SL_MIN_VERSION, SL_MIN_VERSION}
1019
1026 static inline bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor = 0)
1027 {
1028 extern SaveLoadVersion _sl_version;
1029 extern byte _sl_minor_version;
1030 return _sl_version < major || (minor > 0 && _sl_version == major && _sl_minor_version < minor);
1031 }
1032
1040 static inline bool IsSavegameVersionBeforeOrAt(SaveLoadVersion major)
1041 {
1042 extern SaveLoadVersion _sl_version;
1043 return _sl_version <= major;
1044 }
1045
1053 static inline bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
1054 {
1055 extern const SaveLoadVersion SAVEGAME_VERSION;
1056 return version_from <= SAVEGAME_VERSION && SAVEGAME_VERSION < version_to;
1057 }
1058
1065 static inline VarType GetVarMemType(VarType type)
1066 {
1067 return type & 0xF0; // GB(type, 4, 4) << 4;
1068 }
1069
1076 static inline VarType GetVarFileType(VarType type)
1077 {
1078 return type & 0xF; // GB(type, 0, 4);
1079 }
1080
1086 static inline bool IsNumericType(VarType conv)
1087 {
1088 return GetVarMemType(conv) <= SLE_VAR_U64;
1089 }
1090
1096 static inline void *GetVariableAddress(const void *object, const SaveLoad &sld)
1097 {
1098 /* Entry is a null-variable, mostly used to read old savegames etc. */
1099 if (GetVarMemType(sld.conv) == SLE_VAR_NULL) {
1100 assert(sld.address_proc == nullptr);
1101 return nullptr;
1102 }
1103
1104 /* Everything else should be a non-null pointer. */
1105 assert(sld.address_proc != nullptr);
1106 return sld.address_proc(const_cast<void *>(object), sld.extra_data);
1107 }
1108
1109 int64 ReadValue(const void *ptr, VarType conv);
1110 void WriteValue(void *ptr, VarType conv, int64 val);
1111
1112 void SlSetArrayIndex(uint index);
1113 int SlIterateArray();
1114
1115 void SlSetStructListLength(size_t length);
1116 size_t SlGetStructListLength(size_t limit);
1117
1118 void SlAutolength(AutolengthProc *proc, void *arg);
1119 size_t SlGetFieldLength();
1120 void SlSetLength(size_t length);
1121 size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld);
1122 size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
1123
1124 byte SlReadByte();
1125 void SlWriteByte(byte b);
1126
1127 void SlGlobList(const SaveLoadTable &slt);
1128 void SlCopy(void *object, size_t length, VarType conv);
1129 std::vector<SaveLoad> SlTableHeader(const SaveLoadTable &slt);
1130 std::vector<SaveLoad> SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct);
1131 void SlObject(void *object, const SaveLoadTable &slt);
1132 void NORETURN SlError(StringID string, const char *extra_msg = nullptr);
1133 void NORETURN SlErrorCorrupt(const char *msg);
1134 void NORETURN SlErrorCorruptFmt(const char *format, ...) WARN_FORMAT(1, 2);
1135
1136 bool SaveloadCrashWithMissingNewGRFs();
1137
1143 static inline void SlSkipBytes(size_t length)
1144 {
1145 for (; length != 0; length--) SlReadByte();
1146 }
1147
1148 extern std::string _savegame_format;
1149 extern bool _do_autosave;
1150
1151 #endif /* SAVELOAD_H */
FileToSaveLoad::title
char title[255]
Internal name of the game.
Definition: saveload.h:360
SL_NULL
@ SL_NULL
Save null-bytes and load to nowhere.
Definition: saveload.h:649
SLV_131
@ SLV_131
131 18481
Definition: saveload.h:204
SGT_INVALID
@ SGT_INVALID
broken savegame (used internally)
Definition: saveload.h:375
SLV_187
@ SLV_187
187 25899 Linkgraph - restricted flows
Definition: saveload.h:271
SLV_65
@ SLV_65
65 10210
Definition: saveload.h:125
SaveLoad::version_to
SaveLoadVersion version_to
Save/load the variable before this savegame version.
Definition: saveload.h:661
SLV_186
@ SLV_186
186 25833 Objects storage
Definition: saveload.h:270
SLV_69
@ SLV_69
69 10319
Definition: saveload.h:129
REF_ORDER
@ REF_ORDER
Load/save a reference to an order.
Definition: saveload.h:537
SLV_144
@ SLV_144
144 20334
Definition: saveload.h:219
SaveLoadType
SaveLoadType
Type of data saved.
Definition: saveload.h:634
SLV_169
@ SLV_169
169 23816
Definition: saveload.h:249
DefaultSaveLoadHandler
Default handler for saving/loading an object to/from disk.
Definition: saveload.h:517
SLV_RIFF_TO_ARRAY
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
Definition: saveload.h:336
SLV_43
@ SLV_43
43 7642
Definition: saveload.h:98
SLV_114
@ SLV_114
114 15601
Definition: saveload.h:183
SLV_LINKGRAPH_TRAVEL_TIME
@ SLV_LINKGRAPH_TRAVEL_TIME
297 PR#9457 Store travel time in the linkgraph.
Definition: saveload.h:340
SGT_OTTD
@ SGT_OTTD
OTTD savegame.
Definition: saveload.h:373
SLV_62
@ SLV_62
62 9905
Definition: saveload.h:121
SLE_VAR_STR
@ SLE_VAR_STR
string pointer
Definition: saveload.h:591
SLV_TREES_WATER_CLASS
@ SLV_TREES_WATER_CLASS
213 PR#7405 WaterClass update for tree tiles.
Definition: saveload.h:303
GetVarFileType
static VarType GetVarFileType(VarType type)
Get the FileType of a setting.
Definition: saveload.h:1076
SLV_162
@ SLV_162
162 22713
Definition: saveload.h:241
SlErrorCorrupt
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
Definition: saveload.cpp:364
SLV_ROAD_TYPES
@ SLV_ROAD_TYPES
214 PR#6811 NewGRF road types.
Definition: saveload.h:304
SLV_133
@ SLV_133
133 18674
Definition: saveload.h:206
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition: saveload.h:35
REF_TOWN
@ REF_TOWN
Load/save a reference to a town.
Definition: saveload.h:540
SLV_85
@ SLV_85
85 11874
Definition: saveload.h:149
SLV_106
@ SLV_106
106 14919
Definition: saveload.h:174
SLV_40
@ SLV_40
40 7326
Definition: saveload.h:95
SL_STR
@ SL_STR
Save/load a string.
Definition: saveload.h:639
ProcessAsyncSaveFinish
void ProcessAsyncSaveFinish()
Handle async save finishes.
Definition: saveload.cpp:408
REF_ROADSTOPS
@ REF_ROADSTOPS
Load/save a reference to a bus/truck stop.
Definition: saveload.h:542
FileToSaveLoad::SetTitle
void SetTitle(const char *title)
Set the title of the file.
Definition: saveload.cpp:3431
SLV_32
@ SLV_32
32 6001
Definition: saveload.h:85
SLE_FILE_END
@ SLE_FILE_END
Used to mark end-of-header in tables.
Definition: saveload.h:562
SLV_155
@ SLV_155
155 21453
Definition: saveload.h:233
SLV_178
@ SLV_178
178 24789
Definition: saveload.h:260
SLV_124
@ SLV_124
124 16993
Definition: saveload.h:195
ChunkHandlerRef
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition: saveload.h:445
SLV_112
@ SLV_112
112 15290
Definition: saveload.h:181
SLV_GROUP_REPLACE_WAGON_REMOVAL
@ SLV_GROUP_REPLACE_WAGON_REMOVAL
291 PR#7441 Per-group wagon removal flag.
Definition: saveload.h:333
SLV_49
@ SLV_49
49 8969
Definition: saveload.h:105
SLV_146
@ SLV_146
146 20446
Definition: saveload.h:222
SLV_198
@ SLV_198
198 PR#6763 Switch town growth rate and counter to actual game ticks
Definition: saveload.h:285
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:47
SLV_117
@ SLV_117
117 16037
Definition: saveload.h:187
FileToSaveLoad::name
std::string name
Name of the file.
Definition: saveload.h:359
SLV_29
@ SLV_29
29 5070
Definition: saveload.h:81
SLV_79
@ SLV_79
79 11188
Definition: saveload.h:141
_do_autosave
bool _do_autosave
are we doing an autosave at the moment?
Definition: saveload.cpp:69
SaveLoad::size
size_t size
The sizeof size.
Definition: saveload.h:662
SLV_96
@ SLV_96
96 13226
Definition: saveload.h:162
SLV_166
@ SLV_166
166 23415
Definition: saveload.h:246
SLV_56
@ SLV_56
56 9667
Definition: saveload.h:114
SLF_ALLOW_NEWLINE
@ SLF_ALLOW_NEWLINE
Allow new lines in the strings.
Definition: saveload.h:628
SLV_84
@ SLV_84
84 11822
Definition: saveload.h:147
SLV_93
@ SLV_93
93 12648
Definition: saveload.h:158
SLV_52
@ SLV_52
52 9066
Definition: saveload.h:109
SLE_STR
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:800
SLV_157
@ SLV_157
157 21862
Definition: saveload.h:235
SLV_119
@ SLV_119
119 16242
Definition: saveload.h:189
SLV_SHIPS_STOP_IN_LOCKS
@ SLV_SHIPS_STOP_IN_LOCKS
206 PR#7150 Ship/lock movement changes.
Definition: saveload.h:295
SLV_FIX_CARGO_MONITOR
@ SLV_FIX_CARGO_MONITOR
207 PR#7175 v1.9 Cargo monitor data packing fix to support 64 cargotypes.
Definition: saveload.h:296
SGT_TTDP1
@ SGT_TTDP1
TTDP savegame ( -//- ) (data at NW border)
Definition: saveload.h:371
SaveLoadHandler::FixPointers
virtual void FixPointers(void *object) const
A post-load callback to fix SL_REF integers into pointers.
Definition: saveload.h:485
SLV_66
@ SLV_66
66 10211
Definition: saveload.h:126
FileToSaveLoad
Deals with the type of the savegame, independent of extension.
Definition: saveload.h:355
FileToSaveLoad::SetName
void SetName(const char *name)
Set the name of the file.
Definition: saveload.cpp:3422
SLV_87
@ SLV_87
87 12129
Definition: saveload.h:151
SLV_20
@ SLV_20
20 3403
Definition: saveload.h:71
SLE_VAR_NULL
@ SLE_VAR_NULL
useful to write zeros in savegame.
Definition: saveload.h:589
SaveOrLoad
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:3240
SlTableHeader
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition: saveload.cpp:1891
SLV_88
@ SLV_88
88 12134
Definition: saveload.h:152
SaveLoadHandler::GetLoadDescription
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Definition: saveload.cpp:3436
SLV_78
@ SLV_78
78 11176
Definition: saveload.h:140
ChunkHandler::type
ChunkType type
Type of the chunk.
Definition: saveload.h:410
SaveLoad::length
uint16 length
(Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
Definition: saveload.h:659
SLV_138
@ SLV_138
138 18942 1.0.x
Definition: saveload.h:212
SLV_35
@ SLV_35
35 6602
Definition: saveload.h:89
SLV_22
@ SLV_22
22 3726
Definition: saveload.h:73
SLV_104
@ SLV_104
104 14735
Definition: saveload.h:171
DefaultSaveLoadHandler::FixPointers
void FixPointers(void *object) const override
A post-load callback to fix SL_REF integers into pointers.
Definition: saveload.h:532
SLV_SERVE_NEUTRAL_INDUSTRIES
@ SLV_SERVE_NEUTRAL_INDUSTRIES
210 PR#7234 Company stations can serve industries with attached neutral stations.
Definition: saveload.h:300
SLV_15
@ SLV_15
15.0 2499
Definition: saveload.h:63
SLV_REMOVE_OPF
@ SLV_REMOVE_OPF
212 PR#7245 Remove OPF.
Definition: saveload.h:302
SlGlobList
void SlGlobList(const SaveLoadTable &slt)
Save or Load (a list of) global variables.
Definition: saveload.cpp:2083
SAVEGAME_VERSION
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
IsSavegameVersionBeforeOrAt
static bool IsSavegameVersionBeforeOrAt(SaveLoadVersion major)
Checks whether the savegame is below or at major.
Definition: saveload.h:1040
SLV_113
@ SLV_113
113 15340
Definition: saveload.h:182
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:408
SaveLoad::conv
VarType conv
Type of the variable to be saved; this field combines both FileVarType and MemVarType.
Definition: saveload.h:658
SLV_102
@ SLV_102
102 14332
Definition: saveload.h:169
SLV_181
@ SLV_181
181 25012
Definition: saveload.h:264
SlSetStructListLength
void SlSetStructListLength(size_t length)
Set the length of this list.
Definition: saveload.cpp:1809
SLV_175
@ SLV_175
175 24136
Definition: saveload.h:257
SLV_GROUP_LIVERIES
@ SLV_GROUP_LIVERIES
205 PR#7108 Livery storage change and group liveries.
Definition: saveload.h:294
SLV_83
@ SLV_83
83 11589
Definition: saveload.h:146
SLV_76
@ SLV_76
76 11139
Definition: saveload.h:138
SLV_53
@ SLV_53
53 9316
Definition: saveload.h:110
SaveLoadHandler
Handler for saving/loading an object to/from disk.
Definition: saveload.h:457
SLV_163
@ SLV_163
163 22767
Definition: saveload.h:242
SLV_179
@ SLV_179
179 24810
Definition: saveload.h:261
SLV_100
@ SLV_100
100 13952
Definition: saveload.h:167
SLV_141
@ SLV_141
141 19799
Definition: saveload.h:216
SLV_172
@ SLV_172
172 23947
Definition: saveload.h:253
SlGetStructListLength
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
Definition: saveload.cpp:1825
SLV_EXTEND_PERSISTENT_STORAGE
@ SLV_EXTEND_PERSISTENT_STORAGE
201 PR#6885 Extend NewGRF persistent storages.
Definition: saveload.h:289
SaveLoadCompat::name
std::string name
Name of the field.
Definition: saveload.h:677
SLE_FILE_TYPE_MASK
@ SLE_FILE_TYPE_MASK
Mask to get the file-type (and not any flags).
Definition: saveload.h:576
SLV_14
@ SLV_14
14.0 2441
Definition: saveload.h:61
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:670
SLV_61
@ SLV_61
61 9892
Definition: saveload.h:120
SLV_41
@ SLV_41
41 7348 0.5.x
Definition: saveload.h:96
SLV_10
@ SLV_10
10.0 2030
Definition: saveload.h:56
GenerateDefaultSaveName
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
Definition: saveload.cpp:3360
GetSaveLoadErrorString
const char * GetSaveLoadErrorString()
Get the string representation of the error message.
Definition: saveload.cpp:2950
SLV_118
@ SLV_118
118 16129
Definition: saveload.h:188
REF_STATION
@ REF_STATION
Load/save a reference to a station.
Definition: saveload.h:539
SLV_98
@ SLV_98
98 13375
Definition: saveload.h:164
SlWriteByte
void SlWriteByte(byte b)
Wrapper for writing a byte to the dumper.
Definition: saveload.cpp:433
SLE_VAR_STRB
@ SLE_VAR_STRB
string (with pre-allocated buffer)
Definition: saveload.h:590
IsNumericType
static bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
Definition: saveload.h:1086
SLV_EXTEND_INDUSTRY_CARGO_SLOTS
@ SLV_EXTEND_INDUSTRY_CARGO_SLOTS
202 PR#6867 Increase industry cargo slots to 16 in, 16 out
Definition: saveload.h:290
SLV_160
@ SLV_160
160 21974 1.1.x
Definition: saveload.h:239
AbstractFileType
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:16
FileToSaveLoad::abstract_ftype
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition: saveload.h:358
SLV_135
@ SLV_135
135 18719
Definition: saveload.h:209
SlSetLength
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
Definition: saveload.cpp:723
SLV_154
@ SLV_154
154 21426
Definition: saveload.h:231
SLV_5
@ SLV_5
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition: saveload.h:47
SL_SAVEBYTE
@ SL_SAVEBYTE
Save (but not load) a byte.
Definition: saveload.h:648
SLV_174
@ SLV_174
174 23973 1.2.x
Definition: saveload.h:255
SLV_161
@ SLV_161
161 22567
Definition: saveload.h:240
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition: saveload.h:627
SLE_FILE_HAS_LENGTH_FIELD
@ SLE_FILE_HAS_LENGTH_FIELD
Bit stored in savegame to indicate field has a length field for each entry.
Definition: saveload.h:577
SLV_156
@ SLV_156
156 21728
Definition: saveload.h:234
SLV_108
@ SLV_108
108 15045
Definition: saveload.h:176
SLV_111
@ SLV_111
111 15190
Definition: saveload.h:180
SLV_123
@ SLV_123
123 16909
Definition: saveload.h:194
SavegameType
SavegameType
Types of save games.
Definition: saveload.h:369
SLV_150
@ SLV_150
150 20857
Definition: saveload.h:227
SLV_115
@ SLV_115
115 15695
Definition: saveload.h:185
SLV_DOCK_DOCKINGTILES
@ SLV_DOCK_DOCKINGTILES
298 PR#9578 All tiles around docks may be docking tiles.
Definition: saveload.h:341
CH_TYPE_MASK
@ CH_TYPE_MASK
All ChunkType values have to be within this mask.
Definition: saveload.h:403
SLV_55
@ SLV_55
55 9638
Definition: saveload.h:113
SLV_164
@ SLV_164
164 23290
Definition: saveload.h:243
span
A trimmed down version of what std::span will be in C++20.
Definition: span_type.hpp:60
ChunkHandler::Save
virtual void Save() const
Save the chunk.
Definition: saveload.h:420
CH_READONLY
@ CH_READONLY
Chunk is never saved.
Definition: saveload.h:404
SGT_TTO
@ SGT_TTO
TTO savegame.
Definition: saveload.h:374
SLV_31
@ SLV_31
31 5999
Definition: saveload.h:84
SLV_TABLE_CHUNKS
@ SLV_TABLE_CHUNKS
295 PR#9322 Introduction of CH_TABLE and CH_SPARSE_TABLE.
Definition: saveload.h:338
SetSaveLoadError
void SetSaveLoadError(StringID str)
Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friend...
Definition: saveload.cpp:2944
SLV_MULTITILE_DOCKS
@ SLV_MULTITILE_DOCKS
216 PR#7380 Multiple docks per station.
Definition: saveload.h:307
ChunkHandler::id
uint32 id
Unique ID (4 letters).
Definition: saveload.h:409
SL_VAR
@ SL_VAR
Save/load a variable.
Definition: saveload.h:635
SLV_11
@ SLV_11
11.0 2033 11.1 2041
Definition: saveload.h:57
SLV_REMOVE_TOWN_CARGO_CACHE
@ SLV_REMOVE_TOWN_CARGO_CACHE
219 PR#8258 Remove town cargo acceptance and production caches.
Definition: saveload.h:310
SLV_67
@ SLV_67
67 10236
Definition: saveload.h:127
SLV_SCRIPT_MEMLIMIT
@ SLV_SCRIPT_MEMLIMIT
215 PR#7516 Limit on AI/GS memory consumption.
Definition: saveload.h:306
SLV_176
@ SLV_176
176 24446
Definition: saveload.h:258
SaveLoad::extra_data
size_t extra_data
Extra data for the callback proc.
Definition: saveload.h:664
SLV_126
@ SLV_126
126 17433
Definition: saveload.h:198
SLV_132
@ SLV_132
132 18522
Definition: saveload.h:205
SLV_86
@ SLV_86
86 12042
Definition: saveload.h:150
SL_REINIT
@ SL_REINIT
error that was caught in the middle of updating game state, need to clear it. (can only happen during...
Definition: saveload.h:351
SaveLoad::cmd
SaveLoadType cmd
The action to take with the saved/loaded type, All types need different action.
Definition: saveload.h:657
SLV_END_PATCHPACKS
@ SLV_END_PATCHPACKS
286 Last known patchpack to use a version just above ours.
Definition: saveload.h:326
SLV_27
@ SLV_27
27 4757
Definition: saveload.h:79
SLV_158
@ SLV_158
158 21933
Definition: saveload.h:236
SLV_130
@ SLV_130
130 18404
Definition: saveload.h:203
SLV_CUSTOM_SUBSIDY_DURATION
@ SLV_CUSTOM_SUBSIDY_DURATION
292 PR#9081 Configurable subsidy duration.
Definition: saveload.h:334
SLRefType
SLRefType
Type of reference (SLE_REF, SLE_CONDREF).
Definition: saveload.h:536
SLV_73
@ SLV_73
73 10903
Definition: saveload.h:134
SLV_46
@ SLV_46
46 8705
Definition: saveload.h:102
SLV_94
@ SLV_94
94 12816
Definition: saveload.h:159
SLV_74
@ SLV_74
74 11030
Definition: saveload.h:135
SaveLoadCompat::length
uint16 length
Length of the NULL field.
Definition: saveload.h:678
SLV_109
@ SLV_109
109 15075
Definition: saveload.h:177
SlAutolength
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
Definition: saveload.cpp:2093
SLV_54
@ SLV_54
54 9613
Definition: saveload.h:111
SLV_ROADVEH_PATH_CACHE
@ SLV_ROADVEH_PATH_CACHE
211 PR#7261 Add path cache for road vehicles.
Definition: saveload.h:301
SLV_TOWN_CARGOGEN
@ SLV_TOWN_CARGOGEN
208 PR#6965 New algorithms for town building cargo generation.
Definition: saveload.h:297
SLV_128
@ SLV_128
128 18281
Definition: saveload.h:200
SLV_MAPGEN_SETTINGS_REVAMP
@ SLV_MAPGEN_SETTINGS_REVAMP
290 PR#8891 v1.11 Revamp of some mapgen settings (snow coverage, desert coverage, heightmap height,...
Definition: saveload.h:332
SLV_EXTEND_CARGOTYPES
@ SLV_EXTEND_CARGOTYPES
199 PR#6802 Extend cargotypes to 64
Definition: saveload.h:286
SL_ARR
@ SL_ARR
Save/load a fixed-size array of SL_VAR elements.
Definition: saveload.h:642
SLE_FILE_STRINGID
@ SLE_FILE_STRINGID
StringID offset into strings-array.
Definition: saveload.h:571
REF_STORAGE
@ REF_STORAGE
Load/save a reference to a persistent storage.
Definition: saveload.h:546
SLV_168
@ SLV_168
168 23637
Definition: saveload.h:248
SaveLoadVersion
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
Definition: saveload.h:34
SLV_82
@ SLV_82
82 11410
Definition: saveload.h:145
SLV_183
@ SLV_183
183 25363 Cargodist
Definition: saveload.h:266
SLV_120
@ SLV_120
120 16439
Definition: saveload.h:191
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:1026
SLV_45
@ SLV_45
45 8501
Definition: saveload.h:101
SLV_90
@ SLV_90
90 12293
Definition: saveload.h:155
SaveLoadHandler::Save
virtual void Save(void *object) const
Save the object to disk.
Definition: saveload.h:467
REF_ENGINE_RENEWS
@ REF_ENGINE_RENEWS
Load/save a reference to an engine renewal (autoreplace).
Definition: saveload.h:543
SLV_REPAIR_OBJECT_DOCKING_TILES
@ SLV_REPAIR_OBJECT_DOCKING_TILES
299 PR#9594 Fixing issue with docking tiles overlapping objects.
Definition: saveload.h:342
SLV_116
@ SLV_116
116 15893 0.7.x
Definition: saveload.h:186
SLV_125
@ SLV_125
125 17113
Definition: saveload.h:197
SLV_7
@ SLV_7
7.0 1770
Definition: saveload.h:52
REF_VEHICLE
@ REF_VEHICLE
Load/save a reference to a vehicle.
Definition: saveload.h:538
SL_REF
@ SL_REF
Save/load a reference.
Definition: saveload.h:636
REF_CARGO_PACKET
@ REF_CARGO_PACKET
Load/save a reference to a cargo packet.
Definition: saveload.h:544
SL_STRUCT
@ SL_STRUCT
Save/load a struct.
Definition: saveload.h:637
SLV_23
@ SLV_23
23 3915
Definition: saveload.h:74
SLV_25
@ SLV_25
25 4259
Definition: saveload.h:77
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:63
DefaultSaveLoadHandler::Save
void Save(void *object) const override
Save the object to disk.
Definition: saveload.h:523
SLV_182
@ SLV_182
182 25115 FS#5492, r25259, r25296 Goal status
Definition: saveload.h:265
REF_VEHICLE_OLD
@ REF_VEHICLE_OLD
Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
Definition: saveload.h:541
SLV_50
@ SLV_50
50 8973
Definition: saveload.h:107
SLV_17
@ SLV_17
17.0 3212 17.1 3218
Definition: saveload.h:66
SLV_SHIP_CURVE_PENALTY
@ SLV_SHIP_CURVE_PENALTY
209 PR#7289 Configurable ship curve penalties.
Definition: saveload.h:298
SLV_145
@ SLV_145
145 20376
Definition: saveload.h:221
SLV_INDUSTRY_TEXT
@ SLV_INDUSTRY_TEXT
289 PR#8576 v1.11.0-RC1 Additional GS text for industries.
Definition: saveload.h:330
ChunkHandler::Load
virtual void Load() const =0
Load the chunk.
_savegame_format
std::string _savegame_format
how to compress savegames
Definition: saveload.cpp:68
SLV_170
@ SLV_170
170 23826
Definition: saveload.h:251
SLV_42
@ SLV_42
42 7573
Definition: saveload.h:97
DoExitSave
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
Definition: saveload.cpp:3350
SLV_136
@ SLV_136
136 18764
Definition: saveload.h:210
SLV_28
@ SLV_28
28 4987
Definition: saveload.h:80
SLV_107
@ SLV_107
107 15027
Definition: saveload.h:175
ChunkHandler::FixPointers
virtual void FixPointers() const
Fix the pointers.
Definition: saveload.h:434
SLV_64
@ SLV_64
64 10006
Definition: saveload.h:123
SLV_2
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition: saveload.h:38
SaveLoad::handler
std::shared_ptr< SaveLoadHandler > handler
Custom handler for Save/Load procs.
Definition: saveload.h:665
SlIsObjectCurrentlyValid
static 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:1053
SLV_142
@ SLV_142
142 20003
Definition: saveload.h:217
SLV_59
@ SLV_59
59 9779
Definition: saveload.h:117
SLV_SCRIPT_INT64
@ SLV_SCRIPT_INT64
296 PR#9415 SQInteger is 64bit but was saved as 32bit.
Definition: saveload.h:339
SLV_12
@ SLV_12
12.1 2046
Definition: saveload.h:59
SLV_139
@ SLV_139
139 19346
Definition: saveload.h:213
SL_VECTOR
@ SL_VECTOR
Save/load a vector of SL_VAR elements.
Definition: saveload.h:644
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:344
SaveLoadCompat::version_to
SaveLoadVersion version_to
Save/load the variable before this savegame version.
Definition: saveload.h:680
REF_LINK_GRAPH_JOB
@ REF_LINK_GRAPH_JOB
Load/save a reference to a link graph job.
Definition: saveload.h:548
SLV_8
@ SLV_8
8.0 1786
Definition: saveload.h:53
SaveLoadHandler::GetDescription
virtual SaveLoadTable GetDescription() const =0
Get the description of the fields in the savegame.
SGT_TTD
@ SGT_TTD
TTD savegame (can be detected incorrectly)
Definition: saveload.h:370
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
SlErrorCorruptFmt
void NORETURN SlErrorCorruptFmt(const char *format,...)
Issue an SlErrorCorrupt with a format string.
Definition: saveload.cpp:376
SLV_33
@ SLV_33
33 6440
Definition: saveload.h:86
SLV_16
@ SLV_16
16.0 2817 16.1 3155
Definition: saveload.h:64
SLV_30
@ SLV_30
30 5946
Definition: saveload.h:83
SaveLoadCompat
SaveLoad information for backwards compatibility.
Definition: saveload.h:676
DoAutoOrNetsave
void DoAutoOrNetsave(FiosNumberedSaveName &counter)
Create an autosave or netsave.
Definition: saveload.cpp:3331
DefaultSaveLoadHandler::LoadCheck
void LoadCheck(void *object) const override
Similar to load, but used only to validate savegames.
Definition: saveload.h:529
FiosNumberedSaveName
A savegame name automatically numbered.
Definition: fios.h:131
REF_ORDERLIST
@ REF_ORDERLIST
Load/save a reference to an orderlist.
Definition: saveload.h:545
SLV_127
@ SLV_127
127 17439
Definition: saveload.h:199
DetailedFileType
DetailedFileType
Kinds of files in each AbstractFileType.
Definition: fileio_type.h:28
SLV_193
@ SLV_193
193 26802
Definition: saveload.h:279
SLV_189
@ SLV_189
189 26450 Hierarchical vehicle subgroups
Definition: saveload.h:273
SLV_47
@ SLV_47
47 8735
Definition: saveload.h:103
SLV_VEH_MOTION_COUNTER
@ SLV_VEH_MOTION_COUNTER
288 PR#8591 Desync safe motion counter
Definition: saveload.h:329
SLV_GS_INDUSTRY_CONTROL
@ SLV_GS_INDUSTRY_CONTROL
287 PR#7912 and PR#8115 GS industry control.
Definition: saveload.h:328
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:50
SL_REFLIST
@ SL_REFLIST
Save/load a list of SL_REF elements.
Definition: saveload.h:645
VarTypes
VarTypes
VarTypes is the general bitmasked magic type that tells us certain characteristics about the variable...
Definition: saveload.h:559
SaveFilter
Interface for filtering a savegame till it is written.
Definition: saveload_filter.h:60
SLV_36
@ SLV_36
36 6624
Definition: saveload.h:90
GetVarMemType
static VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
Definition: saveload.h:1065
SLV_77
@ SLV_77
77 11172
Definition: saveload.h:139
SLV_91
@ SLV_91
91 12347
Definition: saveload.h:156
SLV_44
@ SLV_44
44 8144
Definition: saveload.h:99
SLV_197
@ SLV_197
197 27978 v1.8
Definition: saveload.h:284
SLV_24
@ SLV_24
24 4150
Definition: saveload.h:75
_sl_minor_version
byte _sl_minor_version
the minor savegame version, DO NOT USE!
Definition: saveload.cpp:67
DefaultSaveLoadHandler::GetDescription
SaveLoadTable GetDescription() const override
Get the description of the fields in the savegame.
Definition: saveload.h:519
SLV_81
@ SLV_81
81 11244
Definition: saveload.h:144
SLV_60
@ SLV_60
60 9874
Definition: saveload.h:119
SLV_89
@ SLV_89
89 12160
Definition: saveload.h:153
SLV_194
@ SLV_194
194 26881 v1.5
Definition: saveload.h:280
SLV_149
@ SLV_149
149 20832
Definition: saveload.h:225
SlReadByte
byte SlReadByte()
Wrapper for reading a byte from the buffer.
Definition: saveload.cpp:424
SaveLoadHandler::Load
virtual void Load(void *object) const
Load the object from disk.
Definition: saveload.h:473
SLV_134
@ SLV_134
134 18703
Definition: saveload.h:207
DefaultSaveLoadHandler::GetCompatDescription
SaveLoadCompatTable GetCompatDescription() const override
Get the pre-header description of the fields in the savegame.
Definition: saveload.h:520
SLV_122
@ SLV_122
122 16855
Definition: saveload.h:193
SaveLoadHandler::LoadCheck
virtual void LoadCheck(void *object) const
Similar to load, but used only to validate savegames.
Definition: saveload.h:479
SLV_129
@ SLV_129
129 18292
Definition: saveload.h:201
SLV_184
@ SLV_184
184 25508 Unit localisation split
Definition: saveload.h:267
SLV_38
@ SLV_38
38 7195
Definition: saveload.h:92
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
SaveLoad::version_from
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
Definition: saveload.h:660
SLV_147
@ SLV_147
147 20621
Definition: saveload.h:223
SaveOrLoadResult
SaveOrLoadResult
Save or load result codes.
Definition: saveload.h:348
SLV_105
@ SLV_105
105 14803
Definition: saveload.h:173
SLV_165
@ SLV_165
165 23304
Definition: saveload.h:245
SLV_3
@ SLV_3
3.x lost
Definition: saveload.h:40
FiosType
FiosType
Elements of a file system that are recognized.
Definition: fileio_type.h:67
SLV_ENDING_YEAR
@ SLV_ENDING_YEAR
218 PR#7747 v1.10 Configurable ending year.
Definition: saveload.h:309
SLE_VAR_STRQ
@ SLE_VAR_STRQ
string pointer enclosed in quotes
Definition: saveload.h:592
ChunkType
ChunkType
Type of a chunk.
Definition: saveload.h:396
SLV_148
@ SLV_148
148 20659
Definition: saveload.h:224
SlGetFieldLength
size_t SlGetFieldLength()
Get the length of the current object.
Definition: saveload.cpp:792
SLV_TRADING_AGE
@ SLV_TRADING_AGE
217 PR#7780 Configurable company trading age.
Definition: saveload.h:308
SLV_188
@ SLV_188
188 26169 v1.4 FS#5831 Unify RV travel time
Definition: saveload.h:272
SLV_99
@ SLV_99
99 13838
Definition: saveload.h:165
SLV_167
@ SLV_167
167 23504
Definition: saveload.h:247
SLV_68
@ SLV_68
68 10266
Definition: saveload.h:128
REF_LINK_GRAPH
@ REF_LINK_GRAPH
Load/save a reference to a link graph.
Definition: saveload.h:547
SLV_21
@ SLV_21
21 3472 0.4.x
Definition: saveload.h:72
SLV_97
@ SLV_97
97 13256
Definition: saveload.h:163
SLV_SHIP_PATH_CACHE
@ SLV_SHIP_PATH_CACHE
203 PR#7072 Add path cache for ships
Definition: saveload.h:291
LoadFilter
Interface for filtering a savegame till it is loaded.
Definition: saveload_filter.h:14
SLV_173
@ SLV_173
173 23967 1.2.0-RC1
Definition: saveload.h:254
SL_DEQUE
@ SL_DEQUE
Save/load a deque of SL_VAR elements.
Definition: saveload.h:643
SLV_171
@ SLV_171
171 23835
Definition: saveload.h:252
SLV_185
@ SLV_185
185 25620 Storybooks
Definition: saveload.h:269
SLV_103
@ SLV_103
103 14598
Definition: saveload.h:170
SLV_SAVELOAD_LIST_LENGTH
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
Definition: saveload.h:335
SLV_80
@ SLV_80
80 11228
Definition: saveload.h:143
GetVariableAddress
static void * GetVariableAddress(const void *object, const SaveLoad &sld)
Get the address of the variable.
Definition: saveload.h:1096
SlCopy
void SlCopy(void *object, size_t length, VarType conv)
Copy a list of SL_VARs to/from a savegame.
Definition: saveload.cpp:1151
LoadWithFilter
SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader)
Load the game using a (reader) filter.
Definition: saveload.cpp:3220
WriteValue
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
Definition: saveload.cpp:828
SLV_180
@ SLV_180
180 24998 1.3.x
Definition: saveload.h:263
SLV_101
@ SLV_101
101 14233
Definition: saveload.h:168
SLV_195
@ SLV_195
195 27572 v1.6.1
Definition: saveload.h:282
SLV_19
@ SLV_19
19 3396
Definition: saveload.h:69
SlCompatTableHeader
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition: saveload.cpp:2029
SLV_191
@ SLV_191
191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store location...
Definition: saveload.h:276
SLV_58
@ SLV_58
58 9762
Definition: saveload.h:116
SLV_192
@ SLV_192
192 26700 FS#6066 Fix saving of order backups
Definition: saveload.h:278
SLV_70
@ SLV_70
70 10541
Definition: saveload.h:131
SaveWithFilter
SaveOrLoadResult SaveWithFilter(struct SaveFilter *writer, bool threaded)
Save the game using a (writer) filter.
Definition: saveload.cpp:3062
SL_ERROR
@ SL_ERROR
error that was caught before internal structures were modified
Definition: saveload.h:350
FileToSaveLoad::detail_ftype
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition: saveload.h:357
SLV_92
@ SLV_92
92 12381 0.6.x
Definition: saveload.h:157
SLV_121
@ SLV_121
121 16694
Definition: saveload.h:192
SaveLoad::address_proc
SaveLoadAddrProc * address_proc
Callback proc the get the actual variable address in memory.
Definition: saveload.h:663
SLV_151
@ SLV_151
151 20918
Definition: saveload.h:228
SLV_75
@ SLV_75
75 11107
Definition: saveload.h:137
SLV_95
@ SLV_95
95 12924
Definition: saveload.h:161
SLV_110
@ SLV_110
110 15148
Definition: saveload.h:179
SaveLoad::name
std::string name
Name of this field (optional, used for tables).
Definition: saveload.h:656
SaveloadCrashWithMissingNewGRFs
void NORETURN bool SaveloadCrashWithMissingNewGRFs()
Did loading the savegame cause a crash? If so, were NewGRFs missing?
Definition: afterload.cpp:365
ChunkHandler::LoadCheck
virtual void LoadCheck(size_t len=0) const
Load the chunk for game preview.
Definition: saveload.cpp:2116
SaveLoadHandler::GetCompatDescription
virtual SaveLoadCompatTable GetCompatDescription() const =0
Get the pre-header description of the fields in the savegame.
SLV_START_PATCHPACKS
@ SLV_START_PATCHPACKS
220 First known patchpack to use a version just above ours.
Definition: saveload.h:325
SLV_4
@ 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:41
FileToSaveLoad::SetMode
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:3393
SaveLoad
SaveLoad type struct.
Definition: saveload.h:655
SLV_153
@ SLV_153
153 21263
Definition: saveload.h:230
SLV_140
@ SLV_140
140 19382
Definition: saveload.h:215
SLV_26
@ SLV_26
26 4466
Definition: saveload.h:78
SLV_196
@ SLV_196
196 27778 v1.7
Definition: saveload.h:283
SLV_9
@ SLV_9
9.0 1909
Definition: saveload.h:54
SL_OK
@ SL_OK
completed successfully
Definition: saveload.h:349
SaveLoadCompat::version_from
SaveLoadVersion version_from
Save/load the variable starting from this savegame version.
Definition: saveload.h:679
SL_STDSTR
@ SL_STDSTR
Save/load a std::string.
Definition: saveload.h:640
SLV_51
@ SLV_51
51 8978
Definition: saveload.h:108
SLV_63
@ SLV_63
63 9956
Definition: saveload.h:122
SGT_TTDP2
@ SGT_TTDP2
TTDP savegame in new format (data at SE border)
Definition: saveload.h:372
SlSkipBytes
static 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:1143
_sl_version
SaveLoadVersion _sl_version
the major savegame version identifier
Definition: saveload.cpp:66
SlObject
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition: saveload.cpp:1838
SLE_VAR_NAME
@ SLE_VAR_NAME
old custom name to be converted to a char pointer
Definition: saveload.h:593
SLV_137
@ SLV_137
137 18912
Definition: saveload.h:211
SLV_143
@ SLV_143
143 20048
Definition: saveload.h:218
SLV_34
@ SLV_34
34 6455
Definition: saveload.h:87
SLV_57
@ SLV_57
57 9691
Definition: saveload.h:115
SLV_72
@ SLV_72
72 10601
Definition: saveload.h:133
SLV_152
@ SLV_152
152 21171
Definition: saveload.h:229
SlCalcObjLength
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt)
Calculate the size of an object.
Definition: saveload.cpp:1594
SLV_37
@ SLV_37
37 7182
Definition: saveload.h:91
SLV_1
@ SLV_1
1.0 0.1.x, 0.2.x
Definition: saveload.h:37
SlError
void NORETURN SlError(StringID string, const char *extra_msg=nullptr)
Error handler.
Definition: saveload.cpp:332
SLV_13
@ SLV_13
13.1 2080 0.4.0, 0.4.0.1
Definition: saveload.h:60
SLV_190
@ SLV_190
190 26547 Separate order travel and wait times
Definition: saveload.h:275
FileToSaveLoad::file_op
SaveLoadOperation file_op
File operation to perform.
Definition: saveload.h:356
SLV_SHIP_ROTATION
@ SLV_SHIP_ROTATION
204 PR#7065 Add extra rotation stages for ships.
Definition: saveload.h:292
SLV_39
@ SLV_39
39 7269
Definition: saveload.h:93
SLV_48
@ SLV_48
48 8935
Definition: saveload.h:104
DefaultSaveLoadHandler::Load
void Load(void *object) const override
Load the object from disk.
Definition: saveload.h:526
SLV_159
@ SLV_159
159 21962
Definition: saveload.h:237
SLV_18
@ SLV_18
18 3227
Definition: saveload.h:68
SLV_177
@ SLV_177
177 24619
Definition: saveload.h:259
SL_STRUCTLIST
@ SL_STRUCTLIST
Save/load a list of structs.
Definition: saveload.h:646
SLV_EXTEND_RAILTYPES
@ SLV_EXTEND_RAILTYPES
200 PR#6805 Extend railtypes to 64, adding uint16 to map array.
Definition: saveload.h:288
SLV_71
@ SLV_71
71 10567
Definition: saveload.h:132
ReadValue
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition: saveload.cpp:804