private void LauncherOpenBtn_Click(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;
            try
            {
                var launcherPath = Assembly.GetEntryAssembly().Location;

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

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

                FirewallHelper.AddApplicationRule("celeste_launcher_outbound_tcp", launcherPath,
                                                  FirewallDirection.Outbound, FirewallProtocol.TCP);
            }
            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 MultiplayerOpenBtn_Click(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;
            try
            {
                //inbound_udp
                var rule = FirewallHelper.RuleExist("celeste_port1000_inbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_port1000_inbound_udp");
                }

                FirewallHelper.AddPortRule("celeste_port1000_inbound_udp", 1000,
                                           FirewallDirection.Inbound, FirewallProtocol.UDP);

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

                FirewallHelper.AddPortRule("celeste_port1000_outbound_udp", 1000,
                                           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 WindowsDefenderGameFilesDirctoryChange()
        {
            //Check if New Game! Files is not in Banned Folder Locations
            CheckGameFilesDirectoryPrevention();

            try
            {
                //Remove current Exclusion and Add new location for Exclusion
                using (PowerShell ps = PowerShell.Create())
                {
                    Log.Warning("WINDOWS DEFENDER: Removing OLD Game Files Directory: " + FileSettingsSave.GameInstallation);
                    ps.AddScript($"Remove-MpPreference -ExclusionPath \"{FileSettingsSave.GameInstallation}\"");
                    Log.Core("WINDOWS DEFENDER: Excluding NEW Game Files Directory: " + _newGameFilesPath);
                    ps.AddScript($"Add-MpPreference -ExclusionPath \"{_newGameFilesPath}\"");
                    var result = ps.Invoke();
                }
            }
            catch (Exception ex)
            {
                Log.Error("WINDOWS DEFENDER: " + ex.Message);
            }

            //Remove current Firewall for the Game Files
            string CurrentGameFilesExePath = Path.Combine(FileSettingsSave.GameInstallation + "\\nfsw.exe");

            if (File.Exists(CurrentGameFilesExePath) && FirewallHelper.FirewallStatus() == true)
            {
                if (FirewallHelper.RuleExist("SBRW - Game") == true)
                {
                    bool removeFirewallRule = true;
                    bool firstTimeRun       = true;

                    string nameOfGame  = "SBRW - Game";
                    string localOfGame = CurrentGameFilesExePath;

                    string groupKeyGame    = "Need for Speed: World";
                    string descriptionGame = groupKeyGame;

                    //Inbound & Outbound
                    FirewallHelper.DoesRulesExist(removeFirewallRule, firstTimeRun, nameOfGame, localOfGame, groupKeyGame, descriptionGame, FirewallProtocol.Any);
                }
            }

            FileSettingsSave.GameInstallation = _newGameFilesPath;

            //Clean Mods Files from New Dirctory (If it has .links in directory)
            var linksPath = Path.Combine(_newGameFilesPath, "\\.links");

            ModNetLinksCleanup.CleanLinks(linksPath);

            _restartRequired = true;
        }
Esempio n. 4
0
        private void Btn_Fix_LauncherRules(object sender, EventArgs e)
        {
            Enabled = false;
            try
            {
                var launcherPath = Assembly.GetEntryAssembly().Location;

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

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

                FirewallHelper.AddApplicationRule("celeste_launcher_inbound_tcp", launcherPath,
                                                  FirewallDirection.Inbound, FirewallProtocol.TCP);

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

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

            RefreshForm();

            Enabled = true;
        }
Esempio n. 5
0
        private void Btn_Fix_MPRules_Click(object sender, EventArgs e)
        {
            Enabled = false;
            try
            {
                //inbound_udp
                var rule = FirewallHelper.RuleExist("celeste_port1000_inbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_port1000_inbound_udp");
                }

                FirewallHelper.AddPortRule("celeste_port1000_inbound_udp", 1000,
                                           FirewallDirection.Inbound, FirewallProtocol.UDP);

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

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

            RefreshForm();

            Enabled = true;
        }
Esempio n. 6
0
        /*******************************/

        /* On Button/Dropdown Functions /
        *  /*******************************/

        /* Settings Save */
        private void SettingsSave_Click(object sender, EventArgs e)
        {
            //TODO null check
            FileSettingsSave.Lang = SettingsLanguage.SelectedValue.ToString();

            if (WindowsProductVersion.GetWindowsNumber() >= 10.0 && (FileSettingsSave.GameInstallation != _newGameFilesPath) && !DetectLinux.LinuxDetected())
            {
                WindowsDefenderGameFilesDirctoryChange();
            }
            else if (FileSettingsSave.GameInstallation != _newGameFilesPath)
            {
                CheckGameFilesDirectoryPrevention();

                if (!DetectLinux.LinuxDetected())
                {
                    //Remove current Firewall for the Game Files
                    string CurrentGameFilesExePath = Path.Combine(FileSettingsSave.GameInstallation + "\\nfsw.exe");

                    if (File.Exists(CurrentGameFilesExePath) && FirewallHelper.RuleExist("SBRW - Game") == true)
                    {
                        bool removeFirewallRule = true;
                        bool firstTimeRun       = true;

                        string nameOfGame  = "SBRW - Game";
                        string localOfGame = CurrentGameFilesExePath;

                        string groupKeyGame    = "Need for Speed: World";
                        string descriptionGame = groupKeyGame;

                        //Inbound & Outbound
                        FirewallHelper.DoesRulesExist(removeFirewallRule, firstTimeRun, nameOfGame, localOfGame, groupKeyGame, descriptionGame, FirewallProtocol.Any);
                    }
                }

                FileSettingsSave.GameInstallation = _newGameFilesPath;

                //Clean Mods Files from New Dirctory (If it has .links in directory)
                var linksPath = Path.Combine(_newGameFilesPath, "\\.links");
                ModNetLinksCleanup.CleanLinks(linksPath);

                _restartRequired = true;
            }

            if (FileSettingsSave.CDN != ((CDNObject)SettingsCDNPick.SelectedItem).Url)
            {
                SettingsCDNCurrentText.Text = "CHANGED CDN";
                SettingsCDNCurrent.Text     = ((CDNObject)SettingsCDNPick.SelectedItem).Url;
                FileSettingsSave.CDN        = ((CDNObject)SettingsCDNPick.SelectedItem).Url;
                _restartRequired            = true;
            }

            String disableProxy = (SettingsProxyCheckbox.Checked == true) ? "1" : "0";

            if (FileSettingsSave.Proxy != disableProxy)
            {
                FileSettingsSave.Proxy = (SettingsProxyCheckbox.Checked == true) ? "1" : "0";
                _restartRequired       = true;
            }

            String disableRPC = (SettingsDiscordRPCCheckbox.Checked == true) ? "1" : "0";

            if (FileSettingsSave.RPC != disableRPC)
            {
                FileSettingsSave.RPC = (SettingsDiscordRPCCheckbox.Checked == true) ? "1" : "0";
                _restartRequired     = true;
            }

            if (_restartRequired)
            {
                MessageBox.Show(null, "In order to see settings changes, you need to restart launcher manually.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            //Actually lets check those 2 files
            if (File.Exists(FileSettingsSave.GameInstallation + "/profwords") && File.Exists(FileSettingsSave.GameInstallation + "/profwords_dis"))
            {
                File.Delete(FileSettingsSave.GameInstallation + "/profwords_dis");
            }

            //Delete/Enable profwords filter here
            if (SettingsWordFilterCheck.Checked)
            {
                if (File.Exists(FileSettingsSave.GameInstallation + "/profwords"))
                {
                    File.Move(FileSettingsSave.GameInstallation + "/profwords", FileSettingsSave.GameInstallation + "/profwords_dis");
                }
            }
            else
            {
                if (File.Exists(FileSettingsSave.GameInstallation + "/profwords_dis"))
                {
                    File.Move(FileSettingsSave.GameInstallation + "/profwords_dis", FileSettingsSave.GameInstallation + "/profwords");
                }
            }

            /* Save Settings */
            FileSettingsSave.SaveSettings();

            var userSettingsXml = new XmlDocument();

            try
            {
                if (File.Exists(_userSettings))
                {
                    try
                    {
                        userSettingsXml.Load(_userSettings);
                        var language = userSettingsXml.SelectSingleNode("Settings/UI/Language");
                        language.InnerText = SettingsLanguage.SelectedValue.ToString();
                    }
                    catch
                    {
                        File.Delete(_userSettings);

                        var setting = userSettingsXml.AppendChild(userSettingsXml.CreateElement("Settings"));
                        var ui      = setting.AppendChild(userSettingsXml.CreateElement("UI"));

                        var persistentValue = setting.AppendChild(userSettingsXml.CreateElement("PersistentValue"));
                        var chat            = persistentValue.AppendChild(userSettingsXml.CreateElement("Chat"));
                        chat.InnerXml = "<DefaultChatGroup Type=\"string\">" + Self.currentLanguage + "</DefaultChatGroup>";
                        ui.InnerXml   = "<Language Type=\"string\">" + SettingsLanguage.SelectedValue + "</Language>";

                        var directoryInfo = Directory.CreateDirectory(Path.GetDirectoryName(_userSettings));
                    }
                }
                else
                {
                    try
                    {
                        var setting = userSettingsXml.AppendChild(userSettingsXml.CreateElement("Settings"));
                        var ui      = setting.AppendChild(userSettingsXml.CreateElement("UI"));

                        var persistentValue = setting.AppendChild(userSettingsXml.CreateElement("PersistentValue"));
                        var chat            = persistentValue.AppendChild(userSettingsXml.CreateElement("Chat"));
                        chat.InnerXml = "<DefaultChatGroup Type=\"string\">" + Self.currentLanguage + "</DefaultChatGroup>";
                        ui.InnerXml   = "<Language Type=\"string\">" + SettingsLanguage.SelectedValue + "</Language>";

                        var directoryInfo = Directory.CreateDirectory(Path.GetDirectoryName(_userSettings));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(null, "There was an error saving your settings to actual file. Restoring default.\n" + ex.Message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        File.Delete(_userSettings);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(null, "There was an error saving your settings to actual file. Restoring default.\n" + ex.Message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                File.Delete(_userSettings);
            }

            /* Save XML Settings */
            userSettingsXml.Save(_userSettings);

            //DialogResult = DialogResult.OK;
            Close();
        }
        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;
        }
Esempio n. 8
0
        private void Btn_Fix_SpartanRules_Click(object sender, EventArgs e)
        {
            Enabled = false;
            try
            {
                var path = !string.IsNullOrWhiteSpace(Program.UserConfig?.GameFilesPath)
                    ? Program.UserConfig?.GameFilesPath
                    : GameScannnerApi.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;
        }