Valhalla Legends Forums Archive | Battle.net Bot Development References | [RB] Packet Builder

AuthorMessageTime
Ryan Marcus
This is my packet builder class, written in REALbasic. I hope this helps anybody who wants to use it. I should get my packet buffer posted soon..

Adding a byte:
[code]
Sub InsertByte(data as integer)
subpacket = subpacket + ChrB(Data)
end sub
[/code]

Adding a DWORD:
[code]
Sub InsertDWORD(data as string)
subpacket = subpacket + MakeDWORD(data)
End Sub
[/code]

Making a DWORD:
[code]
Protected Function MakeDWORD(data as string) as string
  Dim tmp  as String
  Dim a  as String
  Dim B  as String
  Dim c  as String
  Dim D  as String
  DIM varMakeDWORD as String
  tmp = Right(chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + tohex(Data), 8)
  a = Mid(tmp, 1, 2)
  B = Mid(tmp, 3, 2)
  c = Mid(tmp, 5, 2)
  D = Mid(tmp, 7, 2)
  varMakeDWORD=Chr(Val("&H" + D))
  varMakeDWORD= varMakeDWORD + Chr(Val("&H" + c))
  varMakeDWORD= varMakeDWORD + Chr(Val("&H" + B))
  varMakeDWORD= varMakeDWORD + Chr(Val("&H" + a))
  Return varMakeDWORD
End Function
[/code]

Insert a string:
[code]
Sub InsertString(data as string, NT as boolean)
  Select case NT
  case true
    subpacket = subpacket + data + chr(0)
  case false
    subpacket = subpacket + data
  end Select
End Sub
[/code]

Insert a word:
[code]
Sub InsertWORD(data as integer)
subpacket = subpacket + MakeWord(data)
End Sub
[/code]

Make a word:
[code]
Protected Function MakeWORD(data as integer) as string
  Dim tmp  as String
  Dim a  as String
  Dim B  as String
  DIM varMakeWORD as String
  tmp = Right(chr(0) + chr(0) + chr(0) + chr(0) + hex(Data), 4)
  a = Mid(tmp, 1, 2)
  B = Mid(tmp, 3, 2)
  varMakeWORD=Chr( Val("&H" + B) )
  varMakeWORD= varMakeWORD + Chr( Val("&H" + a) )
  Return varMakeWORD
End Function
[/code]

To hex:
[code]
Private Function ToHex(data as string) as string
  Dim i  as Integer
  DIM varToHex as String
  For i =  1 To Len(Data)
    varToHex= varToHex + Right("00" + hex(Asc(Mid(Data, i, 1))), 2)
  Next
  Return varToHex
End Function
[/code]

Applying BNCS headers:
[code]
Sub ApplyHeaders(MessageID as integer)
  headers = chr(&HFF) + chr(MessageID)
  headers = headers + MakeWord(LenB(subpacket) + lenB(Headers) + 2)
  subpacket = headers + subpacket
End Sub
[/code]

Applying BNLS headers:
[code]
Sub ApplyHeadersBNLS(MessageID as integer)
  headers = MakeWord(lenb(subpacket) + 3) // Include the WORD and the message id byte
  headers = headers + chr(MessageID)
  subpacket = headers + subpacket
End Sub
[/code]

Getting the packet to write out:
[code]
Function GetPacket() as string
return subpacket
End Function
[/code]

You will need the following properties:
headers as string (Public)
subpacket as string (Public)


I hope these help!
September 23, 2005, 12:13 PM

Search