Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.63 KB | None | 0 0
  1. Module mCommon
  2.  
  3.     Public Declare Sub Encrypt Lib "swgcrypt.dll" (ByVal Value() As Byte, ByVal nLen As Integer, ByVal crcseed As Int32)
  4.     Public Declare Sub Decrypt Lib "swgcrypt.dll" (ByVal Value() As Byte, ByVal nLen As Integer, ByVal crcseed As Int32)
  5.     Public Declare Sub AppendCRC Lib "swgcrypt.dll" (ByVal Value() As Byte, ByVal nLen As Integer, ByVal crcseed As Int32, ByVal crcLength As Integer)
  6.  
  7.  
  8.     Public omgCrcSeed As Integer = &HDEADBABE
  9.     Public ObjectIDCount As Integer = 1
  10.  
  11.  
  12.  
  13.  
  14.     Public Sub Main()
  15.         frmLogin.Show()
  16.         'frmZone.Show()
  17.  
  18.     End Sub
  19.     Public Sub CopyStream(ByRef input As System.IO.Stream, ByRef output As System.IO.Stream)
  20.         Dim num1 As Integer
  21.         Dim buffer1 As Byte() = New Byte(2000 - 1) {}
  22.         num1 = input.Read(buffer1, 0, 2000)
  23.         Do While (num1 > 0)
  24.             output.Write(buffer1, 0, num1)
  25.             num1 = input.Read(buffer1, 0, 2000)
  26.         Loop
  27.         output.Flush()
  28.     End Sub
  29.     Public Function Decompress(ByVal Data() As Byte) As Byte()
  30.         Dim packet As New zlib.ZStream(), outPut(800) As Byte, newLength As Integer = 0
  31.         packet.avail_in = 0
  32.         packet.inflateInit()
  33.         packet.next_in = Data
  34.         packet.next_in_index = 2
  35.         packet.avail_in = Data.Length - 4
  36.         packet.next_out = outPut
  37.         packet.avail_out = 800
  38.         If packet.inflate(zlib.zlibConst.Z_FINISH) <> zlib.zlibConst.Z_DATA_ERROR Then 'not compressed most likely
  39.             newLength = packet.total_out
  40.             packet.inflateEnd()
  41.             packet = Nothing
  42.  
  43.             Dim retVal(newLength + 2) As Byte
  44.             retVal(0) = Data(0)
  45.             retVal(1) = Data(1)
  46.  
  47.             For i As Integer = 0 To newLength - 1
  48.                 retVal(i + 2) = outPut(i)
  49.             Next
  50.             retVal(retVal.Length - 2) = Data(Data.Length - 2)
  51.             retVal(retVal.Length - 1) = Data(Data.Length - 1)
  52.  
  53.             Return retVal
  54.         Else
  55.             Return Data
  56.         End If
  57.     End Function
  58.  
  59.     Public Function Compress(ByVal Data() As Byte) As Byte()
  60.         Dim packet As New zlib.ZStream(), outPut(Data.Length + 10) As Byte, newLength As Integer = 0
  61.         packet.avail_in = 0
  62.         packet.deflateInit(zlib.zlibConst.Z_DEFAULT_COMPRESSION)
  63.         packet.next_in = Data
  64.         packet.next_in_index = 2
  65.         packet.avail_in = Data.Length - 3
  66.         packet.next_out = outPut
  67.         packet.avail_out = 800
  68.  
  69.         packet.deflate(zlib.zlibConst.Z_FINISH)
  70.  
  71.         newLength = packet.total_out
  72.         packet.deflateEnd()
  73.         packet = Nothing
  74.  
  75.  
  76.         If newLength + 3 < Data.Length Then
  77.             Dim retVal(newLength + 3) As Byte
  78.  
  79.             retVal(0) = Data(0)
  80.             retVal(1) = Data(1)
  81.             For i As Integer = 0 To newLength - 1
  82.                 retVal(i + 2) = outPut(i)
  83.             Next
  84.  
  85.             retVal(retVal.Length - 1) = Data(Data.Length - 1)
  86.  
  87.             Return retVal
  88.         Else
  89.             Return Data
  90.         End If
  91.     End Function
  92.  
  93.  
  94.  
  95.  
  96.     Public Function BinaryToHex(ByVal Data() As Byte) As String
  97.         Dim retVal As String = "", tmpHex As String = ""
  98.         For i As Integer = 0 To Data.Length - 1
  99.             tmpHex = Hex(Data(i))
  100.             If tmpHex.Length = 1 Then
  101.                 tmpHex = "0" & tmpHex
  102.             End If
  103.             retVal &= tmpHex
  104.         Next
  105.         Return retVal
  106.     End Function
  107.  
  108.     Public Function HexToBinary(ByVal Hex As String) As Byte()
  109.         Dim retVal((Hex.Length / 2) - 1) As Byte, curVal As Integer = 0
  110.         For i As Integer = 1 To Hex.Length Step 2
  111.             retVal(curVal) = Val("&H" & Mid(Hex, i, 2))
  112.             curVal += 1
  113.         Next
  114.         Return retVal
  115.     End Function
  116.  
  117.  
  118.     'For reversing bytes. (for sequence etc)
  119.     Public Function GetBytes(ByVal Val As Object) As Byte()
  120.         Dim retVal() As Byte, revVal() As Byte = BitConverter.GetBytes(Val), iCount As Integer = 0
  121.         ReDim retVal(revVal.Length - 1)
  122.         For i As Integer = revVal.Length - 1 To 0 Step -1
  123.             retVal(iCount) = revVal(i)
  124.             iCount += 1
  125.         Next
  126.         Return retVal
  127.     End Function
  128.  
  129.  
  130.  
  131.     Public Function GetPacketStringLength(ByVal p_String As String) As Integer
  132.         Dim ch As Char
  133.  
  134.         Dim totalCount As Integer
  135.  
  136.         For Each ch In p_String
  137.             If ch = " " Then
  138.                 totalCount = totalCount + 1
  139.             End If
  140.         Next ch
  141.  
  142.         'Now, since theres no space at the end, lets add 1
  143.         totalCount = totalCount + 1
  144.         Return totalCount
  145.  
  146.     End Function
  147.  
  148.     Public Function BuildPacketFromString(ByVal p_String As String, ByVal p_Size As Integer) As Byte()
  149.  
  150.         Dim i As Integer
  151.  
  152.         Dim Packet(p_Size - 1) As Byte
  153.  
  154.         For i = 0 To p_Size - 1
  155.             Packet(i) = System.Convert.ToInt32(Split(p_String, " ")(i), 16)
  156.         Next
  157.  
  158.         Return Packet
  159.  
  160.     End Function
  161.     Public Function BuildACK(ByVal Packet() As Byte) As Byte()
  162.         Dim ACK(1) As Byte
  163.         ACK(0) = 0
  164.         ACK(1) = &H15
  165.  
  166.         ACK = AppendPacket(ACK, Packet)
  167.         ACK = AppendPacket(ACK, New Byte() {0, 0, 0}) 'CRC+COMP
  168.         Return ACK
  169.     End Function
  170.     Public Function BuildOK() As Byte()
  171.         Dim OK(8) As Byte
  172.         OK(0) = 1
  173.         OK(1) = 0
  174.         OK(2) = &HAF
  175.         OK(3) = &HF9
  176.         OK(4) = &H6C
  177.         OK(5) = &HA1
  178.         OK(6) = 0
  179.         OK(7) = 0
  180.         OK(8) = 0
  181.         Return OK
  182.     End Function
  183.  
  184.     Public Function BuildNetStatusReply(ByVal Data As Byte()) As Byte()
  185.  
  186.  
  187.         Dim NetStatusReply(3) As Byte
  188.         NetStatusReply(1) = 8
  189.         NetStatusReply(2) = Data(2)
  190.         NetStatusReply(3) = Data(3)
  191.  
  192.  
  193.         ReDim Preserve NetStatusReply(40) 'blank after client tickcount return works
  194.  
  195.         Return NetStatusReply
  196.  
  197.  
  198.     End Function
  199.     Public Function BuildSessionResponse(ByVal Packet() As Byte) As Byte()
  200.  
  201.         Dim SessionID(17) As Byte
  202.  
  203.         Dim i As Integer
  204.         For i = 0 To 16
  205.             SessionID(i) = System.Convert.ToInt32(Split(p_SessionResponse, " ")(i), 16)
  206.         Next
  207.  
  208.         SessionID(2) = Packet(6) 'SESSIONID
  209.         SessionID(3) = Packet(7) 'SESSIONID
  210.         SessionID(4) = Packet(8) 'SESSIONID
  211.         SessionID(5) = Packet(9) 'SESSIONID
  212.  
  213.         SessionID(6) = 222 'CRCSEED
  214.         SessionID(7) = 173 'CRCSEED
  215.         SessionID(8) = 186 'CRCSEED
  216.         SessionID(9) = 190 'CRCSEED
  217.  
  218.         Return SessionID
  219.  
  220.     End Function
  221.  
  222.  
  223.     Public Function BinaryToHexSP(ByVal Data() As Byte) As String
  224.         Dim retVal As String = "", tmpHex As String = ""
  225.         For i As Integer = 0 To Data.Length - 1
  226.             tmpHex = Hex(Data(i))
  227.             If tmpHex.Length = 1 Then
  228.                 tmpHex = "0" & tmpHex
  229.             End If
  230.             retVal &= tmpHex & " "
  231.         Next
  232.         Return retVal
  233.     End Function
  234.     Function rght(ByVal text As String, ByVal val As Long) As String
  235.         rght = Mid(text, Len(text) - val, val + 1)
  236.     End Function
  237.  
  238.     Public Function Randomizer(ByVal iStart As Integer, ByVal iEnd As Integer) As Integer
  239.         'Function To Get a Random Number between # and #
  240.         Dim iRandomValue As Integer
  241.         Randomize()
  242.         iRandomValue = iStart + (Rnd() * (iEnd - iStart))
  243.  
  244.         Return iRandomValue
  245.     End Function
  246.  
  247.  
  248.  
  249.     Public Function RandomizerSingle(ByVal iStart As Single, ByVal iEnd As Single) As Single
  250.         'Function To Get a Random Number between # and #
  251.         Dim iRandomValue As Single
  252.         Randomize()
  253.         iRandomValue = iStart + (Rnd() * (iEnd - iStart))
  254.  
  255.         Return iRandomValue
  256.     End Function
  257. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement