Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: aton on May 01, 2005, 05:47 AM

Title: starcraft in-game protocol
Post by: aton on May 01, 2005, 05:47 AM
hi!
(sorry if this is the wrong place for what i am posting.. i am coding c only thats why i post here)

i am looking for information about the starcraft in-game protocol, like packets that move units, packets that make buildings, packets that change mineral count etc.

if anyone has any information, i'd greatly appreciate that.
(i have been sniffing a long time now, and its getting on my nerves)

thanks in advance,

aton
Title: Re: starcraft in-game protocol
Post by: aton on May 01, 2005, 10:12 AM
what i have so far is at http://aton.skillzenmasse.de/packet.txt
it might be wrong, i will update it constantly. please tell me if you have any idea/data thats more correct than mine.
Title: Re: starcraft in-game protocol
Post by: UserLoser. on May 01, 2005, 04:23 PM
Quote
                  player string        '\0'
                  |                    |
0030  00 00 00 00 55 72 7A 61 68 69 6C 00 50 58 45 53    ....Urzahil.PXES

      |- these are probably version info etc.
0040  20 30 20 30 20 31 20 30 20 30 20 30 20 30 20 30     0 0 1 0 0 0 0 0
         "SEXP" starcraft expansion
          |            '\0'
          |              |
0050  20 50 58 45 53 00                                   PXES.


That's just their battle.net account name and their statstring.  Statstring contains what product they're using, wins, rating, rank, high rank, rating, high rating, spawn, icon etc.

Edit: eww at bnetd stuff at bottom
Title: Re: starcraft in-game protocol
Post by: aton on May 01, 2005, 04:28 PM
do you know what field means what exactly? i think i can find out the wins/losses but not the icon for example
Title: Re: starcraft in-game protocol
Post by: UserLoser. on May 01, 2005, 04:32 PM
Quote from: aton on May 01, 2005, 04:28 PM
do you know what field means what exactly? i think i can find out the wins/losses but not the icon for example


Icon is last part, in this case, 'SEXP'.

Document on user statstrings (http://bnetdocs.valhallalegends.com/content.php?Section=d&id=16)
Title: Re: starcraft in-game protocol
Post by: aton on May 01, 2005, 04:38 PM
thanks, i updated the file.

you dont have any information on "click" packets (or do i better call them "movement" packets?), have you?

as i understand only the player actions are transmitted over the net, i.e. when a player moves a unit, or builds a building, correct?

edit: btw has anyone got an outline of how the udp checksum is created? i am into linux and cannot really debug in windows very well...  just a description of the algorithm would be sufficient, i'd write my own routine...
Title: Re: starcraft in-game protocol
Post by: l)ragon on May 01, 2005, 07:36 PM
your first ?.?.? in the statstring = the persons ladder rank it will only show up if they are ranked on the list eg. #1 - #1000.
Title: Re: starcraft in-game protocol
Post by: Adron on May 01, 2005, 09:31 PM
Only player actions are transmitted yes. Say, when a player queues up a building or unit to be built.

The udp checksum is something like a loop summing the packet. The data in the packet is summed into one accumulator, and that accumulator is summed into another one.
Title: Re: starcraft in-game protocol
Post by: aton on May 02, 2005, 10:47 AM
so each byte is summed together? i.e. longer packets -> bigger checksum? sounds too easy for my taste  ;)
do you have the assembly routine for it?
Title: Re: starcraft in-game protocol
Post by: R.a.B.B.i.T on May 02, 2005, 11:52 AM
I've got the VB6 code here, which I ported from C++ with Pianka (that code I can't find, but is on the forums somewhere).  It should be easy enough to port it back if you can't find the original code.


Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (ByRef Destination As Any, ByRef Source As Any, ByVal numBytes As Long)

Private Function UDPChecksum(ByRef bufa As String) As Single
    Dim subsum As Double
    Dim A As Double
    Dim B As Single
    Dim buf As Long
   
    buf = MakeLong(bufa)
   
    subsum = SubChecksum(buf + 2, buf - 1)

    A = &HFF - ((subsum And &HFF) + (subsum Xor 8)) Mod &HFF
    B = CSng(((&HFF - (A + (ShiftRight(subsum, 8))) Mod &HFF) And &HFF) Or (ShiftLeft(A, 8)))
   
    UDPChecksum = B
End Function

Private Function SubChecksum(ByRef buf As Long, length As Long) As Currency
    Dim sum1 As Double
    Dim sum2 As Double
    Dim p As Long
   
    sum1 = sum2 = 0
   
    p = buf And (length - 1)
    While length - 1 > 0
        sum2 = sum2 + p
        p = p - 1
        If sum2 > &HFF Then sum2 = sum2 - &HFF
        sum1 = sum1 + sum2
        length = length - 1
    Wend
   
    SubChecksum = ((sum2 And &HFF) Xor 8) Or ((sum1 Mod &HFF) And &HFF)
End Function

Private Sub Form_Load()
    Debug.Print UDPChecksum(1234)
End Sub

Public Function ShiftRight(ByVal A As Long, ByVal L As Long) As Double
    ShiftRight = CDbl(A / (2 ^ L))
End Function

Public Function ShiftLeft(ByVal A As Long, ByVal L As Long) As Double
    ShiftLeft = CDbl(A * (2 ^ L))
End Function

Private Function MakeLong(str As String) As Long
    CopyMemory MakeLong, ByVal str, Len(str)
End Function
Title: Re: starcraft in-game protocol
Post by: Adron on May 02, 2005, 12:20 PM
Does your VB6 code work?
Title: Re: starcraft in-game protocol
Post by: Eric on May 02, 2005, 02:39 PM
Quote from: Adron on May 02, 2005, 12:20 PM
Does your VB6 code work?

It looks as if it was just ported from your NBBot :p
Title: Re: starcraft in-game protocol
Post by: R.a.B.B.i.T on May 02, 2005, 04:01 PM
It was ported from some C++ code that someone asked about (if there was an equivolent of in VB6).  Nobody knew about any so that's why Pianka and I ported it.  Where ever the original code came from, I don't know, is where it was ported from.  So, maybe.
Title: Re: starcraft in-game protocol
Post by: aton on May 02, 2005, 07:17 PM
cool thanks, i will port that back to c, i think i gotta fresh up my vb a bit, has been quite a while...
Title: Re: starcraft in-game protocol
Post by: Banana fanna fo fanna on May 02, 2005, 07:55 PM
I think I was able to get into the pregame room, but that was it.
Title: Re: starcraft in-game protocol
Post by: Adron on May 02, 2005, 08:31 PM
Quote from: LoRd[nK] on May 02, 2005, 02:39 PM
Quote from: Adron on May 02, 2005, 12:20 PM
Does your VB6 code work?

It looks as if it was just ported from your NBBot :p

The reason I asked was it looked like an inaccurate nonworking port from NBBot :p
Title: Re: starcraft in-game protocol
Post by: aton on May 02, 2005, 08:47 PM
ok i will begin with writing a bot to login and get game listings etc. there should be enough info for that on the bnet docs
after that i will do some more years of sniffing ;)
Title: Re: starcraft in-game protocol
Post by: aton on May 04, 2005, 11:21 PM
btw i heard iago is doing some linux stuff... so iago how do you logon to b.net? have you written the hashing functions yourself or have you managed to use a .dll somehow? i cannot think of any way that could be done..
Title: Re: starcraft in-game protocol
Post by: Blaze on May 05, 2005, 07:10 AM
Was he using Java?
Title: Re: starcraft in-game protocol
Post by: Ban on May 05, 2005, 09:42 AM
it is more than possible to log onto battle.net with linux...

http://newds.zefga.net <- *poke*
http://www.javaop.com <- *poke*

Just avoid languages that are platform specific (Visual Basic, Basic, etc) and avoid any portions of the language, such as API calls, that would restrict it to a single operating system. Both of the above links are links to open source bots, so if you are interested in how to connect to battle.net using *nix, take a look if it suits you.
Title: Re: starcraft in-game protocol
Post by: aton on May 08, 2005, 02:41 PM
ok solved it, thanks
Title: Re: starcraft in-game protocol
Post by: aton on May 09, 2005, 05:39 AM
now the problem is the udp checksum. does anyone have it in c/c++ ?
Title: Re: starcraft in-game protocol
Post by: Ban on May 09, 2005, 09:40 AM
Please stop double posting.
Title: Re: starcraft in-game protocol
Post by: warz on May 09, 2005, 11:43 AM
This is his thread. Get out of his thread.
Title: Re: starcraft in-game protocol
Post by: aton on May 09, 2005, 12:26 PM
ah nevermind, he is right, i probably double posted, i am somewhat dizzy during the last days.
anyways i converted the vb functions to c, they work perfectly, thanks.