OpenTTD Source 20241224-master-gf74b0cf984
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 "../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 <atomic>
#include "table/strings.h"
#include "saveload_internal.h"
#include "saveload_filter.h"
#include "../safeguards.h"
#include <lzo/lzo1x.h>
#include <zlib.h>
#include <lzma.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 {
  SLA_LOAD , SLA_SAVE , SLA_PTRS , SLA_NULL ,
  SLA_LOAD_CHECK
}
 What are we currently doing? More...
 
enum  NeedLength { 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.
 
static void FixSCCEncoded (std::string &str)
 Scan the string for old values of SCC_ENCODED and fix it to it's new, value.
 
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< SaveLoadSlTableHeader (const SaveLoadTable &slt)
 Save or Load a table header.
 
std::vector< SaveLoadSlCompatTableHeader (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 ChunkHandlerSlFindChunkHandler (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 (const std::string &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 (const std::string &file)
 
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)
 
StringID GetSaveLoadErrorType ()
 Return the appropriate initial string for an error depending on whether we are saving or loading.
 
StringID 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 SaveLoadFormatDetermineSaveLoadFormat (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 (const std::string &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_BE32X('OTTD')
 
static const uint32_t SAVEGAME_TAG_NONE = TO_BE32X('OTTN')
 
static const uint32_t SAVEGAME_TAG_ZLIB = TO_BE32X('OTTZ')
 
static const uint32_t SAVEGAME_TAG_LZMA = TO_BE32X('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 357 of file saveload.cpp.

Enumeration Type Documentation

◆ NeedLength

enum NeedLength
Enumerator
NL_NONE 

not working in NeedLength mode

NL_WANTLENGTH 

writing length and data

NL_CALCLENGTH 

need to calculate the length

Definition at line 77 of file saveload.cpp.

◆ SaveLoadAction

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 69 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 566 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, _road_stop_stop_frame, _settings_client, _settings_game, _settings_newgame, _tunnel_visibility_frame, ShipVehicleInfo::acceleration, IndustrySpec::accepts_cargo, AddInflation(), CargoPacket::AfterLoad(), AfterLoadCompanyStats(), AfterLoadLabelMaps(), AfterLoadLinkGraphs(), AfterLoadRoadStops(), AfterLoadStoryBook(), AfterLoadVehiclesPhase1(), AfterLoadVehiclesPhase2(), AIR_AIRCRAFT, AircraftNextAirportPos_and_Order(), EconomySettings::allow_town_level_crossings, EconomySettings::allow_town_roads, Animated, AssignBit(), AT_OILRIG, AXIS_X, AXIS_Y, AxisToDirection(), IndustrySpec::behaviour, Object::build_date, Station::bus_stops, CalcClosestTownFromTile(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargo_payment_pool >::CanAllocateItem(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_object_pool >::CanAllocateItem(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_roadstop_pool >::CanAllocateItem(), CARGO_NO_REFIT, CeilDiv(), ChangeTileOwner(), CheckGroundVehiclesAtCorrectZ(), Clamp(), CLEAR_FIELDS, ConstructionSettings::clear_frame_burst, CLEAR_GRASS, CLEAR_SNOW, ClearBridgeMiddle(), ClosestTownFromTile(), ClrBit(), ClientSettings::company, DifficultySettings::competitors_interval, ConnectMultiheadedTrains(), GameSettings::construction, ConvertFromOldCompanyManagerFace(), ConvertOldMultiheadToNew(), CopyFromOldName(), CopyTempEngineData(), TimerGameTick::counter, Vehicle::current_order, 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, DIAGDIR_END, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DiagDirToAxis(), DiagDirToDiagTrackBits(), DiagDirToDiagTrackdir(), DiagDirToDir(), GameSettings::difficulty, Vehicle::direction, DirToDiagDir(), VehicleSettings::disable_elrails, DistanceManhattan(), LinkGraphSettings::distribution_armoured, LinkGraphSettings::distribution_default, LinkGraphSettings::distribution_mail, LinkGraphSettings::distribution_pax, DoStartupNewCompany(), DT_MANUAL, VehicleSettings::dynamic_engines, GameSettings::economy, EF_ROAD_TRAM, GameCreationSettings::ending_year, FACIL_AIRPORT, FACIL_DOCK, FACIL_TRAIN, EconomySettings::feeder_payment_share, FindFirstCargoWithTownAcceptanceEffect(), FixOwnerOfRailTrack(), FixupTrainLengths(), FixVehicleInclination(), FLYING, PathfinderSettings::forbid_90_deg, ConstructionSettings::freeform_edges, SpecializedStation< Station, false >::From(), SpecializedVehicle< T, Type >::From(), GameSettings::game_creation, GB(), GCF_COMPATIBLE, GCS_NOT_FOUND, GenerateSavegameId(), GoodsEntry::GES_RATING, SpecializedStation< Station, false >::Get(), CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_object_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), GetAircraftFlightLevelBounds(), BaseStation::GetByTile(), Industry::GetByTile(), GetClearDensity(), GetCompanyRailTypes(), GetCompanyRoadTypes(), GetFirstPlayableCompanyID(), OverrideManagerBase::GetGRFID(), GetHouseType(), SpecializedStation< Station, false >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), GetInclinedSlopeDirection(), GetIndustryGfx(), GetIndustrySpec(), GetIndustryType(), GetLockPart(), GetNorthernBridgeEnd(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_object_pool >::GetNumItems(), GetOtherShipDepotTile(), GetOtherTunnelBridgeEnd(), GetRailType(), GetRawClearGround(), GetRoadOwner(), GetRoadTileType(), GetSlopePixelZ(), GetStationGfx(), GetStationType(), GetTargetAirportIfValid(), GetTileMaxPixelZ(), GetTileMaxZ(), GetTileOwner(), GetTileSlope(), GetTileTrackStatus(), GetTileType(), GetTileZ(), GetTreeGround(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), GetWaterClass(), GetWaterTileType(), GF_REPLACE_PROTECTION, GF_REPLACE_WAGON_REMOVAL, 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(), Object::IncTypeCount(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Industry, DifficultySettings::industry_density, INDUSTRYBEH_BUILT_ONWATER, INDUSTRYBEH_PLANT_ON_BUILT, Economy::inflation_payment, Economy::inflation_prices, EconomySettings::infrastructure_maintenance, InitializeRailGUI(), InitializeWindowsAndCaches(), INVALID_COMPANY, INVALID_DIR, INVALID_OWNER, INVALID_ROADTYPE, INVALID_STRING_ID, 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(), IsValidCargoID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::IsValidID(), IsWater(), Map::Iterate(), SpecializedStation< Waypoint, true >::Iterate(), SpecializedStation< Station, false >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargo_payment_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_depot_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_subsidy_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_backup_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_object_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_sign_pool >::Iterate(), SpecializedVehicle< T, Type >::Iterate(), GameCreationSettings::landscape, EconomySettings::larger_towns, GameSettings::linkgraph, LoadStringWidthTable(), GameSettings::locale, Object::location, LOCK_PART_MIDDLE, Tile::m2(), MakeCanal(), MakeClear(), MakeDefaultName(), MakeSea(), MakeShore(), ConstructionSettings::map_height_limit, ConstructionSettings::max_bridge_length, MAX_COMPANIES, MAX_INFLATION, DifficultySettings::max_loan, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::MAX_SIZE, VehicleSettings::max_train_length, ConstructionSettings::max_tunnel_length, MAX_UVALUE, Map::MaxX(), Map::MaxY(), MayAnimateTile(), MayHaveBridgeAbove(), MIN_SNOWLINE_HEIGHT, 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, GRFConfig::next, SpecializedVehicle< T, Type >::Next(), None, DifficultySettings::number_towns, OBJECT_HQ, OBJECT_STATUE, Economy::old_max_loan_unround, Economy::old_max_loan_unround_fract, Gamelog::Oldver(), OLFB_NO_LOAD, ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, TimerGameConst< struct Calendar >::ORIGINAL_BASE_YEAR, TimerGameConst< struct Economy >::ORIGINAL_BASE_YEAR, OSL_PLATFORM_FAR_END, OUFB_TRANSFER, OUFB_UNLOAD, BaseStation::owner, OWNER_NONE, OWNER_TOWN, OWNER_WATER, GameSettings::pf, VehicleSettings::plane_crashes, VehicleSettings::plane_speed, PM_PAUSED_ERROR, PM_PAUSED_NORMAL, PM_UNPAUSED, Gamelog::PrintDebug(), RailVehicleInfo::railtype, RAILTYPE_ELECTRIC, RAILTYPE_RAIL, RATING_INITIAL, LinkGraphSettings::recalc_interval, LinkGraphSettings::recalc_time, Station::RecomputeCatchmentForAll(), BaseStation::rect, IndustryBuildData::Reset(), ResetCompanyLivery(), ResetOldNames(), ResetSignalHandlers(), Backup< T >::Restore(), PathfinderSettings::reverse_at_signals, ReverseDiagDir(), ReverseDir(), VehicleSettings::road_side, ROAD_TILE_CROSSING, ROAD_TILE_DEPOT, ROAD_TILE_NORMAL, ROAD_X, ROAD_Y, RoadVehicle::roadtype, ROADTYPE_ROAD, ROADTYPE_TRAM, VehicleSettings::roadveh_acceleration_model, VehicleSettings::roadveh_slope_steepness, 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(), TimerGameConst< struct Calendar >::SECONDS_PER_DAY, StationSettings::serve_neutral_industries, SetAircraftPosition(), SetAnimatedTileState(), SetAnimationFrame(), SetBit(), SetBridgeMiddle(), SetClearGroundDensity(), SetCrossingReservation(), TimerGameCalendar::SetDate(), TimerGameEconomy::SetDate(), SetDepotReservation(), SetDockingTile(), SetFence(), SetHouseCompleted(), SetHouseType(), SetLiftPosition(), SetNonFloodingWaterTile(), SetRailStationReservation(), SetRailStationTileFlags(), 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_COMPANY_INAUGURATED_PERIOD, 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_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_REPAIR_OBJECT_DOCKING_TILES, SLV_ROAD_TYPES, SLV_SAVEGAME_ID, SLV_SCRIPT_RANDOMIZER, 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, GameCreationSettings::starting_year, StartScripts(), StartupEngines(), RoadVehicle::state, GameSettings::station, EconomySettings::station_noise_level, BaseTimer< TTimerType >::storage, Swap(), TAE_FOOD, TAE_GOODS, TAE_MAIL, TAE_PASSENGERS, TAE_WATER, TCGM_ORIGINAL, ConstructionSettings::terraform_frame_burst, 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, BaseStation::town, Town, Object::town, CargoSpec::town_acceptance_effect, EconomySettings::town_cargogen_mode, TOWN_CUSTOM_GROWTH, 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(), VehicleSettings::train_acceleration_model, VehicleSettings::train_slope_steepness, BaseStation::train_station, 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(), UpdateHousesAndTowns(), UpdateLevelCrossing(), UpdateNearestTownForRoadTiles(), UpdateOldAircraft(), UpdateStationAcceptance(), UpdateTownMaxPass(), FreeUnitIDGenerator::UseID(), VEH_INVALID, VEH_ROAD, VEH_SHIP, VEH_TRAIN, GameSettings::vehicle, Vehicle::vehstatus, VF_LOADING_FINISHED, VF_PATHFINDER_LOST, VS_CRASHED, VS_HIDDEN, VS_STOPPED, OrthogonalTileArea::w, PathfinderSettings::wait_for_pbs_path, PathfinderSettings::wait_oneway_signal, PathfinderSettings::wait_twoway_signal, WATER_CLASS_CANAL, WATER_CLASS_INVALID, WATER_CLASS_RIVER, WATER_CLASS_SEA, WATER_TILE_CLEAR, WATER_TILE_COAST, WATER_TILE_DEPOT, WATER_TILE_LOCK, 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 202 of file saveload.cpp.

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

◆ ClearSaveLoadState()

static void ClearSaveLoadState ( )
inlinestatic

◆ 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
tagThe tag from the header describing the savegame compression/format.
raw_versionThe raw version from the savegame header.
Returns
The SaveLoadFormat to use for attempting to open the savegame.

Definition at line 2967 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
counterA reference to the counter variable to be used for rotating the file name.
netsaveIndicates if this is a regular autosave or a netsave.

Definition at line 3219 of file saveload.cpp.

References _settings_client, AUTOSAVE_DIR, Debug, DFT_GAME_FILE, FiosNumberedSaveName::Extension(), FiosNumberedSaveName::Filename(), GenerateDefaultSaveName(), ClientSettings::gui, INVALID_STRING_ID, 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 3237 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

◆ 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
writerThe filter to write the savegame to.
threadedWhether to try to perform the saving asynchronously.
Returns
Return the result of the action. SL_OK or SL_ERROR

Definition at line 2916 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()

static void FixSCCEncoded ( std::string &  str)
static

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
strthe string to fix.

Definition at line 915 of file saveload.cpp.

References Utf8Decode(), Utf8Encode(), and Utf8EncodedCharLen().

Referenced by SlStdString().

◆ GenerateDefaultSaveName()

◆ GetSavegameFileType()

static uint8_t GetSavegameFileType ( const SaveLoad sld)
static

◆ GetSavegameFormat()

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

Return the savegameformat of the game.

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

Parameters
full_nameName 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 2741 of file saveload.cpp.

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

Referenced by SaveFileToDisk().

◆ GetSaveLoadErrorMessage()

StringID GetSaveLoadErrorMessage ( )

Return the description of the error.

Definition at line 2842 of file saveload.cpp.

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

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

◆ GetSaveLoadErrorType()

StringID GetSaveLoadErrorType ( )

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

Definition at line 2836 of file saveload.cpp.

References _sl, SaveLoadParams::action, 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
indexThe index that is being converted to a pointer
rtSLRefType type of the object the pointer is sought of
Returns
Return the index converted to a pointer of any type

Definition at line 1139 of file saveload.cpp.

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

Referenced by SlSaveLoadRef().

◆ LoadOldSaveGame()

bool LoadOldSaveGame ( const std::string &  file)
extern

Definition at line 259 of file oldloader.cpp.

◆ LoadWithFilter()

SaveOrLoadResult LoadWithFilter ( std::shared_ptr< LoadFilter reader)

Load the game using a (reader) filter.

Parameters
readerThe filter to read the savegame from.
Returns
Return the result of the action. SL_OK or SL_REINIT ("unload" the game)

Definition at line 3108 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 376 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
ptrpointer to the variable
convtype 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 794 of file saveload.cpp.

References GetVarMemType(), and SLE_VAR_NULL.

Referenced by CheatWindow::DrawWidget(), CheatWindow::OnClick(), 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
objThe object that we want to get the index of
rtSLRefType 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 1106 of file saveload.cpp.

References _sl, SaveLoadParams::action, REF_CARGO_PACKET, REF_ENGINE_RENEWS, REF_LINK_GRAPH, REF_LINK_GRAPH_JOB, REF_ORDER, 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 2789 of file saveload.cpp.

Referenced by DoLoad(), and SaveOrLoad().

◆ SaveFileDone()

static void SaveFileDone ( )
static

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

Definition at line 2817 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 2849 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 2808 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 2859 of file saveload.cpp.

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

Referenced by DoSave().

◆ SaveOrLoad()

SaveOrLoadResult SaveOrLoad ( const std::string &  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
filenameThe name of the savegame being created/loaded
fopSave or load mode. Load can also be a TTD(Patch) game.
sbThe sub directory to save the savegame in
threadedTrue 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 3128 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(), GetSaveLoadErrorMessage(), GetSaveLoadErrorType(), GetString(), GLAT_LOAD, ClientSettings::gui, INVALID_STRING_ID, 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(), DEF_CONSOLE_CMD(), 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
writerThe filter to write the savegame to.
threadedWhether to try to perform the saving asynchronously.
Returns
Return the result of the action. SL_OK or SL_ERROR

Definition at line 2948 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
procThe callback to call when saving is done.

Definition at line 365 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 2830 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
arrayThe array being manipulated
lengthThe length of the array in elements
convVarType type of the atomic array (int, uint8_t, uint64_t, etc.)

Definition at line 1060 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
procThe callback procedure that is called
argThe variable that will be used for the callback procedure

Definition at line 1988 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
lengthThe length of the array counted in elements
convVarType type of the variable that is used in calculating the size

Definition at line 1049 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
convVarType type of variable that is used for calculating the size
Returns
Return the size of this type in bytes

Definition at line 618 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
convVarType type of variable that is used for calculating the size
Returns
Return the size of this type in bytes

Definition at line 588 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
dequeThe std::deque to find the size of
convVarType type of variable that is used for calculating the size

Definition at line 1388 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
objectto be measured.
sltThe SaveLoad table with objects to save/load.
Returns
size of given object.

Definition at line 1539 of file saveload.cpp.

Referenced by SlObject().

◆ SlCalcObjMemberLength()

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

Definition at line 1550 of file saveload.cpp.

◆ SlCalcRefLen()

static size_t SlCalcRefLen ( )
inlinestatic

Return the size in bytes of a reference (pointer)

Definition at line 642 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
listThe std::list to find the size of.
convVarType type of variable that is used for calculating the size.

Definition at line 1334 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
vectorThe std::vector to find the size of.
convVarType type of variable that is used for calculating the size.

Definition at line 1361 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
ptrPointer to the std::string.
Returns
The gross length of the string.

Definition at line 899 of file saveload.cpp.

Referenced by SlCalcTableHeader().

◆ SlCalcTableHeader()

static size_t SlCalcTableHeader ( const SaveLoadTable slt)
static

Calculate the size of the table header.

Parameters
sltThe SaveLoad table with objects to save/load.
Returns
size of given object.

Definition at line 1510 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
vectorThe std::vector to find the size of
convVarType type of variable that is used for calculating the size

Definition at line 1446 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
sltThe SaveLoad table with objects to save/load.
slctThe SaveLoadCompat table the original order of the fields.
Returns
When loading, the ordered SaveLoad array to use; otherwise an empty list.

Definition at line 1924 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()

◆ 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
ptrThe source or destination of the object being manipulated
lengthnumber of bytes this fast CopyBytes lasts

Definition at line 765 of file saveload.cpp.

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

Referenced by SlCopyInternal(), 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
objectThe object being manipulated.
lengthThe length of the object in elements
convVarType type of the items.

Definition at line 981 of file saveload.cpp.

References _sl, _sl_version, SaveLoadParams::action, BSWAP32(), 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
dequeThe std::deque being manipulated
convVarType type of variable that is used for calculating the size

Definition at line 1415 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 
)

◆ SlErrorCorrupt()

◆ 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
idthe chunk in question
Returns
returns the appropriate chunkhandler

Definition at line 2191 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 2228 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 544 of file saveload.cpp.

◆ SlGetFieldLength()

size_t SlGetFieldLength ( )

Get the length of the current object.

Definition at line 782 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 519 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
limitThe maximum size the list can be.
Returns
The length of the list.

Definition at line 1720 of file saveload.cpp.

References SlErrorCorrupt().

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

◆ SlGlobList()

void SlGlobList ( const SaveLoadTable slt)

◆ SlIsObjectValidInSavegame()

static bool SlIsObjectValidInSavegame ( const SaveLoad sld)
inlinestatic

Are we going to save this object or not?

Definition at line 1500 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 659 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
chThe chunkhandler that will be used for the operation

Definition at line 2088 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 2213 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
chThe chunkhandler that will be used for the operation

Definition at line 2035 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 2198 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 296 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
objectThe object that is being saved or loaded.
sltThe SaveLoad table with objects to save/load.

Definition at line 1733 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(), ORDRChunkHandler::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(), ORDRChunkHandler::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 1597 of file saveload.cpp.

◆ SlReadArrayLength()

static uint SlReadArrayLength ( )
inlinestatic

Definition at line 534 of file saveload.cpp.

◆ SlReadByte()

uint8_t SlReadByte ( )

Wrapper for reading a byte from the buffer.

Returns
The read byte.

Definition at line 392 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 452 of file saveload.cpp.

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

◆ SlReadSparseIndex()

static uint SlReadSparseIndex ( )
inlinestatic

Definition at line 524 of file saveload.cpp.

◆ SlReadUint16()

static int SlReadUint16 ( )
inlinestatic

Definition at line 406 of file saveload.cpp.

◆ SlReadUint32()

static uint32_t SlReadUint32 ( )
inlinestatic

Definition at line 412 of file saveload.cpp.

◆ SlReadUint64()

static uint64_t SlReadUint64 ( )
inlinestatic

Definition at line 418 of file saveload.cpp.

◆ SlRefList()

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

Save/Load a list.

Parameters
listThe list being manipulated.
convVarType type of variable that is used for calculating the size.

Definition at line 1344 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
vectorThe vector being manipulated.
convVarType type of variable that is used for calculating the size.

Definition at line 1371 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
chThe chunkhandler that will be used for the operation

Definition at line 2139 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 2175 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
ptrThe object being filled/read
convVarType type of the current element of the struct

Definition at line 844 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
ptrThe object being filled/read.
convVarType type of the current element of the struct.

Definition at line 1215 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 647 of file saveload.cpp.

◆ SlSetLength()

◆ SlSetStructListLength()

void SlSetStructListLength ( size_t  length)

Set the length of this list.

Parameters
Thelength of the list.

Definition at line 1704 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 701 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

◆ 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
sltThe SaveLoad table with objects to save/load.
Returns
When loading, the ordered SaveLoad array to use; otherwise an empty list.

Definition at line 1786 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(), ORDRChunkHandler::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
vectorThe std::vector being manipulated
convVarType type of variable that is used for calculating the size

Definition at line 1473 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 539 of file saveload.cpp.

◆ SlWriteByte()

void SlWriteByte ( uint8_t  b)

Wrapper for writing a byte to the dumper.

Parameters
bThe byte to write.

Definition at line 401 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
iIndex being written

Definition at line 494 of file saveload.cpp.

References SlWriteByte().

◆ SlWriteSparseIndex()

static void SlWriteSparseIndex ( uint  index)
inlinestatic

Definition at line 529 of file saveload.cpp.

◆ SlWriteUint16()

static void SlWriteUint16 ( uint16_t  v)
inlinestatic

Definition at line 425 of file saveload.cpp.

◆ SlWriteUint32()

static void SlWriteUint32 ( uint32_t  v)
inlinestatic

Definition at line 431 of file saveload.cpp.

◆ SlWriteUint64()

static void SlWriteUint64 ( uint64_t  x)
inlinestatic

Definition at line 437 of file saveload.cpp.

◆ WaitTillSaved()

void WaitTillSaved ( )

Definition at line 2898 of file saveload.cpp.

◆ WriteValue()

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

Write the value of a setting.

Parameters
ptrpointer to the variable
convtype of variable, can be a non-clean type, eg with other flags. It is parsed upon read
valthe new value being given to the variable

Definition at line 818 of file saveload.cpp.

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

Referenced by LoadIntList(), CheatWindow::OnClick(), 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 358 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 66 of file saveload.cpp.

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

◆ _file_to_saveload

◆ _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 2577 of file saveload.cpp.

◆ _next_offs

size_t _next_offs
static

Definition at line 653 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 359 of file saveload.cpp.

Referenced by DoSave(), and ProcessAsyncSaveFinish().

◆ _savegame_format

std::string _savegame_format

how to compress savegames

Definition at line 65 of file saveload.cpp.

Referenced by SaveFileToDisk().

◆ _savegame_type

SavegameType _savegame_type

type of savegame we are loading

Definition at line 59 of file saveload.cpp.

Referenced by Order::ConvertFromOldSavegame(), CopyFromOldName(), DoLoad(), LoadChunk(), 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 2706 of file saveload.cpp.

Referenced by DetermineSaveLoadFormat(), and GetSavegameFormat().

◆ _sl

◆ _sl_minor_version

uint8_t _sl_minor_version

the minor savegame version, DO NOT USE!

Definition at line 64 of file saveload.cpp.

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

◆ _sl_version

◆ _ttdp_version

uint32_t _ttdp_version

version of TTDP savegame (if applicable)

Definition at line 62 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 2322 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 84 of file saveload.cpp.

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

◆ SAVEGAME_TAG_LZMA

const uint32_t SAVEGAME_TAG_LZMA = TO_BE32X('OTTX')
static

Definition at line 2703 of file saveload.cpp.

◆ SAVEGAME_TAG_LZO

const uint32_t SAVEGAME_TAG_LZO = TO_BE32X('OTTD')
static

Definition at line 2700 of file saveload.cpp.

◆ SAVEGAME_TAG_NONE

const uint32_t SAVEGAME_TAG_NONE = TO_BE32X('OTTN')
static

Definition at line 2701 of file saveload.cpp.

◆ SAVEGAME_TAG_ZLIB

const uint32_t SAVEGAME_TAG_ZLIB = TO_BE32X('OTTZ')
static

Definition at line 2702 of file saveload.cpp.