예제 #1
0
        /// <summary>
        /// Build game process and return it
        /// </summary>
        public Process GetProcess()
        {
            var native = new MNative(LaunchOption);

            native.CleanNatives();
            native.CreateNatives();

            string  arg = string.Join(" ", CreateArg());
            Process mc  = new Process();

            mc.StartInfo.FileName         = LaunchOption.JavaPath;
            mc.StartInfo.Arguments        = arg;
            mc.StartInfo.WorkingDirectory = Minecraft.path;

            return(mc);
        }
예제 #2
0
        public string[] CreateArg()
        {
            MVersion version = LaunchOption.GetStartVersion();

            var args = new List <string>();

            // Common JVM Arguments
            if (LaunchOption.JVMArguments != null)
            {
                args.AddRange(LaunchOption.JVMArguments);
            }
            else
            {
                args.AddRange(DefaultJavaParameter);

                if (LaunchOption.MaximumRamMb > 0)
                {
                    args.Add("-Xmx" + LaunchOption.MaximumRamMb + "m");
                }

                if (LaunchOption.MinimumRamMb > 0)
                {
                    args.Add("-Xms" + LaunchOption.MinimumRamMb + "m");
                }
            }

            if (!string.IsNullOrEmpty(LaunchOption.DockName))
            {
                args.Add("-Xdock:name=" + handleEmpty(LaunchOption.DockName));
            }
            if (!string.IsNullOrEmpty(LaunchOption.DockIcon))
            {
                args.Add("-Xdock:icon=" + handleEmpty(LaunchOption.DockIcon));
            }

            // Version-specific JVM Arguments
            var classpath = new List <string>(version.Libraries?.Length ?? 1);

            if (version.Libraries != null)
            {
                var libraries = version.Libraries
                                .Where(lib => lib.IsRequire && !lib.IsNative && !string.IsNullOrEmpty(lib.Path))
                                .Select(lib => Path.GetFullPath(Path.Combine(minecraftPath.Library, lib.Path !)));
                classpath.AddRange(libraries);
            }

            if (!string.IsNullOrEmpty(version.Jar))
            {
                classpath.Add(minecraftPath.GetVersionJarPath(version.Jar));
            }

            var classpathStr = IOUtil.CombinePath(classpath.ToArray());

            var native = new MNative(minecraftPath, version);

            native.CleanNatives();
            var nativePath = native.ExtractNatives();

            var jvmdict = new Dictionary <string, string?>
            {
                { "natives_directory", nativePath },
                { "launcher_name", useNotNull(LaunchOption.GameLauncherName, "minecraft-launcher") },
                { "launcher_version", useNotNull(LaunchOption.GameLauncherVersion, "2") },
                { "classpath", classpathStr }
            };

            if (version.JvmArguments != null)
            {
                args.AddRange(Mapper.MapInterpolation(version.JvmArguments, jvmdict));
            }
            else
            {
                args.Add("-Djava.library.path=" + handleEmpty(nativePath));
                args.Add("-cp " + classpathStr);
            }

            if (!string.IsNullOrEmpty(version.MainClass))
            {
                args.Add(version.MainClass);
            }

            // Game Arguments
            MSession session  = LaunchOption.GetSession();
            var      gameDict = new Dictionary <string, string?>
            {
                { "auth_player_name", session.Username },
                { "version_name", version.Id },
                { "game_directory", minecraftPath.BasePath },
                { "assets_root", minecraftPath.Assets },
                { "assets_index_name", version.AssetId ?? "legacy" },
                { "auth_uuid", session.UUID },
                { "auth_access_token", session.AccessToken },
                { "user_properties", "{}" },
                { "user_type", "Mojang" },
                { "game_assets", minecraftPath.GetAssetLegacyPath(version.AssetId ?? "legacy") },
                { "auth_session", session.AccessToken },
                { "version_type", useNotNull(LaunchOption.VersionType, version.TypeStr) }
            };

            if (version.GameArguments != null)
            {
                args.AddRange(Mapper.MapInterpolation(version.GameArguments, gameDict));
            }
            else if (!string.IsNullOrEmpty(version.MinecraftArguments))
            {
                args.AddRange(Mapper.MapInterpolation(version.MinecraftArguments.Split(' '), gameDict));
            }

            // Options
            if (!string.IsNullOrEmpty(LaunchOption.ServerIp))
            {
                args.Add("--server " + handleEmpty(LaunchOption.ServerIp));

                if (LaunchOption.ServerPort != DefaultServerPort)
                {
                    args.Add("--port " + LaunchOption.ServerPort);
                }
            }

            if (LaunchOption.ScreenWidth > 0 && LaunchOption.ScreenHeight > 0)
            {
                args.Add("--width " + LaunchOption.ScreenWidth);
                args.Add("--height " + LaunchOption.ScreenHeight);
            }

            if (LaunchOption.FullScreen)
            {
                args.Add("--fullscreen");
            }

            return(args.ToArray());
        }