Esempio n. 1
0
        private void ModifySaveFile()
        {
            var sav = SaveFileEditor.SAV;

            sav.ModifyBoxes(ModifyPKM);
            SaveFileEditor.ReloadSlots();
        }
Esempio n. 2
0
        private void SortByRegionalDex(Func <PKM, IComparable>[] sortFunctions)
        {
            IEnumerable <PKM> sortMethod(IEnumerable <PKM> pkms, int i) => pkms.OrderByCustom(sortFunctions);

            SaveFileEditor.SAV.SortBoxes(0, -1, sortMethod);
            SaveFileEditor.ReloadSlots();
        }
Esempio n. 3
0
        /// <summary>
        /// Function that generates legal PKM objects from ShowdownSets and views them/sets them in boxes
        /// </summary>
        /// <param name="sets">A list of ShowdownSet(s) that need to be genned</param>
        /// <param name="replace">A boolean that determines if current pokemon will be replaced or not</param>
        private static AutoModErrorCode ImportSetsToBoxes(IReadOnlyList <ShowdownSet> sets, bool replace)
        {
            // ALM Settings
            SetAPILegalitySettings();

            var timer   = Stopwatch.StartNew();
            var sav     = SaveFileEditor.SAV;
            var BoxData = sav.BoxData;
            var start   = sav.CurrentBox * sav.BoxSlotCount;

            Debug.WriteLine($"Commencing Import of {sets.Count} set(s).");
            var result = sav.ImportToExisting(sets, BoxData, start, replace);

            if (result != AutoModErrorCode.None)
            {
                return(result);
            }

            Debug.WriteLine("Multi Set Genning Complete. Setting data to the save file and reloading view.");
            SaveFileEditor.ReloadSlots();

            // Debug Statements
            timer.Stop();
            var timespan = timer.Elapsed;

            Debug.WriteLine($"Time to complete {nameof(ImportSetsToBoxes)}: {timespan.Minutes:00} minutes {timespan.Seconds:00} seconds {timespan.Milliseconds / 10:00} milliseconds");
            return(AutoModErrorCode.None);
        }
Esempio n. 4
0
        private void PersonalizeAll()
        {
            var sav   = SaveFileEditor.SAV;
            var count = sav.PersonalizeBoxes();

            if (count <= 0)
            {
                return;
            }
            SaveFileEditor.ReloadSlots();
            WinFormUtils.Alert($"Personalize {count} Pokemon across all boxes");
        }
        private void AutoEggAllBoxes()
        {
            var sav   = SaveFileEditor.SAV;
            var count = sav.SetEggBoxes();

            if (count <= 0)
            {
                return;
            }
            SaveFileEditor.ReloadSlots();
            WinFormUtils.Alert($"Set {count} Pokemon To Egg across all boxes");
        }
Esempio n. 6
0
        private void LegalizeAllBoxes()
        {
            var sav   = SaveFileEditor.SAV;
            var count = sav.LegalizeBoxes();

            if (count <= 0) // failed to modify anything
            {
                return;
            }
            SaveFileEditor.ReloadSlots();
            WinFormsUtil.Alert($"Legalized {count} Pokémon across all boxes!");
        }
Esempio n. 7
0
        private void LegalizeCurrent()
        {
            var sav   = SaveFileEditor.SAV;
            var count = sav.LegalizeBox(sav.CurrentBox);

            if (count <= 0) // failed to modify anything
            {
                return;
            }
            SaveFileEditor.ReloadSlots();
            WinFormsUtil.Alert($"Legalized {count} Pokémon in Current Box!");
        }
        private void RandPIDAllBoxes(string flag)
        {
            var sav   = SaveFileEditor.SAV;
            var count = sav.SetPIDBoxes(flag);

            if (count <= 0)
            {
                return;
            }
            SaveFileEditor.ReloadSlots();
            WinFormUtils.Alert($"Set {count} Pokemon To {flag} across all boxes");
        }
        private void RandPIDCurrentBox(string flag)
        {
            var sav   = SaveFileEditor.SAV;
            var count = sav.SetPIDBox(sav.CurrentBox, flag);

            if (count <= 0)
            {
                return;
            }
            SaveFileEditor.ReloadSlots();
            WinFormUtils.Alert($"Set {count} Pokemon To {flag} in current box");
        }
Esempio n. 10
0
        private void PersonalizeCurrentBox()
        {
            var sav   = SaveFileEditor.SAV;
            var count = sav.PersonalizeBox(sav.CurrentBox);

            if (count <= 0)
            {
                return;
            }
            SaveFileEditor.ReloadSlots();
            WinFormUtils.Alert($"Personalize {count} Pokemon in current box");
        }
        private void AutoEggCurrentBox()
        {
            var sav   = SaveFileEditor.SAV;
            var count = sav.SetEggBox(sav.CurrentBox);

            if (count <= 0)
            {
                return;
            }
            SaveFileEditor.ReloadSlots();
            WinFormUtils.Alert($"Set {count} Pokemon To Egg in current box");
        }
Esempio n. 12
0
        private void GenLivingDex(object sender, EventArgs e)
        {
            if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Generate a Living Dex?"))
            {
                return;
            }
            var sav  = SaveFileEditor.SAV;
            var pkms = sav.GenerateLivingDex();
            var bd   = sav.BoxData;

            pkms.CopyTo(bd);
            sav.BoxData = bd;
            SaveFileEditor.ReloadSlots();
        }
Esempio n. 13
0
        private void GenLivingDex(object sender, EventArgs e)
        {
            var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Generate a Living Dex?");

            if (prompt != DialogResult.Yes)
            {
                return;
            }

            var sav  = SaveFileEditor.SAV;
            var pkms = sav.GenerateLivingDex(out int attempts);
            var bd   = sav.BoxData;

            pkms.CopyTo(bd);
            sav.BoxData = bd;
            SaveFileEditor.ReloadSlots();

            System.Diagnostics.Debug.WriteLine($"Generated Living Dex after {attempts} attempts.");
        }
Esempio n. 14
0
        /// <summary>
        /// Function that generates legal PKM objects from ShowdownSets and views them/sets them in boxes
        /// </summary>
        /// <param name="sets">A list of ShowdownSet(s) that need to be generated</param>
        /// <param name="replace">A boolean that determines if current pokemon will be replaced or not</param>
        private static AutoModErrorCode ImportSetsToBoxes(IReadOnlyList <ShowdownSet> sets, bool replace)
        {
            var timer   = Stopwatch.StartNew();
            var sav     = SaveFileEditor.SAV;
            var BoxData = sav.BoxData;
            var start   = SaveFileEditor.CurrentBox * sav.BoxSlotCount;

            Debug.WriteLine($"Commencing Import of {sets.Count} set(s).");
            var result = sav.ImportToExisting(sets, BoxData, out var invalid, out var timeout, start, replace);

            if (timeout.Count > 0 || invalid.Count > 0)
            {
                var res = WinFormsUtil.ALMError(
                    $"{timeout.Count} set(s) timed out and {invalid.Count} set(s) are invalid. Please create an issue on GitHub and upload the error_log.txt file in the issue." +
                    "\n\nAlternatively, join the support Discord and post the same file in the #autolegality-livehex-help channel.");
                if (res == DialogResult.Yes)
                {
                    Process.Start("https://discord.gg/tDMvSRv");
                }
                else if (res == DialogResult.No)
                {
                    Process.Start("https://github.com/architdate/PKHeX-Plugins/issues");
                }
            }

            if (result != AutoModErrorCode.None)
            {
                return(result);
            }

            Debug.WriteLine("Multi Set Genning Complete. Setting data to the save file and reloading view.");
            SaveFileEditor.ReloadSlots();

            // Debug Statements
            timer.Stop();
            var timespan = timer.Elapsed;

            Debug.WriteLine($"Time to complete {nameof(ImportSetsToBoxes)}: {timespan.Minutes:00} minutes {timespan.Seconds:00} seconds {timespan.Milliseconds / 10:00} milliseconds");
            return(AutoModErrorCode.None);
        }
Esempio n. 15
0
 private void ModifySaveFile(Form connectform)
 {
     if (controller != null)
     {
         try
         {
             connectform.Controls[5].Font = new Font(connectform.Controls[5].Font.FontFamily, 8);
             var sav = SaveFileEditor.SAV;
             if (sav is SAV8SWSH)
             {
                 var selection = ((ComboBox)connectform.Controls[3]).SelectedIndex;
                 controller.Bot = new PokeSysBotMini(selection == -1 ? 0 : selection)
                 {
                     sys = { IP = connectform.Controls[1].Text, Port = 6000 }
                 };
                 controller.Bot.sys.Connect();
                 var data = controller.Bot.ReadSlot(1, 1);
                 var pkm  = sav.GetDecryptedPKM(data);
                 if (pkm.ChecksumValid)
                 {
                     connectform.Controls[5].Text = "Connected succesfully!";
                 }
                 var limit = selection == 6 ? 8 : 32; // Only read 8 boxes in the last case
                 for (int i = 0; i <= limit - 1; i++)
                 {
                     controller.ReadBox(i);
                 }
                 SaveFileEditor.ReloadSlots();
             }
             else
             {
                 connectform.Controls[5].Text = "Invalid Save File type. Please use a Sword/Shield save version.";
             }
         } catch (Exception)
         {
             connectform.Controls[5].Font = new Font(connectform.Controls[5].Font.FontFamily, 8);
             connectform.Controls[5].Text = "Something went wrong :-( \nCheck your sys-botbase installation and input the correct IP address.";
         }
     }
 }
