Esempio n. 1
0
        private void clickSet(object sender, EventArgs e)
        {
            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 = Array.FindIndex(pba, p => p.Image == null);

            if (lastUnfilled < index)
            {
                index = lastUnfilled;
            }

            setBackground(index, Properties.Resources.slotSet);
            int offset = Main.SAV.WondercardData + index * WC6.Size;

            if (Main.SAV.ORAS)                                                 // ORAS Only
            {
                if (BitConverter.ToUInt16(wondercard_data, 0) == 0x800)        // Eon Ticket #
                {
                    if (BitConverter.ToUInt16(wondercard_data, 0x68) == 0x2D6) // Eon Ticket
                    {
                        BitConverter.GetBytes(EonTicketConst).CopyTo(sav, Main.SAV.EonTicket);
                    }
                    else
                    {
                        Util.Alert("Cannot set Eon Ticket to non OR/AS games."); return;
                    }
                }
            }

            Array.Copy(wondercard_data, 0, sav, offset, WC6.Size);
            populateWClist();
            setCardID(BitConverter.ToUInt16(wondercard_data, 0));
        }
Esempio n. 2
0
 private void B_Copy_Click(object sender, EventArgs e)
 {
     if (RTB_Code.Text.Length > 0)
     {
         Clipboard.SetText(RTB_Code.Text);
     }
     else
     {
         B_Diff.PerformClick();
         try
         {
             Clipboard.SetText(RTB_Code.Text);
             Util.Alert(
                 "Code generated and copied to clipboard!",
                 "Next time click [Create Diff] first.");
         }
         catch
         {
             Util.Alert(
                 "No code created!",
                 "Click [Create Diff], then make sure that data appears in the Text Box below. If no code appears, then you didn't save your changes.",
                 "Be sure to Set the Pokemon you edited back into a Box/Party slot!");
         }
     }
 }
Esempio n. 3
0
        private void B_FDelete_Click(object sender, EventArgs e)
        {
            if (LB_Favorite.SelectedIndex < 1)
            {
                Util.Alert("Cannot delete your Secret Base."); return;
            }
            int index = LB_Favorite.SelectedIndex - 1;

            int    favoff      = Main.SAV.SecretBase + 0x63A;
            string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, favoff + index * 0x3E0 + 0x218, 0x1A));

            if (string.IsNullOrEmpty(BaseTrainer))
            {
                BaseTrainer = "Empty";
            }

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

            const int max    = 29;
            const int size   = 0x3E0;
            int       offset = favoff + index * size;

            if (index != max)
            {
                Array.Copy(sav, offset + size, sav, offset, size * (max - index));
            }
            // Ensure Last Entry is Cleared
            Array.Copy(new byte[size], 0, sav, size * max, size);
            popFavorite();
        }
Esempio n. 4
0
        private void clickSet(object sender, EventArgs e)
        {
            if (!checkSpecialWonderCard(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.Type != mga.Gifts[index].Type)
            {
                Util.Alert("Can't set slot here.", $"{mg.Type} != {mga.Gifts[index].Type}");
                return;
            }
            setBackground(index, Mass_Editor.Properties.Resources.slotSet);
            mga.Gifts[index] = mg.Clone();
            setGiftBoxes();
            setCardID(mg.CardID);
        }
Esempio n. 5
0
        internal static Image getQRImage(byte[] data, string server)
        {
            string qrdata  = Convert.ToBase64String(data);
            string message = server + qrdata;
            string webURL  = "http://chart.apis.google.com/chart?chs=365x365&cht=qr&chl=" + HttpUtility.UrlEncode(message);

            try
            {
                HttpWebRequest  httpWebRequest = (HttpWebRequest)WebRequest.Create(webURL);
                HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
                Stream          stream         = httpWebReponse.GetResponseStream();
                if (stream != null)
                {
                    return(Image.FromStream(stream));
                }
            }
            catch
            {
                if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Unable to connect to the internet to receive QR code.", "Copy QR URL to Clipboard?"))
                {
                    return(null);
                }
                try { Clipboard.SetText(webURL); }
                catch { Util.Alert("Failed to set text to Clipboard"); }
            }
            return(null);
        }
Esempio n. 6
0
        private void B_FDelete_Click(object sender, EventArgs e)
        {
            if (LB_Favorite.SelectedIndex < 1)
            {
                Util.Alert("Cannot delete your Secret Base."); return;
            }
            int index = LB_Favorite.SelectedIndex - 1;

            const int favoff      = fav_offset + 0x5400 + 0x63A;
            string    BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + favoff + index * 0x3E0 + 0x218, 0x1A));

            if (BaseTrainer.Length < 1 || BaseTrainer[0] == '\0')
            {
                BaseTrainer = "Empty";
            }

            if (
                Util.Prompt(MessageBoxButtons.YesNo,
                            String.Format("Delete {1}'s base (Entry {0}) from your records?", index, BaseTrainer)) != DialogResult.Yes)
            {
                return;
            }
            const int max    = 29;
            const int size   = 0x3E0;
            int       offset = sv + favoff + index * size;

            if (index != max)
            {
                Array.Copy(sav, offset + size, sav, offset, size * (max - index));
            }
            // Ensure Last Entry is Cleared
            Array.Copy(new byte[size], 0, sav, size * max, size);
            popFavorite();
        }
