/// <summary> /// Randomize the PID of all <see cref="PKM"/> in the <see cref="data"/>. /// </summary> /// <param name="sav">Save File to personalize</param> /// <param name="data">Data to personalize</param> /// <param name="flag">Shiny/UnShiny flag</param> /// <returns></returns> private static int SetPIDAll(this SaveFile sav, IList <PKM> data, string flag) { var count = 0; for (int i = 0; i < data.Count; i++) { var pkm = data[i]; if (pkm == null || pkm.Species <= 0) { continue; } var result = pkm.SetRandomPID(sav.Version, flag); if (result.Species == 201) { Legalizer.SetMetValid(result); } LegalityAnalysis la = new LegalityAnalysis(result); if (!la.Valid) { continue; } data[i] = result; count++; } return(count); }
private static AutoModErrorCode ImportSetToTabs(ShowdownSet set, bool skipDialog = false) { var regen = new RegenTemplate(set, SaveFileEditor.SAV.Generation); if (!skipDialog && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Import this set?", regen.Text)) { return(AutoModErrorCode.NoSingleImport); } if (set.InvalidLines.Count > 0) { return(AutoModErrorCode.InvalidLines); } Debug.WriteLine($"Commencing Import of {GameInfo.Strings.Species[set.Species]}"); var timer = Stopwatch.StartNew(); var sav = SaveFileEditor.SAV; var legal = sav.GetLegalFromSet(regen, out var msg); timer.Stop(); if (msg is LegalizationResult.Timeout or LegalizationResult.Failed) { Legalizer.Dump(regen, msg == LegalizationResult.Failed); string?analysis = null; if (msg is LegalizationResult.Failed) { analysis = regen.SetAnalysis(sav, sav.BlankPKM); } var errorstr = msg == LegalizationResult.Failed ? "failed to generate" : "timed out"; var invalid_set_error = (analysis == null ? $"Set {errorstr}." : $"Set Invalid: {analysis}") + "\n\nIf you are sure this set is valid, please create an issue on GitHub and upload the error_log.txt file in the issue." + "\n\nAlternatively, join the support Discord and post the same file in the #autolegality-livehex-help channel."; var res = WinFormsUtil.ALMError(invalid_set_error); if (res == DialogResult.Yes) { Process.Start("https://discord.gg/tDMvSRv"); } else if (res == DialogResult.No) { Process.Start("https://github.com/architdate/PKHeX-Plugins/issues"); } } Debug.WriteLine("Single Set Genning Complete. Loading final data to tabs."); PKMEditor.PopulateFields(legal); var timespan = timer.Elapsed; Debug.WriteLine($"Time to complete {nameof(ImportSetToTabs)}: {timespan.Minutes:00} minutes {timespan.Seconds:00} seconds {timespan.Milliseconds / 10:00} milliseconds"); return(AutoModErrorCode.None); }
/// <summary> /// Truly code to personalize <see cref="PKM"/> /// </summary> /// <param name="pkm">Pokemon to be personalized</param> /// <param name="gameVersion">Current Game Version</param> /// <returns></returns> private static PKM PersonalizePokemon(PKM pkm, GameVersion gameVersion) { bool isLimited = isLimitedPokemon(pkm, gameVersion); if (!isLimited) { // Change the original version to game version pkm.Version = (int)gameVersion != 56 ? (int)gameVersion : (int)gameVersion; // change version => change met data if (pkm.Format >= 3) { Legalizer.SetMetValid(pkm); } } Personalize(pkm, isLimited); int format = pkm.Format; if (format == 6 || format == 7 || format == 8) { // Check if it is a pokemon that evolves to link trade if (!LinkTradeEvo.GetLinkTradeEvoPkmList.Contains(pkm.Species) && !isLimited) { pkm.ClearCurrentHandler(); if (pkm is IGeoTrack g) { // to be modified g.Geo1_Country = 0; g.Geo1_Region = 0; g.Geo2_Country = 0; g.Geo2_Region = 0; g.Geo3_Country = 0; g.Geo3_Region = 0; g.Geo4_Country = 0; g.Geo4_Region = 0; g.Geo5_Country = 0; g.Geo5_Region = 0; } ITrainerMemories trainerMemories = (ITrainerMemories)pkm; Extensions.ClearMemoriesHT(trainerMemories); } } return(pkm); }