/// <summary> /// Add the payload of an SRecord to the appropriate blob, or create a new blob if necessary. /// </summary> public void ProcessRecord(SRecord record) { if (record.Payload == null) { return; } foreach (Blob blob in this.Blobs) { if (blob.NextByteAddress == record.Address) { blob.AddRecord(record.Payload); return; } } Blob newBlob = new Blob(record.Address, record.Payload); this.Blobs.Add(newBlob); }
public override bool MetaCheck(IEnumerable<byte> buffer) { Blob checkblob = new Blob(this.StartAddress, buffer); int count = checkblob.Content.Count; byte[] mask = new byte[] { 0xF0, 0xFF, 0x00, 0x00 }; byte[] check = new byte[] { 0x40, 0x0B, 0x00, 0x00 }; byte[] baseline = buffer.ToArray<byte>(); for (int i = 0; i < count; i++) { baseline[i] &= (byte)mask[i]; if (check[i] != baseline[i]) { return false; } } return true; }
/// <summary> /// Check the baseline data for a r4b patch /// </summary> /// <param name="buffer">Buffer containing baseline data</param> /// <returns></returns> public virtual bool MetaCheck(IEnumerable<byte> buffer) { Blob checkblob = new Blob(this.StartAddress, buffer); int count = checkblob.Content.Count; for (int i = 0; i < count; i++) { if (this.Baseline.Content[i] != checkblob.Content[i]) { return false; } } return true; }
/// <summary> /// Try to read the Patch metadata from the file and add this data to table lists. /// </summary> private bool TryParseDefs(Blob metadata, ref int offset, String defPath) { UInt32 cookie = 0; while ((metadata.Content.Count > offset + 8) && metadata.TryGetUInt32(ref cookie, ref offset)) { if (cookie == OpTable3d)//TODO CONDITIONALLY READ LUTS! { string metaString = null; uint metaOffset = 0; if (this.TryReadDefData(metadata, out metaString, out metaOffset, ref offset)) { Blob tableBlob; this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs); Lut3D lut = new Lut3D(metaString, tableBlob, metaOffset); if (metaString != null) { RomLutList.Add(lut); } } else { Trace.WriteLine("Invalid definition found."); return(false); } } else if (cookie == OpTable2d)//TODO CONDITIONALLY READ LUTS! { string metaString = null; uint metaOffset = 0; if (this.TryReadDefData(metadata, out metaString, out metaOffset, ref offset)) { Blob tableBlob; this.parentMod.TryGetMetaBlob(metaOffset, 10, out tableBlob, this.parentMod.blobList.Blobs); Lut2D lut = new Lut2D(metaString, tableBlob, metaOffset); if (metaString != null) { RomLutList.Add(lut); } } else { Trace.WriteLine("Invalid definition found."); return(false); } } else if (cookie == OpTable1d) { string metaString = null; uint metaOffset = 0; if (this.TryReadDefData(metadata, out metaString, out metaOffset, ref offset)) { Lut lut = new Lut(metaString, metaOffset); if (metaString != null) { RomLutList.Add(lut); } } else { Trace.WriteLine("Invalid definition found."); return(false); } } else if (cookie == OpRAM) { string paramName = null; string paramId = null; uint paramOffset = 0; uint paramLenght = 0; if (this.TryReadDefData(metadata, out paramId, out paramOffset, ref offset)) { if (this.TryReadDefData(metadata, out paramName, out paramLenght, ref offset)) { // found modName, output to string! KeyValuePair <String, Table> tempTable = CreateRomRaiderRamTable(paramName, (int)paramOffset, paramId, (int)paramLenght); if (tempTable.Key != null) { this.RamTableList.Add(tempTable.Key, tempTable.Value); } } } else { Trace.WriteLine("Invalid definition found."); return(false); } } else if (cookie == Mod.endoffile) { break; } } return(true); }