public virtual T[] ReadBlockArrayData <T>(BinaryReader binaryReader, BlamPointer blamPointer) where T : GuerillaBlock { var array = new T[blamPointer.ElementCount]; if (!BlamPointer.IsNull(blamPointer) && binaryReader.BaseStream.Position != blamPointer.StartAddress) { var offset = blamPointer.StartAddress - binaryReader.BaseStream.Position; binaryReader.BaseStream.Seek(offset, SeekOrigin.Current); } var pointerArray = new Queue <BlamPointer> [blamPointer.ElementCount]; var ctor = GetObjectActivator <T>(typeof(T)); for (var i = 0; i < blamPointer.ElementCount; ++i) { var element = (T)ctor(); array[i] = element; pointerArray[i] = array[i].ReadFields(binaryReader); } for (var i = 0; i < blamPointer.ElementCount; ++i) { array[i].ReadInstances(binaryReader, pointerArray[i]); } return(array); }
public virtual byte[] ReadDataByteArray(BinaryReader binaryReader, BlamPointer blamPointer) { if (BlamPointer.IsNull(blamPointer)) { return(new byte[0]); } binaryReader.BaseStream.Position = blamPointer.StartAddress; return(binaryReader.ReadBytes(blamPointer.ElementCount)); }
public virtual short[] ReadDataShortArray(BinaryReader binaryReader, BlamPointer blamPointer) { if (BlamPointer.IsNull(blamPointer)) { return(new short[0]); } binaryReader.BaseStream.Position = blamPointer.StartAddress; var elements = new short[blamPointer.ElementCount]; var buffer = binaryReader.ReadBytes(blamPointer.ElementCount * 2); Buffer.BlockCopy(buffer, 0, elements, 0, buffer.Length); return(elements); }
public void WriteQueue( ) { while (_queue.Count > 0) { var item = Dequeue( ); // if the pointer has data, and the stream is not already at the data start address // then seek the data start address using a current stream offset to preserve the read/write // cache. if (!BlamPointer.IsNull(item.Pointer) && BaseStream.Position != item.Pointer.StartAddress) { #if DEBUG var offset = item.Pointer.StartAddress - BaseStream.Position; if (offset < 0) { throw new Exception("That breaks the maps"); } #endif BaseStream.Seek(item.Pointer.StartAddress); } var dataQueueItem = item as ByteDataQueueItem; if (dataQueueItem != null) { Write(dataQueueItem.Data); continue; } var shortDataQueueItem = item as ShortDataQueueItem; if (shortDataQueueItem != null) { var buffer = shortDataQueueItem.Data; for (var i = 0; i < buffer.Length; ++i) { Write(shortDataQueueItem.Data[i]); } continue; } var guerillaBlockQueueItem = item as GuerillaQueueItem; if (guerillaBlockQueueItem == null) { continue; } // then foreach element in the block array call the write method foreach (GuerillaBlock block in guerillaBlockQueueItem.DataBlocks) { block.Write_(this); } } }
public void ReadQueue( ) { while (_queue.Count > 0) { var item = Dequeue( ); // if the pointer has data, and the stream is not already at the data start address // then seek the data start address using a current stream offset to preserve the read/write // cache. if (!BlamPointer.IsNull(item.Pointer) && BaseStream.Position != item.Pointer.StartAddress) { var offset = item.Pointer.StartAddress - BaseStream.Position; BaseStream.Seek(offset, SeekOrigin.Current); } var dataQueueItem = item as ByteDataQueueItem; if (dataQueueItem != null) { dataQueueItem.Data = ReadBytes(item.Pointer.ElementCount); continue; } var shortDataQueueItem = item as ShortDataQueueItem; if (shortDataQueueItem != null) { for (var i = 0; i < item.Pointer.ElementCount; ++i) { shortDataQueueItem.Data[i] = ReadInt16( ); } continue; } var guerillaBlockQueueItem = item as GuerillaQueueItem; if (guerillaBlockQueueItem == null) { continue; } // then foreach element in the block array call the write method foreach (GuerillaBlock block in guerillaBlockQueueItem.DataBlocks) { block.ReadFields(this); } } }