示例#1
0
        private void MoveBox(object sender, EventArgs e)
        {
            int index = LB_BoxSelect.SelectedIndex;
            int dir   = sender == B_Up ? -1 : +1;

            editing = renamingBox = true;
            if (!MoveItem(dir))
            {
                System.Media.SystemSounds.Asterisk.Play();
            }
            else if (!SAV.SwapBox(index, index + dir)) // valid but locked
            {
                MoveItem(-dir);                        // undo
                WinFormsUtil.Alert("Locked/Team slots prevent movement of box(es).");
            }
            else
            {
                ChangeBox(null, EventArgs.Empty);
            }

            editing = renamingBox = false;
        }
示例#2
0
        private void Menu_DeleteClones_Click(object sender, EventArgs e)
        {
            var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo,
                                         MsgDBDeleteCloneWarning + Environment.NewLine +
                                         MsgDBDeleteCloneAdvice, MsgContinue);

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

            var deleted = 0;
            var db      = RawDB.Where(pk => pk.Identifier != null && pk.Identifier.StartsWith(DatabasePath + Path.DirectorySeparatorChar, StringComparison.Ordinal))
                          .OrderByDescending(file => File.GetLastWriteTimeUtc(file.Identifier));

            var clones = SearchUtil.GetExtraClones(db);

            foreach (var pk in clones)
            {
                var path = pk.Identifier;
                if (path == null || !File.Exists(path))
                {
                    continue;
                }

                try { File.Delete(path); ++deleted; }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception ex) { WinFormsUtil.Error(MsgDBDeleteCloneFail + Environment.NewLine + ex.Message + Environment.NewLine + pk.Identifier); }
#pragma warning restore CA1031 // Do not catch general exception types
            }

            if (deleted == 0)
            {
                WinFormsUtil.Alert(MsgDBDeleteCloneNone); return;
            }

            WinFormsUtil.Alert(string.Format(MsgFileDeleteCount, deleted), MsgWindowClose);
            Close();
        }
示例#3
0
        private void RunBatchEdit(StringInstructionSet[] sets, string source, string?destination)
        {
            editor = new Core.BatchEditor();
            bool finished = false, displayed = false; // hack cuz DoWork event isn't cleared after completion

            b.DoWork += (sender, e) =>
            {
                if (finished)
                {
                    return;
                }
                if (RB_Boxes.Checked)
                {
                    RunBatchEditSaveFile(sets, boxes: true);
                }
                else if (RB_Party.Checked)
                {
                    RunBatchEditSaveFile(sets, party: true);
                }
                else if (destination != null)
                {
                    RunBatchEditFolder(sets, source, destination);
                }
                finished = true;
            };
            b.ProgressChanged    += (sender, e) => SetProgressBar(e.ProgressPercentage);
            b.RunWorkerCompleted += (sender, e) =>
            {
                string result = editor.GetEditorResults(sets);
                if (!displayed)
                {
                    WinFormsUtil.Alert(result);
                }
                displayed      = true;
                FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = true;
                SetupProgressBar(0);
            };
            b.RunWorkerAsync();
        }
示例#4
0
        private void MoveForm(object sender, EventArgs e)
        {
            if (editing)
            {
                return;
            }
            var lb = LB_Form;

            if (lb == null || lb.SelectedIndex < 0)
            {
                WinFormsUtil.Alert("No Form selected.");
                return;
            }

            int index = lb.SelectedIndex;
            int delta = sender == B_FUp ? -1 : 1;

            if (index == 0 && lb.Items.Count == 1)
            {
                return;
            }

            int newIndex = index + delta;

            if (newIndex < 0)
            {
                return;
            }
            if (newIndex >= lb.Items.Count)
            {
                return;
            }

            var item = lb.SelectedItem;

            lb.Items.Remove(item);
            lb.Items.Insert(newIndex, item);
            lb.SelectedIndex = newIndex;
        }
示例#5
0
        private void ToggleForm(object sender, EventArgs e)
        {
            if (editing)
            {
                return;
            }
            var lb = sender == B_FLeft ? LB_NForm : LB_Form;

            if (lb == null || lb.SelectedIndex < 0)
            {
                WinFormsUtil.Alert("No Form selected.");
                return;
            }

            var item = lb.SelectedItem;

            lb.Items.RemoveAt(lb.SelectedIndex);
            var dest = lb == LB_Form ? LB_NForm : LB_Form;

            dest.Items.Add(item);
            dest.SelectedIndex = dest.Items.Count - 1;
        }
示例#6
0
        private void toggleSeen(object sender, EventArgs e)
        {
            if (editing)
            {
                return;
            }
            var lb = sender == B_GLeft ? LB_NGender : LB_Gender;

            if (lb == null || lb.SelectedIndex < 0)
            {
                WinFormsUtil.Alert("No Gender selected.");
                return;
            }

            var item = lb.SelectedItem;

            lb.Items.RemoveAt(lb.SelectedIndex);
            var dest = lb == LB_Gender ? LB_NGender : LB_Gender;

            dest.Items.Add(item);
            dest.SelectedIndex = dest.Items.Count - 1;
        }
示例#7
0
        private void getBags()
        {
            foreach (InventoryPouch pouch in Pouches)
            {
                DataGridView dgv = Controls.Find(DGVPrefix + pouch.Type, true).FirstOrDefault() as DataGridView;

                // Sanity Screen
                var invalid = pouch.Items.Where(item => item.Index != 0 && !pouch.LegalItems.Contains((ushort)item.Index)).ToArray();
                var outOfBounds = invalid.Where(item => item.Index >= itemlist.Length).ToArray();
                var incorrectPouch = invalid.Where(item => item.Index < itemlist.Length).ToArray();

                if (outOfBounds.Any())
                    WinFormsUtil.Error("Unknown item detected.", "Item ID(s): " + string.Join(", ", outOfBounds.Select(item => item.Index)));
                if (!Main.HaX && incorrectPouch.Any())
                    WinFormsUtil.Alert($"The following item(s) have been removed from {pouch.Type} pouch.",
                        string.Join(", ", incorrectPouch.Select(item => itemlist[item.Index])), 
                        "If you save changes, the item(s) will no longer be in the pouch.");

                pouch.sanitizePouch(Main.HaX, itemlist.Length - 1);
                getBag(dgv, pouch);
            }
        }
示例#8
0
        private void ModifyAllItems(object sender, EventArgs e)
        {
            // Get Current Pouch
            int pouch = CurrentPouch;

            if (pouch < 0)
            {
                return;
            }

            DataGridView dgv = Controls.Find(DGVPrefix + Pouches[pouch].Type, true).FirstOrDefault() as DataGridView;

            for (int i = 0; i < dgv.RowCount; i++)
            {
                string item      = dgv.Rows[i].Cells[0].Value.ToString();
                int    itemindex = Array.IndexOf(itemlist, item);
                if (itemindex > 0)
                {
                    dgv.Rows[i].Cells[1].Value = IsItemCount1((ushort)itemindex, SAV) ? 1 : NUD_Count.Value;
                }
            }
            WinFormsUtil.Alert(MsgItemPouchCountUpdated);
        }
示例#9
0
        private void ClickSet(object sender, EventArgs e)
        {
            if (!mg.IsCardCompatible(SAV, out var msg))
            {
                WinFormsUtil.Alert(MsgMysteryGiftSlotFail, msg);
                return;
            }

            var pb    = WinFormsUtil.GetUnderlyingControl <PictureBox>(sender);
            int index = Array.IndexOf(pba, pb);

            // Hijack to the latest unfilled slot if index creates interstitial empty slots.
            int lastUnfilled = GetLastUnfilledByType(mg, mga);

            if (lastUnfilled > -1 && lastUnfilled < index)
            {
                index = lastUnfilled;
            }

            if (mg is PCD pcd && mga.Gifts[index] is PGT)
            {
                mg = pcd.Gift;
            }
示例#10
0
        private void B_Delete_Click(object sender, EventArgs e)
        {
            if (LB_DataEntry.SelectedIndex < 1)
            {
                WinFormsUtil.Alert("Cannot delete your first Hall of Fame Clear entry."); return;
            }
            int index = LB_DataEntry.SelectedIndex;

            if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Delete Entry {index} from your records?") != DialogResult.Yes)
            {
                return;
            }

            int offset = index * 0x1B4;

            if (index != 15)
            {
                Array.Copy(data, offset + 0x1B4, data, offset, 0x1B4 * (15 - index));
            }
            // Ensure Last Entry is Cleared
            Array.Copy(new byte[0x1B4], 0, data, 0x1B4 * 15, 0x1B4);
            DisplayEntry(LB_DataEntry, EventArgs.Empty);
        }
示例#11
0
        private void B_ExportGoFiles_Click(object sender, EventArgs e)
        {
            var gofiles = Park.AllEntities.Where(z => z.Species != 0).ToArray();

            if (gofiles.Length == 0)
            {
                WinFormsUtil.Alert("No entities present in Go Park to dump.");
                return;
            }
            using var fbd = new FolderBrowserDialog();
            if (fbd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var folder = fbd.SelectedPath;

            foreach (var gpk in gofiles)
            {
                File.WriteAllBytes(Path.Combine(folder, gpk.FileName), gpk.Data);
            }
            WinFormsUtil.Alert($"Dumped {gofiles.Length} files to {folder}");
        }
示例#12
0
        private void L_QR_Click(object sender, EventArgs e)
        {
            if (ModifierKeys == Keys.Alt)
            {
                byte[] data = QR.getQRData();
                if (data == null) return;

                string[] types = mga.Gifts.Select(g => g.Type).Distinct().ToArray();
                MysteryGift gift = MysteryGift.getMysteryGift(data);
                string giftType = gift.Type;

                if (mga.Gifts.All(card => card.Data.Length != data.Length))
                    WinFormsUtil.Alert("Decoded data not valid for loaded save file.", $"QR Data Size: 0x{data.Length:X}");
                else if (types.All(type => type != giftType))
                    WinFormsUtil.Alert("Gift type is not compatible with the save file.", $"QR Gift Type: {gift.Type}" + Environment.NewLine + $"Expected Types: {string.Join(", ", types)}");
                else if (gift.Species > SAV.MaxSpeciesID || gift.Moves.Any(move => move > SAV.MaxMoveID) || gift.HeldItem > SAV.MaxItemID)
                    WinFormsUtil.Alert("Gift Details are not compatible with the save file.");
                else
                    try { viewGiftData(gift); }
                    catch { WinFormsUtil.Alert("Error loading Mystery Gift data."); }
            }
            else
            {
                if (mg.Data.SequenceEqual(new byte[mg.Data.Length]))
                { WinFormsUtil.Alert("No wondercard data found in loaded slot!"); return; }
                if (SAV.Generation == 6 && mg.Item == 726 && mg.IsItem)
                { WinFormsUtil.Alert("Eon Ticket Wonder Cards will not function properly", "Inject to the save file instead."); return; }

                const string server = "http://lunarcookies.github.io/wc.html#";
                Image qr = QR.getQRImage(mg.Data, server);
                if (qr == null) return;

                string desc = $"({mg.Type}) {getDescription(mg)}";

                new QR(qr, PB_Preview.Image, desc + "PKHeX Wonder Card @ ProjectPokemon.org", "", "", "").ShowDialog();
            }
        }
示例#13
0
        public Main()
        {
            new Task(() => new SplashScreen().ShowDialog()).Start();
            new Task(() => Legal.RefreshMGDB(MGDatabasePath)).Start();
            string[] args = Environment.GetCommandLineArgs();
            FormLoadInitialSettings(args, out bool showChangelog, out bool BAKprompt);

            InitializeComponent();
            FormInitializeSecond();

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

            IsInitialized = true; // Splash Screen closes on its own.
            PKME_Tabs_UpdatePreviewSprite(null, null);
            BringToFront();
            WindowState = FormWindowState.Minimized;
            Show();
            WindowState = FormWindowState.Normal;
            if (HaX)
            {
                PKMConverter.AllowIncompatibleConversion = true;
                WinFormsUtil.Alert(MsgProgramIllegalModeActive, MsgProgramIllegalModeBehave);
            }
            else if (showChangelog)
            {
                new About(1).ShowDialog();
            }

            if (BAKprompt && !Directory.Exists(BackupPath))
            {
                PromptBackup();
            }
        }
示例#14
0
文件: Text.cs 项目: 04sama/PKHeX
        private void B_ApplyTrash_Click(object sender, EventArgs e)
        {
            string species = SpeciesName.GetSpeciesNameGeneration(WinFormsUtil.GetIndex(CB_Species),
                WinFormsUtil.GetIndex(CB_Language), (int) NUD_Generation.Value);

            if (string.IsNullOrEmpty(species)) // no result
                species = CB_Species.Text;

            byte[] current = SetString(TB_Text.Text);
            byte[] data = SetString(species);
            if (data.Length <= current.Length)
            {
                WinFormsUtil.Alert("Trash byte layer is hidden by current text.",
                    $"Current Bytes: {current.Length}" + Environment.NewLine + $"Layer Bytes: {data.Length}");
                return;
            }
            if (data.Length > Bytes.Count)
            {
                WinFormsUtil.Alert("Trash byte layer is too long to apply.");
                return;
            }
            for (int i = current.Length; i < data.Length; i++)
                Bytes[i].Value = data[i];
        }
示例#15
0
        private void GetBags()
        {
            foreach (InventoryPouch pouch in Pouches)
            {
                DataGridView dgv = Controls.Find(DGVPrefix + pouch.Type, true).FirstOrDefault() as DataGridView;

                // Sanity Screen
                var invalid        = pouch.Items.Where(item => item.Index != 0 && !pouch.LegalItems.Contains((ushort)item.Index)).ToArray();
                var outOfBounds    = invalid.Where(item => item.Index >= itemlist.Length).ToArray();
                var incorrectPouch = invalid.Where(item => item.Index < itemlist.Length).ToArray();

                if (outOfBounds.Length > 0)
                {
                    WinFormsUtil.Error(MsgItemPouchUnknown, $"Item ID(s): {string.Join(", ", outOfBounds.Select(item => item.Index))}");
                }
                if (!Main.HaX && incorrectPouch.Length > 0)
                {
                    WinFormsUtil.Alert(string.Format(MsgItemPouchRemoved, pouch.Type), string.Join(", ", incorrectPouch.Select(item => itemlist[item.Index])), MsgItemPouchWarning);
                }

                pouch.Sanitize(Main.HaX, itemlist.Length - 1);
                GetBag(dgv, pouch);
            }
        }
示例#16
0
        private void LoadAllBags()
        {
            foreach (var pouch in Pouches)
            {
                var dgv = GetGrid(pouch.Type);

                // Sanity Screen
                var invalid        = pouch.Items.Where(item => item.Index != 0 && !pouch.LegalItems.Contains((ushort)item.Index)).ToArray();
                var outOfBounds    = invalid.Where(item => item.Index >= itemlist.Length).ToArray();
                var incorrectPouch = invalid.Where(item => item.Index < itemlist.Length).ToArray();

                if (outOfBounds.Length > 0)
                {
                    WinFormsUtil.Error(MsgItemPouchUnknown, $"Item ID(s): {string.Join(", ", outOfBounds.Select(item => item.Index))}");
                }
                if (!Main.HaX && incorrectPouch.Length > 0)
                {
                    WinFormsUtil.Alert(string.Format(MsgItemPouchRemoved, pouch.Type), string.Join(", ", incorrectPouch.Select(item => itemlist[item.Index])), MsgItemPouchWarning);
                }

                pouch.Sanitize(Main.HaX, itemlist.Length - 1);
                GetBag(dgv, pouch);
            }
        }
示例#17
0
        private bool checkSpecialWonderCard(MysteryGift g)
        {
            if (SAV.Generation != 6)
            {
                return(true);
            }

            if (g is WC6)
            {
                if (g.CardID == 2048 && g.Item == 726) // Eon Ticket (OR/AS)
                {
                    if (!Main.SAV.ORAS || ((SAV6)SAV).EonTicket < 0)
                    {
                        goto reject;
                    }
                    BitConverter.GetBytes(WC6.EonTicketConst).CopyTo(SAV.Data, ((SAV6)SAV).EonTicket);
                }
            }

            return(true);

            reject : WinFormsUtil.Alert("Unable to insert the Mystery Gift.", "Does this Mystery Gift really belong to this game?");
            return(false);
        }
示例#18
0
        private void DiffSaves()
        {
            var diff = new EventBlockDiff(TB_OldSAV.Text, TB_NewSAV.Text);

            if (!string.IsNullOrWhiteSpace(diff.Message))
            {
                WinFormsUtil.Alert(diff.Message);
                return;
            }

            TB_IsSet.Text = string.Join(", ", diff.SetFlags.Select(z => $"{z:0000}"));
            TB_UnSet.Text = string.Join(", ", diff.ClearedFlags.Select(z => $"{z:0000}"));

            if (diff.WorkDiff.Count == 0)
            {
                WinFormsUtil.Alert("No Event Constant diff found.");
                return;
            }

            if (DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?"))
            {
                Clipboard.SetText(string.Join(Environment.NewLine, diff.WorkDiff));
            }
        }
示例#19
0
        private void Menu_DeleteClones_Click(object sender, EventArgs e)
        {
            var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo,
                                         "Deleting clones from database is not reversible." + Environment.NewLine +
                                         "If a PKM is deemed a clone, only the newest file (date modified) will be kept.", "Continue?");

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

            var hashes  = new List <string>();
            var deleted = 0;
            var db      = RawDB.Where(pk => pk.Identifier.StartsWith(DatabasePath + Path.DirectorySeparatorChar, StringComparison.Ordinal))
                          .OrderByDescending(file => new FileInfo(file.Identifier).LastWriteTime);

            foreach (var pk in db)
            {
                var h = hash(pk);
                if (!hashes.Contains(h))
                {
                    hashes.Add(h); continue;
                }

                try { File.Delete(pk.Identifier); ++deleted; }
                catch { WinFormsUtil.Error("Unable to delete clone:" + Environment.NewLine + pk.Identifier); }
            }

            if (deleted == 0)
            {
                WinFormsUtil.Alert("No clones detected or deleted."); return;
            }

            WinFormsUtil.Alert($"{deleted} files deleted.", "The form will now close.");
            Close();
        }
示例#20
0
        private void runBackgroundWorker()
        {
            var Filters = getFilters().ToList();

            if (Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))
            {
                WinFormsUtil.Error("Empty Filter Value detected."); return;
            }

            var Instructions = getInstructions().ToList();
            var emptyVal     = Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue)).ToArray();

            if (emptyVal.Any())
            {
                string props = string.Join(", ", emptyVal.Select(z => z.PropertyName));
                if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo,
                                                            $"Empty Property Value{(emptyVal.Length > 1 ? "s" : "")} detected:" + Environment.NewLine + props,
                                                            "Continue?"))
                {
                    return;
                }
            }

            string destPath = "";

            if (RB_Path.Checked)
            {
                WinFormsUtil.Alert("Please select the folder where the files will be saved to.", "This can be the same folder as the source of PKM files.");
                var fbd = new FolderBrowserDialog();
                var dr  = fbd.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }

                destPath = fbd.SelectedPath;
            }

            FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = false;

            b = new BackgroundWorker {
                WorkerReportsProgress = true
            };
            screenStrings(Filters);
            screenStrings(Instructions);

            b.DoWork += (sender, e) => {
                if (RB_SAV.Checked)
                {
                    var data = Main.SAV.BoxData;
                    setupProgressBar(data.Length);
                    processSAV(data, Filters, Instructions);
                }
                else
                {
                    var files = Directory.GetFiles(TB_Folder.Text, "*", SearchOption.AllDirectories);
                    setupProgressBar(files.Length);
                    processFolder(files, Filters, Instructions, destPath);
                }
            };
            b.ProgressChanged += (sender, e) =>
            {
                setProgressBar(e.ProgressPercentage);
            };
            b.RunWorkerCompleted += (sender, e) => {
                string result = $"Modified {ctr}/{len} files.";
                if (err > 0)
                {
                    result += Environment.NewLine + $"{err} files ignored due to an internal error.";
                }
                WinFormsUtil.Alert(result);
                FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = true;
                setupProgressBar(0);
            };
            b.RunWorkerAsync();
        }
