|
OpenTTD Source 20251117-master-g7398d2e290
|
Finding NewGRFs and configuring them. More...
#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. | |
| size_t | GRFGetSizeOfDataSection (FileHandle &f) |
| Get the data section size of a GRF. | |
| static bool | CalcGRFMD5Sum (GRFConfig &config, Subdirectory subdir) |
| Calculate the MD5 sum for a GRF, and store it in the config. | |
| bool | FillGRFDetails (GRFConfig &config, bool is_static, Subdirectory subdir) |
| Find the GRFID of a given grf, and calculate its md5sum. | |
| void | ClearGRFConfigList (GRFConfigList &config) |
| Clear a GRF Config list, freeing all nodes. | |
| static void | AppendGRFConfigList (GRFConfigList &dst, const GRFConfigList &src, bool init_only) |
| Append a GRF Config list onto another list. | |
| void | CopyGRFConfigList (GRFConfigList &dst, const GRFConfigList &src, bool init_only) |
| Copy a GRF Config list. | |
| static void | RemoveDuplicatesFromGRFConfigList (GRFConfigList &list) |
| Removes duplicates from lists of GRFConfigs. | |
| void | AppendStaticGRFConfigs (GRFConfigList &dst) |
| Appends the static GRFs to a list of GRFs. | |
| void | AppendToGRFConfigList (GRFConfigList &dst, std::unique_ptr< GRFConfig > &&el) |
| Appends an element to a list of GRFs. | |
| void | ResetGRFConfig (bool defaults) |
| Reset the current GRF Config to either blank or newgame settings. | |
| GRFListCompatibility | IsGoodGRFConfigList (GRFConfigList &grfconfig) |
| Check if all GRFs in the GRF config from a savegame can be loaded. | |
| static bool | GRFSorter (std::unique_ptr< GRFConfig > const &c1, std::unique_ptr< GRFConfig > const &c2) |
| Simple sorter for GRFS. | |
| void | DoScanNewGRFFiles (NewGRFScanCallback *callback) |
| Really perform the scan for all NewGRFs. | |
| void | ScanNewGRFFiles (NewGRFScanCallback *callback) |
| Scan for all NewGRFs. | |
| const GRFConfig * | FindGRFConfig (uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version) |
| Find a NewGRF in the scanned list. | |
| GRFConfig * | GetGRFConfig (uint32_t grfid, uint32_t mask) |
| Retrieve a NewGRF from the current config by its grfid. | |
| std::string | GRFBuildParamList (const GRFConfig &c) |
| Build a string containing space separated parameter values, and terminate. | |
Variables | |
| GRFConfigList | _all_grfs |
| First item in list of all scanned NewGRFs. | |
| GRFConfigList | _grfconfig |
| First item in list of current GRF set up. | |
| GRFConfigList | _grfconfig_newgame |
| First item in list of default GRF set up. | |
| GRFConfigList | _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. | |
Finding NewGRFs and configuring them.
Definition in file newgrf_config.cpp.
|
static |
Append a GRF Config list onto another list.
| dst | The destination list |
| src | The source list |
| init_only | the copied GRF will be processed up to GLS_INIT |
Definition at line 335 of file newgrf_config.cpp.
References InitOnly.
Referenced by AppendStaticGRFConfigs(), and CopyGRFConfigList().
| void AppendStaticGRFConfigs | ( | GRFConfigList & | dst | ) |
Appends the static GRFs to a list of GRFs.
| dst | the head of the list to add to |
Definition at line 388 of file newgrf_config.cpp.
References _grfconfig_static, AppendGRFConfigList(), and RemoveDuplicatesFromGRFConfigList().
Referenced by NGRFChunkHandler::Load(), and ResetGRFConfig().
| void AppendToGRFConfigList | ( | GRFConfigList & | dst, |
| std::unique_ptr< GRFConfig > && | el | ||
| ) |
Appends an element to a list of GRFs.
| dst | the head of the list to add to |
| el | the new tail to be |
Definition at line 399 of file newgrf_config.cpp.
References RemoveDuplicatesFromGRFConfigList().
|
static |
Calculate the MD5 sum for a GRF, and store it in the config.
| config | GRF to compute. |
| subdir | The subdirectory to look in. |
Definition at line 257 of file newgrf_config.cpp.
References GRFConfig::filename, FioFOpenFile(), GRFGetSizeOfDataSection(), GRFConfig::ident, and GRFIdentifier::md5sum.
Referenced by FillGRFDetails().
| void ClearGRFConfigList | ( | GRFConfigList & | config | ) |
Clear a GRF Config list, freeing all nodes.
| config | Start of the list. |
nullptr. Definition at line 324 of file newgrf_config.cpp.
Referenced by LoadCheckData::Clear(), CopyGRFConfigList(), DoLoad(), DoScanNewGRFFiles(), NetworkAddServer(), NewGRFWindow::OnDropdownSelect(), ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(), QueryNetworkGameSocketHandler::Receive_SERVER_GAME_INFO(), and SaveOrLoad().
| void CopyGRFConfigList | ( | GRFConfigList & | dst, |
| const GRFConfigList & | src, | ||
| bool | init_only | ||
| ) |
Copy a GRF Config list.
| dst | The destination list |
| src | The source list |
| init_only | the copied GRF will be processed up to GLS_INIT |
Definition at line 353 of file newgrf_config.cpp.
References AppendGRFConfigList(), and ClearGRFConfigList().
Referenced by NewGRFWindow::Close(), NewGRFConfirmationCallback(), and ResetGRFConfig().
| void DoScanNewGRFFiles | ( | NewGRFScanCallback * | callback | ) |
Really perform the scan for all NewGRFs.
| callback | The callback to call after the scanning is complete. |
Definition at line 552 of file newgrf_config.cpp.
References _all_grfs, ClearGRFConfigList(), CloseWindowByClass(), Debug, GRFFileScanner::DoScan(), TarScanner::DoScan(), GOID_NEWGRF_RESCANNED, GRFSorter(), InvalidateWindowClassesData(), InvalidateWindowData(), MarkWholeScreenDirty(), NetworkAfterNewGRFScan(), TarScanner::NewGRF, NewGRFScanCallback::OnNewGRFsScanned(), SetModalProgress(), WC_GAME_OPTIONS, WC_MODAL_PROGRESS, WC_SAVELOAD, and WN_GAME_OPTIONS_NEWGRF_STATE.
Referenced by ScanNewGRFFiles().
| bool FillGRFDetails | ( | GRFConfig & | config, |
| bool | is_static, | ||
| Subdirectory | subdir | ||
| ) |
Find the GRFID of a given grf, and calculate its md5sum.
| config | grf to fill. |
| is_static | grf is static. |
| subdir | the subdirectory to search in. |
Definition at line 292 of file newgrf_config.cpp.
References CalcGRFMD5Sum(), GRFConfig::filename, GRFConfig::FinalizeParameterInfo(), FioCheckFileExists(), GRFConfig::flags, GCS_NOT_FOUND, GRFIdentifier::grfid, GRFConfig::ident, LoadNewGRFFile(), GRFConfig::SetSuitablePalette(), GRFConfig::status, System, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and Unsafe.
Referenced by GRFFileScanner::AddFile(), GetDefaultExtraGRFConfig(), GraphicsSet::GetOrCreateExtraConfig(), and GRFLoadConfig().
| const GRFConfig * FindGRFConfig | ( | uint32_t | grfid, |
| FindGRFConfigMode | mode, | ||
| const MD5Hash * | md5sum, | ||
| uint32_t | desired_version | ||
| ) |
Find a NewGRF in the scanned list.
| grfid | GRFID to look for, |
| mode | Restrictions for matching grfs |
| md5sum | Expected MD5 sum |
| desired_version | Requested version |
nullptr. Definition at line 596 of file newgrf_config.cpp.
References _all_grfs, FGCM_ANY, FGCM_COMPATIBLE, FGCM_EXACT, FGCM_NEWEST, Invalid, and GRFConfig::version.
Referenced by AddGrfInfo(), ContentInfo::GetTextfile(), GRFLoadConfig(), HasGRFConfig(), IsGoodGRFConfigList(), NetworkAfterNewGRFScan(), NewGRFWindow::OnInvalidateData(), and ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS().
| GRFConfig * GetGRFConfig | ( | uint32_t | grfid, |
| uint32_t | mask | ||
| ) |
Retrieve a NewGRF from the current config by its grfid.
| grfid | grf to look for. |
| mask | GRFID mask to allow for partial matching. |
nullptr. Definition at line 622 of file newgrf_config.cpp.
References _grfconfig.
Referenced by DrawVehiclePurchaseInfo(), ErrorUnknownCallbackResult(), GetGlobalVariable(), ParamSet(), ShowNewGrfVehicleError(), TranslateGRFStrings(), and VehicleLengthChanged().
| std::string GRFBuildParamList | ( | const GRFConfig & | c | ) |
Build a string containing space separated parameter values, and terminate.
Definition at line 632 of file newgrf_config.cpp.
References GRFConfig::param.
Referenced by GraphicsSetSaveConfig().
| size_t GRFGetSizeOfDataSection | ( | FileHandle & | f | ) |
Get the data section size of a GRF.
| f | GRF. |
Definition at line 227 of file newgrf_config.cpp.
References _grf_cont_v2_sig, and Debug.
Referenced by CalcGRFMD5Sum(), and GraphicsSet::CheckMD5().
|
static |
Simple sorter for GRFS.
Definition at line 543 of file newgrf_config.cpp.
References StrNaturalCompare().
Referenced by DoScanNewGRFFiles().
| GRFListCompatibility IsGoodGRFConfigList | ( | GRFConfigList & | grfconfig | ) |
Check if all GRFs in the GRF config from a savegame can be loaded.
| grfconfig | GrfConfig to check |
Definition at line 425 of file newgrf_config.cpp.
References Compatible, Copy, Debug, FGCM_COMPATIBLE, FGCM_EXACT, GRFConfig::filename, FindGRFConfig(), GRFConfig::flags, FormatArrayAsHex(), GCS_NOT_FOUND, GLC_ALL_GOOD, GLC_COMPATIBLE, GLC_NOT_FOUND, GRFIdentifier::grfid, GRFConfig::has_param_defaults, GRFConfig::ident, Invalid, GRFIdentifier::md5sum, GRFConfig::min_loadable_version, GRFConfig::name, GRFConfig::num_valid_params, GRFConfig::param_info, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and GRFConfig::version.
Referenced by AfterLoadGame(), and DoLoad().
|
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.
| list | the list to remove the duplicates from |
Definition at line 373 of file newgrf_config.cpp.
Referenced by AppendStaticGRFConfigs(), and AppendToGRFConfigList().
| void ResetGRFConfig | ( | bool | defaults | ) |
Reset the current GRF Config to either blank or newgame settings.
Definition at line 407 of file newgrf_config.cpp.
References _grfconfig, _grfconfig_newgame, AppendStaticGRFConfigs(), and CopyGRFConfigList().
Referenced by NewGRFWindow::Close(), NGRFChunkHandler::Load(), LoadIntroGame(), and AfterNewGRFScan::OnNewGRFsScanned().
| void ScanNewGRFFiles | ( | NewGRFScanCallback * | callback | ) |
Scan for all NewGRFs.
| callback | The callback to call after the scanning is complete. |
Definition at line 578 of file newgrf_config.cpp.
References DoScanNewGRFFiles(), MarkWholeScreenDirty(), and SetModalProgress().
| void UpdateNewGRFConfigPalette | ( | int32_t | new_value | ) |
Update the palettes of the graphics from the config file.
Called when changing the default palette in advanced settings.
Definition at line 215 of file newgrf_config.cpp.
References _all_grfs, _grfconfig_newgame, and _grfconfig_static.
Referenced by AfterNewGRFScan::OnNewGRFsScanned().
| GRFConfigList _all_grfs |
First item in list of all scanned NewGRFs.
Definition at line 153 of file newgrf_config.cpp.
Referenced by GRFFileScanner::AddFile(), NewGRFWindow::CanUpgradeCurrent(), DoScanNewGRFFiles(), FindGRFConfig(), UpdateNewGRFConfigPalette(), and NewGRFWindow::UpgradeCurrent().
| GRFConfigList _grfconfig |
First item in list of current GRF set up.
Definition at line 154 of file newgrf_config.cpp.
Referenced by AfterLoadGame(), DoLoad(), GetGRFConfig(), HandleSavegameLoadCrash(), NGRFChunkHandler::Load(), LoadNewGRF(), LoadSpriteTables(), MenuClickSettings(), NewGRFConfirmationCallback(), ResetGRFConfig(), ResetNewGRF(), ResetNewGRFErrors(), NGRFChunkHandler::Save(), SaveOrLoad(), ServerNetworkGameSocketHandler::SendNewGRFCheck(), ShowNewGRFError(), SurveyGrfs(), and SwitchNewGRFBlitter().
| GRFConfigList _grfconfig_newgame |
First item in list of default GRF set up.
Definition at line 155 of file newgrf_config.cpp.
Referenced by LoadFromConfig(), GenerateLandscapeWindow::OnClick(), ResetGRFConfig(), SaveToConfig(), and UpdateNewGRFConfigPalette().
| GRFConfigList _grfconfig_static |
First item in list of static GRF set up.
Definition at line 156 of file newgrf_config.cpp.
Referenced by AppendStaticGRFConfigs(), LoadFromConfig(), SaveToConfig(), and UpdateNewGRFConfigPalette().
| uint _missing_extra_graphics = 0 |
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
Definition at line 157 of file newgrf_config.cpp.
Referenced by SelectGameWindow::DrawWidget(), LoadSpriteTables(), SelectGameWindow::OnInit(), and SelectGameWindow::OnResize().
| int _skip_all_newgrf_scanning = 0 |
Set this flag to prevent any NewGRF scanning from being done.
Definition at line 481 of file newgrf_config.cpp.
Referenced by GRFFileScanner::DoScan(), and openttd_main().