private void Save() { foreach (var rib in riblist) { ReflectUtil.SetValue(pkm, rib.Name, rib.RibbonCount < 0 ? rib.HasRibbon : (object)rib.RibbonCount); } }
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 static void setRandomIVs(PKM PKM, StringInstruction cmd) { int MaxIV = PKM.Format <= 2 ? 15 : 31; if (cmd.PropertyName == "IVs") { int[] IVs = new int[6]; for (int i = 0; i < 6; i++) { IVs[i] = (int)(Util.rnd32() & MaxIV); } if (Legal.Legends.Contains(PKM.Species) || Legal.SubLegends.Contains(PKM.Species)) { for (int i = 0; i < 3; i++) { IVs[i] = MaxIV; } } Util.Shuffle(IVs); PKM.IVs = IVs; } else { ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32() & MaxIV); } }
private void SaveSettings() { foreach (var s in FLP_Settings.Controls.OfType <Control>()) { ReflectUtil.SetValue(SettingsObject, s.Name, GetValue(s)); } }
/// <summary> /// Applies localization to a static class containing language-specific strings. /// </summary> /// <param name="t">Type of the static class containing the desired strings.</param> /// <param name="lines">Lines containing the localized strings</param> private static void SetLocalization(Type t, IReadOnlyCollection <string> lines) { if (lines.Count == 0) { return; } foreach (var line in lines) { var index = line.IndexOf(TranslationSplitter); if (index < 0) { continue; } var prop = line.Substring(0, index); var value = line.Substring(index + 1); try { ReflectUtil.SetValue(t, prop, value); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) #pragma warning restore CA1031 // Do not catch general exception types { Debug.WriteLine($"Property not present: {prop} || Value written: {value}"); Debug.WriteLine(e.Message); } } }
private static void SetRibbonValues(this PKM pk, IEnumerable <string> ribNames, int vRib, bool bRib) { foreach (string rName in ribNames) { bool intRib = rName == nameof(PK6.RibbonCountMemoryBattle) || rName == nameof(PK6.RibbonCountMemoryContest); ReflectUtil.SetValue(pk, rName, intRib ? (object)vRib : bRib); } }
public static void ClearAllRibbon(this PKM pkm) { IEnumerable <RibbonInfo> riblist = RibbonInfo.GetRibbonInfo(pkm); foreach (var rib in riblist) { ReflectUtil.SetValue(pkm, rib.Name, rib.RibbonCount < 0 ? false : (object)0); } }
/// <summary> /// Fix invalid and missing ribbons. (V600 and V601) /// </summary> /// <param name="pk">PKM whose ribbons need to be fixed</param> public static void FixRibbons(PKM pk) { string Report = new LegalityAnalysis(pk).Report(); if (Report.Contains(String.Format(V600, ""))) { string[] ribbonList = Report.Split(new string[] { String.Format(V600, "") }, StringSplitOptions.None)[1].Split(new string[] { "\r\n" }, StringSplitOptions.None)[0].Split(new string[] { ", " }, StringSplitOptions.None); var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pk.GetType(), "Ribbon").Distinct(); List <string> missingRibbons = new List <string>(); foreach (var RibbonName in RibbonNames) { string v = RibbonStrings.GetName(RibbonName).Replace("Ribbon", ""); if (ribbonList.Contains(v)) { missingRibbons.Add(RibbonName); } } foreach (string missing in missingRibbons) { if (missing == "RibbonCountMemoryBattle" || missing == "RibbonCountMemoryContest") { ReflectUtil.SetValue(pk, missing, 0); } else { ReflectUtil.SetValue(pk, missing, -1); } } } if (Report.Contains(String.Format(V601, ""))) { string[] ribbonList = Report.Split(new string[] { String.Format(V601, "") }, StringSplitOptions.None)[1].Split(new string[] { "\r\n" }, StringSplitOptions.None)[0].Split(new string[] { ", " }, StringSplitOptions.None); var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pk.GetType(), "Ribbon").Distinct(); List <string> invalidRibbons = new List <string>(); foreach (var RibbonName in RibbonNames) { string v = RibbonStrings.GetName(RibbonName).Replace("Ribbon", ""); if (ribbonList.Contains(v)) { invalidRibbons.Add(RibbonName); } } foreach (string invalid in invalidRibbons) { if (invalid == "RibbonCountMemoryBattle" || invalid == "RibbonCountMemoryContest") { ReflectUtil.SetValue(pk, invalid, 0); } else { ReflectUtil.SetValue(pk, invalid, false); } } } }
private void Save() { foreach (var rib in riblist) { ReflectUtil.SetValue(pkm, rib.Name, rib.RibbonCount < 0 ? rib.HasRibbon : rib.RibbonCount); } if (pkm is PK8 pk8) { pk8.AffixedRibbon = (sbyte)WinFormsUtil.GetIndex(CB_Affixed); } }
private void Save() { foreach (var rib in riblist) { ReflectUtil.SetValue(Entity, rib.Name, rib.RibbonCount < 0 ? rib.HasRibbon : rib.RibbonCount); } if (Entity is IRibbonSetAffixed affixed) { affixed.AffixedRibbon = (sbyte)WinFormsUtil.GetIndex(CB_Affixed); } }
private static void setProperty(PKM PKM, StringInstruction cmd) { if (cmd.PropertyName == nameof(PKM.MetDate)) { PKM.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); } else if (cmd.PropertyName == nameof(PKM.EggMetDate)) { PKM.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); } else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == CONST_RAND) { ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString()); } else if ((cmd.PropertyName == nameof(PKM.Ability) || cmd.PropertyName == nameof(PKM.AbilityNumber)) && cmd.PropertyValue.StartsWith("$")) { PKM.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30); } else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_RAND) { PKM.setPIDGender(PKM.Gender); } else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == nameof(PKM.PID)) { PKM.EncryptionConstant = PKM.PID; } else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_SHINY) { PKM.setShinyPID(); } else if (cmd.PropertyName == nameof(PKM.Species) && cmd.PropertyValue == "0") { PKM.Data = new byte[PKM.Data.Length]; } else if (cmd.PropertyName.StartsWith("IV") && cmd.PropertyValue == CONST_RAND) { setRandomIVs(PKM, cmd); } else if (cmd.Random) { ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.RandomValue); } else if (cmd.PropertyName == nameof(PKM.IsNicknamed) && cmd.PropertyValue.ToLower() == "false") { PKM.IsNicknamed = false; PKM.Nickname = PKX.getSpeciesName(PKM.Species, PKM.Language); } else { ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue); } }
private static void setRandomIVs(PKM PKM, StringInstruction cmd) { int MaxIV = PKM.Format <= 2 ? 15 : 31; if (cmd.PropertyName == "IVs") { bool IV3 = Legal.Legends.Contains(PKM.Species) || Legal.SubLegends.Contains(PKM.Species); int[] IVs = new int[6]; do { for (int i = 0; i < 6; i++) { IVs[i] = (int)(Util.rnd32() & MaxIV); } } while (IV3 && IVs.Where(i => i == MaxIV).Count() < 3); ReflectUtil.SetValue(PKM, cmd.PropertyName, IVs); } else { ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32() & MaxIV); } }
/// <summary> /// Colosseum/XD pokemon need to be fixed. Fix Gender further in logic using <see cref="FixGender(PKM)"/> /// </summary> /// <param name="pkm">PKM to apply the fix to</param> public static void ColosseumFixes(PKM pkm) { if (pkm.Version == 15) { var RibbonNames = ReflectUtil.GetPropertiesStartWithPrefix(pkm.GetType(), "Ribbon").Distinct(); foreach (var RibbonName in RibbonNames) { if (RibbonName == "RibbonCountMemoryBattle" || RibbonName == "RibbonCountMemoryContest") { ReflectUtil.SetValue(pkm, RibbonName, 0); } else { ReflectUtil.SetValue(pkm, RibbonName, false); } } ReflectUtil.SetValue(pkm, "RibbonNational", true); pkm.Ball = 4; pkm.FatefulEncounter = true; pkm.OT_Gender = 0; } }
private static void SetRibbonValue(PKM pk, string rib, int value) { switch (rib) { case nameof(PK7.RibbonCountMemoryBattle): ReflectUtil.SetValue(pk, rib, value * (pk.Gen4 ? 6 : 8)); break; case nameof(PK7.RibbonCountMemoryContest): ReflectUtil.SetValue(pk, rib, value * (pk.Gen4 ? 20 : 40)); break; default: if (rib.StartsWith("RibbonCountG3", StringComparison.Ordinal)) { ReflectUtil.SetValue(pk, rib, value * 4); } else { ReflectUtil.SetValue(pk, rib, value != 0); } break; } }
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 == nameof(PKM.MetDate)) { PKM.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); } else if (cmd.PropertyName == nameof(PKM.EggMetDate)) { PKM.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); } else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == CONST_RAND) { ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString()); } else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_RAND) { PKM.setPIDGender(PKM.Gender); } else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == nameof(PKM.PID)) { PKM.EncryptionConstant = PKM.PID; } else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_SHINY) { PKM.setShinyPID(); } else if (cmd.PropertyName == nameof(PKM.Species) && cmd.PropertyValue == "0") { PKM.Data = new byte[PKM.Data.Length]; } else if (cmd.PropertyName.StartsWith("IV") && cmd.PropertyValue == CONST_RAND) { setRandomIVs(PKM, cmd); } else if (cmd.Random) { ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.RandomValue); } else { ReflectUtil.SetValue(PKM, cmd.PropertyName, cmd.PropertyValue); } result = ModifyResult.Modified; } catch { Console.WriteLine($"Unable to set {cmd.PropertyName} to {cmd.PropertyValue}."); } } return(result); }
private bool CommonErrorHandling2(PKM pk) { string hp = pk.IV_HP.ToString(); string atk = pk.IV_ATK.ToString(); string def = pk.IV_DEF.ToString(); string spa = pk.IV_SPA.ToString(); string spd = pk.IV_SPD.ToString(); string spe = pk.IV_SPE.ToString(); bool HTworkaround = false; LegalityAnalysis la = new LegalityAnalysis(pk); var report = la.Report(false); var updatedReport = report; if (report.Contains("Ability mismatch for encounter")) { pk.RefreshAbility(pk.AbilityNumber < 6 ? pk.AbilityNumber >> 1 : 0); } if (report.Contains("Invalid Met Location, expected Transporter.")) { pk.Met_Location = 30001; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("Can't have ball for encounter type.")) { if (pk.B2W2) { pk.Ball = 25; //Dream Ball LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } else { pk.Ball = 0; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } } if (report.Contains("Non japanese Mew from Faraway Island. Unreleased event.")) { pk.Language = 1; pk.FatefulEncounter = true; pk.Nickname = PKX.GetSpeciesNameGeneration(pk.Species, pk.Language, 3); pk.PID = PKX.GetRandomPID(pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001)); LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("PID should be equal to EC!")) { pk.EncryptionConstant = pk.PID; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("PID should be equal to EC [with top bit flipped]!")) { pk.PID = PKX.GetRandomPID(pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001)); if (pk.IsShiny) { pk.SetShinyPID(); } LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("PID-Gender mismatch.")) { if (pk.Gender == 0) { pk.Gender = 1; } else { pk.Gender = 0; } LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("Missing Ribbons: National")) { ReflectUtil.SetValue(pk, "RibbonNational", -1); LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("Invalid Ribbons: National")) { ReflectUtil.SetValue(pk, "RibbonNational", 0); LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("OT Name too long.")) { pk.OT_Name = "ARCH"; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("GeoLocation Memory: Memories should be present.")) { pk.Geo1_Country = 1; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("Can't have ball for encounter type.")) { pk.Ball = 4; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("Can't have any OT Memory.")) { pk.OT_Memory = 0; pk.OT_Intensity = 0; pk.OT_Feeling = 0; pk.OT_TextVar = 0; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("OT Memory: Should be index 0.")) { pk.OT_Memory = 0; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("OT Memory: Intensity should be index 0.")) { pk.OT_Intensity = 0; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("OT Memory: Feeling should be index 0.")) { pk.OT_Feeling = 0; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("OT Memory: TextVar should be index 0.")) { pk.OT_TextVar = 0; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("Form cannot exist outside of a battle.")) { pk.AltForm = 0; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("Special ingame Fateful Encounter flag missing")) { pk.FatefulEncounter = true; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Contains("Fateful Encounter should not be checked.")) { pk.FatefulEncounter = false; LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; } if (report.Equals("Invalid: Encounter Type PID mismatch.")) { //return true; if (pk.Version == (int)GameVersion.CXD) { pk = setPIDSID(pk, pk.IsShiny, true); } else { pk = setPIDSID(pk, pk.IsShiny); } if (new LegalityAnalysis(pk).Valid) { return(false); } if (pk.HT_HP) { HTworkaround = true; } LegalityAnalysis recheckLA = new LegalityAnalysis(pk); updatedReport = recheckLA.Report(false); report = updatedReport; if (report.Equals("Invalid: Encounter Type PID mismatch.")) { return(true); } else if (report.Contains("PID-Gender mismatch.")) { if (pk.Gender == 0) { pk.Gender = 1; } else { pk.Gender = 0; } LegalityAnalysis recheckLA2 = new LegalityAnalysis(pk); updatedReport = recheckLA2.Report(false); report = updatedReport; if (new LegalityAnalysis(pk).Valid) { return(false); } } } return(false); }