Example #1
0
//
// W_InitMultipleFiles
// Pass a null terminated list of files to use.
// All files are optional, but at least one file
//  must be found.
// Files with a .wad extension are idlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
// Lump names can appear multiple times.
// The name searcher looks backwards, so a later file
//  does override all earlier ones.
//
void W_InitMultipleFiles (const char** filenames)
{
	int		size;

	if (lumpinfo == NULL)
	{
		// open all the files, load headers, and count lumps
		numlumps = 0;

		// will be realloced as lumps are added
		lumpinfo = NULL;
		
		// Do the first file (the main WAD) seperately, so only it is affected.
	    // Find its medikit, stimpack, and beserk lumps so they can be fixed.
		if (*filenames) {
			W_AddFile (*filenames);
			filenames++;
			lumpnum_media0 = W_CheckNumForName("MEDIA0");
			lumpnum_stima0 = W_CheckNumForName("STIMA0");
			lumpnum_pstra0 = W_CheckNumForName("PSTRA0");
		}
		// Other wads are handled like normal
		for ( ; *filenames ; filenames++)
		{
			W_AddFile (*filenames);
		}
		
		if (!numlumps)
			I_Error ("W_InitMultipleFiles: no files found");

		// set up caching
		size = numlumps * sizeof(*lumpcache);
		lumpcache = (void**)DoomLib::Z_Malloc(size, PU_STATIC_SHARED, 0 );

		if (!lumpcache)
			I_Error ("Couldn't allocate lumpcache");

		memset (lumpcache,0, size);
	} else {
		// set up caching
		size = numlumps * sizeof(*lumpcache);
		lumpcache = (void**)DoomLib::Z_Malloc(size, PU_STATIC_SHARED, 0 );

		if (!lumpcache)
			I_Error ("Couldn't allocate lumpcache");

		memset (lumpcache,0, size);
	}
}
Example #2
0
// Merge in a file by name
boolean W_MergeFile(char *filename)
{
    int old_numlumps;

    old_numlumps = numlumps;

    // Load PWAD
    if (W_AddFile(filename) == NULL)
        return false;

    // IWAD is at the start, PWAD was appended to the end
    iwad.lumps = lumpinfo;
    iwad.numlumps = old_numlumps;

    pwad.lumps = lumpinfo + old_numlumps;
    pwad.numlumps = numlumps - old_numlumps;

    // Setup sprite/flat lists
    SetupLists();

    // Generate list of sprites to be replaced by the PWAD
    GenerateSpriteList();

    // Perform the merge
    DoMerge();

    return true;
}
Example #3
0
//
// W_InitMultipleFiles
// Pass a null terminated list of files to use.
// All files are optional, but at least one file
//  must be found.
// Files with a .wad extension are idlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
// Lump names can appear multiple times.
// The name searcher looks backwards, so a later file
//  does override all earlier ones.
//
void W_InitMultipleFiles (char** filenames)
{	
    int		size;
    
    // open all the files, load headers, and count lumps
    numlumps = 0;

    // will be realloced as lumps are added
    lumpinfo = malloc(1);	

    for ( ; *filenames ; filenames++)
	W_AddFile (*filenames);

    if (!numlumps)
	I_Error ("W_InitFiles: no files found");
    
    // set up caching
    size = numlumps * sizeof(*lumpcache);
    lumpcache = malloc (size);
    
    if (!lumpcache)
	I_Error ("Couldn't allocate lumpcache");

    memset (lumpcache,0, size);
}
Example #4
0
File: w_wad.c Project: camgunz/d2k
void W_Init(void) {
  // CPhipps - start with nothing

  numlumps = 0;
  lumpinfo = NULL;

  // CPhipps - new wadfiles array used
  // open all the files, load headers, and count lumps
  for (unsigned int i = 0; i < resource_files->len; i++)
    W_AddFile(i);

  if (!numlumps)
    I_Error("W_Init: No files found");

  //jff 1/23/98
  // get all the sprites and flats into one marked block each
  // killough 1/24/98: change interface to use M_START/M_END explicitly
  // killough 4/17/98: Add namespace tags to each entry
  // killough 4/4/98: add colormap markers
  W_CoalesceMarkedResource("S_START", "S_END", ns_sprites);
  W_CoalesceMarkedResource("F_START", "F_END", ns_flats);
  W_CoalesceMarkedResource("C_START", "C_END", ns_colormaps);
  W_CoalesceMarkedResource("B_START", "B_END", ns_prboom);
  r_have_internal_hires = (
    0 < W_CoalesceMarkedResource("HI_START", "HI_END", ns_hires)
  );

  // killough 1/31/98: initialize lump hash table
  W_HashLumps();

  /* cph 2001/07/07 - separated cache setup */
  W_InitCache();

  V_FreePlaypal();
}
Example #5
0
void W_Init(void)
{
  // CPhipps - start with nothing

  numlumps = 0; lumpinfo = NULL;

  { // CPhipps - new wadfiles array used 
    // open all the files, load headers, and count lumps
    int i;
    for (i=0; (size_t)i<numwadfiles; i++)
      W_AddFile(&wadfiles[i]);
  }

  if (!numlumps)
    I_Error ("W_Init: No files found");

  //jff 1/23/98
  // get all the sprites and flats into one marked block each
  // killough 1/24/98: change interface to use M_START/M_END explicitly
  // killough 4/17/98: Add namespace tags to each entry
  // killough 4/4/98: add colormap markers
  W_CoalesceMarkedResource("S_START", "S_END", ns_sprites);
  W_CoalesceMarkedResource("F_START", "F_END", ns_flats);
  W_CoalesceMarkedResource("C_START", "C_END", ns_colormaps);
  W_CoalesceMarkedResource("B_START", "B_END", ns_prboom);
  W_CoalesceMarkedResource("HI_START", "HI_END", ns_hires);

  // killough 1/31/98: initialize lump hash table
  W_HashLumps();

  /* cph 2001/07/07 - separated cache setup */
  lprintf(LO_INFO,"W_InitCache\n");
  W_InitCache();
}
Example #6
0
//
// W_InitMultipleFiles
// Pass a null terminated list of files to use.
// All files are optional, but at least one file
//  must be found.
// Files with a .wad extension are idlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
// Lump names can appear multiple times.
// The name searcher looks backwards, so a later file
//  does override all earlier ones.
//
void W_InitMultipleFiles (char **filenames)
{
    int		size;

    // open all the files, load headers, and count lumps
    numlumps = 0;

    // will be realloced as lumps are added
    lumpinfo = malloc(1);

    for (; *filenames; filenames++)
	W_AddFile(*filenames);

    if (!numlumps)
	I_Error("W_InitFiles: no files found");

    // merge the sprites and flats namespaces
    W_MergeLumps("S_START", "S_END");
    W_MergeLumps("F_START", "F_END");

    // set up caching
    size = numlumps * sizeof(*lumpcache);
    lumpcache = malloc(size);

    if (!lumpcache)
	I_Error("Couldn't allocate lumpcache");

    memset(lumpcache, 0, size);

    W_InitLumpHash();
}
Example #7
0
static boolean D_AddFile(char *filename)
{
    wad_file_t  *handle;

    handle = W_AddFile(filename);

    return (handle != NULL);
}
Example #8
0
//
// W_InitMultipleFiles
// Pass a null terminated list of files to use.
// All files are optional, but at least one file
//  must be found.
// Files with a .wad extension are idlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
// Lump names can appear multiple times.
// The name searcher looks backwards, so a later file
//  does override all earlier ones.
//
std::vector<std::string> W_InitMultipleFiles (std::vector<std::string> &filenames)
{
    size_t		size, i;

    // open all the files, load headers, and count lumps
    // will be realloced as lumps are added
    numlumps = 0;

    if(lumpinfo)
    {
        free(lumpinfo);
        lumpinfo = 0;
    }

    std::vector<std::string> hashes(filenames);

    // open each file once, load headers, and count lumps
    int j = 0;
    std::vector<std::string> loaded;
    for(i = 0; i < filenames.size(); i++)
    {
        if(std::find(loaded.begin(), loaded.end(), filenames[i].c_str()) == loaded.end())
        {
            hashes[j++] = W_AddFile(filenames[i].c_str());
            loaded.push_back(filenames[i].c_str());
        }
    }
    filenames = loaded;
    hashes.resize(j);

    if (!numlumps)
        I_Error ("W_InitFiles: no files found");

    // [RH] Set namespace markers to global for everything
    for (i = 0; i < numlumps; i++)
        lumpinfo[i].namespc = ns_global;

    // [RH] Merge sprite and flat groups.
    //		(We don't need to bother with patches, since
    //		Doom doesn't use markers to identify them.)
    W_MergeLumps ("S_START", "S_END", ns_sprites); // denis - fixme - security
    W_MergeLumps ("F_START", "F_END", ns_flats);
    W_MergeLumps ("C_START", "C_END", ns_colormaps);

    // set up caching
    if(lumpcache)
        free(lumpcache);

    size = numlumps * sizeof(*lumpcache);
    lumpcache = (void **)Malloc (size);

    if (!lumpcache)
        I_Error ("Couldn't allocate lumpcache");

    memset (lumpcache,0, size);

    return hashes;
}
Example #9
0
static boolean D_AddFile(char *filename)
{
    wad_file_t *handle;

    printf(" adding %s\n", filename);
    handle = W_AddFile(filename);

    return handle != NULL;
}
Example #10
0
static boolean D_AddFile(char *filename)
{
	wad_file_t *handle;

	I_Print(" adding ");
	I_Print(filename);
	I_Print("\n");
	handle = W_AddFile(filename);

	return handle != NULL;
}
Example #11
0
void W_InitMultipleFiles(char **filenames)
{
	char  **ptr;
	byte    loaded[64];			// Enough?

	iwadLoaded = false;

	// Open all the files, load headers, and count lumps
	numlumps = 0;
	lumpinfo = malloc(1);		// Will be realloced as lumps are added

	// This'll force the loader NOT the flag new records Runtime. (?)
	loadingForStartup = true;

	memset(loaded, 0, sizeof(loaded));

	// IWAD(s) must be loaded first. Let's see if one has been specified
	// with -iwad or -file options.
	for(ptr = filenames; *ptr; ptr++)
	{
		if(W_IsIWAD(*ptr))
		{
			loaded[ptr - filenames] = true;
			W_AddFile(*ptr, false);
		}
	}
	// Make sure an IWAD gets loaded; if not, display a warning.
	W_CheckIWAD();

	// Load the rest of the WADs.
	for(ptr = filenames; *ptr; ptr++)
		if(!loaded[ptr - filenames])
			W_AddFile(*ptr, false);

	if(!numlumps)
	{
		Con_Error("W_InitMultipleFiles: no files found");
	}
}
Example #12
0
void W_NWTDashMerge(char *filename)
{
    wad_file_t *wad_file;
    int old_numlumps;
    int i;

    old_numlumps = numlumps;

    // Load PWAD

    wad_file = W_AddFile(filename);

    if (wad_file == NULL)
    {
        return;
    }

    // IWAD is at the start, PWAD was appended to the end

    iwad.lumps = lumpinfo;
    iwad.numlumps = old_numlumps;

    pwad.lumps = lumpinfo + old_numlumps;
    pwad.numlumps = numlumps - old_numlumps;

    // Setup sprite/flat lists

    SetupLists();

    // Search through the IWAD sprites list.

    for (i=0; i<iwad_sprites.numlumps; ++i)
    {
        if (FindInList(&pwad, iwad_sprites.lumps[i]->name) >= 0)
        {
            // Replace this entry with an empty string.  This is what
            // nwt -merge does.

            M_StringCopy(iwad_sprites.lumps[i]->name, "", 8);
        }
    }

    // Discard PWAD
    // The PWAD must now be added in again with -file.

    numlumps = old_numlumps;

    W_CloseFile(wad_file);
}
Example #13
0
void W_NWTMergeFile(char *filename, int flags)
{
    int old_numlumps;

    old_numlumps = numlumps;

    // Load PWAD

    if (W_AddFile(filename) == NULL)
        return;

    // IWAD is at the start, PWAD was appended to the end

    iwad.lumps = lumpinfo;
    iwad.numlumps = old_numlumps;

    pwad.lumps = lumpinfo + old_numlumps;
    pwad.numlumps = numlumps - old_numlumps;

    // Setup sprite/flat lists

    SetupLists();

    // Merge in flats?

    if (flags & W_NWT_MERGE_FLATS)
    {
        W_NWTAddLumps(&iwad_flats);
    }

    // Sprites?

    if (flags & W_NWT_MERGE_SPRITES)
    {
        W_NWTAddLumps(&iwad_sprites);
    }
    
    // Discard the PWAD

    numlumps = old_numlumps;
}
Example #14
0
static void AddGameDir(const VStr& basedir, const VStr& dir)
{
	guard(AddGameDir);
	//	First add all .pk3 files in that directory.
	if (Sys_OpenDir(basedir + "/" + dir))
	{
		TArray<VStr> ZipFiles;
		for (VStr test = Sys_ReadDir(); test.IsNotEmpty(); test = Sys_ReadDir())
		{
			VStr ext = test.ExtractFileExtension().ToLower();
			if (ext == "pk3")
				ZipFiles.Append(test);
		}
		Sys_CloseDir();
		qsort(ZipFiles.Ptr(), ZipFiles.Num(), sizeof(VStr), cmpfunc);
		for (int i = 0; i < ZipFiles.Num(); i++)
		{
			AddZipFile(basedir + "/" + dir + "/" + ZipFiles[i]);
		}
	}

	//	Then add wad##.wad files.
	VStr gwadir;
	if (fl_savedir.IsNotEmpty() && basedir != fl_savedir)
	{
		gwadir = fl_savedir + "/" + dir;
	}

	for (int i = 0; i < 1024; i++)
	{
		VStr buf = basedir + "/" + dir + "/wad" + i + ".wad";
		if (!Sys_FileExists(buf))
			break;
		W_AddFile(buf, gwadir, false);
	}

	//	Finally add directory itself.
	VFilesDir* info = new VFilesDir(basedir + "/" + dir);
	SearchPaths.Append(info);
	unguard;
}
Example #15
0
//
// W_InitMultipleFiles
// Pass a null terminated list of files to use.
// All files are optional, but at least one file
//  must be found.
// Files with a .wad extension are idlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
// Lump names can appear multiple times.
// The name searcher looks backwards, so a later file
//  does override all earlier ones.
//
void W_InitMultipleFiles (const char** filenames)
{
	int		size;

	if (lumpinfo == NULL)
	{
		// open all the files, load headers, and count lumps
		numlumps = 0;

		// will be realloced as lumps are added
		lumpinfo = NULL;

		for ( ; *filenames ; filenames++)
		{
			W_AddFile (*filenames);
		}
		
		if (!numlumps)
			I_Error ("W_InitMultipleFiles: no files found");

		// set up caching
		size = numlumps * sizeof(*lumpcache);
		lumpcache = (void**)DoomLib::Z_Malloc(size, PU_STATIC_SHARED, 0 );

		if (!lumpcache)
			I_Error ("Couldn't allocate lumpcache");

		memset (lumpcache,0, size);
	} else {
		// set up caching
		size = numlumps * sizeof(*lumpcache);
		lumpcache = (void**)DoomLib::Z_Malloc(size, PU_STATIC_SHARED, 0 );

		if (!lumpcache)
			I_Error ("Couldn't allocate lumpcache");

		memset (lumpcache,0, size);
	}
}
Example #16
0
// The Doom reload hack. The idea here is that if you give a WAD file to -file
// prefixed with the ~ hack, that WAD file will be reloaded each time a new
// level is loaded. This lets you use a level editor in parallel and make
// incremental changes to the level you're working on without having to restart
// the game after every change.
// But: the reload feature is a fragile hack...
void W_Reload(void)
{
    char *filename;
    lumpindex_t i;

    if (reloadname == NULL)
    {
        return;
    }

    // We must free any lumps being cached from the PWAD we're about to reload:
    for (i = reloadlump; i < numlumps; ++i)
    {
        if (lumpinfo[i]->cache != NULL)
        {
            Z_Free(lumpinfo[i]->cache);
        }
    }

    // Reset numlumps to remove the reload WAD file:
    numlumps = reloadlump;

    // Now reload the WAD file.
    filename = reloadname;

    W_CloseFile(reloadhandle);
    free(reloadlumps);

    reloadname = NULL;
    reloadlump = -1;
    reloadhandle = NULL;
    W_AddFile(filename);
    free(filename);

    // The WAD directory has changed, so we have to regenerate the
    // fast lookup hashtable:
    W_GenerateHashTable();
}
Example #17
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 #18
0
static void HandleArgs(void)
{
    int p;

    //!
    // @vanilla
    //
    // Disable monsters.
    //

    nomonsters = M_ParmExists("-nomonsters");

    //!
    // @vanilla
    //
    // Monsters respawn after being killed.
    //

    respawnparm = M_ParmExists("-respawn");

    //!
    // @vanilla
    // @category net
    //
    // In deathmatch mode, change a player's class each time the
    // player respawns.
    //

    randomclass = M_ParmExists("-randclass");

    //!
    // @vanilla
    //
    // Take screenshots when F1 is pressed.
    //

    ravpic = M_ParmExists("-ravpic");

    //!
    // @vanilla
    //
    // Don't allow artifacts to be used when the run key is held down.
    //

    artiskip = M_ParmExists("-artiskip");

    debugmode = M_ParmExists("-debug");

    //!
    // @vanilla
    // @category net
    //
    // Start a deathmatch game.
    //

    deathmatch = M_ParmExists("-deathmatch");

    // currently broken or unused:
    cmdfrag = M_ParmExists("-cmdfrag");

    // Check WAD file command line options
    W_ParseCommandLine();

    //!
    // @vanilla
    // @arg <path>
    //
    // Development option to specify path to level scripts.
    //

    p = M_CheckParmWithArgs("-scripts", 1);

    if (p)
    {
        sc_FileScripts = true;
        sc_ScriptsDir = myargv[p+1];
    }

    //!
    // @arg <skill>
    // @vanilla
    //
    // Set the game skill, 1-5 (1: easiest, 5: hardest).  A skill of
    // 0 disables all monsters.
    //

    p = M_CheckParmWithArgs("-skill", 1);

    if (p)
    {
        startskill = myargv[p+1][0] - '1';
        autostart = true;
    }

    //!
    // @arg <demo>
    // @category demo
    // @vanilla
    //
    // Play back the demo named demo.lmp.
    //

    p = M_CheckParmWithArgs("-playdemo", 1);

    if (!p)
    {
        //!
        // @arg <demo>
        // @category demo
        // @vanilla
        //
        // Play back the demo named demo.lmp, determining the framerate
        // of the screen.
        //

        p = M_CheckParmWithArgs("-timedemo", 1);
    }

    if (p)
    {
        char *uc_filename;
        char file[256];

        M_StringCopy(file, myargv[p+1], sizeof(file));

        // With Vanilla Hexen you have to specify the file without
        // extension, but make that optional.
        uc_filename = strdup(myargv[p + 1]);
        M_ForceUppercase(uc_filename);

        if (!M_StringEndsWith(uc_filename, ".LMP"))
        {
            M_StringConcat(file, ".lmp", sizeof(file));
        }

        free(uc_filename);

        if (W_AddFile(file) != NULL)
        {
            M_StringCopy(demolumpname, lumpinfo[numlumps - 1].name,
                         sizeof(demolumpname));
        }
        else
        {
            // The file failed to load, but copy the original arg as a
            // demo name to make tricks like -playdemo demo1 possible.
            M_StringCopy(demolumpname, myargv[p+1], sizeof(demolumpname));
        }

        ST_Message("Playing demo %s.\n", myargv[p+1]);
    }

    if (M_ParmExists("-testcontrols"))
    {
        autostart = true;
        testcontrols = true;
    }
}
Example #19
0
static void ParseBase(const VStr& name)
{
	guard(ParseBase);
	TArray<version_t>	games;
	bool				select_game;
	VStr				UseName;

	if (fl_savedir.IsNotEmpty() && Sys_FileExists(fl_savedir + "/" + name))
	{
		UseName = fl_savedir + "/" + name;
	}
	else if (Sys_FileExists(fl_basedir + "/" + name))
	{
		UseName = fl_basedir + "/" + name;
	}
	else
	{
		return;
	}

	select_game = false;
	VScriptParser* sc = new VScriptParser(UseName, FL_OpenSysFileRead(UseName));
	while (!sc->AtEnd())
	{
		version_t &dst = games.Alloc();
		dst.ParmFound = 0;
		dst.FixVoices = false;
		sc->Expect("game");
		sc->ExpectString();
		dst.GameDir = sc->String;
		if (sc->Check("iwad"))
		{
			sc->ExpectString();
			dst.MainWad = sc->String;
		}
		while (sc->Check("addfile"))
		{
			sc->ExpectString();
			dst.AddFiles.Append(sc->String);
		}
		if (sc->Check("param"))
		{
			sc->ExpectString();
			dst.ParmFound = GArgs.CheckParm(*sc->String);
			if (dst.ParmFound)
			{
				select_game = true;
			}
		}
		if (sc->Check("fixvoices"))
		{
			dst.FixVoices = true;
		}
		sc->Expect("end");
	}
	delete sc;
	sc = NULL;

	for (int gi = games.Num() - 1; gi >= 0; gi--)
	{
		version_t& G = games[gi];
		if (select_game && !G.ParmFound)
		{
			continue;
		}
		if (fl_mainwad.IsNotEmpty())
		{
			if (G.MainWad.IsEmpty() || G.MainWad == fl_mainwad || select_game)
			{
				if (!bIwadAdded)
				{
					IWadIndex = SearchPaths.Num();
					VStr MainWadPath = FindMainWad(fl_mainwad);
					W_AddFile(MainWadPath, fl_savedir, G.FixVoices);
					bIwadAdded = true;
				}
				for (int j = 0; j < G.AddFiles.Num(); j++)
				{
					W_AddFile(fl_basedir + "/" + G.AddFiles[j], fl_savedir,
						false);
				}
				SetupGameDir(G.GameDir);
				return;
			}
			continue;
		}
		if (G.MainWad.IsEmpty())
		{
			continue;
		}

		//	Look for the main wad file.
		VStr MainWadPath = FindMainWad(G.MainWad);
		if (MainWadPath.IsNotEmpty())
		{
			fl_mainwad = G.MainWad;
			if (!bIwadAdded)
			{
				IWadIndex = SearchPaths.Num();
				W_AddFile(MainWadPath, fl_savedir, G.FixVoices);
				bIwadAdded = true;
			}
			for (int j = 0; j < G.AddFiles.Num(); j++)
			{
				VStr FName = FindMainWad(G.AddFiles[j]);
				if (FName.IsEmpty())
				{
					Sys_Error("Required file %s not found", *G.AddFiles[j]);
				}
				W_AddFile(FName, fl_savedir, false);
			}
			SetupGameDir(G.GameDir);
			return;
		}
	}

	if (select_game)
		Sys_Error("Main wad file not found.");
	else
		Sys_Error("Game mode indeterminate.");
	unguard;
}
Example #20
0
void FL_Init()
{
	guard(FL_Init);
	const char* p;

	//	Set up base directory (main data files).
	fl_basedir = ".";
	p = GArgs.CheckValue("-basedir");
	if (p)
	{
		fl_basedir = p;
	}

	//	Set up save directory (files written by engine).
	p = GArgs.CheckValue("-savedir");
	if (p)
	{
		fl_savedir = p;
	}
#if !defined(_WIN32)
	else
	{
		const char* HomeDir = getenv("HOME");
		if (HomeDir)
		{
			fl_savedir = VStr(HomeDir) + "/.vavoom";
		}
	}
#endif

	//	Set up additional directories where to look for IWAD files.
	int iwp = GArgs.CheckParm("-iwaddir");
	if (iwp)
	{
		while (++iwp != GArgs.Count() && GArgs[iwp][0] != '-' && GArgs[iwp][0] != '+')
		{
			IWadDirs.Append(GArgs[iwp]);
		}
	}

	AddGameDir("basev/common");

	p = GArgs.CheckValue("-iwad");
	if (p)
	{
		fl_mainwad = p;
	}

	p = GArgs.CheckValue("-devgame");
	if (p)
	{
		fl_devmode = true;
	}
	else
	{
		p = GArgs.CheckValue("-game");
	}

	if (p)
	{
		SetupGameDir(p);
	}
	else
	{
		ParseBase("basev/games.txt");
#ifdef DEVELOPER
		//  I need progs to be loaded from files
		fl_devmode = true;
#endif
	}

	int fp = GArgs.CheckParm("-file");
	if (fp)
	{
		while (++fp != GArgs.Count() && GArgs[fp][0] != '-' && GArgs[fp][0] != '+')
		{
			VStr Ext = VStr(GArgs[fp]).ExtractFileExtension().ToLower();
			if (Ext == "pk3" || Ext == "zip")
				AddZipFile(GArgs[fp]);
			else
				W_AddFile(GArgs[fp], VStr(), false);
		}
	}

	RenameSprites();
	unguard;
}
Example #21
0
static void D_AddFile(char *filename)
{
    printf("  adding %s\n", filename);

    W_AddFile(filename);
}
Example #22
0
boolean W_AddFile(const char *filename, boolean allowDuplicate)
{
	char    alterFileName[256];
	wadinfo_t header;
	DFILE  *handle;
	unsigned int length;
	filelump_t *fileinfo, singleinfo;
	filelump_t *freeFileInfo;
	filerecord_t *rec;
	const char *extension;

	// Filename given?
	if(!filename || !filename[0])
		return true;

	if((handle = F_Open(filename, "rb")) == NULL)
	{
		// Didn't find file. Try reading from the data path.
		R_PrependDataPath(filename, alterFileName);
		if((handle = F_Open(alterFileName, "rb")) == NULL)
		{
			Con_Message("W_AddFile: ERROR: %s not found!\n", filename);
			return false;
		}
		// We'll use this instead.
		filename = alterFileName;
	}

	// Do not read files twice.
	if(!allowDuplicate && !M_CheckFileID(filename))
	{
		F_Close(handle);		// The file is not used.
		return false;
	}

	Con_Message("W_AddFile: %s\n", M_Pretty(filename));

	// Determine the file name extension.
	extension = strrchr(filename, '.');
	if(!extension)
		extension = "";
	else
		extension++;			// Move to point after the dot.

	// Is it a zip/pk3 package?
	if(!stricmp(extension, "zip") || !stricmp(extension, "pk3"))
	{
		return Zip_Open(filename, handle);
	}

	// Get a new file record.
	rec = W_RecordNew();
	strcpy(rec->filename, filename);
	convertSlashes(rec->filename);
	rec->handle = handle;

	// If we're not loading for startup, flag the record to be a Runtime one.
	if(!loadingForStartup)
		rec->flags = FRF_RUNTIME;

	if(stricmp(extension, "wad") && stricmp(extension, "gwa"))
	{
		// Single lump file.
		fileinfo = &singleinfo;
		freeFileInfo = NULL;
		singleinfo.filepos = 0;
		singleinfo.size = F_Length(handle);
		M_ExtractFileBase(filename, singleinfo.name);
		rec->numlumps = 1;
	}
	else
	{
		// WAD file.
		F_Read(&header, sizeof(header), handle);
		if(!strncmp(header.identification, "JWAD", 4))
		{
			// This is treated like an IWAD, but we won't set the
			// iwadLoaded flag.
			rec->iwad = true;
		}
		else if(strncmp(header.identification, "IWAD", 4))
		{
			if(strncmp(header.identification, "PWAD", 4))
			{					// Bad file id
				Con_Error("Wad file %s doesn't have IWAD or PWAD id\n",
						  filename);
			}
		}
		else
		{
			// Found an IWAD.
			iwadLoaded = true;
			if(!stricmp(extension, "wad"))
				rec->iwad = true;
		}
		header.numlumps = LONG(header.numlumps);
		header.infotableofs = LONG(header.infotableofs);
		length = header.numlumps * sizeof(filelump_t);
		if(!(fileinfo = malloc(length)))
		{
			Con_Error("W_AddFile: fileinfo malloc failed\n");
		}
		freeFileInfo = fileinfo;
		F_Seek(handle, header.infotableofs, SEEK_SET);
		F_Read(fileinfo, length, handle);
		rec->numlumps = header.numlumps;
	}

	// Insert the lumps to lumpinfo, into their rightful places.
	W_InsertLumps(fileinfo, rec);

	if(freeFileInfo)
		free(freeFileInfo);

	PrimaryLumpInfo = lumpinfo;
	PrimaryLumpCache = lumpcache;
	PrimaryNumLumps = numlumps;

	// Print the 'CRC' number of the IWAD, so it can be identified.
	if(rec->iwad)
		Con_Message("  IWAD identification: %08x\n",
					W_CRCNumberForRecord(rec - records));

	// glBSP: Also load a possible GWA.
	if(!stricmp(extension, "wad"))
	{
		char    buff[256];

		strcpy(buff, filename);
		strcpy(buff + strlen(buff) - 3, "gwa");

		// If GL data exists, load it.
		if(F_Access(buff))
		{
			W_AddFile(buff, allowDuplicate);
		}
	}

	return true;
}