Esempio n. 1
0
        public Main()
        {
            string[] args = Environment.GetCommandLineArgs();
            FormLoadInitialSettings(args, out bool showChangelog, out bool BAKprompt);

            InitializeComponent();
            C_SAV.SetEditEnvironment(new SaveDataEditor <PictureBox>(new FakeSaveFile(), PKME_Tabs));
            FormLoadAddEvents();
            #if DEBUG // translation updater -- all controls are added at this point -- call translate now
            if (DevUtil.IsUpdatingTranslations)
            {
                WinFormsUtil.TranslateInterface(this, CurrentLanguage); // Translate the UI to language.
            }
            #endif
            FormInitializeSecond();
            FormLoadCheckForUpdates();

            var startup = new StartupArguments();
            startup.ReadArguments(args);
            startup.ReadSettings(Settings.Startup);
            startup.ReadTemplateIfNoEntity(TemplatePath);
            FormLoadInitialFiles(startup);

            if (Settings.Startup.PluginLoadMethod != PluginLoadSetting.DontLoad)
            {
                FormLoadPlugins();
            }

            if (HaX)
            {
                PKMConverter.AllowIncompatibleConversion = true;
                WinFormsUtil.Alert(MsgProgramIllegalModeActive, MsgProgramIllegalModeBehave);
            }
            else if (showChangelog)
            {
                ShowAboutDialog(AboutPage.Changelog);
            }

            if (BAKprompt && !Directory.Exists(BackupPath))
            {
                PromptBackup();
            }

            BringToFront();
            WindowState = FormWindowState.Minimized;
            Show();
            WindowState = FormWindowState.Normal;
        }
Esempio n. 2
0
        public Main()
        {
            Form splash = null; // popup a splash screen in another thread

            new Task(() => (splash = new SplashScreen()).ShowDialog()).Start();
            new Task(() => EncounterEvent.RefreshMGDB(MGDatabasePath)).Start();
            string[] args = Environment.GetCommandLineArgs();
            FormLoadInitialSettings(args, out bool showChangelog, out bool BAKprompt);

            InitializeComponent();
            C_SAV.SetEditEnvironment(new SaveDataEditor <PictureBox>(null, PKME_Tabs));
            FormLoadAddEvents();
            #if DEBUG // translation updater -- all controls are added at this point -- call translate now
            if (DevUtil.IsUpdatingTranslations)
            {
                WinFormsUtil.TranslateInterface(this, CurrentLanguage); // Translate the UI to language.
            }
            #endif
            FormInitializeSecond();

            FormLoadCustomBackupPaths();
            FormLoadInitialFiles(args);
            FormLoadCheckForUpdates();
            FormLoadPlugins();

            BringToFront();
            WindowState = FormWindowState.Minimized;
            Show();
            WindowState = FormWindowState.Normal;
            splash.Invoke((MethodInvoker)(() => splash.Close())); // splash closes
            if (HaX)
            {
                PKMConverter.AllowIncompatibleConversion = true;
                WinFormsUtil.Alert(MsgProgramIllegalModeActive, MsgProgramIllegalModeBehave);
            }
            else if (showChangelog)
            {
                ShowAboutDialog(1);
            }

            if (BAKprompt && !Directory.Exists(BackupPath))
            {
                PromptBackup();
            }
        }
        /// <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";
            }
        }
Esempio n. 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");
        }