From bf7cd278ccb02a926976be1630bc337084816a59 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 10 Mar 2015 18:44:51 -0700 Subject: [PATCH] Refactoring Refactoring complete (for now). --- Misc/About.cs | 14 +- Misc/CodeGenerator.cs | 51 +- Misc/Legal.cs | 7 +- Misc/PKX.cs | 221 ++--- Misc/QR.cs | 11 +- Misc/SplashScreen.cs | 8 +- Misc/Util.cs | 136 ++- Misc/pk2pk.cs | 89 +- Misc/ram2sav.cs | 89 +- PKX/f1-Main.cs | 1873 ++++++++++++++++++------------------- PKX/f2-Text.cs | 17 +- PKX/f3-MemoryAmie.cs | 92 +- PKX/f4-RibbMedal.cs | 54 +- Program.cs | 2 - SAV/SAV_BerryField.cs | 13 +- SAV/SAV_BoxLayout.cs | 8 +- SAV/SAV_EventFlagsORAS.cs | 68 +- SAV/SAV_EventFlagsXY.cs | 56 +- SAV/SAV_HallOfFame.cs | 65 +- SAV/SAV_Inventory.cs | 42 +- SAV/SAV_OPower.cs | 63 +- SAV/SAV_PokedexORAS.cs | 446 +++++---- SAV/SAV_PokedexXY.cs | 42 +- SAV/SAV_Pokepuff.cs | 31 +- SAV/SAV_SecretBase.cs | 76 +- SAV/SAV_SuperTrain.cs | 38 +- SAV/SAV_Trainer.cs | 45 +- SAV/SAV_Wondercard.cs | 21 +- SAV/frmReport.cs | 67 +- 29 files changed, 1727 insertions(+), 2018 deletions(-) diff --git a/Misc/About.cs b/Misc/About.cs index c4744033f..0cec97891 100644 --- a/Misc/About.cs +++ b/Misc/About.cs @@ -1,10 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace PKHeX @@ -14,22 +8,22 @@ namespace PKHeX public About() { InitializeComponent(); - RTB.Text = PKHeX.Properties.Resources.changelog; + RTB.Text = Properties.Resources.changelog; } private void B_Close_Click(object sender, EventArgs e) { - this.Close(); + Close(); } private void B_Shortcuts_Click(object sender, EventArgs e) { if (B_Shortcuts.Text == "Shortcuts") { - RTB.Text = PKHeX.Properties.Resources.shortcuts; // display shortcuts + RTB.Text = Properties.Resources.shortcuts; // display shortcuts B_Shortcuts.Text = "Changelog"; } else { - RTB.Text = PKHeX.Properties.Resources.changelog; // display changelog + RTB.Text = Properties.Resources.changelog; // display changelog B_Shortcuts.Text = "Shortcuts"; } } diff --git a/Misc/CodeGenerator.cs b/Misc/CodeGenerator.cs index 2930f6278..ff9f4fa11 100644 --- a/Misc/CodeGenerator.cs +++ b/Misc/CodeGenerator.cs @@ -1,14 +1,9 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; using System.Globalization; using System.IO; +using System.Linq; using System.Text.RegularExpressions; +using System.Windows.Forms; namespace PKHeX { @@ -19,13 +14,13 @@ namespace PKHeX PKX.Structures.SaveGame SaveGame = new PKX.Structures.SaveGame(null); Form1 m_parent; - byte[] tabdata = null; + byte[] tabdata; public CodeGenerator(Form1 frm1, byte[] formdata) { m_parent = frm1; tabdata = formdata; InitializeComponent(); - this.CenterToParent(); + CenterToParent(); RTB_Code.Clear(); TB_Write.Clear(); SaveGame = m_parent.SaveGame; @@ -157,8 +152,7 @@ namespace PKHeX } private void B_Load_Click(object sender, EventArgs e) { - OpenFileDialog ofd = new OpenFileDialog(); - ofd.Filter = "Code File|*.bin"; + OpenFileDialog ofd = new OpenFileDialog {Filter = "Code File|*.bin"}; if (ofd.ShowDialog() == DialogResult.OK) { string path = ofd.FileName; @@ -205,9 +199,7 @@ namespace PKHeX Array.Copy(BitConverter.GetBytes(UInt32.Parse(rip[2], NumberStyles.HexNumber)),0,ncf,4+i*12+8,4); } - SaveFileDialog sfd = new SaveFileDialog(); - sfd.FileName = "code.bin"; - sfd.Filter = "Code File|*.bin"; + SaveFileDialog sfd = new SaveFileDialog {FileName = "code.bin", Filter = "Code File|*.bin"}; if (sfd.ShowDialog() == DialogResult.OK) { string path = sfd.FileName; @@ -296,7 +288,7 @@ namespace PKHeX lines++; if ((lines % 128 == 0) && CHK_Break.Checked) - { result += (Environment.NewLine + "--- Segment " + (lines / 128 + 1).ToString() + " ---" + Environment.NewLine + Environment.NewLine); } + { result += (Environment.NewLine + "--- Segment " + (lines / 128 + 1) + " ---" + Environment.NewLine + Environment.NewLine); } if (lines > 10000) goto toomany; } @@ -350,19 +342,16 @@ namespace PKHeX { if (RTB_Code.Lines[i].Length <= 2 * 8 && RTB_Code.Lines[i].Length > 2 * 8 + 2) { Util.Error("Invalid code pasted (Type)"); return; } - else + try { - try - { - // Grab Line Data - string line = RTB_Code.Lines[i]; - string[] rip = Regex.Split(line, " "); - Array.Resize(ref data, data.Length + 4); - Array.Copy(BitConverter.GetBytes(UInt32.Parse(rip[1], NumberStyles.HexNumber)), 0, data, data.Length - 4, 4); - } - catch (Exception x) - { Util.Error("Invalid code pasted (Content):", x.ToString()); return; } + // Grab Line Data + string line = RTB_Code.Lines[i]; + string[] rip = Regex.Split(line, " "); + Array.Resize(ref data, data.Length + 4); + Array.Copy(BitConverter.GetBytes(UInt32.Parse(rip[1], NumberStyles.HexNumber)), 0, data, data.Length - 4, 4); } + catch (Exception x) + { Util.Error("Invalid code pasted (Content):", x.ToString()); return; } } } // Go over the data @@ -373,14 +362,8 @@ namespace PKHeX data[0] = data[1] = data[2] = data[3] = 0; } if ((data.Length == 232) || (data.Length == 260)) - { - this.returnArray = data; - this.Close(); - } - else - { - Util.Error("Invalid code pasted (Length)"); return; - } + { returnArray = data; Close(); } + else { Util.Error("Invalid code pasted (Length)"); } } } } diff --git a/Misc/Legal.cs b/Misc/Legal.cs index 942fa918a..102820c2d 100644 --- a/Misc/Legal.cs +++ b/Misc/Legal.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace PKHeX +namespace PKHeX { class Legal { diff --git a/Misc/PKX.cs b/Misc/PKX.cs index b739a927b..d8c9dfd51 100644 --- a/Misc/PKX.cs +++ b/Misc/PKX.cs @@ -9,7 +9,7 @@ using System.Text.RegularExpressions; namespace PKHeX { - public partial class PKX + public class PKX { // C# PKX Function Library // No WinForm object related code, only to calculate information. @@ -225,11 +225,9 @@ namespace PKHeX int tl = 0; // Initial Level, immediately incremented before loop. while ((uint)table.Rows[++tl][growth + 1] <= exp) { - if (tl == 100) - { - exp = getEXP(100, species); // Fix EXP - return 100; - } + if (tl != 100) continue; + exp = getEXP(100, species); // Fix EXP + return 100; // After we find the level above ours, we're done. } return --tl; @@ -285,11 +283,9 @@ namespace PKHeX for (int i = 1; i < inputCSV.Length; i++) { string[] countryData = inputCSV[i].Split(','); - if (countryData.Length > 1) - { - indexes[i - 1] = Convert.ToInt32(countryData[0]); - unsortedList[i - 1] = countryData[index + 1]; - } + if (countryData.Length <= 1) continue; + indexes[i - 1] = Convert.ToInt32(countryData[0]); + unsortedList[i - 1] = countryData[index + 1]; } int countrynum = Array.IndexOf(indexes, country); @@ -311,11 +307,9 @@ namespace PKHeX for (int i = 1; i < inputCSV.Length; i++) { string[] countryData = inputCSV[i].Split(','); - if (countryData.Length > 1) - { - indexes[i - 1] = Convert.ToInt32(countryData[0]); - unsortedList[i - 1] = countryData[index + 1]; - } + if (countryData.Length <= 1) continue; + indexes[i - 1] = Convert.ToInt32(countryData[0]); + unsortedList[i - 1] = countryData[index + 1]; } int regionnum = Array.IndexOf(indexes, region); @@ -385,11 +379,9 @@ namespace PKHeX // Account for nature int incr = nature / 5 + 1; int decr = nature % 5 + 1; - if (incr != decr) - { - stats[incr] *= 11; stats[incr] /= 10; - stats[decr] *= 9; stats[decr] /= 10; - } + if (incr == decr) return stats; // if neutral return stats without mod + stats[incr] *= 11; stats[incr] /= 10; + stats[decr] *= 9; stats[decr] /= 10; // Return Result return stats; @@ -440,9 +432,9 @@ namespace PKHeX // Decrypt the Party Stats seed = pv; - if (pkx.Length > 232) - for (int i = 232; i < 260; i += 2) - Array.Copy(BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkx, i) ^ (LCRNG(ref seed) >> 16))), 0, pkx, i, 2); + if (pkx.Length <= 232) return pkx; + for (int i = 232; i < 260; i += 2) + Array.Copy(BitConverter.GetBytes((ushort)(BitConverter.ToUInt16(pkx, i) ^ (LCRNG(ref seed) >> 16))), 0, pkx, i, 2); return pkx; } @@ -478,7 +470,7 @@ namespace PKHeX ushort chk = 0; for (int i = 8; i < 232; i += 2) // Loop through the entire PKX chk += BitConverter.ToUInt16(data, i); - + return chk; } internal static bool verifychk(byte[] input) @@ -1001,88 +993,80 @@ namespace PKHeX public string Name; public SaveGame(string GameID) { - if (GameID == "XY") + switch (GameID) { - Name = "XY"; - Box = 0x27A00; - TrainerCard = 0x19400; - Party = 0x19600; - BattleBox = 0x09E00; - Daycare = 0x20600; - GTS = 0x1CC00; - Fused = 0x1B400; - SUBE = 0x22C90; - - Puff = 0x5400; - Item = 0x5800; - Trainer1 = 0x6800; - Trainer2 = 0x9600; - PCLayout = 0x9800; - Wondercard = 0x21000; - BerryField = 0x20C00; - OPower = 0x1BE00; - EventFlag = 0x19E00; - PokeDex = 0x1A400; - - HoF = 0x1E800; - JPEG = 0x5C600; - PSS = 0x0A400; - } - else if (GameID == "ORAS") - { - // Temp - Name = "ORAS"; - Box = 0x38400; // Confirmed - TrainerCard = 0x19400; // Confirmed - Party = 0x19600; // Confirmed - BattleBox = 0x09E00;// Confirmed - Daycare = 0x21000; // Confirmed (thanks Rei) - GTS = 0x1D600; // Confirmed - Fused = 0x1BE00; // Confirmed - SUBE = 0x22C90; // ****not in use, not updating?**** - - Puff = 0x5400; // Confirmed - Item = 0x5800; // Confirmed - Trainer1 = 0x6800; // Confirmed - Trainer2 = 0x9600; // Confirmed - PCLayout = 0x9800; // Confirmed - Wondercard = 0x22000; // Confirmed - BerryField = 0x20C00; // ****changed**** - OPower = 0x1BE00; - EventFlag = 0x19E00; // Confirmed - PokeDex = 0x1A400; - - HoF = 0x1F200; // Confirmed - JPEG = 0x6D000; // Confirmed - PSS = 0x0A400; // Confirmed (thanks Rei) - } - else - { - // Copied... - Name = "Unknown"; - Box = 0x27A00; - TrainerCard = 0x19400; - Party = 0x19600; - BattleBox = 0x09E00; - Daycare = 0x20600; - GTS = 0x1CC00; - Fused = 0x1B400; - SUBE = 0x22C90; - - Puff = 0x5400; - Item = 0x5800; - Trainer1 = 0x6800; - Trainer2 = 0x9600; - PCLayout = 0x9800; - Wondercard = 0x21000; - BerryField = 0x20C00; - OPower = 0x1BE00; - EventFlag = 0x19E00; - PokeDex = 0x1A400; - - HoF = 0x1E800; - JPEG = 0x5C600; - PSS = 0x0A400; + case "XY": + Name = "XY"; + Box = 0x27A00; + TrainerCard = 0x19400; + Party = 0x19600; + BattleBox = 0x09E00; + Daycare = 0x20600; + GTS = 0x1CC00; + Fused = 0x1B400; + SUBE = 0x22C90; + Puff = 0x5400; + Item = 0x5800; + Trainer1 = 0x6800; + Trainer2 = 0x9600; + PCLayout = 0x9800; + Wondercard = 0x21000; + BerryField = 0x20C00; + OPower = 0x1BE00; + EventFlag = 0x19E00; + PokeDex = 0x1A400; + HoF = 0x1E800; + JPEG = 0x5C600; + PSS = 0x0A400; + break; + case "ORAS": + Name = "ORAS"; + Box = 0x38400; // Confirmed + TrainerCard = 0x19400; // Confirmed + Party = 0x19600; // Confirmed + BattleBox = 0x09E00;// Confirmed + Daycare = 0x21000; // Confirmed (thanks Rei) + GTS = 0x1D600; // Confirmed + Fused = 0x1BE00; // Confirmed + SUBE = 0x22C90; // ****not in use, not updating?**** + Puff = 0x5400; // Confirmed + Item = 0x5800; // Confirmed + Trainer1 = 0x6800; // Confirmed + Trainer2 = 0x9600; // Confirmed + PCLayout = 0x9800; // Confirmed + Wondercard = 0x22000; // Confirmed + BerryField = 0x20C00; // ****changed**** + OPower = 0x1BE00; + EventFlag = 0x19E00; // Confirmed + PokeDex = 0x1A400; + HoF = 0x1F200; // Confirmed + JPEG = 0x6D000; // Confirmed + PSS = 0x0A400; // Confirmed (thanks Rei) + break; + default: + Name = "Unknown"; + Box = 0x27A00; + TrainerCard = 0x19400; + Party = 0x19600; + BattleBox = 0x09E00; + Daycare = 0x20600; + GTS = 0x1CC00; + Fused = 0x1B400; + SUBE = 0x22C90; + Puff = 0x5400; + Item = 0x5800; + Trainer1 = 0x6800; + Trainer2 = 0x9600; + PCLayout = 0x9800; + Wondercard = 0x21000; + BerryField = 0x20C00; + OPower = 0x1BE00; + EventFlag = 0x19E00; + PokeDex = 0x1A400; + HoF = 0x1E800; + JPEG = 0x5C600; + PSS = 0x0A400; + break; } } } @@ -1118,11 +1102,10 @@ namespace PKHeX savindex = 2; } } - if ((data[0x168] ^ 1) != savindex && savindex != 2) - { - Console.WriteLine("ERROR: ACTIVE BLOCK MISMATCH"); - savindex = 2; - } + if ((data[0x168] ^ 1) == savindex || savindex == 2) // success + return savindex; + Console.WriteLine("ERROR: ACTIVE BLOCK MISMATCH"); + savindex = 2; return savindex; } internal static ushort ccitt16(byte[] data) @@ -1208,12 +1191,11 @@ namespace PKHeX internal Personal GetPersonal(int species, int formID) { Personal data = GetPersonal(species); - if (formID > 0 && formID <= data.AltFormCount && data.AltFormCount > 0 && data.FormPointer > 0) // Working with an Alt Forme with a base stat change - { - formID--; - data = GetPersonal(721 + formID + data.FormPointer); - } - return data; + if (formID <= 0 || formID > data.AltFormCount || data.AltFormCount <= 0 || data.FormPointer <= 0) + return data; + + // Working with an Alt Forme with a base stat change + return GetPersonal(721 + --formID + data.FormPointer); } } @@ -1244,7 +1226,7 @@ namespace PKHeX new[] { 1, 1, 1, 0, 0, 1 }, // Ground new[] { 1, 1, 0, 1, 0, 0 }, // Rock new[] { 1, 0, 0, 1, 0, 1 }, // Bug - new[] { 1, 1, 0, 1, 0, 1 }, // Ghost + new[] { 1, 0, 1, 1, 0, 1 }, // Ghost new[] { 1, 1, 1, 1, 0, 1 }, // Steel new[] { 1, 0, 1, 0, 1, 0 }, // Fire new[] { 1, 0, 0, 0, 1, 1 }, // Water @@ -1253,7 +1235,7 @@ namespace PKHeX new[] { 1, 0, 1, 1, 1, 0 }, // Psychic new[] { 1, 0, 0, 1, 1, 1 }, // Ice new[] { 1, 0, 1, 1, 1, 1 }, // Dragon - new[] { 1, 1, 1, 1, 1, 1 } // Dark + new[] { 1, 1, 1, 1, 1, 1 }, // Dark }; public class Simulator { @@ -1291,7 +1273,6 @@ namespace PKHeX string[] stats = { "HP", "Atk", "Def", "SpA", "SpD", "Spe" }; string[] lines = input.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None); - Nickname = null; // Seek for start of set int start = -1; diff --git a/Misc/QR.cs b/Misc/QR.cs index 5fa72ea19..d16c16e98 100644 --- a/Misc/QR.cs +++ b/Misc/QR.cs @@ -1,11 +1,6 @@ using System; -using System.Collections; -using System.Collections.Generic; using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; -using System.Net; namespace PKHeX { @@ -31,13 +26,13 @@ namespace PKHeX g.DrawString(top, font, Brushes.Black, new PointF(18, 5)); g.DrawString(bottom, font, Brushes.Black, new PointF(18, pic.Width - 15)); g.DrawString(left.Replace("s",""), font, Brushes.Black, new PointF(0, 18)); // trim off *V-s-: - g.DrawString(right, font, Brushes.Black, new PointF(pic.Width - 15, 18), new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical)); + g.DrawString(right, font, Brushes.Black, new PointF(pic.Width - 15, 18), new StringFormat(StringFormatFlags.DirectionVertical)); PB_QR.BackgroundImage = pic; } else { - int stretch = 50; + const int stretch = 50; Height += stretch; Image newpic = new Bitmap(PB_QR.Width, PB_QR.Height); Graphics g = Graphics.FromImage(newpic); @@ -46,7 +41,7 @@ namespace PKHeX g.DrawString(top, font, Brushes.Black, new PointF(18, qr.Height - 5)); g.DrawString(bottom, font, Brushes.Black, new PointF(18, qr.Height + 8)); - g.DrawString(left.Replace(Environment.NewLine.ToString(), "/").Replace("//", " ").Replace(":/", ": "), font, Brushes.Black, new PointF(18, qr.Height + 20)); + g.DrawString(left.Replace(Environment.NewLine, "/").Replace("//", " ").Replace(":/", ": "), font, Brushes.Black, new PointF(18, qr.Height + 20)); g.DrawString(right, font, Brushes.Black, new PointF(18, qr.Height + 32)); PB_QR.BackgroundImage = newpic; diff --git a/Misc/SplashScreen.cs b/Misc/SplashScreen.cs index 362e9ee08..70bfcc98b 100644 --- a/Misc/SplashScreen.cs +++ b/Misc/SplashScreen.cs @@ -1,7 +1,5 @@ -using System; -using System.Text; +using System.Timers; using System.Windows.Forms; -using System.Timers; namespace PKHeX { @@ -13,7 +11,7 @@ namespace PKHeX InitializeComponent(); m_parent = frm1; System.Timers.Timer myTimer = new System.Timers.Timer(); - myTimer.Elapsed += new ElapsedEventHandler(DisplayTimeEvent); + myTimer.Elapsed += DisplayTimeEvent; myTimer.Interval = 50; // milliseconds per trigger interval myTimer.Start(); } @@ -24,7 +22,7 @@ namespace PKHeX else { L_Status.Text = Form1.Status; } else if (InvokeRequired && IsHandleCreated) - try { Invoke((MethodInvoker)delegate() { Close(); }); } catch { Close(); } + try { Invoke((MethodInvoker)Close); } catch { Close(); } else Close(); } } diff --git a/Misc/Util.cs b/Misc/Util.cs index 7adeb73d7..c7f8b7069 100644 --- a/Misc/Util.cs +++ b/Misc/Util.cs @@ -10,7 +10,7 @@ using System.Text.RegularExpressions; namespace PKHeX { - public partial class Util + public class Util { // Image Layering/Blending Utility internal static Bitmap LayerImage(Image baseLayer, Image overLayer, int x, int y, double trans) @@ -22,7 +22,7 @@ namespace PKHeX { Color newColor = overlayImage.GetPixel(i % (overlayImage.Width), i / (overlayImage.Width)); Color oldColor = newImage.GetPixel(i % (overlayImage.Width) + x, i / (overlayImage.Width) + y); - newColor = Color.FromArgb((int)((double)(newColor.A) * trans), newColor.R, newColor.G, newColor.B); // Apply transparency change + newColor = Color.FromArgb((int)(newColor.A * trans), newColor.R, newColor.G, newColor.B); // Apply transparency change // if (newColor.A != 0) // If Pixel isn't transparent, we'll overwrite the color. { // if (newColor.A < 100) @@ -40,8 +40,7 @@ namespace PKHeX if (img == null) return null; Bitmap bmp = new Bitmap(img.Width, img.Height); // Determining Width and Height of Source Image Graphics graphics = Graphics.FromImage(bmp); - ColorMatrix colormatrix = new ColorMatrix(); - colormatrix.Matrix33 = (float)trans; + ColorMatrix colormatrix = new ColorMatrix {Matrix33 = (float) trans}; ImageAttributes imgAttribute = new ImageAttributes(); imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttribute); @@ -78,7 +77,7 @@ namespace PKHeX internal static FileInfo GetNewestFile(DirectoryInfo directory) { return directory.GetFiles() - .Union(directory.GetDirectories().Select(d => GetNewestFile(d))) + .Union(directory.GetDirectories().Select(GetNewestFile)) .OrderByDescending(f => (f == null ? DateTime.MinValue : f.LastWriteTime)) .FirstOrDefault(); } @@ -137,8 +136,7 @@ namespace PKHeX } return path_3DS; } - catch { } - return null; + catch { return null; } } internal static string GetSDFLocation() { @@ -155,22 +153,19 @@ namespace PKHeX } if (path_SDF == null) return null; - else - { - // 3DS data found in SD card reader. Let's get the title folder location! - string[] folders = Directory.GetDirectories(path_SDF, "*", System.IO.SearchOption.TopDirectoryOnly); - Array.Sort(folders); // Don't need Modified Date, sort by path names just in case. + // 3DS data found in SD card reader. Let's get the title folder location! + string[] folders = Directory.GetDirectories(path_SDF, "*", SearchOption.TopDirectoryOnly); + Array.Sort(folders); // Don't need Modified Date, sort by path names just in case. - // Loop through all the folders in the Nintendo 3DS folder to see if any of them contain 'title'. - for (int i = folders.Length - 1; i >= 0; i--) - { - if (File.Exists(Path.Combine(folders[i], "000011c4" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "000011c4"); // OR - if (File.Exists(Path.Combine(folders[i], "000011c5" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "000011c5"); // AS - if (File.Exists(Path.Combine(folders[i], "0000055d" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "0000055d"); // X - if (File.Exists(Path.Combine(folders[i], "0000055e" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "0000055e"); // Y - } - return null; // Fallthrough + // Loop through all the folders in the Nintendo 3DS folder to see if any of them contain 'title'. + for (int i = folders.Length - 1; i >= 0; i--) + { + if (File.Exists(Path.Combine(folders[i], "000011c4" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "000011c4"); // OR + if (File.Exists(Path.Combine(folders[i], "000011c5" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "000011c5"); // AS + if (File.Exists(Path.Combine(folders[i], "0000055d" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "0000055d"); // X + if (File.Exists(Path.Combine(folders[i], "0000055e" + Path.DirectorySeparatorChar + "main"))) return Path.Combine(folders[i], "0000055e"); // Y } + return null; // Fallthrough } catch { return null; } } @@ -181,15 +176,12 @@ namespace PKHeX internal static string TrimFromZero(string input) { int index = input.IndexOf('\0'); - if (index < 0) - return input; - - return input.Substring(0, index); + return index < 0 ? input : input.Substring(0, index); } internal static string[] getStringList(string f, string l) { object txt = Properties.Resources.ResourceManager.GetObject("text_" + f + "_" + l); // Fetch File, \n to list. - List rawlist = ((string)txt).Split(new char[] { '\n' }).ToList(); + List rawlist = ((string)txt).Split(new[] { '\n' }).ToList(); string[] stringdata = new string[rawlist.Count]; for (int i = 0; i < rawlist.Count; i++) @@ -200,7 +192,7 @@ namespace PKHeX internal static string[] getSimpleStringList(string f) { object txt = Properties.Resources.ResourceManager.GetObject(f); // Fetch File, \n to list. - List rawlist = ((string)txt).Split(new char[] { '\n' }).ToList(); + List rawlist = ((string)txt).Split(new[] { '\n' }).ToList(); string[] stringdata = new string[rawlist.Count]; for (int i = 0; i < rawlist.Count; i++) @@ -212,9 +204,9 @@ namespace PKHeX { try { - string[] newlist = new string[Util.ToInt32(SimpleStringList[SimpleStringList.Length - 1].Split(',')[0]) + 1]; + string[] newlist = new string[ToInt32(SimpleStringList[SimpleStringList.Length - 1].Split(',')[0]) + 1]; for (int i = 1; i < SimpleStringList.Length; i++) - newlist[Util.ToInt32(SimpleStringList[i].Split(',')[0])] = SimpleStringList[i].Split(',')[1]; + newlist[ToInt32(SimpleStringList[i].Split(',')[0])] = SimpleStringList[i].Split(',')[1]; return newlist; } catch { return null; } @@ -255,7 +247,7 @@ namespace PKHeX return 0; try { - value = value.TrimEnd(new char[] { '_' }); + value = value.TrimEnd(new[] { '_' }); return Int32.Parse(value); } catch { return 0; } @@ -267,7 +259,7 @@ namespace PKHeX return 0; try { - value = value.TrimEnd(new char[] { '_' }); + value = value.TrimEnd(new[] { '_' }); return UInt32.Parse(value); } catch { return 0; } @@ -292,12 +284,10 @@ namespace PKHeX { if (str == null) return "0"; - char c; string s = ""; - for (int i = 0; i < str.Length; i++) + foreach (char c in str) { - c = str[i]; // filter for hex if ((c < 0x0047 && c > 0x002F) || (c < 0x0067 && c > 0x0060)) s += c; @@ -330,16 +320,15 @@ namespace PKHeX // debug(Controls); // Fetch a File // Check to see if a the translation file exists in the same folder as the executable - string externalLangPath = System.Windows.Forms.Application.StartupPath + Path.DirectorySeparatorChar + "lang_" + lang + ".txt"; + string externalLangPath = Application.StartupPath + Path.DirectorySeparatorChar + "lang_" + lang + ".txt"; string[] rawlist; if (File.Exists(externalLangPath)) rawlist = File.ReadAllLines(externalLangPath); else { - object txt; - txt = Properties.Resources.ResourceManager.GetObject("lang_" + lang); // Fetch File, \n to list. + object txt = Properties.Resources.ResourceManager.GetObject("lang_" + lang); if (txt == null) return; // Translation file does not exist as a resource; abort this function and don't translate UI. - rawlist = ((string)txt).Split(new string[] { "\n" }, StringSplitOptions.None); + rawlist = ((string)txt).Split(new[] { "\n" }, StringSplitOptions.None); rawlist = rawlist.Select(i => i.Trim()).ToArray(); // Remove trailing spaces } @@ -408,19 +397,19 @@ namespace PKHeX { System.Media.SystemSounds.Exclamation.Play(); string msg = String.Join(Environment.NewLine + Environment.NewLine, lines); - return (DialogResult)MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } internal static DialogResult Alert(params string[] lines) { System.Media.SystemSounds.Asterisk.Play(); string msg = String.Join(Environment.NewLine + Environment.NewLine, lines); - return (DialogResult)MessageBox.Show(msg, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return MessageBox.Show(msg, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning); } internal static DialogResult Prompt(MessageBoxButtons btn, params string[] lines) { System.Media.SystemSounds.Question.Play(); string msg = String.Join(Environment.NewLine + Environment.NewLine, lines); - return (DialogResult)MessageBox.Show(msg, "Prompt", btn, MessageBoxIcon.Asterisk); + return MessageBox.Show(msg, "Prompt", btn, MessageBoxIcon.Asterisk); } // DataSource Providing @@ -432,11 +421,10 @@ namespace PKHeX internal static List getCBList(string textfile, string lang) { // Set up - List cbList = new List(); - string[] inputCSV = Util.getSimpleStringList(textfile); + string[] inputCSV = getSimpleStringList(textfile); // Get Language we're fetching for - int index = Array.IndexOf(new string[] { "ja", "en", "fr", "de", "it", "es", "ko", "zh", }, lang); + int index = Array.IndexOf(new[] { "ja", "en", "fr", "de", "it", "es", "ko", "zh", }, lang); // Set up our Temporary Storage string[] unsortedList = new string[inputCSV.Length - 1]; @@ -456,20 +444,17 @@ namespace PKHeX Array.Sort(sortedList); // Arrange the input data based on original number - for (int i = 0; i < sortedList.Length; i++) + return sortedList.Select(s => new cbItem { - cbItem ncbi = new cbItem(); - ncbi.Text = sortedList[i]; - ncbi.Value = indexes[Array.IndexOf(unsortedList, sortedList[i])]; - cbList.Add(ncbi); - } - return cbList; + Text = s, + Value = indexes[Array.IndexOf(unsortedList, s)] + }).ToList(); } internal static List getCBList(string[] inStrings, params int[][] allowed) { List cbList = new List(); if (allowed == null) - allowed = new int[][] { Enumerable.Range(0, inStrings.Length).ToArray() }; + allowed = new[] { Enumerable.Range(0, inStrings.Length).ToArray() }; foreach (int[] list in allowed) { @@ -483,13 +468,11 @@ namespace PKHeX Array.Sort(sortedChoices); // Add the rest of the items - for (int i = 0; i < sortedChoices.Length; i++) + cbList.AddRange(sortedChoices.Select(t => new cbItem { - cbItem ncbi = new cbItem(); - ncbi.Text = sortedChoices[i]; - ncbi.Value = list[Array.IndexOf(unsortedChoices, sortedChoices[i])]; - cbList.Add(ncbi); - } + Text = t, + Value = list[Array.IndexOf(unsortedChoices, t)] + })); } return cbList; } @@ -513,13 +496,10 @@ namespace PKHeX Array.Sort(sortedChoices); // Add the rest of the items - for (int i = 0; i < sortedChoices.Length; i++) + cbList.AddRange(sortedChoices.Select(s => new cbItem { - cbItem ncbi = new cbItem(); - ncbi.Text = sortedChoices[i]; - ncbi.Value = allowed[Array.IndexOf(unsortedChoices, sortedChoices[i])]; - cbList.Add(ncbi); - } + Text = s, Value = allowed[Array.IndexOf(unsortedChoices, s)] + })); } return cbList; } @@ -531,9 +511,11 @@ namespace PKHeX for (int i = 4; i > 1; i--) // add 4,3,2 { // First 3 Balls are always first - cbItem ncbi = new cbItem(); - ncbi.Text = inStrings[i]; - ncbi.Value = i; + cbItem ncbi = new cbItem + { + Text = inStrings[i], + Value = i + }; newlist.Add(ncbi); } @@ -547,28 +529,28 @@ namespace PKHeX Array.Sort(sortedballs); // Add the rest of the balls - for (int i = 0; i < sortedballs.Length; i++) + newlist.AddRange(sortedballs.Select(t => new cbItem { - cbItem ncbi = new cbItem(); - ncbi.Text = sortedballs[i]; - ncbi.Value = stringVal[Array.IndexOf(ballnames, sortedballs[i])]; - newlist.Add(ncbi); - } + Text = t, + Value = stringVal[Array.IndexOf(ballnames, t)] + })); return newlist; } internal static List getUnsortedCBList(string textfile) { // Set up List cbList = new List(); - string[] inputCSV = Util.getSimpleStringList(textfile); + string[] inputCSV = getSimpleStringList(textfile); // Gather our data from the input file for (int i = 1; i < inputCSV.Length; i++) { string[] inputData = inputCSV[i].Split(','); - cbItem ncbi = new cbItem(); - ncbi.Value = Convert.ToInt32(inputData[0]); - ncbi.Text = inputData[1]; + cbItem ncbi = new cbItem + { + Text = inputData[1], + Value = Convert.ToInt32(inputData[0]) + }; cbList.Add(ncbi); } return cbList; diff --git a/Misc/pk2pk.cs b/Misc/pk2pk.cs index 0f10bf795..0662b41b0 100644 --- a/Misc/pk2pk.cs +++ b/Misc/pk2pk.cs @@ -1,16 +1,10 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; using System.Data; -using System.Drawing; -using System.Linq; using System.Text; -using System.Windows.Forms; -using System.IO; namespace PKHeX { - public partial class pk2pk + public class pk2pk { public byte[] ConvertPKM(byte[] input, byte[] savefile, int savindex) { @@ -53,7 +47,7 @@ namespace PKHeX byte[] g6data = convertPK5toPK6(g5data); return g6data; } - else if (input.Length == 136 || input.Length == 236 || input.Length == 220) // Ambiguous Gen4/5 file. + if (input.Length == 136 || input.Length == 236 || input.Length == 220) // Ambiguous Gen4/5 file. { if (((BitConverter.ToUInt16(input, 0x80) < 0x3333) && (input[0x5F] < 0x10)) || (BitConverter.ToUInt16(input, 0x46) != 0)) { @@ -63,10 +57,10 @@ namespace PKHeX byte[] g6data = convertPK5toPK6(g5data); return g6data; } - else return convertPK5toPK6(input); + return convertPK5toPK6(input); } #endregion - else return input; // Should never get here. + return input; // Should never get here. } #region Utility public DateTime moment = DateTime.Now; @@ -80,16 +74,16 @@ namespace PKHeX public int subreg = 0x7; // California public int _3DSreg = 0x1; // Americas public string g6trname = "PKHeX"; - public byte g6trgend = 0; + public byte g6trgend; private int getAbilityNumber(int species, int ability, int formnum) { - PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(species, formnum); - int[] spec_abilities = new int[3]; - Array.Copy(MonData.Abilities, spec_abilities, 3); - int abilval = Array.IndexOf(spec_abilities, ability); - if (abilval >= 0) - return 1 << abilval; - else return -1; + PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(species, formnum); + int[] spec_abilities = new int[3]; + Array.Copy(MonData.Abilities, spec_abilities, 3); + int abilval = Array.IndexOf(spec_abilities, ability); + if (abilval >= 0) + return 1 << abilval; + return -1; } public byte[] convertPK3toPK4(byte[] pk3) { @@ -104,7 +98,7 @@ namespace PKHeX pk4[0x8] = (byte)(species & 0xFF); pk4[0x9] = (byte)(species >> 8); uint exp = BitConverter.ToUInt32(pk4, 0x10); - pk4[0x14] = (byte)70; + pk4[0x14] = 70; // ability later pk4[0x16] = pk3[27]; // Copy markings pk4[0x17] = pk3[18]; // Language @@ -114,7 +108,7 @@ namespace PKHeX uint ribo = BitConverter.ToUInt32(pk3, 0x4C); int fateful = (int)(ribo >> 31); uint newrib = 0; - uint mask = 0xF; + const uint mask = 0xF; for (int i = 0; i < 5; i++) // copy contest ribbons { uint oldval = (ribo >> (3 * i)) & 0x7; // get 01234 stage @@ -161,7 +155,7 @@ namespace PKHeX int genderratio = MonData.GenderRatio; uint PID = BitConverter.ToUInt32(pk4, 0); int gv = (int)(PID & 0xFF); - int gender = 0; + int gender; if (genderratio == 255) gender = 2; @@ -170,12 +164,7 @@ namespace PKHeX else if (genderratio == 0) gender = 0; else - { - if (gv <= genderratio) - gender = 1; - else - gender = 0; - } + gender = gv <= genderratio ? 1 : 0; int formnum = 0; // unown @@ -216,7 +205,7 @@ namespace PKHeX chartable = Char3to4J(); // Get Species Names - string[] names = new string[] + string[] names = { speclang_ja[species].ToUpper(), speclang_en[species].ToUpper(), @@ -263,12 +252,9 @@ namespace PKHeX Array.Copy(BitConverter.GetBytes(0xFFFF), 0, pk4, 0x48 + i * 2, 2); break; } - else - { - nickname += (char)chartable.Rows[val][2]; - int newval = (int)chartable.Rows[val][1]; - Array.Copy(BitConverter.GetBytes(newval), 0, pk4, 0x48 + i * 2, 2); - } + nickname += (char)chartable.Rows[val][2]; + int newval = (int)chartable.Rows[val][1]; + Array.Copy(BitConverter.GetBytes(newval), 0, pk4, 0x48 + i * 2, 2); } // nickname detection @@ -278,7 +264,6 @@ namespace PKHeX // Set Trainer Name // First, transfer the Nickname to trashbytes for OT - string trainer = ""; Array.Copy(pk4, 0x48, pk4, 0x68, 0x10); { for (int i = 0; i < 8; i++) @@ -290,12 +275,8 @@ namespace PKHeX Array.Copy(BitConverter.GetBytes(0xFFFF), 0, pk4, 0x68 + i * 2, 2); break; } - else - { - trainer += (char)chartable.Rows[val][2]; - int newval = (int)chartable.Rows[val][1]; - Array.Copy(BitConverter.GetBytes(newval), 0, pk4, 0x68 + i * 2, 2); - } + int newval = (int)chartable.Rows[val][1]; + Array.Copy(BitConverter.GetBytes(newval), 0, pk4, 0x68 + i * 2, 2); } } @@ -338,7 +319,7 @@ namespace PKHeX // Met / Crown Data Detection int species = BitConverter.ToInt16(pk5, 0x8); bool fateful = Convert.ToBoolean(BitConverter.ToUInt16(pk5, 0x40) & 0x1); - int[] crownspec = new int[] { 251, 243, 244, 245 }; + int[] crownspec = { 251, 243, 244, 245 }; if (fateful && Array.IndexOf(crownspec, species) >= 0) { if (species == 251) @@ -361,8 +342,6 @@ namespace PKHeX // Transfer Nickname and OT Name DataTable CT45 = Char4to5(); byte[] nicknamestr = new byte[24]; - string nickname = ""; - string trainer = ""; nicknamestr[22] = nicknamestr[23] = 0xFF; try { @@ -375,7 +354,6 @@ namespace PKHeX // find entry int newval = (int)CT45.Rows.Find(val)[1]; Array.Copy(BitConverter.GetBytes(newval), 0, pk5, 0x48 + i, 2); - nickname += (char)newval; } byte[] OTstr = new byte[24]; @@ -388,7 +366,6 @@ namespace PKHeX // find entry int newval = (int)CT45.Rows.Find(val)[1]; - trainer += (char)newval; Array.Copy(BitConverter.GetBytes(newval), 0, pk5, 0x68 + i, 2); } } catch { return pk4; } @@ -488,8 +465,7 @@ namespace PKHeX { if (BitConverter.ToUInt16(pk5, 0x68 + i) == 0xFFFF) // If terminated, stop break; - else - Array.Copy(pk5, 0x68 + i, pk6, 0xB0 + i, 2); // Copy 16bit Character + Array.Copy(pk5, 0x68 + i, pk6, 0xB0 + i, 2); // Copy 16bit Character } // Copy Met Info @@ -506,11 +482,12 @@ namespace PKHeX // Get the current level of the specimen to be transferred int species = BitConverter.ToInt16(pk6, 0x08); - uint exp = BitConverter.ToUInt32(pk6, 0x10); // Level isn't altered, keeps Gen5 Met Level - // int currentlevel = getLevel((species), (exp)); - // (byte)(((pk5[0x84]) & 0x80) + currentlevel); + // uint exp = BitConverter.ToUInt32(pk6, 0x10); + // int currentlevel = getLevel((species), (exp)); + // (byte)(((pk5[0x84]) & 0x80) + currentlevel); + pk6[0xDD] = pk5[0x84]; // OT Gender & Encounter Level pk6[0xDE] = pk5[0x85]; // Encounter Type @@ -618,10 +595,10 @@ namespace PKHeX // 01 - Not handled by OT // 07 - CA // 31 - USA - byte[] x90x = new byte[] { 0x00, 0x00, g6trgend, 0x01, (byte)subreg, (byte)country, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)PKX.getBaseFriendship(species), 0x00, 0x01, 0x04, (byte)(Util.rnd32() % 10), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + byte[] x90x = { 0x00, 0x00, g6trgend, 0x01, (byte)subreg, (byte)country, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, PKX.getBaseFriendship(species), 0x00, 0x01, 0x04, (byte)(Util.rnd32() % 10), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; Array.Copy(x90x, 0, pk6, 0x90, x90x.Length); // When transferred, friendship gets reset. - pk6[0xCA] = (byte)PKX.getBaseFriendship(species); + pk6[0xCA] = PKX.getBaseFriendship(species); // Write Origin (USA California) - location is dependent on 3DS system that transfers. pk6[0xE0] = (byte)country; @@ -647,7 +624,7 @@ namespace PKHeX // Apply New Checksum Array.Copy(BitConverter.GetBytes(chk), 0, pk6, 06, 2); - string trainer = Util.TrimFromZero(Encoding.Unicode.GetString(pk6, 0xB0, 24)); + Util.TrimFromZero(Encoding.Unicode.GetString(pk6, 0xB0, 24)); return pk6; // Done! } @@ -3906,7 +3883,7 @@ namespace PKHeX private int getg3species(int g3index) { - int[] newindex = new int[] + int[] newindex = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58, @@ -3927,7 +3904,7 @@ namespace PKHeX 345,346,347,348,280,281,282,371,372,373,374,375,376,377,378,379,382,383,384,380,381, 385,386,358, }; - int[] oldindex = new int[] + int[] oldindex = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58, diff --git a/Misc/ram2sav.cs b/Misc/ram2sav.cs index 00cff4bcf..33e68cb1e 100644 --- a/Misc/ram2sav.cs +++ b/Misc/ram2sav.cs @@ -1,22 +1,20 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; +using System.Linq; namespace PKHeX { class ram2sav { - internal static uint UNKNOWNVAL = 0x96696996; + internal const uint UNKNOWNVAL = 0x96696996; internal static byte[] getMAIN(byte[] ramsav) { - byte[] main = new byte[] { }; - uint[] offsets = new uint[] { }; - uint[] lens = new uint[] { }; - uint[] magics = new uint[] { }; - uint[] skips = new uint[] { }; - uint[] instances = new uint[] { }; + byte[] main; + uint[] offsets; + uint[] lens; + uint[] magics; + uint[] skips; + uint[] instances; uint val = BitConverter.ToUInt32(ramsav, 0); uint spos = 0; if (ramsav.Length == 0x80000) // ORAS @@ -34,17 +32,17 @@ namespace PKHeX skips = new uint[] { 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000004, 0x00000004, 0x00000004, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000004 }; magics = new uint[] { 0x0059AE94, 0x0059ACC0, 0x0059AC00, 0x0059AD80, 0x0059AED4, 0x0059A8E8, 0x0059ADE0, 0x0059AD20, 0x0059ADA0, 0x0059A8C8, 0x0059A968, 0x0059AC40, 0x0059AC20, 0x0059AE54, 0x0059ABA0, 0x0059ABA0, 0x0059ABA0, 0x0059ADC0, 0x0059A9A8, 0x00599734, 0x0059AEF4, 0x0059AA48, 0x0059A908, 0x0059AC60, 0x0059A9C8, 0x0059AA08, 0x0059A948, 0x0059AEB4, 0x0059AD40, 0x0059AE74, 0x0059AAE8, 0x0059AD00, 0x0059A8A8, 0x0059A800, 0x0059A888, 0x0059AB70, 0x0059AC80, 0x0059AA28, 0x0059AE34, 0x0059A868, 0x0059A820, 0x0059AB28, 0x0059AA88, 0x0059AAC8, 0x0059ACE0, 0x0059ABC0, 0x0059AAA8, 0x0059AA68, 0x0059A928, 0x0059A9E8, 0x0059AD60, 0x0059AB80, 0x0059AB08, 0x0059A7E0, 0x0059A988, 0x0059ACA0 }; instances = new uint[] { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; - if (val == 0x0059E418) + switch (val) { - magics = new uint[] { 0x0059E418, 0x0059E244, 0x0059E184, 0x0059E304, 0x0059E458, 0x0059DE6C, 0x0059E364, 0x0059E2A4, 0x0059E324, 0x0059DE4C, 0x0059DEEC, 0x0059E1C4, 0x0059E1A4, 0x0059E3D8, 0x0059E124, 0x0059E124, 0x0059E124, 0x0059E344, 0x0059DF2C, 0x0059CCB8, 0x0059E478, 0x0059DFCC, 0x0059DE8C, 0x0059E1E4, 0x0059DF4C, 0x0059DF8C, 0x0059DECC, 0x0059E438, 0x0059E2C4, 0x0059E3F8, 0x0059E06C, 0x0059E284, 0x0059DE2C, 0x0059DD84, 0x0059DE0C, 0x0059E0CC, 0x0059E204, 0x0059DFAC, 0x0059E3B8, 0x0059DDEC, 0x0059DDA4, 0x0059E0AC, 0x0059E00C, 0x0059E04C, 0x0059E264, 0x0059E144, 0x0059E02C, 0x0059DFEC, 0x0059DEAC, 0x0059DF6C, 0x0059E2E4, 0x0059E104, 0x0059E08C, 0x0059DD64, 0x0059DF0C, 0x0059E224 }; - } - else if (val == 0x0059E408) - { - magics = new uint[] { 0x0059E408, 0x0059E234, 0x0059E174, 0x0059E2F4, 0x0059E448, 0x0059DE5C, 0x0059E354, 0x0059E294, 0x0059E314, 0x0059DE3C, 0x0059DEDC, 0x0059E1B4, 0x0059E194, 0x0059E3C8, 0x0059E114, 0x0059E114, 0x0059E114, 0x0059E334, 0x0059DF1C, 0x0059CCA8, 0x0059E468, 0x0059DFBC, 0x0059DE7C, 0x0059E1D4, 0x0059DF3C, 0x0059DF7C, 0x0059DEBC, 0x0059E428, 0x0059E2B4, 0x0059E3E8, 0x0059E05C, 0x0059E274, 0x0059DE1C, 0x0059DD74, 0x0059DDFC, 0x0059E0BC, 0x0059E1F4, 0x0059DF9C, 0x0059E3A8, 0x0059DDDC, 0x0059DD94, 0x0059E09C, 0x0059DFFC, 0x0059E03C, 0x0059E254, 0x0059E134, 0x0059E01C, 0x0059DFDC, 0x0059DE9C, 0x0059DF5C, 0x0059E2D4, 0x0059E0F4, 0x0059E07C, 0x0059DD54, 0x0059DEFC, 0x0059E214 }; - } - else if (val == 0x0059BEC4) - { - magics = new uint[] { 0x0059BEC4, 0x0059BCF0, 0x0059BC30, 0x0059BDB0, 0x0059BF04, 0x0059B918, 0x0059BE10, 0x0059BD50, 0x0059BDD0, 0x0059B8F8, 0x0059B998, 0x0059BC70, 0x0059BC50, 0x0059BE84, 0x0059BBD0, 0x0059BBD0, 0x0059BBD0, 0x0059BDF0, 0x0059B9D8, 0x0059A764, 0x0059BF24, 0x0059BA78, 0x0059B938, 0x0059BC90, 0x0059B9F8, 0x0059BA38, 0x0059B978, 0x0059BEE4, 0x0059BD70, 0x0059BEA4, 0x0059BB18, 0x0059BD30, 0x0059B8D8, 0x0059B830, 0x0059B8B8, 0x0059BBA0, 0x0059BCB0, 0x0059BA58, 0x0059BE64, 0x0059B898, 0x0059B850, 0x0059BB58, 0x0059BAB8, 0x0059BAF8, 0x0059BD10, 0x0059BBF0, 0x0059BAD8, 0x0059BA98, 0x0059B958, 0x0059BA18, 0x0059BD90, 0x0059BBB0, 0x0059BB38, 0x0059B810, 0x0059B9B8, 0x0059BCD0 }; + case 0x0059E418: + magics = new uint[] { 0x0059E418, 0x0059E244, 0x0059E184, 0x0059E304, 0x0059E458, 0x0059DE6C, 0x0059E364, 0x0059E2A4, 0x0059E324, 0x0059DE4C, 0x0059DEEC, 0x0059E1C4, 0x0059E1A4, 0x0059E3D8, 0x0059E124, 0x0059E124, 0x0059E124, 0x0059E344, 0x0059DF2C, 0x0059CCB8, 0x0059E478, 0x0059DFCC, 0x0059DE8C, 0x0059E1E4, 0x0059DF4C, 0x0059DF8C, 0x0059DECC, 0x0059E438, 0x0059E2C4, 0x0059E3F8, 0x0059E06C, 0x0059E284, 0x0059DE2C, 0x0059DD84, 0x0059DE0C, 0x0059E0CC, 0x0059E204, 0x0059DFAC, 0x0059E3B8, 0x0059DDEC, 0x0059DDA4, 0x0059E0AC, 0x0059E00C, 0x0059E04C, 0x0059E264, 0x0059E144, 0x0059E02C, 0x0059DFEC, 0x0059DEAC, 0x0059DF6C, 0x0059E2E4, 0x0059E104, 0x0059E08C, 0x0059DD64, 0x0059DF0C, 0x0059E224 }; + break; + case 0x0059E408: + magics = new uint[] { 0x0059E408, 0x0059E234, 0x0059E174, 0x0059E2F4, 0x0059E448, 0x0059DE5C, 0x0059E354, 0x0059E294, 0x0059E314, 0x0059DE3C, 0x0059DEDC, 0x0059E1B4, 0x0059E194, 0x0059E3C8, 0x0059E114, 0x0059E114, 0x0059E114, 0x0059E334, 0x0059DF1C, 0x0059CCA8, 0x0059E468, 0x0059DFBC, 0x0059DE7C, 0x0059E1D4, 0x0059DF3C, 0x0059DF7C, 0x0059DEBC, 0x0059E428, 0x0059E2B4, 0x0059E3E8, 0x0059E05C, 0x0059E274, 0x0059DE1C, 0x0059DD74, 0x0059DDFC, 0x0059E0BC, 0x0059E1F4, 0x0059DF9C, 0x0059E3A8, 0x0059DDDC, 0x0059DD94, 0x0059E09C, 0x0059DFFC, 0x0059E03C, 0x0059E254, 0x0059E134, 0x0059E01C, 0x0059DFDC, 0x0059DE9C, 0x0059DF5C, 0x0059E2D4, 0x0059E0F4, 0x0059E07C, 0x0059DD54, 0x0059DEFC, 0x0059E214 }; + break; + case 0x0059BEC4: + magics = new uint[] { 0x0059BEC4, 0x0059BCF0, 0x0059BC30, 0x0059BDB0, 0x0059BF04, 0x0059B918, 0x0059BE10, 0x0059BD50, 0x0059BDD0, 0x0059B8F8, 0x0059B998, 0x0059BC70, 0x0059BC50, 0x0059BE84, 0x0059BBD0, 0x0059BBD0, 0x0059BBD0, 0x0059BDF0, 0x0059B9D8, 0x0059A764, 0x0059BF24, 0x0059BA78, 0x0059B938, 0x0059BC90, 0x0059B9F8, 0x0059BA38, 0x0059B978, 0x0059BEE4, 0x0059BD70, 0x0059BEA4, 0x0059BB18, 0x0059BD30, 0x0059B8D8, 0x0059B830, 0x0059B8B8, 0x0059BBA0, 0x0059BCB0, 0x0059BA58, 0x0059BE64, 0x0059B898, 0x0059B850, 0x0059BB58, 0x0059BAB8, 0x0059BAF8, 0x0059BD10, 0x0059BBF0, 0x0059BAD8, 0x0059BA98, 0x0059B958, 0x0059BA18, 0x0059BD90, 0x0059BBB0, 0x0059BB38, 0x0059B810, 0x0059B9B8, 0x0059BCD0 }; + break; } } using (MemoryStream ms = new MemoryStream()) @@ -52,7 +50,7 @@ namespace PKHeX for (int i = 0; i < lens.Length; i++) { int ofs = FindIndex(ramsav, magics[i], instances[i], spos); - ms.Seek((long)(offsets[i] - 0x5400), SeekOrigin.Begin); + ms.Seek(offsets[i] - 0x5400, SeekOrigin.Begin); spos += lens[i]; if (ofs > 0) { @@ -74,11 +72,11 @@ namespace PKHeX bool oras = (main.Length > 0x65600); byte[] newram = new byte[ramsav.Length]; Array.Copy(ramsav, newram, ramsav.Length); - uint[] offsets = new uint[] { }; - uint[] lens = new uint[] { }; - uint[] magics = new uint[] { }; - uint[] skips = new uint[] { }; - uint[] instances = new uint[] { }; + uint[] offsets; + uint[] lens; + uint[] magics; + uint[] skips; + uint[] instances; uint val = BitConverter.ToUInt32(ramsav, 0); uint spos = 0; if (oras) // ORAS @@ -96,30 +94,26 @@ namespace PKHeX skips = new uint[] { 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000004, 0x00000004, 0x00000004, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000004, 0x00000004 }; magics = new uint[] { 0x0059AE94, 0x0059ACC0, 0x0059AC00, 0x0059AD80, 0x0059AED4, 0x0059A8E8, 0x0059ADE0, 0x0059AD20, 0x0059ADA0, 0x0059A8C8, 0x0059A968, 0x0059AC40, 0x0059AC20, 0x0059AE54, 0x0059ABA0, 0x0059ABA0, 0x0059ABA0, 0x0059ADC0, 0x0059A9A8, 0x00599734, 0x0059AEF4, 0x0059AA48, 0x0059A908, 0x0059AC60, 0x0059A9C8, 0x0059AA08, 0x0059A948, 0x0059AEB4, 0x0059AD40, 0x0059AE74, 0x0059AAE8, 0x0059AD00, 0x0059A8A8, 0x0059A800, 0x0059A888, 0x0059AB70, 0x0059AC80, 0x0059AA28, 0x0059AE34, 0x0059A868, 0x0059A820, 0x0059AB28, 0x0059AA88, 0x0059AAC8, 0x0059ACE0, 0x0059ABC0, 0x0059AAA8, 0x0059AA68, 0x0059A928, 0x0059A9E8, 0x0059AD60, 0x0059AB80, 0x0059AB08, 0x0059A7E0, 0x0059A988, 0x0059ACA0 }; instances = new uint[] { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; - if (val == 0x0059E418) + switch (val) { - magics = new uint[] { 0x0059E418, 0x0059E244, 0x0059E184, 0x0059E304, 0x0059E458, 0x0059DE6C, 0x0059E364, 0x0059E2A4, 0x0059E324, 0x0059DE4C, 0x0059DEEC, 0x0059E1C4, 0x0059E1A4, 0x0059E3D8, 0x0059E124, 0x0059E124, 0x0059E124, 0x0059E344, 0x0059DF2C, 0x0059CCB8, 0x0059E478, 0x0059DFCC, 0x0059DE8C, 0x0059E1E4, 0x0059DF4C, 0x0059DF8C, 0x0059DECC, 0x0059E438, 0x0059E2C4, 0x0059E3F8, 0x0059E06C, 0x0059E284, 0x0059DE2C, 0x0059DD84, 0x0059DE0C, 0x0059E0CC, 0x0059E204, 0x0059DFAC, 0x0059E3B8, 0x0059DDEC, 0x0059DDA4, 0x0059E0AC, 0x0059E00C, 0x0059E04C, 0x0059E264, 0x0059E144, 0x0059E02C, 0x0059DFEC, 0x0059DEAC, 0x0059DF6C, 0x0059E2E4, 0x0059E104, 0x0059E08C, 0x0059DD64, 0x0059DF0C, 0x0059E224 }; - } - else if (val == 0x0059E408) - { - magics = new uint[] { 0x0059E408, 0x0059E234, 0x0059E174, 0x0059E2F4, 0x0059E448, 0x0059DE5C, 0x0059E354, 0x0059E294, 0x0059E314, 0x0059DE3C, 0x0059DEDC, 0x0059E1B4, 0x0059E194, 0x0059E3C8, 0x0059E114, 0x0059E114, 0x0059E114, 0x0059E334, 0x0059DF1C, 0x0059CCA8, 0x0059E468, 0x0059DFBC, 0x0059DE7C, 0x0059E1D4, 0x0059DF3C, 0x0059DF7C, 0x0059DEBC, 0x0059E428, 0x0059E2B4, 0x0059E3E8, 0x0059E05C, 0x0059E274, 0x0059DE1C, 0x0059DD74, 0x0059DDFC, 0x0059E0BC, 0x0059E1F4, 0x0059DF9C, 0x0059E3A8, 0x0059DDDC, 0x0059DD94, 0x0059E09C, 0x0059DFFC, 0x0059E03C, 0x0059E254, 0x0059E134, 0x0059E01C, 0x0059DFDC, 0x0059DE9C, 0x0059DF5C, 0x0059E2D4, 0x0059E0F4, 0x0059E07C, 0x0059DD54, 0x0059DEFC, 0x0059E214 }; - } - else if (val == 0x0059BEC4) - { - magics = new uint[] { 0x0059BEC4, 0x0059BCF0, 0x0059BC30, 0x0059BDB0, 0x0059BF04, 0x0059B918, 0x0059BE10, 0x0059BD50, 0x0059BDD0, 0x0059B8F8, 0x0059B998, 0x0059BC70, 0x0059BC50, 0x0059BE84, 0x0059BBD0, 0x0059BBD0, 0x0059BBD0, 0x0059BDF0, 0x0059B9D8, 0x0059A764, 0x0059BF24, 0x0059BA78, 0x0059B938, 0x0059BC90, 0x0059B9F8, 0x0059BA38, 0x0059B978, 0x0059BEE4, 0x0059BD70, 0x0059BEA4, 0x0059BB18, 0x0059BD30, 0x0059B8D8, 0x0059B830, 0x0059B8B8, 0x0059BBA0, 0x0059BCB0, 0x0059BA58, 0x0059BE64, 0x0059B898, 0x0059B850, 0x0059BB58, 0x0059BAB8, 0x0059BAF8, 0x0059BD10, 0x0059BBF0, 0x0059BAD8, 0x0059BA98, 0x0059B958, 0x0059BA18, 0x0059BD90, 0x0059BBB0, 0x0059BB38, 0x0059B810, 0x0059B9B8, 0x0059BCD0 }; + case 0x0059E418: + magics = new uint[] { 0x0059E418, 0x0059E244, 0x0059E184, 0x0059E304, 0x0059E458, 0x0059DE6C, 0x0059E364, 0x0059E2A4, 0x0059E324, 0x0059DE4C, 0x0059DEEC, 0x0059E1C4, 0x0059E1A4, 0x0059E3D8, 0x0059E124, 0x0059E124, 0x0059E124, 0x0059E344, 0x0059DF2C, 0x0059CCB8, 0x0059E478, 0x0059DFCC, 0x0059DE8C, 0x0059E1E4, 0x0059DF4C, 0x0059DF8C, 0x0059DECC, 0x0059E438, 0x0059E2C4, 0x0059E3F8, 0x0059E06C, 0x0059E284, 0x0059DE2C, 0x0059DD84, 0x0059DE0C, 0x0059E0CC, 0x0059E204, 0x0059DFAC, 0x0059E3B8, 0x0059DDEC, 0x0059DDA4, 0x0059E0AC, 0x0059E00C, 0x0059E04C, 0x0059E264, 0x0059E144, 0x0059E02C, 0x0059DFEC, 0x0059DEAC, 0x0059DF6C, 0x0059E2E4, 0x0059E104, 0x0059E08C, 0x0059DD64, 0x0059DF0C, 0x0059E224 }; + break; + case 0x0059E408: + magics = new uint[] { 0x0059E408, 0x0059E234, 0x0059E174, 0x0059E2F4, 0x0059E448, 0x0059DE5C, 0x0059E354, 0x0059E294, 0x0059E314, 0x0059DE3C, 0x0059DEDC, 0x0059E1B4, 0x0059E194, 0x0059E3C8, 0x0059E114, 0x0059E114, 0x0059E114, 0x0059E334, 0x0059DF1C, 0x0059CCA8, 0x0059E468, 0x0059DFBC, 0x0059DE7C, 0x0059E1D4, 0x0059DF3C, 0x0059DF7C, 0x0059DEBC, 0x0059E428, 0x0059E2B4, 0x0059E3E8, 0x0059E05C, 0x0059E274, 0x0059DE1C, 0x0059DD74, 0x0059DDFC, 0x0059E0BC, 0x0059E1F4, 0x0059DF9C, 0x0059E3A8, 0x0059DDDC, 0x0059DD94, 0x0059E09C, 0x0059DFFC, 0x0059E03C, 0x0059E254, 0x0059E134, 0x0059E01C, 0x0059DFDC, 0x0059DE9C, 0x0059DF5C, 0x0059E2D4, 0x0059E0F4, 0x0059E07C, 0x0059DD54, 0x0059DEFC, 0x0059E214 }; + break; + case 0x0059BEC4: + magics = new uint[] { 0x0059BEC4, 0x0059BCF0, 0x0059BC30, 0x0059BDB0, 0x0059BF04, 0x0059B918, 0x0059BE10, 0x0059BD50, 0x0059BDD0, 0x0059B8F8, 0x0059B998, 0x0059BC70, 0x0059BC50, 0x0059BE84, 0x0059BBD0, 0x0059BBD0, 0x0059BBD0, 0x0059BDF0, 0x0059B9D8, 0x0059A764, 0x0059BF24, 0x0059BA78, 0x0059B938, 0x0059BC90, 0x0059B9F8, 0x0059BA38, 0x0059B978, 0x0059BEE4, 0x0059BD70, 0x0059BEA4, 0x0059BB18, 0x0059BD30, 0x0059B8D8, 0x0059B830, 0x0059B8B8, 0x0059BBA0, 0x0059BCB0, 0x0059BA58, 0x0059BE64, 0x0059B898, 0x0059B850, 0x0059BB58, 0x0059BAB8, 0x0059BAF8, 0x0059BD10, 0x0059BBF0, 0x0059BAD8, 0x0059BA98, 0x0059B958, 0x0059BA18, 0x0059BD90, 0x0059BBB0, 0x0059BB38, 0x0059B810, 0x0059B9B8, 0x0059BCD0 }; + break; } } for (int i = 0; i < lens.Length; i++) { int ofs = FindIndex(ramsav, magics[i], instances[i], spos); spos += lens[i]; - if (ofs > 0) - { - Array.Copy(main, (int)offsets[i] - 0x5400, newram, ofs + (int)skips[i], lens[i]); - spos += 4; - } - else { } - //Do nothing. Don't Copy blocks we can't find lol + if (ofs <= 0) continue; + Array.Copy(main, (int)offsets[i] - 0x5400, newram, ofs + (int)skips[i], lens[i]); + spos += 4; } return newram; } @@ -139,12 +133,9 @@ namespace PKHeX times++; v = (BitConverter.ToUInt32(data, ofs)); } - if (ofs + 4 == data.Length) - { - Console.WriteLine("Failed to find " + val.ToString("X8")); - return -1; - } - return ofs + 4; + if (ofs + 4 != data.Length) return ofs + 4; + Console.WriteLine("Failed to find " + val.ToString("X8")); + return -1; } } } diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 4f0aaf3e7..e3bd57d4a 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -26,7 +26,7 @@ namespace PKHeX CB_ExtraBytes.SelectedIndex = 0; // Resize Main Window to PKX Editing Mode - largeWidth = this.Width; + largeWidth = Width; shortWidth = (Width * (30500 / 620)) / 100 + 1; Width = shortWidth; @@ -37,7 +37,7 @@ namespace PKHeX #endregion #region Language Detection before loading // Set up Language Selection - string[] main_langlist = new string[] + string[] main_langlist = { "English", // ENG "日本語", // JPN @@ -46,13 +46,13 @@ namespace PKHeX "Deutsch", // GER "Español", // SPA "한국어", // KOR - "中文", // CHN + "中文" // CHN }; foreach (var cbItem in main_langlist) CB_MainLanguage.Items.Add(cbItem); // Try and detect the language - int[] main_langnum = new int[] { 2, 1, 3, 4, 5, 7, 8, 9 }; + int[] main_langnum = { 2, 1, 3, 4, 5, 7, 8, 9 }; string[] lang_val = { "en", "ja", "fr", "it", "de", "es", "ko", "zh" }; string filename = Path.GetFileNameWithoutExtension(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); string lastTwoChars = filename.Substring(filename.Length - 2); @@ -64,7 +64,7 @@ namespace PKHeX CB_MainLanguage.SelectedIndex = ((lastTwoChars == "jp") ? 1 : 0); #region HaX - HaX = (filename.IndexOf("HaX") >= 0); + HaX = (filename.IndexOf("HaX", StringComparison.Ordinal) >= 0); { CHK_HackedStats.Enabled = CHK_HackedStats.Visible = DEV_Ability.Enabled = DEV_Ability.Visible = @@ -81,8 +81,7 @@ namespace PKHeX #region Localize & Populate InitializeStrings(); Status = "Strings set up"; InitializeFields(); Status = "Fields set up"; - try { CB_Language.SelectedIndex = (lang >= 0) ? main_langnum[lang] : 1; } - catch { } + CB_Language.SelectedIndex = (lang >= 0) ? main_langnum[lang] : 1; #endregion #region Add ContextMenus to the PictureBoxes (PKX slots) @@ -107,30 +106,31 @@ namespace PKHeX PictureBox[] pba2 = { bbpkx1,bbpkx2,bbpkx3,bbpkx4,bbpkx5,bbpkx6, - dcpkx1, dcpkx2, gtspkx, fusedpkx, subepkx1, subepkx2, subepkx3, + dcpkx1, dcpkx2, gtspkx, fusedpkx, subepkx1, subepkx2, subepkx3 }; ContextMenuStrip mnu2 = new ContextMenuStrip(); ToolStripMenuItem mnu2View = new ToolStripMenuItem("View"); // Assign event handlers - mnu2View.Click += new EventHandler(clickView); + mnu2View.Click += clickView; // Add to main context menu mnu2.Items.AddRange(new ToolStripItem[] { mnu2View }); // Assign to datagridview - for (int i = 0; i < pba2.Length; i++) - pba2[i].ContextMenuStrip = mnu2; + foreach (PictureBox p in pba2) + p.ContextMenuStrip = mnu2; + #endregion #region Enable Drag and Drop on the form & tab control. - this.AllowDrop = true; - this.DragEnter += tabMain_DragEnter; - this.DragDrop += tabMain_DragDrop; + AllowDrop = true; + DragEnter += tabMain_DragEnter; + DragDrop += tabMain_DragDrop; // Enable Drag and Drop on each tab. tabMain.AllowDrop = true; - this.tabMain.DragEnter += tabMain_DragEnter; - this.tabMain.DragDrop += tabMain_DragDrop; + tabMain.DragEnter += tabMain_DragEnter; + tabMain.DragDrop += tabMain_DragDrop; foreach (TabPage tab in tabMain.Controls) { @@ -176,10 +176,10 @@ namespace PKHeX init = true; // Splash Screen closes on its own. - this.BringToFront(); - this.WindowState = FormWindowState.Minimized; - this.Show(); - this.WindowState = FormWindowState.Normal; + BringToFront(); + WindowState = FormWindowState.Minimized; + Show(); + WindowState = FormWindowState.Normal; if (HaX) Util.Alert("Illegal mode activated.", "Please behave."); #endregion } @@ -188,26 +188,26 @@ namespace PKHeX public byte[] buff = new byte[260]; // Tab Pokemon Data Storage public byte[] savefile = new byte[0x100000]; public byte[] cyberSAV = new byte[0x65600]; - public static byte[] ramsav = null; - public static bool ramsavloaded = false; + public static byte[] ramsav; + public static bool ramsavloaded; public bool savegame_oras = true; - public bool cybergadget = false; - public bool savLoaded = false; + public bool cybergadget; + public bool savLoaded; public int savindex; public bool savedited; - public string pathSDF = null; - public string path3DS = null; + public string pathSDF; + public string path3DS; public static string Status = "Starting up PKHeX..."; - public static bool HaX = false; - public static bool specialChars = false; // Open Form Tracking + public static bool HaX; + public static bool specialChars; // Open Form Tracking public static Color defaultControlWhite; public static Color defaultControlText; public static int colorizedbox = 32; public static Image mixedHighlight = Util.LayerImage(Properties.Resources.slotSet, Properties.Resources.slotView, 0, 0, 0.5); - public static Image colorizedcolor = null; - public static int colorizedslot = 0; - public static int largeWidth, shortWidth = 0; + public static Image colorizedcolor; + public static int colorizedslot; + public static int largeWidth, shortWidth; public static string eggname = ""; public static string[] gendersymbols = { "♂", "♀", "-" }; public static string[] specieslist = { }; @@ -245,8 +245,8 @@ namespace PKHeX public static int[] saveoffsets = { }; public static string origintrack; public static string curlanguage; - public volatile bool init = false; - public static bool unicode = false; + public volatile bool init; + public static bool unicode; public ToolTip Tip1 = new ToolTip(); public ToolTip Tip2 = new ToolTip(); public ToolTip Tip3 = new ToolTip(); @@ -298,40 +298,38 @@ namespace PKHeX if (!verifiedPKX()) { return; } SavePKX.FileName = TB_Nickname.Text + " - " + TB_PID.Text; DialogResult result = SavePKX.ShowDialog(); - if (result == DialogResult.OK) // Test result. + if (result != DialogResult.OK) return; + string path = SavePKX.FileName; + // Injection Dummy Override + if (path.Contains("pokemon.ekx")) path = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + "pokemon.ekx"; + string ext = Path.GetExtension(path); + + if (File.Exists(path) && !path.Contains("pokemon.ekx")) { - string path = SavePKX.FileName; - // Injection Dummy Override - if (path.Contains("pokemon.ekx")) path = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + "pokemon.ekx"; - string ext = Path.GetExtension(path); + // File already exists, save a .bak + byte[] backupfile = File.ReadAllBytes(path); + File.WriteAllBytes(path + ".bak", backupfile); + } + byte[] pkx = preparepkx(buff); - if (File.Exists(path) && !path.Contains("pokemon.ekx")) - { - // File already exists, save a .bak - byte[] backupfile = File.ReadAllBytes(path); - File.WriteAllBytes(path + ".bak", backupfile); - } - byte[] pkx = preparepkx(buff); - - if ((ext == ".ekx") || (ext == ".bin") || (ext == ".pkx") || (ext == ".ek6") || (ext == ".pk6")) - { - if ((ext == ".ekx") || (ext == ".bin") || (ext == ".ek6")) // User Requested Encrypted File - pkx = PKX.encryptArray(pkx); - File.WriteAllBytes(path, pkx.ToArray()); - } - else - { - Util.Error(String.Format("Foreign File Extension: {0}", ext), "Exporting as encrypted."); + if ((ext == ".ekx") || (ext == ".bin") || (ext == ".pkx") || (ext == ".ek6") || (ext == ".pk6")) + { + if ((ext == ".ekx") || (ext == ".bin") || (ext == ".ek6")) // User Requested Encrypted File pkx = PKX.encryptArray(pkx); - File.WriteAllBytes(path, pkx); - } + File.WriteAllBytes(path, pkx.ToArray()); + } + else + { + Util.Error(String.Format("Foreign File Extension: {0}", ext), "Exporting as encrypted."); + pkx = PKX.encryptArray(pkx); + File.WriteAllBytes(path, pkx); } } private void mainMenuExit(object sender, EventArgs e) { if (ModifierKeys == (Keys.Control | Keys.E)) // Hotkey Triggered if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Quit PKHeX?")) return; - this.Close(); + Close(); } private void mainMenuAbout(object sender, EventArgs e) { @@ -356,20 +354,18 @@ namespace PKHeX // Open Code Generator byte[] formdata = null; if (verifiedPKX()) formdata = preparepkx(buff); - CodeGenerator CodeGen = new PKHeX.CodeGenerator(this, formdata); + CodeGenerator CodeGen = new CodeGenerator(this, formdata); CodeGen.ShowDialog(); byte[] data = CodeGen.returnArray; - if (data != null) + if (data == null) return; + byte[] decdata = PKX.decryptArray(data); + Array.Copy(decdata, buff, 232); + try { populateFields(buff); } + catch { - byte[] decdata = PKX.decryptArray(data); - Array.Copy(decdata, buff, 232); - try { populateFields(buff); } - catch - { - Array.Copy(new byte[232], buff, 232); - populateFields(buff); - Util.Error("Imported code did not decrypt properly", "Please verify that what you imported was correct."); - } + Array.Copy(new byte[232], buff, 232); + populateFields(buff); + Util.Error("Imported code did not decrypt properly", "Please verify that what you imported was correct."); } } private void mainMenuBoxReport(object sender, EventArgs e) @@ -384,13 +380,13 @@ namespace PKHeX unicode = (gendersymbols[0] == "♂"); if (unicode) { - gendersymbols = new string[] { "M", "F", "-" }; + gendersymbols = new[] { "M", "F", "-" }; BTN_Shinytize.Text = "*"; TB_Nickname.Font = TB_OT.Font = TB_OTt2.Font = Label_TID.Font; } else { - gendersymbols = new string[] { "♂", "♀", "-" }; + gendersymbols = new[] { "♂", "♀", "-" }; BTN_Shinytize.Text = "☆"; TB_Nickname.Font = TB_OT.Font = TB_OTt2.Font = PKX.getPKXFont(11); } @@ -456,7 +452,7 @@ namespace PKHeX { if (openXOR(input, path)) // Check if we can load the save via xorpad return; // only if a save is loaded we abort - else if (BitConverter.ToUInt64(input, 0x10) != 0) // encrypted save + if (BitConverter.ToUInt64(input, 0x10) != 0) // encrypted save { Util.Error("PKHeX only edits decrypted save files.", "This save file is not decrypted."); return; } string GameType = "XY"; // Default Game Type to load. @@ -538,14 +534,12 @@ namespace PKHeX // EAD Packet of 363 length byte[] c = new byte[260]; Array.Copy(input, 0x67, c, 0, 260); - input = c; } else if (input.Length == 407 && BitConverter.ToUInt16(input, 0x98) == 0) { // EAD Packet of 407 length byte[] c = new byte[260]; Array.Copy(input, 0x93, c, 0, 260); - input = c; } #endregion #region Box Data @@ -563,13 +557,14 @@ namespace PKHeX for (int i = 0; i < 0x800; i++) { byte[] data = PKX.decryptArray(input.Skip(i).Take(0xE8).ToArray()); - if (PKX.getCHK(data) == BitConverter.ToUInt16(data, 6)) { offset = i; break; } + if (PKX.getCHK(data) != BitConverter.ToUInt16(data, 6)) continue; + offset = i; break; } if (offset < 0) { Util.Alert(path, "Unable to read the input file; not an expected injectiondebug.bin."); return; } C_BoxSelect.SelectedIndex = 0; Array.Copy(input, offset, savefile, SaveGame.Box + 0xE8 * 30 * C_BoxSelect.SelectedIndex, 9 * 30 * 0xE8); setPKXBoxes(); - this.Width = largeWidth; + Width = largeWidth; Util.Alert("Injection Binary loaded."); } #endregion #region RAMSAV @@ -581,7 +576,7 @@ namespace PKHeX if (BitConverter.ToUInt32(input, i) == 0x42454546) { Array.Resize(ref input, 0x70000); break; } bool o = (input.Length == 0x80000); - try { openMAIN(ram2sav.getMAIN(input), path, (o) ? "ORAS" : "XY", o, true); } catch { } + try { openMAIN(ram2sav.getMAIN(input), path, (o) ? "ORAS" : "XY", o, true); } catch { return; } ramsav = (byte[])input.Clone(); } #endregion @@ -589,7 +584,6 @@ namespace PKHeX else if (input.Length == 0x2E60 && BitConverter.ToUInt64(input, 0xE18) != 0 && BitConverter.ToUInt16(input, 0xE12) == 0) { if (Util.Prompt(MessageBoxButtons.YesNo, "Load Batte Video Pokémon data to " + C_BoxSelect.Text + "?", "The first 24 slots will be overwritten.") != DialogResult.Yes) return; - byte[] ekx = new byte[260]; for (int i = 0; i < 24; i++) Array.Copy(input, 0xE18 + 260 * i + (i / 6) * 8, savefile, SaveGame.Box + i * 0xE8 + C_BoxSelect.SelectedIndex * 30 * 0xE8, 0xE8); setPKXBoxes(); @@ -627,7 +621,7 @@ namespace PKHeX // Logic to allow unlocking of Switch SAV // Setup SHA - SHA256 mySHA256 = SHA256Managed.Create(); + SHA256 mySHA256 = SHA256.Create(); // Check both IVFC Hashes byte[] zeroarray = new byte[0x200]; @@ -651,64 +645,54 @@ namespace PKHeX private bool openXOR(byte[] input, string path) { // Detection of stored Decryption XORpads: - if (ModifierKeys != Keys.Control) // Allow bypass via control key. - { - byte[] savID = new byte[0x10]; Array.Copy(input, 0x10, savID, 0, 0x10); - string exepath = System.Windows.Forms.Application.StartupPath; - string xorpath = exepath.Clone().ToString(); - string[] XORpads = Directory.GetFiles(xorpath); + if (ModifierKeys == Keys.Control) return false; // no xorpad compatible + byte[] savID = new byte[0x10]; Array.Copy(input, 0x10, savID, 0, 0x10); + string exepath = Application.StartupPath; + string xorpath = exepath.Clone().ToString(); + string[] XORpads = Directory.GetFiles(xorpath); check: - for (int i = 0; i < XORpads.Length; i++) + foreach (byte[] data in from file in XORpads let fi = new FileInfo(file) where (fi.Name.ToLower().Contains("xorpad") || fi.Name.ToLower().Contains("key")) && (fi.Length == 0x10009C || fi.Length == 0x100000) select File.ReadAllBytes(file)) + { + // Fix xorpad alignment + byte[] xorpad = data; + if (xorpad.Length == 0x10009C) { - FileInfo fi = new FileInfo(XORpads[i]); - if ((fi.Name.ToLower().Contains("xorpad") || fi.Name.ToLower().Contains("key")) && (fi.Length == 0x10009C || fi.Length == 0x100000)) - { - // Load xorpad in - byte[] xorpad = File.ReadAllBytes(XORpads[i]); - - // Fix xorpad alignment - if (xorpad.Length == 0x10009C) - { - Array.Copy(xorpad, 0x9C, xorpad, 0, 0x100000); - Array.Resize(ref xorpad, 0x100000); - } - byte[] xorID = new byte[0x10]; Array.Copy(xorpad, 0x10, xorID, 0, 0x10); - if (xorID.SequenceEqual(savID)) // we match our cart ident. - { - // Set up Decrypted File - byte[] decryptedPS = new byte[0x76000]; - Array.Copy(input, 0x5400, decryptedPS, 0, 0x76000); - - // xor through and decrypt - for (int z = 0; z < 0x76000; z++) - decryptedPS[z] ^= xorpad[0x5400 + z]; - - // Weakly check the validity of the decrypted content - if (BitConverter.ToUInt32(decryptedPS, 0x76000 - 0x1F0) != 0x42454546) // Not OR/AS - if (BitConverter.ToUInt32(decryptedPS, 0x65600 - 0x1F0) != 0x42454546) - continue; // Not X/Y, so continue. - else - Array.Resize(ref decryptedPS, 0x65600); // set to X/Y size - else Array.Resize(ref decryptedPS, 0x76000); // set to ORAS size just in case - - // Save file is now decrypted! Reset the loading variables. - bool oras = (decryptedPS.Length == 0x76000); - string GameType = oras ? "ORAS" : "XY"; - - // Trigger Loading of the decrypted save file. - openMAIN(decryptedPS, path, GameType, oras); - - // Abort the opening of a non-cyber file. - return true; - } - } + Array.Copy(xorpad, 0x9C, xorpad, 0, 0x100000); + Array.Resize(ref xorpad, 0x100000); } - // End file check loop, check the input path for xorpads too if it isn't the same as the EXE (quite common). - if (xorpath == exepath) - { xorpath = Path.GetDirectoryName(path); goto check; } + byte[] xorID = new byte[0x10]; Array.Copy(xorpad, 0x10, xorID, 0, 0x10); + if (!xorID.SequenceEqual(savID)) continue; + + // Set up Decrypted File + byte[] decryptedPS = new byte[0x76000]; + Array.Copy(input, 0x5400, decryptedPS, 0, 0x76000); + + // xor through and decrypt + for (int z = 0; z < 0x76000; z++) + decryptedPS[z] ^= xorpad[0x5400 + z]; + + // Weakly check the validity of the decrypted content + if (BitConverter.ToUInt32(decryptedPS, 0x76000 - 0x1F0) != 0x42454546) // Not OR/AS + if (BitConverter.ToUInt32(decryptedPS, 0x65600 - 0x1F0) != 0x42454546) + continue; // Not X/Y, so continue. + else + Array.Resize(ref decryptedPS, 0x65600); // set to X/Y size + else Array.Resize(ref decryptedPS, 0x76000); // set to ORAS size just in case + + // Save file is now decrypted! Reset the loading variables. + bool oras = (decryptedPS.Length == 0x76000); + string GameType = oras ? "ORAS" : "XY"; + + // Trigger Loading of the decrypted save file. + openMAIN(decryptedPS, path, GameType, oras); + + // Abort the opening of a non-cyber file. + return true; } - return false; // no xorpad compatible + // End file check loop, check the input path for xorpads too if it isn't the same as the EXE (quite common). + if (xorpath != exepath) return false; // no xorpad compatible + xorpath = Path.GetDirectoryName(path); goto check; } private void openSave(bool oras) { @@ -735,7 +719,7 @@ namespace PKHeX GB_SUBE.Visible = !oras; B_OpenSecretBase.Visible = oras; - this.Width = largeWidth; + Width = largeWidth; savLoaded = true; // Indicate audibly the save is loaded System.Media.SystemSounds.Beep.Play(); @@ -916,14 +900,14 @@ namespace PKHeX setCountrySubRegion(CB_Country, "countries"); CB_3DSReg.DataSource = Util.getUnsortedCBList("regions3ds"); CB_Language.DataSource = Util.getUnsortedCBList("languages"); - int[] ball_nums = new int[] { 7, 576, 13, 492, 497, 14, 495, 493, 496, 494, 11, 498, 8, 6, 12, 15, 9, 5, 499, 10, 1, 16 }; - int[] ball_vals = new int[] { 7, 25, 13, 17, 22, 14, 20, 18, 21, 19, 11, 23, 8, 6, 12, 15, 9, 5, 24, 10, 1, 16 }; - CB_Ball.DataSource = Util.getVariedCBList(Util.getCBList(itemlist, new int[] { 4 }, new int[] { 3 }, new int[] { 2 }, new int[] { 1 }), itemlist, ball_nums, ball_vals); + int[] ball_nums = { 7, 576, 13, 492, 497, 14, 495, 493, 496, 494, 11, 498, 8, 6, 12, 15, 9, 5, 499, 10, 1, 16 }; + int[] ball_vals = { 7, 25, 13, 17, 22, 14, 20, 18, 21, 19, 11, 23, 8, 6, 12, 15, 9, 5, 24, 10, 1, 16 }; + CB_Ball.DataSource = Util.getVariedCBList(Util.getCBList(itemlist, new[] { 4 }, new[] { 3 }, new[] { 2 }, new[] { 1 }), itemlist, ball_nums, ball_vals); CB_HeldItem.DataSource = Util.getCBList(itemlist, (DEV_Ability.Enabled) ? null : Legal.Items_Held); CB_Species.DataSource = Util.getCBList(specieslist, null); DEV_Ability.DataSource = Util.getCBList(abilitylist, null); CB_Nature.DataSource = Util.getCBList(natures, null); - CB_EncounterType.DataSource = Util.getCBList(encountertypelist, new int[] { 0 }, Legal.Gen4EncounterTypes); + CB_EncounterType.DataSource = Util.getCBList(encountertypelist, new[] { 0 }, Legal.Gen4EncounterTypes); CB_GameOrigin.DataSource = Util.getCBList(gamelist, Legal.Games_6oras, Legal.Games_6xy, Legal.Games_5, Legal.Games_4, Legal.Games_4e, Legal.Games_4r, Legal.Games_3, Legal.Games_3e, Legal.Games_3r, Legal.Games_3s); string[] hptypes = new string[types.Length - 2]; Array.Copy(types, 1, hptypes, 0, hptypes.Length); @@ -932,7 +916,7 @@ namespace PKHeX // Set the Move ComboBoxes too.. { var moves = Util.getCBList(movelist, null); - foreach (ComboBox cb in new ComboBox[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4, CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4 }) + foreach (ComboBox cb in new[] { CB_Move1, CB_Move2, CB_Move3, CB_Move4, CB_RelearnMove1, CB_RelearnMove2, CB_RelearnMove3, CB_RelearnMove4 }) { cb.DisplayMember = "Text"; cb.ValueMember = "Value"; cb.DataSource = new BindingSource(moves, null); @@ -1027,7 +1011,7 @@ namespace PKHeX string ot = Util.TrimFromZero(Encoding.Unicode.GetString(buff, 0xB0, 24)); // 0xC8, 0xC9 - unused int OTfriendship = buff[0xCA]; - int OTaffection = buff[0xCB]; // Handled by Memory Editor + // int OTaffection = buff[0xCB]; // Handled by Memory Editor // 0xCC, 0xCD, 0xCE, 0xCF, 0xD0 int egg_year = buff[0xD1]; int egg_month = buff[0xD2]; @@ -1135,8 +1119,8 @@ namespace PKHeX TB_MetLevel.Text = metlevel.ToString(); // Reset Label and ComboBox visibility, as well as non-data checked status. - Label_PKRS.Visible = CB_PKRSStrain.Visible = CHK_Infected.Checked = !(PKRS_Strain == 0); - Label_PKRSdays.Visible = CB_PKRSDays.Visible = !(PKRS_Duration == 0); + Label_PKRS.Visible = CB_PKRSStrain.Visible = CHK_Infected.Checked = PKRS_Strain != 0; + Label_PKRSdays.Visible = CB_PKRSDays.Visible = PKRS_Duration != 0; CHK_Cured.Checked = (PKRS_Strain > 0 && PKRS_Duration == 0); // Set SelectedIndexes for PKRS @@ -1176,6 +1160,10 @@ namespace PKHeX CB_PPu2.SelectedIndex = move2_ppu; CB_PPu3.SelectedIndex = move3_ppu; CB_PPu4.SelectedIndex = move4_ppu; + TB_PP1.Text = move1_pp.ToString(); + TB_PP2.Text = move2_pp.ToString(); + TB_PP3.Text = move3_pp.ToString(); + TB_PP4.Text = move4_pp.ToString(); int level = PKX.getLevel(species, ref exp); TB_Level.Text = level.ToString(); @@ -1216,9 +1204,8 @@ namespace PKHeX Util.Alert("PKX File has an invalid checksum."); } // General Use Functions shared by other Forms // - public void setCountrySubRegion(object sender, string type) + public void setCountrySubRegion(ComboBox CB, string type) { - ComboBox CB = sender as ComboBox; int index = CB.SelectedIndex; // fix for Korean / Chinese being swapped string cl = curlanguage + ""; @@ -1241,10 +1228,10 @@ namespace PKHeX // If no forms & not Scatterbug / Spewpa... if (!hasForms) { - cb.DataSource = new[] { new { Text = "", Value = 0 }, + cb.DataSource = new[] { new { Text = "", Value = 0 } };} // Mega List - else if (Array.IndexOf(new int[] + else if (Array.IndexOf(new[] { // XY 003, 009, 065, 094, 115, 127, 130, 142, 181, 212, 214, 229, 248, 257, 282, 303, 306, 308, 310, 354, 359, 380, 381, 445, 448, 460, // ORAS @@ -1255,256 +1242,298 @@ namespace PKHeX new { Text = forms[723], Value = 1}, // Mega };} // MegaXY List - else if ((species == 6) || (species == 150)) { // ... - cb.DataSource = new[] { - new { Text = types[000], Value = 0}, // Normal - new { Text = forms[724], Value = 1}, // Mega X - new { Text = forms[725], Value = 2}, // Mega Y - };} - // Gender List - else if (species == 678) { // Meowstic - cb.DataSource = new[] { - new { Text = gendersymbols[0], Value = 0 }, // Male - new { Text = gendersymbols[1], Value = 1 }, // Female - };} - // Regular Form List - else if (species == 025) { // Pikachu - cb.DataSource = new[] { - new { Text = types[000], Value = 0}, // Normal - new { Text = forms[729], Value = 1}, // Rockstar - new { Text = forms[730], Value = 2}, // Belle - new { Text = forms[731], Value = 3}, // Pop - new { Text = forms[732], Value = 4}, // PhD - new { Text = forms[733], Value = 5}, // Libre - new { Text = forms[734], Value = 6}, // Cosplay - };} - else if (species == 201) { // Unown - cb.DataSource = new[] { - new { Text = "A", Value = 0 }, - new { Text = "B", Value = 1 }, - new { Text = "C", Value = 2 }, - new { Text = "D", Value = 3 }, - new { Text = "E", Value = 4 }, - new { Text = "F", Value = 5 }, - new { Text = "G", Value = 6 }, - new { Text = "H", Value = 7 }, - new { Text = "I", Value = 8 }, - new { Text = "J", Value = 9 }, - new { Text = "K", Value = 10 }, - new { Text = "L", Value = 11 }, - new { Text = "M", Value = 12 }, - new { Text = "N", Value = 13 }, - new { Text = "O", Value = 14 }, - new { Text = "P", Value = 15 }, - new { Text = "Q", Value = 16 }, - new { Text = "R", Value = 17 }, - new { Text = "S", Value = 18 }, - new { Text = "T", Value = 19 }, - new { Text = "U", Value = 20 }, - new { Text = "V", Value = 21 }, - new { Text = "W", Value = 22 }, - new { Text = "X", Value = 23 }, - new { Text = "Y", Value = 24 }, - new { Text = "Z", Value = 25 }, - new { Text = "!", Value = 26 }, - new { Text = "?", Value = 27 }, - };} - else if (species == 351) { // Castform - cb.DataSource = new[] { - new { Text = types[0], Value = 0 }, // Normal - new { Text = forms[789], Value = 1 }, // Sunny - new { Text = forms[790], Value = 2 }, // Rainy - new { Text = forms[791], Value = 3 }, // Snowy - };} - else if (species == 382 || species == 383) { // Kyogre/Groudon - cb.DataSource = new[] { - new { Text = types[0], Value = 0}, // Normal - new { Text = forms[800], Value = 1}, // Primal - };} - else if (species == 386) { // Deoxys - cb.DataSource = new[] { - new { Text = types[0], Value = 0 }, // Normal - new { Text = forms[802], Value = 1 }, // Attack - new { Text = forms[803], Value = 2 }, // Defense - new { Text = forms[804], Value = 3 }, // Speed - };} - else if ((species == 412) || (species == 413)) { // Wormadam - cb.DataSource = new[] { - new { Text = forms[412], Value = 0 }, // Plant - new { Text = forms[805], Value = 1 }, // Sandy - new { Text = forms[806], Value = 2 }, // Trash - };} - else if (species == 421) { // Cherrim - cb.DataSource = new[] { - new { Text = forms[421], Value = 0 }, // Overcast - new { Text = forms[809], Value = 1 }, // Sunshine - };} - else if ((species == 422) || (species == 423)) { // Shellos/Gastrodon - cb.DataSource = new[] { - new { Text = forms[422], Value = 0 }, // West - new { Text = forms[811], Value = 1 }, // East - };} - else if (species == 479) { // Rotom - cb.DataSource = new[] { - new { Text = types[0], Value = 0 }, // Normal - new { Text = forms[817], Value = 1 }, // Heat - new { Text = forms[818], Value = 2 }, // Wash - new { Text = forms[819], Value = 3 }, // Frost - new { Text = forms[820], Value = 4 }, // Fan - new { Text = forms[821], Value = 5 }, // Mow - };} - else if (species == 487) { // Giratina - cb.DataSource = new[] { - new { Text = forms[487], Value = 0 }, // Altered - new { Text = forms[822], Value = 1 }, // Origin - };} - else if (species == 492) { // Shaymin - cb.DataSource = new[] { - new { Text = forms[492], Value = 0 }, // Land - new { Text = forms[823], Value = 1 }, // Sky - };} - else if (species == 493) { // Arceus - cb.DataSource = new[] { - new { Text = types[0], Value = 0 }, // Normal - new { Text = types[1], Value = 1 }, // Fighting - new { Text = types[2], Value = 2 }, // Flying - new { Text = types[3], Value = 3 }, // Poison - new { Text = types[4], Value = 4 }, // etc - new { Text = types[5], Value = 5 }, - new { Text = types[6], Value = 6 }, - new { Text = types[7], Value = 7 }, - new { Text = types[8], Value = 8 }, - new { Text = types[9], Value = 9 }, - new { Text = types[10], Value = 10 }, - new { Text = types[11], Value = 11 }, - new { Text = types[12], Value = 12 }, - new { Text = types[13], Value = 13 }, - new { Text = types[14], Value = 14 }, - new { Text = types[15], Value = 15 }, - new { Text = types[16], Value = 16 }, - new { Text = types[17], Value = 17 }, - };} - else if (species == 550) { // Basculin - cb.DataSource = new[] { - new { Text = forms[550], Value = 0 }, // Red - new { Text = forms[842], Value = 1 }, // Blue - };} - else if (species == 555) { // Darmanitan - cb.DataSource = new[] { - new { Text = forms[555], Value = 0 }, // Standard - new { Text = forms[843], Value = 1 }, // Zen - };} - else if ((species == 585) || (species == 586)) { // Deerling/Sawsbuck - cb.DataSource = new[] { - new { Text = forms[585], Value = 0 }, // Spring - new { Text = forms[844], Value = 1 }, // Summer - new { Text = forms[845], Value = 2 }, // Autumn - new { Text = forms[846], Value = 3 }, // Winter - };} - else if ((species == 641) || (species == 642) || (species == 645)) { // Genies - cb.DataSource = new[] { - new { Text = forms[641], Value = 0 }, // Incarnate - new { Text = forms[852], Value = 1 }, // Therian - };} - else if (species == 646) { // Kyurem - cb.DataSource = new[] { - new { Text = types[0], Value = 0 }, // Normal - new { Text = forms[853], Value = 1 }, // White - new { Text = forms[854], Value = 2 }, // Black - };} - else if (species == 647) { // Keldeo - cb.DataSource = new[] { - new { Text = forms[647], Value = 0 }, // Ordinary - new { Text = forms[855], Value = 1 }, // Resolute - };} - else if (species == 648) { // Meloetta - cb.DataSource = new[] { - new { Text = forms[648], Value = 0 }, // Aria - new { Text = forms[856], Value = 1 }, // Pirouette - };} - else if (species == 649) { // Genesect - cb.DataSource = new[] { - new { Text = types[0], Value = 0 }, // Normal - new { Text = types[10], Value = 1 }, // Douse - new { Text = types[12], Value = 2 }, // Shock - new { Text = types[9], Value = 3 }, // Burn - new { Text = types[14], Value = 4 }, // Chill - };} - else if ((species == 664) || (species == 665) || (species == 666)) { // Vivillon + prevos - cb.DataSource = new[] { - new { Text = forms[666], Value = 0 }, // Icy Snow - new { Text = forms[861], Value = 1 }, // Polar - new { Text = forms[862], Value = 2 }, // Tundra - new { Text = forms[863], Value = 3 }, // Continental - new { Text = forms[864], Value = 4 }, // Garden - new { Text = forms[865], Value = 5 }, // Elegant - new { Text = forms[866], Value = 6 }, // Meadow - new { Text = forms[867], Value = 7 }, // Modern - new { Text = forms[868], Value = 8 }, // Marine - new { Text = forms[869], Value = 9 }, // Archipelago - new { Text = forms[870], Value = 10 }, // High-Plains - new { Text = forms[871], Value = 11 }, // Sandstorm - new { Text = forms[872], Value = 12 }, // River - new { Text = forms[873], Value = 13 }, // Monsoon - new { Text = forms[874], Value = 14 }, // Savannah - new { Text = forms[875], Value = 15 }, // Sun - new { Text = forms[876], Value = 16 }, // Ocean - new { Text = forms[877], Value = 17 }, // Jungle - new { Text = forms[878], Value = 18 }, // Fancy - new { Text = forms[879], Value = 19 }, // Poké Ball - };} - else if ((species == 669) || (species == 671)) { // Flabébé - cb.DataSource = new[] { - new { Text = forms[669], Value = 0 }, // Red - new { Text = forms[884], Value = 1 }, // Yellow - new { Text = forms[885], Value = 2 }, // Orange - new { Text = forms[886], Value = 3 }, // Blue - new { Text = forms[887], Value = 4 }, // White - };} - else if (species == 670) { // Floette - cb.DataSource = new[] { - new { Text = forms[669], Value = 0 }, // Red - new { Text = forms[884], Value = 1 }, // Yellow - new { Text = forms[885], Value = 2 }, // Orange - new { Text = forms[886], Value = 3 }, // Blue - new { Text = forms[887], Value = 4 }, // White - new { Text = forms[888], Value = 5 }, // Eternal - };} - else if (species == 676) { // Furfrou - cb.DataSource = new[] { - new { Text = forms[676], Value = 0 }, // Natural - new { Text = forms[893], Value = 1 }, // Heart - new { Text = forms[894], Value = 2 }, // Star - new { Text = forms[895], Value = 3 }, // Diamond - new { Text = forms[896], Value = 4 }, // Deputante - new { Text = forms[897], Value = 5 }, // Matron - new { Text = forms[898], Value = 6 }, // Dandy - new { Text = forms[899], Value = 7 }, // La Reine - new { Text = forms[900], Value = 8 }, // Kabuki - new { Text = forms[901], Value = 9 }, // Pharaoh - };} - else if (species == 681) { // Aegislash - cb.DataSource = new[] { - new { Text = forms[681], Value = 0 }, // Shield - new { Text = forms[903], Value = 1 }, // Blade - };} - else if ((species == 710) || (species == 711)) { // Pumpkaboo/Goregeist - cb.DataSource = new[] { - new { Text = forms[904], Value = 0 }, // Small - new { Text = forms[710], Value = 1 }, // Average - new { Text = forms[905], Value = 2 }, // Large - new { Text = forms[906], Value = 3 }, // Super - };} - else if (species == 716) { // Xerneas - cb.DataSource = new[] { - new { Text = types[0], Value = 0}, // Normal - new { Text = forms[910], Value = 1}, // Active - };} - else if (species == 720) { // Hoopa - cb.DataSource = new[] { - new { Text = types[0], Value = 0}, // Normal - new { Text = forms[912], Value = 1}, // Unbound - };} + else switch (species) + { + case 6: + case 150: + cb.DataSource = new[] { + new { Text = types[000], Value = 0}, // Normal + new { Text = forms[724], Value = 1}, // Mega X + new { Text = forms[725], Value = 2}, // Mega Y + }; + break; + case 025: + cb.DataSource = new[] { + new { Text = types[000], Value = 0}, // Normal + new { Text = forms[729], Value = 1}, // Rockstar + new { Text = forms[730], Value = 2}, // Belle + new { Text = forms[731], Value = 3}, // Pop + new { Text = forms[732], Value = 4}, // PhD + new { Text = forms[733], Value = 5}, // Libre + new { Text = forms[734], Value = 6}, // Cosplay + }; + break; + case 201: + cb.DataSource = new[] { + new { Text = "A", Value = 0 }, + new { Text = "B", Value = 1 }, + new { Text = "C", Value = 2 }, + new { Text = "D", Value = 3 }, + new { Text = "E", Value = 4 }, + new { Text = "F", Value = 5 }, + new { Text = "G", Value = 6 }, + new { Text = "H", Value = 7 }, + new { Text = "I", Value = 8 }, + new { Text = "J", Value = 9 }, + new { Text = "K", Value = 10 }, + new { Text = "L", Value = 11 }, + new { Text = "M", Value = 12 }, + new { Text = "N", Value = 13 }, + new { Text = "O", Value = 14 }, + new { Text = "P", Value = 15 }, + new { Text = "Q", Value = 16 }, + new { Text = "R", Value = 17 }, + new { Text = "S", Value = 18 }, + new { Text = "T", Value = 19 }, + new { Text = "U", Value = 20 }, + new { Text = "V", Value = 21 }, + new { Text = "W", Value = 22 }, + new { Text = "X", Value = 23 }, + new { Text = "Y", Value = 24 }, + new { Text = "Z", Value = 25 }, + new { Text = "!", Value = 26 }, + new { Text = "?", Value = 27 }, + }; + break; + case 351: + cb.DataSource = new[] { + new { Text = types[0], Value = 0 }, // Normal + new { Text = forms[789], Value = 1 }, // Sunny + new { Text = forms[790], Value = 2 }, // Rainy + new { Text = forms[791], Value = 3 }, // Snowy + }; + break; + case 382: + case 383: + cb.DataSource = new[] { + new { Text = types[0], Value = 0}, // Normal + new { Text = forms[800], Value = 1}, // Primal + }; + break; + case 386: + cb.DataSource = new[] { + new { Text = types[0], Value = 0 }, // Normal + new { Text = forms[802], Value = 1 }, // Attack + new { Text = forms[803], Value = 2 }, // Defense + new { Text = forms[804], Value = 3 }, // Speed + }; + break; + case 412: + case 413: + cb.DataSource = new[] { + new { Text = forms[412], Value = 0 }, // Plant + new { Text = forms[805], Value = 1 }, // Sandy + new { Text = forms[806], Value = 2 }, // Trash + }; + break; + case 421: + cb.DataSource = new[] { + new { Text = forms[421], Value = 0 }, // Overcast + new { Text = forms[809], Value = 1 }, // Sunshine + }; + break; + case 422: + case 423: + cb.DataSource = new[] { + new { Text = forms[422], Value = 0 }, // West + new { Text = forms[811], Value = 1 }, // East + }; + break; + case 479: + cb.DataSource = new[] { + new { Text = types[0], Value = 0 }, // Normal + new { Text = forms[817], Value = 1 }, // Heat + new { Text = forms[818], Value = 2 }, // Wash + new { Text = forms[819], Value = 3 }, // Frost + new { Text = forms[820], Value = 4 }, // Fan + new { Text = forms[821], Value = 5 }, // Mow + }; + break; + case 487: + cb.DataSource = new[] { + new { Text = forms[487], Value = 0 }, // Altered + new { Text = forms[822], Value = 1 }, // Origin + }; + break; + case 492: + cb.DataSource = new[] { + new { Text = forms[492], Value = 0 }, // Land + new { Text = forms[823], Value = 1 }, // Sky + }; + break; + case 493: + cb.DataSource = new[] { + new { Text = types[0], Value = 0 }, // Normal + new { Text = types[1], Value = 1 }, // Fighting + new { Text = types[2], Value = 2 }, // Flying + new { Text = types[3], Value = 3 }, // Poison + new { Text = types[4], Value = 4 }, // etc + new { Text = types[5], Value = 5 }, + new { Text = types[6], Value = 6 }, + new { Text = types[7], Value = 7 }, + new { Text = types[8], Value = 8 }, + new { Text = types[9], Value = 9 }, + new { Text = types[10], Value = 10 }, + new { Text = types[11], Value = 11 }, + new { Text = types[12], Value = 12 }, + new { Text = types[13], Value = 13 }, + new { Text = types[14], Value = 14 }, + new { Text = types[15], Value = 15 }, + new { Text = types[16], Value = 16 }, + new { Text = types[17], Value = 17 }, + }; + break; + case 550: + cb.DataSource = new[] { + new { Text = forms[550], Value = 0 }, // Red + new { Text = forms[842], Value = 1 }, // Blue + }; + break; + case 555: + cb.DataSource = new[] { + new { Text = forms[555], Value = 0 }, // Standard + new { Text = forms[843], Value = 1 }, // Zen + }; + break; + case 585: + case 586: + cb.DataSource = new[] { + new { Text = forms[585], Value = 0 }, // Spring + new { Text = forms[844], Value = 1 }, // Summer + new { Text = forms[845], Value = 2 }, // Autumn + new { Text = forms[846], Value = 3 }, // Winter + }; + break; + case 641: + case 642: + case 645: + cb.DataSource = new[] { + new { Text = forms[641], Value = 0 }, // Incarnate + new { Text = forms[852], Value = 1 }, // Therian + }; + break; + case 646: + cb.DataSource = new[] { + new { Text = types[0], Value = 0 }, // Normal + new { Text = forms[853], Value = 1 }, // White + new { Text = forms[854], Value = 2 }, // Black + }; + break; + case 647: + cb.DataSource = new[] { + new { Text = forms[647], Value = 0 }, // Ordinary + new { Text = forms[855], Value = 1 }, // Resolute + }; + break; + case 648: + cb.DataSource = new[] { + new { Text = forms[648], Value = 0 }, // Aria + new { Text = forms[856], Value = 1 }, // Pirouette + }; + break; + case 649: + cb.DataSource = new[] { + new { Text = types[0], Value = 0 }, // Normal + new { Text = types[10], Value = 1 }, // Douse + new { Text = types[12], Value = 2 }, // Shock + new { Text = types[9], Value = 3 }, // Burn + new { Text = types[14], Value = 4 }, // Chill + }; + break; + case 664: + case 665: + case 666: + cb.DataSource = new[] { + new { Text = forms[666], Value = 0 }, // Icy Snow + new { Text = forms[861], Value = 1 }, // Polar + new { Text = forms[862], Value = 2 }, // Tundra + new { Text = forms[863], Value = 3 }, // Continental + new { Text = forms[864], Value = 4 }, // Garden + new { Text = forms[865], Value = 5 }, // Elegant + new { Text = forms[866], Value = 6 }, // Meadow + new { Text = forms[867], Value = 7 }, // Modern + new { Text = forms[868], Value = 8 }, // Marine + new { Text = forms[869], Value = 9 }, // Archipelago + new { Text = forms[870], Value = 10 }, // High-Plains + new { Text = forms[871], Value = 11 }, // Sandstorm + new { Text = forms[872], Value = 12 }, // River + new { Text = forms[873], Value = 13 }, // Monsoon + new { Text = forms[874], Value = 14 }, // Savannah + new { Text = forms[875], Value = 15 }, // Sun + new { Text = forms[876], Value = 16 }, // Ocean + new { Text = forms[877], Value = 17 }, // Jungle + new { Text = forms[878], Value = 18 }, // Fancy + new { Text = forms[879], Value = 19 }, // Poké Ball + }; + break; + case 669: + case 671: + cb.DataSource = new[] { + new { Text = forms[669], Value = 0 }, // Red + new { Text = forms[884], Value = 1 }, // Yellow + new { Text = forms[885], Value = 2 }, // Orange + new { Text = forms[886], Value = 3 }, // Blue + new { Text = forms[887], Value = 4 }, // White + }; + break; + case 670: + cb.DataSource = new[] { + new { Text = forms[669], Value = 0 }, // Red + new { Text = forms[884], Value = 1 }, // Yellow + new { Text = forms[885], Value = 2 }, // Orange + new { Text = forms[886], Value = 3 }, // Blue + new { Text = forms[887], Value = 4 }, // White + new { Text = forms[888], Value = 5 }, // Eternal + }; + break; + case 676: + cb.DataSource = new[] { + new { Text = forms[676], Value = 0 }, // Natural + new { Text = forms[893], Value = 1 }, // Heart + new { Text = forms[894], Value = 2 }, // Star + new { Text = forms[895], Value = 3 }, // Diamond + new { Text = forms[896], Value = 4 }, // Deputante + new { Text = forms[897], Value = 5 }, // Matron + new { Text = forms[898], Value = 6 }, // Dandy + new { Text = forms[899], Value = 7 }, // La Reine + new { Text = forms[900], Value = 8 }, // Kabuki + new { Text = forms[901], Value = 9 }, // Pharaoh + }; + break; + case 678: + cb.DataSource = new[] { + new { Text = gendersymbols[0], Value = 0 }, // Male + new { Text = gendersymbols[1], Value = 1 }, // Female + }; + break; + case 681: + cb.DataSource = new[] { + new { Text = forms[681], Value = 0 }, // Shield + new { Text = forms[903], Value = 1 }, // Blade + }; + break; + case 710: + case 711: + cb.DataSource = new[] { + new { Text = forms[904], Value = 0 }, // Small + new { Text = forms[710], Value = 1 }, // Average + new { Text = forms[905], Value = 2 }, // Large + new { Text = forms[906], Value = 3 }, // Super + }; + break; + case 716: + cb.DataSource = new[] { + new { Text = types[0], Value = 0}, // Normal + new { Text = forms[910], Value = 1}, // Active + }; + break; + case 720: + cb.DataSource = new[] { + new { Text = types[0], Value = 0}, // Normal + new { Text = forms[912], Value = 1}, // Unbound + }; + break; + } } public void setAbilityList(MaskedTextBox tb_abil, int species, ComboBox cb_abil, ComboBox cb_forme) { @@ -1516,14 +1545,15 @@ namespace PKHeX byte[] abils = PKX.getAbilities(species, form); // Build Ability List - List ability_list = new List(); - ability_list.Add(abilitylist[abils[0]] + " (1)"); - ability_list.Add(abilitylist[abils[1]] + " (2)"); - ability_list.Add(abilitylist[abils[2]] + " (H)"); + List ability_list = new List + { + abilitylist[abils[0]] + " (1)", + abilitylist[abils[1]] + " (2)", + abilitylist[abils[2]] + " (H)" + }; cb_abil.DataSource = ability_list; - if (newabil < 3) cb_abil.SelectedIndex = newabil; - else cb_abil.SelectedIndex = 0; + cb_abil.SelectedIndex = newabil < 3 ? newabil : 0; } // PKX Data Calculation Functions // private void setIsShiny() @@ -1542,12 +1572,12 @@ namespace PKHeX PictureBox[] pba = { PB_Mark1, PB_Mark2, PB_Mark3, PB_Mark4, PB_Mark5, PB_Mark6 }; CheckBox[] cba = { CHK_Circle, CHK_Triangle, CHK_Square, CHK_Heart, CHK_Star, CHK_Diamond }; for (int i = 0; i < 6; i++) - pba[i].Image = Util.ChangeOpacity(pba[i].InitialImage, (float)(Convert.ToUInt16(cba[i].Checked)) * 0.9 + 0.1); + pba[i].Image = Util.ChangeOpacity(pba[i].InitialImage, (Convert.ToUInt16(cba[i].Checked)) * 0.9 + 0.1); - PB_MarkShiny.Image = Util.ChangeOpacity(PB_MarkShiny.InitialImage, (float)(Convert.ToUInt16(!BTN_Shinytize.Enabled)) * 0.9 + 0.1); - PB_MarkCured.Image = Util.ChangeOpacity(PB_MarkCured.InitialImage, (float)(Convert.ToUInt16(CHK_Cured.Checked)) * 0.9 + 0.1); + PB_MarkShiny.Image = Util.ChangeOpacity(PB_MarkShiny.InitialImage, (Convert.ToUInt16(!BTN_Shinytize.Enabled)) * 0.9 + 0.1); + PB_MarkCured.Image = Util.ChangeOpacity(PB_MarkCured.InitialImage, (Convert.ToUInt16(CHK_Cured.Checked)) * 0.9 + 0.1); int gameindex = Util.getIndex(CB_GameOrigin); - PB_MarkPentagon.Image = Util.ChangeOpacity(PB_MarkPentagon.InitialImage, (float)(Convert.ToUInt16(gameindex == 24 || gameindex == 25 || gameindex == 26 || gameindex == 27)) * 0.9 + 0.1); + PB_MarkPentagon.Image = Util.ChangeOpacity(PB_MarkPentagon.InitialImage, (Convert.ToUInt16(gameindex == 24 || gameindex == 25 || gameindex == 26 || gameindex == 27)) * 0.9 + 0.1); } // Clicked Label Shortcuts // private void clickQR(object sender, EventArgs e) @@ -1563,15 +1593,15 @@ namespace PKHeX string webURL = "http://api.qrserver.com/v1/read-qr-code/?fileurl=" + System.Web.HttpUtility.UrlEncode(address); try { - System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(webURL); + System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(webURL); System.Net.HttpWebResponse httpWebReponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse(); var reader = new StreamReader(httpWebReponse.GetResponseStream()); string data = reader.ReadToEnd(); if (data.Contains("could not find")) { Util.Alert("Reader could not find QR data in the image."); return; } // Quickly convert the json response to a data string - string pkstr = data.Substring(data.IndexOf("#") + 1); // Trim intro - pkstr = pkstr.Substring(0, pkstr.IndexOf("\",\"error\":null}]}]")); // Trim outro - if (pkstr.Contains("nQR-Code:")) pkstr = pkstr.Substring(0, pkstr.IndexOf("nQR-Code:")); // Remove multiple QR codes in same image + string pkstr = data.Substring(data.IndexOf("#", StringComparison.Ordinal) + 1); // Trim intro + pkstr = pkstr.Substring(0, pkstr.IndexOf("\",\"error\":null}]}]", StringComparison.Ordinal)); // Trim outro + if (pkstr.Contains("nQR-Code:")) pkstr = pkstr.Substring(0, pkstr.IndexOf("nQR-Code:", StringComparison.Ordinal)); // Remove multiple QR codes in same image pkstr = pkstr.Replace("\\", ""); // Rectify response byte[] ekx; @@ -1595,7 +1625,7 @@ namespace PKHeX Array.Resize(ref ekx, 232); - string server = "http://loadcode.projectpokemon.org/b1s1.html#"; // Rehosted with permission from LC/MS -- massive thanks! + const string server = "http://loadcode.projectpokemon.org/b1s1.html#"; // Rehosted with permission from LC/MS -- massive thanks! string qrdata = Convert.ToBase64String(ekx); string message = server + qrdata; string webURL = "http://chart.apis.google.com/chart?chs=365x365&cht=qr&chl=" + System.Web.HttpUtility.UrlEncode(message); @@ -1603,10 +1633,10 @@ namespace PKHeX Image qr = null; try { - System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(webURL); + System.Net.HttpWebRequest httpWebRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(webURL); System.Net.HttpWebResponse httpWebReponse = (System.Net.HttpWebResponse)httpWebRequest.GetResponse(); Stream stream = httpWebReponse.GetResponseStream(); - qr = Image.FromStream(stream); + if (stream != null) qr = Image.FromStream(stream); } catch { @@ -1646,18 +1676,11 @@ namespace PKHeX private void clickFriendship(object sender, EventArgs e) { if (ModifierKeys == Keys.Control) // prompt to reset - { - if (buff[0x93] == 0) - TB_Friendship.Text = buff[0xCA].ToString(); - else TB_Friendship.Text = buff[0xA2].ToString(); - - return; - } - else if (TB_Friendship.Text == "255") // if it's maxed, set it to base - TB_Friendship.Text = PKX.getBaseFriendship(Util.getIndex(CB_Species)).ToString(); - else // not reset, not maxed, so max - TB_Friendship.Text = "255"; + TB_Friendship.Text = buff[0x93] == 0 ? buff[0xCA].ToString() : buff[0xA2].ToString(); + else + TB_Friendship.Text = TB_Friendship.Text == "255" ? PKX.getBaseFriendship(Util.getIndex(CB_Species)).ToString() : "255"; } + private void clickGender(object sender, EventArgs e) { // Get Gender Threshold @@ -1667,15 +1690,14 @@ namespace PKHeX if (gt == 255 || gt == 0 || gt == 254) // Single gender/genderless return; - if (gt < 255) // If not a single gender(less) species: (should be <254 but whatever, 255 never happens^) - { - Label_Gender.Text = gendersymbols[PKX.getGender(Label_Gender.Text) ^ 1]; + if (gt >= 255) return; + // If not a single gender(less) species: (should be <254 but whatever, 255 never happens^) + Label_Gender.Text = gendersymbols[PKX.getGender(Label_Gender.Text) ^ 1]; - if (PKX.getGender(CB_Form.Text) < 2) // Gendered Forms - CB_Form.SelectedIndex = PKX.getGender(Label_Gender.Text); + if (PKX.getGender(CB_Form.Text) < 2) // Gendered Forms + CB_Form.SelectedIndex = PKX.getGender(Label_Gender.Text); - getQuickFiller(dragout); - } + getQuickFiller(dragout); } private void clickPPUps(object sender, EventArgs e) { @@ -1696,34 +1718,31 @@ namespace PKHeX private void clickOT(object sender, EventArgs e) { string OT = Util.TrimFromZero(Encoding.Unicode.GetString(savefile, SaveGame.TrainerCard + 0x48 + savindex * 0x7F000, 0x1A)); - if (OT.Length > 0) - { - TB_OT.Text = OT; - int savshift = 0x7F000 * savindex; - // Set Gender Label - int g6trgend = savefile[SaveGame.TrainerCard + 0x5 + savshift]; - if (g6trgend == 1) - Label_OTGender.Text = gendersymbols[1]; // ♀ - else Label_OTGender.Text = gendersymbols[0]; // ♂ + if (OT.Length <= 0) return; - // Get TID/SID - TB_TID.Text = BitConverter.ToUInt16(savefile, SaveGame.TrainerCard + 0 + savshift).ToString(); - TB_SID.Text = BitConverter.ToUInt16(savefile, SaveGame.TrainerCard + 2 + savshift).ToString(); - int game = savefile[SaveGame.TrainerCard + 0x4 + savshift]; - int subreg = savefile[SaveGame.TrainerCard + 0x26 + savshift]; - int country = savefile[SaveGame.TrainerCard + 0x27 + savshift]; - int _3DSreg = savefile[SaveGame.TrainerCard + 0x2C + savshift]; - int lang = savefile[SaveGame.TrainerCard + 0x2D + savshift]; + TB_OT.Text = OT; + int savshift = 0x7F000 * savindex; + // Set Gender Label + int g6trgend = savefile[SaveGame.TrainerCard + 0x5 + savshift]; + Label_OTGender.Text = g6trgend == 1 ? gendersymbols[1] : gendersymbols[0]; - // CB_GameOrigin.SelectedValue = game; + // Get TID/SID + TB_TID.Text = BitConverter.ToUInt16(savefile, SaveGame.TrainerCard + 0 + savshift).ToString(); + TB_SID.Text = BitConverter.ToUInt16(savefile, SaveGame.TrainerCard + 2 + savshift).ToString(); + int game = savefile[SaveGame.TrainerCard + 0x4 + savshift]; + int subreg = savefile[SaveGame.TrainerCard + 0x26 + savshift]; + int country = savefile[SaveGame.TrainerCard + 0x27 + savshift]; + int _3DSreg = savefile[SaveGame.TrainerCard + 0x2C + savshift]; + int lang = savefile[SaveGame.TrainerCard + 0x2D + savshift]; - CB_GameOrigin.SelectedValue = game; - CB_SubRegion.SelectedValue = subreg; - CB_Country.SelectedValue = country; - CB_3DSReg.SelectedValue = _3DSreg; - CB_Language.SelectedValue = lang; - updateNickname(null, null); - } + // CB_GameOrigin.SelectedValue = game; + + CB_GameOrigin.SelectedValue = game; + CB_SubRegion.SelectedValue = subreg; + CB_Country.SelectedValue = country; + CB_3DSReg.SelectedValue = _3DSreg; + CB_Language.SelectedValue = lang; + updateNickname(null, null); } private void clickCT(object sender, EventArgs e) { @@ -1750,13 +1769,11 @@ namespace PKHeX private void clickTRGender(object sender, EventArgs e) { Label lbl = sender as Label; - if (lbl.Text == "") - return; - else // set gender label (toggle M/F) + if (lbl.Text != "") // set gender label (toggle M/F) lbl.Text = (PKX.getGender(lbl.Text) == 0) ? gendersymbols[1] : gendersymbols[0]; } // Prompted Updates of PKX Functions // - private bool changingFields = false; + private bool changingFields; private void updateEXPLevel(object sender, EventArgs e) { if (changingFields) return; @@ -1791,9 +1808,11 @@ namespace PKHeX { if (changingFields) return; changingFields = true; - int[] ivs = new int[] { + int[] ivs = + { Util.ToInt32(TB_HPIV.Text), Util.ToInt32(TB_ATKIV.Text), Util.ToInt32(TB_DEFIV.Text), - Util.ToInt32(TB_SPAIV.Text), Util.ToInt32(TB_SPDIV.Text), Util.ToInt32(TB_SPEIV.Text) }; + Util.ToInt32(TB_SPAIV.Text), Util.ToInt32(TB_SPDIV.Text), Util.ToInt32(TB_SPEIV.Text) + }; // Change IVs to match the new Hidden Power int[] newIVs = PKX.setHPIVs(Util.getIndex(CB_HPType), ivs); @@ -1816,9 +1835,11 @@ namespace PKHeX if (Util.ToInt32((sender as MaskedTextBox).Text) > 31) (sender as MaskedTextBox).Text = "31"; - int[] ivs = new int[] { + int[] ivs = + { Util.ToInt32(TB_HPIV.Text), Util.ToInt32(TB_ATKIV.Text), Util.ToInt32(TB_DEFIV.Text), - Util.ToInt32(TB_SPAIV.Text), Util.ToInt32(TB_SPDIV.Text), Util.ToInt32(TB_SPEIV.Text) }; + Util.ToInt32(TB_SPAIV.Text), Util.ToInt32(TB_SPDIV.Text), Util.ToInt32(TB_SPEIV.Text) + }; changingFields = true; CB_HPType.SelectedValue = PKX.getHPType(ivs); @@ -1872,15 +1893,14 @@ namespace PKHeX if (Util.ToInt32((sender as MaskedTextBox).Text) > 252) (sender as MaskedTextBox).Text = "252"; - int evtotal, HP_EV, ATK_EV, DEF_EV, SPA_EV, SPD_EV, SPE_EV; - HP_EV = Util.ToInt32(TB_HPEV.Text); - ATK_EV = Util.ToInt32(TB_ATKEV.Text); - DEF_EV = Util.ToInt32(TB_DEFEV.Text); - SPA_EV = Util.ToInt32(TB_SPAEV.Text); - SPD_EV = Util.ToInt32(TB_SPDEV.Text); - SPE_EV = Util.ToInt32(TB_SPEEV.Text); + int HP_EV = Util.ToInt32(TB_HPEV.Text); + int ATK_EV = Util.ToInt32(TB_ATKEV.Text); + int DEF_EV = Util.ToInt32(TB_DEFEV.Text); + int SPA_EV = Util.ToInt32(TB_SPAEV.Text); + int SPD_EV = Util.ToInt32(TB_SPDEV.Text); + int SPE_EV = Util.ToInt32(TB_SPEEV.Text); - evtotal = HP_EV + ATK_EV + DEF_EV + SPA_EV + SPD_EV + SPE_EV; + int evtotal = HP_EV + ATK_EV + DEF_EV + SPA_EV + SPD_EV + SPE_EV; if (evtotal > 510) // Background turns Red TB_EVTotal.BackColor = Color.Red; @@ -1924,7 +1944,6 @@ namespace PKHeX TB_SPAEV.Text = 0.ToString(); TB_SPDEV.Text = 0.ToString(); TB_SPEEV.Text = 0.ToString(); - return; } else { @@ -2055,13 +2074,13 @@ namespace PKHeX { if (!init) return; if (CHK_Cured.Checked && !CHK_Infected.Checked) { CHK_Cured.Checked = false; return; } - else if (CHK_Cured.Checked) return; + if (CHK_Cured.Checked) return; Label_PKRS.Visible = CB_PKRSStrain.Visible = CHK_Infected.Checked; if (!CHK_Infected.Checked) { CB_PKRSStrain.SelectedIndex = 0; CB_PKRSDays.SelectedIndex = 0; Label_PKRSdays.Visible = CB_PKRSDays.Visible = false; } else if (CB_PKRSStrain.SelectedIndex == 0) { CB_PKRSStrain.SelectedIndex = 1; Label_PKRSdays.Visible = CB_PKRSDays.Visible = true; CB_PKRSDays.SelectedIndex = 1; } // if not cured yet, days > 0 - if (!CHK_Cured.Checked && CHK_Infected.Checked && CB_PKRSDays.SelectedIndex == 0) CB_PKRSDays.SelectedIndex++; + if (CHK_Infected.Checked && CB_PKRSDays.SelectedIndex == 0) CB_PKRSDays.SelectedIndex++; } private void updateCountry(object sender, EventArgs e) { @@ -2116,9 +2135,9 @@ namespace PKHeX #region B2W2 Met Locations { // Build up our met list - var met_list = Util.getCBList(metBW2_00000, new int[] { 0 }); - met_list = Util.getOffsetCBList(met_list, metBW2_60000, 60001, new int[] { 60002 }); - met_list = Util.getOffsetCBList(met_list, metBW2_30000, 30001, new int[] { 30003 }); + var met_list = Util.getCBList(metBW2_00000, new[] { 0 }); + met_list = Util.getOffsetCBList(met_list, metBW2_60000, 60001, new[] { 60002 }); + met_list = Util.getOffsetCBList(met_list, metBW2_30000, 30001, new[] { 30003 }); met_list = Util.getOffsetCBList(met_list, metBW2_00000, 00000, Legal.Met_BW2_0); met_list = Util.getOffsetCBList(met_list, metBW2_30000, 30001, Legal.Met_BW2_3); met_list = Util.getOffsetCBList(met_list, metBW2_40000, 40001, Legal.Met_BW2_4); @@ -2130,10 +2149,7 @@ namespace PKHeX CB_EggLocation.ValueMember = "Value"; CB_EggLocation.DataSource = new BindingSource(met_list, null); CB_EggLocation.SelectedValue = 0; - if (gameorigin < 20) - CB_MetLocation.SelectedValue = 30001; // Transporter - else - CB_MetLocation.SelectedValue = 60001; // Stranger + CB_MetLocation.SelectedValue = gameorigin < 20 ? 30001 : 60001; origintrack = "Past"; } #endregion @@ -2144,9 +2160,9 @@ namespace PKHeX #region ORAS Met Locations { // Build up our met list - var met_list = Util.getCBList(metXY_00000, new int[] { 0 }); - met_list = Util.getOffsetCBList(met_list, metXY_60000, 60001, new int[] { 60002 }); - met_list = Util.getOffsetCBList(met_list, metXY_30000, 30001, new int[] { 30002 }); + var met_list = Util.getCBList(metXY_00000, new[] { 0 }); + met_list = Util.getOffsetCBList(met_list, metXY_60000, 60001, new[] { 60002 }); + met_list = Util.getOffsetCBList(met_list, metXY_30000, 30001, new[] { 30002 }); met_list = Util.getOffsetCBList(met_list, metXY_00000, 00000, Legal.Met_XY_0); met_list = Util.getOffsetCBList(met_list, metXY_30000, 30001, Legal.Met_XY_3); met_list = Util.getOffsetCBList(met_list, metXY_40000, 40001, Legal.Met_XY_4); @@ -2167,14 +2183,10 @@ namespace PKHeX { // Load Gen 4 egg locations if Gen 4 Origin. #region HGSS Met Locations - // Allowed Met Locations - int[] metlocs = { 0, 2000, 2002, 3001 }; - - // Set up - var met_list = Util.getCBList(metHGSS_00000, new int[] { 0 }); - met_list = Util.getOffsetCBList(met_list, metHGSS_02000, 2000, new int[] { 2000 }); - met_list = Util.getOffsetCBList(met_list, metHGSS_02000, 2000, new int[] { 2002 }); - met_list = Util.getOffsetCBList(met_list, metHGSS_03000, 3000, new int[] { 3001 }); + var met_list = Util.getCBList(metHGSS_00000, new[] { 0 }); + met_list = Util.getOffsetCBList(met_list, metHGSS_02000, 2000, new[] { 2000 }); + met_list = Util.getOffsetCBList(met_list, metHGSS_02000, 2000, new[] { 2002 }); + met_list = Util.getOffsetCBList(met_list, metHGSS_03000, 3000, new[] { 3001 }); met_list = Util.getOffsetCBList(met_list, metHGSS_00000, 0000, Legal.Met_HGSS_0); met_list = Util.getOffsetCBList(met_list, metHGSS_02000, 2000, Legal.Met_HGSS_2); met_list = Util.getOffsetCBList(met_list, metHGSS_03000, 3000, Legal.Met_HGSS_3); @@ -2212,33 +2224,31 @@ namespace PKHeX } private void updateNickname(object sender, EventArgs e) { - if (init && (!CHK_Nicknamed.Checked)) - { - // Fetch Current Species and set it as Nickname Text - int species = Util.getIndex(CB_Species); - if (species == 0 || species > 721) - TB_Nickname.Text = ""; - else - { - // get language - int lang = Util.getIndex(CB_Language); - string[] lang_val = { "en", "ja", "fr", "it", "de", "es", "ko" }; + if (!init || (CHK_Nicknamed.Checked)) return; - string l = ""; - switch (lang) - { - case 1: l = "ja"; break; - case 2: l = "en"; break; - case 3: l = "fr"; break; - case 4: l = "it"; break; - case 5: l = "de"; break; - case 7: l = "es"; break; - case 8: l = "ko"; break; - default: l = curlanguage; break; - } - if (CHK_IsEgg.Checked) species = 0; // Set species to 0 to get the egg name. - TB_Nickname.Text = Util.getStringList("Species", l)[(CHK_IsEgg.Checked) ? 0 : species]; + // Fetch Current Species and set it as Nickname Text + int species = Util.getIndex(CB_Species); + if (species == 0 || species > 721) + TB_Nickname.Text = ""; + else + { + // get language + int lang = Util.getIndex(CB_Language); + + string l; + switch (lang) + { + case 1: l = "ja"; break; + case 2: l = "en"; break; + case 3: l = "fr"; break; + case 4: l = "it"; break; + case 5: l = "de"; break; + case 7: l = "es"; break; + case 8: l = "ko"; break; + default: l = curlanguage; break; } + if (CHK_IsEgg.Checked) species = 0; // Set species to 0 to get the egg name. + TB_Nickname.Text = Util.getStringList("Species", l)[(CHK_IsEgg.Checked) ? 0 : species]; } } private void updateNicknameClick(object sender, MouseEventArgs e) @@ -2292,22 +2302,18 @@ namespace PKHeX Label_Friendship.Visible = !CHK_IsEgg.Checked; // Update image to (not) show egg. - if (init) - { - updateNickname(null, null); - getQuickFiller(dragout); - } + if (!init) return; + updateNickname(null, null); + getQuickFiller(dragout); } private void updateMetAsEgg(object sender, EventArgs e) { GB_EggConditions.Enabled = CHK_AsEgg.Checked; - if (!CHK_AsEgg.Checked) - { - // Remove egg met data - CHK_IsEgg.Checked = false; - CAL_EggDate.Value = new DateTime(2000, 01, 01); - CB_EggLocation.SelectedValue = 0; - } + if (CHK_AsEgg.Checked) return; + // Remove egg met data + CHK_IsEgg.Checked = false; + CAL_EggDate.Value = new DateTime(2000, 01, 01); + CB_EggLocation.SelectedValue = 0; } private void updateShinyPID(object sender, EventArgs e) { @@ -2352,10 +2358,7 @@ namespace PKHeX ComboBox cb = sender as ComboBox; cb.SelectionLength = 0; - if (cb.SelectedValue == null) - cb.BackColor = Color.DarkSalmon; - else - cb.BackColor = defaultControlWhite; + cb.BackColor = cb.SelectedValue == null ? Color.DarkSalmon : defaultControlWhite; if (init) { getQuickFiller(dragout); } @@ -2415,17 +2418,15 @@ namespace PKHeX int incr = nature / 5; int decr = nature % 5; - Label[] labarray = new Label[] { Label_ATK, Label_DEF, Label_SPE, Label_SPA, Label_SPD }; + Label[] labarray = { Label_ATK, Label_DEF, Label_SPE, Label_SPA, Label_SPD }; // Reset Label Colors foreach (Label label in labarray) label.ForeColor = defaultControlText; // Set Colored StatLabels only if Nature isn't Neutral - if (incr != decr) - { - labarray[incr].ForeColor = Color.Red; - labarray[decr].ForeColor = Color.Blue; - } + if (incr == decr) return; + labarray[incr].ForeColor = Color.Red; + labarray[decr].ForeColor = Color.Blue; } } // Secondary Windows for Ribbons/Amie/Memories @@ -2453,16 +2454,15 @@ namespace PKHeX for (int i = 0; i < cba.Length; i++) { int back = cba[i].BackColor.ToArgb(); - if (back != System.Drawing.SystemColors.Control.ToArgb() && back != 0 && back != -1 & back != defaultControlWhite.ToArgb()) - { - if (i < 6) // Main Tab - tabMain.SelectedIndex = 0; - else if (i < 9) // Met Tab - tabMain.SelectedIndex = 1; - else // Moves - tabMain.SelectedIndex = 3; - goto invalid; - } + if (back == SystemColors.Control.ToArgb() || back == 0 || + !(back != -1 & back != defaultControlWhite.ToArgb())) continue; + if (i < 6) // Main Tab + tabMain.SelectedIndex = 0; + else if (i < 9) // Met Tab + tabMain.SelectedIndex = 1; + else // Moves + tabMain.SelectedIndex = 3; + goto invalid; } #endregion // Further logic checking @@ -2526,7 +2526,7 @@ namespace PKHeX // pkx[0x16], pkx[0x17] are handled by the Medals UI (Hits & Training Bag) Array.Copy(BitConverter.GetBytes(Util.getHEXval(TB_PID)), 0, pkx, 0x18, 4); // PID pkx[0x1C] = (byte)((Util.getIndex(CB_Nature))); // Nature - int fegform = (int)(Convert.ToInt32(CHK_Fateful.Checked)); // Fateful + int fegform = Convert.ToInt32(CHK_Fateful.Checked); // Fateful fegform |= (PKX.getGender(Label_Gender.Text) << 1); // Gender fegform |= (Math.Min((MT_Form.Enabled) ? Convert.ToInt32(MT_Form.Text) : Util.getIndex(CB_Form), 32) << 3); // Form pkx[0x1D] = (byte)fegform; @@ -2699,25 +2699,21 @@ namespace PKHeX // Fix Moves if a slot is empty for (int i = 0; i < 3; i++) { - if (BitConverter.ToUInt16(pkx, 0x5A + 2 * i) == 0) - { - Array.Copy(pkx, 0x5C + 2 * i, pkx, 0x5A + 2 * i, 2); // Shift moves down - Array.Copy(new byte[2], 0, pkx, 0x5C + 2 * i, 2); // Clear next move (error shifted down) + if (BitConverter.ToUInt16(pkx, 0x5A + 2*i) != 0) continue; + Array.Copy(pkx, 0x5C + 2 * i, pkx, 0x5A + 2 * i, 2); // Shift moves down + Array.Copy(new byte[2], 0, pkx, 0x5C + 2 * i, 2); // Clear next move (error shifted down) - // Move PP and PP Ups down one byte. - pkx[0x62 + i] = pkx[0x63 + i]; pkx[0x63 + i] = 0; // PP - pkx[0x66 + i] = pkx[0x67 + i]; pkx[0x67 + i] = 0; // PP Ups - } + // Move PP and PP Ups down one byte. + pkx[0x62 + i] = pkx[0x63 + i]; pkx[0x63 + i] = 0; // PP + pkx[0x66 + i] = pkx[0x67 + i]; pkx[0x67 + i] = 0; // PP Ups } // Fix Relearn moves if a slot is empty for (int i = 0; i < 3; i++) { - if (BitConverter.ToUInt16(pkx, 0x6A + 2 * i) == 0) - { - Array.Copy(pkx, 0x6C + 2 * i, pkx, 0x6A + 2 * i, 2); // Shift moves down - Array.Copy(new byte[2], 0, pkx, 0x6C + 2 * i, 2); // Clear next move (error shifted down) - } + if (BitConverter.ToUInt16(pkx, 0x6A + 2*i) != 0) continue; + Array.Copy(pkx, 0x6C + 2 * i, pkx, 0x6A + 2 * i, 2); // Shift moves down + Array.Copy(new byte[2], 0, pkx, 0x6C + 2 * i, 2); // Clear next move (error shifted down) } // No foreign memories for Pokemon without a foreign trainer @@ -2756,7 +2752,7 @@ namespace PKHeX if (!verifiedPKX()) { return; } { // Create Temp File to Drag - string basepath = System.Windows.Forms.Application.StartupPath; + string basepath = Application.StartupPath; Cursor.Current = Cursors.Hand; // Make a new file name @@ -2840,7 +2836,7 @@ namespace PKHeX RTB_S.Text += "Invalid: " + i.ToString("X2") + " @ region " + start[i].ToString("X5") + Environment.NewLine; } } - RTB_S.Text += "1st SAV: " + (start.Length - invalid1).ToString() + "/" + start.Length.ToString() + Environment.NewLine; + RTB_S.Text += "1st SAV: " + (start.Length - invalid1) + "/" + start.Length + Environment.NewLine; if (cybergadget) return; @@ -2857,13 +2853,11 @@ namespace PKHeX Array.Copy(savefile, start[i], data, 0, length[i]); ushort checksum = PKX.ccitt16(data); ushort actualsum = BitConverter.ToUInt16(savefile, csoff + i * 0x8); - if (checksum != actualsum) - { - invalid2++; - RTB_S.Text += "Invalid: " + i.ToString("X2") + " @ region " + start[i].ToString("X5") + Environment.NewLine; - } + if (checksum == actualsum) continue; + invalid2++; + RTB_S.Text += "Invalid: " + i.ToString("X2") + " @ region " + start[i].ToString("X5") + Environment.NewLine; } - RTB_S.Text += "2nd SAV: " + (start.Length - invalid2).ToString() + "/" + start.Length.ToString() + Environment.NewLine; + RTB_S.Text += "2nd SAV: " + (start.Length - invalid2) + "/" + start.Length + Environment.NewLine; if (invalid1 + invalid2 == (start.Length * 2)) RTB_S.Text = "No checksums are valid."; } @@ -2987,7 +2981,7 @@ namespace PKHeX 0x6A000, 0x6AFFF, 0x2D20, 0x1000, }; #endregion - SHA256 mySHA256 = SHA256Managed.Create(); + SHA256 mySHA256 = SHA256.Create(); for (int i = 0; i < hashtabledata.Length / 4; i++) { @@ -3002,11 +2996,9 @@ namespace PKHeX byte[] actualhash = new byte[0x20]; Array.Copy(savefile, offset, actualhash, 0, 0x20); - if (!hashValue.SequenceEqual(actualhash)) - { - invalid1++; - RTB_S.Text += "Invalid: " + hashtabledata[2 + 4 * i].ToString("X5") + " @ " + hashtabledata[0 + 4 * i].ToString("X5") + "-" + hashtabledata[1 + 4 * i].ToString("X5") + Environment.NewLine; - } + if (hashValue.SequenceEqual(actualhash)) continue; + invalid1++; + RTB_S.Text += "Invalid: " + hashtabledata[2 + 4 * i].ToString("X5") + " @ " + hashtabledata[0 + 4 * i].ToString("X5") + "-" + hashtabledata[1 + 4 * i].ToString("X5") + Environment.NewLine; } RTB_S.Text += "1st SAV: " + (106 - invalid1).ToString() + "/" + 106.ToString() + Environment.NewLine; @@ -3038,11 +3030,9 @@ namespace PKHeX byte[] actualhash = new byte[0x20]; Array.Copy(savefile, offset, actualhash, 0, 0x20); - if (!hashValue.SequenceEqual(actualhash)) - { - invalid2++; - RTB_S.Text += "Invalid: " + hashtabledata[2 + 4 * i].ToString("X5") + " @ " + hashtabledata[0 + 4 * i].ToString("X5") + "-" + hashtabledata[1 + 4 * i].ToString("X5") + Environment.NewLine; - } + if (hashValue.SequenceEqual(actualhash)) continue; + invalid2++; + RTB_S.Text += "Invalid: " + hashtabledata[2 + 4 * i].ToString("X5") + " @ " + hashtabledata[0 + 4 * i].ToString("X5") + "-" + hashtabledata[1 + 4 * i].ToString("X5") + Environment.NewLine; } RTB_S.Text += "2nd SAV: " + (106 - invalid2).ToString() + "/" + 106.ToString() + Environment.NewLine; @@ -3252,7 +3242,7 @@ namespace PKHeX } } - SHA256 mySHA256 = SHA256Managed.Create(); + SHA256 mySHA256 = SHA256.Create(); // Hash for 0x3000 onwards for (int i = 2; i < hashtabledata.Length / 4; i++) @@ -3332,22 +3322,20 @@ namespace PKHeX for (int i = 0; i < cybersav.Length / 0x200; i++) { Array.Copy(cybersav, i * 0x200, section, 0, 0x200); - if (section.SequenceEqual(FFFF)) + if (!section.SequenceEqual(FFFF)) continue; + string problem = String.Format("0x200 chunk @ 0x{0} is FF'd.", (i * 0x200).ToString("X5")) + + Environment.NewLine + "Cyber will screw up (as of August 31st)." + Environment.NewLine + Environment.NewLine; + + // Check to see if it is in the Pokedex + if (i * 0x200 > 0x14E00 && i * 0x200 < 0x15700) { - string problem = String.Format("0x200 chunk @ 0x{0} is FF'd.", (i * 0x200).ToString("X5")) - + Environment.NewLine + "Cyber will screw up (as of August 31st)." + Environment.NewLine + Environment.NewLine; - - // Check to see if it is in the Pokedex - if (i * 0x200 > 0x14E00 && i * 0x200 < 0x15700) - { - problem += "Problem lies in the Pokedex. "; - if (i * 0x200 == 0x15400) - problem += "Remove a language flag for a species ~ ex " + specieslist[548]; - } - - if (Util.Prompt(MessageBoxButtons.YesNo, problem, "Continue saving?") != DialogResult.Yes) - return; + problem += "Problem lies in the Pokedex. "; + if (i * 0x200 == 0x15400) + problem += "Remove a language flag for a species ~ ex " + specieslist[548]; } + + if (Util.Prompt(MessageBoxButtons.YesNo, problem, "Continue saving?") != DialogResult.Yes) + return; } } SaveFileDialog cySAV = new SaveFileDialog(); @@ -3378,68 +3366,60 @@ namespace PKHeX { Util.Alert("Please specify the target cart/console-RAM save."); OpenFileDialog ofd = new OpenFileDialog(); - if (ofd.ShowDialog() == DialogResult.OK) - { - string target = ofd.FileName; - byte[] targetRAM = File.ReadAllBytes(target); - byte[] newRAM = ram2sav.getRAM(targetRAM, cybersav); + if (ofd.ShowDialog() != DialogResult.OK) return; + string target = ofd.FileName; + byte[] targetRAM = File.ReadAllBytes(target); + byte[] newRAM = ram2sav.getRAM(targetRAM, cybersav); - cySAV.Filter = "ramsav|*.bin"; - cySAV.FileName = "ramsav.bin"; - DialogResult sdr = cySAV.ShowDialog(); - if (sdr == DialogResult.OK) - { - string path = cySAV.FileName; - File.WriteAllBytes(path, newRAM); - Util.Alert("Saved RAM SAV to:" + Environment.NewLine + path, "Target RAM:" + Environment.NewLine + target); - } - } + cySAV.Filter = "ramsav|*.bin"; + cySAV.FileName = "ramsav.bin"; + DialogResult sdr = cySAV.ShowDialog(); + if (sdr != DialogResult.OK) return; + string path = cySAV.FileName; + File.WriteAllBytes(path, newRAM); + Util.Alert("Saved RAM SAV to:" + Environment.NewLine + path, "Target RAM:" + Environment.NewLine + target); } else if (ramsavloaded && ModifierKeys != Keys.Control) // Export RAM SAV if it is the currently loaded one. { cySAV.Filter = "ramsav|*.bin"; cySAV.FileName = "ramsav.bin"; DialogResult sdr = cySAV.ShowDialog(); - if (sdr == DialogResult.OK) - { - string path = cySAV.FileName; - File.WriteAllBytes(path, ram2sav.getRAM(ramsav, cybersav)); - Util.Alert("Saved RAM SAV to:", path); - } + if (sdr != DialogResult.OK) return; + string path = cySAV.FileName; + File.WriteAllBytes(path, ram2sav.getRAM(ramsav, cybersav)); + Util.Alert("Saved RAM SAV to:", path); } else { cySAV.Filter = "Cyber SAV|*.*"; - cySAV.FileName = L_Save.Text.Split(new string[] { ": " }, StringSplitOptions.None)[1]; + cySAV.FileName = L_Save.Text.Split(new[] { ": " }, StringSplitOptions.None)[1]; DialogResult sdr = cySAV.ShowDialog(); - if (sdr == DialogResult.OK) - { - string path = cySAV.FileName; - File.WriteAllBytes(path, cybersav); - Util.Alert("Saved Cyber SAV to:", path); - } + if (sdr != DialogResult.OK) return; + string path = cySAV.FileName; + File.WriteAllBytes(path, cybersav); + Util.Alert("Saved Cyber SAV to:", path); } } else { // Save Full Save File - SaveFileDialog savesav = new SaveFileDialog(); - savesav.Filter = "SAV|*.bin;*.sav"; - savesav.FileName = L_Save.Text.Split(new string[] { ": " }, StringSplitOptions.None)[1]; - DialogResult result = savesav.ShowDialog(); - if (result == DialogResult.OK) + SaveFileDialog savesav = new SaveFileDialog { - string path = savesav.FileName; + Filter = "SAV|*.bin;*.sav", + FileName = L_Save.Text.Split(new[] {": "}, StringSplitOptions.None)[1] + }; + DialogResult result = savesav.ShowDialog(); + if (result != DialogResult.OK) return; + string path = savesav.FileName; - if (File.Exists(path)) - { - // File already exists, save a .bak - byte[] backupfile = File.ReadAllBytes(path); - File.WriteAllBytes(path + ".bak", backupfile); - } - File.WriteAllBytes(path, editedsav); - Util.Alert("Saved 1MB SAV to:", path); + if (File.Exists(path)) + { + // File already exists, save a .bak + byte[] backupfile = File.ReadAllBytes(path); + File.WriteAllBytes(path + ".bak", backupfile); } + File.WriteAllBytes(path, editedsav); + Util.Alert("Saved 1MB SAV to:", path); } } // Box/SAV Functions // @@ -3453,14 +3433,13 @@ namespace PKHeX } private void clickSlot(object sender, EventArgs e) { - if (ModifierKeys == (Keys.Control | Keys.Alt)) - clickClone(sender, e); - else if (ModifierKeys == Keys.Control) - clickView(sender, e); - else if (ModifierKeys == Keys.Shift) - clickSet(sender, e); - else if (ModifierKeys == Keys.Alt) - clickDelete(sender, e); + switch (ModifierKeys) + { + case (Keys.Control | Keys.Alt): clickClone(sender, e); break; + case Keys.Control: clickView(sender, e); break; + case Keys.Shift: clickSet(sender, e); break; + case Keys.Alt: clickDelete(sender, e); break; + } } private void clickView(object sender, EventArgs e) { @@ -3578,7 +3557,7 @@ namespace PKHeX if (slot >= 30 && slot < 36) // Party { Array.Copy(ekxdata, 0, savefile, offset, 0x104); setParty(); return; } - else if (slot < 30 || (slot >= 36 && slot < 42 && DEV_Ability.Enabled)) + if (slot < 30 || (slot >= 36 && slot < 42 && DEV_Ability.Enabled)) { Array.Copy(ekxdata, 0, savefile, offset, 0xE8); } else return; @@ -3890,16 +3869,14 @@ namespace PKHeX if (pb == dragout) L_QR.Visible = (species != 0); if (species == 0) { pb.Image = (Image)Properties.Resources.ResourceManager.GetObject("_0"); return; } - - else { - file = "_" + species.ToString(); + file = "_" + species; if (altforms > 0) // Alt Form Handling - file = file + "_" + altforms.ToString(); + file = file + "_" + altforms; else if (gender == 1 && (species == 592 || species == 593)) // Frillish & Jellicent - file = file + "_" + gender.ToString(); + file = file + "_" + gender; else if (gender == 1 && (species == 521 || species == 668)) // Unfezant & Pyroar - file = "_" + species.ToString() + "f"; + file = "_" + species + "f"; } // Redrawing logic @@ -3908,13 +3885,13 @@ namespace PKHeX { if (species < 722) { - baseImage = PKHeX.Util.LayerImage( - (Image)Properties.Resources.ResourceManager.GetObject("_" + species.ToString()), - (Image)Properties.Resources.unknown, + baseImage = Util.LayerImage( + (Image)Properties.Resources.ResourceManager.GetObject("_" + species), + Properties.Resources.unknown, 0, 0, .5); } else - baseImage = (Image)Properties.Resources.unknown; + baseImage = Properties.Resources.unknown; } if (isegg == 1) { @@ -3932,8 +3909,7 @@ namespace PKHeX { // Has Item int item = BitConverter.ToUInt16(dslotdata, 0xA); - Image itemimg = (Image)Properties.Resources.ResourceManager.GetObject("item_" + item.ToString()); - if (itemimg == null) itemimg = Properties.Resources.helditem; + Image itemimg = (Image)Properties.Resources.ResourceManager.GetObject("item_" + item) ?? Properties.Resources.helditem; // Redraw baseImage = Util.LayerImage(baseImage, itemimg, 22 + (15 - itemimg.Width) / 2, 15 + (15 - itemimg.Height), 1); } @@ -3956,28 +3932,23 @@ namespace PKHeX pb.BackColor = Color.Red; return; } - else pb.BackColor = Color.Transparent; + pb.BackColor = Color.Transparent; int species = BitConverter.ToInt16(dslotdata, 0x08); // Get Species uint isegg = (BitConverter.ToUInt32(dslotdata, 0x74) >> 30) & 1; int altforms = (dslotdata[0x1D] >> 3); int gender = (dslotdata[0x1D] >> 1) & 0x3; - string file; - if (species == 0) { pb.Image = (Image)Properties.Resources.ResourceManager.GetObject("_0"); return; } - else - { - file = "_" + species.ToString(); - if (altforms > 0) // Alt Form Handling - file = file + "_" + altforms.ToString(); - else if (gender == 1 && (species == 592 || species == 593)) // Frillish & Jellicent - file = file + "_" + gender.ToString(); - else if (gender == 1 && (species == 521 || species == 668)) // Unfezant & Pyroar - file = "_" + species.ToString() + "f"; - } + string file = "_" + species; + if (altforms > 0) // Alt Form Handling + file = file + "_" + altforms; + else if (gender == 1 && (species == 592 || species == 593)) // Frillish & Jellicent + file = file + "_" + gender; + else if (gender == 1 && (species == 521 || species == 668)) // Unfezant & Pyroar + file = "_" + species + "f"; // Redrawing logic Image baseImage = (Image)Properties.Resources.ResourceManager.GetObject(file); @@ -3985,13 +3956,13 @@ namespace PKHeX { if (species < 722) { - baseImage = PKHeX.Util.LayerImage( - (Image)Properties.Resources.ResourceManager.GetObject("_" + species.ToString()), - (Image)Properties.Resources.unknown, + baseImage = Util.LayerImage( + (Image)Properties.Resources.ResourceManager.GetObject("_" + species), + Properties.Resources.unknown, 0, 0, .5); } else - baseImage = (Image)Properties.Resources.unknown; + baseImage = Properties.Resources.unknown; } if (isegg == 1) { @@ -4009,8 +3980,7 @@ namespace PKHeX { // Has Item int item = BitConverter.ToUInt16(dslotdata, 0xA); - Image itemimg = (Image)Properties.Resources.ResourceManager.GetObject("item_" + item.ToString()); - if (itemimg == null) itemimg = Properties.Resources.helditem; + Image itemimg = (Image)Properties.Resources.ResourceManager.GetObject("item_" + item) ?? Properties.Resources.helditem; // Redraw baseImage = Util.LayerImage(baseImage, itemimg, 22 + (15 - itemimg.Width) / 2, 15 + (15 - itemimg.Height), 1); } @@ -4032,8 +4002,8 @@ namespace PKHeX dcpkx1, dcpkx2, gtspkx, fusedpkx,subepkx1,subepkx2,subepkx3, }; - for (int i = 0; i < pba.Length; i++) - pba[i].BackgroundImage = null; + foreach (PictureBox t in pba) + t.BackgroundImage = null; if (slot < 32) colorizedbox = C_BoxSelect.SelectedIndex; @@ -4063,15 +4033,16 @@ namespace PKHeX int incr = nature / 5; int decr = nature % 5; - Label[] labarray = new Label[] { Label_ATK, Label_DEF, Label_SPE, Label_SPA, Label_SPD }; + Label[] labarray = { Label_ATK, Label_DEF, Label_SPE, Label_SPA, Label_SPD }; // Reset Label Colors foreach (Label label in labarray) label.ForeColor = defaultControlText; // Set Colored StatLabels only if Nature isn't Neutral - if (incr != decr) - NatureTip.SetToolTip(CB_Nature, String.Format("+{0} / -{1}", labarray[incr].Text, labarray[decr].Text).Replace(":","")); - else NatureTip.SetToolTip(CB_Nature, "-/-"); + NatureTip.SetToolTip(CB_Nature, + incr != decr + ? String.Format("+{0} / -{1}", labarray[incr].Text, labarray[decr].Text).Replace(":", "") + : "-/-"); } private void switchDaycare(object sender, EventArgs e) { @@ -4086,95 +4057,92 @@ namespace PKHeX private void mainMenuBoxDumpLoad(object sender, EventArgs e) { DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to Import All from Folder." + Environment.NewLine + "Press No to Dump All to Folder.", "Press Cancel to Abort."); - if (dr != DialogResult.Cancel) + if (dr == DialogResult.Cancel) return; + string exepath = Application.StartupPath; + string path = ""; { - string exepath = System.Windows.Forms.Application.StartupPath; - string path = ""; + int offset = SaveGame.Box; + const int size = 232; + if (dr == DialogResult.Yes) // Import { - int offset = SaveGame.Box; - int size = 232; - if (dr == DialogResult.Yes) // Import + if (Directory.Exists(Path.Combine(exepath, "db"))) { - if (Directory.Exists(Path.Combine(exepath, "db"))) - { - DialogResult ld = Util.Prompt(MessageBoxButtons.YesNo, "Load from PKHeX's database?"); - if (ld == DialogResult.Yes) - path = Path.Combine(exepath, "db"); - else if (ld == DialogResult.No) - { - // open folder dialog - FolderBrowserDialog fbd = new FolderBrowserDialog(); - if (fbd.ShowDialog() == DialogResult.OK) - path = fbd.SelectedPath; - } - else return; - } - else + DialogResult ld = Util.Prompt(MessageBoxButtons.YesNo, "Load from PKHeX's database?"); + if (ld == DialogResult.Yes) + path = Path.Combine(exepath, "db"); + else if (ld == DialogResult.No) { // open folder dialog FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) path = fbd.SelectedPath; } - loadBoxesFromDB(path); + else return; } - else if (dr == DialogResult.No) + else { - // Dump all of box content to files. + // open folder dialog + FolderBrowserDialog fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + path = fbd.SelectedPath; + } + loadBoxesFromDB(path); + } + else if (dr == DialogResult.No) + { + // Dump all of box content to files. + { + DialogResult ld = Util.Prompt(MessageBoxButtons.YesNo, "Save to PKHeX's database?"); + if (ld == DialogResult.Yes) { - DialogResult ld = Util.Prompt(MessageBoxButtons.YesNo, "Save to PKHeX's database?"); - if (ld == DialogResult.Yes) - { - path = Path.Combine(exepath, "db"); - if (!Directory.Exists(path)) - Directory.CreateDirectory(path); - } - else if (ld == DialogResult.No) - { - // open folder dialog - FolderBrowserDialog fbd = new FolderBrowserDialog(); - if (fbd.ShowDialog() == DialogResult.OK) - path = fbd.SelectedPath; - } - else return; + path = Path.Combine(exepath, "db"); + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); } - for (int i = 0; i < 31 * 30 * size; i += size) + else if (ld == DialogResult.No) { - byte[] ekxdata = new byte[size]; - Array.Copy(savefile, offset + i, ekxdata, 0, size); - byte[] pkxdata = PKX.decryptArray(ekxdata); - - - int species = BitConverter.ToInt16(pkxdata, 0x08); - if (species == 0) continue; - uint chk = BitConverter.ToUInt16(pkxdata, 0x06); - uint EC = BitConverter.ToUInt32(pkxdata, 0); - uint IV32 = BitConverter.ToUInt32(pkxdata, 0x74); - - string nick = ""; - if (Convert.ToBoolean((IV32 >> 31) & 1)) - nick = Util.TrimFromZero(Encoding.Unicode.GetString(pkxdata, 0x40, 24)) + " (" + specieslist[species] + ")"; - else - nick = specieslist[species]; - if (Convert.ToBoolean((IV32 >> 30) & 1)) - nick += " (" + eggname + ")"; - - string isshiny = ""; - int gamevers = pkxdata[0xDF]; - - // Is Shiny - if (PKX.getIsShiny(BitConverter.ToUInt32(pkxdata, 0x18), Util.ToUInt32(TB_TID.Text), Util.ToUInt32(TB_SID.Text))) - isshiny = " ★"; - - string savedname = - species.ToString("000") + isshiny + " - " - + nick + " - " - + chk.ToString("X4") + EC.ToString("X8") - + ".pk6"; - Array.Resize(ref pkxdata, 232); - if (!File.Exists(Path.Combine(path, savedname))) - File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(savedname)), pkxdata); + // open folder dialog + FolderBrowserDialog fbd = new FolderBrowserDialog(); + if (fbd.ShowDialog() == DialogResult.OK) + path = fbd.SelectedPath; } + else return; + } + for (int i = 0; i < 31 * 30 * size; i += size) + { + byte[] ekxdata = new byte[size]; + Array.Copy(savefile, offset + i, ekxdata, 0, size); + byte[] pkxdata = PKX.decryptArray(ekxdata); + + + int species = BitConverter.ToInt16(pkxdata, 0x08); + if (species == 0) continue; + uint chk = BitConverter.ToUInt16(pkxdata, 0x06); + uint EC = BitConverter.ToUInt32(pkxdata, 0); + uint IV32 = BitConverter.ToUInt32(pkxdata, 0x74); + + string nick; + if (Convert.ToBoolean((IV32 >> 31) & 1)) + nick = Util.TrimFromZero(Encoding.Unicode.GetString(pkxdata, 0x40, 24)) + " (" + specieslist[species] + ")"; + else + nick = specieslist[species]; + if (Convert.ToBoolean((IV32 >> 30) & 1)) + nick += " (" + eggname + ")"; + + string isshiny = ""; + + // Is Shiny + if (PKX.getIsShiny(BitConverter.ToUInt32(pkxdata, 0x18), Util.ToUInt32(TB_TID.Text), Util.ToUInt32(TB_SID.Text))) + isshiny = " ★"; + + string savedname = + species.ToString("000") + isshiny + " - " + + nick + " - " + + chk.ToString("X4") + EC.ToString("X8") + + ".pk6"; + Array.Resize(ref pkxdata, 232); + if (!File.Exists(Path.Combine(path, savedname))) + File.WriteAllBytes(Path.Combine(path, Util.CleanFileName(savedname)), pkxdata); } } } @@ -4190,7 +4158,7 @@ namespace PKHeX // Array.Clear(savefile, offset, size * 30 * 31); DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Clear subsequent boxes when importing data?", "If you only want to overwrite for new data, press no."); if (dr == DialogResult.Cancel) return; - else if (dr == DialogResult.Yes) + if (dr == DialogResult.Yes) { byte[] ezeros = PKX.encryptArray(new byte[232]); for (int i = ctr; i < 30 * 31; i++) @@ -4199,87 +4167,97 @@ namespace PKHeX string[] filepaths = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly); var Converter = new pk2pk(); - for (int i = 0; i < filepaths.Length; i++) + foreach (string t in filepaths) { - long len = new FileInfo(filepaths[i]).Length; + long len = new FileInfo(t).Length; if (len > 260) continue; - else if ( - len != 232 && len != 260 // 6th Gen + if ( + len != 232 && len != 260 // 6th Gen && len != 136 && len != 220 && len != 236 // 5th Gen && len != 100 && len != 80) // 4th Gen continue; - string name = filepaths[i]; byte[] data = new byte[232]; - string ext = Path.GetExtension(filepaths[i]); - if (ext == ".pkm" || ext == ".3gpkm" || ext == ".pk3" || ext == ".pk4" || ext == ".pk5") + string ext = Path.GetExtension(t); + switch (ext) { - // Verify PKM (decrypted) - byte[] input = File.ReadAllBytes(filepaths[i]); - if (!PKX.verifychk(input)) - continue; - else + case ".pk5": + case ".pk4": + case ".pk3": + case ".3gpkm": + case ".pkm": { - try // to convert g5pkm - { data = PKX.encryptArray(Converter.ConvertPKM(input, savefile, savindex)); pastctr++; } - catch - { continue; } - } - } - else if (ext == ".pkx" || ext == ".pk6") - { - byte[] input = File.ReadAllBytes(filepaths[i]); - if ((BitConverter.ToUInt16(input, 0xC8) == 0) && (BitConverter.ToUInt16(input, 0x58) == 0)) - { - if (BitConverter.ToUInt16(input, 0x8) == 0) // if species = 0 + // Verify PKM (decrypted) + byte[] input = File.ReadAllBytes(t); + if (!PKX.verifychk(input)) continue; + { + try // to convert g5pkm + { data = PKX.encryptArray(Converter.ConvertPKM(input, savefile, savindex)); pastctr++; } + catch + { continue; } + } + } + break; + case ".pk6": + case ".pkx": + { + byte[] input = File.ReadAllBytes(t); + if ((BitConverter.ToUInt16(input, 0xC8) == 0) && (BitConverter.ToUInt16(input, 0x58) == 0)) + { + if (BitConverter.ToUInt16(input, 0x8) == 0) // if species = 0 + continue; + Array.Resize(ref input, 232); + + ushort chk = 0; + for (int z = 8; z < 232; z += 2) // Loop through the entire PKX + chk += BitConverter.ToUInt16(input, z); + if (chk != BitConverter.ToUInt16(input, 0x6)) continue; + data = PKX.encryptArray(input); + } + } + break; + case ".ek6": + case ".ekx": + { + byte[] input = File.ReadAllBytes(t); Array.Resize(ref input, 232); + Array.Copy(input, data, 232); + // check if it is good data + byte[] decrypteddata = PKX.decryptArray(input); + + if (BitConverter.ToUInt16(decrypteddata, 0xC8) != 0 && BitConverter.ToUInt16(decrypteddata, 0x58) != 0) + continue; // don't allow improperly encrypted files. they must be encrypted properly. + //else if (BitConverter.ToUInt16(decrypteddata, 0x8) == 0) // if species = 0 + // continue; ushort chk = 0; for (int z = 8; z < 232; z += 2) // Loop through the entire PKX - chk += BitConverter.ToUInt16(input, z); - if (chk != BitConverter.ToUInt16(input, 0x6)) continue; - data = PKX.encryptArray(input); + chk += BitConverter.ToUInt16(decrypteddata, z); + if (chk != BitConverter.ToUInt16(decrypteddata, 0x6)) continue; } + break; + default: + continue; } - else if (ext == ".ekx" || ext == ".ek6") - { - byte[] input = File.ReadAllBytes(filepaths[i]); - Array.Resize(ref input, 232); - Array.Copy(input, data, 232); - // check if it is good data - byte[] decrypteddata = PKX.decryptArray(input); - - if (!(BitConverter.ToUInt16(decrypteddata, 0xC8) == 0) && !(BitConverter.ToUInt16(decrypteddata, 0x58) == 0)) - continue; // don't allow improperly encrypted files. they must be encrypted properly. - //else if (BitConverter.ToUInt16(decrypteddata, 0x8) == 0) // if species = 0 - // continue; - - ushort chk = 0; - for (int z = 8; z < 232; z += 2) // Loop through the entire PKX - chk += BitConverter.ToUInt16(decrypteddata, z); - if (chk != BitConverter.ToUInt16(decrypteddata, 0x6)) continue; - } - else continue; Array.Copy(data, 0, savefile, offset + ctr * 232, 232); setPokedex(PKX.decryptArray(data)); // Set the Pokedex data ctr++; if (ctr == 30 * 31) break; // break out if we have written all 31 boxes } - if (ctr > 0) // if we've written at least one pk6 in, go ahead and make sure the window is stretched. + if (ctr <= 0) return; + // if we've written at least one pk6 in, go ahead and make sure the window is stretched. + if (Width < Height) // expand if boxes aren't visible { - if (Width < Height) // expand if boxes aren't visible - { - this.Width = largeWidth; - tabBoxMulti.SelectedIndex = 0; - } - setPKXBoxes(); - string result = String.Format("Loaded {0} files to boxes.", ctr); - if (pastctr > 0) - Util.Alert(result, String.Format("Conversion successful for {0} past generation files.", pastctr)); - else - Util.Alert(result); + Width = largeWidth; + tabBoxMulti.SelectedIndex = 0; } + setPKXBoxes(); + string result = String.Format("Loaded {0} files to boxes.", ctr); + if (pastctr > 0) + Util.Alert(result, String.Format("Conversion successful for {0} past generation files.", pastctr)); + else + Util.Alert(result); } private void B_SaveBoxBin_Click(object sender, EventArgs e) { @@ -4287,18 +4265,14 @@ namespace PKHeX if (dr == DialogResult.Yes) { - SaveFileDialog sfd = new SaveFileDialog(); - sfd.Filter = "Box Data|*.bin"; - sfd.FileName = "pcdata.bin"; - if (sfd.ShowDialog() == DialogResult.OK) + SaveFileDialog sfd = new SaveFileDialog {Filter = "Box Data|*.bin", FileName = "pcdata.bin"}; + if (sfd.ShowDialog() == DialogResult.OK) File.WriteAllBytes(sfd.FileName, savefile.Skip(SaveGame.Box).Take(0xE8 * 30 * 31).ToArray()); } else if (dr == DialogResult.No) { - SaveFileDialog sfd = new SaveFileDialog(); - sfd.Filter = "Box Data|*.bin"; - sfd.FileName = "boxdata.bin"; - if (sfd.ShowDialog() == DialogResult.OK) + SaveFileDialog sfd = new SaveFileDialog {Filter = "Box Data|*.bin", FileName = "boxdata.bin"}; + if (sfd.ShowDialog() == DialogResult.OK) File.WriteAllBytes(sfd.FileName, savefile.Skip(SaveGame.Box + 0xE8 * 30 * C_BoxSelect.SelectedIndex).Take(0xE8 * 30).ToArray()); } } @@ -4332,26 +4306,24 @@ namespace PKHeX if (savegame_oras) { DialogResult dr = Util.Prompt(MessageBoxButtons.YesNo, "No editing support for ORAS :(", "Repopulate all with random berries?"); - if (dr == DialogResult.Yes) + if (dr != DialogResult.Yes) return; // abort + // Randomize the trees. + int offset = 0x1C400 + 0x5400 + savindex * 0x7F000; + byte[] ready = { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x80, 0x40, 0x01, 0x00, 0x00, 0x00, }; + int[] berrylist = { - // Randomize the trees. - int offset = 0x1C400 + 0x5400 + savindex * 0x7F000; - byte[] ready = new byte[] { 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x80, 0x40, 0x01, 0x00, 0x00, 0x00, }; - int[] berrylist = new int[] - { - 0,149,150,151,152,153,154,155,156,157,158,159,160,161,162, - 163,164,165,166,167,168,169,170,171,172,173,174,175,176,177, - 178,179,180,181,182,183,184,185,186,187,188,189,190,191,192, - 193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, - 208,209,210,211,212,686,687,688, - }; - for (int i = 0; i < 90; i++) - { - Array.Copy(ready, 0, savefile, offset + 0x10 * i, 0x10); // prep the berry template tree (which we replace offset 0x6 for the Tree Item) - int randberry = (int)(Util.rnd32() % berrylist.Length); // generate a random berry that will go into the tree - int index = berrylist[randberry]; // get berry item ID from list - Array.Copy(BitConverter.GetBytes(index), 0, savefile, offset + 0x10 * i + 6, 2); // put berry into tree. - } + 0,149,150,151,152,153,154,155,156,157,158,159,160,161,162, + 163,164,165,166,167,168,169,170,171,172,173,174,175,176,177, + 178,179,180,181,182,183,184,185,186,187,188,189,190,191,192, + 193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, + 208,209,210,211,212,686,687,688, + }; + for (int i = 0; i < 90; i++) + { + Array.Copy(ready, 0, savefile, offset + 0x10 * i, 0x10); // prep the berry template tree (which we replace offset 0x6 for the Tree Item) + int randberry = (int)(Util.rnd32() % berrylist.Length); // generate a random berry that will go into the tree + int index = berrylist[randberry]; // get berry item ID from list + Array.Copy(BitConverter.GetBytes(index), 0, savefile, offset + 0x10 * i + 6, 2); // put berry into tree. } } else @@ -4376,30 +4348,28 @@ namespace PKHeX if (savegame_oras) { DialogResult dr = Util.Prompt(MessageBoxButtons.YesNo, "No editing support for ORAS :(", "Max O-Powers with a working code?"); - if (dr == DialogResult.Yes) - { - byte[] maxoras = new byte[] - { - 0x00, 0x01, 0x01, 0x01, - 0x01, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x00, 0x01, - 0x01, 0x01, 0x01, 0x00, - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x01, 0x01, 0x01, - 0x01, 0x00, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x00, 0x01, - 0x01, 0x01, 0x01, 0x00, - 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, - 0x01, 0x00, 0x00, 0x00, - }; - Array.Copy(maxoras, 0, savefile, 0x17400 + 0x5400 + 0x7F000 * savindex, 0x44); - } + if (dr != DialogResult.Yes) return; + byte[] maxoras = + { + 0x00, 0x01, 0x01, 0x01, + 0x01, 0x00, 0x01, 0x01, + 0x01, 0x01, 0x00, 0x01, + 0x01, 0x01, 0x01, 0x00, + 0x01, 0x01, 0x01, 0x01, + 0x00, 0x01, 0x01, 0x01, + 0x01, 0x00, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x00, 0x01, + 0x01, 0x01, 0x01, 0x00, + 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, + 0x01, 0x00, 0x00, 0x00, + }; + Array.Copy(maxoras, 0, savefile, 0x17400 + 0x5400 + 0x7F000 * savindex, 0x44); } else new SAV_OPower(this).ShowDialog(); @@ -4428,7 +4398,7 @@ namespace PKHeX + "----" + Environment.NewLine + headers[g] + Environment.NewLine + "----" + Environment.NewLine; - uint count = BitConverter.ToUInt32(savefile, offset + 0x4E20); + // uint count = BitConverter.ToUInt32(savefile, offset + 0x4E20); int r_offset = offset; for (int i = 0; i < 100; i++) @@ -4442,17 +4412,18 @@ namespace PKHeX // Trim terminated - uint unk1 = BitConverter.ToUInt32(savefile, r_offset + 0x44); - ulong unk2 = BitConverter.ToUInt64(savefile, r_offset + 0x48); - uint unk3 = BitConverter.ToUInt32(savefile, r_offset + 0x50); - uint unk4 = BitConverter.ToUInt16(savefile, r_offset + 0x54); + // uint unk1 = BitConverter.ToUInt32(savefile, r_offset + 0x44); + // ulong unk2 = BitConverter.ToUInt64(savefile, r_offset + 0x48); + // uint unk3 = BitConverter.ToUInt32(savefile, r_offset + 0x50); + // uint unk4 = BitConverter.ToUInt16(savefile, r_offset + 0x54); byte region = savefile[r_offset + 0x56]; byte country = savefile[r_offset + 0x57]; byte game = savefile[r_offset + 0x5A]; - ulong outfit = BitConverter.ToUInt64(savefile, r_offset + 0x5C); + // ulong outfit = BitConverter.ToUInt64(savefile, r_offset + 0x5C); int favpkm = BitConverter.ToUInt16(savefile, r_offset + 0x9C) & 0x7FF; - string gamename = "UNKNOWN GAME"; - try { gamename = gamelist[game]; } catch { } + string gamename; + try { gamename = gamelist[game]; } + catch { gamename = "UNKNOWN GAME"; } string[] cr = PKX.getCountryRegionText(country, region, curlanguage); result += @@ -4493,24 +4464,20 @@ namespace PKHeX Util.Alert("No PGL picture data found in the save file!"); return; } - int length = 0xE004; + const int length = 0xE004; byte[] jpeg = new byte[length]; Array.Copy(savefile, offset, jpeg, 0, length); - SaveFileDialog savejpeg = new SaveFileDialog(); - savejpeg.FileName = filename; - savejpeg.Filter = "JPEG|*.jpeg"; - if (savejpeg.ShowDialog() == DialogResult.OK) + SaveFileDialog savejpeg = new SaveFileDialog {FileName = filename, Filter = "JPEG|*.jpeg"}; + if (savejpeg.ShowDialog() != DialogResult.OK) return; + string path = savejpeg.FileName; + if (File.Exists(path)) { - string path = savejpeg.FileName; - if (File.Exists(path)) - { - // File already exists, save a .bak - byte[] backupfile = File.ReadAllBytes(path); - File.WriteAllBytes(path + ".bak", backupfile); - } - File.WriteAllBytes(path, jpeg); + // File already exists, save a .bak + byte[] backupfile = File.ReadAllBytes(path); + File.WriteAllBytes(path + ".bak", backupfile); } + File.WriteAllBytes(path, jpeg); } // Save Folder Related private void clickSaveFileName(object sender, EventArgs e) @@ -4524,109 +4491,95 @@ namespace PKHeX else if (File.Exists(Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root" + Path.DirectorySeparatorChar + "main")))) // else if cgse exists path = Util.NormalizePath(Path.Combine(Util.GetTempFolder(), "root" + Path.DirectorySeparatorChar + "main")); - if (path != null) - { - if (Util.Prompt(MessageBoxButtons.YesNo, "Open save file from the following location?", path) == DialogResult.Yes) - openQuick(path); // load save - } + if (path == null) return; + if (Util.Prompt(MessageBoxButtons.YesNo, "Open save file from the following location?", path) == DialogResult.Yes) + openQuick(path); // load save } private void clickOpenTempFolder(object sender, EventArgs e) { string path; - if (ModifierKeys == Keys.Control) + switch (ModifierKeys) { - path = Util.GetCacheFolder(); - if (Directory.Exists(path)) - System.Diagnostics.Process.Start("explorer.exe", @path); - else - Util.Alert("Can't find the cache folder."); - } - else if (ModifierKeys == Keys.Alt) - { - path = Util.GetSDFLocation(); - if (Directory.Exists(path)) - System.Diagnostics.Process.Start("explorer.exe", @path); - else - Util.Alert("Can't find the SDF folder."); - } - else - { - path = Util.GetTempFolder(); - if (Directory.Exists(Path.Combine(path, "root"))) - System.Diagnostics.Process.Start("explorer.exe", @Path.Combine(path, "root")); - else if (Directory.Exists(path)) - System.Diagnostics.Process.Start("explorer.exe", @path); - else { Util.Error("Can't find the temporary file.", "Make sure the Cyber Gadget software is paused."); } + case Keys.Control: // Cache + path = Util.GetCacheFolder(); + if (Directory.Exists(path)) System.Diagnostics.Process.Start("explorer.exe", @path); else Util.Alert("Can't find the cache folder."); + break; + case Keys.Alt: // SaveDataFiler + path = Util.GetSDFLocation(); + if (Directory.Exists(path)) System.Diagnostics.Process.Start("explorer.exe", @path); else Util.Alert("Can't find the SDF folder."); + break; + default: // Root + path = Util.GetTempFolder(); + if (Directory.Exists(Path.Combine(path, "root"))) System.Diagnostics.Process.Start("explorer.exe", @Path.Combine(path, "root")); + else if (Directory.Exists(path)) System.Diagnostics.Process.Start("explorer.exe", @path); + else { Util.Error("Can't find the temporary file.", "Make sure the Cyber Gadget software is paused."); } + break; } } + private void clickSwitchSAV(object sender, EventArgs e) { DialogResult switchsav = Util.Prompt(MessageBoxButtons.YesNo, String.Format("Current Savefile is Save {0}.", (savindex + 1)), String.Format("Would you like to switch to Save {0}?", ((savindex + 1) % 2 + 1))); - if (switchsav == DialogResult.Yes) - { - savindex = (savindex + 1) % 2; - setBoxNames(); - setPKXBoxes(); - setSAVLabel(); - } + if (switchsav != DialogResult.Yes) return; + savindex = (savindex + 1) % 2; + setBoxNames(); + setPKXBoxes(); + setSAVLabel(); } // Drag & Drop within Box private void pbBoxSlot_MouseDown(object sender, MouseEventArgs e) { if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Alt || ModifierKeys == Keys.Shift || ModifierKeys == (Keys.Control | Keys.Alt)) - { clickSlot(sender, (EventArgs)e); return; } + { clickSlot(sender, e); return; } PictureBox pb = (PictureBox)(sender); if (pb.Image == null) return; pkm_from_slot = getSlot(sender); int offset = getPKXOffset(pkm_from_slot); - if (e.Button == MouseButtons.Left && e.Clicks == 1) + if (e.Button != MouseButtons.Left || e.Clicks != 1) return; + // Create Temp File to Drag + string basepath = Application.StartupPath; + Cursor.Current = Cursors.Hand; + + // Prepare Data + Array.Copy(savefile, offset, pkm_from, 0, 0xE8); + pkm_from_offset = offset; + + // Make a new file name based off the PID + byte[] dragdata = PKX.decryptArray(pkm_from); + Array.Resize(ref dragdata, 0xE8); + PKX pkx = new PKX(dragdata, "Boxes"); + string filename = pkx.Nickname; + if (filename != pkx.Species) + filename += " (" + pkx.Species + ")"; + filename += " - " + pkx.PID + ".pk6"; + + // Make File + string newfile = Path.Combine(basepath, Util.CleanFileName(filename)); + try { - // Create Temp File to Drag - string basepath = System.Windows.Forms.Application.StartupPath; - Cursor.Current = Cursors.Hand; + File.WriteAllBytes(newfile, dragdata); - // Prepare Data - Array.Copy(savefile, offset, pkm_from, 0, 0xE8); - pkm_from_offset = offset; - - // Make a new file name based off the PID - byte[] dragdata = PKX.decryptArray(pkm_from); - Array.Resize(ref dragdata, 0xE8); - PKX pkx = new PKX(dragdata, "Boxes"); - string filename = pkx.Nickname; - if (filename != pkx.Species) - filename += " (" + pkx.Species + ")"; - filename += " - " + pkx.PID + ".pk6"; - - // Make File - string newfile = Path.Combine(basepath, Util.CleanFileName(filename)); - try - { - File.WriteAllBytes(newfile, dragdata); - - string[] filesToDrag = { newfile }; - this.DoDragDrop(new DataObject(DataFormats.FileDrop, filesToDrag), DragDropEffects.Move); - File.Delete(newfile); // after drop, delete the temporary file - } - catch (ArgumentException x) - { Util.Error("Drag & Drop Error:", x.ToString()); } - File.Delete(newfile); - pkm_from_offset = 0; + string[] filesToDrag = { newfile }; + DoDragDrop(new DataObject(DataFormats.FileDrop, filesToDrag), DragDropEffects.Move); + File.Delete(newfile); // after drop, delete the temporary file } + catch (ArgumentException x) + { Util.Error("Drag & Drop Error:", x.ToString()); } + File.Delete(newfile); + pkm_from_offset = 0; } private void pbBoxSlot_DragDrop(object sender, DragEventArgs e) { - PictureBox pb = (PictureBox)(sender); int slot = getSlot(sender); int offset = getPKXOffset(slot); // Check for In-Dropped files (PKX,SAV,ETC) string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (Directory.Exists(files[0])) { loadBoxesFromDB(files[0]); return; } - if (files != null && pkm_from_offset == 0) + if (pkm_from_offset == 0) { if (files.Length > 0) { @@ -4708,7 +4661,7 @@ namespace PKHeX e.Effect = DragDropEffects.Move; } private byte[] pkm_from = PKX.encryptArray(new byte[0xE8]); - private int pkm_from_offset = 0; + private int pkm_from_offset; private int pkm_from_slot = -1; #endregion } diff --git a/PKX/f2-Text.cs b/PKX/f2-Text.cs index c738b0ff5..d4c45a3bf 100644 --- a/PKX/f2-Text.cs +++ b/PKX/f2-Text.cs @@ -1,10 +1,5 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace PKHeX @@ -14,19 +9,19 @@ namespace PKHeX public f2_Text(TextBox TB_NN) { Form1.specialChars = true; - this.Hide(); + Hide(); InitializeComponent(); Util.TranslateInterface(this, Form1.curlanguage); TB_Nickname = TB_NN; Font pkxFont = PKX.getPKXFont(12F); - Label[] lbla = new Label[] + Label[] lbla = { L00, L01, L02, L03, L04, L05, L06, L07, L08, L09, L0A, L0B, L0C, L0D, L0E, L0F, L10, L11, L12, L13, L14, L15, L16, L17, L18, L19, L1A, L1B, L1C, L1D, L1E, L1F, }; - ushort[] chars = new ushort[] + ushort[] chars = { 0xE081, 0xE082, 0xE083, 0xE084, 0xE085, 0xE086, 0xE087, 0xE08D, 0xE08E, 0xE08F, 0xE090, 0xE091, 0xE092, 0xE093, 0xE094, 0xE095, @@ -37,10 +32,10 @@ namespace PKHeX { lbla[i].Font = pkxFont; lbla[i].Text = Convert.ToChar(chars[i]).ToString(); - lbla[i].Click += new EventHandler(onClick); + lbla[i].Click += onClick; } - this.CenterToParent(); - this.Show(); + CenterToParent(); + Show(); } TextBox TB_Nickname; private void onClick(object sender, EventArgs e) diff --git a/PKX/f3-MemoryAmie.cs b/PKX/f3-MemoryAmie.cs index d3654d14a..3a3e02a32 100644 --- a/PKX/f3-MemoryAmie.cs +++ b/PKX/f3-MemoryAmie.cs @@ -1,13 +1,6 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; -using System.IO; using System.Text.RegularExpressions; +using System.Windows.Forms; namespace PKHeX { @@ -45,7 +38,14 @@ namespace PKHeX past = arguments[3]; withOT = arguments[4]; } - catch { }; + catch + { + disabled = "Disabled"; + notleft = "Never left"; + ot = "OT"; + past = "Past Gen"; + withOT = "Memories with"; + } h = m_parent.buff; getCountries(); @@ -54,7 +54,7 @@ namespace PKHeX } public string[] feeling; public string[] quality; - bool init = false; + bool init; // Load/Save Actions private void loadFields() @@ -118,8 +118,8 @@ namespace PKHeX if ((!m_parent.CHK_IsEgg.Checked)) { - bool enable = false; - int game = (int)(Util.getIndex(m_parent.CB_GameOrigin)); + bool enable; + int game = Util.getIndex(m_parent.CB_GameOrigin); if ((game < 24) && (game != 0)) { // Banked Mon @@ -225,11 +225,11 @@ namespace PKHeX } private void i1cb(ComboBox cb, int o) { - cb.SelectedIndex = (int)h[o]; + cb.SelectedIndex = h[o]; } private void v2cb(ComboBox cb, int o) { - cb.SelectedValue = (int)(h[o] + h[o + 1] * 0x100); + cb.SelectedValue = h[o] + h[o + 1] * 0x100; } private void cb1v(ComboBox cb, int o) { @@ -258,14 +258,15 @@ namespace PKHeX private void getCountries() { - ComboBox[] cba = new ComboBox[] { CB_Country0, CB_Country1, CB_Country2, CB_Country3, CB_Country4, }; - for (int i = 0; i < cba.Length; i++) + ComboBox[] cba = { CB_Country0, CB_Country1, CB_Country2, CB_Country3, CB_Country4, }; + foreach (ComboBox comboBox in cba) { - cba[i].DisplayMember = "Text"; - cba[i].ValueMember = "Value"; - m_parent.setCountrySubRegion(cba[i], "countries"); + comboBox.DisplayMember = "Text"; + comboBox.ValueMember = "Value"; + m_parent.setCountrySubRegion(comboBox, "countries"); } } + private void getLangStrings() { // Memory Chooser @@ -278,7 +279,7 @@ namespace PKHeX allowed[i] = i + 1; } Array.Resize(ref allowed, allowed.Length - 1); - var memory_list1 = Util.getCBList(new string[] { memories[0] }, null); + var memory_list1 = Util.getCBList(new[] { memories[0] }, null); var memory_list = Util.getOffsetCBList(memory_list1, memories, 0, allowed); CB_OTMemory.DisplayMember = "Text"; @@ -309,7 +310,7 @@ namespace PKHeX } private void getMemoryArguments(string ARG, ComboBox sender) { - var argvals = Util.getCBList(new string[] { "" }, null); + var argvals = Util.getCBList(new[] { "" }, null); string vs = ""; bool enabled = true; @@ -331,25 +332,25 @@ namespace PKHeX else if (ARG == "ITEM") { #region Items - int[] items_allowed = new int[] + int[] items_allowed = { - 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49, - 50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99, - 100,101,102,103,104,105,106,107,108,109,110,111,112,116,117,118,119,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149, - 150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199, - 200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249, - 250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299, - 300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349, - 350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399, - 400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449, - 450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499, - 500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549, - 550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599, - 600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649, - 650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699, - 700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717, - /* ORAS */ - 718,719,720,737,738,739,740,741,742,765,775 + 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49, + 50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99, + 100,101,102,103,104,105,106,107,108,109,110,111,112,116,117,118,119,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149, + 150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199, + 200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249, + 250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299, + 300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349, + 350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399, + 400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449, + 450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499, + 500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549, + 550,551,552,553,554,555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599, + 600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,643,644,645,646,647,648,649, + 650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699, + 700,701,702,703,704,705,706,707,708,709,710,711,712,713,714,715,716,717, + /* ORAS */ + 718,719,720,737,738,739,740,741,742,765,775 }; var item_list = Util.getCBList(Form1.itemlist, items_allowed); #endregion @@ -363,7 +364,6 @@ namespace PKHeX } else if (ARG == "LOCATION") { - int[] allowed = { }; argvals = Util.getCBList(Form1.metXY_00000, Legal.Met_XY_0); vs = vartypes[4]; } @@ -487,7 +487,7 @@ namespace PKHeX case 63: getMemoryArguments("NONE", m); break; case 64: getMemoryArguments("NONE", m); break; default: getMemoryArguments("NONE", m); break; - }; + } } if (!init) return; @@ -496,11 +496,11 @@ namespace PKHeX } private void changeCountry(object sender, EventArgs e) { - ComboBox[] cba = new ComboBox[] + ComboBox[] cba = { CB_Country0, CB_Country1, CB_Country2, CB_Country3, CB_Country4 }; - ComboBox[] mta = new ComboBox[] + ComboBox[] mta = { CB_Region0, CB_Region1, CB_Region2, CB_Region3, CB_Region4, }; @@ -522,15 +522,15 @@ namespace PKHeX private void clickResetLocation(object sender, EventArgs e) { - Label[] senderarr = new Label[] + Label[] senderarr = { L_Geo0, L_Geo1, L_Geo2, L_Geo3, L_Geo4, }; - ComboBox[] cba = new ComboBox[] + ComboBox[] cba = { CB_Country0, CB_Country1, CB_Country2, CB_Country3, CB_Country4, }; - ComboBox[] mta = new ComboBox[] + ComboBox[] mta = { CB_Region0, CB_Region1, CB_Region2, CB_Region3, CB_Region4, }; diff --git a/PKX/f4-RibbMedal.cs b/PKX/f4-RibbMedal.cs index 9f6466541..83c8f829c 100644 --- a/PKX/f4-RibbMedal.cs +++ b/PKX/f4-RibbMedal.cs @@ -1,21 +1,13 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Drawing.Imaging; using System.Linq; -using System.Text; using System.Windows.Forms; -using System.IO; -using System.Text.RegularExpressions; namespace PKHeX { public partial class RibbMedal : Form { Form1 m_parent; - CheckBox[] distro; public RibbMedal(Form1 frm1) { InitializeComponent(); @@ -29,7 +21,6 @@ namespace PKHeX comboBox1.Items.Add(Form1.trainingbags[i]); comboBox1.SelectedIndex = m_parent.buff[0x17]; numericUpDown1.Value = m_parent.buff[0x16]; - distro = new CheckBox[] { CHK_D0, CHK_D1, CHK_D2, CHK_D3, CHK_D4, CHK_D5 }; getRibbons(); } private void getRibbons() @@ -298,7 +289,7 @@ namespace PKHeX dis |= addRibbon(CHK_D5); m_parent.buff[0x3A] = (byte)dis; - m_parent.buff[0x72] = (byte)Convert.ToByte(CHK_Secret.Checked); + m_parent.buff[0x72] = Convert.ToByte(CHK_Secret.Checked); } // Saving Ribbons prompted private void updateRibbon(CheckBox chk, int rv, int sh) { @@ -341,11 +332,9 @@ namespace PKHeX TB_PastContest.Text = (Convert.ToInt32(b) * 40).ToString(); TB_PastBattle.Text = (Convert.ToInt32(b) * 8).ToString(); - if (m_parent.buff[0xDF] > 0x10) - { - TB_PastContest.Text = 0.ToString(); - TB_PastBattle.Text = 0.ToString(); - } + if (m_parent.buff[0xDF] <= 0x10) return; // gen3 + TB_PastContest.Text = 0.ToString(); // no past gen ribbons 4-5 + TB_PastBattle.Text = 0.ToString(); } else if (tabControl1.SelectedTab == Tab_Medals) { @@ -369,7 +358,7 @@ namespace PKHeX CHK_Secret }; checkboxFlag(ck, b); - foreach (CheckBox chk in distro) chk.Checked = b; + foreach (CheckBox chk in new[] { CHK_D0, CHK_D1, CHK_D2, CHK_D3, CHK_D4, CHK_D5 }) chk.Checked = b; } } // Checkbox Flipping Logic (dependent on Tab) @@ -396,15 +385,13 @@ namespace PKHeX private void updateSecretSuper(object sender, EventArgs e) { GB_Medals2.Enabled = CHK_Secret.Checked; - if (!CHK_Secret.Checked) - { - CheckBox[] ck = {TMedal3_4, - TMedal3_5, TMedal3_6, TMedal3_7, TMedal4_0, - TMedal4_1, TMedal4_2, TMedal4_3, - TMedal4_4, TMedal4_5, TMedal4_6, - TMedal4_7}; - checkboxFlag(ck, false); - } + if (CHK_Secret.Checked) return; + CheckBox[] ck = { + TMedal3_4, TMedal3_5, TMedal3_6, TMedal3_7, + TMedal4_0, TMedal4_1, TMedal4_2, TMedal4_3, + TMedal4_4, TMedal4_5, TMedal4_6, TMedal4_7 + }; + checkboxFlag(ck, false); } // Only allow secret if checkbox is toggled. private void unusedbits(object sender, EventArgs e) { @@ -458,7 +445,7 @@ namespace PKHeX int index = Array.IndexOf(cba, sender as CheckBox); - pba[index].Image = Util.ChangeOpacity(bma[index], (float)(Convert.ToInt32(cba[index].Checked)) * 0.9 + 0.1); + pba[index].Image = Util.ChangeOpacity(bma[index], Convert.ToInt32(cba[index].Checked) * 0.9 + 0.1); } private void pastribbontoggle(object sender, EventArgs e) { @@ -466,18 +453,11 @@ namespace PKHeX PastContest, PastBattle, }; - if (Util.ToUInt32(TB_PastContest.Text) < 40) - pba2[0].Image = Properties.Resources.contestmemory; - else - pba2[0].Image = Properties.Resources.contestmemory2; + pba2[0].Image = Util.ToUInt32(TB_PastContest.Text) < 40 ? Properties.Resources.contestmemory : Properties.Resources.contestmemory2; + pba2[1].Image = Util.ToUInt32(TB_PastBattle.Text) < 8 ? Properties.Resources.battlememory : Properties.Resources.battlememory2; - if (Util.ToUInt32(TB_PastBattle.Text) < 8) - pba2[1].Image = Properties.Resources.battlememory; - else - pba2[1].Image = Properties.Resources.battlememory2; - - pba2[0].Image = Util.ChangeOpacity(pba2[0].Image, (float)(Util.ToUInt32(TB_PastContest.Text)) * 0.9 + 0.1); - pba2[1].Image = Util.ChangeOpacity(pba2[1].Image, (float)(Util.ToUInt32(TB_PastBattle.Text)) * 0.9 + 0.1); + pba2[0].Image = Util.ChangeOpacity(pba2[0].Image, Util.ToUInt32(TB_PastContest.Text) * 0.9 + 0.1); + pba2[1].Image = Util.ChangeOpacity(pba2[1].Image, Util.ToUInt32(TB_PastBattle.Text) * 0.9 + 0.1); } private void clickRibbon(object sender, EventArgs e) diff --git a/Program.cs b/Program.cs index ebdf36c05..2a86901bb 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Windows.Forms; namespace PKHeX diff --git a/SAV/SAV_BerryField.cs b/SAV/SAV_BerryField.cs index f5d087267..b81a59d08 100644 --- a/SAV/SAV_BerryField.cs +++ b/SAV/SAV_BerryField.cs @@ -1,10 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace PKHeX @@ -16,14 +10,13 @@ namespace PKHeX berryfoffset = bfo; InitializeComponent(); Util.TranslateInterface(this, Form1.curlanguage); - m_parent = frm1; - Array.Copy(m_parent.savefile, sav, 0x100000); - savindex = m_parent.savindex; + Form1 mParent = frm1; + Array.Copy(mParent.savefile, sav, 0x100000); + savindex = mParent.savindex; shiftval = savindex * 0x7F000; listBox1.SelectedIndex = 0; } int berryfoffset; - Form1 m_parent; public byte[] sav = new byte[0x100000]; public int savindex; int shiftval; public bool editing = false; diff --git a/SAV/SAV_BoxLayout.cs b/SAV/SAV_BoxLayout.cs index 792100037..1f1bc20cd 100644 --- a/SAV/SAV_BoxLayout.cs +++ b/SAV/SAV_BoxLayout.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; using System.Text; using System.Windows.Forms; @@ -22,8 +18,8 @@ namespace PKHeX // Repopulate Wallpaper names CB_BG.Items.Clear(); - for (int i = 0; i < Form1.wallpapernames.Length; i++) - CB_BG.Items.Add(Form1.wallpapernames[i]); + foreach (string wallpaper in Form1.wallpapernames) + CB_BG.Items.Add(wallpaper); // Go LB_BoxSelect.SelectedIndex = m_parent.C_BoxSelect.SelectedIndex; diff --git a/SAV/SAV_EventFlagsORAS.cs b/SAV/SAV_EventFlagsORAS.cs index cb3b2490a..925a7c051 100644 --- a/SAV/SAV_EventFlagsORAS.cs +++ b/SAV/SAV_EventFlagsORAS.cs @@ -1,13 +1,8 @@ using System; using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; using System.IO; +using System.Windows.Forms; namespace PKHeX { @@ -20,9 +15,9 @@ namespace PKHeX m_parent = frm1; savshift = 0x7F000 * m_parent.savindex; - this.AllowDrop = true; - this.DragEnter += tabMain_DragEnter; - this.DragDrop += tabMain_DragDrop; + AllowDrop = true; + DragEnter += tabMain_DragEnter; + DragDrop += tabMain_DragDrop; Setup(); nud.Text = "0"; // Prompts an update for flag 0. @@ -41,8 +36,8 @@ namespace PKHeX private void B_Save_Click(object sender, EventArgs e) { // Gather Updated Flags - for (int i = 0; i < chka.Length; i++) - flags[getFlagNum(chka[i])] = chka[i].Checked; + foreach (CheckBox flag in chka) + flags[getFlagNum(flag)] = flag.Checked; byte[] data = new byte[flags.Length / 8]; @@ -58,15 +53,15 @@ namespace PKHeX // Copy back Constants changeConstantIndex(null, null); // Trigger Saving for (int i = 0; i < Constants.Length; i++) - Array.Copy(BitConverter.GetBytes((ushort)Constants[i]), 0, m_parent.savefile, 0x19E00 + savshift + 2 * i, 2); + Array.Copy(BitConverter.GetBytes(Constants[i]), 0, m_parent.savefile, 0x19E00 + savshift + 2 * i, 2); - this.Close(); + Close(); } private void Setup() { // Fill Bit arrays - chka = new CheckBox[] { + chka = new[] { flag_0173,flag_2811, // Raikou flag_0174,flag_2812, // Entei @@ -131,13 +126,11 @@ namespace PKHeX } private void popFlags() { - if (setup) - { - for (int i = 0; i < chka.Length; i++) - chka[i].Checked = flags[getFlagNum(chka[i])]; + if (!setup) return; + foreach (CheckBox flag in chka) + flag.Checked = flags[getFlagNum(flag)]; - changeCustomFlag(null, null); - } + changeCustomFlag(null, null); } private int getFlagNum(CheckBox chk) @@ -195,13 +188,11 @@ namespace PKHeX string tbUnSet = ""; for (int i = 0; i < oldBits.Length; i++) { - if (oldBits[i] != newBits[i]) - { - if (newBits[i]) - tbIsSet += (i.ToString("0000") + ","); - else - tbUnSet += (i.ToString("0000") + ","); - } + if (oldBits[i] == newBits[i]) continue; + if (newBits[i]) + tbIsSet += (i.ToString("0000") + ","); + else + tbUnSet += (i.ToString("0000") + ","); } TB_IsSet.Text = tbIsSet; TB_UnSet.Text = tbUnSet; @@ -218,14 +209,21 @@ namespace PKHeX { FileInfo fi = new FileInfo(path); byte[] eventflags = new byte[0x180]; - if (fi.Length == 0x100000) - Array.Copy(File.ReadAllBytes(path), 0x1A0FC, eventflags, 0, 0x180); - else if (fi.Length == 0x76000) - Array.Copy(File.ReadAllBytes(path), 0x1A0FC - 0x5400, eventflags, 0, 0x180); - else if (fi.Name.ToLower().Contains("ram") && fi.Length == 0x80000) - Array.Copy(ram2sav.getMAIN(File.ReadAllBytes(path)), 0x1A0FC - 0x5400, eventflags, 0, 0x180); - else - { Util.Error("Invalid SAV Size", String.Format("File Size: 0x{1} ({0} bytes)", fi.Length.ToString(), fi.Length.ToString("X5")), "File Loaded: " + path); return; } + switch (fi.Length) + { + case 0x100000: // ramsav + Array.Copy(File.ReadAllBytes(path), 0x1A0FC, eventflags, 0, 0x180); + break; + case 0x76000: // oras main + Array.Copy(File.ReadAllBytes(path), 0x1A0FC - 0x5400, eventflags, 0, 0x180); + break; + default: // figure it out + if (fi.Name.ToLower().Contains("ram") && fi.Length == 0x80000) + Array.Copy(ram2sav.getMAIN(File.ReadAllBytes(path)), 0x1A0FC - 0x5400, eventflags, 0, 0x180); + else + { Util.Error("Invalid SAV Size", String.Format("File Size: 0x{1} ({0} bytes)", fi.Length.ToString(), fi.Length.ToString("X5")), "File Loaded: " + path); return; } + break; + } Button bs = (Button)sender; if (bs.Name == "B_LoadOld") diff --git a/SAV/SAV_EventFlagsXY.cs b/SAV/SAV_EventFlagsXY.cs index c0bed92c6..12de4dca0 100644 --- a/SAV/SAV_EventFlagsXY.cs +++ b/SAV/SAV_EventFlagsXY.cs @@ -1,13 +1,8 @@ using System; using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; -using System.Windows.Forms; using System.IO; +using System.Windows.Forms; namespace PKHeX { @@ -20,9 +15,9 @@ namespace PKHeX m_parent = frm1; savshift = 0x7F000 * m_parent.savindex; - this.AllowDrop = true; - this.DragEnter += tabMain_DragEnter; - this.DragDrop += tabMain_DragDrop; + AllowDrop = true; + DragEnter += tabMain_DragEnter; + DragDrop += tabMain_DragDrop; Setup(); @@ -41,8 +36,8 @@ namespace PKHeX private void B_Save_Click(object sender, EventArgs e) { // Gather Updated Flags - for (int i = 0; i < chka.Length; i++) - flags[getFlagNum(chka[i])] = chka[i].Checked; + foreach (CheckBox flag in chka) + flags[getFlagNum(flag)] = flag.Checked; byte[] data = new byte[flags.Length / 8]; @@ -56,15 +51,15 @@ namespace PKHeX // Copy back Constants changeConstantIndex(null, null); // Trigger Saving for (int i = 0; i < Constants.Length; i++) - Array.Copy(BitConverter.GetBytes((ushort)Constants[i]), 0, m_parent.savefile, 0x19E00 + savshift + 2 * i, 2); + Array.Copy(BitConverter.GetBytes(Constants[i]), 0, m_parent.savefile, 0x19E00 + savshift + 2 * i, 2); - this.Close(); + Close(); } private void Setup() { // Fill Bit arrays - chka = new CheckBox[] { + chka = new[] { flag_0001,flag_0002,flag_0003,flag_0004,flag_0005, flag_2237,flag_2238,flag_2239, flag_0115,flag_0963, // Mewtwo @@ -95,13 +90,11 @@ namespace PKHeX } private void popFlags() { - if (setup) - { - for (int i = 0; i < chka.Length; i++) - chka[i].Checked = flags[getFlagNum(chka[i])]; + if (!setup) return; + foreach (CheckBox flag in chka) + flag.Checked = flags[getFlagNum(flag)]; - changeCustomFlag(null, null); - } + changeCustomFlag(null, null); } private int getFlagNum(CheckBox chk) @@ -184,14 +177,21 @@ namespace PKHeX { FileInfo fi = new FileInfo(path); byte[] eventflags = new byte[0x180]; - if (fi.Length == 0x100000) - Array.Copy(File.ReadAllBytes(path), 0x1A0FC, eventflags, 0, 0x180); - else if (fi.Length == 0x65600) - Array.Copy(File.ReadAllBytes(path), 0x1A0FC - 0x5400, eventflags, 0, 0x180); - else if (fi.Name.ToLower().Contains("ram") && fi.Length == 0x70000) - Array.Copy(ram2sav.getMAIN(File.ReadAllBytes(path)), 0x1A0FC - 0x5400, eventflags, 0, 0x180); - else - { Util.Error("Invalid SAV Size", String.Format("File Size: 0x{1} ({0} bytes)", fi.Length.ToString(), fi.Length.ToString("X5")), "File Loaded: " + path); return; } + switch (fi.Length) + { + case 0x100000: // ramsav + Array.Copy(File.ReadAllBytes(path), 0x1A0FC, eventflags, 0, 0x180); + break; + case 0x65600: // xy main + Array.Copy(File.ReadAllBytes(path), 0x1A0FC - 0x5400, eventflags, 0, 0x180); + break; + default: // figure it out + if (fi.Name.ToLower().Contains("ram") && fi.Length == 0x70000) + Array.Copy(ram2sav.getMAIN(File.ReadAllBytes(path)), 0x1A0FC - 0x5400, eventflags, 0, 0x180); + else + { Util.Error("Invalid SAV Size", String.Format("File Size: 0x{1} ({0} bytes)", fi.Length.ToString(), fi.Length.ToString("X5")), "File Loaded: " + path); return; } + break; + } Button bs = (Button)sender; if (bs.Name == "B_LoadOld") diff --git a/SAV/SAV_HallOfFame.cs b/SAV/SAV_HallOfFame.cs index e46c030aa..9c48f8086 100644 --- a/SAV/SAV_HallOfFame.cs +++ b/SAV/SAV_HallOfFame.cs @@ -1,10 +1,5 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.IO; -using System.Linq; using System.Text; using System.Windows.Forms; @@ -59,7 +54,7 @@ namespace PKHeX Form1 m_parent; public byte[] sav = new byte[0x100000]; public int savindex; int shiftval; - public bool editing = false; + public bool editing; private int data_offset = 0x1E800; private string[] types = Form1.types; @@ -71,16 +66,12 @@ namespace PKHeX private void Setup() { - try - { - CB_Species.Items.Clear(); - CB_HeldItem.Items.Clear(); - CB_Move1.Items.Clear(); - CB_Move2.Items.Clear(); - CB_Move3.Items.Clear(); - CB_Move4.Items.Clear(); - } - catch { } + CB_Species.Items.Clear(); + CB_HeldItem.Items.Clear(); + CB_Move1.Items.Clear(); + CB_Move2.Items.Clear(); + CB_Move3.Items.Clear(); + CB_Move4.Items.Clear(); #region Species { @@ -123,7 +114,6 @@ namespace PKHeX { editing = false; RTB.Font = new Font("Courier New", 8); - string s = ""; RTB.LanguageOption = RichTextBoxLanguageOptions.DualFont; int index = LB_DataEntry.SelectedIndex; int offset = index * 0x1B4; @@ -131,7 +121,7 @@ namespace PKHeX uint vnd = BitConverter.ToUInt32(data, offset + 0x1B0); uint vn = vnd & 0xFF; TB_VN.Text = vn.ToString("000"); - s = "Entry #" + vn + Environment.NewLine; + string s = "Entry #" + vn + Environment.NewLine; uint date = (vnd >> 14) & 0x1FFFF; uint year = (date & 0xFF) + 2000; uint month = (date >> 8) & 0xF; @@ -139,20 +129,17 @@ namespace PKHeX if (day == 0) { s += "No records in this slot."; - for (int i = 0; i < editor_spec.Length; i++) - ((Control)editor_spec[i]).Enabled = false; + foreach (object t in editor_spec) + ((Control)t).Enabled = false; editing = false; NUP_PartyIndex_ValueChanged(sender, e); goto end; } - else - { - for (int i = 0; i < editor_spec.Length; i++) - ((Control)editor_spec[i]).Enabled = true; - } + foreach (object t in editor_spec) + ((Control)t).Enabled = true; - s += "Date: " + year.ToString() + "/" + month.ToString() + "/" + day.ToString() + "" + Environment.NewLine + Environment.NewLine; + s += "Date: " + year + "/" + month + "/" + day + "" + Environment.NewLine + Environment.NewLine; CAL_MetDate.Value = new DateTime((int)year, (int)month, (int)day); int moncount = 0; for (int i = 0; i < 6; i++) @@ -168,11 +155,11 @@ namespace PKHeX int SID = BitConverter.ToUInt16(data, offset + 0x12); uint slgf = BitConverter.ToUInt32(data, offset + 0x14); - uint form = slgf & 0x1F; + // uint form = slgf & 0x1F; uint gender = (slgf >> 5) & 3; // 0 M; 1 F; 2 G uint level = (slgf >> 7) & 0x7F; uint shiny = (slgf >> 14) & 0x1; - uint unkn = slgf >> 15; + // uint unkn = slgf >> 15; string nickname = Util.TrimFromZero(Encoding.Unicode.GetString(data, offset + 0x18, 22)); string OTname = Util.TrimFromZero(Encoding.Unicode.GetString(data, offset + 0x30, 22)); @@ -186,14 +173,14 @@ namespace PKHeX s += "Name: " + nickname; s += " (" + Form1.specieslist[species] + " - " + genderstr + ")" + Environment.NewLine; - s += "Level: " + level.ToString() + Environment.NewLine; + s += "Level: " + level + Environment.NewLine; s += "Shiny: " + shinystr + Environment.NewLine; s += "Held Item: " + Form1.itemlist[helditem] + Environment.NewLine; s += "Move 1: " + Form1.movelist[move1] + Environment.NewLine; s += "Move 2: " + Form1.movelist[move2] + Environment.NewLine; s += "Move 3: " + Form1.movelist[move3] + Environment.NewLine; s += "Move 4: " + Form1.movelist[move4] + Environment.NewLine; - s += "OT: " + OTname + " (" + TID.ToString() + "/" + SID.ToString() + ")" + Environment.NewLine; + s += "OT: " + OTname + " (" + TID + "/" + SID + ")" + Environment.NewLine; s += Environment.NewLine; offset += 0x48; @@ -412,10 +399,7 @@ namespace PKHeX if (gt < 256) // If not a single gender(less) species: { - if (PKX.getGender(Label_Gender.Text) == 0) // ♂ - Label_Gender.Text = gendersymbols[1]; // ♀ - else - Label_Gender.Text = gendersymbols[0]; // ♂ + Label_Gender.Text = PKX.getGender(Label_Gender.Text) == 0 ? gendersymbols[1] : gendersymbols[0]; if (PKX.getGender(CB_Form.Text) == 0 && Label_Gender.Text != gendersymbols[0]) CB_Form.SelectedIndex = 1; @@ -447,26 +431,25 @@ namespace PKHeX { bpkx.Image = (Image)Properties.Resources.ResourceManager.GetObject("_0"); } else { - file = "_" + species.ToString(); + file = "_" + species; if (form > 0) // Alt Form Handling - file = file + "_" + form.ToString(); + file = file + "_" + form; else if ((gender == 1) && (species == 521 || species == 668)) // Unfezant & Pyroar - file = file = "_" + species.ToString() + "f"; + file = "_" + species + "f"; } Image baseImage = (Image)Properties.Resources.ResourceManager.GetObject(file); if (shiny) { // Is Shiny // Redraw our image - baseImage = PKHeX.Util.LayerImage(baseImage, Properties.Resources.rare_icon, 0, 0, 0.7); + baseImage = Util.LayerImage(baseImage, Properties.Resources.rare_icon, 0, 0, 0.7); } if (item > 0) { // Has Item - Image itemimg = (Image)Properties.Resources.ResourceManager.GetObject("item_" + item.ToString()); - if (itemimg == null) itemimg = Properties.Resources.helditem; + Image itemimg = (Image)Properties.Resources.ResourceManager.GetObject("item_" + item) ?? Properties.Resources.helditem; // Redraw - baseImage = PKHeX.Util.LayerImage(baseImage, itemimg, 22 + (15 - itemimg.Width) / 2, 15 + (15 - itemimg.Height), 1); + baseImage = Util.LayerImage(baseImage, itemimg, 22 + (15 - itemimg.Width) / 2, 15 + (15 - itemimg.Height), 1); } bpkx.Image = baseImage; editing = true; diff --git a/SAV/SAV_Inventory.cs b/SAV/SAV_Inventory.cs index 5c057c592..c1914f2f1 100644 --- a/SAV/SAV_Inventory.cs +++ b/SAV/SAV_Inventory.cs @@ -1,10 +1,5 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace PKHeX @@ -21,7 +16,7 @@ namespace PKHeX shiftval = savindex * 0x7F000; if (m_parent.savegame_oras) { - bagoffsets = new int[] + bagoffsets = new[] { 0x05800, 0x05E40, @@ -58,13 +53,14 @@ namespace PKHeX public string[] medicine_val; public string[] berries_val; - public int[] bagoffsets = new int[] { - 0x05800, - 0x05E40, - 0x05FC0, - 0x06168, - 0x06268, - }; + public int[] bagoffsets = + { + 0x05800, + 0x05E40, + 0x05FC0, + 0x06168, + 0x06268, + }; // Initialize String Tables private void getListItems() @@ -147,11 +143,13 @@ namespace PKHeX dgvIndex.Width = 45; dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; } - DataGridViewComboBoxColumn dgvItemVal = new DataGridViewComboBoxColumn(); - dgvItemVal.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; + DataGridViewComboBoxColumn dgvItemVal = new DataGridViewComboBoxColumn { - for (int i = 0; i < itemarr.Length; i++) - dgvItemVal.Items.Add(itemarr[i]); // add only the Item Names + DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing + }; + { + foreach (string t in itemarr) + dgvItemVal.Items.Add(t); // add only the Item Names dgvItemVal.DisplayIndex = 0; dgvItemVal.Width = 135; @@ -197,31 +195,25 @@ namespace PKHeX } private void saveBag(object sender) { - string[] itemstrarr = {}; int offset = 0; if (B_DisplayItems.ForeColor == Color.Red) { - itemstrarr = item_val; offset = bagoffsets[0] + shiftval; } else if (B_DisplayKeyItems.ForeColor == Color.Red) { - itemstrarr = keyitem_val; offset = bagoffsets[1] + shiftval; } else if (B_DisplayTMHM.ForeColor == Color.Red) { - itemstrarr = tmhm_val; offset = bagoffsets[2] + shiftval; } else if (B_DisplayMedicine.ForeColor == Color.Red) { - itemstrarr = medicine_val; offset = bagoffsets[3] + shiftval; } else if (B_DisplayBerries.ForeColor == Color.Red) { - itemstrarr = berries_val; offset = bagoffsets[4] + shiftval; } @@ -232,7 +224,7 @@ namespace PKHeX { string item = dataGridView1.Rows[i].Cells[0].Value.ToString(); int itemindex = Array.IndexOf(Form1.itemlist, item); - int itemcnt = 0; + int itemcnt; try { itemcnt = Convert.ToUInt16(dataGridView1.Rows[i].Cells[1].Value.ToString()); } catch { itemcnt = 0; } @@ -242,7 +234,7 @@ namespace PKHeX emptyslots++; continue; } - else if (itemcnt == 0) + if (itemcnt == 0) itemcnt++; // No 0 count of items else if (itemcnt > 995) itemcnt = 995; diff --git a/SAV/SAV_OPower.cs b/SAV/SAV_OPower.cs index 80241521a..2089390b1 100644 --- a/SAV/SAV_OPower.cs +++ b/SAV/SAV_OPower.cs @@ -1,10 +1,5 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; using System.Linq; -using System.Text; using System.Windows.Forms; namespace PKHeX @@ -23,12 +18,12 @@ namespace PKHeX private void B_Cancel_Click(object sender, EventArgs e) { - this.Close(); + Close(); } private void B_Save_Click(object sender, EventArgs e) { - this.SaveData(); - this.Close(); + SaveData(); + Close(); } private int opoweroffset = 0x1BE00; private void LoadData() @@ -36,10 +31,6 @@ namespace PKHeX int o = opoweroffset + m_parent.savindex * 0x7F000; // offset // Fill up the 17 o-powers - ComboBox[] cba = new ComboBox[] { - CB_1, CB_2, CB_3, CB_4, CB_5, CB_6, CB_7, CB_8, CB_9, - CB_10, CB_11, CB_12, CB_13, CB_14, CB_15, CB_16, CB_17, - }; // 1 2 3 4 5 10 use 4 bytes, everything else uses 3 o++; // Skip first 0 CB_1.SelectedIndex = getIndex(o, 4); o += 4; o++; // @ 1 @@ -76,11 +67,13 @@ namespace PKHeX } private void SaveData() { - ComboBox[] cba = new ComboBox[] { + ComboBox[] cba = + { CB_1, CB_2, CB_3, CB_4, CB_5, CB_6, CB_7, CB_8, CB_9, CB_10, CB_11, CB_12, CB_13, CB_14, CB_15, CB_16, CB_17, }; - int[] offsets= new int[] { + int[] offsets = + { 1,6,0xB,0x10,0x15, 0x1A,0x1D,0x20,0x23, 0x27, @@ -111,21 +104,20 @@ namespace PKHeX } private int getIndex(int o, int l) { - byte[] _0 = new byte[] { 00, 00, 00, 00, }; - byte[] _1 = new byte[] { 01, 00, 00, 00, }; - byte[] _2 = new byte[] { 01, 01, 00, 00, }; - byte[] _3 = new byte[] { 01, 01, 01, 00, }; - byte[] _4 = new byte[] { 01, 01, 01, 01, }; + byte[] _0 = { 00, 00, 00, 00, }; + byte[] _1 = { 01, 00, 00, 00, }; + byte[] _2 = { 01, 01, 00, 00, }; + byte[] _3 = { 01, 01, 01, 00, }; + byte[] _4 = { 01, 01, 01, 01, }; byte[] data = new byte[4]; Array.Copy(m_parent.savefile, o, data, 0, l); - if (data.SequenceEqual(_4)) return 4; - else if (data.SequenceEqual(_3)) return 3; - else if (data.SequenceEqual(_2)) return 2; - else if (data.SequenceEqual(_1)) return 1; - else if (data.SequenceEqual(_0)) return 0; - else return 1; + if (data.SequenceEqual(_4)) return 4; + if (data.SequenceEqual(_3)) return 3; + if (data.SequenceEqual(_2)) return 2; + if (data.SequenceEqual(_1)) return 1; + return data.SequenceEqual(_0) ? 0 : 1; } private void B_AllMax_Click(object sender, EventArgs e) { @@ -137,24 +129,25 @@ namespace PKHeX } private void max(bool s) { - ComboBox[] cba = new ComboBox[] { + ComboBox[] cba = + { CB_1, CB_2, CB_3, CB_4, CB_5, CB_6, CB_7, CB_8, CB_9, CB_10, CB_11, CB_12, CB_13, CB_14, CB_15, CB_16, CB_17, }; - CheckBox[] echk = new CheckBox[] { CHK_1, CHK_2, CHK_3, CHK_4, CHK_5, CHK_6, CHK_7, CHK_8 }; + CheckBox[] echk = { CHK_1, CHK_2, CHK_3, CHK_4, CHK_5, CHK_6, CHK_7, CHK_8 }; - for (int i = 0; i < cba.Length; i++) - cba[i].SelectedIndex = (cba[i].Items.Count-1); + foreach (ComboBox t in cba) + t.SelectedIndex = (t.Items.Count-1); if (!s) - for (int i = 0; i < echk.Length; i++) - echk[i].Checked = !(ModifierKeys == Keys.Control); + foreach (CheckBox t in echk) + t.Checked = ModifierKeys != Keys.Control; else if (ModifierKeys == Keys.Control) { - for (int i = 0; i < cba.Length; i++) - cba[i].SelectedIndex = 0; - for (int i = 0; i < echk.Length; i++) - echk[i].Checked = false; + foreach (ComboBox t in cba) + t.SelectedIndex = 0; + foreach (CheckBox t in echk) + t.Checked = false; } } } diff --git a/SAV/SAV_PokedexORAS.cs b/SAV/SAV_PokedexORAS.cs index aeb78e39e..3faa4dea8 100644 --- a/SAV/SAV_PokedexORAS.cs +++ b/SAV/SAV_PokedexORAS.cs @@ -1,11 +1,5 @@ using System; using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace PKHeX @@ -35,12 +29,8 @@ namespace PKHeX private void Setup() { // Clear Listbox and ComboBox - try - { - LB_Species.Items.Clear(); - CB_Species.Items.Clear(); - } - catch { } + LB_Species.Items.Clear(); + CB_Species.Items.Clear(); // Fill List #region Species @@ -63,7 +53,6 @@ namespace PKHeX int offset = dexoffset + 0x8 + 0x60 * i; Array.Copy(sav, offset, data, 0, 0x60); BitArray BitRegion = new BitArray(data); - bool fuck = BitRegion[767]; for (int b = 0; b < (0x60 * 8); b++) specbools[i, b] = BitRegion[b]; } @@ -83,38 +72,38 @@ namespace PKHeX editing = true; int index = (int)CB_Species.SelectedValue; LB_Species.SelectedIndex = index - 1; // Since we don't allow index0 in combobox, everything is shifted by 1 - LB_Species.TopIndex = (int)(LB_Species.SelectedIndex); + LB_Species.TopIndex = LB_Species.SelectedIndex; loadchks(); editing = false; } } private void changeLBSpecies(object sender, EventArgs e) { - if (!editing) + if (editing) return; + editing = true; + try { - editing = true; - try - { - int index = LB_Species.SelectedIndex + 1; - CB_Species.SelectedValue = index; - } - catch { }; - loadchks(); - editing = false; + int index = LB_Species.SelectedIndex + 1; + CB_Species.SelectedValue = index; } + catch { } + loadchks(); + editing = false; } private void loadchks() { // Load Bools for the data - int pk = 0; + int pk; try { pk = Util.getIndex(CB_Species); } - catch { pk = (int)LB_Species.SelectedIndex + 1; } + catch { pk = LB_Species.SelectedIndex + 1; } - CheckBox[] CP = new CheckBox[] { + CheckBox[] CP = + { CHK_P1,CHK_P2,CHK_P3,CHK_P4,CHK_P5,CHK_P6,CHK_P7,CHK_P8,CHK_P9, }; - CheckBox[] CL = new CheckBox[] { + CheckBox[] CL = + { CHK_L1,CHK_L2,CHK_L3,CHK_L4,CHK_L5,CHK_L6,CHK_L7, }; // Load Partitions @@ -172,7 +161,7 @@ namespace PKHeX private void B_Cancel_Click(object sender, EventArgs e) { - this.Close(); + Close(); } private void B_Save_Click(object sender, EventArgs e) { @@ -180,7 +169,7 @@ namespace PKHeX // Return back to the parent savefile Array.Copy(sav, m_parent.savefile, sav.Length); - this.Close(); + Close(); } private void saveChanges() { @@ -234,19 +223,19 @@ namespace PKHeX CHK_L4.Checked = CHK_L5.Checked = CHK_L6.Checked = - CHK_L7.Checked = !(ModifierKeys == Keys.Control); + CHK_L7.Checked = ModifierKeys != Keys.Control; } if (CHK_P1.Enabled) { - CHK_P1.Checked = !(ModifierKeys == Keys.Control); + CHK_P1.Checked = ModifierKeys != Keys.Control; } int index = LB_Species.SelectedIndex+1; PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(index); int gt = MonData.GenderRatio; - CHK_P2.Checked = CHK_P4.Checked = CHK_P6.Checked = CHK_P8.Checked = ((gt != 254)) && !(ModifierKeys == Keys.Control); - CHK_P3.Checked = CHK_P5.Checked = CHK_P7.Checked = CHK_P9.Checked = (gt != 0) && (gt != 255) && !(ModifierKeys == Keys.Control); + CHK_P2.Checked = CHK_P4.Checked = CHK_P6.Checked = CHK_P8.Checked = ((gt != 254)) && ModifierKeys != Keys.Control; + CHK_P3.Checked = CHK_P5.Checked = CHK_P7.Checked = CHK_P9.Checked = (gt != 0) && (gt != 255) && ModifierKeys != Keys.Control; changePartitionBool(null, null); changeLanguageBool(null, null); @@ -266,207 +255,208 @@ namespace PKHeX { // starting at 0x15068; #region Payload - uint[] payload = new uint[] { - 0x8FFFFFFF, // 20015068 - 0xFFFFFFFF, // 2001506C - 0xFFFFFFFF, // 20015070 - 0xF7FAFFFF, // 20015074 - 0xFFFFFFFF, // 20015078 - 0xFFFFFFFF, // 2001507C - 0xFFFFFFFF, // 20015080 - 0xFFFCDFFF, // 20015084 - 0xFFFFFFFF, // 20015088 - 0xFDFFFFFF, // 2001508C - 0xFFFFFFFF, // 20015090 - 0xF7FFFFFF, // 20015094 - 0x6FFFFFFF, // 20015098 - 0xFF7FFFFF, // 2001509C - 0xDFFFFFFF, // 200150A0 - 0xFFFFFF7F, // 200150A4 - 0xFFFFFFFF, // 200150A8 - 0xFFFFFFE7, // 200150AC - 0xFFFFFFFF, // 200150B0 - 0xFFCFFFFF, // 200150B4 - 0x8FFFFFFF, // 200150B8 - 0xFFFFFFFF, // 200150BC - 0x0001FFFF, // 200150C0 - 0x00000000, // + uint[] payload = + { + 0x8FFFFFFF, // 20015068 + 0xFFFFFFFF, // 2001506C + 0xFFFFFFFF, // 20015070 + 0xF7FAFFFF, // 20015074 + 0xFFFFFFFF, // 20015078 + 0xFFFFFFFF, // 2001507C + 0xFFFFFFFF, // 20015080 + 0xFFFCDFFF, // 20015084 + 0xFFFFFFFF, // 20015088 + 0xFDFFFFFF, // 2001508C + 0xFFFFFFFF, // 20015090 + 0xF7FFFFFF, // 20015094 + 0x6FFFFFFF, // 20015098 + 0xFF7FFFFF, // 2001509C + 0xDFFFFFFF, // 200150A0 + 0xFFFFFF7F, // 200150A4 + 0xFFFFFFFF, // 200150A8 + 0xFFFFFFE7, // 200150AC + 0xFFFFFFFF, // 200150B0 + 0xFFCFFFFF, // 200150B4 + 0x8FFFFFFF, // 200150B8 + 0xFFFFFFFF, // 200150BC + 0x0001FFFF, // 200150C0 + 0x00000000, // - 0x7FFFFFFF, // 200150C8 - 0xFFFFFFFC, // 200150CC - 0xFFFCFFFF, // 200150D0 - 0x7E7FF9E7, // 200150D4 - 0xFF9C7EF7, // 200150D8 - 0xFFFFFFFF, // 200150DC - 0xFFFFFEFF, // 200150E0 - 0xF8E3E6FF, // 200150E4 - 0xFFFFFFFF, // 200150E8 - 0xFEFFFFF7, // 200150EC - 0xFF3CFFFF, // 200150F0 - 0x081FFFFF, // 200150F4 - 0xDFFFFFFC, // 200150F8 - 0xFFE7FFFF, // 200150FC - 0x39FFDFFF, // 20015100 - 0xFFFFC090, // 20015104 - 0xF9FFFFFF, // 20015108 - 0xFFFFFFFF, // 2001510C - 0xFE3FFFFF, // 20015110 - 0x1FF39FBF, // 20015114 - 0xFFFFFE00, // 20015118 - 0xBFFFFFFF, // 2001511C - 0x000007FF, // 10015120 - 0x00000000, // + 0x7FFFFFFF, // 200150C8 + 0xFFFFFFFC, // 200150CC + 0xFFFCFFFF, // 200150D0 + 0x7E7FF9E7, // 200150D4 + 0xFF9C7EF7, // 200150D8 + 0xFFFFFFFF, // 200150DC + 0xFFFFFEFF, // 200150E0 + 0xF8E3E6FF, // 200150E4 + 0xFFFFFFFF, // 200150E8 + 0xFEFFFFF7, // 200150EC + 0xFF3CFFFF, // 200150F0 + 0x081FFFFF, // 200150F4 + 0xDFFFFFFC, // 200150F8 + 0xFFE7FFFF, // 200150FC + 0x39FFDFFF, // 20015100 + 0xFFFFC090, // 20015104 + 0xF9FFFFFF, // 20015108 + 0xFFFFFFFF, // 2001510C + 0xFE3FFFFF, // 20015110 + 0x1FF39FBF, // 20015114 + 0xFFFFFE00, // 20015118 + 0xBFFFFFFF, // 2001511C + 0x000007FF, // 10015120 + 0x00000000, // - 0x8FFFFFFF, // 20015128 - 0xFFFFFFFF, // 2001512C - 0xFFFFFFFF, // 20015130 - 0xF7FAFFFF, // 20015134 - 0xFFFFFFFF, // 20015138 - 0xFFFFFFFF, // 2001513C - 0xFFFFFFFF, // 20015140 - 0xFFFCDFFF, // 20015144 - 0xFFFFFFFF, // 20015148 - 0xFDFFFFFF, // 2001514C - 0xFFFFFFFF, // 20015150 - 0xF7FFFFFF, // 20015154 - 0x6FFFFFFF, // 20015158 - 0xFF7FFFFF, // 2001515C - 0xDFFFFFFF, // 20015160 - 0xFFFFFF7F, // 20015164 - 0xFFFFFFFF, // 20015168 - 0xFFFFFFE7, // 2001516C - 0xFFFFFFFF, // 20015170 - 0xFFCFFFFF, // 20015174 - 0x8FFFFFFF, // 20015178 - 0xFFFFFFFF, // 2001517C - 0x0001FFFF, // 20015180 - 0x00000000, // + 0x8FFFFFFF, // 20015128 + 0xFFFFFFFF, // 2001512C + 0xFFFFFFFF, // 20015130 + 0xF7FAFFFF, // 20015134 + 0xFFFFFFFF, // 20015138 + 0xFFFFFFFF, // 2001513C + 0xFFFFFFFF, // 20015140 + 0xFFFCDFFF, // 20015144 + 0xFFFFFFFF, // 20015148 + 0xFDFFFFFF, // 2001514C + 0xFFFFFFFF, // 20015150 + 0xF7FFFFFF, // 20015154 + 0x6FFFFFFF, // 20015158 + 0xFF7FFFFF, // 2001515C + 0xDFFFFFFF, // 20015160 + 0xFFFFFF7F, // 20015164 + 0xFFFFFFFF, // 20015168 + 0xFFFFFFE7, // 2001516C + 0xFFFFFFFF, // 20015170 + 0xFFCFFFFF, // 20015174 + 0x8FFFFFFF, // 20015178 + 0xFFFFFFFF, // 2001517C + 0x0001FFFF, // 20015180 + 0x00000000, // - 0x7FFFFFFF, // 20015188 - 0xFFFFFFFC, // 2001518C - 0xFFFCFFFF, // 20015190 - 0x7E7FF9E7, // 20015194 - 0xFF9C7EF7, // 20015198 - 0xFFFFFFFF, // 2001519C - 0xFFFFFEFF, // 200151A0 - 0xF8E3E6FF, // 200151A4 - 0xFFFFFFFF, // 200151A8 - 0xFEFFFFF7, // 200151AC - 0xFF3CFFFF, // 200151B0 - 0x081FFFFF, // 200151B4 - 0xDFFFFFFC, // 200151B8 - 0xFFE7FFFF, // 200151BC - 0x39FFDFFF, // 200151C0 - 0xFFFFC090, // 200151C4 - 0xF9FFFFFF, // 200151C8 - 0xFFFFFFFF, // 200151CC - 0xFE3FFFFF, // 200151D0 - 0x1FF39FBF, // 200151D4 - 0xFFFFFE00, // 200151D8 - 0xBFFFFFFF, // 200151DC - 0x000007FF, // 100151E0 - 0x00000000, // + 0x7FFFFFFF, // 20015188 + 0xFFFFFFFC, // 2001518C + 0xFFFCFFFF, // 20015190 + 0x7E7FF9E7, // 20015194 + 0xFF9C7EF7, // 20015198 + 0xFFFFFFFF, // 2001519C + 0xFFFFFEFF, // 200151A0 + 0xF8E3E6FF, // 200151A4 + 0xFFFFFFFF, // 200151A8 + 0xFEFFFFF7, // 200151AC + 0xFF3CFFFF, // 200151B0 + 0x081FFFFF, // 200151B4 + 0xDFFFFFFC, // 200151B8 + 0xFFE7FFFF, // 200151BC + 0x39FFDFFF, // 200151C0 + 0xFFFFC090, // 200151C4 + 0xF9FFFFFF, // 200151C8 + 0xFFFFFFFF, // 200151CC + 0xFE3FFFFF, // 200151D0 + 0x1FF39FBF, // 200151D4 + 0xFFFFFE00, // 200151D8 + 0xBFFFFFFF, // 200151DC + 0x000007FF, // 100151E0 + 0x00000000, // - 0x8FFFFFFF, // 200151E8 - 0xFFFFFFFF, // 200151EC - 0xFFFFFFFF, // 200151F0 - 0xF7FAFFFF, // 200151F4 - 0xFFFFFFFF, // 200151F8 - 0xFFFFFFFF, // 200151FC - 0xFFFFFFFF, // 20015200 - 0xFFFCDFFF, // 20015204 - 0xFFFFFFFF, // 20015208 - 0xFDFFFFFF, // 2001520C - 0xFFFFFFFF, // 20015210 - 0xF7FFFFFF, // 20015214 - 0x6FFFFFFF, // 20015218 - 0xFF7FFFFF, // 2001521C - 0xDFFFFFFF, // 20015220 - 0xFFFFFF7F, // 20015224 - 0xFFFFFFFF, // 20015228 - 0xFFFFFFE7, // 2001522C - 0xFFFFFFFF, // 20015230 - 0xFFCFFFFF, // 20015234 - 0x8FFFFFFF, // 20015238 - 0xFFFFFFFF, // 2001523C - 0x0001FFFF, // 20015240 - 0x00000000, // + 0x8FFFFFFF, // 200151E8 + 0xFFFFFFFF, // 200151EC + 0xFFFFFFFF, // 200151F0 + 0xF7FAFFFF, // 200151F4 + 0xFFFFFFFF, // 200151F8 + 0xFFFFFFFF, // 200151FC + 0xFFFFFFFF, // 20015200 + 0xFFFCDFFF, // 20015204 + 0xFFFFFFFF, // 20015208 + 0xFDFFFFFF, // 2001520C + 0xFFFFFFFF, // 20015210 + 0xF7FFFFFF, // 20015214 + 0x6FFFFFFF, // 20015218 + 0xFF7FFFFF, // 2001521C + 0xDFFFFFFF, // 20015220 + 0xFFFFFF7F, // 20015224 + 0xFFFFFFFF, // 20015228 + 0xFFFFFFE7, // 2001522C + 0xFFFFFFFF, // 20015230 + 0xFFCFFFFF, // 20015234 + 0x8FFFFFFF, // 20015238 + 0xFFFFFFFF, // 2001523C + 0x0001FFFF, // 20015240 + 0x00000000, // - 0x7FFFFFFF, // 20015248 - 0xFFFFFFFC, // 2001524C - 0xFFFCFFFF, // 20015250 - 0x7E7FF9E7, // 20015254 - 0xFF9C7EF7, // 20015258 - 0xFFFFFFFF, // 2001525C - 0xFFFFFEFF, // 20015260 - 0xF8E3E6FF, // 20015264 - 0xFFFFFFFF, // 20015268 - 0xFEFFFFF7, // 2001526C - 0xFF3CFFFF, // 20015270 - 0x081FFFFF, // 20015274 - 0xDFFFFFFC, // 20015278 - 0xFFE7FFFF, // 2001527C - 0x39FFDFFF, // 20015280 - 0xFFFFC090, // 20015284 - 0xF9FFFFFF, // 20015288 - 0xFFFFFFFF, // 2001528C - 0xFE3FFFFF, // 20015290 - 0x1FF39FBF, // 20015294 - 0xFFFFFE00, // 20015298 - 0xBFFFFFFF, // 2001529C - 0x000007FF, // 100152A0 - 0x00000000, // + 0x7FFFFFFF, // 20015248 + 0xFFFFFFFC, // 2001524C + 0xFFFCFFFF, // 20015250 + 0x7E7FF9E7, // 20015254 + 0xFF9C7EF7, // 20015258 + 0xFFFFFFFF, // 2001525C + 0xFFFFFEFF, // 20015260 + 0xF8E3E6FF, // 20015264 + 0xFFFFFFFF, // 20015268 + 0xFEFFFFF7, // 2001526C + 0xFF3CFFFF, // 20015270 + 0x081FFFFF, // 20015274 + 0xDFFFFFFC, // 20015278 + 0xFFE7FFFF, // 2001527C + 0x39FFDFFF, // 20015280 + 0xFFFFC090, // 20015284 + 0xF9FFFFFF, // 20015288 + 0xFFFFFFFF, // 2001528C + 0xFE3FFFFF, // 20015290 + 0x1FF39FBF, // 20015294 + 0xFFFFFE00, // 20015298 + 0xBFFFFFFF, // 2001529C + 0x000007FF, // 100152A0 + 0x00000000, // - 0x8FFFFFFF, // 200152A8 - 0xFFFFFFFF, // 200152AC - 0xFFFFFFFF, // 200152B0 - 0xF7FAFFFF, // 200152B4 - 0xFFFFFFFF, // 200152B8 - 0xFFFFFFFF, // 200152BC - 0xFFFFFFFF, // 200152C0 - 0xFFFCDFFF, // 200152C4 - 0xFFFFFFFF, // 200152C8 - 0xFDFFFFFF, // 200152CC - 0xFFFFFFFF, // 200152D0 - 0xF7FFFFFF, // 200152D4 - 0x6FFFFFFF, // 200152D8 - 0xFF7FFFFF, // 200152DC - 0xDFFFFFFF, // 200152E0 - 0xFFFFFF7F, // 200152E4 - 0xFFFFFFFF, // 200152E8 - 0xFFFFFFE7, // 200152EC - 0xFFFFFFFF, // 200152F0 - 0xFFCFFFFF, // 200152F4 - 0x8FFFFFFF, // 200152F8 - 0xFFFFFFFF, // 200152FC - 0x0001FFFF, // 20015300 - 0x00000000, // + 0x8FFFFFFF, // 200152A8 + 0xFFFFFFFF, // 200152AC + 0xFFFFFFFF, // 200152B0 + 0xF7FAFFFF, // 200152B4 + 0xFFFFFFFF, // 200152B8 + 0xFFFFFFFF, // 200152BC + 0xFFFFFFFF, // 200152C0 + 0xFFFCDFFF, // 200152C4 + 0xFFFFFFFF, // 200152C8 + 0xFDFFFFFF, // 200152CC + 0xFFFFFFFF, // 200152D0 + 0xF7FFFFFF, // 200152D4 + 0x6FFFFFFF, // 200152D8 + 0xFF7FFFFF, // 200152DC + 0xDFFFFFFF, // 200152E0 + 0xFFFFFF7F, // 200152E4 + 0xFFFFFFFF, // 200152E8 + 0xFFFFFFE7, // 200152EC + 0xFFFFFFFF, // 200152F0 + 0xFFCFFFFF, // 200152F4 + 0x8FFFFFFF, // 200152F8 + 0xFFFFFFFF, // 200152FC + 0x0001FFFF, // 20015300 + 0x00000000, // - 0x7FFFFFFF, // 20015308 - 0xFFFFFFFC, // 2001530C - 0xFFFCFFFF, // 20015310 - 0x7E7FF9E7, // 20015314 - 0xFF9C7EF7, // 20015318 - 0xFFFFFFFF, // 2001531C - 0xFFFFFEFF, // 20015320 - 0xF8E3E6FF, // 20015324 - 0xFFFFFFFF, // 20015328 - 0xFEFFFFF7, // 2001532C - 0xFF3CFFFF, // 20015330 - 0x081FFFFF, // 20015334 - 0xDFFFFFFC, // 20015338 - 0xFFE7FFFF, // 2001533C - 0x39FFDFFF, // 20015340 - 0xFFFFC090, // 20015344 - 0xF9FFFFFF, // 20015348 - 0xFFFFFFFF, // 2001534C - 0xFE3FFFFF, // 20015350 - 0x1FF39FBF, // 20015354 - 0xFFFFFE00, // 20015358 - 0xBFFFFFFF, // 2001535C - 0x000007FF, // 10015360 - 0x00000000, // - }; + 0x7FFFFFFF, // 20015308 + 0xFFFFFFFC, // 2001530C + 0xFFFCFFFF, // 20015310 + 0x7E7FF9E7, // 20015314 + 0xFF9C7EF7, // 20015318 + 0xFFFFFFFF, // 2001531C + 0xFFFFFEFF, // 20015320 + 0xF8E3E6FF, // 20015324 + 0xFFFFFFFF, // 20015328 + 0xFEFFFFF7, // 2001532C + 0xFF3CFFFF, // 20015330 + 0x081FFFFF, // 20015334 + 0xDFFFFFFC, // 20015338 + 0xFFE7FFFF, // 2001533C + 0x39FFDFFF, // 20015340 + 0xFFFFC090, // 20015344 + 0xF9FFFFFF, // 20015348 + 0xFFFFFFFF, // 2001534C + 0xFE3FFFFF, // 20015350 + 0x1FF39FBF, // 20015354 + 0xFFFFFE00, // 20015358 + 0xBFFFFFFF, // 2001535C + 0x000007FF, // 10015360 + 0x00000000, // + }; #endregion for (int i = 0; i < payload.Length; i++) Array.Copy(BitConverter.GetBytes(payload[i]), 0, sav, sv + 0x5400 + 0x15068 + 4 * i, 4); diff --git a/SAV/SAV_PokedexXY.cs b/SAV/SAV_PokedexXY.cs index fcf06b544..f3ed9ca37 100644 --- a/SAV/SAV_PokedexXY.cs +++ b/SAV/SAV_PokedexXY.cs @@ -1,11 +1,5 @@ using System; using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace PKHeX @@ -26,7 +20,7 @@ namespace PKHeX } Form1 m_parent; public byte[] sav = new byte[0x100000]; - public int savshift = 0; + public int savshift; public bool[,] specbools = new bool[10, 0x60 * 8]; public bool[,] langbools = new bool[7, 0x60 * 8]; public bool[] foreignbools = new bool[0x52 * 8]; @@ -34,12 +28,8 @@ namespace PKHeX private void Setup() { // Clear Listbox and ComboBox - try - { - LB_Species.Items.Clear(); - CB_Species.Items.Clear(); - } - catch { } + LB_Species.Items.Clear(); + CB_Species.Items.Clear(); // Fill List #region Species @@ -93,7 +83,7 @@ namespace PKHeX editing = true; int index = (int)CB_Species.SelectedValue; LB_Species.SelectedIndex = index - 1; // Since we don't allow index0 in combobox, everything is shifted by 1 - LB_Species.TopIndex = (int)(LB_Species.SelectedIndex); + LB_Species.TopIndex = LB_Species.SelectedIndex; loadchks(); editing = false; } @@ -116,17 +106,19 @@ namespace PKHeX private void loadchks() { // Load Bools for the data - int pk = 0; + int pk; try { pk = Util.getIndex(CB_Species); } - catch { pk = (int)LB_Species.SelectedIndex + 1; } + catch { pk = LB_Species.SelectedIndex + 1; } - CheckBox[] CP = new CheckBox[] { + CheckBox[] CP = + { CHK_P1,CHK_P2,CHK_P3,CHK_P4,CHK_P5,CHK_P6,CHK_P7,CHK_P8,CHK_P9,CHK_P10, }; - CheckBox[] CL = new CheckBox[] { + CheckBox[] CL = + { CHK_L1,CHK_L2,CHK_L3,CHK_L4,CHK_L5,CHK_L6,CHK_L7, }; // Load Partitions @@ -201,7 +193,7 @@ namespace PKHeX private void B_Cancel_Click(object sender, EventArgs e) { - this.Close(); + Close(); } private void B_Save_Click(object sender, EventArgs e) { @@ -209,7 +201,7 @@ namespace PKHeX // Return back to the parent savefile Array.Copy(sav, m_parent.savefile, sav.Length); - this.Close(); + Close(); } private void saveChanges() { @@ -272,23 +264,23 @@ namespace PKHeX CHK_L4.Checked = CHK_L5.Checked = CHK_L6.Checked = - CHK_L7.Checked = !(ModifierKeys == Keys.Control); + CHK_L7.Checked = ModifierKeys != Keys.Control; } if (CHK_P1.Enabled) { CHK_P1.Checked = - CHK_P10.Checked = !(ModifierKeys == Keys.Control); + CHK_P10.Checked = ModifierKeys != Keys.Control; } if (CHK_F1.Enabled) { - CHK_F1.Checked = !(ModifierKeys == Keys.Control); + CHK_F1.Checked = ModifierKeys != Keys.Control; } int index = LB_Species.SelectedIndex+1; PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(index); int gt = MonData.GenderRatio; - CHK_P2.Checked = CHK_P4.Checked = CHK_P6.Checked = CHK_P8.Checked = ((gt != 254)) && !(ModifierKeys == Keys.Control); - CHK_P3.Checked = CHK_P5.Checked = CHK_P7.Checked = CHK_P9.Checked = (gt != 0) && (gt != 255) && !(ModifierKeys == Keys.Control); + CHK_P2.Checked = CHK_P4.Checked = CHK_P6.Checked = CHK_P8.Checked = ((gt != 254)) && ModifierKeys != Keys.Control; + CHK_P3.Checked = CHK_P5.Checked = CHK_P7.Checked = CHK_P9.Checked = (gt != 0) && (gt != 255) && ModifierKeys != Keys.Control; changePartitionBool(null, null); changeLanguageBool(null, null); diff --git a/SAV/SAV_Pokepuff.cs b/SAV/SAV_Pokepuff.cs index 329c74781..dc1f07d2b 100644 --- a/SAV/SAV_Pokepuff.cs +++ b/SAV/SAV_Pokepuff.cs @@ -1,10 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace PKHeX @@ -22,8 +16,8 @@ namespace PKHeX pfa[0] = "---"; Setup(); - new ToolTip().SetToolTip(this.B_Sort, "Hold CTRL to reverse sort."); - new ToolTip().SetToolTip(this.B_All, "Hold CTRL to give Deluxe instead of Supreme."); + new ToolTip().SetToolTip(B_Sort, "Hold CTRL to reverse sort."); + new ToolTip().SetToolTip(B_All, "Hold CTRL to give Deluxe instead of Supreme."); } Form1 m_parent; public byte[] sav = new byte[0x100000]; @@ -51,13 +45,14 @@ namespace PKHeX dgvIndex.ReadOnly = true; dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; } - DataGridViewComboBoxColumn dgvPuff = new DataGridViewComboBoxColumn(); - dgvPuff.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; + DataGridViewComboBoxColumn dgvPuff = new DataGridViewComboBoxColumn { - for (int i = 0; i < pfa.Length; i++) - { - dgvPuff.Items.Add(pfa[i]); - } + DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing + }; + { + foreach (string t in pfa) + dgvPuff.Items.Add(t); + dgvPuff.DisplayIndex = 1; dgvPuff.Width = 135; dgvPuff.FlatStyle = FlatStyle.Flat; @@ -133,11 +128,9 @@ namespace PKHeX { string puff = dataGridView1.Rows[i].Cells[1].Value.ToString(); byte puffval = (byte)Array.IndexOf(pfa, puff); - if (puffval != 0) - { - puffarray[count] = puffval; - count++; - } + if (puffval == 0) continue; + puffarray[count] = puffval; + count++; } Array.Resize(ref puffarray, count); Array.Sort(puffarray); diff --git a/SAV/SAV_SecretBase.cs b/SAV/SAV_SecretBase.cs index aac987cd2..d7a4a9e7f 100644 --- a/SAV/SAV_SecretBase.cs +++ b/SAV/SAV_SecretBase.cs @@ -1,12 +1,6 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; using System.Text; using System.Windows.Forms; -using System.IO; namespace PKHeX { @@ -18,13 +12,7 @@ namespace PKHeX Util.TranslateInterface(this, Form1.curlanguage); m_parent = frm1; Array.Copy(m_parent.savefile, sav, 0x100000); - savindex = m_parent.savindex; - - specieslist = Form1.specieslist; - movelist = Form1.movelist; - itemlist = Form1.itemlist; abilitylist = Form1.abilitylist; - natures = Form1.natures; setupComboBoxes(); popFavorite(); @@ -38,16 +26,12 @@ namespace PKHeX Form1 m_parent; public byte[] sav = new byte[0x100000]; public byte[] wondercard_data = new byte[0x108]; - public bool editing = false; - public int savindex; int sv = 0; - private int fav_offset = 0x23A00; + public bool editing; + private const int sv = 0; + private const int fav_offset = 0x23A00; private bool loading = true; - public static string[] specieslist = { }; - public static string[] movelist = { }; - public static string[] itemlist = { }; public static string[] abilitylist = { }; - public static string[] natures = { }; private void setupComboBoxes() { @@ -89,8 +73,8 @@ namespace PKHeX { LB_Favorite.Items.Clear(); - int playeroff = fav_offset + 0x5400 + 0x326; - int favoff = fav_offset + 0x5400 + 0x63A; + const int playeroff = fav_offset + 0x5400 + 0x326; + const int favoff = fav_offset + 0x5400 + 0x63A; string OT = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + playeroff + 0x218, 0x1A)); LB_Favorite.Items.Add("* " + OT); for (int i = 0; i < 30; i++) @@ -233,13 +217,13 @@ namespace PKHeX } private void B_GiveDecor_Click(object sender, EventArgs e) { - int offset = sv + 0x23A00 + 0x5400; + const int offset = sv + 0x23A00 + 0x5400; for (int i = 0; i < 173; i++) { // int qty = BitConverter.ToUInt16(sav, offset + i * 4); // int has = BitConverter.ToUInt16(sav, offset + i * 4 + 2); - sav[offset + i * 4] = (byte)25; + sav[offset + i * 4] = 25; sav[offset + i * 4 + 2] = 1; } } @@ -256,8 +240,8 @@ namespace PKHeX byte x = objinfo[2]; byte y = objinfo[4]; byte rot = objinfo[6]; - byte unk1 = objinfo[7]; - ushort unk2 = BitConverter.ToUInt16(objinfo, 0x8); + // byte unk1 = objinfo[7]; + // ushort unk2 = BitConverter.ToUInt16(objinfo, 0x8); // Set values to display editing = true; @@ -353,10 +337,10 @@ namespace PKHeX fpkm[i] = pkmdata[index, i]; uint ec = BitConverter.ToUInt32(fpkm, 0); - uint unk = BitConverter.ToUInt32(fpkm, 4); + // uint unk = BitConverter.ToUInt32(fpkm, 4); int spec = BitConverter.ToInt16(fpkm, 8); int item = BitConverter.ToInt16(fpkm, 0xA); - int abil = fpkm[0xC]; + // int abil = fpkm[0xC]; int abil_no = fpkm[0xD]; MT_AbilNo.Text = abil_no.ToString(); // 6 unknown bytes, contest? @@ -444,15 +428,12 @@ namespace PKHeX private void updateSpecies(object sender, EventArgs e) { - int species = Util.getIndex(CB_Species); - // Get Forms for Given Species - m_parent.setForms(species, CB_Form); + m_parent.setForms(Util.getIndex(CB_Species), CB_Form); // Check for Gender Changes // Get Gender Threshold - species = Util.getIndex(CB_Species); - PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(species); + PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(Util.getIndex(CB_Species)); int gt = MonData.GenderRatio; if (gt == 255) // Genderless @@ -474,12 +455,11 @@ namespace PKHeX Label_Gender.Text = Form1.gendersymbols[CB_Form.SelectedIndex]; } - private int species; private int genderflag; + private int genderflag; private void Label_Gender_Click(object sender, EventArgs e) { // Get Gender Threshold - species = Util.getIndex(CB_Species); - PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(species); + PKX.PersonalParser.Personal MonData = PKX.PersonalGetter.GetPersonal(Util.getIndex(CB_Species)); int gt = MonData.GenderRatio; if (gt == 255 || gt == 0 || gt == 254) // Single gender/genderless @@ -497,23 +477,23 @@ namespace PKHeX { if (LB_Favorite.SelectedIndex < 1) { Util.Alert("Cannot delete your Secret Base."); return; } int index = LB_Favorite.SelectedIndex - 1; - - int playeroff = fav_offset + 0x5400 + 0x326; - int favoff = fav_offset + 0x5400 + 0x63A; - string OT = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + playeroff + 0x218, 0x1A)); + + const int favoff = fav_offset + 0x5400 + 0x63A; string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + favoff + index * 0x3E0 + 0x218, 0x1A)); if (BaseTrainer.Length < 1 || BaseTrainer[0] == '\0') BaseTrainer = "Empty"; - if (Util.Prompt(MessageBoxButtons.YesNo, String.Format("Delete {1}'s base (Entry {0}) from your records?", index, BaseTrainer)) == DialogResult.Yes) - { - int max = 29; int size = 0x3E0; - int offset = sv + favoff + index * size; - if (index != max) Array.Copy(sav, offset + size, sav, offset, size * (max - index)); - // Ensure Last Entry is Cleared - Array.Copy(new byte[size], 0, sav, size * max, size); - popFavorite(); - } + if ( + Util.Prompt(MessageBoxButtons.YesNo, + String.Format("Delete {1}'s base (Entry {0}) from your records?", index, BaseTrainer)) != DialogResult.Yes) + return; + const int max = 29; + const int size = 0x3E0; + int offset = sv + favoff + index * size; + if (index != max) Array.Copy(sav, offset + size, sav, offset, size * (max - index)); + // Ensure Last Entry is Cleared + Array.Copy(new byte[size], 0, sav, size * max, size); + popFavorite(); } } } diff --git a/SAV/SAV_SuperTrain.cs b/SAV/SAV_SuperTrain.cs index 43ea5042a..3347bc0ff 100644 --- a/SAV/SAV_SuperTrain.cs +++ b/SAV/SAV_SuperTrain.cs @@ -1,10 +1,4 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace PKHeX @@ -15,7 +9,6 @@ namespace PKHeX { m_parent = frm1; savindex = m_parent.savindex; - specieslist = Form1.specieslist; Array.Copy(m_parent.savefile, sav, 0x100000); if (m_parent.savegame_oras) data_offset = 0x25600; trba = Form1.trainingbags; @@ -34,7 +27,6 @@ namespace PKHeX } Form1 m_parent; public byte[] sav = new byte[0x100000]; - public string[] specieslist; public int savindex; private int data_offset = 0x24600; private string[] trba = { @@ -49,9 +41,9 @@ namespace PKHeX "Big-Shot Bag","Double-Up Bag","Team Flare Bag", "Reset Bag","Soothing Bag", }; - private int offsetVal = 0; - private int offsetTime = 0; - private int offsetSpec = 0; + private int offsetVal; + private int offsetTime; + private int offsetSpec; private void setup() { dataGridView1.Rows.Clear(); @@ -82,12 +74,14 @@ namespace PKHeX dgvIndex.ReadOnly = true; dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; } - DataGridViewComboBoxColumn dgvBag = new DataGridViewComboBoxColumn(); - dgvBag.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing; + DataGridViewComboBoxColumn dgvBag = new DataGridViewComboBoxColumn { - for (int i = 0; i < trba.Length; i++) - if (trba[i].Length > 0) - dgvBag.Items.Add(trba[i]); + DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing + }; + { + foreach (string t in trba) + if (t.Length > 0) + dgvBag.Items.Add(t); dgvBag.DisplayIndex = 1; dgvBag.Width = 135; @@ -108,13 +102,11 @@ namespace PKHeX { try { - if (e.ColumnIndex == 1) - { - ComboBox comboBox = (ComboBox)dataGridView1.EditingControl; - comboBox.DroppedDown = true; - } + if (e.ColumnIndex != 1) return; + ComboBox comboBox = (ComboBox)dataGridView1.EditingControl; + comboBox.DroppedDown = true; } - catch { return; } + catch { } } private void changeListRecordSelection(object sender, EventArgs e) { @@ -167,7 +159,7 @@ namespace PKHeX } private void B_Cancel_Click(object sender, EventArgs e) { - this.Close(); + Close(); } private void changeRecordSpecies(object sender, EventArgs e) { diff --git a/SAV/SAV_Trainer.cs b/SAV/SAV_Trainer.cs index 3e7b025e9..e0bb8fcff 100644 --- a/SAV/SAV_Trainer.cs +++ b/SAV/SAV_Trainer.cs @@ -1,20 +1,16 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; -using System.Drawing.Imaging; namespace PKHeX { public partial class SAV_Trainer : Form { - private int TrainerCard = 0x19400; - private int Trainer1 = 0x6800; - private int Trainer2 = 0x9600; + private const int TrainerCard = 0x19400; + private const int Trainer1 = 0x6800; + private const int Trainer2 = 0x9600; private int Maison = 0x205C0; private int VivillonForm = 0x9650; public SAV_Trainer(Form1 frm1) @@ -32,7 +28,7 @@ namespace PKHeX if (m_parent.savegame_oras) { psssatoffset = 0x24800; Maison += 0xA00; VivillonForm = 0x9644; - this.Width = (int)((float)Width * (float)428 / (float)590); + Width = (int)((float)Width * 428 / 590); CB_Multi.Enabled = true; L_MultiplayerSprite.Enabled = true; // Multiplayer Sprite Label @@ -46,7 +42,7 @@ namespace PKHeX getBadges(); GB_Map.Enabled = !Form1.ramsavloaded; - statdata = new string[] { + statdata = new[] { "0x000", "0x000", // Steps taken? "0x004", "0x004", // Minutes Played / Pokemon Encountered? "0x008", "0x008", @@ -205,13 +201,13 @@ namespace PKHeX CB_Stats.Items.Add(statdata[2 * i + 1]); CB_Stats.SelectedIndex = 0; } - private string[] statdata = new string[] { }; + private string[] statdata = { }; Form1 m_parent; public byte[] sav = new byte[0x100000]; public int savshift; public int savindex; - public bool editing = false; - public byte badgeval = 0; + public bool editing; + public byte badgeval; public ToolTip Tip1 = new ToolTip(); public ToolTip Tip2 = new ToolTip(); @@ -348,7 +344,7 @@ namespace PKHeX }; if (m_parent.savegame_oras) { - bma = new Bitmap[] { + bma = new[] { Properties.Resources.badge_01, // ORAS Badges Properties.Resources.badge_02, Properties.Resources.badge_03, @@ -364,22 +360,19 @@ namespace PKHeX for (int i = 0; i < 8; i++) { - if (!cba[i].Checked) - pba[i].Image = Util.ChangeOpacity(bma[i], 0.1); - else - pba[i].Image = Util.ChangeOpacity(bma[i], 1); + pba[i].Image = Util.ChangeOpacity(bma[i], !cba[i].Checked ? 0.1 : 1); } } private void getTextBoxes() { - byte badgeval = sav[Trainer2 + 0xC + savindex * 0x7F000]; + badgeval = sav[Trainer2 + 0xC + savindex * 0x7F000]; CheckBox[] cba = { cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, }; for (int i = 0; i < 8; i++) - cba[i].Checked = !((badgeval & (1 << i)) == 0); + cba[i].Checked = (badgeval & (1 << i)) != 0; // Get Data string OT_NAME = Encoding.Unicode.GetString(sav, TrainerCard + 0x48 + savshift, 0x1A); - string RIV_NAME = Encoding.Unicode.GetString(sav, Trainer2 + 0x10 + savshift, 0x1A); + // string RIV_NAME = Encoding.Unicode.GetString(sav, Trainer2 + 0x10 + savshift, 0x1A); CB_Game.SelectedIndex = sav[TrainerCard + 0x04 + savshift] - 0x18; CB_Gender.SelectedIndex = sav[TrainerCard + 0x05 + savshift]; @@ -557,7 +550,8 @@ namespace PKHeX // New stuff. // Copy Maison Data in - MaskedTextBox[] tba = new MaskedTextBox[] { + MaskedTextBox[] tba = + { TB_MCSN,TB_MCSS,TB_MBSN,TB_MBSS, TB_MCDN,TB_MCDS,TB_MBDN,TB_MBDS, TB_MCTN,TB_MCTS,TB_MBTN,TB_MBTS, @@ -632,8 +626,8 @@ namespace PKHeX uint TID = Util.ToUInt32(MT_TID.Text); uint SID = Util.ToUInt32(MT_SID.Text); uint tsv = (TID ^ SID) >> 4; - Tip1.SetToolTip(this.MT_TID, "TSV: " + tsv.ToString("0000")); - Tip2.SetToolTip(this.MT_SID, "TSV: " + tsv.ToString("0000")); + Tip1.SetToolTip(MT_TID, "TSV: " + tsv.ToString("0000")); + Tip2.SetToolTip(MT_SID, "TSV: " + tsv.ToString("0000")); } private void B_Cancel_Click(object sender, EventArgs e) @@ -697,7 +691,8 @@ namespace PKHeX } private void giveAllAccessories(object sender, EventArgs e) { - byte[] data = new byte[] { + byte[] data = + { 0xFE,0xFF,0xFF,0x7E,0xFF,0xFD,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xEF,0xFF,0xFF,0xFF,0xF9,0xFF,0xFB,0xFF,0xF7,0xFF,0xFF,0x0F,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF, @@ -717,7 +712,7 @@ namespace PKHeX private void toggleBadge(object sender, EventArgs e) { int val = Convert.ToInt16(((PictureBox)sender).Name.Last().ToString()) - 1; - CheckBox[] chka = new CheckBox[] { cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8 }; + CheckBox[] chka = { cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8 }; chka[val].Checked = !chka[val].Checked; } diff --git a/SAV/SAV_Wondercard.cs b/SAV/SAV_Wondercard.cs index 7f4b7c234..a7fcded9b 100644 --- a/SAV/SAV_Wondercard.cs +++ b/SAV/SAV_Wondercard.cs @@ -1,12 +1,7 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; +using System.IO; using System.Text; using System.Windows.Forms; -using System.IO; namespace PKHeX { @@ -28,8 +23,8 @@ namespace PKHeX if (LB_Received.Items.Count > 0) LB_Received.SelectedIndex = 0; - this.DragEnter += new DragEventHandler(tabMain_DragEnter); - this.DragDrop += new DragEventHandler(tabMain_DragDrop); + DragEnter += tabMain_DragEnter; + DragDrop += tabMain_DragDrop; } Form1 m_parent; public byte[] sav = new byte[0x100000]; @@ -37,7 +32,7 @@ namespace PKHeX public int savindex; public bool editing = false; private int wcoffset = 0x21100; - private uint herpesval = 0x225D73C2; + private const uint herpesval = 0x225D73C2; // Repopulation Functions private void populateWClist() @@ -107,7 +102,6 @@ namespace PKHeX Util.Error("Loading of data failed... is this really a Wondercard?", e.ToString()); Array.Copy(new byte[0x108], wondercard_data, 0x108); RTB.Clear(); - return; } } private void populateReceived() @@ -122,8 +116,7 @@ namespace PKHeX // Wondercard IO (.wc6<->window) private void B_Import_Click(object sender, EventArgs e) { - OpenFileDialog importwc6 = new OpenFileDialog(); - importwc6.Filter = "Wondercard|*.wc6"; + OpenFileDialog importwc6 = new OpenFileDialog {Filter = "Wondercard|*.wc6"}; if (importwc6.ShowDialog() == DialogResult.OK) { string path = importwc6.FileName; @@ -205,9 +198,9 @@ namespace PKHeX // Make sure all of the Received Flags are flipped! byte[] wcflags = new byte[0x100]; - for (int i = 0; i < LB_Received.Items.Count; i++) + foreach (object card in LB_Received.Items) { - string cardID = LB_Received.Items[i].ToString(); + string cardID = card.ToString(); uint cardnum = Util.ToUInt32(cardID); wcflags[(cardnum / 8) & 0xFF] |= (byte)(1 << ((byte)(cardnum & 0x7))); diff --git a/SAV/frmReport.cs b/SAV/frmReport.cs index 7852416ee..f08c1e5f0 100644 --- a/SAV/frmReport.cs +++ b/SAV/frmReport.cs @@ -2,14 +2,10 @@ using System.Collections; using System.Collections.Generic; using System.ComponentModel; -using System.Data; -using System.Drawing; using System.Linq; +using System.Reflection; using System.Text; using System.Windows.Forms; -using System.Security.Cryptography; -using System.Reflection; -using System.Text.RegularExpressions; namespace PKHeX { @@ -26,7 +22,6 @@ namespace PKHeX SaveData = new byte[InputData.Length]; Array.Copy(InputData, SaveData, InputData.Length); PokemonList PL = new PokemonList(); - PKX.Structures.SaveGame SaveGame = new PKX.Structures.SaveGame("XY"); if (savindex > 1) savindex = 0; BoxBar.Maximum = 930 + 100; BoxBar.Step = 1; @@ -62,9 +57,11 @@ namespace PKHeX { if (Util.Prompt(MessageBoxButtons.YesNo,"Save all the data to CSV?") == DialogResult.Yes) { - SaveFileDialog savecsv = new SaveFileDialog(); - savecsv.Filter = "Spreadsheet|*.csv"; - savecsv.FileName = "Box Data Dump.csv"; + SaveFileDialog savecsv = new SaveFileDialog + { + Filter = "Spreadsheet|*.csv", + FileName = "Box Data Dump.csv" + }; if (savecsv.ShowDialog() == DialogResult.OK) Export_CSV(savecsv.FileName); } @@ -103,16 +100,16 @@ namespace PKHeX private ListSortDirection listSortDirection; private PropertyDescriptor propertyDescriptor; - public SortableBindingList() + protected SortableBindingList() : base(new List()) { - this.comparers = new Dictionary>(); + comparers = new Dictionary>(); } public SortableBindingList(IEnumerable enumeration) : base(new List(enumeration)) { - this.comparers = new Dictionary>(); + comparers = new Dictionary>(); } protected override bool SupportsSortingCore @@ -122,17 +119,17 @@ namespace PKHeX protected override bool IsSortedCore { - get { return this.isSorted; } + get { return isSorted; } } protected override PropertyDescriptor SortPropertyCore { - get { return this.propertyDescriptor; } + get { return propertyDescriptor; } } protected override ListSortDirection SortDirectionCore { - get { return this.listSortDirection; } + get { return listSortDirection; } } protected override bool SupportsSearchingCore @@ -142,38 +139,38 @@ namespace PKHeX protected override void ApplySortCore(PropertyDescriptor property, ListSortDirection direction) { - List itemsList = (List)this.Items; + List itemsList = (List)Items; Type propertyType = property.PropertyType; PropertyComparer comparer; - if (!this.comparers.TryGetValue(propertyType, out comparer)) + if (!comparers.TryGetValue(propertyType, out comparer)) { comparer = new PropertyComparer(property, direction); - this.comparers.Add(propertyType, comparer); + comparers.Add(propertyType, comparer); } comparer.SetPropertyAndDirection(property, direction); itemsList.Sort(comparer); - this.propertyDescriptor = property; - this.listSortDirection = direction; - this.isSorted = true; + propertyDescriptor = property; + listSortDirection = direction; + isSorted = true; - this.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1)); + OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1)); } protected override void RemoveSortCore() { - this.isSorted = false; - this.propertyDescriptor = base.SortPropertyCore; - this.listSortDirection = base.SortDirectionCore; + isSorted = false; + propertyDescriptor = base.SortPropertyCore; + listSortDirection = base.SortDirectionCore; - this.OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1)); + OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1)); } protected override int FindCore(PropertyDescriptor property, object key) { - int count = this.Count; + int count = Count; for (int i = 0; i < count; ++i) { T element = this[i]; @@ -194,35 +191,35 @@ namespace PKHeX public PropertyComparer(PropertyDescriptor property, ListSortDirection direction) { - this.propertyDescriptor = property; + propertyDescriptor = property; Type comparerForPropertyType = typeof(Comparer<>).MakeGenericType(property.PropertyType); - this.comparer = (IComparer)comparerForPropertyType.InvokeMember("Default", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public, null, null, null); - this.SetListSortDirection(direction); + comparer = (IComparer)comparerForPropertyType.InvokeMember("Default", BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.Public, null, null, null); + SetListSortDirection(direction); } #region IComparer Members public int Compare(T x, T y) { - return this.reverse * this.comparer.Compare(this.propertyDescriptor.GetValue(x), this.propertyDescriptor.GetValue(y)); + return reverse * comparer.Compare(propertyDescriptor.GetValue(x), propertyDescriptor.GetValue(y)); } #endregion private void SetPropertyDescriptor(PropertyDescriptor descriptor) { - this.propertyDescriptor = descriptor; + propertyDescriptor = descriptor; } private void SetListSortDirection(ListSortDirection direction) { - this.reverse = direction == ListSortDirection.Ascending ? 1 : -1; + reverse = direction == ListSortDirection.Ascending ? 1 : -1; } public void SetPropertyAndDirection(PropertyDescriptor descriptor, ListSortDirection direction) { - this.SetPropertyDescriptor(descriptor); - this.SetListSortDirection(direction); + SetPropertyDescriptor(descriptor); + SetListSortDirection(direction); } } } \ No newline at end of file