Backstory
I've been botting a bit on a private server that aims to remake pre-osrs runescape just for the sake of nostalgia. I could have gone a very traditional route and setup SMART and Simba the gone through the sheer joy of writing pascal scripts, but for various reasons (including utilizing a similar setup for my real job) I decided to switch things up and use python for automation inside a headless X11 server. I'm sharing here because the techniques should be applicable to OSRS and may benefit someone by having a mostly complete reference.
Requirements
- Headless x11 server (or similar for windows)
- Python3+
- Jupyter
- numpy
- pyautogui
- pytesseract (and Tesseract itself)
I'd suggest installing Anaconda and using pip to install the python packages unless they're all in your system package manager.
Details
In principle the code is not linux specific, though you'll have to find some way to deal with mouse take over. Virtual machines, RDP, whatever. On linux I use TigreVNC to start a headless x11 server (vncserver) which I can then vnc into or run totally in the background. Inside of your VNC-like-thing, spin up your runescape client of choice along with a Jupyter notebook. You could reorganize the code in my notebook (below) into python scripts and run them manually, but I like to connect to the Jupyter notebook from my primary workspace and control the macros that way as Jupyter is a pretty nice notebook-IDE complete with code hints.
And that's basically it, you're now ready to run some code.
Design Choices
- All images are numpy arrays, no wrappers.
- Colors are tuples of RGB values (even in images) for clarity.
- Object finding is done by finding colors in proximity to other colors combined with finding clusters of certain counts.
- Didn't use opencv for anything - though this would be easy! (I wanted to implement the search algorithms)
- There is traditional bitmap finding and a homebrew search algorithm similar to opencv template matching (more tailored to RS but a bit slower than the fastest opencv options).
- Scripts are setup as decision trees that are repeatedly called and expected to take the correct action at any point with no/minimal previous state. This is not a requirement but I find it to be quite robust.
The Code
Disclaimer: This is just a teaser not a final product, however for my personal use it's worked quite well. See https://benland.us/files/python-rsps-macros.html for the code and how it looks inside a Jupyter notebook. To run it you'll need to create creds.py in the same directory containing the variables `username` and `password` of the account to login. That won't help you much though because I am not providing the .pngs loaded by the scripts because they're probably useless to anyone else.
If people have questions I might answer here, otherwise catch me on IRC/Discord.
I also wrote a blog post that goes into more detail:
https://ben.land/post/2021/05/21/aut...omputer-games/