public static List <PKM> GetLivingDex(this ITrainerInfo tr, IEnumerable <int> speciesToGenerate, PKM blank) { var result = new List <PKM>(); var destType = blank.GetType(); foreach (var s in speciesToGenerate) { var pk = blank.Clone(); pk.Species = s; pk.Gender = pk.GetSaneGender(); var pi = pk.PersonalInfo; for (int f = 0; f < pi.FormCount; f++) { var entry = tr.GetLivingEntry(pk, s, f, destType); if (entry == null) { continue; } result.Add(entry); } } return(result); }
/// <summary> /// Method to set PID, IV while validating nature. /// </summary> /// <param name="pk">PKM to modify</param> /// <param name="Method">Given Method</param> /// <param name="HPType">HPType INT for preserving Hidden powers</param> private static void FindPIDIV(PKM pk, PIDType Method, int HPType) { if (Method == PIDType.None) { Method = FindLikelyPIDType(pk); if (pk.Version == 15) { Method = PIDType.CXD; } if (Method == PIDType.None) { pk.SetPIDGender(pk.Gender); } } var iterPKM = pk.Clone(); while (true) { uint seed = Util.Rand32(); PIDGenerator.SetValuesFromSeed(pk, Method, seed); if (!(pk.Ability == iterPKM.Ability && pk.AbilityNumber == iterPKM.AbilityNumber && pk.Nature == iterPKM.Nature)) { continue; } if (HPType >= 0 && pk.HPType != HPType) { continue; } if (pk.PID % 25 != iterPKM.Nature) // Util.Rand32 is the way to go { continue; } break; } }
private async Task <PKM> ShowdownImportFromClipboard(PKM template) { var txt = await DataUtil.GetClipboardText().ConfigureAwait(false); if (txt == null) { return(null); } var set = new ShowdownSet(txt); if (set.Species < 0) { await UserDialogs.Instance .AlertAsync("No valid Showdown Set data was found. Please try again.") .ConfigureAwait(false); return(null); } var pkm = template.Clone(); if (set.Nickname?.Length > pkm.NickLength) { set.Nickname = set.Nickname.Substring(0, pkm.NickLength); } pkm.ApplySetDetails(set); return(pkm); }
/// <summary> /// Adds the trainer details of the <see cref="pkm"/> to the <see cref="Database"/>. /// </summary> /// <param name="pkm">Pokémon with Trainer details to add.</param> /// <remarks>A copy of the object will be made to prevent modifications, just in case.</remarks> public void Register(PKM pkm) { if (pkm.GenNumber >= 8 || pkm.GG) { pkm.ConsoleRegion = pkm.Region = pkm.Country = 0; } Register(new PokeTrainerDetails(pkm.Clone())); }
/// <summary> /// Method to set PID, IV while validating nature. /// </summary> /// <param name="pk">PKM to modify</param> /// <param name="Method">Given Method</param> /// <param name="HPType">HPType INT for preserving Hidden powers</param> private static void FindPIDIV(PKM pk, PIDType Method, int HPType) { if (Method == PIDType.None) { Method = FindLikelyPIDType(pk); if (pk.Version == (int)GameVersion.CXD && Method != PIDType.PokeSpot) { Method = PIDType.CXD; } if (Method == PIDType.None) { pk.SetPIDGender(pk.Gender); } } if (Method == PIDType.Method_1_Roamer && pk.HPType != (int)MoveType.Fighting - 1) // M1 Roamers can only be HP fighting { return; } if (Method == PIDType.Pokewalker && (pk.Nature >= 24 || pk.AbilityNumber == 4)) // No possible pokewalker matches { return; } var iterPKM = pk.Clone(); while (true) { uint seed = Util.Rand32(); if (PokeWalkerSeedFail(seed, Method, pk, iterPKM)) { continue; } PIDGenerator.SetValuesFromSeed(pk, Method, seed); if (!(pk.Ability == iterPKM.Ability && pk.AbilityNumber == iterPKM.AbilityNumber && pk.Nature == iterPKM.Nature)) { continue; } if (HPType >= 0 && pk.HPType != HPType) { continue; } if (pk.PID % 25 != iterPKM.Nature) // Util.Rand32 is the way to go { continue; } if (pk.Version == (int)GameVersion.CXD && Method == PIDType.CXD) // verify locks { pk.EncryptionConstant = pk.PID; var la = new LegalityAnalysis(pk); if (la.Info.PIDIV.Type != PIDType.CXD || !la.Info.PIDIVMatches) { continue; } } break; } }
/// <summary> /// Gets all balls that are legal for the input <see cref="PKM"/>. /// </summary> /// <remarks> /// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried. /// </remarks> /// <param name="pk">Pokémon to retrieve a list of valid balls for.</param> /// <returns>Enumerable list of <see cref="Ball"/> values that the <see cref="PKM"/> is legal with.</returns> public static IEnumerable <Ball> GetLegalBalls(PKM pk) { var clone = pk.Clone(); foreach (var b in BallList) { clone.Ball = (int)b; if (new LegalityAnalysis(clone).Valid) { yield return(b); } } }
/// <summary> /// Tries to regenerate the <see cref="pk"/> into a valid pkm. /// </summary> /// <param name="tr">Source/Destination trainer</param> /// <param name="pk">Currently invalid pkm data</param> /// <returns>Legalized PKM (hopefully legal)</returns> public static PKM Legalize(this ITrainerInfo tr, PKM pk) { var set = new ShowdownSet(ShowdownSet.GetShowdownText(pk)); var legal = tr.GetLegalFromTemplate(pk, set, out var satisfied); if (satisfied) { return(legal); } var dest = new PokeTrainerDetails(pk.Clone()); var resetForm = ShowdownUtil.IsInvalidForm(set.Form); legal = BruteForce.ApplyDetails(pk, set, resetForm, dest); legal.SetTrainerData(dest); return(legal); }
private static void FindNestPIDIV(PKM pk, EncounterStatic8N enc, bool shiny) { // Preserve Nature, Altform, Ability (only if HA) // Nest encounter RNG generation int iv_count = enc.FlawlessIVCount; int ability_param; int gender_ratio = pk.PersonalInfo.Gender; const int nature_param = 255; // random nature in raids // TODO: Ability param for A2 raids if (enc.Ability == 0) { ability_param = 255; } else if (enc.Ability == -1) { ability_param = 254; } else { ability_param = enc.Ability >> 1; } var iterPKM = pk.Clone(); while (true) { ulong seed = GetRandomULong(); var RNG = new XOROSHIRO(seed); if (!shiny) { SetValuesFromSeed8Unshiny(pk, RNG, iv_count, ability_param, gender_ratio, nature_param); } if (!(pk.Nature == iterPKM.Nature && pk.AltForm == iterPKM.AltForm)) { continue; } if (iterPKM.AbilityNumber == 4 && !(pk.Ability == iterPKM.Ability && pk.AbilityNumber == iterPKM.AbilityNumber)) { continue; } // can be ability capsuled pk.RefreshAbility(pk.AbilityNumber >> 1); break; } }
/// <summary> /// Accessible method to lead Fields from PKM /// The Loading is done in WinForms /// </summary> /// <param name="pk">The PKM file</param> /// <param name="focus">Set input focus to control</param> /// <param name="skipConversionCheck">Default this to true</param> public void LoadFieldsFromPKM2(PKM pk, bool focus = true, bool skipConversionCheck = true) { if (pk == null) { WinFormsUtil.Error("Attempted to load a null file."); return; } if (focus) { Tab_Main.Focus(); } if (!skipConversionCheck && !PKMConverter.TryMakePKMCompatible(pk, CurrentPKM, out string c, out pk)) { WinFormsUtil.Alert(c); return; } bool oldInit = FieldsInitialized; FieldsInitialized = FieldsLoaded = false; pkm = pk.Clone(); try { GetFieldsfromPKM(); } finally { FieldsInitialized = oldInit; } Stats.UpdateIVs(null, null); UpdatePKRSInfected(null, null); UpdatePKRSCured(null, null); if (HaX) // Load original values from pk not pkm { MT_Level.Text = (pk.Stat_HPMax != 0 ? pk.Stat_Level : PKX.GetLevel(pk.EXP, pk.Species, pk.AltForm)).ToString(); TB_EXP.Text = pk.EXP.ToString(); MT_Form.Text = pk.AltForm.ToString(); if (pk.Stat_HPMax != 0) // stats present { Stats.LoadPartyStats(pk); } } FieldsLoaded = true; SetMarkings(); UpdateLegality(); UpdateSprite(); LastData = PreparePKM()?.Data; }
/// <summary> /// Gets a moveset for the provided <see cref="PKM"/> data. /// </summary> /// <param name="pk">PKM to generate for</param> /// <param name="random">Full movepool & shuffling</param> /// <returns>4 moves</returns> public static int[] GetMoveSet(this PKM pk, bool random = false) { var la = new LegalityAnalysis(pk); var moves = la.GetMoveSet(random); if (random) { return(moves); } var clone = pk.Clone(); clone.SetMoves(moves); clone.SetMaximumPPCurrent(moves); var newLa = new LegalityAnalysis(clone); // ReSharper disable once TailRecursiveCall return(newLa.Valid ? moves : GetMoveSet(pk, true)); }
private PKM Legalize(PKM pk, GameVersion ver) { Report = la.Report(); var sav = SaveUtil.GetBlankSAV(ver, pk.OT_Name); sav.TID = pk.TID; sav.SID = pk.SID; sav.Language = pk.Language; PKM upd = sav.Legalize(pk.Clone()); upd.SetTrainerData(GetTrainerInfo(pk, ver)); la = new LegalityAnalysis(upd); if (la.Valid) { legalpk = upd; Successful = true; return(legalpk); } return(null); }
private static PKM?ConvertPKM(PKM pk, Type destType, ref EntityConverterResult result) { PKM?entity = pk.Clone(); if (entity.IsEgg) { entity.ForceHatchPKM(); } while (true) { entity = IntermediaryConvert(entity, destType, ref result); if (entity == null) // fail convert { return(null); } if (entity.GetType() == destType) // finish convert { return(entity); } } }
/// <summary> /// Tries to regenerate the <see cref="pk"/> into a valid pkm. /// </summary> /// <param name="tr">Source/Destination trainer</param> /// <param name="pk">Currently invalid pkm data</param> /// <returns>Legalized PKM (hopefully legal)</returns> public static PKM Legalize(this ITrainerInfo tr, PKM pk) { var set = new RegenTemplate(pk) { Ball = (Ball)pk.Ball, ShinyType = pk.ShinyXor == 0 ? Shiny.AlwaysSquare : pk.IsShiny ? Shiny.AlwaysStar : Shiny.Never }; var legal = tr.GetLegalFromTemplate(pk, set, out var satisfied); if (satisfied) { return(legal); } var dest = new PokeTrainerDetails(pk.Clone()); var resetForm = ShowdownUtil.IsInvalidForm(set.Form); legal = BruteForce.ApplyDetails(pk, set, resetForm, dest); legal.SetTrainerData(dest); return(legal); }
private static PKM SetUnShinyPID(PKM pkm, GameVersion gameVersion) { PKM tmp = pkm.Clone(); switch (tmp.Format) { case 1: case 2: tmp.Gen12UnShiny(); return(tmp); case 3: case 4: case 5: tmp.Gen345UnShiny(); return(tmp); default: // Gen6-Gen8 tmp.Gen678UnShiny(); return(tmp); } }
private static PKM SetSquareShinyPID(PKM pkm, GameVersion gameVersion) { PKM tmp = pkm.Clone(); switch (tmp.Format) { case 1: case 2: tmp.Gen12Shiny(); return(tmp); case 3: case 4: case 5: tmp.Gen345Shiny(Shiny.AlwaysSquare); return(tmp); default: // Gen6-Gen8 tmp.Gen678Shiny(Shiny.AlwaysSquare); return(tmp); } }
private static PKM SetToEgg(PKM pkm, int origin, GameVersion gameVersion) { int dayCare = origin <= 4 ? Locations.Daycare4 : Locations.Daycare5; int metLevel = origin <= 4 ? 0 : 1; int currentLevel = origin <= 4 ? 5 : 1; // 非初级形态 PKM tmp = pkm.Clone(); tmp.IsEgg = true; tmp.Egg_Location = dayCare; tmp.Data[0xA8] = tmp.Data[0xA8 + 1] = 0; //Milotic List <CheckResult> checkResult = EncounterFinder.FindVerifiedEncounter(tmp).Parse; if (checkResult.IsPropStrInEleList("Comment", LegalityCheckStrings.LEvoInvalid)) { return(null); } int language = pkm.Language; pkm.Nickname = SpeciesName.GetSpeciesNameGeneration((int)Species.None, language, pkm.Format); pkm.IsNicknamed = true; pkm.IsEgg = true; pkm.HeldItem = 0; pkm.CurrentLevel = currentLevel; pkm.StatNature = pkm.Nature; pkm.RefreshAbility(new Random().Next(0, 3)); pkm.SetIVs(); pkm.EVs = new int[6]; pkm.Ball = (int)Ball.Poke; pkm.Met_Location = 0; pkm.Met_Level = metLevel; pkm.Egg_Location = dayCare; ReflectUtils.methods.TryGetValue("GetEggMoves", out MethodInfo method); int[] result = (int[])method.Invoke(null, new object[] { pkm, pkm.Species, pkm.AltForm, gameVersion }); pkm.SetMoves(new List <int>()); if (result.Length == 0) { pkm.SetRelearnMoves(pkm.GetSuggestedRelearnMoves()); } else { pkm.SetRelearnMoves(GetEggMovesRandom(pkm, result)); } pkm.SetMoves(pkm.RelearnMoves); pkm.SetMovesPPUpsToZero(); pkm.SetMaximumPPCurrent(); pkm.FixMoves(); // 8代独有数据 if (pkm.Format == 8) { PK8 pk8 = (PK8)pkm; pk8.DynamaxLevel = 0; pk8.CanGigantamax = false; } pkm.ClearAllRibbon(); pkm.ClearCurrentHandler(); pkm.ClearMemories(); pkm.ClearRecordFlags(); pkm.CurrentFriendship = 4; return(pkm); }
private bool convert(string path, Type t) { FileInfo fi = new FileInfo(path); bool prefer7 = fi.Extension.EndsWith("7"); int genPref = prefer7 ? 7 : 6; if (!PKX.getIsPKM(fi.Length)) { return(log(path, false, "Not a valid PKM size.")); } var pk = PKMConverter.getPKMfromBytes(File.ReadAllBytes(path), prefer: genPref); if (pk.GetType() == t) { return(log(path, false, "Matches desired format.")); } if (pk.Species <= 0) { return(log(path, false, "Not a valid PKM.")); } string comment; var converted = PKMConverter.convertToFormat(pk, t, out comment); if (converted == null) { if (!reflectiveConvertPrompted) { reflectiveConvertPrompted = true; var dr = Prompt(MessageBoxButtons.YesNo, "Incompatible conversion detected.", "Try reflective conversion?"); if (dr == DialogResult.Yes) { reflectiveConvertAllowed = true; } } if (!reflectiveConvertAllowed) { return(log(path, false, "Not converting via reflection.")); } try { if (!checkCompatible(pk)) { return(log(path, false, "Unable to transfer with reflection.")); } converted = Blank.Clone(); pk.TransferPropertiesWithReflection(pk, converted); comment = "Converted via reflection."; } catch (Exception e) { return(log(path, false, e.Message)); } } // Write File try { string foldername = Path.GetDirectoryName(path); if (foldername == null) { return(log(path, false, "Invalid Folder.")); } File.WriteAllBytes(Path.Combine(foldername, (fi.Name.Substring(0, fi.Name.Length - 3) + currType.ToLower())), converted.DecryptedBoxData); return(log(path, true, comment)); } catch (Exception e) { return(log(path, false, e.Message)); } }
/// <summary> /// Adds the trainer details of the <see cref="pkm"/> to the <see cref="Database"/>. /// </summary> /// <param name="pkm">Pokémon with Trainer details to add.</param> /// <remarks>A copy of the object will be made to prevent modifications, just in case.</remarks> public void Register(PKM pkm) => Register(new PokeTrainerDetails(pkm.Clone()));
/// <summary> /// Gets a list of valid ribbons for the <see cref="pk"/> that can be removed. /// </summary> /// <param name="pk">Entity to fetch the list for.</param> /// <param name="allRibbons">All ribbon names.</param> /// <returns>List of all removable ribbon names.</returns> public static IReadOnlyList <string> GetRemovableRibbons(PKM pk, IList <string> allRibbons) { var clone = pk.Clone(); return(RemoveAllValidRibbons(allRibbons, clone)); }