Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question For DOOM Add-On Programmers

11 views
Skip to first unread message

Robert Wesley Snedegar

unread,
Jan 19, 1994, 10:41:03 PM1/19/94
to
Well, I was writing a program to view the contents of the WAD, but I am
having a little problem reading in part of the file. I am posting
here because there is not an alt.games.doom.programmer group that I
know of. I am including my Header file and program code so that those
who are interested can look at it / use it as a basis for more and better
things.

The problem is that I my program is bombing when attempting to read in
the offsets (as a long int) from the WAD. Some times, one of the bytes
of the long is the EOF character ( at least according to PCTOOLS HexEdit
and other hex viewing programs.) This presents a problem to either
a) my code
b) the C++ file I/O routines
If any one can help me with thisI would appreciate it. If you want to
use the code for a much better (i.e. working correctly) program of your
own, feel free to modify as wanted. (Leave my name in the source if
you redistribute).

Source Code Coming Through

---------------------------- CUT HERE --------------------------------

//
// doominfo.h
//
// header file with structures and function declarations
// for the stuff stored in the WAD file.
// (At least as far as I can deduce.)
//

struct WAD_header
{
char iwad[5]; // The string 'IWAD'
long int num_entries; // number of items in pointer table
long int table_offset; // offset into file to beginning of pointer table
};

struct reference // pointer table entry
{ //
long int data_offset; // offset from begining of file to data
long int data_length; // size of data segment
char data_name[9]; // data name
};

struct pointer_table
{
reference * entry; // array or references
unsigned int number; // how many there are
};

void writedata(reference output); // function declaration for writing data

----------------------------- CUT HERE -----------------------------
//
// doomdat.cpp
//
// By: Robert Snedegar
// Date: 1/18/94
//
// Main code for my DOOM WAD data extractor
//

#include <fstream.h> // for io and file io in c++
#include <string.h> // for string mainipulation
#include <process.h> // for exit()

#include "doominfo.h" // local header

void writedata(reference output)
{
char temp; // temp variable
char *filename = new char[12]; // local filename of outfile
strcpy (filename, output.data_name); // create filename from ref.
strcat ( filename, ".dat"); // and append ".dat"
ifstream infile("doom1.wad"); // open DOOM1.wad
ofstream outfile(filename, ios::out); // open/create filename

infile.seekg(output.data_offset, ios::beg); // goto offset in doom1.wad
for ( long int i = 0; i < output.data_length; i++) // loop till done
{
infile.read((char*)&temp, sizeof(char)); // read a character
outfile.write((char*)&temp, sizeof(char)); // write a character
} // very kludgy, I know!
outfile.close(); // close outfile
infile.close(); // close infile
delete filename; // free pointer
}

void main()
{
WAD_header doom_header; // header variable
pointer_table doom_point; // table variable
char *filename = new char[127]; // input filename-allocated

cout << "Enter the path and file name (default = doom1.wad) \n>";
cin.get(filename, 127); // get filename or enter
if ( strlen (filename) < 1 ) // if enter, then set to
strcpy ( filename, "doom1.wad"); // doom1.wad

ifstream doomfile; // make infile object
doomfile.open (filename, ios::in); // open it up

doom_header.iwad[4] = '\x0'; // put NULL in string
//
// The following is the C++ version of fscanf(FILE, char *, arglist)
// I know this more then fscanf, thats why I am using it. maybe
// fscanf will work better. For those that dont use C++ or dont
// yet understand it all, this is reading into the variable
// the amount asked for
// read ((char*)&input, how many bytes);
// This part works fine. (debugger approved!)
//
doomfile.read((char*)&doom_header.iwad, 4*sizeof(char));
doomfile.read((char*)&doom_header.num_entries, sizeof(long int));
doomfile.read((char*)&doom_header.table_offset, sizeof(long int));
//
// set table size in its struct and output for my use
//
doom_point.number = (unsigned int)doom_header.num_entries;
cout << "Number of Entries = " << doom_point.number << endl;
//
// Attempt to allocate appropriate ammount of memory
// if fails, then EXIT
//
if ( !(doom_point.entry = new reference[(int)doom_point.number]))
{
cout << "Error allocating pointer storage.\n";
exit (-1);
}
//
// Go to the beginning of the offset table
// and prepare to read it in
//
doomfile.seekg(doom_header.table_offset, ios::beg);
// Loop -- Duhhh!
for (unsigned int i = 0; i < doom_point.number; i++)
{
//
// This is where things start going funny.
// when reading in the data, when it comes acress the char that
// represents EOF, (as in part of a long int mostly)
// (thanks to help from PCTOOLS HexEdit in viewing hex/ascii), it
// chokes out and starts spewing garbage values for everything
// any one who can help me out on this, I would greatly appreciate it.
//
doom_point.entry[i].data_name[8] = '\x0'; // terminate string
doomfile.read((unsigned char*)&doom_point.entry[i].data_offset, sizeof(long int));
doomfile.read((unsigned char*)&doom_point.entry[i].data_length, sizeof(long int));
doomfile.read((char*)doom_point.entry[i].data_name, 8*sizeof(char));
// output for my conveinience
cout << "Name : " << doom_point.entry[i].data_name << " Length : ";
cout << doom_point.entry[i].data_length << endl;
//
// This is to dump the files for my later inspection
// writedata(doom_point.entry[i]);
//
}
doomfile.close(); // close when we are done

delete filename; // free memory
delete doom_point.entry; // free memory
}
-------------------------- CUT HERE ---------------------------------

-- Robert

/*******************************************************************\
** Robert Snedegar *** The beatings will **
** rsne...@oboe.aix.calpoly.edu *** continue until the **
** rsne...@hertz.elee.calpoly.edu *** moral improves. **
** rsne...@galaxy.csc.calpoly.edu *** - The Management **
\*******************************************************************/

0 new messages