src/newgrf_config.cpp
author smatz
Wed, 07 May 2008 17:36:28 +0000
changeset 9133 705318ad20db
parent 9131 d7da7ac0f845
child 9146 dbe2317185eb
permissions -rw-r--r--
(svn r12993) -Fix (r11175): list used for sorting GRFs wasn't freed
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     1
/* $Id$ */
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8592
diff changeset
     3
/** @file newgrf_config.cpp Finding NewGRFs and configuring them. */
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
     4
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     5
#include "stdafx.h"
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     6
#include "openttd.h"
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     7
#include "debug.h"
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     8
#include "variables.h"
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
     9
#include "saveload.h"
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    10
#include "md5.h"
5469
7edfc643abbc (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5441
diff changeset
    11
#include "network/network_data.h"
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    12
#include "newgrf.h"
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    13
#include "newgrf_config.h"
8213
7bdd7593eb9b (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8133
diff changeset
    14
#include "core/alloc_func.hpp"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8213
diff changeset
    15
#include "string_func.h"
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    16
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    17
#include "fileio.h"
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    18
#include "fios.h"
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    19
#include <sys/stat.h>
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    20
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    21
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    22
GRFConfig *_all_grfs;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    23
GRFConfig *_grfconfig;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    24
GRFConfig *_grfconfig_newgame;
5329
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
    25
GRFConfig *_grfconfig_static;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    26
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    27
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    28
/* Calculate the MD5 Sum for a GRF */
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    29
static bool CalcGRFMD5Sum(GRFConfig *config)
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    30
{
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    31
	FILE *f;
8133
3ab8eaf85ca0 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8131
diff changeset
    32
	Md5 checksum;
3ab8eaf85ca0 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8131
diff changeset
    33
	uint8 buffer[1024];
7574
40e7c5575a2a (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents: 7573
diff changeset
    34
	size_t len, size;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    35
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    36
	/* open the file */
7574
40e7c5575a2a (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents: 7573
diff changeset
    37
	f = FioFOpenFile(config->filename, "rb", DATA_DIR, &size);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    38
	if (f == NULL) return false;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    39
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    40
	/* calculate md5sum */
7574
40e7c5575a2a (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents: 7573
diff changeset
    41
	while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
40e7c5575a2a (svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
truelight
parents: 7573
diff changeset
    42
		size -= len;
8133
3ab8eaf85ca0 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8131
diff changeset
    43
		checksum.Append(buffer, len);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    44
	}
8133
3ab8eaf85ca0 (svn r11695) -Codechange: Converted the md5 algorithm to OOP
skidd13
parents: 8131
diff changeset
    45
	checksum.Finish(config->md5sum);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    46
7592
792daecf7c77 (svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents: 7586
diff changeset
    47
	FioFCloseFile(f);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    48
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    49
	return true;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    50
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    51
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    52
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    53
/* Find the GRFID and calculate the md5sum */
5329
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
    54
bool FillGRFDetails(GRFConfig *config, bool is_static)
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    55
{
7034
e2d80a01d9c1 (svn r10298) -Fix [FS#903]: show the subdirectory below the default data directory in this filename in the newgrf list. The directory was removed in r9560 because then it used to full path instead of the path relative to the data directory, but since the inclusion of "search paths" that is not necessary anymore.
rubidium
parents: 6967
diff changeset
    56
	if (!FioCheckFileExists(config->filename)) {
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6183
diff changeset
    57
		config->status = GCS_NOT_FOUND;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    58
		return false;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    59
	}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    60
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    61
	/* Find and load the Action 8 information */
7805
7ab20f94cc80 (svn r11355) -Fix [FS#1377]: loading too many GRFs was not handled gracefully causing crashes and such.
rubidium
parents: 7649
diff changeset
    62
	LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    63
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    64
	/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */
7882
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
    65
	if (config->grfid == 0 || config->grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    66
5502
003b36599ff8 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5475
diff changeset
    67
	if (is_static) {
003b36599ff8 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5475
diff changeset
    68
		/* Perform a 'safety scan' for static GRFs */
003b36599ff8 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5475
diff changeset
    69
		LoadNewGRFFile(config, 62, GLS_SAFETYSCAN);
003b36599ff8 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5475
diff changeset
    70
003b36599ff8 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5475
diff changeset
    71
		/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
    72
		if (HasBit(config->flags, GCF_UNSAFE)) return false;
5502
003b36599ff8 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5475
diff changeset
    73
	}
003b36599ff8 (svn r7795) -Codechange: [NewGRF] When safety checking, allow an Action E that force activates the GRF. Unfortunately this requires knowing the GRF ID in advance (before the Action 8) so the static GRFs are now scanned twice on start up, once for the GRF ID, and then for the safety check. (This fix allows unifont.grf to be used.)
peter1138
parents: 5475
diff changeset
    74
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    75
	return CalcGRFMD5Sum(config);
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    76
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    77
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    78
5346
3687c73bc65b (svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents: 5339
diff changeset
    79
void ClearGRFConfig(GRFConfig **config)
5329
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
    80
{
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
    81
	/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
    82
	if (!HasBit((*config)->flags, GCF_COPY)) {
5346
3687c73bc65b (svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents: 5339
diff changeset
    83
		free((*config)->filename);
3687c73bc65b (svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents: 5339
diff changeset
    84
		free((*config)->name);
3687c73bc65b (svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents: 5339
diff changeset
    85
		free((*config)->info);
6873
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6834
diff changeset
    86
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6834
diff changeset
    87
		if ((*config)->error != NULL) {
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6834
diff changeset
    88
			free((*config)->error->custom_message);
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6834
diff changeset
    89
			free((*config)->error->data);
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6834
diff changeset
    90
			free((*config)->error);
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6834
diff changeset
    91
		}
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
    92
	}
5346
3687c73bc65b (svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents: 5339
diff changeset
    93
	free(*config);
3687c73bc65b (svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents: 5339
diff changeset
    94
	*config = NULL;
5329
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
    95
}
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
    96
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
    97
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
    98
/* Clear a GRF Config list */
5347
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
    99
void ClearGRFConfigList(GRFConfig **config)
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   100
{
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   101
	GRFConfig *c, *next;
5347
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   102
	for (c = *config; c != NULL; c = next) {
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   103
		next = c->next;
5346
3687c73bc65b (svn r7517) -Codechange: Set pointers to NULL when freeing the newgrf config variables and add the proper const to CopyGRFConfigList
Darkvater
parents: 5339
diff changeset
   104
		ClearGRFConfig(&c);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   105
	}
5347
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   106
	*config = NULL;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   107
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   108
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   109
5347
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   110
/** Copy a GRF Config list
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   111
 * @param dst pointer to destination list
6073
0fb2bb966428 (svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents: 5765
diff changeset
   112
 * @param src pointer to source list values
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   113
 * @param init_only the copied GRF will be processed up to GLS_INIT
5347
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   114
 * @return pointer to the last value added to the destination list */
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   115
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src, bool init_only)
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   116
{
5351
c83b547490f0 (svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents: 5349
diff changeset
   117
	/* Clear destination as it will be overwritten */
c83b547490f0 (svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents: 5349
diff changeset
   118
	ClearGRFConfigList(dst);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   119
	for (; src != NULL; src = src->next) {
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   120
		GRFConfig *c = CallocT<GRFConfig>(1);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   121
		*c = *src;
6424
d410d4c31d15 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6409
diff changeset
   122
		if (src->filename  != NULL) c->filename  = strdup(src->filename);
d410d4c31d15 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6409
diff changeset
   123
		if (src->name      != NULL) c->name      = strdup(src->name);
d410d4c31d15 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6409
diff changeset
   124
		if (src->info      != NULL) c->info      = strdup(src->info);
d410d4c31d15 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6409
diff changeset
   125
		if (src->error     != NULL) {
6139
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6108
diff changeset
   126
			c->error = CallocT<GRFError>(1);
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6108
diff changeset
   127
			memcpy(c->error, src->error, sizeof(GRFError));
6873
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6834
diff changeset
   128
			if (src->error->data != NULL) c->error->data = strdup(src->error->data);
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6834
diff changeset
   129
			if (src->error->custom_message != NULL) c->error->custom_message = strdup(src->error->custom_message);
6139
cd42df0c1f0f (svn r8881) -Feature: Allow built-in newgrf error messages to be translated, and load custom error messages properly.
maedhros
parents: 6108
diff changeset
   130
		}
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   131
7929
6c9b25842b0f (svn r11482) -Codechange: Remove the doubled function ClrBitT and rename the remaining to fit with the naming style
skidd13
parents: 7928
diff changeset
   132
		ClrBit(c->flags, GCF_INIT_ONLY);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   133
		if (init_only) SetBit(c->flags, GCF_INIT_ONLY);
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   134
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   135
		*dst = c;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   136
		dst = &c->next;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   137
	}
5329
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
   138
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
   139
	return dst;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   140
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   141
5393
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   142
/**
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   143
 * Removes duplicates from lists of GRFConfigs. These duplicates
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   144
 * are introduced when the _grfconfig_static GRFs are appended
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   145
 * to the _grfconfig on a newgame or savegame. As the parameters
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   146
 * of the static GRFs could be different that the parameters of
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   147
 * the ones used non-statically. This can result in desyncs in
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   148
 * multiplayers, so the duplicate static GRFs have to be removed.
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   149
 *
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   150
 * This function _assumes_ that all static GRFs are placed after
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   151
 * the non-static GRFs.
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   152
 *
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   153
 * @param list the list to remove the duplicates from
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   154
 */
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   155
static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list)
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   156
{
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   157
	GRFConfig *prev;
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   158
	GRFConfig *cur;
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   159
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   160
	if (list == NULL) return;
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   161
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   162
	for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) {
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   163
		if (cur->grfid != list->grfid) continue;
5675
bbc57cf5cf18 (svn r8135) -Fix (r7582): Don't assert on duplicate non-static grfs when removing duplicates as the PEBKAC effect can result in the user adding the same grf's in the config file.
Darkvater
parents: 5652
diff changeset
   164
5393
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   165
		prev->next = cur->next;
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   166
		ClearGRFConfig(&cur);
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   167
		cur = prev; // Just go back one so it continues as normal later on
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   168
	}
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   169
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   170
	RemoveDuplicatesFromGRFConfigList(list->next);
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   171
}
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   172
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   173
/**
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   174
 * Appends the static GRFs to a list of GRFs
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   175
 * @param dst the head of the list to add to
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   176
 */
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   177
void AppendStaticGRFConfigs(GRFConfig **dst)
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   178
{
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   179
	GRFConfig **tail = dst;
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   180
	while (*tail != NULL) tail = &(*tail)->next;
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   181
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   182
	CopyGRFConfigList(tail, _grfconfig_static, false);
5393
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   183
	RemoveDuplicatesFromGRFConfigList(*dst);
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   184
}
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   185
6073
0fb2bb966428 (svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents: 5765
diff changeset
   186
/** Appends an element to a list of GRFs
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6425
diff changeset
   187
 * @param dst the head of the list to add to
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6425
diff changeset
   188
 * @param el the new tail to be */
6108
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6103
diff changeset
   189
void AppendToGRFConfigList(GRFConfig **dst, GRFConfig *el)
6073
0fb2bb966428 (svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents: 5765
diff changeset
   190
{
0fb2bb966428 (svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents: 5765
diff changeset
   191
	GRFConfig **tail = dst;
0fb2bb966428 (svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents: 5765
diff changeset
   192
	while (*tail != NULL) tail = &(*tail)->next;
6108
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6103
diff changeset
   193
	*tail = el;
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6103
diff changeset
   194
6073
0fb2bb966428 (svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents: 5765
diff changeset
   195
	RemoveDuplicatesFromGRFConfigList(*dst);
0fb2bb966428 (svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents: 5765
diff changeset
   196
}
0fb2bb966428 (svn r8806) -Codechange (r7582): Remove a duplicate append of static GRF's when loading the game and hide the intrinsics of adding elements to the GRFConfig list by using an AppendToGRFConfigList function.
Darkvater
parents: 5765
diff changeset
   197
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   198
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   199
/* Reset the current GRF Config to either blank or newgame settings */
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   200
void ResetGRFConfig(bool defaults)
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   201
{
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   202
	CopyGRFConfigList(&_grfconfig, _grfconfig_newgame, !defaults);
5393
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   203
	AppendStaticGRFConfigs(&_grfconfig);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   204
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   205
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   206
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   207
/** Check if all GRFs in the GRF config from a savegame can be loaded.
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   208
 * @return will return any of the following 3 values:<br>
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   209
 * <ul>
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6183
diff changeset
   210
 * <li> GLC_ALL_GOOD: No problems occured, all GRF files were found and loaded
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6183
diff changeset
   211
 * <li> GLC_COMPATIBLE: For one or more GRF's no exact match was found, but a
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   212
 *     compatible GRF with the same grfid was found and used instead
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6183
diff changeset
   213
 * <li> GLC_NOT_FOUND: For one or more GRF's no match was found at all
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   214
 * </ul> */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6229
diff changeset
   215
GRFListCompatibility IsGoodGRFConfigList()
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   216
{
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6183
diff changeset
   217
	GRFListCompatibility res = GLC_ALL_GOOD;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   218
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   219
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   220
		const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum);
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   221
		if (f == NULL) {
5652
c26cb37e4ef4 (svn r8111) -Fix r8106: silence warnings
glx
parents: 5648
diff changeset
   222
			char buf[256];
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   223
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   224
			/* If we have not found the exactly matching GRF try to find one with the
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   225
			 * same grfid, as it most likely is compatible */
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   226
			f = FindGRFConfig(c->grfid);
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   227
			if (f != NULL) {
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   228
				md5sumToString(buf, lastof(buf), c->md5sum);
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   229
				DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->grfid), c->filename, buf);
7931
b0a46cd92225 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 7929
diff changeset
   230
				SetBit(c->flags, GCF_COMPATIBLE);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   231
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   232
				/* Non-found has precedence over compatibility load */
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6183
diff changeset
   233
				if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   234
				goto compatible_grf;
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   235
			}
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   236
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   237
			/* No compatible grf was found, mark it as disabled */
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   238
			md5sumToString(buf, lastof(buf), c->md5sum);
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   239
			DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->grfid), c->filename, buf);
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   240
6229
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6183
diff changeset
   241
			c->status = GCS_NOT_FOUND;
695400602ab0 (svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents: 6183
diff changeset
   242
			res = GLC_NOT_FOUND;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   243
		} else {
5647
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   244
compatible_grf:
9a96d72c23be (svn r8106) -Feature/Fix: Add the ability to load savegames when you don't have the exact GRF files in your list. GRF files that are found based on GRFID (but not on matching md5sum) are used instead of disabling them. This does not affect MP games, there you still need an exact match.
Darkvater
parents: 5646
diff changeset
   245
			DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->grfid), f->filename);
5349
5e39937d6247 (svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents: 5347
diff changeset
   246
			/* The filename could be the filename as in the savegame. As we need
5e39937d6247 (svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents: 5347
diff changeset
   247
			 * to load the GRF here, we need the correct filename, so overwrite that
5e39937d6247 (svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents: 5347
diff changeset
   248
			 * in any case and set the name and info when it is not set already.
5e39937d6247 (svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents: 5347
diff changeset
   249
			 * When the GCF_COPY flag is set, it is certain that the filename is
5e39937d6247 (svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents: 5347
diff changeset
   250
			 * already a local one, so there is no need to replace it. */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
   251
			if (!HasBit(c->flags, GCF_COPY)) {
5349
5e39937d6247 (svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents: 5347
diff changeset
   252
				free(c->filename);
5e39937d6247 (svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents: 5347
diff changeset
   253
				c->filename = strdup(f->filename);
5701
fdb25177500c (svn r8165) -Revert r8107 and show the MD5SUM of the *REPLACEMENT* grf file, NOT the original one. Reason for this is that this md5sum is saved, and otherwise a wrong md5sum would be stored in a savegame.
Darkvater
parents: 5675
diff changeset
   254
				memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum));
6183
59fa5aa7ea3a (svn r8955) -Fix: crash on loading savegames with GRFs that do not have their GRF info/name set.
rubidium
parents: 6139
diff changeset
   255
				if (c->name == NULL && f->name != NULL) c->name = strdup(f->name);
59fa5aa7ea3a (svn r8955) -Fix: crash on loading savegames with GRFs that do not have their GRF info/name set.
rubidium
parents: 6139
diff changeset
   256
				if (c->info == NULL && f->info != NULL) c->info = strdup(f->info);
6103
d38163ddfef9 (svn r8838) -Feature: Show newgrf error messages loaded in Action B in the newgrf gui
maedhros
parents: 6088
diff changeset
   257
				c->error = NULL;
5349
5e39937d6247 (svn r7520) -Fix(r7348): memleak due to unconditionally overwriting the filename, name and info of a GRFConfig in IsGoodGRFConfigList.
rubidium
parents: 5347
diff changeset
   258
			}
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   259
		}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   260
	}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   261
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   262
	return res;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   263
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   264
7572
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   265
static bool ScanPathAddGrf(const char *filename)
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   266
{
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   267
	GRFConfig *c = CallocT<GRFConfig>(1);
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   268
	c->filename = strdup(filename);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   269
7572
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   270
	bool added = true;
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   271
	if (FillGRFDetails(c, false)) {
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   272
		if (_all_grfs == NULL) {
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   273
			_all_grfs = c;
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   274
		} else {
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   275
			/* Insert file into list at a position determined by its
8592
beea2a140a0a (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8214
diff changeset
   276
			 * name, so the list is sorted as we go along */
7572
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   277
			GRFConfig **pd, *d;
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   278
			bool stop = false;
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   279
			for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   280
				if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   281
				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
7573
505e9d05c10a (svn r11098) -Fix r11096: forgot spaces before comments
truelight
parents: 7572
diff changeset
   282
				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
505e9d05c10a (svn r11098) -Fix r11096: forgot spaces before comments
truelight
parents: 7572
diff changeset
   283
				 *  just after the first with the same name. Avoids doubles in the list. */
8592
beea2a140a0a (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8214
diff changeset
   284
				if (strcasecmp(c->name, d->name) <= 0) {
beea2a140a0a (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8214
diff changeset
   285
					stop = true;
beea2a140a0a (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8214
diff changeset
   286
				} else if (stop) {
beea2a140a0a (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8214
diff changeset
   287
					break;
beea2a140a0a (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8214
diff changeset
   288
				}
7572
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   289
			}
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   290
			if (added) {
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   291
				c->next = d;
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   292
				*pd = c;
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   293
			}
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   294
		}
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   295
	} else {
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   296
		added = false;
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   297
	}
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   298
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   299
	if (!added) {
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   300
		/* File couldn't be opened, or is either not a NewGRF or is a
8592
beea2a140a0a (svn r12173) -Cleanup: Minor codestyle fixes.
peter1138
parents: 8214
diff changeset
   301
		 * 'system' NewGRF or it's already known, so forget about it. */
7572
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   302
		free(c->filename);
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   303
		free(c->name);
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   304
		free(c->info);
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   305
		free(c);
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   306
	}
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   307
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   308
	return added;
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   309
}
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   310
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   311
/* Scan a path for NewGRFs */
6834
7a64c73d5f45 (svn r10073) -Codechange: make the NewGRF paths in the config file without any full paths (again).
rubidium
parents: 6481
diff changeset
   312
static uint ScanPath(const char *path, int basepath_length)
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   313
{
7572
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   314
	extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   315
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   316
	uint num = 0;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   317
	struct stat sb;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   318
	struct dirent *dirent;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   319
	DIR *dir;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   320
6424
d410d4c31d15 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6409
diff changeset
   321
	if (path == NULL || (dir = ttd_opendir(path)) == NULL) return 0;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   322
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   323
	while ((dirent = readdir(dir)) != NULL) {
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   324
		const char *d_name = FS2OTTD(dirent->d_name);
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   325
		char filename[MAX_PATH];
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   326
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   327
		if (!FiosIsValidFile(path, dirent, &sb)) continue;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   328
6424
d410d4c31d15 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6409
diff changeset
   329
		snprintf(filename, lengthof(filename), "%s%s", path, d_name);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   330
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   331
		if (sb.st_mode & S_IFDIR) {
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   332
			/* Directory */
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   333
			if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue;
6424
d410d4c31d15 (svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents: 6409
diff changeset
   334
			AppendPathSeparator(filename, lengthof(filename));
6834
7a64c73d5f45 (svn r10073) -Codechange: make the NewGRF paths in the config file without any full paths (again).
rubidium
parents: 6481
diff changeset
   335
			num += ScanPath(filename, basepath_length);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   336
		} else if (sb.st_mode & S_IFREG) {
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   337
			/* File */
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   338
			char *ext = strrchr(filename, '.');
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   339
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   340
			/* If no extension or extension isn't .grf, skip the file */
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   341
			if (ext == NULL) continue;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   342
			if (strcasecmp(ext, ".grf") != 0) continue;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   343
7572
817d4302228e (svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
truelight
parents: 7571
diff changeset
   344
			if (ScanPathAddGrf(filename + basepath_length)) num++;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   345
		}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   346
	}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   347
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   348
	closedir(dir);
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   349
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   350
	return num;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   351
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   352
7592
792daecf7c77 (svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents: 7586
diff changeset
   353
static uint ScanTar(TarFileList::iterator tar)
7581
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   354
{
7592
792daecf7c77 (svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents: 7586
diff changeset
   355
	uint num = 0;
792daecf7c77 (svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents: 7586
diff changeset
   356
	const char *filename = (*tar).first.c_str();
7586
efc1a25de95e (svn r11111) -Fix (r11106): missing const broke compilation with MSVC
glx
parents: 7581
diff changeset
   357
	const char *ext = strrchr(filename, '.');
7581
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   358
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   359
	/* If no extension or extension isn't .grf, skip the file */
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   360
	if (ext == NULL) return false;
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   361
	if (strcasecmp(ext, ".grf") != 0) return false;
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   362
7592
792daecf7c77 (svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents: 7586
diff changeset
   363
	if (ScanPathAddGrf(filename)) num++;
7581
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   364
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   365
	return num;
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   366
}
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   367
7644
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   368
/**
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   369
 * Simple sorter for GRFS
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   370
 * @param p1 the first GRFConfig *
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   371
 * @param p2 the second GRFConfig *
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   372
 * @return the same strcmp would return for the name of the NewGRF.
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   373
 */
7648
c3f25e9f71e4 (svn r11179) -Fix [FS#1262] (r11175): compilation with MSVC was broken
glx
parents: 7644
diff changeset
   374
static int CDECL GRFSorter(const void *p1, const void *p2)
7644
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   375
{
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   376
	const GRFConfig *c1 = *(const GRFConfig **)p1;
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   377
	const GRFConfig *c2 = *(const GRFConfig **)p2;
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   378
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   379
	return strcmp(c1->name != NULL ? c1->name : c1->filename,
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   380
		c2->name != NULL ? c2->name : c2->filename);
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   381
}
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   382
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   383
/* Scan for all NewGRFs */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6229
diff changeset
   384
void ScanNewGRFFiles()
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   385
{
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6873
diff changeset
   386
	Searchpath sp;
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6873
diff changeset
   387
	char path[MAX_PATH];
7592
792daecf7c77 (svn r11119) -Codechange: analyze .tar files upon loading, remembering their files and offsets, which speeds up .tar handling with a big factor
truelight
parents: 7586
diff changeset
   388
	TarFileList::iterator tar;
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6873
diff changeset
   389
	uint num = 0;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   390
5347
9b1bc705f2ae (svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents: 5346
diff changeset
   391
	ClearGRFConfigList(&_all_grfs);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   392
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5366
diff changeset
   393
	DEBUG(grf, 1, "Scanning for NewGRFs");
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6873
diff changeset
   394
	FOR_ALL_SEARCHPATHS(sp) {
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6873
diff changeset
   395
		FioAppendDirectory(path, MAX_PATH, sp, DATA_DIR);
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6873
diff changeset
   396
		num += ScanPath(path, strlen(path));
6834
7a64c73d5f45 (svn r10073) -Codechange: make the NewGRF paths in the config file without any full paths (again).
rubidium
parents: 6481
diff changeset
   397
	}
7581
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   398
	FOR_ALL_TARS(tar) {
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   399
		num += ScanTar(tar);
24dab79dca15 (svn r11106) -Add: added .tar support; you can pack all files in your data/ dir in how ever many .tar files you like, keeping the dir-structure equal to the unpacked version, and OpenTTD can handle them just like the files were unpacked
truelight
parents: 7574
diff changeset
   400
	}
7644
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   401
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5366
diff changeset
   402
	DEBUG(grf, 1, "Scan complete, found %d files", num);
7649
c4e93cf27732 (svn r11180) -Fix (r11175): crash on load when you don't have any NewGRFs. More interesting is: who plays without them ;)
rubidium
parents: 7648
diff changeset
   403
	if (num == 0 || _all_grfs == NULL) return;
7644
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   404
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   405
	/* Sort the linked list using quicksort.
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   406
	 * For that we first have to make an array, the qsort and
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   407
	 * then remake the linked list. */
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   408
	GRFConfig **to_sort = MallocT<GRFConfig*>(num);
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   409
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   410
	uint i = 0;
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   411
	for (GRFConfig *p = _all_grfs; p != NULL; p = p->next, i++) {
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   412
		to_sort[i] = p;
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   413
	}
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   414
	/* Number of files is not necessarily right */
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   415
	num = i;
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   416
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   417
	qsort(to_sort, num, sizeof(GRFConfig*), GRFSorter);
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   418
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   419
	for (i = 1; i < num; i++) {
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   420
		to_sort[i - 1]->next = to_sort[i];
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   421
	}
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   422
	to_sort[num - 1]->next = NULL;
a7ff5c8ae47e (svn r11175) -Codechange: sort the NewGRFs by name, making searching a specific NewGRF a lot easier.
rubidium
parents: 7592
diff changeset
   423
	_all_grfs = to_sort[0];
9133
705318ad20db (svn r12993) -Fix (r11175): list used for sorting GRFs wasn't freed
smatz
parents: 9131
diff changeset
   424
705318ad20db (svn r12993) -Fix (r11175): list used for sorting GRFs wasn't freed
smatz
parents: 9131
diff changeset
   425
	free(to_sort);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   426
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   427
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   428
5646
e94c63712efe (svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents: 5634
diff changeset
   429
/* Find a NewGRF in the scanned list, if md5sum is NULL, we don't care about it*/
e94c63712efe (svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents: 5634
diff changeset
   430
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   431
{
5646
e94c63712efe (svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents: 5634
diff changeset
   432
	for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
e94c63712efe (svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents: 5634
diff changeset
   433
		if (c->grfid == grfid) {
e94c63712efe (svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents: 5634
diff changeset
   434
			if (md5sum == NULL) return c;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   435
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   436
			if (memcmp(md5sum, c->md5sum, sizeof(c->md5sum)) == 0) return c;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   437
		}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   438
	}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   439
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   440
	return NULL;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   441
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   442
5441
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5401
diff changeset
   443
#ifdef ENABLE_NETWORK
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5401
diff changeset
   444
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   445
/** Structure for UnknownGRFs; this is a lightweight variant of GRFConfig */
5765
27dbbe543fcf (svn r8316) -Codechange: move the GRF ID and MD5 checksum from GRFConfig to GRFIdentifier so it can be reused.
rubidium
parents: 5701
diff changeset
   446
struct UnknownGRF : public GRFIdentifier {
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   447
	UnknownGRF *next;
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   448
	char   name[NETWORK_GRF_NAME_LENGTH];
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   449
};
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   450
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   451
/**
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   452
 * Finds the name of a NewGRF in the list of names for unknown GRFs. An
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   453
 * unknown GRF is a GRF where the .grf is not found during scanning.
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   454
 *
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   455
 * The names are resolved via UDP calls to servers that should know the name,
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   456
 * though the replies may not come. This leaves "<Unknown>" as name, though
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   457
 * that shouldn't matter _very_ much as they need GRF crawler or so to look
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   458
 * up the GRF anyway and that works better with the GRF ID.
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   459
 *
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   460
 * @param grfid  the GRF ID part of the 'unique' GRF identifier
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   461
 * @param md5sum the MD5 checksum part of the 'unique' GRF identifier
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   462
 * @param create whether to create a new GRFConfig if the GRFConfig did not
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   463
 *               exist in the fake list of GRFConfigs.
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   464
 * @return the GRFConfig with the given GRF ID and MD5 checksum or NULL when
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   465
 *         it does not exist and create is false. This value must NEVER be
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   466
 *         freed by the caller.
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   467
 */
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   468
char *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   469
{
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   470
	UnknownGRF *grf;
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   471
	static UnknownGRF *unknown_grfs = NULL;
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   472
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   473
	for (grf = unknown_grfs; grf != NULL; grf = grf->next) {
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   474
		if (grf->grfid == grfid) {
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   475
			if (memcmp(md5sum, grf->md5sum, sizeof(grf->md5sum)) == 0) return grf->name;
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   476
		}
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   477
	}
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   478
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   479
	if (!create) return NULL;
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   480
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   481
	grf = CallocT<UnknownGRF>(1);
5339
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   482
	grf->grfid = grfid;
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   483
	grf->next  = unknown_grfs;
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   484
	ttd_strlcpy(grf->name, UNKNOWN_GRF_NAME_PLACEHOLDER, sizeof(grf->name));
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   485
	memcpy(grf->md5sum, md5sum, sizeof(grf->md5sum));
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   486
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   487
	unknown_grfs = grf;
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   488
	return grf->name;
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   489
}
96ac3f4933bb (svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents: 5333
diff changeset
   490
5441
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5401
diff changeset
   491
#endif /* ENABLE_NETWORK */
e8bac228a6db (svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents: 5401
diff changeset
   492
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   493
5234
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   494
/* Retrieve a NewGRF from the current config by its grfid */
5333
dedf1f6de6d3 (svn r7495) -Fix (r7354): [NewGRF] Deactivate the target GRF, not the current GRF.
peter1138
parents: 5329
diff changeset
   495
GRFConfig *GetGRFConfig(uint32 grfid)
5234
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   496
{
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   497
	GRFConfig *c;
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   498
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   499
	for (c = _grfconfig; c != NULL; c = c->next) {
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   500
		if (c->grfid == grfid) return c;
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   501
	}
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   502
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   503
	return NULL;
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   504
}
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   505
980aa61260aa (svn r7354) -Codechange: Remove grffile->flags and use grfconfig->flags exclusively. Update action 7/9 now that we know if GRFs are disabled.
peter1138
parents: 5229
diff changeset
   506
5308
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   507
/* Build a space separated list of parameters, and terminate */
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   508
char *GRFBuildParamList(char *dst, const GRFConfig *c, const char *last)
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   509
{
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   510
	uint i;
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   511
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   512
	/* Return an empty string if there are no parameters */
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   513
	if (c->num_params == 0) return strecpy(dst, "", last);
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   514
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   515
	for (i = 0; i < c->num_params; i++) {
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   516
		if (i > 0) dst = strecpy(dst, " ", last);
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   517
		dst += snprintf(dst, last - dst, "%d", c->param[i]);
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   518
	}
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   519
	return dst;
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   520
}
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   521
7882
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   522
/** Base GRF ID for OpenTTD's base graphics GRFs. */
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   523
static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400);
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   524
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   525
/**
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   526
 * Checks whether this GRF is a OpenTTD base graphic GRF.
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   527
 * @return true if and only if it is a base GRF.
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   528
 */
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   529
bool GRFConfig::IsOpenTTDBaseGRF() const
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   530
{
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   531
	return (this->grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID;
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   532
}
308cab08d2f3 (svn r11433) -Fix: starting OpenTTD with DOS files made it look weird out of the box.
rubidium
parents: 7805
diff changeset
   533
5308
990a4b188233 (svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents: 5296
diff changeset
   534
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   535
static const SaveLoad _grfconfig_desc[] = {
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   536
	SLE_STR(GRFConfig, filename,   SLE_STR, 0x40),
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   537
	SLE_VAR(GRFConfig, grfid,      SLE_UINT32),
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   538
	SLE_ARR(GRFConfig, md5sum,     SLE_UINT8, 16),
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   539
	SLE_ARR(GRFConfig, param,      SLE_UINT32, 0x80),
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   540
	SLE_VAR(GRFConfig, num_params, SLE_UINT8),
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   541
	SLE_END()
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   542
};
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   543
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   544
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6229
diff changeset
   545
static void Save_NGRF()
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   546
{
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   547
	int index = 0;
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   548
6108
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6103
diff changeset
   549
	for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7882
diff changeset
   550
		if (HasBit(c->flags, GCF_STATIC)) continue;
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   551
		SlSetArrayIndex(index++);
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   552
		SlObject(c, _grfconfig_desc);
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   553
	}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   554
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   555
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   556
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6229
diff changeset
   557
static void Load_NGRF()
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   558
{
6108
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6103
diff changeset
   559
	ClearGRFConfigList(&_grfconfig);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   560
	while (SlIterateArray() != -1) {
6108
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6103
diff changeset
   561
		GRFConfig *c = CallocT<GRFConfig>(1);
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6103
diff changeset
   562
		SlObject(c, _grfconfig_desc);
c0929232db31 (svn r8844) -Revert partly (r8820, r8806): Change AppendToGRFConfigList to add the allocated GRFConfig to its list and not copy it.
Darkvater
parents: 6103
diff changeset
   563
		AppendToGRFConfigList(&_grfconfig, c);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   564
	}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   565
5329
9c5e8061ea0f (svn r7490) -Feature: Load a list of NewGRFs from the config (in the [newgrf-static] section) that should always be loaded. These will also be active during the intro screen, and in multiplayer games. Only "network-safe" NewGRFs are permitted, such as fonts and sprite replacement sets.
peter1138
parents: 5308
diff changeset
   566
	/* Append static NewGRF configuration */
5393
cf584337ea2c (svn r7582) -Fix (r7490): appending static GRFs to the list of to-be loaded GRF for a game could result in duplicate GRFs in that list, which can cause a segmentation fault while loading the GRFs.
rubidium
parents: 5380
diff changeset
   567
	AppendStaticGRFConfigs(&_grfconfig);
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   568
}
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   569
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   570
extern const ChunkHandler _newgrf_chunk_handlers[] = {
5228
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   571
	{ 'NGRF', Save_NGRF, Load_NGRF, CH_ARRAY | CH_LAST }
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   572
};
26dc9acf7d94 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff changeset
   573
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5366
diff changeset
   574
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   575