C# example to load Doom WAD file

using System;
using System.IO;
namespace waddy
{
class Program
{
static string GetString(byte[] arr)
{
return System.Text.ASCIIEncoding.ASCII.GetString(arr);
}
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
if (File.Exists("DOOM.WAD"))
{
using (BinaryReader reader = new BinaryReader(File.Open("DOOM.WAD", FileMode.Open)))
{
string name = GetString(reader.ReadBytes(4));
int numberOfLumps = reader.ReadInt32();
int folderPosition = reader.ReadInt32();
reader.BaseStream.Seek(folderPosition, SeekOrigin.Begin);
Console.WriteLine(name);
Console.WriteLine("Contains " + numberOfLumps + " lumps");
int count = 0;
while (reader.BaseStream.Position < reader.BaseStream.Length)
{
reader.BaseStream.Seek(folderPosition + (16 * count), SeekOrigin.Begin);
int filePos = reader.ReadInt32();
int fileSize = reader.ReadInt32();
string lumpName = GetString(reader.ReadBytes(8));
//Console.WriteLine("Next lump pos is " + filePos);
//Console.WriteLine("Next lump size is " + fileSize);
Console.WriteLine("Next lump name is " + lumpName);
//reader.BaseStream.Seek(filePos + 12, SeekOrigin.Begin);
count++;
}
}
}
}
}
}


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *