components/prboom/d_main.c
//
// CheckIWAD
//
// Verify a file is indeed tagged as an IWAD
// Scan its lumps for levelnames and return gamemode as indicated
// Detect missing wolf levels in DOOM II
//
// The filename to check is passed in iwadname, the gamemode detected is
// returned in gmode, hassec returns the presence of secret levels
//
// jff 4/19/98 Add routine to test IWAD for validity and determine
// the gamemode from it. Also note if DOOM II, whether secret levels exist
// CPhipps - const char* for iwadname, made static
CheckIWAD
Verify a file is indeed tagged as an IWAD
Scan its lumps for levelnames and return gamemode as indicated
Detect missing wolf levels in DOOM II

The filename to check is passed in iwadname, the gamemode detected is
returned in gmode, hassec returns the presence of secret levels

jff 4/19/98 Add routine to test IWAD for validity and determine
the gamemode from it. Also note if DOOM II, whether secret levels exist
CPhipps - const char* for iwadname, made static
CheckIWAD Verify a file is indeed tagged as an IWAD Scan its lumps for levelnames and return gamemode as indicated Detect missing wolf levels in DOOM II The filename to check is passed in iwadname the gamemode detected is returned in gmode hassec returns the presence of secret levels jff 4 / 19 / 98 Add routine to test IWAD for validity and determine the gamemode from it . Also note if DOOM II whether secret levels exist CPhipps - const char * for iwadname made static
static void CheckIWAD(const char *iwadname,GameMode_t *gmode,boolean *hassec)
{
    int ud=0,rg=0,sw=0,cm=0,sc=0;
      wadinfo_t header;
	int fd;
	{
	fd=I_Open(iwadname, 0);
	I_Read(fd, &header, sizeof(header));
      if (!strncmp(header.identification, "IWAD", 4))
      {
        size_t length;
        filelump_t *fileinfo;
        header.numlumps = LONG(header.numlumps);
        header.infotableofs = LONG(header.infotableofs);
        length = header.numlumps;
        fileinfo = malloc(length*sizeof(filelump_t));
		I_Lseek(fd, header.infotableofs, SEEK_SET);
		I_Read(fd, fileinfo, sizeof(filelump_t)*length);
        while (length--)
          if (fileinfo[length].name[0] == 'E' &&
              fileinfo[length].name[2] == 'M' &&
              fileinfo[length].name[4] == 0)
          {
            if (fileinfo[length].name[1] == '4')
              ++ud;
            else if (fileinfo[length].name[1] == '3')
              ++rg;
            else if (fileinfo[length].name[1] == '2')
              ++rg;
            else if (fileinfo[length].name[1] == '1')
              ++sw;
          }
          else if (fileinfo[length].name[0] == 'M' &&
                    fileinfo[length].name[1] == 'A' &&
                    fileinfo[length].name[2] == 'P' &&
                    fileinfo[length].name[5] == 0)
          {
            ++cm;
            if (fileinfo[length].name[3] == '3')
              if (fileinfo[length].name[4] == '1' ||
                  fileinfo[length].name[4] == '2')
                ++sc;
          }
        free(fileinfo);
      }
      else 
        I_Error("CheckIWAD: IWAD tag %s not present", iwadname);
      I_Close(fd);
    }
    *gmode = indetermined;
    *hassec = false;
    if (cm>=30)
    {
      *gmode = commercial;
      *hassec = sc>=2;
    }
    else if (ud>=9)
      *gmode = retail;
    else if (rg>=18)
      *gmode = registered;
    else if (sw>=9)
      *gmode = shareware;
}
static void CheckIWAD ( const char * iwadname , GameMode_t * gmode , boolean * hassec ) { int ud = 0 , rg = 0 , sw = 0 , cm = 0 , sc = 0 ; wadinfo_t header ; int fd ; { fd = I_Open ( iwadname , 0 ) ; I_Read ( fd , & header , sizeof ( header ) ) ; if ( ! strncmp ( header . identification , " " , 4 ) ) { size_t length ; filelump_t * fileinfo ; header . numlumps = LONG ( header . numlumps ) ; header . infotableofs = LONG ( header . infotableofs ) ; length = header . numlumps ; fileinfo = malloc ( length * sizeof ( filelump_t ) ) ; I_Lseek ( fd , header . infotableofs , SEEK_SET ) ; I_Read ( fd , fileinfo , sizeof ( filelump_t ) * length ) ; while ( length -- ) if ( fileinfo [ length ] . name [ 0 ] == ' ' && fileinfo [ length ] . name [ 2 ] == ' ' && fileinfo [ length ] . name [ 4 ] == 0 ) { if ( fileinfo [ length ] . name [ 1 ] == ' ' ) ++ ud ; else if ( fileinfo [ length ] . name [ 1 ] == ' ' ) ++ rg ; else if ( fileinfo [ length ] . name [ 1 ] == ' ' ) ++ rg ; else if ( fileinfo [ length ] . name [ 1 ] == ' ' ) ++ sw ; } else if ( fileinfo [ length ] . name [ 0 ] == ' ' && fileinfo [ length ] . name [ 1 ] == ' ' && fileinfo [ length ] . name [ 2 ] == ' ' && fileinfo [ length ] . name [ 5 ] == 0 ) { ++ cm ; if ( fileinfo [ length ] . name [ 3 ] == ' ' ) if ( fileinfo [ length ] . name [ 4 ] == ' ' || fileinfo [ length ] . name [ 4 ] == ' ' ) ++ sc ; } free ( fileinfo ) ; } else I_Error ( " " , iwadname ) ; I_Close ( fd ) ; } * gmode = indetermined ; * hassec = false ; if ( cm >= 30 ) { * gmode = commercial ; * hassec = sc >= 2 ; } else if ( ud >= 9 ) * gmode = retail ; else if ( rg >= 18 ) * gmode = registered ; else if ( sw >= 9 ) * gmode = shareware ; }
CheckIWAD
Verify a file is indeed tagged as an IWAD
Scan its lumps for levelnames and return gamemode as indicated
Detect missing wolf levels in DOOM II
CheckIWAD Verify a file is indeed tagged as an IWAD Scan its lumps for levelnames and return gamemode as indicated Detect missing wolf levels in DOOM II
//  if ( !access (iwadname,R_OK) ) //  { // read IWAD header // read IWAD directory //        if (fseek (fp, header.infotableofs, SEEK_SET) || //            fread (fileinfo, sizeof(filelump_t), length, fp) != length || //            fclose(fp)) //          I_Error("CheckIWAD: failed to read directory %s",iwadname); // scan directory for levelname lumps // missing IWAD tag in header //else // error from open call //      I_Error("CheckIWAD: Can't open IWAD %s", iwadname); // Determine game mode from levels present // Must be a full set for whichever mode is present // Lack of wolf-3d levels also detected here //  } //  else // error from access call //    I_Error("CheckIWAD: IWAD %s not readable", iwadname);