Wrong number of parameters supplied to pixelSearch().

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
Forum rules
This is a sub-forum for things specific to MicroMacro.

This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Message
Author
Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Wrong number of parameters supplied to pixelSearch().

#1 Post by Exempt » Thu Oct 01, 2015 9:07 pm

I looked up this issue and it seems the answer is suppose to be to make sure my mm is updated which I believe I got the latest version 1.91.41.

As far as I can tell from the wiki this is correct. hwnd is a valid window handle to so I'm not sure why this is happening.

Code: Select all

window.pixelSearch(hwnd, 72, 120, 138, x-5, y-5, x+5, y+5, 1, 1)
Failed to run event function, err code: 7 (Runtime error)
testcolor.lua:30: Wrong number of parameters supplied to pixelSearch().

stack traceback:
[C]: in field 'pixelSearch'
testcolor.lua:30: in function <testcolor.lua:25>

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Wrong number of parameters supplied to pixelSearch().

#2 Post by Administrator » Thu Oct 01, 2015 9:52 pm

Where did you get the script? Can you provide a copy?

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Wrong number of parameters supplied to pixelSearch().

#3 Post by Exempt » Thu Oct 01, 2015 9:56 pm

Just something I was playing with, I haven't used the newer version of MM till just tonight really so.

Code: Select all

function macro.init()
		hwnd = window.find("test");
		print(window.getTitle(hwnd));
	end
 
	local running = true;
	function macro.main()
		return running;
	end
 
	function macro.event(e, data1, data2, data3, data4)
		if( e == "keypressed" ) then

			if(data1 == key.VK_Y) then
				x, y = mouse.getPosition();
				if(window.pixelSearch(hwnd, 72, 120, 138, x-5, y-5, x+5, y+5, 1, 1) ~= -1) then
					print("Working.");
				else
					print("Not working.");
				end
			end


			if( data1 == key.VK_SPACE ) then
				print("Space bar was pressed. Quitting.");
				running = false;
			end
		end
	end
edit: This is what the start screen for MM shows.
MicroMacro v1.91.41
SolarStrike Software http://www.solarstrike.net

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Wrong number of parameters supplied to pixelSearch().

#4 Post by Administrator » Thu Oct 01, 2015 10:08 pm

As it turns out, you weren't doing anything wrong. It was due to a bug in the argument checking. I've attached a patched executable; just replace your micromacro.exe with this one.

Test code:

Code: Select all

function macro.init()
	local hwnd = window.getAppHwnd();
	printf("Hwnd: 0x%x\n", hwnd);
	local x,y = window.pixelSearch(hwnd, 170, 190, 190, 0, 0, 200, 200, 10, 1);
	if( x and y ) then
		local r, g, b = window.getPixel(hwnd, x, y);
		printf("Pixel at (%d, %d) is %d,%d,%d", x, y, r, g, b);
	else
		printf("Not found\n");
	end
end

function macro.main(dt)
	return false;
end

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Wrong number of parameters supplied to pixelSearch().

#5 Post by Exempt » Fri Oct 02, 2015 7:12 am

Thanks, I'll give this a try later today.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Wrong number of parameters supplied to pixelSearch().

#6 Post by Exempt » Fri Oct 02, 2015 4:59 pm

I get an error after replacing MM that says "The application was unable to start correctly (0xc000007b). Click OK to close the application".

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Wrong number of parameters supplied to pixelSearch().

#7 Post by Administrator » Fri Oct 02, 2015 9:26 pm

Probably due to a DLL mismatch. Perhaps you had the x64 DLLs and I only provided the x86 executable, or perhaps one of the DLLs was an older version. I've included a full copy of the x86 binaries.
Attachments
micromacro.1.92.46_x64.zip
(1.01 MiB) Downloaded 109 times
micromacro.1.92.46_x86.zip
(745.21 KiB) Downloaded 121 times

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Wrong number of parameters supplied to pixelSearch().

#8 Post by Exempt » Sat Oct 03, 2015 5:04 pm

The 64bit upload still seems to have the same issue with wrong number of arguments. Also for some reason while using the 32bit MM becomes unresponsive when the pixelSearch returns true I believe.

Code: Select all

function macro.init()
	hwnd = window.find("testJavaClient");
	winX, winY, winW, winH = window.getRect(hwnd);
	print(window.getTitle(hwnd), winX, winY, winW, winH);
end

local running = true;
function macro.main()
	return running;
end

function macro.event(e, data1, data2, data3, data4)
	if( e == "keypressed" ) then

		if(data1 == key.VK_Y) then
			x, y = mouse.getPosition();
			x = x-winX;
			y = y-winY;
			
			r,g,b = window.getPixel(hwnd, x, y);
			print(r,g,b);
			
			px, py = window.pixelSearch(hwnd, 39, 123, 192, x-5, y-5, x+5, y+5, 1, 1);
			if(px and py) then
				print("Working.");
			else
				print("Not working.", x, y);
			end
		end


		if( data1 == key.VK_SPACE ) then
			print("Space bar was pressed. Quitting.");
			running = false;
		end
	end
