diff --git a/bin/data/dosdummy.grf b/bin/data/dosdummy.grf deleted file mode 100644 index 6524d59714bc0e37256acd1f7f422e480baaee36..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ leave it that way + * - all Windows files present -> Windows palette + * - all DOS files present -> DOS palette + * - no Windows files present and any DOS file present -> DOS palette + * - otherwise -> Windows palette + */ +static void DeterminePalette() { - uint i; - /* count of files from this version */ + if (_use_dos_palette) return; + + /* Count of files from the different versions. */ uint dos = 0; uint win = 0; - for (i = 0; i < 2; i++) if (FileMD5(files_dos.basic[i], true)) dos++; - for (i = 0; i < 3; i++) if (FileMD5(files_dos.landscape[i], true)) dos++; - - for (i = 0; i < 2; i++) if (FileMD5(files_win.basic[i], true)) win++; - for (i = 0; i < 3; i++) if (FileMD5(files_win.landscape[i], true)) win++; - - if (!FileMD5(sample_cat_win, false) && !FileMD5(sample_cat_dos, false)) - ShowInfo("Your 'sample.cat' file is corrupted or missing!"); + for (uint i = 0; i < lengthof(files_dos.basic); i++) if (FioCheckFileExists(files_dos.basic[i].filename)) dos++; + for (uint i = 0; i < lengthof(files_dos.landscape); i++) if (FioCheckFileExists(files_dos.landscape[i].filename)) dos++; - for (i = 0; i < lengthof(files_openttd); i++) { - if (!FileMD5(files_openttd[i], false)) { - ShowInfoF("Your '%s' file is corrupted or missing!", files_openttd[i].filename); - } - } + for (uint i = 0; i < lengthof(files_win.basic); i++) if (FioCheckFileExists(files_win.basic[i].filename)) win++; + for (uint i = 0; i < lengthof(files_win.landscape); i++) if (FioCheckFileExists(files_win.landscape[i].filename)) win++; - /* - * forced DOS palette via command line -> leave it that way - * all Windows files present -> Windows palette - * all DOS files present -> DOS palette - * no Windows files present and any DOS file present -> DOS palette - * otherwise -> Windows palette - */ - if (_use_dos_palette) { - return; - } else if (win == 5) { + if (win == 5) { _use_dos_palette = false; } else if (dos == 5 || (win == 0 && dos > 0)) { _use_dos_palette = true; @@ -192,6 +172,46 @@ void CheckExternalFiles() } } +/** + * Checks whether the MD5 checksums of the files are correct. + * + * @note Also checks sample.cat and other required non-NewGRF GRFs for corruption. + */ +void CheckExternalFiles() +{ + DeterminePalette(); + + static const size_t ERROR_MESSAGE_LENGTH = 128; + const FileList *files = _use_dos_palette ? &files_dos : &files_win; + char error_msg[ERROR_MESSAGE_LENGTH * (lengthof(files->basic) + lengthof(files->landscape) + lengthof(files_openttd) + 1)]; + error_msg[0] = '\0'; + char *add_pos = error_msg; + + for (uint i = 0; i < lengthof(files->basic); i++) { + if (!FileMD5(files->basic[i])) { + add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! You can find '%s' on your Transport Tycoon Deluxe CD-ROM.\n", files->basic[i].filename, files->basic[i].filename); + } + } + + for (uint i = 0; i < lengthof(files->landscape); i++) { + if (!FileMD5(files->landscape[i])) { + add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! You can find '%s' on your Transport Tycoon Deluxe CD-ROM.\n", files->landscape[i].filename, files->landscape[i].filename); + } + } + + if (!FileMD5(sample_cat_win) && !FileMD5(sample_cat_dos)) { + add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your 'sample.cat' file is corrupted or missing! You can find 'sample.cat' on your Transport Tycoon Deluxe CD-ROM.\n"); + } + + for (uint i = 0; i < lengthof(files_openttd); i++) { + if (!FileMD5(files_openttd[i])) { + add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! The file was part of your installation.\n", files_openttd[i].filename); + } + } + + if (add_pos != error_msg) ShowInfoF(error_msg); +} + static const SpriteID trg1idx[] = { 0, 1, ///< Mouse cursor, ZZZ @@ -332,7 +352,7 @@ static const SpriteID _openttd_grf_index static void LoadSpriteTables() { - const FileList* files = _use_dos_palette ? &files_dos : &files_win; + const FileList *files = _use_dos_palette ? &files_dos : &files_win; uint load_index; uint i = FIRST_GRF_SLOT; @@ -340,13 +360,20 @@ static void LoadSpriteTables() DupSprite( 2, 130); // non-breaking space medium DupSprite(226, 354); // non-breaking space tiny DupSprite(450, 578); // non-breaking space large - load_index = 4793; - for (uint j = 1; files->basic[j].filename != NULL; j++) { - load_index += LoadGrfFile(files->basic[j].filename, load_index, i++); - } + /* + * The second basic file always starts at the given location and does + * contain a different amount of sprites depending on the "type"; DOS + * has a few sprites less. However, we do not care about those missing + * sprites as they are not shown anyway (logos in intro game). + */ + LoadGrfFile(files->basic[1].filename, 4793, i++); - /* Load additional sprites for climates other than temperate */ + /* + * Load additional sprites for climates other than temperate. + * This overwrites some of the temperate sprites, such as foundations + * and the ground sprites. + */ if (_opt.landscape != LT_TEMPERATE) { LoadGrfIndexed( files->landscape[_opt.landscape - 1].filename, @@ -355,7 +382,8 @@ static void LoadSpriteTables() ); } - assert(load_index == SPR_SIGNALS_BASE); + /* Start loading the extra, non-TTD, base GRFs for the given index. */ + load_index = SPR_SIGNALS_BASE; load_index += LoadGrfFile("nsignalsw.grf", load_index, i++); assert(load_index == SPR_CANALS_BASE); diff --git a/src/table/files.h b/src/table/files.h --- a/src/table/files.h +++ b/src/table/files.h @@ -26,9 +26,7 @@ static FileList files_dos = { { { "TRG1.GRF", {0x93, 0x11, 0x67, 0x62, 0x80, 0xe5, 0xb1, 0x40, 0x77, 0xa8, 0xee, 0x41, 0xc1, 0xb4, 0x21, 0x92} }, // 0 - 4792 inclusive - { "TRGI.GRF", {0xda, 0x6a, 0x6c, 0x9d, 0xcc, 0x45, 0x1e, 0xec, 0x88, 0xd7, 0x92, 0x11, 0x43, 0x7b, 0x76, 0xa8} }, // 4793 - 4889 inclusive - { "dosdummy.grf", {0x07, 0x01, 0xe6, 0xc4, 0x07, 0x6a, 0x5b, 0xc3, 0xf4, 0x9f, 0x01, 0xad, 0x21, 0x6c, 0xa0, 0xc2} }, // 4890 - 4895 inclusive - { NULL, { 0 } } + { "TRGI.GRF", {0xda, 0x6a, 0x6c, 0x9d, 0xcc, 0x45, 0x1e, 0xec, 0x88, 0xd7, 0x92, 0x11, 0x43, 0x7b, 0x76, 0xa8} } // 4793 - 4889 inclusive }, { { "TRGC.GRF", {0xed, 0x44, 0x66, 0x37, 0xe0, 0x34, 0x10, 0x4c, 0x55, 0x59, 0xb3, 0x2c, 0x18, 0xaf, 0xe7, 0x8d} }, { "TRGH.GRF", {0xee, 0x66, 0x16, 0xfb, 0x0e, 0x6e, 0xf6, 0xb2, 0x48, 0x92, 0xc5, 0x8c, 0x93, 0xd8, 0x6f, 0xc9} }, @@ -39,9 +37,7 @@ static FileList files_dos = { static FileList files_win = { { { "TRG1R.GRF", {0xb0, 0x4c, 0xe5, 0x93, 0xd8, 0xc5, 0x01, 0x6e, 0x07, 0x47, 0x3a, 0x74, 0x3d, 0x7d, 0x33, 0x58} }, // 0 - 4792 inclusive - { "TRGIR.GRF", {0x0c, 0x24, 0x84, 0xff, 0x6b, 0xe4, 0x9f, 0xc6, 0x3a, 0x83, 0xbe, 0x6a, 0xb5, 0xc3, 0x8f, 0x32} }, // 4793 - 4895 inclusive - { NULL, { 0 } }, - { NULL, { 0 } } + { "TRGIR.GRF", {0x0c, 0x24, 0x84, 0xff, 0x6b, 0xe4, 0x9f, 0xc6, 0x3a, 0x83, 0xbe, 0x6a, 0xb5, 0xc3, 0x8f, 0x32} } // 4793 - 4895 inclusive }, { { "TRGCR.GRF", {0x36, 0x68, 0xf4, 0x10, 0xc7, 0x61, 0xa0, 0x50, 0xb5, 0xe7, 0x09, 0x5a, 0x2b, 0x14, 0x87, 0x9b} }, { "TRGHR.GRF", {0x06, 0xbf, 0x2b, 0x7a, 0x31, 0x76, 0x6f, 0x04, 0x8b, 0xaa, 0xc2, 0xeb, 0xe4, 0x34, 0x57, 0xb1} },