Java Mouseclicks in the backround?

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.
Post Reply
Message
Author
User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Java Mouseclicks in the backround?

#1 Post by 3cmSailorfuku » Thu Aug 06, 2009 9:46 am

I came a week ago across this fine game, http://www.havenandhearth.com/portal/, and I made a script that partially builds an construction & eats apples.
However I can't get Attach() to work with this Java application, so I wonder if I'm just retarded to get this working (Attach("Haven and Hearth","SunAwtCanvas"); would just end up making the bot do nothing) or do I miss something there.

Code: Select all

exp2 = 0;
exp3 = 0;
exp = 300;
variable2 = 0;

-- Move to Building
function openBuilding(x0,y0)
mouseSet(x0, y0);
mouseRClick();
rest(5000);
end

-- Put the Item into the Building
function putItem(x3,y3,buildx,buildy,x4,y4)

exp2 = exp2+1;
exp3 = exp3+1;

keyboardHold( key.VK_SHIFT );
mouseSet(x3, y3);
mouseLClick();
keyboardRelease( key.VK_SHIFT );
rest(100);
mouseSet(buildx, buildy);
mouseLClick();
rest(100);
keyboardHold( key.VK_SHIFT );
mouseSet(x4, y4);
mouseLClick();
keyboardRelease( key.VK_SHIFT );
rest(9600);
printf("LP: +%d | %d/%d | Eaten: %d\n",exp3*15,exp2,exp,variable2);
end


function getApple(x1,y1,atimes,aposX,aposY)
exp2 = 0;
for variable = 0, atimes, 1 do
	printf("Eating Apple: %d \n",variable);
	-- Walk to tree & get an apple
	mouseSet(x1, y1);
	mouseRClick();
	rest(700);
	mouseMove(30,-30);
	rest(100);	
	mouseLClick();
	rest(3000);

	-- Eat Apple
	mouseSet(aposX, aposY);
	rest(100);
	mouseRClick();
	rest(800);
	mouseMove(0, -30);
	rest(100);
	mouseLClick();
	-- Drop / Repeat
	rest(500);
	variable2 = variable2+1;
end
end

while true do
putItem(142,160,347,333,347,297);
-- Move to Appletree after X runs
if(exp2 >= exp)then
getApple(509,301,1,175,162);
openBuilding(576,381);
end
end
Or do I actually have to call the mouse moves within a codecave? But then again, JAVA.

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

Re: Java Mouseclicks in the backround?

#2 Post by Administrator » Fri Aug 07, 2009 12:15 am

I believe there is another SunAwtCanvas inside of that which is the one you need to send input to. First, try this:

Code: Select all

local win = findWindow("Haven and Hearth", "SunAwtCanvas");
printf("Win: 0x%X\n", win);
attach(win);
What does it say win is? If it is 0, there is your problem.

User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Re: Java Mouseclicks in the backround?

#3 Post by 3cmSailorfuku » Fri Aug 07, 2009 6:49 am

Administrator wrote:I believe there is another SunAwtCanvas inside of that which is the one you need to send input to. First, try this:

Code: Select all

local win = findWindow("Haven and Hearth", "SunAwtCanvas");
printf("Win: 0x%X\n", win);
attach(win);
What does it say win is? If it is 0, there is your problem.
That is what I believed too, however I can't seem to find any other instances of javaw.exe other than running "Haven & Hearth" under that Class.
Spy++ tells me the same.

Also
Win: 0x604F0
Maybe you can try it, the game doesn't need an installation and is about 200kb in size if you only try it in the login.

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

Re: Java Mouseclicks in the backround?

#4 Post by Administrator » Fri Aug 07, 2009 8:14 am

It looks like attached input does work, but it also seems like there are checks built in to the game to see if it is in the foreground, and only then to process input. If you can manage to find the location of the check, you could curcumvent it, but it won't be easy.

User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Re: Java Mouseclicks in the backround?

#5 Post by 3cmSailorfuku » Fri Aug 07, 2009 2:51 pm

Administrator wrote:It looks like attached input does work, but it also seems like there are checks built in to the game to see if it is in the foreground, and only then to process input. If you can manage to find the location of the check, you could curcumvent it, but it won't be easy.
I'll try to look over the source code of the client, haven't found something like that yet though.

User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Re: Java Mouseclicks in the backround?

#6 Post by 3cmSailorfuku » Sun Aug 09, 2009 9:06 pm

After taking a look at the Messages the program receives, I noticed that the Messages sent by MicroMacro are missing something.
It would always put the Message SunAwtComponent in between with 0x0 0x0 values, followed by another SunAwtComponent Message with 0x1.

Now I understand why it won't pick it up properly, it's using an own control that I can't seem to access only by regular sendmessage.
It's a java thing :(

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

Re: Java Mouseclicks in the backround?

#7 Post by Administrator » Mon Aug 10, 2009 7:11 am

3cmSailorfuku wrote: Now I understand why it won't pick it up properly, it's using an own control that I can't seem to access only by regular sendmessage.
It's a java thing :(
I suspected that might be the case. Well, if you have the sourcecode, can't you just modify the game to do whatever you want?

User avatar
3cmSailorfuku
Posts: 354
Joined: Mon Jan 21, 2008 6:25 pm

Re: Java Mouseclicks in the backround?

#8 Post by 3cmSailorfuku » Mon Aug 10, 2009 10:10 am

Administrator wrote:
3cmSailorfuku wrote: Now I understand why it won't pick it up properly, it's using an own control that I can't seem to access only by regular sendmessage.
It's a java thing :(
I suspected that might be the case. Well, if you have the sourcecode, can't you just modify the game to do whatever you want?
It's not in the sourcecode, neither it was done on purpose, it's a java "issue".

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests