OpenTTD Source: src/saveload/saveload.cpp File Reference

OpenTTD Source 15.3

Data Structures | Typedefs | Enumerations | Functions | Variables
saveload.cpp File Reference

All actions handling saving and loading goes on in this file. More...

`#include "../stdafx.h"`
`#include "../debug.h"`
`#include "../station_base.h"`
`#include "../thread.h"`
`#include "../town.h"`
`#include "../network/network.h"`
`#include "../window_func.h"`
`#include "../strings_func.h"`
`#include "../core/endian_func.hpp"`
`#include "../core/string_builder.hpp"`
`#include "../core/string_consumer.hpp"`
`#include "../vehicle_base.h"`
`#include "../company_func.h"`
`#include "../timer/timer_game_economy.h"`
`#include "../autoreplace_base.h"`
`#include "../roadstop_base.h"`
`#include "../linkgraph/linkgraph.h"`
`#include "../linkgraph/linkgraphjob.h"`
`#include "../statusbar_gui.h"`
`#include "../fileio_func.h"`
`#include "../gamelog.h"`
`#include "../string_func.h"`
`#include "../fios.h"`
`#include "../error.h"`
`#include "../strings_type.h"`
`#include "../newgrf_railtype.h"`
`#include "../newgrf_roadtype.h"`
`#include "../settings_internal.h"`
`#include "saveload_internal.h"`
`#include "saveload_filter.h"`
`#include <atomic>`
`#include <lzo/lzo1x.h>`
`#include <zlib.h>`
`#include <lzma.h>`
`#include "table/strings.h"`
`#include "../safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | ReadBuffer
| A buffer for reading (and buffering) savegame data. More...
struct | MemoryDumper
| Container for dumping the savegame (quickly) to memory. More...
struct | SaveLoadParams
| The saveload struct, containing reader-writer functions, buffer, version, etc. More...
class | SlStorageHelper< Tstorage, Tvar, Tallocator >
| Template class to help with list-like types. More...
class | SlSkipHandler
| Handler that is assigned when there is a struct read in the savegame which is not known to the code. More...
struct | FileReader
| Yes, simply reading from a file. More...
struct | FileWriter
| Yes, simply writing to a file. More...
struct | LZOLoadFilter
| Filter using LZO compression. More...
struct | LZOSaveFilter
| Filter using LZO compression. More...
struct | NoCompLoadFilter
| Filter without any compression. More...
struct | NoCompSaveFilter
| Filter without any compression. More...
struct | ZlibLoadFilter
| Filter using Zlib compression. More...
struct | ZlibSaveFilter
| Filter using Zlib compression. More...
struct | LZMALoadFilter
| Filter without any compression. More...
struct | LZMASaveFilter
| Filter using LZMA compression. More...
struct | SaveLoadFormat
| The format for a reader/writer type of a savegame. More...

## Typedefs
typedef void(* | AsyncSaveFinishProc) ()
| Callback for when the savegame loading is finished.

## Enumerations
enum | SaveLoadAction : uint8_t { SLA_LOAD , SLA_SAVE , SLA_PTRS , SLA_NULL , SLA_LOAD_CHECK }
| What are we currently doing? More...
enum | NeedLength : uint8_t { NL_NONE = 0 , NL_WANTLENGTH = 1 , NL_CALCLENGTH = 2 }

## Functions
static const std::vector< ChunkHandlerRef > & | ChunkHandlers ()
static void | SlNullPointers ()
| Null all pointers (convert index -> nullptr)
void | SlError (StringID string, const std::string &extra_msg)
| Error handler.
void | SlErrorCorrupt (const std::string &msg)
| Error handler for corrupt savegames.
static void | SetAsyncSaveFinish (AsyncSaveFinishProc proc)
| Called by save thread to tell we finished saving.
void | ProcessAsyncSaveFinish ()
| Handle async save finishes.
uint8_t | SlReadByte ()
| Wrapper for reading a byte from the buffer.
void | SlWriteByte (uint8_t b)
| Wrapper for writing a byte to the dumper.
static int | SlReadUint16 ()
static uint32_t | SlReadUint32 ()
static uint64_t | SlReadUint64 ()
static void | SlWriteUint16 (uint16_t v)
static void | SlWriteUint32 (uint32_t v)
static void | SlWriteUint64 (uint64_t x)
static uint | SlReadSimpleGamma ()
| Read in the header descriptor of an object or an array.
static void | SlWriteSimpleGamma (size_t i)
| Write the header descriptor of an object or an array.
static uint | SlGetGammaLength (size_t i)
| Return how many bytes used to encode a gamma value.
static uint | SlReadSparseIndex ()
static void | SlWriteSparseIndex (uint index)
static uint | SlReadArrayLength ()
static void | SlWriteArrayLength (size_t length)
static uint | SlGetArrayLength (size_t length)
static uint8_t | GetSavegameFileType (const SaveLoad &sld)
| Return the type as saved/loaded inside the savegame.
static uint | SlCalcConvMemLen (VarType conv)
| Return the size in bytes of a certain type of normal/atomic variable as it appears in memory.
static uint8_t | SlCalcConvFileLen (VarType conv)
| Return the size in bytes of a certain type of normal/atomic variable as it appears in a saved game.
static size_t | SlCalcRefLen ()
| Return the size in bytes of a reference (pointer)
void | SlSetArrayIndex (uint index)
int | SlIterateArray ()
| Iterate through the elements of an array and read the whole thing.
void | SlSkipArray ()
| Skip an array or sparse array.
void | SlSetLength (size_t length)
| Sets the length of either a RIFF object or the number of items in an array.
static void | SlCopyBytes (void *ptr, size_t length)
| Save/Load bytes.
size_t | SlGetFieldLength ()
| Get the length of the current object.
int64_t | ReadValue (const void *ptr, VarType conv)
| Return a signed-long version of the value of a setting.
void | WriteValue (void *ptr, VarType conv, int64_t val)
| Write the value of a setting.
static void | SlSaveLoadConv (void *ptr, VarType conv)
| Handle all conversion and typechecking of variables here.
static size_t | SlCalcStdStringLen (const void *ptr)
| Calculate the gross length of the string that it will occupy in the savegame.
void | FixSCCEncoded (std::string &str, bool fix_code)
| Scan the string for old values of SCC_ENCODED and fix it to it's new, value.
void | FixSCCEncodedNegative (std::string &str)
| Scan the string for SCC_ENCODED_NUMERIC with negative values, and reencode them as uint64_t.
void | SlReadString (std::string &str, size_t length)
| Read the given amount of bytes from the buffer into the string.
static void | SlStdString (void *ptr, VarType conv)
| Save/Load a `std::string`.
static void | SlCopyInternal (void *object, size_t length, VarType conv)
| Internal function to save/Load a list of SL_VARs.
void | SlCopy (void *object, size_t length, VarType conv)
| Copy a list of SL_VARs to/from a savegame.
static size_t | SlCalcArrayLen (size_t length, VarType conv)
| Return the size in bytes of a certain type of atomic array.
static void | SlArray (void *array, size_t length, VarType conv)
| Save/Load the length of the array followed by the array of SL_VAR elements.
static size_t | ReferenceToInt (const void *obj, SLRefType rt)
| Pointers cannot be saved to a savegame, so this functions gets the index of the item, and if not available, it hussles with pointers (looks really bad :() Remember that a nullptr item has value 0, and all indices have +1, so vehicle 0 is saved as index 1.
static void * | IntToReference (size_t index, SLRefType rt)
| Pointers cannot be loaded from a savegame, so this function gets the index from the savegame and returns the appropriate pointer from the already loaded base.
void | SlSaveLoadRef (void *ptr, VarType conv)
| Handle conversion for references.
static size_t | SlCalcRefListLen (const void *list, VarType conv)
| Return the size in bytes of a list.
static void | SlRefList (void *list, VarType conv)
| Save/Load a list.
static size_t | SlCalcRefVectorLen (const void *vector, VarType conv)
| Return the size in bytes of a vector.
static void | SlRefVector (void *vector, VarType conv)
| Save/Load a vector.
static size_t | SlCalcDequeLen (const void *deque, VarType conv)
| Return the size in bytes of a std::deque.
static void | SlDeque (void *deque, VarType conv)
| Save/load a std::deque.
static size_t | SlCalcVectorLen (const void *vector, VarType conv)
| Return the size in bytes of a std::vector.
static void | SlVector (void *vector, VarType conv)
| Save/load a std::vector.
static bool | SlIsObjectValidInSavegame (const SaveLoad &sld)
| Are we going to save this object or not?
static size_t | SlCalcTableHeader (const SaveLoadTable &slt)
| Calculate the size of the table header.
size_t | SlCalcObjLength (const void *object, const SaveLoadTable &slt)
| Calculate the size of an object.
size_t | SlCalcObjMemberLength (const void *object, const SaveLoad &sld)
static bool | SlObjectMember (void *object, const SaveLoad &sld)
void | SlSetStructListLength (size_t length)
| Set the length of this list.
size_t | SlGetStructListLength (size_t limit)
| Get the length of this list; if it exceeds the limit, error out.
void | SlObject (void *object, const SaveLoadTable &slt)
| Main SaveLoad function.
std::vector< SaveLoad > | SlTableHeader (const SaveLoadTable &slt)
| Save or Load a table header.
std::vector< SaveLoad > | SlCompatTableHeader (const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
| Load a table header in a savegame compatible way.
void | SlGlobList (const SaveLoadTable &slt)
| Save or Load (a list of) global variables.
void | SlAutolength (AutolengthProc *proc, int arg)
| Do something of which I have no idea what it is :P.
static void | SlLoadChunk (const ChunkHandler &ch)
| Load a chunk of data (eg vehicles, stations, etc.)
static void | SlLoadCheckChunk (const ChunkHandler &ch)
| Load a chunk of data for checking savegames.
static void | SlSaveChunk (const ChunkHandler &ch)
| Save a chunk of data (eg.
static void | SlSaveChunks ()
| Save all chunks.
static const ChunkHandler * | SlFindChunkHandler (uint32_t id)
| Find the ChunkHandler that will be used for processing the found chunk in the savegame or in memory.
static void | SlLoadChunks ()
| Load all chunks.
static void | SlLoadCheckChunks ()
| Load all chunks for savegame checking.
static void | SlFixPointers ()
| Fix all pointers (convert index -> pointer)
static std::pair< const SaveLoadFormat &, uint8_t > | GetSavegameFormat (std::string_view full_name)
| Return the savegameformat of the game.
void | InitializeGame (uint size_x, uint size_y, bool reset_date, bool reset_settings)
bool | AfterLoadGame ()
| Perform a (large) amount of savegame conversion magic in order to load older savegames and to fill the caches for various purposes.
bool | LoadOldSaveGame (std::string_view file)
static void | ResetSettings ()
| Reset all settings to their default, so any settings missing in the savegame are their default, and not "value of last game".
void | ClearOldOrders ()
| Clear all old orders.
static void | ResetSaveloadData ()
| Clear temporary data that is passed between various saveload phases.
static void | ClearSaveLoadState ()
| Clear/free saveload state.
static void | SaveFileStart ()
| Update the gui accordingly when starting saving and set locks on saveload.
static void | SaveFileDone ()
| Update the gui accordingly when saving is done and release locks on saveload.
void | SetSaveLoadError (StringID str)
| Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friends)
EncodedString | GetSaveLoadErrorType ()
| Return the appropriate initial string for an error depending on whether we are saving or loading.
EncodedString | GetSaveLoadErrorMessage ()
| Return the description of the error.
static void | SaveFileError ()
| Show a gui message when saving has failed.
static SaveOrLoadResult | SaveFileToDisk (bool threaded)
| We have written the whole game into memory, _memory_savegame, now find and appropriate compressor and start writing to file.
void | WaitTillSaved ()
static SaveOrLoadResult | DoSave (std::shared_ptr< SaveFilter > writer, bool threaded)
| Actually perform the saving of the savegame.
SaveOrLoadResult | SaveWithFilter (std::shared_ptr< SaveFilter > writer, bool threaded)
| Save the game using a (writer) filter.
static const SaveLoadFormat * | DetermineSaveLoadFormat (uint32_t tag, uint32_t raw_version)
| Determines the SaveLoadFormat that is connected to the given tag.
static SaveOrLoadResult | DoLoad (std::shared_ptr< LoadFilter > reader, bool load_check)
| Actually perform the loading of a "non-old" savegame.
SaveOrLoadResult | LoadWithFilter (std::shared_ptr< LoadFilter > reader)
| Load the game using a (reader) filter.
SaveOrLoadResult | SaveOrLoad (std::string_view filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
| Main Save or Load function where the high-level saveload functions are handled.
void | DoAutoOrNetsave (FiosNumberedSaveName &counter)
| Create an autosave or netsave.
void | DoExitSave ()
| Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
std::string | GenerateDefaultSaveName ()
| Get the default name for a savegame or screenshot.

## Variables
const SaveLoadVersion | SAVEGAME_VERSION = (SaveLoadVersion)(SL_MAX_VERSION - 1)
| Current savegame version of OpenTTD.
SavegameType | _savegame_type
| type of savegame we are loading
FileToSaveLoad | _file_to_saveload
| File to save or load in the openttd loop.
uint32_t | _ttdp_version
| version of TTDP savegame (if applicable)
SaveLoadVersion | _sl_version
| the major savegame version identifier
uint8_t | _sl_minor_version
| the minor savegame version, DO NOT USE!
std::string | _savegame_format
| how to compress savegames
bool | _do_autosave
| are we doing an autosave at the moment?
static const size_t | MEMORY_CHUNK_SIZE = 128 * 1024
| Save in chunks of 128 KiB.
static SaveLoadParams | _sl
| Parameters used for/at saveload.
static std::atomic< AsyncSaveFinishProc > | _async_save_finish
| Callback to call when the savegame loading is finished.
static std::thread | _save_thread
| The thread we're using to compress and write a savegame.
static size_t | _next_offs
static const uint | LZO_BUFFER_SIZE = 8192
| Buffer size for the LZO compressor.
static const lzma_stream | _lzma_init = LZMA_STREAM_INIT
| Have a copy of an initialised LZMA stream.
static const uint32_t | SAVEGAME_TAG_LZO = TO_BE32('OTTD')
static const uint32_t | SAVEGAME_TAG_NONE = TO_BE32('OTTN')
static const uint32_t | SAVEGAME_TAG_ZLIB = TO_BE32('OTTZ')
static const uint32_t | SAVEGAME_TAG_LZMA = TO_BE32('OTTX')
static const SaveLoadFormat | _saveload_formats []
| The different saveload formats known/understood by OpenTTD.

## Detailed Description

All actions handling saving and loading goes on in this file.

The general actions are as follows for saving a game (loading is analogous):

1. initialize the writer by creating a temporary memory-buffer for it
2. go through all to-be saved elements, each 'chunk' (ChunkHandler) prefixed by a label
3. use their description array (SaveLoad) to know what elements to save and in what version of the game it was active (used when loading)
4. write all data byte-by-byte to the temporary buffer so it is endian-safe
5. when the buffer is full; flush it to the output (eg save to file) (_sl.buf, _sl.bufp, _sl.bufe)
6. repeat this until everything is done, and flush any remaining output to file

Definition in file saveload.cpp.

## Typedef Documentation

## ◆ AsyncSaveFinishProc

typedef void(* AsyncSaveFinishProc) ()

Callback for when the savegame loading is finished.

Definition at line 375 of file saveload.cpp.

## Enumeration Type Documentation

## ◆ NeedLength

enum NeedLength : uint8_t

Enumerator
NL_NONE | not working in NeedLength mode
NL_WANTLENGTH | writing length and data
NL_CALCLENGTH | need to calculate the length

Definition at line 95 of file saveload.cpp.

## ◆ SaveLoadAction

enum SaveLoadAction : uint8_t

What are we currently doing?

Enumerator
SLA_LOAD | loading
SLA_SAVE | saving
SLA_PTRS | fixing pointers
SLA_NULL | null all pointers (on loading error)
SLA_LOAD_CHECK | partial loading into _load_check_data

Definition at line 87 of file saveload.cpp.

## Function Documentation

## ◆ AfterLoadGame()

bool AfterLoadGame | ( |  | ) |
| extern

Perform a (large) amount of savegame conversion magic in order to load older savegames and to fill the caches for various purposes.

Returns
  True iff conversion went without a problem.

< Flag for coast.

Definition at line 560 of file afterload.cpp.

References _animated_tiles, _current_company, _gamelog, _grfconfig, _industry_builder, _network_dedicated, _network_server, _networking, _new_competitor_timeout, _old_vds, _pause_mode, _random, _road_stop_stop_frame, _settings_client, _settings_game, _settings_newgame, _tunnel_visibility_frame, ShipVehicleInfo::acceleration, IndustrySpec::accepts_cargo, ActiveClients, AddInflation(), CargoPacket::AfterLoad(), AfterLoadCompanyStats(), AfterLoadLabelMaps(), AfterLoadLinkGraphs(), AfterLoadRoadStops(), AfterLoadStoryBook(), AfterLoadVehiclesPhase1(), AfterLoadVehiclesPhase2(), AIR_AIRCRAFT, AircraftNextAirportPos_and_Order(), Airport, EconomySettings::allow_town_level_crossings, EconomySettings::allow_town_roads, Animated, AssignBit(), AT_OILRIG, Available, AXIS_X, AXIS_Y, AxisToDirection(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::base(), IndustrySpec::behaviour, Object::build_date, BuildingIsProtected, BuiltOnWater, Station::bus_stops, CalcClosestTownFromTile(), Canal, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_roadstop_pool >::CanAllocateItem(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_object_pool >::CanAllocateItem(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_cargo_payment_pool >::CanAllocateItem(), CARGO_NO_REFIT, CeilDiv(), ChangeTileOwner(), CheckGroundVehiclesAtCorrectZ(), Clamp(), Clear, CLEAR_FIELDS, ConstructionSettings::clear_frame_burst, CLEAR_GRASS, CLEAR_SNOW, ClearBridgeMiddle(), ClearOldOrders(), ClosestTownFromTile(), ClrBit(), Coast, ClientSettings::company, Compatible, DifficultySettings::competitors_interval, ConnectMultiheadedTrains(), GameSettings::construction, ConvertFromOldCompanyManagerFace(), ConvertOldMultiheadToNew(), CopyFromOldName(), CopyTempEngineData(), TimerGameTick::counter, Crashed, Crossing, Vehicle::current_order, CustomGrowth, TimerGameCalendar::date, TimerGameEconomy::date, TimerGameCalendar::date_fract, TimerGameEconomy::date_fract, Ticks::DAY_TICKS, TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameConst< struct Economy >::DAYS_TILL_ORIGINAL_BASE_YEAR, Debug, TimerGameConst< struct Calendar >::DEF_END_YEAR, Depot, DIAGDIR_END, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DiagDirToAxis(), DiagDirToDiagTrackBits(), DiagDirToDiagTrackdir(), DiagDirToDir(), GameSettings::difficulty, DIR_N, Vehicle::direction, DirToDiagDir(), VehicleSettings::disable_elrails, DistanceManhattan(), LinkGraphSettings::distribution_armoured, LinkGraphSettings::distribution_default, LinkGraphSettings::distribution_mail, LinkGraphSettings::distribution_pax, Dock, DoStartupNewCompany(), DT_MANUAL, VehicleSettings::dynamic_engines, GameSettings::economy, GameCreationSettings::ending_year, Error, ExclusivePreview, HouseSpec::extra_flags, FarEnd, EconomySettings::feeder_payment_share, FindCompanyManagerFaceLabel(), FindFirstCargoWithTownAcceptanceEffect(), FixOwnerOfRailTrack(), FixupTrainLengths(), FixVehicleInclination(), FLYING, PathfinderSettings::forbid_90_deg, ConstructionSettings::freeform_edges, SpecializedStation< Station, false >::From(), SpecializedVehicle< T, Type >::From(), GameSettings::game_creation, GB(), GCS_NOT_FOUND, GenerateSavegameId(), SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_object_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Get(), HouseSpec::Get(), CargoSpec::Get(), GetAircraftFlightLevelBounds(), BaseStation::GetByTile(), Industry::GetByTile(), GetClearDensity(), GetClearGround(), GetCompanyRailTypes(), GetCompanyRoadTypes(), GetEncodedString(), GetFirstPlayableCompanyID(), OverrideManagerBase::GetGRFID(), GetHouseType(), SpecializedStation< Station, false >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::GetIfValid(), GetInclinedSlopeDirection(), GetIndustryGfx(), GetIndustrySpec(), GetIndustryType(), GetLockPart(), GetNorthernBridgeEnd(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_object_pool >::GetNumItems(), GetOtherShipDepotTile(), GetOtherTunnelBridgeEnd(), GetRailType(), GetRoadOwner(), GetRoadTileType(), GetSlopePixelZ(), GetStationGfx(), GetStationType(), GetTargetAirportIfValid(), GetTileMaxPixelZ(), GetTileMaxZ(), GetTileOwner(), GetTileSlope(), GetTileTrackStatus(), GetTileType(), GetTileZ(), GetTreeGround(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), GetWaterClass(), GetWaterTileType(), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET, GfxLoadSprites(), GLC_ALL_GOOD, GLC_COMPATIBLE, GLC_NOT_FOUND, Gamelog::GRFAddList(), Gamelog::GRFCompatible(), Gamelog::GRFRemove(), GroundVehicle< T, Type >::gv_flags, GVF_GOINGDOWN_BIT, GVF_GOINGUP_BIT, OrthogonalTileArea::h, HasBit(), HasSignals(), HasStationRail(), HasStationTileRail(), HasTownOwnedRoad(), Hidden, Object::IncTypeCount(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Industry, DifficultySettings::industry_density, Economy::inflation_payment, Economy::inflation_prices, EconomySettings::infrastructure_maintenance, InitializeRailGUI(), InitializeWindowsAndCaches(), Invalid, INVALID_DIR, INVALID_OWNER, INVALID_ROADTYPE, INVALID_TILE, INVALID_TRACK, IsAirportTile(), IsAnyRoadStop(), IsBayRoadStopTile(), IsBridge(), IsBridgeTile(), IsBuoy(), IsBuoyTile(), IsClearGround(), IsDepotTile(), IsDock(), IsDriveThroughStopTile(), SpecializedStation< Station, false >::IsExpected(), IsGoodGRFConfigList(), IsHouseCompleted(), IsInsideMM(), IsLevelCrossing(), IsLevelCrossingTile(), IsLock(), IsOilRig(), IsPlainRail(), IsPlainRailTile(), IsRailDepot(), IsRailDepotTile(), IsRoadDepot(), IsSavegameVersionBefore(), IsSavegameVersionBeforeOrAt(), IsShipDepot(), IsShipDepotTile(), IsStationRoadStop(), IsStationTileBlocked(), IsTileFlat(), IsTileOwner(), IsTileType(), IsTruckStop(), IsTunnelTile(), Order::IsType(), IsValidCargoType(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_industry_pool >::IsValidID(), IsWater(), Map::Iterate(), SpecializedStation< Waypoint, true >::Iterate(), SpecializedStation< Station, false >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_subsidy_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_orderlist_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_industry_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_order_backup_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_cargo_payment_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_engine_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_object_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_group_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_sign_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_depot_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), SpecializedVehicle< T, Type >::Iterate(), Join, GameCreationSettings::landscape, EconomySettings::larger_towns, GameSettings::linkgraph, LoadingFinished, LoadStringWidthTable(), GameSettings::locale, Object::location, Lock, Tile::m2(), MakeCanal(), MakeClear(), MakeDefaultName(), MakeSea(), MakeShore(), ConstructionSettings::map_height_limit, ConstructionSettings::max_bridge_length, MAX_INFLATION, DifficultySettings::max_loan, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::MAX_SIZE, VehicleSettings::max_train_length, ConstructionSettings::max_tunnel_length, Map::MaxX(), Map::MaxY(), MayAnimateTile(), MayHaveBridgeAbove(), Middle, TimerGameConst< struct Economy >::MIN_DATE, MIN_SNOWLINE_HEIGHT, EconomySettings::minutes_per_calendar_year, EngineInfo::misc_flags, StationSettings::modified_catchment, MoveBuoysToWaypoints(), MoveWaypointsToBaseStations(), MP_CLEAR, MP_HOUSE, MP_INDUSTRY, MP_OBJECT, MP_RAILWAY, MP_ROAD, MP_STATION, MP_TREES, MP_TUNNELBRIDGE, MP_VOID, MP_WATER, NEW_HOUSE_OFFSET, SpecializedVehicle< T, Type >::Next(), NoIntermediate, NoLoad, None, Normal, DifficultySettings::number_towns, OBJECT_HQ, OBJECT_STATUE, Economy::old_max_loan_unround, Economy::old_max_loan_unround_fract, Gamelog::Oldver(), TimerGameConst< struct Calendar >::ORIGINAL_BASE_YEAR, TimerGameConst< struct Economy >::ORIGINAL_BASE_YEAR, BaseStation::owner, OWNER_NONE, OWNER_TOWN, OWNER_WATER, PathfinderLost, GameSettings::pf, VehicleSettings::plane_crashes, VehicleSettings::plane_speed, PlantOnBuild, Gamelog::PrintDebug(), RAILTYPE_ELECTRIC, RAILTYPE_RAIL, RailVehicleInfo::railtypes, Random, RandomiseCompanyManagerFace(), GoodsEntry::Rating, RATING_INITIAL, LinkGraphSettings::recalc_interval, LinkGraphSettings::recalc_time, Station::RecomputeCatchmentForAll(), BaseStation::rect, ReplaceProtection, ReplaceWagonRemoval, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Reset(), IndustryBuildData::Reset(), ResetCompanyLivery(), ResetOldNames(), ResetSignalHandlers(), Backup< T >::Restore(), PathfinderSettings::reverse_at_signals, ReverseDiagDir(), ReverseDir(), River, VehicleSettings::road_side, ROAD_X, ROAD_Y, RoadIsTram, RoadVehicle::roadtype, ROADTYPE_ROAD, ROADTYPE_TRAM, VehicleSettings::roadveh_acceleration_model, VehicleSettings::roadveh_slope_steepness, RTT_ROAD, RTT_TRAM, RVS_DRIVE_SIDE, RVS_ENTERED_STOP, RVS_IN_DT_ROAD_STOP, RVS_IN_ROAD_STOP, RVSB_IN_DEPOT, RVSB_IN_ROAD_STOP, RVSB_WORMHOLE, SB(), Sea, TimerGameConst< struct Calendar >::SECONDS_PER_DAY, StationSettings::serve_neutral_industries, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), SetAircraftPosition(), SetAnimatedTileState(), SetAnimationFrame(), SetBit(), SetBridgeMiddle(), SetClearGroundDensity(), SetCompanyManagerFaceStyle(), SetCrossingReservation(), TimerGameCalendar::SetDate(), TimerGameEconomy::SetDate(), SetDepotReservation(), SetDockingTile(), SetFence(), SetHouseCompleted(), SetHouseProtected(), SetHouseType(), SetLiftPosition(), SetNonFloodingWaterTile(), SetRailStationReservation(), SetRailType(), SetRoadOwner(), SetRoadTypes(), SetSaveLoadError(), SetSignalHandlers(), SetSignalStates(), SetStationGfx(), SetTileOwner(), SetTileType(), CompanyProperties::settings, SetTownIndex(), SetTrackReservation(), SetTropicZone(), SetTunnelBridgeReservation(), SetWaterClass(), SetWaterClassDependingOnSurroundings(), SetWaterTileType(), ShowErrorMessage(), SIG_ELECTRIC, SIG_SEMAPHORE, SIGTYPE_COMBO, SlError(), SlErrorCorrupt(), SLV_1, SLV_100, SLV_101, SLV_103, SLV_104, SLV_106, SLV_11, SLV_111, SLV_112, SLV_113, SLV_114, SLV_117, SLV_119, SLV_120, SLV_121, SLV_122, SLV_123, SLV_124, SLV_125, SLV_126, SLV_127, SLV_128, SLV_131, SLV_133, SLV_134, SLV_135, SLV_136, SLV_137, SLV_138, SLV_139, SLV_140, SLV_141, SLV_142, SLV_143, SLV_144, SLV_145, SLV_146, SLV_147, SLV_148, SLV_149, SLV_15, SLV_152, SLV_153, SLV_156, SLV_158, SLV_159, SLV_16, SLV_160, SLV_161, SLV_164, SLV_165, SLV_166, SLV_17, SLV_172, SLV_175, SLV_177, SLV_182, SLV_183, SLV_184, SLV_186, SLV_188, SLV_190, SLV_192, SLV_194, SLV_198, SLV_2, SLV_21, SLV_24, SLV_25, SLV_26, SLV_31, SLV_32, SLV_34, SLV_36, SLV_38, SLV_4, SLV_42, SLV_43, SLV_45, SLV_46, SLV_48, SLV_49, SLV_50, SLV_52, SLV_53, SLV_56, SLV_57, SLV_58, SLV_59, SLV_6, SLV_61, SLV_62, SLV_64, SLV_69, SLV_70, SLV_72, SLV_74, SLV_76, SLV_78, SLV_81, SLV_82, SLV_83, SLV_84, SLV_86, SLV_87, SLV_88, SLV_9, SLV_90, SLV_91, SLV_93, SLV_94, SLV_95, SLV_96, SLV_98, SLV_99, SLV_AI_START_DATE, SLV_ANIMATED_TILE_STATE_IN_MAP, SLV_CALENDAR_SUB_DATE_FRACT, SLV_COMPANY_INAUGURATED_PERIOD_V2, SLV_CONSISTENT_PARTIAL_Z, SLV_DEPOT_UNBUNCHING, SLV_ECONOMY_DATE, SLV_ECONOMY_MODE_TIMEKEEPING_UNITS, SLV_ENDING_YEAR, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_EXTEND_RAILTYPES, SLV_FACE_STYLES, SLV_GROUP_NUMBERS, SLV_GROUP_REPLACE_WAGON_REMOVAL, SLV_GS_INDUSTRY_CONTROL, SLV_INCREASE_HOUSE_LIMIT, SLV_INCREASE_STATION_TYPE_FIELD_SIZE, SLV_LAST_LOADING_TICK, SLV_LINKGRAPH_SECONDS, SLV_MAX_LOAN_FOR_COMPANY, SLV_MULTITILE_DOCKS, SLV_MULTITRACK_LEVEL_CROSSINGS, SLV_NEWGRF_LAST_SERVICE, SLV_NONFLOODING_WATER_TILES, SLV_PROTECT_PLACED_HOUSES, SLV_REPAIR_OBJECT_DOCKING_TILES, SLV_ROAD_TYPES, SLV_SAVEGAME_ID, SLV_SCRIPT_RANDOMIZER, SLV_SCRIPT_SAVE_INSTANCES, SLV_SERVE_NEUTRAL_INDUSTRIES, SLV_SHIP_ACCELERATION, SLV_SHIPS_STOP_IN_LOCKS, SLV_TOWN_CARGOGEN, SLV_TREES_WATER_CLASS, SLV_VEHICLE_ECONOMY_AGE, SLV_VELOCITY_NAUTICAL, SLV_WATER_TILE_TYPE, GameCreationSettings::snow_line_height, SPECSTR_PRESIDENT_NAME, SPECSTR_TOWNNAME_START, GameCreationSettings::starting_year, StartScripts(), StartupEngines(), RoadVehicle::state, GameSettings::station, EconomySettings::station_noise_level, Stopped, BaseTimer< TTimerType >::storage, TAE_FOOD, TAE_GOODS, TAE_MAIL, TAE_PASSENGERS, TAE_WATER, TCGM_ORIGINAL, ConstructionSettings::terraform_frame_burst, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), Gamelog::TestMode(), Gamelog::TestRevision(), TFP_NONE, TFP_STUCK, OrthogonalTileArea::tile, Vehicle::tile, TILE_HEIGHT, TILE_SIZE, TILE_UNIT_MASK, TileAddXY(), TileDiffXY(), TileHash(), TileHeight(), TileVirtXY(), TileX(), TileXY(), TileY(), EconomySettings::timekeeping_units, TL_BETTER_ROADS, TL_RANDOM, to_underlying(), BaseStation::town, Object::town, Town, CargoSpec::town_acceptance_effect, EconomySettings::town_cargogen_mode, TOWN_GROWTH_DESERT, TOWN_GROWTH_RATE_NONE, Ticks::TOWN_GROWTH_TICKS, TOWN_GROWTH_WINTER, TOWN_HOUSE_COMPLETED, EconomySettings::town_layout, GameCreationSettings::town_name, TRACK_BIT_NONE, TRACK_BIT_WORMHOLE, TRACK_BIT_X, TRACK_BIT_Y, TRACK_LOWER, TRACK_UPPER, TrackStatusToTrackBits(), Train, VehicleSettings::train_acceleration_model, VehicleSettings::train_slope_steepness, BaseStation::train_station, Transfer, TRANSPORT_RAIL, TRANSPORT_ROAD, ConstructionSettings::tree_frame_burst, TREE_GROUND_SHORE, TREE_GROUND_SNOW_DESERT, TrimIndustryAcceptedProduced(), TROPICZONE_NORMAL, Station::truck_stops, Object::type, BaseVehicle::type, LocaleSettings::units_force, LocaleSettings::units_height, LocaleSettings::units_power, LocaleSettings::units_velocity, LocaleSettings::units_velocity_nautical, LocaleSettings::units_volume, LocaleSettings::units_weight, GroupStatistics::UpdateAfterLoad(), UpdateAircraftCache(), UpdateCompanyLiveries(), UpdateGroupChildren(), UpdateHousesAndTowns(), UpdateLevelCrossing(), UpdateNearestTownForRoadTiles(), UpdateOldAircraft(), UpdateStationAcceptance(), UpdateTownMaxPass(), FreeUnitIDGenerator::UseID(), VEH_INVALID, VEH_ROAD, VEH_SHIP, VEH_TRAIN, GameSettings::vehicle, Vehicle::vehstatus, OrthogonalTileArea::w, PathfinderSettings::wait_for_pbs_path, PathfinderSettings::wait_oneway_signal, PathfinderSettings::wait_twoway_signal, WL_CRITICAL, XYNSToDiagDir(), YapfNotifyTrackLayoutChange(), TimerGameCalendar::year, and TimerGameEconomy::year.

Referenced by DoLoad(), and SaveOrLoad().

## ◆ ChunkHandlers()

static const std::vector< ChunkHandlerRef > & ChunkHandlers | ( |  | ) |
| static

List of all chunks in a savegame.

Definition at line 220 of file saveload.cpp.

Referenced by SlFindChunkHandler(), SlFixPointers(), SlNullPointers(), and SlSaveChunks().

## ◆ ClearOldOrders()

void ClearOldOrders | ( |  | ) |
| extern

Clear all old orders.

Definition at line 114 of file order_sl.cpp.

Referenced by ResetSaveloadData().

## ◆ ClearSaveLoadState()

static void ClearSaveLoadState | ( |  | ) |
| inlinestatic

Clear/free saveload state.

Definition at line 2930 of file saveload.cpp.

References _sl, SaveLoadParams::dumper, SaveLoadParams::lf, SaveLoadParams::reader, and SaveLoadParams::sf.

Referenced by DoLoad(), LoadWithFilter(), SaveFileToDisk(), SaveOrLoad(), and SaveWithFilter().

## ◆ DetermineSaveLoadFormat()

static const SaveLoadFormat * DetermineSaveLoadFormat | ( | uint32_t | tag,
|  | uint32_t | raw_version
| ) |  |
| static

Determines the SaveLoadFormat that is connected to the given tag.

When the given tag is known, that format is chosen and a check on the validity of the version is performed. Otherwise a fallback to an ancient buggy format using LZO is chosen.

Parameters

  tag | The tag from the header describing the savegame compression/format.
  raw_version | The raw version from the savegame header.

Returns
  The SaveLoadFormat to use for attempting to open the savegame.

Definition at line 3097 of file saveload.cpp.

References _saveload_formats, _sl, _sl_minor_version, _sl_version, Debug, SaveLoadParams::lf, SAVEGAME_VERSION, SL_MIN_VERSION, SlError(), SLV_END_PATCHPACKS, SLV_START_PATCHPACKS, and SaveLoadFormat::tag.

Referenced by DoLoad().

## ◆ DoAutoOrNetsave()

void DoAutoOrNetsave | ( | FiosNumberedSaveName & | counter | ) |

Create an autosave or netsave.

Parameters

  counter | A reference to the counter variable to be used for rotating the file name.
  netsave | Indicates if this is a regular autosave or a netsave.

Definition at line 3349 of file saveload.cpp.

References _settings_client, AUTOSAVE_DIR, Debug, DFT_GAME_FILE, FiosNumberedSaveName::Extension(), FiosNumberedSaveName::Filename(), GenerateDefaultSaveName(), GetEncodedString(), ClientSettings::gui, GUISettings::keep_all_autosave, SaveOrLoad(), ShowErrorMessage(), SL_OK, SLO_SAVE, and WL_ERROR.

Referenced by ClientNetworkEmergencySave().

## ◆ DoExitSave()

void DoExitSave | ( |  | ) |

Do a save when exiting the game (_settings_client.gui.autosave_on_exit)

Definition at line 3367 of file saveload.cpp.

References AUTOSAVE_DIR, DFT_GAME_FILE, SaveOrLoad(), and SLO_SAVE.

Referenced by VideoDriver_Null::MainLoop(), and MainWindow::OnHotkey().

## ◆ DoLoad()

static SaveOrLoadResult DoLoad | ( | std::shared_ptr< LoadFilter > | reader,
|  | bool | load_check
| ) |  |
| static

Actually perform the loading of a "non-old" savegame.

Parameters

  reader | The filter to read the savegame from.
  load_check | Whether to perform the checking ("preview") or actually load the game.

Returns
  Return the result of the action. SL_OK or SL_REINIT ("unload" the game)

Definition at line 3138 of file saveload.cpp.

References _gamelog, _grfconfig, _load_check_data, _savegame_type, _sl, AfterLoadGame(), LoadCheckData::checkable, LoadCheckData::Clear(), ClearGRFConfigList(), ClearSaveLoadState(), DetermineSaveLoadFormat(), GLAT_LOAD, LoadCheckData::grf_compatibility, LoadCheckData::grfconfig, SaveLoadFormat::init_load, IsGoodGRFConfigList(), IsSavegameVersionBefore(), SaveLoadParams::lf, SaveLoadFormat::name, SaveLoadParams::reader, Gamelog::Reset(), ResetSaveloadData(), SGT_OTTD, SL_OK, SL_REINIT, SlError(), SlFixPointers(), SlLoadCheckChunks(), SlLoadChunks(), SLV_4, Gamelog::StartAction(), and Gamelog::StopAction().

Referenced by LoadWithFilter(), and SaveOrLoad().

## ◆ DoSave()

static SaveOrLoadResult DoSave | ( | std::shared_ptr< SaveFilter > | writer,
|  | bool | threaded
| ) |  |
| static

Actually perform the saving of the savegame.

General tactics is to first save the game to memory, then write it to file using the writer, either in threaded mode if possible, or single-threaded.

Parameters

  writer | The filter to write the savegame to.
  threaded | Whether to try to perform the saving asynchronously.

Returns
  Return the result of the action. SL_OK or SL_ERROR

Definition at line 3046 of file saveload.cpp.

References _save_thread, _sl, _sl_version, Debug, SaveLoadParams::dumper, SaveFileDone(), SaveFileStart(), SaveFileToDisk(), SAVEGAME_VERSION, SaveLoadParams::saveinprogress, SaveLoadParams::sf, SL_OK, SlSaveChunks(), and StartNewThread().

Referenced by SaveOrLoad(), and SaveWithFilter().

## ◆ FixSCCEncoded()

void FixSCCEncoded | ( | std::string & | str,
|  | bool | fix_code
| ) |  |

Scan the string for old values of SCC_ENCODED and fix it to it's new, value.

Note that at the moment this runs, the string has not been validated yet because the validation looks for SCC_ENCODED. If there is something invalid, just bail out and do not continue trying to replace the tokens.

Parameters

  str | the string to fix.

Definition at line 933 of file saveload.cpp.

References StringConsumer::AnyBytesLeft(), BaseStringBuilder::PutUtf8(), SCC_ENCODED, SCC_ENCODED_NUMERIC, SCC_ENCODED_STRING, and StringConsumer::TryReadUtf8().

Referenced by SlStdString().

## ◆ FixSCCEncodedNegative()

void FixSCCEncodedNegative | ( | std::string & | str | ) |

Scan the string for SCC_ENCODED_NUMERIC with negative values, and reencode them as uint64_t.

Parameters

  str | the string to fix.

Definition at line 1000 of file saveload.cpp.

References StringConsumer::AnyBytesLeft(), BaseStringBuilder::Put(), BaseStringBuilder::PutIntegerBase(), BaseStringBuilder::PutUtf8(), StringConsumer::READ_ONE_SEPARATOR, StringConsumer::ReadIntegerBase(), StringConsumer::ReadUntilUtf8(), StringConsumer::ReadUtf8If(), SCC_ENCODED, SCC_ENCODED_NUMERIC, and StringConsumer::TryReadIntegerBase().

Referenced by SlStdString().

## ◆ GenerateDefaultSaveName()

std::string GenerateDefaultSaveName | ( |  | ) |

Get the default name for a savegame or screenshot.

Definition at line 3375 of file saveload.cpp.

References _local_company, _settings_client, TimerGameTick::counter, TimerGameEconomy::date, GUISettings::date_format_in_default_names, GetStringWithArgs(), ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_company_pool >::Iterate(), SanitizeFilename(), Ticks::TICKS_PER_SECOND, and TimerGameEconomy::UsingWallclockUnits().

Referenced by DoAutoOrNetsave(), SaveLoadWindow::GenerateFileName(), and MakeScreenshotName().

## ◆ GetSavegameFileType()

static uint8_t GetSavegameFileType | ( | const SaveLoad & | sld | ) |
| static

Return the type as saved/loaded inside the savegame.

Definition at line 570 of file saveload.cpp.

References SaveLoad::cmd, SaveLoad::conv, GetVarFileType(), IsSavegameVersionBefore(), SL_ARR, SL_DEQUE, SL_REF, SL_REFLIST, SL_REFVECTOR, SL_SAVEBYTE, SL_STDSTR, SL_STRUCT, SL_STRUCTLIST, SL_VAR, SL_VECTOR, SLE_FILE_HAS_LENGTH_FIELD, and SLV_69.

Referenced by SlTableHeader().

## ◆ GetSavegameFormat()

static std::pair< const SaveLoadFormat &, uint8_t > GetSavegameFormat | ( | std::string_view | full_name | ) |
| static

Return the savegameformat of the game.

Whether it was created with ZLIB compression uncompressed, or another type

Parameters

  full_name | Name of the savegame format. If empty it picks the first available one

Returns
  Pair containing reference to SaveLoadFormat struct giving all characteristics of this type of savegame, and a compression level to use.

Definition at line 2849 of file saveload.cpp.

References _saveload_formats, Clamp(), SaveLoadFormat::default_compression, GetEncodedString(), SaveLoadFormat::name, ShowErrorMessage(), SlError(), and WL_CRITICAL.

Referenced by SaveFileToDisk().

## ◆ GetSaveLoadErrorMessage()

EncodedString GetSaveLoadErrorMessage | ( |  | ) |

Return the description of the error.

Definition at line 2973 of file saveload.cpp.

References _sl, SaveLoadParams::error_str, SaveLoadParams::extra_msg, and GetEncodedString().

Referenced by SaveFileError(), SaveFileToDisk(), and SaveOrLoad().

## ◆ GetSaveLoadErrorType()

EncodedString GetSaveLoadErrorType | ( |  | ) |

Return the appropriate initial string for an error depending on whether we are saving or loading.

Definition at line 2967 of file saveload.cpp.

References _sl, SaveLoadParams::action, GetEncodedString(), and SLA_SAVE.

Referenced by SaveFileError(), SaveFileToDisk(), and SaveOrLoad().

## ◆ InitializeGame()

void InitializeGame | ( | uint | size_x,
|  | uint | size_y,
|  | bool | reset_date,
|  | bool | reset_settings
| ) |  |

Definition at line 92 of file misc.cpp.

## ◆ IntToReference()

static void * IntToReference | ( | size_t | index,
|  | SLRefType | rt
| ) |  |
| static

Pointers cannot be loaded from a savegame, so this function gets the index from the savegame and returns the appropriate pointer from the already loaded base.

Remember that an index of 0 is a nullptr pointer so all indices are +1 so vehicle 0 is saved as 1.

Parameters

  index | The index that is being converted to a pointer
  rt | SLRefType type of the object the pointer is sought of

Returns
  Return the index converted to a pointer of any type

Definition at line 1258 of file saveload.cpp.

References _sl, SaveLoadParams::action, SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_link_graph_job_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_roadstop_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_enginerenew_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_orderlist_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_cargopacket_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_link_graph_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_persistent_storage_pool >::Get(), IsSavegameVersionBefore(), SpecializedStation< Station, false >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_cargopacket_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_orderlist_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_link_graph_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_town_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_link_graph_job_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_enginerenew_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_roadstop_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_vehicle_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem<&_persistent_storage_pool >::IsValidID(), REF_CARGO_PACKET, REF_ENGINE_RENEWS, REF_LINK_GRAPH, REF_LINK_GRAPH_JOB, REF_ORDERLIST, REF_ROADSTOPS, REF_STATION, REF_STORAGE, REF_TOWN, REF_VEHICLE, REF_VEHICLE_OLD, SLA_PTRS, SlErrorCorrupt(), and SLV_4.

Referenced by SlSaveLoadRef().

## ◆ LoadOldSaveGame()

bool LoadOldSaveGame | ( | std::string_view | file | ) |
| extern

Definition at line 234 of file oldloader.cpp.

## ◆ LoadWithFilter()

SaveOrLoadResult LoadWithFilter | ( | std::shared_ptr< LoadFilter > | reader | ) |

Load the game using a (reader) filter.

Parameters

  reader | The filter to read the savegame from.

Returns
  Return the result of the action. SL_OK or SL_REINIT ("unload" the game)

Definition at line 3238 of file saveload.cpp.

References _sl, SaveLoadParams::action, ClearSaveLoadState(), DoLoad(), SL_REINIT, and SLA_LOAD.

Referenced by SafeLoad().

## ◆ ProcessAsyncSaveFinish()

void ProcessAsyncSaveFinish | ( |  | ) |

Handle async save finishes.

Definition at line 394 of file saveload.cpp.

References _async_save_finish, and _save_thread.

## ◆ ReadValue()

int64_t ReadValue | ( | const void * | ptr,
|  | VarType | conv
| ) |  |

Return a signed-long version of the value of a setting.

Parameters

  ptr | pointer to the variable
  conv | type of variable, can be a non-clean type, eg one with other flags because it is parsed

Returns
  returns the value of the pointer-setting

Definition at line 812 of file saveload.cpp.

References GetVarMemType(), and SLE_VAR_NULL.

Referenced by CheatWindow::OnQueryTextFinished(), IntSettingDesc::Read(), and SlSaveLoadConv().

## ◆ ReferenceToInt()

static size_t ReferenceToInt | ( | const void * | obj,
|  | SLRefType | rt
| ) |  |
| static

Pointers cannot be saved to a savegame, so this functions gets the index of the item, and if not available, it hussles with pointers (looks really bad :() Remember that a nullptr item has value 0, and all indices have +1, so vehicle 0 is saved as index 1.

Parameters

  obj | The object that we want to get the index of
  rt | SLRefType type of the object the index is being sought of

Returns
  Return the pointer converted to an index of the type pointed to

Definition at line 1226 of file saveload.cpp.

References _sl, SaveLoadParams::action, REF_CARGO_PACKET, REF_ENGINE_RENEWS, REF_LINK_GRAPH, REF_LINK_GRAPH_JOB, REF_ORDERLIST, REF_ROADSTOPS, REF_STATION, REF_STORAGE, REF_TOWN, REF_VEHICLE, REF_VEHICLE_OLD, and SLA_SAVE.

Referenced by SlSaveLoadRef().

## ◆ ResetSaveloadData()

static void ResetSaveloadData | ( |  | ) |
| static

Clear temporary data that is passed between various saveload phases.

Definition at line 2917 of file saveload.cpp.

References ClearOldOrders(), and ResetSettings().

Referenced by DoLoad(), and SaveOrLoad().

## ◆ ResetSettings()

static void ResetSettings | ( |  | ) |
| static

Reset all settings to their default, so any settings missing in the savegame are their default, and not "value of last game".

AfterLoad might still fix up values to become non-default, depending on the saveload version.

Definition at line 2901 of file saveload.cpp.

References _network_server, _networking, _settings_game, SettingDesc::flags, GetSaveLoadSettingTable(), GetSettingDesc(), NoNetworkSync, NotInSave, SettingDesc::ResetToDefault(), and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by ResetSaveloadData().

## ◆ SaveFileDone()

static void SaveFileDone | ( |  | ) |
| static

Update the gui accordingly when saving is done and release locks on saveload.

Definition at line 2948 of file saveload.cpp.

References _sl, InvalidateWindowData(), SaveLoadParams::saveinprogress, SBI_SAVELOAD_FINISH, SetMouseCursorBusy(), and WC_STATUS_BAR.

Referenced by DoSave(), SaveFileError(), and SaveFileToDisk().

## ◆ SaveFileError()

static void SaveFileError | ( |  | ) |
| static

Show a gui message when saving has failed.

Definition at line 2979 of file saveload.cpp.

References GetSaveLoadErrorMessage(), GetSaveLoadErrorType(), SaveFileDone(), ShowErrorMessage(), and WL_ERROR.

Referenced by SaveFileToDisk().

## ◆ SaveFileStart()

static void SaveFileStart | ( |  | ) |
| static

Update the gui accordingly when starting saving and set locks on saveload.

Definition at line 2939 of file saveload.cpp.

References _sl, InvalidateWindowData(), SaveLoadParams::saveinprogress, SBI_SAVELOAD_START, SetMouseCursorBusy(), and WC_STATUS_BAR.

Referenced by DoSave().

## ◆ SaveFileToDisk()

static SaveOrLoadResult SaveFileToDisk | ( | bool | threaded | ) |
| static

We have written the whole game into memory, _memory_savegame, now find and appropriate compressor and start writing to file.

Definition at line 2989 of file saveload.cpp.

References _savegame_format, _sl, ClearSaveLoadState(), Debug, SaveLoadParams::dumper, SaveLoadParams::error_str, GetSavegameFormat(), GetSaveLoadErrorMessage(), GetSaveLoadErrorType(), SaveFileDone(), SaveFileError(), SAVEGAME_VERSION, SetAsyncSaveFinish(), SaveLoadParams::sf, and SL_OK.

Referenced by DoSave().

## ◆ SaveOrLoad()

SaveOrLoadResult SaveOrLoad | ( | std::string_view | filename,
|  | SaveLoadOperation | fop,
|  | DetailedFileType | dft,
|  | Subdirectory | sb,
|  | bool | threaded
| ) |  |

Main Save or Load function where the high-level saveload functions are handled.

It opens the savegame, selects format and checks versions

Parameters

  filename | The name of the savegame being created/loaded
  fop | Save or load mode. Load can also be a TTD(Patch) game.
  sb | The sub directory to save the savegame in
  threaded | True when threaded saving is allowed

Returns
  Return the result of the action. SL_OK, SL_ERROR, or SL_REINIT ("unload" the game)

Definition at line 3258 of file saveload.cpp.

References _do_autosave, _gamelog, _grfconfig, _settings_client, _sl, _sl_minor_version, _sl_version, SaveLoadParams::action, AfterLoadGame(), BASE_DIR, ClearGRFConfigList(), ClearSaveLoadState(), TimerGameEconomy::date, TimerGameEconomy::date_fract, Debug, DFT_GAME_FILE, DFT_OLD_GAME_FILE, DoLoad(), DoSave(), FioFOpenFile(), GetEncodedString(), GetSaveLoadErrorMessage(), GetSaveLoadErrorType(), GLAT_LOAD, ClientSettings::gui, Gamelog::Reset(), ResetSaveloadData(), SAVE_DIR, SaveLoadParams::saveinprogress, SCENARIO_DIR, ShowErrorMessage(), SL_MIN_VERSION, SL_OK, SL_REINIT, SLA_LOAD, SLA_LOAD_CHECK, SLA_SAVE, SlError(), SLO_CHECK, SLO_LOAD, SLO_SAVE, Gamelog::StartAction(), Gamelog::StopAction(), GUISettings::threaded_saves, and WL_ERROR.

Referenced by _GenerateWorld(), ConSave(), DoAutoOrNetsave(), DoExitSave(), LoadIntroGame(), SaveLoadWindow::OnClick(), openttd_main(), SafeLoad(), StateGameLoop(), and CrashLog::WriteSavegame().

## ◆ SaveWithFilter()

SaveOrLoadResult SaveWithFilter | ( | std::shared_ptr< SaveFilter > | writer,
|  | bool | threaded
| ) |  |

Save the game using a (writer) filter.

Parameters

  writer | The filter to write the savegame to.
  threaded | Whether to try to perform the saving asynchronously.

Returns
  Return the result of the action. SL_OK or SL_ERROR

Definition at line 3078 of file saveload.cpp.

References _sl, SaveLoadParams::action, ClearSaveLoadState(), DoSave(), and SLA_SAVE.

Referenced by ServerNetworkGameSocketHandler::SendMap().

## ◆ SetAsyncSaveFinish()

static void SetAsyncSaveFinish | ( | AsyncSaveFinishProc | proc | ) |
| static

Called by save thread to tell we finished saving.

Parameters

  proc | The callback to call when saving is done.

Definition at line 383 of file saveload.cpp.

References _async_save_finish, and CSleep().

Referenced by SaveFileToDisk().

## ◆ SetSaveLoadError()

void SetSaveLoadError | ( | StringID | str | ) |

Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friends)

Definition at line 2961 of file saveload.cpp.

References _sl, and SaveLoadParams::error_str.

Referenced by AfterLoadGame().

## ◆ SlArray()

static void SlArray | ( | void * | array,
|  | size_t | length,
|  | VarType | conv
| ) |  |
| static

Save/Load the length of the array followed by the array of SL_VAR elements.

Parameters

  array | The array being manipulated
  length | The length of the array in elements
  conv | VarType type of the atomic array (int, uint8_t, uint64_t, etc.)

Definition at line 1180 of file saveload.cpp.

References _sl, SaveLoadParams::action, GetVarMemType(), IsSavegameVersionBefore(), SLA_LOAD, SLA_LOAD_CHECK, SLA_NULL, SLA_PTRS, SLA_SAVE, SlCopyInternal(), SLE_VAR_NULL, SlErrorCorrupt(), and SLV_SAVELOAD_LIST_LENGTH.

## ◆ SlAutolength()

void SlAutolength | ( | AutolengthProc * | proc,
|  | int | arg
| ) |  |

Do something of which I have no idea what it is :P.

Parameters

  proc | The callback procedure that is called
  arg | The variable that will be used for the callback procedure

Definition at line 2101 of file saveload.cpp.

References _sl, SaveLoadParams::action, SaveLoadParams::dumper, SaveLoadParams::need_length, NL_CALCLENGTH, NL_WANTLENGTH, SaveLoadParams::obj_len, SLA_SAVE, and SlSetLength().

Referenced by AIPLChunkHandler::Save(), and GSDTChunkHandler::Save().

## ◆ SlCalcArrayLen()

static size_t SlCalcArrayLen | ( | size_t | length,
|  | VarType | conv
| ) |  |
| inlinestatic

Return the size in bytes of a certain type of atomic array.

Parameters

  length | The length of the array counted in elements
  conv | VarType type of the variable that is used in calculating the size

Definition at line 1169 of file saveload.cpp.

References SlCalcConvFileLen().

## ◆ SlCalcConvFileLen()

static uint8_t SlCalcConvFileLen | ( | VarType | conv | ) |
| inlinestatic

Return the size in bytes of a certain type of normal/atomic variable as it appears in a saved game.

See VarTypes

Parameters

  conv | VarType type of variable that is used for calculating the size

Returns
  Return the size of this type in bytes

Definition at line 636 of file saveload.cpp.

References GetVarFileType(), SLE_FILE_END, and SLE_FILE_STRINGID.

Referenced by SlCalcArrayLen(), SlStorageHelper< Tstorage, Tvar, Tallocator >::SlCalcLen(), SlCalcTableHeader(), SlCopy(), and SlCopyInternal().

## ◆ SlCalcConvMemLen()

static uint SlCalcConvMemLen | ( | VarType | conv | ) |
| inlinestatic

Return the size in bytes of a certain type of normal/atomic variable as it appears in memory.

See VarTypes

Parameters

  conv | VarType type of variable that is used for calculating the size

Returns
  Return the size of this type in bytes

Definition at line 606 of file saveload.cpp.

References GetVarMemType(), SLE_VAR_NAME, SLE_VAR_NULL, SLE_VAR_STR, and SLE_VAR_STRQ.

Referenced by SlCopyInternal().

## ◆ SlCalcDequeLen()

static size_t SlCalcDequeLen | ( | const void * | deque,
|  | VarType | conv
| ) |  |
| inlinestatic

Return the size in bytes of a std::deque.

Parameters

  deque | The std::deque to find the size of
  conv | VarType type of variable that is used for calculating the size

Definition at line 1501 of file saveload.cpp.

References GetVarMemType(), SlStorageHelper< Tstorage, Tvar, Tallocator >::SlCalcLen(), and SLE_VAR_STR.

## ◆ SlCalcObjLength()

size_t SlCalcObjLength | ( | const void * | object,
|  | const SaveLoadTable & | slt
| ) |  |

Calculate the size of an object.

Parameters

  object | to be measured.
  slt | The SaveLoad table with objects to save/load.

Returns
  size of given object.

Definition at line 1652 of file saveload.cpp.

Referenced by SlObject().

## ◆ SlCalcObjMemberLength()

size_t SlCalcObjMemberLength | ( | const void * | object,
|  | const SaveLoad & | sld
| ) |  |

Definition at line 1663 of file saveload.cpp.

## ◆ SlCalcRefLen()

static size_t SlCalcRefLen | ( |  | ) |
| inlinestatic

Return the size in bytes of a reference (pointer)

Definition at line 660 of file saveload.cpp.

References IsSavegameVersionBefore(), and SLV_69.

## ◆ SlCalcRefListLen()

static size_t SlCalcRefListLen | ( | const void * | list,
|  | VarType | conv
| ) |  |
| inlinestatic

Return the size in bytes of a list.

Parameters

  list | The std::list to find the size of.
  conv | VarType type of variable that is used for calculating the size.

Definition at line 1447 of file saveload.cpp.

References SL_REF, and SlStorageHelper< Tstorage, Tvar, Tallocator >::SlCalcLen().

Referenced by SlRefList().

## ◆ SlCalcRefVectorLen()

static size_t SlCalcRefVectorLen | ( | const void * | vector,
|  | VarType | conv
| ) |  |
| static

Return the size in bytes of a vector.

Parameters

  vector | The std::vector to find the size of.
  conv | VarType type of variable that is used for calculating the size.

Definition at line 1474 of file saveload.cpp.

References SL_REF, and SlStorageHelper< Tstorage, Tvar, Tallocator >::SlCalcLen().

Referenced by SlRefVector().

## ◆ SlCalcStdStringLen()

static size_t SlCalcStdStringLen | ( | const void * | ptr | ) |
| inlinestatic

Calculate the gross length of the string that it will occupy in the savegame.

This includes the real length, returned by SlCalcNetStringLen and the length that the index will occupy.

Parameters

  ptr | Pointer to the `std::string`.

Returns
  The gross length of the string.

Definition at line 917 of file saveload.cpp.

Referenced by SlCalcTableHeader().

## ◆ SlCalcTableHeader()

static size_t SlCalcTableHeader | ( | const SaveLoadTable & | slt | ) |
| static

Calculate the size of the table header.

Parameters

  slt | The SaveLoad table with objects to save/load.

Returns
  size of given object.

Definition at line 1623 of file saveload.cpp.

References SL_STRUCT, SL_STRUCTLIST, SlCalcConvFileLen(), SlCalcStdStringLen(), SlCalcTableHeader(), and SlIsObjectValidInSavegame().

Referenced by SlCalcTableHeader(), and SlTableHeader().

## ◆ SlCalcVectorLen()

static size_t SlCalcVectorLen | ( | const void * | vector,
|  | VarType | conv
| ) |  |
| inlinestatic

Return the size in bytes of a std::vector.

Parameters

  vector | The std::vector to find the size of
  conv | VarType type of variable that is used for calculating the size

Definition at line 1559 of file saveload.cpp.

References GetVarMemType(), SlStorageHelper< Tstorage, Tvar, Tallocator >::SlCalcLen(), and SLE_VAR_STR.

## ◆ SlCompatTableHeader()

std::vector< SaveLoad > SlCompatTableHeader | ( | const SaveLoadTable & | slt,
|  | const SaveLoadCompatTable & | slct
| ) |  |

Load a table header in a savegame compatible way.

If the savegame was made before table headers were added, it will fall back to the SaveLoadCompatTable for the order of fields while loading.

Note
  You only have to call this function if the chunk existed as a non-table type before converting it to a table. New chunks created as table can call SlTableHeader() directly.

Parameters

  slt | The SaveLoad table with objects to save/load.
  slct | The SaveLoadCompat table the original order of the fields.

Returns
  When loading, the ordered SaveLoad array to use; otherwise an empty list.

Definition at line 2037 of file saveload.cpp.

References _sl, SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoad::cmd, Debug, GetVarFileType(), SaveLoad::handler, SaveLoad::name, SL_NULL, SL_STRUCT, SL_STRUCTLIST, SLA_LOAD, SLA_LOAD_CHECK, SlCompatTableHeader(), SLE_VAR_NULL, SlErrorCorrupt(), SlIsObjectValidInSavegame(), and SlTableHeader().

Referenced by AIPLChunkHandler::Load(), ANITChunkHandler::Load(), ERNWChunkHandler::Load(), CMDLChunkHandler::Load(), CMPUChunkHandler::Load(), CAPAChunkHandler::Load(), CHTSChunkHandler::Load(), PLYRChunkHandler::Load(), DEPTChunkHandler::Load(), ECMYChunkHandler::Load(), CAPYChunkHandler::Load(), ENGNChunkHandler::Load(), EIDSChunkHandler::Load(), GSDTChunkHandler::Load(), GSTRChunkHandler::Load(), GOALChunkHandler::Load(), GRPSChunkHandler::Load(), INDYChunkHandler::Load(), IBLDChunkHandler::Load(), ITBLChunkHandler::Load(), RAILChunkHandler::Load(), ROTTChunkHandler::Load(), LGRPChunkHandler::Load(), LGRJChunkHandler::Load(), LGRSChunkHandler::Load(), MAPSChunkHandler::Load(), VIEWChunkHandler::Load(), NewGRFMappingChunkHandler::Load(), OBJSChunkHandler::Load(), ORDRChunkHandler::Load(), ORDLChunkHandler::Load(), BKORChunkHandler::Load(), SIGNChunkHandler::Load(), STNSChunkHandler::Load(), STNNChunkHandler::Load(), ROADChunkHandler::Load(), PSACChunkHandler::Load(), STPEChunkHandler::Load(), STPAChunkHandler::Load(), SUBSChunkHandler::Load(), CITYChunkHandler::Load(), VEHSChunkHandler::Load(), PLYRChunkHandler::LoadCheck(), MAPSChunkHandler::LoadCheck(), LoadSettings(), and SlCompatTableHeader().

## ◆ SlCopy()

void SlCopy | ( | void * | object,
|  | size_t | length,
|  | VarType | conv
| ) |  |

Copy a list of SL_VARs to/from a savegame.

These entries are copied as-is, and you as caller have to make sure things like length-fields are calculated correctly.

Parameters

  object | The object being manipulated.
  length | The length of the object in elements
  conv | VarType type of the items.

Definition at line 1150 of file saveload.cpp.

References _sl, SaveLoadParams::action, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SLA_NULL, SLA_PTRS, SlCalcConvFileLen(), SlCopyInternal(), and SlSetLength().

Referenced by ANITChunkHandler::Load(), PRICChunkHandler::Load(), CAPRChunkHandler::Load(), ENGSChunkHandler::Load(), MAPTChunkHandler::Load(), MAPHChunkHandler::Load(), MAPOChunkHandler::Load(), MAP2ChunkHandler::Load(), M3LOChunkHandler::Load(), M3HIChunkHandler::Load(), MAP5ChunkHandler::Load(), MAPEChunkHandler::Load(), MAP7ChunkHandler::Load(), MAP8ChunkHandler::Load(), ORDRChunkHandler::Load(), ScriptInstance::LoadObjects(), MAPTChunkHandler::Save(), MAPHChunkHandler::Save(), MAPOChunkHandler::Save(), MAP2ChunkHandler::Save(), M3LOChunkHandler::Save(), M3HIChunkHandler::Save(), MAP5ChunkHandler::Save(), MAPEChunkHandler::Save(), MAP7ChunkHandler::Save(), MAP8ChunkHandler::Save(), and ScriptInstance::SaveObject().

## ◆ SlCopyBytes()

static void SlCopyBytes | ( | void * | ptr,
|  | size_t | length
| ) |  |
| static

Save/Load bytes.

These do not need to be converted to Little/Big Endian so directly write them or read them to/from file

Parameters

  ptr | The source or destination of the object being manipulated
  length | number of bytes this fast CopyBytes lasts

Definition at line 783 of file saveload.cpp.

References _sl, SaveLoadParams::action, SLA_LOAD, SLA_LOAD_CHECK, SLA_SAVE, SlReadByte(), and SlWriteByte().

Referenced by SlCopyInternal(), SlReadString(), and SlStdString().

## ◆ SlCopyInternal()

static void SlCopyInternal | ( | void * | object,
|  | size_t | length,
|  | VarType | conv
| ) |  |
| static

Internal function to save/Load a list of SL_VARs.

SlCopy() and SlArray() are very similar, with the exception of the header. This function represents the common part.

Parameters

  object | The object being manipulated.
  length | The length of the object in elements
  conv | VarType type of the items.

Definition at line 1101 of file saveload.cpp.

References _sl, _sl_version, SaveLoadParams::action, GetVarMemType(), SLA_SAVE, SlCalcConvFileLen(), SlCalcConvMemLen(), SlCopyBytes(), SLE_VAR_NULL, SlSaveLoadConv(), and SlSkipBytes().

Referenced by SlArray(), and SlCopy().

## ◆ SlDeque()

static void SlDeque | ( | void * | deque,
|  | VarType | conv
| ) |  |
| static

Save/load a std::deque.

Parameters

  deque | The std::deque being manipulated
  conv | VarType type of variable that is used for calculating the size

Definition at line 1528 of file saveload.cpp.

References _sl, SaveLoadParams::action, GetVarMemType(), SL_STDSTR, SLA_SAVE, SLE_VAR_STR, and SlStorageHelper< Tstorage, Tvar, Tallocator >::SlSaveLoad().

## ◆ SlError()

void SlError | ( | StringID | string,
|  | const std::string & | extra_msg
| ) |  |

Error handler.

Sets everything up to show an error message and to clean up the mess of a partial savegame load.

Parameters

  string | The translatable error message to show.
  extra_msg | An extra error message coming from one of the APIs.

Note
  This function does never return as it throws an exception to break out of all the saveload code.

Definition at line 339 of file saveload.cpp.

References _gamelog, _load_check_data, _sl, SaveLoadParams::action, LoadCheckData::error, LoadCheckData::error_msg, SaveLoadParams::error_str, SaveLoadParams::extra_msg, SLA_LOAD, SLA_LOAD_CHECK, SLA_PTRS, and SlNullPointers().

Referenced by AfterLoadGame(), DetermineSaveLoadFormat(), DoLoad(), PacketWriter::Finish(), GetSavegameFormat(), LZMALoadFilter::LZMALoadFilter(), LZMASaveFilter::LZMASaveFilter(), LZOLoadFilter::LZOLoadFilter(), LZOSaveFilter::LZOSaveFilter(), MoveWaypointsToBaseStations(), ZlibLoadFilter::Read(), LZMALoadFilter::Read(), LZOLoadFilter::Read(), SaveOrLoad(), SlErrorCorrupt(), PacketWriter::Write(), FileWriter::Write(), ZlibSaveFilter::WriteLoop(), LZMASaveFilter::WriteLoop(), ZlibLoadFilter::ZlibLoadFilter(), and ZlibSaveFilter::ZlibSaveFilter().

## ◆ SlErrorCorrupt()

void SlErrorCorrupt | ( | const std::string & | msg | ) |

Error handler for corrupt savegames.

Sets everything up to show the error message and to clean up the mess of a partial savegame load.

Parameters

  msg | Location the corruption has been spotted.

Note
  This function does never return as it throws an exception to break out of all the saveload code.

Definition at line 369 of file saveload.cpp.

References SlError().

Referenced by AfterLoadGame(), AfterLoadVehiclesPhase2(), ConvertOldMultiheadToNew(), CHKPChunkHandler::FixPointers(), IntToReference(), AIPLChunkHandler::Load(), ANITChunkHandler::Load(), CHTSChunkHandler::Load(), ECMYChunkHandler::Load(), GSDTChunkHandler::Load(), IBLDChunkHandler::Load(), ITBLChunkHandler::Load(), LGRSChunkHandler::Load(), MAPSChunkHandler::Load(), VIEWChunkHandler::Load(), NGRFChunkHandler::Load(), NewGRFMappingChunkHandler::Load(), NAMEChunkHandler::Load(), CITYChunkHandler::Load(), VEHSChunkHandler::Load(), MAPSChunkHandler::LoadCheck(), ScriptInstance::LoadObjects(), LoadSettings(), MoveWaypointsToBaseStations(), LZOLoadFilter::Read(), SetWaterClassDependingOnSurroundings(), SlArray(), SlCompatTableHeader(), SlGetStructListLength(), SlLoadCheckChunk(), SlLoadCheckChunks(), SlLoadChunk(), SlLoadChunks(), SlReadSimpleGamma(), SlSaveChunk(), and SlTableHeader().

## ◆ SlFindChunkHandler()

static const ChunkHandler * SlFindChunkHandler | ( | uint32_t | id | ) |
| static

Find the ChunkHandler that will be used for processing the found chunk in the savegame or in memory.

Parameters

  id | the chunk in question

Returns
  returns the appropriate chunkhandler

Definition at line 2304 of file saveload.cpp.

References ChunkHandlers().

Referenced by SlLoadCheckChunks(), and SlLoadChunks().

## ◆ SlFixPointers()

static void SlFixPointers | ( |  | ) |
| static

Fix all pointers (convert index -> pointer)

Definition at line 2341 of file saveload.cpp.

References _sl, SaveLoadParams::action, ChunkHandlers(), Debug, and SLA_PTRS.

Referenced by DoLoad().

## ◆ SlGetArrayLength()

static uint SlGetArrayLength | ( | size_t | length | ) |
| inlinestatic

Definition at line 562 of file saveload.cpp.

## ◆ SlGetFieldLength()

size_t SlGetFieldLength | ( |  | ) |

Get the length of the current object.

Definition at line 800 of file saveload.cpp.

References _sl, and SaveLoadParams::obj_len.

Referenced by ANITChunkHandler::Load(), CHTSChunkHandler::Load(), ORDRChunkHandler::Load(), and NAMEChunkHandler::Load().

## ◆ SlGetGammaLength()

static uint SlGetGammaLength | ( | size_t | i | ) |
| inlinestatic

Return how many bytes used to encode a gamma value.

Definition at line 537 of file saveload.cpp.

## ◆ SlGetStructListLength()

size_t SlGetStructListLength | ( | size_t | limit | ) |

Get the length of this list; if it exceeds the limit, error out.

Parameters

  limit | The maximum size the list can be.

Returns
  The length of the list.

Definition at line 1833 of file saveload.cpp.

References SlErrorCorrupt().

Referenced by VectorSaveLoadHandler< TImpl, TObject, TElementType, MAX_LENGTH >::GetLength(), SlStationSpecList< T >::GetLength(), SlStationGoods::GetNumCargo(), SlTownOldSupplied::GetNumCargo(), SlCompanyLiveries::GetNumLiveries(), and SlSkipHandler::Load().

## ◆ SlGlobList()

void SlGlobList | ( | const SaveLoadTable & | slt | ) |

Save or Load (a list of) global variables.

Parameters

  slt | The SaveLoad table with objects to save/load.

Definition at line 2091 of file saveload.cpp.

References SlObject().

Referenced by ANITChunkHandler::Load(), IBLDChunkHandler::Load(), MAPSChunkHandler::Load(), VIEWChunkHandler::Load(), MAPSChunkHandler::LoadCheck(), ANITChunkHandler::Save(), IBLDChunkHandler::Save(), MAPSChunkHandler::Save(), DATEChunkHandler::Save(), and VIEWChunkHandler::Save().

## ◆ SlIsObjectValidInSavegame()

static bool SlIsObjectValidInSavegame | ( | const SaveLoad & | sld | ) |
| inlinestatic

Are we going to save this object or not?

Definition at line 1613 of file saveload.cpp.

References _sl_version, SaveLoad::version_from, and SaveLoad::version_to.

Referenced by SlCalcTableHeader(), SlCompatTableHeader(), and SlTableHeader().

## ◆ SlIterateArray()

int SlIterateArray | ( |  | ) |

Iterate through the elements of an array and read the whole thing.

Returns
  The index of the object, or -1 if we have reached the end of current block

Definition at line 677 of file saveload.cpp.

References _sl, SaveLoadParams::block_mode, Debug, SaveLoadParams::expect_table_header, SaveLoadParams::obj_len, and SaveLoadParams::reader.

Referenced by AIPLChunkHandler::Load(), ANITChunkHandler::Load(), ERNWChunkHandler::Load(), CMDLChunkHandler::Load(), CMPUChunkHandler::Load(), CAPAChunkHandler::Load(), CHTSChunkHandler::Load(), PLYRChunkHandler::Load(), DEPTChunkHandler::Load(), ECMYChunkHandler::Load(), CAPYChunkHandler::Load(), ENGNChunkHandler::Load(), EIDSChunkHandler::Load(), GSDTChunkHandler::Load(), GSTRChunkHandler::Load(), GOALChunkHandler::Load(), GRPSChunkHandler::Load(), INDYChunkHandler::Load(), IBLDChunkHandler::Load(), ITBLChunkHandler::Load(), RAILChunkHandler::Load(), ROTTChunkHandler::Load(), LEAEChunkHandler::Load(), LEATChunkHandler::Load(), LGRPChunkHandler::Load(), LGRJChunkHandler::Load(), LGRSChunkHandler::Load(), MAPSChunkHandler::Load(), VIEWChunkHandler::Load(), NewGRFMappingChunkHandler::Load(), OBJSChunkHandler::Load(), ORDRChunkHandler::Load(), ORDLChunkHandler::Load(), BKORChunkHandler::Load(), SRNDChunkHandler::Load(), SIGNChunkHandler::Load(), STNSChunkHandler::Load(), STNNChunkHandler::Load(), ROADChunkHandler::Load(), PSACChunkHandler::Load(), STPEChunkHandler::Load(), STPAChunkHandler::Load(), NAMEChunkHandler::Load(), SUBSChunkHandler::Load(), CITYChunkHandler::Load(), VEHSChunkHandler::Load(), CHKPChunkHandler::Load(), PLYRChunkHandler::LoadCheck(), MAPSChunkHandler::LoadCheck(), LoadSettings(), SlLoadCheckChunk(), SlLoadChunk(), and SlSkipArray().

## ◆ SlLoadCheckChunk()

static void SlLoadCheckChunk | ( | const ChunkHandler & | ch | ) |
| static

Load a chunk of data for checking savegames.

If the chunkhandler is nullptr, the chunk is skipped.

Parameters

  ch | The chunkhandler that will be used for the operation

Definition at line 2201 of file saveload.cpp.

References _sl, SaveLoadParams::block_mode, CH_TYPE_MASK, SaveLoadParams::expect_table_header, ChunkHandler::LoadCheck(), SaveLoadParams::obj_len, SaveLoadParams::reader, SlErrorCorrupt(), SlIterateArray(), and SlReadByte().

Referenced by SlLoadCheckChunks().

## ◆ SlLoadCheckChunks()

static void SlLoadCheckChunks | ( |  | ) |
| static

Load all chunks for savegame checking.

Definition at line 2326 of file saveload.cpp.

References Debug, SlErrorCorrupt(), SlFindChunkHandler(), and SlLoadCheckChunk().

Referenced by DoLoad().

## ◆ SlLoadChunk()

static void SlLoadChunk | ( | const ChunkHandler & | ch | ) |
| static

Load a chunk of data (eg vehicles, stations, etc.)

Parameters

  ch | The chunkhandler that will be used for the operation

Definition at line 2148 of file saveload.cpp.

References _sl, SaveLoadParams::block_mode, CH_TYPE_MASK, SaveLoadParams::expect_table_header, ChunkHandler::Load(), SaveLoadParams::obj_len, SaveLoadParams::reader, SlErrorCorrupt(), SlIterateArray(), and SlReadByte().

Referenced by SlLoadChunks().

## ◆ SlLoadChunks()

static void SlLoadChunks | ( |  | ) |
| static

Load all chunks.

Definition at line 2311 of file saveload.cpp.

References Debug, SlErrorCorrupt(), SlFindChunkHandler(), and SlLoadChunk().

Referenced by DoLoad().

## ◆ SlNullPointers()

static void SlNullPointers | ( |  | ) |
| static

Null all pointers (convert index -> nullptr)

Definition at line 314 of file saveload.cpp.

References _sl, _sl_version, SaveLoadParams::action, ChunkHandlers(), Debug, SAVEGAME_VERSION, and SLA_NULL.

Referenced by SlError().

## ◆ SlObject()

void SlObject | ( | void * | object,
|  | const SaveLoadTable & | slt
| ) |  |

Main SaveLoad function.

Parameters

  object | The object that is being saved or loaded.
  slt | The SaveLoad table with objects to save/load.

Definition at line 1846 of file saveload.cpp.

References _sl, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SlCalcObjLength(), and SlSetLength().

Referenced by ERNWChunkHandler::FixPointers(), PLYRChunkHandler::FixPointers(), DEPTChunkHandler::FixPointers(), CAPYChunkHandler::FixPointers(), INDYChunkHandler::FixPointers(), LGRSChunkHandler::FixPointers(), OBJSChunkHandler::FixPointers(), ORDLChunkHandler::FixPointers(), BKORChunkHandler::FixPointers(), STNSChunkHandler::FixPointers(), STNNChunkHandler::FixPointers(), ROADChunkHandler::FixPointers(), CITYChunkHandler::FixPointers(), VEHSChunkHandler::FixPointers(), CHKPChunkHandler::FixPointers(), AIPLChunkHandler::Load(), ERNWChunkHandler::Load(), CMDLChunkHandler::Load(), CMPUChunkHandler::Load(), CAPAChunkHandler::Load(), CHTSChunkHandler::Load(), PLYRChunkHandler::Load(), DEPTChunkHandler::Load(), ECMYChunkHandler::Load(), CAPYChunkHandler::Load(), ENGNChunkHandler::Load(), EIDSChunkHandler::Load(), GSDTChunkHandler::Load(), GSTRChunkHandler::Load(), GOALChunkHandler::Load(), GRPSChunkHandler::Load(), INDYChunkHandler::Load(), ITBLChunkHandler::Load(), RAILChunkHandler::Load(), ROTTChunkHandler::Load(), LEAEChunkHandler::Load(), LEATChunkHandler::Load(), LGRPChunkHandler::Load(), LGRJChunkHandler::Load(), LGRSChunkHandler::Load(), NewGRFMappingChunkHandler::Load(), OBJSChunkHandler::Load(), ORDRChunkHandler::Load(), ORDLChunkHandler::Load(), BKORChunkHandler::Load(), SRNDChunkHandler::Load(), SIGNChunkHandler::Load(), STNSChunkHandler::Load(), STNNChunkHandler::Load(), ROADChunkHandler::Load(), PSACChunkHandler::Load(), STPEChunkHandler::Load(), STPAChunkHandler::Load(), SUBSChunkHandler::Load(), CITYChunkHandler::Load(), VEHSChunkHandler::Load(), CHKPChunkHandler::Load(), ScriptInstance::Load(), SlSkipHandler::Load(), PLYRChunkHandler::LoadCheck(), ScriptInstance::LoadEmpty(), ScriptInstance::LoadObjects(), LoadSettings(), ScriptInstance::Save(), ERNWChunkHandler::Save(), CMDLChunkHandler::Save(), CMPUChunkHandler::Save(), CAPAChunkHandler::Save(), CHTSChunkHandler::Save(), PLYRChunkHandler::Save(), DEPTChunkHandler::Save(), ECMYChunkHandler::Save(), CAPYChunkHandler::Save(), ENGNChunkHandler::Save(), EIDSChunkHandler::Save(), GSTRChunkHandler::Save(), GLOGChunkHandler::Save(), GOALChunkHandler::Save(), GRPSChunkHandler::Save(), INDYChunkHandler::Save(), ITBLChunkHandler::Save(), RAILChunkHandler::Save(), ROTTChunkHandler::Save(), LEAEChunkHandler::Save(), LEATChunkHandler::Save(), LGRPChunkHandler::Save(), LGRJChunkHandler::Save(), LGRSChunkHandler::Save(), NGRFChunkHandler::Save(), NewGRFMappingChunkHandler::Save(), OBJSChunkHandler::Save(), ORDLChunkHandler::Save(), BKORChunkHandler::Save(), SRNDChunkHandler::Save(), SIGNChunkHandler::Save(), STNNChunkHandler::Save(), ROADChunkHandler::Save(), PSACChunkHandler::Save(), STPEChunkHandler::Save(), STPAChunkHandler::Save(), SUBSChunkHandler::Save(), CITYChunkHandler::Save(), VEHSChunkHandler::Save(), ScriptInstance::SaveEmpty(), ScriptInstance::SaveObject(), SaveSettings(), and SlGlobList().

## ◆ SlObjectMember()

static bool SlObjectMember | ( | void * | object,
|  | const SaveLoad & | sld
| ) |  |
| static

Definition at line 1710 of file saveload.cpp.

## ◆ SlReadArrayLength()

static uint SlReadArrayLength | ( |  | ) |
| inlinestatic

Definition at line 552 of file saveload.cpp.

## ◆ SlReadByte()

uint8_t SlReadByte | ( |  | ) |

Wrapper for reading a byte from the buffer.

Returns
  The read byte.

Definition at line 410 of file saveload.cpp.

References _sl, and SaveLoadParams::reader.

Referenced by STNNChunkHandler::Load(), VEHSChunkHandler::Load(), SlCopyBytes(), SlLoadCheckChunk(), SlLoadChunk(), SlReadSimpleGamma(), SlSaveLoadConv(), and SlSkipBytes().

## ◆ SlReadSimpleGamma()

static uint SlReadSimpleGamma | ( |  | ) |
| static

Read in the header descriptor of an object or an array.

If the highest bit is set (7), then the index is bigger than 127 elements, so use the next byte to read in the real value. The actual value is then both bytes added with the first shifted 8 bits to the left, and dropping the highest bit (which only indicated a big index). x = ((x & 0x7F) << 8) + SlReadByte();

Returns
  Return the value of the index

Definition at line 470 of file saveload.cpp.

References HasBit(), SlErrorCorrupt(), and SlReadByte().

## ◆ SlReadSparseIndex()

static uint SlReadSparseIndex | ( |  | ) |
| inlinestatic

Definition at line 542 of file saveload.cpp.

## ◆ SlReadString()

void SlReadString | ( | std::string & | str,
|  | size_t | length
| ) |  |

Read the given amount of bytes from the buffer into the string.

Parameters

  str | The string to write to.
  length | The amount of bytes to read into the string.

Note
  Does not perform any validation on validity of the string.

Definition at line 1039 of file saveload.cpp.

References SlCopyBytes().

Referenced by NAMEChunkHandler::Load(), and SlStdString().

## ◆ SlReadUint16()

static int SlReadUint16 | ( |  | ) |
| inlinestatic

Definition at line 424 of file saveload.cpp.

## ◆ SlReadUint32()

static uint32_t SlReadUint32 | ( |  | ) |
| inlinestatic

Definition at line 430 of file saveload.cpp.

## ◆ SlReadUint64()

static uint64_t SlReadUint64 | ( |  | ) |
| inlinestatic

Definition at line 436 of file saveload.cpp.

## ◆ SlRefList()

static void SlRefList | ( | void * | list,
|  | VarType | conv
| ) |  |
| static

Save/Load a list.

Parameters

  list | The list being manipulated.
  conv | VarType type of variable that is used for calculating the size.

Definition at line 1457 of file saveload.cpp.

References _sl, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SL_REF, SlCalcRefListLen(), SlStorageHelper< Tstorage, Tvar, Tallocator >::SlSaveLoad(), and SlSetLength().

## ◆ SlRefVector()

static void SlRefVector | ( | void * | vector,
|  | VarType | conv
| ) |  |
| static

Save/Load a vector.

Parameters

  vector | The vector being manipulated.
  conv | VarType type of variable that is used for calculating the size.

Definition at line 1484 of file saveload.cpp.

References _sl, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SL_REF, SlCalcRefVectorLen(), SlStorageHelper< Tstorage, Tvar, Tallocator >::SlSaveLoad(), and SlSetLength().

## ◆ SlSaveChunk()

static void SlSaveChunk | ( | const ChunkHandler & | ch | ) |
| static

Save a chunk of data (eg.

vehicles, stations, etc.). Each chunk is prefixed by an ID identifying it, followed by data, and terminator where appropriate

Parameters

  ch | The chunkhandler that will be used for the operation

Definition at line 2252 of file saveload.cpp.

References _sl, SaveLoadParams::block_mode, CH_READONLY, Debug, SaveLoadParams::expect_table_header, ChunkHandler::id, SaveLoadParams::last_array_index, SaveLoadParams::need_length, NL_NONE, NL_WANTLENGTH, ChunkHandler::Save(), SlErrorCorrupt(), SlWriteByte(), and ChunkHandler::type.

Referenced by SlSaveChunks().

## ◆ SlSaveChunks()

static void SlSaveChunks | ( |  | ) |
| static

Save all chunks.

Definition at line 2288 of file saveload.cpp.

References ChunkHandlers(), and SlSaveChunk().

Referenced by DoSave().

## ◆ SlSaveLoadConv()

static void SlSaveLoadConv | ( | void * | ptr,
|  | VarType | conv
| ) |  |
| static

Handle all conversion and typechecking of variables here.

In the case of saving, read in the actual value from the struct and then write them to file, endian safely. Loading a value goes exactly the opposite way

Parameters

  ptr | The object being filled/read
  conv | VarType type of the current element of the struct

Definition at line 862 of file saveload.cpp.

References _sl, SaveLoadParams::action, GetVarFileType(), ReadValue(), RemapOldStringID(), SLA_LOAD, SLA_LOAD_CHECK, SLA_NULL, SLA_PTRS, SLA_SAVE, SLE_FILE_STRINGID, SlReadByte(), SlWriteByte(), and WriteValue().

Referenced by SlCopyInternal(), and SlTableHeader().

## ◆ SlSaveLoadRef()

void SlSaveLoadRef | ( | void * | ptr,
|  | VarType | conv
| ) |  |

Handle conversion for references.

Parameters

  ptr | The object being filled/read.
  conv | VarType type of the current element of the struct.

Definition at line 1328 of file saveload.cpp.

References _sl, SaveLoadParams::action, IntToReference(), IsSavegameVersionBefore(), ReferenceToInt(), SLA_LOAD, SLA_LOAD_CHECK, SLA_NULL, SLA_PTRS, SLA_SAVE, and SLV_69.

## ◆ SlSetArrayIndex()

void SlSetArrayIndex | ( | uint | index | ) |

Definition at line 665 of file saveload.cpp.

## ◆ SlSetLength()

void SlSetLength | ( | size_t | length | ) |

Sets the length of either a RIFF object or the number of items in an array.

This lets us load an object or an array of arbitrary size

Parameters

  length | The length of the sought object/array

Definition at line 731 of file saveload.cpp.

References _sl, SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoadParams::expect_table_header, SaveLoadParams::last_array_index, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, NL_WANTLENGTH, SaveLoadParams::obj_len, and SLA_SAVE.

Referenced by MAPTChunkHandler::Save(), MAPHChunkHandler::Save(), MAPOChunkHandler::Save(), MAP2ChunkHandler::Save(), M3LOChunkHandler::Save(), M3HIChunkHandler::Save(), MAP5ChunkHandler::Save(), MAPEChunkHandler::Save(), MAP7ChunkHandler::Save(), MAP8ChunkHandler::Save(), SlAutolength(), SlCopy(), SlObject(), SlRefList(), SlRefVector(), SlSetStructListLength(), and SlTableHeader().

## ◆ SlSetStructListLength()

void SlSetStructListLength | ( | size_t | length | ) |

Set the length of this list.

Parameters

  The | length of the list.

Definition at line 1817 of file saveload.cpp.

References _sl, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, and SlSetLength().

## ◆ SlSkipArray()

void SlSkipArray | ( |  | ) |

Skip an array or sparse array.

Definition at line 719 of file saveload.cpp.

References _sl, SaveLoadParams::reader, SlIterateArray(), and SlSkipBytes().

Referenced by WaterRegionChunkHandler::Load(), and ChunkHandler::LoadCheck().

## ◆ SlStdString()

static void SlStdString | ( | void * | ptr,
|  | VarType | conv
| ) |  |
| static

Save/Load a `std::string`.

Parameters

  ptr | the string being manipulated
  conv | must be SLE_FILE_STRING

Definition at line 1050 of file saveload.cpp.

References _sl, SaveLoadParams::action, AllowControlCode, AllowNewline, FixSCCEncoded(), FixSCCEncodedNegative(), GetVarMemType(), IsSavegameVersionBefore(), ReplaceTabCrNlWithSpace, ReplaceWithQuestionMark, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), settings, SLA_LOAD, SLA_LOAD_CHECK, SLA_NULL, SLA_PTRS, SLA_SAVE, SlCopyBytes(), SLE_VAR_NULL, SLF_ALLOW_CONTROL, SLF_ALLOW_NEWLINE, SLF_REPLACE_TABCRLF, SlReadString(), SlSkipBytes(), SLV_169, SLV_ENCODED_STRING_FORMAT, SLV_FIX_SCC_ENCODED_NEGATIVE, and StrMakeValidInPlace().

Referenced by SlTableHeader().

## ◆ SlTableHeader()

std::vector< SaveLoad > SlTableHeader | ( | const SaveLoadTable & | slt | ) |

Save or Load a table header.

Note
  a table-header can never contain more than 65535 fields.

Parameters

  slt | The SaveLoad table with objects to save/load.

Returns
  When loading, the ordered SaveLoad array to use; otherwise an empty list.

Definition at line 1899 of file saveload.cpp.

References _sl, SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoad::cmd, Debug, GetSavegameFileType(), SaveLoad::handler, SaveLoad::name, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SL_ARR, SL_MAX_VERSION, SL_MIN_VERSION, SL_STDSTR, SL_STRUCT, SL_STRUCTLIST, SL_VAR, SLA_LOAD, SLA_LOAD_CHECK, SLA_SAVE, SlCalcTableHeader(), SLE_FILE_END, SLE_FILE_HAS_LENGTH_FIELD, SLE_FILE_TYPE_MASK, SLE_VAR_NULL, SlErrorCorrupt(), SlIsObjectValidInSavegame(), SlSaveLoadConv(), SlSetLength(), SlStdString(), and SlTableHeader().

Referenced by LEAEChunkHandler::Load(), LEATChunkHandler::Load(), SRNDChunkHandler::Load(), WaterRegionChunkHandler::Load(), ChunkHandler::LoadCheck(), AIPLChunkHandler::Save(), ANITChunkHandler::Save(), ERNWChunkHandler::Save(), CMDLChunkHandler::Save(), CMPUChunkHandler::Save(), CAPAChunkHandler::Save(), CHTSChunkHandler::Save(), PLYRChunkHandler::Save(), DEPTChunkHandler::Save(), ECMYChunkHandler::Save(), CAPYChunkHandler::Save(), ENGNChunkHandler::Save(), EIDSChunkHandler::Save(), GSDTChunkHandler::Save(), GSTRChunkHandler::Save(), GLOGChunkHandler::Save(), GOALChunkHandler::Save(), GRPSChunkHandler::Save(), INDYChunkHandler::Save(), IBLDChunkHandler::Save(), ITBLChunkHandler::Save(), RAILChunkHandler::Save(), ROTTChunkHandler::Save(), LEAEChunkHandler::Save(), LEATChunkHandler::Save(), LGRPChunkHandler::Save(), LGRJChunkHandler::Save(), LGRSChunkHandler::Save(), MAPSChunkHandler::Save(), DATEChunkHandler::Save(), VIEWChunkHandler::Save(), NGRFChunkHandler::Save(), NewGRFMappingChunkHandler::Save(), OBJSChunkHandler::Save(), ORDLChunkHandler::Save(), BKORChunkHandler::Save(), SRNDChunkHandler::Save(), SIGNChunkHandler::Save(), STNNChunkHandler::Save(), ROADChunkHandler::Save(), PSACChunkHandler::Save(), STPEChunkHandler::Save(), STPAChunkHandler::Save(), SUBSChunkHandler::Save(), CITYChunkHandler::Save(), VEHSChunkHandler::Save(), SaveSettings(), SlCompatTableHeader(), and SlTableHeader().

## ◆ SlVector()

static void SlVector | ( | void * | vector,
|  | VarType | conv
| ) |  |
| static

Save/load a std::vector.

Parameters

  vector | The std::vector being manipulated
  conv | VarType type of variable that is used for calculating the size

Definition at line 1586 of file saveload.cpp.

References _sl, SaveLoadParams::action, GetVarMemType(), SL_STDSTR, SLA_SAVE, SLE_VAR_STR, and SlStorageHelper< Tstorage, Tvar, Tallocator >::SlSaveLoad().

## ◆ SlWriteArrayLength()

static void SlWriteArrayLength | ( | size_t | length | ) |
| inlinestatic

Definition at line 557 of file saveload.cpp.

## ◆ SlWriteByte()

void SlWriteByte | ( | uint8_t | b | ) |

Wrapper for writing a byte to the dumper.

Parameters

  b | The byte to write.

Definition at line 419 of file saveload.cpp.

References _sl, and SaveLoadParams::dumper.

Referenced by SlCopyBytes(), SlSaveChunk(), SlSaveLoadConv(), and SlWriteSimpleGamma().

## ◆ SlWriteSimpleGamma()

static void SlWriteSimpleGamma | ( | size_t | i | ) |
| static

Write the header descriptor of an object or an array.

If the element is bigger than 127, use 2 bytes for saving and use the highest byte of the first written one as a notice that the length consists of 2 bytes, etc.. like this: 0xxxxxxx 10xxxxxx xxxxxxxx 110xxxxx xxxxxxxx xxxxxxxx 1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx 11110— xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx We could extend the scheme ad infinum to support arbitrarily large chunks, but as sizeof(size_t) == 4 is still very common we don't support anything above 32 bits. That's why in the last case the 3 most significant bits are unused.

Parameters

  i | Index being written

Definition at line 512 of file saveload.cpp.

References SlWriteByte().

## ◆ SlWriteSparseIndex()

static void SlWriteSparseIndex | ( | uint | index | ) |
| inlinestatic

Definition at line 547 of file saveload.cpp.

## ◆ SlWriteUint16()

static void SlWriteUint16 | ( | uint16_t | v | ) |
| inlinestatic

Definition at line 443 of file saveload.cpp.

## ◆ SlWriteUint32()

static void SlWriteUint32 | ( | uint32_t | v | ) |
| inlinestatic

Definition at line 449 of file saveload.cpp.

## ◆ SlWriteUint64()

static void SlWriteUint64 | ( | uint64_t | x | ) |
| inlinestatic

Definition at line 455 of file saveload.cpp.

## ◆ WaitTillSaved()

void WaitTillSaved | ( |  | ) |

Definition at line 3028 of file saveload.cpp.

## ◆ WriteValue()

void WriteValue | ( | void * | ptr,
|  | VarType | conv,
|  | int64_t | val
| ) |  |

Write the value of a setting.

Parameters

  ptr | pointer to the variable
  conv | type of variable, can be a non-clean type, eg with other flags. It is parsed upon read
  val | the new value being given to the variable

Definition at line 836 of file saveload.cpp.

References CopyFromOldName(), GetVarMemType(), SLE_VAR_NAME, and SLE_VAR_NULL.

Referenced by LoadIntList(), CheatWindow::OnQueryTextFinished(), SlSaveLoadConv(), and IntSettingDesc::Write().

## Variable Documentation

## ◆ _async_save_finish

std::atomic<AsyncSaveFinishProc> _async_save_finish
| static

Callback to call when the savegame loading is finished.

Definition at line 376 of file saveload.cpp.

Referenced by ProcessAsyncSaveFinish(), and SetAsyncSaveFinish().

## ◆ _do_autosave

bool _do_autosave

are we doing an autosave at the moment?

Definition at line 84 of file saveload.cpp.

Referenced by StatusBarWindow::DrawWidget(), and SaveOrLoad().

## ◆ _file_to_saveload

FileToSaveLoad _file_to_saveload

File to save or load in the openttd loop.

Definition at line 78 of file saveload.cpp.

Referenced by GenerateLandscape(), InitializeWindowsAndCaches(), SIGNChunkHandler::Load(), LoadTownData(), NetworkRestartMap(), SaveLoadWindow::OnClick(), SaveLoadWindow::OnTimeout(), openttd_main(), and ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE().

## ◆ _lzma_init

const lzma_stream _lzma_init = LZMA_STREAM_INIT
| static

Have a copy of an initialised LZMA stream.

We need this as it's impossible to "re"-assign LZMA_STREAM_INIT to a variable in some compilers, i.e. LZMA_STREAM_INIT can't be used to set something. This var has to be used instead.

Definition at line 2685 of file saveload.cpp.

## ◆ _next_offs

size_t _next_offs
| static

Definition at line 671 of file saveload.cpp.

## ◆ _save_thread

std::thread _save_thread
| static

The thread we're using to compress and write a savegame.

Definition at line 377 of file saveload.cpp.

Referenced by DoSave(), and ProcessAsyncSaveFinish().

## ◆ _savegame_format

std::string _savegame_format

how to compress savegames

Definition at line 83 of file saveload.cpp.

Referenced by SaveFileToDisk().

## ◆ _savegame_type

SavegameType _savegame_type

type of savegame we are loading

Definition at line 77 of file saveload.cpp.

Referenced by Order::ConvertFromOldSavegame(), DoLoad(), LoadChunk(), LoadOldCustomString(), and Gamelog::Oldver().

## ◆ _saveload_formats

const SaveLoadFormat _saveload_formats[]
| static

Initial value:
= {
{"lzo", SAVEGAME_TAG_LZO, CreateLoadFilter<LZOLoadFilter>, CreateSaveFilter<LZOSaveFilter>, 0, 0, 0},
{"none", SAVEGAME_TAG_NONE, CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0},
{"zlib", SAVEGAME_TAG_ZLIB, CreateLoadFilter<ZlibLoadFilter>, CreateSaveFilter<ZlibSaveFilter>, 0, 6, 9},
{"lzma", SAVEGAME_TAG_LZMA, CreateLoadFilter<LZMALoadFilter>, CreateSaveFilter<LZMASaveFilter>, 0, 2, 9},
}

The different saveload formats known/understood by OpenTTD.

Definition at line 2814 of file saveload.cpp.

Referenced by DetermineSaveLoadFormat(), and GetSavegameFormat().

## ◆ _sl

SaveLoadParams _sl
| static

Parameters used for/at saveload.

Definition at line 218 of file saveload.cpp.

Referenced by ClearSaveLoadState(), DetermineSaveLoadFormat(), DoLoad(), DoSave(), GetSaveLoadErrorMessage(), GetSaveLoadErrorType(), IntToReference(), ChunkHandler::LoadCheck(), LoadWithFilter(), ReferenceToInt(), SaveFileDone(), SaveFileStart(), SaveFileToDisk(), SaveOrLoad(), SaveWithFilter(), SetSaveLoadError(), SlArray(), SlAutolength(), SlCompatTableHeader(), SlCopy(), SlCopyBytes(), SlCopyInternal(), SlDeque(), SlError(), SlFixPointers(), SlGetFieldLength(), SlIterateArray(), SlLoadCheckChunk(), SlLoadChunk(), SlNullPointers(), SlObject(), SlReadByte(), SlRefList(), SlRefVector(), SlSaveChunk(), SlStorageHelper< Tstorage, Tvar, Tallocator >::SlSaveLoad(), SlSaveLoadConv(), SlSaveLoadRef(), SlSetLength(), SlSetStructListLength(), SlSkipArray(), SlStdString(), SlTableHeader(), SlVector(), and SlWriteByte().

## ◆ _sl_minor_version

uint8_t _sl_minor_version

the minor savegame version, DO NOT USE!

Definition at line 82 of file saveload.cpp.

Referenced by DetermineSaveLoadFormat(), IsSavegameVersionBefore(), Gamelog::Oldver(), and SaveOrLoad().

## ◆ _sl_version

SaveLoadVersion _sl_version

the major savegame version identifier

Definition at line 81 of file saveload.cpp.

Referenced by DetermineSaveLoadFormat(), DoSave(), IsSavegameVersionBefore(), IsSavegameVersionBeforeOrAt(), Gamelog::Oldver(), LZOLoadFilter::Read(), SaveOrLoad(), SlCopyInternal(), SlIsObjectValidInSavegame(), and SlNullPointers().

## ◆ _ttdp_version

uint32_t _ttdp_version

version of TTDP savegame (if applicable)

Definition at line 80 of file saveload.cpp.

Referenced by Gamelog::Oldver().

## ◆ LZO_BUFFER_SIZE

const uint LZO_BUFFER_SIZE = 8192
| static

Buffer size for the LZO compressor.

Definition at line 2434 of file saveload.cpp.

Referenced by LZOLoadFilter::Read(), and LZOSaveFilter::Write().

## ◆ MEMORY_CHUNK_SIZE

const size_t MEMORY_CHUNK_SIZE = 128 * 1024
| static

Save in chunks of 128 KiB.

Definition at line 102 of file saveload.cpp.

Referenced by MemoryDumper::Flush(), and MemoryDumper::WriteByte().

## ◆ SAVEGAME_TAG_LZMA

const uint32_t SAVEGAME_TAG_LZMA = TO_BE32('OTTX')
| static

Definition at line 2811 of file saveload.cpp.

## ◆ SAVEGAME_TAG_LZO

const uint32_t SAVEGAME_TAG_LZO = TO_BE32('OTTD')
| static

Definition at line 2808 of file saveload.cpp.

## ◆ SAVEGAME_TAG_NONE

const uint32_t SAVEGAME_TAG_NONE = TO_BE32('OTTN')
| static

Definition at line 2809 of file saveload.cpp.

## ◆ SAVEGAME_TAG_ZLIB

const uint32_t SAVEGAME_TAG_ZLIB = TO_BE32('OTTZ')
| static

Definition at line 2810 of file saveload.cpp.