VB Packets Help ( Again :D )

08/29/2011 00:32 kevin_owner#16
That's cause you're printing it as a string. you should NEVER use a string when you're working with packets which are byte packed.

keep it as a byte array and use a binaryreader too read the packet.

about the printing part you could do something like this:
C#
Code:
string Packet = "";
for(int i = 0; i < inStream.Length; i++)
{
      Packet += string.Format("{0:X2} ", inStream[i]);
}
Convert to vb
Code:
Dim Packet As String = ""
For i As Integer = 0 To inStream.Length - 1
	Packet += String.Format("{0:X2} ", inStream(i))
Next
now you have the packet as a string but in hex.
Owh and I don't know if the vb part is correct I used a converter.
08/29/2011 00:45 DeXeee#17
Quote:
Originally Posted by kevin_owner View Post
That's cause you're printing it as a string. you should NEVER use a string when you're working with packets which are byte packed.

keep it as a byte array and use a binaryreader too read the packet.

about the printing part you could do something like this:
C#
Code:
string Packet = "";
for(int i = 0; i < inStream.Length; i++)
{
      Packet += string.Format("{0:X2} ", inStream[i]);
}
Convert to vb
Code:
Dim Packet As String = ""
For i As Integer = 0 To inStream.Length - 1
	Packet += String.Format("{0:X2} ", inStream(i))
Next
now you have the packet as a string but in hex.
Owh and I don't know if the vb part is correct I used a converter.
Thanks for helping, i will try it :) !!

I got a lot of "00 00 00 00 00 00" at the end :D
Maybe too much, for about 15k :D
Visual :
[Only registered and activated users can see links. Click Here To Register...]
08/29/2011 07:52 lesderid#18
Quote:
Originally Posted by DeXeee View Post
Thanks for helping, i will try it :) !!

I got a lot of "00 00 00 00 00 00" at the end :D
Maybe too much, for about 15k :D
Visual :
[Only registered and activated users can see links. Click Here To Register...]
Guess why SRO sends size.
08/29/2011 11:32 DeXeee#19
Tnx guys, i make it :)

Code:
Dim inStream(10024) As Byte
        Dim DataLength As Integer = Client.Receive(inStream)
        Client.Receive(inStream, 0, CInt(Client.ReceiveBufferSize), SocketFlags.None)

        Dim Packet As String = ""
        For i As Integer = 0 To inStream.Length - 1
            Packet += String.Format("{0:X2} ", inStream(i))
        Next
        Packet = Mid(Packet, 1, DataLength)
        MsgBox(Packet)
08/29/2011 11:41 InvincibleNoOB#20
Read the size only and then the rest of the packet
Client.Receive(tmpSize, 0, 2, 0);
//determine the actual size of the packet, if it is encrypted
Client.Receive(inStream, 2, actualSize+4, 0);
PWord(@instream.memory[0])^ = actualSize; //set the size
08/29/2011 12:26 kevin_owner#21
That is also a nice way too fix it InvincibleNoOb.

@DeXee the send and receive function also have a return value which is the amount of bytes send/received. so you could also use that one.
08/30/2011 01:00 InvincibleNoOB#22
The result of this function does not guarantee in any way that there's only 1 packet in the buffer.
08/31/2011 01:42 sarkoplata#23
I advise you using SilkroadSecurityApi , but still , if you wanna use diff. proxies , here you can apply what i posted on stealthex.
This code is written by GoneUp , my teacher when i was toooo beginner :)
You should create a class called "sPacket" first , add public objects there ( opcode , data , size etc.)
And you should start this with a thread , or your gui thread will freeze ^^
This was orginally written by GoneUp
Code:
Dim Recv as thread = new thread (addressof receiving)
recv.start()
Code:
Private Sub Receiving()
        Try
            Dim bytetoread As UInt16
            Do
                Dim Packet As New sPacket()
                Do
                    bytetoread = Client.Available
                    If bytetoread >= 6 Then
                        Dim buffer(6 - 1) As Byte
                        Client.Receive(buffer, 6, Net.Sockets.SocketFlags.None)
                        Packet.Lenght = BitConverter.ToUInt16(buffer, 0)
                        Packet.Opcode = BitConverter.ToUInt16(buffer, 2)
                        Packet.Direction = BitConverter.ToUInt16(buffer, 4)
                        Exit Do
                    Else
                        Threading.Thread.Sleep(10)
                    End If
                Loop
                Do 'it has a support to untck multiple packets too
                    bytetoread = Client.Available
                    If bytetoread >= Packet.Lenght Then
                        Dim buffer(Packet.Lenght - 1) As Byte
                        Client.Receive(buffer, Packet.Lenght, Net.Sockets.SocketFlags.None)
                        Packet.data = buffer
                        ParsePacket(Packet)
                        Exit Do
                    Else
                        Threading.Thread.Sleep(10)
                    End If
                Loop
            Loop
        Catch ex As Exception
        End Try

    End Sub
09/02/2011 17:25 lesderid#24
Case-insensitive code is so ugly.
09/02/2011 18:44 LastThief#25
Quote:
Originally Posted by lesderid View Post
Case-insensitive code is so ugly.
Code:
private void Receiving()
{
	try {
		UInt16 bytetoread = default(UInt16);
		do {
			sPacket Packet = new sPacket();
			do {
				bytetoread = Client.Available;
				if (bytetoread >= 6) {
					byte[] buffer = new byte[6];
					Client.Receive(buffer, 6, System.Net.Sockets.SocketFlags.None);
					Packet.Lenght = BitConverter.ToUInt16(buffer, 0);
					Packet.Opcode = BitConverter.ToUInt16(buffer, 2);
					Packet.Direction = BitConverter.ToUInt16(buffer, 4);
					break; 
				} else {
					System.Threading.Thread.Sleep(10);
				}
			} while (true);
			//it has a support to untck multiple packets too
			do {
				bytetoread = Client.Available;
				if (bytetoread >= Packet.Lenght) {
					byte[] buffer = new byte[Packet.Lenght];
					Client.Receive(buffer, Packet.Lenght, System.Net.Sockets.SocketFlags.None);
					Packet.data = buffer;
					ParsePacket(Packet);
					break;
		} else {
					System.Threading.Thread.Sleep(10);
				}
			} while (true);
		} while (true);
	} catch (Exception ex) {
	}

}
if you don't really like vb.net
09/02/2011 23:17 lesderid#26
Quote:
Originally Posted by LastThief View Post
if you don't really like vb.net
I never said I don't like VB.Net (I don't, though), just case-insensitive code written it.

Btw, that C# code isn't really great either.
09/03/2011 00:17 DeXeee#27
Hey guys, about HP, MP, MOB HP, current cord, golds, etc ... Can i get them with packets too ?
09/03/2011 01:10 sarkoplata#28
Quote:
Originally Posted by DeXeee View Post
Hey guys, about HP, MP, MOB HP, current cord, golds, etc ... Can i get them with packets too ?
If the thing you wanna get is shown in client , you can get it . Because client got it from packets , so yes you can.

@lesderid
It makes your life easier:p
09/03/2011 02:05 kevin_owner#29
@DeXee yes you can but sarkoplata already answerd your question

@sarkoplata
Quote:
It makes your life easier
I have to disagree. Sure for some people it can be easier but it makes it harder too switch to another lanuage. If you're used to not give variables the same it'll be harder to code in for example C#.