From: Holger Schemel Date: Sat, 25 Feb 2017 19:05:58 +0000 (+0100) Subject: added detecting Mirror Magic style level files from magic bytes X-Git-Tag: 4.1.0.0~188 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=a78298a20ffab02cb74bb0ec44cf47461c4cce63;p=rocksndiamonds.git added detecting Mirror Magic style level files from magic bytes --- diff --git a/src/files.c b/src/files.c index 0f478eb1..bf0237f2 100644 --- a/src/files.c +++ b/src/files.c @@ -1918,6 +1918,26 @@ static int getFileTypeFromBasename(char *basename) return LEVEL_FILE_TYPE_UNKNOWN; } +static int getFileTypeFromMagicBytes(char *filename, int type) +{ + File *file; + + if ((file = openFile(filename, MODE_READ))) + { + char chunk_name[CHUNK_ID_LEN + 1]; + + getFileChunkBE(file, chunk_name, NULL); + + if (strEqual(chunk_name, "MMII") || + strEqual(chunk_name, "MIRR")) + type = LEVEL_FILE_TYPE_MM; + + closeFile(file); + } + + return type; +} + static boolean checkForPackageFromBasename(char *basename) { /* !!! WON'T WORK ANYMORE IF getFileTypeFromBasename() ALSO DETECTS !!! @@ -2184,6 +2204,9 @@ static void determineLevelFileInfo_Filetype(struct LevelFileInfo *lfi) { if (lfi->type == LEVEL_FILE_TYPE_UNKNOWN) lfi->type = getFileTypeFromBasename(lfi->basename); + + if (lfi->type == LEVEL_FILE_TYPE_RND) + lfi->type = getFileTypeFromMagicBytes(lfi->filename, lfi->type); } static void setLevelFileInfo(struct LevelFileInfo *level_file_info, int nr)