From 8cae6e48779beb3dc8e95a5c32b422b2504b5722 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Tue, 30 Sep 2008 22:50:24 +0000 Subject: Move d_iwad.c into common code and update Heretic to use it on startup to locate the IWAD file. Subversion-branch: /branches/raven-branch Subversion-revision: 1308 --- src/doom/Makefile.am | 1 - src/doom/d_iwad.c | 913 --------------------------------------------------- src/doom/d_iwad.h | 39 --- src/doom/d_main.c | 238 +++++++++++++- 4 files changed, 233 insertions(+), 958 deletions(-) delete mode 100644 src/doom/d_iwad.c delete mode 100644 src/doom/d_iwad.h (limited to 'src/doom') diff --git a/src/doom/Makefile.am b/src/doom/Makefile.am index 5982721f..7b7073b6 100644 --- a/src/doom/Makefile.am +++ b/src/doom/Makefile.am @@ -6,7 +6,6 @@ SOURCE_FILES= \ am_map.c am_map.h \ d_englsh.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/doom/d_iwad.c b/src/doom/d_iwad.c deleted file mode 100644 index dcf2651a..00000000 --- a/src/doom/d_iwad.c +++ /dev/null @@ -1,913 +0,0 @@ -// 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 "doomkeys.h" -#include "doomdef.h" -#include "doomstat.h" -#include "i_system.h" -#include "m_argv.h" -#include "m_config.h" -#include "m_misc.h" -#include "w_wad.h" -#include "z_zone.h" - -// Array of locations to search for IWAD files -// -// "128 IWAD search directories should be enough for anybody". - -#define MAX_IWAD_DIRS 128 - -static boolean iwad_dirs_built = false; -static char *iwad_dirs[MAX_IWAD_DIRS]; -static int num_iwad_dirs = 0; - -static void AddIWADDir(char *dir) -{ - if (num_iwad_dirs < MAX_IWAD_DIRS) - { - 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", - }, - - // Shareware version - - { - HKEY_LOCAL_MACHINE, - "Software\\Microsoft\\Windows\\CurrentVersion\\" - "Uninstall\\Doom Shareware 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", -}; - -// Location where Steam is installed - -static registry_value_t steam_install_location = -{ - HKEY_LOCAL_MACHINE, - "Software\\Valve\\Steam", - "InstallPath", -}; - -// Subdirs of the steam install directory where IWADs are found - -static char *steam_install_subdirs[] = -{ - "steamapps\\common\\doom 2\\base", - "steamapps\\common\\final doom\\base", - "steamapps\\common\\ultimate doom\\base", -}; - -static char *GetRegistryString(registry_value_t *reg_val) -{ - HKEY key; - DWORD len; - DWORD 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 = malloc(len); - - if (RegQueryValueEx(key, reg_val->value, NULL, &valtype, (unsigned char *) result, &len) - != ERROR_SUCCESS) - { - free(result); - return NULL; - } - - // Close the key - - RegCloseKey(key); - - return result; -} - -// Check for the uninstall strings from the CD versions - -static void CheckUninstallStrings(void) -{ - unsigned int i; - - for (i=0; i - // - - iwadparm = M_CheckParm("-iwad"); - - if (iwadparm) - { - // Search through IWAD dirs for an IWAD with the given name. - - iwadfile = myargv[iwadparm + 1]; - - result = D_FindWADByName(iwadfile); - - if (result == NULL) - { - I_Error("IWAD file '%s' not found!", iwadfile); - } - - IdentifyIWADByName(result); - } - else - { - // Search through the list and look for an IWAD - - result = NULL; - - BuildIWADDirList(); - - for (i=0; result == NULL && 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"); - } -} - -// Clever hack: Setup can invoke Doom to determine which IWADs are installed. -// Doom searches install paths and exits with the return code being a -// bitmask of the installed IWAD files. - -void D_FindInstalledIWADs(void) -{ - unsigned int i; - int result; - - BuildIWADDirList(); - - result = 0; - - 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"); + } +} + +static void SetSaveGameDir(char *iwad_filename) +{ + char *sep; + char *basefile; + + // Extract the base filename + + sep = strrchr(iwad_filename, DIR_SEPARATOR); + + if (sep == NULL) + { + basefile = iwad_filename; + } + else + { + basefile = sep + 1; + } + + // eg. ~/.chocolate-doom/savegames/doom2.wad/ + + savegamedir = malloc(strlen(configdir) + strlen(basefile) + 10); + sprintf(savegamedir, "%ssavegames%c%s%c", + configdir, DIR_SEPARATOR, basefile, DIR_SEPARATOR); +} + +// Check if the IWAD file is the Chex Quest IWAD. +// Returns true if this is chex.wad. + +static boolean CheckChex(char *iwadname) +{ + char *chex_iwadname = "chex.wad"; + return (strlen(iwadname) > strlen(chex_iwadname) + && !strcasecmp(iwadname + strlen(iwadname) - strlen(chex_iwadname), + chex_iwadname)); +} // print title for every printed line char title[128]; @@ -711,9 +937,11 @@ static void InitGameVersion(void) { // Determine automatically - if (gameversion == exe_chex) + if (CheckChex(iwadfile)) { - // Already determined + // chex.exe - identified by iwad filename + + gameversion = exe_chex; } else if (gamemode == shareware || gamemode == registered) { @@ -833,7 +1061,7 @@ void D_DoomMain (void) if (M_CheckParm("-findiwads") > 0) { - D_FindInstalledIWADs(); + D_FindInstalledIWADs(iwads); } // print banner @@ -890,7 +1118,7 @@ void D_DoomMain (void) DEH_Init(); #endif - iwadfile = D_FindIWAD(); + iwadfile = D_FindIWAD(iwads, &gamemission); // None found? @@ -1259,7 +1487,7 @@ void D_DoomMain (void) InitGameVersion(); LoadChexDeh(); D_SetGameDescription(); - D_SetSaveGameDir(); + SetSaveGameDir(iwadfile); // Check for -file in shareware if (modifiedgame) -- cgit v1.2.3