thomas-crane / famebot

A bot for Realm of the Mad God designed to automate the process of collecting fame.
MIT License
19 stars 12 forks source link

Fixed issue #21 #26

Closed OFFTKP closed 7 years ago

OFFTKP commented 7 years ago

Ok so now it's fixed I think.

When I would deactivate w_pressed etc. on the older commits it would stop moving correctly.

My solution: Started a new thread that runs while famebot is enabled Every 200ms it checks if the ForegroundWindow has changed. If it has, if the old foreground window wasnt the flashplayer, just set the variable of the old foreground window to the new one. If the old foreground window was the flashplayer (which would mean the bug would occur) Set all w_pressed etc. to false, and re-run calculateMovement with the last specifications that were ran.

I added 2 variables latestTolerance and latestTargetPosition that get updated with each calculatemovement and are used by the thread to recalculate movement after disabling all the "pressed"'s

Why I added a new thread

To avoid referencing the System.Windows.Automation dll to check when a window loses focus. It's a cheaty-ish way to check if focus changes and it works nicely and cpu usage looks the same to me.

thomas-crane commented 7 years ago

Thanks for this fix. I found another solution as I was going over your one: I added a lastLocation variable which is then compared to the current location on every NewTickPacket. If the two are the same, the keys are reset. This fixes the current issue as well as providing a good reset mechanism in case the bot stops moving for some other reason. What are your thoughts on the solutions?

OFFTKP commented 7 years ago

Good thinking, solves the problem without the need of a new thread, and in a more simplistic way. I like your solution, and now issue 21 is fixed 👍

thomas-crane commented 7 years ago

Awesome, I will close this PR and the issue now.