private void save() { foreach (var rib in riblist) { ReflectUtil.SetValue(pkm, rib.Name, rib.RibbonCount < 0 ? rib.HasRibbon : (object)rib.RibbonCount); } Main.pkm = pkm; }
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.PropertyValue == CONST_RAND && (cmd.PropertyName == "PID" || cmd.PropertyName == "EncryptionConstant")) { ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32().ToString()); } else if (cmd.PropertyValue == CONST_SHINY && cmd.PropertyName == "PID") { PKM.setShinyPID(); } else if (cmd.PropertyValue == "0" && cmd.PropertyName == "Species") { 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); }
private static void setRandomIVs(PKM PKM, StringInstruction cmd) { int MaxIVs = PKM.Format <= 2 ? 15 : 31; if (cmd.PropertyName == "IVs") { ReflectUtil.SetValue(PKM, cmd.PropertyName, new byte[6].Select(i => (int)Util.rnd32() & MaxIVs).ToArray()); } else { ReflectUtil.SetValue(PKM, cmd.PropertyName, Util.rnd32() & MaxIVs); } }
protected void TransferPropertiesWithReflection(PKM Source, PKM Destination) { var SourceProperties = ReflectUtil.getPropertiesCanWritePublic(Source.GetType()); var DestinationProperties = ReflectUtil.getPropertiesCanWritePublic(Destination.GetType()); foreach (string property in SourceProperties.Intersect(DestinationProperties).Where(prop => prop != nameof(Data))) { var prop = ReflectUtil.GetValue(this, property); if (prop == null) { continue; } ReflectUtil.SetValue(Destination, property, prop); } }
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.SecretSuperTraining = CHK_Secret.Checked; pk6.TrainingBag = CB_Bag.SelectedIndex; pk6.TrainingBagHits = (int)NUD_BagHits.Value; } Main.pkm = pkm; }
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); } }
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); }