From 457bca3961bd9493747194831923b4e30288513a Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 31 Aug 2005 21:21:18 +0000 Subject: Better IWAD detection and identification. Support '-iwad' to specify the IWAD to use. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 59 --- src/d_main.c | 339 ++++++++++++++++++++++++++++++++++----------------------- src/doomstat.c | 9 +- src/doomstat.h | 7 +- 3 files changed, 216 insertions(+), 139 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 8f4683bd..e4eecaac 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: d_main.c 57 2005-08-30 22:11:10Z fraggle $ +// $Id: d_main.c 59 2005-08-31 21:21:18Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,10 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.7 2005/08/31 21:21:18 fraggle +// Better IWAD detection and identification. Support '-iwad' to specify +// the IWAD to use. +// // Revision 1.6 2005/08/30 22:11:10 fraggle // Windows fixes // @@ -53,20 +57,15 @@ //----------------------------------------------------------------------------- -static const char rcsid[] = "$Id: d_main.c 57 2005-08-30 22:11:10Z fraggle $"; +static const char rcsid[] = "$Id: d_main.c 59 2005-08-31 21:21:18Z fraggle $"; #define BGCOLOR 7 #define FGCOLOR 8 -#ifdef NORMALUNIX #include #include -#include -#include -#include -#include -#endif +#include #include "config.h" @@ -118,6 +117,7 @@ static const char rcsid[] = "$Id: d_main.c 57 2005-08-30 22:11:10Z fraggle $"; void D_DoomLoop (void); +char* iwadfile; char* wadfiles[MAXWADFILES]; @@ -573,166 +573,214 @@ void D_AddFile (char *file) wadfiles[numwadfiles] = newfile; } -// -// IdentifyVersion -// Checks availability of IWAD files by name, -// to determine whether registered/commercial features -// should be executed (notably loading PWAD's). -// -void IdentifyVersion (void) -{ +// Check if a file exists - char* doom1wad; - char* doomwad; - char* doomuwad; - char* doom2wad; +static int FileExists(char *filename) +{ + FILE *fstream; - char* doom2fwad; - char* plutoniawad; - char* tntwad; + fstream = fopen(filename, "r"); -#ifdef NORMALUNIX - char *home; - char *doomwaddir; - doomwaddir = getenv("DOOMWADDIR"); - if (!doomwaddir) - doomwaddir = "."; + if (fstream != NULL) + { + fclose(fstream); + return 1; + } + else + { + return 0; + } +} - // Commercial. - doom2wad = malloc(strlen(doomwaddir)+1+9+1); - sprintf(doom2wad, "%s/doom2.wad", doomwaddir); +struct +{ + char *name; + GameMission_t mission; +} iwads[] = { + {"doom.wad", doom}, + {"doom2.wad", doom2}, + {"tnt.wad", pack_tnt}, + {"plutonia.wad", pack_plut}, + {"doom1.wad", doom}, +}; + +// Search a directory to try to find an IWAD +// Returns non-zero if successful + +static int SearchDirectoryForIWAD(char *dir) +{ + int i; + int result; + + result = 0; - // Retail. - doomuwad = malloc(strlen(doomwaddir)+1+8+1); - sprintf(doomuwad, "%s/doomu.wad", doomwaddir); - - // Registered. - doomwad = malloc(strlen(doomwaddir)+1+8+1); - sprintf(doomwad, "%s/doom.wad", doomwaddir); - - // Shareware. - doom1wad = malloc(strlen(doomwaddir)+1+9+1); - sprintf(doom1wad, "%s/doom1.wad", doomwaddir); + for (i=0; i 0) + { + // Ultimate Doom + + gamedescription = "The Ultimate DOOM"; + gamemode = retail; + } + else if (W_CheckNumForName("E3M1") > 0) + { + gamedescription = "DOOM Registered"; + gamemode = registered; + } + else + { + gamedescription = "DOOM Shareware"; + gamemode = shareware; + } } + else + { + // Doom 2 of some kind. But which mission? - printf("Game mode indeterminate.\n"); - gamemode = indetermined; + gamemode = commercial; - // We don't abort. Let's see what the PWAD contains. - //exit(1); - //I_Error ("Game mode indeterminate\n"); + if (gamemission == doom2) + gamedescription = "DOOM 2: Hell on Earth"; + else if (gamemission == pack_plut) + gamedescription = "DOOM 2: Plutonia Experiment"; + else if (gamemission == pack_tnt) + gamedescription = "DOOM 2: TNT - Evilution"; + } + + printf("%s\n", gamedescription); } // @@ -808,6 +856,18 @@ void FindResponseFile (void) } } +// Startup banner + +void PrintBanner(void) +{ + int i; + + for (i=0; i<39-(strlen(PACKAGE_STRING) / 2); ++i) + putchar(' '); + + puts(PACKAGE_STRING); +} + // // D_DoomMain @@ -819,7 +879,7 @@ void D_DoomMain (void) FindResponseFile (); - IdentifyVersion (); + FindIWAD (); setbuf (stdout, NULL); modifiedgame = false; @@ -833,6 +893,11 @@ void D_DoomMain (void) else if (M_CheckParm ("-deathmatch")) deathmatch = 1; + // print banner + + PrintBanner(); + +#if 0 switch ( gamemode ) { case retail: @@ -887,8 +952,9 @@ void D_DoomMain (void) DOOM_VERSION/100,DOOM_VERSION%100); break; } - printf ("%s\n",title); +#endif + if (devparm) printf(D_DEVSTR); @@ -1043,6 +1109,7 @@ void D_DoomMain (void) printf ("W_Init: Init WADfiles.\n"); W_InitMultipleFiles (wadfiles); + IdentifyVersion(); // Check for -file in shareware if (modifiedgame) diff --git a/src/doomstat.c b/src/doomstat.c index 1e4cbbba..69225241 100644 --- a/src/doomstat.c +++ b/src/doomstat.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: doomstat.c 18 2005-07-23 18:56:07Z fraggle $ +// $Id: doomstat.c 59 2005-08-31 21:21:18Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,10 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.4 2005/08/31 21:21:18 fraggle +// Better IWAD detection and identification. Support '-iwad' to specify +// the IWAD to use. +// // Revision 1.3 2005/07/23 18:56:07 fraggle // Remove unneccessary pragmas // @@ -38,7 +42,7 @@ //----------------------------------------------------------------------------- static const char -rcsid[] = "$Id: doomstat.c 18 2005-07-23 18:56:07Z fraggle $"; +rcsid[] = "$Id: doomstat.c 59 2005-08-31 21:21:18Z fraggle $"; #include "doomstat.h" @@ -47,6 +51,7 @@ rcsid[] = "$Id: doomstat.c 18 2005-07-23 18:56:07Z fraggle $"; // Game Mode - identify IWAD as shareware, retail etc. GameMode_t gamemode = indetermined; GameMission_t gamemission = doom; +char *gamedescription; // Language. Language_t language = english; diff --git a/src/doomstat.h b/src/doomstat.h index 45c53253..a36193c0 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: doomstat.h 18 2005-07-23 18:56:07Z fraggle $ +// $Id: doomstat.h 59 2005-08-31 21:21:18Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -63,6 +63,7 @@ extern boolean devparm; // DEBUG: launched with -devparm // extern GameMode_t gamemode; extern GameMission_t gamemission; +extern char *gamedescription; // Set if homebrew PWAD stuff has been added. extern boolean modifiedgame; @@ -296,6 +297,10 @@ extern int ticdup; //----------------------------------------------------------------------------- // // $Log$ +// Revision 1.4 2005/08/31 21:21:18 fraggle +// Better IWAD detection and identification. Support '-iwad' to specify +// the IWAD to use. +// // Revision 1.3 2005/07/23 18:56:07 fraggle // Remove unneccessary pragmas // -- cgit v1.2.3