Example #1
0
static char *CheckDirectoryHasIWAD(char *dir, char *iwadname)
{
    char *filename; 

    // As a special case, the "directory" may refer directly to an
    // IWAD file if the path comes from DOOMWADDIR or DOOMWADPATH.
    
    if (DirIsFile(dir, iwadname) && M_FileExists(dir))
    {
        return strdup(dir);
    }

    // Construct the full path to the IWAD if it is located in
    // this directory, and check if it exists.

    filename = malloc(strlen(dir) + strlen(iwadname) + 3);

    if (!strcmp(dir, "."))
    {
        strcpy(filename, iwadname);
    }
    else
    {
        sprintf(filename, "%s%c%s", dir, DIR_SEPARATOR, iwadname);
    }

    if (M_FileExists(filename))
    {
        return filename;
    }

    free(filename);

    return NULL;
}
Example #2
0
char *D_FindWADByName(char *name)
{
    char        *path;
    int         i;

    // Absolute path?
    if (M_FileExists(name))
        return name;

    BuildIWADDirList();

    // Search through all IWAD paths for a file with the given name.
    for (i = 0; i < num_iwad_dirs; ++i)
    {
        // As a special case, if this is in DOOMWADDIR or DOOMWADPATH,
        // the "directory" may actually refer directly to an IWAD
        // file.
        if (D_CheckFilename(iwad_dirs[i], name) && M_FileExists(iwad_dirs[i]))
            return strdup(iwad_dirs[i]);

        // Construct a string for the full path
        path = M_StringJoin(iwad_dirs[i], DIR_SEPARATOR_S, name, NULL);

        if (M_FileExists(path))
            return path;

        free(path);
    }

    // File not found
    return NULL;
}
Example #3
0
static char *CheckDirectoryHasIWAD(char *dir, char *iwadname)
{
    char *filename; 

    // As a special case, the "directory" may refer directly to an
    // IWAD file if the path comes from DOOMWADDIR or DOOMWADPATH.

    if (DirIsFile(dir, iwadname) && M_FileExists(dir))
    {
        return M_StringDuplicate(dir);
    }

    // Construct the full path to the IWAD if it is located in
    // this directory, and check if it exists.

    if (!strcmp(dir, "."))
    {
        filename = M_StringDuplicate(iwadname);
    }
    else
    {
        filename = M_StringJoin(dir, DIR_SEPARATOR_S, iwadname, NULL);
    }

    if (M_FileExists(filename))
    {
        return filename;
    }

    free(filename);

    return NULL;
}
Example #4
0
void CheckTimidityConfig(void)
{
    if (*s_timiditycfgpath)
        if (M_FileExists(s_timiditycfgpath))
            C_Output("Using TiMidity configuration file %s.", uppercase(s_timiditycfgpath));
        else
            C_Warning("Can't find TiMidity configuration file %s.", uppercase(s_timiditycfgpath));
}
Example #5
0
//
// BaseFileSearch
// denis - Check all paths of interest for a given file with a possible extension
//
static std::string BaseFileSearch(std::string file, std::string ext = "", std::string hash = "")
{
	#ifdef _WIN32
		// absolute path?
		if(file.find(':') != std::string::npos)
			return file;

		const char separator = ';';
	#else
		// absolute path?
		if(file[0] == PATHSEPCHAR || file[0] == '~')
			return file;

		const char separator = ':';
	#endif

    // [Russell] - Bit of a hack. (since BaseFileSearchDir should handle this)
    // return file if it contains a path already
	if (M_FileExists(file))
		return file;

	std::transform(file.begin(), file.end(), file.begin(), toupper);
	std::transform(ext.begin(), ext.end(), ext.begin(), toupper);
	std::vector<std::string> dirs;

	dirs.push_back(startdir);
	dirs.push_back(progdir);

	D_AddSearchDir(dirs, Args.CheckValue("-waddir"), separator);
	D_AddSearchDir(dirs, getenv("DOOMWADDIR"), separator);
	D_AddSearchDir(dirs, getenv("DOOMWADPATH"), separator);
	D_AddSearchDir(dirs, getenv("HOME"), separator);

	// [AM] Search additional paths based on platform
	D_AddPlatformSearchDirs(dirs);

	D_AddSearchDir(dirs, waddirs.cstring(), separator);

	dirs.erase(std::unique(dirs.begin(), dirs.end()), dirs.end());

	for(size_t i = 0; i < dirs.size(); i++)
	{
		std::string found = BaseFileSearchDir(dirs[i], file, ext, hash);

		if(found.length())
		{
			std::string &dir = dirs[i];

			if(dir[dir.length() - 1] != PATHSEPCHAR)
				dir += PATHSEP;

			return dir + found;
		}
	}

	// Not found
	return "";
}
Example #6
0
char *D_FindWADByName(char *name)
{
    char *buf;
    int i;
    
    // Absolute path?

    if (M_FileExists(name))
    {
        return name;
    }

    BuildIWADDirList();
    
    // Search through all IWAD paths for a file with the given name.

    for (i=0; i<num_iwad_dirs; ++i)
    {
        // As a special case, if this is in DOOMWADDIR or DOOMWADPATH,
        // the "directory" may actually refer directly to an IWAD
        // file.

        if (DirIsFile(iwad_dirs[i], name) && M_FileExists(iwad_dirs[i]))
        {
            return strdup(iwad_dirs[i]);
        }

        // Construct a string for the full path

        buf = malloc(strlen(iwad_dirs[i]) + strlen(name) + 5);
        sprintf(buf, "%s%c%s", iwad_dirs[i], DIR_SEPARATOR, name);

        if (M_FileExists(buf))
        {
            return buf;
        }

        free(buf);
    }

    // File not found

    return NULL;
}
Example #7
0
//===========================================================================
// W_IsIWAD
//  Returns true iff the given filename exists and is an IWAD.
//===========================================================================
int W_IsIWAD(char *fn)
{
	FILE   *file;
	char    id[5];

	if(!M_FileExists(fn))
		return false;
	if((file = fopen(fn, "rb")) == NULL)
		return false;
	fread(id, 4, 1, file);
	id[4] = 0;
	fclose(file);
	return !stricmp(id, "IWAD");
}
Example #8
0
static void LoadChexDeh(void)
{
    char *chex_deh = NULL;
    char *sep;

    if (gameversion == exe_chex)
    {
        // Look for chex.deh in the same directory as the IWAD file.

        sep = strrchr(iwadfile, DIR_SEPARATOR);

        if (sep != NULL)
        {
            size_t chex_deh_len = strlen(iwadfile) + 9;
            chex_deh = malloc(chex_deh_len);
            M_StringCopy(chex_deh, iwadfile, chex_deh_len);
            chex_deh[sep - iwadfile + 1] = '\0';
            M_StringConcat(chex_deh, "chex.deh", chex_deh_len);
        }
        else
        {
            chex_deh = strdup("chex.deh");
        }

        // If the dehacked patch isn't found, try searching the WAD
        // search path instead.  We might find it...

        if (!M_FileExists(chex_deh))
        {
            free(chex_deh);
            chex_deh = D_FindWADByName("chex.deh");
        }

        // Still not found?

        if (chex_deh == NULL)
        {
            I_Error("Unable to find Chex Quest dehacked file (chex.deh).\n"
                    "The dehacked file is required in order to emulate\n"
                    "chex.exe correctly.  It can be found in your nearest\n"
                    "/idgames repository mirror at:\n\n"
                    "   utils/exe_edit/patches/chexdeh.zip");
        }

        if (!DEH_LoadFile(chex_deh))
        {
            I_Error("Failed to load chex.deh needed for emulating chex.exe.");
        }
    }
}
Example #9
0
//
// M_SaveMoveHereToMap
//
// Moves the "HERE" save to a map.
//
void M_SaveMoveHereToMap(void)
{
    char *mapsave  = NULL;
    char *heresave = NULL;
    char tmpnum[33];

    // haleyjd: no itoa available...
    M_snprintf(tmpnum, sizeof(tmpnum), "%d", gamemap);

    mapsave  = M_SafeFilePath(savepathtemp, tmpnum);
    heresave = M_SafeFilePath(savepathtemp, "here");

    if(M_FileExists(heresave))
    {
        remove(mapsave);
        rename(heresave, mapsave);
    }

    Z_Free(mapsave);
    Z_Free(heresave);
}
Example #10
0
//
// M_SaveMoveMapToHere
//
// Moves a map to the "HERE" save.
//
void M_SaveMoveMapToHere(void)
{
    char *mapsave  = NULL;
    char *heresave = NULL;
    char tmpnum[33];

    // haleyjd: no itoa available...
    M_snprintf(tmpnum, sizeof(tmpnum), "%d", gamemap);

    // haleyjd: use M_SafeFilePath, not sprintf
    mapsave  = M_SafeFilePath(savepath, tmpnum);
    heresave = M_SafeFilePath(savepath, "here");

    // haleyjd: use M_FileExists, not access
    if(M_FileExists(mapsave))
    {
        remove(heresave);
        rename(mapsave, heresave);
    }

    Z_Free(mapsave);
    Z_Free(heresave);
}
Example #11
0
static void CheckSteamGUSPatches(void)
{
    const char *current_path;
    char *install_path;
    char *patch_path;
    int len;

    // Already configured? Don't stomp on the user's choices.
    current_path = M_GetStringVariable("gus_patch_path");
    if (current_path != NULL && strlen(current_path) > 0)
    {
        return;
    }

    install_path = GetRegistryString(&steam_install_location);

    if (install_path == NULL)
    {
        return;
    }

    len = strlen(install_path) + strlen(STEAM_BFG_GUS_PATCHES) + 20;
    patch_path = malloc(len);
    M_snprintf(patch_path, len, "%s\\%s\\ACBASS.PAT",
               install_path, STEAM_BFG_GUS_PATCHES);

    // Does acbass.pat exist? If so, then set gus_patch_path.
    if (M_FileExists(patch_path))
    {
        M_snprintf(patch_path, len, "%s\\%s",
                   install_path, STEAM_BFG_GUS_PATCHES);
        M_SetVariable("gus_patch_path", patch_path);
    }

    free(patch_path);
    free(install_path);
}
Example #12
0
//===========================================================================
// W_CheckIWAD
//  Checks if an IWAD has been loaded. If not, tries to load one of the
//  default ones.
//===========================================================================
void W_CheckIWAD(void)
{
	extern char *iwadlist[];
	int     i;

	if(iwadLoaded)
		return;

	// Try one of the default IWADs.
	for(i = 0; iwadlist[i]; i++)
	{
		if(M_FileExists(iwadlist[i]))
			W_AddFile(iwadlist[i], false);
		// We can leave as soon as an IWAD is found.
		if(iwadLoaded)
			return;
	}

	if(!Sys_CriticalMessage
	   ("No IWAD has been specified! "
		"Important data might be missing. Are you sure you "
		"want to continue?"))
		Con_Error("W_CheckIWAD: Init aborted.\n");
}
Example #13
0
//
// CheckIWAD
//
// Tries to find an IWAD from a set of know IWAD names, and checks the first
// one found's contents to determine whether registered/commercial features
// should be executed (notably loading PWAD's).
//
static bool CheckIWAD (std::string suggestion, std::string &titlestring)
{
	static const char *doomwadnames[] =
	{
		"doom2f.wad",
		"doom2.wad",
		"plutonia.wad",
		"tnt.wad",
		"doomu.wad", // Hack from original Linux version. Not necessary, but I threw it in anyway.
		"doom.wad",
		"doom1.wad",
		"freedoom.wad",
		"freedm.wad",
		"chex.wad",		// [ML] 1/7/10: Hello Chex Quest!
		NULL
	};

	std::string iwad;
	std::string iwad_file;
	int i;

	if(suggestion.length())
	{
		std::string found = BaseFileSearch(suggestion, ".WAD");

		if(found.length())
			iwad = found;
		else
		{
			if(M_FileExists(suggestion.c_str()))
				iwad = suggestion;
		}
		/*	[ML] Removed 1/13/10: we can trust the user to provide an iwad
		if(iwad.length())
		{
			FILE *f;

			if ( (f = fopen (iwad.c_str(), "rb")) )
			{
				wadinfo_t header;
				fread (&header, sizeof(header), 1, f);
				header.identification = LONG(header.identification);
				if (header.identification != IWAD_ID)
				{
					if(header.identification == PWAD_ID)
					{
						Printf(PRINT_HIGH, "Suggested file is a PWAD, not an IWAD: %s \n", iwad.c_str());
					}
					else
					{
						Printf(PRINT_HIGH, "Suggested file is not an IWAD: %s \n", iwad.c_str());
					}
					iwad = "";
				}
				fclose(f);
			}
		}
		*/
	}

	if(!iwad.length())
	{
		// Search for a pre-defined IWAD from the list above
		for (i = 0; doomwadnames[i]; i++)
		{
			std::string found = BaseFileSearch(doomwadnames[i]);

			if(found.length())
			{
				iwad = found;
				break;
			}
		}
	}

	// Now scan the contents of the IWAD to determine which one it is
	if (iwad.length())
	{
#define NUM_CHECKLUMPS 9
		static const char checklumps[NUM_CHECKLUMPS][8] = {
			"E1M1", "E2M1", "E4M1", "MAP01",
			{ 'A','N','I','M','D','E','F','S'},
			"FINAL2", "REDTNT2", "CAMO1",
			{ 'E','X','T','E','N','D','E','D'}
		};
		int lumpsfound[NUM_CHECKLUMPS];
		wadinfo_t header;
		FILE *f;
		M_ExtractFileName(iwad,iwad_file);

		memset (lumpsfound, 0, sizeof(lumpsfound));
		if ( (f = fopen (iwad.c_str(), "rb")) )
		{
			fread (&header, sizeof(header), 1, f);
			header.identification = LONG(header.identification);
			if (header.identification == IWAD_ID ||
				header.identification == PWAD_ID)
			{
				header.numlumps = LONG(header.numlumps);
				if (0 == fseek (f, LONG(header.infotableofs), SEEK_SET))
				{
					for (i = 0; i < header.numlumps; i++)
					{
						filelump_t lump;
						int j;

						if (0 == fread (&lump, sizeof(lump), 1, f))
							break;
						for (j = 0; j < NUM_CHECKLUMPS; j++)
							if (!strnicmp (lump.name, checklumps[j], 8))
								lumpsfound[j]++;
					}
				}
			}
			fclose (f);
		}

		gamemode = undetermined;

		if (lumpsfound[3])
		{
			gamemode = commercial;
			gameinfo = CommercialGameInfo;
			if (lumpsfound[6])
			{
				gamemission = pack_tnt;
				titlestring = "DOOM 2: TNT - Evilution";
			}
			else if (lumpsfound[7])
			{
				gamemission = pack_plut;
				titlestring = "DOOM 2: Plutonia Experiment";
			}
			else
			{
				gamemission = doom2;
				titlestring = "DOOM 2: Hell on Earth";
			}
		}
		else if (lumpsfound[0])
		{
			gamemission = doom;
			if (lumpsfound[1])
			{
				if (lumpsfound[2])
				{
					if (!StdStringCompare(iwad_file,"chex.wad",true))	// [ML] 1/7/10: HACK - There's no unique lumps in the chex quest
					{								// iwad.  It's ultimate doom with their stuff replacing most things.
						gamemission = chex;
						gamemode = retail_chex;
						gameinfo = RetailGameInfo;
						titlestring = "Chex Quest";
					}
					else
					{
						gamemode = retail;
						gameinfo = RetailGameInfo;
						titlestring = "The Ultimate DOOM";
					}
				}
				else
				{
					gamemode = registered;
					gameinfo = RegisteredGameInfo;
					titlestring = "DOOM Registered";
				}
			}
			else
			{
				gamemode = shareware;
				gameinfo = SharewareGameInfo;
				titlestring = "DOOM Shareware";
			}
		}
	}

	if (gamemode == undetermined)
	{
		gameinfo = SharewareGameInfo;
	}

	if (iwad.length())
		wadfiles.push_back(iwad);

	return iwad.length() ? true : false;
}
Example #14
0
void IntDownloadComplete(void)
{
    std::string actual_md5 = MD5SUM(download.buf->ptr(), download.buf->maxsize());

	Printf(PRINT_HIGH, "\nDownload complete, got %u bytes\n", download.buf->maxsize());
	Printf(PRINT_HIGH, "%s\n %s\n", download.filename.c_str(), actual_md5.c_str());

	if(download.md5 == "")
	{
		Printf(PRINT_HIGH, "Server gave no checksum, assuming valid\n", (int)download.buf->maxsize());
	}
	else if(actual_md5 != download.md5)
	{
		Printf(PRINT_HIGH, " %s on server\n", download.md5.c_str());
		Printf(PRINT_HIGH, "Download failed: bad checksum\n");

		download.clear();
        CL_QuitNetGame();

        ClearDownloadProgressBar();

        return;
    }

    // got the wad! save it!
    std::vector<std::string> dirs;
    std::string filename;
    size_t i;
#ifdef _WIN32
    const char separator = ';';
#else
    const char separator = ':';
#endif

    // Try to save to the wad paths in this order -- Hyper_Eye
    D_AddSearchDir(dirs, Args.CheckValue("-waddir"), separator);
    D_AddSearchDir(dirs, getenv("DOOMWADDIR"), separator);
    D_AddSearchDir(dirs, getenv("DOOMWADPATH"), separator);
    D_AddSearchDir(dirs, waddirs.cstring(), separator);
    dirs.push_back(startdir);
    dirs.push_back(progdir);

    dirs.erase(std::unique(dirs.begin(), dirs.end()), dirs.end());

    for(i = 0; i < dirs.size(); i++)
    {
        filename.clear();
        filename = dirs[i];
        if(filename[filename.length() - 1] != PATHSEPCHAR)
            filename += PATHSEP;
        filename += download.filename;

        // check for existing file
   	    if(M_FileExists(filename.c_str()))
   	    {
   	        // there is an existing file, so use a new file whose name includes the checksum
   	        filename += ".";
   	        filename += actual_md5;
   	    }

        if (M_WriteFile(filename, download.buf->ptr(), download.buf->maxsize()))
            break;
    }

    // Unable to write
    if(i == dirs.size())
    {
		download.clear();
        CL_QuitNetGame();
        return;
    }

    Printf(PRINT_HIGH, "Saved download as \"%s\"\n", filename.c_str());

	download.clear();
    CL_QuitNetGame();
    CL_Reconnect();

    ClearDownloadProgressBar();
}
Example #15
0
//
// D_DoomMainSetup
//
// CPhipps - the old contents of D_DoomMain, but moved out of the main
//  line of execution so its stack space can be freed
static void D_DoomMainSetup(void)
{
    int     p;
    char    file[256];
    int     temp;
    int     choseniwad;

    SDL_Init(0);

    M_FindResponseFile();

    iwadfile = D_FindIWAD();

    modifiedgame = false;

    nomonsters = M_CheckParm("-nomonsters");
    respawnparm = M_CheckParm("-respawn");
    fastparm = M_CheckParm("-fast");
    devparm = M_CheckParm("-devparm");
    if (M_CheckParm("-altdeath"))
        deathmatch = 2;
    else if (M_CheckParm("-deathmatch"))
        deathmatch = 1;

    M_SetConfigDir();

    // turbo option
    p = M_CheckParm("-turbo");
    if (p)
    {
        int        scale = 200;
        extern int forwardmove[2];
        extern int sidemove[2];

        if (p < myargc - 1)
            scale = atoi(myargv[p + 1]);
        if (scale < 10)
            scale = 10;
        if (scale > 400)
            scale = 400;
        forwardmove[0] = forwardmove[0] * scale / 100;
        forwardmove[1] = forwardmove[1] * scale / 100;
        sidemove[0] = sidemove[0] * scale / 100;
        sidemove[1] = sidemove[1] * scale / 100;
    }

    // init subsystems
    V_Init();

    // Load configuration files before initialising other subsystems.
    M_LoadDefaults();

    if (!M_FileExists("doomretro.wad"))
        if (!M_FileExists("doomretro.wad.temp"))
            I_Error("Can't find doomretro.wad.");

    if (iwadfile)
    {
        if (D_AddFile(iwadfile))
            if (runcount < RUNCOUNT_MAX)
                runcount++;
    }
    else 
    {
        if (!runcount)
            D_FirstUse();

        rename("doomretro.wad", "doomretro.wad.temp");

        do
        {
            choseniwad = D_ChooseIWAD();

            if (choseniwad == -1)
            {
                rename("doomretro.wad.temp", "doomretro.wad");
                I_Quit(false);
            }
            else if (!choseniwad)
                PlaySound((LPCTSTR)SND_ALIAS_SYSTEMHAND, NULL, SND_ALIAS_ID | SND_ASYNC);

        } while (!choseniwad);

        rename("doomretro.wad.temp", "doomretro.wad");

        if (runcount < RUNCOUNT_MAX)
            runcount++;
    }
    M_SaveDefaults();

    if (!W_MergeFile("doomretro.wad"))
        if (!W_MergeFile("doomretro.wad.temp"))
            I_Error("Can't find doomretro.wad.");

    if (W_CheckNumForName("BLD2A0") < 0 ||
        W_CheckNumForName("MEDBA0") < 0 ||
        W_CheckNumForName("STBAR2") < 0)
        I_Error("Wrong version of doomretro.wad.");

    p = M_CheckParmsWithArgs("-file", "-pwad", 1);
    if (p > 0)
    {
        for (p = p + 1; p < myargc && myargv[p][0] != '-'; ++p)
        {
            char *filename = uppercase(D_TryFindWADByName(myargv[p]));

            if (W_MergeFile(filename))
            {
                modifiedgame = true;
                if (D_CheckFilename(filename, "NERVE.WAD"))
                    nerve = true;
            }
        }
    }

    if (FREEDOOM && W_CheckNumForName("FREEDM") < 0 && !modifiedgame)
        I_Error("FREEDOOM requires a BOOM-compatible source port, and is therefore"
                "unable to be opened by DOOM RETRO.");

    DMENUPIC = (W_CheckNumForName("DMENUPIC") >= 0);
    M_DOOM = (W_CheckMultipleLumps("M_DOOM") > 1);
    M_EPISOD = (W_CheckMultipleLumps("M_EPISOD") > 1);
    M_GDHIGH = (W_CheckMultipleLumps("M_GDHIGH") > 1);
    M_GDLOW = (W_CheckMultipleLumps("M_GDLOW") > 1);
    M_LOADG = (W_CheckMultipleLumps("M_LOADG") > 1);
    M_LSCNTR = (W_CheckMultipleLumps("M_LSCNTR") > 1);
    M_MSENS = (W_CheckMultipleLumps("M_MSENS") > 1);
    M_MSGOFF = (W_CheckMultipleLumps("M_MSGOFF") > 1);
    M_MSGON = (W_CheckMultipleLumps("M_MSGON") > 1);
    M_NEWG = (W_CheckMultipleLumps("M_NEWG") > 1);
    M_NMARE = (W_CheckMultipleLumps("M_NMARE") > 1);
    M_OPTTTL = (W_CheckMultipleLumps("M_OPTTTL") > 1);
    M_PAUSE = (W_CheckMultipleLumps("M_PAUSE") > 1);
    M_SAVEG = (W_CheckMultipleLumps("M_SAVEG") > 1);
    M_SKILL = (W_CheckMultipleLumps("M_SKILL") > 1);
    M_SKULL1 = (W_CheckMultipleLumps("M_SKULL1") > 1);
    M_SVOL = (W_CheckMultipleLumps("M_SVOL") > 1);
    STARMS = (W_CheckMultipleLumps("STARMS") > 2);
    STBAR = (W_CheckMultipleLumps("STBAR") > 2);
    STCFN034 = (W_CheckMultipleLumps("STCFN034") > 1);
    STCFN039 = (W_CheckMultipleLumps("STCFN039") > 1);
    STCFN121 = (W_CheckMultipleLumps("STCFN121") > 1);
    STYSNUM0 = (W_CheckMultipleLumps("STYSNUM0") > 1);
    TITLEPIC = (W_CheckNumForName("TITLEPIC") >= 0);
    WISCRT2 = (W_CheckMultipleLumps("WISCRT2") > 1);

    bfgedition = (DMENUPIC && W_CheckNumForName("M_ACPT") >= 0);

    // Generate the WAD hash table. Speed things up a bit.
    W_GenerateHashTable();

    D_IdentifyVersion();
    InitGameVersion();
    D_SetGameDescription();
    D_SetSaveGameDir();

    // Check for -file in shareware
    if (modifiedgame)
    {
        // These are the lumps that will be checked in IWAD,
        // if any one is not present, execution will be aborted.
        char name[23][9] =
        {
            "e2m1", "e2m2", "e2m3", "e2m4", "e2m5", "e2m6", "e2m7", "e2m8", "e2m9",
            "e3m1", "e3m3", "e3m3", "e3m4", "e3m5", "e3m6", "e3m7", "e3m8", "e3m9",
            "dphoof", "bfgga0", "heada1", "cybra1", "spida1d1"
        };
        int i;

        if (gamemode == shareware)
            I_Error("You cannot use -FILE with the shareware version.\n"
                    "Please purchase the full version.");

        // Check for fake IWAD with right name,
        // but w/o all the lumps of the registered version.
        if (gamemode == registered)
            for (i = 0; i < 23; i++)
                if (W_CheckNumForName(name[i]) < 0)
                    I_Error("This is not the registered version.");
    }

    // get skill / episode / map from parms
    startskill = sk_medium;
    startepisode = 1;
    startmap = 1;
    autostart = false;

    p = M_CheckParmWithArgs("-skill", 1);
    if (p)
    {
        temp = myargv[p + 1][0] - '1';
        if (temp >= sk_baby && temp <= sk_nightmare)
        {
            startskill = (skill_t)temp;
            autostart = true;
        }
    }

    p = M_CheckParmWithArgs("-episode", 1);
    if (p)
    {
        temp = myargv[p + 1][0] - '0';
        if ((gamemode == shareware && temp == 1)
            || (temp >= 1
                && ((gamemode == registered && temp <= 3)
                    || (gamemode == retail && temp <= 4))))
        {
            startepisode = temp;
            startmap = 1;
            autostart = true;
        }
    }

    p = M_CheckParmWithArgs("-expansion", 1);
    if (p)
    {
        temp = myargv[p + 1][0] - '0';
        if (gamemode == commercial && temp <= (nerve ? 2 : 1))
        {
            gamemission = (temp == 1 ? doom2 : pack_nerve);
            selectedexpansion = temp - 1;
            startepisode = 1;
            startmap = 1;
            autostart = true;
        }
    }

    timelimit = 0;

    p = M_CheckParmWithArgs("-timer", 1);
    if (p)
        timelimit = atoi(myargv[p + 1]);

    p = M_CheckParm("-avg");
    if (p)
        timelimit = 20;

    p = M_CheckParmWithArgs("-warp", 1);
    if (p)
    {
        static char lumpname[6];

        if (gamemode == commercial)
        {
            if (strlen(myargv[p + 1]) == 5 &&
                toupper(myargv[p + 1][0]) == 'M' &&
                toupper(myargv[p + 1][1]) == 'A' &&
                toupper(myargv[p + 1][2]) == 'P')
                startmap = (myargv[p + 1][3] - '0') * 10 + myargv[p + 1][4] - '0';
            else
                startmap = atoi(myargv[p + 1]);

            sprintf(lumpname, "MAP%02i", startmap);
        }
        else
        {
            if (strlen(myargv[p + 1]) == 4 &&
                toupper(myargv[p + 1][0]) == 'E' &&
                toupper(myargv[p + 1][2]) == 'M')
            {
                startepisode = myargv[p + 1][1] - '0';
                startmap = myargv[p + 1][3] - '0';
            }
            else
            {
                startepisode = myargv[p + 1][0] - '0';

                if (p + 2 < myargc)
                    startmap = myargv[p + 2][0] - '0';
                else
                    startmap = 1;
            }

            sprintf(lumpname, "E%iM%i", startepisode, startmap);
        }

        if (W_CheckNumForName(lumpname) >= 0)
            autostart = true;
    }

    p = M_CheckParmWithArgs("-loadgame", 1);
    if (p)
        startloadgame = atoi(myargv[p + 1]);
    else
        startloadgame = -1;

    if (mouseSensitivity < MOUSESENSITIVITY_MIN || mouseSensitivity > MOUSESENSITIVITY_MAX)
        mouseSensitivity = MOUSESENSITIVITY_DEFAULT;
    if (mouseSensitivity == MOUSESENSITIVITY_MIN)
        mouseSensitivity = -5;
    gamepadSensitivity = (!mouseSensitivity ? 0.0f :
                          (2.0f + mouseSensitivity / (float)MOUSESENSITIVITY_MAX));

    if (sfxVolume < SFXVOLUME_MIN || sfxVolume > SFXVOLUME_MAX)
        sfxVolume = SFXVOLUME_DEFAULT;

    if (musicVolume < MUSICVOLUME_MIN || musicVolume > MUSICVOLUME_MAX)
        musicVolume = MUSICVOLUME_DEFAULT;

    if (screensize < SCREENSIZE_MIN || screensize > SCREENSIZE_MAX)
        screensize = SCREENSIZE_DEFAULT;
    if (widescreen && !fullscreen)
    {
        widescreen = false;
        screensize = SCREENSIZE_MAX;
    }
    if (!widescreen)
        hud = true;
    if (fullscreen && screensize == SCREENSIZE_MAX)
    {
        widescreen = true;
        screensize = SCREENSIZE_MAX - 1;
    }
    if (widescreen)
    {
        returntowidescreen = true;
        widescreen = false;
    }

    if (screenwidth && screenheight
        && (screenwidth < SCREENWIDTH || screenheight < SCREENHEIGHT * 3 / 4))
    {
        screenwidth = SCREENWIDTH;
        screenheight = SCREENWIDTH * 3 / 4;
    }

    if (windowwidth < SCREENWIDTH || windowheight < SCREENWIDTH * 3 / 4)
    {
        windowwidth = SCREENWIDTH;
        windowheight = SCREENWIDTH * 3 / 4;
    }

    if (gammalevel < GAMMALEVEL_MIN || gammalevel > GAMMALEVEL_MAX)
        gammalevel = GAMMALEVEL_DEFAULT;
    gammalevelindex = 0;
    while (gammalevelindex < GAMMALEVELS)
        if (gammalevels[gammalevelindex++] == gammalevel)
            break;
    if (gammalevelindex == GAMMALEVELS)
    {
        gammalevelindex = 0;
        while (gammalevels[gammalevelindex++] != GAMMALEVEL_DEFAULT);
    }
    gammalevelindex--;

    if (bloodsplats < BLOODSPLATS_MIN || bloodsplats > BLOODSPLATS_MAX)
        bloodsplats = BLOODSPLATS_DEFAULT;
    bloodSplatSpawner = ((bloodsplats == UNLIMITED ? P_SpawnBloodSplat : 
                         (bloodsplats ? P_SpawnBloodSplat2 : P_SpawnBloodSplat3)));

    if (pixelwidth < PIXELWIDTH_MIN || pixelwidth > PIXELWIDTH_MAX)
        pixelwidth = PIXELWIDTH_DEFAULT;
    while (SCREENWIDTH % pixelwidth)
        pixelwidth--;
    if (pixelheight < PIXELHEIGHT_MIN || pixelheight > PIXELHEIGHT_MAX)
        pixelheight = PIXELHEIGHT_DEFAULT;
    while (SCREENHEIGHT % pixelheight)
        pixelheight--;

    M_Init();

    R_Init();

    P_Init();

    I_Init();

    S_Init((int)(sfxVolume * (127.0f / 15.0f)), (int)(musicVolume * (127.0f / 15.0f)));

    D_CheckNetGame();

    HU_Init();

    ST_Init();

    AM_Init();

    if (startloadgame >= 0)
    {
        M_StringCopy(file, P_SaveGameFile(startloadgame), sizeof(file));
        G_LoadGame(file);
    }

    if (gameaction != ga_loadgame)
    {
        if (autostart || netgame)
            G_DeferredInitNew(startskill, startepisode, startmap);
        else
            D_StartTitle();                     // start up intro loop
    }
}
Example #16
0
void D_IdentifyVersion(void)
{
    // gamemission is set up by the D_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.
    
    // STRIFE-TODO: some elaborate checks? for now we assume...
    // The logic in strife1.exe is simple:
    // * if strife1.wad is found, set isregistered = true
    // * if strife0.wad is found, set isdemoversion = true

    // Make sure gamemode is set up correctly
    gamemode = commercial;
    gamemission = strife;
    isregistered = true;

    // Load voices.wad 
    if(isregistered)
    {
        char *name = D_FindWADByName("voices.wad");

        if(!name) // not found?
        {
            int p;

            // haleyjd STRIFE-FIXME: Temporary?
            // If -iwad was used, check and see if voices.wad exists on the
            // same filepath.
            if((p = M_CheckParm("-iwad")) && p < myargc - 1)
            {
                char   *iwad     = myargv[p + 1];
                size_t  len      = strlen(iwad) + 24;
                char   *filename = malloc(len);
                char    sepchar;

                // how the heck is Choco surviving without this routine?
                sepchar = M_GetFilePath(iwad, filename, len);
                filename[strlen(filename)] = sepchar;
                M_StringConcat(filename, "voices.wad", sizeof(filename));

                if(!M_FileExists(filename))
                    disable_voices = 1;
                else
                    name = filename; // STRIFE-FIXME: memory leak!!
            }
            else
                disable_voices = 1;
        }

        if(disable_voices) // voices disabled?
        {
            if(devparm)
                 printf("Voices disabled\n");
            return;
        }

        D_AddFile(name);
    }
}
Example #17
0
// Load dehacked patches needed for certain IWADs.
static void LoadIwadDeh(void)
{
    // The Freedoom IWADs have DEHACKED lumps that must be loaded.
    if (W_CheckNumForName("FREEDOOM") >= 0)
    {
        // Old versions of Freedoom (before 2014-09) did not have technically
        // valid DEHACKED lumps, so ignore errors and just continue if this
        // is an old IWAD.
        DEH_LoadLumpByName("DEHACKED", false, true);
    }

    // If this is the HACX IWAD, we need to load the DEHACKED lump.
    if (gameversion == exe_hacx)
    {
        if (!DEH_LoadLumpByName("DEHACKED", true, false))
        {
            I_Error("DEHACKED lump not found.  Please check that this is the "
                    "Hacx v1.2 IWAD.");
        }
    }

    // Chex Quest needs a separate Dehacked patch which must be downloaded
    // and installed next to the IWAD.
    if (gameversion == exe_chex)
    {
        char *chex_deh = NULL;
        char *sep;

        // Look for chex.deh in the same directory as the IWAD file.
        sep = strrchr(iwadfile, DIR_SEPARATOR);

        if (sep != NULL)
        {
            size_t chex_deh_len = strlen(iwadfile) + 9;
            chex_deh = malloc(chex_deh_len);
            M_StringCopy(chex_deh, iwadfile, chex_deh_len);
            chex_deh[sep - iwadfile + 1] = '\0';
            M_StringConcat(chex_deh, "chex.deh", chex_deh_len);
        }
        else
        {
            chex_deh = M_StringDuplicate("chex.deh");
        }

        // If the dehacked patch isn't found, try searching the WAD
        // search path instead.  We might find it...
        if (!M_FileExists(chex_deh))
        {
            free(chex_deh);
            chex_deh = D_FindWADByName("chex.deh");
        }

        // Still not found?
        if (chex_deh == NULL)
        {
            I_Error("Unable to find Chex Quest dehacked file (chex.deh).\n"
                    "The dehacked file is required in order to emulate\n"
                    "chex.exe correctly.  It can be found in your nearest\n"
                    "/idgames repository mirror at:\n\n"
                    "   utils/exe_edit/patches/chexdeh.zip");
        }

        if (!DEH_LoadFile(chex_deh))
        {
            I_Error("Failed to load chex.deh needed for emulating chex.exe.");
        }
    }
}
Example #18
0
void D_IdentifyVersion(void)
{
    // gamemission is set up by the D_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.

    // STRIFE-TODO: some elaborate checks? for now we assume...
    // The logic in strife1.exe is simple:
    // * if strife1.wad is found, set isregistered = true
    // * if strife0.wad is found, set isdemoversion = true

    // Make sure gamemode is set up correctly
    gamemode = commercial;
    gamemission = strife;
    isregistered = true;

    // Load voices.wad
    if(isregistered)
    {
        char *name = D_FindWADByName("voices.wad");

        if(!name) // not found?
        {
            int p;

            // haleyjd STRIFE-FIXME: Temporary?
            // If -iwad was used, check and see if voices.wad exists on the
            // same filepath.
            if((p = M_CheckParm("-iwad")) && p < myargc - 1)
            {
                char   *iwad     = myargv[p + 1];
                size_t  len      = strlen(iwad) + 1;
                char   *iwadpath = Z_Malloc(len, PU_STATIC, NULL);
                char   *voiceswad;

                // extract base path of IWAD parameter
                M_GetFilePath(iwad, iwadpath, len);

                // concatenate with /voices.wad
                voiceswad = M_SafeFilePath(iwadpath, "voices.wad");
                Z_Free(iwadpath);

                if(!M_FileExists(voiceswad))
                {
                    disable_voices = 1;
                    Z_Free(voiceswad);
                }
                else
                    name = voiceswad; // STRIFE-FIXME: memory leak!!
            }
            else
                disable_voices = 1;
        }

        if(disable_voices) // voices disabled?
        {
            if(devparm)
                printf("Voices disabled\n");
            return;
        }

        D_AddFile(name);
    }
}