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); }
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(); }
/// <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 = "无法验证凭据的有效性" }