Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 5th, 2004, 04:02 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
MakeDWORD

Ok, this is one of my bigger problems with creating my application in Python. Someone tried helping me with this before showing me a way to do this through an array, only I didn't quite understand it. Here's the code in Visual Basic, only I have no clue how Python can do anything like this without it being very complicated. (The following code is in a class module)

Code:
Function MakeDWORD(Value As Long) As String
    Dim Result As String * 4
    CopyMemory ByVal Result, Value, 4
    MakeDWORD = Result
End Function


I know that there must be a way for Python to do something to this extent. Can anyone help me?

Reply With Quote
  #2  
Old December 5th, 2004, 06:01 PM
Schol-R-LEA's Avatar
Schol-R-LEA Schol-R-LEA is offline
Commie Mutant Traitor
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: The People's Republic of Berkeley
Posts: 1,282 Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 16 h 23 m 31 sec
Reputation Power: 618
CopyMemory isn't a Visual Basic function, it is a Windows API call, for copying from one area of memory to another; however, in this function, it seems to be used as a way of circumventing the language typing, by converting a VB Long Integer into a DWORD, a type which is used by the Windows API extensively when handling raw (in the sense of typeless) data, by way of a 4-byte string. It is not a cast or conversion, but a bit-for-bit copy, something VB does not normally allow between disparate data types.

AFAICT, there is no direct equivalent in Python, because the conversion itself has no meaning in the Python object model. What you need to do is kick it up one level of abstraction; that is to say, work out what the DWORD in question was used for - probably for some kind of external function call, as it wouldn't be of any use that I can think of in VB itself - and determine how to do that in Python. It will almost certainly be different from how it was done in VB, because of the differences in how the languages handle system calls.

In fact, I think you'll find that a literal translation of a VB program - especially one that uses a lot of system calls, which is the case in this sort of Socket programming - is not going to work very well, as the two languages have very different idioms, and interface with the system differently. I think you'd be better off studying the underlying battle.net protocol and working out a new design instead.

Reply With Quote
  #3  
Old December 5th, 2004, 06:07 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
Well, that's my problem. I've only had a battle.net bot written in Visual Basic 6, and that's what the code was like. Every Visual Basic programmer had the same PacketBuffer code. I also know the proper code to making a PacketBuffer (MakeDWORD is in PacketBuffer) in C++. Only when it comes to Python it seems almost impossible because of how different the 2 languages are. I'm still trying to figure out another way to make MakeDWORD work in Python, only I think I'm going to be the first person ever to create a bot for battle.net in Python. No matter how much I look or where I look it seems no one else has created one yet. EVery other bot is made in either C++ or Visual Basic, and about 2 bots are made in Java. (The bot in Java has an open source copy) If I looked at the MakeDWORD code from this bot (I just thought of this right now) would it be even easier to convert to Python?

Reply With Quote
  #4  
Old December 5th, 2004, 06:31 PM
Schol-R-LEA's Avatar
Schol-R-LEA Schol-R-LEA is offline
Commie Mutant Traitor
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: The People's Republic of Berkeley
Posts: 1,282 Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 16 h 23 m 31 sec
Reputation Power: 618
I sitll think you should try to get more information about the protocols themeselves. A quick Google for "battle.net" protocol and a bit of digging turns up a site called "The Disclaimer" which has fora specific to this topic.

I would be very careful about any of this however; looking this up shows that battleChat is not an open protocol, and there are definite questions about the legality of these bots, even just for chat use. I would go over the Blizzard EULA and related documentation before going forward with this.

Reply With Quote
  #5  
Old December 5th, 2004, 06:45 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
Ya, I've been to The Disclaimer, they have programming forums in there, etc. The only problem is they only have a programming section for Visual Basic, C++, ASP, I think Java, and like one other language. There's no Python in there. Some of the greatest programmers of all time run this site (Skywing, Grok, Yoni...). I have no clue on how much most of the members on the site know about Python. That's why I figured I'd come here instead. I'll go over to BotDev (The Disclaimer) and see if anyone can help. Thanks.

Reply With Quote
  #6  
Old December 5th, 2004, 07:42 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
As Schol-R-LEA said, the VB function takes an integer value and packs it into a 4 byte string. The simplest way to do this in Python is to use the struct module. Here is the Python equivalent:

Code:
import struct

def makeDWORD(value):
    return struct.pack('i', value)


Dave - The Developers' Coach

Reply With Quote
  #7  
Old December 5th, 2004, 07:55 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
A quick google for "battle.net protocol python" threw up this. It may be what you need. Or it may not.

Dave - The Developers' Coach

Reply With Quote
  #8  
Old December 5th, 2004, 07:58 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
Ok, heres the code I now have: (Yes I have struct imported)

Code:
    def MakeDWORD(value):
        MakeDWORD = MakeDWORD()
        return struct.pack(result, value)


Now, in the Visual Basic code it had:

Code:
Function MakeDWORD(Value As Long) As String
    Dim Result As String * 4
    CopyMemory ByVal Result, Value, 4
    MakeDWORD = Result
End Function


I was wondering if the 4 after Value, should be added in my code, for instance:

Code:
    def MakeDWORD(value):
        MakeDWORD = MakeDWORD()
        return struct.pack(result, value, 4)


The people in The Disclaimer don't seem to know Python, if there are any good members in there who really know Python, I can't find them. One of them asked me to ask you how to convert a 32 bit interger into a string, maybe that would make the question easier. So for now, all I need to know is if my code will actually work like the Visual Basic code does. Thanks for the help so far.

Reply With Quote
  #9  
Old December 6th, 2004, 03:45 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
See my previous reply - I posted up the function you want. The one you posted will fail with an exception if you try to run it.

Dave - The Developers' Coach

Reply With Quote
  #10  
Old December 6th, 2004, 06:00 PM
Yegg`'s Avatar
Yegg` Yegg` is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Dec 2004
Location: Meriden, Connecticut
Posts: 1,731 Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level)Yegg` User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Weeks 6 Days 4 h 5 m 27 sec
Reputation Power: 83
Send a message via AIM to Yegg`
Ok, thanks for the help DevCoach, I went to that site and download BnetBot. The only problem was that that bot was probably the most confusing code Iv'e ever looked at, plus it has an entirely different set up from what my bot has. BnetBot doesn't have the normal code from a PacketBuffer as my bot does, I'm not sure what that bot had. All I need to know is that for my code, return struct.pack(result, value, 4), result obviously is the string as you used in your example, "i", and value is a long, you put that in the same spot for your example. Now for Battle.net, there is MakeDWORD, and MakeWORD. MakeDWORD used an interger of 4, and MakeWORD uses an interger of a 2. So is return struct.pack(result, value, 4) proper code? Or is that 4 in the wrong spot? If you can help me with this my PacketBuffer will be set. Thanks for all the help so far though.
Edit:Someone in the BotDev (The Disclaimer) forums has also just told me about the struct module, sicne he knows a lot about battle.net I might also be able to get some help from him.

Reply With Quote
  #11  
Old December 9th, 2004, 02:56 AM
Schol-R-LEA's Avatar
Schol-R-LEA Schol-R-LEA is offline
Commie Mutant Traitor
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: The People's Republic of Berkeley
Posts: 1,282 Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level)Schol-R-LEA User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 16 h 23 m 31 sec
Reputation Power: 618
Yegg, you are going to have to understand what the functions do and why they take the arguments they do, otherwise you'll never accomplish what you're trying to. The kind of blind duplication of the VB code you are using is just going to cause you trouble in the long run, and this is one example of why.

The reason that the VB CopyMemory() function needs the final size argument is because it is copying raw memory space, and it needs to now how many bytes to copy.

The purpose of the Python struct.pack() method, on the other hand, is to take the data in the object and 'pack' it into a a contiguous data space. Because the object already knows how large the data is, it does not need, and will not accept, the size argument. thus, the '4' isn't need at all - and adding it will cause the program to fail. Clear?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > MakeDWORD


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump