예제 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Loading.Visibility = Visibility.Visible;
            Button button = (Button)sender;

            PasswordBox.IsEnabled = NameTextBox.IsEnabled = ComboBox.IsEnabled = button.IsEnabled = false;
            if (ComboBox.SelectedIndex == 0)
            {
                try
                {
                    Task.Run(() =>
                    {
                        string email = null; string password = null;
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            email    = NameTextBox.Text;
                            password = PasswordBox.Password;
                        }));
                        YggdrasilAuthenticator yggdrasilAuthenticator = new YggdrasilAuthenticator(email, password);
                        yggdrasilAuthenticator.Authenticate();
                        if (yggdrasilAuthenticator.GetUserType() == "Mojang")
                        {
                            this.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                JObject jObject = yggdrasilAuthenticator.GetResult();
                                Json.AddUsers((string)jObject["selectedProfile"]["name"], (string)jObject["selectedProfile"]["id"], (string)jObject["accessToken"], "正版", email);
                                Json.Write("Login", "Choose", (string)jObject["selectedProfile"]["id"]);
                                Loading.Visibility = Visibility.Collapsed;
                                this.Close();
                                MainWindow.ShowTip("恭喜你找到彩蛋!\r\n彩蛋码已复制到剪切板", 2);
                                Clipboard.SetDataObject("Mojang Studio 跑路了~");
                            }));
                        }
                        else
                        {
                            this.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                MainWindow.ShowTip("登陆失败,请检查密码.[或多次重复被服务器禁止登录]", 3);
                            }));
                        }
                        this.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            PasswordBox.IsEnabled = NameTextBox.IsEnabled = ComboBox.IsEnabled = button.IsEnabled = true;
                            Loading.Visibility    = Visibility.Collapsed;
                        }));
                    });
                }
                catch { }
            }
            else
            {
                OfflineAuthenticator offlineAuthenticator = new OfflineAuthenticator(NameTextBox.Text);
                offlineAuthenticator.Authenticate();
                JObject jObject = offlineAuthenticator.GetResult();
                Json.AddUsers((string)jObject["selectedProfile"]["name"], (string)jObject["selectedProfile"]["id"], (string)jObject["accessToken"], "离线", "");
                Json.Write("Login", "Choose", (string)jObject["selectedProfile"]["id"]);
                Loading.Visibility = Visibility.Collapsed;
                this.Close();
            }
        }
예제 #2
0
 static void LaunchGame(Version launchVer)
 {
     Console.WriteLine("Ready to launch version {0}", launchVer.ID);
     OfflineAuthenticator authenticator = new OfflineAuthenticator("Nsiso");
     var launchResult = handler.LaunchAsync(new LaunchSetting()
     {
         Version            = launchVer,
         AuthenticateResult = authenticator.DoAuthenticate()
     }).Result;
 }
예제 #3
0
        static void OfflineAuthenticatorTest()
        {
            Console.Write("Input Name:");
            OfflineAuthenticator auth = new OfflineAuthenticator(Console.ReadLine());

            Console.WriteLine("Name:" + auth.Auth().Profile.Name);
            Console.WriteLine("Id:" + auth.Auth().Profile.Id.ToString("N"));
            Console.WriteLine("AccessToken:" + auth.Auth().AccessToken.ToString("N"));
            Console.WriteLine("Properties:");
            foreach (KeyValuePair <string, string> property in auth.Auth().Properties)
            {
                Console.WriteLine("    " + property.Key + ":" + property.Value);
            }
            Console.WriteLine("Type:" + auth.Auth().Type);
        }
예제 #4
0
        static async Task Main(string[] args)
        {
            OfflineAuthenticator mojangAuthenticator = new OfflineAuthenticator
            {
                Account = "*****@*****.**",
            };
            AuthResult authResult = mojangAuthenticator.Auth();

            Console.WriteLine(authResult.PlayerName);
            Global.AuthConfiguation   = authResult;
            Global.LaunchConfiguation = new LaunchConfiguation
            {
                JavaSetting = new JavaSetting
                {
                    MaxMemorySize = 10,
                    MinMemorySize = 6,
                    JavaPath      = @"C:\Program Files\Java\jre1.8.0_241\bin\javaw.exe",
                },
                MinecraftSetting = new MinecraftSetting
                {
                    LauncherName    = "Tets",
                    MinecraftSource = @"D:\Minecraft\Solution1\.minecraft",
                    VersionJson     = JsonStorage.ParseVersionJson(@"D:\Minecraft\Solution1\.minecraft\versions\1.8.9")
                }
            };
            foreach (var item in Libraries.GetExistLibraries())
            {
                Console.WriteLine(item.DownloadUri);
                Console.WriteLine(item.FileName);
            }
            LaunchCore launchCore = new LaunchCore();
            String     argss      = launchCore.GenerateLaunchArgs();

            Console.WriteLine(argss);
            launchCore.ExtraNatives();



            Console.ReadLine();
        }
예제 #5
0
        public static async Task <AuthenticationInfo> Auth(AccountType type, string user, string password = "", bool refresh = false)
        {
            if (type == AccountTypes.Mojang)
            {
                Guid clientToken;
                if (!Guid.TryParse(Config.INSTANCE.ClientToken, out clientToken))
                {
                    clientToken = Guid.NewGuid();
                    Config.INSTANCE.ClientToken = clientToken.ToString();
                }

                CancellationToken  ct   = new CancellationToken();
                AuthenticationInfo info = null;
                if (refresh && Guid.TryParse(password, out Guid access))
                {
                    if (Guid.TryParse(Config.INSTANCE.UUID, out Guid uuid))
                    {
                        info = await new YggdrasilValidate(access, clientToken, uuid, Config.INSTANCE.Playername).DoAsync(ct);
                    }
                    if (info == null || !string.IsNullOrEmpty(info.Error))
                    {
                        info = await new YggdrasilRefresh(access, false).DoAsync(ct);
                    }
                }
                else
                {
                    info = await new YggdrasilLogin(user, password, false, clientToken).DoAsync(ct);
                }
                return(info);
            }
            else if (type == AccountTypes.Offline)
            {
                OfflineAuthenticator offline = new OfflineAuthenticator(user);
                return(offline.Do());
            }
            return(null);
        }
예제 #6
0
        private async Task LaunchGameFromArgs(Controls.LaunchEventArgs args)
        {
            try
            {
                #region 检查有效数据
                if (args.LaunchVersion == null)
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Message.EmptyLaunchVersion"),
                                                App.GetResourceString("String.Message.EmptyLaunchVersion2"));

                    return;
                }
                if (args.UserNode == null)
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Message.EmptyUsername"),
                                                App.GetResourceString("String.Message.EmptyUsername2"));

                    return;
                }
                if (args.AuthNode == null)
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Message.EmptyAuthType"),
                                                App.GetResourceString("String.Message.EmptyAuthType2"));

                    return;
                }
                if (App.handler.Java == null)
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Message.NoJava"), App.GetResourceString("String.Message.NoJava2"));

                    return;
                }
                #endregion


                #region 保存启动数据
                App.config.MainConfig.History.LastLaunchVersion = args.LaunchVersion.ID;
                #endregion

                LaunchSetting launchSetting = new LaunchSetting()
                {
                    Version = args.LaunchVersion
                };

                this.loadingGrid.Visibility = Visibility.Visible;
                this.loadingRing.IsActive   = true;

                #region 验证

                #region 设置ClientToken
                if (string.IsNullOrWhiteSpace(App.config.MainConfig.User.ClientToken))
                {
                    App.config.MainConfig.User.ClientToken = Guid.NewGuid().ToString("N");
                }
                else
                {
                    Requester.ClientToken = App.config.MainConfig.User.ClientToken;
                }
                #endregion

                #region 多语言支持变量
                LoginDialogSettings loginDialogSettings = new LoginDialogSettings()
                {
                    NegativeButtonText         = App.GetResourceString("String.Base.Cancel"),
                    AffirmativeButtonText      = App.GetResourceString("String.Base.Login"),
                    RememberCheckBoxText       = App.GetResourceString("String.Base.ShouldRememberLogin"),
                    UsernameWatermark          = App.GetResourceString("String.Base.Username"),
                    InitialUsername            = args.UserNode.UserName,
                    RememberCheckBoxVisibility = Visibility,
                    EnablePasswordPreview      = true,
                    PasswordWatermark          = App.GetResourceString("String.Base.Password"),
                    NegativeButtonVisibility   = Visibility.Visible
                };
                #endregion

                //主验证器接口
                IAuthenticator authenticator  = null;
                bool           shouldRemember = false;

                //bool isSameAuthType = (authNode.AuthenticationType == auth);
                bool isRemember = (!string.IsNullOrWhiteSpace(args.UserNode.AccessToken)) && (args.UserNode.SelectProfileUUID != null);
                //bool isSameName = userName == App.config.MainConfig.User.UserName;

                switch (args.AuthNode.AuthType)
                {
                    #region 离线验证
                case AuthenticationType.OFFLINE:
                    if (args.IsNewUser)
                    {
                        authenticator = new OfflineAuthenticator(args.UserNode.UserName);
                    }
                    else
                    {
                        authenticator = new OfflineAuthenticator(args.UserNode.UserName,
                                                                 args.UserNode.UserData,
                                                                 args.UserNode.SelectProfileUUID);
                    }
                    break;
                    #endregion

                    #region MOJANG验证
                case AuthenticationType.MOJANG:
                    if (isRemember)
                    {
                        var mYggTokenAuthenticator = new YggdrasilTokenAuthenticator(args.UserNode.AccessToken,
                                                                                     args.UserNode.GetSelectProfileUUID(),
                                                                                     args.UserNode.UserData);
                        mYggTokenAuthenticator.ProxyAuthServerAddress = "https://authserver.mojang.com";
                        authenticator = mYggTokenAuthenticator;
                    }
                    else
                    {
                        var mojangLoginDResult = await this.ShowLoginAsync(App.GetResourceString("String.Mainwindow.Auth.Mojang.Login"),
                                                                           App.GetResourceString("String.Mainwindow.Auth.Mojang.Login2"),
                                                                           loginDialogSettings);

                        if (IsValidateLoginData(mojangLoginDResult))
                        {
                            var mYggAuthenticator = new YggdrasilAuthenticator(new Credentials()
                            {
                                Username = mojangLoginDResult.Username,
                                Password = mojangLoginDResult.Password
                            });
                            mYggAuthenticator.ProxyAuthServerAddress = "https://authserver.mojang.com";
                            authenticator  = mYggAuthenticator;
                            shouldRemember = mojangLoginDResult.ShouldRemember;
                        }
                        else
                        {
                            await this.ShowMessageAsync("您输入的账号或密码为空", "请检查您是否正确填写登录信息");

                            return;
                        }
                    }
                    break;
                    #endregion

                    #region NIDE8验证
                case AuthenticationType.NIDE8:
                    string nide8ID = args.AuthNode.Property["nide8ID"];
                    if (string.IsNullOrWhiteSpace(nide8ID))
                    {
                        await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.Auth.Nide8.NoID"),
                                                    App.GetResourceString("String.Mainwindow.Auth.Nide8.NoID2"));

                        return;
                    }
                    var nide8ChooseResult = await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.Auth.Nide8.Login2"), App.GetResourceString("String.Base.Choose"),
                                                                        MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary,
                                                                        new MetroDialogSettings()
                    {
                        AffirmativeButtonText    = App.GetResourceString("String.Base.Login"),
                        NegativeButtonText       = App.GetResourceString("String.Base.Cancel"),
                        FirstAuxiliaryButtonText = App.GetResourceString("String.Base.Register"),
                        DefaultButtonFocus       = MessageDialogResult.Affirmative
                    });

                    switch (nide8ChooseResult)
                    {
                    case MessageDialogResult.Canceled:
                        return;

                    case MessageDialogResult.Negative:
                        return;

                    case MessageDialogResult.FirstAuxiliary:
                        System.Diagnostics.Process.Start(string.Format("https://login2.nide8.com:233/{0}/register", nide8ID));
                        return;

                    case MessageDialogResult.Affirmative:
                        if (isRemember)
                        {
                            var nYggTokenCator = new Nide8TokenAuthenticator(nide8ID, args.UserNode.AccessToken,
                                                                             args.UserNode.GetSelectProfileUUID(),
                                                                             args.UserNode.UserData);
                            authenticator = nYggTokenCator;
                        }
                        else
                        {
                            var nide8LoginDResult = await this.ShowLoginAsync(App.GetResourceString("String.Mainwindow.Auth.Nide8.Login"),
                                                                              App.GetResourceString("String.Mainwindow.Auth.Nide8.Login2"),
                                                                              loginDialogSettings);

                            if (IsValidateLoginData(nide8LoginDResult))
                            {
                                var nYggCator = new Nide8Authenticator(
                                    nide8ID,
                                    new Credentials()
                                {
                                    Username = nide8LoginDResult.Username,
                                    Password = nide8LoginDResult.Password
                                });
                                authenticator  = nYggCator;
                                shouldRemember = nide8LoginDResult.ShouldRemember;
                            }
                            else
                            {
                                await this.ShowMessageAsync("您输入的账号或密码为空", "请检查您是否正确填写登录信息");

                                return;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                    break;
                    #endregion

                    #region AUTHLIB验证
                case AuthenticationType.AUTHLIB_INJECTOR:
                    string aiRootAddr = args.AuthNode.Property["authserver"];
                    if (string.IsNullOrWhiteSpace(aiRootAddr))
                    {
                        await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.Auth.Custom.NoAdrress"),
                                                    App.GetResourceString("String.Mainwindow.Auth.Custom.NoAdrress2"));

                        return;
                    }
                    else
                    {
                        if (isRemember)
                        {
                            var cYggTokenCator = new AuthlibInjectorTokenAuthenticator(aiRootAddr,
                                                                                       args.UserNode.AccessToken,
                                                                                       args.UserNode.GetSelectProfileUUID(),
                                                                                       args.UserNode.UserData);
                            authenticator = cYggTokenCator;
                        }
                        else
                        {
                            var customLoginDResult = await this.ShowLoginAsync(App.GetResourceString("String.Mainwindow.Auth.Custom.Login"),
                                                                               App.GetResourceString("String.Mainwindow.Auth.Custom.Login2"),
                                                                               loginDialogSettings);

                            if (IsValidateLoginData(customLoginDResult))
                            {
                                var cYggAuthenticator = new AuthlibInjectorAuthenticator(
                                    aiRootAddr,
                                    new Credentials()
                                {
                                    Username = customLoginDResult.Username,
                                    Password = customLoginDResult.Password
                                });
                                authenticator  = cYggAuthenticator;
                                shouldRemember = customLoginDResult.ShouldRemember;
                            }
                            else
                            {
                                await this.ShowMessageAsync("您输入的账号或密码为空", "请检查您是否正确填写登录信息");

                                return;
                            }
                        }
                    }
                    break;
                    #endregion

                    #region 自定义验证
                case AuthenticationType.CUSTOM_SERVER:
                    string customAuthServer = args.AuthNode.Property["authserver"];
                    if (string.IsNullOrWhiteSpace(customAuthServer))
                    {
                        await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.Auth.Custom.NoAdrress"),
                                                    App.GetResourceString("String.Mainwindow.Auth.Custom.NoAdrress2"));

                        return;
                    }
                    else
                    {
                        if (isRemember)
                        {
                            var cYggTokenCator = new YggdrasilTokenAuthenticator(args.UserNode.AccessToken,
                                                                                 args.UserNode.GetSelectProfileUUID(),
                                                                                 args.UserNode.UserData);
                            cYggTokenCator.ProxyAuthServerAddress = customAuthServer;
                        }
                        else
                        {
                            var customLoginDResult = await this.ShowLoginAsync(App.GetResourceString("String.Mainwindow.Auth.Custom.Login"),
                                                                               App.GetResourceString("String.Mainwindow.Auth.Custom.Login2"),
                                                                               loginDialogSettings);

                            if (IsValidateLoginData(customLoginDResult))
                            {
                                var cYggAuthenticator = new YggdrasilAuthenticator(new Credentials()
                                {
                                    Username = customLoginDResult.Username,
                                    Password = customLoginDResult.Password
                                });
                                cYggAuthenticator.ProxyAuthServerAddress = customAuthServer;
                                authenticator  = cYggAuthenticator;
                                shouldRemember = customLoginDResult.ShouldRemember;
                            }
                            else
                            {
                                await this.ShowMessageAsync("您输入的账号或密码为空", "请检查您是否正确填写登录信息");

                                return;
                            }
                        }
                    }
                    break;
                    #endregion

                    #region 意外情况
                default:
                    if (args.IsNewUser)
                    {
                        authenticator = new OfflineAuthenticator(args.UserNode.UserName);
                    }
                    else
                    {
                        authenticator = new OfflineAuthenticator(args.UserNode.UserName,
                                                                 args.UserNode.UserData,
                                                                 args.UserNode.SelectProfileUUID);
                    }
                    break;
                    #endregion
                }

                //如果验证方式不是离线验证
                if (args.AuthNode.AuthType != AuthenticationType.OFFLINE)
                {
                    string currentLoginType = string.Format("正在进行{0}中...", args.AuthNode.Name);
                    string loginMsg         = "这需要联网进行操作,可能需要一分钟的时间";
                    var    loader           = await this.ShowProgressAsync(currentLoginType, loginMsg, true);

                    loader.SetIndeterminate();
                    var authResult = await authenticator.DoAuthenticateAsync();

                    await loader.CloseAsync();

                    switch (authResult.State)
                    {
                    case AuthState.SUCCESS:
                        args.UserNode.SelectProfileUUID = authResult.SelectedProfileUUID.Value;
                        args.UserNode.UserData          = authResult.UserData;
                        if (authResult.Profiles != null)
                        {
                            args.UserNode.Profiles.Clear();
                            authResult.Profiles.ForEach(x => args.UserNode.Profiles.Add(x.Value, x));
                        }
                        if (shouldRemember)
                        {
                            args.UserNode.AccessToken = authResult.AccessToken;
                        }
                        launchSetting.AuthenticateResult = authResult;
                        break;

                    case AuthState.REQ_LOGIN:
                        args.UserNode.ClearAuthCache();
                        await this.ShowMessageAsync("验证失败:您的登录信息已过期",
                                                    string.Format("请您重新进行登录。具体信息:{0}", authResult.Error.ErrorMessage));

                        return;

                    case AuthState.ERR_INVALID_CRDL:
                        await this.ShowMessageAsync("验证失败:您的登录账号或密码错误",
                                                    string.Format("请您确认您输入的账号密码正确。具体信息:{0}", authResult.Error.ErrorMessage));

                        return;

                    case AuthState.ERR_NOTFOUND:
                        if (args.AuthNode.AuthType == AuthenticationType.CUSTOM_SERVER || args.AuthNode.AuthType == AuthenticationType.AUTHLIB_INJECTOR)
                        {
                            await this.ShowMessageAsync("验证失败:代理验证服务器地址有误或账号未找到",
                                                        string.Format("请确认您的Authlib-Injector验证服务器(Authlib-Injector验证)或自定义验证服务器(自定义验证)地址正确或确认账号和游戏角色存在。具体信息:{0}",
                                                                      authResult.Error.ErrorMessage));
                        }
                        else
                        {
                            await this.ShowMessageAsync("验证失败:您的账号未找到",
                                                        string.Format("请确认您的账号和游戏角色存在。具体信息:{0}", authResult.Error.ErrorMessage));
                        }
                        return;

                    case AuthState.ERR_OTHER:
                        await this.ShowMessageAsync("验证失败:其他错误",
                                                    string.Format("具体信息:{0}", authResult.Error.ErrorMessage));

                        return;

                    case AuthState.ERR_INSIDE:
                        await this.ShowMessageAsync("验证失败:启动器内部错误",
                                                    string.Format("建议您联系启动器开发者进行解决。具体信息:{0}", authResult.Error.ErrorMessage));

                        return;

                    default:
                        await this.ShowMessageAsync("验证失败:未知错误",
                                                    "建议您联系启动器开发者进行解决。");

                        return;
                    }
                }
                else
                {
                    var authResult = await authenticator.DoAuthenticateAsync();

                    launchSetting.AuthenticateResult = authResult;
                    args.UserNode.UserData           = authResult.UserData;
                    args.UserNode.SelectProfileUUID  = authResult.SelectedProfileUUID.Value;
                }

                App.config.MainConfig.History.SelectedUserNodeID = args.UserNode.UserData.Uuid;
                if (!App.config.MainConfig.User.UserDatabase.ContainsKey(args.UserNode.UserData.Uuid))
                {
                    App.config.MainConfig.User.UserDatabase.Add(args.UserNode.UserData.Uuid, args.UserNode);
                }
                #endregion

                #region 检查游戏完整
                List <DownloadTask> losts = new List <DownloadTask>();

                App.logHandler.AppendInfo("检查丢失的依赖库文件中...");
                var lostDepend = await FileHelper.GetLostDependDownloadTaskAsync(
                    App.config.MainConfig.Download.DownloadSource,
                    App.handler,
                    launchSetting.Version);

                if (args.AuthNode.AuthType == AuthenticationType.NIDE8)
                {
                    string nideJarPath = App.handler.GetNide8JarPath();
                    if (!File.Exists(nideJarPath))
                    {
                        lostDepend.Add(new DownloadTask("统一通行证核心", "https://login2.nide8.com:233/index/jar", nideJarPath));
                    }
                }
                else if (args.AuthNode.AuthType == AuthenticationType.AUTHLIB_INJECTOR)
                {
                    string aiJarPath = App.handler.GetAIJarPath();
                    if (!File.Exists(aiJarPath))
                    {
                        lostDepend.Add(await MineRealmsLauncherCore.Net.Tools.GetDownloadUrl.GetAICoreDownloadTask(App.config.MainConfig.Download.DownloadSource, aiJarPath));
                    }
                }

                if (App.config.MainConfig.Environment.DownloadLostDepend && lostDepend.Count != 0)
                {
                    MessageDialogResult downDependResult = await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.NeedDownloadDepend"),
                                                                                       App.GetResourceString("String.Mainwindow.NeedDownloadDepend2"),
                                                                                       MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, new MetroDialogSettings()
                    {
                        AffirmativeButtonText    = App.GetResourceString("String.Base.Download"),
                        NegativeButtonText       = App.GetResourceString("String.Base.Cancel"),
                        FirstAuxiliaryButtonText = App.GetResourceString("String.Base.Unremember"),
                        DefaultButtonFocus       = MessageDialogResult.Affirmative
                    });

                    switch (downDependResult)
                    {
                    case MessageDialogResult.Affirmative:
                        losts.AddRange(lostDepend);
                        break;

                    case MessageDialogResult.FirstAuxiliary:
                        App.config.MainConfig.Environment.DownloadLostDepend = false;
                        break;

                    default:
                        break;
                    }
                }

                App.logHandler.AppendInfo("检查丢失的资源文件中...");
                if (App.config.MainConfig.Environment.DownloadLostAssets && (await FileHelper.IsLostAssetsAsync(App.config.MainConfig.Download.DownloadSource,
                                                                                                                App.handler, launchSetting.Version)))
                {
                    MessageDialogResult downDependResult = await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.NeedDownloadAssets"),
                                                                                       App.GetResourceString("String.Mainwindow.NeedDownloadAssets2"),
                                                                                       MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, new MetroDialogSettings()
                    {
                        AffirmativeButtonText    = App.GetResourceString("String.Base.Download"),
                        NegativeButtonText       = App.GetResourceString("String.Base.Cancel"),
                        FirstAuxiliaryButtonText = App.GetResourceString("String.Base.Unremember"),
                        DefaultButtonFocus       = MessageDialogResult.Affirmative
                    });

                    switch (downDependResult)
                    {
                    case MessageDialogResult.Affirmative:
                        var lostAssets = await FileHelper.GetLostAssetsDownloadTaskAsync(
                            App.config.MainConfig.Download.DownloadSource,
                            App.handler, launchSetting.Version);

                        losts.AddRange(lostAssets);
                        break;

                    case MessageDialogResult.FirstAuxiliary:
                        App.config.MainConfig.Environment.DownloadLostAssets = false;
                        break;

                    default:
                        break;
                    }
                }

                if (losts.Count != 0)
                {
                    if (!App.downloader.IsBusy)
                    {
                        App.downloader.SetDownloadTasks(losts);
                        App.downloader.StartDownload();
                        var downloadResult = await new DownloadWindow().ShowWhenDownloading();
                        if (downloadResult?.ErrorList?.Count != 0)
                        {
                            await this.ShowMessageAsync(string.Format("有{0}个文件下载补全失败", downloadResult.ErrorList.Count),
                                                        "这可能是因为本地网络问题或下载源问题,您可以尝试检查网络环境或在设置中切换首选下载源,启动器将继续尝试启动");
                        }
                    }
                    else
                    {
                        await this.ShowMessageAsync("无法下载补全:当前有正在下载中的任务", "请等待其下载完毕或取消下载,启动器将尝试继续启动");
                    }
                }

                #endregion

                #region 根据配置文件设置
                launchSetting.AdvencedGameArguments += App.config.MainConfig.Environment.AdvencedGameArguments;
                launchSetting.AdvencedJvmArguments  += App.config.MainConfig.Environment.AdvencedJvmArguments;
                launchSetting.GCArgument            += App.config.MainConfig.Environment.GCArgument;
                launchSetting.GCEnabled              = App.config.MainConfig.Environment.GCEnabled;
                launchSetting.GCType     = App.config.MainConfig.Environment.GCType;
                launchSetting.JavaAgent += App.config.MainConfig.Environment.JavaAgent;
                if (args.AuthNode.AuthType == AuthenticationType.NIDE8)
                {
                    launchSetting.JavaAgent += string.Format(" \"{0}\"={1}", App.handler.GetNide8JarPath(), args.AuthNode.Property["nide8ID"]);
                }
                else if (args.AuthNode.AuthType == AuthenticationType.AUTHLIB_INJECTOR)
                {
                    launchSetting.JavaAgent += string.Format(" \"{0}\"={1}", App.handler.GetAIJarPath(), args.AuthNode.Property["authserver"]);
                }

                //直连服务器设置
                var lockAuthNode = App.config.MainConfig.User.GetLockAuthNode();
                if (App.config.MainConfig.User.Nide8ServerDependence &&
                    (lockAuthNode != null) &&
                    (lockAuthNode.AuthType == AuthenticationType.NIDE8))
                {
                    var nide8ReturnResult = await(new MineRealmsLauncherCore.Net.Nide8API.APIHandler(lockAuthNode.Property["nide8ID"])).GetInfoAsync();
                    if (!string.IsNullOrWhiteSpace(nide8ReturnResult.Meta.ServerIP))
                    {
                        MineRealmsLauncherCore.Modules.Server server = new MineRealmsLauncherCore.Modules.Server();
                        string[] serverIp = nide8ReturnResult.Meta.ServerIP.Split(':');
                        if (serverIp.Length == 2)
                        {
                            server.Address = serverIp[0];
                            server.Port    = ushort.Parse(serverIp[1]);
                        }
                        else
                        {
                            server.Address = nide8ReturnResult.Meta.ServerIP;
                            server.Port    = 25565;
                        }
                        launchSetting.LaunchToServer = server;
                    }
                }
                else if (App.config.MainConfig.Server.LaunchToServer)
                {
                    launchSetting.LaunchToServer = new MineRealmsLauncherCore.Modules.Server()
                    {
                        Address = App.config.MainConfig.Server.Address, Port = App.config.MainConfig.Server.Port
                    };
                }

                //自动内存设置
                if (App.config.MainConfig.Environment.AutoMemory)
                {
                    var m = SystemTools.GetBestMemory(App.handler.Java);
                    App.config.MainConfig.Environment.MaxMemory = m;
                    launchSetting.MaxMemory = m;
                }
                else
                {
                    launchSetting.MaxMemory = App.config.MainConfig.Environment.MaxMemory;
                }
                launchSetting.VersionType = App.config.MainConfig.Customize.VersionInfo;
                launchSetting.WindowSize  = App.config.MainConfig.Environment.WindowSize;
                #endregion

                #region 配置文件处理
                App.config.Save();
                #endregion

                #region 启动

                App.logHandler.OnLog += (a, b) => { this.Invoke(() => { launchInfoBlock.Text = b.Message; }); };
                var result = await App.handler.LaunchAsync(launchSetting);

                App.logHandler.OnLog -= (a, b) => { this.Invoke(() => { launchInfoBlock.Text = b.Message; }); };

                //程序猿是找不到女朋友的了 :)
                if (!result.IsSuccess)
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.LaunchError") + result.LaunchException.Title, result.LaunchException.Message);

                    App.logHandler.AppendError(result.LaunchException);
                }
                else
                {
                    cancelLaunchButton.Click += (x, y) => { CancelLaunching(result); };

                    #region 等待游戏响应
                    try
                    {
                        await Task.Factory.StartNew(() =>
                        {
                            result.Process.WaitForInputIdle();
                        });
                    }
                    catch (Exception ex)
                    {
                        await this.ShowMessageAsync("启动后等待游戏窗口响应异常", "这可能是由于游戏进程发生意外(闪退)导致的。具体原因:" + ex.Message);

                        return;
                    }
                    #endregion

                    cancelLaunchButton.Click -= (x, y) => { CancelLaunching(result); };

                    #region 数据反馈
                    //API使用次数计数器+1
                    await App.MineRealmsAPIHandler.RefreshUsingTimesCounter();

                    #endregion

                    if (App.config.MainConfig.Environment.ExitAfterLaunch)
                    {
                        Application.Current.Shutdown();
                    }
                    this.WindowState = WindowState.Minimized;

                    mainPanel.Refresh();

                    //自定义处理
                    if (!string.IsNullOrWhiteSpace(App.config.MainConfig.Customize.GameWindowTitle))
                    {
                        GameHelper.SetGameTitle(result, App.config.MainConfig.Customize.GameWindowTitle);
                    }
                    if (App.config.MainConfig.Customize.CustomBackGroundMusic)
                    {
                        mediaElement.Volume = 0.5;
                        await Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                for (int i = 0; i < 50; i++)
                                {
                                    this.Dispatcher.Invoke(new Action(() =>
                                    {
                                        this.mediaElement.Volume -= 0.01;
                                    }));
                                    Thread.Sleep(50);
                                }
                                this.Dispatcher.Invoke(new Action(() =>
                                {
                                    this.mediaElement.Stop();
                                }));
                            }
                            catch (Exception) { }
                        });
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                App.logHandler.AppendFatal(ex);
            }
            finally
            {
                this.loadingGrid.Visibility = Visibility.Hidden;
                this.loadingRing.IsActive   = false;
            }
        }
