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(); }
private void btnStart_Click(object sender, EventArgs e) { btnLogin.Enabled = false; btnSignout.Enabled = false; btnStart.Enabled = false; new Thread(() => { try { var path = new MinecraftPath(); var launcher = new CMLauncher(path); launcher.FileChanged += Launcher_FileChanged; launcher.ProgressChanged += Launcher_ProgressChanged; var versions = launcher.GetAllVersions(); var lastVersion = versions.LatestReleaseVersion; var process = launcher.CreateProcess(lastVersion.Name, new MLaunchOption() { Session = this.session }); process.Start(); MessageBox.Show("Success"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }).Start(); }
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; }
private void LaunchClick(object sender, RoutedEventArgs e) { LaunchProgress.Opacity = 100; var th = new Thread(new ThreadStart(delegate { string selectedver = ""; Application.Current.Dispatcher.Invoke((Action) delegate { LaunchButton.IsEnabled = false; selectedver = versionList.Text; }); var ThisThreadOptions = new MLaunchOption(); Application.Current.Dispatcher.Invoke(delegate { int screenHeight = 0; int screenWidth = 0; int MaxRamMB = Convert.ToInt32(MaxMemSlider.Value); try { screenHeight = Convert.ToInt32(ScreenHeightBox.Text); screenWidth = Convert.ToInt32(ScreenWidthBox.Text); } catch { screenHeight = 0; screenWidth = 0; } var launchOptions = new MLaunchOption { JavaPath = JavaPathBox.Text, ServerIp = ServerIPBox.Text, ScreenHeight = screenHeight, ScreenWidth = screenWidth, MaximumRamMb = MaxRamMB, Session = MainSession, JVMArguments = CustomArgsBox.Text.Split(" ") }; ThisThreadOptions = launchOptions; }); CMLauncher launcher = new CMLauncher(Minecraft.GetOSDefaultPath()); launcher.ProgressChanged += Launcher_ProgressChanged; launcher.FileChanged += Launcher_FileChanged; var process = launcher.CreateProcess(selectedver, ThisThreadOptions); process.Start(); Application.Current.Dispatcher.Invoke((Action) delegate { LaunchButton.IsEnabled = true; LaunchProgress.Visibility = Visibility.Hidden; LaunchLog.Visibility = Visibility.Hidden; }); })); th.Start(); }
private void LaunchGame() { ThreadPool.QueueUserWorkItem((Task) => { MLaunchOption Options = new MLaunchOption() { MaximumRamMb = 2048, Session = CurrentSession, ServerIp = "45.23.44.208" }; Process Proc = CMLauncher.CreateProcess("1.16.3", "34.1.11", Options); Proc.Start(); }); }
public string Launch(string username, string password, int memory, string version, bool fullScreen) { var account = new MLogin().Authenticate(username, password); if (!account.IsSuccess) { return(account.Result.ToString() + '\n' + account.ErrorMessage); } var session = account.Session; var mcp = new MinecraftPath(Path.Combine(Utility.GetWorkingDir(), ".minecraft")); ChangeOption(mcp.BasePath, Thread.CurrentThread.CurrentUICulture.Name.Replace('-', '_').ToLower()); var launcher = new CMLauncher(mcp); launcher.FileChanged += (e) => { LFileKind = e.FileKind.ToString(); LFileName = e.FileName; LProgressedFileCnt = e.ProgressedFileCount.ToString(); LTotFileCnt = e.TotalFileCount.ToString(); }; launcher.ProgressChanged += (sender, e) => { LProgressPercentage = e.ProgressPercentage.ToString(); }; var launchOption = new MLaunchOption { MaximumRamMb = memory, Session = session, FullScreen = fullScreen, ServerIp = "124.71.131.172", ServerPort = 25565, JavaPath = Utility.GetJava(launcher), JVMArguments = new string[] { "-javaagent:../nide8auth.jar=28f8f58a8a7f11e88feb525400b59b6a", "-Dnide8auth.client=true" } }; var process = launcher.CreateProcess(version, launchOption); Console.WriteLine("[Launch] FileName: " + process.StartInfo.FileName); Console.WriteLine("[Launch] Arguments: " + process.StartInfo.Arguments); Console.WriteLine("[Launch] WorkingDirectory: " + process.StartInfo.WorkingDirectory); process.Start(); return(string.Empty); }
// this code is from README.md void 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); }; foreach (var item in launcher.GetAllVersions()) { 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 = launcher.CreateProcess("1.15.2", launchOption); process.Start(); }
private async void Window_Loaded(object sender, RoutedEventArgs e) { DoubleAnimation OpacityAnimation = new DoubleAnimation(); OpacityAnimation.From = this.Opacity; OpacityAnimation.To = 1; OpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); this.BeginAnimation(Window.OpacityProperty, OpacityAnimation); await Task.Delay(300); if (!File.Exists(TotalPath + @"/Storage/Stream/MinecraftVersion")) { try { using (SftpClient Client = new SftpClient("bedrock-project.ru", "root", "singularity")) { Client.Connect(); using (Stream fileStream = File.Create(Environment.CurrentDirectory + @"/Storage/Stream/MinecraftVersion")) { Client.DownloadFile("/launcher/Storage/Stream/MinecraftVersion", fileStream); } } } catch { } } string MinecraftVersion; try { FileStream FileStream = new FileStream(TotalPath + @"/Storage/Stream/MinecraftVersion", FileMode.Open, FileAccess.Read); using (var StreamReader = new StreamReader(FileStream, Encoding.UTF8)) { MinecraftVersion = StreamReader.ReadToEnd(); MinecraftVersion = MinecraftVersion.Trim(); if (MinecraftVersion == null) { MinecraftVersion = "1.16.4"; } } } catch { MinecraftVersion = "1.16.4"; } MSession MSession; if (Nickname != null) { MSession = MSession.GetOfflineSession(Nickname); } else { MSession = MSession.GetOfflineSession("Steve"); } var LaunchOption = new MLaunchOption { MinimumRamMb = 512, MaximumRamMb = 1024, Session = MSession, ScreenWidth = 1920, ScreenHeight = 1080, ServerIp = IP, FullScreen = true }; try { System.Diagnostics.Process Process = Launcher.CreateProcess(MinecraftVersion, LaunchOption); Process.Start(); } catch { string PATH = new MinecraftPath() + @"\versions\" + MinecraftVersion; Directory.Delete(PATH, true); System.Diagnostics.Process Process = Launcher.CreateProcess(MinecraftVersion, LaunchOption); Process.Start(); } // launch forge (already installed) // var process = launcher.CreateProcess("1.16.2-forge-33.0.5", launchOption); // launch forge (install forge if not installed) // var process = launcher.CreateProcess("1.16.2", "33.0.5", launchOption); DoubleAnimation WidthAnimation = new DoubleAnimation(); WidthAnimation.From = LoadProgress.Opacity; WidthAnimation.To = 320; WidthAnimation.Duration = TimeSpan.FromSeconds(2); LoadProgress.BeginAnimation(Rectangle.WidthProperty, WidthAnimation); await Task.Delay(2000); OpacityAnimation.From = this.Opacity; OpacityAnimation.To = 0; OpacityAnimation.Duration = TimeSpan.FromSeconds(0.3); this.BeginAnimation(Window.OpacityProperty, OpacityAnimation); await Task.Delay(1000); this.Close(); }
public Process Start(Server server) { System.Net.ServicePointManager.DefaultConnectionLimit = 256; var game = new MinecraftPath(path); var launcher = new CMLauncher(game); launcher.ProgressChanged += Download_Progress; launcher.FileChanged += Download_ChangeFile; string version = ""; if (server.TYPE == "forge") { version = FindForgeVersion(server.VERSION); if (version == "") { return(null); } } else { version = server.VERSION; } var lv = new LocalVersionLoader(game).GetVersionMetadatas(); var findVersion = lv.GetVersion(version); if (findVersion == null) { var findMVersion = lv.GetVersionMetadata(version); if (findMVersion != null) { findMVersion.Save(game); } else { var findWVersion = new MojangVersionLoader().GetVersionMetadatas().GetVersionMetadata(version); if (findWVersion != null) { findWVersion.Save(game); } else { return(null); } } } var launchOption = new MLaunchOption { ServerIp = server.IP, ServerPort = server.PORT, MaximumRamMb = ram, Session = se, Path = game, StartVersion = findVersion, GameLauncherName = "JML", GameLauncherVersion = "1.0" }; var process = launcher.CreateProcess(launchOption); process.Start(); return(process); }
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; }
private void Btn_Launch_Click(object sender, EventArgs e) { // Launch if (Session == null) { MessageBox.Show("Login First"); return; } if (Cb_Version.Text == "") { return; } groupBox1.Enabled = false; groupBox2.Enabled = false; try { var version = Cb_Version.Text; var forge = ""; if (Cb_Forge.Checked) { forge = Txt_ForgeVersion.Text; } var launchOption = new MLaunchOption() { JavaPath = Txt_Java.Text, MaximumRamMb = int.Parse(Txt_Ram.Text), Session = this.Session, VersionType = Txt_VersionType.Text, GameLauncherName = Txt_GLauncherName.Text, GameLauncherVersion = Txt_GLauncherVersion.Text, ServerIp = Txt_ServerIp.Text, DockName = Txt_DockName.Text, DockIcon = Txt_DockIcon.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(' '); } var th = new Thread(() => { Process mc; if (string.IsNullOrEmpty(forge)) { mc = Launcher.CreateProcess(version, launchOption); // vanilla } else { mc = Launcher.CreateProcess(version, forge, launchOption); // forge } StartProcess(mc); }); th.Start(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { var fWork = new Action(() => { if (logForm != null) { logForm.Close(); } logForm = new GameLog(); logForm.Show(); groupBox1.Enabled = true; groupBox2.Enabled = true; }); if (this.InvokeRequired) { this.Invoke(fWork); } else { fWork.Invoke(); } } }
/// <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(); }