示例#21
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();
        }
示例#22
0
        private void B_GetTickets_Click(object sender, EventArgs e)
        {
            var Pouches  = SAV.Inventory;
            var itemlist = GameInfo.Strings.GetItemStrings(SAV.Generation, SAV.Version).ToArray();

            for (int i = 0; i < itemlist.Length; i++)
            {
                if (string.IsNullOrEmpty(itemlist[i]))
                {
                    itemlist[i] = $"(Item #{i:000})";
                }
            }

            const int oldsea = 0x178;

            int[] tickets = { 0x109, 0x113, 0x172, 0x173, oldsea }; // item IDs
            if (!SAV.Japanese && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Non Japanese save file. Add {itemlist[oldsea]} (unreleased)?"))
            {
                tickets = tickets.Take(tickets.Length - 1).ToArray(); // remove old sea map
            }
            var p = Array.Find(Pouches, z => z.Type == InventoryType.KeyItems);

            if (p == null)
            {
                return;
            }

            // check for missing tickets
            var missing = tickets.Where(z => !p.Items.Any(item => item.Index == z && item.Count == 1)).ToList();
            var have    = tickets.Except(missing).ToList();

            if (missing.Count == 0)
            {
                WinFormsUtil.Alert("Already have all tickets.");
                B_GetTickets.Enabled = false;
                return;
            }

            // check for space
            int end = Array.FindIndex(p.Items, z => z.Index == 0);

            if (end + missing.Count >= p.Items.Length)
            {
                WinFormsUtil.Alert("Not enough space in pouch.", "Please use the InventoryEditor.");
                B_GetTickets.Enabled = false;
                return;
            }

            var added  = string.Join(", ", missing.Select(u => itemlist[u]));
            var addmsg = $"Add the following items?{Environment.NewLine}{added}";

            if (have.Count > 0)
            {
                string had     = string.Join(", ", have.Select(u => itemlist[u]));
                var    havemsg = $"Already have:{Environment.NewLine}{had}";
                addmsg += Environment.NewLine + Environment.NewLine + havemsg;
            }
            if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, addmsg))
            {
                return;
            }

            // insert items at the end
            for (int i = 0; i < missing.Count; i++)
            {
                var item = p.Items[end + i];
                item.Index = missing[i];
                item.Count = 1;
            }

            string alert = $"Inserted the following items to the Key Items Pouch:{Environment.NewLine}{added}";

            WinFormsUtil.Alert(alert);
            SAV.Inventory = Pouches;

            B_GetTickets.Enabled = false;
        }
示例#23
0
        // View Updates
        private void B_Search_Click(object sender, EventArgs e)
        {
            // Populate Search Query Result
            IEnumerable <MysteryGift> res = RawDB;

            int format = MAXFORMAT + 1 - CB_Format.SelectedIndex;

            switch (CB_FormatComparator.SelectedIndex)
            {
            case 0: /* Do nothing */ break;

            case 1: res = res.Where(mg => mg.Format >= format); break;

            case 2: res = res.Where(mg => mg.Format == format); break;

            case 3: res = res.Where(mg => mg.Format <= format); break;
            }

            // Primary Searchables
            int species = WinFormsUtil.GetIndex(CB_Species);
            int item    = WinFormsUtil.GetIndex(CB_HeldItem);

            if (species != -1)
            {
                res = res.Where(pk => pk.Species == species);
            }
            if (item != -1)
            {
                res = res.Where(pk => pk.HeldItem == item);
            }

            // Secondary Searchables
            int move1 = WinFormsUtil.GetIndex(CB_Move1);
            int move2 = WinFormsUtil.GetIndex(CB_Move2);
            int move3 = WinFormsUtil.GetIndex(CB_Move3);
            int move4 = WinFormsUtil.GetIndex(CB_Move4);

            if (move1 != -1)
            {
                res = res.Where(mg => mg.HasMove(move1));
            }
            if (move2 != -1)
            {
                res = res.Where(mg => mg.HasMove(move2));
            }
            if (move3 != -1)
            {
                res = res.Where(mg => mg.HasMove(move3));
            }
            if (move4 != -1)
            {
                res = res.Where(mg => mg.HasMove(move4));
            }
            if (CHK_Shiny.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsShiny);
            }
            if (CHK_Shiny.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsShiny);
            }
            if (CHK_IsEgg.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsEgg);
            }
            if (CHK_IsEgg.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsEgg);
            }

            slotSelected = -1; // reset the slot last viewed

            if (RTB_Instructions.Lines.Any(line => line.Length > 0))
            {
                var filters = StringInstruction.GetFilters(RTB_Instructions.Lines).ToArray();
                BatchEditing.ScreenStrings(filters);
                res = res.Where(pkm => BatchEditing.IsFilterMatch(filters, pkm)); // Compare across all filters
            }

            var results = res.ToArray();

            if (results.Length == 0)
            {
                WinFormsUtil.Alert(MsgDBSearchNone);
            }

            SetResults(new List <MysteryGift>(results)); // updates Count Label as well.
            System.Media.SystemSounds.Asterisk.Play();
        }
示例#24
0
        private void pbBoxSlot_DragDrop(object sender, DragEventArgs e)
        {
            DragInfo.Destination.Parent = this;
            DragInfo.Destination.Slot   = getSlot(sender);
            DragInfo.Destination.Offset = getPKXOffset(DragInfo.Destination.Slot);
            DragInfo.Destination.Box    = CB_BoxSelect.SelectedIndex;

            // Check for In-Dropped files (PKX,SAV,ETC)
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (Directory.Exists(files[0]))
            {
                return;
            }
            if (SAV.getIsSlotLocked(DragInfo.Destination.Box, DragInfo.Destination.Slot))
            {
                DragInfo.Destination.Slot = -1; // Invalidate
                WinFormsUtil.Alert("Unable to set to locked slot.");
                return;
            }
            if (DragInfo.Source.Offset < 0) // file
            {
                if (files.Length <= 0)
                {
                    return;
                }
                string   file = files[0];
                FileInfo fi   = new FileInfo(file);
                if (!PKX.getIsPKM(fi.Length) && !MysteryGift.getIsMysteryGift(fi.Length))
                {
                    return;
                }

                byte[]      data = File.ReadAllBytes(file);
                MysteryGift mg   = MysteryGift.getMysteryGift(data, fi.Extension);
                PKM         temp = mg != null?mg.convertToPKM(SAV) : PKMConverter.getPKMfromBytes(data, prefer: SAV.Generation);

                string c;

                PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c);
                if (pk == null)
                {
                    WinFormsUtil.Error(c); Console.WriteLine(c); return;
                }

                string[] errata = SAV.IsPKMCompatible(pk);
                if (errata.Length > 0)
                {
                    string concat = string.Join(Environment.NewLine, errata);
                    if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, concat, "Continue?"))
                    {
                        Console.WriteLine(c); Console.WriteLine(concat); return;
                    }
                }

                DragInfo.SetPKM(pk, false);
                getQuickFiller(SlotPictureBoxes[DragInfo.Destination.Slot], pk);
                Console.WriteLine(c);
            }
            else
            {
                PKM pkz = DragInfo.GetPKM(true);
                if (!DragInfo.Source.IsValid)
                {
                }                                                                  // not overwritable, do nothing
                else if (ModifierKeys == Keys.Alt && DragInfo.Destination.IsValid) // overwrite
                {
                    // Clear from slot
                    if (DragInfo.SameBox)
                    {
                        getQuickFiller(SlotPictureBoxes[DragInfo.Source.Slot], SAV.BlankPKM); // picturebox
                    }
                    DragInfo.SetPKM(SAV.BlankPKM, true);
                }
                else if (ModifierKeys != Keys.Control && DragInfo.Destination.IsValid) // move
                {
                    // Load data from destination
                    PKM pk = ((PictureBox)sender).Image != null
                        ? DragInfo.GetPKM(false)
                        : SAV.BlankPKM;

                    // Set destination pokemon image to source picture box
                    if (DragInfo.SameBox)
                    {
                        getQuickFiller(SlotPictureBoxes[DragInfo.Source.Slot], pk);
                    }

                    // Set destination pokemon data to source slot
                    DragInfo.SetPKM(pk, true);
                }
                else if (DragInfo.SameBox) // clone
                {
                    getQuickFiller(SlotPictureBoxes[DragInfo.Source.Slot], pkz);
                }

                // Copy from temp to destination slot.
                DragInfo.SetPKM(pkz, false);
                getQuickFiller(SlotPictureBoxes[DragInfo.Destination.Slot], pkz);

                e.Effect = DragDropEffects.Link;
                Cursor   = DefaultCursor;
            }
            if (DragInfo.Source.IsParty || DragInfo.Destination.IsParty)
            {
                parent.setParty();
            }
            if (DragInfo.Source.Parent == null) // another instance or file
            {
                parent.notifyBoxViewerRefresh();
                DragInfo.Reset();
            }
        }
示例#25
0
        // View Updates
        private void B_Search_Click(object sender, EventArgs e)
        {
            // Populate Search Query Result
            IEnumerable <MysteryGift> res = RawDB;

            int format = MAXFORMAT + 1 - CB_Format.SelectedIndex;

            switch (CB_FormatComparator.SelectedIndex)
            {
            case 0: /* Do nothing */ break;

            case 1: res = res.Where(mg => mg.Format >= format); break;

            case 2: res = res.Where(mg => mg.Format == format); break;

            case 3: res = res.Where(mg => mg.Format <= format); break;
            }

            // Primary Searchables
            int species = WinFormsUtil.GetIndex(CB_Species);
            int item    = WinFormsUtil.GetIndex(CB_HeldItem);

            if (species != -1)
            {
                res = res.Where(pk => pk.Species == species);
            }
            if (item != -1)
            {
                res = res.Where(pk => pk.HeldItem == item);
            }

            // Secondary Searchables
            int move1 = WinFormsUtil.GetIndex(CB_Move1);
            int move2 = WinFormsUtil.GetIndex(CB_Move2);
            int move3 = WinFormsUtil.GetIndex(CB_Move3);
            int move4 = WinFormsUtil.GetIndex(CB_Move4);

            if (move1 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move1));
            }
            if (move2 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move2));
            }
            if (move3 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move3));
            }
            if (move4 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move4));
            }
            if (CHK_Shiny.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsShiny);
            }
            if (CHK_Shiny.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsShiny);
            }
            if (CHK_IsEgg.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsEgg);
            }
            if (CHK_IsEgg.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsEgg);
            }

            slotSelected = -1; // reset the slot last viewed

            if (RTB_Instructions.Lines.Any(line => line.Length > 0))
            {
                var raw =
                    RTB_Instructions.Lines
                    .Where(line => !string.IsNullOrWhiteSpace(line))
                    .Where(line => new[] { '!', '=' }.Contains(line[0]));

                var filters = (from line in raw
                               let eval = line[0] == '='
                                          let split = line.Substring(1).Split('=')
                                                      where split.Length == 2 && !string.IsNullOrWhiteSpace(split[0])
                                                      select new BatchEditor.StringInstruction {
                    PropertyName = split[0], PropertyValue = split[1], Evaluator = eval
                }).ToArray();

                if (filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))
                {
                    WinFormsUtil.Error(MsgBEFilterEmpty); return;
                }

                res = res.Where(gift => // Compare across all filters
                {
                    foreach (var cmd in filters)
                    {
                        if (!gift.GetType().HasPropertyAll(cmd.PropertyName))
                        {
                            return(false);
                        }
                        try { if (gift.GetType().IsValueEqual(gift, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator)
                              {
                                  continue;
                              }
                        }
                        catch { Debug.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
                        return(false);
                    }
                    return(true);
                });
            }

            var results = res.ToArray();

            if (results.Length == 0)
            {
                WinFormsUtil.Alert(MsgDBSearchNone);
            }

            SetResults(new List <MysteryGift>(results)); // updates Count Label as well.
            System.Media.SystemSounds.Asterisk.Play();
        }
