News:

Who uses forums anymore?

Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Smarter

#1
General Programming / Re: [C#] Packet Buffer & Parser
December 09, 2006, 12:12:25 AM
Ok, i'm stumped, my buffer is like empty, always, no idea why, sorry for all the help ?'s but I'm eager to get this to work!:

        public void OnConnect()
        {
            sckBNET = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sckBNLS = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sckBNET.Connect("useast.battle.net", 6112);
            sckBNLS.Connect("bnls.valhallalegends.com", 9367);
            //watch for data ( asynchronously )...
            AddC("[BNLS]: Connecting...");
            AddC("[BNET]: Connecting...");
            if (sckBNET.Connected == true)
            {
                AddC("[BNET]: Connected.");
            }
            if (sckBNLS.Connected == true)
            {
                AddC("[BNLS]: Connected.");
            }
            DataBuffer x0 = new DataBuffer();
            x0.InsertByte(0);
            byte[] x = x0.GetData();
            sckBNET.Send(x);
            DataBuffer buf = new DataBuffer();
            int procid = 0;
            buf.InsertInt32(procid);
            string platformid = "IX86";
            buf.InsertDwordString(platformid);
            string productid = "PXES";
            buf.InsertDwordString(productid);
            byte version = 0xCF;
            buf.InsertByte(version);
            buf.InsertInt32(0);
            buf.InsertInt32(0);
            buf.InsertInt32(0);
            buf.InsertInt32(0);
            buf.InsertInt32(0);
            buf.InsertCString("USA");
            buf.InsertCString("United States");
            byte[] p50 = buf.GetData();
            sckBNET.Send(p50);
            AddC("C > S - 0x50 SID_AUTH_INFO!");
            WaitForData();
           
        }

public void WaitForData()
        {
            // now start to listen for any data...
            m_asynResult = sckBNET.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, pfnCallBack, null);
            m_asynResult2 = sckBNLS.BeginReceive(bnlsbufr, 0, bnlsbufr.Length, SocketFlags.None, pfnCallBack2, null);
            if (pfnCallBack == null)
                pfnCallBack = new AsyncCallback(OnDataReceived);
            //if (pfnCallBack2 == null)
            //    pfnCallBack2 = new AsyncCallback(OnDataReceived);
           
        }

public void OnDataReceived(IAsyncResult asyn)
        {
            int len = BitConverter.ToInt16(buffer, 2) - 4;
            byte[] data = new byte[512];
            if (len < 0)
            {
                sckBNET.Receive(buffer, 0, SocketFlags.None);
            }
            HandlePacket(buffer[1], data, len);
            //end receive...
            int iRx = 0;
            iRx = sckBNET.EndReceive(asyn);

            WaitForData();
        }


There's my socket stuff....?
#2
General Programming / Re: [C#] Packet Buffer & Parser
December 08, 2006, 08:38:19 PM
Any idea why?
#3
General Programming / Re: [C#] Packet Buffer & Parser
December 08, 2006, 07:01:26 PM
public void OnDataReceived(IAsyncResult asyn)
        {
            int len = BitConverter.ToInt16(buffer, 2) - 4;
            byte[] data = new byte[len];
            if (len < 0)
            {
                // sckBnet.Read(data, 0, len, SocketFlags.None);
                sckBNET.Receive(data, 0, len, SocketFlags.None);
            }
            HandlePacket(buffer[1], data, len);

            //end receive...
            int iRx = 0;
            iRx = sckBNET.EndReceive(asyn);

            WaitForData();
        }


I get an error stating: byte[] data = new byte[len]; - Arithmetic operation resulted in an overflow., help! lol
#4
General Programming / Re: [C#] Packet Buffer & Parser
December 08, 2006, 01:30:18 PM
Well, i figured all that out, and made the socket use a ASync connection, but now my problem is implementing BNLS into my project... it confuses me... I got the data to buffer and all that great stuff, the project just needs it's 0x51 C>S ... using BNLS, any help on that? lol I hate asking for help >.<.
#5
General Programming / Re: [C#] Packet Buffer & Parser
December 08, 2006, 09:35:32 AM
Gah see, i always don't know the simplest thing, i've been at it for 2 days now, cannot figure out how to get the data into the Buffer array.. >.<.... also Socket doesn't have a .Read method ...? I must be doing something wrong here...! >.<
#6
General Programming / Re: [C#] Packet Buffer & Parser
December 08, 2006, 09:09:17 AM
Did I ever mention I love you, and about 20 minutes after I posted that I started talking with a C# developer friend of mine who told me the only help he would give me is to use TCPClient();, but Socket you say to use, so i'll be sure to use that! Thanks so much, if i ever actually finish my program, you will be credited everywhere possible! Ok, and one other thing, so MBNCSUtil, is just a buffer, so I still have to make a Parser? Or does that have a sexy part for that too, cause in VB that was the part I really blew with, parsing the data... I could make the packets up, etc, but couldn't parse it.. always had to get help.
#7
Trash Can / Re: [C#] Packet Buffer & Parser
December 07, 2006, 06:25:55 PM
A person who's AKA has been Smarter since he was 12.
#8
General Programming / Re: [C#] Packet Buffer & Parser
December 07, 2006, 12:57:43 PM
        private void sckBNET_DataArrival(long bytesTotal, object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e)
        {
            BncsPacket BNCSPacket = new BncsPacket();
            BncsReader BNCSRead = new BncsReader();
            BNCSPacket.Count();
        }

After playing with it a bit, it seems to make some sense, but how do you get the data arriving into the buffer, and use it, etc. Is there a C# Bot source out that I could learn this from?
#9
General Programming / Re: [C#] Packet Buffer & Parser
December 07, 2006, 11:14:24 AM
I've had MBNCSUtil, since I started learning C#, and it seems and I was told that it is hard to use.
#10
General Programming / Re: [C#] Packet Buffer & Parser
December 06, 2006, 08:21:30 PM
Well, both actually, I want to learn through conversion, and i just "want it to work" heh. Could you link me ot the C# pbuffer you speak of?
#11
General Programming / Re: [C#] Packet Buffer & Parser
December 06, 2006, 08:01:23 PM
The originall what?
#12
General Programming / [C#] Packet Buffer & Parser
December 06, 2006, 07:49:20 PM
I'm attempting to convert:
Static strBuffer As String
Dim strTemp As String, lngLen As Long
Winsock1.GetData strTemp, vbString
strBuffer = strBuffer & strTemp
While Len(strBuffer) > 4
    lngLen = Val("&H" & Login.StrToHex(StrReverse(Mid(strBuffer, 3, 2))))
    If Len(strBuffer) < lngLen Then Exit Sub
    Login.ParsePacket Left(strBuffer, lngLen)
    strBuffer = Mid(strBuffer, lngLen + 1)
Wend


and
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, 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(PacketID As Byte)
Dim PacketData As String, Packet As String
If Form1.Winsock1.State <> sckConnected Then: Exit Function
Form1.Winsock1.SendData Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(Buffer) + 4) & Buffer
Clear
End Function






From VB > C#, It's proving quite the challange for me, as I am still learning C#, any help would be greatly appreciated.