SRL Archive - MML Library Development

PyMML and SMART.


Wizzup?

2010-12-01 15:43:57

I played around a bit with pyMML, and it works quite well with SMART. All on a 64 bit machine, native. (64 bit java/smart and 64 bit libMML.) 32 bit should work fine too.

You need the latest pymml code from simba git if you want to play with this. It'll start up SMART from python, initialise the MMLCore object; create a client and also create a SmartMouse object. The SmartMouse object is really just the MML Mouse object with a few methods overridden (surprise surprise it only overrides the actual dll calls). It currently will load SMART, set the mouse position to (100, 100) and then print the SMART mouse position every second. Not too impressive, but it's a start and a good proof of concept. I'm sure that with little extra time we can also add a method to make libMML use the SMART call getSmartArray; we can read colours from SMART.

Save this as "smartmouse.py" in the pymml directory.

from mml.mouse import Mouse
from mml.mtypes import *

class SmartMouse(Mouse):
def __init__(self, MC, cli):
self._mc = MC
pass

def _setMousePos(self, p):
ret = POINT()
ret.x, ret.y = p
r = self._mc.moveMouse(ret.x, ret.y)

def _getMousePos(self):
x, y = c_int(0), c_int(0)
r = self._mc.getMousePos(pointer(x), pointer(y))
return (x.value, y.value)

def _getMouseButtonState(self, button):
pass

def _setMouseButtonState(self, button, state):
pass

And call this what you want, I called it "testsmart.py":
$ cat testsmart.py 
#!/usr/bin/env python
from smartmouse import SmartMouse
from mml import MMLCore
from mml.mtypes import *

DLL = MMLCore('../libmml.so')

client = DLL.dll.create_client()
print 'client', client

from ctypes import *
from time import sleep

d = CDLL('/home/merlijn/public-smart/dist/libsmart.so')
d.setup('http://world19.runescape.com/', 'plugin.js?param=o0,a2,m0', \
765, 503, '')
sleep(5)

DLL.dll.set_array_target.restype = c_int
DLL.dll.set_array_target.argtypes = [c_ulong, c_ulong, POINT]

size = POINT()
size.x = 765
size.y = 503

mouse = SmartMouse(d, None)

mouse.setPos((100,100))

d.getImageArray.restype = c_ulong
arr = d.getImageArray()
print 'arr', arr

print 'set target'
DLL.dll.set_array_target(client, arr, size)

DLL.dll.get_color.restype = c_int
DLL.dll.get_color.argtypes = [c_ulong, c_int, c_int, POINTER(c_int)]

while True:
print 'Looping'
sleep(1)
print mouse.getPos()

for i, j in zip(range(100), range(100)):
col = c_int(0)
res = DLL.dll.get_color(client, c_int(i), c_int(j), byref(col))
print 'col:', col

Note that you'll need to have compiled the libmml.so and possible also libsmart.so (if you don't run 32 a bit system)

E: You'll need to at least change the library paths and names.
I'm not too sure if this will work out of the box in windows, either. CTypes might want me to use a different DLL loader. (I think it is called WinDLL or so)

i luffs yeww

2010-12-01 16:04:18

Nice work! :) I was wondering about this today (I've been thinking about libMML/pyMML since I got off irc this morning), and I'm glad to see it should work just fine.

I'll do all I can tonight. ^^ This is cool stuff.

BenLand100

2010-12-01 16:05:35

Ah, nice. If you can access memory mapped stuff from within python (I assume that is possible) accessing colors shouldn't be an issue and be quite efficient.

Wizzup?

2010-12-01 16:10:22

From: BenLand100
Ah, nice. If you can access memory mapped stuff from within python (I assume that is possible) accessing colors shouldn't be an issue and be quite efficient.


You can; I've already made it get the pointer to the array, which it can then pass to libMML's set_target_array. So then libMML will target SMART's memory. Obviously you can also access it directly from Python, but I don't think that is a good idea speed-wise… :p

Wizzup?

2010-12-01 18:24:42

Updated first post to display a working get_color.

KingKong

2011-05-13 03:20:12

So, does this mean someone has to convert Srl includes to python syntax?

Dgby714

2011-05-13 03:39:28

From: KingKong
So, does this mean someone has to convert Srl includes to python syntax?


No, libMML has to be completed, then pyMML has to be completed. Then you can complete pySRL (or what ever its called…..).

i luffs yeww

2011-05-13 05:02:23

I think pySRL would be best, naming wise.

But still, it's more than porting. There will be functional changes, syntax changes, different methods, etc.

Python and PascalScript are quite different.

KingKong

2011-05-13 05:44:31

So shall I start on rewriting the includes?

E: Just noticed i got another cup :D

Dan Cardin

2011-05-13 07:05:09

judging on the progress in pymml afaik, no.

i luffs yeww

2011-05-14 00:55:35

If you want to help, you could work on libMML.

KingKong

2011-05-14 03:17:07

I want to, but i don't know where to start(What program do i use, what do i do, and other noobish things :(). So if someone could give me a few tips, that would be awesome.

i luffs yeww

2011-05-14 15:34:59

Lazarus + FPC.

KingKong

2011-06-10 06:17:50

Ok, so ive downloaded lazarus and i have a few questions:
Q1)do i absolutely need FPC?

