I’ve been obsessed with the Diablo-like game Path of Exile for the past few months. Great game. For the code nerd in me, I’ve been fascinated by how the community has created a bunch of addons and tools to run with the game, despite the game having no support for them. The kludges are thick and woolly and fascinating.
The primary way most of these addons work is via AutoHotKey, a Windows-specific scripting system that occupies a role a little like AppleScript does on MacOS. AHK has been around forever; its main feature is that it’s very good at capturing global keyboard events and doing odd things in the background that don’t fit the usual GUI paradigm. I use it to remap CapsLock to search Google, for instance.
PoB Item Tester is the most complex addon I know. You hover over an item in the game, press Ctrl-C to copy its description to the clipboard, then press Ctrl-Win-C to have a window popup that shows what the item would do if you used it. Behind the scenes it’s using Path of Building to do calculations that simulate game behavor. PoB is a standalone Windows program that itself is a tour-de-force of reverse engineering. It is a full GUI program written in Lua (!).
Functionality aside, it’s the integration that I’m interested in. Here’s what the AutoHotKey script does:
- Hook Control-Win-C with AHK to get the item from the Windows clipboard and pass it to TestItemFromClipboard
- Write the item to a file on disk
- Invoke a Lua script from AHK
- Pop up a window based on some GUI setup done previously.
- Get the file created by the Lua script and display the contents
- Set up the Mock GUI. Buried in there is the part that launches Path of Building’s Lua code.
- Tell PoB to load the build to test against
- Create an Item object based on the file written by AHK (from the clipboard). These seems to do the actual simulation calculations.
- Capture the item’s tooltip as HTML and write it to a file for AHK to display.
So there you have it. The game sure wasn’t designed to be scripted, but clever use of the clipboard and keyboard hooks lets people write scripts that feel like they’re running in-game. Path of Building wasn’t written to be scripted either, but someone figured out how to hack the Lua to get it to run headless and do calculations for them. That’s a lot of very motivated hackery, I’m impressed.