Esempio n. 16
0
        public void AddToBoxesButtonClick(Object sender, EventArgs events)
        {
            var        sav          = SaveFileEditor.SAV;                                        // current save
            int        generation   = sav.Generation;                                            // the generation of the current save -- used to determine the PK save format
            List <PKM> pokemonList  = new List <PKM>();                                          // list of all Pokemon that will be added to the sav
            string     showdownData = this.input.Text;                                           // user's input

            var pokemonArray = JsonConvert.DeserializeObject <List <RawPokemon> >(showdownData); //jsonify the data

            foreach (RawPokemon rawPokemon in pokemonArray)
            {
                PKM pokemon = new PK2();

                //Determine save format
                switch (generation)
                {
                case 1:
                    pokemon = new PK1();
                    break;

                case 2:
                    pokemon = new PK2();
                    break;

                case 3:
                    pokemon = new PK3();
                    break;

                case 4:
                    pokemon = new PK4();
                    break;

                case 5:
                    pokemon = new PK5();
                    break;

                case 6:
                    pokemon = new PK6();
                    break;

                case 7:
                    pokemon = new PK7();
                    break;

                case 8:
                    pokemon = new PK8();
                    break;
                }

                // Set the species according to the Species enum
                int speciesAsNumber = 0;

                //Check if the Pokemon is Alolan or not; if it is, do some extra logic to set the proper form
                if (rawPokemon.Species.Contains("Alolan"))
                {
                    string[] pokemon_name = rawPokemon.Species.Split('_');
                    speciesAsNumber = (int)(Species)Enum.Parse(typeof(Species), pokemon_name[1]);
                    pokemon.SetForm(810);
                    pokemon.Species = speciesAsNumber;
                }
                else
                {
                    speciesAsNumber = (int)(Species)Enum.Parse(typeof(Species), rawPokemon.Species);
                    pokemon.Species = speciesAsNumber;
                }

                // Check to see if the Pokemon has forms (i.e. Flabebe, Shellos, etc.), and if it does, randomly generate one
                if (rawPokemon.Species.Contains("Burmy"))
                {
                    int form = random.Next(0, burmyForms.Length - 1);
                    pokemon.SetForm(form);
                }
                else if (rawPokemon.Species.Contains("Shellos"))
                {
                    int form = random.Next(0, shellosForms.Length - 1);
                    pokemon.SetForm(form);
                }
                else if (rawPokemon.Species.Contains("Scatterbug"))
                {
                    int form = random.Next(0, scatterbugForms.Length - 1);
                    pokemon.SetForm(form);
                }
                else if (rawPokemon.Species.Contains("Flabébé"))
                {
                    int form = random.Next(0, flabebeForms.Length - 1);
                    pokemon.SetForm(form);
                }
                else if (rawPokemon.Species.Contains("Oricorio"))
                {
                    int form = random.Next(0, oricorioForms.Length - 1);
                    pokemon.SetForm(form);
                }
                else if (rawPokemon.Species.Contains("Minior"))
                {
                    int form = random.Next(0, miniorForms.Length - 1);
                    pokemon.SetForm(form);
                }

                GameVersion  game         = (GameVersion)sav.Game;
                EncounterEgg encounterEgg = new EncounterEgg(speciesAsNumber, pokemon.Form, 1, sav.Generation, game);
                PKM          pokemonAsEgg = encounterEgg.ConvertToPKM(sav);
                pokemonAsEgg.IsEgg  = true;
                pokemon.IsNicknamed = true;
                pokemon.Nickname    = "Egg";

                // Set the ability
                string ability         = rawPokemon.Ability.Replace(" ", "");
                int    abilityAsNumber = (int)(Ability)Enum.Parse(typeof(Ability), ability);
                pokemonAsEgg.SetAbility(abilityAsNumber);

                //Set gender
                switch (rawPokemon.Gender)
                {
                case "M":
                    pokemonAsEgg.SetGender(0);
                    break;

                case "F":
                    pokemonAsEgg.SetGender(1);
                    break;

                case "N":
                    pokemonAsEgg.SetGender(2);
                    break;
                }

                // Set Nature via the Nature enum
                int natureAsNumber = (int)(Nature)Enum.Parse(typeof(Nature), rawPokemon.Nature);
                pokemonAsEgg.Nature = natureAsNumber;

                // Set the IVs
                pokemonAsEgg.IV_HP  = rawPokemon.HP;
                pokemonAsEgg.IV_ATK = rawPokemon.Atk;
                pokemonAsEgg.IV_DEF = rawPokemon.Def;
                pokemonAsEgg.IV_SPA = rawPokemon.SpA;
                pokemonAsEgg.IV_SPD = rawPokemon.SpD;
                pokemonAsEgg.IV_SPE = rawPokemon.Spe;

                // Set moves and make sure they have the proper PP
                string move = "";
                if (string.IsNullOrEmpty(rawPokemon.MoveOne) == false)
                {
                    move = rawPokemon.MoveOne.Replace("-", "");
                    move = move.Replace(" ", "");
                    pokemonAsEgg.Move1        = (int)(Move)Enum.Parse(typeof(Move), move);
                    pokemonAsEgg.RelearnMove1 = pokemonAsEgg.Move1;
                }
                if (string.IsNullOrEmpty(rawPokemon.MoveTwo) == false)
                {
                    move = rawPokemon.MoveTwo.Replace("-", "");
                    move = move.Replace(" ", "");
                    pokemonAsEgg.Move2        = (int)(Move)Enum.Parse(typeof(Move), move);
                    pokemonAsEgg.RelearnMove2 = pokemonAsEgg.Move2;
                }
                if (string.IsNullOrEmpty(rawPokemon.MoveThree) == false)
                {
                    move = rawPokemon.MoveThree.Replace("-", "");
                    move = move.Replace(" ", "");
                    pokemonAsEgg.Move3        = (int)(Move)Enum.Parse(typeof(Move), move);
                    pokemonAsEgg.RelearnMove3 = pokemonAsEgg.Move3;
                }
                if (string.IsNullOrEmpty(rawPokemon.MoveFour) == false)
                {
                    move = rawPokemon.MoveFour.Replace("-", "");
                    move = move.Replace(" ", "");
                    pokemonAsEgg.Move4        = (int)(Move)Enum.Parse(typeof(Move), move);
                    pokemonAsEgg.RelearnMove4 = pokemonAsEgg.Move4;
                }

                pokemonAsEgg.SetMaximumPPCurrent();

                //Finally, if the Pokemon is supposed to be shiny, make it so
                if (rawPokemon.IsShiny == "true")
                {
                    CommonEdits.SetShiny(pokemonAsEgg);
                }
                else
                {
                    CommonEdits.SetUnshiny(pokemonAsEgg);
                }

                pokemonAsEgg.Met_Location = 0;

                if (generation == 7 || generation == 6 || generation == 5)
                {
                    pokemonAsEgg.Egg_Location = Locations.Daycare5;
                }
                else
                {
                    pokemonAsEgg.Egg_Location = Locations.Daycare4;
                }

                pokemonAsEgg.IsNicknamed = true;
                pokemonAsEgg.Nickname    = SpeciesName.GetSpeciesNameGeneration(0, sav.Language, generation);

                //Hatch counter is for some reason called "CurrentFriendship".  Don't ask me why, I don't know.
                pokemonAsEgg.CurrentFriendship = 1;

                pokemonList.Add(pokemonAsEgg);
            }

            // Import Pokemon, reload the boxes so they can be seen, show a message and close the window
            sav.ImportPKMs(pokemonList);
            SaveFileEditor.ReloadSlots();
            MessageBox.Show("Done!");
            this.input.Clear();
            this.form.Close();
        }
Esempio n. 17
0
 private void SortByNationalDex()
 {
     SaveFileEditor.SAV.SortBoxes();
     SaveFileEditor.ReloadSlots();
 }
Esempio n. 18
0
 private void ModifySaveFile()
 {
     // Make everything Bulbasaur!
     SaveFileEditor.SAV.ModifyBoxes(pk => pk.Species = 1);
     SaveFileEditor.ReloadSlots();
 }
Esempio n. 19
0
        private void Legalize(object sender, EventArgs e)
        {
            AutomaticLegality.PKMEditor         = PKMEditor;
            AutomaticLegality.SaveFileEditor    = SaveFileEditor;
            AutoLegalityMod.AutoLegalityMod.SAV = SaveFileEditor.SAV;
            IList <PKM> BoxData = SaveFileEditor.SAV.BoxData;

            for (int i = 0; i < 30; i++)
            {
                PKM  illegalPK = PKMEditor.PreparePKM();
                bool box       = false;
                if ((Control.ModifierKeys & Keys.Control) == Keys.Control)
                {
                    box = true;
                }

                if (box && BoxData.Count > (SaveFileEditor.CurrentBox * SaveFileEditor.SAV.BoxSlotCount) + i)
                {
                    illegalPK = BoxData[(SaveFileEditor.CurrentBox * SaveFileEditor.SAV.BoxSlotCount) + i];
                }

                if (illegalPK.Species > 0 && !new LegalityAnalysis(illegalPK).Valid)
                {
                    ShowdownSet Set       = new ShowdownSet(ShowdownSet.GetShowdownText(illegalPK));
                    bool        resetForm = false;
                    if (Set.Form != null)
                    {
                        if (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted")
                        {
                            resetForm = true;
                        }
                    }
                    PKM  legal;
                    PKM  APIGenerated = SaveFileEditor.SAV.BlankPKM;
                    bool satisfied    = false;
                    try { APIGenerated = AutoLegalityMod.AutoLegalityMod.APILegality(illegalPK, Set, out satisfied); }
                    catch { satisfied = false; }
                    if (!satisfied)
                    {
                        BruteForce b = new BruteForce {
                            SAV = SaveFileEditor.SAV
                        };
                        legal = b.LoadShowdownSetModded_PKSM(illegalPK, Set, resetForm, illegalPK.TID, illegalPK.SID, illegalPK.OT_Name, illegalPK.OT_Gender);
                    }
                    else
                    {
                        legal = APIGenerated;
                    }

                    legal = AutoLegalityMod.AutoLegalityMod.SetTrainerData(illegalPK.OT_Name, illegalPK.TID, illegalPK.SID, illegalPK.OT_Gender, legal, satisfied);

                    if (box)
                    {
                        BoxData[(SaveFileEditor.CurrentBox * SaveFileEditor.SAV.BoxSlotCount) + i] = legal;
                    }
                    else
                    {
                        PKMEditor.PopulateFields(legal);
                        MessageBox.Show("Legalized Active Pokemon.");
                        return;
                    }
                }
            }
            SaveFileEditor.SAV.BoxData = BoxData;
            SaveFileEditor.ReloadSlots();
            MessageBox.Show("Legalized Box Pokemon");
        }
Esempio n. 20
0
        /// <summary>
        /// Function that generates legal PKM objects from ShowdownSets and views them/sets them in boxes
        /// </summary>
        /// <param name="sets">A list of ShowdownSet(s) that need to be genned</param>
        /// <param name="replace">A boolean that determines if current pokemon will be replaced or not</param>
        /// <param name="message">Output message to be displayed for the user</param>
        /// <param name="allowAPI">Use of generators before bruteforcing</param>
        private static void ImportSets(List <ShowdownSet> sets, bool replace, out string message, bool allowAPI = true)
        {
            message = "[DEBUG] Commencing Import";
            List <int>  emptySlots = new List <int>();
            IList <PKM> BoxData    = SAV.BoxData;
            int         BoxOffset  = SaveFileEditor.CurrentBox * SAV.BoxSlotCount;

            if (replace)
            {
                emptySlots = Enumerable.Range(0, sets.Count).ToList();
            }
            else
            {
                emptySlots = PopulateEmptySlots(BoxData, SaveFileEditor.CurrentBox);
            }
            if (emptySlots.Count < sets.Count && sets.Count != 1)
            {
                message = "Not enough space in the box"; return;
            }
            int apiCounter = 0;
            List <ShowdownSet> invalidAPISets = new List <ShowdownSet>();

            for (int i = 0; i < sets.Count; i++)
            {
                ShowdownSet Set = sets[i];
                if (sets.Count == 1 && DialogResult.Yes != Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.Text))
                {
                    return;
                }
                if (Set.InvalidLines.Count > 0)
                {
                    Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines));
                }
                bool resetForm = false;
                if (Set.Form != null && (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted"))
                {
                    resetForm = true;
                }
                PKM roughPKM = SAV.BlankPKM;
                roughPKM.ApplySetDetails(Set);
                roughPKM.Version = (int)GameVersion.MN; // Avoid the blank version glitch
                PKM  legal     = SAV.BlankPKM;
                bool satisfied = false;
                if (allowAPI)
                {
                    PKM APIGeneratedPKM = SAV.BlankPKM;
                    try { APIGeneratedPKM = AutoLegalityMod.APILegality(roughPKM, Set, out satisfied); }
                    catch { satisfied = false; }
                    if (satisfied)
                    {
                        legal = APIGeneratedPKM;
                        apiCounter++;
                        APILegalized = true;
                    }
                }
                if (!allowAPI || !satisfied)
                {
                    invalidAPISets.Add(Set);
                    BruteForce b = new BruteForce {
                        SAV = SAV
                    };
                    legal        = b.LoadShowdownSetModded_PKSM(roughPKM, Set, resetForm, TID_ALM, SID_ALM, OT_ALM, gender_ALM);
                    APILegalized = false;
                }
                PKM pk = SetTrainerData(legal, sets.Count == 1);
                if (sets.Count > 1)
                {
                    BoxData[BoxOffset + emptySlots[i]] = pk;
                }
            }
            if (sets.Count > 1)
            {
                SAV.BoxData = BoxData;
                SaveFileEditor.ReloadSlots();
                message = "[DEBUG] API Genned Sets: " + apiCounter + Environment.NewLine + Environment.NewLine + "Number of sets not genned by the API: " + invalidAPISets.Count;
                foreach (ShowdownSet i in invalidAPISets)
                {
                    Debug.WriteLine(i.Text);
                }
            }
            else
            {
                message = "[DEBUG] Set Genning Complete";
            }
        }