Esempio n. 1
0
        private void ExportQRFromView()
        {
            if (mg.Data.SequenceEqual(new byte[mg.Data.Length]))
            {
                WinFormsUtil.Alert("No wondercard data found in loaded slot!");
                return;
            }
            if (SAV.Generation == 6 && mg.ItemID == 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, SAV)}";

            new QR(qr, PB_Preview.Image, null, desc + "PKHeX Wonder Card @ ProjectPokemon.org").ShowDialog();
        }
Esempio n. 2
0
        private void ImportQRToView(string url)
        {
            byte[] data = QR.GetQRData(url);
            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
            {
                ViewGiftData(gift);
            }
        }
Esempio n. 3
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();
            }
        }
        private void ExportQRCodes(object sender, EventArgs e)
        {
            SaveFile SAV     = C_SAV.SAV;
            var      boxdata = SAV.BoxData;

            if (boxdata == null)
            {
                WinFormsUtil.Alert("Box Data is null");
            }
            int ctr = 0;
            Dictionary <string, Image> qrcodes = new Dictionary <string, Image>();

            foreach (PKM pk in boxdata)
            {
                if (pk.Species == 0 || !pk.Valid || (pk.Box - 1) != C_SAV.Box.CurrentBox)
                {
                    continue;
                }
                ctr++;
                Image qr;
                switch (pk.Format)
                {
                case 7:
                    qr = QR.GenerateQRCode7((PK7)pk);
                    break;

                default:
                    if (pk.Format == 6 && !QR6Notified)     // users should not be using QR6 injection
                    {
                        WinFormsUtil.Alert(MsgQRDeprecated, MsgQRAlternative);
                        QR6Notified = true;
                    }
                    qr = QR.GetQRImage(pk.EncryptedBoxData, QR.GetQRServer(pk.Format));
                    break;
                }
                if (qr == null)
                {
                    continue;
                }
                var sprite = dragout.Image;
                var la     = new LegalityAnalysis(pk, C_SAV.SAV.Personal);
                if (la.Parsed && pk.Species != 0)
                {
                    var img = la.Valid ? Resources.valid : Resources.warn;
                    sprite = ImageUtil.LayerImage(sprite, img, 24, 0, 1);
                }
                string[] r     = pk.QRText;
                string   refer = "PKHeX Auto Legality Mod";
                qrcodes.Add(Util.CleanFileName(pk.FileName), RefreshImage(qr, sprite, r[0], r[1], r[2], $"{refer} ({pk.GetType().Name})"));
            }
            if (!Directory.Exists(Path.Combine(WorkingDirectory, "qrcodes")))
            {
                Directory.CreateDirectory(Path.Combine(WorkingDirectory, "qrcodes"));
            }
            int counter = 0;

            foreach (KeyValuePair <string, Image> qrcode in qrcodes)
            {
                Console.WriteLine(counter);
                counter++;
                qrcode.Value.Save(Path.Combine(WorkingDirectory, "qrcodes", qrcode.Key + ".png"));
            }
        }