private void Btn_action_Click(object sender, EventArgs e) { var mcProcesses = Process.GetProcessesByName("javaw").Where(b => b.MainWindowTitle.Contains("Minecraft")).ToList(); var mainHandle = this.Handle; if (!int.TryParse(this.txtDelay.Text, out int delay)) { MessageBox.Show(@"The delay must be an integer! Resetting to default.", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); this.txtDelay.Text = @"300"; return; } if (!int.TryParse(this.txtRand.Text, out int rand)) { MessageBox.Show(@"The random must be an integer! Resetting to default.", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); this.txtDelay.Text = @"300"; return; } if (!mcProcesses.Any()) { MessageBox.Show(@"Minecraft not running!", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (mcProcesses.Count > 1) { var instancesForm = new MultipleInstances(mcProcesses); if (instancesForm.ShowDialog() != DialogResult.OK) { return; } mcProcesses = instancesForm.SelectedInstances.Select(Process.GetProcessById).ToList(); } var buttonCode = rdio_RightClick.Checked ? Win32Api.WmRbuttonDown : Win32Api.WmLbuttonDown; this._stop = false; this.lblstart_time.Text = DateTime.Now.ToString("MMMM dd HH:mm tt"); foreach (var mcProcess in mcProcesses) { var thread = new BackgroundWorker(); thread.DoWork += delegate { StartClick(mcProcess, mainHandle, (uint)buttonCode, delay, rand, this.chkHold.Checked); }; thread.RunWorkerAsync(); Thread.Sleep(200); FocusToggle(mcProcess.MainWindowHandle); FocusToggle(this.Handle); } }
private void Btn_action_Click(object sender, EventArgs e) { try { EnableElements(false); var mcProcesses = Process.GetProcesses().Where(b => b.ProcessName.StartsWith("java") && WindowTitles.Any(title => b.MainWindowTitle.Contains(title))).ToList(); var mainHandle = Handle; if (!mcProcesses.Any()) { // if we first don't find any windows matching an expected name, give the user the ability to override var notRunning = new NotRunning(); if (notRunning.ShowDialog() != DialogResult.OK) { EnableElements(true); return; } if (!string.IsNullOrEmpty(notRunning.ProcessTitle)) { mcProcesses = Process.GetProcesses().Where(b => b.MainWindowTitle == notRunning.ProcessTitle).ToList(); } } if (!mcProcesses.Any()) { MessageBox.Show(@"Unable to find Minecraft process!", @"Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); EnableElements(true); return; } if (mcProcesses.Count > 1) { using (var instancesForm = new MultipleInstances(mcProcesses)) { if (instancesForm.ShowDialog() != DialogResult.OK) { EnableElements(true); return; } mcProcesses = instancesForm.SelectedInstances.Select(Process.GetProcessById).ToList(); } } lblStartTime.Text = DateTime.Now.ToString("MMMM dd HH:mm tt"); lblStarted.Visible = true; lblStartTime.Visible = true; foreach (var mcProcess in mcProcesses) { SetControlPropertyThreadSafe(btn_start, "Enabled", false); SetControlPropertyThreadSafe(btn_stop, "Enabled", true); var minecraftHandle = mcProcess.MainWindowHandle; FocusToggle(minecraftHandle); SetControlPropertyThreadSafe(btn_start, "Text", @"Starting in: "); Thread.Sleep(500); for (var i = 5; i > 0; i--) { SetControlPropertyThreadSafe(btn_start, "Text", i.ToString()); Thread.Sleep(500); } FocusToggle(mainHandle); SetControlPropertyThreadSafe(btn_start, "Text", @"Running..."); Thread.Sleep(500); //Right click needs to be ahead of left click for concrete mining if (biRightMouse.Needed) { var clicker = biRightMouse.StartClicking(minecraftHandle); AddToInstanceClickers(mcProcess, clicker); } /* * This sleep is needed, because if you want to mine concrete, then Minecraft starts to hold left click first * and it won't place the block in your second hand for some reason... */ Thread.Sleep(100); if (biLeftMouse.Needed) { var clicker = biLeftMouse.StartClicking(minecraftHandle); AddToInstanceClickers(mcProcess, clicker); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "An error occured", MessageBoxButtons.OK, MessageBoxIcon.Error); Stop(); } }