|
@@ -291,12 +291,34 @@ bool UpdateNewGRFConfigPalette(int32 p1)
|
|
|
for (GRFConfig *c = _grfconfig_static; c != NULL; c = c->next) c->SetSuitablePalette();
|
|
|
for (GRFConfig *c = _all_grfs; c != NULL; c = c->next) c->SetSuitablePalette();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the data section size of a GRF.
|
|
|
* @param f GRF.
|
|
|
* @return Size of the data section or SIZE_MAX if the file has no separate data section.
|
|
|
*/
|
|
|
size_t GRFGetSizeOfDataSection(FILE *f)
|
|
|
{
|
|
|
extern const byte _grf_cont_v2_sig[];
|
|
|
static const uint header_len = 14;
|
|
|
|
|
|
byte data[header_len];
|
|
|
if (fread(data, 1, header_len, f) == header_len) {
|
|
|
if (data[0] == 0 && data[1] == 0 && MemCmpT(data + 2, _grf_cont_v2_sig, 8) == 0) {
|
|
|
/* Valid container version 2, get data section size. */
|
|
|
size_t offset = (data[13] << 24) | (data[12] << 16) | (data[11] << 8) | data[10];
|
|
|
return header_len + offset;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return SIZE_MAX;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Calculate the MD5 sum for a GRF, and store it in the config.
|
|
|
* @param config GRF to compute.
|
|
|
* @param subdir The subdirectory to look in.
|
|
|
* @return MD5 sum was successfully computed
|
|
|
*/
|
|
|
static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
|
|
@@ -307,12 +329,16 @@ static bool CalcGRFMD5Sum(GRFConfig *con
|
|
|
size_t len, size;
|
|
|
|
|
|
/* open the file */
|
|
|
f = FioFOpenFile(config->filename, "rb", subdir, &size);
|
|
|
if (f == NULL) return false;
|
|
|
|
|
|
size_t start = ftell(f);
|
|
|
size = min(size, GRFGetSizeOfDataSection(f));
|
|
|
fseek(f, start, SEEK_SET);
|
|
|
|
|
|
/* calculate md5sum */
|
|
|
while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
|
|
|
size -= len;
|
|
|
checksum.Append(buffer, len);
|
|
|
}
|
|
|
checksum.Finish(config->ident.md5sum);
|