Beispiel #1
0
        private void ReadTextureEntries(BinaryReader br)
        {
            var validTypes = Enum.GetValues(typeof(WadEntryType)).OfType <WadEntryType>().Select(x => (byte)x).ToArray();

            br.BaseStream.Position = _lumpOffset;
            for (var i = 0; i < _numTextures; i++)
            {
                var offset           = br.ReadUInt32();
                var compressedLength = br.ReadUInt32();
                var fullLength       = br.ReadUInt32();
                var type             = br.ReadByte();
                var compressionType  = br.ReadByte();
                br.ReadBytes(2); // struct padding
                var name = br.ReadFixedLengthString(Encoding.ASCII, 16).ToLowerInvariant();

                if (!validTypes.Contains(type))
                {
                    continue;                             // Skip unsupported types
                }
                if (_entries.ContainsKey(name))
                {
                    continue;                             // Don't add duplicates
                }
                _entries[name] = new WadEntry(name, (WadEntryType)type, offset, compressionType, compressedLength, fullLength);
            }
        }
Beispiel #2
0
 public WadImageStream(WadEntry entry, Stream stream)
 {
     _entry = entry;
     using (var br = new BinaryReader(stream))
     {
         PrepareData(br);
     }
 }
Beispiel #3
0
 public Stream OpenEntry(WadEntry entry)
 {
     if (entry == null)
     {
         throw new FileNotFoundException();
     }
     return(new WadImageStream(entry, new SubStream(_stream, entry.Offset, entry.Length)));
 }
Beispiel #4
0
 public WadImageStream(WadEntry entry, WadPackage package)
 {
     _entry = entry;
     using (var br = new BinaryReader(package.File.Open()))
     {
         br.BaseStream.Position = entry.Offset;
         PrepareData(br);
     }
 }
Beispiel #5
0
        private void SetEntryData(WadEntry e, BinaryReader br)
        {
            uint width, height, paletteSize;
            long textureDataOffset, paletteDataOffset;

            switch (e.Type)
            {
            case WadEntryType.Image:
                width                   = br.ReadUInt32();
                height                  = br.ReadUInt32();
                textureDataOffset       = br.BaseStream.Position;
                br.BaseStream.Position += width * height;     // Skip texture data
                paletteSize             = br.ReadUInt16();
                paletteDataOffset       = br.BaseStream.Position;
                break;

            case WadEntryType.Texture:
                br.BaseStream.Position += 16;     // Skip name
                width             = br.ReadUInt32();
                height            = br.ReadUInt32();
                textureDataOffset = br.BaseStream.Position + 16;
                var num         = (int)(width * height);
                var skipMapData = (num / 4) + (num / 16) + (num / 64);
                br.BaseStream.Position += 16 + num + skipMapData;     // Skip mipmap offsets, texture data, mipmap texture data
                paletteSize             = br.ReadUInt16();
                paletteDataOffset       = br.BaseStream.Position;
                break;

            /*
             * case WadEntryType.Font:
             *  width = br.ReadUInt32();
             *  height = br.ReadUInt32();
             *  textureDataOffset = br.BaseStream.Position + 8 + (256 * 4);
             *  br.BaseStream.Position += 8 + (256 * 4) + (width * height); // Skip font data, texture data
             *  paletteSize = br.ReadUInt16();
             *  paletteDataOffset = br.BaseStream.Position;
             *  break;*/
            default:
                throw new ArgumentOutOfRangeException();
            }
            e.Width             = width;
            e.Height            = height;
            e.PaletteSize       = paletteSize;
            e.TextureDataOffset = textureDataOffset;
            e.PaletteDataOffset = paletteDataOffset;
        }