• Stars
    star
    2,729
  • Rank 16,690 (Top 0.4 %)
  • Language
    C#
  • License
    MIT License
  • Created over 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Another fucking c# Steamworks implementation

Facepunch.Steamworks

Another fucking c# Steamworks implementation

Build All

Features

Feature Supported
Windows
Linux
MacOS
Unity Support
Unity IL2CPP Support
Async Callbacks (steam callresults)
Events (steam callbacks)
Single C# dll (no native requirements apart from Steam)
Open Source
MIT license
Any 32bit OS

Why

The Steamworks C# implementations I found that were compatible with Unity have worked for a long time. But I hate them all. For a number of different reasons.

  • They're not C#, they're just a collection of functions.
  • They're not up to date.
  • They require a 3rd party native dll.
  • They can't be compiled into a standalone dll (in Unity).
  • They're not free
  • They have a restrictive license.

C# is meant to make things easier. So lets try to wrap it up in a way that makes it all easier.

What

Get your own information

    SteamClient.SteamId // Your SteamId
    SteamClient.Name // Your Name

View your friends list

foreach ( var friend in SteamFriends.GetFriends() )
{
    Console.WriteLine( $"{friend.Id}: {friend.Name}" );
    Console.WriteLine( $"{friend.IsOnline} / {friend.SteamLevel}" );
    
    friend.SendMessage( "Hello Friend" );
}

App Info

    Console.WriteLine( SteamApps.GameLanguage ); // Print the current game language
    var installDir = SteamApps.AppInstallDir( 4000 ); // Get the path to the Garry's Mod install folder

    var fileinfo = await SteamApps.GetFileDetailsAsync( "hl2.exe" ); // async get file details
    DoSomething( fileinfo.SizeInBytes, fileinfo.Sha1 );

Get Avatars

    var image = await SteamFriends.GetLargeAvatarAsync( steamid );
    if ( !image.HasValue ) return DefaultImage;

    return MakeTextureFromRGBA( image.Value.Data, image.Value.Width, image.Value.Height );

Get a list of servers

using ( var list = new ServerList.Internet() )
{
    list.AddFilter( "map", "de_dust" );
    await list.RunQueryAsync();

    foreach ( var server in list.Responsive )
    {
        Console.WriteLine( $"{server.Address} {server.Name}" );
    }
}

Achievements

List them

    foreach ( var a in SteamUserStats.Achievements )
    {
        Console.WriteLine( $"{a.Name} ({a.State})" );
    }	

Unlock them

    var ach = new Achievement( "GM_PLAYED_WITH_GARRY" );
    ach.Trigger();

Voice

    SteamUser.VoiceRecord = KeyDown( "V" );

    if ( SteamUser.HasVoiceData )
    {
        var bytesrwritten = SteamUser.ReadVoiceData( stream );
        // Send Stream Data To Server or Something
    }

Auth

    // Client sends ticket data to server somehow
    var ticket = SteamUser.GetAuthSessionTicket();

    // server listens to event
    SteamServer.OnValidateAuthTicketResponse += ( steamid, ownerid, rsponse ) =>
    {
        if ( rsponse == AuthResponse.OK )
            TellUserTheyCanBeOnServer( steamid );
        else
            KickUser( steamid );
    };

    // server gets ticket data from client, calls this function.. which either returns
    // false straight away, or will issue a TicketResponse.
    if ( !SteamServer.BeginAuthSession( ticketData, clientSteamId ) )
    {
        KickUser( clientSteamId );
    }

    //
    // Client is leaving, cancels their ticket OnValidateAuth is called on the server again
    // this time with AuthResponse.AuthTicketCanceled
    //
    ticket.Cancel();

Utils

    SteamUtils.SecondsSinceAppActive;
    SteamUtils.SecondsSinceComputerActive;
    SteamUtils.IpCountry;
    SteamUtils.UsingBatteryPower;
    SteamUtils.CurrentBatteryPower;
    SteamUtils.AppId;
    SteamUtils.IsOverlayEnabled;
    SteamUtils.IsSteamRunningInVR;
    SteamUtils.IsSteamInBigPictureMode;

