Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Doom WAD file reader
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++;
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment