SRL Archive - S.M.A.R.T.

Smart Talk Fix?


Brandon

2011-07-27 15:53:45

[ATTACH]11480[/ATTACH] [ATTACH]11481[/ATTACH]

I noticed that when Smart is minimized and then restored to the screen, it has to regain focus and it has to Re-enter a thread.. but that thread only checked for mouse clicks on the client I believe.. so I added the part for detecting keyboard events.. Also when smart is just starting up (not at login screen yet), all keyboard and mouse events are passed through the eventnazi without lag.

Another problem is that Smart only allows input through the event nazi when the mouse is clicks on the client.. So while smart is using the mouse, input cannot go through… U'd have to either minimize/restore smart to restart the thread for input.. or u can spam click the client really fast while typing with another hand to get input to the screen.. This is because it gains focus when you click the screen for some reason.. I looked at the ClickMouse procedure and noticed it does getfocus().. but the movemouse one doesn't so while the mouse moves, u can't type.. and while its clicking, u can type.. but our scripts click so fast the input doesn't go through..

Below is my edits to the client that lets input through after u minimized a couple times to re-enter the thread.. Right now Im typing right through smart just like RSBuddy and RSBot but it only works after I after the thread is transfered.. so basically when your script logs u in and starts, just minimize and restore twice.. and let the script do whatever.. if u try typing, it will go straight through without lag.. Tested with My fungus script, Flight's ZMI and Livid Farmer.

Bugs: Sometimes the first letter of a sentence doesn't go through but this is rare..

Client.Java

blitThread = createBlitThread();
BlockingEventQueue.addComponent(canvas, new EventRedirect() {

@Override
public void dispatched(AWTEvent e) {
if ((e instanceof MouseEvent && e.getID() == MouseEvent.MOUSE_CLICKED) || (e instanceof KeyEvent)){ [B]//Added the KeyEvent Part..[/B]
clientFrame.requestFocusInWindow();
}
}
});
EventNazi.java Added the getfocus and loosefocus..

public synchronized Point windMouse(int x, int y) {
if (canInteract()) {
if (!focused) getFocus();
double speed = (Math.random() * 15D + 15D) / 10D;
if (!mousein) looseFocus(false);
return windMouseImpl(cx,cy,x,y,9D,3D,5D/speed,10D/speed,10D*speed,8D*speed);
}
return null;
}

public synchronized Point moveMouse(int x, int y) {
if (canInteract()) {
if (!focused) getFocus();
return moveMouseImpl(x,y);
}
return null;
}
Your going to Have to Change the Extension back to .DLL if you plan on using the precompiled on below..

Coh3n

2011-07-27 18:49:20

Wow nice find! :)

I don't really know if you said, but why do you have to minimize/restore a couple times before it'll work?

Brandon

2011-07-27 18:59:26

From: Coh3n
Wow nice find! :)

I don't really know if you said, but why do you have to minimize/restore a couple times before it'll work?


Because The only time the console says "Thread Transfered" is when you minimize.. and when you minimize it creates that bltthread.. thats where that over-ride code goes.. I tried to put it where right before and after the thread starts but it crashes smart.. so it can only go in the middle.

Since its in the middle then we gotta minimize once or twice inorder for the thread to transfer thus doing the procedure and giving us input. After that u basically don't have to minimize or disable anymore.. it automatically just gives input.

Its also faster to just minimize it once to get the thread going rather than to wait 2-3 minutes for it to start.

masterBB

2011-07-27 19:08:18

Rep++;

This was annoying me for so long!

Echo_

2011-07-28 08:01:28

Nice snippets, I hope they get added officially :)

Coh3n

2011-07-28 09:56:47

From: ggzz
Because The only time the console says "Thread Transfered" is when you minimize.. and when you minimize it creates that bltthread.. thats where that over-ride code goes.. I tried to put it where right before and after the thread starts but it crashes smart.. so it can only go in the middle.

Since its in the middle then we gotta minimize once or twice inorder for the thread to transfer thus doing the procedure and giving us input. After that u basically don't have to minimize or disable anymore.. it automatically just gives input.

Its also faster to just minimize it once to get the thread going rather than to wait 2-3 minutes for it to start.
Ah I see, okay. This may sound stupid as I know nothing about C++, but couldn't you just create the bltthread when SMART starts?

Also, if you want this added officially to SMART, I remember Ben saying the best way is to send a pull request through github.

Brandon

2011-07-28 12:38:20

From: Coh3n
Ah I see, okay. This may sound stupid as I know nothing about C++, but couldn't you just create the bltthread when SMART starts?

Also, if you want this added officially to SMART, I remember Ben saying the best way is to send a pull request through github.



Im trying to do that… right now.. atm the blitthread already starts but when u reach the login screen, all focus and input is given to the script..

When simba is minimize and restored, the canvas changes and then target(Canvas it) notifies the client of the change so that it adapts accordingly.. only then does that snippet above get called and give us the input again..

I added a button to smart called Refresh and I'm trying to get it to call Target() so that it refreshes when you press it and you get input.. Basically simulate minimize and restore without actually doing it.

The snippet above is written in java so its a bit of a task for me as I only know how to write C++ and read other languages but not write them.. so its kinda a learning process at the same time..

Yago

2011-07-28 12:44:15

Maybe we can help… I know 10% of java (a bit) :) What missing?

Carlito

2011-07-28 12:46:12

wow very nice work, hopefully this can get inputted

Coh3n

2011-07-28 19:39:49

From: ggzz
Im trying to do that… right now.. atm the blitthread already starts but when u reach the login screen, all focus and input is given to the script..

When simba is minimize and restored, the canvas changes and then target(Canvas it) notifies the client of the change so that it adapts accordingly.. only then does that snippet above get called and give us the input again..

I added a button to smart called Refresh and I'm trying to get it to call Target() so that it refreshes when you press it and you get input.. Basically simulate minimize and restore without actually doing it.

The snippet above is written in java so its a bit of a task for me as I only know how to write C++ and read other languages but not write them.. so its kinda a learning process at the same time..

Sounds pretty good so far, and there are a lot of people here who know quite a bit of Java, so they should be able to help out. You can always post in the Java Programming section if need be.

Keep at it, you're doing great. :)

BenLand100

2011-07-29 08:56:55

None of this is doing what you think it is (I can say that for certain because the blitThread is always running in some form, its the one that transfers the image to Simba. target, as well, must be called for ANYTHING to work, so minimizing/restoring the window later just invokes it mroe time), but you might have pointed me towards another bug that could potentially be a problem. (i.e. the new canvas could be grabbing focus so that nothing ever makes it to the frame like I would want it to)

Let me educate you a bit on how these pieces work once I get to another place with internet (someone bug me on IRC if I forget)

Brandon

2011-07-29 10:58:18

Uhh it might not do what I thought it does but it definitely works.. without the (e instanceof KeyEvent)… minimizing and restoring while smart is enabled does nothing.. I tried it first before I added it.. minimized and restored quite a lot and no keys went through.. I added that and it started letting keys through :S

Oh and I wanna know why the canvas goes black when transferring because I was reading up on how to write java and it says something about not painting right. cuz when rsbuddy and rsbot minimize and restore, the canvas is stll the same.. it doesn't change/transfer? I guessed that because it doesn't go black at all.. or maybe it just does it so fast we can't see it.

oh and the reason I wanted to change .stop to .join was because I saw stop is no longer used and considered dangerous and I wanted to make sure that the thread actually does stop before smart does anything else.

For the button I messaged you about I did this – Because I saw that that u have to notify and target the canvas then stop blocking and stop the thread, create thread and start blocking.. but I get some null pointer thing when I run smart and something about JNI in a native call warning.. No errors during compiling though.
Educate me pls:

http://pastebin.com/raw.php?i=h6nm738m

Yago

2011-07-29 13:01:23

This is turning interesting :)

BenLand100

2011-07-29 16:36:01

From: ggzz
Uhh it might not do what I thought it does but it definitely works.. without the (e instanceof KeyEvent)… minimizing and restoring while smart is enabled does nothing.. I tried it first before I added it.. minimized and restored quite a lot and no keys went through.. I added that and it started letting keys through :S

Side effects you don't understand. The things you are doing are unnecessary and, quite honestly, wrong.

From: ggzz
Oh and I wanna know why the canvas goes black when transferring because I was reading up on how to write java and it says something about not painting right. cuz when rsbuddy and rsbot minimize and restore, the canvas is stll the same.. it doesn't change/transfer? I guessed that because it doesn't go black at all.. or maybe it just does it so fast we can't see it.

What goes black, the memory buffer or the image? Memory buffer shouldn't, image doesn't matter. Remember, all those java bots do completely different things than SMART

From: ggzz
oh and the reason I wanted to change .stop to .join was because I saw stop is no longer used and considered dangerous and I wanted to make sure that the thread actually does stop before smart does anything else.

