OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
12 #include "3rdparty/md5/md5.h"
53 version(config.version),
54 min_loadable_version(config.min_loadable_version),
55 flags(config.flags & ~(1 <<
GCF_COPY)),
56 status(config.status),
57 grf_bugs(config.grf_bugs),
58 num_params(config.num_params),
59 num_valid_params(config.num_valid_params),
60 palette(config.palette),
61 has_param_defaults(config.has_param_defaults)
67 for (uint i = 0; i < config.
param_info.size(); i++) {
136 for (uint i = 0; i < this->
param_info.size(); i++) {
164 if (
info ==
nullptr)
continue;
192 custom_message(
error.custom_message),
194 message(
error.message),
195 severity(
error.severity)
209 max_value(UINT32_MAX),
215 complete_labels(false)
227 min_value(info.min_value),
228 max_value(info.max_value),
229 def_value(info.def_value),
230 param_nr(info.param_nr),
231 first_bit(info.first_bit),
232 num_bit(info.num_bit),
233 value_names(info.value_names),
234 complete_labels(info.complete_labels)
247 return GB(config->
param[this->param_nr], this->first_bit, this->num_bit);
261 SB(config->
param[this->param_nr], this->first_bit, this->num_bit, value);
303 static const uint header_len = 14;
305 byte data[header_len];
306 if (fread(data, 1, header_len, f) == header_len) {
309 size_t offset = ((size_t)data[13] << 24) | ((size_t)data[12] << 16) | ((size_t)data[11] << 8) | (size_t)data[10];
310 if (offset >= 1 * 1024 * 1024 * 1024) {
311 DEBUG(grf, 0,
"Unexpectedly large offset for NewGRF");
317 return header_len + offset;
339 if (f ==
nullptr)
return false;
341 long start = ftell(f);
344 if (start < 0 || fseek(f, start, SEEK_SET) < 0) {
350 while ((len = fread(buffer, 1, (size >
sizeof(buffer)) ?
sizeof(buffer) : size, f)) != 0 && size != 0) {
352 checksum.Append(buffer, len);
404 for (c = *config; c !=
nullptr; c = next) {
423 for (; src !=
nullptr; src = src->
next) {
454 if (list ==
nullptr)
return;
456 for (prev = list, cur = list->
next; cur !=
nullptr; prev = cur, cur = cur->
next) {
474 while (*tail !=
nullptr) tail = &(*tail)->
next;
488 while (*tail !=
nullptr) tail = &(*tail)->
next;
528 DEBUG(grf, 1,
"NewGRF %08X (%s) not found; checksum %s. Compatibility mode on",
BSWAP32(c->ident.grfid), c->filename, buf);
532 memcpy(c->original_md5sum, c->ident.md5sum,
sizeof(c->original_md5sum));
542 DEBUG(grf, 0,
"NewGRF %08X (%s) not found; checksum %s",
BSWAP32(c->ident.grfid), c->filename, buf);
557 memcpy(c->ident.md5sum, f->
ident.
md5sum,
sizeof(c->ident.md5sum));
565 for (uint i = 0; i < f->
param_info.size(); i++) {
567 c->param_info.push_back(
nullptr);
587 this->next_update = std::chrono::steady_clock::now();
590 bool AddFile(
const std::string &filename,
size_t basepath_length,
const std::string &tar_filename)
override;
638 if (std::chrono::steady_clock::now() >= this->
next_update) {
644 const char *name =
nullptr;
646 if (name ==
nullptr) name = c->
filename;
684 DEBUG(grf, 1,
"Scanning for NewGRFs");
687 DEBUG(grf, 1,
"Scan complete, found %d files", num);
692 std::vector<GRFConfig *> to_sort;
696 to_sort.push_back(p);
701 std::sort(to_sort.begin(), to_sort.end(),
GRFSorter);
703 for (i = 1; i < num; i++) {
704 to_sort[i - 1]->next = to_sort[i];
706 to_sort[num - 1]->next =
nullptr;
757 assert((mode ==
FGCM_EXACT) != (md5sum ==
nullptr));
761 if (!c->ident.HasGrfIdentifier(grfid, md5sum))
continue;
763 if (md5sum !=
nullptr || mode ==
FGCM_ANY)
return c;
767 if (mode ==
FGCM_COMPATIBLE && (c->version < desired_version || c->min_loadable_version > desired_version))
continue;
804 static std::vector<UnknownGRF> unknown_grfs;
806 for (
const auto &grf : unknown_grfs) {
807 if (grf.grfid == grfid) {
808 if (memcmp(md5sum, grf.md5sum,
sizeof(grf.md5sum)) == 0)
return grf.name;
812 if (!create)
return nullptr;
814 unknown_grfs.emplace_back(grfid, md5sum);
833 if ((c->
ident.
grfid & mask) == (grfid & mask))
return c;
849 if (i > 0) dst =
strecpy(dst,
" ", last);
uint32 version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
void SetSuitablePalette()
Set the palette of this GRFConfig to something suitable.
@ WC_SAVELOAD
Saveload window; Window numbers:
uint8 num_valid_params
NOSAVE: Number of valid parameters (action 0x14)
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-...
GRFTextWrapper info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
@ PAL_DOS
Use the DOS palette.
GRFError * error
NOSAVE: Error/Warning during GRF loading (Action 0x0B)
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
std::vector< GRFText > GRFTextList
A GRF text with a list of translations.
static const uint MODAL_PROGRESS_REDRAW_TIMEOUT
Timeout between redraws.
std::mutex _modal_progress_paint_mutex
Rights for the painting.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
@ GLC_COMPATIBLE
Compatible (eg. the same ID, but different checksum) GRF found in at least one case.
GRFTextWrapper name
Name of the GRF.
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
uint8 num_params
Number of used parameters.
void DoScanNewGRFFiles(NewGRFScanCallback *callback)
Really perform the scan for all NewGRFs.
GRFConfig * _all_grfs
First item in list of all scanned NewGRFs.
static bool GRFSorter(GRFConfig *const &c1, GRFConfig *const &c2)
Simple sorter for GRFS.
const byte _grf_cont_v2_sig[8]
Signature of a container version 2 GRF.
PaletteType
Palettes OpenTTD supports.
uint Scan(const char *extension, Subdirectory sd, bool tars=true, bool recursive=true)
Scan for files with the given extension in the given search path.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
void SetValue(struct GRFConfig *config, uint32 value)
Set the value of this user-changeable parameter in the given config.
@ FGCM_COMPATIBLE
Find best compatible Grf wrt. desired_version.
byte param_nr
GRF parameter to store content in.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
uint8 newgrf_default_palette
default palette to use for NewGRFs without action 14 palette information
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
ClientSettings _settings_client
The current settings for this game.
@ GCF_COPY
The data is copied from a grf in _all_grfs.
GRFStatus status
NOSAVE: GRFStatus, enum.
static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID
Base GRF ID for OpenTTD's base graphics GRFs.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
@ GRFP_USE_BIT
The bit used for storing the palette to use.
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
@ WN_GAME_OPTIONS_NEWGRF_STATE
NewGRF settings.
uint32 grfid
GRF ID (defined by Action 0x08)
uint32 GetValue(struct GRFConfig *config) const
Get the value of this user-changeable parameter from the given config.
@ GCF_COMPATIBLE
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
byte num_bit
Number of bits to use for this parameter.
void UpdateNewGRFScanStatus(uint num, const char *name)
Update the NewGRF scan status.
@ GCF_INVALID
GRF is unusable with this version of OpenTTD.
@ GCF_INIT_ONLY
GRF file is processed up to GLS_INIT.
bool UpdateNewGRFConfigPalette(int32 p1)
Update the palettes of the graphics from the config file.
char * GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
Build a string containing space separated parameter values, and terminate.
@ FGCM_ANY
Use first found.
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers:
Basic data to distinguish a GRF.
@ GRFP_GRF_DOS
The NewGRF says the DOS palette can be used.
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
Check if all GRFs in the GRF config from a savegame can be loaded.
Structure for UnknownGRFs; this is a lightweight variant of GRFConfig.
@ GCF_UNSAFE
GRF file is unsafe for static usage.
Information about GRF, used in the game and (part of it) in savegames.
GRFError(StringID severity, StringID message=0)
Construct a new GRFError.
@ GCF_SYSTEM
GRF file is an openttd-internal system grf.
@ GRFP_USE_DOS
The palette state is set to use the DOS palette.
#define DEBUG(name, level,...)
Output a line of debugging information.
@ CONFIG_SLOT
Slot used for the GRF scanning and such.
FILE * FioFOpenFile(const std::string &filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
uint8 flags
NOSAVE: GCF_Flags, bitset.
@ GRFP_USE_WINDOWS
The palette state is set to use the Windows palette.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
uint _missing_extra_graphics
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
Base class that provides memory initialization on dynamically created objects.
GRFConfig ** CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only)
Copy a GRF Config list.
const char * GetGRFStringFromGRFText(const GRFTextList &text_list)
Get a C-string from a GRFText-list.
Helper for scanning for files with GRF as extension.
#define UNKNOWN_GRF_NAME_PLACEHOLDER
For communication about GRFs over the network.
bool StartNewThread(std::thread *thr, const char *name, TFn &&_Fx, TArgs &&... _Ax)
Start a new thread.
const char * GetTextfile(TextfileType type) const
Search a textfile file next to this NewGRF.
FindGRFConfigMode
Method to find GRFs using FindGRFConfig.
Information about one grf parameter.
size_t GRFGetSizeOfDataSection(FILE *f)
Get the data section size of a GRF.
bool has_param_defaults
NOSAVE: did this newgrf specify any defaults for it's parameters.
@ NEWGRF
Scan for non-base sets.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void ScanNewGRFFiles(NewGRFScanCallback *callback)
Scan for all NewGRFs.
~GRFConfig()
Cleanup a GRFConfig object.
void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir)
Load a particular NewGRF.
const char * GetURL() const
Get the grf url.
@ GRFP_GRF_MASK
Bitmask to get only the NewGRF supplied information.
void CopyParams(const GRFConfig &src)
Copy the parameter information from the src config.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
static uint DoScan()
Do the scan for GRFs.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
Calculate the MD5 sum for a GRF, and store it in the config.
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename) override
Add a file with the given filename.
Information about why GRF had problems during initialisation.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void Finalize()
Finalize Action 14 info after file scan is finished.
uint32 max_value
The maximal value of this parameter.
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ GRFP_GRF_WINDOWS
The NewGRF says the Windows palette can be used.
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
SmallMap< uint32, GRFTextList > value_names
Names for each value.
GRFTextWrapper name
NOSAVE: GRF name (Action 0x08)
void AppendStaticGRFConfigs(GRFConfig **dst)
Appends the static GRFs to a list of GRFs.
uint32 min_loadable_version
NOSAVE: Minimum compatible version a NewGRF can define.
const char * GetDescription() const
Get the grf info.
uint8 original_md5sum[16]
MD5 checksum of original file if only a 'compatible' file was loaded.
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...
@ GOID_NEWGRF_RESCANNED
NewGRFs were just rescanned.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
@ FGCM_NEWEST
Find newest Grf.
virtual void OnNewGRFsScanned()=0
Called whenever the NewGRF scan completed.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Subdirectory
The different kinds of subdirectories OpenTTD uses.
GRFTextWrapper url
NOSAVE: URL belonging to this GRF.
GRFConfig(const char *filename=nullptr)
Create a new GRFConfig.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
uint8 palette
GRFPalette, bitset.
bool complete_labels
True if all values have a label.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
GRFConfig * _grfconfig
First item in list of current GRF set up.
Callback for NewGRF scanning.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
#define lengthof(x)
Return the length of an fixed size array.
static bool UseThreadedModelProgress()
Check if we can use a thread for modal progress.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
void FinalizeParameterInfo()
Finalize Action 14 info after file scan is finished.
Helper for scanning for files with a given name.
static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list)
Removes duplicates from lists of GRFConfigs.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
void NetworkAfterNewGRFScan()
Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new N...
uint32 last_newgrf_count
the numbers of NewGRFs we found during the last scan
@ PTYPE_UINT_ENUM
The parameter allows a range of numbers, each of which can have a special name.
TextfileType
Additional text files accompanying Tar archives.
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
@ FGCM_EXACT
Only find Grfs matching md5sum.
std::shared_ptr< GRFTextList > GRFTextWrapper
Reference counted wrapper around a GRFText pointer.
GRFParameterInfo(uint nr)
Create a new empty GRFParameterInfo object.
@ GLC_ALL_GOOD
All GRF needed by game are present.
char * filename
Filename - either with or without full path.
GRFTextWrapper FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
Finds the name of a NewGRF in the list of names for unknown GRFs.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
void SetModalProgress(bool state)
Set the modal progress state.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
static int MemCmpT(const T *ptr1, const T *ptr2, size_t num=1)
Type-safe version of memcmp().
@ PAL_WINDOWS
Use the Windows palette.
std::chrono::steady_clock::time_point next_update
The next moment we do update the screen.
uint32 param_value[2]
Values of GRF parameters to show for message and custom_message.
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
Find the GRFID of a given grf, and calculate its md5sum.
#define lastof(x)
Get the last element of an fixed size array.
@ GLC_NOT_FOUND
At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
GRFListCompatibility
Status of post-gameload GRF compatibility check.
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el)
Appends an element to a list of GRFs.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
static void AddGRFTextToList(GRFTextList &list, byte langid, const std::string &text_to_add)
Add a new text to a GRFText list.
std::vector< GRFParameterInfo * > param_info
NOSAVE: extra information about the parameters.
GUISettings gui
settings related to the GUI
void FioFCloseFile(FILE *f)
Close a file in a safe way.
uint32 param[0x80]
GRF parameters.
uint32 min_value
The minimal value this parameter can have.
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
const char * GetName() const
Get the name of this grf.
uint num_scanned
The number of GRFs we have scanned.
std::mutex _modal_progress_work_mutex
Rights for the performing work.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.