VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsPBuffer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'-----------------------------------------------------
' MirageBot Packet Buffer Class
' Written by Christopher Nevin (lancergli@gmail.com)
'-----------------------------------------------------

Option Explicit

Public strBuffer As String
Public Function GetBytes() As Byte()
    Dim B() As Byte
    ReDim B(Len(strBuffer) - 1)
    Dim I As Integer, C As Integer
    C = Len(strBuffer)
    For I = 1 To C
        B(I - 1) = Asc(Mid$(strBuffer, I, 1))
    Next I
    GetBytes = B
End Function
Public Sub Clear()
    strBuffer = vbNS
End Sub
Public Sub InsertBYTE(ByRef Value As Byte)
    strBuffer = strBuffer & Chr$(Value)
End Sub
Public Sub InsertBYTES(ByRef Values() As Byte)
    Dim I As Integer
    For I = 0 To UBound(Values)
        InsertBYTE Values(I)
    Next I
End Sub
Public Sub InsertWORD(ByRef Value As Integer)
    strBuffer = strBuffer & CreateInt16(Value)
End Sub
Public Sub InsertDWORD(ByRef Value As Long)
    strBuffer = strBuffer & CreateInt32(Value)
End Sub
Public Sub InsertFixedString(ByRef Value As String)
    strBuffer = strBuffer & Value
End Sub
Public Sub InsertCString(ByRef Value As String)
    strBuffer = strBuffer & Value & vbNullChar
End Sub
Public Sub SendRealmPacket(ByRef socket As Winsock, ByRef ID As Byte)
    On Error Resume Next
    If (socket.State <> sckConnected) Then Clear: Exit Sub
    socket.SendData CreateInt16(Len(strBuffer) + 3) & Chr$(ID) & strBuffer
    Clear
End Sub
Public Sub SendBnlsPacket(ByRef socket As Winsock, ByRef ID As Byte)
    On Error Resume Next
    If (socket.State <> sckConnected) Then Clear: Exit Sub
    socket.SendData CreateInt16(Len(strBuffer) + 3) & Chr$(ID) & strBuffer
    Clear
End Sub
Public Sub SendBnetPacket(ByRef socket As Winsock, ByRef ID As Byte)
    On Error Resume Next
    If (socket.State <> sckConnected) Then Clear: Exit Sub
    socket.SendData Chr$(&HFF) & Chr$(ID) & CreateInt16(Len(strBuffer) + 4) & strBuffer
    Clear
End Sub

Public Property Get Buffer() As String
    Buffer = strBuffer
End Property

Public Property Let Buffer(ByVal vNewValue As String)
    strBuffer = vNewValue
End Property
