From: Simon McVittie Date: Fri, 6 Aug 2010 20:26:40 +0100 Subject: [PATCH] FS_FOpenFileRead: allow loading any demo, not just the current protocol Origin: vendor, Debian Bug: http://bugzilla.icculus.org/show_bug.cgi?id=4698 Forwarded: yes --- code/qcommon/files.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-) diff --git a/code/qcommon/files.c b/code/qcommon/files.c index 3d2a2a4..9e76a0b 100644 --- a/code/qcommon/files.c +++ b/code/qcommon/files.c @@ -992,6 +992,14 @@ qboolean FS_FilenameCompare( const char *s1, const char *s2 ) { return qfalse; // strings are equal } +static ID_INLINE qboolean extension_is_demo( const char *filename, int len ) { + return (Q_stricmpn (filename + len - 6, ".dm_", 4) == 0 && + filename[len - 2] >= '0' && + filename[len - 2] <= '9' && + filename[len - 1] >= '0' && + filename[len - 1] <= '9' ); +} + /* =========== FS_FOpenFileRead @@ -1013,7 +1021,6 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF long hash; FILE *temp; int l; - char demoExt[16]; hash = 0; @@ -1060,7 +1067,6 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF Com_Error( ERR_FATAL, "FS_FOpenFileRead: NULL 'filename' parameter passed\n" ); } - Com_sprintf (demoExt, sizeof(demoExt), ".dm_%d",PROTOCOL_VERSION ); // qpaths are not supposed to have a leading slash if ( filename[0] == '/' || filename[0] == '\\' ) { filename++; @@ -1177,7 +1183,7 @@ int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueF if ( Q_stricmp( filename + l - 4, ".cfg" ) // for config files && Q_stricmp( filename + l - 5, ".menu" ) // menu files && Q_stricmp( filename + l - 5, ".game" ) // menu files - && Q_stricmp( filename + l - strlen(demoExt), demoExt ) // menu files + && !extension_is_demo( filename, l ) // demos && Q_stricmp( filename + l - 4, ".dat" ) ) { // for journal files continue; } --