Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Jaquio on July 19, 2005, 01:08 AM

Title: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 01:08 AM
I was wondering what would cause my bot to disconnect after sending the packet 0x3A, here is the code I am using.


Public Function Send_0x01()
Select Case UCase(DB.Product)
    Case "D2DV", "VD2D"
        DB.Product = "VD2D"
        VerByte = "09"
        Executable = "Game.EXE"
    Case Else
        AC vbRed, "Unknown Product"
        Form1.Winsock1.Close
        Exit Function
End Select
HashPath = App.Path & "\D2DV\"
Form1.Winsock1.SendData Chr(1)
AC &HFFFFC0, "Sent 0x01"
End Function

Public Function Send_0x50()
On Error Resume Next
Packet.InsertDWORD &H0
Packet.InsertNonNTString "68XI"
Packet.InsertNonNTString DB.Product
Packet.InsertDWORD "&H" & VerByte
Packet.InsertDWORD &H0
Packet.InsertDWORD &H0
Packet.InsertDWORD &H0
Packet.InsertDWORD &H0
Packet.InsertDWORD &H0
Packet.InsertNTString "USA"
Packet.InsertNTString "United States"
Packet.SendPacket &H50
AC &HFFFFC0, "Sent 0x50"
End Function

Public Function Send_0x51(Data As String)
Dim Hash As String, MPQName As String, TempData As String
Dim EXEInfo As String, version As Long, CheckSum As Long, Result As Long
Dim dblProdID As Double, dblValue1 As Double, dblValue2 As Double
Dim lngProdID As Long, lngValue1 As Long, lngValue2 As Long
Dim AccountHash As String, TempString As String, dblKey As Long
Dim Servers As String
Token = Mid(Data, 9, 4)
MPQName = Mid(Data, InStr(Data, "I"), 12)
Hash = Mid(Mid(Data, 34), InStr(Mid(Data, 34), Chr(0)) + 1, InStr(Mid(Mid(Data, 34), InStr(Data, Chr(0)) + 1), Chr(0)))
Hash = Replace(Hash, Chr(0), "")
EXEInfo = Space(256)
dblKey = GetTickCount()
If DB.Product = "VD2D" Then
    Result = z(HashPath & Executable, HashPath & "BNClient.DLL", HashPath & "D2Client.DLL", Hash, version, CheckSum, EXEInfo, MPQName)
Else
    Result = z(HashPath & Executable, HashPath & "Storm.DLL", HashPath & "Battle.SNP", Hash, version, CheckSum, EXEInfo, MPQName)
End If
NullTruncString EXEInfo
DecodeCDKey DB.CDKey1, dblProdID, dblValue1, dblValue2
lngProdID = CLng(dblProdID)
lngValue1 = CLng(dblValue1)
lngValue2 = CLng(dblValue2)
Servers = CLng(Val("&h" & StrToHex(StrReverse(Token))))
AccountHash = String(5 * 4, vbNullChar)
TempString = c(AccountHash, Servers, lngProdID, lngValue1, lngValue2, dblKey)
If Result = 0 Then
    AC vbRed, "Hashing Failed"
    Form1.Winsock1.Close
    Exit Function
End If
Packet.InsertDWORD dblKey
Packet.InsertDWORD version
Packet.InsertDWORD CheckSum
Packet.InsertDWORD &H1
Packet.InsertDWORD "&H0"
Packet.InsertDWORD Len(DB.CDKey1)
Packet.InsertDWORD CLng(dblProdID)
Packet.InsertDWORD CLng(dblValue1)
Packet.InsertDWORD &H0
Packet.InsertNonNTString AccountHash
Packet.InsertNTString EXEInfo
Packet.InsertNTString DB.Username
Packet.SendPacket &H51
AC &HFFFFC0, "Sent Username & Password. "
End Function

Public Sub Send_0x3A()
Dim PD As String
PD = String(7 * 4, vbNullChar)
Packet.InsertNonNTString PD
Packet.InsertNTString DB.Username
Packet.SendPacket &H3A
AC &HFFFFC0, "Sent 0x3A"
End Sub

Public Function Send_0x14()
Packet.InsertNonNTString "tenb"
Packet.SendPacket &H14
AC &HFFFFC0, "Sent 0x14"
End Function

Public Function Send_0x0A()
Packet.InsertNTString DB.Username
Packet.InsertBYTE 0
Packet.SendPacket &HA
AC &HFFFFC0, "Sent 0x0A"
Packet.InsertNonNTString DB.Product
Packet.SendPacket &HB
AC &HFFFFC0, "Sent 0x0B"
Packet.InsertDWORD 2
Packet.InsertNTString DB.Home
Packet.SendPacket &HC
AC &HFFFFC0, "Sent 0x0C"
AC &HC0FFFF, "Attempting To Flood Channel [", False, False, vbWhite, DB.Home, False, False, &HC0FFFF, "]"
End Function

Public Function ParsePacket(Data As String)
Dim PacketID As String
PacketID = Asc(Mid(Data, 2, 1))
Select Case PacketID
    Case &H25
        Form1.Winsock1.SendData Data
    Case &H1
        AC &HC0FFC0, "Received 0x01"
    Case &H50
        AC &HC0FFC0, "Received 0x50"
        Send_0x51 Data
    Case &H51
        AC &HC0FFC0, "Received 0x51"
        Send_0x3A
    Case &H3A
        AC &HC0FFC0, "Received 0x3A"
        'Send_0x14
        Send_0x0A
    'Case &H14
        'AC &HC0FFC0, "Received 0x14"
        'Send_0x0A
    Case &HA
        AC &HC0FFC0, "Received 0x0A"
    Case &HF
        DispatchMessage Data
End Select
End Function


After it sends 0x3A I get disconnected and ipbanned, it sucks lol. I did the result thing and it gave me "1" meaning the account don't exist but it does because I just logged onto it. Any idea, why?
Title: Re: Disconnect after 0x3a?
Post by: R.a.B.B.i.T on July 19, 2005, 01:10 AM
Yes.  Aside from that, you should use BnetDocs a bit more.  It seems you don't know how to debug either.  Google is a great resource.
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 01:15 AM
And I should be looking for what? Could be a little more help rabbit,  :(.
Title: Re: Disconnect after 0x3a?
Post by: PaiD on July 19, 2005, 01:15 AM
Hm your making a floodbot also. Good luck getting help

AC &HC0FFFF, "Attempting To Flood Channel [", False, False, vbWhite, DB.Home, False, False, &HC0FFFF, "]"
Title: Re: Disconnect after 0x3a?
Post by: MyndFyre on July 19, 2005, 01:30 AM
Quote from: Jaquio on July 19, 2005, 01:15 AM
And I should be looking for what? Could be a little more help rabbit,  :(.

I don't know... maybe an invalid packet sequence or structure?  That's a possible cause of a disconnect (protocol violation).

On that note, it looks like you are entirely off (http://bnetdocs.valhallalegends.com/content.php?Section=m&Code=367) on the structure of 0x3a.  Just throwin' that out there.
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 01:49 AM
Quote from: DueL on July 19, 2005, 01:15 AM
Hm your making a floodbot also. Good luck getting help

AC &HC0FFFF, "Attempting To Flood Channel [", False, False, vbWhite, DB.Home, False, False, &HC0FFFF, "]"



Kinda.. I am thinking about having it as an option to my bot. It will  be a chat/ops/flood bot.


Quote from: MyndFyre on July 19, 2005, 01:30 AM
Quote from: Jaquio on July 19, 2005, 01:15 AM
And I should be looking for what? Could be a little more help rabbit,  :(.

I don't know... maybe an invalid packet sequence or structure? That's a possible cause of a disconnect (protocol violation).

On that note, it looks like you are entirely off (http://bnetdocs.valhallalegends.com/content.php?Section=m&Code=367) on the structure of 0x3a. Just throwin' that out there.


Umm, ok thanks. I will look around and try to figure out how to fix it I guess... Oh yea, one question I am kinda new to all this wtf is a server token and client token? >.<
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 02:17 AM
Doulbe-posting not allowed I know but the modify button isn't working now, I have my client token thanks to bnet docs. But I don't know how to get my server token, can someone help me on this? Then how do I get my password hash for 0x3A also?
Title: Re: Disconnect after 0x3a?
Post by: MyndFyre on July 19, 2005, 02:27 AM
Quote from: Jaquio on July 19, 2005, 02:17 AM
Doulbe-posting not allowed I know but the modify button isn't working now, I have my client token thanks to bnet docs. But I don't know how to get my server token, can someone help me on this? Then how do I get my password hash for 0x3A also?

So, pretty much what you're saying is that, you have this code from someone else's work, and you want us to make it work for you?
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 02:35 AM
Quote from: MyndFyre on July 19, 2005, 02:27 AM
Quote from: Jaquio on July 19, 2005, 02:17 AM
Doulbe-posting not allowed I know but the modify button isn't working now, I have my client token thanks to bnet docs. But I don't know how to get my server token, can someone help me on this? Then how do I get my password hash for 0x3A also?

So, pretty much what you're saying is that, you have this code from someone else's work, and you want us to make it work for you?


No I only took send_0x3A and send_0x51 I am trying to get help to make it work. If you don't want to help me that is fine. I am just trying to learn all I can and find out what everything does and how to do it so I can someday make my own bot really. I am just trying to get the hang of it one day I will rewrite it all and them 2 functions won't be someone elses.
Title: Re: Disconnect after 0x3a?
Post by: Hdx on July 19, 2005, 06:31 AM
What I suggest. Is you get rid of any sources you currently have. And start everything with a clean slate. Then get testBNCS, and use that server to go packet by packet building your bot. Also Read ALL of BnetDocs.
If you would notice, the Client and Server tokens are blue, place your mouse over them to get s short description.

poke (http://bnetdocs.valhallalegends.com/content.php?Section=m&Code=3) S->C0x50 is where you get the Server token.

DO NOT use anycode that you did not write yourself and then 'rewrite it', I've done this, and it's jsut caused nothing but confussion.
Anyways:
Server Token: A 32-bit value determined by the server, used to inproved the security of the hashing functions. Can be retriend from 0x50, or 0x1D.
Client Token: A 32-Bit value determined by the client, used to inproved security of the hashing functions. Can be anything but 0 (I'm pretty sure). Many programmers use the Windows GetCurrentTime() API to get a valid value.
~-~(HDX)~-~
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 01:57 PM
Alright, I guess I can start fully from scratch considering I know I won't get very far with a bot anyways. This TestBNCS how exactly do I get it working? I followed the instructions but when it came to the part to use "bncsctl getfiles" it didn't because it said that command wasn't valid. Am I doing something wrong or what?
Title: Re: Disconnect after 0x3a?
Post by: Archangel on July 19, 2005, 02:18 PM
Theres a TestBNCS Forums, go check them :D.
Title: Re: Disconnect after 0x3a?
Post by: Warrior on July 19, 2005, 02:24 PM
The ServerToken is the second DWORD in SID_AUTH_INFO.

You also can't expect to get far withought _parsing_ the packets.
It seems you just recieve them and call the next packet in order.
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 02:26 PM
Thanks, but after  I get TestBNCS up and going. What do I do, packetlog a bot connecting to that server so I know what to do. Or write me back and get as far as I on connecting to my TestBNCS server? I am confused >.<, I had help from my friend John getting my bot now as far as it is.
Title: Re: Disconnect after 0x3a?
Post by: Warrior on July 19, 2005, 02:43 PM
BnetDocs has all the packet structures availible for you. You're going to need to write (or borrow an existing) class to store the contents of the packets in a buffer and send them in a specific order.

I usually only packetlog when I am stumped on something since BnetDocs is a great resource.

Np.
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 02:47 PM
I have a packet buffer, Then I am gonna have to rewrite the Send Packet codes and then maybe I will be able to do it. I am still kinda stumped on how to obtain the server and client token.. lol.
Title: Re: Disconnect after 0x3a?
Post by: Blaze on July 19, 2005, 02:48 PM
Maybe you should learn more about packets before you make a bot then..
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 02:51 PM
Meh! If I could just get past the connection code I could do just fine with the rest of it. I have no idea where to learn about BNet Packets or nothing, it sucks I have looked on google and only place I found was BNetDocs which has helped me alot already. Just I am missing 3 things to connect.. Password Hash,Client Token and Server Token. But I guess I can sit here for awhile at my computer until I get it.
Title: Re: Disconnect after 0x3a?
Post by: Blaze on July 19, 2005, 02:55 PM
Study this:

http://forum.valhallalegends.com/phpbbs/index.php?topic=9278.0
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 03:00 PM
Alright, thanks I found that very helpful I am gonna look at it some more and read alot of stuff on it. I guess I will be back here if I get stuck on something else, or the same damn thing. Thanks everyone for the help.
Title: Re: Disconnect after 0x3a?
Post by: MyndFyre on July 19, 2005, 05:51 PM
Quote from: Jaquio on July 19, 2005, 02:51 PM
If I could just get past the connection code I could do just fine with the rest of it.
Generally, you'll find people here who are willing to help if you want to learn how that works.  However, you won't find people who are particularly willing to just give it to you.  I believe that attitude is because, once you get it, it's *really* easy.

Look at it as an opportunity to learn something new.
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 06:37 PM
Quote from: MyndFyre on July 19, 2005, 05:51 PM
Quote from: Jaquio on July 19, 2005, 02:51 PM
If I could just get past the connection code I could do just fine with the rest of it.
Generally, you'll find people here who are willing to help if you want to learn how that works.  However, you won't find people who are particularly willing to just give it to you.  I believe that attitude is because, once you get it, it's *really* easy.

Look at it as an opportunity to learn something new.

Well yea I want to learn how it works, and I guess everyone is right you won't learn much about it if you take it from someone elses source or something. Maybe someone would be willing to give me a lot of hints to help me with this. Because right now I have no clue on some of these, right now this is what my bot looks like...


Public Username As String, Password As String, Server As String
Public Product As String, CDKey As String, CDKeyEXP As String
Public Trigger As String, HomeChannel As String, BotMaster As String
Private VerByte As String, Executable As String, HashPath As String
Private CToken As String, SToken As String

Public Function Send_0x01()
'0x01 Stuff Here
End Function

Public Function Send_0x14()
'0x14 Stuff Here
End Function

Public Function Send_0x50()
'0x50 Stuff Here
End Function

Public Function Send_0x51()
'0x51 Stuff Here
End Function

Public Function Send_0x0A()
'0x0A Stuff Here
End Function

Public Function Send_0x3A()
'0x3A Stuff Here
End Function

Public Function ParsePacket(Data As String)
Dim PacketID As String
PacketID = Asc(Mid(Data, 2, 1))
Select Case PacketID
'Gotta work on this once everything else is done
End Select
End Function


I am still working on it I am just now going to bnet docs to get the packet information. However I feel I will be stuck on the Client Token and Server Token again.. As well as the Password Hash if anyone wants to give me hints on this..
Title: Re: Disconnect after 0x3a?
Post by: Blaze on July 19, 2005, 06:54 PM
There are other datatypes other then string you know. ;)

Also everyone one of those "Functions" should be Subs.
Title: Re: Disconnect after 0x3a?
Post by: Jaquio on July 19, 2005, 07:07 PM
Quote from: Blaze on July 19, 2005, 06:54 PM
There are other datatypes other then string you know. ;)

Yea I know.. I am just not to sure what each of them strings are gonna end up to be until I debug it and choose the right datatype..

Quote from: Blaze on July 19, 2005, 06:54 PM
Also everyone one of those "Functions" should be Subs.

Even in a class file? I wasn't sure so I left them as functions..
Title: Re: Disconnect after 0x3a?
Post by: Warrior on July 19, 2005, 07:21 PM
My rule for Functions/Subs, if it isn't returning a value then make it a Sub.
Title: Re: Disconnect after 0x3a?
Post by: MyndFyre on July 19, 2005, 07:56 PM
Quote from: Warrior on July 19, 2005, 07:21 PM
My rule for Functions/Subs, if it isn't returning a value then make it a Sub.

Isn't that the point of the difference between functions and subroutines?
Title: Re: Disconnect after 0x3a?
Post by: R.a.B.B.i.T on July 19, 2005, 08:47 PM
Quote from: MyndFyre on July 19, 2005, 07:56 PM
Quote from: Warrior on July 19, 2005, 07:21 PM
My rule for Functions/Subs, if it isn't returning a value then make it a Sub.

Isn't that the point of the difference between functions and subroutines?
Yep.