Пример #1
0
        public PK5 convertToPK5(SAV6 SAV)
        {
            if (!IsPokémon)
            {
                return(null);
            }

            DateTime dt = DateTime.Now;

            if (Day == 0)
            {
                Day   = (byte)dt.Day;
                Month = (byte)dt.Month;
                Year  = (byte)dt.Year;
            }
            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK5 pk           = new PK5
            {
                Species      = Species,
                HeldItem     = HeldItem,
                Met_Level    = currentLevel,
                Nature       = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender       = PKX.Personal[Species].Gender == 255 ? 2 : (Gender != 2 ? Gender : PKX.Personal[Species].RandomGender),
                AltForm      = Form,
                Version      = OriginGame == 0 ? new[] { 20, 21, 22, 23 }[Util.rnd32() & 0x3] : OriginGame,
                Language     = Language == 0 ? SAV.Language : Language,
                Ball         = Pokéball,
                Move1        = Move1,
                Move2        = Move2,
                Move3        = Move3,
                Move4        = Move4,
                Move1_PP     = PKX.getBasePP(Move1),
                Move2_PP     = PKX.getBasePP(Move2),
                Move3_PP     = PKX.getBasePP(Move3),
                Move4_PP     = PKX.getBasePP(Move4),
                Met_Location = MetLocation,
                Met_Day      = Day,
                Met_Month    = Month,
                Met_Year     = Year - 2000,
                Egg_Location = EggLocation,
                CNT_Cool     = CNT_Cool,
                CNT_Beauty   = CNT_Beauty,
                CNT_Cute     = CNT_Cute,
                CNT_Smart    = CNT_Smart,
                CNT_Tough    = CNT_Tough,
                CNT_Sheen    = CNT_Sheen,

                EXP = PKX.getEXP(Level, Species),

                // Ribbons
                RIB7_4 = RIB0_0, // Country Ribbon
                RIB7_5 = RIB0_1, // National Ribbon
                RIB7_6 = RIB0_2, // Earth Ribbon
                RIB7_7 = RIB0_3, // World Ribbon
                RIB3_2 = RIB0_4, // Classic Ribbon
                RIB3_3 = RIB0_5, // Premier Ribbon
                RIB2_3 = RIB0_6, // Event Ribbon
                RIB2_6 = RIB0_7, // Birthday Ribbon

                RIB2_7 = RIB1_0, // Special Ribbon
                RIB3_0 = RIB1_1, // Souvenir Ribbon
                RIB3_1 = RIB1_2, // Wishing Ribbon
                RIB7_1 = RIB1_3, // Battle Champ Ribbon
                RIB7_2 = RIB1_4, // Regional Champ Ribbon
                RIB7_3 = RIB1_5, // National Champ Ribbon
                RIB2_5 = RIB1_6, // World Champ Ribbon

                Friendship       = PKX.getBaseFriendship(Species),
                FatefulEncounter = true,
            };

            if (OTGender == 3) // User's
            {
                pk.TID       = 12345;
                pk.SID       = 54321;
                pk.OT_Name   = "PKHeX";
                pk.OT_Gender = 1; // Red PKHeX OT
            }
            else
            {
                pk.TID       = TID;
                pk.SID       = SID;
                pk.OT_Name   = OT.Length > 0 ? OT : "PKHeX";
                pk.OT_Gender = OTGender % 2; // %2 just in case?
            }
            pk.IsNicknamed = IsNicknamed;
            pk.Nickname    = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language);

            // More 'complex' logic to determine final values

            // Dumb way to generate random IVs.
            int[] finalIVs = new int[6];
            for (int i = 0; i < IVs.Length; i++)
            {
                finalIVs[i] = IVs[i] == 0xFF ? (int)(Util.rnd32() & 0x1F) : IVs[i];
            }
            pk.IVs = finalIVs;

            int av = 0;

            switch (AbilityType)
            {
            case 00:     // 0 - 0
            case 01:     // 1 - 1
            case 02:     // 2 - H
                av = AbilityType;
                break;

            case 03:     // 0/1
            case 04:     // 0/1/H
                av = (int)(Util.rnd32() % (AbilityType - 1));
                break;
            }
            pk.HiddenAbility = av == 2;
            pk.Ability       = PKX.Personal[PKX.Personal[Species].FormeIndex(Species, pk.AltForm)].Abilities[av];

            if (PID != 0)
            {
                pk.PID = PID;
            }
            else
            {
                pk.PID = Util.rnd32();
                // Force Ability
                if (av == 0)
                {
                    pk.PID &= 0xFFFEFFFF;
                }
                else
                {
                    pk.PID |= 0x10000;
                }
                // Force Gender
                do
                {
                    pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF;
                } while (!pk.getGenderIsValid());
                if (PIDType == 2) // Force Shiny
                {
                    uint gb = pk.PID & 0xFF;
                    pk.PID = (uint)(((gb ^ pk.TID ^ pk.SID) & 0xFFFE) << 16) | gb;
                    if (av == 0)
                    {
                        pk.PID &= 0xFFFEFFFE;
                    }
                    else
                    {
                        pk.PID |= 0x10001;
                    }
                }
                else if (PIDType != 1) // Force Not Shiny
                {
                    if (((pk.PID >> 16) ^ (pk.PID & 0xffff) ^ pk.SID ^ pk.TID) < 8)
                    {
                        pk.PID ^= 0x80000000;
                    }
                }
            }

            if (IsEgg)
            {
                // pk.IsEgg = true;
                pk.Egg_Day   = Day;
                pk.Egg_Month = Month;
                pk.Egg_Year  = Year - 2000;
                // Force hatch
                pk.IsEgg        = false;
                pk.Met_Location = 4; // Nuvema Town
            }

            pk.RefreshChecksum();
            return(pk);
        }
Пример #2
0
        public PK6 convertToPK6(SAV6 SAV)
        {
            if (!IsPokémon)
            {
                return(null);
            }

            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK6 pk           = new PK6
            {
                Species            = Species,
                HeldItem           = HeldItem,
                TID                = TID,
                SID                = SID,
                Met_Level          = currentLevel,
                Nature             = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender             = PKX.Personal[Species].Gender == 255 ? 2 : (Gender != 3 ? Gender : PKX.Personal[Species].RandomGender),
                AltForm            = Form,
                EncryptionConstant = EncryptionConstant == 0 ? Util.rnd32() : EncryptionConstant,
                Version            = OriginGame == 0 ? SAV.Game : OriginGame,
                Language           = Language == 0 ? SAV.Language : Language,
                Ball               = Pokéball,
                Country            = SAV.Country,
                Region             = SAV.SubRegion,
                ConsoleRegion      = SAV.ConsoleRegion,
                Move1              = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4,
                Move1_PP           = PKX.getBasePP(Move1),
                Move2_PP           = PKX.getBasePP(Move2),
                Move3_PP           = PKX.getBasePP(Move3),
                Move4_PP           = PKX.getBasePP(Move4),
                RelearnMove1       = RelearnMove1, RelearnMove2 = RelearnMove2,
                RelearnMove3       = RelearnMove3, RelearnMove4 = RelearnMove4,
                Met_Location       = MetLocation,
                Met_Day            = (int)Day,
                Met_Month          = (int)Month,
                Met_Year           = (int)Year - 2000,
                Egg_Location       = EggLocation,
                CNT_Cool           = CNT_Cool,
                CNT_Beauty         = CNT_Beauty,
                CNT_Cute           = CNT_Cute,
                CNT_Smart          = CNT_Smart,
                CNT_Tough          = CNT_Tough,
                CNT_Sheen          = CNT_Sheen,

                OT_Name        = OT.Length > 0 ? OT : SAV.OT,
                OT_Gender      = OTGender != 3 ? OTGender % 2 : SAV.Gender,
                HT_Name        = OT.Length > 0 ? SAV.OT : "",
                HT_Gender      = OT.Length > 0 ? SAV.Gender : 0,
                CurrentHandler = OT.Length > 0 ? 1 : 0,

                EXP = PKX.getEXP(Level, Species),

                // Ribbons
                RIB2_6 = RIB0_3, // Country Ribbon
                RIB2_7 = RIB0_4, // National Ribbon

                RIB3_0 = RIB0_5, // Earth Ribbon
                RIB3_1 = RIB0_6, // World Ribbon
                RIB3_2 = RIB1_5, // Classic Ribbon
                RIB3_3 = RIB1_6, // Premier Ribbon
                RIB3_4 = RIB0_7, // Event Ribbon
                RIB3_5 = RIB1_1, // Birthday Ribbon
                RIB3_6 = RIB1_2, // Special Ribbon
                RIB3_7 = RIB1_3, // Souvenir Ribbon

                RIB4_0 = RIB1_4, // Wishing Ribbon
                RIB4_1 = RIB0_0, // Battle Champ Ribbon
                RIB4_2 = RIB0_1, // Regional Champ Ribbon
                RIB4_3 = RIB0_2, // National Champ Ribbon
                RIB4_4 = RIB1_0, // World Champ Ribbon

                OT_Friendship    = PKX.getBaseFriendship(Species),
                FatefulEncounter = true,
            };

            if (pk.CurrentHandler == 0) // OT
            {
                pk.OT_Memory    = 3;
                pk.OT_TextVar   = 9;
                pk.OT_Intensity = 1;
                pk.OT_Feeling   = Util.rand.Next(0, 9);
            }
            else
            {
                pk.HT_Memory     = 3;
                pk.HT_TextVar    = 9;
                pk.HT_Intensity  = 1;
                pk.HT_Feeling    = Util.rand.Next(0, 9);
                pk.HT_Friendship = pk.OT_Friendship;
            }
            pk.IsNicknamed = IsNicknamed;
            pk.Nickname    = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language);

            // More 'complex' logic to determine final values

            // Dumb way to generate random IVs.
            int[] finalIVs = new int[6];
            switch (IVs[0])
            {
            case 0xFE:
                finalIVs[0] = 31;
                do       // 31 HP IV, 2 other 31s
                {
                    for (int i = 1; i < 6; i++)
                    {
                        finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                    }
                } while (finalIVs.Count(r => r == 31) < 3);     // 31 + 2*31
                break;

            case 0xFD:
                do       // 2 other 31s
                {
                    for (int i = 0; i < 6; i++)
                    {
                        finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                    }
                } while (finalIVs.Count(r => r == 31) < 2);     // 2*31
                break;

            default:     // Random IVs
                for (int i = 0; i < 6; i++)
                {
                    finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                }
                break;
            }
            pk.IVs = finalIVs;

            int av = 0;

            switch (AbilityType)
            {
            case 00:     // 0 - 0
            case 01:     // 1 - 1
            case 02:     // 2 - H
                av = AbilityType;
                break;

            case 03:     // 0/1
            case 04:     // 0/1/H
                av = (int)(Util.rnd32() % (AbilityType - 1));
                break;
            }
            pk.Ability       = PKX.Personal[PKX.Personal[Species].FormeIndex(Species, pk.AltForm)].Abilities[av];
            pk.AbilityNumber = 1 << av;

            switch (PIDType)
            {
            case 00:     // Specified
                pk.PID = PID;
                break;

            case 01:     // Random
                pk.PID = Util.rnd32();
                break;

            case 02:     // Random Shiny
                pk.PID = Util.rnd32();
                pk.PID = (uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF));
                break;

            case 03:     // Random Nonshiny
                do
                {
                    pk.PID = Util.rnd32();
                } while ((uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF)) < 16);
                break;
            }

            if (IsEgg)
            {
                pk.IsEgg     = true;
                pk.Egg_Day   = (int)Day;
                pk.Egg_Month = (int)Month;
                pk.Egg_Year  = (int)Year;
            }

            pk.RefreshChecksum();
            return(pk);
        }
Пример #3
0
        public PK4 convertToPK4(SAV6 SAV)
        {
            if (!PokémonGift)
            {
                return(null);
            }

            PK4 pk4 = new PK4(PK.Data);

            if (!IsPokémon && Detail == 0)
            {
                pk4.OT_Name   = "PKHeX";
                pk4.TID       = 12345;
                pk4.SID       = 54321;
                pk4.OT_Gender = (int)(Util.rnd32() % 2);
            }
            if (IsManaphyEgg)
            {
                // Since none of this data is populated, fill in default info.
                pk4.Species = 490;
                // Level 1 Moves
                pk4.Move1            = 294;
                pk4.Move2            = 145;
                pk4.Move3            = 346;
                pk4.FatefulEncounter = true;
                pk4.Ball             = 4;
                pk4.Version          = 10; // Diamond
                pk4.Language         = 2;  // English
                pk4.Nickname         = "MANAPHY";
                pk4.Egg_Location     = 1;  // Ranger (will be +3000 later)
            }

            // Generate IV
            uint seed = Util.rnd32();

            if (pk4.PID == 1) // Create Nonshiny
            {
                uint pid1 = PKM.LCRNG(ref seed) >> 16;
                uint pid2 = PKM.LCRNG(ref seed) >> 16;

                while ((pid1 ^ pid2 ^ pk4.TID ^ pk4.SID) < 8)
                {
                    uint testPID = pid1 | pid2 << 16;

                    // Call the ARNG to change the PID
                    testPID = testPID * 0x6c078965 + 1;

                    pid1 = testPID & 0xFFFF;
                    pid2 = testPID >> 16;
                }
                pk4.PID = pid1 | (pid2 << 16);
            }

            // Generate IVs
            if (pk4.IV32 == 0)
            {
                uint iv1 = PKM.LCRNG(ref seed) >> 16;
                uint iv2 = PKM.LCRNG(ref seed) >> 16;
                pk4.IV32 = (iv1 | iv2 << 16) & 0x3FFFFFFF;
            }

            // Generate Met Info
            DateTime dt = DateTime.Now;

            if (IsPokémon)
            {
                pk4.Met_Location = pk4.Egg_Location + 3000;
                pk4.Egg_Location = 0;
                pk4.Met_Day      = dt.Day;
                pk4.Met_Month    = dt.Month;
                pk4.Met_Year     = dt.Year - 2000;
                pk4.IsEgg        = false;
            }
            else
            {
                pk4.Egg_Location = pk4.Egg_Location + 3000;
                pk4.Egg_Day      = dt.Day;
                pk4.Egg_Month    = dt.Month;
                pk4.Egg_Year     = dt.Year - 2000;
                pk4.IsEgg        = false;
                // Met Location is modified when transferred to pk5; don't worry about it.
            }
            if (pk4.Species == 201) // Never will be true; Unown was never distributed.
            {
                pk4.AltForm = PKM.getUnownForm(pk4.PID);
            }

            return(pk4);
        }
Пример #4
0
        public override PKM convertToPKM(SaveFile SAV)
        {
            if (!IsPokémon)
            {
                return(null);
            }

            DateTime dt = DateTime.Now;

            if (Day == 0)
            {
                Day   = (byte)dt.Day;
                Month = (byte)dt.Month;
                Year  = (byte)dt.Year;
            }
            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK5 pk           = new PK5
            {
                Species      = Species,
                HeldItem     = HeldItem,
                Met_Level    = currentLevel,
                Nature       = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender       = PersonalTable.B2W2[Species].Gender == 255 ? 2 : (Gender != 2 ? Gender : PersonalTable.B2W2[Species].RandomGender),
                AltForm      = Form,
                Version      = OriginGame == 0 ? new[] { 20, 21, 22, 23 }[Util.rnd32() & 0x3] : OriginGame,
                Language     = Language == 0 ? SAV.Language : Language,
                Ball         = Ball,
                Move1        = Move1,
                Move2        = Move2,
                Move3        = Move3,
                Move4        = Move4,
                Met_Location = MetLocation,
                MetDate      = Date,
                Egg_Location = EggLocation,
                CNT_Cool     = CNT_Cool,
                CNT_Beauty   = CNT_Beauty,
                CNT_Cute     = CNT_Cute,
                CNT_Smart    = CNT_Smart,
                CNT_Tough    = CNT_Tough,
                CNT_Sheen    = CNT_Sheen,

                EXP = PKX.getEXP(Level, Species),

                // Ribbons
                RibbonCountry  = RibbonCountry,
                RibbonNational = RibbonNational,
                RibbonEarth    = RibbonEarth,
                RibbonWorld    = RibbonWorld,
                RibbonClassic  = RibbonClassic,
                RibbonPremier  = RibbonPremier,
                RibbonEvent    = RibbonEvent,
                RibbonBirthday = RibbonBirthday,

                RibbonSpecial          = RibbonSpecial,
                RibbonSouvenir         = RibbonSouvenir,
                RibbonWishing          = RibbonWishing,
                RibbonChampionBattle   = RibbonChampionBattle,
                RibbonChampionRegional = RibbonChampionRegional,
                RibbonChampionNational = RibbonChampionNational,
                RibbonChampionWorld    = RibbonChampionWorld,

                OT_Friendship    = PersonalTable.B2W2[Species].BaseFriendship,
                FatefulEncounter = true,
            };

            pk.Move1_PP = pk.getMovePP(Move1, 0);
            pk.Move2_PP = pk.getMovePP(Move2, 0);
            pk.Move3_PP = pk.getMovePP(Move3, 0);
            pk.Move4_PP = pk.getMovePP(Move4, 0);
            if (OTGender == 3) // User's
            {
                pk.TID       = SAV.TID;
                pk.SID       = SAV.SID;
                pk.OT_Name   = SAV.OT;
                pk.OT_Gender = 1; // Red PKHeX OT
            }
            else
            {
                pk.TID       = IsEgg ? SAV.TID : TID;
                pk.SID       = IsEgg ? SAV.SID : SID;
                pk.OT_Name   = OT.Length > 0 ? OT : SAV.OT;
                pk.OT_Gender = OTGender % 2; // %2 just in case?
            }
            pk.IsNicknamed = IsNicknamed;
            pk.Nickname    = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language);

            // More 'complex' logic to determine final values

            // Dumb way to generate random IVs.
            int[] finalIVs = new int[6];
            for (int i = 0; i < IVs.Length; i++)
            {
                finalIVs[i] = IVs[i] == 0xFF ? (int)(Util.rnd32() & 0x1F) : IVs[i];
            }
            pk.IVs = finalIVs;

            int av = 0;

            switch (AbilityType)
            {
            case 00:     // 0 - 0
            case 01:     // 1 - 1
            case 02:     // 2 - H
                av = AbilityType;
                break;

            case 03:     // 0/1
            case 04:     // 0/1/H
                av = (int)(Util.rnd32() % (AbilityType - 1));
                break;
            }
            pk.HiddenAbility = av == 2;
            pk.Ability       = PersonalTable.B2W2.getAbilities(Species, pk.AltForm)[av];

            if (PID != 0)
            {
                pk.PID = PID;
            }
            else
            {
                pk.PID = Util.rnd32();
                // Force Ability
                if (av == 0)
                {
                    pk.PID &= 0xFFFEFFFF;
                }
                else
                {
                    pk.PID |= 0x10000;
                }
                // Force Gender
                do
                {
                    pk.PID = (pk.PID & 0xFFFFFF00) | Util.rnd32() & 0xFF;
                } while (!pk.getGenderIsValid());
                if (PIDType == 2) // Force Shiny
                {
                    uint gb = pk.PID & 0xFF;
                    pk.PID = (uint)(((gb ^ pk.TID ^ pk.SID) & 0xFFFE) << 16) | gb;
                    if (av == 0)
                    {
                        pk.PID &= 0xFFFEFFFE;
                    }
                    else
                    {
                        pk.PID |= 0x10001;
                    }
                }
                else if (PIDType != 1) // Force Not Shiny
                {
                    if (((pk.PID >> 16) ^ (pk.PID & 0xffff) ^ pk.SID ^ pk.TID) < 8)
                    {
                        pk.PID ^= 0x80000000;
                    }
                }
            }

            if (IsEgg)
            {
                // pk.IsEgg = true;
                pk.EggMetDate = Date;
                // Force hatch
                pk.IsEgg        = false;
                pk.Met_Location = 4; // Nuvema Town
            }

            pk.RefreshChecksum();
            return(pk);
        }
Пример #5
0
        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);
        }
Пример #6
0
        public override PKM convertToPKM(SaveFile SAV)
        {
            if (!IsPokémon)
            {
                return(null);
            }

            int currentLevel = Level > 0 ? Level : (int)(Util.rnd32() % 100 + 1);
            PK6 pk           = new PK6
            {
                Species            = Species,
                HeldItem           = HeldItem,
                TID                = TID,
                SID                = SID,
                Met_Level          = currentLevel,
                Nature             = Nature != 0xFF ? Nature : (int)(Util.rnd32() % 25),
                Gender             = PersonalTable.AO[Species].Gender == 255 ? 2 : (Gender != 3 ? Gender : PersonalTable.AO[Species].RandomGender),
                AltForm            = Form,
                EncryptionConstant = EncryptionConstant == 0 ? Util.rnd32() : EncryptionConstant,
                Version            = OriginGame == 0 ? SAV.Game : OriginGame,
                Language           = Language == 0 ? SAV.Language : Language,
                Ball               = Ball,
                Country            = SAV.Country,
                Region             = SAV.SubRegion,
                ConsoleRegion      = SAV.ConsoleRegion,
                Move1              = Move1, Move2 = Move2, Move3 = Move3, Move4 = Move4,
                RelearnMove1       = RelearnMove1, RelearnMove2 = RelearnMove2,
                RelearnMove3       = RelearnMove3, RelearnMove4 = RelearnMove4,
                Met_Location       = MetLocation,
                Egg_Location       = EggLocation,
                CNT_Cool           = CNT_Cool,
                CNT_Beauty         = CNT_Beauty,
                CNT_Cute           = CNT_Cute,
                CNT_Smart          = CNT_Smart,
                CNT_Tough          = CNT_Tough,
                CNT_Sheen          = CNT_Sheen,

                OT_Name        = OT.Length > 0 ? OT : SAV.OT,
                OT_Gender      = OTGender != 3 ? OTGender % 2 : SAV.Gender,
                HT_Name        = OT.Length > 0 ? SAV.OT : "",
                HT_Gender      = OT.Length > 0 ? SAV.Gender : 0,
                CurrentHandler = OT.Length > 0 ? 1 : 0,

                EXP = PKX.getEXP(Level, Species),

                // Ribbons
                RibbonCountry  = RibbonCountry,
                RibbonNational = RibbonNational,

                RibbonEarth    = RibbonEarth,
                RibbonWorld    = RibbonWorld,
                RibbonClassic  = RibbonClassic,
                RibbonPremier  = RibbonPremier,
                RibbonEvent    = RibbonEvent,
                RibbonBirthday = RibbonBirthday,
                RibbonSpecial  = RibbonSpecial,
                RibbonSouvenir = RibbonSouvenir,

                RibbonWishing          = RibbonWishing,
                RibbonChampionBattle   = RibbonChampionBattle,
                RibbonChampionRegional = RibbonChampionRegional,
                RibbonChampionNational = RibbonChampionNational,
                RibbonChampionWorld    = RibbonChampionWorld,

                OT_Friendship    = PersonalTable.AO[Species].BaseFriendship,
                OT_Intensity     = OT_Intensity,
                OT_Memory        = OT_Memory,
                OT_TextVar       = OT_TextVar,
                OT_Feeling       = OT_Feeling,
                FatefulEncounter = true,
            };

            pk.Move1_PP = pk.getMovePP(Move1, 0);
            pk.Move2_PP = pk.getMovePP(Move2, 0);
            pk.Move3_PP = pk.getMovePP(Move3, 0);
            pk.Move4_PP = pk.getMovePP(Move4, 0);

            pk.MetDate = Date ?? DateTime.Now;

            if (SAV.Generation > 6) // Gen7
            {
                pk.Version = (int)GameVersion.OR;
            }

            if (pk.CurrentHandler == 0) // OT
            {
                pk.OT_Memory    = 3;
                pk.OT_TextVar   = 9;
                pk.OT_Intensity = 1;
                pk.OT_Feeling   = Util.rand.Next(0, 9);
            }
            else
            {
                pk.HT_Memory     = 3;
                pk.HT_TextVar    = 9;
                pk.HT_Intensity  = 1;
                pk.HT_Feeling    = Util.rand.Next(0, 9);
                pk.HT_Friendship = pk.OT_Friendship;
            }
            pk.IsNicknamed = IsNicknamed;
            pk.Nickname    = IsNicknamed ? Nickname : PKX.getSpeciesName(Species, pk.Language);

            // More 'complex' logic to determine final values

            // Dumb way to generate random IVs.
            int[] finalIVs = new int[6];
            switch (IVs[0])
            {
            case 0xFE:
                finalIVs[0] = 31;
                do       // 31 HP IV, 2 other 31s
                {
                    for (int i = 1; i < 6; i++)
                    {
                        finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                    }
                } while (finalIVs.Count(r => r == 31) < 3);     // 31 + 2*31
                break;

            case 0xFD:
                do       // 2 other 31s
                {
                    for (int i = 0; i < 6; i++)
                    {
                        finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                    }
                } while (finalIVs.Count(r => r == 31) < 2);     // 2*31
                break;

            default:     // Random IVs
                for (int i = 0; i < 6; i++)
                {
                    finalIVs[i] = IVs[i] > 31 ? (int)(Util.rnd32() & 0x1F) : IVs[i];
                }
                break;
            }
            pk.IVs = finalIVs;

            int av = 0;

            switch (AbilityType)
            {
            case 00:     // 0 - 0
            case 01:     // 1 - 1
            case 02:     // 2 - H
                av = AbilityType;
                break;

            case 03:     // 0/1
            case 04:     // 0/1/H
                av = (int)(Util.rnd32() % (AbilityType - 1));
                break;
            }
            pk.Ability       = PersonalTable.AO.getAbilities(Species, pk.AltForm)[av];
            pk.AbilityNumber = 1 << av;

            switch (PIDType)
            {
            case 00:     // Specified
                pk.PID = PID;
                break;

            case 01:     // Random
                pk.PID = Util.rnd32();
                break;

            case 02:     // Random Shiny
                pk.PID = Util.rnd32();
                pk.PID = (uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF));
                break;

            case 03:     // Random Nonshiny
                do
                {
                    pk.PID = Util.rnd32();
                } while ((uint)(((TID ^ SID ^ (pk.PID & 0xFFFF)) << 16) + (pk.PID & 0xFFFF)) < 16);
                break;
            }

            if (IsEgg)
            {
                pk.IsEgg      = true;
                pk.EggMetDate = Date;
            }

            pk.RefreshChecksum();
            return(pk);
        }