Beispiel #1
0
        public void setWC6(WC6 wc6, int index)
        {
            if (WondercardData < 0)
            {
                return;
            }
            if (index < 0 || index > 24)
            {
                return;
            }

            wc6.Data.CopyTo(Data, WondercardData + index * WC6.Size);

            for (int i = 0; i < 24; i++)
            {
                if (BitConverter.ToUInt16(Data, WondercardData + i * WC6.Size) == 0)
                {
                    for (int j = i + 1; j < 24 - i; j++) // Shift everything down
                    {
                        Array.Copy(Data, WondercardData + j * WC6.Size, Data, WondercardData + (j - 1) * WC6.Size, WC6.Size);
                    }
                }
            }

            Edited = true;
        }
Beispiel #2
0
        // String Creation
        private string getWCDescriptionString(byte[] data)
        {
            WC6 wc = new WC6(data);

            if (wc.CardID == 0)
            {
                return("Empty Slot. No data!");
            }

            string s = $"Card #: {wc.CardID.ToString("0000")} - {wc.CardTitle.Trim()}" + Environment.NewLine;

            switch (wc.CardType)
            {
            case 1:
                s += "Item: " + Main.itemlist[wc.Item] + Environment.NewLine + "Quantity: " + wc.Quantity;
                return(s);

            case 0:
                s +=
                    $"{Main.specieslist[wc.Species]} @ {Main.itemlist[wc.HeldItem]} --- {wc.OT} - {wc.TID.ToString("00000")}/{wc.SID.ToString("00000")}" + Environment.NewLine +
                    $"{Main.movelist[wc.Move1]} / {Main.movelist[wc.Move2]} / {Main.movelist[wc.Move3]} / {Main.movelist[wc.Move4]}" + Environment.NewLine;
                return(s);

            default:
                s += "Unknown Wonder Card Type!";
                return(s);
            }
        }
Beispiel #3
0
        private LegalityCheck verifyLevel()
        {
            WC6 MatchedWC6 = EncounterMatch as WC6;

            if (MatchedWC6 != null && MatchedWC6.Level != pk6.Met_Level)
            {
                return(new LegalityCheck(Severity.Invalid, "Met Level does not match Wonder Card level."));
            }

            int lvl = pk6.CurrentLevel;

            if (lvl < pk6.Met_Level)
            {
                return(new LegalityCheck(Severity.Invalid, "Current level is below met level."));
            }
            if ((pk6.WasEgg || EncounterMatch == null) && !Legal.getEvolutionValid(pk6))
            {
                return(new LegalityCheck(Severity.Invalid, "Level is below evolution requirements."));
            }
            if (lvl > pk6.Met_Level && lvl > 1 && lvl != 100 && pk6.EXP == PKX.getEXP(pk6.Stat_Level, pk6.Species))
            {
                return(new LegalityCheck(Severity.Fishy, "Current experience matches level threshold."));
            }

            return(new LegalityCheck(Severity.Valid, "Current level is not below met level."));
        }
        private void loadwcdata()
        {
            if (wc6 == null)
            {
                return;
            }
            try
            {
                if (wc6.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?"))
                {
                    wc6.GiftUsed = false;
                }

                RTB.Text         = wc6.Description;
                PB_Preview.Image = wc6.Preview;
            }
            catch (Exception e)
            {
                Util.Error("Loading of data failed... is this really a Wonder Card?", e.ToString());
                wc6 = new WC6();
                RTB.Clear();
            }
        }
 private void populateWClist()
 {
     for (int i = 0; i < 24; i++)
     {
         WC6 wc = SAV.getWC6(i);
         pba[i].Image = wc.CardID == 0 ? null : wc.Preview;
     }
 }
        // Wonder Card RW (window<->sav)
        private void clickView(object sender, EventArgs e)
        {
            sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
            int index = Array.IndexOf(pba, sender);

            setBackground(index, Properties.Resources.slotView);
            wc6 = SAV.getWC6(index);
            loadwcdata();
        }
        private void L_QR_Click(object sender, EventArgs e)
        {
            if (ModifierKeys == Keys.Alt)
            {
                byte[] data = Util.getQRData();
                if (data == null)
                {
                    return;
                }
                if (data.Length != WC6.Size)
                {
                    Util.Alert("Decoded data not 0x108 bytes.",
                               $"QR Data Size: 0x{data.Length.ToString("X")}");
                }
                else
                {
                    try
                    {
                        wc6 = new WC6(data);
                        loadwcdata();
                    }
                    catch { Util.Alert("Error loading wondercard data."); }
                }
            }
            else
            {
                if (wc6.Data.SequenceEqual(new byte[wc6.Data.Length]))
                {
                    Util.Alert("No wondercard data found in loaded slot!"); return;
                }
                if (wc6.Item == 726 && wc6.IsItem)
                {
                    Util.Alert("Eon Ticket Wonder Cards will not function properly", "Inject to the save file instead."); return;
                }
                // Prep data
                byte[] wcdata = wc6.Data;
                // Ensure size
                Array.Resize(ref wcdata, WC6.Size);
                // Setup QR
                const string server = "http://lunarcookies.github.io/wc.html#";
                Image        qr     = Util.getQRImage(wcdata, server);
                if (qr == null)
                {
                    return;
                }

                string desc = wc6.Description;

                new QR(qr, PB_Preview.Image, desc, "", "", "PKHeX Wonder Card @ ProjectPokemon.org").ShowDialog();
            }
        }
Beispiel #8
0
        private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e)
        {
            if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift ||
                ModifierKeys == (Keys.Control | Keys.Alt))
            {
                switch (ModifierKeys)
                {
                case Keys.Control: clickView(sender, e); break;

                case Keys.Shift: clickSet(sender, e); break;

                case Keys.Alt: clickDelete(sender, e); break;
                }
                return;
            }
            PictureBox pb = (PictureBox)(sender);

            if (pb.Image == null)
            {
                return;
            }

            if (e.Button != MouseButtons.Left || e.Clicks != 1)
            {
                return;
            }

            int index = Array.FindIndex(pba, p => p.Name == (sender as PictureBox).Name);

            wc_slot = index;
            // Create Temp File to Drag
            Cursor.Current = Cursors.Hand;

            // Prepare Data
            byte[] dragdata = sav.Skip(Main.SAV.WondercardData + WC6.Size * index).Take(WC6.Size).ToArray();
            WC6    card     = new WC6(dragdata);
            string filename = Util.CleanFileName(card.CardID.ToString("0000") + " - " + card.CardTitle + ".wc6");

            // Make File
            string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename));

            try
            {
                File.WriteAllBytes(newfile, dragdata);
                DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
            }
            catch (ArgumentException x)
            { Util.Error("Drag & Drop Error:", x.ToString()); }
            File.Delete(newfile);
            wc_slot = -1;
        }
        private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e)
        {
            if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift ||
                ModifierKeys == (Keys.Control | Keys.Alt))
            {
                switch (ModifierKeys)
                {
                case Keys.Control: clickView(sender, e); break;

                case Keys.Shift: clickSet(sender, e); break;

                case Keys.Alt: clickDelete(sender, e); break;
                }
                return;
            }
            PictureBox pb = (PictureBox)sender;

            if (pb.Image == null)
            {
                return;
            }

            if (e.Button != MouseButtons.Left || e.Clicks != 1)
            {
                return;
            }

            int index = Array.IndexOf(pba, sender);

            wc_slot = index;
            // Create Temp File to Drag
            Cursor.Current = Cursors.Hand;

            // Prepare Data
            WC6    card     = SAV.getWC6(index);
            string filename = Util.CleanFileName($"{card.CardID.ToString("0000")} - {card.CardTitle}.wc6");

            // Make File
            string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename));

            try
            {
                File.WriteAllBytes(newfile, card.Data);
                DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
            }
            catch (ArgumentException x)
            { Util.Error("Drag & Drop Error:", x.ToString()); }
            File.Delete(newfile);
            wc_slot = -1;
        }
        private bool checkSpecialWonderCard(WC6 wc)
        {
            if (wc6.CardID == 2048 && wc.Item == 726) // Eon Ticket (OR/AS)
            {
                if (!Main.SAV.ORAS || Main.SAV.EonTicket < 0)
                {
                    goto reject;
                }
                BitConverter.GetBytes(WC6.EonTicketConst).CopyTo(SAV.Data, Main.SAV.EonTicket);
            }

            return(true);

            reject : Util.Alert("Unable to insert the Wonder Card.", "Does this Wonder Card really belong to this game?");
            return(false);
        }
Beispiel #11
0
        // String Creation
        private string getWCDescriptionString(byte[] data)
        {
            // Load up the data according to the wiki!
            int cardID = BitConverter.ToUInt16(data, 0);

            if (cardID == 0)
            {
                return("Empty Slot. No data!");
            }

            string cardname = Util.TrimFromZero(Encoding.Unicode.GetString(data, 0x2, 0x48));
            int    cardtype = data[0x51];
            string s        = "";

            s += "Card #: " + cardID.ToString("0000") + " - " + cardname + Environment.NewLine;

            if (cardtype == 1) // Item
            {
                int item = BitConverter.ToUInt16(data, 0x68);
                int qty  = BitConverter.ToUInt16(data, 0x70);

                s += "Item: " + Main.itemlist[item] + Environment.NewLine + "Quantity: " + qty;
            }
            else if (cardtype == 0) // PKM
            {
                WC6 card = new WC6(data);
                s += String.Format(
                    "{1} @ {2} --- {7} - {8}/{9}{0}" +
                    "{3} / {4} / {5} / {6}{0}",
                    Environment.NewLine,
                    Main.specieslist[card.Species],
                    Main.itemlist[card.HeldItem],
                    Main.movelist[card.Move1],
                    Main.movelist[card.Move2],
                    Main.movelist[card.Move3],
                    Main.movelist[card.Move4],
                    card.OT, card.TID.ToString("00000"), card.SID.ToString("00000"));
            }
            else
            {
                s += "Unknown Wonder Card Type!";
            }

            return(s);
        }
        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;
            }

            // Check for In-Dropped files (PKX,SAV,ETC)

            if (wc_slot == -1)
            {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                if (files.Length < 1 || new FileInfo(files[0]).Length != WC6.Size)
                {
                    return;
                }

                WC6 wc = new WC6(File.ReadAllBytes(files[0]));
                SAV.setWC6(wc, index);
                setCardID(wc.CardID);
                wc6 = wc;
                loadwcdata();
            }
            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);
                }
                WC6 s1 = SAV.getWC6(index);
                WC6 s2 = SAV.getWC6(wc_slot);
                SAV.setWC6(s1, wc_slot);
                SAV.setWC6(s2, index);
            }
            setBackground(index, Properties.Resources.slotView);
            populateWClist();
        }
        private void loadwcdata()
        {
            if (wc6 == null)
                return;
            try
            {
                if (wc6.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?"))
                    wc6.GiftUsed = false;

                RTB.Text = wc6.Description;
                PB_Preview.Image = wc6.Preview;
            }
            catch (Exception e)
            {
                Util.Error("Loading of data failed... is this really a Wonder Card?", e.ToString());
                wc6 = new WC6();
                RTB.Clear();
            }
        }
        // Wonder Card IO (.wc6<->window)
        private void B_Import_Click(object sender, EventArgs e)
        {
            OpenFileDialog importwc6 = new OpenFileDialog {
                Filter = "Wonder Card|*.wc6;*.wc6full"
            };

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

            string path = importwc6.FileName;
            long   len  = new FileInfo(path).Length;

            if (len != WC6.Size && len != WC6.SizeFull)
            {
                Util.Error("File is not a Wonder Card:", path);
                return;
            }
            wc6 = new WC6(File.ReadAllBytes(path));
            loadwcdata();
        }
Beispiel #15
0
        private Image getWCPreviewImage(byte[] data)
        {
            Image img;
            WC6   wc = new WC6(data);

            if (wc.IsPokémon)
            {
                img = PKX.getSprite(wc.Species, wc.Form, wc.Gender, wc.HeldItem, wc.IsEgg, wc.PIDType == 2);
            }
            else if (wc.IsItem)
            {
                img = (Image)(Properties.Resources.ResourceManager.GetObject("item_" + BitConverter.ToUInt16(data, 0x68)) ?? Properties.Resources.unknown);
            }
            else
            {
                img = Properties.Resources.unknown;
            }

            if (wc.GiftUsed)
            {
                img = Util.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3);
            }
            return(img);
        }
Beispiel #16
0
        // String Creation
        private string getWCDescriptionString(byte[] data)
        {
            WC6 wc = new WC6(data);
            if (wc.CardID == 0)
                return "Empty Slot. No data!";

            string s = $"Card #: {wc.CardID.ToString("0000")} - {wc.CardTitle.Trim()}" + Environment.NewLine;

            switch (wc.CardType)
            {
                case 1:
                    s += "Item: " + Main.itemlist[wc.Item] + Environment.NewLine + "Quantity: " + wc.Quantity;
                    return s;
                case 0:
                    s +=
                        $"{Main.specieslist[wc.Species]} @ {Main.itemlist[wc.HeldItem]} --- {wc.OT} - {wc.TID.ToString("00000")}/{wc.SID.ToString("00000")}" + Environment.NewLine +
                        $"{Main.movelist[wc.Move1]} / {Main.movelist[wc.Move2]} / {Main.movelist[wc.Move3]} / {Main.movelist[wc.Move4]}" + Environment.NewLine;
                    return s;
                default:
                    s += "Unknown Wonder Card Type!";
                    return s;
            }
        }
        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;

            // Check for In-Dropped files (PKX,SAV,ETC)

            if (wc_slot == -1)
            {
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

                if (files.Length < 1 || new FileInfo(files[0]).Length != WC6.Size)
                    return;
                
                WC6 wc = new WC6(File.ReadAllBytes(files[0]));
                SAV.setWC6(wc, index);
                setCardID(wc.CardID);
                wc6 = wc;
                loadwcdata();
            }
            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);
                WC6 s1 = SAV.getWC6(index);
                WC6 s2 = SAV.getWC6(wc_slot);
                SAV.setWC6(s1, wc_slot);
                SAV.setWC6(s2, index);
            }
            setBackground(index, Properties.Resources.slotView);
            populateWClist();
        }
        private void L_QR_Click(object sender, EventArgs e)
        {
            if (ModifierKeys == Keys.Alt)
            {
                byte[] data = Util.getQRData();
                if (data == null) return;
                if (data.Length != WC6.Size) { Util.Alert("Decoded data not 0x108 bytes.",
                    $"QR Data Size: 0x{data.Length.ToString("X")}"); }
                else try
                    {
                        wc6 = new WC6(data);
                        loadwcdata();
                    }
                    catch { Util.Alert("Error loading wondercard data."); }
            }
            else
            {
                if (wc6.Data.SequenceEqual(new byte[wc6.Data.Length]))
                { Util.Alert("No wondercard data found in loaded slot!"); return; }
                if (wc6.Item == 726 && wc6.IsItem)
                { Util.Alert("Eon Ticket Wonder Cards will not function properly", "Inject to the save file instead."); return; }
                // Prep data
                byte[] wcdata = wc6.Data;
                // Ensure size
                Array.Resize(ref wcdata, WC6.Size);
                // Setup QR
                const string server = "http://lunarcookies.github.io/wc.html#";
                Image qr = Util.getQRImage(wcdata, server);
                if (qr == null) return;

                string desc = wc6.Description;

                new QR(qr, PB_Preview.Image, desc, "", "", "PKHeX Wonder Card @ ProjectPokemon.org").ShowDialog();
            }
        }
Beispiel #19
0
        private LegalityCheck verifyRibbons()
        {
            if (!Encounter.Valid)
            {
                return(new LegalityCheck(Severity.Valid, "Skipped Ribbon check due to other check being invalid."));
            }

            List <string> missingRibbons = new List <string>();
            List <string> invalidRibbons = new List <string>();

            // Check Event Ribbons
            bool[] EventRib =
            {
                pk6.RIB2_6, pk6.RIB2_7, pk6.RIB3_0, pk6.RIB3_1, pk6.RIB3_2,
                pk6.RIB3_3, pk6.RIB3_4, pk6.RIB3_5, pk6.RIB3_6, pk6.RIB3_7,
                pk6.RIB4_0, pk6.RIB4_1, pk6.RIB4_2, pk6.RIB4_3, pk6.RIB4_4
            };
            WC6 MatchedWC6 = EncounterMatch as WC6;

            if (MatchedWC6 != null) // Wonder Card
            {
                bool[] wc6rib =
                {
                    MatchedWC6.RIB0_3, MatchedWC6.RIB0_4, MatchedWC6.RIB0_5, MatchedWC6.RIB0_6, MatchedWC6.RIB1_5,
                    MatchedWC6.RIB1_6, MatchedWC6.RIB0_7, MatchedWC6.RIB1_1, MatchedWC6.RIB1_2, MatchedWC6.RIB1_3,
                    MatchedWC6.RIB1_4, MatchedWC6.RIB0_0, MatchedWC6.RIB0_1, MatchedWC6.RIB0_2, MatchedWC6.RIB1_0
                };
                for (int i = 0; i < EventRib.Length; i++)
                {
                    if (EventRib[i] ^ wc6rib[i]) // Mismatch
                    {
                        (wc6rib[i] ? missingRibbons : invalidRibbons).Add(EventRibName[i]);
                    }
                }
            }
            else if (EncounterType == typeof(EncounterLink))
            {
                // No Event Ribbons except Classic (unless otherwise specified, ie not for Demo)
                for (int i = 0; i < EventRib.Length; i++)
                {
                    if (i != 4 && EventRib[i])
                    {
                        invalidRibbons.Add(EventRibName[i]);
                    }
                }

                if (EventRib[4] ^ ((EncounterLink)EncounterMatch).Classic)
                {
                    (EventRib[4] ? invalidRibbons : missingRibbons).Add(EventRibName[4]);
                }
            }
            else // No ribbons
            {
                for (int i = 0; i < EventRib.Length; i++)
                {
                    if (EventRib[i])
                    {
                        invalidRibbons.Add(EventRibName[i]);
                    }
                }
            }

            // Unobtainable ribbons for Gen6 Origin
            if (pk6.RIB0_1)
            {
                invalidRibbons.Add("GBA Champion"); // RSE HoF
            }
            if (pk6.RIB0_2)
            {
                invalidRibbons.Add("Sinnoh Champ"); // DPPt HoF
            }
            if (pk6.RIB2_2)
            {
                invalidRibbons.Add("Artist"); // RSE Master Rank Portrait
            }
            if (pk6.RIB2_4)
            {
                invalidRibbons.Add("Record"); // Unobtainable
            }
            if (pk6.RIB2_5)
            {
                invalidRibbons.Add("Legend"); // HGSS Defeat Red @ Mt.Silver
            }
            if (pk6.Memory_ContestCount > 0)
            {
                invalidRibbons.Add("Contest Memory"); // Gen3/4 Contest
            }
            if (pk6.Memory_BattleCount > 0)
            {
                invalidRibbons.Add("Battle Memory"); // Gen3/4 Battle
            }
            if (missingRibbons.Count + invalidRibbons.Count == 0)
            {
                return(new LegalityCheck(Severity.Valid, "All ribbons accounted for."));
            }

            string[] result = new string[2];
            if (missingRibbons.Count > 0)
            {
                result[0] = "Missing Ribbons: " + string.Join(", ", missingRibbons);
            }
            if (invalidRibbons.Count > 0)
            {
                result[1] = "Invalid Ribbons: " + string.Join(", ", invalidRibbons);
            }
            return(new LegalityCheck(Severity.Invalid, string.Join(Environment.NewLine, result.Where(s => !string.IsNullOrEmpty(s)))));
        }
Beispiel #20
0
        private void openFile(byte[] input, string path, string ext)
        {
            #region Powersaves Read-Only Conversion
            if (input.Length == 0x10009C) // Resize to 1MB
            {
                Array.Copy(input, 0x9C, input, 0, 0x100000);
                Array.Resize(ref input, 0x100000);
            }
            #endregion
            #region Saves
            if (SAV6.SizeValid(input.Length) && BitConverter.ToUInt32(input, input.Length - 0x1F0) == SAV6.BEEF)
                openMAIN(input, path);
            // Verify the Data Input Size is Proper
            else if (input.Length == 0x100000)
            {
                if (openXOR(input, path)) // Check if we can load the save via xorpad
                    return; // only if a save is loaded we abort
                if (BitConverter.ToUInt64(input, 0x10) != 0) // encrypted save
                { Util.Error("PKHeX only edits decrypted save files." + Environment.NewLine + "This save file is not decrypted.", path); return; }
                
                DialogResult sdr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000", "Press No for the one at 0x82000");
                if (sdr == DialogResult.Cancel)
                    return;
                int savshift = sdr == DialogResult.Yes ? 0 : 0x7F000;
                byte[] psdata = input.Skip(0x5400 + savshift).Take(SAV6.SIZE_ORAS).ToArray();
                if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != SAV6.BEEF)
                    Array.Resize(ref psdata, SAV6.SIZE_XY);
                if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != SAV6.BEEF)
                { Util.Error("The data file is not a valid save file", path); return; }

                openMAIN(psdata, path);
            }
            #endregion
            #region PK6/EK6
            else if ((input.Length == PK6.SIZE_PARTY || input.Length == PK6.SIZE_STORED) && ext != ".pgt")
            {
                // Check if Input is PKX
                if (new[] {".pk6", ".ek6", ".pkx", ".ekx", ""}.Contains(ext))
                {
                    // Check if Encrypted before Loading
                    populateFields(new PK6(BitConverter.ToUInt16(input, 0xC8) == 0 && BitConverter.ToUInt16(input, 0x58) == 0 ? input : PKX.decryptArray(input)));
                }
                else
                    Util.Error("Unable to recognize file." + Environment.NewLine + "Only valid .pk* .ek* .bin supported.",
                        $"File Loaded:{Environment.NewLine}{path}");
            }
            #endregion
            #region PK3/PK4/PK5 Conversion
            else if (new[] { PK3.SIZE_PARTY, PK3.SIZE_STORED, PK4.SIZE_PARTY, PK4.SIZE_STORED, PK5.SIZE_PARTY }.Contains(input.Length))
            {
                if (!PKX.verifychk(input)) Util.Error("Invalid File (Checksum Error)");
                try // to convert g5pkm
                {
                    populateFields(Converter.ConvertPKMtoPK6(input));
                }
                catch
                {
                    populateFields(new PK6());
                    Util.Error("Attempted to load previous generation PKM.", "Conversion failed.");
                }
            }
            #endregion
            #region Box Data
            else if ((input.Length == PK6.SIZE_STORED * 30 || input.Length == PK6.SIZE_STORED * 30 * 31) && BitConverter.ToUInt16(input, 4) == 0 && BitConverter.ToUInt32(input, 8) > 0)
            {
                int baseOffset = SAV.Box + PK6.SIZE_STORED * 30 * (input.Length == PK6.SIZE_STORED * 30 ? CB_BoxSelect.SelectedIndex : 0);
                for (int i = 0; i < input.Length / PK6.SIZE_STORED; i++)
                {
                    byte[] data = input.Skip(PK6.SIZE_STORED * i).Take(PK6.SIZE_STORED).ToArray();
                    SAV.setEK6Stored(data, baseOffset + i * PK6.SIZE_STORED);
                }
                setPKXBoxes();
                Util.Alert("Box Binary loaded.");
            }
            #endregion
            #region Battle Video
            else if (input.Length == 0x2E60 && BitConverter.ToUInt64(input, 0xE18) != 0 && BitConverter.ToUInt16(input, 0xE12) == 0)
            {
                if (Util.Prompt(MessageBoxButtons.YesNo, "Load Batte Video Pokémon data to " + CB_BoxSelect.Text + "?", "The first 24 slots will be overwritten.") != DialogResult.Yes)
                    return;

                DialogResult noSet = Util.Prompt(MessageBoxButtons.YesNoCancel, "Loading overrides:",
                    "Yes - Modify .pk6 when set to SAV" + Environment.NewLine +
                    "No - Don't modify .pk6" + Environment.NewLine +
                    "Cancel - Use current settings (" + (Menu_ModifyPK6.Checked ? "Yes" : "No") + ")");
                bool? noSetb = noSet == DialogResult.Yes ? true : (noSet == DialogResult.No ? (bool?)false : null);

                for (int i = 0; i < 24; i++)
                {
                    byte[] data = input.Skip(0xE18 + PK6.SIZE_PARTY * i + i / 6 * 8).Take(PK6.SIZE_STORED).ToArray();
                    int offset = SAV.Box + i*PK6.SIZE_STORED + CB_BoxSelect.SelectedIndex*30*PK6.SIZE_STORED;
                    SAV.setEK6Stored(data, offset, noSetb);
                }
                setPKXBoxes();
            }
            #endregion
            #region Wondercard
            else if ((input.Length == WC6.Size && ext == ".wc6") || (input.Length == WC6.SizeFull && ext == ".wc6full"))
            {
                if (input.Length == WC6.SizeFull) // Take bytes at end = WC6 size.
                    input = input.Skip(WC6.SizeFull - WC6.Size).ToArray();
                if (ModifierKeys == Keys.Control && SAV.PokeDex > -1)
                    new SAV_Wondercard(input).ShowDialog();
                else
                {
                    PK6 pk = new WC6(input).convertToPK6(SAV);
                    if (pk == null || pk.Species == 0 || pk.Species > 721)
                    {
                        Util.Error("Failed to convert Wondercard.",
                            pk == null ? "Not a Pokémon Wondercard." : "Invalid species.");
                        return;
                    }
                    populateFields(pk);
                }
            }
            else if (input.Length == PGF.Size && ext == ".pgf")
            {
                PK5 pk = new PGF(input).convertToPK5(SAV);
                if (pk == null || pk.Species == 0 || pk.Species > 721)
                {
                    Util.Error("Failed to convert PGF.",
                        pk == null ? "Not a Pokémon PGF." : "Invalid species.");
                    return;
                }
                populateFields(Converter.ConvertPKMtoPK6(pk.Data));
            }
            else if (input.Length == PGT.Size && ext == ".pgt")
            {
                PGT pgt = new PGT(input);
                PK4 pk = pgt.convertToPK4(SAV);
                if (pk == null || pk.Species == 0 || pk.Species > 721)
                {
                    Util.Error("Failed to convert PGT.",
                        pk == null ? "Not a Pokémon PGT." : "Invalid species.");
                    return;
                }
                populateFields(Converter.ConvertPKMtoPK6(pk.Data));
            }
            else if (input.Length == PCD.Size && ext == ".pcd")
            {
                PCD pcd = new PCD(input);
                PGT pgt = pcd.Gift;
                PK4 pk = pgt.convertToPK4(SAV);
                if (pk == null || pk.Species == 0 || pk.Species > 721)
                {
                    Util.Error("Failed to convert PCD.",
                        pk == null ? "Not a Pokémon PCD." : "Invalid species.");
                    return;
                }
                populateFields(Converter.ConvertPKMtoPK6(pk.Data));
            }
            #endregion
            else
                Util.Error("Attempted to load an unsupported file type/size.",
                    $"File Loaded:{Environment.NewLine}{path}",
                    $"File Size:{Environment.NewLine}{input.Length} bytes (0x{input.Length.ToString("X4")})");
        }
        // Wonder Card IO (.wc6<->window)
        private void B_Import_Click(object sender, EventArgs e)
        {
            OpenFileDialog importwc6 = new OpenFileDialog {Filter = "Wonder Card|*.wc6;*.wc6full"};
            if (importwc6.ShowDialog() != DialogResult.OK) return;

            string path = importwc6.FileName;
            long len = new FileInfo(path).Length;
            if (len != WC6.Size && len != WC6.SizeFull)
            {
                Util.Error("File is not a Wonder Card:", path);
                return;
            }
            wc6 = new WC6(File.ReadAllBytes(path));
            loadwcdata();
        }
Beispiel #22
0
        private LegalityCheck verifyHandlerMemories()
        {
            if (!Encounter.Valid)
            {
                return(new LegalityCheck(Severity.Valid, "Skipped Memory check due to other check being invalid."));
            }

            WC6 MatchedWC6 = EncounterMatch as WC6;

            if (MatchedWC6?.OT.Length > 0) // Has Event OT -- null propagation yields false if MatchedWC6=null
            {
                if (pk6.OT_Friendship != PKX.getBaseFriendship(pk6.Species))
                {
                    return(new LegalityCheck(Severity.Invalid, "Event OT Friendship does not match base friendship."));
                }
                if (pk6.OT_Affection != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Event OT Affection should be zero."));
                }
                if (pk6.CurrentHandler != 1)
                {
                    return(new LegalityCheck(Severity.Invalid, "Current handler should not be Event OT."));
                }
            }
            if (!pk6.WasEvent && (pk6.HT_Name.Length == 0 || pk6.Geo1_Country == 0)) // Is not Traded
            {
                if (pk6.HT_Name.Length != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "GeoLocation -- HT Name present but has no previous Country."));
                }
                if (pk6.Geo1_Country != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "GeoLocation -- Previous country of residence but no Handling Trainer."));
                }
                if (pk6.HT_Memory != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- Handling Trainer memory present but no Handling Trainer."));
                }
                if (pk6.CurrentHandler != 0) // Badly edited; PKHeX doesn't trip this.
                {
                    return(new LegalityCheck(Severity.Invalid, "Untraded -- Current handler should not be the Handling Trainer."));
                }
                if (pk6.HT_Friendship != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Untraded -- Handling Trainer Friendship should be zero."));
                }
                if (pk6.HT_Affection != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Untraded -- Handling Trainer Affection should be zero."));
                }
                if (pk6.XY && pk6.CNTs.Any(stat => stat > 0))
                {
                    return(new LegalityCheck(Severity.Invalid, "Untraded -- Contest stats on XY should be zero."));
                }

                // We know it is untraded (HT is empty), if it must be trade evolved flag it.
                if (Legal.getHasTradeEvolved(pk6))
                {
                    if (pk6.Species != 350) // Milotic
                    {
                        return(new LegalityCheck(Severity.Invalid, "Untraded -- requires a trade evolution."));
                    }
                    if (pk6.CNT_Beauty < 170) // Beauty Contest Stat Requirement
                    {
                        return(new LegalityCheck(Severity.Invalid, "Untraded -- Beauty is not high enough for Levelup Evolution."));
                    }
                }
            }
            else // Is Traded
            {
                if (pk6.HT_Memory == 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- missing Handling Trainer Memory."));
                }
            }

            // Memory Checks
            if (pk6.IsEgg)
            {
                if (pk6.HT_Memory != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- has Handling Trainer Memory."));
                }
                if (pk6.OT_Memory != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- has Original Trainer Memory."));
                }
            }
            else if (EncounterType != typeof(WC6))
            {
                if (pk6.OT_Memory == 0 ^ !pk6.Gen6)
                {
                    return(new LegalityCheck(Severity.Invalid, "Memory -- missing Original Trainer Memory."));
                }
                if (!pk6.Gen6 && pk6.OT_Affection != 0)
                {
                    return(new LegalityCheck(Severity.Invalid, "OT Affection should be zero."));
                }
            }
            // Unimplemented: Ingame Trade Memories

            return(new LegalityCheck(Severity.Valid, "History is valid."));
        }
Beispiel #23
0
        private LegalityCheck[] verifyMoves()
        {
            int[]           Moves = pk6.Moves;
            LegalityCheck[] res   = new LegalityCheck[4];
            for (int i = 0; i < 4; i++)
            {
                res[i] = new LegalityCheck();
            }
            if (!pk6.Gen6)
            {
                return(res);
            }

            var validMoves = Legal.getValidMoves(pk6).ToArray();

            if (pk6.Species == 235)
            {
                for (int i = 0; i < 4; i++)
                {
                    res[i] = Legal.InvalidSketch.Contains(Moves[i])
                        ? new LegalityCheck(Severity.Invalid, "Invalid Sketch move.")
                        : new LegalityCheck();
                }
            }
            else if (CardMatch?.Count > 1) // Multiple possible WC6 matched
            {
                int[] RelearnMoves = pk6.RelearnMoves;
                foreach (var wc in CardMatch)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (Moves[i] == Legal.Struggle)
                        {
                            res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move: Struggle.");
                        }
                        else if (validMoves.Contains(Moves[i]))
                        {
                            res[i] = new LegalityCheck(Severity.Valid, Moves[i] == 0 ? "Empty" : "Level-up.");
                        }
                        else if (RelearnMoves.Contains(Moves[i]))
                        {
                            res[i] = new LegalityCheck(Severity.Valid, Moves[i] == 0 ? "Empty" : "Relearn Move.")
                            {
                                Flag = true
                            }
                        }
                        ;
                        else if (wc.Moves.Contains(Moves[i]))
                        {
                            res[i] = new LegalityCheck(Severity.Valid, "Wonder Card Non-Relearn Move.");
                        }
                        else
                        {
                            res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move.");
                        }
                    }
                    if (res.All(r => r.Valid)) // Card matched
                    {
                        EncounterMatch = wc; RelearnBase = wc.RelearnMoves;
                    }
                }
            }
            else
            {
                int[] RelearnMoves = pk6.RelearnMoves;
                WC6   MatchedWC6   = EncounterMatch as WC6;
                int[] WC6Moves     = MatchedWC6?.Moves ?? new int[0];
                for (int i = 0; i < 4; i++)
                {
                    if (Moves[i] == Legal.Struggle)
                    {
                        res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move: Struggle.");
                    }
                    else if (validMoves.Contains(Moves[i]))
                    {
                        res[i] = new LegalityCheck(Severity.Valid, Moves[i] == 0 ? "Empty" : "Level-up.");
                    }
                    else if (RelearnMoves.Contains(Moves[i]))
                    {
                        res[i] = new LegalityCheck(Severity.Valid, Moves[i] == 0 ? "Empty" : "Relearn Move.")
                        {
                            Flag = true
                        }
                    }
                    ;
                    else if (WC6Moves.Contains(Moves[i]))
                    {
                        res[i] = new LegalityCheck(Severity.Valid, "Wonder Card Non-Relearn Move.");
                    }
                    else
                    {
                        res[i] = new LegalityCheck(Severity.Invalid, "Invalid Move.");
                    }
                }
            }
            if (Moves[0] == 0)
            {
                res[0] = new LegalityCheck(Severity.Invalid, "Invalid Move.");
            }


            if (pk6.Species == 647) // Keldeo
            {
                if (pk6.AltForm == 1 ^ pk6.Moves.Contains(548))
                {
                    res[0] = new LegalityCheck(Severity.Invalid, "Secret Sword / Resolute Keldeo Mismatch.");
                }
            }

            // Duplicate Moves Check
            for (int i = 0; i < 4; i++)
            {
                if (Moves.Count(m => m != 0 && m == Moves[i]) > 1)
                {
                    res[i] = new LegalityCheck(Severity.Invalid, "Duplicate Move.");
                }
            }

            return(res);
        }
Beispiel #24
0
        public void setWC6(WC6 wc6, int index)
        {
            if (WondercardData < 0)
                return;
            if (index < 0 || index > 24)
                return;

            wc6.Data.CopyTo(Data, WondercardData + index * WC6.Size);

            for (int i = 0; i < 24; i++)
                if (BitConverter.ToUInt16(Data, WondercardData + i * WC6.Size) == 0)
                    for (int j = i + 1; j < 24 - i; j++) // Shift everything down
                        Array.Copy(Data, WondercardData + j * WC6.Size, Data, WondercardData + (j - 1) * WC6.Size, WC6.Size);

            Edited = true;
        }
Beispiel #25
0
        // String Creation
        private string getWCDescriptionString(byte[] data)
        {
            // Load up the data according to the wiki!
            int cardID = BitConverter.ToUInt16(data, 0);
            if (cardID == 0) return "Empty Slot. No data!";

            string cardname = Util.TrimFromZero(Encoding.Unicode.GetString(data, 0x2, 0x48));
            int cardtype = data[0x51];
            string s = "";
            s += "Card #: " + cardID.ToString("0000") + " - " + cardname + Environment.NewLine;

            if (cardtype == 1) // Item
            {
                int item = BitConverter.ToUInt16(data, 0x68);
                int qty = BitConverter.ToUInt16(data, 0x70);

                s += "Item: " + Main.itemlist[item] + Environment.NewLine + "Quantity: " + qty;
            }
            else if (cardtype == 0) // PKM
            {
                WC6 card = new WC6(data);
                s += String.Format(
                    "{1} @ {2} --- {7} - {8}/{9}{0}" +
                    "{3} / {4} / {5} / {6}{0}",
                    Environment.NewLine,
                    Main.specieslist[card.Species],
                    Main.itemlist[card.HeldItem],
                    Main.movelist[card.Move1],
                    Main.movelist[card.Move2],
                    Main.movelist[card.Move3],
                    Main.movelist[card.Move4],
                    card.OT, card.TID.ToString("00000"), card.SID.ToString("00000"));
            }
            else
                s += "Unknown Wonder Card Type!";

            return s;
        }
Beispiel #26
0
 private Image getWCPreviewImage(byte[] data)
 {
     Image img;
     WC6 wc = new WC6(data);
     if (wc.IsPokémon)
         img = PKX.getSprite(wc.Species, wc.Form, wc.Gender, wc.HeldItem, wc.IsEgg, wc.PIDType == 2);
     else if (wc.IsItem)
         img = (Image)(Properties.Resources.ResourceManager.GetObject("item_" + BitConverter.ToUInt16(data, 0x68)) ?? Properties.Resources.unknown);
     else
         img = Properties.Resources.unknown;
             
     if (wc.GiftUsed)
         img = Util.LayerImage(new Bitmap(img.Width, img.Height), img, 0, 0, 0.3);
     return img;
 }
        // Wonder Card RW (window<->sav)
        private void clickView(object sender, EventArgs e)
        {
            sender = ((sender as ToolStripItem)?.Owner as ContextMenuStrip)?.SourceControl ?? sender as PictureBox;
            int index = Array.IndexOf(pba, sender);

            setBackground(index, Properties.Resources.slotView);
            wc6 = SAV.getWC6(index);
            loadwcdata();
        }
Beispiel #28
0
        private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e)
        {
            if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift ||
                ModifierKeys == (Keys.Control | Keys.Alt))
            {
                switch (ModifierKeys)
                {
                    case Keys.Control: clickView(sender, e); break;
                    case Keys.Shift: clickSet(sender, e); break;
                    case Keys.Alt: clickDelete(sender, e); break;
                }
                return;
            }
            PictureBox pb = (PictureBox)sender;
            if (pb.Image == null)
                return;

            if (e.Button != MouseButtons.Left || e.Clicks != 1) return;

            int index = Array.IndexOf(pba, sender);
            wc_slot = index;
            // Create Temp File to Drag
            Cursor.Current = Cursors.Hand;

            // Prepare Data
            byte[] dragdata = sav.Skip(Main.SAV.WondercardData + WC6.Size * index).Take(WC6.Size).ToArray();
            WC6 card = new WC6(dragdata);
            string filename = Util.CleanFileName($"{card.CardID.ToString("0000")} - {card.CardTitle}.wc6");

            // Make File
            string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename));
            try
            {
                File.WriteAllBytes(newfile, dragdata);
                DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
            }
            catch (ArgumentException x)
            { Util.Error("Drag & Drop Error:", x.ToString()); }
            File.Delete(newfile);
            wc_slot = -1;
        }
        private void tabMain_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            // Check for multiple wondercards
            int ctr = currentSlot;
            if (Directory.Exists(files[0]))
                files = Directory.GetFiles(files[0], "*", SearchOption.AllDirectories);
            if (files.Length == 1 && !Directory.Exists(files[0]))
            {
                string path = files[0]; // open first D&D
                long len = new FileInfo(path).Length;
                if (len != WC6.Size && len != WC6.SizeFull)
                {
                    Util.Error("File is not a Wonder Card:", path);
                    return;
                }
                byte[] newwc6 = File.ReadAllBytes(path);
                if (newwc6.Length == WC6.SizeFull)
                    newwc6 = newwc6.Skip(WC6.SizeFull - WC6.Size).ToArray();
                Array.Copy(newwc6, wc6.Data, newwc6.Length);
                loadwcdata();
                return;
            }

            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, $"Try to load {files.Length} Wonder Cards starting at Card {ctr + 1}?"))
                return;

            foreach (string file in files)
            {
                long len = new FileInfo(file).Length;
                if (len != WC6.Size && len != WC6.SizeFull)
                { Util.Error("File is not a Wonder Card:", file); continue; }

                // Load in WC
                byte[] newwc6 = File.ReadAllBytes(file);

                if (newwc6.Length == WC6.SizeFull)
                    newwc6 = newwc6.Skip(WC6.SizeFull - WC6.Size).ToArray();
                if (checkSpecialWonderCard(new WC6(newwc6)))
                {
                    WC6 wc = new WC6(newwc6);
                    SAV.setWC6(wc, ctr++);
                    setCardID(wc.CardID);
                }
                if (ctr >= 24)
                    break;
            }
            populateWClist();
        }
Beispiel #30
0
        private void openFile(byte[] input, string path, string ext)
        {
            #region Powersaves Read-Only Conversion
            if (input.Length == 0x10009C) // Resize to 1MB
            {
                Array.Copy(input, 0x9C, input, 0, 0x100000);
                Array.Resize(ref input, 0x100000);
            }
            #endregion

            #region Saves
            if ((input.Length == 0x76000) && BitConverter.ToUInt32(input, 0x75E10) == 0x42454546) // ORAS
                openMAIN(input, path);
            else if ((input.Length == 0x65600) && BitConverter.ToUInt32(input, 0x65410) == 0x42454546) // XY
                openMAIN(input, path);
            // Verify the Data Input Size is Proper
            else if (input.Length == 0x100000)
            {
                if (openXOR(input, path)) // Check if we can load the save via xorpad
                    return; // only if a save is loaded we abort
                if (BitConverter.ToUInt64(input, 0x10) != 0) // encrypted save
                { Util.Error("PKHeX only edits decrypted save files.", "This save file is not decrypted."); return; }

                DialogResult sdr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000", "Press No for the one at 0x82000");
                int savshift = 0;
                if (sdr == DialogResult.Yes)
                    savshift += 0x7F000;
                if (sdr == DialogResult.Cancel)
                    return;
                byte[] psdata = input.Skip(0x5400 + savshift).Take(0x76000).ToArray();
                if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != 0x42454546)
                    Array.Resize(ref psdata, 0x65600);
                if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != 0x42454546)
                    return;

                openMAIN(psdata, path);
            }
            #endregion
            #region PK6/EK6
            else if ((input.Length == PK6.SIZE_PARTY) || (input.Length == PK6.SIZE_STORED))
            {
                // Check if Input is PKX
                if ((ext == ".pk6") || (ext == ".ek6") || (ext == ".pkx") || (ext == ".ekx") || (ext == ".bin") || (ext == ""))
                {
                    // Check if Encrypted before Loading
                    populateFields((BitConverter.ToUInt16(input, 0xC8) == 0 && BitConverter.ToUInt16(input, 0x58) == 0) ? input : PKX.decryptArray(input));
                }
                else
                    Util.Error("Unable to recognize file." + Environment.NewLine + "Only valid .pk* .ek* .bin supported.", String.Format("File Loaded:{0}{1}", Environment.NewLine, path));
            }
            #endregion
            #region PK3/PK4/PK5
            else if ((input.Length == 136) || (input.Length == 220) || (input.Length == 236) || (input.Length == 100) || (input.Length == 80)) // to convert g5pkm
            {
                if (!PKX.verifychk(input)) Util.Error("Invalid File (Checksum Error)");
                try // to convert g5pkm
                {
                    byte[] data = Converter.ConvertPKM(input);
                    Array.Resize(ref data, PK6.SIZE_STORED);
                    populateFields(data);
                }
                catch
                {
                    populateFields(new byte[PK6.SIZE_STORED]);
                    Util.Error("Attempted to load previous generation PKM.", "Conversion failed.");
                }
            }
            #endregion
            #region Trade Packets
            else if (input.Length == 363 && BitConverter.ToUInt16(input, 0x6B) == 0)
            {
                // EAD Packet of 363 length
                Array.Copy(input, 0x67, pk6.Data, 0, PK6.SIZE_STORED);
                Array.Resize(ref pk6.Data, PK6.SIZE_STORED);
                populateFields(pk6.Data);
            }
            else if (input.Length == 407 && BitConverter.ToUInt16(input, 0x98) == 0)
            {
                // EAD Packet of 407 length
                Array.Copy(input, 0x93, pk6.Data, 0, PK6.SIZE_STORED);
                Array.Resize(ref pk6.Data, PK6.SIZE_STORED);
                populateFields(pk6.Data);
            }
            #endregion
            #region Box Data
            else if ((input.Length == PK6.SIZE_STORED * 30 || input.Length == PK6.SIZE_STORED * 30 * 31) && BitConverter.ToUInt16(input, 4) == 0 && BitConverter.ToUInt32(input, 8) > 0)
            {
                int baseOffset = SAV.Box + PK6.SIZE_STORED * 30 * ((input.Length == PK6.SIZE_STORED * 30) ? CB_BoxSelect.SelectedIndex : 0);
                for (int i = 0; i < input.Length / PK6.SIZE_STORED; i++)
                {
                    byte[] data = input.Skip(PK6.SIZE_STORED * i).Take(PK6.SIZE_STORED).ToArray();
                    SAV.setEK6Stored(data, baseOffset + i * PK6.SIZE_STORED);
                }
                setPKXBoxes();
                Width = largeWidth;
                Util.Alert("Box Binary loaded.");
            }
            #endregion
            #region injectiondebug
            else if (input.Length == 0x10000)
            {
                int offset = -1; // Seek to find data start
                for (int i = 0; i < 0x800; i++)
                {
                    byte[] data = PKX.decryptArray(input.Skip(i).Take(PK6.SIZE_STORED).ToArray());
                    if (PKX.getCHK(data) != BitConverter.ToUInt16(data, 6)) continue;
                    offset = i; break;
                }
                if (offset < 0) { Util.Alert(path, "Unable to read the input file; not an expected injectiondebug.bin."); return; }
                CB_BoxSelect.SelectedIndex = 0;
                for (int i = 0; i < input.Length / (9*30); i++)
                {
                    byte[] data = input.Skip(offset + PK6.SIZE_STORED * i).Take(PK6.SIZE_STORED).ToArray();
                    SAV.setEK6Stored(data, SAV.Box + i * PK6.SIZE_STORED);
                }
                setPKXBoxes();
                Width = largeWidth;
                Util.Alert("Injection Binary loaded.");
            }
            #endregion
            #region RAMSAV
            else if (( /*XY*/ input.Length == 0x70000 || /*ORAS*/ input.Length == 0x80000) && Path.GetFileName(path).Contains("ram"))
            {
                if (input.Length == 0x80000)
                    // Scan for FEEB in XY location, 3DS only overwrites data if file already exists.
                    for (int i = 0x60000; i < 0x64000; i+=4)
                        if (BitConverter.ToUInt32(input, i) == 0x42454546) { Array.Resize(ref input, 0x70000); break; }

                ramsav = (byte[])input.Clone();
                try { openMAIN(ram2sav.getMAIN(input), path, true); }
                catch { ramsav = null; }
            }
            #endregion
            #region Battle Video
            else if (input.Length == 0x2E60 && BitConverter.ToUInt64(input, 0xE18) != 0 && BitConverter.ToUInt16(input, 0xE12) == 0)
            {
                if (Util.Prompt(MessageBoxButtons.YesNo, "Load Batte Video Pokémon data to " + CB_BoxSelect.Text + "?", "The first 24 slots will be overwritten.") != DialogResult.Yes) return;
                for (int i = 0; i < 24; i++)
                {
                    byte[] data = input.Skip(0xE18 + PK6.SIZE_PARTY * i + (i / 6) * 8).Take(PK6.SIZE_STORED).ToArray();
                    SAV.setEK6Stored(data, SAV.Box + i*PK6.SIZE_STORED + CB_BoxSelect.SelectedIndex*30*PK6.SIZE_STORED);
                }
                setPKXBoxes();
                Width = largeWidth;
            }
            #endregion
            #region Wondercard
            else if (input.Length == 0x108 && ext == ".wc6")
                if (ModifierKeys == Keys.Control)
                    new SAV_Wondercard(input).Show();
                else
                {
                    PK6 pk = new WC6(input).convertToPK6(SAV);
                    if (pk != null && pk.Species != 0)
                        populateFields(pk.Data);
                }
            #endregion
            else
                Util.Error("Attempted to load an unsupported file type/size.",
                    String.Format("File Loaded:{0}{1}", Environment.NewLine, path),
                    String.Format("File Size:{0}{1} bytes (0x{2})", Environment.NewLine, input.Length, input.Length.ToString("X4")));
        }
        private bool checkSpecialWonderCard(WC6 wc)
        {
            if (wc6.CardID == 2048 && wc.Item == 726) // Eon Ticket (OR/AS)
            {
                if (!Main.SAV.ORAS || Main.SAV.EonTicket < 0)
                    goto reject;
                BitConverter.GetBytes(WC6.EonTicketConst).CopyTo(SAV.Data, Main.SAV.EonTicket);
            }

            return true;
            reject: Util.Alert("Unable to insert the Wonder Card.", "Does this Wonder Card really belong to this game?");
            return false;
        }
Beispiel #32
0
        private LegalityCheck verifyEncounter()
        {
            if (!pk6.Gen6)
            {
                return new LegalityCheck {
                           Judgement = Severity.NotImplemented
                }
            }
            ;

            if (pk6.WasLink)
            {
                // Should NOT be Fateful, and should be in Database
                EncounterLink enc = EncounterMatch as EncounterLink;

                if (enc == null)
                {
                    return(new LegalityCheck(Severity.Invalid, "Not a valid Link gift -- unable to find matching gift."));
                }

                if (pk6.XY && !enc.XY)
                {
                    return(new LegalityCheck(Severity.Invalid, "Not a valid Link gift -- can't obtain in XY."));
                }
                if (pk6.AO && !enc.ORAS)
                {
                    return(new LegalityCheck(Severity.Invalid, "Not a valid Link gift -- can't obtain in ORAS."));
                }

                if (enc.Shiny != null && (bool)enc.Shiny ^ pk6.IsShiny)
                {
                    return(new LegalityCheck(Severity.Invalid, "Shiny Link gift mismatch."));
                }

                return(pk6.FatefulEncounter
                    ? new LegalityCheck(Severity.Invalid, "Not a valid Link gift -- should not be Fateful Encounter.")
                    : new LegalityCheck(Severity.Valid, "Valid Link gift."));
            }
            if (pk6.WasEvent || pk6.WasEventEgg)
            {
                WC6 MatchedWC6 = EncounterMatch as WC6;
                return(MatchedWC6 != null // Matched in RelearnMoves check.
                    ? new LegalityCheck(Severity.Valid, $"Matches #{MatchedWC6.CardID.ToString("0000")} ({MatchedWC6.CardTitle})")
                    : new LegalityCheck(Severity.Invalid, "Not a valid Wonder Card gift."));
            }

            EncounterMatch = null; // Reset object
            if (pk6.WasEgg)
            {
                // Check Hatch Locations
                if (pk6.Met_Level != 1)
                {
                    return(new LegalityCheck(Severity.Invalid, "Invalid met level, expected 1."));
                }
                // Check species
                if (Legal.NoHatchFromEgg.Contains(pk6.Species))
                {
                    return(new LegalityCheck(Severity.Invalid, "Species cannot be hatched from an egg."));
                }
                if (pk6.IsEgg)
                {
                    if (pk6.Egg_Location == 30002)
                    {
                        return(new LegalityCheck(Severity.Invalid, "Egg location shouldn't be 'traded' for an un-hatched egg."));
                    }

                    if (pk6.Met_Location == 30002)
                    {
                        return(new LegalityCheck(Severity.Valid, "Valid traded un-hatched egg."));
                    }
                    return(pk6.Met_Location == 0
                        ? new LegalityCheck(Severity.Valid, "Valid un-hatched egg.")
                        : new LegalityCheck(Severity.Invalid, "Invalid location for un-hatched egg (expected no met location)."));
                }
                if (pk6.XY)
                {
                    return(Legal.ValidMet_XY.Contains(pk6.Met_Location)
                        ? new LegalityCheck(Severity.Valid, "Valid X/Y hatched egg.")
                        : new LegalityCheck(Severity.Invalid, "Invalid X/Y location for hatched egg."));
                }
                if (pk6.AO)
                {
                    return(Legal.ValidMet_AO.Contains(pk6.Met_Location)
                        ? new LegalityCheck(Severity.Valid, "Valid OR/AS hatched egg.")
                        : new LegalityCheck(Severity.Invalid, "Invalid OR/AS location for hatched egg."));
                }
                return(new LegalityCheck(Severity.Invalid, "Invalid location for hatched egg."));
            }

            EncounterMatch = Legal.getValidStaticEncounter(pk6);
            if (EncounterMatch != null)
            {
                return(new LegalityCheck(Severity.Valid, "Valid gift/static encounter."));
            }

            if (Legal.getIsFossil(pk6))
            {
                return(pk6.AbilityNumber != 4
                    ? new LegalityCheck(Severity.Valid, "Valid revived fossil.")
                    : new LegalityCheck(Severity.Invalid, "Hidden ability on revived fossil."));
            }
            EncounterMatch = Legal.getValidFriendSafari(pk6);
            if (EncounterMatch != null)
            {
                if (pk6.Species == 670 || pk6.Species == 671) // Floette
                {
                    if (pk6.AltForm % 2 != 0)                 // 0/2/4
                    {
                        return(new LegalityCheck(Severity.Invalid, "Friend Safari: Not valid color."));
                    }
                    else if (pk6.Species == 710 || pk6.Species == 711) // Pumpkaboo
                    {
                        if (pk6.AltForm != 1)                          // Average
                        {
                            return(new LegalityCheck(Severity.Invalid, "Friend Safari: Not average sized."));
                        }
                        else if (pk6.Species == 586) // Sawsbuck
                        {
                            if (pk6.AltForm != 0)
                            {
                                return(new LegalityCheck(Severity.Invalid, "Friend Safari: Not Spring form."));
                            }
                        }
                    }
                }

                return(new LegalityCheck(Severity.Valid, "Valid friend safari encounter."));
            }

            EncounterMatch = Legal.getValidWildEncounters(pk6);
            if (EncounterMatch != null)
            {
                return(((EncounterSlot[])EncounterMatch).Any(slot => !slot.DexNav)
                    ? new LegalityCheck(Severity.Valid, "Valid encounter at location.")
                    : new LegalityCheck(Severity.Valid, "Valid DexNav encounter at location."));
            }
            EncounterMatch = Legal.getValidIngameTrade(pk6);
            if (EncounterMatch != null)
            {
                return(new LegalityCheck(Severity.Valid, "Valid ingame trade."));
            }
            return(new LegalityCheck(Severity.Invalid, "Not a valid encounter."));
        }
        private void tabMain_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            // Check for multiple wondercards
            int ctr = currentSlot;

            if (Directory.Exists(files[0]))
            {
                files = Directory.GetFiles(files[0], "*", SearchOption.AllDirectories);
            }
            if (files.Length == 1 && !Directory.Exists(files[0]))
            {
                string path = files[0]; // open first D&D
                long   len  = new FileInfo(path).Length;
                if (len != WC6.Size && len != WC6.SizeFull)
                {
                    Util.Error("File is not a Wonder Card:", path);
                    return;
                }
                byte[] newwc6 = File.ReadAllBytes(path);
                if (newwc6.Length == WC6.SizeFull)
                {
                    newwc6 = newwc6.Skip(WC6.SizeFull - WC6.Size).ToArray();
                }
                Array.Copy(newwc6, wc6.Data, newwc6.Length);
                loadwcdata();
                return;
            }

            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, $"Try to load {files.Length} Wonder Cards starting at Card {ctr + 1}?"))
            {
                return;
            }

            foreach (string file in files)
            {
                long len = new FileInfo(file).Length;
                if (len != WC6.Size && len != WC6.SizeFull)
                {
                    Util.Error("File is not a Wonder Card:", file); continue;
                }

                // Load in WC
                byte[] newwc6 = File.ReadAllBytes(file);

                if (newwc6.Length == WC6.SizeFull)
                {
                    newwc6 = newwc6.Skip(WC6.SizeFull - WC6.Size).ToArray();
                }
                if (checkSpecialWonderCard(new WC6(newwc6)))
                {
                    WC6 wc = new WC6(newwc6);
                    SAV.setWC6(wc, ctr++);
                    setCardID(wc.CardID);
                }
                if (ctr >= 24)
                {
                    break;
                }
            }
            populateWClist();
        }