Пример #1
0
 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);
     }
 }
Пример #2
0
		public override bool Operate(LauncherCore core, MinecraftLaunchArguments args)
		{
			core.CopyVersionDirectory("mods", args.Version.Id);
			core.CopyVersionDirectory("coremods", args.Version.Id);
			core.CopyVersionDirectories(core.GetVersionRootPath(args.Version));
			return true;
		}
Пример #3
0
 private LaunchResult LaunchGame(MinecraftLaunchArguments args)
 {
     try
     {
         var handle = new LaunchHandle(args.Authentication)
         {
             Code      = CurrentCode,
             Core      = this,
             Arguments = args,
             Process   = Process.Start(new ProcessStartInfo(JavaPath)
             {
                 Arguments              = args.ToArguments(),
                 UseShellExecute        = false,
                 WorkingDirectory       = GameRootPath,
                 RedirectStandardError  = true,
                 RedirectStandardOutput = true
             })
         };
         handle.Work();
         Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
         return(new LaunchResult {
             Success = true, Handle = handle
         });
     }
     catch (Exception exp)
     {
         return(new LaunchResult {
             Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "启动时出现了异常", Exception = exp
         });
     }
 }
Пример #4
0
 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));
     }
 }
Пример #5
0
 public override bool Operate(LauncherCore core, MinecraftLaunchArguments args)
 {
     return(_operatorMethod.Invoke(core, args));
 }
Пример #6
0
 public override bool Operate(LauncherCore core, MinecraftLaunchArguments args)
 {
     args.Tokens["game_directory"] = Tools.SystemTools.GetIsWindows() ? String.Format(@".\versions\{0}\", args.Version.Id) : String.Format(core.GameRootPath + "/versions/{0}/", args.Version.Id);
     return(true);
 }
Пример #7
0
 /// <summary>
 ///     启动模式
 /// </summary>
 /// <returns>模式是否应用成功</returns>
 public abstract bool Operate(LauncherCore core, MinecraftLaunchArguments args);
Пример #8
0
		public override bool Operate(LauncherCore core, MinecraftLaunchArguments args)
		{
			return _operatorMethod.Invoke(core, args);
		}
Пример #9
0
		public override bool Operate(LauncherCore core, MinecraftLaunchArguments args)
		{
			args.Tokens["game_directory"] = String.Format(@".\versions\{0}\", args.Version.Id);
			return true;
		}
Пример #10
0
		/// <summary>
		///     启动模式
		/// </summary>
		/// <returns>模式是否应用成功</returns>
		public abstract bool Operate(LauncherCore core, MinecraftLaunchArguments args);
Пример #11
0
        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
                });
            }
        }
Пример #12
0
		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};
			}
		}
Пример #13
0
		private LaunchResult LaunchGame(MinecraftLaunchArguments args)
		{
			try
			{
				var handle = new LaunchHandle(args.Authentication)
				{
					Code = CurrentCode,
					Core = this,
					Arguments = args,
					Process = Process.Start(new ProcessStartInfo(JavaPath)
					{
						Arguments = args.ToArguments(),
						UseShellExecute = false,
						WorkingDirectory = GameRootPath,
						RedirectStandardError = true,
						RedirectStandardOutput = true
					})
				};
				handle.Work();
				Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
				return new LaunchResult {Success = true, Handle = handle};
			}
			catch (Exception exp)
			{
				return new LaunchResult {Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "启动时出现了异常", Exception = exp};
			}
		}
Пример #14
0
 public override bool Operate(LauncherCore core, MinecraftLaunchArguments args)
 {
     args.Tokens["game_directory"] = String.Format(@".\versions\{0}\", args.Version.Id);
     return(true);
 }