private void save() { foreach (var reg in reglist) { ReflectUtil.SetValue(pkm, reg.Name, reg.CompletedRegimen); } foreach (var reg in distlist) { ReflectUtil.SetValue(pkm, reg.Name, reg.CompletedRegimen); } if (pkm is PK6) { PK6 pk6 = (PK6)pkm; pk6.SecretSuperTrainingUnlocked = CHK_SecretUnlocked.Checked; pk6.SecretSuperTrainingComplete = CHK_SecretComplete.Checked; pk6.TrainingBag = CB_Bag.SelectedIndex; pk6.TrainingBagHits = (int)NUD_BagHits.Value; } else // clear flags if manually cleared { pkm.SecretSuperTrainingUnlocked &= CHK_SecretUnlocked.Checked; pkm.SecretSuperTrainingComplete &= CHK_SecretComplete.Checked; } Main.pkm = pkm; }
private void btnApply_Click(object sender, EventArgs e) { if (inpath != "") { FolderBrowserDialog folderbrowser = new FolderBrowserDialog(); folderbrowser.Description = "Select an output folder."; if (folderbrowser.ShowDialog() != DialogResult.Cancel) { if (folderbrowser.SelectedPath != "") { outpath = folderbrowser.SelectedPath; } } DirectoryInfo indir = new DirectoryInfo(inpath); DirectoryInfo outdir = new DirectoryInfo(outpath); foreach (FileInfo file in indir.GetFiles("*.pk6")) { PK6 pk6 = Functions.ReadPK6(file.FullName); pk6.OTName = txtOTName.Text; pk6.OTIsFemale = rbOTFemale.Checked; pk6.TID = (UInt16)numTID.Value; pk6.SID = (UInt16)numSID.Value; pk6.CalcChecksum(); Functions.WritePK6(pk6, Path.Combine(outpath, file.Name)); } } }
public static PKM GetPKMFromPayload(byte[] inputBuffer) { byte[] pkmData = new byte[PKSIZE]; Array.Copy(inputBuffer, HEADER.Length + GAME_LEN, pkmData, 0, 232); PKM pk; byte version = inputBuffer[HEADER.Length]; switch (version) { case GEN6: pk = new PK6(pkmData); break; case GEN7: pk = new PK7(pkmData); break; default: pk = new PK7(); break; } return(pk); }
/// <summary> /// Sets a random memory specific to <see cref="GameVersion.Gen6"/> locality. /// </summary> /// <param name="pk">Pokémon to modify.</param> public static void SetRandomMemory6(this PK6 pk) { // for lack of better randomization :) pk.OT_Memory = 63; pk.OT_Intensity = 6; pk.OT_Feeling = Memories.GetRandomFeeling(pk.OT_Memory); }
public void HasOriginalMetLocation6(GameVersion g) { var pk5 = new PK6 { Version = (int)g }; pk5.HasOriginalMetLocation.Should().BeTrue(); }
private void B_Save_Click(object sender, EventArgs e) { for (int i = 0; i < seen.Length; i++) { PKM tempPkm = new PK6(); tempPkm.Species = i + 1; SAV.setSeen(tempPkm, seen[i]); SAV.setCaught(tempPkm, caught[i]); } SAV.Data.CopyTo(Main.SAV.Data, 0); Main.SAV.Edited = true; Close(); }
public SuperTrainingEditor(PKM pk) { pkm = pk; InitializeComponent(); WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage); int vertScrollWidth = SystemInformation.VerticalScrollBarWidth; TLP_SuperTrain.Padding = TLP_DistSuperTrain.Padding = new Padding(0, 0, vertScrollWidth, 0); // Updating a Control display with autosized elements on every row addition is cpu intensive. Disable layout updates while populating. TLP_SuperTrain.SuspendLayout(); TLP_DistSuperTrain.SuspendLayout(); TLP_SuperTrain.Scroll += WinFormsUtil.PanelScroll; TLP_DistSuperTrain.Scroll += WinFormsUtil.PanelScroll; PopulateRegimens("SuperTrain", TLP_SuperTrain, reglist); PopulateRegimens("DistSuperTrain", TLP_DistSuperTrain, distlist); TLP_SuperTrain.ResumeLayout(); TLP_DistSuperTrain.ResumeLayout(); CHK_SecretUnlocked.Checked = pkm.SecretSuperTrainingUnlocked; CHK_SecretComplete.Checked = pkm.SecretSuperTrainingComplete; if (pkm is PK6) { CB_Bag.Items.Clear(); CB_Bag.Items.Add("---"); for (int i = 1; i < GameInfo.Strings.trainingbags.Length - 1; i++) { CB_Bag.Items.Add(GameInfo.Strings.trainingbags[i]); } PK6 pk6 = (PK6)pkm; CB_Bag.SelectedIndex = pk6.TrainingBag; NUD_BagHits.Value = pk6.TrainingBagHits; if (!CHK_SecretUnlocked.Checked) // force update to disable checkboxes { CHK_Secret_CheckedChanged(null, null); } } else { L_Bag.Visible = CB_Bag.Visible = L_Hits.Visible = NUD_BagHits.Visible = false; CHK_SecretUnlocked.Visible = CHK_SecretComplete.Visible = false; } }
public SAV_SimplePokedex() { InitializeComponent(); WinFormsUtil.TranslateInterface(this, Main.curlanguage); seen = new bool[SAV.MaxSpeciesID]; caught = new bool[SAV.MaxSpeciesID]; string[] spec = Util.getSpeciesList(Main.curlanguage); for (int i = 0; i < seen.Length; i++) { PKM tempPkm = new PK6(); tempPkm.Species = i + 1; seen[i] = SAV.getSeen(tempPkm); caught[i] = SAV.getCaught(tempPkm); CLB_Seen.Items.Add(spec[i + 1]); CLB_Caught.Items.Add(spec[i + 1]); CLB_Seen.SetItemChecked(i, seen[i]); CLB_Caught.SetItemChecked(i, caught[i]); } initialized = true; }
/// <summary> /// Check if a pokémon can be traded via Wonder Trade, checks legality, /// egg and ribbons. /// </summary> /// <param name="poke">PKM data to check.</param> /// <returns>Returns false if the pokémon is an egg or has special ribbons. It /// also returns false if the pokémon is illegal, except when the program is in /// illegal mode.</returns> public static bool IsTradeable(PKM poke) { if (!IsLegal(poke)) { // Don't trade illegal pokemon return(false); } if (poke.IsEgg) { // Don't trade eggs return(false); } if (poke.Format == 6) { var poke6 = new PK6(poke.Data); if (poke6.RibbonCountry || poke6.RibbonWorld || poke6.RibbonClassic || poke6.RibbonPremier || poke6.RibbonEvent || poke6.RibbonBirthday || poke6.RibbonSpecial || poke6.RibbonSouvenir || poke6.RibbonWishing || poke6.RibbonChampionBattle || poke6.RibbonChampionRegional || poke6.RibbonChampionNational || poke6.RibbonChampionWorld) { // Check for Special Ribbons return(false); } } if (poke.Format == 7) { var poke7 = new PK7(poke.Data); if (poke7.RibbonCountry || poke7.RibbonWorld || poke7.RibbonClassic || poke7.RibbonPremier || poke7.RibbonEvent || poke7.RibbonBirthday || poke7.RibbonSpecial || poke7.RibbonSouvenir || poke7.RibbonWishing || poke7.RibbonChampionBattle || poke7.RibbonChampionRegional || poke7.RibbonChampionNational || poke7.RibbonChampionWorld) { // Check for Special Ribbons return(false); } } return(true); }
private void PopulateFieldsPK6() { PK6 pk6 = pkm as PK6; if (pk6 == null) { return; } // Do first pk6.Stat_Level = PKX.GetLevel(pk6.Species, pk6.EXP); if (pk6.Stat_Level == 100 && !HaX) { pk6.EXP = PKX.GetEXP(pk6.Stat_Level, pk6.Species); } CB_Species.SelectedValue = pk6.Species; TB_Level.Text = pk6.Stat_Level.ToString(); TB_EXP.Text = pk6.EXP.ToString(); // Load rest TB_EC.Text = pk6.EncryptionConstant.ToString("X8"); CHK_Fateful.Checked = pk6.FatefulEncounter; CHK_IsEgg.Checked = pk6.IsEgg; CHK_Nicknamed.Checked = pk6.IsNicknamed; Label_OTGender.Text = gendersymbols[pk6.OT_Gender]; Label_OTGender.ForeColor = GetGenderColor(pk6.OT_Gender); TB_PID.Text = pk6.PID.ToString("X8"); CB_HeldItem.SelectedValue = pk6.HeldItem; TB_AbilityNumber.Text = pk6.AbilityNumber.ToString(); CB_Ability.SelectedIndex = pk6.AbilityNumber < 6 ? pk6.AbilityNumber >> 1 : 0; // with some simple error handling CB_Nature.SelectedValue = pk6.Nature; TB_TID.Text = pk6.TID.ToString("00000"); TB_SID.Text = pk6.SID.ToString("00000"); TB_Nickname.Text = pk6.Nickname; TB_OT.Text = pk6.OT_Name; TB_OTt2.Text = pk6.HT_Name; TB_Friendship.Text = pk6.CurrentFriendship.ToString(); if (pk6.CurrentHandler == 1) // HT { GB_nOT.BackgroundImage = mixedHighlight; GB_OT.BackgroundImage = null; } else // = 0 { GB_OT.BackgroundImage = mixedHighlight; GB_nOT.BackgroundImage = null; } CB_Language.SelectedValue = pk6.Language; CB_Country.SelectedValue = pk6.Country; CB_SubRegion.SelectedValue = pk6.Region; CB_3DSReg.SelectedValue = pk6.ConsoleRegion; CB_GameOrigin.SelectedValue = pk6.Version; CB_EncounterType.SelectedValue = pk6.Gen4 ? pk6.EncounterType : 0; CB_Ball.SelectedValue = pk6.Ball; CAL_MetDate.Value = pk6.MetDate ?? new DateTime(2000, 1, 1); if (pk6.Egg_Location != 0) { // Was obtained initially as an egg. CHK_AsEgg.Checked = true; GB_EggConditions.Enabled = true; CB_EggLocation.SelectedValue = pk6.Egg_Location; CAL_EggDate.Value = pk6.EggMetDate ?? new DateTime(2000, 1, 1); } else { CAL_EggDate.Value = new DateTime(2000, 01, 01); CHK_AsEgg.Checked = GB_EggConditions.Enabled = false; CB_EggLocation.SelectedValue = 0; } CB_MetLocation.SelectedValue = pk6.Met_Location; // Set CT Gender to None if no CT, else set to gender symbol. Label_CTGender.Text = pk6.HT_Name == "" ? "" : gendersymbols[pk6.HT_Gender % 2]; Label_CTGender.ForeColor = GetGenderColor(pk6.HT_Gender % 2); TB_MetLevel.Text = pk6.Met_Level.ToString(); // Reset Label and ComboBox visibility, as well as non-data checked status. Label_PKRS.Visible = CB_PKRSStrain.Visible = CHK_Infected.Checked = pk6.PKRS_Strain != 0; Label_PKRSdays.Visible = CB_PKRSDays.Visible = pk6.PKRS_Days != 0; // Set SelectedIndexes for PKRS CB_PKRSStrain.SelectedIndex = pk6.PKRS_Strain; CHK_Cured.Checked = pk6.PKRS_Strain > 0 && pk6.PKRS_Days == 0; CB_PKRSDays.SelectedIndex = Math.Min(CB_PKRSDays.Items.Count - 1, pk6.PKRS_Days); // to strip out bad hacked 'rus Contest.Cool = pk6.CNT_Cool; Contest.Beauty = pk6.CNT_Beauty; Contest.Cute = pk6.CNT_Cute; Contest.Smart = pk6.CNT_Smart; Contest.Tough = pk6.CNT_Tough; Contest.Sheen = pk6.CNT_Sheen; TB_HPIV.Text = pk6.IV_HP.ToString(); TB_ATKIV.Text = pk6.IV_ATK.ToString(); TB_DEFIV.Text = pk6.IV_DEF.ToString(); TB_SPEIV.Text = pk6.IV_SPE.ToString(); TB_SPAIV.Text = pk6.IV_SPA.ToString(); TB_SPDIV.Text = pk6.IV_SPD.ToString(); CB_HPType.SelectedValue = pk6.HPType; TB_HPEV.Text = pk6.EV_HP.ToString(); TB_ATKEV.Text = pk6.EV_ATK.ToString(); TB_DEFEV.Text = pk6.EV_DEF.ToString(); TB_SPEEV.Text = pk6.EV_SPE.ToString(); TB_SPAEV.Text = pk6.EV_SPA.ToString(); TB_SPDEV.Text = pk6.EV_SPD.ToString(); CB_Move1.SelectedValue = pk6.Move1; CB_Move2.SelectedValue = pk6.Move2; CB_Move3.SelectedValue = pk6.Move3; CB_Move4.SelectedValue = pk6.Move4; CB_RelearnMove1.SelectedValue = pk6.RelearnMove1; CB_RelearnMove2.SelectedValue = pk6.RelearnMove2; CB_RelearnMove3.SelectedValue = pk6.RelearnMove3; CB_RelearnMove4.SelectedValue = pk6.RelearnMove4; CB_PPu1.SelectedIndex = pk6.Move1_PPUps; CB_PPu2.SelectedIndex = pk6.Move2_PPUps; CB_PPu3.SelectedIndex = pk6.Move3_PPUps; CB_PPu4.SelectedIndex = pk6.Move4_PPUps; TB_PP1.Text = pk6.Move1_PP.ToString(); TB_PP2.Text = pk6.Move2_PP.ToString(); TB_PP3.Text = pk6.Move3_PP.ToString(); TB_PP4.Text = pk6.Move4_PP.ToString(); // Set Form if count is enough, else cap. CB_Form.SelectedIndex = CB_Form.Items.Count > pk6.AltForm ? pk6.AltForm : CB_Form.Items.Count - 1; // Load Extrabyte Value TB_ExtraByte.Text = pk6.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); UpdateStats(); TB_EXP.Text = pk6.EXP.ToString(); Label_Gender.Text = gendersymbols[pk6.Gender]; Label_Gender.ForeColor = GetGenderColor(pk6.Gender); // Highlight the Current Handler ClickGT(pk6.CurrentHandler == 1 ? GB_nOT : GB_OT, null); if (HaX) { DEV_Ability.SelectedValue = pk6.Ability; } }
private PKM PreparePK6() { PK6 pk6 = pkm as PK6; if (pk6 == null) { return(null); } // Repopulate PK6 with Edited Stuff CheckTransferPIDValid(); pk6.EncryptionConstant = Util.GetHexValue(TB_EC.Text); pk6.Checksum = 0; // 0 CHK for now // Block A pk6.Species = WinFormsUtil.GetIndex(CB_Species); pk6.HeldItem = WinFormsUtil.GetIndex(CB_HeldItem); pk6.TID = Util.ToInt32(TB_TID.Text); pk6.SID = Util.ToInt32(TB_SID.Text); pk6.EXP = Util.ToUInt32(TB_EXP.Text); if (CB_Ability.Text.Length >= 4) { pk6.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); pk6.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number } // pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag) pk6.PID = Util.GetHexValue(TB_PID.Text); pk6.Nature = (byte)WinFormsUtil.GetIndex(CB_Nature); pk6.FatefulEncounter = CHK_Fateful.Checked; pk6.Gender = PKX.GetGender(Label_Gender.Text); pk6.AltForm = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F; pk6.EV_HP = Util.ToInt32(TB_HPEV.Text); // EVs pk6.EV_ATK = Util.ToInt32(TB_ATKEV.Text); pk6.EV_DEF = Util.ToInt32(TB_DEFEV.Text); pk6.EV_SPE = Util.ToInt32(TB_SPEEV.Text); pk6.EV_SPA = Util.ToInt32(TB_SPAEV.Text); pk6.EV_SPD = Util.ToInt32(TB_SPDEV.Text); pk6.CNT_Cool = Contest.Cool; pk6.CNT_Beauty = Contest.Beauty; pk6.CNT_Cute = Contest.Cute; pk6.CNT_Smart = Contest.Smart; pk6.CNT_Tough = Contest.Tough; pk6.CNT_Sheen = Contest.Sheen; pk6.PKRS_Days = CB_PKRSDays.SelectedIndex; pk6.PKRS_Strain = CB_PKRSStrain.SelectedIndex; // Already in buff (then transferred to new pkx) // 0x2C, 0x2D, 0x2E, 0x2F // 0x30, 0x31, 0x32, 0x33 // 0x34, 0x35, 0x36, 0x37 // 0x38, 0x39 // Unused // 0x3A, 0x3B // 0x3C, 0x3D, 0x3E, 0x3F // Block B // Convert Nickname field back to bytes pk6.Nickname = TB_Nickname.Text; pk6.Move1 = WinFormsUtil.GetIndex(CB_Move1); pk6.Move2 = WinFormsUtil.GetIndex(CB_Move2); pk6.Move3 = WinFormsUtil.GetIndex(CB_Move3); pk6.Move4 = WinFormsUtil.GetIndex(CB_Move4); pk6.Move1_PP = WinFormsUtil.GetIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0; pk6.Move2_PP = WinFormsUtil.GetIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0; pk6.Move3_PP = WinFormsUtil.GetIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0; pk6.Move4_PP = WinFormsUtil.GetIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0; pk6.Move1_PPUps = WinFormsUtil.GetIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0; pk6.Move2_PPUps = WinFormsUtil.GetIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0; pk6.Move3_PPUps = WinFormsUtil.GetIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0; pk6.Move4_PPUps = WinFormsUtil.GetIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0; pk6.RelearnMove1 = WinFormsUtil.GetIndex(CB_RelearnMove1); pk6.RelearnMove2 = WinFormsUtil.GetIndex(CB_RelearnMove2); pk6.RelearnMove3 = WinFormsUtil.GetIndex(CB_RelearnMove3); pk6.RelearnMove4 = WinFormsUtil.GetIndex(CB_RelearnMove4); // 0x72 - Ribbon editor sets this flag (Secret Super Training) // 0x73 pk6.IV_HP = Util.ToInt32(TB_HPIV.Text); pk6.IV_ATK = Util.ToInt32(TB_ATKIV.Text); pk6.IV_DEF = Util.ToInt32(TB_DEFIV.Text); pk6.IV_SPE = Util.ToInt32(TB_SPEIV.Text); pk6.IV_SPA = Util.ToInt32(TB_SPAIV.Text); pk6.IV_SPD = Util.ToInt32(TB_SPDIV.Text); pk6.IsEgg = CHK_IsEgg.Checked; pk6.IsNicknamed = CHK_Nicknamed.Checked; // Block C pk6.HT_Name = TB_OTt2.Text; // 0x90-0xAF pk6.HT_Gender = PKX.GetGender(Label_CTGender.Text) & 1; // Plus more, set by MemoryAmie (already in buff) // Block D pk6.OT_Name = TB_OT.Text; pk6.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); DateTime?egg_date = null; int egg_location = 0; if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields. { egg_date = CAL_EggDate.Value; egg_location = WinFormsUtil.GetIndex(CB_EggLocation); } // Egg Met Data pk6.EggMetDate = egg_date; pk6.Egg_Location = egg_location; // Met Data pk6.MetDate = CAL_MetDate.Value; pk6.Met_Location = WinFormsUtil.GetIndex(CB_MetLocation); if (pk6.IsEgg && pk6.Met_Location == 0) // If still an egg, it has no hatch location/date. Zero it! { pk6.MetDate = null; } // 0xD7 Unknown pk6.Ball = WinFormsUtil.GetIndex(CB_Ball); pk6.Met_Level = Util.ToInt32(TB_MetLevel.Text); pk6.OT_Gender = PKX.GetGender(Label_OTGender.Text); pk6.EncounterType = WinFormsUtil.GetIndex(CB_EncounterType); pk6.Version = WinFormsUtil.GetIndex(CB_GameOrigin); pk6.Country = WinFormsUtil.GetIndex(CB_Country); pk6.Region = WinFormsUtil.GetIndex(CB_SubRegion); pk6.ConsoleRegion = WinFormsUtil.GetIndex(CB_3DSReg); pk6.Language = WinFormsUtil.GetIndex(CB_Language); // 0xE4-0xE7 // Toss in Party Stats Array.Resize(ref pk6.Data, pk6.SIZE_PARTY); pk6.Stat_Level = Util.ToInt32(TB_Level.Text); pk6.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text); pk6.Stat_HPMax = Util.ToInt32(Stat_HP.Text); pk6.Stat_ATK = Util.ToInt32(Stat_ATK.Text); pk6.Stat_DEF = Util.ToInt32(Stat_DEF.Text); pk6.Stat_SPE = Util.ToInt32(Stat_SPE.Text); pk6.Stat_SPA = Util.ToInt32(Stat_SPA.Text); pk6.Stat_SPD = Util.ToInt32(Stat_SPD.Text); // Unneeded Party Stats (Status, Flags, Unused) pk6.Data[0xE8] = pk6.Data[0xE9] = pk6.Data[0xEA] = pk6.Data[0xEB] = pk6.Data[0xED] = pk6.Data[0xEE] = pk6.Data[0xEF] = pk6.Data[0xFE] = pk6.Data[0xFF] = pk6.Data[0x100] = pk6.Data[0x101] = pk6.Data[0x102] = pk6.Data[0x103] = 0; // Hax Illegality if (HaX) { pk6.Ability = (byte)WinFormsUtil.GetIndex(DEV_Ability); pk6.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue); } // Fix Moves if a slot is empty pk6.FixMoves(); pk6.FixRelearn(); // Fix Handler (Memories & OT) -- no foreign memories for Pokemon without a foreign trainer (none for eggs) if (ModifyPKM) { pk6.FixMemories(); } // PKX is now filled pk6.RefreshChecksum(); return(pk6); }
public async void RunBot() { try { Program.gCmdWindow.SetBotMode(true); while (botworking && Program.gCmdWindow.IsConnected) { switch (botstate) { case BotState.botstart: Report("Bot: START Gen 6 Wonder Trade bot"); botstate = BotState.backup; break; case BotState.backup: Report("Bot: Backup boxes"); waitTaskbool = Program.helper.waitNTRmultiread(pcpkmOff, 232 * 30 * 31); if (await waitTaskbool) { attempts = 0; string fileName = "WTBefore-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".ek6"; backuppath = wtfolderpath + fileName; Program.gCmdWindow.WriteDataToFile(Program.helper.lastmultiread, backuppath); botstate = BotState.testpssmenu; } else { attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.backup; } break; case BotState.testpssmenu: Report("Bot: Test if the PSS menu is shown"); waitTaskbool = Program.helper.memoryinrange(psssmenu1Off, psssmenu1IN, 0x10000); if (await waitTaskbool) { if (sourceBox.Checked) { botstate = BotState.readpoke; } else { botstate = BotState.readfolder; } } else { botresult = ErrorMessage.NotInPSS; botstate = BotState.endbot; } break; case BotState.readpoke: Report("Bot: Look for pokemon to trade"); waitTaskPKM = Program.helper.waitPokeRead(Box, Slot); WTpoke = await waitTaskPKM; if (WTpoke == null) { // No data or invalid attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.readpoke; } else if (WTpoke.Species == 0) { // Empty space Report("Bot: Empty slot"); attempts = 0; getNextSlot(); } else { // Valid pkm, check legality attempts = 0; if (IsTradeable(WTpoke)) { currentCHK = WTpoke.Checksum; Report("Bot: Pokémon found - 0x" + currentCHK.ToString("X4")); botstate = BotState.pressWTbutton; } else { if (Program.gCmdWindow.HaX) { Report("Bot: Pokémon cannot be traded, is an egg or have special ribbons."); } else { Report("Bot: Pokémon cannot be traded, is illegal or is an egg or have special ribbons."); } getNextSlot(); } } break; case BotState.readfolder: Report("Bot: Reading Wonder Trade folder"); pkfiles = Directory.GetFiles(wtfolderpath, "*.pk6"); if (pkfiles.Length > 0) { foreach (string pkf in pkfiles) { byte[] temp = File.ReadAllBytes(pkf); if (temp.Length == 232) { PK6 pkmn = new PK6(temp); if (IsTradeable(pkmn)) { // Legal pkm Report("Bot: Valid PK6 file"); pklist.Add(pkmn); } else { // Illegal pkm Report("Bot: File " + pkf + " cannot be traded"); } } else { // Not valid file Report("Bot: File " + pkf + " is not a valid pk6 file"); } } } if (pklist.Count > 0) { botstate = BotState.writefromfolder; } else { Report("Bot: No files detected"); botresult = ErrorMessage.Finished; botstate = BotState.endbot; } break; case BotState.writefromfolder: Report("Bot: Write pkm file from list"); if (sourceRandom.Checked) { // Select a random file currentfile = RNG.Next() % pklist.Count; } waitTaskbool = Program.helper.waitNTRwrite(GetBoxOffset(pcpkmOff, Box, Slot), pklist[currentfile].EncryptedBoxData, Program.gCmdWindow.pid); if (await waitTaskbool) { Program.gCmdWindow.UpdateDumpBoxes(Box, Slot); Program.gCmdWindow.Pokemon = pklist[currentfile]; currentCHK = pklist[currentfile].Checksum; if (sourceFolder.Checked) { currentfile++; if (currentfile > pklist.Count - 1) { currentfile = 0; } } attempts = 0; botstate = BotState.pressWTbutton; } else { attempts++; botresult = ErrorMessage.WriteError; botstate = BotState.writefromfolder; } break; case BotState.pressWTbutton: Report("Bot: Touch Wonder Trade button"); waitTaskbool = Program.helper.waittouch(240, 120); if (await waitTaskbool) { botstate = BotState.testsavescrn; } else { attempts++; botresult = ErrorMessage.TouchError; botstate = BotState.pressWTbutton; } break; case BotState.testsavescrn: Report("Bot: Test if the save screen is shown"); await Task.Delay(delaytime); waitTaskbool = Program.helper.timememoryinrange(savescrnOff, savescrnIN, 0x10000, 500, 5000); if (await waitTaskbool) { attempts = 0; botstate = BotState.confirmsave; } else { // If not in save screen, try again attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.pressWTbutton; } break; case BotState.confirmsave: Report("Bot: Press Yes"); await Task.Delay(delaytime); waitTaskbool = Program.helper.waitbutton(LookupTable.ButtonA); if (await waitTaskbool) { botstate = BotState.testwtscrn; } else { attempts++; botresult = ErrorMessage.ButtonError; botstate = BotState.confirmsave; } break; case BotState.testwtscrn: Report("Bot: Test if Wonder Trade screen is shown"); waitTaskbool = Program.helper.timememoryinrange(wtconfirmationOff, wtconfirmationIN, 0x10000, 500, 5000); if (await waitTaskbool) { attempts = 0; botstate = BotState.confirmwt; } else { attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.confirmsave; } break; case BotState.confirmwt: Report("Bot: Touch Yes"); await Task.Delay(delaytime); waitTaskbool = Program.helper.waittouch(160, 100); if (await waitTaskbool) { botstate = BotState.testboxes; } else { attempts++; botresult = ErrorMessage.TouchError; botstate = BotState.confirmwt; } break; case BotState.testboxes: Report("Bot: Test if the boxes are shown"); waitTaskbool = Program.helper.timememoryinrange(wtboxesOff, wtboxesIN, 0x10000, 500, 5000); if (await waitTaskbool) { attempts = 0; botstate = BotState.gotoboxchange; } else { attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.confirmwt; } break; case BotState.gotoboxchange: await Task.Delay(8 *delaytime); if (boxchange) { botstate = BotState.touchboxview; boxchange = false; } else { botstate = BotState.touchpoke; } break; case BotState.touchboxview: Report("Bot: Touch Box View"); waitTaskbool = Program.helper.waittouch(30, 220); if (await waitTaskbool) { botstate = BotState.testboxview; } else { attempts++; botresult = ErrorMessage.TouchError; botstate = BotState.touchboxview; } break; case BotState.testboxview: Report("Bot: Test if box view is shown"); waitTaskbool = Program.helper.timememoryinrange(wtboxviewOff, wtboxviewIN, wtboxviewRange, 500, 5000); if (await waitTaskbool) { attempts = 0; botstate = BotState.touchnewbox; } else { attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.touchboxview; } break; case BotState.touchnewbox: Report("Bot: Touch New Box"); await Task.Delay(delaytime); waitTaskbool = Program.helper.waittouch(LookupTable.boxposX6[GetIndex(Box)], LookupTable.boxposY6[GetIndex(Box)]); if (await waitTaskbool) { attempts = 0; botstate = BotState.selectnewbox; } else { attempts++; botresult = ErrorMessage.TouchError; botstate = BotState.touchboxview; } break; case BotState.selectnewbox: Report("Bot: Select New Box"); await Task.Delay(delaytime); waitTaskbool = Program.helper.waitbutton(LookupTable.ButtonA); if (await waitTaskbool) { botstate = BotState.testboxviewout; } else { attempts++; botresult = ErrorMessage.ButtonError; botstate = BotState.confirmsave; } break; case BotState.testboxviewout: Report("Bot: Test if box view is not shown"); waitTaskbool = Program.helper.timememoryinrange(wtboxviewOff, wtboxviewOUT, wtboxviewRange, 500, 5000); if (await waitTaskbool) { attempts = 0; botstate = BotState.touchpoke; } else { attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.touchnewbox; } break; case BotState.touchpoke: Report("Bot: Touch Pokémon"); await Task.Delay(delaytime); waitTaskbool = Program.helper.waittouch(LookupTable.pokeposX6[GetIndex(Slot)], LookupTable.pokeposY6[GetIndex(Slot)]); if (await waitTaskbool) { attempts = 0; botstate = BotState.selectrade; } else { attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.touchpoke; } break; case BotState.selectrade: Report("Bot: Select Trade"); await Task.Delay(2 *delaytime); waitTaskbool = Program.helper.waitbutton(LookupTable.ButtonA); if (await waitTaskbool) { attempts = 0; botstate = BotState.confirmsend; } else { attempts++; botresult = ErrorMessage.ButtonError; botstate = BotState.selectrade; } break; case BotState.confirmsend: Report("Bot: Select Yes"); await Task.Delay(2 *delaytime); waitTaskbool = Program.helper.waitbutton(LookupTable.ButtonA); if (await waitTaskbool) { attempts = 0; botstate = BotState.testboxesout; } else { attempts++; botresult = ErrorMessage.ButtonError; botstate = BotState.confirmsend; } break; case BotState.testboxesout: Report("Bot: Test if the boxes are not shown"); waitTaskbool = Program.helper.timememoryinrange(wtboxesOff, wtboxesOUT, 0x10000, 500, 5000); if (await waitTaskbool) { attempts = 0; tradewait = 0; botstate = BotState.waitfortrade; } else { attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.touchpoke; } break; case BotState.waitfortrade: Report("Bot: Wait for trade"); ushort newCHK; waitTaskPKM = Program.helper.waitPokeRead(Box, Slot); WTpoke = await waitTaskPKM; if (WTpoke == null) { newCHK = (ushort)(currentCHK + 1); } else if (WTpoke.Species == 0) { newCHK = (ushort)(currentCHK + 1); } else { newCHK = WTpoke.Checksum; } if (newCHK == currentCHK) { await Task.Delay(8 *delaytime); tradewait++; if (tradewait > 30) // Too much time passed { attempts = 0; botstate = BotState.notradepartner; } } else { Report("Bot: Wait 30 seconds"); await Task.Delay(30000); botstate = BotState.testbackpssmenu; } break; case BotState.testbackpssmenu: Report("Bot: Test if back to the PSS menu"); waitTaskbool = Program.helper.timememoryinrange(psssmenu1Off, psssmenu1IN, 0x10000, 2000, 10000); if (await waitTaskbool) { // Trade sucessfull attempts = 0; getNextSlot(); } else { // Still waiting attempts++; botresult = ErrorMessage.GeneralError; botstate = BotState.testbackpssmenu; } break; case BotState.notradepartner: Report("Bot: Test if back to the PSS menu"); waitTaskbool = Program.helper.timememoryinrange(psssmenu1Off, psssmenu1IN, 0x10000, 500, 3000); if (await waitTaskbool) { // Back in menu attempts = 0; botstate = BotState.pressWTbutton; } else { // Still waiting attempts++; botresult = ErrorMessage.GeneralError; Report("Bot: Select Yes"); Program.helper.quickbuton(LookupTable.ButtonA, commandtime); await Task.Delay(commandtime + delaytime); botstate = BotState.notradepartner; } break; case BotState.dumpafter: if (afterDump.Checked) { Report("Bot: Dump boxes"); waitTaskbool = Program.helper.waitNTRmultiread(pcpkmOff, 232 * 30 * 31); if (await waitTaskbool) { attempts = 0; string fileName = "WTAfter-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".ek6"; Program.gCmdWindow.WriteDataToFile(Program.helper.lastmultiread, wtfolderpath + fileName); botstate = BotState.actionafter; } else { attempts++; botresult = ErrorMessage.ReadError; botstate = BotState.dumpafter; } } else { botstate = BotState.actionafter; } break; case BotState.actionafter: if (afterRestore.Checked) { botstate = BotState.restorebackup; } else if (afterDelete.Checked) { botstate = BotState.delete; } else { botresult = ErrorMessage.Finished; botstate = BotState.endbot; } break; case BotState.restorebackup: Report("Bot: Restore boxes backup"); byte[] restore = File.ReadAllBytes(backuppath); if (restore.Length == 232 * 30 * 31) { waitTaskbool = Program.helper.waitNTRwrite(pcpkmOff, restore, Program.gCmdWindow.pid); if (await waitTaskbool) { attempts = 0; botresult = ErrorMessage.Finished; botstate = BotState.endbot; } else { attempts++; botresult = ErrorMessage.WriteError; botstate = BotState.restorebackup; } } else { Report("Bot: Invalid boxes file"); botresult = ErrorMessage.GeneralError; botstate = BotState.endbot; } break; case BotState.delete: Report("Bot: Delete traded pokémon"); byte[] deletearray = new byte[232 * (int)starttrades]; for (int i = 0; i < starttrades; i++) { Program.gCmdWindow.SAV.BlankPKM.EncryptedBoxData.CopyTo(deletearray, i * 232); } waitTaskbool = Program.helper.waitNTRwrite(GetBoxOffset(pcpkmOff, Box, Slot), deletearray, Program.gCmdWindow.pid); if (await waitTaskbool) { attempts = 0; botstate = BotState.endbot; } else { attempts++; botresult = ErrorMessage.WriteError; botstate = BotState.delete; } break; case BotState.endbot: Report("Bot: STOP Gen 6 Wonder Trade bot"); botworking = false; break; default: Report("Bot: STOP Gen 6 Wonder Trade 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(10 *delaytime); attempts = 0; } else { botresult = ErrorMessage.GeneralError; botworking = false; } } else { Report("Bot: Maximum number of reconnection attempts reached"); Report("Bot: STOP Gen 6 Wonder Trade bot"); botworking = false; } } } } catch (Exception ex) { Report("Bot: Exception detected:"); Report(ex.Source); Report(ex.Message); Report(ex.StackTrace); Report("Bot: STOP Gen 6 Wonder Trade bot"); MessageBox.Show(ex.Message); botworking = false; botresult = ErrorMessage.GeneralError; } if (userstop) { botresult = ErrorMessage.UserStop; } else if (!Program.gCmdWindow.IsConnected) { botresult = ErrorMessage.Disconnect; } ShowResult("Wonder Trade bot", botresult); Delg.SetText(RunStop, "Start Bot"); Program.gCmdWindow.SetBotMode(false); EnableControls(); Delg.SetEnabled(RunStop, true); }
public void AddToBoxesButtonClick(Object sender, EventArgs events) { var sav = SaveFileEditor.SAV; // current save int generation = sav.Generation; // the generation of the current save -- used to determine the PK save format List <PKM> pokemonList = new List <PKM>(); // list of all Pokemon that will be added to the sav string showdownData = this.input.Text; // user's input var pokemonArray = JsonConvert.DeserializeObject <List <RawPokemon> >(showdownData); //jsonify the data foreach (RawPokemon rawPokemon in pokemonArray) { PKM pokemon = new PK2(); //Determine save format switch (generation) { case 1: pokemon = new PK1(); break; case 2: pokemon = new PK2(); break; case 3: pokemon = new PK3(); break; case 4: pokemon = new PK4(); break; case 5: pokemon = new PK5(); break; case 6: pokemon = new PK6(); break; case 7: pokemon = new PK7(); break; case 8: pokemon = new PK8(); break; } // Set the species according to the Species enum int speciesAsNumber = 0; //Check if the Pokemon is Alolan or not; if it is, do some extra logic to set the proper form if (rawPokemon.Species.Contains("Alolan")) { string[] pokemon_name = rawPokemon.Species.Split('_'); speciesAsNumber = (int)(Species)Enum.Parse(typeof(Species), pokemon_name[1]); pokemon.SetForm(810); pokemon.Species = speciesAsNumber; } else { speciesAsNumber = (int)(Species)Enum.Parse(typeof(Species), rawPokemon.Species); pokemon.Species = speciesAsNumber; } // Check to see if the Pokemon has forms (i.e. Flabebe, Shellos, etc.), and if it does, randomly generate one if (rawPokemon.Species.Contains("Burmy")) { int form = random.Next(0, burmyForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Shellos")) { int form = random.Next(0, shellosForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Scatterbug")) { int form = random.Next(0, scatterbugForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Flabébé")) { int form = random.Next(0, flabebeForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Oricorio")) { int form = random.Next(0, oricorioForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Minior")) { int form = random.Next(0, miniorForms.Length - 1); pokemon.SetForm(form); } GameVersion game = (GameVersion)sav.Game; EncounterEgg encounterEgg = new EncounterEgg(speciesAsNumber, pokemon.Form, 1, sav.Generation, game); PKM pokemonAsEgg = encounterEgg.ConvertToPKM(sav); pokemonAsEgg.IsEgg = true; pokemon.IsNicknamed = true; pokemon.Nickname = "Egg"; // Set the ability string ability = rawPokemon.Ability.Replace(" ", ""); int abilityAsNumber = (int)(Ability)Enum.Parse(typeof(Ability), ability); pokemonAsEgg.SetAbility(abilityAsNumber); //Set gender switch (rawPokemon.Gender) { case "M": pokemonAsEgg.SetGender(0); break; case "F": pokemonAsEgg.SetGender(1); break; case "N": pokemonAsEgg.SetGender(2); break; } // Set Nature via the Nature enum int natureAsNumber = (int)(Nature)Enum.Parse(typeof(Nature), rawPokemon.Nature); pokemonAsEgg.Nature = natureAsNumber; // Set the IVs pokemonAsEgg.IV_HP = rawPokemon.HP; pokemonAsEgg.IV_ATK = rawPokemon.Atk; pokemonAsEgg.IV_DEF = rawPokemon.Def; pokemonAsEgg.IV_SPA = rawPokemon.SpA; pokemonAsEgg.IV_SPD = rawPokemon.SpD; pokemonAsEgg.IV_SPE = rawPokemon.Spe; // Set moves and make sure they have the proper PP string move = ""; if (string.IsNullOrEmpty(rawPokemon.MoveOne) == false) { move = rawPokemon.MoveOne.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move1 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove1 = pokemonAsEgg.Move1; } if (string.IsNullOrEmpty(rawPokemon.MoveTwo) == false) { move = rawPokemon.MoveTwo.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move2 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove2 = pokemonAsEgg.Move2; } if (string.IsNullOrEmpty(rawPokemon.MoveThree) == false) { move = rawPokemon.MoveThree.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move3 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove3 = pokemonAsEgg.Move3; } if (string.IsNullOrEmpty(rawPokemon.MoveFour) == false) { move = rawPokemon.MoveFour.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move4 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove4 = pokemonAsEgg.Move4; } pokemonAsEgg.SetMaximumPPCurrent(); //Finally, if the Pokemon is supposed to be shiny, make it so if (rawPokemon.IsShiny == "true") { CommonEdits.SetShiny(pokemonAsEgg); } else { CommonEdits.SetUnshiny(pokemonAsEgg); } pokemonAsEgg.Met_Location = 0; if (generation == 7 || generation == 6 || generation == 5) { pokemonAsEgg.Egg_Location = Locations.Daycare5; } else { pokemonAsEgg.Egg_Location = Locations.Daycare4; } pokemonAsEgg.IsNicknamed = true; pokemonAsEgg.Nickname = SpeciesName.GetSpeciesNameGeneration(0, sav.Language, generation); //Hatch counter is for some reason called "CurrentFriendship". Don't ask me why, I don't know. pokemonAsEgg.CurrentFriendship = 1; pokemonList.Add(pokemonAsEgg); } // Import Pokemon, reload the boxes so they can be seen, show a message and close the window sav.ImportPKMs(pokemonList); SaveFileEditor.ReloadSlots(); MessageBox.Show("Done!"); this.input.Clear(); this.form.Close(); }