GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


Doom .WAD Reading by baldurk
bool ReadWad()
{
  // BEGIN READING WAD!
  FILE *fp = fopen("doom2.wad", "r");
  if(!fp)
  {
    cout << "Holy cow! Can't open doom2.wad" << endl;
    return false;
  }

  char ID[5];
  memset(ID, 0, 5);
  fread(ID, sizeof(char), 4, fp);

  if(strcmp(ID, "IWAD") && strcmp(ID, "PWAD"))
  {
    cout << "Holy cow! doom2.wad ain't a valid PWAD or IWAD. ID: " << ID << endl;
    return false;
  }

  long size, offset;
  fread(&size, sizeof(long), 1, fp);
  cerr << "Got " << size << " lumps." << endl;

  fread(&offset, sizeof(long), 1, fp);
  cerr << "Directory at: " << offset << endl;

  cerr << "Seeking.." << endl;

  int ret = fseek(fp, offset, SEEK_SET);

  if(ret)
  {
    cout << "Holy cow! error seeking to directory." << endl;
    return false;
  }

  return true;
}