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 InsertNonNTString(Data As String)
    buffer = buffer & Data
End Function

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(Optional PacketID As Byte, Optional Download As Boolean)

    If PacketScreen = True Then
        If Len(Hex(PacketID)) = 1 Then
            AddC True, Form8.TALK, vbRed, "[Battle.net (TCP)]: C => S: 0x0" & Hex(PacketID)
        Else
            AddC True, Form8.TALK, vbRed, "[Battle.net (TCP)]: C => S: 0x" & Hex(PacketID)
        End If
    End If
    Dim PacketData As String
    Dim packet As String

    If Connected = True And PacketID <> &H0 And PacketID <> &H25 And PacketID <> &H15 Then
            If FastQueue = True Then
                modModule2.SendData MDIForm1.winsock.SocketHandle, Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(buffer) + 4) & buffer
                flLastSend = GetTickCount()
                CheckDelay (Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(buffer) + 4) & buffer)
                FastQueue = False
            Else
                Q.QAdd Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(buffer) + 4) & buffer
            End If
    Else
            modModule2.SendData MDIForm1.winsock.SocketHandle, Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(buffer) + 4) & buffer
    End If
    Clear
    BytesSent = BytesSent + Len(Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(buffer) + 4) & buffer)
    PacketsSent = PacketsSent + 1
End Function
Public Function GetWORD(Data As String) As Long
Dim tmp As String
tmp = ToHex(Data)
Dim a As String, b As String
a = Mid(tmp, 1, 2)
b = Mid(tmp, 3, 2)
tmp = b & a
GetWORD = Val("&H" & tmp)
End Function
Public Function SendBNLSPacket(PacketID As Byte)
If MDIForm1.BNLSSock.State <> sckConnected Then Exit Function
    If PacketScreen = True Then
        If Len(Hex(PacketID)) = 1 Then
            AddC True, Form8.TALK, vbRed, "[BNLS (TCP)]: C => S: 0x0" & Hex(PacketID)
        Else
            AddC True, Form8.TALK, vbRed, "[BNLS (TCP)]: C => S: 0x" & Hex(PacketID)
        End If
    End If
    MDIForm1.BNLSSock.SendData MakeWORD(Len(buffer) + 3) & Chr(PacketID) & buffer
    Clear
End Function
Public Function GetPacket(PacketID As Byte) As String

    GetPacket = buffer ' Chr$(&HFF) & Chr$(PacketID) & MakeWORD(Len(Buffer) + 4) &'
    
    Call Clear
    
End Function

