public GameScanProgressForm(string gameFilesPath, bool isSteam = false, int concurrentDownload = 0)
        {
            InitializeComponent();

            if (string.IsNullOrWhiteSpace(gameFilesPath))
            {
                throw new Exception(@"Game files path is empty!");
            }

            SkinHelperFonts.SetFont(Controls);

            if (!Directory.Exists(gameFilesPath))
            {
                Directory.CreateDirectory(gameFilesPath);
            }

            _concurrentDownload     = concurrentDownload;
            _gameScanner            = new GameScannerManager(gameFilesPath, isSteam);
            lbl_ProgressTitle.Text  = string.Empty;
            lbl_ProgressDetail.Text = string.Empty;
            lbl_GlobalProgress.Text = string.Empty;
            label1.Text             = string.Empty;
            pB_GlobalProgress.Value = 0;
            pB_SubProgress.Value    = 0;
        }
        public GameScannerWindow(string gameFilesPath, bool isSteam, bool useParallelDownloader)
        {
            InitializeComponent();

            if (!Directory.Exists(gameFilesPath))
            {
                Directory.CreateDirectory(gameFilesPath);
            }

            GameScanner            = new GameScannerManager(gameFilesPath, isSteam);
            _useParallelDownloader = useParallelDownloader;
        }
Esempio n. 3
0
        static async Task <int> Main(string[] args)
        {
            var rootCommand = new RootCommand
            {
                new Option <string>(
                    "--game-dir",
                    description: "Path to the directory where Spartan.exe is located")
                {
                    IsRequired = true
                },
                new Option <bool>(
                    "--is-steam",
                    description: "Enabled for installations that are launchable through Steam"),
                new Option <bool>(
                    "--verbose-mode",
                    getDefaultValue: () => false,
                    description: "Write more detailed log about progress"),
            };

            rootCommand.Handler = CommandHandler.Create <string, bool, bool>(async(gameDir, isSteam, verboseMode) =>
            {
                Console.WriteLine($"Starting game scan towards {gameDir}");

                var gameScannner = new GameScannerManager(gameDir, isSteam);

                Console.WriteLine("Fetching manifest data");
                await gameScannner.InitializeFromCelesteManifest();

                Console.WriteLine("Scanning game files");
                var progress    = new Progress <ScanProgress>();
                var subProgress = new Progress <ScanSubProgress>();

                if (verboseMode)
                {
                    subProgress.ProgressChanged += SubProgress_ProgressChanged;
                    progress.ProgressChanged    += Progress_ProgressChanged;
                }

                if (!await gameScannner.ScanAndRepair(progress, subProgress))
                {
                    Console.WriteLine("Scan completed: No game files were updated, everything up to date");
                    return(0);
                }
                else
                {
                    Console.WriteLine("Gamescan has completed and updated game files");
                    return(0);
                }
            });

            return(await rootCommand.InvokeAsync(args));
        }
Esempio n. 4
0
        public GameScan()
        {
            InitializeComponent();

            SkinHelperFonts.SetFont(Controls);

            if (Program.UserConfig != null && !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath))
            {
                tb_GamePath.Text = Program.UserConfig.GameFilesPath;
            }
            else
            {
                tb_GamePath.Text = GameScannerManager.GetGameFilesRootPath();
            }
        }
Esempio n. 5
0
        public GameScannerWindow()
        {
            var gameFilesPath = LegacyBootstrapper.UserConfig.GameFilesPath;
            var isSteam       = LegacyBootstrapper.UserConfig.IsSteamVersion;

            InitializeComponent();

            Logger.Information($"Initialized game scanner to directory {gameFilesPath}");

            if (!Directory.Exists(gameFilesPath))
            {
                Directory.CreateDirectory(gameFilesPath);
            }

            GameScanner = new GameScannerManager(gameFilesPath, isSteam);
        }
        private async void GameScanProgressForm_Shown(object sender, EventArgs e)
        {
            var progress = new Progress <ScanProgress>();

            progress.ProgressChanged += ProgressChanged;
            var subProgress = new Progress <ScanSubProgress>();

            subProgress.ProgressChanged += SubProgressChanged;
            try
            {
                await _gameScanner.InitializeFromCelesteManifest();

                if (await _gameScanner.ScanAndRepair(progress, subProgress, _concurrentDownload))
                {
                    MsgBox.ShowMessage(@"Game scan completed with success.",
                                       @"Celeste Fan Project",
                                       MessageBoxButtons.OK, MessageBoxIcon.Information);

                    DialogResult = DialogResult.OK;
                }
                else
                {
                    throw new Exception("Game scan failed");
                }
            }
            catch (Exception ex)
            {
                _gameScanner?.Abort();
                _gameScanner?.Dispose();
                _gameScanner = null;

                MsgBox.ShowMessage("Exception:\r\n" + ex.Message,
                                   @"Celeste Fan Project",
                                   MessageBoxButtons.OK, MessageBoxIcon.Error);

                DialogResult = DialogResult.Cancel;
            }
        }
Esempio n. 7
0
        public static async void StartGame(bool isOffline = false)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                MsgBox.ShowMessage(@"Game already running!");
                return;
            }

            //QuickGameScan
            if (!isOffline || InternetUtils.IsConnectedToInternet())
            {
                try
                {
                    var gameFilePath = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath)
                        ? Program.UserConfig.GameFilesPath
                        : GameScannerManager.GetGameFilesRootPath();

                    using (var gameScannner = new GameScannerManager(gameFilePath, Program.UserConfig.IsSteamVersion))
                    {
                        await gameScannner.InitializeFromCelesteManifest();

retry:
                        if (!await gameScannner.Scan(true))
                        {
                            bool success;
                            using (var form =
                                       new MsgBoxYesNo(
                                           @"Error: Your game files are corrupted or outdated. Click ""Yes"" to run a ""Game Scan"" to fix your game files, or ""No"" to ignore the error (not recommended).")
                                   )
                            {
                                var dr = form.ShowDialog();
                                if (dr == DialogResult.OK)
                                {
                                    using (var form2 = new GameScan())
                                    {
                                        form2.ShowDialog();
                                        success = false;
                                    }
                                }
                                else
                                {
                                    success = true;
                                }
                            }
                            if (!success)
                            {
                                goto retry;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MsgBox.ShowMessage(
                        $"Warning: Error during quick scan. Error message: {ex.Message}",
                        @"Celeste Fan Project",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            //isSteam
            if (!Program.UserConfig.IsSteamVersion)
            {
                var steamApiDll = Path.Combine(Program.UserConfig.GameFilesPath, "steam_api.dll");
                if (File.Exists(steamApiDll))
                {
                    File.Delete(steamApiDll);
                }
            }

            //MpSettings
            if (!isOffline && Program.UserConfig.MpSettings != null)
            {
                if (Program.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    Program.UserConfig.MpSettings.PublicIp = Program.CurrentUser.Ip;

                    if (Program.UserConfig.MpSettings.PortMappingType == PortMappingType.Upnp)
                    {
                        try
                        {
                            await OpenNat.MapPortTask(1000, 1000);
                        }
                        catch (Exception)
                        {
                            Program.UserConfig.MpSettings.PortMappingType = PortMappingType.NatPunch;

                            MsgBox.ShowMessage(
                                "Error: Upnp device not found! \"UPnP Port Mapping\" has been disabled.",
                                @"Celeste Fan Project",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
Esempio n. 8
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var mutex = new Mutex(true, AppName, out bool createdNew);

            //Only one instance
            if (!createdNew)
            {
                MsgBox.ShowMessage(
                    $@"""Celeste Fan Project Launcher"" v{
                            Assembly.GetEntryAssembly()?.GetName().Version
                        } already running!", "Celeste Fan Project",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }

            //
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            //Load UserConfig
            try
            {
                if (File.Exists(UserConfigFilePath))
                {
                    UserConfig = UserConfig.Load(UserConfigFilePath);
                }
            }
            catch (Exception)
            {
                //
            }

            try
            {
                if (string.IsNullOrWhiteSpace(UserConfig.GameFilesPath))
                {
                    UserConfig.GameFilesPath = GameScannerManager.GetGameFilesRootPath();
                }
            }
            catch (Exception)
            {
                //
            }

            //Check if Steam Version
            try
            {
                UserConfig.IsSteamVersion = Assembly.GetEntryAssembly()?.Location
                                            .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase) ?? false;
            }
            catch (Exception)
            {
                //
            }

            //SslFix (invalid cert)
            InternetUtils.SslFix();

            //Init WebSocketApi
            WebSocketApi = new WebSocketApi(UserConfig.ServerUri);

            //Start Gui
            Application.Run(new MainForm());

            GC.KeepAlive(mutex);
        }
Esempio n. 9
0
        public static async Task StartGame(bool isOffline = false)
        {
            Logger.Information("Preparing to start game, is offline: {@isOffline}", isOffline);

            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                Logger.Information("Game is already started with PID {@PID}", pname.Select(t => t.Id));
                GenericMessageDialog.Show(Properties.Resources.GameAlreadyRunningError, DialogIcon.Warning);
                return;
            }

            //QuickGameScan
            if (!isOffline || InternetUtils.IsConnectedToInternet())
            {
                Logger.Information("User is online, will perform game scan");
                try
                {
                    var success = false;

                    while (!success)
                    {
                        Logger.Information("Starting quick game scan");
                        var gameFilePath = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig.GameFilesPath)
                            ? LegacyBootstrapper.UserConfig.GameFilesPath
                            : GameScannerManager.GetGameFilesRootPath();

                        Logger.Information("Preparing games canner api");

                        var gameScannner = new GameScannerManager(gameFilePath, LegacyBootstrapper.UserConfig.IsSteamVersion);
                        await gameScannner.InitializeFromCelesteManifest();

                        if (!await gameScannner.Scan(true))
                        {
                            Logger.Information("Game scanner did not approve game files");

                            var dialogResult = GenericMessageDialog.Show(
                                Properties.Resources.GameScannerDidNotPassQuickScan,
                                DialogIcon.None,
                                DialogOptions.YesNo);

                            if (dialogResult.Value)
                            {
                                var gamePathSelectionWindow = new GamePathSelectionWindow();
                                gamePathSelectionWindow.ShowDialog();
                            }
                            else
                            {
                                success = true;
                            }
                        }
                        else
                        {
                            Logger.Information("Game files passed file scanner");
                            success = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, ex.Message);
                    GenericMessageDialog.Show(Properties.Resources.GameScannerScanError, DialogIcon.Warning);
                }
            }

            //isSteam
            if (!LegacyBootstrapper.UserConfig.IsSteamVersion)
            {
                var steamApiDll = Path.Combine(LegacyBootstrapper.UserConfig.GameFilesPath, "steam_api.dll");
                if (File.Exists(steamApiDll))
                {
                    File.Delete(steamApiDll);
                }
            }

            //MpSettings
            if (!isOffline && LegacyBootstrapper.UserConfig.MpSettings != null)
            {
                if (LegacyBootstrapper.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    LegacyBootstrapper.UserConfig.MpSettings.PublicIp = LegacyBootstrapper.CurrentUser.Ip;

                    if (LegacyBootstrapper.UserConfig.MpSettings.PortMappingType == PortMappingType.Upnp)
                    {
                        try
                        {
                            await OpenNat.MapPortTask(1000, 1000);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex, ex.Message);
                            LegacyBootstrapper.UserConfig.MpSettings.PortMappingType = PortMappingType.NatPunch;

                            GenericMessageDialog.Show(Properties.Resources.UPnPDisabledError, DialogIcon.Error);
                        }
                        finally
                        {
                            NatDiscoverer.TraceSource.Close();
                        }
                    }
                }
            }

            try
            {
                //Launch Game
                var gamePath = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig.GameFilesPath)
                    ? LegacyBootstrapper.UserConfig.GameFilesPath
                    : GameScannerManager.GetGameFilesRootPath();

                var spartanPath = Path.Combine(gamePath, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    GenericMessageDialog.Show(Properties.Resources.GameScannerSpartanNotFound, DialogIcon.Error);
                    return;
                }

                string lang;
                switch (LegacyBootstrapper.UserConfig.GameLanguage)
                {
                case GameLanguage.deDE:
                    lang = "de-DE";
                    break;

                case GameLanguage.enUS:
                    lang = "en-US";
                    break;

                case GameLanguage.esES:
                    lang = "es-ES";
                    break;

                case GameLanguage.frFR:
                    lang = "fr-FR";
                    break;

                case GameLanguage.itIT:
                    lang = "it-IT";
                    break;

                case GameLanguage.zhCHT:
                    lang = "zh-CHT";
                    break;

                case GameLanguage.ptBR:
                    lang = "pt-BR";
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(LegacyBootstrapper.UserConfig.GameLanguage),
                                                          LegacyBootstrapper.UserConfig.GameLanguage, null);
                }

                try
                {
                    if (LegacyBootstrapper.UserConfig.IsDiagnosticMode)
                    {
                        Logger.Information("Diagnostics mode is enabled");
                        //
                        try
                        {
                            var killInfo = new ProcessStartInfo("cmd.exe", "/c taskkill /F /IM procdump.exe /T")
                            {
                                WorkingDirectory       = gamePath,
                                CreateNoWindow         = true,
                                UseShellExecute        = false,
                                RedirectStandardError  = true,
                                RedirectStandardOutput = true
                            };

                            Logger.Information("Starting prcoess {@Proc} with args {@Procargs}", killInfo.FileName, killInfo.Arguments);
                            Process.Start(killInfo);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex, ex.Message);
                        }

                        var       procdumpFileName   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "procdump.exe");
                        const int maxNumOfCrashDumps = 30;
                        if (!File.Exists(procdumpFileName))
                        {
                            Logger.Information("Could not find procdump.exe");
                            LegacyBootstrapper.UserConfig.IsDiagnosticMode = false;
                            throw new FileNotFoundException(
                                      Properties.Resources.DiagnosticsModeMissingProcdump,
                                      procdumpFileName);
                        }

                        // First ensure that all directories are set
                        var pathToCrashDumpFolder =
                            Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                         @"Spartan\MiniDumps");

                        Logger.Information("CrashDumpFolder is set to {@CrashDumpFolder}", pathToCrashDumpFolder);

                        if (!Directory.Exists(pathToCrashDumpFolder))
                        {
                            Directory.CreateDirectory(pathToCrashDumpFolder);
                        }

                        // Check for cleanup
                        Directory.GetFiles(pathToCrashDumpFolder)
                        .OrderByDescending(File.GetLastWriteTime) // Sort by age --> old one last
                        .Skip(maxNumOfCrashDumps)                 // Skip max num crash dumps
                        .ToList()
                        .ForEach(File.Delete);                    // Remove the rest

                        var excludeExceptions = new[]
                        {
                            "E0434F4D.COM", // .NET native exception
                            "E06D7363.msc",
                            "E06D7363.PAVEEFileLoadException@@",
                            "E0434F4D.System.IO.FileNotFoundException" // .NET managed exception
                        };

                        var excludeExcpetionsCmd = string.Join(" ", excludeExceptions.Select(elem => "-fx " + elem));

                        var fullCmdArgs = "-accepteula -mm -e 1 -n 10 " + excludeExcpetionsCmd +
                                          " -g -w Spartan.exe \"" + pathToCrashDumpFolder + "\"";

                        var startInfo = new ProcessStartInfo(procdumpFileName, fullCmdArgs)
                        {
                            WorkingDirectory       = gamePath,
                            CreateNoWindow         = true,
                            UseShellExecute        = false,
                            RedirectStandardError  = true,
                            RedirectStandardOutput = true
                        };

                        Logger.Information("Starting prcoess {@Proc} with args {@Procargs}", startInfo.FileName, startInfo.Arguments);

                        Process.Start(startInfo);
                    }
                }
                catch (Exception exception)
                {
                    Logger.Error(exception, exception.Message);
                    GenericMessageDialog.Show(Properties.Resources.DiagnosticsModeError, DialogIcon.Warning);
                }

                //SymLink CustomScn Folder
                var profileDir        = Path.Combine(Environment.GetEnvironmentVariable("userprofile"));
                var customScnGamePath = Path.Combine(gamePath, "Scenario", "CustomScn");
                var scenarioUserPath  = Path.Combine(profileDir, "Documents", "Spartan", "Scenario");

                Logger.Information("CustomScn directory: {@customScnPath}", customScnGamePath);
                Logger.Information("Scenario directory: {@scenarioPath}", scenarioUserPath);

                if (!Directory.Exists(scenarioUserPath))
                {
                    Directory.CreateDirectory(scenarioUserPath);
                }

                if (Directory.Exists(customScnGamePath) &&
                    (!Misc.IsSymLink(customScnGamePath, Misc.SymLinkFlag.Directory) ||
                     !string.Equals(Misc.GetRealPath(customScnGamePath), scenarioUserPath, StringComparison.OrdinalIgnoreCase)))
                {
                    Directory.Delete(customScnGamePath, true);
                    Misc.CreateSymbolicLink(customScnGamePath, scenarioUserPath, Misc.SymLinkFlag.Directory);
                }
                else
                {
                    Misc.CreateSymbolicLink(customScnGamePath, scenarioUserPath, Misc.SymLinkFlag.Directory);
                }

                string arg;
                if (isOffline)
                {
                    arg = $"--offline --ignore_rest LauncherLang={lang} LauncherLocale=1033";
                }
                else if (LegacyBootstrapper.UserConfig?.MpSettings == null ||
                         LegacyBootstrapper.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    arg = LegacyBootstrapper.UserConfig.MpSettings.PortMappingType == PortMappingType.NatPunch
                        ? $"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033"
                        : $"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --no-nat-punchthrough --ignore_rest LauncherLang={lang} LauncherLocale=1033";
                }
                else
                {
                    arg =
                        $"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --online-ip \"{LegacyBootstrapper.UserConfig.MpSettings.PublicIp}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033";
                }

                Logger.Information("Starting game {@GameExecutable} at {@GamePath}", spartanPath, gamePath);
                Process.Start(new ProcessStartInfo(spartanPath, arg)
                {
                    WorkingDirectory = gamePath
                });
            }
            catch (Exception exception)
            {
                Logger.Error(exception, exception.Message);
                GenericMessageDialog.Show(Properties.Resources.StartGameError, DialogIcon.Error);
            }
        }
 private void GameScan_FormClosing(object sender, FormClosingEventArgs e)
 {
     _gameScanner?.Dispose();
     _gameScanner = null;
 }
        public static void InitializeLegacyComponents()
        {
            Logger.Information("Initializing bootstrapper");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // TODO: Move this to app.xaml.cs
            var mutex = new Mutex(true, AppName, out bool createdNew);

            //Only one instance
            if (!createdNew)
            {
                Logger.Information("Launcher is already started, will exit");
                GenericMessageDialog.Show(Properties.Resources.LauncherAlreadyRunningMessage, DialogIcon.Warning, DialogOptions.Ok);
                return;
            }

            //
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            //Load UserConfig
            try
            {
                if (File.Exists(UserConfigFilePath))
                {
                    UserConfig = UserConfig.Load(UserConfigFilePath);
                    Logger.Information("User config loaded from {@Path}", UserConfigFilePath);
                }
                else
                {
                    Logger.Information("No user config loaded, path {@Path} does not exist", UserConfigFilePath);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            try
            {
                if (string.IsNullOrWhiteSpace(UserConfig.GameFilesPath))
                {
                    UserConfig.GameFilesPath = GameScannerManager.GetGameFilesRootPath();
                    Logger.Information("Game path set to {@Path}", UserConfigFilePath);
                }
                else
                {
                    Logger.Information("No game path is set");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Check if Steam Version
            try
            {
                UserConfig.IsSteamVersion = Assembly.GetEntryAssembly().Location
                                            .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase);

                Logger.Information("IsSteamVersion: {@IsSteamVersion}", UserConfig.IsSteamVersion);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Init WebSocketApi
            WebSocketApi = new WebSocketApi(UserConfig.ServerUri);
            Logger.Information("Initialized web socket");

            GC.KeepAlive(mutex);

            Logger.Information("Initializing fingerprint provider");
            FingerPrintProvider.Initialize();

            SetUILanguage();

            Logger.Information("Bootstrapper initialized");
        }
        public static void InitializeLegacyComponents()
        {
            if (!FileSystem.IsWritableDirectory(AppDomain.CurrentDomain.BaseDirectory))
            {
                MessageBox.Show(string.Format(Properties.Resources.InstallationPathForbidden, AppDomain.CurrentDomain.BaseDirectory), "Celeste Launcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                System.Windows.Application.Current.Shutdown();
                return;
            }

            Logger.Information("Initializing bootstrapper");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // TODO: Move this to app.xaml.cs
            var mutex = new Mutex(true, AppName, out bool createdNew);

            //Only one instance
            if (!createdNew)
            {
                Logger.Information("Launcher is already started, will exit");
                GenericMessageDialog.Show(Properties.Resources.LauncherAlreadyRunningMessage, DialogIcon.Warning, DialogOptions.Ok);
                return;
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            LoadUserConfig();

            try
            {
                if (string.IsNullOrWhiteSpace(UserConfig.GameFilesPath))
                {
                    UserConfig.GameFilesPath = GameScannerManager.GetGameFilesRootPath();
                    Logger.Information("Game path set to {@Path}", UserConfigFilePath);
                }
                else
                {
                    Logger.Information("No game path is set");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Check if Steam Version
            try
            {
                var isSteamVersion = Assembly.GetEntryAssembly().Location
                                     .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase);

                if (UserConfig.IsSteamVersion != isSteamVersion)
                {
                    UserConfig.IsSteamVersion = isSteamVersion;
                    UserConfig.Save(UserConfigFilePath);
                }

                Logger.Information("IsSteamVersion: {@IsSteamVersion}", UserConfig.IsSteamVersion);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Init WebSocketApi
            WebSocketApi = new WebSocketApi(UserConfig.ServerUri);
            Logger.Information("Initialized web socket");

            GC.KeepAlive(mutex);

            Logger.Information("Initializing fingerprint provider");
            FingerPrintProvider.Initialize();

            SetUILanguage();

            Logger.Information("Bootstrapper initialized");
        }
        private void SpartanOpenBtn_Click(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;
            try
            {
                var path = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig?.GameFilesPath)
                    ? LegacyBootstrapper.UserConfig?.GameFilesPath
                    : GameScannerManager.GetGameFilesRootPath();

                var spartanPath = Path.Combine(path, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperSpartanNotFound, DialogIcon.Error, DialogOptions.Ok);
                    Close();
                    return;
                }

                //inbound_tcp
                var rule = FirewallHelper.RuleExist("celeste_spartan_inbound_tcp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_inbound_tcp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_inbound_tcp", spartanPath,
                                                  FirewallDirection.Inbound, FirewallProtocol.TCP);

                //outbound_tcp
                rule = FirewallHelper.RuleExist("celeste_spartan_outbound_tcp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_outbound_tcp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_outbound_tcp", spartanPath,
                                                  FirewallDirection.Outbound, FirewallProtocol.TCP);

                //inbound_udp
                rule = FirewallHelper.RuleExist("celeste_spartan_inbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_inbound_udp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_inbound_udp", spartanPath,
                                                  FirewallDirection.Inbound, FirewallProtocol.UDP);

                //outbound_udp
                rule = FirewallHelper.RuleExist("celeste_spartan_outbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_outbound_udp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_outbound_udp", spartanPath,
                                                  FirewallDirection.Outbound, FirewallProtocol.UDP);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error, DialogOptions.Ok);
            }

            LoadFirewallRules();

            IsEnabled = true;
        }
        private void LoadFirewallRules()
        {
            try
            {
                //Launcher
                var launcherPath = Assembly.GetEntryAssembly().Location;

                if (!File.Exists(launcherPath))
                {
                    GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperLauncherNotFound, DialogIcon.Error, DialogOptions.Ok);
                    Close();
                    return;
                }

                var rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_launcher_outbound_tcp");
                if (rule == null)
                {
                    LauncherOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    LauncherOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.TCP || rule.ApplicationName != launcherPath ||
                        rule.LocalPortType != FirewallPortType.All || rule.Direction != FirewallDirection.Outbound)
                    {
                        LauncherOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        LauncherOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        LauncherOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        LauncherOutboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }

                var path = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig?.GameFilesPath)
                    ? LegacyBootstrapper.UserConfig?.GameFilesPath
                    : GameScannerManager.GetGameFilesRootPath();

                var spartanPath = Path.Combine(path, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperSpartanNotFound, DialogIcon.Error, DialogOptions.Ok);
                    Close();
                    return;
                }

                //Spartan
                var rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_tcp");
                var rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_udp");
                if (rule1 == null || rule2 == null)
                {
                    SpartanInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    SpartanInboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath ||
                        rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Inbound ||
                        rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath ||
                        rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Inbound)
                    {
                        SpartanInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        SpartanInboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        SpartanInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        SpartanInboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }

                rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_tcp");
                rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_udp");
                if (rule1 == null || rule2 == null)
                {
                    SpartanOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    SpartanOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath ||
                        rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Outbound ||
                        rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath ||
                        rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Outbound)
                    {
                        SpartanOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        SpartanOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        SpartanOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        SpartanOutboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }

                //Port 1000
                rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_inbound_udp");
                if (rule == null)
                {
                    MultiplayerInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    MultiplayerInboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) ||
                        rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Inbound)
                    {
                        MultiplayerInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        MultiplayerInboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        MultiplayerInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        MultiplayerInboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }

                rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_outbound_udp");
                if (rule == null)
                {
                    MultiplayerOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    MultiplayerOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) ||
                        rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Outbound)
                    {
                        MultiplayerOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        MultiplayerOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        MultiplayerOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        MultiplayerOutboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error, DialogOptions.Ok);
            }
        }
Esempio n. 15
0
        private void RefreshForm()
        {
            try
            {
                //Launcher
                var launcherPath = Assembly.GetEntryAssembly().Location;

                if (!File.Exists(launcherPath))
                {
                    throw new FileNotFoundException("Launcher not found!", launcherPath);
                }

                var rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_launcher_inbound_tcp");
                if (rule == null)
                {
                    l_State_L_In.Text      = @"Not Found";
                    l_State_L_In.ForeColor = Color.Red;
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.TCP || rule.ApplicationName != launcherPath ||
                        rule.LocalPortType != FirewallPortType.All || rule.Direction != FirewallDirection.Inbound)
                    {
                        l_State_L_In.Text      = @"Invalid";
                        l_State_L_In.ForeColor = Color.Red;
                    }
                    else
                    {
                        l_State_L_In.Text      = @"Valid";
                        l_State_L_In.ForeColor = Color.Green;
                    }
                }

                rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_launcher_outbound_tcp");
                if (rule == null)
                {
                    l_State_L_Out.Text      = @"Not Found";
                    l_State_L_Out.ForeColor = Color.Red;
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.TCP || rule.ApplicationName != launcherPath ||
                        rule.LocalPortType != FirewallPortType.All || rule.Direction != FirewallDirection.Outbound)
                    {
                        l_State_L_Out.Text      = @"Invalid";
                        l_State_L_Out.ForeColor = Color.Red;
                    }
                    else
                    {
                        l_State_L_Out.Text      = @"Valid";
                        l_State_L_Out.ForeColor = Color.Green;
                    }
                }

                var path = !string.IsNullOrWhiteSpace(Program.UserConfig?.GameFilesPath)
                    ? Program.UserConfig?.GameFilesPath
                    : GameScannerManager.GetGameFilesRootPath();

                var spartanPath = Path.Combine(path, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    throw new FileNotFoundException("Spartan.exe not found!", spartanPath);
                }

                //Spartan
                var rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_tcp");
                var rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_udp");
                if (rule1 == null || rule2 == null)
                {
                    l_State_S_In.Text      = @"Not Found";
                    l_State_S_In.ForeColor = Color.Red;
                }
                else
                {
                    if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath ||
                        rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Inbound ||
                        rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath ||
                        rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Inbound)
                    {
                        l_State_S_In.Text      = @"Invalid";
                        l_State_S_In.ForeColor = Color.Red;
                    }
                    else
                    {
                        l_State_S_In.Text      = @"Valid";
                        l_State_S_In.ForeColor = Color.Green;
                    }
                }

                rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_tcp");
                rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_udp");
                if (rule1 == null || rule2 == null)
                {
                    l_State_S_Out.Text      = @"Not Found";
                    l_State_S_Out.ForeColor = Color.Red;
                }
                else
                {
                    if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath ||
                        rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Outbound ||
                        rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath ||
                        rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Outbound)
                    {
                        l_State_S_Out.Text      = @"Invalid";
                        l_State_S_Out.ForeColor = Color.Red;
                    }
                    else
                    {
                        l_State_S_Out.Text      = @"Valid";
                        l_State_S_Out.ForeColor = Color.Green;
                    }
                }

                //Port 1000
                rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_inbound_udp");
                if (rule == null)
                {
                    l_State_MP_In.Text      = @"Not Found";
                    l_State_MP_In.ForeColor = Color.Red;
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) ||
                        rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Inbound)
                    {
                        l_State_MP_In.Text      = @"Invalid";
                        l_State_MP_In.ForeColor = Color.Red;
                    }
                    else
                    {
                        l_State_MP_In.Text      = @"Valid";
                        l_State_MP_In.ForeColor = Color.Green;
                    }
                }

                rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_outbound_udp");
                if (rule == null)
                {
                    l_State_MP_Out.Text      = @"Not Found";
                    l_State_MP_Out.ForeColor = Color.Red;
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) ||
                        rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Outbound)
                    {
                        l_State_MP_Out.Text      = @"Invalid";
                        l_State_MP_Out.ForeColor = Color.Red;
                    }
                    else
                    {
                        l_State_MP_Out.Text      = @"Valid";
                        l_State_MP_Out.ForeColor = Color.Green;
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage(
                    $"Error: {ex.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 16
0
        private void Btn_Fix_SpartanRules_Click(object sender, EventArgs e)
        {
            Enabled = false;
            try
            {
                var path = !string.IsNullOrWhiteSpace(Program.UserConfig?.GameFilesPath)
                    ? Program.UserConfig?.GameFilesPath
                    : GameScannerManager.GetGameFilesRootPath();

                var spartanPath = Path.Combine(path, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    throw new FileNotFoundException("Spartan.exe not found!", spartanPath);
                }

                //inbound_tcp
                var rule = FirewallHelper.RuleExist("celeste_spartan_inbound_tcp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_inbound_tcp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_inbound_tcp", spartanPath,
                                                  FirewallDirection.Inbound, FirewallProtocol.TCP);

                //outbound_tcp
                rule = FirewallHelper.RuleExist("celeste_spartan_outbound_tcp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_outbound_tcp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_outbound_tcp", spartanPath,
                                                  FirewallDirection.Outbound, FirewallProtocol.TCP);

                //inbound_udp
                rule = FirewallHelper.RuleExist("celeste_spartan_inbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_inbound_udp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_inbound_udp", spartanPath,
                                                  FirewallDirection.Inbound, FirewallProtocol.UDP);

                //outbound_udp
                rule = FirewallHelper.RuleExist("celeste_spartan_outbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_outbound_udp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_outbound_udp", spartanPath,
                                                  FirewallDirection.Outbound, FirewallProtocol.UDP);
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage(
                    $"Error: {ex.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            RefreshForm();

            Enabled = true;
        }