• Welcome to Valhalla Legends Archive.
 

[Solved]D2 Game Server Packets

Started by Ringo, May 05, 2005, 02:20 PM

Previous topic - Next topic

Ringo

Hi, iv currently spent alot of time logging d2 game server packets trying to make sence of incoming ones - but got driven mad.
Then common sence kinda hit me in the face and i thought i would ask here to see if anyone has a ported VB version of this:
http://forum.valhallalegends.com/phpbbs/index.php?topic=585.0
Or is there a .dll that can decompress the packets?
Iv been really stuck and confused with this for the past week and really need some info - i have looked through the forum and found "1.10" tables posted by smoke (i cant rememebr the link) and was wundering if them tables (in the above link) will still work for the current d2 patch?

Any help/info on decompressing the packets would be great!

Thanks in advance!

[edit]
Thanks everyone!
dll for d2 ingame decompression: D2GS.dll

Blaze

If it still works, why not just compile that code as a C++ dll?
Quote
Mitosis: Haha, Im great arent I!
hismajesty[yL]: No

Ringo

#2
Quote from: Blaze on May 05, 2005, 02:27 PM
If it still works, why not just compile that code as a C++ dll?
Because i dont have any c++ programing software or know any c/c++ :(

[edit]
Is it possible somone could do this for me? that would great thanks!

Yegg

I myself only know a little bit of C/C++. But if you take time to actually look at the code, you can figure out what some of it is doing. If you desperately need the proper code, but not in C++, you should just study C++ for a little while, so that you understand what the code is doing and how you can convert it to another language (Visual Basic 6?).

Ringo

#4

Public Function GamePacketSize(data As String, size As Integer, offset As Integer) As Integer

    Dim a As Long 'String  ?

    If Len(data) < Chr(&HF0) Then
        size = Len(data) - 1
        offset = 1
        GamePacketSize = 1
        End Function
   End If
   'a = data & chr(&HF) << 8 /left shift?
   a = CDbl(data & Chr(&HF) * (2 ^ 8))
   size = Asc(a) + Len(data) - 2
   offset = 2
   'return &data[2];
   GamePacketSize = 2
End Function
Public Function GamePacketDecode(indata As String, insize As Integer, outdata As String, outmax As Integer, outsize As Integer)
'int GamePacketDecode(unsigned char *indata, unsigned int insize,
'                    unsigned char *outdata, unsigned int outmax,
'                    unsigned int *outsize)
'{
   Dim a, b, c, d As Integer
   Dim maxcnt, index As Integer
   Dim cnt As Long
   Dim outptr, inptr As String
   Dim size As Integer

   b = 0

   size = insize
   inptr = indata
   maxcnt = outmax
   outptr = outdata
   cnt = &H20  'long?

   'while (1) { 'size > 1?

       If cnt > &H8 Then
           While (size > 0 And cnt > &H8)
               cnt = cnt - &H8
               'size--;
               'a = *inptr++ << cnt;
               'b |= a;

           Wend
       End If

       index = CharIndex(CDbl(b \ (2 ^ &H18)))
       a = CharTable(index)
       d = CDbl(b \ (2 ^ (&H18 - a))) & BitMasks(a)
       c = CharTable(index + 2 * (d + 2))

       cnt = cnt + c
       If cnt > &H20 Then
           outsize = outmax - maxcnt
           GamePacketDecode = 1
           End Function
       End If

       'if (maxcnt-- == 0)
       '    return 0;
           'GamePacketDecode = 0
           
       a = CharTable(index + 2 * (d + 1))
       '*outptr++ = (unsigned char)a;

       'b <<= (c & 0xFF);
   '}

   'assert(0);
   'return 0;
'}
End Function

i cant do it... my head is gonner go bang, iv tryed for to many days now.

[edit]
iv tryed restarting a few times, iv tryed looking at the c++ code vs packet log data to try and figger out what byte shift operations are taking place.
I can only guess what some of that code above means..
beleave me i have tryed.

Yegg

Can you re-post the code, but show which is VB6 and which is C++? You seem to have added notes in the VB6 code of C++ code you wern't sure of, that sort of threw me off. Also, << is left shift and >> is right shift for bit shifting. You can probably find the code to an LShift function and an RShift function in VB6, many bots have them.

Ringo

(im probly not even close to right on what im doing here lol)
VB6:

Public Function GamePacketSize(data As String, size As Integer, offset As Integer) As Integer
    Dim a As Long
    If Len(data) < Chr(&HF0) Then
        size = Len(data) - 1
        offset = 1
        GamePacketSize = 1
        End Function
   End If
   a = CDbl(data & Chr(&HF) * (2 ^ 8))
   size = Asc(a) + Len(data) - 2
   offset = 2
   GamePacketSize = 2
End Function
Public Function GamePacketDecode(indata As String, insize As Integer, outdata As String, outmax As Integer, outsize As Integer) As Integer '?
   Dim a, b, c, d As Integer
   Dim maxcnt, index As Integer
   Dim cnt As Long
   Dim outptr, inptr As String
   Dim size As Integer
   
   b = 0
   size = insize
   inptr = indata
   maxcnt = outmax
   outptr = outdata
   cnt = &H20


       If cnt > &H8 Then
           While (size > 0 And cnt > &H8)
               cnt = cnt - &H8

           Wend
       End If

       index = CharIndex(CDbl(b \ (2 ^ &H18)))
       a = CharTable(index)
       d = CDbl(b \ (2 ^ (&H18 - a))) & BitMasks(a)
       c = CharTable(index + 2 * (d + 2))

       cnt = cnt + c
       If cnt > &H20 Then
           outsize = outmax - maxcnt
           GamePacketDecode = 1
           End Function
       End If

       a = CharTable(index + 2 * (d + 1))

End Function


c++:

unsigned char *GamePacketSize(unsigned char *data, unsigned int *size,
                             unsigned int *offset)
{
   unsigned int a;

   if (data[0] < 0xF0) {
       *size = data[0] - 1;
       *offset = 1;
       return &data[1];
   }

   a = (data[0] & 0xF) << 8;
   *size = a + data[1] - 2;
   *offset = 2;
   return &data[2];
}


int GamePacketDecode(unsigned char *indata, unsigned int insize,
                    unsigned char *outdata, unsigned int outmax,
                    unsigned int *outsize)
{
   unsigned int a, b, c, d;
   unsigned int maxcnt, index, cnt;
   unsigned char *outptr, *inptr;
   int size;

   b = 0;

   size = insize;
   inptr = indata;

   maxcnt = outmax;
   outptr = outdata;
   cnt = 0x20;

   while (1) {

       if (cnt >= 0x8) {
           while (size > 0 && cnt >= 8) {
               cnt -= 0x8;
               size--;
               a = *inptr++ << cnt;
               b |= a;
           };
       }

       index = CharIndex[b >> 0x18];
       a = CharTable[index];
       d = (b >> (0x18 - a)) & BitMasks[a];
       c = CharTable[index + 2*d + 2];

       cnt += c;
       if (cnt > 0x20) {
           *outsize = outmax - maxcnt;
           return 1;
       }

       if (maxcnt-- == 0)
           return 0;

       a = CharTable[index + 2*d + 1];
       *outptr++ = (unsigned char)a;

       b <<= (c & 0xFF);
   }

   assert(0);
   return 0;
}

If i left anything out, Brand.X's code can be fouund here:
http://forum.valhallalegends.com/phpbbs/index.php?topic=585.0

Thanks inadvance for any weight you can lift off my sholders.

Ringo

#7
Hmm could somone please explain what these mean in VB6?

no idea what its basing a loop on here...

while (1) {


Size somthing..

'size--;


a = somthing inptr left shift cnt?

a = *inptr++ << cnt;



b |= a;

b = b Xor a?

if maxcnt somthing somthing 0 then

if (maxcnt-- == 0)


outputr somthing = somthing a?

outptr++ = (unsigned char)a;


Not sure how its leftshifting b

b <<= (c & 0xFF)


Also if somone could say if the guess's iv taken (below) are anything close to what they really mean in c/c++ ?

thanks

[edit]
Attempt #128409 to make sence of it


Public Function GamePacketSize(data As String, size As Integer, offset As Integer) As Integer
    Dim a As Long
    If Len(data) < Chr(&HF0) Then
        size = Len(data) - 1
        offset = 1
        GamePacketSize = 1
        End Function
   End If
   a = LeftShift(data & Chr(&HF), 8)
   size = Asc(a) + Len(data) - 2
   offset = 2
   GamePacketSize = 2
End Function
Public Function GamePacketDecode(indata As String, insize As Integer, outdata As String, outmax As Integer, outsize As Integer) As Integer
   Dim a As Integer
   Dim b As Integer
   Dim c As Integer
   Dim d As Integer
   Dim maxcnt As Integer
   Dim index As Integer
   Dim cnt As Long
   Dim outptr As String
   Dim inptr As String
   Dim size As Integer
   b = 0
   size = insize
   inptr = indata
   maxcnt = outmax
   outptr = outdata
   cnt = &H20

'///while (1) {
       If (cnt > Chr(&H8)) Then
           While (size > 0 And cnt > Chr(&H8))
               cnt = cnt - &H8
        '///// size--; / no idea
        '///// a = *inptr++ << cnt;
        '///// b |= a;
           Wend
       End If
       index = CharIndex(RightShift(b, &H18))
       a = CharTable(index)
       d = RightShift(b, (&H18 - a)) & BitMasks(a)
       c = CharTable(index + (2 * d) + 2)
       cnt = cnt + c
       If (cnt > Chr(&H20)) Then
           outsize = outmax - maxcnt
           GamePacketDecode = 1
           Exit Function
       End If
'/////if (maxcnt-- == 0)
'/////     return 0;
       a = CharTable(index + (2 * d) + 1)
'///// *outptr++ = (unsigned char)a;

'///// b <<= (c & &HFF)
   '}
'///// assert(0);
'///// return 0;
'}
End Function
Private Function RightShift(ByVal Value As Long, ByVal Shift As Long) As Double
RightShift = CDbl(Value \ (2 ^ Shift))
End Function
Private Function LeftShift(ByVal Value As Long, ByVal Shift As Long) As Double
LeftShift = CDbl(Value * (2 ^ Shift))
End Function


MyndFyre

Quote from: Ringo on May 05, 2005, 06:05 PM
Hmm could somone please explain what these mean in VB6?

no idea what its basing a loop on here...

while (1) {

This is IMO bad programming style, but legal C.  It's essentially "while (true)".  There's a break statement inside somewhere.

Quote from: Ringo on May 05, 2005, 06:05 PM
Size somthing..

'size--;

Equivalent code: size = size - 1;  It's the decrement operator.

Quote from: Ringo on May 05, 2005, 06:05 PM
a = somthing inptr left shift cnt?

a = *inptr++ << cnt;

The value currently pointed to of the inptr array (pointers and arrays work identically in C) is left-shifted by the number of bits in the cnt variable.  The result is stored in "a".  Then, inptr points to the next element in the array.

Quote from: Ringo on May 05, 2005, 06:05 PM

b |= a;

b = b Xor a?
Close.  b = b Or a.  The Xor operator in C is ^

Quote from: Ringo on May 05, 2005, 06:05 PM
if maxcnt somthing somthing 0 then

if (maxcnt-- == 0)

The decrement operator again.  This is important: these unary (one-variable) operators can either be prefixed or postfixed.  This is an example of a prefixed operator: --maxcnt.  This is an example of a postfixed operator: maxcnt--.  As you can see, the code example you gave is postfixed.  If the operator is postfixed, the code evaluates the expression and then performs the operator's function; in this case, the expression (maxcnt-- == 0) returns false of all values except 0.  After that expression is evaluated, the value in maxcnt is decremented by 1.  If the operator is prefixed, the code performs the operator's function first, so the expression (--maxcnt == 0) would return false for all values except 1, because if maxcnt equalled 1, it would be decremented and then compared to 0.

Quote from: Ringo on May 05, 2005, 06:05 PM
outputr somthing = somthing a?

outptr++ = (unsigned char)a;

You misquoted that code.  There's an asterisk preceeding it:

*outptr++ = (unsigned char)a;

The array item that outptr currently points to is assigned the byte value (unsigned char is an 8-bit positive-only value) currently stored in the a variable.  Then the outptr variable is incremented to point to the next array item.

Quote from: Ringo on May 05, 2005, 06:05 PMNot sure how its leftshifting b

b <<= (c & 0xFF)

First, evaluate the expression (c & 0xff).  That is the and operator.  By ANDing c and 0xff, you're effectively limiting the range of values that the result can hold from 0 to 0xff.  b is then left-shifted by the number of values returned by the expression I just described.

Quote from: Ringo on May 05, 2005, 06:05 PM
[edit]
Attempt #128409 to make sence of it
Stop whining.  I highly recommend looking up a tutorial on pointers in C.  It'll help you make sense of the two pointer things you asked about.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Ringo

#9
Quote
Stop whining.  I highly recommend looking up a tutorial on pointers in C.  It'll help you make sense of the two pointer things you asked about.

Thanks for explaining what they mean!

Im not whining im being honest ;)

Also why do people think i want to learn c/c++ ?

Pointer things?

MyndFyre

Quote from: Ringo on May 05, 2005, 07:14 PM
Also why do people think i want to learn c/c++ ?
I didn't say you want to learn C/++.  I said you should learn enough of it to help you figure out how to translate the code, since that's what you're doing.  Pointers aren't an easy topic to learn.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Ringo

Nore is C :P

Im just kiddin with ya, thanks for your help, im gonner give it another go in a sec :)

MyndFyre

Quote from: Ringo on May 05, 2005, 07:18 PM
Nore is C :P

Nor is programming, but you're trying that, aren't you?

If you're not willing to help yourself, you will quickly find that others here will be increasingly unwilling to help you.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Ringo

#13
-_-?
I posted here as a last option but i think ur missing the point.
I dont ask for help unless i really cant see light at the end of the tunnle and iv tryed my hardest to do the task in hand :P

Read top post ;)
Or my log of total posts here at VL..

[edit]
damn what did i do to get a nice flaming like that :P
And what makes u think im "trying" to program?
lol :(

Ringo

Ok thats enough - my head just exploded.
cant somone just take 5 seconds to put it in a C dll?