All Projects → Facepunch → Facepunch.steamworks

Facepunch / Facepunch.steamworks

Licence: mit
Another fucking c# Steamworks implementation

Programming Languages

C#
18002 projects
C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Facepunch.steamworks

Melonloader
The World's First Universal Mod Loader for Unity Games that is Compatible with both Il2Cpp and Mono
Stars: ✭ 306 (-84.27%)
Mutual labels:  game, unity, dll
Projectfieldwarning
Project: Field Warning is a community-made RTS game centered around lethal regiment and division-scale warfare.
Stars: ✭ 86 (-95.58%)
Mutual labels:  game, unity
1 Character Movement
The first section of the course. You will learn everything required to build a simple movement system in your RPG, creating the core experience. http://gdev.tv/rpggithub
Stars: ✭ 81 (-95.84%)
Mutual labels:  game, unity
Play
The free and open source karaoke singing game UltraStar Play for Windows, Linux, Android, Xbox, PlayStation and other platforms.
Stars: ✭ 94 (-95.17%)
Mutual labels:  game, unity
3 Modifiers And Abilities
Customise character abilities, weapons, characters and enemies. This includes multiple damage types, modifiers, sounds, animations. By the end you can create your core combat experience. (REF MA_RPG) http://gdev.tv/rpggithub
Stars: ✭ 64 (-96.71%)
Mutual labels:  game, unity
09 Zombierunner Original
First person shooter with Unity terrain and AI pathfinding (http://gdev.tv/cudgithub)
Stars: ✭ 64 (-96.71%)
Mutual labels:  game, unity
Yarnspinner
Yarn Spinner is a tool for building interactive dialogue in games!
Stars: ✭ 1,283 (-34.04%)
Mutual labels:  game, unity
Dll hook Rs
Rust code to show how hooking in rust with a dll works.
Stars: ✭ 57 (-97.07%)
Mutual labels:  game, dll
Entitas Sync Framework
Networking framework for Entitas ECS. Targeted at turnbased games or other slow-paced genres.
Stars: ✭ 98 (-94.96%)
Mutual labels:  game, unity
Unlitclouds
A unity cloud shader, using vertex colors and tessellation for a simple stylized look.
Stars: ✭ 110 (-94.34%)
Mutual labels:  cloud, unity
Gdk For Unity Fps Starter Project
SpatialOS GDK for Unity FPS Starter Project
Stars: ✭ 119 (-93.88%)
Mutual labels:  game, unity
Sycophant
Numerous Ninjas: Beta stage mobile game written in Unity
Stars: ✭ 64 (-96.71%)
Mutual labels:  game, unity
Ksframework
QQ Group:538722494,KSFramework = KEngine + SLua(or xLua) , Unity3D Framework/Toolsets focus on hot reload
Stars: ✭ 1,119 (-42.47%)
Mutual labels:  game, unity
Bdframework.core
[中]Simple! Easy! Powerful Unity3d game workflow! Unity3d framework:c# hotfix(ILRuntime)、asset manager、ui workflow、network debug... and so on
Stars: ✭ 1,196 (-38.51%)
Mutual labels:  game, unity
Escapefromtarkov Trainer
Escape from Tarkov Trainer
Stars: ✭ 59 (-96.97%)
Mutual labels:  game, unity
Card Game Simulator
Create, Share, and Play
Stars: ✭ 87 (-95.53%)
Mutual labels:  game, unity
Sgf
This is a Smart Game Foundation (Not Framework)
Stars: ✭ 122 (-93.73%)
Mutual labels:  game, unity
Srp
A customized forward+ render pipeline for Unity
Stars: ✭ 53 (-97.28%)
Mutual labels:  game, unity
Gold Player
A first person player controller for Unity.
Stars: ✭ 53 (-97.28%)
Mutual labels:  game, unity
Unity Platformer
Unity platformer framework: IA, Ladders, Jumps, WallStick, WallJumps, Slopes, MovingPlatforms, OneWayPlatforms/Walls, Ropes and more...
Stars: ✭ 97 (-95.01%)
Mutual labels:  game, unity

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].