示例#26
0
        public SAV_FestivalPlaza(SaveFile sav)
        {
            SAV     = (SAV7)(Origin = sav).Clone();
            editing = true;
            InitializeComponent();
            typeMAX = SAV.USUM ? 0x7F : 0x7C;
            if (SAV.USUM)
            {
                PBs          = new[] { ppkx1, ppkx2, ppkx3 };
                NUD_Trainers = new[] { NUD_Trainer1, NUD_Trainer2, NUD_Trainer3 };
                LoadBattleAgency();
            }
            else
            {
                TC_Editor.TabPages.Remove(Tab_BattleAgency);
            }
            if (Main.Unicode)
            {
                try { TB_OTName.Font = FontUtil.GetPKXFont(11); }
                catch (Exception e) { WinFormsUtil.Alert("Font loading failed...", e.ToString()); }
            }
            uint cc = SAV.FestaCoins;
            uint cu = SAV.UsedFestaCoins;

            NUD_FC_Current.Value = Math.Min(cc, NUD_FC_Current.Maximum);
            NUD_FC_Used.Value    = Math.Min(cu, NUD_FC_Used.Maximum);
            L_FC_CollectedV.Text = (cc + cu).ToString();
            string[] res;
            switch (Main.CurrentLanguage)
            {
            case "ja":
                res = new[] {
                    "おじさんの きんのたま だからね!", "かがくの ちからって すげー", "1 2の …… ポカン!", "おーす! みらいの チャンピオン!", "おお! あんたか!", "みんな げんきに なりましたよ!", "とっても 幸せそう!", "なんでも ないです", "いあいぎりで きりますか?", "レポートを かきこんでいます",
                    "…… ぼくも もう いかなきゃ!", "ボンジュール!", "バイビー!", "ばか はずれです……", "やけどなおしの よういは いいか!", "ウー! ハーッ!", "ポケモンは たたかわせるものさ", "ヤドランは そっぽを むいた!", "マサラは まっしろ はじまりのいろ", "10000こうねん はやいんだよ!", "おーい! まてー! まつんじゃあ!", "こんちわ! ぼく ポケモン……!", "っだと こらあ!", "ぐ ぐーッ! そんな ばかなーッ!", "みゅう!", "タチサレ…… タチサレ……",
                    "カイリュー はかいこうせん", "どっちか 遊んでくれないか?", "ぬいぐるみ かっておいたわよ", "ひとのこと じろじろ みてんなよ", "なんのことだか わかんない", "みんな ポケモン やってるやん", "きょうから 24時間 とっくんだ!", "あたいが ホンモノ!", "でんげきで いちころ……", "スイクンを おいかけて 10ねん", "かんどうが よみがえるよ!", "われわれ ついに やりましたよー!", "ヤドンのシッポを うるなんて……", "ショオーッ!!", "ギャーアアス!!", "だいいっぽを ふみだした!",
                    "いちばん つよくて すごいんだよね", "にくらしいほど エレガント!", "そうぞうりょくが たりないよ", "キミは ビッグウェーブ!", "おまえさんには しびれた わい", "なに いってんだろ…… てへへ……", "ぬいぐるみ なんか かってないよ", "ここで ゆっくり して おいき!", "はじけろ! ポケモン トレーナー!", "はいが はいに はいった……", "…できる!", "ぶつかった かいすう 5かい!", "たすけて おくれーっ!!", "マボロシじま みえんのう……", "ひゅああーん!", "しゅわーん!",
                    "あつい きもち つたわってくる!", "こいつが! おれの きりふだ!", "ひとりじめとか そういうの ダメよ!", "ワーオ! ぶんせきどーり!", "ぱるぱるぅ!!!", "グギュグバァッ!!!", "ばっきん 100まんえん な!", "オレ つよくなる……", "ながれる 時間は とめられない!", "ぜったいに お願いだからね", "きみたちから はどうを かんじる!", "あたしのポケモンに なにすんのさ!", "リングは おれの うみ~♪", "オレの おおごえの ひとりごとを", "そう コードネームは ハンサム!", "……わたしが まけるかも だと!?",
                    "やめたげてよぉ!", "ブラボー! スーパー ブラボー!", "ボクは チャンピオンを こえる", "オレは いまから いかるぜッ!", "ライモンで ポケモン つよいもん", "キミ むしポケモン つかいなよ", "ストップ!", "ひとよんで メダルおやじ!", "トレーナーさんも がんばれよ!", "おもうぞんぶん きそおーぜ!", "プラズマズイ!", "ワタクシを とめることは できない!", "けいさんずみ ですとも!", "ババリバリッシュ!", "ンバーニンガガッ!", "ヒュラララ!",
                    "お友達に なっちゃお♪", "じゃあ みんな またねえ!", "このひとたち ムチャクチャです……", "トレーナーとは なにか しりたい", "スマートに くずれおちるぜ", "いのち ばくはつッ!!", "いいんじゃない いいんじゃないの!", "あれだよ あれ おみごとだよ!", "ぜんりょくでいけー! ってことよ!", "おまちなさいな!", "つまり グッド ポイント なわけ!", "ざんねん ですが さようなら", "にくすぎて むしろ 好きよ", "この しれもの が!", "イクシャア!!", "イガレッカ!!",
                    "フェスサークル ランク 100!",
                };
                break;

            default:
                string musical8note = "♪";
                string linedP       = "₽"; //currency Ruble
                res = new[] {              //source:UltraMoon
                    /* (SM)Pokémon House */ "There's nothing funny about Nuggets.", "The Power of science is awesome.", "1, 2, and... Ta-da!", "How's the future Champ today?", "Why, you!", "There! All happy and healthy!", "Your Pokémon seems to be very happy!", "No thanks!", "Would you like to use Cut?", "Saving...",
                    /* (SM)Kanto Tent */ "Well, I better get going!", "Bonjour!", "Smell ya later!", "Sorry! Bad call!", "You better have Burn Heal!", "Hoo hah!", "Pokémon are for battling!", "Slowbro took a snooze...", "Shades of your journey await!", "You're 10,000 light-years from facing Brock!", "Hey! Wait! Don't go out!", "Hiya! I'm a Pokémon...", "What do you want?", "WHAT! This can't be!", "Mew!", "Be gone... Intruders...",
                    /* (SM)Joht Tent */ "Dragonite, Hymer Beam.", "Spread the fun around.", "I bought an adorable doll with your money.", "What are you staring at?", "I just don't understand.", "Everyone is into Pokémon.", "I'm going to train 24 hours a day!", "I'm the real deal!", "With a jolt of electricity...", "For 10 years I chased Suicune.", "I am just so deeply moved!", "We have finally made it!", "...But selling Slowpoke Tails?", "Shaoooh!", "Gyaaas!", "you've taken your first step!",
                    /* (SM)Hoenn Tent */ "I'm just the strongest there is right now.", "And confoundedly elegant!", "You guys need some imagination.", "You made a much bigger splash!", "You ended up giving me a thrill!", "So what am I talking about...", "I'm not buying any Dolls.", "Take your time and rest up!", "Have a blast, Pokémon Trainers!", "I got ashes in my eyelashes!", "You're sharp!", "Number of collisions: 5 times!", "Please! Help me out!", "I can't see Mirage Island today...", "Hyahhn!", "Shwahhn!",
                    /* (SM)Sinnoh Tent */ "Your will is overwhelming me!", "This is it! My trump card!", "Trying to monopolize Pokémon just isn't...", "See? Just as analyzed.", "Gagyagyaah!", "Gugyugubah!", "It's a " + linedP + "10 million fine if you're late!", "I'm going to get tougher...", "You'll never be able to stem the flow of time!", "Please come!", "Your team! I sense your strong aura!", "What do you think you're doing?!", "The ring is my rolling sea. " + musical8note, "I was just thinking out loud.", "My code name, it is Looker.", "It's not possible that I lose!",
                    /* (SM)Unova Tent */ "Knock it off!", "Bravo! Excellent!!", "I'll defeat the Champion.", "You're about to feel my rage!", "Nimbasa's Pokémon can dance a nimble bossa!", "Use Bug-type Pokémon!", "Stop!", "People call me Mr. Medal!", "Trainer, do your best, too!", "See who's stronger!", "Plasbad, for short!", "I won't allow anyone to stop me!", "I was expecting exactly that kind of move!", "Bazzazzazzash!", "Preeeeaah!", "Haaahraaan!",
                    /* (SM)Kalos Tent */ "We'll become friends. " + musical8note, "I'll see you all later!", "These people have a few screws loose...", "I want to know what a \"Trainer\" is.", "When I lose, I go out in style!", "Let's give it all we've got!", "Fantastic! Just fantastic!", "Outstanding!", "Try as hard as possible!", "Stop right there!", "That really hit me right here...", "But this is adieu to you all.", "You're just too much, you know?", "Fool! You silly, unseeing child!", "Xsaaaaaah!", "Yvaaaaaar!",
                    "I reached Festival Plaza Rank 100!",
                };
                break;
            }
            CLB_Phrases.Items.Clear();
            CLB_Phrases.Items.Add(res.Last(), SAV.GetFestaPhraseUnlocked(106)); //add Lv100 before TentPhrases
            for (int i = 0; i < res.Length - 1; i++)
            {
                CLB_Phrases.Items.Add(res[i], SAV.GetFestaPhraseUnlocked(i));
            }

            DateTime dt = SAV.FestaDate ?? new DateTime(2000, 1, 1);

            CAL_FestaStartDate.Value = CAL_FestaStartTime.Value = dt;

            string[] res2 = { "Rank 4: missions", "Rank 8: facility", "Rank 10: fashion", "Rank 20: rename", "Rank 30: special menu", "Rank 40: BGM", "Rank 50: theme Glitz", "Rank 60: theme Fairy", "Rank 70: theme Tone", "Rank 100: phrase", "Current Rank", };
            CLB_Reward.Items.Clear();
            CLB_Reward.Items.Add(res2.Last(), (CheckState)r[SAV.GetFestPrizeReceived(10)]); //add CurrentRank before const-rewards
            for (int i = 0; i < res2.Length - 1; i++)
            {
                CLB_Reward.Items.Add(res2[i], (CheckState)r[SAV.GetFestPrizeReceived(i)]);
            }

            for (int i = 0; i < 7; i++)
            {
                f[i] = new FestaFacility(SAV, i);
            }

            string[] res3 = { "Meet", "Part", "Moved", "Disappointed" };
            CB_FacilityMessage.Items.Clear();
            CB_FacilityMessage.Items.AddRange(res3);
            string[] res5 =
            {
                "Ace Trainer" + gendersymbols[1],
                "Ace Trainer" + gendersymbols[0],
                "Veteran" + gendersymbols[1],
                "Veteran" + gendersymbols[0],
                "Office Worker" + gendersymbols[0],
                "Office Worker" + gendersymbols[1],
                "Punk Guy",
                "Punk Girl",
                "Breeder" + gendersymbols[0],
                "Breeder" + gendersymbols[1],
                "Youngster",
                "Lass"
            };
            CB_FacilityNPC.Items.Clear();
            CB_FacilityNPC.Items.AddRange(res5);
            string[]   res6 = { "Lottery", "Haunted", "Goody", "Food", "Bouncy", "Fortune", "Dye", "Exchange" };
            string[][] res7 =
            {
                new[] { "BigDream",  "GoldRush",  "TreasureHunt"     },
                new[] { "GhostsDen", "TrickRoom", "ConfuseRay"       },
                new[] { "Ball",      "General",   "Battle", "SoftDrink", "Pharmacy"},
                new[] { "Rare",      "Battle",    "FriendshipCafé", "FriendshipParlor"},
                new[] { "Thump",     "Clink",     "Stomp"            },
                new[] { "Kanto",     "Johto",     "Hoenn", "Sinnoh", "Unova", "Kalos", "Pokémon"},
                new[] { "Red",       "Yellow",    "Green", "Blue", "Orange", "NavyBlue", "Purple", "Pink"},
                new[] { "Switcheroo" }
            };
            CB_FacilityType.Items.Clear();
            for (int k = 0; k < RES_FacilityLevelType.Length - (SAV.USUM ? 0 : 1); k++) //Exchange is USUM only
            {
                for (int j = 0; j < RES_FacilityLevelType[k].Length; j++)
                {
                    if (RES_FacilityLevelType[k][j] != 4)
                    {
                        for (int i = 0; i < RES_FacilityLevelType[k][j]; i++)
                        {
                            CB_FacilityType.Items.Add($"{res6[k]} {res7[k][j]} {i + 1}");
                        }
                    }
                    else
                    {
                        CB_FacilityType.Items.Add($"{res6[k]} {res7[k][j]} 1");
                        CB_FacilityType.Items.Add($"{res6[k]} {res7[k][j]} 3");
                        CB_FacilityType.Items.Add($"{res6[k]} {res7[k][j]} 5");
                    }
                }
            }
            string[] res8 = { "GTS", "Wonder Trade", "Battle Spot", "Festival Plaza", "mission", "lottery shop", "haunted house" };
            string[] res9 = { "+", "++", "+++" };
            CB_LuckyResult.Items.Clear();
            CB_LuckyResult.Items.Add("none");
            for (int i = 0; i < res8.Length; i++)
            {
                for (int j = 0; j < res9.Length; j++)
                {
                    CB_LuckyResult.Items.Add($"{res9[j]} {res8[i]}");
                }
            }

            NUD_Rank.Value = SAV.FestaRank;
            LoadRankLabel(SAV.FestaRank);
            NUD_Messages = new[] { NUD_MyMessageMeet, NUD_MyMessagePart, NUD_MyMessageMoved, NUD_MyMessageDissapointed };
            for (int i = 0; i < NUD_Messages.Length; i++)
            {
                NUD_Messages[i].Value = SAV.GetFestaMessage(i);
            }

            LB_FacilityIndex.SelectedIndex   = 0;
            CB_FacilityMessage.SelectedIndex = 0;
            editing = false;

            entry = 0;
            LoadFacility();
        }
示例#27
0
        private void ClickDelete(object sender, EventArgs e)
        {
            sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
            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("Can't delete from a backup save.");
                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.Data.SequenceEqual(pk.Data)) // data still exists in SAV, unmodified
                {
                    WinFormsUtil.Error("Database slot data does not match save data!", "Don't move Pokémon after initializing the Database, please re-open the Database viewer.");
                    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();
        }
示例#28
0
        private void DiffSaves()
        {
            if (!File.Exists(TB_OldSAV.Text))
            {
                WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 1)); return;
            }
            if (!File.Exists(TB_NewSAV.Text))
            {
                WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 2)); return;
            }
            if (new FileInfo(TB_OldSAV.Text).Length > 0x100000)
            {
                WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 1)); return;
            }
            if (new FileInfo(TB_NewSAV.Text).Length > 0x100000)
            {
                WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 2)); return;
            }

            var s1 = SaveUtil.GetVariantSAV(TB_OldSAV.Text);
            var s2 = SaveUtil.GetVariantSAV(TB_NewSAV.Text);

            if (s1 == null)
            {
                WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 1)); return;
            }
            if (s2 == null)
            {
                WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 2)); return;
            }

            if (s1.GetType() != s2.GetType())
            {
                WinFormsUtil.Alert(MsgSaveDifferentTypes, $"S1: {s1.GetType().Name}", $"S2: {s2.GetType().Name}"); return;
            }
            if (s1.Version != s2.Version)
            {
                WinFormsUtil.Alert(MsgSaveDifferentVersions, $"S1: {s1.Version}", $"S2: {s2.Version}"); return;
            }

            var tbIsSet = new List <int>();
            var tbUnSet = new List <int>();
            var result  = new List <string>();

            bool[] oldBits  = s1.EventFlags;
            bool[] newBits  = s2.EventFlags;
            var    oldConst = s1.EventConsts;
            var    newConst = s2.EventConsts;

            for (int i = 0; i < oldBits.Length; i++)
            {
                if (oldBits[i] != newBits[i])
                {
                    (newBits[i] ? tbIsSet : tbUnSet).Add(i);
                }
            }
            TB_IsSet.Text = string.Join(", ", tbIsSet.Select(z => $"{z:0000}"));
            TB_UnSet.Text = string.Join(", ", tbUnSet.Select(z => $"{z:0000}"));

            for (int i = 0; i < newConst.Length; i++)
            {
                if (oldConst[i] != newConst[i])
                {
                    result.Add($"{i}: {oldConst[i]}->{newConst[i]}");
                }
            }

            if (result.Count == 0)
            {
                WinFormsUtil.Alert("No Event Constant diff found.");
                return;
            }

            if (DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?"))
            {
                Clipboard.SetText(string.Join(Environment.NewLine, result));
            }
        }
