changeset 15331:fcc18215652e draft

(svn r19972) -Change: Use the md5sum from the previous save of the game for BaNaNaS instead of the initial (when the grf was added) md5sum from the gamelog. Neither method is 'better', but this way it is independent from the gamelog.
author frosch <frosch@openttd.org>
date Sun, 13 Jun 2010 14:11:32 +0000
parents 839bc68a738c
children e2d08cace39d
files src/gamelog.cpp src/gamelog.h src/newgrf_config.cpp src/newgrf_config.h src/newgrf_gui.cpp
diffstat 5 files changed, 9 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/gamelog.cpp
+++ b/src/gamelog.cpp
@@ -705,30 +705,3 @@
 	free(ol);
 	free(nl);
 }
-
-/**
- * Get the MD5 checksum of the original NewGRF that was loaded.
- * @param grfid the GRF ID to search for
- * @param md5sum the MD5 checksum to write to.
- */
-void GamelogGetOriginalGRFMD5Checksum(uint32 grfid, byte *md5sum)
-{
-	const LoggedAction *la = &_gamelog_action[_gamelog_actions - 1];
-	/* There should always be a "start game" action */
-	assert(_gamelog_actions > 0);
-
-	do {
-		const LoggedChange *lc = &la->change[la->changes - 1];
-		/* There should always be at least one change per action */
-		assert(la->changes > 0);
-
-		do {
-			if (lc->ct == GLCT_GRFADD && lc->grfadd.grfid == grfid) {
-				memcpy(md5sum, lc->grfadd.md5sum, sizeof(lc->grfadd.md5sum));
-				return;
-			}
-		} while (lc-- != la->change);
-	} while (la-- != _gamelog_action);
-
-	NOT_REACHED();
-}
--- a/src/gamelog.h
+++ b/src/gamelog.h
@@ -57,6 +57,4 @@
 
 bool GamelogGRFBugReverse(uint32 grfid, uint16 internal_id);
 
-void GamelogGetOriginalGRFMD5Checksum(uint32 grfid, byte *md5sum);
-
 #endif /* GAMELOG_H */
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -299,7 +299,11 @@
 			if (f != NULL) {
 				md5sumToString(buf, lastof(buf), c->ident.md5sum);
 				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);
+				if (!HasBit(c->flags, GCF_COMPATIBLE)) {
+					/* Preserve original_md5sum after it has been assigned */
+					SetBit(c->flags, GCF_COMPATIBLE);
+					memcpy(c->original_md5sum, c->ident.md5sum, sizeof(c->original_md5sum));
+				}
 
 				/* Non-found has precedence over compatibility load */
 				if (res != GLC_NOT_FOUND) res = GLC_COMPATIBLE;
--- a/src/newgrf_config.h
+++ b/src/newgrf_config.h
@@ -86,6 +86,7 @@
 	~GRFConfig();
 
 	GRFIdentifier ident; ///< grfid and md5sum to uniquely identify newgrfs
+	uint8 original_md5sum[16]; ///< MD5 checksum of original file if only a 'compatible' file was loaded
 	char *filename;     ///< Filename - either with or without full path
 	char *name;         ///< NOSAVE: GRF name (Action 0x08)
 	char *info;         ///< NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -604,9 +604,9 @@
 					ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
 				} else {
 #if defined(ENABLE_NETWORK)
-				this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
+					this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window
 
-				/* Only show the things in the current list, or everything when nothing's selected */
+					/* Only show the things in the current list, or everything when nothing's selected */
 					ContentVector cv;
 					for (const GRFConfig *c = this->actives; c != NULL; c = c->next) {
 						if (c->status != GCS_NOT_FOUND && !HasBit(c->flags, GCF_COMPATIBLE)) continue;
@@ -616,8 +616,7 @@
 						ci->state = ContentInfo::DOES_NOT_EXIST;
 						ttd_strlcpy(ci->name, c->GetName(), lengthof(ci->name));
 						ci->unique_id = BSWAP32(c->ident.grfid);
-						memcpy(ci->md5sum, c->ident.md5sum, sizeof(ci->md5sum));
-						if (HasBit(c->flags, GCF_COMPATIBLE)) GamelogGetOriginalGRFMD5Checksum(c->ident.grfid, ci->md5sum);
+						memcpy(ci->md5sum, HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum, sizeof(ci->md5sum));
 						*cv.Append() = ci;
 					}
 					ShowNetworkContentListWindow(cv.Length() == 0 ? NULL : &cv, CONTENT_TYPE_NEWGRF);