Exemplo n.º 1
0
        // Get a single resource from the WAD file
        public static byte[] GetResource(FileStream wadStream, WADEntry entry)
        {
            wadStream.Seek(entry.ResourceOffset, SeekOrigin.Begin);

            var bytes = new byte[entry.ResourceLength];

            wadStream.Read(bytes, 0, entry.ResourceLength);

            return(bytes);
        }
Exemplo n.º 2
0
        // Get a raw sprite - floors and ceilings mostly
        public static SpriteData GetRawSprite(FileStream wadStream, WADEntry spriteEntry)
        {
            var res = GetResource(wadStream, spriteEntry);

            return(new SpriteData(spriteEntry.Name, SpriteType.Raw, 64, 64, 0, 0, res));
        }
Exemplo n.º 3
0
        // Get a picture sprite: basically, anything that is not a floor or ceiling texture
        public static SpriteData GetPictureSprite(FileStream wadStream, WADEntry spriteEntry)
        {
            var res = GetResource(wadStream, spriteEntry);

            return(new SpriteData(spriteEntry.Name, SpriteType.Picture, BitConverter.ToInt16(res, 0), BitConverter.ToInt16(res, 2), BitConverter.ToInt16(res, 4), BitConverter.ToInt16(res, 6), res));
        }
Exemplo n.º 4
0
        // Deals with reading data from the WAD file
        // See https://github.com/nukeop/TheUnofficialDoomSpecs

        public static WADInfo GetInfo(FileStream wadStream)
        {
            // Root WAD data
            var wi = new WADInfo()
            {
                Type            = ReadString(wadStream, 0, 4),
                NumEntries      = ReadInt(wadStream, 4, 4),
                DirectoryOffset = ReadInt(wadStream, 8, 4)
            };

            // Get a list of the contents of the WAD
            for (var i = 0; i < wi.NumEntries; i++)
            {
                var entryOffset = wi.DirectoryOffset + (i * 16);
                var entry       = new WADEntry()
                {
                    ResourceOffset = ReadInt(wadStream, entryOffset, 4),
                    ResourceLength = ReadInt(wadStream, entryOffset + 4, 4),
                    Name           = ReadString(wadStream, entryOffset + 8, 8)
                };
                wi.Entries.Add(entry);
                if (!wi.EntryDictionary.ContainsKey(entry.Name.Replace("\0", "")))
                {
                    wi.EntryDictionary.Add(entry.Name.Replace("\0", ""), entry);
                    //Debug.Log(entry.Name);
                }
            }

            // Wall patches
            // Get patchnames lookup
            var patchesEntry = wi.EntryDictionary["PNAMES"];
            var patchesData  = GetResource(wadStream, patchesEntry);
            var numPatches   = BitConverter.ToInt32(patchesData, 0);

            wi.PatchNames = new string[numPatches];
            var pos = 4;

            for (var i = 0; i < numPatches; i++)
            {
                wi.PatchNames[i] = Encoding.UTF8.GetString(patchesData, pos, 8).ToUpper().Replace("\0", "");
                pos += 8;
            }

            // Wall textures: textures listed in the TEXTURE1 resource are for shareware (Episode 1) maps, all others are in TEXTURE2.
            var texEntry = wi.EntryDictionary["TEXTURE1"];
            var texList  = GetTextures(wadStream, wi, GetResource(wadStream, texEntry));

            foreach (var t in texList)
            {
                wi.WallTextures.Add(t.Name, t);
            }
            if (wi.EntryDictionary.ContainsKey("TEXTURE2"))
            {
                texEntry = wi.EntryDictionary["TEXTURE2"];
                texList  = GetTextures(wadStream, wi, GetResource(wadStream, texEntry));
                foreach (var t in texList)
                {
                    wi.WallTextures.Add(t.Name, t);
                }
            }

            return(wi);
        }