示例#1
0
        public void MetDateSetterTest()
        {
            var pk = new PK7();

            // Ensure setting to null zeros the components
            // -- Set to something else first
            pk.Met_Day   = 12;
            pk.Met_Month = 12;
            pk.Met_Year  = 12;
            // -- Act
            pk.MetDate = null;
            // -- Assert
            Assert.AreEqual(0, pk.Met_Day, "Met_Day was not zeroed when MetDate is set to null");
            Assert.AreEqual(0, pk.Met_Month, "Met_Month was not zeroed when MetDate is set to null");
            Assert.AreEqual(0, pk.Met_Year, "Met_Year was not zeroed when MetDate is set to null");

            // Ensure setting to a date sets the components
            var now = DateTime.UtcNow;

            // -- Set to something else first
            pk.Met_Day   = 12;
            pk.Met_Month = 12;
            pk.Met_Year  = 12;
            if (now.Month == 12)
            {
                // We don't want the test to work just because it's 12/12 right now.
                pk.Met_Month = 11;
            }
            // -- Act
            pk.MetDate = now;
            // -- Assert
            Assert.AreEqual(now.Day, pk.Met_Day, "Met_Day was not correctly set");
            Assert.AreEqual(now.Month, pk.Met_Month, "Met_Month was not correctly set");
            Assert.AreEqual(now.Year - 2000, pk.Met_Year, "Met_Year was not correctly set");
        }
示例#2
0
        public static Image GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int num_copies = 1)
        {
            byte[] data = QR7.GenerateQRData(pk7, box, slot, num_copies);
            var    msg  = QRMessageUtil.GetMessage(data);

            return(GenerateQRCode(msg, ppm: 4));
        }
示例#3
0
        public void SimulatorGetEncounters()
        {
            var set = new ShowdownSet(SetGlaceonUSUMTutor);
            var pk7 = new PK7 {
                Species = set.Species, AltForm = set.FormIndex, Moves = set.Moves
            };
            var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.MN);

            Assert.IsTrue(!encs.Any());
            pk7.HT_Name = "PKHeX";
            encs        = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.MN);
            var first = encs.FirstOrDefault();

            Assert.IsTrue(first != null);

            var egg  = (EncounterEgg)first;
            var info = new SimpleTrainerInfo();
            var pk   = egg.ConvertToPKM(info);

            Assert.IsTrue(pk.Species != set.Species);

            var la = new LegalityAnalysis(pk);

            Assert.IsTrue(la.Valid);

            var test = EncounterMovesetGenerator.GeneratePKMs(pk7, info).ToList();

            foreach (var t in test)
            {
                var la2 = new LegalityAnalysis(t);
                Assert.IsTrue(la2.Valid);
            }
        }
示例#4
0
        public static PKM GetPKMFromPayload(byte[] inputBuffer)
        {
            byte[] pkmData = new byte[PKSIZE];
            Array.Copy(inputBuffer, HEADER.Length + GAME_LEN, pkmData, 0, 232);
            PKM pk;

            byte version = inputBuffer[HEADER.Length];

            switch (version)
            {
            case GEN6:
                pk = new PK6(pkmData);
                break;

            case GEN7:
                pk = new PK7(pkmData);
                break;

            default:
                pk = new PK7();
                break;
            }

            return(pk);
        }
示例#5
0
        private static byte[] GenerateQRData(PK7 pk7, int box = 0, int slot = 0, int num_copies = 1)
        {
            if (box > 31)
            {
                box = 31;
            }
            if (slot > 29)
            {
                slot = 29;
            }
            if (box < 0)
            {
                box = 0;
            }
            if (slot < 0)
            {
                slot = 0;
            }
            if (num_copies < 0)
            {
                num_copies = 1;
            }

            byte[] data = new byte[0x1A2];
            BitConverter.GetBytes(0x454B4F50).CopyTo(data, 0); // POKE magic
            data[0x4] = 0xFF;                                  // QR Type
            BitConverter.GetBytes(box).CopyTo(data, 0x8);
            BitConverter.GetBytes(slot).CopyTo(data, 0xC);
            BitConverter.GetBytes(num_copies).CopyTo(data, 0x10); // No need to check max num_copies, payload parser handles it on-console.

            pk7.EncryptedPartyData.CopyTo(data, 0x30);            // Copy in pokemon data
            GetRawQR(pk7.Species, pk7.AltForm, pk7.IsShiny, pk7.Gender).CopyTo(data, 0x140);
            BitConverter.GetBytes((ushort)SaveUtil.check16(data.Take(0x1A0).ToArray(), 0)).CopyTo(data, 0x1A0);
            return(data);
        }
示例#6
0
文件: PKM.cs 项目: Arch9SK7/PKHeX
        public PKM convertPK1toPK7()
        {
            if (Format != 1)
            {
                return(null);
            }
            if (Species > 151)
            {
                return(null);
            }

            var pk = new PK7();

            TransferPropertiesWithReflection(this, pk);
            pk.EVs    = new int[6];
            pk.Nature = IVs.Sum() % 25;
            pk.IVs    = new[] { 31, 31, 31, 31, 31, 31 };
            pk.RefreshChecksum();
            if (!IsNicknamed)
            {
                pk.Nickname = Nickname.ToLower();
            }
            pk.Version = -1;
            pk.Ability = PersonalTable.SM[Species].Abilities[0];
            do
            {
                PID = PKX.getRandomPID(Species, Gender, Version, Nature, AltForm, PID);
            } while (!IsShiny);
            return(pk);
        }
示例#7
0
        public void StringEncodingTest()
        {
            const string name_fabian = "Fabian♂";
            var          pkm         = new PK7 {
                OT_Name = name_fabian
            };
            var byte_fabian = new byte[]
            {
                0x46, 0x00, // F
                0x61, 0x00, // a
                0x62, 0x00, // b
                0x69, 0x00, // i
                0x61, 0x00, // a
                0x6E, 0x00, // n
                0x8E, 0xE0, // ♂
                0x00, 0x00, // \0 terminator
            };

            CheckStringGetSet(nameof(pkm.OT_Name), name_fabian, pkm.OT_Name, byte_fabian, pkm.OT_Trash);

            const string name_nidoran = "ニドラン♀";

            pkm.Nickname = name_nidoran;
            var byte_nidoran = new byte[]
            {
                0xCB, 0x30, // ニ
                0xC9, 0x30, // ド
                0xE9, 0x30, // ラ
                0xF3, 0x30, // ン
                0x40, 0x26, // ♀
                0x00, 0x00, // \0 terminator
            };

            CheckStringGetSet(nameof(pkm.Nickname), name_nidoran, pkm.Nickname, byte_nidoran, pkm.Nickname_Trash);
        }
示例#8
0
        public void EggMetDateSetterTest()
        {
            var pk = new PK7();

            // Ensure setting to null zeros the components
            // -- Set to a default value(dummy data) first
            pk.Egg_Day   = 12;
            pk.Egg_Month = 12;
            pk.Egg_Year  = 12;
            // -- Act
            pk.EggMetDate = null;
            // -- Assert
            Assert.AreEqual(0, pk.Egg_Day, "Egg_Day was not zero-ed when EggMetDate is set to null");
            Assert.AreEqual(0, pk.Egg_Month, "Egg_Month was not zero-ed when EggMetDate is set to null");
            Assert.AreEqual(0, pk.Egg_Year, "Egg_Year was not zero-ed when EggMetDate is set to null");

            // Ensure setting to a date sets the components
            var now = DateTime.UtcNow;

            // -- Set to a default value(dummy data) first
            pk.Egg_Day   = 12;
            pk.Egg_Month = 12;
            pk.Egg_Year  = 12;
            if (now.Month == 12)
            {
                // We do not want the test to work just because it's 12/12 right now.
                pk.Egg_Month = 11;
            }
            // -- Act
            pk.EggMetDate = now;
            // -- Assert
            Assert.AreEqual(now.Day, pk.Egg_Day, "Egg_Day was not correctly set");
            Assert.AreEqual(now.Month, pk.Egg_Month, "Egg_Month was not correctly set");
            Assert.AreEqual(now.Year - 2000, pk.Egg_Year, "Egg_Year was not correctly set");
        }
示例#9
0
        protected override void setPKM(PKM pkm)
        {
            PK7 pk7 = pkm as PK7;
            // Apply to this Save File
            int      CT   = pk7.CurrentHandler;
            DateTime Date = DateTime.Now;

            pk7.Trade(OT, TID, SID, Country, SubRegion, Gender, false, Date.Day, Date.Month, Date.Year);
            if (CT != pk7.CurrentHandler) // Logic updated Friendship
            {
                // Copy over the Friendship Value only under certain circumstances
                if (pk7.Moves.Contains(216)) // Return
                {
                    pk7.CurrentFriendship = pk7.OppositeFriendship;
                }
                else if (pk7.Moves.Contains(218)) // Frustration
                {
                    pkm.CurrentFriendship = pk7.OppositeFriendship;
                }
                else if (pk7.CurrentHandler == 1) // OT->HT, needs new Friendship/Affection
                {
                    pk7.TradeFriendshipAffection(OT);
                }
            }
            pkm.RefreshChecksum();
        }
示例#10
0
        public void HasOriginalMetLocation7(GameVersion g)
        {
            var pk5 = new PK7 {
                Version = (int)g
            };

            pk5.HasOriginalMetLocation.Should().BeTrue();
        }
示例#11
0
文件: QR.cs 项目: Rocci1212/PKHeX
 // QR7 Utility
 public static Image GenerateQRCode7(PK7 pk7, int box = 0, int slot = 0, int num_copies = 1)
 {
     byte[] data = QR7.GenerateQRData(pk7, box, slot, num_copies);
     using (var generator = new QRCodeGenerator())
         using (var qr_data = generator.CreateQRCode(data))
             using (var qr_code = new QRCode(qr_data))
                 return(qr_code.GetGraphic(4));
 }
示例#12
0
        /// <summary>
        /// Creates an instance of <see cref="PKM"/> from the given data.
        /// </summary>
        /// <param name="data">Raw data of the Pokemon file.</param>
        /// <param name="ident">Optional identifier for the Pokemon.  Usually the full path of the source file.</param>
        /// <returns>An instance of <see cref="PKM"/> created from the given <paramref name="data"/>, or null if <paramref name="data"/> is invalid.</returns>
        public static PKM getPKMfromBytes(byte[] data, string ident = null)
        {
            checkEncrypted(ref data);
            switch (getPKMDataFormat(data))
            {
            case 1:
                var PL1 = new PokemonList1(data, PokemonList1.CapacityType.Single, data.Length == PKX.SIZE_1JLIST);
                if (ident != null)
                {
                    PL1[0].Identifier = ident;
                }
                return(PL1[0]);

            case 2:
                var PL2 = new PokemonList2(data, PokemonList2.CapacityType.Single, data.Length == PKX.SIZE_2JLIST);
                if (ident != null)
                {
                    PL2[0].Identifier = ident;
                }
                return(PL2[0]);

            case 3:
                switch (data.Length)
                {
                case PKX.SIZE_3CSTORED: return(new CK3(data, ident));

                case PKX.SIZE_3XSTORED: return(new XK3(data, ident));

                default: return(new PK3(data, ident));
                }

            case 4:
                var pk = new PK4(data, ident);
                if (!pk.Valid || pk.Sanity != 0)
                {
                    var bk = new BK4(data, ident);
                    if (bk.Valid)
                    {
                        return(bk);
                    }
                }
                return(pk);

            case 5:
                return(new PK5(data, ident));

            case 6:
                PKM pkx = new PK6(data, ident);
                if (pkx.SM)
                {
                    pkx = new PK7(data, ident);
                }
                return(pkx);

            default:
                return(null);
            }
        }
示例#13
0
文件: QR.cs 项目: vvcln/PKHeX
        private void ReloadQRData(PK7 pk7)
        {
            var box    = (int)NUD_Box.Value - 1;
            var slot   = (int)NUD_Slot.Value - 1;
            var copies = (int)NUD_Copies.Value;

            extraText = $" (Box {box + 1}, Slot {slot + 1}, {copies} cop{(copies > 1 ? "ies" : "y")})";
            qr        = QREncode.GenerateQRCode7(pk7, box, slot, copies);
        }
示例#14
0
    public void EggMetDateNullWhenDateComponentsAreAllZero()
    {
        var pk = new PK7
        {
            Egg_Day   = 0,
            Egg_Month = 0,
            Egg_Year  = 0,
        };

        pk.EggMetDate.HasValue.Should().BeFalse();
    }
示例#15
0
    public void EggMetDateCalculatesYear0Correctly()
    {
        var pk = new PK7
        {
            Egg_Day   = 1,
            Egg_Month = 1,
            Egg_Year  = 0,
        };

        pk.EggMetDate.GetValueOrDefault().Date.Year.Should().Be(2000);
    }
示例#16
0
            public void MetDateNullWhenDateComponentsAreAllZero()
            {
                var pk = new PK7
                {
                    Met_Day   = 0,
                    Met_Month = 0,
                    Met_Year  = 0
                };

                pk.MetDate.HasValue.Should().BeFalse();
            }
示例#17
0
            public void MetDateCalculatesYear0Correctly()
            {
                var pk = new PK7
                {
                    Met_Day   = 1,
                    Met_Month = 1,
                    Met_Year  = 0
                };

                pk.MetDate.GetValueOrDefault().Date.Year.Should().Be(2000);
            }
示例#18
0
    public void EggMetDateReturnsCorrectDate()
    {
        var pk = new PK7
        {
            Egg_Day   = 10,
            Egg_Month = 8,
            Egg_Year  = 16,
        };

        pk.EggMetDate.GetValueOrDefault().Should().Be(new DateTime(2016, 8, 10).Date);
    }
示例#19
0
            public void MetDateReturnsCorrectDate()
            {
                var pk = new PK7
                {
                    Met_Day   = 10,
                    Met_Month = 8,
                    Met_Year  = 16
                };

                pk.MetDate.GetValueOrDefault().Should().Be(new DateTime(2016, 8, 10).Date);
            }
示例#20
0
    public PKM[] GetTeam(int teamIndex)
    {
        var team = new PKM[6];
        var ofs  = offsets[teamIndex];

        for (int p = 0; p < 6; p++)
        {
            int offset = ofs + (PokeCrypto.SIZE_6PARTY * p);
            team[p] = new PK7(Data.Slice(offset, PokeCrypto.SIZE_6STORED));
        }

        return(team);
    }
示例#21
0
        public void SimulatorParseEncounter(string text)
        {
            var set = new ShowdownSet(text);
            var pk7 = new PK7 {
                Species = set.Species, AltForm = set.FormIndex, Moves = set.Moves, CurrentLevel = set.Level
            };
            var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves);
            var tr3  = encs.First(z => z is EncounterTrade t && t.Generation == 3);
            var pk3  = tr3.ConvertToPKM(new SAV3());

            var la = new LegalityAnalysis(pk3);

            la.Valid.Should().BeTrue();
        }
示例#22
0
            public void SettingEggMetDateToNullZerosComponents()
            {
                var pk = new PK7
                {
                    Egg_Day   = 12,
                    Egg_Month = 12,
                    Egg_Year  = 12
                };

                pk.EggMetDate = null;

                pk.Egg_Day.Should().Be(0);
                pk.Egg_Month.Should().Be(0);
                pk.Egg_Year.Should().Be(0);
            }
示例#23
0
            public void SettingToNullZerosComponents()
            {
                var pk = new PK7
                {
                    Met_Day   = 12,
                    Met_Month = 12,
                    Met_Year  = 12
                };

                pk.MetDate = null;

                pk.Met_Day.Should().Be(0);
                pk.Met_Month.Should().Be(0);
                pk.Met_Year.Should().Be(0);
            }
示例#24
0
 //[TestMethod]
 //[TestCategory(SimulatorParse)]
 public void TestGenerate()
 {
     for (int i = 1; i <= 807; i++)
     {
         var tr = new SimpleTrainerInfo();
         var pk = new PK7 {
             Species = i
         };
         var ez = EncounterMovesetGenerator.GeneratePKMs(pk, tr);
         Debug.WriteLine($"Starting {i:000}");
         bool v = ez.Select(p => new LegalityAnalysis(p)).All(la => la.Valid);
         Debug.WriteLine($"Finished {i:000}");
         Debug.Assert(v);
     }
 }
示例#25
0
            public void SettingEggMetDateSetsComponents()
            {
                var pk = new PK7
                {
                    Egg_Day   = 12,
                    Egg_Month = 12,
                    Egg_Year  = 12
                };

                pk.EggMetDate = new DateTime(2005, 5, 5);

                pk.Egg_Day.Should().Be(5);
                pk.Egg_Month.Should().Be(5);
                pk.Egg_Year.Should().Be(5);
            }
示例#26
0
        public void EggMetDateGetterTest()
        {
            var pk = new PK7();

            // Ensure MetDate is null when components are all 0
            pk.Egg_Day   = 0;
            pk.Egg_Month = 0;
            pk.Egg_Year  = 0;
            Assert.IsFalse(pk.MetDate.HasValue, "EggMetDate should be null when date component are all 0.");

            // Ensure MetDate gives correct date
            pk.Egg_Day   = 10;
            pk.Egg_Month = 8;
            pk.Egg_Year  = 16;
            Assert.AreEqual(new DateTime(2016, 8, 10).Date, pk.EggMetDate.Value.Date, "Egg met date does not return correct date.");
        }
示例#27
0
        public void SimulatorGetVCEgg1()
        {
            var set = new ShowdownSet(SetSlowpoke12);
            var pk7 = new PK7 {
                Species = set.Species, AltForm = set.FormIndex, Moves = set.Moves, HT_Name = "PKHeX"
            };
            var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.GD).ToList();

            Assert.True(encs.Count > 0);

            var info = new SimpleTrainerInfo(GameVersion.SN);
            var enc  = encs[0];
            var pk   = enc.ConvertToPKM(info);

            var la = new LegalityAnalysis(pk);

            Assert.True(la.Valid);
        }
示例#28
0
            public void EncodesNicknameCorrectly()
            {
                const string name_nidoran = "ニドラン♀";
                var          pkm          = new PK7 {
                    Nickname = name_nidoran
                };
                var byte_nidoran = new byte[]
                {
                    0xCB, 0x30, // ニ
                    0xC9, 0x30, // ド
                    0xE9, 0x30, // ラ
                    0xF3, 0x30, // ン
                    0x40, 0x26, // ♀
                    0x00, 0x00, // \0 terminator
                };

                CheckStringGetSet(nameof(pkm.Nickname), name_nidoran, pkm.Nickname, byte_nidoran, pkm.Nickname_Trash);
            }
示例#29
0
        public void SimulatorGetSplitBreed()
        {
            var set = new ShowdownSet(SetMunchSnorLax);
            var pk7 = new PK7 {
                Species = set.Species, AltForm = set.FormIndex, Moves = set.Moves, HT_Name = "PKHeX"
            };                                                                                                          // !! specify the HT name, we need tutors for this one
            var encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.SN).ToList();

            Assert.True(encs.Count > 0);
            Assert.True(encs.All(z => z.Species > 150));

            var info = new SimpleTrainerInfo(GameVersion.SN);
            var enc  = encs[0];
            var pk   = enc.ConvertToPKM(info);

            var la = new LegalityAnalysis(pk);

            Assert.True(la.Valid);
        }
示例#30
0
    public void SettingMetDateSetsComponents()
    {
        var pk = new PK7
        {
            Met_Day   = 12,
            Met_Month = 12,
            Met_Year  = 12,
        };

        pk.Met_Day.Should().Be(12);
        pk.Met_Month.Should().Be(12);
        pk.Met_Year.Should().Be(12);

        pk.MetDate = new DateTime(2005, 5, 5);

        pk.Met_Day.Should().Be(5);
        pk.Met_Month.Should().Be(5);
        pk.Met_Year.Should().Be(5);
    }