From 2de7da80b0986ef20db5b454404a331b17211a10 Mon Sep 17 00:00:00 2001 From: ReignOfComputer Date: Sun, 5 Feb 2017 23:23:02 +0800 Subject: [PATCH 01/18] Add Check for Bad Ability Length Prevents System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. --- PKHeX.WinForms/MainWindow/MainPK4.cs | 6 +++++- PKHeX.WinForms/MainWindow/MainPK5.cs | 7 +++++-- PKHeX.WinForms/MainWindow/MainPK6.cs | 9 +++++++-- PKHeX.WinForms/MainWindow/MainPK7.cs | 8 ++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/MainPK4.cs b/PKHeX.WinForms/MainWindow/MainPK4.cs index c222bf9f5..64121dc44 100644 --- a/PKHeX.WinForms/MainWindow/MainPK4.cs +++ b/PKHeX.WinForms/MainWindow/MainPK4.cs @@ -142,7 +142,11 @@ private PKM preparePK4() pk4.SID = Util.ToInt32(TB_SID.Text); pk4.EXP = Util.ToUInt32(TB_EXP.Text); pk4.PID = Util.getHEXval(TB_PID.Text); - pk4.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + + if (CB_Ability.Text.Length >= 4) + { + pk4.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + } pk4.FatefulEncounter = CHK_Fateful.Checked; pk4.Gender = PKX.getGender(Label_Gender.Text); diff --git a/PKHeX.WinForms/MainWindow/MainPK5.cs b/PKHeX.WinForms/MainWindow/MainPK5.cs index 92c18e5df..a36ac2ea7 100644 --- a/PKHeX.WinForms/MainWindow/MainPK5.cs +++ b/PKHeX.WinForms/MainWindow/MainPK5.cs @@ -247,8 +247,11 @@ private PKM preparePK5() } else { - pk5.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); - pk5.HiddenAbility = CB_Ability.SelectedIndex > 1; // not 0 or 1 + if (CB_Ability.Text.Length >= 4) + { + pk5.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + pk5.HiddenAbility = CB_Ability.SelectedIndex > 1; // not 0 or 1 + } } // Fix Moves if a slot is empty diff --git a/PKHeX.WinForms/MainWindow/MainPK6.cs b/PKHeX.WinForms/MainWindow/MainPK6.cs index 43a4238a5..6943d250a 100644 --- a/PKHeX.WinForms/MainWindow/MainPK6.cs +++ b/PKHeX.WinForms/MainWindow/MainPK6.cs @@ -184,8 +184,13 @@ private PKM preparePK6() pk6.TID = Util.ToInt32(TB_TID.Text); pk6.SID = Util.ToInt32(TB_SID.Text); pk6.EXP = Util.ToUInt32(TB_EXP.Text); - pk6.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); - pk6.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number + + if (CB_Ability.Text.Length >= 4) + { + pk6.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + pk6.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number + } + // pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag) pk6.PID = Util.getHEXval(TB_PID.Text); pk6.Nature = (byte)WinFormsUtil.getIndex(CB_Nature); diff --git a/PKHeX.WinForms/MainWindow/MainPK7.cs b/PKHeX.WinForms/MainWindow/MainPK7.cs index b9591eab2..56b4c727e 100644 --- a/PKHeX.WinForms/MainWindow/MainPK7.cs +++ b/PKHeX.WinForms/MainWindow/MainPK7.cs @@ -184,8 +184,12 @@ private PKM preparePK7() pk7.TID = Util.ToInt32(TB_TID.Text); pk7.SID = Util.ToInt32(TB_SID.Text); pk7.EXP = Util.ToUInt32(TB_EXP.Text); - pk7.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); - pk7.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number + + { + pk7.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); + pk7.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number + } + // pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag) pk7.PID = Util.getHEXval(TB_PID.Text); pk7.Nature = (byte)WinFormsUtil.getIndex(CB_Nature); From c7e570b92d489eec5d2885999fbb0ef248da1a50 Mon Sep 17 00:00:00 2001 From: ReignOfComputer Date: Sun, 5 Feb 2017 23:23:17 +0800 Subject: [PATCH 02/18] Add Check for Bad Ability Length 2 Forgot to save, again. --- PKHeX.WinForms/MainWindow/MainPK7.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PKHeX.WinForms/MainWindow/MainPK7.cs b/PKHeX.WinForms/MainWindow/MainPK7.cs index 56b4c727e..df8660054 100644 --- a/PKHeX.WinForms/MainWindow/MainPK7.cs +++ b/PKHeX.WinForms/MainWindow/MainPK7.cs @@ -185,6 +185,7 @@ private PKM preparePK7() pk7.SID = Util.ToInt32(TB_SID.Text); pk7.EXP = Util.ToUInt32(TB_EXP.Text); + if (CB_Ability.Text.Length >= 4) { pk7.Ability = (byte)Array.IndexOf(GameInfo.Strings.abilitylist, CB_Ability.Text.Remove(CB_Ability.Text.Length - 4)); pk7.AbilityNumber = Util.ToInt32(TB_AbilityNumber.Text); // Number From 2d0b216b339cd8ed2710d12184b63b695096662a Mon Sep 17 00:00:00 2001 From: ReignOfComputer Date: Mon, 6 Feb 2017 00:08:49 +0800 Subject: [PATCH 03/18] G7TID Generator Thought it'd be good to add a way to generate a TID/SID based on desired G7TID. Using code from my repo at https://github.com/ReignOfComputer/Reverse-G7TID-Calculator, thanks to @PP-theSLAYER and @SciresM. For your consideration to add :) --- PKHeX.WinForms/MainWindow/Main.Designer.cs | 8 +- .../Gen7/SAV_Trainer7.Designer.cs | 90 +++++++++++++------ .../Save Editors/Gen7/SAV_Trainer7.cs | 34 +++++++ 3 files changed, 102 insertions(+), 30 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.Designer.cs b/PKHeX.WinForms/MainWindow/Main.Designer.cs index 212134cb8..9c8c90021 100644 --- a/PKHeX.WinForms/MainWindow/Main.Designer.cs +++ b/PKHeX.WinForms/MainWindow/Main.Designer.cs @@ -3981,7 +3981,7 @@ public void InitializeComponent() this.CB_MainLanguage}); this.Menu_Language.Image = ((System.Drawing.Image)(resources.GetObject("Menu_Language.Image"))); this.Menu_Language.Name = "Menu_Language"; - this.Menu_Language.Size = new System.Drawing.Size(152, 22); + this.Menu_Language.Size = new System.Drawing.Size(139, 22); this.Menu_Language.Text = "Language"; // // CB_MainLanguage @@ -4001,7 +4001,7 @@ public void InitializeComponent() this.Menu_Redo}); this.Menu_Modify.Image = ((System.Drawing.Image)(resources.GetObject("Menu_Modify.Image"))); this.Menu_Modify.Name = "Menu_Modify"; - this.Menu_Modify.Size = new System.Drawing.Size(152, 22); + this.Menu_Modify.Size = new System.Drawing.Size(139, 22); this.Menu_Modify.Text = "Set to SAV"; // // Menu_ModifyDex @@ -4058,7 +4058,7 @@ public void InitializeComponent() this.Menu_Unicode.CheckOnClick = true; this.Menu_Unicode.CheckState = System.Windows.Forms.CheckState.Checked; this.Menu_Unicode.Name = "Menu_Unicode"; - this.Menu_Unicode.Size = new System.Drawing.Size(152, 22); + this.Menu_Unicode.Size = new System.Drawing.Size(139, 22); this.Menu_Unicode.Text = "Unicode"; this.Menu_Unicode.Click += new System.EventHandler(this.mainMenuUnicode); // @@ -4068,7 +4068,7 @@ public void InitializeComponent() this.Menu_About.Name = "Menu_About"; this.Menu_About.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P))); this.Menu_About.ShowShortcutKeys = false; - this.Menu_About.Size = new System.Drawing.Size(152, 22); + this.Menu_About.Size = new System.Drawing.Size(139, 22); this.Menu_About.Text = "About &PKHeX"; this.Menu_About.Click += new System.EventHandler(this.mainMenuAbout); // diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.Designer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.Designer.cs index 7450d16eb..34948d403 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.Designer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.Designer.cs @@ -157,6 +157,7 @@ private void InitializeComponent() this.NUD_RCStreak0 = new System.Windows.Forms.NumericUpDown(); this.L_CStreak0 = new System.Windows.Forms.Label(); this.Tab_Misc = new System.Windows.Forms.TabPage(); + this.CB_Fashion = new System.Windows.Forms.ComboBox(); this.L_SkinColor = new System.Windows.Forms.Label(); this.CB_SkinColor = new System.Windows.Forms.ComboBox(); this.GB_PokeFinder = new System.Windows.Forms.GroupBox(); @@ -170,7 +171,9 @@ private void InitializeComponent() this.NUD_ThumbsTotal = new System.Windows.Forms.NumericUpDown(); this.L_ThumbsTotal = new System.Windows.Forms.Label(); this.B_Fashion = new System.Windows.Forms.Button(); - this.CB_Fashion = new System.Windows.Forms.ComboBox(); + this.L_G7TID = new System.Windows.Forms.Label(); + this.MT_G7TID = new System.Windows.Forms.MaskedTextBox(); + this.B_GenTID = new System.Windows.Forms.Button(); this.TC_Editor.SuspendLayout(); this.Tab_Overview.SuspendLayout(); this.GB_Stats.SuspendLayout(); @@ -207,7 +210,7 @@ private void InitializeComponent() // // B_Cancel // - this.B_Cancel.Location = new System.Drawing.Point(250, 296); + this.B_Cancel.Location = new System.Drawing.Point(250, 334); this.B_Cancel.Name = "B_Cancel"; this.B_Cancel.Size = new System.Drawing.Size(75, 23); this.B_Cancel.TabIndex = 0; @@ -217,7 +220,7 @@ private void InitializeComponent() // // B_Save // - this.B_Save.Location = new System.Drawing.Point(331, 296); + this.B_Save.Location = new System.Drawing.Point(331, 334); this.B_Save.Name = "B_Save"; this.B_Save.Size = new System.Drawing.Size(75, 23); this.B_Save.TabIndex = 1; @@ -453,7 +456,7 @@ private void InitializeComponent() // // L_Language // - this.L_Language.Location = new System.Drawing.Point(14, 77); + this.L_Language.Location = new System.Drawing.Point(202, 82); this.L_Language.Name = "L_Language"; this.L_Language.Size = new System.Drawing.Size(80, 13); this.L_Language.TabIndex = 21; @@ -519,7 +522,7 @@ private void InitializeComponent() // this.CB_Language.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_Language.FormattingEnabled = true; - this.CB_Language.Location = new System.Drawing.Point(99, 73); + this.CB_Language.Location = new System.Drawing.Point(287, 79); this.CB_Language.Name = "CB_Language"; this.CB_Language.Size = new System.Drawing.Size(93, 21); this.CB_Language.TabIndex = 15; @@ -805,11 +808,14 @@ private void InitializeComponent() this.TC_Editor.Location = new System.Drawing.Point(12, 12); this.TC_Editor.Name = "TC_Editor"; this.TC_Editor.SelectedIndex = 0; - this.TC_Editor.Size = new System.Drawing.Size(394, 279); + this.TC_Editor.Size = new System.Drawing.Size(394, 316); this.TC_Editor.TabIndex = 54; // // Tab_Overview // + this.Tab_Overview.Controls.Add(this.B_GenTID); + this.Tab_Overview.Controls.Add(this.L_G7TID); + this.Tab_Overview.Controls.Add(this.MT_G7TID); this.Tab_Overview.Controls.Add(this.GB_Stats); this.Tab_Overview.Controls.Add(this.CB_AlolaTime); this.Tab_Overview.Controls.Add(this.L_AlolaTime); @@ -836,7 +842,7 @@ private void InitializeComponent() this.Tab_Overview.Location = new System.Drawing.Point(4, 22); this.Tab_Overview.Name = "Tab_Overview"; this.Tab_Overview.Padding = new System.Windows.Forms.Padding(3); - this.Tab_Overview.Size = new System.Drawing.Size(386, 253); + this.Tab_Overview.Size = new System.Drawing.Size(386, 290); this.Tab_Overview.TabIndex = 0; this.Tab_Overview.Text = "Overview"; this.Tab_Overview.UseVisualStyleBackColor = true; @@ -851,7 +857,7 @@ private void InitializeComponent() this.GB_Stats.Controls.Add(this.L_BP); this.GB_Stats.Controls.Add(this.L_Value); this.GB_Stats.Controls.Add(this.CB_Stats); - this.GB_Stats.Location = new System.Drawing.Point(212, 113); + this.GB_Stats.Location = new System.Drawing.Point(212, 130); this.GB_Stats.Name = "GB_Stats"; this.GB_Stats.Size = new System.Drawing.Size(171, 137); this.GB_Stats.TabIndex = 60; @@ -954,14 +960,14 @@ private void InitializeComponent() // this.CB_AlolaTime.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.CB_AlolaTime.FormattingEnabled = true; - this.CB_AlolaTime.Location = new System.Drawing.Point(287, 89); + this.CB_AlolaTime.Location = new System.Drawing.Point(287, 106); this.CB_AlolaTime.Name = "CB_AlolaTime"; this.CB_AlolaTime.Size = new System.Drawing.Size(93, 21); this.CB_AlolaTime.TabIndex = 59; // // L_AlolaTime // - this.L_AlolaTime.Location = new System.Drawing.Point(209, 92); + this.L_AlolaTime.Location = new System.Drawing.Point(209, 109); this.L_AlolaTime.Name = "L_AlolaTime"; this.L_AlolaTime.Size = new System.Drawing.Size(72, 13); this.L_AlolaTime.TabIndex = 58; @@ -985,7 +991,7 @@ private void InitializeComponent() this.GB_Adventure.Controls.Add(this.L_Minutes); this.GB_Adventure.Controls.Add(this.CAL_AdventureStartTime); this.GB_Adventure.Controls.Add(this.CAL_LastSavedTime); - this.GB_Adventure.Location = new System.Drawing.Point(3, 99); + this.GB_Adventure.Location = new System.Drawing.Point(3, 130); this.GB_Adventure.Name = "GB_Adventure"; this.GB_Adventure.Size = new System.Drawing.Size(200, 151); this.GB_Adventure.TabIndex = 56; @@ -1075,7 +1081,7 @@ private void InitializeComponent() this.Tab_BadgeMap.Controls.Add(this.GB_Map); this.Tab_BadgeMap.Location = new System.Drawing.Point(4, 22); this.Tab_BadgeMap.Name = "Tab_BadgeMap"; - this.Tab_BadgeMap.Size = new System.Drawing.Size(386, 253); + this.Tab_BadgeMap.Size = new System.Drawing.Size(386, 294); this.Tab_BadgeMap.TabIndex = 3; this.Tab_BadgeMap.Text = "Map"; this.Tab_BadgeMap.UseVisualStyleBackColor = true; @@ -1266,7 +1272,7 @@ private void InitializeComponent() this.Tab_BattleTree.Location = new System.Drawing.Point(4, 22); this.Tab_BattleTree.Name = "Tab_BattleTree"; this.Tab_BattleTree.Padding = new System.Windows.Forms.Padding(3); - this.Tab_BattleTree.Size = new System.Drawing.Size(386, 253); + this.Tab_BattleTree.Size = new System.Drawing.Size(386, 294); this.Tab_BattleTree.TabIndex = 5; this.Tab_BattleTree.Text = "Battle Tree"; this.Tab_BattleTree.UseVisualStyleBackColor = true; @@ -1557,11 +1563,24 @@ private void InitializeComponent() this.Tab_Misc.Location = new System.Drawing.Point(4, 22); this.Tab_Misc.Name = "Tab_Misc"; this.Tab_Misc.Padding = new System.Windows.Forms.Padding(3); - this.Tab_Misc.Size = new System.Drawing.Size(386, 253); + this.Tab_Misc.Size = new System.Drawing.Size(386, 294); this.Tab_Misc.TabIndex = 4; this.Tab_Misc.Text = "Misc"; this.Tab_Misc.UseVisualStyleBackColor = true; // + // CB_Fashion + // + this.CB_Fashion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.CB_Fashion.FormattingEnabled = true; + this.CB_Fashion.Items.AddRange(new object[] { + "New Game", + "All Legal", + "Everything"}); + this.CB_Fashion.Location = new System.Drawing.Point(31, 76); + this.CB_Fashion.Name = "CB_Fashion"; + this.CB_Fashion.Size = new System.Drawing.Size(107, 21); + this.CB_Fashion.TabIndex = 60; + // // L_SkinColor // this.L_SkinColor.Location = new System.Drawing.Point(144, 6); @@ -1719,24 +1738,40 @@ private void InitializeComponent() this.B_Fashion.UseVisualStyleBackColor = true; this.B_Fashion.Click += new System.EventHandler(this.B_Fashion_Click); // - // CB_Fashion + // L_G7TID // - this.CB_Fashion.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.CB_Fashion.FormattingEnabled = true; - this.CB_Fashion.Items.AddRange(new object[] { - "New Game", - "All Legal", - "Everything"}); - this.CB_Fashion.Location = new System.Drawing.Point(31, 76); - this.CB_Fashion.Name = "CB_Fashion"; - this.CB_Fashion.Size = new System.Drawing.Size(107, 21); - this.CB_Fashion.TabIndex = 60; + this.L_G7TID.Location = new System.Drawing.Point(-1, 78); + this.L_G7TID.Name = "L_G7TID"; + this.L_G7TID.Size = new System.Drawing.Size(48, 13); + this.L_G7TID.TabIndex = 61; + this.L_G7TID.Text = "G7TID:"; + this.L_G7TID.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // MT_G7TID + // + this.MT_G7TID.Location = new System.Drawing.Point(53, 75); + this.MT_G7TID.Mask = "000000"; + this.MT_G7TID.Name = "MT_G7TID"; + this.MT_G7TID.RightToLeft = System.Windows.Forms.RightToLeft.Yes; + this.MT_G7TID.Size = new System.Drawing.Size(65, 20); + this.MT_G7TID.TabIndex = 62; + this.MT_G7TID.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // B_GenTID + // + this.B_GenTID.Location = new System.Drawing.Point(124, 75); + this.B_GenTID.Name = "B_GenTID"; + this.B_GenTID.Size = new System.Drawing.Size(68, 20); + this.B_GenTID.TabIndex = 63; + this.B_GenTID.Text = "Generate"; + this.B_GenTID.UseVisualStyleBackColor = true; + this.B_GenTID.Click += new System.EventHandler(this.B_GenTID_Click); // // SAV_Trainer7 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(414, 326); + this.ClientSize = new System.Drawing.Size(414, 366); this.Controls.Add(this.TC_Editor); this.Controls.Add(this.B_Save); this.Controls.Add(this.B_Cancel); @@ -1931,5 +1966,8 @@ private void InitializeComponent() private System.Windows.Forms.Label L_Value; private System.Windows.Forms.Label L_Offset; private System.Windows.Forms.ComboBox CB_Fashion; + private System.Windows.Forms.Button B_GenTID; + private System.Windows.Forms.Label L_G7TID; + private System.Windows.Forms.MaskedTextBox MT_G7TID; } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index ef39f0425..f33f69a6a 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -111,6 +111,7 @@ private void getTextBoxes() MT_TID.Text = SAV.TID.ToString("00000"); MT_SID.Text = SAV.SID.ToString("00000"); + MT_G7TID.Text = SAV.TrainerID7.ToString("000000"); MT_Money.Text = SAV.Money.ToString(); CB_Country.SelectedValue = SAV.Country; @@ -386,6 +387,39 @@ private void changeStatVal(object sender, EventArgs e) SAV.setRecord(index, (int)NUD_Stat.Value); } + private void B_GenTID_Click(object sender, EventArgs e) + { + B_GenTID.Text = "Generating"; + B_GenTID.Enabled = false; + int final, i_TID, i_SID; + Random random = new Random(); + i_TID = random.Next(0, 65535); + bool matchFound = false; + + while (!matchFound) + { + i_SID = 0; + + while (i_SID < 65535 && !matchFound) + { + final = i_TID + (i_SID * 65536) % 1000000; + + if (final == int.Parse(MT_G7TID.Text)) + { + MT_TID.Text = i_TID.ToString(); + MT_SID.Text = i_SID.ToString(); + matchFound = true; + B_GenTID.Text = "Generate"; + B_GenTID.Enabled = true; + } + + i_SID++; + } + + i_TID = (i_TID == 65535) ? 0 : i_TID + 1; + } + } + private readonly Dictionary RecordList = new Dictionary { {000, "Steps Taken"}, From f64d31c557eb15dfdba54b17576603621f0ed834 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 5 Feb 2017 10:57:42 -0800 Subject: [PATCH 04/18] Faster G7TID generation #823 generate a random T7SID instead of brute forcing a pair --- .../Save Editors/Gen7/SAV_Trainer7.cs | 32 ++----------------- PKHeX/Saves/SaveUtil.cs | 27 ++++++++++++++++ 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index f33f69a6a..06cbe8684 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -389,35 +389,9 @@ private void changeStatVal(object sender, EventArgs e) private void B_GenTID_Click(object sender, EventArgs e) { - B_GenTID.Text = "Generating"; - B_GenTID.Enabled = false; - int final, i_TID, i_SID; - Random random = new Random(); - i_TID = random.Next(0, 65535); - bool matchFound = false; - - while (!matchFound) - { - i_SID = 0; - - while (i_SID < 65535 && !matchFound) - { - final = i_TID + (i_SID * 65536) % 1000000; - - if (final == int.Parse(MT_G7TID.Text)) - { - MT_TID.Text = i_TID.ToString(); - MT_SID.Text = i_SID.ToString(); - matchFound = true; - B_GenTID.Text = "Generate"; - B_GenTID.Enabled = true; - } - - i_SID++; - } - - i_TID = (i_TID == 65535) ? 0 : i_TID + 1; - } + var tuple = SaveUtil.getTIDSID(Util.ToUInt32(MT_G7TID.Text), ModifierKeys == Keys.Control); + MT_TID.Text = tuple.Item1.ToString("D5"); + MT_SID.Text = tuple.Item2.ToString("D5"); } private readonly Dictionary RecordList = new Dictionary diff --git a/PKHeX/Saves/SaveUtil.cs b/PKHeX/Saves/SaveUtil.cs index 48282469c..67648f2c9 100644 --- a/PKHeX/Saves/SaveUtil.cs +++ b/PKHeX/Saves/SaveUtil.cs @@ -975,5 +975,32 @@ public static ushort[] AdvanceGCKeys(ushort[] oldKeys) return keys; } + + /// + /// Creates a 16bit TID/SID tuple for a given G7TID. + /// + /// Desired G7TID + /// Optional param to yield minimum SID. + /// 16bit TID/SID tuple + public static Tuple getTIDSID(uint G7TID, bool minimizeSID = false) + { + // 32 bit number = 4294 967295 + // lowest 6 digits G7TID + + // Bare minimum 32bit value to get ID, yields min SID + uint val = G7TID; + if (!minimizeSID) // randomize SID + { + uint s7 = 4294; + if (val > 967295) + s7 -= 1; + s7 = (uint)Util.rand.Next(0, (int)s7); + val += s7 * 1000000; + } + uint TID = val & 0xFFFF; + uint SID = val >> 16; + + return new Tuple(TID, SID); + } } } From 00bb2ec84c189b486e2c8cc257149fe8f0506bee Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 5 Feb 2017 12:54:36 -0800 Subject: [PATCH 05/18] Unprotect pelago setter Allows it to appear in batch editor closes #825 --- PKHeX/PKM/PK7.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKHeX/PKM/PK7.cs b/PKHeX/PKM/PK7.cs index 8ad65154a..c61e925be 100644 --- a/PKHeX/PKM/PK7.cs +++ b/PKHeX/PKM/PK7.cs @@ -93,7 +93,7 @@ public override uint PID public override int CNT_Smart { get { return Data[0x27]; } set { Data[0x27] = (byte)value; } } public override int CNT_Tough { get { return Data[0x28]; } set { Data[0x28] = (byte)value; } } public override int CNT_Sheen { get { return Data[0x29]; } set { Data[0x29] = (byte)value; } } - public byte PelagoEventStatus { get { return Data[0x2A]; } protected set { Data[0x2A] = value; } } + public byte PelagoEventStatus { get { return Data[0x2A]; } set { Data[0x2A] = value; } } private byte PKRS { get { return Data[0x2B]; } set { Data[0x2B] = value; } } public override int PKRS_Days { get { return PKRS & 0xF; } set { PKRS = (byte)(PKRS & ~0xF | value); } } public override int PKRS_Strain { get { return PKRS >> 4; } set { PKRS = (byte)(PKRS & 0xF | value << 4); } } From 77c25c41d330d4d04a931e6a5fc9910312f1b1c1 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 5 Feb 2017 12:55:17 -0800 Subject: [PATCH 06/18] Add legality indication for exported QRs only appears if the legality was checked (ie checking supported) --- PKHeX.WinForms/MainWindow/Main.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index a52fbf692..3556fdfdf 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -1703,9 +1703,17 @@ private void clickQR(object sender, EventArgs e) if (qr == null) return; + var sprite = dragout.Image; + var la = new LegalityAnalysis(pkx); + if (la.Parsed) + { + var img = la.Valid ? Resources.valid : Resources.warn; + sprite = ImageUtil.LayerImage(sprite, img, 24, 0, 1); + } + string[] r = pkx.QRText; - const string refURL = "PKHeX @ ProjectPokemon.org"; - new QR(qr, dragout.Image, r[0], r[1], r[2], $"{refURL} ({pkx.GetType().Name})", pkx).ShowDialog(); + string refer = $"PKHeX ({Resources.ProgramVersion})"; + new QR(qr, sprite, r[0], r[1], r[2], $"{refer} ({pkx.GetType().Name})", pkx).ShowDialog(); } } private void clickFriendship(object sender, EventArgs e) From 80d81f92de43cf0a565597056f4ef384041809a7 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 5 Feb 2017 13:08:25 -0800 Subject: [PATCH 07/18] Flag evo stone evolved pkm in eggs Evolution stone pkm at level 1 slipped through (example Ninetails) while levelup evos were already caught. Add the check to getValidPreEvolutions as well as other evolution method checks. Closes #827 --- PKHeX/Legality/Core.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index 9a9411a79..58521965d 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -520,6 +520,9 @@ private static IEnumerable getMatchingWC7(PKM pkm, IEnumerable getLineage(PKM pkm) { + if (pkm.IsEgg) + return new[] {pkm.Species}; + var table = getEvolutionTable(pkm); var lineage = table.getValidPreEvolutions(pkm, pkm.CurrentLevel); return lineage.Select(evolution => evolution.Species); @@ -545,10 +548,16 @@ internal static bool getDexNavValid(PKM pkm) } internal static bool getHasEvolved(PKM pkm) { + if (pkm.IsEgg) + return false; + return getValidPreEvolutions(pkm).Count() > 1; } internal static bool getHasEvolvedFormChange(PKM pkm) { + if (pkm.IsEgg) + return false; + if (pkm.Format >= 7 && EvolveToAlolanForms.Contains(pkm.Species)) return pkm.AltForm == 1; if (pkm.Species == 678 && pkm.Gender == 1) @@ -557,6 +566,9 @@ internal static bool getHasEvolvedFormChange(PKM pkm) } internal static bool getHasTradeEvolved(PKM pkm) { + if (pkm.IsEgg) + return false; + var table = getEvolutionTable(pkm); var lineage = table.getValidPreEvolutions(pkm, 100, skipChecks:true); return lineage.Any(evolution => EvolutionMethod.TradeMethods.Any(method => method == evolution.Flag)); // Trade Evolutions @@ -866,6 +878,11 @@ private static IEnumerable getValidPreEvolutions(PKM pkm, int lvl = -1 { if (lvl < 0) lvl = pkm.CurrentLevel; + if (lvl == 1 && pkm.IsEgg) + return new List + { + new DexLevel { Species = pkm.Species, Level = 1 }, + }; if (pkm.Species == 292 && pkm.Met_Level + 1 <= lvl && lvl >= 20) return new List { From ac818424f22019ba9a286398496bfbaeedecfaaa Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 5 Feb 2017 13:24:39 -0800 Subject: [PATCH 08/18] Delay pkm file loading via cmd args to end Closes #828 --- PKHeX.WinForms/MainWindow/Main.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 3556fdfdf..ac1245bde 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -172,9 +172,16 @@ public Main() #endregion #region Load Initial File(s) - if (args.Length > 1) // Load the arguments + string pkmArg = null; + foreach (string arg in args.Skip(1)) // skip .exe { - foreach (string arg in args.Skip(1).Where(a => a.Length > 4)) + var fi = new FileInfo(arg); + if (!fi.Exists) + continue; + + if (PKX.getIsPKM(fi.Length)) + pkmArg = arg; + else openQuick(arg, force: true); } if (!SAV.Exportable) // No SAV loaded from exe args @@ -203,6 +210,8 @@ public Main() SAV.Edited = false; // Prevents form close warning from showing until changes are made } } + if (pkmArg != null) + openQuick(pkmArg, force: true); // Splash Screen closes on its own. BringToFront(); From 065795cdbea6a8277c35030f697de38b9de6f7a8 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 5 Feb 2017 14:38:39 -0800 Subject: [PATCH 09/18] Add database IdentifierContains filter --- PKHeX.WinForms/Subforms/SAV_Database.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index ac5bf9d93..6ee3137d2 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -504,6 +504,8 @@ private void B_Search_Click(object sender, EventArgs e) { foreach (var cmd in filters) { + if (cmd.PropertyName == nameof(PKM.Identifier) + "Contains") + return pkm.Identifier.Contains(cmd.PropertyValue); if (!pkm.GetType().HasPropertyAll(cmd.PropertyName)) return false; try { if (ReflectUtil.GetValueEquals(pkm, cmd.PropertyName, cmd.PropertyValue) == cmd.Evaluator) continue; } From fbc56ace6d52037ad4734f8e0ab7fcbc08ac0a1f Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 5 Feb 2017 21:50:06 -0800 Subject: [PATCH 10/18] Add more g7 stat records Thanks skywalker25 & Holla! --- .../Subforms/Save Editors/Gen7/SAV_Trainer7.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs index 06cbe8684..7ab41d9c6 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen7/SAV_Trainer7.cs @@ -398,7 +398,9 @@ private void B_GenTID_Click(object sender, EventArgs e) { {000, "Steps Taken"}, {001, "Times Saved"}, + {003, "Total Battles"}, {004, "Wild Pokémon Battles"}, + {005, "Trainer Battles"}, {006, "Pokemon Caught"}, {007, "Pokemon Caught Fishing"}, {008, "Eggs Hatched"}, @@ -411,17 +413,22 @@ private void B_GenTID_Click(object sender, EventArgs e) {022, "Exp. Points Collected"}, {024, "Deposited in the GTS"}, {025, "Nicknames Given"}, + {027, "Battle Points Earned"}, {028, "Battle Points Spent"}, {029, "Super Effective Moves Used"}, {032, "Berry Harvests"}, {033, "Trades at the GTS"}, {034, "Wonder Trades"}, + {035, "Quick Links"}, {036, "Pokemon Rides"}, {037, "Beans Given"}, {038, "Festival Coins Spent"}, {039, "Poke Beans Collected"}, {040, "Battles at the Battle Tree"}, {041, "Z-Moves Used"}, + {046, "Ran From Battles"}, + {050, "Total Thumbs-Ups"}, + {052, "Record Thumbs-ups"}, {053, "Pokemon Petted"}, {066, "Guests Interacted With"}, @@ -429,6 +436,7 @@ private void B_GenTID_Click(object sender, EventArgs e) {110, "Pokemon Defeated (Highest)"}, {112, "Pokemon Caught (Highest)"}, {114, "Trainers Battled (Highest)"}, + {115, "Items Picked Up"}, {116, "Pokemon Evolved (Highest)"}, {118, "Fossils Restored"}, {119, "Photos Taken"}, @@ -438,10 +446,13 @@ private void B_GenTID_Click(object sender, EventArgs e) {128, "Missions Participated In"}, {129, "Facilities Hosted"}, {130, "QR Code Scans"}, + {137, "Battle Royal Dome Battles"}, {158, "Outfit Changes"}, + {159, "Battle Royal Dome Wins"}, {161, "Pelago Training Sessions"}, {162, "Pelago Hot Spring Sessions"}, {166, "Island Scans"}, + {172, "Berry Tree Battles"}, }; } } From ca17dd4c763b7ca8db026b08560cdf610379b378 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 6 Feb 2017 07:24:56 -0800 Subject: [PATCH 11/18] unban gen3 ball starters g7 --- PKHeX/Legality/Tables7.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PKHeX/Legality/Tables7.cs b/PKHeX/Legality/Tables7.cs index 170603c9b..fe5cd0208 100644 --- a/PKHeX/Legality/Tables7.cs +++ b/PKHeX/Legality/Tables7.cs @@ -472,6 +472,12 @@ public static partial class Legal }; internal static readonly int[] Ban_Gen3Ball_AllowG7 = { + 252, 255, 258, //1 - Treeko, Torchic, Mudkip + 253, 256, 259, //2 + 254, 257, 260, //3 + 387, 390, 393, //1 - Turtwig, Chimchar, Piplup + 388, 391, 394, //2 + 389, 392, 395, //3 495, 498, 501, //1 - Snivy, Tepig, Oshawott 496, 499, 502, //2 497, 500, 503, //3 From 2b606dfc3274e5123d5e4e13a0ae40626b2d6123 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 6 Feb 2017 21:36:00 -0800 Subject: [PATCH 12/18] Cleanup fixes qr7 import --- PKHeX.WinForms/Misc/QR.cs | 2 +- PKHeX/Legality/Core.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/PKHeX.WinForms/Misc/QR.cs b/PKHeX.WinForms/Misc/QR.cs index 4b9983f1c..5bcb177af 100644 --- a/PKHeX.WinForms/Misc/QR.cs +++ b/PKHeX.WinForms/Misc/QR.cs @@ -108,7 +108,7 @@ internal static byte[] getQRData() pkstr = pkstr.Substring(0, pkstr.IndexOf(cap, StringComparison.Ordinal)); // Trim outro try { - if (!pkstr.StartsWith("http") && pkstr.StartsWith(BadQRUrl)) // G7 + if (!pkstr.StartsWith("http") && !pkstr.StartsWith(BadQRUrl)) // G7 { string fstr = Regex.Unescape(pkstr); byte[] raw = Encoding.Unicode.GetBytes(fstr); diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index 58521965d..ebbf3b879 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -371,21 +371,21 @@ private static int getMaxSpeciesOrigin(int generation) switch (generation) { case 1: - return Legal.MaxSpeciesID_1; + return MaxSpeciesID_1; case 2: - return Legal.MaxSpeciesID_2; + return MaxSpeciesID_2; case 3: - return Legal.MaxSpeciesID_3; + return MaxSpeciesID_3; case 4: - return Legal.MaxSpeciesID_4; + return MaxSpeciesID_4; case 5: - return Legal.MaxSpeciesID_5; + return MaxSpeciesID_5; case 6: - return Legal.MaxSpeciesID_6; + return MaxSpeciesID_6; case 7: - return Legal.MaxSpeciesID_7; + return MaxSpeciesID_7; default: - return Legal.MaxSpeciesID_7; + return MaxSpeciesID_7; } } From 2ecf1c1c7b8fc4ccedcea4e0da01e281cbd0692b Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 6 Feb 2017 22:19:10 -0800 Subject: [PATCH 13/18] Improve file loaded transfer preference use last char of file extension if available. edge case for pk[m] considered: pk[m] => 0x6D, -0x30 = 61d, &7 = 5, which prefers 6 instead of 7+ :) adds a check for transferred pkm not having their CurrentHandler being flagged as the save file (impossible for a transferred PKM to be still handled by the OT). --- PKHeX.WinForms/MainWindow/Main.cs | 4 ++-- PKHeX.WinForms/Subforms/SAV_Database.cs | 2 +- PKHeX/Legality/Checks.cs | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index ac1245bde..ce33c1461 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -741,7 +741,7 @@ private void openFile(byte[] input, string path, string ext) { openSAV(sav, path); } - else if ((temp = PKMConverter.getPKMfromBytes(input, prefer: SAV.Generation)) != null) + else if ((temp = PKMConverter.getPKMfromBytes(input, prefer: ext.Length > 0 ? (ext.Last() - 0x30)&7 : SAV.Generation)) != null) { PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c); if (pk == null) @@ -4173,7 +4173,7 @@ private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) byte[] data = File.ReadAllBytes(file); MysteryGift mg = MysteryGift.getMysteryGift(data, fi.Extension); - PKM temp = mg?.convertToPKM(SAV) ?? PKMConverter.getPKMfromBytes(data, prefer: SAV.Generation); + PKM temp = mg?.convertToPKM(SAV) ?? PKMConverter.getPKMfromBytes(data, prefer: fi.Extension.Length > 0 ? (fi.Extension.Last() - 0x30)&7 : SAV.Generation); string c; PKM pk = PKMConverter.convertToFormat(temp, SAV.PKMType, out c); diff --git a/PKHeX.WinForms/Subforms/SAV_Database.cs b/PKHeX.WinForms/Subforms/SAV_Database.cs index 6ee3137d2..f82007601 100644 --- a/PKHeX.WinForms/Subforms/SAV_Database.cs +++ b/PKHeX.WinForms/Subforms/SAV_Database.cs @@ -89,7 +89,7 @@ public SAV_Database(Main f1) { FileInfo fi = new FileInfo(file); if (!fi.Extension.Contains(".pk") || !PKX.getIsPKM(fi.Length)) return; - var pk = PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file, prefer: Main.SAV.Generation); + var pk = PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file, prefer: (fi.Extension.Last() - 0x30)&7); if (pk != null) dbTemp.Add(pk); }); diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index 683b8e263..5ce6c22e6 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -1170,6 +1170,9 @@ private CheckResult verifyHistory() return new CheckResult(Severity.Invalid, "Should not have OT memories.", CheckIdentifier.History); } + if (pkm.Format >= 6 && pkm.GenNumber != pkm.Format && pkm.CurrentHandler != 1) + return new CheckResult(Severity.Invalid, "Current handler cannot be past gen OT for transferred specimen.", CheckIdentifier.History); + if (pkm.HT_Gender > 1) return new CheckResult(Severity.Invalid, $"HT Gender invalid {pkm.HT_Gender}.", CheckIdentifier.History); From c205eef22eb4b29f15e5178e7714a260bc6b50d0 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 6 Feb 2017 22:48:39 -0800 Subject: [PATCH 14/18] Update 170207 Update version string & posted binaries --- PKHeX/Resources/text/changelog.txt | 14 +++++++++++++- PKHeX/Resources/text/version.txt | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/PKHeX/Resources/text/changelog.txt b/PKHeX/Resources/text/changelog.txt index 291b510fc..d9690b60a 100644 --- a/PKHeX/Resources/text/changelog.txt +++ b/PKHeX/Resources/text/changelog.txt @@ -1,7 +1,19 @@ PKHeX - By Kaphotics http://projectpokemon.org/pkhex -17/01/31 - New Update: +17/02/07 - New Update: + - Legality: + - - Added: Legality indication for exported QR images (if legality check is available for origin). + - - Added: Legality indication for Box/Party pkm slots (^ + opt-in via Options->Set to SAV). + - - Fixed: More edge cases for legality checks. + - Added: More Generation 7 trainer stat record labels. Thanks skywalker25 & Holla! + - Added: G7TID -> TID/SID generator for Generation 7 Trainer Editor. Thanks RoC! + - Added: QR exporting for non gen6/7 pkm. Only use is for sharing via image rather than file. + - Fixed: Transferred markings are now applied correctly. + - Fixed: Gen 2 inventory items TMHM cap raised from 1 to 99. + - Fixed: Importing japanese pk1 files now transfer to generation 7 without errors. + +17/01/31 - New Update: (44550) [295748] - Added: Default/Illegal(old code) fashion payloads for those wanting to undo/have anything. - Changed: Internal program version updated to .NET 4.6. - Changed: Improved exception checking for config & dll exceptions. diff --git a/PKHeX/Resources/text/version.txt b/PKHeX/Resources/text/version.txt index 3428244ea..0722a4787 100644 --- a/PKHeX/Resources/text/version.txt +++ b/PKHeX/Resources/text/version.txt @@ -1 +1 @@ -20170131 \ No newline at end of file +20170207 \ No newline at end of file From 989759942045448f28cd8077d6608af13f0ec565 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 7 Feb 2017 16:10:14 -0800 Subject: [PATCH 15/18] Reorder 6->7 logic Geolocation data cleared when converting 6->7 this tradebank/georegion apply happens first but don't modify the pk6. all that matters is that we do this before the clearing --- PKHeX/PKM/PK6.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PKHeX/PKM/PK6.cs b/PKHeX/PKM/PK6.cs index 1f188af9b..5b8cc89cd 100644 --- a/PKHeX/PKM/PK6.cs +++ b/PKHeX/PKM/PK6.cs @@ -619,6 +619,10 @@ public PK7 convertToPK7() break; } + pk7.TradeMemory(Bank: true); // oh no, memories on gen7 pkm + pk7.Geo1_Country = PKMConverter.Country; + pk7.Geo1_Region = PKMConverter.Region; + // Bank-accurate data zeroing for (var i = 0x94; i < 0x9E; i++) pk7.Data[i] = 0; /* Geolocations. */ for (var i = 0xAA; i < 0xB0; i++) pk7.Data[i] = 0; /* Unused/Amie Fullness & Enjoyment. */ @@ -626,10 +630,6 @@ public PK7 convertToPK7() pk7.Data[0x72] &= 0xFC; /* Clear lower two bits of Super training flags. */ pk7.Data[0xDE] = 0; /* Gen IV encounter type. */ - pk7.TradeMemory(Bank: true); // oh no, memories on gen7 pkm - pk7.Geo1_Country = PKMConverter.Country; - pk7.Geo1_Region = PKMConverter.Region; - // Fix Checksum pk7.RefreshChecksum(); From 2f5b5790db1218214c842cf352489ed083d8a187 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 7 Feb 2017 16:25:13 -0800 Subject: [PATCH 16/18] Add xy trainer nickname Closes #283 --- .../Save Editors/Gen6/SAV_Trainer.Designer.cs | 34 ++++++++++++++----- .../Subforms/Save Editors/Gen6/SAV_Trainer.cs | 11 +++++- PKHeX/Saves/SAV6.cs | 5 +++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.Designer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.Designer.cs index 97b462b24..c3fa354d2 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.Designer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.Designer.cs @@ -202,6 +202,8 @@ private void InitializeComponent() this.Tab_Multiplayer = new System.Windows.Forms.TabPage(); this.Tab_Maison = new System.Windows.Forms.TabPage(); this.Tab_Appearance = new System.Windows.Forms.TabPage(); + this.TB_TRNick = new System.Windows.Forms.TextBox(); + this.L_TRNick = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.PB_Badge8)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Badge6)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.PB_Badge4)).BeginInit(); @@ -416,7 +418,6 @@ private void InitializeComponent() // // PB_Badge8 // - this.PB_Badge8.Image = Core.Properties.Resources.badge_8; this.PB_Badge8.Location = new System.Drawing.Point(248, 63); this.PB_Badge8.Name = "PB_Badge8"; this.PB_Badge8.Size = new System.Drawing.Size(50, 50); @@ -427,7 +428,6 @@ private void InitializeComponent() // // PB_Badge6 // - this.PB_Badge6.Image = Core.Properties.Resources.badge_6; this.PB_Badge6.Location = new System.Drawing.Point(142, 63); this.PB_Badge6.Name = "PB_Badge6"; this.PB_Badge6.Size = new System.Drawing.Size(50, 50); @@ -438,7 +438,6 @@ private void InitializeComponent() // // PB_Badge4 // - this.PB_Badge4.Image = Core.Properties.Resources.badge_4; this.PB_Badge4.Location = new System.Drawing.Point(248, 10); this.PB_Badge4.Name = "PB_Badge4"; this.PB_Badge4.Size = new System.Drawing.Size(50, 50); @@ -449,7 +448,6 @@ private void InitializeComponent() // // PB_Badge2 // - this.PB_Badge2.Image = Core.Properties.Resources.badge_2; this.PB_Badge2.Location = new System.Drawing.Point(142, 10); this.PB_Badge2.Name = "PB_Badge2"; this.PB_Badge2.Size = new System.Drawing.Size(50, 50); @@ -460,7 +458,6 @@ private void InitializeComponent() // // PB_Badge7 // - this.PB_Badge7.Image = Core.Properties.Resources.badge_7; this.PB_Badge7.Location = new System.Drawing.Point(195, 63); this.PB_Badge7.Name = "PB_Badge7"; this.PB_Badge7.Size = new System.Drawing.Size(50, 50); @@ -471,7 +468,6 @@ private void InitializeComponent() // // PB_Badge5 // - this.PB_Badge5.Image = Core.Properties.Resources.badge_5; this.PB_Badge5.Location = new System.Drawing.Point(89, 63); this.PB_Badge5.Name = "PB_Badge5"; this.PB_Badge5.Size = new System.Drawing.Size(50, 50); @@ -482,7 +478,6 @@ private void InitializeComponent() // // PB_Badge3 // - this.PB_Badge3.Image = Core.Properties.Resources.badge_3; this.PB_Badge3.Location = new System.Drawing.Point(195, 10); this.PB_Badge3.Name = "PB_Badge3"; this.PB_Badge3.Size = new System.Drawing.Size(50, 50); @@ -493,7 +488,6 @@ private void InitializeComponent() // // PB_Badge1 // - this.PB_Badge1.Image = Core.Properties.Resources.badge_1; this.PB_Badge1.Location = new System.Drawing.Point(89, 10); this.PB_Badge1.Name = "PB_Badge1"; this.PB_Badge1.Size = new System.Drawing.Size(50, 50); @@ -2102,6 +2096,8 @@ private void InitializeComponent() // // Tab_Appearance // + this.Tab_Appearance.Controls.Add(this.L_TRNick); + this.Tab_Appearance.Controls.Add(this.TB_TRNick); this.Tab_Appearance.Controls.Add(this.CB_Skin); this.Tab_Appearance.Controls.Add(this.CB_Hair); this.Tab_Appearance.Controls.Add(this.MT_Hat); @@ -2151,6 +2147,26 @@ private void InitializeComponent() this.Tab_Appearance.Text = "Appearance"; this.Tab_Appearance.UseVisualStyleBackColor = true; // + // TB_TRNick + // + this.TB_TRNick.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.TB_TRNick.Location = new System.Drawing.Point(202, 230); + this.TB_TRNick.MaxLength = 12; + this.TB_TRNick.Name = "TB_TRNick"; + this.TB_TRNick.Size = new System.Drawing.Size(93, 20); + this.TB_TRNick.TabIndex = 73; + this.TB_TRNick.Text = "WWWWWWWWWWWW"; + this.TB_TRNick.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // + // L_TRNick + // + this.L_TRNick.Location = new System.Drawing.Point(68, 230); + this.L_TRNick.Name = "L_TRNick"; + this.L_TRNick.Size = new System.Drawing.Size(128, 20); + this.L_TRNick.TabIndex = 74; + this.L_TRNick.Text = "Trainer Nickname:"; + this.L_TRNick.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // // SAV_Trainer // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -2379,5 +2395,7 @@ private void InitializeComponent() private System.Windows.Forms.Label L_Fame; private System.Windows.Forms.DateTimePicker CAL_HoFDate; private System.Windows.Forms.DateTimePicker CAL_HoFTime; + private System.Windows.Forms.Label L_TRNick; + private System.Windows.Forms.TextBox TB_TRNick; } } diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs index f5339f732..9edcd8edf 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_Trainer.cs @@ -13,7 +13,12 @@ public SAV_Trainer() { InitializeComponent(); if (Main.unicode) - try { TB_OTName.Font = FontUtil.getPKXFont(11); } + try + { + TB_OTName.Font = FontUtil.getPKXFont(11); + if (Main.SAV.XY) + TB_TRNick.Font = TB_OTName.Font; + } catch (Exception e) { WinFormsUtil.Alert("Font loading failed...", e.ToString()); } WinFormsUtil.TranslateInterface(this, Main.curlanguage); @@ -448,6 +453,8 @@ private void getTextBoxes() MT_1403D.Text = SAV.Data[SAV.TrainerCard + 0x3D].ToString(); MT_1403E.Text = SAV.Data[SAV.TrainerCard + 0x3E].ToString(); MT_1403F.Text = SAV.Data[SAV.TrainerCard + 0x3F].ToString(); + + TB_TRNick.Text = SAV.OT_Nick; } CB_Vivillon.SelectedIndex = SAV.Vivillon; @@ -540,6 +547,8 @@ private void save() SAV.Data[SAV.TrainerCard + 0x3D] = byte.Parse(MT_1403D.Text); SAV.Data[SAV.TrainerCard + 0x3E] = byte.Parse(MT_1403E.Text); SAV.Data[SAV.TrainerCard + 0x3F] = byte.Parse(MT_1403F.Text); + + SAV.OT_Nick = TB_TRNick.Text; } // Vivillon diff --git a/PKHeX/Saves/SAV6.cs b/PKHeX/Saves/SAV6.cs index 37fa8415f..2e3bdde97 100644 --- a/PKHeX/Saves/SAV6.cs +++ b/PKHeX/Saves/SAV6.cs @@ -398,6 +398,11 @@ public override string OT get { return Util.TrimFromZero(Encoding.Unicode.GetString(Data, TrainerCard + 0x48, 0x1A)); } set { Encoding.Unicode.GetBytes(value.PadRight(13, '\0')).CopyTo(Data, TrainerCard + 0x48); } } + public string OT_Nick + { + get { return Util.TrimFromZero(Encoding.Unicode.GetString(Data, TrainerCard + 0x62, 0x1A)); } + set { Encoding.Unicode.GetBytes(value.PadRight(value.Length + 1, '\0')).CopyTo(Data, TrainerCard + 0x62); } + } public string Saying1 { get { return Util.TrimFromZero(Encoding.Unicode.GetString(Data, TrainerCard + 0x7C + 0x22 * 0, 0x22)); } From 6504d5305ad7681a3eb4f8b95c08885145ca0ab9 Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Tue, 7 Feb 2017 23:12:18 -0600 Subject: [PATCH 17/18] Fixed settings not saving when form closes Should resolve #833. This is why I prefer if statement logic to return statements littered everywhere. --- PKHeX.WinForms/MainWindow/Main.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index ce33c1461..805f94dbf 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -3118,10 +3118,14 @@ private void dragoutDrop(object sender, DragEventArgs e) private void Main_FormClosing(object sender, FormClosingEventArgs e) { - if (!SAV.Edited) - return; - if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Any unsaved changes will be lost.", "Are you sure you want to close PKHeX?")) - { e.Cancel = true; return; } + if (SAV.Edited) + { + if (SAV.Edited && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Any unsaved changes will be lost.", "Are you sure you want to close PKHeX?")) + { + e.Cancel = true; + return; + } + } try { Properties.Settings.Default.Save(); } catch (Exception x) { File.WriteAllLines("config error.txt", new[] {x.ToString()}); } From bd4b40062650098e62cf8030a9ae085e26e741e4 Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Tue, 7 Feb 2017 23:13:33 -0600 Subject: [PATCH 18/18] Cleanup Whoops. --- PKHeX.WinForms/MainWindow/Main.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/PKHeX.WinForms/MainWindow/Main.cs b/PKHeX.WinForms/MainWindow/Main.cs index 805f94dbf..c01152956 100644 --- a/PKHeX.WinForms/MainWindow/Main.cs +++ b/PKHeX.WinForms/MainWindow/Main.cs @@ -3118,17 +3118,14 @@ private void dragoutDrop(object sender, DragEventArgs e) private void Main_FormClosing(object sender, FormClosingEventArgs e) { - if (SAV.Edited) + if (SAV.Edited && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Any unsaved changes will be lost.", "Are you sure you want to close PKHeX?")) { - if (SAV.Edited && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Any unsaved changes will be lost.", "Are you sure you want to close PKHeX?")) - { - e.Cancel = true; - return; - } + e.Cancel = true; + return; } try { Properties.Settings.Default.Save(); } - catch (Exception x) { File.WriteAllLines("config error.txt", new[] {x.ToString()}); } + catch (Exception x) { File.WriteAllLines("config error.txt", new[] { x.ToString() }); } } #endregion