Example #1
0
        public LaunchResult Launch(LaunchOptionBase launchOption, params Action <MinecraftLaunchArguments>[] argumentsOperators)
        {
            if (UserAuthenticator == null)
            {
                FailedResult.ErrorType    = ErrorType.AuthenticationFailed;
                FailedResult.ErrorMessage = "User authenticator no set";
                Console.WriteLine("ERROR: User authenticator no set");
                return(FailedResult);
            }
            if (launchOption == null)
            {
                Console.WriteLine("ERROR: Launch message is null");
                FailedResult.ErrorMessage = "Launch message is null";
                return(FailedResult);
            }

            Core.JavaPath = launchOption.javaExt;

            //LaunchOptions in KMCCC, different with LaunchOption in OneMCL.Core
            LaunchOptions options = new LaunchOptions()
            {
                Version       = Core.GetVersion(launchOption.versionId),
                Authenticator = UserAuthenticator,
                GameDirPath   = string.IsNullOrEmpty(launchOption.gameDir) ? Core.GameRootPath : launchOption.gameDir,
            };

            Console.WriteLine("Launching...");

            int argsCount = 0;

            if (argumentsOperators != null)
            {
                argsCount = argumentsOperators.Length;
            }
            Action <MinecraftLaunchArguments>[] argsOpt = new Action <MinecraftLaunchArguments> [argsCount + 1];
            argsOpt[0] = (Action <MinecraftLaunchArguments>)(args =>
            {
                args.AdvencedArguments.Add(launchOption.javaArgs);
                System.Version osVersion = Environment.OSVersion.Version;
                args.AdvencedArguments.Add("-Dos.name=\"" + GetSystemVersionName(osVersion.Major, osVersion.Minor) + "\"");
                args.AdvencedArguments.Add("-Dos.version=" + osVersion.Major + "." + osVersion.Minor);
                args.AdvencedArguments.Add("-Dminecraft.launcher.brand=one-minecraft-launcher");
                //args.AdvencedArguments.Add("-Dminecraft.launcher.version=");
                args.AdvencedArguments.Add("-Dminecraft.client.jar=" + Core.GetVersionJarPath(options.Version));
                //args.AdvencedArguments.Add("-Dlog4j.configurationFile=");
            });
            argumentsOperators?.CopyTo(argsOpt, 1);
            return(Core.Launch(options, argsOpt));
        }
Example #2
0
        public static void VLW(Window window, string username, string password, string memory, string path, bool fullScreen)
        {
            LauncherCore core   = LauncherCore.Create();
            var          option = new LaunchOptions
            {
                Version   = core.GetVersion(VersionName),
                MaxMemory = Convert.ToInt32(memory),
                Mode      = LaunchMode.MCLauncher,
                Size      = new WindowSize
                {
                    Height = (ushort?)(Gdk.Screen.Default.Height / 2),
                    Width  = (ushort?)(Gdk.Screen.Default.Width / 2)
                }
            };

            if (fullScreen)
            {
                option.Size.FullScreen = true;
            }
#if ENABLE_TONGYI_AUTHENTICATION
            option.AgentPath     = "nide8auth.jar=" + ServerTongyiStr; // Chinese Third-party Authentication System: Minecraft 统一通行证
            option.Authenticator = new YggdrasilLogin(username, password, true, null, "https://auth2.nide8.com:233/" + ServerTongyiStr + "/authserver");
#else
            option.Authenticator = new OfflineAuthenticator(username);
#endif
            if (ServerIP.Length != 0)
            {
                option.Server = new ServerInfo {
                    Address = ServerIP, Port = ServerPort
                }
            }
            ;
            var result = core.Launch(option);
            if (!result.Success)
            {
                MessageDialog messageDialog;
                switch (result.ErrorType)
                {
                case ErrorType.NoJAVA:
                    messageDialog = new MessageDialog(window, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Java Error, try to reinstall the client.")
                    {
                        Title = "Java Error"
                    };
                    break;

                case ErrorType.AuthenticationFailed:
                    messageDialog = new MessageDialog(window, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Please check your username and password.")
                    {
                        Title = "Profile Error"
                    };
                    break;

                case ErrorType.UncompressingFailed:
                    messageDialog = new MessageDialog(window, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Decompressing Failed!\n\nCheck your client or reinstall.")
                    {
                        Title = "Decompression Failure"
                    };
                    break;

                default:
                    messageDialog = new MessageDialog(window, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, result.ErrorMessage + "\n" + (result.Exception == null ? string.Empty : result.Exception.StackTrace))
                    {
                        Title = "Unknown Error"
                    };
                    break;
                }
                messageDialog.Run();
            }
            Thread.Sleep(50);
        }
    }