/// <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> /// <param name="originalPKMN"></param> public static void FindPIDIV(PKM pk, PIDType Method, int HPType, PKM originalPKMN) { if (Method == PIDType.None) { Method = FindLikelyPIDType(pk, originalPKMN); if (pk.Version == 15) { Method = PIDType.CXD; } if (Method == PIDType.None) { pk.SetPIDGender(pk.Gender); } } PKM iterPKM = pk; while (Method != PIDType.None) { uint seed = Util.Rand32(); PIDGenerator.SetValuesFromSeed(pk, Method, seed); if (!(pk.Ability == iterPKM.Ability && pk.AbilityNumber == iterPKM.AbilityNumber && pk.Nature == iterPKM.Nature)) { continue; } if (pk.PID % 25 == iterPKM.Nature && pk.HPType == HPType) // Util.Rand32 is the way to go { break; } pk = iterPKM; } }
public static void Gen3UnShiny(this PKM pkm) { RNG rng = RNG.LCRNG; PIDType type = PIDType.Method_1; if (pkm.Version == (int)GameVersion.CXD) { rng = RNG.XDRNG; type = PIDType.CXD; } IEnumerable <uint> seeds; do { pkm.SetPIDGender(pkm.Gender); seeds = GetSeedsFromPID(pkm.PID, rng); } while (pkm.IsShiny || seeds == null); if (pkm.Species == 201) { type = PIDType.Method_1_Unown; } PIDGenerator.SetValuesFromSeed(pkm, type, seeds.ElementAt(0)); }
public void PIDIVMatchingTest3() { // Method 1/2/4 var pk1 = new PK3 { PID = 0xE97E0000, IVs = new[] { 17, 19, 20, 16, 13, 12 } }; var ga1 = MethodFinder.Analyze(pk1); Assert.AreEqual(PIDType.Method_1, ga1.Type, "Unable to match PID to Method 1 spread"); var pk2 = new PK3 { PID = 0x5271E97E, IVs = new[] { 02, 18, 03, 12, 22, 24 } }; Assert.AreEqual(PIDType.Method_2, MethodFinder.Analyze(pk2)?.Type, "Unable to match PID to Method 2 spread"); var pk4 = new PK3 { PID = 0x31B05271, IVs = new[] { 02, 18, 03, 05, 30, 11 } }; Assert.AreEqual(PIDType.Method_4, MethodFinder.Analyze(pk4)?.Type, "Unable to match PID to Method 4 spread"); var gk1 = new PK3(); PIDGenerator.SetValuesFromSeed(gk1, ga1.Type, ga1.OriginSeed); Assert.AreEqual(pk1.PID, gk1.PID, "Unable to match generated PID to Method 1 PID"); Assert.IsTrue(gk1.IVs.SequenceEqual(pk1.IVs), "Unable to match generated PID to Method 1 IVs"); }
private static bool GetPokewalkerMatch(PKM pk, uint oldpid, out PIDIV pidiv) { // check surface compatibility var mid = oldpid & 0x00FFFF00; if (mid != 0 && mid != 0x00FFFF00) // not expected bits { return(GetNonMatch(out pidiv)); } var nature = oldpid % 25; if (nature == 24) // impossible nature { return(GetNonMatch(out pidiv)); } var gender = pk.Gender; uint pid = PIDGenerator.GetPokeWalkerPID(pk.TID, pk.SID, nature, gender, pk.PersonalInfo.Gender); if (pid != oldpid) { if (!(gender == 0 && IsAzurillEdgeCaseM(pk, nature, oldpid))) { return(GetNonMatch(out pidiv)); } } pidiv = PIDIV.Pokewalker; return(true); }
public void PIDIVMatchingTest3Misc() { // Colosseum / XD var pk3 = new PK3 { PID = 0x0985A297, IVs = new[] { 06, 01, 00, 07, 17, 07 } }; var ak3 = MethodFinder.Analyze(pk3); Assert.AreEqual(PIDType.CXD, MethodFinder.Analyze(pk3)?.Type, "Unable to match PID to CXD spread"); var gk3 = new PK3(); PIDGenerator.SetValuesFromSeed(gk3, PIDType.CXD, ak3.OriginSeed); Assert.AreEqual(pk3.PID, gk3.PID, "Unable to match generated PID to CXD spread"); Assert.IsTrue(pk3.IVs.SequenceEqual(gk3.IVs), "Unable to match generated IVs to CXD spread"); // Channel Jirachi var pkC = new PK3 { PID = 0x264750D9, IVs = new[] { 06, 31, 14, 27, 05, 27 }, SID = 45819, OT_Gender = 1, Version = (int)GameVersion.R }; var akC = MethodFinder.Analyze(pkC); Assert.AreEqual(PIDType.Channel, akC.Type, "Unable to match PID to Channel spread"); var gkC = new PK3(); PIDGenerator.SetValuesFromSeed(gkC, PIDType.Channel, akC.OriginSeed); Assert.AreEqual(pkC.PID, gkC.PID, "Unable to match generated PID to Channel spread"); Assert.IsTrue(pkC.IVs.SequenceEqual(gkC.IVs), "Unable to match generated IVs to Channel spread"); }
public static void Gen4Shiny(this PKM pkm, Shiny shinyType) { if (pkm.GenNumber == 3) { if (pkm.Met_Location == 55 && pkm.Ball == 4) { pkm.SetPIDGender(pkm.Gender); CommonEdits.SetShiny(pkm, shinyType); return; } Gen3Shiny(pkm, shinyType); return; } RNG rng = RNG.LCRNG; PIDType type = PIDType.Method_1; if (pkm.Met_Location == 233) { type = PIDType.Pokewalker; } IEnumerable <uint> seeds; do { pkm.SetPIDGender(pkm.Gender); CommonEdits.SetShiny(pkm, shinyType); seeds = GetSeedsFromPID(pkm.PID, rng); } while (!pkm.IsShiny || seeds == null); PIDGenerator.SetValuesFromSeed(pkm, type, seeds.ElementAt(0)); }
public static void Gen5UnShiny(this PKM pkm) { var generation = pkm.GenNumber; if (generation == 3) { if (pkm.Met_Location == Locations.Transfer4 && pkm.Ball == 4) { pkm.SetPIDGender(pkm.Gender); return; } Gen3UnShiny(pkm); return; } RNG rng = RNG.LCRNG; PIDType type = PIDType.Method_1; IEnumerable <uint> seeds = null; do { pkm.SetPIDGender(pkm.Gender); seeds = GetSeedsFromPID(pkm.PID, rng); } while (pkm.IsShiny || seeds == null); PIDGenerator.SetValuesFromSeed(pkm, type, seeds.ElementAt(0)); }
/// <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; } }
/// <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; } }
protected override void SetPINGA(PKM pk, EncounterCriteria criteria) { int gender = criteria.GetGender(-1, pk.PersonalInfo); int nature = (int)criteria.GetNature(Nature.Random); int ability = Util.Rand.Next(2); PIDGenerator.SetRandomPokeSpotPID(pk, nature, gender, ability, SlotNumber); pk.Gender = gender; pk.StatNature = nature; }
public void PIDIVMatchingTest3Event() { // Restricted: TID/SID are zero. var pkR = new PK3 { PID = 0x0000E97E, IVs = new[] { 17, 19, 20, 16, 13, 12 } }; Assert.AreEqual(PIDType.BACD_R, MethodFinder.Analyze(pkR)?.Type, "Unable to match PID to BACD-R spread"); // Restricted Antishiny: PID is incremented 2 times to lose shininess. var pkRA = new PK3 { PID = 0x0000E980, IVs = new[] { 17, 19, 20, 16, 13, 12 }, TID = 01337, SID = 60486 }; Assert.AreEqual(PIDType.BACD_R_A, MethodFinder.Analyze(pkRA)?.Type, "Unable to match PID to BACD-R antishiny spread"); // Unrestricted: TID/SID are zero. var pkU = new PK3 { PID = 0x67DBFC33, IVs = new[] { 12, 25, 27, 30, 02, 31 } }; Assert.AreEqual(PIDType.BACD_U, MethodFinder.Analyze(pkU)?.Type, "Unable to match PID to BACD-U spread"); // Unrestricted Antishiny: PID is incremented 5 times to lose shininess. var pkUA = new PK3 { PID = 0x67DBFC38, IVs = new[] { 12, 25, 27, 30, 02, 31 }, TID = 01337, SID = 40657 }; Assert.AreEqual(PIDType.BACD_U_A, MethodFinder.Analyze(pkUA)?.Type, "Unable to match PID to BACD-U antishiny spread"); // berry fix zigzagoon: seed 0x0020 var pkRS = new PK3 { PID = 0x38CA4EA0, IVs = new[] { 00, 20, 28, 11, 19, 00 }, TID = 30317, SID = 00000 }; var a_pkRS = MethodFinder.Analyze(pkRS); Assert.AreEqual(PIDType.BACD_R_S, a_pkRS?.Type, "Unable to match PID to BACD-R shiny spread"); Assert.IsTrue(0x0020 == a_pkRS?.OriginSeed, "Unable to match PID to BACD-R shiny spread origin seed"); var gkRS = new PK3 { TID = 30317, SID = 00000 }; PIDGenerator.SetValuesFromSeed(gkRS, PIDType.BACD_R_S, a_pkRS.OriginSeed); Assert.AreEqual(pkRS.PID, gkRS.PID, "Unable to match generated PID to BACD-R shiny spread"); Assert.IsTrue(pkRS.IVs.SequenceEqual(gkRS.IVs), "Unable to match generated IVs to BACD-R shiny spread"); // Unrestricted Antishiny nyx var nyxUA = new PK3 { PID = 0xBD3DF676, IVs = new[] { 00, 15, 05, 04, 21, 05 }, TID = 80, SID = 0 }; var nyx_pkUA = MethodFinder.Analyze(nyxUA); Assert.AreEqual(PIDType.BACD_U_AX, nyx_pkUA?.Type, "Unable to match PID to BACD-U antishiny nyx spread"); }
public void PIDIVMatchingTest3MiscChannel() { // Channel Jirachi var pkC = new PK3 { PID = 0x264750D9, IVs = new[] { 06, 31, 14, 27, 05, 27 }, SID = 45819, OT_Gender = 1, Version = (int)GameVersion.R }; var(type, seed) = MethodFinder.Analyze(pkC); Assert.Equal(PIDType.Channel, type); var gkC = new PK3(); PIDGenerator.SetValuesFromSeed(gkC, PIDType.Channel, seed); Assert.Equal(pkC.PID, gkC.PID); Assert.True(pkC.IVs.SequenceEqual(gkC.IVs), "Unable to match generated IVs to Channel spread"); }
public void PIDIVMatchingTest3MiscCXD() { // Colosseum / XD var pk3 = new PK3 { PID = 0x0985A297, IVs = new[] { 06, 01, 00, 07, 17, 07 } }; var(type, seed) = MethodFinder.Analyze(pk3); Assert.Equal(PIDType.CXD, type); var gk3 = new PK3(); PIDGenerator.SetValuesFromSeed(gk3, PIDType.CXD, seed); Assert.Equal(pk3.PID, gk3.PID); Assert.True(pk3.IVs.SequenceEqual(gk3.IVs), "Unable to match generated IVs to CXD spread"); }
private static bool GetG5MGShinyMatch(PKM pk, uint pid, out PIDIV pidiv) { var low = pid & 0xFFFF; // generation 5 shiny PIDs if (low <= 0xFF) { var av = (pid >> 16) & 1; var genPID = PIDGenerator.GetMG5ShinyPID(low, av, pk.TID, pk.SID); if (genPID == pid) { pidiv = PIDIV.G5MGShiny; return(true); } } return(GetNonMatch(out pidiv)); }
public static void Gen3Shiny(this PKM pkm, Shiny shinyType) { RNG rng = RNG.LCRNG; PIDType type = PIDType.Method_1; if (pkm.Species == 201) { type = PIDType.Method_1_Unown; } IEnumerable <uint> seeds; do { pkm.SetPIDGender(pkm.Gender); CommonEdits.SetShiny(pkm, shinyType); seeds = GetSeedsFromPID(pkm.PID, rng); } while (!pkm.IsShiny || seeds == null); PIDGenerator.SetValuesFromSeed(pkm, type, seeds.ElementAt(0)); }
private static bool IsAzurillEdgeCaseM(PKM pk, uint nature, uint oldpid) { // check for Azurill evolution edge case... 75% F-M is now 50% F-M; was this a F->M bend? int species = pk.Species; if (species is not((int)Species.Marill or(int) Species.Azumarill)) { return(false); } const int AzurillGenderRatio = 0xBF; var gender = EntityGender.GetFromPIDAndRatio(pk.PID, AzurillGenderRatio); if (gender != 1) { return(false); } var pid = PIDGenerator.GetPokeWalkerPID(pk.TID, pk.SID, nature, 1, AzurillGenderRatio); return(pid == oldpid); }
public static void VerifyResults(IReadOnlyList <uint[]> results, TeamLock[] team) { var pkm = new PK3(); for (int i = 0; i < results.Count; i++) { var result = results[i]; var seeds = getSeeds(result[result.Length - 1]); bool match = false; foreach (var seed in seeds) { PIDGenerator.SetValuesFromSeed(pkm, PIDType.CXD, seed); var info = MethodFinder.Analyze(pkm); info.OriginSeed.Should().Be(seed); info.Type.Should().Be(PIDType.CXD, "because the PID should have matched the CXD spread"); if (!GetCanOriginateFrom(team, info)) { continue; } match = true; break; } match.Should().BeTrue($"because the lock conditions for result {i} and species {team[0].Species} should have been verified"); } IEnumerable <uint> getSeeds(uint PID) { var top = PID >> 16; var bot = PID & 0xFFFF; var seeds = MethodFinder.GetSeedsFromPIDEuclid(RNG.XDRNG, top, bot); foreach (var s in seeds) { yield return(RNG.XDRNG.Reverse(s, 3)); } } }
/// <summary> /// Adds the PKM to the inventory, while applying according properties /// </summary> /// <param name="pk"></param> public void AddPokemonToInventory(PKM pk) { pk.TID = FormMain.main.C_SAV.SAV.TID; pk.SID = FormMain.main.C_SAV.SAV.SID; pk.OT_Name = FormMain.main.C_SAV.SAV.OT; pk.OT_Gender = FormMain.main.C_SAV.SAV.Gender; pk.MetDate = DateTime.Today; pk.SetRandomIVs(); pk.SetRandomPIDNature(); PIDGenerator.SetRandomWildPID(pk, 4, pk.Nature, pk.Ability, pk.Gender, PIDType.Pokewalker); FormMain.main.PKME_Tabs.PopulateFields(pk); inventoryPokemon.Add(pk); // Add the pokemon to the dgv ResourceManager rm = new ResourceManager(typeof(Properties.Resources)); string resourceName = "_" + pk.Species; Species name = (Species)pk.Species; grdPokemon.Rows.Add((Image)rm.GetObject(resourceName), name.ToString()); }
public static void VerifyResults(IReadOnlyList <uint[]> results, TeamLock[] team) { var pkm = new PK3(); for (int i = 0; i < results.Count; i++) { var result = results[i]; var seeds = getSeeds(result[result.Length - 1]); bool match = false; foreach (var seed in seeds) { PIDGenerator.SetValuesFromSeed(pkm, PIDType.CXD, seed); var info = MethodFinder.Analyze(pkm); info.OriginSeed.Should().Be(seed); info.Type.Should().Be(PIDType.CXD, "because the PID should have matched the CXD spread"); if (!LockFinder.IsAllShadowLockValid(info, team)) { continue; } match = true; break; } match.Should().BeTrue($"because the lock conditions for result {i} and species {team[0].Species} should have been verified"); }