Q2)I get this error(and loads of other more not so important) when trying to compile libmml:
dtm.pas(82,5) Fatal: Can't find unit DCPbase64 used by dtm <- is this due to fpc not being installed?

Q3)Am I supposed to have more than these units here to work with libmml?
https://github.com/MerlijnWajer/Simba/tree/master/Units/MMLCore

Q4)Here is one function that I made, now I need to know if its the right way of doing things:

function get_colors(C: TClient; const Coords: TPointArray;
out colors: TIntegerArray): TIntegerArray; cdecl;
begin
try
colors := C.MFinder.GetColors(Coords);
if Length(colors) > 0 then
result := RESULT_OK
else
result := RESULT_FALSE;
except on e : Exception do
begin
set_last_error(e.message);
result := RESULT_ERROR;
end;
end;
end;

Dgby714

2011-06-10 06:33:45

From: KingKong
Ok, so ive downloaded lazarus and i have a few questions:
Q1)do i absolutely need FPC?

Q2)I get this error(and loads of other more not so important) when trying to compile libmml:
dtm.pas(82,5) Fatal: Can't find unit DCPbase64 used by dtm <- is this due to fpc not being installed?

Q3)Am I supposed to have more than these units here to work with libmml?
https://github.com/MerlijnWajer/Simba/tree/master/Units/MMLCore

Q4)Here is one function that I made, now I need to know if its the right way of doing things:

function get_colors(C: TClient; const Coords: TPointArray;
out colors: TIntegerArray): TIntegerArray; cdecl;
begin
try
colors := C.MFinder.GetColors(Coords);
if Length(colors) > 0 then
result := RESULT_OK
else
result := RESULT_FALSE;
except on e : Exception do
begin
set_last_error(e.message);
result := RESULT_ERROR;
end;
end;
end;


You do need FPC, tho from you actually being able to compile I'd say you already have it.

You need everything in the Units folder. Not just MMLCore.

Wizzup?

2011-06-10 07:20:24

From: KingKong
Ok, so ive downloaded lazarus and i have a few questions:
Q1)do i absolutely need FPC?

Q2)I get this error(and loads of other more not so important) when trying to compile libmml:
dtm.pas(82,5) Fatal: Can't find unit DCPbase64 used by dtm <- is this due to fpc not being installed?

Q3)Am I supposed to have more than these units here to work with libmml?
https://github.com/MerlijnWajer/Simba/tree/master/Units/MMLCore

Q4)Here is one function that I made, now I need to know if its the right way of doing things:

function get_colors(C: TClient; const Coords: TPointArray;
out colors: TIntegerArray): TIntegerArray; cdecl;
begin
try
colors := C.MFinder.GetColors(Coords);
if Length(colors) > 0 then
result := RESULT_OK
else
result := RESULT_FALSE;
except on e : Exception do
begin
set_last_error(e.message);
result := RESULT_ERROR;
end;
end;
end;


  • Yes, but it's typically included if you install Lazarus.
  • You probably don't have all the units. Even though we mainly just need the MMLCore/ units, they have a few dependencies (like DCP)
  • See ^
  • Yes, it looks alright. Have a look at find_colors, the logic is probably very similar. It will probably also help with returning the array (pointer in this case)

Nice to see someone work on it.

Oh, and as a note; I'll probably have more time in about four days or so.

KingKong

2011-06-10 07:49:17

where do i get those extra units from?

Dgby714

2011-06-10 07:57:17

From: KingKong
where do i get those extra units from?


https://github.com/MerlijnWajer/Simba/tree/master/Units

Mainly in the misc folder.

i luffs yeww

2011-06-10 07:57:45

git clone git://github.com/MerlijnWajer/Simba.git

KingKong

2011-06-10 09:24:39

So I compiled the libmml and now i get this error when i try to run testmouse.py:
The program cant start because libgdk-win32-2.0-0.dll is missing. Did I forget to include something in lazarus before compiling or something?

