Binding Steamworks SDK

Tuesday, November 1, 2016

I've been working on Facepunch.Steamworks in the background while doing Rust's workshop integration. Just Prerelease branch is shipping with it now.
The challenge was to make a c# library that works under Unity (and not) without recompiling, and on a bunch of platforms.
Here's everything that sucked about it.

The awesome confusing part of the VTable is that the first two functions swap positions on windows.

steam_api_interop.cs

For a long time I was trying to use the steam_api_interop.cs file included with the SDK. Don't use this. It's non functional out of the box, it's using the wrong parameters for a bunch of functions and it's not packing structs.
Because of this I ended up writing my own generator (which I'm sure is getting a few things wrong, but I'm unit testing as much as I can).
For this I'm using the steam_api.json file and some source code regexes for missing stuff. So as much as steam_api_interop.cs sucks, I'm sure it's only there to serve as an example of how to use steam_api.json and steam_api_flat.h - which makes this all a million times easier.

Things That Suck

Callbacks can return with "IO Failure" if you call them too soon after Steam Init. This sucks for Unit Tests.
Steam thinks your game is still running until you close the exe. This sucks when working in Unity Editor etc.