end
Edit: Maybe just me doing something wrong because the colors and cords are not exactly what I'd expect.
Edit2: Seems that it's always returning nil and the crash is at "if(px and py)"... hrm, maybe it's just the program I'm trying to use it on... not sure why it wouldn't detect a color on the screen though. window.getPixel works perfectly fine though.

I changed my pixelSearch to check the entire client area and it's still only returning nil.

Code: Select all

PX, PY = window.pixelSearch(hwnd, 73, 122, 137, winX, winY, winX+winW, winY+winH, 10, 1)

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Wrong number of parameters supplied to pixelSearch().

#9 Post by BlubBlab » Sun Oct 04, 2015 8:02 am

Hm what up with it ? I wanted to upgrade/update my version so do the changes work ?...
The command is relatively new but isn't that the same function I suggest in LUA for reading the LP bar in ArcheAge ? :D
It not a problem it is just so that I thought back than that the LP in other games could have all kinds of forms , some of them even looks like smilies.
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Wrong number of parameters supplied to pixelSearch().

#10 Post by Administrator » Sun Oct 04, 2015 11:27 am

Exempt wrote:The 64bit upload still seems to have the same issue with wrong number of arguments.
You're right. Sometimes I'm kind of a ding dong and forget to compile things before packaging them for distribution.
Also for some reason while using the 32bit MM becomes unresponsive when the pixelSearch returns true I believe.
I'm unable to reproduce that at all. Have you overwritten all files with the pack I uploaded?


I modified your script to just check Notepad for the color white:

Code: Select all

function macro.init()
   hwnd = window.find("Untitled - Notepad");--("testJavaClient");
   winX, winY, winW, winH = window.getRect(hwnd);
   print(window.getTitle(hwnd), winX, winY, winW, winH);
end

local running = true;
function macro.main()
   return running;
end

function macro.event(e, data1, data2, data3, data4)
   if( e == "keypressed" ) then

      if(data1 == key.VK_Y) then
         x, y = mouse.getPosition();
         x = x-winX;
         y = y-winY;
         
         r,g,b = window.getPixel(hwnd, x, y);
         print(r,g,b);
         
		local sr, sg, sb = 255, 255, 255;

         px, py = window.pixelSearch(hwnd, sr, sg, sb, x-5, y-5, x+5, y+5, 1, 1);
         if(px and py) then
            print("Working.");
         else
            print("Not working.", x, y);
         end
      end


      if( data1 == key.VK_SPACE ) then
         print("Space bar was pressed. Quitting.");
         running = false;
      end
   end
end
It works just fine there. What is the target application you're trying to check against? It could be related to how that window is being rendered, or perhaps it has some sort of anti-cheat that is preventing MicroMacro from grabbing a screenshot of it. Alternatively, it could be that there is some sort of blending which is causing the color values at those pixels to slightly change and therefor be outside of the accuracy range.
bar_example.png
bar_example.png (14.93 KiB) Viewed 6107 times
In this example, the top health bar shows an optimal candidate for pixel searching. It is solid, has very contrasting colors against nearby pixels that you don't want to detect, and has no alpha transparency or overlays. This means it is reliable because the pixel colors are fairly constant.

The bottom bar is a bad example. The colors blend together a bit with the gradient, there is alpha transparency which causes background element (the tree, in this case) to potentially throw off color values, and the green part of the bar can be too similar to surrounding elements. This means the exact pixel colors vary and will be unreliable.
The command is relatively new but isn't that the same function I suggest in LUA for reading the LP bar in ArcheAge ? :D
I'm not sure. It's been part of MicroMacro for a very long time. However, its usefulness is minimized due to the fact that it is a very poor way to do detections in anything beyond the most simplistic of visual elements. It cannot recognize shapes or anything like that; it just looks for any pixel that matches a single specified color.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Wrong number of parameters supplied to pixelSearch().

#11 Post by BlubBlab » Sun Oct 04, 2015 12:18 pm

It isn't I saw it my idea was to search in a line with an binary search/skiplists, yours is just more general without any optimization. The problem is you never know in which kind of form you searched LP bar has I know games where they are formed like an O with which lines wouldn't work obvious... maybe I can optimize yours.
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Wrong number of parameters supplied to pixelSearch().

#12 Post by Exempt » Sun Oct 04, 2015 4:29 pm

I'm unable to reproduce that at all. Have you overwritten all files with the pack I uploaded?
Yeah, I just deleted the old one before extracting the new.
It works just fine there. What is the target application you're trying to check against? It could be related to how that window is being rendered, or perhaps it has some sort of anti-cheat that is preventing MicroMacro from grabbing a screenshot of it. Alternatively, it could be that there is some sort of blending which is causing the color values at those pixels to slightly change and therefor be outside of the accuracy range.
The game is called wurm online. I find it odd the getPixel works fine but not pixelSearch.

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Wrong number of parameters supplied to pixelSearch().

