Exemplo n.º 1
0
 public static Patch FromWad(Wad wad, string name)
 {
     //* test for fullscreen graphics
     if (name == "TITLE")
     {
         return(FromDataRaw(name, wad.ReadLump(name)));
     }
     return(FromData(name, wad.ReadLump(name)));
 }
Exemplo n.º 2
0
        private void Init(Wad wad)
        {
            textures      = new List <Texture>();
            nameToTexture = new Dictionary <string, Texture>();
            nameToNumber  = new Dictionary <string, int>();

            var patches = LoadPatches(wad);

            for (var n = 1; n <= 2; n++)
            {
                var lumpNumber = wad.GetLumpNumber("TEXTURE" + n);
                if (lumpNumber == -1)
                {
                    break;
                }

                var data  = wad.ReadLump(lumpNumber);
                var count = BitConverter.ToInt32(data, 0);
                for (var i = 0; i < count; i++)
                {
                    var offset  = BitConverter.ToInt32(data, 4 + 4 * i);
                    var texture = Texture.FromData(data, offset, patches);
                    nameToNumber.Add(texture.Name, textures.Count);
                    textures.Add(texture);
                    nameToTexture.Add(texture.Name, texture);
                }
            }
        }
Exemplo n.º 3
0
        public static BlockMap FromWad(Wad wad, int lump, LineDef[] lines)
        {
            var data = wad.ReadLump(lump);

            var table = new short[data.Length / 2];

            for (var i = 0; i < table.Length; i++)
            {
                var offset = 2 * i;
                table[i] = BitConverter.ToInt16(data, offset);
            }

            var originX = Fixed.FromInt(table[0]);
            var originY = Fixed.FromInt(table[1]);
            var width   = table[2];
            var height  = table[3];

            return(new BlockMap(
                       originX,
                       originY,
                       width,
                       height,
                       table,
                       lines));
        }
Exemplo n.º 4
0
        public ColorMap(Wad wad)
        {
            try
            {
                Console.Write("Load color map: ");

                var raw = wad.ReadLump("COLORMAP");
                var num = raw.Length / 256;
                data = new byte[num][];
                for (var i = 0; i < num; i++)
                {
                    data[i] = new byte[256];
                    var offset = 256 * i;
                    for (var c = 0; c < 256; c++)
                    {
                        data[i][c] = raw[offset + c];
                    }
                }

                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
Exemplo n.º 5
0
        private void InitDummy(Wad wad)
        {
            textures      = new List <Texture>();
            nameToTexture = new Dictionary <string, Texture>();
            nameToNumber  = new Dictionary <string, int>();

            for (var n = 1; n <= 2; n++)
            {
                var lumpNumber = wad.GetLumpNumber("TEXTURE" + n);
                if (lumpNumber == -1)
                {
                    break;
                }

                var data  = wad.ReadLump(lumpNumber);
                var count = BitConverter.ToInt32(data, 0);
                for (var i = 0; i < count; i++)
                {
                    var offset  = BitConverter.ToInt32(data, 4 + 4 * i);
                    var name    = Texture.GetName(data, offset);
                    var height  = Texture.GetHeight(data, offset);
                    var texture = Dummy.GetTexture(height);
                    nameToNumber.Add(name, textures.Count);
                    textures.Add(texture);
                    nameToTexture.Add(name, texture);
                }
            }
        }
Exemplo n.º 6
0
        public SfmlAudio(Wad wad)
        {
            buffers    = new SoundBuffer[DoomInfo.SfxNames.Length];
            amplitudes = new short[DoomInfo.SfxNames.Length];
            for (var i = 0; i < DoomInfo.SfxNames.Length; i++)
            {
                var lump = wad.GetLumpNumber("DS" + DoomInfo.SfxNames[i]);

                if (lump == -1)
                {
                    continue;
                }

                var data = wad.ReadLump(lump);

                var sampleRate  = BitConverter.ToUInt16(data, 2);
                var sampleCount = BitConverter.ToInt32(data, 4) - 32;
                var samples     = new short[sampleCount];
                for (var t = 0; t < samples.Length; t++)
                {
                    samples[t] = (short)((data[24 + t] - 128) << 8);
                }

                buffers[i] = new SoundBuffer(samples, 1, sampleRate);

                short max = 0;
                if (sampleCount > 0)
                {
                    var count = Math.Min(sampleRate / 5, sampleCount);
                    for (var t = 0; t < count; t++)
                    {
                        var a = samples[t];
                        if (a == short.MinValue)
                        {
                            max = short.MaxValue;
                            break;
                        }
                        if (a < 0)
                        {
                            a = (short)(-a);
                        }
                        if (a > max)
                        {
                            max = a;
                        }
                    }
                }
                amplitudes[i] = max;
            }

            channels   = new Sound[channelCount];
            sources    = new Mobj[channelCount];
            priorities = new float[channelCount];
            for (var i = 0; i < channels.Length; i++)
            {
                channels[i] = new Sound();
            }
        }
Exemplo n.º 7
0
        private static Patch CachedRead(int lump, Wad wad, Dictionary <int, Patch> cache)
        {
            if (!cache.ContainsKey(lump))
            {
                var name = wad.LumpInfos[lump].Name;
                cache.Add(lump, Patch.FromData(name, wad.ReadLump(lump)));
            }

            return(cache[lump]);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public ColorMap(Wad wad)
        {
            var raw = wad.ReadLump("COLORMAP");
            var num = raw.Length / 256;

            data = new byte[num][];
            for (var i = 0; i < num; i++)
            {
                data[i] = new byte[256];
                var offset = 256 * i;
                for (var c = 0; c < 256; c++)
                {
                    data[i][c] = raw[offset + c];
                }
            }
        }
Exemplo n.º 10
0
        private void InitStandard(Wad wad)
        {
            try
            {
                Console.Write("Load flats: ");

                var firstFlat = wad.GetLumpNumber("F_START") + 1;
                var lastFlat  = wad.GetLumpNumber("F_END") - 1;
                var count     = lastFlat - firstFlat + 1;

                flats = new Flat[count];

                nameToFlat   = new Dictionary <string, Flat>();
                nameToNumber = new Dictionary <string, int>();

                for (var lump = firstFlat; lump <= lastFlat; lump++)
                {
                    if (wad.GetLumpSize(lump) != 4096 && wad.GetLumpSize(lump) != 4)
                    {
                        continue;
                    }

                    var number = lump - firstFlat;
                    var name   = wad.LumpInfos[lump].Name;
                    var flat   = new Flat(name, wad.ReadLump(lump));

                    flats[number]      = flat;
                    nameToFlat[name]   = flat;
                    nameToNumber[name] = number;
                }

                skyFlatNumber = nameToNumber["F_SKY1"];
                skyFlat       = nameToFlat["F_SKY1"];

                Console.WriteLine("OK (" + nameToFlat.Count + " flats)");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
Exemplo n.º 11
0
        private static Patch[] LoadPatches(Wad wad)
        {
            var patchNames = LoadPatchNames(wad);
            var patches    = new Patch[patchNames.Length];

            for (var i = 0; i < patches.Length; i++)
            {
                var name = patchNames[i];

                // This check is necessary to avoid crash in DOOM1.WAD.
                if (wad.GetLumpNumber(name) == -1)
                {
                    continue;
                }

                var data = wad.ReadLump(name);
                patches[i] = Patch.FromData(name, data);
            }
            return(patches);
        }
Exemplo n.º 12
0
        public static Subsector[] FromWad(Wad wad, int lump, Seg[] segs)
        {
            var length = wad.GetLumpSize(lump);

            if (length % Subsector.DataSize != 0)
            {
                throw new Exception();
            }

            var data       = wad.ReadLump(lump);
            var count      = length / Subsector.DataSize;
            var subsectors = new Subsector[count];

            for (var i = 0; i < count; i++)
            {
                var offset = Subsector.DataSize * i;
                subsectors[i] = Subsector.FromData(data, offset, segs);
            }

            return(subsectors);
        }
Exemplo n.º 13
0
        public static Seg[] FromWad(Wad wad, int lump, Vertex[] vertices, LineDef[] lines)
        {
            var length = wad.GetLumpSize(lump);

            if (length % Seg.DataSize != 0)
            {
                throw new Exception();
            }

            var data  = wad.ReadLump(lump);
            var count = length / Seg.DataSize;
            var segs  = new Seg[count];;

            for (var i = 0; i < count; i++)
            {
                var offset = Seg.DataSize * i;
                segs[i] = Seg.FromData(data, offset, vertices, lines);
            }

            return(segs);
        }
Exemplo n.º 14
0
        public static Node[] FromWad(Wad wad, int lump, Subsector[] subsectors)
        {
            var length = wad.GetLumpSize(lump);

            if (length % Node.DataSize != 0)
            {
                throw new Exception();
            }

            var data  = wad.ReadLump(lump);
            var count = length / Node.DataSize;
            var nodes = new Node[count];

            for (var i = 0; i < count; i++)
            {
                var offset = Node.DataSize * i;
                nodes[i] = Node.FromData(data, offset);
            }

            return(nodes);
        }
Exemplo n.º 15
0
        public static Vertex[] FromWad(Wad wad, int lump)
        {
            var length = wad.GetLumpSize(lump);

            if (length % DataSize != 0)
            {
                throw new Exception();
            }

            var data     = wad.ReadLump(lump);
            var count    = length / DataSize;
            var vertices = new Vertex[count];;

            for (var i = 0; i < count; i++)
            {
                var offset = DataSize * i;
                vertices[i] = FromData(data, offset);
            }

            return(vertices);
        }
Exemplo n.º 16
0
        public static Sector[] FromWad(Wad wad, int lump, FlatLookup flats)
        {
            var length = wad.GetLumpSize(lump);

            if (length % dataSize != 0)
            {
                throw new Exception();
            }

            var data    = wad.ReadLump(lump);
            var count   = length / dataSize;
            var sectors = new Sector[count];;

            for (var i = 0; i < count; i++)
            {
                var offset = dataSize * i;
                sectors[i] = FromData(data, offset, i, flats);
            }

            return(sectors);
        }
Exemplo n.º 17
0
        public static SideDef[] FromWad(Wad wad, int lump, TextureLookup textures, Sector[] sectors)
        {
            var length = wad.GetLumpSize(lump);

            if (length % dataSize != 0)
            {
                throw new Exception();
            }

            var data  = wad.ReadLump(lump);
            var count = length / dataSize;
            var sides = new SideDef[count];;

            for (var i = 0; i < count; i++)
            {
                var offset = dataSize * i;
                sides[i] = FromData(data, offset, textures, sectors);
            }

            return(sides);
        }
Exemplo n.º 18
0
        public static MapThing[] FromWad(Wad wad, int lump)
        {
            var length = wad.GetLumpSize(lump);

            if (length % DataSize != 0)
            {
                throw new Exception();
            }

            var data   = wad.ReadLump(lump);
            var count  = length / DataSize;
            var things = new MapThing[count];

            for (var i = 0; i < count; i++)
            {
                var offset = DataSize * i;
                things[i] = FromData(data, offset);
            }

            return(things);
        }
Exemplo n.º 19
0
        public static LineDef[] FromWad(Wad wad, int lump, Vertex[] vertices, SideDef[] sides)
        {
            var length = wad.GetLumpSize(lump);

            if (length % DataSize != 0)
            {
                throw new Exception();
            }

            var data  = wad.ReadLump(lump);
            var count = length / DataSize;
            var lines = new LineDef[count];;

            for (var i = 0; i < count; i++)
            {
                var offset = 14 * i;
                lines[i] = FromData(data, offset, vertices, sides);
            }

            return(lines);
        }
Exemplo n.º 20
0
        private void Init(Wad wad)
        {
            try
            {
                Console.Write("Load textures: ");

                textures      = new List <Texture>();
                nameToTexture = new Dictionary <string, Texture>();
                nameToNumber  = new Dictionary <string, int>();

                var patches = LoadPatches(wad);

                for (var n = 1; n <= 2; n++)
                {
                    var lumpNumber = wad.GetLumpNumber("TEXTURE" + n);
                    if (lumpNumber == -1)
                    {
                        break;
                    }

                    var data  = wad.ReadLump(lumpNumber);
                    var count = BitConverter.ToInt32(data, 0);
                    for (var i = 0; i < count; i++)
                    {
                        var offset  = BitConverter.ToInt32(data, 4 + 4 * i);
                        var texture = Texture.FromData(data, offset, patches);
                        nameToNumber.TryAdd(texture.Name, textures.Count);
                        textures.Add(texture);
                        nameToTexture.TryAdd(texture.Name, texture);
                    }
                }

                Console.WriteLine("OK (" + textures.Count + " textures)");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
Exemplo n.º 21
0
        public Palette(Wad wad)
        {
            try
            {
                Console.Write("Load palette: ");

                data = wad.ReadLump("PLAYPAL");

                var count = data.Length / (3 * 256);
                palettes = new uint[count][];
                for (var i = 0; i < palettes.Length; i++)
                {
                    palettes[i] = new uint[256];
                }

                Console.WriteLine("OK");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
Exemplo n.º 22
0
        private void Init(Wad wad)
        {
            foreach (var lump in EnumerateFlats(wad))
            {
                var name = wad.LumpInfos[lump].Name;

                if (nameToFlat.ContainsKey(name))
                {
                    continue;
                }

                var data = wad.ReadLump(lump);

                var flat = Flat.FromData(name, data);

                nameToNumber.Add(name, flats.Count);
                flats.Add(flat);
                nameToFlat.Add(name, flat);
            }

            skyFlatNumber = nameToNumber["F_SKY1"];
            skyFlat       = nameToFlat["F_SKY1"];
        }
Exemplo n.º 23
0
        public static void ReadDeHackEdLump(Wad wad)
        {
            var lump = wad.GetLumpNumber("DEHACKED");

            if (lump != -1)
            {
                // Ensure the static members are initialized.
                DoomInfo.Strings.PRESSKEY.GetHashCode();

                try
                {
                    Console.Write("Load DeHackEd patch from WAD: ");

                    ProcessLines(ReadLines(wad.ReadLump(lump)));

                    Console.WriteLine("OK");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed");
                    throw new Exception("Failed to apply DeHackEd patch!", e);
                }
            }
        }
Exemplo n.º 24
0
        public Palette(Wad wad)
        {
            data = wad.ReadLump("PLAYPAL");

            GammaCorrectionTest();
        }
Exemplo n.º 25
0
        private void InitDeuTexMerge(Wad wad)
        {
            try
            {
                Console.Write("Load flats: ");

                var allFlats = new List <int>();
                var flatZone = false;
                for (var lump = 0; lump < wad.LumpInfos.Count; lump++)
                {
                    var name = wad.LumpInfos[lump].Name;
                    if (flatZone)
                    {
                        if (name == "F_END" || name == "FF_END")
                        {
                            flatZone = false;
                        }
                        else
                        {
                            allFlats.Add(lump);
                        }
                    }
                    else
                    {
                        if (name == "F_START" || name == "FF_START")
                        {
                            flatZone = true;
                        }
                    }
                }
                allFlats.Reverse();

                var dupCheck      = new HashSet <string>();
                var distinctFlats = new List <int>();
                foreach (var lump in allFlats)
                {
                    if (!dupCheck.Contains(wad.LumpInfos[lump].Name))
                    {
                        distinctFlats.Add(lump);
                        dupCheck.Add(wad.LumpInfos[lump].Name);
                    }
                }
                distinctFlats.Reverse();

                flats = new Flat[distinctFlats.Count];

                nameToFlat   = new Dictionary <string, Flat>();
                nameToNumber = new Dictionary <string, int>();

                for (var number = 0; number < flats.Length; number++)
                {
                    var lump = distinctFlats[number];

                    if (wad.GetLumpSize(lump) != 4096)
                    {
                        continue;
                    }

                    var name = wad.LumpInfos[lump].Name;
                    var flat = new Flat(name, wad.ReadLump(lump));

                    flats[number]      = flat;
                    nameToFlat[name]   = flat;
                    nameToNumber[name] = number;
                }

                skyFlatNumber = nameToNumber["F_SKY1"];
                skyFlat       = nameToFlat["F_SKY1"];

                Console.WriteLine("OK (" + nameToFlat.Count + " flats)");
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed");
                ExceptionDispatchInfo.Throw(e);
            }
        }
Exemplo n.º 26
0
 public static Patch FromWad(Wad wad, string name)
 {
     return(FromData(name, wad.ReadLump(name)));
 }
Exemplo n.º 27
0
 public static Reject FromWad(Wad wad, int lump, Sector[] sectors)
 {
     return(new Reject(wad.ReadLump(lump), sectors.Length));
 }