Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module mCommon
- Public Declare Sub Encrypt Lib "swgcrypt.dll" (ByVal Value() As Byte, ByVal nLen As Integer, ByVal crcseed As Int32)
- Public Declare Sub Decrypt Lib "swgcrypt.dll" (ByVal Value() As Byte, ByVal nLen As Integer, ByVal crcseed As Int32)
- Public Declare Sub AppendCRC Lib "swgcrypt.dll" (ByVal Value() As Byte, ByVal nLen As Integer, ByVal crcseed As Int32, ByVal crcLength As Integer)
- Public omgCrcSeed As Integer = &HDEADBABE
- Public ObjectIDCount As Integer = 1
- Public Sub Main()
- frmLogin.Show()
- 'frmZone.Show()
- End Sub
- Public Sub CopyStream(ByRef input As System.IO.Stream, ByRef output As System.IO.Stream)
- Dim num1 As Integer
- Dim buffer1 As Byte() = New Byte(2000 - 1) {}
- num1 = input.Read(buffer1, 0, 2000)
- Do While (num1 > 0)
- output.Write(buffer1, 0, num1)
- num1 = input.Read(buffer1, 0, 2000)
- Loop
- output.Flush()
- End Sub
- Public Function Decompress(ByVal Data() As Byte) As Byte()
- Dim packet As New zlib.ZStream(), outPut(800) As Byte, newLength As Integer = 0
- packet.avail_in = 0
- packet.inflateInit()
- packet.next_in = Data
- packet.next_in_index = 2
- packet.avail_in = Data.Length - 4
- packet.next_out = outPut
- packet.avail_out = 800
- If packet.inflate(zlib.zlibConst.Z_FINISH) <> zlib.zlibConst.Z_DATA_ERROR Then 'not compressed most likely
- newLength = packet.total_out
- packet.inflateEnd()
- packet = Nothing
- Dim retVal(newLength + 2) As Byte
- retVal(0) = Data(0)
- retVal(1) = Data(1)
- For i As Integer = 0 To newLength - 1
- retVal(i + 2) = outPut(i)
- Next
- retVal(retVal.Length - 2) = Data(Data.Length - 2)
- retVal(retVal.Length - 1) = Data(Data.Length - 1)
- Return retVal
- Else
- Return Data
- End If
- End Function
- Public Function Compress(ByVal Data() As Byte) As Byte()
- Dim packet As New zlib.ZStream(), outPut(Data.Length + 10) As Byte, newLength As Integer = 0
- packet.avail_in = 0
- packet.deflateInit(zlib.zlibConst.Z_DEFAULT_COMPRESSION)
- packet.next_in = Data
- packet.next_in_index = 2
- packet.avail_in = Data.Length - 3
- packet.next_out = outPut
- packet.avail_out = 800
- packet.deflate(zlib.zlibConst.Z_FINISH)
- newLength = packet.total_out
- packet.deflateEnd()
- packet = Nothing
- If newLength + 3 < Data.Length Then
- Dim retVal(newLength + 3) As Byte
- retVal(0) = Data(0)
- retVal(1) = Data(1)
- For i As Integer = 0 To newLength - 1
- retVal(i + 2) = outPut(i)
- Next
- retVal(retVal.Length - 1) = Data(Data.Length - 1)
- Return retVal
- Else
- Return Data
- End If
- End Function
- Public Function BinaryToHex(ByVal Data() As Byte) As String
- Dim retVal As String = "", tmpHex As String = ""
- For i As Integer = 0 To Data.Length - 1
- tmpHex = Hex(Data(i))
- If tmpHex.Length = 1 Then
- tmpHex = "0" & tmpHex
- End If
- retVal &= tmpHex
- Next
- Return retVal
- End Function
- Public Function HexToBinary(ByVal Hex As String) As Byte()
- Dim retVal((Hex.Length / 2) - 1) As Byte, curVal As Integer = 0
- For i As Integer = 1 To Hex.Length Step 2
- retVal(curVal) = Val("&H" & Mid(Hex, i, 2))
- curVal += 1
- Next
- Return retVal
- End Function
- 'For reversing bytes. (for sequence etc)
- Public Function GetBytes(ByVal Val As Object) As Byte()
- Dim retVal() As Byte, revVal() As Byte = BitConverter.GetBytes(Val), iCount As Integer = 0
- ReDim retVal(revVal.Length - 1)
- For i As Integer = revVal.Length - 1 To 0 Step -1
- retVal(iCount) = revVal(i)
- iCount += 1
- Next
- Return retVal
- End Function
- Public Function GetPacketStringLength(ByVal p_String As String) As Integer
- Dim ch As Char
- Dim totalCount As Integer
- For Each ch In p_String
- If ch = " " Then
- totalCount = totalCount + 1
- End If
- Next ch
- 'Now, since theres no space at the end, lets add 1
- totalCount = totalCount + 1
- Return totalCount
- End Function
- Public Function BuildPacketFromString(ByVal p_String As String, ByVal p_Size As Integer) As Byte()
- Dim i As Integer
- Dim Packet(p_Size - 1) As Byte
- For i = 0 To p_Size - 1
- Packet(i) = System.Convert.ToInt32(Split(p_String, " ")(i), 16)
- Next
- Return Packet
- End Function
- Public Function BuildACK(ByVal Packet() As Byte) As Byte()
- Dim ACK(1) As Byte
- ACK(0) = 0
- ACK(1) = &H15
- ACK = AppendPacket(ACK, Packet)
- ACK = AppendPacket(ACK, New Byte() {0, 0, 0}) 'CRC+COMP
- Return ACK
- End Function
- Public Function BuildOK() As Byte()
- Dim OK(8) As Byte
- OK(0) = 1
- OK(1) = 0
- OK(2) = &HAF
- OK(3) = &HF9
- OK(4) = &H6C
- OK(5) = &HA1
- OK(6) = 0
- OK(7) = 0
- OK(8) = 0
- Return OK
- End Function
- Public Function BuildNetStatusReply(ByVal Data As Byte()) As Byte()
- Dim NetStatusReply(3) As Byte
- NetStatusReply(1) = 8
- NetStatusReply(2) = Data(2)
- NetStatusReply(3) = Data(3)
- ReDim Preserve NetStatusReply(40) 'blank after client tickcount return works
- Return NetStatusReply
- End Function
- Public Function BuildSessionResponse(ByVal Packet() As Byte) As Byte()
- Dim SessionID(17) As Byte
- Dim i As Integer
- For i = 0 To 16
- SessionID(i) = System.Convert.ToInt32(Split(p_SessionResponse, " ")(i), 16)
- Next
- SessionID(2) = Packet(6) 'SESSIONID
- SessionID(3) = Packet(7) 'SESSIONID
- SessionID(4) = Packet(8) 'SESSIONID
- SessionID(5) = Packet(9) 'SESSIONID
- SessionID(6) = 222 'CRCSEED
- SessionID(7) = 173 'CRCSEED
- SessionID(8) = 186 'CRCSEED
- SessionID(9) = 190 'CRCSEED
- Return SessionID
- End Function
- Public Function BinaryToHexSP(ByVal Data() As Byte) As String
- Dim retVal As String = "", tmpHex As String = ""
- For i As Integer = 0 To Data.Length - 1
- tmpHex = Hex(Data(i))
- If tmpHex.Length = 1 Then
- tmpHex = "0" & tmpHex
- End If
- retVal &= tmpHex & " "
- Next
- Return retVal
- End Function
- Function rght(ByVal text As String, ByVal val As Long) As String
- rght = Mid(text, Len(text) - val, val + 1)
- End Function
- Public Function Randomizer(ByVal iStart As Integer, ByVal iEnd As Integer) As Integer
- 'Function To Get a Random Number between # and #
- Dim iRandomValue As Integer
- Randomize()
- iRandomValue = iStart + (Rnd() * (iEnd - iStart))
- Return iRandomValue
- End Function
- Public Function RandomizerSingle(ByVal iStart As Single, ByVal iEnd As Single) As Single
- 'Function To Get a Random Number between # and #
- Dim iRandomValue As Single
- Randomize()
- iRandomValue = iStart + (Rnd() * (iEnd - iStart))
- Return iRandomValue
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement