예제 #1
0
        private void B_Load_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog {
                Filter = "Code File|*.bin"
            };

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

            string path = ofd.FileName;

            byte[] ncf    = File.ReadAllBytes(path);
            uint   length = BitConverter.ToUInt32(ncf, 0);

            if (ncf.Length != length + 4)
            {
                Util.Error("Not a valid code file.");
                return;
            }
            if (RTB_Code.Text.Length > 0)
            {
                DialogResult ld = Util.Prompt(MessageBoxButtons.YesNo, "Replace current code?");
                if (ld == DialogResult.Yes)
                {
                    RTB_Code.Clear();
                }
                else if (ld != DialogResult.No)
                {
                    return;
                }
            }
            for (int i = 4; i <= ncf.Length - 12; i += 12)
            {
                RTB_Code.AppendText(BitConverter.ToUInt32(ncf, i + 0 * 4).ToString("X8") + " ");
                RTB_Code.AppendText(BitConverter.ToUInt32(ncf, i + 1 * 4).ToString("X8") + " ");
                RTB_Code.AppendText(BitConverter.ToUInt32(ncf, i + 2 * 4).ToString("X8") + Environment.NewLine);
            }
        }
예제 #2
0
        // 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();
        }
예제 #3
0
        // Wonder Card IO (.wc6<->window)
        private void B_Import_Click(object sender, EventArgs e)
        {
            OpenFileDialog importwc6 = new OpenFileDialog {
                Filter = "Wonder Card|*.wc6"
            };

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

            string path = importwc6.FileName;

            if (new FileInfo(path).Length != WC6.Size)
            {
                Util.Error("File is not a Wonder Card:", path);
                return;
            }
            byte[] newwc6 = File.ReadAllBytes(path);
            Array.Copy(newwc6, wondercard_data, newwc6.Length);
            loadwcdata();
        }
예제 #4
0
        private void loadSAV(object sender, string path)
        {
            FileInfo fi = new FileInfo(path);

            byte[] eventflags = new byte[0x180];
            switch (fi.Length)
            {
            case 0x100000:     // ramsav
                Array.Copy(File.ReadAllBytes(path), Main.SaveGame.EventFlag, eventflags, 0, 0x180);
                break;

            case 0x76000:     // oras main
                Array.Copy(File.ReadAllBytes(path), Main.SaveGame.EventFlag, eventflags, 0, 0x180);
                break;

            default:     // figure it out
                if (fi.Name.ToLower().Contains("ram") && fi.Length == 0x80000)
                {
                    Array.Copy(ram2sav.getMAIN(File.ReadAllBytes(path)), Main.SaveGame.EventFlag, eventflags, 0, 0x180);
                }
                else
                {
                    Util.Error("Invalid SAV Size", String.Format("File Size: 0x{1} ({0} bytes)", fi.Length, fi.Length.ToString("X5")), "File Loaded: " + path); return;
                }
                break;
            }

            Button bs = (Button)sender;

            if (bs.Name == "B_LoadOld")
            {
                Array.Copy(eventflags, olddata, 0x180); TB_OldSAV.Text = path;
            }
            else
            {
                Array.Copy(eventflags, newdata, 0x180); TB_NewSAV.Text = path;
            }
        }
예제 #5
0
        private void B_ImportPNG_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter = "PNG File|*.png",
                FileName = "Background.png",
            };

            if (ofd.ShowDialog() != DialogResult.OK)
                return;

            Bitmap img = (Bitmap)Image.FromFile(ofd.FileName);

            try
            {
                bg.SetImage(img);
                PB_Background.Image = bg.GetImage();
            }
            catch (Exception ex)
            {
                Util.Error(ex.Message);
            }
        }
예제 #6
0
        private void viewGiftData(MysteryGift g)
        {
            try
            {
                // only check if the form is visible (not opening)
                if (Visible && g.GiftUsed && DialogResult.Yes ==
                    Util.Prompt(MessageBoxButtons.YesNo,
                                "Wonder Card is marked as USED and will not be able to be picked up in-game.",
                                "Do you want to remove the USED flag so that it is UNUSED?"))
                {
                    g.GiftUsed = false;
                }

                RTB.Text         = getDescription(g);
                PB_Preview.Image = getSprite(g);
                mg = g;
            }
            catch (Exception e)
            {
                Util.Error("Loading of data failed... is this really a Wonder Card?", e.ToString());
                RTB.Clear();
            }
        }
예제 #7
0
        private void tabMain_DragDrop(object sender, DragEventArgs e)
        {
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            // Check for multiple wondercards
            int ctr = currentSlot;

            if (files.Length == 1)
            {
                string path = files[0]; // open first D&D
                if (new FileInfo(path).Length != WC6.Size)
                {
                    Util.Error("File is not a Wonder Card:", path);
                    return;
                }
                byte[] newwc6 = File.ReadAllBytes(path);
                Array.Copy(newwc6, wondercard_data, newwc6.Length);
                loadwcdata();
            }
            else if (DialogResult.Yes == Util.Prompt(MessageBoxButtons.YesNo, String.Format("Try to load {0} Wonder Cards starting at Card {1}?", files.Length, ctr + 1)))
            {
                foreach (string file in files)
                {
                    if (new FileInfo(file).Length != WC6.Size)
                    {
                        Util.Error("File is not a Wonder Card:", file); continue;
                    }

                    // Load in WC
                    File.ReadAllBytes(file).CopyTo(sav, Main.SAV.WondercardData + WC6.Size * ctr++);
                    if (ctr >= 24)
                    {
                        break;
                    }
                }
            }
        }
예제 #8
0
        private void Menu_DeleteClones_Click(object sender, EventArgs e)
        {
            var dr = Util.Prompt(MessageBoxButtons.YesNo,
                                 "Deleting clones from database is not reversible." + Environment.NewLine +
                                 "If a PKM is deemed a clone, only the newest file (date modified) will be kept.", "Continue?");

            if (dr != DialogResult.Yes)
            {
                return;
            }

            var hashes  = new List <string>();
            var deleted = 0;
            var db      = RawDB.Where(pk => pk.Identifier.StartsWith(DatabasePath + Path.DirectorySeparatorChar))
                          .OrderByDescending(file => new FileInfo(file.Identifier).LastWriteTime);

            foreach (var pk in db)
            {
                var h = hash(pk);
                if (!hashes.Contains(h))
                {
                    hashes.Add(h); continue;
                }

                try { File.Delete(pk.Identifier); ++deleted; }
                catch { Util.Error("Unable to delete clone:" + Environment.NewLine + pk.Identifier); }
            }

            if (deleted == 0)
            {
                Util.Alert("No clones detected or deleted."); return;
            }

            Util.Alert($"{deleted} files deleted.", "The form will now close.");
            Close();
        }
예제 #9
0
        private void loadSAV(object sender, string path)
        {
            FileInfo fi = new FileInfo(path);

            if (fi.Length != SAV6.SIZE_XY)
            {
                Util.Error("Invalid SAV Size", string.Format("File Size: 0x{1} ({0} bytes)", fi.Length, fi.Length.ToString("X5")), "File Loaded: " + path);
                return;
            }

            byte[] data = File.ReadAllBytes(path);
            if (sender == B_LoadOld)
            {
                oldFlags       = data.Skip(Main.SAV.EventFlag).Take(0x180).ToArray();
                oldConst       = data.Skip(Main.SAV.EventConst).Take(Constants.Length * 2).ToArray();
                TB_OldSAV.Text = path;
            }
            else
            {
                newFlags       = data.Skip(Main.SAV.EventFlag).Take(0x180).ToArray();
                newConst       = data.Skip(Main.SAV.EventConst).Take(Constants.Length * 2).ToArray();
                TB_NewSAV.Text = path;
            }
        }
예제 #10
0
        private void pbBoxSlot_MouseMove(object sender, MouseEventArgs e)
        {
            if (DragInfo.slotDragDropInProgress)
            {
                return;
            }

            if (DragInfo.slotLeftMouseIsDown)
            {
                // The goal is to create a temporary PKX file for the underlying Pokemon
                // and use that file to perform a drag drop operation.

                // Abort if there is no Pokemon in the given slot.
                PictureBox pb = (PictureBox)sender;
                if (pb.Image == null)
                {
                    return;
                }

                int slot = getSlot(pb);
                int box  = slot >= 30 ? -1 : CB_BoxSelect.SelectedIndex;
                if (SAV.getIsSlotLocked(box, slot))
                {
                    return;
                }

                // Set flag to prevent re-entering.
                DragInfo.slotDragDropInProgress = true;

                DragInfo.slotSource           = this;
                DragInfo.slotSourceSlotNumber = slot;
                DragInfo.slotSourceBoxNumber  = box;
                DragInfo.slotSourceOffset     = getPKXOffset(DragInfo.slotSourceSlotNumber);

                // Prepare Data
                DragInfo.slotPkmSource = SAV.getData(DragInfo.slotSourceOffset, SAV.SIZE_STORED);

                // Make a new file name based off the PID
                byte[] dragdata = SAV.decryptPKM(DragInfo.slotPkmSource);
                Array.Resize(ref dragdata, SAV.SIZE_STORED);
                PKM    pkx      = SAV.getPKM(dragdata);
                string filename = pkx.FileName;

                // Make File
                string newfile = Path.Combine(Path.GetTempPath(), Util.CleanFileName(filename));
                try
                {
                    File.WriteAllBytes(newfile, dragdata);
                    var img = (Bitmap)pb.Image;
                    DragInfo.Cursor    = Cursor.Current = new Cursor(img.GetHicon());
                    pb.Image           = null;
                    pb.BackgroundImage = Properties.Resources.slotDrag;
                    // Thread Blocks on DoDragDrop
                    DragInfo.CurrentPath = newfile;
                    DragDropEffects result = pb.DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move);
                    if (!DragInfo.SourceValid || result != DragDropEffects.Link) // not dropped to another box slot, restore img
                    {
                        pb.Image = img;
                    }
                    else // refresh image
                    {
                        getQuickFiller(pb, SAV.getStoredSlot(DragInfo.slotSourceOffset));
                    }
                    pb.BackgroundImage = null;

                    if (DragInfo.SameBox && DragInfo.DestinationValid)
                    {
                        SlotPictureBoxes[DragInfo.slotDestinationSlotNumber].Image = img;
                    }
                }
                catch (Exception x)
                {
                    Util.Error("Drag & Drop Error", x);
                }
                parent.notifyBoxViewerRefresh();
                DragInfo.Reset();
                Cursor = DefaultCursor;

                // Browser apps need time to load data since the file isn't moved to a location on the user's local storage.
                // Tested 10ms -> too quick, 100ms was fine. 500ms should be safe?
                new Thread(() =>
                {
                    Thread.Sleep(500);
                    if (File.Exists(newfile) && DragInfo.CurrentPath == null)
                    {
                        File.Delete(newfile);
                    }
                }).Start();
            }
        }
예제 #11
0
        private void spillBag(DataGridView dgv, int bag)
        {
            var pouch     = Pouches[bag];
            var itemcount = Pouches[bag].Items.Length;

            string[] itemarr = Main.HaX ? (string[])itemlist.Clone() : getItems(pouch.LegalItems);

            dgv.Rows.Clear();
            dgv.Columns.Clear();

            DataGridViewComboBoxColumn dgvItemVal = new DataGridViewComboBoxColumn
            {
                DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
                DisplayIndex = 0,
                Width        = 135,
                FlatStyle    = FlatStyle.Flat
            };
            DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn();

            {
                dgvIndex.HeaderText   = "CNT";
                dgvIndex.DisplayIndex = 1;
                dgvIndex.Width        = 45;
                dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            }
            foreach (string t in itemarr)
            {
                dgvItemVal.Items.Add(t); // add only the Item Names
            }
            dgv.Columns.Add(dgvItemVal);
            dgv.Columns.Add(dgvIndex);

            dgv.Rows.Add(itemcount > 0 ? itemcount : itemarr.Length);
            dgv.CancelEdit();

            string itemname = "";
            string err      = "";

            for (int i = 0; i < pouch.Items.Length; i++)
            {
                int itemvalue = pouch.Items[i].Index;
                if (itemvalue >= itemlist.Length)
                {
                    Util.Error("Unknown item detected.", "Item ID: " + itemvalue, "Item is after: " + itemname);
                    dgv.Rows[i].Cells[0].Value = itemarr[0];
                    dgv.Rows[i].Cells[1].Value = 0;
                    continue;
                }
                itemname = itemlist[itemvalue];

                int itemarrayval = Array.IndexOf(itemarr, itemname);
                if (itemarrayval == -1)
                {
                    dgv.Rows[i].Cells[0].Value = itemarr[0];
                    dgv.Rows[i].Cells[1].Value = 0;

                    err += itemname + ", ";
                }
                else
                {
                    dgv.Rows[i].Cells[0].Value = itemname;
                    dgv.Rows[i].Cells[1].Value = pouch.Items[i].Count;
                }
            }
            if (err.Length > 0)
            {
                Util.Alert($"The following items have been removed from {Pouches[bag].Type} pouch.", err,
                           "If you save changes, the item(s) will no longer be in the pouch.");
            }
        }
예제 #12
0
        private void diffSaves()
        {
            if (!File.Exists(TB_OldSAV.Text))
            {
                Util.Alert("Save 1 path invalid."); return;
            }
            if (!File.Exists(TB_NewSAV.Text))
            {
                Util.Alert("Save 2 path invalid."); return;
            }
            if (new FileInfo(TB_OldSAV.Text).Length > 0x100000)
            {
                Util.Alert("Save 1 file invalid."); return;
            }
            if (new FileInfo(TB_NewSAV.Text).Length > 0x100000)
            {
                Util.Alert("Save 2 file invalid."); return;
            }

            SaveFile s1 = SaveUtil.getVariantSAV(File.ReadAllBytes(TB_OldSAV.Text));
            SaveFile s2 = SaveUtil.getVariantSAV(File.ReadAllBytes(TB_NewSAV.Text));

            if (s1.GetType() != s2.GetType())
            {
                Util.Alert("Save types are different.", $"S1: {s1.GetType()}", $"S2: {s2.GetType()}"); return;
            }
            if (s1.Version != s2.Version)
            {
                Util.Alert("Save versions are different.", $"S1: {s1.Version}", $"S2: {s2.Version}"); return;
            }

            string tbIsSet = "";
            string tbUnSet = "";

            try
            {
                bool[] oldBits = s1.EventFlags;
                bool[] newBits = s2.EventFlags;
                if (oldBits.Length != newBits.Length)
                {
                    Util.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return;
                }

                for (int i = 0; i < oldBits.Length; i++)
                {
                    if (oldBits[i] == newBits[i])
                    {
                        continue;
                    }
                    if (newBits[i])
                    {
                        tbIsSet += i.ToString("0000") + ",";
                    }
                    else
                    {
                        tbUnSet += i.ToString("0000") + ",";
                    }
                }
            }
            catch (Exception e)
            {
                Util.Error(e.ToString());
                Console.Write(e);
            }
            TB_IsSet.Text = tbIsSet;
            TB_UnSet.Text = tbUnSet;

            string r = "";

            try
            {
                ushort[] oldConst = s1.EventConsts;
                ushort[] newConst = s2.EventConsts;
                if (oldConst.Length != newConst.Length)
                {
                    Util.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return;
                }

                for (int i = 0; i < newConst.Length; i++)
                {
                    if (oldConst[i] != newConst[i])
                    {
                        r += $"{i}: {oldConst[i]}->{newConst[i]}{Environment.NewLine}";
                    }
                }
            }
            catch (Exception e)
            {
                Util.Error(e.ToString());
                Console.Write(e);
            }

            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?"))
            {
                return;
            }
            Clipboard.SetText(r);
        }
