Exemple #1
0
        private static void MainInner(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

            try {
                Everest.ParseArgs(args);
                orig_Main(args);
            } catch (Exception e) {
                CriticalFailureHandler(e);
                return;
            } finally {
                Instance?.Dispose();
            }

            Everest.Shutdown();
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            if (Thread.CurrentThread.Name != "Main Thread")
            {
                Thread.CurrentThread.Name = "Main Thread";
            }

            if (File.Exists("BuildIsXNA.txt"))
            {
                File.Delete("BuildIsXNA.txt");
            }
            if (File.Exists("BuildIsFNA.txt"))
            {
                File.Delete("BuildIsFNA.txt");
            }
            File.WriteAllText($"BuildIs{(typeof(Game).Assembly.FullName.Contains("FNA") ? "FNA" : "XNA")}.txt", "");

            if (File.Exists("launch.txt"))
            {
                args =
                    File.ReadAllLines("launch.txt")
                    .Select(l => l.Trim())
                    .Where(l => !l.StartsWith("#"))
                    .SelectMany(l => l.Split(' '))
                    .Concat(args)
                    .ToArray();
            }
            else
            {
                using (StreamWriter writer = File.CreateText("launch.txt")) {
                    writer.WriteLine("# Add any Everest launch flags here. Lines starting with # are ignored.");
                    writer.WriteLine();
                    writer.WriteLine("# If you're having graphics issues with the FNA version on Windows,");
                    writer.WriteLine("# remove the # from the following line to enable using Direct3D.");
                    writer.WriteLine("#--d3d");
                    writer.WriteLine();
                    writer.WriteLine("# If you've got an Intel GPU, are using the FNA version on Windows and");
                    writer.WriteLine("# are 100% sure that you want to use Intel's possibly broken OpenGL drivers,");
                    writer.WriteLine("# remove the # from the following line to revert to using OpenGL.");
                    writer.WriteLine("#--no-d3d");
                    writer.WriteLine();
                }
            }

            if (args.Contains("--console") && PlatformHelper.Is(MonoMod.Utils.Platform.Windows))
            {
                AllocConsole();
            }

            // PlatformHelper is part of MonoMod.
            // Environment.OSVersion.Platform is good enough as well, but Everest consistently uses PlatformHelper.
            // The following is based off of https://github.com/FNA-XNA/FNA/wiki/4:-FNA-and-Windows-API#direct3d-support
            if (PlatformHelper.Is(MonoMod.Utils.Platform.Windows))
            {
                bool useD3D = args.Contains("--d3d");

                try {
                    // Keep all usage of System.Management in a separate method.
                    // Member references are resolved as soon as a method is called.
                    // This means that if System.Management cannot be found due to
                    // f.e. the use of MonoKickstart, this method won't even get as
                    // far as checking the platform.
                    if (DoesGPUHaveBadOpenGLDrivers())
                    {
                        useD3D = true;
                    }
                } catch {
                    // Silently catch all exceptions: Method and type load errors,
                    // permission / access related exceptions and whatnot.
                }

                if (args.Contains("--no-d3d"))
                {
                    useD3D = false;
                }

                if (useD3D)
                {
                    Environment.SetEnvironmentVariable("FNA_OPENGL_FORCE_ES3", "1");
                    Environment.SetEnvironmentVariable("SDL_OPENGL_ES_DRIVER", "1");
                }
            }

            if (args.Contains("--nolog"))
            {
                MainInner(args);
                Everest.Shutdown();
                return;
            }

            if (File.Exists("log.txt"))
            {
                File.Delete("log.txt");
            }

            using (Stream fileStream = new FileStream("log.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite | FileShare.Delete))
                using (StreamWriter fileWriter = new StreamWriter(fileStream, Console.OutputEncoding))
                    using (LogWriter logWriter = new LogWriter {
                        STDOUT = Console.Out,
                        File = fileWriter
                    }) {
                        try {
                            Console.SetOut(logWriter);

                            MainInner(args);
                        } finally {
                            if (logWriter.STDOUT != null)
                            {
                                Console.SetOut(logWriter.STDOUT);
                                logWriter.STDOUT = null;
                            }
                        }
                    }
        }