/// <summary> /// Reads C-style wide (2 bytes) string (null terminated) from the stream. /// </summary> public StringReference ReadCStringWide() { StringReference value = BaseReader.ReadCStringWide(); uint size = (uint)value.Buffer.Bytes.Length + 2; if (size <= blockRemaining) { blockRemaining -= size; position += size; CheckMoveReader(); return(value); } // Check if we are reading from two consecutive blocks if (size < BlockSize * 2 && blockIndex + 1 < Blocks.Length && Blocks[blockIndex] + 1 == Blocks[blockIndex + 1]) { uint secondBlockRead = size - blockRemaining; position += size; // Seek for next block blockIndex++; if (blockIndex + 1 == Blocks.Length) { blockRemaining = (uint)(Length - position); } else { blockRemaining = BlockSize; } blockRemaining -= secondBlockRead; return(value); } // Rewind and fallback to slow reader (byte per byte) BaseReader.Position -= size; List <byte> bytes = new List <byte>(); byte b1 = ReadByte(); byte b2 = ReadByte(); while (b1 != 0 || b2 != 0) { bytes.Add(b1); bytes.Add(b2); b1 = ReadByte(); b2 = ReadByte(); } MemoryBuffer buffer = new MemoryBuffer(bytes.ToArray()); return(new StringReference(buffer, StringReference.Encoding.Unicode)); }