void TestStartSync(MSession session) { var path = new MinecraftPath(); var launcher = new CMLauncher(path); launcher.FileChanged += Downloader_ChangeFile; launcher.ProgressChanged += Downloader_ChangeProgress; var versions = launcher.GetAllVersions(); foreach (var item in versions) { Console.WriteLine(item.Name); } var process = launcher.CreateProcess("1.5.2", new MLaunchOption { Session = session }); var processUtil = new CmlLib.Utils.ProcessUtil(process); processUtil.OutputReceived += (s, e) => Console.WriteLine(e); processUtil.StartWithEvents(); }
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; }
async Task TestAll(MSession session) { var path = MinecraftPath.GetOSDefaultPath(); var game = new MinecraftPath(path); var launcher = new CMLauncher(game); System.Net.ServicePointManager.DefaultConnectionLimit = 256; launcher.FileDownloader = new AsyncParallelDownloader(); launcher.ProgressChanged += Downloader_ChangeProgress; launcher.FileChanged += Downloader_ChangeFile; Console.WriteLine($"Initialized in {launcher.MinecraftPath.BasePath}"); var launchOption = new MLaunchOption { MaximumRamMb = 1024, Session = session, }; var versions = await launcher.GetAllVersionsAsync(); foreach (var item in versions) { Console.WriteLine(item.Type + " " + item.Name); if (!item.IsLocalVersion) { continue; } var process = launcher.CreateProcess(item.Name, 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(); Thread.Sleep(1000 * 15); if (process.HasExited) { Console.WriteLine("FAILED!!!!!!!!!"); Console.ReadLine(); } process.Kill(); process.WaitForExit(); } return; }
void Start(MSession session) { // 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 path = MinecraftPath.GetOSDefaultPath(); var game = new MinecraftPath(path); // Create CMLauncher instance var launcher = new CMLauncher(game); launcher.ProgressChanged += Downloader_ChangeProgress; launcher.FileChanged += Downloader_ChangeFile; launcher.LogOutput += (s, e) => Console.WriteLine(e); Console.WriteLine($"Initialized in {launcher.MinecraftPath.BasePath}"); var versions = launcher.GetAllVersions(); // Get all installed profiles and load all profiles from mojang server foreach (var item in versions) // Display all profiles { // You can filter snapshots and old versions to add if statement : // if (item.MType == MProfileType.Custom || item.MType == MProfileType.Release) Console.WriteLine(item.Type + " " + item.Name); } var launchOption = new MLaunchOption { MaximumRamMb = 1024, Session = session, // 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. // (A) download forge and launch var process = launcher.CreateProcess("1.7.10", "10.13.4.1614", 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); //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; }
/// <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; }
void Start(MSession session) { // 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 = "./testdir"; 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($"Initialized in {launcher.MinecraftPath.BasePath}"); // Get all installed profiles and load all profiles from mojang server var versions = launcher.GetAllVersions(); foreach (var item in versions) // Display all profiles { // You can filter snapshots and old versions to add if statement : // if (item.MType == MProfileType.Custom || item.MType == MProfileType.Release) Console.WriteLine(item.Type + " " + item.Name); } var launchOption = new MLaunchOption { MaximumRamMb = 1024, Session = session, //ScreenWidth = 1600, //ScreenHeight = 900, //ServerIp = "mc.hypixel.net", //MinimumRamMb = 102, //FullScreen = true, // More options: // https://github.com/AlphaBs/CmlLib.Core/wiki/MLaunchOption }; // download essential files (ex: vanilla libraries) and create game process. // var process = await launcher.CreateProcessAsync("1.15.2", launchOption); // vanilla // var process = await launcher.CreateProcessAsync("1.12.2-forge1.12.2-14.23.5.2838", launchOption); // forge // var process = await launcher.CreateProcessAsync("1.12.2-LiteLoader1.12.2"); // liteloader // var process = await launcher.CreateProcessAsync("fabric-loader-0.11.3-1.16.5") // fabric-loader Console.WriteLine("input version (example: 1.12.2) : "); var process = launcher.CreateProcess(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(); }