Esempio n. 7
0
        private void tabMain_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            // Check for multiple wondercards
            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 > 0x1000)       // arbitrary
                {
                    Util.Alert("File is not a Mystery Gift.", path);
                    return;
                }
                MysteryGift g = MysteryGift.getMysteryGift(File.ReadAllBytes(path), Path.GetExtension(path));
                if (g == null)
                {
                    Util.Error("File is not a Mystery Gift:", path);
                    return;
                }
                viewGiftData(g);
                return;
            }
            setGiftBoxes();
        }
Esempio n. 8
0
        private void removeAllItems(object sender, EventArgs e)
        {
            // Get Current Pouch
            int pouch = CurrentPouch;

            if (pouch < 0)
            {
                return;
            }

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

            for (int i = 0; i < dgv.RowCount; i++)
            {
                int c = 0;
                dgv.Rows[i].Cells[c++].Value = itemlist[0];
                dgv.Rows[i].Cells[c++].Value = 0;
                if (HasFreeSpace)
                {
                    dgv.Rows[i].Cells[c++].Value = false;
                }
                if (HasNew)
                {
                    dgv.Rows[i].Cells[c].Value = false;
                }
            }
            Util.Alert("Items cleared.");
        }
Esempio n. 9
0
        private void getBags()
        {
            foreach (InventoryPouch pouch in Pouches)
            {
                DataGridView dgv = Controls.Find(DGVPrefix + pouch.Type, true).FirstOrDefault() as DataGridView;

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

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

                int purgedItems = outOfBounds.Length + incorrectPouch.Length;
                pouch.Items = pouch.Items.Concat(new byte[purgedItems].Select(i => new InventoryItem())).ToArray();

                getBag(dgv, pouch);
            }
        }
Esempio n. 10
0
        public SAV_Trainer7()
        {
            Loading = true;
            InitializeComponent();
            if (Main.unicode)
            {
                try { TB_OTName.Font = PKX.getPKXFont(11); }
                catch (Exception e) { Util.Alert("Font loading failed...", e.ToString()); }
            }

            Util.TranslateInterface(this, Main.curlanguage);
            B_MaxCash.Click += (sender, e) => MT_Money.Text = "9,999,999";

            CB_Gender.Items.Clear();
            CB_Gender.Items.AddRange(Main.gendersymbols.Take(2).ToArray()); // m/f depending on unicode selection

            getComboBoxes();
            getTextBoxes();

            CB_Stats.Items.Clear();
            for (int i = 0; i < 200; i++)
            {
                string name;
                if (!RecordList.TryGetValue(i, out name))
                {
                    name = i.ToString("D3");
                }

                CB_Stats.Items.Add(name);
            }
            CB_Stats.SelectedIndex = RecordList.First().Key;

            Loading = false;
        }
        private void Menu_Export_Click(object sender, EventArgs e)
        {
            if (Results == null || Results.Count == 0)
            {
                Util.Alert("No results to export."); return;
            }

            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Export to a folder?"))
            {
                return;
            }

            FolderBrowserDialog fbd = new FolderBrowserDialog();

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

            string path = fbd.SelectedPath;

            if (!Directory.Exists(path)) // just in case...
            {
                Directory.CreateDirectory(path);
            }

            foreach (var gift in Results)
            {
                File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(gift.FileName)), gift.Data);
            }
        }
Esempio n. 12
0
File: QR.cs Progetto: mikemow/PKHeX
        // QR Utility
        internal static byte[] getQRData()
        {
            // Fetch data from QR code...
            string address;

            try { address = Clipboard.GetText(); }
            catch { Util.Alert("No text (url) in clipboard."); return(null); }
            try { if (address.Length < 4 || address.Substring(0, 3) != "htt")
                  {
                      Util.Alert("Clipboard text is not a valid URL:", address); return(null);
                  }
            }
            catch { Util.Alert("Clipboard text is not a valid URL:", address); return(null); }
            string webURL = "http://api.qrserver.com/v1/read-qr-code/?fileurl=" + HttpUtility.UrlEncode(address);

            try
            {
                string data = Util.getStringFromURL(webURL);
                if (data.Contains("could not find"))
                {
                    Util.Alert("Reader could not find QR data in the image."); return(null);
                }
                if (data.Contains("filetype not supported"))
                {
                    Util.Alert("Input URL is not valid. Double check that it is an image (jpg/png).", address); return(null);
                }
                // Quickly convert the json response to a data string
                const string cap   = "\",\"error\":null}]}]";
                const string intro = "[{\"type\":\"qrcode\",\"symbol\":[{\"seq\":0,\"data\":\"";
                if (!data.StartsWith(intro))
                {
                    throw new Exception();
                }

                string pkstr = data.Substring(intro.Length);
                if (pkstr.Contains("nQR-Code:")) // Remove multiple QR codes in same image
                {
                    pkstr = pkstr.Substring(0, pkstr.IndexOf("nQR-Code:", StringComparison.Ordinal));
                }
                pkstr = pkstr.Substring(0, pkstr.IndexOf(cap, StringComparison.Ordinal)); // Trim outro
                try
                {
                    if (!pkstr.StartsWith("http")) // G7
                    {
                        string fstr = Regex.Unescape(pkstr);
                        byte[] raw  = Encoding.Unicode.GetBytes(fstr);
                        // Remove 00 interstitials and retrieve from offset 0x30, take PK7 Stored Size (always)
                        return(raw.ToList().Where((c, i) => i % 2 == 0).Skip(0x30).Take(0xE8).ToArray());
                    }
                    // All except G7
                    pkstr = pkstr.Substring(pkstr.IndexOf("#", StringComparison.Ordinal) + 1); // Trim URL
                    pkstr = pkstr.Replace("\\", "");                                           // Rectify response

                    return(Convert.FromBase64String(pkstr));
                }
                catch { Util.Alert("QR string to Data failed."); return(null); }
            }
            catch { Util.Alert("Unable to connect to the internet to decode QR code."); return(null); }
        }
Esempio n. 13
0
        // User Cheats
        private void B_GiveAll_Click(object sender, EventArgs e)
        {
            // Get Current Pouch
            int pouch = tabControl1.SelectedIndex;

            if (pouch < 0)
            {
                return;
            }

            ushort[] legalitems = Pouches[pouch].LegalItems;

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

            if (ModifierKeys == Keys.Alt)
            {
                for (int i = 0; i < legalitems.Length; i++)
                {
                    dgv.Rows[i].Cells[0].Value = itemlist[0];
                    dgv.Rows[i].Cells[1].Value = 0;
                }
                Util.Alert("Items cleared.");
                return;
            }
            int Count = ModifierKeys == Keys.Control ? 1 : Pouches[pouch].MaxCount;

            for (int i = 0; i < legalitems.Length; i++)
            {
                int    item = legalitems[i];
                string itemname;
                int    c = Count;

                // Override for HMs
                switch (SAV.Generation)
                {
                case 3: {
                    itemname = itemlist[item];
                    if (Legal.Pouch_HM_RS.Contains(legalitems[i]))
                    {
                        c = 1;
                    }
                    break;
                }

                default: {
                    itemname = itemlist[item];
                    if (new[] { 420, 421, 422, 423, 423, 424, 425, 426, 427, 737 }.Contains(legalitems[i]))
                    {
                        c = 1;
                    }
                    break;
                }
                }

                dgv.Rows[i].Cells[0].Value = itemname;
                dgv.Rows[i].Cells[1].Value = c;
            }
            System.Media.SystemSounds.Asterisk.Play();
        }
Esempio n. 14
0
 private void PB_QR_Click(object sender, EventArgs e)
 {
     if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy QR Image to Clipboard?"))
     {
         return;
     }
     try { Clipboard.SetImage(PB_QR.BackgroundImage); }
     catch { Util.Alert("Failed to set Image to Clipboard"); }
 }
Esempio n. 15
0
        private void populateList(string[] itemarr, int offset, int itemcount)
        {
            dataGridView1.Rows.Clear();
            dataGridView1.Columns.Clear();

            DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn();
            {
                dgvIndex.HeaderText   = "CNT";
                dgvIndex.DisplayIndex = 1;
                dgvIndex.Width        = 45;
                dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }
            DataGridViewComboBoxColumn dgvItemVal = new DataGridViewComboBoxColumn
            {
                DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing
            };

            {
                foreach (string t in itemarr)
                {
                    dgvItemVal.Items.Add(t); // add only the Item Names
                }
                dgvItemVal.DisplayIndex = 0;
                dgvItemVal.Width        = 135;
                dgvItemVal.FlatStyle    = FlatStyle.Flat;
            }
            dataGridView1.Columns.Add(dgvItemVal);
            dataGridView1.Columns.Add(dgvIndex);

            dataGridView1.Rows.Add(itemcount);
            dataGridView1.CancelEdit();

            string itemname = "";

            for (int i = 0; i < itemcount; i++)
            {
                int itemvalue = BitConverter.ToUInt16(sav, offset + i * 4);
                try { itemname = Main.itemlist[itemvalue]; }
                catch
                {
                    Util.Error("Unknown item detected.", "Item ID: " + itemvalue, "Item is after: " + itemname);
                    continue;
                }
                int itemarrayval = Array.IndexOf(itemarr, itemname);
                if (itemarrayval == -1)
                {
                    dataGridView1.Rows[i].Cells[0].Value = itemarr[0];
                    dataGridView1.Rows[i].Cells[1].Value = 0;
                    Util.Alert(itemname + " removed from item pouch.", "If you exit the Item Editor by saving changes, the item will no longer be in the pouch.");
                }
                else
                {
                    dataGridView1.Rows[i].Cells[0].Value = itemarr[itemarrayval];
                    dataGridView1.Rows[i].Cells[1].Value = BitConverter.ToUInt16(sav, offset + i * 4 + 2);
                }
            }
        }
Esempio n. 16
0
        private void L_QR_Click(object sender, EventArgs e)
        {
            if (ModifierKeys == Keys.Alt)
            {
                byte[] data = QR.getQRData();
                if (data == null)
                {
                    return;
                }

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

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

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

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

                new QR(qr, PB_Preview.Image, desc, "", "", "PKHeX Wonder Card @ ProjectPokemon.org").ShowDialog();
            }
        }
        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();
            }
        }
Esempio n. 18
0
        private void B_Go_Click(object sender, EventArgs e)
        {
            if (b.IsBusy)
            {
                Util.Alert("Currently executing instruction list."); return;
            }

            if (RTB_Instructions.Lines.Any(line => line.Length == 0))
            {
                Util.Error("Line length error in instruction list."); return;
            }

            runBackgroundWorker();
        }
Esempio n. 19
0
        private void clickSet(object sender, EventArgs e)
        {
            // Don't care what slot was clicked, just add it to the database
            if (!m_parent.verifiedPKX())
            {
                return;
            }

            PK6 pk = m_parent.preparepkx();

            if (!Directory.Exists(DatabasePath))
            {
                Directory.CreateDirectory(DatabasePath);
            }

            string path = Path.Combine(DatabasePath, Util.CleanFileName(pk.FileName));

            if (RawDB.Any(p => p.Identifier == path))
            {
                Util.Alert("File already exists in database!");
                return;
            }

            File.WriteAllBytes(path, pk.Data.Take(PK6.SIZE_STORED).ToArray());
            pk.Identifier = path;

            int pre = RawDB.Count;

            RawDB.Add(pk);
            RawDB = new List <PK6>(RawDB.Distinct()); // just in case
            int post = RawDB.Count;

            if (pre == post)
            {
                Util.Alert("Pokémon already exists in database."); return;
            }
            Results.Add(pk);

            // Refresh database view.
            L_Count.Text = string.Format(Counter, Results.Count);
            slotSelected = Results.Count - 1;
            slotColor    = Properties.Resources.slotSet;
            if ((SCR_Box.Maximum + 1) * 6 < Results.Count)
            {
                SCR_Box.Maximum += 1;
            }
            SCR_Box.Value = Math.Max(0, SCR_Box.Maximum - PKXBOXES.Length / 6 + 1);
            FillPKXBoxes(SCR_Box.Value);
            Util.Alert("Added Pokémon from tabs to database.");
        }
        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);
        }
