One of the key challenges to building a simulator such as this one is to utilise good software.
The Simpit builders have it lucky – as they have such great sims as Flight Simulator X and Falcon 4. Both of these include support for external interfacing.
The train simulator community isn’t so lucky – MSTS is still an excellent program and it is the one that I have chosen to power my simulator, however lacks any form of API – something that is a huge drawback. There have been an number of attempts to over come this – the Raildriver product uses a “screen scrape” of the data – a novel idea but something I would like to avoid.
Doug Johnson, with his “My Ultimate Toy Train” project, provided some answers – if you read his excellent project report (site link on the Blogroll) he did a lot of the ground work in getting data out of MSTS using the excellent “Cheat Engine” tool.
However, I have taken his ideas one step further. MSTS allows for data to both be extracted and input back into the simulator – avoiding any need to develop a keyboard emulator or the like.
Utilising the same concepts as Doug, I developed a series of patches for MSTS that create a code cave in which a sequence of pointers is stored to key values within MSTS. Then it is simply a matter of writing and reading to these addresses and you can control MSTS externally!
What is also interesting is that as well as providing input for the brake and master controller inputs, MSTS will also allow you to change other operational parameters and it will behave accordingly.
For example, it is easy to simulate a breakaway by reducing the value of the brakepipe to 0, MSTS then automatically applies the brakes (as is prototypical of the Westinghouse system). Also prototypically, it does attempt to keep recharging the brakes – until of course you lap the brake valve.
It’s a bit hard to see in the screenshot below – however this is Chris Jennings’ B-Set sitting at Central platform – on the right is a quick piece of VB code that is reading (and writing) data into the memory space of MSTS. The number at the top reads 95.6666 which is the brake pipe pressure – the number on the left is 0 which is the current amps being pulled. (The throttle is closed here). The words are “CAFEBABE” which is a test hex string for debugging and the buttons activate the brakes externally to MSTS.
Simulator Software - MSTS showing connection to a VB6 app
This next screenshot shows us accelerating at the end of the platform – the amp gauge now reads 379.5977 and the brake pipe 110. Note – this is configured as “straight westinghouse” in MSTS. The Red Rattlers used an EP brake – but I’ll get to that in the next post.
Simulator Software - Accelerating Screenshot