Пример #1
0
        internal static Image getSprite(MysteryGift gift)
        {
            Image img;
            if (gift.IsPokémon)
                img = PKX.getSprite(gift.convertToPKM(Main.SAV));
            else if (gift.IsItem)
                img = (Image)(Properties.Resources.ResourceManager.GetObject("item_" + gift.Item) ?? Properties.Resources.unknown);
            else
                img = Properties.Resources.unknown;

            if (gift.GiftUsed)
                img = Util.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3);
            return img;
        }
Пример #2
0
        public SAV_Wondercard(MysteryGift g = null)
        {
            InitializeComponent();
            Util.TranslateInterface(this, Main.curlanguage);
            mga = Main.SAV.GiftAlbum;

            switch (SAV.Generation)
            {
                case 4:
                    pba = popG4Gifts().ToArray();
                    break;
                case 5:
                case 6:
                case 7:
                    pba = popG567Gifts().ToArray();
                    break;
                default:
                    throw new ArgumentException("Game not supported.");
            }

            foreach (PictureBox pb in pba)
            {
                pb.AllowDrop = true;
                pb.DragDrop += pbBoxSlot_DragDrop;
                pb.DragEnter += pbBoxSlot_DragEnter;
                pb.MouseDown += pbBoxSlot_MouseDown;
                pb.ContextMenuStrip = mnuVSD;
            }

            setGiftBoxes();
            getReceivedFlags();

            if (LB_Received.Items.Count > 0)
                LB_Received.SelectedIndex = 0;

            DragEnter += tabMain_DragEnter;
            DragDrop += tabMain_DragDrop;

            if (g == null)
                clickView(pba[0], null);
            else
                viewGiftData(g);
        }
Пример #3
0
        private void B_Import_Click(object sender, EventArgs e)
        {
            OpenFileDialog import = new OpenFileDialog {
                Filter = getFilter()
            };

            if (import.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string      path = import.FileName;
            MysteryGift g    = MysteryGift.getMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path));

            if (g == null)
            {
                Util.Error("File is not a Mystery Gift:", path);
                return;
            }
            viewGiftData(g);
        }
Пример #4
0
        private void viewGiftData(MysteryGift g)
        {
            try
            {
                // only check if the form is visible (not opening)
                if (Visible && g.GiftUsed && DialogResult.Yes ==
                        Util.Prompt(MessageBoxButtons.YesNo,
                            "Wonder Card is marked as USED and will not be able to be picked up in-game.",
                            "Do you want to remove the USED flag so that it is UNUSED?"))
                    g.GiftUsed = false;

                RTB.Text = getDescription(g);
                PB_Preview.Image = getSprite(g);
                mg = g;
            }
            catch (Exception e)
            {
                Util.Error("Loading of data failed... is this really a Wonder Card?", e);
                RTB.Clear();
            }
        }
Пример #5
0
        private static string getDescription(MysteryGift gift)
        {
            if (gift.Empty)
            {
                return("Empty Slot. No data!");
            }

            string s = gift.getCardHeader() + Environment.NewLine;

            if (gift.IsItem)
            {
                s += "Item: " + Main.GameStrings.itemlist[gift.Item] + Environment.NewLine + "Quantity: " + gift.Quantity;
                return(s);
            }
            if (gift.IsPokémon)
            {
                PKM pk = gift.convertToPKM(Main.SAV);

                try
                {
                    s += $"{Main.GameStrings.specieslist[pk.Species]} @ {Main.GameStrings.itemlist[pk.HeldItem]}  --- ";
                    s += (pk.IsEgg ? Main.GameStrings.eggname : $"{pk.OT_Name} - {pk.TID.ToString("00000")}/{pk.SID.ToString("00000")}") + Environment.NewLine;
                    s += $"{Main.GameStrings.movelist[pk.Move1]} / {Main.GameStrings.movelist[pk.Move2]} / {Main.GameStrings.movelist[pk.Move3]} / {Main.GameStrings.movelist[pk.Move4]}" + Environment.NewLine;
                    if (gift is WC7)
                    {
                        var addItem = ((WC7)gift).AdditionalItem;
                        if (addItem != 0)
                        {
                            s += $"+ {Main.GameStrings.itemlist[addItem]}";
                        }
                    }
                }
                catch { s += "Unable to create gift description."; }
                return(s);
            }
            s += "Unknown Wonder Card Type!";
            return(s);
        }
Пример #6
0
        private static Image getSprite(MysteryGift gift)
        {
            Image img;

            if (gift.IsPokémon)
            {
                img = PKX.getSprite(gift.convertToPKM(Main.SAV));
            }
            else if (gift.IsItem)
            {
                img = (Image)(Properties.Resources.ResourceManager.GetObject("item_" + gift.Item) ?? Properties.Resources.unknown);
            }
            else
            {
                img = Properties.Resources.unknown;
            }

            if (gift.GiftUsed)
            {
                img = Util.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3);
            }
            return(img);
        }
Пример #7
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))
                    Util.Alert("Decoded data not valid for loaded save file.", $"QR Data Size: 0x{data.Length.ToString("X")}");
                else if (types.All(type => type != giftType))
                    Util.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)
                    Util.Alert("Gift Details are not compatible with the save file.");
                else
                    try { viewGiftData(gift); }
                    catch { Util.Alert("Error loading Mystery Gift data."); }
            }
            else
            {
                if (mg.Data.SequenceEqual(new byte[mg.Data.Length]))
                { Util.Alert("No wondercard data found in loaded slot!"); return; }
                if (SAV.Generation == 6 && mg.Item == 726 && mg.IsItem)
                { Util.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();
            }
        }
Пример #8
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 : Util.Alert("Unable to insert the Mystery Gift.", "Does this Mystery Gift really belong to this game?");
            return(false);
        }
Пример #9
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: Util.Alert("Unable to insert the Mystery Gift.", "Does this Mystery Gift really belong to this game?");
            return false;
        }
Пример #10
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)
                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)
                { Util.Alert("Data size invalid.", files[0]); return; }
                
                byte[] data = File.ReadAllBytes(files[0]);
                if (data.Length != mga.Gifts[index].Data.Length)
                {
                    Util.Alert("Can't set slot here.",
                        $"{data.Length} != {mga.Gifts[index].Data.Length}, {mga.Gifts[index].Type}", files[0]);
                    return;
                }

                mga.Gifts[index].Data = data;
                setCardID(mga.Gifts[index].CardID);
                viewGiftData(mga.Gifts[index]);
            }
            else // Swap Data
            {
                MysteryGift s1 = mga.Gifts[index];
                MysteryGift s2 = mga.Gifts[wc_slot];

                if (s1.Type != s2.Type)
                { Util.Alert($"Can't swap {s1.Type} with {s2.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();
        }
Пример #11
0
        private static string getDescription(MysteryGift gift)
        {
            if (gift.Empty)
                return "Empty Slot. No data!";

            string s = gift.getCardHeader() + Environment.NewLine;
            if (gift.IsItem)
            {
                s += "Item: " + Main.GameStrings.itemlist[gift.Item] + Environment.NewLine + "Quantity: " + gift.Quantity;
                return s;
            }
            if (gift.IsPokémon)
            {
                PKM pk = gift.convertToPKM(Main.SAV);

                try
                {
                    s += $"{Main.GameStrings.specieslist[pk.Species]} @ {Main.GameStrings.itemlist[pk.HeldItem]}  --- ";
                    s += (pk.IsEgg ? Main.GameStrings.eggname : $"{pk.OT_Name} - {pk.TID.ToString("00000")}/{pk.SID.ToString("00000")}") + Environment.NewLine;
                    s += $"{Main.GameStrings.movelist[pk.Move1]} / {Main.GameStrings.movelist[pk.Move2]} / {Main.GameStrings.movelist[pk.Move3]} / {Main.GameStrings.movelist[pk.Move4]}" + Environment.NewLine;
                }
                catch { s += "Unable to create gift description."; }
                return s;
            }
            s += "Unknown Wonder Card Type!";
            return s;
        }
Пример #12
0
        public SAV_MysteryGiftDB(Main f1)
        {
            m_parent = f1;
            InitializeComponent();

            // Preset Filters to only show PKM available for loaded save
            CB_FormatComparator.SelectedIndex = 3; // <=

            PKXBOXES = new[]
            {
                bpkx1, bpkx2, bpkx3, bpkx4, bpkx5, bpkx6,
                bpkx7, bpkx8, bpkx9, bpkx10, bpkx11, bpkx12,
                bpkx13, bpkx14, bpkx15, bpkx16, bpkx17, bpkx18,
                bpkx19, bpkx20, bpkx21, bpkx22, bpkx23, bpkx24,
                bpkx25, bpkx26, bpkx27, bpkx28, bpkx29, bpkx30,

                bpkx31, bpkx32, bpkx33, bpkx34, bpkx35, bpkx36,
                bpkx37, bpkx38, bpkx39, bpkx40, bpkx41, bpkx42,
                bpkx43, bpkx44, bpkx45, bpkx46, bpkx47, bpkx48,
                bpkx49, bpkx50, bpkx51, bpkx52, bpkx53, bpkx54,
                bpkx55, bpkx56, bpkx57, bpkx58, bpkx59, bpkx60,
                bpkx61, bpkx62, bpkx63, bpkx64, bpkx65, bpkx66,
            };

            // Enable Scrolling when hovered over
            PAN_Box.MouseHover += (sender, args) =>
            {
                if (ActiveForm == this)
                {
                    SCR_Box.Focus();
                }
            };
            foreach (var slot in PKXBOXES)
            {
                slot.MouseEnter += (sender, args) =>
                {
                    if (ActiveForm == this)
                    {
                        SCR_Box.Focus();
                    }
                };
                // Enable Click
                slot.MouseClick += (sender, args) =>
                {
                    if (ModifierKeys == Keys.Control)
                    {
                        clickView(sender, args);
                    }
                };
            }

            Counter       = L_Count.Text;
            Viewed        = L_Viewed.Text;
            L_Viewed.Text = ""; // invis for now

            ContextMenuStrip  mnu     = new ContextMenuStrip();
            ToolStripMenuItem mnuView = new ToolStripMenuItem("View");

            // Assign event handlers
            mnuView.Click += clickView;

            // Add to main context menu
            mnu.Items.AddRange(new ToolStripItem[] { mnuView });

            // Assign to datagridview
            foreach (PictureBox p in PKXBOXES)
            {
                p.ContextMenuStrip = mnu;
            }

            // Load Data
            RawDB = new List <MysteryGift>();
            RawDB.AddRange(Legal.MGDB_G6);
            RawDB.AddRange(Legal.MGDB_G7);

            if (Directory.Exists(DatabasePath))
            {
                foreach (string file in Directory.GetFiles(DatabasePath, "*", SearchOption.AllDirectories))
                {
                    FileInfo fi = new FileInfo(file);
                    if (!MysteryGift.getIsMysteryGift(fi.Length))
                    {
                        continue;
                    }
                    var mg = MysteryGift.getMysteryGift(File.ReadAllBytes(file), fi.Extension);
                    if (mg != null)
                    {
                        RawDB.Add(mg);
                    }
                }
            }

            RawDB = new List <MysteryGift>(RawDB.Where(mg => !mg.IsItem && mg.IsPokémon && mg.Species > 0).Distinct().OrderBy(mg => mg.Species));
            foreach (var mg in RawDB)
            {
                mg.GiftUsed = false;
            }
            setResults(RawDB);

            Menu_SearchSettings.DropDown.Closing += (sender, e) =>
            {
                if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
                {
                    e.Cancel = true;
                }
            };

            populateComboBoxes();
            CenterToParent();
        }
Пример #13
0
        private void viewGiftData(MysteryGift g)
        {
            try
            {
                // only check if the form is visible (not opening)
                if (Visible && g.GiftUsed && DialogResult.Yes ==
                        Util.Prompt(MessageBoxButtons.YesNo,
                            "Wonder Card is marked as USED and will not be able to be picked up in-game.",
                            "Do you want to remove the USED flag so that it is UNUSED?"))
                    g.GiftUsed = false;

                RTB.Text = getDescription(g);
                PB_Preview.Image = getSprite(g);
                mg = g;
            }
            catch (Exception e)
            {
                Util.Error("Loading of data failed... is this really a Wonder Card?", e);
                RTB.Clear();
            }
        }
Пример #14
0
 private int getLastUnfilledByType(MysteryGift Gift, MysteryGiftAlbum Album)
 {
     for (int i = 0; i < Album.Gifts.Length; i++)
     {
         if (!Album.Gifts[i].Empty)
             continue;
         if (Album.Gifts[i].Type != Gift.Type)
             continue;
         return i;
     }
     return -1;
 }
Пример #15
0
        public SAV_Wondercard(MysteryGift g = null)
        {
            InitializeComponent();
            Util.TranslateInterface(this, Main.curlanguage);
            mga = Main.SAV.GiftAlbum;
            pba = new[]
            {
                PB_Card01, PB_Card02, PB_Card03, PB_Card04, PB_Card05, PB_Card06,
                PB_Card07, PB_Card08, PB_Card09, PB_Card10, PB_Card11, PB_Card12,
                PB_Card13, PB_Card14, PB_Card15, PB_Card16, PB_Card17, PB_Card18,
                PB_Card19, PB_Card20, PB_Card21, PB_Card22, PB_Card23, PB_Card24,
            };

            foreach (PictureBox pb in pba)
            {
                pb.AllowDrop = true;
                // The PictureBoxes have their own drag&drop event handlers.
            }

            // Hide slots not present on game
            for (int i = mga.Gifts.Length; i < pba.Length; i++)
            {
                pba[i].Visible = false;
            }
            if (mga.Gifts.Length < 7)
            {
                L_r2.Visible = false;
            }
            if (mga.Gifts.Length < 13)
            {
                L_r3.Visible = false;
            }
            if (mga.Gifts.Length < 19)
            {
                L_r4.Visible = false;
            }

            if (SAV.Generation == 4) // pgt & pcd, split up
            {
                PB_Card09.Location = PB_Card19.Location;
                PB_Card10.Location = PB_Card20.Location;
                PB_Card11.Location = PB_Card21.Location;
                L_r4.Visible       = true;
                L_r1.Text          = "PGT 1-6";
                L_r2.Text          = "PGT 7-8";
                L_r4.Text          = "PCD 1-3";
            }

            setGiftBoxes();
            getReceivedFlags();

            if (LB_Received.Items.Count > 0)
            {
                LB_Received.SelectedIndex = 0;
            }

            DragEnter += tabMain_DragEnter;
            DragDrop  += tabMain_DragDrop;

            if (g == null)
            {
                clickView(PB_Card01, null);
            }
            else
            {
                viewGiftData(g);
            }
        }
Пример #16
0
        private void pbBoxSlot_DragDrop(object sender, DragEventArgs e)
        {
            DragInfo.slotDestination           = this;
            DragInfo.slotDestinationSlotNumber = getSlot(sender);
            DragInfo.slotDestinationOffset     = getPKXOffset(DragInfo.slotDestinationSlotNumber);
            DragInfo.slotDestinationBoxNumber  = 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.slotDestinationBoxNumber, DragInfo.slotDestinationSlotNumber))
            {
                DragInfo.slotDestinationSlotNumber = -1; // Invalidate
                Util.Alert("Unable to set to locked slot.");
                return;
            }
            if (DragInfo.slotSourceOffset < 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);

                string c;

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

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

                DragInfo.setPKMtoDestination(SAV, pk);
                getQuickFiller(SlotPictureBoxes[DragInfo.slotDestinationSlotNumber], pk);
                Console.WriteLine(c);
            }
            else
            {
                PKM pkz = DragInfo.getPKMfromSource(SAV);
                if (!DragInfo.SourceValid)
                {
                }                                                               // not overwritable, do nothing
                else if (ModifierKeys == Keys.Alt && DragInfo.DestinationValid) // overwrite
                {
                    // Clear from slot
                    if (DragInfo.SameBox)
                    {
                        getQuickFiller(SlotPictureBoxes[DragInfo.slotSourceSlotNumber], SAV.BlankPKM); // picturebox
                    }
                    DragInfo.setPKMtoSource(SAV, SAV.BlankPKM);
                }
                else if (ModifierKeys != Keys.Control && DragInfo.DestinationValid) // move
                {
                    // Load data from destination
                    PKM pk = ((PictureBox)sender).Image != null
                        ? DragInfo.getPKMfromDestination(SAV)
                        : SAV.BlankPKM;

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

                    // Set destination pokemon data to source slot
                    DragInfo.setPKMtoSource(SAV, pk);
                }
                else if (DragInfo.SameBox) // clone
                {
                    getQuickFiller(SlotPictureBoxes[DragInfo.slotSourceSlotNumber], pkz);
                }

                // Copy from temp to destination slot.
                DragInfo.setPKMtoDestination(SAV, pkz);
                getQuickFiller(SlotPictureBoxes[DragInfo.slotDestinationSlotNumber], pkz);

                e.Effect = DragDropEffects.Link;
                Cursor   = DefaultCursor;
            }
            if (DragInfo.SourceParty || DragInfo.DestinationParty)
            {
                parent.setParty();
            }
            if (DragInfo.slotSource == null) // another instance or file
            {
                parent.notifyBoxViewerRefresh();
                DragInfo.Reset();
            }
        }
Пример #17
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 = Array.FindIndex(pba, p => p.Image == null);

            if (lastUnfilled < index)
            {
                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)
                {
                    Util.Alert("Data size invalid.", files[0]); return;
                }

                byte[] data = File.ReadAllBytes(files[0]);
chk:
                if (data.Length != mga.Gifts[index].Data.Length)
                {
                    if (index < 8)
                    {
                        index = 8;
                        goto chk;
                    }
                    { Util.Alert("Can't set slot here.", $"{data.Length} != {mga.Gifts[index].Data.Length}, {mga.Gifts[index].GetType()}", files[0]); return; }
                }

                mga.Gifts[index].Data = data;
                setCardID(mga.Gifts[index].CardID);
                viewGiftData(mga.Gifts[index]);
            }
            else // Swap Data
            {
                // Check to see if they copied beyond blank slots.
                if (index > Math.Max(wc_slot, lastUnfilled - 1))
                {
                    index = Math.Max(wc_slot, lastUnfilled - 1);
                }

                MysteryGift s1 = mga.Gifts[index];
                MysteryGift s2 = mga.Gifts[wc_slot];

                if (s1.Data.Length != s2.Data.Length)
                {
                    Util.Alert("Can't swap these two slots."); return;
                }
                mga.Gifts[wc_slot] = s1;
                mga.Gifts[index]   = s2;
            }
            setBackground(index, Properties.Resources.slotView);
            setGiftBoxes();
        }