示例#1
0
文件: w_wad.c 项目: Krazygamr/D-Touch
void W_ReadLump(int lump, void *dest)
{
  lumpinfo_t *l = lumpinfo + lump;

#ifdef RANGECHECK
  if (lump >= numlumps)
    I_Error ("W_ReadLump: %i >= numlumps",lump);
#endif

//e6y
#ifdef ALL_IN_ONE
  if (l->wadfile && l->wadfile->src == source_pre)
  {
    memcpy(dest, GetAllInOneLumpHandle() + l->position, l->size);
    return;
  }
#endif

    {
      if (l->wadfile)
      {
        lseek(l->wadfile->handle, l->position, SEEK_SET);
        I_Read(l->wadfile->handle, dest, l->size);
      }
    }
}
示例#2
0
文件: w_wad.c 项目: CaptainHIT/prboom
void W_ReadLump(int lump, void *dest)
{
  lumpinfo_t *l = lumpinfo + lump;

#ifdef RANGECHECK
  if (lump >= numlumps)
    I_Error ("W_ReadLump: %i >= numlumps",lump);
#endif

    {
      if (l->wadfile)
      {
        lseek(l->wadfile->handle, l->position, SEEK_SET);
        I_Read(l->wadfile->handle, dest, l->size);
      }
    }
}
示例#3
0
文件: w_wad.c 项目: CaptainHIT/prboom
//
// W_AddFile
// All files are optional, but at least one file must be
//  found (PWAD, if all required lumps are present).
// Files with a .wad extension are wadlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
//
// Reload hack removed by Lee Killough
// CPhipps - source is an enum
//
// proff - changed using pointer to wadfile_info_t
static void W_AddFile(wadfile_info_t *wadfile) 
// killough 1/31/98: static, const
{
  wadinfo_t   header;
  lumpinfo_t* lump_p;
  unsigned    i;
  int         length;
  int         startlump;
  filelump_t  *fileinfo, *fileinfo2free=NULL; //killough
  filelump_t  singleinfo;

  // open the file and add to directory

  wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY);

#ifdef HAVE_NET
  if (wadfile->handle == -1 && D_NetGetWad(wadfile->name)) // CPhipps
    wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY);
#endif
    
  if (wadfile->handle == -1) 
    {
      if (  strlen(wadfile->name)<=4 ||      // add error check -- killough
	         (strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".lmp" ) &&
	          strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".gwa" ) )
         )
	I_Error("W_AddFile: couldn't open %s",wadfile->name);
      return;
    }

  //jff 8/3/98 use logical output routine
  lprintf (LO_INFO," adding %s\n",wadfile->name);
  startlump = numlumps;

  if (  strlen(wadfile->name)<=4 || 
	      (
          strcasecmp(wadfile->name+strlen(wadfile->name)-4,".wad") && 
	        strcasecmp(wadfile->name+strlen(wadfile->name)-4,".gwa")
        )
     )
    {
      // single lump file
      fileinfo = &singleinfo;
      singleinfo.filepos = 0;
      singleinfo.size = LONG(I_Filelength(wadfile->handle));
      ExtractFileBase(wadfile->name, singleinfo.name);
      numlumps++;
    }
  else
    {
      // WAD file
      I_Read(wadfile->handle, &header, sizeof(header));
      if (strncmp(header.identification,"IWAD",4) &&
          strncmp(header.identification,"PWAD",4))
        I_Error("W_AddFile: Wad file %s doesn't have IWAD or PWAD id", wadfile->name);
      header.numlumps = LONG(header.numlumps);
      header.infotableofs = LONG(header.infotableofs);
      length = header.numlumps*sizeof(filelump_t);
      fileinfo2free = fileinfo = malloc(length);    // killough
      lseek(wadfile->handle, header.infotableofs, SEEK_SET);
      I_Read(wadfile->handle, fileinfo, length);
      numlumps += header.numlumps;
    }

    // Fill in lumpinfo
    lumpinfo = realloc(lumpinfo, numlumps*sizeof(lumpinfo_t));

    lump_p = &lumpinfo[startlump];

    for (i=startlump ; (int)i<numlumps ; i++,lump_p++, fileinfo++)
      {
        lump_p->wadfile = wadfile;                    //  killough 4/25/98
        lump_p->position = LONG(fileinfo->filepos);
        lump_p->size = LONG(fileinfo->size);
        lump_p->li_namespace = ns_global;              // killough 4/17/98
        strncpy (lump_p->name, fileinfo->name, 8);
	lump_p->source = wadfile->src;                    // Ty 08/29/98
      }

    free(fileinfo2free);      // killough
}
示例#4
0
//
// W_AddFile
// All files are optional, but at least one file must be
//  found (PWAD, if all required lumps are present).
// Files with a .wad extension are wadlink files
//  with multiple lumps.
// Other files are single lumps with the base filename
//  for the lump name.
//
// Reload hack removed by Lee Killough
// CPhipps - source is an enum
//
// proff - changed using pointer to wadfile_info_t
static void W_AddFile(wadfile_info_t *wadfile) 
// killough 1/31/98: static, const
{
  wadinfo_t   header;
  lumpinfo_t* lump_p;
  unsigned    i;
  int         length;
  int         startlump;
  filelump_t  *fileinfo, *fileinfo2free=NULL; //killough
  filelump_t  singleinfo;
  int         flags = 0;

  // open the file and add to directory

  wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY);

#ifdef HAVE_NET
  if (wadfile->handle == -1 && D_NetGetWad(wadfile->name)) // CPhipps
    wadfile->handle = open(wadfile->name,O_RDONLY | O_BINARY);
#endif

  if (wadfile->handle == -1 &&
    strlen(wadfile->name) > 4 &&
    wadfile->src == source_pwad && 
    !strcasecmp(wadfile->name + strlen(wadfile->name) - 4 , ".wad") &&
    D_TryGetWad(wadfile->name))
  {
    wadfile->handle = open(wadfile->name, O_RDONLY | O_BINARY);
  }

  if (wadfile->handle == -1) 
    {
      if (  strlen(wadfile->name)<=4 ||      // add error check -- killough
	         (strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".lmp" ) &&
	          strcasecmp(wadfile->name+strlen(wadfile->name)-4 , ".gwa" ) )
         )
	I_Error("W_AddFile: couldn't open %s",wadfile->name);
      return;
    }

  //jff 8/3/98 use logical output routine
  lprintf (LO_INFO," adding %s\n",wadfile->name);
  startlump = numlumps;

  // mark lumps from internal resource
  if (wadfile->src == source_auto_load)
  {
    int len = strlen(PACKAGE_TARNAME ".wad");
    int len_file = strlen(wadfile->name);
    if (len_file >= len)
    {
      if (!strcasecmp(wadfile->name + len_file - len, PACKAGE_TARNAME ".wad"))
      {
        flags = LUMP_PRBOOM;
      }
    }
  }

  if (  strlen(wadfile->name)<=4 || 
	      (
          strcasecmp(wadfile->name+strlen(wadfile->name)-4,".wad") && 
	        strcasecmp(wadfile->name+strlen(wadfile->name)-4,".gwa")
        )
     )
    {
      // single lump file
      fileinfo = &singleinfo;
      singleinfo.filepos = 0;
      singleinfo.size = LittleLong(I_Filelength(wadfile->handle));
      ExtractFileBase(wadfile->name, singleinfo.name);
      numlumps++;
    }
  else
    {
      // WAD file
      I_Read(wadfile->handle, &header, sizeof(header));
      if (strncmp(header.identification,"IWAD",4) &&
          strncmp(header.identification,"PWAD",4))
        I_Error("W_AddFile: Wad file %s doesn't have IWAD or PWAD id", wadfile->name);
      header.numlumps = LittleLong(header.numlumps);
      header.infotableofs = LittleLong(header.infotableofs);
      length = header.numlumps*sizeof(filelump_t);
      fileinfo2free = fileinfo = malloc(length);    // killough
      lseek(wadfile->handle, header.infotableofs, SEEK_SET),
      I_Read(wadfile->handle, fileinfo, length);
      numlumps += header.numlumps;
    }

    // Fill in lumpinfo
    lumpinfo = realloc(lumpinfo, numlumps*sizeof(lumpinfo_t));

    lump_p = &lumpinfo[startlump];

    for (i=startlump ; (int)i<numlumps ; i++,lump_p++, fileinfo++)
      {
        lump_p->flags = flags;
        lump_p->wadfile = wadfile;                    //  killough 4/25/98
        lump_p->position = LittleLong(fileinfo->filepos);
        lump_p->size = LittleLong(fileinfo->size);
        if (wadfile->src == source_lmp)
        {
          // Modifications to place command-line-added demo lumps
          // into a separate "ns_demos" namespace so that they cannot
          // conflict with other lump names
          lump_p->li_namespace = ns_demos;
        }
        else
        {
          lump_p->li_namespace = ns_global;              // killough 4/17/98
        }
        strncpy (lump_p->name, fileinfo->name, 8);
	lump_p->source = wadfile->src;                    // Ty 08/29/98
    // IWAD file used as recource PWAD must not override TEXTURE1 or PNAMES
    if (wadfile->src != source_iwad && !strncmp(header.identification,"IWAD",4) &&
      (!strnicmp(fileinfo->name,"TEXTURE1",8) || !strnicmp(fileinfo->name,"PNAMES",6)))
    {
      strncpy (lump_p->name, "-IGNORE-", 8);
    }
      }

    free(fileinfo2free);      // killough
}