Exemplo n.º 1
0
        public static string[] GetTextureList(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            var reader = new BinaryReader(stream);

            var startOffset = stream.Position;

            // Validate version
            uint version = reader.ReadUInt32();

            if (version != Version)
            {
                throw new BspLib.Wad.Exceptions.WadVersionNotSupportedException(version);
            }

            int num    = reader.ReadInt32();
            int offset = reader.ReadInt32();

            List <string> names = new List <string>(num);

            stream.Position = offset + startOffset;
            for (int i = 0; i < num; i++)
            {
                var entry = WadEntry.Read(reader);
                // Is a texture
                if (entry.Type == WadEntry.TextureType)
                {
                    // Compressed
                    if (entry.Compressed)
                    {
                        // Could not find how it works (no documentation).
                        // In official github ( https://github.com/ValveSoftware/halflife/blob/5d761709a31ce1e71488f2668321de05f791b405/utils/common/wadlib.c on line 301 ):
                        //    // F I X M E: do compression
                        Console.Error.WriteLine("WadEntry ID={0}, Name='{1}' is compressed texture which is not supported. Skipping.", i, entry.Name_s);
                    }
                    // Not Compressed
                    else
                    {
                        names.Add(entry.Name_s);
                    }
                }
                // Not a texture
                else
                {
                    Console.Error.WriteLine("WadEntry ID={0}, Name='{1}' has unknown / unsupported type 0x{2:X2}.", i, entry.Name_s, entry.Type);
                }
            }

            return(names.ToArray());
        }
Exemplo n.º 2
0
        public static void Load(WadFile wad, Stream stream)
        {
            if (wad == null)
            {
                throw new ArgumentNullException("wad");
            }
            if (stream == null)
            {
                throw new ArgumentOutOfRangeException("stream");
            }

            var reader = new BinaryReader(stream);

            var startOffset = stream.Position;// Position of start in stream (current - version)

            // Validate version
            uint version = reader.ReadUInt32();

            if (version != Version)
            {
                throw new BspLib.Wad.Exceptions.WadVersionNotSupportedException(version);
            }

            // Header
            int num    = reader.ReadInt32(); // Number of entries, not textures
            int offset = reader.ReadInt32();

            var entries = new List <WadEntry>();

            // Offset of entries
            // Often bedore end of file
            stream.Position = offset + startOffset;
            for (int i = 0; i < num; i++)
            {
                var entry = WadEntry.Read(reader);
                // Is a texture
                if (entry.Type == WadEntry.TextureType)
                {
                    // Compressed
                    if (entry.Compressed)
                    {
                        // Could not find how it works (no documentation).
                        // In official github ( https://github.com/ValveSoftware/halflife/blob/5d761709a31ce1e71488f2668321de05f791b405/utils/common/wadlib.c on line 301 ):
                        //    // F I X M E: do compression
                        Console.Error.WriteLine("WadEntry ID={0}, Name='{1}' is compressed texture which is not supported. Skipping.", i, entry.Name_s);
                    }
                    // Not Compressed
                    else
                    {
                        entries.Add(entry);
                    }
                }
                // Not a texture
                else
                {
                    Console.Error.WriteLine("WadEntry ID={0}, Name='{1}' has unknown / unsupported type 0x{2:X2}.", i, entry.Name_s, entry.Type);
                }
            }

            // Load all textures
            for (int i = 0; i < entries.Count; i++)
            {
                var entry = entries[i];

                stream.Position = entry.PositionInFile + startOffset;

                //TODO Load entry
                throw new NotImplementedException("Loading entry is not implemented yet.");
            }
        }