DooM Wad level name viewer
Hi this is the starting point of my to be WAD tool for doom this class allows you to show all the lump names in the main doom.wad file.
Comments and suggestions welcome.
Class code cWad.cs
vbnet Code:
Imports System.IO
Imports System.Text
Public Class cWad
Public LumpNames As List(Of String)
Public Sub LoadWad(ByVal Filename As String)
Dim br As BinaryReader = Nothing
Dim Counter As Integer = 0
'Wad variables.
Dim Sig As String = vbNullString
Dim Lumps As Integer = 0
Dim Offset As Integer = 0
'Lump variables.
Dim LumpAddr As Integer = 0
Dim LumpSize As Integer = 0
Dim LumpName As String = vbNullString
'Open wad filename.
br = New BinaryReader(File.OpenRead(Filename))
'Get header sig should be IWAD
Sig = Encoding.ASCII.GetString(br.ReadBytes(4))
'Check for vaild wad sig
If Not Sig.Equals("IWAD") Then
Throw New ArgumentException("No Vaild IWAD Header Found")
Exit Sub
End If
'Read number of lumps and lump start offset.
Lumps = br.ReadInt32
Offset = br.ReadInt32
'Create new lump names list.
LumpNames = New List(Of String)
'Seek to Offset
br.BaseStream.Seek(Offset, SeekOrigin.Begin)
While( Counter < Lumps)
'Read lump offset and lump size.
LumpAddr = br.ReadInt32
LumpSize = br.ReadInt32
'Get lump name.
LumpName = Encoding.ASCII.GetString(br.ReadBytes(8)).Replace(Chr(0), "")
'Add lump name to list
LumpNames.Add(LumpName)
'INC Counter
Counter += 1
End While
'Close file.
br.Close()
End Sub
End Class
Example showing level names.
vbnet Code:
Dim WadFile As New cWad
Try
'Load wad filename.
WadFile.LoadWad("C:\out\data\DOOM.WAD")
ListBox1.Items.Clear()
'This sniplet below adds all the doom level names to a listbox.
For Each Item As String In WadFile.LumpNames
If Item.StartsWith("E") And Char.IsDigit(Item(1)) Then
ListBox1.Items.Add(Item)
End If
Next Item
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub