コード例 #1
0
ファイル: MysteryUtil.cs プロジェクト: ShadyRelapse-PP/PKHeX
    private static void AddLinesPKM(MysteryGift gift, IBasicStrings strings, ICollection <string> result)
    {
        var id = gift.Generation < 7 ? $"{gift.TID:D5}/{gift.SID:D5}" : $"[{gift.TrainerSID7:D4}]{gift.TrainerID7:D6}";

        var first =
            $"{strings.Species[gift.Species]} @ {strings.Item[gift.HeldItem >= 0 ? gift.HeldItem : 0]}  --- "
            + (gift.IsEgg ? strings.EggName : $"{gift.OT_Name} - {id}");

        result.Add(first);
        result.Add(string.Join(" / ", gift.Moves.Select(z => strings.Move[z])));

        if (gift is WC7 wc7)
        {
            var addItem = wc7.AdditionalItem;
            if (addItem != 0)
            {
                result.Add($"+ {strings.Item[addItem]}");
            }
        }
    }
コード例 #2
0
        /// <summary>
        /// Opens a dialog to save a <see cref="MysteryGift"/> file.
        /// </summary>
        /// <param name="gift"><see cref="MysteryGift"/> to be saved.</param>
        /// <param name="origin">Game the gift originates from</param>
        /// <returns>Result of whether or not the file was saved.</returns>
        public static bool ExportMGDialog(MysteryGift gift, GameVersion origin)
        {
            var sfd = new SaveFileDialog
            {
                Filter   = GetMysterGiftFilter(gift.Format, origin),
                FileName = Util.CleanFileName(gift.FileName)
            };

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

            string path = sfd.FileName;

            SaveBackup(path);

            File.WriteAllBytes(path, gift.Data);
            return(true);
        }
コード例 #3
0
ファイル: SAV_Wondercard.cs プロジェクト: wyatt8740/PKHeX
        private void ViewGiftData(MysteryGift g)
        {
            try
            {
                // only check if the form is visible (not opening)
                if (Visible && g.GiftUsed && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgMsyteryGiftUsedAlert, MsgMysteryGiftUsedFix))
                {
                    g.GiftUsed = false;
                }

                RTB.Lines        = g.GetDescription().ToArray();
                PB_Preview.Image = g.Sprite();
                mg = g;
            }
            catch (Exception e)
            {
                WinFormsUtil.Error(MsgMysteryGiftParseTypeUnknown, e);
                RTB.Clear();
            }
        }
コード例 #4
0
ファイル: SAV_Wondercard.cs プロジェクト: tkfltkgk/PKHeX
        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)
            {
                WinFormsUtil.Error("File is not a Mystery Gift:", path);
                return;
            }
            viewGiftData(g);
        }
コード例 #5
0
ファイル: SpriteUtil.cs プロジェクト: kuzaness/PKHeX.Mobile
 private static SKBitmap GetBaseImage(MysteryGift gift)
 {
     if (gift.IsEgg && gift.Species == 490) // Manaphy Egg
     {
         return(SpriteBuilder.LoadBitmapResource("pkm.490_e"));
     }
     if (gift.IsPokémon)
     {
         return(GetSprite(gift.Species, gift.Form, gift.Gender, gift.HeldItem, gift.IsEgg, gift.IsShiny, gift.Format));
     }
     if (gift.IsItem)
     {
         int item = gift.ItemID;
         if (Legal.ZCrystalDictionary.TryGetValue(item, out int value))
         {
             item = value;
         }
         return(SpriteBuilder.LoadBitmapResource($"item.item_{item}") ?? SpriteBuilder.LoadBitmapResource("bag.Bag_Key"));
     }
     return(SpriteBuilder.LoadBitmapResource("pkm.unknown"));
 }
コード例 #6
0
        private void viewGiftData(MysteryGift g)
        {
            try
            {
                // only check if the form is visible (not opening)
                if (Visible && g.GiftUsed && DialogResult.Yes ==
                        WinFormsUtil.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 = g.Sprite();
                mg = g;
            }
            catch (Exception e)
            {
                WinFormsUtil.Error("Loading of data failed... is this really a Wonder Card?", e);
                RTB.Clear();
            }
        }
コード例 #7
0
 private static Image GetBaseImage(MysteryGift gift)
 {
     if (gift.IsEgg && gift.Species == 490) // Manaphy Egg
     {
         return((Image)(Resources.ResourceManager.GetObject("_490_e") ?? Resources.unknown));
     }
     if (gift.IsPokémon)
     {
         return(GetSprite(gift.Species, gift.Form, gift.Gender, gift.HeldItem, gift.IsEgg, gift.IsShiny, gift.Format));
     }
     if (gift.IsItem)
     {
         int item = gift.ItemID;
         if (Legal.ZCrystalDictionary.TryGetValue(item, out int value))
         {
             item = value;
         }
         return((Image)(Resources.ResourceManager.GetObject("item_" + item) ?? Resources.unknown));
     }
     return(Resources.unknown);
 }
コード例 #8
0
        // Mystery Gift IO (.file<->window)
        private void B_Import_Click(object sender, EventArgs e)
        {
            OpenFileDialog import = new OpenFileDialog {
                Filter = WinFormsUtil.GetMysterGiftFilter(SAV.Generation, SAV.Version)
            };

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

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

            if (g == null)
            {
                WinFormsUtil.Error(MsgMysteryGiftInvalid, path);
                return;
            }
            ViewGiftData(g);
        }
コード例 #9
0
    private static Image GetBaseImage(MysteryGift gift)
    {
        if (gift.IsEgg && gift.Species == (int)Species.Manaphy) // Manaphy Egg
        {
            return(SpriteUtil.GetMysteryGiftPreviewPoke(gift));
        }
        if (gift.IsPokémon)
        {
            return(SpriteUtil.GetMysteryGiftPreviewPoke(gift));
        }

        if (gift.IsItem)
        {
            int item = gift.ItemID;
            if (Legal.ZCrystalDictionary.TryGetValue(item, out int value))
            {
                item = value;
            }
            return(SpriteUtil.GetItemSprite(item) ?? Resources.Bag_Key);
        }
        return(PokeSprite.Properties.Resources.b_unknown);
    }
コード例 #10
0
        private void ClickSet(object sender, EventArgs e)
        {
            if (!IsSpecialWonderCard(mg))
            {
                return;
            }

            sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
            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 (mg is PCD pcd && mga.Gifts[index] is PGT)
            {
                mg = pcd.Gift;
            }
コード例 #11
0
        private void ClickSet(object sender, EventArgs e)
        {
            if (!IsSpecialWonderCard(mg))
            {
                return;
            }

            sender = WinFormsUtil.GetUnderlyingControl(sender);
            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 (mg is PCD pcd && mga.Gifts[index] is PGT)
            {
                mg = pcd.Gift;
            }
コード例 #12
0
        private void ClickSet(object sender, EventArgs e)
        {
            if (!mg.IsCardCompatible(SAV, out var msg))
            {
                WinFormsUtil.Alert(MsgMysteryGiftSlotFail, msg);
                return;
            }

            sender = WinFormsUtil.GetUnderlyingControl(sender);
            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 (mg is PCD pcd && mga.Gifts[index] is PGT)
            {
                mg = pcd.Gift;
            }
コード例 #13
0
        private static Image GetSprite(MysteryGift gift)
        {
            if (gift.Empty)
            {
                return(null);
            }

            Image img;

            if (gift.IsEgg && gift.Species == 490) // Manaphy Egg
            {
                img = (Image)(Resources.ResourceManager.GetObject("_490_e") ?? Resources.unknown);
            }
            else if (gift.IsPokémon)
            {
                img = GetSprite(gift.Species, gift.Form, gift.Gender, gift.HeldItem, gift.IsEgg, gift.IsShiny, gift.Format);
            }
            else if (gift.IsItem)
            {
                int item = gift.ItemID;
                if (Legal.ZCrystalDictionary.TryGetValue(item, out int value))
                {
                    item = value;
                }
                img = (Image)(Resources.ResourceManager.GetObject("item_" + item) ?? Resources.unknown);
            }
            else
            {
                img = Resources.unknown;
            }

            if (gift.GiftUsed)
            {
                img = ImageUtil.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3);
            }
            return(img);
        }
コード例 #14
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();
            }
        }
コード例 #15
0
ファイル: SAV_Wondercard.cs プロジェクト: tkfltkgk/PKHeX
        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);
        }
コード例 #16
0
ファイル: MysteryUtil.cs プロジェクト: ShadyRelapse-PP/PKHeX
 /// <summary>
 /// Gets a description of the <see cref="MysteryGift"/> using the current default string data.
 /// </summary>
 /// <param name="gift">Gift data to parse</param>
 /// <returns>List of lines</returns>
 public static IEnumerable <string> GetDescription(this MysteryGift gift) => gift.GetDescription(GameInfo.Strings);
コード例 #17
0
 public static Image GenerateQRCode(MysteryGift mg) => GenerateQRCode(QRMessageUtil.GetMessage(mg));
コード例 #18
0
ファイル: Program.cs プロジェクト: Sotam/MysteryGiftTool
        private static void ExtractArchives()
        {
            foreach (var game in games)
            {
                Log($"Extracting archives for {game.Name}...");
                var game_dir    = Path.Combine("data", game.Name);
                var archive_dir = Path.Combine(game_dir, "boss");
                var dec_dir     = Path.Combine(game_dir, "boss_dec");
                CreateDirectoryIfNull(archive_dir);
                CreateDirectoryIfNull(dec_dir);
                foreach (var file in new DirectoryInfo(archive_dir).GetFiles())
                {
                    if (!file.Name.Contains("-_-"))
                    {
                        continue;
                    }
                    var boss     = BossMetadata.FromArchiveName(file.Name);
                    var dec_path = Path.Combine(dec_dir, boss.FileName);
                    if (File.Exists(dec_path))
                    {
                        continue;
                    }
                    Log($"Decrypting {boss.FileName}...");
                    var dec_data = engine.DecryptBOSS(File.ReadAllBytes(file.FullName));
                    if (dec_data == null)
                    {
                        Log($"Failed to decrypt {boss.FileName}");
                        continue;
                    }
                    Log($"Decrypted {boss.FileName}.");
                    File.WriteAllBytes(dec_path, dec_data);

                    var contentData = dec_data.Skip(0x296).ToArray();
                    if (contentData.Length % 0x310 == 0) // Wondercard!
                    {
                        var wcgdir    = Path.Combine("wondercards", game.Name);
                        var wcdir     = Path.Combine(wcgdir, $"wc{game.Generation}");
                        var wcfulldir = Path.Combine(wcgdir, $"wc{game.Generation}full");
                        CreateDirectoryIfNull(wcgdir);
                        CreateDirectoryIfNull(wcdir);
                        CreateDirectoryIfNull(wcfulldir);

                        var count = 0;
                        do
                        {
                            count++;
                            var currentWc = contentData.Take(0x310).ToArray();

                            var gameId = contentData.Take(0x03).ToArray();

                            File.WriteAllBytes(Path.Combine(wcfulldir, boss.FileName + $"_{GetGameVersion(gameId, game.Generation)}_{count}.wc{game.Generation}full"), currentWc);

                            MysteryGift wc = null;
                            if (game.Generation == 6)
                            {
                                wc = new WC6(currentWc);
                                File.WriteAllBytes(Path.Combine(wcdir, boss.FileName + $"_{GetGameVersion(gameId, game.Generation)}_{count}.wc{game.Generation}"), wc.Data);
                            }
                            else if (game.Generation == 7)
                            {
                                wc = new WC7(currentWc);
                                File.WriteAllBytes(Path.Combine(wcdir, boss.FileName + $"_{GetGameVersion(gameId, game.Generation)}_{count}.wc{game.Generation}"), wc.Data);
                            }

                            Log($"{boss.FileName} ({count}) is a wondercard ({wc.Type}): ");
                            var fullDesc = Util.TrimFromZero(Encoding.Unicode.GetString(currentWc, 4, 0x1FC));
                            //Log(fullDesc);

                            Log(GetWonderCardDescription(wc));
                            contentData = contentData.Skip(0x310).ToArray(); // Keep remaining data
                        } while (contentData.Length > 0 && contentData.Length % 0x310 == 0);

                        if (contentData.Length > 0)
                        {
                            Log($"Data remaining: {contentData.Length}");
                        }
                        Log($"Found WCs: {count}.");
                    }
                    else if (boss.Name.ToUpper().Contains("CUP") && contentData.Length == 0x4C0) // CUP Regulation
                    {
                        Log($"{boss.FileName} is a CUP!");
                        var cup_dir = Path.Combine("cups", game.Name);
                        CreateDirectoryIfNull(cup_dir);
                        var reg_arc = new RegulationArchive(contentData, boss.FileName);
                        Log($"Extracting/Saving {boss.FileName}...");
                        reg_arc.Save(cup_dir);
                    }
                    else if (boss.Name.Contains("regulation") && game.Generation == 7) // Gen VII Regulations
                    {
                        Log($"{boss.FileName} is a regulation!");
                        var reg_dir = Path.Combine("regulations", game.Name);
                        CreateDirectoryIfNull(reg_dir);
                        var reg_arc = new RegulationArchive(contentData, boss.FileName);
                        Log($"Extracting/Saving {boss.FileName}...");
                        reg_arc.Save(reg_dir);
                    }
                    else
                    {
                        Log($"{boss.FileName} {contentData.Length} unknown file format");
                    }
                }
            }
        }
コード例 #19
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();
        }
コード例 #20
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();
        }
コード例 #21
0
 /// <summary>
 /// Tries to get a <see cref="MysteryGift"/> object from the input parameters.
 /// </summary>
 /// <param name="data">Binary data</param>
 /// <param name="mg">Output result</param>
 /// <param name="ext">Format hint</param>
 /// <returns>True if file object reference is valid, false if none found.</returns>
 public static bool TryGetMysteryGift(byte[] data, [NotNullWhen(true)] out MysteryGift?mg, string ext)
 {
     mg = MysteryGift.GetMysteryGift(data, ext);
     return(mg != null);
 }
コード例 #22
0
        private static string GetDescription(MysteryGift gift, SaveFile SAV)
        {
            if (gift.Empty)
            {
                return("Empty Slot. No data!");
            }

            string s = gift.CardHeader + Environment.NewLine;

            if (gift.IsItem)
            {
                s += $"Item: {GameInfo.Strings.itemlist[gift.ItemID]} (Quantity: {gift.Quantity})" + Environment.NewLine;
                if (gift is WC7)
                {
                    var ind = 1;
                    var wc7 = (WC7)gift;
                    while (wc7.GetItem(ind) != 0)
                    {
                        s += $"Item: {GameInfo.Strings.itemlist[wc7.GetItem(ind)]} (Quantity: {wc7.GetQuantity(ind)})" + Environment.NewLine;
                        ind++;
                    }
                }
            }
            else if (gift.IsPokémon)
            {
                PKM pk = gift.ConvertToPKM(SAV);

                try
                {
                    s += $"{GameInfo.Strings.specieslist[pk.Species]} @ {GameInfo.Strings.itemlist[pk.HeldItem]}  --- ";
                    s += (pk.IsEgg ? GameInfo.Strings.eggname : $"{pk.OT_Name} - {pk.TID:00000}/{pk.SID:00000}") + Environment.NewLine;
                    s += $"{GameInfo.Strings.movelist[pk.Move1]} / {GameInfo.Strings.movelist[pk.Move2]} / {GameInfo.Strings.movelist[pk.Move3]} / {GameInfo.Strings.movelist[pk.Move4]}" + Environment.NewLine;
                    if (gift is WC7)
                    {
                        var addItem = ((WC7)gift).AdditionalItem;
                        if (addItem != 0)
                        {
                            s += $"+ {GameInfo.Strings.itemlist[addItem]}" + Environment.NewLine;
                        }
                    }
                }
                catch { s += "Unable to create gift description." + Environment.NewLine; }
            }
            else if (gift.IsBP)
            {
                s += "BP: " + gift.BP + Environment.NewLine;
            }
            else if (gift.IsBean)
            {
                s += "Bean ID: " + gift.Bean + Environment.NewLine + "Quantity: " + gift.Quantity + Environment.NewLine;
            }
            else
            {
                s += "Unknown Wonder Card Type!" + Environment.NewLine;
            }
            if (gift is WC7)
            {
                var wc7 = (WC7)gift;
                s += $"Repeatable: {wc7.GiftRepeatable}" + Environment.NewLine;
                s += $"Collected: {wc7.GiftUsed}" + Environment.NewLine;
                s += $"Once Per Day: {wc7.GiftOncePerDay}" + Environment.NewLine;
            }
            return(s);
        }
コード例 #23
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)
                {
                    WinFormsUtil.Alert("Data size invalid.", files[0]); return;
                }

                byte[] data = File.ReadAllBytes(files[0]);
                if (data.Length != mga.Gifts[index].Data.Length)
                {
                    WinFormsUtil.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)
                {
                    WinFormsUtil.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, Core.Properties.Resources.slotView);
            setGiftBoxes();
        }
コード例 #24
0
ファイル: SpriteUtil.cs プロジェクト: kuzaness/PKHeX.Mobile
 public static SKBitmap Sprite(this MysteryGift gift) => GetSprite(gift);
コード例 #25
0
 public static Image Sprite(this MysteryGift gift) => GetSprite(gift);
コード例 #26
0
ファイル: Program.cs プロジェクト: hnjm/MysteryGiftTool
        private static void ExtractArchives()
        {
            foreach (var game in games)
            {
                Log($"Extracting archives for {game.Name}...");
                var game_dir    = Path.Combine("data", game.Name);
                var archive_dir = Path.Combine(game_dir, "boss");
                var dec_dir     = Path.Combine(game_dir, "boss_dec");
                CreateDirectoryIfNull(archive_dir);
                CreateDirectoryIfNull(dec_dir);
                foreach (var file in new DirectoryInfo(archive_dir).GetFiles())
                {
                    if (!file.Name.Contains("-_-"))
                    {
                        continue;
                    }
                    var boss     = BossMetadata.FromArchiveName(file.Name);
                    var dec_path = Path.Combine(dec_dir, boss.FileName);
                    if (File.Exists(dec_path))
                    {
                        continue;
                    }
                    Log($"Decrypting {boss.FileName}...");
                    var dec_data = engine.DecryptBOSS(File.ReadAllBytes(file.FullName));
                    if (dec_data == null)
                    {
                        Log($"Failed to decrypt {boss.FileName}");
                        continue;
                    }
                    Log($"Decrypted {boss.FileName}.");
                    File.WriteAllBytes(dec_path, dec_data);

                    var content_data = dec_data.Skip(0x296).ToArray();
                    if (content_data.Length == 0x310) // Wondercard!
                    {
                        var wcgdir    = Path.Combine("wondercards", game.Name);
                        var wcdir     = Path.Combine(wcgdir, $"wc{game.Generation}");
                        var wcfulldir = Path.Combine(wcgdir, $"wc{game.Generation}full");
                        CreateDirectoryIfNull(wcgdir);
                        CreateDirectoryIfNull(wcdir);
                        CreateDirectoryIfNull(wcfulldir);

                        File.WriteAllBytes(Path.Combine(wcfulldir, boss.FileName + $".wc{game.Generation}full"), content_data);

                        MysteryGift wc = null;
                        if (game.Generation == 6)
                        {
                            wc = new WC6(content_data);
                            File.WriteAllBytes(Path.Combine(wcdir, boss.FileName + $".wc{game.Generation}"), wc.Data);
                        }
                        else if (game.Generation == 7)
                        {
                            wc = new WC7(content_data);
                            File.WriteAllBytes(Path.Combine(wcdir, boss.FileName + $".wc{game.Generation}"), wc.Data);
                        }

                        Log($"{boss.FileName} is a wondercard ({wc.Type}): ");
                        Log(wc.FullDesc);
                        Log(MysteryGift.getDescription(wc));
                    }
                    else if (boss.Name.ToUpper().Contains("CUP") && content_data.Length == 0x4C0) // CUP Regulation
                    {
                        Log($"{boss.FileName} is a CUP!");
                        var cup_dir = Path.Combine("cups", game.Name);
                        CreateDirectoryIfNull(cup_dir);
                        var reg_arc = new RegulationArchive(content_data, boss.FileName);
                        Log($"Extracting/Saving {boss.FileName}...");
                        reg_arc.Save(cup_dir);
                    }
                    else if (boss.Name.Contains("regulation") && game.Generation == 7) // Gen VII Regulations
                    {
                        Log($"{boss.FileName} is a regulation!");
                        var reg_dir = Path.Combine("regulations", game.Name);
                        CreateDirectoryIfNull(reg_dir);
                        var reg_arc = new RegulationArchive(content_data, boss.FileName);
                        Log($"Extracting/Saving {boss.FileName}...");
                        reg_arc.Save(reg_dir);
                    }
                }
            }
        }
コード例 #27
0
 public static Image Sprite(this MysteryGift gift, SaveFile SAV) => GetSprite(gift, SAV);
コード例 #28
0
ファイル: SAV_BoxViewer.cs プロジェクト: Rocci1212/PKHeX
        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();
            }
        }
コード例 #29
0
        private static IEnumerable <string> GetDescription(MysteryGift gift, SaveFile SAV)
        {
            if (gift.Empty)
            {
                return new[] { "Empty Slot. No data!" }
            }
            ;

            var result = new List <string> {
                gift.CardHeader
            };

            if (gift.IsItem)
            {
                result.Add($"Item: {GameInfo.Strings.itemlist[gift.ItemID]} (Quantity: {gift.Quantity})");

                if (gift is WC7 wc7)
                {
                    var ind = 1;
                    while (wc7.GetItem(ind) != 0)
                    {
                        result.Add($"Item: {GameInfo.Strings.itemlist[wc7.GetItem(ind)]} (Quantity: {wc7.GetQuantity(ind)})");
                        ind++;
                    }
                }
            }
            else if (gift.IsPokémon)
            {
                PKM pk = gift.ConvertToPKM(SAV);

                try
                {
                    var first =
                        $"{GameInfo.Strings.specieslist[pk.Species]} @ {GameInfo.Strings.itemlist[pk.HeldItem]}  --- "
                        + (pk.IsEgg ? GameInfo.Strings.eggname : $"{pk.OT_Name} - {pk.TID:00000}/{pk.SID:00000}");
                    result.Add(first);
                    result.Add(string.Join(" / ", pk.Moves.Select(z => GameInfo.Strings.movelist[z])));

                    if (gift is WC7 wc7)
                    {
                        var addItem = wc7.AdditionalItem;
                        if (addItem != 0)
                        {
                            result.Add($"+ {GameInfo.Strings.itemlist[addItem]}");
                        }
                    }
                }
                catch { result.Add("Unable to create gift description."); }
            }
            else if (gift.IsBP)
            {
                result.Add($"BP: {gift.BP}");
            }
            else if (gift.IsBean)
            {
                result.Add($"Bean ID: {gift.Bean}");
                result.Add($"Quantity: {gift.Quantity}");
            }
            else
            {
                result.Add("Unknown Wonder Card Type!");
            }
            if (gift is WC7 w7)
            {
                result.Add($"Repeatable: {w7.GiftRepeatable}");
                result.Add($"Collected: {w7.GiftUsed}");
                result.Add($"Once Per Day: {w7.GiftOncePerDay}");
            }
            return(result);
        }