public uint GetSizeValue(uint dataOffset) { if (!ValidOffset(dataOffset)) { throw new ArgumentOutOfRangeException("dataOffset", string.Format("{0} > {1}", dataOffset.ToString("X8"), mPoolSize.ToString("X6"))); } if (dataOffset < sizeof(uint)) { throw new ArgumentOutOfRangeException("dataOffset", "Offset doesn't have room for a size value"); } uint size_value; if (!mDataOffsetToSizeValue.TryGetValue(dataOffset, out size_value)) { if (mBufferedDataRemaining == 0) { throw new InvalidOperationException("No data left in buffer"); } else if (mBuffer == null) { throw new InvalidOperationException("No underlying buffer"); } uint size_offset = dataOffset - sizeof(uint); // Great, now read the entry's value data mBuffer.Seek32(size_offset); size_value = mBuffer.ReadUInt32(); // Update how much data is still remaining mBufferedDataRemaining -= sizeof(uint); if (mBufferedDataRemaining == 0) { DisposeBuffer(); } mDataOffsetToSizeValue.Add(dataOffset, size_value); } return(size_value); }
PoolEntry DeBuffer(XmbVariantType type, uint offset, byte flags = 0) { if (!ValidOffset(offset)) { throw new ArgumentOutOfRangeException("offset", string.Format("{0} > {1}", offset.ToString("X8"), mPoolSize.ToString("X6"))); } PoolEntry e; if (!mEntries.TryGetValue(offset, out e)) { if (mBufferedDataRemaining == 0) { throw new InvalidOperationException("No data left in buffer"); } else if (mBuffer == null) { throw new InvalidOperationException("No underlying buffer"); } // Create our new entry, setting any additional properties e = PoolEntry.New(type); if (type == XmbVariantType.String) { e.IsUnicode = flags != 0; } else if (type == XmbVariantType.Vector) { e.VectorLength = flags; } // Great, now read the entry's value data mBuffer.Seek32(offset); e.Read(mBuffer); // Update how much data is still remaining uint bytes_read = (uint)(mBuffer.BaseStream.Position - offset); mBufferedDataRemaining -= bytes_read; if (mBufferedDataRemaining == 0) { DisposeBuffer(); } mEntries.Add(offset, e); } return(e); }