OpenTTD Source: src/newgrf_config.cpp File Reference

OpenTTD Source 14.0-RC3

Data Structures | Functions | Variables
newgrf_config.cpp File Reference
`#include "stdafx.h"`
`#include "debug.h"`
`#include "3rdparty/md5/md5.h"`
`#include "newgrf.h"`
`#include "network/network_func.h"`
`#include "gfx_func.h"`
`#include "newgrf_text.h"`
`#include "window_func.h"`
`#include "progress.h"`
`#include "video/video_driver.hpp"`
`#include "string_func.h"`
`#include "strings_func.h"`
`#include "textfile_gui.h"`
`#include "thread.h"`
`#include "newgrf_config.h"`
`#include "fileio_func.h"`
`#include "fios.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
class | GRFFileScanner
| Helper for scanning for files with GRF as extension. More...

## Functions
void | UpdateNewGRFConfigPalette (int32_t)
| Update the palettes of the graphics from the config file. More...
size_t | GRFGetSizeOfDataSection (FILE *f)
| Get the data section size of a GRF. More...
static bool | CalcGRFMD5Sum (GRFConfig *config, Subdirectory subdir)
| Calculate the MD5 sum for a GRF, and store it in the config. More...
bool | FillGRFDetails (GRFConfig *config, bool is_static, Subdirectory subdir)
| Find the GRFID of a given grf, and calculate its md5sum. More...
void | ClearGRFConfigList (GRFConfig **config)
| Clear a GRF Config list, freeing all nodes. More...
GRFConfig ** | CopyGRFConfigList (GRFConfig **dst, const GRFConfig *src, bool init_only)
| Copy a GRF Config list. More...
static void | RemoveDuplicatesFromGRFConfigList (GRFConfig *list)
| Removes duplicates from lists of GRFConfigs. More...
void | AppendStaticGRFConfigs (GRFConfig **dst)
| Appends the static GRFs to a list of GRFs. More...
void | AppendToGRFConfigList (GRFConfig **dst, GRFConfig *el)
| Appends an element to a list of GRFs. More...
void | ResetGRFConfig (bool defaults)
| Reset the current GRF Config to either blank or newgame settings.
GRFListCompatibility | IsGoodGRFConfigList (GRFConfig *grfconfig)
| Check if all GRFs in the GRF config from a savegame can be loaded. More...
static bool | GRFSorter (GRFConfig *const &c1, GRFConfig *const &c2)
| Simple sorter for GRFS. More...
void | DoScanNewGRFFiles (NewGRFScanCallback *callback)
| Really perform the scan for all NewGRFs. More...
void | ScanNewGRFFiles (NewGRFScanCallback *callback)
| Scan for all NewGRFs. More...
const GRFConfig * | FindGRFConfig (uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
| Find a NewGRF in the scanned list. More...
GRFConfig * | GetGRFConfig (uint32_t grfid, uint32_t mask)
| Retrieve a NewGRF from the current config by its grfid. More...
std::string | GRFBuildParamList (const GRFConfig *c)
| Build a string containing space separated parameter values, and terminate.

## Variables
GRFConfig * | _all_grfs
| First item in list of all scanned NewGRFs.
GRFConfig * | _grfconfig
| First item in list of current GRF set up.
GRFConfig * | _grfconfig_newgame
| First item in list of default GRF set up.
GRFConfig * | _grfconfig_static
| First item in list of static GRF set up.
uint | _missing_extra_graphics = 0
| Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
int | _skip_all_newgrf_scanning = 0
| Set this flag to prevent any NewGRF scanning from being done.

## Detailed Description

Finding NewGRFs and configuring them.

Definition in file newgrf_config.cpp.

## Function Documentation

## ◆ AppendStaticGRFConfigs()

void AppendStaticGRFConfigs | ( | GRFConfig ** | dst | ) |

Appends the static GRFs to a list of GRFs.

Parameters

  dst | the head of the list to add to

Definition at line 426 of file newgrf_config.cpp.

References _grfconfig_static, CopyGRFConfigList(), GRFConfig::next, and RemoveDuplicatesFromGRFConfigList().

Referenced by ResetGRFConfig().

## ◆ AppendToGRFConfigList()

void AppendToGRFConfigList | ( | GRFConfig ** | dst,
|  | GRFConfig * | el
| ) |  |

Appends an element to a list of GRFs.

Parameters

  dst | the head of the list to add to
  el | the new tail to be

Definition at line 440 of file newgrf_config.cpp.

References GRFConfig::next, and RemoveDuplicatesFromGRFConfigList().

## ◆ CalcGRFMD5Sum()

static bool CalcGRFMD5Sum | ( | GRFConfig * | config,
|  | Subdirectory | subdir
| ) |  |
| static

Calculate the MD5 sum for a GRF, and store it in the config.

Parameters

  config | GRF to compute.
  subdir | The subdirectory to look in.

Returns
  MD5 sum was successfully computed

Definition at line 285 of file newgrf_config.cpp.

References GRFConfig::filename, FioFCloseFile(), FioFOpenFile(), GRFGetSizeOfDataSection(), GRFConfig::ident, and GRFIdentifier::md5sum.

## ◆ ClearGRFConfigList()

void ClearGRFConfigList | ( | GRFConfig ** | config | ) |

Clear a GRF Config list, freeing all nodes.

Parameters

  config | Start of the list.

Postcondition
  config is set to `nullptr`.

Definition at line 356 of file newgrf_config.cpp.

References GRFConfig::next.

Referenced by LoadCheckData::Clear(), CopyGRFConfigList(), DoScanNewGRFFiles(), NetworkAddServer(), NetworkGameListRemoveExpired(), NetworkGameListRemoveItem(), ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(), and QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO().

## ◆ CopyGRFConfigList()

GRFConfig** CopyGRFConfigList | ( | GRFConfig ** | dst,
|  | const GRFConfig * | src,
|  | bool | init_only
| ) |  |

Copy a GRF Config list.

Parameters

  dst | pointer to destination list
  src | pointer to source list values
  init_only | the copied GRF will be processed up to GLS_INIT

Returns
  pointer to the last value added to the destination list

Definition at line 374 of file newgrf_config.cpp.

References ClearGRFConfigList(), ClrBit(), GRFConfig::flags, GCF_INIT_ONLY, GRFConfig::next, and SetBit().

Referenced by AppendStaticGRFConfigs(), NewGRFConfirmationCallback(), and ResetGRFConfig().

## ◆ DoScanNewGRFFiles()

void DoScanNewGRFFiles | ( | NewGRFScanCallback * | callback | ) |

Really perform the scan for all NewGRFs.

Parameters

  callback | The callback to call after the scanning is complete.

Definition at line 625 of file newgrf_config.cpp.

References _all_grfs, ClearGRFConfigList(), Debug, TarScanner::DoScan(), GRFFileScanner::DoScan(), GOID_NEWGRF_RESCANNED, GRFSorter(), InvalidateWindowClassesData(), InvalidateWindowData(), NetworkAfterNewGRFScan(), TarScanner::NEWGRF, GRFConfig::next, WC_GAME_OPTIONS, WC_SAVELOAD, and WN_GAME_OPTIONS_NEWGRF_STATE.

Referenced by ScanNewGRFFiles().

## ◆ FillGRFDetails()

bool FillGRFDetails | ( | GRFConfig * | config,
|  | bool | is_static,
|  | Subdirectory | subdir
| ) |  |

Find the GRFID of a given grf, and calculate its md5sum.

Parameters

  config | grf to fill.
  is_static | grf is static.
  subdir | the subdirectory to search in.

Returns
  Operation was successfully completed.

Definition at line 324 of file newgrf_config.cpp.

References GRFConfig::filename, FioCheckFileExists(), GCS_NOT_FOUND, LoadNewGRFFile(), and GRFConfig::status.

Referenced by GraphicsSet::GetOrCreateExtraConfig(), and GRFLoadConfig().

## ◆ FindGRFConfig()

const GRFConfig* FindGRFConfig | ( | uint32_t | grfid,
|  | FindGRFConfigMode | mode,
|  | const MD5Hash * | md5sum,
|  | uint32_t | desired_version
| ) |  |

Find a NewGRF in the scanned list.

Parameters

  grfid | GRFID to look for,
  mode | Restrictions for matching grfs
  md5sum | Expected MD5 sum
  desired_version | Requested version

Returns
  The matching grf, if it exists in _all_grfs, else `nullptr`.

Definition at line 690 of file newgrf_config.cpp.

References _all_grfs, FGCM_ANY, FGCM_COMPATIBLE, FGCM_EXACT, FGCM_NEWEST, GCF_INVALID, HasBit(), GRFConfig::next, and GRFConfig::version.

Referenced by AddGrfInfo(), GRFLoadConfig(), HasGRFConfig(), IsGoodGRFConfigList(), NetworkAfterNewGRFScan(), NewGRFWindow::OnInvalidateData(), and ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS().

## ◆ GetGRFConfig()

GRFConfig* GetGRFConfig | ( | uint32_t | grfid,
|  | uint32_t | mask
| ) |  |

Retrieve a NewGRF from the current config by its grfid.

Parameters

  grfid | grf to look for.
  mask | GRFID mask to allow for partial matching.

Returns
  The grf config, if it exists, else `nullptr`.

Definition at line 716 of file newgrf_config.cpp.

References _grfconfig, GRFIdentifier::grfid, GRFConfig::ident, and GRFConfig::next.

Referenced by ShowNewGrfVehicleError(), TranslateGRFStrings(), and VehicleLengthChanged().

## ◆ GRFGetSizeOfDataSection()

size_t GRFGetSizeOfDataSection | ( | FILE * | f | ) |

Get the data section size of a GRF.

Parameters

  f | GRF.

Returns
  Size of the data section or SIZE_MAX if the file has no separate data section.

Definition at line 255 of file newgrf_config.cpp.

References _grf_cont_v2_sig, Debug, and MemCmpT().

Referenced by CalcGRFMD5Sum(), and GraphicsSet::CheckMD5().

## ◆ GRFSorter()

static bool GRFSorter | ( | GRFConfig *const & | c1,
|  | GRFConfig *const & | c2
| ) |  |
| static

Simple sorter for GRFS.

Parameters

  c1 | the first GRFConfig *
  c2 | the second GRFConfig *

Returns
  true if the name of first NewGRF is before the name of the second.

Definition at line 616 of file newgrf_config.cpp.

References GRFConfig::GetName(), and StrNaturalCompare().

Referenced by DoScanNewGRFFiles().

## ◆ IsGoodGRFConfigList()

GRFListCompatibility IsGoodGRFConfigList | ( | GRFConfig * | grfconfig | ) |

Check if all GRFs in the GRF config from a savegame can be loaded.

Parameters

  grfconfig | GrfConfig to check

Returns
  will return any of the following 3 values:
  - GLC_ALL_GOOD: No problems occurred, all GRF files were found and loaded
  - GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a compatible GRF with the same grfid was found and used instead
  - GLC_NOT_FOUND: For one or more GRF's no match was found at all

Definition at line 469 of file newgrf_config.cpp.

References BSWAP32(), Debug, FGCM_COMPATIBLE, FGCM_EXACT, GRFConfig::filename, FindGRFConfig(), GRFConfig::flags, FormatArrayAsHex(), GCF_COMPATIBLE, GCF_COPY, GCF_INVALID, GCS_NOT_FOUND, GLC_ALL_GOOD, GLC_COMPATIBLE, GLC_NOT_FOUND, GRFIdentifier::grfid, GRFConfig::has_param_defaults, HasBit(), GRFConfig::ident, GRFIdentifier::md5sum, GRFConfig::min_loadable_version, GRFConfig::name, GRFConfig::next, GRFConfig::num_valid_params, GRFConfig::param_info, SetBit(), and GRFConfig::version.

## ◆ RemoveDuplicatesFromGRFConfigList()

static void RemoveDuplicatesFromGRFConfigList | ( | GRFConfig * | list | ) |
| static

Removes duplicates from lists of GRFConfigs.

These duplicates are introduced when the _grfconfig_static GRFs are appended to the _grfconfig on a newgame or savegame. As the parameters of the static GRFs could be different that the parameters of the ones used non-statically. This can result in desyncs in multiplayers, so the duplicate static GRFs have to be removed.

This function assumes that all static GRFs are placed after the non-static GRFs.

Parameters

  list | the list to remove the duplicates from

Definition at line 404 of file newgrf_config.cpp.

References GRFIdentifier::grfid, GRFConfig::ident, and GRFConfig::next.

Referenced by AppendStaticGRFConfigs(), and AppendToGRFConfigList().

## ◆ ScanNewGRFFiles()

void ScanNewGRFFiles | ( | NewGRFScanCallback * | callback | ) |

Scan for all NewGRFs.

Parameters

  callback | The callback to call after the scanning is complete.

Definition at line 672 of file newgrf_config.cpp.

References DoScanNewGRFFiles(), MarkWholeScreenDirty(), and SetModalProgress().

## ◆ UpdateNewGRFConfigPalette()

void UpdateNewGRFConfigPalette | ( | int32_t |  | ) |

Update the palettes of the graphics from the config file.

Called when changing the default palette in advanced settings.

Definition at line 243 of file newgrf_config.cpp.

References _all_grfs, _grfconfig_newgame, _grfconfig_static, and GRFConfig::next.

Referenced by AfterNewGRFScan::OnNewGRFsScanned().