Public Class CSBinaryReader
    Dim br As IO.BinaryReader

    Public Sub New(ByVal stream As IO.Stream)
        Me.br = New IO.BinaryReader(stream)
    End Sub

    Public Function ReadByte() As Byte
        ReadByte = br.ReadByte
    End Function

    Public Function ReadInt32() As Integer
        Dim b4 As Byte = br.ReadByte()
        Dim b3 As Byte = br.ReadByte()
        Dim b2 As Byte = br.ReadByte()
        Dim b1 As Byte = br.ReadByte()
        ReadInt32 = (CInt(b4) << 24) Or (CInt(b3) << 16) Or (CInt(b2) << 8) Or (CInt(b1))
    End Function

    Public Function ReadInt16() As Short
        Dim b2 As Byte = br.ReadByte()
        Dim b1 As Byte = br.ReadByte()
        ReadInt16 = (CShort(b2) << 8) Or (CShort(b1))
    End Function

    Public Function ReadRectPos() As RectPos
        ReadRectPos = New RectPos()
        ReadRectPos.x = ReadInt16()
        ReadRectPos.y = ReadInt16()
        ReadRectPos.cx = ReadInt16()
        ReadRectPos.cy = ReadInt16()
    End Function

    Public Function ReadSOUND() As SOUND
        ReadSOUND = New SOUND()
        ReadSOUND.word0 = ReadInt16()
        ReadSOUND.byte2 = ReadByte()
        ReadSOUND.byte3 = ReadByte()
        ReadSOUND.byte4 = ReadByte()
        ReadSOUND.byte5 = ReadByte()
        ReadSOUND.byte6 = ReadByte()
        ReadSOUND.byte7 = ReadByte()
    End Function

    Public Function ReadICONDISPLAY() As ICONDISPLAY
        ReadICONDISPLAY = New ICONDISPLAY()
        ReadICONDISPLAY.pixelX = ReadInt16()
        ReadICONDISPLAY.pixelY = ReadInt16()
        ReadICONDISPLAY.objectType = ReadInt16()
    End Function

    Public Function ReadPALETTE() As PALETTE
        ReadPALETTE = New PALETTE()
        Dim i As Integer
        For i = 1 To 16
            ReadPALETTE.color(i) = ReadInt16()
        Next
    End Function
End Class
