mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r19255) -Codechange: encapsulate GRFIdentifier in GRFConfig instead of subclassing it
This commit is contained in:
parent
4377b5fd44
commit
a9c8dbc0a0
|
@ -643,10 +643,10 @@ void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
|
||||||
const GRFConfig *og = ol->grf[o];
|
const GRFConfig *og = ol->grf[o];
|
||||||
const GRFConfig *ng = nl->grf[n];
|
const GRFConfig *ng = nl->grf[n];
|
||||||
|
|
||||||
if (og->grfid != ng->grfid) {
|
if (og->ident.grfid != ng->ident.grfid) {
|
||||||
uint oi, ni;
|
uint oi, ni;
|
||||||
for (oi = 0; oi < ol->n; oi++) {
|
for (oi = 0; oi < ol->n; oi++) {
|
||||||
if (ol->grf[oi]->grfid == nl->grf[n]->grfid) break;
|
if (ol->grf[oi]->ident.grfid == nl->grf[n]->ident.grfid) break;
|
||||||
}
|
}
|
||||||
if (oi < o) {
|
if (oi < o) {
|
||||||
/* GRF was moved, this change has been logged already */
|
/* GRF was moved, this change has been logged already */
|
||||||
|
@ -659,7 +659,7 @@ void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (ni = 0; ni < nl->n; ni++) {
|
for (ni = 0; ni < nl->n; ni++) {
|
||||||
if (nl->grf[ni]->grfid == ol->grf[o]->grfid) break;
|
if (nl->grf[ni]->ident.grfid == ol->grf[o]->ident.grfid) break;
|
||||||
}
|
}
|
||||||
if (ni < n) {
|
if (ni < n) {
|
||||||
/* GRF was moved, this change has been logged already */
|
/* GRF was moved, this change has been logged already */
|
||||||
|
@ -668,7 +668,7 @@ void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
|
||||||
}
|
}
|
||||||
if (ni == nl->n) {
|
if (ni == nl->n) {
|
||||||
/* GRF couldn't be found in the NEW list, GRF was REMOVED */
|
/* GRF couldn't be found in the NEW list, GRF was REMOVED */
|
||||||
GamelogGRFRemove(ol->grf[o++]->grfid);
|
GamelogGRFRemove(ol->grf[o++]->ident.grfid);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,18 +682,18 @@ void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
|
||||||
|
|
||||||
if (ni >= oi) { // prefer the one that is moved further
|
if (ni >= oi) { // prefer the one that is moved further
|
||||||
/* GRF was moved down */
|
/* GRF was moved down */
|
||||||
GamelogGRFMove(ol->grf[o++]->grfid, ni);
|
GamelogGRFMove(ol->grf[o++]->ident.grfid, ni);
|
||||||
} else {
|
} else {
|
||||||
GamelogGRFMove(nl->grf[n++]->grfid, -(int)oi);
|
GamelogGRFMove(nl->grf[n++]->ident.grfid, -(int)oi);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (memcmp(og->md5sum, ng->md5sum, sizeof(og->md5sum)) != 0) {
|
if (memcmp(og->ident.md5sum, ng->ident.md5sum, sizeof(og->ident.md5sum)) != 0) {
|
||||||
/* md5sum changed, probably loading 'compatible' GRF */
|
/* md5sum changed, probably loading 'compatible' GRF */
|
||||||
GamelogGRFCompatible(nl->grf[n]);
|
GamelogGRFCompatible(&nl->grf[n]->ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (og->num_params != ng->num_params || memcmp(og->param, ng->param, og->num_params * sizeof(og->param[0])) != 0) {
|
if (og->num_params != ng->num_params || memcmp(og->param, ng->param, og->num_params * sizeof(og->param[0])) != 0) {
|
||||||
GamelogGRFParameters(ol->grf[o]->grfid);
|
GamelogGRFParameters(ol->grf[o]->ident.grfid);
|
||||||
}
|
}
|
||||||
|
|
||||||
o++;
|
o++;
|
||||||
|
@ -701,8 +701,8 @@ void GamelogGRFUpdate(const GRFConfig *oldc, const GRFConfig *newc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (o < ol->n) GamelogGRFRemove(ol->grf[o++]->grfid); // remaining GRFs were removed ...
|
while (o < ol->n) GamelogGRFRemove(ol->grf[o++]->ident.grfid); // remaining GRFs were removed ...
|
||||||
while (n < nl->n) GamelogGRFAdd (nl->grf[n++]); // ... or added
|
while (n < nl->n) GamelogGRFAdd (nl->grf[n++]); // ... or added
|
||||||
|
|
||||||
free(ol);
|
free(ol);
|
||||||
free(nl);
|
free(nl);
|
||||||
|
|
|
@ -181,7 +181,7 @@ void NetworkUDPSocketHandler::Send_NetworkGameInfo(Packet *p, const NetworkGameI
|
||||||
|
|
||||||
/* Send actual GRF Identifications */
|
/* Send actual GRF Identifications */
|
||||||
for (c = info->grfconfig; c != NULL; c = c->next) {
|
for (c = info->grfconfig; c != NULL; c = c->next) {
|
||||||
if (!HasBit(c->flags, GCF_STATIC)) this->Send_GRFIdentifier(p, c);
|
if (!HasBit(c->flags, GCF_STATIC)) this->Send_GRFIdentifier(p, &c->ident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ void NetworkUDPSocketHandler::Recv_NetworkGameInfo(Packet *p, NetworkGameInfo *i
|
||||||
|
|
||||||
for (i = 0; i < num_grfs; i++) {
|
for (i = 0; i < num_grfs; i++) {
|
||||||
GRFConfig *c = CallocT<GRFConfig>(1);
|
GRFConfig *c = CallocT<GRFConfig>(1);
|
||||||
this->Recv_GRFIdentifier(p, c);
|
this->Recv_GRFIdentifier(p, &c->ident);
|
||||||
this->HandleIncomingNetworkGameInfoGRFConfig(c);
|
this->HandleIncomingNetworkGameInfoGRFConfig(c);
|
||||||
|
|
||||||
/* Append GRFConfig to the list */
|
/* Append GRFConfig to the list */
|
||||||
|
|
|
@ -512,15 +512,15 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHECK_NEWGRFS)
|
||||||
/* Check all GRFs */
|
/* Check all GRFs */
|
||||||
for (; grf_count > 0; grf_count--) {
|
for (; grf_count > 0; grf_count--) {
|
||||||
GRFConfig c;
|
GRFConfig c;
|
||||||
MY_CLIENT->Recv_GRFIdentifier(p, &c);
|
MY_CLIENT->Recv_GRFIdentifier(p, &c.ident);
|
||||||
|
|
||||||
/* Check whether we know this GRF */
|
/* Check whether we know this GRF */
|
||||||
const GRFConfig *f = FindGRFConfig(c.grfid, c.md5sum);
|
const GRFConfig *f = FindGRFConfig(c.ident.grfid, c.ident.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
/* We do not know this GRF, bail out of initialization */
|
/* We do not know this GRF, bail out of initialization */
|
||||||
char buf[sizeof(c.md5sum) * 2 + 1];
|
char buf[sizeof(c.ident.md5sum) * 2 + 1];
|
||||||
md5sumToString(buf, lastof(buf), c.md5sum);
|
md5sumToString(buf, lastof(buf), c.ident.md5sum);
|
||||||
DEBUG(grf, 0, "NewGRF %08X not found; checksum %s", BSWAP32(c.grfid), buf);
|
DEBUG(grf, 0, "NewGRF %08X not found; checksum %s", BSWAP32(c.ident.grfid), buf);
|
||||||
ret = NETWORK_RECV_STATUS_NEWGRF_MISMATCH;
|
ret = NETWORK_RECV_STATUS_NEWGRF_MISMATCH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,12 +172,12 @@ void NetworkAfterNewGRFScan()
|
||||||
for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) {
|
for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) {
|
||||||
assert(HasBit(c->flags, GCF_COPY));
|
assert(HasBit(c->flags, GCF_COPY));
|
||||||
|
|
||||||
const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
/* Don't know the GRF, so mark game incompatible and the (possibly)
|
/* Don't know the GRF, so mark game incompatible and the (possibly)
|
||||||
* already resolved name for this GRF (another server has sent the
|
* already resolved name for this GRF (another server has sent the
|
||||||
* name of the GRF already */
|
* name of the GRF already */
|
||||||
c->name = FindUnknownGRFName(c->grfid, c->md5sum, true);
|
c->name = FindUnknownGRFName(c->ident.grfid, c->ident.md5sum, true);
|
||||||
c->status = GCS_NOT_FOUND;
|
c->status = GCS_NOT_FOUND;
|
||||||
|
|
||||||
/* If we miss a file, we're obviously incompatible */
|
/* If we miss a file, we're obviously incompatible */
|
||||||
|
|
|
@ -797,7 +797,7 @@ public:
|
||||||
for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) {
|
for (GRFConfig *c = item->info.grfconfig; c != NULL; c = c->next) {
|
||||||
if (c->status != GCS_NOT_FOUND) continue;
|
if (c->status != GCS_NOT_FOUND) continue;
|
||||||
|
|
||||||
const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
missing_grfs = true;
|
missing_grfs = true;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -202,7 +202,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_CHECK_NEWGRFS)(NetworkClientSocket *
|
||||||
|
|
||||||
p->Send_uint8 (grf_count);
|
p->Send_uint8 (grf_count);
|
||||||
for (c = _grfconfig; c != NULL; c = c->next) {
|
for (c = _grfconfig; c != NULL; c = c->next) {
|
||||||
if (!HasBit(c->flags, GCF_STATIC)) cs->Send_GRFIdentifier(p, c);
|
if (!HasBit(c->flags, GCF_STATIC)) cs->Send_GRFIdentifier(p, &c->ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
cs->Send_Packet(p);
|
cs->Send_Packet(p);
|
||||||
|
|
|
@ -180,16 +180,16 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS)
|
||||||
GRFConfig c;
|
GRFConfig c;
|
||||||
const GRFConfig *f;
|
const GRFConfig *f;
|
||||||
|
|
||||||
this->Recv_GRFIdentifier(p, &c);
|
this->Recv_GRFIdentifier(p, &c.ident);
|
||||||
|
|
||||||
/* Find the matching GRF file */
|
/* Find the matching GRF file */
|
||||||
f = FindGRFConfig(c.grfid, c.md5sum);
|
f = FindGRFConfig(c.ident.grfid, c.ident.md5sum);
|
||||||
if (f == NULL) continue; // The GRF is unknown to this server
|
if (f == NULL) continue; // The GRF is unknown to this server
|
||||||
|
|
||||||
/* If the reply might exceed the size of the packet, only reply
|
/* If the reply might exceed the size of the packet, only reply
|
||||||
* the current list and do not send the other data.
|
* the current list and do not send the other data.
|
||||||
* The name could be an empty string, if so take the filename. */
|
* The name could be an empty string, if so take the filename. */
|
||||||
packet_len += sizeof(c.grfid) + sizeof(c.md5sum) +
|
packet_len += sizeof(c.ident.grfid) + sizeof(c.ident.md5sum) +
|
||||||
min(strlen((!StrEmpty(f->name)) ? f->name : f->filename) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
|
min(strlen((!StrEmpty(f->name)) ? f->name : f->filename) + 1, (size_t)NETWORK_GRF_NAME_LENGTH);
|
||||||
if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply
|
if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply
|
||||||
break;
|
break;
|
||||||
|
@ -207,7 +207,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS)
|
||||||
|
|
||||||
/* The name could be an empty string, if so take the filename */
|
/* The name could be an empty string, if so take the filename */
|
||||||
strecpy(name, (!StrEmpty(in_reply[i]->name)) ? in_reply[i]->name : in_reply[i]->filename, lastof(name));
|
strecpy(name, (!StrEmpty(in_reply[i]->name)) ? in_reply[i]->name : in_reply[i]->filename, lastof(name));
|
||||||
this->Send_GRFIdentifier(&packet, in_reply[i]);
|
this->Send_GRFIdentifier(&packet, &in_reply[i]->ident);
|
||||||
packet.Send_string(name);
|
packet.Send_string(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_RESPONSE)
|
||||||
|
|
||||||
packet.Send_uint8(in_request_count);
|
packet.Send_uint8(in_request_count);
|
||||||
for (i = 0; i < in_request_count; i++) {
|
for (i = 0; i < in_request_count; i++) {
|
||||||
this->Send_GRFIdentifier(&packet, in_request[i]);
|
this->Send_GRFIdentifier(&packet, &in_request[i]->ident);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->SendPacket(&packet, &item->address);
|
this->SendPacket(&packet, &item->address);
|
||||||
|
@ -343,7 +343,7 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_NEWGRFS)
|
||||||
char name[NETWORK_GRF_NAME_LENGTH];
|
char name[NETWORK_GRF_NAME_LENGTH];
|
||||||
GRFConfig c;
|
GRFConfig c;
|
||||||
|
|
||||||
this->Recv_GRFIdentifier(p, &c);
|
this->Recv_GRFIdentifier(p, &c.ident);
|
||||||
p->Recv_string(name, sizeof(name));
|
p->Recv_string(name, sizeof(name));
|
||||||
|
|
||||||
/* An empty name is not possible under normal circumstances
|
/* An empty name is not possible under normal circumstances
|
||||||
|
@ -353,7 +353,7 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_NEWGRFS)
|
||||||
/* Finds the fake GRFConfig for the just read GRF ID and MD5sum tuple.
|
/* Finds the fake GRFConfig for the just read GRF ID and MD5sum tuple.
|
||||||
* If it exists and not resolved yet, then name of the fake GRF is
|
* If it exists and not resolved yet, then name of the fake GRF is
|
||||||
* overwritten with the name from the reply. */
|
* overwritten with the name from the reply. */
|
||||||
unknown_name = FindUnknownGRFName(c.grfid, c.md5sum, false);
|
unknown_name = FindUnknownGRFName(c.ident.grfid, c.ident.md5sum, false);
|
||||||
if (unknown_name != NULL && strcmp(unknown_name, UNKNOWN_GRF_NAME_PLACEHOLDER) == 0) {
|
if (unknown_name != NULL && strcmp(unknown_name, UNKNOWN_GRF_NAME_PLACEHOLDER) == 0) {
|
||||||
ttd_strlcpy(unknown_name, name, NETWORK_GRF_NAME_LENGTH);
|
ttd_strlcpy(unknown_name, name, NETWORK_GRF_NAME_LENGTH);
|
||||||
}
|
}
|
||||||
|
@ -363,12 +363,12 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_NEWGRFS)
|
||||||
void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
|
void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
|
||||||
{
|
{
|
||||||
/* Find the matching GRF file */
|
/* Find the matching GRF file */
|
||||||
const GRFConfig *f = FindGRFConfig(config->grfid, config->md5sum);
|
const GRFConfig *f = FindGRFConfig(config->ident.grfid, config->ident.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
/* Don't know the GRF, so mark game incompatible and the (possibly)
|
/* Don't know the GRF, so mark game incompatible and the (possibly)
|
||||||
* already resolved name for this GRF (another server has sent the
|
* already resolved name for this GRF (another server has sent the
|
||||||
* name of the GRF already */
|
* name of the GRF already */
|
||||||
config->name = FindUnknownGRFName(config->grfid, config->md5sum, true);
|
config->name = FindUnknownGRFName(config->ident.grfid, config->ident.md5sum, true);
|
||||||
config->status = GCS_NOT_FOUND;
|
config->status = GCS_NOT_FOUND;
|
||||||
} else {
|
} else {
|
||||||
config->filename = f->filename;
|
config->filename = f->filename;
|
||||||
|
|
|
@ -4258,7 +4258,7 @@ static void CfgApply(ByteReader *buf)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GRFLocation location(_cur_grfconfig->grfid, _nfo_line + 1);
|
GRFLocation location(_cur_grfconfig->ident.grfid, _nfo_line + 1);
|
||||||
GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
|
GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
|
||||||
if (it != _grf_line_to_action6_sprite_override.end()) {
|
if (it != _grf_line_to_action6_sprite_override.end()) {
|
||||||
free(preload_sprite);
|
free(preload_sprite);
|
||||||
|
@ -4336,7 +4336,7 @@ static void DisableStaticNewGRFInfluencingNonStaticNewGRFs(GRFConfig *c)
|
||||||
c->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC);
|
c->error = new GRFError(STR_NEWGRF_ERROR_MSG_FATAL, STR_NEWGRF_ERROR_STATIC_GRF_CAUSES_DESYNC);
|
||||||
c->error->data = strdup(_cur_grfconfig->name);
|
c->error->data = strdup(_cur_grfconfig->name);
|
||||||
|
|
||||||
ClearTemporaryNewGRFData(GetFileByGRFID(c->grfid));
|
ClearTemporaryNewGRFData(GetFileByGRFID(c->ident.grfid));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Action 0x07
|
/* Action 0x07
|
||||||
|
@ -4510,7 +4510,7 @@ static void ScanInfo(ByteReader *buf)
|
||||||
buf->ReadByte();
|
buf->ReadByte();
|
||||||
uint32 grfid = buf->ReadDWord();
|
uint32 grfid = buf->ReadDWord();
|
||||||
|
|
||||||
_cur_grfconfig->grfid = grfid;
|
_cur_grfconfig->ident.grfid = grfid;
|
||||||
|
|
||||||
/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
|
/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
|
||||||
if (GB(grfid, 24, 8) == 0xFF) SetBit(_cur_grfconfig->flags, GCF_SYSTEM);
|
if (GB(grfid, 24, 8) == 0xFF) SetBit(_cur_grfconfig->flags, GCF_SYSTEM);
|
||||||
|
@ -5177,7 +5177,7 @@ static void SafeGRFInhibit(ByteReader *buf)
|
||||||
uint32 grfid = buf->ReadDWord();
|
uint32 grfid = buf->ReadDWord();
|
||||||
|
|
||||||
/* GRF is unsafe it if tries to deactivate other GRFs */
|
/* GRF is unsafe it if tries to deactivate other GRFs */
|
||||||
if (grfid != _cur_grfconfig->grfid) {
|
if (grfid != _cur_grfconfig->ident.grfid) {
|
||||||
SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
|
SetBit(_cur_grfconfig->flags, GCF_UNSAFE);
|
||||||
|
|
||||||
/* Skip remainder of GRF */
|
/* Skip remainder of GRF */
|
||||||
|
@ -6304,7 +6304,7 @@ static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage)
|
||||||
/* 0x13 */ { NULL, NULL, NULL, NULL, NULL, TranslateGRFStrings, },
|
/* 0x13 */ { NULL, NULL, NULL, NULL, NULL, TranslateGRFStrings, },
|
||||||
};
|
};
|
||||||
|
|
||||||
GRFLocation location(_cur_grfconfig->grfid, _nfo_line);
|
GRFLocation location(_cur_grfconfig->ident.grfid, _nfo_line);
|
||||||
|
|
||||||
GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
|
GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location);
|
||||||
if (it == _grf_line_to_action6_sprite_override.end()) {
|
if (it == _grf_line_to_action6_sprite_override.end()) {
|
||||||
|
@ -6722,7 +6722,7 @@ void LoadNewGRF(uint load_index, uint file_index)
|
||||||
SetBit(c->flags, GCF_RESERVED);
|
SetBit(c->flags, GCF_RESERVED);
|
||||||
} else if (stage == GLS_ACTIVATION) {
|
} else if (stage == GLS_ACTIVATION) {
|
||||||
ClrBit(c->flags, GCF_RESERVED);
|
ClrBit(c->flags, GCF_RESERVED);
|
||||||
assert(GetFileByGRFID(c->grfid) == _cur_grffile);
|
assert(GetFileByGRFID(c->ident.grfid) == _cur_grffile);
|
||||||
ClearTemporaryNewGRFData(_cur_grffile);
|
ClearTemporaryNewGRFData(_cur_grffile);
|
||||||
BuildCargoTranslationMap();
|
BuildCargoTranslationMap();
|
||||||
DEBUG(sprite, 2, "LoadNewGRF: Currently %i sprites are loaded", _cur_spriteid);
|
DEBUG(sprite, 2, "LoadNewGRF: Currently %i sprites are loaded", _cur_spriteid);
|
||||||
|
|
|
@ -69,7 +69,7 @@ static bool CalcGRFMD5Sum(GRFConfig *config)
|
||||||
size -= len;
|
size -= len;
|
||||||
checksum.Append(buffer, len);
|
checksum.Append(buffer, len);
|
||||||
}
|
}
|
||||||
checksum.Finish(config->md5sum);
|
checksum.Finish(config->ident.md5sum);
|
||||||
|
|
||||||
FioFCloseFile(f);
|
FioFCloseFile(f);
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ bool FillGRFDetails(GRFConfig *config, bool is_static)
|
||||||
LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN);
|
LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN);
|
||||||
|
|
||||||
/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */
|
/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */
|
||||||
if (config->grfid == 0 || config->grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false;
|
if (config->ident.grfid == 0 || config->ident.grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false;
|
||||||
|
|
||||||
if (is_static) {
|
if (is_static) {
|
||||||
/* Perform a 'safety scan' for static GRFs */
|
/* Perform a 'safety scan' for static GRFs */
|
||||||
|
@ -200,7 +200,7 @@ static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list)
|
||||||
if (list == NULL) return;
|
if (list == NULL) return;
|
||||||
|
|
||||||
for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) {
|
for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) {
|
||||||
if (cur->grfid != list->grfid) continue;
|
if (cur->ident.grfid != list->ident.grfid) continue;
|
||||||
|
|
||||||
prev->next = cur->next;
|
prev->next = cur->next;
|
||||||
ClearGRFConfig(&cur);
|
ClearGRFConfig(&cur);
|
||||||
|
@ -257,35 +257,35 @@ GRFListCompatibility IsGoodGRFConfigList()
|
||||||
GRFListCompatibility res = GLC_ALL_GOOD;
|
GRFListCompatibility res = GLC_ALL_GOOD;
|
||||||
|
|
||||||
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
|
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
|
||||||
const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
|
||||||
if (f == NULL) {
|
if (f == NULL) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
/* If we have not found the exactly matching GRF try to find one with the
|
/* If we have not found the exactly matching GRF try to find one with the
|
||||||
* same grfid, as it most likely is compatible */
|
* same grfid, as it most likely is compatible */
|
||||||
f = FindGRFConfig(c->grfid);
|
f = FindGRFConfig(c->ident.grfid);
|
||||||
if (f != NULL) {
|
if (f != NULL) {
|
||||||
md5sumToString(buf, lastof(buf), c->md5sum);
|
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
||||||
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->grfid), c->filename, buf);
|
DEBUG(grf, 1, "NewGRF %08X (%s) not found; checksum %s. Compatibility mode on", BSWAP32(c->ident.grfid), c->filename, buf);
|
||||||
SetBit(c->flags, GCF_COMPATIBLE);
|
SetBit(c->flags, GCF_COMPATIBLE);
|
||||||
|
|
||||||
/* Non-found has precedence over compatibility load */
|
/* Non-found has precedence over compatibility load */
|
||||||
if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
|
if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
|
||||||
GamelogGRFCompatible(f);
|
GamelogGRFCompatible(&f->ident);
|
||||||
goto compatible_grf;
|
goto compatible_grf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No compatible grf was found, mark it as disabled */
|
/* No compatible grf was found, mark it as disabled */
|
||||||
md5sumToString(buf, lastof(buf), c->md5sum);
|
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
||||||
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->grfid), c->filename, buf);
|
DEBUG(grf, 0, "NewGRF %08X (%s) not found; checksum %s", BSWAP32(c->ident.grfid), c->filename, buf);
|
||||||
|
|
||||||
GamelogGRFRemove(c->grfid);
|
GamelogGRFRemove(c->ident.grfid);
|
||||||
|
|
||||||
c->status = GCS_NOT_FOUND;
|
c->status = GCS_NOT_FOUND;
|
||||||
res = GLC_NOT_FOUND;
|
res = GLC_NOT_FOUND;
|
||||||
} else {
|
} else {
|
||||||
compatible_grf:
|
compatible_grf:
|
||||||
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->grfid), f->filename);
|
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->ident.grfid), f->filename);
|
||||||
/* The filename could be the filename as in the savegame. As we need
|
/* The filename could be the filename as in the savegame. As we need
|
||||||
* to load the GRF here, we need the correct filename, so overwrite that
|
* to load the GRF here, we need the correct filename, so overwrite that
|
||||||
* in any case and set the name and info when it is not set already.
|
* in any case and set the name and info when it is not set already.
|
||||||
|
@ -294,7 +294,7 @@ compatible_grf:
|
||||||
if (!HasBit(c->flags, GCF_COPY)) {
|
if (!HasBit(c->flags, GCF_COPY)) {
|
||||||
free(c->filename);
|
free(c->filename);
|
||||||
c->filename = strdup(f->filename);
|
c->filename = strdup(f->filename);
|
||||||
memcpy(c->md5sum, f->md5sum, sizeof(c->md5sum));
|
memcpy(c->ident.md5sum, f->ident.md5sum, sizeof(c->ident.md5sum));
|
||||||
if (c->name == NULL && f->name != NULL) c->name = strdup(f->name);
|
if (c->name == NULL && f->name != NULL) c->name = strdup(f->name);
|
||||||
if (c->info == NULL && f->info != NULL) c->info = strdup(f->info);
|
if (c->info == NULL && f->info != NULL) c->info = strdup(f->info);
|
||||||
c->error = NULL;
|
c->error = NULL;
|
||||||
|
@ -333,7 +333,7 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length)
|
||||||
GRFConfig **pd, *d;
|
GRFConfig **pd, *d;
|
||||||
bool stop = false;
|
bool stop = false;
|
||||||
for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
|
for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
|
||||||
if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
|
if (c->ident.grfid == d->ident.grfid && memcmp(c->ident.md5sum, d->ident.md5sum, sizeof(c->ident.md5sum)) == 0) added = false;
|
||||||
/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
|
/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
|
||||||
* before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
|
* before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
|
||||||
* just after the first with the same name. Avoids doubles in the list. */
|
* just after the first with the same name. Avoids doubles in the list. */
|
||||||
|
@ -419,10 +419,10 @@ void ScanNewGRFFiles()
|
||||||
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)
|
const GRFConfig *FindGRFConfig(uint32 grfid, const uint8 *md5sum)
|
||||||
{
|
{
|
||||||
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
|
for (const GRFConfig *c = _all_grfs; c != NULL; c = c->next) {
|
||||||
if (c->grfid == grfid) {
|
if (c->ident.grfid == grfid) {
|
||||||
if (md5sum == NULL) return c;
|
if (md5sum == NULL) return c;
|
||||||
|
|
||||||
if (memcmp(md5sum, c->md5sum, sizeof(c->md5sum)) == 0) return c;
|
if (memcmp(md5sum, c->ident.md5sum, sizeof(c->ident.md5sum)) == 0) return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,7 +486,7 @@ GRFConfig *GetGRFConfig(uint32 grfid, uint32 mask)
|
||||||
GRFConfig *c;
|
GRFConfig *c;
|
||||||
|
|
||||||
for (c = _grfconfig; c != NULL; c = c->next) {
|
for (c = _grfconfig; c != NULL; c = c->next) {
|
||||||
if ((c->grfid & mask) == (grfid & mask)) return c;
|
if ((c->ident.grfid & mask) == (grfid & mask)) return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -517,5 +517,5 @@ static const uint32 OPENTTD_GRAPHICS_BASE_GRF_ID = BSWAP32(0xFF4F5400);
|
||||||
*/
|
*/
|
||||||
bool GRFConfig::IsOpenTTDBaseGRF() const
|
bool GRFConfig::IsOpenTTDBaseGRF() const
|
||||||
{
|
{
|
||||||
return (this->grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID;
|
return (this->ident.grfid & 0x00FFFFFF) == OPENTTD_GRAPHICS_BASE_GRF_ID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,8 @@ struct GRFError : ZeroedMemoryAllocator {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Information about GRF, used in the game and (part of it) in savegames */
|
/** Information about GRF, used in the game and (part of it) in savegames */
|
||||||
struct GRFConfig : public GRFIdentifier {
|
struct GRFConfig {
|
||||||
|
GRFIdentifier ident; ///< grfid and md5sum to uniquely identify newgrfs
|
||||||
char *filename; ///< Filename - either with or without full path
|
char *filename; ///< Filename - either with or without full path
|
||||||
char *name; ///< NOSAVE: GRF name (Action 0x08)
|
char *name; ///< NOSAVE: GRF name (Action 0x08)
|
||||||
char *info; ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
|
char *info; ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
|
||||||
|
|
|
@ -100,12 +100,12 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint right, uint
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare and draw GRF ID */
|
/* Prepare and draw GRF ID */
|
||||||
snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->grfid));
|
snprintf(buff, lengthof(buff), "%08X", BSWAP32(c->ident.grfid));
|
||||||
SetDParamStr(0, buff);
|
SetDParamStr(0, buff);
|
||||||
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_GRF_ID);
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_GRF_ID);
|
||||||
|
|
||||||
/* Prepare and draw MD5 sum */
|
/* Prepare and draw MD5 sum */
|
||||||
md5sumToString(buff, lastof(buff), c->md5sum);
|
md5sumToString(buff, lastof(buff), c->ident.md5sum);
|
||||||
SetDParamStr(0, buff);
|
SetDParamStr(0, buff);
|
||||||
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MD5SUM);
|
y = DrawStringMultiLine(x, right, y, bottom, STR_NEWGRF_SETTINGS_MD5SUM);
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ public:
|
||||||
|
|
||||||
/* Find last entry in the list, checking for duplicate grfid on the way */
|
/* Find last entry in the list, checking for duplicate grfid on the way */
|
||||||
for (list = this->list; *list != NULL; list = &(*list)->next) {
|
for (list = this->list; *list != NULL; list = &(*list)->next) {
|
||||||
if ((*list)->grfid == src->grfid) {
|
if ((*list)->ident.grfid == src->ident.grfid) {
|
||||||
ShowErrorMessage(STR_NEWGRF_DUPLICATE_GRFID, INVALID_STRING_ID, WL_INFO);
|
ShowErrorMessage(STR_NEWGRF_DUPLICATE_GRFID, INVALID_STRING_ID, WL_INFO);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -862,9 +862,9 @@ struct NewGRFWindow : public Window {
|
||||||
ci->type = CONTENT_TYPE_NEWGRF;
|
ci->type = CONTENT_TYPE_NEWGRF;
|
||||||
ci->state = ContentInfo::DOES_NOT_EXIST;
|
ci->state = ContentInfo::DOES_NOT_EXIST;
|
||||||
ttd_strlcpy(ci->name, c->name != NULL ? c->name : c->filename, lengthof(ci->name));
|
ttd_strlcpy(ci->name, c->name != NULL ? c->name : c->filename, lengthof(ci->name));
|
||||||
ci->unique_id = BSWAP32(c->grfid);
|
ci->unique_id = BSWAP32(c->ident.grfid);
|
||||||
memcpy(ci->md5sum, c->md5sum, sizeof(ci->md5sum));
|
memcpy(ci->md5sum, c->ident.md5sum, sizeof(ci->md5sum));
|
||||||
if (HasBit(c->flags, GCF_COMPATIBLE)) GamelogGetOriginalGRFMD5Checksum(c->grfid, ci->md5sum);
|
if (HasBit(c->flags, GCF_COMPATIBLE)) GamelogGetOriginalGRFMD5Checksum(c->ident.grfid, ci->md5sum);
|
||||||
*cv.Append() = ci;
|
*cv.Append() = ci;
|
||||||
}
|
}
|
||||||
ShowNetworkContentListWindow(cv.Length() == 0 ? NULL : &cv, CONTENT_TYPE_NEWGRF);
|
ShowNetworkContentListWindow(cv.Length() == 0 ? NULL : &cv, CONTENT_TYPE_NEWGRF);
|
||||||
|
@ -943,7 +943,7 @@ struct NewGRFWindow : public Window {
|
||||||
for (GRFConfig *c = this->list; c != NULL; c = c->next) {
|
for (GRFConfig *c = this->list; c != NULL; c = c->next) {
|
||||||
if (c->status != GCS_NOT_FOUND) continue;
|
if (c->status != GCS_NOT_FOUND) continue;
|
||||||
|
|
||||||
const GRFConfig *f = FindGRFConfig(c->grfid, c->md5sum);
|
const GRFConfig *f = FindGRFConfig(c->ident.grfid, c->ident.md5sum);
|
||||||
if (f == NULL) continue;
|
if (f == NULL) continue;
|
||||||
|
|
||||||
free(c->filename);
|
free(c->filename);
|
||||||
|
|
|
@ -301,14 +301,14 @@ static void ResetSignalHandlers()
|
||||||
static const GRFIdentifier *GetOverriddenIdentifier(const GRFConfig *c)
|
static const GRFIdentifier *GetOverriddenIdentifier(const GRFConfig *c)
|
||||||
{
|
{
|
||||||
const LoggedAction *la = &_gamelog_action[_gamelog_actions - 1];
|
const LoggedAction *la = &_gamelog_action[_gamelog_actions - 1];
|
||||||
if (la->at != GLAT_LOAD) return c;
|
if (la->at != GLAT_LOAD) return &c->ident;
|
||||||
|
|
||||||
const LoggedChange *lcend = &la->change[la->changes];
|
const LoggedChange *lcend = &la->change[la->changes];
|
||||||
for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
|
for (const LoggedChange *lc = la->change; lc != lcend; lc++) {
|
||||||
if (lc->ct == GLCT_GRFCOMPAT && lc->grfcompat.grfid == c->grfid) return &lc->grfcompat;
|
if (lc->ct == GLCT_GRFCOMPAT && lc->grfcompat.grfid == c->ident.grfid) return &lc->grfcompat;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return &c->ident;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Was the saveload crash because of missing NewGRFs? */
|
/** Was the saveload crash because of missing NewGRFs? */
|
||||||
|
@ -354,13 +354,13 @@ static void CDECL HandleSavegameLoadCrash(int signum)
|
||||||
const GRFIdentifier *replaced = GetOverriddenIdentifier(c);
|
const GRFIdentifier *replaced = GetOverriddenIdentifier(c);
|
||||||
char buf[40];
|
char buf[40];
|
||||||
md5sumToString(buf, lastof(buf), replaced->md5sum);
|
md5sumToString(buf, lastof(buf), replaced->md5sum);
|
||||||
p += seprintf(p, lastof(buffer), "NewGRF %08X (checksum %s) not found.\n Loaded NewGRF \"%s\" with same GRF ID instead.\n", BSWAP32(c->grfid), buf, c->filename);
|
p += seprintf(p, lastof(buffer), "NewGRF %08X (checksum %s) not found.\n Loaded NewGRF \"%s\" with same GRF ID instead.\n", BSWAP32(c->ident.grfid), buf, c->filename);
|
||||||
_saveload_crash_with_missing_newgrfs = true;
|
_saveload_crash_with_missing_newgrfs = true;
|
||||||
}
|
}
|
||||||
if (c->status == GCS_NOT_FOUND) {
|
if (c->status == GCS_NOT_FOUND) {
|
||||||
char buf[40];
|
char buf[40];
|
||||||
md5sumToString(buf, lastof(buf), c->md5sum);
|
md5sumToString(buf, lastof(buf), c->ident.md5sum);
|
||||||
p += seprintf(p, lastof(buffer), "NewGRF %08X (%s) not found; checksum %s.\n", BSWAP32(c->grfid), c->filename, buf);
|
p += seprintf(p, lastof(buffer), "NewGRF %08X (%s) not found; checksum %s.\n", BSWAP32(c->ident.grfid), c->filename, buf);
|
||||||
_saveload_crash_with_missing_newgrfs = true;
|
_saveload_crash_with_missing_newgrfs = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
|
|
||||||
static const SaveLoad _grfconfig_desc[] = {
|
static const SaveLoad _grfconfig_desc[] = {
|
||||||
SLE_STR(GRFConfig, filename, SLE_STR, 0x40),
|
SLE_STR(GRFConfig, filename, SLE_STR, 0x40),
|
||||||
SLE_VAR(GRFConfig, grfid, SLE_UINT32),
|
SLE_VAR(GRFConfig, ident.grfid, SLE_UINT32),
|
||||||
SLE_ARR(GRFConfig, md5sum, SLE_UINT8, 16),
|
SLE_ARR(GRFConfig, ident.md5sum, SLE_UINT8, 16),
|
||||||
SLE_ARR(GRFConfig, param, SLE_UINT32, 0x80),
|
SLE_ARR(GRFConfig, param, SLE_UINT32, 0x80),
|
||||||
SLE_VAR(GRFConfig, num_params, SLE_UINT8),
|
SLE_VAR(GRFConfig, num_params, SLE_UINT8),
|
||||||
SLE_CONDVAR(GRFConfig, windows_paletted, SLE_BOOL, 101, SL_MAX_VERSION),
|
SLE_CONDVAR(GRFConfig, windows_paletted, SLE_BOOL, 101, SL_MAX_VERSION),
|
||||||
|
|
|
@ -1520,11 +1520,11 @@ static bool LoadTTDPatchExtraChunks(LoadgameState *ls, int num)
|
||||||
|
|
||||||
if (ReadByte(ls) == 1) {
|
if (ReadByte(ls) == 1) {
|
||||||
GRFConfig *c = CallocT<GRFConfig>(1);
|
GRFConfig *c = CallocT<GRFConfig>(1);
|
||||||
c->grfid = grfid;
|
c->ident.grfid = grfid;
|
||||||
c->filename = strdup("TTDP game, no information");
|
c->filename = strdup("TTDP game, no information");
|
||||||
|
|
||||||
AppendToGRFConfigList(&_grfconfig, c);
|
AppendToGRFConfigList(&_grfconfig, c);
|
||||||
DEBUG(oldloader, 3, "TTDPatch game using GRF file with GRFID %0X", BSWAP32(c->grfid));
|
DEBUG(oldloader, 3, "TTDPatch game using GRF file with GRFID %0X", BSWAP32(c->ident.grfid));
|
||||||
}
|
}
|
||||||
len -= 5;
|
len -= 5;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1224,7 +1224,7 @@ static GRFConfig *GRFLoadConfig(IniFile *ini, const char *grpname, bool is_stati
|
||||||
/* Check for duplicate GRFID (will also check for duplicate filenames) */
|
/* Check for duplicate GRFID (will also check for duplicate filenames) */
|
||||||
bool duplicate = false;
|
bool duplicate = false;
|
||||||
for (const GRFConfig *gc = first; gc != NULL; gc = gc->next) {
|
for (const GRFConfig *gc = first; gc != NULL; gc = gc->next) {
|
||||||
if (gc->grfid == c->grfid) {
|
if (gc->ident.grfid == c->ident.grfid) {
|
||||||
ShowInfoF("ini: ignoring NewGRF '%s': duplicate GRF ID with '%s'", item->name, gc->filename);
|
ShowInfoF("ini: ignoring NewGRF '%s': duplicate GRF ID with '%s'", item->name, gc->filename);
|
||||||
duplicate = true;
|
duplicate = true;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue