0xDocs 0x.limo

Docs / Steamworks compatibility

Point a Steamworks game at 0x

Partly live

The process layout, environment variables and build publishing that make an unmodified Steamworks game run against 0x, on Linux, under Proton, and on Windows, plus dedicated servers.

Nothing in the game changes. The game keeps the libsteam_api it ships with. What changes is the client library that library loads, and the environment the game starts in.

The 0x app will do this for you

The 0x app (0.1.0) does not start Steamworks games yet and does not ship sg-steamclient. The layout below is what the app sets up for each game process; it is also how 0x's own real-game tests run.

#1. Give the game an app ID

Your game needs a 0x app ID: the number of its store listing (see Getting started). Ownership, stats, achievements, leaderboards, cloud saves, Workshop items and lobbies are all keyed by it.

#2. Publish the build

Native builds are published with sg-content, which ships next to the 0x app in both downloads (sg-content on Linux, sg-content.exe on Windows). Signed in as a publisher of the app (it signs in like a game: SG_BACKEND, plus SG_TOKEN or SG_TOKEN_FILE), run:

bash
sg-content publish <appid> ./build --branch public --description "1.0.3"
FlagEffect
--branch NAMEThe branch the build is published to (default public; other names are betas).
--description TEXTThe build's description, shown in branch lists.
--encryptEncrypt every file per piece; only owners of the app receive the keys.
--sign-key key.jsonSign a build statement with a publisher key (see 0xpak and signing). --statement-expires sets its expiry (Unix seconds, default one year).
--launch path[,path...]Files marked as launch files: installers fetch them first, head first, so the game can start before the rest arrives.

A build is a manifest of files, each stored once by content ID (the SHA-256 of what is stored). Unchanged files keep their IDs from build to build, so an update downloads only what changed, and players fetch the bytes from each other through the player swarm. Large files are published in parts (64 MiB each by default, SG_PART_MB; at most 512 MiB), so a later change moves only the parts it touched.

#3. The process layout

On Linux, libsteam_api loads $HOME/.steam/sdk64/steamclient.so and checks that a Steam client is running by reading $HOME/.steam/steam.pid. So the game process gets:

  • ~/.steam/sdk64/steamclient.so: sg-steamclient;
  • ~/.steam/steam.pid: the PID of a live process (the 0x app);
  • the environment below.

The intended layout gives each game this view without touching the player's real home directory or a Steam install on the same machine: sg-steamclient is bind-mounted over that path for the game process only (as container runtimes for games do), so saves under $HOME stay where they always were. A manual test can use a separate HOME instead:

bash
mkdir -p "$PWD/home/.steam/sdk64"
cp libsteamclient.so "$PWD/home/.steam/sdk64/steamclient.so"
sleep infinity & echo $! > "$PWD/home/.steam/steam.pid"     # stands in for the running client
HOME="$PWD/home" SteamAppId=<appid> SG_BACKEND=https://api.0x.limo \
  SG_TOKEN_FILE=~/.config/0x/session/tokens.json ./MyGame

Games write their saves under $HOME, so with a separate HOME those saves land in the test home: this is for testing, not for players.

#4. Environment

VariableMeaning
SteamAppIdThe 0x app ID. Read before steam_appid.txt.
SG_BACKENDThe platform API. https://api.0x.limo for 0x.
SG_TOKEN_FILEThe signed-in account's token file, shared with the 0x app. sg-steamclient refreshes the access token on a 401 and writes the rotated pair back, holding <file>.lock while it does, so the app and the game never spend the same refresh token.
SG_TOKEN / SG_REFRESH_TOKENTokens passed directly instead of a file (tests).
SG_DATA_DIRWhere the offline cache and pending writes are kept. Default $XDG_DATA_HOME/0x1 (~/.local/share/0x1).
SG_OFFLINESet: skip the network and use only the local cache.
SG_OFFLINE_DAYSHow long a cached ownership is honoured offline (default 30).
SG_LAUNCH_COMMAND_LINEWhat ISteamApps::GetLaunchCommandLine returns (join links, +connect).
SG_LAUNCH_<key>What ISteamApps::GetLaunchQueryParam(key) returns.
SG_INSTALL_DIRWhat GetAppInstallDir reports (default: the working directory).

The game never sees your password, and never needs one: it runs as whoever is signed in to the 0x app.

#5. Windows games

Under Proton or Wine. A Windows build's steam_api64.dll loads the steamclient64.dll registered for the running client. Proton redirects it to its lsteamclient bridge, which calls the Linux ~/.steam/sdk64/steamclient.so. Put sg-steamclient there and the Windows build runs against 0x like a Linux one; set SteamAppId and SteamGameId in the environment.

Natively. The same source builds as a PE steamclient64.dll with the Microsoft C++ ABI (vtable order, hidden struct-return pointers, Windows struct packing). The Windows steam_api64.dll loads it from the path the client registers under HKCU\Software\Valve\Steam\ActiveProcess\SteamClientDll64. Native Windows support is new: see limitations.

#6. Dedicated and listen servers

A server built with SteamGameServer_Init works unchanged:

  • libsteam_api first looks for a steamclient.so next to the server binary, so a dedicated server can carry sg-steamclient in its own directory, with no ~/.steam at all.
  • Point it at 0x with SG_BACKEND and SteamAppId.
  • LogOnAnonymous() gives the server an anonymous game-server ID. LogOn(token) with a registered game-server token gives it a persistent ID; 0x has no self-serve page for those tokens yet, so use anonymous logon.
  • The server sends a heartbeat every 30 seconds and on every state change, and stays in the server browser while it is fresh (90 seconds after the last heartbeat). A server bound to INADDR_ANY is listed at the address 0x sees, which GetPublicIP returns.
  • BeginAuthSession verifies a player's ticket with 0x (one-shot: a ticket cannot be replayed), and falls back to a local signature check against GET /v1/keys if 0x is unreachable. UserHasLicenseForApp, BUpdateUserData, ISteamGameServerStats and the server browser filters (map, gamedir, gametagsand, gametagsnor, notfull, hasplayers, noplayers, dedicated, secure, password, name_match) work as on Steam.

A process can host a client and a server at once (listen servers): each has its own interfaces, callback queue and network state.

#7. Check it worked

  • SteamAPI_Init returns true, and ISteamUser::GetSteamID is your 0x account.
  • ISteamApps::BIsSubscribedApp(<appid>) is true for an account that owns the game.
  • Set a stat or unlock an achievement, call StoreStats, and see it on the game's store page (GET /v1/apps/{appid}/achievements).

Two diagnostic variables make sg-steamclient log what the game does: SG_TRACE_CALLS=1 (every interface call) and SG_TRACE_CALLBACKS=1 (every callback delivered).