コード例 #1
0
ファイル: MainForm.cs プロジェクト: bdoscientist/Launcher
        private async Task <bool> StartGameAsync()
        {
            string gameExecutableFilePath = Path.Combine(this.configuration.GameDirectoryPath, "bin64", "BlackDesert64.exe");

            if (!File.Exists(gameExecutableFilePath))
            {
                MessageBox.Show($"Failed to find `BlackDesert64.exe`.\nUsed path: `{gameExecutableFilePath}`.\nPlease set the correct path to the game.",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            if (String.IsNullOrEmpty(this.UsernameTextBox.Text) || String.IsNullOrEmpty(this.PasswordTextBox.Text))
            {
                MessageBox.Show("Please enter valid credentials.",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            using (AuthenticationServiceProvider authenticationServiceProvider = new AuthenticationServiceProvider())
            {
                string playToken = await authenticationServiceProvider.AuthenticateAsync(this.UsernameTextBox.Text, this.PasswordTextBox.Text);

                if (playToken == null)
                {
                    MessageBox.Show("Your username/password is not correct.\n(Or there might be an authentication problem.)",
                                    "Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);

                    return(false);
                }

                using (Process process = new Process())
                {
                    process.StartInfo.FileName         = gameExecutableFilePath;
                    process.StartInfo.Arguments        = playToken;
                    process.StartInfo.WorkingDirectory = Path.GetDirectoryName(gameExecutableFilePath);

                    process.Start();
                }
            }

            return(true);
        }
コード例 #2
0
        private async Task <bool> StartGameAsync()
        {
            var gameExecutableFilePath = Path.Combine(_configuration.GameDirectoryPath, "BlackDesertEAC.exe");

            if (!File.Exists(gameExecutableFilePath))
            {
                MessageBox.Show($"Failed to find `BlackDesertEAC.exe`.\nUsed path: `{gameExecutableFilePath}`.\nPlease set the correct path to the game.",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            if (string.IsNullOrEmpty(UsernameTextBox.Text) || string.IsNullOrEmpty(PasswordTextBox.Text))
            {
                MessageBox.Show("Please enter the valid credential(s).",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            var authenticationServiceProvider = new AuthenticationServiceProvider();
            var otp = 0;

            if (OtpCheckBox.Checked)
            {
                // Skip if not using master OTP
                if (!string.IsNullOrEmpty(OtpTextBox.Text))
                {
                    _otp.Password = Base32Converter.ToBytes(OtpTextBox.Text);
                }

                otp = _otp.OneTimePassword;
            }

            var playToken = await authenticationServiceProvider.AuthenticateAsync(
                UsernameTextBox.Text,
                PasswordTextBox.Text,
                RegionComboBox.SelectedItem.ToString(),
                otp);

            if (!playToken.StartsWith("0x"))
            {
                MessageBox.Show($"{playToken}",
                                "Authentication Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return(false);
            }

            if (!GameMode32BitCheckBox.Checked)
            {
                playToken += " -eac_launcher_settings Settings64.json";
            }

            using (var process = new Process())
            {
                process.StartInfo.FileName               = "CMD";
                process.StartInfo.Arguments              = "/min /C set __COMPAT_LAYER=RUNASINVOKER && start \"\" \"" + gameExecutableFilePath + "\" " + playToken;
                process.StartInfo.UseShellExecute        = true;
                process.StartInfo.RedirectStandardOutput = false;
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.WorkingDirectory       = Path.GetDirectoryName(gameExecutableFilePath);
                process.Start();

                // The following will start the game normally
                //process.StartInfo.FileName = gameExecutableFilePath;
                //process.StartInfo.Arguments = playToken;
                //process.StartInfo.WorkingDirectory = Path.GetDirectoryName(gameExecutableFilePath);
                //process.Start();
            }

            return(true);
        }