Update Dec 2024: It’s my absolute pleasure to announce that the described hoops are no longer necessary and much of this content is now obsolete. Egosoft added native head tracking via OpenTrack into X4 Foundations starting with the public beta 7.50 after all my nagging! It’s like a miracle. Check a short demo video at https://www.youtube.com/watch?v=rgOkGwMShT0
This is the journey of getting head tracking for X4 Foundations on Linux. Browsing the in-game options I found key bindings to enable and reset a head tracker so I got my hopes high for head tracking for X4 on Linux and started reading.
tl;dr: The native build of X4 does not support this at all. It even lacks the symbols in the executable. There is hope with Wine though.
While seeking through the patch notes two things catched my eye (harhar). The notes suggest support for Tobi Eyetracker and somewhat earlier TrackIR. The Tobi one was marked as “Windows only” so I hoped for TrackIR and tried to understand what is involved into getting this particular head tracking to work.
Please do keep in mind that I never touched any head tracking before so I had to grasp the theory behind all this first.
So apparently there are not many possibilities to configure anything in-game. There is the additional start parameter -forcehmd
that may have some effect here but that’s about it. So everything related must come from the outside, right?
Funny enough a Kerbal Space Program extension on GitHub provided me with the idea how TrackIR is supposed to function: https://github.com/pizzaoverhead/KerbTrack/blob/master/KerbTrack/TrackIRClient.cs#L45 so let’s clear that one up: The code looks for the registry entry “Software\\NaturalPoint\\NATURALPOINT\\NPClient Location
” that points to the NPClient.dll
(or NPClient64.dll
) which in turn in loaded by the executable if found and accessed. And sure enough I found the same pattern by using the good old hexeditor on X4.exe
as well:
You may suspect this already but none of that can be found in the X4 binary for Linux and this is the end of the story.
Appendix: It might be possible that a joystick look-around thingy may be abused for this but since I do not own such a joystick (yet) I wouldn’t know how to fake such signals.
A new hope
During my research on head tracking on Linux I stumbled over the website https://tkoletivrijedi.in.rs/node/219?language=en that mentioned the OpenTrack project https://github.com/opentrack/opentrack to play Windows games with Wine on Linux. How cool is that? A quick check suggests that OpenTrack features (also) the output protocol “freetrack” for Windows and a “Wine freetrack glue protocol” for Linux and OSX.
Freetrack seems to be a implementation of what TrackIR does up to version 4. Looks like the company didn’t like that or was afraid that some tinkerers use self built head tracking devices and not buy their ~200$ hardware any more so they added encryption to their devices with version 5 leaving freetrack dead in the water. Or whatever. So if a game would only support protocol 5… it’ll probably no longer work. Anyway, let’s jump into OpenTrack and give it a try. Once all required developer packages are installed, that includes the wine-devel packages for i686 (and libevdev if you want virtual joystick support), this can be compiled:
git clone https://github.com/opentrack/opentrack cd opentrack mkdir build cd build ccmake ../ make -j4 make install ./install/bin/opentrack
The important part is to tick the SDK_WINE
option or we don’t get the precious Wine Glue. Here, have a video:
And sure enough we find the following already familiar files in install/libexec/opentrack/
- NPClient.dll
- NPClient64.dll
- TrackIR.exe
- opentrack-wrapper-wine.exe.so
So what OpenTrack does is once it’s started and configured to use “Wine — Windows layer for Unix” as Output: It “injects” the key [Software\NaturalPoint\NATURALPOINT\NPClient Location]
to the user.reg
of the configured Wine/Proton prefix on start while the also started opentrack-wrapper-wine.exe.so
is used for the shared memory mapping – means from my understanding from the OpenTrack binary to some Wine process. TrackIR.exe
is just a dummy that may also be run with Wine but does nothing. It’s apparently for games that check for a process with that name before they initialize head tracking features. Neat, huh?
For this to work you have to click on the little hammer symbol next to Output so make sure that your Wine Prefix is properly configured or OpenTrack may insert the registry key to the wrong Wine prefix. Sure enough it seems to come Steam and Proton ready as well but I did not try this because I made the mistake of buying X4 on GOG (I know this is getting old).
So what’s next? Oh yes, a Head Tracking device. Well bite me, I don’t even have any. Why did I go through all this trouble at all?
The head tracking device
Well why should I purchase such a device without knowing if I can even use it? Do you know what kind of device has a gyroscope built in however? Yes, every average smart phone has one and some are even really good (I hear.) So here comes the fun part: I strapped my mobile phone to my headphones while an app sends the tracking information via wifi and the UDP protocol to OpenTrack as input source.
So I will not bore you with the details how I configured and mapped this in Opentrack. It will be of no use for you anyway since this depends totally on your device and system but I can tell you that this is a lot of fiddling with the settings. Also know that a 3-point device can indeed be built for ~10$ with some LED and a webcam – there are various people demonstrating this on the net and you will find plenty on the usual video platforms.
Finally
I don’t like to have to install the game twice now, once native and once with Wine, but… it’s for science! Or so.
Yes, it’s a little clunky. This is probably because:
- my phone sucks
- my phone really sucks (seriously)
- it’s UDP – order of packages is not guaranteed
- it’s wireless and the access point is two walls away
- …and I probably also messed up with the mapping and filter options 🙂
- I even read that it’s not any better on Windows xD
So that’s it. Head tracking on Linux for X4 Foundations. Jumped the hoops 🙂
This Article was mentioned on github.com