OpenTTD Source: src/newgrf_config.cpp Source File

OpenTTD Source 15.0-RC2

newgrf_config.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "debug.h"
12#include "3rdparty/md5/md5.h"
13#include "newgrf.h"
14#include "network/network_func.h"
15#include "gfx_func.h"
16#include "newgrf_text.h"
17#include "window_func.h"
18#include "progress.h"
19#include "video/video_driver.hpp"
20#include "string_func.h"
21#include "strings_func.h"
22#include "textfile_gui.h"
23#include "thread.h"
24#include "newgrf_config.h"
25#include "newgrf_text.h"
26
27#include "fileio_func.h"
28#include "fios.h"
29
30#include "safeguards.h"
31
36GRFConfig::GRFConfig(const GRFConfig &config) :
37 ident(config.ident),
38 original_md5sum(config.original_md5sum),
39 filename(config.filename),
40 name(config.name),
41 info(config.info),
42 url(config.url),
43 errors(config.errors),
44 version(config.version),
45 min_loadable_version(config.min_loadable_version),
46 flags(config.flags),
47 status(config.status),
48 grf_bugs(config.grf_bugs),
49 num_valid_params(config.num_valid_params),
50 palette(config.palette),
51 has_param_defaults(config.has_param_defaults),
52 param_info(config.param_info),
53 param(config.param)
54{
55 this->flags.Reset(GRFConfigFlag::Copy);
56}
57
58void GRFConfig::SetParams(std::span<const uint32_t> pars)
59{
60 this->param.assign(std::begin(pars), std::end(pars));
61}
62
66 bool GRFConfig::IsCompatible(uint32_t old_version) const
67{
68 return this->min_loadable_version <= old_version && old_version <= this->version;
69}
70
75 void GRFConfig::CopyParams(const GRFConfig &src)
76{
77 this->param = src.param;
78}
79
85std::string GRFConfig::GetName() const
86{
87 auto name = GetGRFStringFromGRFText(this->name);
88 return name.has_value() && !name->empty() ? std::string(*name) : this->filename;
89}
90
95std::optional<std::string> GRFConfig::GetDescription() const
96{
97 auto str = GetGRFStringFromGRFText(this->info);
98 if (!str.has_value()) return std::nullopt;
99 return std::string(*str);
100}
101
106std::optional<std::string> GRFConfig::GetURL() const
107{
108 auto str = GetGRFStringFromGRFText(this->url);
109 if (!str.has_value()) return std::nullopt;
110 return std::string(*str);
111}
112
114 void GRFConfig::SetParameterDefaults()
115{
116 this->param.clear();
117
118 if (!this->has_param_defaults) return;
119
120 for (const auto &info : this->param_info) {
121 if (!info.has_value()) continue;
122 this->SetValue(info.value(), info->def_value);
123 }
124}
125
131 void GRFConfig::SetSuitablePalette()
132{
133 PaletteType pal;
134 switch (this->palette & GRFP_GRF_MASK) {
135 case GRFP_GRF_DOS: pal = PAL_DOS; break;
136 case GRFP_GRF_WINDOWS: pal = PAL_WINDOWS; break;
137 default: pal = _settings_client.gui.newgrf_default_palette == 1 ? PAL_WINDOWS : PAL_DOS; break;
138 }
139 SB(this->palette, GRFP_USE_BIT, 1, pal == PAL_WINDOWS ? GRFP_USE_WINDOWS : GRFP_USE_DOS);
140}
141
145 void GRFConfig::FinalizeParameterInfo()
146{
147 for (auto &info : this->param_info) {
148 if (!info.has_value()) continue;
149 info->Finalize();
150 }
151}
152
153GRFConfigList _all_grfs;
154GRFConfigList _grfconfig;
155GRFConfigList _grfconfig_newgame;
156GRFConfigList _grfconfig_static;
157uint _missing_extra_graphics = 0;
158
164uint32_t GRFConfig::GetValue(const GRFParameterInfo &info) const
165{
166 /* If the parameter is not set then it must be 0. */
167 if (info.param_nr >= std::size(this->param)) return 0;
168
169 /* GB doesn't work correctly with nbits == 32, so handle that case here. */
170 if (info.num_bit == 32) return this->param[info.param_nr];
171
172 return GB(this->param[info.param_nr], info.first_bit, info.num_bit);
173}
174
180 void GRFConfig::SetValue(const GRFParameterInfo &info, uint32_t value)
181{
182 value = Clamp(value, info.min_value, info.max_value);
183
184 /* Allocate the new parameter if it's not already present. */
185 if (info.param_nr >= std::size(this->param)) this->param.resize(info.param_nr + 1);
186
187 /* SB doesn't work correctly with nbits == 32, so handle that case here. */
188 if (info.num_bit == 32) {
189 this->param[info.param_nr] = value;
190 } else {
191 SB(this->param[info.param_nr], info.first_bit, info.num_bit, value);
192 }
193
194 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE);
195}
196
200 void GRFParameterInfo::Finalize()
201{
202 /* Remove value names outside of the permitted range of values. */
203 auto it = std::remove_if(std::begin(this->value_names), std::end(this->value_names),
204 [this](const ValueName &vn) { return vn.first < this->min_value || vn.first > this->max_value; });
205 this->value_names.erase(it, std::end(this->value_names));
206
207 /* Test if the number of named values matches the full ranges of values. -1 because the range is inclusive. */
208 this->complete_labels = (this->max_value - this->min_value) == std::size(this->value_names) - 1;
209}
210
215 void UpdateNewGRFConfigPalette(int32_t)
216{
217 for (const auto &c : _grfconfig_newgame) c->SetSuitablePalette();
218 for (const auto &c : _grfconfig_static ) c->SetSuitablePalette();
219 for (const auto &c : _all_grfs ) c->SetSuitablePalette();
220}
221
227 size_t GRFGetSizeOfDataSection(FileHandle &f)
228{
229 extern const std::array<uint8_t, 8> _grf_cont_v2_sig;
230 static const uint header_len = 14;
231
232 uint8_t data[header_len];
233 if (fread(data, 1, header_len, f) == header_len) {
234 if (data[0] == 0 && data[1] == 0 && std::ranges::equal(std::span(data + 2, _grf_cont_v2_sig.size()), _grf_cont_v2_sig)) {
235 /* Valid container version 2, get data section size. */
236 size_t offset = (static_cast<size_t>(data[13]) << 24) | (static_cast<size_t>(data[12]) << 16) | (static_cast<size_t>(data[11]) << 8) | static_cast<size_t>(data[10]);
237 if (offset >= 1 * 1024 * 1024 * 1024) {
238 Debug(grf, 0, "Unexpectedly large offset for NewGRF");
239 /* Having more than 1 GiB of data is very implausible. Mostly because then
240 * all pools in OpenTTD are flooded already. Or it's just Action C all over.
241 * In any case, the offsets to graphics will likely not work either. */
242 return SIZE_MAX;
243 }
244 return header_len + offset;
245 }
246 }
247
248 return SIZE_MAX;
249}
250
257 static bool CalcGRFMD5Sum(GRFConfig &config, Subdirectory subdir)
258{
259 Md5 checksum;
260 uint8_t buffer[1024];
261 size_t len, size;
262
263 /* open the file */
264 auto f = FioFOpenFile(config.filename, "rb", subdir, &size);
265 if (!f.has_value()) return false;
266
267 long start = ftell(*f);
268 size = std::min(size, GRFGetSizeOfDataSection(*f));
269
270 if (start < 0 || fseek(*f, start, SEEK_SET) < 0) {
271 return false;
272 }
273
274 /* calculate md5sum */
275 while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, *f)) != 0 && size != 0) {
276 size -= len;
277 checksum.Append(buffer, len);
278 }
279 checksum.Finish(config.ident.md5sum);
280
281 return true;
282}
283
284
292 bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir)
293{
294 if (!FioCheckFileExists(config.filename, subdir)) {
295 config.status = GCS_NOT_FOUND;
296 return false;
297 }
298
299 /* Find and load the Action 8 information */
300 LoadNewGRFFile(config, GLS_FILESCAN, subdir, true);
301 config.SetSuitablePalette();
302 config.FinalizeParameterInfo();
303
304 /* Skip if the grfid is 0 (not read) or if it is an internal GRF */
305 if (config.ident.grfid == 0 || config.flags.Test(GRFConfigFlag::System)) return false;
306
307 if (is_static) {
308 /* Perform a 'safety scan' for static GRFs */
309 LoadNewGRFFile(config, GLS_SAFETYSCAN, subdir, true);
310
311 /* GRFConfigFlag::Unsafe is set if GLS_SAFETYSCAN finds unsafe actions */
312 if (config.flags.Test(GRFConfigFlag::Unsafe)) return false;
313 }
314
315 return CalcGRFMD5Sum(config, subdir);
316}
317
318
324 void ClearGRFConfigList(GRFConfigList &config)
325{
326 config.clear();
327}
328
335 static void AppendGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only)
336{
337 for (const auto &s : src) {
338 auto &c = dst.emplace_back(std::make_unique<GRFConfig>(*s));
339 if (init_only) {
340 c->flags.Set(GRFConfigFlag::InitOnly);
341 } else {
342 c->flags.Reset(GRFConfigFlag::InitOnly);
343 }
344 }
345}
346
353 void CopyGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only)
354{
355 /* Clear destination as it will be overwritten */
356 ClearGRFConfigList(dst);
357 AppendGRFConfigList(dst, src, init_only);
358}
359
373 static void RemoveDuplicatesFromGRFConfigList(GRFConfigList &list)
374{
375 if (list.empty()) return;
376
377 auto last = std::end(list);
378 for (auto it = std::begin(list); it != last; ++it) {
379 auto remove = std::remove_if(std::next(it), last, [&grfid = (*it)->ident.grfid](const auto &c) { return grfid == c->ident.grfid; });
380 last = list.erase(remove, last);
381 }
382}
383
388 void AppendStaticGRFConfigs(GRFConfigList &dst)
389{
390 AppendGRFConfigList(dst, _grfconfig_static, false);
391 RemoveDuplicatesFromGRFConfigList(dst);
392}
393
399 void AppendToGRFConfigList(GRFConfigList &dst, std::unique_ptr<GRFConfig> &&el)
400{
401 dst.push_back(std::move(el));
402 RemoveDuplicatesFromGRFConfigList(dst);
403}
404
405
407 void ResetGRFConfig(bool defaults)
408{
409 CopyGRFConfigList(_grfconfig, _grfconfig_newgame, !defaults);
410 AppendStaticGRFConfigs(_grfconfig);
411}
412
413
425 GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig)
426{
427 GRFListCompatibility res = GLC_ALL_GOOD;
428
429 for (auto &c : grfconfig) {
430 const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, &c->ident.md5sum);
431 if (f == nullptr || f->flags.Test(GRFConfigFlag::Invalid)) {
432 /* If we have not found the exactly matching GRF try to find one with the
433 * same grfid, as it most likely is compatible */
434 f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE, nullptr, c->version);
435 if (f != nullptr) {
436 Debug(grf, 1, "NewGRF {:08X} ({}) not found; checksum {}. Compatibility mode on", std::byteswap(c->ident.grfid), c->filename, FormatArrayAsHex(c->ident.md5sum));
437 if (!c->flags.Test(GRFConfigFlag::Compatible)) {
438 /* Preserve original_md5sum after it has been assigned */
439 c->flags.Set(GRFConfigFlag::Compatible);
440 c->original_md5sum = c->ident.md5sum;
441 }
442
443 /* Non-found has precedence over compatibility load */
444 if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
445 goto compatible_grf;
446 }
447
448 /* No compatible grf was found, mark it as disabled */
449 Debug(grf, 0, "NewGRF {:08X} ({}) not found; checksum {}", std::byteswap(c->ident.grfid), c->filename, FormatArrayAsHex(c->ident.md5sum));
450
451 c->status = GCS_NOT_FOUND;
452 res = GLC_NOT_FOUND;
453 } else {
454compatible_grf:
455 Debug(grf, 1, "Loading GRF {:08X} from {}", std::byteswap(f->ident.grfid), f->filename);
456 /* The filename could be the filename as in the savegame. As we need
457 * to load the GRF here, we need the correct filename, so overwrite that
458 * in any case and set the name and info when it is not set already.
459 * When the GRFConfigFlag::Copy flag is set, it is certain that the filename is
460 * already a local one, so there is no need to replace it. */
461 if (!c->flags.Test(GRFConfigFlag::Copy)) {
462 c->filename = f->filename;
463 c->ident.md5sum = f->ident.md5sum;
464 c->name = f->name;
465 c->info = f->name;
466 c->errors.clear();
467 c->version = f->version;
468 c->min_loadable_version = f->min_loadable_version;
469 c->num_valid_params = f->num_valid_params;
470 c->param_info = f->param_info;
471 c->has_param_defaults = f->has_param_defaults;
472 }
473 }
474 }
475
476 return res;
477}
478
479
481 int _skip_all_newgrf_scanning = 0;
482
484 class GRFFileScanner : FileScanner {
485 std::chrono::steady_clock::time_point next_update;
486 uint num_scanned;
487
488public:
489 GRFFileScanner() : num_scanned(0)
490 {
491 this->next_update = std::chrono::steady_clock::now();
492 }
493
494 bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
495
497 static uint DoScan()
498 {
499 if (_skip_all_newgrf_scanning > 0) {
500 if (_skip_all_newgrf_scanning == 1) _skip_all_newgrf_scanning = 0;
501 return 0;
502 }
503
504 GRFFileScanner fs;
505 int ret = fs.Scan(".grf", NEWGRF_DIR);
506 /* The number scanned and the number returned may not be the same;
507 * duplicate NewGRFs and base sets are ignored in the return value. */
508 _settings_client.gui.last_newgrf_count = fs.num_scanned;
509 return ret;
510 }
511};
512
513 bool GRFFileScanner::AddFile(const std::string &filename, size_t basepath_length, const std::string &)
514{
515 /* Abort if the user stopped the game during a scan. */
516 if (_exit_game) return false;
517
518 bool added = false;
519 auto c = std::make_unique<GRFConfig>(filename.substr(basepath_length));
520 GRFConfig *grfconfig = c.get();
521 if (FillGRFDetails(*c, false)) {
522 if (std::ranges::none_of(_all_grfs, [&c](const auto &gc) { return c->ident.grfid == gc->ident.grfid && c->ident.md5sum == gc->ident.md5sum; })) {
523 _all_grfs.push_back(std::move(c));
524 added = true;
525 }
526 }
527
528 this->num_scanned++;
529
530 std::string name = grfconfig->GetName();
531 UpdateNewGRFScanStatus(this->num_scanned, std::move(name));
532 VideoDriver::GetInstance()->GameLoopPause();
533
534 return added;
535}
536
543 static bool GRFSorter(std::unique_ptr<GRFConfig> const &c1, std::unique_ptr<GRFConfig> const &c2)
544{
545 return StrNaturalCompare(c1->GetName(), c2->GetName()) < 0;
546}
547
552 void DoScanNewGRFFiles(NewGRFScanCallback *callback)
553{
554 ClearGRFConfigList(_all_grfs);
555 TarScanner::DoScan(TarScanner::Mode::NewGRF);
556
557 Debug(grf, 1, "Scanning for NewGRFs");
558 uint num = GRFFileScanner::DoScan();
559
560 Debug(grf, 1, "Scan complete, found {} files", num);
561 std::ranges::sort(_all_grfs, GRFSorter);
562 NetworkAfterNewGRFScan();
563
564 /* Yes... these are the NewGRF windows */
565 InvalidateWindowClassesData(WC_SAVELOAD, 0, true);
566 InvalidateWindowData(WC_GAME_OPTIONS, WN_GAME_OPTIONS_NEWGRF_STATE, GOID_NEWGRF_RESCANNED, true);
567 if (!_exit_game && callback != nullptr) callback->OnNewGRFsScanned();
568
569 CloseWindowByClass(WC_MODAL_PROGRESS);
570 SetModalProgress(false);
571 MarkWholeScreenDirty();
572}
573
578 void ScanNewGRFFiles(NewGRFScanCallback *callback)
579{
580 /* First set the modal progress. This ensures that it will eventually let go of the paint mutex. */
581 SetModalProgress(true);
582 /* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
583 MarkWholeScreenDirty();
584
585 DoScanNewGRFFiles(callback);
586}
587
596 const GRFConfig *FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
597{
598 assert((mode == FGCM_EXACT) != (md5sum == nullptr));
599 const GRFConfig *best = nullptr;
600 for (const auto &c : _all_grfs) {
601 /* if md5sum is set, we look for an exact match and continue if not found */
602 if (!c->ident.HasGrfIdentifier(grfid, md5sum)) continue;
603 /* return it, if the exact same newgrf is found, or if we do not care about finding "the best" */
604 if (md5sum != nullptr || mode == FGCM_ANY) return c.get();
605 /* Skip incompatible stuff, unless explicitly allowed */
606 if (mode != FGCM_NEWEST && c->flags.Test(GRFConfigFlag::Invalid)) continue;
607 /* check version compatibility */
608 if (mode == FGCM_COMPATIBLE && !c->IsCompatible(desired_version)) continue;
609 /* remember the newest one as "the best" */
610 if (best == nullptr || c->version > best->version) best = c.get();
611 }
612
613 return best;
614}
615
622 GRFConfig *GetGRFConfig(uint32_t grfid, uint32_t mask)
623{
624 auto it = std::ranges::find_if(_grfconfig, [grfid, mask](const auto &c) { return (c->ident.grfid & mask) == (grfid & mask); });
625 if (it != std::end(_grfconfig)) return it->get();
626
627 return nullptr;
628}
629
630
632std::string GRFBuildParamList(const GRFConfig &c)
633{
634 std::string result;
635 for (const uint32_t &value : c.param) {
636 if (!result.empty()) result += ' ';
637 format_append(result, "{}", value);
638 }
639 return result;
640}
641
647std::optional<std::string> GRFConfig::GetTextfile(TextfileType type) const
648{
649 return ::GetTextfile(type, NEWGRF_DIR, this->filename);
650}
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition bitmath_func.hpp:58
GB
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Reset
constexpr Timpl & Reset()
Reset all bits.
Definition base_bitset_type.hpp:83
FileHandle
Definition fileio_type.h:132
FileScanner
Helper for scanning for files with a given name.
Definition fileio_func.h:37
FileScanner::Scan
uint Scan(std::string_view extension, Subdirectory sd, bool tars=true, bool recursive=true)
Scan for files with the given extension in the given search path.
Definition fileio.cpp:1115
GRFFileScanner
Helper for scanning for files with GRF as extension.
Definition newgrf_config.cpp:484
GRFFileScanner::DoScan
static uint DoScan()
Do the scan for GRFs.
Definition newgrf_config.cpp:497
GRFFileScanner::next_update
std::chrono::steady_clock::time_point next_update
The next moment we do update the screen.
Definition newgrf_config.cpp:485
GRFFileScanner::AddFile
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override
Add a file with the given filename.
Definition newgrf_config.cpp:513
GRFFileScanner::num_scanned
uint num_scanned
The number of GRFs we have scanned.
Definition newgrf_config.cpp:486
TarScanner::Mode::NewGRF
@ NewGRF
Scan for non-base sets.
TarScanner::DoScan
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
Definition fileio.cpp:377
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition video_driver.hpp:192
VideoDriver::GameLoopPause
void GameLoopPause()
Pause the game-loop for a bit, releasing the game-state lock.
Definition video_driver.cpp:68
debug.h
Functions related to debugging.
Debug
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
FioFOpenFile
std::optional< FileHandle > FioFOpenFile(std::string_view filename, std::string_view mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
Definition fileio.cpp:242
FioCheckFileExists
bool FioCheckFileExists(std::string_view filename, Subdirectory subdir)
Check whether the given file exists.
Definition fileio.cpp:121
fileio_func.h
Functions for Standard In/Out file operations.
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition fileio_type.h:88
NEWGRF_DIR
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
Definition fileio_type.h:97
fios.h
Declarations for savegames operations.
gfx_func.h
Functions related to the gfx engine.
PaletteType
PaletteType
Palettes OpenTTD supports.
Definition gfx_type.h:351
PAL_DOS
@ PAL_DOS
Use the DOS palette.
Definition gfx_type.h:352
PAL_WINDOWS
@ PAL_WINDOWS
Use the Windows palette.
Definition gfx_type.h:353
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1546
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
network_func.h
Network functions used by other parts of OpenTTD.
NetworkAfterNewGRFScan
void NetworkAfterNewGRFScan()
Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new N...
Definition network_gamelist.cpp:80
LoadNewGRFFile
void LoadNewGRFFile(GRFConfig &config, GrfLoadingStage stage, Subdirectory subdir, bool temporary)
Load a particular NewGRF.
Definition newgrf.cpp:1391
newgrf.h
Base for the NewGRF implementation.
UpdateNewGRFConfigPalette
void UpdateNewGRFConfigPalette(int32_t)
Update the palettes of the graphics from the config file.
Definition newgrf_config.cpp:215
_grfconfig
GRFConfigList _grfconfig
First item in list of current GRF set up.
Definition newgrf_config.cpp:154
_grfconfig_static
GRFConfigList _grfconfig_static
First item in list of static GRF set up.
Definition newgrf_config.cpp:156
CopyGRFConfigList
void CopyGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only)
Copy a GRF Config list.
Definition newgrf_config.cpp:353
IsGoodGRFConfigList
GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig)
Check if all GRFs in the GRF config from a savegame can be loaded.
Definition newgrf_config.cpp:425
CalcGRFMD5Sum
static bool CalcGRFMD5Sum(GRFConfig &config, Subdirectory subdir)
Calculate the MD5 sum for a GRF, and store it in the config.
Definition newgrf_config.cpp:257
GRFBuildParamList
std::string GRFBuildParamList(const GRFConfig &c)
Build a string containing space separated parameter values, and terminate.
Definition newgrf_config.cpp:632
_missing_extra_graphics
uint _missing_extra_graphics
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
Definition newgrf_config.cpp:157
RemoveDuplicatesFromGRFConfigList
static void RemoveDuplicatesFromGRFConfigList(GRFConfigList &list)
Removes duplicates from lists of GRFConfigs.
Definition newgrf_config.cpp:373
FindGRFConfig
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
Definition newgrf_config.cpp:596
ResetGRFConfig
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
Definition newgrf_config.cpp:407
_grfconfig_newgame
GRFConfigList _grfconfig_newgame
First item in list of default GRF set up.
Definition newgrf_config.cpp:155
_all_grfs
GRFConfigList _all_grfs
First item in list of all scanned NewGRFs.
Definition newgrf_config.cpp:153
FillGRFDetails
bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
Definition newgrf_config.cpp:292
AppendGRFConfigList
static void AppendGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only)
Append a GRF Config list onto another list.
Definition newgrf_config.cpp:335
AppendStaticGRFConfigs
void AppendStaticGRFConfigs(GRFConfigList &dst)
Appends the static GRFs to a list of GRFs.
Definition newgrf_config.cpp:388
ScanNewGRFFiles
void ScanNewGRFFiles(NewGRFScanCallback *callback)
Scan for all NewGRFs.
Definition newgrf_config.cpp:578
GRFSorter
static bool GRFSorter(std::unique_ptr< GRFConfig > const &c1, std::unique_ptr< GRFConfig > const &c2)
Simple sorter for GRFS.
Definition newgrf_config.cpp:543
GetGRFConfig
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Definition newgrf_config.cpp:622
GRFGetSizeOfDataSection
size_t GRFGetSizeOfDataSection(FileHandle &f)
Get the data section size of a GRF.
Definition newgrf_config.cpp:227
DoScanNewGRFFiles
void DoScanNewGRFFiles(NewGRFScanCallback *callback)
Really perform the scan for all NewGRFs.
Definition newgrf_config.cpp:552
_skip_all_newgrf_scanning
int _skip_all_newgrf_scanning
Set this flag to prevent any NewGRF scanning from being done.
Definition newgrf_config.cpp:481
AppendToGRFConfigList
void AppendToGRFConfigList(GRFConfigList &dst, std::unique_ptr< GRFConfig > &&el)
Appends an element to a list of GRFs.
Definition newgrf_config.cpp:399
ClearGRFConfigList
void ClearGRFConfigList(GRFConfigList &config)
Clear a GRF Config list, freeing all nodes.
Definition newgrf_config.cpp:324
newgrf_config.h
Functions to find and configure NewGRFs.
GRFListCompatibility
GRFListCompatibility
Status of post-gameload GRF compatibility check.
Definition newgrf_config.h:52
GLC_COMPATIBLE
@ GLC_COMPATIBLE
Compatible (eg. the same ID, but different checksum) GRF found in at least one case.
Definition newgrf_config.h:54
GLC_ALL_GOOD
@ GLC_ALL_GOOD
All GRF needed by game are present.
Definition newgrf_config.h:53
GLC_NOT_FOUND
@ GLC_NOT_FOUND
At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
Definition newgrf_config.h:55
GCS_NOT_FOUND
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
Definition newgrf_config.h:36
InitOnly
@ InitOnly
GRF file is processed up to GLS_INIT.
Definition newgrf_config.h:26
System
@ System
GRF file is an openttd-internal system grf.
Definition newgrf_config.h:21
Copy
@ Copy
The data is copied from a grf in _all_grfs.
Definition newgrf_config.h:25
Compatible
@ Compatible
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
Definition newgrf_config.h:24
Unsafe
@ Unsafe
GRF file is unsafe for static usage.
Definition newgrf_config.h:22
Invalid
@ Invalid
GRF is unusable with this version of OpenTTD.
Definition newgrf_config.h:28
UpdateNewGRFScanStatus
void UpdateNewGRFScanStatus(uint num, std::string &&name)
Update the NewGRF scan status.
Definition newgrf_gui.cpp:2218
FindGRFConfigMode
FindGRFConfigMode
Method to find GRFs using FindGRFConfig.
Definition newgrf_config.h:207
FGCM_NEWEST
@ FGCM_NEWEST
Find newest Grf.
Definition newgrf_config.h:210
FGCM_ANY
@ FGCM_ANY
Use first found.
Definition newgrf_config.h:212
FGCM_EXACT
@ FGCM_EXACT
Only find Grfs matching md5sum.
Definition newgrf_config.h:208
FGCM_COMPATIBLE
@ FGCM_COMPATIBLE
Find best compatible Grf wrt. desired_version.
Definition newgrf_config.h:209
GRFP_USE_DOS
@ GRFP_USE_DOS
The palette state is set to use the DOS palette.
Definition newgrf_config.h:66
GRFP_GRF_WINDOWS
@ GRFP_GRF_WINDOWS
The NewGRF says the Windows palette can be used.
Definition newgrf_config.h:72
GRFP_USE_WINDOWS
@ GRFP_USE_WINDOWS
The palette state is set to use the Windows palette.
Definition newgrf_config.h:67
GRFP_GRF_DOS
@ GRFP_GRF_DOS
The NewGRF says the DOS palette can be used.
Definition newgrf_config.h:71
GRFP_USE_BIT
@ GRFP_USE_BIT
The bit used for storing the palette to use.
Definition newgrf_config.h:60
GRFP_GRF_MASK
@ GRFP_GRF_MASK
Bitmask to get only the NewGRF supplied information.
Definition newgrf_config.h:74
GetGRFStringFromGRFText
std::optional< std::string_view > GetGRFStringFromGRFText(const GRFTextList &text_list)
Get a C-string from a GRFText-list.
Definition newgrf_text.cpp:599
newgrf_text.h
Header of Action 04 "universal holder" structure and functions.
SetModalProgress
void SetModalProgress(bool state)
Set the modal progress state.
Definition progress.cpp:22
progress.h
Functions related to modal progress.
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
_grf_cont_v2_sig
const std::array< uint8_t, 8 > _grf_cont_v2_sig
Signature of a container version 2 GRF.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
FormatArrayAsHex
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Definition string.cpp:77
StrNaturalCompare
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition string.cpp:427
string_func.h
Functions related to low-level strings.
strings_func.h
Functions related to OTTD's strings.
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition newgrf_config.h:158
GRFConfig::SetParameterDefaults
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
Definition newgrf_config.cpp:114
GRFConfig::url
GRFTextWrapper url
NOSAVE: URL belonging to this GRF.
Definition newgrf_config.h:173
GRFConfig::palette
uint8_t palette
GRFPalette, bitset.
Definition newgrf_config.h:182
GRFConfig::info
GRFTextWrapper info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
Definition newgrf_config.h:172
GRFConfig::param_info
std::vector< std::optional< GRFParameterInfo > > param_info
NOSAVE: extra information about the parameters.
Definition newgrf_config.h:184
GRFConfig::version
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
Definition newgrf_config.h:176
GRFConfig::param
std::vector< uint32_t > param
GRF parameters.
Definition newgrf_config.h:185
GRFConfig::FinalizeParameterInfo
void FinalizeParameterInfo()
Finalize Action 14 info after file scan is finished.
Definition newgrf_config.cpp:145
GRFConfig::has_param_defaults
bool has_param_defaults
NOSAVE: did this newgrf specify any defaults for it's parameters.
Definition newgrf_config.h:183
GRFConfig::name
GRFTextWrapper name
NOSAVE: GRF name (Action 0x08)
Definition newgrf_config.h:171
GRFConfig::GetURL
std::optional< std::string > GetURL() const
Get the grf url.
Definition newgrf_config.cpp:106
GRFConfig::status
GRFStatus status
NOSAVE: GRFStatus, enum.
Definition newgrf_config.h:179
GRFConfig::SetValue
void SetValue(const GRFParameterInfo &info, uint32_t value)
Set the value of the given user-changeable parameter.
Definition newgrf_config.cpp:180
GRFConfig::IsCompatible
bool IsCompatible(uint32_t old_version) const
Return whether this NewGRF can replace an older version of the same NewGRF.
Definition newgrf_config.cpp:66
GRFConfig::CopyParams
void CopyParams(const GRFConfig &src)
Copy the parameter information from the src config.
Definition newgrf_config.cpp:75
GRFConfig::GetTextfile
std::optional< std::string > GetTextfile(TextfileType type) const
Search a textfile file next to this NewGRF.
Definition newgrf_config.cpp:647
GRFConfig::flags
GRFConfigFlags flags
NOSAVE: GCF_Flags, bitset.
Definition newgrf_config.h:178
GRFConfig::num_valid_params
uint8_t num_valid_params
NOSAVE: Number of valid parameters (action 0x14)
Definition newgrf_config.h:181
GRFConfig::filename
std::string filename
Filename - either with or without full path.
Definition newgrf_config.h:170
GRFConfig::ident
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
Definition newgrf_config.h:168
GRFConfig::SetSuitablePalette
void SetSuitablePalette()
Set the palette of this GRFConfig to something suitable.
Definition newgrf_config.cpp:131
GRFConfig::min_loadable_version
uint32_t min_loadable_version
NOSAVE: Minimum compatible version a NewGRF can define.
Definition newgrf_config.h:177
GRFConfig::GetName
std::string GetName() const
Get the name of this grf.
Definition newgrf_config.cpp:85
GRFConfig::GetDescription
std::optional< std::string > GetDescription() const
Get the grf info.
Definition newgrf_config.cpp:95
GRFConfig::GetValue
uint32_t GetValue(const GRFParameterInfo &info) const
Get the value of the given user-changeable parameter.
Definition newgrf_config.cpp:164
GRFIdentifier::grfid
uint32_t grfid
GRF ID (defined by Action 0x08)
Definition newgrf_config.h:84
GRFIdentifier::md5sum
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
Definition newgrf_config.h:85
GRFParameterInfo
Information about one grf parameter.
Definition newgrf_config.h:129
GRFParameterInfo::complete_labels
bool complete_labels
True if all values have a label.
Definition newgrf_config.h:149
GRFParameterInfo::param_nr
uint8_t param_nr
GRF parameter to store content in.
Definition newgrf_config.h:145
GRFParameterInfo::min_value
uint32_t min_value
The minimal value this parameter can have.
Definition newgrf_config.h:139
GRFParameterInfo::max_value
uint32_t max_value
The maximal value of this parameter.
Definition newgrf_config.h:140
GRFParameterInfo::value_names
std::vector< ValueName > value_names
Names for each value.
Definition newgrf_config.h:152
GRFParameterInfo::Finalize
void Finalize()
Finalize Action 14 info after file scan is finished.
Definition newgrf_config.cpp:200
GUISettings::last_newgrf_count
uint32_t last_newgrf_count
the numbers of NewGRFs we found during the last scan
Definition settings_type.h:227
GUISettings::newgrf_default_palette
uint8_t newgrf_default_palette
default palette to use for NewGRFs without action 14 palette information
Definition settings_type.h:256
NewGRFScanCallback
Callback for NewGRF scanning.
Definition newgrf_config.h:222
NewGRFScanCallback::OnNewGRFsScanned
virtual void OnNewGRFsScanned()=0
Called whenever the NewGRF scan completed.
textfile_gui.h
GUI functions related to textfiles.
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition textfile_type.h:14
thread.h
Base of all threads.
video_driver.hpp
Base of all video drivers.
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1205
InvalidateWindowData
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
Definition window.cpp:3294
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3176
InvalidateWindowClassesData
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition window.cpp:3311
window_func.h
Window functions not directly related to making/drawing windows.
WN_GAME_OPTIONS_NEWGRF_STATE
@ WN_GAME_OPTIONS_NEWGRF_STATE
NewGRF settings.
Definition window_type.h:30
GOID_NEWGRF_RESCANNED
@ GOID_NEWGRF_RESCANNED
NewGRFs were just rescanned.
Definition window_type.h:741
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition window_type.h:635
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition window_type.h:149
WC_MODAL_PROGRESS
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers:
Definition window_type.h:474