#13 Post by Administrator » Mon Oct 05, 2015 5:40 pm

I'll investigate further when I have the time. Super busy with work tonight.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Wrong number of parameters supplied to pixelSearch().

#14 Post by Exempt » Mon Oct 05, 2015 5:47 pm

Thanks. I'm still messing with it some. Do you know if just using getPixel() would be in a double for loop to scan an area would be a bad idea? I'll try to test it but I'm not sure how to just yet lol. :)

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Wrong number of parameters supplied to pixelSearch().

#15 Post by Administrator » Mon Oct 05, 2015 5:55 pm

It's fine in that it works. Not so fine as it would be slow as dirt. pixelSearch() grabs a screenshot of the window to use as a buffer so that it only needs to make one API call instead of thousands.

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Wrong number of parameters supplied to pixelSearch().

#16 Post by BlubBlab » Tue Oct 06, 2015 4:39 am

Ups I noticed that I done some changes on my version because VS wasn't sure if things aren't null:

Code: Select all

// Make sure we will even be able to handle it
	if( IsIconic(hwnd) || hdcScreen == NULL || tmpHdc == NULL || hBmp == NULL )
	{ // Throw an error
		DeleteDC(tmpHdc);
		DeleteObject(hBmp);
		ReleaseDC(NULL, hdcScreen);

I changed to this to silent the warning

Code: Select all

// Make sure we will even be able to handle it
	if( IsIconic(hwnd) || hdcScreen == NULL || tmpHdc == NULL || hBmp == NULL )
	{ // Throw an error
		if ( tmpHdc != NULL ) {
			DeleteDC( tmpHdc );
		}
		if ( hBmp != NULL ) {
			DeleteObject( hBmp );
		}
		if ( hdcScreen != NULL ) {
			ReleaseDC( NULL, hdcScreen );
		}
maybe a bit paranoid but better sure than sorry.
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Wrong number of parameters supplied to pixelSearch().

#17 Post by Administrator » Wed Oct 07, 2015 7:15 pm

I'm still working on this. Seems I still have more logic to work through to solve any potential problems, but still cannot seem to figure out why the DIBits is returning all 0xFFFFFF.

However, I have found some bugs in your code as well:

Code: Select all

winX, winY, winW, winH = window.getRect(hwnd);
This should be getClientRect(). You are (potentially) adding the titlebar's height into the equation which is throwing off the math. You also probably don't want to do this only at the initialization as if the window is minimized you'll get invalid data.

Also, you're not doing any bounds checking on the area you're passing to the pixel search. That is, x-5,y-5 x+5, y+5 can potentially be outside the window rect. Of course, this should be handled internally anyways (fixing that now).

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Wrong number of parameters supplied to pixelSearch().

#18 Post by Exempt » Wed Oct 07, 2015 7:37 pm

Administrator wrote:I'm still working on this. Seems I still have more logic to work through to solve any potential problems, but still cannot seem to figure out why the DIBits is returning all 0xFFFFFF.

However, I have found some bugs in your code as well:

Code: Select all

winX, winY, winW, winH = window.getRect(hwnd);
This should be getClientRect(). You are (potentially) adding the titlebar's height into the equation which is throwing off the math. You also probably don't want to do this only at the initialization as if the window is minimized you'll get invalid data.

Also, you're not doing any bounds checking on the area you're passing to the pixel search. That is, x-5,y-5 x+5, y+5 can potentially be outside the window rect. Of course, this should be handled internally anyways (fixing that now).
I tried with both getClientRect and getRect as I had the same idea but that didn't seem to be the case sadly. I didn't think checking outside the window would be an issue but maybe that's why it was crashing sometimes.

User avatar
Administrator
Site Admin
Posts: 4923
Joined: Sat Jan 05, 2008 4:21 pm

Re: Wrong number of parameters supplied to pixelSearch().

#19 Post by Administrator » Wed Oct 07, 2015 8:12 pm

Yes, the crashing was due to being out of bounds. That part is fixed. However, I'm not really able to fix the problem of not being able to find the color inside of Wurm's window. It just has something to do with how it is painting the screen which is causing it to not fill our buffer properly. I don't think there's anything I can do to fix that, unfortunately.

I did consider capturing the desktop and scanning that (using the window's rect as the bounding box) but that has its own problems. Namely, it's not able to operate on that memory space.

Is there some reason you're not just using memory reads? That is far quicker and more reliable.

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Wrong number of parameters supplied to pixelSearch().

#20 Post by Exempt » Wed Oct 07, 2015 9:18 pm

I just want to avoid attaching debuggers and such to the game all together. I will just use getPixel and keep the search area very small like 5x5 to 10x10.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest