예제 #1
0
 private static IEnumerable <IEncounterable> GetEncounters(int species, int[] moves, PKM pk, IReadOnlyList <GameVersion> vers)
 {
     pk.Species = species;
     return(EncounterMovesetGenerator.GenerateEncounters(pk, moves, vers));
 }
예제 #2
0
 private void LoadEVs(PKM pk) => Stats.LoadEVs(pk.EVs);
예제 #3
0
        /// <summary>
        /// Bot procedure.
        /// </summary>
        public async void RunBot()
        {
            try
            {
                Program.gCmdWindow.SetBotMode(true);
                while (botworking && Program.gCmdWindow.IsConnected)
                {
                    switch (botState)
                    {
                    case (int)BotState.BotStart:
                        Report("Bot: START Gen 7 Breding bot");
                        if (Mode.SelectedIndex >= 0 && Mode.SelectedIndex != 3 &&
                            Eggs.Value > 0)
                        {
                            Delg.SetValue(Slot, 1);
                            botState = BotState.SelectBox;
                        }
                        else if (Mode.SelectedIndex == 3 && (Accept.Value > 0 ||
                                                             Reject.Value > 0))
                        {
                            botState = BotState.EggSeed;
                        }
                        else
                        {
                            botresult = ErrorMessage.Finished;
                            botState  = BotState.BotExit;
                        }
                        break;

                    case BotState.SelectBox:
                        Report("Bot: Set start box");
                        waitTaskbool = Program.helper.waitNTRwrite(LookupTable
                                                                   .CurrentboxOffset, (uint)GetIndex(Box),
                                                                   Program.gCmdWindow.pid);
                        if (await waitTaskbool)
                        {
                            attempts = 0;
                            botState = BotState.ReadSlot;
                        }
                        else
                        {
                            attempts++;
                            botresult = ErrorMessage.WriteError;
                            botState  = BotState.SelectBox;
                        }
                        break;

                    case BotState.ReadSlot:
                        Report("Bot: Search for empty slot");
                        waitTaskPKM = Program.helper.waitPokeRead(Box, Slot);
                        breedPoke   = await waitTaskPKM;
                        if (breedPoke == null)
                        {     // No data or invalid
                            attempts++;
                            botresult = ErrorMessage.ReadError;
                            botState  = BotState.ReadSlot;
                        }
                        else if (breedPoke.Species == 0)
                        {     // Empty space
                            Report("Bot: Empty slot");
                            attempts = 0;
                            botState = BotState.EggSeed;
                        }
                        else
                        {
                            GetNextSlot();
                            botState = BotState.ReadSlot;
                        }
                        break;

                    case BotState.EggSeed:
                        Report("Bot: Update Egg seed");
                        waitTaskbool = Program.helper.waitNTRmultiread(LookupTable.SeedEggOffset,
                                                                       0x10);
                        if (await waitTaskbool)
                        {
                            Report("Bot: Current seed - " + UpdateSeed(Program.helper
                                                                       .lastmultiread));
                            attempts = 0;
                            if (Mode.SelectedIndex != 3)
                            {
                                botState = BotState.GenerateEgg;
                            }
                            else
                            {
                                if (Accept.Value == 0 && Reject.Value == 0)
                                {
                                    botresult = ErrorMessage.Finished;
                                    botState  = BotState.BotExit;
                                }
                                else
                                {
                                    botState = BotState.GenerateEgg;
                                }
                            }
                        }
                        else
                        {
                            attempts++;
                            botresult = ErrorMessage.ReadError;
                            botState  = BotState.EggSeed;
                        }
                        break;

                    case BotState.GenerateEgg:
                        Report("Bot: Produce Egg in Nursery");
                        waitTaskbool = Program.helper.waitNTRwrite(EggOff, 0x01,
                                                                   Program.gCmdWindow.pid);
                        if (await waitTaskbool)
                        {
                            attempts = 0;
                            botState = BotState.TriggerDialog;
                        }
                        else
                        {
                            attempts++;
                            botresult = ErrorMessage.WriteError;
                            botState  = BotState.GenerateEgg;
                        }
                        break;

                    case BotState.TriggerDialog:
                        Report("Bot: Start dialog");
                        waitTaskbool = Program.helper.waitbutton(LookupTable.ButtonA);
                        if (await waitTaskbool)
                        {
                            botState = BotState.TestDialog1;
                        }
                        else
                        {
                            attempts++;
                            botresult = ErrorMessage.ButtonError;
                            botState  = BotState.TriggerDialog;
                        }
                        break;

                    case BotState.TestDialog1:
                        Report("Bot: Test if dialog has started");
                        waitTaskbool = Program.helper.memoryinrange(DialogOff,
                                                                    DialogIn, 0x10000000);
                        if (await waitTaskbool)
                        {
                            attempts = 0;
                            botState = BotState.ContinueDialog;
                        }
                        else
                        {
                            attempts++;
                            botresult = ErrorMessage.ReadError;
                            botState  = BotState.TriggerDialog;
                        }
                        break;

                    case BotState.ContinueDialog:
                        Report("Bot: Continue dialog");
                        int maxi;
                        if (Mode.SelectedIndex == 3 && Accept.Value == 0)
                        {
                            key  = LookupTable.ButtonB;
                            maxi = 9;
                        }
                        else
                        {
                            key  = LookupTable.ButtonA;
                            maxi = 6;
                        }
                        int i;
                        for (i = 0; i < maxi; i++)
                        {
                            waitTaskbool = Program.helper.waitbutton(key);
                            if (!(await waitTaskbool))
                            {
                                break;
                            }
                        }
                        if (i == 6)
                        {
                            botState = BotState.CheckNoEgg;
                        }
                        if (i == 9)
                        {
                            botState = BotState.TestDialog2;
                        }
                        else
                        {
                            botState = BotState.FixDialog;
                        }
                        break;

                    case BotState.FixDialog:
                        waitTaskbool = Program.helper.waitbutton(key);
                        if (await waitTaskbool)
                        {
                            botState = BotState.CheckNoEgg;
                        }
                        else
                        {
                            attempts++;
                            botresult = ErrorMessage.ButtonError;
                            botState  = BotState.FixDialog;
                        }
                        break;

                    case BotState.CheckNoEgg:
                        waitTaskbool = Program.helper.memoryinrange(EggOff, 0x00,
                                                                    0x01);
                        if (await waitTaskbool)
                        {
                            attempts = 0;
                            Report("Bot: Egg received");
                            botState = BotState.ExitDialog;
                        }
                        else
                        {
                            attempts++;
                            botresult = ErrorMessage.ReadError;
                            botState  = BotState.FixDialog;
                        }
                        break;

                    case BotState.ExitDialog:
                        Report("Bot: Exit dialog");
                        await Task.Delay(1500);

                        waitTaskbool = Program.helper.waitbutton(LookupTable.ButtonB);
                        if (await waitTaskbool)
                        {
                            waitTaskbool = Program.helper.waitbutton(LookupTable
                                                                     .ButtonB);
                            if (await waitTaskbool)
                            {
                                botState = BotState.TestDialog2;
                            }
                            else
                            {
                                attempts++;
                                botresult = ErrorMessage.ButtonError;
                                botState  = BotState.ExitDialog;
                            }
                        }
                        else
                        {
                            attempts++;
                            botresult = ErrorMessage.ButtonError;
                            botState  = BotState.ExitDialog;
                        }
                        break;

                    case BotState.TestDialog2:
                        waitTaskbool = Program.helper.memoryinrange(DialogOff,
                                                                    DialogOut, 0x10000000);
                        if (await waitTaskbool)
                        {
                            attempts = 0;
                            Report("Bot: Dialog finished");
                            if (Mode.SelectedIndex != 3)
                            {
                                botState = BotState.Filter;
                            }
                            else
                            {
                                if (Accept.Value > 0)
                                {
                                    Delg.SetValue(Accept, Accept.Value - 1);
                                }
                                else
                                {
                                    Delg.SetValue(Reject, Reject.Value - 1);;
                                }
                                botState = BotState.EggSeed;
                            }
                        }
                        else
                        {
                            attempts++;
                            botresult = ErrorMessage.ReadError;
                            botState  = BotState.ExitDialog;
                        }
                        break;

                    case BotState.Filter:
                        bool testsok = false;
                        Report("Bot: Read recevied egg");
                        waitTaskPKM = Program.helper.waitPokeRead(Box, Slot);
                        breedPoke   = await waitTaskPKM;
                        if (breedPoke == null)
                        {     // No data or invalid
                            attempts++;
                            botresult = ErrorMessage.ReadError;
                            botState  = BotState.Filter;
                        }
                        else if (breedPoke.Species == 0)
                        {     // Empty space
                            Report("Bot: Error detected - slot is empty");
                            attempts  = 11;
                            botresult = ErrorMessage.GeneralError;
                            botState  = BotState.BotExit;
                        }
                        else
                        {
                            attempts = 0;
                            Delg.SetValue(Eggs, Eggs.Value - 1);
                            if (ReadESV.Checked || Mode.SelectedIndex == 2)
                            {
                                Delg.DataGridViewAddRow(esvList, Box.Value,
                                                        Slot.Value, breedPoke.PSV.ToString("D4"));
                                if (Mode.SelectedIndex == 2)
                                {
                                    testsok = ESV_TSV_check(breedPoke.PSV);
                                }
                            }
                            if (Mode.SelectedIndex == 1)
                            {
                                filternum = CheckFilters(breedPoke, filterList);
                                testsok   = filternum > 0;
                            }
                        }
                        if (testsok)
                        {
                            botState = BotState.TestsPassed;
                            break;
                        }
                        else if (Eggs.Value > 0)
                        {
                            GetNextSlot();
                            botState = BotState.ReadSlot;
                        }
                        else
                        {
                            if (Mode.SelectedIndex == 1 || Mode.SelectedIndex == 2)
                            {
                                Report("Bot: No match found");
                                botresult = ErrorMessage.NoMatch;
                            }
                            else
                            {
                                botresult = ErrorMessage.Finished;
                            }
                            botState = BotState.BotExit;
                        }
                        break;

                    case BotState.TestsPassed:
                        if (Mode.SelectedIndex == 1)
                        {
                            Report("Bot: All tests passed");
                            botresult        = ErrorMessage.FilterMatch;
                            finishmessage[0] = (int)Box.Value;
                            finishmessage[1] = (int)Slot.Value;
                            finishmessage[2] = filternum;
                        }
                        else if (Mode.SelectedIndex == 2)
                        {
                            Report("Bot: ESV/TSV match found");
                            botresult        = ErrorMessage.SVMatch;
                            finishmessage[0] = (int)Box.Value;
                            finishmessage[1] = (int)Slot.Value;
                            finishmessage[2] = breedPoke.PSV;
                        }
                        botState = BotState.BotExit;
                        break;

                    case BotState.BotExit:
                        Report("Bot: STOP Gen 7 Breding bot");
                        botworking = false;
                        break;

                    default:
                        Report("Bot: STOP Gen 7 Breding bot");
                        botresult  = ErrorMessage.GeneralError;
                        botworking = false;
                        break;
                    }
                    if (attempts > 10)
                    { // Too many attempts
                        if (maxreconnect > 0)
                        {
                            Report("Bot: Try reconnection to fix error");
                            waitTaskbool = Program.gCmdWindow.Reconnect();
                            maxreconnect--;
                            if (await waitTaskbool)
                            {
                                await Task.Delay(2500);

                                attempts = 0;
                            }
                            else
                            {
                                botresult  = ErrorMessage.GeneralError;
                                botworking = false;
                            }
                        }
                        else
                        {
                            Report("Bot: Maximum number of reconnection attempts reached");
                            Report("Bot: STOP Gen 7 Breeding bot");
                            botworking = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Report("Bot: Exception detected:");
                Report(ex.Source);
                Report(ex.Message);
                Report(ex.StackTrace);
                Report("Bot: STOP Gen 7 Breeding bot");
                MessageBox.Show(ex.Message);
                botworking = false;
                botresult  = ErrorMessage.GeneralError;
            }
            if (userstop)
            {
                botresult = ErrorMessage.UserStop;
            }
            else if (!Program.gCmdWindow.IsConnected)
            {
                botresult = ErrorMessage.Disconnect;
            }
            ShowResult("Breeding bot", botresult, finishmessage);
            Delg.SetText(RunStop, "Start Bot");
            Program.gCmdWindow.SetBotMode(false);
            EnableControls();
            Delg.SetEnabled(RunStop, true);
        }
예제 #4
0
 private void SaveHandlingTrainer(PKM pk)
 {
     pk.HT_Name   = TB_OTt2.Text;
     pk.HT_Gender = PKX.GetGenderFromString(Label_CTGender.Text) & 1;
 }
예제 #5
0
 private void LoadNickname(PKM pk)
 {
     CHK_Nicknamed.Checked = pk.IsNicknamed;
     TB_Nickname.Text      = pk.Nickname;
 }
예제 #6
0
 private void SaveNickname(PKM pk)
 {
     pk.IsNicknamed = CHK_Nicknamed.Checked;
     pk.Nickname    = TB_Nickname.Text;
 }
예제 #7
0
 private void SaveSpeciesLevelEXP(PKM pk)
 {
     pk.Species = WinFormsUtil.GetIndex(CB_Species);
     pk.EXP     = Util.ToUInt32(TB_EXP.Text);
 }
예제 #8
0
 public static async Task SendPKMAsShowdownSetAsync(this ISocketMessageChannel channel, PKM pkm)
 {
     var txt = GetFormattedShowdownText(pkm);
     await channel.SendMessageAsync(txt).ConfigureAwait(false);
 }
예제 #9
0
        public static string GetFormattedShowdownText(PKM pkm)
        {
            var showdown = ShowdownSet.GetShowdownText(pkm);

            return(Format.Code(showdown));
        }
예제 #10
0
 /// <summary>
 /// Gets the minimum hatch counter value allowed for an Egg Entity.
 /// </summary>
 /// <param name="pk">Egg Entity</param>
 /// <returns>Usually 0...</returns>
 public static int GetMinimumEggHatchCycles(PKM pk) => pk switch
 {
예제 #11
0
 public SlotChangeInfo(SaveFile sav)
 {
     Blank = sav.BlankPKM;
     Reset();
 }
예제 #12
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);
        }
예제 #13
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);
        }
예제 #14
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);
        }
예제 #15
0
        private void LoadAbility4(PKM pk)
        {
            var index = GetAbilityIndex4(pk);

            CB_Ability.SelectedIndex = Math.Min(CB_Ability.Items.Count - 1, index);
        }
예제 #16
0
 public static Image GenerateQRCode(PKM pkm) => GenerateQRCode(QRMessageUtil.GetMessage(pkm));
예제 #17
0
 private void SaveOT(PKM pk)
 {
     pk.OT_Name   = TB_OT.Text;
     pk.OT_Gender = PKX.GetGenderFromString(Label_OTGender.Text);
 }
예제 #18
0
 private void UpdateSelectedPKM(PKM pkm) => VM.Selected = pkm;
예제 #19
0
 private void LoadGeolocation(PKM pk)
 {
     CB_Country.SelectedValue   = pk.Country;
     CB_SubRegion.SelectedValue = pk.Region;
     CB_3DSReg.SelectedValue    = pk.ConsoleRegion;
 }
예제 #20
0
 private static async Task DisplayLegality(PKM pk)
 {
     var la = new LegalityAnalysis(pk);
     await UserDialogs.Instance.AlertAsync($"Legality Report for {pk.Nickname}:" + Environment.NewLine + la.Report()).ConfigureAwait(false);
 }
예제 #21
0
 private void SaveGeolocation(PKM pk)
 {
     pk.Country       = WinFormsUtil.GetIndex(CB_Country);
     pk.Region        = WinFormsUtil.GetIndex(CB_SubRegion);
     pk.ConsoleRegion = WinFormsUtil.GetIndex(CB_3DSReg);
 }
예제 #22
0
        private void ClickDelete(object sender, EventArgs e)
        {
            sender = WinFormsUtil.GetUnderlyingControl(sender);
            int index = Array.IndexOf(PKXBOXES, sender);

            if (index >= RES_MAX)
            {
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }
            index += SCR_Box.Value * RES_MIN;
            if (index >= Results.Count)
            {
                System.Media.SystemSounds.Exclamation.Play();
                return;
            }

            var    pk   = Results[index];
            string path = pk.Identifier;

#if LOADALL
            if (path.StartsWith(EXTERNAL_SAV))
            {
                WinFormsUtil.Alert(MsgDBDeleteFailBackup);
                return;
            }
#endif
            if (path.Contains(Path.DirectorySeparatorChar))
            {
                // Data from Database: Delete file from disk
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
            else
            {
                // Data from Box: Delete from save file
                int box    = pk.Box - 1;
                int slot   = pk.Slot - 1;
                int offset = SAV.GetBoxOffset(box) + slot * SAV.SIZE_STORED;
                PKM pkSAV  = SAV.GetStoredSlot(offset);

                if (!pkSAV.DecryptedBoxData.SequenceEqual(pk.DecryptedBoxData)) // data still exists in SAV, unmodified
                {
                    WinFormsUtil.Error(MsgDBDeleteFailModified, MsgDBDeleteFailWarning);
                    return;
                }
                var change = new SlotChange {
                    Box = box, Offset = offset, Slot = slot
                };
                BoxView.M.SetPKM(BoxView.SAV.BlankPKM, change, true, Properties.Resources.slotDel);
            }
            // Remove from database.
            RawDB.Remove(pk);
            Results.Remove(pk);
            // Refresh database view.
            L_Count.Text = string.Format(Counter, Results.Count);
            slotSelected = -1;
            FillPKXBoxes(SCR_Box.Value);
            System.Media.SystemSounds.Asterisk.Play();
        }
예제 #23
0
 private void SavePKRS(PKM pk)
 {
     pk.PKRS_Days   = CB_PKRSDays.SelectedIndex;
     pk.PKRS_Strain = CB_PKRSStrain.SelectedIndex;
 }
 /// <summary>
 /// Checks to see if Crystal is available to visit/originate from.
 /// </summary>
 /// <param name="pkm">Data being checked</param>
 /// <returns>True if Crystal data is allowed</returns>
 public static bool AllowGen2Crystal(PKM pkm) => !pkm.Korean;
예제 #25
0
 private void LoadIVs(PKM pk) => Stats.LoadIVs(pk.IVs);
 /// <summary>
 /// Checks to see if the Move Reminder (Relearner) is available.
 /// </summary>
 /// <remarks> Pokemon Stadium 2 was never released in Korea.</remarks>
 /// <param name="pkm">Data being checked</param>
 /// <returns>True if Crystal data is allowed</returns>
 public static bool AllowGen2MoveReminder(PKM pkm) => !pkm.Korean && AllowGBCartEra;
예제 #27
0
        private void B_ReadRAM_Click(object sender, EventArgs e)
        {
            var txt    = RamOffset.Text;
            var offset = Util.GetHexValue64(txt);
            var valid  = int.TryParse(RamSize.Text, out int size);

            if (offset.ToString("X16") != txt.ToUpper().PadLeft(16, '0') || !valid)
            {
                WinFormsUtil.Alert("Make sure that the RAM offset is a hex string and the size is a valid integer");
                return;
            }

            try
            {
                byte[] result;
                if (Remote.Bot.com is not ICommunicatorNX cnx)
                {
                    result = Remote.ReadRAM(offset, size);
                }
                else if (RB_Main.Checked)
                {
                    result = cnx.ReadBytesMain(offset, size);
                }
                else if (RB_Absolute.Checked)
                {
                    result = cnx.ReadBytesAbsolute(offset, size);
                }
                else
                {
                    result = Remote.ReadRAM(offset, size);
                }

                bool blockview = (ModifierKeys & Keys.Control) == Keys.Control;
                PKM? pkm       = null;
                if (blockview)
                {
                    pkm = SAV.SAV.GetDecryptedPKM(result);
                    if (!pkm.ChecksumValid)
                    {
                        blockview = false;
                    }
                }

                using var form = new SimpleHexEditor(result, Remote.Bot, offset, GetRWMethod());
                var loadgrid = blockview && ReflectUtil.GetPropertiesCanWritePublicDeclared(pkm !.GetType()).Count() > 1;
                if (loadgrid)
                {
                    form.PG_BlockView.Visible        = true;
                    form.PG_BlockView.SelectedObject = pkm;
                }
                var res = form.ShowDialog();
                if (res != DialogResult.OK)
                {
                    return;
                }

                if (loadgrid)
                {
                    PKM pk       = pkm !;
                    var pkmbytes = RamOffsets.WriteBoxData(Remote.Bot.Version) ? pk.EncryptedBoxData : pk.EncryptedPartyData;
                    if (pkmbytes.Length == Remote.Bot.SlotSize)
                    {
                        form.Bytes = pkmbytes;
                    }
                    else
                    {
                        form.Bytes = result;
                        WinFormsUtil.Error("Size mismatch. Please report this issue on the discord server.");
                    }
                }

                var modifiedRAM = form.Bytes;
                if (Remote.Bot.com is not ICommunicatorNX nx)
                {
                    Remote.WriteRAM(offset, modifiedRAM);
                }
 internal static bool IsFromActiveTrainer(PKM pkm) => ActiveTrainer.IsFromTrainer(pkm);
예제 #29
0
        public static string GetPotentialString(this PKM pkm, bool unicode = true)
        {
            var arr = unicode ? PotentialUnicode : PotentialNoUnicode;

            return(arr[pkm.PotentialRating]);
        }
예제 #30
0
 protected abstract bool IsMatchDeferred(PKM pkm);