private List <Patch.AddressDataPair> ParseEnteredPatchData(string version) { List <Patch.AddressDataPair> addressDataPairList = new List <Patch.AddressDataPair>(); List <string> lines = txtPatchData.Text.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList(); int startLine = lines.IndexOf("START " + version); int endLine = lines.IndexOf("END " + version); for (int i = startLine; i < endLine; i++) { if (lines.ElementAt(i).Contains(":")) { Patch.AddressDataPair adp = new Patch.AddressDataPair(); try { int addressLength = lines.ElementAt(i).IndexOf(":"); uint address = uint.Parse(lines.ElementAt(i).Replace("0x", "").Replace("(0x)", "").Substring(0, addressLength), System.Globalization.NumberStyles.HexNumber); adp.m_Address = address; } catch { MessageBox.Show("Error parsing address on line " + i + "\n\n" + lines.ElementAt(i)); return(null); } i++; List <byte> byteList = new List <byte>(); int count = i; while (count < endLine && !lines.ElementAt(count).Contains(":")) { string bytes = lines.ElementAt(count).Replace(" ", "").Replace("0x", "").Replace("(0x)", ""); int numBytes = bytes.Length / 2; if (bytes.Length % 2 != 0) { bytes.Insert(bytes.Length - 1, "0"); numBytes++; } for (int j = 0; j < numBytes; j++) { try { byteList.Add(byte.Parse(bytes.Substring(j * 2, 2), System.Globalization.NumberStyles.HexNumber)); } catch { MessageBox.Show("Error parsing data on line " + i + ", character " + (j * 2) + "\n\n" + bytes.Substring(j * 2, 2)); return(null); } } count++; } adp.m_Data = byteList.ToArray(); addressDataPairList.Add(adp); } } return(addressDataPairList); }
private List<Patch.AddressDataPair> ParseEnteredPatchData(string version) { List<Patch.AddressDataPair> addressDataPairList = new List<Patch.AddressDataPair>(); List<string> lines = txtPatchData.Text.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList(); int startLine = lines.IndexOf("START " + version); int endLine = lines.IndexOf("END " + version); for (int i = startLine; i < endLine; i++) { if (lines.ElementAt(i).Contains(":")) { Patch.AddressDataPair adp = new Patch.AddressDataPair(); try { int addressLength = lines.ElementAt(i).IndexOf(":"); uint address = uint.Parse(lines.ElementAt(i).Replace("0x", "").Replace("(0x)", "").Substring(0, addressLength), System.Globalization.NumberStyles.HexNumber); adp.m_Address = address; } catch { MessageBox.Show("Error parsing address on line " + i + "\n\n" + lines.ElementAt(i)); return null; } i++; List<byte> byteList = new List<byte>(); int count = i; while (count < endLine && !lines.ElementAt(count).Contains(":")) { string bytes = lines.ElementAt(count).Replace(" ", "").Replace("0x", "").Replace("(0x)", ""); int numBytes = bytes.Length / 2; if (bytes.Length % 2 != 0) { bytes.Insert(bytes.Length - 1, "0"); numBytes++; } for (int j = 0; j < numBytes; j++) { try { byteList.Add(byte.Parse(bytes.Substring(j * 2, 2), System.Globalization.NumberStyles.HexNumber)); } catch { MessageBox.Show("Error parsing data on line " + i + ", character " + (j * 2) + "\n\n" + bytes.Substring(j * 2, 2)); return null; } } count++; } adp.m_Data = byteList.ToArray(); addressDataPairList.Add(adp); } } return addressDataPairList; }