Trials Fusion Bot
I’ve thoroughly enjoyed playing both Trials Evolution and the recent Trials Fusion sequel. The Trials games are physics-based off-road motorcycle simulators, requiring the player to negotiate tricky ramps and obstacles, using just throttle, brake and leaning the rider forward and back.
The objective of the game is to complete each track as quickly as possible with a minimum number of faults. Since levels play out exactly the same each game, this game seemed to me to be the ideal candidate for adding some automated assistance.
I pondered how to do this for quite some time, trying various ideas. Eventually I came up with a solution I was happy with.
Firstly, this solution isn’t a bot like this one. It is simply a tool that allows the user to record their gameplay, edit the recordings if necessary, and play them back into the game.
Secondly, Yes, this is cheating and No, I am not going to make the code available. This was a fun little project for my own personal entertainment. I used it for the thrill of seeing my rider pull off some tricky moves that I was struggling with in the Inferno IV level, then put it to one side and haven’t used it any more.
I went through a couple of iterations before settling on the solution I liked. Breaking the problem down into separate parts, normally a good idea, this time lead me astray a little as I attempted to address each of the parts I needed separately. In the end one piece of code I wrote was able to handle everything, using a fairly simple technique.
The tool I wrote is a DLL file which drops in the game installation directory and pretends to be the xinput1_3.dll joystick input handling code.
I used the excellent DLL_Wrapper_Gen tool by Min Lin to generate the source code for a fake version of xinput1_3.dll that would emulate the original DLL by loading it in and forwarding calls to the fake DLL on into the original library. Several people on the internet have written a tool to do this and I tried a couple of them without success until finding Min’s which worked smoothly and easily.
Inside the code generated by DLL_Wrapper_Gen, I needed to supply my own code to replace the XInputGetState call. This function is called by the game every frame to see which joystick buttons are being pressed. By faking the results I can replay my own data into the game whenever I want to. Alternatively I can look at the results of the actual call to XInputGetState and record the joystick state into a text file for later playback. I use joystick buttons that aren’t used by the game to control playback and recording. The code to do all of this is pretty simple.
I found that editing the recorded joystick data is quite tricky. It is a list of numbers to say what position the sticks are in, which is very difficult to match up against the onscreen action. I had hoped to complete checkpoints in the game one by one, recording them one at a time, then edit the recordings into a single file that could be played back to run through the level without faulting. I did this for the first few checkpoints of Inferno IV, the hardest level in the game, and while it was possible, it took a lot of fiddling with the data files and retrying in order to get it right.
The end result is that now at the press of a button on my joystick I can sit back as the DLL takes over the game and automatically drives my rider over the first five checkpoints of Inferno IV without faulting. This is something I certainly can’t do on my own!
I’d imagine that this technique could be applied to other games that require fixed precisely timed actions, examples maybe being Super Meat Boy, Bit Trip Runner, or possibly even the Guitar Hero series of games.
The idea of replacing DLLs with imposter versions can be used for other purposes, too - for example intercepting graphics system calls in order to extract 3D game models; or snooping on network calls.
Additional Credits
I used the joystick functions in SDL for some of my initial tests.
The onscreen joystick display is a plugin for Open Broadcaster screen casting software.
The idea for replacing the joystick DLL came from joypad converter software xbox360ce.