Esempio n. 21
0
        private void changeNickname(object sender, MouseEventArgs e)
        {
            TextBox tb = !(sender is TextBox) ? TB_Nickname : (TextBox)sender;

            // Special Character Form
            if (ModifierKeys != Keys.Control)
            {
                return;
            }

            if (Application.OpenForms.Cast <Form>().Any(form => form.Name == typeof(f2_Text).Name))
            {
                Util.Alert("Window is already open."); return;
            }
            new f2_Text(tb).Show();
        }
Esempio n. 22
0
 public SAV_HallOfFame(Form1 frm1)
 {
     InitializeComponent();
     Util.TranslateInterface(this, Form1.curlanguage);
     m_parent = frm1;
     Array.Copy(m_parent.savefile, sav, 0x100000);
     savindex = m_parent.savindex;
     shiftval = savindex * 0x7F000;
     if (m_parent.savegame_oras)
     {
         data_offset = 0x1F200;
     }
     Array.Copy(sav, shiftval + data_offset, data, 0, data.Length); //Copy HoF section of save into Data
     Setup();
     editor_spec = new object[] {
         GB_OT,
         GB_CurrentMoves,
         CB_Species,
         CB_HeldItem,
         TB_EC,
         TB_VN,
         CAL_MetDate,
         CHK_Nicknamed,
         CHK_Shiny,
         L_PartyNum,
         L_Victory,
         L_Shiny,
         L_Level,
         Label_TID,
         Label_Form,
         Label_Gender,
         Label_HeldItem,
         Label_OT,
         Label_TID,
         Label_SID,
         Label_Species,
         TB_Level,
         NUP_PartyIndex,
         Label_EncryptionConstant,
         Label_MetDate,
     };
     LB_DataEntry.SelectedIndex = 0;
     NUP_PartyIndex_ValueChanged(null, null);
     try { TB_Nickname.Font = PKX.getPKXFont(11); }
     catch (Exception e) { Util.Alert("Font loading failed...", e.ToString()); }
     editing = true;
 }
Esempio n. 23
0
        private void L_QR_Click(object sender, EventArgs e)
        {
            if (ModifierKeys == Keys.Alt)
            {
                byte[] wc = Util.getQRData();

                if (wc.Length != WC6.Size)
                {
                    Util.Alert("Decoded data not 0x108 bytes.", String.Format("QR Data Size: 0x{0}", wc.Length.ToString("X")));
                }
                else
                {
                    try
                    {
                        Array.Copy(wc, wondercard_data, wc.Length);
                        loadwcdata();
                    }
                    catch { Util.Alert("Error loading wondercard data."); }
                }
            }
            else
            {
                if (wondercard_data.SequenceEqual((new byte[wondercard_data.Length])))
                {
                    Util.Alert("No wondercard data found in loaded slot!"); return;
                }
                if (BitConverter.ToUInt16(wondercard_data, 0x68) == 726 && wondercard_data[0x51] == 1)
                {
                    Util.Alert("Eon Ticket Wonder Cards will not function properly", "Inject to the save file instead."); return;
                }
                // Prep data
                byte[] wcdata = wondercard_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 = getWCDescriptionString(wondercard_data);

                new QR(qr, PB_Preview.Image, desc, "", "", "PKHeX Wonder Card @ ProjectPokemon.org").ShowDialog();
            }
        }
Esempio n. 24
0
        private void B_Add_Click(object sender, EventArgs e)
        {
            if (CB_Property.SelectedIndex < 0)
            {
                Util.Alert("Invalid property selected."); return;
            }

            char[] prefix = { '.', '=', '!' };
            string s      = prefix[CB_Require.SelectedIndex] + CB_Property.Items[CB_Property.SelectedIndex].ToString() + "=";

            if (RTB_Instructions.Lines.Length != 0 && RTB_Instructions.Lines.Last().Length > 0)
            {
                s = Environment.NewLine + s;
            }

            RTB_Instructions.AppendText(s);
        }
Esempio n. 25
0
        public SAV_Trainer7()
        {
            InitializeComponent();
            if (!Main.unicode)
            {
                try { TB_OTName.Font = PKX.getPKXFont(11); }
                catch (Exception e) { Util.Alert("Font loading failed...", e.ToString()); }
            }

            Util.TranslateInterface(this, Main.curlanguage);
            B_MaxCash.Click += (sender, e) => MT_Money.Text = "9,999,999";

            CB_Gender.Items.Clear();
            CB_Gender.Items.AddRange(Main.gendersymbols.Take(2).ToArray()); // m/f depending on unicode selection

            getComboBoxes();
            getTextBoxes();
        }
Esempio n. 26
0
        private void B_Export_Click(object sender, EventArgs e)
        {
            if (LinkInfo.Data == null)
            {
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog {
                Filter = PL6.Filter
            };

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

            File.WriteAllBytes(sfd.FileName, LinkInfo.Data);
            Util.Alert("Pokémon Link data saved to:\r" + sfd.FileName + ".");
        }
Esempio n. 27
0
 public SAV_Link6()
 {
     InitializeComponent();
     foreach (var cb in TAB_Items.Controls.OfType <ComboBox>())
     {
         cb.DisplayMember = "Text";
         cb.ValueMember   = "Value";
         cb.DataSource    = new BindingSource(GameInfo.ItemDataSource.Where(item => item.Value <= SAV.MaxItemID).ToArray(), null);
     }
     Util.TranslateInterface(this, Main.curlanguage);
     byte[] data = SAV.LinkBlock;
     if (data == null)
     {
         Util.Alert("Invalid save file / Link Information");
         Close();
     }
     data = data.Skip(0x1FF).Take(PL6.Size).ToArray();
     loadLinkData(data);
 }
Esempio n. 28
0
        // QR Utility
        internal static byte[] getQRData()
        {
            // Fetch data from QR code...
            string address;

            try { address = Clipboard.GetText(); }
            catch { Util.Alert("No text (url) in clipboard."); return(null); }
            try { if (address.Length < 4 || address.Substring(0, 3) != "htt")
                  {
                      Util.Alert("Clipboard text is not a valid URL:", address); return(null);
                  }
            }
            catch { Util.Alert("Clipboard text is not a valid URL:", address); return(null); }
            string webURL = "http://api.qrserver.com/v1/read-qr-code/?fileurl=" + HttpUtility.UrlEncode(address);

            try
            {
                HttpWebRequest  httpWebRequest = (HttpWebRequest)WebRequest.Create(webURL);
                HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse();
                var             reader         = new StreamReader(httpWebReponse.GetResponseStream());
                string          data           = reader.ReadToEnd();
                if (data.Contains("could not find"))
                {
                    Util.Alert("Reader could not find QR data in the image."); return(null);
                }
                if (data.Contains("filetype not supported"))
                {
                    Util.Alert("Input URL is not valid. Double check that it is an image (jpg/png).", address); return(null);
                }
                // Quickly convert the json response to a data string
                string pkstr = data.Substring(data.IndexOf("#", StringComparison.Ordinal) + 1);               // Trim intro
                pkstr = pkstr.Substring(0, pkstr.IndexOf("\",\"error\":null}]}]", StringComparison.Ordinal)); // Trim outro
                if (pkstr.Contains("nQR-Code:"))
                {
                    pkstr = pkstr.Substring(0, pkstr.IndexOf("nQR-Code:", StringComparison.Ordinal)); //  Remove multiple QR codes in same image
                }
                pkstr = pkstr.Replace("\\", "");                                                      // Rectify response

                try { return(Convert.FromBase64String(pkstr)); }
                catch { Util.Alert("QR string to Data failed.", pkstr); return(null); }
            }
            catch { Util.Alert("Unable to connect to the internet to decode QR code."); return(null); }
        }
Esempio n. 29
0
        private bool checkSpecialWonderCard(MysteryGift g)
        {
            if (SAV.Generation != 6)
                return true;

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

            return true;
            reject: Util.Alert("Unable to insert the Mystery Gift.", "Does this Mystery Gift really belong to this game?");
            return false;
        }
Esempio n. 30
0
        private bool checkSpecialWonderCard(byte[] data)
        {
            ushort cardID = BitConverter.ToUInt16(data, 0);
            ushort item   = BitConverter.ToUInt16(data, 0x68);

            if (cardID == 2048 && item == 726) // Eon Ticket (OR/AS)
            {
                if (!Main.SAV.ORAS || Main.SAV.EonTicket < 0)
                {
                    goto reject;
                }
                BitConverter.GetBytes(EonTicketConst).CopyTo(sav, 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);
        }