diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 0d6619f45..2a584773a 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -129,14 +129,13 @@ public Main() #region Global Variables: Always Visible! public static readonly byte[] blankEK6 = PKX.encryptArray(new byte[PK6.SIZE_PARTY]); public static PK6 pk6 = new PK6(); // Tab Pokemon Data Storage - public static SAV6 SAV = new SAV6(); + public static SAV6 SAV = new SAV6(); // Save File public static byte[] originalSAV; // original save for CyberGadget Codes public static string pathSDF; public static string path3DS; public static volatile bool formInitialized, fieldsInitialized; public static bool HaX; - public static bool specialChars; // Open Form Tracking public static Color defaultControlWhite; public static Color defaultControlText; public static int colorizedbox = 32; @@ -145,6 +144,7 @@ public Main() public static int colorizedslot; public static string eggname = ""; public static string DatabasePath = "db"; + public static string BackupPath = "bak"; public static string[] lang_val = { "en", "ja", "fr", "it", "de", "es", "ko", "zh", "pt" }; public static string[] main_langlist = { @@ -605,7 +605,7 @@ private void openFile(byte[] input, string path, string ext) else if ((input.Length == PK6.SIZE_PARTY || input.Length == PK6.SIZE_STORED) && ext != ".pgt") { // Check if Input is PKX - if ((ext == ".pk6") || (ext == ".ek6") || (ext == ".pkx") || (ext == ".ekx") || (ext == ".bin") || (ext == "")) + if (new[] {".pk6", ".ek6", ".pkx", ".ekx", ""}.Contains(ext)) { // Check if Encrypted before Loading populateFields(new PK6(BitConverter.ToUInt16(input, 0xC8) == 0 && BitConverter.ToUInt16(input, 0x58) == 0 ? input : PKX.decryptArray(input))); @@ -1376,14 +1376,12 @@ private void clickEV(object sender, EventArgs e) } private void clickOT(object sender, EventArgs e) { - string OT = SAV.OT; - if (OT.Length <= 0) return; - - TB_OT.Text = OT; - // Set Gender Label - Label_OTGender.Text = SAV.Gender == 1 ? gendersymbols[1] : gendersymbols[0]; + if (!SAV.Exportable) + return; // Get Save Information + TB_OT.Text = SAV.OT; + Label_OTGender.Text = gendersymbols[SAV.Gender % 2]; TB_TID.Text = SAV.TID.ToString(); TB_SID.Text = SAV.SID.ToString(); CB_GameOrigin.SelectedValue = SAV.Game; @@ -1396,7 +1394,7 @@ private void clickOT(object sender, EventArgs e) private void clickCT(object sender, EventArgs e) { if (TB_OTt2.Text.Length > 0) - Label_CTGender.Text = gendersymbols[SAV.Gender]; + Label_CTGender.Text = gendersymbols[SAV.Gender % 2]; } private void clickGT(object sender, EventArgs e) { @@ -1441,7 +1439,7 @@ private void updateEXPLevel(object sender, EventArgs e) { if (changingFields) return; - if (sender as MaskedTextBox == TB_EXP) + if (sender == TB_EXP) { changingFields = true; // Change the Level @@ -1901,7 +1899,7 @@ private void updateExtraByteIndex(object sender, EventArgs e) } private void updateNatureModification(object sender, EventArgs e) { - if (sender is ComboBox && (sender as ComboBox).Name != CB_Nature.Name) return; + if (sender != CB_Nature) return; int nature = Util.getIndex(CB_Nature); int incr = nature / 5; int decr = nature % 5; @@ -1947,8 +1945,12 @@ private void updateNicknameClick(object sender, MouseEventArgs e) { TextBox tb = !(sender is TextBox) ? TB_Nickname : sender as TextBox; // Special Character Form - if (ModifierKeys == Keys.Control && !specialChars) - new f2_Text(tb).Show(); + if (ModifierKeys != Keys.Control) + return; + + if (Application.OpenForms.Cast
().Any(form => form.Name == typeof(f2_Text).Name)) + { Util.Alert("Window is already open."); return; } + new f2_Text(tb).Show(); } private void updateNotOT(object sender, EventArgs e) { @@ -2786,32 +2788,29 @@ private void setParty() } private int getPKXOffset(int slot) { - int offset = SAV.Box + (30 * CB_BoxSelect.SelectedIndex + slot) * PK6.SIZE_STORED; - - if (slot > 29) // Not a party - { - if (slot < 36) // Party Slot - offset = SAV.Party + (slot - 30) * PK6.SIZE_PARTY; - else if (slot < 42) // Battle Box Slot - offset = SAV.BattleBox + (slot - 36) * PK6.SIZE_STORED; - else if (slot < 44) // Daycare - offset = SAV.DaycareSlot[DaycareSlot] + 8 + (slot - 42) * (PK6.SIZE_STORED + 8); - else if (slot < 45) // GTS - offset = SAV.GTS; - else if (slot < 46) // Fused - offset = SAV.Fused; - else // SUBE - offset = SAV.SUBE + (slot - 46) * (PK6.SIZE_STORED + 4); - } - return offset; + if (slot < 30) // Box Slot + return SAV.Box + (30 * CB_BoxSelect.SelectedIndex + slot) * PK6.SIZE_STORED; + if (slot < 36) // Party Slot + return SAV.Party + (slot - 30) * PK6.SIZE_PARTY; + if (slot < 42) // Battle Box Slot + return SAV.BattleBox + (slot - 36) * PK6.SIZE_STORED; + if (slot < 44) // Daycare + return SAV.DaycareSlot[DaycareSlot] + 8 + (slot - 42) * (PK6.SIZE_STORED + 8); + if (slot < 45) // GTS + return SAV.GTS; + if (slot < 46) // Fused + return SAV.Fused; + if (slot < 50) // SUBE + return SAV.SUBE + (slot - 46) * (PK6.SIZE_STORED + 4); + return -1; } private int getSlot(object sender) { - string name = sender is ToolStripItem - ? ((sender as ToolStripItem).Owner as ContextMenuStrip).SourceControl.Name - : (sender as PictureBox).Name; + sender = sender is ToolStripItem + ? ((sender as ToolStripItem).Owner as ContextMenuStrip).SourceControl + : sender as PictureBox; - return Array.FindIndex(SlotPictureBoxes, p => p.Name == name); + return Array.IndexOf(SlotPictureBoxes, sender); } public void setPKXBoxes() { @@ -2936,7 +2935,7 @@ private void getSlotColor(int slot, Image color) foreach (PictureBox t in SlotPictureBoxes) t.BackgroundImage = null; - if (slot < 32) + if (slot < 30) colorizedbox = CB_BoxSelect.SelectedIndex; SlotPictureBoxes[slot].BackgroundImage = color; @@ -3004,10 +3003,7 @@ private void loadBoxesFromDB(string path) if (len > PK6.SIZE_PARTY) continue; - if ( - len != PK6.SIZE_STORED && len != PK6.SIZE_PARTY // 6th Gen - && len != 136 && len != 220 && len != 236 // 5th Gen - && len != 100 && len != 80) // 4th Gen + if (!new[] {PK6.SIZE_STORED, PK6.SIZE_PARTY, PK5.SIZE_STORED, PK5.SIZE_PARTY, PK4.SIZE_PARTY, PK3.SIZE_STORED, PK3.SIZE_PARTY}.Contains((int)len)) continue; byte[] data = new byte[PK6.SIZE_STORED]; switch (Path.GetExtension(t)) // Filter all files by extension @@ -3076,7 +3072,7 @@ private void loadBoxesFromDB(string path) } private void B_SaveBoxBin_Click(object sender, EventArgs e) { - DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Yes: Export All Boxes" + Environment.NewLine + String.Format("No: Export {1} (Box {0})", CB_BoxSelect.SelectedIndex + 1, CB_BoxSelect.Text) + Environment.NewLine + "Cancel: Abort"); + DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Yes: Export All Boxes" + Environment.NewLine + string.Format("No: Export {1} (Box {0})", CB_BoxSelect.SelectedIndex + 1, CB_BoxSelect.Text) + Environment.NewLine + "Cancel: Abort"); if (dr == DialogResult.Yes) { @@ -3345,7 +3341,7 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) FileInfo fi = new FileInfo(files[0]); // Detect if PKM/PKX - if ((fi.Length == 136) || (fi.Length == 220) || (fi.Length == 236) || (fi.Length == 100) || (fi.Length == 80)) + if (new[] { PK3.SIZE_PARTY, PK3.SIZE_STORED, PK4.SIZE_PARTY, PK4.SIZE_STORED, PK5.SIZE_PARTY }.Contains((int)fi.Length)) { byte[] input = File.ReadAllBytes(files[0]); if (!PKX.verifychk(input)) Util.Alert("Invalid File Loaded.", "Checksum is not valid."); diff --git a/PKX/f2-Text.Designer.cs b/PKX/f2-Text.Designer.cs index 08db5d2f8..e672ec3b4 100644 --- a/PKX/f2-Text.Designer.cs +++ b/PKX/f2-Text.Designer.cs @@ -395,7 +395,6 @@ private void InitializeComponent() this.Name = "f2_Text"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Special Characters"; - this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.onClosed); this.ResumeLayout(false); this.PerformLayout(); diff --git a/PKX/f2-Text.cs b/PKX/f2-Text.cs index a63f0e90a..145bb7ca1 100644 --- a/PKX/f2-Text.cs +++ b/PKX/f2-Text.cs @@ -8,7 +8,6 @@ public partial class f2_Text : Form { public f2_Text(TextBox TB_NN) { - Main.specialChars = true; Hide(); InitializeComponent(); Util.TranslateInterface(this, Main.curlanguage); @@ -45,9 +44,5 @@ private void onClick(object sender, EventArgs e) if (nickname.Length < TB_Nickname.MaxLength) TB_Nickname.Text += (sender as Label).Text; } - private void onClosed(object sender, FormClosedEventArgs e) - { - Main.specialChars = false; - } } } diff --git a/SAV/SAV_HallOfFame.cs b/SAV/SAV_HallOfFame.cs index b5b099ba1..d40ac6810 100644 --- a/SAV/SAV_HallOfFame.cs +++ b/SAV/SAV_HallOfFame.cs @@ -1,5 +1,6 @@ using System; using System.Drawing; +using System.Linq; using System.Text; using System.Windows.Forms; @@ -439,8 +440,12 @@ private void changeNickname(object sender, MouseEventArgs e) { TextBox tb = !(sender is TextBox) ? TB_Nickname : sender as TextBox; // Special Character Form - if (ModifierKeys == Keys.Control && !Main.specialChars) - new f2_Text(tb).Show(); + if (ModifierKeys != Keys.Control) + return; + + if (Application.OpenForms.Cast().Any(form => form.Name == typeof(f2_Text).Name)) + { Util.Alert("Window is already open."); return; } + new f2_Text(tb).Show(); } } } diff --git a/SAV/SAV_Trainer.cs b/SAV/SAV_Trainer.cs index b7e093512..f0d94652c 100644 --- a/SAV/SAV_Trainer.cs +++ b/SAV/SAV_Trainer.cs @@ -542,8 +542,12 @@ private void clickOT(object sender, MouseEventArgs e) { TextBox tb = !(sender is TextBox) ? TB_OTName : sender as TextBox; // Special Character Form - if (ModifierKeys == Keys.Control && !Main.specialChars) - new f2_Text(tb).Show(); + if (ModifierKeys != Keys.Control) + return; + + if (Application.OpenForms.Cast().Any(form => form.Name == typeof(f2_Text).Name)) + { Util.Alert("Window is already open."); return; } + new f2_Text(tb).Show(); } private void showTSV(object sender, EventArgs e) {