# saveload.cpp File Reference

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

`#include "stdafx.h"`
`#include "openttd.h"`
`#include "debug.h"`
`#include "station.h"`
`#include "thread.h"`
`#include "town.h"`
`#include "saveload.h"`
`#include "network/network.h"`
`#include "variables.h"`
`#include "window_func.h"`
`#include "strings_func.h"`
`#include "gfx_func.h"`
`#include "core/alloc_func.hpp"`
`#include "functions.h"`
`#include "core/endian_func.hpp"`
`#include "vehicle_base.h"`
`#include "autoreplace_base.h"`
`#include <list>`
`#include "table/strings.h"`
`#include "minilzo.h"`
`#include "table/sprites.h"`
`#include "gui.h"`

Go to the source code of this file.

## Data Structures
struct | ThreadedSave
struct | SaveLoadFormat
| The format for a reader/writer type of a savegame. More...
## Defines
#define | LZO_SIZE 8192
## Typedefs
typedef void | WriterProc (uint len)
typedef uint | ReaderProc ()
## Enumerations
enum | NeedLengthValues { NL_NONE = 0, NL_WANTLENGTH = 1, NL_CALCLENGTH = 2 }
## Functions
static void NORETURN | SlError (StringID string, const char *extra_msg=NULL)
| Error handler, calls longjmp to simulate an exception.
static void | SlReadFill ()
| Fill the input buffer by reading from the file with the given reader.
static uint32 | SlGetOffs ()
static byte | SlCalcConvMemLen (VarType conv)
| Return the size in bytes of a certain type of normal/atomic variable as it appears in memory.
static byte | 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).
static void | SlWriteFill ()
| Flush the output buffer by writing to disk with the given reader.
static byte | SlReadByteInternal ()
| Read in a single byte from file.
byte | SlReadByte ()
| Wrapper for SlReadByteInternal.
static void | SlWriteByteInternal (byte b)
| Write away a single byte from memory.
void | SlWriteByte (byte b)
| Wrapper for SlWriteByteInternal.
static int | SlReadUint16 ()
static uint32 | SlReadUint32 ()
static uint64 | SlReadUint64 ()
static void | SlWriteUint16 (uint16 v)
static void | SlWriteUint32 (uint32 v)
static void | SlWriteUint64 (uint64 x)
static uint | SlReadSimpleGamma ()
| Read in the header descriptor of an object or an array.
static void | SlWriteSimpleGamma (uint i)
| Write the header descriptor of an object or an array.
static uint | SlGetGammaLength (uint 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 (uint length)
static uint | SlGetArrayLength (uint length)
void | SlSetArrayIndex (uint index)
int | SlIterateArray ()
| Iterate through the elements of an array and read the whole thing.
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.
static void | SlSkipBytes (size_t length)
| Read in bytes from the file/data structure but don't do anything with them, discarding them in effect.
uint | SlGetFieldLength ()
int64 | ReadValue (const void *ptr, VarType conv)
| Return a signed-long version of the value of a setting.
void | WriteValue (void *ptr, VarType conv, int64 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 | SlCalcNetStringLen (const char *ptr, size_t length)
| Calculate the net length of a string.
static size_t | SlCalcStringLen (const void *ptr, size_t length, VarType conv)
| Calculate the gross length of the string that it will occupy in the savegame.
static void | SlString (void *ptr, size_t length, VarType conv)
| Save/Load a string.
static size_t | SlCalcArrayLen (uint length, VarType conv)
| Return the size in bytes of a certain type of atomic array.
void | SlArray (void *array, uint length, VarType conv)
| Save/Load an array.
static uint | 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 NULL item has value 0, and all indeces have +1, so vehicle 0 is saved as index 1.
static void * | IntToReference (uint index, SLRefType rt)
| Pointers cannot be loaded from a savegame, so this function gets the index from the savegame and returns the appropiate pointer from the already loaded base.
static size_t | SlCalcListLen (const void *list)
| Return the size in bytes of a list.
void | SlList (void *list, SLRefType conv)
| Save/Load a list.
static bool | SlIsObjectValidInSavegame (const SaveLoad *sld)
| Are we going to save this object or not?
static bool | SlSkipVariableOnLoad (const SaveLoad *sld)
| Are we going to load this variable when loading a savegame or not?
static size_t | SlCalcObjLength (const void *object, const SaveLoad *sld)
| Calculate the size of an object.
size_t | SlCalcObjMemberLength (const void *object, const SaveLoad *sld)
bool | SlObjectMember (void *ptr, const SaveLoad *sld)
void | SlObject (void *object, const SaveLoad *sld)
| Main SaveLoad function.
void | SlGlobList (const SaveLoadGlobVarList *sldg)
| Save or Load (a list of) global variables.
void | SlAutolength (AutolengthProc *proc, void *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 | SlStubSaveProc2 (void *arg)
static void | SlStubSaveProc ()
static void | SlSaveChunk (const ChunkHandler *ch)
| Save a chunk of data (eg.
static void | SlSaveChunks ()
| Save all chunks.
static const ChunkHandler * | SlFindChunkHandler (uint32 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 uint | ReadLZO ()
static void | WriteLZO (uint size)
static bool | InitLZO ()
static void | UninitLZO ()
static uint | ReadNoComp ()
static void | WriteNoComp (uint size)
static bool | InitNoComp ()
static void | UninitNoComp ()
static bool | InitMem ()
static void | UnInitMem ()
static void | WriteMem (uint size)
static const SaveLoadFormat * | GetSavegameFormat (const char *s)
| Return the savegameformat of the game.
void | InitializeGame (int mode, uint size_x, uint size_y)
bool | AfterLoadGame ()
void | BeforeSaveGame ()
bool | LoadOldSaveGame (const char *file)
static SaveOrLoadResult | AbortSaveLoad ()
| Small helper function to close the to be loaded savegame an signal error.
void | SaveFileStart ()
| Update the gui accordingly when starting saving and set locks on saveload.
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).
const char * | GetSaveLoadErrorString ()
| Get the string representation of the error message.
void | SaveFileError ()
| Show a gui message when saving has failed.
static SaveOrLoadResult | SaveFileToDisk (bool threaded)
| We have written the whole game into memory, _Savegame_pool, now find and appropiate compressor and start writing to file.
static void * | SaveFileToDiskThread (void *arg)
void | WaitTillSaved ()
SaveOrLoadResult | SaveOrLoad (const char *filename, int mode, Subdirectory sb)
| Main Save or Load function where the high-level saveload functions are handled.
void | DoExitSave ()
| Do a save when exiting the game (patch option) _patches.autosave_on_exit.
## Variables
const uint16 | SAVEGAME_VERSION = 92
uint16 | _sl_version
| the major savegame version identifier
byte | _sl_minor_version
| the minor savegame version, DO NOT USE!
struct {
bool save
| are we doing a save or a load atm. True when saving
byte need_length
| ???
byte block_mode
| ???
bool error
| did an error occur or not
int obj_len
| the length of the current object we are busy with
int array_index
int last_array_index
| in the case of an array, the current and last positions
uint32 offs_base
| the offset in number of bytes since we started writing data (eg uncompressed savegame size)
WriterProc * write_bytes
| savegame writer function
ReaderProc * read_bytes
| savegame loader function
const ChunkHandler *const * chs
| the chunk of data that is being processed atm (vehicles, signs, etc.)
byte * bufp
byte * bufe
| bufp(ointer) gives the current position in the buffer bufe(nd) gives the end of the buffer
byte * buf
| pointer to temporary memory to read/write, initialized by SaveLoadFormat->initread/write
byte * buf_ori
| pointer to the original memory location of buf, used to free it afterwards
uint bufsize
| the size of the temporary memory *buf
FILE * fh
| the file from which is read or written to
void(* excpt_uninit )()
| the function to execute on any encountered error
StringID error_str
| the translateable error message to show
char * extra_msg
| the error message
} | _sl
| The saveload struct, containing reader-writer functions, bufffer, version, etc.
static uint32 | _next_offs
static ChunkSaveLoadProc * | _tmp_proc_1
static ThreadedSave | _ts
const ChunkHandler | _misc_chunk_handlers []
const ChunkHandler | _setting_chunk_handlers []
const ChunkHandler | _player_chunk_handlers []
const ChunkHandler | _engine_chunk_handlers []
const ChunkHandler | _veh_chunk_handlers []
const ChunkHandler | _waypoint_chunk_handlers []
const ChunkHandler | _depot_chunk_handlers []
const ChunkHandler | _order_chunk_handlers []
const ChunkHandler | _town_chunk_handlers []
const ChunkHandler | _sign_chunk_handlers []
const ChunkHandler | _station_chunk_handlers []
const ChunkHandler | _industry_chunk_handlers []
const ChunkHandler | _economy_chunk_handlers []
const ChunkHandler | _animated_tile_chunk_handlers []
const ChunkHandler | _newgrf_chunk_handlers []
const ChunkHandler | _group_chunk_handlers []
const ChunkHandler | _cargopacket_chunk_handlers []
static const ChunkHandler *const | _chunk_handlers []
static const SaveLoadFormat | _saveload_formats []
static OTTDThread * | save_thread

## 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.

## Function Documentation

static const SaveLoadFormat* GetSavegameFormat | ( | const char * | s | ) | `[static]`

Return the savegameformat of the game.

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

Parameters:

  | s | Name of the savegame format. If NULL it picks the first available one

Returns:
  Pointer to SaveLoadFormat struct giving all characteristics of this type of savegame

Definition at line 1427 of file saveload.cpp.

References SaveLoadFormat::init_write, and SaveLoadFormat::name.

Referenced by SaveFileToDisk(), and SaveOrLoad().

static void * IntToReference | ( | uint | index,
|  | SLRefType | rt |
| ) |  |  | `[static]`

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

Remember that an index of 0 is a NULL pointer so all indeces 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 1336 of file saveload.cpp.

References CheckSavegameVersionOldStyle(), and error.

Referenced by SlList().

int64 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 401 of file saveload.cpp.

References SLE_VAR_NULL.

Referenced by CmdChangePatchSetting(), ini_save_settings(), PatchesSelectionWndProc(), SetPatchValue(), and SlSaveLoadConv().

static uint 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 NULL item has value 0, and all indeces 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 1307 of file saveload.cpp.

Referenced by SlList().

void SaveFileStart | ( |  | ) |

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

Also turn off fast-forward cause with that saving takes Aaaaages

Definition at line 1464 of file saveload.cpp.

References SendWindowMessage().

Referenced by SaveOrLoad().

SaveOrLoadResult SaveOrLoad | ( | const char * | filename,
|  | int | mode,
|  | Subdirectory | sb |
| ) |  |  |

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
  | mode | Save or load. Load can also be a TTD(Patch) game. Use SL_LOAD, SL_OLD_LOAD or SL_SAVE

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

Definition at line 1591 of file saveload.cpp.

References _sl, _sl_minor_version, _sl_version, AbortSaveLoad(), BASE_DIR, FioFOpenFile(), GetSavegameFormat(), GetSaveLoadErrorString(), SaveLoadFormat::init_read, SaveLoadFormat::init_write, SaveLoadFormat::name, SaveLoadFormat::reader, SAVE_DIR, SaveFileDone(), SaveFileStart(), SaveFileToDisk(), SL_ERROR, SL_OK, SL_REINIT, SlError(), SlLoadChunks(), SlSaveChunks(), SlWriteFill(), SaveLoadFormat::tag, SaveLoadFormat::uninit_read, SaveLoadFormat::uninit_write, and SaveLoadFormat::writer.

Referenced by DoAutosave(), DoExitSave(), SafeSaveOrLoad(), and StartScenario().

void SlArray | ( | void * | array,
|  | uint | length,
|  | VarType | conv |
| ) |  |  |

Save/Load an array.

Parameters:

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

Definition at line 611 of file saveload.cpp.

References _sl, _sl_version, BSWAP32(), SlCalcArrayLen(), SlCalcConvFileLen(), SlCalcConvMemLen(), SlCopyBytes(), SlSaveLoadConv(), and SlSetLength().

Referenced by Load_ANIT(), Save_ANIT(), SaveLoad_CAPR(), and SaveLoad_PRIC().

void SlAutolength | ( | AutolengthProc * | proc,
|  | void * | 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 862 of file saveload.cpp.

References _sl, SlError(), and SlSetLength().

static size_t SlCalcArrayLen | ( | uint | length,
|  | VarType | conv |
| ) |  |  | `[inline, static]`

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 600 of file saveload.cpp.

References SlCalcConvFileLen().

Referenced by SlArray().

static byte SlCalcConvFileLen | ( | VarType | conv | ) | `[inline, static]`

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 121 of file saveload.cpp.

References GB().

Referenced by SlArray(), and SlCalcArrayLen().

static byte SlCalcConvMemLen | ( | VarType | conv | ) | `[inline, static]`

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 109 of file saveload.cpp.

References GB().

Referenced by SlArray(), and SlSkipVariableOnLoad().

static size_t SlCalcListLen | ( | const void * | list | ) | `[inline, static]`

Return the size in bytes of a list.

Parameters:

  | list | The std::list to find the size of

Definition at line 662 of file saveload.cpp.

References CheckSavegameVersion().

Referenced by SlList().

static size_t SlCalcNetStringLen | ( | const char * | ptr,
|  | size_t | length |
| ) |  |  | `[inline, static]`

Calculate the net length of a string.

This is in almost all cases just strlen(), but if the string is not properly terminated, we'll resort to the maximum length of the buffer.

Parameters:

  | ptr | pointer to the stringbuffer
  | length | maximum length of the string (buffer). If -1 we don't care about a maximum length, but take string length as it is.

Returns:
  return the net length of the string

Definition at line 501 of file saveload.cpp.

References minu().

Referenced by SlCalcStringLen(), and SlString().

static size_t SlCalcObjLength | ( | const void * | object,
|  | const SaveLoad * | sld |
| ) |  |  | `[static]`

Calculate the size of an object.

Parameters:

  | object | to be measured
  | sld | The SaveLoad description of the object so we know how to manipulate it

Returns:
  size of given objetc

Definition at line 737 of file saveload.cpp.

References SaveLoad::cmd.

Referenced by SlObject().

static size_t SlCalcStringLen | ( | const void * | ptr,
|  | size_t | length,
|  | VarType | conv |
| ) |  |  | `[inline, static]`

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 stringbuffer
  | length | maximum length of the string (buffer size, etc.)
  | conv | type of data been used

Returns:
  return the gross length of the string

Definition at line 514 of file saveload.cpp.

References SlCalcNetStringLen(), SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, and SLE_VAR_STRQ.

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 373 of file saveload.cpp.

References _sl, SlReadByteInternal(), and SlWriteByteInternal().

Referenced by SlArray(), and SlString().

static void NORETURN SlError | ( | StringID | string,
|  | const char * | extra_msg = `NULL` |
| ) |  |  | `[static]`

Error handler, calls longjmp to simulate an exception.

Todo:
  this was used to have a central place to handle errors, but it is pretty ugly, and seriously interferes with any multithreaded approaches

Definition at line 82 of file saveload.cpp.

References _sl, and extra_msg.

Referenced by SaveFileToDisk(), SaveOrLoad(), SlAutolength(), SlIterateArray(), SlLoadChunk(), SlLoadChunks(), SlReadFill(), and SlReadSimpleGamma().

static const ChunkHandler* SlFindChunkHandler | ( | uint32 | 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 appropiate chunkhandler

Definition at line 996 of file saveload.cpp.

References _sl.

Referenced by SlLoadChunks().

void SlGlobList | ( | const SaveLoadGlobVarList * | sldg | ) |

Save or Load (a list of) global variables.

Parameters:

  | sldg | The global variable that is being loaded or saved

Definition at line 852 of file saveload.cpp.

References SlObject().

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 299 of file saveload.cpp.

References _sl, and SlError().

Referenced by Load_SIGN(), and Load_VEHS().

void SlList | ( | void * | list,
|  | SLRefType | conv |
| ) |  |  |

Save/Load a list.

Parameters:

  | list | The list being manipulated
  | conv | SLRefType type of the list (Vehicle *, Station *, etc)

Definition at line 678 of file saveload.cpp.

References _sl, CheckSavegameVersion(), IntToReference(), ReferenceToInt(), SlCalcListLen(), and SlSetLength().

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 889 of file saveload.cpp.

References _sl, SlError(), and SlReadByte().

Referenced by SlLoadChunks().

void SlObject | ( | void * | object,
|  | const SaveLoad * | sld |
| ) |  |  |

Main SaveLoad function.

Parameters:

  | object | The object that is being saved or loaded
  | sld | The SaveLoad description of the object so we know how to manipulate it

Definition at line 834 of file saveload.cpp.

References _sl, SaveLoad::address, SaveLoad::cmd, GetVariableAddress(), SaveLoad::global, SlCalcObjLength(), and SlSetLength().

Referenced by Load_SIGN(), Load_VEHS(), Save_SIGN(), Save_VEHS(), SaveLoad_ECMY(), and SlGlobList().

static byte SlReadByteInternal | ( |  | ) | `[inline, static]`

Read in a single byte from file.

If the temporary buffer is full, flush it to its final destination

Returns:
  return the read byte from file

Definition at line 155 of file saveload.cpp.

References _sl, and SlReadFill().

Referenced by SlCopyBytes(), and SlReadByte().

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 223 of file saveload.cpp.

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

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 appropiate

Parameters:

  | ch | The chunkhandler that will be used for the operation

Definition at line 931 of file saveload.cpp.

References _sl, and SlWriteByte().

Referenced by SlSaveChunks().

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 452 of file saveload.cpp.

References _sl, ReadValue(), RemapOldStringID(), SLE_FILE_STRINGID, SlReadByte(), SlWriteByte(), and WriteValue().

Referenced by SlArray().

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 334 of file saveload.cpp.

References _sl.

Referenced by Save_ANIT(), SaveSettings(), SlArray(), SlAutolength(), SlList(), and SlObject().

static void SlSkipBytes | ( | size_t | length | ) | `[inline, static]`

Read in bytes from the file/data structure but don't do anything with them, discarding them in effect.

Parameters:

  | length | The amount of bytes that is being treated this way

Definition at line 388 of file saveload.cpp.

References SlReadByte().

Referenced by SlSkipVariableOnLoad(), and SlString().

static bool SlSkipVariableOnLoad | ( | const SaveLoad * | sld | ) | `[inline, static]`

Are we going to load this variable when loading a savegame or not?

Note:
  If the variable is skipped it is skipped in the savegame bytestream itself as well, so there is no need to skip it somewhere else

Definition at line 721 of file saveload.cpp.

References _networking, _sl, SaveLoad::conv, SaveLoad::length, SlCalcConvMemLen(), SLF_NETWORK_NO, and SlSkipBytes().

static void SlString | ( | void * | ptr,
|  | size_t | length,
|  | VarType | conv |
| ) |  |  | `[static]`

Save/Load a string.

Parameters:

  | ptr | the string being manipulated
  | length | of the string (full length)
  | conv | must be SLE_FILE_STRING

Definition at line 542 of file saveload.cpp.

References _sl, SlCalcNetStringLen(), SlCopyBytes(), SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, SLE_VAR_STRQ, and SlSkipBytes().

static void SlWriteByteInternal | ( | byte | b | ) | `[inline, static]`

Write away a single byte from memory.

If the temporary buffer is full, flush it to its destination (file)

Parameters:

  | b | the byte that is currently written

Definition at line 168 of file saveload.cpp.

References _sl, and SlWriteFill().

Referenced by SlCopyBytes(), and SlWriteByte().

static void SlWriteFill | ( |  | ) | `[static]`

Flush the output buffer by writing to disk with the given reader.

If the buffer pointer has not yet been set up, set it up now. Usually only called when the buffer is full, or there is no more data to be processed

Definition at line 136 of file saveload.cpp.

References _sl.

Referenced by SaveOrLoad(), and SlWriteByteInternal().

static void SlWriteSimpleGamma | ( | uint | 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

Parameters:

  | i | Index being written

Definition at line 255 of file saveload.cpp.

References SlWriteByte().

void WriteValue | ( | void * | ptr,
|  | VarType | conv,
|  | int64 | 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 426 of file saveload.cpp.

References SLE_VAR_NAME, and SLE_VAR_NULL.

Referenced by SlSaveLoadConv(), and Write_ValidateSetting().

## Variable Documentation

const ChunkHandler* const _chunk_handlers[]`[static]`

Initial value:

     {
      _misc_chunk_handlers,
      _setting_chunk_handlers,
      _veh_chunk_handlers,
      _waypoint_chunk_handlers,
      _depot_chunk_handlers,
      _order_chunk_handlers,
      _industry_chunk_handlers,
      _economy_chunk_handlers,
      _engine_chunk_handlers,
      _town_chunk_handlers,
      _sign_chunk_handlers,
      _station_chunk_handlers,
      _player_chunk_handlers,
      _animated_tile_chunk_handlers,
      _newgrf_chunk_handlers,
      _group_chunk_handlers,
      _cargopacket_chunk_handlers,
      NULL,
    }

Definition at line 1276 of file saveload.cpp.

const SaveLoadFormat _saveload_formats[]`[static]`

Initial value:

     {
      {"memory", 0,                NULL,         NULL,       NULL,           InitMem,       WriteMem,    UnInitMem},
      {"lzo",    TO_BE32X('OTTD'), InitLZO,      ReadLZO,    UninitLZO,      InitLZO,       WriteLZO,    UninitLZO},
      {"none",   TO_BE32X('OTTN'), InitNoComp,   ReadNoComp, UninitNoComp,   InitNoComp,    WriteNoComp, UninitNoComp},

      {"zlib",   TO_BE32X('OTTZ'), NULL,         NULL,       NULL,           NULL,          NULL,        NULL},

    }

Definition at line 1410 of file saveload.cpp.

struct { ... } _sl`[static]`

The saveload struct, containing reader-writer functions, bufffer, version, etc.

Referenced by AbortSaveLoad(), GetSaveLoadErrorString(), SaveFileToDisk(), SaveOrLoad(), SetSaveLoadError(), SlArray(), SlAutolength(), SlCopyBytes(), SlError(), SlFindChunkHandler(), SlIterateArray(), SlList(), SlLoadChunk(), SlObject(), SlReadByteInternal(), SlReadFill(), SlSaveChunk(), SlSaveChunks(), SlSaveLoadConv(), SlSetLength(), SlSkipVariableOnLoad(), SlString(), SlWriteByteInternal(), and SlWriteFill().