Example #1
0
/*
   open the main WAD file, read in its directory and create the master directory
*/
void OpenMainWad( char *filename)
{
   MDirPtr lastp, newp;
   WadPtr wad;
   long n;

   /* open the WAD file */
   printf( "Loading main WAD file: %s...\n", filename);
   wad = BasicWadOpen( filename);
   if (strncmp( wad->type, "IWAD", 4))
      ProgError( "\"%s\" is not the main WAD file", filename);

   /* create the master directory */
   lastp = NULL;
   for (n = 0; n < wad->dirsize; n++)
   {
      newp = (MDirPtr) GetMemory( sizeof( struct MasterDirectory));
      newp->next = NULL;
      newp->wadfile = wad;
      memcpy( (char *) &(newp->dir), (char *) &(wad->directory[ n]), sizeof( struct Directory));
      if (MasterDir)
	 lastp->next = newp;
      else
	 MasterDir = newp;
      lastp = newp;
   }

   /* check if registered/commercial/ultimate version */
   /* if you change this, bad things will happen to you... */
   if (FindMasterDir( MasterDir, "E4M9") != NULL)
      GameVersion = 4;
   else if (FindMasterDir( MasterDir, "MAP29") != NULL)
      GameVersion = 2;
   else if (FindMasterDir( MasterDir, "E2M9") != NULL)
      GameVersion = 1;

   /* check if Heretic version */
   if (FindMasterDir( MasterDir, "M_HTIC") != NULL)
      GameVersion += 16;
}
Example #2
0
////////////////////////////////////////////////////////////
// TViewSpriteDialog
// -----------------
//
void TViewSpriteDialog::SetupWindow ()
{
	TViewBitmapListDialog::SetupWindow();

	SetCaption ("Viewing Sprites");
	pChooseStatic->SetCaption ("Choose sprite name:");

	// Insert sprites names in list box
	MDirPtr dir = FindMasterDir( MasterDir, "S_START");
	for (dir = dir->next ;
		 dir != NULL && strcmp(dir->dir.name, "S_END") ;
		 dir = dir->next)
	{
		char str[MAX_BITMAPNAME + 1];

		strncpy (str, dir->dir.name, MAX_BITMAPNAME);
		str[MAX_BITMAPNAME] = '\0';

		pBitmapList->AddString (str);
	}
}
Example #3
0
////////////////////////////////////////////////////////////
// TSprite256Control
// -----------------
//
void TSprite256Control::LoadPictureData (const char *picname, BYTE HUGE **ppData,
										 USHORT *pxsize, USHORT *pysize,
										 SHORT remapPlayer)
{
  MDirPtr  dir;
	SHORT  x, y;
	SHORT  xofs, yofs;
	 BYTE HUGE *lpColumnData;
	 BYTE *lpColumn;
	 BYTE  color;
	 LONG *lpNeededOffsets;
	SHORT  nColumns, nCurrentColumn;
	 LONG  lCurrentOffset;
	SHORT  i, n;
	 BYTE  bRowStart, bColored;

	assert (pUsedColors != NULL);

	TRACE ("TSprite256Control::LoadPictureData(" << dec << picname);

	// Search for picture name
	dir = FindMasterDir (MasterDir, (char *)picname);
	if (dir == NULL)
	{
		*ppData = NULL;
		// Notify ("Couldn't find sprite or picture \"%s\" (BUG!)", picname);
		return;
	}

	// Read picture size and offset
	BasicWadSeek(dir->wadfile, dir->dir.start);
	BasicWadRead(dir->wadfile, pxsize, 2L);
	BasicWadRead(dir->wadfile, pysize, 2L);
	// We ingnore x and y offsets
	BasicWadRead(dir->wadfile, &xofs, 2L);
	BasicWadRead(dir->wadfile, &yofs, 2L);
	xofs = yofs = 0;

	USHORT xsize = *pxsize;
	USHORT ysize = *pysize;
	nColumns = xsize;

	// Allocate space for bitmap data
	ULONG dsize = (ULONG)xsize * ysize;

	TRACE ("TSprite256Control::LoadPictureData: " << dec
		   << "Datasize = " << dsize
		   << ", xsize = "  << xsize
		   << ", ysize = "  << ysize);

	*ppData = (BYTE *)GetMemory (dsize);

#define TEX_COLUMNBUFFERSIZE    (60L * 1024L)
#define TEX_COLUMNSIZE      512L

// dir->size - 4 shorts (size and offset) - Columns offsets * 4L
#define CD_BUFFER_SIZE		(dir->dir.size - 4 * 2L - nColumns * 4L)

	/* Note from CJS:
	   I tried to use far memory originally, but kept getting out-of-mem errors
	   that is really strange - I assume that the wad dir et al uses all
	   the far mem, and there is only near memory available. NEVER seen
	   this situation before..... I'll keep them huge pointers anyway,
	   in case something changes later
	*/
	lpColumnData = (BYTE HUGE *)GetMemory (CD_BUFFER_SIZE);

	// Initialize columns offsets
	lpNeededOffsets = (LONG *)GetMemory (nColumns * 4L);
	BasicWadRead (dir->wadfile, lpNeededOffsets, nColumns * 4);

	// read first column data, and subsequent column data
	BasicWadSeek(dir->wadfile, dir->dir.start + lpNeededOffsets[0]);
	BasicWadRead(dir->wadfile, lpColumnData, CD_BUFFER_SIZE);

	for (nCurrentColumn = 0; nCurrentColumn < nColumns; nCurrentColumn++)
	{
		lCurrentOffset  = lpNeededOffsets[nCurrentColumn];
		assert (lCurrentOffset - lpNeededOffsets[0] < CD_BUFFER_SIZE);
		lpColumn = (BYTE *)&lpColumnData[lCurrentOffset - lpNeededOffsets[0]];

		/* we now have the needed column data, one way or another, so write it */
		n = 1;
		bRowStart = lpColumn[0];
		x = nCurrentColumn;
		while (bRowStart != 255 && n < TEX_COLUMNSIZE)
		{
			bColored = lpColumn[n];
			n += 2;             // skip over 'null' pixel in data
			y = bRowStart;
			for (i = 0; i < bColored; i++)
			{
				assert (x >= 0 && x < xsize);
				assert (y >= 0 && y < ysize);

				color = lpColumn[i+n];
				// Remap player start position color (GREEN, RED, ...)
				if ( (remapPlayer) && (color >= 0x70) && (color < 0x80))
					color += remapPlayer;

				(*ppData)[(LONG)y * xsize + x] = color;
				pUsedColors[color] = TRUE;
				y++;
			}
			n += bColored + 1;  // skip over written pixels, and the 'null' one
			bRowStart = lpColumn[n++];
		}
		assert (bRowStart == 255);
	}
	FreeMemory (lpColumnData);
	FreeMemory (lpNeededOffsets);
}
Example #4
0
/*
   open a patch WAD file, read in its directory and alter the master directory
*/
void OpenPatchWad( char *filename)
{
   MDirPtr mdir = 0;
   WadPtr wad;
   BCINT n, l;
   char entryname[ 9];

   /* ignore the file if it doesn't exist */
   if (! Exists( filename))
   {
      printf( "Warning: patch WAD file \"%s\" doesn't exist.  Ignored.\n", filename);
      return;
   }

   /* open the WAD file */
   printf( "Loading patch WAD file: %s...\n", filename);
   wad = BasicWadOpen( filename);
   if (strncmp( wad->type, "PWAD", 4))
      ProgError( "\"%s\" is not a patch WAD file", filename);

   /* alter the master directory */
   l = 0;
   for (n = 0; n < wad->dirsize; n++)
   {
      strncpy( entryname, wad->directory[ n].name, 8);
      entryname[ 8] = '\0';
      if (l == 0)
      {
	 mdir = FindMasterDir( MasterDir, wad->directory[ n].name);
	 /* if this entry is not in the master directory, then add it */
	 if (! mdir)
	 {
	    printf( "   [Adding new entry %s]\n", entryname);
	    mdir = MasterDir;
	    while (mdir->next)
	       mdir = mdir->next;
	    mdir->next = (MDirPtr) GetMemory( sizeof( struct MasterDirectory));
	    mdir = mdir->next;
	    mdir->next = NULL;
	 }
	 /* if this is a level, then copy this entry and the next 10 */
	 else if ((GameVersion == 2 && wad->directory[ n].name[ 0] == 'M' &&
				       wad->directory[ n].name[ 1] == 'A' &&
				       wad->directory[ n].name[ 2] == 'P' &&
				       wad->directory[ n].name[ 5] == '\0') ||
		  (GameVersion != 2 && wad->directory[ n].name[ 0] == 'E' &&
				       wad->directory[ n].name[ 2] == 'M' &&
				       wad->directory[ n].name[ 4] == '\0'))
	 {
	    printf( "   [Updating level %s]\n", entryname);
	    l = 10;
	 }
	 else
	    printf( "   [Updating entry %s]\n", entryname);
      }
      else
      {
	 mdir = mdir->next;
	 /* the level data should replace an existing level */
	 if (mdir == NULL || strncmp(mdir->dir.name, wad->directory[ n].name, 8))
	    ProgError( "\\%s\" is not an understandable PWAD file (error with %s)", filename, entryname);
	 l--;
      }
      mdir->wadfile = wad;
      memcpy( (char *) &(mdir->dir), (char *) &(wad->directory[ n]), sizeof( struct Directory));
   }
}