public PK3(byte[] decryptedData = null, string ident = null) { Data = (byte[])(decryptedData ?? new byte[SIZE_PARTY]).Clone(); PKMConverter.checkEncrypted(ref Data); Identifier = ident; if (Data.Length != SIZE_PARTY) { Array.Resize(ref Data, SIZE_PARTY); } }
private void processFolder(string[] files, List <StringInstruction> Filters, List <StringInstruction> Instructions, string destPath) { len = err = ctr = 0; for (int i = 0; i < files.Length; i++) { string file = files[i]; if (!PKX.getIsPKM(new FileInfo(file).Length)) { b.ReportProgress(i); continue; } byte[] data = File.ReadAllBytes(file); var pkm = PKMConverter.getPKMfromBytes(data); if (!pkm.Valid) { b.ReportProgress(i); continue; } ModifyResult r = ProcessPKM(pkm, Filters, Instructions); if (r != ModifyResult.Invalid) { len++; } if (r == ModifyResult.Error) { err++; } if (r == ModifyResult.Modified) { if (pkm.Species > 0) { pkm.RefreshChecksum(); File.WriteAllBytes(Path.Combine(destPath, Path.GetFileName(file)), pkm.DecryptedBoxData); ctr++; } } b.ReportProgress(i); } }
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(); } }
public SAV_Database(Main f1) { m_parent = f1; InitializeComponent(); // Preset Filters to only show PKM available for loaded save CB_FormatComparator.SelectedIndex = 3; // <= PKXBOXES = new[] { bpkx1, bpkx2, bpkx3, bpkx4, bpkx5, bpkx6, bpkx7, bpkx8, bpkx9, bpkx10, bpkx11, bpkx12, bpkx13, bpkx14, bpkx15, bpkx16, bpkx17, bpkx18, bpkx19, bpkx20, bpkx21, bpkx22, bpkx23, bpkx24, bpkx25, bpkx26, bpkx27, bpkx28, bpkx29, bpkx30, bpkx31, bpkx32, bpkx33, bpkx34, bpkx35, bpkx36, bpkx37, bpkx38, bpkx39, bpkx40, bpkx41, bpkx42, bpkx43, bpkx44, bpkx45, bpkx46, bpkx47, bpkx48, bpkx49, bpkx50, bpkx51, bpkx52, bpkx53, bpkx54, bpkx55, bpkx56, bpkx57, bpkx58, bpkx59, bpkx60, bpkx61, bpkx62, bpkx63, bpkx64, bpkx65, bpkx66, }; // Enable Scrolling when hovered over PAN_Box.MouseHover += (sender, args) => { if (ActiveForm == this) { SCR_Box.Focus(); } }; foreach (var slot in PKXBOXES) { slot.MouseEnter += (sender, args) => { if (ActiveForm == this) { SCR_Box.Focus(); } }; // Enable Click slot.MouseClick += (sender, args) => { if (ModifierKeys == Keys.Control) { clickView(sender, args); } else if (ModifierKeys == Keys.Alt) { clickDelete(sender, args); } else if (ModifierKeys == Keys.Shift) { clickSet(sender, args); } }; } Counter = L_Count.Text; Viewed = L_Viewed.Text; L_Viewed.Text = ""; // invis for now populateComboBoxes(); ContextMenuStrip mnu = new ContextMenuStrip(); ToolStripMenuItem mnuView = new ToolStripMenuItem("View"); ToolStripMenuItem mnuDelete = new ToolStripMenuItem("Delete"); // Assign event handlers mnuView.Click += clickView; mnuDelete.Click += clickDelete; // Add to main context menu mnu.Items.AddRange(new ToolStripItem[] { mnuView, mnuDelete }); // Assign to datagridview foreach (PictureBox p in PKXBOXES) { p.ContextMenuStrip = mnu; } // Load Data var dbTemp = new ConcurrentBag <PKM>(); var files = Directory.GetFiles(DatabasePath, "*", SearchOption.AllDirectories); Parallel.ForEach(files, file => { FileInfo fi = new FileInfo(file); if (!fi.Extension.Contains(".pk") || !PKX.getIsPKM(fi.Length)) { return; } var pk = PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file); if (pk != null) { dbTemp.Add(pk); } }); // Prepare Database RawDB = new List <PKM>(dbTemp.OrderBy(pk => pk.Identifier) .Concat(Main.SAV.BoxData.Where(pk => pk.Species != 0)) // Fetch from save file .Where(pk => pk.ChecksumValid && pk.Species != 0 && pk.Sanity == 0) .Distinct()); setResults(RawDB); Menu_SearchSettings.DropDown.Closing += (sender, e) => { if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked) { e.Cancel = true; } }; CenterToParent(); }