예제 #13
0
        private void B_FAV2SAV(object sender, EventArgs e)
        {
            // Write data back to save
            int index = LB_Favorite.SelectedIndex; // store for restoring

            if (!GB_PKM.Enabled && index > 0)
            {
                Util.Error("Sorry, no overwriting someone else's base with your own data."); return;
            }
            if (GB_PKM.Enabled && index == 0)
            {
                Util.Error("Sorry, no overwriting of your own base with someone else's."); return;
            }
            if (LB_Favorite.Items[index].ToString().Substring(LB_Favorite.Items[index].ToString().Length - 5, 5) == "Empty")
            {
                Util.Error("Sorry, no overwriting an empty base with someone else's."); return;
            }
            if (index < 0)
            {
                return;
            }
            int offset = Main.SAV.SecretBase + 0x25A;

            // Base Offset Changing
            if (index == 0)
            {
                offset = Main.SAV.SecretBase + 0x326;
            }
            else
            {
                offset += 0x3E0 * index;
            }

            string TrainerName = TB_FOT.Text;

            byte[] tr = Encoding.Unicode.GetBytes(TrainerName);
            Array.Resize(ref tr, 0x22); Array.Copy(tr, 0, sav, offset + 0x218, 0x1A);

            string team1 = TB_FT1.Text;
            string team2 = TB_FT2.Text;

            byte[] t1 = Encoding.Unicode.GetBytes(team1);
            Array.Resize(ref t1, 0x22); Array.Copy(t1, 0, sav, offset + 0x232 + 0x22 * 0, 0x22);
            byte[] t2 = Encoding.Unicode.GetBytes(team2);
            Array.Resize(ref t2, 0x22); Array.Copy(t2, 0, sav, offset + 0x232 + 0x22 * 1, 0x22);

            string saying1 = TB_FSay1.Text;
            string saying2 = TB_FSay2.Text;
            string saying3 = TB_FSay3.Text;
            string saying4 = TB_FSay4.Text;

            byte[] s1 = Encoding.Unicode.GetBytes(saying1);
            Array.Resize(ref s1, 0x22); Array.Copy(s1, 0, sav, offset + 0x276 + 0x22 * 0, 0x22);
            byte[] s2 = Encoding.Unicode.GetBytes(saying2);
            Array.Resize(ref s2, 0x22); Array.Copy(s2, 0, sav, offset + 0x276 + 0x22 * 1, 0x22);
            byte[] s3 = Encoding.Unicode.GetBytes(saying3);
            Array.Resize(ref s3, 0x22); Array.Copy(s3, 0, sav, offset + 0x276 + 0x22 * 2, 0x22);
            byte[] s4 = Encoding.Unicode.GetBytes(saying4);
            Array.Resize(ref s4, 0x22); Array.Copy(s4, 0, sav, offset + 0x276 + 0x22 * 3, 0x22);

            int baseloc = (int)NUD_FBaseLocation.Value;

            if (baseloc < 3)
            {
                baseloc = 0;              // skip 1/2 baselocs as they are dummied out ingame.
            }
            Array.Copy(BitConverter.GetBytes(baseloc), 0, sav, offset, 2);

            TB_FOT.Text = TrainerName; TB_FSay1.Text = saying1; TB_FSay2.Text = saying2; TB_FSay3.Text = saying3; TB_FSay4.Text = saying4;

            // Copy back Objects
            for (int i = 0; i < 25; i++)
            {
                for (int z = 0; z < 12; z++)
                {
                    sav[offset + 2 + 12 * i + z] = objdata[i, z];
                }
            }

            if (GB_PKM.Enabled) // Copy pkm data back in
            {
                saveFavPKM();
                for (int i = 0; i < 3; i++)
                {
                    for (int z = 0; z < 0x34; z++)
                    {
                        sav[offset + 0x32E + 0x34 * i + z] = pkmdata[i, z];
                    }
                }
            }
            popFavorite();
            LB_Favorite.SelectedIndex = index;
        }
예제 #14
0
        // View Updates
        private void B_Search_Click(object sender, EventArgs e)
        {
            // Populate Search Query Result
            IEnumerable <MysteryGift> res = RawDB;

            int format = MAXFORMAT + 1 - CB_Format.SelectedIndex;

            switch (CB_FormatComparator.SelectedIndex)
            {
            case 0: /* Do nothing */ break;

            case 1: res = res.Where(mg => mg.Format >= format); break;

            case 2: res = res.Where(mg => mg.Format == format); break;

            case 3: res = res.Where(mg => mg.Format <= format); break;
            }

            // Primary Searchables
            int species = Util.getIndex(CB_Species);
            int item    = Util.getIndex(CB_HeldItem);

            if (species != -1)
            {
                res = res.Where(pk => pk.Species == species);
            }
            if (item != -1)
            {
                res = res.Where(pk => pk.HeldItem == item);
            }

            // Secondary Searchables
            int move1 = Util.getIndex(CB_Move1);
            int move2 = Util.getIndex(CB_Move2);
            int move3 = Util.getIndex(CB_Move3);
            int move4 = Util.getIndex(CB_Move4);

            if (move1 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move1));
            }
            if (move2 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move2));
            }
            if (move3 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move3));
            }
            if (move4 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move4));
            }
            if (CHK_Shiny.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsShiny);
            }
            if (CHK_Shiny.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsShiny);
            }
            if (CHK_IsEgg.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsEgg);
            }
            if (CHK_IsEgg.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsEgg);
            }

            slotSelected = -1; // reset the slot last viewed

            if (RTB_Instructions.Lines.Any(line => line.Length > 0))
            {
                var raw =
                    RTB_Instructions.Lines
                    .Where(line => !string.IsNullOrWhiteSpace(line))
                    .Where(line => new[] { '!', '=' }.Contains(line[0]));

                var filters = (from line in raw
                               let eval = line[0] == '='
                                          let split = line.Substring(1).Split('=')
                                                      where split.Length == 2 && !string.IsNullOrWhiteSpace(split[0])
                                                      select new BatchEditor.StringInstruction {
                    PropertyName = split[0], PropertyValue = split[1], Evaluator = eval
                }).ToArray();

                if (filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))
                {
                    Util.Error("Empty Filter Value detected."); return;
                }

                res = res.Where(gift => // Compare across all filters
                {
                    foreach (var cmd in filters)
                    {
                        if (!gift.GetType().HasPropertyAll(cmd.PropertyName))
                        {
                            return(false);
                        }
                        try { if (ReflectUtil.GetValueEquals(gift, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator)
                              {
                                  continue;
                              }
                        }
                        catch { Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
                        return(false);
                    }
                    return(true);
                });
            }

            var results = res.ToArray();

            if (results.Length == 0)
            {
                Util.Alert("No results found!");
            }
            setResults(new List <MysteryGift>(results)); // updates Count Label as well.
            System.Media.SystemSounds.Asterisk.Play();
        }
예제 #15
0
        private void pbBoxSlot_DragDrop(object sender, DragEventArgs e)
        {
            DragInfo.slotDestination           = this;
            DragInfo.slotDestinationSlotNumber = getSlot(sender);
            DragInfo.slotDestinationOffset     = getPKXOffset(DragInfo.slotDestinationSlotNumber);
            DragInfo.slotDestinationBoxNumber  = CB_BoxSelect.SelectedIndex;

            // Check for In-Dropped files (PKX,SAV,ETC)
            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
            if (Directory.Exists(files[0]))
            {
                return;
            }
            if (SAV.getIsSlotLocked(DragInfo.slotDestinationBoxNumber, DragInfo.slotDestinationSlotNumber))
            {
                DragInfo.slotDestinationSlotNumber = -1; // Invalidate
                Util.Alert("Unable to set to locked slot.");
                return;
            }
            if (DragInfo.slotSourceOffset < 0) // file
            {
                if (files.Length <= 0)
                {
                    return;
                }
                string   file = files[0];
                FileInfo fi   = new FileInfo(file);
                if (!PKX.getIsPKM(fi.Length) && !MysteryGift.getIsMysteryGift(fi.Length))
                {
                    return;
                }

                byte[]      data = File.ReadAllBytes(file);
                MysteryGift mg   = MysteryGift.getMysteryGift(data, fi.Extension);
                PKM         temp = mg != null?mg.convertToPKM(SAV) : PKMConverter.getPKMfromBytes(data);

                string c;

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

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

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

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

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

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

                e.Effect = DragDropEffects.Link;
                Cursor   = DefaultCursor;
            }
            if (DragInfo.SourceParty || DragInfo.DestinationParty)
            {
                parent.setParty();
            }
            if (DragInfo.slotSource == null) // another instance or file
            {
                parent.notifyBoxViewerRefresh();
                DragInfo.Reset();
            }
        }
