A Bot for The Lost Runes written in Typescript as a Chrome Extension
I’ve spent some time and created a bot for The Lost Runes written in Typescript as a Chrome Extension. All you have to do is navigate to the chrome web store page and install it. It’s free and open source.
Features
- Automatically attacks for you.
- Automatically performs tradeskills for you.
- Automatically walks you to a destination.
- Alerts you when a quest has been completed.(audio and title bar)
- Alerts you when a captcha is present. (audio and title bar)
- Alerts you when you receive a private message (audio only)
- Alerts you when a new Game Event is detected, such as a boss (audio only)
- Optionally wait a random period of time before each action, minimizing risk of detection.
- Minimalistic User Interface. It won’t bother you or get in your way.
Why a new bot?
The truth is, the first time I do a project, it works but turns out being non-optimal. The second time around, I expect to fix almost all of the major design flaws and I am pleased with the design. If there is a third rewrite, it is because further requirements have been introduced that weren’t there initially. It’s the same for a lot of software development in real life also. The customer simply doesn’t know what they want until they see what you give them and try to apply it to their actual needs that initiated the project. This is the second revision of the bot, so we will see what happens in the future.
Why Typescript?
I’ve spent the last few days rewriting my bot for the lost runes in typescript. I’ve decided to go a step further than I have in previous articles by walking you through how it was built. I’ve chosen to write the new bot in typescript because it allows me to easily segregate the logic in my code into their own file. It could of course have just been written in JavaScript, but I thought it would be the perfect time to try a new language if for no reason than to see if I enjoy it.
Another very nice side-effects of writing the bot in typescript is that it will allow me to make changes to the bot much easier in the future. It is very likely that The Lost Runes will change at some point in time, breaking my bot. That’s unfortunate, but unavoidable. By using typescript, I have narrowed the scope of everything, allowing me to quickly identify what needs changing and change it without worrying about affecting other code as much. It is much less like spaghetti code.
Environment
You can view the entire source code for my bot at bitbucket HERE.
I chose to avoid Visual Studio for this project, because I know how being locked into windows can feel. Instead, I take advantage of the typescript compiler that you get with npm and a few other packages that watch my project hierarchy for changes and invoke the compiler when necessary. To build my project, all you need to do is cd to the project directory and run npm link. This will go download all of the development dependencies. Once finished, simply running ‘grunt typescript’ will build a new tlrbot.js and put it inside the dist directory.
The dist directory is what is packaged up as a chrome extension. Google provides quite good documentation for how to build a chrome extension, it really only depends on you having a manifest.json file that tells chrome what your extension is all about.
The modules directory contains typescript definitions for non-typescript types. For example, you will see a jquery.d.ts file as well as a chrome.d.ts file in there. The chrome.d.ts file was made by me, so you may not find it elsewhere. It allows me to tell Typescript about the chrome.exension.getURL() method.
The app directory contains the actual code for the bot, and the AppConfig.ts file is our entry point. It is not wrapped in any kind of module and is very much just plain JavaScript with the exception of the first two lines. It allows us to kick-start our bot after making sure that all dependencies have been loaded with the help of require.js. All of these classes will be compiled down to a single JavaScript file that chrome uses.
Basic Design
The basic idea behind the new design was to abstract away the portion of code that gathered information from the game from the logic that performs actions based upon that information. In order to accomplish this, I created first, a StateManager class whose responsibility is simply gather information and fire ‘events’ when information we care about changes. A majority of the ugly code that has to rely upon screen-scraping the game data is inside the StateManager class.
I created different ‘Bot’ classes for each of the major functions of the bot (BattleBot, TradeskillBot, WalkBot, and NotifyBot). Each of them registers for events from the StateManager and handle them accordingly. You should be able to see the benefit now of organizing the code this way.
I would say the only other portion worth pointing out is the UserInterface class, which is responsible for creating the bar across the top of the page and for handling user input. This class also exposes some events such as when the bot is paused or the Walk button is pressed.
TL;DR
If you’re just here for the download and don’t really care about anything else I have to say, the link to the chrome web store page is right HERE. I have to warn you again, however, that you may very well get banned for using this. I’ve made every effort on my part to help make the bot as inconspicuous as possible to help minimize the risk that you will be caught, but that is no guarantee.
