internal static void SetBasicData(PKM pkm) { var newPID = pkm.PID; var ability = pkm.GenNumber < 5 ? (int)(newPID & 1) : (int)(newPID >> 16) & 1; pkm.SetGender(PKX.GetGenderFromPID(pkm.Species, newPID)); if (pkm.GenNumber < 5) { pkm.SetNature((int)(newPID % 25)); } switch (pkm.GenNumber) { case 3: var pk3 = new PK3 { PID = newPID, Species = pkm.Species }; var pi3 = (PersonalInfoG3)pk3.PersonalInfo; if (!pi3.HasSecondAbility) { pkm.SetAbility(pi3.Ability1); } else { pkm.SetAbility(pi3.Abilities[ability]); } break; default: pkm.RefreshAbility(ability); break; } pkm.PID = newPID; }
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 Channel spread"); Assert.IsTrue(pk3.IVs.SequenceEqual(gk3.IVs), "Unable to match generated IVs to Channel 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 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"); }
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[^ 1]);
public override PKM Clone() { // Don't use the byte[] constructor, the DecryptIfEncrypted call is based on checksum. // An invalid checksum will shuffle the data; we already know it's un-shuffled. Set up manually. var pk = new PK3(); Data.CopyTo(pk.Data, 0); return(pk); }
public static void CheckGen3PID() { var pk3 = new PK3(File.ReadAllBytes(PKMFolder + @"\003 - VENUSAUR - 156F1CC41245.pk3")); Assert.NotNull(pk3); PIDEdits.Gen345UnShiny(pk3); Assert.True(new LegalityAnalysis(pk3).Valid, "Set Gen3 Pokemon UnShiny Successfully"); }
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"); }
/// <summary> /// Reads an archive from the path provided. /// </summary> /// <param name="path">The path to read from.</param> /// <returns>The archive, if it can be read.</returns> public static Optional <IArchive> ReadFile(string path) { if (path.EndsWith(".wad", StringComparison.OrdinalIgnoreCase)) { return(Wad.FromArchive(path)); } // Note that by not searching for PK3 only, we indirectly support // reading anything that is a zip archive. return(PK3.FromArchive(path)); }
private static void Verify(TeamLock[] teams, uint pid, int[] ivs, bool xd = true) { var pk3 = new PK3 { PID = pid, IVs = ivs }; var info = MethodFinder.Analyze(pk3); Assert.AreEqual(PIDType.CXD, info.Type, "Unable to match PID to CXD spread!"); bool match = GetCanOriginateFrom(teams, info, xd, out var _); Assert.IsTrue(match, "Unable to verify lock conditions: " + teams[0].Species); }
private static void VerifySingle(TeamLock[] teams, uint pid, int[] ivs, bool xd = true) { var pk3 = new PK3 { PID = pid, IVs = ivs }; var info = MethodFinder.Analyze(pk3); Assert.AreEqual(PIDType.CXD, info.Type, "Unable to match PID to CXD spread!"); bool match = LockFinder.IsFirstShadowLockValid(info, teams, xd); Assert.IsTrue(match, "Unable to verify lock conditions: " + teams[0].Species); }
public static void Verify(TeamLock[] teams, uint pid, int[] ivs) { var pk3 = new PK3 { PID = pid, IVs = ivs }; var info = MethodFinder.Analyze(pk3); info.Type.Should().Be(PIDType.CXD, "because the PID should match the CXD spread"); bool match = LockFinder.IsAllShadowLockValid(info, teams); match.Should().BeTrue($"because the lock conditions for {teams[0].Species} should have been verified"); }
public void PIDIVMatchingTest3() { // Method 1/2/4 var pk1 = new PK3 { PID = 0xE97E0000, IVs = new[] { 17, 19, 20, 16, 13, 12 } }; Assert.AreEqual(PIDType.Method_1, MethodFinder.Analyze(pk1)?.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"); // Method 1/2/4, reversed for Unown. var pk1U = new PK3 { PID = 0x815549A2, IVs = new[] { 02, 26, 30, 30, 11, 26 }, Species = 201 }; // Unown-C Assert.AreEqual(PIDType.Method_1_Unown, MethodFinder.Analyze(pk1U)?.Type, "Unable to match PID to Method 1 Unown spread"); var pk2U = new PK3 { PID = 0x8A7B5190, IVs = new[] { 14, 02, 21, 30, 29, 15 }, Species = 201 }; // Unown-M Assert.AreEqual(PIDType.Method_2_Unown, MethodFinder.Analyze(pk2U)?.Type, "Unable to match PID to Method 2 Unown spread"); var pk4U = new PK3 { PID = 0x5FA80D70, IVs = new[] { 02, 06, 03, 26, 04, 19 }, Species = 201 }; // Unown-A Assert.AreEqual(PIDType.Method_4_Unown, MethodFinder.Analyze(pk4U)?.Type, "Unable to match PID to Method 4 Unown spread"); // Colosseum / XD var pk3 = new PK3 { PID = 0x0985A297, IVs = new[] { 06, 01, 00, 07, 17, 07 } }; Assert.AreEqual(PIDType.CXD, MethodFinder.Analyze(pk3)?.Type, "Unable to match PID to CXD spread"); // Channel Jirachi var pkC = new PK3 { PID = 0x9E27D2F6, IVs = new[] { 04, 15, 21, 14, 18, 29 } }; Assert.AreEqual(PIDType.Channel, MethodFinder.Analyze(pkC)?.Type, "Unable to match PID to Channel spread"); }
public void PIDIVMatchingTest3Method3() { // Method 3, reversed for Unown. var m3R = new PK3 { PID = 0x3DD1BB49, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 001 }; // Regular var m3t = MethodFinder.Analyze(m3R)?.Type; Assert.Equal(PIDType.Method_3, m3t); var m3u = new PK3 { PID = 0xBB493DD1, IVs = new[] { 23, 12, 31, 09, 03, 03 }, Species = 201 }; // Unown var u3t = MethodFinder.Analyze(m3u)?.Type; Assert.Equal(PIDType.Method_3_Unown, u3t); }
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"); }
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 PIDIVPokeSpotTest() { // XD PokeSpots: Check all 3 Encounter Slots (examples are one for each location). var pkPS0 = new PK3 { PID = 0x7B2D9DA7 }; // Zubat (Cave) Assert.IsTrue(MethodFinder.GetPokeSpotSeeds(pkPS0, 0).Any(), "PokeSpot encounter info mismatch (Common)"); var pkPS1 = new PK3 { PID = 0x3EE9AF66 }; // Gligar (Rock) Assert.IsTrue(MethodFinder.GetPokeSpotSeeds(pkPS1, 1).Any(), "PokeSpot encounter info mismatch (Uncommon)"); var pkPS2 = new PK3 { PID = 0x9B667F3C }; // Surskit (Oasis) Assert.IsTrue(MethodFinder.GetPokeSpotSeeds(pkPS2, 2).Any(), "PokeSpot encounter info mismatch (Rare)"); }
public void PIDIVMatchingTest3Unown() { // Method 1/2/4, reversed for Unown. var pk1U = new PK3 { PID = 0x815549A2, IVs = new[] { 02, 26, 30, 30, 11, 26 }, Species = 201 }; // Unown-C Assert.AreEqual(PIDType.Method_1_Unown, MethodFinder.Analyze(pk1U)?.Type, "Unable to match PID to Method 1 Unown spread"); var pk2U = new PK3 { PID = 0x8A7B5190, IVs = new[] { 14, 02, 21, 30, 29, 15 }, Species = 201 }; // Unown-M Assert.AreEqual(PIDType.Method_2_Unown, MethodFinder.Analyze(pk2U)?.Type, "Unable to match PID to Method 2 Unown spread"); var pk4U = new PK3 { PID = 0x5FA80D70, IVs = new[] { 02, 06, 03, 26, 04, 19 }, Species = 201 }; // Unown-A Assert.AreEqual(PIDType.Method_4_Unown, MethodFinder.Analyze(pk4U)?.Type, "Unable to match PID to Method 4 Unown spread"); }
public void PIDIVMethod4IVs() { var pk4 = new PK3 { PID = 0xFEE73213, IVs = new[] { 03, 29, 23, 30, 28, 24 } }; Assert.AreEqual(PIDType.Method_4, MethodFinder.Analyze(pk4)?.Type, "Unable to match PID to Method 4 spread"); // See if any origin seed for the IVs matches what we expect // Load the IVs uint rand1 = 0; // HP/ATK/DEF uint rand3 = 0; // SPE/SPA/SPD var IVs = pk4.IVs; for (int i = 0; i < 3; i++) { rand1 |= (uint)IVs[i] << (5 * i); rand3 |= (uint)IVs[i + 3] << (5 * i); } Assert.IsTrue(MethodFinder.GetSeedsFromIVsSkip(RNG.LCRNG, rand1, rand3).Any(z => z == 0xFEE7047C)); }
public void PIDIVEncounterSlotTest() { // Modest Method 1 var pk = new PK3 { PID = 0x6937DA48, IVs = new[] { 31, 31, 31, 31, 31, 31 } }; var pidiv = MethodFinder.Analyze(pk); Assert.AreEqual(PIDType.Method_1, pidiv?.Type, "Unable to match PID to Method 1 spread"); // Test for Method J { // Pearl pk.Version = (int)GameVersion.P; var results = FrameFinder.GetFrames(pidiv, pk); const int failSyncCount = 1; const int noSyncCount = 2; const int SyncCount = 37; var r2 = results.ToArray(); var failSync = r2.Where(z => z.Lead == LeadRequired.SynchronizeFail); var noSync = r2.Where(z => z.Lead == LeadRequired.None); var sync = r2.Where(z => z.Lead == LeadRequired.Synchronize); Assert.AreEqual(failSync.Count(), failSyncCount, "Failed Sync count mismatch."); Assert.AreEqual(sync.Count(), SyncCount, "Sync count mismatch."); Assert.AreEqual(noSync.Count(), noSyncCount, "Non-Sync count mismatch."); var type = SlotType.Grass; var slots = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 9 }; Assert.IsTrue(slots.All(s => r2.Any(z => z.GetSlot(type) == s)), "Required slots not present."); var slotsForType = r2.Where(z => !z.LevelSlotModified).Select(z => z.GetSlot(type)).Distinct().OrderBy(z => z); Assert.IsTrue(slotsForType.SequenceEqual(slots), "Unexpected slots present."); } // Test for Method H and K { // Sapphire // pk.Version = (int)GameVersion.S; // var results = FrameFinder.GetFrames(pidiv, pk); } }
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"); }
public void PIDIVMethod4IVs() { var pk4 = new PK3 { PID = 0xFEE73213, IVs = new[] { 03, 29, 23, 30, 28, 24 } }; var analysis = MethodFinder.Analyze(pk4); analysis.Type.Should().Be(PIDType.Method_4); // See if any origin seed for the IVs matches what we expect // Load the IVs uint rand1 = 0; // HP/ATK/DEF uint rand3 = 0; // SPE/SPA/SPD var IVs = pk4.IVs; for (int i = 0; i < 3; i++) { rand1 |= (uint)IVs[i] << (5 * i); rand3 |= (uint)IVs[i + 3] << (5 * i); } Assert.Contains(MethodFinder.GetSeedsFromIVsSkip(RNG.LCRNG, rand1, rand3), z => z == 0xFEE7047C); }
public void SimulatorGetWC3() { var set = new ShowdownSet(SetROCKSMetang); var pk3 = new PK3 { Species = set.Species, AltForm = set.FormIndex, Moves = set.Moves }; var encs = EncounterMovesetGenerator.GenerateEncounters(pk3, set.Moves, GameVersion.R); Assert.IsTrue(encs.Any()); encs = EncounterMovesetGenerator.GenerateEncounters(pk3, set.Moves, GameVersion.R); var first = encs.FirstOrDefault(); Assert.IsTrue(first != null); var wc3 = (WC3)first; var info = new SimpleTrainerInfo(); var pk = wc3.ConvertToPKM(info); var la = new LegalityAnalysis(pk); Assert.IsTrue(la.Valid); }
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)); } } }
public void PIDIVEncounterSlotTest() { // Modest Method 1 var pk = new PK3 { PID = 0x6937DA48, IVs = new[] { 31, 31, 31, 31, 31, 31 } }; var pidiv = MethodFinder.Analyze(pk); Assert.Equal(PIDType.Method_1, pidiv?.Type); // Test for Method J { // Pearl pk.Version = (int)GameVersion.P; var results = FrameFinder.GetFrames(pidiv, pk).ToArray(); var failSync = results.Where(z => z.Lead == LeadRequired.SynchronizeFail); var noSync = results.Where(z => z.Lead == LeadRequired.None); var sync = results.Where(z => z.Lead == LeadRequired.Synchronize); failSync.Should().HaveCount(1); sync.Should().HaveCount(37); noSync.Should().HaveCount(2); const SlotType type = SlotType.Grass; var slots = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 9 }; Assert.True(slots.All(s => results.Any(z => z.GetSlot(type) == s)), "Required slots not present."); var slotsForType = results.Where(z => !z.LevelSlotModified).Select(z => z.GetSlot(type)).Distinct().OrderBy(z => z); Assert.True(slotsForType.SequenceEqual(slots), "Unexpected slots present."); } // Test for Method H and K { // Sapphire // pk.Version = (int)GameVersion.S; // var results = FrameFinder.GetFrames(pidiv, pk); } }
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"); }
public void AddToBoxesButtonClick(Object sender, EventArgs events) { var sav = SaveFileEditor.SAV; // current save int generation = sav.Generation; // the generation of the current save -- used to determine the PK save format List <PKM> pokemonList = new List <PKM>(); // list of all Pokemon that will be added to the sav string showdownData = this.input.Text; // user's input var pokemonArray = JsonConvert.DeserializeObject <List <RawPokemon> >(showdownData); //jsonify the data foreach (RawPokemon rawPokemon in pokemonArray) { PKM pokemon = new PK2(); //Determine save format switch (generation) { case 1: pokemon = new PK1(); break; case 2: pokemon = new PK2(); break; case 3: pokemon = new PK3(); break; case 4: pokemon = new PK4(); break; case 5: pokemon = new PK5(); break; case 6: pokemon = new PK6(); break; case 7: pokemon = new PK7(); break; case 8: pokemon = new PK8(); break; } // Set the species according to the Species enum int speciesAsNumber = 0; //Check if the Pokemon is Alolan or not; if it is, do some extra logic to set the proper form if (rawPokemon.Species.Contains("Alolan")) { string[] pokemon_name = rawPokemon.Species.Split('_'); speciesAsNumber = (int)(Species)Enum.Parse(typeof(Species), pokemon_name[1]); pokemon.SetForm(810); pokemon.Species = speciesAsNumber; } else { speciesAsNumber = (int)(Species)Enum.Parse(typeof(Species), rawPokemon.Species); pokemon.Species = speciesAsNumber; } // Check to see if the Pokemon has forms (i.e. Flabebe, Shellos, etc.), and if it does, randomly generate one if (rawPokemon.Species.Contains("Burmy")) { int form = random.Next(0, burmyForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Shellos")) { int form = random.Next(0, shellosForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Scatterbug")) { int form = random.Next(0, scatterbugForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Flabébé")) { int form = random.Next(0, flabebeForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Oricorio")) { int form = random.Next(0, oricorioForms.Length - 1); pokemon.SetForm(form); } else if (rawPokemon.Species.Contains("Minior")) { int form = random.Next(0, miniorForms.Length - 1); pokemon.SetForm(form); } GameVersion game = (GameVersion)sav.Game; EncounterEgg encounterEgg = new EncounterEgg(speciesAsNumber, pokemon.Form, 1, sav.Generation, game); PKM pokemonAsEgg = encounterEgg.ConvertToPKM(sav); pokemonAsEgg.IsEgg = true; pokemon.IsNicknamed = true; pokemon.Nickname = "Egg"; // Set the ability string ability = rawPokemon.Ability.Replace(" ", ""); int abilityAsNumber = (int)(Ability)Enum.Parse(typeof(Ability), ability); pokemonAsEgg.SetAbility(abilityAsNumber); //Set gender switch (rawPokemon.Gender) { case "M": pokemonAsEgg.SetGender(0); break; case "F": pokemonAsEgg.SetGender(1); break; case "N": pokemonAsEgg.SetGender(2); break; } // Set Nature via the Nature enum int natureAsNumber = (int)(Nature)Enum.Parse(typeof(Nature), rawPokemon.Nature); pokemonAsEgg.Nature = natureAsNumber; // Set the IVs pokemonAsEgg.IV_HP = rawPokemon.HP; pokemonAsEgg.IV_ATK = rawPokemon.Atk; pokemonAsEgg.IV_DEF = rawPokemon.Def; pokemonAsEgg.IV_SPA = rawPokemon.SpA; pokemonAsEgg.IV_SPD = rawPokemon.SpD; pokemonAsEgg.IV_SPE = rawPokemon.Spe; // Set moves and make sure they have the proper PP string move = ""; if (string.IsNullOrEmpty(rawPokemon.MoveOne) == false) { move = rawPokemon.MoveOne.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move1 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove1 = pokemonAsEgg.Move1; } if (string.IsNullOrEmpty(rawPokemon.MoveTwo) == false) { move = rawPokemon.MoveTwo.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move2 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove2 = pokemonAsEgg.Move2; } if (string.IsNullOrEmpty(rawPokemon.MoveThree) == false) { move = rawPokemon.MoveThree.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move3 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove3 = pokemonAsEgg.Move3; } if (string.IsNullOrEmpty(rawPokemon.MoveFour) == false) { move = rawPokemon.MoveFour.Replace("-", ""); move = move.Replace(" ", ""); pokemonAsEgg.Move4 = (int)(Move)Enum.Parse(typeof(Move), move); pokemonAsEgg.RelearnMove4 = pokemonAsEgg.Move4; } pokemonAsEgg.SetMaximumPPCurrent(); //Finally, if the Pokemon is supposed to be shiny, make it so if (rawPokemon.IsShiny == "true") { CommonEdits.SetShiny(pokemonAsEgg); } else { CommonEdits.SetUnshiny(pokemonAsEgg); } pokemonAsEgg.Met_Location = 0; if (generation == 7 || generation == 6 || generation == 5) { pokemonAsEgg.Egg_Location = Locations.Daycare5; } else { pokemonAsEgg.Egg_Location = Locations.Daycare4; } pokemonAsEgg.IsNicknamed = true; pokemonAsEgg.Nickname = SpeciesName.GetSpeciesNameGeneration(0, sav.Language, generation); //Hatch counter is for some reason called "CurrentFriendship". Don't ask me why, I don't know. pokemonAsEgg.CurrentFriendship = 1; pokemonList.Add(pokemonAsEgg); } // Import Pokemon, reload the boxes so they can be seen, show a message and close the window sav.ImportPKMs(pokemonList); SaveFileEditor.ReloadSlots(); MessageBox.Show("Done!"); this.input.Clear(); this.form.Close(); }
private PKM preparePK3() { PK3 pk3 = pkm as PK3; if (pk3 == null) { return(null); } pk3.Species = WinFormsUtil.getIndex(CB_Species); pk3.HeldItem = WinFormsUtil.getIndex(CB_HeldItem); pk3.TID = Util.ToInt32(TB_TID.Text); pk3.SID = Util.ToInt32(TB_SID.Text); pk3.EXP = Util.ToUInt32(TB_EXP.Text); pk3.PID = Util.getHEXval(TB_PID.Text); pk3.AbilityNumber = 1 << CB_Ability.SelectedIndex; // to match gen6+ pk3.FatefulEncounter = CHK_Fateful.Checked; pk3.Gender = PKX.getGender(Label_Gender.Text); pk3.EV_HP = Util.ToInt32(TB_HPEV.Text); pk3.EV_ATK = Util.ToInt32(TB_ATKEV.Text); pk3.EV_DEF = Util.ToInt32(TB_DEFEV.Text); pk3.EV_SPE = Util.ToInt32(TB_SPEEV.Text); pk3.EV_SPA = Util.ToInt32(TB_SPAEV.Text); pk3.EV_SPD = Util.ToInt32(TB_SPDEV.Text); pk3.CNT_Cool = Util.ToInt32(TB_Cool.Text); pk3.CNT_Beauty = Util.ToInt32(TB_Beauty.Text); pk3.CNT_Cute = Util.ToInt32(TB_Cute.Text); pk3.CNT_Smart = Util.ToInt32(TB_Smart.Text); pk3.CNT_Tough = Util.ToInt32(TB_Tough.Text); pk3.CNT_Sheen = Util.ToInt32(TB_Sheen.Text); pk3.PKRS_Days = CB_PKRSDays.SelectedIndex; pk3.PKRS_Strain = CB_PKRSStrain.SelectedIndex; pk3.Nickname = TB_Nickname.Text; pk3.Move1 = WinFormsUtil.getIndex(CB_Move1); pk3.Move2 = WinFormsUtil.getIndex(CB_Move2); pk3.Move3 = WinFormsUtil.getIndex(CB_Move3); pk3.Move4 = WinFormsUtil.getIndex(CB_Move4); pk3.Move1_PP = WinFormsUtil.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0; pk3.Move2_PP = WinFormsUtil.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0; pk3.Move3_PP = WinFormsUtil.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0; pk3.Move4_PP = WinFormsUtil.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0; pk3.Move1_PPUps = WinFormsUtil.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0; pk3.Move2_PPUps = WinFormsUtil.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0; pk3.Move3_PPUps = WinFormsUtil.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0; pk3.Move4_PPUps = WinFormsUtil.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0; pk3.IV_HP = Util.ToInt32(TB_HPIV.Text); pk3.IV_ATK = Util.ToInt32(TB_ATKIV.Text); pk3.IV_DEF = Util.ToInt32(TB_DEFIV.Text); pk3.IV_SPE = Util.ToInt32(TB_SPEIV.Text); pk3.IV_SPA = Util.ToInt32(TB_SPAIV.Text); pk3.IV_SPD = Util.ToInt32(TB_SPDIV.Text); pk3.IsEgg = CHK_IsEgg.Checked; pk3.IsNicknamed = CHK_Nicknamed.Checked; pk3.OT_Name = TB_OT.Text; pk3.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); pk3.Ball = WinFormsUtil.getIndex(CB_Ball); pk3.Met_Level = Util.ToInt32(TB_MetLevel.Text); pk3.OT_Gender = PKX.getGender(Label_OTGender.Text); pk3.Version = WinFormsUtil.getIndex(CB_GameOrigin); pk3.Language = WinFormsUtil.getIndex(CB_Language); pk3.Met_Location = WinFormsUtil.getIndex(CB_MetLocation); // Toss in Party Stats Array.Resize(ref pk3.Data, pk3.SIZE_PARTY); pk3.Stat_Level = Util.ToInt32(TB_Level.Text); pk3.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text); pk3.Stat_HPMax = Util.ToInt32(Stat_HP.Text); pk3.Stat_ATK = Util.ToInt32(Stat_ATK.Text); pk3.Stat_DEF = Util.ToInt32(Stat_DEF.Text); pk3.Stat_SPE = Util.ToInt32(Stat_SPE.Text); pk3.Stat_SPA = Util.ToInt32(Stat_SPA.Text); pk3.Stat_SPD = Util.ToInt32(Stat_SPD.Text); if (HaX) { pk3.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue); } // Fix Moves if a slot is empty pk3.FixMoves(); pk3.RefreshChecksum(); return(pk3); }
public PKM convertToPK3() { if (Format != 3) return null; if (GetType() == typeof(PK3)) return this; var pk = new PK3(); TransferPropertiesWithReflection(this, pk); pk.RefreshChecksum(); return pk; }
private void populateFieldsPK3() { PK3 pk3 = pkm as PK3; if (pk3 == null) { return; } // Do first pk3.Stat_Level = PKX.getLevel(pk3.Species, pk3.EXP); if (pk3.Stat_Level == 100 && !HaX) { pk3.EXP = PKX.getEXP(pk3.Stat_Level, pk3.Species); } CB_Species.SelectedValue = pk3.Species; TB_Level.Text = pk3.Stat_Level.ToString(); TB_EXP.Text = pk3.EXP.ToString(); // Load rest CHK_Fateful.Checked = pk3.FatefulEncounter; CHK_IsEgg.Checked = pk3.IsEgg; CHK_Nicknamed.Checked = pk3.IsNicknamed; Label_OTGender.Text = gendersymbols[pk3.OT_Gender]; Label_OTGender.ForeColor = getGenderColor(pk3.OT_Gender); TB_PID.Text = pk3.PID.ToString("X8"); CB_HeldItem.SelectedValue = pk3.HeldItem; CB_Ability.SelectedIndex = pk3.AbilityBit && CB_Ability.Items.Count > 1 ? 1 : 0; CB_Nature.SelectedValue = pk3.Nature; TB_TID.Text = pk3.TID.ToString("00000"); TB_SID.Text = pk3.SID.ToString("00000"); TB_Nickname.Text = pk3.Nickname; TB_OT.Text = pk3.OT_Name; TB_Friendship.Text = pk3.CurrentFriendship.ToString(); GB_OT.BackgroundImage = null; CB_Language.SelectedValue = pk3.Language; CB_GameOrigin.SelectedValue = pk3.Version; CB_EncounterType.SelectedValue = pk3.Gen4 ? pk3.EncounterType : 0; CB_Ball.SelectedValue = pk3.Ball; CB_MetLocation.SelectedValue = pk3.Met_Location; TB_MetLevel.Text = pk3.Met_Level.ToString(); // Reset Label and ComboBox visibility, as well as non-data checked status. Label_PKRS.Visible = CB_PKRSStrain.Visible = CHK_Infected.Checked = pk3.PKRS_Strain != 0; Label_PKRSdays.Visible = CB_PKRSDays.Visible = pk3.PKRS_Days != 0; // Set SelectedIndexes for PKRS CB_PKRSStrain.SelectedIndex = pk3.PKRS_Strain; CHK_Cured.Checked = pk3.PKRS_Strain > 0 && pk3.PKRS_Days == 0; CB_PKRSDays.SelectedIndex = Math.Min(CB_PKRSDays.Items.Count - 1, pk3.PKRS_Days); // to strip out bad hacked 'rus TB_Cool.Text = pk3.CNT_Cool.ToString(); TB_Beauty.Text = pk3.CNT_Beauty.ToString(); TB_Cute.Text = pk3.CNT_Cute.ToString(); TB_Smart.Text = pk3.CNT_Smart.ToString(); TB_Tough.Text = pk3.CNT_Tough.ToString(); TB_Sheen.Text = pk3.CNT_Sheen.ToString(); TB_HPIV.Text = pk3.IV_HP.ToString(); TB_ATKIV.Text = pk3.IV_ATK.ToString(); TB_DEFIV.Text = pk3.IV_DEF.ToString(); TB_SPEIV.Text = pk3.IV_SPE.ToString(); TB_SPAIV.Text = pk3.IV_SPA.ToString(); TB_SPDIV.Text = pk3.IV_SPD.ToString(); CB_HPType.SelectedValue = pk3.HPType; TB_HPEV.Text = pk3.EV_HP.ToString(); TB_ATKEV.Text = pk3.EV_ATK.ToString(); TB_DEFEV.Text = pk3.EV_DEF.ToString(); TB_SPEEV.Text = pk3.EV_SPE.ToString(); TB_SPAEV.Text = pk3.EV_SPA.ToString(); TB_SPDEV.Text = pk3.EV_SPD.ToString(); CB_Move1.SelectedValue = pk3.Move1; CB_Move2.SelectedValue = pk3.Move2; CB_Move3.SelectedValue = pk3.Move3; CB_Move4.SelectedValue = pk3.Move4; CB_PPu1.SelectedIndex = pk3.Move1_PPUps; CB_PPu2.SelectedIndex = pk3.Move2_PPUps; CB_PPu3.SelectedIndex = pk3.Move3_PPUps; CB_PPu4.SelectedIndex = pk3.Move4_PPUps; TB_PP1.Text = pk3.Move1_PP.ToString(); TB_PP2.Text = pk3.Move2_PP.ToString(); TB_PP3.Text = pk3.Move3_PP.ToString(); TB_PP4.Text = pk3.Move4_PP.ToString(); // Set Form if count is enough, else cap. CB_Form.SelectedIndex = CB_Form.Items.Count > pk3.AltForm ? pk3.AltForm : CB_Form.Items.Count - 1; // Load Extrabyte Value TB_ExtraByte.Text = pk3.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString(); updateStats(); TB_EXP.Text = pk3.EXP.ToString(); Label_Gender.Text = gendersymbols[pk3.Gender]; Label_Gender.ForeColor = getGenderColor(pk3.Gender); }