示例#1
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 || DownloadFileUtils.IsConnectedToInternet())
            {
                try
                {
                    var gameFilePath = !string.IsNullOrWhiteSpace(Program.UserConfig.GameFilesPath)
                        ? Program.UserConfig.GameFilesPath
                        : GameScannnerApi.GetGameFilesRootPath();

                    var gameScannner = new GameScannnerApi(gameFilePath, Program.UserConfig.IsSteamVersion);

retry:
                    if (!await gameScannner.QuickScan())
                    {
                        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);
                        }
                    }
示例#2
0
        private async void MainForm_Load(object sender, EventArgs e)
        {
            //CleanUpFiles
            try
            {
                Misc.CleanUpFiles(Directory.GetCurrentDirectory(), "*.old");
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage(
                    $"Warning: Error during files clean-up. Error message: {ex.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (!DownloadFileUtils.IsConnectedToInternet())
            {
                return;
            }

            //Update Check
            try
            {
                if (await UpdaterForm.GetGitHubVersion() > Assembly.GetExecutingAssembly().GetName().Version)
                {
                    using (var form =
                               new MsgBoxYesNo(
                                   @"An update is avalaible. Click ""Yes"" to install it, or ""No"" to ignore it (not recommended).")
                           )
                    {
                        var dr = form.ShowDialog();
                        if (dr == DialogResult.OK)
                        {
                            using (var form2 = new UpdaterForm())
                            {
                                form2.ShowDialog();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage(
                    $"Warning: Error during update check. Error message: {ex.Message}",
                    @"Celeste Fan Project",
                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            //Auto Login
            if (Program.UserConfig?.LoginInfo == null)
            {
                return;
            }

            if (!Program.UserConfig.LoginInfo.AutoLogin)
            {
                return;
            }

            panelManager1.Enabled = false;
            try
            {
                var response = await Program.WebSocketApi.DoLogin(Program.UserConfig.LoginInfo.Email,
                                                                  Program.UserConfig.LoginInfo.Password);

                if (response.Result)
                {
                    Program.CurrentUser = response.User;

                    gamerCard1.UserName = Program.CurrentUser.ProfileName;
                    gamerCard1.Rank     = $@"{Program.CurrentUser.Rank}";

                    panelManager1.SelectedPanel = managedPanel1;
                }
            }
            catch (Exception)
            {
                //
            }
            panelManager1.Enabled = true;
        }
        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;
        }
        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);
            }
        }
示例#5
0
        private async void RefreshBtn_Click(object sender, EventArgs e)
        {
            listView1.Enabled  = false;
            customBtn1.Enabled = false;

            try
            {
                var response = await Program.WebSocketApi.DoGetFriends();

                if (!response.Result)
                {
                    throw new Exception(response.Message);
                }

                var friends = response.Friends.Friends;

                //
                listView1.Items.Clear();
                listView1.Items.AddRange(friends.Where(friend => friend.IsConnected).Select(friend =>
                {
                    var ret = new ListViewItem(friend.ProfileName)
                    {
                        Group = friend.IsConnected ? listView1.Groups[0] : listView1.Groups[1],
                        Tag   = friend
                    };
                    if (string.IsNullOrWhiteSpace(friend.RichPresence))
                    {
                        return(ret);
                    }

                    foreach (var str in friend.RichPresence.Split(
                                 new[] { "\r\n", "\r", "\n" },
                                 StringSplitOptions.RemoveEmptyEntries
                                 ))
                    {
                        ret.SubItems.Add(str);
                    }
                    return(ret);
                }
                                                                                            ).ToArray());
                listView1.Groups[0].Header = $@"Online ({listView1.Groups[0].Items.Count} / {friends.Length})";
                listView1.Groups[1].Header = $@"Offline ({listView1.Groups[1].Items.Count} / {friends.Length})";

                //
                listView3.Items.Clear();
                listView3.Items.AddRange(friends.Where(friend => !friend.IsConnected).Select(friend =>
                {
                    var ret = new ListViewItem(friend.ProfileName)
                    {
                        Group = friend.IsConnected ? listView3.Groups[0] : listView3.Groups[1],
                        Tag   = friend
                    };
                    if (string.IsNullOrWhiteSpace(friend.RichPresence))
                    {
                        return(ret);
                    }

                    foreach (var str in friend.RichPresence.Split(
                                 new[] { "\r\n", "\r", "\n" },
                                 StringSplitOptions.RemoveEmptyEntries
                                 ))
                    {
                        ret.SubItems.Add(str);
                    }
                    return(ret);
                }
                                                                                             ).ToArray());
                listView3.Groups[0].Header = $@"Online ({listView1.Groups[0].Items.Count} / {friends.Length})";
                listView3.Groups[1].Header = $@"Offline ({listView1.Groups[1].Items.Count} / {friends.Length})";
            }
            catch (Exception ex)
            {
                MsgBox.ShowMessage($@"Error: {ex.Message}", @"Celeste Fan Project",
                                   MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            listView1.Enabled  = true;
            customBtn1.Enabled = true;
        }