Esempio n. 1
0
 /// <summary>
 /// Opens an existing WAD file for reading
 /// </summary>
 /// <param name="fName">File name</param>
 public WADfile(string fName)
 {
     Program.Log(Verbosity.Debug, "Loading {0} into Memory", fName);
     using (FileStream FS = File.OpenRead(fName))
     {
         using (BinaryReader BR = new BinaryReader(FS))
         {
             string temp = ToString(BR.ReadBytes(4));
             if (temp == "IWAD")
             {
                 Type = WADtype.IWAD;
             }
             else if (temp == "PWAD")
             {
                 Type = WADtype.PWAD;
             }
             else
             {
                 throw new NotSupportedException("Unsupported file. Unknown Header");
             }
             int NumEntries = BR.ReadInt32();
             int Directory  = BR.ReadInt32();
             Program.Log(Verbosity.Debug, "Number of Entries: {0}, Directory start: {1}", NumEntries, Directory);
             FS.Seek(Directory, SeekOrigin.Begin);
             Entries = new WADentry[NumEntries];
             for (int i = 0; i < NumEntries; i++)
             {
                 int    Pos  = BR.ReadInt32();
                 int    Len  = BR.ReadInt32();
                 string Name = ToString(BR.ReadBytes(8));
                 if (Len > 0 && Pos > 0)
                 {
                     Program.Log(Verbosity.Debug, "{0} is {1} bytes", Name, Len);
                     byte[] Data          = new byte[Len];
                     int    currentOffset = (int)FS.Position;
                     //Read Data and seek back
                     FS.Seek(Pos, SeekOrigin.Begin);
                     FS.Read(Data, 0, Len);
                     FS.Seek(currentOffset, SeekOrigin.Begin);
                     Entries[i] = new WADentry(Name, Pos, (byte[])Data.Clone());
                 }
                 else
                 {
                     Program.Log(Verbosity.Debug, "{0} is Virtual", Name);
                     Entries[i] = new WADentry(Name, 0, null);
                 }
             }
         }
     }
     Program.Log(Verbosity.Info, "WAD file has {0} entries ({1} virtual)", Entries.Length, Entries.Count(m => m.Virtual));
 }
Esempio n. 2
0
 /// <summary>
 /// Opens an existing WAD file for reading
 /// </summary>
 /// <param name="fName">File name</param>
 public WADfile(string fName)
 {
     using (FileStream FS = File.OpenRead(fName))
     {
         using (BinaryReader BR = new BinaryReader(FS))
         {
             string temp = ToString(BR.ReadBytes(4));
             if (temp == "IWAD")
             {
                 Type = WADtype.IWAD;
             }
             else if (temp == "PWAD")
             {
                 Type = WADtype.PWAD;
             }
             else
             {
                 throw new Exception("Not a WAD file. Wrong Header");
             }
             int NumEntries = BR.ReadInt32();
             int Directory  = BR.ReadInt32();
             FS.Seek(Directory, SeekOrigin.Begin);
             Entries = new WADentry[NumEntries];
             for (int i = 0; i < NumEntries; i++)
             {
                 int    Pos  = BR.ReadInt32();
                 int    Len  = BR.ReadInt32();
                 string Name = ToString(BR.ReadBytes(8));
                 if (Len > 0 && Pos > 0)
                 {
                     byte[] Data          = new byte[Len];
                     int    currentOffset = (int)FS.Position;
                     FS.Seek(Pos, SeekOrigin.Begin);
                     FS.Read(Data, 0, Len);
                     FS.Seek(currentOffset, SeekOrigin.Begin);
                     Entries[i] = new WADentry(Name, Pos, (byte[])Data.Clone());
                 }
                 else
                 {
                     Entries[i] = new WADentry(Name, 0, null);
                 }
             }
         }
     }
 }