|
@@ -12,24 +12,26 @@
|
|
|
#include "newgrf.h"
|
|
|
#include "md5.h"
|
|
|
#include "variables.h"
|
|
|
#include "fontcache.h"
|
|
|
#include "gfx_func.h"
|
|
|
#include "core/alloc_func.hpp"
|
|
|
#include "core/bitmath_func.hpp"
|
|
|
#include <string.h>
|
|
|
#include "settings_type.h"
|
|
|
|
|
|
#include "table/sprites.h"
|
|
|
|
|
|
Palette _use_palette = PAL_AUTODETECT;
|
|
|
|
|
|
struct MD5File {
|
|
|
const char * filename; ///< filename
|
|
|
uint8 hash[16]; ///< md5 sum of the file
|
|
|
};
|
|
|
|
|
|
struct FileList {
|
|
|
MD5File basic[2]; ///< GRF files that always have to be loaded
|
|
|
MD5File landscape[3]; ///< Landscape specific grf files
|
|
|
MD5File sound; ///< Sound samples
|
|
|
MD5File openttd; ///< GRF File with OTTD specific graphics
|
|
|
};
|
|
|
|
|
@@ -121,56 +123,56 @@ static bool FileMD5(const MD5File file)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Determine the palette that has to be used.
|
|
|
* - 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
|
|
|
*/
|
|
|
static void DeterminePalette()
|
|
|
{
|
|
|
if (_use_dos_palette) return;
|
|
|
if (_use_palette < MAX_PAL) return;
|
|
|
|
|
|
/* Count of files from the different versions. */
|
|
|
uint dos = 0;
|
|
|
uint win = 0;
|
|
|
|
|
|
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 (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++;
|
|
|
|
|
|
if (win == 5) {
|
|
|
_use_dos_palette = false;
|
|
|
_use_palette = PAL_WINDOWS;
|
|
|
} else if (dos == 5 || (win == 0 && dos > 0)) {
|
|
|
_use_dos_palette = true;
|
|
|
_use_palette = PAL_DOS;
|
|
|
} else {
|
|
|
_use_dos_palette = false;
|
|
|
_use_palette = PAL_WINDOWS;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 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;
|
|
|
const FileList *files = (_use_palette == PAL_DOS) ? &files_dos : &files_win;
|
|
|
char error_msg[ERROR_MESSAGE_LENGTH * (lengthof(files->basic) + lengthof(files->landscape) + 3)];
|
|
|
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])) {
|
|
@@ -183,25 +185,25 @@ void CheckExternalFiles()
|
|
|
}
|
|
|
|
|
|
if (!FileMD5(files->openttd)) {
|
|
|
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.filename);
|
|
|
}
|
|
|
|
|
|
if (add_pos != error_msg) ShowInfoF(error_msg);
|
|
|
}
|
|
|
|
|
|
|
|
|
static void LoadSpriteTables()
|
|
|
{
|
|
|
const FileList *files = _use_dos_palette ? &files_dos : &files_win;
|
|
|
const FileList *files = (_use_palette == PAL_DOS) ? &files_dos : &files_win;
|
|
|
uint i = FIRST_GRF_SLOT;
|
|
|
|
|
|
LoadGrfFile(files->basic[0].filename, 0, 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++);
|
|
|
|