public static async Task LaunchGameAsync(FileManager.Modpacks modpack)
        {
            try
            {
                var path     = new MinecraftPath(Directory.GetCurrentDirectory() + $@"\Launcher\{modpack}");
                var launcher = new CMLauncher(path);


                // more options : https://github.com/AlphaBs/CmlLib.Core/wiki/MLaunchOption
                var launchOption = new MLaunchOption
                {
                    MaximumRamMb = Settings.RAM,
                    Session      = SESSION
                };

                forgeVersion = File.ReadAllText($"Launcher/{modpack}/Forge Version.txt");
                var process = await launcher.CreateProcessAsync(forgeVersion, launchOption);

                process.Start();
            }
            catch (Exception)
            {
                main.GetError($"Failed Launching {modpack}!");
            }
        }
Exemplo n.º 2
0
        async Task StartAsync(MSession session) // async version
        {
            var path     = new MinecraftPath();
            var launcher = new CMLauncher(path);

            System.Net.ServicePointManager.DefaultConnectionLimit = 256;

            var versions = await launcher.GetAllVersionsAsync();

            foreach (var item in versions)
            {
                Console.WriteLine(item.Type + " " + item.Name);
            }

            launcher.FileChanged     += Downloader_ChangeFile;
            launcher.ProgressChanged += Downloader_ChangeProgress;

            Console.WriteLine("input version (example: 1.12.2) : ");
            var versionName = Console.ReadLine();
            var process     = await launcher.CreateProcessAsync(versionName, new MLaunchOption
            {
                Session      = session,
                MaximumRamMb = 1024
            });

            Console.WriteLine(process.StartInfo.Arguments);
            process.Start();
        }
Exemplo n.º 3
0
        async Task Start(MSession session)
        {
            var path = MinecraftPath.GetOSDefaultPath();
            var game = new MinecraftPath(path);

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

            // if you want to download with parallel downloader, add below code :
            System.Net.ServicePointManager.DefaultConnectionLimit = 256;

            launcher.ProgressChanged += Downloader_ChangeProgress;
            launcher.FileChanged     += Downloader_ChangeFile;

            Console.WriteLine($"{launcher.MinecraftPath.BasePath} adresine kuruldu.");

            // Get all installed profiles and load all profiles from mojang server
            var versions = await launcher.GetAllVersionsAsync();

            foreach (var item in versions) // Display all profiles
            {
                // You can filter snapshots and old versions to add if statement :
                if (item.MType == CmlLib.Core.Version.MVersionType.Release || item.MType == CmlLib.Core.Version.MVersionType.Custom)
                {
                    List <string> list = new List <string> {
                        item.Type + " " + item.Name
                    };

                    list.ForEach(i => Console.Write("{0}\n", i));
                }
            }

            var launchOption = new MLaunchOption
            {
                MaximumRamMb = 1024,
                Session      = session,
            };


            Console.WriteLine("Versiyon yazın (örnek 1.12.2): ");
            var process = await launcher.CreateProcessAsync(Console.ReadLine(), launchOption);

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

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

            processUtil.OutputReceived += (s, e) => Console.WriteLine(e);
            processUtil.StartWithEvents();
            process.WaitForExit();

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

            Console.ReadLine();
            return;
        }
Exemplo n.º 4
0
        // this code is from README.md

        async Task QuickStart()
        {
            //var path = new MinecraftPath("game_directory_path");
            var path = new MinecraftPath(); // use default directory

            var launcher = new CMLauncher(path);

            launcher.FileChanged += (e) =>
            {
                Console.WriteLine("[{0}] {1} - {2}/{3}", e.FileKind.ToString(), e.FileName, e.ProgressedFileCount, e.TotalFileCount);
            };
            launcher.ProgressChanged += (s, e) =>
            {
                Console.WriteLine("{0}%", e.ProgressPercentage);
            };

            var versions = await launcher.GetAllVersionsAsync();

            foreach (var item in versions)
            {
                Console.WriteLine(item.Name);
            }

            var launchOption = new MLaunchOption
            {
                MaximumRamMb = 1024,
                Session      = MSession.GetOfflineSession("hello"), // Login Session. ex) Session = MSession.GetOfflineSession("hello")

                //ScreenWidth = 1600,
                //ScreenHeigth = 900,
                //ServerIp = "mc.hypixel.net"
            };

            // launch vanila
            var process = await launcher.CreateProcessAsync("1.15.2", launchOption);

            process.Start();
        }
