private static List <AddressDataPair> ReadAddressDataPairs(XmlReader reader) { List <AddressDataPair> addressDataPairList = new List <AddressDataPair>(); while (reader.Read()) { reader.MoveToContent(); if (reader.LocalName.Equals("AddressDataPair")) { AddressDataPair addressDataPair = new AddressDataPair(); List <byte> byteList = new List <byte>(); while (reader.Read()) { reader.MoveToContent(); if (reader.LocalName.Equals("Address")) { addressDataPair.m_Address = (uint)(reader.ReadElementContentAsLong()); } else if (reader.LocalName.Equals("Data")) { while (reader.Read()) { reader.MoveToContent(); if (reader.LocalName.Equals("Byte")) { byteList.Add((byte)reader.ReadElementContentAsLong()); } else { addressDataPair.m_Data = byteList.ToArray(); addressDataPairList.Add(addressDataPair); break; } } } else { break; } } } else { break; } } return(addressDataPairList); }
public static List <AddressDataPair> GenerateRestoreData(List <AddressDataPair> patchData, string fileName = null, string overlayID = null) { List <AddressDataPair> restoreDataList = new List <AddressDataPair>(); INitroROMBlock fileToPatch = null; if (fileName != null) { fileToPatch = Program.m_ROM.GetFileFromName(fileName); } else if (overlayID != null) { fileToPatch = new NitroOverlay(Program.m_ROM, uint.Parse(overlayID)); } foreach (AddressDataPair addressDataPair in patchData) { AddressDataPair restoreData = new AddressDataPair(); restoreData.m_Address = addressDataPair.m_Address; List <byte> data = new List <byte>(); for (int i = 0; i < addressDataPair.m_Data.Length; i++) { if (fileToPatch == null) { if (Program.m_IsROMFolder) { Program.m_ROM.arm9R.BaseStream.Position = addressDataPair.m_Address + (uint)i - Program.m_ROM.headerSize; data.Add(Program.m_ROM.arm9R.ReadByte()); } else { data.Add(Program.m_ROM.Read8(addressDataPair.m_Address + (uint)i)); } } else { data.Add(fileToPatch.Read8(addressDataPair.m_Address + (uint)i)); } } restoreData.m_Data = data.ToArray(); restoreDataList.Add(restoreData); } return(restoreDataList); }
/// <summary> /// 处理数据 /// </summary> /// <param name="pair">地址数据对</param> private void OnDataReceived(AddressDataPair pair) { Helper.RaiseEvent(this, DataReceived, new EventArgs<AddressDataPair>(pair)); }
private static List<AddressDataPair> ReadAddressDataPairs(XmlReader reader) { List<AddressDataPair> addressDataPairList = new List<AddressDataPair>(); while (reader.Read()) { reader.MoveToContent(); if (reader.LocalName.Equals("AddressDataPair")) { AddressDataPair addressDataPair = new AddressDataPair(); List<byte> byteList = new List<byte>(); while (reader.Read()) { reader.MoveToContent(); if (reader.LocalName.Equals("Address")) { addressDataPair.m_Address = (uint)(reader.ReadElementContentAsLong()); } else if (reader.LocalName.Equals("Data")) { while (reader.Read()) { reader.MoveToContent(); if (reader.LocalName.Equals("Byte")) { byteList.Add((byte)reader.ReadElementContentAsLong()); } else { addressDataPair.m_Data = byteList.ToArray(); addressDataPairList.Add(addressDataPair); break; } } } else break; } } else break; } return addressDataPairList; }
public static List<AddressDataPair> GenerateRestoreData(List<AddressDataPair> patchData, string fileName = null, string overlayID = null) { List<AddressDataPair> restoreDataList = new List<AddressDataPair>(); INitroROMBlock fileToPatch = null; if (fileName != null) fileToPatch = Program.m_ROM.GetFileFromName(fileName); else if (overlayID != null) fileToPatch = new NitroOverlay(Program.m_ROM, uint.Parse(overlayID)); foreach (AddressDataPair addressDataPair in patchData) { AddressDataPair restoreData = new AddressDataPair(); restoreData.m_Address = addressDataPair.m_Address; List<byte> data = new List<byte>(); for (int i = 0; i < addressDataPair.m_Data.Length; i++) { if (fileToPatch == null) data.Add(Program.m_ROM.Read8(addressDataPair.m_Address + (uint)i)); else data.Add(fileToPatch.Read8(addressDataPair.m_Address + (uint)i)); } restoreData.m_Data = data.ToArray(); restoreDataList.Add(restoreData); } return restoreDataList; }
/* * This method takes the first Address and Data from the patch and tests if the current values in the * ROM match the values of the patch - if they match the patch is already applied. This doesn't test * all values to speed things up. */ public bool CheckIsApplied(NitroROM rom) { if (m_DecompressAllOverlays && Helper.CheckAllOverlaysDecompressed() == false) { m_IsApplied = false; return(false); } INitroROMBlock fileToPatch = null; if (m_FileToPatch != null) { fileToPatch = Program.m_ROM.GetFileFromName(m_FileToPatch); } else if (m_OverlayID != null) { fileToPatch = new NitroOverlay(Program.m_ROM, uint.Parse(m_OverlayID)); } AddressDataPair testAddressDataPair = null; switch (rom.m_Version) { case NitroROM.Version.EUR: testAddressDataPair = (m_EURPatch.Count == 0) ? null : m_EURPatch.ElementAt(0); break; case NitroROM.Version.USA_v1: testAddressDataPair = (m_USv1Patch.Count == 0) ? null : m_USv1Patch.ElementAt(0); break; case NitroROM.Version.USA_v2: testAddressDataPair = (m_USv2Patch.Count == 0) ? null : m_USv2Patch.ElementAt(0); break; case NitroROM.Version.JAP: testAddressDataPair = (m_JAPPatch.Count == 0) ? null : m_JAPPatch.ElementAt(0); break; } if (testAddressDataPair == null || testAddressDataPair.m_Data == null || testAddressDataPair.m_Data.Length == 0) { m_IsApplied = false; return(false); } for (int i = 0; i < testAddressDataPair.m_Data.Length; i++) { if (fileToPatch == null) { if (Program.m_IsROMFolder) { Program.m_ROM.arm9R.BaseStream.Position = testAddressDataPair.m_Address + (uint)i - Program.m_ROM.headerSize; if (Program.m_ROM.arm9R.ReadByte() != testAddressDataPair.m_Data[i]) { m_IsApplied = false; return(false); } } else { if (rom.Read8(testAddressDataPair.m_Address + (uint)i) != testAddressDataPair.m_Data[i]) { m_IsApplied = false; return(false); } } } else if (fileToPatch != null && fileToPatch.Read8(testAddressDataPair.m_Address + (uint)i) != testAddressDataPair.m_Data[i]) { m_IsApplied = false; return(false); } } //If it reaches here, the patch has already been applied m_IsApplied = true; return(true); }
protected void RaiseDataReceived(AddressDataPair pair) { Helper.RaiseEvent(this, DataReceived, new EventArgs<AddressDataPair>(pair)); }