2009-03-22 11:42:46 +00:00
|
|
|
/*
|
|
|
|
** d_iwad.cpp
|
|
|
|
** IWAD detection code
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2009 Randy Heit
|
|
|
|
** Copyright 2009 CHristoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
#include "d_main.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "w_zip.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "m_argv.h"
|
2009-03-23 07:37:57 +00:00
|
|
|
#include "m_misc.h"
|
2009-03-22 11:42:46 +00:00
|
|
|
#include "c_cvars.h"
|
2010-10-15 15:13:53 +00:00
|
|
|
#include "sc_man.h"
|
|
|
|
#include "v_video.h"
|
2009-03-22 11:42:46 +00:00
|
|
|
#include "gameconfigfile.h"
|
2009-05-30 09:53:38 +00:00
|
|
|
#include "resourcefiles/resourcefile.h"
|
2009-03-22 11:42:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
CVAR (Bool, queryiwad, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
|
|
|
CVAR (String, defaultiwad, "", CVAR_ARCHIVE|CVAR_GLOBALCONFIG);
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2010-10-15 15:13:53 +00:00
|
|
|
// Clear check list
|
2009-03-22 11:42:46 +00:00
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
void FIWadManager::ClearChecks()
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
mLumpsFound.Resize(mIWads.Size());
|
|
|
|
for(unsigned i=0;i<mLumpsFound.Size(); i++)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
mLumpsFound[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-03-22 11:42:46 +00:00
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Check one lump
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2009-05-30 09:53:38 +00:00
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
void FIWadManager::CheckLumpName(const char *name)
|
|
|
|
{
|
|
|
|
for(unsigned i=0; i< mIWads.Size(); i++)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
for(unsigned j=0; j < mIWads[i].Lumps.Size(); j++)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
if (!mIWads[i].Lumps[j].CompareNoCase(name))
|
2009-11-10 02:29:18 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
mLumpsFound[i] |= (1<<j);
|
2009-11-10 02:29:18 +00:00
|
|
|
}
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
}
|
2009-03-22 11:42:46 +00:00
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Returns check result
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
int FIWadManager::GetIWadInfo()
|
|
|
|
{
|
|
|
|
for(unsigned i=0; i< mIWads.Size(); i++)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
if (mLumpsFound[i] == (1 << mIWads[i].Lumps.Size()) - 1)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
return i;
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Parses IWAD definitions
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FIWadManager::ParseIWadInfo(const char *fn, const char *data, int datasize)
|
|
|
|
{
|
|
|
|
FScanner sc;
|
|
|
|
|
|
|
|
sc.OpenMem("IWADINFO", data, datasize);
|
|
|
|
while (sc.GetString())
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
if (sc.Compare("IWAD"))
|
2009-10-29 05:51:20 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
FIWADInfo *iwad = &mIWads[mIWads.Reserve(1)];
|
|
|
|
sc.MustGetStringName("{");
|
|
|
|
while (!sc.CheckString("}"))
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetString();
|
|
|
|
if (sc.Compare("Name"))
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetStringName("=");
|
|
|
|
sc.MustGetString();
|
|
|
|
iwad->Name = sc.String;
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
else if (sc.Compare("Autoname"))
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetStringName("=");
|
|
|
|
sc.MustGetString();
|
|
|
|
iwad->Autoname = sc.String;
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
else if (sc.Compare("Config"))
|
2009-10-29 05:51:20 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetStringName("=");
|
|
|
|
sc.MustGetString();
|
|
|
|
iwad->Configname = sc.String;
|
2009-10-29 05:51:20 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
else if (sc.Compare("Game"))
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetStringName("=");
|
|
|
|
sc.MustGetString();
|
|
|
|
if (sc.Compare("Doom")) iwad->gametype = GAME_Doom;
|
|
|
|
else if (sc.Compare("Heretic")) iwad->gametype = GAME_Heretic;
|
|
|
|
else if (sc.Compare("Hexen")) iwad->gametype = GAME_Hexen;
|
|
|
|
else if (sc.Compare("Strife")) iwad->gametype = GAME_Strife;
|
|
|
|
else if (sc.Compare("Chex")) iwad->gametype = GAME_Chex;
|
|
|
|
else sc.ScriptError(NULL);
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
else if (sc.Compare("Mapinfo"))
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetStringName("=");
|
|
|
|
sc.MustGetString();
|
|
|
|
iwad->MapInfo = sc.String;
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
else if (sc.Compare("Compatibility"))
|
2009-05-30 08:56:40 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetStringName("=");
|
|
|
|
do
|
|
|
|
{
|
|
|
|
sc.MustGetString();
|
|
|
|
if(sc.Compare("NoTextcolor")) iwad->flags |= GI_NOTEXTCOLOR;
|
|
|
|
else if(sc.Compare("Poly1")) iwad->flags |= GI_COMPATPOLY1;
|
|
|
|
else if(sc.Compare("Poly2")) iwad->flags |= GI_COMPATPOLY2;
|
|
|
|
else if(sc.Compare("Shareware")) iwad->flags |= GI_SHAREWARE;
|
|
|
|
else if(sc.Compare("Teaser2")) iwad->flags |= GI_TEASER2;
|
|
|
|
else if(sc.Compare("Extended")) iwad->flags |= GI_MENUHACK_EXTENDED;
|
|
|
|
else if(sc.Compare("Shorttex")) iwad->flags |= GI_COMPATSHORTTEX;
|
|
|
|
else if(sc.Compare("Stairs")) iwad->flags |= GI_COMPATSTAIRS;
|
|
|
|
else sc.ScriptError(NULL);
|
|
|
|
}
|
|
|
|
while (sc.CheckString(","));
|
2009-05-30 08:56:40 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
else if (sc.Compare("MustContain"))
|
2009-05-30 08:56:40 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetStringName("=");
|
|
|
|
do
|
|
|
|
{
|
|
|
|
sc.MustGetString();
|
|
|
|
iwad->Lumps.Push(FString(sc.String));
|
|
|
|
}
|
|
|
|
while (sc.CheckString(","));
|
2009-05-30 08:56:40 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
else if (sc.Compare("BannerColors"))
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetStringName("=");
|
|
|
|
sc.MustGetString();
|
|
|
|
iwad->FgColor = V_GetColor(NULL, sc.String);
|
|
|
|
sc.MustGetStringName(",");
|
|
|
|
sc.MustGetString();
|
|
|
|
iwad->BkColor = V_GetColor(NULL, sc.String);
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
else if (sc.Compare("Load"))
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetStringName("=");
|
|
|
|
do
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.MustGetString();
|
|
|
|
iwad->Load.Push(FString(sc.String));
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
while (sc.CheckString(","));
|
|
|
|
}
|
|
|
|
else if (sc.Compare("Required"))
|
|
|
|
{
|
|
|
|
sc.MustGetStringName("=");
|
|
|
|
sc.MustGetString();
|
|
|
|
iwad->Required = sc.String;
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
sc.ScriptError("Unknown keyword '%s'", sc.String);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sc.Compare("NAMES"))
|
|
|
|
{
|
|
|
|
sc.MustGetStringName("{");
|
|
|
|
mIWadNames.Push(FString());
|
|
|
|
while (!sc.CheckString("}"))
|
|
|
|
{
|
|
|
|
sc.MustGetString();
|
|
|
|
FString wadname = sc.String;
|
2010-11-10 23:39:34 +00:00
|
|
|
#if defined(_WIN32) || defined(__APPLE__) // Turns out Mac OS X is case insensitive.
|
2010-10-15 15:13:53 +00:00
|
|
|
mIWadNames.Push(wadname);
|
|
|
|
#else
|
|
|
|
// check for lowercase, uppercased first letter and full uppercase on Linux etc.
|
|
|
|
wadname.ToLower();
|
|
|
|
mIWadNames.Push(wadname);
|
2010-10-16 06:38:42 +00:00
|
|
|
wadname.LockBuffer()[0] = toupper(wadname[0]);
|
|
|
|
wadname.UnlockBuffer();
|
2010-10-15 15:13:53 +00:00
|
|
|
mIWadNames.Push(wadname);
|
|
|
|
wadname.ToUpper();
|
|
|
|
mIWadNames.Push(wadname);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Lool for IWAD definition lump
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FIWadManager::ParseIWadInfos(const char *fn)
|
|
|
|
{
|
|
|
|
FResourceFile *resfile = FResourceFile::OpenResourceFile(fn, NULL, true);
|
|
|
|
if (resfile != NULL)
|
|
|
|
{
|
|
|
|
DWORD cnt = resfile->LumpCount();
|
|
|
|
for(int i=cnt-1; i>=0; i--)
|
|
|
|
{
|
|
|
|
FResourceLump *lmp = resfile->GetLump(i);
|
|
|
|
|
|
|
|
if (lmp->Namespace == ns_global && !stricmp(lmp->Name, "IWADINFO"))
|
|
|
|
{
|
|
|
|
// Found one!
|
|
|
|
ParseIWadInfo(resfile->Filename, (const char*)lmp->CacheLump(), lmp->LumpSize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete resfile;
|
|
|
|
}
|
2011-01-23 08:49:30 +00:00
|
|
|
if (mIWadNames.Size() == 0 || mIWads.Size() == 0)
|
|
|
|
{
|
|
|
|
I_FatalError("No IWAD definitions found");
|
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// ScanIWAD
|
|
|
|
//
|
|
|
|
// Scan the contents of an IWAD to determine which one it is
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
int FIWadManager::ScanIWAD (const char *iwad)
|
|
|
|
{
|
|
|
|
FResourceFile *iwadfile = FResourceFile::OpenResourceFile(iwad, NULL, true);
|
|
|
|
|
|
|
|
if (iwadfile != NULL)
|
|
|
|
{
|
|
|
|
ClearChecks();
|
|
|
|
for(DWORD ii = 0; ii < iwadfile->LumpCount(); ii++)
|
|
|
|
{
|
|
|
|
FResourceLump *lump = iwadfile->GetLump(ii);
|
|
|
|
|
|
|
|
CheckLumpName(lump->Name);
|
|
|
|
if (lump->FullName != NULL)
|
|
|
|
{
|
|
|
|
if (strnicmp(lump->FullName, "maps/", 5) == 0)
|
|
|
|
{
|
|
|
|
FString mapname(lump->FullName+5, strcspn(lump->FullName+5, "."));
|
|
|
|
CheckLumpName(mapname);
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
delete iwadfile;
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
return GetIWadInfo();
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CheckIWAD
|
|
|
|
//
|
|
|
|
// Tries to find an IWAD from a set of known IWAD names, and checks the
|
|
|
|
// contents of each one found to determine which game it belongs to.
|
|
|
|
// Returns the number of new wads found in this pass (does not count wads
|
|
|
|
// found from a previous call).
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
int FIWadManager::CheckIWAD (const char *doomwaddir, WadStuff *wads)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
|
|
|
const char *slash;
|
|
|
|
int numfound;
|
|
|
|
|
|
|
|
numfound = 0;
|
2012-07-06 02:37:50 +00:00
|
|
|
|
2009-03-22 11:42:46 +00:00
|
|
|
slash = (doomwaddir[0] && doomwaddir[strlen (doomwaddir)-1] != '/') ? "/" : "";
|
|
|
|
|
|
|
|
// Search for a pre-defined IWAD
|
2010-10-15 15:13:53 +00:00
|
|
|
for (unsigned i=0; i< mIWadNames.Size(); i++)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
if (mIWadNames[i].IsNotEmpty() && wads[i].Path.IsEmpty())
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
|
|
|
FString iwad;
|
|
|
|
|
2010-10-16 06:38:42 +00:00
|
|
|
iwad.Format ("%s%s%s", doomwaddir, slash, mIWadNames[i].GetChars());
|
2010-01-01 15:31:00 +00:00
|
|
|
FixPathSeperator (iwad);
|
2009-03-22 11:42:46 +00:00
|
|
|
if (FileExists (iwad))
|
|
|
|
{
|
|
|
|
wads[i].Type = ScanIWAD (iwad);
|
2010-10-15 15:13:53 +00:00
|
|
|
if (wads[i].Type != -1)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
|
|
|
wads[i].Path = iwad;
|
2010-10-15 15:13:53 +00:00
|
|
|
wads[i].Name = mIWads[wads[i].Type].Name;
|
2009-03-22 11:42:46 +00:00
|
|
|
numfound++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return numfound;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// IdentifyVersion
|
|
|
|
//
|
|
|
|
// Tries to find an IWAD in one of four directories under DOS or Win32:
|
|
|
|
// 1. Current directory
|
|
|
|
// 2. Executable directory
|
|
|
|
// 3. $DOOMWADDIR
|
|
|
|
// 4. $HOME
|
|
|
|
//
|
|
|
|
// Under UNIX OSes, the search path is:
|
|
|
|
// 1. Current directory
|
|
|
|
// 2. $DOOMWADDIR
|
2013-07-05 04:45:45 +00:00
|
|
|
// 3. $HOME/.config/zdoom
|
2009-03-22 11:42:46 +00:00
|
|
|
// 4. The share directory defined at compile time (/usr/local/share/zdoom)
|
|
|
|
//
|
|
|
|
// The search path can be altered by editing the IWADSearch.Directories
|
|
|
|
// section of the config file.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
int FIWadManager::IdentifyVersion (TArray<FString> &wadfiles, const char *iwad, const char *zdoom_wad)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
TArray<WadStuff> wads;
|
|
|
|
TArray<size_t> foundwads;
|
2009-03-22 11:42:46 +00:00
|
|
|
const char *iwadparm = Args->CheckValue ("-iwad");
|
|
|
|
size_t numwads;
|
|
|
|
int pickwad;
|
|
|
|
size_t i;
|
|
|
|
bool iwadparmfound = false;
|
|
|
|
FString custwad;
|
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
ParseIWadInfos(zdoom_wad);
|
|
|
|
wads.Resize(mIWadNames.Size());
|
|
|
|
foundwads.Resize(mIWads.Size());
|
|
|
|
memset(&foundwads[0], 0, foundwads.Size() * sizeof(foundwads[0]));
|
|
|
|
|
2010-01-01 15:31:00 +00:00
|
|
|
if (iwadparm == NULL && iwad != NULL && *iwad != 0)
|
|
|
|
{
|
|
|
|
iwadparm = iwad;
|
|
|
|
}
|
|
|
|
|
2009-03-22 11:42:46 +00:00
|
|
|
if (iwadparm)
|
|
|
|
{
|
|
|
|
custwad = iwadparm;
|
2010-01-01 15:31:00 +00:00
|
|
|
FixPathSeperator (custwad);
|
2010-10-15 15:13:53 +00:00
|
|
|
if (CheckIWAD (custwad, &wads[0]))
|
2009-03-22 11:42:46 +00:00
|
|
|
{ // -iwad parameter was a directory
|
|
|
|
iwadparm = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DefaultExtension (custwad, ".wad");
|
|
|
|
iwadparm = custwad;
|
2010-10-15 15:13:53 +00:00
|
|
|
mIWadNames[0] = custwad;
|
|
|
|
CheckIWAD ("", &wads[0]);
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-08 05:12:03 +00:00
|
|
|
if (iwadparm == NULL || wads[0].Path.IsEmpty() || mIWads[wads[0].Type].Required.IsNotEmpty())
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
|
|
|
if (GameConfig->SetSection ("IWADSearch.Directories"))
|
|
|
|
{
|
|
|
|
const char *key;
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
while (GameConfig->NextInSection (key, value))
|
|
|
|
{
|
|
|
|
if (stricmp (key, "Path") == 0)
|
|
|
|
{
|
2009-09-09 17:12:47 +00:00
|
|
|
FString nice = NicePath(value);
|
2010-01-01 15:31:00 +00:00
|
|
|
FixPathSeperator(nice);
|
2010-10-15 15:13:53 +00:00
|
|
|
CheckIWAD(nice, &wads[0]);
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
|
|
FString steam_path = I_GetSteamPath();
|
|
|
|
if (steam_path.IsNotEmpty())
|
|
|
|
{
|
|
|
|
static const char *const steam_dirs[] =
|
|
|
|
{
|
|
|
|
"doom 2/base",
|
|
|
|
"final doom/base",
|
|
|
|
"heretic shadow of the serpent riders/base",
|
|
|
|
"hexen/base",
|
|
|
|
"hexen deathkings of the dark citadel/base",
|
2013-02-19 01:55:14 +00:00
|
|
|
"ultimate doom/base",
|
|
|
|
"DOOM 3 BFG Edition/base/wads"
|
2009-03-22 11:42:46 +00:00
|
|
|
};
|
|
|
|
steam_path += "/SteamApps/common/";
|
|
|
|
for (i = 0; i < countof(steam_dirs); ++i)
|
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
CheckIWAD (steam_path + steam_dirs[i], &wads[0]);
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iwadparm != NULL && !wads[0].Path.IsEmpty())
|
|
|
|
{
|
|
|
|
iwadparmfound = true;
|
|
|
|
}
|
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
for (i = numwads = 0; i < mIWadNames.Size(); i++)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
|
|
|
if (!wads[i].Path.IsEmpty())
|
|
|
|
{
|
|
|
|
if (i != numwads)
|
|
|
|
{
|
|
|
|
wads[numwads] = wads[i];
|
|
|
|
}
|
|
|
|
foundwads[wads[numwads].Type] = numwads + 1;
|
|
|
|
numwads++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
for (unsigned i=0; i<mIWads.Size(); i++)
|
|
|
|
{
|
|
|
|
if (mIWads[i].Required.IsNotEmpty() && foundwads[i])
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
bool found = false;
|
|
|
|
// needs to be loaded with another IWAD (HexenDK)
|
|
|
|
for (unsigned j=0; j<mIWads.Size(); j++)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
if (!mIWads[i].Required.Compare(mIWads[j].Name))
|
|
|
|
{
|
|
|
|
if (foundwads[j])
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
mIWads[i].preload = j;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// The required WAD is not there so this one can't be used and must be deleted from the list
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
size_t kill = foundwads[i];
|
|
|
|
for (size_t j = kill; j < numwads; ++j)
|
|
|
|
{
|
|
|
|
wads[j - 1] = wads[j];
|
|
|
|
}
|
|
|
|
numwads--;
|
|
|
|
foundwads[i] = 0;
|
|
|
|
for (unsigned j = 0; j < foundwads.Size(); ++j)
|
|
|
|
{
|
|
|
|
if (foundwads[j] > kill)
|
|
|
|
{
|
|
|
|
foundwads[j]--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numwads == 0)
|
|
|
|
{
|
|
|
|
I_FatalError ("Cannot find a game IWAD (doom.wad, doom2.wad, heretic.wad, etc.).\n"
|
|
|
|
"Did you install ZDoom properly? You can do either of the following:\n"
|
|
|
|
"\n"
|
2013-07-05 04:45:45 +00:00
|
|
|
#if defined(_WIN32)
|
2009-03-22 11:42:46 +00:00
|
|
|
"1. Place one or more of these wads in the same directory as ZDoom.\n"
|
|
|
|
"2. Edit your zdoom-username.ini and add the directories of your iwads\n"
|
|
|
|
"to the list beneath [IWADSearch.Directories]");
|
2013-07-05 04:45:45 +00:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
"1. Place one or more of these wads in ~/Library/Application Support/zdoom/\n"
|
|
|
|
"2. Edit your ~/Library/Preferences/zdoom.ini and add the directories\n"
|
|
|
|
"of your iwads to the list beneath [IWADSearch.Directories]");
|
|
|
|
#else
|
|
|
|
"1. Place one or more of these wads in ~/.config/zdoom/.\n"
|
|
|
|
"2. Edit your ~/.config/zdoom/zdoom.ini and add the directories of your\n"
|
|
|
|
"iwads to the list beneath [IWADSearch.Directories]");
|
|
|
|
#endif
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pickwad = 0;
|
|
|
|
|
|
|
|
if (!iwadparmfound && numwads > 1)
|
|
|
|
{
|
|
|
|
int defiwad = 0;
|
|
|
|
|
|
|
|
// Locate the user's prefered IWAD, if it was found.
|
|
|
|
if (defaultiwad[0] != '\0')
|
|
|
|
{
|
|
|
|
for (i = 0; i < numwads; ++i)
|
|
|
|
{
|
|
|
|
FString basename = ExtractFileBase (wads[i].Path);
|
|
|
|
if (stricmp (basename, defaultiwad) == 0)
|
|
|
|
{
|
|
|
|
defiwad = (int)i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
pickwad = I_PickIWad (&wads[0], (int)numwads, queryiwad, defiwad);
|
2009-03-22 11:42:46 +00:00
|
|
|
if (pickwad >= 0)
|
|
|
|
{
|
|
|
|
// The newly selected IWAD becomes the new default
|
|
|
|
FString basename = ExtractFileBase (wads[pickwad].Path);
|
|
|
|
defaultiwad = basename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pickwad < 0)
|
|
|
|
exit (0);
|
|
|
|
|
|
|
|
// zdoom.pk3 must always be the first file loaded and the IWAD second.
|
2010-12-13 10:02:45 +00:00
|
|
|
wadfiles.Clear();
|
2010-01-01 12:40:47 +00:00
|
|
|
D_AddFile (wadfiles, zdoom_wad);
|
2009-03-22 11:42:46 +00:00
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
if (mIWads[wads[pickwad].Type].preload >= 0)
|
|
|
|
{
|
|
|
|
D_AddFile (wadfiles, wads[foundwads[mIWads[wads[pickwad].Type].preload]-1].Path);
|
2009-03-22 11:42:46 +00:00
|
|
|
}
|
2010-01-01 12:40:47 +00:00
|
|
|
D_AddFile (wadfiles, wads[pickwad].Path);
|
2009-03-22 11:42:46 +00:00
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
for (unsigned i=0; i < mIWads[wads[pickwad].Type].Load.Size(); i++)
|
|
|
|
{
|
2009-03-22 11:42:46 +00:00
|
|
|
long lastslash = wads[pickwad].Path.LastIndexOf ('/');
|
|
|
|
FString path;
|
|
|
|
|
|
|
|
if (lastslash == -1)
|
|
|
|
{
|
|
|
|
path = "";// wads[pickwad].Path;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = FString (wads[pickwad].Path.GetChars(), lastslash + 1);
|
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
path += mIWads[wads[pickwad].Type].Load[i];
|
2010-01-01 12:40:47 +00:00
|
|
|
D_AddFile (wadfiles, path);
|
2009-03-22 11:42:46 +00:00
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
}
|
2009-03-22 11:42:46 +00:00
|
|
|
return wads[pickwad].Type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-15 15:13:53 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Find an IWAD to use for this game
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
const FIWADInfo *FIWadManager::FindIWAD(TArray<FString> &wadfiles, const char *iwad, const char *basewad)
|
2009-03-22 11:42:46 +00:00
|
|
|
{
|
2010-10-15 15:13:53 +00:00
|
|
|
int iwadType = IdentifyVersion(wadfiles, iwad, basewad);
|
|
|
|
//gameiwad = iwadType;
|
|
|
|
const FIWADInfo *iwad_info = &mIWads[iwadType];
|
2010-09-24 14:27:52 +00:00
|
|
|
if (DoomStartupInfo.Name.IsEmpty()) DoomStartupInfo.Name = iwad_info->Name;
|
|
|
|
if (DoomStartupInfo.BkColor == 0 && DoomStartupInfo.FgColor == 0)
|
|
|
|
{
|
|
|
|
DoomStartupInfo.BkColor = iwad_info->BkColor;
|
|
|
|
DoomStartupInfo.FgColor = iwad_info->FgColor;
|
|
|
|
}
|
2010-10-15 15:13:53 +00:00
|
|
|
I_SetIWADInfo();
|
2009-03-22 11:42:46 +00:00
|
|
|
return iwad_info;
|
|
|
|
}
|