Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Sixen on July 18, 2007, 12:25 AM

Title: [Vb] Trouble handling S->C 0x26 (D2GS)
Post by: Sixen on July 18, 2007, 12:25 AM
Alright, so I understand how to receive it, as I am doing so. My only problem is getting it's length for decompression. You need to have the Character name and the Chat Message, but i'm not exactly sure as to how I would go about "extracting" this information. If anyone would be so kind as to help.. And, if it makes any difference, i'm using DM's PacketBuffer, ^_^.
Title: Re: Trouble handling S->C 0x26 (D2GS)
Post by: Spht on July 18, 2007, 05:43 AM
Quote from: Sixen on July 18, 2007, 12:25 AM
Alright, so I understand how to receive it, as I am doing so. My only problem is getting it's length for decompression. You need to have the Character name and the Chat Message, but i'm not exactly sure as to how I would go about "extracting" this information. If anyone would be so kind as to help.. And, if it makes any difference, i'm using DM's PacketBuffer, ^_^.

Like the code I pasted for you on Battle.net illustrates, you have to measure the length of the name to know where to start reading the text, then you total that size up along with the other parts of the message for the final length

Let's say x is the position where the name starts, as i don't know where it is offhand, and data is your decompressed message beginning with the header

name = mid(data, x)

So if your name is sixen and the text is "hi there", name will now be "Sixen\0x0hi there\0x0" -- notice that name is null terminated, that's where the function nearestnull() comes in that you were confused about.  It returns a string up to its first null byte.  So to isolate the name, you'd do something like:

name = mid(data, x, instr(mid(data, x), vbnullchar)-1)

Next, you want to know the text, so it's the same deal, just that you're going to start reading where name ends [x+len(name)+1]

text = mid(data, x+len(name)+1, instr(mid(data, x+len(name)+1), vbnullchar)-1)

Nearestnull() just eliminates repetitive instructions which confuse readability of code so i can just do name = nearestnull(mid(data, x)): text = nearestnull(mid(data, x+len(name)+1))

So final length of the message is x+len(name)+1+len(text)+1