private void LaunchButton_Click(object sender, EventArgs e) { string sptxt = Data.serverIP; if (!string.IsNullOrEmpty(sptxt)) { File.WriteAllText("mars_client\\serverip.ser", sptxt); } else { File.WriteAllText("mars_client\\serverip.ser", ""); } object _version = Data.versionString; if (_version == null) { MessageBox.Show("Please select a version!", "Mars", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string version = (string)_version; File.WriteAllText("mars_client\\version.ser", version); CMLauncher launcher = Data.launcher; bool forge = version.ToLower().Contains("forge"); OutputManager.ShowConsoleWindow(true); Console.WriteLine("[MARS] Setting up launch arguments... Please wait!"); MSession ssh; if (!Data.offline) { ssh = new MSession(); Type editor = typeof(MSession); editor.GetField("<ClientToken>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ssh, Data.clientToken); editor.GetField("<AccessToken>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ssh, Data.accessToken); editor.GetField("<Username>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ssh, Data.username); editor.GetField("<UUID>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(ssh, Data.mcUUID); } else { string username = Data.username; ssh = MSession.GetOfflineSession(username); } Console.WriteLine("[MARS] Successfully created session."); MLaunchOption options = new MLaunchOption() { JavaPath = "java.exe", MaximumRamMb = GetInstalledMemoryMB() / 2, Session = ssh, VersionType = version, GameLauncherName = "MarsClient", GameLauncherVersion = "1.5", }; Console.WriteLine("[MARS] Assigned launch options."); if (forge) { string[] parts = version.Split('-'); string mcVer = parts[0]; string forgeVer = parts[2] + "-" + parts[3]; MProfile forgeProfile = launcher.GetProfile(mcVer, forgeVer); options.StartProfile = forgeProfile; } else { options.StartProfile = launcher.GetProfile(version); } if (!string.IsNullOrEmpty(sptxt)) { options.ServerIp = sptxt; } Console.WriteLine("[MARS] Located target profile. Launching..."); Console.WriteLine("[MARS] Moving to new thread..."); Data.hook.OnHookKeyPressed += Hook_OnHookKeyPressed; MLaunch launch = new MLaunch(options); mcThread = new Thread(new ParameterizedThreadStart(delegate(object obj) { MLaunch threadLaunch = (MLaunch)obj; Process pr = threadLaunch.GetProcess(); ProcessStartInfo psi = pr.StartInfo; psi.RedirectStandardOutput = true; psi.RedirectStandardInput = true; psi.UseShellExecute = false; staticMC = Process.Start(psi); staticMC.EnableRaisingEvents = true; launched = true; staticMC.Exited += delegate { //OutputManager.RemoveConsole(); rpcTimer.Stop(); Data.rpccli.Dispose(); Invoke((MethodInvoker) delegate { minecraftClosed = true; }); mcThread.Abort(); }; staticMC.OutputDataReceived += (object _, DataReceivedEventArgs _a) => { string txt = _a.Data; OutputManager.ProcessText(txt); if (txt == null) { return; } if (txt.Contains("[Client thread/INFO]: Connecting to")) { int timeind = txt.IndexOf(']'); string a = txt.Substring(timeind + 38); string b = a.Split(',')[0]; string newserver = "Server: " + b; if (!currentServer.Equals(newserver)) { Debug.WriteLine("Connected to: \"" + b + "\""); Console.WriteLine("Connected to: \"" + b + "\""); } currentServer = "Server: " + b; } }; staticMC.BeginOutputReadLine(); })); mcThread.Start(launch); int launchWaits = 0; while (staticMC == null) { launchWaits++; Console.WriteLine("[MARS] Waiting for process to launch... #{0}", launchWaits); Thread.Sleep(250); } Console.WriteLine("[MARS] Waiting for main window handle..."); Data.mcProcess = staticMC; while (staticMC.MainWindowHandle == IntPtr.Zero) { Thread.Sleep(100); } Data.mcWindow = staticMC.MainWindowHandle; Console.WriteLine("\n\n[MARS] Got main window handle. Attaching UI framework..."); Console.WriteLine("[MARS] Building window...\n\n"); InGameWindow igw = new InGameWindow(); Data.hud = igw; igw.Show(); SetParent(igw.Handle, Data.mcWindow); igw.NowParented(); Console.WriteLine("[MARS] Begun window message pump."); Console.WriteLine("[MARS] Fetching HypixelSelf info..."); if (File.Exists("mars_client\\hypixelself.ser")) { Data.player = HypixelSelf.Deserialize(File.ReadAllText ("mars_client\\hypixelself.ser")); } Console.WriteLine("[MARS] Loaded, if any.\n\n"); Console.WriteLine("[MARS] Finished initialization."); }