Example #1
0
        private static PKM M2EventFix(PKM pk, bool shiny)
        {
            int  eggloc = pk.Egg_Location;
            bool feFlag = pk.FatefulEncounter;

            pk.Egg_Location     = 0;
            pk.FatefulEncounter = true;
            string[] NatureHPIVs = IVtoPIDGenerator.GetIVPID((uint)pk.Nature, pk.HPType, false, IVPIDMethod.M2);
            pk.PID = Util.GetHexValue(NatureHPIVs[0]);
            if (pk.GenNumber < 5)
            {
                pk.EncryptionConstant = pk.PID;
            }
            pk.IV_HP  = Convert.ToInt32(NatureHPIVs[1]);
            pk.IV_ATK = Convert.ToInt32(NatureHPIVs[2]);
            pk.IV_DEF = Convert.ToInt32(NatureHPIVs[3]);
            pk.IV_SPA = Convert.ToInt32(NatureHPIVs[4]);
            pk.IV_SPD = Convert.ToInt32(NatureHPIVs[5]);
            pk.IV_SPE = Convert.ToInt32(NatureHPIVs[6]);
            if (shiny)
            {
                pk.SetShinySID();
            }
            var    recheckLA     = new LegalityAnalysis(pk);
            string updatedReport = recheckLA.Report();

            if (updatedReport.Contains(LPIDGenderMismatch))
            {
                pk.Gender = pk.Gender == 0 ? 1 : 0;
                var recheckLA2 = new LegalityAnalysis(pk);
                updatedReport = recheckLA2.Report();
            }

            if (!updatedReport.Contains(LPIDTypeMismatch) || UsesEventBasedMethod(pk.Species, pk.Moves, PIDType.Method_2))
            {
                return(pk);
            }
            Debug.WriteLine(GetReport(pk));
            pk.FatefulEncounter = feFlag;
            pk.Egg_Location     = eggloc;
            return(pk);
        }
Example #2
0
        private static void SetPIDSID(PKM pk, bool shiny, bool XD = false)
        {
            uint hp  = (uint)pk.IV_HP;
            uint atk = (uint)pk.IV_ATK;
            uint def = (uint)pk.IV_DEF;
            uint spa = (uint)pk.IV_SPA;
            uint spd = (uint)pk.IV_SPD;
            uint spe = (uint)pk.IV_SPE;

            void LoadOldIVs()
            {
                pk.IV_HP  = (int)hp;
                pk.IV_ATK = (int)atk;
                pk.IV_DEF = (int)def;
                pk.IV_SPA = (int)spa;
                pk.IV_SPD = (int)spd;
                pk.IV_SPE = (int)spe;
            }

            uint nature = (uint)pk.Nature;
            var  type   = XD ? RNGReporter.FrameType.ColoXD : RNGReporter.FrameType.Method1;
            var  pidsid = IVtoPIDGenerator.Generate(hp, atk, def, spa, spd, spe, nature, 0, type);

            if (pk.Species == 490 && pk.Gen4)
            {
                pk.WasEgg           = true;
                pk.Egg_Location     = 2002;
                pk.FatefulEncounter = true;
            }
            pk.PID = Util.GetHexValue(pidsid[0]);
            if (pk.GenNumber < 5)
            {
                pk.EncryptionConstant = pk.PID;
            }
            pk.SID = Convert.ToInt32(pidsid[1]);
            if (shiny)
            {
                pk.SetShinySID();
            }
            var    recheckLA     = new LegalityAnalysis(pk);
            string updatedReport = recheckLA.Report();

            Debug.WriteLine(updatedReport);
            if (!updatedReport.Contains(LPIDTypeMismatch))
            {
                return;
            }

            var NatureHPIVs = IVtoPIDGenerator.GetIVPID(nature, pk.HPType, XD);

            Debug.WriteLine(XD);
            pk.PID = Util.GetHexValue(NatureHPIVs[0]);
            if (pk.GenNumber < 5)
            {
                pk.EncryptionConstant = pk.PID;
            }

            SetIVs(pk, NatureHPIVs);
            if (shiny)
            {
                pk.SetShinySID();
            }

            recheckLA     = new LegalityAnalysis(pk);
            updatedReport = recheckLA.Report();

            bool pidsidmethod = updatedReport.Contains(LPIDTypeMismatch);

            if (pidsid[0] == "0" && pidsid[1] == "0" && pidsidmethod)
            {
                pk.PID = PKX.GetRandomPID(pk.Species, pk.Gender, pk.Version, pk.Nature, pk.Format, (uint)(pk.AbilityNumber * 0x10001));
                LoadOldIVs();
            }
            if (shiny)
            {
                pk.SetShinySID();
            }

            recheckLA     = new LegalityAnalysis(pk);
            updatedReport = recheckLA.Report();
            if (updatedReport.Contains(LPIDGenderMismatch))
            {
                pk.Gender = pk.Gender == 0 ? 1 : 0;
                var recheckLA2 = new LegalityAnalysis(pk);
                updatedReport = recheckLA2.Report();
            }
            if (updatedReport.Contains(LHyperBelow100))
            {
                pk.CurrentLevel = 100;
                var recheckLA2 = new LegalityAnalysis(pk);
                updatedReport = recheckLA2.Report();
            }
            var la = new LegalityAnalysis(pk);

            if (la.Valid)
            {
                return;
            }
            // Fix Moves if a slot is empty
            pk.FixMoves();

            pk.RefreshAbility(pk.AbilityNumber < 6 ? pk.AbilityNumber >> 1 : 0);
            if (updatedReport.Contains(LPIDTypeMismatch) || UsesEventBasedMethod(pk.Species, pk.Moves, PIDType.Method_2))
            {
                if (pk.GenNumber == 3 || UsesEventBasedMethod(pk.Species, pk.Moves, PIDType.Method_2))
                {
                    pk = M2EventFix(pk, shiny);
                    if (!new LegalityAnalysis(pk).Report().Contains(LPIDTypeMismatch) || UsesEventBasedMethod(pk.Species, pk.Moves, PIDType.Method_2))
                    {
                        return;
                    }
                }
                LoadOldIVs();
            }
        }