Exemple #1
0
        private void ClickShowdownImportPKMModded(object sender, EventArgs e)
        {
            if (!Clipboard.ContainsText())
            {
                WinFormsUtil.Alert("Clipboard does not contain text."); return;
            }

            if (!Directory.Exists(MGDatabasePath))
            {
                Directory.CreateDirectory(MGDatabasePath);
            }

            int    TID           = -1;
            int    SID           = -1;
            string OT            = "";
            int    gender        = 0;
            string Country       = "";
            string SubRegion     = "";
            string ConsoleRegion = "";

            if (File.Exists(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\trainerdata.txt"))
            {
                string   text  = File.ReadAllText(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\trainerdata.txt", System.Text.Encoding.UTF8);
                string[] lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                TID = Convert.ToInt32(lines[0].Split(':')[1].Trim());
                SID = Convert.ToInt32(lines[1].Split(':')[1].Trim());
                OT  = lines[2].Split(':')[1].Trim();
                if (lines[3].Split(':')[1].Trim() == "F" || lines[3].Split(':')[1].Trim() == "Female")
                {
                    gender = 1;
                }
                try
                {
                    Country       = lines[4].Split(':')[1].Trim();
                    SubRegion     = lines[5].Split(':')[1].Trim();
                    ConsoleRegion = lines[6].Split(':')[1].Trim();
                }
                catch { }
            }

            string source = Clipboard.GetText().TrimEnd();

            string[] stringSeparators = new string[] { "\n\r" };
            string[] result;

            // ...
            result = source.Split(stringSeparators, StringSplitOptions.None);
            Console.WriteLine(result.Length);

            if (result.Length > 1)
            {
                for (int i = 0; i < result.Length; i++)
                {
                    ShowdownSet Set = new ShowdownSet(result[i]);
                    if (Set.InvalidLines.Any())
                    {
                        WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines));
                    }

                    // Set Species & Nickname
                    bool resetForm = false;
                    PKME_Tabs.hardReset();
                    if (Set.Form == null)
                    {
                    }
                    else if (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted")
                    {
                        resetForm = true;
                        Console.WriteLine(Set.Species);
                    }
                    PKME_Tabs.LoadShowdownSet(Set);
                    PKM p = PreparePKM();
                    p.Version = (int)GameVersion.MN;
                    Blah b     = new Blah();
                    PKM  legal = b.LoadShowdownSetModded_PKSM(p, Set, resetForm, TID, SID, OT, gender);
                    PKME_Tabs.PopulateFields(legal);
                    if (Country != "" && SubRegion != "" && ConsoleRegion != "")
                    {
                        PKME_Tabs.SetRegions(Country, SubRegion, ConsoleRegion);
                    }
                    PKM pk = PreparePKM();
                    PKME_Tabs.ClickSet(C_SAV.Box.SlotPictureBoxes[0], i);
                }
            }
            else
            {
                // Get Simulator Data
                ShowdownSet Set = new ShowdownSet(Clipboard.GetText());

                if (Set.Species < 0)
                {
                    WinFormsUtil.Alert("Set data not found in clipboard."); return;
                }

                if (Set.Nickname?.Length > C_SAV.SAV.NickLength)
                {
                    Set.Nickname = Set.Nickname.Substring(0, C_SAV.SAV.NickLength);
                }

                if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.Text))
                {
                    return;
                }

                if (Set.InvalidLines.Any())
                {
                    WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines));
                }

                // Set Species & Nickname
                //PKME_Tabs.LoadShowdownSet(Set);
                bool resetForm = false;
                PKME_Tabs.hardReset();
                if (Set.Form == null)
                {
                }
                else if (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted")
                {
                    resetForm = true;
                    Console.WriteLine(Set.Species);
                }
                PKME_Tabs.LoadShowdownSet(Set);
                PKM p = PreparePKM();
                p.Version = (int)GameVersion.MN;
                Blah b     = new Blah();
                PKM  legal = b.LoadShowdownSetModded_PKSM(p, Set, resetForm, TID, SID, OT, gender);
                PKME_Tabs.PopulateFields(legal);
                if (Country != "" && SubRegion != "" && ConsoleRegion != "")
                {
                    PKME_Tabs.SetRegions(Country, SubRegion, ConsoleRegion);
                }
            }
        }
Exemple #2
0
        private void ClickShowdownImportPKMModded(object sender, EventArgs e)
        {
            if (!showdownData() || (ModifierKeys & Keys.Shift) == Keys.Shift)
            {
                if (WinFormsUtil.OpenSAVPKMDialog(new string[] { "txt" }, out string path))
                {
                    Clipboard.SetText(File.ReadAllText(path).TrimEnd());
                    if (!showdownData())
                    {
                        WinFormsUtil.Alert("Text file with invalid data provided. Please provide a text file with proper Showdown data");
                        return;
                    }
                }
                else
                {
                    WinFormsUtil.Alert("No data provided.");
                    return;
                }
            }

            if (!Directory.Exists(MGDatabasePath))
            {
                Directory.CreateDirectory(MGDatabasePath);
            }


            string[] tdataVals = PKME_Tabs.parseTrainerData(C_SAV);

            int    TID = Convert.ToInt32(tdataVals[0]);
            int    SID = Convert.ToInt32(tdataVals[1]);
            string OT  = tdataVals[2];

            if (OT == "PKHeX")
            {
                OT = "Archit(TCD)";                // Avoids secondary handler error
            }
            int gender = 0;

            if (tdataVals[3] == "F" || tdataVals[3] == "Female")
            {
                gender = 1;
            }
            string Country       = tdataVals[4];
            string SubRegion     = tdataVals[5];
            string ConsoleRegion = tdataVals[6];

            string source = Clipboard.GetText().TrimEnd();

            string[] stringSeparators = new string[] { "\n\r" };
            string[] result;

            // ...
            result = source.Split(stringSeparators, StringSplitOptions.None);
            Console.WriteLine(result.Length);

            if (result.Length > 1)
            {
                List <int> emptySlots = new List <int> {
                };
                if ((ModifierKeys & Keys.Control) == Keys.Control) // Hold Ctrl while clicking to replace
                {
                    for (int i = 0; i < result.Length; i++)
                    {
                        emptySlots.Add(i);
                    }
                }
                else
                {
                    for (int i = 0; i < C_SAV.Box.BoxSlotCount; i++)
                    {
                        if ((C_SAV.Box.SlotPictureBoxes[i] as PictureBox)?.Image == null)
                        {
                            emptySlots.Add(i);
                        }
                    }
                    if (emptySlots.Count < result.Length)
                    {
                        WinFormsUtil.Alert("Not enough space in the box");
                        return;
                    }
                }
                for (int i = 0; i < result.Length; i++)
                {
                    ShowdownSet Set = new ShowdownSet(result[i]);
                    if (Set.InvalidLines.Any())
                    {
                        WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines));
                    }

                    // Set Species & Nickname
                    bool resetForm = false;
                    PKME_Tabs.hardReset(C_SAV.SAV);
                    if (Set.Form == null)
                    {
                    }
                    else if (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted")
                    {
                        resetForm = true;
                        Console.WriteLine(Set.Species);
                    }
                    PKME_Tabs.LoadShowdownSet(Set);
                    PKM p = PreparePKM();
                    p.Version = (int)GameVersion.MN;
                    Blah b = new Blah();
                    b.C_SAV = C_SAV;
                    PKM legal = b.LoadShowdownSetModded_PKSM(p, Set, resetForm, TID, SID, OT, gender);
                    if (int.TryParse(Country, out int n) && int.TryParse(SubRegion, out int m) && int.TryParse(ConsoleRegion, out int o))
                    {
                        legal         = PKME_Tabs.SetPKMRegions(n, m, o, legal);
                        Country       = "";
                        SubRegion     = "";
                        ConsoleRegion = "";
                    }
                    PKME_Tabs.PopulateFields(legal);
                    if (Country != "" && SubRegion != "" && ConsoleRegion != "")
                    {
                        PKME_Tabs.SetRegions(Country, SubRegion, ConsoleRegion);
                    }
                    PKM pk = PreparePKM();
                    PKME_Tabs.ClickSet(C_SAV.Box.SlotPictureBoxes[0], emptySlots[i]);
                }
            }
            else
            {
                // Get Simulator Data
                ShowdownSet Set = new ShowdownSet(Clipboard.GetText());

                if (Set.Species < 0)
                {
                    WinFormsUtil.Alert("Set data not found in clipboard."); return;
                }

                if (Set.Nickname?.Length > C_SAV.SAV.NickLength)
                {
                    Set.Nickname = Set.Nickname.Substring(0, C_SAV.SAV.NickLength);
                }

                if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.Text))
                {
                    return;
                }

                if (Set.InvalidLines.Any())
                {
                    WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines));
                }

                // Set Species & Nickname
                //PKME_Tabs.LoadShowdownSet(Set);
                bool resetForm = false;
                PKME_Tabs.hardReset(C_SAV.SAV);

                if (Set.Form == null)
                {
                }
                else if (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted")
                {
                    Set       = new ShowdownSet(Set.Text.Replace("-" + Set.Form, ""));
                    resetForm = true;
                    Console.WriteLine(Set.Species);
                }
                PKME_Tabs.LoadShowdownSet(Set);
                PKM p = PreparePKM();
                p.Version = (int)GameVersion.MN;
                Blah b = new Blah();
                b.C_SAV = C_SAV;
                PKM legal = b.LoadShowdownSetModded_PKSM(p, Set, resetForm, TID, SID, OT, gender);
                if (int.TryParse(Country, out int n) && int.TryParse(SubRegion, out int m) && int.TryParse(ConsoleRegion, out int o))
                {
                    legal         = PKME_Tabs.SetPKMRegions(n, m, o, legal);
                    Country       = "";
                    SubRegion     = "";
                    ConsoleRegion = "";
                }
                PKME_Tabs.PopulateFields(legal);
                if (legal.Format < 7)
                {
                    PKME_Tabs.LoadFieldsFromPKM2(legal, true, false);
                }
                if (Country != "" && SubRegion != "" && ConsoleRegion != "")
                {
                    PKME_Tabs.SetRegions(Country, SubRegion, ConsoleRegion);
                }
            }
        }
        /// <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   = C_SAV.SAV.BoxData;
            int         BoxOffset = C_SAV.CurrentBox * C_SAV.SAV.BoxSlotCount;

            if (replace)
            {
                emptySlots = Enumerable.Range(0, sets.Count).ToList();
            }
            else
            {
                emptySlots = PopulateEmptySlots(BoxData, C_SAV.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 != PKHeX.WinForms.WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.Text))
                {
                    return;
                }
                if (Set.InvalidLines.Count > 0)
                {
                    PKHeX.WinForms.WinFormsUtil.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 = C_SAV.SAV.BlankPKM;
                roughPKM.ApplySetDetails(Set);
                roughPKM.Version = (int)GameVersion.MN; // Avoid the blank version glitch
                PKM  legal     = C_SAV.SAV.BlankPKM;
                bool satisfied = false;
                if (allowAPI)
                {
                    PKM APIGeneratedPKM = C_SAV.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);
                    Blah b = new Blah {
                        SAV = C_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)
            {
                C_SAV.SAV.BoxData = BoxData;
                C_SAV.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";
            }
        }
