Skip to content

Instantly share code, notes, and snippets.

@AdhirRamjiawan
Created September 12, 2022 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdhirRamjiawan/32467de5a2a8713938b58f5ee4ab4c5d to your computer and use it in GitHub Desktop.
Save AdhirRamjiawan/32467de5a2a8713938b58f5ee4ab4c5d to your computer and use it in GitHub Desktop.
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