From b56edf1fec470ddb151cfa5c9495b9e0d5a267cf Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 11 Mar 2015 21:44:12 -0700 Subject: [PATCH] Continued Refactoring Should be good now, a lot of silly stuff removed. --- Misc/CodeGenerator.cs | 167 ++++++++++++++++++-------------------- Misc/Util.cs | 68 ++++++++-------- PKX/f1-Main.cs | 92 ++++++++++----------- SAV/SAV_BoxLayout.cs | 34 +++----- SAV/SAV_EventFlagsORAS.cs | 2 +- SAV/SAV_EventFlagsXY.cs | 14 ++-- SAV/SAV_HallOfFame.cs | 19 ++--- SAV/SAV_Inventory.cs | 10 +-- SAV/SAV_PokedexORAS.cs | 35 +++----- SAV/SAV_PokedexXY.cs | 44 ++++------ SAV/SAV_Pokepuff.cs | 53 ++++++------ SAV/SAV_SecretBase.cs | 6 +- SAV/SAV_SuperTrain.cs | 12 +-- SAV/SAV_Trainer.cs | 22 ++--- SAV/SAV_Wondercard.cs | 54 ++++++------ 15 files changed, 292 insertions(+), 340 deletions(-) diff --git a/Misc/CodeGenerator.cs b/Misc/CodeGenerator.cs index ff9f4fa11..71434968f 100644 --- a/Misc/CodeGenerator.cs +++ b/Misc/CodeGenerator.cs @@ -54,11 +54,10 @@ private bool loaddata() + CB_Slot.SelectedIndex * 232, // Slot Shift newdata, 0, 0xE8); - if (newdata.SequenceEqual(new byte[0xE8])) - { - System.Media.SystemSounds.Exclamation.Play(); - return false; - } + if (!newdata.SequenceEqual(new byte[0xE8])) return true; + + System.Media.SystemSounds.Exclamation.Play(); + return false; } else if (CB_Source.SelectedIndex == 2) { @@ -69,11 +68,10 @@ private bool loaddata() // copy from save, the chosen wondercard offset, to new data Array.Copy(m_parent.savefile, SaveGame.Wondercard + wcn * 0x108 + 0x100, newdata, 0, 0x108); byte[] zerodata = new byte[0x108]; - if (newdata.SequenceEqual(zerodata)) - { - System.Media.SystemSounds.Exclamation.Play(); - return false; - } + if (!newdata.SequenceEqual(zerodata)) return true; + + System.Media.SystemSounds.Exclamation.Play(); + return false; } return true; } @@ -153,31 +151,30 @@ private void B_Clear_Click(object sender, EventArgs e) private void B_Load_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog {Filter = "Code File|*.bin"}; - if (ofd.ShowDialog() == DialogResult.OK) - { - string path = ofd.FileName; - byte[] ncf = File.ReadAllBytes(path); - uint length = BitConverter.ToUInt32(ncf, 0); + if (ofd.ShowDialog() != DialogResult.OK) return; - if (ncf.Length != length + 4) - { - Util.Error("Not a valid code file."); + string path = ofd.FileName; + byte[] ncf = File.ReadAllBytes(path); + uint length = BitConverter.ToUInt32(ncf, 0); + + if (ncf.Length != length + 4) + { + Util.Error("Not a valid code file."); + return; + } + if (RTB_Code.Text.Length > 0) + { + DialogResult ld = Util.Prompt(MessageBoxButtons.YesNo, "Replace current code?"); + if (ld == DialogResult.Yes) + RTB_Code.Clear(); + else if (ld != DialogResult.No) return; - } - if (RTB_Code.Text.Length > 0) - { - DialogResult ld = Util.Prompt(MessageBoxButtons.YesNo, "Replace current code?"); - if (ld == DialogResult.Yes) - RTB_Code.Clear(); - else if (ld != DialogResult.No) - return; - } - for (int i = 4; i <= ncf.Length-12; i+=12) - { - RTB_Code.AppendText(BitConverter.ToUInt32(ncf, i + 0 * 4).ToString("X8") + " "); - RTB_Code.AppendText(BitConverter.ToUInt32(ncf, i + 1 * 4).ToString("X8") + " "); - RTB_Code.AppendText(BitConverter.ToUInt32(ncf, i + 2 * 4).ToString("X8") + Environment.NewLine); - } + } + for (int i = 4; i <= ncf.Length-12; i+=12) + { + RTB_Code.AppendText(BitConverter.ToUInt32(ncf, i + 0 * 4).ToString("X8") + " "); + RTB_Code.AppendText(BitConverter.ToUInt32(ncf, i + 1 * 4).ToString("X8") + " "); + RTB_Code.AppendText(BitConverter.ToUInt32(ncf, i + 2 * 4).ToString("X8") + Environment.NewLine); } } private void B_Save_Click(object sender, EventArgs e) @@ -200,17 +197,16 @@ private void B_Save_Click(object sender, EventArgs e) } SaveFileDialog sfd = new SaveFileDialog {FileName = "code.bin", Filter = "Code File|*.bin"}; - if (sfd.ShowDialog() == DialogResult.OK) + if (sfd.ShowDialog() != DialogResult.OK) return; + + string path = sfd.FileName; + if (File.Exists(path)) { - string path = sfd.FileName; - if (File.Exists(path)) - { - // File already exists, save a .bak - byte[] backupfile = File.ReadAllBytes(path); - File.WriteAllBytes(path + ".bak", backupfile); - } - File.WriteAllBytes(path, ncf); + // File already exists, save a .bak + byte[] backupfile = File.ReadAllBytes(path); + File.WriteAllBytes(path + ".bak", backupfile); } + File.WriteAllBytes(path, ncf); } private void B_Copy_Click(object sender, EventArgs e) { @@ -248,16 +244,15 @@ private void B_Diff_Click(object sender, EventArgs e) // Skip Party and Boxes if (i == 0x14200) i += (260 * 6 + 4); // +4 to skip over party count if (i == boxoffset) i += (232 * 30 * 31); - if (BitConverter.ToUInt32(cybersav, i) != BitConverter.ToUInt32(newcyber, i)) - { - result += ((0x20000000 + i).ToString("X8") + " "); - result += (BitConverter.ToUInt32(newcyber, i).ToString("X8") + Environment.NewLine); + if (BitConverter.ToUInt32(cybersav, i) == BitConverter.ToUInt32(newcyber, i)) continue; - lines++; - if ((lines % 128 == 0) && CHK_Break.Checked) - { result += (Environment.NewLine + "--- Segment " + (lines / 128 + 1).ToString() + " ---" + Environment.NewLine + Environment.NewLine); } - if (lines > 10000) goto toomany; - } + result += ((0x20000000 + i).ToString("X8") + " "); + result += (BitConverter.ToUInt32(newcyber, i).ToString("X8") + Environment.NewLine); + + lines++; + if ((lines % 128 == 0) && CHK_Break.Checked) + { result += (Environment.NewLine + "--- Segment " + (lines / 128 + 1) + " ---" + Environment.NewLine + Environment.NewLine); } + if (lines > 10000) goto toomany; } // Loop Through Party @@ -265,18 +260,17 @@ private void B_Diff_Click(object sender, EventArgs e) { byte[] newdata = new byte[260]; Array.Copy(newcyber, i, newdata, 0, 260); byte[] olddata = new byte[260]; Array.Copy(cybersav, i, olddata, 0, 260); - if (!newdata.SequenceEqual(olddata)) - { - for (int z = 0; z < newdata.Length; z += 4) - { - result += ((0x20000000 + i + z).ToString("X8") + " "); - result += (BitConverter.ToUInt32(newdata, z).ToString("X8") + Environment.NewLine); + if (newdata.SequenceEqual(olddata)) continue; - lines++; - if ((lines % 128 == 0) && CHK_Break.Checked) - { result += (Environment.NewLine + "--- Segment " + (lines / 128 + 1).ToString() + " ---" + Environment.NewLine + Environment.NewLine); } - if (lines > 10000) goto toomany; - } + for (int z = 0; z < newdata.Length; z += 4) + { + result += ((0x20000000 + i + z).ToString("X8") + " "); + result += (BitConverter.ToUInt32(newdata, z).ToString("X8") + Environment.NewLine); + + lines++; + if ((lines % 128 == 0) && CHK_Break.Checked) + { result += (Environment.NewLine + "--- Segment " + (lines / 128 + 1) + " ---" + Environment.NewLine + Environment.NewLine); } + if (lines > 10000) goto toomany; } } @@ -297,24 +291,23 @@ private void B_Diff_Click(object sender, EventArgs e) { byte[] newdata = new byte[232]; Array.Copy(newcyber, i, newdata, 0, 232); byte[] olddata = new byte[232]; Array.Copy(cybersav, i, olddata, 0, 232); - if (!newdata.SequenceEqual(olddata)) - { - for (int z = 0; z < newdata.Length; z += 4) - { - result += ((0x20000000 + i + z).ToString("X8") + " "); - result += (BitConverter.ToUInt32(newdata, z).ToString("X8") + Environment.NewLine); + if (newdata.SequenceEqual(olddata)) continue; - lines++; - if ((lines % 128 == 0) && CHK_Break.Checked) - { result += (Environment.NewLine + "--- Segment " + (lines / 128 + 1).ToString() + " ---" + Environment.NewLine + Environment.NewLine); } - if (lines > 10000) goto toomany; - } + for (int z = 0; z < newdata.Length; z += 4) + { + result += ((0x20000000 + i + z).ToString("X8") + " "); + result += (BitConverter.ToUInt32(newdata, z).ToString("X8") + Environment.NewLine); + + lines++; + if ((lines % 128 == 0) && CHK_Break.Checked) + { result += (Environment.NewLine + "--- Segment " + (lines / 128 + 1) + " ---" + Environment.NewLine + Environment.NewLine); } + if (lines > 10000) goto toomany; } } if ((lines / 128 > 0) && CHK_Break.Checked) { - Util.Alert(String.Format("{0} Code Segments.", (1 + (lines / 128)).ToString()), String.Format("{0} Lines.", lines.ToString())); + Util.Alert(String.Format("{0} Code Segments.", (1 + (lines / 128))), String.Format("{0} Lines.", lines)); } RTB_Code.Text = result; return; @@ -338,21 +331,21 @@ private void B_Import_Click(object sender, EventArgs e) // Get Actual Lines for (int i = 0; i < RTB_Code.Lines.Count(); i++) { - if (RTB_Code.Lines[i].Length > 0) + if (RTB_Code.Lines[i].Length <= 0) continue; + + if (RTB_Code.Lines[i].Length <= 2 * 8 && RTB_Code.Lines[i].Length > 2 * 8 + 2) + { Util.Error("Invalid code pasted (Type)"); return; } + + try { - if (RTB_Code.Lines[i].Length <= 2 * 8 && RTB_Code.Lines[i].Length > 2 * 8 + 2) - { Util.Error("Invalid code pasted (Type)"); return; } - 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 if ((data.Length == 232 - 4) || (data.Length == 260 - 4)) diff --git a/Misc/Util.cs b/Misc/Util.cs index c7f8b7069..ce2c6abf7 100644 --- a/Misc/Util.cs +++ b/Misc/Util.cs @@ -131,8 +131,9 @@ internal static string get3DSLocation() for (int i = 1; i < DriveList.Length; i++) // Skip first drive (some users still have floppy drives and would chew up time!) { string potentialPath = DriveList[i] + Path.DirectorySeparatorChar + "Nintendo 3DS"; - if (Directory.Exists(potentialPath)) - { path_3DS = potentialPath; break; } + if (!Directory.Exists(potentialPath)) continue; + + path_3DS = potentialPath; break; } return path_3DS; } @@ -148,8 +149,9 @@ internal static string GetSDFLocation() for (int i = 1; i < DriveList.Length; i++) // Skip first drive (some users still have floppy drives and would chew up time!) { string potentialPath_SDF = NormalizePath(Path.Combine(DriveList[i], "filer" + Path.DirectorySeparatorChar + "UserSaveData")); - if (Directory.Exists(potentialPath_SDF)) - { path_SDF = potentialPath_SDF; break; } + if (!Directory.Exists(potentialPath_SDF)) continue; + + path_SDF = potentialPath_SDF; break; } if (path_SDF == null) return null; @@ -273,10 +275,11 @@ internal static uint getHEXval(TextBox tb) } internal static int getIndex(ComboBox cb) { - int val = 0; - if (cb.SelectedValue != null) - try { val = int.Parse(cb.SelectedValue.ToString()); } - catch { val = cb.SelectedIndex; if (val < 0) val = 0; } + int val; + if (cb.SelectedValue == null) return 0; + + try { val = int.Parse(cb.SelectedValue.ToString()); } + catch { val = cb.SelectedIndex; if (val < 0) val = 0; } return val; } @@ -337,24 +340,20 @@ internal static void TranslateInterface(Control form, string lang, MenuStrip men for (int i = 0; i < rawlist.Length; i++) { // Find our starting point - if (rawlist[i].Contains("! " + FORM_NAME)) // Start our data + if (!rawlist[i].Contains("! " + FORM_NAME)) continue; + + // Allow renaming of the Window Title + string[] WindowName = Regex.Split(rawlist[i], " = "); + if (WindowName.Length > 1) form.Text = WindowName[1]; + // Copy our Control Names and Text to a new array for later processing. + for (int j = i + 1; j < rawlist.Length; j++) { - // Allow renaming of the Window Title - string[] WindowName = Regex.Split(rawlist[i], " = "); - if (WindowName.Length > 1) form.Text = WindowName[1]; - // Copy our Control Names and Text to a new array for later processing. - for (int j = i + 1; j < rawlist.Length; j++) - { - if (rawlist[j].Length == 0) - continue; // Skip Over Empty Lines, errhandled - if (rawlist[j][0].ToString() != "-") // If line is not a comment line... - { - if (rawlist[j][0].ToString() == "!") // Stop if we have reached the end of translation - goto rename; - stringdata[itemsToRename] = rawlist[j]; // Add the entry to process later. - itemsToRename++; - } - } + if (rawlist[j].Length == 0) continue; // Skip Over Empty Lines, errhandled + if (rawlist[j][0].ToString() == "-") continue; // Keep translating if line is a comment line + if (rawlist[j][0].ToString() == "!") // Stop if we have reached the end of translation + goto rename; + stringdata[itemsToRename] = rawlist[j]; // Add the entry to process later. + itemsToRename++; } } return; // Not Found @@ -374,16 +373,15 @@ internal static void TranslateInterface(Control form, string lang, MenuStrip men { // Menu Items can't be found with Controls.Find as they aren't Controls ToolStripDropDownItem TSI = (ToolStripDropDownItem)menu.Items[ctrl]; - if (TSI != null) - { - // We'll rename the main and child in a row. - string[] ToolItems = Regex.Split(SplitString[1], " ; "); - TSI.Text = ToolItems[0]; // Set parent's text first - if (TSI.DropDownItems.Count != ToolItems.Length - 1) - continue; // Error in Input, errhandled - for (int ti = 1; ti <= TSI.DropDownItems.Count; ti++) - TSI.DropDownItems[ti - 1].Text = ToolItems[ti]; // Set child text - } + if (TSI == null) continue; + + // We'll rename the main and child in a row. + string[] ToolItems = Regex.Split(SplitString[1], " ; "); + TSI.Text = ToolItems[0]; // Set parent's text first + if (TSI.DropDownItems.Count != ToolItems.Length - 1) + continue; // Error in Input, errhandled + for (int ti = 1; ti <= TSI.DropDownItems.Count; ti++) + TSI.DropDownItems[ti - 1].Text = ToolItems[ti]; // Set child text // If not found, it is not something to rename and is thus skipped. } catch { } diff --git a/PKX/f1-Main.cs b/PKX/f1-Main.cs index 0a741ff0f..81d43bcb1 100644 --- a/PKX/f1-Main.cs +++ b/PKX/f1-Main.cs @@ -287,11 +287,10 @@ private void mainMenuOpen(object sender, EventArgs e) } DialogResult result = OpenPKX.ShowDialog(); - if (result == DialogResult.OK) - { - string path = OpenPKX.FileName; - openQuick(path); - } + if (result != DialogResult.OK) return; + + string path = OpenPKX.FileName; + openQuick(path); } private void mainMenuSave(object sender, EventArgs e) { @@ -460,31 +459,29 @@ private void openFile(byte[] input, string path, string ext) if ((BitConverter.ToUInt32(input, 0x100) != 0x41534944) && (BitConverter.ToUInt32(input, 0x5234) != 0x6E69616D)) { DialogResult dialogResult = Util.Prompt(MessageBoxButtons.YesNo, "Save file is not decrypted.", "Press Yes to ignore this warning and continue loading the save file."); - if (dialogResult == DialogResult.Yes) - { - DialogResult sdr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000", "Press No for the one at 0x82000"); - if (sdr == DialogResult.Cancel) - return; - savindex = (sdr == DialogResult.Yes) ? 0 : 1; - B_SwitchSAV.Enabled = true; - open1MB(input, path, GameType, false); - } + if (dialogResult != DialogResult.Yes) return; + + DialogResult sdr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000", "Press No for the one at 0x82000"); + if (sdr == DialogResult.Cancel) return; + + savindex = (sdr == DialogResult.Yes) ? 0 : 1; + B_SwitchSAV.Enabled = true; + open1MB(input, path, GameType, false); } else if (PKX.detectSAVIndex(input, ref savindex) == 2) { DialogResult dialogResult = Util.Prompt(MessageBoxButtons.YesNo, "Hash verification failed.", "Press Yes to ignore this warning and continue loading the save file."); - if (dialogResult == DialogResult.Yes) + if (dialogResult != DialogResult.Yes) return; + + DialogResult sdr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000", "Press No for the one at 0x82000"); + if (sdr == DialogResult.Cancel) { - DialogResult sdr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000", "Press No for the one at 0x82000"); - if (sdr == DialogResult.Cancel) - { - savindex = 0; - return; // abort load - } - savindex = (sdr == DialogResult.Yes) ? 0 : 1; - B_SwitchSAV.Enabled = true; - open1MB(input, path, GameType, false); + savindex = 0; + return; // abort load } + savindex = (sdr == DialogResult.Yes) ? 0 : 1; + B_SwitchSAV.Enabled = true; + open1MB(input, path, GameType, false); } else { @@ -1651,7 +1648,7 @@ private void clickQR(object sender, EventArgs e) string filename = data.Nickname; if (filename != data.Species) filename += " (" + data.Species + ")"; - string s1 = String.Format("{0} [{4}] lv{3} @ {1} -- {2}", filename, data.HeldItem, data.Nature, data.Level.ToString(), data.Ability); + string s1 = String.Format("{0} [{4}] lv{3} @ {1} -- {2}", filename, data.HeldItem, data.Nature, data.Level, data.Ability); string s2 = String.Format("{0} / {1} / {2} / {3}", data.Move1, data.Move2, data.Move3, data.Move4); string IVs = String.Format( "IVs:{0}{1}{2}{3}{4}{5}" @@ -2013,28 +2010,26 @@ private void updatePP(object sender, EventArgs e) } private void updatePKRSstrain(object sender, EventArgs e) { - if (CB_PKRSStrain.SelectedIndex == 0) - { - // Never Infected - CB_PKRSDays.SelectedValue = 0; - CHK_Cured.Checked = false; - CHK_Infected.Checked = false; - } + if (CB_PKRSStrain.SelectedIndex != 0) return; + // Never Infected + CB_PKRSDays.SelectedValue = 0; + CHK_Cured.Checked = false; + CHK_Infected.Checked = false; } private void updatePKRSdays(object sender, EventArgs e) { - if (CB_PKRSDays.SelectedIndex == 0) + if (CB_PKRSDays.SelectedIndex != 0) return; + + // If no days are selected + if (CB_PKRSStrain.SelectedIndex == 0) { - // If no days are selected - if (CB_PKRSStrain.SelectedIndex == 0) - { - // Never Infected - CHK_Cured.Checked = false; - CHK_Infected.Checked = false; - } - else CHK_Cured.Checked = true; + // Never Infected + CHK_Cured.Checked = false; + CHK_Infected.Checked = false; } + else CHK_Cured.Checked = true; } + private void updatePKRSCured(object sender, EventArgs e) { if (!init) return; @@ -2830,11 +2825,10 @@ private void clickVerifyCHK(object sender, EventArgs e) 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) - { - invalid1++; - RTB_S.Text += "Invalid: " + i.ToString("X2") + " @ region " + start[i].ToString("X5") + Environment.NewLine; - } + if (checksum == actualsum) continue; + + invalid1++; + RTB_S.Text += "Invalid: " + i.ToString("X2") + " @ region " + start[i].ToString("X5") + Environment.NewLine; } RTB_S.Text += "1st SAV: " + (start.Length - invalid1) + "/" + start.Length + Environment.NewLine; @@ -3000,7 +2994,7 @@ private void clickVerifySHA(object sender, EventArgs e) 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; + RTB_S.Text += "1st SAV: " + (106 - invalid1) + "/" + 106 + Environment.NewLine; // Check The Second Half of Hashes for (int i = 0; i < hashtabledata.Length; i += 4) @@ -3034,7 +3028,7 @@ private void clickVerifySHA(object sender, EventArgs e) 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; + RTB_S.Text += "2nd SAV: " + (106 - invalid2) + "/" + 106 + Environment.NewLine; if (invalid1 + invalid2 == (2 * 106)) RTB_S.Text = "None of the IVFC hashes are valid." + Environment.NewLine; @@ -3810,7 +3804,7 @@ private void setBoxNames() private void setSAVLabel() { L_SAVINDEX.Text = (savindex + 1).ToString(); - RTB_S.AppendText("Loaded Save File " + (savindex + 1).ToString() + Environment.NewLine); + RTB_S.AppendText("Loaded Save File " + (savindex + 1) + Environment.NewLine); } private void getSAVOffsets(ref bool oras) { diff --git a/SAV/SAV_BoxLayout.cs b/SAV/SAV_BoxLayout.cs index 1f1bc20cd..57c0710f1 100644 --- a/SAV/SAV_BoxLayout.cs +++ b/SAV/SAV_BoxLayout.cs @@ -27,13 +27,7 @@ public SAV_BoxLayout(Form1 frm1) Form1 m_parent; public byte[] sav = new byte[0x100000]; public int savindex; - public bool editing = false; - private static uint ToUInt32(String value) - { - if (String.IsNullOrEmpty(value)) - return 0; - return UInt32.Parse(value); - } + public bool editing; private void changeBox(object sender, EventArgs e) { @@ -54,25 +48,23 @@ private void changeBox(object sender, EventArgs e) } private void changeBoxDetails(object sender, EventArgs e) { - if (!editing) - { - int index = LB_BoxSelect.SelectedIndex; - int offset = 0x9800 + savindex * 0x7F000; + if (editing) return; - sav[(0x7F000 * savindex) + 0x9C1E + LB_BoxSelect.SelectedIndex] = (byte)CB_BG.SelectedIndex; + int index = LB_BoxSelect.SelectedIndex; + int offset = 0x9800 + savindex * 0x7F000; - // Get Sender Index + sav[(0x7F000 * savindex) + 0x9C1E + LB_BoxSelect.SelectedIndex] = (byte)CB_BG.SelectedIndex; - byte[] boxname = Encoding.Unicode.GetBytes(TB_BoxName.Text); - Array.Resize(ref boxname, 0x22); - Array.Copy(boxname, 0, sav, offset + 0x22 * index, boxname.Length); + // Get Sender Index - sav[0x9C1E + savindex * 0x7F000 + index] = (byte)CB_BG.SelectedIndex; - sav[0x9C3D + savindex * 0x7F000] = (byte)ToUInt32(MT_BG1.Text); - sav[0x9C3F + savindex * 0x7F000] = (byte)ToUInt32(MT_BG2.Text); + byte[] boxname = Encoding.Unicode.GetBytes(TB_BoxName.Text); + Array.Resize(ref boxname, 0x22); + Array.Copy(boxname, 0, sav, offset + 0x22 * index, boxname.Length); - sav[0x9C3E + savindex * 0x7F000] = (byte)ToUInt32(CB_Unlocked.Text); - } + sav[0x9C1E + savindex * 0x7F000 + index] = (byte)CB_BG.SelectedIndex; + sav[0x9C3D + savindex * 0x7F000] = (byte)Util.ToUInt32(MT_BG1.Text); + sav[0x9C3F + savindex * 0x7F000] = (byte)Util.ToUInt32(MT_BG2.Text); + sav[0x9C3E + savindex * 0x7F000] = (byte)Util.ToUInt32(CB_Unlocked.Text); } private void B_Cancel_Click(object sender, EventArgs e) { diff --git a/SAV/SAV_EventFlagsORAS.cs b/SAV/SAV_EventFlagsORAS.cs index 925a7c051..a026dc7e1 100644 --- a/SAV/SAV_EventFlagsORAS.cs +++ b/SAV/SAV_EventFlagsORAS.cs @@ -221,7 +221,7 @@ private void loadSAV(object sender, string path) 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; } + { Util.Error("Invalid SAV Size", String.Format("File Size: 0x{1} ({0} bytes)", fi.Length, fi.Length.ToString("X5")), "File Loaded: " + path); return; } break; } diff --git a/SAV/SAV_EventFlagsXY.cs b/SAV/SAV_EventFlagsXY.cs index 12de4dca0..25ac2b367 100644 --- a/SAV/SAV_EventFlagsXY.cs +++ b/SAV/SAV_EventFlagsXY.cs @@ -154,13 +154,11 @@ private void diffSaves() 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; @@ -189,7 +187,7 @@ private void loadSAV(object sender, string path) 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; } + { Util.Error("Invalid SAV Size", String.Format("File Size: 0x{1} ({0} bytes)", fi.Length, fi.Length.ToString("X5")), "File Loaded: " + path); return; } break; } diff --git a/SAV/SAV_HallOfFame.cs b/SAV/SAV_HallOfFame.cs index 9c48f8086..a668a4270 100644 --- a/SAV/SAV_HallOfFame.cs +++ b/SAV/SAV_HallOfFame.cs @@ -457,22 +457,21 @@ private void UpdateImage(int species, int form, int item, int gender, bool shiny private void B_CopyText_Click(object sender, EventArgs e) { - try { Clipboard.SetText(RTB.Text); } - catch { }; + Clipboard.SetText(RTB.Text); } private void B_Delete_Click(object sender, EventArgs e) { if (LB_DataEntry.SelectedIndex < 1) { Util.Alert("Cannot delete your first Hall of Fame Clear entry."); return; } int index = LB_DataEntry.SelectedIndex; - if (Util.Prompt(MessageBoxButtons.YesNo, String.Format("Delete Entry {0} from your records?", index)) == DialogResult.Yes) - { - int offset = index * 0x1B4; - if (index != 15) Array.Copy(data, offset + 0x1B4, data, offset, 0x1B4 * (15 - index)); - // Ensure Last Entry is Cleared - Array.Copy(new byte[0x1B4], 0, data, 0x1B4 * 15, 0x1B4); - displayEntry(LB_DataEntry, null); - } + if (Util.Prompt(MessageBoxButtons.YesNo, String.Format("Delete Entry {0} from your records?", index)) + != DialogResult.Yes) return; + + int offset = index * 0x1B4; + if (index != 15) Array.Copy(data, offset + 0x1B4, data, offset, 0x1B4 * (15 - index)); + // Ensure Last Entry is Cleared + Array.Copy(new byte[0x1B4], 0, data, 0x1B4 * 15, 0x1B4); + displayEntry(LB_DataEntry, null); } private void changeNickname(object sender, MouseEventArgs e) diff --git a/SAV/SAV_Inventory.cs b/SAV/SAV_Inventory.cs index c1914f2f1..cbd1b67ef 100644 --- a/SAV/SAV_Inventory.cs +++ b/SAV/SAV_Inventory.cs @@ -45,7 +45,6 @@ public SAV_Inventory(Form1 frm1) Form1 m_parent; public byte[] sav = new byte[0x100000]; public int savindex; int shiftval; - public bool editing = false; public string[] item_val; public string[] keyitem_val; @@ -187,11 +186,10 @@ private void populateList(string[] itemarr, int offset, int itemcount) } private void dropclick(object sender, DataGridViewCellEventArgs e) { - if (e.ColumnIndex == 0) - { - ComboBox comboBox = (ComboBox)dataGridView1.EditingControl; - comboBox.DroppedDown = true; - } + if (e.ColumnIndex != 0) return; + + ComboBox comboBox = (ComboBox)dataGridView1.EditingControl; + comboBox.DroppedDown = true; } private void saveBag(object sender) { diff --git a/SAV/SAV_PokedexORAS.cs b/SAV/SAV_PokedexORAS.cs index 3faa4dea8..61dc77acb 100644 --- a/SAV/SAV_PokedexORAS.cs +++ b/SAV/SAV_PokedexORAS.cs @@ -22,7 +22,7 @@ public SAV_PokedexORAS(Form1 frm1) private int dexoffset = 0x15000 + 0x5400; Form1 m_parent; public byte[] sav = new byte[0x100000]; - public int sv = 0; + public int sv; public bool[,] specbools = new bool[9, 0x60 * 8]; public bool[,] langbools = new bool[7, 0x60 * 8]; bool editing = true; @@ -67,26 +67,21 @@ private void Setup() } private void changeCBSpecies(object sender, EventArgs e) { - if (!editing) - { - 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 = LB_Species.SelectedIndex; - loadchks(); - editing = false; - } + if (editing) return; + + 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 = LB_Species.SelectedIndex; + loadchks(); + editing = false; } private void changeLBSpecies(object sender, EventArgs e) { if (editing) return; editing = true; - try - { - int index = LB_Species.SelectedIndex + 1; - CB_Species.SelectedValue = index; - } - catch { } + int index = LB_Species.SelectedIndex + 1; + CB_Species.SelectedValue = index; loadchks(); editing = false; } @@ -204,12 +199,8 @@ private void saveChanges() } // Store Spinda Spot - try - { - uint PID = Util.getHEXval(TB_Spinda); - Array.Copy(BitConverter.GetBytes(PID), 0, sav, dexoffset + 0x680, 4); - } - catch { }; + uint PID = Util.getHEXval(TB_Spinda); + Array.Copy(BitConverter.GetBytes(PID), 0, sav, dexoffset + 0x680, 4); } private void B_GiveAll_Click(object sender, EventArgs e) diff --git a/SAV/SAV_PokedexXY.cs b/SAV/SAV_PokedexXY.cs index f3ed9ca37..da043b228 100644 --- a/SAV/SAV_PokedexXY.cs +++ b/SAV/SAV_PokedexXY.cs @@ -78,30 +78,24 @@ private void Setup() } private void changeCBSpecies(object sender, EventArgs e) { - if (!editing) - { - 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 = LB_Species.SelectedIndex; - loadchks(); - editing = false; - } + if (editing) return; + + 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 = LB_Species.SelectedIndex; + loadchks(); + editing = false; } private void changeLBSpecies(object sender, EventArgs e) { - if (!editing) - { - editing = true; - try - { - int index = LB_Species.SelectedIndex + 1; - CB_Species.SelectedValue = index; - } - catch { }; - loadchks(); - editing = false; - } + if (editing) return; + + editing = true; + int index = LB_Species.SelectedIndex + 1; + CB_Species.SelectedValue = index; + loadchks(); + editing = false; } private void loadchks() { @@ -245,12 +239,8 @@ private void saveChanges() } // Store Spinda Spot - try - { - uint PID = Util.getHEXval(TB_Spinda); - Array.Copy(BitConverter.GetBytes(PID), 0, sav, 0x1AA48 + Convert.ToInt16(m_parent.savegame_oras) * 0x38 + savshift, 4); - } - catch { }; + uint PID = Util.getHEXval(TB_Spinda); + Array.Copy(BitConverter.GetBytes(PID), 0, sav, 0x1AA48 + Convert.ToInt16(m_parent.savegame_oras) * 0x38 + savshift, 4); } private void B_GiveAll_Click(object sender, EventArgs e) diff --git a/SAV/SAV_Pokepuff.cs b/SAV/SAV_Pokepuff.cs index dc1f07d2b..d99ef061f 100644 --- a/SAV/SAV_Pokepuff.cs +++ b/SAV/SAV_Pokepuff.cs @@ -19,23 +19,23 @@ public SAV_Pokepuff(Form1 frm1) 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; + + private Form1 m_parent; public byte[] sav = new byte[0x100000]; public int savindex; - public bool editing = false; - private string[] pfa = { - "Empty", - "Basic Sweet","Basic Mint","Basic Citrus","Basic Mocha","Basic Spice", - "Frosted Sweet","Frosted Mint","Frosted Citrus","Frosted Mocha","Frosted Spice", - "Fancy Sweet","Fancy Mint","Fancy Citrus","Fancy Mocha","Fancy Spice", - "Deluxe Sweet","Deluxe Mint","Deluxe Citrus","Deluxe Mocha","Deluxe Spice", - "Supreme Wish","Supreme Honor","Supreme Spring","Supreme Summer","Supreme Fall","Supreme Winter", - }; + private string[] pfa = + { + "Empty", + "Basic Sweet", "Basic Mint", "Basic Citrus", "Basic Mocha", "Basic Spice", + "Frosted Sweet", "Frosted Mint", "Frosted Citrus", "Frosted Mocha", "Frosted Spice", + "Fancy Sweet", "Fancy Mint", "Fancy Citrus", "Fancy Mocha", "Fancy Spice", + "Deluxe Sweet", "Deluxe Mint", "Deluxe Citrus", "Deluxe Mocha", "Deluxe Spice", + "Supreme Wish", "Supreme Honor", "Supreme Spring", "Supreme Summer", "Supreme Fall", "Supreme Winter", + }; private void Setup() { dataGridView1.Rows.Clear(); dataGridView1.Columns.Clear(); - DataGridViewColumn dgvIndex = new DataGridViewTextBoxColumn(); { @@ -61,22 +61,22 @@ private void Setup() dataGridView1.Columns.Add(dgvPuff); dataGridView1.Rows.Add(100); - int offset = 0x5400 + 0x7F000 * savindex; + int offset = 0x5400 + 0x7F000*savindex; for (int i = 0; i < 100; i++) { dataGridView1.Rows[i].Cells[0].Value = (i + 1).ToString(); - dataGridView1.Rows[i].Cells[1].Value = pfa[sav[offset+i]]; + dataGridView1.Rows[i].Cells[1].Value = pfa[sav[offset + i]]; } MT_CNT.Text = BitConverter.ToUInt32(sav, offset + 100).ToString("0"); } private void dropclick(object sender, DataGridViewCellEventArgs e) { - 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; } + private void B_Cancel_Click(object sender, EventArgs e) { Close(); @@ -92,9 +92,9 @@ private void B_All_Click(object sender, EventArgs e) } byte[] newpuffs = new byte[100]; for (int i = 0; i < 100; i++) - newpuffs[i] = (byte)(Util.rnd32() % basemod + basepuff); + newpuffs[i] = (byte) (Util.rnd32()%basemod + basepuff); - Array.Copy(newpuffs, 0, sav, 0x5400 + savindex * 0x7F000, 100); + Array.Copy(newpuffs, 0, sav, 0x5400 + savindex*0x7F000, 100); Setup(); } private void B_None_Click(object sender, EventArgs e) @@ -105,7 +105,7 @@ private void B_None_Click(object sender, EventArgs e) newpuffs[2] = 3; newpuffs[3] = 4; newpuffs[4] = 5; - Array.Copy(newpuffs, 0, sav, 0x5400 + savindex * 0x7F000, 100); + Array.Copy(newpuffs, 0, sav, 0x5400 + savindex*0x7F000, 100); Setup(); } private void B_Sort_Click(object sender, EventArgs e) @@ -116,7 +116,7 @@ private void B_Sort_Click(object sender, EventArgs e) for (int i = 0; i < 100; i++) { string puff = dataGridView1.Rows[i].Cells[1].Value.ToString(); - puffarray[i] = (byte)Array.IndexOf(pfa, puff); + puffarray[i] = (byte) Array.IndexOf(pfa, puff); } Array.Sort(puffarray); Array.Reverse(puffarray); @@ -127,7 +127,7 @@ private void B_Sort_Click(object sender, EventArgs e) for (int i = 0; i < 100; i++) { string puff = dataGridView1.Rows[i].Cells[1].Value.ToString(); - byte puffval = (byte)Array.IndexOf(pfa, puff); + byte puffval = (byte) Array.IndexOf(pfa, puff); if (puffval == 0) continue; puffarray[count] = puffval; count++; @@ -136,7 +136,7 @@ private void B_Sort_Click(object sender, EventArgs e) Array.Sort(puffarray); Array.Resize(ref puffarray, 100); } - Array.Copy(puffarray, 0, sav, 0x5400 + savindex * 0x7F000, 100); + Array.Copy(puffarray, 0, sav, 0x5400 + savindex*0x7F000, 100); Setup(); } private void B_Save_Click(object sender, EventArgs e) @@ -151,9 +151,10 @@ private void B_Save_Click(object sender, EventArgs e) emptyslots++; continue; } - puffarray[i-emptyslots] = (byte)Array.IndexOf(pfa, puff); + + puffarray[i - emptyslots] = (byte) Array.IndexOf(pfa, puff); } - Array.Copy(puffarray, 0, sav, 0x5400 + savindex * 0x7F000, 100); + Array.Copy(puffarray, 0, sav, 0x5400 + savindex*0x7F000, 100); Array.Copy(sav, m_parent.savefile, 0x100000); m_parent.savedited = true; Close(); diff --git a/SAV/SAV_SecretBase.cs b/SAV/SAV_SecretBase.cs index d7a4a9e7f..39305b712 100644 --- a/SAV/SAV_SecretBase.cs +++ b/SAV/SAV_SecretBase.cs @@ -25,7 +25,6 @@ public SAV_SecretBase(Form1 frm1) } Form1 m_parent; public byte[] sav = new byte[0x100000]; - public byte[] wondercard_data = new byte[0x108]; public bool editing; private const int sv = 0; private const int fav_offset = 0x23A00; @@ -82,7 +81,7 @@ private void popFavorite() string BaseTrainer = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + favoff + i * 0x3E0 + 0x218, 0x1A)); if (BaseTrainer.Length < 1 || BaseTrainer[0] == '\0') BaseTrainer = "Empty"; - LB_Favorite.Items.Add(i.ToString() + " " + BaseTrainer); + LB_Favorite.Items.Add(i + " " + BaseTrainer); } } private void B_SAV2FAV(object sender, EventArgs e) @@ -93,8 +92,7 @@ private void B_SAV2FAV(object sender, EventArgs e) int offset = fav_offset + 0x5400 + 0x25A; // Base Offset Changing - if (index == 0) - offset = fav_offset + 0x5400 + 0x326; + if (index == 0) offset = fav_offset + 0x5400 + 0x326; else offset += 0x3E0 * index; string TrainerName = Util.TrimFromZero(Encoding.Unicode.GetString(sav, sv + offset + 0x218, 0x1A)); diff --git a/SAV/SAV_SuperTrain.cs b/SAV/SAV_SuperTrain.cs index 3347bc0ff..d3d59706b 100644 --- a/SAV/SAV_SuperTrain.cs +++ b/SAV/SAV_SuperTrain.cs @@ -138,14 +138,14 @@ private void B_Save_Click(object sender, EventArgs e) Array.Resize(ref data, 4); Array.Copy(data, 0, sav, offsetTime + 4 * 30, 4); } - catch { }; + catch { } try { byte[] data = BitConverter.GetBytes(Single.Parse(TB_Time2.Text)); Array.Resize(ref data, 4); Array.Copy(data, 0, sav, offsetTime + 4 * 31, 4); } - catch { }; + catch { } { int offsetSpec = data_offset + 0x188 + 0x7F000 * savindex; byte[] data = BitConverter.GetBytes(Convert.ToUInt16(CB_S2.SelectedValue.ToString())); @@ -155,7 +155,7 @@ private void B_Save_Click(object sender, EventArgs e) Array.Copy(bagarray, 0, sav, data_offset + 0x308 + savindex * 0x7F000, 12); Array.Copy(sav, m_parent.savefile, 0x100000); m_parent.savedited = true; - this.Close(); + Close(); } private void B_Cancel_Click(object sender, EventArgs e) { @@ -171,7 +171,7 @@ private void changeRecordSpecies(object sender, EventArgs e) Array.Resize(ref data, 2); Array.Copy(data, 0, sav, offsetSpec + 4 * index, 2); } - catch { return; } + catch { } } private void changeRecordVal(object sender, EventArgs e) { @@ -183,7 +183,7 @@ private void changeRecordVal(object sender, EventArgs e) Array.Resize(ref data, 2); Array.Copy(data, 0, sav, offsetVal + 4 * index, 2); } - catch { return; } + catch { } } private void changeRecordTime(object sender, EventArgs e) { @@ -195,7 +195,7 @@ private void changeRecordTime(object sender, EventArgs e) Array.Resize(ref data, 4); Array.Copy(data, 0, sav, offsetTime + 4 * index, 4); } - catch { return; } + catch { } } } } diff --git a/SAV/SAV_Trainer.cs b/SAV/SAV_Trainer.cs index e0bb8fcff..ffdfafe36 100644 --- a/SAV/SAV_Trainer.cs +++ b/SAV/SAV_Trainer.cs @@ -27,7 +27,8 @@ public SAV_Trainer(Form1 frm1) savshift = savindex * 0x7F000; if (m_parent.savegame_oras) { - psssatoffset = 0x24800; Maison += 0xA00; VivillonForm = 0x9644; + psssatoffset = 0x24800; Maison += 0xA00; + VivillonForm = 0x9644; Width = (int)((float)Width * 428 / 590); CB_Multi.Enabled = true; L_MultiplayerSprite.Enabled = true; // Multiplayer Sprite Label @@ -677,17 +678,16 @@ private void changeStat(object sender, EventArgs e) } private void changeStatVal(object sender, EventArgs e) { - if (!editing) - { - int pssoff = psssatoffset + savindex * 0x7F000; - string offsetstr = statdata[CB_Stats.SelectedIndex * 2]; - int offset = (int)new System.ComponentModel.Int32Converter().ConvertFromString(offsetstr); + if (editing) return; - uint val = UInt32.Parse(MT_Stat.Text); - byte[] data = BitConverter.GetBytes(val); - Array.Resize(ref data, 4); - Array.Copy(data, 0, sav, pssoff + offset, 4); - } + int pssoff = psssatoffset + savindex * 0x7F000; + string offsetstr = statdata[CB_Stats.SelectedIndex * 2]; + int offset = (int)new System.ComponentModel.Int32Converter().ConvertFromString(offsetstr); + + uint val = UInt32.Parse(MT_Stat.Text); + byte[] data = BitConverter.GetBytes(val); + Array.Resize(ref data, 4); + Array.Copy(data, 0, sav, pssoff + offset, 4); } private void giveAllAccessories(object sender, EventArgs e) { diff --git a/SAV/SAV_Wondercard.cs b/SAV/SAV_Wondercard.cs index b47b27a86..a38a2fe31 100644 --- a/SAV/SAV_Wondercard.cs +++ b/SAV/SAV_Wondercard.cs @@ -76,18 +76,17 @@ private void populateReceived() private void B_Import_Click(object sender, EventArgs e) { OpenFileDialog importwc6 = new OpenFileDialog {Filter = "Wondercard|*.wc6"}; - if (importwc6.ShowDialog() == DialogResult.OK) + if (importwc6.ShowDialog() != DialogResult.OK) return; + + string path = importwc6.FileName; + if (new FileInfo(path).Length > 0x108) { - string path = importwc6.FileName; - if (new FileInfo(path).Length > 0x108) - { - Util.Error("File is not a Wondercard:", path); - return; - } - byte[] newwc6 = File.ReadAllBytes(path); - Array.Copy(newwc6, wondercard_data, newwc6.Length); - loadwcdata(); + Util.Error("File is not a Wondercard:", path); + return; } + byte[] newwc6 = File.ReadAllBytes(path); + Array.Copy(newwc6, wondercard_data, newwc6.Length); + loadwcdata(); } private void B_Output_Click(object sender, EventArgs e) { @@ -96,19 +95,18 @@ private void B_Output_Click(object sender, EventArgs e) string cardname = Encoding.Unicode.GetString(wondercard_data, 0x2, 0x48); outputwc6.FileName = cardID + " - " + cardname + ".wc6"; outputwc6.Filter = "Wondercard|*.wc6"; - if (outputwc6.ShowDialog() == DialogResult.OK) + if (outputwc6.ShowDialog() != DialogResult.OK) return; + + string path = outputwc6.FileName; + + if (File.Exists(path)) { - string path = outputwc6.FileName; - - if (File.Exists(path)) - { - // File already exists, save a .bak - byte[] backupfile = File.ReadAllBytes(path); - File.WriteAllBytes(path + ".bak", backupfile); - } - - File.WriteAllBytes(path, wondercard_data); + // File already exists, save a .bak + byte[] backupfile = File.ReadAllBytes(path); + File.WriteAllBytes(path + ".bak", backupfile); } + + File.WriteAllBytes(path, wondercard_data); } // Wondercard RW (window<->sav) @@ -133,9 +131,10 @@ private void B_WC2SAV(object sender, EventArgs e) populateWClist(); int cardID = BitConverter.ToUInt16(wondercard_data, 0); - if (cardID > 0 && cardID < 0x100 * 8) - if (!LB_Received.Items.Contains(cardID.ToString("0000"))) - LB_Received.Items.Add(cardID.ToString("0000")); + if (cardID <= 0 || cardID >= 0x100*8) return; + + if (!LB_Received.Items.Contains(cardID.ToString("0000"))) + LB_Received.Items.Add(cardID.ToString("0000")); } private void B_DeleteWC_Click(object sender, EventArgs e) { @@ -181,9 +180,10 @@ select Util.ToUInt32(cardID)) // Delete WC Flag private void B_DeleteReceived_Click(object sender, EventArgs e) { - if (LB_Received.SelectedIndex > -1) - if (LB_Received.Items.Count > 0) - LB_Received.Items.Remove(LB_Received.Items[LB_Received.SelectedIndex]); + if (LB_Received.SelectedIndex <= -1) return; + + if (LB_Received.Items.Count > 0) + LB_Received.Items.Remove(LB_Received.Items[LB_Received.SelectedIndex]); } // Drag & Drop Wondercards