Workshop

Download a workshop item by ID

    SteamUGC.Download( 1717844711 );

Get a workshop item information

    var itemInfo = await Ugc.Item.Get( 1720164672 );

    Console.WriteLine( $"Title: {itemInfo?.Title}" );
    Console.WriteLine( $"IsInstalled: {itemInfo?.IsInstalled}" );
    Console.WriteLine( $"IsDownloading: {itemInfo?.IsDownloading}" );
    Console.WriteLine( $"IsDownloadPending: {itemInfo?.IsDownloadPending}" );
    Console.WriteLine( $"IsSubscribed: {itemInfo?.IsSubscribed}" );
    Console.WriteLine( $"NeedsUpdate: {itemInfo?.NeedsUpdate}" );
    Console.WriteLine( $"Description: {itemInfo?.Description}" );

Query a list of workshop items

    var q = Ugc.Query.All
                    .WithTag( "Fun" )
                    .WithTag( "Movie" )
                    .MatchAllTags();

    var result = await q.GetPageAsync( 1 );

    Console.WriteLine( $"ResultCount: {result?.ResultCount}" );
    Console.WriteLine( $"TotalCount: {result?.TotalCount}" );

    foreach ( Ugc.Item entry in result.Value.Entries )
    {
        Console.WriteLine( $"{entry.Title}" );
    }

Query items created by friends

    var q = Ugc.UserQuery.All
                        .CreatedByFriends();

Query items created by yourself

    var q = Ugc.UserQuery.All
                        .FromSelf();

Publish your own file

    var result = await Ugc.Editor.NewCommunityFile
                      .WithTitle( "My New FIle" )
                      .WithDescription( "This is a description" )
                      .WithContent( "c:/folder/addon/location" )
                      .WithTag( "awesome" )
                      .WithTag( "small" )
                      .SubmitAsync( iProgressBar );

Steam Cloud

Write a cloud file

    SteamRemoteStorage.FileWrite( "file.txt", fileContents );

Read a cloud file

    var fileContents = SteamRemoteStorage.FileRead( "file.txt" );

List all files

    foreach ( var file in SteamRemoteStorage.Files )
    {
        Console.WriteLine( $"{file} ({SteamRemoteStorage.FileSize(file)} {SteamRemoteStorage.FileTime( file )})" );
    }

Steam Inventory

Get item definitions

    foreach ( InventoryDef def in SteamInventory.Definitions )
    {
        Console.WriteLine( $"{def.Name}" );
    }

Get items that are for sale in the item shop

    var defs = await SteamInventory.GetDefinitionsWithPricesAsync();

    foreach ( var def in defs )
    {
        Console.WriteLine( $"{def.Name} [{def.LocalPriceFormatted}]" );
    }

Get a list of your items

    var result = await SteamInventory.GetItems();

    // result is disposable, good manners to dispose after use
    using ( result )
    {
        var items = result?.GetItems( bWithProperties );

        foreach ( InventoryItem item in items )
        {
            Console.WriteLine( $"{item.Id} / {item.Quantity} / {item.Def.Name} " );
        }
    }

Getting Started

Client

To initialize a client you can do this.

using Steamworks;

// ...

try 
{
    SteamClient.Init( 4000 );
}
catch ( System.Exception e )
{
    // Couldn't init for some reason (steam is closed etc)
}

Replace 4000 with the appid of your game. You shouldn't call any Steam functions before you initialize.

When you're done, when you're closing your game, just shutdown.

SteamClient.Shutdown();

Server

To create a server do this.

var serverInit = new SteamServerInit( "gmod", "Garry Mode" )
{
    GamePort = 28015,
    Secure = true,
    QueryPort = 28016
};

try
{
    Steamworks.SteamServer.Init( 4000, serverInit );
}
catch ( System.Exception )
{
    // Couldn't init for some reason (dll errors, blocked ports)
}

Help

Wanna help? Go for it, pull requests, bug reports, yes, do it.

You can also hit up the Steamworks Thread for help/discussion.

We also have a wiki you can read and help fill out with examples and advice.

License

MIT - do whatever you want.

More Repositories

1

garrysmod

Sandbox mod for the Source Engine
Lua
1,027
star
2

sandbox

Garry's Mod for s&box
C#
405
star
3

Facepunch.Highlight

Mesh outline effect
C#
314
star
4

WhatUsesThis

Right click an asset and get a list of assets that use it
C#
215
star
5

dm98

Deathmatch gamemode for s&box
C#
164
star
6

sbox-issues

162
star
7

garrysmod-issues

Garry's Mod issue tracker
137
star
8

gmad

Garry's Mod Addon Creator and Extractor
C++
132
star
9

webrcon

Game server rcon, using websockets
120
star
10

gmod-module-base

The base interface to create binary modules for Garry's Mod
C++
86
star
11

sbox-minimal

Minimal gamemode for s&box
C#
83
star
12

garrysmod-requests

Feature requests for Garry's Mod
81
star
13

Rust.World

SDK to support the creation of custom map tools for Rust
C#
79
star
14

Rust.Community

Community Entity to fill Server Side modder requests
C#
40
star
15

sbox-hidden

Eliminate the crazy invisible lunatic with the knife, or be him and slay those trying to survive.
C#
38
star
16

sbox-rts

A competitive real-time strategy game with support for up to 4 players.
C#
36
star
17

sbox-scenestaging

A staging area for the scene system
C#
33
star
18

RustWorkshop

32
star
19

sbox-ai-lab

C#
27
star
20

Tub.Editor

C#
21
star
21

sbox-hover

A competitive 32 player capture the flag game where movement is based on jetpacking and skiing around the map.
C#
21
star
22

Facepunch-Discourse-Theme

Theme for https://forum.facepunch.com
SCSS
19
star
23

sbox-pool

A classic pub game where your skill is determined by your blood-alcohol content.
C#
19
star
24

Facepunch.UnityBatch

Wrap the running of Unity3d in jenkins, on build servers. Output log file to stdout.
C#
18
star
25

Facepunch.Parse

Context-free grammar parsing tool
C#
18
star
26

sbox-sandblox

voxels
C#
15
star
27

facepunch.construct

construct map
14
star
28

GithubDocGen

Generate md documentation from a c# dll and its xml file
C#
14
star
29

sbox-vscode

Development tools for S&box
TypeScript
14
star
30

Rust.ModLoader

A simple server-side script loader for Rust
C#
13
star
31

Rust.HarmonyMods

Serverside harmony mods for Rust, aimed at staging servers currently.
C#
13
star
32

Facepunch.WebGame

TypeScript WebGL game helpers.
TypeScript
13
star
33

sbox-sdf

Library providing marching cubes / squares mesh generation
C#
13
star
34

sbox-tabletennis-vr

🏓 Facepunch presents Table Tennis VR
C#
13
star
35

sbox-arena

Simple multiplayer deathmatch game using the Scene System.
C#
13
star
36

sbox-gunfight

A realistic attempt at a modern CoD/Battlefield-esque shooter in s&box.
C#
12
star
37

sbox-unicycle-frenzy

C#
12
star
38

sbox-csg

A simple real-time CSG library for S&box
C#
11
star
39

sbox-netlab

Project to test net stuff
C#
11
star
40

gmod-html

GMod's HTML interface and implementations
C++
11
star
41

sbox-walker

A map exploration game for s&box
C#
11
star
42

sbox-minigolf

Play minigolf with your friends in s&box
C#
10
star
43

sbox-strafe

C#
10
star
44

sbox-time-system

☀️ A simple library for implementing a 24 hour time system for day and night. Includes a time controller entity for mappers to use to set specific colors and settings for each time period.
C#
10
star
45

sbox-vr-lab

C#
9
star
46

sbox-boomer

C#
9
star
47

sbox-projectiles

🚀 Lag compensated simulated projectiles using game resources for projectile definitions.
C#
9
star
48

sbox-spire

A top-down RPG made in s&box.
C#
9
star
49

Legal

We put our legal stuff here so we can be transparent with the changes to our policies. This is also available in the legal section of our website.
9
star
50

sbox-radial-menu

🥧 A reusable and customizable radial menu for use in games.
HTML
9
star
51

sbox-2dtest

Playing around with making 2D games
C#
8
star
52

sbox-worldcraft

Experimental ingame multiplayer world editor
C#
7
star
53

sbox-platformer

C#
7
star
54

react-class-model

State management for React with hooks, inspired by Flutter's scoped_model
TypeScript
7
star
55

sbox-spritetools

C#
7
star
56

Facepunch.Steamworks.UnityTest

This is Garry's personal Unity test for Facepunch.Steamworks. It allows him to test the library in Unity in Windows, Linux, MacOS and Windows with IL2CPP.
C#
7
star
57

sbox-iconify

😀 A simple way to use many different icon packs in a s&box project.
C#
6
star
58

sbox-stream-lab

C#
6
star
59

sbox-voxeltest

Tech demo that lets you paint blobby 3D geometry
C#
6
star
60

sbox-bombroyale

SCSS
6
star
61

sbox-inventory-system

📦 A slot based inventory system API that uses game resources for item definitions.
C#
6
star
62

Line-Renderer

Line renderer wip for s&box
GLSL
6
star
63

qt

Our build of qt, which is based on Valve's build of qt
5
star
64

sbox-checkers

Checkers gamemode for S&box
C#
5
star
65

Facepunch.ObjectAnimation

C#
5
star
66

sbox-voxels

🧱 An easy to use voxel base that covers textured blocks, chunk generation support, and dynamic loading and unloading of chunks.
C#
5
star
67

sbox-forsaken

A co-op game with a mysterious lore where players must adapt to survive
C#
4
star
68

sbox-juicebox

Hackweek project
C#
4
star
69

Facepunch.Flexbox

CSS Flexbox inspired layout for Unity UGUI
C#
4
star
70

LevelBuilderVR

Rough level builder in VR
C#
3
star
71

sbox-pixelwall

C#
3
star
72

facepunch.flatgrass

3
star
73

arcade-tutorial-gettingstarted-csharp

BBDK tutorial for the C# game API
C#
3
star
74

sbox-autovmat

Create materials from a group of textures easily.
C#
3
star
75

sbox-floating-text

A floating text library, for damage numbers and whatnot
C#
3
star
76

sbox-customization-editor

An editor tool for configuring minigolf/unicycle frenzy customization
C#
3
star
77

sbox-crt

C#
2
star
78

sbox-persistence

💾 A simple persistence system that can be used to serialize and deserialize the game state.
C#
2
star
79

RenderInfo

App to visualize the render info generated by Rust
C#
2
star
80

sbox-dungeons

A procedurally generated dungeon crawler with progressively harder levels. Work together to survive, or kill other players to hinder their progress.
C#
2
star
81

sbox-corewars

A voxel-based PVP game where multiple teams fight to destroy their enemy's Core to prevent them from respawning.
C#
2
star
82

sbox-dm98-datacore

Remake of Datecore
1
star
83

sbox-pool2

A classic pub game where your skill is determined by your blood-alcohol content.
C#
1
star
84

sbox-mazing

C#
1
star
85

sbox-towerwars

Tower defense project for hack week
C#
1
star
86

arcade-SmashBloxTS

Scripts and resources for the SmashBloxTS arcade game by @metapyziks
TypeScript
1
star
87

sbox-boomer-maps-assets

ShaderLab
1
star
88

sbox-platformer-maps

GLSL
1
star
89

arcade-SmashBloxJS

Scripts and resources for the SmashBloxJS arcade game by @aylaylay
JavaScript
1
star
90

arcade-TypeScript

TypeScript definitions generated from the arcade JavaScript API.
TypeScript
1
star
91

sbox-libpolygon

Tools to generate fancy meshes from 2D polygons.
C#
1
star
92

sbox-roguemoji

ui-only grid game
C#
1
star
93

sbox-roguefps

C#
1
star