Exemplo n.º 5
0
        // Start Game
        private async void Btn_Launch_Click(object sender, EventArgs e)
        {
            if (session == null)
            {
                MessageBox.Show("Login First");
                return;
            }

            if (cbVersion.Text == "")
            {
                MessageBox.Show("Select Version");
                return;
            }

            // disable ui
            setUIEnabled(false);

            try
            {
                // create LaunchOption
                var launchOption = new MLaunchOption()
                {
                    MaximumRamMb = int.Parse(TxtXmx.Text),
                    Session      = this.session,

                    VersionType         = Txt_VersionType.Text,
                    GameLauncherName    = Txt_GLauncherName.Text,
                    GameLauncherVersion = Txt_GLauncherVersion.Text,

                    FullScreen = cbFullscreen.Checked,

                    ServerIp = Txt_ServerIp.Text,

                    DockName = Txt_DockName.Text,
                    DockIcon = Txt_DockIcon.Text
                };

                if (!string.IsNullOrEmpty(javaPath))
                {
                    launchOption.JavaPath = javaPath;
                }

                if (!string.IsNullOrEmpty(txtXms.Text))
                {
                    launchOption.MinimumRamMb = int.Parse(txtXms.Text);
                }

                if (!string.IsNullOrEmpty(Txt_ServerPort.Text))
                {
                    launchOption.ServerPort = int.Parse(Txt_ServerPort.Text);
                }

                if (!string.IsNullOrEmpty(Txt_ScWd.Text) && !string.IsNullOrEmpty(Txt_ScHt.Text))
                {
                    launchOption.ScreenHeight = int.Parse(Txt_ScHt.Text);
                    launchOption.ScreenWidth  = int.Parse(Txt_ScWd.Text);
                }

                if (!string.IsNullOrEmpty(Txt_JavaArgs.Text))
                {
                    launchOption.JVMArguments = Txt_JavaArgs.Text.Split(' ');
                }

                if (rbParallelDownload.Checked)
                {
                    System.Net.ServicePointManager.DefaultConnectionLimit = 256;
                    launcher.FileDownloader = new AsyncParallelDownloader();
                }
                else
                {
                    launcher.FileDownloader = new SequenceDownloader();
                }

                // check file hash or don't check
                launcher.GameFileCheckers.AssetFileChecker.CheckHash   = cbSkipHashCheck.Checked;
                launcher.GameFileCheckers.ClientFileChecker.CheckHash  = cbSkipHashCheck.Checked;
                launcher.GameFileCheckers.LibraryFileChecker.CheckHash = cbSkipHashCheck.Checked;

                if (cbSkipAssetsDownload.Checked)
                {
                    launcher.GameFileCheckers.AssetFileChecker = null;
                }

                var process = await launcher.CreateProcessAsync(cbVersion.Text, launchOption); // Create Arguments and Process

                // process.Start(); // Just start game, or
                StartProcess(process);  // Start Process with debug options
            }
            catch (FormatException fex) // int.Parse exception
            {
                MessageBox.Show("Failed to create MLaunchOption\n\n" + fex);
            }
            catch (MDownloadFileException mex) // download exception
            {
                MessageBox.Show(
                    $"FileName : {mex.ExceptionFile.Name}\n" +
                    $"FilePath : {mex.ExceptionFile.Path}\n" +
                    $"FileUrl : {mex.ExceptionFile.Url}\n" +
                    $"FileType : {mex.ExceptionFile.Type}\n\n" +
                    mex.ToString());
            }
            catch (Win32Exception wex) // java exception
            {
                MessageBox.Show(wex + "\n\nIt seems your java setting has problem");
            }
            catch (Exception ex) // all exception
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                // re open log form
                if (logForm != null)
                {
                    logForm.Close();
                }

                logForm = new GameLog();
                logForm.Show();

                // enable ui
                setUIEnabled(true);
            }
        }