Another fucking c# Steamworks implementation
Go to file
2017-08-07 09:24:28 -07:00
Facepunch.Steamworks Small README update and adjusts doc tags for Lobby functions. 2017-08-07 09:24:28 -07:00
Facepunch.Steamworks.Test Implements ability for a user to set/get individual user metadata for the joined lobby 2017-07-31 23:42:29 -07:00
Generator Made SteamNative.SteamApi less hacky to initialize 2017-07-06 10:33:13 +01:00
.gitattributes 💥🐫 Added .gitattributes & .gitignore files 2016-07-06 17:36:50 +01:00
.gitignore Simple comment update 2017-08-06 22:09:13 -07:00
Facepunch.Steamworks.sln VS2017 2017-04-05 16:06:12 +01:00
Jenkinsfile Build on windows nodes 2017-05-09 20:43:46 +01:00
LICENSE Update license with company/year 2016-10-11 07:40:42 -04:00
README.md Small README update and adjusts doc tags for Lobby functions. 2017-08-07 09:24:28 -07:00

Facepunch.Steamworks

Another fucking c# Steamworks implementation

Build Status

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 have a license.

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

What

So say you want to print a list of your friends?

foreach ( var friend in client.Friends.All )
{
    Console.WriteLine( "{0}: {1}", friend.Id, friend.Name );
}

But what if you want to get a list of friends playing the same game that we're playing?

foreach ( var friend in client.Friends.All.Where( x => x.IsPlayingThisGame ) )
{
    Console.WriteLine( "{0}: {1}", friend.Id, friend.Name );
}

You can view examples of everything in the Facepunch.Steamworks.Test project.

Usage

Client

Compile the Facepunch.Steamworks project and add the library to your Unity project. To create a client you can do this.

var client = new Facepunch.Steamworks.Client( 252490 );

Replace 252490 with the appid of your game. This should be a singleton - you should only create one client, right at the start of your game.

The client is disposable, so when you're closing your game should probably call..

client.Dispose();

Or use it in a using block if you can.

Server

To create a server do this.

var server = new Facepunch.Steamworks.Server( 252490, 0, 28015, true, "MyGame453" );

This will register a secure server for game 252490, any ip, port 28015. Again, more usage in the Facepunch.Steamworks.Test project.

Lobby

To create a Lobby do this.

client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);

Created lobbies are auto-joined, but if you want to find a friend's lobby, you'd call

client.LobbyList.Refresh();
//wait for the callback
client.LobbyList.OnLobbiesUpdated = () =>
{
    if (client.LobbyList.Finished)
    {
        foreach (LobbyList.Lobby lobby in client.LobbyList.Lobbies)
        {
            Console.WriteLine($"Found Lobby: {lobby.Name}");
        }
    }
};
//join a lobby you found
client.Lobby.Join(LobbyList.Lobbies[0]);

Your can find more examples of Lobby functionality in the Lobby.cs file in the test project. Sending chat messages, assinging lobby data and member data, etc.

Unity

Yeah this works under Unity. That's half the point of it.

There's another repo with an example project with it working in Unity. You can find it here.

The TLDR is before you create the Client or the Server, call this to let Facepunch.Steamworks know which platform we're on - because it can't tell the difference between osx and linux by itself.

Facepunch.Steamworks.Config.ForUnity( Application.platform.ToString() );

You'll also want to put steam_api64.dll and steam_appid.txt (on windows 64) in your project root next to Assets.

Help

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

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

License

MIT - do whatever you want.