Page 1 of 1

Java Mouseclicks in the backround?

Posted: Thu Aug 06, 2009 9:46 am
by 3cmSailorfuku
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.

Re: Java Mouseclicks in the backround?

Posted: Fri Aug 07, 2009 12:15 am
by Administrator
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.

Re: Java Mouseclicks in the backround?

Posted: Fri Aug 07, 2009 6:49 am
by 3cmSailorfuku
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.

Re: Java Mouseclicks in the backround?

Posted: Fri Aug 07, 2009 8:14 am
by Administrator
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.

Re: Java Mouseclicks in the backround?

Posted: Fri Aug 07, 2009 2:51 pm
by 3cmSailorfuku
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.

Re: Java Mouseclicks in the backround?

Posted: Sun Aug 09, 2009 9:06 pm
by 3cmSailorfuku
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 :(

Re: Java Mouseclicks in the backround?

Posted: Mon Aug 10, 2009 7:11 am
by Administrator
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?

Re: Java Mouseclicks in the backround?

Posted: Mon Aug 10, 2009 10:10 am
by 3cmSailorfuku
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".