Exemple #1
0
        /// <summary>
        /// Loads the trainerdata variables into the global variables for AutoLegalityMod
        /// </summary>
        /// <param name="legal">Optional legal PKM for loading trainerdata on a per game basis</param>
        private static void LoadTrainerData(PKM legal = null)
        {
            bool checkPerGame = (AutoLegalityMod.CheckMode() == "game");
            // If mode is not set as game: (auto or save)
            var tdataVals = !checkPerGame || legal == null
                ? AutoLegalityMod.ParseTrainerJSON(SAV)
                : AutoLegalityMod.ParseTrainerJSON(SAV, legal.Version);

            TID_ALM = Convert.ToInt32(tdataVals[0]);
            SID_ALM = Convert.ToInt32(tdataVals[1]);
            if (legal != null)
            {
                SID_ALM = legal.VC ? 0 : SID_ALM;
            }

            OT_ALM = tdataVals[2];
            if (OT_ALM == "PKHeX")
            {
                OT_ALM = "Archit(TCD)";                    // Avoids secondary handler error
            }
            gender_ALM = 0;
            if (tdataVals[3] == "F" || tdataVals[3] == "Female")
            {
                gender_ALM = 1;
            }
            Country_ALM       = tdataVals[4];
            SubRegion_ALM     = tdataVals[5];
            ConsoleRegion_ALM = tdataVals[6];
            if ((checkPerGame && legal != null) || APILegalized)
            {
                legal = AutoLegalityMod.SetTrainerData(OT_ALM, TID_ALM, SID_ALM, gender_ALM, legal, APILegalized);
            }
        }
Exemple #2
0
        public static void ImportModded()
        {
            Stopwatch timer = Stopwatch.StartNew();
            // TODO: Check for Auto Legality Mod Updates
            const bool allowAPI = true; // Use true to allow experimental API usage

            APILegalized = false;       // Initialize to false everytime command is used

            // Check for lack of showdown data provided
            CheckLoadFromText(out bool valid);
            if (!valid)
            {
                return;
            }

            // Make a blank MGDB directory and initialize trainerdata
            if (!Directory.Exists(MGDatabasePath))
            {
                Directory.CreateDirectory(MGDatabasePath);
            }
            if (AutoLegalityMod.CheckMode() != "game")
            {
                LoadTrainerData();
            }

            // Get Text source from clipboard and convert to ShowdownSet(s)
            string             source = Clipboard.GetText().TrimEnd();
            List <ShowdownSet> Sets   = ShowdownSets(source, out Dictionary <int, string[]> TeamData);

            if (TeamData != null)
            {
                Alert(TeamDataAlert(TeamData));
            }

            // Import Showdown Sets and alert user of any messages intended
            ImportSets(Sets, (Control.ModifierKeys & Keys.Control) == Keys.Control, out string message, allowAPI);

            // Debug Statements
            Debug.WriteLine(LogTimer(timer));
            if (message.StartsWith("[DEBUG]"))
            {
                Debug.WriteLine(message);
            }
            else
            {
                Alert(message);
            }
        }
Exemple #3
0
        /// <summary>
        /// Set trainer data for a legal PKM
        /// </summary>
        /// <param name="legal">Legal PKM for setting the data</param>
        /// <param name="display"></param>
        /// <returns>PKM with the necessary values modified to reflect trainerdata changes</returns>
        private static PKM SetTrainerData(PKM legal, bool display)
        {
            bool intRegions = false;

            LoadTrainerData(legal);
            if (int.TryParse(Country_ALM, out int n) && int.TryParse(SubRegion_ALM, out int m) && int.TryParse(ConsoleRegion_ALM, out int o))
            {
                legal      = AutoLegalityMod.SetPKMRegions(n, m, o, legal);
                intRegions = true;
            }
            if (display)
            {
                PKMEditor.PopulateFields(legal);
            }
            if (!intRegions)
            {
                AutoLegalityMod.SetRegions(Country_ALM, SubRegion_ALM, ConsoleRegion_ALM, legal);
                return(legal);
            }
            return(legal);
        }
Exemple #4
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";
            }
        }