Exemple #1
0
        static void Main(string[] arguments)
        {
            Message("doomwadcorrupter v{0} arookas", new Version(0, 1, 12));
            Separator();
            if (arguments == null || arguments.Length < 2)
            {
                Message("Usage: doomwadcorrupter <input.wad> <output.wad> [options]");
                Message();
                Message("Options:");
                Message("    -start <value>");
                Message("    -end <value>");
                Message("    -inc <value>");
                Message("    -mode <type> [<value>]");
                Message("    -skip <filter> [<filter> [...]]");
                Message("    -only <filter> [<filter> [...]]");
                Message("    -zdoom");
                Message();
                Message("For more detailed instructions, refer to the official repo page.");
                Pause();
                Exit(false);
            }
            var inputWAD  = arguments[0];
            var outputWAD = arguments[1];

            cmd     = new aCommandLine(arguments.Skip(2).ToArray());
            options = new CorrupterOptions(cmd);
            DisplayOptions(inputWAD, outputWAD);

            int lumpCount;
            var lumpsCorrupted = 0;
            var lumpsSkipped   = 0;
            var bytesCorrupted = 0;

            rnd = new Random((uint)options.CorruptSeed);
            var timeTaken = Stopwatch.StartNew();

            using (var instream = OpenWAD(inputWAD)) {
                var reader = new aBinaryReader(instream, Endianness.Little, Encoding.ASCII);

                // header
                var wadType = reader.ReadString(4);

                if (wadType != "IWAD" && wadType != "PWAD")
                {
                    Error("Input file is not a DOOM WAD.");
                }

                lumpCount = reader.ReadS32();
                var directoryOffset = reader.ReadS32();

                // directory
                reader.Goto(directoryOffset);
                var lumps = aCollection.Initialize(lumpCount, () => new Lump(reader));

                using (var outstream = CreateWAD(outputWAD)) {
                    var writer = new aBinaryWriter(outstream, Endianness.Little, Encoding.ASCII);
                    // header
                    writer.WriteString(wadType);
                    writer.WriteS32(lumpCount);
                    writer.WriteS32(directoryOffset);

                    // data
                    var corruptBuff = new byte[options.Increment];
                    var startBuff   = new byte[options.Start];
                    var ns          = LumpNamespace.Global;

                    foreach (var lump in lumps)
                    {
                        reader.Goto(lump.Start);
                        writer.Goto(lump.Start);
                        CheckNamespaceMarker(lump, ref ns);
                        if (options.Filter.IsCorruptable(lump.Name, ns) && !(options.ZDOOM && IsZDOOMLump(lump.Name)))
                        {
                            ++lumpsCorrupted;
                            var i   = options.Start;
                            var end = options.End ?? lump.Length;
                            if (i > 0)
                            {
                                var count = (int)System.Math.Min(lump.Length, i);
                                reader.Read(startBuff, count);
                                writer.Write8s(startBuff, count);
                            }
                            while (i < lump.Length && i < end)
                            {
                                Status("Corrupting '{0}'... (0x{1:X8} / 0x{2:X8})", lump.Name, i, lump.Length);
                                var count = (int)System.Math.Min(lump.Length - i, options.Increment);
                                reader.Read(corruptBuff, count);
                                CorruptByte(ref corruptBuff[0], options.CorruptMode, options.CorruptValue);
                                writer.Write8s(corruptBuff, count);
                                ++bytesCorrupted;
                                i += count;
                            }
                        }
                        else
                        {
                            ++lumpsSkipped;
                            writer.Write8s(reader.Read8s(lump.Length));
                        }
                    }

                    // directory
                    writer.Goto(directoryOffset);
                    foreach (var lump in lumps)
                    {
                        Status("Writing lump directory for '{0}'...", lump.Name);
                        lump.ToStream(writer);
                    }
                }
            }

            timeTaken.Stop();
            Status("Finished corrupting.");
            Message();
            Separator();
            Message("                       Files : {0}", lumpCount);
            Message("             Files corrupted : {0}", lumpsCorrupted);
            Message("               Files skipped : {0}", lumpsSkipped);
            Message("Bytes mercilessly sacrificed : {0}", bytesCorrupted);
            Message("                  Time taken : {0}", timeTaken.Elapsed.ToString("g"));
            Message("                 Finished at : {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            Pause();
        }
        static void Main(string[] arguments)
        {
            Message("doomwadcorrupter v{0} arookas", new Version(0, 1, 12));
            Separator();
            if (arguments == null || arguments.Length < 2) {
                Message("Usage: doomwadcorrupter <input.wad> <output.wad> [options]");
                Message();
                Message("Options:");
                Message("    -start <value>");
                Message("    -end <value>");
                Message("    -inc <value>");
                Message("    -mode <type> [<value>]");
                Message("    -skip <filter> [<filter> [...]]");
                Message("    -only <filter> [<filter> [...]]");
                Message("    -zdoom");
                Message();
                Message("For more detailed instructions, refer to the official repo page.");
                Pause();
                Exit(false);
            }
            var inputWAD = arguments[0];
            var outputWAD = arguments[1];
            cmd = new aCommandLine(arguments.Skip(2).ToArray());
            options = new CorrupterOptions(cmd);
            DisplayOptions(inputWAD, outputWAD);

            int lumpCount;
            var lumpsCorrupted = 0;
            var lumpsSkipped = 0;
            var bytesCorrupted = 0;
            rnd = new Random((uint)options.CorruptSeed);
            var timeTaken = Stopwatch.StartNew();
            using (var instream = OpenWAD(inputWAD)) {
                var reader = new aBinaryReader(instream, Endianness.Little, Encoding.ASCII);

                // header
                var wadType = reader.ReadString(4);

                if (wadType != "IWAD" && wadType != "PWAD") {
                    Error("Input file is not a DOOM WAD.");
                }

                lumpCount = reader.ReadS32();
                var directoryOffset = reader.ReadS32();

                // directory
                reader.Goto(directoryOffset);
                var lumps = aCollection.Initialize(lumpCount, () => new Lump(reader));

                using (var outstream = CreateWAD(outputWAD)) {
                    var writer = new aBinaryWriter(outstream, Endianness.Little, Encoding.ASCII);
                    // header
                    writer.WriteString(wadType);
                    writer.WriteS32(lumpCount);
                    writer.WriteS32(directoryOffset);

                    // data
                    var corruptBuff = new byte[options.Increment];
                    var startBuff = new byte[options.Start];
                    var ns = LumpNamespace.Global;

                    foreach (var lump in lumps) {
                        reader.Goto(lump.Start);
                        writer.Goto(lump.Start);
                        CheckNamespaceMarker(lump, ref ns);
                        if (options.Filter.IsCorruptable(lump.Name, ns) && !(options.ZDOOM && IsZDOOMLump(lump.Name))) {
                            ++lumpsCorrupted;
                            var i = options.Start;
                            var end = options.End ?? lump.Length;
                            if (i > 0) {
                                var count = (int)System.Math.Min(lump.Length, i);
                                reader.Read(startBuff, count);
                                writer.Write8s(startBuff, count);
                            }
                            while (i < lump.Length && i < end) {
                                Status("Corrupting '{0}'... (0x{1:X8} / 0x{2:X8})", lump.Name, i, lump.Length);
                                var count = (int)System.Math.Min(lump.Length - i, options.Increment);
                                reader.Read(corruptBuff, count);
                                CorruptByte(ref corruptBuff[0], options.CorruptMode, options.CorruptValue);
                                writer.Write8s(corruptBuff, count);
                                ++bytesCorrupted;
                                i += count;
                            }
                        }
                        else {
                            ++lumpsSkipped;
                            writer.Write8s(reader.Read8s(lump.Length));
                        }
                    }

                    // directory
                    writer.Goto(directoryOffset);
                    foreach (var lump in lumps) {
                        Status("Writing lump directory for '{0}'...", lump.Name);
                        lump.ToStream(writer);
                    }
                }
            }

            timeTaken.Stop();
            Status("Finished corrupting.");
            Message();
            Separator();
            Message("                       Files : {0}", lumpCount);
            Message("             Files corrupted : {0}", lumpsCorrupted);
            Message("               Files skipped : {0}", lumpsSkipped);
            Message("Bytes mercilessly sacrificed : {0}", bytesCorrupted);
            Message("                  Time taken : {0}", timeTaken.Elapsed.ToString("g"));
            Message("                 Finished at : {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            Pause();
        }