Exemplo n.º 1
0
        private void B_Delete_Click(object sender, EventArgs e)
        {
            if (LB_DataEntry.SelectedIndex < 1)
            {
                Util.Alert("Cannot delete your first Hall of Fame Clear entry."); return;
            }
            int index = LB_DataEntry.SelectedIndex;

            if (Util.Prompt(MessageBoxButtons.YesNo, String.Format("Delete Entry {0} from your records?", index)) == DialogResult.Yes)
            {
                int offset = index * 0x1B4;
                if (index != 15)
                {
                    Array.Copy(data, offset + 0x1B4, data, offset, 0x1B4 * (15 - index));
                }
                // Ensure Last Entry is Cleared
                Array.Copy(new byte[0x1B4], 0, data, 0x1B4 * 15, 0x1B4);
                displayEntry(LB_DataEntry, null);
            }
        }
Exemplo n.º 2
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);
                RTB.Clear();
            }
        }
Exemplo n.º 3
0
 private void loadwcdata()
 {
     try
     {
         if ((wondercard_data[0x52] & 2) != 0 && 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?"))
         {
             wondercard_data[0x52] &= 0xFD; // keep all bits but bit1 (11111101)
         }
         RTB.Text         = getWCDescriptionString(wondercard_data);
         PB_Preview.Image = getWCPreviewImage(wondercard_data);
     }
     catch (Exception e)
     {
         Util.Error("Loading of data failed... is this really a Wonder Card?", e.ToString());
         wondercard_data = new byte[WC6.Size];
         RTB.Clear();
     }
 }
Exemplo n.º 4
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
            {
                return(Util.getImageFromURL(webURL));
            }
            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);
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
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;
                    }
                }
            }
        }
Exemplo n.º 7
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();
        }
Exemplo n.º 8
0
 private void tabMain_DragDrop(object sender, DragEventArgs e)
 {
     string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
     loadSAV(Util.Prompt(MessageBoxButtons.YesNo, "FlagDiff Researcher:", "Yes: Old Save" + Environment.NewLine + "No: New Save") == DialogResult.Yes ? B_LoadOld : B_LoadNew, files[0]);
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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();
            var emptyVal     = Instructions.Where(z => string.IsNullOrWhiteSpace(z.PropertyValue)).ToArray();

            if (emptyVal.Any())
            {
                string props = string.Join(", ", emptyVal.Select(z => z.PropertyName));
                if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo,
                                                    $"Empty Property Value{(emptyVal.Length > 1 ? "s" : "")} detected:" + Environment.NewLine + props,
                                                    "Continue?"))
                {
                    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();
        }
Exemplo n.º 11
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();
            }
        }
Exemplo n.º 12
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();
        }