예제 #7
0
        /// <summary>
        /// 启动游戏。
        /// Launch the game.
        /// </summary>
        /// <param name="settings">启动设置。Launch Settings.</param>
        /// <returns>启动结果。如果成功则包含消耗的时间,如果失败则包含异常信息。The result contains elapsed time(if successful) or elapsed time plus exception info(if failed).</returns>
        public async Task <LaunchResult> LaunchTaskAsync(LaunchSettings settings)
        {
            try
            {
                //逐步测量启动时间。
                //To measure the launch time step by step.
                var prevSpan  = new TimeSpan();
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                #region 解析游戏 Game Info Resolver
                var version = VersionLocator.GetGame(settings.Version);

                //在以下方法中,我们存储前一个步骤的时间并且重置秒表,以此逐步测量启动时间。
                //In the method InvokeLaunchLogThenStart(args), we storage the time span of the previous process and restart the watch in order that the time used in each step is recorded.
                InvokeLaunchLogThenStart("解析游戏", ref prevSpan, ref stopwatch);

                //错误处理
                //Error processor
                if (version == null)
                {
                    return(new LaunchResult
                    {
                        ErrorType = LaunchErrorType.OperationFailed,
                        Error = new ErrorModel
                        {
                            Error = "解析游戏失败",
                            ErrorMessage = "我们在解析游戏时出现了错误",
                            Cause = "这有可能是因为您的游戏JSON文件损坏所导致的问题"
                        }
                    });
                }
                #endregion

                #region 验证账户凭据 Legal Account Verifier

                //以下代码实现了账户模式从离线到在线的切换。
                //The following code switches account mode between offline and yggdrasil.
                var authResult = settings.Authenticator switch
                {
                    OfflineAuthenticator off => off.Auth(false),
                    YggdrasilAuthenticator ygg => await ygg.AuthTaskAsync(true).ConfigureAwait(true),
                    _ => null
                };
                InvokeLaunchLogThenStart("验证账户凭据", ref prevSpan, ref stopwatch);

                //错误处理
                //Error processor
                if (authResult == null || authResult.AuthStatus == AuthStatus.Failed ||
                    authResult.AuthStatus == AuthStatus.Unknown)
                {
                    return(new LaunchResult
                    {
                        LaunchSettings = settings,
                        Error = new ErrorModel
                        {
                            Error = "验证失败",
                            Cause = authResult == null ? "未知的验证器" : authResult.AuthStatus switch
                            {
                                AuthStatus.Failed => "可能是因为用户名或密码错误,或是验证服务器暂时未响应",
                                AuthStatus.Unknown => "未知错误",
                                _ => "未知错误"
                            },
                            ErrorMessage = "无法验证凭据的有效性"
                        }
예제 #8
0
        private async Task LaunchGameFromWindow()
        {
            try
            {
                string userName = playerNameTextBox.Text;

                #region 检查有效数据
                if (authTypeCombobox.SelectedItem == null)
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Message.EmptyAuthType"),
                                                App.GetResourceString("String.Message.EmptyAuthType2"));

                    return;
                }
                if (string.IsNullOrWhiteSpace(userName))
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Message.EmptyUsername"),
                                                App.GetResourceString("String.Message.EmptyUsername2"));

                    return;
                }
                if (launchVersionCombobox.SelectedItem == null)
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Message.EmptyLaunchVersion"),
                                                App.GetResourceString("String.Message.EmptyLaunchVersion2"));

                    return;
                }
                if (App.handler.Java == null)
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Message.NoJava"), App.GetResourceString("String.Message.NoJava2"));

                    return;
                }
                #endregion

                NsisoLauncherCore.Modules.Version launchVersion = (NsisoLauncherCore.Modules.Version)launchVersionCombobox.SelectedItem;
                AuthTypeItem auth = (AuthTypeItem)authTypeCombobox.SelectedItem;

                #region 保存启动数据
                App.config.MainConfig.History.LastLaunchVersion = launchVersion.ID;
                App.config.MainConfig.User.UserName             = userName;
                #endregion

                LaunchSetting launchSetting = new LaunchSetting()
                {
                    Version = (NsisoLauncherCore.Modules.Version)launchVersionCombobox.SelectedItem
                };

                this.loadingGrid.Visibility = Visibility.Visible;
                this.loadingRing.IsActive   = true;

                #region 验证

                #region 设置ClientToken
                if (string.IsNullOrWhiteSpace(App.config.MainConfig.User.ClientToken))
                {
                    App.config.MainConfig.User.ClientToken = Guid.NewGuid().ToString("N");
                }
                else
                {
                    Requester.ClientToken = App.config.MainConfig.User.ClientToken;
                }
                #endregion

                #region 多语言支持变量(old)
                //string autoVerifyingMsg = null;
                //string autoVerifyingMsg2 = null;
                //string autoVerificationFailedMsg = null;
                //string autoVerificationFailedMsg2 = null;
                //string loginMsg = null;
                //string loginMsg2 = null;
                LoginDialogSettings loginDialogSettings = new LoginDialogSettings()
                {
                    NegativeButtonText         = App.GetResourceString("String.Base.Cancel"),
                    AffirmativeButtonText      = App.GetResourceString("String.Base.Login"),
                    RememberCheckBoxText       = App.GetResourceString("String.Base.ShouldRememberLogin"),
                    UsernameWatermark          = App.GetResourceString("String.Base.Username"),
                    InitialUsername            = userName,
                    RememberCheckBoxVisibility = Visibility,
                    EnablePasswordPreview      = true,
                    PasswordWatermark          = App.GetResourceString("String.Base.Password"),
                    NegativeButtonVisibility   = Visibility.Visible
                };
                //string verifyingMsg = null, verifyingMsg2 = null, verifyingFailedMsg = null, verifyingFailedMsg2 = null;
                #endregion

                //主验证器接口
                IAuthenticator authenticator  = null;
                bool           shouldRemember = false;

                bool isSameAuthType = App.config.MainConfig.User.AuthenticationType == auth.Type;
                bool isRemember     = (!string.IsNullOrWhiteSpace(App.config.MainConfig.User.AccessToken)) && (App.config.MainConfig.User.AuthenticationUUID != null);

                switch (auth.Type)
                {
                    #region 离线验证
                case Config.AuthenticationType.OFFLINE:
                    authenticator = new OfflineAuthenticator(userName);
                    break;
                    #endregion

                    #region Mojang验证
                case Config.AuthenticationType.MOJANG:
                    if (isSameAuthType && isRemember)
                    {
                        var mYggTokenAuthenticator = new YggdrasilTokenAuthenticator(App.config.MainConfig.User.AccessToken,
                                                                                     App.config.MainConfig.User.AuthenticationUUID,
                                                                                     App.config.MainConfig.User.AuthenticationUserData);
                        mYggTokenAuthenticator.ProxyAuthServerAddress = "https://authserver.mojang.com";
                        authenticator = mYggTokenAuthenticator;
                    }
                    else
                    {
                        var mojangLoginDResult = await this.ShowLoginAsync(App.GetResourceString("String.Mainwindow.Auth.Mojang.Login"),
                                                                           App.GetResourceString("String.Mainwindow.Auth.Mojang.Login2"),
                                                                           loginDialogSettings);

                        if (IsValidateLoginData(mojangLoginDResult))
                        {
                            var mYggAuthenticator = new YggdrasilAuthenticator(new Credentials()
                            {
                                Username = mojangLoginDResult.Username,
                                Password = mojangLoginDResult.Password
                            });
                            mYggAuthenticator.ProxyAuthServerAddress = "https://authserver.mojang.com";
                            authenticator  = mYggAuthenticator;
                            shouldRemember = mojangLoginDResult.ShouldRemember;
                        }
                        else
                        {
                            await this.ShowMessageAsync("您输入的账号或密码为空", "请检查您是否正确填写登陆信息");

                            return;
                        }
                    }
                    break;
                    #endregion

                    #region 统一通行证验证
                case Config.AuthenticationType.NIDE8:
                    if (App.nide8Handler == null)
                    {
                        await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.Auth.Nide8.NoID"),
                                                    App.GetResourceString("String.Mainwindow.Auth.Nide8.NoID2"));

                        return;
                    }
                    var nide8ChooseResult = await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.Auth.Nide8.Login2"), App.GetResourceString("String.Base.Choose"),
                                                                        MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary,
                                                                        new MetroDialogSettings()
                    {
                        AffirmativeButtonText    = App.GetResourceString("String.Base.Login"),
                        NegativeButtonText       = App.GetResourceString("String.Base.Cancel"),
                        FirstAuxiliaryButtonText = App.GetResourceString("String.Base.Register"),
                        DefaultButtonFocus       = MessageDialogResult.Affirmative
                    });

                    switch (nide8ChooseResult)
                    {
                    case MessageDialogResult.Canceled:
                        return;

                    case MessageDialogResult.Negative:
                        return;

                    case MessageDialogResult.FirstAuxiliary:
                        System.Diagnostics.Process.Start(string.Format("https://login2.nide8.com:233/{0}/register", App.nide8Handler.ServerID));
                        return;

                    case MessageDialogResult.SecondAuxiliary:
                        if (isSameAuthType && isRemember)
                        {
                            var nYggTokenCator = new Nide8TokenAuthenticator(App.config.MainConfig.User.AccessToken,
                                                                             App.config.MainConfig.User.AuthenticationUUID,
                                                                             App.config.MainConfig.User.AuthenticationUserData);
                            nYggTokenCator.ProxyAuthServerAddress = string.Format("{0}authserver", App.nide8Handler.BaseURL);
                            authenticator = nYggTokenCator;
                        }
                        else
                        {
                            var nide8LoginDResult = await this.ShowLoginAsync(App.GetResourceString("String.Mainwindow.Auth.Nide8.Login"),
                                                                              App.GetResourceString("String.Mainwindow.Auth.Nide8.Login2"),
                                                                              loginDialogSettings);

                            if (IsValidateLoginData(nide8LoginDResult))
                            {
                                var nYggCator = new Nide8Authenticator(new Credentials()
                                {
                                    Username = nide8LoginDResult.Username,
                                    Password = nide8LoginDResult.Password
                                });
                                nYggCator.ProxyAuthServerAddress = string.Format("{0}authserver", App.nide8Handler.BaseURL);
                                authenticator  = nYggCator;
                                shouldRemember = nide8LoginDResult.ShouldRemember;
                            }
                            else
                            {
                                await this.ShowMessageAsync("您输入的账号或密码为空", "请检查您是否正确填写登陆信息");

                                return;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                    break;
                    #endregion

                    #region 自定义验证
                case Config.AuthenticationType.CUSTOM_SERVER:
                    string customAuthServer = App.config.MainConfig.User.AuthServer;
                    if (string.IsNullOrWhiteSpace(customAuthServer))
                    {
                        await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.Auth.Custom.NoAdrress"),
                                                    App.GetResourceString("String.Mainwindow.Auth.Custom.NoAdrress2"));

                        return;
                    }
                    else
                    {
                        if (shouldRemember && isSameAuthType)
                        {
                            var cYggTokenCator = new YggdrasilTokenAuthenticator(App.config.MainConfig.User.AccessToken,
                                                                                 App.config.MainConfig.User.AuthenticationUUID,
                                                                                 App.config.MainConfig.User.AuthenticationUserData);
                            cYggTokenCator.ProxyAuthServerAddress = customAuthServer;
                        }
                        else
                        {
                            var customLoginDResult = await this.ShowLoginAsync(App.GetResourceString("String.Mainwindow.Auth.Custom.Login"),
                                                                               App.GetResourceString("String.Mainwindow.Auth.Custom.Login2"),
                                                                               loginDialogSettings);

                            if (IsValidateLoginData(customLoginDResult))
                            {
                                var cYggAuthenticator = new YggdrasilAuthenticator(new Credentials()
                                {
                                    Username = customLoginDResult.Username,
                                    Password = customLoginDResult.Password
                                });
                                cYggAuthenticator.ProxyAuthServerAddress = customAuthServer;
                                authenticator  = cYggAuthenticator;
                                shouldRemember = customLoginDResult.ShouldRemember;
                            }
                            else
                            {
                                await this.ShowMessageAsync("您输入的账号或密码为空", "请检查您是否正确填写登陆信息");

                                return;
                            }
                        }
                    }
                    break;
                    #endregion

                default:
                    authenticator = new OfflineAuthenticator(userName);
                    break;
                }

                #region Old
                //if (auth.Type != Config.AuthenticationType.OFFLINE)
                //{
                //    try
                //    {
                //        #region 如果记住登陆(有登陆记录)
                //        if ((!string.IsNullOrWhiteSpace(App.config.MainConfig.User.AccessToken)) && (App.config.MainConfig.User.AuthenticationUUID != null))
                //        {
                //            authenticator = new YggdrasilTokenAuthenticator(App.config.MainConfig.User.AccessToken,
                //                App.config.MainConfig.User.AuthenticationUUID,
                //                App.config.MainConfig.User.AuthenticationUserData);
                //            //var loader = await this.ShowProgressAsync(autoVerifyingMsg, autoVerifyingMsg2);
                //            //loader.SetIndeterminate();
                //            //Validate validate = new Validate(App.config.MainConfig.User.AccessToken);
                //            //var validateResult = await validate.PerformRequestAsync();
                //            //if (validateResult.IsSuccess)
                //            //{

                //            //    launchSetting.AuthenticateAccessToken = App.config.MainConfig.User.AccessToken;
                //            //    launchSetting.AuthenticateUUID = App.config.MainConfig.User.AuthenticationUUID;
                //            //    await loader.CloseAsync();
                //            //}
                //            //else
                //            //{
                //            //    Refresh refresher = new Refresh(App.config.MainConfig.User.AccessToken);
                //            //    var refreshResult = await refresher.PerformRequestAsync();
                //            //    await loader.CloseAsync();
                //            //    if (refreshResult.IsSuccess)
                //            //    {
                //            //        App.config.MainConfig.User.AccessToken = refreshResult.AccessToken;

                //            //        launchSetting.AuthenticateUUID = App.config.MainConfig.User.AuthenticationUUID;
                //            //        launchSetting.AuthenticateAccessToken = refreshResult.AccessToken;
                //            //    }
                //            //    else
                //            //    {
                //            //        App.config.MainConfig.User.AccessToken = string.Empty;
                //            //        App.config.Save();
                //            //        await this.ShowMessageAsync(autoVerificationFailedMsg, autoVerificationFailedMsg2);
                //            //        return;
                //            //    }
                //            //}
                //        }
                //        #endregion

                //        #region 从零登陆
                //        else
                //        {
                //            var loginMsgResult = await this.ShowLoginAsync(loginMsg, loginMsg2, loginDialogSettings);

                //            if (loginMsgResult == null)
                //            {
                //                return;
                //            }
                //            var loader = await this.ShowProgressAsync(verifyingMsg, verifyingMsg2);
                //            loader.SetIndeterminate();
                //            userName = loginMsgResult.Username;
                //            Authenticate authenticate = new Authenticate(new Credentials() { Username = loginMsgResult.Username, Password = loginMsgResult.Password });
                //            var aloginResult = await authenticate.PerformRequestAsync();
                //            await loader.CloseAsync();
                //            if (aloginResult.IsSuccess)
                //            {
                //                if (loginMsgResult.ShouldRemember)
                //                {
                //                    App.config.MainConfig.User.AccessToken = aloginResult.AccessToken;
                //                }
                //                App.config.MainConfig.User.AuthenticationUserData = aloginResult.User;
                //                App.config.MainConfig.User.AuthenticationUUID = aloginResult.SelectedProfile;

                //                launchSetting.AuthenticateAccessToken = aloginResult.AccessToken;
                //                launchSetting.AuthenticateUUID = aloginResult.SelectedProfile;
                //                launchSetting.AuthenticationUserData = aloginResult.User;
                //            }
                //            else
                //            {
                //                await this.ShowMessageAsync(verifyingFailedMsg, verifyingFailedMsg2 + aloginResult.Error.ErrorMessage);
                //                return;
                //            }
                //        }
                //        #endregion
                //    }
                //    catch (Exception ex)
                //    {
                //        await this.ShowMessageAsync(verifyingFailedMsg, verifyingFailedMsg2 + ex.Message);
                //        return;
                //    }
                //}
                #endregion

                if (auth.Type != Config.AuthenticationType.OFFLINE)
                {
                    string currentLoginType = string.Format("正在进行{0}中...", auth.Name);
                    string loginMsg         = "这需要联网进行操作,可能需要一分钟的时间";
                    var    loader           = await this.ShowProgressAsync(currentLoginType, loginMsg);

                    loader.SetIndeterminate();
                    var authResult = await authenticator.DoAuthenticateAsync();

                    await loader.CloseAsync();

                    switch (authResult.State)
                    {
                    case AuthState.SUCCESS:
                        if (shouldRemember)
                        {
                            App.config.MainConfig.User.AccessToken            = authResult.AccessToken;
                            App.config.MainConfig.User.AuthenticationUUID     = authResult.UUID;
                            App.config.MainConfig.User.AuthenticationUserData = authResult.UserData;
                        }
                        launchSetting.AuthenticateResult = authResult;
                        break;

                    case AuthState.REQ_LOGIN:
                        await this.ShowMessageAsync("验证失败:您的登陆信息已过期",
                                                    string.Format("请您重新进行登陆。具体信息:{0}", authResult.Error.ErrorMessage));

                        return;

                    case AuthState.ERR_INVALID_CRDL:
                        await this.ShowMessageAsync("验证失败:您的登陆账号或密码错误",
                                                    string.Format("请您确认您输入的账号密码正确。具体信息:{0}", authResult.Error.ErrorMessage));

                        return;

                    case AuthState.ERR_NOTFOUND:
                        await this.ShowMessageAsync("验证失败:您的账号未找到",
                                                    string.Format("请确认您的账号和游戏角色存在。具体信息:{0}", authResult.Error.ErrorMessage));

                        return;

                    case AuthState.ERR_OTHER:
                        await this.ShowMessageAsync("验证失败:其他错误",
                                                    string.Format("具体信息:{0}", authResult.Error.ErrorMessage));

                        return;

                    case AuthState.ERR_INSIDE:
                        await this.ShowMessageAsync("验证失败:启动器内部错误",
                                                    string.Format("建议您联系启动器开发者进行解决。具体信息:{0}", authResult.Error.ErrorMessage));

                        return;

                    default:
                        await this.ShowMessageAsync("验证失败:未知错误",
                                                    "建议您联系启动器开发者进行解决。");

                        return;
                    }
                }
                else
                {
                    launchSetting.AuthenticateResult = await authenticator.DoAuthenticateAsync();
                }
                App.config.MainConfig.User.AuthenticationType = auth.Type;
                #endregion

                #region 检查游戏完整
                List <DownloadTask> losts = new List <DownloadTask>();

                App.logHandler.AppendInfo("检查丢失的依赖库文件中...");
                var lostDepend = await FileHelper.GetLostDependDownloadTaskAsync(
                    App.config.MainConfig.Download.DownloadSource,
                    App.handler,
                    launchSetting.Version);

                if (auth.Type == Config.AuthenticationType.NIDE8)
                {
                    string nideJarPath = App.handler.GetNide8JarPath();
                    if (!File.Exists(nideJarPath))
                    {
                        lostDepend.Add(new DownloadTask("统一通行证核心", "https://login2.nide8.com:233/index/jar", nideJarPath));
                    }
                }
                if (App.config.MainConfig.Environment.DownloadLostDepend && lostDepend.Count != 0)
                {
                    MessageDialogResult downDependResult = await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.NeedDownloadDepend"),
                                                                                       App.GetResourceString("String.Mainwindow.NeedDownloadDepend2"),
                                                                                       MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, new MetroDialogSettings()
                    {
                        AffirmativeButtonText    = App.GetResourceString("String.Base.Download"),
                        NegativeButtonText       = App.GetResourceString("String.Base.Cancel"),
                        FirstAuxiliaryButtonText = App.GetResourceString("String.Base.Unremember"),
                        DefaultButtonFocus       = MessageDialogResult.Affirmative
                    });

                    switch (downDependResult)
                    {
                    case MessageDialogResult.Affirmative:
                        losts.AddRange(lostDepend);
                        break;

                    case MessageDialogResult.FirstAuxiliary:
                        App.config.MainConfig.Environment.DownloadLostDepend = false;
                        break;

                    default:
                        break;
                    }
                }

                App.logHandler.AppendInfo("检查丢失的资源文件中...");
                if (App.config.MainConfig.Environment.DownloadLostAssets && (await FileHelper.IsLostAssetsAsync(App.config.MainConfig.Download.DownloadSource,
                                                                                                                App.handler, launchSetting.Version)))
                {
                    MessageDialogResult downDependResult = await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.NeedDownloadAssets"),
                                                                                       App.GetResourceString("String.Mainwindow.NeedDownloadAssets2"),
                                                                                       MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, new MetroDialogSettings()
                    {
                        AffirmativeButtonText    = App.GetResourceString("String.Base.Download"),
                        NegativeButtonText       = App.GetResourceString("String.Base.Cancel"),
                        FirstAuxiliaryButtonText = App.GetResourceString("String.Base.Unremember"),
                        DefaultButtonFocus       = MessageDialogResult.Affirmative
                    });

                    switch (downDependResult)
                    {
                    case MessageDialogResult.Affirmative:
                        var lostAssets = await FileHelper.GetLostAssetsDownloadTaskAsync(
                            App.config.MainConfig.Download.DownloadSource,
                            App.handler, launchSetting.Version);

                        losts.AddRange(lostAssets);
                        break;

                    case MessageDialogResult.FirstAuxiliary:
                        App.config.MainConfig.Environment.DownloadLostAssets = false;
                        break;

                    default:
                        break;
                    }
                }

                if (losts.Count != 0)
                {
                    App.downloader.SetDownloadTasks(losts);
                    App.downloader.StartDownload();
                    await new Windows.DownloadWindow().ShowWhenDownloading();
                }

                #endregion

                #region 根据配置文件设置
                launchSetting.AdvencedGameArguments += App.config.MainConfig.Environment.AdvencedGameArguments;
                launchSetting.AdvencedJvmArguments  += App.config.MainConfig.Environment.AdvencedJvmArguments;
                launchSetting.GCArgument            += App.config.MainConfig.Environment.GCArgument;
                launchSetting.GCEnabled              = App.config.MainConfig.Environment.GCEnabled;
                launchSetting.GCType     = App.config.MainConfig.Environment.GCType;
                launchSetting.JavaAgent += App.config.MainConfig.Environment.JavaAgent;
                if (auth.Type == Config.AuthenticationType.NIDE8)
                {
                    launchSetting.JavaAgent += string.Format(" \"{0}\"={1}", App.handler.GetNide8JarPath(), App.config.MainConfig.User.Nide8ServerID);
                }

                //直连服务器设置
                if ((auth.Type == Config.AuthenticationType.NIDE8) && App.config.MainConfig.User.AllUsingNide8)
                {
                    var nide8ReturnResult = await App.nide8Handler.GetInfoAsync();

                    if (App.config.MainConfig.User.AllUsingNide8 && !string.IsNullOrWhiteSpace(nide8ReturnResult.Meta.ServerIP))
                    {
                        Server   server   = new Server();
                        string[] serverIp = nide8ReturnResult.Meta.ServerIP.Split(':');
                        if (serverIp.Length == 2)
                        {
                            server.Address = serverIp[0];
                            server.Port    = ushort.Parse(serverIp[1]);
                        }
                        else
                        {
                            server.Address = nide8ReturnResult.Meta.ServerIP;
                            server.Port    = 25565;
                        }
                        launchSetting.LaunchToServer = server;
                    }
                }
                else if (App.config.MainConfig.Server.LaunchToServer)
                {
                    launchSetting.LaunchToServer = new Server()
                    {
                        Address = App.config.MainConfig.Server.Address, Port = App.config.MainConfig.Server.Port
                    };
                }

                //自动内存设置
                if (App.config.MainConfig.Environment.AutoMemory)
                {
                    var m = SystemTools.GetBestMemory(App.handler.Java);
                    App.config.MainConfig.Environment.MaxMemory = m;
                    launchSetting.MaxMemory = m;
                }
                else
                {
                    launchSetting.MaxMemory = App.config.MainConfig.Environment.MaxMemory;
                }
                launchSetting.VersionType = App.config.MainConfig.Customize.VersionInfo;
                launchSetting.WindowSize  = App.config.MainConfig.Environment.WindowSize;
                #endregion

                #region 配置文件处理
                App.config.Save();
                #endregion

                #region 启动

                App.logHandler.OnLog += (a, b) => { this.Invoke(() => { launchInfoBlock.Text = b.Message; }); };
                var result = await App.handler.LaunchAsync(launchSetting);

                App.logHandler.OnLog -= (a, b) => { this.Invoke(() => { launchInfoBlock.Text = b.Message; }); };

                //程序猿是找不到女朋友的了 :)
                if (!result.IsSuccess)
                {
                    await this.ShowMessageAsync(App.GetResourceString("String.Mainwindow.LaunchError") + result.LaunchException.Title, result.LaunchException.Message);

                    App.logHandler.AppendError(result.LaunchException);
                }
                else
                {
                    try
                    {
                        await Task.Factory.StartNew(() =>
                        {
                            result.Process.WaitForInputIdle();
                        });
                    }
                    catch (Exception ex)
                    {
                        await this.ShowMessageAsync("启动后等待游戏窗口响应异常", "这可能是由于游戏进程发生意外(闪退)导致的。具体原因:" + ex.Message);

                        return;
                    }
                    if (App.config.MainConfig.Environment.ExitAfterLaunch)
                    {
                        Application.Current.Shutdown();
                    }
                    this.WindowState = WindowState.Minimized;
                    Refresh();

                    //自定义处理
                    if (!string.IsNullOrWhiteSpace(App.config.MainConfig.Customize.GameWindowTitle))
                    {
                        GameHelper.SetGameTitle(result, App.config.MainConfig.Customize.GameWindowTitle);
                    }
                    if (App.config.MainConfig.Customize.CustomBackGroundMusic)
                    {
                        mediaElement.Volume = 0.5;
                        await Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                for (int i = 0; i < 50; i++)
                                {
                                    this.Dispatcher.Invoke(new Action(() =>
                                    {
                                        this.mediaElement.Volume -= 0.01;
                                    }));
                                    Thread.Sleep(50);
                                }
                                this.Dispatcher.Invoke(new Action(() =>
                                {
                                    this.mediaElement.Stop();
                                }));
                            }
                            catch (Exception) { }
                        });
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                App.logHandler.AppendFatal(ex);
            }
            finally
            {
                this.loadingGrid.Visibility = Visibility.Hidden;
                this.loadingRing.IsActive   = false;
            }
        }