Exemple #1
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            var mc = new MinecraftPath(txtPath.Text);

            mc.Runtime = MinecraftPath.Runtime;
            mc.SetAssetsPath(Path.Combine(MinecraftPath.GetOSDefaultPath(), "assets"));
            apply(mc);
        }
Exemple #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (cbEditMore.Checked)
            {
                MinecraftPath.Library  = txtLibrary.Text;
                MinecraftPath.Runtime  = txtRuntime.Text;
                MinecraftPath.Versions = txtVersion.Text;

                // You have to call SetAssetsPath when you want to change assets directory to what you want.
                // SetAssetsPath change not only Assets property, but also AssetsLegacy, AssetsObject, Index property.
                if (txtAssets.Text != MinecraftPath.Assets)
                {
                    MinecraftPath.SetAssetsPath(txtAssets.Text);
                }
            }

            this.Close();
        }
        void StartWithAdvancedOptions(MSession session)
        {
            // game directory
            var defaultPath = MinecraftPath.GetOSDefaultPath();
            var path        = Path.Combine(Environment.CurrentDirectory, "game dir");

            // create minecraft path instance
            var minecraft = new MinecraftPath(path);

            minecraft.SetAssetsPath(Path.Combine(defaultPath, "assets")); // this speed up asset downloads

            // get all version metadatas
            // you can also use MVersionLoader.GetVersionMetadatasFromLocal and GetVersionMetadatasFromWeb
            var versionMetadatas = MVersionLoader.GetVersionMetadatas(minecraft);

            foreach (var item in versionMetadatas)
            {
                Console.WriteLine("Name : {0}", item.Name);
                Console.WriteLine("Type : {0}", item.Type);
                Console.WriteLine("Path : {0}", item.Path);
                Console.WriteLine("IsLocalVersion : {0}", item.IsLocalVersion);
                Console.WriteLine("============================================");
            }
            Console.WriteLine("");
            Console.WriteLine("LatestRelease : {0}", versionMetadatas.LatestReleaseVersion?.Name);
            Console.WriteLine("LatestSnapshot : {0}", versionMetadatas.LatestSnapshotVersion?.Name);

            Console.WriteLine("Input Version Name (ex: 1.15.2) : ");
            var versionName = Console.ReadLine();

            // get MVersion from MVersionMetadata
            var version = versionMetadatas.GetVersion(versionName);

            if (version == null)
            {
                Console.WriteLine("{0} is not exist", versionName);
                return;
            }

            Console.WriteLine("\n\nVersion Information : ");
            Console.WriteLine("Id : {0}", version.Id);
            Console.WriteLine("Type : {0}", version.TypeStr);
            Console.WriteLine("ReleaseTime : {0}", version.ReleaseTime);
            Console.WriteLine("AssetId : {0}", version.AssetId);
            Console.WriteLine("JAR : {0}", version.Jar);
            Console.WriteLine("Libraries : {0}", version.Libraries.Length);

            if (version.IsInherited)
            {
                Console.WriteLine("Inherited Profile from {0}", version.ParentVersionId);
            }

            // Download mode
            Console.WriteLine("\nSelect download mode : ");
            Console.WriteLine("(1) Sequence Download");
            Console.WriteLine("(2) Parallel Download");
            var downloadModeInput = Console.ReadLine();

            MDownloader downloader;

            if (downloadModeInput == "1")
            {
                downloader = new MDownloader(minecraft, version); // Sequence Download
            }
            else if (downloadModeInput == "2")
            {
                downloader = new MParallelDownloader(minecraft, version); // Parallel Download (note: Parallel Download is not stable yet)
            }
            else
            {
                Console.WriteLine("Input 1 or 2");
                Console.ReadLine();
                return;
            }

            downloader.ChangeFile     += Downloader_ChangeFile;
            downloader.ChangeProgress += Downloader_ChangeProgress;

            // Start download
            downloader.DownloadAll();

            Console.WriteLine("Download Completed.\n");

            // Set java
            Console.WriteLine("Input java path (empty input will download java) : ");
            var javaInput = Console.ReadLine();

            if (javaInput == "")
            {
                var java = new MJava();
                java.ProgressChanged += Downloader_ChangeProgress;
                javaInput             = java.CheckJava();
            }

            // LaunchOption
            var option = new MLaunchOption()
            {
                JavaPath     = javaInput,
                Session      = session,
                StartVersion = version,
                Path         = minecraft,

                MaximumRamMb = 4096,
                ScreenWidth  = 1600,
                ScreenHeight = 900,
            };

            // Launch
            var launch  = new MLaunch(option);
            var process = launch.GetProcess();

            Console.WriteLine(process.StartInfo.Arguments);
            process.Start();
            Console.WriteLine("Started");
            Console.ReadLine();
        }
        /// <summary>
        /// Launch minecraft
        /// </summary>
        /// <param name="session"></param>
        public void LaunchGame(MSession session)
        {
            moddedLauncher.SetStatusBar("Starting Minecraft", GetType(), StatusType.Launching);

            // Initializing Launcher

            // Set minecraft home directory
            // MinecraftPath.GetOSDefaultPath() return default minecraft BasePath of current OS.
            // https://github.com/AlphaBs/CmlLib.Core/blob/master/CmlLib/Core/MinecraftPath.cs

            // You can set this path to what you want like this :
            // var path = Environment.GetEnvironmentVariable("APPDATA") + "\\.mylauncher";
            var gamePath = configuration.GamePath;
            var game     = new MinecraftPath(configuration.ModpackPath)
            {
                Library  = Dir(gamePath + "/libraries"),
                Versions = Dir(gamePath + "/versions"),
                Runtime  = Dir(gamePath + "/runtime"),
            };

            game.SetAssetsPath(gamePath + "/assets");

            // Create CMLauncher instance
            var launcher = new CMLauncher(game);

            launcher.ProgressChanged += moddedLauncher.LauncherDownloadChangeProgress;
            launcher.FileChanged     += moddedLauncher.LauncherDownloadChangeFile;
            launcher.LogOutput       += (s, e) =>
            {
                Console.WriteLine("NO");
                moddedLauncher.GameOutputWriteLine(e);
            };
            moddedLauncher.GameOutputWriteLine($"Initialized in {launcher.MinecraftPath.BasePath}");

            var launchOption = new MLaunchOption
            {
                MaximumRamMb = configuration.Memory,
                Session      = session,
                ScreenHeight = configuration.ResolutionHeight,
                ScreenWidth  = configuration.ResolutionWidth,
                JVMArguments = configuration.JVMArgs.Split(" ")
                               // More options:
                               // https://github.com/AlphaBs/CmlLib.Core/wiki/MLaunchOption
            };

            // (A) checks forge installation and install forge if it was not installed.
            // (B) just launch any versions without installing forge, but it can still launch forge already installed.
            // Both methods automatically download essential files (ex: vanilla libraries) and create game process.
            moddedLauncher.SetStatusBar("Minecraft Starting", GetType(), StatusType.Launching);

            // (A) download forge and launch
            var process = launcher.CreateProcess("1.12.2", "14.23.5.2854", launchOption);

            // (B) launch vanilla version
            // var process = launcher.CreateProcess("1.15.2", launchOption);

            // If you have already installed forge, you can launch it directly like this.
            // var process = launcher.CreateProcess("1.12.2-forge1.12.2-14.23.5.2838", launchOption);

            // launch by user input
            //Console.WriteLine("input version (example: 1.12.2) : ");
            //var process = launcher.CreateProcess(Console.ReadLine(), launchOption);
            moddedLauncher.SetStatusBar("Minecraft Starting", GetType(), StatusType.Launching);

            //var process = launcher.CreateProcess("1.16.2", "33.0.5", launchOption);
            WriteLine(process.StartInfo.Arguments);

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                Thread.Sleep(TimeSpan.FromSeconds(30));
                moddedLauncher.SetStatusBar("Minecraft Started", GetType(), StatusType.Ready);
            }).Start();



            // Below codes are print game logs in Console.
            var processUtil = new CmlLib.Utils.ProcessUtil(process);

            processUtil.OutputReceived += (s, e) =>
            {
                if (!string.IsNullOrEmpty(e))
                {
                    moddedLauncher.GameOutputWriteLine(e);
                }
            };
            processUtil.StartWithEvents();
            process.WaitForExit();

            // or just start it without print logs
            // process.Start();

            Console.ReadLine();

            return;
        }