• Welcome to Valhalla Legends Archive.
 

Why do you do this?

Started by BaDDBLooD, August 29, 2004, 11:31 PM

Previous topic - Next topic

Arta

If you do that, make sure the spare bytes (not being used for the tag) are null. If you don't, you might end up with junk memory being sent as part of the clan tag. I'm not sure how VB stores strings so it might not be an issue but in a real language it certainly would ;)

BaDDBLooD

Why didn't i need to reverse it? =|
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.

Sorc.Polgara

#17
Quote from: BaDDBLooD on August 30, 2004, 01:00 AM
Actually in the bot i am looking at:



ServerToken = Val("&h" & StrToHex(StrReverse(Mid(Data, 9, 4))))



That makes no Sence to me.  Why don't you just use GetDWORD

wth... that StrToHex function looks weird.  Yeah it doesn't make sense to me either... "0" & strTemp


And what is this GetDWORD function? ^_^

shadypalm88

Quote from: BaDDBLooD on August 30, 2004, 02:39 AMWhy didn't i need to reverse it? =|
I'm not sure; I think you actually did need to at some point.

The reason you were having to reverse it in the first place is because of differences in the way your computer stores strings and DWORDS (or any integers that take up more than one byte).

Let's look at my "clan"'s tag, then, SO.  In hex, those 2 characters are:
53 4F53 = S, 4F = 0

Now SO is only 2 characters (bytes) long, but the DWORD field it will be going into is 4.  So, it must be padded with null characters.  (In VB, "SO" & vbNullChar & vbNullChar.)  Now we have:
53 4F 00 00
So far, so good.  You have a 4-character string representing "SO".  But if you send this to Battle.Net in one of the clan packets, it won't work.  This is due to a subtle difference in the way strings and numbers (i.e. DWORD's) are stored and interpreted by your computer: byte order.

All WORD's and DWORD's sent between you and Battle.Net are in little-endian order, which is the native order of Intel (x86) systems.  In this order, the least-significant byte comes first.  This can be a hard concept to wrap your head around, so instead think of the number 123,456,789.  If you used little-endian order, you would write it as 789,456,123.  Instead of writing the most-significant group (123) first, you write the least-significant group (789) first.  (The 123 group is more significant because it is the millions group, i.e. changing it to 124 changes the number as a whole by 1 million, but changing the 789 group to 790 only changes the number by 1.)

Only, instead of talking about groups of thousands, we're talking about bytes.  Strings are not stored in the same way.  Remember, you're the only one who's thinking of it as a string.  Battle.Net will interpret it as a DWORD.  Also remember that DWORD's are stored in the order opposite to what you would expect.  It expects to get the last "character" first, which is why you have to reverse it.

Indeed, when Battle.Net reports my clan to me, it appears like this (in hex):
00 00 4F 53
Doing CopyMemory, however, will NOT reverse it, and as you hopefully should understand by now, you have to.

(If anyone can explain this better, please do  ::))

UserLoser.

#19
Quote from: Kp on August 28, 2004, 04:26 PM
Quote from: MindArchon on August 28, 2004, 04:13 PMWhy is his IX68 reversed?

Intel chips are little endian.

Should answer your questions about it being "reversed".  

VB ex: CopyMemory(ReturnVal, ByVal "STAR", 4) will put 0x52415453 into ReturnVal.  That converted from hex to a readable string is "RATS"

shadypalm88

#20
Quote from: UserLoser. on August 30, 2004, 01:51 PMVB ex: CopyMemory(ReturnVal, ByVal "STAR", 4) will put 0x52415453 into ReturnVal.  That converted from hex to a readable string is "RATS"
strTest = "STAR"
CopyMemory lngTest, ByVal strTest, 4
Debug.Print Hex(lngTest) 'outputs 52415453
Debug.Print lngTest 'outputs 1380013139
Debug.Print Hex(1398030674) 'outputs 53544152
0x52415453 = "RATS" = (LSB order) 1398030674
0x53544152 = "STAR" = (LSB order) 1380013139

I must be missing something here, because I still don't understand how that works out.

BaDDBLooD

Ok... so if you have a String of 3 characters, and when you put them in order from least significant to most significant.  Wouldn't, at some point in time,  Battle.net NOT be able to see what tag your sending?
There are only two kinds of people who are really fascinating: people who know absolutely everything, and people who know absolutely nothing.