Esempio n. 1
0
            private string ReadVersion()
            {
                var value = DoomInterop.ToString(data, ptr, versionSize);

                ptr += versionSize;
                return(value);
            }
Esempio n. 2
0
            private string ReadDescription()
            {
                var value = DoomInterop.ToString(data, ptr, DescriptionSize);

                ptr += DescriptionSize;
                return(value);
            }
Esempio n. 3
0
        private static string[] LoadPatchNames(Wad wad)
        {
            var data  = wad.ReadLump("PNAMES");
            var count = BitConverter.ToInt32(data, 0);
            var names = new string[count];

            for (var i = 0; i < names.Length; i++)
            {
                names[i] = DoomInterop.ToString(data, 4 + 8 * i, 8);
            }
            return(names);
        }
Esempio n. 4
0
        private void AddFile(string fileName)
        {
            names.Add(Path.GetFileNameWithoutExtension(fileName).ToLower());

            //var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            var stream = DoomApplication.WadStream;

            streams.Add(stream);

            string identification;
            int    lumpCount;
            int    lumpInfoTableOffset;
            {
                var data = new byte[12];
                if (stream.Read(data, 0, data.Length) != data.Length)
                {
                    throw new Exception("Failed to read the WAD file.");
                }

                identification      = DoomInterop.ToString(data, 0, 4);
                lumpCount           = BitConverter.ToInt32(data, 4);
                lumpInfoTableOffset = BitConverter.ToInt32(data, 8);
                if (identification != "IWAD" && identification != "PWAD")
                {
                    throw new Exception("The file is not a WAD file.");
                }
            }

            {
                var data = new byte[LumpInfo.DataSize * lumpCount];
                stream.Seek(lumpInfoTableOffset, SeekOrigin.Begin);
                if (stream.Read(data, 0, data.Length) != data.Length)
                {
                    throw new Exception("Failed to read the WAD file.");
                }

                for (var i = 0; i < lumpCount; i++)
                {
                    var offset   = LumpInfo.DataSize * i;
                    var lumpInfo = new LumpInfo(
                        DoomInterop.ToString(data, offset + 8, 8),
                        stream,
                        BitConverter.ToInt32(data, offset),
                        BitConverter.ToInt32(data, offset + 4));
                    lumpInfos.Add(lumpInfo);
                }
            }
        }
Esempio n. 5
0
        public static SideDef FromData(byte[] data, int offset, TextureLookup textures, Sector[] sectors)
        {
            var textureOffset     = BitConverter.ToInt16(data, offset);
            var rowOffset         = BitConverter.ToInt16(data, offset + 2);
            var topTextureName    = DoomInterop.ToString(data, offset + 4, 8);
            var bottomTextureName = DoomInterop.ToString(data, offset + 12, 8);
            var middleTextureName = DoomInterop.ToString(data, offset + 20, 8);
            var sectorNum         = BitConverter.ToInt16(data, offset + 28);

            return(new SideDef(
                       Fixed.FromInt(textureOffset),
                       Fixed.FromInt(rowOffset),
                       textures.GetNumber(topTextureName),
                       textures.GetNumber(bottomTextureName),
                       textures.GetNumber(middleTextureName),
                       sectorNum != -1 ? sectors[sectorNum] : null));
        }
Esempio n. 6
0
        public static Sector FromData(byte[] data, int offset, int number, FlatLookup flats)
        {
            var floorHeight     = BitConverter.ToInt16(data, offset);
            var ceilingHeight   = BitConverter.ToInt16(data, offset + 2);
            var floorFlatName   = DoomInterop.ToString(data, offset + 4, 8);
            var ceilingFlatName = DoomInterop.ToString(data, offset + 12, 8);
            var lightLevel      = BitConverter.ToInt16(data, offset + 20);
            var special         = BitConverter.ToInt16(data, offset + 22);
            var tag             = BitConverter.ToInt16(data, offset + 24);

            return(new Sector(
                       number,
                       Fixed.FromInt(floorHeight),
                       Fixed.FromInt(ceilingHeight),
                       flats.GetNumber(floorFlatName),
                       flats.GetNumber(ceilingFlatName),
                       lightLevel,
                       (SectorSpecial)special,
                       tag));
        }
Esempio n. 7
0
        private void ReadSlots()
        {
            slots = new string[slotCount];

            var directory = ConfigUtilities.GetExeDirectory();
            var buffer    = new byte[descriptionSize];

            for (var i = 0; i < slots.Length; i++)
            {
                var path = Path.Combine(directory, "doomsav" + i + ".dsg");
                if (File.Exists(path))
                {
                    using (var reader = new FileStream(path, FileMode.Open, FileAccess.Read))
                    {
                        reader.Read(buffer, 0, buffer.Length);
                        slots[i] = DoomInterop.ToString(buffer, 0, buffer.Length);
                    }
                }
            }
        }
Esempio n. 8
0
        public static Texture FromData(byte[] data, int offset, Patch[] patchLookup)
        {
            var name       = DoomInterop.ToString(data, offset, 8);
            var masked     = BitConverter.ToInt32(data, offset + 8);
            var width      = BitConverter.ToInt16(data, offset + 12);
            var height     = BitConverter.ToInt16(data, offset + 14);
            var patchCount = BitConverter.ToInt16(data, offset + 20);
            var patches    = new TexturePatch[patchCount];

            for (var i = 0; i < patchCount; i++)
            {
                var patchOffset = offset + 22 + TexturePatch.DataSize * i;
                patches[i] = TexturePatch.FromData(data, patchOffset, patchLookup);
            }

            return(new Texture(
                       name,
                       masked != 0,
                       width,
                       height,
                       patches));
        }
Esempio n. 9
0
 public static string GetName(byte[] data, int offset)
 {
     return(DoomInterop.ToString(data, offset, 8));
 }