Skip to content
edanickPublic

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Steam API - Steamworks for Silver

A Steamworks wrapper for Silver, shipped as a QuickSilver .qs library. It lets a game plug into Steam from a handful of lines: rich presence ("now playing"), the Shift+Tab overlay, achievements and stats, lobbies and invitations, friend lists, and avatar images.

It is pure Silver (.sr) — no C/C++ glue, no generated stubs, no vendored SDK. The library binds the SDK's flat C API (steam_api_flat.h) directly and receives events through manual callback dispatch, because Silver has no indirect calls with arguments.

SPEC.md is the normative contract, and references/STEAM_API.md holds the transcribed flat-API tables (Steamworks SDK 1.65). This page is the orientation.

Status: v0.1.0, verified live on Windows (2026-10-21, SDK 1.65, silverc 0.7.9) against a real Steam client. Linux type-checks but has not run; macOS is blocked by the toolchain. See Status.

Quick start

Build the bundle (see Building), then consume it. A consuming project needs three things, all required:

// game.srp
{
    imports: ["path/to/steam_api.qs"],
    nativeModules: [
        { module: "steam", windows: "steam_api64.dll", linux: "libsteam_api.so" },
        { module: "steamlibc", windows: "ucrtbase.dll", linux: "libc.so.6" }
    ]
}
import * from steam_api;

void main() {
    Steam steam = new Steam();
    if (steam.init()) {
        steam.friends().setRichPresence("status", "#Playing_Solo");
        steam.pump();                     // every frame: drains Steam's callbacks
        // ... the game ...
        steam.shutdown();
    } else {
        printline(steam.errorText());     // no client / no app id / licence missing
    }
    steam.destroy();
}

Point imports at the built bundle (the in-repo examples use ../../build/steam_api.qs). The consumer's own nativeModules entry is mandatory: without it the build fails, naming the missing declaration. The steamlibc module exists only to memcpy callback payloads out of Steam's memory; it carries no Steamworks logic.

Requirements

Requirement Notes
Silver toolchain (silverc) 0.7.9 is the verified version. The interpreter (silveri) cannot run this library.
Steamworks SDK 1.65 Ship redistributable_bin/win64/steam_api64.dll (Windows) or redistributable_bin/linux64/libsteam_api.so (Linux) next to the executable. Never vendored into this repo.
Steam client Running, logged in, and owning the app.
App id A steam_appid.txt next to the executable during development, or launch the game through Steam. 480 (Spacewar) works for testing.

Use the 1.65 redistributable specifically. Older DLLs lack some interface accessors this library imports, and Windows refuses to start an executable with an unresolved import — so a stale DLL is a hard failure at launch, not a graceful degrade.

Building

silverc steam_api.srp          # -> build/steam_api.qs

build/ is compiler output and is not committed. Every src/*.sr file declares mod export steam_api;, so consumers keep writing import * from steam_api;.

Features

Feature Where
"Now playing" rich presence SteamFriends.setRichPresence / clearRichPresence
Shift+Tab overlay SteamFriends.activateOverlay / overlayActive
Achievements and stats SteamStats
Lobbies, chat, invitations SteamLobby
Friend list, persona, presence SteamFriends
Avatar images SteamFriends.avatarHandle + SteamUtils
User identity, auth ticket, app id SteamUser / SteamUtils
Callback pump Steam.pump() + SteamCallbacks

Public API

The root Steam owns one thin facade per Steamworks interface. The full signatures, including every addition beyond this table, are in SPEC.md §7.

Class Responsibility and key methods
Steam Lifecycle and the pump: init(), shutdown(), destroy(), ready(), appID(), errorText(), initCode(), isSteamRunning(), gameLanguage(), subscribed(), restartIfNecessary(appID), and pump() — call it every frame. Access the rest through user(), friends(), stats(), lobby(), utils(), callbacks().
SteamUser Identity: steamID(), accountID(), accountType(), universe(), personaName(), playerLevel(), userDataFolder(), loggedOn(), authTicket() / authTicketSize() / authTicketHex() / cancelAuthTicket().
SteamFriends People: friendCount(), friendIDAt(i), friendNameAt(i), friendStateAt(i), friendGameAt(i), nameOf(id), stateOf(id), richPresenceOf(id, key), setRichPresence(key, value), clearRichPresence(), activateOverlay(dialog), overlayActive(), avatarHandle(id, size), inviteToGame(id, connectString).
SteamStats Progress: request(), requestDone(), getStatInt(name), setStatInt(name, value), getStatFloatScaled(name), getAchievement(name), setAchievement(name), clearAchievement(name), achievementCount(), achievementNameAt(i), achievementAttribute(name, attribute), store(), stored(), errorText().
SteamLobby Multiplayer: createLobby(type, maxMembers), join(id), acceptInvite(), leave(), joined(), lobbyID(), memberCount(), memberIDAt(i), ownerID(), lobbyData(key), setLobbyData(key, value), memberData(id, key), setMemberData(key, value), sendChat(message), chatCount(), chatAt(i), chatSenderAt(i), inviteUser(id), openInviteDialog(), lastResult().
SteamUtils App and images: appID(), overlayEnabled(), secondsSinceAppActive(), getImageSize(handle, width, height), getImageRGBA(handle, rgba, size), imageByteAt(rgba, offset).
SteamCallbacks The manual-dispatch registry: onLobbyInvite, onOverlayActive, onAchievementUnlocked, onStatsStored, onSteamShutdown, callbackCount(), lastCallbackID().

Free steam*Of(int steamID) decoders (steamAccountIDOf, steamInstanceOf, steamAccountTypeOf, steamUniverseOf) work on any raw 64-bit SteamID.

Events

Every handler is a void () — Silver has no indirect calls with arguments. A facade stores the handler and fires it with no payload; the handler reads the result from the facade afterwards (lobbyID(), lastAchievementName(), ...).

Handlers cannot capture locals either, so keep any state they need in a global box:

Steam[] GAME_STEAM = [null];

void wireEvents(Steam steam) {
    steam.stats().onAchievementUnlocked((void () {
        printline("unlocked: " + GAME_STEAM[0].stats().lastAchievementName());
    }));
    steam.lobby().onLobbyEntered((void () {
        printline("in lobby " + GAME_STEAM[0].lobby().lobbyID());
    }));
    steam.callbacks().onSteamShutdown((void () {
        printline("Steam is going away");
    }));
}
Event Fires when
SteamFriends.onOverlayActive The overlay opens or closes — read overlayActive().
SteamFriends.onFriendStateChange A friend's persona or state changed — read lastChangedID().
SteamFriends.onAvatarLoaded An avatar became available — read loadedAvatarUser() / loadedAvatarHandle().
SteamStats.onStatsReceived request() completed.
SteamStats.onAchievementUnlocked A real unlock. Progress notifications only update lastAchievementProgress().
SteamStats.onStatsStored store() completed — read storeResult().
SteamLobby.onLobbyCreated createLobby() finished — read lastResult().
SteamLobby.onLobbyEntered You joined a lobby.
SteamLobby.onChatMessage Chat arrived — read chatAt(chatCount() - 1).
SteamLobby.onMemberJoined / onMemberLeft Membership changed — read lastMemberID().
onLobbyInvite (on SteamLobby and SteamCallbacks) An invite arrived (inviteAccepted() is false — ask the player), or the player accepted one in the Steam UI (true — call acceptInvite()).
SteamCallbacks.onSteamShutdown The client is shutting down.

Stats and achievements

SteamStats stats = steam.stats();
if (stats.requestDone() == false) {
    stats.request();       // async — keep calling steam.pump() until requestDone()
}
int games = stats.getStatInt("NumGames");
int feet  = stats.getStatFloatScaled("FeetTraveled");   // millionths
if (stats.getAchievement("ACH_WIN_ONE_GAME") == false) {
    stats.setAchievement("ACH_WIN_ONE_GAME");
    stats.store();        // async — onStatsStored / stored()
}

Lobbies

SteamLobby lobby = steam.lobby();
int call = lobby.createLobby(1, 4);   // type: 0 private / 1 friends-only / 2 public / 3 invisible; 0 = not issued
// Steam enters the new lobby itself — wait for onLobbyEntered
lobby.setLobbyData("name", "My lobby");
lobby.setMemberData("ready", "1");
lobby.sendChat("hello");
lobby.inviteUser(friendSteamID);
lobby.leave();

Avatars

int handle = steam.friends().avatarHandle(steam.user().steamID(), 2);   // size: 0 small / 1 medium / 2 large; -1 = still loading
int[] width = new int[1];
int[] height = new int[1];
if (handle > 0 && steam.utils().getImageSize(handle, width, height)) {
    int size = width[0] * height[0] * 4;
    byte[] rgba = new byte[size];
    steam.utils().getImageRGBA(handle, rgba, size);
    int red = steam.utils().imageByteAt(rgba, 0);   // byte[] reads are slot-wide, so go through imageByteAt
}

Examples

cd examples/steam_demo && silverc demo.srp                   # -> build/steam_demo.exe
cd examples/steam_test && silverc test.srp --os WINDOWS      # -> build/steam_test.exe

Copy the executable next to a 1.65 steam_api64.dll before running it.

steam_demo — the feature tour on a real client. Put a steam_appid.txt containing 480 (Valve's public Spacewar test app) next to the executable and run it with Steam logged in:

steam_demo                 identity, friends, presence, stats, avatar
steam_demo --achieve       + unlock ACH_WIN_ONE_GAME, store, clear it again, store
steam_demo --lobby         + friends-only lobby round trip: create, enter, data, chat, leave
steam_demo --overlay       + open the Friends overlay (needs a windowed program to see)
steam_demo --seconds N     keep pumping for N more seconds (default 3)

Without an app id, client, or licence it prints the reason and exits 0 — the game-keeps-running path.

steam_test — headless, no Steam needed. Run it without a steam_appid.txt: it checks the degrade path (init() false, Steam's own reason in errorText()), every facade inert and null-safe before init, the SteamID / float / i32 / bool decoders, and every callback driven through Steam.simulateCallback with SDK-exact payloads in both Windows and Linux struct packings. 118 checks; the exit code is the number of failures.

Status

Verified live on Windows, 2026-10-21 (SDK 1.65, silverc 0.7.9, app 480, logged-in client):

  • Lifecycle, manual-dispatch pump, graceful degrade (steam_test 118/118)
  • Identity: persona, SteamID decode, level, language, user data folder, auth ticket
  • Friend list with states, rich presence set/clear, avatar RGBA
  • Achievements and int/float stats: unlock → store → clear → store round trip
  • Lobby: create → enter → data → members → chat → leave
  • [~] Overlay: activateOverlay runs, but a console program has no renderer for the overlay to hook — proving it needs a windowed game
  • [~] Invites: covered by simulated payloads only; a second Steam account is needed to test them live
  • P2P networking, UGC, screenshots, Steam Input, Web API auth ticket

Platform support

OS State
Windows (64-bit) Verified live.
Linux --os LINUX builds type-check, but silverc 0.7.9 still writes a PE file, so nothing has actually run.
macOS Blocked: the nativeModules schema has no macos key and the compiler has no Darwin target. Not a library-side problem.

Behaviour worth knowing

  • silverc only. The interpreter cannot call custom native modules, so real Steam calls are impossible under silveri.
  • A missing steam_api64.dll is not degradable. Windows refuses to start a PE with an unresolved import before any Silver code runs. The degrade path covers "DLL present, Steam / app id / licence missing".
  • setStatFloatScaled is blocked and returns false with SteamStats.errorText() set: the compiler cannot pass a float argument to native code. Float reads work (getStatFloatScaled).
  • Handlers cannot capture locals — use global boxes (see Events).
  • Shutdown is thorough. shutdown() clears rich presence, leaves the lobby, and cancels the auth ticket before SteamAPI_Shutdown. shutdown() and destroy() are null-safe and idempotent.

Layout

steam_api/
  README.md                  this file
  SPEC.md                    normative specification
  steam_api.srp              quicksilver manifest (+ nativeModules)
  src/                       one file per facade; every file `mod export steam_api`
    steam_api.sr             facade: module decl + all flat grants + FFI notes (no logic)
    steam.sr                 Steam lifecycle + pump
    user.sr                  SteamUser + 64-bit ID decode
    friends.sr               SteamFriends + presence + overlay
    stats.sr                 SteamStats
    lobby.sr                 SteamLobby
    utils.sr                 SteamUtils + avatar images
    callbacks.sr             SteamCallbacks + CallbackMsg_t decode
  references/STEAM_API.md    transcribed flat-API tables (SDK 1.65, no C source)
  examples/steam_demo/       consumer: feature tour on a real client
  examples/steam_test/       consumer: headless checks, no Steam needed
  build/                     steam_api.qs + example binaries (gitignored)

Design rules

  • Pure Silver and the compiler's emitted x86-64 only — no .c/.h/.cpp, no shell-outs, no generated stubs, no vendored SDK.
  • Only the flat C API (SteamAPI_*) is bound, through declared nativeModules grants. Export names are transcribed from the SDK headers, never guessed.
  • Manual dispatch (SteamAPI_ManualDispatch_*) only; SteamAPI_RunCallbacks is never called.
  • Every fallible call returns a non-null object — check valid() / ready(), never a bare null that loses the error.
  • No #on / #off regions in bundle sources (bundles are lexed raw); OS differences live in nativeModules and per-OS data.

License

Copyright 2026 Silver.

Trademarks

Steam, Steamworks, and the Steam logo are trademarks of Valve Corporation. Steam API is an independent library, not affiliated with, endorsed by, or sponsored by Valve. It ships none of Valve's code or SDK content — it only calls the exports of the Steamworks redistributable, which you obtain separately from Valve.

About

No description or website provided.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors