示例#1
0
        /// <summary>
        /// Main method.
        /// </summary>
        /// <param name="args">Array of command-line parameters</param>
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }

            using (WadFile wad = new WadFile())
            {
                foreach (string file in args)
                {
                    if (!File.Exists(file))
                    {
                        continue;
                    }

                    string lumpName = Regex.Replace(
                        Path.GetFileNameWithoutExtension(file).ToUpperInvariant(),
                        @"[^\u0000-\u007F]+", string.Empty); // Remove non-ASCII characters

                    wad.AddLump(lumpName, File.ReadAllBytes(file));
                }

                wad.SaveToFile("PackedFiles.wad");
            }
        }
示例#2
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="args">Command line parameters</param>
        public PNGToWad(params string[] args)
        {
            string[] mapBitmapFiles = (from string file in args where File.Exists(file) && Path.GetExtension(file).ToLowerInvariant() == ".png" select file).ToArray();

            if (mapBitmapFiles.Length == 0)
            {
                Console.WriteLine("Missing parameters or no valid PNG file in the parameters.");
                Console.WriteLine("Syntax is: PixelsOfDoom.exe SomeImage.png [SomeOtherImage.png] [YetAnotherImage.png]...");
                Console.ReadKey();
                return;
            }

            string wadFile = Path.GetFileNameWithoutExtension(mapBitmapFiles[0]) + ".wad"; // Output file is the name of the first file with a WAD extension.

#if DEBUG
            Preferences config = new Preferences(@"..\Release\Preferences.ini");
#else
            Preferences config = new Preferences("Preferences.ini");
#endif
            MapGenerator generator = new MapGenerator(config);
            WadFile      wad       = new WadFile();

            for (int i = 0; i < mapBitmapFiles.Length; i++)
            {
                int mapNumber = i + 1;

                if ((config.Doom1Format && (mapNumber > 9)) || (!config.Doom1Format && (mapNumber > 99))) // Too many maps, stop here
                {
                    break;
                }

#if !DEBUG
                try
                {
#endif
                string mapName = config.Doom1Format ? $"E{config.Episode:0}M{mapNumber:0}" : $"MAP{mapNumber:00}";

                using (Bitmap bitmap = (Bitmap)Image.FromFile(mapBitmapFiles[i]))
                {
                    using (DoomMap map = generator.Generate(mapName, bitmap))
                    {
                        map.AddToWad(wad);
                    }
                }
#if !DEBUG
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine();
                continue;
            }
#endif
            }

            wad.SaveToFile(wadFile);
            wad.Dispose();
            generator.Dispose();

            if (config.BuildNodes)
            {
                Process bspProcess;

                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                    Console.WriteLine("Building nodes with bsp-w32.exe...");
#if DEBUG
                    bspProcess = Process.Start(@"..\Release\bsp-w32.exe", $"\"{wadFile}\" -o \"{wadFile}\"");
#else
                    bspProcess = Process.Start("bsp-w32.exe", $"\"{wadFile}\" -o \"{wadFile}\"");
#endif
                    bspProcess.WaitForExit();
                    if (bspProcess.ExitCode != 0)
                    {
                        Console.WriteLine("Failed to build nodes!");
                    }
                    break;
                }
            }
        }