Valhalla Legends Forums Archive | Battle.net Bot Development | [Python] MakeDWORD

AuthorMessageTime
Yegg
Ok, I am currently trying to make a bot in Python and I've actually gotten quite a lot added to it. My main problem is that when I come to adding the parts that a normal battle.net packetbuffer would have, I can't add MakeDWORD. As far as I know the way Visual Basic 6 does MakeDWORD cannot be converted into Python. I tried getting help on this topic at forums.devshed.com, only no one there is good with battle.net and the only help someone could give me was to come here (which I've been here many times before). Does anyone know how to make a working MakeDWORD code in Python?
December 5, 2004, 11:52 PM
BaDDBLooD
Try asking how to convert a 32 bit integer into a string.
December 6, 2004, 12:20 AM
St0rm.iD
Actually, you almost have a complete packet buffer included with Python: the struct module. Please see here:

http://docs.python.org/lib/module-struct.html

That should do most of the work for you for a packet buffer, but I'll also provide your makedword function in case that would be easier/better for you:

[code]
import struct

def make_dword(n):
    "convert a number to an unsigned double word"
    return struct.pack("< I", n)

def get_dword(buf):
    "get the first dword in the buffer"
    return struct.unpack("< I", buf[:4])[0]
[/code]

EDIT: spaced out the code to make it more readable
December 6, 2004, 1:19 AM
Yegg
Lol. After Baddblood posted and i went back down to the other forums, the admin there also told me about struct, he obviously gave a different example but they are both the same things. Since you seem to know about it, will the following code work:
[code]    def MakeDWORD(value):
        MakeDWORD = MakeDWORD()
        return struct.pack(result, value, 4)[/code]

Result being the string and value being long, as it is said in Visual Basic. As for the 4, I'm not sure if the 4 is needed, because in VB6 MakeDWORD has an interger of 4, and MakeWORD has an integer of 2, because of this I'm assuming those intergers will be needed?  I just have no clue how to place the interger if it is needed. Post back whenever you can.
December 6, 2004, 11:11 PM
St0rm.iD
Ew, that code is horrible....it absolutely will not work at all.

What's wrong with the code I posted? It outta work. What are you trying to do?
December 7, 2004, 12:29 AM
St0rm.iD
[quote author="Yegg"]
I just had a quick question about this. Where you have the code,
[code]def make_dword(n):
    "convert a number to an unsigned double word"
    return struct.pack("< I", n)[/code]

I'm a little confused on what the <, the I and the n do. Can you just clarify what each of these are, because in VB6 there is an interger, string, and long. I wan't to understand your code so I can use it later on without having to ask questions. Thanks.
[/quote]

The "n" is the argument you passed to the function.

Read the module docs! They'll tell you that:
- < means little-endian byte order
- I means an unsigned, double word (dword)
December 8, 2004, 3:22 AM
Yegg
Sorry to bring this topic back up, but, if MakeDWORD uses I for long, then would this mean that MakeWORD uses H? Or do I only need MakeDWORD and not MakeWORD? Also, for GetDWORD, is the argument for that buf,
December 11, 2004, 12:05 AM
St0rm.iD
MakeWORD would use H, yes.
December 13, 2004, 1:10 AM

Search