internal static IEnumerable<int> getBaseEggMoves(PKM pkm, int skipOption, GameVersion gameSource) { int species = getBaseSpecies(pkm, skipOption); if (gameSource == GameVersion.Any) gameSource = (GameVersion) pkm.Version; switch (gameSource) { case GameVersion.X: case GameVersion.Y: case GameVersion.XY: if (pkm.InhabitedGeneration(6)) return LevelUpXY[species].getMoves(1); break; case GameVersion.AS: case GameVersion.OR: case GameVersion.ORAS: if (pkm.InhabitedGeneration(6)) return LevelUpAO[species].getMoves(1); break; case GameVersion.SN: case GameVersion.MN: case GameVersion.SM: if (pkm.InhabitedGeneration(7)) return LevelUpSM[species].getMoves(1); break; } return null; }
public LegalityAnalysis(PKM pk) { for (int i = 0; i < 4; i++) { vMoves[i] = new CheckResult(CheckIdentifier.Move); vRelearn[i] = new CheckResult(CheckIdentifier.RelearnMove); } try { switch (pk.GenNumber) { case 6: parsePK6(pk); break; case 7: parsePK7(pk); break; default: return; } Valid = Parsed = Parse.Any(); if (Parsed) { if (Parse.Any(chk => !chk.Valid)) Valid = false; if (vMoves.Any(m => m.Valid != true)) Valid = false; else if (vRelearn.Any(m => m.Valid != true)) Valid = false; if (pkm.FatefulEncounter && vRelearn.Any(chk => !chk.Valid) && EncounterMatch == null) AddLine(Severity.Indeterminate, "Fateful Encounter with no matching Encounter. Has the Mystery Gift data been contributed?", CheckIdentifier.Fateful); } } catch { Valid = false; } getLegalityReport(); }
private static ModifyResult ProcessPKM(PKM PKM, IEnumerable<StringInstruction> Filters, IEnumerable<StringInstruction> Instructions) { if (!PKM.ChecksumValid || PKM.Species == 0) return ModifyResult.Invalid; Type pkm = PKM.GetType(); foreach (var cmd in Filters) { try { if (!pkm.HasProperty(cmd.PropertyName)) return ModifyResult.Filtered; if (ReflectUtil.GetValueEquals(PKM, cmd.PropertyName, cmd.PropertyValue) != cmd.Evaluator) return ModifyResult.Filtered; } catch { Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); return ModifyResult.Filtered; } } ModifyResult result = ModifyResult.Error; foreach (var cmd in Instructions) { try { if (cmd.PropertyName == "MetDate") PKM.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); else if (cmd.PropertyName == "EggMetDate") PKM.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); else if (cmd.PropertyName == "EncryptionConstant" && cmd.PropertyValue == CONST_RAND) ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString()); else if(cmd.PropertyName == "PID" && cmd.PropertyValue == CONST_RAND) PKM.setPIDGender(PKM.Gender); else if (cmd.PropertyName == "EncryptionConstant" && cmd.PropertyValue == "PID") PKM.EncryptionConstant = PKM.PID; else if (cmd.PropertyName == "PID" && cmd.PropertyValue == CONST_SHINY) PKM.setShinyPID(); else if (cmd.PropertyName == "Species" && cmd.PropertyValue == "0") PKM.Data = new byte[PKM.Data.Length]; else ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue); result = ModifyResult.Modified; } catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); } } return result; }
internal static PKM convertToFormat(PKM pk, int Format, out string comment) { if (pk == null) { comment = "Null input. Aborting."; return null; } if (pk.Format == Format) { comment = "No need to convert, current format matches requested format."; return pk; } if (pk.Format > Format) { comment = "Cannot convert a PKM backwards." + Environment.NewLine + "Current Format: " + pk.Format + Environment.NewLine + "Desired Format: " + Format; return null; } string currentFormat = pk.Format.ToString(); PKM pkm = pk.Clone(); if (pkm.IsEgg) // force hatch { pkm.IsEgg = false; if (pkm.AO) pkm.Met_Location = 318; // Battle Resort else if (pkm.XY) pkm.Met_Location = 38; // Route 7 else if (pkm.Gen5) pkm.Met_Location = 16; // Route 16 else pkm.Met_Location = 30001; // Pokétransfer } if (pkm.Format == 3 && Format > 3) pkm = (pkm as PK3).convertToPK4(); if (pkm.Format == 4 && Format > 4) pkm = (pkm as PK4).convertToPK5(); if (pkm.Format == 5 && Format > 5) pkm = (pkm as PK5).convertToPK6(); comment = $"Converted from pk{currentFormat} to pk{Format}"; return pkm; }
public LegalityAnalysis(PKM pk) { try { switch (pk.Format) { case 6: parsePK6(pk); break; case 7: parsePK7(pk); break; default: return; } Valid = Parse.Any() && Parse.All(chk => chk.Valid); if (vMoves.Any(m => m.Valid != true)) Valid = false; else if (vRelearn.Any(m => m.Valid != true)) Valid = false; } catch { Valid = false; } Parsed = true; if (pkm.FatefulEncounter && vRelearn.Any(chk => !chk.Valid) && EncounterMatch == null) AddLine(Severity.Indeterminate, "Fateful Encounter with no matching Encounter. Has the Mystery Gift data been contributed?", CheckIdentifier.Fateful); }
public IEnumerable<DexLevel> getExplicitLineage(PKM pkm, int lvl, int maxSpecies) { List<DexLevel> dl = new List<DexLevel> { new DexLevel { Species = pkm.Species, Level = lvl, Form = pkm.AltForm } }; for (int i = Chain.Count-1; i >= 0; i--) // reverse evolution! { foreach (var evo in Chain[i].StageEntryMethods) { if (!evo.Valid(pkm, lvl)) continue; if (evo.Species > maxSpecies) // Gen7 Personal Formes -- unmap the forme personal entry to the actual species ID since species are consecutive dl.Add(evo.GetDexLevel(pkm.Species - Chain.Count + i, lvl)); else dl.Add(evo.GetDexLevel(lvl)); if (evo.RequiresLevelUp) lvl--; break; } } return dl; }
private void showLegality(PKM pk, bool tabs, bool verbose) { LegalityAnalysis la = new LegalityAnalysis(pk); if (!la.Native) { Util.Alert($"Checking legality of PK{pk.Format} files that originated from Gen{pk.GenNumber} is not supported."); return; } if (tabs) updateLegality(la); Util.Alert(verbose ? la.VerboseReport : la.Report); }
private void openSAV(SaveFile sav, string path) { if (sav == null || sav.Version == GameVersion.Invalid) { Util.Error("Invalid save file loaded. Aborting.", path); return; } // Finish setting up the save file. if (sav.IndeterminateGame && sav.Generation == 3) { // Hacky cheats invalidated the Game Code value. var drGame = Util.Prompt(MessageBoxButtons.YesNoCancel, "Unknown Gen3 Game Detected. Select Origins:", "Yes: Ruby / Sapphire" + Environment.NewLine + "No: Emerald" + Environment.NewLine + "Cancel: FireRed / LeafGreen"); switch (drGame) // Reset save file info { case DialogResult.Yes: sav = new SAV3(sav.BAK, GameVersion.RS); break; case DialogResult.No: sav = new SAV3(sav.BAK, GameVersion.E); break; case DialogResult.Cancel: sav = new SAV3(sav.BAK, GameVersion.FRLG); break; default: return; } } if (sav.IndeterminateLanguage) { // Japanese Save files are different. Get isJapanese var drJP = Util.Prompt(MessageBoxButtons.YesNoCancel, $"{sav.Version} Save File detected. Select language...", "Yes: International" + Environment.NewLine + "No: Japanese"); if (drJP == DialogResult.Cancel) return; sav.Japanese = drJP == DialogResult.No; } if (sav.IndeterminateSubVersion && sav.Version == GameVersion.FRLG) { var drFRLG = Util.Prompt(MessageBoxButtons.YesNoCancel, $"{sav.Version} detected. Select version...", "Yes: FireRed" + Environment.NewLine + "No: LeafGreen"); if (drFRLG == DialogResult.Cancel) return; sav.Personal = drFRLG == DialogResult.Yes ? PersonalTable.FR : PersonalTable.LG; } // clean fields PKM pk = preparePKM(); populateFields(SAV.BlankPKM); SAV = sav; if (path != null) // Actual save file { SAV.FilePath = Path.GetDirectoryName(path); SAV.FileName = Path.GetExtension(path) == ".bak" ? Path.GetFileName(path).Split(new[] { " [" }, StringSplitOptions.None)[0] : Path.GetFileName(path); Text = $"PKH{(HaX ? "a" : "e")}X - " + $"SAV{SAV.Generation}: {Path.GetFileNameWithoutExtension(Util.CleanFileName(SAV.BAKName))}"; // more descriptive // If backup folder exists, save a backup. string backupName = Path.Combine(BackupPath, Util.CleanFileName(SAV.BAKName)); if (SAV.Exportable && Directory.Exists(BackupPath) && !File.Exists(backupName)) File.WriteAllBytes(backupName, SAV.BAK); GB_SAVtools.Visible = true; } else // Blank save file { SAV.FilePath = null; SAV.FileName = "Blank Save File"; Text = $"PKH{(HaX ? "a" : "e")}X - " + $"SAV{SAV.Generation}: {SAV.FileName} [{SAV.OT} ({SAV.Version})]"; GB_SAVtools.Visible = false; } Menu_ExportSAV.Enabled = B_VerifyCHK.Enabled = SAV.Exportable; // Close subforms that are save dependent Type[] f = { typeof(SAV_BoxViewer), typeof(f2_Text) }; foreach (var form in Application.OpenForms.Cast<Form>().Where(form => f.Contains(form.GetType())).ToArray()) form.Close(); setBoxNames(); // Display the Box Names if (SAV.HasBox) { int startBox = path == null ? 0 : SAV.CurrentBox; // FF if BattleBox if (startBox > SAV.BoxCount - 1) { tabBoxMulti.SelectedIndex = 1; CB_BoxSelect.SelectedIndex = 0; } else { tabBoxMulti.SelectedIndex = 0; CB_BoxSelect.SelectedIndex = startBox; } } setPKXBoxes(); // Reload all of the PKX Windows bool WindowTranslationRequired = false; // Hide content if not present in game. GB_SUBE.Visible = SAV.HasSUBE; PB_Locked.Visible = SAV.HasBattleBox && SAV.BattleBoxLocked; if (!SAV.HasBox && tabBoxMulti.TabPages.Contains(Tab_Box)) tabBoxMulti.TabPages.Remove(Tab_Box); else if (SAV.HasBox && !tabBoxMulti.TabPages.Contains(Tab_Box)) { tabBoxMulti.TabPages.Insert(0, Tab_Box); WindowTranslationRequired = true; } Menu_LoadBoxes.Enabled = Menu_DumpBoxes.Enabled = Menu_Report.Enabled = Menu_Modify.Enabled = B_SaveBoxBin.Enabled = SAV.HasBox; int BoxTab = tabBoxMulti.TabPages.IndexOf(Tab_Box); int PartyTab = tabBoxMulti.TabPages.IndexOf(Tab_PartyBattle); if (!SAV.HasParty && tabBoxMulti.TabPages.Contains(Tab_PartyBattle)) tabBoxMulti.TabPages.Remove(Tab_PartyBattle); else if (SAV.HasParty && !tabBoxMulti.TabPages.Contains(Tab_PartyBattle)) { int index = BoxTab; if (index < 0) index = -1; tabBoxMulti.TabPages.Insert(index + 1, Tab_PartyBattle); WindowTranslationRequired = true; } if (!SAV.HasDaycare && tabBoxMulti.TabPages.Contains(Tab_Other)) tabBoxMulti.TabPages.Remove(Tab_Other); else if (SAV.HasDaycare && !tabBoxMulti.TabPages.Contains(Tab_Other)) { int index = PartyTab; if (index < 0) index = BoxTab; if (index < 0) index = -1; tabBoxMulti.TabPages.Insert(index + 1, Tab_Other); WindowTranslationRequired = true; } if (path != null) // Actual save file { PAN_BattleBox.Visible = L_BattleBox.Visible = L_ReadOnlyPBB.Visible = SAV.HasBattleBox; GB_Daycare.Visible = SAV.HasDaycare; GB_Fused.Visible = SAV.HasFused; GB_GTS.Visible = SAV.HasGTS; B_OpenSecretBase.Enabled = SAV.HasSecretBase; B_OpenPokepuffs.Enabled = SAV.HasPuff; B_OUTPasserby.Enabled = SAV.HasPSS; B_OpenBoxLayout.Enabled = SAV.HasBoxWallpapers; B_OpenWondercards.Enabled = SAV.HasWondercards; B_OpenSuperTraining.Enabled = SAV.HasSuperTrain; B_OpenHallofFame.Enabled = SAV.HasHoF; B_OpenOPowers.Enabled = SAV.HasOPower; B_OpenPokedex.Enabled = SAV.HasPokeDex; B_OpenBerryField.Enabled = SAV.HasBerryField && SAV.XY; B_OpenPokeblocks.Enabled = SAV.HasPokeBlock; B_JPEG.Enabled = SAV.HasJPEG; B_OpenEventFlags.Enabled = SAV.HasEvents; B_OpenLinkInfo.Enabled = SAV.HasLink; B_CGearSkin.Enabled = SAV.Generation == 5; B_OpenTrainerInfo.Visible = B_OpenItemPouch.Visible = SAV.HasParty; // Box RS } GB_SAVtools.Visible = FLP_SAVtools.Controls.Cast<Control>().Any(c => c.Enabled); foreach (Control c in FLP_SAVtools.Controls.Cast<Control>()) c.Visible = c.Enabled; // Generational Interface byte[] extraBytes = new byte[1]; Tip1.RemoveAll(); Tip2.RemoveAll(); Tip3.RemoveAll(); // TSV/PSV FLP_Country.Visible = FLP_SubRegion.Visible = FLP_3DSRegion.Visible = SAV.Generation >= 6; Label_EncryptionConstant.Visible = BTN_RerollEC.Visible = TB_EC.Visible = SAV.Generation >= 6; GB_nOT.Visible = GB_RelearnMoves.Visible = BTN_Medals.Visible = BTN_History.Visible = SAV.Generation >= 6; PB_Legal.Visible = PB_WarnMove1.Visible = PB_WarnMove2.Visible = PB_WarnMove3.Visible = PB_WarnMove4.Visible = SAV.Generation >= 6; PB_MarkPentagon.Visible = SAV.Generation >= 6; PB_MarkAlola.Visible = SAV.Generation >= 7; TB_Secure1.Visible = TB_Secure2.Visible = L_GameSync.Visible = L_Secure1.Visible = L_Secure2.Visible = SAV.Exportable && SAV.Generation >= 6; TB_GameSync.Visible = SAV.Exportable && SAV.Generation == 6; FLP_NSparkle.Visible = L_NSparkle.Visible = CHK_NSparkle.Visible = SAV.Generation == 5; CB_Form.Visible = Label_Form.Visible = CHK_AsEgg.Visible = GB_EggConditions.Visible = PB_Mark5.Visible = PB_Mark6.Visible = SAV.Generation >= 4; DEV_Ability.Enabled = DEV_Ability.Visible = SAV.Generation > 3 && HaX; CB_Ability.Visible = !DEV_Ability.Enabled && SAV.Generation >= 3; FLP_Nature.Visible = SAV.Generation >= 3; FLP_Ability.Visible = SAV.Generation >= 3; FLP_Language.Visible = SAV.Generation >= 3; GB_ExtraBytes.Visible = GB_ExtraBytes.Enabled = SAV.Generation >= 3; GB_Markings.Visible = SAV.Generation >= 3; BTN_Ribbons.Visible = SAV.Generation >= 3; CB_HPType.Enabled = CB_Form.Enabled = SAV.Generation >= 3; BTN_RerollPID.Visible = Label_PID.Visible = TB_PID.Visible = Label_SID.Visible = TB_SID.Visible = SAV.Generation >= 3; FLP_FriendshipForm.Visible = SAV.Generation >= 2; FLP_HeldItem.Visible = SAV.Generation >= 2; CHK_IsEgg.Visible = Label_Gender.Visible = SAV.Generation >= 2; FLP_PKRS.Visible = FLP_EggPKRSRight.Visible = SAV.Generation >= 2; Label_OTGender.Visible = SAV.Generation >= 2; if (SAV.Generation == 1) Label_IsShiny.Visible = false; if (SAV.Version == GameVersion.BATREV) { L_SaveSlot.Visible = CB_SaveSlot.Visible = true; CB_SaveSlot.Items.Clear(); CB_SaveSlot.DisplayMember = "Text"; CB_SaveSlot.ValueMember = "Value"; CB_SaveSlot.DataSource = new BindingSource(((SAV4BR) SAV).SaveSlots.Select(i => new ComboItem { Text = ((SAV4BR) SAV).SaveNames[i], Value = i }).ToList(), null); CB_SaveSlot.SelectedValue = ((SAV4BR)SAV).CurrentSlot; } else L_SaveSlot.Visible = CB_SaveSlot.Visible = false; FLP_Purification.Visible = FLP_ShadowID.Visible = SAV.Version == GameVersion.COLO || SAV.Version == GameVersion.XD; NUD_ShadowID.Maximum = SAV.MaxShadowID; // HaX override, needs to be after DEV_Ability enabled assignment. TB_AbilityNumber.Visible = SAV.Generation >= 6 && DEV_Ability.Enabled; // Met Tab FLP_MetDate.Visible = SAV.Generation >= 4; FLP_Fateful.Visible = FLP_Ball.Visible = FLP_OriginGame.Visible = SAV.Generation >= 3; FLP_MetLocation.Visible = FLP_MetLevel.Visible = SAV.Generation >= 2; FLP_TimeOfDay.Visible = SAV.Generation == 2; // Stats FLP_StatsTotal.Visible = SAV.Generation >= 3; FLP_Characteristic.Visible = SAV.Generation >= 3; FLP_HPType.Visible = SAV.Generation >= 2; PAN_Contest.Visible = SAV.Generation >= 3; // Second daycare slot SlotPictureBoxes[43].Visible = SAV.Generation >= 2; if (sav.Generation == 1) { FLP_SpD.Visible = false; Label_SPA.Visible = false; Label_SPC.Visible = true; TB_HPIV.Enabled = false; MaskedTextBox[] evControls = { TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV }; foreach (var ctrl in evControls) { ctrl.Mask = "00000"; ctrl.Size = Stat_HP.Size; } } else if (sav.Generation == 2) { FLP_SpD.Visible = true; Label_SPA.Visible = true; Label_SPC.Visible = false; TB_SPDEV.Enabled = TB_SPDIV.Enabled = false; TB_HPIV.Enabled = false; MaskedTextBox[] evControls = { TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV }; foreach (var ctrl in evControls) { ctrl.Mask = "00000"; ctrl.Size = Stat_HP.Size; } } else { FLP_SpD.Visible = true; Label_SPA.Visible = true; Label_SPC.Visible = false; TB_SPDEV.Enabled = TB_SPDIV.Enabled = true; TB_HPIV.Enabled = true; MaskedTextBox[] evControls = { TB_SPAEV, TB_HPEV, TB_ATKEV, TB_DEFEV, TB_SPEEV, TB_SPDEV }; foreach (var ctrl in evControls) { ctrl.Mask = "000"; ctrl.Size = TB_ExtraByte.Size; } } // Recenter PKM SubEditors FLP_PKMEditors.Location = new Point((Tab_OTMisc.Width - FLP_PKMEditors.Width) / 2, FLP_PKMEditors.Location.Y); switch (SAV.Generation) { case 1: getFieldsfromPKM = populateFieldsPK1; getPKMfromFields = preparePK1; extraBytes = new byte[] {}; break; case 2: getFieldsfromPKM = populateFieldsPK2; getPKMfromFields = preparePK2; extraBytes = new byte[] { }; break; case 3: if (SAV.Version == GameVersion.COLO) { getFieldsfromPKM = populateFieldsCK3; getPKMfromFields = prepareCK3; extraBytes = CK3.ExtraBytes; break; } if (SAV.Version == GameVersion.XD) { getFieldsfromPKM = populateFieldsXK3; getPKMfromFields = prepareXK3; extraBytes = XK3.ExtraBytes; break; } getFieldsfromPKM = populateFieldsPK3; getPKMfromFields = preparePK3; extraBytes = PK3.ExtraBytes; break; case 4: if (SAV.Version == GameVersion.BATREV) { getFieldsfromPKM = populateFieldsBK4; getPKMfromFields = prepareBK4; } else { getFieldsfromPKM = populateFieldsPK4; getPKMfromFields = preparePK4; } extraBytes = PK4.ExtraBytes; break; case 5: getFieldsfromPKM = populateFieldsPK5; getPKMfromFields = preparePK5; extraBytes = PK5.ExtraBytes; break; case 6: getFieldsfromPKM = populateFieldsPK6; getPKMfromFields = preparePK6; extraBytes = PK6.ExtraBytes; TB_GameSync.Enabled = (SAV.GameSyncID ?? 0) != 0; TB_GameSync.Text = SAV.GameSyncID?.ToString("X16"); TB_Secure1.Text = SAV.Secure1?.ToString("X16"); TB_Secure2.Text = SAV.Secure2?.ToString("X16"); break; case 7: getFieldsfromPKM = populateFieldsPK7; getPKMfromFields = preparePK7; extraBytes = PK7.ExtraBytes; TB_GameSync.Enabled = (SAV.GameSyncID ?? 0) != 0; TB_GameSync.Text = SAV.GameSyncID?.ToString("X16"); TB_Secure1.Text = SAV.Secure1?.ToString("X16"); TB_Secure2.Text = SAV.Secure2?.ToString("X16"); break; } bool init = fieldsInitialized; fieldsInitialized = fieldsLoaded = false; pkm = pkm.GetType() != SAV.PKMType ? SAV.BlankPKM : pk; if (pkm.Format < 3) pkm = SAV.BlankPKM; populateFilteredDataSources(); populateFields(pkm); fieldsInitialized |= init; // SAV Specific Limits TB_OT.MaxLength = SAV.OTLength; TB_OTt2.MaxLength = SAV.OTLength; TB_Nickname.MaxLength = SAV.NickLength; // Hide Unused Tabs if (SAV.Generation == 1 && tabMain.TabPages.Contains(Tab_Met)) tabMain.TabPages.Remove(Tab_Met); else if (SAV.Generation != 1 && !tabMain.TabPages.Contains(Tab_Met)) { tabMain.TabPages.Insert(1, Tab_Met); WindowTranslationRequired = true; } // Common HaX Interface CHK_HackedStats.Enabled = CHK_HackedStats.Visible = MT_Level.Enabled = MT_Level.Visible = MT_Form.Enabled = MT_Form.Visible = HaX; TB_Level.Visible = !HaX; // Load Extra Byte List if (GB_ExtraBytes.Enabled) { CB_ExtraBytes.Items.Clear(); foreach (byte b in extraBytes) CB_ExtraBytes.Items.Add("0x" + b.ToString("X2")); CB_ExtraBytes.SelectedIndex = 0; } // pk2 save files do not have an Origin Game stored. Prompt the met location list to update. if (SAV.Generation == 2) updateOriginGame(null, null); // Refresh PK* conversion info PKMConverter.updateConfig(SAV.SubRegion, SAV.Country, SAV.ConsoleRegion, SAV.OT, SAV.Gender); if (WindowTranslationRequired) // force update -- re-added controls may be untranslated Util.TranslateInterface(this, curlanguage); // No changes made yet UndoStack.Clear(); Menu_Undo.Enabled = false; RedoStack.Clear(); Menu_Redo.Enabled = false; // Indicate audibly the save is loaded SystemSounds.Beep.Play(); }
// Misc Options private void clickShowdownImportPKM(object sender, EventArgs e) { if (!formInitialized) return; if (!Clipboard.ContainsText()) { Util.Alert("Clipboard does not contain text."); return; } // Get Simulator Data ShowdownSet Set = new ShowdownSet(Clipboard.GetText()); if (Set.Species < 0) { Util.Alert("Set data not found in clipboard."); return; } if (Set.Nickname != null && Set.Nickname.Length > SAV.NickLength) Set.Nickname = Set.Nickname.Substring(0, SAV.NickLength); if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.getText())) { return; } if (Set.InvalidLines.Any()) Util.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines)); // Set Species & Nickname CB_Species.SelectedValue = Set.Species; CHK_Nicknamed.Checked = Set.Nickname != null; if (Set.Nickname != null) TB_Nickname.Text = Set.Nickname; if (Set.Gender != null) { int Gender = PKX.getGender(Set.Gender); Label_Gender.Text = gendersymbols[Gender]; Label_Gender.ForeColor = Gender == 2 ? Label_Species.ForeColor : (Gender == 1 ? Color.Red : Color.Blue); } // Set Form string[] formStrings = PKX.getFormList(Set.Species, Util.getTypesList("en"), Util.getFormsList("en"), gendersymbols, SAV.Generation); int form = 0; for (int i = 0; i < formStrings.Length; i++) if (formStrings[i].Contains(Set.Form ?? "")) { form = i; break; } CB_Form.SelectedIndex = form; // Set Ability int[] abilities = SAV.Personal.getAbilities(Set.Species, form); int ability = Array.IndexOf(abilities, Set.Ability); if (ability < 0) ability = 0; CB_Ability.SelectedIndex = ability; ComboBox[] m = {CB_Move1, CB_Move2, CB_Move3, CB_Move4}; for (int i = 0; i < 4; i++) m[i].SelectedValue = Set.Moves[i]; // Set Item and Nature CB_HeldItem.SelectedValue = Set.Item < 0 ? 0 : Set.Item; CB_Nature.SelectedValue = Set.Nature < 0 ? 0 : Set.Nature; // Set IVs TB_HPIV.Text = Set.IVs[0].ToString(); TB_ATKIV.Text = Set.IVs[1].ToString(); TB_DEFIV.Text = Set.IVs[2].ToString(); TB_SPAIV.Text = Set.IVs[4].ToString(); TB_SPDIV.Text = Set.IVs[5].ToString(); TB_SPEIV.Text = Set.IVs[3].ToString(); // Set EVs TB_HPEV.Text = Set.EVs[0].ToString(); TB_ATKEV.Text = Set.EVs[1].ToString(); TB_DEFEV.Text = Set.EVs[2].ToString(); TB_SPAEV.Text = Set.EVs[4].ToString(); TB_SPDEV.Text = Set.EVs[5].ToString(); TB_SPEEV.Text = Set.EVs[3].ToString(); // Set Level and Friendship TB_Level.Text = Set.Level.ToString(); TB_Friendship.Text = Set.Friendship.ToString(); // Reset IV/EVs BTN_RerollPID.PerformClick(); BTN_RerollEC.PerformClick(); ComboBox[] p = {CB_PPu1, CB_PPu2, CB_PPu3, CB_PPu4}; for (int i = 0; i < 4; i++) p[i].SelectedIndex = m[i].SelectedIndex != 0 ? 3 : 0; // max PP if (Set.Shiny) BTN_Shinytize.PerformClick(); pkm = preparePKM(); updateLegality(); }
protected internal override void setCaught(PKM pkm, bool caught = true) { if (pkm.Species == 0) return; if (pkm.Species > MaxSpeciesID) return; if (Version == GameVersion.Unknown) return; int bit = pkm.Species - 1; int ofs = bit >> 3; byte bitval = (byte)(1 << (bit & 7)); // Set the Captured Flag Data[(Japanese ? 0x259E : 0x25A3) + ofs] &= (byte)(~bitval); if (caught) Data[(Japanese ? 0x259E : 0x25A3) + ofs] |= bitval; }
internal static PKM convertToFormat(PKM pk, Type PKMType, out string comment) { if (pk == null || pk.Species == 0) { comment = "Null input. Aborting."; return null; } Type fromType = pk.GetType(); int fromFormat = int.Parse(fromType.Name.Last().ToString()); int toFormat = int.Parse(PKMType.Name.Last().ToString()); Console.WriteLine($"Trying to convert {fromType.Name} to {PKMType.Name}."); PKM pkm = null; if (fromType == PKMType) { comment = "No need to convert, current format matches requested format."; return pk; } if (fromFormat <= toFormat || fromFormat == 2) { pkm = pk.Clone(); if (pkm.IsEgg) // force hatch { pkm.IsEgg = false; if (pkm.AO) pkm.Met_Location = 318; // Battle Resort else if (pkm.XY) pkm.Met_Location = 38; // Route 7 else if (pkm.Gen5) pkm.Met_Location = 16; // Route 16 else pkm.Met_Location = 30001; // Pokétransfer } switch (fromType.Name) { case "PK1": if (toFormat == 2) { pkm = PKMType == typeof (PK2) ? ((PK1) pk).convertToPK2() : null; break; } if (toFormat == 7) pkm = null; // pkm.convertPK1toPK7(); break; case "PK2": if (PKMType == typeof (PK1)) { if (pk.Species > 151) { comment = $"Cannot convert a {PKX.getSpeciesName(pkm.Species, ((PK2)pkm).Japanese ? 1 : 2)} to {PKMType.Name}"; return null; } pkm = ((PK2) pk).convertToPK1(); } else pkm = null; break; case "CK3": case "XK3": // interconverting C/XD needs to visit main series format // ends up stripping purification/shadow etc stats pkm = pkm.convertToPK3(); goto case "PK3"; // fall through case "PK3": if (toFormat == 3) // Gen3 Inter-trading { switch (PKMType.Name) { case "CK3": pkm = pkm.convertToCK3(); break; case "XK3": pkm = pkm.convertToXK3(); break; case "PK3": pkm = pkm.convertToPK3(); break; // already converted, instantly returns default: throw new FormatException(); } break; } if (fromType.Name != "PK3") pkm = pkm.convertToPK3(); pkm = ((PK3)pkm).convertToPK4(); if (toFormat == 4) { if (PKMType == typeof (BK4)) pkm = ((PK4) pkm).convertToBK4(); break; } pkm = ((PK4)pkm).convertToPK5(); if (toFormat == 5) break; pkm = ((PK5)pkm).convertToPK6(); if (toFormat == 6) break; pkm = new PK7(pkm.Data, pkm.Identifier); break; case "PK4": if (PKMType == typeof(BK4)) { pkm = ((PK4)pkm).convertToBK4(); break; } pkm = ((PK4)pkm).convertToPK5(); if (toFormat == 5) break; pkm = ((PK5)pkm).convertToPK6(); if (toFormat == 6) break; pkm = new PK7(pkm.Data, pkm.Identifier); break; case "BK4": pkm = ((BK4)pkm).convertToPK4(); if (toFormat == 4) break; pkm = ((PK4)pkm).convertToPK5(); if (toFormat == 5) break; pkm = ((PK5)pkm).convertToPK6(); if (toFormat == 6) break; pkm = new PK7(pkm.Data, pkm.Identifier); break; case "PK5": pkm = ((PK5)pkm).convertToPK6(); break; case "PK6": pkm = new PK7(pkm.Data, pkm.Identifier); break; } } comment = pkm == null ? $"Cannot convert a {fromType.Name} to a {PKMType.Name}." : $"Converted from {fromType.Name} to {PKMType.Name}."; return pkm; }
public override void setStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null) { if (pkm == null) return; if (pkm.GetType() != PKMType) throw new InvalidCastException($"PKM Format needs to be {PKMType} when setting to a Gen{Generation} Save File."); if (trade ?? SetUpdatePKM) setPKM(pkm); if (dex ?? SetUpdateDex) setDex(pkm); byte[] data = pkm.EncryptedBoxData; setData(data, offset); BitConverter.GetBytes((ushort)pkm.TID).CopyTo(Data, offset + data.Length + 0); BitConverter.GetBytes((ushort)pkm.SID).CopyTo(Data, offset + data.Length + 2); Edited = true; }
protected internal virtual void setSeen(PKM pkm, bool seen = true) { }
protected virtual void setDex(PKM pkm) { setSeen(pkm); setCaught(pkm); }
private void getQuickFiller(PictureBox pb, PKM pk) { pb.Image = pk.Species == 0 ? null : pk.Sprite; if (pb.BackColor == Color.Red) pb.BackColor = Color.Transparent; }
private static int GetRequiredMoveCountDecrement(PKM pk, IReadOnlyList <int> moves, IReadOnlyList <int>[] learn, IReadOnlyList <int> initialmoves) { int usedslots = initialmoves.Union(learn[1]).Where(m => m != 0).Distinct().Count(); switch (pk.Species) { case (int)Species.Venonat: // Venonat; ignore Venomoth (by the time Venonat evolves it will always have 4 moves) if (pk.CurrentLevel >= 11 && !moves.Contains(48)) // Supersonic { usedslots--; } if (pk.CurrentLevel >= 19 && !moves.Contains(93)) // Confusion { usedslots--; } break; case (int)Species.Kadabra: case (int)Species.Alakazam: // Abra & Kadabra int catch_rate = ((PK1)pk).Catch_Rate; if (catch_rate != 100) // Initial Yellow Kadabra Kinesis (move 134) { usedslots--; } if (catch_rate == 200 && pk.CurrentLevel < 20) // Kadabra Disable, not learned until 20 if captured as Abra (move 50) { usedslots--; } break; case (int)Species.Cubone: case (int)Species.Marowak: // Cubone & Marowak if (!moves.Contains(39)) // Initial Yellow Tail Whip { usedslots--; } if (!moves.Contains(125)) // Initial Yellow Bone Club { usedslots--; } if (pk.Species == 105 && pk.CurrentLevel < 33 && !moves.Contains(116)) // Marowak evolved without Focus Energy { usedslots--; } break; case (int)Species.Chansey: if (!moves.Contains(39)) // Yellow Initial Tail Whip { usedslots--; } if (!moves.Contains(3)) // Yellow Lvl 12 and Initial Red/Blue Double Slap { usedslots--; } break; case (int)Species.Mankey when pk.CurrentLevel >= 9 && !moves.Contains(67): // Mankey (Low Kick) case (int)Species.Pinsir when pk.CurrentLevel >= 21 && !moves.Contains(20): // Pinsir (Bind) case (int)Species.Gyarados when pk.CurrentLevel < 32: // Gyarados usedslots--; break; default: return(usedslots); } return(usedslots); }
public virtual bool getCaught(PKM pkm) { throw new NotImplementedException(); }
public PK4 convertToPK4(SAV6 SAV) { if (!PokémonGift) { return(null); } PK4 pk4 = new PK4(PK.Data); if (!IsPokémon && Detail == 0) { pk4.OT_Name = "PKHeX"; pk4.TID = 12345; pk4.SID = 54321; pk4.OT_Gender = (int)(Util.rnd32() % 2); } if (IsManaphyEgg) { // Since none of this data is populated, fill in default info. pk4.Species = 490; // Level 1 Moves pk4.Move1 = 294; pk4.Move2 = 145; pk4.Move3 = 346; pk4.FatefulEncounter = true; pk4.Ball = 4; pk4.Version = 10; // Diamond pk4.Language = 2; // English pk4.Nickname = "MANAPHY"; pk4.Egg_Location = 1; // Ranger (will be +3000 later) } // Generate IV uint seed = Util.rnd32(); if (pk4.PID == 1) // Create Nonshiny { uint pid1 = PKM.LCRNG(ref seed) >> 16; uint pid2 = PKM.LCRNG(ref seed) >> 16; while ((pid1 ^ pid2 ^ pk4.TID ^ pk4.SID) < 8) { uint testPID = pid1 | pid2 << 16; // Call the ARNG to change the PID testPID = testPID * 0x6c078965 + 1; pid1 = testPID & 0xFFFF; pid2 = testPID >> 16; } pk4.PID = pid1 | (pid2 << 16); } // Generate IVs if (pk4.IV32 == 0) { uint iv1 = PKM.LCRNG(ref seed) >> 16; uint iv2 = PKM.LCRNG(ref seed) >> 16; pk4.IV32 = (iv1 | iv2 << 16) & 0x3FFFFFFF; } // Generate Met Info DateTime dt = DateTime.Now; if (IsPokémon) { pk4.Met_Location = pk4.Egg_Location + 3000; pk4.Egg_Location = 0; pk4.Met_Day = dt.Day; pk4.Met_Month = dt.Month; pk4.Met_Year = dt.Year - 2000; pk4.IsEgg = false; } else { pk4.Egg_Location = pk4.Egg_Location + 3000; pk4.Egg_Day = dt.Day; pk4.Egg_Month = dt.Month; pk4.Egg_Year = dt.Year - 2000; pk4.IsEgg = false; // Met Location is modified when transferred to pk5; don't worry about it. } if (pk4.Species == 201) // Never will be true; Unown was never distributed. { pk4.AltForm = PKM.getUnownForm(pk4.PID); } return(pk4); }
protected override void setDex(PKM pkm) { if (pkm.Species == 0) return; if (pkm.Species > MaxSpeciesID) return; if (Version == GameVersion.Unknown) return; if (PokeDex < 0) return; const int brSize = 0x54; int bit = pkm.Species - 1; int lang = pkm.Language - 1; if (lang > 5) lang--; // 0-6 language vals int gender = pkm.Gender % 2; // genderless -> male int shiny = pkm.IsShiny ? 1 : 0; int shiftoff = shiny * brSize * 2 + gender * brSize + brSize; // Set the Species Owned Flag Data[PokeDex + 0x8 + bit / 8] |= (byte)(1 << (bit % 8)); // Set the [Species/Gender/Shiny] Seen Flag Data[PokeDex + 0x8 + shiftoff + bit / 8] |= (byte)(1 << (bit % 8)); // Set the Display flag if none are set bool Displayed = false; Displayed |= (Data[PokeDex + 0x8 + brSize*5 + bit/8] & (byte)(1 << (bit%8))) != 0; Displayed |= (Data[PokeDex + 0x8 + brSize*6 + bit/8] & (byte)(1 << (bit%8))) != 0; Displayed |= (Data[PokeDex + 0x8 + brSize*7 + bit/8] & (byte)(1 << (bit%8))) != 0; Displayed |= (Data[PokeDex + 0x8 + brSize*8 + bit/8] & (byte)(1 << (bit%8))) != 0; if (!Displayed) // offset is already biased by brSize, reuse shiftoff but for the display flags. Data[PokeDex + 0x8 + shiftoff + brSize*4 + bit/8] |= (byte)(1 << (bit%8)); // Set the Language if (lang < 0) lang = 1; Data[PokeDexLanguageFlags + (bit*7 + lang) / 8] |= (byte)(1 << ((bit*7 + lang) % 8)); // Formes int fc = Personal[pkm.Species].FormeCount; int f = B2W2 ? SaveUtil.getDexFormIndexB2W2(pkm.Species, fc) : SaveUtil.getDexFormIndexBW(pkm.Species, fc); if (f < 0) return; int FormLen = B2W2 ? 0xB : 0x9; int FormDex = PokeDex + 0x8 + brSize*9; bit = f + pkm.AltForm; // Set Form Seen Flag Data[FormDex + FormLen*shiny + bit/8] |= (byte)(1 << (bit%8)); // Set Displayed Flag if necessary, check all flags for (int i = 0; i < fc; i++) { bit = f + i; if ((Data[FormDex + FormLen*2 + bit/8] & (byte)(1 << (bit%8))) != 0) // Nonshiny return; // already set if ((Data[FormDex + FormLen*3 + bit/8] & (byte)(1 << (bit%8))) != 0) // Shiny return; // already set } bit = f + pkm.AltForm; Data[FormDex + FormLen * (2 + shiny) + bit / 8] |= (byte)(1 << (bit % 8)); }
internal static Image getSprite(PKM pkm) { return getSprite(pkm.Species, pkm.AltForm, pkm.Gender, pkm.HeldItem, pkm.IsEgg, pkm.IsShiny); }
private static IEnumerable <EncounterArea> getEncounterAreas(PKM pkm) { return(getEncounterSlots(pkm).Where(l => l.Location == pkm.Met_Location)); }
protected internal virtual void setCaught(PKM pkm, bool caught = true) { }
private static IEnumerable <EncounterSlot> getValidEncounterSlots(PKM pkm, EncounterArea loc, bool DexNav, bool ignoreLevel = false) { const int fluteBoost = 4; const int dexnavBoost = 30; int df = DexNav ? fluteBoost : 0; int dn = DexNav ? fluteBoost + dexnavBoost : 0; List <EncounterSlot> slotdata = new List <EncounterSlot>(); // Get Valid levels IEnumerable <DexLevel> vs = getValidPreEvolutions(pkm); // Get slots where pokemon can exist IEnumerable <EncounterSlot> slots = loc.Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species && evo.Level >= slot.LevelMin - df) || ignoreLevel); // Filter for Met Level int lvl = pkm.Met_Level; var encounterSlots = slots.Where(slot => slot.LevelMin - df <= lvl && lvl <= slot.LevelMax + (slot.AllowDexNav ? dn : df) || ignoreLevel).ToList(); // Pressure Slot EncounterSlot slotMax = encounterSlots.OrderByDescending(slot => slot.LevelMax).FirstOrDefault(); if (slotMax != null) { slotMax = new EncounterSlot(slotMax) { Pressure = true, Form = pkm.AltForm } } ; if (!DexNav) { // Filter for Form Specific slotdata.AddRange(WildForms.Contains(pkm.Species) ? encounterSlots.Where(slot => slot.Form == pkm.AltForm) : encounterSlots); if (slotMax != null) { slotdata.Add(slotMax); } return(slotdata); } List <EncounterSlot> eslots = encounterSlots.Where(slot => !WildForms.Contains(pkm.Species) || slot.Form == pkm.AltForm).ToList(); if (slotMax != null) { eslots.Add(slotMax); } foreach (EncounterSlot s in eslots) { bool nav = s.AllowDexNav && (pkm.RelearnMove1 != 0 || pkm.AbilityNumber == 4); EncounterSlot slot = new EncounterSlot(s) { DexNav = nav }; if (slot.LevelMin > lvl) { slot.WhiteFlute = true; } if (slot.LevelMax + 1 <= lvl && lvl <= slot.LevelMax + fluteBoost) { slot.BlackFlute = true; } if (slot.LevelMax != lvl && slot.AllowDexNav) { slot.DexNav = true; } slotdata.Add(slot); } return(slotdata); }
private static IEnumerable <EncounterStatic> getStatic(PKM pkm, IEnumerable <EncounterStatic> table, int lvl = -1) { IEnumerable <DexLevel> dl = getValidPreEvolutions(pkm, lvl); return(table.Where(e => dl.Any(d => d.Species == e.Species))); }
protected virtual void setPKM(PKM pkm) { }
private static IEnumerable <int> getMoves(PKM pkm, int species, int lvl, int form, bool moveTutor, GameVersion Version, bool LVL, bool specialTutors, bool Machine, int Generation, bool MoveReminder) { List <int> r = new List <int>(); var ver = Version; switch (Generation) { case 6: switch (ver) { case GameVersion.Any: // Start at the top, hit every table case GameVersion.X: case GameVersion.Y: case GameVersion.XY: { int index = PersonalTable.XY.getFormeIndex(species, form); PersonalInfo pi = PersonalTable.XY.getFormeEntry(species, form); if (LVL) { r.AddRange(LevelUpXY[index].getMoves(lvl)); } if (moveTutor) { r.AddRange(getTutorMoves(pkm, species, form, specialTutors)); } if (Machine) { r.AddRange(TMHM_XY.Where((t, m) => pi.TMHM[m])); } if (ver == GameVersion.Any) // Fall Through { goto case GameVersion.ORAS; } break; } case GameVersion.AS: case GameVersion.OR: case GameVersion.ORAS: { int index = PersonalTable.AO.getFormeIndex(species, form); PersonalInfo pi = PersonalTable.AO.getFormeEntry(species, form); if (LVL) { r.AddRange(LevelUpAO[index].getMoves(lvl)); } if (moveTutor) { r.AddRange(getTutorMoves(pkm, species, form, specialTutors)); } if (Machine) { r.AddRange(TMHM_AO.Where((t, m) => pi.TMHM[m])); } break; } } break; case 7: switch (ver) { case GameVersion.Any: case GameVersion.SN: case GameVersion.MN: case GameVersion.SM: { int index = PersonalTable.SM.getFormeIndex(species, form); PersonalInfo pi = PersonalTable.SM.getFormeEntry(species, form); if (MoveReminder) { lvl = 100; // Move reminder can teach any level in movepool now! } if (LVL) { r.AddRange(LevelUpSM[index].getMoves(lvl)); } if (moveTutor) { r.AddRange(getTutorMoves(pkm, species, form, specialTutors)); } if (Machine) { r.AddRange(TMHM_SM.Where((t, m) => pi.TMHM[m])); } break; } } break; default: return(r); } return(r); }
internal static ushort[] getStats(PKM pkm) { return getStats(pkm.Species, pkm.Stat_Level, pkm.Nature, pkm.AltForm, pkm.EV_HP, pkm.EV_ATK, pkm.EV_DEF, pkm.EV_SPA, pkm.EV_SPD, pkm.EV_SPE, pkm.IV_HP, pkm.IV_ATK, pkm.IV_DEF, pkm.IV_SPA, pkm.IV_SPD, pkm.IV_SPE); }
internal static EncounterTrade getValidIngameTrade(PKM pkm) { if (!pkm.WasIngameTrade) { return(null); } int lang = pkm.Language; if (lang == 0 || lang == 6) { return(null); } // Get valid pre-evolutions IEnumerable <DexLevel> p = getValidPreEvolutions(pkm); EncounterTrade[] table = null; if (pkm.XY) { table = TradeGift_XY; } if (pkm.AO) { table = TradeGift_AO; } if (pkm.SM) { table = TradeGift_SM; } EncounterTrade z = table?.FirstOrDefault(f => p.Any(r => r.Species == f.Species)); if (z == null) { return(null); } for (int i = 0; i < 6; i++) { if (z.IVs[i] != -1 && z.IVs[i] != pkm.IVs[i]) { return(null); } } if (z.Shiny ^ pkm.IsShiny) // Are PIDs static? { return(null); } if (z.TID != pkm.TID) { return(null); } if (z.SID != pkm.SID) { return(null); } if (z.Location != pkm.Met_Location) { return(null); } if (z.Level != pkm.Met_Level) { return(null); } if (z.Nature != Nature.Random && (int)z.Nature != pkm.Nature) { return(null); } if (z.Gender != pkm.Gender) { return(null); } if (z.OTGender != -1 && z.OTGender != pkm.OT_Gender) { return(null); } // if (z.Ability == 4 ^ pkm.AbilityNumber == 4) // defer to Ability // return null; return(z); }
protected override void setDex(PKM pkm) { }
private static IEnumerable <MysteryGift> getMatchingWC7(PKM pkm, IEnumerable <MysteryGift> DB) { List <MysteryGift> validWC7 = new List <MysteryGift>(); if (DB == null) { return(validWC7); } var vs = getValidPreEvolutions(pkm).ToArray(); foreach (WC7 wc in DB.OfType <WC7>().Where(wc => vs.Any(dl => dl.Species == wc.Species))) { if (pkm.Egg_Location == 0) // Not Egg { if (wc.OTGender != 3) { if (wc.SID != pkm.SID) { continue; } if (wc.TID != pkm.TID) { continue; } if (wc.OTGender != pkm.OT_Gender) { continue; } } if (!string.IsNullOrEmpty(wc.OT) && wc.OT != pkm.OT_Name) { continue; } if (wc.PIDType == 0 && pkm.PID != wc.PID) { continue; } if (wc.PIDType == 2 && !pkm.IsShiny) { continue; } if (wc.PIDType == 3 && pkm.IsShiny) { continue; } if (wc.OriginGame != 0 && wc.OriginGame != pkm.Version) { continue; } if (wc.EncryptionConstant != 0 && wc.EncryptionConstant != pkm.EncryptionConstant) { continue; } if (wc.Language != 0 && wc.Language != pkm.Language) { continue; } } if (wc.Form != pkm.AltForm && vs.All(dl => !FormChange.Contains(dl.Species))) { continue; } if (wc.MetLocation != pkm.Met_Location) { continue; } if (wc.EggLocation != pkm.Egg_Location) { continue; } if (wc.MetLevel != pkm.Met_Level) { continue; } if (wc.Ball != pkm.Ball) { continue; } if (wc.OTGender < 3 && wc.OTGender != pkm.OT_Gender) { continue; } if (wc.Nature != 0xFF && wc.Nature != pkm.Nature) { continue; } if (wc.Gender != 3 && wc.Gender != pkm.Gender) { continue; } if (wc.CNT_Cool > pkm.CNT_Cool) { continue; } if (wc.CNT_Beauty > pkm.CNT_Beauty) { continue; } if (wc.CNT_Cute > pkm.CNT_Cute) { continue; } if (wc.CNT_Smart > pkm.CNT_Smart) { continue; } if (wc.CNT_Tough > pkm.CNT_Tough) { continue; } if (wc.CNT_Sheen > pkm.CNT_Sheen) { continue; } // Some checks are best performed separately as they are caused by users screwing up valid data. // if (!wc.RelearnMoves.SequenceEqual(pkm.RelearnMoves)) continue; // Defer to relearn legality // if (wc.OT.Length > 0 && pkm.CurrentHandler != 1) continue; // Defer to ownership legality // if (wc.OT.Length > 0 && pkm.OT_Friendship != PKX.getBaseFriendship(pkm.Species)) continue; // Friendship // if (wc.Level > pkm.CurrentLevel) continue; // Defer to level legality // RIBBONS: Defer to ribbon legality validWC7.Add(wc); } return(validWC7); }
// Pokédex public override bool getSeen(PKM pkm) { if (pkm.Species == 0) return false; if (pkm.Species > MaxSpeciesID) return false; if (Version == GameVersion.Unknown) return false; int bit = pkm.Species - 1; int ofs = bit >> 3; byte bitval = (byte)(1 << (bit & 7)); // Get the Seen Flag return (Data[(Japanese ? 0x25B1 : 0x25B6) + ofs] & bitval) != 0; }
internal static bool getHasEvolved(PKM pkm) { return(getValidPreEvolutions(pkm).Count() > 1); }
protected internal override void setSeen(PKM pkm, bool seen = true) { if (pkm.Species == 0) return; if (pkm.Species > MaxSpeciesID) return; if (Version == GameVersion.Unknown) return; int bit = pkm.Species - 1; int ofs = bit >> 3; byte bitval = (byte)(1 << (bit & 7)); // Set the Seen Flag Data[(Japanese ? 0x25B1 : 0x25B6) + ofs] &= (byte)(~bitval); if (seen) Data[(Japanese ? 0x25B1 : 0x25B6) + ofs] |= bitval; }
internal static EncounterStatic getStaticLocation(PKM pkm) { return(getStaticEncounters(pkm).FirstOrDefault()); }
private void getQuickFiller(PictureBox pb, PKM pk = null) { if (!fieldsInitialized) return; pk = pk ?? preparePKM(false); // don't perform control loss click if (pb == dragout) mnuLQR.Enabled = pk.Species != 0; // Species pb.Image = pk.Species != 0 ? pk.Sprite : null; if (pb.BackColor == Color.Red) pb.BackColor = Color.Transparent; }
internal static bool getCanRelearnMove(PKM pkm, int move, GameVersion version = GameVersion.Any) { return(getValidMoves(pkm, version, LVL: true, Relearn: true).Contains(move)); }
public static string[] verifyPKMtoSAV(PKM pk) { // Check if PKM properties are outside of the valid range List<string> errata = new List<string>(); if (SAV.Generation > 1) { ushort held = (ushort)pk.HeldItem; if (held > GameStrings.itemlist.Length) errata.Add($"Item Index beyond range: {held}"); else if (held > SAV.MaxItemID) errata.Add($"Game can't obtain item: {GameStrings.itemlist[held]}"); else if (!pk.CanHoldItem(SAV.HeldItems)) errata.Add($"Game can't hold item: {GameStrings.itemlist[held]}"); } if (pk.Species > GameStrings.specieslist.Length) errata.Add($"Species Index beyond range: {pk.HeldItem}"); else if (SAV.MaxSpeciesID < pk.Species) errata.Add($"Game can't obtain species: {GameStrings.specieslist[pk.Species]}"); if (pk.Moves.Any(m => m > GameStrings.movelist.Length)) errata.Add($"Item Index beyond range: {string.Join(", ", pk.Moves.Where(m => m > GameStrings.movelist.Length).Select(m => m.ToString()))}"); else if (pk.Moves.Any(m => m > SAV.MaxMoveID)) errata.Add($"Game can't have move: {string.Join(", ", pk.Moves.Where(m => m > SAV.MaxMoveID).Select(m => GameStrings.movelist[m]))}"); if (pk.Ability > GameStrings.abilitylist.Length) errata.Add($"Ability Index beyond range: {pk.Ability}"); else if (pk.Ability > SAV.MaxAbilityID) errata.Add($"Game can't have ability: {GameStrings.abilitylist[pk.Ability]}"); return errata.ToArray(); }
internal static bool getCanLearnMove(PKM pkm, int move, GameVersion version = GameVersion.Any) { return(getValidMoves(pkm, version, Tutor: true, Machine: true).Contains(move)); }
public void populateFields(PKM pk, bool focus = true) { if (pk == null) { Util.Error("Attempted to load a null file."); return; } if ((pk.Format >= 3 && pk.Format > SAV.Generation) // pk3-7, can't go backwards || (pk.Format <= 2 && SAV.Generation > 2 && SAV.Generation < 7)) // pk1-2, can't go 3-6 { Util.Alert($"Can't load Gen{pk.Format} to Gen{SAV.Generation} games."); return; } bool oldInit = fieldsInitialized; fieldsInitialized = fieldsLoaded = false; if (focus) Tab_Main.Focus(); pkm = pk.Clone(); if (fieldsInitialized & !pkm.ChecksumValid) Util.Alert("PKX File has an invalid checksum."); if (pkm.Format != SAV.Generation) // past gen format { string c; pkm = PKMConverter.convertToFormat(pkm, SAV.PKMType, out c); if (pk.Format != pkm.Format && focus) // converted Util.Alert("Converted File."); } try { getFieldsfromPKM(); } catch { fieldsInitialized = oldInit; throw; } CB_EncounterType.Visible = Label_EncounterType.Visible = pkm.Gen4; fieldsInitialized = oldInit; updateIVs(null, null); updatePKRSInfected(null, null); updatePKRSCured(null, null); if (HaX) { MT_Level.Text = pkm.Stat_Level.ToString(); MT_Form.Text = pkm.AltForm.ToString(); if (pkm.Stat_HPMax != 0) // stats present { Stat_HP.Text = pkm.Stat_HPCurrent.ToString(); Stat_ATK.Text = pkm.Stat_ATK.ToString(); Stat_DEF.Text = pkm.Stat_DEF.ToString(); Stat_SPA.Text = pkm.Stat_SPA.ToString(); Stat_SPD.Text = pkm.Stat_SPD.ToString(); Stat_SPE.Text = pkm.Stat_SPE.ToString(); } } fieldsLoaded = true; Label_HatchCounter.Visible = CHK_IsEgg.Checked && SAV.Generation > 1; Label_Friendship.Visible = !CHK_IsEgg.Checked && SAV.Generation > 1; // Set the Preview Box dragout.Image = pk.Sprite; updateLegality(); }
protected override void setDex(PKM pkm) { if (PokeDex < 0 || Version == GameVersion.Unknown) // sanity { return; } if (pkm.Species == 0 || pkm.Species > MaxSpeciesID) // out of range { return; } if (pkm.IsEgg) // do not add { return; } int bit = pkm.Species - 1; int bd = bit >> 3; // div8 int bm = bit & 7; // mod8 int gender = pkm.Gender % 2; // genderless -> male int shiny = pkm.IsShiny ? 1 : 0; if (pkm.Species == 351) // castform { shiny = 0; } int shift = gender | (shiny << 1); if (pkm.Species == 327) // Spinda { if ((Data[PokeDex + 0x84] & (1 << (shift + 4))) != 0) // Already 2 { BitConverter.GetBytes(pkm.EncryptionConstant).CopyTo(Data, PokeDex + 0x8E8 + shift * 4); // Data[PokeDex + 0x84] |= (byte)(1 << (shift + 4)); // 2 -- pointless Data[PokeDex + 0x84] |= (byte)(1 << shift); // 1 } else if ((Data[PokeDex + 0x84] & (1 << shift)) == 0) // Not yet 1 { Data[PokeDex + 0x84] |= (byte)(1 << shift); // 1 } } int ofs = PokeDex // Raw Offset + 0x08 // Magic + Flags + 0x80; // Misc Data (1024 bits) // Set the Owned Flag Data[ofs + bd] |= (byte)(1 << bm); // Starting with Gen7, form bits are stored in the same region as the species flags. int formstart = pkm.AltForm; int formend = pkm.AltForm; int fs, fe; bool reset = sanitizeFormsToIterate(pkm.Species, out fs, out fe, formstart); if (reset) { formstart = fs; formend = fe; } for (int form = formstart; form <= formend; form++) { int bitIndex = bit; if (form > 0) // Override the bit to overwrite { int fc = Personal[pkm.Species].FormeCount; if (fc > 1) // actually has forms { int f = SaveUtil.getDexFormIndexSM(pkm.Species, fc, MaxSpeciesID - 1); if (f >= 0) // bit index valid { bitIndex = f + form; } } } setDexFlags(bitIndex, gender, shiny, pkm.Species - 1); } // Set the Language int lang = pkm.Language; const int langCount = 9; if (lang <= 10 && lang != 6 && lang != 0) // valid language { if (lang >= 7) { lang--; } lang--; // 0-8 languages if (lang < 0) { lang = 1; } int lbit = bit * langCount + lang; if (lbit >> 3 < 920) // Sanity check for max length of region { Data[PokeDexLanguageFlags + (lbit >> 3)] |= (byte)(1 << (lbit & 7)); } } }
private void parsePK7(PKM pk) { if (!(pk is PK7)) return; pkm = pk; updateRelearnLegality(); updateMoveLegality(); updateChecks(); getLegalityReport(); }
public Preview(PKM p) { pkm = p; }
protected override void setDex(PKM pkm) { // Dex Related var entry = StrategyMemo.GetEntry(pkm.Species); if (entry.IsEmpty) // Populate { entry.Species = pkm.Species; entry.PID = pkm.PID; entry.TID = pkm.TID; entry.SID = pkm.SID; } if (entry.Matches(pkm.Species, pkm.PID, pkm.TID, pkm.SID)) { entry.Seen = true; entry.Owned = true; } StrategyMemo.SetEntry(entry); }
internal static string getFileName(PKM pkm) { return $"{pkm.Species.ToString("000")}{(pkm.IsShiny ? " ★" : "")} - {pkm.Nickname} - {pkm.Checksum.ToString("X4")}{pkm.EncryptionConstant.ToString("X8")}.{pkm.Extension}"; }
private void parsePK7(PKM pk) { pkm = pk; if (pkm.Species > 802) { AddLine(Severity.Invalid, "Species does not exist in origin game.", CheckIdentifier.None); return; } updateRelearnLegality(); updateMoveLegality(); updateChecks(); }
internal static string getLocation(PKM pk, bool egg) { return getLocation(egg, pk.Version, egg ? pk.Egg_Location : pk.Met_Location, pk.Format); }
private void processSAV(PKM[] data, List<StringInstruction> Filters, List<StringInstruction> Instructions) { len = err = ctr = 0; for (int i = 0; i < data.Length; i++) { var pkm = data[i]; if (!pkm.Valid) { b.ReportProgress(i); continue; } ModifyResult r = ProcessPKM(pkm, Filters, Instructions); if (r != ModifyResult.Invalid) len++; if (r == ModifyResult.Error) err++; if (r == ModifyResult.Modified) { if (pkm.Species != 0) pkm.RefreshChecksum(); ctr++; } b.ReportProgress(i); } Main.SAV.BoxData = data; }
internal static string[] getQRText(PKM pkm) { string[] response = new string[3]; // Summarize string filename = pkm.Nickname; if (pkm.Nickname != Main.specieslist[pkm.Species] && Main.specieslist[pkm.Species] != null) filename += $" ({Main.specieslist[pkm.Species]})"; response[0] = $"{filename} [{Main.abilitylist[pkm.Ability]}] lv{pkm.Stat_Level} @ {Main.itemlist[pkm.HeldItem]} -- {Main.natures[pkm.Nature]}"; response[1] = $"{Main.movelist[pkm.Move1]} / {Main.movelist[pkm.Move2]} / {Main.movelist[pkm.Move3]} / {Main.movelist[pkm.Move4]}"; response[2] = String.Format( "IVs:{0}{1}{2}{3}{4}{5}" + Environment.NewLine + Environment.NewLine + "EVs:{6}{7}{8}{9}{10}{11}", Environment.NewLine + pkm.IV_HP.ToString("00"), Environment.NewLine + pkm.IV_ATK.ToString("00"), Environment.NewLine + pkm.IV_DEF.ToString("00"), Environment.NewLine + pkm.IV_SPA.ToString("00"), Environment.NewLine + pkm.IV_SPD.ToString("00"), Environment.NewLine + pkm.IV_SPE.ToString("00"), Environment.NewLine + pkm.EV_HP, Environment.NewLine + pkm.EV_ATK, Environment.NewLine + pkm.EV_DEF, Environment.NewLine + pkm.EV_SPA, Environment.NewLine + pkm.EV_SPD, Environment.NewLine + pkm.EV_SPE); return response; }
internal static string getShowdownText(PKM pkm) { if (pkm.Species == 0) return ""; ShowdownSet Set = new ShowdownSet { Nickname = pkm.Nickname, Species = pkm.Species, Item = pkm.HeldItem, Ability = pkm.Ability, EVs = pkm.EVs, IVs = pkm.IVs, Moves = pkm.Moves, Nature = pkm.Nature, Gender = new[] { " (M)", " (F)", "" }[pkm.Gender], Friendship = pkm.CurrentFriendship, Level = PKX.getLevel(pkm.Species, pkm.EXP), Shiny = pkm.IsShiny, Form = pkm.AltForm > 0 ? PKX.getFormList(pkm.Species, types, forms, new[] { "", "F", "" })[pkm.AltForm] : "", }; if (Set.Form == "F") Set.Gender = ""; return Set.getText(); }
public PK4 convertToPK4() { DateTime moment = DateTime.Now; PK4 pk4 = new PK4 // Convert away! { PID = PID, Species = Species, TID = TID, SID = SID, EXP = IsEgg ? PKX.getEXP(5, Species) : EXP, IsEgg = false, Friendship = 40, Circle = Circle, Square = Square, Triangle = Triangle, Heart = Heart, Language = Language, EV_HP = EV_HP, EV_ATK = EV_ATK, EV_DEF = EV_DEF, EV_SPA = EV_SPA, EV_SPD = EV_SPD, EV_SPE = EV_SPE, CNT_Cool = CNT_Cool, CNT_Beauty = CNT_Beauty, CNT_Cute = CNT_Cute, CNT_Smart = CNT_Smart, CNT_Tough = CNT_Tough, CNT_Sheen = CNT_Sheen, FatefulEncounter = Obedience, Move1 = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4, Move1_PPUps = Move1_PPUps, Move2_PPUps = Move2_PPUps, Move3_PPUps = Move3_PPUps, Move4_PPUps = Move4_PPUps, Move1_PP = PKX.getMovePP(Move1, Move1_PPUps), Move2_PP = PKX.getMovePP(Move2, Move2_PPUps), Move3_PP = PKX.getMovePP(Move3, Move3_PPUps), Move4_PP = PKX.getMovePP(Move4, Move4_PPUps), IV_HP = IV_HP, IV_ATK = IV_ATK, IV_DEF = IV_DEF, IV_SPA = IV_SPA, IV_SPD = IV_SPD, IV_SPE = IV_SPE, Ability = PKM.Gen3Abilities[Species][Ability], Version = Version, Ball = Pokéball, PKRS_Strain = PKRS_Strain, PKRS_Days = PKRS_Days, OT_Gender = OT_Gender, Met_Year = moment.Year - 2000, Met_Month = moment.Month, Met_Day = moment.Day, Met_Location = 0x37, // Pal Park RIB6_4 = Champion, RIB6_5 = Winning, RIB6_6 = Victory, RIB6_7 = Artist, RIB7_0 = Effort, RIB7_1 = Special1, // Battle Champion Ribbon RIB7_2 = Special2, // Regional Champion Ribbon RIB7_3 = Special3, // National Champion Ribbon RIB7_4 = Special4, // Country Ribbon RIB7_5 = Special5, // National Ribbon RIB7_6 = Special6, // Earth Ribbon RIB7_7 = Special7, // World Ribbon }; // Remaining Ribbons pk4.RIB4_0 |= Cool_Ribbons > 0; pk4.RIB4_1 |= Cool_Ribbons > 1; pk4.RIB4_2 |= Cool_Ribbons > 2; pk4.RIB4_3 |= Cool_Ribbons > 3; pk4.RIB4_4 |= Beauty_Ribbons > 0; pk4.RIB4_5 |= Beauty_Ribbons > 1; pk4.RIB4_6 |= Beauty_Ribbons > 2; pk4.RIB4_7 |= Beauty_Ribbons > 3; pk4.RIB5_0 |= Cute_Ribbons > 0; pk4.RIB5_1 |= Cute_Ribbons > 1; pk4.RIB5_2 |= Cute_Ribbons > 2; pk4.RIB5_3 |= Cute_Ribbons > 3; pk4.RIB5_4 |= Smart_Ribbons > 0; pk4.RIB5_5 |= Smart_Ribbons > 1; pk4.RIB5_6 |= Smart_Ribbons > 2; pk4.RIB5_7 |= Smart_Ribbons > 3; pk4.RIB6_0 |= Tough_Ribbons > 0; pk4.RIB6_1 |= Tough_Ribbons > 1; pk4.RIB6_2 |= Tough_Ribbons > 2; pk4.RIB6_3 |= Tough_Ribbons > 3; // Yay for reusing string buffers! PKM.G4TransferTrashBytes[pk4.Language].CopyTo(pk4.Data, 0x48 + 4); pk4.Nickname = IsEgg ? PKM.getSpeciesName(pk4.Species, pk4.Language) : Nickname; Array.Copy(pk4.Data, 0x48, pk4.Data, 0x68, 0x10); pk4.OT_Name = OT_Name; // Ribbons // Set Final Data pk4.Met_Level = PKX.getLevel(pk4.Species, pk4.EXP); pk4.Gender = PKM.getGender(pk4.Species, pk4.PID); pk4.IsNicknamed |= pk4.Nickname != PKM.getSpeciesName(pk4.Species, pk4.Language); // Remove HM moves int[] banned = { 15, 19, 57, 70, 148, 249, 127, 291 }; int[] newMoves = pk4.Moves; for (int i = 0; i < 4; i++) { if (banned.Contains(newMoves[i])) { newMoves[i] = 0; } } pk4.Moves = newMoves; pk4.FixMoves(); pk4.RefreshChecksum(); return(pk4); }