예제 #16
0
        // View Updates
        private void B_Search_Click(object sender, EventArgs e)
        {
            // Populate Search Query Result
            IEnumerable <PKM> res = RawDB;

            int format = MAXFORMAT + 1 - CB_Format.SelectedIndex;

            switch (CB_FormatComparator.SelectedIndex)
            {
            case 0: /* Do nothing */ break;

            case 1: res = res.Where(pk => pk.Format >= format); break;

            case 2: res = res.Where(pk => pk.Format == format); break;

            case 3: res = res.Where(pk => pk.Format <= format); break;
            }
            if (CB_FormatComparator.SelectedIndex != 0)
            {
                if (format <= 2) // 1-2
                {
                    res = res.Where(pk => pk.Format <= 2);
                }
                if (format >= 3 && format <= 6) // 3-6
                {
                    res = res.Where(pk => pk.Format >= 3);
                }
                if (format >= 7) // 1,3-6,7
                {
                    res = res.Where(pk => pk.Format != 2);
                }
            }

            switch (CB_Generation.SelectedIndex)
            {
            case 0: /* Do nothing */ break;

            case 1: res = res.Where(pk => pk.Gen7); break;

            case 2: res = res.Where(pk => pk.Gen6); break;

            case 3: res = res.Where(pk => pk.Gen5); break;

            case 4: res = res.Where(pk => pk.Gen4); break;

            case 5: res = res.Where(pk => pk.Gen3); break;
            }

            // Primary Searchables
            int species = Util.getIndex(CB_Species);
            int ability = Util.getIndex(CB_Ability);
            int nature  = Util.getIndex(CB_Nature);
            int item    = Util.getIndex(CB_HeldItem);

            if (species != -1)
            {
                res = res.Where(pk => pk.Species == species);
            }
            if (ability != -1)
            {
                res = res.Where(pk => pk.Ability == ability);
            }
            if (nature != -1)
            {
                res = res.Where(pk => pk.Nature == nature);
            }
            if (item != -1)
            {
                res = res.Where(pk => pk.HeldItem == item);
            }

            // Secondary Searchables
            int move1 = Util.getIndex(CB_Move1);
            int move2 = Util.getIndex(CB_Move2);
            int move3 = Util.getIndex(CB_Move3);
            int move4 = Util.getIndex(CB_Move4);

            if (move1 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move1));
            }
            if (move2 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move2));
            }
            if (move3 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move3));
            }
            if (move4 != -1)
            {
                res = res.Where(pk => pk.Moves.Contains(move4));
            }
            int vers = Util.getIndex(CB_GameOrigin);

            if (vers != -1)
            {
                res = res.Where(pk => pk.Version == vers);
            }
            int hptype = Util.getIndex(CB_HPType);

            if (hptype != -1)
            {
                res = res.Where(pk => pk.HPType == hptype);
            }
            if (CHK_Shiny.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsShiny);
            }
            if (CHK_Shiny.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsShiny);
            }
            if (CHK_IsEgg.CheckState == CheckState.Checked)
            {
                res = res.Where(pk => pk.IsEgg);
            }
            if (CHK_IsEgg.CheckState == CheckState.Unchecked)
            {
                res = res.Where(pk => !pk.IsEgg);
            }
            if (CHK_IsEgg.CheckState == CheckState.Checked && MT_ESV.Text != "")
            {
                res = res.Where(pk => pk.PSV == Convert.ToInt16(MT_ESV.Text));
            }

            // Tertiary Searchables
            if (TB_Level.Text != "") // Level
            {
                int level = Convert.ToInt16(TB_Level.Text);
                if (level <= 100)
                {
                    switch (CB_Level.SelectedIndex)
                    {
                    case 0: break; // Any

                    case 1:        // <=
                        res = res.Where(pk => pk.Stat_Level <= level);
                        break;

                    case 2: // ==
                        res = res.Where(pk => pk.Stat_Level == level);
                        break;

                    case 3: // >=
                        res = res.Where(pk => pk.Stat_Level >= level);
                        break;
                    }
                }
            }
            switch (CB_IV.SelectedIndex)
            {
            case 0: break; // Do nothing

            case 1:        // <= 90
                res = res.Where(pk => pk.IVs.Sum() <= 90);
                break;

            case 2:     // 91-120
                res = res.Where(pk => pk.IVs.Sum() > 90 && pk.IVs.Sum() <= 120);
                break;

            case 3:     // 121-150
                res = res.Where(pk => pk.IVs.Sum() > 120 && pk.IVs.Sum() <= 150);
                break;

            case 4:     // 151-179
                res = res.Where(pk => pk.IVs.Sum() > 150 && pk.IVs.Sum() < 180);
                break;

            case 5:     // 180+
                res = res.Where(pk => pk.IVs.Sum() >= 180);
                break;

            case 6:     // == 186
                res = res.Where(pk => pk.IVs.Sum() == 186);
                break;
            }
            switch (CB_EVTrain.SelectedIndex)
            {
            case 0: break; // Do nothing

            case 1:        // None (0)
                res = res.Where(pk => pk.EVs.Sum() == 0);
                break;

            case 2:     // Some (127-0)
                res = res.Where(pk => pk.EVs.Sum() < 128);
                break;

            case 3:     // Half (128-507)
                res = res.Where(pk => pk.EVs.Sum() >= 128 && pk.EVs.Sum() < 508);
                break;

            case 4:     // Full (508+)
                res = res.Where(pk => pk.EVs.Sum() >= 508);
                break;
            }

            // Filter for Selected Source
            if (!Menu_SearchBoxes.Checked)
            {
                res = res.Where(pk => pk.Identifier.Contains("db\\"));
            }
            if (!Menu_SearchDatabase.Checked)
            {
                res = res.Where(pk => !pk.Identifier.Contains("db\\"));
            }

            slotSelected = -1;                                           // reset the slot last viewed

            if (Menu_SearchLegal.Checked && !Menu_SearchIllegal.Checked) // Legal Only
            {
                res = res.Where(pk => pk.GenNumber >= 6 && new LegalityAnalysis(pk).Valid);
            }
            if (!Menu_SearchLegal.Checked && Menu_SearchIllegal.Checked) // Illegal Only
            {
                res = res.Where(pk => pk.GenNumber >= 6 && !new LegalityAnalysis(pk).Valid);
            }

            if (RTB_Instructions.Lines.Any(line => line.Length > 0))
            {
                var raw =
                    RTB_Instructions.Lines
                    .Where(line => !string.IsNullOrWhiteSpace(line))
                    .Where(line => new[] { '!', '=' }.Contains(line[0]));

                var filters = (from line in raw
                               let eval = line[0] == '='
                                          let split = line.Substring(1).Split('=')
                                                      where split.Length == 2 && !string.IsNullOrWhiteSpace(split[0])
                                                      select new BatchEditor.StringInstruction {
                    PropertyName = split[0], PropertyValue = split[1], Evaluator = eval
                }).ToArray();

                if (filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))
                {
                    Util.Error("Empty Filter Value detected."); return;
                }

                BatchEditor.screenStrings(filters);
                res = res.Where(pkm => // Compare across all filters
                {
                    foreach (var cmd in filters)
                    {
                        if (!pkm.GetType().HasPropertyAll(cmd.PropertyName))
                        {
                            return(false);
                        }
                        try { if (ReflectUtil.GetValueEquals(pkm, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator)
                              {
                                  continue;
                              }
                        }
                        catch { Console.WriteLine($"Unable to compare {cmd.PropertyName} to {cmd.PropertyValue}."); }
                        return(false);
                    }
                    return(true);
                });
            }

            var results = res.ToArray();

            if (results.Length == 0)
            {
                if (!Menu_SearchBoxes.Checked && !Menu_SearchDatabase.Checked)
                {
                    Util.Alert("No data source to search!", "No results found!");
                }
                else
                {
                    Util.Alert("No results found!");
                }
            }
            setResults(new List <PKM>(results)); // updates Count Label as well.
            System.Media.SystemSounds.Asterisk.Play();
        }
예제 #17
0
        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();
        }
예제 #18
0
        private void runBackgroundWorker()
        {
            var Filters = getFilters().ToList();

            if (Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))
            {
                Util.Error("Empty Filter Value detected."); return;
            }

            var Instructions = getInstructions().ToList();

            if (Instructions.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue)))
            {
                Util.Error("Empty Property Value detected."); return;
            }

            string destPath = "";

            if (RB_Path.Checked)
            {
                Util.Alert("Please select the folder where the files will be saved to.", "This can be the same folder as the source of PKM files.");
                var fbd = new FolderBrowserDialog();
                var dr  = fbd.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }

                destPath = fbd.SelectedPath;
            }

            FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = false;

            b = new BackgroundWorker {
                WorkerReportsProgress = true
            };
            screenStrings(Filters);
            screenStrings(Instructions);

            b.DoWork += (sender, e) => {
                if (RB_SAV.Checked)
                {
                    var data = Main.SAV.BoxData;
                    setupProgressBar(data.Length);
                    processSAV(data, Filters, Instructions);
                }
                else
                {
                    var files = Directory.GetFiles(TB_Folder.Text, "*", SearchOption.AllDirectories);
                    setupProgressBar(files.Length);
                    processFolder(files, Filters, Instructions, destPath);
                }
            };
            b.ProgressChanged += (sender, e) =>
            {
                setProgressBar(e.ProgressPercentage);
            };
            b.RunWorkerCompleted += (sender, e) => {
                string result = $"Modified {ctr}/{len} files.";
                if (err > 0)
                {
                    result += Environment.NewLine + $"{err} files ignored due to an internal error.";
                }
                Util.Alert(result);
                FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = true;
                setupProgressBar(0);
            };
            b.RunWorkerAsync();
        }
예제 #19
0