Exemple #4
0
        private void LegalizeBoxes(object sender, EventArgs e)
        {
            IList <PKM> BoxData = C_SAV.SAV.BoxData;

            for (int i = 0; i < 30; i++)
            {
                PKM  illegalPK = PreparePKM();
                bool box       = false;
                if ((ModifierKeys & Keys.Control) == Keys.Control)
                {
                    box = true;
                }
                if (box)
                {
                    illegalPK = BoxData[C_SAV.CurrentBox * C_SAV.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 = C_SAV.SAV.BlankPKM;
                    bool satisfied    = false;
                    try {
                        APIGenerated = AutoLegalityModMain.AutoLegalityMod.APILegality(illegalPK, Set, out satisfied);
                    }
                    catch {
                        satisfied = false;
                    }
                    if (!satisfied)
                    {
                        Blah b = new Blah();
                        b.SAV = C_SAV.SAV;
                        legal = b.LoadShowdownSetModded_PKSM(illegalPK, Set, resetForm, illegalPK.TID, illegalPK.SID, illegalPK.OT_Name, illegalPK.OT_Gender);
                    }
                    else
                    {
                        legal = APIGenerated;
                    }
                    legal = PKME_Tabs.SetTrainerData(illegalPK.OT_Name, illegalPK.TID, illegalPK.SID, illegalPK.OT_Gender, legal, satisfied);
                    if (box)
                    {
                        BoxData[C_SAV.CurrentBox * C_SAV.SAV.BoxSlotCount + i] = legal;
                    }
                    else
                    {
                        PKME_Tabs.PopulateFields(legal);
                        WinFormsUtil.Alert("Legalized Active Pokemon.");
                        return;
                    }
                }
            }
            C_SAV.SAV.BoxData = BoxData;
            C_SAV.ReloadSlots();
            WinFormsUtil.Alert("Legalized Box Pokemon");
        }