summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2005-08-31 21:21:18 +0000
committerSimon Howard2005-08-31 21:21:18 +0000
commit457bca3961bd9493747194831923b4e30288513a (patch)
tree30ce047c713a5573609bf8d9480aa6ec4f73c0d1
parentf51fa9af948a581e291274867439214e5ae3e04f (diff)
downloadchocolate-doom-457bca3961bd9493747194831923b4e30288513a.tar.gz
chocolate-doom-457bca3961bd9493747194831923b4e30288513a.tar.bz2
chocolate-doom-457bca3961bd9493747194831923b4e30288513a.zip
Better IWAD detection and identification. Support '-iwad' to specify
the IWAD to use. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 59
-rw-r--r--src/d_main.c339
-rw-r--r--src/doomstat.c9
-rw-r--r--src/doomstat.h7
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 <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#endif
+#include <string.h>
#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<sizeof(iwads) / sizeof(*iwads); ++i)
+ {
+ char *filename = malloc(strlen(dir) + strlen(iwads[i].name) + 3);
+
+ sprintf(filename, "%s/%s", dir, iwads[i].name);
+
+ if (FileExists(filename))
+ {
+ iwadfile = filename;
+ gamemission = iwads[i].mission;
+ D_AddFile(filename);
+ result = 1;
+ break;
+ }
+ else
+ {
+ free(filename);
+ }
+ }
- // Bug, dear Shawn.
- // Insufficient malloc, caused spurious realloc errors.
- plutoniawad = malloc(strlen(doomwaddir)+1+/*9*/12+1);
- sprintf(plutoniawad, "%s/plutonia.wad", doomwaddir);
+ return result;
+}
- tntwad = malloc(strlen(doomwaddir)+1+9+1);
- sprintf(tntwad, "%s/tnt.wad", doomwaddir);
+// When given an IWAD with the '-iwad' parameter,
+// attempt to identify it by its name.
+static void IdentifyIWADByName(char *name)
+{
+ int i;
- // French stuff.
- doom2fwad = malloc(strlen(doomwaddir)+1+10+1);
- sprintf(doom2fwad, "%s/doom2f.wad", doomwaddir);
+ for (i=0; i<sizeof(iwads) / sizeof(*iwads); ++i)
+ {
+ if (strlen(name) < strlen(iwads[i].name))
+ continue;
- home = getenv("HOME");
- if (!home)
- I_Error("Please set $HOME to your home directory");
- sprintf(basedefault, "%s/.doomrc", home);
-#endif
+ // Check if it ends in this IWAD name.
- if (M_CheckParm ("-shdev"))
- {
- gamemode = shareware;
- devparm = true;
- D_AddFile (DEVDATA"doom1.wad");
- D_AddFile (DEVMAPS"data_se/texture1.lmp");
- D_AddFile (DEVMAPS"data_se/pnames.lmp");
- strcpy (basedefault,DEVDATA"default.cfg");
- return;
+ if (!strcasecmp(name + strlen(name) - strlen(iwads[i].name),
+ iwads[i].name))
+ {
+ gamemission = iwads[i].mission;
+ break;
+ }
}
- if (M_CheckParm ("-regdev"))
- {
- gamemode = registered;
- devparm = true;
- D_AddFile (DEVDATA"doom.wad");
- D_AddFile (DEVMAPS"data_se/texture1.lmp");
- D_AddFile (DEVMAPS"data_se/texture2.lmp");
- D_AddFile (DEVMAPS"data_se/pnames.lmp");
- strcpy (basedefault,DEVDATA"default.cfg");
- return;
- }
+ gamemission = none;
+}
- if (M_CheckParm ("-comdev"))
- {
- gamemode = commercial;
- devparm = true;
- /* I don't bother
- if(plutonia)
- D_AddFile (DEVDATA"plutonia.wad");
- else if(tnt)
- D_AddFile (DEVDATA"tnt.wad");
- else*/
- D_AddFile (DEVDATA"doom2.wad");
-
- D_AddFile (DEVMAPS"cdata/texture1.lmp");
- D_AddFile (DEVMAPS"cdata/pnames.lmp");
- strcpy (basedefault,DEVDATA"default.cfg");
- return;
- }
+//
+// FindIWAD
+// Checks availability of IWAD files by name,
+// to determine whether registered/commercial features
+// should be executed (notably loading PWAD's).
+//
+static void FindIWAD (void)
+{
+ char *doomwaddir;
+ int result;
+ int iwadparm;
- if ( !access (doom2fwad,R_OK) )
- {
- gamemode = commercial;
- // C'est ridicule!
- // Let's handle languages in config files, okay?
- language = french;
- printf("French version\n");
- D_AddFile (doom2fwad);
- return;
- }
+ result = 0;
+ doomwaddir = getenv("DOOMWADDIR");
+ iwadparm = M_CheckParm("-iwad");
- if ( !access (doom2wad,R_OK) )
+ if (iwadparm)
{
- gamemode = commercial;
- D_AddFile (doom2wad);
- return;
+ iwadfile = myargv[iwadparm + 1];
+ D_AddFile(iwadfile);
+ IdentifyIWADByName(iwadfile);
+ result = 1;
}
-
- if ( !access (plutoniawad, R_OK ) )
+ else if (doomwaddir != NULL)
{
- gamemode = commercial;
- D_AddFile (plutoniawad);
- return;
+ result = SearchDirectoryForIWAD(doomwaddir);
}
- if ( !access ( tntwad, R_OK ) )
+ if (result == 0)
{
- gamemode = commercial;
- D_AddFile (tntwad);
- return;
+ result = SearchDirectoryForIWAD(".")
+ || SearchDirectoryForIWAD("/usr/share/games/doom")
+ || SearchDirectoryForIWAD("/usr/local/share/games/doom");
}
- if ( !access (doomuwad,R_OK) )
+ if (result == 0)
{
- gamemode = retail;
- D_AddFile (doomuwad);
- return;
+ I_Error("Game mode indeterminate. No IWAD file was found. Try\n"
+ "specifying one with the '-iwad' command line parameter.\n");
}
+}
+
+//
+// Find out what version of Doom is playing.
+//
+
+static void IdentifyVersion(void)
+{
+ // gamemission is set up by the FindIWAD function. But if
+ // we specify '-iwad', we have to identify using
+ // IdentifyIWADByName. However, if the iwad does not match
+ // any known IWAD name, we may have a dilemma. Try to
+ // identify by its contents.
- if ( !access (doomwad,R_OK) )
+ if (gamemission == none)
{
- gamemode = registered;
- D_AddFile (doomwad);
- return;
+ int i;
+
+ for (i=0; i<numlumps; ++i)
+ {
+ if (!strncasecmp(lumpinfo[i].name, "MAP01", 8))
+ {
+ gamemission = doom2;
+ break;
+ }
+ else if (!strncasecmp(lumpinfo[i].name, "E1M1", 8))
+ {
+ gamemission = doom;
+ break;
+ }
+ }
+
+ if (gamemission == none)
+ {
+ // Still no idea. I don't think this is going to work.
+
+ I_Error("Unknown or invalid IWAD file.");
+ }
}
- if ( !access (doom1wad,R_OK) )
+ // Make sure gamemode is set up correctly
+
+ if (gamemission == doom)
{
- gamemode = shareware;
- D_AddFile (doom1wad);
- return;
+ // Doom 1. But which version?
+
+ if (W_CheckNumForName("E4M1") > 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
//