public void MajorMemoryFrameLocateSubrecord() { var majorFrame = new MajorRecordFrame(GameConstants.Oblivion, _majorBytes); majorFrame.LocateSubrecord(RecordTypes.DATA, out var loc); Assert.Equal(DataPos, loc); }
private void ProcessLeveledItemDataFields( MajorRecordFrame majorFrame, long fileOffset) { if (!majorFrame.TryLocateSubrecordFrame(RecordTypes.DATA, out var dataFrame, out var dataIndex)) { return; } int amount = 0; var dataFlag = dataFrame.AsUInt8(); if (dataFlag == 1) { var lvld = majorFrame.LocateSubrecord(RecordTypes.LVLD, out var index); index += lvld.HeaderLength + 1; this._instructions.SetAddition( loc: index + fileOffset, addition: new byte[] { (byte)'L', (byte)'V', (byte)'L', (byte)'F', 0x1, 0x0, 0x2 }); amount += 7; } else { var existingLen = dataFrame.ContentLength; byte[] lenData = new byte[2]; using (var writer = new MutagenWriter(new MemoryStream(lenData), this.GameRelease)) { writer.Write((ushort)(existingLen - 7)); } this._instructions.SetSubstitution( loc: fileOffset + Plugins.Internals.Constants.HeaderLength, sub: lenData); } // Remove DATA var dataRange = new RangeInt64(dataIndex + fileOffset, dataIndex + fileOffset + 7 - 1); this._instructions.SetRemove(dataRange); amount -= (int)dataRange.Width; ProcessLengths( majorFrame, amount, fileOffset); }
/// <summary> /// Iterates a MajorRecordFrame's subrecords and locates the first occurance of the desired type /// </summary> /// <param name="majorFrame">Frame to read from</param> /// <param name="type">Type to search for</param> /// <exception cref="System.ArgumentException">Thrown if target type cannot be found.</exception> /// <returns>First encountered SubrecordHeader with the given type</returns> public static SubrecordHeader LocateSubrecord(this MajorRecordFrame majorFrame, RecordType type) { return(majorFrame.LocateSubrecord(type, loc: out var _)); }