author | rubidium |
Thu, 01 Feb 2007 15:49:12 +0000 | |
changeset 5893 | 7e431a4abebb |
parent 5765 | 27dbbe543fcf |
child 6073 | 0fb2bb966428 |
permissions | -rw-r--r-- |
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 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
3 |
#include "stdafx.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
4 |
#include "openttd.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
5 |
#include "functions.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
6 |
#include "macros.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" |
5308
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
9 |
#include "string.h" |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
10 |
#include "saveload.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
11 |
#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
|
12 |
#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
|
13 |
#include "newgrf.h" |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
14 |
#include "newgrf_config.h" |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
15 |
#include "helpers.hpp" |
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/types.h> |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
20 |
#include <sys/stat.h> |
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 |
#ifdef WIN32 |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
23 |
# include <io.h> |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
24 |
#else |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
25 |
# include <unistd.h> |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
26 |
# include <dirent.h> |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
27 |
#endif /* WIN32 */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
28 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
29 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
30 |
GRFConfig *_all_grfs; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
31 |
GRFConfig *_grfconfig; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
32 |
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
|
33 |
GRFConfig *_grfconfig_static; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
34 |
|
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 |
/* 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
|
37 |
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
|
38 |
{ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
39 |
FILE *f; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
40 |
char filename[MAX_PATH]; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
41 |
md5_state_t md5state; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
42 |
md5_byte_t buffer[1024]; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
43 |
size_t len; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
44 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
45 |
/* open the file */ |
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5234
diff
changeset
|
46 |
snprintf(filename, lengthof(filename), "%s%s", _paths.data_dir, config->filename); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
47 |
f = fopen(filename, "rb"); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
48 |
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
|
49 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
50 |
/* calculate md5sum */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
51 |
md5_init(&md5state); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
52 |
while ((len = fread(buffer, 1, sizeof(buffer), f)) != 0) { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
53 |
md5_append(&md5state, buffer, len); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
54 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
55 |
md5_finish(&md5state, config->md5sum); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
56 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
57 |
fclose(f); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
58 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
59 |
return true; |
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 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
62 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
63 |
/* 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
|
64 |
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
|
65 |
{ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
66 |
if (!FioCheckFileExists(config->filename)) { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
67 |
SETBIT(config->flags, GCF_NOT_FOUND); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
68 |
return false; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
69 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
70 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
71 |
/* Find and load the Action 8 information */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
72 |
/* 62 is the last file slot before sample.cat. |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
73 |
* Should perhaps be some "don't care" value */ |
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
|
74 |
LoadNewGRFFile(config, 62, GLS_FILESCAN); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
75 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
76 |
/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
77 |
if (config->grfid == 0 || config->grfid == 0xFFFFFFFF) return false; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
78 |
|
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
|
79 |
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
|
80 |
/* 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
|
81 |
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
|
82 |
|
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
|
83 |
/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */ |
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
|
84 |
if (HASBIT(config->flags, GCF_UNSAFE)) return false; |
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
|
85 |
} |
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
|
86 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
87 |
return CalcGRFMD5Sum(config); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
88 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
89 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
90 |
|
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
|
91 |
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
|
92 |
{ |
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
|
93 |
/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */ |
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
|
94 |
if (!HASBIT((*config)->flags, GCF_COPY)) { |
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
|
95 |
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
|
96 |
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
|
97 |
free((*config)->info); |
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
|
98 |
} |
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
|
99 |
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
|
100 |
*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
|
101 |
} |
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
|
102 |
|
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
|
103 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
104 |
/* Clear a GRF Config list */ |
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
105 |
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
|
106 |
{ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
107 |
GRFConfig *c, *next; |
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
108 |
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
|
109 |
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
|
110 |
ClearGRFConfig(&c); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
111 |
} |
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
112 |
*config = NULL; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
113 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
114 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
115 |
|
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
116 |
/** Copy a GRF Config list |
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
117 |
* @param dst pointer to destination list |
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
118 |
* @param srt pointer to source list values |
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
119 |
* @return pointer to the last value added to the destination list */ |
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
|
120 |
GRFConfig **CopyGRFConfigList(GRFConfig **dst, const GRFConfig *src) |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
121 |
{ |
5351
c83b547490f0
(svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents:
5349
diff
changeset
|
122 |
/* Clear destination as it will be overwritten */ |
c83b547490f0
(svn r7522) -Codechange: Have CopyGRFConfigList clear the destination list before assigning
Darkvater
parents:
5349
diff
changeset
|
123 |
ClearGRFConfigList(dst); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
124 |
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
|
125 |
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
|
126 |
*c = *src; |
5366
e469c6d36582
(svn r7551) -Fix (r7523): segmentation fault on showing NewGRF settings of a network game.
rubidium
parents:
5351
diff
changeset
|
127 |
if (src->filename != NULL) c->filename = strdup(src->filename); |
e469c6d36582
(svn r7551) -Fix (r7523): segmentation fault on showing NewGRF settings of a network game.
rubidium
parents:
5351
diff
changeset
|
128 |
if (src->name != NULL) c->name = strdup(src->name); |
e469c6d36582
(svn r7551) -Fix (r7523): segmentation fault on showing NewGRF settings of a network game.
rubidium
parents:
5351
diff
changeset
|
129 |
if (src->info != NULL) c->info = strdup(src->info); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
130 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
131 |
*dst = c; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
132 |
dst = &c->next; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
133 |
} |
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
|
134 |
|
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
|
135 |
return dst; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
136 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
137 |
|
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
|
138 |
/** |
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
|
139 |
* 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
|
140 |
* 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
|
141 |
* 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
|
142 |
* 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
|
143 |
* 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
|
144 |
* 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
|
145 |
* |
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 |
* 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
|
147 |
* 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
|
148 |
* |
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 |
* @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
|
150 |
*/ |
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 |
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
|
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 |
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
|
154 |
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
|
155 |
|
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 |
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
|
157 |
|
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 |
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
|
159 |
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
|
160 |
|
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
|
161 |
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
|
162 |
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
|
163 |
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
|
164 |
} |
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 |
|
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 |
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
|
167 |
} |
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 |
* 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
|
171 |
* @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
|
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 |
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
|
174 |
{ |
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 |
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
|
176 |
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
|
177 |
|
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 |
CopyGRFConfigList(tail, _grfconfig_static); |
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 |
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
|
180 |
} |
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 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
182 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
183 |
/* 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
|
184 |
void ResetGRFConfig(bool defaults) |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
185 |
{ |
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
|
186 |
GRFConfig **c = &_grfconfig; |
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
|
187 |
|
5401
b329aa268ce4
(svn r7594) -Fix (r7522): GRF config list wasn't cleared when no GRFs should be used.
peter1138
parents:
5393
diff
changeset
|
188 |
if (defaults) { |
b329aa268ce4
(svn r7594) -Fix (r7522): GRF config list wasn't cleared when no GRFs should be used.
peter1138
parents:
5393
diff
changeset
|
189 |
c = CopyGRFConfigList(c, _grfconfig_newgame); |
b329aa268ce4
(svn r7594) -Fix (r7522): GRF config list wasn't cleared when no GRFs should be used.
peter1138
parents:
5393
diff
changeset
|
190 |
} else { |
b329aa268ce4
(svn r7594) -Fix (r7522): GRF config list wasn't cleared when no GRFs should be used.
peter1138
parents:
5393
diff
changeset
|
191 |
ClearGRFConfigList(c); |
b329aa268ce4
(svn r7594) -Fix (r7522): GRF config list wasn't cleared when no GRFs should be used.
peter1138
parents:
5393
diff
changeset
|
192 |
} |
b329aa268ce4
(svn r7594) -Fix (r7522): GRF config list wasn't cleared when no GRFs should be used.
peter1138
parents:
5393
diff
changeset
|
193 |
|
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
|
194 |
AppendStaticGRFConfigs(&_grfconfig); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
195 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
196 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
197 |
|
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
|
198 |
/** 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
|
199 |
* @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
|
200 |
* <ul> |
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
|
201 |
* <li> GCF_ACTIVATED: No problems occured, all GRF files were found and 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
|
202 |
* <li> GCF_COMPATIBLE: For one or more GRF's no exact match was found, but a |
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
|
203 |
* compatible GRF with the same grfid was found and used instead |
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
|
204 |
* <li> GCF_NOT_FOUND: For one or more GRF's no match was found at all |
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
|
205 |
* </ul> */ |
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
|
206 |
GCF_Flags IsGoodGRFConfigList(void) |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
207 |
{ |
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
|
208 |
GCF_Flags res = GCF_ACTIVATED; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
209 |
|
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
|
210 |
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
|
211 |
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
|
212 |
if (f == NULL) { |
5652 | 213 |
char buf[256]; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
214 |
|
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
|
215 |
/* 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
|
216 |
* 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
|
217 |
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
|
218 |
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
|
219 |
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
|
220 |
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", 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
|
221 |
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
|
222 |
|
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
|
223 |
/* Non-found has precedence over compatibility load */ |
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 (res != GCF_NOT_FOUND) res = GCF_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
|
225 |
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
|
226 |
} |
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 |
|
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 |
/* 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
|
229 |
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
|
230 |
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
|
231 |
|
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 |
SETBIT(c->flags, GCF_NOT_FOUND); |
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
|
233 |
res = GCF_NOT_FOUND; |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
234 |
} 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
|
235 |
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
|
236 |
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
|
237 |
/* 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
|
238 |
* 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
|
239 |
* 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
|
240 |
* 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
|
241 |
* already a local one, so there is no need to replace it. */ |
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
|
242 |
if (!HASBIT(c->flags, GCF_COPY)) { |
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
|
243 |
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
|
244 |
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
|
245 |
memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum)); |
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 |
if (c->name == NULL) c->name = strdup(f->name); |
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 |
if (c->info == NULL) c->info = strdup(f->info); |
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 |
} |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
249 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
250 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
251 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
252 |
return res; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
253 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
254 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
255 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
256 |
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
257 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
258 |
/* Scan a path for NewGRFs */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
259 |
static uint ScanPath(const char *path) |
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 |
uint num = 0; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
262 |
struct stat sb; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
263 |
struct dirent *dirent; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
264 |
DIR *dir; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
265 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
266 |
if ((dir = opendir(path)) == NULL) return 0; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
267 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
268 |
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
|
269 |
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
|
270 |
char filename[MAX_PATH]; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
271 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
272 |
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
|
273 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
274 |
snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, d_name); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
275 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
276 |
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
|
277 |
/* Directory */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
278 |
if (strcmp(d_name, ".") == 0 || strcmp(d_name, "..") == 0) continue; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
279 |
num += ScanPath(filename); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
280 |
} 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
|
281 |
/* File */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
282 |
char *ext = strrchr(filename, '.'); |
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5234
diff
changeset
|
283 |
char *file = filename + strlen(_paths.data_dir) + 1; // Crop base path |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
284 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
285 |
/* 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
|
286 |
if (ext == NULL) continue; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
287 |
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
|
288 |
|
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
|
289 |
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
|
290 |
c->filename = strdup(file); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
291 |
|
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
|
292 |
if (FillGRFDetails(c, false)) { |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
293 |
if (_all_grfs == NULL) { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
294 |
_all_grfs = c; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
295 |
} else { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
296 |
/* Insert file into list at a position determined by its |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
297 |
* name, so the list is sorted as we go along */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
298 |
GRFConfig **pd, *d; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
299 |
for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
300 |
if (strcasecmp(c->name, d->name) <= 0) break; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
301 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
302 |
c->next = d; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
303 |
*pd = c; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
304 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
305 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
306 |
num++; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
307 |
} else { |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
308 |
/* File couldn't be opened, or is either not a NewGRF or is a |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
309 |
* 'system' NewGRF, so forget about it. */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
310 |
free(c->filename); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
311 |
free(c->name); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
312 |
free(c->info); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
313 |
free(c); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
314 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
315 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
316 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
317 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
318 |
closedir(dir); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
319 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
320 |
return num; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
321 |
} |
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 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
324 |
/* Scan for all NewGRFs */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
325 |
void ScanNewGRFFiles(void) |
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 |
uint num; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
328 |
|
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
329 |
ClearGRFConfigList(&_all_grfs); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
330 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5366
diff
changeset
|
331 |
DEBUG(grf, 1, "Scanning for NewGRFs"); |
5296
e7acddfdd8a7
(svn r7449) -Codechange: Rename _path to _paths as it is technically more correct, but mainly because
Darkvater
parents:
5234
diff
changeset
|
332 |
num = ScanPath(_paths.data_dir); |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5366
diff
changeset
|
333 |
DEBUG(grf, 1, "Scan complete, found %d files", num); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
334 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
335 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
336 |
|
5646
e94c63712efe
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5634
diff
changeset
|
337 |
/* 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
|
338 |
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
|
339 |
{ |
5646
e94c63712efe
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5634
diff
changeset
|
340 |
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
|
341 |
if (c->grfid == grfid) { |
e94c63712efe
(svn r8105) -Codechange: Change FindGRFConfig so that if md5sum parameter is omitted (or NULL)
Darkvater
parents:
5634
diff
changeset
|
342 |
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
|
343 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
344 |
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
|
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 |
return NULL; |
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 |
|
5441
e8bac228a6db
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5401
diff
changeset
|
351 |
#ifdef ENABLE_NETWORK |
e8bac228a6db
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5401
diff
changeset
|
352 |
|
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
|
353 |
/** Structure for UnknownGRFs; this is a lightweight variant of GRFConfig */ |
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
|
354 |
typedef struct UnknownGRF UnknownGRF; |
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
|
355 |
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
|
356 |
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
|
357 |
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
|
358 |
}; |
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
|
359 |
|
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
|
360 |
/** |
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
|
361 |
* 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
|
362 |
* 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
|
363 |
* |
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
|
364 |
* 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
|
365 |
* 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
|
366 |
* 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
|
367 |
* 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
|
368 |
* |
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
|
369 |
* @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
|
370 |
* @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
|
371 |
* @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
|
372 |
* 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
|
373 |
* @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
|
374 |
* 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
|
375 |
* 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
|
376 |
*/ |
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
|
377 |
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
|
378 |
{ |
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
|
379 |
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
|
380 |
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
|
381 |
|
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
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
} |
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
|
386 |
} |
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
|
387 |
|
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
|
388 |
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
|
389 |
|
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
|
390 |
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
|
391 |
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
|
392 |
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
|
393 |
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
|
394 |
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
|
395 |
|
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
|
396 |
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
|
397 |
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
|
398 |
} |
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
|
399 |
|
5441
e8bac228a6db
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5401
diff
changeset
|
400 |
#endif /* ENABLE_NETWORK */ |
e8bac228a6db
(svn r7692) -Fix: OpenTTD didn't compile without network enabled (newgrf sync code)
Darkvater
parents:
5401
diff
changeset
|
401 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
402 |
|
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
|
403 |
/* 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
|
404 |
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
|
405 |
{ |
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
|
406 |
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
|
407 |
|
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
|
408 |
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
|
409 |
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
|
410 |
} |
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
|
411 |
|
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
|
412 |
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
|
413 |
} |
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
|
414 |
|
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
|
415 |
|
5308
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
416 |
/* 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
|
417 |
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
|
418 |
{ |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
419 |
uint i; |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
420 |
|
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
421 |
/* 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
|
422 |
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
|
423 |
|
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
424 |
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
|
425 |
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
|
426 |
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
|
427 |
} |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
428 |
return dst; |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
429 |
} |
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
430 |
|
990a4b188233
(svn r7464) -Codechange: move BuildParamList from newgrf_gui to newgrf_config and
peter1138
parents:
5296
diff
changeset
|
431 |
|
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
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
|
436 |
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
|
437 |
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
|
438 |
SLE_END() |
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 |
|
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 |
static void Save_NGRF(void) |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
443 |
{ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
444 |
GRFConfig *c; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
445 |
int index = 0; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
446 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
447 |
for (c = _grfconfig; c != NULL; c = c->next) { |
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
|
448 |
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
|
449 |
SlSetArrayIndex(index++); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
450 |
SlObject(c, _grfconfig_desc); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
451 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
452 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
453 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
454 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
455 |
static void Load_NGRF(void) |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
456 |
{ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
457 |
GRFConfig *first = NULL; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
458 |
GRFConfig **last = &first; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
459 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
460 |
while (SlIterateArray() != -1) { |
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
|
461 |
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
|
462 |
SlObject(c, _grfconfig_desc); |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
463 |
|
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
464 |
/* Append our configuration to the list */ |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
465 |
*last = c; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
466 |
last = &c->next; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
467 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
468 |
|
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
|
469 |
/* Append static NewGRF configuration */ |
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
|
470 |
CopyGRFConfigList(last, _grfconfig_static); |
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
|
471 |
|
5347
9b1bc705f2ae
(svn r7518) -Codechange: more NULL pointer resets after free.
Darkvater
parents:
5346
diff
changeset
|
472 |
ClearGRFConfigList(&_grfconfig); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
473 |
_grfconfig = first; |
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
|
474 |
AppendStaticGRFConfigs(&_grfconfig); |
5228
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
475 |
} |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
476 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
477 |
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
|
478 |
{ '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
|
479 |
}; |
26dc9acf7d94
(svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents:
diff
changeset
|
480 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5366
diff
changeset
|
481 |