Speedrunning Portal 2 on Linux

I went on a bit of an adventure over the past few weeks in a move from Windows to Linux full time. Over a few months of dual-booting I'd taken care of the big, critical hurdles, and finally decided to pull the trigger. One that was still on the list was getting Portal 2 and its speedrunning tools up and moving, and jumped in knowing more or less that there are people who run on Linux, but not necessarily how. Through some trial and error, I got things working for my setup and hope to capture here some of what I learned.

The major hurdles were getting Portal 2 to display correctly and learning how to configure Adrift – I've detailed things below but the major bullet points are:

Steam and Portal 2

For Steam, use your preferred method of install for your distro. Many distros have current versions of steam in their package repos, but a .deb/.rpm package straight from valve or install from a flatpak/snap store should be just fine. Install Portal 2, but don't sweat turning Proton on – we need to run Portal 2 as its native Linux version for compatibility with the current version of Adrift.

Install the Linux release of SAR by placing sar.so in your Portal 2 install folder (usually .steam/steam/steamapps/common/Portal\ 2/. Optionally, consider also installing srconfigs in addition to SAR, which provides enhanced functionality and control. Both are cross-platform.

Finally, launch Portal 2. If you're on a single-monitor setup, or you have a multi-monitor setup where your leftmost monitor is your primary, odds are Portal 2 will have launched at the right resolution and position. You're good to move on to setting up Adrift. If you're like me and have a non-conventional monitor setup, or even just a multi-monitor where you don't want the game on the far left monitor, there will likely need to be a little extra to do. This will take some adjusting depending on your specific needs.

I found that if I launched Portal 2 with no parameters, it would try to display at the full resolution of the “rectangle” that encloses my monitors display area, and lock to my center monitor with scaling that wouldn't allow me to interact with anything but the top-left of the window via mouse, and an inability to confirm settings changes via keyboard. This means configuring, generally, through the in-game menus is out.

In Steam, you can add launch parameters by right-clicking on the game in your gameslist and selecting “Properties”. The key options that got 90% of the way there were:

For a full list of launch options, see here.

For my particular use case, -sw -w 1920 -h 1080 -x 1280 was the right combination to position the Portal 2 window on my center monitor at the right resolution.

Past this, you may need to take care of a desktop panel, if applicable, as any existing panels will likely try to draw over top of the Portal 2 game window. In KDE, I set an Application Window Rule to force Portal 2 to be fullscreen from the DE (as opposed to the application). This locks Portal 2 to the monitor and allows it to draw on top of the KDE taskbar panel. Alternatively, one could set the panel to hide automatically or move it to another location. Continue to work the settings until you're satisfied with where Portal 2 launches and displays.

Setting Up Adrift

For Adrift, pre-compiled binaries are avaialble on the releases page. v0.1.1 was most current as of this writing. If you go this route, grab both the “adrift” binary download and the “splitters.tar.gz” archive.

If you'd prefer, you can compile from source – adrift requires a special build of vtk to also be built and installed from source, which itself requires libcairo2-dev and libgtk2.0-dev on Debian-based systems (or the equivalent for your system). More detail is on each project's page for building.

As a high-level overview, Adrift is a timer built on using autosplitters for program control, and cannot be manually controlled, and is pretty bare-bones, which means it's really only suitable for Source engine games such as Portal 2. Being pretty minimal, that means there's a little setup Adrift needs before it can be used.

By default Adrift will look for three files – splits, splitter, and config – in the same directory where the adrift executable is located, but a directory with a set of files for a particular game can be specified at launch time by passing the directory as an argument (eg, ./adrift p2_amc), which can be useful if you run multiple games or categories. For example, if you run both Portal 2 singleplayer and co-op, you might have a directory for portal2_nosla and portal2_amc that each have their own splits and config for Singleplayer No SLA and Co-Op All Main Courses specifically, which will also allow gold splits and peronal bests to be separated. For the rough purposes of this guide, we'll assume a flat structure with all files in the same directory as the Adrift executable – you can always restructure for your particular need if you choose to later.

  1. Make a splits file – it is required that a splits file be present, otherwise Adrift will not start. Each line will have a split name. Typically, one split for each chapter or course will suffice with a default SAR configuration. This file should be named “splits”.
  2. Extract the splitter file – the splitters.tar.gz archive has a few contents, but what we need is the sar_split file. Place this in the same folder as the Adrift executable and rename it to “splitter”.
  3. Create a “config” file – The Adrift github page has details on what options Adrift supports, but at minimum you'll likely want to change the category name to match what you're running. By default, Adrift shows Portal 2 No SLA, with white text on a transparent window.
  4. Make Adrift executable – Change adrift's permissions to allow it be executable from either your file manager (Right-click –> Properties), or by running chmod +x /path/to/adrift/executable From here, Adrift can be run either by double-clicking the executable in your file manager, or navigating to the folder where you have adrift stored in your terminal and executing with ./adrift.

Adrift should launch using your config files, and if you launched from terminal you should also see status messages as Adrift searches for the Portal 2 application process. If Portal 2 hasn't yet been launched, do so and verify that Adrift finds the process via the terminal messages. If there are issues, Adrift will give confirmation both when it finds the portal2 process and when it makes connection with SAR, which should help to give indication of where to start troubleshooting.

Start Running

That's the critical minimum to get up and running. From here, Reference SAR and Adrift documentation for additional configuration and customization to meet your needs. Speedrun timing should start when you launch either a Single Player or Co-Operative Game, and using the do_reset command during or following a run should reset the timer and your game both for a fresh run.

Be sure also to visit the Portal 2 Speedrunning Discord server for dicussion, help, and support. Much of the information here is an amalgamation of information from P2SR and the members' effort in gathering resources and creating tools are what allow this to be possible in the first place.