private void ViewGiftData(DataMysteryGift g) { try { // only check if the form is visible (not opening) if (Visible && g.GiftUsed && DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgMsyteryGiftUsedAlert, MsgMysteryGiftUsedFix)) { g.GiftUsed = false; } RTB.Lines = g.GetDescription().ToArray(); PB_Preview.Image = g.Sprite(); mg = g; } // Some user input mystery gifts can have out-of-bounds values. Just swallow any exception. #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) #pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error(MsgMysteryGiftParseTypeUnknown, e); RTB.Clear(); } }
private void B_Delete_Click(object sender, EventArgs e) { if (LB_DataEntry.SelectedIndex < 1) { WinFormsUtil.Alert("Cannot delete your first Hall of Fame Clear entry."); return; } int index = LB_DataEntry.SelectedIndex; if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Delete Entry {index} from your records?") != DialogResult.Yes) { return; } 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); }
private static bool GetModifySettings(InventoryPouch pouch, out bool truncate, out bool shuffle) { truncate = false; shuffle = false; if (!pouch.IsCramped) { return(true); } var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgItemPouchSizeSmall, string.Format(MsgItemPouchRandom, Environment.NewLine)); if (dr == DialogResult.Cancel) { return(false); } truncate = true; if (dr == DialogResult.No) { shuffle = true; } return(true); }
private static void DeleteSettings() { try { var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Resetting settings requires the program to exit.", MessageStrings.MsgContinue); if (dr != DialogResult.Yes) { return; } var path = Main.ConfigPath; if (File.Exists(path)) { File.Delete(path); } System.Diagnostics.Process.Start(Application.ExecutablePath); Environment.Exit(0); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) #pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error("Failed to delete settings.", ex.Message); } }
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { bool cp = keyData == (Keys.Control | Keys.C) && ActiveControl is DataGridView; if (!cp) { return(base.ProcessCmdKey(ref msg, keyData)); } string data = dgData.GetClipboardContent().GetText(); var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgReportExportTable); if (dr != DialogResult.Yes) { WinFormsUtil.SetClipboardText(data); return(true); } // Reformat datagrid clipboard content string[] lines = data.Split(new[] { Environment.NewLine }, StringSplitOptions.None); string[] newlines = ConvertTabbedToRedditTable(lines); WinFormsUtil.SetClipboardText(string.Join(Environment.NewLine, newlines)); return(true); }
private void Menu_DeleteClones_Click(object sender, EventArgs e) { var dr = WinFormsUtil.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, StringComparison.Ordinal)) .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 { WinFormsUtil.Error("Unable to delete clone:" + Environment.NewLine + pk.Identifier); } } if (deleted == 0) { WinFormsUtil.Alert("No clones detected or deleted."); return; } WinFormsUtil.Alert($"{deleted} files deleted.", "The form will now close."); Close(); }
private void DiffSaves() { var diff = new EventBlockDiff(TB_OldSAV.Text, TB_NewSAV.Text); if (!string.IsNullOrWhiteSpace(diff.Message)) { WinFormsUtil.Alert(diff.Message); return; } TB_IsSet.Text = string.Join(", ", diff.SetFlags.Select(z => $"{z:0000}")); TB_UnSet.Text = string.Join(", ", diff.ClearedFlags.Select(z => $"{z:0000}")); if (diff.WorkDiff.Count == 0) { WinFormsUtil.Alert("No Event Constant diff found."); return; } if (DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?")) { Clipboard.SetText(string.Join(Environment.NewLine, diff.WorkDiff)); } }
private void save() { SAV.Game = (byte)(CB_Game.SelectedIndex + 30); SAV.Gender = (byte)CB_Gender.SelectedIndex; SAV.TID = (ushort)Util.ToUInt32(MT_TID.Text); SAV.SID = (ushort)Util.ToUInt32(MT_SID.Text); SAV.Money = Util.ToUInt32(MT_Money.Text); SAV.SubRegion = WinFormsUtil.getIndex(CB_Region); SAV.Country = WinFormsUtil.getIndex(CB_Country); SAV.ConsoleRegion = WinFormsUtil.getIndex(CB_3DSReg); SAV.Language = WinFormsUtil.getIndex(CB_Language); SAV.AlolaTime = (ulong)WinFormsUtil.getIndex(CB_AlolaTime); SAV.OT = TB_OTName.Text; // Copy Position if (GB_Map.Enabled && MapUpdated) { SAV.M = (int)NUD_M.Value; SAV.X = (float)NUD_X.Value; SAV.Z = (float)NUD_Z.Value; SAV.Y = (float)NUD_Y.Value; SAV.R = (float)NUD_R.Value; } // Save PlayTime SAV.PlayedHours = ushort.Parse(MT_Hours.Text); SAV.PlayedMinutes = ushort.Parse(MT_Minutes.Text) % 60; SAV.PlayedSeconds = ushort.Parse(MT_Seconds.Text) % 60; int seconds = (int)(CAL_AdventureStartDate.Value - new DateTime(2000, 1, 1)).TotalSeconds; seconds -= seconds % 86400; seconds += (int)(CAL_AdventureStartTime.Value - new DateTime(2000, 1, 1)).TotalSeconds; SAV.SecondsToStart = seconds; int fame = (int)(CAL_HoFDate.Value - new DateTime(2000, 1, 1)).TotalSeconds; fame -= fame % 86400; fame += (int)(CAL_HoFTime.Value - new DateTime(2000, 1, 1)).TotalSeconds; SAV.SecondsToFame = fame; if (SAV.LastSavedDate.HasValue) { SAV.LastSavedDate = new DateTime(CAL_LastSavedDate.Value.Year, CAL_LastSavedDate.Value.Month, CAL_LastSavedDate.Value.Day, CAL_LastSavedTime.Value.Hour, CAL_LastSavedTime.Value.Minute, 0); } SAV.BP = (uint)NUD_BP.Value; SAV.FestaCoins = (uint)NUD_FC.Value; // Poké Finder SAV.PokeFinderSnapCount = (uint)NUD_SnapCount.Value; SAV.PokeFinderThumbsTotalValue = (uint)NUD_ThumbsTotal.Value; SAV.PokeFinderThumbsHighValue = (uint)NUD_ThumbsRecord.Value; SAV.PokeFinderCameraVersion = (ushort)CB_CameraVersion.SelectedIndex; SAV.PokeFinderGyroFlag = CHK_Gyro.Checked; // Battle Tree SAV.setTreeStreak((int)NUD_RCStreak0.Value, 0, super: false, max: false); SAV.setTreeStreak((int)NUD_RCStreak1.Value, 1, super: false, max: false); SAV.setTreeStreak((int)NUD_RCStreak2.Value, 2, super: false, max: false); SAV.setTreeStreak((int)NUD_RMStreak0.Value, 0, super: false, max: true); SAV.setTreeStreak((int)NUD_RMStreak1.Value, 1, super: false, max: true); SAV.setTreeStreak((int)NUD_RMStreak2.Value, 2, super: false, max: true); SAV.setTreeStreak((int)NUD_SCStreak0.Value, 0, super: true, max: false); SAV.setTreeStreak((int)NUD_SCStreak1.Value, 1, super: true, max: false); SAV.setTreeStreak((int)NUD_SCStreak2.Value, 2, super: true, max: false); SAV.setTreeStreak((int)NUD_SMStreak0.Value, 0, super: true, max: true); SAV.setTreeStreak((int)NUD_SMStreak1.Value, 1, super: true, max: true); SAV.setTreeStreak((int)NUD_SMStreak2.Value, 2, super: true, max: true); // Skin changed && (gender matches || override) int gender = CB_Gender.SelectedIndex & 1; int skin = CB_SkinColor.SelectedIndex & 1; string gStr = CB_Gender.Items[gender].ToString(); string sStr = CB_Gender.Items[skin].ToString(); if (SAV.DressUpSkinColor != CB_SkinColor.SelectedIndex && (SAV.Gender == skin || DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Gender-Skin mismatch:\nGender: {gStr}, Skin: {sStr}", "Save selected Skin Color?"))) { SAV.DressUpSkinColor = CB_SkinColor.SelectedIndex; } SAV.FestivalPlazaName = TB_PlazaName.Text; // Vivillon if (CB_Vivillon.SelectedIndex >= 0) { SAV.Vivillon = CB_Vivillon.SelectedIndex; } SAV.DaysFromRefreshed = (byte)NUD_DaysFromRefreshed.Value; }
private void DiffSaves() { if (!File.Exists(TB_OldSAV.Text)) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 1)); return; } if (!File.Exists(TB_NewSAV.Text)) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 2)); return; } if (new FileInfo(TB_OldSAV.Text).Length > 0x100000) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 1)); return; } if (new FileInfo(TB_NewSAV.Text).Length > 0x100000) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 2)); return; } var s1 = SaveUtil.GetVariantSAV(TB_OldSAV.Text); var s2 = SaveUtil.GetVariantSAV(TB_NewSAV.Text); if (s1 == null) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 1)); return; } if (s2 == null) { WinFormsUtil.Alert(string.Format(MsgSaveNumberInvalid, 2)); return; } if (s1.GetType() != s2.GetType()) { WinFormsUtil.Alert(MsgSaveDifferentTypes, $"S1: {s1.GetType().Name}", $"S2: {s2.GetType().Name}"); return; } if (s1.Version != s2.Version) { WinFormsUtil.Alert(MsgSaveDifferentVersions, $"S1: {s1.Version}", $"S2: {s2.Version}"); return; } var tbIsSet = new List <int>(); var tbUnSet = new List <int>(); var result = new List <string>(); bool[] oldBits = s1.EventFlags; bool[] newBits = s2.EventFlags; var oldConst = s1.EventConsts; var newConst = s2.EventConsts; for (int i = 0; i < oldBits.Length; i++) { if (oldBits[i] != newBits[i]) { (newBits[i] ? tbIsSet : tbUnSet).Add(i); } } TB_IsSet.Text = string.Join(", ", tbIsSet.Select(z => $"{z:0000}")); TB_UnSet.Text = string.Join(", ", tbUnSet.Select(z => $"{z:0000}")); for (int i = 0; i < newConst.Length; i++) { if (oldConst[i] != newConst[i]) { result.Add($"{i}: {oldConst[i]}->{newConst[i]}"); } } if (result.Count == 0) { WinFormsUtil.Alert("No Event Constant diff found."); return; } if (DialogResult.Yes == WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?")) { Clipboard.SetText(string.Join(Environment.NewLine, result)); } }
private void Main_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); LoadSAV(WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "FlagDiff Researcher:", "Yes: Old Save" + Environment.NewLine + "No: New Save") == DialogResult.Yes ? B_LoadOld : B_LoadNew, files[0]); }
private void DiffSaves() { if (!File.Exists(TB_OldSAV.Text)) { WinFormsUtil.Alert("Save 1 path invalid."); return; } if (!File.Exists(TB_NewSAV.Text)) { WinFormsUtil.Alert("Save 2 path invalid."); return; } if (new FileInfo(TB_OldSAV.Text).Length > 0x100000) { WinFormsUtil.Alert("Save 1 file invalid."); return; } if (new FileInfo(TB_NewSAV.Text).Length > 0x100000) { WinFormsUtil.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 == null) { WinFormsUtil.Alert("Save 1 file invalid."); return; } if (s2 == null) { WinFormsUtil.Alert("Save 2 file invalid."); return; } if (s1.GetType() != s2.GetType()) { WinFormsUtil.Alert("Save types are different.", $"S1: {s1.GetType().Name}", $"S2: {s2.GetType().Name}"); return; } if (s1.Version != s2.Version) { WinFormsUtil.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) { WinFormsUtil.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:0000},"; } else { tbUnSet += $"{i:0000},"; } } } catch (Exception e) { WinFormsUtil.Error("An unexpected error has occurred.", e); Debug.WriteLine(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) { WinFormsUtil.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) { WinFormsUtil.Error("An unexpected error has occurred.", e); Debug.WriteLine(e); } if (string.IsNullOrEmpty(r)) { WinFormsUtil.Alert("No Event Constant diff found."); return; } if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?")) { return; } Clipboard.SetText(r); }
private void runBackgroundWorker() { var Filters = getFilters().ToList(); if (Filters.Any(z => string.IsNullOrWhiteSpace(z.PropertyValue))) { WinFormsUtil.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 != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Empty Property Value{(emptyVal.Length > 1 ? "s" : "")} detected:" + Environment.NewLine + props, "Continue?")) { return; } } string destPath = ""; if (RB_Path.Checked) { WinFormsUtil.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."; } WinFormsUtil.Alert(result); FLP_RB.Enabled = RTB_Instructions.Enabled = B_Go.Enabled = true; setupProgressBar(0); }; b.RunWorkerAsync(); }
private void GiveAllItems(object sender, EventArgs e) { // Get Current Pouch int pouch = CurrentPouch; if (pouch < 0) { return; } var p = Pouches[pouch]; ushort[] legalitems = (ushort[])p.LegalItems.Clone(); bool resize = legalitems.Length > p.Items.Length; if (resize) { var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, MsgItemPouchSizeSmall, string.Format(MsgItemPouchRandom, Environment.NewLine)); if (dr == DialogResult.Cancel) { return; } if (dr == DialogResult.No) { Util.Shuffle(legalitems); } Array.Resize(ref legalitems, p.Items.Length); } DataGridView dgv = Controls.Find(DGVPrefix + p.Type, true).FirstOrDefault() as DataGridView; SetBag(dgv, p); int Count = (int)NUD_Count.Value; for (int i = 0; i < legalitems.Length; i++) { ushort item = legalitems[i]; var itemname = itemlist[item]; int c = Count; // Override for HMs if (IsItemCount1(item, SAV)) { c = 1; } int l = 0; dgv.Rows[i].Cells[l++].Value = itemname; dgv.Rows[i].Cells[l++].Value = c; var t = Array.Find(p.Items, m => m.Index == item); if (HasFreeSpace) { dgv.Rows[i].Cells[l++].Value = t?.FreeSpace ?? false; } if (HasNew) { dgv.Rows[i].Cells[l].Value = t?.New ?? CHK_NEW.Checked; } } System.Media.SystemSounds.Asterisk.Play(); }
private void ClickShowdownImportPKMModded(object sender, EventArgs e) { if (!showdownData() || (ModifierKeys & Keys.Shift) == Keys.Shift) { if (WinFormsUtil.OpenSAVPKMDialog(new string[] { "txt" }, out string path)) { Clipboard.SetText(File.ReadAllText(path).TrimEnd()); if (!showdownData()) { WinFormsUtil.Alert("Text file with invalid data provided. Please provide a text file with proper Showdown data"); return; } } else { WinFormsUtil.Alert("No data provided."); return; } } if (!Directory.Exists(MGDatabasePath)) { Directory.CreateDirectory(MGDatabasePath); } string[] tdataVals = PKME_Tabs.parseTrainerData(C_SAV); int TID = Convert.ToInt32(tdataVals[0]); int SID = Convert.ToInt32(tdataVals[1]); string OT = tdataVals[2]; if (OT == "PKHeX") { OT = "Archit(TCD)"; // Avoids secondary handler error } int gender = 0; if (tdataVals[3] == "F" || tdataVals[3] == "Female") { gender = 1; } string Country = tdataVals[4]; string SubRegion = tdataVals[5]; string ConsoleRegion = tdataVals[6]; string source = Clipboard.GetText().TrimEnd(); string[] stringSeparators = new string[] { "\n\r" }; string[] result; // ... result = source.Split(stringSeparators, StringSplitOptions.None); Console.WriteLine(result.Length); if (result.Length > 1) { List <int> emptySlots = new List <int> { }; if ((ModifierKeys & Keys.Control) == Keys.Control) // Hold Ctrl while clicking to replace { for (int i = 0; i < result.Length; i++) { emptySlots.Add(i); } } else { for (int i = 0; i < C_SAV.Box.BoxSlotCount; i++) { if ((C_SAV.Box.SlotPictureBoxes[i] as PictureBox)?.Image == null) { emptySlots.Add(i); } } if (emptySlots.Count < result.Length) { WinFormsUtil.Alert("Not enough space in the box"); return; } } for (int i = 0; i < result.Length; i++) { ShowdownSet Set = new ShowdownSet(result[i]); if (Set.InvalidLines.Any()) { WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines)); } // Set Species & Nickname bool resetForm = false; PKME_Tabs.hardReset(C_SAV.SAV); if (Set.Form == null) { } else if (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted") { resetForm = true; Console.WriteLine(Set.Species); } PKME_Tabs.LoadShowdownSet(Set); PKM p = PreparePKM(); p.Version = (int)GameVersion.MN; Blah b = new Blah(); b.C_SAV = C_SAV; PKM legal = b.LoadShowdownSetModded_PKSM(p, Set, resetForm, TID, SID, OT, gender); if (int.TryParse(Country, out int n) && int.TryParse(SubRegion, out int m) && int.TryParse(ConsoleRegion, out int o)) { legal = PKME_Tabs.SetPKMRegions(n, m, o, legal); Country = ""; SubRegion = ""; ConsoleRegion = ""; } PKME_Tabs.PopulateFields(legal); if (Country != "" && SubRegion != "" && ConsoleRegion != "") { PKME_Tabs.SetRegions(Country, SubRegion, ConsoleRegion); } PKM pk = PreparePKM(); PKME_Tabs.ClickSet(C_SAV.Box.SlotPictureBoxes[0], emptySlots[i]); } } else { // Get Simulator Data ShowdownSet Set = new ShowdownSet(Clipboard.GetText()); if (Set.Species < 0) { WinFormsUtil.Alert("Set data not found in clipboard."); return; } if (Set.Nickname?.Length > C_SAV.SAV.NickLength) { Set.Nickname = Set.Nickname.Substring(0, C_SAV.SAV.NickLength); } if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.Text)) { return; } if (Set.InvalidLines.Any()) { WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines)); } // Set Species & Nickname //PKME_Tabs.LoadShowdownSet(Set); bool resetForm = false; PKME_Tabs.hardReset(C_SAV.SAV); if (Set.Form == null) { } else if (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted") { Set = new ShowdownSet(Set.Text.Replace("-" + Set.Form, "")); resetForm = true; Console.WriteLine(Set.Species); } PKME_Tabs.LoadShowdownSet(Set); PKM p = PreparePKM(); p.Version = (int)GameVersion.MN; Blah b = new Blah(); b.C_SAV = C_SAV; PKM legal = b.LoadShowdownSetModded_PKSM(p, Set, resetForm, TID, SID, OT, gender); if (int.TryParse(Country, out int n) && int.TryParse(SubRegion, out int m) && int.TryParse(ConsoleRegion, out int o)) { legal = PKME_Tabs.SetPKMRegions(n, m, o, legal); Country = ""; SubRegion = ""; ConsoleRegion = ""; } PKME_Tabs.PopulateFields(legal); if (legal.Format < 7) { PKME_Tabs.LoadFieldsFromPKM2(legal, true, false); } if (Country != "" && SubRegion != "" && ConsoleRegion != "") { PKME_Tabs.SetRegions(Country, SubRegion, ConsoleRegion); } } }
private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) { DragInfo.Destination.Parent = this; DragInfo.Destination.Slot = getSlot(sender); DragInfo.Destination.Offset = getPKXOffset(DragInfo.Destination.Slot); DragInfo.Destination.Box = 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.Destination.Box, DragInfo.Destination.Slot)) { DragInfo.Destination.Slot = -1; // Invalidate WinFormsUtil.Alert("Unable to set to locked slot."); return; } if (DragInfo.Source.Offset < 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, prefer: SAV.Generation); string c; PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c); if (pk == null) { WinFormsUtil.Error(c); Console.WriteLine(c); return; } string[] errata = SAV.IsPKMCompatible(pk); if (errata.Length > 0) { string concat = string.Join(Environment.NewLine, errata); if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, concat, "Continue?")) { Console.WriteLine(c); Console.WriteLine(concat); return; } } DragInfo.SetPKM(pk, false); getQuickFiller(SlotPictureBoxes[DragInfo.Destination.Slot], pk); Console.WriteLine(c); } else { PKM pkz = DragInfo.GetPKM(true); if (!DragInfo.Source.IsValid) { } // not overwritable, do nothing else if (ModifierKeys == Keys.Alt && DragInfo.Destination.IsValid) // overwrite { // Clear from slot if (DragInfo.SameBox) { getQuickFiller(SlotPictureBoxes[DragInfo.Source.Slot], SAV.BlankPKM); // picturebox } DragInfo.SetPKM(SAV.BlankPKM, true); } else if (ModifierKeys != Keys.Control && DragInfo.Destination.IsValid) // move { // Load data from destination PKM pk = ((PictureBox)sender).Image != null ? DragInfo.GetPKM(false) : SAV.BlankPKM; // Set destination pokemon image to source picture box if (DragInfo.SameBox) { getQuickFiller(SlotPictureBoxes[DragInfo.Source.Slot], pk); } // Set destination pokemon data to source slot DragInfo.SetPKM(pk, true); } else if (DragInfo.SameBox) // clone { getQuickFiller(SlotPictureBoxes[DragInfo.Source.Slot], pkz); } // Copy from temp to destination slot. DragInfo.SetPKM(pkz, false); getQuickFiller(SlotPictureBoxes[DragInfo.Destination.Slot], pkz); e.Effect = DragDropEffects.Link; Cursor = DefaultCursor; } if (DragInfo.Source.IsParty || DragInfo.Destination.IsParty) { parent.setParty(); } if (DragInfo.Source.Parent == null) // another instance or file { parent.notifyBoxViewerRefresh(); DragInfo.Reset(); } }
private void B_GetTickets_Click(object sender, EventArgs e) { var Pouches = SAV.Inventory; var itemlist = GameInfo.Strings.GetItemStrings(SAV.Generation, SAV.Version).ToArray(); for (int i = 0; i < itemlist.Length; i++) { if (string.IsNullOrEmpty(itemlist[i])) { itemlist[i] = $"(Item #{i:000})"; } } const int oldsea = 0x178; int[] tickets = { 0x109, 0x113, 0x172, 0x173, oldsea }; // item IDs if (!SAV.Japanese && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Non Japanese save file. Add {itemlist[oldsea]} (unreleased)?")) { tickets = tickets.Take(tickets.Length - 1).ToArray(); // remove old sea map } var p = Array.Find(Pouches, z => z.Type == InventoryType.KeyItems); if (p == null) { return; } // check for missing tickets var missing = tickets.Where(z => !p.Items.Any(item => item.Index == z && item.Count == 1)).ToList(); var have = tickets.Except(missing).ToList(); if (missing.Count == 0) { WinFormsUtil.Alert("Already have all tickets."); B_GetTickets.Enabled = false; return; } // check for space int end = Array.FindIndex(p.Items, z => z.Index == 0); if (end + missing.Count >= p.Items.Length) { WinFormsUtil.Alert("Not enough space in pouch.", "Please use the InventoryEditor."); B_GetTickets.Enabled = false; return; } var added = string.Join(", ", missing.Select(u => itemlist[u])); var addmsg = $"Add the following items?{Environment.NewLine}{added}"; if (have.Count > 0) { string had = string.Join(", ", have.Select(u => itemlist[u])); var havemsg = $"Already have:{Environment.NewLine}{had}"; addmsg += Environment.NewLine + Environment.NewLine + havemsg; } if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, addmsg)) { return; } // insert items at the end for (int i = 0; i < missing.Count; i++) { var item = p.Items[end + i]; item.Index = missing[i]; item.Count = 1; } string alert = $"Inserted the following items to the Key Items Pouch:{Environment.NewLine}{added}"; WinFormsUtil.Alert(alert); SAV.Inventory = Pouches; B_GetTickets.Enabled = false; }
private void ClickShowdownImportPKMModded(object sender, EventArgs e) { if (!Clipboard.ContainsText()) { WinFormsUtil.Alert("Clipboard does not contain text."); return; } if (!Directory.Exists(MGDatabasePath)) { Directory.CreateDirectory(MGDatabasePath); } int TID = -1; int SID = -1; string OT = ""; int gender = 0; string Country = ""; string SubRegion = ""; string ConsoleRegion = ""; if (File.Exists(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\trainerdata.txt")) { string text = File.ReadAllText(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\trainerdata.txt", System.Text.Encoding.UTF8); string[] lines = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); TID = Convert.ToInt32(lines[0].Split(':')[1].Trim()); SID = Convert.ToInt32(lines[1].Split(':')[1].Trim()); OT = lines[2].Split(':')[1].Trim(); if (lines[3].Split(':')[1].Trim() == "F" || lines[3].Split(':')[1].Trim() == "Female") { gender = 1; } try { Country = lines[4].Split(':')[1].Trim(); SubRegion = lines[5].Split(':')[1].Trim(); ConsoleRegion = lines[6].Split(':')[1].Trim(); } catch { } } string source = Clipboard.GetText().TrimEnd(); string[] stringSeparators = new string[] { "\n\r" }; string[] result; // ... result = source.Split(stringSeparators, StringSplitOptions.None); Console.WriteLine(result.Length); if (result.Length > 1) { for (int i = 0; i < result.Length; i++) { ShowdownSet Set = new ShowdownSet(result[i]); if (Set.InvalidLines.Any()) { WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines)); } // Set Species & Nickname bool resetForm = false; PKME_Tabs.hardReset(); if (Set.Form == null) { } else if (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted") { resetForm = true; Console.WriteLine(Set.Species); } PKME_Tabs.LoadShowdownSet(Set); PKM p = PreparePKM(); p.Version = (int)GameVersion.MN; Blah b = new Blah(); PKM legal = b.LoadShowdownSetModded_PKSM(p, Set, resetForm, TID, SID, OT, gender); PKME_Tabs.PopulateFields(legal); if (Country != "" && SubRegion != "" && ConsoleRegion != "") { PKME_Tabs.SetRegions(Country, SubRegion, ConsoleRegion); } PKM pk = PreparePKM(); PKME_Tabs.ClickSet(C_SAV.Box.SlotPictureBoxes[0], i); } } else { // Get Simulator Data ShowdownSet Set = new ShowdownSet(Clipboard.GetText()); if (Set.Species < 0) { WinFormsUtil.Alert("Set data not found in clipboard."); return; } if (Set.Nickname?.Length > C_SAV.SAV.NickLength) { Set.Nickname = Set.Nickname.Substring(0, C_SAV.SAV.NickLength); } if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Import this set?", Set.Text)) { return; } if (Set.InvalidLines.Any()) { WinFormsUtil.Alert("Invalid lines detected:", string.Join(Environment.NewLine, Set.InvalidLines)); } // Set Species & Nickname //PKME_Tabs.LoadShowdownSet(Set); bool resetForm = false; PKME_Tabs.hardReset(); if (Set.Form == null) { } else if (Set.Form.Contains("Mega") || Set.Form == "Primal" || Set.Form == "Busted") { resetForm = true; Console.WriteLine(Set.Species); } PKME_Tabs.LoadShowdownSet(Set); PKM p = PreparePKM(); p.Version = (int)GameVersion.MN; Blah b = new Blah(); PKM legal = b.LoadShowdownSetModded_PKSM(p, Set, resetForm, TID, SID, OT, gender); PKME_Tabs.PopulateFields(legal); if (Country != "" && SubRegion != "" && ConsoleRegion != "") { PKME_Tabs.SetRegions(Country, SubRegion, ConsoleRegion); } } }