14 #include "3rdparty/md5/md5.h" 53 if (filename != NULL) this->filename =
stredup(filename);
103 this->
name->Release();
104 this->
info->Release();
105 this->
url->Release();
186 if (*
info == NULL)
continue;
224 GRFError::~GRFError()
239 max_value(UINT32_MAX),
244 complete_labels(false)
290 return GB(config->
param[this->param_nr], this->first_bit, this->num_bit);
304 SB(config->
param[this->param_nr], this->first_bit, this->num_bit, value);
332 for (
GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->
next) c->SetSuitablePalette();
333 for (
GRFConfig *c = _grfconfig_static; c != NULL; c = c->
next) c->SetSuitablePalette();
334 for (
GRFConfig *c = _all_grfs; c != NULL; c = c->
next) c->SetSuitablePalette();
346 static const uint header_len = 14;
348 byte data[header_len];
349 if (fread(data, 1, header_len, f) == header_len) {
350 if (data[0] == 0 && data[1] == 0 &&
MemCmpT(data + 2, _grf_cont_v2_sig, 8) == 0) {
352 size_t offset = ((size_t)data[13] << 24) | ((size_t)data[12] << 16) | ((size_t)data[11] << 8) | (size_t)data[10];
353 if (offset >= 1 * 1024 * 1024 * 1024) {
354 DEBUG(grf, 0,
"Unexpectedly large offset for NewGRF");
360 return header_len + offset;
382 if (f == NULL)
return false;
384 long start = ftell(f);
387 if (start < 0 || fseek(f, start, SEEK_SET) < 0) {
393 while ((len = fread(buffer, 1, (size >
sizeof(buffer)) ?
sizeof(buffer) : size, f)) != 0 && size != 0) {
395 checksum.Append(buffer, len);
447 for (c = *config; c != NULL; c = next) {
466 for (; src != NULL; src = src->
next) {
497 if (list == NULL)
return;
499 for (prev = list, cur = list->
next; cur != NULL; prev = cur, cur = cur->
next) {
517 while (*tail != NULL) tail = &(*tail)->
next;
531 while (*tail != NULL) tail = &(*tail)->
next;
571 DEBUG(grf, 1,
"NewGRF %08X (%s) not found; checksum %s. Compatibility mode on",
BSWAP32(c->ident.grfid), c->filename, buf);
575 memcpy(c->original_md5sum, c->ident.md5sum,
sizeof(c->original_md5sum));
585 DEBUG(grf, 0,
"NewGRF %08X (%s) not found; checksum %s",
BSWAP32(c->ident.grfid), c->filename, buf);
600 memcpy(c->ident.md5sum, f->
ident.
md5sum,
sizeof(c->ident.md5sum));
614 *c->param_info.Append() = NULL;
636 bool AddFile(
const char *filename,
size_t basepath_length,
const char *tar_filename);
656 if (_all_grfs == NULL) {
663 for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->
next) {
688 const char *
name = NULL;
690 if (name == NULL) name = c->
filename;
733 DEBUG(grf, 1,
"Scanning for NewGRFs");
736 DEBUG(grf, 1,
"Scan complete, found %d files", num);
737 if (num != 0 && _all_grfs != NULL) {
741 GRFConfig **to_sort = MallocT<GRFConfig*>(num);
744 for (
GRFConfig *p = _all_grfs; p != NULL; p = p->
next, i++) {
752 for (i = 1; i < num; i++) {
753 to_sort[i - 1]->
next = to_sort[i];
755 to_sort[num - 1]->
next = NULL;
756 _all_grfs = to_sort[0];
760 #ifdef ENABLE_NETWORK 811 assert((mode ==
FGCM_EXACT) != (md5sum == NULL));
813 for (
const GRFConfig *c = _all_grfs; c != NULL; c = c->
next) {
815 if (!c->ident.HasGrfIdentifier(grfid, md5sum))
continue;
817 if (md5sum != NULL || mode ==
FGCM_ANY)
return c;
821 if (mode ==
FGCM_COMPATIBLE && (c->version < desired_version || c->min_loadable_version > desired_version))
continue;
829 #ifdef ENABLE_NETWORK 859 for (grf = unknown_grfs; grf != NULL; grf = grf->
next) {
860 if (grf->
grfid == grfid) {
861 if (memcmp(md5sum, grf->
md5sum,
sizeof(grf->
md5sum)) == 0)
return grf->
name;
865 if (!create)
return NULL;
867 grf = CallocT<UnknownGRF>(1);
869 grf->
next = unknown_grfs;
893 for (c = _grfconfig; c != NULL; c = c->
next) {
894 if ((c->
ident.
grfid & mask) == (grfid & mask))
return c;
910 if (i > 0) dst =
strecpy(dst,
" ", last);
~GRFTextWrapper()
Cleanup a GRFTextWrapper object.
Functions related to OTTD's strings.
bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
Add a file with the given filename.
void SetValue(struct GRFConfig *config, uint32 value)
Set the value of this user-changeable parameter in the given config.
Base of all video drivers.
uint8 newgrf_default_palette
default palette to use for NewGRFs without action 14 palette information
uint32 param_value[2]
Values of GRF parameters to show for message and custom_message.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
uint32 _realtime_tick
The real time in the game.
The parameter allows a range of numbers, each of which can have a special name.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
GRFConfig * _grfconfig
First item in list of current GRF set up.
static int MemCmpT(const T *ptr1, const T *ptr2, size_t num=1)
Type-safe version of memcmp().
Subdirectory
The different kinds of subdirectories OpenTTD uses.
size_t GRFGetSizeOfDataSection(FILE *f)
Get the data section size of a GRF.
void FioFCloseFile(FILE *f)
Close a file in a safe way.
GRF file is processed up to GLS_INIT.
Saveload window; Window numbers:
GRFError(StringID severity, StringID message=0)
Construct a new GRFError.
All GRF needed by game are present.
NewGRFs were just rescanned.
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
GRFConfig * _grfconfig_newgame
First item in list of default GRF set up.
Compatible (eg. the same ID, but different checksum) GRF found in at least one case.
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
GRFParameterType type
The type of this parameter.
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Progress report of landscape generation; Window numbers:
const byte _grf_cont_v2_sig[8]
Signature of a container version 2 GRF.
Functions related to debugging.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
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.
UnknownGRF * next
The next unknown GRF.
uint _missing_extra_graphics
Number of sprites provided by the fallback extra GRF, i.e. missing in the baseset.
uint32 def_value
Default value of this parameter.
GRFStatus status
NOSAVE: GRFStatus, enum.
struct GRFText * text
The actual text.
char * md5sumToString(char *buf, const char *last, const uint8 md5sum[16])
Convert the md5sum to a hexadecimal string representation.
GRFListCompatibility IsGoodGRFConfigList(GRFConfig *grfconfig)
Check if all GRFs in the GRF config from a savegame can be loaded.
char * custom_message
Custom message (if present)
uint8 num_valid_params
NOSAVE: Number of valid parameters (action 0x14)
const T * Begin() const
Get the pointer to the first item (const)
bool Insert(const T &key, const U &data)
Adds new item to this map.
GRFError * error
NOSAVE: Error/Warning during GRF loading (Action 0x0B)
Functions for Standard In/Out file operations.
byte param_nr
GRF parameter to store content in.
uint8 original_md5sum[16]
MD5 checksum of original file if only a 'compatible' file was loaded.
#define lastof(x)
Get the last element of an fixed size array.
StringID severity
Info / Warning / Error / Fatal.
GRF file was not found in the local cache.
bool UpdateNewGRFConfigPalette(int32 p1)
Update the palettes of the graphics from the config file.
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
Slot used for the GRF scanning and such.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
uint32 last_newgrf_count
the numbers of NewGRFs we found during the last scan
virtual void EndCritical(bool allow_recursive=false)=0
End of the critical section.
Basic data to distinguish a GRF.
const T * End() const
Get the pointer behind the last valid item (const)
SmallVector< GRFParameterInfo *, 4 > param_info
NOSAVE: extra information about the parameters.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
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.
GRFConfig * _grfconfig_static
First item in list of static GRF set up.
T * Append(uint to_add=1)
Append an item and return it.
Helper for scanning for files with a given name.
ThreadMutex * _modal_progress_work_mutex
Rights for the performing work.
GRFConfig * _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.
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...
struct GRFText * desc
The description of this parameter.
Header of Action 04 "universal holder" structure and functions.
uint32 GetValue(struct GRFConfig *config) const
Get the value of this user-changeable parameter from the given config.
uint32 grf_bugs
NOSAVE: bugs in this GRF in this run,.
uint8 num_params
Number of used parameters.
GRFTextWrapper * FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
Finds the name of a NewGRF in the list of names for unknown GRFs.
uint Length() const
Get the number of items in the list.
GRF file is an openttd-internal system grf.
Information about GRF, used in the game and (part of it) in savegames.
void AddGRFTextToList(GRFText **list, GRFText *text_to_add)
Add a GRFText to a GRFText list.
GRFConfig ** CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only)
Copy a GRF Config list.
bool has_param_defaults
NOSAVE: did this newgrf specify any defaults for it's parameters.
void CleanUpGRFText(GRFText *grftext)
Delete all items of a linked GRFText list.
Functions related to the gfx engine.
const char * GetDescription() const
Get the grf info.
void CopyParams(const GRFConfig &src)
Copy the parameter information from the src config.
char * GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
Build a string containing space separated parameter values, and terminate.
ClientSettings _settings_client
The current settings for this game.
FILE * FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize)
Opens a OpenTTD file somewhere in a personal or global directory.
byte num_bit
Number of bits to use for this parameter.
Functions related to modal progress.
SmallMap< uint32, struct GRFText *, 8 > value_names
Names for each value.
The palette state is set to use the Windows palette.
Definition of base types and functions in a cross-platform compatible way.
The data is copied from a grf in _all_grfs.
A number of safeguards to prevent using unsafe methods.
Information about why GRF had problems during initialisation.
uint32 max_value
The maximal value of this parameter.
~GRFParameterInfo()
Cleanup all parameter info.
void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage, Subdirectory subdir)
Load a particular NewGRF.
static uint DoScan()
Do the scan for GRFs.
uint8 flags
NOSAVE: GCF_Flags, bitset.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
GRF is unusable with this version of OpenTTD.
GRFConfig(const char *filename=NULL)
Create a new GRFConfig.
GRFTextWrapper()
Create a new GRFTextWrapper.
void AppendStaticGRFConfigs(GRFConfig **dst)
Appends the static GRFs to a list of GRFs.
uint next_update
The next (realtime tick) we do update the screen.
#define lengthof(x)
Return the length of an fixed size array.
TextfileType
Additional text files accompanying Tar archives.
StringID message
Default message.
static T min(const T a, const T b)
Returns the minimum of two values.
Reference counted wrapper around a GRFText pointer.
void FinalizeParameterInfo()
Finalize Action 14 info after file scan is finished.
bool FioCheckFileExists(const char *filename, Subdirectory subdir)
Check whether the given file exists.
Base class that provides memory initialization on dynamically created objects.
ThreadMutex * _modal_progress_paint_mutex
Rights for the painting.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Subdirectory for all NewGRFs.
uint DoScan(Subdirectory sd)
Perform the scanning of a particular subdirectory.
uint32 version
NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown.
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el)
Appends an element to a list of GRFs.
The palette state is set to use the DOS palette.
#define DEBUG(name, level,...)
Output a line of debugging information.
GRFTextWrapper * url
NOSAVE: URL belonging to this GRF.
~GRFConfig()
Cleanup a GRFConfig object.
GRFText * DuplicateGRFText(GRFText *orig)
Create a copy of this GRFText list.
The NewGRF says the Windows palette can be used.
Callback for NewGRF scanning.
const char * GetURL() const
Get the grf url.
byte first_bit
First bit to use in the GRF parameter.
const char * GetGRFStringFromGRFText(const GRFText *text)
Get a C-string from a GRFText-list.
void UpdateNewGRFScanStatus(uint num, const char *name)
Update the NewGRF scan status.
void Finalize()
Finalize Action 14 info after file scan is finished.
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
GUISettings gui
settings related to the GUI
Information about one grf parameter.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Declarations for savegames operations.
const char * GetTextfile(TextfileType type) const
Search a textfile file next to this NewGRF.
GRFListCompatibility
Status of post-gameload GRF compatibility check.
uint8 palette
GRFPalette, bitset.
#define UNKNOWN_GRF_NAME_PLACEHOLDER
For communication about GRFs over the network.
bool complete_labels
True if all values have a label.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
GRF file is unsafe for static usage.
void DoScanNewGRFFiles(void *callback)
Really perform the scan for all NewGRFs.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Structure for UnknownGRFs; this is a lightweight variant of GRFConfig.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
char * filename
Filename - either with or without full path.
PaletteType
Palettes OpenTTD supports.
FindGRFConfigMode
Method to find GRFs using FindGRFConfig.
void SetSuitablePalette()
Set the palette of this GRFConfig to something suitable.
void ScanNewGRFFiles(NewGRFScanCallback *callback)
Scan for all NewGRFs.
GRFTextWrapper * name
NOSAVE: GRF name (Action 0x08)
Network functions used by other parts of OpenTTD.
The NewGRF says the DOS palette can be used.
uint32 min_loadable_version
NOSAVE: Minimum compatible version a NewGRF can define.
uint32 min_value
The minimal value this parameter can have.
void SetModalProgress(bool state)
Set the modal progress state.
const char * GetName() const
Get the name of this grf.
uint32 grfid
GRF ID (defined by Action 0x08)
char * data
Additional data for message and custom_message.
struct GRFText * name
The name of this parameter.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
uint32 param[0x80]
GRF parameters.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
void NetworkAfterNewGRFScan()
Rebuild the GRFConfig's of the servers in the game list as we did a rescan and might have found new N...
const T * Get(uint index) const
Get the pointer to item "number" (const)
GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches) ...
Bitmask to get only the NewGRF supplied information.
Helper for scanning for files with GRF as extension.
virtual void BeginCritical(bool allow_recursive=false)=0
Begin the critical section.
The bit used for storing the palette to use.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
Window functions not directly related to making/drawing windows.
static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list)
Removes duplicates from lists of GRFConfigs.
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF) ...
static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
Calculate the MD5 sum for a GRF, and store it in the config.
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Only find Grfs matching md5sum.
static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID
Base GRF ID for OpenTTD's base graphics GRFs.
static int CDECL GRFSorter(GRFConfig *const *p1, GRFConfig *const *p2)
Simple sorter for GRFS.
static void QSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe qsort()
static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread=NULL, const char *name=NULL)
Create a thread; proc will be called as first function inside the thread, with optional params...
GRFParameterInfo(uint nr)
Create a new empty GRFParameterInfo object.
Game options window; Window numbers:
uint num_scanned
The number of GRFs we have scanned.
GRFTextWrapper * name
Name of the GRF.
Find best compatible Grf wrt. desired_version.
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-...
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
GUI functions related to textfiles.
GRFTextWrapper * info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
Base for the NewGRF implementation.