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/>.
8 /** @file saveload.h Functions/types related to saving and loading games. */
13 #include "saveload_error.hpp"
14 #include "../fileio_type.h"
16 #include "../core/span_type.hpp"
19 * Previous savegame versions, the trunk revision where they were
20 * introduced and the released version that had that particular
22 * Up to savegame version 18 there is a minor version as well.
24 * Older entries keep their original numbering.
26 * Newer entries should use a descriptive labels, numeric version
27 * and PR can be added to comment.
29 * Note that this list must not be reordered.
31 enum SaveLoadVersion
: uint16
{
32 SL_MIN_VERSION
, ///< First savegame version
34 SLV_1
, ///< 1.0 0.1.x, 0.2.x
39 * 4.1 122 0.3.3, 0.3.4
53 SLV_10
, ///< 10.0 2030
54 SLV_11
, /**< 11.0 2033
56 SLV_12
, ///< 12.1 2046
57 SLV_13
, ///< 13.1 2080 0.4.0, 0.4.0.1
58 SLV_14
, ///< 14.0 2441
60 SLV_15
, ///< 15.0 2499
61 SLV_16
, /**< 16.0 2817
63 SLV_17
, /**< 17.0 3212
69 SLV_21
, ///< 21 3472 0.4.x
93 SLV_41
, ///< 41 7348 0.5.x
120 SLV_64
, ///< 64 10006
122 SLV_65
, ///< 65 10210
123 SLV_66
, ///< 66 10211
124 SLV_67
, ///< 67 10236
125 SLV_68
, ///< 68 10266
126 SLV_69
, ///< 69 10319
128 SLV_70
, ///< 70 10541
129 SLV_71
, ///< 71 10567
130 SLV_72
, ///< 72 10601
131 SLV_73
, ///< 73 10903
132 SLV_74
, ///< 74 11030
134 SLV_75
, ///< 75 11107
135 SLV_76
, ///< 76 11139
136 SLV_77
, ///< 77 11172
137 SLV_78
, ///< 78 11176
138 SLV_79
, ///< 79 11188
140 SLV_80
, ///< 80 11228
141 SLV_81
, ///< 81 11244
142 SLV_82
, ///< 82 11410
143 SLV_83
, ///< 83 11589
144 SLV_84
, ///< 84 11822
146 SLV_85
, ///< 85 11874
147 SLV_86
, ///< 86 12042
148 SLV_87
, ///< 87 12129
149 SLV_88
, ///< 88 12134
150 SLV_89
, ///< 89 12160
152 SLV_90
, ///< 90 12293
153 SLV_91
, ///< 91 12347
154 SLV_92
, ///< 92 12381 0.6.x
155 SLV_93
, ///< 93 12648
156 SLV_94
, ///< 94 12816
158 SLV_95
, ///< 95 12924
159 SLV_96
, ///< 96 13226
160 SLV_97
, ///< 97 13256
161 SLV_98
, ///< 98 13375
162 SLV_99
, ///< 99 13838
164 SLV_100
, ///< 100 13952
165 SLV_101
, ///< 101 14233
166 SLV_102
, ///< 102 14332
167 SLV_103
, ///< 103 14598
168 SLV_104
, ///< 104 14735
170 SLV_105
, ///< 105 14803
171 SLV_106
, ///< 106 14919
172 SLV_107
, ///< 107 15027
173 SLV_108
, ///< 108 15045
174 SLV_109
, ///< 109 15075
176 SLV_110
, ///< 110 15148
177 SLV_111
, ///< 111 15190
178 SLV_112
, ///< 112 15290
179 SLV_113
, ///< 113 15340
180 SLV_114
, ///< 114 15601
182 SLV_115
, ///< 115 15695
183 SLV_116
, ///< 116 15893 0.7.x
184 SLV_117
, ///< 117 16037
185 SLV_118
, ///< 118 16129
186 SLV_119
, ///< 119 16242
188 SLV_120
, ///< 120 16439
189 SLV_121
, ///< 121 16694
190 SLV_122
, ///< 122 16855
191 SLV_123
, ///< 123 16909
192 SLV_124
, ///< 124 16993
194 SLV_125
, ///< 125 17113
195 SLV_126
, ///< 126 17433
196 SLV_127
, ///< 127 17439
197 SLV_128
, ///< 128 18281
198 SLV_129
, ///< 129 18292
200 SLV_130
, ///< 130 18404
201 SLV_131
, ///< 131 18481
202 SLV_132
, ///< 132 18522
203 SLV_133
, ///< 133 18674
204 SLV_134
, ///< 134 18703
206 SLV_135
, ///< 135 18719
207 SLV_136
, ///< 136 18764
208 SLV_137
, ///< 137 18912
209 SLV_138
, ///< 138 18942 1.0.x
210 SLV_139
, ///< 139 19346
212 SLV_140
, ///< 140 19382
213 SLV_141
, ///< 141 19799
214 SLV_142
, ///< 142 20003
215 SLV_143
, ///< 143 20048
216 SLV_144
, ///< 144 20334
218 SLV_145
, ///< 145 20376
219 SLV_146
, ///< 146 20446
220 SLV_147
, ///< 147 20621
221 SLV_148
, ///< 148 20659
222 SLV_149
, ///< 149 20832
224 SLV_150
, ///< 150 20857
225 SLV_151
, ///< 151 20918
226 SLV_152
, ///< 152 21171
227 SLV_153
, ///< 153 21263
228 SLV_154
, ///< 154 21426
230 SLV_155
, ///< 155 21453
231 SLV_156
, ///< 156 21728
232 SLV_157
, ///< 157 21862
233 SLV_158
, ///< 158 21933
234 SLV_159
, ///< 159 21962
236 SLV_160
, ///< 160 21974 1.1.x
237 SLV_161
, ///< 161 22567
238 SLV_162
, ///< 162 22713
239 SLV_163
, ///< 163 22767
240 SLV_164
, ///< 164 23290
242 SLV_165
, ///< 165 23304
243 SLV_166
, ///< 166 23415
244 SLV_167
, ///< 167 23504
245 SLV_168
, ///< 168 23637
246 SLV_169
, ///< 169 23816
248 SLV_170
, ///< 170 23826
249 SLV_171
, ///< 171 23835
250 SLV_172
, ///< 172 23947
251 SLV_173
, ///< 173 23967 1.2.0-RC1
252 SLV_174
, ///< 174 23973 1.2.x
254 SLV_175
, ///< 175 24136
255 SLV_176
, ///< 176 24446
256 SLV_177
, ///< 177 24619
257 SLV_178
, ///< 178 24789
258 SLV_179
, ///< 179 24810
260 SLV_180
, ///< 180 24998 1.3.x
261 SLV_181
, ///< 181 25012
262 SLV_182
, ///< 182 25115 FS#5492, r25259, r25296 Goal status
263 SLV_183
, ///< 183 25363 Cargodist
264 SLV_184
, ///< 184 25508 Unit localisation split
266 SLV_185
, ///< 185 25620 Storybooks
267 SLV_186
, ///< 186 25833 Objects storage
268 SLV_187
, ///< 187 25899 Linkgraph - restricted flows
269 SLV_188
, ///< 188 26169 v1.4 FS#5831 Unify RV travel time
270 SLV_189
, ///< 189 26450 Hierarchical vehicle subgroups
272 SLV_190
, ///< 190 26547 Separate order travel and wait times
273 SLV_191
, ///< 191 26636 FS#6026 Fix disaster vehicle storage (No bump)
274 ///< 191 26646 FS#6041 Linkgraph - store locations
275 SLV_192
, ///< 192 26700 FS#6066 Fix saving of order backups
276 SLV_193
, ///< 193 26802
277 SLV_194
, ///< 194 26881 v1.5
279 SLV_195
, ///< 195 27572 v1.6.1
280 SLV_196
, ///< 196 27778 v1.7
281 SLV_197
, ///< 197 27978 v1.8
282 SLV_198
, ///< 198 PR#6763 Switch town growth rate and counter to actual game ticks
283 SLV_EXTEND_CARGOTYPES
, ///< 199 PR#6802 Extend cargotypes to 64
285 SLV_EXTEND_RAILTYPES
, ///< 200 PR#6805 Extend railtypes to 64, adding uint16 to map array.
286 SLV_EXTEND_PERSISTENT_STORAGE
, ///< 201 PR#6885 Extend NewGRF persistent storages.
287 SLV_EXTEND_INDUSTRY_CARGO_SLOTS
, ///< 202 PR#6867 Increase industry cargo slots to 16 in, 16 out
288 SLV_SHIP_PATH_CACHE
, ///< 203 PR#7072 Add path cache for ships
289 SLV_SHIP_ROTATION
, ///< 204 PR#7065 Add extra rotation stages for ships.
291 SLV_GROUP_LIVERIES
, ///< 205 PR#7108 Livery storage change and group liveries.
292 SLV_SHIPS_STOP_IN_LOCKS
, ///< 206 PR#7150 Ship/lock movement changes.
293 SLV_FIX_CARGO_MONITOR
, ///< 207 PR#7175 v1.9 Cargo monitor data packing fix to support 64 cargotypes.
294 SLV_TOWN_CARGOGEN
, ///< 208 PR#6965 New algorithms for town building cargo generation.
295 SLV_SHIP_CURVE_PENALTY
, ///< 209 PR#7289 Configurable ship curve penalties.
297 SLV_SERVE_NEUTRAL_INDUSTRIES
, ///< 210 PR#7234 Company stations can serve industries with attached neutral stations.
298 SLV_ROADVEH_PATH_CACHE
, ///< 211 PR#7261 Add path cache for road vehicles.
299 SLV_REMOVE_OPF
, ///< 212 PR#7245 Remove OPF.
300 SLV_TREES_WATER_CLASS
, ///< 213 PR#7405 WaterClass update for tree tiles.
301 SLV_ROAD_TYPES
, ///< 214 PR#6811 NewGRF road types.
303 SLV_SCRIPT_MEMLIMIT
, ///< 215 PR#7516 Limit on AI/GS memory consumption.
304 SLV_MULTITILE_DOCKS
, ///< 216 PR#7380 Multiple docks per station.
305 SLV_TRADING_AGE
, ///< 217 PR#7780 Configurable company trading age.
306 SLV_ENDING_YEAR
, ///< 218 PR#7747 v1.10 Configurable ending year.
307 SLV_REMOVE_TOWN_CARGO_CACHE
, ///< 219 PR#8258 Remove town cargo acceptance and production caches.
309 /* Patchpacks for a while considered it a good idea to jump a few versions
310 * above our version for their savegames. But as time continued, this gap
311 * has been closing, up to the point we would start to reuse versions from
312 * their patchpacks. This is not a problem from our perspective: the
313 * savegame will simply fail to load because they all contain chunks we
314 * cannot digest. But, this gives for ugly errors. As we have plenty of
315 * versions anyway, we simply skip the versions we know belong to
316 * patchpacks. This way we can present the user with a clean error
317 * indicate they are loading a savegame from a patchpack.
318 * For future patchpack creators: please follow a system like JGRPP, where
319 * the version is masked with 0x8000, and the true version is stored in
320 * its own chunk with feature toggles.
322 SLV_START_PATCHPACKS
, ///< 220 First known patchpack to use a version just above ours.
323 SLV_END_PATCHPACKS
= 286, ///< 286 Last known patchpack to use a version just above ours.
325 SLV_GS_INDUSTRY_CONTROL
, ///< 287 PR#7912 and PR#8115 GS industry control.
326 SLV_VEH_MOTION_COUNTER
, ///< 288 PR#8591 Desync safe motion counter
327 SLV_INDUSTRY_TEXT
, ///< 289 PR#8576 v1.11.0-RC1 Additional GS text for industries.
329 SLV_MAPGEN_SETTINGS_REVAMP
, ///< 290 PR#8891 v1.11 Revamp of some mapgen settings (snow coverage, desert coverage, heightmap height, custom terrain type).
330 SLV_GROUP_REPLACE_WAGON_REMOVAL
, ///< 291 PR#7441 Per-group wagon removal flag.
331 SLV_CUSTOM_SUBSIDY_DURATION
, ///< 292 PR#9081 Configurable subsidy duration.
332 SLV_SAVELOAD_LIST_LENGTH
, ///< 293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
333 SLV_RIFF_TO_ARRAY
, ///< 294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
335 SLV_TABLE_CHUNKS
, ///< 295 PR#9322 Introduction of CH_TABLE and CH_SPARSE_TABLE.
336 SLV_SCRIPT_INT64
, ///< 296 PR#9415 SQInteger is 64bit but was saved as 32bit.
337 SLV_LINKGRAPH_TRAVEL_TIME
, ///< 297 PR#9457 v12.0-RC1 Store travel time in the linkgraph.
338 SLV_DOCK_DOCKINGTILES
, ///< 298 PR#9578 All tiles around docks may be docking tiles.
339 SLV_REPAIR_OBJECT_DOCKING_TILES
, ///< 299 PR#9594 v12.0 Fixing issue with docking tiles overlapping objects.
341 SLV_U64_TICK_COUNTER
, ///< 300 PR#10035 Make tick counter 64bit to avoid wrapping.
342 SLV_LAST_LOADING_TICK
, ///< 301 PR#9693 Store tick of last loading for vehicles.
343 SLV_MULTITRACK_LEVEL_CROSSINGS
, ///< 302 PR#9931 v13.0 Multi-track level crossings.
344 SLV_NEWGRF_ROAD_STOPS
, ///< 303 PR#10144 NewGRF road stops.
345 SLV_LINKGRAPH_EDGES
, ///< 304 PR#10314 Explicitly store link graph edges destination, PR#10471 int64 instead of uint64 league rating
347 SLV_VELOCITY_NAUTICAL
, ///< 305 PR#10594 Separation of land and nautical velocity (knots!)
348 SLV_CONSISTENT_PARTIAL_Z
, ///< 306 PR#10570 Conversion from an inconsistent partial Z calculation for slopes, to one that is (more) consistent.
349 SLV_MORE_CARGO_AGE
, ///< 307 PR#10596 Track cargo age for a longer period.
350 SLV_LINKGRAPH_SECONDS
, ///< 308 PR#10610 Store linkgraph update intervals in seconds instead of days.
351 SLV_AI_START_DATE
, ///< 309 PR#10653 Removal of individual AI start dates and added a generic one.
353 SLV_EXTEND_VEHICLE_RANDOM
, ///< 310 PR#10701 Extend vehicle random bits.
354 SLV_EXTEND_ENTITY_MAPPING
, ///< 311 PR#10672 Extend entity mapping range.
355 SLV_DISASTER_VEH_STATE
, ///< 312 PR#10798 Explicit storage of disaster vehicle state.
357 SL_MAX_VERSION
, ///< Highest possible saveload version
360 /** Save or load result codes. */
361 enum SaveOrLoadResult
{
362 SL_OK
= 0, ///< completed successfully
363 SL_ERROR
= 1, ///< error that was caught before internal structures were modified
364 SL_REINIT
= 2, ///< error that was caught in the middle of updating game state, need to clear it. (can only happen during load)
367 /** Deals with the type of the savegame, independent of extension */
368 struct FileToSaveLoad
{
369 SaveLoadOperation file_op
; ///< File operation to perform.
370 DetailedFileType detail_ftype
; ///< Concrete file type (PNG, BMP, old save, etc).
371 AbstractFileType abstract_ftype
; ///< Abstract type of file (scenario, heightmap, etc).
372 std::string name
; ///< Name of the file.
373 std::string title
; ///< Internal name of the game.
375 void SetMode(FiosType ft
);
376 void SetMode(SaveLoadOperation fop
, AbstractFileType aft
, DetailedFileType dft
);
377 void Set(const FiosItem
&item
);
380 /** Types of save games. */
382 SGT_TTD
, ///< TTD savegame (can be detected incorrectly)
383 SGT_TTDP1
, ///< TTDP savegame ( -//- ) (data at NW border)
384 SGT_TTDP2
, ///< TTDP savegame in new format (data at SE border)
385 SGT_OTTD
, ///< OTTD savegame
386 SGT_TTO
, ///< TTO savegame
387 SGT_INVALID
= 0xFF, ///< broken savegame (used internally)
390 extern FileToSaveLoad _file_to_saveload
;
392 void GenerateDefaultSaveName(char *buf
, const char *last
);
393 void SetSaveLoadError(StringID str
);
394 const char *GetSaveLoadErrorString();
395 SaveOrLoadResult
SaveOrLoad(const std::string
&filename
, SaveLoadOperation fop
, DetailedFileType dft
, Subdirectory sb
, bool threaded
= true);
396 void WaitTillSaved();
397 void ProcessAsyncSaveFinish();
400 void DoAutoOrNetsave(FiosNumberedSaveName
&counter
);
402 SaveOrLoadResult
SaveWithFilter(struct SaveFilter
*writer
, bool threaded
);
403 SaveOrLoadResult
LoadWithFilter(struct LoadFilter
*reader
);
405 typedef void AutolengthProc(void *arg
);
407 /** Type of a chunk. */
415 CH_TYPE_MASK
= 0xf, ///< All ChunkType values have to be within this mask.
416 CH_READONLY
, ///< Chunk is never saved.
419 /** Handlers and description of chunk. */
420 struct ChunkHandler
{
421 uint32 id
; ///< Unique ID (4 letters).
422 ChunkType type
; ///< Type of the chunk. @see ChunkType
424 ChunkHandler(uint32 id
, ChunkType type
) : id(id
), type(type
) {}
426 virtual ~ChunkHandler() {}
430 * Must be overridden, unless Chunk type is CH_READONLY.
432 virtual void Save() const { NOT_REACHED(); }
436 * Must be overridden.
438 virtual void Load() const = 0;
442 * Pointers are saved using the index of the pointed object.
443 * On load, pointers are filled with indices and need to be fixed to point to the real object.
444 * Must be overridden if the chunk saves any pointer.
446 virtual void FixPointers() const {}
449 * Load the chunk for game preview.
450 * Default implementation just skips the data.
451 * @param len Number of bytes to skip.
453 virtual void LoadCheck(size_t len
= 0) const;
455 std::string
GetName() const
458 + static_cast<char>(this->id
>> 24)
459 + static_cast<char>(this->id
>> 16)
460 + static_cast<char>(this->id
>> 8)
461 + static_cast<char>(this->id
);
465 /** A reference to ChunkHandler. */
466 using ChunkHandlerRef
= std::reference_wrapper
<const ChunkHandler
>;
468 /** A table of ChunkHandler entries. */
469 using ChunkHandlerTable
= span
<const ChunkHandlerRef
>;
471 /** A table of SaveLoad entries. */
472 using SaveLoadTable
= span
<const struct SaveLoad
>;
474 /** A table of SaveLoadCompat entries. */
475 using SaveLoadCompatTable
= span
<const struct SaveLoadCompat
>;
477 /** Handler for saving/loading an object to/from disk. */
478 class SaveLoadHandler
{
480 std::optional
<std::vector
<SaveLoad
>> load_description
;
482 virtual ~SaveLoadHandler() {}
485 * Save the object to disk.
486 * @param object The object to store.
488 virtual void Save(void *object
) const {}
491 * Load the object from disk.
492 * @param object The object to load.
494 virtual void Load(void *object
) const {}
497 * Similar to load, but used only to validate savegames.
498 * @param object The object to load.
500 virtual void LoadCheck(void *object
) const {}
503 * A post-load callback to fix #SL_REF integers into pointers.
504 * @param object The object to fix.
506 virtual void FixPointers(void *object
) const {}
509 * Get the description of the fields in the savegame.
511 virtual SaveLoadTable
GetDescription() const = 0;
514 * Get the pre-header description of the fields in the savegame.
516 virtual SaveLoadCompatTable
GetCompatDescription() const = 0;
519 * Get the description for how to load the chunk. Depending on the
520 * savegame version this can either use the headers in the savegame or
521 * fall back to backwards compatibility and uses hard-coded headers.
523 SaveLoadTable
GetLoadDescription() const;
527 * Default handler for saving/loading an object to/from disk.
529 * This handles a few common things for handlers, meaning the actual handler
532 * Usage: class SlMine : public DefaultSaveLoadHandler<SlMine, MyObject> {}
534 * @tparam TImpl The class initializing this template.
535 * @tparam TObject The class of the object using this SaveLoadHandler.
537 template <class TImpl
, class TObject
>
538 class DefaultSaveLoadHandler
: public SaveLoadHandler
{
540 SaveLoadTable
GetDescription() const override
{ return static_cast<const TImpl
*>(this)->description
; }
541 SaveLoadCompatTable
GetCompatDescription() const override
{ return static_cast<const TImpl
*>(this)->compat_description
; }
543 virtual void Save(TObject
*object
) const {}
544 void Save(void *object
) const override
{ this->Save(static_cast<TObject
*>(object
)); }
546 virtual void Load(TObject
*object
) const {}
547 void Load(void *object
) const override
{ this->Load(static_cast<TObject
*>(object
)); }
549 virtual void LoadCheck(TObject
*object
) const {}
550 void LoadCheck(void *object
) const override
{ this->LoadCheck(static_cast<TObject
*>(object
)); }
552 virtual void FixPointers(TObject
*object
) const {}
553 void FixPointers(void *object
) const override
{ this->FixPointers(static_cast<TObject
*>(object
)); }
556 /** Type of reference (#SLE_REF, #SLE_CONDREF). */
558 REF_ORDER
= 0, ///< Load/save a reference to an order.
559 REF_VEHICLE
= 1, ///< Load/save a reference to a vehicle.
560 REF_STATION
= 2, ///< Load/save a reference to a station.
561 REF_TOWN
= 3, ///< Load/save a reference to a town.
562 REF_VEHICLE_OLD
= 4, ///< Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
563 REF_ROADSTOPS
= 5, ///< Load/save a reference to a bus/truck stop.
564 REF_ENGINE_RENEWS
= 6, ///< Load/save a reference to an engine renewal (autoreplace).
565 REF_CARGO_PACKET
= 7, ///< Load/save a reference to a cargo packet.
566 REF_ORDERLIST
= 8, ///< Load/save a reference to an orderlist.
567 REF_STORAGE
= 9, ///< Load/save a reference to a persistent storage.
568 REF_LINK_GRAPH
= 10, ///< Load/save a reference to a link graph.
569 REF_LINK_GRAPH_JOB
= 11, ///< Load/save a reference to a link graph job.
573 * VarTypes is the general bitmasked magic type that tells us
574 * certain characteristics about the variable it refers to. For example
575 * SLE_FILE_* gives the size(type) as it would be in the savegame and
576 * SLE_VAR_* the size(type) as it is in memory during runtime. These are
577 * the first 8 bits (0-3 SLE_FILE, 4-7 SLE_VAR).
578 * Bits 8-15 are reserved for various flags as explained below
581 /* 4 bits allocated a maximum of 16 types for NumberType.
582 * NOTE: the SLE_FILE_NNN values are stored in the savegame! */
583 SLE_FILE_END
= 0, ///< Used to mark end-of-header in tables.
592 SLE_FILE_STRINGID
= 9, ///< StringID offset into strings-array
593 SLE_FILE_STRING
= 10,
594 SLE_FILE_STRUCT
= 11,
595 /* 4 more possible file-primitives */
597 SLE_FILE_TYPE_MASK
= 0xf, ///< Mask to get the file-type (and not any flags).
598 SLE_FILE_HAS_LENGTH_FIELD
= 1 << 4, ///< Bit stored in savegame to indicate field has a length field for each entry.
600 /* 4 bits allocated a maximum of 16 types for NumberType */
604 SLE_VAR_I16
= 3 << 4,
605 SLE_VAR_U16
= 4 << 4,
606 SLE_VAR_I32
= 5 << 4,
607 SLE_VAR_U32
= 6 << 4,
608 SLE_VAR_I64
= 7 << 4,
609 SLE_VAR_U64
= 8 << 4,
610 SLE_VAR_NULL
= 9 << 4, ///< useful to write zeros in savegame.
611 SLE_VAR_STRB
= 10 << 4, ///< string (with pre-allocated buffer)
612 SLE_VAR_STR
= 12 << 4, ///< string pointer
613 SLE_VAR_STRQ
= 13 << 4, ///< string pointer enclosed in quotes
614 SLE_VAR_NAME
= 14 << 4, ///< old custom name to be converted to a char pointer
615 /* 1 more possible memory-primitives */
617 /* Shortcut values */
618 SLE_VAR_CHAR
= SLE_VAR_I8
,
620 /* Default combinations of variables. As savegames change, so can variables
621 * and thus it is possible that the saved value and internal size do not
622 * match and you need to specify custom combo. The defaults are listed here */
623 SLE_BOOL
= SLE_FILE_I8
| SLE_VAR_BL
,
624 SLE_INT8
= SLE_FILE_I8
| SLE_VAR_I8
,
625 SLE_UINT8
= SLE_FILE_U8
| SLE_VAR_U8
,
626 SLE_INT16
= SLE_FILE_I16
| SLE_VAR_I16
,
627 SLE_UINT16
= SLE_FILE_U16
| SLE_VAR_U16
,
628 SLE_INT32
= SLE_FILE_I32
| SLE_VAR_I32
,
629 SLE_UINT32
= SLE_FILE_U32
| SLE_VAR_U32
,
630 SLE_INT64
= SLE_FILE_I64
| SLE_VAR_I64
,
631 SLE_UINT64
= SLE_FILE_U64
| SLE_VAR_U64
,
632 SLE_CHAR
= SLE_FILE_I8
| SLE_VAR_CHAR
,
633 SLE_STRINGID
= SLE_FILE_STRINGID
| SLE_VAR_U32
,
634 SLE_STRINGBUF
= SLE_FILE_STRING
| SLE_VAR_STRB
,
635 SLE_STRING
= SLE_FILE_STRING
| SLE_VAR_STR
,
636 SLE_STRINGQUOTE
= SLE_FILE_STRING
| SLE_VAR_STRQ
,
637 SLE_NAME
= SLE_FILE_STRINGID
| SLE_VAR_NAME
,
639 /* Shortcut values */
640 SLE_UINT
= SLE_UINT32
,
642 SLE_STRB
= SLE_STRINGBUF
,
643 SLE_STR
= SLE_STRING
,
644 SLE_STRQ
= SLE_STRINGQUOTE
,
646 /* 8 bits allocated for a maximum of 8 flags
647 * Flags directing saving/loading of a variable */
648 SLF_ALLOW_CONTROL
= 1 << 8, ///< Allow control codes in the strings.
649 SLF_ALLOW_NEWLINE
= 1 << 9, ///< Allow new lines in the strings.
652 typedef uint32 VarType
;
654 /** Type of data saved. */
655 enum SaveLoadType
: byte
{
656 SL_VAR
= 0, ///< Save/load a variable.
657 SL_REF
= 1, ///< Save/load a reference.
658 SL_STRUCT
= 2, ///< Save/load a struct.
660 SL_STR
= 3, ///< Save/load a string.
661 SL_STDSTR
= 4, ///< Save/load a \c std::string.
663 SL_ARR
= 5, ///< Save/load a fixed-size array of #SL_VAR elements.
664 SL_DEQUE
= 6, ///< Save/load a deque of #SL_VAR elements.
665 SL_VECTOR
= 7, ///< Save/load a vector of #SL_VAR elements.
666 SL_REFLIST
= 8, ///< Save/load a list of #SL_REF elements.
667 SL_STRUCTLIST
= 9, ///< Save/load a list of structs.
669 SL_SAVEBYTE
= 10, ///< Save (but not load) a byte.
670 SL_NULL
= 11, ///< Save null-bytes and load to nowhere.
673 typedef void *SaveLoadAddrProc(void *base
, size_t extra
);
675 /** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
677 std::string name
; ///< Name of this field (optional, used for tables).
678 SaveLoadType cmd
; ///< The action to take with the saved/loaded type, All types need different action.
679 VarType conv
; ///< Type of the variable to be saved; this field combines both FileVarType and MemVarType.
680 uint16 length
; ///< (Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
681 SaveLoadVersion version_from
; ///< Save/load the variable starting from this savegame version.
682 SaveLoadVersion version_to
; ///< Save/load the variable before this savegame version.
683 size_t size
; ///< The sizeof size.
684 SaveLoadAddrProc
*address_proc
; ///< Callback proc the get the actual variable address in memory.
685 size_t extra_data
; ///< Extra data for the callback proc.
686 std::shared_ptr
<SaveLoadHandler
> handler
; ///< Custom handler for Save/Load procs.
690 * SaveLoad information for backwards compatibility.
692 * At SLV_SETTINGS_NAME a new method of keeping track of fields in a savegame
693 * was added, where the order of fields is no longer important. For older
694 * savegames we still need to know the correct order. This struct is the glue
695 * to make that happen.
697 struct SaveLoadCompat
{
698 std::string name
; ///< Name of the field.
699 uint16 length
; ///< Length of the NULL field.
700 SaveLoadVersion version_from
; ///< Save/load the variable starting from this savegame version.
701 SaveLoadVersion version_to
; ///< Save/load the variable before this savegame version.
705 * Storage of simple variables, references (pointers), and arrays.
706 * @param cmd Load/save type. @see SaveLoadType
707 * @param name Field name for table chunks.
708 * @param base Name of the class or struct containing the variable.
709 * @param variable Name of the variable in the class or struct referenced by \a base.
710 * @param type Storage of the data in memory and in the savegame.
711 * @param from First savegame version that has the field.
712 * @param to Last savegame version that has the field.
713 * @param extra Extra data to pass to the address callback function.
714 * @note In general, it is better to use one of the SLE_* macros below.
716 #define SLE_GENERAL_NAME(cmd, name, base, variable, type, length, from, to, extra) SaveLoad {name, 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}
719 * Storage of simple variables, references (pointers), and arrays with a custom name.
720 * @param cmd Load/save type. @see SaveLoadType
721 * @param base Name of the class or struct containing the variable.
722 * @param variable Name of the variable in the class or struct referenced by \a base.
723 * @param type Storage of the data in memory and in the savegame.
724 * @param from First savegame version that has the field.
725 * @param to Last savegame version that has the field.
726 * @param extra Extra data to pass to the address callback function.
727 * @note In general, it is better to use one of the SLE_* macros below.
729 #define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra) SLE_GENERAL_NAME(cmd, #variable, base, variable, type, length, from, to, extra)
732 * Storage of a variable in some savegame versions.
733 * @param base Name of the class or struct containing the variable.
734 * @param variable Name of the variable in the class or struct referenced by \a base.
735 * @param type Storage of the data in memory and in the savegame.
736 * @param from First savegame version that has the field.
737 * @param to Last savegame version that has the field.
739 #define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to, 0)
742 * Storage of a variable in some savegame versions.
743 * @param base Name of the class or struct containing the variable.
744 * @param variable Name of the variable in the class or struct referenced by \a base.
745 * @param name Field name for table chunks.
746 * @param type Storage of the data in memory and in the savegame.
747 * @param from First savegame version that has the field.
748 * @param to Last savegame version that has the field.
750 #define SLE_CONDVARNAME(base, variable, name, type, from, to) SLE_GENERAL_NAME(SL_VAR, name, base, variable, type, 0, from, to, 0)
753 * Storage of a reference in some savegame versions.
754 * @param base Name of the class or struct containing the variable.
755 * @param variable Name of the variable in the class or struct referenced by \a base.
756 * @param type Type of the reference, a value from #SLRefType.
757 * @param from First savegame version that has the field.
758 * @param to Last savegame version that has the field.
760 #define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to, 0)
763 * Storage of a fixed-size array of #SL_VAR elements in some savegame versions.
764 * @param base Name of the class or struct containing the array.
765 * @param variable Name of the variable in the class or struct referenced by \a base.
766 * @param type Storage of the data in memory and in the savegame.
767 * @param length Number of elements in the array.
768 * @param from First savegame version that has the array.
769 * @param to Last savegame version that has the array.
771 #define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to, 0)
774 * Storage of a string in some savegame versions.
775 * @param base Name of the class or struct containing the string.
776 * @param variable Name of the variable in the class or struct referenced by \a base.
777 * @param type Storage of the data in memory and in the savegame.
778 * @param length Number of elements in the string (only used for fixed size buffers).
779 * @param from First savegame version that has the string.
780 * @param to Last savegame version that has the string.
782 #define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to, 0)
785 * Storage of a \c std::string in some savegame versions.
786 * @param base Name of the class or struct containing the string.
787 * @param variable Name of the variable in the class or struct referenced by \a base.
788 * @param type Storage of the data in memory and in the savegame.
789 * @param from First savegame version that has the string.
790 * @param to Last savegame version that has the string.
792 #define SLE_CONDSSTR(base, variable, type, from, to) SLE_GENERAL(SL_STDSTR, base, variable, type, 0, from, to, 0)
795 * Storage of a list of #SL_REF elements in some savegame versions.
796 * @param base Name of the class or struct containing the list.
797 * @param variable Name of the variable in the class or struct referenced by \a base.
798 * @param type Storage of the data in memory and in the savegame.
799 * @param from First savegame version that has the list.
800 * @param to Last savegame version that has the list.
802 #define SLE_CONDREFLIST(base, variable, type, from, to) SLE_GENERAL(SL_REFLIST, base, variable, type, 0, from, to, 0)
805 * Storage of a deque of #SL_VAR elements in some savegame versions.
806 * @param base Name of the class or struct containing the list.
807 * @param variable Name of the variable in the class or struct referenced by \a base.
808 * @param type Storage of the data in memory and in the savegame.
809 * @param from First savegame version that has the list.
810 * @param to Last savegame version that has the list.
812 #define SLE_CONDDEQUE(base, variable, type, from, to) SLE_GENERAL(SL_DEQUE, base, variable, type, 0, from, to, 0)
815 * Storage of a variable in every version of a savegame.
816 * @param base Name of the class or struct containing the variable.
817 * @param variable Name of the variable in the class or struct referenced by \a base.
818 * @param type Storage of the data in memory and in the savegame.
820 #define SLE_VAR(base, variable, type) SLE_CONDVAR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
823 * Storage of a reference in every version of a savegame.
824 * @param base Name of the class or struct containing the variable.
825 * @param variable Name of the variable in the class or struct referenced by \a base.
826 * @param type Type of the reference, a value from #SLRefType.
828 #define SLE_REF(base, variable, type) SLE_CONDREF(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
831 * Storage of fixed-size array of #SL_VAR elements in every version of a savegame.
832 * @param base Name of the class or struct containing the array.
833 * @param variable Name of the variable in the class or struct referenced by \a base.
834 * @param type Storage of the data in memory and in the savegame.
835 * @param length Number of elements in the array.
837 #define SLE_ARR(base, variable, type, length) SLE_CONDARR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION)
840 * Storage of a string in every savegame version.
841 * @param base Name of the class or struct containing the string.
842 * @param variable Name of the variable in the class or struct referenced by \a base.
843 * @param type Storage of the data in memory and in the savegame.
844 * @param length Number of elements in the string (only used for fixed size buffers).
846 #define SLE_STR(base, variable, type, length) SLE_CONDSTR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION)
849 * Storage of a \c std::string in every savegame version.
850 * @param base Name of the class or struct containing the string.
851 * @param variable Name of the variable in the class or struct referenced by \a base.
852 * @param type Storage of the data in memory and in the savegame.
854 #define SLE_SSTR(base, variable, type) SLE_CONDSSTR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
857 * Storage of a list of #SL_REF elements in every savegame version.
858 * @param base Name of the class or struct containing the list.
859 * @param variable Name of the variable in the class or struct referenced by \a base.
860 * @param type Storage of the data in memory and in the savegame.
862 #define SLE_REFLIST(base, variable, type) SLE_CONDREFLIST(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
865 * Only write byte during saving; never read it during loading.
866 * When using SLE_SAVEBYTE you will have to read this byte before the table
867 * this is in is read. This also means SLE_SAVEBYTE can only be used at the
869 * This is intended to be used to indicate what type of entry this is in a
871 * @param base Name of the class or struct containing the variable.
872 * @param variable Name of the variable in the class or struct referenced by \a base.
874 #define SLE_SAVEBYTE(base, variable) SLE_GENERAL(SL_SAVEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0)
877 * Storage of global simple variables, references (pointers), and arrays.
878 * @param name The name of the field.
879 * @param cmd Load/save type. @see SaveLoadType
880 * @param variable Name of the global variable.
881 * @param type Storage of the data in memory and in the savegame.
882 * @param from First savegame version that has the field.
883 * @param to Last savegame version that has the field.
884 * @param extra Extra data to pass to the address callback function.
885 * @note In general, it is better to use one of the SLEG_* macros below.
887 #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}
890 * Storage of a global variable in some savegame versions.
891 * @param name The name of the field.
892 * @param variable Name of the global variable.
893 * @param type Storage of the data in memory and in the savegame.
894 * @param from First savegame version that has the field.
895 * @param to Last savegame version that has the field.
897 #define SLEG_CONDVAR(name, variable, type, from, to) SLEG_GENERAL(name, SL_VAR, variable, type, 0, from, to, 0)
900 * Storage of a global reference in some savegame versions.
901 * @param name The name of the field.
902 * @param variable Name of the global variable.
903 * @param type Storage of the data in memory and in the savegame.
904 * @param from First savegame version that has the field.
905 * @param to Last savegame version that has the field.
907 #define SLEG_CONDREF(name, variable, type, from, to) SLEG_GENERAL(name, SL_REF, variable, type, 0, from, to, 0)
910 * Storage of a global fixed-size array of #SL_VAR elements in some savegame versions.
911 * @param name The name of the field.
912 * @param variable Name of the global variable.
913 * @param type Storage of the data in memory and in the savegame.
914 * @param length Number of elements in the array.
915 * @param from First savegame version that has the array.
916 * @param to Last savegame version that has the array.
918 #define SLEG_CONDARR(name, variable, type, length, from, to) SLEG_GENERAL(name, SL_ARR, variable, type, length, from, to, 0)
921 * Storage of a global string in some savegame versions.
922 * @param name The name of the field.
923 * @param variable Name of the global variable.
924 * @param type Storage of the data in memory and in the savegame.
925 * @param length Number of elements in the string (only used for fixed size buffers).
926 * @param from First savegame version that has the string.
927 * @param to Last savegame version that has the string.
929 #define SLEG_CONDSTR(name, variable, type, length, from, to) SLEG_GENERAL(name, SL_STR, variable, type, length, from, to, 0)
932 * Storage of a global \c std::string in some savegame versions.
933 * @param name The name of the field.
934 * @param variable Name of the global variable.
935 * @param type Storage of the data in memory and in the savegame.
936 * @param from First savegame version that has the string.
937 * @param to Last savegame version that has the string.
939 #define SLEG_CONDSSTR(name, variable, type, from, to) SLEG_GENERAL(name, SL_STDSTR, variable, type, 0, from, to, 0)
942 * Storage of a structs in some savegame versions.
943 * @param name The name of the field.
944 * @param handler SaveLoadHandler for the structs.
945 * @param from First savegame version that has the struct.
946 * @param to Last savegame version that has the struct.
948 #define SLEG_CONDSTRUCT(name, handler, from, to) SaveLoad {name, SL_STRUCT, 0, 0, from, to, 0, nullptr, 0, std::make_shared<handler>()}
951 * Storage of a global reference list in some savegame versions.
952 * @param name The name of the field.
953 * @param variable Name of the global variable.
954 * @param type Storage of the data in memory and in the savegame.
955 * @param from First savegame version that has the list.
956 * @param to Last savegame version that has the list.
958 #define SLEG_CONDREFLIST(name, variable, type, from, to) SLEG_GENERAL(name, SL_REFLIST, variable, type, 0, from, to, 0)
961 * Storage of a global vector of #SL_VAR elements in some savegame versions.
962 * @param name The name of the field.
963 * @param variable Name of the global variable.
964 * @param type Storage of the data in memory and in the savegame.
965 * @param from First savegame version that has the list.
966 * @param to Last savegame version that has the list.
968 #define SLEG_CONDVECTOR(name, variable, type, from, to) SLEG_GENERAL(name, SL_VECTOR, variable, type, 0, from, to, 0)
971 * Storage of a list of structs in some savegame versions.
972 * @param name The name of the field.
973 * @param handler SaveLoadHandler for the list of structs.
974 * @param from First savegame version that has the list.
975 * @param to Last savegame version that has the list.
977 #define SLEG_CONDSTRUCTLIST(name, handler, from, to) SaveLoad {name, SL_STRUCTLIST, 0, 0, from, to, 0, nullptr, 0, std::make_shared<handler>()}
980 * Storage of a global variable in every savegame version.
981 * @param name The name of the field.
982 * @param variable Name of the global variable.
983 * @param type Storage of the data in memory and in the savegame.
985 #define SLEG_VAR(name, variable, type) SLEG_CONDVAR(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
988 * Storage of a global reference in every savegame version.
989 * @param name The name of the field.
990 * @param variable Name of the global variable.
991 * @param type Storage of the data in memory and in the savegame.
993 #define SLEG_REF(name, variable, type) SLEG_CONDREF(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
996 * Storage of a global fixed-size array of #SL_VAR elements in every savegame version.
997 * @param name The name of the field.
998 * @param variable Name of the global variable.
999 * @param type Storage of the data in memory and in the savegame.
1001 #define SLEG_ARR(name, variable, type) SLEG_CONDARR(name, variable, type, lengthof(variable), SL_MIN_VERSION, SL_MAX_VERSION)
1004 * Storage of a global string in every savegame version.
1005 * @param name The name of the field.
1006 * @param variable Name of the global variable.
1007 * @param type Storage of the data in memory and in the savegame.
1009 #define SLEG_STR(name, variable, type) SLEG_CONDSTR(name, variable, type, sizeof(variable), SL_MIN_VERSION, SL_MAX_VERSION)
1012 * Storage of a global \c std::string in every savegame version.
1013 * @param name The name of the field.
1014 * @param variable Name of the global variable.
1015 * @param type Storage of the data in memory and in the savegame.
1017 #define SLEG_SSTR(name, variable, type) SLEG_CONDSSTR(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1020 * Storage of a structs in every savegame version.
1021 * @param name The name of the field.
1022 * @param handler SaveLoadHandler for the structs.
1024 #define SLEG_STRUCT(name, handler) SLEG_CONDSTRUCT(name, handler, SL_MIN_VERSION, SL_MAX_VERSION)
1027 * Storage of a global reference list in every savegame version.
1028 * @param name The name of the field.
1029 * @param variable Name of the global variable.
1030 * @param type Storage of the data in memory and in the savegame.
1032 #define SLEG_REFLIST(name, variable, type) SLEG_CONDREFLIST(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1035 * Storage of a global vector of #SL_VAR elements in every savegame version.
1036 * @param name The name of the field.
1037 * @param variable Name of the global variable.
1038 * @param type Storage of the data in memory and in the savegame.
1040 #define SLEG_VECTOR(name, variable, type) SLEG_CONDVECTOR(name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
1043 * Storage of a list of structs in every savegame version.
1044 * @param name The name of the field.
1045 * @param handler SaveLoadHandler for the list of structs.
1047 #define SLEG_STRUCTLIST(name, handler) SLEG_CONDSTRUCTLIST(name, handler, SL_MIN_VERSION, SL_MAX_VERSION)
1050 * Field name where the real SaveLoad can be located.
1051 * @param name The name of the field.
1053 #define SLC_VAR(name) {name, 0, SL_MIN_VERSION, SL_MAX_VERSION}
1056 * Empty space in every savegame version.
1057 * @param length Length of the empty space.
1058 * @param from First savegame version that has the empty space.
1059 * @param to Last savegame version that has the empty space.
1061 #define SLC_NULL(length, from, to) {{}, length, from, to}
1063 /** End marker of compat variables save or load. */
1064 #define SLC_END() {{}, 0, SL_MIN_VERSION, SL_MIN_VERSION}
1067 * Checks whether the savegame is below \a major.\a minor.
1068 * @param major Major number of the version to check against.
1069 * @param minor Minor number of the version to check against. If \a minor is 0 or not specified, only the major number is checked.
1070 * @return Savegame version is earlier than the specified version.
1072 static inline bool IsSavegameVersionBefore(SaveLoadVersion major
, byte minor
= 0)
1074 extern SaveLoadVersion _sl_version
;
1075 extern byte _sl_minor_version
;
1076 return _sl_version
< major
|| (minor
> 0 && _sl_version
== major
&& _sl_minor_version
< minor
);
1080 * Checks whether the savegame is below or at \a major. This should be used to repair data from existing
1081 * savegames which is no longer corrupted in new savegames, but for which otherwise no savegame
1083 * @param major Major number of the version to check against.
1084 * @return Savegame version is at most the specified version.
1086 static inline bool IsSavegameVersionBeforeOrAt(SaveLoadVersion major
)
1088 extern SaveLoadVersion _sl_version
;
1089 return _sl_version
<= major
;
1093 * Checks if some version from/to combination falls within the range of the
1094 * active savegame version.
1095 * @param version_from Inclusive savegame version lower bound.
1096 * @param version_to Exclusive savegame version upper bound. SL_MAX_VERSION if no upper bound.
1097 * @return Active savegame version falls within the given range.
1099 static inline bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from
, SaveLoadVersion version_to
)
1101 extern const SaveLoadVersion SAVEGAME_VERSION
;
1102 return version_from
<= SAVEGAME_VERSION
&& SAVEGAME_VERSION
< version_to
;
1106 * Get the NumberType of a setting. This describes the integer type
1107 * as it is represented in memory
1108 * @param type VarType holding information about the variable-type
1109 * @return the SLE_VAR_* part of a variable-type description
1111 static inline VarType
GetVarMemType(VarType type
)
1113 return GB(type
, 4, 4) << 4;
1117 * Get the FileType of a setting. This describes the integer type
1118 * as it is represented in a savegame/file
1119 * @param type VarType holding information about the file-type
1120 * @return the SLE_FILE_* part of a variable-type description
1122 static inline VarType
GetVarFileType(VarType type
)
1124 return GB(type
, 0, 4);
1128 * Check if the given saveload type is a numeric type.
1129 * @param conv the type to check
1130 * @return True if it's a numeric type.
1132 static inline bool IsNumericType(VarType conv
)
1134 return GetVarMemType(conv
) <= SLE_VAR_U64
;
1138 * Get the address of the variable. Null-variables don't have an address,
1139 * everything else has a callback function that returns the address based
1140 * on the saveload data and the current object for non-globals.
1142 static inline void *GetVariableAddress(const void *object
, const SaveLoad
&sld
)
1144 /* Entry is a null-variable, mostly used to read old savegames etc. */
1145 if (GetVarMemType(sld
.conv
) == SLE_VAR_NULL
) {
1146 assert(sld
.address_proc
== nullptr);
1150 /* Everything else should be a non-null pointer. */
1151 assert(sld
.address_proc
!= nullptr);
1152 return sld
.address_proc(const_cast<void *>(object
), sld
.extra_data
);
1155 int64
ReadValue(const void *ptr
, VarType conv
);
1156 void WriteValue(void *ptr
, VarType conv
, int64 val
);
1158 void SlSetArrayIndex(uint index
);
1159 int SlIterateArray();
1161 void SlSetStructListLength(size_t length
);
1162 size_t SlGetStructListLength(size_t limit
);
1164 void SlAutolength(AutolengthProc
*proc
, void *arg
);
1165 size_t SlGetFieldLength();
1166 void SlSetLength(size_t length
);
1167 size_t SlCalcObjMemberLength(const void *object
, const SaveLoad
&sld
);
1168 size_t SlCalcObjLength(const void *object
, const SaveLoadTable
&slt
);
1171 void SlWriteByte(byte b
);
1173 void SlGlobList(const SaveLoadTable
&slt
);
1174 void SlCopy(void *object
, size_t length
, VarType conv
);
1175 std::vector
<SaveLoad
> SlTableHeader(const SaveLoadTable
&slt
);
1176 std::vector
<SaveLoad
> SlCompatTableHeader(const SaveLoadTable
&slt
, const SaveLoadCompatTable
&slct
);
1177 void SlObject(void *object
, const SaveLoadTable
&slt
);
1179 bool SaveloadCrashWithMissingNewGRFs();
1182 * Read in bytes from the file/data structure but don't do
1183 * anything with them, discarding them in effect
1184 * @param length The amount of bytes that is being treated this way
1186 static inline void SlSkipBytes(size_t length
)
1188 for (; length
!= 0; length
--) SlReadByte();
1191 extern std::string _savegame_format
;
1192 extern bool _do_autosave
;
1194 #endif /* SAVELOAD_H */