VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "PacketBuffer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private buffer As String
Public Function InsertDWORDArray(Data() As Long)
    Dim i As Integer
    For i = LBound(Data) To UBound(Data) Step 1
        buffer = buffer & MakeDWORD(Data(i))
    Next i
End Function
Public Function InsertDWORD(Data As Long)
    buffer = buffer & MakeDWORD(Data)
End Function
Public Function InsertData(Data As String)
    buffer = buffer & Data
End Function
Public Function InsertWORD(Data As Integer)
    buffer = buffer & MakeWORD(Data)
End Function
Public Function InsertBYTE(Data As Integer)
    buffer = buffer & Chr(Data)
End Function
Public Sub InsertBytes(Data As String)
    Dim i As Long
    Dim enqueueer As String
    
    For i = 1 To Len(Data) Step 3
        enqueueer = enqueueer & Chr(Val("&h0" & Mid(Data, i, 2)))
    Next i
    buffer = buffer & enqueueer
End Sub
Public Function InsertNTString(Data As String)
    buffer = buffer & Data & Chr(0)
End Function
Public Function InsertATString(Data As String)
    buffer = buffer & Data & Chr(&HA)
End Function
Public Function InsertNonNTString(Data As String)
    buffer = buffer & Data
End Function
Public Function InsertNonNTStringArray(Data() As String)
Dim i As Integer
For i = LBound(Data) To UBound(Data) Step 1
    buffer = buffer & Data(i)
    Next
End Function
Public Function MakeDWORD(value As Long) As String
    Dim Result As String * 4
    CopyMemory ByVal Result, value, 4
    MakeDWORD = Result
End Function
Function MakeWORD(value As Integer) As String
    Dim Result As String * 2
    CopyMemory ByVal Result, value, 2
    MakeWORD = Result
End Function
Public Function Clear()
    buffer = ""
End Function
Public Function SendPacket(PacketID As Byte)
If frmMain.wsBnet.State <> sckConnected Then: Exit Function
    frmMain.wsBnet.SendData Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(buffer) + 4) & buffer
    buffer = Replace(buffer, Chr(0), "\0")
    Clear
End Function
Public Function SendRPacket(PacketID As Byte)
If frmMain.wsRealm.State <> sckConnected Then: Exit Function
    frmMain.wsRealm.SendData MakeWORD(Len(buffer) + 3) & Chr(PacketID) & buffer
    Clear
End Function
Public Function SendBNLSPacket(PacketID As Byte)
If frmMain.wsBnls.State <> sckConnected Then: Exit Function
    frmMain.wsBnls.SendData MakeWORD(Len(buffer) + 3) & Chr(PacketID) & buffer
    buffer = Replace(buffer, Chr(0), "\0")
    Clear
End Function