It stops when you stop it. Only dangerous if you are doing things that could cause a deadlock. Join is just silly

From: ggzz
For the button I messaged you about I did this – Because I saw that that u have to notify and target the canvas then stop blocking and stop the thread, create thread and start blocking.. but I get some null pointer thing when I run smart and something about JNI in a native call warning.. No errors during compiling though.
Educate me pls:

http://pastebin.com/raw.php?i=h6nm738m

Unnecessary and, quite frankly, wrong again. Sorry if I sound blunt or assholish. The result you are achieving is a side effect and the things you are doing are dangerous from a detectability standpoint. Adding a button won't fix the problem. Plus, I can't take your reasoning seriously when all you're doing is reading back the names of the methods that get called, lol

Brandon

2011-07-29 17:07:57

:c So what I did was wrong? then how do I fix it? what about the things I did in the first post.. if I can't add the button is the first post right then? where I added the keyboard event thing? What different things do those java bots do than smart beside colour finding and bitmap and ocr stuff? They all bot runescape… Smart can't be used for anything else as far as I see it..

Uhh I don't mind if ur being assholish im only learning something. I don't know java much so if u say im wrong I'll accept that. Uhh the thing that goes black is when u minimize smart and restore, the screen itself is black and the JFrame is still there.. and why does smart give input when minimized and restored.. but only with the changes I made in the first post.. it never gives input if those changes aren't there :S if they are side effects I don't understand then can u explain them to me?
Detectable how? I only stopped the thread and transferred the canvas then restart it the same way u had…

BenLand100

2011-07-29 17:20:35

The way SMART handles the graphics is different, it's understandable that it goes black when you restore, it's just a side effect of the way I did things (which is just the best way to do it for this application).

Your KeyEvent and getFocus additions just don't do anything useful. Granted, the KeyEvent thing is probably not a bad idea, but clicking should have the same effect. The get focus things are completely unneeded because it will get focus when keyevents arrive, they (for some unknown reason) are simply not arriving as expected. This is probably because the client frame is not maintaining focus which is what I quickly tried to fix. (Granted, I figured out this is the problem by noticing that a side effect of your changes is how often the client frame tries to grab focus). It's ALWAYS worked fine for me, so I'd appreciate if someone could test it on their machine.

Binaries: http://bland.no-ip.org/files/SMARTv6.7beta.zip
Source: see github

Brandon

2011-07-29 17:29:09

From: BenLand100
The way SMART handles the graphics is different, it's understandable that it goes black when you restore, it's just a side effect of the way I did things (which is just the best way to do it for this application).

Your KeyEvent and getFocus additions just don't do anything useful. Granted, the KeyEvent thing is probably not a bad idea, but clicking should have the same effect. The get focus things are completely unneeded because it will get focus when keyevents arrive, they (for some unknown reason) are simply not arriving as expected. This is probably because the client frame is not maintaining focus which is what I quickly tried to fix. (Granted, I figured out this is the problem by noticing that a side effect of your changes is how often the client frame tries to grab focus). It's ALWAYS worked fine for me, so I'd appreciate if someone could test it on their machine.

Binaries: http://bland.no-ip.org/files/SMARTv6.7beta.zip
Source: see github



I just tested that.. its different than the version Simba comes with… on that one u have above, typing works through smart but with a very slight delay/lag of about 2 seconds total.. but in 6.6 it doesn't work at all!

For some reason whatever u just changed in that 6.7 beta, smart no longer shows PassingKeyEvent(e…..) etc.. it no longer debugs that in the console.. instead the key event just goes right through but with the slight delay like i mentioned.. care to share what u changed? Oh and while the script is using the mouse, input is delayed even longer (quite long) until the mouse becomes still. A minimize and restore + a 5 second wait.. makes the input instant! :O and now it also shows how many people have loaded smart… and how many times it was loaded.. u changed a lot?!

Edit: whatever u did, smart now grabs focus automatically.. when I try to click the console, smart puts itself on top now.. it recognizes a different window is clicked and so the console is behind smart doesn't do that for other windows though but it keeps its focus. Also spams debug a lot less.. seems to concentrate on keeping focus thus making typing exactly the same speed as rsbot/rsbuddy and my scripts are snappier and run better :S

Nice stuff.. definitely works. so instead of just doing the keyevent and mouse like the first post, u did it for all event :D and when minimized or activated or restored, it grabs focus.. Works for me and thanks for taking the time to fix it! Much appreciated! I am a happy lad now I'll go on my way.

Coh3n

2011-07-29 17:55:13

This sounds awesome, maybe the new version can be included with Simba 0.97. Also, any word on the "SMART Declaration error"?

Brandon

2011-07-29 18:08:56

From: Coh3n
This sounds awesome, maybe the new version can be included with Simba 0.97. Also, any word on the "SMART Declaration error"?


e.printStackTrace();
JOptionPane.showMessageDialog(null, "Error starting SMART, ensure the target page has an applet declaration", "SMART", JOptionPane.ERROR_MESSAGE);
I think u mean that part… Uhh if we can make smart start java then that error won't come.. I do it all the time.. whenever rs updates, I just go to start menu, type Java.. click it when it shows the little java icon in the system tray, I start smart and then it works.. I heard people saying that u have to load runescape in a browser first.. well that does the same thing because it starts a java applet.

Not sure what ben means by this:
/**
* Creates a new SMART java instance with the given native buffers, allocated size, and startup params.
* This method can take some time, but returns as SOON as the applet is loaded, i.e. does not wait
* for the applet to finish setting itself up.

*/

it should probably wait for the applet to start at least? Unless it already does that.. that Im not seeing.

BenLand100

2011-07-29 20:47:08

From: ggzz
Edit: whatever u did, smart now grabs focus automatically.. when I try to click the console, smart puts itself on top now.. it recognizes a different window is clicked and so the console is behind smart doesn't do that for other windows though but it keeps its focus.

I have no idea what you mean by this. Please try to form complete thoughts and separate them into complete statements. You're saying SMART always tries to put itself on top of… console? You mean the Simba console? Does it try to take focus from Simba or anything else?

From: ggzz

/**
* Creates a new SMART java instance with the given native buffers, allocated size, and startup params.
* This method can take some time, but returns as SOON as the applet is loaded, i.e. [B]does not wait
* for the applet to finish setting itself up.[/B]
*/

it should probably wait for the applet to start at least? Unless it already does that.. that Im not seeing.

It waits for the applet to start, but it doesn't wait for runescape to finish loading (no easy way to check for that). Completely unrelated to anything. Could someone give me the stack trace for the ensure applet declaration error? E: The error is called an "ensure applet declaration" error because the MOST LIKELY cause is the page that was loaded has no applet declaration (the <applet> tag in html), which is an error external to the internal workings of SMART. Could be that you just need to load the HTML page after differently after an update… but yea, stack trace will let me know more about that.

Also, that stuff about how many times SMART has been loaded is a side effect of this not being an official version, it will go away for an official release.

Brandon

2011-07-29 22:56:14

From: BenLand100
I have no idea what you mean by this. Please try to form complete thoughts and separate them into complete statements. You're saying SMART always tries to put itself on top of… console? You mean the Simba console? Does it try to take focus from Simba or anything else?


Nah it only takes focus from the Simba console.. Like if you have the simba console on screen and smart on screen at the same time.. click smart. Next click the console and wait a couple seconds. It will auto switch the window to Smart so smart stays on top of the simba console. No it does not do this for anything else. Only the simba console so I guess its fine.

As for applet declaration thing, how do u get the stacktrace if it crashes simba aswell.. It crashes and just leaves a textfile on the desktop with random crap in it.

BenLand100

2011-07-29 23:49:17

It crashes simba? lolwat… It just throws an exception in java…

Brandon

2011-07-30 01:28:13

Iunno about u guys but simba automatically closes/crashes for me when I get that error..
then it leaves a text file called: hs_er_pid2212
with stuff like (which I usually just delete):

#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000, pid=2212, tid=4868
#
# JRE version: 6.0_26-b03
# Java VM: Java HotSpot(TM) Client VM (20.1-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C 0x00000000
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#

masterBB

2011-07-30 08:03:05

From: BenLand100
It crashes simba? lolwat… It just throws an exception in java…


Nop, it opens an error dialog screen. And if I press 'ok' simba closes.

e:
Are you sure it has anything to do with the applet declaration? You call it for every exception while loading.


Yago

2011-07-30 16:32:08

it closes simba for me…

BenLand100

2011-07-30 20:36:06

From: masterBB

Are you sure it has anything to do with the applet declaration? You call it for every exception while loading.


The ONLY thing that changes is the webpage, obviously it has to do with the declaration. I added in some checks for null pointers, but I really don't understand why this error is happening at all