i luffs yeww

2011-06-10 15:31:30

All I can think of are your paths are messed up somehow. :/ Can you try reinstalling Lazarus and make sure it downloads and installs everything it needs for sure? (Not sure if it will ask you - I can't remember.)

Try downloading GIMP. :p http://gimp-win.sourceforge.net/stable.html. I never do stuff with .dlls in Windows (or Windows in general), but from what I can tell, you just need to download them and place them where laz is.

http://wiki.lazarus.freepascal.org/GTK2_Interface#Using_the_Gtk2_interface_under_Microsoft_Windows maybe.

Wizzup?

2011-06-10 18:02:38

It's actually perfectly possible that it doesn't work on Windows ATM, I haven't tried that in quite a long time.

i luffs yeww

2011-06-10 18:24:41

Also true, but that problem he brought up (libgdk-win32-whatever.dll being missing) is unrelated to it working on windows, isn't it?

Actually, iirc, neither of us worked on a Windows version at all. Last I remember the path was set up specific to one of our machines (yours I'm sure) and I had to do some manual tweaking to get it working?

Oh, I just looked again. It is definitely set up specifically to be used on your machine. :p Path needs to be changed for the .dll and everything (*.so -> *.dll).

And, iirc, all(?) CDLL calls need to be changed to WinDLL or something.

KingKong

2011-06-11 01:07:58

From: i luffs yeww
All I can think of are your paths are messed up somehow. :/ Can you try reinstalling Lazarus and make sure it downloads and installs everything it needs for sure? (Not sure if it will ask you - I can't remember.)

Try downloading GIMP. :p http://gimp-win.sourceforge.net/stable.html. I never do stuff with .dlls in Windows (or Windows in general), but from what I can tell, you just need to download them and place them where laz is.

http://wiki.lazarus.freepascal.org/GTK2_Interface#Using_the_Gtk2_interface_under_Microsoft_Windows maybe.


Turns out I had to download all gtk libraries which is like 23 dlls(~12.1 MB) to stop all the errors from appearing

From: Wizzup?
It's actually perfectly possible that it doesn't work on Windows ATM, I haven't tried that in quite a long time.


What isn't supposed to work?:confused:

From: i luffs yeww
Also true, but that problem he brought up (libgdk-win32-whatever.dll being missing) is unrelated to it working on windows, isn't it?

Actually, iirc, neither of us worked on a Windows version at all. Last I remember the path was set up specific to one of our machines (yours I'm sure) and I had to do some manual tweaking to get it working?

Oh, I just looked again. It is definitely set up specifically to be used on your machine. :p Path needs to be changed for the .dll and everything (*.so -> *.dll).

And, iirc, all(?) CDLL calls need to be changed to WinDLL or something.


Yes, i changed all the paths(im not that useless), and for the libmml we are supposed to use cdll because it exports as cdecl. Im having erros when it gets to the setupsmart bit, I tried using cdll, windll and oledll, but all result in the same error, they cant find setup in libsmart, here is the SS:
http://i54.tinypic.com/2ef3k9z.png

i luffs yeww

2011-06-11 01:14:30

lol @ "error" :p Should be done better than that.

I think we had to compile SMART ourselves with some changes. I really don't remember, especially since it got no use besides from the people who were working on it. It'd be nice if someone could try this on a linux machine to see if it works at all (there's also a chance there's something in SMART that is making this not work by the way). We used a way older version than 6.6.

Wizzup?

2011-06-11 07:12:45

From: KingKong
Turns out I had to download all gtk libraries which is like 23 dlls(~12.1 MB) to stop all the errors from appearing



What isn't supposed to work?:confused:

I was referring to this: "The program cant start because libgdk-win32-2.0-0.dll is missing".

But apparently it works now. SMART is not part of pyMML, so if that doesn't work, that's not directly something I can look at now.

i luffs yeww

2011-06-11 14:31:46

Well we did use an earlier version (maybe only 6.5, looking at github, I dunno), but still. Could be a factor.

KingKong

2011-06-11 21:01:27

From: i luffs yeww
Well we did use an earlier version (maybe only 6.5, looking at github, I dunno), but still. Could be a factor.


I still get an attribute error while try to call setup, even with the older versions

i luffs yeww

2011-06-11 22:41:59

Hm. I'm on windows atm so I can't see if it works on linux, but I'll look into it later on windows.

KingKong

2011-06-13 20:28:00

Hmm, i think i solved the atrribute error, turns out i had to call the smartsetup function by its ordinal number(1), but i still get an error which doesn't print to the screen(it might due to my gtk library)