From 37c6b72103cc9d7965a669cdca01edae83f765e4 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 21 Dec 2006 21:43:47 +0000 Subject: Split off IWAD-related code into separate d_iwad.c. On Windows, search the registry to automatically find the locations of installed IWADs. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 791 --- src/Makefile.am | 1 + src/d_iwad.c | 622 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/d_iwad.h | 36 ++++ src/d_main.c | 437 ++++----------------------------------- src/m_misc.c | 19 ++ src/m_misc.h | 2 + 6 files changed, 716 insertions(+), 401 deletions(-) create mode 100644 src/d_iwad.c create mode 100644 src/d_iwad.h diff --git a/src/Makefile.am b/src/Makefile.am index 6ffac860..d34a5b17 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,6 +40,7 @@ deh_weapon.c \ d_englsh.h \ d_event.h \ d_items.c d_items.h \ +d_iwad.c d_iwad.h \ d_main.c d_main.h \ d_net.c d_net.h \ doomdata.h \ diff --git a/src/d_iwad.c b/src/d_iwad.c new file mode 100644 index 00000000..96e0670c --- /dev/null +++ b/src/d_iwad.c @@ -0,0 +1,622 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 2006 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// DESCRIPTION: +// Search for and locate an IWAD file, and initialise according +// to the IWAD type. +// +//----------------------------------------------------------------------------- + +#include +#include +#include +#include + +#include "deh_main.h" +#include "doomdef.h" +#include "doomstat.h" +#include "i_system.h" +#include "m_argv.h" +#include "m_misc.h" +#include "w_wad.h" +#include "z_zone.h" + +// Array of locations to search for IWAD files + +#define MAX_IWAD_DIRS 32 +static char *iwad_dirs[MAX_IWAD_DIRS]; +static int num_iwad_dirs = 0; + +static void AddIWADDir(char *dir) +{ + iwad_dirs[num_iwad_dirs] = dir; + ++num_iwad_dirs; +} + +// This is Windows-specific code that automatically finds the location +// of installed IWAD files. The registry is inspected to find special +// keys installed by the Windows installers for various CD versions +// of Doom. From these keys we can deduce where to find an IWAD. + +#ifdef _WIN32 + +#define WIN32_LEAN_AND_MEAN +#include + +typedef struct +{ + HKEY root; + char *path; + char *value; +} registry_value_t; + +#define UNINSTALLER_STRING "\\uninstl.exe /S " + +// Keys installed by the various CD editions. These are actually the +// commands to invoke the uninstaller and look like this: +// +// C:\Program Files\Path\uninstl.exe /S C:\Program Files\Path +// +// With some munging we can find where Doom was installed. + +static registry_value_t uninstall_values[] = +{ + // Ultimate Doom, CD version (Depths of Doom trilogy) + + { + HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Windows\\CurrentVersion\\" + "Uninstall\\Ultimate Doom for Windows 95", + "UninstallString", + }, + + // Doom II, CD version (Depths of Doom trilogy) + + { + HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Windows\\CurrentVersion\\" + "Uninstall\\Doom II for Windows 95", + "UninstallString", + }, + + // Final Doom + + { + HKEY_LOCAL_MACHINE, + "Software\\Microsoft\\Windows\\CurrentVersion\\" + "Uninstall\\Final Doom for Windows 95", + "UninstallString", + }, +}; + +// Value installed by the Collector's Edition when it is installed + +static registry_value_t collectors_edition_value = +{ + HKEY_LOCAL_MACHINE, + "Software\\Activision\\DOOM Collector's Edition\\v1.0", + "INSTALLPATH", +}; + +// Subdirectories of the above install path, where IWADs are installed. + +static char *collectors_edition_subdirs[] = +{ + "Doom2", + "Final Doom", + "Ultimate Doom", +}; + +static char *GetRegistryString(registry_value_t *reg_val) +{ + HKEY key; + int len; + int valtype; + char *result; + + // Open the key (directory where the value is stored) + + if (RegOpenKeyEx(reg_val->root, reg_val->path, 0, KEY_READ, &key) + != ERROR_SUCCESS) + { + return NULL; + } + + // Find the type and length of the string + + if (RegQueryValueEx(key, reg_val->value, NULL, &valtype, NULL, &len) + != ERROR_SUCCESS) + { + return NULL; + } + + // Only accept strings + + if (valtype != REG_SZ) + { + return NULL; + } + + // Allocate a buffer for the value and read the value + + result = Z_Malloc(len, PU_STATIC, 0); + + if (RegQueryValueEx(key, reg_val->value, NULL, &valtype, result, &len) + != ERROR_SUCCESS) + { + Z_Free(result); + return NULL; + } + + // Close the key + + RegCloseKey(key); + + return result; +} + +// Check for the uninstall strings from the CD versions + +static void CheckUninstallStrings(void) +{ + int i; + + for (i=0; i 0) + { + // Ultimate Doom + + gamemode = retail; + } + else if (W_CheckNumForName("E3M1") > 0) + { + gamemode = registered; + } + else + { + gamemode = shareware; + } + } + else + { + // Doom 2 of some kind. + + gamemode = commercial; + } +} + +// Set the gamedescription string + +void D_SetGameDescription(void) +{ + gamedescription = "Unknown"; + + if (gamemission == doom) + { + // Doom 1. But which version? + + if (gamemode == retail) + { + // Ultimate Doom + + gamedescription = GetGameName("The Ultimate DOOM"); + } + else if (gamemode == registered) + { + gamedescription = GetGameName("DOOM Registered"); + } + else if (gamemode == shareware) + { + gamedescription = GetGameName("DOOM Shareware"); + } + } + else + { + // Doom 2 of some kind. But which mission? + + if (gamemission == doom2) + gamedescription = GetGameName("DOOM 2: Hell on Earth"); + else if (gamemission == pack_plut) + gamedescription = GetGameName("DOOM 2: Plutonia Experiment"); + else if (gamemission == pack_tnt) + gamedescription = GetGameName("DOOM 2: TNT - Evilution"); + } +} + diff --git a/src/d_iwad.h b/src/d_iwad.h new file mode 100644 index 00000000..404d7efb --- /dev/null +++ b/src/d_iwad.h @@ -0,0 +1,36 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 2006 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// DESCRIPTION: +// Find IWAD and initialise according to IWAD type. +// +//----------------------------------------------------------------------------- + + +#ifndef __D_IWAD__ +#define __D_IWAD__ + +char *D_FindIWAD(void); +void D_SetSaveGameDir(void); +void D_IdentifyVersion(void); +void D_SetGameDescription(void); + +#endif + diff --git a/src/d_main.c b/src/d_main.c index f77c55cf..a8c46a95 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -28,11 +28,6 @@ //----------------------------------------------------------------------------- - -#define BGCOLOR 7 -#define FGCOLOR 8 - - #include #include #include @@ -47,6 +42,7 @@ #include "doomfeatures.h" #include "sounds.h" +#include "d_iwad.h" #include "z_zone.h" #include "w_wad.h" @@ -595,345 +591,6 @@ static boolean D_AddFile(char *filename) return handle != NULL; } - -// Check if a file exists - -static int FileExists(char *filename) -{ - FILE *fstream; - - fstream = fopen(filename, "r"); - - if (fstream != NULL) - { - fclose(fstream); - return 1; - } - else - { - return 0; - } -} - -struct -{ - char *name; - GameMission_t mission; -} iwads[] = { - {"doom2.wad", doom2}, - {"plutonia.wad", pack_plut}, - {"tnt.wad", pack_tnt}, - {"doom.wad", doom}, - {"doom1.wad", doom}, -}; - -// Search a directory to try to find an IWAD -// Returns the location of the IWAD if found, otherwise NULL. - -static char *SearchDirectoryForIWAD(char *dir) -{ - size_t i; - - for (i=0; i 0) - { - // Ultimate Doom - - gamemode = retail; - } - else if (W_CheckNumForName("E3M1") > 0) - { - gamemode = registered; - } - else - { - gamemode = shareware; - } - } - else - { - // Doom 2 of some kind. - - gamemode = commercial; - } -} - -// Set the gamedescription string - -static void SetGameDescription(void) -{ - gamedescription = "Unknown"; - - if (gamemission == doom) - { - // Doom 1. But which version? - - if (gamemode == retail) - { - // Ultimate Doom - - gamedescription = GetGameName("The Ultimate DOOM"); - } - else if (gamemode == registered) - { - gamedescription = GetGameName("DOOM Registered"); - } - else if (gamemode == shareware) - { - gamedescription = GetGameName("DOOM Shareware"); - } - } - else - { - // Doom 2 of some kind. But which mission? - - if (gamemission == doom2) - gamedescription = GetGameName("DOOM 2: Hell on Earth"); - else if (gamemission == pack_plut) - gamedescription = GetGameName("DOOM 2: Plutonia Experiment"); - else if (gamemission == pack_tnt) - gamedescription = GetGameName("DOOM 2: TNT - Evilution"); - } -} - #define MAXARGVS 100 static void LoadResponseFile(int argv_index) @@ -1107,6 +764,29 @@ void PrintBanner(char *msg) puts(msg); } +// Copyright message banners +// Some dehacked mods replace these. These are only displayed if they are +// replaced by dehacked. + +static char *copyright_banners[] = +{ + "===========================================================================\n" + "ATTENTION: This version of DOOM has been modified. If you would like to\n" + "get a copy of the original game, call 1-800-IDGAMES or see the readme file.\n" + " You will not receive technical support for modified games.\n" + " press enter to continue\n" + "===========================================================================\n", + + "===========================================================================\n" + " Commercial product - do not distribute!\n" + " Please report software piracy to the SPA: 1-800-388-PIR8\n" + "===========================================================================\n", + + "===========================================================================\n" + " Shareware!\n" + "===========================================================================\n" +}; + // Prints a message only if it has been modified by dehacked. void PrintDehackedBanners(void) @@ -1134,57 +814,6 @@ void PrintDehackedBanners(void) } } -// -// SetSaveGameDir -// -// Chooses the directory used to store saved games. -// - -static void SetSaveGameDir(void) -{ - size_t i; - - if (!strcmp(configdir, "")) - { - // Use the current directory, just like configdir. - - savegamedir = strdup(""); - } - else - { - // Directory for savegames - - savegamedir = malloc(strlen(configdir) + 30); - sprintf(savegamedir, "%ssavegames", configdir); - - M_MakeDirectory(savegamedir); - - // Find what subdirectory to use for savegames - // - // They should be stored in something like - // ~/.chocolate-doom/savegames/doom.wad/ - // - // The directory depends on the IWAD, so that savegames for - // different IWADs are kept separate. - // - // Note that we match on gamemission rather than on IWAD name. - // This ensures that doom1.wad and doom.wad saves are stored - // in the same place. - - for (i=0; i