OpenTTD Source 20261112-master-gbcbec5e63f
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
9
10#include "stdafx.h"
11#include "debug.h"
12#include "3rdparty/md5/md5.h"
13#include "newgrf.h"
15#include "gfx_func.h"
16#include "newgrf_text.h"
17#include "window_func.h"
18#include "progress.h"
20#include "string_func.h"
21#include "textfile_gui.h"
22#include "newgrf_config.h"
23#include "newgrf_text.h"
24
25#include "fileio_func.h"
26
27#include "safeguards.h"
28
33GRFConfig::GRFConfig(const GRFConfig &config) :
34 ident(config.ident),
36 filename(config.filename),
37 name(config.name),
38 info(config.info),
39 url(config.url),
40 errors(config.errors),
41 version(config.version),
43 flags(config.flags),
44 status(config.status),
45 grf_bugs(config.grf_bugs),
47 palette(config.palette),
49 param_info(config.param_info),
50 param(config.param)
51{
52 this->flags.Reset(GRFConfigFlag::Copy);
53}
54
55void GRFConfig::SetParams(std::span<const uint32_t> pars)
56{
57 this->param.assign(std::begin(pars), std::end(pars));
58}
59
65bool GRFConfig::IsCompatible(uint32_t old_version) const
66{
67 return this->min_loadable_version <= old_version && old_version <= this->version;
68}
69
74void GRFConfig::CopyParams(const GRFConfig &src)
75{
76 this->param = src.param;
77}
78
84std::string GRFConfig::GetName() const
85{
86 auto name = GetGRFStringFromGRFText(this->name);
87 return name.has_value() && !name->empty() ? std::string(*name) : this->filename;
88}
89
94std::optional<std::string> GRFConfig::GetDescription() const
95{
96 auto str = GetGRFStringFromGRFText(this->info);
97 if (!str.has_value()) return std::nullopt;
98 return std::string(*str);
99}
100
105std::optional<std::string> GRFConfig::GetURL() const
106{
107 auto str = GetGRFStringFromGRFText(this->url);
108 if (!str.has_value()) return std::nullopt;
109 return std::string(*str);
110}
111
114{
115 this->param.clear();
116
117 if (!this->has_param_defaults) return;
118
119 for (const auto &info : this->param_info) {
120 if (!info.has_value()) continue;
121 this->SetValue(info.value(), info->def_value);
122 }
123}
124
131{
132 PaletteType pal;
133 switch (this->palette & GRFP_GRF_MASK) {
134 case GRFP_GRF_DOS: pal = PaletteType::DOS; break;
135 case GRFP_GRF_WINDOWS: pal = PaletteType::Windows; break;
136 default: pal = _settings_client.gui.newgrf_default_palette == 1 ? PaletteType::Windows : PaletteType::DOS; break;
137 }
139}
140
145{
146 for (auto &info : this->param_info) {
147 if (!info.has_value()) continue;
148 info->Finalize();
149 }
150}
151
152GRFConfigList _all_grfs;
153GRFConfigList _grfconfig;
154GRFConfigList _grfconfig_newgame;
155GRFConfigList _grfconfig_static;
157
164{
165 /* If the parameter is not set then it must be 0. */
166 if (info.param_nr >= std::size(this->param)) return 0;
167
168 /* GB doesn't work correctly with nbits == 32, so handle that case here. */
169 if (info.num_bit == 32) return this->param[info.param_nr];
170
171 return GB(this->param[info.param_nr], info.first_bit, info.num_bit);
172}
173
179void GRFConfig::SetValue(const GRFParameterInfo &info, uint32_t value)
180{
181 value = Clamp(value, info.min_value, info.max_value);
182
183 /* Allocate the new parameter if it's not already present. */
184 if (info.param_nr >= std::size(this->param)) this->param.resize(info.param_nr + 1);
185
186 /* SB doesn't work correctly with nbits == 32, so handle that case here. */
187 if (info.num_bit == 32) {
188 this->param[info.param_nr] = value;
189 } else {
190 SB(this->param[info.param_nr], info.first_bit, info.num_bit, value);
191 }
192
193 SetWindowDirty(WindowClass::GameOptions, GameOptionsWindowNumber::NewGRFState);
194}
195
200{
201 /* Remove value names outside of the permitted range of values. */
202 auto it = std::remove_if(std::begin(this->value_names), std::end(this->value_names),
203 [this](const ValueName &vn) { return vn.first < this->min_value || vn.first > this->max_value; });
204 this->value_names.erase(it, std::end(this->value_names));
205
206 /* Test if the number of named values matches the full ranges of values. -1 because the range is inclusive. */
207 this->complete_labels = (this->max_value - this->min_value) == std::size(this->value_names) - 1;
208}
209
215{
216 for (const auto &c : _grfconfig_newgame) c->SetSuitablePalette();
217 for (const auto &c : _grfconfig_static ) c->SetSuitablePalette();
218 for (const auto &c : _all_grfs ) c->SetSuitablePalette();
219}
220
227{
228 extern const std::array<uint8_t, 8> _grf_cont_v2_sig;
229 static const uint header_len = 14;
230
231 uint8_t data[header_len];
232 if (fread(data, 1, header_len, f) == header_len) {
233 if (data[0] == 0 && data[1] == 0 && std::ranges::equal(std::span(data + 2, _grf_cont_v2_sig.size()), _grf_cont_v2_sig)) {
234 /* Valid container version 2, get data section size. */
235 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]);
236 if (offset >= 1 * 1024 * 1024 * 1024) {
237 Debug(Facility::Grf, Severity::Critical, "Unexpectedly large offset for NewGRF");
238 /* Having more than 1 GiB of data is very implausible. Mostly because then
239 * all pools in OpenTTD are flooded already. Or it's just Action C all over.
240 * In any case, the offsets to graphics will likely not work either. */
241 return SIZE_MAX;
242 }
243 return header_len + offset;
244 }
245 }
246
247 return SIZE_MAX;
248}
249
256static bool CalcGRFMD5Sum(GRFConfig &config, Subdirectory subdir)
257{
258 Md5 checksum;
259 uint8_t buffer[1024];
260 size_t len, size;
261
262 /* open the file */
263 auto f = FioFOpenFile(config.filename, "rb", subdir, &size);
264 if (!f.has_value()) return false;
265
266 long start = ftell(*f);
267 size = std::min(size, GRFGetSizeOfDataSection(*f));
268
269 if (start < 0 || fseek(*f, start, SEEK_SET) < 0) {
270 return false;
271 }
272
273 /* calculate md5sum */
274 while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, *f)) != 0 && size != 0) {
275 size -= len;
276 checksum.Append(buffer, len);
277 }
278 checksum.Finish(config.ident.md5sum);
279
280 return true;
281}
282
283
291bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir)
292{
293 if (!FioCheckFileExists(config.filename, subdir)) {
295 return false;
296 }
297
298 /* Find and load the Action 8 information */
299 LoadNewGRFFile(config, GrfLoadingStage::FileScan, subdir, true);
300 config.SetSuitablePalette();
301 config.FinalizeParameterInfo();
302
303 /* Skip if the grfid is 0 (not read) or if it is an internal GRF */
304 if (config.ident.grfid.Empty() || config.flags.Test(GRFConfigFlag::System)) return false;
305
306 if (is_static) {
307 /* Perform a 'safety scan' for static GRFs */
308 LoadNewGRFFile(config, GrfLoadingStage::SafetyScan, subdir, true);
309
310 /* GRFConfigFlag::Unsafe is set if GrfLoadingStage::SafetyScan finds unsafe actions */
311 if (config.flags.Test(GRFConfigFlag::Unsafe)) return false;
312 }
313
314 return CalcGRFMD5Sum(config, subdir);
315}
316
317
323void ClearGRFConfigList(GRFConfigList &config)
324{
325 config.clear();
326}
327
334static void AppendGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only)
335{
336 for (const auto &s : src) {
337 auto &c = dst.emplace_back(std::make_unique<GRFConfig>(*s));
338 if (init_only) {
339 c->flags.Set(GRFConfigFlag::InitOnly);
340 } else {
341 c->flags.Reset(GRFConfigFlag::InitOnly);
342 }
343 }
344}
345
352void CopyGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only)
353{
354 /* Clear destination as it will be overwritten */
356 AppendGRFConfigList(dst, src, init_only);
357}
358
372static void RemoveDuplicatesFromGRFConfigList(GRFConfigList &list)
373{
374 if (list.empty()) return;
375
376 auto last = std::end(list);
377 for (auto it = std::begin(list); it != last; ++it) {
378 auto remove = std::remove_if(std::next(it), last, [&grfid = (*it)->ident.grfid](const auto &c) { return grfid == c->ident.grfid; });
379 last = list.erase(remove, last);
380 }
381}
382
387void AppendStaticGRFConfigs(GRFConfigList &dst)
388{
391}
392
398void AppendToGRFConfigList(GRFConfigList &dst, std::unique_ptr<GRFConfig> &&el)
399{
400 dst.push_back(std::move(el));
402}
403
404
414
415
428{
430
431 for (auto &c : grfconfig) {
432 const GRFConfig *f = FindGRFConfig(c->ident.grfid, FindGRFConfigMode::Exact, &c->ident.md5sum);
433 if (f == nullptr || f->flags.Test(GRFConfigFlag::Invalid)) {
434 /* If we have not found the exactly matching GRF try to find one with the
435 * same grfid, as it most likely is compatible */
436 f = FindGRFConfig(c->ident.grfid, FindGRFConfigMode::Compatible, nullptr, c->version);
437 if (f != nullptr) {
438 Debug(Facility::Grf, Severity::Error, "NewGRF {} ({}) not found; checksum {}. Compatibility mode on", FormatArrayAsHex(c->ident.grfid), c->filename, FormatArrayAsHex(c->ident.md5sum));
439 if (!c->flags.Test(GRFConfigFlag::Compatible)) {
440 /* Preserve original_md5sum after it has been assigned */
441 c->flags.Set(GRFConfigFlag::Compatible);
442 c->original_md5sum = c->ident.md5sum;
443 }
444
445 /* Non-found has precedence over compatibility load */
447 goto compatible_grf;
448 }
449
450 /* No compatible grf was found, mark it as disabled */
451 Debug(Facility::Grf, Severity::Critical, "NewGRF {} ({}) not found; checksum {}", FormatArrayAsHex(c->ident.grfid), c->filename, FormatArrayAsHex(c->ident.md5sum));
452
453 c->status = GRFStatus::NotFound;
455 } else {
456compatible_grf:
457 Debug(Facility::Grf, Severity::Error, "Loading GRF {} from {}", FormatArrayAsHex(f->ident.grfid), f->filename);
458 /* The filename could be the filename as in the savegame. As we need
459 * to load the GRF here, we need the correct filename, so overwrite that
460 * in any case and set the name and info when it is not set already.
461 * When the GRFConfigFlag::Copy flag is set, it is certain that the filename is
462 * already a local one, so there is no need to replace it. */
463 if (!c->flags.Test(GRFConfigFlag::Copy)) {
464 c->filename = f->filename;
465 c->ident.md5sum = f->ident.md5sum;
466 c->name = f->name;
467 c->info = f->name;
468 c->errors.clear();
469 c->version = f->version;
470 c->min_loadable_version = f->min_loadable_version;
471 c->num_valid_params = f->num_valid_params;
472 c->param_info = f->param_info;
473 c->has_param_defaults = f->has_param_defaults;
474 }
475 }
476 }
477
478 return res;
479}
480
481
484
486class GRFFileScanner : FileScanner {
487 std::chrono::steady_clock::time_point next_update;
489
490public:
491 GRFFileScanner() : num_scanned(0)
492 {
493 this->next_update = std::chrono::steady_clock::now();
494 }
495
496 bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override;
497
502 static uint DoScan()
503 {
506 return 0;
507 }
508
509 GRFFileScanner fs;
510 int ret = fs.Scan(".grf", Subdirectory::NewGrf);
511 /* The number scanned and the number returned may not be the same;
512 * duplicate NewGRFs and base sets are ignored in the return value. */
513 _settings_client.gui.last_newgrf_count = fs.num_scanned;
514 return ret;
515 }
516};
517
518bool GRFFileScanner::AddFile(const std::string &filename, size_t basepath_length, const std::string &)
519{
520 /* Abort if the user stopped the game during a scan. */
521 if (_exit_game) return false;
522
523 bool added = false;
524 auto c = std::make_unique<GRFConfig>(filename.substr(basepath_length));
525 GRFConfig *grfconfig = c.get();
526 if (FillGRFDetails(*c, false)) {
527 if (std::ranges::none_of(_all_grfs, [&c](const auto &gc) { return c->ident.grfid == gc->ident.grfid && c->ident.md5sum == gc->ident.md5sum; })) {
528 _all_grfs.push_back(std::move(c));
529 added = true;
530 }
531 }
532
533 this->num_scanned++;
534
535 std::string name = grfconfig->GetName();
536 UpdateNewGRFScanStatus(this->num_scanned, std::move(name));
538
539 return added;
540}
541
544static bool GRFSorter(std::unique_ptr<GRFConfig> const &a, std::unique_ptr<GRFConfig> const &b)
545{
546 return StrNaturalCompare(a->GetName(), b->GetName()) < 0;
547}
548
554{
557
558 Debug(Facility::Grf, Severity::Error, "Scanning for NewGRFs");
559 uint num = GRFFileScanner::DoScan();
560
561 Debug(Facility::Grf, Severity::Error, "Scan complete, found {} files", num);
562 std::ranges::sort(_all_grfs, GRFSorter);
564
565 /* Yes... these are the NewGRF windows */
566 InvalidateWindowClassesData(WindowClass::SaveLoad, 0, true);
568 if (!_exit_game && callback != nullptr) callback->OnNewGRFsScanned();
569
570 CloseWindowByClass(WindowClass::ModalProgress);
571 SetModalProgress(false);
573}
574
580{
581 /* First set the modal progress. This ensures that it will eventually let go of the paint mutex. */
582 SetModalProgress(true);
583 /* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
585
586 DoScanNewGRFFiles(callback);
587}
588
597const GRFConfig *FindGRFConfig(GrfID grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
598{
599 assert((mode == FindGRFConfigMode::Exact) != (md5sum == nullptr));
600 const GRFConfig *best = nullptr;
601 for (const auto &c : _all_grfs) {
602 /* if md5sum is set, we look for an exact match and continue if not found */
603 if (!c->ident.HasGrfIdentifier(grfid, md5sum)) continue;
604 /* return it, if the exact same newgrf is found, or if we do not care about finding "the best" */
605 if (md5sum != nullptr || mode == FindGRFConfigMode::Any) return c.get();
606 /* Skip incompatible stuff, unless explicitly allowed */
607 if (mode != FindGRFConfigMode::Newest && c->flags.Test(GRFConfigFlag::Invalid)) continue;
608 /* check version compatibility */
609 if (mode == FindGRFConfigMode::Compatible && !c->IsCompatible(desired_version)) continue;
610 /* remember the newest one as "the best" */
611 if (best == nullptr || c->version > best->version) best = c.get();
612 }
613
614 return best;
615}
616
623GRFConfig *GetGRFConfig(GrfID grfid, uint32_t mask)
624{
625 auto it = std::ranges::find_if(_grfconfig, [grfid, mask](const auto &c) { return (FlattenNewGRFLabel(c->ident.grfid) & mask) == (FlattenNewGRFLabel(grfid) & mask); });
626 if (it != std::end(_grfconfig)) return it->get();
627
628 return nullptr;
629}
630
631
637std::string GRFBuildParamList(const GRFConfig &c)
638{
639 std::string result;
640 for (const uint32_t &value : c.param) {
641 if (!result.empty()) result += ' ';
642 format_append(result, "{}", value);
643 }
644 return result;
645}
646
652std::optional<std::string> GRFConfig::GetTextfile(TextfileType type) const
653{
654 return ::GetTextfile(type, Subdirectory::NewGrf, this->filename);
655}
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.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Helper for scanning for files with a given name.
Definition fileio_func.h:37
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:1169
static uint DoScan()
Do the scan for GRFs.
std::chrono::steady_clock::time_point next_update
The next moment we do update the screen.
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override
Add a file with the given filename.
uint num_scanned
The number of GRFs we have scanned.
@ NewGRF
Scan for non-base sets.
Definition fileio_func.h:65
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
Definition fileio.cpp:382
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
void GameLoopPause()
Pause the game-loop for a bit, releasing the game-state lock.
Functions related to debugging.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
Definition debug.h:36
@ Grf
Grf message facility.
Definition debug_type.h:30
@ Critical
Critical, user should know about this.
Definition debug_type.h:15
@ Error
Error, but we are recovering.
Definition debug_type.h:16
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:248
bool FioCheckFileExists(std::string_view filename, Subdirectory subdir)
Check whether the given file exists.
Definition fileio.cpp:122
Functions for standard in/out file operations.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition fileio_type.h:87
@ NewGrf
Subdirectory for all NewGRFs.
Definition fileio_type.h:96
Functions related to the gfx engine.
PaletteType
Palettes OpenTTD supports.
Definition gfx_type.h:398
@ DOS
Use the DOS palette.
Definition gfx_type.h:399
@ Windows
Use the Windows palette.
Definition gfx_type.h:400
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1548
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
Network functions used by other parts of OpenTTD.
void NetworkAfterNewGRFScan()
Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new N...
void LoadNewGRFFile(GRFConfig &config, GrfLoadingStage stage, Subdirectory subdir, bool temporary)
Load a particular NewGRF.
Definition newgrf.cpp:1394
Base for the NewGRF implementation.
constexpr uint32_t FlattenNewGRFLabel(T label)
Flatten a NewGRF related label to a 32 bits integer.
Definition newgrf.h:262
@ SafetyScan
Checks whether the NewGRF can be used in a static context.
Definition newgrf.h:59
@ FileScan
Load the Action 8 metadata (GRF ID, name).
Definition newgrf.h:58
GRFConfigList _grfconfig
First item in list of current GRF set up.
GRFConfigList _grfconfig_static
First item in list of static GRF set up.
void CopyGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only)
Copy a GRF Config list.
GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig)
Check if all GRFs in the GRF config from a savegame can be loaded.
static bool CalcGRFMD5Sum(GRFConfig &config, Subdirectory subdir)
Calculate the MD5 sum for a GRF, and store it in the config.
std::string GRFBuildParamList(const GRFConfig &c)
Build a string containing space separated parameter values.
static bool GRFSorter(std::unique_ptr< GRFConfig > const &a, std::unique_ptr< GRFConfig > const &b)
Simple sorter for GRFS.
uint _missing_extra_graphics
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
static void RemoveDuplicatesFromGRFConfigList(GRFConfigList &list)
Removes duplicates from lists of GRFConfigs.
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
GRFConfigList _grfconfig_newgame
First item in list of default GRF set up.
GRFConfigList _all_grfs
First item in list of all scanned NewGRFs.
bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
static void AppendGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bool init_only)
Append a GRF Config list onto another list.
GRFConfig * GetGRFConfig(GrfID grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
void AppendStaticGRFConfigs(GRFConfigList &dst)
Appends the static GRFs to a list of GRFs.
const GRFConfig * FindGRFConfig(GrfID grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
void ScanNewGRFFiles(NewGRFScanCallback *callback)
Scan for all NewGRFs.
size_t GRFGetSizeOfDataSection(FileHandle &f)
Get the data section size of a GRF.
void DoScanNewGRFFiles(NewGRFScanCallback *callback)
Really perform the scan for all NewGRFs.
int _skip_all_newgrf_scanning
Set this flag to prevent any NewGRF scanning from being done.
void AppendToGRFConfigList(GRFConfigList &dst, std::unique_ptr< GRFConfig > &&el)
Appends an element to a list of GRFs.
void UpdateNewGRFConfigPalette()
Update the palettes of the graphics from the config file.
void ClearGRFConfigList(GRFConfigList &config)
Clear a GRF Config list, freeing all nodes.
Functions to find and configure NewGRFs.
GRFListCompatibility
Status of post-gameload GRF compatibility check.
@ NotFound
At least one GRF couldn't be found (higher priority than GRFListCompatibility::Compatible).
@ AllGood
All GRF needed by game are present.
@ Compatible
Compatible (eg. the same ID, but different checksum) GRF found in at least one case.
@ NotFound
GRF file was not found in the local cache.
@ Invalid
GRF is unusable with this version of OpenTTD.
@ Copy
The data is copied from a grf in _all_grfs.
@ Compatible
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches).
@ System
GRF file is an openttd-internal system grf.
@ Unsafe
GRF file is unsafe for static usage.
@ InitOnly
GRF file is processed up to GrfLoadingStage::Init.
void UpdateNewGRFScanStatus(uint num, std::string &&name)
Update the NewGRF scan status.
FindGRFConfigMode
Method to find GRFs using FindGRFConfig.
@ Exact
Only find Grfs matching md5sum.
@ Compatible
Find best compatible Grf wrt. desired_version.
@ Newest
Find newest Grf.
@ Any
Use first found.
@ GRFP_USE_DOS
The palette state is set to use the DOS palette.
@ GRFP_GRF_WINDOWS
The NewGRF says the Windows palette can be used.
@ GRFP_USE_WINDOWS
The palette state is set to use the Windows palette.
@ GRFP_GRF_DOS
The NewGRF says the DOS palette can be used.
@ GRFP_USE_BIT
The bit used for storing the palette to use.
@ GRFP_GRF_MASK
Bitmask to get only the NewGRF supplied information.
std::optional< std::string_view > GetGRFStringFromGRFText(const GRFTextList &text_list)
Get a C-string from a GRFText-list.
Header of Action 04 "universal holder" structure and functions.
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
Definition newgrf_type.h:17
void SetModalProgress(bool state)
Set the modal progress state.
Definition progress.cpp:22
Functions related to modal progress.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
const std::array< uint8_t, 8 > _grf_cont_v2_sig
Signature of a container version 2 GRF.
Definition of base types and functions in a cross-platform compatible way.
std::string FormatArrayAsHex(std::span< const uint8_t > data)
Format a byte array into a continuous hex string.
Definition string.cpp:76
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:428
Functions related to low-level strings.
constexpr bool Empty() const
Check whether the label is empty.
Information about GRF, used in the game and (part of it) in savegames.
MD5Hash original_md5sum
MD5 checksum of original file if only a 'compatible' file was loaded.
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
GRFTextWrapper url
NOSAVE: URL belonging to this GRF.
uint8_t palette
GRFPalette, bitset.
GRFTextWrapper info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08).
std::vector< std::optional< GRFParameterInfo > > param_info
NOSAVE: extra information about the parameters.
std::vector< GRFError > errors
NOSAVE: Error/Warning during GRF loading (Action 0x0B).
uint32_t version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
std::vector< uint32_t > param
GRF parameters.
void FinalizeParameterInfo()
Finalize Action 14 info after file scan is finished.
bool has_param_defaults
NOSAVE: did this newgrf specify any defaults for it's parameters.
GRFTextWrapper name
NOSAVE: GRF name (Action 0x08).
GRFBugs grf_bugs
NOSAVE: bugs in this GRF in this run,.
std::optional< std::string > GetURL() const
Get the grf url.
GRFStatus status
NOSAVE: GRFStatus, enum.
void SetValue(const GRFParameterInfo &info, uint32_t value)
Set the value of the given user-changeable parameter.
bool IsCompatible(uint32_t old_version) const
Return whether this NewGRF can replace an older version of the same NewGRF.
void CopyParams(const GRFConfig &src)
Copy the parameter information from the src config.
std::optional< std::string > GetTextfile(TextfileType type) const
Search a textfile file next to this NewGRF.
GRFConfigFlags flags
NOSAVE: GCF_Flags, bitset.
uint8_t num_valid_params
NOSAVE: Number of valid parameters (action 0x14).
std::string filename
Filename - either with or without full path.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
void SetSuitablePalette()
Set the palette of this GRFConfig to something suitable.
uint32_t min_loadable_version
NOSAVE: Minimum compatible version a NewGRF can define.
std::string GetName() const
Get the name of this grf.
std::optional< std::string > GetDescription() const
Get the grf info.
uint32_t GetValue(const GRFParameterInfo &info) const
Get the value of the given user-changeable parameter.
GrfID grfid
GRF ID (defined by Action 0x08).
MD5Hash md5sum
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF).
Information about one grf parameter.
bool complete_labels
True if all values have a label.
uint32_t min_value
The minimal value this parameter can have.
uint32_t max_value
The maximal value of this parameter.
std::vector< ValueName > value_names
Names for each value.
void Finalize()
Finalize Action 14 info after file scan is finished.
Callback for NewGRF scanning.
virtual void OnNewGRFsScanned()=0
Called whenever the NewGRF scan completed.
GUI functions related to textfiles.
TextfileType
Additional text files accompanying Tar archives.
Base of all video drivers.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1255
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:3377
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Definition window.cpp:3255
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:3395
Window functions not directly related to making/drawing windows.
@ GOID_NEWGRF_RESCANNED
NewGRFs were just rescanned.
@ NewGRFState
NewGRF settings.
Definition window_type.h:31