private void getNextSlot() { if (Slot.Value == 30) { Delg.SetValue(Box, Box.Value + 1); Delg.SetValue(Slot, 1); } else { Delg.SetValue(Slot, Slot.Value + 1); } }
/// <summary> /// Resets the form. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ClearAll_Click(object sender, EventArgs e) { Delg.SetSelectedIndex(Mode, -1); Delg.SetValue(Box, 1); Delg.SetValue(Slot, 1); Delg.SetValue(Eggs, 1); Delg.SetValue(Accept, 0); Delg.SetValue(Reject, 0); Delg.SetChecked(ReadESV, false); esvList.Rows.Clear(); TSVlist.Items.Clear(); filterList.Rows.Clear(); }
private void SetControls(bool state) { foreach (Control ctrl in controlList) { ctrl.Enabled = state; } if (state) { Delg.SetMinimum(numFor, 1); Delg.SetValue(numFor, 1); } else { Delg.SetMinimum(numFor, 0); Delg.SetValue(numFor, 0); } }
private async void Fill6() { SetControls(false); Delg.SetText(TB_Name, await waitName()); Delg.SetValue(Num_TID, await waitTID()); Delg.SetValue(Num_SID, await waitSID()); Delg.SetValue(Num_Money, await waitMoney()); Delg.SetValue(Num_Miles, await waitMiles()); Delg.SetValue(Num_BP, await waitBP()); Delg.SetSelectedValue(CB_Language, await waitLang()); byte[] time = await waitTime(); Delg.SetValue(Num_Hour, BitConverter.ToUInt16(time, 0)); Delg.SetValue(Num_Min, time[2]); Delg.SetValue(Num_Sec, time[3]); Delg.SetEnabled(ReloadFields, true); }
private void getNextSlot() { if (Slot.Value == 30) { Delg.SetValue(Box, Box.Value + 1); Delg.SetValue(Slot, 1); boxchange = true; } else { Delg.SetValue(Slot, Slot.Value + 1); } Delg.SetValue(Trades, Trades.Value - 1); if (Trades.Value > 0) { if (sourceBox.Checked) { botstate = BotState.readpoke; } else { botstate = BotState.writefromfolder; } attempts = 0; } else if (runEndless.Checked) { Delg.SetValue(Box, startbox); Delg.SetValue(Slot, startslot); Delg.SetValue(Trades, starttrades); if (sourceBox.Checked) { botstate = BotState.readpoke; } else { botstate = BotState.writefromfolder; } attempts = 0; } else { botstate = BotState.dumpafter; } }
private void ResetForm() { Delg.SetChecked(filterShiny, false); Delg.SetSelectedIndex(filterNature, -1); Delg.SetSelectedIndex(filterAbility, -1); Delg.SetSelectedIndex(filterHPtype, -1); Delg.SetSelectedIndex(filterGender, -1); Delg.SetSelectedIndex(filterHPlogic, 0); Delg.SetSelectedIndex(filterATKlogic, 0); Delg.SetSelectedIndex(filterDEFlogic, 0); Delg.SetSelectedIndex(filterSPAlogic, 0); Delg.SetSelectedIndex(filterSPDlogic, 0); Delg.SetSelectedIndex(filterSPElogic, 0); Delg.SetSelectedIndex(filterPerIVlogic, 0); Delg.SetValue(filterHPvalue, 0); Delg.SetValue(filterATKvalue, 0); Delg.SetValue(filterDEFvalue, 0); Delg.SetValue(filterSPAvalue, 0); Delg.SetValue(filterSPDvalue, 0); Delg.SetValue(filterSPEvalue, 0); }
private void filterRead_Click(object sender, EventArgs e) { if (filterList.SelectedRows.Count > 0) { if ((int)filterList.SelectedRows[0].Cells[0].Value == 1) { Delg.SetChecked(filterShiny, true); } else { Delg.SetChecked(filterShiny, false); } Delg.SetSelectedIndex(filterNature, (int)filterList.SelectedRows[0].Cells[1].Value); Delg.SetSelectedIndex(filterAbility, (int)filterList.SelectedRows[0].Cells[2].Value); Delg.SetSelectedIndex(filterHPtype, (int)filterList.SelectedRows[0].Cells[3].Value); Delg.SetSelectedIndex(filterGender, (int)filterList.SelectedRows[0].Cells[4].Value); Delg.SetValue(filterHPvalue, (int)filterList.SelectedRows[0].Cells[5].Value); Delg.SetSelectedIndex(filterHPlogic, (int)filterList.SelectedRows[0].Cells[6].Value); Delg.SetValue(filterATKvalue, (int)filterList.SelectedRows[0].Cells[7].Value); Delg.SetSelectedIndex(filterATKlogic, (int)filterList.SelectedRows[0].Cells[8].Value); Delg.SetValue(filterDEFvalue, (int)filterList.SelectedRows[0].Cells[9].Value); Delg.SetSelectedIndex(filterDEFlogic, (int)filterList.SelectedRows[0].Cells[10].Value); Delg.SetValue(filterSPAvalue, (int)filterList.SelectedRows[0].Cells[11].Value); Delg.SetSelectedIndex(filterSPAlogic, (int)filterList.SelectedRows[0].Cells[12].Value); Delg.SetValue(filterSPDvalue, (int)filterList.SelectedRows[0].Cells[13].Value); Delg.SetSelectedIndex(filterSPDlogic, (int)filterList.SelectedRows[0].Cells[14].Value); Delg.SetValue(filterSPEvalue, (int)filterList.SelectedRows[0].Cells[15].Value); Delg.SetSelectedIndex(filterSPElogic, (int)filterList.SelectedRows[0].Cells[16].Value); Delg.SetValue(filterPerIVvalue, (int)filterList.SelectedRows[0].Cells[17].Value); Delg.SetSelectedIndex(filterPerIVlogic, (int)filterList.SelectedRows[0].Cells[18].Value); } else { MessageBox.Show("There is no filter selected."); } }
/// <summary> /// Bot procedure. /// </summary> public async void RunBot() { try { Program.gCmdWindow.SetBotMode(true); while (botworking && Program.gCmdWindow.IsConnected) { switch (botState) { case (int)BotState.BotStart: Report("Bot: START Gen 7 Breding bot"); if (Mode.SelectedIndex >= 0 && Mode.SelectedIndex != 3 && Eggs.Value > 0) { Delg.SetValue(Slot, 1); botState = BotState.SelectBox; } else if (Mode.SelectedIndex == 3 && (Accept.Value > 0 || Reject.Value > 0)) { botState = BotState.EggSeed; } else { botresult = ErrorMessage.Finished; botState = BotState.BotExit; } break; case BotState.SelectBox: Report("Bot: Set start box"); waitTaskbool = Program.helper.waitNTRwrite(LookupTable .CurrentboxOffset, (uint)GetIndex(Box), Program.gCmdWindow.pid); if (await waitTaskbool) { attempts = 0; botState = BotState.ReadSlot; } else { attempts++; botresult = ErrorMessage.WriteError; botState = BotState.SelectBox; } break; case BotState.ReadSlot: Report("Bot: Search for empty slot"); waitTaskPKM = Program.helper.waitPokeRead(Box, Slot); breedPoke = await waitTaskPKM; if (breedPoke == null) { // No data or invalid attempts++; botresult = ErrorMessage.ReadError; botState = BotState.ReadSlot; } else if (breedPoke.Species == 0) { // Empty space Report("Bot: Empty slot"); attempts = 0; botState = BotState.EggSeed; } else { GetNextSlot(); botState = BotState.ReadSlot; } break; case BotState.EggSeed: Report("Bot: Update Egg seed"); waitTaskbool = Program.helper.waitNTRmultiread(eggseedOff, 0x10); if (await waitTaskbool) { Report("Bot: Current seed - " + UpdateSeed(Program.helper .lastmultiread)); attempts = 0; if (Mode.SelectedIndex != 3) { botState = BotState.GenerateEgg; } else { if (Accept.Value == 0 && Reject.Value == 0) { botresult = ErrorMessage.Finished; botState = BotState.BotExit; } else { botState = BotState.GenerateEgg; } } } else { attempts++; botresult = ErrorMessage.ReadError; botState = BotState.EggSeed; } break; case BotState.GenerateEgg: Report("Bot: Produce Egg in Nursery"); waitTaskbool = Program.helper.waitNTRwrite(EggOff, 0x01, Program.gCmdWindow.pid); if (await waitTaskbool) { attempts = 0; botState = BotState.TriggerDialog; } else { attempts++; botresult = ErrorMessage.WriteError; botState = BotState.GenerateEgg; } break; case BotState.TriggerDialog: Report("Bot: Start dialog"); waitTaskbool = Program.helper.waitbutton(LookupTable.ButtonA); if (await waitTaskbool) { botState = BotState.TestDialog1; } else { attempts++; botresult = ErrorMessage.ButtonError; botState = BotState.TriggerDialog; } break; case BotState.TestDialog1: Report("Bot: Test if dialog has started"); waitTaskbool = Program.helper.memoryinrange(DialogOff, DialogIn, 0x10000000); if (await waitTaskbool) { attempts = 0; botState = BotState.ContinueDialog; } else { attempts++; botresult = ErrorMessage.ReadError; botState = BotState.TriggerDialog; } break; case BotState.ContinueDialog: Report("Bot: Continue dialog"); int maxi; if (Mode.SelectedIndex == 3 && Accept.Value == 0) { key = LookupTable.ButtonB; maxi = 9; } else { key = LookupTable.ButtonA; maxi = 6; } int i; for (i = 0; i < maxi; i++) { waitTaskbool = Program.helper.waitbutton(key); if (!(await waitTaskbool)) { break; } } if (i == 6) { botState = BotState.CheckNoEgg; } if (i == 9) { botState = BotState.TestDialog2; } else { botState = BotState.FixDialog; } break; case BotState.FixDialog: waitTaskbool = Program.helper.waitbutton(key); if (await waitTaskbool) { botState = BotState.CheckNoEgg; } else { attempts++; botresult = ErrorMessage.ButtonError; botState = BotState.FixDialog; } break; case BotState.CheckNoEgg: waitTaskbool = Program.helper.memoryinrange(EggOff, 0x00, 0x01); if (await waitTaskbool) { attempts = 0; Report("Bot: Egg received"); botState = BotState.ExitDialog; } else { attempts++; botresult = ErrorMessage.ReadError; botState = BotState.FixDialog; } break; case BotState.ExitDialog: Report("Bot: Exit dialog"); await Task.Delay(1500); waitTaskbool = Program.helper.waitbutton(LookupTable.ButtonB); if (await waitTaskbool) { waitTaskbool = Program.helper.waitbutton(LookupTable .ButtonB); if (await waitTaskbool) { botState = BotState.TestDialog2; } else { attempts++; botresult = ErrorMessage.ButtonError; botState = BotState.ExitDialog; } } else { attempts++; botresult = ErrorMessage.ButtonError; botState = BotState.ExitDialog; } break; case BotState.TestDialog2: waitTaskbool = Program.helper.memoryinrange(DialogOff, DialogOut, 0x10000000); if (await waitTaskbool) { attempts = 0; Report("Bot: Dialog finished"); if (Mode.SelectedIndex != 3) { botState = BotState.Filter; } else { if (Accept.Value > 0) { Delg.SetValue(Accept, Accept.Value - 1); } else { Delg.SetValue(Reject, Reject.Value - 1);; } botState = BotState.EggSeed; } } else { attempts++; botresult = ErrorMessage.ReadError; botState = BotState.ExitDialog; } break; case BotState.Filter: bool testsok = false; Report("Bot: Read recevied egg"); waitTaskPKM = Program.helper.waitPokeRead(Box, Slot); breedPoke = await waitTaskPKM; if (breedPoke == null) { // No data or invalid attempts++; botresult = ErrorMessage.ReadError; botState = BotState.Filter; } else if (breedPoke.Species == 0) { // Empty space Report("Bot: Error detected - slot is empty"); attempts = 11; botresult = ErrorMessage.GeneralError; botState = BotState.BotExit; } else { attempts = 0; Delg.SetValue(Eggs, Eggs.Value - 1); if (ReadESV.Checked || Mode.SelectedIndex == 2) { Delg.DataGridViewAddRow(esvList, Box.Value, Slot.Value, breedPoke.PSV.ToString("D4")); if (Mode.SelectedIndex == 2) { testsok = ESV_TSV_check(breedPoke.PSV); } } if (Mode.SelectedIndex == 1) { filternum = CheckFilters(breedPoke, filterList); testsok = filternum > 0; } } if (testsok) { botState = BotState.TestsPassed; break; } else if (Eggs.Value > 0) { GetNextSlot(); botState = BotState.ReadSlot; } else { if (Mode.SelectedIndex == 1 || Mode.SelectedIndex == 2) { Report("Bot: No match found"); botresult = ErrorMessage.NoMatch; } else { botresult = ErrorMessage.Finished; } botState = BotState.BotExit; } break; case BotState.TestsPassed: if (Mode.SelectedIndex == 1) { Report("Bot: All tests passed"); botresult = ErrorMessage.FilterMatch; finishmessage[0] = (int)Box.Value; finishmessage[1] = (int)Slot.Value; finishmessage[2] = filternum; } else if (Mode.SelectedIndex == 2) { Report("Bot: ESV/TSV match found"); botresult = ErrorMessage.SVMatch; finishmessage[0] = (int)Box.Value; finishmessage[1] = (int)Slot.Value; finishmessage[2] = breedPoke.PSV; } botState = BotState.BotExit; break; case BotState.BotExit: Report("Bot: STOP Gen 7 Breding bot"); botworking = false; break; default: Report("Bot: STOP Gen 7 Breding bot"); botresult = ErrorMessage.GeneralError; botworking = false; break; } if (attempts > 10) { // Too many attempts if (maxreconnect > 0) { Report("Bot: Try reconnection to fix error"); waitTaskbool = Program.gCmdWindow.Reconnect(); maxreconnect--; if (await waitTaskbool) { await Task.Delay(2500); attempts = 0; } else { botresult = ErrorMessage.GeneralError; botworking = false; } } else { Report("Bot: Maximum number of reconnection attempts reached"); Report("Bot: STOP Gen 7 Breeding bot"); botworking = false; } } } } catch (Exception ex) { Report("Bot: Exception detected:"); Report(ex.Source); Report(ex.Message); Report(ex.StackTrace); Report("Bot: STOP Gen 7 Breeding bot"); MessageBox.Show(ex.Message); botworking = false; botresult = ErrorMessage.GeneralError; } if (userstop) { botresult = ErrorMessage.UserStop; } else if (!Program.gCmdWindow.IsConnected) { botresult = ErrorMessage.Disconnect; } ShowResult("Breeding bot", botresult, finishmessage); Delg.SetText(RunStop, "Start Bot"); Program.gCmdWindow.SetBotMode(false); EnableControls(); Delg.SetEnabled(RunStop, true); }
private async void ExecuteScript() { if (this.InvokeRequired) { BeginInvoke(new MethodDelegate(ExecuteScript)); return; } if (actions.Count < 1) { MessageBox.Show("No actions to execute.", "Script Builder", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SetControls(false); Program.gCmdWindow.ScriptMode(true); scriptRunning = true; ScriptAction.Report("Script: Start script"); for (int index = 0; index < actions.Count; index++) { lstActions.SelectedIndex = index; if (actions[index] is StartFor) { // Search for EndFor if (((StartFor)actions[index]).EndInstruction < 0) { int endins = SearchEndFor(index, ((StartFor)actions[index]).ID); if (endins >= 0) { ((StartFor)actions[index]).EndInstruction = endins; } else { ScriptAction.Report("Script: End of loop not found"); break; } } // Check if finished, and restart if (((StartFor)actions[index]).IsFinished) { await Task.Delay(200); int tempins = ((StartFor)actions[index]).EndInstruction; ((StartFor)actions[index]).EndInstruction = -1; ((StartFor)actions[index]).Loops = 0; Delg.SetValue(numFor, 0); index = tempins; ((EndFor)actions[index]).StartInstruction = -1; ScriptAction.Report("Script: End loops"); continue; } else { Delg.SetValue(numFor, ((StartFor)actions[index]).TotalLoops - ((StartFor)actions[index]).Loops); } } else if (actions[index] is EndFor) { // Search for StartFor if (((EndFor)actions[index]).StartInstruction < 0) { int startins = SearchStartFor(index, ((EndFor)actions[index]).ID); if (startins >= 0) { ((EndFor)actions[index]).StartInstruction = startins; } else { ScriptAction.Report("Script: Start of loop not found"); break; } } await actions[index].Excecute(); index = ((EndFor)actions[index]).StartInstruction - 1; continue; } if (stopScript || !Program.gCmdWindow.IsConnected) { break; } await actions[index].Excecute(); } ScriptAction.Report("Script: Stop script"); scriptRunning = false; Program.gCmdWindow.ScriptMode(false); MessageBox.Show("Script finished.", "Script Builder", MessageBoxButtons.OK, MessageBoxIcon.Information); if (Program.gCmdWindow.IsConnected) { btnStartStop.Text = "Start Script"; btnStartStop.Enabled = true; } else { btnStartStop.Text = "Not connected"; btnStartStop.Enabled = false; } SetControls(true); }