14 #include "3rdparty/md5/md5.h"
53 if (filename != NULL) this->filename =
stredup(filename);
69 version(config.version),
70 min_loadable_version(config.min_loadable_version),
71 flags(config.flags & ~(1 <<
GCF_COPY)),
72 status(config.status),
73 grf_bugs(config.grf_bugs),
74 num_params(config.num_params),
75 num_valid_params(config.num_valid_params),
76 palette(config.palette),
77 has_param_defaults(config.has_param_defaults)
103 this->
name->Release();
104 this->
info->Release();
105 this->
url->Release();
186 if (*
info == NULL)
continue;
214 custom_message(error.custom_message),
216 message(error.message),
217 severity(error.severity)
224 GRFError::~GRFError()
239 max_value(UINT32_MAX),
244 complete_labels(false)
256 min_value(info.min_value),
257 max_value(info.max_value),
258 def_value(info.def_value),
259 param_nr(info.param_nr),
260 first_bit(info.first_bit),
261 num_bit(info.num_bit),
262 complete_labels(info.complete_labels)
290 return GB(config->
param[this->param_nr], this->first_bit, this->num_bit);
304 SB(config->
param[this->param_nr], this->first_bit, this->num_bit, value);
332 for (
GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->
next) c->SetSuitablePalette();
333 for (
GRFConfig *c = _grfconfig_static; c != NULL; c = c->
next) c->SetSuitablePalette();
334 for (
GRFConfig *c = _all_grfs; c != NULL; c = c->
next) c->SetSuitablePalette();
346 static const uint header_len = 14;
348 byte data[header_len];
349 if (fread(data, 1, header_len, f) == header_len) {
350 if (data[0] == 0 && data[1] == 0 &&
MemCmpT(data + 2, _grf_cont_v2_sig, 8) == 0) {
352 size_t offset = ((size_t)data[13] << 24) | ((size_t)data[12] << 16) | ((size_t)data[11] << 8) | (size_t)data[10];
353 if (offset >= 1 * 1024 * 1024 * 1024) {
354 DEBUG(grf, 0,
"Unexpectedly large offset for NewGRF");
360 return header_len + offset;
382 if (f == NULL)
return false;
384 long start = ftell(f);
387 if (start < 0 || fseek(f, start, SEEK_SET) < 0) {
393 while ((len = fread(buffer, 1, (size >
sizeof(buffer)) ?
sizeof(buffer) : size, f)) != 0 && size != 0) {
395 checksum.Append(buffer, len);
447 for (c = *config; c != NULL; c = next) {
466 for (; src != NULL; src = src->
next) {
497 if (list == NULL)
return;
499 for (prev = list, cur = list->
next; cur != NULL; prev = cur, cur = cur->
next) {
517 while (*tail != NULL) tail = &(*tail)->
next;
531 while (*tail != NULL) tail = &(*tail)->
next;
571 DEBUG(grf, 1,
"NewGRF %08X (%s) not found; checksum %s. Compatibility mode on",
BSWAP32(c->ident.grfid), c->filename, buf);
575 memcpy(c->original_md5sum, c->ident.md5sum,
sizeof(c->original_md5sum));
585 DEBUG(grf, 0,
"NewGRF %08X (%s) not found; checksum %s",
BSWAP32(c->ident.grfid), c->filename, buf);
600 memcpy(c->ident.md5sum, f->
ident.
md5sum,
sizeof(c->ident.md5sum));
614 *c->param_info.Append() = NULL;
636 bool AddFile(
const char *filename,
size_t basepath_length,
const char *tar_filename);
650 bool GRFFileScanner::AddFile(
const char *filename,
size_t basepath_length,
const char *tar_filename)
656 if (_all_grfs == NULL) {
663 for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->
next) {
688 const char *name = NULL;
690 if (name == NULL) name = c->
filename;
733 DEBUG(grf, 1,
"Scanning for NewGRFs");
736 DEBUG(grf, 1,
"Scan complete, found %d files", num);
737 if (num != 0 && _all_grfs != NULL) {
741 GRFConfig **to_sort = MallocT<GRFConfig*>(num);
744 for (
GRFConfig *p = _all_grfs; p != NULL; p = p->
next, i++) {
752 for (i = 1; i < num; i++) {
753 to_sort[i - 1]->
next = to_sort[i];
755 to_sort[num - 1]->
next = NULL;
756 _all_grfs = to_sort[0];
760 #ifdef ENABLE_NETWORK
811 assert((mode ==
FGCM_EXACT) != (md5sum == NULL));
813 for (
const GRFConfig *c = _all_grfs; c != NULL; c = c->
next) {
817 if (md5sum != NULL || mode ==
FGCM_ANY)
return c;
829 #ifdef ENABLE_NETWORK
859 for (grf = unknown_grfs; grf != NULL; grf = grf->
next) {
860 if (grf->
grfid == grfid) {
861 if (memcmp(md5sum, grf->
md5sum,
sizeof(grf->
md5sum)) == 0)
return grf->
name;
865 if (!create)
return NULL;
867 grf = CallocT<UnknownGRF>(1);
869 grf->
next = unknown_grfs;
893 for (c = _grfconfig; c != NULL; c = c->
next) {
894 if ((c->
ident.
grfid & mask) == (grfid & mask))
return c;
910 if (i > 0) dst =
strecpy(dst,
" ", last);