News:

Who uses forums anymore?

Main Menu

Logging to BNet in c/c++

Started by KrzaQ, April 13, 2007, 12:19:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

KrzaQ

Hey, its my first post here.

I am trying to write program that would log to bnet as Diablo II client (and sit in a game for two hours which is rather boring, but its not important now), and ,of course, I've spotted some problems.
Before you redirect me, I already found these docs mirrored here. It helped me a lot with login sequence, but there is nothing about "A=A.S" etc strings in packet from bnet. I've found some functions reffering to these strings in javaop source, but I don't understand them. Here is my question: does any of you know any tutorial about this? Or, is any of you willing to tell me what should I do to connect to bnet? Please, don't tell me to use BNLS, its slow and require sending cdkeys as plain text.

It would be also nice if you could show algorithm in pseudocode/c/c++ in easy format ;)

PS:  sorry for my english.

iago

The actual stuff you're talking about is CheckRevision. It's recently been changed on older games (Starcraft and Warcraft 2), but I believe Diablo 2 is still the older version.

The code in CheckRevision.java would be a good place to start, or search for other implementations of CheckRevision, I know there's a few.

Good luck!

KrzaQ

I really hope its not a stupid question. I've tried to understand how this algorithm works and i think I'm close to, but I don't know where do you get String[] files, int mpqNum from.
(in CheckRevision.java)

Thanks in advance.

iago

Each game has three important files that are used. Starcraft uses Starcraft.exe, Storm.dll, and Battle.snp. Diablo 2, I believe, uses Diablo2.exe, storm.dll, and bnclient.dll. But I don't remember which order they're in, and I'm not positive that those are the right ones, there should be a file called Diablo2.java somewhere that lists them.

KrzaQ

        games.getWrite("D2XP", "File1", prefix + "D2XP/Game.exe");
        games.getWrite("D2XP", "File2", prefix + "D2XP/Bnclient.dll");
        games.getWrite("D2XP", "File3", prefix + "D2XP/D2Client.dll");

I guess these are files you meant.  (found here)

If so, Check.Revision.javas "files.length" is always 3 (for now, at least) and, for Diablo2
string files[] = "D2XP/Game.exe" "D2XP/Bnclient.dll" "D2XP/D2Client.dll"; is exactly what I need.

Alsio, I am not sire what is "String versionString" needed in CheckRevision function. Is it "D2XP" or version hash or...

Its first time I am doing something that big and complicated, if there was no Open Source bnet bot I would probably give up.

iago

Yeah, those are the three files you need, and everything else is in the CheckRevision() function. The algorithm isn't really that complicated, once you understand it.

KrzaQ

#6
I hope its ok right now:

public static int checkRevision(String versionString, String[] files, int mpqNum) throws FileNotFoundException, IOException

Thats string i got by logging today in the morning.
[some non writable chars before]ver-IX86-3.mpqC=3463600698 B=817405548 A=2386379605 4 A=A^S B=B-C C=C+A A=A^B

Just tell me if am I right:
versionString = C=3463600698 B=817405548 A=2386379605 4 A=A^S B=B-C C=C+A A=A^B;
files = these 3 i mentioned before
mpqNum = 3; <-- ?

thanks alot!

edit:

I also don't know what exactly is done here:
            File currentFile = new File(files[i]);
            int roundedSize = (int)((currentFile.length() / 1024) * 1024);

            MappedByteBuffer fileData = new FileInputStream(currentFile).getChannel().map(FileChannel.MapMode.READ_ONLY, 0, roundedSize);
            fileData.order(ByteOrder.LITTLE_ENDIAN);

and how to write it in c/cpp.

I guess (oh, theres nothing to guess, its too simple) first two lines give me rounded file size in kB but I don't have a clue whats done in lines #3 and #4 :/

iago

The last two lines set up the file to be used like an array. It's not necessary, it's an optimization. You should be able to figure out how it works without those lines.

And yes, you have those values right.

KrzaQ

#8
I have found some info here and here, it tells me nothing tho.

Would this arrat look so:
[type] filedata[roundedsize*1024] = load this_file;

Then, changing byteorder to Little Endian seems to be quite important.

and, I hope last question for this algorithm:
int s = fileData.getInt(j);
Does it just get  4 bits value as int? (and if byte order is reverted, its getting values from last to first, yep?)

edit:
        crCache.put(versionString + mpqNum + files[0], new Integer(c));
       
        return c;

Whats returned?

iago

Don't worry about crCache, it's useless.

The variable "c" is returned. Duh?

All it's doing is looping through the three files, and putting each byte of the file into the "s" variable, and doing mathematical operations on a, b, c, and s.

KrzaQ

#10
I think i have my code almost done, but I am not sure.
could you tell me proper "c" value for this string received:
ver-IX86-3.mpqC=3463600698 B=817405548 A=2386379605 4 A=A^S B=B-C C=C+A A=A^B

I hoped its not that complicated :/

If proper result is sent as 0x51 response then my code is wrong :/

(my code returned 0x87 84 9E 77 22 3C 4D 7A )

edit:
after few modifications (some stpid bugs) my code returns 28 9D 9D EB 82 CA E1 54

iago

I don't have code handy that can do it. If anybody else wants to field, I'd appreciate it.

Hdx

Version 1: 0x0faf5346
Version 2: 0x0faf5346
Yay for no padding needed :P
~Hdx
http://img140.exs.cx/img140/6720/hdxnew6lb.gif
09/08/05 - Clan SBs @ USEast
[19:59:04.000] <DeadHelp> We don't like customers.
[19:59:05.922] <DeadHelp> They're assholes
[19:59:08.094] <DeadHelp> And they're never right.

KrzaQ

Quote from: HdxBmx27 on April 17, 2007, 07:12:27 PM
Version 1: 0x0faf5346
Version 2: 0x0faf5346
Yay for no padding needed :P
~Hdx
If thats right (and I suppose it is) my code doesn't work :/

KrzaQ

I have some questions:

fileData.order(ByteOrder.LITTLE_ENDIAN);
Does whole code get reverted? Or just partially?
Lets say I have file with "ABCDEFGH" data (  0x 41424344 45464748 )
What do I receive after conversion?
Maybe:
"HGFEDCBA" or "DCBAHGFE" or "BADCFEHG" ?

Also, the code seems to be wrong in one part:
     * weird version strings that Battle.net would never send.  Battle.net's version strings are _always_ in the form:
     * A=x B=y C=z 4 A=A?S B=B?C C=C?A A=A?B:


Actually bnet is sending e=x f=y g=z 4 A=A?S B=B?C C=C?A A=A?B where e f g are A B C in random order.
Which value do i hash? Which one do i return?