예제 #1
0
        private static bool CommonErrorHandling2(PKM pk)
        {
            var report = GetReport(pk);

            // f*****g M2
            if (GameVersion.FRLG.Contains(pk.Version) && UsesEventBasedMethod(pk.Species, pk.Moves, PIDType.Method_2))
            {
                M2EventFix(pk, pk.IsShiny);
                report = GetReport(pk);
            }

            if (UsesEventBasedMethod(pk.Species, pk.Moves, PIDType.BACD_R) && pk.Version == (int)GameVersion.R)
            {
                BACD_REventFix(pk, pk.IsShiny);
                report = GetReport(pk);
            }

            if (report.Contains(LNickMatchLanguageFail))
            {
                pk.Nickname = SpeciesName.GetSpeciesNameGeneration(pk.Species, pk.Language, pk.Format); // failsafe to reset nick
                report      = GetReport(pk);
            }
            if (report.Contains(LStatIncorrectCP))
            {
                ((PB7)pk).ResetCP();
                report = GetReport(pk);
            }
            if (report.Contains(LAbilityMismatch)) //V223 = Ability mismatch for encounter.
            {
                pk.RefreshAbility((uint)pk.AbilityNumber < 6 ? pk.AbilityNumber >> 1 : 0);
                report = GetReport(pk);
                if (report.Contains(LAbilityMismatch)) //V223 = Ability mismatch for encounter.
                {
                    AlternateAbilityRefresh(pk);
                }
                report = GetReport(pk);
            }
            if (report.Contains(LTransferEggLocationTransporter)) //V61 = Invalid Met Location, expected Transporter.
            {
                pk.Met_Location = 30001;
                report          = GetReport(pk);
            }
            if (report.Contains(LBallEncMismatch)) //V118 = Can't have ball for encounter type.
            {
                if (pk.B2W2)
                {
                    pk.Ball = 25; //Dream Ball
                    report  = GetReport(pk);
                }
                else
                {
                    pk.Ball = 0;
                    report  = GetReport(pk);
                }
            }
            if (report.Contains(LEncUnreleasedEMewJP)) //V353 = Non japanese Mew from Faraway Island. Unreleased event.
            {
                bool shiny = pk.IsShiny;
                pk.Language         = 1;
                pk.FatefulEncounter = true;
                pk.Nickname         = SpeciesName.GetSpeciesNameGeneration(pk.Species, pk.Language, 3);
                pk.PID = PKX.GetRandomPID(Util.Rand, pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
                if (shiny)
                {
                    pk.SetShinySID();
                }
                report = GetReport(pk);
            }
            if (report.Contains(LPIDEqualsEC)) //V208 = Encryption Constant matches PID.
            {
                pk.SetRandomEC();
                report = GetReport(pk);
            }
            if (report.Contains(LTransferPIDECEquals)) //V216 = PID should be equal to EC!
            {
                pk.EncryptionConstant = pk.PID;
                report = GetReport(pk);
            }
            if (report.Contains(LTransferPIDECBitFlip)) //V215 = PID should be equal to EC [with top bit flipped]!
            {
                pk.PID = PKX.GetRandomPID(Util.Rand, pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
                if (pk.IsShiny)
                {
                    pk.SetShiny();
                }
                report = GetReport(pk);
            }
            if (report.Contains(LPIDGenderMismatch)) //V251 = PID-Gender mismatch.
            {
                pk.Gender = pk.Gender == 0 ? 1 : 0;
                report    = GetReport(pk);
            }
            if (report.Contains(LG3OTGender) || report.Contains(LG1OTGender)) //V407 = OT from Colosseum/XD cannot be female. V408 = Female OT from Generation 1 / 2 is invalid.
            {
                pk.OT_Gender = 0;
                report       = GetReport(pk);
            }
            if (report.Contains(LLevelMetBelow)) //V85 = Current level is below met level.
            {
                pk.CurrentLevel = 100;
                report          = GetReport(pk);
            }
            if (report.Contains(string.Format(LRibbonFMissing_0, "National"))) //V600 = Missing Ribbons: {0} (National in this case)
            {
                if (pk is IRibbonSetEvent3 e3)
                {
                    e3.RibbonNational = true;
                }
                report = GetReport(pk);
            }
            if (report.Contains(string.Format(LRibbonFInvalid_0, "National"))) //V601 = Invalid Ribbons: {0} (National in this case)
            {
                if (pk is IRibbonSetEvent3 e3)
                {
                    e3.RibbonNational = false;
                }
                report = GetReport(pk);
            }
            if (report.Contains(LOTLong)) //V38 = OT Name too long.
            {
                pk.OT_Name = "ARCH";
                report     = GetReport(pk);
            }
            if (report.Contains(LG1CharOT)) //V421 = OT from Generation 1/2 uses unavailable characters.
            {
                pk.OT_Name = "ARCH";
                report     = GetReport(pk);
            }
            if (report.Contains(LGeoNoCountryHT))
            {
                var g = (IGeoTrack)pk;
                g.Geo1_Country = 1;
                report         = GetReport(pk);
            }
            if (report.Contains(LMemoryMissingHT)) //V150 = Memory: Handling Trainer Memory missing.
            {
                pk.HT_Memory     = 3;
                pk.HT_TextVar    = 9;
                pk.HT_Intensity  = 1;
                pk.HT_Feeling    = Util.Rand.Next(0, 10); // 0-9
                pk.HT_Friendship = pk.OT_Friendship;
                report           = GetReport(pk);
            }
            if (report.Contains(LMemoryMissingOT)) //V152 = Memory: Original Trainer Memory missing.
            {
                pk.OT_Memory    = 3;
                pk.OT_TextVar   = 9;
                pk.OT_Intensity = 1;
                pk.OT_Feeling   = Util.Rand.Next(0, 10); // 0-9
                report          = GetReport(pk);
            }
            if (report.Contains(string.Format(LMemoryFeelInvalid, "OT")) || report.Contains(string.Format(LMemoryFeelInvalid, "HT"))) //V255 = {0} Memory: Invalid Feeling (0 = OT/HT)
            {
                pk.HT_Memory     = 3;
                pk.HT_TextVar    = 9;
                pk.HT_Intensity  = 1;
                pk.HT_Feeling    = Memories.GetRandomFeeling(pk.HT_Memory);
                pk.HT_Friendship = pk.OT_Friendship;
                pk.OT_Memory     = 3;
                pk.OT_TextVar    = 9;
                pk.OT_Intensity  = 1;
                pk.OT_Feeling    = Memories.GetRandomFeeling(pk.OT_Memory);
                report           = GetReport(pk);
            }
            if (report.Contains(LGeoMemoryMissing)) //V137 = GeoLocation Memory: Memories should be present.
            {
                var g = (IGeoTrack)pk;
                g.Geo1_Country = 1;
                report         = GetReport(pk);
            }
            if (report.Contains(LBallEncMismatch)) //V118 = Can't have ball for encounter type.
            {
                pk.Ball = 4;
                report  = GetReport(pk);
            }
            if (report.Contains(LGeoHardwareInvalid)) //Geolocation: Country is not in 3DS region.
            {
                pk.Country       = 0;
                pk.Region        = 0;
                pk.ConsoleRegion = 2;
                report           = GetReport(pk);
            }
            if (report.Contains(LFormBattle)) //V310 = Form cannot exist outside of a battle.
            {
                if (pk.Species == 718 && pk.Ability == 211)
                {
                    pk.AltForm = 3; // Zygarde Edge case
                }
                else
                {
                    pk.AltForm = 0;
                }
                report = GetReport(pk);
            }
            if (report.Contains(LFatefulMissing)) //V324 = Special ingame Fateful Encounter flag missing.
            {
                pk.FatefulEncounter = true;
                report = GetReport(pk);
            }
            if (report.Contains(LFatefulInvalid)) //V325 = Fateful Encounter should not be checked.

            {
                pk.FatefulEncounter = false;
                report = GetReport(pk);
            }
            if (report.Contains(LEncTypeMismatch)) //V381 = Encounter Type does not match encounter.
            {
                var match = new LegalityAnalysis(pk).Info.EncounterMatch;
                var type  = GetRequiredEncounterType(pk, match);

                if (!type.Contains(pk.EncounterType))
                {
                    pk.EncounterType = Convert.ToInt32(Math.Log((int)type, 2));
                }
                else
                {
                    Debug.WriteLine("This should never happen");
                }
                report = GetReport(pk);
            }
            if (report.Contains(LEvoInvalid)) //V86 = Evolution not valid (or level/trade evolution unsatisfied).
            {
                pk.Met_Level--;
                report = GetReport(pk);
            }
            if (report.Contains(LPIDTypeMismatch)) //V411 = Encounter Type PID mismatch.
            {
                SetPIDSID(pk, pk.IsShiny, pk.Version == (int)GameVersion.CXD);

                if (new LegalityAnalysis(pk).Valid)
                {
                    return(false);
                }

                report = GetReport(pk);
                if (report.Equals(LPIDTypeMismatch)) // V411 = Encounter Type PID mismatch.
                {
                    return(true);
                }

                if (report.Contains(LPIDGenderMismatch)) // V251 = PID-Gender mismatch.
                {
                    pk.Gender = pk.Gender == 0 ? 1 : 0;
                    report    = GetReport(pk);
                    if (new LegalityAnalysis(pk).Valid)
                    {
                        return(false);
                    }
                }
            }
            if (report.Contains(LHyperPerfectAll)) // V41 = Can't Hyper Train a Pokémon with perfect IVs.
            {
                ((IHyperTrain)pk).HyperTrainClear();
                report = GetReport(pk);
            }
            if (report.Contains(LHyperPerfectOne)) // V42 = Can't Hyper Train a perfect IV.
            {
                pk.ClearHyperTrainedPerfectIVs();
            }

            return(false);
        }
예제 #2
0
        private PKM prepareCK3()
        {
            CK3 ck3 = pkm as CK3;

            if (ck3 == null)
            {
                return(null);
            }

            ck3.Species       = Util.getIndex(CB_Species);
            ck3.HeldItem      = Util.getIndex(CB_HeldItem);
            ck3.TID           = Util.ToInt32(TB_TID.Text);
            ck3.SID           = Util.ToInt32(TB_SID.Text);
            ck3.EXP           = Util.ToUInt32(TB_EXP.Text);
            ck3.PID           = Util.getHEXval(TB_PID.Text);
            ck3.AbilityNumber = CB_Ability.SelectedIndex;

            ck3.FatefulEncounter = CHK_Fateful.Checked;
            ck3.Gender           = PKX.getGender(Label_Gender.Text);
            ck3.EV_HP            = Util.ToInt32(TB_HPEV.Text);
            ck3.EV_ATK           = Util.ToInt32(TB_ATKEV.Text);
            ck3.EV_DEF           = Util.ToInt32(TB_DEFEV.Text);
            ck3.EV_SPE           = Util.ToInt32(TB_SPEEV.Text);
            ck3.EV_SPA           = Util.ToInt32(TB_SPAEV.Text);
            ck3.EV_SPD           = Util.ToInt32(TB_SPDEV.Text);

            ck3.CNT_Cool   = Util.ToInt32(TB_Cool.Text);
            ck3.CNT_Beauty = Util.ToInt32(TB_Beauty.Text);
            ck3.CNT_Cute   = Util.ToInt32(TB_Cute.Text);
            ck3.CNT_Smart  = Util.ToInt32(TB_Smart.Text);
            ck3.CNT_Tough  = Util.ToInt32(TB_Tough.Text);
            ck3.CNT_Sheen  = Util.ToInt32(TB_Sheen.Text);

            ck3.PKRS_Days   = CB_PKRSDays.SelectedIndex;
            ck3.PKRS_Strain = CB_PKRSStrain.SelectedIndex;
            ck3.Nickname    = TB_Nickname.Text;
            ck3.Move1       = Util.getIndex(CB_Move1);
            ck3.Move2       = Util.getIndex(CB_Move2);
            ck3.Move3       = Util.getIndex(CB_Move3);
            ck3.Move4       = Util.getIndex(CB_Move4);
            ck3.Move1_PP    = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            ck3.Move2_PP    = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            ck3.Move3_PP    = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            ck3.Move4_PP    = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            ck3.Move1_PPUps = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            ck3.Move2_PPUps = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            ck3.Move3_PPUps = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            ck3.Move4_PPUps = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;

            ck3.IV_HP       = Util.ToInt32(TB_HPIV.Text);
            ck3.IV_ATK      = Util.ToInt32(TB_ATKIV.Text);
            ck3.IV_DEF      = Util.ToInt32(TB_DEFIV.Text);
            ck3.IV_SPE      = Util.ToInt32(TB_SPEIV.Text);
            ck3.IV_SPA      = Util.ToInt32(TB_SPAIV.Text);
            ck3.IV_SPD      = Util.ToInt32(TB_SPDIV.Text);
            ck3.IsEgg       = CHK_IsEgg.Checked;
            ck3.IsNicknamed = CHK_Nicknamed.Checked;

            ck3.OT_Name           = TB_OT.Text;
            ck3.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);

            ck3.Ball      = Util.getIndex(CB_Ball);
            ck3.Met_Level = Util.ToInt32(TB_MetLevel.Text);
            ck3.OT_Gender = PKX.getGender(Label_OTGender.Text);
            ck3.Version   = Util.getIndex(CB_GameOrigin);
            ck3.Language  = Util.getIndex(CB_Language);

            ck3.Met_Location = Util.getIndex(CB_MetLocation);

            // Toss in Party Stats
            Array.Resize(ref ck3.Data, ck3.SIZE_PARTY);
            ck3.Stat_Level     = Util.ToInt32(TB_Level.Text);
            ck3.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            ck3.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            ck3.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            ck3.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            ck3.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            ck3.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            ck3.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            if (HaX)
            {
                ck3.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }

            // Shadow Info
            ck3.ShadowID = (int)NUD_ShadowID.Value;
            if (ck3.ShadowID > 0)
            {
                ck3.Purification = (int)NUD_Purification.Value;
            }

            // Fix Moves if a slot is empty
            ck3.FixMoves();

            ck3.RefreshChecksum();
            return(ck3);
        }
예제 #3
0
        public PKM LoadShowdownSetModded_PKSM(PKM Set, bool resetForm = false, int TID = -1, int SID = -1, string OT = "")
        {
            bool trainerinfo = TID > 0;
            int  abilitynum  = Set.AbilityNumber < 6 ? Set.AbilityNumber >> 1 : 0;

            if (resetForm)
            {
                Set.AltForm = 0;
                Set.RefreshAbility(Set.AbilityNumber < 6 ? Set.AbilityNumber >> 1 : 0);
            }
            bool shiny     = Set.IsShiny;
            bool legendary = false;
            bool eventMon  = false;

            int[] legendaryList = new int[] { 144, 145, 146, 150, 151, 243, 244, 245, 249, 250, 251, 377, 378, 379, 380, 381, 382, 383, 384, 385,
                                              386, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 638, 639, 640, 642,
                                              641, 645, 643, 644, 646, 647, 648, 649, 716, 717, 718, 719, 720, 721, 785, 786, 787, 788, 789, 790,
                                              791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801 };

            int[] eventList = new int[] { 251, 719, 649, 720, 385, 647, 490, 648, 721, 801, 802 };

            int[] GameVersionList = new int[] { (int)GameVersion.MN, (int)GameVersion.SN, (int)GameVersion.AS, (int)GameVersion.OR, (int)GameVersion.X,
                                                (int)GameVersion.Y, (int)GameVersion.B, (int)GameVersion.B2, (int)GameVersion.W, (int)GameVersion.W2,
                                                (int)GameVersion.D, (int)GameVersion.P, (int)GameVersion.Pt, (int)GameVersion.HG, (int)GameVersion.SS,
                                                (int)GameVersion.R, (int)GameVersion.S, (int)GameVersion.E, (int)GameVersion.FR, (int)GameVersion.LG,
                                                (int)GameVersion.CXD, (int)GameVersion.RD, (int)GameVersion.GN, (int)GameVersion.BU, (int)GameVersion.YW };

            foreach (int mon in legendaryList)
            {
                if (Set.Species == mon)
                {
                    legendary = true;
                }
            }

            foreach (int mon in eventList)
            {
                if (Set.Species == mon)
                {
                    eventMon = true;
                }
            }

            // Egg based pokemon
            if (!legendary && !eventMon)
            {
                for (int i = 0; i < GameVersionList.Length; i++)
                {
                    Set.Version  = GameVersionList[i];
                    Set.Language = 2;
                    if (Set.OT_Name != "" && Set.TID > 0 && Set.SID > 0)
                    {
                    }
                    else if (trainerinfo)
                    {
                        Set.OT_Name = OT;
                        Set.TID     = TID;
                        Set.SID     = SID;
                    }
                    else
                    {
                        Set.OT_Name = "Archit (TCD)";
                        Set.TID     = 24521;
                        Set.SID     = 42312;
                    }
                    Set.MetDate = DateTime.Today;
                    if (Set.Version == (int)GameVersion.RD || Set.Version == (int)GameVersion.BU || Set.Version == (int)GameVersion.YW || Set.Version == (int)GameVersion.GN)
                    {
                        Set.SID = 0;
                    }
                    Set.EggMetDate   = new DateTime(2000, 1, 1);
                    Set.Egg_Location = 60002;
                    if (Set.Version == (int)GameVersion.D || Set.Version == (int)GameVersion.P || Set.Version == (int)GameVersion.Pt)
                    {
                        Set.Egg_Location = 2002;
                    }
                    Set.Met_Level     = 1;
                    Set.Country       = 64;
                    Set.ConsoleRegion = 2;
                    if (Set.Version == (int)GameVersion.RD || Set.Version == (int)GameVersion.BU || Set.Version == (int)GameVersion.YW || Set.Version == (int)GameVersion.GN)
                    {
                        Set.Met_Location = 30013;
                        Set.Met_Level    = 100;
                    }
                    if (Set.Version == (int)GameVersion.CXD)
                    {
                        Set.Met_Location = 30001;
                        Set.Met_Level    = 100;
                    }
                    else
                    {
                        Set = clickMetLocationModPKSM(Set);
                    }
                    if (Set.GenNumber > 4)
                    {
                        Set.Met_Level = 1;
                    }
                    try
                    {
                        Set.CurrentHandler = 1;
                        Set.HT_Name        = "Archit";
                        Set     = SetSuggestedRelearnMoves_PKSM(Set);
                        Set.PID = PKX.GetRandomPID(Set.Species, Set.Gender, Set.Version, Set.Nature, Set.Format, (uint)(Set.AbilityNumber * 0x10001));
                        if (shiny)
                        {
                            Set.SetShinyPID();
                        }
                        if (Set.PID == 0)
                        {
                            Set.PID = PKX.GetRandomPID(Set.Species, Set.Gender, Set.Version, Set.Nature, Set.Format, (uint)(Set.AbilityNumber * 0x10001));
                            if (shiny)
                            {
                                Set.SetShinyPID();
                            }
                        }
                        if (Set.GenNumber < 6)
                        {
                            Set.EncryptionConstant = Set.PID;
                        }
                        if (CommonErrorHandling2(Set))
                        {
                            if (shiny)
                            {
                                Set.SetShinyPID();
                            }
                            return(Set);
                        }
                        if (Set.GenNumber < 6)
                        {
                            Set.EncryptionConstant = Set.PID;
                        }
                        if (new LegalityAnalysis(Set).Valid)
                        {
                            return(Set);
                        }
                        else
                        {
                            if (debug)
                            {
                                LegalityAnalysis la = new LegalityAnalysis(Set);
                                Console.WriteLine(la.Report(false));
                            }
                        }
                    }
                    catch { continue; }
                }
            }

            if (!new LegalityAnalysis(Set).Valid&& !eventMon)
            {
                for (int i = 0; i < GameVersionList.Length; i++)
                {
                    if (Set.Met_Level == 100)
                    {
                        Set.Met_Level = 0;
                    }
                    Set.WasEgg        = false;
                    Set.EggMetDate    = null;
                    Set.Egg_Location  = 0;
                    Set.Version       = GameVersionList[i];
                    Set.Language      = 2;
                    Set.Country       = 64;
                    Set.ConsoleRegion = 2;
                    if (Set.OT_Name != "" && Set.TID > 0 && Set.SID > 0)
                    {
                    }
                    else if (trainerinfo)
                    {
                        Set.OT_Name = OT;
                        Set.TID     = TID;
                        Set.SID     = SID;
                    }
                    else
                    {
                        Set.OT_Name = "Archit (TCD)";
                        Set.TID     = 24521;
                        Set.SID     = 42312;
                    }
                    Set.MetDate = DateTime.Today;
                    if (Set.Species == 793 || Set.Species == 794 || Set.Species == 795 || Set.Species == 796 || Set.Species == 797 || Set.Species == 798 || Set.Species == 799)
                    {
                        Set.Ball = 26;
                    }
                    if (Set.Version == (int)GameVersion.RD || Set.Version == (int)GameVersion.BU || Set.Version == (int)GameVersion.YW || Set.Version == (int)GameVersion.GN)
                    {
                        Set.SID = 0;
                    }
                    try
                    {
                        Set.RelearnMove1 = 0;
                        Set.RelearnMove2 = 0;
                        Set.RelearnMove3 = 0;
                        Set.RelearnMove4 = 0;
                        if (Set.Version == (int)GameVersion.RD || Set.Version == (int)GameVersion.BU || Set.Version == (int)GameVersion.YW || Set.Version == (int)GameVersion.GN)
                        {
                            Set.Met_Location = 30013;
                            Set.Met_Level    = 100;
                        }
                        if (Set.Version == (int)GameVersion.CXD)
                        {
                            Set.Met_Location = 30001;
                            Set.Met_Level    = 100;
                        }
                        else
                        {
                            clickMetLocationModPKSM(Set);
                        }
                        Set.CurrentHandler = 1;
                        Set.HT_Name        = "Archit";
                        Set.PID            = PKX.GetRandomPID(Set.Species, Set.Gender, Set.Version, Set.Nature, Set.Format, (uint)(Set.AbilityNumber * 0x10001));
                        if (shiny)
                        {
                            Set.SetShinyPID();
                        }
                        if (Set.PID == 0)
                        {
                            Set.PID = PKX.GetRandomPID(Set.Species, Set.Gender, Set.Version, Set.Nature, Set.Format, (uint)(Set.AbilityNumber * 0x10001));
                            if (shiny)
                            {
                                Set.SetShinyPID();
                            }
                        }
                        Set.RefreshAbility(abilitynum);
                        if (Set.GenNumber < 6)
                        {
                            Set.EncryptionConstant = Set.PID;
                        }
                        if (CommonErrorHandling2(Set))
                        {
                            if (shiny)
                            {
                                Set.SetShinyPID();
                            }
                            return(Set);
                        }
                        Set.RefreshAbility(abilitynum);
                        if (Set.GenNumber < 6)
                        {
                            Set.EncryptionConstant = Set.PID;
                        }

                        if (new LegalityAnalysis(Set).Valid || Set.Valid)
                        {
                            return(Set);
                        }
                        else
                        {
                            if (debug)
                            {
                                LegalityAnalysis la = new LegalityAnalysis(Set);
                                Console.WriteLine(la.Report(false));
                            }
                        }
                    }
                    catch { continue; }
                }
            }

            return(Set);
        }
예제 #4
0
        /// <summary>
        /// Set IV Values for the pokemon
        /// </summary>
        /// <param name="pk"></param>
        /// <param name="set"></param>
        /// <param name="method"></param>
        /// <param name="hpType"></param>
        /// <param name="original"></param>
        private static void SetIVsPID(this PKM pk, ShowdownSet set, PIDType method, int hpType, PKM original)
        {
            // Useful Values for computation
            int Species       = pk.Species;
            int Nature        = pk.Nature;
            int Gender        = pk.Gender;
            int AbilityNumber = pk.AbilityNumber; // 1,2,4 (HA)

            // Find the encounter
            var li = EncounterFinder.FindVerifiedEncounter(original);

            // TODO: Something about the gen 5 events. Maybe check for nature and shiny val and not touch the PID in that case?
            // Also need to figure out hidden power handling in that case.. for PIDType 0 that may isn't even be possible.
            if (li.EncounterMatch is EncounterStatic8N || li.EncounterMatch is EncounterStatic8NC || li.EncounterMatch is EncounterStatic8ND)
            {
                pk.IVs = set.IVs;
                var e = (EncounterStatic)li.EncounterMatch;
                if (AbilityNumber == 4 && (e.Ability == 0 || e.Ability == 1 || e.Ability == 2))
                {
                    return;
                }

                var pk8 = (PK8)pk;
                switch (e)
                {
                case EncounterStatic8NC c: FindNestPIDIV(pk8, c, set.Shiny); break;

                case EncounterStatic8ND c: FindNestPIDIV(pk8, c, set.Shiny); break;

                case EncounterStatic8N c: FindNestPIDIV(pk8, c, set.Shiny); break;
                }
            }
            else if (pk.GenNumber > 4 || pk.VC)
            {
                pk.IVs = set.IVs;
                if (Species == 658 && pk.AltForm == 1)
                {
                    pk.IVs = new[] { 20, 31, 20, 31, 31, 20 }
                }
                ;
                if (method != PIDType.G5MGShiny)
                {
                    pk.PID = PKX.GetRandomPID(Util.Rand, Species, Gender, pk.Version, Nature, pk.Format, pk.PID);
                    if (li.Generation != 5)
                    {
                        return;
                    }

                    while (true)
                    {
                        if (li.EncounterMatch is EncounterStatic s && (s.Gift || s.Roaming || s.Ability != 4 || s.Location == 75))
                        {
                            break;
                        }
                        if (pk is PK5 p && p.NPokémon)
                        {
                            break;
                        }
                        var result = (pk.PID & 1) ^ (pk.PID >> 31) ^ (pk.TID & 1) ^ (pk.SID & 1);
                        if (result == 0)
                        {
                            break;
                        }
                        pk.PID = PKX.GetRandomPID(Util.Rand, Species, Gender, pk.Version, Nature, pk.Format, pk.PID);
                    }
                }
            }
            else
            {
                pk.IVs = set.IVs;
                if (li.EncounterMatch is PCD d)
                {
                    if (d.Gift.PK.PID != 1)
                    {
                        pk.PID = d.Gift.PK.PID;
                    }
                    else if (pk.Nature != pk.PID % 25)
                    {
                        pk.SetPIDNature(Nature);
                    }
                    return;
                }
                if (li.EncounterMatch is EncounterEgg)
                {
                    pk.SetPIDNature(Nature);
                    return;
                }
                FindPIDIV(pk, method, hpType, set.Shiny);
                ValidateGender(pk);
            }
        }
예제 #5
0
        public SAV_Trainer(Form1 frm1)
        {
            InitializeComponent();

            try { TB_OTName.Font = PKX.getPKXFont(11); }
            catch (Exception e) { Util.Alert("Font loading failed...", e.ToString()); }

            Util.TranslateInterface(this, Form1.curlanguage);
            m_parent = frm1;
            Array.Copy(m_parent.savefile, sav, 0x100000);
            savindex = m_parent.savindex;
            savshift = savindex * 0x7F000;
            if (m_parent.savegame_oras)
            {
                psssatoffset                = 0x24800; Maison += 0xA00; VivillonForm = 0x9644;
                this.Width                  = (int)((float)Width * (float)428 / (float)590);
                CB_Multi.Enabled            = true;
                L_MultiplayerSprite.Enabled = true; // Multiplayer Sprite Label

                L_Style.Visible   = false;          // Style Label
                TB_Style.Visible  = false;
                GB_Appear.Visible = false;
            }
            editing = true;
            getComboBoxes();
            getTextBoxes();
            getBadges();

            statdata = new string[] {
                "0x000", "0x000",        // Steps taken?
                "0x004", "0x004",        // Minutes Played / Pokemon Encountered?
                "0x008", "0x008",
                "0x00C", "0x00C",
                "0x010", "0x010",
                "0x014", "0x014",
                "0x018", "0x018",
                "0x01C", "PKMN Captured",
                "0x020", "0x020",
                "0x024", "Eggs Hatched",
                "0x028", "PKMN Evolved",
                "0x02C", "0x02C",
                "0x030", "~People Passed",
                "0x034", "0x034",
                "0x038", "0x038",
                "0x03C", "0x03C",
                "0x040", "0x040",
                "0x044", "0x044",
                "0x048", "0x048",
                "0x04C", "0x04C",
                "0x050", "0x050",
                "0x054", "0x054",
                "0x058", "0x058",
                "0x05C", "0x05C",
                "0x060", "0x060",
                "0x064", "0x064",
                "0x068", "0x068",
                "0x06C", "0x06C",
                "0x070", "0x070",
                "0x074", "0x074",
                "0x078", "0x078",
                "0x07C", "0x07C",
                "0x080", "0x080",
                "0x084", "0x084",
                "0x088", "0x088",
                "0x08C", "0x08C",
                "0x090", "0x090",
                "0x094", "0x094",
                "0x098", "0x098",
                "0x09C", "0x09C",
                "0x0A0", "0x0A0",
                "0x0A4", "0x0A4",
                "0x0A8", "0x0A8",
                "0x0AC", "0x0AC",
                "0x0B0", "0x0B0",
                "0x0B4", "0x0B4",
                "0x0B8", "0x0B8",
                "0x0BC", "0x0BC",
                "0x0C0", "0x0C0",
                "0x0C4", "0x0C4",
                "0x0C8", "0x0C8",
                "0x0CC", "0x0CC",
                "0x0D0", "0x0D0",
                "0x0D4", "0x0D4",
                "0x0D8", "0x0D8",
                "0x0DC", "0x0DC",
                "0x0E0", "0x0E0",
                "0x0E4", "0x0E4",
                "0x0E8", "0x0E8",
                "0x0EC", "Nice! Received",
                "0x0F0", "0x0F0",
                "0x0F4", "Total People Met Online",
                "0x0F8", "0x0F8",
                "0x0FC", "Current Pokemiles",
                "0x100", "Obtained Pokemiles",
                "0x104", "0x104",
                "0x108", "0x108",
                "0x10C", "Super Training Clears",
                "0x110", "Times Judged",
                "0x114", "0x114",
                "0x118", "0x118",        // Link Trades?
                "0x11C", "Link Battle",  // Wins", // ?
                "0x120", "0x120",        // Link Battle Losses?
                "0x124", "0x124",
                "0x128", "0x128",
                "0x12C", "0x12C",
                "0x130", "0x130",
                "0x134", "0x134",
                "0x138", "0x138",
                "0x13C", "0x13C",
                "0x140", "Flags Captured",
                "0x144", "0x144",
                "0x148", "0x148",
                "0x14C", "0x14C",
                "0x150", "0x150",
                "0x154", "0x154",
                "0x158", "0x158",
                "0x15C", "0x15C",
                "0x160", "0x160",
                "0x164", "0x164",
                "0x168", "0x168",
                "0x16C", "0x16C",
                "0x170", "0x170",
                "0x174", "0x174",
                "0x178", "0x178",
                "0x17C", "0x17C",
                "0x180", "0x180",
                "0x184", "0x184",
                "0x188", "0x188",
                "0x18C", "0x18C",
                "0x190", "0x190",
                "0x194", "0x194",
                "0x198", "0x198",
                "0x19C", "0x19C",
                "0x1A0", "0x1A0",
                "0x1A4", "0x1A4",
                "0x1A8", "0x1A8",
                "0x1AC", "0x1AC",
                "0x1B0", "0x1B0",
                "0x1B4", "0x1B4",
                "0x1B8", "0x1B8",
                "0x1BC", "Battle Tests",
                "0x1C0", "0x1C0",
                "0x1C4", "0x1C4",
                "0x1C8", "0x1C8",
                "0x1CC", "0x1CC",
                "0x1D0", "0x1D0",
                "0x1D4", "0x1D4",
                "0x1D8", "0x1D8",
                "0x1DC", "0x1DC",
                "0x1E0", "0x1E0",
                "0x1E4", "0x1E4",
                "0x1E8", "0x1E8",
                "0x1EC", "0x1EC",
                "0x1F0", "0x1F0",
                "0x1F4", "0x1F4",
                "0x1F8", "0x1F8",
                "0x1FC", "0x1FC",
                "0x200", "0x200",
                "0x204", "0x204",
                "0x208", "0x208",
                "0x20C", "0x20C",
                "0x210", "0x210",
                "0x214", "0x214",
                "0x218", "0x218",
                "0x21C", "0x21C",
                "0x220", "0x220",
                "0x224", "0x224",
                "0x228", "0x228",
                "0x22C", "0x22C",
                "0x230", "0x230",
                "0x234", "0x234",
                "0x238", "0x238",
                "0x23C", "0x23C",
                "0x240", "0x240",
                "0x244", "0x244",
                "0x248", "0x248",
                "0x24C", "0x24C",
                "0x250", "0x250",
                "0x254", "0x254",
                "0x258", "0x258",
            }; // Offset, Title. Horrible implementation, but works.

            CB_Stats.Items.Clear();
            for (int i = 0; i < statdata.Length / 2; i++)
            {
                CB_Stats.Items.Add(statdata[2 * i + 1]);
            }
            CB_Stats.SelectedIndex = 0;
        }
예제 #6
0
 private void SaveHandlingTrainer(PKM pk)
 {
     pk.HT_Name   = TB_OTt2.Text;
     pk.HT_Gender = PKX.GetGenderFromString(Label_CTGender.Text) & 1;
 }
예제 #7
0
 public override byte[] decryptPKM(byte[] data)
 {
     return(PKX.decryptArray45(data));
 }
예제 #8
0
파일: MainPK7.cs 프로젝트: zsw12abc/PKHeX
        private void populateFieldsPK7()
        {
            PK7 pk7 = pkm as PK7;

            if (pk7 == null)
            {
                return;
            }

            // Do first
            pk7.Stat_Level = PKX.getLevel(pk7.Species, pk7.EXP);
            if (pk7.Stat_Level == 100)
            {
                pk7.EXP = PKX.getEXP(pk7.Stat_Level, pk7.Species);
            }

            CB_Species.SelectedValue = pk7.Species;
            TB_Level.Text            = pk7.Stat_Level.ToString();
            TB_EXP.Text = pk7.EXP.ToString();

            // Load rest
            TB_EC.Text                = pk7.EncryptionConstant.ToString("X8");
            CHK_Fateful.Checked       = pk7.FatefulEncounter;
            CHK_IsEgg.Checked         = pk7.IsEgg;
            CHK_Nicknamed.Checked     = pk7.IsNicknamed;
            Label_OTGender.Text       = gendersymbols[pk7.OT_Gender];
            Label_OTGender.ForeColor  = pk7.OT_Gender == 1 ? Color.Red : Color.Blue;
            TB_PID.Text               = pk7.PID.ToString("X8");
            CB_HeldItem.SelectedValue = pk7.HeldItem;
            TB_AbilityNumber.Text     = pk7.AbilityNumber.ToString();
            CB_Ability.SelectedIndex  = pk7.AbilityNumber < 6 ? pk7.AbilityNumber >> 1 : 0; // with some simple error handling
            CB_Nature.SelectedValue   = pk7.Nature;
            TB_TID.Text               = pk7.TID.ToString("00000");
            TB_SID.Text               = pk7.SID.ToString("00000");
            TB_Nickname.Text          = pk7.Nickname;
            TB_OT.Text                = pk7.OT_Name;
            TB_OTt2.Text              = pk7.HT_Name;
            TB_Friendship.Text        = pk7.CurrentFriendship.ToString();
            if (pk7.CurrentHandler == 1)  // HT
            {
                GB_nOT.BackgroundImage = mixedHighlight;
                GB_OT.BackgroundImage  = null;
            }
            else                  // = 0
            {
                GB_OT.BackgroundImage  = mixedHighlight;
                GB_nOT.BackgroundImage = null;
            }
            CB_Language.SelectedValue      = pk7.Language;
            CB_Country.SelectedValue       = pk7.Country;
            CB_SubRegion.SelectedValue     = pk7.Region;
            CB_3DSReg.SelectedValue        = pk7.ConsoleRegion;
            CB_GameOrigin.SelectedValue    = pk7.Version;
            CB_EncounterType.SelectedValue = pk7.Gen4 ? pk7.EncounterType : 0;
            CB_Ball.SelectedValue          = pk7.Ball;

            if (pk7.MetDate.HasValue)
            {
                CAL_MetDate.Value = pk7.MetDate.Value;
            }
            else
            {
                CAL_MetDate.Value = new DateTime(2000, 1, 1);
            }

            if (pk7.Egg_Location != 0)
            {
                // Was obtained initially as an egg.
                CHK_AsEgg.Checked        = true;
                GB_EggConditions.Enabled = true;

                CB_EggLocation.SelectedValue = pk7.Egg_Location;
                if (pk7.EggMetDate.HasValue)
                {
                    CAL_EggDate.Value = pk7.EggMetDate.Value;
                }
                else
                {
                    CAL_EggDate.Value = new DateTime(2000, 1, 1);
                }
            }
            else
            {
                CAL_EggDate.Value = new DateTime(2000, 01, 01); CHK_AsEgg.Checked = GB_EggConditions.Enabled = false; CB_EggLocation.SelectedValue = 0;
            }

            CB_MetLocation.SelectedValue = pk7.Met_Location;

            // Set CT Gender to None if no CT, else set to gender symbol.
            Label_CTGender.Text      = pk7.HT_Name == "" ? "" : gendersymbols[pk7.HT_Gender % 2];
            Label_CTGender.ForeColor = pk7.HT_Gender == 1 ? Color.Red : Color.Blue;

            TB_MetLevel.Text = pk7.Met_Level.ToString();

            // Reset Label and ComboBox visibility, as well as non-data checked status.
            Label_PKRS.Visible     = CB_PKRSStrain.Visible = CHK_Infected.Checked = pk7.PKRS_Strain != 0;
            Label_PKRSdays.Visible = CB_PKRSDays.Visible = pk7.PKRS_Days != 0;

            // Set SelectedIndexes for PKRS
            CB_PKRSStrain.SelectedIndex = pk7.PKRS_Strain;
            CHK_Cured.Checked           = pk7.PKRS_Strain > 0 && pk7.PKRS_Days == 0;
            CB_PKRSDays.SelectedIndex   = Math.Min(CB_PKRSDays.Items.Count - 1, pk7.PKRS_Days); // to strip out bad hacked 'rus

            TB_Cool.Text   = pk7.CNT_Cool.ToString();
            TB_Beauty.Text = pk7.CNT_Beauty.ToString();
            TB_Cute.Text   = pk7.CNT_Cute.ToString();
            TB_Smart.Text  = pk7.CNT_Smart.ToString();
            TB_Tough.Text  = pk7.CNT_Tough.ToString();
            TB_Sheen.Text  = pk7.CNT_Sheen.ToString();

            TB_HPIV.Text            = pk7.IV_HP.ToString();
            TB_ATKIV.Text           = pk7.IV_ATK.ToString();
            TB_DEFIV.Text           = pk7.IV_DEF.ToString();
            TB_SPEIV.Text           = pk7.IV_SPE.ToString();
            TB_SPAIV.Text           = pk7.IV_SPA.ToString();
            TB_SPDIV.Text           = pk7.IV_SPD.ToString();
            CB_HPType.SelectedValue = pk7.HPType;

            TB_HPEV.Text  = pk7.EV_HP.ToString();
            TB_ATKEV.Text = pk7.EV_ATK.ToString();
            TB_DEFEV.Text = pk7.EV_DEF.ToString();
            TB_SPEEV.Text = pk7.EV_SPE.ToString();
            TB_SPAEV.Text = pk7.EV_SPA.ToString();
            TB_SPDEV.Text = pk7.EV_SPD.ToString();

            CB_Move1.SelectedValue        = pk7.Move1;
            CB_Move2.SelectedValue        = pk7.Move2;
            CB_Move3.SelectedValue        = pk7.Move3;
            CB_Move4.SelectedValue        = pk7.Move4;
            CB_RelearnMove1.SelectedValue = pk7.RelearnMove1;
            CB_RelearnMove2.SelectedValue = pk7.RelearnMove2;
            CB_RelearnMove3.SelectedValue = pk7.RelearnMove3;
            CB_RelearnMove4.SelectedValue = pk7.RelearnMove4;
            CB_PPu1.SelectedIndex         = pk7.Move1_PPUps;
            CB_PPu2.SelectedIndex         = pk7.Move2_PPUps;
            CB_PPu3.SelectedIndex         = pk7.Move3_PPUps;
            CB_PPu4.SelectedIndex         = pk7.Move4_PPUps;
            TB_PP1.Text = pk7.Move1_PP.ToString();
            TB_PP2.Text = pk7.Move2_PP.ToString();
            TB_PP3.Text = pk7.Move3_PP.ToString();
            TB_PP4.Text = pk7.Move4_PP.ToString();

            // Set Form if count is enough, else cap.
            CB_Form.SelectedIndex = CB_Form.Items.Count > pk7.AltForm ? pk7.AltForm : CB_Form.Items.Count - 1;

            // Load Extrabyte Value
            TB_ExtraByte.Text = pk7.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString();

            updateStats();

            TB_EXP.Text            = pk7.EXP.ToString();
            Label_Gender.Text      = gendersymbols[pk7.Gender];
            Label_Gender.ForeColor = pk7.Gender == 2 ? Label_Species.ForeColor : (pk7.Gender == 1 ? Color.Red : Color.Blue);

            // Highlight the Current Handler
            clickGT(pk7.CurrentHandler == 1 ? GB_nOT : GB_OT, null);

            if (HaX)
            {
                DEV_Ability.SelectedValue = pk7.Ability;
            }
        }
예제 #9
0
        private void pbBoxSlot_DragDrop(object sender, DragEventArgs e)
        {
            DragInfo.slotDestination           = this;
            DragInfo.slotDestinationSlotNumber = getSlot(sender);
            DragInfo.slotDestinationOffset     = getPKXOffset(DragInfo.slotDestinationSlotNumber);
            DragInfo.slotDestinationBoxNumber  = CB_BoxSelect.SelectedIndex;

            // Check for In-Dropped files (PKX,SAV,ETC)
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (Directory.Exists(files[0]))
            {
                return;
            }
            if (DragInfo.slotSourceOffset < 0) // file
            {
                if (files.Length <= 0)
                {
                    return;
                }
                string   file = files[0];
                FileInfo fi   = new FileInfo(file);
                if (!PKX.getIsPKM(fi.Length) && !MysteryGift.getIsMysteryGift(fi.Length))
                {
                    return;
                }

                byte[]      data = File.ReadAllBytes(file);
                MysteryGift mg   = MysteryGift.getMysteryGift(data, fi.Extension);
                PKM         temp = mg != null?mg.convertToPKM(SAV) : PKMConverter.getPKMfromBytes(data);

                string c;

                PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c);
                if (pk == null)
                {
                    Util.Error(c); Console.WriteLine(c); return;
                }

                string[] errata = verifyPKMtoSAV(pk);
                if (errata.Length > 0)
                {
                    string concat = string.Join(Environment.NewLine, errata);
                    if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, concat, "Continue?"))
                    {
                        Console.WriteLine(c); Console.WriteLine(concat); return;
                    }
                }

                SAV.setStoredSlot(pk, DragInfo.slotDestinationOffset);
                getQuickFiller(SlotPictureBoxes[DragInfo.slotDestinationSlotNumber], pk);
                Console.WriteLine(c);
            }
            else
            {
                PKM pkz = SAV.getStoredSlot(DragInfo.slotSourceOffset);
                if (!DragInfo.SourceValid)
                {
                }                                                               // not overwritable, do nothing
                else if (ModifierKeys == Keys.Alt && DragInfo.DestinationValid) // overwrite
                {
                    // Clear from slot
                    if (DragInfo.SameBox)
                    {
                        getQuickFiller(SlotPictureBoxes[DragInfo.slotSourceSlotNumber], SAV.BlankPKM); // picturebox
                    }
                    SAV.setStoredSlot(SAV.BlankPKM, DragInfo.slotSourceOffset);
                }
                else if (ModifierKeys != Keys.Control && DragInfo.DestinationValid) // move
                {
                    // Load data from destination
                    PKM pk = ((PictureBox)sender).Image != null
                        ? SAV.getStoredSlot(DragInfo.slotDestinationOffset)
                        : SAV.BlankPKM;

                    // Set destination pokemon image to source picture box
                    if (DragInfo.SameBox)
                    {
                        getQuickFiller(SlotPictureBoxes[DragInfo.slotSourceSlotNumber], pk);
                    }

                    // Set destination pokemon data to source slot
                    SAV.setStoredSlot(pk, DragInfo.slotSourceOffset);
                }
                else if (DragInfo.SameBox) // clone
                {
                    getQuickFiller(SlotPictureBoxes[DragInfo.slotSourceSlotNumber], pkz);
                }

                // Copy from temp to destination slot.
                SAV.setStoredSlot(pkz, DragInfo.slotDestinationOffset);
                getQuickFiller(SlotPictureBoxes[DragInfo.slotDestinationSlotNumber], pkz);

                e.Effect = DragDropEffects.Link;
                Cursor   = DefaultCursor;
            }
            if (DragInfo.slotSource == null) // another instance or file
            {
                parent.notifyBoxViewerRefresh();
                DragInfo.Reset();
            }
        }
예제 #10
0
        private void getEntry()
        {
            // Load Bools for the data
            int pk = species;

            L_Spinda.Visible = TB_Spinda.Visible = pk == 327;

            // Load Partitions
            for (int i = 0; i < 9; i++)
            {
                CP[i].Checked = specbools[i, pk - 1];
            }
            for (int i = 0; i < 7; i++)
            {
                CL[i].Checked = langbools[i, pk - 1];
            }

            if (pk < 650)
            {
                CHK_F1.Enabled = true; CHK_F1.Checked = foreignbools[pk - 1];
            }
            else
            {
                CHK_F1.Enabled = CHK_F1.Checked = false;
            }

            int gt = SAV.Personal[pk].Gender;

            CHK_P2.Enabled = CHK_P4.Enabled = CHK_P6.Enabled = CHK_P8.Enabled = gt != 254;                 // Not Female-Only
            CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = !(gt == 0 || (gt == 255)); // Not Male-Only and Not Genderless

            CLB_FormsSeen.Items.Clear();
            CLB_FormDisplayed.Items.Clear();

            int fc = SAV.Personal[species].FormeCount;
            int f  = SaveUtil.getDexFormIndexXY(species, fc);

            if (f < 0)
            {
                return;
            }
            string[] forms = PKX.getFormList(species, Main.GameStrings.types, Main.GameStrings.forms, Main.gendersymbols);
            if (forms.Length < 1)
            {
                return;
            }

            // 0x26 packs of bools
            for (int i = 0; i < forms.Length; i++) // Seen
            {
                CLB_FormsSeen.Items.Add(forms[i], formbools[f + i + 0 * FormLen * 8]);
            }
            for (int i = 0; i < forms.Length; i++) // Seen Shiny
            {
                CLB_FormsSeen.Items.Add("* " + forms[i], formbools[f + i + 1 * FormLen * 8]);
            }

            for (int i = 0; i < forms.Length; i++) // Displayed
            {
                CLB_FormDisplayed.Items.Add(forms[i], formbools[f + i + 2 * FormLen * 8]);
            }
            for (int i = 0; i < forms.Length; i++) // Displayed Shiny
            {
                CLB_FormDisplayed.Items.Add("* " + forms[i], formbools[f + i + 3 * FormLen * 8]);
            }
        }
예제 #11
0
파일: MainPK7.cs 프로젝트: zsw12abc/PKHeX
        private PKM preparePK7()
        {
            PK7 pk7 = pkm as PK7;

            if (pk7 == null)
            {
                return(null);
            }

            // Repopulate PK6 with Edited Stuff
            if (Util.getIndex(CB_GameOrigin) < 24)
            {
                uint EC  = Util.getHEXval(TB_EC.Text);
                uint PID = Util.getHEXval(TB_PID.Text);
                uint SID = Util.ToUInt32(TB_TID.Text);
                uint TID = Util.ToUInt32(TB_TID.Text);
                uint LID = PID & 0xFFFF;
                uint HID = PID >> 16;
                uint XOR = TID ^ LID ^ SID ^ HID;

                // Ensure we don't have a shiny.
                if (XOR >> 3 == 1) // Illegal, fix. (not 16<XOR>=8)
                {
                    // Keep as shiny, so we have to mod the PID
                    PID        ^= XOR;
                    TB_PID.Text = PID.ToString("X8");
                    TB_EC.Text  = PID.ToString("X8");
                }
                else if ((XOR ^ 0x8000) >> 3 == 1 && PID != EC)
                {
                    TB_EC.Text = (PID ^ 0x80000000).ToString("X8");
                }
                else // Not Illegal, no fix.
                {
                    TB_EC.Text = PID.ToString("X8");
                }
            }

            pk7.EncryptionConstant = Util.getHEXval(TB_EC.Text);
            pk7.Checksum           = 0; // 0 CHK for now

            // Block A
            pk7.Species       = Util.getIndex(CB_Species);
            pk7.HeldItem      = Util.getIndex(CB_HeldItem);
            pk7.TID           = Util.ToInt32(TB_TID.Text);
            pk7.SID           = Util.ToInt32(TB_SID.Text);
            pk7.EXP           = Util.ToUInt32(TB_EXP.Text);
            pk7.Ability       = (byte)Array.IndexOf(GameStrings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4));
            pk7.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text);   // Number
            // pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag)
            pk7.PID              = Util.getHEXval(TB_PID.Text);
            pk7.Nature           = (byte)Util.getIndex(CB_Nature);
            pk7.FatefulEncounter = CHK_Fateful.Checked;
            pk7.Gender           = PKX.getGender(Label_Gender.Text);
            pk7.AltForm          = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F;
            pk7.EV_HP            = Util.ToInt32(TB_HPEV.Text); // EVs
            pk7.EV_ATK           = Util.ToInt32(TB_ATKEV.Text);
            pk7.EV_DEF           = Util.ToInt32(TB_DEFEV.Text);
            pk7.EV_SPE           = Util.ToInt32(TB_SPEEV.Text);
            pk7.EV_SPA           = Util.ToInt32(TB_SPAEV.Text);
            pk7.EV_SPD           = Util.ToInt32(TB_SPDEV.Text);

            pk7.CNT_Cool   = Util.ToInt32(TB_Cool.Text);     // CNT
            pk7.CNT_Beauty = Util.ToInt32(TB_Beauty.Text);
            pk7.CNT_Cute   = Util.ToInt32(TB_Cute.Text);
            pk7.CNT_Smart  = Util.ToInt32(TB_Smart.Text);
            pk7.CNT_Tough  = Util.ToInt32(TB_Tough.Text);
            pk7.CNT_Sheen  = Util.ToInt32(TB_Sheen.Text);

            pk7.PKRS_Days   = CB_PKRSDays.SelectedIndex;
            pk7.PKRS_Strain = CB_PKRSStrain.SelectedIndex;
            // Already in buff (then transferred to new pkx)
            // 0x2C, 0x2D, 0x2E, 0x2F
            // 0x30, 0x31, 0x32, 0x33
            // 0x34, 0x35, 0x36, 0x37
            // 0x38, 0x39

            // Unused
            // 0x3A, 0x3B
            // 0x3C, 0x3D, 0x3E, 0x3F

            // Block B
            // Convert Nickname field back to bytes
            pk7.Nickname     = TB_Nickname.Text;
            pk7.Move1        = Util.getIndex(CB_Move1);
            pk7.Move2        = Util.getIndex(CB_Move2);
            pk7.Move3        = Util.getIndex(CB_Move3);
            pk7.Move4        = Util.getIndex(CB_Move4);
            pk7.Move1_PP     = Util.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            pk7.Move2_PP     = Util.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            pk7.Move3_PP     = Util.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            pk7.Move4_PP     = Util.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            pk7.Move1_PPUps  = Util.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            pk7.Move2_PPUps  = Util.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            pk7.Move3_PPUps  = Util.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            pk7.Move4_PPUps  = Util.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;
            pk7.RelearnMove1 = Util.getIndex(CB_RelearnMove1);
            pk7.RelearnMove2 = Util.getIndex(CB_RelearnMove2);
            pk7.RelearnMove3 = Util.getIndex(CB_RelearnMove3);
            pk7.RelearnMove4 = Util.getIndex(CB_RelearnMove4);
            // 0x72 - Ribbon editor sets this flag (Secret Super Training)
            // 0x73
            pk7.IV_HP       = Util.ToInt32(TB_HPIV.Text);
            pk7.IV_ATK      = Util.ToInt32(TB_ATKIV.Text);
            pk7.IV_DEF      = Util.ToInt32(TB_DEFIV.Text);
            pk7.IV_SPE      = Util.ToInt32(TB_SPEIV.Text);
            pk7.IV_SPA      = Util.ToInt32(TB_SPAIV.Text);
            pk7.IV_SPD      = Util.ToInt32(TB_SPDIV.Text);
            pk7.IsEgg       = CHK_IsEgg.Checked;
            pk7.IsNicknamed = CHK_Nicknamed.Checked;

            // Block C
            pk7.HT_Name = TB_OTt2.Text;

            // 0x90-0xAF
            pk7.HT_Gender = PKX.getGender(Label_CTGender.Text);
            // Plus more, set by MemoryAmie (already in buff)

            // Block D
            pk7.OT_Name           = TB_OT.Text;
            pk7.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);

            DateTime?egg_date     = null;
            int      egg_location = 0;

            if (CHK_AsEgg.Checked)      // If encountered as an egg, load the Egg Met data from fields.
            {
                egg_date     = CAL_EggDate.Value;
                egg_location = Util.getIndex(CB_EggLocation);
            }
            // Egg Met Data
            pk7.EggMetDate   = egg_date;
            pk7.Egg_Location = egg_location;
            // Met Data
            pk7.MetDate      = CAL_MetDate.Value;
            pk7.Met_Location = Util.getIndex(CB_MetLocation);

            if (pk7.IsEgg && pk7.Met_Location == 0)    // If still an egg, it has no hatch location/date. Zero it!
            {
                pk7.MetDate = null;
            }

            // 0xD7 Unknown

            pk7.Ball          = Util.getIndex(CB_Ball);
            pk7.Met_Level     = Util.ToInt32(TB_MetLevel.Text);
            pk7.OT_Gender     = PKX.getGender(Label_OTGender.Text);
            pk7.EncounterType = Util.getIndex(CB_EncounterType);
            pk7.Version       = Util.getIndex(CB_GameOrigin);
            pk7.Country       = Util.getIndex(CB_Country);
            pk7.Region        = Util.getIndex(CB_SubRegion);
            pk7.ConsoleRegion = Util.getIndex(CB_3DSReg);
            pk7.Language      = Util.getIndex(CB_Language);
            // 0xE4-0xE7

            // Toss in Party Stats
            Array.Resize(ref pk7.Data, pk7.SIZE_PARTY);
            pk7.Stat_Level     = Util.ToInt32(TB_Level.Text);
            pk7.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            pk7.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            pk7.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            pk7.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            pk7.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            pk7.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            pk7.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            // Unneeded Party Stats (Status, Flags, Unused)
            pk7.Data[0xE8]              = pk7.Data[0xE9] = pk7.Data[0xEA] = pk7.Data[0xEB] =
                pk7.Data[0xED]          = pk7.Data[0xEE] = pk7.Data[0xEF] =
                    pk7.Data[0xFE]      = pk7.Data[0xFF] = pk7.Data[0x100] =
                        pk7.Data[0x101] = pk7.Data[0x102] = pk7.Data[0x103] = 0;

            // Hax Illegality
            if (HaX)
            {
                pk7.Ability    = (byte)Util.getIndex(DEV_Ability);
                pk7.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }

            // Fix Moves if a slot is empty
            pk7.FixMoves();
            pk7.FixRelearn();

            // Fix Handler (Memories & OT) -- no foreign memories for Pokemon without a foreign trainer (none for eggs)
            if (Menu_ModifyPKM.Checked)
            {
                pk7.FixMemories();
            }

            // PKX is now filled
            pk7.RefreshChecksum();
            return(pk7);
        }
예제 #12
0
        public SAV_Database(Main f1)
        {
            m_parent = f1;
            InitializeComponent();

            // Preset Filters to only show PKM available for loaded save
            CB_FormatComparator.SelectedIndex = 3; // <=

            PKXBOXES = new[]
            {
                bpkx1, bpkx2, bpkx3, bpkx4, bpkx5, bpkx6,
                bpkx7, bpkx8, bpkx9, bpkx10, bpkx11, bpkx12,
                bpkx13, bpkx14, bpkx15, bpkx16, bpkx17, bpkx18,
                bpkx19, bpkx20, bpkx21, bpkx22, bpkx23, bpkx24,
                bpkx25, bpkx26, bpkx27, bpkx28, bpkx29, bpkx30,

                bpkx31, bpkx32, bpkx33, bpkx34, bpkx35, bpkx36,
                bpkx37, bpkx38, bpkx39, bpkx40, bpkx41, bpkx42,
                bpkx43, bpkx44, bpkx45, bpkx46, bpkx47, bpkx48,
                bpkx49, bpkx50, bpkx51, bpkx52, bpkx53, bpkx54,
                bpkx55, bpkx56, bpkx57, bpkx58, bpkx59, bpkx60,
                bpkx61, bpkx62, bpkx63, bpkx64, bpkx65, bpkx66,
            };

            // Enable Scrolling when hovered over
            PAN_Box.MouseHover += (sender, args) =>
            {
                if (ActiveForm == this)
                {
                    SCR_Box.Focus();
                }
            };
            foreach (var slot in PKXBOXES)
            {
                slot.MouseEnter += (sender, args) =>
                {
                    if (ActiveForm == this)
                    {
                        SCR_Box.Focus();
                    }
                };
                // Enable Click
                slot.MouseClick += (sender, args) =>
                {
                    if (ModifierKeys == Keys.Control)
                    {
                        clickView(sender, args);
                    }
                    else if (ModifierKeys == Keys.Alt)
                    {
                        clickDelete(sender, args);
                    }
                    else if (ModifierKeys == Keys.Shift)
                    {
                        clickSet(sender, args);
                    }
                };
            }

            Counter       = L_Count.Text;
            Viewed        = L_Viewed.Text;
            L_Viewed.Text = ""; // invis for now
            populateComboBoxes();

            ContextMenuStrip  mnu       = new ContextMenuStrip();
            ToolStripMenuItem mnuView   = new ToolStripMenuItem("View");
            ToolStripMenuItem mnuDelete = new ToolStripMenuItem("Delete");

            // Assign event handlers
            mnuView.Click   += clickView;
            mnuDelete.Click += clickDelete;

            // Add to main context menu
            mnu.Items.AddRange(new ToolStripItem[] { mnuView, mnuDelete });

            // Assign to datagridview
            foreach (PictureBox p in PKXBOXES)
            {
                p.ContextMenuStrip = mnu;
            }

            // Load Data
            RawDB = new List <PKM>();
            foreach (string file in Directory.GetFiles(DatabasePath, "*", SearchOption.AllDirectories))
            {
                FileInfo fi = new FileInfo(file);
                if (fi.Extension.Contains(".pk") && PKX.getIsPKM(fi.Length))
                {
                    RawDB.Add(PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file));
                }
            }
            // Fetch from save file
            foreach (var pkm in Main.SAV.BoxData.Where(pk => pk.Species != 0))
            {
                RawDB.Add(pkm);
            }

            // Prepare Database
            RawDB = new List <PKM>(RawDB.Where(pk => pk.ChecksumValid && pk.Species != 0 && pk.Sanity == 0));
            RawDB = new List <PKM>(RawDB.Distinct());
            setResults(RawDB);

            Menu_SearchSettings.DropDown.Closing += (sender, e) =>
            {
                if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
                {
                    e.Cancel = true;
                }
            };
            CenterToParent();
        }
예제 #13
0
        private void GetEntry()
        {
            // Load Bools for the data
            int pk = species;

            // Load Partitions
            for (int i = 0; i < 9; i++)
            {
                CP[i].Checked = specbools[i, pk - 1];
            }

            if (species > 493)
            {
                for (int i = 0; i < 7; i++)
                {
                    CL[i].Checked = false;
                }
                GB_Language.Enabled = false;
            }
            else
            {
                for (int i = 0; i < 7; i++)
                {
                    CL[i].Checked = langbools[i, pk - 1];
                }
                GB_Language.Enabled = true;
            }

            int gt = SAV.Personal[pk].Gender;

            CHK_P2.Enabled = CHK_P4.Enabled = CHK_P6.Enabled = CHK_P8.Enabled = gt != 254;                 // Not Female-Only
            CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = !(gt == 0 || (gt == 255)); // Not Male-Only and Not Genderless

            CLB_FormsSeen.Items.Clear();
            CLB_FormDisplayed.Items.Clear();

            int fc = SAV.Personal[species].FormeCount;
            int f  = SAV.B2W2 ? SaveUtil.GetDexFormIndexB2W2(species, fc) : SaveUtil.GetDexFormIndexBW(species, fc);

            if (f < 0)
            {
                return;
            }
            string[] forms = PKX.GetFormList(species, GameInfo.Strings.types, GameInfo.Strings.forms, Main.GenderSymbols, SAV.Generation);
            if (forms.Length < 1)
            {
                return;
            }

            for (int i = 0; i < forms.Length; i++) // Seen
            {
                CLB_FormsSeen.Items.Add(forms[i], formbools[f + i + (0 * FormLen * 8)]);
            }
            for (int i = 0; i < forms.Length; i++) // Seen Shiny
            {
                CLB_FormsSeen.Items.Add($"* {forms[i]}", formbools[f + i + (1 * FormLen * 8)]);
            }

            for (int i = 0; i < forms.Length; i++) // Displayed
            {
                CLB_FormDisplayed.Items.Add(forms[i], formbools[f + i + (2 * FormLen * 8)]);
            }
            for (int i = 0; i < forms.Length; i++) // Displayed Shiny
            {
                CLB_FormDisplayed.Items.Add($"* {forms[i]}", formbools[f + i + (3 * FormLen * 8)]);
            }
        }
예제 #14
0
        private static bool BruteForceEgg(PKM pk, ShowdownSet set, ITrainerInfo trainer, bool shiny)
        {
            foreach (var game in BruteTables.GameVersionList)
            {
                if (pk.DebutGeneration > game.GetGeneration())
                {
                    continue;
                }
                pk.Version = (int)game;
                pk.RestoreIVs(set.IVs); // Restore IVs to template, and HT to false
                pk.Language     = 2;
                pk.OT_Name      = trainer.OT;
                pk.TID          = trainer.TID;
                pk.SID          = trainer.SID;
                pk.OT_Gender    = trainer.Gender;
                pk.MetDate      = DateTime.Today;
                pk.EggMetDate   = DateTime.Today;
                pk.Egg_Location = pk.Version < (int)GameVersion.W ? 2002 : 60002;

                pk.Met_Level     = 1;
                pk.ConsoleRegion = 2;

                if (pk.Version == (int)GameVersion.RD || pk.Version == (int)GameVersion.BU || pk.Version == (int)GameVersion.YW || pk.Version == (int)GameVersion.GN)
                {
                    pk.SID          = 0;
                    pk.Met_Location = 30013;
                    pk.Met_Level    = 100;
                }
                if (pk.Version == (int)GameVersion.CXD)
                {
                    pk.Met_Location = 30001;
                    pk.Met_Level    = 100;
                }
                else
                {
                    try
                    {
                        pk.SetSuggestedMetLocation();
                    }
                    catch { }
                }
                if (pk.GenNumber > 4)
                {
                    pk.Met_Level = 1;
                }

                pk.SetMarkings();
                pk.CurrentHandler = 1;
                pk.HT_Name        = "Archit";
                try
                {
                    pk.SetSuggestedRelearnMoves();
                }
                catch { }
                pk.SetPIDNature(pk.Nature);
                if (shiny)
                {
                    pk.SetShiny();
                }
                if (pk.PID == 0)
                {
                    pk.PID = PKX.GetRandomPID(Util.Rand, pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
                    if (shiny)
                    {
                        pk.SetShiny();
                    }
                }
                pk.SetSuggestedMemories();
                if (pk.GenNumber < 6)
                {
                    pk.EncryptionConstant = pk.PID;
                }
                if (CommonErrorHandling2(pk))
                {
                    pk.HyperTrain();
                    if (shiny && !pk.IsShiny)
                    {
                        pk.SetShiny();
                    }
                    {
                        return(true);
                    }
                }
                pk.HyperTrain();
                bool legalized = new LegalityAnalysis(pk).Valid;
                if (pk.GenNumber < 6 && !legalized)
                {
                    pk.EncryptionConstant = pk.PID;
                }
                if (new LegalityAnalysis(pk).Valid&& pk.Format >= pk.GenNumber)
                {
                    pk.SetHappiness();
                    pk.SetBelugaValues();
                    if (shiny && !pk.IsShiny)
                    {
                        pk.SetShinySID();
                    }
                    {
                        return(true);
                    }
                }
                else
                {
                    var la = new LegalityAnalysis(pk);
                    Debug.WriteLine(la.Report());
                }
            }
            return(false);
        }
예제 #15
0
        private PKM prepareBK4()
        {
            BK4 pk4 = pkm as BK4;

            if (pk4 == null)
            {
                return(null);
            }

            pk4.Species  = WinFormsUtil.getIndex(CB_Species);
            pk4.HeldItem = WinFormsUtil.getIndex(CB_HeldItem);
            pk4.TID      = Util.ToInt32(TB_TID.Text);
            pk4.SID      = Util.ToInt32(TB_SID.Text);
            pk4.EXP      = Util.ToUInt32(TB_EXP.Text);
            pk4.PID      = Util.getHEXval(TB_PID.Text);
            pk4.Ability  = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4));

            pk4.FatefulEncounter = CHK_Fateful.Checked;
            pk4.Gender           = PKX.getGender(Label_Gender.Text);
            pk4.AltForm          = (MT_Form.Enabled ? Convert.ToInt32(MT_Form.Text) : CB_Form.Enabled ? CB_Form.SelectedIndex : 0) & 0x1F;
            pk4.EV_HP            = Util.ToInt32(TB_HPEV.Text);
            pk4.EV_ATK           = Util.ToInt32(TB_ATKEV.Text);
            pk4.EV_DEF           = Util.ToInt32(TB_DEFEV.Text);
            pk4.EV_SPE           = Util.ToInt32(TB_SPEEV.Text);
            pk4.EV_SPA           = Util.ToInt32(TB_SPAEV.Text);
            pk4.EV_SPD           = Util.ToInt32(TB_SPDEV.Text);

            pk4.CNT_Cool   = Util.ToInt32(TB_Cool.Text);
            pk4.CNT_Beauty = Util.ToInt32(TB_Beauty.Text);
            pk4.CNT_Cute   = Util.ToInt32(TB_Cute.Text);
            pk4.CNT_Smart  = Util.ToInt32(TB_Smart.Text);
            pk4.CNT_Tough  = Util.ToInt32(TB_Tough.Text);
            pk4.CNT_Sheen  = Util.ToInt32(TB_Sheen.Text);

            pk4.PKRS_Days   = CB_PKRSDays.SelectedIndex;
            pk4.PKRS_Strain = CB_PKRSStrain.SelectedIndex;
            pk4.Nickname    = TB_Nickname.Text;
            pk4.Move1       = WinFormsUtil.getIndex(CB_Move1);
            pk4.Move2       = WinFormsUtil.getIndex(CB_Move2);
            pk4.Move3       = WinFormsUtil.getIndex(CB_Move3);
            pk4.Move4       = WinFormsUtil.getIndex(CB_Move4);
            pk4.Move1_PP    = WinFormsUtil.getIndex(CB_Move1) > 0 ? Util.ToInt32(TB_PP1.Text) : 0;
            pk4.Move2_PP    = WinFormsUtil.getIndex(CB_Move2) > 0 ? Util.ToInt32(TB_PP2.Text) : 0;
            pk4.Move3_PP    = WinFormsUtil.getIndex(CB_Move3) > 0 ? Util.ToInt32(TB_PP3.Text) : 0;
            pk4.Move4_PP    = WinFormsUtil.getIndex(CB_Move4) > 0 ? Util.ToInt32(TB_PP4.Text) : 0;
            pk4.Move1_PPUps = WinFormsUtil.getIndex(CB_Move1) > 0 ? CB_PPu1.SelectedIndex : 0;
            pk4.Move2_PPUps = WinFormsUtil.getIndex(CB_Move2) > 0 ? CB_PPu2.SelectedIndex : 0;
            pk4.Move3_PPUps = WinFormsUtil.getIndex(CB_Move3) > 0 ? CB_PPu3.SelectedIndex : 0;
            pk4.Move4_PPUps = WinFormsUtil.getIndex(CB_Move4) > 0 ? CB_PPu4.SelectedIndex : 0;

            pk4.IV_HP       = Util.ToInt32(TB_HPIV.Text);
            pk4.IV_ATK      = Util.ToInt32(TB_ATKIV.Text);
            pk4.IV_DEF      = Util.ToInt32(TB_DEFIV.Text);
            pk4.IV_SPE      = Util.ToInt32(TB_SPEIV.Text);
            pk4.IV_SPA      = Util.ToInt32(TB_SPAIV.Text);
            pk4.IV_SPD      = Util.ToInt32(TB_SPDIV.Text);
            pk4.IsEgg       = CHK_IsEgg.Checked;
            pk4.IsNicknamed = CHK_Nicknamed.Checked;

            pk4.OT_Name           = TB_OT.Text;
            pk4.CurrentFriendship = Util.ToInt32(TB_Friendship.Text);

            pk4.Ball          = WinFormsUtil.getIndex(CB_Ball);
            pk4.Met_Level     = Util.ToInt32(TB_MetLevel.Text);
            pk4.OT_Gender     = PKX.getGender(Label_OTGender.Text);
            pk4.EncounterType = WinFormsUtil.getIndex(CB_EncounterType);
            pk4.Version       = WinFormsUtil.getIndex(CB_GameOrigin);
            pk4.Language      = WinFormsUtil.getIndex(CB_Language);

            // Default Dates
            DateTime?egg_date     = null;
            int      egg_location = 0;

            if (CHK_AsEgg.Checked) // If encountered as an egg, load the Egg Met data from fields.
            {
                egg_date     = CAL_EggDate.Value;
                egg_location = WinFormsUtil.getIndex(CB_EggLocation);
            }
            // Egg Met Data
            pk4.EggMetDate   = egg_date;
            pk4.Egg_Location = egg_location;
            // Met Data
            pk4.MetDate      = CAL_MetDate.Value;
            pk4.Met_Location = WinFormsUtil.getIndex(CB_MetLocation);

            if (pk4.IsEgg && pk4.Met_Location == 0)    // If still an egg, it has no hatch location/date. Zero it!
            {
                pk4.MetDate = null;
            }

            // Toss in Party Stats
            Array.Resize(ref pk4.Data, pk4.SIZE_PARTY);
            pk4.Stat_Level     = Util.ToInt32(TB_Level.Text);
            pk4.Stat_HPCurrent = Util.ToInt32(Stat_HP.Text);
            pk4.Stat_HPMax     = Util.ToInt32(Stat_HP.Text);
            pk4.Stat_ATK       = Util.ToInt32(Stat_ATK.Text);
            pk4.Stat_DEF       = Util.ToInt32(Stat_DEF.Text);
            pk4.Stat_SPE       = Util.ToInt32(Stat_SPE.Text);
            pk4.Stat_SPA       = Util.ToInt32(Stat_SPA.Text);
            pk4.Stat_SPD       = Util.ToInt32(Stat_SPD.Text);

            if (HaX)
            {
                pk4.Ability    = (byte)WinFormsUtil.getIndex(DEV_Ability);
                pk4.Stat_Level = (byte)Math.Min(Convert.ToInt32(MT_Level.Text), byte.MaxValue);
            }

            // Fix Moves if a slot is empty
            pk4.FixMoves();

            pk4.RefreshChecksum();
            return(pk4);
        }
예제 #16
0
        private void LoadDatabase()
        {
            var dbTemp = new ConcurrentBag <PKM>();
            var files  = Directory.EnumerateFiles(DatabasePath, "*", SearchOption.AllDirectories);

            Parallel.ForEach(files, file =>
            {
                FileInfo fi = new FileInfo(file);
                if (!fi.Extension.Contains(".pk") || !PKX.IsPKM(fi.Length))
                {
                    return;
                }
                var data   = File.ReadAllBytes(file);
                var prefer = PKX.GetPKMFormatFromExtension(fi.Extension, SAV.Generation);
                var pk     = PKMConverter.GetPKMfromBytes(data, file, prefer);
                if (pk != null)
                {
                    dbTemp.Add(pk);
                }
            });

#if LOADALL
            if (SaveUtil.GetSavesFromFolder(Main.BackupPath, false, out IEnumerable <string> result))
            {
                Parallel.ForEach(result, file =>
                {
                    var sav  = SaveUtil.GetVariantSAV(File.ReadAllBytes(file));
                    var path = EXTERNAL_SAV + new FileInfo(file).Name;
                    if (sav.HasBox)
                    {
                        foreach (var pk in sav.BoxData)
                        {
                            addPKM(pk);
                        }
                    }

                    void addPKM(PKM pk)
                    {
                        pk.Identifier = Path.Combine(path, pk.Identifier);
                        dbTemp.Add(pk);
                    }
                });
            }
#endif

            // Prepare Database
            RawDB = new List <PKM>(dbTemp.OrderBy(pk => pk.Identifier)
                                   .Concat(SAV.BoxData.Where(pk => pk.Species != 0)) // Fetch from save file
                                   .Where(pk => pk.ChecksumValid && pk.Species != 0 && pk.Sanity == 0)
                                   .Distinct());

            // Load stats for pkm who do not have any
            foreach (var pk in RawDB.Where(z => z.Stat_Level == 0))
            {
                pk.Stat_Level = pk.CurrentLevel;
                pk.SetStats(pk.GetStats(pk.PersonalInfo));
            }

            try
            {
                BeginInvoke(new MethodInvoker(() => SetResults(RawDB)));
            }
            catch { /* Window Closed? */ }
        }
예제 #17
0
        // Main Series
        private void populateFieldsPK4()
        {
            PK4 pk4 = pkm as PK4;

            if (pk4 == null)
            {
                return;
            }

            // Do first
            pk4.Stat_Level = PKX.getLevel(pk4.Species, pk4.EXP);
            if (pk4.Stat_Level == 100 && !HaX)
            {
                pk4.EXP = PKX.getEXP(pk4.Stat_Level, pk4.Species);
            }

            CB_Species.SelectedValue = pk4.Species;
            TB_Level.Text            = pk4.Stat_Level.ToString();
            TB_EXP.Text = pk4.EXP.ToString();

            // Load rest
            CHK_Fateful.Checked      = pk4.FatefulEncounter;
            CHK_IsEgg.Checked        = pk4.IsEgg;
            CHK_Nicknamed.Checked    = pk4.IsNicknamed;
            Label_OTGender.Text      = gendersymbols[pk4.OT_Gender];
            Label_OTGender.ForeColor = pk4.OT_Gender == 1 ? Color.Red : Color.Blue;
            TB_PID.Text = pk4.PID.ToString("X8");
            CB_HeldItem.SelectedValue = pk4.HeldItem;
            CB_Nature.SelectedValue   = pk4.Nature;
            TB_TID.Text                    = pk4.TID.ToString("00000");
            TB_SID.Text                    = pk4.SID.ToString("00000");
            TB_Nickname.Text               = pk4.Nickname;
            TB_OT.Text                     = pk4.OT_Name;
            TB_Friendship.Text             = pk4.CurrentFriendship.ToString();
            GB_OT.BackgroundImage          = null;
            CB_Language.SelectedValue      = pk4.Language;
            CB_GameOrigin.SelectedValue    = pk4.Version;
            CB_EncounterType.SelectedValue = pk4.Gen4 ? pk4.EncounterType : 0;
            CB_Ball.SelectedValue          = pk4.Ball;

            CAL_MetDate.Value = pk4.MetDate ?? new DateTime(2000, 1, 1);

            if (pk4.Egg_Location != 0)
            {
                // Was obtained initially as an egg.
                CHK_AsEgg.Checked        = true;
                GB_EggConditions.Enabled = true;

                CB_EggLocation.SelectedValue = pk4.Egg_Location;
                CAL_EggDate.Value            = pk4.EggMetDate ?? new DateTime(2000, 1, 1);
            }
            else
            {
                CAL_EggDate.Value = new DateTime(2000, 01, 01); CHK_AsEgg.Checked = GB_EggConditions.Enabled = false; CB_EggLocation.SelectedValue = 0;
            }

            CB_MetLocation.SelectedValue = pk4.Met_Location;

            TB_MetLevel.Text = pk4.Met_Level.ToString();

            // Reset Label and ComboBox visibility, as well as non-data checked status.
            Label_PKRS.Visible     = CB_PKRSStrain.Visible = CHK_Infected.Checked = pk4.PKRS_Strain != 0;
            Label_PKRSdays.Visible = CB_PKRSDays.Visible = pk4.PKRS_Days != 0;

            // Set SelectedIndexes for PKRS
            CB_PKRSStrain.SelectedIndex = pk4.PKRS_Strain;
            CHK_Cured.Checked           = pk4.PKRS_Strain > 0 && pk4.PKRS_Days == 0;
            CB_PKRSDays.SelectedIndex   = Math.Min(CB_PKRSDays.Items.Count - 1, pk4.PKRS_Days); // to strip out bad hacked 'rus

            TB_Cool.Text   = pk4.CNT_Cool.ToString();
            TB_Beauty.Text = pk4.CNT_Beauty.ToString();
            TB_Cute.Text   = pk4.CNT_Cute.ToString();
            TB_Smart.Text  = pk4.CNT_Smart.ToString();
            TB_Tough.Text  = pk4.CNT_Tough.ToString();
            TB_Sheen.Text  = pk4.CNT_Sheen.ToString();

            TB_HPIV.Text            = pk4.IV_HP.ToString();
            TB_ATKIV.Text           = pk4.IV_ATK.ToString();
            TB_DEFIV.Text           = pk4.IV_DEF.ToString();
            TB_SPEIV.Text           = pk4.IV_SPE.ToString();
            TB_SPAIV.Text           = pk4.IV_SPA.ToString();
            TB_SPDIV.Text           = pk4.IV_SPD.ToString();
            CB_HPType.SelectedValue = pk4.HPType;

            TB_HPEV.Text  = pk4.EV_HP.ToString();
            TB_ATKEV.Text = pk4.EV_ATK.ToString();
            TB_DEFEV.Text = pk4.EV_DEF.ToString();
            TB_SPEEV.Text = pk4.EV_SPE.ToString();
            TB_SPAEV.Text = pk4.EV_SPA.ToString();
            TB_SPDEV.Text = pk4.EV_SPD.ToString();

            CB_Move1.SelectedValue = pk4.Move1;
            CB_Move2.SelectedValue = pk4.Move2;
            CB_Move3.SelectedValue = pk4.Move3;
            CB_Move4.SelectedValue = pk4.Move4;
            CB_PPu1.SelectedIndex  = pk4.Move1_PPUps;
            CB_PPu2.SelectedIndex  = pk4.Move2_PPUps;
            CB_PPu3.SelectedIndex  = pk4.Move3_PPUps;
            CB_PPu4.SelectedIndex  = pk4.Move4_PPUps;
            TB_PP1.Text            = pk4.Move1_PP.ToString();
            TB_PP2.Text            = pk4.Move2_PP.ToString();
            TB_PP3.Text            = pk4.Move3_PP.ToString();
            TB_PP4.Text            = pk4.Move4_PP.ToString();

            // Set Form if count is enough, else cap.
            CB_Form.SelectedIndex = CB_Form.Items.Count > pk4.AltForm ? pk4.AltForm : CB_Form.Items.Count - 1;

            // Load Extrabyte Value
            TB_ExtraByte.Text = pk4.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString();

            updateStats();

            TB_EXP.Text            = pk4.EXP.ToString();
            Label_Gender.Text      = gendersymbols[pk4.Gender];
            Label_Gender.ForeColor = pk4.Gender == 2 ? Label_Species.ForeColor : (pk4.Gender == 1 ? Color.Red : Color.Blue);

            if (HaX)
            {
                DEV_Ability.SelectedValue = pk4.Ability;
            }
            else
            {
                int[] abils = SAV.Personal.getAbilities(pk4.Species, pk4.AltForm);
                int   abil  = Array.IndexOf(abils, pk4.Ability);

                if (abil < 0)
                {
                    CB_Ability.SelectedIndex = 0;
                }
                else if (abils[0] == abils[1] || abils[1] == 0)
                {
                    CB_Ability.SelectedIndex = pk4.PIDAbility;
                }
                else
                {
                    CB_Ability.SelectedIndex = abil < 0 || abil >= CB_Ability.Items.Count ? 0 : abil;
                }
            }
        }
예제 #18
0
        private void GetComboBoxes()
        {
            var dsregion_list = new[] {
                new { Text = "NA/SA", Value = 1 },
                new { Text = "EUR", Value = 2 },
                new { Text = "JPN", Value = 0 },
                new { Text = "CN", Value = 4 },
                new { Text = "KOR", Value = 5 },
                new { Text = "TW", Value = 6 }
            };

            CB_3DSReg.InitializeBinding();
            CB_3DSReg.DataSource = dsregion_list;
            CB_Language.InitializeBinding();
            CB_Language.DataSource = GameInfo.LanguageDataSource(SAV.Generation);

            CB_Country.InitializeBinding();
            CB_Region.InitializeBinding();
            Main.SetCountrySubRegion(CB_Country, "countries");

            var oras_sprite_list = new[] {
                //new { Text = "Calem",                       Value = 00 },
                //new { Text = "Serena",                      Value = 01 },
                new { Text = "Sycamore", Value = 02 },
                new { Text = "Diantha", Value = 03 },
                new { Text = "Wikstrom", Value = 04 },
                new { Text = "Malva", Value = 05 },
                new { Text = "Drasna", Value = 06 },
                new { Text = "Siebold", Value = 07 },
                new { Text = "Viola", Value = 08 },
                new { Text = "Grant", Value = 09 },
                new { Text = "Korrina", Value = 10 },
                new { Text = "Ramos", Value = 11 },
                new { Text = "Clemont", Value = 12 },
                new { Text = "Valerie", Value = 13 },
                new { Text = "Olympia", Value = 14 },
                new { Text = "Wulfric", Value = 15 },
                new { Text = "Youngster (XY)", Value = 16 },
                //new { Text = "(None)",                      Value = 17 },
                new { Text = "Lass (XY)", Value = 18 },
                new { Text = "Lady (XY)", Value = 19 },
                new { Text = "Schoolgirl (XY)", Value = 20 },
                new { Text = "Battle Girl (XY)", Value = 21 },
                new { Text = "Schoolboy (XY)", Value = 22 },
                new { Text = "Rich Boy (XY)", Value = 23 },
                new { Text = "Female Ace Trainer (XY)", Value = 24 },
                //new { Text = "(None)",                      Value = 25 },
                new { Text = "Female Ranger (XY)", Value = 26 },
                new { Text = "Male Ace Trainer (XY)", Value = 27 },
                new { Text = "Male Ranger (XY)", Value = 28 },
                new { Text = "Madame", Value = 29 },
                new { Text = "Monsieur", Value = 30 },
                new { Text = "Black Belt (XY)", Value = 31 },
                new { Text = "Male Punk (XY)", Value = 32 },
                new { Text = "Fairy Tale Girl (XY)", Value = 33 },
                new { Text = "Shauna", Value = 34 },
                new { Text = "Tierno", Value = 35 },
                new { Text = "Trevor", Value = 36 },
                new { Text = "Brendan", Value = 37 },
                new { Text = "May", Value = 38 },
                //new { Text = "(None)",                      Value = 39 },
                new { Text = "Hiker", Value = 40 },
                new { Text = "Aroma Lady", Value = 41 },
                new { Text = "Male Schoolkid", Value = 42 },
                new { Text = "Female Schoolkid", Value = 43 },
                new { Text = "Black Belt (ORAS)", Value = 44 },
                new { Text = "Battle Girl (ORAS)", Value = 45 },
                new { Text = "Pokemaniac (ORAS)", Value = 46 },
                new { Text = "Fairy Tale Girl (ORAS)", Value = 47 },
                new { Text = "Victor Winstrate", Value = 48 },
                new { Text = "Victoria Winstrate", Value = 49 },
                new { Text = "Male Ranger (ORAS)", Value = 50 },
                new { Text = "Female Ranger (ORAS)", Value = 51 },
                new { Text = "Male Swimmer (ORAS)", Value = 52 },
                new { Text = "Hex Maniac", Value = 53 },
                new { Text = "Male Ace Trainer (ORAS)", Value = 54 },
                new { Text = "Female Ace Trainer (ORAS)", Value = 55 },
                new { Text = "Street Thug", Value = 56 },
                new { Text = "Delinquent", Value = 57 },
                new { Text = "Male Expert", Value = 58 },
                new { Text = "Female Expert", Value = 59 },
                new { Text = "Lady (ORAS)", Value = 60 },
                new { Text = "Rich Boy (ORAS)", Value = 61 },
                new { Text = "Ninja Boy", Value = 62 },
                new { Text = "Beauty (ORAS)", Value = 63 },
                new { Text = "Guitarist", Value = 64 },
                new { Text = "Lass (ORAS)", Value = 65 },
                new { Text = "Male Breeder (ORAS)", Value = 66 },
                new { Text = "Female Breeder (ORAS)", Value = 67 },
                new { Text = "Camper", Value = 68 },
                new { Text = "Picnicker", Value = 69 },
                new { Text = "Wally", Value = 70 },
                new { Text = "Steven", Value = 71 },
                new { Text = "Maxie", Value = 72 },
                new { Text = "Archie", Value = 73 },
                new { Text = "Pokémon Center", Value = 0x80 },
                new { Text = "Gift", Value = 0x81 },
            };

            CB_MultiplayerSprite.InitializeBinding();
            CB_MultiplayerSprite.DataSource = oras_sprite_list;

            L_Vivillon.Text = GameInfo.Strings.specieslist[666] + ":";
            CB_Vivillon.InitializeBinding();
            CB_Vivillon.DataSource = PKX.GetFormList(666, GameInfo.Strings.types, GameInfo.Strings.forms, Main.GenderSymbols, 6).ToList();
        }
예제 #19
0
 private void SaveOT(PKM pk)
 {
     pk.OT_Name   = TB_OT.Text;
     pk.OT_Gender = PKX.GetGenderFromString(Label_OTGender.Text);
 }
예제 #20
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;
            }
            if (av == 2)
            {
                pk.HiddenAbility = true;
            }
            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);
        }
예제 #21
0
파일: WC6.cs 프로젝트: akoimeexx/PKHeX
        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               = Poké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);

            if (Date.HasValue)
            {
                pk.MetDate = Date.Value;
            }
            else
            {
                // No datetime set, typical for wc6full
                // Set it to now, instead of zeroing it out.
                pk.MetDate = DateTime.Now;
            }

            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);
        }
예제 #22
0
        private int skipFlag => SAV.USUM ? 4160 : 3200; // FlagMax - 768

        private void GetComboBoxes()
        {
            var dsregion_list = new[] {
                new { Text = "NA/SA", Value = 1 },
                new { Text = "EUR", Value = 2 },
                new { Text = "JPN", Value = 0 },
                new { Text = "CN", Value = 4 },
                new { Text = "KOR", Value = 5 },
                new { Text = "TW", Value = 6 }
            };

            var language_list = new[] {
                new { Text = "ENG", Value = 2 },
                new { Text = "JPN", Value = 1 },
                new { Text = "FRE", Value = 3 },
                new { Text = "ITA", Value = 4 },
                new { Text = "GER", Value = 5 },
                new { Text = "SPA", Value = 7 },
                new { Text = "KOR", Value = 8 },
                new { Text = "CHS", Value = 9 },
                new { Text = "CHT", Value = 10 },
            };

            var alolatime_list = new[] { new { Text = "Sun Time", Value = 24 * 60 * 60 } };

            Array.Resize(ref alolatime_list, 24);
            for (int i = 1; i < 24; i++)
            {
                alolatime_list[i] = new { Text = $"+{i:00} Hours", Value = i * 60 * 60 }
            }
            ;
            alolatime_list[12] = new { Text = "Moon Time", Value = 12 * 60 * 60 };

            CB_3DSReg.DisplayMember    = "Text";
            CB_3DSReg.ValueMember      = "Value";
            CB_3DSReg.DataSource       = dsregion_list;
            CB_Language.DisplayMember  = "Text";
            CB_Language.ValueMember    = "Value";
            CB_Language.DataSource     = language_list;
            CB_AlolaTime.DisplayMember = "Text";
            CB_AlolaTime.ValueMember   = "Value";
            CB_AlolaTime.DataSource    = alolatime_list;

            CB_Country.DisplayMember = "Text";
            CB_Country.ValueMember   = "Value";
            CB_Region.DisplayMember  = "Text";
            CB_Region.ValueMember    = "Value";
            Main.SetCountrySubRegion(CB_Country, "countries");

            CB_SkinColor.Items.Clear();
            string[] skinColors = { "Pale", "Default", "Tan", "Dark" };
            foreach (string c in skinColors)
            {
                CB_SkinColor.Items.Add($"{Main.GenderSymbols[0]} - {c}"); // M
                CB_SkinColor.Items.Add($"{Main.GenderSymbols[1]} - {c}"); // F
            }

            L_Vivillon.Text           = GameInfo.Strings.specieslist[666] + ":";
            CB_Vivillon.DisplayMember = "Text";
            CB_Vivillon.ValueMember   = "Value";
            CB_Vivillon.DataSource    = PKX.GetFormList(666, GameInfo.Strings.types, GameInfo.Strings.forms, Main.GenderSymbols, SAV.Generation).ToList();

            var styles = new List <string>(BattleStyles);

            if (SAV.USUM)
            {
                styles.Add("Nihilist");
            }
            foreach (string t in styles)
            {
                CB_BallThrowType.Items.Add(t);
                LB_BallThrowTypeUnlocked.Items.Add(t);
                LB_BallThrowTypeLearned.Items.Add(t);
            }

            foreach (string t in TrainerStampTitle)
            {
                LB_Stamps.Items.Add(t);
            }
        }
예제 #23
0
 public override string getBoxName(int box)
 {
     return(PKX.getColoStr(Data, Box + (30 * SIZE_STORED + 0x14) * box, 8));
 }
예제 #24
0
        private PersonalTable(byte[] data, GameVersion format)
        {
            int size = 0;

            switch (format)
            {
            case GameVersion.RBY: size = PersonalInfoG1.SIZE; break;

            case GameVersion.GS:
            case GameVersion.C: size = PersonalInfoG2.SIZE; break;

            case GameVersion.RS:
            case GameVersion.E:
            case GameVersion.FR:
            case GameVersion.LG: size = PersonalInfoG3.SIZE; break;

            case GameVersion.DP:
            case GameVersion.Pt:
            case GameVersion.HGSS: size = PersonalInfoG4.SIZE; break;

            case GameVersion.BW: size = PersonalInfoBW.SIZE; break;

            case GameVersion.B2W2: size = PersonalInfoB2W2.SIZE; break;

            case GameVersion.XY: size = PersonalInfoXY.SIZE; break;

            case GameVersion.ORAS: size = PersonalInfoORAS.SIZE; break;

            case GameVersion.SM: size = PersonalInfoSM.SIZE; break;
            }

            if (size == 0)
            {
                Table = null; return;
            }

            byte[][]       entries = splitBytes(data, size);
            PersonalInfo[] d       = new PersonalInfo[data.Length / size];

            switch (format)
            {
            case GameVersion.RBY:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG1(entries[i]);
                }
                break;

            case GameVersion.GS:
            case GameVersion.C:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG2(entries[i]);
                }
                break;

            case GameVersion.RS:
            case GameVersion.E:
            case GameVersion.FR:
            case GameVersion.LG:
                Array.Resize(ref d, 387);
                for (int i = 0; i < d.Length; i++)     // entries are not in order of natdexID
                {
                    d[i] = new PersonalInfoG3(entries[PKX.getG3Species(i)]);
                }
                break;

            case GameVersion.DP:
            case GameVersion.Pt:
            case GameVersion.HGSS:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoG4(entries[i]);
                }
                break;

            case GameVersion.BW:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoBW(entries[i]);
                }
                break;

            case GameVersion.B2W2:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoB2W2(entries[i]);
                }
                break;

            case GameVersion.XY:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoXY(entries[i]);
                }
                break;

            case GameVersion.ORAS:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoORAS(entries[i]);
                }
                break;

            case GameVersion.SM:
                for (int i = 0; i < d.Length; i++)
                {
                    d[i] = new PersonalInfoSM(entries[i]);
                }
                break;
            }
            Table = d;
        }
예제 #25
0
        public override PKM convertToPKM(SaveFile SAV)
        {
            if (!IsPokémon)
            {
                return(null);
            }

            PK4 pk4 = new PK4(PK.Data);

            if (!IsHatched && Detail == 0)
            {
                pk4.OT_Name   = SAV.OT;
                pk4.TID       = SAV.TID;
                pk4.SID       = SAV.SID;
                pk4.OT_Gender = SAV.Gender;
            }
            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 || IsManaphyEgg) // Create Nonshiny
            {
                uint pid1 = PKX.LCRNG(ref seed) >> 16;
                uint pid2 = PKX.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 = PKX.LCRNG(ref seed) >> 16;
                uint iv2 = PKX.LCRNG(ref seed) >> 16;
                pk4.IV32 = (iv1 | iv2 << 16) & 0x3FFFFFFF;
            }

            // Generate Met Info
            if (IsPokémon)
            {
                pk4.Met_Location = pk4.Egg_Location + 3000;
                pk4.Egg_Location = 0;
                pk4.MetDate      = DateTime.Now;
                pk4.IsEgg        = false;
            }
            else
            {
                pk4.Egg_Location = pk4.Egg_Location + 3000;
                pk4.MetDate      = DateTime.Now;
                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 = PKX.getUnownForm(pk4.PID);
            }
            if (IsEgg || IsManaphyEgg)
            {
                pk4.IsEgg = true;
            }

            pk4.RefreshChecksum();
            return(pk4);
        }
예제 #26
0
 public override byte[] Encrypt()
 {
     RefreshChecksum();
     return(PKX.encryptArray45(Data));
 }
예제 #27
0
        private void populateFieldsCK3()
        {
            CK3 ck3 = pkm as CK3;

            if (ck3 == null)
            {
                return;
            }

            // Do first
            ck3.Stat_Level = PKX.getLevel(ck3.Species, ck3.EXP);
            if (ck3.Stat_Level == 100 && !HaX)
            {
                ck3.EXP = PKX.getEXP(ck3.Stat_Level, ck3.Species);
            }

            CB_Species.SelectedValue = ck3.Species;
            TB_Level.Text            = ck3.Stat_Level.ToString();
            TB_EXP.Text = ck3.EXP.ToString();

            // Load rest
            CHK_Fateful.Checked      = ck3.FatefulEncounter;
            CHK_IsEgg.Checked        = ck3.IsEgg;
            CHK_Nicknamed.Checked    = ck3.IsNicknamed;
            Label_OTGender.Text      = gendersymbols[ck3.OT_Gender];
            Label_OTGender.ForeColor = ck3.OT_Gender == 1 ? Color.Red : Color.Blue;
            TB_PID.Text = ck3.PID.ToString("X8");
            CB_HeldItem.SelectedValue = ck3.HeldItem;
            CB_Ability.SelectedIndex  = ck3.AbilityNumber > CB_Ability.Items.Count ? 0 : ck3.AbilityNumber;
            CB_Nature.SelectedValue   = ck3.Nature;
            TB_TID.Text                    = ck3.TID.ToString("00000");
            TB_SID.Text                    = ck3.SID.ToString("00000");
            TB_Nickname.Text               = ck3.Nickname;
            TB_OT.Text                     = ck3.OT_Name;
            TB_Friendship.Text             = ck3.CurrentFriendship.ToString();
            GB_OT.BackgroundImage          = null;
            CB_Language.SelectedValue      = ck3.Language;
            CB_GameOrigin.SelectedValue    = ck3.Version;
            CB_EncounterType.SelectedValue = ck3.Gen4 ? ck3.EncounterType : 0;
            CB_Ball.SelectedValue          = ck3.Ball;

            int cr  = ck3.CurrentRegion;
            int or  = ck3.OriginalRegion;
            int ver = ck3.Version;

            CB_MetLocation.SelectedValue = ck3.Met_Location;

            TB_MetLevel.Text = ck3.Met_Level.ToString();

            // Reset Label and ComboBox visibility, as well as non-data checked status.
            Label_PKRS.Visible     = CB_PKRSStrain.Visible = CHK_Infected.Checked = ck3.PKRS_Strain != 0;
            Label_PKRSdays.Visible = CB_PKRSDays.Visible = ck3.PKRS_Days != 0;

            // Set SelectedIndexes for PKRS
            CB_PKRSStrain.SelectedIndex = ck3.PKRS_Strain;
            CHK_Cured.Checked           = ck3.PKRS_Strain > 0 && ck3.PKRS_Days == 0;
            CB_PKRSDays.SelectedIndex   = Math.Min(CB_PKRSDays.Items.Count - 1, ck3.PKRS_Days); // to strip out bad hacked 'rus

            TB_Cool.Text   = ck3.CNT_Cool.ToString();
            TB_Beauty.Text = ck3.CNT_Beauty.ToString();
            TB_Cute.Text   = ck3.CNT_Cute.ToString();
            TB_Smart.Text  = ck3.CNT_Smart.ToString();
            TB_Tough.Text  = ck3.CNT_Tough.ToString();
            TB_Sheen.Text  = ck3.CNT_Sheen.ToString();

            TB_HPIV.Text            = ck3.IV_HP.ToString();
            TB_ATKIV.Text           = ck3.IV_ATK.ToString();
            TB_DEFIV.Text           = ck3.IV_DEF.ToString();
            TB_SPEIV.Text           = ck3.IV_SPE.ToString();
            TB_SPAIV.Text           = ck3.IV_SPA.ToString();
            TB_SPDIV.Text           = ck3.IV_SPD.ToString();
            CB_HPType.SelectedValue = ck3.HPType;

            TB_HPEV.Text  = ck3.EV_HP.ToString();
            TB_ATKEV.Text = ck3.EV_ATK.ToString();
            TB_DEFEV.Text = ck3.EV_DEF.ToString();
            TB_SPEEV.Text = ck3.EV_SPE.ToString();
            TB_SPAEV.Text = ck3.EV_SPA.ToString();
            TB_SPDEV.Text = ck3.EV_SPD.ToString();

            CB_Move1.SelectedValue = ck3.Move1;
            CB_Move2.SelectedValue = ck3.Move2;
            CB_Move3.SelectedValue = ck3.Move3;
            CB_Move4.SelectedValue = ck3.Move4;
            CB_PPu1.SelectedIndex  = ck3.Move1_PPUps;
            CB_PPu2.SelectedIndex  = ck3.Move2_PPUps;
            CB_PPu3.SelectedIndex  = ck3.Move3_PPUps;
            CB_PPu4.SelectedIndex  = ck3.Move4_PPUps;
            TB_PP1.Text            = ck3.Move1_PP.ToString();
            TB_PP2.Text            = ck3.Move2_PP.ToString();
            TB_PP3.Text            = ck3.Move3_PP.ToString();
            TB_PP4.Text            = ck3.Move4_PP.ToString();

            // Set Form if count is enough, else cap.
            CB_Form.SelectedIndex = CB_Form.Items.Count > ck3.AltForm ? ck3.AltForm : CB_Form.Items.Count - 1;

            // Load Extrabyte Value
            TB_ExtraByte.Text = ck3.Data[Convert.ToInt32(CB_ExtraBytes.Text, 16)].ToString();

            NUD_ShadowID.Value       = ck3.ShadowID;
            FLP_Purification.Visible = ck3.ShadowID > 0;
            if (ck3.ShadowID > 0)
            {
                int puri = ck3.Purification;
                if (puri > NUD_Purification.Maximum)
                {
                    puri = (int)NUD_Purification.Maximum;
                }
                NUD_Purification.Value = puri;
                CHK_Shadow.Checked     = puri > 0;

                NUD_ShadowID.Value = Math.Max(ck3.ShadowID, 0);
            }
            else
            {
                NUD_Purification.Value = 0;
                CHK_Shadow.Checked     = false;
                NUD_ShadowID.Value     = 0;
            }

            updateStats();

            TB_EXP.Text            = ck3.EXP.ToString();
            Label_Gender.Text      = gendersymbols[ck3.Gender];
            Label_Gender.ForeColor = ck3.Gender == 2 ? Label_Species.ForeColor : (ck3.Gender == 1 ? Color.Red : Color.Blue);
        }
예제 #28
0
        private void Write_Entry(object sender, EventArgs e)
        {
            if (!editing)
            {
                return; //Don't do writing until loaded
            }
            Validate_TextBoxes();

            int index       = LB_DataEntry.SelectedIndex;
            int partymember = Convert.ToInt32(NUP_PartyIndex.Value) - 1;
            int offset      = (index * 0x1B4) + (partymember * 0x48);

            BitConverter.GetBytes(Convert.ToUInt16(CB_Species.SelectedValue)).CopyTo(data, offset + 0x00);
            BitConverter.GetBytes(Convert.ToUInt16(CB_HeldItem.SelectedValue)).CopyTo(data, offset + 0x02);
            BitConverter.GetBytes(Convert.ToUInt16(CB_Move1.SelectedValue)).CopyTo(data, offset + 0x04);
            BitConverter.GetBytes(Convert.ToUInt16(CB_Move2.SelectedValue)).CopyTo(data, offset + 0x06);
            BitConverter.GetBytes(Convert.ToUInt16(CB_Move3.SelectedValue)).CopyTo(data, offset + 0x08);
            BitConverter.GetBytes(Convert.ToUInt16(CB_Move4.SelectedValue)).CopyTo(data, offset + 0x0A);
            BitConverter.GetBytes(Util.GetHexValue(TB_EC.Text)).CopyTo(data, offset + 0x0C);

            BitConverter.GetBytes(Convert.ToUInt16(TB_TID.Text)).CopyTo(data, offset + 0x10);
            BitConverter.GetBytes(Convert.ToUInt16(TB_SID.Text)).CopyTo(data, offset + 0x12);

            uint rawslgf = BitConverter.ToUInt32(data, offset + 0x14);
            uint slgf    = 0;

            slgf |= (uint)(CB_Form.SelectedIndex & 0x1F);
            slgf |= (uint)((PKX.GetGenderFromString(Label_Gender.Text) & 0x3) << 5);
            slgf |= (uint)((Convert.ToUInt16(TB_Level.Text) & 0x7F) << 7);
            if (CHK_Shiny.Checked)
            {
                slgf |= 1 << 14;
            }

            slgf |= rawslgf & 0x8000;
            Array.Copy(BitConverter.GetBytes(slgf), 0, data, offset + 0x14, 2);

            uint nick = 0;

            if (CHK_Nicknamed.Checked)
            {
                nick = 1;
            }
            Array.Copy(BitConverter.GetBytes(nick), 0, data, offset + 0x16, 2);

            //Mimic in-game behavior of not clearing strings. It's awful, but accuracy > good.
            string pk = TB_Nickname.Text; if (pk.Length != 12)
            {
                pk = pk.PadRight(pk.Length + 1, '\0');
            }
            string ot = TB_OT.Text; if (ot.Length != 12)

            {
                ot = ot.PadRight(pk.Length + 1, '\0');
            }

            Encoding.Unicode.GetBytes(pk).CopyTo(data, offset + 0x18);
            Encoding.Unicode.GetBytes(ot).CopyTo(data, offset + 0x30);

            offset = index * 0x1B4;

            uint vnd  = 0;
            uint date = 0;

            vnd  |= Convert.ToUInt32(TB_VN.Text) & 0xFF;
            date |= (uint)((CAL_MetDate.Value.Year - 2000) & 0xFF);
            date |= (uint)((CAL_MetDate.Value.Month & 0xF) << 8);
            date |= (uint)((CAL_MetDate.Value.Day & 0x1F) << 12);
            vnd  |= (date & 0x1FFFF) << 14;
            //Fix for top bit
            uint rawvnd = BitConverter.ToUInt32(data, offset + 0x1B0);

            vnd |= rawvnd & 0x80000000;
            Array.Copy(BitConverter.GetBytes(vnd), 0, data, offset + 0x1B0, 4);

            var species = WinFormsUtil.GetIndex(CB_Species);
            var form    = CB_Form.SelectedIndex & 0x1F;
            var gender  = PKX.GetGenderFromString(Label_Gender.Text);
            var item    = WinFormsUtil.GetIndex(CB_HeldItem);

            bpkx.Image = SpriteUtil.GetSprite(species, form, gender, 0, item, false, CHK_Shiny.Checked);
            DisplayEntry(this, EventArgs.Empty); // refresh text view
        }
예제 #29
0
        private bool CommonErrorHandling2(PKM pk)
        {
            string           hp           = pk.IV_HP.ToString();
            string           atk          = pk.IV_ATK.ToString();
            string           def          = pk.IV_DEF.ToString();
            string           spa          = pk.IV_SPA.ToString();
            string           spd          = pk.IV_SPD.ToString();
            string           spe          = pk.IV_SPE.ToString();
            bool             HTworkaround = false;
            LegalityAnalysis la           = new LegalityAnalysis(pk);
            var report        = la.Report(false);
            var updatedReport = report;

            if (report.Contains("Ability mismatch for encounter"))
            {
                pk.RefreshAbility(pk.AbilityNumber < 6 ? pk.AbilityNumber >> 1 : 0);
            }
            if (report.Contains("Invalid Met Location, expected Transporter."))
            {
                pk.Met_Location = 30001;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("Can't have ball for encounter type."))
            {
                if (pk.B2W2)
                {
                    pk.Ball = 25; //Dream Ball
                    LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                    updatedReport = recheckLA.Report(false);
                    report        = updatedReport;
                }
                else
                {
                    pk.Ball = 0;
                    LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                    updatedReport = recheckLA.Report(false);
                    report        = updatedReport;
                }
            }
            if (report.Contains("Non japanese Mew from Faraway Island. Unreleased event."))
            {
                pk.Language         = 1;
                pk.FatefulEncounter = true;
                pk.Nickname         = PKX.GetSpeciesNameGeneration(pk.Species, pk.Language, 3);
                pk.PID = PKX.GetRandomPID(pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("PID should be equal to EC!"))
            {
                pk.EncryptionConstant = pk.PID;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("PID should be equal to EC [with top bit flipped]!"))
            {
                pk.PID = PKX.GetRandomPID(pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
                if (pk.IsShiny)
                {
                    pk.SetShinyPID();
                }
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("PID-Gender mismatch."))
            {
                if (pk.Gender == 0)
                {
                    pk.Gender = 1;
                }
                else
                {
                    pk.Gender = 0;
                }
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("Missing Ribbons: National"))
            {
                ReflectUtil.SetValue(pk, "RibbonNational", -1);
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("Invalid Ribbons: National"))
            {
                ReflectUtil.SetValue(pk, "RibbonNational", 0);
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("OT Name too long."))
            {
                pk.OT_Name = "ARCH";
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("GeoLocation Memory: Memories should be present."))
            {
                pk.Geo1_Country = 1;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("Can't have ball for encounter type."))
            {
                pk.Ball = 4;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("Can't have any OT Memory."))
            {
                pk.OT_Memory    = 0;
                pk.OT_Intensity = 0;
                pk.OT_Feeling   = 0;
                pk.OT_TextVar   = 0;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("OT Memory: Should be index 0."))
            {
                pk.OT_Memory = 0;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("OT Memory: Intensity should be index 0."))
            {
                pk.OT_Intensity = 0;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("OT Memory: Feeling should be index 0."))
            {
                pk.OT_Feeling = 0;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("OT Memory: TextVar should be index 0."))
            {
                pk.OT_TextVar = 0;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("Form cannot exist outside of a battle."))
            {
                pk.AltForm = 0;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("Special ingame Fateful Encounter flag missing"))
            {
                pk.FatefulEncounter = true;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Contains("Fateful Encounter should not be checked."))
            {
                pk.FatefulEncounter = false;
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
            }
            if (report.Equals("Invalid: Encounter Type PID mismatch."))
            {
                //return true;

                if (pk.Version == (int)GameVersion.CXD)
                {
                    pk = setPIDSID(pk, pk.IsShiny, true);
                }
                else
                {
                    pk = setPIDSID(pk, pk.IsShiny);
                }
                if (new LegalityAnalysis(pk).Valid)
                {
                    return(false);
                }
                if (pk.HT_HP)
                {
                    HTworkaround = true;
                }
                LegalityAnalysis recheckLA = new LegalityAnalysis(pk);
                updatedReport = recheckLA.Report(false);
                report        = updatedReport;
                if (report.Equals("Invalid: Encounter Type PID mismatch."))
                {
                    return(true);
                }
                else if (report.Contains("PID-Gender mismatch."))
                {
                    if (pk.Gender == 0)
                    {
                        pk.Gender = 1;
                    }
                    else
                    {
                        pk.Gender = 0;
                    }
                    LegalityAnalysis recheckLA2 = new LegalityAnalysis(pk);
                    updatedReport = recheckLA2.Report(false);
                    report        = updatedReport;
                    if (new LegalityAnalysis(pk).Valid)
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
예제 #30
0
        private static bool InnerBruteForce(PKM pk, GameVersion game, bool shiny, int abilitynum, ShowdownSet set)
        {
            pk.ClearRelearnMoves();
            switch (game)
            {
            case GameVersion.RD:
            case GameVersion.BU:
            case GameVersion.YW:
            case GameVersion.GN:
                pk.Met_Location = 30013;
                pk.Met_Level    = 100;
                break;

            case GameVersion.GD:
            case GameVersion.SV:
            case GameVersion.C:
                pk.Met_Location = 30017;
                pk.Met_Level    = 100;
                break;

            case GameVersion.CXD:
                pk.Met_Location = 30001;
                pk.Met_Level    = 100;
                break;

            default:
                try
                {
                    pk.SetSuggestedMetLocation();
                }
                catch { }
                break;
            }
            try
            {
                pk.SetSuggestedRelearnMoves();
            }
            catch { }
            pk.CurrentHandler = 1;
            pk.HT_Name        = "Archit";
            pk.PID            = PKX.GetRandomPID(Util.Rand, pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
            if (shiny)
            {
                pk.SetShiny();
            }
            if (pk.PID == 0)
            {
                pk.PID = PKX.GetRandomPID(Util.Rand, pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
                if (shiny)
                {
                    pk.SetShiny();
                }
            }

            pk.RefreshAbility(abilitynum);
            pk.SetSuggestedMemories();
            if (pk.GenNumber < 6)
            {
                pk.EncryptionConstant = pk.PID;
            }

            if (CommonErrorHandling2(pk))
            {
                pk.HyperTrain();
                if (shiny)
                {
                    pk.SetShiny();
                }
                return(true);
            }

            pk.HyperTrain();
            bool legalized = new LegalityAnalysis(pk).Valid;

            AlternateAbilityRefresh(pk);
            if (pk.GenNumber < 6 && !legalized)
            {
                pk.EncryptionConstant = pk.PID;
            }

            if (new LegalityAnalysis(pk).Valid&& pk.Format >= pk.GenNumber)
            {
                pk.SetHappiness();
                if (shiny && pk.IsShiny)
                {
                    return(true);
                }
                if (!set.Shiny || pk.IsShiny)
                {
                    return(true);
                }

                pk.SetShinySID();
                if (new LegalityAnalysis(pk).Valid)
                {
                    return(true);
                }

                pk.SetShiny();
                if (new LegalityAnalysis(pk).Valid)
                {
                    return(true);
                }
            }
            else
            {
                var edge = EncounterMovesetGenerator.GenerateEncounters(pk).OfType <EncounterStatic>();
                foreach (EncounterStatic el in edge)
                {
                    ApplyEncounterAttributes(pk, set, el);
                    var la = new LegalityAnalysis(pk);
                    if (la.Valid)
                    {
                        return(true);
                    }
                    Debug.WriteLine(la.Report());
                }
            }

            return(false);
        }