internal LaunchResult LaunchInternal(LaunchOptions options, params Action<MinecraftLaunchArguments>[] argumentsOperators) { lock (Locker) { if (!File.Exists(JavaPath)) { return new LaunchResult {Success = false, ErrorType = ErrorType.NoJAVA, ErrorMessage = "指定的JAVA位置不存在"}; } CurrentCode = Random.Next(); var args = new MinecraftLaunchArguments(); var result = GenerateArguments(options, ref args); if (result != null) { return result; } if (argumentsOperators == null) return LaunchGame(args); foreach (var opt in argumentsOperators) { try { if (opt != null) { opt(args); } } catch (Exception exp) { return new LaunchResult {Success = false, ErrorType = ErrorType.OperatorException, ErrorMessage = "指定的操作器引发了异常", Exception = exp}; } } return LaunchGame(args); } }
public BasicLaunchReport(LauncherCore core, LaunchResult result, LaunchOptions options) : base(result, options) { #region 系统信息 VideoCardInfo = GetVideoCardInfo(); ProcessorInfo = GetProcessorInfo(); #endregion #region 启动信息 JavaPath = core.JavaPath; #endregion }
internal LaunchResult LaunchInternal(LaunchOptions options, params Action <MinecraftLaunchArguments>[] argumentsOperators) { lock (Locker) { if (!File.Exists(JavaPath)) { return(new LaunchResult { Success = false, ErrorType = ErrorType.NoJAVA, ErrorMessage = "指定的JAVA位置不存在" }); } CurrentCode = Random.Next(); var args = new MinecraftLaunchArguments(); var result = GenerateArguments(options, ref args); if (result != null) { return(result); } if (argumentsOperators == null) { return(LaunchGame(args)); } foreach (var opt in argumentsOperators) { try { if (opt != null) { opt(args); } } catch (Exception exp) { return(new LaunchResult { Success = false, ErrorType = ErrorType.OperatorException, ErrorMessage = "指定的操作器引发了异常", Exception = exp }); } } return(LaunchGame(args)); } }
/// <summary> /// 报告一次启动结果 /// </summary> /// <param name="core">启动器核心</param> /// <param name="result">启动结果</param> /// <param name="options">启动选项</param> public static LaunchResult Report(this LauncherCore core, LaunchResult result, LaunchOptions options) { if (_reportLevel == ReportLevel.None) { return(result); } if (result.ErrorType == ErrorType.NoJAVA) { if (NoJavaReported) { return(result); } NoJavaReported = true; } Task.Factory.StartNew(() => { try { var wc = new WebClient(); wc.Headers.Add("user-agent", _clientName); wc.UploadString(LAUNCH_REPORT, JsonMapper.ToJson((_reportLevel == ReportLevel.Full) ? new FullLaunchReport(core, result, options) : (_reportLevel == ReportLevel.Basic) ? new BasicLaunchReport(core, result, options) : new MinLaunchReport(result, options)) #if DEBUG .Print() #endif ); } catch { Console.WriteLine("[KMCCC] report failed"); } }); return(result); }
/// <summary> /// 报告一次启动结果 /// </summary> /// <param name="core">启动器核心</param> /// <param name="result">启动结果</param> /// <param name="options">启动选项</param> public static LaunchResult Report(this LauncherCore core, LaunchResult result, LaunchOptions options) { if (_reportLevel == ReportLevel.None) return result; if (result.ErrorType == ErrorType.NoJAVA) { if (NoJavaReported) { return result; } NoJavaReported = true; } Task.Factory.StartNew(() => { try { var wc = new WebClient(); wc.Headers.Add("user-agent", _clientName); wc.UploadString(LAUNCH_REPORT, JsonMapper.ToJson((_reportLevel == ReportLevel.Full) ? new FullLaunchReport(core, result, options) : (_reportLevel == ReportLevel.Basic) ? new BasicLaunchReport(core, result, options) : new MinLaunchReport(result, options)) #if DEBUG .Print() #endif ); } catch { Console.WriteLine("[KMCCC] report failed"); } }); return result; }
public MinLaunchReport(LaunchResult result, LaunchOptions options) { #region KMCCC信息 LauncherType = KMCCC_TYPE; LauncherVersion = Version; #endregion #region 系统信息 RuntimeVersion = Environment.Version.ToString(); SystemVersion = Environment.OSVersion.VersionString; Memory = ((uint) (SystemTools.GetTotalMemory() >> 20)); Arch = SystemTools.GetArch(); #endregion #region 启动信息 LaunchErrorType = result.ErrorType.ToString(); AuthenticationType = options.Authenticator.Type; #endregion }
public FullLaunchReport(LauncherCore core, LaunchResult result, LaunchOptions options) : base(core, result, options) { LaunchedVersionId = options.Version.Id; AutoConnectServer = (options.Server != null) ? options.Server.ToString() : ""; LauncherDirectory = Environment.CurrentDirectory; GameDirectory = core.GameRootPath; if (result.Handle != null) { PlayerName = result.Handle.Arguments.Authentication.DisplayName; } }
public BasicLaunchReport(LauncherCore core, LaunchResult result, LaunchOptions options) : base(result, options) { #region 系统信息 VideoCardInfo = GetVideoCardInfo(); ProcessorInfo = GetProcessorInfo(); #endregion #region 启动信息 JavaPath = core.JavaPath; #endregion }
private LaunchResult GenerateArguments(LaunchOptions options, ref MinecraftLaunchArguments args) { try { var authentication = options.Authenticator.Do(); if (!string.IsNullOrWhiteSpace(authentication.Error)) { return new LaunchResult { Success = false, ErrorType = ErrorType.AuthenticationFailed, ErrorMessage = "验证错误: " + authentication.Error } } ; args.CGCEnabled = true; args.MainClass = options.Version.MainClass; args.MaxMemory = options.MaxMemory; args.AgentPath = options.AgentPath; args.MinMemory = options.MinMemory; args.NativePath = GameRootPath + @"\$natives"; foreach (var native in options.Version.Natives) { var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options); if (exp == null) { continue; } return(new LaunchResult { Success = false, ErrorType = ErrorType.UncompressingFailed, ErrorMessage = string.Format("解压错误: {0}:{1}:{2}", native.NS, native.Name, native.Version), Exception = exp }); } args.Server = options.Server; args.Size = options.Size; args.Libraries = options.Version.Libraries.Select(this.GetLibPath).ToList(); args.Libraries.Add(this.GetVersionJarPath(options.Version.JarId)); args.MinecraftArguments = options.Version.MinecraftArguments; string AssetsPath = options.Version.Assets == "legacy" ? "assets\\virtual\\legacy" : "assets"; args.Tokens.Add("auth_access_token", authentication.AccessToken.GoString()); args.Tokens.Add("auth_session", authentication.AccessToken.GoString()); args.Tokens.Add("auth_player_name", authentication.DisplayName); args.Tokens.Add("version_name", options.Version.Id); args.Tokens.Add("game_directory", "."); args.Tokens.Add("game_assets", AssetsPath); args.Tokens.Add("assets_root", AssetsPath); args.Tokens.Add("assets_index_name", options.Version.Assets); args.Tokens.Add("auth_uuid", authentication.UUID.GoString()); args.Tokens.Add("user_properties", authentication.Properties); args.Tokens.Add("user_type", authentication.UserType); args.Tokens.Add("version_type", options.VersionType ?? "KMCCC"); args.AdvencedArguments = new List <string> { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" }; args.Authentication = authentication; args.Version = options.Version; if (options.Mode != null) { options.Mode.Operate(this, args); } return(null); } catch (Exception exp) { return(new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "在生成参数时发生了意外的错误", Exception = exp }); } }
private LaunchResult GenerateArguments(LaunchOptions options, ref MinecraftLaunchArguments args) { try { var authentication = options.Authenticator.Do(); if (!string.IsNullOrWhiteSpace(authentication.Error)) return new LaunchResult { Success = false, ErrorType = ErrorType.AuthenticationFailed, ErrorMessage = "验证错误: " + authentication.Error }; args.CGCEnabled = true; args.MainClass = options.Version.MainClass; args.MaxMemory = options.MaxMemory; args.MinMemory = options.MinMemory; args.NativePath = GameRootPath + @"\$natives"; foreach (var native in options.Version.Natives) { var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options); if (exp == null) { continue; } return new LaunchResult { Success = false, ErrorType = ErrorType.UncompressingFailed, ErrorMessage = string.Format("解压错误: {0}:{1}:{2}", native.NS, native.Name, native.Version), Exception = exp }; } args.Server = options.Server; args.Size = options.Size; args.Libraries = options.Version.Libraries.Select(this.GetLibPath).ToList(); args.Libraries.Add(this.GetVersionJarPath(options.Version.JarId)); args.MinecraftArguments = options.Version.MinecraftArguments; args.Tokens.Add("auth_access_token", authentication.AccessToken.GoString()); args.Tokens.Add("auth_session", authentication.AccessToken.GoString()); args.Tokens.Add("auth_player_name", authentication.DisplayName); args.Tokens.Add("version_name", options.Version.Id); args.Tokens.Add("game_directory", "."); args.Tokens.Add("game_assets", "assets"); args.Tokens.Add("assets_root", "assets"); args.Tokens.Add("assets_index_name", options.Version.Assets); args.Tokens.Add("auth_uuid", authentication.UUID.GoString()); args.Tokens.Add("user_properties", authentication.Properties); args.Tokens.Add("user_type", authentication.UserType); args.AdvencedArguments = new List<string> {"-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true"}; args.Authentication = authentication; args.Version = options.Version; if (options.Mode != null) { options.Mode.Operate(this, args); } return null; } catch (Exception exp) { return new LaunchResult {Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "在生成参数时发生了意外的错误", Exception = exp}; } }
/// <summary> /// 启动函数 /// 过程: /// 1. 运行验证器(authenticator),出错返回null /// 2. 继续构造启动参数 /// 3. 遍历Operators对启动参数进行修改 /// 4. 启动 /// </summary> /// <param name="options">启动选项</param> /// <param name="argumentsOperators">启动参数的修改器</param> /// <returns>启动结果</returns> public LaunchResult Launch(LaunchOptions options, params Action <MinecraftLaunchArguments>[] argumentsOperators) { return(this.Report(LaunchInternal(options, argumentsOperators), options)); }
/// <summary> /// 启动函数 /// 过程: /// 1. 运行验证器(authenticator),出错返回null /// 2. 继续构造启动参数 /// 3. 遍历Operators对启动参数进行修改 /// 4. 启动 /// </summary> /// <param name="options">启动选项</param> /// <param name="argumentsOperators">启动参数的修改器</param> /// <returns>启动结果</returns> public LaunchResult Launch(LaunchOptions options, params Action<MinecraftLaunchArguments>[] argumentsOperators) { return this.Report(LaunchInternal(options, argumentsOperators), options); }