示例#29
0
        private void DiffSaves()
        {
            if (!File.Exists(TB_OldSAV.Text))
            {
                WinFormsUtil.Alert("Save 1 path invalid."); return;
            }
            if (!File.Exists(TB_NewSAV.Text))
            {
                WinFormsUtil.Alert("Save 2 path invalid."); return;
            }
            if (new FileInfo(TB_OldSAV.Text).Length > 0x100000)
            {
                WinFormsUtil.Alert("Save 1 file invalid."); return;
            }
            if (new FileInfo(TB_NewSAV.Text).Length > 0x100000)
            {
                WinFormsUtil.Alert("Save 2 file invalid."); return;
            }

            SaveFile s1 = SaveUtil.GetVariantSAV(File.ReadAllBytes(TB_OldSAV.Text));
            SaveFile s2 = SaveUtil.GetVariantSAV(File.ReadAllBytes(TB_NewSAV.Text));

            if (s1 == null)
            {
                WinFormsUtil.Alert("Save 1 file invalid."); return;
            }
            if (s2 == null)
            {
                WinFormsUtil.Alert("Save 2 file invalid."); return;
            }

            if (s1.GetType() != s2.GetType())
            {
                WinFormsUtil.Alert("Save types are different.", $"S1: {s1.GetType().Name}", $"S2: {s2.GetType().Name}"); return;
            }
            if (s1.Version != s2.Version)
            {
                WinFormsUtil.Alert("Save versions are different.", $"S1: {s1.Version}", $"S2: {s2.Version}"); return;
            }

            string tbIsSet = "";
            string tbUnSet = "";

            try
            {
                bool[] oldBits = s1.EventFlags;
                bool[] newBits = s2.EventFlags;
                if (oldBits.Length != newBits.Length)
                {
                    WinFormsUtil.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return;
                }

                for (int i = 0; i < oldBits.Length; i++)
                {
                    if (oldBits[i] == newBits[i])
                    {
                        continue;
                    }
                    if (newBits[i])
                    {
                        tbIsSet += $"{i:0000},";
                    }
                    else
                    {
                        tbUnSet += $"{i:0000},";
                    }
                }
            }
            catch (Exception e)
            {
                WinFormsUtil.Error("An unexpected error has occurred.", e);
                Debug.WriteLine(e);
            }
            TB_IsSet.Text = tbIsSet;
            TB_UnSet.Text = tbUnSet;

            string r = "";

            try
            {
                ushort[] oldConst = s1.EventConsts;
                ushort[] newConst = s2.EventConsts;
                if (oldConst.Length != newConst.Length)
                {
                    WinFormsUtil.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return;
                }

                for (int i = 0; i < newConst.Length; i++)
                {
                    if (oldConst[i] != newConst[i])
                    {
                        r += $"{i}: {oldConst[i]}->{newConst[i]}{Environment.NewLine}";
                    }
                }
            }
            catch (Exception e)
            {
                WinFormsUtil.Error("An unexpected error has occurred.", e);
                Debug.WriteLine(e);
            }

            if (string.IsNullOrEmpty(r))
            {
                WinFormsUtil.Alert("No Event Constant diff found.");
                return;
            }

            if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?"))
            {
                return;
            }
            Clipboard.SetText(r);
        }
示例#30
0
        private void pbBoxSlot_DragDrop(object sender, DragEventArgs e)
        {
            int index = Array.IndexOf(pba, sender);

            // Hijack to the latest unfilled slot if index creates interstitial empty slots.
            int lastUnfilled = getLastUnfilledByType(mg, mga);
            if (lastUnfilled > -1 && lastUnfilled < index && mga.Gifts[lastUnfilled].Type == mga.Gifts[index].Type)
                index = lastUnfilled;
            
            if (wc_slot == -1) // dropped
            {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                if (files.Length < 1)
                    return;
                if (PCD.Size < (int)new FileInfo(files[0]).Length)
                { WinFormsUtil.Alert("Data size invalid.", files[0]); return; }
                
                byte[] data = File.ReadAllBytes(files[0]);
                MysteryGift gift = MysteryGift.getMysteryGift(data, new FileInfo(files[0]).Extension);

                if (gift is PCD && mga.Gifts[index] is PGT)
                    gift = (gift as PCD).Gift;
                else if (gift.Type != mga.Gifts[index].Type)
                {
                    WinFormsUtil.Alert("Can't set slot here.", $"{gift.Type} != {mga.Gifts[index].Type}");
                    return;
                }
                setBackground(index, Properties.Resources.slotSet);
                mga.Gifts[index] = gift.Clone();
                
                setCardID(mga.Gifts[index].CardID);
                viewGiftData(mga.Gifts[index]);
            }
            else // Swap Data
            {
                MysteryGift s1 = mga.Gifts[index];
                MysteryGift s2 = mga.Gifts[wc_slot];

                if (s2 is PCD && s1 is PGT)
                {
                    // set the PGT to the PGT slot instead
                    viewGiftData(s2);
                    clickSet(pba[index], null);
                    { WinFormsUtil.Alert($"Set {s2.Type} gift to {s1.Type} slot."); return; }
                }
                if (s1.Type != s2.Type)
                { WinFormsUtil.Alert($"Can't swap {s2.Type} with {s1.Type}."); return; }
                mga.Gifts[wc_slot] = s1;
                mga.Gifts[index] = s2;

                if (mga.Gifts[wc_slot].Empty) // empty slot created, slide down
                {
                    int i = wc_slot;
                    while (i < index)
                    {
                        if (mga.Gifts[i + 1].Empty)
                            break;
                        if (mga.Gifts[i + 1].Type != mga.Gifts[i].Type)
                            break;

                        i++;

                        var mg1 = mga.Gifts[i];
                        var mg2 = mga.Gifts[i - 1];

                        mga.Gifts[i - 1] = mg1;
                        mga.Gifts[i] = mg2;
                    }
                    index = i-1;
                }
            }
            setBackground(index, Properties.Resources.slotView);
            setGiftBoxes();
        }